diff --git a/Jenkinsfile2 b/Jenkinsfile2 index ac152e2aa4605b570d6db4289c594fcb3d01aa0e..9e89e5a2f85344cad3767c3cdc6e40088079e61d 100644 --- a/Jenkinsfile2 +++ b/Jenkinsfile2 @@ -173,8 +173,9 @@ def pre_test_build_mac() { ''' sh ''' cd ${WK}/debug - cmake .. -DBUILD_TEST=true - make -j8 + cmake .. -DBUILD_TEST=true -DBUILD_HTTPS=false + make -j10 + ctest -j10 || exit 7 ''' sh ''' date @@ -428,7 +429,7 @@ pipeline { date rm -rf ${WKC}/debug cd ${WKC}/tests/parallel_test - time ./container_build.sh -w ${WKDIR} -t 8 -e + time ./container_build.sh -w ${WKDIR} -t 10 -e rm -f /tmp/cases.task ./collect_cases.sh -e ''' diff --git a/cmake/cmake.version b/cmake/cmake.version index 1a83126cd7d1ce3257cc6d3c811bd4e2f49a0371..03598519ed9f0745f4f61dc4c6327b097f296243 100644 --- a/cmake/cmake.version +++ b/cmake/cmake.version @@ -2,7 +2,7 @@ IF (DEFINED VERNUMBER) SET(TD_VER_NUMBER ${VERNUMBER}) ELSE () - SET(TD_VER_NUMBER "3.0.1.5") + SET(TD_VER_NUMBER "3.0.1.6") ENDIF () IF (DEFINED VERCOMPATIBLE) @@ -65,13 +65,14 @@ ELSE () ENDIF () MESSAGE(STATUS "============= compile version parameter information start ============= ") -MESSAGE(STATUS "ver number:" ${TD_VER_NUMBER}) -MESSAGE(STATUS "compatible ver number:" ${TD_VER_COMPATIBLE}) -MESSAGE(STATUS "communit commit id:" ${TD_VER_GIT}) -MESSAGE(STATUS "build date:" ${TD_VER_DATE}) -MESSAGE(STATUS "ver type:" ${TD_VER_VERTYPE}) -MESSAGE(STATUS "ver cpu:" ${TD_VER_CPUTYPE}) -MESSAGE(STATUS "os type:" ${TD_VER_OSTYPE}) +MESSAGE(STATUS "version: " ${TD_VER_NUMBER}) +MESSAGE(STATUS "compatible: " ${TD_VER_COMPATIBLE}) +MESSAGE(STATUS "commit id: " ${TD_VER_GIT}) +MESSAGE(STATUS "build date: " ${TD_VER_DATE}) +MESSAGE(STATUS "build type: " ${CMAKE_BUILD_TYPE}) +MESSAGE(STATUS "type: " ${TD_VER_VERTYPE}) +MESSAGE(STATUS "cpu: " ${TD_VER_CPUTYPE}) +MESSAGE(STATUS "os: " ${TD_VER_OSTYPE}) MESSAGE(STATUS "============= compile version parameter information end ============= ") STRING(REPLACE "." "_" TD_LIB_VER_NUMBER ${TD_VER_NUMBER}) diff --git a/cmake/taosadapter_CMakeLists.txt.in b/cmake/taosadapter_CMakeLists.txt.in index 5b8192831e74bf78cfee8e7c55604cbfa8fdc11c..79d54f522efb679fe0362789efebe981bbfd2709 100644 --- a/cmake/taosadapter_CMakeLists.txt.in +++ b/cmake/taosadapter_CMakeLists.txt.in @@ -2,7 +2,7 @@ # taosadapter ExternalProject_Add(taosadapter GIT_REPOSITORY https://github.com/taosdata/taosadapter.git - GIT_TAG a11131c + GIT_TAG 0d5663d SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosadapter" BINARY_DIR "" #BUILD_IN_SOURCE TRUE diff --git a/cmake/taostools_CMakeLists.txt.in b/cmake/taostools_CMakeLists.txt.in index 340de43343d6ee717466025399649f471073a0c5..d18d85171d4fcbc42e5caed0c41b6901bc70ef5d 100644 --- a/cmake/taostools_CMakeLists.txt.in +++ b/cmake/taostools_CMakeLists.txt.in @@ -2,7 +2,7 @@ # taos-tools ExternalProject_Add(taos-tools GIT_REPOSITORY https://github.com/taosdata/taos-tools.git - GIT_TAG f9c1d32 + GIT_TAG a921bd4 SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools" BINARY_DIR "" #BUILD_IN_SOURCE TRUE diff --git a/cmake/taosws_CMakeLists.txt.in b/cmake/taosws_CMakeLists.txt.in index 67a23b32b0a7390c2087666a0af71754d07bb56f..33ca6c659cc0b228dd08c61e304faa4d8f2c260d 100644 --- a/cmake/taosws_CMakeLists.txt.in +++ b/cmake/taosws_CMakeLists.txt.in @@ -2,7 +2,7 @@ # taosws-rs ExternalProject_Add(taosws-rs GIT_REPOSITORY https://github.com/taosdata/taos-connector-rust.git - GIT_TAG 0373a70 + GIT_TAG 38c4599 SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosws-rs" BINARY_DIR "" #BUILD_IN_SOURCE TRUE diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index 969724cc8d0ebd68f3a3cbdf5716bdcb4efb5ff9..8f943133820bfa45a963ad9c36c48ddf60756a98 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -270,7 +270,7 @@ if(${JEMALLOC_ENABLED}) PREFIX "jemalloc" SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/jemalloc BUILD_IN_SOURCE 1 - CONFIGURE_COMMAND ./autogen.sh COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/build/ --disable-initial-exec-tls --with-malloc-conf='background_thread:true,metadata_thp:auto' + CONFIGURE_COMMAND ./autogen.sh COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/build/ --disable-initial-exec-tls BUILD_COMMAND ${MAKE} ) INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/build/include) diff --git a/docs/en/07-develop/03-insert-data/02-influxdb-line.mdx b/docs/en/07-develop/03-insert-data/02-influxdb-line.mdx index 6f933d52ac0b70bf4700525d31e0e46bad470193..3c088602602301fafa824bc256f1f2caca128abd 100644 --- a/docs/en/07-develop/03-insert-data/02-influxdb-line.mdx +++ b/docs/en/07-develop/03-insert-data/02-influxdb-line.mdx @@ -37,9 +37,9 @@ meters,location=California.LosAngeles,groupid=2 current=13.4,voltage=223,phase=0 - All the data in `tag_set` will be converted to NCHAR type automatically . - Each data in `field_set` must be self-descriptive for its data type. For example 1.2f32 means a value 1.2 of float type. Without the "f" type suffix, it will be treated as type double. - Multiple kinds of precision can be used for the `timestamp` field. Time precision can be from nanosecond (ns) to hour (h). -- You can configure smlChildTableName in taos.cfg to specify table names, for example, `smlChildTableName=tname`. You can insert `st,tname=cpul,t1=4 c1=3 1626006833639000000` and the cpu1 table will be automatically created. Note that if multiple rows have the same tname but different tag_set values, the tag_set of the first row is used to create the table and the others are ignored. +- The child table name is created automatically in a rule to guarantee its uniqueness. But you can configure `smlChildTableName` in taos.cfg to specify a tag value as the table names if the tag value is unique globally. For example, if a tag is called `tname` and you set `smlChildTableName=tname` in taos.cfg, when you insert `st,tname=cpu1,t1=4 c1=3 1626006833639000000`, the child table `cpu1` will be created automatically. Note that if multiple rows have the same tname but different tag_set values, the tag_set of the first row is used to create the table and the others are ignored. - It is assumed that the order of field_set in a supertable is consistent, meaning that the first record contains all fields and subsequent records store fields in the same order. If the order is not consistent, set smlDataFormat in taos.cfg to false. Otherwise, data will be written out of order and a database error will occur.(smlDataFormat in taos.cfg default to false after version of 3.0.1.3) - ::: +::: For more details please refer to [InfluxDB Line Protocol](https://docs.influxdata.com/influxdb/v2.0/reference/syntax/line-protocol/) and [TDengine Schemaless](/reference/schemaless/#Schemaless-Line-Protocol) diff --git a/docs/en/07-develop/03-insert-data/03-opentsdb-telnet.mdx b/docs/en/07-develop/03-insert-data/03-opentsdb-telnet.mdx index 10482df6b21674ec45e1f3e5e0517475618f94b6..5d3f25dca96a0d41a4562aa067800607e8e04277 100644 --- a/docs/en/07-develop/03-insert-data/03-opentsdb-telnet.mdx +++ b/docs/en/07-develop/03-insert-data/03-opentsdb-telnet.mdx @@ -32,7 +32,7 @@ For example: meters.current 1648432611250 11.3 location=California.LosAngeles groupid=3 ``` -- The defult child table name is generated by rules.You can configure smlChildTableName in taos.cfg to specify child table names, for example, `smlChildTableName=tname`. You can insert `meters.current 1648432611250 11.3 tname=cpu1 location=California.LosAngeles groupid=3` and the cpu1 table will be automatically created. Note that if multiple rows have the same tname but different tag_set values, the tag_set of the first row is used to create the table and the others are ignored. +- The child table name is created automatically in a rule to guarantee its uniqueness. But you can configure `smlChildTableName` in taos.cfg to specify a tag value as the table names if the tag value is unique globally. For example, if a tag is called `tname` and you set `smlChildTableName=tname` in taos.cfg, when you insert `st,tname=cpu1,t1=4 c1=3 1626006833639000000`, the child table `cpu1` will be automatically created. Note that if multiple rows have the same tname but different tag_set values, the tag_set of the first row is used to create the table and the others are ignored. Please refer to [OpenTSDB Telnet API](http://opentsdb.net/docs/build/html/api_telnet/put.html) for more details. ## Examples diff --git a/docs/en/07-develop/03-insert-data/04-opentsdb-json.mdx b/docs/en/07-develop/03-insert-data/04-opentsdb-json.mdx index be8f521cf2e7d2ed1364dedc7b523e65af287f4f..7a3ac6bad3b203a9859e235e92d0865f7147d24c 100644 --- a/docs/en/07-develop/03-insert-data/04-opentsdb-json.mdx +++ b/docs/en/07-develop/03-insert-data/04-opentsdb-json.mdx @@ -48,8 +48,8 @@ Please refer to [OpenTSDB HTTP API](http://opentsdb.net/docs/build/html/api_http - In JSON protocol, strings will be converted to NCHAR type and numeric values will be converted to double type. - Only data in array format is accepted and so an array must be used even if there is only one row. -- The defult child table name is generated by rules.You can configure smlChildTableName in taos.cfg to specify child table names, for example, `smlChildTableName=tname`. You can insert `"tags": { "host": "web02","dc": "lga","tname":"cpu1"}` and the cpu1 table will be automatically created. Note that if multiple rows have the same tname but different tag_set values, the tag_set of the first row is used to create the table and the others are ignored. - ::: +- The child table name is created automatically in a rule to guarantee its uniqueness. But you can configure `smlChildTableName` in taos.cfg to specify a tag value as the table names if the tag value is unique globally. For example, if a tag is called `tname` and you set `smlChildTableName=tname` in taos.cfg, when you insert `st,tname=cpu1,t1=4 c1=3 1626006833639000000`, the child table `cpu1` will be automatically created. Note that if multiple rows have the same tname but different tag_set values, the tag_set of the first row is used to create the table and the others are ignored. +::: ## Examples diff --git a/docs/en/07-develop/09-udf.md b/docs/en/07-develop/09-udf.md index deb9c4cdb5b50edf7b48537f607ac47edc1246fd..253f1270f5556a329460cb89176323ed307ac152 100644 --- a/docs/en/07-develop/09-udf.md +++ b/docs/en/07-develop/09-udf.md @@ -218,9 +218,9 @@ After compiling your function into a DLL, you add it to TDengine. For more infor ## Sample Code -### Sample scalar function: [bit_and](https://github.com/taosdata/TDengine/blob/develop/tests/script/sh/bit_and.c) +### Sample scalar function: [bit_and](https://github.com/taosdata/TDengine/blob/3.0/tests/script/sh/bit_and.c) -The bit_add function implements bitwise addition for multiple columns. If there is only one column, the column is returned. The bit_add function ignores null values. +The bit_and function implements bitwise addition for multiple columns. If there is only one column, the column is returned. The bit_and function ignores null values.
bit_and.c @@ -231,7 +231,7 @@ The bit_add function implements bitwise addition for multiple columns. If there
-### Sample aggregate function: [l2norm](https://github.com/taosdata/TDengine/blob/develop/tests/script/sh/l2norm.c) +### Sample aggregate function: [l2norm](https://github.com/taosdata/TDengine/blob/3.0/tests/script/sh/l2norm.c) The l2norm function finds the second-order norm for all data in the input column. This squares the values, takes a cumulative sum, and finds the square root. diff --git a/docs/en/12-taos-sql/03-table.md b/docs/en/12-taos-sql/03-table.md index 5a2c8ed6ee4a5ea129023fec68fa97d577832f60..6d12b8c73056d049997a244ed0ab788742094d65 100644 --- a/docs/en/12-taos-sql/03-table.md +++ b/docs/en/12-taos-sql/03-table.md @@ -7,12 +7,12 @@ title: Table You create standard tables and subtables with the `CREATE TABLE` statement. ```sql -CREATE TABLE [IF NOT EXISTS] [db_name.]tb_name (create_definition [, create_definitionn] ...) [table_options] +CREATE TABLE [IF NOT EXISTS] [db_name.]tb_name (create_definition [, create_definition] ...) [table_options] CREATE TABLE create_subtable_clause -CREATE TABLE [IF NOT EXISTS] [db_name.]tb_name (create_definition [, create_definitionn] ...) - [TAGS (create_definition [, create_definitionn] ...)] +CREATE TABLE [IF NOT EXISTS] [db_name.]tb_name (create_definition [, create_definition] ...) + [TAGS (create_definition [, create_definition] ...)] [table_options] create_subtable_clause: { @@ -195,4 +195,4 @@ This command is useful in migrating data from one TDengine cluster to another be ``` DESCRIBE [db_name.]tb_name; -``` \ No newline at end of file +``` diff --git a/docs/en/12-taos-sql/04-stable.md b/docs/en/12-taos-sql/04-stable.md index a20e33163b5cc33129d33ed096607d6ca1cec114..8a7c713f8cad6d61c8b098583cc4e282b00d48cf 100644 --- a/docs/en/12-taos-sql/04-stable.md +++ b/docs/en/12-taos-sql/04-stable.md @@ -6,7 +6,7 @@ title: Supertable ## Create a Supertable ```sql -CREATE STABLE [IF NOT EXISTS] stb_name (create_definition [, create_definitionn] ...) TAGS (create_definition [, create_definition] ...) [table_options] +CREATE STABLE [IF NOT EXISTS] stb_name (create_definition [, create_definition] ...) TAGS (create_definition [, create_definition] ...) [table_options] create_definition: col_name column_definition diff --git a/docs/en/12-taos-sql/06-select.md b/docs/en/12-taos-sql/06-select.md index 570defe1a7d2061c383d27f7969d6c4d5d0b30f5..0c55578efa0896d5b66799c8cf0a0da3cca51266 100644 --- a/docs/en/12-taos-sql/06-select.md +++ b/docs/en/12-taos-sql/06-select.md @@ -255,7 +255,7 @@ Note: If you include an ORDER BY clause, only one partition can be displayed. Some special query functions can be invoked without `FROM` sub-clause. -## Obtain Current Database +### Obtain Current Database The following SQL statement returns the current database. If a database has not been specified on login or with the `USE` command, a null value is returned. @@ -270,7 +270,7 @@ SELECT CLIENT_VERSION(); SELECT SERVER_VERSION(); ``` -## Obtain Server Status +### Obtain Server Status The following SQL statement returns the status of the TDengine server. An integer indicates that the server is running normally. An error code indicates that an error has occurred. This statement can also detect whether a connection pool or third-party tool is connected to TDengine properly. By using this statement, you can ensure that connections in a pool are not lost due to an incorrect heartbeat detection statement. @@ -314,6 +314,40 @@ Regular expression filtering is supported only on table names (TBNAME), BINARY t A regular expression string cannot exceed 128 bytes. You can configure this value by modifying the maxRegexStringLen parameter on the TDengine Client. The modified value takes effect when the client is restarted. +## CASE Expressions + +### Syntax + +```txt +CASE value WHEN compare_value THEN result [WHEN compare_value THEN result ...] [ELSE result] END +CASE WHEN condition THEN result [WHEN condition THEN result ...] [ELSE result] END +``` + +### Description +CASE expressions let you use IF ... THEN ... ELSE logic in SQL statements without having to invoke procedures. + +The first CASE syntax returns the `result` for the first `value`=`compare_value` comparison that is true. + +The second syntax returns the `result` for the first `condition` that is true. + +If no comparison or condition is true, the result after ELSE is returned, or NULL if there is no ELSE part. + +The return type of the CASE expression is the result type of the first WHEN WHEN part, and the result type of the other WHEN WHEN parts and ELSE parts can be converted to them, otherwise TDengine will report an error. + +### Examples + +A device has three status codes to display its status. The statements are as follows: + +```sql +SELECT CASE dev_status WHEN 1 THEN 'Running' WHEN 2 THEN 'Warning' WHEN 3 THEN 'Downtime' ELSE 'Unknown' END FROM dev_table; +``` + +The average voltage value of the smart meter is counted. When the voltage is less than 200 or more than 250, it is considered that the statistics is wrong, and the value is corrected to 220. The statement is as follows: + +```sql +SELECT AVG(CASE WHEN voltage < 200 or voltage > 250 THEN 220 ELSE voltage END) FROM meters; +``` + ## JOIN TDengine supports natural joins between supertables, between standard tables, and between subqueries. The difference between natural joins and inner joins is that natural joins require that the fields being joined in the supertables or standard tables must have the same name. Data or tag columns must be joined with the equivalent column in another table. diff --git a/docs/en/12-taos-sql/12-distinguished.md b/docs/en/12-taos-sql/12-distinguished.md index 296c2376427b28ea0fa8404517af7215ffa7030f..0763e85a53bc6021a2fe28d7df20f627d1b3fbe7 100644 --- a/docs/en/12-taos-sql/12-distinguished.md +++ b/docs/en/12-taos-sql/12-distinguished.md @@ -126,6 +126,12 @@ Only care about the information of the status window when the status is 2. For e SELECT * FROM (SELECT COUNT(*) AS cnt, FIRST(ts) AS fst, status FROM temp_tb_1 STATE_WINDOW(status)) t WHERE status = 2; ``` +TDengine also supports the use of CASE expressions in state quantities. It can express that the beginning of a state is triggered by meeting a certain condition, and the end of this state is triggered by meeting another condition. For example, if the normal voltage range of the smart meter is 205V to 235V, you can judge whether the circuit is normal by monitoring the voltage. + +``` +SELECT tbname, _wstart, CASE WHEN voltage >= 205 and voltage <= 235 THEN 1 ELSE 0 END status FROM meters PARTITION BY tbname STATE_WINDOW(CASE WHEN voltage >= 205 and voltage <= 235 THEN 1 ELSE 0 END); +``` + ### Session Window The primary key, i.e. timestamp, is used to determine which session window a row belongs to. As shown in the figure below, if the limit of time interval for the session window is specified as 12 seconds, then the 6 rows in the figure constitutes 2 time windows, [2019-04-28 14:22:10,2019-04-28 14:22:30] and [2019-04-28 14:23:10,2019-04-28 14:23:30] because the time difference between 2019-04-28 14:22:30 and 2019-04-28 14:23:10 is 40 seconds, which exceeds the time interval limit of 12 seconds. diff --git a/docs/en/14-reference/03-connector/04-java.mdx b/docs/en/14-reference/03-connector/04-java.mdx index ecf632c624db6d6eb99bcdc5c0edc00a025d6330..7b3440ebac2f630a2f6f39c3b270a2196d1d7739 100644 --- a/docs/en/14-reference/03-connector/04-java.mdx +++ b/docs/en/14-reference/03-connector/04-java.mdx @@ -201,7 +201,7 @@ The configuration parameters in the URL are as follows: - httpConnectTimeout: REST connection timeout in milliseconds, the default value is 5000 ms. - httpSocketTimeout: socket timeout in milliseconds, the default value is 5000 ms. It only takes effect when batchfetch is false. - messageWaitTimeout: message transmission timeout in milliseconds, the default value is 3000 ms. It only takes effect when batchfetch is true. -- useSSL: connecting Securely Using SSL. true: using SSL conneciton, false: not using SSL connection. +- useSSL: connecting Securely Using SSL. true: using SSL connection, false: not using SSL connection. **Note**: Some configuration items (e.g., locale, timezone) do not work in the REST connection. @@ -268,7 +268,7 @@ The configuration parameters in properties are as follows. - TSDBDriver.HTTP_CONNECT_TIMEOUT: REST connection timeout in milliseconds, the default value is 5000 ms. It only takes effect when using JDBC REST connection. - TSDBDriver.HTTP_SOCKET_TIMEOUT: socket timeout in milliseconds, the default value is 5000 ms. It only takes effect when using JDBC REST connection and batchfetch is false. - TSDBDriver.PROPERTY_KEY_MESSAGE_WAIT_TIMEOUT: message transmission timeout in milliseconds, the default value is 3000 ms. It only takes effect when using JDBC REST connection and batchfetch is true. -- TSDBDriver.PROPERTY_KEY_USE_SSL: connecting Securely Using SSL. true: using SSL conneciton, false: not using SSL connection. It only takes effect when using JDBC REST connection. +- TSDBDriver.PROPERTY_KEY_USE_SSL: connecting Securely Using SSL. true: using SSL connection, false: not using SSL connection. It only takes effect when using JDBC REST connection. For JDBC native connections, you can specify other parameters, such as log level, SQL length, etc., by specifying URL and Properties. For more detailed configuration, please refer to [Client Configuration](/reference/config/#Client-Only). ### Priority of configuration parameters @@ -824,7 +824,7 @@ Example usage is as follows. //query or insert // ... - connection.close(); // put back to conneciton pool + connection.close(); // put back to connection pool } ``` @@ -856,7 +856,7 @@ public static void main(String[] args) throws Exception { //query or insert // ... - connection.close(); // put back to conneciton pool + connection.close(); // put back to connection pool } ``` @@ -878,7 +878,9 @@ The source code of the sample application is under `TDengine/examples/JDBC`: | taos-jdbcdriver version | major changes | | :---------------------: | :--------------------------------------------: | +| 3.0.1 - 3.0.2 | fix the resultSet data is parsed incorrectly sometimes. 3.0.1 is compiled on JDK 11, you are advised to use 3.0.2 in the JDK 8 environment | | 3.0.0 | Support for TDengine 3.0 | +| 2.0.41 | fix decode method of username and password in REST connection | | 2.0.39 - 2.0.40 | Add REST connection/request timeout parameters | | 2.0.38 | JDBC REST connections add bulk pull function | | 2.0.37 | Support json tags | @@ -910,6 +912,12 @@ The source code of the sample application is under `TDengine/examples/JDBC`: **Solution**: Use taos-jdbcdriver 2.* with your TDengine 2.* deployment. +5. java.lang.NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer; ... taos-jdbcdriver-3.0.1.jar + +**Cause**:taos-jdbcdriver 3.0.1 is compiled on JDK 11. + +**Solution**: Use taos-jdbcdriver 3.0.2. + For additional troubleshooting, see [FAQ](../../../train-faq/faq). ## API Reference diff --git a/docs/en/14-reference/03-connector/05-go.mdx b/docs/en/14-reference/03-connector/05-go.mdx index a33b302a9201737bda83a0536ffd76c4594aa283..df5b129cea552144d5833190d46e8a78f2fd2fa5 100644 --- a/docs/en/14-reference/03-connector/05-go.mdx +++ b/docs/en/14-reference/03-connector/05-go.mdx @@ -353,7 +353,7 @@ The `af` package encapsulates TDengine advanced functions such as connection man Closes the connection. -#### Subscribe to +#### Subscribe * `func NewConsumer(conf *Config) (*Consumer, error)` @@ -387,7 +387,7 @@ Close consumer. * `func (conn *Connector) InfluxDBInsertLines(lines []string, precision string) error` - Write to influxDB line protocol. + Write to InfluxDB line protocol. * `func (conn *Connector) OpenTSDBInsertTelnetLines(lines []string) error` @@ -413,7 +413,7 @@ Close consumer. * `func (stmt *InsertStmt) SetTableName(name string) error` - Bind the set table name parameter. + Bind the table name parameter. * `func (stmt *InsertStmt) SetSubTableName(name string) error` @@ -463,6 +463,54 @@ Close consumer. For a complete example see [GitHub sample file](https://github.com/taosdata/driver-go/blob/3.0/examples/tmqoverws/main.go) +### parameter binding via WebSocket + +* `func NewConnector(config *Config) (*Connector, error)` + + Create a connection. + +* `func (c *Connector) Init() (*Stmt, error)` + + Initialize the parameters. + +* `func (c *Connector) Close() error` + + Close the connection. + +* `func (s *Stmt) Prepare(sql string) error` + + Parameter binding preprocessing SQL statement. + +* `func (s *Stmt) SetTableName(name string) error` + + Bind the table name parameter. + +* `func (s *Stmt) SetTags(tags *param.Param, bindType *param.ColumnType) error` + + Set tags. + +* `func (s *Stmt) BindParam(params []*param.Param, bindType *param.ColumnType) error` + + Parameter bind multiple rows of data. + +* `func (s *Stmt) AddBatch() error` + + Add to a parameter-bound batch. + +* `func (s *Stmt) Exec() error` + + Execute a parameter binding. + +* `func (s *Stmt) GetAffectedRows() int` + + Gets the number of affected rows inserted by the parameter binding. + +* `func (s *Stmt) Close() error` + + Closes the parameter binding. + +For a complete example see [GitHub sample file](https://github.com/taosdata/driver-go/blob/3.0/examples/stmtoverws/main.go) + ## API Reference Full API see [driver-go documentation](https://pkg.go.dev/github.com/taosdata/driver-go/v3) diff --git a/docs/en/14-reference/05-taosbenchmark.md b/docs/en/14-reference/05-taosbenchmark.md index b114f92a41241bd21f5dc7ca5ea5709b8c2ffbd3..6e08671e344100aa3dcfeba5a10c0d0e304a1a91 100644 --- a/docs/en/14-reference/05-taosbenchmark.md +++ b/docs/en/14-reference/05-taosbenchmark.md @@ -217,7 +217,7 @@ taosBenchmark -A INT,DOUBLE,NCHAR,BINARY\(16\) The parameters listed in this section apply to all function modes. - **filetype** : The function to be tested, with optional values `insert`, `query` and `subscribe`. These correspond to the insert, query, and subscribe functions, respectively. Users can specify only one of these in each configuration file. -**cfgdir**: specify the TDengine cluster configuration file's directory. The default path is /etc/taos. +**cfgdir**: specify the TDengine client configuration file's directory. The default path is /etc/taos. - **host**: Specify the FQDN of the TDengine server to connect. The default value is `localhost`. @@ -374,7 +374,11 @@ The configuration parameters for specifying super table tag columns and data col ### Query scenario configuration parameters -`filetype` must be set to `query` in the query scenario. See [General Configuration Parameters](#General Configuration Parameters) for details of this parameter and other general parameters +`filetype` must be set to `query` in the query scenario. + +To control the query scenario by setting `kill_slow_query_threshold` and `kill_slow_query_interval` parameters to kill the execution of slow query statements. Threshold controls exec_usec of query command will be killed by taosBenchmark after the specified time, in seconds; interval controls sleep time to avoid continuous querying of slow queries consuming CPU in seconds. + +See [General Configuration Parameters](#General Configuration Parameters) for details of other general parameters. #### Configuration parameters for executing the specified query statement diff --git a/docs/en/14-reference/12-config/index.md b/docs/en/14-reference/12-config/index.md index 8053c4d25d527adf3e2c22fd107c7c28114e2eb6..bb5516ae700ad7cd5b47a87ed56338c27aa1eab0 100644 --- a/docs/en/14-reference/12-config/index.md +++ b/docs/en/14-reference/12-config/index.md @@ -735,19 +735,17 @@ To prevent system resource from being exhausted by multiple concurrent streams, | 44 | numOfVnodeQueryThreads | No | Yes | | 45 | numOfVnodeStreamThreads | No | Yes | | 46 | numOfVnodeFetchThreads | No | Yes | -| 47 | numOfVnodeWriteThreads | No | Yes | -| 48 | numOfVnodeSyncThreads | No | Yes | -| 49 | numOfVnodeRsmaThreads | No | Yes | -| 50 | numOfQnodeQueryThreads | No | Yes | -| 51 | numOfQnodeFetchThreads | No | Yes | -| 52 | numOfSnodeSharedThreads | No | Yes | -| 53 | numOfSnodeUniqueThreads | No | Yes | -| 54 | rpcQueueMemoryAllowed | No | Yes | -| 55 | logDir | Yes | Yes | -| 56 | minimalLogDirGB | Yes | Yes | -| 57 | numOfLogLines | Yes | Yes | -| 58 | asyncLog | Yes | Yes | -| 59 | logKeepDays | Yes | Yes | +| 47 | numOfVnodeRsmaThreads | No | Yes | +| 48 | numOfQnodeQueryThreads | No | Yes | +| 49 | numOfQnodeFetchThreads | No | Yes | +| 50 | numOfSnodeSharedThreads | No | Yes | +| 51 | numOfSnodeUniqueThreads | No | Yes | +| 52 | rpcQueueMemoryAllowed | No | Yes | +| 53 | logDir | Yes | Yes | +| 54 | minimalLogDirGB | Yes | Yes | +| 55 | numOfLogLines | Yes | Yes | +| 56 | asyncLog | Yes | Yes | +| 57 | logKeepDays | Yes | Yes | | 60 | debugFlag | Yes | Yes | | 61 | tmrDebugFlag | Yes | Yes | | 62 | uDebugFlag | Yes | Yes | diff --git a/docs/en/28-releases/01-tdengine.md b/docs/en/28-releases/01-tdengine.md index 14096bd40011ef514b522fe29060c85a69ab0670..74eeeb5efbb0ccb8ce031daaa78cabb2ca3bcc18 100644 --- a/docs/en/28-releases/01-tdengine.md +++ b/docs/en/28-releases/01-tdengine.md @@ -6,6 +6,10 @@ description: TDengine release history, Release Notes and download links. import Release from "/components/ReleaseV3"; +## 3.0.1.6 + + + ## 3.0.1.5 diff --git a/docs/en/28-releases/02-tools.md b/docs/en/28-releases/02-tools.md index a7446be4e39489e02e333f03c2c4f6f47503617a..0a96c776e061a40ed9ef769f6efbf3583df033fc 100644 --- a/docs/en/28-releases/02-tools.md +++ b/docs/en/28-releases/02-tools.md @@ -6,6 +6,10 @@ description: taosTools release history, Release Notes, download links. import Release from "/components/ReleaseV3"; +## 2.2.7 + + + ## 2.2.6 diff --git a/docs/en/28-releases/index.md b/docs/en/28-releases/index.md new file mode 100644 index 0000000000000000000000000000000000000000..c01c99cdce0190fb04f88d55a09e8cc406d4d8b0 --- /dev/null +++ b/docs/en/28-releases/index.md @@ -0,0 +1,10 @@ +--- +title: Releases +--- + +```mdx-code-block +import DocCardList from '@theme/DocCardList'; +import {useCurrentSidebarCategory} from '@docusaurus/theme-common'; + + +``` \ No newline at end of file diff --git a/docs/examples/c/insert_example.c b/docs/examples/c/insert_example.c index ce8fdc5b9372aec7b02d3c9254ec25c4c4f62adc..a921f794fdf8e5a33cef3d7e03860d28478b4547 100644 --- a/docs/examples/c/insert_example.c +++ b/docs/examples/c/insert_example.c @@ -36,10 +36,10 @@ int main() { executeSQL(taos, "CREATE DATABASE power"); executeSQL(taos, "USE power"); executeSQL(taos, "CREATE STABLE meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)"); - executeSQL(taos, "INSERT INTO d1001 USING meters TAGS(California.SanFrancisco, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)" - "d1002 USING meters TAGS(California.SanFrancisco, 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)" - "d1003 USING meters TAGS(California.LosAngeles, 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)" - "d1004 USING meters TAGS(California.LosAngeles, 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)"); + executeSQL(taos, "INSERT INTO d1001 USING meters TAGS('California.SanFrancisco', 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)" + "d1002 USING meters TAGS('California.SanFrancisco', 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)" + "d1003 USING meters TAGS('California.LosAngeles', 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)" + "d1004 USING meters TAGS('California.LosAngeles', 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)"); taos_close(taos); taos_cleanup(); } @@ -48,4 +48,4 @@ int main() { // affected rows 0 // affected rows 0 // affected rows 0 -// affected rows 8 \ No newline at end of file +// affected rows 8 diff --git a/docs/examples/csharp/wsConnect/Program.cs b/docs/examples/csharp/wsConnect/Program.cs index 2e89372c3e3dd23c16bad0362f494b2c64191cbc..f9a56c842fcfe1f0a032cca70460b4f84732cf18 100644 --- a/docs/examples/csharp/wsConnect/Program.cs +++ b/docs/examples/csharp/wsConnect/Program.cs @@ -9,9 +9,10 @@ namespace Examples { string DSN = "ws://root:taosdata@127.0.0.1:6041/test"; IntPtr wsConn = LibTaosWS.WSConnectWithDSN(DSN); + if (wsConn == IntPtr.Zero) { - throw new Exception($"get WS connection failed,reason:{LibTaosWS.WSErrorStr(IntPtr.Zero)} code:{LibTaosWS.WSErrorNo(IntPtr.Zero)}"); + throw new Exception("get WS connection failed"); } else { diff --git a/docs/examples/csharp/wsInsert/Program.cs b/docs/examples/csharp/wsInsert/Program.cs index 4cd812cda916308f80f7bf2001d38046434056c1..1f2d0a67253f478913f7eb0093b732a1a0c0f541 100644 --- a/docs/examples/csharp/wsInsert/Program.cs +++ b/docs/examples/csharp/wsInsert/Program.cs @@ -13,7 +13,7 @@ namespace Examples // Assert if connection is validate if (wsConn == IntPtr.Zero) { - throw new Exception($"get WS connection failed,reason:{LibTaosWS.WSErrorStr(IntPtr.Zero)} code:{LibTaosWS.WSErrorNo(IntPtr.Zero)}"); + throw new Exception("get WS connection failed"); } else { diff --git a/docs/examples/csharp/wsQuery/Program.cs b/docs/examples/csharp/wsQuery/Program.cs index de5591aa536655606547cf8998145025642989cd..a220cae9032bb2633f0514cbbd3f859a5f1a1f17 100644 --- a/docs/examples/csharp/wsQuery/Program.cs +++ b/docs/examples/csharp/wsQuery/Program.cs @@ -13,7 +13,7 @@ namespace Examples IntPtr wsConn = LibTaosWS.WSConnectWithDSN(DSN); if (wsConn == IntPtr.Zero) { - throw new Exception($"get WS connection failed,reason:{LibTaosWS.WSErrorStr(IntPtr.Zero)} code:{LibTaosWS.WSErrorNo(IntPtr.Zero)}"); + throw new Exception("get WS connection failed"); } else { diff --git a/docs/examples/csharp/wsStmt/Program.cs b/docs/examples/csharp/wsStmt/Program.cs index 54de77ec1f98deaf14fd2ad9ca0acd57e6b38f63..8af807ec39d72651c48ab82b79db7f4c5049225f 100644 --- a/docs/examples/csharp/wsStmt/Program.cs +++ b/docs/examples/csharp/wsStmt/Program.cs @@ -21,7 +21,7 @@ namespace Examples IntPtr wsConn = LibTaosWS.WSConnectWithDSN(DSN); if (wsConn == IntPtr.Zero) { - throw new Exception($"get WS connection failed,reason:{LibTaosWS.WSErrorStr(IntPtr.Zero)} code:{LibTaosWS.WSErrorNo(IntPtr.Zero)}"); + throw new Exception($"get WS connection failed"); } else { diff --git a/docs/zh/07-develop/03-insert-data/02-influxdb-line.mdx b/docs/zh/07-develop/03-insert-data/02-influxdb-line.mdx index 19ccf49906237f606d128ef568bcf8cf3ee23775..afe73af8dbc3a768a3e7640a9de5f11dbe18653c 100644 --- a/docs/zh/07-develop/03-insert-data/02-influxdb-line.mdx +++ b/docs/zh/07-develop/03-insert-data/02-influxdb-line.mdx @@ -38,9 +38,8 @@ meters,location=California.LosAngeles,groupid=2 current=13.4,voltage=223,phase=0 - field_set 中的每个数据项都需要对自身的数据类型进行描述, 比如 1.2f32 代表 FLOAT 类型的数值 1.2, 如果不带类型后缀会被当作 DOUBLE 处理; - timestamp 支持多种时间精度。写入数据的时候需要用参数指定时间精度,支持从小时到纳秒的 6 种时间精度。 - 为了提高写入的效率,默认假设同一个超级表中 field_set 的顺序是一样的(第一条数据包含所有的 field,后面的数据按照这个顺序),如果顺序不一样,需要配置参数 smlDataFormat 为 false,否则,数据写入按照相同顺序写入,库中数据会异常。(3.0.1.3 之后的版本 smlDataFormat 默认为 false) [TDengine 无模式写入参考指南](/reference/schemaless/#无模式写入行协议) -- 默认生产的子表名是根据规则生成的唯一 ID 值。为了让用户可以指定生成的表名,可以通过在 taos.cfg 里配置 smlChildTableName 参数来指定。 - 举例如下:配置 smlChildTableName=tname 插入数据为 st,tname=cpu1,t1=4 c1=3 1626006833639000000 则创建的表名为 cpu1,注意如果多行数据 tname 相同,但是后面的 tag_set 不同,则使用第一行自动建表时指定的 tag_set,其他的行会忽略)。[TDengine 无模式写入参考指南](/reference/schemaless/#无模式写入行协议) - ::: +- 默认产生的子表名是根据规则生成的唯一 ID 值。用户也可以通过在 taos.cfg 里配置 smlChildTableName 参数来指定某个标签值作为子表名。该标签值应该具有全局唯一性。举例如下:假设有个标签名为tname, 配置 smlChildTableName=tname, 插入数据为 st,tname=cpu1,t1=4 c1=3 1626006833639000000 则创建的子表名为 cpu1。注意如果多行数据 tname 相同,但是后面的 tag_set 不同,则使用第一行自动建表时指定的 tag_set,其他的行会忽略)。[TDengine 无模式写入参考指南](/reference/schemaless/#无模式写入行协议) +::: 要了解更多可参考:[InfluxDB Line 协议官方文档](https://docs.influxdata.com/influxdb/v2.0/reference/syntax/line-protocol/) 和 [TDengine 无模式写入参考指南](/reference/schemaless/#无模式写入行协议) diff --git a/docs/zh/07-develop/03-insert-data/03-opentsdb-telnet.mdx b/docs/zh/07-develop/03-insert-data/03-opentsdb-telnet.mdx index 25be8a0aa4486121642f73e0117db4de5f33877e..3b2148ef4abfd534a6560f4c3854fabce2267fd7 100644 --- a/docs/zh/07-develop/03-insert-data/03-opentsdb-telnet.mdx +++ b/docs/zh/07-develop/03-insert-data/03-opentsdb-telnet.mdx @@ -32,8 +32,7 @@ OpenTSDB 行协议同样采用一行字符串来表示一行数据。OpenTSDB meters.current 1648432611250 11.3 location=California.LosAngeles groupid=3 ``` -- 默认生产的子表名是根据规则生成的唯一 ID 值。为了让用户可以指定生成的表名,可以通过在 taos.cfg 里配置 smlChildTableName 参数来指定。 - 举例如下:配置 smlChildTableName=tname 插入数据为 meters.current 1648432611250 11.3 tname=cpu1 location=California.LosAngeles groupid=3 则创建的表名为 cpu1,注意如果多行数据 tname 相同,但是后面的 tag_set 不同,则使用第一行自动建表时指定的 tag_set,其他的行会忽略)。 +- 默认生产的子表名是根据规则生成的唯一 ID 值。用户也可以通过在 taos.cfg 里配置 smlChildTableName 参数来指定某个标签值作为子表名。该标签值应该具有全局唯一性。举例如下:假设有个标签名为tname, 配置 smlChildTableName=tname, 插入数据为 meters.current 1648432611250 11.3 tname=cpu1 location=California.LosAngeles groupid=3 则创建的表名为 cpu1,注意如果多行数据 tname 相同,但是后面的 tag_set 不同,则使用第一行自动建表时指定的 tag_set,其他的行会忽略)。 参考 [OpenTSDB Telnet API 文档](http://opentsdb.net/docs/build/html/api_telnet/put.html)。 ## 示例代码 diff --git a/docs/zh/07-develop/03-insert-data/04-opentsdb-json.mdx b/docs/zh/07-develop/03-insert-data/04-opentsdb-json.mdx index 57b00ab310cd10012e800ff12685a7be9f76bb69..89818409c5032166e77a50f07ea1b54bd66617cb 100644 --- a/docs/zh/07-develop/03-insert-data/04-opentsdb-json.mdx +++ b/docs/zh/07-develop/03-insert-data/04-opentsdb-json.mdx @@ -48,9 +48,8 @@ OpenTSDB JSON 格式协议采用一个 JSON 字符串表示一行或多行数据 - 对于 JSON 格式协议,TDengine 并不会自动把所有标签转成 NCHAR 类型, 字符串将将转为 NCHAR 类型, 数值将同样转换为 DOUBLE 类型。 - TDengine 只接收 JSON **数组格式**的字符串,即使一行数据也需要转换成数组形式。 -- 默认生产的子表名是根据规则生成的唯一 ID 值。为了让用户可以指定生成的表名,可以通过在 taos.cfg 里配置 smlChildTableName 参数来指定。 - 举例如下:配置 smlChildTableName=tname 插入数据为 `"tags": { "host": "web02","dc": "lga","tname":"cpu1"}` 则创建的表名为 cpu1,注意如果多行数据 tname 相同,但是后面的 tag_set 不同,则使用第一行自动建表时指定的 tag_set,其他的行会忽略)。 - ::: +- 默认生成的子表名是根据规则生成的唯一 ID 值。用户也可以通过在 taos.cfg 里配置 smlChildTableName 参数来指定某个标签值作为子表名。该标签值应该具有全局唯一性。举例如下:假设有个标签名为tname, 配置 smlChildTableName=tname, 插入数据为 `"tags": { "host": "web02","dc": "lga","tname":"cpu1"}` 则创建的子表名为 cpu1。注意如果多行数据 tname 相同,但是后面的 tag_set 不同,则使用第一行自动建表时指定的 tag_set,其他的行会忽略)。 +::: ## 示例代码 diff --git a/docs/zh/08-connector/14-java.mdx b/docs/zh/08-connector/14-java.mdx index d13e21ad547610972cdc4817b799744896ee6ec8..1ee59d2df429f2bd64b1dfdcc2ef81f12b1272d0 100644 --- a/docs/zh/08-connector/14-java.mdx +++ b/docs/zh/08-connector/14-java.mdx @@ -68,38 +68,39 @@ TDengine 目前支持时间戳、数字、字符、布尔类型,与 Java 对 ### 安装连接器 - + -目前 taos-jdbcdriver 已经发布到 [Sonatype Repository](https://search.maven.org/artifact/com.taosdata.jdbc/taos-jdbcdriver) 仓库,且各大仓库都已同步。 + 目前 taos-jdbcdriver 已经发布到 [Sonatype Repository](https://search.maven.org/artifact/com.taosdata.jdbc/taos-jdbcdriver) + 仓库,且各大仓库都已同步。 -- [sonatype](https://search.maven.org/artifact/com.taosdata.jdbc/taos-jdbcdriver) -- [mvnrepository](https://mvnrepository.com/artifact/com.taosdata.jdbc/taos-jdbcdriver) -- [maven.aliyun](https://maven.aliyun.com/mvn/search) + - [sonatype](https://search.maven.org/artifact/com.taosdata.jdbc/taos-jdbcdriver) + - [mvnrepository](https://mvnrepository.com/artifact/com.taosdata.jdbc/taos-jdbcdriver) + - [maven.aliyun](https://maven.aliyun.com/mvn/search) -Maven 项目中,在 pom.xml 中添加以下依赖: + Maven 项目中,在 pom.xml 中添加以下依赖: -```xml-dtd - - com.taosdata.jdbc - taos-jdbcdriver - 3.0.0 - -``` + ```xml-dtd + + com.taosdata.jdbc + taos-jdbcdriver + 3.0.0 + + ``` - - + + -可以通过下载 TDengine 的源码,自己编译最新版本的 Java connector + 可以通过下载 TDengine 的源码,自己编译最新版本的 Java connector -```shell -git clone https://github.com/taosdata/taos-connector-jdbc.git -cd taos-connector-jdbc -mvn clean install -Dmaven.test.skip=true -``` + ```shell + git clone https://github.com/taosdata/taos-connector-jdbc.git + cd taos-connector-jdbc + mvn clean install -Dmaven.test.skip=true + ``` -编译后,在 target 目录下会产生 taos-jdbcdriver-3.0.*-dist.jar 的 jar 包,并自动将编译的 jar 文件放在本地的 Maven 仓库中。 + 编译后,在 target 目录下会产生 taos-jdbcdriver-3.0.*-dist.jar 的 jar 包,并自动将编译的 jar 文件放在本地的 Maven 仓库中。 - + ## 建立连接 @@ -110,116 +111,125 @@ TDengine 的 JDBC URL 规范格式为: 对于建立连接,原生连接与 REST 连接有细微不同。 - + -```java -Class.forName("com.taosdata.jdbc.TSDBDriver"); -String jdbcUrl = "jdbc:TAOS://taosdemo.com:6030/test?user=root&password=taosdata"; -Connection conn = DriverManager.getConnection(jdbcUrl); -``` + ```java + Class.forName("com.taosdata.jdbc.TSDBDriver"); + String jdbcUrl = "jdbc:TAOS://taosdemo.com:6030/test?user=root&password=taosdata"; + Connection conn = DriverManager.getConnection(jdbcUrl); + ``` -以上示例,使用了 JDBC 原生连接的 TSDBDriver,建立了到 hostname 为 taosdemo.com,端口为 6030(TDengine 的默认端口),数据库名为 test 的连接。这个 URL 中指定用户名(user)为 root,密码(password)为 taosdata。 + 以上示例,使用了 JDBC 原生连接的 TSDBDriver,建立了到 hostname 为 taosdemo.com,端口为 6030(TDengine 的默认端口),数据库名为 test 的连接。这个 URL + 中指定用户名(user)为 root,密码(password)为 taosdata。 -**注意**:使用 JDBC 原生连接,taos-jdbcdriver 需要依赖客户端驱动(Linux 下是 libtaos.so;Windows 下是 taos.dll;macOS 下是 libtaos.dylib)。 + **注意**:使用 JDBC 原生连接,taos-jdbcdriver 需要依赖客户端驱动(Linux 下是 libtaos.so;Windows 下是 taos.dll;macOS 下是 libtaos.dylib)。 -url 中的配置参数如下: + url 中的配置参数如下: -- user:登录 TDengine 用户名,默认值 'root'。 -- password:用户登录密码,默认值 'taosdata'。 -- cfgdir:客户端配置文件目录路径,Linux OS 上默认值 `/etc/taos`,Windows OS 上默认值 `C:/TDengine/cfg`。 -- charset:客户端使用的字符集,默认值为系统字符集。 -- locale:客户端语言环境,默认值系统当前 locale。 -- timezone:客户端使用的时区,默认值为系统当前时区。 -- batchfetch: true:在执行查询时批量拉取结果集;false:逐行拉取结果集。默认值为:true。开启批量拉取同时获取一批数据在查询数据量较大时批量拉取可以有效的提升查询性能。 -- batchErrorIgnore:true:在执行 Statement 的 executeBatch 时,如果中间有一条 SQL 执行失败将继续执行下面的 SQL。false:不再执行失败 SQL 后的任何语句。默认值为:false。 + - user:登录 TDengine 用户名,默认值 'root'。 + - password:用户登录密码,默认值 'taosdata'。 + - cfgdir:客户端配置文件目录路径,Linux OS 上默认值 `/etc/taos`,Windows OS 上默认值 `C:/TDengine/cfg`。 + - charset:客户端使用的字符集,默认值为系统字符集。 + - locale:客户端语言环境,默认值系统当前 locale。 + - timezone:客户端使用的时区,默认值为系统当前时区。 + - batchfetch: true:在执行查询时批量拉取结果集;false:逐行拉取结果集。默认值为:true。开启批量拉取同时获取一批数据在查询数据量较大时批量拉取可以有效的提升查询性能。 + - batchErrorIgnore:true:在执行 Statement 的 executeBatch 时,如果中间有一条 SQL 执行失败将继续执行下面的 SQL。false:不再执行失败 SQL + 后的任何语句。默认值为:false。 -JDBC 原生连接的使用请参见[视频教程](https://www.taosdata.com/blog/2020/11/11/1955.html)。 + JDBC 原生连接的使用请参见[视频教程](https://www.taosdata.com/blog/2020/11/11/1955.html)。 -**使用 TDengine 客户端驱动配置文件建立连接 ** + **使用 TDengine 客户端驱动配置文件建立连接 ** -当使用 JDBC 原生连接连接 TDengine 集群时,可以使用 TDengine 客户端驱动配置文件,在配置文件中指定集群的 firstEp、secondEp 等参数。如下所示: + 当使用 JDBC 原生连接连接 TDengine 集群时,可以使用 TDengine 客户端驱动配置文件,在配置文件中指定集群的 firstEp、secondEp 等参数。如下所示: -1. 在 Java 应用中不指定 hostname 和 port + 1. 在 Java 应用中不指定 hostname 和 port -```java -public Connection getConn() throws Exception{ - Class.forName("com.taosdata.jdbc.TSDBDriver"); - String jdbcUrl = "jdbc:TAOS://:/test?user=root&password=taosdata"; - Properties connProps = new Properties(); - connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); - connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); - connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); - Connection conn = DriverManager.getConnection(jdbcUrl, connProps); - return conn; -} -``` + ```java + public Connection getConn() throws Exception{ + Class.forName("com.taosdata.jdbc.TSDBDriver"); + String jdbcUrl = "jdbc:TAOS://:/test?user=root&password=taosdata"; + Properties connProps = new Properties(); + connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8"); + connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8"); + connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8"); + Connection conn = DriverManager.getConnection(jdbcUrl, connProps); + return conn; + } + ``` -2. 在配置文件中指定 firstEp 和 secondEp + 2. 在配置文件中指定 firstEp 和 secondEp -```shell -# first fully qualified domain name (FQDN) for TDengine system -firstEp cluster_node1:6030 + ```shell + # first fully qualified domain name (FQDN) for TDengine system + firstEp cluster_node1:6030 -# second fully qualified domain name (FQDN) for TDengine system, for cluster only -secondEp cluster_node2:6030 + # second fully qualified domain name (FQDN) for TDengine system, for cluster only + secondEp cluster_node2:6030 -# default system charset -# charset UTF-8 + # default system charset + # charset UTF-8 -# system locale -# locale en_US.UTF-8 -``` + # system locale + # locale en_US.UTF-8 + ``` -以上示例,jdbc 会使用客户端的配置文件,建立到 hostname 为 cluster_node1、端口为 6030、数据库名为 test 的连接。当集群中 firstEp 节点失效时,JDBC 会尝试使用 secondEp 连接集群。 + 以上示例,jdbc 会使用客户端的配置文件,建立到 hostname 为 cluster_node1、端口为 6030、数据库名为 test 的连接。当集群中 firstEp 节点失效时,JDBC 会尝试使用 secondEp + 连接集群。 -TDengine 中,只要保证 firstEp 和 secondEp 中一个节点有效,就可以正常建立到集群的连接。 + TDengine 中,只要保证 firstEp 和 secondEp 中一个节点有效,就可以正常建立到集群的连接。 -> **注意**:这里的配置文件指的是调用 JDBC Connector 的应用程序所在机器上的配置文件,Linux OS 上默认值 /etc/taos/taos.cfg ,Windows OS 上默认值 C://TDengine/cfg/taos.cfg。 + > **注意**:这里的配置文件指的是调用 JDBC Connector 的应用程序所在机器上的配置文件,Linux OS 上默认值 /etc/taos/taos.cfg ,Windows OS 上默认值 + C://TDengine/cfg/taos.cfg。 - - + + -```java -Class.forName("com.taosdata.jdbc.rs.RestfulDriver"); -String jdbcUrl = "jdbc:TAOS-RS://taosdemo.com:6041/test?user=root&password=taosdata"; -Connection conn = DriverManager.getConnection(jdbcUrl); -``` + ```java + Class.forName("com.taosdata.jdbc.rs.RestfulDriver"); + String jdbcUrl = "jdbc:TAOS-RS://taosdemo.com:6041/test?user=root&password=taosdata"; + Connection conn = DriverManager.getConnection(jdbcUrl); + ``` -以上示例,使用了 JDBC REST 连接的 RestfulDriver,建立了到 hostname 为 taosdemo.com,端口为 6041,数据库名为 test 的连接。这个 URL 中指定用户名(user)为 root,密码(password)为 taosdata。 + 以上示例,使用了 JDBC REST 连接的 RestfulDriver,建立了到 hostname 为 taosdemo.com,端口为 6041,数据库名为 test 的连接。这个 URL 中指定用户名(user)为 + root,密码(password)为 taosdata。 -使用 JDBC REST 连接,不需要依赖客户端驱动。与 JDBC 原生连接相比,仅需要: + 使用 JDBC REST 连接,不需要依赖客户端驱动。与 JDBC 原生连接相比,仅需要: -1. driverClass 指定为“com.taosdata.jdbc.rs.RestfulDriver”; -2. jdbcUrl 以“jdbc:TAOS-RS://”开头; -3. 使用 6041 作为连接端口。 + 1. driverClass 指定为“com.taosdata.jdbc.rs.RestfulDriver”; + 2. jdbcUrl 以“jdbc:TAOS-RS://”开头; + 3. 使用 6041 作为连接端口。 -url 中的配置参数如下: + url 中的配置参数如下: -- user:登录 TDengine 用户名,默认值 'root'。 -- password:用户登录密码,默认值 'taosdata'。 -- batchfetch: true:在执行查询时批量拉取结果集;false:逐行拉取结果集。默认值为:false。逐行拉取结果集使用 HTTP 方式进行数据传输。JDBC REST 连接支持批量拉取数据功能。taos-jdbcdriver 与 TDengine 之间通过 WebSocket 连接进行数据传输。相较于 HTTP,WebSocket 可以使 JDBC REST 连接支持大数据量查询,并提升查询性能。 -- charset: 当开启批量拉取数据时,指定解析字符串数据的字符集。 -- batchErrorIgnore:true:在执行 Statement 的 executeBatch 时,如果中间有一条 SQL 执行失败,继续执行下面的 SQL 了。false:不再执行失败 SQL 后的任何语句。默认值为:false。 -- httpConnectTimeout: 连接超时时间,单位 ms, 默认值为 5000。 -- httpSocketTimeout: socket 超时时间,单位 ms,默认值为 5000。仅在 batchfetch 设置为 false 时生效。 -- messageWaitTimeout: 消息超时时间, 单位 ms, 默认值为 3000。 仅在 batchfetch 设置为 true 时生效。 -- useSSL: 连接中是否使用 SSL。 + - user:登录 TDengine 用户名,默认值 'root'。 + - password:用户登录密码,默认值 'taosdata'。 + - batchfetch: true:在执行查询时批量拉取结果集;false:逐行拉取结果集。默认值为:false。逐行拉取结果集使用 HTTP 方式进行数据传输。JDBC REST + 连接支持批量拉取数据功能。taos-jdbcdriver 与 TDengine 之间通过 WebSocket 连接进行数据传输。相较于 HTTP,WebSocket 可以使 JDBC REST 连接支持大数据量查询,并提升查询性能。 + - charset: 当开启批量拉取数据时,指定解析字符串数据的字符集。 + - batchErrorIgnore:true:在执行 Statement 的 executeBatch 时,如果中间有一条 SQL 执行失败,继续执行下面的 SQL 了。false:不再执行失败 SQL + 后的任何语句。默认值为:false。 + - httpConnectTimeout: 连接超时时间,单位 ms, 默认值为 5000。 + - httpSocketTimeout: socket 超时时间,单位 ms,默认值为 5000。仅在 batchfetch 设置为 false 时生效。 + - messageWaitTimeout: 消息超时时间, 单位 ms, 默认值为 3000。 仅在 batchfetch 设置为 true 时生效。 + - useSSL: 连接中是否使用 SSL。 -**注意**:部分配置项(比如:locale、timezone)在 REST 连接中不生效。 + **注意**:部分配置项(比如:locale、timezone)在 REST 连接中不生效。 -:::note + :::note -- 与原生连接方式不同,REST 接口是无状态的。在使用 JDBC REST 连接时,需要在 SQL 中指定表、超级表的数据库名称。例如: + - 与原生连接方式不同,REST 接口是无状态的。在使用 JDBC REST 连接时,需要在 SQL 中指定表、超级表的数据库名称。例如: -```sql -INSERT INTO test.t1 USING test.weather (ts, temperature) TAGS('California.SanFrancisco') VALUES(now, 24.6); -``` + ```sql + INSERT INTO test.t1 USING test.weather (ts, temperature) TAGS('California.SanFrancisco') VALUES(now, 24.6); + ``` -- 如果在 url 中指定了 dbname,那么,JDBC REST 连接会默认使用/rest/sql/dbname 作为 restful 请求的 url,在 SQL 中不需要指定 dbname。例如:url 为 jdbc:TAOS-RS://127.0.0.1:6041/test,那么,可以执行 sql:insert into t1 using weather(ts, temperature) tags('California.SanFrancisco') values(now, 24.6); + - 如果在 url 中指定了 dbname,那么,JDBC REST 连接会默认使用/rest/sql/dbname 作为 restful 请求的 url,在 SQL 中不需要指定 dbname。例如:url 为 + jdbc:TAOS-RS://127.0.0.1:6041/test,那么,可以执行 sql:insert into t1 using weather(ts, temperature) + tags('California.SanFrancisco') values(now, 24.6); -::: + ::: - + ### 指定 URL 和 Properties 获取连接 @@ -271,7 +281,7 @@ properties 中的配置参数如下: - TSDBDriver.HTTP_SOCKET_TIMEOUT: socket 超时时间,单位 ms,默认值为 5000。仅在 REST 连接且 batchfetch 设置为 false 时生效。 - TSDBDriver.PROPERTY_KEY_MESSAGE_WAIT_TIMEOUT: 消息超时时间, 单位 ms, 默认值为 3000。 仅在 REST 连接且 batchfetch 设置为 true 时生效。 - TSDBDriver.PROPERTY_KEY_USE_SSL: 连接中是否使用 SSL。仅在 REST 连接时生效。 - 此外对 JDBC 原生连接,通过指定 URL 和 Properties 还可以指定其他参数,比如日志级别、SQL 长度等。更多详细配置请参考[客户端配置](/reference/config/#仅客户端适用)。 +此外对 JDBC 原生连接,通过指定 URL 和 Properties 还可以指定其他参数,比如日志级别、SQL 长度等。更多详细配置请参考[客户端配置](/reference/config/#仅客户端适用)。 ### 配置参数的优先级 @@ -826,7 +836,7 @@ public abstract class ConsumerLoop { //query or insert // ... - connection.close(); // put back to conneciton pool + connection.close(); // put back to connection pool } ``` @@ -858,7 +868,7 @@ public static void main(String[] args) throws Exception { //query or insert // ... - connection.close(); // put back to conneciton pool + connection.close(); // put back to connection pool } ``` @@ -880,7 +890,9 @@ public static void main(String[] args) throws Exception { | taos-jdbcdriver 版本 | 主要变化 | | :------------------: | :----------------------------: | +| 3.0.1 - 3.0.2 | 修复一些情况下结果集数据解析错误的问题。3.0.1 在 JDK 11 环境编译,JDK 8 环境下建议使用 3.0.2 版本 | | 3.0.0 | 支持 TDengine 3.0 | +| 2.0.41 | 修正 REST 连接中用户名和密码转码方式 | | 2.0.39 - 2.0.40 | 增加 REST 连接/请求 超时设置 | | 2.0.38 | JDBC REST 连接增加批量拉取功能 | | 2.0.37 | 增加对 json tag 支持 | @@ -890,27 +902,33 @@ public static void main(String[] args) throws Exception { 1. 使用 Statement 的 `addBatch()` 和 `executeBatch()` 来执行“批量写入/更新”,为什么没有带来性能上的提升? - **原因**:TDengine 的 JDBC 实现中,通过 `addBatch` 方法提交的 SQL 语句,会按照添加的顺序,依次执行,这种方式没有减少与服务端的交互次数,不会带来性能上的提升。 +**原因**:TDengine 的 JDBC 实现中,通过 `addBatch` 方法提交的 SQL 语句,会按照添加的顺序,依次执行,这种方式没有减少与服务端的交互次数,不会带来性能上的提升。 - **解决方法**:1. 在一条 insert 语句中拼接多个 values 值;2. 使用多线程的方式并发插入;3. 使用参数绑定的写入方式 +**解决方法**:1. 在一条 insert 语句中拼接多个 values 值;2. 使用多线程的方式并发插入;3. 使用参数绑定的写入方式 2. java.lang.UnsatisfiedLinkError: no taos in java.library.path - **原因**:程序没有找到依赖的本地函数库 taos。 +**原因**:程序没有找到依赖的本地函数库 taos。 - **解决方法**:Windows 下可以将 C:\TDengine\driver\taos.dll 拷贝到 C:\Windows\System32\ 目录下,Linux 下将建立如下软链 `ln -s /usr/local/taos/driver/libtaos.so.x.x.x.x /usr/lib/libtaos.so` 即可,macOS 下需要建立软链 `ln -s /usr/local/lib/libtaos.dylib`。 +**解决方法**:Windows 下可以将 C:\TDengine\driver\taos.dll 拷贝到 C:\Windows\System32\ 目录下,Linux 下将建立如下软链 `ln -s /usr/local/taos/driver/libtaos.so.x.x.x.x /usr/lib/libtaos.so` 即可,macOS 下需要建立软链 `ln -s /usr/local/lib/libtaos.dylib`。 3. java.lang.UnsatisfiedLinkError: taos.dll Can't load AMD 64 bit on a IA 32-bit platform - **原因**:目前 TDengine 只支持 64 位 JDK。 +**原因**:目前 TDengine 只支持 64 位 JDK。 - **解决方法**:重新安装 64 位 JDK。 +**解决方法**:重新安装 64 位 JDK。 4. java.lang.NoSuchMethodError: setByteArray - **原因**:taos-jdbcdriver 3.* 版本仅支持 TDengine 3.0 及以上版本。 +**原因**:taos-jdbcdriver 3.* 版本仅支持 TDengine 3.0 及以上版本。 + +**解决方法**: 使用 taos-jdbcdriver 2.* 版本连接 TDengine 2.* 版本。 + +5. java.lang.NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer; ... taos-jdbcdriver-3.0.1.jar + +**原因**:taos-jdbcdriver 3.0.1 版本需要在 JDK 11+ 环境使用。 - **解决方法**: 使用 taos-jdbcdriver 2.* 版本连接 TDengine 2.* 版本。 +**解决方法**: 更换 taos-jdbcdriver 3.0.2 版本。 其它问题请参考 [FAQ](../../../train-faq/faq) diff --git a/docs/zh/08-connector/20-go.mdx b/docs/zh/08-connector/20-go.mdx index 7a6058db3c60f876b850e78e8dcb76e1be6b4f15..0fc4007f6362697222b425c8c2c803b911b9ac8a 100644 --- a/docs/zh/08-connector/20-go.mdx +++ b/docs/zh/08-connector/20-go.mdx @@ -8,7 +8,7 @@ title: TDengine Go Connector import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; -import Preparition from "./_preparition.mdx" +import Preparation from "./_preparation.mdx" import GoInsert from "../07-develop/03-insert-data/_go_sql.mdx" import GoInfluxLine from "../07-develop/03-insert-data/_go_line.mdx" import GoOpenTSDBTelnet from "../07-develop/03-insert-data/_go_opts_telnet.mdx" @@ -389,7 +389,7 @@ func main() { * `func (conn *Connector) InfluxDBInsertLines(lines []string, precision string) error` - 写入 influxDB 行协议。 + 写入 InfluxDB 行协议。 * `func (conn *Connector) OpenTSDBInsertTelnetLines(lines []string) error` @@ -465,6 +465,54 @@ func main() { 完整订阅示例参见 [GitHub 示例文件](https://github.com/taosdata/driver-go/blob/3.0/examples/tmqoverws/main.go) +### 通过 WebSocket 进行参数绑定 + +* `func NewConnector(config *Config) (*Connector, error)` + + 创建连接。 + +* `func (c *Connector) Init() (*Stmt, error)` + + 初始化参数。 + +* `func (c *Connector) Close() error` + + 关闭连接。 + +* `func (s *Stmt) Prepare(sql string) error` + + 参数绑定预处理 SQL 语句。 + +* `func (s *Stmt) SetTableName(name string) error` + + 参数绑定设置表名。 + +* `func (s *Stmt) SetTags(tags *param.Param, bindType *param.ColumnType) error` + + 参数绑定设置标签。 + +* `func (s *Stmt) BindParam(params []*param.Param, bindType *param.ColumnType) error` + + 参数绑定多行数据。 + +* `func (s *Stmt) AddBatch() error` + + 添加到参数绑定批处理。 + +* `func (s *Stmt) Exec() error` + + 执行参数绑定。 + +* `func (s *Stmt) GetAffectedRows() int` + + 获取参数绑定插入受影响行数。 + +* `func (s *Stmt) Close() error` + + 结束参数绑定。 + +完整参数绑定示例参见 [GitHub 示例文件](https://github.com/taosdata/driver-go/blob/3.0/examples/stmtoverws/main.go) + ## API 参考 全部 API 见 [driver-go 文档](https://pkg.go.dev/github.com/taosdata/driver-go/v3) diff --git a/docs/zh/08-connector/26-rust.mdx b/docs/zh/08-connector/26-rust.mdx index 63dce4b69b7a66c0888f306b72fd87b45e4c5bf3..eeb93a6558b755a6c179ecea86aae8b594fd16fe 100644 --- a/docs/zh/08-connector/26-rust.mdx +++ b/docs/zh/08-connector/26-rust.mdx @@ -7,7 +7,7 @@ title: TDengine Rust Connector import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; -import Preparition from "./_preparition.mdx" +import Preparation from "./_preparation.mdx" import RustInsert from "../07-develop/03-insert-data/_rust_sql.mdx" import RustBind from "../07-develop/03-insert-data/_rust_stmt.mdx" import RustQuery from "../07-develop/04-query-data/_rust.mdx" diff --git a/docs/zh/08-connector/35-node.mdx b/docs/zh/08-connector/35-node.mdx index 1de19cdd3a39b178f0ce9755f332fbfae6fe70f1..35c28e3b9fc52698b813e65191732d3dd84c336e 100644 --- a/docs/zh/08-connector/35-node.mdx +++ b/docs/zh/08-connector/35-node.mdx @@ -7,7 +7,7 @@ title: TDengine Node.js Connector import Tabs from "@theme/Tabs"; import TabItem from "@theme/TabItem"; -import Preparition from "./_preparition.mdx"; +import Preparation from "./_preparation.mdx"; import NodeInsert from "../07-develop/03-insert-data/_js_sql.mdx"; import NodeInfluxLine from "../07-develop/03-insert-data/_js_line.mdx"; import NodeOpenTSDBTelnet from "../07-develop/03-insert-data/_js_opts_telnet.mdx"; @@ -249,4 +249,4 @@ Node.js 连接器的使用参见[视频教程](https://www.taosdata.com/blog/202 ## API 参考 -[API 参考](https://docs.taosdata.com/api/td2.0-connector/) \ No newline at end of file +[API 参考](https://docs.taosdata.com/api/td2.0-connector/) diff --git a/docs/zh/08-connector/40-csharp.mdx b/docs/zh/08-connector/40-csharp.mdx index 70c0382080cde6bc0ca942dc15cc142ed0dfd833..a1a161d4eea9e2534ebb3a573211dcfae5dbb21f 100644 --- a/docs/zh/08-connector/40-csharp.mdx +++ b/docs/zh/08-connector/40-csharp.mdx @@ -7,7 +7,7 @@ title: C# Connector import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; -import Preparition from "./_preparition.mdx" +import Preparation from "./_preparation.mdx" import CSInsert from "../07-develop/03-insert-data/_cs_sql.mdx" import CSInfluxLine from "../07-develop/03-insert-data/_cs_line.mdx" import CSOpenTSDBTelnet from "../07-develop/03-insert-data/_cs_opts_telnet.mdx" diff --git a/docs/zh/08-connector/_preparition.mdx b/docs/zh/08-connector/_preparation.mdx similarity index 100% rename from docs/zh/08-connector/_preparition.mdx rename to docs/zh/08-connector/_preparation.mdx diff --git a/docs/zh/10-deployment/01-deploy.md b/docs/zh/10-deployment/01-deploy.md index eecb86ce415b6ad0a24a7fcd0d6d9d9ce1357a33..b68bf7b743c8f5ee8b8a0b91919d2399cbd6bc3e 100644 --- a/docs/zh/10-deployment/01-deploy.md +++ b/docs/zh/10-deployment/01-deploy.md @@ -190,3 +190,16 @@ DROP DNODE dnodeId; dnodeID 是集群自动分配的,不得人工指定。它在生成时是递增的,不会重复。 ::: + +## 常见问题 + +1、建立集群时使用 CREATE DNODE 增加新节点后,新节点始终显示 offline 状态? +```sql + 1)首先要检查增加的新节点上的 taosd 服务是否已经正常启动 + + 2)如果已经启动,再检查到新节点的网络是否通畅,可以使用 ping fqdn 验证下 + + 3)如果前面两步都没有问题,这一步要检查新节点做为独立集群在运行了,可以使用 taos -h fqdn 连接上后,show dnodes; 命令查看. + 如果显示的列表与你主节点上显示的不一致,说明此节点自己单独成立了一个集群,解决的方法是停止新节点上的服务,然后清空新节点上 + taos.cfg 中配置的 dataDir 目录下的所有文件,重新启动新节点服务即可解决。 +``` diff --git a/docs/zh/12-taos-sql/03-table.md b/docs/zh/12-taos-sql/03-table.md index f6790e3c692b815c1031413933c47eb7ad203204..045abcde95e04cb4009dea9de597339c25fe36b0 100644 --- a/docs/zh/12-taos-sql/03-table.md +++ b/docs/zh/12-taos-sql/03-table.md @@ -9,12 +9,12 @@ description: 对表的各种管理操作 `CREATE TABLE` 语句用于创建普通表和以超级表为模板创建子表。 ```sql -CREATE TABLE [IF NOT EXISTS] [db_name.]tb_name (create_definition [, create_definitionn] ...) [table_options] +CREATE TABLE [IF NOT EXISTS] [db_name.]tb_name (create_definition [, create_definition] ...) [table_options] CREATE TABLE create_subtable_clause -CREATE TABLE [IF NOT EXISTS] [db_name.]tb_name (create_definition [, create_definitionn] ...) - [TAGS (create_definition [, create_definitionn] ...)] +CREATE TABLE [IF NOT EXISTS] [db_name.]tb_name (create_definition [, create_definition] ...) + [TAGS (create_definition [, create_definition] ...)] [table_options] create_subtable_clause: { diff --git a/docs/zh/12-taos-sql/04-stable.md b/docs/zh/12-taos-sql/04-stable.md index 7dff30e443fce4d7a375c6d6c7b1f31a20768489..bd32da68aecc4c42be110e7716c1b2b4ebdab37c 100644 --- a/docs/zh/12-taos-sql/04-stable.md +++ b/docs/zh/12-taos-sql/04-stable.md @@ -7,7 +7,7 @@ description: 对超级表的各种管理操作 ## 创建超级表 ```sql -CREATE STABLE [IF NOT EXISTS] stb_name (create_definition [, create_definitionn] ...) TAGS (create_definition [, create_definition] ...) [table_options] +CREATE STABLE [IF NOT EXISTS] stb_name (create_definition [, create_definition] ...) TAGS (create_definition [, create_definition] ...) [table_options] create_definition: col_name column_definition diff --git a/docs/zh/12-taos-sql/06-select.md b/docs/zh/12-taos-sql/06-select.md index 3ffc081cd723c4511c913bd6e7c517cbdc2aedb5..9d4faae23a82fb8b328fe0df39c82789a7cc2ad2 100644 --- a/docs/zh/12-taos-sql/06-select.md +++ b/docs/zh/12-taos-sql/06-select.md @@ -224,7 +224,7 @@ GROUP BY 子句中的表达式可以包含表或视图中的任何列,这些 该子句对行进行分组,但不保证结果集的顺序。若要对分组进行排序,请使用 ORDER BY 子句 -## PARTITON BY +## PARTITION BY PARTITION BY 子句是 TDengine 特色语法,按 part_list 对数据进行切分,在每个切分的分片中进行计算。 @@ -315,6 +315,39 @@ WHERE (column|tbname) **match/MATCH/nmatch/NMATCH** _regex_ 正则匹配字符串长度不能超过 128 字节。可以通过参数 _maxRegexStringLen_ 设置和调整最大允许的正则匹配字符串,该参数是客户端配置参数,需要重启才能生效。 +## CASE 表达式 + +### 语法 + +```txt +CASE value WHEN compare_value THEN result [WHEN compare_value THEN result ...] [ELSE result] END +CASE WHEN condition THEN result [WHEN condition THEN result ...] [ELSE result] END +``` + +### 说明 + +TDengine 通过 CASE 表达式让用户可以在 SQL 语句中使用 IF ... THEN ... ELSE 逻辑。 + +第一种 CASE 语法返回第一个 value 等于 compare_value 的 result,如果没有 compare_value 符合,则返回 ELSE 之后的 result,如果没有 ELSE 部分,则返回 NULL。 + +第二种语法返回第一个 condition 为真的 result。 如果没有 condition 符合,则返回 ELSE 之后的 result,如果没有 ELSE 部分,则返回 NULL。 + +CASE 表达式的返回类型为第一个 WHEN THEN 部分的 result 类型,其余 WHEN THEN 部分和 ELSE 部分,result 类型都需要可以向其转换,否则 TDengine 会报错。 + +### 示例 + +某设备有三个状态码,显示其状态,语句如下: + +```sql +SELECT CASE dev_status WHEN 1 THEN 'Running' WHEN 2 THEN 'Warning' WHEN 3 THEN 'Downtime' ELSE 'Unknown' END FROM dev_table; +``` + +统计智能电表的电压平均值,当电压小于 200 或大于 250 时认为是统计有误,修正其值为 220,语句如下: + +```sql +SELECT AVG(CASE WHEN voltage < 200 or voltage > 250 THEN 220 ELSE voltage END) FROM meters; +``` + ## JOIN 子句 TDengine 支持“普通表与普通表之间”、“超级表与超级表之间”、“子查询与子查询之间” 进行自然连接。自然连接与内连接的主要区别是,自然连接要求参与连接的字段在不同的表/超级表中必须是同名字段。也即,TDengine 在连接关系的表达中,要求必须使用同名数据列/标签列的相等关系。 diff --git a/docs/zh/12-taos-sql/12-distinguished.md b/docs/zh/12-taos-sql/12-distinguished.md index ee8e8e15cacc0fef8ef5a5dc370f4f58de710230..d36c852e7975dbe602166d8c7d12027043c2e302 100644 --- a/docs/zh/12-taos-sql/12-distinguished.md +++ b/docs/zh/12-taos-sql/12-distinguished.md @@ -119,6 +119,12 @@ SELECT COUNT(*), FIRST(ts), status FROM temp_tb_1 STATE_WINDOW(status); SELECT * FROM (SELECT COUNT(*) AS cnt, FIRST(ts) AS fst, status FROM temp_tb_1 STATE_WINDOW(status)) t WHERE status = 2; ``` +TDengine 还支持将 CASE 表达式用在状态量,可以表达某个状态的开始是由满足某个条件而触发,这个状态的结束是由另外一个条件满足而触发的语义。例如,智能电表的电压正常范围是 205V 到 235V,那么可以通过监控电压来判断电路是否正常。 + +``` +SELECT tbname, _wstart, CASE WHEN voltage >= 205 and voltage <= 235 THEN 1 ELSE 0 END status FROM meters PARTITION BY tbname STATE_WINDOW(CASE WHEN voltage >= 205 and voltage <= 235 THEN 1 ELSE 0 END); +``` + ### 会话窗口 会话窗口根据记录的时间戳主键的值来确定是否属于同一个会话。如下图所示,如果设置时间戳的连续的间隔小于等于 12 秒,则以下 6 条记录构成 2 个会话窗口,分别是:[2019-04-28 14:22:10,2019-04-28 14:22:30]和[2019-04-28 14:23:10,2019-04-28 14:23:30]。因为 2019-04-28 14:22:30 与 2019-04-28 14:23:10 之间的时间间隔是 40 秒,超过了连续时间间隔(12 秒)。 diff --git a/docs/zh/12-taos-sql/24-show.md b/docs/zh/12-taos-sql/24-show.md index ef0c8b90edfe671cc39371a65aa8725748d91977..4bd1e52284f46d94cfd892c82a7fbe119b685532 100644 --- a/docs/zh/12-taos-sql/24-show.md +++ b/docs/zh/12-taos-sql/24-show.md @@ -201,7 +201,7 @@ SHOW TOPICS; SHOW TRANSACTIONS; ``` -显示当前系统中正在执行的事务的信息 +显示当前系统中正在执行的事务的信息(该事务仅针对除普通表以外的元数据级别) ## SHOW USERS @@ -211,10 +211,10 @@ SHOW USERS; 显示当前系统中所有用户的信息。包括用户自定义的用户和系统默认用户。 -## SHOW VARIABLES +## SHOW CLUSTER VARIABLES(3.0.1.6 之前为 SHOW VARIABLES) ```sql -SHOW VARIABLES; +SHOW CLUSTER VARIABLES; SHOW DNODE dnode_id VARIABLES; ``` diff --git a/docs/zh/14-reference/05-taosbenchmark.md b/docs/zh/14-reference/05-taosbenchmark.md index afc050298f3be6c09fa0c09fbc3ba678cdd2e89d..76dd5f12d89b223292a8c868fd66135ec204319b 100644 --- a/docs/zh/14-reference/05-taosbenchmark.md +++ b/docs/zh/14-reference/05-taosbenchmark.md @@ -217,7 +217,7 @@ taosBenchmark -A INT,DOUBLE,NCHAR,BINARY\(16\) 本节所列参数适用于所有功能模式。 - **filetype** : 要测试的功能,可选值为 `insert`, `query` 和 `subscribe`。分别对应插入、查询和订阅功能。每个配置文件中只能指定其中之一。 -- **cfgdir** : TDengine 集群配置文件所在的目录,默认路径是 /etc/taos 。 +- **cfgdir** : TDengine 客户端配置文件所在的目录,默认路径是 /etc/taos 。 - **host** : 指定要连接的 TDengine 服务端的 FQDN,默认值为 localhost。 @@ -374,7 +374,11 @@ taosBenchmark -A INT,DOUBLE,NCHAR,BINARY\(16\) ### 查询场景配置参数 -查询场景下 `filetype` 必须设置为 `query`,该参数及其它通用参数详见[通用配置参数](#通用配置参数) +查询场景下 `filetype` 必须设置为 `query`。 + +查询场景可以通过设置 `kill_slow_query_threshold` 和 `kill_slow_query_interval` 参数来控制杀掉慢查询语句的执行,threshold 控制如果 exec_usec 超过指定时间的查询将被 taosBenchmark 杀掉,单位为秒;interval 控制休眠时间,避免持续查询慢查询消耗 CPU ,单位为秒。 + +其它通用参数详见[通用配置参数](#通用配置参数)。 #### 执行指定查询语句的配置参数 diff --git a/docs/zh/14-reference/12-config/index.md b/docs/zh/14-reference/12-config/index.md index 74af793f9f7a6a5d0fb08a6b4980ed95c111ebf8..145c5eed935568f013d4451cd590c8b745b165c5 100644 --- a/docs/zh/14-reference/12-config/index.md +++ b/docs/zh/14-reference/12-config/index.md @@ -711,19 +711,17 @@ charset 的有效值是 UTF-8。 | 44 | numOfVnodeQueryThreads | 否 | 是 | | | 45 | numOfVnodeStreamThreads | 否 | 是 | | | 46 | numOfVnodeFetchThreads | 否 | 是 | | -| 47 | numOfVnodeWriteThreads | 否 | 是 | | -| 48 | numOfVnodeSyncThreads | 否 | 是 | | -| 49 | numOfVnodeRsmaThreads | 否 | 是 | | -| 50 | numOfQnodeQueryThreads | 否 | 是 | | -| 51 | numOfQnodeFetchThreads | 否 | 是 | | -| 52 | numOfSnodeSharedThreads | 否 | 是 | | -| 53 | numOfSnodeUniqueThreads | 否 | 是 | | -| 54 | rpcQueueMemoryAllowed | 否 | 是 | | -| 55 | logDir | 是 | 是 | | -| 56 | minimalLogDirGB | 是 | 是 | | -| 57 | numOfLogLines | 是 | 是 | | -| 58 | asyncLog | 是 | 是 | | -| 59 | logKeepDays | 是 | 是 | | +| 47 | numOfVnodeRsmaThreads | 否 | 是 | | +| 48 | numOfQnodeQueryThreads | 否 | 是 | | +| 49 | numOfQnodeFetchThreads | 否 | 是 | | +| 50 | numOfSnodeSharedThreads | 否 | 是 | | +| 51 | numOfSnodeUniqueThreads | 否 | 是 | | +| 52 | rpcQueueMemoryAllowed | 否 | 是 | | +| 53 | logDir | 是 | 是 | | +| 54 | minimalLogDirGB | 是 | 是 | | +| 55 | numOfLogLines | 是 | 是 | | +| 56 | asyncLog | 是 | 是 | | +| 57 | logKeepDays | 是 | 是 | | | 60 | debugFlag | 是 | 是 | | | 61 | tmrDebugFlag | 是 | 是 | | | 62 | uDebugFlag | 是 | 是 | | diff --git a/docs/zh/28-releases/01-tdengine.md b/docs/zh/28-releases/01-tdengine.md index a5b35342508d2e9f234bdf9fb9daae48ee3e90c7..31093ce5577b804dcc66978b2f13baa8c207795d 100644 --- a/docs/zh/28-releases/01-tdengine.md +++ b/docs/zh/28-releases/01-tdengine.md @@ -6,6 +6,10 @@ description: TDengine 发布历史、Release Notes 及下载链接 import Release from "/components/ReleaseV3"; +## 3.0.1.6 + + + ## 3.0.1.5 diff --git a/docs/zh/28-releases/02-tools.md b/docs/zh/28-releases/02-tools.md index e86481435c1a9cc8c7c99fdae11464fcb4d87caf..2623391fb90c1ac7b12c8017c93fa57324e1981b 100644 --- a/docs/zh/28-releases/02-tools.md +++ b/docs/zh/28-releases/02-tools.md @@ -6,6 +6,10 @@ description: taosTools 的发布历史、Release Notes 和下载链接 import Release from "/components/ReleaseV3"; +## 2.2.7 + + + ## 2.2.6 diff --git a/examples/c/CMakeLists.txt b/examples/c/CMakeLists.txt index 4a9007acecaa679dc716c5665eea7f0cd1e34dbb..37edc739e47b88236ee98c3ef0f1185c622abf9d 100644 --- a/examples/c/CMakeLists.txt +++ b/examples/c/CMakeLists.txt @@ -15,6 +15,7 @@ IF (TD_LINUX) add_executable(tmq "") add_executable(stream_demo "") add_executable(demoapi "") + add_executable(api_reqid "") target_sources(tmq PRIVATE @@ -31,6 +32,12 @@ IF (TD_LINUX) "demoapi.c" ) + target_sources(api_reqid + PRIVATE + "api_with_reqid_test.c" + ) + + target_link_libraries(tmq taos_static ) @@ -43,6 +50,11 @@ IF (TD_LINUX) taos_static ) + target_link_libraries(api_reqid + taos_static + ) + + target_include_directories(tmq PUBLIC "${TD_SOURCE_DIR}/include/os" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" @@ -58,9 +70,16 @@ IF (TD_LINUX) PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) + target_include_directories(api_reqid + PUBLIC "${TD_SOURCE_DIR}/include/client" + PUBLIC "${TD_SOURCE_DIR}/include/os" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" + ) + SET_TARGET_PROPERTIES(tmq PROPERTIES OUTPUT_NAME tmq) SET_TARGET_PROPERTIES(stream_demo PROPERTIES OUTPUT_NAME stream_demo) SET_TARGET_PROPERTIES(demoapi PROPERTIES OUTPUT_NAME demoapi) + SET_TARGET_PROPERTIES(api_reqid PROPERTIES OUTPUT_NAME api_reqid) ENDIF () IF (TD_DARWIN) INCLUDE_DIRECTORIES(. ${TD_SOURCE_DIR}/src/inc ${TD_SOURCE_DIR}/src/client/inc ${TD_SOURCE_DIR}/inc) diff --git a/examples/c/api_with_reqid_test.c b/examples/c/api_with_reqid_test.c new file mode 100644 index 0000000000000000000000000000000000000000..003639ba0005e55ab3446451c02e28356adfca7b --- /dev/null +++ b/examples/c/api_with_reqid_test.c @@ -0,0 +1,449 @@ +// sample code to verify all TDengine API +// to compile: gcc -o apitest apitest.c -ltaos + +#include +#include +#include +#include +#include "taos.h" +static int64_t count = 10000; + +int64_t genReqid() { + count += 100; + return count; +} +static void prepare_data(TAOS* taos) { + TAOS_RES* result; + result = taos_query_with_reqid(taos, "drop database if exists test;", genReqid()); + taos_free_result(result); + usleep(100000); + result = taos_query_with_reqid(taos, "create database test precision 'us';", genReqid()); + taos_free_result(result); + usleep(100000); + taos_select_db(taos, "test"); + + result = taos_query_with_reqid(taos, "create table meters(ts timestamp, a int) tags(area int);", genReqid()); + taos_free_result(result); + + result = taos_query_with_reqid(taos, "create table t0 using meters tags(0);", genReqid()); + taos_free_result(result); + result = taos_query_with_reqid(taos, "create table t1 using meters tags(1);", genReqid()); + taos_free_result(result); + result = taos_query_with_reqid(taos, "create table t2 using meters tags(2);", genReqid()); + taos_free_result(result); + result = taos_query_with_reqid(taos, "create table t3 using meters tags(3);", genReqid()); + taos_free_result(result); + result = taos_query_with_reqid(taos, "create table t4 using meters tags(4);", genReqid()); + taos_free_result(result); + result = taos_query_with_reqid(taos, "create table t5 using meters tags(5);", genReqid()); + taos_free_result(result); + result = taos_query_with_reqid(taos, "create table t6 using meters tags(6);", genReqid()); + taos_free_result(result); + result = taos_query_with_reqid(taos, "create table t7 using meters tags(7);", genReqid()); + taos_free_result(result); + result = taos_query_with_reqid(taos, "create table t8 using meters tags(8);", genReqid()); + taos_free_result(result); + result = taos_query(taos, "create table t9 using meters tags(9);"); + taos_free_result(result); + + result = taos_query_with_reqid(taos, + "insert into t0 values('2020-01-01 00:00:00.000', 0)" + " ('2020-01-01 00:01:00.000', 0)" + " ('2020-01-01 00:02:00.000', 0)" + " t1 values('2020-01-01 00:00:00.000', 0)" + " ('2020-01-01 00:01:00.000', 0)" + " ('2020-01-01 00:02:00.000', 0)" + " ('2020-01-01 00:03:00.000', 0)" + " t2 values('2020-01-01 00:00:00.000', 0)" + " ('2020-01-01 00:01:00.000', 0)" + " ('2020-01-01 00:01:01.000', 0)" + " ('2020-01-01 00:01:02.000', 0)" + " t3 values('2020-01-01 00:01:02.000', 0)" + " t4 values('2020-01-01 00:01:02.000', 0)" + " t5 values('2020-01-01 00:01:02.000', 0)" + " t6 values('2020-01-01 00:01:02.000', 0)" + " t7 values('2020-01-01 00:01:02.000', 0)" + " t8 values('2020-01-01 00:01:02.000', 0)" + " t9 values('2020-01-01 00:01:02.000', 0)", + genReqid()); + int affected = taos_affected_rows(result); + if (affected != 18) { + printf("\033[31m%d rows affected by last insert statement, but it should be 18\033[0m\n", affected); + } + taos_free_result(result); + // super tables subscription + usleep(1000000); +} + +static int print_result(TAOS_RES* res, int blockFetch) { + TAOS_ROW row = NULL; + int num_fields = taos_num_fields(res); + TAOS_FIELD* fields = taos_fetch_fields(res); + int nRows = 0; + + if (blockFetch) { + int rows = 0; + while ((rows = taos_fetch_block(res, &row))) { + // for (int i = 0; i < rows; i++) { + // char temp[256]; + // taos_print_row(temp, row + i, fields, num_fields); + // puts(temp); + // } + nRows += rows; + } + } else { + while ((row = taos_fetch_row(res))) { + char temp[256] = {0}; + taos_print_row(temp, row, fields, num_fields); + puts(temp); + nRows++; + } + } + + printf("%d rows consumed.\n", nRows); + return nRows; +} + +static void check_row_count(int line, TAOS_RES* res, int expected) { + int actual = print_result(res, expected % 2); + if (actual != expected) { + printf("\033[31mline %d: row count mismatch, expected: %d, actual: %d\033[0m\n", line, expected, actual); + } else { + printf("line %d: %d rows consumed as expected\n", line, actual); + } +} + +static void verify_query(TAOS* taos) { + prepare_data(taos); + + int code = taos_load_table_info(taos, "t0,t1,t2,t3,t4,t5,t6,t7,t8,t9"); + if (code != 0) { + printf("\033[31mfailed to load table info: 0x%08x\033[0m\n", code); + } + + code = taos_validate_sql(taos, "select * from nonexisttable"); + if (code == 0) { + printf("\033[31mimpossible, the table does not exists\033[0m\n"); + } + + code = taos_validate_sql(taos, "select * from meters"); + if (code != 0) { + printf("\033[31mimpossible, the table does exists: 0x%08x\033[0m\n", code); + } + + TAOS_RES* res = taos_query_with_reqid(taos, "select * from meters", genReqid()); + check_row_count(__LINE__, res, 18); + printf("result precision is: %d\n", taos_result_precision(res)); + int c = taos_field_count(res); + printf("field count is: %d\n", c); + int* lengths = taos_fetch_lengths(res); + for (int i = 0; i < c; i++) { + printf("length of column %d is %d\n", i, lengths[i]); + } + taos_free_result(res); + + res = taos_query_with_reqid(taos, "select * from t0", genReqid()); + check_row_count(__LINE__, res, 3); + taos_free_result(res); + + res = taos_query_with_reqid(taos, "select * from nonexisttable", genReqid()); + code = taos_errno(res); + printf("code=%d, error msg=%s\n", code, taos_errstr(res)); + taos_free_result(res); + + res = taos_query_with_reqid(taos, "select * from meters", genReqid()); + taos_stop_query(res); + taos_free_result(res); +} + +void retrieve_callback(void* param, TAOS_RES* tres, int numOfRows) { + if (numOfRows > 0) { + printf("%d rows async retrieved\n", numOfRows); + taos_fetch_rows_a(tres, retrieve_callback, param); + } else { + if (numOfRows < 0) { + printf("\033[31masync retrieve failed, code: %d\033[0m\n", numOfRows); + } else { + printf("async retrieve completed\n"); + } + taos_free_result(tres); + } +} + +void select_callback(void* param, TAOS_RES* tres, int code) { + if (code == 0 && tres) { + taos_fetch_rows_a(tres, retrieve_callback, param); + } else { + printf("\033[31masync select failed, code: %d\033[0m\n", code); + } +} + +void verify_async(TAOS* taos) { + prepare_data(taos); + taos_query_a_with_reqid(taos, "select * from meters", select_callback, NULL, genReqid()); + usleep(1000000); +} + +int32_t verify_schema_less(TAOS* taos) { + TAOS_RES* result; + result = taos_query_with_reqid(taos, "drop database if exists test;", genReqid()); + taos_free_result(result); + usleep(100000); + result = taos_query_with_reqid(taos, "create database test precision 'us' update 1;", genReqid()); + taos_free_result(result); + usleep(100000); + + taos_select_db(taos, "test"); + result = taos_query_with_reqid(taos, "create stable ste(ts timestamp, f int) tags(t1 bigint)", genReqid()); + taos_free_result(result); + usleep(100000); + + int code = 0; + + char* lines[] = { + "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns", + "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns", + "ste,t2=5f64,t3=L\"ste\" c1=true,c2=4i64,c3=\"iam\" 1626056811823316532ns", + "st,t1=4i64,t2=5f64,t3=\"t4\" c1=3i64,c3=L\"passitagain\",c2=true,c4=5f64 1626006833642000000ns", + "ste,t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false 1626056811843316532ns", + "ste,t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false,c5=32i8,c6=64i16,c7=32i32,c8=88.88f32 1626056812843316532ns", + "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 " + "1626006933640000000ns", + "stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 " + "1626006933640000000ns", + "stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 " + "1626006933641000000ns"}; + + taos_select_db(taos, "test"); + + TAOS_RES* res = taos_schemaless_insert_with_reqid(taos, lines, sizeof(lines) / sizeof(char*), TSDB_SML_LINE_PROTOCOL, + TSDB_SML_TIMESTAMP_NOT_CONFIGURED, genReqid()); + if (taos_errno(res) != 0) { + printf("failed to insert schema-less data, reason: %s\n", taos_errstr(res)); + } else { + int affectedRow = taos_affected_rows(res); + printf("successfully inserted %d rows\n", affectedRow); + } + taos_free_result(res); + + return (code); +} + +void veriry_stmt(TAOS* taos) { + TAOS_RES* result = taos_query(taos, "drop database if exists test;"); + taos_free_result(result); + usleep(100000); + result = taos_query(taos, "create database test;"); + + int code = taos_errno(result); + if (code != 0) { + printf("\033[31mfailed to create database, reason:%s\033[0m\n", taos_errstr(result)); + taos_free_result(result); + return; + } + taos_free_result(result); + + usleep(100000); + taos_select_db(taos, "test"); + + // create table + const char* sql = + "create table m1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin " + "binary(40), blob nchar(10))"; + result = taos_query(taos, sql); + code = taos_errno(result); + if (code != 0) { + printf("\033[31mfailed to create table, reason:%s\033[0m\n", taos_errstr(result)); + taos_free_result(result); + return; + } + taos_free_result(result); + + // insert 10 records + struct { + int64_t ts[10]; + int8_t b[10]; + int8_t v1[10]; + int16_t v2[10]; + int32_t v4[10]; + int64_t v8[10]; + float f4[10]; + double f8[10]; + char bin[10][40]; + char blob[10][80]; + } v; + + int32_t* t8_len = malloc(sizeof(int32_t) * 10); + int32_t* t16_len = malloc(sizeof(int32_t) * 10); + int32_t* t32_len = malloc(sizeof(int32_t) * 10); + int32_t* t64_len = malloc(sizeof(int32_t) * 10); + int32_t* float_len = malloc(sizeof(int32_t) * 10); + int32_t* double_len = malloc(sizeof(int32_t) * 10); + int32_t* bin_len = malloc(sizeof(int32_t) * 10); + int32_t* blob_len = malloc(sizeof(int32_t) * 10); + + TAOS_STMT* stmt = taos_stmt_init_with_reqid(taos, genReqid()); + TAOS_MULTI_BIND params[10]; + char is_null[10] = {0}; + + params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; + params[0].buffer_length = sizeof(v.ts[0]); + params[0].buffer = v.ts; + params[0].length = t64_len; + params[0].is_null = is_null; + params[0].num = 10; + + params[1].buffer_type = TSDB_DATA_TYPE_BOOL; + params[1].buffer_length = sizeof(v.b[0]); + params[1].buffer = v.b; + params[1].length = t8_len; + params[1].is_null = is_null; + params[1].num = 10; + + params[2].buffer_type = TSDB_DATA_TYPE_TINYINT; + params[2].buffer_length = sizeof(v.v1[0]); + params[2].buffer = v.v1; + params[2].length = t8_len; + params[2].is_null = is_null; + params[2].num = 10; + + params[3].buffer_type = TSDB_DATA_TYPE_SMALLINT; + params[3].buffer_length = sizeof(v.v2[0]); + params[3].buffer = v.v2; + params[3].length = t16_len; + params[3].is_null = is_null; + params[3].num = 10; + + params[4].buffer_type = TSDB_DATA_TYPE_INT; + params[4].buffer_length = sizeof(v.v4[0]); + params[4].buffer = v.v4; + params[4].length = t32_len; + params[4].is_null = is_null; + params[4].num = 10; + + params[5].buffer_type = TSDB_DATA_TYPE_BIGINT; + params[5].buffer_length = sizeof(v.v8[0]); + params[5].buffer = v.v8; + params[5].length = t64_len; + params[5].is_null = is_null; + params[5].num = 10; + + params[6].buffer_type = TSDB_DATA_TYPE_FLOAT; + params[6].buffer_length = sizeof(v.f4[0]); + params[6].buffer = v.f4; + params[6].length = float_len; + params[6].is_null = is_null; + params[6].num = 10; + + params[7].buffer_type = TSDB_DATA_TYPE_DOUBLE; + params[7].buffer_length = sizeof(v.f8[0]); + params[7].buffer = v.f8; + params[7].length = double_len; + params[7].is_null = is_null; + params[7].num = 10; + + params[8].buffer_type = TSDB_DATA_TYPE_BINARY; + params[8].buffer_length = sizeof(v.bin[0]); + params[8].buffer = v.bin; + params[8].length = bin_len; + params[8].is_null = is_null; + params[8].num = 10; + + params[9].buffer_type = TSDB_DATA_TYPE_NCHAR; + params[9].buffer_length = sizeof(v.blob[0]); + params[9].buffer = v.blob; + params[9].length = blob_len; + params[9].is_null = is_null; + params[9].num = 10; + + sql = "insert into ? (ts, b, v1, v2, v4, v8, f4, f8, bin, blob) values(?,?,?,?,?,?,?,?,?,?)"; + code = taos_stmt_prepare(stmt, sql, 0); + if (code != 0) { + printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; + } + + code = taos_stmt_set_tbname(stmt, "m1"); + if (code != 0) { + printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; + } + + int64_t ts = 1591060628000; + for (int i = 0; i < 10; ++i) { + v.ts[i] = ts++; + is_null[i] = 0; + + v.b[i] = (int8_t)i % 2; + v.v1[i] = (int8_t)i; + v.v2[i] = (int16_t)(i * 2); + v.v4[i] = (int32_t)(i * 4); + v.v8[i] = (int64_t)(i * 8); + v.f4[i] = (float)(i * 40); + v.f8[i] = (double)(i * 80); + for (int j = 0; j < sizeof(v.bin[0]); ++j) { + v.bin[i][j] = (char)(i + '0'); + } + strcpy(v.blob[i], "一二三四五六七八九十"); + + t8_len[i] = sizeof(int8_t); + t16_len[i] = sizeof(int16_t); + t32_len[i] = sizeof(int32_t); + t64_len[i] = sizeof(int64_t); + float_len[i] = sizeof(float); + double_len[i] = sizeof(double); + bin_len[i] = sizeof(v.bin[0]); + blob_len[i] = (int32_t)strlen(v.blob[i]); + } + + taos_stmt_bind_param_batch(stmt, params); + taos_stmt_add_batch(stmt); + + if (taos_stmt_execute(stmt) != 0) { + printf("\033[31mfailed to execute insert statement.error:%s\033[0m\n", taos_stmt_errstr(stmt)); + taos_stmt_close(stmt); + return; + } + + taos_stmt_close(stmt); + + free(t8_len); + free(t16_len); + free(t32_len); + free(t64_len); + free(float_len); + free(double_len); + free(bin_len); + free(blob_len); +} + +int main(int argc, char* argv[]) { + const char* host = "127.0.0.1"; + const char* user = "root"; + const char* passwd = "taosdata"; + + taos_options(TSDB_OPTION_TIMEZONE, "GMT-8"); + TAOS* taos = taos_connect(host, user, passwd, "", 0); + if (taos == NULL) { + printf("\033[31mfailed to connect to db, reason:%s\033[0m\n", taos_errstr(taos)); + exit(1); + } + + printf("************ verify schema-less *************\n"); + verify_schema_less(taos); + + printf("************ verify query *************\n"); + verify_query(taos); + + printf("********* verify async query **********\n"); + verify_async(taos); + + printf("********* verify stmt query **********\n"); + veriry_stmt(taos); + + printf("done\n"); + taos_close(taos); + taos_cleanup(); +} diff --git a/examples/c/apitest.c b/examples/c/apitest.c index 9f4c7678ec059dbb3f0d4d43f0fc5adb277243d3..c179acaf4ef086a702e3130d8ae7effade0f09b9 100644 --- a/examples/c/apitest.c +++ b/examples/c/apitest.c @@ -1,8 +1,8 @@ // sample code to verify all TDengine API // to compile: gcc -o apitest apitest.c -ltaos -#include "taoserror.h" #include "cJSON.h" +#include "taoserror.h" #include #include @@ -11,7 +11,7 @@ #include "../../../include/client/taos.h" static void prepare_data(TAOS* taos) { - TAOS_RES *result; + TAOS_RES* result; result = taos_query(taos, "drop database if exists test;"); taos_free_result(result); usleep(100000); @@ -44,24 +44,25 @@ static void prepare_data(TAOS* taos) { result = taos_query(taos, "create table t9 using meters tags(9);"); taos_free_result(result); - result = taos_query(taos, "insert into t0 values('2020-01-01 00:00:00.000', 0)" - " ('2020-01-01 00:01:00.000', 0)" - " ('2020-01-01 00:02:00.000', 0)" - " t1 values('2020-01-01 00:00:00.000', 0)" - " ('2020-01-01 00:01:00.000', 0)" - " ('2020-01-01 00:02:00.000', 0)" - " ('2020-01-01 00:03:00.000', 0)" - " t2 values('2020-01-01 00:00:00.000', 0)" - " ('2020-01-01 00:01:00.000', 0)" - " ('2020-01-01 00:01:01.000', 0)" - " ('2020-01-01 00:01:02.000', 0)" - " t3 values('2020-01-01 00:01:02.000', 0)" - " t4 values('2020-01-01 00:01:02.000', 0)" - " t5 values('2020-01-01 00:01:02.000', 0)" - " t6 values('2020-01-01 00:01:02.000', 0)" - " t7 values('2020-01-01 00:01:02.000', 0)" - " t8 values('2020-01-01 00:01:02.000', 0)" - " t9 values('2020-01-01 00:01:02.000', 0)"); + result = taos_query(taos, + "insert into t0 values('2020-01-01 00:00:00.000', 0)" + " ('2020-01-01 00:01:00.000', 0)" + " ('2020-01-01 00:02:00.000', 0)" + " t1 values('2020-01-01 00:00:00.000', 0)" + " ('2020-01-01 00:01:00.000', 0)" + " ('2020-01-01 00:02:00.000', 0)" + " ('2020-01-01 00:03:00.000', 0)" + " t2 values('2020-01-01 00:00:00.000', 0)" + " ('2020-01-01 00:01:00.000', 0)" + " ('2020-01-01 00:01:01.000', 0)" + " ('2020-01-01 00:01:02.000', 0)" + " t3 values('2020-01-01 00:01:02.000', 0)" + " t4 values('2020-01-01 00:01:02.000', 0)" + " t5 values('2020-01-01 00:01:02.000', 0)" + " t6 values('2020-01-01 00:01:02.000', 0)" + " t7 values('2020-01-01 00:01:02.000', 0)" + " t8 values('2020-01-01 00:01:02.000', 0)" + " t9 values('2020-01-01 00:01:02.000', 0)"); int affected = taos_affected_rows(result); if (affected != 18) { printf("\033[31m%d rows affected by last insert statement, but it should be 18\033[0m\n", affected); @@ -80,11 +81,11 @@ static int print_result(TAOS_RES* res, int blockFetch) { if (blockFetch) { int rows = 0; while ((rows = taos_fetch_block(res, &row))) { - //for (int i = 0; i < rows; i++) { - // char temp[256]; - // taos_print_row(temp, row + i, fields, num_fields); - // puts(temp); - //} + // for (int i = 0; i < rows; i++) { + // char temp[256]; + // taos_print_row(temp, row + i, fields, num_fields); + // puts(temp); + // } nRows += rows; } } else { @@ -127,32 +128,32 @@ static void verify_query(TAOS* taos) { printf("\033[31mimpossible, the table does exists: 0x%08x\033[0m\n", code); } - TAOS_RES* res = taos_query(taos, "select * from meters"); + TAOS_RES* res = taos_query_with_reqid(taos, "select * from meters", genReqid()); check_row_count(__LINE__, res, 18); - printf("result precision is: %d\n", taos_result_precision(res)); + printf("result precision is: %d\n", taos_result_precision(res)); int c = taos_field_count(res); - printf("field count is: %d\n", c); + printf("field count is: %d\n", c); int* lengths = taos_fetch_lengths(res); for (int i = 0; i < c; i++) { printf("length of column %d is %d\n", i, lengths[i]); } taos_free_result(res); - res = taos_query(taos, "select * from t0"); + res = taos_query_with_reqid(taos, "select * from t0", genReqid()); check_row_count(__LINE__, res, 3); taos_free_result(res); - res = taos_query(taos, "select * from nonexisttable"); + res = taos_query_with_reqid(taos, "select * from nonexisttable", genReqid()); code = taos_errno(res); printf("code=%d, error msg=%s\n", code, taos_errstr(res)); taos_free_result(res); - res = taos_query(taos, "select * from meters"); + res = taos_query_with_reqid(taos, "select * from meters", genReqid()); taos_stop_query(res); taos_free_result(res); } -void subscribe_callback(TAOS_SUB* tsub, TAOS_RES *res, void* param, int code) { +void subscribe_callback(TAOS_SUB* tsub, TAOS_RES* res, void* param, int code) { int rows = print_result(res, *(int*)param); printf("%d rows consumed in subscribe_callback\n", rows); } @@ -167,7 +168,7 @@ static void verify_subscribe(TAOS* taos) { res = taos_consume(tsub); check_row_count(__LINE__, res, 0); - TAOS_RES *result; + TAOS_RES* result; result = taos_query(taos, "insert into t0 values('2020-01-01 00:02:00.001', 0);"); taos_free_result(result); result = taos_query(taos, "insert into t8 values('2020-01-01 00:01:03.000', 0);"); @@ -253,8 +254,10 @@ void verify_prepare(TAOS* taos) { taos_select_db(taos, "test"); // create table - const char* sql = "create table m1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(40), blob nchar(10))"; - result = taos_query(taos, sql); + const char* sql = + "create table m1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin " + "binary(40), blob nchar(10))"; + result = taos_query_with_reqid(taos, sql, genReqid()); code = taos_errno(result); if (code != 0) { printf("\033[31mfailed to create table, reason:%s\033[0m\n", taos_errstr(result)); @@ -265,20 +268,20 @@ void verify_prepare(TAOS* taos) { // insert 10 records struct { - int64_t ts; - int8_t b; - int8_t v1; - int16_t v2; - int32_t v4; - int64_t v8; - float f4; - double f8; - char bin[40]; - char blob[80]; + int64_t ts; + int8_t b; + int8_t v1; + int16_t v2; + int32_t v4; + int64_t v8; + float f4; + double f8; + char bin[40]; + char blob[80]; } v = {0}; TAOS_STMT* stmt = taos_stmt_init(taos); - TAOS_BIND params[10]; + TAOS_BIND params[10]; params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; params[0].buffer_length = sizeof(v.ts); params[0].buffer = &v.ts; @@ -344,7 +347,7 @@ void verify_prepare(TAOS* taos) { sql = "insert into m1 values(?,?,?,?,?,?,?,?,?,?)"; code = taos_stmt_prepare(stmt, sql, 0); - if (code != 0){ + if (code != 0) { printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); taos_stmt_close(stmt); return; @@ -393,7 +396,7 @@ void verify_prepare(TAOS* taos) { TAOS_ROW row; int rows = 0; int num_fields = taos_num_fields(result); - TAOS_FIELD *fields = taos_fetch_fields(result); + TAOS_FIELD* fields = taos_fetch_fields(result); // fetch the records row by row while ((row = taos_fetch_row(result))) { @@ -425,7 +428,9 @@ void verify_prepare2(TAOS* taos) { taos_select_db(taos, "test"); // create table - const char* sql = "create table m1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(40), blob nchar(10))"; + const char* sql = + "create table m1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin " + "binary(40), blob nchar(10))"; result = taos_query(taos, sql); code = taos_errno(result); if (code != 0) { @@ -437,31 +442,31 @@ void verify_prepare2(TAOS* taos) { // insert 10 records struct { - int64_t ts[10]; - int8_t b[10]; - int8_t v1[10]; - int16_t v2[10]; - int32_t v4[10]; - int64_t v8[10]; - float f4[10]; - double f8[10]; - char bin[10][40]; - char blob[10][80]; + int64_t ts[10]; + int8_t b[10]; + int8_t v1[10]; + int16_t v2[10]; + int32_t v4[10]; + int64_t v8[10]; + float f4[10]; + double f8[10]; + char bin[10][40]; + char blob[10][80]; } v; - int32_t *t8_len = malloc(sizeof(int32_t) * 10); - int32_t *t16_len = malloc(sizeof(int32_t) * 10); - int32_t *t32_len = malloc(sizeof(int32_t) * 10); - int32_t *t64_len = malloc(sizeof(int32_t) * 10); - int32_t *float_len = malloc(sizeof(int32_t) * 10); - int32_t *double_len = malloc(sizeof(int32_t) * 10); - int32_t *bin_len = malloc(sizeof(int32_t) * 10); - int32_t *blob_len = malloc(sizeof(int32_t) * 10); + int32_t* t8_len = malloc(sizeof(int32_t) * 10); + int32_t* t16_len = malloc(sizeof(int32_t) * 10); + int32_t* t32_len = malloc(sizeof(int32_t) * 10); + int32_t* t64_len = malloc(sizeof(int32_t) * 10); + int32_t* float_len = malloc(sizeof(int32_t) * 10); + int32_t* double_len = malloc(sizeof(int32_t) * 10); + int32_t* bin_len = malloc(sizeof(int32_t) * 10); + int32_t* blob_len = malloc(sizeof(int32_t) * 10); - TAOS_STMT* stmt = taos_stmt_init(taos); + TAOS_STMT* stmt = taos_stmt_init(taos); TAOS_MULTI_BIND params[10]; - char is_null[10] = {0}; - + char is_null[10] = {0}; + params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; params[0].buffer_length = sizeof(v.ts[0]); params[0].buffer = v.ts; @@ -541,12 +546,12 @@ void verify_prepare2(TAOS* taos) { } code = taos_stmt_set_tbname(stmt, "m1"); - if (code != 0){ + if (code != 0) { printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); taos_stmt_close(stmt); return; } - + int64_t ts = 1591060628000; for (int i = 0; i < 10; ++i) { v.ts[i] = ts++; @@ -561,7 +566,7 @@ void verify_prepare2(TAOS* taos) { v.f8[i] = (double)(i * 80); for (int j = 0; j < sizeof(v.bin[0]); ++j) { v.bin[i][j] = (char)(i + '0'); - } + } strcpy(v.blob[i], "一二三四五六七八九十"); t8_len[i] = sizeof(int8_t); @@ -576,7 +581,7 @@ void verify_prepare2(TAOS* taos) { taos_stmt_bind_param_batch(stmt, params); taos_stmt_add_batch(stmt); - + if (taos_stmt_execute(stmt) != 0) { printf("\033[31mfailed to execute insert statement.error:%s\033[0m\n", taos_stmt_errstr(stmt)); taos_stmt_close(stmt); @@ -590,7 +595,7 @@ void verify_prepare2(TAOS* taos) { taos_stmt_prepare(stmt, "SELECT * FROM m1 WHERE v1 > ? AND v2 < ?", 0); TAOS_BIND qparams[2]; - int8_t v1 = 5; + int8_t v1 = 5; int16_t v2 = 15; qparams[0].buffer_type = TSDB_DATA_TYPE_TINYINT; qparams[0].buffer_length = sizeof(v1); @@ -607,7 +612,7 @@ void verify_prepare2(TAOS* taos) { taos_stmt_bind_param(stmt, qparams); if (taos_stmt_execute(stmt) != 0) { printf("\033[31mfailed to execute select statement.error:%s\033[0m\n", taos_stmt_errstr(stmt)); - taos_stmt_close(stmt); + taos_stmt_close(stmt); return; } @@ -616,7 +621,7 @@ void verify_prepare2(TAOS* taos) { TAOS_ROW row; int rows = 0; int num_fields = taos_num_fields(result); - TAOS_FIELD *fields = taos_fetch_fields(result); + TAOS_FIELD* fields = taos_fetch_fields(result); // fetch the records row by row while ((row = taos_fetch_row(result))) { @@ -657,7 +662,9 @@ void verify_prepare3(TAOS* taos) { taos_select_db(taos, "test"); // create table - const char* sql = "create stable st1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin binary(40), blob nchar(10)) tags (id1 int, id2 binary(40))"; + const char* sql = + "create stable st1 (ts timestamp, b bool, v1 tinyint, v2 smallint, v4 int, v8 bigint, f4 float, f8 double, bin " + "binary(40), blob nchar(10)) tags (id1 int, id2 binary(40))"; result = taos_query(taos, sql); code = taos_errno(result); if (code != 0) { @@ -669,10 +676,10 @@ void verify_prepare3(TAOS* taos) { TAOS_BIND tags[2]; - int32_t id1 = 1; - char id2[40] = "abcdefghijklmnopqrstuvwxyz0123456789"; + int32_t id1 = 1; + char id2[40] = "abcdefghijklmnopqrstuvwxyz0123456789"; uintptr_t id2_len = strlen(id2); - + tags[0].buffer_type = TSDB_DATA_TYPE_INT; tags[0].buffer_length = sizeof(int); tags[0].buffer = &id1; @@ -685,34 +692,33 @@ void verify_prepare3(TAOS* taos) { tags[1].length = &id2_len; tags[1].is_null = NULL; - // insert 10 records struct { - int64_t ts[10]; - int8_t b[10]; - int8_t v1[10]; - int16_t v2[10]; - int32_t v4[10]; - int64_t v8[10]; - float f4[10]; - double f8[10]; - char bin[10][40]; - char blob[10][80]; + int64_t ts[10]; + int8_t b[10]; + int8_t v1[10]; + int16_t v2[10]; + int32_t v4[10]; + int64_t v8[10]; + float f4[10]; + double f8[10]; + char bin[10][40]; + char blob[10][80]; } v; - int32_t *t8_len = malloc(sizeof(int32_t) * 10); - int32_t *t16_len = malloc(sizeof(int32_t) * 10); - int32_t *t32_len = malloc(sizeof(int32_t) * 10); - int32_t *t64_len = malloc(sizeof(int32_t) * 10); - int32_t *float_len = malloc(sizeof(int32_t) * 10); - int32_t *double_len = malloc(sizeof(int32_t) * 10); - int32_t *bin_len = malloc(sizeof(int32_t) * 10); - int32_t *blob_len = malloc(sizeof(int32_t) * 10); + int32_t* t8_len = malloc(sizeof(int32_t) * 10); + int32_t* t16_len = malloc(sizeof(int32_t) * 10); + int32_t* t32_len = malloc(sizeof(int32_t) * 10); + int32_t* t64_len = malloc(sizeof(int32_t) * 10); + int32_t* float_len = malloc(sizeof(int32_t) * 10); + int32_t* double_len = malloc(sizeof(int32_t) * 10); + int32_t* bin_len = malloc(sizeof(int32_t) * 10); + int32_t* blob_len = malloc(sizeof(int32_t) * 10); - TAOS_STMT* stmt = taos_stmt_init(taos); + TAOS_STMT* stmt = taos_stmt_init(taos); TAOS_MULTI_BIND params[10]; - char is_null[10] = {0}; - + char is_null[10] = {0}; + params[0].buffer_type = TSDB_DATA_TYPE_TIMESTAMP; params[0].buffer_length = sizeof(v.ts[0]); params[0].buffer = v.ts; @@ -783,27 +789,26 @@ void verify_prepare3(TAOS* taos) { params[9].is_null = is_null; params[9].num = 10; - sql = "insert into ? using st1 tags(?,?) values(?,?,?,?,?,?,?,?,?,?)"; code = taos_stmt_prepare(stmt, sql, 0); - if (code != 0){ + if (code != 0) { printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); taos_stmt_close(stmt); - return; + return; } code = taos_stmt_set_tbname_tags(stmt, "m1", tags); - if (code != 0){ + if (code != 0) { printf("\033[31mfailed to execute taos_stmt_prepare. error:%s\033[0m\n", taos_stmt_errstr(stmt)); - taos_stmt_close(stmt); + taos_stmt_close(stmt); return; } - + int64_t ts = 1591060628000; for (int i = 0; i < 10; ++i) { v.ts[i] = ts++; is_null[i] = 0; - + v.b[i] = (int8_t)i % 2; v.v1[i] = (int8_t)i; v.v2[i] = (int16_t)(i * 2); @@ -813,7 +818,7 @@ void verify_prepare3(TAOS* taos) { v.f8[i] = (double)(i * 80); for (int j = 0; j < sizeof(v.bin[0]); ++j) { v.bin[i][j] = (char)(i + '0'); - } + } strcpy(v.blob[i], "一二三四五六七八九十"); t8_len[i] = sizeof(int8_t); @@ -828,10 +833,10 @@ void verify_prepare3(TAOS* taos) { taos_stmt_bind_param_batch(stmt, params); taos_stmt_add_batch(stmt); - + if (taos_stmt_execute(stmt) != 0) { printf("\033[31mfailed to execute insert statement.error:%s\033[0m\n", taos_stmt_errstr(stmt)); - taos_stmt_close(stmt); + taos_stmt_close(stmt); return; } taos_stmt_close(stmt); @@ -842,7 +847,7 @@ void verify_prepare3(TAOS* taos) { TAOS_BIND qparams[2]; - int8_t v1 = 5; + int8_t v1 = 5; int16_t v2 = 15; qparams[0].buffer_type = TSDB_DATA_TYPE_TINYINT; qparams[0].buffer_length = sizeof(v1); @@ -859,7 +864,7 @@ void verify_prepare3(TAOS* taos) { taos_stmt_bind_param(stmt, qparams); if (taos_stmt_execute(stmt) != 0) { printf("\033[31mfailed to execute select statement.error:%s\033[0m\n", taos_stmt_errstr(stmt)); - taos_stmt_close(stmt); + taos_stmt_close(stmt); return; } @@ -868,7 +873,7 @@ void verify_prepare3(TAOS* taos) { TAOS_ROW row; int rows = 0; int num_fields = taos_num_fields(result); - TAOS_FIELD *fields = taos_fetch_fields(result); + TAOS_FIELD* fields = taos_fetch_fields(result); // fetch the records row by row while ((row = taos_fetch_row(result))) { @@ -891,8 +896,7 @@ void verify_prepare3(TAOS* taos) { free(blob_len); } -void retrieve_callback(void *param, TAOS_RES *tres, int numOfRows) -{ +void retrieve_callback(void* param, TAOS_RES* tres, int numOfRows) { if (numOfRows > 0) { printf("%d rows async retrieved\n", numOfRows); taos_fetch_rows_a(tres, retrieve_callback, param); @@ -906,8 +910,7 @@ void retrieve_callback(void *param, TAOS_RES *tres, int numOfRows) } } -void select_callback(void *param, TAOS_RES *tres, int code) -{ +void select_callback(void* param, TAOS_RES* tres, int code) { if (code == 0 && tres) { taos_fetch_rows_a(tres, retrieve_callback, param); } else { @@ -921,11 +924,11 @@ void verify_async(TAOS* taos) { usleep(1000000); } -void stream_callback(void *param, TAOS_RES *res, TAOS_ROW row) { +void stream_callback(void* param, TAOS_RES* res, TAOS_ROW row) { if (res == NULL || row == NULL) { return; } - + int num_fields = taos_num_fields(res); TAOS_FIELD* fields = taos_fetch_fields(res); @@ -937,14 +940,9 @@ void stream_callback(void *param, TAOS_RES *res, TAOS_ROW row) { void verify_stream(TAOS* taos) { prepare_data(taos); - TAOS_STREAM* strm = taos_open_stream( - taos, - "select count(*) from meters interval(1m)", - stream_callback, - 0, - NULL, - NULL); - printf("waiting for stream data\n"); + TAOS_STREAM* strm = + taos_open_stream(taos, "select count(*) from meters interval(1m)", stream_callback, 0, NULL, NULL); + printf("waiting for stream data\n"); usleep(100000); TAOS_RES* result = taos_query(taos, "insert into t0 values(now, 0)(now+5s,1)(now+10s, 2);"); taos_free_result(result); @@ -953,7 +951,7 @@ void verify_stream(TAOS* taos) { } int32_t verify_schema_less(TAOS* taos) { - TAOS_RES *result; + TAOS_RES* result; result = taos_query(taos, "drop database if exists test;"); taos_free_result(result); usleep(100000); @@ -975,50 +973,52 @@ int32_t verify_schema_less(TAOS* taos) { "st,t1=4i64,t2=5f64,t3=\"t4\" c1=3i64,c3=L\"passitagain\",c2=true,c4=5f64 1626006833642000000ns", "ste,t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false 1626056811843316532ns", "ste,t2=5f64,t3=L\"ste2\" c3=\"iamszhou\",c4=false,c5=32i8,c6=64i16,c7=32i32,c8=88.88f32 1626056812843316532ns", - "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000ns", - "stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 1626006933640000000ns", - "stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 1626006933641000000ns" - }; + "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 " + "1626006933640000000ns", + "stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64,c6=7u64 " + "1626006933640000000ns", + "stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 " + "1626006933641000000ns"}; - code = taos_insert_lines(taos, lines , sizeof(lines)/sizeof(char*)); + code = taos_insert_lines(taos, lines, sizeof(lines) / sizeof(char*)); char* lines2[] = { "stg,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns", - "stg,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns" - }; + "stg,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns"}; code = taos_insert_lines(taos, &lines2[0], 1); code = taos_insert_lines(taos, &lines2[1], 1); char* lines3[] = { - "sth,t1=4i64,t2=5f64,t4=5f64,ID=\"childtable\" c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 1626006933641ms", - "sth,t1=4i64,t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 1626006933654ms" - }; + "sth,t1=4i64,t2=5f64,t4=5f64,ID=\"childtable\" c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 " + "1626006933641ms", + "sth,t1=4i64,t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 1626006933654ms"}; code = taos_insert_lines(taos, lines3, 2); - char* lines4[] = { - "st123456,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns", - "dgtyqodr,t2=5f64,t3=L\"ste\" c1=tRue,c2=4i64,c3=\"iam\" 1626056811823316532ns" - }; + char* lines4[] = {"st123456,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns", + "dgtyqodr,t2=5f64,t3=L\"ste\" c1=tRue,c2=4i64,c3=\"iam\" 1626056811823316532ns"}; code = taos_insert_lines(taos, lines4, 2); char* lines5[] = { - "zqlbgs,id=\"zqlbgs_39302_21680\",t0=f,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"binaryTagValue\",t8=L\"ncharTagValue\" c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"binaryColValue\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000ns", - "zqlbgs,t9=f,id=\"zqlbgs_39302_21680\",t0=f,t1=127i8,t11=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"binaryTagValue\",t8=L\"ncharTagValue\",t10=L\"ncharTagValue\" c10=f,c0=f,c1=127i8,c12=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"binaryColValue\",c8=L\"ncharColValue\",c9=7u64,c11=L\"ncharColValue\" 1626006833639000000ns" - }; + "zqlbgs,id=\"zqlbgs_39302_21680\",t0=f,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11." + "12345f32,t6=22.123456789f64,t7=\"binaryTagValue\",t8=L\"ncharTagValue\" " + "c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=" + "\"binaryColValue\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000ns", + "zqlbgs,t9=f,id=\"zqlbgs_39302_21680\",t0=f,t1=127i8,t11=127i8,t2=32767i16,t3=2147483647i32,t4=" + "9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"binaryTagValue\",t8=L\"ncharTagValue\",t10=" + "L\"ncharTagValue\" " + "c10=f,c0=f,c1=127i8,c12=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22." + "123456789f64,c7=\"binaryColValue\",c8=L\"ncharColValue\",c9=7u64,c11=L\"ncharColValue\" 1626006833639000000ns"}; code = taos_insert_lines(taos, &lines5[0], 1); code = taos_insert_lines(taos, &lines5[1], 1); - - char* lines6[] = { - "st123456,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns", - "dgtyqodr,t2=5f64,t3=L\"ste\" c1=tRue,c2=4i64,c3=\"iam\" 1626056811823316532ns" - }; + char* lines6[] = {"st123456,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns", + "dgtyqodr,t2=5f64,t3=L\"ste\" c1=tRue,c2=4i64,c3=\"iam\" 1626056811823316532ns"}; code = taos_insert_lines(taos, lines6, 2); return (code); } void verify_telnet_insert(TAOS* taos) { - TAOS_RES *result; + TAOS_RES* result; result = taos_query(taos, "drop database if exists db;"); taos_free_result(result); @@ -1043,12 +1043,9 @@ void verify_telnet_insert(TAOS* taos) { /* timestamp */ char* lines1[] = { - "stb1 1626006833s 1i8 host=\"host0\"", - "stb1 1626006833639000000ns 2i8 host=\"host0\"", - "stb1 1626006833640000us 3i8 host=\"host0\"", - "stb1 1626006833641123 4i8 host=\"host0\"", - "stb1 1626006833651ms 5i8 host=\"host0\"", - "stb1 0 6i8 host=\"host0\"", + "stb1 1626006833s 1i8 host=\"host0\"", "stb1 1626006833639000000ns 2i8 host=\"host0\"", + "stb1 1626006833640000us 3i8 host=\"host0\"", "stb1 1626006833641123 4i8 host=\"host0\"", + "stb1 1626006833651ms 5i8 host=\"host0\"", "stb1 0 6i8 host=\"host0\"", }; code = taos_insert_telnet_lines(taos, lines1, 6); if (code) { @@ -1056,113 +1053,83 @@ void verify_telnet_insert(TAOS* taos) { } /* metric value */ - //tinyin - char* lines2_0[] = { - "stb2_0 1626006833651ms -127i8 host=\"host0\"", - "stb2_0 1626006833652ms 127i8 host=\"host0\"" - }; + // tinyin + char* lines2_0[] = {"stb2_0 1626006833651ms -127i8 host=\"host0\"", "stb2_0 1626006833652ms 127i8 host=\"host0\""}; code = taos_insert_telnet_lines(taos, lines2_0, 2); if (code) { printf("lines2_0 code: %d, %s.\n", code, tstrerror(code)); } - //smallint - char* lines2_1[] = { - "stb2_1 1626006833651ms -32767i16 host=\"host0\"", - "stb2_1 1626006833652ms 32767i16 host=\"host0\"" - }; + // smallint + char* lines2_1[] = {"stb2_1 1626006833651ms -32767i16 host=\"host0\"", + "stb2_1 1626006833652ms 32767i16 host=\"host0\""}; code = taos_insert_telnet_lines(taos, lines2_1, 2); if (code) { printf("lines2_1 code: %d, %s.\n", code, tstrerror(code)); } - //int - char* lines2_2[] = { - "stb2_2 1626006833651ms -2147483647i32 host=\"host0\"", - "stb2_2 1626006833652ms 2147483647i32 host=\"host0\"" - }; + // int + char* lines2_2[] = {"stb2_2 1626006833651ms -2147483647i32 host=\"host0\"", + "stb2_2 1626006833652ms 2147483647i32 host=\"host0\""}; code = taos_insert_telnet_lines(taos, lines2_2, 2); if (code) { printf("lines2_2 code: %d, %s.\n", code, tstrerror(code)); } - //bigint - char* lines2_3[] = { - "stb2_3 1626006833651ms -9223372036854775807i64 host=\"host0\"", - "stb2_3 1626006833652ms 9223372036854775807i64 host=\"host0\"" - }; + // bigint + char* lines2_3[] = {"stb2_3 1626006833651ms -9223372036854775807i64 host=\"host0\"", + "stb2_3 1626006833652ms 9223372036854775807i64 host=\"host0\""}; code = taos_insert_telnet_lines(taos, lines2_3, 2); if (code) { printf("lines2_3 code: %d, %s.\n", code, tstrerror(code)); } - //float + // float char* lines2_4[] = { - "stb2_4 1626006833610ms 3f32 host=\"host0\"", - "stb2_4 1626006833620ms -3f32 host=\"host0\"", - "stb2_4 1626006833630ms 3.4f32 host=\"host0\"", - "stb2_4 1626006833640ms -3.4f32 host=\"host0\"", - "stb2_4 1626006833650ms 3.4E10f32 host=\"host0\"", - "stb2_4 1626006833660ms -3.4e10f32 host=\"host0\"", - "stb2_4 1626006833670ms 3.4E+2f32 host=\"host0\"", - "stb2_4 1626006833680ms -3.4e-2f32 host=\"host0\"", - "stb2_4 1626006833690ms 3.15 host=\"host0\"", - "stb2_4 1626006833700ms 3.4E38f32 host=\"host0\"", - "stb2_4 1626006833710ms -3.4E38f32 host=\"host0\"" - }; + "stb2_4 1626006833610ms 3f32 host=\"host0\"", "stb2_4 1626006833620ms -3f32 host=\"host0\"", + "stb2_4 1626006833630ms 3.4f32 host=\"host0\"", "stb2_4 1626006833640ms -3.4f32 host=\"host0\"", + "stb2_4 1626006833650ms 3.4E10f32 host=\"host0\"", "stb2_4 1626006833660ms -3.4e10f32 host=\"host0\"", + "stb2_4 1626006833670ms 3.4E+2f32 host=\"host0\"", "stb2_4 1626006833680ms -3.4e-2f32 host=\"host0\"", + "stb2_4 1626006833690ms 3.15 host=\"host0\"", "stb2_4 1626006833700ms 3.4E38f32 host=\"host0\"", + "stb2_4 1626006833710ms -3.4E38f32 host=\"host0\""}; code = taos_insert_telnet_lines(taos, lines2_4, 11); if (code) { printf("lines2_4 code: %d, %s.\n", code, tstrerror(code)); } - //double + // double char* lines2_5[] = { - "stb2_5 1626006833610ms 3f64 host=\"host0\"", - "stb2_5 1626006833620ms -3f64 host=\"host0\"", - "stb2_5 1626006833630ms 3.4f64 host=\"host0\"", - "stb2_5 1626006833640ms -3.4f64 host=\"host0\"", - "stb2_5 1626006833650ms 3.4E10f64 host=\"host0\"", - "stb2_5 1626006833660ms -3.4e10f64 host=\"host0\"", - "stb2_5 1626006833670ms 3.4E+2f64 host=\"host0\"", - "stb2_5 1626006833680ms -3.4e-2f64 host=\"host0\"", - "stb2_5 1626006833690ms 1.7E308f64 host=\"host0\"", - "stb2_5 1626006833700ms -1.7E308f64 host=\"host0\"" - }; + "stb2_5 1626006833610ms 3f64 host=\"host0\"", "stb2_5 1626006833620ms -3f64 host=\"host0\"", + "stb2_5 1626006833630ms 3.4f64 host=\"host0\"", "stb2_5 1626006833640ms -3.4f64 host=\"host0\"", + "stb2_5 1626006833650ms 3.4E10f64 host=\"host0\"", "stb2_5 1626006833660ms -3.4e10f64 host=\"host0\"", + "stb2_5 1626006833670ms 3.4E+2f64 host=\"host0\"", "stb2_5 1626006833680ms -3.4e-2f64 host=\"host0\"", + "stb2_5 1626006833690ms 1.7E308f64 host=\"host0\"", "stb2_5 1626006833700ms -1.7E308f64 host=\"host0\""}; code = taos_insert_telnet_lines(taos, lines2_5, 10); if (code) { printf("lines2_5 code: %d, %s.\n", code, tstrerror(code)); } - //bool - char* lines2_6[] = { - "stb2_6 1626006833610ms t host=\"host0\"", - "stb2_6 1626006833620ms T host=\"host0\"", - "stb2_6 1626006833630ms true host=\"host0\"", - "stb2_6 1626006833640ms True host=\"host0\"", - "stb2_6 1626006833650ms TRUE host=\"host0\"", - "stb2_6 1626006833660ms f host=\"host0\"", - "stb2_6 1626006833670ms F host=\"host0\"", - "stb2_6 1626006833680ms false host=\"host0\"", - "stb2_6 1626006833690ms False host=\"host0\"", - "stb2_6 1626006833700ms FALSE host=\"host0\"" - }; + // bool + char* lines2_6[] = {"stb2_6 1626006833610ms t host=\"host0\"", "stb2_6 1626006833620ms T host=\"host0\"", + "stb2_6 1626006833630ms true host=\"host0\"", "stb2_6 1626006833640ms True host=\"host0\"", + "stb2_6 1626006833650ms TRUE host=\"host0\"", "stb2_6 1626006833660ms f host=\"host0\"", + "stb2_6 1626006833670ms F host=\"host0\"", "stb2_6 1626006833680ms false host=\"host0\"", + "stb2_6 1626006833690ms False host=\"host0\"", "stb2_6 1626006833700ms FALSE host=\"host0\""}; code = taos_insert_telnet_lines(taos, lines2_6, 10); if (code) { printf("lines2_6 code: %d, %s.\n", code, tstrerror(code)); } - //binary - char* lines2_7[] = { - "stb2_7 1626006833610ms \"binary_val.!@#$%^&*\" host=\"host0\"", - "stb2_7 1626006833620ms \"binary_val.:;,./?|+-=\" host=\"host0\"", - "stb2_7 1626006833630ms \"binary_val.()[]{}<>\" host=\"host0\"" - }; + // binary + char* lines2_7[] = {"stb2_7 1626006833610ms \"binary_val.!@#$%^&*\" host=\"host0\"", + "stb2_7 1626006833620ms \"binary_val.:;,./?|+-=\" host=\"host0\"", + "stb2_7 1626006833630ms \"binary_val.()[]{}<>\" host=\"host0\""}; code = taos_insert_telnet_lines(taos, lines2_7, 3); if (code) { printf("lines2_7 code: %d, %s.\n", code, tstrerror(code)); } - //nchar + // nchar char* lines2_8[] = { "stb2_8 1626006833610ms L\"nchar_val数值一\" host=\"host0\"", "stb2_8 1626006833620ms L\"nchar_val数值二\" host=\"host0\"", @@ -1173,22 +1140,23 @@ void verify_telnet_insert(TAOS* taos) { } /* tags */ - //tag value types + // tag value types char* lines3_0[] = { - "stb3_0 1626006833610ms 1 t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=3.4E38f32,t6=1.7E308f64,t7=true,t8=\"binary_val_1\",t9=L\"标签值1\"", - "stb3_0 1626006833610ms 2 t1=-127i8,t2=-32767i16,t3=-2147483647i32,t4=-9223372036854775807i64,t5=-3.4E38f32,t6=-1.7E308f64,t7=false,t8=\"binary_val_2\",t9=L\"标签值2\"" - }; + "stb3_0 1626006833610ms 1 " + "t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=3.4E38f32,t6=1.7E308f64,t7=true,t8=\"binary_" + "val_1\",t9=L\"标签值1\"", + "stb3_0 1626006833610ms 2 " + "t1=-127i8,t2=-32767i16,t3=-2147483647i32,t4=-9223372036854775807i64,t5=-3.4E38f32,t6=-1.7E308f64,t7=false,t8=" + "\"binary_val_2\",t9=L\"标签值2\""}; code = taos_insert_telnet_lines(taos, lines3_0, 2); if (code) { printf("lines3_0 code: %d, %s.\n", code, tstrerror(code)); } - //tag ID as child table name - char* lines3_1[] = { - "stb3_1 1626006833610ms 1 id=\"child_table1\",host=\"host1\"", - "stb3_1 1626006833610ms 2 host=\"host2\",iD=\"child_table2\"", - "stb3_1 1626006833610ms 3 ID=\"child_table3\",host=\"host3\"" - }; + // tag ID as child table name + char* lines3_1[] = {"stb3_1 1626006833610ms 1 id=\"child_table1\",host=\"host1\"", + "stb3_1 1626006833610ms 2 host=\"host2\",iD=\"child_table2\"", + "stb3_1 1626006833610ms 3 ID=\"child_table3\",host=\"host3\""}; code = taos_insert_telnet_lines(taos, lines3_1, 3); if (code) { printf("lines3_1 code: %d, %s.\n", code, tstrerror(code)); @@ -1198,7 +1166,7 @@ void verify_telnet_insert(TAOS* taos) { } void verify_json_insert(TAOS* taos) { - TAOS_RES *result; + TAOS_RES* result; result = taos_query(taos, "drop database if exists db;"); taos_free_result(result); @@ -1210,8 +1178,8 @@ void verify_json_insert(TAOS* taos) { (void)taos_select_db(taos, "db"); int32_t code = 0; - char *message = - "{ \ + char* message = + "{ \ \"metric\":\"cpu_load_0\", \ \"timestamp\": 1626006833610123, \ \"value\": 55.5, \ @@ -1228,8 +1196,8 @@ void verify_json_insert(TAOS* taos) { printf("payload_0 code: %d, %s.\n", code, tstrerror(code)); } - char *message1 = - "[ \ + char* message1 = + "[ \ { \ \"metric\":\"cpu_load_1\", \ \"timestamp\": 1626006833610123, \ @@ -1259,8 +1227,8 @@ void verify_json_insert(TAOS* taos) { printf("payload_1 code: %d, %s.\n", code, tstrerror(code)); } - char *message2 = - "[ \ + char* message2 = + "[ \ { \ \"metric\":\"cpu_load_3\", \ \"timestamp\": \ @@ -1310,12 +1278,11 @@ void verify_json_insert(TAOS* taos) { printf("payload_2 code: %d, %s.\n", code, tstrerror(code)); } - cJSON *payload, *tags; - char *payload_str; + char* payload_str; /* Default format */ - //number + // number payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb0_0"); cJSON_AddNumberToObject(payload, "timestamp", 1626006833610123); @@ -1327,7 +1294,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1336,7 +1303,7 @@ void verify_json_insert(TAOS* taos) { free(payload_str); cJSON_Delete(payload); - //true + // true payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb0_1"); cJSON_AddNumberToObject(payload, "timestamp", 1626006833610123); @@ -1348,7 +1315,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1357,7 +1324,7 @@ void verify_json_insert(TAOS* taos) { free(payload_str); cJSON_Delete(payload); - //false + // false payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb0_2"); cJSON_AddNumberToObject(payload, "timestamp", 1626006833610123); @@ -1369,7 +1336,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1378,7 +1345,7 @@ void verify_json_insert(TAOS* taos) { free(payload_str); cJSON_Delete(payload); - //string + // string payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb0_3"); cJSON_AddNumberToObject(payload, "timestamp", 1626006833610123); @@ -1390,7 +1357,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1399,7 +1366,7 @@ void verify_json_insert(TAOS* taos) { free(payload_str); cJSON_Delete(payload); - //timestamp 0 -> current time + // timestamp 0 -> current time payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb0_4"); cJSON_AddNumberToObject(payload, "timestamp", 0); @@ -1411,7 +1378,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1420,7 +1387,7 @@ void verify_json_insert(TAOS* taos) { free(payload_str); cJSON_Delete(payload); - //ID + // ID payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb0_5"); cJSON_AddNumberToObject(payload, "timestamp", 0); @@ -1435,7 +1402,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "id", "tb555"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1445,9 +1412,9 @@ void verify_json_insert(TAOS* taos) { cJSON_Delete(payload); /* Nested format */ - //timestamp - cJSON *timestamp; - //seconds + // timestamp + cJSON* timestamp; + // seconds payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb1_0"); @@ -1464,7 +1431,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1473,7 +1440,7 @@ void verify_json_insert(TAOS* taos) { free(payload_str); cJSON_Delete(payload); - //milleseconds + // milleseconds payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb1_1"); @@ -1490,7 +1457,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1499,7 +1466,7 @@ void verify_json_insert(TAOS* taos) { free(payload_str); cJSON_Delete(payload); - //microseconds + // microseconds payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb1_2"); @@ -1516,7 +1483,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1525,7 +1492,7 @@ void verify_json_insert(TAOS* taos) { free(payload_str); cJSON_Delete(payload); - //nanoseconds + // nanoseconds payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb1_3"); @@ -1542,7 +1509,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1551,7 +1518,7 @@ void verify_json_insert(TAOS* taos) { free(payload_str); cJSON_Delete(payload); - //now + // now payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb1_4"); @@ -1568,7 +1535,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1577,9 +1544,9 @@ void verify_json_insert(TAOS* taos) { free(payload_str); cJSON_Delete(payload); - //metric value - cJSON *metric_val; - //bool + // metric value + cJSON* metric_val; + // bool payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb2_0"); @@ -1600,7 +1567,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1609,7 +1576,7 @@ void verify_json_insert(TAOS* taos) { free(payload_str); cJSON_Delete(payload); - //tinyint + // tinyint payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb2_1"); @@ -1630,7 +1597,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1639,7 +1606,7 @@ void verify_json_insert(TAOS* taos) { free(payload_str); cJSON_Delete(payload); - //smallint + // smallint payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb2_2"); @@ -1660,7 +1627,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1669,7 +1636,7 @@ void verify_json_insert(TAOS* taos) { free(payload_str); cJSON_Delete(payload); - //int + // int payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb2_3"); @@ -1690,7 +1657,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1699,7 +1666,7 @@ void verify_json_insert(TAOS* taos) { free(payload_str); cJSON_Delete(payload); - //bigint + // bigint payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb2_4"); @@ -1720,7 +1687,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1729,7 +1696,7 @@ void verify_json_insert(TAOS* taos) { free(payload_str); cJSON_Delete(payload); - //float + // float payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb2_5"); @@ -1750,7 +1717,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1759,7 +1726,7 @@ void verify_json_insert(TAOS* taos) { free(payload_str); cJSON_Delete(payload); - //double + // double payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb2_6"); @@ -1780,7 +1747,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1789,7 +1756,7 @@ void verify_json_insert(TAOS* taos) { free(payload_str); cJSON_Delete(payload); - //binary + // binary payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb2_7"); @@ -1810,7 +1777,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1819,7 +1786,7 @@ void verify_json_insert(TAOS* taos) { free(payload_str); cJSON_Delete(payload); - //nchar + // nchar payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb2_8"); @@ -1840,7 +1807,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddStringToObject(tags, "t4", "123_abc_.!@#$%^&*:;,./?|+-=()[]{}<>"); cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1849,8 +1816,8 @@ void verify_json_insert(TAOS* taos) { free(payload_str); cJSON_Delete(payload); - //tag value - cJSON *tag; + // tag value + cJSON* tag; payload = cJSON_CreateObject(); cJSON_AddStringToObject(payload, "metric", "stb3_0"); @@ -1920,7 +1887,7 @@ void verify_json_insert(TAOS* taos) { cJSON_AddItemToObject(payload, "tags", tags); payload_str = cJSON_Print(payload); - //printf("%s\n", payload_str); + // printf("%s\n", payload_str); code = taos_insert_json_payload(taos, payload_str); if (code) { @@ -1930,7 +1897,7 @@ void verify_json_insert(TAOS* taos) { cJSON_Delete(payload); } -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) { const char* host = "127.0.0.1"; const char* user = "root"; const char* passwd = "taosdata"; diff --git a/examples/go/taosdemo.go b/examples/go/taosdemo.go index 543cfcc0f65aad154cc411891a76ae2fdb4e0e02..03cab74d6de14928e61c08d8e413b6cff073d547 100644 --- a/examples/go/taosdemo.go +++ b/examples/go/taosdemo.go @@ -26,7 +26,7 @@ import ( "sync" "time" - _ "github.com/taosdata/driver-go/taosSql" + _ "github.com/taosdata/driver-go/v3/taosSql" ) const ( @@ -173,7 +173,7 @@ func createDatabase(dbName string, supTblName string) { time.Sleep(time.Second) // create database - sqlStr = "create database " + dbName + " keep " + strconv.Itoa(configPara.keep) + " days " + strconv.Itoa(configPara.days) + sqlStr = "create database " + dbName _, err = db.Exec(sqlStr) checkErr(err, sqlStr) diff --git a/include/client/taos.h b/include/client/taos.h index 44443752c50abcadfc64ae5373d654824022e109..25887b2879e3d534584f8d857ee3af670c7bcbd1 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -130,17 +130,16 @@ typedef struct TAOS_VGROUP_HASH_INFO { int32_t vgId; uint32_t hashBegin; uint32_t hashEnd; -} TAOS_VGROUP_HASH_INFO ; +} TAOS_VGROUP_HASH_INFO; typedef struct TAOS_DB_ROUTE_INFO { - int32_t routeVersion; - int16_t hashPrefix; - int16_t hashSuffix; - int8_t hashMethod; - int32_t vgNum; + int32_t routeVersion; + int16_t hashPrefix; + int16_t hashSuffix; + int8_t hashMethod; + int32_t vgNum; TAOS_VGROUP_HASH_INFO *vgHash; -} TAOS_DB_ROUTE_INFO ; - +} TAOS_DB_ROUTE_INFO; DLL_EXPORT void taos_cleanup(void); DLL_EXPORT int taos_options(TSDB_OPTION option, const void *arg, ...); @@ -153,6 +152,7 @@ DLL_EXPORT void taos_close(TAOS *taos); const char *taos_data_type(int type); DLL_EXPORT TAOS_STMT *taos_stmt_init(TAOS *taos); +DLL_EXPORT TAOS_STMT *taos_stmt_init_with_reqid(TAOS *taos, int64_t reqid); DLL_EXPORT int taos_stmt_prepare(TAOS_STMT *stmt, const char *sql, unsigned long length); DLL_EXPORT int taos_stmt_set_tbname_tags(TAOS_STMT *stmt, const char *name, TAOS_MULTI_BIND *tags); DLL_EXPORT int taos_stmt_set_tbname(TAOS_STMT *stmt, const char *name); @@ -176,6 +176,7 @@ DLL_EXPORT int taos_stmt_affected_rows(TAOS_STMT *stmt); DLL_EXPORT int taos_stmt_affected_rows_once(TAOS_STMT *stmt); DLL_EXPORT TAOS_RES *taos_query(TAOS *taos, const char *sql); +DLL_EXPORT TAOS_RES *taos_query_with_reqid(TAOS *taos, const char *sql, int64_t reqId); 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 @@ -207,17 +208,23 @@ DLL_EXPORT const char *taos_get_client_info(); DLL_EXPORT const char *taos_errstr(TAOS_RES *res); DLL_EXPORT int taos_errno(TAOS_RES *res); -DLL_EXPORT void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param); -DLL_EXPORT void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param); -DLL_EXPORT void taos_fetch_raw_block_a(TAOS_RES *res, __taos_async_fn_t fp, void *param); +DLL_EXPORT void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param); +DLL_EXPORT void taos_query_a_with_reqid(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param, int64_t reqid); +DLL_EXPORT void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param); +DLL_EXPORT void taos_fetch_raw_block_a(TAOS_RES *res, __taos_async_fn_t fp, void *param); DLL_EXPORT const void *taos_get_raw_block(TAOS_RES *res); -DLL_EXPORT int taos_get_db_route_info(TAOS* taos, const char* db, TAOS_DB_ROUTE_INFO* dbInfo); -DLL_EXPORT int taos_get_table_vgId(TAOS* taos, const char* db, const char* table, int* vgId); +DLL_EXPORT int taos_get_db_route_info(TAOS *taos, const char *db, TAOS_DB_ROUTE_INFO *dbInfo); +DLL_EXPORT int taos_get_table_vgId(TAOS *taos, const char *db, const char *table, int *vgId); DLL_EXPORT int taos_load_table_info(TAOS *taos, const char *tableNameList); DLL_EXPORT TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision); -DLL_EXPORT TAOS_RES *taos_schemaless_insert_raw(TAOS* taos, char* lines, int len, int32_t *totalRows, int protocol, int precision); +DLL_EXPORT TAOS_RES *taos_schemaless_insert_with_reqid(TAOS *taos, char *lines[], int numLines, int protocol, + int precision, int64_t reqid); +DLL_EXPORT TAOS_RES *taos_schemaless_insert_raw(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol, + int precision); +DLL_EXPORT TAOS_RES *taos_schemaless_insert_raw_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows, + int protocol, int precision, int64_t reqid); /* --------------------------TMQ INTERFACE------------------------------- */ diff --git a/include/common/tcommon.h b/include/common/tcommon.h index 2b45a5d206e71d5726cb4f781aa0eccf8c4d371d..674bdcf1718c5bab537e479c2c247d5377c9adb4 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -164,14 +164,6 @@ typedef enum EStreamType { STREAM_FILL_OVER, } EStreamType; -typedef struct { - SArray* pGroupList; - SArray* pTableList; - SHashObj* map; // speedup acquire the tableQueryInfo by table uid - bool needSortTableByGroupId; - uint64_t suid; -} STableListInfo; - #pragma pack(push, 1) typedef struct SColumnDataAgg { int16_t colId; @@ -233,13 +225,13 @@ typedef struct SVarColAttr { // pBlockAgg->numOfNull == info.rows, all data are null // pBlockAgg->numOfNull == 0, no data are null. typedef struct SColumnInfoData { - SColumnInfo info; // column info - bool hasNull; // if current column data has null value. - char* pData; // the corresponding block data in memory + char* pData; // the corresponding block data in memory union { char* nullbitmap; // bitmap, one bit for each item in the list SVarColAttr varmeta; }; + SColumnInfo info; // column info + bool hasNull; // if current column data has null value. } SColumnInfoData; typedef struct SQueryTableDataCond { diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index 24dfa5958dcef1656787f9add4bd8bbfd44d0dbf..502ba10d337d80107b94cb01b182a63d14a63cc9 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -137,6 +137,9 @@ static FORCE_INLINE void colDataAppendNNULL(SColumnInfoData* pColumnInfoData, ui for (int32_t i = start; i < start + nRows; ++i) { colDataSetNull_f(pColumnInfoData->nullbitmap, i); } + + int32_t bytes = pColumnInfoData->info.bytes; + memset(pColumnInfoData->pData + start * bytes, 0, nRows * bytes); } pColumnInfoData->hasNull = true; @@ -215,7 +218,7 @@ size_t blockDataGetSerialMetaSize(uint32_t numOfCols); int32_t blockDataSort(SSDataBlock* pDataBlock, SArray* pOrderInfo); int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullFirst); -int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, uint32_t numOfRows); +int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, uint32_t numOfRows, bool clearPayload); int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows); void colInfoDataCleanup(SColumnInfoData* pColumn, uint32_t numOfRows); @@ -241,7 +244,7 @@ int32_t blockDataAppendColInfo(SSDataBlock* pBlock, SColumnInfoData* pColIn SColumnInfoData createColumnInfoData(int16_t type, int32_t bytes, int16_t colId); SColumnInfoData* bdGetColumnInfoData(const SSDataBlock* pBlock, int32_t index); -void blockEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols, int8_t needCompress); +int32_t blockEncode(const SSDataBlock* pBlock, char* data, int32_t numOfCols); const char* blockDecode(SSDataBlock* pBlock, const char* pData); void blockDebugShowDataBlock(SSDataBlock* pBlock, const char* flag); diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index c0c3fc7fbc931246597a2d7c3fed8bc0febdf96f..2eda2f66cc143ddfd78f883f6c4b79547183d6e5 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -74,9 +74,7 @@ int32_t tTSchemaCreate(int32_t sver, SSchema *pSchema, int32_t nCols, STSchema * void tTSchemaDestroy(STSchema *pTSchema); // SValue ================================ -int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type); -int32_t tGetValue(uint8_t *p, SValue *pValue, int8_t type); -int tValueCmprFn(const SValue *pValue1, const SValue *pValue2, int8_t type); +static FORCE_INLINE int32_t tGetValue(uint8_t *p, SValue *pValue, int8_t type); // SColVal ================================ #define CV_FLAG_VALUE ((int8_t)0x0) @@ -132,8 +130,9 @@ void tColDataInit(SColData *pColData, int16_t cid, int8_t type, int8_t smaOn) void tColDataClear(SColData *pColData); int32_t tColDataAppendValue(SColData *pColData, SColVal *pColVal); void tColDataGetValue(SColData *pColData, int32_t iVal, SColVal *pColVal); -uint8_t tColDataGetBitValue(SColData *pColData, int32_t iVal); +uint8_t tColDataGetBitValue(const SColData *pColData, int32_t iVal); int32_t tColDataCopy(SColData *pColDataSrc, SColData *pColDataDest); +extern void (*tColDataCalcSMA[])(SColData *pColData, int64_t *sum, int64_t *max, int64_t *min, int16_t *numOfNull); // STRUCT ================================ struct STColumn { @@ -241,13 +240,6 @@ struct STag { memcpy(varDataVal(x), (str), __len); \ } while (0); -#define STR_TO_NET_VARSTR(x, str) \ - do { \ - VarDataLenT __len = (VarDataLenT)strlen(str); \ - *(VarDataLenT *)(x) = htons(__len); \ - memcpy(varDataVal(x), (str), __len); \ - } while (0); - #define STR_WITH_MAXSIZE_TO_VARSTR(x, str, _maxs) \ do { \ char *_e = stpncpy(varDataVal(x), (str), (_maxs)-VARSTR_HEADER_SIZE); \ @@ -289,6 +281,15 @@ void tdResetTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version) int32_t tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int8_t flags, col_id_t colId, col_bytes_t bytes); STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder); +static FORCE_INLINE int32_t tGetValue(uint8_t *p, SValue *pValue, int8_t type) { + if (IS_VAR_DATA_TYPE(type)) { + return tGetBinary(p, &pValue->pData, pValue ? &pValue->nData : NULL); + } else { + memcpy(&pValue->val, p, tDataTypes[type].bytes); + return tDataTypes[type].bytes; + } +} + #endif #ifdef __cplusplus diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 4a2e14eb78a6d79aff12279c4170167ea6e80b0b..681d1beb7983adef7579a45a09fe809e4c30a271 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -55,13 +55,11 @@ extern int32_t tsNumOfMnodeReadThreads; extern int32_t tsNumOfVnodeQueryThreads; extern int32_t tsNumOfVnodeStreamThreads; extern int32_t tsNumOfVnodeFetchThreads; -extern int32_t tsNumOfVnodeWriteThreads; -extern int32_t tsNumOfVnodeSyncThreads; extern int32_t tsNumOfVnodeRsmaThreads; extern int32_t tsNumOfQnodeQueryThreads; extern int32_t tsNumOfQnodeFetchThreads; -extern int32_t tsNumOfSnodeSharedThreads; -extern int32_t tsNumOfSnodeUniqueThreads; +extern int32_t tsNumOfSnodeStreamThreads; +extern int32_t tsNumOfSnodeWriteThreads; extern int64_t tsRpcQueueMemoryAllowed; // monitor @@ -91,6 +89,7 @@ extern bool tsQueryPlannerTrace; extern int32_t tsQueryNodeChunkSize; extern bool tsQueryUseNodeAllocator; extern bool tsKeepColumnName; +extern bool tsEnableQueryHb; // client extern int32_t tsMinSlidingTime; @@ -118,12 +117,16 @@ extern SDiskCfg tsDiskCfg[]; // udf extern bool tsStartUdfd; extern char tsUdfdResFuncs[]; +extern char tsUdfdLdLibPath[]; // schemaless extern char tsSmlChildTableName[]; extern char tsSmlTagName[]; extern bool tsSmlDataFormat; +// wal +extern int64_t tsWalFsyncDataSizeLimit; + // internal extern int32_t tsTransPullupInterval; extern int32_t tsMqRebalanceInterval; diff --git a/include/common/tmsg.h b/include/common/tmsg.h index a0f78d0d590c05938e046a6487655ac98d6b3647..db7d0640f60c81ee5ed4e04bb86b19af287c91df 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -57,9 +57,11 @@ extern int32_t tMsgDict[]; #define TMSG_SEG_SEQ(TYPE) ((TYPE)&0xff) #define TMSG_INFO(TYPE) \ ((TYPE) < TDMT_DND_MAX_MSG || (TYPE) < TDMT_MND_MAX_MSG || (TYPE) < TDMT_VND_MAX_MSG || (TYPE) < TDMT_SCH_MAX_MSG || \ - (TYPE) < TDMT_STREAM_MAX_MSG || (TYPE) < TDMT_MON_MAX_MSG || (TYPE) < TDMT_SYNC_MAX_MSG) \ + (TYPE) < TDMT_STREAM_MAX_MSG || (TYPE) < TDMT_MON_MAX_MSG || (TYPE) < TDMT_SYNC_MAX_MSG) || \ + (TYPE) < TDMT_VND_STREAM_MSG || (TYPE) < TDMT_VND_TMQ_MSG \ ? tMsgInfo[tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE)] \ : 0 + #define TMSG_INDEX(TYPE) (tMsgDict[TMSG_SEG_CODE(TYPE)] + TMSG_SEG_SEQ(TYPE)) typedef uint16_t tmsg_t; @@ -295,7 +297,6 @@ typedef struct { typedef struct { int32_t code; - int8_t hashMeta; int64_t uid; char* tblFName; int32_t numOfRows; @@ -837,6 +838,7 @@ typedef struct { int64_t dbId; int32_t vgVersion; int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT + int64_t stateTs; // ms } SUseDbReq; int32_t tSerializeSUseDbReq(void* buf, int32_t bufLen, SUseDbReq* pReq); @@ -851,6 +853,8 @@ typedef struct { int16_t hashSuffix; int8_t hashMethod; SArray* pVgroupInfos; // Array of SVgroupInfo + int32_t errCode; + int64_t stateTs; // ms } SUseDbRsp; int32_t tSerializeSUseDbRsp(void* buf, int32_t bufLen, const SUseDbRsp* pRsp); @@ -1126,6 +1130,7 @@ typedef struct { SQnodeLoad qload; SClusterCfg clusterCfg; SArray* pVloads; // array of SVnodeLoad + int32_t statusSeq; } SStatusReq; int32_t tSerializeSStatusReq(void* buf, int32_t bufLen, SStatusReq* pReq); @@ -1147,6 +1152,7 @@ typedef struct { int64_t dnodeVer; SDnodeCfg dnodeCfg; SArray* pDnodeEps; // Array of SDnodeEp + int32_t statusSeq; } SStatusRsp; int32_t tSerializeSStatusRsp(void* buf, int32_t bufLen, SStatusRsp* pRsp); @@ -1478,6 +1484,7 @@ typedef struct { int32_t dnodeId; char fqdn[TSDB_FQDN_LEN]; int32_t port; + int8_t force; } SDropDnodeReq; int32_t tSerializeSDropDnodeReq(void* buf, int32_t bufLen, SDropDnodeReq* pReq); @@ -1607,6 +1614,7 @@ typedef struct SSubQueryMsg { int8_t needFetch; uint32_t sqlLen; // the query sql, uint32_t phyLen; + int32_t msgMask; char msg[]; } SSubQueryMsg; @@ -1726,6 +1734,9 @@ typedef struct { #define STREAM_TRIGGER_WINDOW_CLOSE 2 #define STREAM_TRIGGER_MAX_DELAY 3 #define STREAM_DEFAULT_IGNORE_EXPIRED 0 +#define STREAM_FILL_HISTORY_ON 1 +#define STREAM_FILL_HISTORY_OFF 0 +#define STREAM_DEFAULT_FILL_HISTORY STREAM_FILL_HISTORY_OFF typedef struct { char name[TSDB_STREAM_FNAME_LEN]; @@ -1794,7 +1805,7 @@ int32_t tDeserializeSCMCreateTopicRsp(void* buf, int32_t bufLen, SCMCreateTopicR typedef struct { int64_t consumerId; -} SMqConsumerLostMsg, SMqConsumerRecoverMsg; +} SMqConsumerLostMsg, SMqConsumerRecoverMsg, SMqConsumerClearMsg; typedef struct { int64_t consumerId; @@ -3125,7 +3136,8 @@ int32_t tEncodeDeleteRes(SEncoder* pCoder, const SDeleteRes* pRes); int32_t tDecodeDeleteRes(SDecoder* pCoder, SDeleteRes* pRes); typedef struct { - int64_t uid; + // int64_t uid; + char tbname[TSDB_TABLE_NAME_LEN]; int64_t ts; } SSingleDeleteReq; diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index be4bf0e4d2b17b3a3f139e1a4c3212d7f367c9ab..a12a63583702c5b34fb0d9c8a4ab400144ec3849 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -138,18 +138,18 @@ enum { TD_DEF_MSG_TYPE(TDMT_MND_GET_TABLE_INDEX, "get-table-index", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_BATCH_META, "batch-meta", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_TABLE_CFG, "table-cfg", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_MND_CREATE_TOPIC, "create-topic", SMCreateTopicReq, SMCreateTopicRsp) - TD_DEF_MSG_TYPE(TDMT_MND_ALTER_TOPIC, "alter-topic", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_MND_DROP_TOPIC, "drop-topic", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_MND_SUBSCRIBE, "subscribe", SCMSubscribeReq, SCMSubscribeRsp) - TD_DEF_MSG_TYPE(TDMT_MND_MQ_ASK_EP, "ask-ep", SMqAskEpReq, SMqAskEpRsp) - TD_DEF_MSG_TYPE(TDMT_MND_MQ_CONSUMER_LOST, "consumer-lost", SMqConsumerLostMsg, NULL) - TD_DEF_MSG_TYPE(TDMT_MND_MQ_CONSUMER_RECOVER, "consumer-recover", SMqConsumerRecoverMsg, NULL) - TD_DEF_MSG_TYPE(TDMT_MND_MQ_HB, "consumer-hb", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_MND_MQ_DO_REBALANCE, "do-rebalance", SMqDoRebalanceMsg, NULL) - TD_DEF_MSG_TYPE(TDMT_MND_MQ_DROP_CGROUP, "drop-cgroup", SMqDropCGroupReq, SMqDropCGroupRsp) - TD_DEF_MSG_TYPE(TDMT_MND_MQ_COMMIT_OFFSET, "mnode-commit-offset", SMqCMCommitOffsetReq, SMqCMCommitOffsetRsp) - TD_DEF_MSG_TYPE(TDMT_MND_MQ_TIMER, "mq-tmr", SMTimerReq, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_TMQ_CREATE_TOPIC, "create-topic", SMCreateTopicReq, SMCreateTopicRsp) + TD_DEF_MSG_TYPE(TDMT_MND_UNUSED1, "unused", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_TMQ_DROP_TOPIC, "drop-topic", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_TMQ_SUBSCRIBE, "subscribe", SCMSubscribeReq, SCMSubscribeRsp) + TD_DEF_MSG_TYPE(TDMT_MND_TMQ_ASK_EP, "ask-ep", SMqAskEpReq, SMqAskEpRsp) + TD_DEF_MSG_TYPE(TDMT_MND_TMQ_CONSUMER_LOST, "consumer-lost", SMqConsumerLostMsg, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_TMQ_CONSUMER_RECOVER, "consumer-recover", SMqConsumerRecoverMsg, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_TMQ_HB, "consumer-hb", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_TMQ_DO_REBALANCE, "do-rebalance", SMqDoRebalanceMsg, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_TMQ_DROP_CGROUP, "drop-cgroup", SMqDropCGroupReq, SMqDropCGroupRsp) + TD_DEF_MSG_TYPE(TDMT_MND_UNUSED2, "unused2", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_TMQ_TIMER, "tmq-tmr", SMTimerReq, NULL) TD_DEF_MSG_TYPE(TDMT_MND_TELEM_TIMER, "telem-tmr", SMTimerReq, SMTimerReq) TD_DEF_MSG_TYPE(TDMT_MND_TRANS_TIMER, "trans-tmr", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_TTL_TIMER, "ttl-tmr", NULL, NULL) @@ -171,6 +171,7 @@ enum { TD_DEF_MSG_TYPE(TDMT_MND_SHOW_VARIABLES, "show-variables", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_SERVER_VERSION, "server-version", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_UPTIME_TIMER, "uptime-timer", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_MND_TMQ_LOST_CONSUMER_CLEAR, "lost-consumer-clear", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_MND_MAX_MSG, "mnd-max", NULL, NULL) TD_NEW_MSG_SEG(TDMT_VND_MSG) @@ -186,21 +187,21 @@ enum { TD_DEF_MSG_TYPE(TDMT_VND_CREATE_STB, "vnode-create-stb", SVCreateStbReq, NULL) TD_DEF_MSG_TYPE(TDMT_VND_ALTER_STB, "vnode-alter-stb", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_DROP_STB, "vnode-drop-stb", SVDropStbReq, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_MQ_VG_CHANGE, "vnode-mq-vg-change", SMqRebVgReq, SMqRebVgRsp) - TD_DEF_MSG_TYPE(TDMT_VND_MQ_VG_DELETE, "vnode-mq-vg-delete", SMqVDeleteReq, SMqVDeleteRsp) - TD_DEF_MSG_TYPE(TDMT_VND_MQ_COMMIT_OFFSET, "vnode-commit-offset", STqOffset, STqOffset) - TD_DEF_MSG_TYPE(TDMT_VND_ADD_CHECK_INFO, "vnode-add-check-info", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_DELETE_CHECK_INFO, "vnode-delete-check-info", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_CREATE_TOPIC, "vnode-create-topic", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_ALTER_TOPIC, "vnode-alter-topic", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_DROP_TOPIC, "vnode-drop-topic", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_SUBSCRIBE, "vnode-subscribe", SMVSubscribeReq, SMVSubscribeRsp) - TD_DEF_MSG_TYPE(TDMT_VND_CONSUME, "vnode-consume", SMqPollReq, SMqDataBlkRsp) - TD_DEF_MSG_TYPE(TDMT_VND_STREAM_TRIGGER, "vnode-stream-trigger", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_STREAM_DISPATCH_WRITE, "vnode-stream-task-dispatch-write", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_STREAM_RECOVER_STEP1, "vnode-stream-recover1", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_STREAM_RECOVER_STEP2, "vnode-stream-recover2", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_VND_STREAM_RECOVER_FINISH, "vnode-stream-finish", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_UNUSED1, "vnode-unused1", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_UNUSED2, "vnode-unused2", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_UNUSED3, "vnode-unused3", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_UNUSED4, "vnode-unused4", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_UNUSED5, "vnode-unused5", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_UNUSED6, "vnode-unused6", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_UNUSED7, "vnode-unused7", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_UNUSED8, "vnode-unused8", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_UNUSED9, "vnode-unused9", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_UNUSED10, "vnode-unused10", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_UNUSED11, "vnode-unused11", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_UNUSED12, "vnode-unused12", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_UNUSED13, "vnode-unused13", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_UNUSED14, "vnode-unused14", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_UNUSED15, "vnode-unused15", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_CREATE_SMA, "vnode-create-sma", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_CANCEL_SMA, "vnode-cancel-sma", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_DROP_SMA, "vnode-drop-sma", NULL, NULL) @@ -232,13 +233,16 @@ enum { TD_DEF_MSG_TYPE(TDMT_SCH_LINK_BROKEN, "link-broken", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SCH_MAX_MSG, "sch-max", NULL, NULL) + TD_NEW_MSG_SEG(TDMT_STREAM_MSG) TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_DEPLOY, "stream-task-deploy", SStreamTaskDeployReq, SStreamTaskDeployRsp) TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_DROP, "stream-task-drop", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_RUN, "stream-task-run", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_DISPATCH, "stream-task-dispatch", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_RECOVER, "stream-task-recover", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_STREAM_UNUSED1, "stream-unused1", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_STREAM_RETRIEVE, "stream-retrieve", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_STREAM_RECOVER_FINISH, "vnode-stream-finish", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_STREAM_TASK_CHECK, "vnode-stream-task-check", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_STREAM_MAX_MSG, "stream-max", NULL, NULL) TD_NEW_MSG_SEG(TDMT_MON_MSG) @@ -260,8 +264,8 @@ enum { TD_DEF_MSG_TYPE(TDMT_SYNC_UNKNOWN, "sync-unknown", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_COMMON_RESPONSE, "sync-common-response", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_APPLY_MSG, "sync-apply-msg", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_SYNC_CONFIG_CHANGE, "sync-config-change", NULL, NULL) - TD_DEF_MSG_TYPE(TDMT_SYNC_CONFIG_CHANGE_FINISH, "sync-config-change-finish", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_SYNC_CONFIG_CHANGE, "sync-config-change", NULL, NULL) // no longer used + TD_DEF_MSG_TYPE(TDMT_SYNC_CONFIG_CHANGE_FINISH, "sync-config-change-finish", NULL, NULL) // no longer used TD_DEF_MSG_TYPE(TDMT_SYNC_SNAPSHOT_SEND, "sync-snapshot-send", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_SNAPSHOT_RSP, "sync-snapshot-rsp", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_LEADER_TRANSFER, "sync-leader-transfer", NULL, NULL) @@ -269,8 +273,27 @@ enum { TD_DEF_MSG_TYPE(TDMT_SYNC_SET_VNODE_STANDBY, "set-vnode-standby", NULL, NULL) // no longer used TD_DEF_MSG_TYPE(TDMT_SYNC_HEARTBEAT, "sync-heartbeat", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_HEARTBEAT_REPLY, "sync-heartbeat-reply", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_SYNC_LOCAL_CMD, "sync-local-cmd", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_SYNC_PRE_SNAPSHOT, "sync-pre-snapshot", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_SYNC_PRE_SNAPSHOT_REPLY, "sync-pre-snapshot-reply", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_SYNC_MAX_MSG, "sync-max", NULL, NULL) + TD_NEW_MSG_SEG(TDMT_VND_STREAM_MSG) + TD_DEF_MSG_TYPE(TDMT_VND_STREAM_TRIGGER, "vnode-stream-trigger", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_STREAM_RECOVER_STEP1, "vnode-stream-recover1", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_STREAM_RECOVER_STEP2, "vnode-stream-recover2", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_STREAM_MAX_MSG, "vnd-stream-max", NULL, NULL) + + TD_NEW_MSG_SEG(TDMT_VND_TMQ_MSG) + TD_DEF_MSG_TYPE(TDMT_VND_TMQ_SUBSCRIBE, "vnode-tmq-subscribe", SMqRebVgReq, SMqRebVgRsp) + TD_DEF_MSG_TYPE(TDMT_VND_TMQ_DELETE_SUB, "vnode-tmq-delete-sub", SMqVDeleteReq, SMqVDeleteRsp) + TD_DEF_MSG_TYPE(TDMT_VND_TMQ_COMMIT_OFFSET, "vnode-tmq-commit-offset", STqOffset, STqOffset) + TD_DEF_MSG_TYPE(TDMT_VND_TMQ_ADD_CHECKINFO, "vnode-tmq-add-checkinfo", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_TMQ_DEL_CHECKINFO, "vnode-del-checkinfo", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_TMQ_CONSUME, "vnode-tmq-consume", SMqPollReq, SMqDataBlkRsp) + TD_DEF_MSG_TYPE(TDMT_VND_TMQ_MAX_MSG, "vnd-tmq-max", NULL, NULL) + + #if defined(TD_MSG_NUMBER_) TDMT_MAX #endif diff --git a/include/common/tname.h b/include/common/tname.h index 8c594a2b5ebbb8b9d71f54d01ac0d867ddb5c133..666a25303ebae0d9098c50e10d4a8c4df0e7624f 100644 --- a/include/common/tname.h +++ b/include/common/tname.h @@ -72,13 +72,13 @@ bool tNameTbNameEqual(SName* left, SName* right); typedef struct { // input - SArray* tags; // element is SSmlKv - const char* sTableName; // super table name - uint8_t sTableNameLen; // the length of super table name + SArray* tags; // element is SSmlKv + const char* stbFullName; // super table name + uint8_t stbFullNameLen; // the length of super table name // output - char* childTableName; // must have size of TSDB_TABLE_NAME_LEN; - uint64_t uid; // child table uid, may be useful + char* ctbShortName; // must have size of TSDB_TABLE_NAME_LEN; + uint64_t uid; // child table uid, may be useful } RandTableName; void buildChildTableName(RandTableName* rName); diff --git a/include/common/ttokendef.h b/include/common/ttokendef.h index 64d0ecc21115dec9468aa253a457f729422419d7..f5c99fcae75295c1793ba38d7774d63211ef3afb 100644 --- a/include/common/ttokendef.h +++ b/include/common/ttokendef.h @@ -66,279 +66,281 @@ #define TK_PORT 48 #define TK_DNODES 49 #define TK_NK_IPTOKEN 50 -#define TK_LOCAL 51 -#define TK_QNODE 52 -#define TK_BNODE 53 -#define TK_SNODE 54 -#define TK_MNODE 55 -#define TK_DATABASE 56 -#define TK_USE 57 -#define TK_FLUSH 58 -#define TK_TRIM 59 -#define TK_IF 60 -#define TK_NOT 61 -#define TK_EXISTS 62 -#define TK_BUFFER 63 -#define TK_CACHEMODEL 64 -#define TK_CACHESIZE 65 -#define TK_COMP 66 -#define TK_DURATION 67 -#define TK_NK_VARIABLE 68 -#define TK_MAXROWS 69 -#define TK_MINROWS 70 -#define TK_KEEP 71 -#define TK_PAGES 72 -#define TK_PAGESIZE 73 -#define TK_TSDB_PAGESIZE 74 -#define TK_PRECISION 75 -#define TK_REPLICA 76 -#define TK_STRICT 77 -#define TK_VGROUPS 78 -#define TK_SINGLE_STABLE 79 -#define TK_RETENTIONS 80 -#define TK_SCHEMALESS 81 -#define TK_WAL_LEVEL 82 -#define TK_WAL_FSYNC_PERIOD 83 -#define TK_WAL_RETENTION_PERIOD 84 -#define TK_WAL_RETENTION_SIZE 85 -#define TK_WAL_ROLL_PERIOD 86 -#define TK_WAL_SEGMENT_SIZE 87 -#define TK_STT_TRIGGER 88 -#define TK_TABLE_PREFIX 89 -#define TK_TABLE_SUFFIX 90 -#define TK_NK_COLON 91 -#define TK_MAX_SPEED 92 -#define TK_TABLE 93 -#define TK_NK_LP 94 -#define TK_NK_RP 95 -#define TK_STABLE 96 -#define TK_ADD 97 -#define TK_COLUMN 98 -#define TK_MODIFY 99 -#define TK_RENAME 100 -#define TK_TAG 101 -#define TK_SET 102 -#define TK_NK_EQ 103 -#define TK_USING 104 -#define TK_TAGS 105 -#define TK_COMMENT 106 -#define TK_BOOL 107 -#define TK_TINYINT 108 -#define TK_SMALLINT 109 -#define TK_INT 110 -#define TK_INTEGER 111 -#define TK_BIGINT 112 -#define TK_FLOAT 113 -#define TK_DOUBLE 114 -#define TK_BINARY 115 -#define TK_TIMESTAMP 116 -#define TK_NCHAR 117 -#define TK_UNSIGNED 118 -#define TK_JSON 119 -#define TK_VARCHAR 120 -#define TK_MEDIUMBLOB 121 -#define TK_BLOB 122 -#define TK_VARBINARY 123 -#define TK_DECIMAL 124 -#define TK_MAX_DELAY 125 -#define TK_WATERMARK 126 -#define TK_ROLLUP 127 -#define TK_TTL 128 -#define TK_SMA 129 -#define TK_FIRST 130 -#define TK_LAST 131 -#define TK_SHOW 132 -#define TK_DATABASES 133 -#define TK_TABLES 134 -#define TK_STABLES 135 -#define TK_MNODES 136 -#define TK_QNODES 137 -#define TK_FUNCTIONS 138 -#define TK_INDEXES 139 -#define TK_ACCOUNTS 140 -#define TK_APPS 141 -#define TK_CONNECTIONS 142 -#define TK_LICENCES 143 -#define TK_GRANTS 144 -#define TK_QUERIES 145 -#define TK_SCORES 146 -#define TK_TOPICS 147 -#define TK_VARIABLES 148 -#define TK_CLUSTER 149 -#define TK_BNODES 150 -#define TK_SNODES 151 -#define TK_TRANSACTIONS 152 -#define TK_DISTRIBUTED 153 -#define TK_CONSUMERS 154 -#define TK_SUBSCRIPTIONS 155 -#define TK_VNODES 156 -#define TK_LIKE 157 -#define TK_INDEX 158 -#define TK_FUNCTION 159 -#define TK_INTERVAL 160 -#define TK_TOPIC 161 -#define TK_AS 162 -#define TK_WITH 163 -#define TK_META 164 -#define TK_CONSUMER 165 -#define TK_GROUP 166 -#define TK_DESC 167 -#define TK_DESCRIBE 168 -#define TK_RESET 169 -#define TK_QUERY 170 -#define TK_CACHE 171 -#define TK_EXPLAIN 172 -#define TK_ANALYZE 173 -#define TK_VERBOSE 174 -#define TK_NK_BOOL 175 -#define TK_RATIO 176 -#define TK_NK_FLOAT 177 -#define TK_OUTPUTTYPE 178 -#define TK_AGGREGATE 179 -#define TK_BUFSIZE 180 -#define TK_STREAM 181 -#define TK_INTO 182 -#define TK_TRIGGER 183 -#define TK_AT_ONCE 184 -#define TK_WINDOW_CLOSE 185 -#define TK_IGNORE 186 -#define TK_EXPIRED 187 -#define TK_SUBTABLE 188 -#define TK_KILL 189 -#define TK_CONNECTION 190 -#define TK_TRANSACTION 191 -#define TK_BALANCE 192 -#define TK_VGROUP 193 -#define TK_MERGE 194 -#define TK_REDISTRIBUTE 195 -#define TK_SPLIT 196 -#define TK_DELETE 197 -#define TK_INSERT 198 -#define TK_NULL 199 -#define TK_NK_QUESTION 200 -#define TK_NK_ARROW 201 -#define TK_ROWTS 202 -#define TK_TBNAME 203 -#define TK_QSTART 204 -#define TK_QEND 205 -#define TK_QDURATION 206 -#define TK_WSTART 207 -#define TK_WEND 208 -#define TK_WDURATION 209 -#define TK_IROWTS 210 -#define TK_QTAGS 211 -#define TK_CAST 212 -#define TK_NOW 213 -#define TK_TODAY 214 -#define TK_TIMEZONE 215 -#define TK_CLIENT_VERSION 216 -#define TK_SERVER_VERSION 217 -#define TK_SERVER_STATUS 218 -#define TK_CURRENT_USER 219 -#define TK_COUNT 220 -#define TK_LAST_ROW 221 -#define TK_CASE 222 -#define TK_END 223 -#define TK_WHEN 224 -#define TK_THEN 225 -#define TK_ELSE 226 -#define TK_BETWEEN 227 -#define TK_IS 228 -#define TK_NK_LT 229 -#define TK_NK_GT 230 -#define TK_NK_LE 231 -#define TK_NK_GE 232 -#define TK_NK_NE 233 -#define TK_MATCH 234 -#define TK_NMATCH 235 -#define TK_CONTAINS 236 -#define TK_IN 237 -#define TK_JOIN 238 -#define TK_INNER 239 -#define TK_SELECT 240 -#define TK_DISTINCT 241 -#define TK_WHERE 242 -#define TK_PARTITION 243 -#define TK_BY 244 -#define TK_SESSION 245 -#define TK_STATE_WINDOW 246 -#define TK_SLIDING 247 -#define TK_FILL 248 -#define TK_VALUE 249 -#define TK_NONE 250 -#define TK_PREV 251 -#define TK_LINEAR 252 -#define TK_NEXT 253 -#define TK_HAVING 254 -#define TK_RANGE 255 -#define TK_EVERY 256 -#define TK_ORDER 257 -#define TK_SLIMIT 258 -#define TK_SOFFSET 259 -#define TK_LIMIT 260 -#define TK_OFFSET 261 -#define TK_ASC 262 -#define TK_NULLS 263 -#define TK_ABORT 264 -#define TK_AFTER 265 -#define TK_ATTACH 266 -#define TK_BEFORE 267 -#define TK_BEGIN 268 -#define TK_BITAND 269 -#define TK_BITNOT 270 -#define TK_BITOR 271 -#define TK_BLOCKS 272 -#define TK_CHANGE 273 -#define TK_COMMA 274 -#define TK_COMPACT 275 -#define TK_CONCAT 276 -#define TK_CONFLICT 277 -#define TK_COPY 278 -#define TK_DEFERRED 279 -#define TK_DELIMITERS 280 -#define TK_DETACH 281 -#define TK_DIVIDE 282 -#define TK_DOT 283 -#define TK_EACH 284 -#define TK_FAIL 285 -#define TK_FILE 286 -#define TK_FOR 287 -#define TK_GLOB 288 -#define TK_ID 289 -#define TK_IMMEDIATE 290 -#define TK_IMPORT 291 -#define TK_INITIALLY 292 -#define TK_INSTEAD 293 -#define TK_ISNULL 294 -#define TK_KEY 295 -#define TK_MODULES 296 -#define TK_NK_BITNOT 297 -#define TK_NK_SEMI 298 -#define TK_NOTNULL 299 -#define TK_OF 300 -#define TK_PLUS 301 -#define TK_PRIVILEGE 302 -#define TK_RAISE 303 -#define TK_REPLACE 304 -#define TK_RESTRICT 305 -#define TK_ROW 306 -#define TK_SEMI 307 -#define TK_STAR 308 -#define TK_STATEMENT 309 -#define TK_STRING 310 -#define TK_TIMES 311 -#define TK_UPDATE 312 -#define TK_VALUES 313 -#define TK_VARIABLE 314 -#define TK_VIEW 315 -#define TK_WAL 316 +#define TK_FORCE 51 +#define TK_LOCAL 52 +#define TK_QNODE 53 +#define TK_BNODE 54 +#define TK_SNODE 55 +#define TK_MNODE 56 +#define TK_DATABASE 57 +#define TK_USE 58 +#define TK_FLUSH 59 +#define TK_TRIM 60 +#define TK_IF 61 +#define TK_NOT 62 +#define TK_EXISTS 63 +#define TK_BUFFER 64 +#define TK_CACHEMODEL 65 +#define TK_CACHESIZE 66 +#define TK_COMP 67 +#define TK_DURATION 68 +#define TK_NK_VARIABLE 69 +#define TK_MAXROWS 70 +#define TK_MINROWS 71 +#define TK_KEEP 72 +#define TK_PAGES 73 +#define TK_PAGESIZE 74 +#define TK_TSDB_PAGESIZE 75 +#define TK_PRECISION 76 +#define TK_REPLICA 77 +#define TK_STRICT 78 +#define TK_VGROUPS 79 +#define TK_SINGLE_STABLE 80 +#define TK_RETENTIONS 81 +#define TK_SCHEMALESS 82 +#define TK_WAL_LEVEL 83 +#define TK_WAL_FSYNC_PERIOD 84 +#define TK_WAL_RETENTION_PERIOD 85 +#define TK_WAL_RETENTION_SIZE 86 +#define TK_WAL_ROLL_PERIOD 87 +#define TK_WAL_SEGMENT_SIZE 88 +#define TK_STT_TRIGGER 89 +#define TK_TABLE_PREFIX 90 +#define TK_TABLE_SUFFIX 91 +#define TK_NK_COLON 92 +#define TK_MAX_SPEED 93 +#define TK_TABLE 94 +#define TK_NK_LP 95 +#define TK_NK_RP 96 +#define TK_STABLE 97 +#define TK_ADD 98 +#define TK_COLUMN 99 +#define TK_MODIFY 100 +#define TK_RENAME 101 +#define TK_TAG 102 +#define TK_SET 103 +#define TK_NK_EQ 104 +#define TK_USING 105 +#define TK_TAGS 106 +#define TK_COMMENT 107 +#define TK_BOOL 108 +#define TK_TINYINT 109 +#define TK_SMALLINT 110 +#define TK_INT 111 +#define TK_INTEGER 112 +#define TK_BIGINT 113 +#define TK_FLOAT 114 +#define TK_DOUBLE 115 +#define TK_BINARY 116 +#define TK_TIMESTAMP 117 +#define TK_NCHAR 118 +#define TK_UNSIGNED 119 +#define TK_JSON 120 +#define TK_VARCHAR 121 +#define TK_MEDIUMBLOB 122 +#define TK_BLOB 123 +#define TK_VARBINARY 124 +#define TK_DECIMAL 125 +#define TK_MAX_DELAY 126 +#define TK_WATERMARK 127 +#define TK_ROLLUP 128 +#define TK_TTL 129 +#define TK_SMA 130 +#define TK_FIRST 131 +#define TK_LAST 132 +#define TK_SHOW 133 +#define TK_DATABASES 134 +#define TK_TABLES 135 +#define TK_STABLES 136 +#define TK_MNODES 137 +#define TK_QNODES 138 +#define TK_FUNCTIONS 139 +#define TK_INDEXES 140 +#define TK_ACCOUNTS 141 +#define TK_APPS 142 +#define TK_CONNECTIONS 143 +#define TK_LICENCES 144 +#define TK_GRANTS 145 +#define TK_QUERIES 146 +#define TK_SCORES 147 +#define TK_TOPICS 148 +#define TK_VARIABLES 149 +#define TK_CLUSTER 150 +#define TK_BNODES 151 +#define TK_SNODES 152 +#define TK_TRANSACTIONS 153 +#define TK_DISTRIBUTED 154 +#define TK_CONSUMERS 155 +#define TK_SUBSCRIPTIONS 156 +#define TK_VNODES 157 +#define TK_LIKE 158 +#define TK_INDEX 159 +#define TK_FUNCTION 160 +#define TK_INTERVAL 161 +#define TK_TOPIC 162 +#define TK_AS 163 +#define TK_WITH 164 +#define TK_META 165 +#define TK_CONSUMER 166 +#define TK_GROUP 167 +#define TK_DESC 168 +#define TK_DESCRIBE 169 +#define TK_RESET 170 +#define TK_QUERY 171 +#define TK_CACHE 172 +#define TK_EXPLAIN 173 +#define TK_ANALYZE 174 +#define TK_VERBOSE 175 +#define TK_NK_BOOL 176 +#define TK_RATIO 177 +#define TK_NK_FLOAT 178 +#define TK_OUTPUTTYPE 179 +#define TK_AGGREGATE 180 +#define TK_BUFSIZE 181 +#define TK_STREAM 182 +#define TK_INTO 183 +#define TK_TRIGGER 184 +#define TK_AT_ONCE 185 +#define TK_WINDOW_CLOSE 186 +#define TK_IGNORE 187 +#define TK_EXPIRED 188 +#define TK_FILL_HISTORY 189 +#define TK_SUBTABLE 190 +#define TK_KILL 191 +#define TK_CONNECTION 192 +#define TK_TRANSACTION 193 +#define TK_BALANCE 194 +#define TK_VGROUP 195 +#define TK_MERGE 196 +#define TK_REDISTRIBUTE 197 +#define TK_SPLIT 198 +#define TK_DELETE 199 +#define TK_INSERT 200 +#define TK_NULL 201 +#define TK_NK_QUESTION 202 +#define TK_NK_ARROW 203 +#define TK_ROWTS 204 +#define TK_TBNAME 205 +#define TK_QSTART 206 +#define TK_QEND 207 +#define TK_QDURATION 208 +#define TK_WSTART 209 +#define TK_WEND 210 +#define TK_WDURATION 211 +#define TK_IROWTS 212 +#define TK_QTAGS 213 +#define TK_CAST 214 +#define TK_NOW 215 +#define TK_TODAY 216 +#define TK_TIMEZONE 217 +#define TK_CLIENT_VERSION 218 +#define TK_SERVER_VERSION 219 +#define TK_SERVER_STATUS 220 +#define TK_CURRENT_USER 221 +#define TK_COUNT 222 +#define TK_LAST_ROW 223 +#define TK_CASE 224 +#define TK_END 225 +#define TK_WHEN 226 +#define TK_THEN 227 +#define TK_ELSE 228 +#define TK_BETWEEN 229 +#define TK_IS 230 +#define TK_NK_LT 231 +#define TK_NK_GT 232 +#define TK_NK_LE 233 +#define TK_NK_GE 234 +#define TK_NK_NE 235 +#define TK_MATCH 236 +#define TK_NMATCH 237 +#define TK_CONTAINS 238 +#define TK_IN 239 +#define TK_JOIN 240 +#define TK_INNER 241 +#define TK_SELECT 242 +#define TK_DISTINCT 243 +#define TK_WHERE 244 +#define TK_PARTITION 245 +#define TK_BY 246 +#define TK_SESSION 247 +#define TK_STATE_WINDOW 248 +#define TK_SLIDING 249 +#define TK_FILL 250 +#define TK_VALUE 251 +#define TK_NONE 252 +#define TK_PREV 253 +#define TK_LINEAR 254 +#define TK_NEXT 255 +#define TK_HAVING 256 +#define TK_RANGE 257 +#define TK_EVERY 258 +#define TK_ORDER 259 +#define TK_SLIMIT 260 +#define TK_SOFFSET 261 +#define TK_LIMIT 262 +#define TK_OFFSET 263 +#define TK_ASC 264 +#define TK_NULLS 265 +#define TK_ABORT 266 +#define TK_AFTER 267 +#define TK_ATTACH 268 +#define TK_BEFORE 269 +#define TK_BEGIN 270 +#define TK_BITAND 271 +#define TK_BITNOT 272 +#define TK_BITOR 273 +#define TK_BLOCKS 274 +#define TK_CHANGE 275 +#define TK_COMMA 276 +#define TK_COMPACT 277 +#define TK_CONCAT 278 +#define TK_CONFLICT 279 +#define TK_COPY 280 +#define TK_DEFERRED 281 +#define TK_DELIMITERS 282 +#define TK_DETACH 283 +#define TK_DIVIDE 284 +#define TK_DOT 285 +#define TK_EACH 286 +#define TK_FAIL 287 +#define TK_FILE 288 +#define TK_FOR 289 +#define TK_GLOB 290 +#define TK_ID 291 +#define TK_IMMEDIATE 292 +#define TK_IMPORT 293 +#define TK_INITIALLY 294 +#define TK_INSTEAD 295 +#define TK_ISNULL 296 +#define TK_KEY 297 +#define TK_MODULES 298 +#define TK_NK_BITNOT 299 +#define TK_NK_SEMI 300 +#define TK_NOTNULL 301 +#define TK_OF 302 +#define TK_PLUS 303 +#define TK_PRIVILEGE 304 +#define TK_RAISE 305 +#define TK_REPLACE 306 +#define TK_RESTRICT 307 +#define TK_ROW 308 +#define TK_SEMI 309 +#define TK_STAR 310 +#define TK_STATEMENT 311 +#define TK_STRING 312 +#define TK_TIMES 313 +#define TK_UPDATE 314 +#define TK_VALUES 315 +#define TK_VARIABLE 316 +#define TK_VIEW 317 +#define TK_WAL 318 -#define TK_NK_SPACE 300 -#define TK_NK_COMMENT 301 -#define TK_NK_ILLEGAL 302 -#define TK_NK_HEX 303 // hex number 0x123 -#define TK_NK_OCT 304 // oct number -#define TK_NK_BIN 305 // bin format data 0b111 +#define TK_NK_SPACE 600 +#define TK_NK_COMMENT 601 +#define TK_NK_ILLEGAL 602 +#define TK_NK_HEX 603 // hex number 0x123 +#define TK_NK_OCT 604 // oct number +#define TK_NK_BIN 605 // bin format data 0b111 #define TK_NK_NIL 65535 diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index c9e47c25b7b9d99e48fc26a956bff6365a7d323d..cdb1642a5c313767fe6a6d5ad53d6202f8c677a6 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -99,7 +99,6 @@ int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad); */ int32_t mndProcessRpcMsg(SRpcMsg *pMsg); int32_t mndProcessSyncMsg(SRpcMsg *pMsg); -int32_t mndProcessSyncCtrlMsg(SRpcMsg *pMsg); int32_t mndPreProcessQueryMsg(SRpcMsg *pMsg); void mndPostProcessQueryMsg(SRpcMsg *pMsg); diff --git a/include/dnode/snode/snode.h b/include/dnode/snode/snode.h index 3d0ef2e052ef20978156b76b1dd7d552391b4a8b..e8c64b07c4f90d064a5a4709568bd0e35bbe8e51 100644 --- a/include/dnode/snode/snode.h +++ b/include/dnode/snode/snode.h @@ -68,8 +68,8 @@ int32_t sndGetLoad(SSnode *pSnode, SSnodeLoad *pLoad); * @param pMsg The request message * @param pRsp The response message */ -int32_t sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg); -int32_t sndProcessSMsg(SSnode *pSnode, SRpcMsg *pMsg); +int32_t sndProcessWriteMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg *pRsp); +int32_t sndProcessStreamMsg(SSnode *pSnode, SRpcMsg *pMsg); #ifdef __cplusplus } diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index 9f1513d100f9ab610d9ce08af74610979d36a891..7717d3bccc17910667fa6f42c6c5e1a556541601 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -124,6 +124,7 @@ typedef struct SDbVgVersion { int64_t dbId; int32_t vgVersion; int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT + int64_t stateTs; } SDbVgVersion; typedef struct STbSVersion { @@ -203,6 +204,12 @@ int32_t catalogUpdateTableMeta(SCatalog* pCatalog, STableMetaRsp* rspMsg); int32_t catalogUpdateTableMeta(SCatalog* pCatalog, STableMetaRsp* rspMsg); +int32_t catalogGetCachedTableMeta(SCatalog* pCtg, const SName* pTableName, STableMeta** pTableMeta); + +int32_t catalogGetCachedSTableMeta(SCatalog* pCtg, const SName* pTableName, STableMeta** pTableMeta); + +int32_t catalogGetCachedTableHashVgroup(SCatalog* pCtg, const SName* pTableName, SVgroupInfo* pVgroup, bool* exists); + /** * Force refresh DB's local cached vgroup info. * @param pCtg (input, got with catalogGetHandle) @@ -301,6 +308,9 @@ int32_t catalogGetUdfInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* f int32_t catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, const char* dbFName, AUTH_TYPE type, bool* pass); +int32_t catalogChkAuthFromCache(SCatalog* pCtg, const char* user, const char* dbFName, AUTH_TYPE type, bool* pass, + bool* exists); + int32_t catalogUpdateUserAuthInfo(SCatalog* pCtg, SGetUserAuthRsp* pAuth); int32_t catalogUpdateVgEpSet(SCatalog* pCtg, const char* dbFName, int32_t vgId, SEpSet* epSet); @@ -315,6 +325,10 @@ SMetaData* catalogCloneMetaData(SMetaData* pData); void catalogFreeMetaData(SMetaData* pData); +int32_t ctgdEnableDebug(char* option, bool enable); + +int32_t ctgdHandleDbgCommand(char* command); + /** * Destroy catalog and relase all resources */ diff --git a/include/libs/executor/executor.h b/include/libs/executor/executor.h index 5709132571b9b643e6eaf099b0d0dedf4cecbb79..1fe30a2d66b0a42470ca846d1682ec68bd64f4f3 100644 --- a/include/libs/executor/executor.h +++ b/include/libs/executor/executor.h @@ -79,6 +79,7 @@ qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, SReadHandle* readers); */ qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* readers, int32_t* numOfCols, SSchemaWrapper** pSchema); +int32_t qSetStreamOpOpen(qTaskInfo_t tinfo); /** * Set multiple input data blocks for the stream scan. * @param tinfo @@ -89,6 +90,16 @@ qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* readers, int32_t* n */ int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type); +/** + * Set block for sma + * @param tinfo + * @param pBlocks + * @param numOfInputBlock + * @param type + * @return + */ +int32_t qSetSMAInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type); + /** * Update the table id list, add or remove. * diff --git a/include/libs/function/function.h b/include/libs/function/function.h index 72248336f713386807b3b62360226dd485bb519d..6f2a67546658228615ebe20eade9e626e9a13ed7 100644 --- a/include/libs/function/function.h +++ b/include/libs/function/function.h @@ -182,7 +182,7 @@ struct SScalarParam { }; void cleanupResultRowEntry(struct SResultRowEntryInfo *pCell); -int32_t getNumOfResult(SqlFunctionCtx *pCtx, int32_t num, SSDataBlock *pResBlock); +//int32_t getNumOfResult(SqlFunctionCtx *pCtx, int32_t num, SSDataBlock *pResBlock); bool isRowEntryCompleted(struct SResultRowEntryInfo *pEntry); bool isRowEntryInitialized(struct SResultRowEntryInfo *pEntry); diff --git a/include/libs/function/functionMgt.h b/include/libs/function/functionMgt.h index 6968f1712c2743b648012f0a95118a9521aa53b9..81f63537e59ee7f51e01a0bc5c9527601be83300 100644 --- a/include/libs/function/functionMgt.h +++ b/include/libs/function/functionMgt.h @@ -216,6 +216,7 @@ bool fmIsMultiRowsFunc(int32_t funcId); bool fmIsKeepOrderFunc(int32_t funcId); bool fmIsCumulativeFunc(int32_t funcId); bool fmIsInterpPseudoColumnFunc(int32_t funcId); +bool fmIsGroupKeyFunc(int32_t funcId); void getLastCacheDataType(SDataType* pType); @@ -223,7 +224,7 @@ int32_t fmGetDistMethod(const SFunctionNode* pFunc, SFunctionNode** pPartialFunc typedef enum EFuncDataRequired { FUNC_DATA_REQUIRED_DATA_LOAD = 1, - FUNC_DATA_REQUIRED_STATIS_LOAD, + FUNC_DATA_REQUIRED_SMA_LOAD, FUNC_DATA_REQUIRED_NOT_LOAD, FUNC_DATA_REQUIRED_FILTEROUT, } EFuncDataRequired; diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 295555594f1f6ce2320d9385b9c8464503e33045..59f64f186384910dc186ceb8b31fa0b42880c142 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -235,6 +235,7 @@ typedef struct SDropDnodeStmt { int32_t dnodeId; char fqdn[TSDB_FQDN_LEN]; int32_t port; + bool force; } SDropDnodeStmt; typedef struct SAlterDnodeStmt { @@ -374,6 +375,7 @@ typedef struct SStreamOptions { int8_t triggerType; SNode* pDelay; SNode* pWatermark; + int8_t fillHistory; int8_t ignoreExpired; } SStreamOptions; diff --git a/include/libs/nodes/plannodes.h b/include/libs/nodes/plannodes.h index d0e1c3d2583f015525cf49c6e6d6abfeafcd6ebd..f942713f5da5a9ce9db9088c178f11813d9be48c 100644 --- a/include/libs/nodes/plannodes.h +++ b/include/libs/nodes/plannodes.h @@ -567,6 +567,7 @@ typedef struct SSubplan { SDataSinkNode* pDataSink; // data of the subplan flow into the datasink SNode* pTagCond; SNode* pTagIndexCond; + bool showRewrite; } SSubplan; typedef enum EExplainMode { EXPLAIN_MODE_DISABLE = 1, EXPLAIN_MODE_STATIC, EXPLAIN_MODE_ANALYZE } EExplainMode; @@ -585,8 +586,6 @@ typedef struct SQueryPlan { SExplainInfo explainInfo; } SQueryPlan; -void nodesWalkPhysiPlan(SNode* pNode, FNodeWalker walker, void* pContext); - const char* dataOrderStr(EDataOrderLevel order); #ifdef __cplusplus diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index 837834f795b4c8583acc708373a9ece43bc1665b..a85f8bf63d7c32157b30b8e458ff00ed0e22b9fd 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -354,12 +354,33 @@ typedef struct SVgDataBlocks { void* pData; // SMsgDesc + SSubmitReq + SSubmitBlk + ... } SVgDataBlocks; +typedef void (*FFreeDataBlockHash)(SHashObj*); +typedef void (*FFreeDataBlockArray)(SArray*); + typedef struct SVnodeModifOpStmt { - ENodeType nodeType; - ENodeType sqlNodeType; - SArray* pDataBlocks; // data block for each vgroup, SArray. - uint32_t insertType; // insert data from [file|sql statement| bound statement] - const char* sql; // current sql statement position + ENodeType nodeType; + ENodeType sqlNodeType; + SArray* pDataBlocks; // data block for each vgroup, SArray. + uint32_t insertType; // insert data from [file|sql statement| bound statement] + const char* pSql; // current sql statement position + int32_t totalRowsNum; + int32_t totalTbNum; + SName targetTableName; + SName usingTableName; + const char* pBoundCols; + struct STableMeta* pTableMeta; + SHashObj* pVgroupsHashObj; + SHashObj* pTableBlockHashObj; + SHashObj* pSubTableHashObj; + SHashObj* pTableNameHashObj; + SHashObj* pDbFNameHashObj; + SArray* pVgDataBlocks; + SVCreateTbReq createTblReq; + TdFilePtr fp; + FFreeDataBlockHash freeHashFunc; + FFreeDataBlockArray freeArrayFunc; + bool usingTableProcessing; + bool fileProcessing; } SVnodeModifOpStmt; typedef struct SExplainOptions { @@ -389,24 +410,32 @@ typedef enum EQueryExecMode { QUERY_EXEC_MODE_EMPTY_RESULT } EQueryExecMode; +typedef enum EQueryExecStage { + QUERY_EXEC_STAGE_PARSE = 1, + QUERY_EXEC_STAGE_ANALYSE, + QUERY_EXEC_STAGE_SCHEDULE, + QUERY_EXEC_STAGE_END +} EQueryExecStage; + typedef struct SQuery { - ENodeType type; - EQueryExecMode execMode; - bool haveResultSet; - SNode* pRoot; - int32_t numOfResCols; - SSchema* pResSchema; - int8_t precision; - SCmdMsgInfo* pCmdMsg; - int32_t msgType; - SArray* pTargetTableList; - SArray* pTableList; - SArray* pDbList; - bool showRewrite; - int32_t placeholderNum; - SArray* pPlaceholderValues; - SNode* pPrepareRoot; - bool stableQuery; + ENodeType type; + EQueryExecStage execStage; + EQueryExecMode execMode; + bool haveResultSet; + SNode* pRoot; + int32_t numOfResCols; + SSchema* pResSchema; + int8_t precision; + SCmdMsgInfo* pCmdMsg; + int32_t msgType; + SArray* pTargetTableList; + SArray* pTableList; + SArray* pDbList; + bool showRewrite; + int32_t placeholderNum; + SArray* pPlaceholderValues; + SNode* pPrepareRoot; + bool stableQuery; } SQuery; void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker walker, void* pContext); diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index bcd2316baf22f896916bb0eb5b3f6ae654afb48a..1a7e6dc748c1f86c0c23ccbe8e70e41cf2912df8 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -64,8 +64,6 @@ typedef struct SParseContext { SArray* pTableMetaPos; // sql table pos => catalog data pos SArray* pTableVgroupPos; // sql table pos => catalog data pos int64_t allocatorId; - bool needMultiParse; - SParseCsvCxt csvCxt; } SParseContext; int32_t qParseSql(SParseContext* pCxt, SQuery** pQuery); @@ -75,6 +73,8 @@ bool qIsInsertValuesSql(const char* pStr, size_t length); int32_t qParseSqlSyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq); int32_t qAnalyseSqlSemantic(SParseContext* pCxt, const struct SCatalogReq* pCatalogReq, const struct SMetaData* pMetaData, SQuery* pQuery); +int32_t qContinueParseSql(SParseContext* pCxt, struct SCatalogReq* pCatalogReq, const struct SMetaData* pMetaData, + SQuery* pQuery); void qDestroyParseContext(SParseContext* pCxt); diff --git a/include/libs/planner/planner.h b/include/libs/planner/planner.h index e52fe39527dda9aa80ea05c1ffcab487b84cd466..82f5c478c1ec7a83728e18997b1b494c1e627057 100644 --- a/include/libs/planner/planner.h +++ b/include/libs/planner/planner.h @@ -61,7 +61,6 @@ int32_t qStringToSubplan(const char* pStr, SSubplan** pSubplan); int32_t qSubPlanToMsg(const SSubplan* pSubplan, char** pStr, int32_t* pLen); int32_t qMsgToSubplan(const char* pStr, int32_t len, SSubplan** pSubplan); -char* qQueryPlanToString(const SQueryPlan* pPlan); SQueryPlan* qStringToQueryPlan(const char* pStr); void qDestroyQueryPlan(SQueryPlan* pPlan); diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index 7d95e840e9c539aa7d75fa32a325de2be766aec2..74c1a8c07cd261fac97951bf5c0a8699adbb509c 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -57,6 +57,10 @@ typedef enum { #define QUERY_RSP_POLICY_DELAY 0 #define QUERY_RSP_POLICY_QUICK 1 +#define QUERY_MSG_MASK_SHOW_REWRITE() (1 << 0) +#define TEST_SHOW_REWRITE_MASK(m) (((m) & QUERY_MSG_MASK_SHOW_REWRITE()) != 0) + + typedef struct STableComInfo { uint8_t numOfTags; // the number of tags in schema uint8_t precision; // the number of precision @@ -242,13 +246,13 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t #define SET_META_TYPE_BOTH_TABLE(t) (t) = META_TYPE_BOTH_TABLE #define NEED_CLIENT_RM_TBLMETA_ERROR(_code) \ - ((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_VND_TB_NOT_EXIST || \ + ((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_TDB_TABLE_NOT_EXIST || \ (_code) == TSDB_CODE_PAR_INVALID_COLUMNS_NUM || (_code) == TSDB_CODE_PAR_INVALID_COLUMN || \ (_code) == TSDB_CODE_PAR_TAGS_NOT_MATCHED || (_code) == TSDB_CODE_PAR_VALUE_TOO_LONG || \ (_code) == TSDB_CODE_PAR_INVALID_DROP_COL || ((_code) == TSDB_CODE_TDB_INVALID_TABLE_ID)) #define NEED_CLIENT_REFRESH_VG_ERROR(_code) \ ((_code) == TSDB_CODE_VND_HASH_MISMATCH || (_code) == TSDB_CODE_VND_INVALID_VGROUP_ID) -#define NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_TDB_TABLE_RECREATED) +#define NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER) #define NEED_CLIENT_HANDLE_ERROR(_code) \ (NEED_CLIENT_RM_TBLMETA_ERROR(_code) || NEED_CLIENT_REFRESH_VG_ERROR(_code) || \ NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code)) diff --git a/include/libs/qworker/qworker.h b/include/libs/qworker/qworker.h index 7a1e9bb2721c214dcf0ff961ca62dc0953d54882..6ddd906700dfb74517aa383a50cc6f45b39578c8 100644 --- a/include/libs/qworker/qworker.h +++ b/include/libs/qworker/qworker.h @@ -76,7 +76,7 @@ int32_t qWorkerInit(int8_t nodeType, int32_t nodeId, void **qWorkerMgmt, const S int32_t qWorkerAbortPreprocessQueryMsg(void *qWorkerMgmt, SRpcMsg *pMsg); -int32_t qWorkerPreprocessQueryMsg(void *qWorkerMgmt, SRpcMsg *pMsg); +int32_t qWorkerPreprocessQueryMsg(void *qWorkerMgmt, SRpcMsg *pMsg, bool chkGrant); int32_t qWorkerProcessQueryMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int64_t ts); diff --git a/include/libs/stream/streamState.h b/include/libs/stream/streamState.h index 3d59a69deaa7e45fb4e68d663b7f60934462dec4..9443df5e14e32ca54d76e4bb3c21219509b90cf2 100644 --- a/include/libs/stream/streamState.h +++ b/include/libs/stream/streamState.h @@ -60,19 +60,19 @@ int32_t streamStateDel(SStreamState* pState, const SWinKey* key); int32_t streamStateClear(SStreamState* pState); void streamStateSetNumber(SStreamState* pState, int32_t number); -int32_t streamStateSessionAddIfNotExist(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen); +int32_t streamStateSessionAddIfNotExist(SStreamState* pState, SSessionKey* key, TSKEY gap, void** pVal, int32_t* pVLen); int32_t streamStateSessionPut(SStreamState* pState, const SSessionKey* key, const void* value, int32_t vLen); int32_t streamStateSessionGet(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen); int32_t streamStateSessionDel(SStreamState* pState, const SSessionKey* key); int32_t streamStateSessionClear(SStreamState* pState); -int32_t streamStateSessionGetKVByCur(SStreamStateCur* pCur, SSessionKey* pKey, const void** pVal, int32_t* pVLen); +int32_t streamStateSessionGetKVByCur(SStreamStateCur* pCur, SSessionKey* pKey, void** pVal, int32_t* pVLen); int32_t streamStateStateAddIfNotExist(SStreamState* pState, SSessionKey* key, char* pKeyData, int32_t keyDataLen, state_key_cmpr_fn fn, void** pVal, int32_t* pVLen); -int32_t streamStateSessionGetKey(SStreamState* pState, const SSessionKey* key, SSessionKey* curKey); +int32_t streamStateSessionGetKeyByRange(SStreamState* pState, const SSessionKey* range, SSessionKey* curKey); SStreamStateCur* streamStateSessionSeekKeyNext(SStreamState* pState, const SSessionKey* key); SStreamStateCur* streamStateSessionSeekKeyCurrentPrev(SStreamState* pState, const SSessionKey* key); -SStreamStateCur* streamStateSessionGetCur(SStreamState* pState, const SSessionKey* key); +SStreamStateCur* streamStateSessionSeekKeyCurrentNext(SStreamState* pState, const SSessionKey* key); int32_t streamStateFillPut(SStreamState* pState, const SWinKey* key, const void* value, int32_t vLen); int32_t streamStateFillGet(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen); @@ -99,6 +99,10 @@ int32_t streamStateSeekLast(SStreamState* pState, SStreamStateCur* pCur); int32_t streamStateCurNext(SStreamState* pState, SStreamStateCur* pCur); int32_t streamStateCurPrev(SStreamState* pState, SStreamStateCur* pCur); +#if 0 +char* streamStateSessionDump(SStreamState* pState); +#endif + #ifdef __cplusplus } #endif diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h index 534d86b1f17bec768d9052355c73a788be85953e..0354078b7b9dfae731cc05e4aa846e46b2ab6cd0 100644 --- a/include/libs/stream/tstream.h +++ b/include/libs/stream/tstream.h @@ -46,7 +46,7 @@ enum { TASK_STATUS__DROPPING, TASK_STATUS__FAIL, TASK_STATUS__STOP, - TASK_STATUS__RECOVER_DOWNSTREAM, + TASK_STATUS__WAIT_DOWNSTREAM, TASK_STATUS__RECOVER_PREPARE, TASK_STATUS__RECOVER1, TASK_STATUS__RECOVER2, @@ -317,6 +317,8 @@ typedef struct SStreamTask { int8_t inputStatus; int8_t outputStatus; + // STaosQueue* inputQueue1; + // STaosQall* inputQall; SStreamQueue* inputQueue; SStreamQueue* outputQueue; @@ -332,7 +334,10 @@ typedef struct SStreamTask { SStreamState* pState; // do not serialize - int32_t recoverWaitingChild; + int32_t recoverTryingDownstream; + int32_t recoverWaitingUpstream; + int64_t checkReqId; + SArray* checkReqIds; // shuffle } SStreamTask; @@ -418,7 +423,10 @@ typedef struct { typedef struct { int64_t streamId; - int32_t taskId; + int32_t upstreamNodeId; + int32_t upstreamTaskId; + int32_t downstreamNodeId; + int32_t downstreamTaskId; int8_t inputStatus; } SStreamDispatchRsp; @@ -441,59 +449,40 @@ typedef struct { } SStreamRetrieveRsp; typedef struct { + int64_t reqId; int64_t streamId; - int32_t taskId; -} SStreamRecoverStep1Req, SStreamRecoverStep2Req; - -typedef struct { - int64_t streamId; - int32_t taskId; + int32_t upstreamNodeId; + int32_t upstreamTaskId; + int32_t downstreamNodeId; + int32_t downstreamTaskId; int32_t childId; -} SStreamRecoverFinishReq; - -int32_t tEncodeSStreamRecoverFinishReq(SEncoder* pEncoder, const SStreamRecoverFinishReq* pReq); -int32_t tDecodeSStreamRecoverFinishReq(SDecoder* pDecoder, SStreamRecoverFinishReq* pReq); +} SStreamTaskCheckReq; -#if 0 typedef struct { + int64_t reqId; int64_t streamId; - int32_t taskId; - int32_t upstreamTaskId; int32_t upstreamNodeId; -} SStreamTaskRecoverReq; - -typedef struct { - int64_t streamId; - int32_t rspTaskId; - int32_t reqTaskId; - int8_t inputStatus; -} SStreamTaskRecoverRsp; - -int32_t tEncodeStreamTaskRecoverReq(SEncoder* pEncoder, const SStreamTaskRecoverReq* pReq); -int32_t tDecodeStreamTaskRecoverReq(SDecoder* pDecoder, SStreamTaskRecoverReq* pReq); - -int32_t tEncodeStreamTaskRecoverRsp(SEncoder* pEncoder, const SStreamTaskRecoverRsp* pRsp); -int32_t tDecodeStreamTaskRecoverRsp(SDecoder* pDecoder, SStreamTaskRecoverRsp* pRsp); + int32_t upstreamTaskId; + int32_t downstreamNodeId; + int32_t downstreamTaskId; + int32_t childId; + int8_t status; +} SStreamTaskCheckRsp; typedef struct { - int64_t streamId; - int32_t taskId; -} SMStreamTaskRecoverReq; + SMsgHead msgHead; + int64_t streamId; + int32_t taskId; +} SStreamRecoverStep1Req, SStreamRecoverStep2Req; typedef struct { int64_t streamId; int32_t taskId; -} SMStreamTaskRecoverRsp; - -int32_t tEncodeSMStreamTaskRecoverReq(SEncoder* pEncoder, const SMStreamTaskRecoverReq* pReq); -int32_t tDecodeSMStreamTaskRecoverReq(SDecoder* pDecoder, SMStreamTaskRecoverReq* pReq); - -int32_t tEncodeSMStreamTaskRecoverRsp(SEncoder* pEncoder, const SMStreamTaskRecoverRsp* pRsp); -int32_t tDecodeSMStreamTaskRecoverRsp(SDecoder* pDecoder, SMStreamTaskRecoverRsp* pRsp); + int32_t childId; +} SStreamRecoverFinishReq; -int32_t streamProcessRecoverReq(SStreamTask* pTask, SStreamTaskRecoverReq* pReq, SRpcMsg* pMsg); -int32_t streamProcessRecoverRsp(SStreamTask* pTask, SStreamTaskRecoverRsp* pRsp); -#endif +int32_t tEncodeSStreamRecoverFinishReq(SEncoder* pEncoder, const SStreamRecoverFinishReq* pReq); +int32_t tDecodeSStreamRecoverFinishReq(SDecoder* pDecoder, SStreamRecoverFinishReq* pReq); typedef struct { int64_t streamId; @@ -508,20 +497,18 @@ typedef struct { SArray* checkpointVer; // SArray } SStreamRecoverDownstreamRsp; +int32_t tEncodeSStreamTaskCheckReq(SEncoder* pEncoder, const SStreamTaskCheckReq* pReq); +int32_t tDecodeSStreamTaskCheckReq(SDecoder* pDecoder, SStreamTaskCheckReq* pReq); + +int32_t tEncodeSStreamTaskCheckRsp(SEncoder* pEncoder, const SStreamTaskCheckRsp* pRsp); +int32_t tDecodeSStreamTaskCheckRsp(SDecoder* pDecoder, SStreamTaskCheckRsp* pRsp); + int32_t tEncodeSStreamTaskRecoverReq(SEncoder* pEncoder, const SStreamRecoverDownstreamReq* pReq); int32_t tDecodeSStreamTaskRecoverReq(SDecoder* pDecoder, SStreamRecoverDownstreamReq* pReq); int32_t tEncodeSStreamTaskRecoverRsp(SEncoder* pEncoder, const SStreamRecoverDownstreamRsp* pRsp); int32_t tDecodeSStreamTaskRecoverRsp(SDecoder* pDecoder, SStreamRecoverDownstreamRsp* pRsp); -typedef struct { - int64_t streamId; - int32_t taskId; - int32_t waitingRspCnt; - int32_t totReq; - SArray* info; // SArray*> -} SStreamRecoverStatus; - int32_t tDecodeStreamDispatchReq(SDecoder* pDecoder, SStreamDispatchReq* pReq); int32_t tDecodeStreamRetrieveReq(SDecoder* pDecoder, SStreamRetrieveReq* pReq); void tDeleteStreamRetrieveReq(SStreamRetrieveReq* pReq); @@ -532,7 +519,7 @@ int32_t streamSetupTrigger(SStreamTask* pTask); int32_t streamProcessRunReq(SStreamTask* pTask); int32_t streamProcessDispatchReq(SStreamTask* pTask, SStreamDispatchReq* pReq, SRpcMsg* pMsg, bool exec); -int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp); +int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, int32_t code); int32_t streamProcessRetrieveReq(SStreamTask* pTask, SStreamRetrieveReq* pReq, SRpcMsg* pMsg); int32_t streamProcessRetrieveRsp(SStreamTask* pTask, SStreamRetrieveRsp* pRsp); @@ -543,6 +530,10 @@ int32_t streamSchedExec(SStreamTask* pTask); int32_t streamScanExec(SStreamTask* pTask, int32_t batchSz); // recover and fill history +int32_t streamTaskCheckDownstream(SStreamTask* pTask, int64_t version); +int32_t streamTaskLaunchRecover(SStreamTask* pTask, int64_t version); +int32_t streamProcessTaskCheckReq(SStreamTask* pTask, const SStreamTaskCheckReq* pReq); +int32_t streamProcessTaskCheckRsp(SStreamTask* pTask, const SStreamTaskCheckRsp* pRsp, int64_t version); // common int32_t streamSetParamForRecover(SStreamTask* pTask); int32_t streamRestoreParam(SStreamTask* pTask); diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index ff14e637d0c90a80c2a232ab209dd23549cd4ca1..a27be95049d64b8ff68bc2f75fd62e49f32a47cd 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -25,8 +25,6 @@ extern "C" { #include "tlrucache.h" #include "tmsgcb.h" -extern bool gRaftDetailLog; - #define SYNC_RESP_TTL_MS 10000000 #define SYNC_SPEED_UP_HB_TIMER 400 #define SYNC_SPEED_UP_AFTER_MS (1000 * 20) @@ -38,7 +36,8 @@ extern bool gRaftDetailLog; #define SYNC_DEL_WAL_MS (1000 * 60) #define SYNC_ADD_QUORUM_COUNT 3 #define SYNC_MNODE_LOG_RETENTION 10000 -#define SYNC_VNODE_LOG_RETENTION 500 +#define SYNC_VNODE_LOG_RETENTION 100 +#define SNAPSHOT_MAX_CLOCK_SKEW_MS 1000 * 10 #define SYNC_APPEND_ENTRIES_TIMEOUT_MS 10000 @@ -132,27 +131,29 @@ typedef struct SSnapshotMeta { typedef struct SSyncFSM { void* data; - void (*FpCommitCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta); - void (*FpPreCommitCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta); - void (*FpRollBackCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta); + void (*FpCommitCb)(const struct SSyncFSM* pFsm, const SRpcMsg* pMsg, const SFsmCbMeta* pMeta); + void (*FpPreCommitCb)(const struct SSyncFSM* pFsm, const SRpcMsg* pMsg, const SFsmCbMeta* pMeta); + void (*FpRollBackCb)(const struct SSyncFSM* pFsm, const SRpcMsg* pMsg, const SFsmCbMeta* pMeta); - void (*FpRestoreFinishCb)(struct SSyncFSM* pFsm); - void (*FpReConfigCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta* cbMeta); - void (*FpLeaderTransferCb)(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta); + void (*FpRestoreFinishCb)(const struct SSyncFSM* pFsm); + void (*FpReConfigCb)(const struct SSyncFSM* pFsm, const SRpcMsg* pMsg, const SReConfigCbMeta* pMeta); + void (*FpLeaderTransferCb)(const struct SSyncFSM* pFsm, const SRpcMsg* pMsg, const SFsmCbMeta* pMeta); + bool (*FpApplyQueueEmptyCb)(const struct SSyncFSM* pFsm); + int32_t (*FpApplyQueueItems)(const struct SSyncFSM* pFsm); - void (*FpBecomeLeaderCb)(struct SSyncFSM* pFsm); - void (*FpBecomeFollowerCb)(struct SSyncFSM* pFsm); + void (*FpBecomeLeaderCb)(const struct SSyncFSM* pFsm); + void (*FpBecomeFollowerCb)(const struct SSyncFSM* pFsm); - int32_t (*FpGetSnapshot)(struct SSyncFSM* pFsm, SSnapshot* pSnapshot, void* pReaderParam, void** ppReader); - int32_t (*FpGetSnapshotInfo)(struct SSyncFSM* pFsm, SSnapshot* pSnapshot); + int32_t (*FpGetSnapshot)(const struct SSyncFSM* pFsm, SSnapshot* pSnapshot, void* pReaderParam, void** ppReader); + int32_t (*FpGetSnapshotInfo)(const struct SSyncFSM* pFsm, SSnapshot* pSnapshot); - int32_t (*FpSnapshotStartRead)(struct SSyncFSM* pFsm, void* pReaderParam, void** ppReader); - int32_t (*FpSnapshotStopRead)(struct SSyncFSM* pFsm, void* pReader); - int32_t (*FpSnapshotDoRead)(struct SSyncFSM* pFsm, void* pReader, void** ppBuf, int32_t* len); + int32_t (*FpSnapshotStartRead)(const struct SSyncFSM* pFsm, void* pReaderParam, void** ppReader); + int32_t (*FpSnapshotStopRead)(const struct SSyncFSM* pFsm, void* pReader); + int32_t (*FpSnapshotDoRead)(const struct SSyncFSM* pFsm, void* pReader, void** ppBuf, int32_t* len); - int32_t (*FpSnapshotStartWrite)(struct SSyncFSM* pFsm, void* pWriterParam, void** ppWriter); - int32_t (*FpSnapshotStopWrite)(struct SSyncFSM* pFsm, void* pWriter, bool isApply, SSnapshot* pSnapshot); - int32_t (*FpSnapshotDoWrite)(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_t len); + int32_t (*FpSnapshotStartWrite)(const struct SSyncFSM* pFsm, void* pWriterParam, void** ppWriter); + int32_t (*FpSnapshotStopWrite)(const struct SSyncFSM* pFsm, void* pWriter, bool isApply, SSnapshot* pSnapshot); + int32_t (*FpSnapshotDoWrite)(const struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_t len); } SSyncFSM; @@ -193,44 +194,38 @@ typedef struct SSyncInfo { SWal* pWal; SSyncFSM* pFsm; SMsgCb* msgcb; - int32_t (*FpSendMsg)(const SEpSet* pEpSet, SRpcMsg* pMsg); - int32_t (*FpEqMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg); - int32_t (*FpEqCtrlMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg); -} SSyncInfo; - -int32_t syncInit(); -void syncCleanUp(); -int64_t syncOpen(SSyncInfo* pSyncInfo); -void syncStart(int64_t rid); -void syncStop(int64_t rid); -int32_t syncSetStandby(int64_t rid); -ESyncState syncGetMyRole(int64_t rid); -bool syncIsReady(int64_t rid); -const char* syncGetMyRoleStr(int64_t rid); -bool syncRestoreFinish(int64_t rid); -SyncTerm syncGetMyTerm(int64_t rid); -SyncIndex syncGetLastIndex(int64_t rid); -SyncIndex syncGetCommitIndex(int64_t rid); -SyncGroupId syncGetVgId(int64_t rid); -void syncGetEpSet(int64_t rid, SEpSet* pEpSet); -void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet); -int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak); -// int32_t syncProposeBatch(int64_t rid, SRpcMsg** pMsgPArr, bool* pIsWeakArr, int32_t arrSize); -bool syncEnvIsStart(); -const char* syncStr(ESyncState state); -bool syncIsRestoreFinish(int64_t rid); -int32_t syncGetSnapshotByIndex(int64_t rid, SyncIndex index, SSnapshot* pSnapshot); - -int32_t syncReconfig(int64_t rid, SSyncCfg* pNewCfg); - -// build SRpcMsg, need to call syncPropose with SRpcMsg -int32_t syncReconfigBuild(int64_t rid, const SSyncCfg* pNewCfg, SRpcMsg* pRpcMsg); + int32_t pingMs; + int32_t electMs; + int32_t heartbeatMs; -int32_t syncLeaderTransfer(int64_t rid); -int32_t syncLeaderTransferTo(int64_t rid, SNodeInfo newLeader); + int32_t (*syncSendMSg)(const SEpSet* pEpSet, SRpcMsg* pMsg); + int32_t (*syncEqMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg); + int32_t (*syncEqCtrlMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg); +} SSyncInfo; +typedef struct SSyncState { + ESyncState state; + bool restored; +} SSyncState; + +int32_t syncInit(); +void syncCleanUp(); +int64_t syncOpen(SSyncInfo* pSyncInfo); +void syncStart(int64_t rid); +void syncStop(int64_t rid); +void syncPreStop(int64_t rid); +int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak); +int32_t syncProcessMsg(int64_t rid, SRpcMsg* pMsg); +int32_t syncReconfig(int64_t rid, SSyncCfg* pCfg); int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex); int32_t syncEndSnapshot(int64_t rid); +int32_t syncLeaderTransfer(int64_t rid); +int32_t syncStepDown(int64_t rid, SyncTerm newTerm); +bool syncIsReadyForRead(int64_t rid); + +SSyncState syncGetState(int64_t rid); +void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet); +const char* syncStr(ESyncState state); #ifdef __cplusplus } diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h index 08dba5d50d0fb10321bcc083d880852d2f543196..ed85fd3517f09f42548133a0360376f846c885ee 100644 --- a/include/libs/wal/wal.h +++ b/include/libs/wal/wal.h @@ -43,7 +43,6 @@ extern "C" { #define WAL_FILE_LEN (WAL_PATH_LEN + 32) #define WAL_MAGIC 0xFAFBFCFDF4F3F2F1ULL #define WAL_SCAN_BUF_SIZE (1024 * 1024 * 3) -#define WAL_RECOV_SIZE_LIMIT (100 * WAL_SCAN_BUF_SIZE) typedef enum { TAOS_WAL_WRITE = 1, @@ -159,6 +158,7 @@ void walCleanUp(); // handle open and ctl SWal *walOpen(const char *path, SWalCfg *pCfg); int32_t walAlter(SWal *, SWalCfg *pCfg); +int32_t walPersist(SWal *); void walClose(SWal *); // write interfaces diff --git a/include/os/osFile.h b/include/os/osFile.h index 21e3d2e6cf7b2b35e62c04b459d63a03198598a4..f6759d19a74499cc16e08ad84ff543c7a17d7550 100644 --- a/include/os/osFile.h +++ b/include/os/osFile.h @@ -42,6 +42,16 @@ extern "C" { #define PATH_MAX 256 #endif +#ifdef WINDOWS +#define TD_PATH_MAX _MAX_PATH +#elif defined(PATH_MAX) +#define TD_PATH_MAX PATH_MAX +#elif defined(_XOPEN_PATH_MAX) +#define TD_PATH_MAX _XOPEN_PATH_MAX +#else +#define TD_PATH_MAX _POSIX_PATH_MAX +#endif + typedef struct TdFile *TdFilePtr; #define TD_FILE_CREATE 0x0001 diff --git a/include/os/osMemory.h b/include/os/osMemory.h index 7ec8366ee4cb584dc41aa0ce94d5c54f6405964e..14d53a7a066f60b5f0d3c0f37526b2533b3b05af 100644 --- a/include/os/osMemory.h +++ b/include/os/osMemory.h @@ -36,6 +36,7 @@ void *taosMemoryStrDup(const char *ptr); void taosMemoryFree(void *ptr); int64_t taosMemorySize(void *ptr); void taosPrintBackTrace(); +void taosMemoryTrim(int32_t size); #define taosMemoryFreeClear(ptr) \ do { \ diff --git a/include/util/taoserror.h b/include/util/taoserror.h index bbddb539c60dd53d73ee6e7528caa5a4c48ce9c1..a03dc7d9f999647dc887c4ffe4115fdd2c1e9c2b 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -91,6 +91,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_MSG_DECODE_ERROR TAOS_DEF_ERROR_CODE(0, 0x0128) #define TSDB_CODE_NO_AVAIL_DISK TAOS_DEF_ERROR_CODE(0, 0x0129) #define TSDB_CODE_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x012A) +#define TSDB_CODE_NO_DISKSPACE TAOS_DEF_ERROR_CODE(0, 0x012B) //client #define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200) @@ -106,7 +107,6 @@ int32_t* taosGetErrno(); #define TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH TAOS_DEF_ERROR_CODE(0, 0x020A) #define TSDB_CODE_TSC_INVALID_CONNECTION TAOS_DEF_ERROR_CODE(0, 0x020B) #define TSDB_CODE_TSC_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x020C) -#define TSDB_CODE_TSC_NO_DISKSPACE TAOS_DEF_ERROR_CODE(0, 0x020D) #define TSDB_CODE_TSC_QUERY_CACHE_ERASED TAOS_DEF_ERROR_CODE(0, 0x020E) #define TSDB_CODE_TSC_QUERY_CANCELLED TAOS_DEF_ERROR_CODE(0, 0x020F) #define TSDB_CODE_TSC_SORTED_RES_TOO_MANY TAOS_DEF_ERROR_CODE(0, 0x0210) @@ -154,7 +154,7 @@ int32_t* taosGetErrno(); // mnode-sdb #define TSDB_CODE_SDB_OBJ_ALREADY_THERE TAOS_DEF_ERROR_CODE(0, 0x0320) -#define TSDB_CODE_SDB_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0321) +#define TSDB_CODE_SDB_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0321) // internal #define TSDB_CODE_SDB_INVALID_TABLE_TYPE TAOS_DEF_ERROR_CODE(0, 0x0322) #define TSDB_CODE_SDB_OBJ_NOT_THERE TAOS_DEF_ERROR_CODE(0, 0x0323) #define TSDB_CODE_SDB_INVALID_KEY_TYPE TAOS_DEF_ERROR_CODE(0, 0x0325) @@ -218,14 +218,24 @@ int32_t* taosGetErrno(); // mnode-db #define TSDB_CODE_MND_DB_NOT_SELECTED TAOS_DEF_ERROR_CODE(0, 0x0380) -#define TSDB_CODE_MND_DB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0381) -#define TSDB_CODE_MND_INVALID_DB_OPTION TAOS_DEF_ERROR_CODE(0, 0x0382) +#define TSDB_CODE_MND_DB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0381) // +#define TSDB_CODE_MND_INVALID_DB_OPTION TAOS_DEF_ERROR_CODE(0, 0x0382) // #define TSDB_CODE_MND_INVALID_DB TAOS_DEF_ERROR_CODE(0, 0x0383) +// #define TSDB_CODE_MND_MONITOR_DB_FORBIDDEN TAOS_DEF_ERROR_CODE(0, 0x0384) // 2.x #define TSDB_CODE_MND_TOO_MANY_DATABASES TAOS_DEF_ERROR_CODE(0, 0x0385) -#define TSDB_CODE_MND_DB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0388) -#define TSDB_CODE_MND_INVALID_DB_ACCT TAOS_DEF_ERROR_CODE(0, 0x0389) -#define TSDB_CODE_MND_DB_OPTION_UNCHANGED TAOS_DEF_ERROR_CODE(0, 0x038A) +#define TSDB_CODE_MND_DB_IN_DROPPING TAOS_DEF_ERROR_CODE(0, 0x0386) // +// #define TSDB_CODE_MND_VGROUP_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0387) // 2.x +#define TSDB_CODE_MND_DB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0388) // +#define TSDB_CODE_MND_INVALID_DB_ACCT TAOS_DEF_ERROR_CODE(0, 0x0389) // internal +#define TSDB_CODE_MND_DB_OPTION_UNCHANGED TAOS_DEF_ERROR_CODE(0, 0x038A) // #define TSDB_CODE_MND_DB_INDEX_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x038B) +// #define TSDB_CODE_MND_INVALID_DB_OPTION_DAYS TAOS_DEF_ERROR_CODE(0, 0x0390) // 2.x +// #define TSDB_CODE_MND_INVALID_DB_OPTION_KEEP TAOS_DEF_ERROR_CODE(0, 0x0391) // 2.x +// #define TSDB_CODE_MND_INVALID_TOPIC TAOS_DEF_ERROR_CODE(0, 0x0392) // 2.x +// #define TSDB_CODE_MND_INVALID_TOPIC_OPTION TAOS_DEF_ERROR_CODE(0, 0x0393) // 2.x +// #define TSDB_CODE_MND_INVALID_TOPIC_PARTITONSTAOS_DEF_ERROR_CODE(0, 0x0394) // 2.x +// #define TSDB_CODE_MND_TOPIC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0395) // 2.x +#define TSDB_CODE_MND_DB_IN_CREATING TAOS_DEF_ERROR_CODE(0, 0x0396) // #define TSDB_CODE_MND_INVALID_SYS_TABLENAME TAOS_DEF_ERROR_CODE(0, 0x039A) // mnode-node @@ -305,34 +315,14 @@ int32_t* taosGetErrno(); #define TSDB_CODE_NODE_NOT_DEPLOYED TAOS_DEF_ERROR_CODE(0, 0x040A) // vnode -#define TSDB_CODE_VND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0500) -#define TSDB_CODE_VND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0501) -#define TSDB_CODE_VND_ACTION_NEED_REPROCESSED TAOS_DEF_ERROR_CODE(0, 0x0502) #define TSDB_CODE_VND_INVALID_VGROUP_ID TAOS_DEF_ERROR_CODE(0, 0x0503) -#define TSDB_CODE_VND_INIT_FAILED TAOS_DEF_ERROR_CODE(0, 0x0504) -#define TSDB_CODE_VND_NO_DISKSPACE TAOS_DEF_ERROR_CODE(0, 0x0505) -#define TSDB_CODE_VND_NO_DISK_PERMISSIONS TAOS_DEF_ERROR_CODE(0, 0x0506) -#define TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR TAOS_DEF_ERROR_CODE(0, 0x0507) -#define TSDB_CODE_VND_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0508) -#define TSDB_CODE_VND_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0509) -#define TSDB_CODE_VND_IS_FLOWCTRL TAOS_DEF_ERROR_CODE(0, 0x050C) -#define TSDB_CODE_VND_IS_DROPPING TAOS_DEF_ERROR_CODE(0, 0x050D) -#define TSDB_CODE_VND_IS_UPDATING TAOS_DEF_ERROR_CODE(0, 0x050E) -#define TSDB_CODE_VND_IS_CLOSING TAOS_DEF_ERROR_CODE(0, 0x0510) -#define TSDB_CODE_VND_NOT_SYNCED TAOS_DEF_ERROR_CODE(0, 0x0511) #define TSDB_CODE_VND_NO_WRITE_AUTH TAOS_DEF_ERROR_CODE(0, 0x0512) -#define TSDB_CODE_VND_IS_SYNCING TAOS_DEF_ERROR_CODE(0, 0x0513) -#define TSDB_CODE_VND_INVALID_TSDB_STATE TAOS_DEF_ERROR_CODE(0, 0x0514) -#define TSDB_CODE_VND_TB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0520) -#define TSDB_CODE_VND_SMA_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0521) #define TSDB_CODE_VND_HASH_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x0522) -#define TSDB_CODE_VND_TABLE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0523) #define TSDB_CODE_VND_INVALID_TABLE_ACTION TAOS_DEF_ERROR_CODE(0, 0x0524) #define TSDB_CODE_VND_COL_ALREADY_EXISTS TAOS_DEF_ERROR_CODE(0, 0x0525) -#define TSDB_CODE_VND_TABLE_COL_NOT_EXISTS TAOS_DEF_ERROR_CODE(0, 0x0526) +#define TSDB_CODE_VND_COL_NOT_EXISTS TAOS_DEF_ERROR_CODE(0, 0x0526) #define TSDB_CODE_VND_COL_SUBSCRIBED TAOS_DEF_ERROR_CODE(0, 0x0527) -#define TSDB_CODE_VND_INVALID_CFG_FILE TAOS_DEF_ERROR_CODE(0, 0x0528) -#define TSDB_CODE_VND_INVALID_TERM_FILE TAOS_DEF_ERROR_CODE(0, 0x0529) +#define TSDB_CODE_VND_NO_AVAIL_BUFPOOL TAOS_DEF_ERROR_CODE(0, 0x0528) // tsdb #define TSDB_CODE_TDB_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0600) @@ -341,7 +331,6 @@ int32_t* taosGetErrno(); #define TSDB_CODE_TDB_TABLE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0603) #define TSDB_CODE_TDB_INVALID_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0604) #define TSDB_CODE_TDB_INIT_FAILED TAOS_DEF_ERROR_CODE(0, 0x0605) -#define TSDB_CODE_TDB_NO_DISKSPACE TAOS_DEF_ERROR_CODE(0, 0x0606) #define TSDB_CODE_TDB_NO_DISK_PERMISSIONS TAOS_DEF_ERROR_CODE(0, 0x0607) #define TSDB_CODE_TDB_FILE_CORRUPTED TAOS_DEF_ERROR_CODE(0, 0x0608) #define TSDB_CODE_TDB_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0609) @@ -361,13 +350,12 @@ int32_t* taosGetErrno(); #define TSDB_CODE_TDB_TABLE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0618) #define TSDB_CODE_TDB_STB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0619) #define TSDB_CODE_TDB_STB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x061A) -#define TSDB_CODE_TDB_TABLE_RECREATED TAOS_DEF_ERROR_CODE(0, 0x061B) +#define TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER TAOS_DEF_ERROR_CODE(0, 0x061B) #define TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR TAOS_DEF_ERROR_CODE(0, 0x061C) // query #define TSDB_CODE_QRY_INVALID_QHANDLE TAOS_DEF_ERROR_CODE(0, 0x0700) #define TSDB_CODE_QRY_INVALID_MSG TAOS_DEF_ERROR_CODE(0, 0x0701) -#define TSDB_CODE_QRY_NO_DISKSPACE TAOS_DEF_ERROR_CODE(0, 0x0702) #define TSDB_CODE_QRY_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0703) #define TSDB_CODE_QRY_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x0704) #define TSDB_CODE_QRY_DUP_JOIN_KEY TAOS_DEF_ERROR_CODE(0, 0x0705) @@ -420,7 +408,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_SYN_NOT_LEADER TAOS_DEF_ERROR_CODE(0, 0x090C) #define TSDB_CODE_SYN_ONE_REPLICA TAOS_DEF_ERROR_CODE(0, 0x090D) #define TSDB_CODE_SYN_NOT_IN_NEW_CONFIG TAOS_DEF_ERROR_CODE(0, 0x090E) -#define TSDB_CODE_SYN_NEW_CONFIG_ERROR TAOS_DEF_ERROR_CODE(0, 0x090F) +#define TSDB_CODE_SYN_NEW_CONFIG_ERROR TAOS_DEF_ERROR_CODE(0, 0x090F) // internal #define TSDB_CODE_SYN_RECONFIG_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0910) #define TSDB_CODE_SYN_PROPOSE_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0911) #define TSDB_CODE_SYN_STANDBY_NOT_READY TAOS_DEF_ERROR_CODE(0, 0x0912) @@ -430,7 +418,6 @@ int32_t* taosGetErrno(); // tq #define TSDB_CODE_TQ_INVALID_CONFIG TAOS_DEF_ERROR_CODE(0, 0x0A00) #define TSDB_CODE_TQ_INIT_FAILED TAOS_DEF_ERROR_CODE(0, 0x0A01) -#define TSDB_CODE_TQ_NO_DISKSPACE TAOS_DEF_ERROR_CODE(0, 0x0A02) #define TSDB_CODE_TQ_NO_DISK_PERMISSIONS TAOS_DEF_ERROR_CODE(0, 0x0A03) #define TSDB_CODE_TQ_FILE_CORRUPTED TAOS_DEF_ERROR_CODE(0, 0x0A04) #define TSDB_CODE_TQ_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0A05) @@ -451,6 +438,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_WAL_OUT_OF_MEMORY TAOS_DEF_ERROR_CODE(0, 0x1004) #define TSDB_CODE_WAL_LOG_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x1005) #define TSDB_CODE_WAL_CHKSUM_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x1006) +#define TSDB_CODE_WAL_LOG_INCOMPLETE TAOS_DEF_ERROR_CODE(0, 0x1007) // tfs #define TSDB_CODE_FS_INVLD_CFG TAOS_DEF_ERROR_CODE(0, 0x2201) @@ -634,9 +622,12 @@ int32_t* taosGetErrno(); #define TSDB_CODE_TMQ_CONSUMER_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x4001) #define TSDB_CODE_TMQ_CONSUMER_CLOSED TAOS_DEF_ERROR_CODE(0, 0x4002) +// stream +#define TSDB_CODE_STREAM_TASK_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x4100) + // TDLite -#define TSDB_CODE_TDLITE_IVLD_OPEN_FLAGS TAOS_DEF_ERROR_CODE(0, 0x4100) -#define TSDB_CODE_TDLITE_IVLD_OPEN_DIR TAOS_DEF_ERROR_CODE(0, 0x4101) +#define TSDB_CODE_TDLITE_IVLD_OPEN_FLAGS TAOS_DEF_ERROR_CODE(0, 0x5100) +#define TSDB_CODE_TDLITE_IVLD_OPEN_DIR TAOS_DEF_ERROR_CODE(0, 0x5101) #ifdef __cplusplus } diff --git a/include/util/tdef.h b/include/util/tdef.h index 936fbdf0d58656f61c2f1019d70f71e604636363..b6a7f5c82464607258db6111f9fcf18510fd3346 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -234,9 +234,9 @@ typedef enum ELogicConditionType { * - Secondly, if all cols are VarDataT type except primary key, we need 4 bits to store the offset, thus * the final value is 65531-(4096-1)*4 = 49151. */ -#define TSDB_MAX_BYTES_PER_ROW 49151 -#define TSDB_MAX_TAGS_LEN 16384 -#define TSDB_MAX_TAGS 128 +#define TSDB_MAX_BYTES_PER_ROW 49151 +#define TSDB_MAX_TAGS_LEN 16384 +#define TSDB_MAX_TAGS 128 #define TSDB_MAX_COL_TAG_NUM (TSDB_MAX_COLUMNS + TSDB_MAX_TAGS) #define TSDB_MAX_JSON_TAG_LEN 16384 @@ -290,7 +290,7 @@ typedef enum ELogicConditionType { #define TSDB_DEFAULT_VN_PER_DB 2 #define TSDB_MIN_BUFFER_PER_VNODE 3 // unit MB #define TSDB_MAX_BUFFER_PER_VNODE 16384 // unit MB -#define TSDB_DEFAULT_BUFFER_PER_VNODE 96 +#define TSDB_DEFAULT_BUFFER_PER_VNODE 256 #define TSDB_MIN_PAGES_PER_VNODE 64 #define TSDB_MAX_PAGES_PER_VNODE (INT32_MAX - 1) #define TSDB_DEFAULT_PAGES_PER_VNODE 256 @@ -360,7 +360,7 @@ typedef enum ELogicConditionType { #define TSDB_DEFAULT_DB_SCHEMALESS TSDB_DB_SCHEMALESS_OFF #define TSDB_MIN_STT_TRIGGER 1 #define TSDB_MAX_STT_TRIGGER 16 -#define TSDB_DEFAULT_SST_TRIGGER 8 +#define TSDB_DEFAULT_SST_TRIGGER 1 #define TSDB_MIN_HASH_PREFIX 0 #define TSDB_MAX_HASH_PREFIX 128 #define TSDB_DEFAULT_HASH_PREFIX 0 @@ -370,13 +370,13 @@ typedef enum ELogicConditionType { #define TSDB_DB_MIN_WAL_RETENTION_PERIOD -1 #define TSDB_REP_DEF_DB_WAL_RET_PERIOD 0 -#define TSDB_REPS_DEF_DB_WAL_RET_PERIOD (24 * 60 * 60 * 4) +#define TSDB_REPS_DEF_DB_WAL_RET_PERIOD 0 #define TSDB_DB_MIN_WAL_RETENTION_SIZE -1 #define TSDB_REP_DEF_DB_WAL_RET_SIZE 0 -#define TSDB_REPS_DEF_DB_WAL_RET_SIZE -1 +#define TSDB_REPS_DEF_DB_WAL_RET_SIZE 0 #define TSDB_DB_MIN_WAL_ROLL_PERIOD 0 #define TSDB_REP_DEF_DB_WAL_ROLL_PERIOD 0 -#define TSDB_REPS_DEF_DB_WAL_ROLL_PERIOD (24 * 60 * 60 * 1) +#define TSDB_REPS_DEF_DB_WAL_ROLL_PERIOD 0 #define TSDB_DB_MIN_WAL_SEGMENT_SIZE 0 #define TSDB_DEFAULT_DB_WAL_SEGMENT_SIZE 0 @@ -409,7 +409,7 @@ typedef enum ELogicConditionType { #define TSDB_MAX_RPC_THREADS 10 #endif -#define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type +#define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type #define TSDB_META_COMPACT_RATIO 0 // disable tsdb meta compact by default @@ -486,7 +486,7 @@ enum { #define MAX_NUM_STR_SIZE 40 -#define MAX_META_MSG_IN_BATCH 1048576 +#define MAX_META_MSG_IN_BATCH 1048576 #define MAX_META_BATCH_RSP_SIZE (1 * 1048576 * 1024) #ifdef __cplusplus diff --git a/include/util/tqueue.h b/include/util/tqueue.h index da409a90bb96c2b19ad081c4599a9fa75de1ad4e..8b46bbd0642366d9dce26f406939b3c3112cb97e 100644 --- a/include/util/tqueue.h +++ b/include/util/tqueue.h @@ -59,6 +59,47 @@ typedef enum { typedef void (*FItem)(SQueueInfo *pInfo, void *pItem); typedef void (*FItems)(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfItems); +typedef struct STaosQnode STaosQnode; + +typedef struct STaosQnode { + STaosQnode *next; + STaosQueue *queue; + int64_t timestamp; + int32_t size; + int8_t itype; + int8_t reserved[3]; + char item[]; +} STaosQnode; + +typedef struct STaosQueue { + STaosQnode *head; + STaosQnode *tail; + STaosQueue *next; // for queue set + STaosQset *qset; // for queue set + void *ahandle; // for queue set + FItem itemFp; + FItems itemsFp; + TdThreadMutex mutex; + int64_t memOfItems; + int32_t numOfItems; + int64_t threadId; +} STaosQueue; + +typedef struct STaosQset { + STaosQueue *head; + STaosQueue *current; + TdThreadMutex mutex; + tsem_t sem; + int32_t numOfQueues; + int32_t numOfItems; +} STaosQset; + +typedef struct STaosQall { + STaosQnode *current; + STaosQnode *start; + int32_t numOfItems; +} STaosQall; + STaosQueue *taosOpenQueue(); void taosCloseQueue(STaosQueue *queue); void taosSetQueueFp(STaosQueue *queue, FItem itemFp, FItems itemsFp); diff --git a/include/util/tref.h b/include/util/tref.h index c2cc54cb07ac3167941061b475f8811e460a3b91..c4b2ec8fa72b1ec58456f76a20f5ac7757e014f7 100644 --- a/include/util/tref.h +++ b/include/util/tref.h @@ -25,7 +25,8 @@ extern "C" { // open a reference set, max is the mod used by hash, fp is the pointer to free resource function // return rsetId which will be used by other APIs. On error, -1 is returned, and terrno is set appropriately -int32_t taosOpenRef(int32_t max, void (*fp)(void *)); +typedef void (*RefFp)(void *); +int32_t taosOpenRef(int32_t max, RefFp fp); // close the reference set, refId is the return value by taosOpenRef // return 0 if success. On error, -1 is returned, and terrno is set appropriately diff --git a/include/util/tworker.h b/include/util/tworker.h index 3545aeed898b990fce7be3e2d34eb4496123c6d6..8766f87a0870aef3b3a4d08ed84ba55dc96c50f7 100644 --- a/include/util/tworker.h +++ b/include/util/tworker.h @@ -26,8 +26,9 @@ typedef struct SQWorkerPool SQWorkerPool; typedef struct SWWorkerPool SWWorkerPool; typedef struct SQWorker { - int32_t id; // worker ID - TdThread thread; // thread + int32_t id; // worker id + int64_t pid; // thread pid + TdThread thread; // thread id SQWorkerPool *pool; } SQWorker; @@ -43,9 +44,10 @@ typedef struct SQWorkerPool { typedef struct SWWorker { int32_t id; // worker id - TdThread thread; // thread + int64_t pid; // thread pid + TdThread thread; // thread id STaosQall *qall; - STaosQset *qset; // queue set + STaosQset *qset; SWWorkerPool *pool; } SWWorker; diff --git a/packaging/MPtestJenkinsfile b/packaging/MPtestJenkinsfile index 5b793459164baec2791107842bddb3f0bb90b2df..5dc8024f29ddc0f09727d167aceb3f2516886488 100644 --- a/packaging/MPtestJenkinsfile +++ b/packaging/MPtestJenkinsfile @@ -13,7 +13,7 @@ def sync_source(branch_name) { git branch git pull || git pull git log | head -n 20 - git submodule update --init --recursive + git clean -fxd ''' return 1 } @@ -37,19 +37,24 @@ def build_run() { pipeline { agent none parameters { + choice( + name: 'sourcePath', + choices: ['nas','web'], + description: 'choice which way to download the installation pacakge;web is Office Web and nas means taos nas server ' + ) string ( name:'version', - defaultValue:'3.0.0.1', + defaultValue:'3.0.1.6', description: 'release version number,eg: 3.0.0.1 or 3.0.0.' ) string ( name:'baseVersion', - defaultValue:'3.0.0.1', + defaultValue:'3.0.1.6', description: 'This number of baseVerison is generally not modified.Now it is 3.0.0.1' ) string ( name:'toolsVersion', - defaultValue:'2.1.2', + defaultValue:'2.2.7', description: 'This number of baseVerison is generally not modified.Now it is 3.0.0.1' ) string ( @@ -62,7 +67,7 @@ pipeline { WORK_DIR = '/var/lib/jenkins/workspace' TDINTERNAL_ROOT_DIR = '/var/lib/jenkins/workspace/TDinternal' TDENGINE_ROOT_DIR = '/var/lib/jenkins/workspace/TDinternal/community' - BRANCH_NAME = 'test/chr/TD-14699' + BRANCH_NAME = '3.0' TD_SERVER_TAR = "TDengine-server-${version}-Linux-x64.tar.gz" BASE_TD_SERVER_TAR = "TDengine-server-${baseVersion}-Linux-x64.tar.gz" @@ -104,17 +109,17 @@ pipeline { sync_source("${BRANCH_NAME}") sh ''' cd ${TDENGINE_ROOT_DIR}/packaging - bash testpackage.sh ${TD_SERVER_TAR} ${version} ${BASE_TD_SERVER_TAR} ${baseVersion} server + bash testpackage.sh ${TD_SERVER_TAR} ${version} ${BASE_TD_SERVER_TAR} ${baseVersion} server ${sourcePath} python3 checkPackageRuning.py ''' sh ''' cd ${TDENGINE_ROOT_DIR}/packaging - bash testpackage.sh ${TD_SERVER_LITE_TAR} ${version} ${BASE_TD_SERVER_LITE_TAR} ${baseVersion} server + bash testpackage.sh ${TD_SERVER_LITE_TAR} ${version} ${BASE_TD_SERVER_LITE_TAR} ${baseVersion} server ${sourcePath} python3 checkPackageRuning.py ''' sh ''' cd ${TDENGINE_ROOT_DIR}/packaging - bash testpackage.sh ${TD_SERVER_DEB} ${version} ${BASE_TD_SERVER_TAR} ${baseVersion} server + bash testpackage.sh ${TD_SERVER_DEB} ${version} ${BASE_TD_SERVER_TAR} ${baseVersion} server ${sourcePath} python3 checkPackageRuning.py ''' } @@ -127,17 +132,17 @@ pipeline { sync_source("${BRANCH_NAME}") sh ''' cd ${TDENGINE_ROOT_DIR}/packaging - bash testpackage.sh ${TD_SERVER_TAR} ${version} ${BASE_TD_SERVER_TAR} ${baseVersion} server + bash testpackage.sh ${TD_SERVER_TAR} ${version} ${BASE_TD_SERVER_TAR} ${baseVersion} server ${sourcePath} python3 checkPackageRuning.py ''' sh ''' cd ${TDENGINE_ROOT_DIR}/packaging - bash testpackage.sh ${TD_SERVER_LITE_TAR} ${version} ${BASE_TD_SERVER_LITE_TAR} ${baseVersion} server + bash testpackage.sh ${TD_SERVER_LITE_TAR} ${version} ${BASE_TD_SERVER_LITE_TAR} ${baseVersion} server ${sourcePath} python3 checkPackageRuning.py ''' sh ''' cd ${TDENGINE_ROOT_DIR}/packaging - bash testpackage.sh ${TD_SERVER_DEB} ${version} ${BASE_TD_SERVER_TAR} ${baseVersion} server + bash testpackage.sh ${TD_SERVER_DEB} ${version} ${BASE_TD_SERVER_TAR} ${baseVersion} server ${sourcePath} python3 checkPackageRuning.py dpkg -r tdengine ''' @@ -152,17 +157,17 @@ pipeline { sync_source("${BRANCH_NAME}") sh ''' cd ${TDENGINE_ROOT_DIR}/packaging - bash testpackage.sh ${TD_SERVER_TAR} ${version} ${BASE_TD_SERVER_TAR} ${baseVersion} server + bash testpackage.sh ${TD_SERVER_TAR} ${version} ${BASE_TD_SERVER_TAR} ${baseVersion} server ${sourcePath} python3 checkPackageRuning.py ''' sh ''' cd ${TDENGINE_ROOT_DIR}/packaging - bash testpackage.sh ${TD_SERVER_LITE_TAR} ${version} ${BASE_TD_SERVER_LITE_TAR} ${baseVersion} server + bash testpackage.sh ${TD_SERVER_LITE_TAR} ${version} ${BASE_TD_SERVER_LITE_TAR} ${baseVersion} server ${sourcePath} python3 checkPackageRuning.py ''' sh ''' cd ${TDENGINE_ROOT_DIR}/packaging - bash testpackage.sh ${TD_SERVER_RPM} ${version} ${BASE_TD_SERVER_TAR} ${baseVersion} server + bash testpackage.sh ${TD_SERVER_RPM} ${version} ${BASE_TD_SERVER_TAR} ${baseVersion} server ${sourcePath} python3 checkPackageRuning.py ''' } @@ -175,17 +180,17 @@ pipeline { sync_source("${BRANCH_NAME}") sh ''' cd ${TDENGINE_ROOT_DIR}/packaging - bash testpackage.sh ${TD_SERVER_TAR} ${version} ${BASE_TD_SERVER_TAR} ${baseVersion} server + bash testpackage.sh ${TD_SERVER_TAR} ${version} ${BASE_TD_SERVER_TAR} ${baseVersion} server ${sourcePath} python3 checkPackageRuning.py ''' sh ''' cd ${TDENGINE_ROOT_DIR}/packaging - bash testpackage.sh ${TD_SERVER_LITE_TAR} ${version} ${BASE_TD_SERVER_LITE_TAR} ${baseVersion} server + bash testpackage.sh ${TD_SERVER_LITE_TAR} ${version} ${BASE_TD_SERVER_LITE_TAR} ${baseVersion} server ${sourcePath} python3 checkPackageRuning.py ''' sh ''' cd ${TDENGINE_ROOT_DIR}/packaging - bash testpackage.sh ${TD_SERVER_RPM} ${version} ${BASE_TD_SERVER_TAR} ${baseVersion} server + bash testpackage.sh ${TD_SERVER_RPM} ${version} ${BASE_TD_SERVER_TAR} ${baseVersion} server ${sourcePath} python3 checkPackageRuning.py sudo rpm -e tdengine ''' @@ -199,7 +204,7 @@ pipeline { sync_source("${BRANCH_NAME}") sh ''' cd ${TDENGINE_ROOT_DIR}/packaging - bash testpackage.sh ${TD_SERVER_ARM_TAR} ${version} ${BASE_TD_SERVER_ARM_TAR} ${baseVersion} server + bash testpackage.sh ${TD_SERVER_ARM_TAR} ${version} ${BASE_TD_SERVER_ARM_TAR} ${baseVersion} server ${sourcePath} python3 checkPackageRuning.py ''' } @@ -215,7 +220,7 @@ pipeline { timeout(time: 30, unit: 'MINUTES'){ sh ''' cd ${TDENGINE_ROOT_DIR}/packaging - bash testpackage.sh ${TD_CLIENT_TAR} ${version} ${BASE_TD_CLIENT_TAR} ${baseVersion} client + bash testpackage.sh ${TD_CLIENT_TAR} ${version} ${BASE_TD_CLIENT_TAR} ${baseVersion} client ${sourcePath} python3 checkPackageRuning.py 192.168.0.21 ''' } @@ -227,7 +232,7 @@ pipeline { timeout(time: 30, unit: 'MINUTES'){ sh ''' cd ${TDENGINE_ROOT_DIR}/packaging - bash testpackage.sh ${TD_CLIENT_LITE_TAR} ${version} ${BASE_TD_CLIENT_LITE_TAR} ${baseVersion} client + bash testpackage.sh ${TD_CLIENT_LITE_TAR} ${version} ${BASE_TD_CLIENT_LITE_TAR} ${baseVersion} client ${sourcePath} python3 checkPackageRuning.py 192.168.0.24 ''' } @@ -241,7 +246,7 @@ pipeline { timeout(time: 30, unit: 'MINUTES'){ sh ''' cd ${TDENGINE_ROOT_DIR}/packaging - bash testpackage.sh ${TD_CLIENT_ARM_TAR} ${version} ${BASE_TD_CLIENT_ARM_TAR} ${baseVersion} client + bash testpackage.sh ${TD_CLIENT_ARM_TAR} ${version} ${BASE_TD_CLIENT_ARM_TAR} ${baseVersion} client ${sourcePath} python3 checkPackageRuning.py 192.168.0.21 ''' } diff --git a/packaging/cfg/taos.cfg b/packaging/cfg/taos.cfg index 87f465fdb93ddbff8973430b11ecadc13878069d..eeb089d1abe9266231924f5543bfa7b5e85bd5ad 100644 --- a/packaging/cfg/taos.cfg +++ b/packaging/cfg/taos.cfg @@ -5,42 +5,50 @@ # # ######################################################## -# The end point of the first dnode in the cluster to be connected to when `taosd` or `taos` is started +######### 0. Client only configurations ############# + +# The interval for TDengine CLI to send heartbeat to mnode +# shellActivityTimer 3 + + +############### 1. Cluster End point ############################ + +# The end point of the first dnode in the cluster to be connected to when this dnode or a TDengine CLI `taos` is started # firstEp hostname:6030 -# The end point of the second dnode to be connected to if the firstEp is not available when `taosd` or `taos` is started +# The end point of the second dnode to be connected to if the firstEp is not available # secondEp -# The FQDN of the host where `taosd` will be started. It can be IP address + +############### 2. Configuration Parameters of current dnode ##### + +# The FQDN of the host on which this dnode will be started. It can be IP address # fqdn hostname -# The port for external access after `taosd` is started +# The port for external access after this dnode is started # serverPort 6030 # The maximum number of connections a dnode can accept -# maxShellConns 5000 +# maxShellConns 5000 -# The directory for writing log files +# The directory for writing log files, if you are using Windows platform please change to Windows path # logDir /var/log/taos -# All data files are stored in this directory +# All data files are stored in this directory, if you are using Windows platform please change to Windows path # dataDir /var/lib/taos -# temporary file's directory +# temporary file's directory, if you are using Windows platform please change to Windows path # tempDir /tmp/ # Switch for allowing TDengine to collect and report service usage information # telemetryReporting 1 -# The maximum number of vnodes supported by dnode +# The maximum number of vnodes supported by this dnode # supportVnodes 0 -# The interval of dnode reporting status to mnode +# The interval of this dnode reporting status to mnode, [1..10] seconds # statusInterval 1 -# The interval for TDengine CLI to send heartbeat to mnode -# shellActivityTimer 3 - # The minimum sliding window time, milli-second # minSlidingTime 10 @@ -66,13 +74,14 @@ # system time zone # timezone Asia/Shanghai (CST, +0800) + # system time zone (for windows 10) # timezone UTC-8 # system locale # locale en_US.UTF-8 -# default system charset +# system charset # charset UTF-8 # stop writing logs when the disk size of the log folder is less than this value @@ -81,7 +90,7 @@ # stop writing temporary files when the disk size of the tmp folder is less than this value # minimalTmpDirGB 1.0 -# if disk free space is less than this value, taosd service exit directly within startup process +# if free disk space is less than this value, this dnode will fail to start # minimalDataDirGB 2.0 # enable/disable system monitor @@ -91,14 +100,18 @@ # max number of lines per log filters # numOfLogLines 10000000 -# enable/disable async log +# write log in async way: 1 - async, 0 - sync # asyncLog 1 -# time of keeping log files, days +# time period of keeping log files, in days # logKeepDays 0 -# The following parameters are used for debug purpose only. -# debugFlag 8 bits mask: FILE-SCREEN-UNUSED-HeartBeat-DUMP-TRACE_WARN-ERROR + +############ 3. Debug Flag and levels ############################################# + +# The following parameters are used for debug purpose only by this dnode. +# debugFlag is a 8 bits mask: FILE-SCREEN-UNUSED-HeartBeat-DUMP-TRACE_WARN-ERROR +# Available debug levels are: # 131: output warning and error # 135: output debug, warning and error # 143: output trace, debug, warning and error to log @@ -166,4 +179,4 @@ # metaDebugFlag 131 # generate core file when service crash -# enableCoreFile 1 +# enableCoreFile 1 \ No newline at end of file diff --git a/packaging/release.bat b/packaging/release.bat index b87ae68e2b2f8b0507992206af6ed482e5a9392c..4ab7297f03931ef2fe8a0de9d641f86c2cb3d59e 100644 --- a/packaging/release.bat +++ b/packaging/release.bat @@ -39,8 +39,8 @@ if not exist %work_dir%\debug\ver-%2-x86 ( md %work_dir%\debug\ver-%2-x86 ) cd %work_dir%\debug\ver-%2-x64 -call vcvarsall.bat x64 -cmake ../../ -G "NMake Makefiles JOM" -DCMAKE_MAKE_PROGRAM=jom -DBUILD_TOOLS=true -DBUILD_HTTP=false -DBUILD_TEST=false -DVERNUMBER=%2 -DCPUTYPE=x64 +rem #call vcvarsall.bat x64 +cmake ../../ -G "NMake Makefiles JOM" -DCMAKE_MAKE_PROGRAM=jom -DBUILD_TOOLS=true -DWEBSOCKET=true -DBUILD_HTTP=false -DBUILD_TEST=false -DVERNUMBER=%2 -DCPUTYPE=x64 cmake --build . rd /s /Q C:\TDengine cmake --install . @@ -63,4 +63,4 @@ exit /b :RUNFAILED echo %* cd %package_dir% -goto :eof \ No newline at end of file +goto :eof diff --git a/packaging/testpackage.sh b/packaging/testpackage.sh index 20f93ecaec41045fca38c552e0b150c65b37c0be..b0e33835ddf5316d4d8374baaa657176642af181 100755 --- a/packaging/testpackage.sh +++ b/packaging/testpackage.sh @@ -6,6 +6,8 @@ version=$2 originPackageName=$3 originversion=$4 testFile=$5 +# sourcePath:web/nas +sourcePath=$6 subFile="taos.tar.gz" # Color setting @@ -67,16 +69,27 @@ fi } + function wgetFile { file=$1 +versionPath=$2 +sourceP=$3 +nasServerIP="192.168.1.131" +packagePath="/nas/TDengine/v${versionPath}/community" +if [ -f ${file} ];then + echoColor YD "${file} already exists ,it will delete it and download it again " + rm -rf ${file} +fi -if [ ! -f ${file} ];then - echoColor BD "wget https://www.taosdata.com/assets-download/3.0/${file}" +if [ ${sourceP} = 'web' ];then + echoColor BD "====download====:wget https://www.taosdata.com/assets-download/3.0/${file}" wget https://www.taosdata.com/assets-download/3.0/${file} -else - echoColor YD "${file} already exists " +elif [ ${sourceP} = 'nas' ];then + echoColor BD "====download====:scp root@${nasServerIP}:${packagePath}/${file} ." + scp root@${nasServerIP}:${packagePath}/${file} . fi + } function newPath { @@ -138,8 +151,9 @@ if [ -d ${installPath}/${tdPath} ] ;then fi echoColor G "===== download installPackage =====" -cd ${installPath} && wgetFile ${packgeName} -cd ${oriInstallPath} && wgetFile ${originPackageName} +cd ${installPath} && wgetFile ${packgeName} ${version} ${sourcePath} +cd ${oriInstallPath} && wgetFile ${originPackageName} ${originversion} ${sourcePath} + cd ${installPath} cp -r ${scriptDir}/debRpmAutoInstall.sh . @@ -189,7 +203,7 @@ elif [[ ${packgeName} =~ "tar" ]];then cd ${oriInstallPath} if [ ! -f {originPackageName} ];then echoColor YD "download base installPackage" - wgetFile ${originPackageName} + wgetFile ${originPackageName} ${originversion} ${sourcePath} fi echoColor YD "unzip the base installation package" echoColor BD "tar -xf ${originPackageName}" && tar -xf ${originPackageName} @@ -211,7 +225,8 @@ elif [[ ${packgeName} =~ "tar" ]];then if [ ${diffNumbers} != 0 ];then echoColor R "The number and names of files is different from the previous installation package" - echoColor Y `cat ${installPath}/diffFile.log` + diffLog=`cat ${installPath}/diffFile.log` + echoColor Y "${diffLog}" exit -1 else echoColor G "The number and names of files are the same as previous installation packages" @@ -233,14 +248,19 @@ cd ${installPath} if [[ ${packgeName} =~ "Lite" ]] || ([[ ${packgeName} =~ "x64" ]] && [[ ${packgeName} =~ "client" ]]) || ([[ ${packgeName} =~ "deb" ]] && [[ ${packgeName} =~ "server" ]]) || ([[ ${packgeName} =~ "rpm" ]] && [[ ${packgeName} =~ "server" ]]) ;then echoColor G "===== install taos-tools when package is lite or client =====" cd ${installPath} - wgetFile taosTools-2.1.3-Linux-x64.tar.gz . - tar xf taosTools-2.1.3-Linux-x64.tar.gz + if [ ! -f "taosTools-2.1.3-Linux-x64.tar.gz " ];then + wgetFile taosTools-2.1.3-Linux-x64.tar.gz v2.1.3 web + tar xf taosTools-2.1.3-Linux-x64.tar.gz + fi cd taosTools-2.1.3 && bash install-taostools.sh elif ([[ ${packgeName} =~ "arm64" ]] && [[ ${packgeName} =~ "client" ]]);then echoColor G "===== install taos-tools arm when package is arm64-client =====" cd ${installPath} - wgetFile taosTools-2.1.3-Linux-arm64.tar.gz . - tar xf taosTools-2.1.3-Linux-arm64.tar.gz + if [ ! -f "taosTools-2.1.3-Linux-x64.tar.gz " ];then + wgetFile taosTools-2.1.3-Linux-x64.tar.gz v2.1.3 web + tar xf taosTools-2.1.3-Linux-arm64.tar.gz + fi + cd taosTools-2.1.3 && bash install-taostools.sh fi diff --git a/packaging/tools/make_install.bat b/packaging/tools/make_install.bat index f777d10918844690be56828b66fb8853112be27e..c19519f9a1fc4c014c01496ca32925ba1eb19516 100644 --- a/packaging/tools/make_install.bat +++ b/packaging/tools/make_install.bat @@ -1,4 +1,7 @@ @echo off + +for /F %%a in ('echo prompt $E ^| cmd') do set "ESC=%%a" + goto %1 :needAdmin @@ -11,59 +14,94 @@ set binary_dir=%3 set binary_dir=%binary_dir:/=\\% set osType=%4 set verNumber=%5 -set tagert_dir=C:\\TDengine +set target_dir=C:\\TDengine -if not exist %tagert_dir% ( - mkdir %tagert_dir% +if not exist %target_dir% ( + mkdir %target_dir% ) -if not exist %tagert_dir%\\cfg ( - mkdir %tagert_dir%\\cfg +if not exist %target_dir%\\cfg ( + mkdir %target_dir%\\cfg ) -if not exist %tagert_dir%\\include ( - mkdir %tagert_dir%\\include +if not exist %target_dir%\\include ( + mkdir %target_dir%\\include ) -if not exist %tagert_dir%\\driver ( - mkdir %tagert_dir%\\driver +if not exist %target_dir%\\driver ( + mkdir %target_dir%\\driver ) if not exist C:\\TDengine\\cfg\\taos.cfg ( - copy %source_dir%\\packaging\\cfg\\taos.cfg %tagert_dir%\\cfg\\taos.cfg > nul + copy %source_dir%\\packaging\\cfg\\taos.cfg %target_dir%\\cfg\\taos.cfg > nul ) if exist %binary_dir%\\test\\cfg\\taosadapter.toml ( - if not exist %tagert_dir%\\cfg\\taosadapter.toml ( - copy %binary_dir%\\test\\cfg\\taosadapter.toml %tagert_dir%\\cfg\\taosadapter.toml > nul + if not exist %target_dir%\\cfg\\taosadapter.toml ( + copy %binary_dir%\\test\\cfg\\taosadapter.toml %target_dir%\\cfg\\taosadapter.toml > nul ) ) - -copy %source_dir%\\include\\client\\taos.h %tagert_dir%\\include > nul -copy %source_dir%\\include\\util\\taoserror.h %tagert_dir%\\include > nul -copy %source_dir%\\include\\libs\\function\\taosudf.h %tagert_dir%\\include > nul -copy %binary_dir%\\build\\lib\\taos.lib %tagert_dir%\\driver > nul -copy %binary_dir%\\build\\lib\\taos_static.lib %tagert_dir%\\driver > nul -copy %binary_dir%\\build\\lib\\taos.dll %tagert_dir%\\driver > nul -copy %binary_dir%\\build\\bin\\taos.exe %tagert_dir% > nul -copy %binary_dir%\\build\\bin\\taosd.exe %tagert_dir% > nul -copy %binary_dir%\\build\\bin\\udfd.exe %tagert_dir% > nul +copy %source_dir%\\include\\client\\taos.h %target_dir%\\include > nul +copy %source_dir%\\include\\util\\taoserror.h %target_dir%\\include > nul +copy %source_dir%\\include\\libs\\function\\taosudf.h %target_dir%\\include > nul +copy %binary_dir%\\build\\lib\\taos.lib %target_dir%\\driver > nul +copy %binary_dir%\\build\\lib\\taos_static.lib %target_dir%\\driver > nul +copy %binary_dir%\\build\\lib\\taos.dll %target_dir%\\driver > nul +copy %binary_dir%\\build\\bin\\taos.exe %target_dir% > nul if exist %binary_dir%\\build\\bin\\taosBenchmark.exe ( - copy %binary_dir%\\build\\bin\\taosBenchmark.exe %tagert_dir% > nul + copy %binary_dir%\\build\\bin\\taosBenchmark.exe %target_dir% > nul ) if exist %binary_dir%\\build\\lib\\taosws.dll.lib ( - copy %binary_dir%\\build\\lib\\taosws.dll.lib %tagert_dir%\\driver > nul + copy %binary_dir%\\build\\lib\\taosws.dll.lib %target_dir%\\driver > nul ) if exist %binary_dir%\\build\\lib\\taosws.dll ( - copy %binary_dir%\\build\\lib\\taosws.dll %tagert_dir%\\driver > nul + copy %binary_dir%\\build\\lib\\taosws.dll %target_dir%\\driver > nul + copy %source_dir%\\tools\\taosws-rs\\target\\release\\taosws.h %target_dir%\\include > nul ) if exist %binary_dir%\\build\\bin\\taosdump.exe ( - copy %binary_dir%\\build\\bin\\taosdump.exe %tagert_dir% > nul + copy %binary_dir%\\build\\bin\\taosdump.exe %target_dir% > nul +) + +copy %binary_dir%\\build\\bin\\taosd.exe %target_dir% > nul +copy %binary_dir%\\build\\bin\\udfd.exe %target_dir% > nul + +if exist %binary_dir%\\build\\bin\\taosadapter.exe ( + copy %binary_dir%\\build\\bin\\taosadapter.exe %target_dir% > nul ) + +mshta vbscript:createobject("shell.application").shellexecute("%~s0",":hasAdmin","","runas",1)(window.close) + +echo. +echo Please manually remove C:\TDengine from your system PATH environment after you remove TDengine software +echo. +echo To start/stop TDengine with administrator privileges: %ESC%[92msc start/stop taosd %ESC%[0m + if exist %binary_dir%\\build\\bin\\taosadapter.exe ( - copy %binary_dir%\\build\\bin\\taosadapter.exe %tagert_dir% > nul + echo To start/stop taosAdapter with administrator privileges: %ESC%[92msc start/stop taosadapter %ESC%[0m ) -mshta vbscript:createobject("shell.application").shellexecute("%~s0",":hasAdmin","","runas",1)(window.close)&& echo To start/stop TDengine with administrator privileges: sc start/stop taosd &goto :eof +goto :eof + :hasAdmin + +sc query "taosd" && sc stop taosd && sc delete taosd +sc query "taosadapter" && sc stop taosadapter && sc delete taosd + copy /y C:\\TDengine\\driver\\taos.dll C:\\Windows\\System32 > nul if exist C:\\TDengine\\driver\\taosws.dll ( copy /y C:\\TDengine\\driver\\taosws.dll C:\\Windows\\System32 > nul ) + sc query "taosd" >nul || sc create "taosd" binPath= "C:\\TDengine\\taosd.exe --win_service" start= DEMAND +sc query "taosadapter" >nul || sc create "taosadapter" binPath= "C:\\TDengine\\taosadapter.exe" start= DEMAND + +set "env=HKLM\System\CurrentControlSet\Control\Session Manager\Environment" +for /f "tokens=2*" %%I in ('reg query "%env%" /v Path ^| findstr /i "\"') do ( + + rem // make addition persistent through reboots + reg add "%env%" /f /v Path /t REG_EXPAND_SZ /d "%%J;C:\TDengine" + + rem // apply change to the current process + for %%a in ("%%J;C:\TDengine") do path %%~a +) + +rem // use setx to set a temporary throwaway value to trigger a WM_SETTINGCHANGE +rem // applies change to new console windows without requiring a reboot +(setx /m foo bar & reg delete "%env%" /f /v foo) >NUL 2>NUL + diff --git a/packaging/tools/makepkg.sh b/packaging/tools/makepkg.sh index e9546ba103b885cd44c2ad658e239b15d904772e..2776683a249c3376b9cf5e5d54ba43f534f3df47 100755 --- a/packaging/tools/makepkg.sh +++ b/packaging/tools/makepkg.sh @@ -285,10 +285,14 @@ if [[ $dbName == "taos" ]]; then fi # Add web files - if [ -d "${web_dir}/admin" ]; then - mkdir -p ${install_dir}/share/ - cp ${web_dir}/admin ${install_dir}/share/ -r - cp ${web_dir}/png/taos.png ${install_dir}/share/admin/images/taos.png + if [ "$verMode" == "cluster" ] || [ "$verMode" == "cloud" ]; then + if [ -d "${web_dir}/admin" ] ; then + mkdir -p ${install_dir}/share/ + cp ${web_dir}/admin ${install_dir}/share/ -r + cp ${web_dir}/png/taos.png ${install_dir}/share/admin/images/taos.png + else + echo "directory not found for enterprise release: ${web_dir}/admin" + fi fi fi @@ -375,4 +379,4 @@ if [ -n "${taostools_bin_files}" ]; then fi fi -cd ${curr_dir} +cd ${curr_dir} \ No newline at end of file diff --git a/packaging/tools/tdengine.iss b/packaging/tools/tdengine.iss index 272a0dfb5c556bf9ed1f5a567579e1a93b10be80..981bee91b87bd60b38dc7a560c8ca519afbac499 100644 --- a/packaging/tools/tdengine.iss +++ b/packaging/tools/tdengine.iss @@ -15,10 +15,10 @@ #define MyAppExeName "\*.exe" #define MyAppTaosExeName "\taos.bat" #define MyAppTaosdemoExeName "\taosBenchmark.exe" -#define MyAppDLLName "\driver\taos.dll" +#define MyAppDLLName "\driver\*.dll" ;#define MyAppVersion "3.0" ;#define MyAppInstallName "TDengine" - +;#define MyAppInstallName "TDengine" [Setup] VersionInfoVersion={#MyAppVersion} AppId={{A0F7A93C-79C4-485D-B2B8-F0D03DF42FAB} @@ -60,6 +60,29 @@ Source: {#MyAppSourceDir}{#MyAppIncludeName}; DestDir: "{app}\include"; Flags: i Source: {#MyAppSourceDir}{#MyAppExeName}; DestDir: "{app}"; Excludes: {#MyAppExcludeSource} ; Flags: igNoreversion recursesubdirs createallsubdirs Source: {#MyAppSourceDir}{#MyAppTaosdemoExeName}; DestDir: "{app}"; Flags: igNoreversion recursesubdirs createallsubdirs + +[Registry] +Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; \ + ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};C:\TDengine"; \ + Check: NeedsAddPath('C:\TDengine') + +[Code] +function NeedsAddPath(Param: string): boolean; +var + OrigPath: string; +begin + if not RegQueryStringValue(HKEY_LOCAL_MACHINE, + 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', + 'Path', OrigPath) + then begin + Result := True; + exit; + end; + { look for the path with leading and trailing semicolon } + { Pos() returns 0 if not found } + Result := Pos(';' + Param + ';', ';' + OrigPath + ';') = 0; +end; + [UninstallDelete] Name: {app}\driver; Type: filesandordirs Name: {app}\connector; Type: filesandordirs diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index cf8b0babdd15a22c4fde32da9fddb3854cec36af..e569a977239c5feca935b99fe200096053755849 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -271,7 +271,11 @@ int32_t transferTableNameList(const char* tbList, int32_t acctId, char* dbName, void syncCatalogFn(SMetaData* pResult, void* param, int32_t code); TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly); -void taosAsyncQueryImpl(uint64_t connId, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly); +TAOS_RES* taosQueryImplWithReqid(TAOS* taos, const char* sql, bool validateOnly, int64_t reqid); + +void taosAsyncQueryImpl(uint64_t connId, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly); +void taosAsyncQueryImplWithReqid(uint64_t connId, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly, + int64_t reqid); int32_t getVersion1BlockMetaSize(const char* p, int32_t numOfCols); @@ -318,10 +322,11 @@ void* createTscObj(const char* user, const char* auth, const char* db, int32_ void destroyTscObj(void* pObj); STscObj* acquireTscObj(int64_t rid); int32_t releaseTscObj(int64_t rid); +void destroyAppInst(SAppInstInfo* pAppInfo); uint64_t generateRequestId(); -void* createRequest(uint64_t connId, int32_t type); +void* createRequest(uint64_t connId, int32_t type, int64_t reqid); void destroyRequest(SRequestObj* pRequest); SRequestObj* acquireRequest(int64_t rid); int32_t releaseRequest(int64_t rid); @@ -352,7 +357,7 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtC int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList); int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param, bool validateSql, - SRequestObj** pRequest); + SRequestObj** pRequest, int64_t reqid); void taos_close_internal(void* taos); @@ -379,7 +384,6 @@ void hbMgrInitMqHbRspHandle(); typedef struct SSqlCallbackWrapper { SParseContext* pParseCtx; SCatalogReq* pCatalogReq; - SMetaData* pResultMeta; SRequestObj* pRequest; } SSqlCallbackWrapper; @@ -393,7 +397,7 @@ int32_t removeMeta(STscObj* pTscObj, SArray* tbList); int32_t handleAlterTbExecRes(void* res, struct SCatalog* pCatalog); int32_t handleCreateTbExecRes(void* res, SCatalog* pCatalog); bool qnodeRequired(SRequestObj* pRequest); -int32_t continueInsertFromCsv(SSqlCallbackWrapper* pWrapper, SRequestObj* pRequest); +void continueInsertFromCsv(SSqlCallbackWrapper* pWrapper, SRequestObj* pRequest); void destorySqlCallbackWrapper(SSqlCallbackWrapper* pWrapper); #ifdef __cplusplus diff --git a/source/client/inc/clientStmt.h b/source/client/inc/clientStmt.h index 2261a6becb30c01e5d8edb096169721d84a4a88c..e5507ccf816b9fd591e6e27ee2974badcb5734ed 100644 --- a/source/client/inc/clientStmt.h +++ b/source/client/inc/clientStmt.h @@ -39,6 +39,7 @@ typedef enum { STMT_BIND_COL, STMT_ADD_BATCH, STMT_EXECUTE, + STMT_MAX, } STMT_STATUS; typedef struct SStmtTableCache { @@ -94,12 +95,25 @@ typedef struct STscStmt { STscObj *taos; SCatalog *pCatalog; int32_t affectedRows; + uint32_t seqId; + uint32_t seqIds[STMT_MAX]; SStmtSQLInfo sql; SStmtExecInfo exec; SStmtBindInfo bInfo; + + int64_t reqid; } STscStmt; +extern char *gStmtStatusStr[]; + +#define STMT_LOG_SEQ(n) \ + do { \ + (pStmt)->seqId++; \ + (pStmt)->seqIds[n]++; \ + STMT_DLOG("the %dth:%d %s", (pStmt)->seqIds[n], (pStmt)->seqId, gStmtStatusStr[n]); \ + } while (0) + #define STMT_STATUS_NE(S) (pStmt->sql.status != STMT_##S) #define STMT_STATUS_EQ(S) (pStmt->sql.status == STMT_##S) @@ -128,7 +142,13 @@ typedef struct STscStmt { } \ } while (0) -TAOS_STMT *stmtInit(STscObj *taos); +#define STMT_ELOG(param, ...) qError("stmt:%p " param, pStmt, __VA_ARGS__) +#define STMT_DLOG(param, ...) qDebug("stmt:%p " param, pStmt, __VA_ARGS__) + +#define STMT_ELOG_E(param) qError("stmt:%p " param, pStmt) +#define STMT_DLOG_E(param) qDebug("stmt:%p " param, pStmt) + +TAOS_STMT *stmtInit(STscObj *taos, int64_t reqid); int stmtClose(TAOS_STMT *stmt); int stmtExec(TAOS_STMT *stmt); const char *stmtErrstr(TAOS_STMT *stmt); diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 0f6d394611504828e48766c9b471b02fb04b3916..bb25a595afa829e22c674c2bd8a17310922f7d2c 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -77,19 +77,19 @@ static void deregisterRequest(SRequestObj *pRequest) { pRequest->self, pTscObj->id, pRequest->requestId, duration / 1000.0, num, currentInst); if (QUERY_NODE_VNODE_MODIF_STMT == pRequest->stmtType) { -// tscPerf("insert duration %" PRId64 "us: syntax:%" PRId64 "us, ctg:%" PRId64 "us, semantic:%" PRId64 -// "us, exec:%" PRId64 "us", -// duration, pRequest->metric.syntaxEnd - pRequest->metric.syntaxStart, -// pRequest->metric.ctgEnd - pRequest->metric.ctgStart, pRequest->metric.semanticEnd - pRequest->metric.ctgEnd, -// pRequest->metric.execEnd - pRequest->metric.semanticEnd); + // tscPerf("insert duration %" PRId64 "us: syntax:%" PRId64 "us, ctg:%" PRId64 "us, semantic:%" PRId64 + // "us, exec:%" PRId64 "us", + // duration, pRequest->metric.syntaxEnd - pRequest->metric.syntaxStart, + // pRequest->metric.ctgEnd - pRequest->metric.ctgStart, pRequest->metric.semanticEnd - + // pRequest->metric.ctgEnd, pRequest->metric.execEnd - pRequest->metric.semanticEnd); atomic_add_fetch_64((int64_t *)&pActivity->insertElapsedTime, duration); } else if (QUERY_NODE_SELECT_STMT == pRequest->stmtType) { -// tscPerf("select duration %" PRId64 "us: syntax:%" PRId64 "us, ctg:%" PRId64 "us, semantic:%" PRId64 -// "us, planner:%" PRId64 "us, exec:%" PRId64 "us, reqId:0x%" PRIx64, -// duration, pRequest->metric.syntaxEnd - pRequest->metric.syntaxStart, -// pRequest->metric.ctgEnd - pRequest->metric.ctgStart, pRequest->metric.semanticEnd - pRequest->metric.ctgEnd, -// pRequest->metric.planEnd - pRequest->metric.semanticEnd, -// pRequest->metric.resultReady - pRequest->metric.planEnd, pRequest->requestId); + // tscPerf("select duration %" PRId64 "us: syntax:%" PRId64 "us, ctg:%" PRId64 "us, semantic:%" PRId64 + // "us, planner:%" PRId64 "us, exec:%" PRId64 "us, reqId:0x%" PRIx64, + // duration, pRequest->metric.syntaxEnd - pRequest->metric.syntaxStart, + // pRequest->metric.ctgEnd - pRequest->metric.ctgStart, pRequest->metric.semanticEnd - + // pRequest->metric.ctgEnd, pRequest->metric.planEnd - pRequest->metric.semanticEnd, + // pRequest->metric.resultReady - pRequest->metric.planEnd, pRequest->requestId); atomic_add_fetch_64((int64_t *)&pActivity->queryElapsedTime, duration); } @@ -271,7 +271,7 @@ STscObj *acquireTscObj(int64_t rid) { return (STscObj *)taosAcquireRef(clientCon int32_t releaseTscObj(int64_t rid) { return taosReleaseRef(clientConnRefPool, rid); } -void *createRequest(uint64_t connId, int32_t type) { +void *createRequest(uint64_t connId, int32_t type, int64_t reqid) { SRequestObj *pRequest = (SRequestObj *)taosMemoryCalloc(1, sizeof(SRequestObj)); if (NULL == pRequest) { terrno = TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -286,7 +286,7 @@ void *createRequest(uint64_t connId, int32_t type) { } pRequest->resType = RES_TYPE__QUERY; - pRequest->requestId = generateRequestId(); + pRequest->requestId = reqid == 0 ? generateRequestId() : reqid; pRequest->metric.start = taosGetTimestampUs(); pRequest->body.resInfo.convertUcs4 = true; // convert ucs4 by default diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 0c12d78c186e25217b77fb65a6db96151f8d1877..88d78235935cf77672f81016dab0e212854267c6 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -133,6 +133,12 @@ STscObj* taos_connect_internal(const char* ip, const char* user, const char* pas taosThreadMutexInit(&p->qnodeMutex, NULL); p->pTransporter = openTransporter(user, secretEncrypt, tsNumOfCores); p->pAppHbMgr = appHbMgrInit(p, key); + if (NULL == p->pAppHbMgr) { + destroyAppInst(p); + taosThreadMutexUnlock(&appInfo.mutex); + taosMemoryFreeClear(key); + return NULL; + } taosHashPut(appInfo.pInstMap, key, strlen(key), &p, POINTER_BYTES); p->instKey = key; key = NULL; @@ -148,8 +154,8 @@ STscObj* taos_connect_internal(const char* ip, const char* user, const char* pas } int32_t buildRequest(uint64_t connId, const char* sql, int sqlLen, void* param, bool validateSql, - SRequestObj** pRequest) { - *pRequest = createRequest(connId, TSDB_SQL_SELECT); + SRequestObj** pRequest, int64_t reqid) { + *pRequest = createRequest(connId, TSDB_SQL_SELECT, reqid); if (*pRequest == NULL) { tscError("failed to malloc sqlObj, %s", sql); return terrno; @@ -867,6 +873,10 @@ int32_t handleQueryExecRsp(SRequestObj* pRequest) { return code; } +static bool incompletaFileParsing(SNode* pStmt) { + return QUERY_NODE_VNODE_MODIF_STMT != nodeType(pStmt) ? false : ((SVnodeModifOpStmt*)pStmt)->fileProcessing; +} + // todo refacto the error code mgmt void schedulerExecCb(SExecResult* pResult, void* param, int32_t code) { SSqlCallbackWrapper* pWrapper = param; @@ -921,11 +931,10 @@ void schedulerExecCb(SExecResult* pResult, void* param, int32_t code) { pRequest->code = code1; } - if (pRequest->code == TSDB_CODE_SUCCESS && NULL != pWrapper->pParseCtx && pWrapper->pParseCtx->needMultiParse) { - code = continueInsertFromCsv(pWrapper, pRequest); - if (TSDB_CODE_SUCCESS == code) { - return; - } + if (pRequest->code == TSDB_CODE_SUCCESS && NULL != pRequest->pQuery && + incompletaFileParsing(pRequest->pQuery->pRoot)) { + continueInsertFromCsv(pWrapper, pRequest); + return; } destorySqlCallbackWrapper(pWrapper); @@ -1049,7 +1058,9 @@ static int32_t asyncExecSchQuery(SRequestObj* pRequest, SQuery* pQuery, SMetaDat } if (TSDB_CODE_SUCCESS == code && !pRequest->validateOnly) { SArray* pNodeList = NULL; - buildAsyncExecNodeList(pRequest, &pNodeList, pMnodeList, pResultMeta); + if (QUERY_NODE_VNODE_MODIF_STMT != nodeType(pQuery->pRoot)) { + buildAsyncExecNodeList(pRequest, &pNodeList, pMnodeList, pResultMeta); + } SRequestConnInfo conn = {.pTrans = getAppInfo(pRequest)->pTransporter, .requestId = pRequest->requestId, @@ -1224,7 +1235,7 @@ STscObj* taosConnectImpl(const char* user, const char* auth, const char* db, __t return pTscObj; } - SRequestObj* pRequest = createRequest(pTscObj->id, TDMT_MND_CONNECT); + SRequestObj* pRequest = createRequest(pTscObj->id, TDMT_MND_CONNECT, 0); if (pRequest == NULL) { destroyTscObj(pTscObj); return NULL; @@ -1266,7 +1277,9 @@ static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest) { pMsgSendInfo->requestObjRefId = pRequest->self; pMsgSendInfo->requestId = pRequest->requestId; pMsgSendInfo->fp = getMsgRspHandle(pMsgSendInfo->msgType); - pMsgSendInfo->param = pRequest; + pMsgSendInfo->param = taosMemoryCalloc(1, sizeof(pRequest->self)); + + *(int64_t*)pMsgSendInfo->param = pRequest->self; SConnectReq connectReq = {0}; STscObj* pObj = pRequest->pTscObj; @@ -2226,7 +2239,37 @@ void taosAsyncQueryImpl(uint64_t connId, const char* sql, __taos_async_fn_t fp, } SRequestObj* pRequest = NULL; - int32_t code = buildRequest(connId, sql, sqlLen, param, validateOnly, &pRequest); + int32_t code = buildRequest(connId, sql, sqlLen, param, validateOnly, &pRequest, 0); + if (code != TSDB_CODE_SUCCESS) { + terrno = code; + fp(param, NULL, terrno); + return; + } + + pRequest->body.queryFp = fp; + doAsyncQuery(pRequest, false); +} +void taosAsyncQueryImplWithReqid(uint64_t connId, const char* sql, __taos_async_fn_t fp, void* param, bool validateOnly, + int64_t reqid) { + if (sql == NULL || NULL == fp) { + terrno = TSDB_CODE_INVALID_PARA; + if (fp) { + fp(param, NULL, terrno); + } + + return; + } + + size_t sqlLen = strlen(sql); + if (sqlLen > (size_t)TSDB_MAX_ALLOWED_SQL_LEN) { + tscError("sql string exceeds max length:%d", TSDB_MAX_ALLOWED_SQL_LEN); + terrno = TSDB_CODE_TSC_EXCEED_SQL_LIMIT; + fp(param, NULL, terrno); + return; + } + + SRequestObj* pRequest = NULL; + int32_t code = buildRequest(connId, sql, sqlLen, param, validateOnly, &pRequest, reqid); if (code != TSDB_CODE_SUCCESS) { terrno = code; fp(param, NULL, terrno); @@ -2253,3 +2296,20 @@ TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly) { } return param->pRequest; } + +TAOS_RES* taosQueryImplWithReqid(TAOS* taos, const char* sql, bool validateOnly, int64_t reqid) { + if (NULL == taos) { + terrno = TSDB_CODE_TSC_DISCONNECTED; + return NULL; + } + + SSyncQueryParam* param = taosMemoryCalloc(1, sizeof(SSyncQueryParam)); + tsem_init(¶m->sem, 0, 0); + + taosAsyncQueryImplWithReqid(*(int64_t*)taos, sql, syncQueryFn, param, validateOnly, reqid); + tsem_wait(¶m->sem); + if (param->pRequest != NULL) { + param->pRequest->syncQuery = true; + } + return param->pRequest; +} diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index b03576ff01b06f946f5f99a8fcc7eba6bb34aeee..efa7d095c519d3e56ff3f7766a89995987e95f27 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -248,6 +248,9 @@ TAOS_FIELD *taos_fetch_fields(TAOS_RES *res) { } TAOS_RES *taos_query(TAOS *taos, const char *sql) { return taosQueryImpl(taos, sql, false); } +TAOS_RES *taos_query_with_reqid(TAOS *taos, const char *sql, int64_t reqid) { + return taosQueryImplWithReqid(taos, sql, false, reqid); +} TAOS_ROW taos_fetch_row(TAOS_RES *res) { if (res == NULL) { @@ -286,7 +289,8 @@ TAOS_ROW taos_fetch_row(TAOS_RES *res) { return NULL; } else { // assert to avoid un-initialization error - ASSERT(0); + tscError("invalid result passed to taos_fetch_row"); + return NULL; } return NULL; } @@ -682,11 +686,10 @@ void destorySqlCallbackWrapper(SSqlCallbackWrapper *pWrapper) { } destoryCatalogReq(pWrapper->pCatalogReq); qDestroyParseContext(pWrapper->pParseCtx); - catalogFreeMetaData(pWrapper->pResultMeta); taosMemoryFree(pWrapper); } -void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) { +static void doAsyncQueryFromAnalyse(SMetaData *pResultMeta, void *param, int32_t code) { SSqlCallbackWrapper *pWrapper = (SSqlCallbackWrapper *)param; SRequestObj *pRequest = pWrapper->pRequest; SQuery *pQuery = pRequest->pQuery; @@ -704,13 +707,6 @@ void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) { pRequest->metric.semanticEnd = taosGetTimestampUs(); - if (code == TSDB_CODE_SUCCESS && pWrapper->pParseCtx->needMultiParse) { - pWrapper->pResultMeta = catalogCloneMetaData(pResultMeta); - if (NULL == pWrapper->pResultMeta) { - code = TSDB_CODE_OUT_OF_MEMORY; - } - } - if (code == TSDB_CODE_SUCCESS) { if (pQuery->haveResultSet) { setResSchemaInfo(&pRequest->body.resInfo, pQuery->pResSchema, pQuery->numOfResCols); @@ -747,14 +743,83 @@ void retrieveMetaCallback(SMetaData *pResultMeta, void *param, int32_t code) { } } -int32_t continueInsertFromCsv(SSqlCallbackWrapper *pWrapper, SRequestObj *pRequest) { - qDestroyQuery(pRequest->pQuery); - pRequest->pQuery = (SQuery *)nodesMakeNode(QUERY_NODE_QUERY); - if (NULL == pRequest->pQuery) { - return TSDB_CODE_OUT_OF_MEMORY; +static int32_t getAllMetaAsync(SSqlCallbackWrapper *pWrapper, catalogCallback fp) { + SRequestConnInfo conn = {.pTrans = pWrapper->pParseCtx->pTransporter, + .requestId = pWrapper->pParseCtx->requestId, + .requestObjRefId = pWrapper->pParseCtx->requestRid, + .mgmtEps = pWrapper->pParseCtx->mgmtEpSet}; + + pWrapper->pRequest->metric.ctgStart = taosGetTimestampUs(); + + return catalogAsyncGetAllMeta(pWrapper->pParseCtx->pCatalog, &conn, pWrapper->pCatalogReq, fp, pWrapper, + &pWrapper->pRequest->body.queryJob); +} + +static void doAsyncQueryFromParse(SMetaData *pResultMeta, void *param, int32_t code); + +static int32_t phaseAsyncQuery(SSqlCallbackWrapper *pWrapper) { + int32_t code = TSDB_CODE_SUCCESS; + switch (pWrapper->pRequest->pQuery->execStage) { + case QUERY_EXEC_STAGE_PARSE: { + // continue parse after get metadata + code = getAllMetaAsync(pWrapper, doAsyncQueryFromParse); + break; + } + case QUERY_EXEC_STAGE_ANALYSE: { + // analysis after get metadata + code = getAllMetaAsync(pWrapper, doAsyncQueryFromAnalyse); + break; + } + case QUERY_EXEC_STAGE_SCHEDULE: { + launchAsyncQuery(pWrapper->pRequest, pWrapper->pRequest->pQuery, NULL, pWrapper); + break; + } + default: + break; + } + return code; +} + +static void doAsyncQueryFromParse(SMetaData *pResultMeta, void *param, int32_t code) { + SSqlCallbackWrapper *pWrapper = (SSqlCallbackWrapper *)param; + SRequestObj *pRequest = pWrapper->pRequest; + SQuery *pQuery = pRequest->pQuery; + + pRequest->metric.ctgEnd = taosGetTimestampUs(); + qDebug("0x%" PRIx64 " start to continue parse, reqId:0x%" PRIx64, pRequest->self, pRequest->requestId); + + if (code == TSDB_CODE_SUCCESS) { + code = qContinueParseSql(pWrapper->pParseCtx, pWrapper->pCatalogReq, pResultMeta, pQuery); + } + + if (TSDB_CODE_SUCCESS == code) { + code = phaseAsyncQuery(pWrapper); + } + + if (TSDB_CODE_SUCCESS != code) { + tscError("0x%" PRIx64 " error happens, code:%d - %s, reqId:0x%" PRIx64, pWrapper->pRequest->self, code, + tstrerror(code), pWrapper->pRequest->requestId); + destorySqlCallbackWrapper(pWrapper); + terrno = code; + pRequest->code = code; + pRequest->body.queryFp(pRequest->body.param, pRequest, code); + } +} + +void continueInsertFromCsv(SSqlCallbackWrapper *pWrapper, SRequestObj *pRequest) { + int32_t code = qParseSqlSyntax(pWrapper->pParseCtx, &pRequest->pQuery, pWrapper->pCatalogReq); + if (TSDB_CODE_SUCCESS == code) { + code = phaseAsyncQuery(pWrapper); + } + + if (TSDB_CODE_SUCCESS != code) { + tscError("0x%" PRIx64 " error happens, code:%d - %s, reqId:0x%" PRIx64, pWrapper->pRequest->self, code, + tstrerror(code), pWrapper->pRequest->requestId); + destorySqlCallbackWrapper(pWrapper); + terrno = code; + pWrapper->pRequest->code = code; + pWrapper->pRequest->body.queryFp(pWrapper->pRequest->body.param, pWrapper->pRequest, code); } - retrieveMetaCallback(pWrapper->pResultMeta, pWrapper, TSDB_CODE_SUCCESS); - return TSDB_CODE_SUCCESS; } void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param) { @@ -762,6 +827,11 @@ void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param taosAsyncQueryImpl(connId, sql, fp, param, false); } +void taos_query_a_with_reqid(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param, int64_t reqid) { + int64_t connId = *(int64_t *)taos; + taosAsyncQueryImplWithReqid(connId, sql, fp, param, false, reqid); +} + int32_t createParseContext(const SRequestObj *pRequest, SParseContext **pCxt) { const STscObj *pTscObj = pRequest->pTscObj; @@ -836,26 +906,16 @@ void doAsyncQuery(SRequestObj *pRequest, bool updateMetaForce) { if (TSDB_CODE_SUCCESS == code && !updateMetaForce) { SAppClusterSummary *pActivity = &pTscObj->pAppInfo->summary; - if (NULL == pRequest->pQuery->pRoot) { + if (QUERY_NODE_INSERT_STMT == nodeType(pRequest->pQuery->pRoot)) { atomic_add_fetch_64((int64_t *)&pActivity->numOfInsertsReq, 1); - } else if (QUERY_NODE_SELECT_STMT == pRequest->pQuery->pRoot->type) { + } else if (QUERY_NODE_SELECT_STMT == nodeType(pRequest->pQuery->pRoot)) { atomic_add_fetch_64((int64_t *)&pActivity->numOfQueryReq, 1); } } if (TSDB_CODE_SUCCESS == code) { - SRequestConnInfo conn = {.pTrans = pWrapper->pParseCtx->pTransporter, - .requestId = pWrapper->pParseCtx->requestId, - .requestObjRefId = pWrapper->pParseCtx->requestRid, - .mgmtEps = pWrapper->pParseCtx->mgmtEpSet}; - - pRequest->metric.ctgStart = taosGetTimestampUs(); - - code = catalogAsyncGetAllMeta(pWrapper->pParseCtx->pCatalog, &conn, pWrapper->pCatalogReq, retrieveMetaCallback, - pWrapper, &pRequest->body.queryJob); - } - - if (TSDB_CODE_SUCCESS != code) { + phaseAsyncQuery(pWrapper); + } else { tscError("0x%" PRIx64 " error happens, code:%d - %s, reqId:0x%" PRIx64, pRequest->self, code, tstrerror(code), pRequest->requestId); destorySqlCallbackWrapper(pWrapper); @@ -930,7 +990,7 @@ void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) { // all data has returned to App already, no need to try again if (pResultInfo->completed) { // it is a local executed query, no need to do async fetch - if (QUERY_EXEC_MODE_LOCAL == pRequest->body.execMode) { + if (QUERY_EXEC_MODE_SCHEDULE != pRequest->body.execMode) { if (pResultInfo->localResultFetched) { pResultInfo->numOfRows = 0; pResultInfo->current = 0; @@ -991,7 +1051,7 @@ int taos_get_db_route_info(TAOS *taos, const char *db, TAOS_DB_ROUTE_INFO *dbInf int64_t connId = *(int64_t *)taos; SRequestObj *pRequest = NULL; char *sql = "taos_get_db_route_info"; - int32_t code = buildRequest(connId, sql, strlen(sql), NULL, false, &pRequest); + int32_t code = buildRequest(connId, sql, strlen(sql), NULL, false, &pRequest, 0); if (code != TSDB_CODE_SUCCESS) { terrno = code; return terrno; @@ -1040,7 +1100,7 @@ int taos_get_table_vgId(TAOS *taos, const char *db, const char *table, int *vgId int64_t connId = *(int64_t *)taos; SRequestObj *pRequest = NULL; char *sql = "taos_get_table_vgId"; - int32_t code = buildRequest(connId, sql, strlen(sql), NULL, false, &pRequest); + int32_t code = buildRequest(connId, sql, strlen(sql), NULL, false, &pRequest, 0); if (code != TSDB_CODE_SUCCESS) { return terrno; } @@ -1101,7 +1161,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { } char *sql = "taos_load_table_info"; - code = buildRequest(connId, sql, strlen(sql), NULL, false, &pRequest); + code = buildRequest(connId, sql, strlen(sql), NULL, false, &pRequest, 0); if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; @@ -1146,7 +1206,22 @@ TAOS_STMT *taos_stmt_init(TAOS *taos) { return NULL; } - TAOS_STMT *pStmt = stmtInit(pObj); + TAOS_STMT *pStmt = stmtInit(pObj, 0); + + releaseTscObj(*(int64_t *)taos); + + return pStmt; +} + +TAOS_STMT *taos_stmt_init_with_reqid(TAOS *taos, int64_t reqid) { + STscObj *pObj = acquireTscObj(*(int64_t *)taos); + if (NULL == pObj) { + tscError("invalid parameter for %s", __FUNCTION__); + terrno = TSDB_CODE_TSC_DISCONNECTED; + return NULL; + } + + TAOS_STMT *pStmt = stmtInit(pObj, reqid); releaseTscObj(*(int64_t *)taos); diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index e586018c190765bdf632cae272dc111eba2a7b7e..591d469d7c28308c0e41ca204a4548dd498a9b1f 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -45,8 +45,13 @@ int32_t genericRspCallback(void* param, SDataBuf* pMsg, int32_t code) { } int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { - SRequestObj* pRequest = param; - + SRequestObj *pRequest = acquireRequest(*(int64_t*)param); + if (NULL == pRequest) { + setErrno(pRequest, TSDB_CODE_TSC_DISCONNECTED); + tsem_post(&pRequest->body.rspSem); + goto End; + } + if (code != TSDB_CODE_SUCCESS) { setErrno(pRequest, code); tsem_post(&pRequest->body.rspSem); @@ -55,6 +60,12 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { STscObj* pTscObj = pRequest->pTscObj; + if (NULL == pTscObj->pAppInfo || NULL == pTscObj->pAppInfo->pAppHbMgr) { + setErrno(pRequest, TSDB_CODE_TSC_DISCONNECTED); + tsem_post(&pRequest->body.rspSem); + goto End; + } + SConnectRsp connectRsp = {0}; if (tDeserializeSConnectRsp(pMsg->pData, pMsg->len, &connectRsp) != 0) { code = TSDB_CODE_TSC_INVALID_VERSION; @@ -115,10 +126,15 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { tscDebug("0x%" PRIx64 " clusterId:%" PRId64 ", totalConn:%" PRId64, pRequest->requestId, connectRsp.clusterId, pTscObj->pAppInfo->numOfConns); - + tsem_post(&pRequest->body.rspSem); End: + if (pRequest) { + releaseRequest(pRequest->self); + } + + taosMemoryFree(param); taosMemoryFree(pMsg->pEpSet); taosMemoryFree(pMsg->pData); return code; @@ -159,7 +175,8 @@ int32_t processCreateDbRsp(void* param, SDataBuf* pMsg, int32_t code) { int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { SRequestObj* pRequest = param; - if (TSDB_CODE_MND_DB_NOT_EXIST == code) { + if (TSDB_CODE_MND_DB_NOT_EXIST == code || TSDB_CODE_MND_DB_IN_CREATING == code || + TSDB_CODE_MND_DB_IN_DROPPING == code) { SUseDbRsp usedbRsp = {0}; tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); struct SCatalog* pCatalog = NULL; @@ -196,7 +213,20 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) { tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp); if (strlen(usedbRsp.db) == 0) { - return TSDB_CODE_MND_DB_NOT_EXIST; + if (usedbRsp.errCode != 0) { + return usedbRsp.errCode; + } else { + return TSDB_CODE_APP_ERROR; + } + } + + tscTrace("db:%s, usedbRsp received, numOfVgroups:%d", usedbRsp.db, usedbRsp.vgNum); + for (int32_t i = 0; i < usedbRsp.vgNum; ++i) { + SVgroupInfo* pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i); + tscTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse); + for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) { + tscTrace("vgId:%d, index:%d epset:%s:%u", pInfo->vgId, j, pInfo->epSet.eps[j].fqdn, pInfo->epSet.eps[j].port); + } } SName name = {0}; @@ -412,8 +442,7 @@ static int32_t buildShowVariablesRsp(SArray* pVars, SRetrieveTableRsp** pRsp) { (*pRsp)->numOfRows = htonl(pBlock->info.rows); (*pRsp)->numOfCols = htonl(SHOW_VARIABLES_RESULT_COLS); - int32_t len = 0; - blockEncode(pBlock, (*pRsp)->data, &len, SHOW_VARIABLES_RESULT_COLS, false); + int32_t len = blockEncode(pBlock, (*pRsp)->data, SHOW_VARIABLES_RESULT_COLS); ASSERT(len == rspSize - sizeof(SRetrieveTableRsp)); blockDataDestroy(pBlock); diff --git a/source/client/src/clientRawBlockWrite.c b/source/client/src/clientRawBlockWrite.c index f05d37765d6ac2ecb9eaa28af791190c51a0c1fe..90a2adb64743585070a4f5a2e5414c1d45648bf2 100644 --- a/source/client/src/clientRawBlockWrite.c +++ b/source/client/src/clientRawBlockWrite.c @@ -410,7 +410,7 @@ static char* processAlterTable(SMqMetaRsp* metaRsp) { SDecoder decoder = {0}; SVAlterTbReq vAlterTbReq = {0}; char* string = NULL; - cJSON* json = NULL; + cJSON* json = NULL; // decode void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead)); @@ -525,7 +525,7 @@ static char* processDropSTable(SMqMetaRsp* metaRsp) { SDecoder decoder = {0}; SVDropStbReq req = {0}; char* string = NULL; - cJSON* json = NULL; + cJSON* json = NULL; // decode void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead)); @@ -558,7 +558,7 @@ static char* processDropTable(SMqMetaRsp* metaRsp) { SDecoder decoder = {0}; SVDropTbBatchReq req = {0}; char* string = NULL; - cJSON* json = NULL; + cJSON* json = NULL; // decode void* data = POINTER_SHIFT(metaRsp->metaRsp, sizeof(SMsgHead)); @@ -603,7 +603,7 @@ static int32_t taosCreateStb(TAOS* taos, void* meta, int32_t metaLen) { int32_t code = TSDB_CODE_SUCCESS; SRequestObj* pRequest = NULL; - code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest); + code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest, 0); if (code != TSDB_CODE_SUCCESS) { goto end; } @@ -692,7 +692,7 @@ static int32_t taosDropStb(TAOS* taos, void* meta, int32_t metaLen) { int32_t code = TSDB_CODE_SUCCESS; SRequestObj* pRequest = NULL; - code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest); + code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest, 0); if (code != TSDB_CODE_SUCCESS) { goto end; } @@ -773,7 +773,7 @@ static int32_t taosCreateTable(TAOS* taos, void* meta, int32_t metaLen) { SQuery* pQuery = NULL; SHashObj* pVgroupHashmap = NULL; - code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest); + code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest, 0); if (code != TSDB_CODE_SUCCESS) { goto end; } @@ -926,7 +926,7 @@ static int32_t taosDropTable(TAOS* taos, void* meta, int32_t metaLen) { SQuery* pQuery = NULL; SHashObj* pVgroupHashmap = NULL; - code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest); + code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest, 0); if (code != TSDB_CODE_SUCCESS) { goto end; } @@ -1097,7 +1097,7 @@ static int32_t taosAlterTable(TAOS* taos, void* meta, int32_t metaLen) { SArray* pArray = NULL; SVgDataBlocks* pVgData = NULL; - code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest); + code = buildRequest(*(int64_t*)taos, "", 0, NULL, false, &pRequest, 0); if (code != TSDB_CODE_SUCCESS) { goto end; @@ -1181,7 +1181,7 @@ static int32_t taosAlterTable(TAOS* taos, void* meta, int32_t metaLen) { pVgData = NULL; pArray = NULL; code = pRequest->code; - if (code == TSDB_CODE_VND_TABLE_NOT_EXIST) { + if (code == TSDB_CODE_TDB_TABLE_NOT_EXIST) { code = TSDB_CODE_SUCCESS; } @@ -1217,7 +1217,7 @@ int taos_write_raw_block(TAOS* taos, int rows, char* pData, const char* tbname) SQuery* pQuery = NULL; SSubmitReq* subReq = NULL; - SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT); + SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, 0); if (!pRequest) { uError("WriteRaw:createRequest error request is null"); code = terrno; @@ -1281,7 +1281,7 @@ int taos_write_raw_block(TAOS* taos, int rows, char* pData, const char* tbname) int32_t schemaLen = 0; int32_t submitLen = sizeof(SSubmitBlk) + schemaLen + rows * extendedRowSize; - int32_t totalLen = sizeof(SSubmitReq) + submitLen; + int32_t totalLen = sizeof(SSubmitReq) + submitLen; subReq = taosMemoryCalloc(1, totalLen); SSubmitBlk* blk = POINTER_SHIFT(subReq, sizeof(SSubmitReq)); void* blkSchema = POINTER_SHIFT(blk, sizeof(SSubmitBlk)); @@ -1407,7 +1407,7 @@ static int32_t tmqWriteRawDataImpl(TAOS* taos, void* data, int32_t dataLen) { STableMeta* pTableMeta = NULL; terrno = TSDB_CODE_SUCCESS; - SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT); + SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, 0); if (!pRequest) { uError("WriteRaw:createRequest error request is null"); return terrno; @@ -1674,7 +1674,7 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen) STableMeta* pTableMeta = NULL; terrno = TSDB_CODE_SUCCESS; - SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT); + SRequestObj* pRequest = (SRequestObj*)createRequest(*(int64_t*)taos, TSDB_SQL_INSERT, 0); if (!pRequest) { uError("WriteRaw:createRequest error request is null"); return terrno; diff --git a/source/client/src/clientSml.c b/source/client/src/clientSml.c index 5da7bebf2a87902c55f31b0eb9a3b4eef5dce84d..d1aeaac5875da6e781c731ab8098180f5b52210e 100644 --- a/source/client/src/clientSml.c +++ b/source/client/src/clientSml.c @@ -28,12 +28,12 @@ #define QUOTE '"' #define SLASH '\\' -#define JUMP_SPACE(sql, sqlEnd) \ - while (sql < sqlEnd) { \ - if (*sql == SPACE) \ - sql++; \ - else \ - break; \ +#define JUMP_SPACE(sql, sqlEnd) \ + while (sql < sqlEnd) { \ + if (*sql == SPACE) \ + sql++; \ + else \ + break; \ } // comma , #define IS_SLASH_COMMA(sql) (*(sql) == COMMA && *((sql)-1) == SLASH) @@ -353,7 +353,7 @@ static int32_t smlSendMetaMsg(SSmlHandle *info, SName *pName, SArray *pColumns, pReq.numOfTags = taosArrayGetSize(pTags); pReq.pTags = pTags; - code = buildRequest(info->taos->id, "", 0, NULL, false, &pRequest); + code = buildRequest(info->taos->id, "", 0, NULL, false, &pRequest, 0); if (code != TSDB_CODE_SUCCESS) { goto end; } @@ -1010,9 +1010,9 @@ static void smlParseTelnetElement(const char **sql, const char *sqlEnd, const ch } } -static int32_t smlParseTelnetTags(const char *data, const char *sqlEnd, SArray *cols, char *childTableName, SHashObj *dumplicateKey, - SSmlMsgBuf *msg) { - if(!cols) return TSDB_CODE_OUT_OF_MEMORY; +static int32_t smlParseTelnetTags(const char *data, const char *sqlEnd, SArray *cols, char *childTableName, + SHashObj *dumplicateKey, SSmlMsgBuf *msg) { + if (!cols) return TSDB_CODE_OUT_OF_MEMORY; const char *sql = data; size_t childTableNameLen = strlen(tsSmlChildTableName); while (sql < sqlEnd) { @@ -1093,7 +1093,8 @@ static int32_t smlParseTelnetTags(const char *data, const char *sqlEnd, SArray * } // format: =[ =] -static int32_t smlParseTelnetString(SSmlHandle *info, const char *sql, const char *sqlEnd, SSmlTableInfo *tinfo, SArray *cols) { +static int32_t smlParseTelnetString(SSmlHandle *info, const char *sql, const char *sqlEnd, SSmlTableInfo *tinfo, + SArray *cols) { if (!sql) return TSDB_CODE_SML_INVALID_DATA; // parse metric @@ -1372,19 +1373,19 @@ static int32_t smlKvTimeArrayCompare(const void *key1, const void *key2) { static int32_t smlKvTimeHashCompare(const void *key1, const void *key2) { SHashObj *s1 = *(SHashObj **)key1; SHashObj *s2 = *(SHashObj **)key2; - SSmlKv **kv1pp = (SSmlKv **)taosHashGet(s1, TS, TS_LEN); - SSmlKv **kv2pp = (SSmlKv **)taosHashGet(s2, TS, TS_LEN); - if(!kv1pp || !kv2pp){ + SSmlKv **kv1pp = (SSmlKv **)taosHashGet(s1, TS, TS_LEN); + SSmlKv **kv2pp = (SSmlKv **)taosHashGet(s2, TS, TS_LEN); + if (!kv1pp || !kv2pp) { uError("smlKvTimeHashCompare kv is null"); return -1; } - SSmlKv *kv1 = *kv1pp; - SSmlKv *kv2 = *kv2pp; - if(!kv1 || kv1->type != TSDB_DATA_TYPE_TIMESTAMP){ + SSmlKv *kv1 = *kv1pp; + SSmlKv *kv2 = *kv2pp; + if (!kv1 || kv1->type != TSDB_DATA_TYPE_TIMESTAMP) { uError("smlKvTimeHashCompare kv1"); return -1; } - if(!kv2 || kv2->type != TSDB_DATA_TYPE_TIMESTAMP){ + if (!kv2 || kv2->type != TSDB_DATA_TYPE_TIMESTAMP) { uError("smlKvTimeHashCompare kv2"); return -1; } @@ -1947,7 +1948,7 @@ static int32_t smlParseValueFromJSON(cJSON *root, SSmlKv *kv) { } static int32_t smlParseColsFromJSON(cJSON *root, SArray *cols) { - if(!cols) return TSDB_CODE_OUT_OF_MEMORY; + if (!cols) return TSDB_CODE_OUT_OF_MEMORY; cJSON *metricVal = cJSON_GetObjectItem(root, "value"); if (metricVal == NULL) { return TSDB_CODE_TSC_INVALID_JSON; @@ -1971,7 +1972,7 @@ static int32_t smlParseColsFromJSON(cJSON *root, SArray *cols) { static int32_t smlParseTagsFromJSON(cJSON *root, SArray *pKVs, char *childTableName, SHashObj *dumplicateKey, SSmlMsgBuf *msg) { int32_t ret = TSDB_CODE_SUCCESS; - if (!pKVs){ + if (!pKVs) { return TSDB_CODE_OUT_OF_MEMORY; } cJSON *tags = cJSON_GetObjectItem(root, "tags"); @@ -2204,7 +2205,7 @@ static int32_t smlParseTelnetLine(SSmlHandle *info, void *data, const int len) { } if (info->protocol == TSDB_SML_TELNET_PROTOCOL) { - ret = smlParseTelnetString(info, (const char *)data, (char*)data + len, tinfo, cols); + ret = smlParseTelnetString(info, (const char *)data, (char *)data + len, tinfo, cols); } else if (info->protocol == TSDB_SML_JSON_PROTOCOL) { ret = smlParseJSONString(info, (cJSON *)data, tinfo, cols); } else { @@ -2384,16 +2385,16 @@ static void smlPrintStatisticInfo(SSmlHandle *info) { info->cost.endTime - info->cost.insertRpcTime, info->cost.endTime - info->cost.parseTime); } -static int32_t smlParseLine(SSmlHandle *info, char *lines[], char* rawLine, char* rawLineEnd, int numLines) { +static int32_t smlParseLine(SSmlHandle *info, char *lines[], char *rawLine, char *rawLineEnd, int numLines) { int32_t code = TSDB_CODE_SUCCESS; if (info->protocol == TSDB_SML_JSON_PROTOCOL) { - if(lines){ + if (lines) { code = smlParseJSON(info, *lines); - }else if(rawLine){ + } else if (rawLine) { code = smlParseJSON(info, rawLine); } if (code != TSDB_CODE_SUCCESS) { - uError("SML:0x%" PRIx64 " smlParseJSON failed:%s", info->id, lines?*lines:rawLine); + uError("SML:0x%" PRIx64 " smlParseJSON failed:%s", info->id, lines ? *lines : rawLine); return code; } return code; @@ -2401,19 +2402,19 @@ static int32_t smlParseLine(SSmlHandle *info, char *lines[], char* rawLine, char for (int32_t i = 0; i < numLines; ++i) { char *tmp = NULL; - int len = 0; - if(lines){ + int len = 0; + if (lines) { tmp = lines[i]; len = strlen(tmp); - }else if(rawLine){ + } else if (rawLine) { tmp = rawLine; - while(rawLine < rawLineEnd){ - if(*(rawLine++) == '\n'){ + while (rawLine < rawLineEnd) { + if (*(rawLine++) == '\n') { break; } len++; } - if(info->protocol == TSDB_SML_LINE_PROTOCOL && tmp[0] == '#'){ // this line is comment + if (info->protocol == TSDB_SML_LINE_PROTOCOL && tmp[0] == '#') { // this line is comment continue; } } @@ -2433,7 +2434,7 @@ static int32_t smlParseLine(SSmlHandle *info, char *lines[], char* rawLine, char return code; } -static int smlProcess(SSmlHandle *info, char *lines[], char* rawLine, char* rawLineEnd, int numLines) { +static int smlProcess(SSmlHandle *info, char *lines[], char *rawLine, char *rawLineEnd, int numLines) { int32_t code = TSDB_CODE_SUCCESS; int32_t retryNum = 0; @@ -2532,8 +2533,8 @@ static void smlInsertCallback(void *param, void *res, int32_t code) { smlDestroyInfo(info); } - -TAOS_RES *taos_schemaless_insert_inner(SRequestObj *request, char *lines[], char *rawLine, char *rawLineEnd, int numLines, int protocol, int precision) { +TAOS_RES *taos_schemaless_insert_inner(SRequestObj *request, char *lines[], char *rawLine, char *rawLineEnd, + int numLines, int protocol, int precision) { int batchs = 0; STscObj *pTscObj = request->pTscObj; @@ -2581,7 +2582,7 @@ TAOS_RES *taos_schemaless_insert_inner(SRequestObj *request, char *lines[], char batchs = ceil(((double)numLines) / LINE_BATCH); params.total = batchs; for (int i = 0; i < batchs; ++i) { - SRequestObj *req = (SRequestObj *)createRequest(pTscObj->id, TSDB_SQL_INSERT); + SRequestObj *req = (SRequestObj *)createRequest(pTscObj->id, TSDB_SQL_INSERT, 0); if (!req) { request->code = TSDB_CODE_OUT_OF_MEMORY; uError("SML:taos_schemaless_insert error request is null"); @@ -2608,16 +2609,16 @@ TAOS_RES *taos_schemaless_insert_inner(SRequestObj *request, char *lines[], char info->pRequest->body.queryFp = smlInsertCallback; info->pRequest->body.param = info; int32_t code = smlProcess(info, lines, rawLine, rawLineEnd, perBatch); - if(lines){ + if (lines) { lines += perBatch; } - if(rawLine){ + if (rawLine) { int num = 0; - while(rawLine < rawLineEnd){ - if(*(rawLine++) == '\n'){ + while (rawLine < rawLineEnd) { + if (*(rawLine++) == '\n') { num++; } - if(num == perBatch){ + if (num == perBatch) { break; } } @@ -2628,7 +2629,7 @@ TAOS_RES *taos_schemaless_insert_inner(SRequestObj *request, char *lines[], char } tsem_wait(¶ms.sem); - end: +end: taosThreadSpinDestroy(¶ms.lock); tsem_destroy(¶ms.sem); // ((STscObj *)taos)->schemalessType = 0; @@ -2653,9 +2654,7 @@ TAOS_RES *taos_schemaless_insert_inner(SRequestObj *request, char *lines[], char * 0 - influxDB line protocol * 1 - OpenTSDB telnet line protocol * 2 - OpenTSDB JSON format protocol - * @return return zero for successful insertion. Otherwise return none-zero error code of - * failure reason. - * + * @return TAOS_RES */ TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int protocol, int precision) { @@ -2664,7 +2663,30 @@ TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int pr return NULL; } - SRequestObj *request = (SRequestObj *)createRequest(*(int64_t *)taos, TSDB_SQL_INSERT); + SRequestObj *request = (SRequestObj *)createRequest(*(int64_t *)taos, TSDB_SQL_INSERT, 0); + if (!request) { + uError("SML:taos_schemaless_insert error request is null"); + return NULL; + } + + if (!lines) { + SSmlMsgBuf msg = {ERROR_MSG_BUF_DEFAULT_SIZE, request->msgBuf}; + request->code = TSDB_CODE_SML_INVALID_DATA; + smlBuildInvalidDataMsg(&msg, "lines is null", NULL); + return (TAOS_RES *)request; + } + + return taos_schemaless_insert_inner(request, lines, NULL, NULL, numLines, protocol, precision); +} + +TAOS_RES *taos_schemaless_insert_with_reqid(TAOS *taos, char *lines[], int numLines, int protocol, int precision, + int64_t reqid) { + if (NULL == taos) { + terrno = TSDB_CODE_TSC_DISCONNECTED; + return NULL; + } + + SRequestObj *request = (SRequestObj *)createRequest(*(int64_t *)taos, TSDB_SQL_INSERT, reqid); if (!request) { uError("SML:taos_schemaless_insert error request is null"); return NULL; @@ -2680,13 +2702,49 @@ TAOS_RES *taos_schemaless_insert(TAOS *taos, char *lines[], int numLines, int pr return taos_schemaless_insert_inner(request, lines, NULL, NULL, numLines, protocol, precision); } -TAOS_RES *taos_schemaless_insert_raw(TAOS* taos, char* lines, int len, int32_t *totalRows, int protocol, int precision){ +TAOS_RES *taos_schemaless_insert_raw(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol, + int precision) { + if (NULL == taos) { + terrno = TSDB_CODE_TSC_DISCONNECTED; + return NULL; + } + + SRequestObj *request = (SRequestObj *)createRequest(*(int64_t *)taos, TSDB_SQL_INSERT, 0); + if (!request) { + uError("SML:taos_schemaless_insert error request is null"); + return NULL; + } + + if (!lines || len <= 0) { + SSmlMsgBuf msg = {ERROR_MSG_BUF_DEFAULT_SIZE, request->msgBuf}; + request->code = TSDB_CODE_SML_INVALID_DATA; + smlBuildInvalidDataMsg(&msg, "lines is null", NULL); + return (TAOS_RES *)request; + } + + int numLines = 0; + *totalRows = 0; + char *tmp = lines; + for (int i = 0; i < len; i++) { + if (lines[i] == '\n' || i == len - 1) { + numLines++; + if (tmp[0] != '#' || protocol != TSDB_SML_LINE_PROTOCOL) { // ignore comment + (*totalRows)++; + } + tmp = lines + i + 1; + } + } + return taos_schemaless_insert_inner(request, NULL, lines, lines + len, numLines, protocol, precision); +} + +TAOS_RES *taos_schemaless_insert_raw_with_reqid(TAOS *taos, char *lines, int len, int32_t *totalRows, int protocol, + int precision, int64_t reqid) { if (NULL == taos) { terrno = TSDB_CODE_TSC_DISCONNECTED; return NULL; } - SRequestObj *request = (SRequestObj *)createRequest(*(int64_t *)taos, TSDB_SQL_INSERT); + SRequestObj *request = (SRequestObj *)createRequest(*(int64_t *)taos, TSDB_SQL_INSERT, reqid); if (!request) { uError("SML:taos_schemaless_insert error request is null"); return NULL; @@ -2702,10 +2760,10 @@ TAOS_RES *taos_schemaless_insert_raw(TAOS* taos, char* lines, int len, int32_t * int numLines = 0; *totalRows = 0; char *tmp = lines; - for(int i = 0; i < len; i++){ - if(lines[i] == '\n' || i == len - 1){ + for (int i = 0; i < len; i++) { + if (lines[i] == '\n' || i == len - 1) { numLines++; - if(tmp[0] != '#' || protocol != TSDB_SML_LINE_PROTOCOL){ //ignore comment + if (tmp[0] != '#' || protocol != TSDB_SML_LINE_PROTOCOL) { // ignore comment (*totalRows)++; } tmp = lines + i + 1; diff --git a/source/client/src/clientStmt.c b/source/client/src/clientStmt.c index 81d0d616c995bdb71ba73fff8387a1ea67bc7c8b..c5f49bce89d14dbd49361b964e7aabb7a6acc484 100644 --- a/source/client/src/clientStmt.c +++ b/source/client/src/clientStmt.c @@ -5,11 +5,18 @@ #include "clientStmt.h" +char* gStmtStatusStr[] = {"unknown", "init", "prepare", "settbname", "settags", + "fetchFields", "bind", "bindCol", "addBatch", "exec"}; + static int32_t stmtCreateRequest(STscStmt* pStmt) { int32_t code = 0; if (pStmt->exec.pRequest == NULL) { - code = buildRequest(pStmt->taos->id, pStmt->sql.sqlStr, pStmt->sql.sqlLen, NULL, false, &pStmt->exec.pRequest); + code = buildRequest(pStmt->taos->id, pStmt->sql.sqlStr, pStmt->sql.sqlLen, NULL, false, &pStmt->exec.pRequest, + pStmt->reqid); + if (pStmt->reqid != 0) { + pStmt->reqid++; + } if (TSDB_CODE_SUCCESS == code) { pStmt->exec.pRequest->syncQuery = true; } @@ -21,6 +28,10 @@ static int32_t stmtCreateRequest(STscStmt* pStmt) { int32_t stmtSwitchStatus(STscStmt* pStmt, STMT_STATUS newStatus) { int32_t code = 0; + if (newStatus >= STMT_INIT && newStatus < STMT_MAX) { + STMT_LOG_SEQ(newStatus); + } + switch (newStatus) { case STMT_PREPARE: break; @@ -201,10 +212,10 @@ int32_t stmtCacheBlock(STscStmt* pStmt) { } STableDataBlocks** pSrc = taosHashGet(pStmt->exec.pBlockHash, pStmt->bInfo.tbFName, strlen(pStmt->bInfo.tbFName)); - if(!pSrc){ + if (!pSrc) { return TSDB_CODE_OUT_OF_MEMORY; } - STableDataBlocks* pDst = NULL; + STableDataBlocks* pDst = NULL; STMT_ERR_RET(qCloneStmtDataBlock(&pDst, *pSrc)); @@ -507,7 +518,7 @@ int32_t stmtResetStmt(STscStmt* pStmt) { return TSDB_CODE_SUCCESS; } -TAOS_STMT* stmtInit(STscObj* taos) { +TAOS_STMT* stmtInit(STscObj* taos, int64_t reqid) { STscObj* pObj = (STscObj*)taos; STscStmt* pStmt = NULL; @@ -527,6 +538,11 @@ TAOS_STMT* stmtInit(STscObj* taos) { pStmt->taos = pObj; pStmt->bInfo.needParse = true; pStmt->sql.status = STMT_INIT; + pStmt->reqid = reqid; + + STMT_LOG_SEQ(STMT_INIT); + + tscDebug("stmt:%p initialized", pStmt); return pStmt; } @@ -534,7 +550,7 @@ TAOS_STMT* stmtInit(STscObj* taos) { int stmtPrepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { STscStmt* pStmt = (STscStmt*)stmt; - tscDebug("stmt start to prepare"); + STMT_DLOG_E("start to prepare"); if (pStmt->sql.status >= STMT_PREPARE) { STMT_ERR_RET(stmtResetStmt(pStmt)); @@ -555,7 +571,7 @@ int stmtPrepare(TAOS_STMT* stmt, const char* sql, unsigned long length) { int stmtSetTbName(TAOS_STMT* stmt, const char* tbName) { STscStmt* pStmt = (STscStmt*)stmt; - tscDebug("stmt start to set tbName: %s", tbName); + STMT_DLOG("start to set tbName: %s", tbName); STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTBNAME)); @@ -587,7 +603,7 @@ int stmtSetTbName(TAOS_STMT* stmt, const char* tbName) { int stmtSetTbTags(TAOS_STMT* stmt, TAOS_MULTI_BIND* tags) { STscStmt* pStmt = (STscStmt*)stmt; - tscDebug("stmt start to set tbTags"); + STMT_DLOG_E("start to set tbTags"); STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTAGS)); @@ -649,7 +665,7 @@ int stmtFetchColFields(STscStmt* pStmt, int32_t* fieldNum, TAOS_FIELD_E** fields int stmtBindBatch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int32_t colIdx) { STscStmt* pStmt = (STscStmt*)stmt; - tscDebug("start to bind stmt data, colIdx: %d", colIdx); + STMT_DLOG("start to bind stmt data, colIdx: %d", colIdx); STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_BIND)); @@ -743,7 +759,7 @@ int stmtBindBatch(TAOS_STMT* stmt, TAOS_MULTI_BIND* bind, int32_t colIdx) { int stmtAddBatch(TAOS_STMT* stmt) { STscStmt* pStmt = (STscStmt*)stmt; - tscDebug("stmt start to add batch"); + STMT_DLOG_E("start to add batch"); STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_ADD_BATCH)); @@ -756,8 +772,7 @@ int stmtUpdateTableUid(STscStmt* pStmt, SSubmitRsp* pRsp) { tscDebug("stmt start to update tbUid, blockNum: %d", pRsp->nBlocks); if (pRsp->nBlocks <= 0) { - tscError("invalid submit resp block number %d", pRsp->nBlocks); - STMT_ERR_RET(TSDB_CODE_TSC_APP_ERROR); + return TSDB_CODE_SUCCESS; } size_t keyLen = 0; @@ -810,7 +825,7 @@ int stmtExec(TAOS_STMT* stmt) { SSubmitRsp* pRsp = NULL; bool autoCreateTbl = pStmt->exec.autoCreateTbl; - tscDebug("stmt start to exec"); + STMT_DLOG_E("start to exec"); STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_EXECUTE)); @@ -885,6 +900,8 @@ int stmtAffectedRowsOnce(TAOS_STMT* stmt) { return ((STscStmt*)stmt)->exec.affec int stmtIsInsert(TAOS_STMT* stmt, int* insert) { STscStmt* pStmt = (STscStmt*)stmt; + STMT_DLOG_E("start is insert"); + if (pStmt->sql.type) { *insert = (STMT_TYPE_INSERT == pStmt->sql.type || STMT_TYPE_MULTI_INSERT == pStmt->sql.type); } else { @@ -897,6 +914,8 @@ int stmtIsInsert(TAOS_STMT* stmt, int* insert) { int stmtGetTagFields(TAOS_STMT* stmt, int* nums, TAOS_FIELD_E** fields) { STscStmt* pStmt = (STscStmt*)stmt; + STMT_DLOG_E("start to get tag fields"); + if (STMT_TYPE_QUERY == pStmt->sql.type) { STMT_RET(TSDB_CODE_TSC_STMT_API_ERROR); } @@ -927,6 +946,8 @@ int stmtGetTagFields(TAOS_STMT* stmt, int* nums, TAOS_FIELD_E** fields) { int stmtGetColFields(TAOS_STMT* stmt, int* nums, TAOS_FIELD_E** fields) { STscStmt* pStmt = (STscStmt*)stmt; + STMT_DLOG_E("start to get col fields"); + if (STMT_TYPE_QUERY == pStmt->sql.type) { STMT_RET(TSDB_CODE_TSC_STMT_API_ERROR); } @@ -957,6 +978,8 @@ int stmtGetColFields(TAOS_STMT* stmt, int* nums, TAOS_FIELD_E** fields) { int stmtGetParamNum(TAOS_STMT* stmt, int* nums) { STscStmt* pStmt = (STscStmt*)stmt; + STMT_DLOG_E("start to get param num"); + STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_FETCH_FIELDS)); if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && @@ -986,6 +1009,8 @@ int stmtGetParamNum(TAOS_STMT* stmt, int* nums) { int stmtGetParam(TAOS_STMT* stmt, int idx, int* type, int* bytes) { STscStmt* pStmt = (STscStmt*)stmt; + STMT_DLOG_E("start to get param"); + if (STMT_TYPE_QUERY == pStmt->sql.type) { STMT_RET(TSDB_CODE_TSC_STMT_API_ERROR); } @@ -1028,6 +1053,8 @@ int stmtGetParam(TAOS_STMT* stmt, int idx, int* type, int* bytes) { TAOS_RES* stmtUseResult(TAOS_STMT* stmt) { STscStmt* pStmt = (STscStmt*)stmt; + STMT_DLOG_E("start to use result"); + if (STMT_TYPE_QUERY != pStmt->sql.type) { tscError("useResult only for query statement"); return NULL; diff --git a/source/client/src/clientTmq.c b/source/client/src/clientTmq.c index c18e1e3e40ea891c05a245bb7638bbdf891bd80c..ab44236d96ad877988231bcbf15369c14df35855 100644 --- a/source/client/src/clientTmq.c +++ b/source/client/src/clientTmq.c @@ -508,7 +508,7 @@ static int32_t tmqSendCommitReq(tmq_t* tmq, SMqClientVg* pVg, SMqClientTopic* pT pMsgSendInfo->param = pParam; pMsgSendInfo->paramFreeFp = taosMemoryFree; pMsgSendInfo->fp = tmqCommitCb; - pMsgSendInfo->msgType = TDMT_VND_MQ_COMMIT_OFFSET; + pMsgSendInfo->msgType = TDMT_VND_TMQ_COMMIT_OFFSET; // send msg atomic_add_fetch_32(&pParamSet->waitingRspNum, 1); @@ -750,7 +750,7 @@ void tmqSendHbReq(void* param, void* tmrId) { sendInfo->requestObjRefId = 0; sendInfo->param = NULL; sendInfo->fp = tmqHbCb; - sendInfo->msgType = TDMT_MND_MQ_HB; + sendInfo->msgType = TDMT_MND_TMQ_HB; SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp); @@ -1038,7 +1038,7 @@ int32_t tmq_subscribe(tmq_t* tmq, const tmq_list_t* topic_list) { sendInfo->requestObjRefId = 0; sendInfo->param = ¶m; sendInfo->fp = tmqSubscribeCb; - sendInfo->msgType = TDMT_MND_SUBSCRIBE; + sendInfo->msgType = TDMT_MND_TMQ_SUBSCRIBE; SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp); @@ -1420,7 +1420,7 @@ int32_t tmqAskEp(tmq_t* tmq, bool async) { sendInfo->requestObjRefId = 0; sendInfo->param = pParam; sendInfo->fp = tmqAskEpCb; - sendInfo->msgType = TDMT_MND_MQ_ASK_EP; + sendInfo->msgType = TDMT_MND_TMQ_ASK_EP; SEpSet epSet = getEpSet_s(&tmq->pTscObj->pAppInfo->mgmtEp); @@ -1573,7 +1573,7 @@ int32_t tmqPollImpl(tmq_t* tmq, int64_t timeout) { sendInfo->requestObjRefId = 0; sendInfo->param = pParam; sendInfo->fp = tmqPollCb; - sendInfo->msgType = TDMT_VND_CONSUME; + sendInfo->msgType = TDMT_VND_TMQ_CONSUME; int64_t transporterId = 0; /*printf("send poll\n");*/ @@ -1649,7 +1649,7 @@ void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) { taosFreeQitem(pollRspWrapper); return pRsp; } else { - tscDebug("msg discard since epoch mismatch: msg epoch %d, consumer epoch %d\n", + tscDebug("msg discard since epoch mismatch: msg epoch %d, consumer epoch %d", pollRspWrapper->dataRsp.head.epoch, consumerEpoch); taosFreeQitem(pollRspWrapper); } @@ -1667,7 +1667,7 @@ void* tmqHandleAllRsp(tmq_t* tmq, int64_t timeout, bool pollIfReset) { taosFreeQitem(pollRspWrapper); return pRsp; } else { - tscDebug("msg discard since epoch mismatch: msg epoch %d, consumer epoch %d\n", + tscDebug("msg discard since epoch mismatch: msg epoch %d, consumer epoch %d", pollRspWrapper->metaRsp.head.epoch, consumerEpoch); taosFreeQitem(pollRspWrapper); } @@ -1756,7 +1756,7 @@ TAOS_RES* tmq_consumer_poll(tmq_t* tmq, int64_t timeout) { rspObj = tmqHandleAllRsp(tmq, timeout, false); if (rspObj) { - tscDebug("consumer:%" PRId64 ", return rsp", tmq->consumerId); + tscDebug("consumer:%" PRId64 ", return rsp %p", tmq->consumerId, rspObj); return (TAOS_RES*)rspObj; } else if (terrno == TSDB_CODE_TQ_NO_COMMITTED_OFFSET) { tscDebug("consumer:%" PRId64 ", return null since no committed offset", tmq->consumerId); diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 21a52a4b57f9e7ba9cda24e8f9a08fdb53545b1c..85814305bd9cce41efebec8bb997f207c8d1a847 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -112,7 +112,7 @@ void createNewTable(TAOS* pConn, int32_t index) { } taos_free_result(pRes); - for(int32_t i = 0; i < 10000; i += 20) { + for(int32_t i = 0; i < 20; i += 20) { char sql[1024] = {0}; sprintf(sql, "insert into tu%d values(now+%da, %d)(now+%da, %d)(now+%da, %d)(now+%da, %d)" @@ -692,6 +692,7 @@ TEST(testCase, insert_test) { taos_free_result(pRes); taos_close(pConn); } +#endif TEST(testCase, projection_query_tables) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); @@ -703,7 +704,7 @@ TEST(testCase, projection_query_tables) { // } // taos_free_result(pRes); - TAOS_RES* pRes = taos_query(pConn, "use benchmarkcpu"); + TAOS_RES* pRes = taos_query(pConn, "use abc2"); taos_free_result(pRes); pRes = taos_query(pConn, "create stable st1 (ts timestamp, k int) tags(a int)"); @@ -725,7 +726,7 @@ TEST(testCase, projection_query_tables) { } taos_free_result(pRes); - for (int32_t i = 0; i < 2; ++i) { + for (int32_t i = 0; i < 200000; ++i) { printf("create table :%d\n", i); createNewTable(pConn, i); } @@ -750,7 +751,9 @@ TEST(testCase, projection_query_tables) { taos_free_result(pRes); taos_close(pConn); } -#endif + + +#if 0 TEST(testCase, tsbs_perf_test) { TdThread qid[20] = {0}; @@ -761,7 +764,7 @@ TEST(testCase, tsbs_perf_test) { getchar(); } -#if 0 + TEST(testCase, projection_query_stables) { TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); ASSERT_NE(pConn, nullptr); diff --git a/source/common/src/systable.c b/source/common/src/systable.c index 24f71a47c09797f165e8a441a2c3179976663079..d3d006ab350bc102b05b70aa8ada6803ba309f50 100644 --- a/source/common/src/systable.c +++ b/source/common/src/systable.c @@ -270,7 +270,7 @@ static const SSysTableMeta infosMeta[] = { {TSDB_INS_TABLE_MNODES, mnodesSchema, tListLen(mnodesSchema), true}, {TSDB_INS_TABLE_MODULES, modulesSchema, tListLen(modulesSchema), true}, {TSDB_INS_TABLE_QNODES, qnodesSchema, tListLen(qnodesSchema), true}, - // {TSDB_INS_TABLE_SNODES, snodesSchema, tListLen(snodesSchema)}, + {TSDB_INS_TABLE_SNODES, snodesSchema, tListLen(snodesSchema)}, {TSDB_INS_TABLE_CLUSTER, clusterSchema, tListLen(clusterSchema), true}, {TSDB_INS_TABLE_DATABASES, userDBSchema, tListLen(userDBSchema), false}, {TSDB_INS_TABLE_FUNCTIONS, userFuncSchema, tListLen(userFuncSchema), false}, diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 0c38d43543db0df063381174528d886551ee8d8f..536cbed33e8353d704ef30096d2b2514d8e28632 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -246,7 +246,7 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, int32_t numOfRow1, int uint32_t finalNumOfRows = numOfRow1 + numOfRow2; if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) { // Handle the bitmap - if (finalNumOfRows > *capacity || (numOfRow1 == 0 && pColumnInfoData->info.bytes != 0)) { + if (finalNumOfRows > (*capacity)) { char* p = taosMemoryRealloc(pColumnInfoData->varmeta.offset, sizeof(int32_t) * (numOfRow1 + numOfRow2)); if (p == NULL) { return TSDB_CODE_OUT_OF_MEMORY; @@ -280,16 +280,14 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, int32_t numOfRow1, int memcpy(pColumnInfoData->pData + oldLen, pSource->pData, len); pColumnInfoData->varmeta.length = len + oldLen; } else { - if (finalNumOfRows > *capacity || (numOfRow1 == 0 && pColumnInfoData->info.bytes != 0)) { + if (finalNumOfRows > (*capacity)) { // all data may be null, when the pColumnInfoData->info.type == 0, bytes == 0; - // ASSERT(finalNumOfRows * pColumnInfoData->info.bytes); char* tmp = taosMemoryRealloc(pColumnInfoData->pData, finalNumOfRows * pColumnInfoData->info.bytes); if (tmp == NULL) { - return TSDB_CODE_VND_OUT_OF_MEMORY; + return TSDB_CODE_OUT_OF_MEMORY; } pColumnInfoData->pData = tmp; - if (BitmapLen(numOfRow1) < BitmapLen(finalNumOfRows)) { char* btmp = taosMemoryRealloc(pColumnInfoData->nullbitmap, BitmapLen(finalNumOfRows)); uint32_t extend = BitmapLen(finalNumOfRows) - BitmapLen(numOfRow1); @@ -823,7 +821,7 @@ static int32_t blockDataAssign(SColumnInfoData* pCols, const SSDataBlock* pDataB } static SColumnInfoData* createHelpColInfoData(const SSDataBlock* pDataBlock) { - int32_t rows = pDataBlock->info.rows; + int32_t rows = pDataBlock->info.capacity; size_t numOfCols = taosArrayGetSize(pDataBlock->pDataBlock); SColumnInfoData* pCols = taosMemoryCalloc(numOfCols, sizeof(SColumnInfoData)); @@ -1126,22 +1124,28 @@ int32_t blockDataSort_rv(SSDataBlock* pDataBlock, SArray* pOrderInfo, bool nullF } void blockDataCleanup(SSDataBlock* pDataBlock) { - pDataBlock->info.rows = 0; - pDataBlock->info.groupId = 0; + SDataBlockInfo* pInfo = &pDataBlock->info; - pDataBlock->info.window.ekey = 0; - pDataBlock->info.window.skey = 0; + pInfo->rows = 0; + pInfo->groupId = 0; + pInfo->window.ekey = 0; + pInfo->window.skey = 0; + + if (pInfo->capacity == 0) { + return; + } size_t numOfCols = taosArrayGetSize(pDataBlock->pDataBlock); for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* p = taosArrayGet(pDataBlock->pDataBlock, i); - colInfoDataCleanup(p, pDataBlock->info.capacity); + colInfoDataCleanup(p, pInfo->capacity); } } -static int32_t doEnsureCapacity(SColumnInfoData* pColumn, const SDataBlockInfo* pBlockInfo, uint32_t numOfRows) { - ASSERT(numOfRows > 0 && pBlockInfo->capacity >= pBlockInfo->rows); - if (numOfRows < pBlockInfo->capacity) { +// todo temporarily disable it +static int32_t doEnsureCapacity(SColumnInfoData* pColumn, const SDataBlockInfo* pBlockInfo, uint32_t numOfRows, bool clearPayload) { + ASSERT(numOfRows > 0 /*&& pBlockInfo->capacity >= pBlockInfo->rows*/); + if (numOfRows <= pBlockInfo->capacity) { return TSDB_CODE_SUCCESS; } @@ -1168,24 +1172,24 @@ static int32_t doEnsureCapacity(SColumnInfoData* pColumn, const SDataBlockInfo* pColumn->nullbitmap = tmp; memset(&pColumn->nullbitmap[oldLen], 0, BitmapLen(numOfRows) - oldLen); - if (pColumn->info.type == TSDB_DATA_TYPE_NULL) { - return TSDB_CODE_SUCCESS; - } - - assert(pColumn->info.bytes); + ASSERT(pColumn->info.bytes); tmp = taosMemoryRealloc(pColumn->pData, numOfRows * pColumn->info.bytes); if (tmp == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - memset(tmp + pColumn->info.bytes * existedRows, 0, pColumn->info.bytes * (numOfRows - existedRows)); pColumn->pData = tmp; + if (clearPayload) { + memset(tmp + pColumn->info.bytes * existedRows, 0, pColumn->info.bytes * (numOfRows - existedRows)); + } } return TSDB_CODE_SUCCESS; } void colInfoDataCleanup(SColumnInfoData* pColumn, uint32_t numOfRows) { + pColumn->hasNull = false; + if (IS_VAR_DATA_TYPE(pColumn->info.type)) { pColumn->varmeta.length = 0; if (pColumn->varmeta.offset != NULL) { @@ -1198,30 +1202,27 @@ void colInfoDataCleanup(SColumnInfoData* pColumn, uint32_t numOfRows) { } } -int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, uint32_t numOfRows) { +int32_t colInfoDataEnsureCapacity(SColumnInfoData* pColumn, uint32_t numOfRows, bool clearPayload) { SDataBlockInfo info = {0}; - return doEnsureCapacity(pColumn, &info, numOfRows); + return doEnsureCapacity(pColumn, &info, numOfRows, clearPayload); } int32_t blockDataEnsureCapacity(SSDataBlock* pDataBlock, uint32_t numOfRows) { int32_t code = 0; - if (numOfRows == 0) { + if (numOfRows == 0 || numOfRows <= pDataBlock->info.capacity) { return TSDB_CODE_SUCCESS; } - if (pDataBlock->info.capacity < numOfRows) { - pDataBlock->info.capacity = numOfRows; - } - size_t numOfCols = taosArrayGetSize(pDataBlock->pDataBlock); for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData* p = taosArrayGet(pDataBlock->pDataBlock, i); - code = doEnsureCapacity(p, &pDataBlock->info, numOfRows); + code = doEnsureCapacity(p, &pDataBlock->info, numOfRows, true); if (code) { return code; } } + pDataBlock->info.capacity = numOfRows; return TSDB_CODE_SUCCESS; } @@ -1908,6 +1909,22 @@ char* dumpBlockData(SSDataBlock* pDataBlock, const char* flag, char** pDataBuf) len += snprintf(dumpBuf + len, size - len, " %25s |", pBuf); if (len >= size - 1) return dumpBuf; break; + case TSDB_DATA_TYPE_TINYINT: + len += snprintf(dumpBuf + len, size - len, " %15d |", *(int8_t*)var); + if (len >= size - 1) return dumpBuf; + break; + case TSDB_DATA_TYPE_UTINYINT: + len += snprintf(dumpBuf + len, size - len, " %15d |", *(uint8_t*)var); + if (len >= size - 1) return dumpBuf; + break; + case TSDB_DATA_TYPE_SMALLINT: + len += snprintf(dumpBuf + len, size - len, " %15d |", *(int16_t*)var); + if (len >= size - 1) return dumpBuf; + break; + case TSDB_DATA_TYPE_USMALLINT: + len += snprintf(dumpBuf + len, size - len, " %15d |", *(uint16_t*)var); + if (len >= size - 1) return dumpBuf; + break; case TSDB_DATA_TYPE_INT: len += snprintf(dumpBuf + len, size - len, " %15d |", *(int32_t*)var); if (len >= size - 1) return dumpBuf; @@ -2063,8 +2080,8 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SSDataBlock* pDataB default: if (pColInfoData->info.type < TSDB_DATA_TYPE_MAX && pColInfoData->info.type > TSDB_DATA_TYPE_NULL) { if (colDataIsNull_s(pColInfoData, j)) { - tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pCol->type, TD_VTYPE_NULL, NULL, false, offset, - k); + tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pCol->type, TD_VTYPE_NULL, NULL, false, + offset, k); } else if (pCol->type == pColInfoData->info.type) { tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pCol->type, TD_VTYPE_NORM, var, true, offset, k); @@ -2137,10 +2154,26 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SSDataBlock* pDataB return TSDB_CODE_SUCCESS; } -char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId) { - ASSERT(stbName[0] != 0); +char* buildCtbNameByGroupId(const char* stbFullName, uint64_t groupId) { + ASSERT(stbFullName[0] != 0); SArray* tags = taosArrayInit(0, sizeof(void*)); + if (tags == NULL) { + return NULL; + } + SSmlKv* pTag = taosMemoryCalloc(1, sizeof(SSmlKv)); + if (pTag == NULL) { + taosArrayDestroy(tags); + return NULL; + } + + void* cname = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1); + if (cname == NULL) { + taosArrayDestroy(tags); + taosMemoryFree(pTag); + return NULL; + } + pTag->key = "group_id"; pTag->keyLen = strlen(pTag->key); pTag->type = TSDB_DATA_TYPE_UBIGINT; @@ -2148,13 +2181,11 @@ char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId) { pTag->length = sizeof(uint64_t); taosArrayPush(tags, &pTag); - void* cname = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN + 1); - RandTableName rname = { .tags = tags, - .sTableName = stbName, - .sTableNameLen = strlen(stbName), - .childTableName = cname, + .stbFullName = stbFullName, + .stbFullNameLen = strlen(stbFullName), + .ctbShortName = cname, }; buildChildTableName(&rname); @@ -2162,11 +2193,13 @@ char* buildCtbNameByGroupId(const char* stbName, uint64_t groupId) { taosMemoryFree(pTag); taosArrayDestroy(tags); - ASSERT(rname.childTableName && rname.childTableName[0]); - return rname.childTableName; + ASSERT(rname.ctbShortName && rname.ctbShortName[0]); + return rname.ctbShortName; } -void blockEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols, int8_t needCompress) { +int32_t blockEncode(const SSDataBlock* pBlock, char* data, int32_t numOfCols) { + int32_t dataLen = 0; + // todo extract method int32_t* version = (int32_t*)data; *version = 1; @@ -2207,7 +2240,7 @@ void blockEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_ int32_t* colSizes = (int32_t*)data; data += numOfCols * sizeof(int32_t); - *dataLen = blockDataGetSerialMetaSize(numOfCols); + dataLen = blockDataGetSerialMetaSize(numOfCols); int32_t numOfRows = pBlock->info.rows; for (int32_t col = 0; col < numOfCols; ++col) { @@ -2224,26 +2257,23 @@ void blockEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_ } data += metaSize; - (*dataLen) += metaSize; + dataLen += metaSize; - if (needCompress) { - colSizes[col] = blockCompressColData(pColRes, numOfRows, data, needCompress); - data += colSizes[col]; - (*dataLen) += colSizes[col]; - } else { - colSizes[col] = colDataGetLength(pColRes, numOfRows); - (*dataLen) += colSizes[col]; - memmove(data, pColRes->pData, colSizes[col]); - data += colSizes[col]; - } + colSizes[col] = colDataGetLength(pColRes, numOfRows); + dataLen += colSizes[col]; + memmove(data, pColRes->pData, colSizes[col]); + data += colSizes[col]; colSizes[col] = htonl(colSizes[col]); } - *actualLen = *dataLen; + *actualLen = dataLen; *groupId = pBlock->info.groupId; - ASSERT(*dataLen > 0); - uDebug("build data block, actualLen:%d, rows:%d, cols:%d", *dataLen, *rows, *cols); + ASSERT(dataLen > 0); + + uDebug("build data block, actualLen:%d, rows:%d, cols:%d", dataLen, *rows, *cols); + + return dataLen; } const char* blockDecode(SSDataBlock* pBlock, const char* pData) { diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 513c54c7e9a5a7fbc513cfe55e397e48f6018b9e..73b887342cf995a1aa564b1aa6f5bae55dac01e1 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -56,7 +56,7 @@ typedef struct { #define TSROW_IS_KV_ROW(r) ((r)->flags & TSROW_KV_ROW) // SValue -int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type) { +static FORCE_INLINE int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type) { if (IS_VAR_DATA_TYPE(type)) { return tPutBinary(p, pValue->pData, pValue->nData); } else { @@ -65,20 +65,6 @@ int32_t tPutValue(uint8_t *p, SValue *pValue, int8_t type) { } } -int32_t tGetValue(uint8_t *p, SValue *pValue, int8_t type) { - if (IS_VAR_DATA_TYPE(type)) { - return tGetBinary(p, &pValue->pData, pValue ? &pValue->nData : NULL); - } else { - memcpy(&pValue->val, p, tDataTypes[type].bytes); - return tDataTypes[type].bytes; - } -} - -int tValueCmprFn(const SValue *pValue1, const SValue *pValue2, int8_t type) { - // TODO - return 0; -} - // STSRow2 ======================================================================== static void setBitMap(uint8_t *pb, uint8_t v, int32_t idx, uint8_t flags) { if (pb) { @@ -923,7 +909,7 @@ char *tTagValToData(const STagVal *value, bool isJson) { } bool tTagGet(const STag *pTag, STagVal *pTagVal) { - if(!pTag || !pTagVal){ + if (!pTag || !pTagVal) { return false; } @@ -1164,31 +1150,27 @@ static FORCE_INLINE int32_t tColDataPutValue(SColData *pColData, SColVal *pColVa ASSERT(pColData->nData == tDataTypes[pColData->type].bytes * pColData->nVal); code = tRealloc(&pColData->pData, pColData->nData + tDataTypes[pColData->type].bytes); if (code) goto _exit; - pColData->nData += tPutValue(pColData->pData + pColData->nData, &pColVal->value, pColVal->type); + memcpy(pColData->pData + pColData->nData, &pColVal->value.val, tDataTypes[pColData->type].bytes); + pColData->nData += tDataTypes[pColData->type].bytes; } + pColData->nVal++; _exit: return code; } static FORCE_INLINE int32_t tColDataAppendValue00(SColData *pColData, SColVal *pColVal) { - int32_t code = 0; pColData->flag = HAS_VALUE; - code = tColDataPutValue(pColData, pColVal); - if (code) return code; - pColData->nVal++; - return code; + return tColDataPutValue(pColData, pColVal); } static FORCE_INLINE int32_t tColDataAppendValue01(SColData *pColData, SColVal *pColVal) { - int32_t code = 0; pColData->flag = HAS_NONE; pColData->nVal++; - return code; + return 0; } static FORCE_INLINE int32_t tColDataAppendValue02(SColData *pColData, SColVal *pColVal) { - int32_t code = 0; pColData->flag = HAS_NULL; pColData->nVal++; - return code; + return 0; } static FORCE_INLINE int32_t tColDataAppendValue10(SColData *pColData, SColVal *pColVal) { int32_t code = 0; @@ -1216,16 +1198,11 @@ static FORCE_INLINE int32_t tColDataAppendValue10(SColData *pColData, SColVal *p } } - code = tColDataPutValue(pColData, pColVal); - if (code) return code; - pColData->nVal++; - - return code; + return tColDataPutValue(pColData, pColVal); } static FORCE_INLINE int32_t tColDataAppendValue11(SColData *pColData, SColVal *pColVal) { - int32_t code = 0; pColData->nVal++; - return code; + return 0; } static FORCE_INLINE int32_t tColDataAppendValue12(SColData *pColData, SColVal *pColVal) { int32_t code = 0; @@ -1268,11 +1245,7 @@ static FORCE_INLINE int32_t tColDataAppendValue20(SColData *pColData, SColVal *p } } - code = tColDataPutValue(pColData, pColVal); - if (code) return code; - pColData->nVal++; - - return code; + return tColDataPutValue(pColData, pColVal); } static FORCE_INLINE int32_t tColDataAppendValue21(SColData *pColData, SColVal *pColVal) { int32_t code = 0; @@ -1290,9 +1263,8 @@ static FORCE_INLINE int32_t tColDataAppendValue21(SColData *pColData, SColVal *p return code; } static FORCE_INLINE int32_t tColDataAppendValue22(SColData *pColData, SColVal *pColVal) { - int32_t code = 0; pColData->nVal++; - return code; + return 0; } static FORCE_INLINE int32_t tColDataAppendValue30(SColData *pColData, SColVal *pColVal) { int32_t code = 0; @@ -1325,11 +1297,7 @@ static FORCE_INLINE int32_t tColDataAppendValue30(SColData *pColData, SColVal *p } } - code = tColDataPutValue(pColData, pColVal); - if (code) return code; - pColData->nVal++; - - return code; + return tColDataPutValue(pColData, pColVal); } static FORCE_INLINE int32_t tColDataAppendValue31(SColData *pColData, SColVal *pColVal) { int32_t code = 0; @@ -1353,15 +1321,7 @@ static FORCE_INLINE int32_t tColDataAppendValue32(SColData *pColData, SColVal *p return code; } -static FORCE_INLINE int32_t tColDataAppendValue40(SColData *pColData, SColVal *pColVal) { - int32_t code = 0; - - code = tColDataPutValue(pColData, pColVal); - if (code) return code; - pColData->nVal++; - - return code; -} +#define tColDataAppendValue40 tColDataPutValue static FORCE_INLINE int32_t tColDataAppendValue41(SColData *pColData, SColVal *pColVal) { int32_t code = 0; @@ -1374,12 +1334,7 @@ static FORCE_INLINE int32_t tColDataAppendValue41(SColData *pColData, SColVal *p memset(pColData->pBitMap, 255, nBit); SET_BIT1(pColData->pBitMap, pColData->nVal, 0); - code = tColDataPutValue(pColData, pColVal); - if (code) return code; - - pColData->nVal++; - - return code; + return tColDataPutValue(pColData, pColVal); } static FORCE_INLINE int32_t tColDataAppendValue42(SColData *pColData, SColVal *pColVal) { int32_t code = 0; @@ -1393,12 +1348,7 @@ static FORCE_INLINE int32_t tColDataAppendValue42(SColData *pColData, SColVal *p memset(pColData->pBitMap, 255, nBit); SET_BIT1(pColData->pBitMap, pColData->nVal, 0); - code = tColDataPutValue(pColData, pColVal); - if (code) return code; - - pColData->nVal++; - - return code; + return tColDataPutValue(pColData, pColVal); } static FORCE_INLINE int32_t tColDataAppendValue50(SColData *pColData, SColVal *pColVal) { int32_t code = 0; @@ -1408,12 +1358,7 @@ static FORCE_INLINE int32_t tColDataAppendValue50(SColData *pColData, SColVal *p SET_BIT1(pColData->pBitMap, pColData->nVal, 1); - code = tColDataPutValue(pColData, pColVal); - if (code) return code; - - pColData->nVal++; - - return code; + return tColDataPutValue(pColData, pColVal); } static FORCE_INLINE int32_t tColDataAppendValue51(SColData *pColData, SColVal *pColVal) { int32_t code = 0; @@ -1423,12 +1368,7 @@ static FORCE_INLINE int32_t tColDataAppendValue51(SColData *pColData, SColVal *p SET_BIT1(pColData->pBitMap, pColData->nVal, 0); - code = tColDataPutValue(pColData, pColVal); - if (code) return code; - - pColData->nVal++; - - return code; + return tColDataPutValue(pColData, pColVal); } static FORCE_INLINE int32_t tColDataAppendValue52(SColData *pColData, SColVal *pColVal) { int32_t code = 0; @@ -1447,12 +1387,7 @@ static FORCE_INLINE int32_t tColDataAppendValue52(SColData *pColData, SColVal *p tFree(pColData->pBitMap); pColData->pBitMap = pBitMap; - code = tColDataPutValue(pColData, pColVal); - if (code) return code; - - pColData->nVal++; - - return code; + return tColDataPutValue(pColData, pColVal); } static FORCE_INLINE int32_t tColDataAppendValue60(SColData *pColData, SColVal *pColVal) { int32_t code = 0; @@ -1461,12 +1396,7 @@ static FORCE_INLINE int32_t tColDataAppendValue60(SColData *pColData, SColVal *p if (code) return code; SET_BIT1(pColData->pBitMap, pColData->nVal, 1); - code = tColDataPutValue(pColData, pColVal); - if (code) return code; - - pColData->nVal++; - - return code; + return tColDataPutValue(pColData, pColVal); } static FORCE_INLINE int32_t tColDataAppendValue61(SColData *pColData, SColVal *pColVal) { int32_t code = 0; @@ -1485,12 +1415,7 @@ static FORCE_INLINE int32_t tColDataAppendValue61(SColData *pColData, SColVal *p tFree(pColData->pBitMap); pColData->pBitMap = pBitMap; - code = tColDataPutValue(pColData, pColVal); - if (code) return code; - - pColData->nVal++; - - return code; + return tColDataPutValue(pColData, pColVal); } static FORCE_INLINE int32_t tColDataAppendValue62(SColData *pColData, SColVal *pColVal) { int32_t code = 0; @@ -1499,12 +1424,7 @@ static FORCE_INLINE int32_t tColDataAppendValue62(SColData *pColData, SColVal *p if (code) return code; SET_BIT1(pColData->pBitMap, pColData->nVal, 0); - code = tColDataPutValue(pColData, pColVal); - if (code) return code; - - pColData->nVal++; - - return code; + return tColDataPutValue(pColData, pColVal); } static FORCE_INLINE int32_t tColDataAppendValue70(SColData *pColData, SColVal *pColVal) { int32_t code = 0; @@ -1513,12 +1433,7 @@ static FORCE_INLINE int32_t tColDataAppendValue70(SColData *pColData, SColVal *p if (code) return code; SET_BIT2(pColData->pBitMap, pColData->nVal, 2); - code = tColDataPutValue(pColData, pColVal); - if (code) return code; - - pColData->nVal++; - - return code; + return tColDataPutValue(pColData, pColVal); } static FORCE_INLINE int32_t tColDataAppendValue71(SColData *pColData, SColVal *pColVal) { int32_t code = 0; @@ -1527,12 +1442,7 @@ static FORCE_INLINE int32_t tColDataAppendValue71(SColData *pColData, SColVal *p if (code) return code; SET_BIT2(pColData->pBitMap, pColData->nVal, 0); - code = tColDataPutValue(pColData, pColVal); - if (code) return code; - - pColData->nVal++; - - return code; + return tColDataPutValue(pColData, pColVal); } static FORCE_INLINE int32_t tColDataAppendValue72(SColData *pColData, SColVal *pColVal) { int32_t code = 0; @@ -1541,12 +1451,7 @@ static FORCE_INLINE int32_t tColDataAppendValue72(SColData *pColData, SColVal *p if (code) return code; SET_BIT2(pColData->pBitMap, pColData->nVal, 1); - code = tColDataPutValue(pColData, pColVal); - if (code) return code; - - pColData->nVal++; - - return code; + return tColDataPutValue(pColData, pColVal); } static int32_t (*tColDataAppendValueImpl[8][3])(SColData *pColData, SColVal *pColVal) = { {tColDataAppendValue00, tColDataAppendValue01, tColDataAppendValue02}, // 0 @@ -1652,7 +1557,7 @@ void tColDataGetValue(SColData *pColData, int32_t iVal, SColVal *pColVal) { tColDataGetValueImpl[pColData->flag](pColData, iVal, pColVal); } -uint8_t tColDataGetBitValue(SColData *pColData, int32_t iVal) { +uint8_t tColDataGetBitValue(const SColData *pColData, int32_t iVal) { uint8_t v; switch (pColData->flag) { case HAS_NONE: @@ -1723,3 +1628,385 @@ int32_t tColDataCopy(SColData *pColDataSrc, SColData *pColDataDest) { _exit: return code; } + +#define CALC_SUM_MAX_MIN(SUM, MAX, MIN, VAL) \ + do { \ + (SUM) += (VAL); \ + if ((MAX) < (VAL)) (MAX) = (VAL); \ + if ((MIN) > (VAL)) (MIN) = (VAL); \ + } while (0) + +static FORCE_INLINE void tColDataCalcSMABool(SColData *pColData, int64_t *sum, int64_t *max, int64_t *min, + int16_t *numOfNull) { + *sum = 0; + *max = 0; + *min = 1; + *numOfNull = 0; + + int8_t val; + if (HAS_VALUE == pColData->flag) { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + val = ((int8_t *)pColData->pData)[iVal] ? 1 : 0; + CALC_SUM_MAX_MIN(*sum, *max, *min, val); + } + } else { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + switch (tColDataGetBitValue(pColData, iVal)) { + case 0: + case 1: + (*numOfNull)++; + break; + case 2: + val = ((int8_t *)pColData->pData)[iVal] ? 1 : 0; + CALC_SUM_MAX_MIN(*sum, *max, *min, val); + break; + default: + ASSERT(0); + break; + } + } + } +} + +static FORCE_INLINE void tColDataCalcSMATinyInt(SColData *pColData, int64_t *sum, int64_t *max, int64_t *min, + int16_t *numOfNull) { + *sum = 0; + *max = INT8_MIN; + *min = INT8_MAX; + *numOfNull = 0; + + int8_t val; + if (HAS_VALUE == pColData->flag) { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + val = ((int8_t *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*sum, *max, *min, val); + } + } else { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + switch (tColDataGetBitValue(pColData, iVal)) { + case 0: + case 1: + (*numOfNull)++; + break; + case 2: + val = ((int8_t *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*sum, *max, *min, val); + break; + default: + ASSERT(0); + break; + } + } + } +} + +static FORCE_INLINE void tColDataCalcSMATinySmallInt(SColData *pColData, int64_t *sum, int64_t *max, int64_t *min, + int16_t *numOfNull) { + *sum = 0; + *max = INT16_MIN; + *min = INT16_MAX; + *numOfNull = 0; + + int16_t val; + if (HAS_VALUE == pColData->flag) { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + val = ((int16_t *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*sum, *max, *min, val); + } + } else { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + switch (tColDataGetBitValue(pColData, iVal)) { + case 0: + case 1: + (*numOfNull)++; + break; + case 2: + val = ((int16_t *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*sum, *max, *min, val); + break; + default: + ASSERT(0); + break; + } + } + } +} + +static FORCE_INLINE void tColDataCalcSMAInt(SColData *pColData, int64_t *sum, int64_t *max, int64_t *min, + int16_t *numOfNull) { + *sum = 0; + *max = INT32_MIN; + *min = INT32_MAX; + *numOfNull = 0; + + int32_t val; + if (HAS_VALUE == pColData->flag) { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + val = ((int32_t *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*sum, *max, *min, val); + } + } else { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + switch (tColDataGetBitValue(pColData, iVal)) { + case 0: + case 1: + (*numOfNull)++; + break; + case 2: + val = ((int32_t *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*sum, *max, *min, val); + break; + default: + ASSERT(0); + break; + } + } + } +} + +static FORCE_INLINE void tColDataCalcSMABigInt(SColData *pColData, int64_t *sum, int64_t *max, int64_t *min, + int16_t *numOfNull) { + *sum = 0; + *max = INT64_MIN; + *min = INT64_MAX; + *numOfNull = 0; + + int64_t val; + if (HAS_VALUE == pColData->flag) { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + val = ((int64_t *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*sum, *max, *min, val); + } + } else { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + switch (tColDataGetBitValue(pColData, iVal)) { + case 0: + case 1: + (*numOfNull)++; + break; + case 2: + val = ((int64_t *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*sum, *max, *min, val); + break; + default: + ASSERT(0); + break; + } + } + } +} + +static FORCE_INLINE void tColDataCalcSMAFloat(SColData *pColData, int64_t *sum, int64_t *max, int64_t *min, + int16_t *numOfNull) { + *(double *)sum = 0; + *(double *)max = -FLT_MAX; + *(double *)min = FLT_MAX; + *numOfNull = 0; + + float val; + if (HAS_VALUE == pColData->flag) { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + val = ((float *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*(double *)sum, *(double *)max, *(double *)min, val); + } + } else { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + switch (tColDataGetBitValue(pColData, iVal)) { + case 0: + case 1: + (*numOfNull)++; + break; + case 2: + val = ((float *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*(double *)sum, *(double *)max, *(double *)min, val); + break; + default: + ASSERT(0); + break; + } + } + } +} + +static FORCE_INLINE void tColDataCalcSMADouble(SColData *pColData, int64_t *sum, int64_t *max, int64_t *min, + int16_t *numOfNull) { + *(double *)sum = 0; + *(double *)max = -DBL_MAX; + *(double *)min = DBL_MAX; + *numOfNull = 0; + + double val; + if (HAS_VALUE == pColData->flag) { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + val = ((double *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*(double *)sum, *(double *)max, *(double *)min, val); + } + } else { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + switch (tColDataGetBitValue(pColData, iVal)) { + case 0: + case 1: + (*numOfNull)++; + break; + case 2: + val = ((double *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*(double *)sum, *(double *)max, *(double *)min, val); + break; + default: + ASSERT(0); + break; + } + } + } +} + +static FORCE_INLINE void tColDataCalcSMAUTinyInt(SColData *pColData, int64_t *sum, int64_t *max, int64_t *min, + int16_t *numOfNull) { + *(uint64_t *)sum = 0; + *(uint64_t *)max = 0; + *(uint64_t *)min = UINT8_MAX; + *numOfNull = 0; + + uint8_t val; + if (HAS_VALUE == pColData->flag) { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + val = ((uint8_t *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*(uint64_t *)sum, *(uint64_t *)max, *(uint64_t *)min, val); + } + } else { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + switch (tColDataGetBitValue(pColData, iVal)) { + case 0: + case 1: + (*numOfNull)++; + break; + case 2: + val = ((uint8_t *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*(uint64_t *)sum, *(uint64_t *)max, *(uint64_t *)min, val); + break; + default: + ASSERT(0); + break; + } + } + } +} + +static FORCE_INLINE void tColDataCalcSMATinyUSmallInt(SColData *pColData, int64_t *sum, int64_t *max, int64_t *min, + int16_t *numOfNull) { + *(uint64_t *)sum = 0; + *(uint64_t *)max = 0; + *(uint64_t *)min = UINT16_MAX; + *numOfNull = 0; + + uint16_t val; + if (HAS_VALUE == pColData->flag) { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + val = ((uint16_t *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*(uint64_t *)sum, *(uint64_t *)max, *(uint64_t *)min, val); + } + } else { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + switch (tColDataGetBitValue(pColData, iVal)) { + case 0: + case 1: + (*numOfNull)++; + break; + case 2: + val = ((uint16_t *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*(uint64_t *)sum, *(uint64_t *)max, *(uint64_t *)min, val); + break; + default: + ASSERT(0); + break; + } + } + } +} + +static FORCE_INLINE void tColDataCalcSMAUInt(SColData *pColData, int64_t *sum, int64_t *max, int64_t *min, + int16_t *numOfNull) { + *(uint64_t *)sum = 0; + *(uint64_t *)max = 0; + *(uint64_t *)min = UINT32_MAX; + *numOfNull = 0; + + uint32_t val; + if (HAS_VALUE == pColData->flag) { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + val = ((uint32_t *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*(uint64_t *)sum, *(uint64_t *)max, *(uint64_t *)min, val); + } + } else { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + switch (tColDataGetBitValue(pColData, iVal)) { + case 0: + case 1: + (*numOfNull)++; + break; + case 2: + val = ((uint32_t *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*(uint64_t *)sum, *(uint64_t *)max, *(uint64_t *)min, val); + break; + default: + ASSERT(0); + break; + } + } + } +} + +static FORCE_INLINE void tColDataCalcSMAUBigInt(SColData *pColData, int64_t *sum, int64_t *max, int64_t *min, + int16_t *numOfNull) { + *(uint64_t *)sum = 0; + *(uint64_t *)max = 0; + *(uint64_t *)min = UINT64_MAX; + *numOfNull = 0; + + uint64_t val; + if (HAS_VALUE == pColData->flag) { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + val = ((uint64_t *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*(uint64_t *)sum, *(uint64_t *)max, *(uint64_t *)min, val); + } + } else { + for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { + switch (tColDataGetBitValue(pColData, iVal)) { + case 0: + case 1: + (*numOfNull)++; + break; + case 2: + val = ((uint64_t *)pColData->pData)[iVal]; + CALC_SUM_MAX_MIN(*(uint64_t *)sum, *(uint64_t *)max, *(uint64_t *)min, val); + break; + default: + ASSERT(0); + break; + } + } + } +} + +void (*tColDataCalcSMA[])(SColData *pColData, int64_t *sum, int64_t *max, int64_t *min, int16_t *numOfNull) = { + NULL, + tColDataCalcSMABool, // TSDB_DATA_TYPE_BOOL + tColDataCalcSMATinyInt, // TSDB_DATA_TYPE_TINYINT + tColDataCalcSMATinySmallInt, // TSDB_DATA_TYPE_SMALLINT + tColDataCalcSMAInt, // TSDB_DATA_TYPE_INT + tColDataCalcSMABigInt, // TSDB_DATA_TYPE_BIGINT + tColDataCalcSMAFloat, // TSDB_DATA_TYPE_FLOAT + tColDataCalcSMADouble, // TSDB_DATA_TYPE_DOUBLE + NULL, // TSDB_DATA_TYPE_VARCHAR + tColDataCalcSMABigInt, // TSDB_DATA_TYPE_TIMESTAMP + NULL, // TSDB_DATA_TYPE_NCHAR + tColDataCalcSMAUTinyInt, // TSDB_DATA_TYPE_UTINYINT + tColDataCalcSMATinyUSmallInt, // TSDB_DATA_TYPE_USMALLINT + tColDataCalcSMAUInt, // TSDB_DATA_TYPE_UINT + tColDataCalcSMAUBigInt, // TSDB_DATA_TYPE_UBIGINT + NULL, // TSDB_DATA_TYPE_JSON + NULL, // TSDB_DATA_TYPE_VARBINARY + NULL, // TSDB_DATA_TYPE_DECIMAL + NULL, // TSDB_DATA_TYPE_BLOB + NULL // TSDB_DATA_TYPE_MEDIUMBLOB +}; diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 5025cbcac581604b64bfe1f3abe2c9fd335560ed..1be77077b6033005405293d41398c3c9c91b8b27 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -50,13 +50,11 @@ int32_t tsNumOfMnodeReadThreads = 1; int32_t tsNumOfVnodeQueryThreads = 4; int32_t tsNumOfVnodeStreamThreads = 2; int32_t tsNumOfVnodeFetchThreads = 4; -int32_t tsNumOfVnodeWriteThreads = 2; -int32_t tsNumOfVnodeSyncThreads = 2; int32_t tsNumOfVnodeRsmaThreads = 2; int32_t tsNumOfQnodeQueryThreads = 4; int32_t tsNumOfQnodeFetchThreads = 1; -int32_t tsNumOfSnodeSharedThreads = 2; -int32_t tsNumOfSnodeUniqueThreads = 2; +int32_t tsNumOfSnodeStreamThreads = 4; +int32_t tsNumOfSnodeWriteThreads = 1; // monitor bool tsEnableMonitor = true; @@ -82,6 +80,7 @@ bool tsSmlDataFormat = false; // query int32_t tsQueryPolicy = 1; int32_t tsQueryRspPolicy = 0; +bool tsEnableQueryHb = false; int32_t tsQuerySmaOptimize = 0; int32_t tsQueryRsmaTolerance = 1000; // the tolerance time (ms) to judge from which level to query rsma data. bool tsQueryPlannerTrace = false; @@ -132,7 +131,7 @@ int32_t tsDiskCfgNum = 0; SDiskCfg tsDiskCfg[TFS_MAX_DISKS] = {0}; // stream scheduler -bool tsSchedStreamToSnode = true; +bool tsDeployOnSnode = true; /* * minimum scale for whole system, millisecond by default @@ -155,6 +154,9 @@ char tsCompressor[32] = "ZSTD_COMPRESSOR"; // ZSTD_COMPRESSOR or GZIP_COMPR // udf bool tsStartUdfd = true; +// wal +int64_t tsWalFsyncDataSizeLimit = (100 * 1024 * 1024L); + // internal int32_t tsTransPullupInterval = 2; int32_t tsMqRebalanceInterval = 2; @@ -162,7 +164,8 @@ int32_t tsTtlUnit = 86400; int32_t tsTtlPushInterval = 86400; int32_t tsGrantHBInterval = 60; int32_t tsUptimeInterval = 300; // seconds -char tsUdfdResFuncs[1024] = ""; // udfd resident funcs that teardown when udfd exits +char tsUdfdResFuncs[512] = ""; // udfd resident funcs that teardown when udfd exits +char tsUdfdLdLibPath[512] = ""; #ifndef _STORAGE int32_t taosSetTfsCfg(SConfig *pCfg) { @@ -284,6 +287,7 @@ static int32_t taosAddClientCfg(SConfig *pCfg) { if (cfgAddInt32(pCfg, "compressMsgSize", tsCompressMsgSize, -1, 100000000, 1) != 0) return -1; if (cfgAddInt32(pCfg, "compressColData", tsCompressColData, -1, 100000000, 1) != 0) return -1; if (cfgAddInt32(pCfg, "queryPolicy", tsQueryPolicy, 1, 4, 1) != 0) return -1; + if (cfgAddBool(pCfg, "enableQueryHb", tsEnableQueryHb, false) != 0) return -1; if (cfgAddInt32(pCfg, "querySmaOptimize", tsQuerySmaOptimize, 0, 1, 1) != 0) return -1; if (cfgAddBool(pCfg, "queryPlannerTrace", tsQueryPlannerTrace, true) != 0) return -1; if (cfgAddInt32(pCfg, "queryNodeChunkSize", tsQueryNodeChunkSize, 1024, 128 * 1024, true) != 0) return -1; @@ -368,14 +372,6 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { tsNumOfVnodeFetchThreads = TMAX(tsNumOfVnodeFetchThreads, 4); if (cfgAddInt32(pCfg, "numOfVnodeFetchThreads", tsNumOfVnodeFetchThreads, 4, 1024, 0) != 0) return -1; - tsNumOfVnodeWriteThreads = tsNumOfCores; - tsNumOfVnodeWriteThreads = TMAX(tsNumOfVnodeWriteThreads, 1); - if (cfgAddInt32(pCfg, "numOfVnodeWriteThreads", tsNumOfVnodeWriteThreads, 1, 1024, 0) != 0) return -1; - - tsNumOfVnodeSyncThreads = tsNumOfCores * 2; - tsNumOfVnodeSyncThreads = TMAX(tsNumOfVnodeSyncThreads, 16); - if (cfgAddInt32(pCfg, "numOfVnodeSyncThreads", tsNumOfVnodeSyncThreads, 1, 1024, 0) != 0) return -1; - tsNumOfVnodeRsmaThreads = tsNumOfCores; tsNumOfVnodeRsmaThreads = TMAX(tsNumOfVnodeRsmaThreads, 4); if (cfgAddInt32(pCfg, "numOfVnodeRsmaThreads", tsNumOfVnodeRsmaThreads, 1, 1024, 0) != 0) return -1; @@ -388,13 +384,13 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { // tsNumOfQnodeFetchThreads = TMAX(tsNumOfQnodeFetchThreads, 4); // if (cfgAddInt32(pCfg, "numOfQnodeFetchThreads", tsNumOfQnodeFetchThreads, 1, 1024, 0) != 0) return -1; - tsNumOfSnodeSharedThreads = tsNumOfCores / 4; - tsNumOfSnodeSharedThreads = TRANGE(tsNumOfSnodeSharedThreads, 2, 4); - if (cfgAddInt32(pCfg, "numOfSnodeSharedThreads", tsNumOfSnodeSharedThreads, 2, 1024, 0) != 0) return -1; + tsNumOfSnodeStreamThreads = tsNumOfCores / 4; + tsNumOfSnodeStreamThreads = TRANGE(tsNumOfSnodeStreamThreads, 2, 4); + if (cfgAddInt32(pCfg, "numOfSnodeSharedThreads", tsNumOfSnodeStreamThreads, 2, 1024, 0) != 0) return -1; - tsNumOfSnodeUniqueThreads = tsNumOfCores / 4; - tsNumOfSnodeUniqueThreads = TRANGE(tsNumOfSnodeUniqueThreads, 2, 4); - if (cfgAddInt32(pCfg, "numOfSnodeUniqueThreads", tsNumOfSnodeUniqueThreads, 2, 1024, 0) != 0) return -1; + tsNumOfSnodeWriteThreads = tsNumOfCores / 4; + tsNumOfSnodeWriteThreads = TRANGE(tsNumOfSnodeWriteThreads, 2, 4); + if (cfgAddInt32(pCfg, "numOfSnodeUniqueThreads", tsNumOfSnodeWriteThreads, 2, 1024, 0) != 0) return -1; tsRpcQueueMemoryAllowed = tsTotalMemoryKB * 1024 * 0.1; tsRpcQueueMemoryAllowed = TRANGE(tsRpcQueueMemoryAllowed, TSDB_MAX_MSG_SIZE * 10LL, TSDB_MAX_MSG_SIZE * 10000LL); @@ -420,8 +416,12 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddInt32(pCfg, "uptimeInterval", tsUptimeInterval, 1, 100000, 1) != 0) return -1; if (cfgAddInt32(pCfg, "queryRsmaTolerance", tsQueryRsmaTolerance, 0, 900000, 0) != 0) return -1; + if (cfgAddInt64(pCfg, "walFsyncDataSizeLimit", tsWalFsyncDataSizeLimit, 100 * 1024 * 1024, INT64_MAX, 0) != 0) + return -1; + if (cfgAddBool(pCfg, "udf", tsStartUdfd, 0) != 0) return -1; if (cfgAddString(pCfg, "udfdResFuncs", tsUdfdResFuncs, 0) != 0) return -1; + if (cfgAddString(pCfg, "udfdLdLibPath", tsUdfdLdLibPath, 0) != 0) return -1; GRANT_CFG_ADD; return 0; } @@ -496,22 +496,6 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem->stype = stype; } - pItem = cfgGetItem(tsCfg, "numOfVnodeWriteThreads"); - if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { - tsNumOfVnodeWriteThreads = numOfCores; - tsNumOfVnodeWriteThreads = TMAX(tsNumOfVnodeWriteThreads, 1); - pItem->i32 = tsNumOfVnodeWriteThreads; - pItem->stype = stype; - } - - pItem = cfgGetItem(tsCfg, "numOfVnodeSyncThreads"); - if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { - tsNumOfVnodeSyncThreads = numOfCores * 2; - tsNumOfVnodeSyncThreads = TMAX(tsNumOfVnodeSyncThreads, 16); - pItem->i32 = tsNumOfVnodeSyncThreads; - pItem->stype = stype; - } - pItem = cfgGetItem(tsCfg, "numOfVnodeRsmaThreads"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { tsNumOfVnodeRsmaThreads = numOfCores; @@ -540,17 +524,17 @@ static int32_t taosUpdateServerCfg(SConfig *pCfg) { pItem = cfgGetItem(tsCfg, "numOfSnodeSharedThreads"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { - tsNumOfSnodeSharedThreads = numOfCores / 4; - tsNumOfSnodeSharedThreads = TRANGE(tsNumOfSnodeSharedThreads, 2, 4); - pItem->i32 = tsNumOfSnodeSharedThreads; + tsNumOfSnodeStreamThreads = numOfCores / 4; + tsNumOfSnodeStreamThreads = TRANGE(tsNumOfSnodeStreamThreads, 2, 4); + pItem->i32 = tsNumOfSnodeStreamThreads; pItem->stype = stype; } pItem = cfgGetItem(tsCfg, "numOfSnodeUniqueThreads"); if (pItem != NULL && pItem->stype == CFG_STYPE_DEFAULT) { - tsNumOfSnodeUniqueThreads = numOfCores / 4; - tsNumOfSnodeUniqueThreads = TRANGE(tsNumOfSnodeUniqueThreads, 2, 4); - pItem->i32 = tsNumOfSnodeUniqueThreads; + tsNumOfSnodeWriteThreads = numOfCores / 4; + tsNumOfSnodeWriteThreads = TRANGE(tsNumOfSnodeWriteThreads, 2, 4); + pItem->i32 = tsNumOfSnodeWriteThreads; pItem->stype = stype; } @@ -644,6 +628,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) { tsCompressColData = cfgGetItem(pCfg, "compressColData")->i32; tsNumOfTaskQueueThreads = cfgGetItem(pCfg, "numOfTaskQueueThreads")->i32; tsQueryPolicy = cfgGetItem(pCfg, "queryPolicy")->i32; + tsEnableQueryHb = cfgGetItem(pCfg, "enableQueryHb")->bval; tsQuerySmaOptimize = cfgGetItem(pCfg, "querySmaOptimize")->i32; tsQueryPlannerTrace = cfgGetItem(pCfg, "queryPlannerTrace")->bval; tsQueryNodeChunkSize = cfgGetItem(pCfg, "queryNodeChunkSize")->i32; @@ -688,13 +673,11 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { tsNumOfVnodeQueryThreads = cfgGetItem(pCfg, "numOfVnodeQueryThreads")->i32; tsNumOfVnodeStreamThreads = cfgGetItem(pCfg, "numOfVnodeStreamThreads")->i32; tsNumOfVnodeFetchThreads = cfgGetItem(pCfg, "numOfVnodeFetchThreads")->i32; - tsNumOfVnodeWriteThreads = cfgGetItem(pCfg, "numOfVnodeWriteThreads")->i32; - tsNumOfVnodeSyncThreads = cfgGetItem(pCfg, "numOfVnodeSyncThreads")->i32; tsNumOfVnodeRsmaThreads = cfgGetItem(pCfg, "numOfVnodeRsmaThreads")->i32; tsNumOfQnodeQueryThreads = cfgGetItem(pCfg, "numOfQnodeQueryThreads")->i32; // tsNumOfQnodeFetchThreads = cfgGetItem(pCfg, "numOfQnodeFetchThreads")->i32; - tsNumOfSnodeSharedThreads = cfgGetItem(pCfg, "numOfSnodeSharedThreads")->i32; - tsNumOfSnodeUniqueThreads = cfgGetItem(pCfg, "numOfSnodeUniqueThreads")->i32; + tsNumOfSnodeStreamThreads = cfgGetItem(pCfg, "numOfSnodeSharedThreads")->i32; + tsNumOfSnodeWriteThreads = cfgGetItem(pCfg, "numOfSnodeUniqueThreads")->i32; tsRpcQueueMemoryAllowed = cfgGetItem(pCfg, "rpcQueueMemoryAllowed")->i64; tsEnableMonitor = cfgGetItem(pCfg, "monitor")->bval; @@ -717,9 +700,11 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { tsUptimeInterval = cfgGetItem(pCfg, "uptimeInterval")->i32; tsQueryRsmaTolerance = cfgGetItem(pCfg, "queryRsmaTolerance")->i32; + tsWalFsyncDataSizeLimit = cfgGetItem(pCfg, "walFsyncDataSizeLimit")->i64; + tsStartUdfd = cfgGetItem(pCfg, "udf")->bval; tstrncpy(tsUdfdResFuncs, cfgGetItem(pCfg, "udfdResFuncs")->str, sizeof(tsUdfdResFuncs)); - + tstrncpy(tsUdfdLdLibPath, cfgGetItem(pCfg, "udfdLdLibPath")->str, sizeof(tsUdfdLdLibPath)); if (tsQueryBufferSize >= 0) { tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL; } @@ -773,6 +758,9 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) { case 'd': { if (strcasecmp("dDebugFlag", name) == 0) { dDebugFlag = cfgGetItem(pCfg, "dDebugFlag")->i32; + } else if (strcasecmp("debugFlag", name) == 0) { + int32_t flag = cfgGetItem(pCfg, "debugFlag")->i32; + taosSetAllDebugFlag(flag, true); } break; } @@ -780,6 +768,8 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) { if (strcasecmp("enableCoreFile", name) == 0) { bool enableCore = cfgGetItem(pCfg, "enableCoreFile")->bval; taosSetCoreDump(enableCore); + } else if (strcasecmp("enableQueryHb", name) == 0) { + tsEnableQueryHb = cfgGetItem(pCfg, "enableQueryHb")->bval; } break; } @@ -928,10 +918,6 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) { } else if (strcasecmp("numOfVnodeFetchThreads", name) == 0) { tsNumOfVnodeFetchThreads = cfgGetItem(pCfg, "numOfVnodeFetchThreads")->i32; */ - } else if (strcasecmp("numOfVnodeWriteThreads", name) == 0) { - tsNumOfVnodeWriteThreads = cfgGetItem(pCfg, "numOfVnodeWriteThreads")->i32; - } else if (strcasecmp("numOfVnodeSyncThreads", name) == 0) { - tsNumOfVnodeSyncThreads = cfgGetItem(pCfg, "numOfVnodeSyncThreads")->i32; } else if (strcasecmp("numOfVnodeRsmaThreads", name) == 0) { tsNumOfVnodeRsmaThreads = cfgGetItem(pCfg, "numOfVnodeRsmaThreads")->i32; } else if (strcasecmp("numOfQnodeQueryThreads", name) == 0) { @@ -941,9 +927,9 @@ int32_t taosSetCfg(SConfig *pCfg, char *name) { tsNumOfQnodeFetchThreads = cfgGetItem(pCfg, "numOfQnodeFetchThreads")->i32; */ } else if (strcasecmp("numOfSnodeSharedThreads", name) == 0) { - tsNumOfSnodeSharedThreads = cfgGetItem(pCfg, "numOfSnodeSharedThreads")->i32; + tsNumOfSnodeStreamThreads = cfgGetItem(pCfg, "numOfSnodeSharedThreads")->i32; } else if (strcasecmp("numOfSnodeUniqueThreads", name) == 0) { - tsNumOfSnodeUniqueThreads = cfgGetItem(pCfg, "numOfSnodeUniqueThreads")->i32; + tsNumOfSnodeWriteThreads = cfgGetItem(pCfg, "numOfSnodeUniqueThreads")->i32; } else if (strcasecmp("numOfLogLines", name) == 0) { tsNumOfLogLines = cfgGetItem(pCfg, "numOfLogLines")->i32; } diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index a001126b21b8eda8265b2148477869044a05bac9..2eb94773e9ed4ad0fe509d35b461dd5f5450639a 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -1020,6 +1020,7 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { if (tEncodeI64(&encoder, pReq->qload.timeInQueryQueue) < 0) return -1; if (tEncodeI64(&encoder, pReq->qload.timeInFetchQueue) < 0) return -1; + if (tEncodeI32(&encoder, pReq->statusSeq) < 0) return -1; tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -1095,6 +1096,7 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { if (tDecodeI64(&decoder, &pReq->qload.timeInQueryQueue) < 0) return -1; if (tDecodeI64(&decoder, &pReq->qload.timeInFetchQueue) < 0) return -1; + if (tDecodeI32(&decoder, &pReq->statusSeq) < 0) return -1; tEndDecode(&decoder); tDecoderClear(&decoder); return 0; @@ -1126,6 +1128,7 @@ int32_t tSerializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) { if (tEncodeU16(&encoder, pDnodeEp->ep.port) < 0) return -1; } + if (tEncodeI32(&encoder, pRsp->statusSeq) < 0) return -1; tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -1167,6 +1170,7 @@ int32_t tDeserializeSStatusRsp(void *buf, int32_t bufLen, SStatusRsp *pRsp) { } } + if (tDecodeI32(&decoder, &pRsp->statusSeq) < 0) return -1; tEndDecode(&decoder); tDecoderClear(&decoder); return 0; @@ -1485,6 +1489,7 @@ int32_t tSerializeSDropDnodeReq(void *buf, int32_t bufLen, SDropDnodeReq *pReq) if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1; if (tEncodeCStr(&encoder, pReq->fqdn) < 0) return -1; if (tEncodeI32(&encoder, pReq->port) < 0) return -1; + if (tEncodeI8(&encoder, pReq->force) < 0) return -1; tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -1500,6 +1505,7 @@ int32_t tDeserializeSDropDnodeReq(void *buf, int32_t bufLen, SDropDnodeReq *pReq if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1; if (tDecodeCStrTo(&decoder, pReq->fqdn) < 0) return -1; if (tDecodeI32(&decoder, &pReq->port) < 0) return -1; + if (tDecodeI8(&decoder, &pReq->force) < 0) return -1; tEndDecode(&decoder); tDecoderClear(&decoder); @@ -2232,6 +2238,7 @@ int32_t tSerializeSUseDbReq(void *buf, int32_t bufLen, SUseDbReq *pReq) { if (tEncodeI64(&encoder, pReq->dbId) < 0) return -1; if (tEncodeI32(&encoder, pReq->vgVersion) < 0) return -1; if (tEncodeI32(&encoder, pReq->numOfTable) < 0) return -1; + if (tEncodeI64(&encoder, pReq->stateTs) < 0) return -1; tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -2248,6 +2255,7 @@ int32_t tDeserializeSUseDbReq(void *buf, int32_t bufLen, SUseDbReq *pReq) { if (tDecodeI64(&decoder, &pReq->dbId) < 0) return -1; if (tDecodeI32(&decoder, &pReq->vgVersion) < 0) return -1; if (tDecodeI32(&decoder, &pReq->numOfTable) < 0) return -1; + if (tDecodeI64(&decoder, &pReq->stateTs) < 0) return -1; tEndDecode(&decoder); tDecoderClear(&decoder); @@ -2483,6 +2491,8 @@ int32_t tSerializeSUseDbRspImp(SEncoder *pEncoder, const SUseDbRsp *pRsp) { if (tEncodeI32(pEncoder, pVgInfo->numOfTable) < 0) return -1; } + if (tEncodeI32(pEncoder, pRsp->errCode) < 0) return -1; + if (tEncodeI64(pEncoder, pRsp->stateTs) < 0) return -1; return 0; } @@ -2547,6 +2557,8 @@ int32_t tDeserializeSUseDbRspImp(SDecoder *pDecoder, SUseDbRsp *pRsp) { taosArrayPush(pRsp->pVgroupInfos, &vgInfo); } + if (tDecodeI32(pDecoder, &pRsp->errCode) < 0) return -1; + if (tDecodeI64(pDecoder, &pRsp->stateTs) < 0) return -1; return 0; } @@ -4996,6 +5008,7 @@ int32_t tDeserializeSMRecoverStreamReq(void *buf, int32_t bufLen, SMRecoverStrea } void tFreeSCMCreateStreamReq(SCMCreateStreamReq *pReq) { + taosArrayDestroy(pReq->pTags); taosMemoryFreeClear(pReq->sql); taosMemoryFreeClear(pReq->ast); } @@ -5429,9 +5442,12 @@ static int32_t tEncodeSSubmitBlkRsp(SEncoder *pEncoder, const SSubmitBlkRsp *pBl if (tStartEncode(pEncoder) < 0) return -1; if (tEncodeI32(pEncoder, pBlock->code) < 0) return -1; - if (tEncodeI8(pEncoder, pBlock->hashMeta) < 0) return -1; if (tEncodeI64(pEncoder, pBlock->uid) < 0) return -1; - if (tEncodeCStr(pEncoder, pBlock->tblFName) < 0) return -1; + if (pBlock->tblFName) { + if (tEncodeCStr(pEncoder, pBlock->tblFName) < 0) return -1; + } else { + if (tEncodeCStr(pEncoder, "") < 0) return -1; + } if (tEncodeI32v(pEncoder, pBlock->numOfRows) < 0) return -1; if (tEncodeI32v(pEncoder, pBlock->affectedRows) < 0) return -1; if (tEncodeI64v(pEncoder, pBlock->sver) < 0) return -1; @@ -5448,7 +5464,6 @@ static int32_t tDecodeSSubmitBlkRsp(SDecoder *pDecoder, SSubmitBlkRsp *pBlock) { if (tStartDecode(pDecoder) < 0) return -1; if (tDecodeI32(pDecoder, &pBlock->code) < 0) return -1; - if (tDecodeI8(pDecoder, &pBlock->hashMeta) < 0) return -1; if (tDecodeI64(pDecoder, &pBlock->uid) < 0) return -1; pBlock->tblFName = taosMemoryCalloc(TSDB_TABLE_FNAME_LEN, 1); if (NULL == pBlock->tblFName) return -1; @@ -6120,13 +6135,13 @@ void tDeleteSTaosxRsp(STaosxRsp *pRsp) { } int32_t tEncodeSSingleDeleteReq(SEncoder *pEncoder, const SSingleDeleteReq *pReq) { - if (tEncodeI64(pEncoder, pReq->uid) < 0) return -1; + if (tEncodeCStr(pEncoder, pReq->tbname) < 0) return -1; if (tEncodeI64(pEncoder, pReq->ts) < 0) return -1; return 0; } int32_t tDecodeSSingleDeleteReq(SDecoder *pDecoder, SSingleDeleteReq *pReq) { - if (tDecodeI64(pDecoder, &pReq->uid) < 0) return -1; + if (tDecodeCStrTo(pDecoder, pReq->tbname) < 0) return -1; if (tDecodeI64(pDecoder, &pReq->ts) < 0) return -1; return 0; } diff --git a/source/common/src/tname.c b/source/common/src/tname.c index 70682d6cd4efbf621668197d1b40da3f453c4c50..4d83b6e3d84bfd2ab123efd0720b90ebca18ce81 100644 --- a/source/common/src/tname.c +++ b/source/common/src/tname.c @@ -315,7 +315,7 @@ static int compareKv(const void* p1, const void* p2) { */ void buildChildTableName(RandTableName* rName) { SStringBuilder sb = {0}; - taosStringBuilderAppendStringLen(&sb, rName->sTableName, rName->sTableNameLen); + taosStringBuilderAppendStringLen(&sb, rName->stbFullName, rName->stbFullNameLen); taosArraySort(rName->tags, compareKv); for (int j = 0; j < taosArrayGetSize(rName->tags); ++j) { taosStringBuilderAppendChar(&sb, ','); @@ -336,11 +336,11 @@ void buildChildTableName(RandTableName* rName) { tMD5Final(&context); char temp[8] = {0}; - rName->childTableName[0] = 't'; - rName->childTableName[1] = '_'; + rName->ctbShortName[0] = 't'; + rName->ctbShortName[1] = '_'; for (int i = 0; i < 16; i++) { sprintf(temp, "%02x", context.digest[i]); - strcat(rName->childTableName, temp); + strcat(rName->ctbShortName, temp); } taosStringBuilderDestroy(&sb); rName->uid = *(uint64_t*)(context.digest); diff --git a/source/common/src/trow.c b/source/common/src/trow.c index b007075efe863943020f9d2bc4f1b771c93115c4..d39d3c501a4c3df1afe4f1389865bd98906dacbd 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -74,6 +74,12 @@ void tdSCellValPrint(SCellVal *pVal, int8_t colType) { printf("NONE "); return; } + if (!pVal->val) { + ASSERT(0); + printf("BadVal "); + return; + } + switch (colType) { case TSDB_DATA_TYPE_BOOL: printf("%s ", (*(int8_t *)pVal->val) == 0 ? "false" : "true"); @@ -678,6 +684,10 @@ int32_t tdAppendColValToRow(SRowBuilder *pBuilder, col_id_t colId, int8_t colTyp } // TS KEY is stored in STSRow.ts and not included in STSRow.data field. if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) { + if (!val) { + terrno = TSDB_CODE_INVALID_PARA; + return terrno; + } TD_ROW_KEY(pRow) = *(TSKEY *)val; // The primary TS key is Norm all the time, thus its valType is not stored in bitmap. return TSDB_CODE_SUCCESS; @@ -1055,8 +1065,8 @@ void tdSTSRowIterInit(STSRowIter *pIter, STSchema *pSchema) { void tTSRowGetVal(STSRow *pRow, STSchema *pTSchema, int16_t iCol, SColVal *pColVal) { STColumn *pTColumn = &pTSchema->columns[iCol]; - SCellVal cv; - SValue value; + SCellVal cv = {0}; + SValue value = {0}; ASSERT((pTColumn->colId == PRIMARYKEY_TIMESTAMP_COL_ID) || (iCol > 0)); @@ -1073,13 +1083,15 @@ void tTSRowGetVal(STSRow *pRow, STSchema *pTSchema, int16_t iCol, SColVal *pColV } else if (tdValTypeIsNull(cv.valType)) { *pColVal = COL_VAL_NULL(pTColumn->colId, pTColumn->type); } else { + pColVal->cid = pTColumn->colId; + pColVal->type = pTColumn->type; + pColVal->flag = CV_FLAG_VALUE; + if (IS_VAR_DATA_TYPE(pTColumn->type)) { - value.nData = varDataLen(cv.val); - value.pData = varDataVal(cv.val); + pColVal->value.nData = varDataLen(cv.val); + pColVal->value.pData = varDataVal(cv.val); } else { - tGetValue(cv.val, &value, pTColumn->type); + memcpy(&pColVal->value.val, cv.val, tDataTypes[pTColumn->type].bytes); } - - *pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, value); } } \ No newline at end of file diff --git a/source/common/src/ttszip.c b/source/common/src/ttszip.c index fe5c599d533dea63f128a6cf29cc43550b975130..3a6bc097c1ae97c7cfadac1df81b6cfb0897dab3 100644 --- a/source/common/src/ttszip.c +++ b/source/common/src/ttszip.c @@ -31,7 +31,7 @@ static int32_t STSBufUpdateHeader(STSBuf* pTSBuf, STSBufFileHeader* pHeader); */ STSBuf* tsBufCreate(bool autoDelete, int32_t order) { if (!osTempSpaceAvailable()) { - terrno = TSDB_CODE_TSC_NO_DISKSPACE; + terrno = TSDB_CODE_NO_DISKSPACE; // tscError("tmp file created failed since %s", terrstr()); return NULL; } diff --git a/source/dnode/mgmt/CMakeLists.txt b/source/dnode/mgmt/CMakeLists.txt index 423028b1679eb6f663d80dfb0df09fc0e2fe10ec..762b8fd5293e97aae4fb38ca5c021aaa893ff2b8 100644 --- a/source/dnode/mgmt/CMakeLists.txt +++ b/source/dnode/mgmt/CMakeLists.txt @@ -13,4 +13,18 @@ target_include_directories( taosd PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/node_mgmt/inc" ) -target_link_libraries(taosd dnode) + +IF (TD_LINUX_64 AND JEMALLOC_ENABLED) + ADD_DEFINITIONS(-DTD_JEMALLOC_ENABLED -I${CMAKE_BINARY_DIR}/build/include -L${CMAKE_BINARY_DIR}/build/lib -Wl,-rpath,${CMAKE_BINARY_DIR}/build/lib -ljemalloc) + SET(LINK_JEMALLOC "-L${CMAKE_BINARY_DIR}/build/lib -ljemalloc") +ELSE () + SET(LINK_JEMALLOC "") +ENDIF () + +IF (TD_LINUX_64 AND JEMALLOC_ENABLED) + ADD_DEPENDENCIES(taosd jemalloc) + target_link_libraries(taosd dnode ${LINK_JEMALLOC}) +ELSE () + target_link_libraries(taosd dnode) +ENDIF () + diff --git a/source/dnode/mgmt/mgmt_dnode/inc/dmInt.h b/source/dnode/mgmt/mgmt_dnode/inc/dmInt.h index dc4412b77bbe3fd5adac8fb671eef60a1b65acac..c776beb3f099d40173bc69490f7dc65bef67ed71 100644 --- a/source/dnode/mgmt/mgmt_dnode/inc/dmInt.h +++ b/source/dnode/mgmt/mgmt_dnode/inc/dmInt.h @@ -36,6 +36,7 @@ typedef struct SDnodeMgmt { GetVnodeLoadsFp getVnodeLoadsFp; GetMnodeLoadsFp getMnodeLoadsFp; GetQnodeLoadsFp getQnodeLoadsFp; + int32_t statusSeq; } SDnodeMgmt; // dmHandle.c diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index 782c828bb2327dc30587659d5e41fc1eb0f014d7..8a8561161b0057130c5998bba2abe780c4b842f9 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c @@ -32,9 +32,13 @@ static void dmUpdateDnodeCfg(SDnodeMgmt *pMgmt, SDnodeCfg *pCfg) { } static void dmProcessStatusRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) { + const STraceId *trace = &pRsp->info.traceId; + dGTrace("status rsp received from mnode, statusSeq:%d code:0x%x", pMgmt->statusSeq, pRsp->code); + if (pRsp->code != 0) { if (pRsp->code == TSDB_CODE_MND_DNODE_NOT_EXIST && !pMgmt->pData->dropped && pMgmt->pData->dnodeId > 0) { - dInfo("dnode:%d, set to dropped since not exist in mnode", pMgmt->pData->dnodeId); + dGInfo("dnode:%d, set to dropped since not exist in mnode, statusSeq:%d", pMgmt->pData->dnodeId, + pMgmt->statusSeq); pMgmt->pData->dropped = 1; dmWriteEps(pMgmt->pData); } @@ -42,9 +46,9 @@ static void dmProcessStatusRsp(SDnodeMgmt *pMgmt, SRpcMsg *pRsp) { SStatusRsp statusRsp = {0}; if (pRsp->pCont != NULL && pRsp->contLen > 0 && tDeserializeSStatusRsp(pRsp->pCont, pRsp->contLen, &statusRsp) == 0) { - dTrace("status msg received from mnode, dnodeVer:%" PRId64 " saved:%" PRId64, statusRsp.dnodeVer, - pMgmt->pData->dnodeVer); if (pMgmt->pData->dnodeVer != statusRsp.dnodeVer) { + dGInfo("status rsp received from mnode, statusSeq:%d:%d dnodeVer:%" PRId64 ":%" PRId64, pMgmt->statusSeq, + statusRsp.statusSeq, pMgmt->pData->dnodeVer, statusRsp.dnodeVer); pMgmt->pData->dnodeVer = statusRsp.dnodeVer; dmUpdateDnodeCfg(pMgmt, &statusRsp.dnodeCfg); dmUpdateEps(pMgmt->pData, statusRsp.pDnodeEps); @@ -91,6 +95,9 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { (*pMgmt->getQnodeLoadsFp)(&req.qload); + pMgmt->statusSeq++; + req.statusSeq = pMgmt->statusSeq; + int32_t contLen = tSerializeSStatusReq(NULL, 0, &req); void *pHead = rpcMallocCont(contLen); tSerializeSStatusReq(pHead, contLen, &req); @@ -99,13 +106,13 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { SRpcMsg rpcMsg = {.pCont = pHead, .contLen = contLen, .msgType = TDMT_MND_STATUS, .info.ahandle = (void *)0x9527}; SRpcMsg rpcRsp = {0}; - dTrace("send status msg to mnode, dnodeVer:%" PRId64, req.dnodeVer); + dTrace("send status req to mnode, dnodeVer:%" PRId64 " statusSeq:%d", req.dnodeVer, req.statusSeq); SEpSet epSet = {0}; dmGetMnodeEpSet(pMgmt->pData, &epSet); rpcSendRecv(pMgmt->msgCb.clientRpc, &epSet, &rpcMsg, &rpcRsp); if (rpcRsp.code != 0) { - dError("failed to send status msg since %s, numOfEps:%d inUse:%d", tstrerror(rpcRsp.code), epSet.numOfEps, + dError("failed to send status req since %s, numOfEps:%d inUse:%d", tstrerror(rpcRsp.code), epSet.numOfEps, epSet.inUse); for (int32_t i = 0; i < epSet.numOfEps; ++i) { dDebug("index:%d, mnode ep:%s:%u", i, epSet.eps[i].fqdn, epSet.eps[i].port); @@ -300,8 +307,7 @@ int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) { pStart += sizeof(SSysTableSchema); } - int32_t len = 0; - blockEncode(pBlock, pStart, &len, numOfCols, false); + int32_t len = blockEncode(pBlock, pStart, numOfCols); pRsp->numOfRows = htonl(pBlock->info.rows); pRsp->precision = TSDB_TIME_PRECISION_MILLI; // millisecond time precision @@ -332,7 +338,6 @@ SArray *dmGetMsgHandles() { // Requests handled by MNODE if (dmSetMgmtHandle(pArray, TDMT_MND_GRANT, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER; - // if (dmSetMgmtHandle(pArray, TDMT_MND_GRANT_RSP, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_AUTH_RSP, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER; code = 0; diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c index ca8a434d0500ef66febda17855a6eaec0670fe82..07a612bb351e1fe6ed1dc93cb993ebdea42310dc 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c @@ -20,7 +20,7 @@ static void *dmStatusThreadFp(void *param) { SDnodeMgmt *pMgmt = param; int64_t lastTime = taosGetTimestampMs(); setThreadName("dnode-status"); - + while (1) { taosMsleep(200); if (pMgmt->pData->dropped || pMgmt->pData->stopped) break; @@ -28,6 +28,7 @@ static void *dmStatusThreadFp(void *param) { int64_t curTime = taosGetTimestampMs(); float interval = (curTime - lastTime) / 1000.0f; if (interval >= tsStatusInterval) { + taosMemoryTrim(0); dmSendStatusReq(pMgmt); lastTime = curTime; } diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c index 89b68febd515e86df269ed14bdbe51dae7b3a37a..ec4f42c847b5cc7099ec4a1b2388e0a313b9e3b0 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c @@ -91,7 +91,7 @@ SArray *mmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_SNODE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_VNODE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_DND_DROP_VNODE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_DND_CONFIG_DNODE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_DND_CONFIG_DNODE_RSP, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_CONNECT, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_ACCT, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; @@ -102,7 +102,7 @@ SArray *mmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_USER, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_GET_USER_AUTH, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_DNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_MND_CONFIG_DNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_MND_CONFIG_DNODE, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_DNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_MNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_ALTER_MNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; @@ -116,7 +116,7 @@ SArray *mmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_SNODE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_DB, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_DB, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_MND_USE_DB, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_MND_USE_DB, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_ALTER_DB, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_COMPACT_DB, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_TRIM_DB, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; @@ -124,9 +124,10 @@ SArray *mmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_MND_VGROUP_LIST, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_REDISTRIBUTE_VGROUP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_MERGE_VGROUP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_MND_SPLIT_VGROUP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_BALANCE_VGROUP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_FUNC, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_MND_RETRIEVE_FUNC, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_MND_RETRIEVE_FUNC, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_FUNC, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_STB, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_ALTER_STB, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; @@ -140,19 +141,17 @@ SArray *mmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_STREAM, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_GET_INDEX, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_GET_TABLE_INDEX, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_MND_CREATE_TOPIC, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_MND_ALTER_TOPIC, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_MND_DROP_TOPIC, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_MND_SUBSCRIBE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_MND_MQ_ASK_EP, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_MND_MQ_HB, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_MND_MQ_DROP_CGROUP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_MND_MQ_DROP_CGROUP_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_MND_MQ_COMMIT_OFFSET, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_CREATE_TOPIC, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_DROP_TOPIC, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_SUBSCRIBE, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_ASK_EP, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_HB, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_DROP_CGROUP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_MND_TMQ_DROP_CGROUP_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_KILL_TRANS, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_KILL_QUERY, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_KILL_CONN, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_MND_HEARTBEAT, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_MND_HEARTBEAT, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_STATUS, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_SYSTABLE_RETRIEVE, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_MND_AUTH, mmPutMsgToReadQueue, 0) == NULL) goto _OVER; @@ -170,10 +169,10 @@ SArray *mmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_STB_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_SMA_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_SMA_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_CHANGE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_DELETE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_ADD_CHECK_INFO_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_DELETE_CHECK_INFO_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_SUBSCRIBE_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_DELETE_SUB_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_ADD_CHECKINFO_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_DEL_CHECKINFO_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SCH_DROP_TASK, mmPutMsgToFetchQueue, 1) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DEPLOY_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DROP_RSP, mmPutMsgToWriteQueue, 0) == NULL) goto _OVER; @@ -196,6 +195,8 @@ SArray *mmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_SYNC_APPEND_ENTRIES_REPLY, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_SEND, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_RSP, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_SYNC_PRE_SNAPSHOT, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_SYNC_PRE_SNAPSHOT_REPLY, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT, mmPutMsgToSyncCtrlQueue, 1) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT_REPLY, mmPutMsgToSyncCtrlQueue, 1) == NULL) goto _OVER; diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c index e0a39a6bf18a97f690261335b3d7455e47cb97bc..e50b527bac925c2d9c05f04329d1149b0c7eaafe 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c @@ -67,24 +67,6 @@ static void mmProcessRpcMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) { taosFreeQitem(pMsg); } -static void mmProcessSyncCtrlMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) { - SMnodeMgmt *pMgmt = pInfo->ahandle; - pMsg->info.node = pMgmt->pMnode; - - const STraceId *trace = &pMsg->info.traceId; - dGTrace("msg:%p, get from mnode-sync-ctrl queue", pMsg); - - SMsgHead *pHead = pMsg->pCont; - pHead->contLen = ntohl(pHead->contLen); - pHead->vgId = ntohl(pHead->vgId); - - int32_t code = mndProcessSyncCtrlMsg(pMsg); - - dGTrace("msg:%p, is freed, code:0x%x", pMsg, code); - rpcFreeCont(pMsg->pCont); - taosFreeQitem(pMsg); -} - static void mmProcessSyncMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) { SMnodeMgmt *pMgmt = pInfo->ahandle; pMsg->info.node = pMgmt->pMnode; @@ -252,7 +234,7 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) { .min = 1, .max = 1, .name = "mnode-sync-ctrl", - .fp = (FItem)mmProcessSyncCtrlMsg, + .fp = (FItem)mmProcessSyncMsg, .param = pMgmt, }; if (tSingleWorkerInit(&pMgmt->syncCtrlWorker, &scCfg) != 0) { diff --git a/source/dnode/mgmt/mgmt_snode/inc/smInt.h b/source/dnode/mgmt/mgmt_snode/inc/smInt.h index 4efe1c997b578a3397f1ab0fbcc39b612af123a8..9d519e88f02aaa44cfc5c1804e9c479019975f04 100644 --- a/source/dnode/mgmt/mgmt_snode/inc/smInt.h +++ b/source/dnode/mgmt/mgmt_snode/inc/smInt.h @@ -30,9 +30,9 @@ typedef struct SSnodeMgmt { SMsgCb msgCb; const char *path; const char *name; - int8_t uniqueWorkerInUse; - SArray *uniqueWorkers; // SArray - SSingleWorker sharedWorker; + int8_t writeWorkerInUse; + SArray *writeWroker; // SArray + SSingleWorker streamWorker; } SSnodeMgmt; // smHandle.c @@ -43,13 +43,14 @@ int32_t smProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg); // smWorker.c int32_t smStartWorker(SSnodeMgmt *pMgmt); void smStopWorker(SSnodeMgmt *pMgmt); +int32_t smPutMsgToQueue(SSnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pMsg); int32_t smPutNodeMsgToMgmtQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg); -int32_t smPutNodeMsgToUniqueQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg); -int32_t smPutNodeMsgToSharedQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg); -int32_t smPutNodeMsgToExecQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg); +int32_t smPutNodeMsgToWriteQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg); +int32_t smPutNodeMsgToStreamQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg); +void sndEnqueueStreamDispatch(SSnode *pSnode, SRpcMsg *pMsg); #ifdef __cplusplus } #endif -#endif /*_TD_DND_SNODE_INT_H_*/ \ No newline at end of file +#endif /*_TD_DND_SNODE_INT_H_*/ diff --git a/source/dnode/mgmt/mgmt_snode/src/smHandle.c b/source/dnode/mgmt/mgmt_snode/src/smHandle.c index 65c96767ab33edf6f1ddcb04aa76d276dc17e92f..7ecb6fb208b1153e4495d425587dc840cddf7d5e 100644 --- a/source/dnode/mgmt/mgmt_snode/src/smHandle.c +++ b/source/dnode/mgmt/mgmt_snode/src/smHandle.c @@ -69,13 +69,11 @@ SArray *smGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DEPLOY, smPutNodeMsgToMgmtQueue, 1) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DROP, smPutNodeMsgToMgmtQueue, 1) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RUN, smPutNodeMsgToSharedQueue, 1) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH, smPutNodeMsgToSharedQueue, 1) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH_RSP, smPutNodeMsgToSharedQueue, 1) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER, smPutNodeMsgToSharedQueue, 1) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER_RSP, smPutNodeMsgToSharedQueue, 1) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE, smPutNodeMsgToSharedQueue, 1) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE_RSP, smPutNodeMsgToSharedQueue, 1) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RUN, smPutNodeMsgToStreamQueue, 1) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH, smPutNodeMsgToStreamQueue, 1) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH_RSP, smPutNodeMsgToStreamQueue, 1) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE, smPutNodeMsgToStreamQueue, 1) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE_RSP, smPutNodeMsgToStreamQueue, 1) == NULL) goto _OVER; code = 0; _OVER: diff --git a/source/dnode/mgmt/mgmt_snode/src/smInt.c b/source/dnode/mgmt/mgmt_snode/src/smInt.c index 971a6ac4c78f57b4c19c79e08fbc1190169e4bf9..28097311ac3530788d83c965ed4918d4621effc4 100644 --- a/source/dnode/mgmt/mgmt_snode/src/smInt.c +++ b/source/dnode/mgmt/mgmt_snode/src/smInt.c @@ -45,6 +45,7 @@ int32_t smOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) { pMgmt->name = pInput->name; pMgmt->msgCb = pInput->msgCb; pMgmt->msgCb.mgmt = pMgmt; + pMgmt->msgCb.putToQueueFp = (PutToQueueFp)smPutMsgToQueue; SSnodeOpt option = {0}; smInitOption(pMgmt, &option); diff --git a/source/dnode/mgmt/mgmt_snode/src/smWorker.c b/source/dnode/mgmt/mgmt_snode/src/smWorker.c index ad56d57f69472f5101c7149118fbb95c4a05b5f2..1381d4c39180866e26f57a5b2462f1b00aa3d063 100644 --- a/source/dnode/mgmt/mgmt_snode/src/smWorker.c +++ b/source/dnode/mgmt/mgmt_snode/src/smWorker.c @@ -26,18 +26,24 @@ static inline void smSendRsp(SRpcMsg *pMsg, int32_t code) { tmsgSendRsp(&rsp); } -static void smProcessUniqueQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { +static void smProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { SSnodeMgmt *pMgmt = pInfo->ahandle; for (int32_t i = 0; i < numOfMsgs; i++) { SRpcMsg *pMsg = NULL; taosGetQitem(qall, (void **)&pMsg); - - dTrace("msg:%p, get from snode-unique queue", pMsg); - if (sndProcessUMsg(pMgmt->pSnode, pMsg) < 0) { - ASSERT(0); + const STraceId *trace = &pMsg->info.traceId; + + dTrace("msg:%p, get from snode-write queue", pMsg); + int32_t code = sndProcessWriteMsg(pMgmt->pSnode, pMsg, NULL); + if (code < 0) { + dGError("snd, msg:%p failed to process write since %s", pMsg, terrstr(code)); + if (pMsg->info.handle != NULL) { + tmsgSendRsp(pMsg); + } + } else { + smSendRsp(pMsg, 0); } - smSendRsp(pMsg, 0); dTrace("msg:%p, is freed", pMsg); rpcFreeCont(pMsg->pCont); @@ -45,13 +51,19 @@ static void smProcessUniqueQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t num } } -static void smProcessSharedQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { - SSnodeMgmt *pMgmt = pInfo->ahandle; - - dTrace("msg:%p, get from snode-shared queue", pMsg); - if (sndProcessSMsg(pMgmt->pSnode, pMsg) < 0) { +static void smProcessStreamQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { + SSnodeMgmt *pMgmt = pInfo->ahandle; + const STraceId *trace = &pMsg->info.traceId; + + dTrace("msg:%p, get from snode-stream queue", pMsg); + int32_t code = sndProcessStreamMsg(pMgmt->pSnode, pMsg); + if (code < 0) { + if (pMsg) { + dGError("snd, msg:%p failed to process stream msg %s since %s", pMsg, TMSG_INFO(pMsg->msgType), terrstr(code)); + } else { + dGError("snd, msg:%p failed to process stream empty msg since %s", pMsg, terrstr(code)); + } smSendRsp(pMsg, terrno); - ASSERT(0); } dTrace("msg:%p, is freed", pMsg); @@ -60,44 +72,44 @@ static void smProcessSharedQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { } int32_t smStartWorker(SSnodeMgmt *pMgmt) { - pMgmt->uniqueWorkers = taosArrayInit(0, sizeof(SMultiWorker *)); - if (pMgmt->uniqueWorkers == NULL) { + pMgmt->writeWroker = taosArrayInit(0, sizeof(SMultiWorker *)); + if (pMgmt->writeWroker == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - for (int32_t i = 0; i < tsNumOfSnodeUniqueThreads; i++) { - SMultiWorker *pUniqueWorker = taosMemoryMalloc(sizeof(SMultiWorker)); - if (pUniqueWorker == NULL) { + for (int32_t i = 0; i < tsNumOfSnodeWriteThreads; i++) { + SMultiWorker *pWriteWorker = taosMemoryMalloc(sizeof(SMultiWorker)); + if (pWriteWorker == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } SMultiWorkerCfg cfg = { .max = 1, - .name = "snode-unique", - .fp = smProcessUniqueQueue, + .name = "snode-write", + .fp = smProcessWriteQueue, .param = pMgmt, }; - if (tMultiWorkerInit(pUniqueWorker, &cfg) != 0) { + if (tMultiWorkerInit(pWriteWorker, &cfg) != 0) { dError("failed to start snode-unique worker since %s", terrstr()); return -1; } - if (taosArrayPush(pMgmt->uniqueWorkers, &pUniqueWorker) == NULL) { + if (taosArrayPush(pMgmt->writeWroker, &pWriteWorker) == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } } SSingleWorkerCfg cfg = { - .min = tsNumOfSnodeSharedThreads, - .max = tsNumOfSnodeSharedThreads, - .name = "snode-shared", - .fp = (FItem)smProcessSharedQueue, + .min = tsNumOfSnodeStreamThreads, + .max = tsNumOfSnodeStreamThreads, + .name = "snode-stream", + .fp = (FItem)smProcessStreamQueue, .param = pMgmt, }; - if (tSingleWorkerInit(&pMgmt->sharedWorker, &cfg)) { + if (tSingleWorkerInit(&pMgmt->streamWorker, &cfg)) { dError("failed to start snode shared-worker since %s", terrstr()); return -1; } @@ -107,30 +119,53 @@ int32_t smStartWorker(SSnodeMgmt *pMgmt) { } void smStopWorker(SSnodeMgmt *pMgmt) { - for (int32_t i = 0; i < taosArrayGetSize(pMgmt->uniqueWorkers); i++) { - SMultiWorker *pWorker = taosArrayGetP(pMgmt->uniqueWorkers, i); + for (int32_t i = 0; i < taosArrayGetSize(pMgmt->writeWroker); i++) { + SMultiWorker *pWorker = taosArrayGetP(pMgmt->writeWroker, i); tMultiWorkerCleanup(pWorker); } - taosArrayDestroy(pMgmt->uniqueWorkers); - tSingleWorkerCleanup(&pMgmt->sharedWorker); + taosArrayDestroy(pMgmt->writeWroker); + tSingleWorkerCleanup(&pMgmt->streamWorker); dDebug("snode workers are closed"); } -static FORCE_INLINE int32_t smGetSWIdFromMsg(SRpcMsg *pMsg) { - SMsgHead *pHead = pMsg->pCont; - pHead->vgId = htonl(pHead->vgId); - return pHead->vgId % tsNumOfSnodeUniqueThreads; -} +int32_t smPutMsgToQueue(SSnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) { + SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM); + if (pMsg == NULL) { + rpcFreeCont(pRpc->pCont); + pRpc->pCont = NULL; + return -1; + } -static FORCE_INLINE int32_t smGetSWTypeFromMsg(SRpcMsg *pMsg) { - /*SMsgHead *pHead = pMsg->pCont;*/ - /*pHead->workerType = htonl(pHead->workerType);*/ - /*return pHead->workerType;*/ + SSnode *pSnode = pMgmt->pSnode; + if (pSnode == NULL) { + dError("snode: msg:%p failed to put into vnode queue since %s, type:%s qtype:%d", pMsg, terrstr(), + TMSG_INFO(pMsg->msgType), qtype); + taosFreeQitem(pMsg); + rpcFreeCont(pRpc->pCont); + pRpc->pCont = NULL; + return -1; + } + + SMsgHead *pHead = pRpc->pCont; + pHead->contLen = htonl(pHead->contLen); + pHead->vgId = SNODE_HANDLE; + memcpy(pMsg, pRpc, sizeof(SRpcMsg)); + + switch (qtype) { + case STREAM_QUEUE: + smPutNodeMsgToStreamQueue(pMgmt, pMsg); + break; + case WRITE_QUEUE: + smPutNodeMsgToWriteQueue(pMgmt, pMsg); + break; + default: + ASSERT(0); + } return 0; } int32_t smPutNodeMsgToMgmtQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) { - SMultiWorker *pWorker = taosArrayGetP(pMgmt->uniqueWorkers, 0); + SMultiWorker *pWorker = taosArrayGetP(pMgmt->writeWroker, 0); if (pWorker == NULL) { terrno = TSDB_CODE_INVALID_MSG; return -1; @@ -141,9 +176,8 @@ int32_t smPutNodeMsgToMgmtQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) { return 0; } -int32_t smPutNodeMsgToUniqueQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) { - int32_t index = smGetSWIdFromMsg(pMsg); - SMultiWorker *pWorker = taosArrayGetP(pMgmt->uniqueWorkers, index); +int32_t smPutNodeMsgToWriteQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) { + SMultiWorker *pWorker = taosArrayGetP(pMgmt->writeWroker, 0); if (pWorker == NULL) { terrno = TSDB_CODE_INVALID_MSG; return -1; @@ -154,19 +188,14 @@ int32_t smPutNodeMsgToUniqueQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) { return 0; } -int32_t smPutNodeMsgToSharedQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) { - SSingleWorker *pWorker = &pMgmt->sharedWorker; +int32_t smPutNodeMsgToStreamQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) { + SSingleWorker *pWorker = &pMgmt->streamWorker; dTrace("msg:%p, put into worker %s", pMsg, pWorker->name); - taosWriteQitem(pWorker->queue, pMsg); - return 0; -} - -int32_t smPutNodeMsgToExecQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) { - int32_t workerType = smGetSWTypeFromMsg(pMsg); - if (workerType == SND_WORKER_TYPE__SHARED) { - return smPutNodeMsgToSharedQueue(pMgmt, pMsg); + if (pMsg->msgType == TDMT_STREAM_TASK_DISPATCH) { + sndEnqueueStreamDispatch(pMgmt->pSnode, pMsg); } else { - return smPutNodeMsgToUniqueQueue(pMgmt, pMsg); + taosWriteQitem(pWorker->queue, pMsg); } + return 0; } diff --git a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h index bf1ccc1a7b6abf167515ed91fff82b612e1d64c4..b38dc19361a0bedf9cf1f22b34d3fc074e1172b4 100644 --- a/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h +++ b/source/dnode/mgmt/mgmt_vnode/inc/vmInt.h @@ -33,10 +33,6 @@ typedef struct SVnodeMgmt { SQWorkerPool queryPool; SQWorkerPool streamPool; SWWorkerPool fetchPool; - SWWorkerPool syncPool; - SWWorkerPool syncCtrlPool; - SWWorkerPool writePool; - SWWorkerPool applyPool; SSingleWorker mgmtWorker; SHashObj *hash; TdThreadRwlock lock; @@ -52,19 +48,19 @@ typedef struct { } SWrapperCfg; typedef struct { - int32_t vgId; - int32_t vgVersion; - int32_t refCount; - int8_t dropped; - char *path; - SVnode *pImpl; - STaosQueue *pWriteQ; - STaosQueue *pSyncQ; - STaosQueue *pSyncCtrlQ; - STaosQueue *pApplyQ; - STaosQueue *pQueryQ; - STaosQueue *pStreamQ; - STaosQueue *pFetchQ; + int32_t vgId; + int32_t vgVersion; + int32_t refCount; + int8_t dropped; + char *path; + SVnode *pImpl; + SMultiWorker pWriteW; + SMultiWorker pSyncW; + SMultiWorker pSyncCtrlW; + SMultiWorker pApplyW; + STaosQueue *pQueryQ; + STaosQueue *pStreamQ; + STaosQueue *pFetchQ; } SVnodeObj; typedef struct { diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index d682fa9cc58339e6e8d9a926a50e08d2cd9d42d2..2265f58060ccdad0a94ce238528c3806ef1a1892 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -191,6 +191,16 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { dInfo("vgId:%d, replica:%d id:%d fqdn:%s port:%u", req.vgId, i, req.replicas[i].id, req.replicas[i].fqdn, req.replicas[i].port); } + + SReplica *pReplica = &req.replicas[req.selfIndex]; + if (pReplica->id != pMgmt->pData->dnodeId || pReplica->port != tsServerPort || + strcmp(pReplica->fqdn, tsLocalFqdn) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + dError("vgId:%d, dnodeId:%d ep:%s:%u not matched with local dnode", req.vgId, pReplica->id, pReplica->fqdn, + pReplica->port); + return -1; + } + vmGenerateVnodeCfg(&req, &vnodeCfg); if (vmTsmaAdjustDays(&vnodeCfg, &req) < 0) { @@ -285,6 +295,15 @@ int32_t vmProcessAlterVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return -1; } + SReplica *pReplica = &alterReq.replicas[alterReq.selfIndex]; + if (pReplica->id != pMgmt->pData->dnodeId || pReplica->port != tsServerPort || + strcmp(pReplica->fqdn, tsLocalFqdn) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + dError("vgId:%d, dnodeId:%d ep:%s:%u not matched with local dnode", alterReq.vgId, pReplica->id, pReplica->fqdn, + pReplica->port); + return -1; + } + SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId); if (pVnode == NULL) { dError("vgId:%d, failed to alter replica since %s", vgId, terrstr()); @@ -341,6 +360,12 @@ int32_t vmProcessDropVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { int32_t vgId = dropReq.vgId; dDebug("vgId:%d, start to drop vnode", vgId); + if (dropReq.dnodeId != pMgmt->pData->dnodeId) { + terrno = TSDB_CODE_INVALID_MSG; + dError("vgId:%d, dnodeId:%d not matched with local dnode", dropReq.vgId, dropReq.dnodeId); + return -1; + } + SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId); if (pVnode == NULL) { dDebug("vgId:%d, failed to drop since %s", vgId, terrstr()); @@ -392,27 +417,28 @@ SArray *vmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_VND_CANCEL_SMA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_SMA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_SUBMIT_RSMA, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_CHANGE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_VG_DELETE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_MQ_COMMIT_OFFSET, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_ADD_CHECK_INFO, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_DELETE_CHECK_INFO, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_CONSUME, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_SUBSCRIBE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_DELETE_SUB, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_COMMIT_OFFSET, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_ADD_CHECKINFO, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_DEL_CHECKINFO, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_TMQ_CONSUME, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_DELETE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_BATCH_DEL, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_COMMIT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SCH_QUERY_HEARTBEAT, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_VND_STREAM_TRIGGER, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DROP, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DEPLOY, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RUN, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DISPATCH_RSP, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER; - if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_RECOVER_RSP, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_RETRIEVE_RSP, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_RECOVER_FINISH, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_CHECK, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_CHECK_RSP, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_STREAM_TRIGGER, vmPutMsgToStreamQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_REPLICA, vmPutMsgToMgmtQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_CONFIG, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; @@ -436,6 +462,9 @@ SArray *vmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_SYNC_APPEND_ENTRIES_REPLY, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_SEND, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_RSP, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_SYNC_PRE_SNAPSHOT, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_SYNC_PRE_SNAPSHOT_REPLY, vmPutMsgToSyncQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT, vmPutMsgToSyncCtrlQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT_REPLY, vmPutMsgToSyncCtrlQueue, 0) == NULL) goto _OVER; diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c index f36604eb27a299822bb57d578256a1b590762ba0..07ebd72379e29d26d2ebbe830f0df9c8458aa969 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c @@ -79,29 +79,49 @@ int32_t vmOpenVnode(SVnodeMgmt *pMgmt, SWrapperCfg *pCfg, SVnode *pImpl) { void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { char path[TSDB_FILENAME_LEN] = {0}; - vnodePreClose(pVnode->pImpl); - taosThreadRwlockWrlock(&pMgmt->lock); taosHashRemove(pMgmt->hash, &pVnode->vgId, sizeof(int32_t)); taosThreadRwlockUnlock(&pMgmt->lock); vmReleaseVnode(pMgmt, pVnode); - dTrace("vgId:%d, wait for vnode ref become 0", pVnode->vgId); + dInfo("vgId:%d, pre close", pVnode->vgId); + vnodePreClose(pVnode->pImpl); + + dInfo("vgId:%d, wait for vnode ref become 0", pVnode->vgId); while (pVnode->refCount > 0) taosMsleep(10); - dTrace("vgId:%d, wait for vnode queue is empty", pVnode->vgId); - while (!taosQueueEmpty(pVnode->pWriteQ)) taosMsleep(10); - while (!taosQueueEmpty(pVnode->pSyncQ)) taosMsleep(10); - while (!taosQueueEmpty(pVnode->pApplyQ)) taosMsleep(10); + dInfo("vgId:%d, wait for vnode write queue:%p is empty, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue, + pVnode->pWriteW.queue->threadId); + tMultiWorkerCleanup(&pVnode->pWriteW); + + dInfo("vgId:%d, wait for vnode sync queue:%p is empty, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue, + pVnode->pSyncW.queue->threadId); + tMultiWorkerCleanup(&pVnode->pSyncW); + + dInfo("vgId:%d, wait for vnode sync ctrl queue:%p is empty, thread:%08" PRId64, pVnode->vgId, + pVnode->pSyncCtrlW.queue, pVnode->pSyncCtrlW.queue->threadId); + tMultiWorkerCleanup(&pVnode->pSyncCtrlW); + + dInfo("vgId:%d, wait for vnode apply queue:%p is empty, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue, + pVnode->pApplyW.queue->threadId); + tMultiWorkerCleanup(&pVnode->pApplyW); + + dInfo("vgId:%d, wait for vnode query queue:%p is empty", pVnode->vgId, pVnode->pQueryQ); while (!taosQueueEmpty(pVnode->pQueryQ)) taosMsleep(10); + + dInfo("vgId:%d, wait for vnode fetch queue:%p is empty, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ, + pVnode->pFetchQ->threadId); while (!taosQueueEmpty(pVnode->pFetchQ)) taosMsleep(10); + + dInfo("vgId:%d, wait for vnode stream queue:%p is empty", pVnode->vgId, pVnode->pStreamQ); while (!taosQueueEmpty(pVnode->pStreamQ)) taosMsleep(10); - dTrace("vgId:%d, vnode queue is empty", pVnode->vgId); + + dInfo("vgId:%d, all vnode queues is empty", pVnode->vgId); vmFreeQueue(pMgmt, pVnode); vnodeClose(pVnode->pImpl); pVnode->pImpl = NULL; - dDebug("vgId:%d, vnode is closed", pVnode->vgId); + dInfo("vgId:%d, vnode is closed", pVnode->vgId); if (pVnode->dropped) { dInfo("vgId:%d, vnode is destroyed, dropped:%d", pVnode->vgId, pVnode->dropped); diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c index d5b1e18c7b63050b7fad1ccf820481c80520e747..17bc1526b5fd6e95df1b83f6aad3c31106339fd1 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c @@ -86,7 +86,12 @@ static void vmProcessStreamQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { int32_t code = vnodeProcessFetchMsg(pVnode->pImpl, pMsg, pInfo); if (code != 0) { if (terrno != 0) code = terrno; - dGError("vgId:%d, msg:%p failed to process stream since %s", pVnode->vgId, pMsg, terrstr(code)); + if (pMsg) { + dGError("vgId:%d, msg:%p failed to process stream msg %s since %s", pVnode->vgId, pMsg, TMSG_INFO(pMsg->msgType), + terrstr(code)); + } else { + dGError("vgId:%d, msg:%p failed to process stream empty msg since %s", pVnode->vgId, pMsg, terrstr(code)); + } vmSendRsp(pMsg, code); } @@ -133,22 +138,6 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf } } -static void vmProcessSyncCtrlQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { - SVnodeObj *pVnode = pInfo->ahandle; - SRpcMsg *pMsg = NULL; - - for (int32_t i = 0; i < numOfMsgs; ++i) { - if (taosGetQitem(qall, (void **)&pMsg) == 0) continue; - const STraceId *trace = &pMsg->info.traceId; - dGTrace("vgId:%d, msg:%p get from vnode-sync queue", pVnode->vgId, pMsg); - - int32_t code = vnodeProcessSyncCtrlMsg(pVnode->pImpl, pMsg, NULL); // no response here - dGTrace("vgId:%d, msg:%p is freed, code:0x%x", pVnode->vgId, pMsg, code); - rpcFreeCont(pMsg->pCont); - taosFreeQitem(pMsg); - } -} - static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) { const STraceId *trace = &pMsg->info.traceId; SMsgHead *pHead = pMsg->pCont; @@ -166,12 +155,10 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp switch (qtype) { case QUERY_QUEUE: - if ((pMsg->msgType == TDMT_SCH_QUERY) && (grantCheck(TSDB_GRANT_TIME) != TSDB_CODE_SUCCESS)) { - terrno = TSDB_CODE_GRANT_EXPIRED; - code = terrno; - dDebug("vgId:%d, msg:%p put into vnode-query queue failed since %s", pVnode->vgId, pMsg, terrstr(code)); + code = vnodePreprocessQueryMsg(pVnode->pImpl, pMsg); + if (code) { + dError("vgId:%d, msg:%p preprocess query msg failed since %s", pVnode->vgId, pMsg, terrstr(code)); } else { - vnodePreprocessQueryMsg(pVnode->pImpl, pMsg); dGTrace("vgId:%d, msg:%p put into vnode-query queue", pVnode->vgId, pMsg); taosWriteQitem(pVnode->pQueryQ, pMsg); } @@ -190,7 +177,7 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp break; case WRITE_QUEUE: if (!osDataSpaceAvailable()) { - terrno = TSDB_CODE_VND_NO_DISKSPACE; + terrno = TSDB_CODE_NO_DISKSPACE; code = terrno; dError("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, terrstr(code)); } else if ((pMsg->msgType == TDMT_VND_SUBMIT) && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) { @@ -199,30 +186,20 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp dDebug("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, terrstr(code)); } else { dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg); - taosWriteQitem(pVnode->pWriteQ, pMsg); -#if 0 // tests for batch writes - if (pMsg->msgType == TDMT_VND_CREATE_TABLE) { - SRpcMsg *pDup = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM); - memcpy(pDup, pMsg, sizeof(SRpcMsg)); - pDup->pCont = rpcMallocCont(pMsg->contLen); - memcpy(pDup->pCont, pMsg->pCont, pMsg->contLen); - pDup->info.handle = NULL; - taosWriteQitem(pVnode->pWriteQ, pDup); - } -#endif + taosWriteQitem(pVnode->pWriteW.queue, pMsg); } break; case SYNC_QUEUE: dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg); - taosWriteQitem(pVnode->pSyncQ, pMsg); + taosWriteQitem(pVnode->pSyncW.queue, pMsg); break; case SYNC_CTRL_QUEUE: dGTrace("vgId:%d, msg:%p put into vnode-sync-ctrl queue", pVnode->vgId, pMsg); - taosWriteQitem(pVnode->pSyncCtrlQ, pMsg); + taosWriteQitem(pVnode->pSyncCtrlW.queue, pMsg); break; case APPLY_QUEUE: dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg); - taosWriteQitem(pVnode->pApplyQ, pMsg); + taosWriteQitem(pVnode->pApplyW.queue, pMsg); break; default: code = -1; @@ -234,7 +211,9 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp return code; } -int32_t vmPutMsgToSyncCtrlQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_CTRL_QUEUE); } +int32_t vmPutMsgToSyncCtrlQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { + return vmPutMsgToQueue(pMgmt, pMsg, SYNC_CTRL_QUEUE); +} int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); } @@ -285,13 +264,13 @@ int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) { if (pVnode != NULL) { switch (qtype) { case WRITE_QUEUE: - size = taosQueueItemSize(pVnode->pWriteQ); + size = taosQueueItemSize(pVnode->pWriteW.queue); break; case SYNC_QUEUE: - size = taosQueueItemSize(pVnode->pSyncQ); + size = taosQueueItemSize(pVnode->pSyncW.queue); break; case APPLY_QUEUE: - size = taosQueueItemSize(pVnode->pApplyQ); + size = taosQueueItemSize(pVnode->pApplyW.queue); break; case QUERY_QUEUE: size = taosQueueItemSize(pVnode->pQueryQ); @@ -315,40 +294,44 @@ int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) { } int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { - pVnode->pWriteQ = tWWorkerAllocQueue(&pMgmt->writePool, pVnode->pImpl, (FItems)vnodeProposeWriteMsg); - pVnode->pSyncQ = tWWorkerAllocQueue(&pMgmt->syncPool, pVnode, (FItems)vmProcessSyncQueue); - pVnode->pSyncCtrlQ = tWWorkerAllocQueue(&pMgmt->syncCtrlPool, pVnode, (FItems)vmProcessSyncCtrlQueue); - pVnode->pApplyQ = tWWorkerAllocQueue(&pMgmt->applyPool, pVnode->pImpl, (FItems)vnodeApplyWriteMsg); + SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl}; + SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode}; + SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-ctrl", .fp = (FItems)vmProcessSyncQueue, .param = pVnode}; + SMultiWorkerCfg acfg = {.max = 1, .name = "vnode-apply", .fp = (FItems)vnodeApplyWriteMsg, .param = pVnode->pImpl}; + (void)tMultiWorkerInit(&pVnode->pWriteW, &wcfg); + (void)tMultiWorkerInit(&pVnode->pSyncW, &scfg); + (void)tMultiWorkerInit(&pVnode->pSyncCtrlW, &sccfg); + (void)tMultiWorkerInit(&pVnode->pApplyW, &acfg); + pVnode->pQueryQ = tQWorkerAllocQueue(&pMgmt->queryPool, pVnode, (FItem)vmProcessQueryQueue); pVnode->pStreamQ = tQWorkerAllocQueue(&pMgmt->streamPool, pVnode, (FItem)vmProcessStreamQueue); pVnode->pFetchQ = tWWorkerAllocQueue(&pMgmt->fetchPool, pVnode, (FItems)vmProcessFetchQueue); - if (pVnode->pWriteQ == NULL || pVnode->pSyncQ == NULL || pVnode->pApplyQ == NULL || pVnode->pQueryQ == NULL || - pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL) { + if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncCtrlW.queue == NULL || + pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - dDebug("vgId:%d, write-queue:%p is alloced", pVnode->vgId, pVnode->pWriteQ); - dDebug("vgId:%d, sync-queue:%p is alloced", pVnode->vgId, pVnode->pSyncQ); - dDebug("vgId:%d, apply-queue:%p is alloced", pVnode->vgId, pVnode->pApplyQ); - dDebug("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ); - dDebug("vgId:%d, stream-queue:%p is alloced", pVnode->vgId, pVnode->pStreamQ); - dDebug("vgId:%d, fetch-queue:%p is alloced", pVnode->vgId, pVnode->pFetchQ); + dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue, + pVnode->pWriteW.queue->threadId); + dInfo("vgId:%d, sync-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncW.queue, + pVnode->pSyncW.queue->threadId); + dInfo("vgId:%d, sync-ctrl-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pSyncCtrlW.queue, + pVnode->pSyncCtrlW.queue->threadId); + dInfo("vgId:%d, apply-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pApplyW.queue, + pVnode->pApplyW.queue->threadId); + dInfo("vgId:%d, query-queue:%p is alloced", pVnode->vgId, pVnode->pQueryQ); + dInfo("vgId:%d, fetch-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pFetchQ, + pVnode->pFetchQ->threadId); + dInfo("vgId:%d, stream-queue:%p is alloced", pVnode->vgId, pVnode->pStreamQ); return 0; } void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { - tWWorkerFreeQueue(&pMgmt->writePool, pVnode->pWriteQ); - tWWorkerFreeQueue(&pMgmt->applyPool, pVnode->pApplyQ); - tWWorkerFreeQueue(&pMgmt->syncPool, pVnode->pSyncQ); - tWWorkerFreeQueue(&pMgmt->syncCtrlPool, pVnode->pSyncCtrlQ); tQWorkerFreeQueue(&pMgmt->queryPool, pVnode->pQueryQ); tQWorkerFreeQueue(&pMgmt->streamPool, pVnode->pStreamQ); tWWorkerFreeQueue(&pMgmt->fetchPool, pVnode->pFetchQ); - pVnode->pWriteQ = NULL; - pVnode->pSyncQ = NULL; - pVnode->pApplyQ = NULL; pVnode->pQueryQ = NULL; pVnode->pStreamQ = NULL; pVnode->pFetchQ = NULL; @@ -373,26 +356,6 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) { pFPool->max = tsNumOfVnodeFetchThreads; if (tWWorkerInit(pFPool) != 0) return -1; - SWWorkerPool *pWPool = &pMgmt->writePool; - pWPool->name = "vnode-write"; - pWPool->max = tsNumOfVnodeWriteThreads; - if (tWWorkerInit(pWPool) != 0) return -1; - - SWWorkerPool *pAPool = &pMgmt->applyPool; - pAPool->name = "vnode-apply"; - pAPool->max = tsNumOfVnodeWriteThreads; - if (tWWorkerInit(pAPool) != 0) return -1; - - SWWorkerPool *pSPool = &pMgmt->syncPool; - pSPool->name = "vnode-sync"; - pSPool->max = tsNumOfVnodeSyncThreads; - if (tWWorkerInit(pSPool) != 0) return -1; - - SWWorkerPool *pSCPool = &pMgmt->syncCtrlPool; - pSCPool->name = "vnode-sync-ctrl"; - pSCPool->max = tsNumOfVnodeSyncThreads; - if (tWWorkerInit(pSCPool) != 0) return -1; - SSingleWorkerCfg mgmtCfg = { .min = 1, .max = 1, @@ -407,10 +370,6 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) { } void vmStopWorker(SVnodeMgmt *pMgmt) { - tWWorkerCleanup(&pMgmt->writePool); - tWWorkerCleanup(&pMgmt->applyPool); - tWWorkerCleanup(&pMgmt->syncPool); - tWWorkerCleanup(&pMgmt->syncCtrlPool); tQWorkerCleanup(&pMgmt->queryPool); tQWorkerCleanup(&pMgmt->streamPool); tWWorkerCleanup(&pMgmt->fetchPool); diff --git a/source/dnode/mgmt/node_mgmt/src/dmEnv.c b/source/dnode/mgmt/node_mgmt/src/dmEnv.c index a222ad3f7da738c8f2f9a84ac4f9463ae309b5d5..421d723202b0f7fb9824cab2fa0a568f4cf38e69 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmEnv.c +++ b/source/dnode/mgmt/node_mgmt/src/dmEnv.c @@ -71,17 +71,17 @@ static bool dmCheckDiskSpace() { bool ret = true; if (!osDataSpaceAvailable()) { dError("data disk space unavailable, i.e. %s", tsDataDir); - terrno = TSDB_CODE_VND_NO_DISKSPACE; + terrno = TSDB_CODE_NO_DISKSPACE; ret = false; } if (!osLogSpaceAvailable()) { dError("log disk space unavailable, i.e. %s", tsLogDir); - terrno = TSDB_CODE_VND_NO_DISKSPACE; + terrno = TSDB_CODE_NO_DISKSPACE; ret = false; } if (!osTempSpaceAvailable()) { dError("temp disk space unavailable, i.e. %s", tsTempDir); - terrno = TSDB_CODE_VND_NO_DISKSPACE; + terrno = TSDB_CODE_NO_DISKSPACE; ret = false; } return ret; diff --git a/source/dnode/mgmt/node_mgmt/src/dmTransport.c b/source/dnode/mgmt/node_mgmt/src/dmTransport.c index 7ad24be258ee23b547543f0296cc27ea281ee89f..1e5f3139aa7ee86b3ff68efc3742c90f008a2c3b 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmTransport.c +++ b/source/dnode/mgmt/node_mgmt/src/dmTransport.c @@ -105,6 +105,7 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) { } if (IsReq(pRpc) && pRpc->pCont == NULL) { + dGError("msg:%p, type:%s pCont is NULL", pRpc, TMSG_INFO(pRpc->msgType)); terrno = TSDB_CODE_INVALID_MSG_LEN; goto _OVER; } @@ -133,6 +134,7 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) { break; } } else { + dGError("msg:%p, type:%s contLen is 0", pRpc, TMSG_INFO(pRpc->msgType)); terrno = TSDB_CODE_INVALID_MSG_LEN; goto _OVER; } @@ -155,7 +157,11 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) { _OVER: if (code != 0) { if (terrno != 0) code = terrno; - dGTrace("msg:%p, failed to process since %s", pMsg, terrstr()); + if (pMsg) { + dGTrace("msg:%p, failed to process %s since %s", pMsg, TMSG_INFO(pMsg->msgType), terrstr()); + } else { + dGTrace("msg:%p, failed to process empty msg since %s", pMsg, terrstr()); + } if (IsReq(pRpc)) { SRpcMsg rsp = {.code = code, .info = pRpc->info}; diff --git a/source/dnode/mgmt/node_util/src/dmUtil.c b/source/dnode/mgmt/node_util/src/dmUtil.c index 80bb8debd28db2a6f15fbeb243702b267dd38676..648a9ab9ce030ad045630bed7942471a678bf911 100644 --- a/source/dnode/mgmt/node_util/src/dmUtil.c +++ b/source/dnode/mgmt/node_util/src/dmUtil.c @@ -55,7 +55,7 @@ void *dmSetMgmtHandle(SArray *pArray, tmsg_t msgType, void *nodeMsgFp, bool need } void dmGetMonitorSystemInfo(SMonSysInfo *pInfo) { - taosGetCpuUsage(&pInfo->cpu_engine, &pInfo->cpu_system); + taosGetCpuUsage(&pInfo->cpu_system, &pInfo->cpu_engine); taosGetCpuCores(&pInfo->cpu_cores); taosGetProcMemory(&pInfo->mem_engine); taosGetSysMemory(&pInfo->mem_system); diff --git a/source/dnode/mgmt/test/sut/inc/server.h b/source/dnode/mgmt/test/sut/inc/server.h index 69581e52e281d3b8627884153551b21dd2648330..7343276210499ff713cef24b29c36e98b1f00809 100644 --- a/source/dnode/mgmt/test/sut/inc/server.h +++ b/source/dnode/mgmt/test/sut/inc/server.h @@ -20,7 +20,8 @@ class TestServer { public: bool Start(); void Stop(); - +bool runnning; + private: TdThread threadId; }; diff --git a/source/dnode/mgmt/test/sut/src/server.cpp b/source/dnode/mgmt/test/sut/src/server.cpp index 98c59a1614303c4c8a342d1d63ab39e9116214fd..81e6dcf4959df1835f64203547e7d5580c82a6fb 100644 --- a/source/dnode/mgmt/test/sut/src/server.cpp +++ b/source/dnode/mgmt/test/sut/src/server.cpp @@ -16,8 +16,18 @@ #include "sut.h" void* serverLoop(void* param) { - dmInit(); - dmRun(); + TestServer* server = (TestServer*)param; + server->runnning = false; + + if (dmInit() != 0) { + return NULL; + } + + server->runnning = true; + if (dmRun() != 0) { + return NULL; + } + dmCleanup(); return NULL; } @@ -26,10 +36,10 @@ bool TestServer::Start() { TdThreadAttr thAttr; taosThreadAttrInit(&thAttr); taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); - taosThreadCreate(&threadId, &thAttr, serverLoop, NULL); + taosThreadCreate(&threadId, &thAttr, serverLoop, this); taosThreadAttrDestroy(&thAttr); taosMsleep(2100); - return true; + return runnning; } void TestServer::Stop() { diff --git a/source/dnode/mgmt/test/sut/src/sut.cpp b/source/dnode/mgmt/test/sut/src/sut.cpp index a4d2e4688179b7161c03837b5478b197a6576bca..b54590ce82702c6987b8039eee423d7194151549 100644 --- a/source/dnode/mgmt/test/sut/src/sut.cpp +++ b/source/dnode/mgmt/test/sut/src/sut.cpp @@ -53,7 +53,10 @@ void Testbase::Init(const char* path, int16_t port) { taosMkDir(path); InitLog(TD_TMP_DIR_PATH "td"); - server.Start(); + if (!server.Start()) { + printf("failed to start server, exit\n"); + exit(0); + }; client.Init("root", "taosdata"); showRsp = NULL; } diff --git a/source/dnode/mnode/impl/inc/mndConsumer.h b/source/dnode/mnode/impl/inc/mndConsumer.h index 210e336ac251165cfefb0c8f8b60ddbb9d1df843..1176e1af0b8fa09328669f11066235870f39b06a 100644 --- a/source/dnode/mnode/impl/inc/mndConsumer.h +++ b/source/dnode/mnode/impl/inc/mndConsumer.h @@ -44,6 +44,7 @@ SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer); SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw); int32_t mndSetConsumerCommitLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *pConsumer); +int32_t mndSetConsumerDropLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *pConsumer); bool mndRebTryStart(); void mndRebEnd(); diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 74a92c9fcd1e021ccef13c86556b96a228e02feb..04ac5aba49dcc1622c81201c88524a7b1eed8591 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -321,6 +321,7 @@ typedef struct { int32_t vgVersion; SDbCfg cfg; SRWLatch lock; + int64_t stateTs; } SDbObj; typedef struct { diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index f55e830a44c8d341e25cd294ee31c56ed7707277..a0f3c98f8340f44e1ca940008a69835eb0f4cbcf 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -20,7 +20,6 @@ #include "sdb.h" #include "sync.h" -#include "syncTools.h" #include "tcache.h" #include "tdatablock.h" #include "tglobal.h" @@ -80,8 +79,8 @@ typedef struct { } SProfileMgmt; typedef struct { - SRWLatch lock; - char email[TSDB_FQDN_LEN]; + TdThreadMutex lock; + char email[TSDB_FQDN_LEN]; } STelemMgmt; typedef struct { @@ -90,7 +89,6 @@ typedef struct { int32_t errCode; int32_t transId; SRWLatch lock; - int8_t leaderTransferFinish; int8_t selfIndex; int8_t numOfReplicas; SReplica replicas[TSDB_MAX_REPLICA]; diff --git a/source/dnode/mnode/impl/inc/mndMnode.h b/source/dnode/mnode/impl/inc/mndMnode.h index a433af9947ecde6be83a3dc63e980363fd13694a..320d3651f0dee08d319d68cf52b76443c52bb6ed 100644 --- a/source/dnode/mnode/impl/inc/mndMnode.h +++ b/source/dnode/mnode/impl/inc/mndMnode.h @@ -28,7 +28,7 @@ SMnodeObj *mndAcquireMnode(SMnode *pMnode, int32_t mnodeId); void mndReleaseMnode(SMnode *pMnode, SMnodeObj *pObj); bool mndIsMnode(SMnode *pMnode, int32_t dnodeId); void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet); -int32_t mndSetDropMnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj); +int32_t mndSetDropMnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj, bool force); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndOffset.h b/source/dnode/mnode/impl/inc/mndOffset.h deleted file mode 100644 index f7569b964875bbffe90c8fc5525fda8f68b688b8..0000000000000000000000000000000000000000 --- a/source/dnode/mnode/impl/inc/mndOffset.h +++ /dev/null @@ -1,50 +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_MND_OFFSET_H_ -#define _TD_MND_OFFSET_H_ - -#include "mndInt.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int32_t mndInitOffset(SMnode *pMnode); -void mndCleanupOffset(SMnode *pMnode); - -SMqOffsetObj *mndAcquireOffset(SMnode *pMnode, const char *key); -void mndReleaseOffset(SMnode *pMnode, SMqOffsetObj *pOffset); - -SSdbRaw *mndOffsetActionEncode(SMqOffsetObj *pOffset); -SSdbRow *mndOffsetActionDecode(SSdbRaw *pRaw); - -int32_t mndCreateOffsets(STrans *pTrans, const char *cgroup, const char *topicName, const SArray *vgs); - -static FORCE_INLINE int32_t mndMakePartitionKey(char *key, const char *cgroup, const char *topicName, int32_t vgId) { - return snprintf(key, TSDB_PARTITION_KEY_LEN, "%d:%s:%s", vgId, cgroup, topicName); -} - -int32_t mndDropOffsetByDB(SMnode *pMnode, STrans *pTrans, SDbObj *pDb); -int32_t mndDropOffsetByTopic(SMnode *pMnode, STrans *pTrans, const char *topic); -int32_t mndDropOffsetBySubKey(SMnode *pMnode, STrans *pTrans, const char *subKey); - -bool mndOffsetFromTopic(SMqOffsetObj *pOffset, const char *topic); - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_MND_OFFSET_H_*/ diff --git a/source/dnode/mnode/impl/inc/mndQnode.h b/source/dnode/mnode/impl/inc/mndQnode.h index 17615500c47abc2ea0dcad21b5a70ec8a1310892..36eebd3157820b31c89996b8cc56c4600c8c080f 100644 --- a/source/dnode/mnode/impl/inc/mndQnode.h +++ b/source/dnode/mnode/impl/inc/mndQnode.h @@ -29,7 +29,7 @@ void mndCleanupQnode(SMnode *pMnode); SQnodeObj *mndAcquireQnode(SMnode *pMnode, int32_t qnodeId); void mndReleaseQnode(SMnode *pMnode, SQnodeObj *pObj); int32_t mndCreateQnodeList(SMnode *pMnode, SArray **pList, int32_t limit); -int32_t mndSetDropQnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SQnodeObj *pObj); +int32_t mndSetDropQnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SQnodeObj *pObj, bool force); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndSnode.h b/source/dnode/mnode/impl/inc/mndSnode.h index ec7bb02ca7cd86ad5f677fa229f7a575ace6086a..342bc23712ca71d1f418ee3cc97f7aec79e69612 100644 --- a/source/dnode/mnode/impl/inc/mndSnode.h +++ b/source/dnode/mnode/impl/inc/mndSnode.h @@ -27,7 +27,7 @@ void mndCleanupSnode(SMnode *pMnode); SSnodeObj *mndAcquireSnode(SMnode *pMnode, int32_t qnodeId); void mndReleaseSnode(SMnode *pMnode, SSnodeObj *pObj); SEpSet mndAcquireEpFromSnode(SMnode *pMnode, const SSnodeObj *pSnode); -int32_t mndSetDropSnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SSnodeObj *pObj); +int32_t mndSetDropSnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SSnodeObj *pObj, bool force); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/inc/mndSubscribe.h b/source/dnode/mnode/impl/inc/mndSubscribe.h index d91c2bd4c3f69063420f3a775f6183e3eaa3824d..fad316ea12edce96bde4c21694b5402d97bf4ae0 100644 --- a/source/dnode/mnode/impl/inc/mndSubscribe.h +++ b/source/dnode/mnode/impl/inc/mndSubscribe.h @@ -31,6 +31,10 @@ void mndReleaseSubscribe(SMnode *pMnode, SMqSubscribeObj *pSub); int32_t mndMakeSubscribeKey(char *key, const char *cgroup, const char *topicName); +static FORCE_INLINE int32_t mndMakePartitionKey(char *key, const char *cgroup, const char *topicName, int32_t vgId) { + return snprintf(key, TSDB_PARTITION_KEY_LEN, "%d:%s:%s", vgId, cgroup, topicName); +} + int32_t mndDropSubByDB(SMnode *pMnode, STrans *pTrans, SDbObj *pDb); int32_t mndDropSubByTopic(SMnode *pMnode, STrans *pTrans, const char *topic); int32_t mndSetDropSubCommitLogs(SMnode *pMnode, STrans *pTrans, SMqSubscribeObj *pSub); diff --git a/source/dnode/mnode/impl/inc/mndVgroup.h b/source/dnode/mnode/impl/inc/mndVgroup.h index 76c351980804840382fa8916e8aa4be868901056..94469899fc080c52f5dd767ccd43448fd3f5038a 100644 --- a/source/dnode/mnode/impl/inc/mndVgroup.h +++ b/source/dnode/mnode/impl/inc/mndVgroup.h @@ -42,8 +42,7 @@ int32_t mndAddCreateVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *p int32_t mndAddAlterVnodeConfirmAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup); int32_t mndAddAlterVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, tmsg_t msgType); int32_t mndAddDropVnodeAction(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, SVnodeGid *pVgid, bool isRedo); -int32_t mndSetMoveVgroupInfoToTrans(SMnode *, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, int32_t vn, SArray *pArray); -int32_t mndSetMoveVgroupsInfoToTrans(SMnode *, STrans *pTrans, int32_t dropDnodeId); +int32_t mndSetMoveVgroupsInfoToTrans(SMnode *, STrans *pTrans, int32_t dropDnodeId, bool force); int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb, SDbObj *pNewDb, SVgObj *pVgroup, SArray *pArray); diff --git a/source/dnode/mnode/impl/src/mndConsumer.c b/source/dnode/mnode/impl/src/mndConsumer.c index 77f91b6d29a37ceaf9ade6ecda5b917ed4a3773f..62ad5bae157f9cfd15a23caa971424c0b7c92250 100644 --- a/source/dnode/mnode/impl/src/mndConsumer.c +++ b/source/dnode/mnode/impl/src/mndConsumer.c @@ -18,7 +18,6 @@ #include "mndDb.h" #include "mndDnode.h" #include "mndMnode.h" -#include "mndOffset.h" #include "mndPrivilege.h" #include "mndShow.h" #include "mndStb.h" @@ -33,7 +32,8 @@ #define MND_CONSUMER_VER_NUMBER 1 #define MND_CONSUMER_RESERVE_SIZE 64 -#define MND_CONSUMER_LOST_HB_CNT 3 +#define MND_CONSUMER_LOST_HB_CNT 3 +#define MND_CONSUMER_LOST_CLEAR_THRESHOLD 43200 static int8_t mqRebInExecCnt = 0; @@ -51,6 +51,7 @@ static int32_t mndProcessAskEpReq(SRpcMsg *pMsg); static int32_t mndProcessMqHbReq(SRpcMsg *pMsg); static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg); static int32_t mndProcessConsumerLostMsg(SRpcMsg *pMsg); +static int32_t mndProcessConsumerClearMsg(SRpcMsg *pMsg); static int32_t mndProcessConsumerRecoverMsg(SRpcMsg *pMsg); int32_t mndInitConsumer(SMnode *pMnode) { @@ -64,12 +65,13 @@ int32_t mndInitConsumer(SMnode *pMnode) { .deleteFp = (SdbDeleteFp)mndConsumerActionDelete, }; - mndSetMsgHandle(pMnode, TDMT_MND_SUBSCRIBE, mndProcessSubscribeReq); - mndSetMsgHandle(pMnode, TDMT_MND_MQ_HB, mndProcessMqHbReq); - mndSetMsgHandle(pMnode, TDMT_MND_MQ_ASK_EP, mndProcessAskEpReq); - mndSetMsgHandle(pMnode, TDMT_MND_MQ_TIMER, mndProcessMqTimerMsg); - mndSetMsgHandle(pMnode, TDMT_MND_MQ_CONSUMER_LOST, mndProcessConsumerLostMsg); - mndSetMsgHandle(pMnode, TDMT_MND_MQ_CONSUMER_RECOVER, mndProcessConsumerRecoverMsg); + mndSetMsgHandle(pMnode, TDMT_MND_TMQ_SUBSCRIBE, mndProcessSubscribeReq); + mndSetMsgHandle(pMnode, TDMT_MND_TMQ_HB, mndProcessMqHbReq); + mndSetMsgHandle(pMnode, TDMT_MND_TMQ_ASK_EP, mndProcessAskEpReq); + mndSetMsgHandle(pMnode, TDMT_MND_TMQ_TIMER, mndProcessMqTimerMsg); + mndSetMsgHandle(pMnode, TDMT_MND_TMQ_CONSUMER_LOST, mndProcessConsumerLostMsg); + mndSetMsgHandle(pMnode, TDMT_MND_TMQ_CONSUMER_RECOVER, mndProcessConsumerRecoverMsg); + mndSetMsgHandle(pMnode, TDMT_MND_TMQ_LOST_CONSUMER_CLEAR, mndProcessConsumerClearMsg); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONSUMERS, mndRetrieveConsumer); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CONSUMERS, mndCancelGetNextConsumer); @@ -163,6 +165,43 @@ FAIL: return -1; } +static int32_t mndProcessConsumerClearMsg(SRpcMsg *pMsg) { + SMnode *pMnode = pMsg->info.node; + SMqConsumerClearMsg *pClearMsg = pMsg->pCont; + SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pClearMsg->consumerId); + if (pConsumer == NULL) { + return 0; + } + + mInfo("receive consumer clear msg, consumer id %" PRId64 ", status %s", pClearMsg->consumerId, + mndConsumerStatusName(pConsumer->status)); + + if (pConsumer->status != MQ_CONSUMER_STATUS__LOST_REBD) { + mndReleaseConsumer(pMnode, pConsumer); + return -1; + } + + SMqConsumerObj *pConsumerNew = tNewSMqConsumerObj(pConsumer->consumerId, pConsumer->cgroup); + pConsumerNew->updateType = CONSUMER_UPDATE__LOST; + + mndReleaseConsumer(pMnode, pConsumer); + + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pMsg, "clear-csm"); + if (pTrans == NULL) goto FAIL; + if (mndSetConsumerDropLogs(pMnode, pTrans, pConsumerNew) != 0) goto FAIL; + if (mndTransPrepare(pMnode, pTrans) != 0) goto FAIL; + + tDeleteSMqConsumerObj(pConsumerNew); + taosMemoryFree(pConsumerNew); + mndTransDrop(pTrans); + return 0; +FAIL: + tDeleteSMqConsumerObj(pConsumerNew); + taosMemoryFree(pConsumerNew); + mndTransDrop(pTrans); + return -1; +} + static SMqRebInfo *mndGetOrCreateRebSub(SHashObj *pHash, const char *key) { SMqRebInfo *pRebInfo = taosHashGet(pHash, key, strlen(key) + 1); if (pRebInfo == NULL) { @@ -207,15 +246,28 @@ static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg) { SMqConsumerLostMsg *pLostMsg = rpcMallocCont(sizeof(SMqConsumerLostMsg)); pLostMsg->consumerId = pConsumer->consumerId; - SRpcMsg pRpcMsg = { - .msgType = TDMT_MND_MQ_CONSUMER_LOST, + SRpcMsg rpcMsg = { + .msgType = TDMT_MND_TMQ_CONSUMER_LOST, .pCont = pLostMsg, .contLen = sizeof(SMqConsumerLostMsg), }; - tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &pRpcMsg); + tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); } - if (status == MQ_CONSUMER_STATUS__LOST_REBD || status == MQ_CONSUMER_STATUS__READY) { + + if (status == MQ_CONSUMER_STATUS__READY) { // do nothing + } else if (status == MQ_CONSUMER_STATUS__LOST_REBD) { + if (hbStatus > MND_CONSUMER_LOST_CLEAR_THRESHOLD) { + SMqConsumerClearMsg *pClearMsg = rpcMallocCont(sizeof(SMqConsumerClearMsg)); + + pClearMsg->consumerId = pConsumer->consumerId; + SRpcMsg rpcMsg = { + .msgType = TDMT_MND_TMQ_LOST_CONSUMER_CLEAR, + .pCont = pClearMsg, + .contLen = sizeof(SMqConsumerClearMsg), + }; + tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg); + } } else if (status == MQ_CONSUMER_STATUS__LOST) { taosRLockLatch(&pConsumer->lock); int32_t topicNum = taosArrayGetSize(pConsumer->currentTopics); @@ -257,7 +309,7 @@ static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg) { if (taosHashGetSize(pRebMsg->rebSubHash) != 0) { mInfo("mq rebalance will be triggered"); SRpcMsg rpcMsg = { - .msgType = TDMT_MND_MQ_DO_REBALANCE, + .msgType = TDMT_MND_TMQ_DO_REBALANCE, .pCont = pRebMsg, .contLen = sizeof(SMqDoRebalanceMsg), }; @@ -293,7 +345,7 @@ static int32_t mndProcessMqHbReq(SRpcMsg *pMsg) { pRecoverMsg->consumerId = consumerId; SRpcMsg pRpcMsg = { - .msgType = TDMT_MND_MQ_CONSUMER_RECOVER, + .msgType = TDMT_MND_TMQ_CONSUMER_RECOVER, .pCont = pRecoverMsg, .contLen = sizeof(SMqConsumerRecoverMsg), }; @@ -332,7 +384,7 @@ static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) { pRecoverMsg->consumerId = consumerId; SRpcMsg pRpcMsg = { - .msgType = TDMT_MND_MQ_CONSUMER_RECOVER, + .msgType = TDMT_MND_TMQ_CONSUMER_RECOVER, .pCont = pRecoverMsg, .contLen = sizeof(SMqConsumerRecoverMsg), }; @@ -408,12 +460,6 @@ static int32_t mndProcessAskEpReq(SRpcMsg *pMsg) { .offset = -1, }; - // 2.2.2 fetch vg offset - SMqOffsetObj *pOffsetObj = mndAcquireOffset(pMnode, offsetKey); - if (pOffsetObj != NULL) { - vgEp.offset = atomic_load_64(&pOffsetObj->offset); - mndReleaseOffset(pMnode, pOffsetObj); - } taosArrayPush(topicEp.vgs, &vgEp); } taosArrayPush(rsp.topics, &topicEp); @@ -451,6 +497,14 @@ FAIL: return -1; } +int32_t mndSetConsumerDropLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *pConsumer) { + SSdbRaw *pCommitRaw = mndConsumerActionEncode(pConsumer); + if (pCommitRaw == NULL) return -1; + if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; + if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1; + return 0; +} + int32_t mndSetConsumerCommitLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *pConsumer) { SSdbRaw *pCommitRaw = mndConsumerActionEncode(pConsumer); if (pCommitRaw == NULL) return -1; diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 1fa886b722bacfc4ac15b0ed2700769b55c6d3e3..cdd0ce9fc513eb11f2bd305e1817a02395440c5f 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -17,7 +17,6 @@ #include "mndDb.h" #include "mndCluster.h" #include "mndDnode.h" -#include "mndOffset.h" #include "mndPrivilege.h" #include "mndShow.h" #include "mndSma.h" @@ -286,8 +285,17 @@ static inline int32_t mndGetGlobalVgroupVersion(SMnode *pMnode) { SDbObj *mndAcquireDb(SMnode *pMnode, const char *db) { SSdb *pSdb = pMnode->pSdb; SDbObj *pDb = sdbAcquire(pSdb, SDB_DB, db); - if (pDb == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) { - terrno = TSDB_CODE_MND_DB_NOT_EXIST; + if (pDb == NULL) { + if (terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) { + terrno = TSDB_CODE_MND_DB_NOT_EXIST; + } else if (terrno == TSDB_CODE_SDB_OBJ_CREATING) { + terrno = TSDB_CODE_MND_DB_IN_CREATING; + } else if (terrno == TSDB_CODE_SDB_OBJ_DROPPING) { + terrno = TSDB_CODE_MND_DB_IN_DROPPING; + } else { + terrno = TSDB_CODE_APP_ERROR; + mFatal("db:%s, failed to acquire db since %s", db, terrstr()); + } } return pDb; } @@ -595,16 +603,22 @@ static int32_t mndProcessCreateDbReq(SRpcMsg *pReq) { terrno = TSDB_CODE_MND_DB_ALREADY_EXIST; goto _OVER; } - } else if (terrno == TSDB_CODE_SDB_OBJ_CREATING) { - if (mndSetRpcInfoForDbTrans(pMnode, pReq, MND_OPER_CREATE_DB, createReq.db) == 0) { - mInfo("db:%s, is creating and response after trans finished", createReq.db); - code = TSDB_CODE_ACTION_IN_PROGRESS; + } else { + if (terrno == TSDB_CODE_MND_DB_IN_CREATING) { + if (mndSetRpcInfoForDbTrans(pMnode, pReq, MND_OPER_CREATE_DB, createReq.db) == 0) { + mInfo("db:%s, is creating and createdb response after trans finished", createReq.db); + code = TSDB_CODE_ACTION_IN_PROGRESS; + goto _OVER; + } else { + goto _OVER; + } + } else if (terrno == TSDB_CODE_MND_DB_IN_DROPPING) { goto _OVER; - } else { + } else if (terrno == TSDB_CODE_MND_DB_NOT_EXIST) { + // continue + } else { // TSDB_CODE_APP_ERROR goto _OVER; } - } else if (terrno != TSDB_CODE_MND_DB_NOT_EXIST) { - goto _OVER; } pUser = mndAcquireUser(pMnode, pReq->info.conn.user); @@ -641,12 +655,8 @@ static int32_t mndSetDbCfgFromAlterDbReq(SDbObj *pDb, SAlterDbReq *pAlter) { } if (pAlter->pageSize > 0 && pAlter->pageSize != pDb->cfg.pageSize) { -#if 1 - terrno = TSDB_CODE_OPS_NOT_SUPPORT; -#else pDb->cfg.pageSize = pAlter->pageSize; terrno = 0; -#endif } if (pAlter->daysPerFile > 0 && pAlter->daysPerFile != pDb->cfg.daysPerFile) { @@ -791,7 +801,6 @@ static int32_t mndProcessAlterDbReq(SRpcMsg *pReq) { pDb = mndAcquireDb(pMnode, alterReq.db); if (pDb == NULL) { - terrno = TSDB_CODE_MND_DB_NOT_EXIST; goto _OVER; } @@ -841,7 +850,6 @@ static int32_t mndProcessGetDbCfgReq(SRpcMsg *pReq) { pDb = mndAcquireDb(pMnode, cfgReq.db); if (pDb == NULL) { - terrno = TSDB_CODE_MND_DB_NOT_EXIST; goto _OVER; } @@ -1071,11 +1079,8 @@ static int32_t mndProcessDropDbReq(SRpcMsg *pReq) { if (pDb == NULL) { if (dropReq.ignoreNotExists) { code = mndBuildDropDbRsp(pDb, &pReq->info.rspLen, &pReq->info.rsp, true); - goto _OVER; - } else { - terrno = TSDB_CODE_MND_DB_NOT_EXIST; - goto _OVER; } + goto _OVER; } if (mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_DROP_DB, pDb) != 0) { @@ -1177,6 +1182,7 @@ int32_t mndExtractDbInfo(SMnode *pMnode, SDbObj *pDb, SUseDbRsp *pRsp, const SUs memcpy(pRsp->db, pDb->name, TSDB_DB_FNAME_LEN); pRsp->uid = pDb->uid; pRsp->vgVersion = pDb->vgVersion; + pRsp->stateTs = pDb->stateTs; pRsp->vgNum = taosArrayGetSize(pRsp->pVgroupInfos); pRsp->hashMethod = pDb->cfg.hashMethod; pRsp->hashPrefix = pDb->cfg.hashPrefix; @@ -1202,10 +1208,7 @@ static int32_t mndProcessUseDbReq(SRpcMsg *pReq) { int32_t vgVersion = mndGetGlobalVgroupVersion(pMnode); if (usedbReq.vgVersion < vgVersion) { usedbRsp.pVgroupInfos = taosArrayInit(10, sizeof(SVgroupInfo)); - if (usedbRsp.pVgroupInfos == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - goto _OVER; - } + if (usedbRsp.pVgroupInfos == NULL) goto _OVER; mndBuildDBVgroupInfo(NULL, pMnode, usedbRsp.pVgroupInfos); usedbRsp.vgVersion = vgVersion++; @@ -1214,16 +1217,21 @@ static int32_t mndProcessUseDbReq(SRpcMsg *pReq) { } usedbRsp.vgNum = taosArrayGetSize(usedbRsp.pVgroupInfos); code = 0; - - // no jump, need to construct rsp } else { pDb = mndAcquireDb(pMnode, usedbReq.db); if (pDb == NULL) { - terrno = TSDB_CODE_MND_DB_NOT_EXIST; - memcpy(usedbRsp.db, usedbReq.db, TSDB_DB_FNAME_LEN); usedbRsp.uid = usedbReq.dbId; usedbRsp.vgVersion = usedbReq.vgVersion; + usedbRsp.errCode = terrno; + + if (terrno == TSDB_CODE_MND_DB_IN_CREATING) { + if (mndSetRpcInfoForDbTrans(pMnode, pReq, MND_OPER_CREATE_DB, usedbReq.db) == 0) { + mInfo("db:%s, is creating and usedb response after trans finished", usedbReq.db); + code = TSDB_CODE_ACTION_IN_PROGRESS; + goto _OVER; + } + } mError("db:%s, failed to process use db req since %s", usedbReq.db, terrstr()); } else { @@ -1235,6 +1243,8 @@ static int32_t mndProcessUseDbReq(SRpcMsg *pReq) { goto _OVER; } + mDebug("db:%s, process usedb req vgVersion:%d stateTs:%" PRId64 ", rsp vgVersion:%d stateTs:%" PRId64, + usedbReq.db, usedbReq.vgVersion, usedbReq.stateTs, usedbRsp.vgVersion, usedbRsp.stateTs); code = 0; } } @@ -1253,7 +1263,7 @@ static int32_t mndProcessUseDbReq(SRpcMsg *pReq) { pReq->info.rspLen = contLen; _OVER: - if (code != 0) { + if (code != 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) { mError("db:%s, failed to process use db req since %s", usedbReq.db, terrstr()); } @@ -1291,13 +1301,19 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbVgVersion *pDbs, int32_t numOfDbs, int32_t numOfTable = mndGetDBTableNum(pDb, pMnode); - if (pDbVgVersion->vgVersion >= pDb->vgVersion && numOfTable == pDbVgVersion->numOfTable) { - mInfo("db:%s, version and numOfTable not changed", pDbVgVersion->dbFName); + if (pDbVgVersion->vgVersion >= pDb->vgVersion && numOfTable == pDbVgVersion->numOfTable /* && + pDbVgVersion->stateTs == pDb->stateTs */) { + mTrace("db:%s, valid dbinfo, vgVersion:%d stateTs:%" PRId64 + " numOfTables:%d, not changed vgVersion:%d stateTs:%" PRId64 " numOfTables:%d", + pDbVgVersion->dbFName, pDbVgVersion->vgVersion, pDbVgVersion->stateTs, pDbVgVersion->numOfTable, + pDb->vgVersion, pDb->stateTs, numOfTable); mndReleaseDb(pMnode, pDb); continue; } else { - mInfo("db:%s, vgroup version changed from %d to %d", pDbVgVersion->dbFName, pDbVgVersion->vgVersion, - pDb->vgVersion); + mInfo("db:%s, valid dbinfo, vgVersion:%d stateTs:%" PRId64 + " numOfTables:%d, changed to vgVersion:%d stateTs:%" PRId64 " numOfTables:%d", + pDbVgVersion->dbFName, pDbVgVersion->vgVersion, pDbVgVersion->stateTs, pDbVgVersion->numOfTable, + pDb->vgVersion, pDb->stateTs, numOfTable); } usedbRsp.pVgroupInfos = taosArrayInit(pDb->cfg.numOfVgroups, sizeof(SVgroupInfo)); @@ -1311,6 +1327,7 @@ int32_t mndValidateDbInfo(SMnode *pMnode, SDbVgVersion *pDbs, int32_t numOfDbs, memcpy(usedbRsp.db, pDb->name, TSDB_DB_FNAME_LEN); usedbRsp.uid = pDb->uid; usedbRsp.vgVersion = pDb->vgVersion; + usedbRsp.stateTs = pDb->stateTs; usedbRsp.vgNum = (int32_t)taosArrayGetSize(usedbRsp.pVgroupInfos); usedbRsp.hashMethod = pDb->cfg.hashMethod; usedbRsp.hashPrefix = pDb->cfg.hashPrefix; diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 264b8d979b7a00de55ae7b10b422ee27889854fc..521f924fad89eb3a169044e6dce27b41a5487770 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -15,6 +15,7 @@ #define _DEFAULT_SOURCE #include "mndDnode.h" +#include "mndDb.h" #include "mndMnode.h" #include "mndPrivilege.h" #include "mndQnode.h" @@ -345,6 +346,19 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { } } + int64_t dnodeVer = sdbGetTableVer(pMnode->pSdb, SDB_DNODE) + sdbGetTableVer(pMnode->pSdb, SDB_MNODE); + int64_t curMs = taosGetTimestampMs(); + bool online = mndIsDnodeOnline(pDnode, curMs); + bool dnodeChanged = (statusReq.dnodeVer == 0) || (statusReq.dnodeVer != dnodeVer); + bool reboot = (pDnode->rebootTime != statusReq.rebootTime); + bool needCheck = !online || dnodeChanged || reboot; + + pDnode->accessTimes++; + pDnode->lastAccessTime = curMs; + const STraceId *trace = &pReq->info.traceId; + mGTrace("dnode:%d, status received, accessTimes:%d check:%d online:%d reboot:%d changed:%d statusSeq:%d", pDnode->id, + pDnode->accessTimes, needCheck, online, reboot, dnodeChanged, statusReq.statusSeq); + for (int32_t v = 0; v < taosArrayGetSize(statusReq.pVloads); ++v) { SVnodeLoad *pVload = taosArrayGet(statusReq.pVloads, v); @@ -363,6 +377,9 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { if (pVgroup->vnodeGid[vg].dnodeId == statusReq.dnodeId) { if (pVgroup->vnodeGid[vg].syncState != pVload->syncState || pVgroup->vnodeGid[vg].syncRestore != pVload->syncRestore) { + mInfo("vgId:%d, state changed by status msg, old state:%s restored:%d new state:%s restored:%d", + pVgroup->vgId, syncStr(pVgroup->vnodeGid[vg].syncState), pVgroup->vnodeGid[vg].syncRestore, + syncStr(pVload->syncState), pVload->syncRestore); pVgroup->vnodeGid[vg].syncState = pVload->syncState; pVgroup->vnodeGid[vg].syncRestore = pVload->syncRestore; roleChanged = true; @@ -371,7 +388,12 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { } } if (roleChanged) { - // notify scheduler role has changed + SDbObj *pDb = mndAcquireDb(pMnode, pVgroup->dbName); + if (pDb != NULL && pDb->stateTs != curMs) { + mInfo("db:%s, stateTs changed by status msg, old stateTs:%" PRId64 " new stateTs:%" PRId64, pDb->name, pDb->stateTs, curMs); + pDb->stateTs = curMs; + } + mndReleaseDb(pMnode, pDb); } } @@ -396,13 +418,6 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { mndReleaseQnode(pMnode, pQnode); } - int64_t dnodeVer = sdbGetTableVer(pMnode->pSdb, SDB_DNODE) + sdbGetTableVer(pMnode->pSdb, SDB_MNODE); - int64_t curMs = taosGetTimestampMs(); - bool online = mndIsDnodeOnline(pDnode, curMs); - bool dnodeChanged = (statusReq.dnodeVer == 0) || (statusReq.dnodeVer != dnodeVer); - bool reboot = (pDnode->rebootTime != statusReq.rebootTime); - bool needCheck = !online || dnodeChanged || reboot; - if (needCheck) { if (statusReq.sver != tsVersion) { if (pDnode != NULL) { @@ -424,9 +439,6 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { pMnode->clusterId); terrno = TSDB_CODE_MND_INVALID_CLUSTER_ID; goto _OVER; - } else { - pDnode->accessTimes++; - mDebug("dnode:%d, status received, access times %d", pDnode->id, pDnode->accessTimes); } } @@ -453,6 +465,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { pDnode->memTotal = statusReq.memTotal; SStatusRsp statusRsp = {0}; + statusRsp.statusSeq++; statusRsp.dnodeVer = dnodeVer; statusRsp.dnodeCfg.dnodeId = pDnode->id; statusRsp.dnodeCfg.clusterId = pMnode->clusterId; @@ -473,8 +486,6 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { pReq->info.rsp = pHead; } - pDnode->lastAccessTime = curMs; - pDnode->accessTimes++; code = 0; _OVER: @@ -670,7 +681,7 @@ _OVER: } static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SMnodeObj *pMObj, SQnodeObj *pQObj, - SSnodeObj *pSObj, int32_t numOfVnodes) { + SSnodeObj *pSObj, int32_t numOfVnodes, bool force) { int32_t code = -1; SSdbRaw *pRaw = NULL; STrans *pTrans = NULL; @@ -678,7 +689,7 @@ static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SM pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_GLOBAL, pReq, "drop-dnode"); if (pTrans == NULL) goto _OVER; mndTransSetSerial(pTrans); - mInfo("trans:%d, used to drop dnode:%d", pTrans->id, pDnode->id); + mInfo("trans:%d, used to drop dnode:%d, force:%d", pTrans->id, pDnode->id, force); pRaw = mndDnodeActionEncode(pDnode); if (pRaw == NULL) goto _OVER; @@ -694,22 +705,22 @@ static int32_t mndDropDnode(SMnode *pMnode, SRpcMsg *pReq, SDnodeObj *pDnode, SM if (pMObj != NULL) { mInfo("trans:%d, mnode on dnode:%d will be dropped", pTrans->id, pDnode->id); - if (mndSetDropMnodeInfoToTrans(pMnode, pTrans, pMObj) != 0) goto _OVER; + if (mndSetDropMnodeInfoToTrans(pMnode, pTrans, pMObj, force) != 0) goto _OVER; } if (pQObj != NULL) { mInfo("trans:%d, qnode on dnode:%d will be dropped", pTrans->id, pDnode->id); - if (mndSetDropQnodeInfoToTrans(pMnode, pTrans, pQObj) != 0) goto _OVER; + if (mndSetDropQnodeInfoToTrans(pMnode, pTrans, pQObj, force) != 0) goto _OVER; } if (pSObj != NULL) { mInfo("trans:%d, snode on dnode:%d will be dropped", pTrans->id, pDnode->id); - if (mndSetDropSnodeInfoToTrans(pMnode, pTrans, pSObj) != 0) goto _OVER; + if (mndSetDropSnodeInfoToTrans(pMnode, pTrans, pSObj, force) != 0) goto _OVER; } if (numOfVnodes > 0) { mInfo("trans:%d, %d vnodes on dnode:%d will be dropped", pTrans->id, numOfVnodes, pDnode->id); - if (mndSetMoveVgroupsInfoToTrans(pMnode, pTrans, pDnode->id) != 0) goto _OVER; + if (mndSetMoveVgroupsInfoToTrans(pMnode, pTrans, pDnode->id, force) != 0) goto _OVER; } if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; @@ -767,21 +778,16 @@ static int32_t mndProcessDropDnodeReq(SRpcMsg *pReq) { } int32_t numOfVnodes = mndGetVnodesNum(pMnode, pDnode->id); - if (numOfVnodes > 0 || pMObj != NULL) { + if ((numOfVnodes > 0 || pMObj != NULL || pSObj != NULL || pQObj != NULL) && !dropReq.force) { if (!mndIsDnodeOnline(pDnode, taosGetTimestampMs())) { terrno = TSDB_CODE_NODE_OFFLINE; - mError("dnode:%d, failed to drop since %s, has_mnode:%d numOfVnodes:%d", pDnode->id, terrstr(), pMObj != NULL, - numOfVnodes); + mError("dnode:%d, failed to drop since %s, vnodes:%d mnode:%d qnode:%d snode:%d", pDnode->id, terrstr(), + numOfVnodes, pMObj != NULL, pQObj != NULL, pSObj != NULL); goto _OVER; } } - if (numOfVnodes > 0) { - terrno = TSDB_CODE_OPS_NOT_SUPPORT; - goto _OVER; - } - - code = mndDropDnode(pMnode, pReq, pDnode, pMObj, pQObj, pSObj, numOfVnodes); + code = mndDropDnode(pMnode, pReq, pDnode, pMObj, pQObj, pSObj, numOfVnodes, dropReq.force); if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS; _OVER: diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index fbfa1b73be6cae79c547b3f21248e25af5cddf3b..dcfc046a1eb8fde76e04fd23ba523ad0ea8994b3 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -23,7 +23,6 @@ #include "mndGrant.h" #include "mndInfoSchema.h" #include "mndMnode.h" -#include "mndOffset.h" #include "mndPerfSchema.h" #include "mndPrivilege.h" #include "mndProfile.h" @@ -106,7 +105,7 @@ static void mndCalMqRebalance(SMnode *pMnode) { int32_t contLen = 0; void *pReq = mndBuildTimerMsg(&contLen); if (pReq != NULL) { - SRpcMsg rpcMsg = {.msgType = TDMT_MND_MQ_TIMER, .pCont = pReq, .contLen = contLen}; + SRpcMsg rpcMsg = {.msgType = TDMT_MND_TMQ_TIMER, .pCont = pReq, .contLen = contLen}; tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg); } } @@ -140,6 +139,63 @@ static void mndIncreaseUpTime(SMnode *pMnode) { } } +static void mndSetVgroupOffline(SMnode *pMnode, int32_t dnodeId, int64_t curMs) { + SSdb *pSdb = pMnode->pSdb; + + void *pIter = NULL; + while (1) { + SVgObj *pVgroup = NULL; + pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); + if (pIter == NULL) break; + + bool roleChanged = false; + for (int32_t vg = 0; vg < pVgroup->replica; ++vg) { + if (pVgroup->vnodeGid[vg].dnodeId == dnodeId) { + if (pVgroup->vnodeGid[vg].syncState != TAOS_SYNC_STATE_ERROR) { + mInfo("vgId:%d, state changed by offline check, old state:%s restored:%d new state:error restored:0", + pVgroup->vgId, syncStr(pVgroup->vnodeGid[vg].syncState), pVgroup->vnodeGid[vg].syncRestore); + pVgroup->vnodeGid[vg].syncState = TAOS_SYNC_STATE_ERROR; + pVgroup->vnodeGid[vg].syncRestore = 0; + roleChanged = true; + } + break; + } + } + + if (roleChanged) { + SDbObj *pDb = mndAcquireDb(pMnode, pVgroup->dbName); + if (pDb != NULL && pDb->stateTs != curMs) { + mInfo("db:%s, stateTs changed by offline check, old newTs:%" PRId64 " newTs:%" PRId64, pDb->name, pDb->stateTs, + curMs); + pDb->stateTs = curMs; + } + mndReleaseDb(pMnode, pDb); + } + + sdbRelease(pSdb, pVgroup); + } +} + +static void mndCheckDnodeOffline(SMnode *pMnode) { + SSdb *pSdb = pMnode->pSdb; + int64_t curMs = taosGetTimestampMs(); + + void *pIter = NULL; + while (1) { + SDnodeObj *pDnode = NULL; + pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode); + if (pIter == NULL) break; + + bool online = mndIsDnodeOnline(pDnode, curMs); + if (!online) { + mInfo("dnode:%d, in offline state", pDnode->id); + mndSetVgroupOffline(pMnode, pDnode->id, curMs); + } + + sdbRelease(pSdb, pDnode); + } +} + static void *mndThreadFp(void *param) { SMnode *pMnode = param; int64_t lastTime = 0; @@ -175,6 +231,10 @@ static void *mndThreadFp(void *param) { if (sec % tsUptimeInterval == 0) { mndIncreaseUpTime(pMnode); } + + if (sec % (tsStatusInterval * 5) == 0) { + mndCheckDnodeOffline(pMnode); + } } return NULL; @@ -305,7 +365,6 @@ static int32_t mndInitSteps(SMnode *pMnode) { if (mndAllocStep(pMnode, "mnode-topic", mndInitTopic, mndCleanupTopic) != 0) return -1; if (mndAllocStep(pMnode, "mnode-consumer", mndInitConsumer, mndCleanupConsumer) != 0) return -1; if (mndAllocStep(pMnode, "mnode-subscribe", mndInitSubscribe, mndCleanupSubscribe) != 0) return -1; - if (mndAllocStep(pMnode, "mnode-offset", mndInitOffset, mndCleanupOffset) != 0) return -1; if (mndAllocStep(pMnode, "mnode-vgroup", mndInitVgroup, mndCleanupVgroup) != 0) return -1; if (mndAllocStep(pMnode, "mnode-stb", mndInitStb, mndCleanupStb) != 0) return -1; if (mndAllocStep(pMnode, "mnode-sma", mndInitSma, mndCleanupSma) != 0) return -1; @@ -424,24 +483,14 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { return NULL; } - mInfo("mnode open successfully "); + mInfo("mnode open successfully"); return pMnode; } void mndPreClose(SMnode *pMnode) { if (pMnode != NULL) { - atomic_store_8(&(pMnode->syncMgmt.leaderTransferFinish), 0); syncLeaderTransfer(pMnode->syncMgmt.sync); - -#if 0 - mInfo("vgId:1, mnode start leader transfer"); - // wait for leader transfer finish - while (!atomic_load_8(&(pMnode->syncMgmt.leaderTransferFinish))) { - taosMsleep(10); - mInfo("vgId:1, mnode waiting for leader transfer"); - } - mInfo("vgId:1, mnode finish leader transfer"); -#endif + syncPreStop(pMnode->syncMgmt.sync); } } @@ -476,128 +525,18 @@ void mndStop(SMnode *pMnode) { mndCleanupTimer(pMnode); } -int32_t mndProcessSyncCtrlMsg(SRpcMsg *pMsg) { - SMnode *pMnode = pMsg->info.node; - SSyncMgmt *pMgmt = &pMnode->syncMgmt; - int32_t code = 0; - - mInfo("vgId:%d, process sync ctrl msg", 1); - - if (!syncEnvIsStart()) { - mError("failed to process sync msg:%p type:%s since syncEnv stop", pMsg, TMSG_INFO(pMsg->msgType)); - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - return -1; - } - - SSyncNode *pSyncNode = syncNodeAcquire(pMgmt->sync); - if (pSyncNode == NULL) { - mError("failed to process sync msg:%p type:%s since syncNode is null", pMsg, TMSG_INFO(pMsg->msgType)); - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - return -1; - } - - if (pMsg->msgType == TDMT_SYNC_HEARTBEAT) { - SyncHeartbeat *pSyncMsg = syncHeartbeatFromRpcMsg2(pMsg); - code = syncNodeOnHeartbeat(pSyncNode, pSyncMsg); - syncHeartbeatDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_HEARTBEAT_REPLY) { - SyncHeartbeatReply *pSyncMsg = syncHeartbeatReplyFromRpcMsg2(pMsg); - code = syncNodeOnHeartbeatReply(pSyncNode, pSyncMsg); - syncHeartbeatReplyDestroy(pSyncMsg); - } - - syncNodeRelease(pSyncNode); - - if (code != 0) { - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - } - return code; -} - int32_t mndProcessSyncMsg(SRpcMsg *pMsg) { SMnode *pMnode = pMsg->info.node; SSyncMgmt *pMgmt = &pMnode->syncMgmt; - int32_t code = 0; - - if (!syncEnvIsStart()) { - mError("failed to process sync msg:%p type:%s since syncEnv stop", pMsg, TMSG_INFO(pMsg->msgType)); - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - return -1; - } - - SSyncNode *pSyncNode = syncNodeAcquire(pMgmt->sync); - if (pSyncNode == NULL) { - mError("failed to process sync msg:%p type:%s since syncNode is null", pMsg, TMSG_INFO(pMsg->msgType)); - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - return -1; - } - - if (pMsg->msgType == TDMT_SYNC_TIMEOUT) { - SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg); - code = syncNodeOnTimer(pSyncNode, pSyncMsg); - syncTimeoutDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_PING) { - SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg); - code = syncNodeOnPingCb(pSyncNode, pSyncMsg); - syncPingDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) { - SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg); - code = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg); - syncPingReplyDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) { - SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pMsg); - code = syncNodeOnClientRequest(pSyncNode, pSyncMsg, NULL); - syncClientRequestDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) { - SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg); - code = syncNodeOnRequestVote(pSyncNode, pSyncMsg); - syncRequestVoteDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) { - SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg); - code = syncNodeOnRequestVoteReply(pSyncNode, pSyncMsg); - syncRequestVoteReplyDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) { - SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pMsg); - code = syncNodeOnAppendEntries(pSyncNode, pSyncMsg); - syncAppendEntriesDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) { - SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg); - code = syncNodeOnAppendEntriesReply(pSyncNode, pSyncMsg); - syncAppendEntriesReplyDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) { - SyncSnapshotSend *pSyncMsg = syncSnapshotSendFromRpcMsg2(pMsg); - code = syncNodeOnSnapshot(pSyncNode, pSyncMsg); - syncSnapshotSendDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) { - SyncSnapshotRsp *pSyncMsg = syncSnapshotRspFromRpcMsg2(pMsg); - code = syncNodeOnSnapshotReply(pSyncNode, pSyncMsg); - syncSnapshotRspDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_SET_MNODE_STANDBY) { - code = syncSetStandby(pMgmt->sync); - SRpcMsg rsp = {.code = code, .info = pMsg->info}; - tmsgSendRsp(&rsp); - } else { - mError("failed to process msg:%p since invalid type:%s", pMsg, TMSG_INFO(pMsg->msgType)); - code = -1; - } - - syncNodeRelease(pSyncNode); + const STraceId *trace = &pMsg->info.traceId; + mGTrace("vgId:1, sync msg:%p will be processed, type:%s", pMsg, TMSG_INFO(pMsg->msgType)); + int32_t code = syncProcessMsg(pMgmt->sync, pMsg); if (code != 0) { - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; + mGError("vgId:1, failed to process sync msg:%p type:%s since %s", pMsg, TMSG_INFO(pMsg->msgType), terrstr()); } + return code; } @@ -610,14 +549,14 @@ static int32_t mndCheckMnodeState(SRpcMsg *pMsg) { } if (mndAcquireRpc(pMsg->info.node) == 0) return 0; - SMnode *pMnode = pMsg->info.node; - const char *role = syncGetMyRoleStr(pMnode->syncMgmt.sync); - bool restored = syncIsRestoreFinish(pMnode->syncMgmt.sync); - if (pMsg->msgType == TDMT_MND_MQ_TIMER || pMsg->msgType == TDMT_MND_TELEM_TIMER || + SMnode *pMnode = pMsg->info.node; + SSyncState state = syncGetState(pMnode->syncMgmt.sync); + + if (pMsg->msgType == TDMT_MND_TMQ_TIMER || pMsg->msgType == TDMT_MND_TELEM_TIMER || pMsg->msgType == TDMT_MND_TRANS_TIMER || pMsg->msgType == TDMT_MND_TTL_TIMER || pMsg->msgType == TDMT_MND_UPTIME_TIMER) { mTrace("timer not process since mnode restored:%d stopped:%d, sync restored:%d role:%s ", pMnode->restored, - pMnode->stopped, restored, role); + pMnode->stopped, state.restored, syncStr(state.restored)); return -1; } @@ -628,8 +567,8 @@ static int32_t mndCheckMnodeState(SRpcMsg *pMsg) { mDebug( "msg:%p, type:%s failed to process since %s, mnode restored:%d stopped:%d, sync restored:%d " "role:%s, redirect numOfEps:%d inUse:%d", - pMsg, TMSG_INFO(pMsg->msgType), terrstr(), pMnode->restored, pMnode->stopped, restored, role, epSet.numOfEps, - epSet.inUse); + pMsg, TMSG_INFO(pMsg->msgType), terrstr(), pMnode->restored, pMnode->stopped, state.restored, + syncStr(state.restored), epSet.numOfEps, epSet.inUse); if (epSet.numOfEps > 0) { for (int32_t i = 0; i < epSet.numOfEps; ++i) { @@ -852,8 +791,9 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr } int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad) { - pLoad->syncState = syncGetMyRole(pMnode->syncMgmt.sync); - pLoad->syncRestore = pMnode->restored; + SSyncState state = syncGetState(pMnode->syncMgmt.sync); + pLoad->syncState = state.state; + pLoad->syncRestore = state.restored; mTrace("mnode current syncState is %s, syncRestore:%d", syncStr(pLoad->syncState), pLoad->syncRestore); return 0; } diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index 5889a162f83659cb1e94cb0a9cbcbec1ab077ede..563b3cd3cf6859440a5f12f9826729a4a89102f8 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -472,7 +472,8 @@ static int32_t mndSetDropMnodeCommitLogs(SMnode *pMnode, STrans *pTrans, SMnodeO return 0; } -static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) { +static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj, + bool force) { SSdb *pSdb = pMnode->pSdb; void *pIter = NULL; SDDropMnodeReq dropReq = {0}; @@ -485,12 +486,21 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode int32_t totalMnodes = sdbGetSize(pSdb, SDB_MNODE); if (totalMnodes == 2) { + if (force) { + mError("cant't force drop dnode, since a mnode on it and replica is 2"); + terrno = TSDB_CODE_NODE_OFFLINE; + return -1; + } mInfo("vgId:1, has %d mnodes, exec redo log first", totalMnodes); if (mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj) != 0) return -1; - if (mndBuildDropMnodeRedoAction(pTrans, &dropReq, &dropEpSet) != 0) return -1; + if (!force) { + if (mndBuildDropMnodeRedoAction(pTrans, &dropReq, &dropEpSet) != 0) return -1; + } } else if (totalMnodes == 3) { mInfo("vgId:1, has %d mnodes, exec redo action first", totalMnodes); - if (mndBuildDropMnodeRedoAction(pTrans, &dropReq, &dropEpSet) != 0) return -1; + if (!force) { + if (mndBuildDropMnodeRedoAction(pTrans, &dropReq, &dropEpSet) != 0) return -1; + } if (mndSetDropMnodeRedoLogs(pMnode, pTrans, pObj) != 0) return -1; } else { return -1; @@ -499,9 +509,9 @@ static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnode return 0; } -int32_t mndSetDropMnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) { +int32_t mndSetDropMnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj, bool force) { if (pObj == NULL) return 0; - if (mndSetDropMnodeRedoActions(pMnode, pTrans, pObj->pDnode, pObj) != 0) return -1; + if (mndSetDropMnodeRedoActions(pMnode, pTrans, pObj->pDnode, pObj, force) != 0) return -1; if (mndSetDropMnodeCommitLogs(pMnode, pTrans, pObj) != 0) return -1; return 0; } @@ -515,7 +525,7 @@ static int32_t mndDropMnode(SMnode *pMnode, SRpcMsg *pReq, SMnodeObj *pObj) { mndTransSetSerial(pTrans); mInfo("trans:%d, used to drop mnode:%d", pTrans->id, pObj->id); - if (mndSetDropMnodeInfoToTrans(pMnode, pTrans, pObj) != 0) goto _OVER; + if (mndSetDropMnodeInfoToTrans(pMnode, pTrans, pObj, false) != 0) goto _OVER; if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; code = 0; @@ -743,7 +753,7 @@ static void mndReloadSyncConfig(SMnode *pMnode) { mInfo("vgId:1, mnode sync not reconfig since readyMnodes:%d updatingMnodes:%d", readyMnodes, updatingMnodes); return; } - // ASSERT(0); + // ASSERT(0); if (cfg.myIndex == -1) { #if 1 diff --git a/source/dnode/mnode/impl/src/mndOffset.c b/source/dnode/mnode/impl/src/mndOffset.c deleted file mode 100644 index 8d779f00217a7070873633249081d75f68f643ab..0000000000000000000000000000000000000000 --- a/source/dnode/mnode/impl/src/mndOffset.c +++ /dev/null @@ -1,370 +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 . - */ - -#define _DEFAULT_SOURCE -#include "mndOffset.h" -#include "mndDb.h" -#include "mndDnode.h" -#include "mndMnode.h" -#include "mndPrivilege.h" -#include "mndShow.h" -#include "mndStb.h" -#include "mndTopic.h" -#include "mndTrans.h" -#include "mndUser.h" -#include "mndVgroup.h" -#include "tname.h" - -#define MND_OFFSET_VER_NUMBER 1 -#define MND_OFFSET_RESERVE_SIZE 64 - -static int32_t mndOffsetActionInsert(SSdb *pSdb, SMqOffsetObj *pOffset); -static int32_t mndOffsetActionDelete(SSdb *pSdb, SMqOffsetObj *pOffset); -static int32_t mndOffsetActionUpdate(SSdb *pSdb, SMqOffsetObj *pOffset, SMqOffsetObj *pNewOffset); -static int32_t mndProcessCommitOffsetReq(SRpcMsg *pReq); - -int32_t mndInitOffset(SMnode *pMnode) { - SSdbTable table = { - .sdbType = SDB_OFFSET, - .keyType = SDB_KEY_BINARY, - .encodeFp = (SdbEncodeFp)mndOffsetActionEncode, - .decodeFp = (SdbDecodeFp)mndOffsetActionDecode, - .insertFp = (SdbInsertFp)mndOffsetActionInsert, - .updateFp = (SdbUpdateFp)mndOffsetActionUpdate, - .deleteFp = (SdbDeleteFp)mndOffsetActionDelete, - }; - - mndSetMsgHandle(pMnode, TDMT_MND_MQ_COMMIT_OFFSET, mndProcessCommitOffsetReq); - - return sdbSetTable(pMnode->pSdb, table); -} - -void mndCleanupOffset(SMnode *pMnode) {} - -bool mndOffsetFromTopic(SMqOffsetObj *pOffset, const char *topic) { - int32_t i = 0; - while (pOffset->key[i] != ':') i++; - while (pOffset->key[i] != ':') i++; - if (strcmp(&pOffset->key[i + 1], topic) == 0) return true; - return false; -} - -bool mndOffsetFromSubKey(SMqOffsetObj *pOffset, const char *subKey) { - int32_t i = 0; - while (pOffset->key[i] != ':') i++; - if (strcmp(&pOffset->key[i + 1], subKey) == 0) return true; - return false; -} -SSdbRaw *mndOffsetActionEncode(SMqOffsetObj *pOffset) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - void *buf = NULL; - int32_t tlen = tEncodeSMqOffsetObj(NULL, pOffset); - int32_t size = sizeof(int32_t) + tlen + MND_OFFSET_RESERVE_SIZE; - - SSdbRaw *pRaw = sdbAllocRaw(SDB_OFFSET, MND_OFFSET_VER_NUMBER, size); - if (pRaw == NULL) goto OFFSET_ENCODE_OVER; - - buf = taosMemoryMalloc(tlen); - if (buf == NULL) goto OFFSET_ENCODE_OVER; - - void *abuf = buf; - tEncodeSMqOffsetObj(&abuf, pOffset); - - int32_t dataPos = 0; - SDB_SET_INT32(pRaw, dataPos, tlen, OFFSET_ENCODE_OVER); - SDB_SET_BINARY(pRaw, dataPos, buf, tlen, OFFSET_ENCODE_OVER); - SDB_SET_RESERVE(pRaw, dataPos, MND_OFFSET_RESERVE_SIZE, OFFSET_ENCODE_OVER); - SDB_SET_DATALEN(pRaw, dataPos, OFFSET_ENCODE_OVER); - - terrno = TSDB_CODE_SUCCESS; - -OFFSET_ENCODE_OVER: - taosMemoryFreeClear(buf); - if (terrno != TSDB_CODE_SUCCESS) { - mError("offset:%s, failed to encode to raw:%p since %s", pOffset->key, pRaw, terrstr()); - sdbFreeRaw(pRaw); - return NULL; - } - - mTrace("offset:%s, encode to raw:%p, row:%p", pOffset->key, pRaw, pOffset); - return pRaw; -} - -SSdbRow *mndOffsetActionDecode(SSdbRaw *pRaw) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - void *buf = NULL; - - int8_t sver = 0; - if (sdbGetRawSoftVer(pRaw, &sver) != 0) goto OFFSET_DECODE_OVER; - - if (sver != MND_OFFSET_VER_NUMBER) { - terrno = TSDB_CODE_SDB_INVALID_DATA_VER; - goto OFFSET_DECODE_OVER; - } - - int32_t size = sizeof(SMqOffsetObj); - SSdbRow *pRow = sdbAllocRow(size); - if (pRow == NULL) goto OFFSET_DECODE_OVER; - - SMqOffsetObj *pOffset = sdbGetRowObj(pRow); - if (pOffset == NULL) goto OFFSET_DECODE_OVER; - - int32_t dataPos = 0; - int32_t tlen; - SDB_GET_INT32(pRaw, dataPos, &tlen, OFFSET_DECODE_OVER); - buf = taosMemoryMalloc(tlen + 1); - if (buf == NULL) goto OFFSET_DECODE_OVER; - SDB_GET_BINARY(pRaw, dataPos, buf, tlen, OFFSET_DECODE_OVER); - SDB_GET_RESERVE(pRaw, dataPos, MND_OFFSET_RESERVE_SIZE, OFFSET_DECODE_OVER); - - if (tDecodeSMqOffsetObj(buf, pOffset) == NULL) { - goto OFFSET_DECODE_OVER; - } - - terrno = TSDB_CODE_SUCCESS; - -OFFSET_DECODE_OVER: - taosMemoryFreeClear(buf); - if (terrno != TSDB_CODE_SUCCESS) { - mError("offset:%s, failed to decode from raw:%p since %s", pOffset->key, pRaw, terrstr()); - taosMemoryFreeClear(pRow); - return NULL; - } - - mTrace("offset:%s, decode from raw:%p, row:%p", pOffset->key, pRaw, pOffset); - return pRow; -} - -int32_t mndCreateOffsets(STrans *pTrans, const char *cgroup, const char *topicName, const SArray *vgs) { - int32_t sz = taosArrayGetSize(vgs); - for (int32_t i = 0; i < sz; i++) { - int32_t vgId = *(int32_t *)taosArrayGet(vgs, i); - SMqOffsetObj offsetObj = {0}; - if (mndMakePartitionKey(offsetObj.key, cgroup, topicName, vgId) < 0) { - return -1; - } - // TODO assign db - offsetObj.offset = -1; - SSdbRaw *pOffsetRaw = mndOffsetActionEncode(&offsetObj); - if (pOffsetRaw == NULL) { - return -1; - } - (void)sdbSetRawStatus(pOffsetRaw, SDB_STATUS_READY); - // commit log or redo log? - if (mndTransAppendRedolog(pTrans, pOffsetRaw) < 0) { - return -1; - } - } - return 0; -} - -static int32_t mndProcessCommitOffsetReq(SRpcMsg *pMsg) { - char key[TSDB_PARTITION_KEY_LEN]; - - SMnode *pMnode = pMsg->info.node; - char *msgStr = pMsg->pCont; - SMqCMCommitOffsetReq commitOffsetReq; - SDecoder decoder; - tDecoderInit(&decoder, msgStr, pMsg->contLen); - - tDecodeSMqCMCommitOffsetReq(&decoder, &commitOffsetReq); - - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pMsg, "commit-offset"); - if (pTrans == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - tDecoderClear(&decoder); - return -1; - } - - for (int32_t i = 0; i < commitOffsetReq.num; i++) { - SMqOffset *pOffset = &commitOffsetReq.offsets[i]; - mInfo("commit offset %" PRId64 " to vgId:%d of consumer group %s on topic %s", pOffset->offset, pOffset->vgId, - pOffset->cgroup, pOffset->topicName); - if (mndMakePartitionKey(key, pOffset->cgroup, pOffset->topicName, pOffset->vgId) < 0) { - mError("submit offset to topic %s failed", pOffset->topicName); - return -1; - } - bool create = false; - SMqOffsetObj *pOffsetObj = mndAcquireOffset(pMnode, key); - if (pOffsetObj == NULL) { - SMqTopicObj *pTopic = mndAcquireTopic(pMnode, pOffset->topicName); - if (pTopic == NULL) { - terrno = TSDB_CODE_MND_TOPIC_NOT_EXIST; - mError("submit offset to topic %s failed since %s", pOffset->topicName, terrstr()); - continue; - } - pOffsetObj = taosMemoryMalloc(sizeof(SMqOffsetObj)); - pOffsetObj->dbUid = pTopic->dbUid; - mndReleaseTopic(pMnode, pTopic); - memcpy(pOffsetObj->key, key, TSDB_PARTITION_KEY_LEN); - create = true; - } - pOffsetObj->offset = pOffset->offset; - SSdbRaw *pOffsetRaw = mndOffsetActionEncode(pOffsetObj); - (void)sdbSetRawStatus(pOffsetRaw, SDB_STATUS_READY); - mndTransAppendCommitlog(pTrans, pOffsetRaw); - if (create) { - taosMemoryFree(pOffsetObj); - } else { - mndReleaseOffset(pMnode, pOffsetObj); - } - } - - tDecoderClear(&decoder); - - if (mndTransPrepare(pMnode, pTrans) != 0) { - mError("mq-commit-offset-trans:%d, failed to prepare since %s", pTrans->id, terrstr()); - mndTransDrop(pTrans); - return -1; - } - - mndTransDrop(pTrans); - return TSDB_CODE_ACTION_IN_PROGRESS; -} - -static int32_t mndOffsetActionInsert(SSdb *pSdb, SMqOffsetObj *pOffset) { - mTrace("offset:%s, perform insert action", pOffset->key); - return 0; -} - -static int32_t mndOffsetActionDelete(SSdb *pSdb, SMqOffsetObj *pOffset) { - mTrace("offset:%s, perform delete action", pOffset->key); - return 0; -} - -static int32_t mndOffsetActionUpdate(SSdb *pSdb, SMqOffsetObj *pOldOffset, SMqOffsetObj *pNewOffset) { - mTrace("offset:%s, perform update action", pOldOffset->key); - atomic_store_64(&pOldOffset->offset, pNewOffset->offset); - return 0; -} - -SMqOffsetObj *mndAcquireOffset(SMnode *pMnode, const char *key) { - SSdb *pSdb = pMnode->pSdb; - SMqOffsetObj *pOffset = sdbAcquire(pSdb, SDB_OFFSET, key); - if (pOffset == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) { - terrno = TSDB_CODE_MND_OFFSET_NOT_EXIST; - } - return pOffset; -} - -void mndReleaseOffset(SMnode *pMnode, SMqOffsetObj *pOffset) { - SSdb *pSdb = pMnode->pSdb; - sdbRelease(pSdb, pOffset); -} - -static void mndCancelGetNextOffset(SMnode *pMnode, void *pIter) { - SSdb *pSdb = pMnode->pSdb; - sdbCancelFetch(pSdb, pIter); -} - -static int32_t mndSetDropOffsetCommitLogs(SMnode *pMnode, STrans *pTrans, SMqOffsetObj *pOffset) { - SSdbRaw *pCommitRaw = mndOffsetActionEncode(pOffset); - if (pCommitRaw == NULL) return -1; - if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1; - if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1; - return 0; -} - -static int32_t mndSetDropOffsetRedoLogs(SMnode *pMnode, STrans *pTrans, SMqOffsetObj *pOffset) { - SSdbRaw *pRedoRaw = mndOffsetActionEncode(pOffset); - if (pRedoRaw == NULL) return -1; - if (mndTransAppendRedolog(pTrans, pRedoRaw) != 0) return -1; - if (sdbSetRawStatus(pRedoRaw, SDB_STATUS_DROPPED) != 0) return -1; - return 0; -} - -int32_t mndDropOffsetByDB(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { - int32_t code = 0; - SSdb *pSdb = pMnode->pSdb; - - void *pIter = NULL; - SMqOffsetObj *pOffset = NULL; - while (1) { - pIter = sdbFetch(pSdb, SDB_OFFSET, pIter, (void **)&pOffset); - if (pIter == NULL) break; - - if (pOffset->dbUid != pDb->uid) { - sdbRelease(pSdb, pOffset); - continue; - } - - if (mndSetDropOffsetCommitLogs(pMnode, pTrans, pOffset) < 0) { - sdbRelease(pSdb, pOffset); - sdbCancelFetch(pSdb, pIter); - code = -1; - break; - } - - sdbRelease(pSdb, pOffset); - } - - return code; -} - -int32_t mndDropOffsetByTopic(SMnode *pMnode, STrans *pTrans, const char *topic) { - int32_t code = -1; - SSdb *pSdb = pMnode->pSdb; - - void *pIter = NULL; - SMqOffsetObj *pOffset = NULL; - while (1) { - pIter = sdbFetch(pSdb, SDB_OFFSET, pIter, (void **)&pOffset); - if (pIter == NULL) break; - - if (!mndOffsetFromTopic(pOffset, topic)) { - sdbRelease(pSdb, pOffset); - continue; - } - - if (mndSetDropOffsetCommitLogs(pMnode, pTrans, pOffset) < 0) { - sdbRelease(pSdb, pOffset); - goto END; - } - - sdbRelease(pSdb, pOffset); - } - - code = 0; -END: - return code; -} - -int32_t mndDropOffsetBySubKey(SMnode *pMnode, STrans *pTrans, const char *subKey) { - int32_t code = -1; - SSdb *pSdb = pMnode->pSdb; - - void *pIter = NULL; - SMqOffsetObj *pOffset = NULL; - while (1) { - pIter = sdbFetch(pSdb, SDB_OFFSET, pIter, (void **)&pOffset); - if (pIter == NULL) break; - - if (!mndOffsetFromSubKey(pOffset, subKey)) { - sdbRelease(pSdb, pOffset); - continue; - } - - if (mndSetDropOffsetCommitLogs(pMnode, pTrans, pOffset) < 0) { - sdbRelease(pSdb, pOffset); - goto END; - } - - sdbRelease(pSdb, pOffset); - } - - code = 0; -END: - return code; -} diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index 70f9b35312a40405a1413f4ec7089d37f3f4d5c9..434e6fbc52d9754cbc6fac929a94965fe8e3a63d 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -353,11 +353,13 @@ static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQn return 0; } -int32_t mndSetDropQnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SQnodeObj *pObj) { +int32_t mndSetDropQnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SQnodeObj *pObj, bool force) { if (pObj == NULL) return 0; if (mndSetDropQnodeRedoLogs(pTrans, pObj) != 0) return -1; if (mndSetDropQnodeCommitLogs(pTrans, pObj) != 0) return -1; - if (mndSetDropQnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) return -1; + if (!force) { + if (mndSetDropQnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) return -1; + } return 0; } @@ -368,7 +370,7 @@ static int32_t mndDropQnode(SMnode *pMnode, SRpcMsg *pReq, SQnodeObj *pObj) { if (pTrans == NULL) goto _OVER; mInfo("trans:%d, used to drop qnode:%d", pTrans->id, pObj->id); - if (mndSetDropQnodeInfoToTrans(pMnode, pTrans, pObj) != 0) goto _OVER; + if (mndSetDropQnodeInfoToTrans(pMnode, pTrans, pObj, false) != 0) goto _OVER; if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; code = 0; diff --git a/source/dnode/mnode/impl/src/mndQuery.c b/source/dnode/mnode/impl/src/mndQuery.c index 3e4c8005b49c06eade4f432c48981e768dd01fc7..2b0edfebc2b1333f63a81203f8912e7d6c436034 100644 --- a/source/dnode/mnode/impl/src/mndQuery.c +++ b/source/dnode/mnode/impl/src/mndQuery.c @@ -21,7 +21,7 @@ int32_t mndPreProcessQueryMsg(SRpcMsg *pMsg) { if (TDMT_SCH_QUERY != pMsg->msgType && TDMT_SCH_MERGE_QUERY != pMsg->msgType) return 0; SMnode *pMnode = pMsg->info.node; - return qWorkerPreprocessQueryMsg(pMnode->pQuery, pMsg); + return qWorkerPreprocessQueryMsg(pMnode->pQuery, pMsg, false); } void mndPostProcessQueryMsg(SRpcMsg *pMsg) { @@ -55,7 +55,7 @@ int32_t mndProcessQueryMsg(SRpcMsg *pMsg) { code = qWorkerProcessHbMsg(pMnode, pMnode->pQuery, pMsg, 0); break; default: - terrno = TSDB_CODE_VND_APP_ERROR; + terrno = TSDB_CODE_APP_ERROR; mError("unknown msg type:%d in query queue", pMsg->msgType); } @@ -92,7 +92,7 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) { for (int32_t i = 0; i < msgNum; ++i) { if (offset >= pMsg->contLen) { mError("offset %d is bigger than contLen %d", offset, pMsg->contLen); - terrno = TSDB_CODE_MSG_NOT_PROCESSED; + terrno = TSDB_CODE_INVALID_MSG_LEN; taosArrayDestroy(batchRsp); return -1; } @@ -101,7 +101,7 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) { offset += sizeof(req.msgIdx); if (offset >= pMsg->contLen) { mError("offset %d is bigger than contLen %d", offset, pMsg->contLen); - terrno = TSDB_CODE_MSG_NOT_PROCESSED; + terrno = TSDB_CODE_INVALID_MSG_LEN; taosArrayDestroy(batchRsp); return -1; } @@ -110,7 +110,7 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) { offset += sizeof(req.msgType); if (offset >= pMsg->contLen) { mError("offset %d is bigger than contLen %d", offset, pMsg->contLen); - terrno = TSDB_CODE_MSG_NOT_PROCESSED; + terrno = TSDB_CODE_INVALID_MSG_LEN; taosArrayDestroy(batchRsp); return -1; } @@ -119,7 +119,7 @@ int32_t mndProcessBatchMetaMsg(SRpcMsg *pMsg) { offset += sizeof(req.msgLen); if (offset >= pMsg->contLen) { mError("offset %d is bigger than contLen %d", offset, pMsg->contLen); - terrno = TSDB_CODE_MSG_NOT_PROCESSED; + terrno = TSDB_CODE_INVALID_MSG_LEN; taosArrayDestroy(batchRsp); return -1; } diff --git a/source/dnode/mnode/impl/src/mndScheduler.c b/source/dnode/mnode/impl/src/mndScheduler.c index 6c54d41818255269e9523463b60e612e49fb894c..7e7c6ee0b60242b1d2a34e17e332a2e571031c5b 100644 --- a/source/dnode/mnode/impl/src/mndScheduler.c +++ b/source/dnode/mnode/impl/src/mndScheduler.c @@ -18,7 +18,6 @@ #include "mndDb.h" #include "mndDnode.h" #include "mndMnode.h" -#include "mndOffset.h" #include "mndShow.h" #include "mndSnode.h" #include "mndStb.h" @@ -33,7 +32,7 @@ #include "tname.h" #include "tuuid.h" -extern bool tsSchedStreamToSnode; +extern bool tsDeployOnSnode; static int32_t mndAddTaskToTaskSet(SArray* pArray, SStreamTask* pTask) { int32_t childId = taosArrayGetSize(pArray); @@ -191,7 +190,7 @@ int32_t mndAssignTaskToSnode(SMnode* pMnode, SStreamTask* pTask, SSubplan* plan, pTask->nodeId = SNODE_HANDLE; pTask->epSet = mndAcquireEpFromSnode(pMnode, pSnode); - plan->execNode.nodeId = 0; + plan->execNode.nodeId = SNODE_HANDLE; plan->execNode.epSet = pTask->epSet; if (qSubPlanToString(plan, &pTask->exec.qmsg, &msgLen) < 0) { @@ -374,7 +373,7 @@ int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream) { return -1; } - if (tsSchedStreamToSnode) { + if (tsDeployOnSnode) { SSnodeObj* pSnode = mndSchedFetchOneSnode(pMnode); if (pSnode == NULL) { SVgObj* pVgroup = mndSchedFetchOneVg(pMnode, pStream->sourceDbUid); @@ -488,6 +487,7 @@ int32_t mndScheduleStream(SMnode* pMnode, SStreamObj* pStream) { qDestroyQueryPlan(pPlan); return -1; } + pTask->fillHistory = pStream->fillHistory; mndAddTaskToTaskSet(taskOneLevel, pTask); // source diff --git a/source/dnode/mnode/impl/src/mndShow.c b/source/dnode/mnode/impl/src/mndShow.c index 8b4cacf8d609ecf24b699f4cccf6306c6ada15c8..b0af98b9332743db185bb5ad763b98a3de7b6423 100644 --- a/source/dnode/mnode/impl/src/mndShow.c +++ b/source/dnode/mnode/impl/src/mndShow.c @@ -240,25 +240,22 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { return -1; } - int32_t numOfCols = pShow->pMeta->numOfColumns; - SSDataBlock *pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock)); - pBlock->pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData)); + int32_t numOfCols = pShow->pMeta->numOfColumns; + SSDataBlock *pBlock = createDataBlock(); for (int32_t i = 0; i < numOfCols; ++i) { SColumnInfoData idata = {0}; - SSchema *p = &pShow->pMeta->pSchemas[i]; + + SSchema *p = &pShow->pMeta->pSchemas[i]; idata.info.bytes = p->bytes; idata.info.type = p->type; idata.info.colId = p->colId; - - taosArrayPush(pBlock->pDataBlock, &idata); - if (IS_VAR_DATA_TYPE(p->type)) { - pBlock->info.hasVarCol = true; - } + blockDataAppendColInfo(pBlock, &idata); } blockDataEnsureCapacity(pBlock, rowsToRead); + if (mndCheckRetrieveFinished(pShow)) { mDebug("show:0x%" PRIx64 ", read finished, numOfRows:%d", pShow->id, pShow->numOfRows); rowsRead = 0; @@ -306,8 +303,7 @@ static int32_t mndProcessRetrieveSysTableReq(SRpcMsg *pReq) { pStart += sizeof(SSysTableSchema); } - int32_t len = 0; - blockEncode(pBlock, pStart, &len, pShow->pMeta->numOfColumns, false); + int32_t len = blockEncode(pBlock, pStart, pShow->pMeta->numOfColumns); } pRsp->numOfRows = htonl(rowsRead); diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index 8127d5912e9fb1f43b2d7fb84b38b4ca19114188..7753e5b1279b310fb97955c61343c9ce3cca681e 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -273,9 +273,6 @@ _OVER: } static int32_t mndProcessCreateSnodeReq(SRpcMsg *pReq) { -#if 1 - return TSDB_CODE_OPS_NOT_SUPPORT; -#else SMnode *pMnode = pReq->info.node; int32_t code = -1; SSnodeObj *pObj = NULL; @@ -318,7 +315,6 @@ _OVER: mndReleaseSnode(pMnode, pObj); mndReleaseDnode(pMnode, pDnode); return code; -#endif } static int32_t mndSetDropSnodeRedoLogs(STrans *pTrans, SSnodeObj *pObj) { @@ -364,11 +360,13 @@ static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSn return 0; } -int32_t mndSetDropSnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SSnodeObj *pObj) { +int32_t mndSetDropSnodeInfoToTrans(SMnode *pMnode, STrans *pTrans, SSnodeObj *pObj, bool force) { if (pObj == NULL) return 0; if (mndSetDropSnodeRedoLogs(pTrans, pObj) != 0) return -1; if (mndSetDropSnodeCommitLogs(pTrans, pObj) != 0) return -1; - if (mndSetDropSnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) return -1; + if (!force) { + if (mndSetDropSnodeRedoActions(pTrans, pObj->pDnode, pObj) != 0) return -1; + } return 0; } @@ -379,7 +377,7 @@ static int32_t mndDropSnode(SMnode *pMnode, SRpcMsg *pReq, SSnodeObj *pObj) { if (pTrans == NULL) goto _OVER; mInfo("trans:%d, used to drop snode:%d", pTrans->id, pObj->id); - if (mndSetDropSnodeInfoToTrans(pMnode, pTrans, pObj) != 0) goto _OVER; + if (mndSetDropSnodeInfoToTrans(pMnode, pTrans, pObj, false) != 0) goto _OVER; if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; code = 0; @@ -390,12 +388,9 @@ _OVER: } static int32_t mndProcessDropSnodeReq(SRpcMsg *pReq) { -#if 1 - return TSDB_CODE_OPS_NOT_SUPPORT; -#else - SMnode *pMnode = pReq->info.node; - int32_t code = -1; - SSnodeObj *pObj = NULL; + SMnode *pMnode = pReq->info.node; + int32_t code = -1; + SSnodeObj *pObj = NULL; SMDropSnodeReq dropReq = {0}; if (tDeserializeSCreateDropMQSNodeReq(pReq->pCont, pReq->contLen, &dropReq) != 0) { @@ -429,7 +424,6 @@ _OVER: mndReleaseSnode(pMnode, pObj); return code; -#endif } static int32_t mndRetrieveSnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 4b1906ba7039213f3507488c91dafff8c1795497..cee0b84672a6d8e5c57c6718f1f665b2ab82e934 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -466,7 +466,7 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt contLen += sizeof(SMsgHead); - SMsgHead *pHead = taosMemoryMalloc(contLen); + SMsgHead *pHead = taosMemoryCalloc(1, contLen); if (pHead == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto _err; @@ -2029,7 +2029,7 @@ static int32_t mndSetDropStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj * action.pCont = pReq; action.contLen = contLen; action.msgType = TDMT_VND_DROP_STB; - action.acceptableCode = TSDB_CODE_VND_TB_NOT_EXIST; + action.acceptableCode = TSDB_CODE_TDB_STB_NOT_EXIST; if (mndTransAppendRedoAction(pTrans, &action) != 0) { taosMemoryFree(pReq); sdbCancelFetch(pSdb, pIter); @@ -2596,4 +2596,4 @@ const char *mndGetStbStr(const char *src) { if (posStb != NULL) ++posStb; if (posStb == NULL) return posDb; return posStb; -} \ No newline at end of file +} diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index 3ff989e6707e840c7bea8a21471111b381df3831..594c13f9574347b5058512781d1d09b4cd03c009 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -287,9 +287,7 @@ static int32_t mndBuildStreamObjFromCreateReq(SMnode *pMnode, SStreamObj *pObj, memcpy(pObj->sourceDb, pCreate->sourceDB, TSDB_DB_FNAME_LEN); SDbObj *pSourceDb = mndAcquireDb(pMnode, pCreate->sourceDB); if (pSourceDb == NULL) { - /*ASSERT(0);*/ - mInfo("stream:%s failed to create, source db %s not exist", pCreate->name, pObj->sourceDb); - terrno = TSDB_CODE_MND_DB_NOT_EXIST; + mInfo("stream:%s failed to create, source db %s not exist since %s", pCreate->name, pObj->sourceDb, terrstr()); return -1; } pObj->sourceDbUid = pSourceDb->uid; @@ -298,8 +296,7 @@ static int32_t mndBuildStreamObjFromCreateReq(SMnode *pMnode, SStreamObj *pObj, SDbObj *pTargetDb = mndAcquireDbByStb(pMnode, pObj->targetSTbName); if (pTargetDb == NULL) { - mInfo("stream:%s failed to create, target db %s not exist", pCreate->name, pObj->targetDb); - terrno = TSDB_CODE_MND_DB_NOT_EXIST; + mInfo("stream:%s failed to create, target db %s not exist since %s", pCreate->name, pObj->targetDb, terrstr()); return -1; } tstrncpy(pObj->targetDb, pTargetDb->name, TSDB_DB_FNAME_LEN); @@ -557,78 +554,6 @@ static int32_t mndPersistTaskDropReq(STrans *pTrans, SStreamTask *pTask) { return 0; } -#if 0 -static int32_t mndPersistTaskRecoverReq(STrans *pTrans, SStreamTask *pTask) { - SMStreamTaskRecoverReq *pReq = taosMemoryCalloc(1, sizeof(SMStreamTaskRecoverReq)); - if (pReq == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - pReq->streamId = pTask->streamId; - pReq->taskId = pTask->taskId; - int32_t len; - int32_t code; - tEncodeSize(tEncodeSMStreamTaskRecoverReq, pReq, len, code); - if (code != 0) { - return -1; - } - void *buf = taosMemoryCalloc(1, sizeof(SMsgHead) + len); - if (buf == NULL) { - return -1; - } - void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); - SEncoder encoder; - tEncoderInit(&encoder, abuf, len); - tEncodeSMStreamTaskRecoverReq(&encoder, pReq); - ((SMsgHead *)buf)->vgId = pTask->nodeId; - - STransAction action = {0}; - memcpy(&action.epSet, &pTask->epSet, sizeof(SEpSet)); - action.pCont = buf; - action.contLen = sizeof(SMsgHead) + len; - action.msgType = TDMT_STREAM_TASK_RECOVER; - if (mndTransAppendRedoAction(pTrans, &action) != 0) { - taosMemoryFree(buf); - return -1; - } - return 0; -} - -int32_t mndRecoverStreamTasks(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { - if (pStream->isDistributed) { - int32_t lv = taosArrayGetSize(pStream->tasks); - for (int32_t i = 0; i < lv; i++) { - SArray *pTasks = taosArrayGetP(pStream->tasks, i); - int32_t sz = taosArrayGetSize(pTasks); - SStreamTask *pTask = taosArrayGetP(pTasks, 0); - if (pTask->taskLevel == TASK_LEVEL__AGG) { - ASSERT(sz == 1); - if (mndPersistTaskRecoverReq(pTrans, pTask) < 0) { - return -1; - } - } else { - continue; - } - } - } else { - int32_t lv = taosArrayGetSize(pStream->tasks); - for (int32_t i = 0; i < lv; i++) { - SArray *pTasks = taosArrayGetP(pStream->tasks, i); - int32_t sz = taosArrayGetSize(pTasks); - for (int32_t j = 0; j < sz; j++) { - SStreamTask *pTask = taosArrayGetP(pTasks, j); - if (pTask->taskLevel != TASK_LEVEL__SOURCE) break; - ASSERT(pTask->taskLevel != TASK_LEVEL__SINK); - if (mndPersistTaskRecoverReq(pTrans, pTask) < 0) { - return -1; - } - } - } - } - return 0; -} -#endif - int32_t mndDropStreamTasks(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { int32_t lv = taosArrayGetSize(pStream->tasks); for (int32_t i = 0; i < lv; i++) { @@ -777,7 +702,8 @@ static int32_t mndProcessDropStreamReq(SRpcMsg *pReq) { return -1; } - STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, pReq, "drop-stream"); + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_DB_INSIDE, pReq, "drop-stream"); + mndTransSetDbName(pTrans, pStream->sourceDb, pStream->targetDb); if (pTrans == NULL) { mError("stream:%s, failed to drop since %s", dropReq.name, terrstr()); sdbRelease(pMnode->pSdb, pStream); diff --git a/source/dnode/mnode/impl/src/mndSubscribe.c b/source/dnode/mnode/impl/src/mndSubscribe.c index 3c81c2f733a8b21447e6c74829ae1498dda78d58..a62f15f978bba618668ff2df5d0146db8c40f531 100644 --- a/source/dnode/mnode/impl/src/mndSubscribe.c +++ b/source/dnode/mnode/impl/src/mndSubscribe.c @@ -19,7 +19,6 @@ #include "mndDb.h" #include "mndDnode.h" #include "mndMnode.h" -#include "mndOffset.h" #include "mndScheduler.h" #include "mndShow.h" #include "mndStb.h" @@ -74,11 +73,11 @@ int32_t mndInitSubscribe(SMnode *pMnode) { .deleteFp = (SdbDeleteFp)mndSubActionDelete, }; - mndSetMsgHandle(pMnode, TDMT_VND_MQ_VG_CHANGE_RSP, mndTransProcessRsp); - mndSetMsgHandle(pMnode, TDMT_VND_MQ_VG_DELETE_RSP, mndTransProcessRsp); - mndSetMsgHandle(pMnode, TDMT_MND_MQ_DO_REBALANCE, mndProcessRebalanceReq); - mndSetMsgHandle(pMnode, TDMT_MND_MQ_DROP_CGROUP, mndProcessDropCgroupReq); - mndSetMsgHandle(pMnode, TDMT_MND_MQ_DROP_CGROUP_RSP, mndTransProcessRsp); + mndSetMsgHandle(pMnode, TDMT_VND_TMQ_SUBSCRIBE_RSP, mndTransProcessRsp); + mndSetMsgHandle(pMnode, TDMT_VND_TMQ_DELETE_SUB_RSP, mndTransProcessRsp); + mndSetMsgHandle(pMnode, TDMT_MND_TMQ_DO_REBALANCE, mndProcessRebalanceReq); + mndSetMsgHandle(pMnode, TDMT_MND_TMQ_DROP_CGROUP, mndProcessDropCgroupReq); + mndSetMsgHandle(pMnode, TDMT_MND_TMQ_DROP_CGROUP_RSP, mndTransProcessRsp); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_SUBSCRIPTIONS, mndRetrieveSubscribe); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndCancelGetNextSubscribe); @@ -165,7 +164,7 @@ static int32_t mndPersistSubChangeVgReq(SMnode *pMnode, STrans *pTrans, const SM action.epSet = mndGetVgroupEpset(pMnode, pVgObj); action.pCont = buf; action.contLen = tlen; - action.msgType = TDMT_VND_MQ_VG_CHANGE; + action.msgType = TDMT_VND_TMQ_SUBSCRIBE; mndReleaseVgroup(pMnode, pVgObj); if (mndTransAppendRedoAction(pTrans, &action) != 0) { @@ -613,14 +612,14 @@ static int32_t mndProcessRebalanceReq(SRpcMsg *pMsg) { mndReleaseSubscribe(pMnode, pSub); } - // TODO replace assert with error check - ASSERT(mndDoRebalance(pMnode, &rebInput, &rebOutput) == 0); + if (mndDoRebalance(pMnode, &rebInput, &rebOutput) < 0) { + mError("mq rebalance internal error"); + } // if add more consumer to balanced subscribe, // possibly no vg is changed /*ASSERT(taosArrayGetSize(rebOutput.rebVgs) != 0);*/ - // TODO replace assert with error check if (mndPersistRebResult(pMnode, pMsg, &rebOutput) < 0) { mError("mq rebalance persist rebalance output error, possibly vnode splitted or dropped"); } @@ -683,12 +682,6 @@ static int32_t mndProcessDropCgroupReq(SRpcMsg *pReq) { mInfo("trans:%d, used to drop cgroup:%s on topic %s", pTrans->id, dropReq.cgroup, dropReq.topic); - if (mndDropOffsetBySubKey(pMnode, pTrans, pSub->key) < 0) { - mndReleaseSubscribe(pMnode, pSub); - mndTransDrop(pTrans); - return -1; - } - if (mndSetDropSubCommitLogs(pMnode, pTrans, pSub) < 0) { mError("cgroup %s on topic:%s, failed to drop since %s", dropReq.cgroup, dropReq.topic, terrstr()); mndReleaseSubscribe(pMnode, pSub); @@ -927,7 +920,7 @@ int32_t mndDropSubByTopic(SMnode *pMnode, STrans *pTrans, const char *topicName) action.epSet = pVgEp->epSet; action.pCont = pReq; action.contLen = sizeof(SMqVDeleteReq); - action.msgType = TDMT_VND_MQ_VG_DELETE; + action.msgType = TDMT_VND_TMQ_DELETE_SUB; if (mndTransAppendRedoAction(pTrans, &action) != 0) { taosMemoryFree(pReq); return -1; diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index df4b526775539996f1895cf34f334367a01e9f9e..450d7a30ed1f0863c4bfafcd0725a5151ff00146 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -17,11 +17,44 @@ #include "mndSync.h" #include "mndTrans.h" +static int32_t mndSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) { + if (pMsg == NULL || pMsg->pCont == NULL) { + return -1; + } + + SMsgHead *pHead = pMsg->pCont; + pHead->contLen = htonl(pHead->contLen); + pHead->vgId = htonl(pHead->vgId); + + if (msgcb == NULL || msgcb->putToQueueFp == NULL) { + rpcFreeCont(pMsg->pCont); + pMsg->pCont = NULL; + return -1; + } + + int32_t code = tmsgPutToQueue(msgcb, SYNC_CTRL_QUEUE, pMsg); + if (code != 0) { + rpcFreeCont(pMsg->pCont); + pMsg->pCont = NULL; + } + return code; +} + static int32_t mndSyncEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) { + if (pMsg == NULL || pMsg->pCont == NULL) { + return -1; + } + SMsgHead *pHead = pMsg->pCont; pHead->contLen = htonl(pHead->contLen); pHead->vgId = htonl(pHead->vgId); + if (msgcb == NULL || msgcb->putToQueueFp == NULL) { + rpcFreeCont(pMsg->pCont); + pMsg->pCont = NULL; + return -1; + } + int32_t code = tmsgPutToQueue(msgcb, SYNC_QUEUE, pMsg); if (code != 0) { rpcFreeCont(pMsg->pCont); @@ -39,25 +72,25 @@ static int32_t mndSyncSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) { return code; } -void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { +void mndSyncCommitMsg(const SSyncFSM *pFsm, const SRpcMsg *pMsg, const SFsmCbMeta *pMeta) { SMnode *pMnode = pFsm->data; SSyncMgmt *pMgmt = &pMnode->syncMgmt; SSdbRaw *pRaw = pMsg->pCont; // delete msg handle SRpcMsg rpcMsg = {0}; - syncGetAndDelRespRpc(pMnode->syncMgmt.sync, cbMeta.seqNum, &rpcMsg.info); + rpcMsg.info = pMsg->info; int32_t transId = sdbGetIdFromRaw(pMnode->pSdb, pRaw); - pMgmt->errCode = cbMeta.code; + pMgmt->errCode = pMeta->code; mInfo("trans:%d, is proposed, saved:%d code:0x%x, apply index:%" PRId64 " term:%" PRIu64 " config:%" PRId64 " role:%s raw:%p", - transId, pMgmt->transId, cbMeta.code, cbMeta.index, cbMeta.term, cbMeta.lastConfigIndex, syncStr(cbMeta.state), + transId, pMgmt->transId, pMeta->code, pMeta->index, pMeta->term, pMeta->lastConfigIndex, syncStr(pMeta->state), pRaw); if (pMgmt->errCode == 0) { sdbWriteWithoutFree(pMnode->pSdb, pRaw); - sdbSetApplyInfo(pMnode->pSdb, cbMeta.index, cbMeta.term, cbMeta.lastConfigIndex); + sdbSetApplyInfo(pMnode->pSdb, pMeta->index, pMeta->term, pMeta->lastConfigIndex); } taosWLockLatch(&pMgmt->lock); @@ -87,7 +120,7 @@ void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbM } } -int32_t mndSyncGetSnapshot(struct SSyncFSM *pFsm, SSnapshot *pSnapshot, void *pReaderParam, void **ppReader) { +int32_t mndSyncGetSnapshot(const SSyncFSM *pFsm, SSnapshot *pSnapshot, void *pReaderParam, void **ppReader) { mInfo("start to read snapshot from sdb in atomic way"); SMnode *pMnode = pFsm->data; return sdbStartRead(pMnode->pSdb, (SSdbIter **)ppReader, &pSnapshot->lastApplyIndex, &pSnapshot->lastApplyTerm, @@ -95,13 +128,13 @@ int32_t mndSyncGetSnapshot(struct SSyncFSM *pFsm, SSnapshot *pSnapshot, void *pR return 0; } -int32_t mndSyncGetSnapshotInfo(struct SSyncFSM *pFsm, SSnapshot *pSnapshot) { +int32_t mndSyncGetSnapshotInfo(const SSyncFSM *pFsm, SSnapshot *pSnapshot) { SMnode *pMnode = pFsm->data; sdbGetCommitInfo(pMnode->pSdb, &pSnapshot->lastApplyIndex, &pSnapshot->lastApplyTerm, &pSnapshot->lastConfigIndex); return 0; } -void mndRestoreFinish(struct SSyncFSM *pFsm) { +void mndRestoreFinish(const SSyncFSM *pFsm) { SMnode *pMnode = pFsm->data; if (!pMnode->deploy) { @@ -113,32 +146,30 @@ void mndRestoreFinish(struct SSyncFSM *pFsm) { } } -void mndReConfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta *cbMeta) {} - -int32_t mndSnapshotStartRead(struct SSyncFSM *pFsm, void *pParam, void **ppReader) { +int32_t mndSnapshotStartRead(const SSyncFSM *pFsm, void *pParam, void **ppReader) { mInfo("start to read snapshot from sdb"); SMnode *pMnode = pFsm->data; return sdbStartRead(pMnode->pSdb, (SSdbIter **)ppReader, NULL, NULL, NULL); } -int32_t mndSnapshotStopRead(struct SSyncFSM *pFsm, void *pReader) { +int32_t mndSnapshotStopRead(const SSyncFSM *pFsm, void *pReader) { mInfo("stop to read snapshot from sdb"); SMnode *pMnode = pFsm->data; return sdbStopRead(pMnode->pSdb, pReader); } -int32_t mndSnapshotDoRead(struct SSyncFSM *pFsm, void *pReader, void **ppBuf, int32_t *len) { +int32_t mndSnapshotDoRead(const SSyncFSM *pFsm, void *pReader, void **ppBuf, int32_t *len) { SMnode *pMnode = pFsm->data; return sdbDoRead(pMnode->pSdb, pReader, ppBuf, len); } -int32_t mndSnapshotStartWrite(struct SSyncFSM *pFsm, void *pParam, void **ppWriter) { +int32_t mndSnapshotStartWrite(const SSyncFSM *pFsm, void *pParam, void **ppWriter) { mInfo("start to apply snapshot to sdb"); SMnode *pMnode = pFsm->data; return sdbStartWrite(pMnode->pSdb, (SSdbIter **)ppWriter); } -int32_t mndSnapshotStopWrite(struct SSyncFSM *pFsm, void *pWriter, bool isApply, SSnapshot *pSnapshot) { +int32_t mndSnapshotStopWrite(const SSyncFSM *pFsm, void *pWriter, bool isApply, SSnapshot *pSnapshot) { mInfo("stop to apply snapshot to sdb, apply:%d, index:%" PRId64 " term:%" PRIu64 " config:%" PRId64, isApply, pSnapshot->lastApplyIndex, pSnapshot->lastApplyTerm, pSnapshot->lastConfigIndex); SMnode *pMnode = pFsm->data; @@ -146,18 +177,12 @@ int32_t mndSnapshotStopWrite(struct SSyncFSM *pFsm, void *pWriter, bool isApply, pSnapshot->lastConfigIndex); } -int32_t mndSnapshotDoWrite(struct SSyncFSM *pFsm, void *pWriter, void *pBuf, int32_t len) { +int32_t mndSnapshotDoWrite(const SSyncFSM *pFsm, void *pWriter, void *pBuf, int32_t len) { SMnode *pMnode = pFsm->data; return sdbDoWrite(pMnode->pSdb, pWriter, pBuf, len); } -void mndLeaderTransfer(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { - SMnode *pMnode = pFsm->data; - atomic_store_8(&(pMnode->syncMgmt.leaderTransferFinish), 1); - mInfo("vgId:1, mnode leader transfer finish"); -} - -static void mndBecomeFollower(struct SSyncFSM *pFsm) { +static void mndBecomeFollower(const SSyncFSM *pFsm) { SMnode *pMnode = pFsm->data; mInfo("vgId:1, become follower"); @@ -172,11 +197,33 @@ static void mndBecomeFollower(struct SSyncFSM *pFsm) { taosWUnLockLatch(&pMnode->syncMgmt.lock); } -static void mndBecomeLeader(struct SSyncFSM *pFsm) { +static void mndBecomeLeader(const SSyncFSM *pFsm) { mInfo("vgId:1, become leader"); SMnode *pMnode = pFsm->data; } +static bool mndApplyQueueEmpty(const SSyncFSM *pFsm) { + SMnode *pMnode = pFsm->data; + + if (pMnode != NULL && pMnode->msgCb.qsizeFp != NULL) { + int32_t itemSize = tmsgGetQueueSize(&pMnode->msgCb, 1, APPLY_QUEUE); + return (itemSize == 0); + } else { + return true; + } +} + +static int32_t mndApplyQueueItems(const SSyncFSM *pFsm) { + SMnode *pMnode = pFsm->data; + + if (pMnode != NULL && pMnode->msgCb.qsizeFp != NULL) { + int32_t itemSize = tmsgGetQueueSize(&pMnode->msgCb, 1, APPLY_QUEUE); + return itemSize; + } else { + return -1; + } +} + SSyncFSM *mndSyncMakeFsm(SMnode *pMnode) { SSyncFSM *pFsm = taosMemoryCalloc(1, sizeof(SSyncFSM)); pFsm->data = pMnode; @@ -184,8 +231,10 @@ SSyncFSM *mndSyncMakeFsm(SMnode *pMnode) { pFsm->FpPreCommitCb = NULL; pFsm->FpRollBackCb = NULL; pFsm->FpRestoreFinishCb = mndRestoreFinish; - pFsm->FpLeaderTransferCb = mndLeaderTransfer; - pFsm->FpReConfigCb = mndReConfig; + pFsm->FpLeaderTransferCb = NULL; + pFsm->FpApplyQueueEmptyCb = mndApplyQueueEmpty; + pFsm->FpApplyQueueItems = mndApplyQueueItems; + pFsm->FpReConfigCb = NULL; pFsm->FpBecomeLeaderCb = mndBecomeLeader; pFsm->FpBecomeFollowerCb = mndBecomeFollower; pFsm->FpGetSnapshot = mndSyncGetSnapshot; @@ -209,10 +258,13 @@ int32_t mndInitSync(SMnode *pMnode) { .batchSize = 1, .vgId = 1, .pWal = pMnode->pWal, - .msgcb = NULL, - .FpSendMsg = mndSyncSendMsg, - .FpEqMsg = mndSyncEqMsg, - .FpEqCtrlMsg = NULL, + .msgcb = &pMnode->msgCb, + .syncSendMSg = mndSyncSendMsg, + .syncEqMsg = mndSyncEqMsg, + .syncEqCtrlMsg = mndSyncEqCtrlMsg, + .pingMs = 5000, + .electMs = 3000, + .heartbeatMs = 500, }; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", pMnode->path, TD_DIRSEP); @@ -236,11 +288,6 @@ int32_t mndInitSync(SMnode *pMnode) { return -1; } - // decrease election timer - setPingTimerMS(pMgmt->sync, 5000); - setElectTimerMS(pMgmt->sync, 3000); - setHeartbeatTimerMS(pMgmt->sync, 500); - mInfo("mnode-sync is opened, id:%" PRId64, pMgmt->sync); return 0; } @@ -256,32 +303,28 @@ void mndCleanupSync(SMnode *pMnode) { int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; - SRpcMsg req = {.msgType = TDMT_MND_APPLY_MSG, .contLen = sdbGetRawTotalSize(pRaw)}; - if (req.contLen <= 0) { - terrno = TSDB_CODE_APP_ERROR; - return -1; - } + pMgmt->errCode = 0; + + SRpcMsg req = {.msgType = TDMT_MND_APPLY_MSG, .contLen = sdbGetRawTotalSize(pRaw)}; + if (req.contLen <= 0) return -1; req.pCont = rpcMallocCont(req.contLen); if (req.pCont == NULL) return -1; memcpy(req.pCont, pRaw, req.contLen); - pMgmt->errCode = 0; taosWLockLatch(&pMgmt->lock); if (pMgmt->transId != 0) { - mError("trans:%d, can't be proposed since trans:%d alrady waiting for confirm", transId, pMgmt->transId); + mError("trans:%d, can't be proposed since trans:%d already waiting for confirm", transId, pMgmt->transId); taosWUnLockLatch(&pMgmt->lock); terrno = TSDB_CODE_APP_NOT_READY; return -1; - } else { - pMgmt->transId = transId; - mInfo("trans:%d, will be proposed", pMgmt->transId); - taosWUnLockLatch(&pMgmt->lock); } - const bool isWeak = false; - int32_t code = syncPropose(pMgmt->sync, &req, isWeak); + mInfo("trans:%d, will be proposed", transId); + pMgmt->transId = transId; + taosWUnLockLatch(&pMgmt->lock); + int32_t code = syncPropose(pMgmt->sync, &req, false); if (code == 0) { mInfo("trans:%d, is proposing and wait sem", pMgmt->transId); tsem_wait(&pMgmt->syncSem); @@ -294,8 +337,8 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) { sdbSetApplyInfo(pMnode->pSdb, req.info.conn.applyIndex, req.info.conn.applyTerm, SYNC_INDEX_INVALID); code = 0; } else { - taosWLockLatch(&pMgmt->lock); mInfo("trans:%d, failed to proposed since %s", transId, terrstr()); + taosWLockLatch(&pMgmt->lock); pMgmt->transId = 0; taosWUnLockLatch(&pMgmt->lock); if (terrno == TSDB_CODE_SYN_NOT_LEADER) { @@ -311,13 +354,12 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) { return code; } - if (pMgmt->errCode != 0) terrno = pMgmt->errCode; + terrno = pMgmt->errCode; return pMgmt->errCode; } void mndSyncStart(SMnode *pMnode) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; - syncSetMsgCb(pMgmt->sync, &pMnode->msgCb); syncStart(pMgmt->sync); mInfo("vgId:1, sync started, id:%" PRId64, pMgmt->sync); } @@ -333,11 +375,15 @@ void mndSyncStop(SMnode *pMnode) { } bool mndIsLeader(SMnode *pMnode) { - SSyncMgmt *pMgmt = &pMnode->syncMgmt; + SSyncState state = syncGetState(pMnode->syncMgmt.sync); - if (!syncIsReady(pMgmt->sync)) { - // get terrno from syncIsReady - // terrno = TSDB_CODE_SYN_NOT_LEADER; + if (state.state != TAOS_SYNC_STATE_LEADER || !state.restored) { + if (state.state != TAOS_SYNC_STATE_LEADER) { + terrno = TSDB_CODE_SYN_NOT_LEADER; + } else { + terrno = TSDB_CODE_APP_NOT_READY; + } + mDebug("vgId:1, mnode not ready, state:%s, restore:%d", syncStr(state.state), state.restored); return false; } diff --git a/source/dnode/mnode/impl/src/mndTelem.c b/source/dnode/mnode/impl/src/mndTelem.c index ff2461b63b41da33df1a6c2479ed8d58e963a484..1d3209691adae6c917f430a2e6eb716951aefedf 100644 --- a/source/dnode/mnode/impl/src/mndTelem.c +++ b/source/dnode/mnode/impl/src/mndTelem.c @@ -127,8 +127,10 @@ static int32_t mndProcessTelemTimer(SRpcMsg* pReq) { STelemMgmt* pMgmt = &pMnode->telemMgmt; if (!tsEnableTelem) return 0; - taosWLockLatch(&pMgmt->lock); + taosThreadMutexLock(&pMgmt->lock); char* pCont = mndBuildTelemetryReport(pMnode); + taosThreadMutexUnlock(&pMgmt->lock); + if (pCont != NULL) { if (taosSendHttpReport(tsTelemServer, tsTelemPort, pCont, strlen(pCont), HTTP_FLAT) != 0) { mError("failed to send telemetry report"); @@ -137,18 +139,20 @@ static int32_t mndProcessTelemTimer(SRpcMsg* pReq) { } taosMemoryFree(pCont); } - taosWUnLockLatch(&pMgmt->lock); return 0; } int32_t mndInitTelem(SMnode* pMnode) { STelemMgmt* pMgmt = &pMnode->telemMgmt; - taosInitRWLatch(&pMgmt->lock); + taosThreadMutexInit(&pMgmt->lock, NULL); taosGetEmail(pMgmt->email, sizeof(pMgmt->email)); mndSetMsgHandle(pMnode, TDMT_MND_TELEM_TIMER, mndProcessTelemTimer); return 0; } -void mndCleanupTelem(SMnode* pMnode) {} +void mndCleanupTelem(SMnode* pMnode) { + STelemMgmt* pMgmt = &pMnode->telemMgmt; + taosThreadMutexDestroy(&pMgmt->lock); +} diff --git a/source/dnode/mnode/impl/src/mndTopic.c b/source/dnode/mnode/impl/src/mndTopic.c index 90ac69423c5f496bebc156b290264e990cacd615..e1ca1d2708e4e0d05ed2018d8f62500352518795 100644 --- a/source/dnode/mnode/impl/src/mndTopic.c +++ b/source/dnode/mnode/impl/src/mndTopic.c @@ -18,7 +18,6 @@ #include "mndDb.h" #include "mndDnode.h" #include "mndMnode.h" -#include "mndOffset.h" #include "mndPrivilege.h" #include "mndShow.h" #include "mndStb.h" @@ -54,11 +53,10 @@ int32_t mndInitTopic(SMnode *pMnode) { .deleteFp = (SdbDeleteFp)mndTopicActionDelete, }; - mndSetMsgHandle(pMnode, TDMT_MND_CREATE_TOPIC, mndProcessCreateTopicReq); - mndSetMsgHandle(pMnode, TDMT_MND_DROP_TOPIC, mndProcessDropTopicReq); - mndSetMsgHandle(pMnode, TDMT_VND_DROP_TOPIC_RSP, mndTransProcessRsp); - mndSetMsgHandle(pMnode, TDMT_VND_ADD_CHECK_INFO_RSP, mndTransProcessRsp); - mndSetMsgHandle(pMnode, TDMT_VND_DELETE_CHECK_INFO_RSP, mndTransProcessRsp); + mndSetMsgHandle(pMnode, TDMT_MND_TMQ_CREATE_TOPIC, mndProcessCreateTopicReq); + mndSetMsgHandle(pMnode, TDMT_MND_TMQ_DROP_TOPIC, mndProcessDropTopicReq); + mndSetMsgHandle(pMnode, TDMT_VND_TMQ_ADD_CHECKINFO_RSP, mndTransProcessRsp); + mndSetMsgHandle(pMnode, TDMT_VND_TMQ_DEL_CHECKINFO_RSP, mndTransProcessRsp); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndRetrieveTopic); mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndCancelGetNextTopic); @@ -507,7 +505,7 @@ static int32_t mndCreateTopic(SMnode *pMnode, SRpcMsg *pReq, SCMCreateTopicReq * action.epSet = mndGetVgroupEpset(pMnode, pVgroup); action.pCont = buf; action.contLen = sizeof(SMsgHead) + len; - action.msgType = TDMT_VND_ADD_CHECK_INFO; + action.msgType = TDMT_VND_TMQ_ADD_CHECKINFO; if (mndTransAppendRedoAction(pTrans, &action) != 0) { taosMemoryFree(buf); sdbRelease(pSdb, pVgroup); @@ -716,7 +714,7 @@ static int32_t mndProcessDropTopicReq(SRpcMsg *pReq) { action.epSet = mndGetVgroupEpset(pMnode, pVgroup); action.pCont = buf; action.contLen = sizeof(SMsgHead) + TSDB_TOPIC_FNAME_LEN; - action.msgType = TDMT_VND_DELETE_CHECK_INFO; + action.msgType = TDMT_VND_TMQ_DEL_CHECKINFO; if (mndTransAppendRedoAction(pTrans, &action) != 0) { taosMemoryFree(buf); sdbRelease(pSdb, pVgroup); diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 6a606a1a7ef2e0e758eba3e8f52705315c514f6b..db878d72b956fb05030ab8203342d16b7dcae652 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -375,7 +375,7 @@ static SSdbRow *mndTransActionDecode(SSdbRaw *pRaw) { if (taosArrayPush(pTrans->undoActions, &action) == NULL) goto _OVER; action.pCont = NULL; } else { - if (taosArrayPush(pTrans->redoActions, &action) == NULL) goto _OVER; + if (taosArrayPush(pTrans->undoActions, &action) == NULL) goto _OVER; } } @@ -938,11 +938,15 @@ static void mndTransSendRpcRsp(SMnode *pMnode, STrans *pTrans) { for (int32_t i = 0; i < size; ++i) { SRpcHandleInfo *pInfo = taosArrayGet(pTrans->pRpcArray, i); if (pInfo->handle != NULL) { - mInfo("trans:%d, send rsp, code:0x%x stage:%s app:%p", pTrans->id, code, mndTransStr(pTrans->stage), - pInfo->ahandle); if (code == TSDB_CODE_RPC_NETWORK_UNAVAIL) { code = TSDB_CODE_MND_TRANS_NETWORK_UNAVAILL; } + if (i != 0 && code == 0) { + code = TSDB_CODE_RPC_REDIRECT; + } + mInfo("trans:%d, client:%d send rsp, code:0x%x stage:%s app:%p", pTrans->id, i, code, mndTransStr(pTrans->stage), + pInfo->ahandle); + SRpcMsg rspMsg = {.code = code, .info = *pInfo}; if (pTrans->originRpcType == TDMT_MND_CREATE_DB) { diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 23397cedc6f37c1a3ccc072d03f8a5f19c47bd54..e00d0d955ec820176cb696fa652c5e7fdd374edb 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -60,7 +60,7 @@ int32_t mndInitVgroup(SMnode *pMnode) { mndSetMsgHandle(pMnode, TDMT_VND_COMPACT_RSP, mndTransProcessRsp); mndSetMsgHandle(pMnode, TDMT_MND_REDISTRIBUTE_VGROUP, mndProcessRedistributeVgroupMsg); - mndSetMsgHandle(pMnode, TDMT_MND_MERGE_VGROUP, mndProcessSplitVgroupMsg); + mndSetMsgHandle(pMnode, TDMT_MND_SPLIT_VGROUP, mndProcessSplitVgroupMsg); mndSetMsgHandle(pMnode, TDMT_MND_BALANCE_VGROUP, mndProcessBalanceVgroupMsg); mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_VGROUP, mndRetrieveVgroups); @@ -325,10 +325,10 @@ static void *mndBuildAlterVnodeConfigReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pV static void *mndBuildAlterVnodeReplicaReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgroup, int32_t dnodeId, int32_t *pContLen) { SAlterVnodeReplicaReq alterReq = { - alterReq.vgId = pVgroup->vgId, - alterReq.strict = pDb->cfg.strict, - alterReq.replica = pVgroup->replica, - alterReq.selfIndex = -1, + .vgId = pVgroup->vgId, + .strict = pDb->cfg.strict, + .replica = pVgroup->replica, + .selfIndex = -1, }; for (int32_t v = 0; v < pVgroup->replica; ++v) { @@ -617,35 +617,6 @@ SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup) { return epset; } -static bool mndGetVgroupMaxReplicaFp(SMnode *pMnode, void *pObj, void *p1, void *p2, void *p3) { - SVgObj *pVgroup = pObj; - int64_t uid = *(int64_t *)p1; - int8_t *pReplica = p2; - int32_t *pNumOfVgroups = p3; - - if (pVgroup->dbUid == uid) { - *pReplica = TMAX(*pReplica, pVgroup->replica); - (*pNumOfVgroups)++; - } - - return true; -} - -static int32_t mndGetVgroupMaxReplica(SMnode *pMnode, char *dbName, int8_t *pReplica, int32_t *pNumOfVgroups) { - SSdb *pSdb = pMnode->pSdb; - SDbObj *pDb = mndAcquireDb(pMnode, dbName); - if (pDb == NULL) { - terrno = TSDB_CODE_MND_DB_NOT_SELECTED; - return -1; - } - - *pReplica = 1; - *pNumOfVgroups = 0; - sdbTraverse(pSdb, SDB_VGROUP, mndGetVgroupMaxReplicaFp, &pDb->uid, pReplica, pNumOfVgroups); - mndReleaseDb(pMnode, pDb); - return 0; -} - static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { SMnode *pMnode = pReq->info.node; SSdb *pSdb = pMnode->pSdb; @@ -1100,7 +1071,7 @@ int32_t mndAddDropVnodeAction(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgOb } int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, SVgObj *pVgroup, int32_t vnIndex, - SArray *pArray) { + SArray *pArray, bool force) { SVgObj newVg = {0}; memcpy(&newVg, pVgroup, sizeof(SVgObj)); @@ -1109,20 +1080,45 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, mInfo("vgId:%d, vnode:%d dnode:%d", newVg.vgId, i, newVg.vnodeGid[i].dnodeId); } - mInfo("vgId:%d, will add 1 vnodes", pVgroup->vgId); - if (mndAddVnodeToVgroup(pMnode, &newVg, pArray) != 0) return -1; - if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVg, &newVg.vnodeGid[newVg.replica - 1]) != 0) return -1; - if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg, -1) != 0) return -1; - if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1; + if (!force) { + mInfo("vgId:%d, will add 1 vnode", pVgroup->vgId); + if (mndAddVnodeToVgroup(pMnode, &newVg, pArray) != 0) return -1; + if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVg, &newVg.vnodeGid[newVg.replica - 1]) != 0) return -1; + for (int32_t i = 0; i < newVg.replica - 1; ++i) { + if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg, newVg.vnodeGid[i].dnodeId) != 0) return -1; + } + if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1; + + mInfo("vgId:%d, will remove 1 vnode", pVgroup->vgId); + newVg.replica--; + SVnodeGid del = newVg.vnodeGid[vnIndex]; + newVg.vnodeGid[vnIndex] = newVg.vnodeGid[newVg.replica]; + memset(&newVg.vnodeGid[newVg.replica], 0, sizeof(SVnodeGid)); + if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg, &del, true) != 0) return -1; + for (int32_t i = 0; i < newVg.replica; ++i) { + if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg, newVg.vnodeGid[i].dnodeId) != 0) return -1; + } + if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1; + } else { + mInfo("vgId:%d, will add 1 vnode and force remove 1 vnode", pVgroup->vgId); + if (mndAddVnodeToVgroup(pMnode, &newVg, pArray) != 0) return -1; + newVg.replica--; + SVnodeGid del = newVg.vnodeGid[vnIndex]; + newVg.vnodeGid[vnIndex] = newVg.vnodeGid[newVg.replica]; + memset(&newVg.vnodeGid[newVg.replica], 0, sizeof(SVnodeGid)); + + if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVg, &newVg.vnodeGid[vnIndex]) != 0) return -1; + for (int32_t i = 0; i < newVg.replica; ++i) { + if (i != vnIndex) { + if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg, newVg.vnodeGid[i].dnodeId) != 0) return -1; + } + } + if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1; - mInfo("vgId:%d, will remove 1 vnodes", pVgroup->vgId); - newVg.replica--; - SVnodeGid del = newVg.vnodeGid[vnIndex]; - newVg.vnodeGid[vnIndex] = newVg.vnodeGid[newVg.replica]; - memset(&newVg.vnodeGid[newVg.replica], 0, sizeof(SVnodeGid)); - if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg, -1) != 0) return -1; - if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg, &del, true) != 0) return -1; - if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg) != 0) return -1; + if (newVg.replica == 1) { + mInfo("vgId:%d, all data is dropped since replica=1", pVgroup->vgId); + } + } { SSdbRaw *pRaw = mndVgroupActionEncode(&newVg); @@ -1145,7 +1141,7 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, return 0; } -int32_t mndSetMoveVgroupsInfoToTrans(SMnode *pMnode, STrans *pTrans, int32_t delDnodeId) { +int32_t mndSetMoveVgroupsInfoToTrans(SMnode *pMnode, STrans *pTrans, int32_t delDnodeId, bool force) { int32_t code = 0; SArray *pArray = mndBuildDnodesArray(pMnode, delDnodeId); if (pArray == NULL) return -1; @@ -1166,9 +1162,9 @@ int32_t mndSetMoveVgroupsInfoToTrans(SMnode *pMnode, STrans *pTrans, int32_t del code = 0; if (vnIndex != -1) { - mInfo("vgId:%d, vnode:%d will be removed from dnode:%d", pVgroup->vgId, vnIndex, delDnodeId); + mInfo("vgId:%d, vnode:%d will be removed from dnode:%d, force:%d", pVgroup->vgId, vnIndex, delDnodeId, force); SDbObj *pDb = mndAcquireDb(pMnode, pVgroup->dbName); - code = mndSetMoveVgroupInfoToTrans(pMnode, pTrans, pDb, pVgroup, vnIndex, pArray); + code = mndSetMoveVgroupInfoToTrans(pMnode, pTrans, pDb, pVgroup, vnIndex, pArray, force); mndReleaseDb(pMnode, pDb); } @@ -1193,21 +1189,11 @@ static int32_t mndAddIncVgroupReplicaToTrans(SMnode *pMnode, STrans *pTrans, SDb pGid->dnodeId = newDnodeId; pGid->syncState = TAOS_SYNC_STATE_ERROR; - if (pVgroup->replica == 2) { - if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, pVgroup, pGid) != 0) return -1; - if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, pVgroup->vnodeGid[0].dnodeId) != 0) return -1; - if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1; - } else if (pVgroup->replica == 4) { - if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, pVgroup, pGid) != 0) return -1; - if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, pVgroup->vnodeGid[0].dnodeId) != 0) return -1; - if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, pVgroup->vnodeGid[1].dnodeId) != 0) return -1; - if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, pVgroup->vnodeGid[2].dnodeId) != 0) return -1; - if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1; - } else { - mError("vgId:%d, failed to add 1 vnode since invalid replica:%d", pVgroup->vgId, pVgroup->replica); - terrno = TSDB_CODE_MND_APP_ERROR; - return -1; + if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, pVgroup, pGid) != 0) return -1; + for (int32_t i = 0; i < pVgroup->replica - 1; ++i) { + if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, pVgroup->vnodeGid[i].dnodeId) != 0) return -1; } + if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1; return 0; } @@ -1232,21 +1218,11 @@ static int32_t mndAddDecVgroupReplicaFromTrans(SMnode *pMnode, STrans *pTrans, S memcpy(pGid, &pVgroup->vnodeGid[pVgroup->replica], sizeof(SVnodeGid)); memset(&pVgroup->vnodeGid[pVgroup->replica], 0, sizeof(SVnodeGid)); - if (pVgroup->replica == 1) { - if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, pVgroup->vnodeGid[0].dnodeId) != 0) return -1; - if (mndAddDropVnodeAction(pMnode, pTrans, pDb, pVgroup, &delGid, true) != 0) return -1; - if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1; - } else if (pVgroup->replica == 3) { - if (mndAddDropVnodeAction(pMnode, pTrans, pDb, pVgroup, &delGid, true) != 0) return -1; - if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, pVgroup->vnodeGid[0].dnodeId) != 0) return -1; - if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, pVgroup->vnodeGid[1].dnodeId) != 0) return -1; - if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, pVgroup->vnodeGid[2].dnodeId) != 0) return -1; - if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1; - } else { - mError("vgId:%d, failed to remove 1 vnode since invalid replica:%d", pVgroup->vgId, pVgroup->replica); - terrno = TSDB_CODE_MND_APP_ERROR; - return -1; + if (mndAddDropVnodeAction(pMnode, pTrans, pDb, pVgroup, &delGid, true) != 0) return -1; + for (int32_t i = 0; i < pVgroup->replica; ++i) { + if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, pVgroup, pVgroup->vnodeGid[i].dnodeId) != 0) return -1; } + if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, pVgroup) != 0) return -1; return 0; } @@ -1686,35 +1662,81 @@ static int32_t mndSplitVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, SVgObj if (newVg1.replica == 1) { if (mndAddVnodeToVgroup(pMnode, &newVg1, pArray) != 0) goto _OVER; if (mndAddCreateVnodeAction(pMnode, pTrans, pDb, &newVg1, &newVg1.vnodeGid[1]) != 0) goto _OVER; - if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg1, -1) != 0) goto _OVER; + if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg1, newVg1.vnodeGid[0].dnodeId) != 0) goto _OVER; if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg1) != 0) goto _OVER; } else if (newVg1.replica == 3) { SVnodeGid del1 = {0}; if (mndRemoveVnodeFromVgroup(pMnode, &newVg1, pArray, &del1) != 0) goto _OVER; - if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg1, -1) != 0) goto _OVER; + if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg1, newVg1.vnodeGid[0].dnodeId) != 0) goto _OVER; + if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pDb, &newVg1, newVg1.vnodeGid[1].dnodeId) != 0) goto _OVER; if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg1, &del1, true) != 0) goto _OVER; if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pDb, &newVg1) != 0) goto _OVER; } else { goto _OVER; } + mInfo("vgId:%d, vgroup info after adjust replica, replica:%d hashBegin:%u hashEnd:%u vnode:0 dnode:%d", newVg1.vgId, + newVg1.replica, newVg1.hashBegin, newVg1.hashEnd, newVg1.vnodeGid[0].dnodeId); + for (int32_t i = 0; i < newVg1.replica; ++i) { + mInfo("vgId:%d, vnode:%d dnode:%d", newVg1.vgId, i, newVg1.vnodeGid[i].dnodeId); + } + SVgObj newVg2 = {0}; - memcpy(&newVg1, &newVg2, sizeof(SVgObj)); + memcpy(&newVg2, &newVg1, sizeof(SVgObj)); newVg1.replica = 1; - newVg1.hashEnd = (newVg1.hashBegin + newVg1.hashEnd) / 2; + newVg1.hashEnd = newVg1.hashBegin / 2 + newVg1.hashEnd / 2; memset(&newVg1.vnodeGid[1], 0, sizeof(SVnodeGid)); newVg2.replica = 1; newVg2.hashBegin = newVg1.hashEnd + 1; memcpy(&newVg2.vnodeGid[0], &newVg2.vnodeGid[1], sizeof(SVnodeGid)); - memset(&newVg1.vnodeGid[1], 0, sizeof(SVnodeGid)); + memset(&newVg2.vnodeGid[1], 0, sizeof(SVnodeGid)); + + mInfo("vgId:%d, vgroup info after adjust hash, replica:%d hashBegin:%u hashEnd:%u vnode:0 dnode:%d", newVg1.vgId, + newVg1.replica, newVg1.hashBegin, newVg1.hashEnd, newVg1.vnodeGid[0].dnodeId); + mInfo("vgId:%d, vgroup info after adjust hash, replica:%d hashBegin:%u hashEnd:%u vnode:0 dnode:%d", newVg2.vgId, + newVg2.replica, newVg2.hashBegin, newVg2.hashEnd, newVg2.vnodeGid[0].dnodeId); if (mndAddAlterVnodeHashRangeAction(pMnode, pTrans, pDb, &newVg1) != 0) goto _OVER; if (mndAddAlterVnodeHashRangeAction(pMnode, pTrans, pDb, &newVg2) != 0) goto _OVER; - // adjust vgroup - if (mndBuildAlterVgroupAction(pMnode, pTrans, pDb, pDb, &newVg1, pArray) != 0) goto _OVER; - if (mndBuildAlterVgroupAction(pMnode, pTrans, pDb, pDb, &newVg2, pArray) != 0) goto _OVER; +#if 0 + // adjust vgroup replica + if (pDb->cfg.replications != newVg1.replica) { + if (mndBuildAlterVgroupAction(pMnode, pTrans, pDb, pDb, &newVg1, pArray) != 0) goto _OVER; + } + if (pDb->cfg.replications != newVg2.replica) { + if (mndBuildAlterVgroupAction(pMnode, pTrans, pDb, pDb, &newVg2, pArray) != 0) goto _OVER; + } +#endif + + { + pRaw = mndVgroupActionEncode(&newVg1); + if (pRaw == NULL || mndTransAppendCommitlog(pTrans, pRaw) != 0) goto _OVER; + (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); + pRaw = NULL; + } + + { + pRaw = mndVgroupActionEncode(&newVg2); + if (pRaw == NULL || mndTransAppendCommitlog(pTrans, pRaw) != 0) goto _OVER; + (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); + pRaw = NULL; + } + + mInfo("vgId:%d, vgroup info after adjust hash, replica:%d hashBegin:%u hashEnd:%u vnode:0 dnode:%d", newVg1.vgId, + newVg1.replica, newVg1.hashBegin, newVg1.hashEnd, newVg1.vnodeGid[0].dnodeId); + for (int32_t i = 0; i < newVg1.replica; ++i) { + mInfo("vgId:%d, vnode:%d dnode:%d", newVg1.vgId, i, newVg1.vnodeGid[i].dnodeId); + } + mInfo("vgId:%d, vgroup info after adjust hash, replica:%d hashBegin:%u hashEnd:%u vnode:0 dnode:%d", newVg2.vgId, + newVg2.replica, newVg2.hashBegin, newVg2.hashEnd, newVg2.vnodeGid[0].dnodeId); + for (int32_t i = 0; i < newVg1.replica; ++i) { + mInfo("vgId:%d, vnode:%d dnode:%d", newVg2.vgId, i, newVg2.vnodeGid[i].dnodeId); + } + + if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER; + code = 0; _OVER: mndTransDrop(pTrans); @@ -1890,9 +1912,6 @@ _OVER: } static int32_t mndProcessBalanceVgroupMsg(SRpcMsg *pReq) { -#if 1 - return TSDB_CODE_OPS_NOT_SUPPORT; -#else SMnode *pMnode = pReq->info.node; int32_t code = -1; SArray *pArray = NULL; @@ -1941,7 +1960,6 @@ _OVER: taosArrayDestroy(pArray); return code; -#endif } bool mndVgroupInDb(SVgObj *pVgroup, int64_t dbUid) { return !pVgroup->isTsma && pVgroup->dbUid == dbUid; } diff --git a/source/dnode/mnode/impl/test/sdb/sdbTest.cpp b/source/dnode/mnode/impl/test/sdb/sdbTest.cpp index 7a8a5e8ca74fe228a06285f1050108e4e5954967..37b722465af88da33139506aaea4ed3a44a8dff3 100644 --- a/source/dnode/mnode/impl/test/sdb/sdbTest.cpp +++ b/source/dnode/mnode/impl/test/sdb/sdbTest.cpp @@ -367,6 +367,80 @@ bool sdbTraverseFail(SMnode *pMnode, SStrObj *pObj, int32_t *p1, int32_t *p2, in return false; } +#ifndef WINDOWS + +TEST_F(MndTestSdb, 00_API) { + SMnode mnode = {0}; + SSdbOpt opt = {0}; + opt.pMnode = &mnode; + opt.path = TD_TMP_DIR_PATH "mnode_test_sdb"; + taosRemoveDir(opt.path); + SSdb *pSdb = sdbInit(&opt); + + SSdbTable table = {.sdbType = SDB_USER, .keyType = SDB_KEY_BINARY}; + sdbSetTable(pSdb, table); + + // sdbRow.c + SSdbRow *pRow1 = sdbAllocRow(-128); + ASSERT_EQ(pRow1 == NULL, 1); + + void *pRow2 = sdbGetRowObj(NULL); + ASSERT_EQ(pRow2 == NULL, 1); + + //sdbRaw.c + SStrObj strObj; + SSdbRaw *pRaw1 = NULL; + strSetDefault(&strObj, 1); + + pRaw1 = strEncode(&strObj); + int32_t id = sdbGetIdFromRaw(pSdb, pRaw1); + ASSERT_EQ(id, -2); + + SSdbRaw *pRaw2 = sdbAllocRaw(SDB_USER, 1, -128); + ASSERT_EQ(pRaw2 == NULL, 1); + + ASSERT_EQ(sdbSetRawInt8(NULL, 0, 0), -1); + ASSERT_EQ(sdbSetRawInt8(pRaw1, -128, 0), -1); + ASSERT_EQ(sdbSetRawInt32(NULL, 0, 0), -1); + ASSERT_EQ(sdbSetRawInt32(pRaw1, -128, 0), -1); + ASSERT_EQ(sdbSetRawInt16(NULL, 0, 0), -1); + ASSERT_EQ(sdbSetRawInt16(pRaw1, -128, 0), -1); + ASSERT_EQ(sdbSetRawInt64(NULL, 0, 0), -1); + ASSERT_EQ(sdbSetRawInt64(pRaw1, -128, 0), -1); + ASSERT_EQ(sdbSetRawBinary(NULL, 0, "12", 3), -1); + ASSERT_EQ(sdbSetRawBinary(pRaw1, 9028, "12", 3), -1); + ASSERT_EQ(sdbSetRawDataLen(NULL, 0), -1); + ASSERT_EQ(sdbSetRawDataLen(pRaw1, 9000), -1); + ASSERT_EQ(sdbSetRawStatus(NULL, SDB_STATUS_READY), -1); + ASSERT_EQ(sdbSetRawStatus(pRaw1, SDB_STATUS_INIT), -1); + + ASSERT_EQ(sdbGetRawInt8(NULL, 0, 0), -1); + ASSERT_EQ(sdbGetRawInt8(pRaw1, 9000, 0), -1); + ASSERT_EQ(sdbGetRawInt32(NULL, 0, 0), -1); + ASSERT_EQ(sdbGetRawInt32(pRaw1, 9000, 0), -1); + ASSERT_EQ(sdbGetRawInt16(NULL, 0, 0), -1); + ASSERT_EQ(sdbGetRawInt16(pRaw1, 9000, 0), -1); + ASSERT_EQ(sdbGetRawInt64(NULL, 0, 0), -1); + ASSERT_EQ(sdbGetRawInt64(pRaw1, 9000, 0), -1); + ASSERT_EQ(sdbGetRawBinary(NULL, 0, 0, 4096), -1); + ASSERT_EQ(sdbGetRawBinary(pRaw1, 9000, 0, 112), -1); + ASSERT_EQ(sdbGetRawSoftVer(NULL, 0), -1); + ASSERT_EQ(sdbGetRawTotalSize(NULL), -1); + + // sdbHash.c + EXPECT_STREQ(sdbTableName((ESdbType)100), "undefine"); + EXPECT_STREQ(sdbStatusName((ESdbStatus)100), "undefine"); + ASSERT_EQ(sdbGetTableVer(pSdb, (ESdbType)100), -1); + + SSdbRaw *pRaw3 = sdbAllocRaw((ESdbType)-12, 1, 128); + ASSERT_NE(sdbWriteWithoutFree(pSdb, pRaw3), 0); + pSdb->hashObjs[1] = NULL; + SSdbRaw *pRaw4 = sdbAllocRaw((ESdbType)1, 1, 128); + ASSERT_NE(sdbWriteWithoutFree(pSdb, pRaw4), 0); +} + +#endif + TEST_F(MndTestSdb, 01_Write_Str) { void *pIter = NULL; int32_t num = 0; @@ -885,8 +959,8 @@ TEST_F(MndTestSdb, 01_Read_Str) { ASSERT_EQ(sdbWrite(pSdb, pRaw), 0); pI32Obj = (SI32Obj *)sdbAcquire(pSdb, SDB_VGROUP, &key); ASSERT_EQ(pI32Obj, nullptr); - int32_t code = terrno; - ASSERT_EQ(code, TSDB_CODE_SDB_OBJ_DROPPING); + // int32_t code = terrno; + // ASSERT_EQ(code, TSDB_CODE_SDB_OBJ_DROPPING); } { @@ -899,8 +973,8 @@ TEST_F(MndTestSdb, 01_Read_Str) { ASSERT_EQ(sdbWrite(pSdb, pRaw), 0); pI32Obj = (SI32Obj *)sdbAcquire(pSdb, SDB_VGROUP, &key); ASSERT_EQ(pI32Obj, nullptr); - int32_t code = terrno; - ASSERT_EQ(code, TSDB_CODE_SDB_OBJ_CREATING); + // int32_t code = terrno; + // ASSERT_EQ(code, TSDB_CODE_SDB_OBJ_CREATING); } { @@ -934,4 +1008,4 @@ TEST_F(MndTestSdb, 01_Read_Str) { sdbCleanup(pSdb); ASSERT_EQ(mnode.insertTimes, 9); ASSERT_EQ(mnode.deleteTimes, 9); -} \ No newline at end of file +} diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index f2a18b7212c0c89bebc2fa48ec79f70a02af0771..6558a98aaadbedca659268ff7b05f00243145450 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -265,34 +265,47 @@ static int32_t sdbReadFileImp(SSdb *pSdb) { if (ret < 0) { code = TAOS_SYSTEM_ERROR(errno); mError("failed to read sdb file:%s since %s", file, tstrerror(code)); - break; + goto _OVER; } if (ret != readLen) { code = TSDB_CODE_FILE_CORRUPTED; - mError("failed to read sdb file:%s since %s", file, tstrerror(code)); - break; + mError("failed to read sdb file:%s since %s, ret:%" PRId64 " != readLen:%d", file, tstrerror(code), ret, readLen); + goto _OVER; } readLen = pRaw->dataLen + sizeof(int32_t); + if (readLen >= pRaw->dataLen) { + SSdbRaw *pNewRaw = taosMemoryMalloc(pRaw->dataLen + TSDB_MAX_MSG_SIZE); + if (pNewRaw == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + mError("failed read sdb file since malloc new sdbRaw size:%d failed", pRaw->dataLen + TSDB_MAX_MSG_SIZE); + goto _OVER; + } + mInfo("malloc new sdbRaw size:%d, type:%d", pRaw->dataLen + TSDB_MAX_MSG_SIZE, pRaw->type); + memcpy(pNewRaw, pRaw, sizeof(SSdbRaw)); + sdbFreeRaw(pRaw); + pRaw = pNewRaw; + } + ret = taosReadFile(pFile, pRaw->pData, readLen); if (ret < 0) { code = TAOS_SYSTEM_ERROR(errno); - mError("failed to read sdb file:%s since %s", file, tstrerror(code)); - break; + mError("failed to read sdb file:%s since %s, ret:%" PRId64 " readLen:%d", file, tstrerror(code), ret, readLen); + goto _OVER; } if (ret != readLen) { code = TSDB_CODE_FILE_CORRUPTED; - mError("failed to read sdb file:%s since %s", file, tstrerror(code)); - break; + mError("failed to read sdb file:%s since %s, ret:%" PRId64 " != readLen:%d", file, tstrerror(code), ret, readLen); + goto _OVER; } int32_t totalLen = sizeof(SSdbRaw) + pRaw->dataLen + sizeof(int32_t); if ((!taosCheckChecksumWhole((const uint8_t *)pRaw, totalLen)) != 0) { code = TSDB_CODE_CHECKSUM_ERROR; - mError("failed to read sdb file:%s since %s", file, tstrerror(code)); - break; + mError("failed to read sdb file:%s since %s, readLen:%d", file, tstrerror(code), readLen); + goto _OVER; } code = sdbWriteWithoutFree(pSdb, pRaw); @@ -654,15 +667,12 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, i } if (config > 0) { - ASSERT(pSdb->commitConfig == config); pSdb->commitConfig = config; } if (term > 0) { - ASSERT(pSdb->commitTerm == term); pSdb->commitTerm = term; } if (index > 0) { - ASSERT(pSdb->commitIndex == index); pSdb->commitIndex = index; } diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index 6c00a654e92e245ca0e477f9b25de60007c4a34d..c44b659ef589ed930fd9d92fb153fe3712311dca 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -241,9 +241,7 @@ int32_t sdbWriteWithoutFree(SSdb *pSdb, SSdbRaw *pRaw) { SdbDecodeFp decodeFp = pSdb->decodeFps[pRaw->type]; SSdbRow *pRow = (*decodeFp)(pRaw); - if (pRow == NULL) { - return terrno; - } + if (pRow == NULL) return terrno; pRow->type = pRaw->type; diff --git a/source/dnode/qnode/src/qnode.c b/source/dnode/qnode/src/qnode.c index be5ea67b48b1fa436a99f1415ef6c2b9ebe73b38..5efc714e95c85b528c24d64fc9642788d06c99ec 100644 --- a/source/dnode/qnode/src/qnode.c +++ b/source/dnode/qnode/src/qnode.c @@ -69,7 +69,7 @@ int32_t qndPreprocessQueryMsg(SQnode *pQnode, SRpcMsg *pMsg) { return 0; } - return qWorkerPreprocessQueryMsg(pQnode->pQuery, pMsg); + return qWorkerPreprocessQueryMsg(pQnode->pQuery, pMsg, false); } int32_t qndProcessQueryMsg(SQnode *pQnode, int64_t ts, SRpcMsg *pMsg) { @@ -90,12 +90,12 @@ int32_t qndProcessQueryMsg(SQnode *pQnode, int64_t ts, SRpcMsg *pMsg) { code = qWorkerProcessFetchMsg(pQnode, pQnode->pQuery, pMsg, ts); break; case TDMT_SCH_CANCEL_TASK: - code = qWorkerProcessCancelMsg(pQnode, pQnode->pQuery, pMsg, ts); + // code = qWorkerProcessCancelMsg(pQnode, pQnode->pQuery, pMsg, ts); break; case TDMT_SCH_DROP_TASK: code = qWorkerProcessDropMsg(pQnode, pQnode->pQuery, pMsg, ts); break; - case TDMT_VND_CONSUME: + case TDMT_VND_TMQ_CONSUME: // code = tqProcessConsumeReq(pQnode->pTq, pMsg); // break; case TDMT_SCH_QUERY_HEARTBEAT: @@ -103,7 +103,7 @@ int32_t qndProcessQueryMsg(SQnode *pQnode, int64_t ts, SRpcMsg *pMsg) { break; default: qError("unknown msg type:%d in qnode queue", pMsg->msgType); - terrno = TSDB_CODE_VND_APP_ERROR; + terrno = TSDB_CODE_APP_ERROR; } if (code == 0) return TSDB_CODE_ACTION_IN_PROGRESS; diff --git a/source/dnode/snode/inc/sndInt.h b/source/dnode/snode/inc/sndInt.h index 5ee55079810b34ea63e8ac416ff696949787a334..3fcee862a102acd202be4848af800f16a8ef3b66 100644 --- a/source/dnode/snode/inc/sndInt.h +++ b/source/dnode/snode/inc/sndInt.h @@ -31,7 +31,9 @@ extern "C" { #endif typedef struct SSnode { - SMsgCb msgCb; + char* path; + SStreamMeta* pMeta; + SMsgCb msgCb; } SSnode; #if 0 diff --git a/source/dnode/snode/src/snode.c b/source/dnode/snode/src/snode.c index cda4663285ec560c1ea635a56e242d62efa45d41..f53350c10bbeea2e0b9b9d53edfb5caaa4304b8f 100644 --- a/source/dnode/snode/src/snode.c +++ b/source/dnode/snode/src/snode.c @@ -15,197 +15,197 @@ #include "executor.h" #include "sndInt.h" +#include "tstream.h" #include "tuuid.h" -/*SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) { return NULL; }*/ -/*void sndClose(SSnode *pSnode) {}*/ -int32_t sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg) { return 0; } -int32_t sndProcessSMsg(SSnode *pSnode, SRpcMsg *pMsg) { return 0; } + +void sndEnqueueStreamDispatch(SSnode *pSnode, SRpcMsg *pMsg) { + char *msgStr = pMsg->pCont; + char *msgBody = POINTER_SHIFT(msgStr, sizeof(SMsgHead)); + int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); + int32_t code = 0; + + SStreamDispatchReq req; + SDecoder decoder; + tDecoderInit(&decoder, msgBody, msgLen); + if (tDecodeStreamDispatchReq(&decoder, &req) < 0) { + code = TSDB_CODE_MSG_DECODE_ERROR; + tDecoderClear(&decoder); + goto FAIL; + } + tDecoderClear(&decoder); + + int32_t taskId = req.taskId; + + SStreamTask *pTask = streamMetaGetTask(pSnode->pMeta, taskId); + if (pTask) { + SRpcMsg rsp = { + .info = pMsg->info, + .code = 0, + }; + streamProcessDispatchReq(pTask, &req, &rsp, false); + rpcFreeCont(pMsg->pCont); + taosFreeQitem(pMsg); + return; + } + +FAIL: + if (pMsg->info.handle == NULL) return; + SRpcMsg rsp = { + .code = code, + .info = pMsg->info, + }; + tmsgSendRsp(&rsp); + rpcFreeCont(pMsg->pCont); + taosFreeQitem(pMsg); +} + +int32_t sndExpandTask(SSnode *pSnode, SStreamTask *pTask, int64_t ver) { + ASSERT(pTask->taskLevel == TASK_LEVEL__AGG); + ASSERT(taosArrayGetSize(pTask->childEpInfo) != 0); + + pTask->schedStatus = TASK_SCHED_STATUS__INACTIVE; + pTask->inputQueue = streamQueueOpen(); + pTask->outputQueue = streamQueueOpen(); + + if (pTask->inputQueue == NULL || pTask->outputQueue == NULL) { + return -1; + } + + pTask->inputStatus = TASK_INPUT_STATUS__NORMAL; + pTask->outputStatus = TASK_OUTPUT_STATUS__NORMAL; + + pTask->pMsgCb = &pSnode->msgCb; + + pTask->startVer = ver; + + pTask->pState = streamStateOpen(pSnode->path, pTask, false, -1, -1); + if (pTask->pState == NULL) { + return -1; + } + + SReadHandle mgHandle = { + .vnode = NULL, + .numOfVgroups = (int32_t)taosArrayGetSize(pTask->childEpInfo), + .pStateBackend = pTask->pState, + }; + pTask->exec.executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &mgHandle); + ASSERT(pTask->exec.executor); + + return 0; +} SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) { SSnode *pSnode = taosMemoryCalloc(1, sizeof(SSnode)); if (pSnode == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } + pSnode->path = strdup(path); + if (pSnode->path == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto FAIL; + } pSnode->msgCb = pOption->msgCb; -#if 0 - pSnode->pMeta = sndMetaNew(); + + pSnode->pMeta = streamMetaOpen(path, pSnode, (FTaskExpand *)sndExpandTask, SNODE_HANDLE); if (pSnode->pMeta == NULL) { - taosMemoryFree(pSnode); - return NULL; + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto FAIL; } -#endif + return pSnode; + +FAIL: + taosMemoryFree(pSnode->path); + taosMemoryFree(pSnode); + return NULL; } void sndClose(SSnode *pSnode) { - /*sndMetaDelete(pSnode->pMeta);*/ + streamMetaClose(pSnode->pMeta); + taosMemoryFree(pSnode->path); taosMemoryFree(pSnode); } int32_t sndGetLoad(SSnode *pSnode, SSnodeLoad *pLoad) { return 0; } -#if 0 -SStreamMeta *sndMetaNew() { - SStreamMeta *pMeta = taosMemoryCalloc(1, sizeof(SStreamMeta)); - if (pMeta == NULL) { - return NULL; - } - pMeta->pHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); - if (pMeta->pHash == NULL) { - taosMemoryFree(pMeta); - return NULL; - } - return pMeta; -} - -void sndMetaDelete(SStreamMeta *pMeta) { - taosHashCleanup(pMeta->pHash); - taosMemoryFree(pMeta); -} - -int32_t sndMetaDeployTask(SStreamMeta *pMeta, SStreamTask *pTask) { - pTask->exec.executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, NULL); - return taosHashPut(pMeta->pHash, &pTask->taskId, sizeof(int32_t), pTask, sizeof(void *)); -} - -SStreamTask *sndMetaGetTask(SStreamMeta *pMeta, int32_t taskId) { - return taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t)); -} - -int32_t sndMetaRemoveTask(SStreamMeta *pMeta, int32_t taskId) { - SStreamTask *pTask = taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t)); - if (pTask == NULL) { - return -1; - } - taosMemoryFree(pTask->exec.qmsg); - // TODO:free executor - taosMemoryFree(pTask); - return taosHashRemove(pMeta->pHash, &taskId, sizeof(int32_t)); -} - -static int32_t sndProcessTaskDeployReq(SSnode *pNode, SRpcMsg *pMsg) { - SStreamMeta *pMeta = pNode->pMeta; - char *msg = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); - int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); +int32_t sndProcessTaskDeployReq(SSnode *pSnode, char *msg, int32_t msgLen) { + int32_t code; + // 1.deserialize msg and build task SStreamTask *pTask = taosMemoryCalloc(1, sizeof(SStreamTask)); if (pTask == NULL) { return -1; } SDecoder decoder; tDecoderInit(&decoder, (uint8_t *)msg, msgLen); - if (tDecodeSStreamTask(&decoder, pTask) < 0) { - ASSERT(0); + code = tDecodeSStreamTask(&decoder, pTask); + if (code < 0) { + tDecoderClear(&decoder); + taosMemoryFree(pTask); + return -1; } tDecoderClear(&decoder); - pTask->execStatus = TASK_EXEC_STATUS__IDLE; - - pTask->inputQueue = streamQueueOpen(); - pTask->outputQueue = streamQueueOpen(); - pTask->inputStatus = TASK_INPUT_STATUS__NORMAL; - pTask->outputStatus = TASK_INPUT_STATUS__NORMAL; - - if (pTask->inputQueue == NULL || pTask->outputQueue == NULL) goto FAIL; - - pTask->pMsgCb = &pNode->msgCb; + ASSERT(pTask->taskLevel == TASK_LEVEL__AGG); - pTask->exec.executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, NULL); - ASSERT(pTask->exec.executor); - - streamSetupTrigger(pTask); - - qInfo("deploy stream: stream id %" PRId64 " task id %d child id %d on snode", pTask->streamId, pTask->taskId, - pTask->selfChildId); + // 2.save task + code = streamMetaAddTask(pSnode->pMeta, -1, pTask); + if (code < 0) { + return -1; + } - taosHashPut(pMeta->pHash, &pTask->taskId, sizeof(int32_t), &pTask, sizeof(void *)); + // 3.go through recover steps to fill history + if (pTask->fillHistory) { + streamSetParamForRecover(pTask); + streamAggRecoverPrepare(pTask); + } return 0; +} -FAIL: - if (pTask->inputQueue) streamQueueClose(pTask->inputQueue); - if (pTask->outputQueue) streamQueueClose(pTask->outputQueue); - if (pTask) taosMemoryFree(pTask); - return -1; +int32_t sndProcessTaskDropReq(SSnode *pSnode, char *msg, int32_t msgLen) { + SVDropStreamTaskReq *pReq = (SVDropStreamTaskReq *)msg; + return streamMetaRemoveTask(pSnode->pMeta, pReq->taskId); } -static int32_t sndProcessTaskRunReq(SSnode *pNode, SRpcMsg *pMsg) { - SStreamMeta *pMeta = pNode->pMeta; +int32_t sndProcessTaskRunReq(SSnode *pSnode, SRpcMsg *pMsg) { SStreamTaskRunReq *pReq = pMsg->pCont; int32_t taskId = pReq->taskId; - SStreamTask *pTask = *(SStreamTask **)taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t)); - streamProcessRunReq(pTask); - return 0; + SStreamTask *pTask = streamMetaGetTask(pSnode->pMeta, taskId); + if (pTask) { + streamProcessRunReq(pTask); + return 0; + } else { + return -1; + } } -static int32_t sndProcessTaskDispatchReq(SSnode *pNode, SRpcMsg *pMsg) { - SStreamMeta *pMeta = pNode->pMeta; - - char *msgStr = pMsg->pCont; - char *msgBody = POINTER_SHIFT(msgStr, sizeof(SMsgHead)); - int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); - +int32_t sndProcessTaskDispatchReq(SSnode *pSnode, SRpcMsg *pMsg, bool exec) { + char *msgStr = pMsg->pCont; + char *msgBody = POINTER_SHIFT(msgStr, sizeof(SMsgHead)); + int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); SStreamDispatchReq req; SDecoder decoder; - tDecoderInit(&decoder, msgBody, msgLen); + tDecoderInit(&decoder, (uint8_t *)msgBody, msgLen); tDecodeStreamDispatchReq(&decoder, &req); - int32_t taskId = req.taskId; - SStreamTask *pTask = *(SStreamTask **)taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t)); - SRpcMsg rsp = { - .info = pMsg->info, - .code = 0, - }; - streamProcessDispatchReq(pTask, &req, &rsp, true); - return 0; -} - -static int32_t sndProcessTaskRecoverReq(SSnode *pNode, SRpcMsg *pMsg) { - SStreamMeta *pMeta = pNode->pMeta; - - SStreamTaskRecoverReq *pReq = pMsg->pCont; - int32_t taskId = pReq->taskId; - SStreamTask *pTask = *(SStreamTask **)taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t)); - streamProcessRecoverReq(pTask, pReq, pMsg); - return 0; -} - -static int32_t sndProcessTaskDispatchRsp(SSnode *pNode, SRpcMsg *pMsg) { - SStreamMeta *pMeta = pNode->pMeta; - - SStreamDispatchRsp *pRsp = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); - int32_t taskId = pRsp->taskId; - SStreamTask *pTask = *(SStreamTask **)taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t)); - streamProcessDispatchRsp(pTask, pRsp); - return 0; -} - -static int32_t sndProcessTaskRecoverRsp(SSnode *pNode, SRpcMsg *pMsg) { - SStreamMeta *pMeta = pNode->pMeta; - - SStreamTaskRecoverRsp *pRsp = pMsg->pCont; - int32_t taskId = pRsp->rspTaskId; - SStreamTask *pTask = *(SStreamTask **)taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t)); - streamProcessRecoverRsp(pTask, pRsp); - return 0; -} - -static int32_t sndProcessTaskDropReq(SSnode *pNode, SRpcMsg *pMsg) { - SStreamMeta *pMeta = pNode->pMeta; - - char *msg = pMsg->pCont; - int32_t msgLen = pMsg->contLen; - SVDropStreamTaskReq *pReq = (SVDropStreamTaskReq *)msg; - int32_t code = taosHashRemove(pMeta->pHash, &pReq->taskId, sizeof(int32_t)); - ASSERT(code == 0); - if (code == 0) { - // sendrsp + int32_t taskId = req.taskId; + + SStreamTask *pTask = streamMetaGetTask(pSnode->pMeta, taskId); + if (pTask) { + SRpcMsg rsp = { + .info = pMsg->info, + .code = 0, + }; + streamProcessDispatchReq(pTask, &req, &rsp, exec); + return 0; + } else { + return -1; } - return code; + return 0; } -static int32_t sndProcessTaskRetrieveReq(SSnode *pNode, SRpcMsg *pMsg) { - SStreamMeta *pMeta = pNode->pMeta; - +int32_t sndProcessTaskRetrieveReq(SSnode *pSnode, SRpcMsg *pMsg) { char *msgStr = pMsg->pCont; char *msgBody = POINTER_SHIFT(msgStr, sizeof(SMsgHead)); int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); @@ -213,58 +213,102 @@ static int32_t sndProcessTaskRetrieveReq(SSnode *pNode, SRpcMsg *pMsg) { SDecoder decoder; tDecoderInit(&decoder, msgBody, msgLen); tDecodeStreamRetrieveReq(&decoder, &req); + tDecoderClear(&decoder); int32_t taskId = req.dstTaskId; - SStreamTask *pTask = *(SStreamTask **)taosHashGet(pMeta->pHash, &taskId, sizeof(int32_t)); - if (atomic_load_8(&pTask->taskStatus) != TASK_STATUS__NORMAL) { + SStreamTask *pTask = streamMetaGetTask(pSnode->pMeta, taskId); + if (pTask) { + SRpcMsg rsp = { + .info = pMsg->info, + .code = 0, + }; + streamProcessRetrieveReq(pTask, &req, &rsp); + tDeleteStreamRetrieveReq(&req); return 0; + } else { + return -1; + } +} + +int32_t sndProcessTaskDispatchRsp(SSnode *pSnode, SRpcMsg *pMsg) { + SStreamDispatchRsp *pRsp = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); + int32_t taskId = ntohl(pRsp->upstreamTaskId); + SStreamTask *pTask = streamMetaGetTask(pSnode->pMeta, taskId); + if (pTask) { + streamProcessDispatchRsp(pTask, pRsp, pMsg->code); + return 0; + } else { + return -1; } - SRpcMsg rsp = { - .info = pMsg->info, - .code = 0, - }; - streamProcessRetrieveReq(pTask, &req, &rsp); return 0; } -static int32_t sndProcessTaskRetrieveRsp(SSnode *pNode, SRpcMsg *pMsg) { +int32_t sndProcessTaskRetrieveRsp(SSnode *pSnode, SRpcMsg *pMsg) { // return 0; } -int32_t sndProcessUMsg(SSnode *pSnode, SRpcMsg *pMsg) { - // stream deploy - // stream stop/resume - // operator exec +int32_t sndProcessWriteMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg *pRsp) { + void *pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); + int32_t len = pMsg->contLen - sizeof(SMsgHead); switch (pMsg->msgType) { case TDMT_STREAM_TASK_DEPLOY: - return sndProcessTaskDeployReq(pSnode, pMsg); + return sndProcessTaskDeployReq(pSnode, pReq, len); case TDMT_STREAM_TASK_DROP: - return sndProcessTaskDropReq(pSnode, pMsg); + return sndProcessTaskDropReq(pSnode, pReq, len); default: ASSERT(0); } return 0; } -int32_t sndProcessSMsg(SSnode *pSnode, SRpcMsg *pMsg) { +int32_t sndProcessTaskRecoverFinishReq(SSnode *pSnode, SRpcMsg *pMsg) { + char *msg = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); + int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); + + // deserialize + SStreamRecoverFinishReq req; + + SDecoder decoder; + tDecoderInit(&decoder, msg, msgLen); + tDecodeSStreamRecoverFinishReq(&decoder, &req); + tDecoderClear(&decoder); + + // find task + SStreamTask *pTask = streamMetaGetTask(pSnode->pMeta, req.taskId); + if (pTask == NULL) { + return -1; + } + // do process request + if (streamProcessRecoverFinishReq(pTask, req.childId) < 0) { + return -1; + } + + return 0; +} + +int32_t sndProcessTaskRecoverFinishRsp(SSnode *pSnode, SRpcMsg *pMsg) { + // + return 0; +} + +int32_t sndProcessStreamMsg(SSnode *pSnode, SRpcMsg *pMsg) { switch (pMsg->msgType) { case TDMT_STREAM_TASK_RUN: return sndProcessTaskRunReq(pSnode, pMsg); case TDMT_STREAM_TASK_DISPATCH: - return sndProcessTaskDispatchReq(pSnode, pMsg); - case TDMT_STREAM_TASK_RECOVER: - return sndProcessTaskRecoverReq(pSnode, pMsg); - case TDMT_STREAM_RETRIEVE: - return sndProcessTaskRecoverReq(pSnode, pMsg); + return sndProcessTaskDispatchReq(pSnode, pMsg, true); case TDMT_STREAM_TASK_DISPATCH_RSP: return sndProcessTaskDispatchRsp(pSnode, pMsg); - case TDMT_STREAM_TASK_RECOVER_RSP: - return sndProcessTaskRecoverRsp(pSnode, pMsg); + case TDMT_STREAM_RETRIEVE: + return sndProcessTaskRetrieveReq(pSnode, pMsg); case TDMT_STREAM_RETRIEVE_RSP: return sndProcessTaskRetrieveRsp(pSnode, pMsg); + case TDMT_STREAM_RECOVER_FINISH: + return sndProcessTaskRecoverFinishReq(pSnode, pMsg); + case TDMT_STREAM_RECOVER_FINISH_RSP: + return sndProcessTaskRecoverFinishRsp(pSnode, pMsg); default: ASSERT(0); } return 0; } -#endif diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index d200ed56a5346427d6b2480d50f32297b47e24f0..370103c222b5d4a34b3865f7727b3e5f5035b745 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -83,7 +83,6 @@ int32_t vnodePreprocessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg); int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg *pRsp); int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); -int32_t vnodeProcessSyncCtrlMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp); int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg); int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo); void vnodeProposeWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs); @@ -152,12 +151,14 @@ typedef struct STsdbReader STsdbReader; #define CACHESCAN_RETRIEVE_LAST_ROW 0x4 #define CACHESCAN_RETRIEVE_LAST 0x8 -int32_t tsdbSetTableId(STsdbReader *pReader, int64_t uid); -int32_t tsdbReaderOpen(SVnode *pVnode, SQueryTableDataCond *pCond, SArray *pTableList, STsdbReader **ppReader, - const char *idstr); +int32_t tsdbSetTableList(STsdbReader *pReader, const void *pTableList, int32_t num); +int32_t tsdbReaderOpen(SVnode *pVnode, SQueryTableDataCond *pCond, void *pTableList, int32_t numOfTables, + STsdbReader **ppReader, const char *idstr); + void tsdbReaderClose(STsdbReader *pReader); bool tsdbNextDataBlock(STsdbReader *pReader); -void tsdbRetrieveDataBlockInfo(STsdbReader *pReader, SDataBlockInfo *pDataBlockInfo); +bool tsdbTableNextDataBlock(STsdbReader *pReader, uint64_t uid); +void tsdbRetrieveDataBlockInfo(const STsdbReader *pReader, int32_t *rows, uint64_t *uid, STimeWindow *pWindow); int32_t tsdbRetrieveDatablockSMA(STsdbReader *pReader, SColumnDataAgg ***pBlockStatis, bool *allHave); SArray *tsdbRetrieveDataBlock(STsdbReader *pTsdbReadHandle, SArray *pColumnIdList); int32_t tsdbReaderReset(STsdbReader *pReader, SQueryTableDataCond *pCond); @@ -167,8 +168,8 @@ void *tsdbGetIdx(SMeta *pMeta); void *tsdbGetIvtIdx(SMeta *pMeta); uint64_t getReaderMaxVersion(STsdbReader *pReader); -int32_t tsdbCacherowsReaderOpen(void *pVnode, int32_t type, SArray *pTableIdList, int32_t numOfCols, uint64_t suid, - void **pReader); +int32_t tsdbCacherowsReaderOpen(void *pVnode, int32_t type, void *pTableIdList, int32_t numOfTables, int32_t numOfCols, + uint64_t suid, void **pReader); int32_t tsdbRetrieveCacheRows(void *pReader, SSDataBlock *pResBlock, const int32_t *slotIds, SArray *pTableUids); void *tsdbCacherowsReaderClose(void *pReader); int32_t tsdbGetTableSchema(SVnode *pVnode, int64_t uid, STSchema **pSchema, int64_t *suid); @@ -239,7 +240,7 @@ bool tqNextDataBlock(STqReader *pReader); bool tqNextDataBlockFilterOut(STqReader *pReader, SHashObj *filterOutUids); int32_t tqRetrieveDataBlock(SSDataBlock *pBlock, STqReader *pReader); -void vnodeEnqueueStreamMsg(SVnode *pVnode, SRpcMsg *pMsg); +int32_t vnodeEnqueueStreamMsg(SVnode *pVnode, SRpcMsg *pMsg); // sma int32_t smaGetTSmaDays(SVnodeCfg *pCfg, void *pCont, uint32_t contLen, int32_t *days); diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index e5b8a1f327698bf805f997f8ba97e43256aa8907..ba9d68ee7f677eab28ad1479aee92b356e3f545b 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -110,7 +110,6 @@ static FORCE_INLINE int64_t tsdbLogicToFileSize(int64_t lSize, int32_t szPage) { #define tsdbRowFromBlockData(BLOCKDATA, IROW) ((TSDBROW){.type = 1, .pBlockData = (BLOCKDATA), .iRow = (IROW)}) void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal); int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow); -int32_t tGetTSDBRow(uint8_t *p, TSDBROW *pRow); int32_t tsdbRowCmprFn(const void *p1, const void *p2); // SRowIter void tRowIterInit(SRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema); @@ -155,15 +154,13 @@ int32_t tCmprBlockL(void const *lhs, void const *rhs); int32_t tBlockDataCreate(SBlockData *pBlockData); void tBlockDataDestroy(SBlockData *pBlockData, int8_t deepClear); int32_t tBlockDataInit(SBlockData *pBlockData, TABLEID *pId, STSchema *pTSchema, int16_t *aCid, int32_t nCid); -int32_t tBlockDataInitEx(SBlockData *pBlockData, SBlockData *pBlockDataFrom); void tBlockDataReset(SBlockData *pBlockData); int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTSchema, int64_t uid); void tBlockDataClear(SBlockData *pBlockData); SColData *tBlockDataGetColDataByIdx(SBlockData *pBlockData, int32_t idx); void tBlockDataGetColData(SBlockData *pBlockData, int16_t cid, SColData **ppColData); -int32_t tBlockDataCopy(SBlockData *pBlockDataSrc, SBlockData *pBlockDataDest); int32_t tBlockDataMerge(SBlockData *pBlockData1, SBlockData *pBlockData2, SBlockData *pBlockData); -int32_t tBlockDataAddColData(SBlockData *pBlockData, int32_t iColData, SColData **ppColData); +int32_t tBlockDataAddColData(SBlockData *pBlockData, SColData **ppColData); int32_t tCmprBlockData(SBlockData *pBlockData, int8_t cmprAlg, uint8_t **ppOut, int32_t *szOut, uint8_t *aBuf[], int32_t aBufN[]); int32_t tDecmprBlockData(uint8_t *pIn, int32_t szIn, SBlockData *pBlockData, uint8_t *aBuf[]); @@ -193,7 +190,6 @@ int32_t tsdbKeyFid(TSKEY key, int32_t minutes, int8_t precision); void tsdbFidKeyRange(int32_t fid, int32_t minutes, int8_t precision, TSKEY *minKey, TSKEY *maxKey); int32_t tsdbFidLevel(int32_t fid, STsdbKeepCfg *pKeepCfg, int64_t now); int32_t tsdbBuildDeleteSkyline(SArray *aDelData, int32_t sidx, int32_t eidx, SArray *aSkyline); -void tsdbCalcColDataSMA(SColData *pColData, SColumnDataAgg *pColAgg); int32_t tPutColumnDataAgg(uint8_t *p, SColumnDataAgg *pColAgg); int32_t tGetColumnDataAgg(uint8_t *p, SColumnDataAgg *pColAgg); int32_t tsdbCmprData(uint8_t *pIn, int32_t szIn, int8_t type, int8_t cmprAlg, uint8_t **ppOut, int32_t nOut, @@ -213,11 +209,10 @@ void tsdbRefMemTable(SMemTable *pMemTable); void tsdbUnrefMemTable(SMemTable *pMemTable); SArray *tsdbMemTableGetTbDataArray(SMemTable *pMemTable); // STbDataIter -int32_t tsdbTbDataIterCreate(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter **ppIter); -void *tsdbTbDataIterDestroy(STbDataIter *pIter); -void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter *pIter); -TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter); -bool tsdbTbDataIterNext(STbDataIter *pIter); +int32_t tsdbTbDataIterCreate(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter **ppIter); +void *tsdbTbDataIterDestroy(STbDataIter *pIter); +void tsdbTbDataIterOpen(STbData *pTbData, TSDBKEY *pFrom, int8_t backward, STbDataIter *pIter); +bool tsdbTbDataIterNext(STbDataIter *pIter); // STbData int32_t tsdbGetNRowsInTbData(STbData *pTbData); // tsdbFile.c ============================================================================================== @@ -473,7 +468,7 @@ struct SBlockData { int64_t *aUid; // uids of each row, only exist in block data in .last file (uid == 0) int64_t *aVersion; // versions of each row TSKEY *aTSKEY; // timestamp of each row - SArray *aIdx; // SArray + int32_t nColData; SArray *aColData; // SArray }; @@ -643,6 +638,14 @@ typedef struct SSttBlockLoadInfo { STSchema *pSchema; int16_t *colIds; int32_t numOfCols; + bool sttBlockLoaded; + + // keep the last access position, this position may be used to reduce the binary times for + // starting last block data for a new table + struct { + int32_t blockIndex; + int32_t rowIndex; + } prevEndPos; } SSttBlockLoadInfo; typedef struct SMergeTree { @@ -708,15 +711,17 @@ void *destroyLastBlockLoadInfo(SSttBlockLoadInfo *pLoadInfo); // tsdbCache ============================================================================================== typedef struct SCacheRowsReader { - SVnode *pVnode; - STSchema *pSchema; - uint64_t uid; - uint64_t suid; - char **transferBuf; // todo remove it soon - int32_t numOfCols; - int32_t type; - int32_t tableIndex; // currently returned result tables - SArray *pTableList; // table id list + SVnode *pVnode; + STSchema *pSchema; + uint64_t uid; + uint64_t suid; + char **transferBuf; // todo remove it soon + int32_t numOfCols; + int32_t type; + int32_t tableIndex; // currently returned result tables + + STableKeyInfo *pTableList; // table id list + int32_t numOfTables; SSttBlockLoadInfo *pLoadInfo; STsdbReadSnap *pReadSnap; SDataFReader *pDataFReader; @@ -765,6 +770,40 @@ static FORCE_INLINE int32_t tsdbKeyCmprFn(const void *p1, const void *p2) { return 0; } +#define SL_NODE_FORWARD(n, l) ((n)->forwards[l]) +#define SL_NODE_BACKWARD(n, l) ((n)->forwards[(n)->level + (l)]) +#define SL_NODE_DATA(n) (&SL_NODE_BACKWARD(n, (n)->level)) + +static FORCE_INLINE int32_t tGetTSDBRow(uint8_t *p, TSDBROW *pRow) { + int32_t n = tGetI64(p, &pRow->version); + pRow->pTSRow = (STSRow *)(p + n); + n += pRow->pTSRow->len; + return n; +} + +static FORCE_INLINE TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter) { + if (pIter == NULL) return NULL; + + if (pIter->pRow) { + return pIter->pRow; + } + + if (pIter->backward) { + if (pIter->pNode == pIter->pTbData->sl.pHead) { + return NULL; + } + } else { + if (pIter->pNode == pIter->pTbData->sl.pTail) { + return NULL; + } + } + + tGetTSDBRow((uint8_t *)SL_NODE_DATA(pIter->pNode), &pIter->row); + pIter->pRow = &pIter->row; + + return pIter->pRow; +} + #ifdef __cplusplus } #endif diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index 988ecc5dd3c0046c142ffde9a3d902f2b9904cd3..8f8691cfc2af4cb5f2d30ca9d3708327a8d2f2f6 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -17,7 +17,6 @@ #define _TD_VND_H_ #include "sync.h" -#include "syncTools.h" #include "ttrace.h" #include "vnodeInt.h" @@ -98,6 +97,7 @@ bool vnodeShouldRollback(SVnode* pVnode); // vnodeSync.c int32_t vnodeSyncOpen(SVnode* pVnode, char* path); void vnodeSyncStart(SVnode* pVnode); +void vnodeSyncPreClose(SVnode* pVnode); void vnodeSyncClose(SVnode* pVnode); void vnodeRedirectRpcMsg(SVnode* pVnode, SRpcMsg* pMsg); bool vnodeIsLeader(SVnode* pVnode); diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index a5dc4431ab711307834dc73affbe81718b6b641c..ac9fabf05248fc4bf58f4e271ca161681f327eca 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -102,6 +102,7 @@ int metaClose(SMeta* pMeta); int metaBegin(SMeta* pMeta, int8_t fromSys); int metaCommit(SMeta* pMeta); int metaFinishCommit(SMeta* pMeta); +int metaPrepareAsyncCommit(SMeta* pMeta); int metaCreateSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* pReq); int metaAlterSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* pReq); int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq, SArray* tbUidList); @@ -150,22 +151,19 @@ typedef struct { int32_t metaGetStbStats(SMeta* pMeta, int64_t uid, SMetaStbStats* pInfo); // tsdb -int tsdbOpen(SVnode* pVnode, STsdb** ppTsdb, const char* dir, STsdbKeepCfg* pKeepCfg, int8_t rollback); -int tsdbClose(STsdb** pTsdb); -int32_t tsdbBegin(STsdb* pTsdb); -int32_t tsdbCommit(STsdb* pTsdb); -int32_t tsdbFinishCommit(STsdb* pTsdb); -int32_t tsdbRollbackCommit(STsdb* pTsdb); -int32_t tsdbDoRetention(STsdb* pTsdb, int64_t now); -int tsdbScanAndConvertSubmitMsg(STsdb* pTsdb, SSubmitReq* pMsg); -int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSubmitRsp* pRsp); -int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, - SSubmitBlkRsp* pRsp); -int32_t tsdbDeleteTableData(STsdb* pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey); -STsdbReader tsdbQueryCacheLastT(STsdb* tsdb, SQueryTableDataCond* pCond, STableListInfo* tableList, uint64_t qId, - void* pMemRef); -int32_t tsdbSetKeepCfg(STsdb* pTsdb, STsdbCfg* pCfg); -int32_t tsdbGetStbIdList(SMeta* pMeta, int64_t suid, SArray* list); +int tsdbOpen(SVnode* pVnode, STsdb** ppTsdb, const char* dir, STsdbKeepCfg* pKeepCfg, int8_t rollback); +int tsdbClose(STsdb** pTsdb); +int32_t tsdbBegin(STsdb* pTsdb); +int32_t tsdbCommit(STsdb* pTsdb); +int32_t tsdbFinishCommit(STsdb* pTsdb); +int32_t tsdbRollbackCommit(STsdb* pTsdb); +int32_t tsdbDoRetention(STsdb* pTsdb, int64_t now); +int tsdbScanAndConvertSubmitMsg(STsdb* pTsdb, SSubmitReq* pMsg); +int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSubmitRsp* pRsp); +int32_t tsdbInsertTableData(STsdb* pTsdb, int64_t version, SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, + SSubmitBlkRsp* pRsp); +int32_t tsdbDeleteTableData(STsdb* pTsdb, int64_t version, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKEY eKey); +int32_t tsdbSetKeepCfg(STsdb* pTsdb, STsdbCfg* pCfg); // tq int tqInit(); @@ -179,22 +177,26 @@ int32_t tqCheckColModifiable(STQ* pTq, int64_t tbUid, int32_t colId); // tq-mq int32_t tqProcessAddCheckInfoReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen); int32_t tqProcessDelCheckInfoReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen); -int32_t tqProcessVgChangeReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen); -int32_t tqProcessVgDeleteReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen); +int32_t tqProcessSubscribeReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen); +int32_t tqProcessDeleteSubReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen); int32_t tqProcessOffsetCommitReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen); int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg); // tq-stream int32_t tqProcessTaskDeployReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen); int32_t tqProcessTaskDropReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen); +int32_t tqProcessStreamTaskCheckReq(STQ* pTq, SRpcMsg* pMsg); +int32_t tqProcessStreamTaskCheckRsp(STQ* pTq, int64_t version, char* msg, int32_t msgLen); int32_t tqProcessSubmitReq(STQ* pTq, SSubmitReq* data, int64_t ver); int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver); int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg); int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg, bool exec); -int32_t tqProcessTaskRecoverReq(STQ* pTq, SRpcMsg* pMsg); int32_t tqProcessTaskDispatchRsp(STQ* pTq, SRpcMsg* pMsg); -int32_t tqProcessTaskRecoverRsp(STQ* pTq, SRpcMsg* pMsg); int32_t tqProcessTaskRetrieveReq(STQ* pTq, SRpcMsg* pMsg); int32_t tqProcessTaskRetrieveRsp(STQ* pTq, SRpcMsg* pMsg); +int32_t tqProcessTaskRecover1Req(STQ* pTq, SRpcMsg* pMsg); +int32_t tqProcessTaskRecover2Req(STQ* pTq, int64_t version, char* msg, int32_t msgLen); +int32_t tqProcessTaskRecoverFinishReq(STQ* pTq, SRpcMsg* pMsg); +int32_t tqProcessTaskRecoverFinishRsp(STQ* pTq, SRpcMsg* pMsg); SSubmitReq* tqBlockToSubmit(SVnode* pVnode, const SArray* pBlocks, const STSchema* pSchema, SSchemaWrapper* pTagSchemaWrapper, bool createTb, int64_t suid, const char* stbFullName, diff --git a/source/dnode/vnode/src/meta/metaCommit.c b/source/dnode/vnode/src/meta/metaCommit.c index 01ad833d203023b59f69e2f985d964d21a213972..0be0c3e40798ec953a529d433b7294d564ceee84 100644 --- a/source/dnode/vnode/src/meta/metaCommit.c +++ b/source/dnode/vnode/src/meta/metaCommit.c @@ -35,6 +35,7 @@ int metaBegin(SMeta *pMeta, int8_t fromSys) { // commit the meta txn int metaCommit(SMeta *pMeta) { return tdbCommit(pMeta->pEnv, &pMeta->txn); } int metaFinishCommit(SMeta *pMeta) { return tdbPostCommit(pMeta->pEnv, &pMeta->txn); } +int metaPrepareAsyncCommit(SMeta *pMeta) { return tdbPrepareAsyncCommit(pMeta->pEnv, &pMeta->txn); } // abort the meta txn int metaAbort(SMeta *pMeta) { return tdbAbort(pMeta->pEnv, &pMeta->txn); } diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index 43e80b99d41258b3a6969dd853b69ae806da231f..4aabd3980050cb805d722b8d68a71f650be82ea1 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -153,7 +153,7 @@ bool metaIsTableExist(SMeta *pMeta, tb_uid_t uid) { int metaGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid) { SMeta *pMeta = pReader->pMeta; - int64_t version; + int64_t version1; // query uid.idx if (tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pReader->pBuf, &pReader->szBuf) < 0) { @@ -161,8 +161,8 @@ int metaGetTableEntryByUid(SMetaReader *pReader, tb_uid_t uid) { return -1; } - version = ((SUidIdxVal *)pReader->pBuf)[0].version; - return metaGetTableEntryByVersion(pReader, version, uid); + version1 = ((SUidIdxVal *)pReader->pBuf)[0].version; + return metaGetTableEntryByVersion(pReader, version1, uid); } int metaGetTableEntryByName(SMetaReader *pReader, const char *name) { diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 1196b512d3925bd6d8448a92dfceb81477050d33..6dadce80ca459ce371cf13311b643974e6f1cd07 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -53,7 +53,7 @@ static void metaGetEntryInfo(const SMetaEntry *pEntry, SMetaInfo *pInfo) { static int metaUpdateMetaRsp(tb_uid_t uid, char *tbName, SSchemaWrapper *pSchema, STableMetaRsp *pMetaRsp) { pMetaRsp->pSchemas = taosMemoryMalloc(pSchema->nCols * sizeof(SSchema)); if (NULL == pMetaRsp->pSchemas) { - terrno = TSDB_CODE_VND_OUT_OF_MEMORY; + terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -498,7 +498,7 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi rc = tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &pData, &nData); if (rc < 0) { - terrno = TSDB_CODE_VND_TABLE_NOT_EXIST; + terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST; return -1; } uid = *(tb_uid_t *)pData; @@ -743,7 +743,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl // search name index ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal); if (ret < 0) { - terrno = TSDB_CODE_VND_TABLE_NOT_EXIST; + terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST; return -1; } @@ -824,7 +824,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl break; case TSDB_ALTER_TABLE_DROP_COLUMN: if (pColumn == NULL) { - terrno = TSDB_CODE_VND_TABLE_COL_NOT_EXISTS; + terrno = TSDB_CODE_VND_COL_NOT_EXISTS; goto _err; } if (pColumn->colId == 0) { @@ -846,7 +846,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl break; case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES: if (pColumn == NULL) { - terrno = TSDB_CODE_VND_TABLE_COL_NOT_EXISTS; + terrno = TSDB_CODE_VND_COL_NOT_EXISTS; goto _err; } if (!IS_VAR_DATA_TYPE(pColumn->type) || pColumn->bytes > pAlterTbReq->colModBytes) { @@ -866,7 +866,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl goto _err; } if (pColumn == NULL) { - terrno = TSDB_CODE_VND_TABLE_COL_NOT_EXISTS; + terrno = TSDB_CODE_VND_COL_NOT_EXISTS; goto _err; } if (tqCheckColModifiable(pMeta->pVnode->pTq, uid, pColumn->colId) != 0) { @@ -934,7 +934,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA // search name index ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal); if (ret < 0) { - terrno = TSDB_CODE_VND_TABLE_NOT_EXIST; + terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST; return -1; } @@ -990,7 +990,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA } if (pColumn == NULL) { - terrno = TSDB_CODE_VND_TABLE_COL_NOT_EXISTS; + terrno = TSDB_CODE_VND_COL_NOT_EXISTS; goto _err; } @@ -1093,7 +1093,7 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p // search name index ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal); if (ret < 0) { - terrno = TSDB_CODE_VND_TABLE_NOT_EXIST; + terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST; return -1; } diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c index c56b32514a3195f311d504c28d66609f937e8545..03532eb6d409221c2fa138df419af1dd4a2620d9 100644 --- a/source/dnode/vnode/src/sma/smaRollup.c +++ b/source/dnode/vnode/src/sma/smaRollup.c @@ -15,11 +15,11 @@ #include "sma.h" -#define RSMA_QTASKEXEC_SMOOTH_SIZE (100) // cnt -#define RSMA_SUBMIT_BATCH_SIZE (1024) // cnt -#define RSMA_FETCH_DELAY_MAX (120000) // ms -#define RSMA_FETCH_ACTIVE_MAX (1000) // ms -#define RSMA_FETCH_INTERVAL (5000) // ms +#define RSMA_QTASKEXEC_SMOOTH_SIZE (100) // cnt +#define RSMA_SUBMIT_BATCH_SIZE (1024) // cnt +#define RSMA_FETCH_DELAY_MAX (120000) // ms +#define RSMA_FETCH_ACTIVE_MAX (1000) // ms +#define RSMA_FETCH_INTERVAL (5000) // ms SSmaMgmt smaMgmt = { .inited = 0, @@ -701,25 +701,28 @@ static int32_t tdRSmaExecAndSubmitResult(SSma *pSma, qTaskInfo_t taskInfo, SRSma #endif for (int32_t i = 0; i < taosArrayGetSize(pResList); ++i) { SSDataBlock *output = taosArrayGetP(pResList, i); + smaDebug("result block, uid:%"PRIu64", groupid:%"PRIu64", rows:%d", output->info.uid, output->info.groupId, + output->info.rows); + STsdb *sinkTsdb = (pItem->level == TSDB_RETENTION_L1 ? pSma->pRSmaTsdb[0] : pSma->pRSmaTsdb[1]); SSubmitReq *pReq = NULL; // TODO: the schema update should be handled later(TD-17965) if (buildSubmitReqFromDataBlock(&pReq, output, pTSchema, SMA_VID(pSma), suid) < 0) { - smaError("vgId:%d, build submit req for rsma table %" PRIi64 " level %" PRIi8 " failed since %s", SMA_VID(pSma), - suid, pItem->level, terrstr()); + smaError("vgId:%d, build submit req for rsma table suid:%" PRIu64 ", uid:%"PRIu64", level %" PRIi8 " failed since %s", SMA_VID(pSma), + suid, output->info.groupId, pItem->level, terrstr()); goto _err; } if (pReq && tdProcessSubmitReq(sinkTsdb, output->info.version, pReq) < 0) { taosMemoryFreeClear(pReq); - smaError("vgId:%d, process submit req for rsma table %" PRIi64 " level %" PRIi8 " failed since %s", - SMA_VID(pSma), suid, pItem->level, terrstr()); + smaError("vgId:%d, process submit req for rsma suid:%"PRIu64", uid:%" PRIu64 " level %" PRIi8 " failed since %s", + SMA_VID(pSma), suid, output->info.groupId, pItem->level, terrstr()); goto _err; } - smaDebug("vgId:%d, process submit req for rsma table %" PRIi64 " level %" PRIi8 " ver %" PRIi64 " len %" PRIu32, - SMA_VID(pSma), suid, pItem->level, output->info.version, htonl(pReq->header.contLen)); + smaDebug("vgId:%d, process submit req for rsma suid:%" PRIu64 ",uid:%"PRIu64", level %" PRIi8 " ver %" PRIi64 " len %" PRIu32, + SMA_VID(pSma), suid, output->info.groupId, pItem->level, output->info.version, htonl(pReq->header.contLen)); taosMemoryFreeClear(pReq); } @@ -839,7 +842,7 @@ static int32_t tdExecuteRSmaImpl(SSma *pSma, const void *pMsg, int32_t msgSize, tdRsmaPrintSubmitReq(pSma, pReq); } #endif - if (qSetMultiStreamInput(qTaskInfo, pMsg, msgSize, inputType) < 0) { + if (qSetSMAInput(qTaskInfo, pMsg, msgSize, inputType) < 0) { smaError("vgId:%d, rsma %" PRIi8 " qSetStreamInput failed since %s", SMA_VID(pSma), level, tstrerror(terrno)); return TSDB_CODE_FAILED; } @@ -1404,7 +1407,7 @@ static int32_t tdRSmaFetchAllResult(SSma *pSma, SRSmaInfo *pInfo) { pItem->nScanned = 0; - if ((terrno = qSetMultiStreamInput(taskInfo, &dataBlock, 1, STREAM_INPUT__DATA_BLOCK)) < 0) { + if ((terrno = qSetSMAInput(taskInfo, &dataBlock, 1, STREAM_INPUT__DATA_BLOCK)) < 0) { goto _err; } if (tdRSmaExecAndSubmitResult(pSma, taskInfo, pItem, pInfo->pTSchema, pInfo->suid) < 0) { diff --git a/source/dnode/vnode/src/sma/smaTimeRange.c b/source/dnode/vnode/src/sma/smaTimeRange.c index b0ae97263598743fe8b022ad0b184a1331aa9446..f5ba7b501412841a943ab75dcf481cf999dc14f9 100644 --- a/source/dnode/vnode/src/sma/smaTimeRange.c +++ b/source/dnode/vnode/src/sma/smaTimeRange.c @@ -197,7 +197,7 @@ static int32_t tdProcessTSmaInsertImpl(SSma *pSma, int64_t indexUid, const char } if (pTsmaStat->pTSma->indexUid != indexUid) { - terrno = TSDB_CODE_VND_APP_ERROR; + terrno = TSDB_CODE_APP_ERROR; smaError("vgId:%d, tsma insert for smaIndex %" PRIi64 "(!=%" PRIi64 ") failed since %s", SMA_VID(pSma), indexUid, pTsmaStat->pTSma->indexUid, tstrerror(terrno)); goto _err; diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 1b4f67cc7107782d8b5ea20748dad230e42cfc9a..9c377fe7f579756c0a3e374e57d337ad276a519a 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -671,8 +671,6 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) { if (tqTaosxScanLog(pTq, pHandle, pCont, &taosxRsp) < 0) { /*ASSERT(0);*/ } - // TODO batch optimization: - // TODO continue scan until meeting batch requirement if (taosxRsp.blockNum > 0 /* threshold */) { tqOffsetResetToLog(&taosxRsp.rspOffset, fetchVer); if (tqSendTaosxRsp(pTq, pMsg, pReq, &taosxRsp) < 0) { @@ -711,7 +709,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg) { return 0; } -int32_t tqProcessVgDeleteReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen) { +int32_t tqProcessDeleteSubReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen) { SMqVDeleteReq* pReq = (SMqVDeleteReq*)msg; taosWLockLatch(&pTq->pushLock); @@ -769,7 +767,7 @@ int32_t tqProcessDelCheckInfoReq(STQ* pTq, int64_t version, char* msg, int32_t m return 0; } -int32_t tqProcessVgChangeReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen) { +int32_t tqProcessSubscribeReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen) { SMqRebVgReq req = {0}; tDecodeSMqRebVgReq(msg, &req); // todo lock @@ -898,6 +896,10 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int64_t ver) { pTask->startVer = ver; // expand executor + if (pTask->fillHistory) { + pTask->taskStatus = TASK_STATUS__WAIT_DOWNSTREAM; + } + if (pTask->taskLevel == TASK_LEVEL__SOURCE) { pTask->pState = streamStateOpen(pTq->pStreamMeta->path, pTask, false, -1, -1); if (pTask->pState == NULL) { @@ -913,9 +915,6 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int64_t ver) { pTask->exec.executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &handle); ASSERT(pTask->exec.executor); - if (pTask->fillHistory) { - pTask->taskStatus = TASK_STATUS__RECOVER_PREPARE; - } } else if (pTask->taskLevel == TASK_LEVEL__AGG) { pTask->pState = streamStateOpen(pTq->pStreamMeta->path, pTask, false, -1, -1); if (pTask->pState == NULL) { @@ -949,11 +948,90 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int64_t ver) { streamSetupTrigger(pTask); - tqInfo("expand stream task on vg %d, task id %d, child id %d", TD_VID(pTq->pVnode), pTask->taskId, - pTask->selfChildId); + tqInfo("expand stream task on vg %d, task id %d, child id %d, level %d", TD_VID(pTq->pVnode), pTask->taskId, + pTask->selfChildId, pTask->taskLevel); + return 0; +} + +int32_t tqProcessStreamTaskCheckReq(STQ* pTq, SRpcMsg* pMsg) { + char* msgStr = pMsg->pCont; + char* msgBody = POINTER_SHIFT(msgStr, sizeof(SMsgHead)); + int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); + SStreamTaskCheckReq req; + SDecoder decoder; + tDecoderInit(&decoder, msgBody, msgLen); + tDecodeSStreamTaskCheckReq(&decoder, &req); + tDecoderClear(&decoder); + int32_t taskId = req.downstreamTaskId; + SStreamTaskCheckRsp rsp = { + .reqId = req.reqId, + .streamId = req.streamId, + .childId = req.childId, + .downstreamNodeId = req.downstreamNodeId, + .downstreamTaskId = req.downstreamTaskId, + .upstreamNodeId = req.upstreamNodeId, + .upstreamTaskId = req.upstreamTaskId, + }; + SStreamTask* pTask = streamMetaGetTask(pTq->pStreamMeta, taskId); + if (pTask && atomic_load_8(&pTask->taskStatus) == TASK_STATUS__NORMAL) { + rsp.status = 1; + } else { + rsp.status = 0; + } + + tqDebug("tq recv task check req(reqId: %" PRId64 ") %d at node %d check req from task %d at node %d, status %d", + rsp.reqId, rsp.downstreamTaskId, rsp.downstreamNodeId, rsp.upstreamTaskId, rsp.upstreamNodeId, rsp.status); + + SEncoder encoder; + int32_t code; + int32_t len; + tEncodeSize(tEncodeSStreamTaskCheckRsp, &rsp, len, code); + if (code < 0) { + ASSERT(0); + } + void* buf = rpcMallocCont(sizeof(SMsgHead) + len); + ((SMsgHead*)buf)->vgId = htonl(req.upstreamNodeId); + + void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); + tEncoderInit(&encoder, (uint8_t*)abuf, len); + tEncodeSStreamTaskCheckRsp(&encoder, &rsp); + tEncoderClear(&encoder); + + SRpcMsg rspMsg = { + .code = 0, + .pCont = buf, + .contLen = sizeof(SMsgHead) + len, + .info = pMsg->info, + }; + + tmsgSendRsp(&rspMsg); return 0; } +int32_t tqProcessStreamTaskCheckRsp(STQ* pTq, int64_t version, char* msg, int32_t msgLen) { + int32_t code; + SStreamTaskCheckRsp rsp; + + SDecoder decoder; + tDecoderInit(&decoder, (uint8_t*)msg, msgLen); + code = tDecodeSStreamTaskCheckRsp(&decoder, &rsp); + if (code < 0) { + tDecoderClear(&decoder); + return -1; + } + tDecoderClear(&decoder); + + tqDebug("tq recv task check rsp(reqId: %" PRId64 ") %d at node %d check req from task %d at node %d, status %d", + rsp.reqId, rsp.downstreamTaskId, rsp.downstreamNodeId, rsp.upstreamTaskId, rsp.upstreamNodeId, rsp.status); + + SStreamTask* pTask = streamMetaGetTask(pTq->pStreamMeta, rsp.upstreamTaskId); + if (pTask == NULL) { + return -1; + } + + return streamProcessTaskCheckRsp(pTask, &rsp, version); +} + int32_t tqProcessTaskDeployReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen) { int32_t code; #if 0 @@ -984,36 +1062,17 @@ int32_t tqProcessTaskDeployReq(STQ* pTq, int64_t version, char* msg, int32_t msg // 3.go through recover steps to fill history if (pTask->fillHistory) { - streamSetParamForRecover(pTask); - if (pTask->taskLevel == TASK_LEVEL__SOURCE) { - streamSourceRecoverPrepareStep1(pTask, version); - - SStreamRecoverStep1Req req; - streamBuildSourceRecover1Req(pTask, &req); - - void* serialziedReq = (void*)&req; - int32_t len = sizeof(SStreamRecoverStep1Req); - - SRpcMsg rpcMsg = { - .contLen = len, - .pCont = serialziedReq, - .msgType = TDMT_VND_STREAM_RECOVER_STEP1, - }; - - tmsgPutToQueue(&pTq->pVnode->msgCb, STREAM_QUEUE, &rpcMsg); - - } else if (pTask->taskLevel == TASK_LEVEL__AGG) { - streamAggRecoverPrepare(pTask); - } else if (pTask->taskLevel == TASK_LEVEL__SINK) { - // do nothing - } + streamTaskCheckDownstream(pTask, version); } return 0; } -int32_t tqProcessTaskRecover1Req(STQ* pTq, char* msg, int32_t msgLen) { - int32_t code; +int32_t tqProcessTaskRecover1Req(STQ* pTq, SRpcMsg* pMsg) { + int32_t code; + char* msg = pMsg->pCont; + int32_t msgLen = pMsg->contLen; + SStreamRecoverStep1Req* pReq = (SStreamRecoverStep1Req*)msg; SStreamTask* pTask = streamMetaGetTask(pTq->pStreamMeta, pReq->taskId); if (pTask == NULL) { @@ -1037,16 +1096,24 @@ int32_t tqProcessTaskRecover1Req(STQ* pTq, char* msg, int32_t msgLen) { return -1; } + ASSERT(pReq->taskId == pTask->taskId); + // serialize msg - int32_t len = sizeof(SStreamRecoverStep2Req); - void* serializedReq = (void*)&req; + int32_t len = sizeof(SStreamRecoverStep1Req); + + void* serializedReq = rpcMallocCont(len); + if (serializedReq == NULL) { + return -1; + } + + memcpy(serializedReq, &req, len); // dispatch msg SRpcMsg rpcMsg = { .code = 0, .contLen = len, .msgType = TDMT_VND_STREAM_RECOVER_STEP2, - .pCont = (void*)serializedReq, + .pCont = serializedReq, }; tmsgPutToQueue(&pTq->pVnode->msgCb, WRITE_QUEUE, &rpcMsg); @@ -1089,15 +1156,15 @@ int32_t tqProcessTaskRecover2Req(STQ* pTq, int64_t version, char* msg, int32_t m return 0; } -int32_t tqProcessTaskRecoverFinishReq(STQ* pTq, char* msg, int32_t msgLen) { - int32_t code; +int32_t tqProcessTaskRecoverFinishReq(STQ* pTq, SRpcMsg* pMsg) { + char* msg = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); + int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); // deserialize - int32_t len; SStreamRecoverFinishReq req; SDecoder decoder; - tDecoderInit(&decoder, msg, sizeof(SStreamRecoverFinishReq)); + tDecoderInit(&decoder, msg, msgLen); tDecodeSStreamRecoverFinishReq(&decoder, &req); tDecoderClear(&decoder); @@ -1114,6 +1181,11 @@ int32_t tqProcessTaskRecoverFinishReq(STQ* pTq, char* msg, int32_t msgLen) { return 0; } +int32_t tqProcessTaskRecoverFinishRsp(STQ* pTq, SRpcMsg* pMsg) { + // + return 0; +} + int32_t tqProcessDelReq(STQ* pTq, void* pReq, int32_t len, int64_t ver) { bool failed = false; SDecoder* pCoder = &(SDecoder){0}; @@ -1237,7 +1309,7 @@ int32_t tqProcessSubmitReq(STQ* pTq, SSubmitReq* pReq, int64_t ver) { pSubmit = streamDataSubmitNew(pReq); if (pSubmit == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; - qError("failed to create data submit for stream since out of memory"); + tqError("failed to create data submit for stream since out of memory"); failed = true; } @@ -1246,18 +1318,21 @@ int32_t tqProcessSubmitReq(STQ* pTq, SSubmitReq* pReq, int64_t ver) { if (pIter == NULL) break; SStreamTask* pTask = *(SStreamTask**)pIter; if (pTask->taskLevel != TASK_LEVEL__SOURCE) continue; - if (pTask->taskStatus == TASK_STATUS__RECOVER_PREPARE || pTask->taskStatus == TASK_STATUS__RECOVER1) continue; + if (pTask->taskStatus == TASK_STATUS__RECOVER_PREPARE || pTask->taskStatus == TASK_STATUS__WAIT_DOWNSTREAM) { + tqDebug("skip push task %d, task status %d", pTask->taskId, pTask->taskStatus); + continue; + } - qDebug("data submit enqueue stream task: %d, ver: %" PRId64, pTask->taskId, ver); + tqDebug("data submit enqueue stream task: %d, ver: %" PRId64, pTask->taskId, ver); if (!failed) { if (streamTaskInput(pTask, (SStreamQueueItem*)pSubmit) < 0) { - qError("stream task input failed, task id %d", pTask->taskId); + tqError("stream task input failed, task id %d", pTask->taskId); continue; } if (streamSchedExec(pTask) < 0) { - qError("stream task launch failed, task id %d", pTask->taskId); + tqError("stream task launch failed, task id %d", pTask->taskId); continue; } } else { @@ -1274,7 +1349,6 @@ int32_t tqProcessSubmitReq(STQ* pTq, SSubmitReq* pReq, int64_t ver) { } int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg) { - // SStreamTaskRunReq* pReq = pMsg->pCont; int32_t taskId = pReq->taskId; SStreamTask* pTask = streamMetaGetTask(pTq->pStreamMeta, taskId); @@ -1287,7 +1361,6 @@ int32_t tqProcessTaskRunReq(STQ* pTq, SRpcMsg* pMsg) { } int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg, bool exec) { - ASSERT(0); char* msgStr = pMsg->pCont; char* msgBody = POINTER_SHIFT(msgStr, sizeof(SMsgHead)); int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); @@ -1310,39 +1383,13 @@ int32_t tqProcessTaskDispatchReq(STQ* pTq, SRpcMsg* pMsg, bool exec) { } } -#if 0 -int32_t tqProcessTaskRecoverReq(STQ* pTq, SRpcMsg* pMsg) { - SStreamTaskRecoverReq* pReq = pMsg->pCont; - int32_t taskId = pReq->taskId; - SStreamTask* pTask = streamMetaGetTask(pTq->pStreamMeta, taskId); - if (pTask) { - streamProcessRecoverReq(pTask, pReq, pMsg); - return 0; - } else { - return -1; - } -} - -int32_t tqProcessTaskRecoverRsp(STQ* pTq, SRpcMsg* pMsg) { - SStreamTaskRecoverRsp* pRsp = pMsg->pCont; - int32_t taskId = pRsp->rspTaskId; - - SStreamTask* pTask = streamMetaGetTask(pTq->pStreamMeta, taskId); - if (pTask) { - streamProcessRecoverRsp(pTask, pRsp); - return 0; - } else { - return -1; - } -} -#endif - int32_t tqProcessTaskDispatchRsp(STQ* pTq, SRpcMsg* pMsg) { SStreamDispatchRsp* pRsp = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); - int32_t taskId = pRsp->taskId; + int32_t taskId = ntohl(pRsp->upstreamTaskId); SStreamTask* pTask = streamMetaGetTask(pTq->pStreamMeta, taskId); + tqDebug("recv dispatch rsp, code: %x", pMsg->code); if (pTask) { - streamProcessDispatchRsp(pTask, pRsp); + streamProcessDispatchRsp(pTask, pRsp, pMsg->code); return 0; } else { return -1; @@ -1351,7 +1398,6 @@ int32_t tqProcessTaskDispatchRsp(STQ* pTq, SRpcMsg* pMsg) { int32_t tqProcessTaskDropReq(STQ* pTq, int64_t version, char* msg, int32_t msgLen) { SVDropStreamTaskReq* pReq = (SVDropStreamTaskReq*)msg; - return streamMetaRemoveTask(pTq->pStreamMeta, pReq->taskId); } @@ -1384,12 +1430,12 @@ int32_t tqProcessTaskRetrieveRsp(STQ* pTq, SRpcMsg* pMsg) { return 0; } -void vnodeEnqueueStreamMsg(SVnode* pVnode, SRpcMsg* pMsg) { - STQ* pTq = pVnode->pTq; - char* msgStr = pMsg->pCont; - char* msgBody = POINTER_SHIFT(msgStr, sizeof(SMsgHead)); - int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); - int32_t code = 0; +int32_t vnodeEnqueueStreamMsg(SVnode* pVnode, SRpcMsg* pMsg) { + STQ* pTq = pVnode->pTq; + SMsgHead* msgStr = pMsg->pCont; + char* msgBody = POINTER_SHIFT(msgStr, sizeof(SMsgHead)); + int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); + int32_t code = 0; SStreamDispatchReq req; SDecoder decoder; @@ -1412,16 +1458,45 @@ void vnodeEnqueueStreamMsg(SVnode* pVnode, SRpcMsg* pMsg) { streamProcessDispatchReq(pTask, &req, &rsp, false); rpcFreeCont(pMsg->pCont); taosFreeQitem(pMsg); - return; + return 0; } + code = TSDB_CODE_STREAM_TASK_NOT_EXIST; + FAIL: - if (pMsg->info.handle == NULL) return; + if (pMsg->info.handle == NULL) return -1; + + SMsgHead* pRspHead = rpcMallocCont(sizeof(SMsgHead) + sizeof(SStreamDispatchRsp)); + if (pRspHead == NULL) { + SRpcMsg rsp = { + .code = TSDB_CODE_OUT_OF_MEMORY, + .info = pMsg->info, + }; + tqDebug("send dispatch error rsp, code: %x", code); + tmsgSendRsp(&rsp); + rpcFreeCont(pMsg->pCont); + taosFreeQitem(pMsg); + return -1; + } + + pRspHead->vgId = htonl(req.upstreamNodeId); + SStreamDispatchRsp* pRsp = POINTER_SHIFT(pRspHead, sizeof(SMsgHead)); + pRsp->streamId = htobe64(req.streamId); + pRsp->upstreamTaskId = htonl(req.upstreamTaskId); + pRsp->upstreamNodeId = htonl(req.upstreamNodeId); + pRsp->downstreamNodeId = htonl(pVnode->config.vgId); + pRsp->downstreamTaskId = htonl(req.taskId); + pRsp->inputStatus = TASK_OUTPUT_STATUS__NORMAL; + SRpcMsg rsp = { .code = code, .info = pMsg->info, + .contLen = sizeof(SMsgHead) + sizeof(SStreamDispatchRsp), + .pCont = pRspHead, }; + tqDebug("send dispatch error rsp, code: %x", code); tmsgSendRsp(&rsp); rpcFreeCont(pMsg->pCont); taosFreeQitem(pMsg); + return -1; } diff --git a/source/dnode/vnode/src/tq/tqExec.c b/source/dnode/vnode/src/tq/tqExec.c index a6e8767a4d8347aafa3f6053e2c07f6439b399ea..48c14bc758bc4ee6271b20a731b7f0a25be2ea4b 100644 --- a/source/dnode/vnode/src/tq/tqExec.c +++ b/source/dnode/vnode/src/tq/tqExec.c @@ -27,9 +27,7 @@ int32_t tqAddBlockDataToRsp(const SSDataBlock* pBlock, SMqDataRsp* pRsp, int32_t pRetrieve->completed = 1; pRetrieve->numOfRows = htonl(pBlock->info.rows); - // TODO enable compress - int32_t actualLen = 0; - blockEncode(pBlock, pRetrieve->data, &actualLen, numOfCols, false); + int32_t actualLen = blockEncode(pBlock, pRetrieve->data, numOfCols); actualLen += sizeof(SRetrieveTableRsp); ASSERT(actualLen <= dataStrLen); taosArrayPush(pRsp->blockDataLen, &actualLen); diff --git a/source/dnode/vnode/src/tq/tqMeta.c b/source/dnode/vnode/src/tq/tqMeta.c index b852acb936450dcdeda2db1c22ea3a240b2f3105..27c491c86b432477b4174edc6f5f842e1a5a843b 100644 --- a/source/dnode/vnode/src/tq/tqMeta.c +++ b/source/dnode/vnode/src/tq/tqMeta.c @@ -125,6 +125,10 @@ int32_t tqMetaSaveCheckInfo(STQ* pTq, const char* key, const void* value, int32_ return -1; } + if (tdbPostCommit(pTq->pMetaDB, &txn) < 0) { + return -1; + } + return 0; } @@ -147,6 +151,10 @@ int32_t tqMetaDeleteCheckInfo(STQ* pTq, const char* key) { ASSERT(0); } + if (tdbPostCommit(pTq->pMetaDB, &txn) < 0) { + ASSERT(0); + } + return 0; } @@ -226,6 +234,10 @@ int32_t tqMetaSaveHandle(STQ* pTq, const char* key, const STqHandle* pHandle) { ASSERT(0); } + if (tdbPostCommit(pTq->pMetaDB, &txn) < 0) { + ASSERT(0); + } + tEncoderClear(&encoder); taosMemoryFree(buf); return 0; @@ -250,6 +262,10 @@ int32_t tqMetaDeleteHandle(STQ* pTq, const char* key) { ASSERT(0); } + if (tdbPostCommit(pTq->pMetaDB, &txn) < 0) { + ASSERT(0); + } + return 0; } diff --git a/source/dnode/vnode/src/tq/tqOffset.c b/source/dnode/vnode/src/tq/tqOffset.c index 952f81e1f46fdd5d6d3e537921a8c2f3790a6925..a7f816bb1be2dfec3f848d01081ad90a91106e3d 100644 --- a/source/dnode/vnode/src/tq/tqOffset.c +++ b/source/dnode/vnode/src/tq/tqOffset.c @@ -17,9 +17,9 @@ #include "tq.h" struct STqOffsetStore { - char* fname; STQ* pTq; SHashObj* pHash; // SHashObj + int8_t needCommit; }; char* tqOffsetBuildFName(const char* path, int32_t fVer) { @@ -74,6 +74,7 @@ STqOffsetStore* tqOffsetOpen(STQ* pTq) { return NULL; } pStore->pTq = pTq; + pStore->needCommit = 0; pTq->pOffsetStore = pStore; pStore->pHash = taosHashInit(64, MurmurHash3_32, true, HASH_NO_LOCK); @@ -100,6 +101,7 @@ STqOffset* tqOffsetRead(STqOffsetStore* pStore, const char* subscribeKey) { } int32_t tqOffsetWrite(STqOffsetStore* pStore, const STqOffset* pOffset) { + pStore->needCommit = 1; return taosHashPut(pStore->pHash, pOffset->subKey, strlen(pOffset->subKey), pOffset, sizeof(STqOffset)); } @@ -108,14 +110,23 @@ int32_t tqOffsetDelete(STqOffsetStore* pStore, const char* subscribeKey) { } int32_t tqOffsetCommitFile(STqOffsetStore* pStore) { + if (!pStore->needCommit) return 0; // TODO file name should be with a newer version char* fname = tqOffsetBuildFName(pStore->pTq->path, 0); TdFilePtr pFile = taosOpenFile(fname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); - taosMemoryFree(fname); if (pFile == NULL) { + terrno = TAOS_SYSTEM_ERROR(errno); + + int32_t err = terrno; + const char* errStr = tstrerror(err); + int32_t sysErr = errno; + const char* sysErrStr = strerror(errno); + tqError("vgId:%d, cannot open file %s when commit offset since %s", pStore->pTq->pVnode->config.vgId, fname, + sysErrStr); ASSERT(0); return -1; } + taosMemoryFree(fname); void* pIter = NULL; while (1) { pIter = taosHashIterate(pStore->pHash, pIter); @@ -152,5 +163,6 @@ int32_t tqOffsetCommitFile(STqOffsetStore* pStore) { } // close and rename file taosCloseFile(&pFile); + pStore->needCommit = 0; return 0; } diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c index 2f6ec0c39f14215351e3ea09d1a6c9d8b675eb26..48e69f8f4d303dca8071e497c3b48665400bdd9b 100644 --- a/source/dnode/vnode/src/tq/tqRead.c +++ b/source/dnode/vnode/src/tq/tqRead.c @@ -199,6 +199,9 @@ int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalCkHea goto END; } + tqDebug("vgId:%d, taosx get msg ver %" PRId64 ", type: %s", pTq->pVnode->config.vgId, offset, + TMSG_INFO((*ppCkHead)->head.msgType)); + if ((*ppCkHead)->head.msgType == TDMT_VND_SUBMIT) { code = walFetchBody(pHandle->pWalReader, ppCkHead); @@ -216,17 +219,20 @@ int64_t tqFetchLog(STQ* pTq, STqHandle* pHandle, int64_t* fetchOffset, SWalCkHea SWalCont* pHead = &((*ppCkHead)->head); if (IS_META_MSG(pHead->msgType)) { code = walFetchBody(pHandle->pWalReader, ppCkHead); - if (code < 0) { ASSERT(0); *fetchOffset = offset; code = -1; goto END; } + if (isValValidForTable(pHandle, pHead)) { *fetchOffset = offset; code = 0; goto END; + } else { + offset++; + continue; } } } @@ -586,8 +592,39 @@ int32_t tqUpdateTbUidList(STQ* pTq, const SArray* tbUidList, bool isAdd) { taosHashPut(pExec->execHandle.execDb.pFilterOutTbUid, &tbUid, sizeof(int64_t), NULL, 0); } } + } else if (pExec->execHandle.subType == TOPIC_SUB_TYPE__TABLE) { + if (isAdd) { + SArray* qa = taosArrayInit(4, sizeof(tb_uid_t)); + SMetaReader mr = {0}; + metaReaderInit(&mr, pTq->pVnode->pMeta, 0); + for (int32_t i = 0; i < taosArrayGetSize(tbUidList); ++i) { + uint64_t* id = (uint64_t*)taosArrayGet(tbUidList, i); + + int32_t code = metaGetTableEntryByUid(&mr, *id); + if (code != TSDB_CODE_SUCCESS) { + qError("failed to get table meta, uid:%" PRIu64 " code:%s", *id, tstrerror(terrno)); + continue; + } + + tDecoderClear(&mr.coder); + + if (mr.me.type != TSDB_CHILD_TABLE || mr.me.ctbEntry.suid != pExec->execHandle.execTb.suid) { + tqDebug("table uid %" PRId64 " does not add to tq handle", *id); + continue; + } + tqDebug("table uid %" PRId64 " add to tq handle", *id); + taosArrayPush(qa, id); + } + metaReaderClear(&mr); + if (taosArrayGetSize(qa) > 0) { + tqReaderAddTbUidList(pExec->execHandle.pExecReader, qa); + } + taosArrayDestroy(qa); + } else { + // TODO handle delete table from stb + } } else { - // tq update id + ASSERT(0); } } while (1) { diff --git a/source/dnode/vnode/src/tq/tqSink.c b/source/dnode/vnode/src/tq/tqSink.c index 8a811512737cc3b33079e1e1be2bf65eeda0d0f4..913fa67bd6a0e5fec7bcc4fd3f35880328bef32c 100644 --- a/source/dnode/vnode/src/tq/tqSink.c +++ b/source/dnode/vnode/src/tq/tqSink.c @@ -25,6 +25,8 @@ int32_t tqBuildDeleteReq(SVnode* pVnode, const char* stbFullName, const SSDataBl SColumnInfoData* pGidCol = taosArrayGet(pDataBlock->pDataBlock, GROUPID_COLUMN_INDEX); SColumnInfoData* pTbNameCol = taosArrayGet(pDataBlock->pDataBlock, TABLE_NAME_COLUMN_INDEX); + tqDebug("stream delete msg: row %d", totRow); + for (int32_t row = 0; row < totRow; row++) { int64_t ts = *(int64_t*)colDataGetData(pTsCol, row); int64_t groupId = *(int64_t*)colDataGetData(pGidCol, row); @@ -36,22 +38,28 @@ int32_t tqBuildDeleteReq(SVnode* pVnode, const char* stbFullName, const SSDataBl } else { name = buildCtbNameByGroupId(stbFullName, groupId); } - tqDebug("stream delete msg: groupId :%" PRId64 ", name: %s", groupId, name); + tqDebug("stream delete msg: vgId:%d, groupId :%" PRId64 ", name: %s, ts:%" PRId64, pVnode->config.vgId, groupId, + name, ts); +#if 0 SMetaReader mr = {0}; metaReaderInit(&mr, pVnode->pMeta, 0); if (metaGetTableEntryByName(&mr, name) < 0) { metaReaderClear(&mr); + tqDebug("stream delete msg, skip vgId:%d since no table: %s", pVnode->config.vgId, name); taosMemoryFree(name); - return -1; + continue; } int64_t uid = mr.me.uid; metaReaderClear(&mr); taosMemoryFree(name); +#endif SSingleDeleteReq req = { .ts = ts, - .uid = uid, }; + strncpy(req.tbname, name, TSDB_TABLE_NAME_LEN); + taosMemoryFree(name); + /*tqDebug("stream delete msg, active: vgId:%d, ts:%" PRId64 " name:%s", pVnode->config.vgId, ts, name);*/ taosArrayPush(deleteReq->deleteReqs, &req); } return 0; @@ -309,6 +317,10 @@ void tqSinkToTablePipeline(SStreamTask* pTask, void* vnode, int64_t ver, void* d deleteReq.deleteReqs = taosArrayInit(0, sizeof(SSingleDeleteReq)); deleteReq.suid = suid; tqBuildDeleteReq(pVnode, stbFullName, pDataBlock, &deleteReq); + if (taosArrayGetSize(deleteReq.deleteReqs) == 0) { + taosArrayDestroy(deleteReq.deleteReqs); + continue; + } int32_t len; int32_t code; diff --git a/source/dnode/vnode/src/tq/tqSnapshot.c b/source/dnode/vnode/src/tq/tqSnapshot.c index c52e0e2c098478c0fc055306ad2eda9ced09dfea..b68763867efcf9a8e7c13ec43bfb827df75b5959 100644 --- a/source/dnode/vnode/src/tq/tqSnapshot.c +++ b/source/dnode/vnode/src/tq/tqSnapshot.c @@ -169,6 +169,8 @@ int32_t tqSnapWriterClose(STqSnapWriter** ppWriter, int8_t rollback) { } else { code = tdbCommit(pWriter->pTq->pMetaDB, &pWriter->txn); if (code) goto _err; + code = tdbPostCommit(pWriter->pTq->pMetaDB, &pWriter->txn); + if (code) goto _err; } taosMemoryFree(pWriter); diff --git a/source/dnode/vnode/src/tq/tqStreamStateSnap.c b/source/dnode/vnode/src/tq/tqStreamStateSnap.c index 92e5f8df7adc3c2061a39979ad51f2e238a88097..08d5931bc3250895d2f2eea5b9c164e54ae4c127 100644 --- a/source/dnode/vnode/src/tq/tqStreamStateSnap.c +++ b/source/dnode/vnode/src/tq/tqStreamStateSnap.c @@ -169,6 +169,8 @@ int32_t tqSnapWriterClose(STqSnapWriter** ppWriter, int8_t rollback) { } else { code = tdbCommit(pWriter->pTq->pMetaDB, &pWriter->txn); if (code) goto _err; + code = tdbPostCommit(pWriter->pTq->pMetaDB, &pWriter->txn); + if (code) goto _err; } taosMemoryFree(pWriter); diff --git a/source/dnode/vnode/src/tq/tqStreamTaskSnap.c b/source/dnode/vnode/src/tq/tqStreamTaskSnap.c index b4a7ce7737e5f599dac051f33e275918e7709c0d..31e44a5b6dcd170d801b3aa0481b6dd7ea851f0b 100644 --- a/source/dnode/vnode/src/tq/tqStreamTaskSnap.c +++ b/source/dnode/vnode/src/tq/tqStreamTaskSnap.c @@ -169,6 +169,8 @@ int32_t tqSnapWriterClose(STqSnapWriter** ppWriter, int8_t rollback) { } else { code = tdbCommit(pWriter->pTq->pMetaStore, &pWriter->txn); if (code) goto _err; + code = tdbPostCommit(pWriter->pTq->pMetaStore, &pWriter->txn); + if (code) goto _err; } taosMemoryFree(pWriter); diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index aa5058a1a2eb2b1c0fd1d4264ea1fe91d96ccdd9..76236e5078392229b109911904de0244d8bfff1c 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -684,7 +684,7 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow) { if (*state->pDataFReader != NULL) { tsdbDataFReaderClose(state->pDataFReader); - resetLastBlockLoadInfo(state->pLoadInfo); + // resetLastBlockLoadInfo(state->pLoadInfo); } code = tsdbDataFReaderOpen(state->pDataFReader, state->pTsdb, pFileSet); @@ -764,7 +764,7 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow) { if (--state->iBlock < 0) { tsdbDataFReaderClose(state->pDataFReader); *state->pDataFReader = NULL; - resetLastBlockLoadInfo(state->pLoadInfo); + // resetLastBlockLoadInfo(state->pLoadInfo); if (state->aBlockIdx) { taosArrayDestroy(state->aBlockIdx); @@ -1093,72 +1093,71 @@ _err: // iterate next row non deleted backward ts, version (from high to low) static int32_t nextRowIterGet(CacheNextRowIter *pIter, TSDBROW **ppRow) { int code = 0; + for (;;) { + for (int i = 0; i < 4; ++i) { + if (pIter->input[i].next && !pIter->input[i].stop) { + code = pIter->input[i].nextRowFn(pIter->input[i].iter, &pIter->input[i].pRow); + if (code) goto _err; - for (int i = 0; i < 4; ++i) { - if (pIter->input[i].next && !pIter->input[i].stop) { - code = pIter->input[i].nextRowFn(pIter->input[i].iter, &pIter->input[i].pRow); - if (code) goto _err; - - if (pIter->input[i].pRow == NULL) { - pIter->input[i].stop = true; - pIter->input[i].next = false; + if (pIter->input[i].pRow == NULL) { + pIter->input[i].stop = true; + pIter->input[i].next = false; + } } } - } - if (pIter->input[0].stop && pIter->input[1].stop && pIter->input[2].stop && pIter->input[3].stop) { - *ppRow = NULL; - return code; - } + if (pIter->input[0].stop && pIter->input[1].stop && pIter->input[2].stop && pIter->input[3].stop) { + *ppRow = NULL; + return code; + } - // select maxpoint(s) from mem, imem, fs and last - TSDBROW *max[4] = {0}; - int iMax[4] = {-1, -1, -1, -1}; - int nMax = 0; - TSKEY maxKey = TSKEY_MIN; + // select maxpoint(s) from mem, imem, fs and last + TSDBROW *max[4] = {0}; + int iMax[4] = {-1, -1, -1, -1}; + int nMax = 0; + TSKEY maxKey = TSKEY_MIN; + + for (int i = 0; i < 4; ++i) { + if (!pIter->input[i].stop && pIter->input[i].pRow != NULL) { + TSDBKEY key = TSDBROW_KEY(pIter->input[i].pRow); + + // merging & deduplicating on client side + if (maxKey <= key.ts) { + if (maxKey < key.ts) { + nMax = 0; + maxKey = key.ts; + } - for (int i = 0; i < 4; ++i) { - if (!pIter->input[i].stop && pIter->input[i].pRow != NULL) { - TSDBKEY key = TSDBROW_KEY(pIter->input[i].pRow); - - // merging & deduplicating on client side - if (maxKey <= key.ts) { - if (maxKey < key.ts) { - nMax = 0; - maxKey = key.ts; + iMax[nMax] = i; + max[nMax++] = pIter->input[i].pRow; } - - iMax[nMax] = i; - max[nMax++] = pIter->input[i].pRow; } } - } - // delete detection - TSDBROW *merge[4] = {0}; - int iMerge[4] = {-1, -1, -1, -1}; - int nMerge = 0; - for (int i = 0; i < nMax; ++i) { - TSDBKEY maxKey1 = TSDBROW_KEY(max[i]); - - bool deleted = tsdbKeyDeleted(&maxKey1, pIter->pSkyline, &pIter->iSkyline); - if (!deleted) { - iMerge[nMerge] = iMax[i]; - merge[nMerge++] = max[i]; - } + // delete detection + TSDBROW *merge[4] = {0}; + int iMerge[4] = {-1, -1, -1, -1}; + int nMerge = 0; + for (int i = 0; i < nMax; ++i) { + TSDBKEY maxKey1 = TSDBROW_KEY(max[i]); + + bool deleted = tsdbKeyDeleted(&maxKey1, pIter->pSkyline, &pIter->iSkyline); + if (!deleted) { + iMerge[nMerge] = iMax[i]; + merge[nMerge++] = max[i]; + } - pIter->input[iMax[i]].next = deleted; - } + pIter->input[iMax[i]].next = deleted; + } - if (nMerge > 0) { - pIter->input[iMerge[0]].next = true; + if (nMerge > 0) { + pIter->input[iMerge[0]].next = true; - *ppRow = merge[0]; - } else { - *ppRow = NULL; + *ppRow = merge[0]; + return code; + } } - return code; _err: return code; } diff --git a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c index b8f49f38e4a020dc8ba407f822cb4f83e29212e0..2ae3115c0ab8de0f19a6bf82d2cc2fa9de4d3e9b 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCacheRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbCacheRead.c @@ -97,10 +97,9 @@ static void saveOneRow(SArray* pRow, SSDataBlock* pBlock, SCacheRowsReader* pRea } } -int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList, int32_t numOfCols, uint64_t suid, - void** pReader) { +int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, void* pTableIdList, int32_t numOfTables, int32_t numOfCols, + uint64_t suid, void** pReader) { *pReader = NULL; - SCacheRowsReader* p = taosMemoryCalloc(1, sizeof(SCacheRowsReader)); if (p == NULL) { return TSDB_CODE_OUT_OF_MEMORY; @@ -111,14 +110,15 @@ int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList p->numOfCols = numOfCols; p->suid = suid; - if (taosArrayGetSize(pTableIdList) == 0) { + if (numOfTables == 0) { *pReader = p; return TSDB_CODE_SUCCESS; } - STableKeyInfo* pKeyInfo = taosArrayGet(pTableIdList, 0); + STableKeyInfo* pKeyInfo = &((STableKeyInfo*)pTableIdList)[0]; p->pSchema = metaGetTbTSchema(p->pVnode->pMeta, pKeyInfo->uid, -1, 1); p->pTableList = pTableIdList; + p->numOfTables = numOfTables; p->transferBuf = taosMemoryCalloc(p->pSchema->numOfCols, POINTER_BYTES); if (p->transferBuf == NULL) { @@ -205,7 +205,6 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32 SLRUCache* lruCache = pr->pVnode->pTsdb->lruCache; LRUHandle* h = NULL; SArray* pRow = NULL; - size_t numOfTables = taosArrayGetSize(pr->pTableList); bool hasRes = false; SArray* pLastCols = NULL; @@ -243,8 +242,8 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32 // retrieve the only one last row of all tables in the uid list. if (HASTYPE(pr->type, CACHESCAN_RETRIEVE_TYPE_SINGLE)) { - for (int32_t i = 0; i < numOfTables; ++i) { - STableKeyInfo* pKeyInfo = taosArrayGet(pr->pTableList, i); + for (int32_t i = 0; i < pr->numOfTables; ++i) { + STableKeyInfo* pKeyInfo = &pr->pTableList[i]; code = doExtractCacheRow(pr, lruCache, pKeyInfo->uid, &pRow, &h); if (code != TSDB_CODE_SUCCESS) { @@ -308,8 +307,8 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32 } } else if (HASTYPE(pr->type, CACHESCAN_RETRIEVE_TYPE_ALL)) { - for (int32_t i = pr->tableIndex; i < numOfTables; ++i) { - STableKeyInfo* pKeyInfo = (STableKeyInfo*)taosArrayGet(pr->pTableList, i); + for (int32_t i = pr->tableIndex; i < pr->numOfTables; ++i) { + STableKeyInfo* pKeyInfo = &pr->pTableList[i]; code = doExtractCacheRow(pr, lruCache, pKeyInfo->uid, &pRow, &h); if (code != TSDB_CODE_SUCCESS) { return code; @@ -339,6 +338,7 @@ _end: tsdbDataFReaderClose(&pr->pDataFReader); tsdbUntakeReadSnap(pr->pVnode->pTsdb, pr->pReadSnap, "cache-l"); + resetLastBlockLoadInfo(pr->pLoadInfo); for (int32_t j = 0; j < pr->numOfCols; ++j) { taosMemoryFree(pRes[j]); diff --git a/source/dnode/vnode/src/tsdb/tsdbDiskData.c b/source/dnode/vnode/src/tsdb/tsdbDiskData.c index 43be51a6946be11f057b9e8a0c052d1411321b58..9f59707ddc469a3aff34a0f8817393773a63de11 100644 --- a/source/dnode/vnode/src/tsdb/tsdbDiskData.c +++ b/source/dnode/vnode/src/tsdb/tsdbDiskData.c @@ -427,13 +427,13 @@ static int32_t (*tDiskColAddValImpl[8][3])(SDiskColBuilder *pBuilder, SColVal *p {tDiskColAddVal60, tDiskColAddVal61, tDiskColAddVal62}, // HAS_VALUE|HAS_NULL {tDiskColAddVal70, tDiskColAddVal71, tDiskColAddVal72} // HAS_VALUE|HAS_NULL|HAS_NONE }; -extern void (*tSmaUpdateImpl[])(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, uint8_t *maxSet); +// extern void (*tSmaUpdateImpl[])(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, uint8_t *maxSet); static int32_t tDiskColAddVal(SDiskColBuilder *pBuilder, SColVal *pColVal) { int32_t code = 0; if (pBuilder->calcSma) { if (COL_VAL_IS_VALUE(pColVal)) { - tSmaUpdateImpl[pBuilder->type](&pBuilder->sma, pColVal, &pBuilder->minSet, &pBuilder->maxSet); + // tSmaUpdateImpl[pBuilder->type](&pBuilder->sma, pColVal, &pBuilder->minSet, &pBuilder->maxSet); } else { pBuilder->sma.numOfNull++; } diff --git a/source/dnode/vnode/src/tsdb/tsdbMemTable.c b/source/dnode/vnode/src/tsdb/tsdbMemTable.c index 0189ced3c6819f8b4d11adf63bf977579f5efc56..52c7a07c4943e41a89b3b2f8da6a418f15a150a5 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMemTable.c +++ b/source/dnode/vnode/src/tsdb/tsdbMemTable.c @@ -116,6 +116,13 @@ int32_t tsdbInsertTableData(STsdb *pTsdb, int64_t version, SSubmitMsgIter *pMsgI if (info.suid) { metaGetInfo(pTsdb->pVnode->pMeta, info.suid, &info); } + if (pMsgIter->sversion != info.skmVer) { + tsdbError("vgId:%d, req sver:%d, skmVer:%d suid:%" PRId64 " uid:%" PRId64, TD_VID(pTsdb->pVnode), + pMsgIter->sversion, info.skmVer, suid, uid); + code = TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER; + goto _err; + } + pRsp->sver = info.skmVer; // create/get STbData to op @@ -133,6 +140,7 @@ int32_t tsdbInsertTableData(STsdb *pTsdb, int64_t version, SSubmitMsgIter *pMsgI return code; _err: + terrno = code; return code; } @@ -190,14 +198,14 @@ int32_t tsdbDeleteTableData(STsdb *pTsdb, int64_t version, tb_uid_t suid, tb_uid } tsdbInfo("vgId:%d, delete data from table suid:%" PRId64 " uid:%" PRId64 " skey:%" PRId64 " eKey:%" PRId64 - " since %s", - TD_VID(pTsdb->pVnode), suid, uid, sKey, eKey, tstrerror(code)); + " at version %" PRId64 " since %s", + TD_VID(pTsdb->pVnode), suid, uid, sKey, eKey, version, tstrerror(code)); return code; _err: tsdbError("vgId:%d, failed to delete data from table suid:%" PRId64 " uid:%" PRId64 " skey:%" PRId64 " eKey:%" PRId64 - " since %s", - TD_VID(pTsdb->pVnode), suid, uid, sKey, eKey, tstrerror(code)); + " at version %" PRId64 " since %s", + TD_VID(pTsdb->pVnode), suid, uid, sKey, eKey, version, tstrerror(code)); return code; } @@ -286,31 +294,6 @@ bool tsdbTbDataIterNext(STbDataIter *pIter) { return true; } -TSDBROW *tsdbTbDataIterGet(STbDataIter *pIter) { - // we add here for commit usage - if (pIter == NULL) return NULL; - - if (pIter->pRow) { - goto _exit; - } - - if (pIter->backward) { - if (pIter->pNode == pIter->pTbData->sl.pHead) { - goto _exit; - } - } else { - if (pIter->pNode == pIter->pTbData->sl.pTail) { - goto _exit; - } - } - - tGetTSDBRow((uint8_t *)SL_NODE_DATA(pIter->pNode), &pIter->row); - pIter->pRow = &pIter->row; - -_exit: - return pIter->pRow; -} - static int32_t tsdbMemTableRehash(SMemTable *pMemTable) { int32_t code = 0; diff --git a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c index 6c67c11220a60185cdef78192ee4e36b2adfc194..01fbcf657fad18776286e288368821c3924df1d3 100644 --- a/source/dnode/vnode/src/tsdb/tsdbMergeTree.c +++ b/source/dnode/vnode/src/tsdb/tsdbMergeTree.c @@ -72,6 +72,7 @@ void resetLastBlockLoadInfo(SSttBlockLoadInfo *pLoadInfo) { pLoadInfo[i].elapsedTime = 0; pLoadInfo[i].loadBlocks = 0; + pLoadInfo[i].sttBlockLoaded = false; } } @@ -278,9 +279,9 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t (*pIter)->pBlockLoadInfo = pBlockLoadInfo; - size_t size = taosArrayGetSize(pBlockLoadInfo->aSttBlk); - if (size == 0) { + if (!pBlockLoadInfo->sttBlockLoaded) { int64_t st = taosGetTimestampUs(); + pBlockLoadInfo->sttBlockLoaded = true; code = tsdbReadSttBlk(pReader, iStt, pBlockLoadInfo->aSttBlk); if (code) { @@ -288,18 +289,18 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t } // only apply to the child tables, ordinary tables will not incur this filter procedure. - size = taosArrayGetSize(pBlockLoadInfo->aSttBlk); + size_t size = taosArrayGetSize(pBlockLoadInfo->aSttBlk); - if (size > 1) { + if (size >= 1) { SSttBlk *pStart = taosArrayGet(pBlockLoadInfo->aSttBlk, 0); SSttBlk *pEnd = taosArrayGet(pBlockLoadInfo->aSttBlk, size - 1); // all identical if (pStart->suid == pEnd->suid) { - if (pStart->suid == suid) { - // do nothing - } else if (pStart->suid != suid) { + if (pStart->suid != suid) { // no qualified stt block existed + taosArrayClear(pBlockLoadInfo->aSttBlk); + (*pIter)->iSttBlk = -1; double el = (taosGetTimestampUs() - st) / 1000.0; tsdbDebug("load the last file info completed, elapsed time:%.2fms, %s", el, idStr); @@ -330,7 +331,7 @@ int32_t tLDataIterOpen(struct SLDataIter **pIter, SDataFReader *pReader, int32_t tsdbDebug("load the last file info completed, elapsed time:%.2fms, %s", el, idStr); } - size = taosArrayGetSize(pBlockLoadInfo->aSttBlk); + size_t size = taosArrayGetSize(pBlockLoadInfo->aSttBlk); // find the start block (*pIter)->iSttBlk = binarySearchForStartBlock(pBlockLoadInfo->aSttBlk->pData, size, uid, backward); diff --git a/source/dnode/vnode/src/tsdb/tsdbOpen.c b/source/dnode/vnode/src/tsdb/tsdbOpen.c index efc74b68ba31db362441002589998d6ed04cfde9..bb20a9b0121e6ca1d99cf996fed1d1c7bc3c0245 100644 --- a/source/dnode/vnode/src/tsdb/tsdbOpen.c +++ b/source/dnode/vnode/src/tsdb/tsdbOpen.c @@ -48,7 +48,7 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb, const char *dir, STsdbKeepCfg *pKee } pTsdb->path = (char *)&pTsdb[1]; - sprintf(pTsdb->path, "%s%s%s", pVnode->path, TD_DIRSEP, dir); + snprintf(pTsdb->path, TD_PATH_MAX, "%s%s%s", pVnode->path, TD_DIRSEP, dir); taosRealPath(pTsdb->path, NULL, slen); pTsdb->pVnode = pVnode; taosThreadRwlockInit(&pTsdb->rwLock, NULL); diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index f83755fc4f63355129ca4e9a73c2ddfe5a5f5161..c157faecb14f71a5d5fb872989090d2c0ad6a5e5 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -35,11 +35,17 @@ typedef struct { int32_t numOfLastFiles; } SBlockNumber; +typedef struct SBlockIndex { + int32_t ordinalIndex; + int64_t inFileOffset; + STimeWindow window; +} SBlockIndex; + typedef struct STableBlockScanInfo { uint64_t uid; TSKEY lastKey; SMapData mapData; // block info (compressed) - SArray* pBlockList; // block data index list + SArray* pBlockList; // block data index list, SArray SIterInfo iter; // mem buffer skip list iterator SIterInfo iiter; // imem buffer skip list iterator SArray* delSkyline; // delete info for this table @@ -72,6 +78,7 @@ typedef struct SIOCostSummary { double lastBlockLoadTime; int64_t composedBlocks; double buildComposedBlockTime; + double createScanInfoList; } SIOCostSummary; typedef struct SBlockLoadSuppInfo { @@ -111,7 +118,7 @@ typedef struct SDataBlockIter { int32_t index; SArray* blockList; // SArray int32_t order; - SDataBlk block; // current SDataBlk data + SDataBlk block; // current SDataBlk data SHashObj* pTableMap; } SDataBlockIter; @@ -128,18 +135,24 @@ typedef struct SUidOrderCheckInfo { } SUidOrderCheckInfo; typedef struct SReaderStatus { - bool loadFromFile; // check file stage - bool composedDataBlock; // the returned data block is a composed block or not - SHashObj* pTableMap; // SHash - STableBlockScanInfo* pTableIter; // table iterator used in building in-memory buffer data blocks. - SUidOrderCheckInfo uidCheckInfo; // check all table in uid order - SFileBlockDumpInfo fBlockDumpInfo; - SDFileSet* pCurrentFileset; // current opened file set - SBlockData fileBlockData; - SFilesetIter fileIter; - SDataBlockIter blockIter; + bool loadFromFile; // check file stage + bool composedDataBlock; // the returned data block is a composed block or not + SHashObj* pTableMap; // SHash + STableBlockScanInfo** pTableIter; // table iterator used in building in-memory buffer data blocks. + SUidOrderCheckInfo uidCheckInfo; // check all table in uid order + SFileBlockDumpInfo fBlockDumpInfo; + SDFileSet* pCurrentFileset; // current opened file set + SBlockData fileBlockData; + SFilesetIter fileIter; + SDataBlockIter blockIter; } SReaderStatus; +typedef struct SBlockInfoBuf { + int32_t currentIndex; + SArray* pData; + int32_t numPerBucket; +} SBlockInfoBuf; + struct STsdbReader { STsdb* pTsdb; uint64_t suid; @@ -157,9 +170,9 @@ struct STsdbReader { STSchema* pMemSchema; // the previous schema for in-memory data, to avoid load schema too many times SDataFReader* pFileReader; SVersionRange verRange; - - int32_t step; - STsdbReader* innerReader[2]; + SBlockInfoBuf blockInfoBuf; + int32_t step; + STsdbReader* innerReader[2]; }; static SFileDataBlockInfo* getCurrentBlockInfo(SDataBlockIter* pBlockIter); @@ -169,14 +182,16 @@ static TSDBROW* getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdbRe static int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pScanInfo, STsdbReader* pReader, SRowMerger* pMerger); static int32_t doMergeRowsInLastBlock(SLastBlockReader* pLastBlockReader, STableBlockScanInfo* pScanInfo, int64_t ts, - SRowMerger* pMerger); + SRowMerger* pMerger, SVersionRange* pVerRange); static int32_t doMergeRowsInBuf(SIterInfo* pIter, uint64_t uid, int64_t ts, SArray* pDelList, SRowMerger* pMerger, STsdbReader* pReader); -static int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, STSRow* pTSRow, uint64_t uid); +static int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, STSRow* pTSRow, + STableBlockScanInfo* pInfo); static int32_t doAppendRowFromFileBlock(SSDataBlock* pResBlock, STsdbReader* pReader, SBlockData* pBlockData, int32_t rowIndex); static void setComposedBlockFlag(STsdbReader* pReader, bool composed); -static bool hasBeenDropped(const SArray* pDelList, int32_t* index, TSDBKEY* pKey, int32_t order); +static bool hasBeenDropped(const SArray* pDelList, int32_t* index, TSDBKEY* pKey, int32_t order, + SVersionRange* pVerRange); static int32_t doMergeMemTableMultiRows(TSDBROW* pRow, uint64_t uid, SIterInfo* pIter, SArray* pDelList, STSRow** pTSRow, STsdbReader* pReader, bool* freeTSRow); @@ -195,7 +210,6 @@ static bool hasDataInLastBlock(SLastBlockReader* pLastBlockReader); static int32_t doBuildDataBlock(STsdbReader* pReader); static TSDBKEY getCurrentKeyInBuf(STableBlockScanInfo* pScanInfo, STsdbReader* pReader); static bool hasDataInFileBlock(const SBlockData* pBlockData, const SFileBlockDumpInfo* pDumpInfo); -static bool hasDataInLastBlock(SLastBlockReader* pLastBlockReader); static bool outOfTimeWindow(int64_t ts, STimeWindow* pWindow) { return (ts > pWindow->ekey) || (ts < pWindow->skey); } @@ -225,6 +239,50 @@ static int32_t setColumnIdSlotList(STsdbReader* pReader, SSDataBlock* pBlock) { return TSDB_CODE_SUCCESS; } +static int32_t initBlockScanInfoBuf(SBlockInfoBuf* pBuf, int32_t numOfTables) { + int32_t num = numOfTables / pBuf->numPerBucket; + int32_t remainder = numOfTables % pBuf->numPerBucket; + if (pBuf->pData == NULL) { + pBuf->pData = taosArrayInit(num + 1, POINTER_BYTES); + } + + for (int32_t i = 0; i < num; ++i) { + char* p = taosMemoryCalloc(pBuf->numPerBucket, sizeof(STableBlockScanInfo)); + if (p == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + taosArrayPush(pBuf->pData, &p); + } + + if (remainder > 0) { + char* p = taosMemoryCalloc(remainder, sizeof(STableBlockScanInfo)); + if (p == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + taosArrayPush(pBuf->pData, &p); + } + + return TSDB_CODE_SUCCESS; +} + +static void clearBlockScanInfoBuf(SBlockInfoBuf* pBuf) { + size_t num = taosArrayGetSize(pBuf->pData); + for (int32_t i = 0; i < num; ++i) { + char** p = taosArrayGet(pBuf->pData, i); + taosMemoryFree(*p); + } + + taosArrayDestroy(pBuf->pData); +} + +static void* getPosInBlockInfoBuf(SBlockInfoBuf* pBuf, int32_t index) { + int32_t bucketIndex = index / pBuf->numPerBucket; + char** pBucket = taosArrayGet(pBuf->pData, bucketIndex); + return (*pBucket) + (index % pBuf->numPerBucket) * sizeof(STableBlockScanInfo); +} + +// NOTE: speedup the whole processing by preparing the buffer for STableBlockScanInfo in batch model static SHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, const STableKeyInfo* idList, int32_t numOfTables) { // allocate buffer in order to load data blocks from file // todo use simple hash instead, optimize the memory consumption @@ -234,8 +292,24 @@ static SHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, const STableK return NULL; } + int64_t st = taosGetTimestampUs(); + initBlockScanInfoBuf(&pTsdbReader->blockInfoBuf, numOfTables); + for (int32_t j = 0; j < numOfTables; ++j) { - STableBlockScanInfo info = {.lastKey = 0, .uid = idList[j].uid}; + STableBlockScanInfo* pScanInfo = getPosInBlockInfoBuf(&pTsdbReader->blockInfoBuf, j); + pScanInfo->uid = idList[j].uid; + if (ASCENDING_TRAVERSE(pTsdbReader->order)) { + int64_t skey = pTsdbReader->window.skey; + pScanInfo->lastKey = (skey > INT64_MIN) ? (skey - 1) : skey; + } else { + int64_t ekey = pTsdbReader->window.ekey; + pScanInfo->lastKey = (ekey < INT64_MAX) ? (ekey + 1) : ekey; + } + + taosHashPut(pTableMap, &pScanInfo->uid, sizeof(uint64_t), &pScanInfo, POINTER_BYTES); + +#if 0 +// STableBlockScanInfo info = {.lastKey = 0, .uid = idList[j].uid}; if (ASCENDING_TRAVERSE(pTsdbReader->order)) { int64_t skey = pTsdbReader->window.skey; info.lastKey = (skey > INT64_MIN) ? (skey - 1) : skey; @@ -245,49 +319,57 @@ static SHashObj* createDataBlockScanInfo(STsdbReader* pTsdbReader, const STableK } taosHashPut(pTableMap, &info.uid, sizeof(uint64_t), &info, sizeof(info)); - tsdbDebug("%p check table uid:%" PRId64 " from lastKey:%" PRId64 " %s", pTsdbReader, info.uid, info.lastKey, - pTsdbReader->idStr); +#endif + + tsdbTrace("%p check table uid:%" PRId64 " from lastKey:%" PRId64 " %s", pTsdbReader, pScanInfo->uid, + pScanInfo->lastKey, pTsdbReader->idStr); } - tsdbDebug("%p create %d tables scan-info, size:%.2f Kb, %s", pTsdbReader, numOfTables, - (sizeof(STableBlockScanInfo) * numOfTables) / 1024.0, pTsdbReader->idStr); + pTsdbReader->cost.createScanInfoList = (taosGetTimestampUs() - st) / 1000.0; + tsdbDebug("%p create %d tables scan-info, size:%.2f Kb, elapsed time:%.2f ms, %s", pTsdbReader, numOfTables, + (sizeof(STableBlockScanInfo) * numOfTables) / 1024.0, pTsdbReader->cost.createScanInfoList, + pTsdbReader->idStr); return pTableMap; } -static void resetDataBlockScanInfo(SHashObj* pTableMap, int64_t ts) { - STableBlockScanInfo* p = NULL; - +static void resetAllDataBlockScanInfo(SHashObj* pTableMap, int64_t ts) { + STableBlockScanInfo** p = NULL; while ((p = taosHashIterate(pTableMap, p)) != NULL) { - p->iterInit = false; - p->iiter.hasVal = false; - if (p->iter.iter != NULL) { - p->iter.iter = tsdbTbDataIterDestroy(p->iter.iter); + STableBlockScanInfo* pInfo = *(STableBlockScanInfo**)p; + + pInfo->iterInit = false; + pInfo->iiter.hasVal = false; + if (pInfo->iter.iter != NULL) { + pInfo->iter.iter = tsdbTbDataIterDestroy(pInfo->iter.iter); } - p->delSkyline = taosArrayDestroy(p->delSkyline); - p->lastKey = ts; + pInfo->delSkyline = taosArrayDestroy(pInfo->delSkyline); + pInfo->lastKey = ts; } } -static void destroyBlockScanInfo(SHashObj* pTableMap) { - STableBlockScanInfo* p = NULL; +static void clearBlockScanInfo(STableBlockScanInfo* p) { + p->iterInit = false; + p->iiter.hasVal = false; - while ((p = taosHashIterate(pTableMap, p)) != NULL) { - p->iterInit = false; - p->iiter.hasVal = false; + if (p->iter.iter != NULL) { + p->iter.iter = tsdbTbDataIterDestroy(p->iter.iter); + } - if (p->iter.iter != NULL) { - p->iter.iter = tsdbTbDataIterDestroy(p->iter.iter); - } + if (p->iiter.iter != NULL) { + p->iiter.iter = tsdbTbDataIterDestroy(p->iiter.iter); + } - if (p->iiter.iter != NULL) { - p->iiter.iter = tsdbTbDataIterDestroy(p->iiter.iter); - } + p->delSkyline = taosArrayDestroy(p->delSkyline); + p->pBlockList = taosArrayDestroy(p->pBlockList); + tMapDataClear(&p->mapData); +} - p->delSkyline = taosArrayDestroy(p->delSkyline); - p->pBlockList = taosArrayDestroy(p->pBlockList); - tMapDataClear(&p->mapData); +static void destroyAllBlockScanInfo(SHashObj* pTableMap, bool clearEntry) { + void* p = NULL; + while (clearEntry && ((p = taosHashIterate(pTableMap, p)) != NULL)) { + clearBlockScanInfo(*(STableBlockScanInfo**)p); } taosHashCleanup(pTableMap); @@ -453,7 +535,7 @@ static SSDataBlock* createResBlock(SQueryTableDataCond* pCond, int32_t capacity) } for (int32_t i = 0; i < pCond->numOfCols; ++i) { - SColumnInfoData colInfo = {{0}, 0}; + SColumnInfoData colInfo = {0, {0}}; colInfo.info = pCond->colList[i]; blockDataAppendColInfo(pResBlock, &colInfo); } @@ -464,7 +546,6 @@ static SSDataBlock* createResBlock(SQueryTableDataCond* pCond, int32_t capacity) taosMemoryFree(pResBlock); return NULL; } - return pResBlock; } @@ -492,7 +573,7 @@ static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, STsd pReader->verRange = getQueryVerRange(pVnode, pCond, level); pReader->type = pCond->type; pReader->window = updateQueryTimeWindow(pReader->pTsdb, &pCond->twindows); - + pReader->blockInfoBuf.numPerBucket = 1000; // 1000 tables per bucket ASSERT(pCond->numOfCols > 0); limitOutputBufferSize(pCond, &pReader->capacity); @@ -563,9 +644,9 @@ static int32_t doLoadBlockIndex(STsdbReader* pReader, SDataFReader* pFileReader, continue; } - STableBlockScanInfo* pScanInfo = p; + STableBlockScanInfo* pScanInfo = *(STableBlockScanInfo**)p; if (pScanInfo->pBlockList == NULL) { - pScanInfo->pBlockList = taosArrayInit(4, sizeof(int32_t)); + pScanInfo->pBlockList = taosArrayInit(4, sizeof(SBlockIndex)); } taosArrayPush(pIndexList, pBlockIdx); @@ -583,7 +664,7 @@ _end: } static void cleanupTableScanInfo(SHashObj* pTableMap) { - STableBlockScanInfo* px = NULL; + STableBlockScanInfo** px = NULL; while (1) { px = taosHashIterate(pTableMap, px); if (px == NULL) { @@ -591,8 +672,8 @@ static void cleanupTableScanInfo(SHashObj* pTableMap) { } // reset the index in last block when handing a new file - tMapDataClear(&px->mapData); - taosArrayClear(px->pBlockList); + tMapDataClear(&(*px)->mapData); + taosArrayClear((*px)->pBlockList); } } @@ -607,7 +688,8 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN for (int32_t i = 0; i < numOfTables; ++i) { SBlockIdx* pBlockIdx = taosArrayGet(pIndexList, i); - STableBlockScanInfo* pScanInfo = taosHashGet(pReader->status.pTableMap, &pBlockIdx->uid, sizeof(int64_t)); + STableBlockScanInfo* pScanInfo = + *(STableBlockScanInfo**)taosHashGet(pReader->status.pTableMap, &pBlockIdx->uid, sizeof(int64_t)); tMapDataReset(&pScanInfo->mapData); tsdbReadDataBlk(pReader->pFileReader, pBlockIdx, &pScanInfo->mapData); @@ -627,7 +709,10 @@ static int32_t doLoadFileBlock(STsdbReader* pReader, SArray* pIndexList, SBlockN continue; } - void* p = taosArrayPush(pScanInfo->pBlockList, &j); + SBlockIndex bIndex = {.ordinalIndex = j, .inFileOffset = block.aSubBlock->offset}; + bIndex.window = (STimeWindow){.skey = block.minKey.ts, .ekey = block.maxKey.ts}; + + void* p = taosArrayPush(pScanInfo->pBlockList, &bIndex); if (p == NULL) { tMapDataClear(&pScanInfo->mapData); return TSDB_CODE_OUT_OF_MEMORY; @@ -808,7 +893,7 @@ static int doBinarySearchKey(TSKEY* keyList, int num, int pos, TSKEY key, int or } } -int32_t getEndPosInDataBlock(STsdbReader* pReader, SBlockData* pBlockData, SDataBlk* pBlock, int32_t pos) { +static int32_t getEndPosInDataBlock(STsdbReader* pReader, SBlockData* pBlockData, SDataBlk* pBlock, int32_t pos) { // NOTE: reverse the order to find the end position in data block int32_t endPos = -1; bool asc = ASCENDING_TRAVERSE(pReader->order); @@ -818,12 +903,124 @@ int32_t getEndPosInDataBlock(STsdbReader* pReader, SBlockData* pBlockData, SData } else if (!asc && pReader->window.skey <= pBlock->minKey.ts) { endPos = 0; } else { - endPos = doBinarySearchKey(pBlockData->aTSKEY, pBlock->nRow, pos, pReader->window.ekey, pReader->order); + int64_t key = asc ? pReader->window.ekey : pReader->window.skey; + endPos = doBinarySearchKey(pBlockData->aTSKEY, pBlock->nRow, pos, key, pReader->order); } return endPos; } +static void copyPrimaryTsCol(const SBlockData* pBlockData, SFileBlockDumpInfo* pDumpInfo, SColumnInfoData* pColData, + int32_t dumpedRows, bool asc) { + if (asc) { + memcpy(pColData->pData, &pBlockData->aTSKEY[pDumpInfo->rowIndex], dumpedRows * sizeof(int64_t)); + } else { + int32_t startIndex = pDumpInfo->rowIndex - dumpedRows + 1; + memcpy(pColData->pData, &pBlockData->aTSKEY[startIndex], dumpedRows * sizeof(int64_t)); + + // todo: opt perf by extract the loop + // reverse the array list + int32_t mid = dumpedRows >> 1u; + int64_t* pts = (int64_t*)pColData->pData; + for (int32_t j = 0; j < mid; ++j) { + int64_t t = pts[j]; + pts[j] = pts[dumpedRows - j - 1]; + pts[dumpedRows - j - 1] = t; + } + } +} + +// a faster version of copy procedure. +static void copyNumericCols(const SColData* pData, SFileBlockDumpInfo* pDumpInfo, SColumnInfoData* pColData, + int32_t dumpedRows, bool asc) { + uint8_t* p = NULL; + if (asc) { + p = pData->pData + tDataTypes[pData->type].bytes * pDumpInfo->rowIndex; + } else { + int32_t startIndex = pDumpInfo->rowIndex - dumpedRows + 1; + p = pData->pData + tDataTypes[pData->type].bytes * startIndex; + } + + int32_t step = asc? 1:-1; + + // make sure it is aligned to 8bit + ASSERT((((uint64_t)pColData->pData) & (0x8 - 1)) == 0); + + // 1. copy data in a batch model + memcpy(pColData->pData, p, dumpedRows * tDataTypes[pData->type].bytes); + + // 2. reverse the array list in case of descending order scan data block + if (!asc) { + switch(pColData->info.type) { + case TSDB_DATA_TYPE_TIMESTAMP: + case TSDB_DATA_TYPE_DOUBLE: + case TSDB_DATA_TYPE_BIGINT: + case TSDB_DATA_TYPE_UBIGINT: + { + int32_t mid = dumpedRows >> 1u; + int64_t* pts = (int64_t*)pColData->pData; + for (int32_t j = 0; j < mid; ++j) { + int64_t t = pts[j]; + pts[j] = pts[dumpedRows - j - 1]; + pts[dumpedRows - j - 1] = t; + } + break; + } + + case TSDB_DATA_TYPE_BOOL: + case TSDB_DATA_TYPE_TINYINT: + case TSDB_DATA_TYPE_UTINYINT: { + int32_t mid = dumpedRows >> 1u; + int8_t* pts = (int8_t*)pColData->pData; + for (int32_t j = 0; j < mid; ++j) { + int8_t t = pts[j]; + pts[j] = pts[dumpedRows - j - 1]; + pts[dumpedRows - j - 1] = t; + } + break; + } + + case TSDB_DATA_TYPE_SMALLINT: + case TSDB_DATA_TYPE_USMALLINT: { + int32_t mid = dumpedRows >> 1u; + int16_t* pts = (int16_t*)pColData->pData; + for (int32_t j = 0; j < mid; ++j) { + int64_t t = pts[j]; + pts[j] = pts[dumpedRows - j - 1]; + pts[dumpedRows - j - 1] = t; + } + break; + } + + case TSDB_DATA_TYPE_FLOAT: + case TSDB_DATA_TYPE_INT: + case TSDB_DATA_TYPE_UINT: { + int32_t mid = dumpedRows >> 1u; + int32_t* pts = (int32_t*)pColData->pData; + for (int32_t j = 0; j < mid; ++j) { + int32_t t = pts[j]; + pts[j] = pts[dumpedRows - j - 1]; + pts[dumpedRows - j - 1] = t; + } + break; + } + } + } + + // 3. if the null value exists, check items one-by-one + if (pData->flag != HAS_VALUE) { + int32_t rowIndex = 0; + + for (int32_t j = pDumpInfo->rowIndex; rowIndex < dumpedRows; j += step, rowIndex++) { + uint8_t v = tColDataGetBitValue(pData, j); + if (v == 0 || v == 1) { + colDataSetNull_f(pColData->nullbitmap, rowIndex); + pColData->hasNull = true; + } + } + } +} + static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, STableBlockScanInfo* pBlockScanInfo) { SReaderStatus* pStatus = &pReader->status; SDataBlockIter* pBlockIter = &pStatus->blockIter; @@ -849,8 +1046,9 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, STableBlockScanIn // pDumpInfo->rowIndex = pBlock->nRow - 1; } else { int32_t pos = asc ? pBlock->nRow - 1 : 0; - int32_t order = (pReader->order == TSDB_ORDER_ASC) ? TSDB_ORDER_DESC : TSDB_ORDER_ASC; - pDumpInfo->rowIndex = doBinarySearchKey(pBlockData->aTSKEY, pBlock->nRow, pos, pReader->window.skey, order); + int32_t order = asc ? TSDB_ORDER_DESC : TSDB_ORDER_ASC; + int64_t key = asc ? pReader->window.skey : pReader->window.ekey; + pDumpInfo->rowIndex = doBinarySearchKey(pBlockData->aTSKEY, pBlock->nRow, pos, key, order); } } @@ -862,29 +1060,22 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, STableBlockScanIn } endIndex += step; - int32_t remain = asc ? (endIndex - pDumpInfo->rowIndex) : (pDumpInfo->rowIndex - endIndex); - if (remain > pReader->capacity) { // output buffer check - remain = pReader->capacity; + int32_t dumpedRows = asc ? (endIndex - pDumpInfo->rowIndex) : (pDumpInfo->rowIndex - endIndex); + if (dumpedRows > pReader->capacity) { // output buffer check + dumpedRows = pReader->capacity; } + int32_t i = 0; int32_t rowIndex = 0; - int32_t i = 0; SColumnInfoData* pColData = taosArrayGet(pResBlock->pDataBlock, i); if (pColData->info.colId == PRIMARYKEY_TIMESTAMP_COL_ID) { - if (asc) { - memcpy(pColData->pData, &pBlockData->aTSKEY[pDumpInfo->rowIndex], remain * sizeof(int64_t)); - } else { - for (int32_t j = pDumpInfo->rowIndex; rowIndex < remain; j += step) { - colDataAppendInt64(pColData, rowIndex++, &pBlockData->aTSKEY[j]); - } - } - + copyPrimaryTsCol(pBlockData, pDumpInfo, pColData, dumpedRows, asc); i += 1; } int32_t colIndex = 0; - int32_t num = taosArrayGetSize(pBlockData->aIdx); + int32_t num = pBlockData->nColData; while (i < numOfOutputCols && colIndex < num) { rowIndex = 0; pColData = taosArrayGet(pResBlock->pDataBlock, i); @@ -894,23 +1085,12 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, STableBlockScanIn colIndex += 1; } else if (pData->cid == pColData->info.colId) { if (pData->flag == HAS_NONE || pData->flag == HAS_NULL || pData->flag == (HAS_NULL | HAS_NONE)) { - colDataAppendNNULL(pColData, 0, remain); + colDataAppendNNULL(pColData, 0, dumpedRows); } else { - if (IS_NUMERIC_TYPE(pColData->info.type) && asc) { - uint8_t* p = pData->pData + tDataTypes[pData->type].bytes * pDumpInfo->rowIndex; - memcpy(pColData->pData, p, remain * tDataTypes[pData->type].bytes); - - // null value exists, check one-by-one - if (pData->flag != HAS_VALUE) { - for (int32_t j = pDumpInfo->rowIndex; rowIndex < remain; j += step, rowIndex++) { - uint8_t v = tColDataGetBitValue(pData, j); - if (v == 0 || v == 1) { - colDataSetNull_f(pColData->nullbitmap, rowIndex); - } - } - } - } else { - for (int32_t j = pDumpInfo->rowIndex; rowIndex < remain; j += step) { + if (IS_MATHABLE_TYPE(pColData->info.type)) { + copyNumericCols(pData, pDumpInfo, pColData, dumpedRows, asc); + } else { // varchar/nchar type + for (int32_t j = pDumpInfo->rowIndex; rowIndex < dumpedRows; j += step) { tColDataGetValue(pData, j, &cv); doCopyColVal(pColData, rowIndex++, i, &cv, pSupInfo); } @@ -920,7 +1100,7 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, STableBlockScanIn colIndex += 1; i += 1; } else { // the specified column does not exist in file block, fill with null data - colDataAppendNNULL(pColData, 0, remain); + colDataAppendNNULL(pColData, 0, dumpedRows); i += 1; } } @@ -928,12 +1108,12 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, STableBlockScanIn // fill the mis-matched columns with null value while (i < numOfOutputCols) { pColData = taosArrayGet(pResBlock->pDataBlock, i); - colDataAppendNNULL(pColData, 0, remain); + colDataAppendNNULL(pColData, 0, dumpedRows); i += 1; } - pResBlock->info.rows = remain; - pDumpInfo->rowIndex += step * remain; + pResBlock->info.rows = dumpedRows; + pDumpInfo->rowIndex += step * dumpedRows; // check if current block are all handled if (pDumpInfo->rowIndex >= 0 && pDumpInfo->rowIndex < pBlock->nRow) { @@ -952,7 +1132,7 @@ static int32_t copyBlockDataToSDataBlock(STsdbReader* pReader, STableBlockScanIn int32_t unDumpedRows = asc ? pBlock->nRow - pDumpInfo->rowIndex : pDumpInfo->rowIndex + 1; tsdbDebug("%p copy file block to sdatablock, global index:%d, table index:%d, brange:%" PRId64 "-%" PRId64 ", rows:%d, remain:%d, minVer:%" PRId64 ", maxVer:%" PRId64 ", elapsed time:%.2f ms, %s", - pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, pBlock->minKey.ts, pBlock->maxKey.ts, remain, + pReader, pBlockIter->index, pBlockInfo->tbBlockIdx, pBlock->minKey.ts, pBlock->maxKey.ts, dumpedRows, unDumpedRows, pBlock->minVer, pBlock->maxVer, elapsedTime, pReader->idStr); return TSDB_CODE_SUCCESS; @@ -1050,14 +1230,14 @@ static int32_t fileDataBlockOrderCompar(const void* pLeft, const void* pRight, v static int32_t doSetCurrentBlock(SDataBlockIter* pBlockIter, const char* idStr) { SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(pBlockIter); if (pBlockInfo != NULL) { - STableBlockScanInfo* pScanInfo = taosHashGet(pBlockIter->pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid)); + STableBlockScanInfo** pScanInfo = taosHashGet(pBlockIter->pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid)); if (pScanInfo == NULL) { - tsdbError("failed to locate the uid:%"PRIu64" in query table uid list, %s", pBlockInfo->uid, idStr); + tsdbError("failed to locate the uid:%" PRIu64 " in query table uid list, %s", pBlockInfo->uid, idStr); return TSDB_CODE_INVALID_PARA; } - int32_t* mapDataIndex = taosArrayGet(pScanInfo->pBlockList, pBlockInfo->tbBlockIdx); - tMapDataGetItemByIdx(&pScanInfo->mapData, *mapDataIndex, &pBlockIter->block, tGetDataBlk); + SBlockIndex* pIndex = taosArrayGet((*pScanInfo)->pBlockList, pBlockInfo->tbBlockIdx); + tMapDataGetItemByIdx(&(*pScanInfo)->mapData, pIndex->ordinalIndex, &pBlockIter->block, tGetDataBlk); } #if 0 @@ -1070,6 +1250,7 @@ static int32_t doSetCurrentBlock(SDataBlockIter* pBlockIter, const char* idStr) static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIter, int32_t numOfBlocks) { bool asc = ASCENDING_TRAVERSE(pReader->order); + SBlockOrderSupporter sup = {0}; pBlockIter->numOfBlocks = numOfBlocks; taosArrayClear(pBlockIter->blockList); pBlockIter->pTableMap = pReader->status.pTableMap; @@ -1078,9 +1259,7 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte int32_t numOfTables = (int32_t)taosHashGetSize(pReader->status.pTableMap); int64_t st = taosGetTimestampUs(); - - SBlockOrderSupporter sup = {0}; - int32_t code = initBlockOrderSupporter(&sup, numOfTables); + int32_t code = initBlockOrderSupporter(&sup, numOfTables); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -1093,7 +1272,7 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte break; } - STableBlockScanInfo* pTableScanInfo = (STableBlockScanInfo*)ptr; + STableBlockScanInfo* pTableScanInfo = *(STableBlockScanInfo**)ptr; if (pTableScanInfo->pBlockList == NULL || taosArrayGetSize(pTableScanInfo->pBlockList) == 0) { continue; } @@ -1108,17 +1287,11 @@ static int32_t initBlockIterator(STsdbReader* pReader, SDataBlockIter* pBlockIte } sup.pDataBlockInfo[sup.numOfTables] = (SBlockOrderWrapper*)buf; - SDataBlk block = {0}; - for (int32_t k = 0; k < num; ++k) { - SBlockOrderWrapper wrapper = {0}; - - int32_t* mapDataIndex = taosArrayGet(pTableScanInfo->pBlockList, k); - tMapDataGetItemByIdx(&pTableScanInfo->mapData, *mapDataIndex, &block, tGetDataBlk); - wrapper.uid = pTableScanInfo->uid; - wrapper.offset = block.aSubBlock[0].offset; - - sup.pDataBlockInfo[sup.numOfTables][k] = wrapper; + for (int32_t k = 0; k < num; ++k) { + SBlockIndex* pIndex = taosArrayGet(pTableScanInfo->pBlockList, k); + sup.pDataBlockInfo[sup.numOfTables][k] = + (SBlockOrderWrapper){.uid = pTableScanInfo->uid, .offset = pIndex->inFileOffset}; cnt++; } @@ -1209,25 +1382,22 @@ static int32_t dataBlockPartiallyRequired(STimeWindow* pWindow, SVersionRange* p (pVerRange->maxVer < pBlock->maxVer && pVerRange->maxVer >= pBlock->minVer); } -static SDataBlk* getNeighborBlockOfSameTable(SFileDataBlockInfo* pBlockInfo, STableBlockScanInfo* pTableBlockScanInfo, - int32_t* nextIndex, int32_t order) { +static bool getNeighborBlockOfSameTable(SFileDataBlockInfo* pBlockInfo, STableBlockScanInfo* pTableBlockScanInfo, + int32_t* nextIndex, int32_t order, SBlockIndex* pBlockIndex) { bool asc = ASCENDING_TRAVERSE(order); if (asc && pBlockInfo->tbBlockIdx >= taosArrayGetSize(pTableBlockScanInfo->pBlockList) - 1) { - return NULL; + return false; } if (!asc && pBlockInfo->tbBlockIdx == 0) { - return NULL; + return false; } int32_t step = asc ? 1 : -1; *nextIndex = pBlockInfo->tbBlockIdx + step; - - SDataBlk* pBlock = taosMemoryCalloc(1, sizeof(SDataBlk)); - int32_t* indexInMapdata = taosArrayGet(pTableBlockScanInfo->pBlockList, *nextIndex); - - tMapDataGetItemByIdx(&pTableBlockScanInfo->mapData, *indexInMapdata, pBlock, tGetDataBlk); - return pBlock; + *pBlockIndex = *(SBlockIndex*)taosArrayGet(pTableBlockScanInfo->pBlockList, *nextIndex); + // tMapDataGetItemByIdx(&pTableBlockScanInfo->mapData, pIndex->ordinalIndex, pBlock, tGetDataBlk); + return true; } static int32_t findFileBlockInfoIndex(SDataBlockIter* pBlockIter, SFileDataBlockInfo* pFBlockInfo) { @@ -1269,12 +1439,12 @@ static int32_t setFileBlockActiveInBlockIter(SDataBlockIter* pBlockIter, int32_t return TSDB_CODE_SUCCESS; } -static bool overlapWithNeighborBlock(SDataBlk* pBlock, SDataBlk* pNeighbor, int32_t order) { +static bool overlapWithNeighborBlock(SDataBlk* pBlock, SBlockIndex* pNeighborBlockIndex, int32_t order) { // it is the last block in current file, no chance to overlap with neighbor blocks. if (ASCENDING_TRAVERSE(order)) { - return pBlock->maxKey.ts == pNeighbor->minKey.ts; + return pBlock->maxKey.ts == pNeighborBlockIndex->window.skey; } else { - return pBlock->minKey.ts == pNeighbor->maxKey.ts; + return pBlock->minKey.ts == pNeighborBlockIndex->window.ekey; } } @@ -1290,10 +1460,11 @@ static bool keyOverlapFileBlock(TSDBKEY key, SDataBlk* pBlock, SVersionRange* pV (pBlock->minVer <= pVerRange->maxVer); } -static bool doCheckforDatablockOverlap(STableBlockScanInfo* pBlockScanInfo, const SDataBlk* pBlock) { +static bool doCheckforDatablockOverlap(STableBlockScanInfo* pBlockScanInfo, const SDataBlk* pBlock, + int32_t startIndex) { size_t num = taosArrayGetSize(pBlockScanInfo->delSkyline); - for (int32_t i = pBlockScanInfo->fileDelIndex; i < num; i += 1) { + for (int32_t i = startIndex; i < num; i += 1) { TSDBKEY* p = taosArrayGet(pBlockScanInfo->delSkyline, i); if (p->ts >= pBlock->minKey.ts && p->ts <= pBlock->maxKey.ts) { if (p->version >= pBlock->minVer) { @@ -1332,7 +1503,7 @@ static bool overlapWithDelSkyline(STableBlockScanInfo* pBlockScanInfo, const SDa // version is not overlap if (ASCENDING_TRAVERSE(order)) { - return doCheckforDatablockOverlap(pBlockScanInfo, pBlock); + return doCheckforDatablockOverlap(pBlockScanInfo, pBlock, pBlockScanInfo->fileDelIndex); } else { int32_t index = pBlockScanInfo->fileDelIndex; while (1) { @@ -1344,7 +1515,7 @@ static bool overlapWithDelSkyline(STableBlockScanInfo* pBlockScanInfo, const SDa } } - return doCheckforDatablockOverlap(pBlockScanInfo, pBlock); + return doCheckforDatablockOverlap(pBlockScanInfo, pBlock, index); } } @@ -1361,13 +1532,14 @@ typedef struct { static void getBlockToLoadInfo(SDataBlockToLoadInfo* pInfo, SFileDataBlockInfo* pBlockInfo, SDataBlk* pBlock, STableBlockScanInfo* pScanInfo, TSDBKEY keyInBuf, SLastBlockReader* pLastBlockReader, STsdbReader* pReader) { - int32_t neighborIndex = 0; - SDataBlk* pNeighbor = getNeighborBlockOfSameTable(pBlockInfo, pScanInfo, &neighborIndex, pReader->order); + int32_t neighborIndex = 0; + SBlockIndex bIndex = {0}; + + bool hasNeighbor = getNeighborBlockOfSameTable(pBlockInfo, pScanInfo, &neighborIndex, pReader->order, &bIndex); // overlap with neighbor - if (pNeighbor) { - pInfo->overlapWithNeighborBlock = overlapWithNeighborBlock(pBlock, pNeighbor, pReader->order); - taosMemoryFree(pNeighbor); + if (hasNeighbor) { + pInfo->overlapWithNeighborBlock = overlapWithNeighborBlock(pBlock, &bIndex, pReader->order); } // has duplicated ts of different version in this block @@ -1451,8 +1623,8 @@ static bool tryCopyDistinctRowFromFileBlock(STsdbReader* pReader, SBlockData* pB // opt version // 1. it is not a border point // 2. the direct next point is not an duplicated timestamp - if ((pDumpInfo->rowIndex < pDumpInfo->totalRows - 1 && pReader->order == TSDB_ORDER_ASC) || - (pDumpInfo->rowIndex > 0 && pReader->order == TSDB_ORDER_DESC)) { + bool asc = (pReader->order == TSDB_ORDER_ASC); + if ((pDumpInfo->rowIndex < pDumpInfo->totalRows - 1 && asc) || (pDumpInfo->rowIndex > 0 && (!asc))) { int32_t step = pReader->order == TSDB_ORDER_ASC ? 1 : -1; int64_t nextKey = pBlockData->aTSKEY[pDumpInfo->rowIndex + step]; @@ -1466,7 +1638,8 @@ static bool tryCopyDistinctRowFromFileBlock(STsdbReader* pReader, SBlockData* pB return false; } -static bool nextRowFromLastBlocks(SLastBlockReader* pLastBlockReader, STableBlockScanInfo* pBlockScanInfo) { +static bool nextRowFromLastBlocks(SLastBlockReader* pLastBlockReader, STableBlockScanInfo* pBlockScanInfo, + SVersionRange* pVerRange) { while (1) { bool hasVal = tMergeTreeNext(&pLastBlockReader->mergeTree); if (!hasVal) { @@ -1475,7 +1648,8 @@ static bool nextRowFromLastBlocks(SLastBlockReader* pLastBlockReader, STableBloc TSDBROW row = tMergeTreeGetRow(&pLastBlockReader->mergeTree); TSDBKEY k = TSDBROW_KEY(&row); - if (!hasBeenDropped(pBlockScanInfo->delSkyline, &pBlockScanInfo->lastBlockDelIndex, &k, pLastBlockReader->order)) { + if (!hasBeenDropped(pBlockScanInfo->delSkyline, &pBlockScanInfo->lastBlockDelIndex, &k, pLastBlockReader->order, + pVerRange)) { return true; } } @@ -1483,7 +1657,7 @@ static bool nextRowFromLastBlocks(SLastBlockReader* pLastBlockReader, STableBloc static bool tryCopyDistinctRowFromSttBlock(TSDBROW* fRow, SLastBlockReader* pLastBlockReader, STableBlockScanInfo* pScanInfo, int64_t ts, STsdbReader* pReader) { - bool hasVal = nextRowFromLastBlocks(pLastBlockReader, pScanInfo); + bool hasVal = nextRowFromLastBlocks(pLastBlockReader, pScanInfo, &pReader->verRange); if (hasVal) { int64_t next1 = getCurrentKeyInLastBlock(pLastBlockReader); if (next1 != ts) { @@ -1602,7 +1776,7 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo* return code; } } - doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLast, &merge); + doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLast, &merge, &pReader->verRange); } if (minKey == k.ts) { @@ -1647,7 +1821,7 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo* return code; } } - doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLast, &merge); + doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLast, &merge, &pReader->verRange); } if (minKey == key) { @@ -1669,7 +1843,7 @@ static int32_t doMergeBufAndFileRows(STsdbReader* pReader, STableBlockScanInfo* return code; } - doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo->uid); + doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo); taosMemoryFree(pTSRow); tRowMergerClear(&merge); @@ -1690,6 +1864,7 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader, // only last block exists if ((!mergeBlockData) || (tsLastBlock != pBlockData->aTSKEY[pDumpInfo->rowIndex])) { if (tryCopyDistinctRowFromSttBlock(&fRow, pLastBlockReader, pBlockScanInfo, tsLastBlock, pReader)) { + pBlockScanInfo->lastKey = tsLastBlock; return TSDB_CODE_SUCCESS; } else { int32_t code = tRowMergerInit(&merge, &fRow, pReader->pSchema); @@ -1699,14 +1874,14 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader, TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree); tRowMerge(&merge, &fRow1); - doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLastBlock, &merge); + doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLastBlock, &merge, &pReader->verRange); code = tRowMergerGetRow(&merge, &pTSRow); if (code != TSDB_CODE_SUCCESS) { return code; } - doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo->uid); + doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo); taosMemoryFree(pTSRow); tRowMergerClear(&merge); @@ -1717,7 +1892,7 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader, return code; } - doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLastBlock, &merge); + doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLastBlock, &merge, &pReader->verRange); ASSERT(mergeBlockData); // merge with block data if ts == key @@ -1730,7 +1905,7 @@ static int32_t doMergeFileBlockAndLastBlock(SLastBlockReader* pLastBlockReader, return code; } - doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo->uid); + doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo); taosMemoryFree(pTSRow); tRowMergerClear(&merge); @@ -1771,14 +1946,14 @@ static int32_t mergeFileBlockAndLastBlock(STsdbReader* pReader, SLastBlockReader TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree); tRowMerge(&merge, &fRow1); - doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, ts, &merge); + doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, ts, &merge, &pReader->verRange); code = tRowMergerGetRow(&merge, &pTSRow); if (code != TSDB_CODE_SUCCESS) { return code; } - doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo->uid); + doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo); taosMemoryFree(pTSRow); tRowMergerClear(&merge); @@ -1862,7 +2037,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo* if (minKey == key) { init = true; TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex); - int32_t code = tRowMergerInit(&merge, &fRow, pReader->pSchema); + code = tRowMergerInit(&merge, &fRow, pReader->pSchema); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -1876,13 +2051,13 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo* tRowMerge(&merge, &fRow1); } else { init = true; - int32_t code = tRowMergerInit(&merge, &fRow1, pReader->pSchema); + code = tRowMergerInit(&merge, &fRow1, pReader->pSchema); if (code != TSDB_CODE_SUCCESS) { return code; } } - doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLast, &merge); + doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLast, &merge, &pReader->verRange); } if (minKey == ik.ts) { @@ -1901,8 +2076,8 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo* } } - code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, ik.ts, pBlockScanInfo->delSkyline, - &merge, pReader); + code = doMergeRowsInBuf(&pBlockScanInfo->iiter, pBlockScanInfo->uid, ik.ts, pBlockScanInfo->delSkyline, &merge, + pReader); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -1973,7 +2148,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo* return code; } } - doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLast, &merge); + doMergeRowsInLastBlock(pLastBlockReader, pBlockScanInfo, tsLast, &merge, &pReader->verRange); } if (minKey == key) { @@ -1993,7 +2168,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo* } } - if (merge.pTSchema == NULL) { + if (merge.pTSchema == NULL) { return code; } @@ -2002,7 +2177,7 @@ static int32_t doMergeMultiLevelRows(STsdbReader* pReader, STableBlockScanInfo* return code; } - doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo->uid); + doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo); taosMemoryFree(pTSRow); tRowMergerClear(&merge); @@ -2095,7 +2270,8 @@ static bool isValidFileBlockRow(SBlockData* pBlockData, SFileBlockDumpInfo* pDum } TSDBKEY k = {.ts = ts, .version = ver}; - if (hasBeenDropped(pBlockScanInfo->delSkyline, &pBlockScanInfo->fileDelIndex, &k, pReader->order)) { + if (hasBeenDropped(pBlockScanInfo->delSkyline, &pBlockScanInfo->fileDelIndex, &k, pReader->order, + &pReader->verRange)) { return false; } @@ -2105,7 +2281,7 @@ static bool isValidFileBlockRow(SBlockData* pBlockData, SFileBlockDumpInfo* pDum static bool initLastBlockReader(SLastBlockReader* pLBlockReader, STableBlockScanInfo* pScanInfo, STsdbReader* pReader) { // the last block reader has been initialized for this table. if (pLBlockReader->uid == pScanInfo->uid) { - return true; + return hasDataInLastBlock(pLBlockReader); } if (pLBlockReader->uid != 0) { @@ -2130,7 +2306,7 @@ static bool initLastBlockReader(SLastBlockReader* pLBlockReader, STableBlockScan return false; } - return nextRowFromLastBlocks(pLBlockReader, pScanInfo); + return nextRowFromLastBlocks(pLBlockReader, pScanInfo, &pReader->verRange); } static int64_t getCurrentKeyInLastBlock(SLastBlockReader* pLastBlockReader) { @@ -2152,6 +2328,7 @@ int32_t mergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pBloc STsdbReader* pReader) { SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; if (tryCopyDistinctRowFromFileBlock(pReader, pBlockData, key, pDumpInfo)) { + pBlockScanInfo->lastKey = key; return TSDB_CODE_SUCCESS; } else { TSDBROW fRow = tsdbRowFromBlockData(pBlockData, pDumpInfo->rowIndex); @@ -2170,7 +2347,7 @@ int32_t mergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pBloc return code; } - doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo->uid); + doAppendRowFromTSRow(pReader->pResBlock, pReader, pTSRow, pBlockScanInfo); taosMemoryFree(pTSRow); tRowMergerClear(&merge); @@ -2218,36 +2395,41 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) { SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(&pReader->status.blockIter); SLastBlockReader* pLastBlockReader = pReader->status.fileIter.pLastBlockReader; + bool asc = ASCENDING_TRAVERSE(pReader->order); int64_t st = taosGetTimestampUs(); + int32_t step = asc ? 1 : -1; STableBlockScanInfo* pBlockScanInfo = NULL; if (pBlockInfo != NULL) { - pBlockScanInfo = taosHashGet(pReader->status.pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid)); - if (pBlockScanInfo == NULL) { + void* p = taosHashGet(pReader->status.pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid)); + if (p == NULL) { code = TSDB_CODE_INVALID_PARA; - tsdbError("failed to locate the uid:%"PRIu64" in query table uid list, total tables:%d, %s", - pBlockInfo->uid, taosHashGetSize(pReader->status.pTableMap), pReader->idStr); + tsdbError("failed to locate the uid:%" PRIu64 " in query table uid list, total tables:%d, %s", pBlockInfo->uid, + taosHashGetSize(pReader->status.pTableMap), pReader->idStr); goto _end; } + pBlockScanInfo = *(STableBlockScanInfo**)p; + SDataBlk* pBlock = getCurrentBlock(&pReader->status.blockIter); TSDBKEY keyInBuf = getCurrentKeyInBuf(pBlockScanInfo, pReader); // it is a clean block, load it directly if (isCleanFileDataBlock(pReader, pBlockInfo, pBlock, pBlockScanInfo, keyInBuf, pLastBlockReader)) { - if (pReader->order == TSDB_ORDER_ASC || - (pReader->order == TSDB_ORDER_DESC && (!hasDataInLastBlock(pLastBlockReader)))) { + if (asc || ((!asc) && (!hasDataInLastBlock(pLastBlockReader)))) { copyBlockDataToSDataBlock(pReader, pBlockScanInfo); + + // record the last key value + pBlockScanInfo->lastKey = asc ? pBlock->maxKey.ts : pBlock->minKey.ts; goto _end; } } } else { // file blocks not exist - pBlockScanInfo = pReader->status.pTableIter; + pBlockScanInfo = *pReader->status.pTableIter; } SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; SBlockData* pBlockData = &pReader->status.fileBlockData; - int32_t step = ASCENDING_TRAVERSE(pReader->order) ? 1 : -1; while (1) { bool hasBlockData = false; @@ -2290,7 +2472,7 @@ static int32_t buildComposedDataBlock(STsdbReader* pReader) { } _end: - pResBlock->info.uid = (pBlockScanInfo != NULL)? pBlockScanInfo->uid:0; + pResBlock->info.uid = (pBlockScanInfo != NULL) ? pBlockScanInfo->uid : 0; blockDataUpdateTsWindow(pResBlock, 0); setComposedBlockFlag(pReader, true); @@ -2467,7 +2649,7 @@ static void extractOrderedTableUidList(SUidOrderCheckInfo* pOrderCheckInfo, SRea void* p = taosHashIterate(pStatus->pTableMap, NULL); while (p != NULL) { - STableBlockScanInfo* pScanInfo = p; + STableBlockScanInfo* pScanInfo = *(STableBlockScanInfo**)p; pOrderCheckInfo->tableUidList[index++] = pScanInfo->uid; p = taosHashIterate(pStatus->pTableMap, p); } @@ -2541,7 +2723,7 @@ static int32_t doLoadLastBlockSequentially(STsdbReader* pReader) { while (1) { // load the last data block of current table - STableBlockScanInfo* pScanInfo = pStatus->pTableIter; + STableBlockScanInfo* pScanInfo = *(STableBlockScanInfo**)pStatus->pTableIter; bool hasVal = initLastBlockReader(pLastBlockReader, pScanInfo, pReader); if (!hasVal) { bool hasNexTable = moveToNextTable(pOrderedCheckInfo, pStatus); @@ -2579,9 +2761,10 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) { SLastBlockReader* pLastBlockReader = pReader->status.fileIter.pLastBlockReader; if (pBlockInfo != NULL) { - pScanInfo = taosHashGet(pReader->status.pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid)); + pScanInfo = + *(STableBlockScanInfo**)taosHashGet(pReader->status.pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid)); } else { - pScanInfo = pReader->status.pTableIter; + pScanInfo = *pReader->status.pTableIter; } if (pScanInfo == NULL) { @@ -2629,6 +2812,9 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) { pInfo->window = (STimeWindow){.skey = pBlock->minKey.ts, .ekey = pBlock->maxKey.ts}; setComposedBlockFlag(pReader, false); setBlockAllDumped(&pStatus->fBlockDumpInfo, pBlock->maxKey.ts, pReader->order); + + // update the last key for the corresponding table + pScanInfo->lastKey = ASCENDING_TRAVERSE(pReader->order) ? pInfo->window.ekey : pInfo->window.skey; } } @@ -2646,11 +2832,11 @@ static int32_t buildBlockFromBufferSequentially(STsdbReader* pReader) { } } - STableBlockScanInfo* pBlockScanInfo = pStatus->pTableIter; - initMemDataIterator(pBlockScanInfo, pReader); + STableBlockScanInfo** pBlockScanInfo = pStatus->pTableIter; + initMemDataIterator(*pBlockScanInfo, pReader); int64_t endKey = (ASCENDING_TRAVERSE(pReader->order)) ? INT64_MAX : INT64_MIN; - int32_t code = buildDataBlockFromBuf(pReader, pBlockScanInfo, endKey); + int32_t code = buildDataBlockFromBuf(pReader, *pBlockScanInfo, endKey); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -2859,7 +3045,7 @@ SVersionRange getQueryVerRange(SVnode* pVnode, SQueryTableDataCond* pCond, int8_ return (SVersionRange){.minVer = startVer, .maxVer = endVer}; } -bool hasBeenDropped(const SArray* pDelList, int32_t* index, TSDBKEY* pKey, int32_t order) { +bool hasBeenDropped(const SArray* pDelList, int32_t* index, TSDBKEY* pKey, int32_t order, SVersionRange* pVerRange) { ASSERT(pKey != NULL); if (pDelList == NULL) { return false; @@ -2887,7 +3073,8 @@ bool hasBeenDropped(const SArray* pDelList, int32_t* index, TSDBKEY* pKey, int32 return false; } - if (pCurrent->ts <= pKey->ts && pNext->ts >= pKey->ts && pCurrent->version >= pKey->version) { + if (pCurrent->ts <= pKey->ts && pNext->ts >= pKey->ts && pCurrent->version >= pKey->version && + pVerRange->maxVer >= pCurrent->version) { return true; } @@ -2903,7 +3090,8 @@ bool hasBeenDropped(const SArray* pDelList, int32_t* index, TSDBKEY* pKey, int32 continue; } - if (pCurrent->ts <= pKey->ts && pNext->ts >= pKey->ts && pCurrent->version >= pKey->version) { + if (pCurrent->ts <= pKey->ts && pNext->ts >= pKey->ts && pCurrent->version >= pKey->version && + pVerRange->maxVer >= pCurrent->version) { return true; } } @@ -2973,7 +3161,7 @@ TSDBROW* getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdbReader* p // it is a valid data version if ((key.version <= pReader->verRange.maxVer && key.version >= pReader->verRange.minVer) && - (!hasBeenDropped(pDelList, &pIter->index, &key, pReader->order))) { + (!hasBeenDropped(pDelList, &pIter->index, &key, pReader->order, &pReader->verRange))) { return pRow; } @@ -2992,7 +3180,7 @@ TSDBROW* getValidMemRow(SIterInfo* pIter, const SArray* pDelList, STsdbReader* p } if (key.version <= pReader->verRange.maxVer && key.version >= pReader->verRange.minVer && - (!hasBeenDropped(pDelList, &pIter->index, &key, pReader->order))) { + (!hasBeenDropped(pDelList, &pIter->index, &key, pReader->order, &pReader->verRange))) { return pRow; } } @@ -3059,15 +3247,15 @@ static int32_t checkForNeighborFileBlock(STsdbReader* pReader, STableBlockScanIn *state = CHECK_FILEBLOCK_QUIT; int32_t step = ASCENDING_TRAVERSE(pReader->order) ? 1 : -1; - int32_t nextIndex = -1; - SDataBlk* pNeighborBlock = getNeighborBlockOfSameTable(pFBlock, pScanInfo, &nextIndex, pReader->order); - if (pNeighborBlock == NULL) { // do nothing + int32_t nextIndex = -1; + SBlockIndex bIndex = {0}; + + bool hasNeighbor = getNeighborBlockOfSameTable(pFBlock, pScanInfo, &nextIndex, pReader->order, &bIndex); + if (!hasNeighbor) { // do nothing return 0; } - bool overlap = overlapWithNeighborBlock(pBlock, pNeighborBlock, pReader->order); - taosMemoryFree(pNeighborBlock); - + bool overlap = overlapWithNeighborBlock(pBlock, &bIndex, pReader->order); if (overlap) { // load next block SReaderStatus* pStatus = &pReader->status; SDataBlockIter* pBlockIter = &pStatus->blockIter; @@ -3130,9 +3318,8 @@ int32_t doMergeRowsInFileBlocks(SBlockData* pBlockData, STableBlockScanInfo* pSc } int32_t doMergeRowsInLastBlock(SLastBlockReader* pLastBlockReader, STableBlockScanInfo* pScanInfo, int64_t ts, - SRowMerger* pMerger) { - pScanInfo->lastKey = ts; - while (nextRowFromLastBlocks(pLastBlockReader, pScanInfo)) { + SRowMerger* pMerger, SVersionRange* pVerRange) { + while (nextRowFromLastBlocks(pLastBlockReader, pScanInfo, pVerRange)) { int64_t next1 = getCurrentKeyInLastBlock(pLastBlockReader); if (next1 == ts) { TSDBROW fRow1 = tMergeTreeGetRow(&pLastBlockReader->mergeTree); @@ -3324,9 +3511,11 @@ int32_t tsdbGetNextRowInMem(STableBlockScanInfo* pBlockScanInfo, STsdbReader* pR return TSDB_CODE_SUCCESS; } -int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, STSRow* pTSRow, uint64_t uid) { +int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, STSRow* pTSRow, + STableBlockScanInfo* pScanInfo) { int32_t numOfRows = pBlock->info.rows; int32_t numOfCols = (int32_t)taosArrayGetSize(pBlock->pDataBlock); + int64_t uid = pScanInfo->uid; SBlockLoadSuppInfo* pSupInfo = &pReader->suppInfo; STSchema* pSchema = doGetSchemaForTSRow(pTSRow->sver, pReader, uid); @@ -3365,6 +3554,7 @@ int32_t doAppendRowFromTSRow(SSDataBlock* pBlock, STsdbReader* pReader, STSRow* } pBlock->info.rows += 1; + pScanInfo->lastKey = pTSRow->ts; return TSDB_CODE_SUCCESS; } @@ -3382,7 +3572,7 @@ int32_t doAppendRowFromFileBlock(SSDataBlock* pResBlock, STsdbReader* pReader, S } SColVal cv = {0}; - int32_t numOfInputCols = pBlockData->aIdx->size; + int32_t numOfInputCols = pBlockData->nColData; int32_t numOfOutputCols = pResBlock->pDataBlock->size; while (i < numOfOutputCols && j < numOfInputCols) { @@ -3428,7 +3618,8 @@ int32_t buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t e break; } - doAppendRowFromTSRow(pBlock, pReader, pTSRow, pBlockScanInfo->uid); + doAppendRowFromTSRow(pBlock, pReader, pTSRow, pBlockScanInfo); + if (freeTSRow) { taosMemoryFree(pTSRow); } @@ -3447,13 +3638,28 @@ int32_t buildDataBlockFromBufImpl(STableBlockScanInfo* pBlockScanInfo, int64_t e return TSDB_CODE_SUCCESS; } -// todo refactor, use arraylist instead -int32_t tsdbSetTableId(STsdbReader* pReader, int64_t uid) { +// TODO refactor: with createDataBlockScanInfo +int32_t tsdbSetTableList(STsdbReader* pReader, const void* pTableList, int32_t num) { ASSERT(pReader != NULL); + int32_t size = taosHashGetSize(pReader->status.pTableMap); + + STableBlockScanInfo** p = NULL; + while ((p = taosHashIterate(pReader->status.pTableMap, p)) != NULL) { + clearBlockScanInfo(*p); + } + + // todo handle the case where size is less than the value of num + ASSERT(size >= num); + taosHashClear(pReader->status.pTableMap); - STableBlockScanInfo info = {.lastKey = 0, .uid = uid}; - taosHashPut(pReader->status.pTableMap, &info.uid, sizeof(uint64_t), &info, sizeof(info)); + STableKeyInfo* pList = (STableKeyInfo*)pTableList; + for (int32_t i = 0; i < num; ++i) { + STableBlockScanInfo* pInfo = getPosInBlockInfoBuf(&pReader->blockInfoBuf, i); + pInfo->uid = pList[i].uid; + taosHashPut(pReader->status.pTableMap, &pInfo->uid, sizeof(uint64_t), &pInfo, POINTER_BYTES); + } + return TDB_CODE_SUCCESS; } @@ -3489,8 +3695,8 @@ static int32_t doOpenReaderImpl(STsdbReader* pReader) { } // ====================================== EXPOSED APIs ====================================== -int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* pTableList, STsdbReader** ppReader, - const char* idstr) { +int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, void* pTableList, int32_t numOfTables, + STsdbReader** ppReader, const char* idstr) { STimeWindow window = pCond->twindows; if (pCond->type == TIMEWINDOW_RANGE_EXTERNAL) { pCond->twindows.skey += 1; @@ -3549,8 +3755,8 @@ int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* pTabl if (pReader->pSchema == NULL) { tsdbError("failed to get table schema, suid:%" PRIu64 ", ver:-1, %s", pReader->suid, pReader->idStr); } - } else if (taosArrayGetSize(pTableList) > 0) { - STableKeyInfo* pKey = taosArrayGet(pTableList, 0); + } else if (numOfTables > 0) { + STableKeyInfo* pKey = pTableList; pReader->pSchema = metaGetTbTSchema(pReader->pTsdb->pVnode->pMeta, pKey->uid, -1, 1); if (pReader->pSchema == NULL) { tsdbError("failed to get table schema, uid:%" PRIu64 ", ver:-1, %s", pKey->uid, pReader->idStr); @@ -3559,8 +3765,7 @@ int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* pTabl STsdbReader* p = pReader->innerReader[0] != NULL ? pReader->innerReader[0] : pReader; - int32_t numOfTables = taosArrayGetSize(pTableList); - pReader->status.pTableMap = createDataBlockScanInfo(p, pTableList->pData, numOfTables); + pReader->status.pTableMap = createDataBlockScanInfo(p, pTableList, numOfTables); if (pReader->status.pTableMap == NULL) { tsdbReaderClose(pReader); *ppReader = NULL; @@ -3601,16 +3806,6 @@ int32_t tsdbReaderOpen(SVnode* pVnode, SQueryTableDataCond* pCond, SArray* pTabl if (code != TSDB_CODE_SUCCESS) { return code; } - - code = doOpenReaderImpl(pNextReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - code = doOpenReaderImpl(pReader); - if (code != TSDB_CODE_SUCCESS) { - return code; - } } } @@ -3666,8 +3861,9 @@ void tsdbReaderClose(STsdbReader* pReader) { cleanupDataBlockIterator(&pReader->status.blockIter); size_t numOfTables = taosHashGetSize(pReader->status.pTableMap); - destroyBlockScanInfo(pReader->status.pTableMap); + destroyAllBlockScanInfo(pReader->status.pTableMap, (pReader->innerReader[0] == NULL) ? true : false); blockDataDestroy(pReader->pResBlock); + clearBlockScanInfoBuf(&pReader->blockInfoBuf); if (pReader->pFileReader != NULL) { tsdbDataFReaderClose(&pReader->pFileReader); @@ -3689,15 +3885,16 @@ void tsdbReaderClose(STsdbReader* pReader) { taosMemoryFree(pLReader); } - tsdbDebug( - "%p :io-cost summary: head-file:%" PRIu64 ", head-file time:%.2f ms, SMA:%" PRId64 - " SMA-time:%.2f ms, fileBlocks:%" PRId64 - ", fileBlocks-load-time:%.2f ms, " - "build in-memory-block-time:%.2f ms, lastBlocks:%" PRId64 ", lastBlocks-time:%.2f ms, composed-blocks:%" PRId64 - ", composed-blocks-time:%.2fms, STableBlockScanInfo size:%.2f Kb %s", - pReader, pCost->headFileLoad, pCost->headFileLoadTime, pCost->smaDataLoad, pCost->smaLoadTime, pCost->numOfBlocks, - pCost->blockLoadTime, pCost->buildmemBlock, pCost->lastBlockLoad, pCost->lastBlockLoadTime, pCost->composedBlocks, - pCost->buildComposedBlockTime, numOfTables * sizeof(STableBlockScanInfo) / 1000.0, pReader->idStr); + tsdbDebug("%p :io-cost summary: head-file:%" PRIu64 ", head-file time:%.2f ms, SMA:%" PRId64 + " SMA-time:%.2f ms, fileBlocks:%" PRId64 + ", fileBlocks-load-time:%.2f ms, " + "build in-memory-block-time:%.2f ms, lastBlocks:%" PRId64 + ", lastBlocks-time:%.2f ms, composed-blocks:%" PRId64 + ", composed-blocks-time:%.2fms, STableBlockScanInfo size:%.2f Kb, creatTime:%.2f ms, %s", + pReader, pCost->headFileLoad, pCost->headFileLoadTime, pCost->smaDataLoad, pCost->smaLoadTime, + pCost->numOfBlocks, pCost->blockLoadTime, pCost->buildmemBlock, pCost->lastBlockLoad, + pCost->lastBlockLoadTime, pCost->composedBlocks, pCost->buildComposedBlockTime, + numOfTables * sizeof(STableBlockScanInfo) / 1000.0, pCost->createScanInfoList, pReader->idStr); taosMemoryFree(pReader->idStr); taosMemoryFree(pReader->pSchema); @@ -3741,15 +3938,21 @@ bool tsdbNextDataBlock(STsdbReader* pReader) { if (pReader->innerReader[0] != NULL && pReader->step == 0) { bool ret = doTsdbNextDataBlock(pReader->innerReader[0]); - resetDataBlockScanInfo(pReader->innerReader[0]->status.pTableMap, pReader->innerReader[0]->window.ekey); pReader->step = EXTERNAL_ROWS_PREV; - if (ret) { return ret; } } if (pReader->step == EXTERNAL_ROWS_PREV) { + // prepare for the main scan + int32_t code = doOpenReaderImpl(pReader); + resetAllDataBlockScanInfo(pReader->status.pTableMap, pReader->innerReader[0]->window.ekey); + + if (code != TSDB_CODE_SUCCESS) { + return code; + } + pReader->step = EXTERNAL_ROWS_MAIN; } @@ -3759,7 +3962,13 @@ bool tsdbNextDataBlock(STsdbReader* pReader) { } if (pReader->innerReader[1] != NULL && pReader->step == EXTERNAL_ROWS_MAIN) { - resetDataBlockScanInfo(pReader->innerReader[1]->status.pTableMap, pReader->window.ekey); + // prepare for the next row scan + int32_t code = doOpenReaderImpl(pReader->innerReader[1]); + resetAllDataBlockScanInfo(pReader->innerReader[1]->status.pTableMap, pReader->window.ekey); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + bool ret1 = doTsdbNextDataBlock(pReader->innerReader[1]); pReader->step = EXTERNAL_ROWS_NEXT; if (ret1) { @@ -3771,32 +3980,33 @@ bool tsdbNextDataBlock(STsdbReader* pReader) { } bool tsdbTableNextDataBlock(STsdbReader* pReader, uint64_t uid) { - STableBlockScanInfo* pBlockScanInfo = taosHashGet(pReader->status.pTableMap, &uid, sizeof(uid)); - if (pBlockScanInfo == NULL) { // no data block for the table of given uid + STableBlockScanInfo* pBlockScanInfo = + *(STableBlockScanInfo**)taosHashGet(pReader->status.pTableMap, &uid, sizeof(uid)); + if (pBlockScanInfo == NULL) { // no data block for the table of given uid return false; } return true; } -static void setBlockInfo(STsdbReader* pReader, SDataBlockInfo* pDataBlockInfo) { - ASSERT(pDataBlockInfo != NULL && pReader != NULL); - pDataBlockInfo->rows = pReader->pResBlock->info.rows; - pDataBlockInfo->uid = pReader->pResBlock->info.uid; - pDataBlockInfo->window = pReader->pResBlock->info.window; +static void setBlockInfo(const STsdbReader* pReader, int32_t* rows, uint64_t* uid, STimeWindow* pWindow) { + ASSERT(pReader != NULL); + *rows = pReader->pResBlock->info.rows; + *uid = pReader->pResBlock->info.uid; + *pWindow = pReader->pResBlock->info.window; } -void tsdbRetrieveDataBlockInfo(STsdbReader* pReader, SDataBlockInfo* pDataBlockInfo) { +void tsdbRetrieveDataBlockInfo(const STsdbReader* pReader, int32_t* rows, uint64_t* uid, STimeWindow* pWindow) { if (pReader->type == TIMEWINDOW_RANGE_EXTERNAL) { if (pReader->step == EXTERNAL_ROWS_MAIN) { - setBlockInfo(pReader, pDataBlockInfo); + setBlockInfo(pReader, rows, uid, pWindow); } else if (pReader->step == EXTERNAL_ROWS_PREV) { - setBlockInfo(pReader->innerReader[0], pDataBlockInfo); + setBlockInfo(pReader->innerReader[0], rows, uid, pWindow); } else { - setBlockInfo(pReader->innerReader[1], pDataBlockInfo); + setBlockInfo(pReader->innerReader[1], rows, uid, pWindow); } } else { - setBlockInfo(pReader, pDataBlockInfo); + setBlockInfo(pReader, rows, uid, pWindow); } } @@ -3818,7 +4028,7 @@ int32_t tsdbRetrieveDatablockSMA(STsdbReader* pReader, SColumnDataAgg*** pBlockS SFileDataBlockInfo* pFBlock = getCurrentBlockInfo(&pReader->status.blockIter); SDataBlk* pBlock = getCurrentBlock(&pReader->status.blockIter); - int64_t stime = taosGetTimestampUs(); + // int64_t stime = taosGetTimestampUs(); SBlockLoadSuppInfo* pSup = &pReader->suppInfo; @@ -3849,7 +4059,9 @@ int32_t tsdbRetrieveDatablockSMA(STsdbReader* pReader, SColumnDataAgg*** pBlockS size_t numOfCols = blockDataGetNumOfCols(pReader->pResBlock); int32_t i = 0, j = 0; - while (j < numOfCols && i < taosArrayGetSize(pSup->pColAgg)) { + size_t size = taosArrayGetSize(pSup->pColAgg); + + while (j < numOfCols && i < size) { SColumnDataAgg* pAgg = taosArrayGet(pSup->pColAgg, i); if (pAgg->colId == pSup->colIds[j]) { if (IS_BSMA_ON(&(pReader->pSchema->columns[i]))) { @@ -3866,14 +4078,10 @@ int32_t tsdbRetrieveDatablockSMA(STsdbReader* pReader, SColumnDataAgg*** pBlockS } } - double elapsed = (taosGetTimestampUs() - stime) / 1000.0; - pReader->cost.smaLoadTime += elapsed; pReader->cost.smaDataLoad += 1; - *pBlockStatis = pSup->plist; - tsdbDebug("vgId:%d, succeed to load block SMA for uid %" PRIu64 ", elapsed time:%.2f ms, %s", 0, pFBlock->uid, - elapsed, pReader->idStr); + tsdbDebug("vgId:%d, succeed to load block SMA for uid %" PRIu64 ", %s", 0, pFBlock->uid, pReader->idStr); return code; } @@ -3886,7 +4094,8 @@ static SArray* doRetrieveDataBlock(STsdbReader* pReader) { } SFileDataBlockInfo* pBlockInfo = getCurrentBlockInfo(&pStatus->blockIter); - STableBlockScanInfo* pBlockScanInfo = taosHashGet(pStatus->pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid)); + STableBlockScanInfo* pBlockScanInfo = + *(STableBlockScanInfo**)taosHashGet(pStatus->pTableMap, &pBlockInfo->uid, sizeof(pBlockInfo->uid)); if (pBlockScanInfo == NULL) { terrno = TSDB_CODE_INVALID_PARA; tsdbError("failed to locate the uid:%" PRIu64 " in query table uid list, total tables:%d, %s", pBlockInfo->uid, @@ -3922,6 +4131,8 @@ int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) { return TSDB_CODE_SUCCESS; } + SDataBlockIter* pBlockIter = &pReader->status.blockIter; + pReader->order = pCond->order; pReader->type = TIMEWINDOW_RANGE_CONTAINED; pReader->status.loadFromFile = true; @@ -3938,13 +4149,12 @@ int32_t tsdbReaderReset(STsdbReader* pReader, SQueryTableDataCond* pCond) { int32_t numOfTables = taosHashGetSize(pReader->status.pTableMap); initFilesetIterator(&pReader->status.fileIter, pReader->pReadSnap->fs.aDFileSet, pReader); - resetDataBlockIterator(&pReader->status.blockIter, pReader->order); + resetDataBlockIterator(pBlockIter, pReader->order); int64_t ts = ASCENDING_TRAVERSE(pReader->order) ? pReader->window.skey - 1 : pReader->window.ekey + 1; - resetDataBlockScanInfo(pReader->status.pTableMap, ts); + resetAllDataBlockScanInfo(pReader->status.pTableMap, ts); - int32_t code = 0; - SDataBlockIter* pBlockIter = &pReader->status.blockIter; + int32_t code = 0; // no data in files, let's try buffer in memory if (pReader->status.fileIter.numOfFiles == 0) { @@ -4046,7 +4256,7 @@ int64_t tsdbGetNumOfRowsInMemTable(STsdbReader* pReader) { pStatus->pTableIter = taosHashIterate(pStatus->pTableMap, NULL); while (pStatus->pTableIter != NULL) { - STableBlockScanInfo* pBlockScanInfo = pStatus->pTableIter; + STableBlockScanInfo* pBlockScanInfo = *(STableBlockScanInfo**)pStatus->pTableIter; STbData* d = NULL; if (pReader->pTsdb->mem != NULL) { diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c index 27beb22165cbfb619f6cddd5d7eccfc55d80a43e..8c1b0004a38201c1c9d827070137d69de85f4f7a 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c +++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c @@ -514,13 +514,13 @@ static int32_t tsdbWriteBlockSma(SDataFWriter *pWriter, SBlockData *pBlockData, pSmaInfo->size = 0; // encode - for (int32_t iColData = 0; iColData < taosArrayGetSize(pBlockData->aIdx); iColData++) { + for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) { SColData *pColData = tBlockDataGetColDataByIdx(pBlockData, iColData); if ((!pColData->smaOn) || IS_VAR_DATA_TYPE(pColData->type)) continue; - SColumnDataAgg sma; - tsdbCalcColDataSMA(pColData, &sma); + SColumnDataAgg sma = {.colId = pColData->cid}; + tColDataCalcSMA[pColData->type](pColData, &sma.sum, &sma.max, &sma.min, &sma.numOfNull); code = tRealloc(&pWriter->aBuf[0], pSmaInfo->size + tPutColumnDataAgg(NULL, &sma)); if (code) goto _err; @@ -1112,7 +1112,7 @@ static int32_t tsdbReadBlockDataImpl(SDataFReader *pReader, SBlockInfo *pBlkInfo ASSERT(p - pReader->aBuf[0] == pBlkInfo->szKey); // read and decode columns - if (taosArrayGetSize(pBlockData->aIdx) == 0) goto _exit; + if (pBlockData->nColData == 0) goto _exit; if (hdr.szBlkCol > 0) { int64_t offset = pBlkInfo->offset + pBlkInfo->szKey; @@ -1128,7 +1128,7 @@ static int32_t tsdbReadBlockDataImpl(SDataFReader *pReader, SBlockInfo *pBlkInfo SBlockCol *pBlockCol = &blockCol; int32_t n = 0; - for (int32_t iColData = 0; iColData < taosArrayGetSize(pBlockData->aIdx); iColData++) { + for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) { SColData *pColData = tBlockDataGetColDataByIdx(pBlockData, iColData); while (pBlockCol && pBlockCol->cid < pColData->cid) { @@ -1212,49 +1212,6 @@ int32_t tsdbReadDataBlock(SDataFReader *pReader, SDataBlk *pDataBlk, SBlockData ASSERT(pDataBlk->nSubBlock == 1); -#if 0 - if (pDataBlk->nSubBlock > 1) { - SBlockData bData1; - SBlockData bData2; - - // create - code = tBlockDataCreate(&bData1); - if (code) goto _err; - code = tBlockDataCreate(&bData2); - if (code) goto _err; - - // init - tBlockDataInitEx(&bData1, pBlockData); - tBlockDataInitEx(&bData2, pBlockData); - - for (int32_t iSubBlock = 1; iSubBlock < pDataBlk->nSubBlock; iSubBlock++) { - code = tsdbReadBlockDataImpl(pReader, &pDataBlk->aSubBlock[iSubBlock], &bData1); - if (code) { - tBlockDataDestroy(&bData1, 1); - tBlockDataDestroy(&bData2, 1); - goto _err; - } - - code = tBlockDataCopy(pBlockData, &bData2); - if (code) { - tBlockDataDestroy(&bData1, 1); - tBlockDataDestroy(&bData2, 1); - goto _err; - } - - code = tBlockDataMerge(&bData1, &bData2, pBlockData); - if (code) { - tBlockDataDestroy(&bData1, 1); - tBlockDataDestroy(&bData2, 1); - goto _err; - } - } - - tBlockDataDestroy(&bData1, 1); - tBlockDataDestroy(&bData2, 1); - } -#endif - return code; _err: diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c index 4e02a28cdf49affbc722ae69a60cbf067ff98139..9ac9a7d66d0954f06fd8c46b62c13ef0dcea2703 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c @@ -575,16 +575,6 @@ int32_t tPutTSDBRow(uint8_t *p, TSDBROW *pRow) { return n; } -int32_t tGetTSDBRow(uint8_t *p, TSDBROW *pRow) { - int32_t n = 0; - - n += tGetI64(p, &pRow->version); - pRow->pTSRow = (STSRow *)(p + n); - n += pRow->pTSRow->len; - - return n; -} - int32_t tsdbRowCmprFn(const void *p1, const void *p2) { return tsdbKeyCmprFn(&TSDBROW_KEY((TSDBROW *)p1), &TSDBROW_KEY((TSDBROW *)p2)); } @@ -607,13 +597,13 @@ void tRowIterInit(SRowIter *pIter, TSDBROW *pRow, STSchema *pTSchema) { SColVal *tRowIterNext(SRowIter *pIter) { if (pIter->pRow->type == 0) { if (pIter->i < pIter->pTSchema->numOfCols) { - tsdbRowGetColVal(pIter->pRow, pIter->pTSchema, pIter->i, &pIter->colVal); + tTSRowGetVal(pIter->pRow->pTSRow, pIter->pTSchema, pIter->i, &pIter->colVal); pIter->i++; return &pIter->colVal; } } else { - if (pIter->i < taosArrayGetSize(pIter->pRow->pBlockData->aIdx)) { + if (pIter->i < pIter->pRow->pBlockData->nColData) { SColData *pColData = tBlockDataGetColDataByIdx(pIter->pRow->pBlockData, pIter->i); tColDataGetValue(pColData, pIter->pRow->iRow, &pIter->colVal); @@ -917,14 +907,9 @@ int32_t tBlockDataCreate(SBlockData *pBlockData) { pBlockData->aUid = NULL; pBlockData->aVersion = NULL; pBlockData->aTSKEY = NULL; - pBlockData->aIdx = taosArrayInit(0, sizeof(int32_t)); - if (pBlockData->aIdx == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _exit; - } + pBlockData->nColData = 0; pBlockData->aColData = taosArrayInit(0, sizeof(SColData)); if (pBlockData->aColData == NULL) { - taosArrayDestroy(pBlockData->aIdx); code = TSDB_CODE_OUT_OF_MEMORY; goto _exit; } @@ -937,12 +922,10 @@ void tBlockDataDestroy(SBlockData *pBlockData, int8_t deepClear) { tFree((uint8_t *)pBlockData->aUid); tFree((uint8_t *)pBlockData->aVersion); tFree((uint8_t *)pBlockData->aTSKEY); - taosArrayDestroy(pBlockData->aIdx); taosArrayDestroyEx(pBlockData->aColData, deepClear ? tColDataDestroy : NULL); pBlockData->aUid = NULL; pBlockData->aVersion = NULL; pBlockData->aTSKEY = NULL; - pBlockData->aIdx = NULL; pBlockData->aColData = NULL; } @@ -955,7 +938,7 @@ int32_t tBlockDataInit(SBlockData *pBlockData, TABLEID *pId, STSchema *pTSchema, pBlockData->uid = pId->uid; pBlockData->nRow = 0; - taosArrayClear(pBlockData->aIdx); + pBlockData->nColData = 0; if (aCid) { int32_t iColumn = 1; STColumn *pTColumn = &pTSchema->columns[iColumn]; @@ -969,7 +952,7 @@ int32_t tBlockDataInit(SBlockData *pBlockData, TABLEID *pId, STSchema *pTSchema, break; } else if (pTColumn->colId == aCid[iCid]) { SColData *pColData; - code = tBlockDataAddColData(pBlockData, taosArrayGetSize(pBlockData->aIdx), &pColData); + code = tBlockDataAddColData(pBlockData, &pColData); if (code) goto _exit; tColDataInit(pColData, pTColumn->colId, pTColumn->type, (pTColumn->flags & COL_SMA_ON) ? 1 : 0); @@ -982,7 +965,7 @@ int32_t tBlockDataInit(SBlockData *pBlockData, TABLEID *pId, STSchema *pTSchema, STColumn *pTColumn = &pTSchema->columns[iColumn]; SColData *pColData; - code = tBlockDataAddColData(pBlockData, iColumn - 1, &pColData); + code = tBlockDataAddColData(pBlockData, &pColData); if (code) goto _exit; tColDataInit(pColData, pTColumn->colId, pTColumn->type, (pTColumn->flags & COL_SMA_ON) ? 1 : 0); @@ -993,64 +976,36 @@ _exit: return code; } -int32_t tBlockDataInitEx(SBlockData *pBlockData, SBlockData *pBlockDataFrom) { - int32_t code = 0; - - ASSERT(pBlockDataFrom->suid || pBlockDataFrom->uid); - - pBlockData->suid = pBlockDataFrom->suid; - pBlockData->uid = pBlockDataFrom->uid; - pBlockData->nRow = 0; - - taosArrayClear(pBlockData->aIdx); - for (int32_t iColData = 0; iColData < taosArrayGetSize(pBlockDataFrom->aIdx); iColData++) { - SColData *pColDataFrom = tBlockDataGetColDataByIdx(pBlockDataFrom, iColData); - - SColData *pColData; - code = tBlockDataAddColData(pBlockData, iColData, &pColData); - if (code) goto _exit; - - tColDataInit(pColData, pColDataFrom->cid, pColDataFrom->type, pColDataFrom->smaOn); - } - -_exit: - return code; -} - void tBlockDataReset(SBlockData *pBlockData) { pBlockData->suid = 0; pBlockData->uid = 0; pBlockData->nRow = 0; - taosArrayClear(pBlockData->aIdx); + pBlockData->nColData = 0; } void tBlockDataClear(SBlockData *pBlockData) { ASSERT(pBlockData->suid || pBlockData->uid); pBlockData->nRow = 0; - for (int32_t iColData = 0; iColData < taosArrayGetSize(pBlockData->aIdx); iColData++) { + for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) { SColData *pColData = tBlockDataGetColDataByIdx(pBlockData, iColData); tColDataClear(pColData); } } -int32_t tBlockDataAddColData(SBlockData *pBlockData, int32_t iColData, SColData **ppColData) { +int32_t tBlockDataAddColData(SBlockData *pBlockData, SColData **ppColData) { int32_t code = 0; SColData *pColData = NULL; - int32_t idx = taosArrayGetSize(pBlockData->aIdx); - if (idx >= taosArrayGetSize(pBlockData->aColData)) { + if (pBlockData->nColData >= taosArrayGetSize(pBlockData->aColData)) { if (taosArrayPush(pBlockData->aColData, &((SColData){0})) == NULL) { code = TSDB_CODE_OUT_OF_MEMORY; goto _err; } } - pColData = (SColData *)taosArrayGet(pBlockData->aColData, idx); + pColData = (SColData *)taosArrayGet(pBlockData->aColData, pBlockData->nColData); - if (taosArrayInsert(pBlockData->aIdx, iColData, &idx) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _err; - } + pBlockData->nColData++; *ppColData = pColData; return code; @@ -1087,8 +1042,8 @@ int32_t tBlockDataAppendRow(SBlockData *pBlockData, TSDBROW *pRow, STSchema *pTS tRowIterInit(&rIter, pRow, pTSchema); pColVal = tRowIterNext(&rIter); - for (int32_t iColData = 0; iColData < taosArrayGetSize(pBlockData->aIdx); iColData++) { - SColData *pColData = tBlockDataGetColDataByIdx(pBlockData, iColData); + for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) { + SColData *pColData = &((SColData *)pBlockData->aColData->pData)[iColData]; while (pColVal && pColVal->cid < pColData->cid) { pColVal = tRowIterNext(&rIter); @@ -1115,19 +1070,19 @@ int32_t tBlockDataCorrectSchema(SBlockData *pBlockData, SBlockData *pBlockDataFr int32_t code = 0; int32_t iColData = 0; - for (int32_t iColDataFrom = 0; iColDataFrom < taosArrayGetSize(pBlockDataFrom->aIdx); iColDataFrom++) { + for (int32_t iColDataFrom = 0; iColDataFrom < pBlockDataFrom->nColData; iColDataFrom++) { SColData *pColDataFrom = tBlockDataGetColDataByIdx(pBlockDataFrom, iColDataFrom); while (true) { SColData *pColData; - if (iColData < taosArrayGetSize(pBlockData->aIdx)) { + if (iColData < pBlockData->nColData) { pColData = tBlockDataGetColDataByIdx(pBlockData, iColData); } else { pColData = NULL; } if (pColData == NULL || pColData->cid > pColDataFrom->cid) { - code = tBlockDataAddColData(pBlockData, iColData, &pColData); + code = tBlockDataAddColData(pBlockData, &pColData); if (code) goto _exit; tColDataInit(pColData, pColDataFrom->cid, pColDataFrom->type, pColDataFrom->smaOn); @@ -1226,55 +1181,15 @@ _exit: return code; } -int32_t tBlockDataCopy(SBlockData *pSrc, SBlockData *pDest) { - int32_t code = 0; - - tBlockDataClear(pDest); - - ASSERT(pDest->suid == pSrc->suid); - ASSERT(pDest->uid == pSrc->uid); - ASSERT(taosArrayGetSize(pSrc->aIdx) == taosArrayGetSize(pDest->aIdx)); - - pDest->nRow = pSrc->nRow; - - if (pSrc->uid == 0) { - code = tRealloc((uint8_t **)&pDest->aUid, sizeof(int64_t) * pDest->nRow); - if (code) goto _exit; - memcpy(pDest->aUid, pSrc->aUid, sizeof(int64_t) * pDest->nRow); - } - - code = tRealloc((uint8_t **)&pDest->aVersion, sizeof(int64_t) * pDest->nRow); - if (code) goto _exit; - memcpy(pDest->aVersion, pSrc->aVersion, sizeof(int64_t) * pDest->nRow); - - code = tRealloc((uint8_t **)&pDest->aTSKEY, sizeof(TSKEY) * pDest->nRow); - if (code) goto _exit; - memcpy(pDest->aTSKEY, pSrc->aTSKEY, sizeof(TSKEY) * pDest->nRow); - - for (int32_t iColData = 0; iColData < taosArrayGetSize(pSrc->aIdx); iColData++) { - SColData *pColSrc = tBlockDataGetColDataByIdx(pSrc, iColData); - SColData *pColDest = tBlockDataGetColDataByIdx(pDest, iColData); - - ASSERT(pColSrc->cid == pColDest->cid); - ASSERT(pColSrc->type == pColDest->type); - - code = tColDataCopy(pColSrc, pColDest); - if (code) goto _exit; - } - -_exit: - return code; -} - SColData *tBlockDataGetColDataByIdx(SBlockData *pBlockData, int32_t idx) { - ASSERT(idx >= 0 && idx < taosArrayGetSize(pBlockData->aIdx)); - return (SColData *)taosArrayGet(pBlockData->aColData, *(int32_t *)taosArrayGet(pBlockData->aIdx, idx)); + ASSERT(idx >= 0 && idx < pBlockData->nColData); + return (SColData *)taosArrayGet(pBlockData->aColData, idx); } void tBlockDataGetColData(SBlockData *pBlockData, int16_t cid, SColData **ppColData) { ASSERT(cid != PRIMARYKEY_TIMESTAMP_COL_ID); int32_t lidx = 0; - int32_t ridx = taosArrayGetSize(pBlockData->aIdx) - 1; + int32_t ridx = pBlockData->nColData - 1; while (lidx <= ridx) { int32_t midx = (lidx + ridx) / 2; @@ -1308,7 +1223,7 @@ int32_t tCmprBlockData(SBlockData *pBlockData, int8_t cmprAlg, uint8_t **ppOut, // encode ================= // columns AND SBlockCol aBufN[0] = 0; - for (int32_t iColData = 0; iColData < taosArrayGetSize(pBlockData->aIdx); iColData++) { + for (int32_t iColData = 0; iColData < pBlockData->nColData; iColData++) { SColData *pColData = tBlockDataGetColDataByIdx(pBlockData, iColData); ASSERT(pColData->flag); @@ -1431,7 +1346,7 @@ int32_t tDecmprBlockData(uint8_t *pIn, int32_t szIn, SBlockData *pBlockData, uin ASSERT(nt <= hdr.szBlkCol); SColData *pColData; - code = tBlockDataAddColData(pBlockData, taosArrayGetSize(pBlockData->aIdx), &pColData); + code = tBlockDataAddColData(pBlockData, &pColData); if (code) goto _exit; tColDataInit(pColData, blockCol.cid, blockCol.type, blockCol.smaOn); @@ -1512,111 +1427,6 @@ int32_t tGetColumnDataAgg(uint8_t *p, SColumnDataAgg *pColAgg) { return n; } -#define SMA_UPDATE(SUM_V, MIN_V, MAX_V, VAL, MINSET, MAXSET) \ - do { \ - (SUM_V) += (VAL); \ - if (!(MINSET)) { \ - (MIN_V) = (VAL); \ - (MINSET) = 1; \ - } else if ((MIN_V) > (VAL)) { \ - (MIN_V) = (VAL); \ - } \ - if (!(MAXSET)) { \ - (MAX_V) = (VAL); \ - (MAXSET) = 1; \ - } else if ((MAX_V) < (VAL)) { \ - (MAX_V) = (VAL); \ - } \ - } while (0) - -static FORCE_INLINE void tSmaUpdateBool(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, uint8_t *maxSet) { - int8_t val = *(int8_t *)&pColVal->value.val ? 1 : 0; - SMA_UPDATE(pColAgg->sum, pColAgg->min, pColAgg->max, val, *minSet, *maxSet); -} -static FORCE_INLINE void tSmaUpdateTinyint(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, - uint8_t *maxSet) { - int8_t val = *(int8_t *)&pColVal->value.val; - SMA_UPDATE(pColAgg->sum, pColAgg->min, pColAgg->max, val, *minSet, *maxSet); -} -static FORCE_INLINE void tSmaUpdateSmallint(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, - uint8_t *maxSet) { - int16_t val = *(int16_t *)&pColVal->value.val; - SMA_UPDATE(pColAgg->sum, pColAgg->min, pColAgg->max, val, *minSet, *maxSet); -} -static FORCE_INLINE void tSmaUpdateInt(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, uint8_t *maxSet) { - int32_t val = *(int32_t *)&pColVal->value.val; - SMA_UPDATE(pColAgg->sum, pColAgg->min, pColAgg->max, val, *minSet, *maxSet); -} -static FORCE_INLINE void tSmaUpdateBigint(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, uint8_t *maxSet) { - int64_t val = *(int64_t *)&pColVal->value.val; - SMA_UPDATE(pColAgg->sum, pColAgg->min, pColAgg->max, val, *minSet, *maxSet); -} -static FORCE_INLINE void tSmaUpdateFloat(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, uint8_t *maxSet) { - float val = *(float *)&pColVal->value.val; - SMA_UPDATE(*(double *)&pColAgg->sum, *(double *)&pColAgg->min, *(double *)&pColAgg->max, val, *minSet, *maxSet); -} -static FORCE_INLINE void tSmaUpdateDouble(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, uint8_t *maxSet) { - double val = *(double *)&pColVal->value.val; - SMA_UPDATE(*(double *)&pColAgg->sum, *(double *)&pColAgg->min, *(double *)&pColAgg->max, val, *minSet, *maxSet); -} -static FORCE_INLINE void tSmaUpdateUTinyint(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, - uint8_t *maxSet) { - uint8_t val = *(uint8_t *)&pColVal->value.val; - SMA_UPDATE(pColAgg->sum, pColAgg->min, pColAgg->max, val, *minSet, *maxSet); -} -static FORCE_INLINE void tSmaUpdateUSmallint(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, - uint8_t *maxSet) { - uint16_t val = *(uint16_t *)&pColVal->value.val; - SMA_UPDATE(pColAgg->sum, pColAgg->min, pColAgg->max, val, *minSet, *maxSet); -} -static FORCE_INLINE void tSmaUpdateUInt(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, uint8_t *maxSet) { - uint32_t val = *(uint32_t *)&pColVal->value.val; - SMA_UPDATE(pColAgg->sum, pColAgg->min, pColAgg->max, val, *minSet, *maxSet); -} -static FORCE_INLINE void tSmaUpdateUBigint(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, - uint8_t *maxSet) { - uint64_t val = *(uint64_t *)&pColVal->value.val; - SMA_UPDATE(pColAgg->sum, pColAgg->min, pColAgg->max, val, *minSet, *maxSet); -} -void (*tSmaUpdateImpl[])(SColumnDataAgg *pColAgg, SColVal *pColVal, uint8_t *minSet, uint8_t *maxSet) = { - NULL, - tSmaUpdateBool, // TSDB_DATA_TYPE_BOOL - tSmaUpdateTinyint, // TSDB_DATA_TYPE_TINYINT - tSmaUpdateSmallint, // TSDB_DATA_TYPE_SMALLINT - tSmaUpdateInt, // TSDB_DATA_TYPE_INT - tSmaUpdateBigint, // TSDB_DATA_TYPE_BIGINT - tSmaUpdateFloat, // TSDB_DATA_TYPE_FLOAT - tSmaUpdateDouble, // TSDB_DATA_TYPE_DOUBLE - NULL, // TSDB_DATA_TYPE_VARCHAR - tSmaUpdateBigint, // TSDB_DATA_TYPE_TIMESTAMP - NULL, // TSDB_DATA_TYPE_NCHAR - tSmaUpdateUTinyint, // TSDB_DATA_TYPE_UTINYINT - tSmaUpdateUSmallint, // TSDB_DATA_TYPE_USMALLINT - tSmaUpdateUInt, // TSDB_DATA_TYPE_UINT - tSmaUpdateUBigint, // TSDB_DATA_TYPE_UBIGINT - NULL, // TSDB_DATA_TYPE_JSON - NULL, // TSDB_DATA_TYPE_VARBINARY - NULL, // TSDB_DATA_TYPE_DECIMAL - NULL, // TSDB_DATA_TYPE_BLOB - NULL, // TSDB_DATA_TYPE_MEDIUMBLOB -}; -void tsdbCalcColDataSMA(SColData *pColData, SColumnDataAgg *pColAgg) { - *pColAgg = (SColumnDataAgg){.colId = pColData->cid}; - uint8_t minSet = 0; - uint8_t maxSet = 0; - - SColVal cv; - for (int32_t iVal = 0; iVal < pColData->nVal; iVal++) { - tColDataGetValue(pColData, iVal, &cv); - - if (COL_VAL_IS_VALUE(&cv)) { - tSmaUpdateImpl[pColData->type](pColAgg, &cv, &minSet, &maxSet); - } else { - pColAgg->numOfNull++; - } - } -} - int32_t tsdbCmprData(uint8_t *pIn, int32_t szIn, int8_t type, int8_t cmprAlg, uint8_t **ppOut, int32_t nOut, int32_t *szOut, uint8_t **ppBuf) { int32_t code = 0; diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index e593bbd602e598707a02ffa228f839b4582751ea..7040d2d7c8a0dbc4dd9bc5923723c648d593712a 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -212,6 +212,12 @@ int vnodeCommit(SVnode *pVnode) { vInfo("vgId:%d, start to commit, commit ID:%" PRId64 " version:%" PRId64, TD_VID(pVnode), pVnode->state.commitID, pVnode->state.applied); + // persist wal before starting + if (walPersist(pVnode->pWal) < 0) { + vError("vgId:%d, failed to persist wal since %s", TD_VID(pVnode), terrstr()); + return -1; + } + pVnode->state.commitTerm = pVnode->state.applyTerm; // save info diff --git a/source/dnode/vnode/src/vnd/vnodeModule.c b/source/dnode/vnode/src/vnd/vnodeModule.c index 9fe37505add7d2ec768233637f9da2c55f7124fb..782ffd788d27d338743447fb67954a9dd7812ba7 100644 --- a/source/dnode/vnode/src/vnd/vnodeModule.c +++ b/source/dnode/vnode/src/vnd/vnodeModule.c @@ -37,6 +37,12 @@ struct SVnodeGlobal vnodeGlobal; static void* loop(void* arg); +static tsem_t canCommit = {0}; + +static void vnodeInitCommit() { tsem_init(&canCommit, 0, 4); }; +void vnode_wait_commit() { tsem_wait(&canCommit); } +void vnode_done_commit() { tsem_wait(&canCommit); } + int vnodeInit(int nthreads) { int8_t init; int ret; diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index 0696ec090178b56f85bcc757532cc81e00c41457..8c2036b97b50cc3ebea0e85022cca3c8bcb4e805 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -242,11 +242,7 @@ _err: return NULL; } -void vnodePreClose(SVnode *pVnode) { - if (pVnode) { - syncLeaderTransfer(pVnode->sync); - } -} +void vnodePreClose(SVnode *pVnode) { vnodeSyncPreClose(pVnode); } void vnodeClose(SVnode *pVnode) { if (pVnode) { diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index f1bbb2d4b36b1f487af42e1424a95d6f00c1da82..efedc12d80ff555173c57a72142f235d26246cde 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -290,7 +290,7 @@ int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) { for (int32_t i = 0; i < msgNum; ++i) { if (offset >= pMsg->contLen) { qError("vnode offset %d is bigger than contLen %d", offset, pMsg->contLen); - terrno = TSDB_CODE_MSG_NOT_PROCESSED; + terrno = TSDB_CODE_INVALID_MSG_LEN; taosArrayDestroy(batchRsp); return -1; } @@ -300,7 +300,7 @@ int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) { if (offset >= pMsg->contLen) { qError("vnode offset %d is bigger than contLen %d", offset, pMsg->contLen); - terrno = TSDB_CODE_MSG_NOT_PROCESSED; + terrno = TSDB_CODE_INVALID_MSG_LEN; taosArrayDestroy(batchRsp); return -1; } @@ -310,7 +310,7 @@ int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) { if (offset >= pMsg->contLen) { qError("vnode offset %d is bigger than contLen %d", offset, pMsg->contLen); - terrno = TSDB_CODE_MSG_NOT_PROCESSED; + terrno = TSDB_CODE_INVALID_MSG_LEN; taosArrayDestroy(batchRsp); return -1; } @@ -320,7 +320,7 @@ int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) { if (offset >= pMsg->contLen) { qError("vnode offset %d is bigger than contLen %d", offset, pMsg->contLen); - terrno = TSDB_CODE_MSG_NOT_PROCESSED; + terrno = TSDB_CODE_INVALID_MSG_LEN; taosArrayDestroy(batchRsp); return -1; } @@ -362,6 +362,7 @@ int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) { offset = 0; if (rspSize > MAX_META_BATCH_RSP_SIZE) { + qError("rspSize:%d overload", rspSize); code = TSDB_CODE_INVALID_MSG_LEN; goto _exit; } @@ -414,9 +415,11 @@ _exit: } int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) { + SSyncState state = syncGetState(pVnode->sync); + pLoad->vgId = TD_VID(pVnode); - pLoad->syncState = syncGetMyRole(pVnode->sync); - pLoad->syncRestore = pVnode->restored; + pLoad->syncState = state.state; + pLoad->syncRestore = state.restored; pLoad->cacheUsage = tsdbCacheGetUsage(pVnode); pLoad->numOfTables = metaGetTbNum(pVnode->pMeta); pLoad->numOfTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta); diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index c8089ead9963d76ca6a39aa3c4d883f3f3b86806..688335454791c456b8d417d5b81dd5ab57530c68 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -173,7 +173,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp int32_t ret; if (!pVnode->inUse) { - terrno = TSDB_CODE_VND_NOT_SYNCED; + terrno = TSDB_CODE_VND_NO_AVAIL_BUFPOOL; vError("vgId:%d, not ready to write since %s", TD_VID(pVnode), terrstr()); return -1; } @@ -228,38 +228,33 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp if (vnodeProcessBatchDeleteReq(pVnode, version, pReq, len, pRsp) < 0) goto _err; break; /* TQ */ - case TDMT_VND_MQ_VG_CHANGE: - if (tqProcessVgChangeReq(pVnode->pTq, version, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), - pMsg->contLen - sizeof(SMsgHead)) < 0) { + case TDMT_VND_TMQ_SUBSCRIBE: + if (tqProcessSubscribeReq(pVnode->pTq, version, pReq, len) < 0) { goto _err; } break; - case TDMT_VND_MQ_VG_DELETE: - if (tqProcessVgDeleteReq(pVnode->pTq, version, pMsg->pCont, pMsg->contLen) < 0) { + case TDMT_VND_TMQ_DELETE_SUB: + if (tqProcessDeleteSubReq(pVnode->pTq, version, pMsg->pCont, pMsg->contLen) < 0) { goto _err; } break; - case TDMT_VND_MQ_COMMIT_OFFSET: - if (tqProcessOffsetCommitReq(pVnode->pTq, version, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), - pMsg->contLen - sizeof(SMsgHead)) < 0) { + case TDMT_VND_TMQ_COMMIT_OFFSET: + if (tqProcessOffsetCommitReq(pVnode->pTq, version, pReq, pMsg->contLen - sizeof(SMsgHead)) < 0) { goto _err; } break; - case TDMT_VND_ADD_CHECK_INFO: - if (tqProcessAddCheckInfoReq(pVnode->pTq, version, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), - pMsg->contLen - sizeof(SMsgHead)) < 0) { + case TDMT_VND_TMQ_ADD_CHECKINFO: + if (tqProcessAddCheckInfoReq(pVnode->pTq, version, pReq, len) < 0) { goto _err; } break; - case TDMT_VND_DELETE_CHECK_INFO: - if (tqProcessDelCheckInfoReq(pVnode->pTq, version, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), - pMsg->contLen - sizeof(SMsgHead)) < 0) { + case TDMT_VND_TMQ_DEL_CHECKINFO: + if (tqProcessDelCheckInfoReq(pVnode->pTq, version, pReq, len) < 0) { goto _err; } break; case TDMT_STREAM_TASK_DEPLOY: { - if (tqProcessTaskDeployReq(pVnode->pTq, version, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)), - pMsg->contLen - sizeof(SMsgHead)) < 0) { + if (tqProcessTaskDeployReq(pVnode->pTq, version, pReq, len) < 0) { goto _err; } } break; @@ -268,6 +263,16 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp goto _err; } } break; + case TDMT_VND_STREAM_RECOVER_STEP2: { + if (tqProcessTaskRecover2Req(pVnode->pTq, version, pMsg->pCont, pMsg->contLen) < 0) { + goto _err; + } + } break; + case TDMT_STREAM_TASK_CHECK_RSP: { + if (tqProcessStreamTaskCheckRsp(pVnode->pTq, version, pReq, len) < 0) { + goto _err; + } + } break; case TDMT_VND_ALTER_CONFIRM: vnodeProcessAlterConfirmReq(pVnode, version, pReq, len, pRsp); break; @@ -280,11 +285,12 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp case TDMT_VND_COMMIT: goto _do_commit; default: - ASSERT(0); - break; + vError("vgId:%d, unprocessed msg, %d", TD_VID(pVnode), pMsg->msgType); + return -1; } - vTrace("vgId:%d, process %s request success, index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), version); + vTrace("vgId:%d, process %s request, code:0x%x index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), pRsp->code, + version); walApplyVer(pVnode->pWal, version); @@ -323,12 +329,13 @@ int32_t vnodePreprocessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) { return 0; } - return qWorkerPreprocessQueryMsg(pVnode->pQuery, pMsg); + return qWorkerPreprocessQueryMsg(pVnode->pQuery, pMsg, TDMT_SCH_QUERY == pMsg->msgType); } int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) { vTrace("message in vnode query queue is processing"); - if ((pMsg->msgType == TDMT_SCH_QUERY) && !vnodeIsLeader(pVnode)) { + // if ((pMsg->msgType == TDMT_SCH_QUERY) && !vnodeIsLeader(pVnode)) { + if ((pMsg->msgType == TDMT_SCH_QUERY) && !syncIsReadyForRead(pVnode->sync)) { vnodeRedirectRpcMsg(pVnode, pMsg); return 0; } @@ -342,7 +349,7 @@ int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) { return qWorkerProcessCQueryMsg(&handle, pVnode->pQuery, pMsg, 0); default: vError("unknown msg type:%d in query queue", pMsg->msgType); - return TSDB_CODE_VND_APP_ERROR; + return TSDB_CODE_APP_ERROR; } } @@ -350,27 +357,25 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { vTrace("vgId:%d, msg:%p in fetch queue is processing", pVnode->config.vgId, pMsg); if ((pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_VND_TABLE_META || pMsg->msgType == TDMT_VND_TABLE_CFG || pMsg->msgType == TDMT_VND_BATCH_META) && - !vnodeIsLeader(pVnode)) { + !syncIsReadyForRead(pVnode->sync)) { + // !vnodeIsLeader(pVnode)) { vnodeRedirectRpcMsg(pVnode, pMsg); return 0; } - if (pMsg->msgType == TDMT_VND_CONSUME && !pVnode->restored) { + if (pMsg->msgType == TDMT_VND_TMQ_CONSUME && !pVnode->restored) { vnodeRedirectRpcMsg(pVnode, pMsg); return 0; } - char *msgstr = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)); - int32_t msgLen = pMsg->contLen - sizeof(SMsgHead); - switch (pMsg->msgType) { case TDMT_SCH_FETCH: case TDMT_SCH_MERGE_FETCH: return qWorkerProcessFetchMsg(pVnode, pVnode->pQuery, pMsg, 0); case TDMT_SCH_FETCH_RSP: return qWorkerProcessRspMsg(pVnode, pVnode->pQuery, pMsg, 0); - case TDMT_SCH_CANCEL_TASK: - return qWorkerProcessCancelMsg(pVnode, pVnode->pQuery, pMsg, 0); + // case TDMT_SCH_CANCEL_TASK: + // return qWorkerProcessCancelMsg(pVnode, pVnode->pQuery, pMsg, 0); case TDMT_SCH_DROP_TASK: return qWorkerProcessDropMsg(pVnode, pVnode->pQuery, pMsg, 0); case TDMT_SCH_QUERY_HEARTBEAT: @@ -381,26 +386,31 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { return vnodeGetTableCfg(pVnode, pMsg, true); case TDMT_VND_BATCH_META: return vnodeGetBatchMeta(pVnode, pMsg); - case TDMT_VND_CONSUME: + case TDMT_VND_TMQ_CONSUME: return tqProcessPollReq(pVnode->pTq, pMsg); case TDMT_STREAM_TASK_RUN: return tqProcessTaskRunReq(pVnode->pTq, pMsg); +#if 1 case TDMT_STREAM_TASK_DISPATCH: - // return tqProcessTaskDispatchReq(pVnode->pTq, pMsg, pInfo->workerId != 0); return tqProcessTaskDispatchReq(pVnode->pTq, pMsg, true); - /*case TDMT_STREAM_TASK_RECOVER:*/ - /*return tqProcessTaskRecoverReq(pVnode->pTq, pMsg);*/ - case TDMT_STREAM_RETRIEVE: - return tqProcessTaskRetrieveReq(pVnode->pTq, pMsg); +#endif + case TDMT_STREAM_TASK_CHECK: + return tqProcessStreamTaskCheckReq(pVnode->pTq, pMsg); case TDMT_STREAM_TASK_DISPATCH_RSP: return tqProcessTaskDispatchRsp(pVnode->pTq, pMsg); - /*case TDMT_STREAM_TASK_RECOVER_RSP:*/ - /*return tqProcessTaskRecoverRsp(pVnode->pTq, pMsg);*/ + case TDMT_STREAM_RETRIEVE: + return tqProcessTaskRetrieveReq(pVnode->pTq, pMsg); case TDMT_STREAM_RETRIEVE_RSP: return tqProcessTaskRetrieveRsp(pVnode->pTq, pMsg); + case TDMT_VND_STREAM_RECOVER_STEP1: + return tqProcessTaskRecover1Req(pVnode->pTq, pMsg); + case TDMT_STREAM_RECOVER_FINISH: + return tqProcessTaskRecoverFinishReq(pVnode->pTq, pMsg); + case TDMT_STREAM_RECOVER_FINISH_RSP: + return tqProcessTaskRecoverFinishRsp(pVnode->pTq, pMsg); default: vError("unknown msg type:%d in fetch queue", pMsg->msgType); - return TSDB_CODE_VND_APP_ERROR; + return TSDB_CODE_APP_ERROR; } } @@ -766,7 +776,7 @@ static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t version, void *pReq /* code */ ret = metaDropTable(pVnode->pMeta, version, pDropTbReq, tbUids, &tbUid); if (ret < 0) { - if (pDropTbReq->igNotExists && terrno == TSDB_CODE_VND_TABLE_NOT_EXIST) { + if (pDropTbReq->igNotExists && terrno == TSDB_CODE_TDB_TABLE_NOT_EXIST) { dropTbRsp.code = TSDB_CODE_SUCCESS; } else { dropTbRsp.code = terrno; @@ -855,6 +865,7 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq SEncoder encoder = {0}; SArray *newTbUids = NULL; SVStatis statis = {0}; + bool tbCreated = false; terrno = TSDB_CODE_SUCCESS; pRsp->code = 0; @@ -888,11 +899,10 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq if (pBlock == NULL) break; SSubmitBlkRsp submitBlkRsp = {0}; + tbCreated = false; // create table for auto create table mode if (msgIter.schemaLen > 0) { - submitBlkRsp.hashMeta = 1; - tDecoderInit(&decoder, pBlock->data, msgIter.schemaLen); if (tDecodeSVCreateTbReq(&decoder, &createTbReq) < 0) { pRsp->code = TSDB_CODE_INVALID_MSG; @@ -929,11 +939,12 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq } taosArrayPush(newTbUids, &createTbReq.uid); - } - submitBlkRsp.uid = createTbReq.uid; - submitBlkRsp.tblFName = taosMemoryMalloc(strlen(pVnode->config.dbname) + strlen(createTbReq.name) + 2); - sprintf(submitBlkRsp.tblFName, "%s.%s", pVnode->config.dbname, createTbReq.name); + submitBlkRsp.uid = createTbReq.uid; + submitBlkRsp.tblFName = taosMemoryMalloc(strlen(pVnode->config.dbname) + strlen(createTbReq.name) + 2); + sprintf(submitBlkRsp.tblFName, "%s.%s", pVnode->config.dbname, createTbReq.name); + tbCreated = true; + } msgIter.uid = createTbReq.uid; if (createTbReq.type == TSDB_CHILD_TABLE) { @@ -947,9 +958,6 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq #endif tDecoderClear(&decoder); taosArrayDestroy(createTbReq.ctb.tagName); - } else { - submitBlkRsp.tblFName = taosMemoryMalloc(TSDB_TABLE_FNAME_LEN); - sprintf(submitBlkRsp.tblFName, "%s.", pVnode->config.dbname); } if (tsdbInsertTableData(pVnode->pTsdb, version, &msgIter, pBlock, &submitBlkRsp) < 0) { @@ -958,7 +966,9 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq submitRsp.numOfRows += submitBlkRsp.numOfRows; submitRsp.affectedRows += submitBlkRsp.affectedRows; - taosArrayPush(submitRsp.pArray, &submitBlkRsp); + if (tbCreated || submitBlkRsp.code) { + taosArrayPush(submitRsp.pArray, &submitBlkRsp); + } } if (taosArrayGetSize(newTbUids) > 0) { @@ -1159,14 +1169,28 @@ static int32_t vnodeProcessBatchDeleteReq(SVnode *pVnode, int64_t version, void tDecoderInit(&decoder, pReq, len); tDecodeSBatchDeleteReq(&decoder, &deleteReq); + SMetaReader mr = {0}; + metaReaderInit(&mr, pVnode->pMeta, 0); + int32_t sz = taosArrayGetSize(deleteReq.deleteReqs); for (int32_t i = 0; i < sz; i++) { SSingleDeleteReq *pOneReq = taosArrayGet(deleteReq.deleteReqs, i); - int32_t code = tsdbDeleteTableData(pVnode->pTsdb, version, deleteReq.suid, pOneReq->uid, pOneReq->ts, pOneReq->ts); - if (code) { - // TODO + char *name = pOneReq->tbname; + if (metaGetTableEntryByName(&mr, name) < 0) { + vDebug("stream delete msg, skip vgId:%d since no table: %s", pVnode->config.vgId, name); + continue; + } + + int64_t uid = mr.me.uid; + + int32_t code = tsdbDeleteTableData(pVnode->pTsdb, version, deleteReq.suid, uid, pOneReq->ts, pOneReq->ts); + if (code < 0) { + terrno = code; + vError("vgId:%d, delete error since %s, suid:%" PRId64 ", uid:%" PRId64 ", start ts:%" PRId64 ", end ts:%" PRId64, + TD_VID(pVnode), terrstr(), deleteReq.suid, uid, pOneReq->ts, pOneReq->ts); } } + metaReaderClear(&mr); taosArrayDestroy(deleteReq.deleteReqs); return 0; } diff --git a/source/dnode/vnode/src/vnd/vnodeSync.c b/source/dnode/vnode/src/vnd/vnodeSync.c index d3ae1015d007da53005bedb11f4b3677798744b2..38cb534d7f3e7f8343893db38b286b2da2eabdae 100644 --- a/source/dnode/vnode/src/vnd/vnodeSync.c +++ b/source/dnode/vnode/src/vnd/vnodeSync.c @@ -230,142 +230,27 @@ void vnodeApplyWriteMsg(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { } } -int32_t vnodeProcessSyncCtrlMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { - int32_t code = 0; +int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { const STraceId *trace = &pMsg->info.traceId; - - if (!syncEnvIsStart()) { - vGError("vgId:%d, msg:%p failed to process since sync env not start", pVnode->config.vgId, pMsg); - terrno = TSDB_CODE_APP_ERROR; - return -1; - } - - SSyncNode *pSyncNode = syncNodeAcquire(pVnode->sync); - if (pSyncNode == NULL) { - vGError("vgId:%d, msg:%p failed to process since invalid sync node", pVnode->config.vgId, pMsg); - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - return -1; - } - vGTrace("vgId:%d, sync msg:%p will be processed, type:%s", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType)); - if (pMsg->msgType == TDMT_SYNC_HEARTBEAT) { - SyncHeartbeat *pSyncMsg = syncHeartbeatFromRpcMsg2(pMsg); - code = syncNodeOnHeartbeat(pSyncNode, pSyncMsg); - syncHeartbeatDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_HEARTBEAT_REPLY) { - SyncHeartbeatReply *pSyncMsg = syncHeartbeatReplyFromRpcMsg2(pMsg); - code = syncNodeOnHeartbeatReply(pSyncNode, pSyncMsg); - syncHeartbeatReplyDestroy(pSyncMsg); - - } else { - vGError("vgId:%d, msg:%p failed to process since error msg type:%d", pVnode->config.vgId, pMsg, pMsg->msgType); - code = -1; + int32_t code = syncProcessMsg(pVnode->sync, pMsg); + if (code != 0) { + vGError("vgId:%d, failed to process sync msg:%p type:%s since %s", pVnode->config.vgId, pMsg, + TMSG_INFO(pMsg->msgType), terrstr()); } - vTrace("vgId:%d, sync msg:%p is processed, type:%s code:0x%x", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType), - code); - syncNodeRelease(pSyncNode); - if (code != 0 && terrno == 0) { - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - } return code; } -int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { - int32_t code = 0; - const STraceId *trace = &pMsg->info.traceId; - - if (!syncEnvIsStart()) { - vGError("vgId:%d, msg:%p failed to process since sync env not start", pVnode->config.vgId, pMsg); - terrno = TSDB_CODE_APP_ERROR; - return -1; - } - - SSyncNode *pSyncNode = syncNodeAcquire(pVnode->sync); - if (pSyncNode == NULL) { - vGError("vgId:%d, msg:%p failed to process since invalid sync node", pVnode->config.vgId, pMsg); - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; +static int32_t vnodeSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) { + if (pMsg == NULL || pMsg->pCont == NULL) { return -1; } - vGTrace("vgId:%d, sync msg:%p will be processed, type:%s", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType)); - - if (pMsg->msgType == TDMT_SYNC_TIMEOUT) { - SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnTimer(pSyncNode, pSyncMsg); - syncTimeoutDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_PING) { - SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnPingCb(pSyncNode, pSyncMsg); - syncPingDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) { - SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg); - syncPingReplyDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) { - SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnClientRequest(pSyncNode, pSyncMsg, NULL); - syncClientRequestDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) { - SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnRequestVote(pSyncNode, pSyncMsg); - syncRequestVoteDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) { - SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnRequestVoteReply(pSyncNode, pSyncMsg); - syncRequestVoteReplyDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) { - SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnAppendEntries(pSyncNode, pSyncMsg); - syncAppendEntriesDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) { - SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg); - ASSERT(pSyncMsg != NULL); - code = syncNodeOnAppendEntriesReply(pSyncNode, pSyncMsg); - syncAppendEntriesReplyDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) { - SyncSnapshotSend *pSyncMsg = syncSnapshotSendFromRpcMsg2(pMsg); - code = syncNodeOnSnapshot(pSyncNode, pSyncMsg); - syncSnapshotSendDestroy(pSyncMsg); - - } else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) { - SyncSnapshotRsp *pSyncMsg = syncSnapshotRspFromRpcMsg2(pMsg); - code = syncNodeOnSnapshotReply(pSyncNode, pSyncMsg); - syncSnapshotRspDestroy(pSyncMsg); - - } else { - vGError("vgId:%d, msg:%p failed to process since error msg type:%d", pVnode->config.vgId, pMsg, pMsg->msgType); - code = -1; - } - - vTrace("vgId:%d, sync msg:%p is processed, type:%s code:0x%x", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType), - code); - syncNodeRelease(pSyncNode); - if (code != 0 && terrno == 0) { - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - } - return code; -} - -static int32_t vnodeSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) { - if (msgcb == NULL) { + if (msgcb == NULL || msgcb->putToQueueFp == NULL) { + rpcFreeCont(pMsg->pCont); + pMsg->pCont = NULL; return -1; } @@ -378,7 +263,13 @@ static int32_t vnodeSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) { } static int32_t vnodeSyncEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) { - if (msgcb == NULL) { + if (pMsg == NULL || pMsg->pCont == NULL) { + return -1; + } + + if (msgcb == NULL || msgcb->putToQueueFp == NULL) { + rpcFreeCont(pMsg->pCont); + pMsg->pCont = NULL; return -1; } @@ -399,121 +290,78 @@ static int32_t vnodeSyncSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) { return code; } -static int32_t vnodeSyncGetSnapshot(SSyncFSM *pFsm, SSnapshot *pSnapshot) { +static int32_t vnodeSyncGetSnapshot(const SSyncFSM *pFsm, SSnapshot *pSnapshot) { vnodeGetSnapshot(pFsm->data, pSnapshot); return 0; } -static void vnodeSyncReconfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta *cbMeta) {} - -static void vnodeSyncCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { - if (cbMeta.isWeak == 0) { - SVnode *pVnode = pFsm->data; +static void vnodeSyncApplyMsg(const SSyncFSM *pFsm, const SRpcMsg *pMsg, const SFsmCbMeta *pMeta) { + SVnode *pVnode = pFsm->data; - if (cbMeta.code == 0) { - SRpcMsg rpcMsg = {.msgType = pMsg->msgType, .contLen = pMsg->contLen}; - rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen); - memcpy(rpcMsg.pCont, pMsg->pCont, pMsg->contLen); - syncGetAndDelRespRpc(pVnode->sync, cbMeta.seqNum, &rpcMsg.info); - rpcMsg.info.conn.applyIndex = cbMeta.index; - rpcMsg.info.conn.applyTerm = cbMeta.term; + if (pMeta->code == 0) { + SRpcMsg rpcMsg = {.msgType = pMsg->msgType, .contLen = pMsg->contLen}; + rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen); + memcpy(rpcMsg.pCont, pMsg->pCont, pMsg->contLen); + rpcMsg.info = pMsg->info; + rpcMsg.info.conn.applyIndex = pMeta->index; + rpcMsg.info.conn.applyTerm = pMeta->term; - vInfo("vgId:%d, commit-cb is excuted, fsm:%p, index:%" PRId64 ", term:%" PRIu64 ", msg-index:%" PRId64 + const STraceId *trace = &pMsg->info.traceId; + vGTrace("vgId:%d, commit-cb is excuted, fsm:%p, index:%" PRId64 ", term:%" PRIu64 ", msg-index:%" PRId64 ", weak:%d, code:%d, state:%d %s, type:%s", - syncGetVgId(pVnode->sync), pFsm, cbMeta.index, cbMeta.term, rpcMsg.info.conn.applyIndex, cbMeta.isWeak, - cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), TMSG_INFO(pMsg->msgType)); + pVnode->config.vgId, pFsm, pMeta->index, pMeta->term, rpcMsg.info.conn.applyIndex, pMeta->isWeak, + pMeta->code, pMeta->state, syncStr(pMeta->state), TMSG_INFO(pMsg->msgType)); - tmsgPutToQueue(&pVnode->msgCb, APPLY_QUEUE, &rpcMsg); - } else { - SRpcMsg rsp = {.code = cbMeta.code, .info = pMsg->info}; - vError("vgId:%d, commit-cb execute error, type:%s, index:%" PRId64 ", error:0x%x %s", syncGetVgId(pVnode->sync), - TMSG_INFO(pMsg->msgType), cbMeta.index, cbMeta.code, tstrerror(cbMeta.code)); - if (rsp.info.handle != NULL) { - tmsgSendRsp(&rsp); - } + tmsgPutToQueue(&pVnode->msgCb, APPLY_QUEUE, &rpcMsg); + } else { + SRpcMsg rsp = {.code = pMeta->code, .info = pMsg->info}; + vError("vgId:%d, commit-cb execute error, type:%s, index:%" PRId64 ", error:0x%x %s", pVnode->config.vgId, + TMSG_INFO(pMsg->msgType), pMeta->index, pMeta->code, tstrerror(pMeta->code)); + if (rsp.info.handle != NULL) { + tmsgSendRsp(&rsp); } } } -static void vnodeSyncPreCommitMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { - if (cbMeta.isWeak == 1) { - SVnode *pVnode = pFsm->data; - vTrace("vgId:%d, pre-commit-cb is excuted, fsm:%p, index:%" PRId64 ", weak:%d, code:%d, state:%d %s, type:%s", - syncGetVgId(pVnode->sync), pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, - syncUtilState2String(cbMeta.state), TMSG_INFO(pMsg->msgType)); - - if (cbMeta.code == 0) { - SRpcMsg rpcMsg = {.msgType = pMsg->msgType, .contLen = pMsg->contLen}; - rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen); - memcpy(rpcMsg.pCont, pMsg->pCont, pMsg->contLen); - syncGetAndDelRespRpc(pVnode->sync, cbMeta.seqNum, &rpcMsg.info); - rpcMsg.info.conn.applyIndex = cbMeta.index; - rpcMsg.info.conn.applyTerm = cbMeta.term; - tmsgPutToQueue(&pVnode->msgCb, APPLY_QUEUE, &rpcMsg); - } else { - SRpcMsg rsp = {.code = cbMeta.code, .info = pMsg->info}; - vError("vgId:%d, pre-commit-cb execute error, type:%s, error:0x%x %s", syncGetVgId(pVnode->sync), - TMSG_INFO(pMsg->msgType), cbMeta.code, tstrerror(cbMeta.code)); - if (rsp.info.handle != NULL) { - tmsgSendRsp(&rsp); - } - } +static void vnodeSyncCommitMsg(const SSyncFSM *pFsm, const SRpcMsg *pMsg, const SFsmCbMeta *pMeta) { + if (pMeta->isWeak == 0) { + vnodeSyncApplyMsg(pFsm, pMsg, pMeta); + } +} + +static void vnodeSyncPreCommitMsg(const SSyncFSM *pFsm, const SRpcMsg *pMsg, const SFsmCbMeta *pMeta) { + if (pMeta->isWeak == 1) { + vnodeSyncApplyMsg(pFsm, pMsg, pMeta); } } -static void vnodeSyncRollBackMsg(SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { +static void vnodeSyncRollBackMsg(const SSyncFSM *pFsm, const SRpcMsg *pMsg, const SFsmCbMeta *pMeta) { SVnode *pVnode = pFsm->data; vTrace("vgId:%d, rollback-cb is excuted, fsm:%p, index:%" PRId64 ", weak:%d, code:%d, state:%d %s, type:%s", - syncGetVgId(pVnode->sync), pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, - syncUtilState2String(cbMeta.state), TMSG_INFO(pMsg->msgType)); + pVnode->config.vgId, pFsm, pMeta->index, pMeta->isWeak, pMeta->code, pMeta->state, syncStr(pMeta->state), + TMSG_INFO(pMsg->msgType)); } -#define USE_TSDB_SNAPSHOT - -static int32_t vnodeSnapshotStartRead(struct SSyncFSM *pFsm, void *pParam, void **ppReader) { -#ifdef USE_TSDB_SNAPSHOT +static int32_t vnodeSnapshotStartRead(const SSyncFSM *pFsm, void *pParam, void **ppReader) { SVnode *pVnode = pFsm->data; SSnapshotParam *pSnapshotParam = pParam; int32_t code = vnodeSnapReaderOpen(pVnode, pSnapshotParam->start, pSnapshotParam->end, (SVSnapReader **)ppReader); return code; -#else - *ppReader = taosMemoryMalloc(32); - return 0; -#endif } -static int32_t vnodeSnapshotStopRead(struct SSyncFSM *pFsm, void *pReader) { -#ifdef USE_TSDB_SNAPSHOT +static int32_t vnodeSnapshotStopRead(const SSyncFSM *pFsm, void *pReader) { SVnode *pVnode = pFsm->data; int32_t code = vnodeSnapReaderClose(pReader); return code; -#else - taosMemoryFree(pReader); - return 0; -#endif } -static int32_t vnodeSnapshotDoRead(struct SSyncFSM *pFsm, void *pReader, void **ppBuf, int32_t *len) { -#ifdef USE_TSDB_SNAPSHOT +static int32_t vnodeSnapshotDoRead(const SSyncFSM *pFsm, void *pReader, void **ppBuf, int32_t *len) { SVnode *pVnode = pFsm->data; int32_t code = vnodeSnapRead(pReader, (uint8_t **)ppBuf, len); return code; -#else - static int32_t times = 0; - if (times++ < 5) { - *len = 64; - *ppBuf = taosMemoryMalloc(*len); - snprintf(*ppBuf, *len, "snapshot block %d", times); - } else { - *len = 0; - *ppBuf = NULL; - } - return 0; -#endif } -static int32_t vnodeSnapshotStartWrite(struct SSyncFSM *pFsm, void *pParam, void **ppWriter) { -#ifdef USE_TSDB_SNAPSHOT +static int32_t vnodeSnapshotStartWrite(const SSyncFSM *pFsm, void *pParam, void **ppWriter) { SVnode *pVnode = pFsm->data; SSnapshotParam *pSnapshotParam = pParam; @@ -530,14 +378,9 @@ static int32_t vnodeSnapshotStartWrite(struct SSyncFSM *pFsm, void *pParam, void int32_t code = vnodeSnapWriterOpen(pVnode, pSnapshotParam->start, pSnapshotParam->end, (SVSnapWriter **)ppWriter); return code; -#else - *ppWriter = taosMemoryMalloc(32); - return 0; -#endif } -static int32_t vnodeSnapshotStopWrite(struct SSyncFSM *pFsm, void *pWriter, bool isApply, SSnapshot *pSnapshot) { -#ifdef USE_TSDB_SNAPSHOT +static int32_t vnodeSnapshotStopWrite(const SSyncFSM *pFsm, void *pWriter, bool isApply, SSnapshot *pSnapshot) { SVnode *pVnode = pFsm->data; vInfo("vgId:%d, stop write vnode snapshot, apply:%d, index:%" PRId64 " term:%" PRIu64 " config:%" PRId64, pVnode->config.vgId, isApply, pSnapshot->lastApplyIndex, pSnapshot->lastApplyTerm, pSnapshot->lastConfigIndex); @@ -545,27 +388,17 @@ static int32_t vnodeSnapshotStopWrite(struct SSyncFSM *pFsm, void *pWriter, bool int32_t code = vnodeSnapWriterClose(pWriter, !isApply, pSnapshot); vInfo("vgId:%d, apply vnode snapshot finished, code:0x%x", pVnode->config.vgId, code); return code; -#else - taosMemoryFree(pWriter); - return 0; -#endif } -static int32_t vnodeSnapshotDoWrite(struct SSyncFSM *pFsm, void *pWriter, void *pBuf, int32_t len) { -#ifdef USE_TSDB_SNAPSHOT +static int32_t vnodeSnapshotDoWrite(const SSyncFSM *pFsm, void *pWriter, void *pBuf, int32_t len) { SVnode *pVnode = pFsm->data; vDebug("vgId:%d, continue write vnode snapshot, len:%d", pVnode->config.vgId, len); int32_t code = vnodeSnapWrite(pWriter, pBuf, len); vDebug("vgId:%d, continue write vnode snapshot finished, len:%d", pVnode->config.vgId, len); return code; -#else - return 0; -#endif } -static void vnodeLeaderTransfer(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {} - -static void vnodeRestoreFinish(struct SSyncFSM *pFsm) { +static void vnodeRestoreFinish(const SSyncFSM *pFsm) { SVnode *pVnode = pFsm->data; do { @@ -585,11 +418,10 @@ static void vnodeRestoreFinish(struct SSyncFSM *pFsm) { vDebug("vgId:%d, sync restore finished", pVnode->config.vgId); } -static void vnodeBecomeFollower(struct SSyncFSM *pFsm) { +static void vnodeBecomeFollower(const SSyncFSM *pFsm) { SVnode *pVnode = pFsm->data; vDebug("vgId:%d, become follower", pVnode->config.vgId); - // clear old leader resource taosThreadMutexLock(&pVnode->lock); if (pVnode->blocked) { pVnode->blocked = false; @@ -599,18 +431,31 @@ static void vnodeBecomeFollower(struct SSyncFSM *pFsm) { taosThreadMutexUnlock(&pVnode->lock); } -static void vnodeBecomeLeader(struct SSyncFSM *pFsm) { +static void vnodeBecomeLeader(const SSyncFSM *pFsm) { SVnode *pVnode = pFsm->data; vDebug("vgId:%d, become leader", pVnode->config.vgId); +} -#if 0 - taosThreadMutexLock(&pVnode->lock); - if (pVnode->blocked) { - pVnode->blocked = false; - tsem_post(&pVnode->syncSem); +static bool vnodeApplyQueueEmpty(const SSyncFSM *pFsm) { + SVnode *pVnode = pFsm->data; + + if (pVnode != NULL && pVnode->msgCb.qsizeFp != NULL) { + int32_t itemSize = tmsgGetQueueSize(&pVnode->msgCb, pVnode->config.vgId, APPLY_QUEUE); + return (itemSize == 0); + } else { + return true; + } +} + +static int32_t vnodeApplyQueueItems(const SSyncFSM *pFsm) { + SVnode *pVnode = pFsm->data; + + if (pVnode != NULL && pVnode->msgCb.qsizeFp != NULL) { + int32_t itemSize = tmsgGetQueueSize(&pVnode->msgCb, pVnode->config.vgId, APPLY_QUEUE); + return itemSize; + } else { + return -1; } - taosThreadMutexUnlock(&pVnode->lock); -#endif } static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) { @@ -621,10 +466,12 @@ static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) { pFsm->FpRollBackCb = vnodeSyncRollBackMsg; pFsm->FpGetSnapshotInfo = vnodeSyncGetSnapshot; pFsm->FpRestoreFinishCb = vnodeRestoreFinish; - pFsm->FpLeaderTransferCb = vnodeLeaderTransfer; + pFsm->FpLeaderTransferCb = NULL; + pFsm->FpApplyQueueEmptyCb = vnodeApplyQueueEmpty; + pFsm->FpApplyQueueItems = vnodeApplyQueueItems; pFsm->FpBecomeLeaderCb = vnodeBecomeLeader; pFsm->FpBecomeFollowerCb = vnodeBecomeFollower; - pFsm->FpReConfigCb = vnodeSyncReconfig; + pFsm->FpReConfigCb = NULL; pFsm->FpSnapshotStartRead = vnodeSnapshotStartRead; pFsm->FpSnapshotStopRead = vnodeSnapshotStopRead; pFsm->FpSnapshotDoRead = vnodeSnapshotDoRead; @@ -642,10 +489,13 @@ int32_t vnodeSyncOpen(SVnode *pVnode, char *path) { .vgId = pVnode->config.vgId, .syncCfg = pVnode->config.syncCfg, .pWal = pVnode->pWal, - .msgcb = NULL, - .FpSendMsg = vnodeSyncSendMsg, - .FpEqMsg = vnodeSyncEqMsg, - .FpEqCtrlMsg = vnodeSyncEqCtrlMsg, + .msgcb = &pVnode->msgCb, + .syncSendMSg = vnodeSyncSendMsg, + .syncEqMsg = vnodeSyncEqMsg, + .syncEqCtrlMsg = vnodeSyncEqCtrlMsg, + .pingMs = 5000, + .electMs = 4000, + .heartbeatMs = 700, }; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", path, TD_DIRSEP); @@ -664,29 +514,47 @@ int32_t vnodeSyncOpen(SVnode *pVnode, char *path) { return -1; } - setPingTimerMS(pVnode->sync, 5000); - setElectTimerMS(pVnode->sync, 4000); - setHeartbeatTimerMS(pVnode->sync, 700); return 0; } void vnodeSyncStart(SVnode *pVnode) { - vDebug("vgId:%d, start sync", pVnode->config.vgId); - syncSetMsgCb(pVnode->sync, &pVnode->msgCb); + vInfo("vgId:%d, start sync", pVnode->config.vgId); syncStart(pVnode->sync); } +void vnodeSyncPreClose(SVnode *pVnode) { + vInfo("vgId:%d, pre close sync", pVnode->config.vgId); + syncLeaderTransfer(pVnode->sync); + syncPreStop(pVnode->sync); + taosThreadMutexLock(&pVnode->lock); + if (pVnode->blocked) { + vInfo("vgId:%d, post block after close sync", pVnode->config.vgId); + pVnode->blocked = false; + tsem_post(&pVnode->syncSem); + } + taosThreadMutexUnlock(&pVnode->lock); +} + void vnodeSyncClose(SVnode *pVnode) { - vDebug("vgId:%d, close sync", pVnode->config.vgId); + vInfo("vgId:%d, close sync", pVnode->config.vgId); syncStop(pVnode->sync); } -bool vnodeIsRoleLeader(SVnode *pVnode) { return syncGetMyRole(pVnode->sync) == TAOS_SYNC_STATE_LEADER; } +bool vnodeIsRoleLeader(SVnode *pVnode) { + SSyncState state = syncGetState(pVnode->sync); + return state.state == TAOS_SYNC_STATE_LEADER; +} bool vnodeIsLeader(SVnode *pVnode) { - if (!syncIsReady(pVnode->sync)) { - vDebug("vgId:%d, vnode not ready, state:%s, restore:%d", pVnode->config.vgId, syncGetMyRoleStr(pVnode->sync), - syncRestoreFinish(pVnode->sync)); + SSyncState state = syncGetState(pVnode->sync); + + if (state.state != TAOS_SYNC_STATE_LEADER || !state.restored) { + if (state.state != TAOS_SYNC_STATE_LEADER) { + terrno = TSDB_CODE_SYN_NOT_LEADER; + } else { + terrno = TSDB_CODE_APP_NOT_READY; + } + vDebug("vgId:%d, vnode not ready, state:%s, restore:%d", pVnode->config.vgId, syncStr(state.state), state.restored); return false; } diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index 0786321686a5ae6f5b7f7937f4c5ec425f6d6c31..4d3a3a1ab41ea01090ff7a350f7d9638978de1a3 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -33,6 +33,7 @@ extern "C" { #define CTG_DEFAULT_MAX_RETRY_TIMES 3 #define CTG_DEFAULT_BATCH_NUM 64 #define CTG_DEFAULT_FETCH_NUM 8 +#define CTG_MAX_COMMAND_LEN 512 #define CTG_RENT_SLOT_SECOND 1.5 @@ -223,6 +224,7 @@ typedef struct SCtgUserAuth { typedef struct SCatalog { uint64_t clusterId; + bool stopUpdate; SHashObj* userCache; // key:user, value:SCtgUserAuth SHashObj* dbCache; // key:dbname, value:SCtgDBCache SCtgRentMgmt dbRent; @@ -536,7 +538,8 @@ typedef struct SCtgOperation { (sizeof(STableMeta) + ((pMeta)->tableInfo.numOfTags + (pMeta)->tableInfo.numOfColumns) * sizeof(SSchema)) #define CTG_TABLE_NOT_EXIST(code) (code == CTG_ERR_CODE_TABLE_NOT_EXIST) -#define CTG_DB_NOT_EXIST(code) (code == TSDB_CODE_MND_DB_NOT_EXIST) +#define CTG_DB_NOT_EXIST(code) \ + (code == TSDB_CODE_MND_DB_NOT_EXIST || code == TSDB_CODE_MND_DB_IN_CREATING || code == TSDB_CODE_MND_DB_IN_DROPPING) #define ctgFatal(param, ...) qFatal("CTG:%p " param, pCtg, __VA_ARGS__) #define ctgError(param, ...) qError("CTG:%p " param, pCtg, __VA_ARGS__) @@ -671,7 +674,7 @@ void ctgdShowClusterCache(SCatalog* pCtg); int32_t ctgdShowCacheInfo(void); int32_t ctgRemoveTbMetaFromCache(SCatalog* pCtg, SName* pTableName, bool syncReq); -int32_t ctgGetTbMetaFromCache(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgTbMetaCtx* ctx, STableMeta** pTableMeta); +int32_t ctgGetTbMetaFromCache(SCatalog* pCtg, SCtgTbMetaCtx* ctx, STableMeta** pTableMeta); int32_t ctgGetTbMetasFromCache(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgTbMetasCtx* ctx, int32_t dbIdx, int32_t* fetchIdx, int32_t baseResIdx, SArray* pList); @@ -786,6 +789,7 @@ void ctgFreeTbCacheImpl(SCtgTbCache* pCache); int32_t ctgRemoveTbMeta(SCatalog* pCtg, SName* pTableName); int32_t ctgGetTbHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* pVgroup, bool* exists); SName* ctgGetFetchName(SArray* pNames, SCtgFetch* pFetch); +int32_t ctgdGetOneHandle(SCatalog **pHandle); extern SCatalogMgmt gCtgMgmt; extern SCtgDebug gCTGDebug; diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 8f621545c9b3800f7260fe29a58861cb7655acb2..1f87066c8258948ec92199e6786ed7c20698d283 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -202,7 +202,7 @@ int32_t ctgGetTbMeta(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgTbMetaCtx* ctx int32_t code = 0; STableMetaOutput* output = NULL; - CTG_ERR_RET(ctgGetTbMetaFromCache(pCtg, pConn, ctx, pTableMeta)); + CTG_ERR_RET(ctgGetTbMetaFromCache(pCtg, ctx, pTableMeta)); if (*pTableMeta || (ctx->flag & CTG_FLAG_ONLY_CACHE)) { goto _return; } @@ -320,7 +320,7 @@ _return: } int32_t ctgChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, const char* dbFName, AUTH_TYPE type, - bool* pass) { + bool* pass, bool* exists) { bool inCache = false; int32_t code = 0; @@ -329,6 +329,13 @@ int32_t ctgChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user, co CTG_ERR_RET(ctgChkAuthFromCache(pCtg, (char*)user, (char*)dbFName, type, &inCache, pass)); if (inCache) { + if (exists) { + *exists = true; + } + + return TSDB_CODE_SUCCESS; + } else if (exists) { + *exists = false; return TSDB_CODE_SUCCESS; } @@ -952,14 +959,14 @@ int32_t catalogGetTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SName CTG_API_LEAVE(ctgGetTbMeta(pCtg, pConn, &ctx, pTableMeta)); } -int32_t catalogGetCachedTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, STableMeta** pTableMeta) { +int32_t catalogGetCachedTableMeta(SCatalog* pCtg, const SName* pTableName, STableMeta** pTableMeta) { CTG_API_ENTER(); SCtgTbMetaCtx ctx = {0}; ctx.pName = (SName*)pTableName; ctx.flag = CTG_FLAG_UNKNOWN_STB | CTG_FLAG_ONLY_CACHE; - CTG_API_LEAVE(ctgGetTbMeta(pCtg, pConn, &ctx, pTableMeta)); + CTG_API_LEAVE(ctgGetTbMeta(pCtg, NULL, &ctx, pTableMeta)); } @@ -974,15 +981,14 @@ int32_t catalogGetSTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SNam CTG_API_LEAVE(ctgGetTbMeta(pCtg, pConn, &ctx, pTableMeta)); } -int32_t catalogGetCachedSTableMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, - STableMeta** pTableMeta) { +int32_t catalogGetCachedSTableMeta(SCatalog* pCtg, const SName* pTableName, STableMeta** pTableMeta) { CTG_API_ENTER(); SCtgTbMetaCtx ctx = {0}; ctx.pName = (SName*)pTableName; ctx.flag = CTG_FLAG_STB | CTG_FLAG_ONLY_CACHE; - CTG_API_LEAVE(ctgGetTbMeta(pCtg, pConn, &ctx, pTableMeta)); + CTG_API_LEAVE(ctgGetTbMeta(pCtg, NULL, &ctx, pTableMeta)); } @@ -1032,7 +1038,7 @@ int32_t catalogChkTbMetaVersion(SCatalog* pCtg, SRequestConnInfo* pConn, SArray* switch (tbType) { case TSDB_CHILD_TABLE: { SName stb = name; - strcpy(stb.tname, stbName); + tstrncpy(stb.tname, stbName, sizeof(stb.tname)); ctgRemoveTbMeta(pCtg, &stb); break; } @@ -1107,13 +1113,13 @@ int32_t catalogGetTableHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const CTG_API_LEAVE(ctgGetTbHashVgroup(pCtg, pConn, pTableName, pVgroup, NULL)); } -int32_t catalogGetCachedTableHashVgroup(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, - SVgroupInfo* pVgroup, bool* exists) { +int32_t catalogGetCachedTableHashVgroup(SCatalog* pCtg, const SName* pTableName, SVgroupInfo* pVgroup, bool* exists) { CTG_API_ENTER(); - CTG_API_LEAVE(ctgGetTbHashVgroup(pCtg, pConn, pTableName, pVgroup, exists)); + CTG_API_LEAVE(ctgGetTbHashVgroup(pCtg, NULL, pTableName, pVgroup, exists)); } +#if 0 int32_t catalogGetAllMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SCatalogReq* pReq, SMetaData* pRsp) { CTG_API_ENTER(); @@ -1176,6 +1182,7 @@ _return: CTG_API_LEAVE(code); } +#endif int32_t catalogAsyncGetAllMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SCatalogReq* pReq, catalogCallback fp, void* param, int64_t* jobId) { @@ -1371,13 +1378,30 @@ int32_t catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* user } int32_t code = 0; - CTG_ERR_JRET(ctgChkAuth(pCtg, pConn, user, dbFName, type, pass)); + CTG_ERR_JRET(ctgChkAuth(pCtg, pConn, user, dbFName, type, pass, NULL)); + +_return: + + CTG_API_LEAVE(code); +} + +int32_t catalogChkAuthFromCache(SCatalog* pCtg, const char* user, const char* dbFName, AUTH_TYPE type, + bool* pass, bool* exists) { + CTG_API_ENTER(); + + if (NULL == pCtg || NULL == user || NULL == dbFName || NULL == pass || NULL == exists) { + CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT); + } + + int32_t code = 0; + CTG_ERR_JRET(ctgChkAuth(pCtg, NULL, user, dbFName, type, pass, exists)); _return: CTG_API_LEAVE(code); } + int32_t catalogGetServerVersion(SCatalog* pCtg, SRequestConnInfo* pConn, char** pVersion) { CTG_API_ENTER(); diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c index 1f1a210699b8611f68bf3e0db410087cd4d2e949..b6018653060694d69b0a3381260f1c1c034ab9bd 100644 --- a/source/libs/catalog/src/ctgAsync.c +++ b/source/libs/catalog/src/ctgAsync.c @@ -1204,11 +1204,15 @@ int32_t ctgHandleGetTbMetasRsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBu stbCtx.flag = flag; stbCtx.pName = &stbName; - taosMemoryFreeClear(pOut->tbMeta); - CTG_ERR_JRET(ctgReadTbMetaFromCache(pCtg, &stbCtx, &pOut->tbMeta)); - if (pOut->tbMeta) { + STableMeta *stbMeta = NULL; + ctgReadTbMetaFromCache(pCtg, &stbCtx, &stbMeta); + if (stbMeta && stbMeta->sversion >= pOut->tbMeta->sversion) { ctgDebug("use cached stb meta, tbName:%s", tNameGetTableName(pName)); exist = 1; + } else { + ctgDebug("need to get/update stb meta, tbName:%s", tNameGetTableName(pName)); + taosMemoryFreeClear(pOut->tbMeta); + taosMemoryFreeClear(stbMeta); } } @@ -1641,7 +1645,7 @@ int32_t ctgLaunchGetTbMetaTask(SCtgTask* pTask) { pMsgCtx->pBatchs = pJob->pBatchs; } - CTG_ERR_RET(ctgGetTbMetaFromCache(pCtg, pConn, (SCtgTbMetaCtx*)pTask->taskCtx, (STableMeta**)&pTask->res)); + CTG_ERR_RET(ctgGetTbMetaFromCache(pCtg, (SCtgTbMetaCtx*)pTask->taskCtx, (STableMeta**)&pTask->res)); if (pTask->res) { CTG_ERR_RET(ctgHandleTaskEnd(pTask, 0)); return TSDB_CODE_SUCCESS; diff --git a/source/libs/catalog/src/ctgCache.c b/source/libs/catalog/src/ctgCache.c index ca562aee3e912b9fb4ed1633e8beed32da091e5d..51807a145a343c2fe9620ea2f11a95fe5cd97e33 100644 --- a/source/libs/catalog/src/ctgCache.c +++ b/source/libs/catalog/src/ctgCache.c @@ -248,6 +248,8 @@ int32_t ctgAcquireStbMetaFromCache(SCatalog *pCtg, char *dbFName, uint64_t suid, goto _return; } + taosHashRelease(dbCache->stbCache, stName); + CTG_LOCK(CTG_READ, &pCache->metaLock); if (NULL == pCache->pMeta) { ctgDebug("stb 0x%" PRIx64 " meta not in cache, dbFName:%s", suid, dbFName); @@ -621,14 +623,18 @@ int32_t ctgEnqueue(SCatalog *pCtg, SCtgCacheOperation *operation) { node->op = operation; CTG_LOCK(CTG_WRITE, &gCtgMgmt.queue.qlock); + if (gCtgMgmt.queue.stopQueue) { ctgFreeQNode(node); CTG_UNLOCK(CTG_WRITE, &gCtgMgmt.queue.qlock); CTG_RET(TSDB_CODE_CTG_EXIT); } - gCtgMgmt.queue.stopQueue = operation->stopQueue; + gCtgMgmt.queue.tail->next = node; gCtgMgmt.queue.tail = node; + + gCtgMgmt.queue.stopQueue = operation->stopQueue; + CTG_UNLOCK(CTG_WRITE, &gCtgMgmt.queue.qlock); ctgDebug("action [%s] added into queue", opName); @@ -1546,7 +1552,7 @@ int32_t ctgOpUpdateVgroup(SCtgCacheOperation *operation) { char *dbFName = msg->dbFName; SCatalog *pCtg = msg->pCtg; - if (NULL == dbInfo->vgHash) { + if (pCtg->stopUpdate || NULL == dbInfo->vgHash) { goto _return; } @@ -1616,6 +1622,10 @@ int32_t ctgOpDropDbCache(SCtgCacheOperation *operation) { SCtgDropDBMsg *msg = operation->data; SCatalog *pCtg = msg->pCtg; + if (pCtg->stopUpdate) { + goto _return; + } + SCtgDBCache *dbCache = NULL; ctgGetDBCache(msg->pCtg, msg->dbFName, &dbCache); if (NULL == dbCache) { @@ -1642,6 +1652,10 @@ int32_t ctgOpDropDbVgroup(SCtgCacheOperation *operation) { SCtgDropDbVgroupMsg *msg = operation->data; SCatalog *pCtg = msg->pCtg; + if (pCtg->stopUpdate) { + goto _return; + } + SCtgDBCache *dbCache = NULL; ctgGetDBCache(msg->pCtg, msg->dbFName, &dbCache); if (NULL == dbCache) { @@ -1671,6 +1685,10 @@ int32_t ctgOpUpdateTbMeta(SCtgCacheOperation *operation) { STableMetaOutput *pMeta = msg->pMeta; SCtgDBCache *dbCache = NULL; + if (pCtg->stopUpdate) { + goto _return; + } + if ((!CTG_IS_META_CTABLE(pMeta->metaType)) && NULL == pMeta->tbMeta) { ctgError("no valid tbmeta got from meta rsp, dbFName:%s, tbName:%s", pMeta->dbFName, pMeta->tbName); CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); @@ -1719,6 +1737,10 @@ int32_t ctgOpDropStbMeta(SCtgCacheOperation *operation) { SCtgDropStbMetaMsg *msg = operation->data; SCatalog *pCtg = msg->pCtg; + if (pCtg->stopUpdate) { + goto _return; + } + SCtgDBCache *dbCache = NULL; ctgGetDBCache(pCtg, msg->dbFName, &dbCache); if (NULL == dbCache) { @@ -1772,6 +1794,10 @@ int32_t ctgOpDropTbMeta(SCtgCacheOperation *operation) { SCtgDropTblMetaMsg *msg = operation->data; SCatalog *pCtg = msg->pCtg; + if (pCtg->stopUpdate) { + goto _return; + } + SCtgDBCache *dbCache = NULL; ctgGetDBCache(pCtg, msg->dbFName, &dbCache); if (NULL == dbCache) { @@ -1815,6 +1841,10 @@ int32_t ctgOpUpdateUser(SCtgCacheOperation *operation) { SCtgUpdateUserMsg *msg = operation->data; SCatalog *pCtg = msg->pCtg; + if (pCtg->stopUpdate) { + goto _return; + } + SCtgUserAuth *pUser = (SCtgUserAuth *)taosHashGet(pCtg->userCache, msg->userAuth.user, strlen(msg->userAuth.user)); if (NULL == pUser) { SCtgUserAuth userAuth = {0}; @@ -1868,8 +1898,12 @@ int32_t ctgOpUpdateEpset(SCtgCacheOperation *operation) { int32_t code = 0; SCtgUpdateEpsetMsg *msg = operation->data; SCatalog *pCtg = msg->pCtg; - SCtgDBCache *dbCache = NULL; + + if (pCtg->stopUpdate) { + goto _return; + } + CTG_ERR_JRET(ctgGetDBCache(pCtg, msg->dbFName, &dbCache)); if (NULL == dbCache) { ctgDebug("db %s not exist, ignore epset update", msg->dbFName); @@ -1916,6 +1950,10 @@ int32_t ctgOpUpdateTbIndex(SCtgCacheOperation *operation) { STableIndex *pIndex = msg->pIndex; SCtgDBCache *dbCache = NULL; + if (pCtg->stopUpdate) { + goto _return; + } + CTG_ERR_JRET(ctgGetAddDBCache(pCtg, pIndex->dbFName, 0, &dbCache)); CTG_ERR_JRET(ctgWriteTbIndexToCache(pCtg, dbCache, pIndex->dbFName, pIndex->tbName, &pIndex)); @@ -1938,6 +1976,10 @@ int32_t ctgOpDropTbIndex(SCtgCacheOperation *operation) { SCatalog *pCtg = msg->pCtg; SCtgDBCache *dbCache = NULL; + if (pCtg->stopUpdate) { + goto _return; + } + CTG_ERR_JRET(ctgGetDBCache(pCtg, msg->dbFName, &dbCache)); if (NULL == dbCache) { return TSDB_CODE_SUCCESS; @@ -1997,6 +2039,59 @@ _return: CTG_RET(code); } +void ctgFreeCacheOperationData(SCtgCacheOperation *op) { + if (NULL == op || NULL == op->data) { + return; + } + + switch (op->opId) { + case CTG_OP_UPDATE_VGROUP: { + SCtgUpdateVgMsg *msg = op->data; + ctgFreeVgInfo(msg->dbInfo); + taosMemoryFreeClear(op->data); + break; + } + case CTG_OP_UPDATE_TB_META: { + SCtgUpdateTbMetaMsg *msg = op->data; + taosMemoryFreeClear(msg->pMeta->tbMeta); + taosMemoryFreeClear(msg->pMeta); + taosMemoryFreeClear(op->data); + break; + } + case CTG_OP_DROP_DB_CACHE: + case CTG_OP_DROP_DB_VGROUP: + case CTG_OP_DROP_STB_META: + case CTG_OP_DROP_TB_META: + case CTG_OP_UPDATE_VG_EPSET: + case CTG_OP_DROP_TB_INDEX: + case CTG_OP_CLEAR_CACHE: { + taosMemoryFreeClear(op->data); + break; + } + case CTG_OP_UPDATE_USER: { + SCtgUpdateUserMsg *msg = op->data; + taosHashCleanup(msg->userAuth.createdDbs); + taosHashCleanup(msg->userAuth.readDbs); + taosHashCleanup(msg->userAuth.writeDbs); + taosMemoryFreeClear(op->data); + break; + } + case CTG_OP_UPDATE_TB_INDEX: { + SCtgUpdateTbIndexMsg *msg = op->data; + if (msg->pIndex) { + taosArrayDestroyEx(msg->pIndex->pIndex, tFreeSTableIndexInfo); + taosMemoryFreeClear(msg->pIndex); + } + taosMemoryFreeClear(op->data); + break; + } + default: { + qError("invalid cache op id:%d", op->opId); + break; + } + } +} + void ctgCleanupCacheQueue(void) { SCtgQNode *node = NULL; SCtgQNode *nodeNext = NULL; @@ -2015,7 +2110,7 @@ void ctgCleanupCacheQueue(void) { stopQueue = true; CTG_RT_STAT_INC(numOfOpDequeue, 1); } else { - taosMemoryFree(op->data); + ctgFreeCacheOperationData(op); CTG_RT_STAT_INC(numOfOpAbort, 1); } @@ -2053,7 +2148,7 @@ void *ctgUpdateThreadFunc(void *param) { qError("ctg tsem_wait failed, error:%s", tstrerror(TAOS_SYSTEM_ERROR(errno))); } - if (atomic_load_8((int8_t *)&gCtgMgmt.exit)) { + if (atomic_load_8((int8_t *)&gCtgMgmt.queue.stopQueue)) { ctgCleanupCacheQueue(); break; } @@ -2097,7 +2192,7 @@ int32_t ctgStartUpdateThread() { return TSDB_CODE_SUCCESS; } -int32_t ctgGetTbMetaFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbMetaCtx *ctx, STableMeta **pTableMeta) { +int32_t ctgGetTbMetaFromCache(SCatalog *pCtg, SCtgTbMetaCtx *ctx, STableMeta **pTableMeta) { if (IS_SYS_DBNAME(ctx->pName->dbname)) { CTG_FLAG_SET_SYS_DB(ctx->flag); } diff --git a/source/libs/catalog/src/ctgDbg.c b/source/libs/catalog/src/ctgDbg.c index dbca2ad9776b8b278f6795bebcca4423c55bcc99..26b5903bb0ffc3cfc4425f3f39262b88d45d373d 100644 --- a/source/libs/catalog/src/ctgDbg.c +++ b/source/libs/catalog/src/ctgDbg.c @@ -226,28 +226,45 @@ _return: CTG_RET(code); } -int32_t ctgdEnableDebug(char *option) { +int32_t ctgdEnableDebug(char *option, bool enable) { if (0 == strcasecmp(option, "lock")) { - gCTGDebug.lockEnable = true; - qDebug("lock debug enabled"); + gCTGDebug.lockEnable = enable; + qDebug("catalog lock debug set to %d", enable); return TSDB_CODE_SUCCESS; } if (0 == strcasecmp(option, "cache")) { - gCTGDebug.cacheEnable = true; - qDebug("cache debug enabled"); + gCTGDebug.cacheEnable = enable; + qDebug("catalog cache debug set to %d", enable); return TSDB_CODE_SUCCESS; } if (0 == strcasecmp(option, "api")) { - gCTGDebug.apiEnable = true; - qDebug("api debug enabled"); + gCTGDebug.apiEnable = enable; + qDebug("catalog api debug set to %d", enable); return TSDB_CODE_SUCCESS; } if (0 == strcasecmp(option, "meta")) { - gCTGDebug.metaEnable = true; - qDebug("api debug enabled"); + gCTGDebug.metaEnable = enable; + qDebug("catalog meta debug set to %d", enable); + return TSDB_CODE_SUCCESS; + } + + if (0 == strcasecmp(option, "stopUpdate")) { + SCatalog *pCtg = NULL; + + void *pIter = taosHashIterate(gCtgMgmt.pCluster, NULL); + while (pIter) { + pCtg = *(SCatalog **)pIter; + + pCtg->stopUpdate = enable; + + pIter = taosHashIterate(gCtgMgmt.pCluster, pIter); + } + + qDebug("catalog stopUpdate set to %d", enable); + return TSDB_CODE_SUCCESS; } @@ -256,6 +273,77 @@ int32_t ctgdEnableDebug(char *option) { return TSDB_CODE_CTG_INTERNAL_ERROR; } +int32_t ctgdHandleDbgCommand(char *command) { + if (NULL == command) { + CTG_RET(TSDB_CODE_INVALID_PARA); + } + + if (strlen(command) > CTG_MAX_COMMAND_LEN) { + CTG_RET(TSDB_CODE_INVALID_PARA); + } + + char *dup = strdup(command); + char *option = NULL; + char *param = NULL; + + int32_t i = 0; + bool newItem = true; + while (*(dup + i)) { + if (isspace(*(dup + i))) { + *(dup + i) = 0; + ++i; + newItem = true; + continue; + } + + if (!newItem) { + ++i; + continue; + } + + newItem = false; + if (NULL == option) { + option = dup + i; + ++i; + continue; + } + + if (NULL == param) { + param = dup + i; + ++i; + continue; + } + + taosMemoryFree(dup); + CTG_RET(TSDB_CODE_INVALID_PARA); + } + + bool enable = atoi(param); + + int32_t code = ctgdEnableDebug(option, enable); + + taosMemoryFree(dup); + + CTG_RET(code); +} + +int32_t ctgdGetOneHandle(SCatalog **pHandle) { + SCatalog *pCtg = NULL; + + void *pIter = taosHashIterate(gCtgMgmt.pCluster, NULL); + while (pIter) { + pCtg = *(SCatalog **)pIter; + + taosHashCancelIterate(gCtgMgmt.pCluster, pIter); + break; + } + + *pHandle = pCtg; + + return TSDB_CODE_SUCCESS; +} + + int32_t ctgdGetStatNum(char *option, void *res) { if (0 == strcasecmp(option, "runtime.numOfOpDequeue")) { *(uint64_t *)res = atomic_load_64(&gCtgMgmt.stat.runtime.numOfOpDequeue); diff --git a/source/libs/catalog/src/ctgUtil.c b/source/libs/catalog/src/ctgUtil.c index 4a64a8666eabf645d09753ab404c34e2167f7df4..3d21bbbcd9a2060d71d81193f37fc68e9bf6bd26 100644 --- a/source/libs/catalog/src/ctgUtil.c +++ b/source/libs/catalog/src/ctgUtil.c @@ -924,6 +924,11 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SCtgTaskReq* tReq, SDBVgInfo* if (1 == vgNum) { void* pIter = taosHashIterate(dbInfo->vgHash, NULL); + if (NULL == pIter) { + ctgError("empty vgHash, db:%s, vgroup number:%d", dbFName, vgNum); + CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); + } + for (int32_t i = 0; i < tbNum; ++i) { vgInfo = taosMemoryMalloc(sizeof(SVgroupInfo)); if (NULL == vgInfo) { diff --git a/source/libs/catalog/test/CMakeLists.txt b/source/libs/catalog/test/CMakeLists.txt index b8d50b9c636cf1125cb291f7c05bddb2c37e9fa1..dbbb24ce0b5e8b3ac37b212d88b49d2766bf78ca 100644 --- a/source/libs/catalog/test/CMakeLists.txt +++ b/source/libs/catalog/test/CMakeLists.txt @@ -18,8 +18,8 @@ IF(NOT TD_DARWIN) PRIVATE "${TD_SOURCE_DIR}/source/libs/catalog/inc" ) - #add_test( - # NAME catalogTest - # COMMAND catalogTest - #) + add_test( + NAME catalogTest + COMMAND catalogTest + ) ENDIF() diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index cbfe342c8ae5697d92e092a861b955875969fe94..ebf7c7baebfe4fd8105412d8e4b0fa780ad60377 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -27,8 +27,8 @@ #ifdef WINDOWS #define TD_USE_WINSOCK #endif -#include "catalog.h" #include "catalogInt.h" +#include "catalog.h" #include "os.h" #include "stub.h" #include "taos.h" @@ -41,7 +41,6 @@ namespace { extern "C" int32_t ctgdGetClusterCacheNum(struct SCatalog *pCatalog, int32_t type); -extern "C" int32_t ctgdEnableDebug(char *option); extern "C" int32_t ctgdGetStatNum(char *option, void *res); void ctgTestSetRspTableMeta(); @@ -49,7 +48,7 @@ void ctgTestSetRspCTableMeta(); void ctgTestSetRspSTableMeta(); void ctgTestSetRspMultiSTableMeta(); -// extern "C" SCatalogMgmt gCtgMgmt; +extern int32_t clientConnRefPool; enum { CTGT_RSP_VGINFO = 1, @@ -57,6 +56,15 @@ enum { CTGT_RSP_CTBMETA, CTGT_RSP_STBMETA, CTGT_RSP_MSTBMETA, + CTGT_RSP_INDEXINFO_E, + CTGT_RSP_USERAUTH, + CTGT_RSP_TBLCFG, + CTGT_RSP_TBLINDEX, + CTGT_RSP_DBCFG, + CTGT_RSP_QNODELIST, + CTGT_RSP_UDF, + CTGT_RSP_SVRVER, + CTGT_RSP_DNODElIST, CTGT_RSP_TBMETA_NOT_EXIST, }; @@ -72,6 +80,10 @@ int32_t ctgTestVgVersion = 1; int32_t ctgTestVgNum = 10; int32_t ctgTestColNum = 2; int32_t ctgTestTagNum = 1; +int32_t ctgTestQnodeNum = 3; +int32_t ctgTestIndexNum = 3; +int32_t ctgTestFuncNum = 2; +int32_t ctgTestFuncType = 3; int32_t ctgTestSVersion = 1; int32_t ctgTestTVersion = 1; int32_t ctgTestSuid = 2; @@ -83,6 +95,7 @@ char *ctgTestDbname = "1.db1"; char *ctgTestTablename = "table1"; char *ctgTestCTablename = "ctable1"; char *ctgTestSTablename = "stable1"; +char *ctgTestUsername = "user1"; char *ctgTestCurrentCTableName = NULL; char *ctgTestCurrentTableName = NULL; char *ctgTestCurrentSTableName = NULL; @@ -139,10 +152,10 @@ void ctgTestInitLogFile() { qDebugFlag = 159; strcpy(tsLogDir, TD_LOG_DIR_PATH); - ctgdEnableDebug("api"); - ctgdEnableDebug("meta"); - ctgdEnableDebug("cache"); - ctgdEnableDebug("lock"); + ctgdEnableDebug("api", true); + ctgdEnableDebug("meta", true); + ctgdEnableDebug("cache", true); + ctgdEnableDebug("lock", true); if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) { printf("failed to open log file in directory:%s\n", tsLogDir); @@ -284,6 +297,8 @@ void ctgTestBuildSTableMetaRsp(STableMetaRsp *rspMsg) { } void ctgTestRspDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + rpcFreeCont(pMsg->pCont); + SUseDbRsp usedbRsp = {0}; strcpy(usedbRsp.db, ctgTestDbname); usedbRsp.vgVersion = ctgTestVgVersion; @@ -310,6 +325,7 @@ void ctgTestRspDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg * strcpy(addr->fqdn, "a0"); addr->port = n + 22; } + vg.numOfTable = i % 2; taosArrayPush(usedbRsp.pVgroupInfos, &vg); } @@ -321,9 +337,13 @@ void ctgTestRspDbVgroups(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg * pRsp->code = 0; pRsp->contLen = contLen; pRsp->pCont = pReq; + + taosArrayDestroy(usedbRsp.pVgroupInfos); } void ctgTestRspTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + rpcFreeCont(pMsg->pCont); + STableMetaRsp metaRsp = {0}; strcpy(metaRsp.dbFName, ctgTestDbname); strcpy(metaRsp.tbName, ctgTestTablename); @@ -363,10 +383,14 @@ void ctgTestRspTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg * } void ctgTestRspTableMetaNotExist(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + rpcFreeCont(pMsg->pCont); + pRsp->code = CTG_ERR_CODE_TABLE_NOT_EXIST; } void ctgTestRspCTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + rpcFreeCont(pMsg->pCont); + STableMetaRsp metaRsp = {0}; strcpy(metaRsp.dbFName, ctgTestDbname); strcpy(metaRsp.tbName, ctgTestCurrentCTableName ? ctgTestCurrentCTableName : ctgTestCTablename); @@ -413,6 +437,8 @@ void ctgTestRspCTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg } void ctgTestRspSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + rpcFreeCont(pMsg->pCont); + STableMetaRsp metaRsp = {0}; strcpy(metaRsp.dbFName, ctgTestDbname); strcpy(metaRsp.tbName, ctgTestCurrentSTableName ? ctgTestCurrentSTableName : ctgTestSTablename); @@ -459,6 +485,8 @@ void ctgTestRspSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg } void ctgTestRspMultiSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + rpcFreeCont(pMsg->pCont); + static int32_t idx = 1; STableMetaRsp metaRsp = {0}; @@ -508,6 +536,234 @@ void ctgTestRspMultiSTableMeta(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRp tFreeSTableMetaRsp(&metaRsp); } + +void ctgTestRspErrIndexInfo(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + rpcFreeCont(pMsg->pCont); + + pRsp->code = TSDB_CODE_MND_DB_INDEX_NOT_EXIST; + pRsp->contLen = 0; + pRsp->pCont = NULL; +} + + +void ctgTestRspUserAuth(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + rpcFreeCont(pMsg->pCont); + + SGetUserAuthRsp userRsp = {0}; + strcpy(userRsp.user, ctgTestUsername); + userRsp.version = 1; + userRsp.superAuth = 1; + + int32_t contLen = tSerializeSGetUserAuthRsp(NULL, 0, &userRsp); + void *pReq = rpcMallocCont(contLen); + tSerializeSGetUserAuthRsp(pReq, contLen, &userRsp); + + pRsp->code = 0; + pRsp->contLen = contLen; + pRsp->pCont = pReq; +} + +void ctgTestRspTableCfg(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + rpcFreeCont(pMsg->pCont); + + static int32_t idx = 1; + + STableCfgRsp tblRsp = {0}; + strcpy(tblRsp.tbName, ctgTestTablename); + tblRsp.numOfColumns = ctgTestColNum; + + tblRsp.pSchemas = (SSchema *)taosMemoryMalloc((tblRsp.numOfTags + tblRsp.numOfColumns) * sizeof(SSchema)); + + SSchema *s = NULL; + s = &tblRsp.pSchemas[0]; + s->type = TSDB_DATA_TYPE_TIMESTAMP; + s->colId = 1; + s->bytes = 8; + strcpy(s->name, "ts"); + + s = &tblRsp.pSchemas[1]; + s->type = TSDB_DATA_TYPE_INT; + s->colId = 2; + s->bytes = 4; + strcpy(s->name, "col1"); + + int32_t contLen = tSerializeSTableCfgRsp(NULL, 0, &tblRsp); + void *pReq = rpcMallocCont(contLen); + tSerializeSTableCfgRsp(pReq, contLen, &tblRsp); + + pRsp->code = 0; + pRsp->contLen = contLen; + pRsp->pCont = pReq; + + tFreeSTableCfgRsp(&tblRsp); +} + +void ctgTestRspTableIndex(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + rpcFreeCont(pMsg->pCont); + + static int32_t idx = 1; + + STableIndexRsp tblRsp = {0}; + strcpy(tblRsp.tbName, ctgTestSTablename); + + tblRsp.pIndex = taosArrayInit(ctgTestIndexNum, sizeof(STableIndexInfo)); + + STableIndexInfo info = {0}; + for (int32_t i = 0; i < ctgTestIndexNum; ++i) { + info.interval = 1 + i; + info.expr = (char*)taosMemoryCalloc(1, 10); + taosArrayPush(tblRsp.pIndex, &info); + } + + int32_t contLen = tSerializeSTableIndexRsp(NULL, 0, &tblRsp); + void *pReq = rpcMallocCont(contLen); + tSerializeSTableIndexRsp(pReq, contLen, &tblRsp); + + pRsp->code = 0; + pRsp->contLen = contLen; + pRsp->pCont = pReq; + + tFreeSTableIndexRsp(&tblRsp); +} + +void ctgTestRspDBCfg(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + rpcFreeCont(pMsg->pCont); + + static int32_t idx = 1; + + SDbCfgRsp dbRsp = {0}; + dbRsp.numOfVgroups = ctgTestVgNum; + + int32_t contLen = tSerializeSDbCfgRsp(NULL, 0, &dbRsp); + void *pReq = rpcMallocCont(contLen); + tSerializeSDbCfgRsp(pReq, contLen, &dbRsp); + + pRsp->code = 0; + pRsp->contLen = contLen; + pRsp->pCont = pReq; +} + +void ctgTestRspQnodeList(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + rpcFreeCont(pMsg->pCont); + + SQnodeListRsp qlistRsp = {0}; + qlistRsp.qnodeList = taosArrayInit(10, sizeof(SQueryNodeLoad)); + for (int32_t i = 0; i < ctgTestQnodeNum; ++i) { + SQueryNodeLoad nodeLoad = {0}; + nodeLoad.addr.nodeId = i; + + (void)taosArrayPush(qlistRsp.qnodeList, &nodeLoad); + } + + int32_t rspLen = tSerializeSQnodeListRsp(NULL, 0, &qlistRsp); + void *pReq = rpcMallocCont(rspLen); + tSerializeSQnodeListRsp(pReq, rspLen, &qlistRsp); + + pRsp->code = 0; + pRsp->contLen = rspLen; + pRsp->pCont = pReq; + + tFreeSQnodeListRsp(&qlistRsp); +} + +void ctgTestRspUdfInfo(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + rpcFreeCont(pMsg->pCont); + + SRetrieveFuncRsp funcRsp = {0}; + funcRsp.numOfFuncs = 1; + funcRsp.pFuncInfos = taosArrayInit(1, sizeof(SFuncInfo)); + SFuncInfo funcInfo = {0}; + strcpy(funcInfo.name, "func1"); + funcInfo.funcType = ctgTestFuncType; + + (void)taosArrayPush(funcRsp.pFuncInfos, &funcInfo); + + int32_t rspLen = tSerializeSRetrieveFuncRsp(NULL, 0, &funcRsp); + void *pReq = rpcMallocCont(rspLen); + tSerializeSRetrieveFuncRsp(pReq, rspLen, &funcRsp); + + pRsp->code = 0; + pRsp->contLen = rspLen; + pRsp->pCont = pReq; + + tFreeSRetrieveFuncRsp(&funcRsp); +} + +void ctgTestRspSvrVer(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + rpcFreeCont(pMsg->pCont); + + SServerVerRsp verRsp = {0}; + strcpy(verRsp.ver, "1.0"); + + int32_t rspLen = tSerializeSServerVerRsp(NULL, 0, &verRsp); + void *pReq = rpcMallocCont(rspLen); + tSerializeSServerVerRsp(pReq, rspLen, &verRsp); + + pRsp->code = 0; + pRsp->contLen = rspLen; + pRsp->pCont = pReq; +} + +void ctgTestRspDndeList(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + rpcFreeCont(pMsg->pCont); + + SDnodeListRsp dRsp = {0}; + dRsp.dnodeList = taosArrayInit(1, sizeof(SEpSet)); + SEpSet epSet = {0}; + epSet.numOfEps = 1; + tstrncpy(epSet.eps[0].fqdn, "localhost", TSDB_FQDN_LEN); + epSet.eps[0].port = 6030; + + (void)taosArrayPush(dRsp.dnodeList, &epSet); + + int32_t rspLen = tSerializeSDnodeListRsp(NULL, 0, &dRsp); + void *pReq = rpcMallocCont(rspLen); + tSerializeSDnodeListRsp(pReq, rspLen, &dRsp); + + pRsp->code = 0; + pRsp->contLen = rspLen; + pRsp->pCont = pReq; + + tFreeSDnodeListRsp(&dRsp); +} + + + +void ctgTestRspAuto(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { + switch (pMsg->msgType) { + case TDMT_MND_USE_DB: + ctgTestRspDbVgroups(shandle, pEpSet, pMsg, pRsp); + break; + case TDMT_VND_TABLE_CFG: + case TDMT_MND_TABLE_CFG: + ctgTestRspTableCfg(shandle, pEpSet, pMsg, pRsp); + break; + case TDMT_MND_GET_TABLE_INDEX: + ctgTestRspTableIndex(shandle, pEpSet, pMsg, pRsp); + break; + case TDMT_MND_GET_DB_CFG: + ctgTestRspDBCfg(shandle, pEpSet, pMsg, pRsp); + break; + case TDMT_MND_QNODE_LIST: + ctgTestRspQnodeList(shandle, pEpSet, pMsg, pRsp); + break; + case TDMT_MND_RETRIEVE_FUNC: + ctgTestRspUdfInfo(shandle, pEpSet, pMsg, pRsp); + break; + case TDMT_MND_SERVER_VERSION: + ctgTestRspSvrVer(shandle, pEpSet, pMsg, pRsp); + break; + case TDMT_MND_DNODE_LIST: + ctgTestRspDndeList(shandle, pEpSet, pMsg, pRsp); + break; + default: + break; + } + + return; +} + + void ctgTestRspByIdx(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp) { switch (ctgTestRspFunc[ctgTestRspIdx]) { case CTGT_RSP_VGINFO: @@ -525,10 +781,38 @@ void ctgTestRspByIdx(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pRsp case CTGT_RSP_MSTBMETA: ctgTestRspMultiSTableMeta(shandle, pEpSet, pMsg, pRsp); break; + case CTGT_RSP_INDEXINFO_E: + ctgTestRspErrIndexInfo(shandle, pEpSet, pMsg, pRsp); + break; + case CTGT_RSP_USERAUTH: + ctgTestRspUserAuth(shandle, pEpSet, pMsg, pRsp); + break; + case CTGT_RSP_TBLCFG: + ctgTestRspTableCfg(shandle, pEpSet, pMsg, pRsp); + break; case CTGT_RSP_TBMETA_NOT_EXIST: ctgTestRspTableMetaNotExist(shandle, pEpSet, pMsg, pRsp); break; + case CTGT_RSP_TBLINDEX: + ctgTestRspTableIndex(shandle, pEpSet, pMsg, pRsp); + break; + case CTGT_RSP_DBCFG: + ctgTestRspDBCfg(shandle, pEpSet, pMsg, pRsp); + break; + case CTGT_RSP_QNODELIST: + ctgTestRspQnodeList(shandle, pEpSet, pMsg, pRsp); + break; + case CTGT_RSP_UDF: + ctgTestRspUdfInfo(shandle, pEpSet, pMsg, pRsp); + break; + case CTGT_RSP_SVRVER: + ctgTestRspSvrVer(shandle, pEpSet, pMsg, pRsp); + break; + case CTGT_RSP_DNODElIST: + ctgTestRspDndeList(shandle, pEpSet, pMsg, pRsp); + break; default: + ctgTestRspAuto(shandle, pEpSet, pMsg, pRsp); break; } @@ -921,6 +1205,34 @@ void *ctgTestSetCtableMetaThread(void *param) { } +void ctgTestFetchRows(TAOS_RES *result, int32_t *rows) { + TAOS_ROW row; + int num_fields = taos_num_fields(result); + TAOS_FIELD *fields = taos_fetch_fields(result); + char temp[256]; + + // fetch the records row by row + while ((row = taos_fetch_row(result))) { + (*rows)++; + memset(temp, 0, sizeof(temp)); + taos_print_row(temp, row, fields, num_fields); + printf("\t[%s]\n", temp); + } +} + +void ctgTestExecQuery(TAOS * taos, char* sql, bool fetch, int32_t *rows) { + TAOS_RES *result = taos_query(taos, sql); + int code = taos_errno(result); + ASSERT_EQ(code, 0); + + if (fetch) { + ctgTestFetchRows(result, rows); + } + + taos_free_result(result); +} + + TEST(tableMeta, normalTable) { struct SCatalog *pCtg = NULL; SVgroupInfo vgInfo = {0}; @@ -950,10 +1262,24 @@ TEST(tableMeta, normalTable) { ASSERT_EQ(vgInfo.vgId, 8); ASSERT_EQ(vgInfo.epSet.numOfEps, 3); - while (0 == ctgdGetClusterCacheNum(pCtg, CTG_DBG_DB_NUM)) { - taosMsleep(50); + while (true) { + uint64_t n = 0; + ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n); + if (n != 1) { + taosMsleep(50); + } else { + break; + } } + memset(&vgInfo, 0, sizeof(vgInfo)); + bool exists = false; + code = catalogGetCachedTableHashVgroup(pCtg, &n, &vgInfo, &exists); + ASSERT_EQ(code, 0); + ASSERT_EQ(vgInfo.vgId, 8); + ASSERT_EQ(vgInfo.epSet.numOfEps, 3); + ASSERT_EQ(exists, true); + ctgTestSetRspTableMeta(); STableMeta *tableMeta = NULL; @@ -969,6 +1295,8 @@ TEST(tableMeta, normalTable) { ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); + taosMemoryFree(tableMeta); + while (true) { uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); if (0 == n) { @@ -990,6 +1318,20 @@ TEST(tableMeta, normalTable) { ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); + taosMemoryFree(tableMeta); + + tableMeta = NULL; + catalogGetCachedTableMeta(pCtg, &n, &tableMeta); + ASSERT_EQ(code, 0); + ASSERT_EQ(tableMeta->vgId, 8); + ASSERT_EQ(tableMeta->tableType, TSDB_NORMAL_TABLE); + ASSERT_EQ(tableMeta->sversion, ctgTestSVersion); + ASSERT_EQ(tableMeta->tversion, ctgTestTVersion); + ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum); + ASSERT_EQ(tableMeta->tableInfo.numOfTags, 0); + ASSERT_EQ(tableMeta->tableInfo.precision, 1); + ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); + SDbVgVersion *dbs = NULL; SSTableVersion *stb = NULL; uint32_t dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0; @@ -1026,7 +1368,6 @@ TEST(tableMeta, normalTable) { ASSERT_EQ(allStbNum, 0); catalogDestroy(); - memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); } TEST(tableMeta, childTableCase) { @@ -1064,6 +1405,8 @@ TEST(tableMeta, childTableCase) { ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); + taosMemoryFree(tableMeta); + while (true) { uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); if (0 == n) { @@ -1099,6 +1442,8 @@ TEST(tableMeta, childTableCase) { ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); + taosMemoryFree(tableMeta); + SDbVgVersion *dbs = NULL; SSTableVersion *stb = NULL; uint32_t dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0; @@ -1135,7 +1480,6 @@ TEST(tableMeta, childTableCase) { ASSERT_EQ(allStbNum, 1); catalogDestroy(); - memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); } TEST(tableMeta, superTableCase) { @@ -1173,6 +1517,8 @@ TEST(tableMeta, superTableCase) { ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); + taosMemoryFree(tableMeta); + while (true) { uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); if (0 == n) { @@ -1182,6 +1528,21 @@ TEST(tableMeta, superTableCase) { } } + tableMeta = NULL; + code = catalogGetCachedSTableMeta(pCtg, &n, &tableMeta); + ASSERT_EQ(code, 0); + ASSERT_EQ(tableMeta->vgId, 0); + ASSERT_EQ(tableMeta->tableType, TSDB_SUPER_TABLE); + ASSERT_EQ(tableMeta->sversion, ctgTestSVersion); + ASSERT_EQ(tableMeta->tversion, ctgTestTVersion); + ASSERT_EQ(tableMeta->uid, ctgTestSuid); + ASSERT_EQ(tableMeta->suid, ctgTestSuid); + ASSERT_EQ(tableMeta->tableInfo.numOfColumns, ctgTestColNum); + ASSERT_EQ(tableMeta->tableInfo.numOfTags, ctgTestTagNum); + ASSERT_EQ(tableMeta->tableInfo.precision, 1); + ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); + taosMemoryFree(tableMeta); + ctgTestSetRspCTableMeta(); tableMeta = NULL; @@ -1199,6 +1560,8 @@ TEST(tableMeta, superTableCase) { ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); + taosMemoryFree(tableMeta); + while (true) { uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); if (2 != n) { @@ -1220,6 +1583,8 @@ TEST(tableMeta, superTableCase) { ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); + taosMemoryFree(tableMeta); + SDbVgVersion *dbs = NULL; SSTableVersion *stb = NULL; uint32_t dbNum = 0, stbNum = 0, allDbNum = 0, allStbNum = 0; @@ -1257,7 +1622,6 @@ TEST(tableMeta, superTableCase) { ASSERT_EQ(allStbNum, 1); catalogDestroy(); - memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); } TEST(tableMeta, rmStbMeta) { @@ -1297,6 +1661,8 @@ TEST(tableMeta, rmStbMeta) { ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); + taosMemoryFree(tableMeta); + while (true) { uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); if (0 == n) { @@ -1326,7 +1692,6 @@ TEST(tableMeta, rmStbMeta) { ASSERT_EQ(ctgdGetClusterCacheNum(pCtg, CTG_DBG_STB_RENT_NUM), 0); catalogDestroy(); - memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); } TEST(tableMeta, updateStbMeta) { @@ -1416,7 +1781,36 @@ TEST(tableMeta, updateStbMeta) { taosMemoryFreeClear(tableMeta); catalogDestroy(); - memset(&gCtgMgmt.stat, 0, sizeof(gCtgMgmt.stat)); +} + +TEST(getIndexInfo, notExists) { + struct SCatalog *pCtg = NULL; + SRequestConnInfo connInfo = {0}; + SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo; + SVgroupInfo vgInfo = {0}; + SArray *vgList = NULL; + + ctgTestInitLogFile(); + + memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc)); + ctgTestRspIdx = 0; + ctgTestRspFunc[0] = CTGT_RSP_INDEXINFO_E; + + ctgTestSetRspByIdx(); + + initQueryModuleMsgHandle(); + + int32_t code = catalogInit(NULL); + ASSERT_EQ(code, 0); + + code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + SIndexInfo info; + code = catalogGetIndexMeta(pCtg, mockPointer, "index1", &info); + ASSERT_TRUE(code != 0); + + catalogDestroy(); } TEST(refreshGetMeta, normal2normal) { @@ -1496,7 +1890,6 @@ TEST(refreshGetMeta, normal2normal) { taosMemoryFreeClear(tableMeta); catalogDestroy(); - memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); } TEST(refreshGetMeta, normal2notexist) { @@ -1567,7 +1960,6 @@ TEST(refreshGetMeta, normal2notexist) { ASSERT_TRUE(tableMeta == NULL); catalogDestroy(); - memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); } TEST(refreshGetMeta, normal2child) { @@ -1649,7 +2041,6 @@ TEST(refreshGetMeta, normal2child) { taosMemoryFreeClear(tableMeta); catalogDestroy(); - memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); ctgTestCurrentCTableName = NULL; ctgTestCurrentSTableName = NULL; } @@ -1737,7 +2128,6 @@ TEST(refreshGetMeta, stable2child) { taosMemoryFreeClear(tableMeta); catalogDestroy(); - memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); ctgTestCurrentCTableName = NULL; ctgTestCurrentSTableName = NULL; } @@ -1824,7 +2214,6 @@ TEST(refreshGetMeta, stable2stable) { taosMemoryFreeClear(tableMeta); catalogDestroy(); - memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); ctgTestCurrentCTableName = NULL; ctgTestCurrentSTableName = NULL; } @@ -1911,7 +2300,6 @@ TEST(refreshGetMeta, child2stable) { taosMemoryFreeClear(tableMeta); catalogDestroy(); - memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); ctgTestCurrentCTableName = NULL; ctgTestCurrentSTableName = NULL; } @@ -1951,7 +2339,6 @@ TEST(tableDistVgroup, normalTable) { ASSERT_TRUE(code != 0); catalogDestroy(); - memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); } TEST(tableDistVgroup, childTableCase) { @@ -1990,7 +2377,6 @@ TEST(tableDistVgroup, childTableCase) { ASSERT_TRUE(code != 0); catalogDestroy(); - memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); } TEST(tableDistVgroup, superTableCase) { @@ -2037,8 +2423,9 @@ TEST(tableDistVgroup, superTableCase) { ASSERT_EQ(vgInfo->vgId, 3); ASSERT_EQ(vgInfo->epSet.numOfEps, 3); + taosArrayDestroy(vgList); + catalogDestroy(); - memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); } TEST(dbVgroup, getSetDbVgroupCase) { @@ -2077,6 +2464,8 @@ TEST(dbVgroup, getSetDbVgroupCase) { ASSERT_EQ(code, 0); ASSERT_EQ(taosArrayGetSize((const SArray *)vgList), ctgTestVgNum); + taosArrayDestroy(vgList); + while (true) { uint64_t n = 0; ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n); @@ -2094,6 +2483,15 @@ TEST(dbVgroup, getSetDbVgroupCase) { code = catalogGetTableDistVgInfo(pCtg, mockPointer, &n, &vgList); ASSERT_TRUE(code != 0); + int32_t dbVer = 0; + int64_t dbId = 0; + int32_t tbNum = 0; + code = catalogGetDBVgVersion(pCtg, ctgTestDbname, &dbVer, &dbId, &tbNum); + ASSERT_EQ(code, 0); + ASSERT_EQ(dbVer, ctgTestVgVersion); + ASSERT_EQ(dbId, ctgTestDbId); + ASSERT_EQ(tbNum, ctgTestVgNum / 2); + ctgTestBuildDBVgroup(&dbVgroup); code = catalogUpdateDBVgInfo(pCtg, ctgTestDbname, ctgTestDbId, dbVgroup); ASSERT_EQ(code, 0); @@ -2117,7 +2515,6 @@ TEST(dbVgroup, getSetDbVgroupCase) { ASSERT_TRUE(code != 0); catalogDestroy(); - memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); } TEST(multiThread, getSetRmSameDbVgroup) { @@ -2170,7 +2567,6 @@ TEST(multiThread, getSetRmSameDbVgroup) { taosSsleep(1); catalogDestroy(); - memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); } TEST(multiThread, getSetRmDiffDbVgroup) { @@ -2223,7 +2619,6 @@ TEST(multiThread, getSetRmDiffDbVgroup) { taosSsleep(1); catalogDestroy(); - memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); } TEST(multiThread, ctableMeta) { @@ -2275,7 +2670,6 @@ TEST(multiThread, ctableMeta) { taosSsleep(2); catalogDestroy(); - memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); } TEST(rentTest, allRent) { @@ -2323,6 +2717,8 @@ TEST(rentTest, allRent) { ASSERT_EQ(tableMeta->tableInfo.precision, 1); ASSERT_EQ(tableMeta->tableInfo.rowSize, 12); + taosMemoryFree(tableMeta); + while (ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM) < i) { taosMsleep(50); } @@ -2353,9 +2749,401 @@ TEST(rentTest, allRent) { } catalogDestroy(); - memset(&gCtgMgmt, 0, sizeof(gCtgMgmt)); } +TEST(apiTest, catalogRefreshDBVgInfo_test) { + struct SCatalog *pCtg = NULL; + SRequestConnInfo connInfo = {0}; + SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo; + + ctgTestInitLogFile(); + + memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc)); + ctgTestRspIdx = 0; + ctgTestRspFunc[0] = CTGT_RSP_VGINFO; + + ctgTestSetRspByIdx(); + + initQueryModuleMsgHandle(); + + int32_t code = catalogInit(NULL); + ASSERT_EQ(code, 0); + + code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + code = catalogRefreshDBVgInfo(pCtg, mockPointer, ctgTestDbname); + ASSERT_EQ(code, 0); + + catalogDestroy(); +} + +TEST(apiTest, catalogChkAuth_test) { + struct SCatalog *pCtg = NULL; + SRequestConnInfo connInfo = {0}; + SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo; + + ctgTestInitLogFile(); + + memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc)); + ctgTestRspIdx = 0; + ctgTestRspFunc[0] = CTGT_RSP_USERAUTH; + + ctgTestSetRspByIdx(); + + initQueryModuleMsgHandle(); + + int32_t code = catalogInit(NULL); + ASSERT_EQ(code, 0); + + code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + bool pass = false; + bool exists = false; + code = catalogChkAuthFromCache(pCtg, ctgTestUsername, ctgTestDbname, AUTH_TYPE_READ, &pass, &exists); + ASSERT_EQ(code, 0); + ASSERT_EQ(exists, false); + + code = catalogChkAuth(pCtg, mockPointer, ctgTestUsername, ctgTestDbname, AUTH_TYPE_READ, &pass); + ASSERT_EQ(code, 0); + ASSERT_EQ(pass, true); + + while (true) { + uint64_t n = 0; + ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n); + if (n != 1) { + taosMsleep(50); + } else { + break; + } + } + + code = catalogChkAuthFromCache(pCtg, ctgTestUsername, ctgTestDbname, AUTH_TYPE_READ, &pass, &exists); + ASSERT_EQ(code, 0); + ASSERT_EQ(pass, true); + ASSERT_EQ(exists, true); + + catalogDestroy(); +} + +TEST(apiTest, catalogRefreshGetTableCfg_test) { + struct SCatalog *pCtg = NULL; + SRequestConnInfo connInfo = {0}; + SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo; + + ctgTestInitLogFile(); + + memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc)); + ctgTestRspIdx = 0; + ctgTestRspFunc[0] = CTGT_RSP_VGINFO; + ctgTestRspFunc[1] = CTGT_RSP_TBMETA; + + ctgTestSetRspByIdx(); + + initQueryModuleMsgHandle(); + + int32_t code = catalogInit(NULL); + ASSERT_EQ(code, 0); + + code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; + strcpy(n.dbname, "db1"); + strcpy(n.tname, ctgTestTablename); + STableCfg *pCfg = NULL; + + code = catalogRefreshGetTableCfg(pCtg, mockPointer, &n, &pCfg); + ASSERT_EQ(code, 0); + ASSERT_TRUE(NULL != pCfg); + ASSERT_EQ(pCfg->numOfColumns, ctgTestColNum); + + tFreeSTableCfgRsp((STableCfgRsp *)pCfg); + taosMemoryFree(pCfg); + + catalogDestroy(); +} + +TEST(apiTest, catalogGetTableIndex_test) { + struct SCatalog *pCtg = NULL; + SRequestConnInfo connInfo = {0}; + SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo; + + ctgTestInitLogFile(); + + memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc)); + ctgTestRspIdx = 0; + ctgTestRspFunc[0] = CTGT_RSP_TBLINDEX; + + ctgTestSetRspByIdx(); + + initQueryModuleMsgHandle(); + + int32_t code = catalogInit(NULL); + ASSERT_EQ(code, 0); + + code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; + strcpy(n.dbname, "db1"); + strcpy(n.tname, ctgTestTablename); + SArray *pRes = NULL; + + code = catalogGetTableIndex(pCtg, mockPointer, &n, &pRes); + ASSERT_EQ(code, 0); + ASSERT_TRUE(NULL != pRes); + ASSERT_EQ(taosArrayGetSize(pRes), ctgTestIndexNum); + + taosArrayDestroyEx(pRes, tFreeSTableIndexInfo); + + catalogDestroy(); +} + +TEST(apiTest, catalogGetDBCfg_test) { + struct SCatalog *pCtg = NULL; + SRequestConnInfo connInfo = {0}; + SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo; + + ctgTestInitLogFile(); + + memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc)); + ctgTestRspIdx = 0; + ctgTestRspFunc[0] = CTGT_RSP_DBCFG; + + ctgTestSetRspByIdx(); + + initQueryModuleMsgHandle(); + + int32_t code = catalogInit(NULL); + ASSERT_EQ(code, 0); + + code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + SName n = {TSDB_TABLE_NAME_T, 1, {0}, {0}}; + strcpy(n.dbname, "db1"); + strcpy(n.tname, ctgTestTablename); + + SDbCfgInfo cfgInfo = {0}; + code = catalogGetDBCfg(pCtg, mockPointer, ctgTestDbname, &cfgInfo); + ASSERT_EQ(code, 0); + ASSERT_EQ(cfgInfo.numOfVgroups, ctgTestVgNum); + + catalogDestroy(); +} + +TEST(apiTest, catalogGetQnodeList_test) { + struct SCatalog *pCtg = NULL; + SRequestConnInfo connInfo = {0}; + SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo; + + ctgTestInitLogFile(); + + memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc)); + ctgTestRspIdx = 0; + ctgTestRspFunc[0] = CTGT_RSP_QNODELIST; + + ctgTestSetRspByIdx(); + + initQueryModuleMsgHandle(); + + int32_t code = catalogInit(NULL); + ASSERT_EQ(code, 0); + + code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + SArray *qnodeList = taosArrayInit(10, sizeof(SQueryNodeLoad)); + code = catalogGetQnodeList(pCtg, mockPointer, qnodeList); + ASSERT_EQ(code, 0); + ASSERT_EQ(taosArrayGetSize(qnodeList), ctgTestQnodeNum); + + for (int32_t i = 0; i < ctgTestQnodeNum; ++i) { + SQueryNodeLoad * pLoad = (SQueryNodeLoad *)taosArrayGet(qnodeList, i); + ASSERT_EQ(pLoad->addr.nodeId, i); + } + + catalogDestroy(); +} + + +TEST(apiTest, catalogGetUdfInfo_test) { + struct SCatalog *pCtg = NULL; + SRequestConnInfo connInfo = {0}; + SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo; + + ctgTestInitLogFile(); + + memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc)); + ctgTestRspIdx = 0; + ctgTestRspFunc[0] = CTGT_RSP_UDF; + + ctgTestSetRspByIdx(); + + initQueryModuleMsgHandle(); + + int32_t code = catalogInit(NULL); + ASSERT_EQ(code, 0); + + code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + SFuncInfo funcInfo = {0}; + code = catalogGetUdfInfo(pCtg, mockPointer, "func1", &funcInfo); + ASSERT_EQ(code, 0); + ASSERT_EQ(funcInfo.funcType, ctgTestFuncType); + + catalogDestroy(); +} + + +TEST(apiTest, catalogGetServerVersion_test) { + struct SCatalog *pCtg = NULL; + SRequestConnInfo connInfo = {0}; + SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo; + + ctgTestInitLogFile(); + + memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc)); + ctgTestRspIdx = 0; + ctgTestRspFunc[0] = CTGT_RSP_SVRVER; + + ctgTestSetRspByIdx(); + + initQueryModuleMsgHandle(); + + int32_t code = catalogInit(NULL); + ASSERT_EQ(code, 0); + + code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + char* ver = NULL; + code = catalogGetServerVersion(pCtg, mockPointer, &ver); + ASSERT_EQ(code, 0); + ASSERT_TRUE(0 == strcmp(ver, "1.0")); + + catalogDestroy(); +} + +TEST(apiTest, catalogUpdateTableIndex_test) { + struct SCatalog *pCtg = NULL; + SRequestConnInfo connInfo = {0}; + SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo; + + ctgTestInitLogFile(); + + memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc)); + ctgTestRspIdx = 0; + ctgTestRspFunc[0] = CTGT_RSP_SVRVER; + + ctgTestSetRspByIdx(); + + initQueryModuleMsgHandle(); + + int32_t code = catalogInit(NULL); + ASSERT_EQ(code, 0); + + code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + STableIndexRsp rsp = {0}; + strcpy(rsp.dbFName, ctgTestDbname); + strcpy(rsp.tbName, ctgTestSTablename); + rsp.suid = ctgTestSuid; + rsp.version = 1; + code = catalogUpdateTableIndex(pCtg, &rsp); + ASSERT_EQ(code, 0); + + catalogDestroy(); +} + + +TEST(apiTest, catalogGetDnodeList_test) { + struct SCatalog *pCtg = NULL; + SRequestConnInfo connInfo = {0}; + SRequestConnInfo *mockPointer = (SRequestConnInfo *)&connInfo; + + ctgTestInitLogFile(); + + memset(ctgTestRspFunc, 0, sizeof(ctgTestRspFunc)); + ctgTestRspIdx = 0; + ctgTestRspFunc[0] = CTGT_RSP_DNODElIST; + + ctgTestSetRspByIdx(); + + initQueryModuleMsgHandle(); + + int32_t code = catalogInit(NULL); + ASSERT_EQ(code, 0); + + code = catalogGetHandle(ctgTestClusterId, &pCtg); + ASSERT_EQ(code, 0); + + SArray* pList = NULL; + code = catalogGetDnodeList(pCtg, mockPointer, &pList); + ASSERT_EQ(code, 0); + ASSERT_EQ(taosArrayGetSize(pList), 1); + + taosArrayDestroy(pList); + + catalogDestroy(); +} + +#ifdef INTEGRATION_TEST +TEST(intTest, autoCreateTableTest) { + struct SCatalog *pCtg = NULL; + + TAOS *taos = taos_connect("localhost", "root", "taosdata", NULL, 0); + ASSERT_TRUE(NULL != taos); + + ctgdEnableDebug("api", true); + ctgdEnableDebug("meta", true); + ctgdEnableDebug("cache", true); + ctgdEnableDebug("lock", true); + + ctgTestExecQuery(taos, "drop database if exists db1", false, NULL); + ctgTestExecQuery(taos, "create database db1", false, NULL); + ctgTestExecQuery(taos, "create stable db1.st1 (ts timestamp, f1 int) tags(tg1 int)", false, NULL); + ctgTestExecQuery(taos, "insert into db1.tb1 using db1.st1 tags(1) values(now, 1)", false, NULL); + + ctgdGetOneHandle(&pCtg); + + while (true) { + uint32_t n = ctgdGetClusterCacheNum(pCtg, CTG_DBG_META_NUM); + if (2 != n) { + taosMsleep(50); + } else { + break; + } + } + + uint64_t n = 0, m = 0; + ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&n); + + ctgTestExecQuery(taos, "insert into db1.tb1 using db1.st1 tags(1) values(now, 2)", false, NULL); + + ctgTestExecQuery(taos, "insert into db1.tb1 values(now, 3)", false, NULL); + + taosMsleep(1000); + ctgdGetStatNum("runtime.numOfOpDequeue", (void *)&m); + + ASSERT_EQ(n, m); + + ctgdEnableDebug("stopUpdate", true); + ctgTestExecQuery(taos, "alter table db1.st1 add column f2 double", false, NULL); + + ctgdEnableDebug("stopUpdate", false); + + ctgTestExecQuery(taos, "insert into db1.tb1 (ts, f1) values(now, 4)", false, NULL); + + taos_close(taos); +} + +#endif + int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); diff --git a/source/libs/command/inc/commandInt.h b/source/libs/command/inc/commandInt.h index ce4c4cf09ba4c59c751f1d1c8c2dd028d60b7417..4d0c5389e145bc91ebe459f95d8a34fa5b1552df 100644 --- a/source/libs/command/inc/commandInt.h +++ b/source/libs/command/inc/commandInt.h @@ -96,6 +96,7 @@ extern "C" { #define COMMAND_RESET_LOG "resetLog" #define COMMAND_SCHEDULE_POLICY "schedulePolicy" #define COMMAND_ENABLE_RESCHEDULE "enableReSchedule" +#define COMMAND_CATALOG_DEBUG "catalogDebug" typedef struct SExplainGroup { int32_t nodeNum; diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 47a904bba210ef157b048515e4b0cb0528ae9f32..1c2d7e1f662129cfb103087a7f09c577b7bac22f 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -39,8 +39,7 @@ static int32_t buildRetrieveTableRsp(SSDataBlock* pBlock, int32_t numOfCols, SRe (*pRsp)->numOfRows = htonl(pBlock->info.rows); (*pRsp)->numOfCols = htonl(numOfCols); - int32_t len = 0; - blockEncode(pBlock, (*pRsp)->data, &len, numOfCols, false); + int32_t len = blockEncode(pBlock, (*pRsp)->data, numOfCols); ASSERT(len == rspSize - sizeof(SRetrieveTableRsp)); return TSDB_CODE_SUCCESS; @@ -571,6 +570,8 @@ static int32_t execAlterCmd(char* cmd, char* value, bool* processed) { code = schedulerUpdatePolicy(atoi(value)); } else if (0 == strcasecmp(cmd, COMMAND_ENABLE_RESCHEDULE)) { code = schedulerEnableReSchedule(atoi(value)); + } else if (0 == strcasecmp(cmd, COMMAND_CATALOG_DEBUG)) { + code = ctgdHandleDbgCommand(value); } else { goto _return; } diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 80a524496c2287a884e4f8b2bf4a2e4ea65c6974..915dc08c142bcff36e3e6b7fbc1306d3d3cb107f 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -1610,8 +1610,7 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) { rsp->completed = 1; rsp->numOfRows = htonl(rowNum); - int32_t len = 0; - blockEncode(pBlock, rsp->data, &len, taosArrayGetSize(pBlock->pDataBlock), 0); + int32_t len = blockEncode(pBlock, rsp->data, taosArrayGetSize(pBlock->pDataBlock)); ASSERT(len == rspSize - sizeof(SRetrieveTableRsp)); rsp->compLen = htonl(len); diff --git a/source/libs/executor/inc/executil.h b/source/libs/executor/inc/executil.h index 0cfef7dc24f2f56c82a408e85789d658ceae576a..fd8a357a8b50bfddc3346bb0f8a92b0712bfcd9f 100644 --- a/source/libs/executor/inc/executil.h +++ b/source/libs/executor/inc/executil.h @@ -23,12 +23,13 @@ #include "tpagedbuf.h" #include "tsimplehash.h" #include "vnode.h" +#include "executor.h" #define T_LONG_JMP(_obj, _c) \ do { \ ASSERT((_c) != -1); \ longjmp((_obj), (_c)); \ - } while (0); + } while (0) #define SET_RES_WINDOW_KEY(_k, _ori, _len, _uid) \ do { \ @@ -95,8 +96,25 @@ typedef struct SColMatchInfo { int32_t matchType; // determinate the source according to col id or slot id } SColMatchInfo; +typedef struct SExecTaskInfo SExecTaskInfo; +typedef struct STableListInfo STableListInfo; struct SqlFunctionCtx; +int32_t createScanTableListInfo(SScanPhysiNode* pScanNode, SNodeList* pGroupTags, bool groupSort, SReadHandle* pHandle, + STableListInfo* pTableListInfo, SNode* pTagCond, SNode* pTagIndexCond, SExecTaskInfo* pTaskInfo); + +STableListInfo* tableListCreate(); +void* tableListDestroy(STableListInfo* pTableListInfo); +void tableListClear(STableListInfo* pTableListInfo); +int32_t tableListGetOutputGroups(const STableListInfo* pTableList); +bool oneTableForEachGroup(const STableListInfo* pTableList); +uint64_t getTableGroupId(const STableListInfo* pTableList, uint64_t tableUid); +int32_t tableListAddTableInfo(STableListInfo* pTableList, uint64_t uid, uint64_t gid); +int32_t tableListGetGroupList(const STableListInfo* pTableList, int32_t ordinalIndex, STableKeyInfo** pKeyInfo, int32_t* num); +uint64_t tableListGetSize(const STableListInfo* pTableList); +uint64_t tableListGetSuid(const STableListInfo* pTableList); +STableKeyInfo* tableListGetInfo(const STableListInfo* pTableList, int32_t index); + size_t getResultRowSize(struct SqlFunctionCtx* pCtx, int32_t numOfOutput); void initResultRowInfo(SResultRowInfo* pResultRowInfo); void closeResultRow(SResultRow* pResultRow); @@ -109,6 +127,7 @@ static FORCE_INLINE SResultRow* getResultRowByPos(SDiskbasedBuf* pBuf, SResultRo if (forUpdate) { setBufPageDirty(bufPage, true); } + SResultRow* pRow = (SResultRow*)((char*)bufPage + pos->offset); return pRow; } @@ -124,10 +143,7 @@ int32_t getNumOfTotalRes(SGroupResInfo* pGroupResInfo); SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode); EDealRes doTranslateTagExpr(SNode** pNode, void* pContext); -int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, SNode* pTagCond, SNode* pTagIndexCond, - STableListInfo* pListInfo); int32_t getGroupIdFromTagsVal(void* pMeta, uint64_t uid, SNodeList* pGroupNode, char* keyBuf, uint64_t* pGroupId); -int32_t getColInfoResultForGroupby(void* metaHandle, SNodeList* group, STableListInfo* pTableListInfo); size_t getTableTagsBufLen(const SNodeList* pGroups); SArray* createSortInfo(SNodeList* pNodeList); @@ -150,9 +166,7 @@ int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableScanPhysi void cleanupQueryTableDataCond(SQueryTableDataCond* pCond); int32_t convertFillType(int32_t mode); - int32_t resultrowComparAsc(const void* p1, const void* p2); - int32_t isQualifiedTable(STableKeyInfo* info, SNode* pTagCond, void* metaHandle, bool* pQualified); #endif // TDENGINE_QUERYUTIL_H diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index e930620cb29a4ba02774422ef563498d472d3809..62146b60486de6854e7fa4732e570565dcd5b0b1 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -87,27 +87,12 @@ typedef struct SLimit { typedef struct STableScanAnalyzeInfo SFileBlockLoadRecorder; typedef struct STaskCostInfo { - int64_t created; - int64_t start; - uint64_t loadStatisTime; - uint64_t loadFileBlockTime; - uint64_t loadDataInCacheTime; - uint64_t loadStatisSize; - uint64_t loadFileBlockSize; - uint64_t loadDataInCacheSize; - - uint64_t loadDataTime; - - SFileBlockLoadRecorder* pRecoder; + int64_t created; + int64_t start; uint64_t elapsedTime; - - uint64_t winInfoSize; - uint64_t tableInfoSize; - uint64_t hashSize; - uint64_t numOfTimeWindows; - - SArray* queryProfEvents; // SArray - SHashObj* operatorProfResults; // map + double extractListTime; + double groupIdMapTime; + SFileBlockLoadRecorder* pRecoder; } STaskCostInfo; typedef struct SOperatorCostInfo { @@ -150,18 +135,13 @@ typedef struct { SSchemaWrapper* schema; char tbName[TSDB_TABLE_NAME_LEN]; - SSDataBlock* pullOverBlk; // for streaming - SWalFilterCond cond; - int64_t lastScanUid; int8_t recoverStep; SQueryTableDataCond tableCond; - int64_t recoverStartVer; - int64_t recoverEndVer; int64_t fillHistoryVer1; int64_t fillHistoryVer2; - int8_t triggerSaved; - int64_t deleteMarkSaved; + // int8_t triggerSaved; + // int64_t deleteMarkSaved; SStreamState* pState; } SStreamTaskInfo; @@ -184,7 +164,7 @@ typedef struct SExecTaskInfo { int64_t version; // used for stream to record wal version SStreamTaskInfo streamInfo; SSchemaInfo schemaInfo; - STableListInfo tableqinfoList; // this is a table list + STableListInfo* pTableInfoList; // this is a table list const char* sql; // query sql string jmp_buf env; // jump to this position when error happens. EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model] @@ -204,8 +184,7 @@ enum { typedef struct SOperatorFpSet { __optr_open_fn_t _openFn; // DO NOT invoke this function directly __optr_fn_t getNextFn; - __optr_fn_t getStreamResFn; // execute the aggregate in the stream model, todo remove it - __optr_fn_t cleanupFn; // call this function to release the allocated resources ASAP + __optr_fn_t cleanupFn; // call this function to release the allocated resources ASAP __optr_close_fn_t closeFn; __optr_encode_fn_t encodeResultRow; __optr_decode_fn_t decodeResultRow; @@ -271,10 +250,10 @@ typedef struct SLimitInfo { } SLimitInfo; typedef struct SExchangeInfo { - SArray* pSources; - SArray* pSourceDataInfo; - tsem_t ready; - void* pTransporter; + SArray* pSources; + SArray* pSourceDataInfo; + tsem_t ready; + void* pTransporter; // SArray, result block list, used to keep the multi-block that // passed by downstream operator SArray* pResultBlockList; @@ -285,6 +264,7 @@ typedef struct SExchangeInfo { SLoadRemoteDataInfo loadInfo; uint64_t self; SLimitInfo limitInfo; + int64_t openedTs; // start exec time stamp } SExchangeInfo; typedef struct SScanInfo { @@ -318,51 +298,55 @@ typedef struct { SExprSupp* pExprSup; // expr supporter of aggregate operator } SAggOptrPushDownInfo; -typedef struct STableScanInfo { - STsdbReader* dataReader; - SReadHandle readHandle; +typedef struct STableMetaCacheInfo { + SLRUCache* pTableMetaEntryCache; // 100 by default + uint64_t metaFetch; + uint64_t cacheHit; +} STableMetaCacheInfo; +typedef struct STableScanInfo { + STsdbReader* dataReader; + SReadHandle readHandle; + SLimitInfo limitInfo; SFileBlockLoadRecorder readRecorder; SScanInfo scanInfo; int32_t scanTimes; - SNode* pFilterNode; // filter info, which is push down by optimizer - - SSDataBlock* pResBlock; - SColMatchInfo matchInfo; - SExprSupp pseudoSup; - SQueryTableDataCond cond; - int32_t scanFlag; // table scan flag to denote if it is a repeat/reverse/main scan - int32_t dataBlockLoadFlag; - SSampleExecInfo sample; // sample execution info - int32_t currentGroupId; - int32_t currentTable; - int8_t scanMode; - int8_t noTable; - SAggOptrPushDownInfo pdInfo; - int8_t assignBlockUid; + SSDataBlock* pResBlock; + SColMatchInfo matchInfo; + SExprSupp pseudoSup; + SQueryTableDataCond cond; + int32_t scanFlag; // table scan flag to denote if it is a repeat/reverse/main scan + int32_t dataBlockLoadFlag; + SSampleExecInfo sample; // sample execution info + int32_t currentGroupId; + int32_t currentTable; + int8_t scanMode; + SAggOptrPushDownInfo pdInfo; + int8_t assignBlockUid; + STableMetaCacheInfo metaCache; } STableScanInfo; typedef struct STableMergeScanInfo { - STableListInfo* tableListInfo; - int32_t tableStartIndex; - int32_t tableEndIndex; - bool hasGroupId; - uint64_t groupId; - SArray* dataReaders; // array of tsdbReaderT* - SReadHandle readHandle; - int32_t bufPageSize; - uint32_t sortBufSize; // max buffer size for in-memory sort - SArray* pSortInfo; - SSortHandle* pSortHandle; - SSDataBlock* pSortInputBlock; - int64_t startTs; // sort start time - SArray* sortSourceParams; - + STableListInfo* tableListInfo; + int32_t tableStartIndex; + int32_t tableEndIndex; + bool hasGroupId; + uint64_t groupId; + SArray* queryConds; // array of queryTableDataCond + STsdbReader* pReader; + SReadHandle readHandle; + int32_t bufPageSize; + uint32_t sortBufSize; // max buffer size for in-memory sort + SArray* pSortInfo; + SSortHandle* pSortHandle; + SSDataBlock* pSortInputBlock; + int64_t startTs; // sort start time + SArray* sortSourceParams; + SLimitInfo limitInfo; SFileBlockLoadRecorder readRecorder; int64_t numOfRows; SScanInfo scanInfo; int32_t scanTimes; - SNode* pFilterNode; // filter info, which is push down by optimizer SqlFunctionCtx* pCtx; // which belongs to the direct upstream operator operator query context SResultRowInfo* pResultRowInfo; int32_t* rowEntryInfoOffset; @@ -374,6 +358,7 @@ typedef struct STableMergeScanInfo { SQueryTableDataCond cond; int32_t scanFlag; // table scan flag to denote if it is a repeat/reverse/main scan int32_t dataBlockLoadFlag; + // if the upstream is an interval operator, the interval info is also kept here to get the time // window to check if current data block needs to be loaded. SInterval interval; @@ -460,8 +445,10 @@ typedef struct SPartitionDataInfo { typedef struct STimeWindowAggSupp { int8_t calTrigger; - int64_t waterMark; + int8_t calTriggerSaved; int64_t deleteMark; + int64_t deleteMarkSaved; + int64_t waterMark; TSKEY maxTs; TSKEY minTs; SColumnInfoData timeWindowData; // query time window info for scalar function execution. @@ -477,7 +464,6 @@ typedef struct SStreamScanInfo { SReadHandle readHandle; SInterval interval; // if the upstream is an interval operator, the interval info is also kept here. SColMatchInfo matchInfo; - SNode* pCondition; SArray* pBlockLists; // multiple SSDatablock. SSDataBlock* pRes; // result SSDataBlock @@ -553,10 +539,10 @@ typedef struct SSysTableScanInfo { } SSysTableScanInfo; typedef struct SBlockDistInfo { - SSDataBlock* pResBlock; - void* pHandle; - SReadHandle readHandle; - uint64_t uid; // table uid + SSDataBlock* pResBlock; + STsdbReader* pHandle; + SReadHandle readHandle; + uint64_t uid; // table uid } SBlockDistInfo; // todo remove this @@ -567,7 +553,6 @@ typedef struct SOptrBasicInfo { } SOptrBasicInfo; typedef struct SIntervalAggOperatorInfo { - // SOptrBasicInfo should be first, SAggSupporter should be second for stream encode SOptrBasicInfo binfo; // basic info SAggSupporter aggSup; // aggregate supporter SExprSupp scalarSupp; // supporter for perform scalar function @@ -582,22 +567,18 @@ typedef struct SIntervalAggOperatorInfo { EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model] STimeWindowAggSupp twAggSup; SArray* pPrevValues; // SArray used to keep the previous not null value for interpolation. - SNode* pCondition; } SIntervalAggOperatorInfo; typedef struct SMergeAlignedIntervalAggOperatorInfo { SIntervalAggOperatorInfo* intervalAggOperatorInfo; - // bool hasGroupId; uint64_t groupId; // current groupId int64_t curTs; // current ts SSDataBlock* prefetchedBlock; - SNode* pCondition; SResultRow* pResultRow; } SMergeAlignedIntervalAggOperatorInfo; typedef struct SStreamIntervalOperatorInfo { - // SOptrBasicInfo should be first, SAggSupporter should be second for stream encode SOptrBasicInfo binfo; // basic info SAggSupporter aggSup; // aggregate supporter SExprSupp scalarSupp; // supporter for perform scalar function @@ -623,26 +604,21 @@ typedef struct SStreamIntervalOperatorInfo { } SStreamIntervalOperatorInfo; typedef struct SAggOperatorInfo { - // SOptrBasicInfo should be first, SAggSupporter should be second for stream encode - SOptrBasicInfo binfo; - SAggSupporter aggSup; - + SOptrBasicInfo binfo; + SAggSupporter aggSup; STableQueryInfo* current; uint64_t groupId; SGroupResInfo groupResInfo; SExprSupp scalarExprSup; - SNode* pCondition; } SAggOperatorInfo; typedef struct SProjectOperatorInfo { SOptrBasicInfo binfo; SAggSupporter aggSup; - SNode* pFilterNode; // filter info, which is push down by optimizer SArray* pPseudoColInfo; SLimitInfo limitInfo; bool mergeDataBlocks; SSDataBlock* pFinalRes; - SNode* pCondition; } SProjectOperatorInfo; typedef struct SIndefOperatorInfo { @@ -650,10 +626,8 @@ typedef struct SIndefOperatorInfo { SAggSupporter aggSup; SArray* pPseudoColInfo; SExprSupp scalarSup; - SNode* pCondition; uint64_t groupId; - - SSDataBlock* pNextGroupRes; + SSDataBlock* pNextGroupRes; } SIndefOperatorInfo; typedef struct SFillOperatorInfo { @@ -664,7 +638,6 @@ typedef struct SFillOperatorInfo { void** p; SSDataBlock* existNewGroupBlock; STimeWindow win; - SNode* pCondition; SColMatchInfo matchInfo; int32_t primaryTsCol; int32_t primarySrcSlotId; @@ -679,7 +652,6 @@ typedef struct SGroupbyOperatorInfo { SAggSupporter aggSup; SArray* pGroupCols; // group by columns, SArray SArray* pGroupColVals; // current group column values, SArray - SNode* pCondition; bool isInit; // denote if current val is initialized or not char* keyBuf; // group by keys for hash int32_t groupKeyLen; // total group by column width @@ -729,7 +701,6 @@ typedef struct SSessionAggOperatorInfo { int64_t gap; // session window gap int32_t tsSlotId; // primary timestamp slot id STimeWindowAggSupp twAggSup; - const SNode* pCondition; } SSessionAggOperatorInfo; typedef struct SResultWindowInfo { @@ -803,7 +774,6 @@ typedef struct SStreamFillOperatorInfo { SSDataBlock* pSrcDelBlock; int32_t srcDelRowIndex; SSDataBlock* pDelRes; - SNode* pCondition; SColMatchInfo matchInfo; int32_t primaryTsCol; int32_t primarySrcSlotId; @@ -840,7 +810,6 @@ typedef struct SStateWindowOperatorInfo { SStateKeys stateKey; int32_t tsSlotId; // primary timestamp column slot id STimeWindowAggSupp twAggSup; - const SNode* pCondition; } SStateWindowOperatorInfo; typedef struct SSortOperatorInfo { @@ -853,13 +822,8 @@ typedef struct SSortOperatorInfo { int64_t startTs; // sort start time uint64_t sortElapsed; // sort elapsed time, time to flush to disk not included. SLimitInfo limitInfo; - SNode* pCondition; } SSortOperatorInfo; -typedef struct STagFilterOperatorInfo { - SOptrBasicInfo binfo; -} STagFilterOperatorInfo; - typedef struct SJoinOperatorInfo { SSDataBlock* pRes; int32_t joinType; @@ -878,10 +842,8 @@ typedef struct SJoinOperatorInfo { #define OPTR_IS_OPENED(_optr) (((_optr)->status & OP_OPENED) == OP_OPENED) #define OPTR_SET_OPENED(_optr) ((_optr)->status |= OP_OPENED) -void doDestroyExchangeOperatorInfo(void* param); - -SOperatorFpSet createOperatorFpSet(__optr_open_fn_t openFn, __optr_fn_t nextFn, __optr_fn_t streamFn, - __optr_fn_t cleanup, __optr_close_fn_t closeFn, __optr_explain_fn_t explain); +SOperatorFpSet createOperatorFpSet(__optr_open_fn_t openFn, __optr_fn_t nextFn, __optr_fn_t cleanup, + __optr_close_fn_t closeFn, __optr_explain_fn_t explain); int32_t operatorDummyOpenFn(SOperatorInfo* pOperator); int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t num); @@ -903,6 +865,7 @@ void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SG int32_t handleLimitOffset(SOperatorInfo* pOperator, SLimitInfo* pLimitInfo, SSDataBlock* pBlock, bool holdDataInBuf); bool hasLimitOffsetInfo(SLimitInfo* pLimitInfo); void initLimitInfo(const SNode* pLimit, const SNode* pSLimit, SLimitInfo* pLimitInfo); +void applyLimitOffset(SLimitInfo* pLimitInfo, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo, SOperatorInfo* pOperator); void doApplyFunctions(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, SColumnInfoData* pTimeWindowData, int32_t offset, int32_t forwardStep, int32_t numOfTotal, int32_t numOfOutput); @@ -916,14 +879,18 @@ STimeWindow getFirstQualifiedTimeWindow(int64_t ts, STimeWindow* pWindow, SInter int32_t getTableScanInfo(SOperatorInfo* pOperator, int32_t* order, int32_t* scanFlag); int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* defaultBufsz); -void doSetOperatorCompleted(SOperatorInfo* pOperator); -void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock, SColMatchInfo* pColMatchInfo, SFilterInfo* pFilterInfo); -int32_t addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int32_t numOfPseudoExpr, - SSDataBlock* pBlock, const char* idStr); +void doDestroyExchangeOperatorInfo(void* param); + +void setOperatorCompleted(SOperatorInfo* pOperator); +void setOperatorInfo(SOperatorInfo* pOperator, const char* name, int32_t type, bool blocking, int32_t status, void* pInfo, + SExecTaskInfo* pTaskInfo); +void doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo); +int32_t addTagPseudoColumnData(SReadHandle* pHandle, const SExprInfo* pExpr, int32_t numOfExpr, + SSDataBlock* pBlock, int32_t rows, const char* idStr, STableMetaCacheInfo * pCache); void cleanupAggSup(SAggSupporter* pAggSup); void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHandle); -void setTbNameColData(void* pMeta, const SSDataBlock* pBlock, SColumnInfoData* pColInfoData, int32_t functionId); +void setTbNameColData(const SSDataBlock* pBlock, SColumnInfoData* pColInfoData, int32_t functionId, const char* name); int32_t doPrepareScan(SOperatorInfo* pOperator, uint64_t uid, int64_t ts); int32_t doGetScanStatus(SOperatorInfo* pOperator, uint64_t* uid, int64_t* ts); @@ -968,8 +935,8 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream, SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SSessionWinodwPhysiNode* pSessionNode, SExecTaskInfo* pTaskInfo); SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pAggNode, SExecTaskInfo* pTaskInfo); -SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SReadHandle* readHandle, uint64_t uid, - SBlockDistScanPhysiNode* pBlockScanNode, SExecTaskInfo* pTaskInfo); +SOperatorInfo* createDataBlockInfoScanOperator(SReadHandle* readHandle, SBlockDistScanPhysiNode* pBlockScanNode, + SExecTaskInfo* pTaskInfo); SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhysiNode* pTableScanNode, SNode* pTagCond, SExecTaskInfo* pTaskInfo); @@ -1063,10 +1030,6 @@ uint64_t calGroupIdByData(SPartitionBySupporter* pParSup, SExprSupp* pExprSup, S int32_t finalizeResultRows(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPosition, SExprSupp* pSup, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo); -int32_t createScanTableListInfo(SScanPhysiNode* pScanNode, SNodeList* pGroupTags, bool groupSort, SReadHandle* pHandle, - STableListInfo* pTableListInfo, SNode* pTagCond, SNode* pTagIndexCond, - const char* idstr); - SOperatorInfo* createGroupSortOperatorInfo(SOperatorInfo* downstream, SGroupSortPhysiNode* pSortPhyNode, SExecTaskInfo* pTaskInfo); SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanNode, STableListInfo* pTableListInfo, @@ -1075,7 +1038,6 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN void copyUpdateDataBlock(SSDataBlock* pDest, SSDataBlock* pSource, int32_t tsColIndex); bool groupbyTbname(SNodeList* pGroupList); -int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle, SNodeList* groupKey); void* destroySqlFunctionCtx(SqlFunctionCtx* pCtx, int32_t numOfOutput); int32_t buildDataBlockFromGroupRes(SOperatorInfo* pOperator, SStreamState* pState, SSDataBlock* pBlock, SExprSupp* pSup, SGroupResInfo* pGroupResInfo); diff --git a/source/libs/executor/src/cachescanoperator.c b/source/libs/executor/src/cachescanoperator.c index f645e71c6ec9fa4d2d5db1b78bcacdc1694e0247..6f9084ce52c3ae2caac867c73f23f40b95bff95f 100644 --- a/source/libs/executor/src/cachescanoperator.c +++ b/source/libs/executor/src/cachescanoperator.c @@ -48,6 +48,10 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe int32_t numOfCols = 0; code = extractColMatchInfo(pScanNode->scan.pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID, &pInfo->matchInfo); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + removeRedundantTsCol(pScanNode, &pInfo->matchInfo); code = extractCacheScanSlotId(pInfo->matchInfo.pList, pTaskInfo, &pInfo->pSlotIds); @@ -55,18 +59,23 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe goto _error; } - STableListInfo* pTableList = &pTaskInfo->tableqinfoList; + STableListInfo* pTableList = pTaskInfo->pTableInfoList; initResultSizeInfo(&pOperator->resultInfo, 4096); blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); pInfo->pUidList = taosArrayInit(4, sizeof(int64_t)); - // partition by tbname - if (taosArrayGetSize(pTableList->pGroupList) == taosArrayGetSize(pTableList->pTableList)) { + // partition by tbname, todo opt perf + if (oneTableForEachGroup(pTableList) || (tableListGetSize(pTableList) == 1)) { pInfo->retrieveType = CACHESCAN_RETRIEVE_TYPE_ALL | (pScanNode->ignoreNull ? CACHESCAN_RETRIEVE_LAST : CACHESCAN_RETRIEVE_LAST_ROW); - code = tsdbCacherowsReaderOpen(pInfo->readHandle.vnode, pInfo->retrieveType, pTableList->pTableList, - taosArrayGetSize(pInfo->matchInfo.pList), pTableList->suid, &pInfo->pLastrowReader); + + STableKeyInfo* pList = tableListGetInfo(pTableList, 0); + + size_t num = tableListGetSize(pTableList); + uint64_t suid = tableListGetSuid(pTableList); + code = tsdbCacherowsReaderOpen(pInfo->readHandle.vnode, pInfo->retrieveType, pList, num, + taosArrayGetSize(pInfo->matchInfo.pList), suid, &pInfo->pLastrowReader); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -84,21 +93,16 @@ SOperatorInfo* createCacherowsScanOperator(SLastRowScanPhysiNode* pScanNode, SRe p->pCtx = createSqlFunctionCtx(p->pExprInfo, p->numOfExprs, &p->rowEntryInfoOffset); } - pOperator->name = "LastrowScanOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; + setOperatorInfo(pOperator, "CachedRowScanOperator", QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN, false, OP_NOT_OPENED, pInfo, pTaskInfo); pOperator->exprSupp.numOfExprs = taosArrayGetSize(pInfo->pRes->pDataBlock); pOperator->fpSet = - createOperatorFpSet(operatorDummyOpenFn, doScanCache, NULL, NULL, destroyLastrowScanOperator, NULL); + createOperatorFpSet(operatorDummyOpenFn, doScanCache, NULL, destroyLastrowScanOperator, NULL); pOperator->cost.openCost = 0; return pOperator; -_error: + _error: pTaskInfo->code = code; destroyLastrowScanOperator(pInfo); taosMemoryFree(pOperator); @@ -112,10 +116,12 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) { SLastrowScanInfo* pInfo = pOperator->info; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - STableListInfo* pTableList = &pTaskInfo->tableqinfoList; - int32_t size = taosArrayGetSize(pTableList->pTableList); + STableListInfo* pTableList = pTaskInfo->pTableInfoList; + + uint64_t suid = tableListGetSuid(pTableList); + int32_t size = tableListGetSize(pTableList); if (size == 0) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return NULL; } @@ -141,62 +147,58 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) { pInfo->indexOfBufferedRes = 0; } + SSDataBlock* pRes = pInfo->pRes; + if (pInfo->indexOfBufferedRes < pInfo->pBufferredRes->info.rows) { for (int32_t i = 0; i < taosArrayGetSize(pInfo->matchInfo.pList); ++i) { SColMatchItem* pMatchInfo = taosArrayGet(pInfo->matchInfo.pList, i); int32_t slotId = pMatchInfo->dstSlotId; SColumnInfoData* pSrc = taosArrayGet(pInfo->pBufferredRes->pDataBlock, slotId); - SColumnInfoData* pDst = taosArrayGet(pInfo->pRes->pDataBlock, slotId); + SColumnInfoData* pDst = taosArrayGet(pRes->pDataBlock, slotId); char* p = colDataGetData(pSrc, pInfo->indexOfBufferedRes); bool isNull = colDataIsNull_s(pSrc, pInfo->indexOfBufferedRes); colDataAppend(pDst, 0, p, isNull); } - pInfo->pRes->info.uid = *(tb_uid_t*)taosArrayGet(pInfo->pUidList, pInfo->indexOfBufferedRes); - pInfo->pRes->info.rows = 1; - - if (pInfo->pseudoExprSup.numOfExprs > 0) { - SExprSupp* pSup = &pInfo->pseudoExprSup; - int32_t code = addTagPseudoColumnData(&pInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pInfo->pRes, - GET_TASKID(pTaskInfo)); - if (code != TSDB_CODE_SUCCESS) { - pTaskInfo->code = code; - return NULL; - } - } + pRes->info.uid = *(tb_uid_t*)taosArrayGet(pInfo->pUidList, pInfo->indexOfBufferedRes); + pRes->info.rows = 1; - if (pTableList->map != NULL) { - int64_t* groupId = taosHashGet(pTableList->map, &pInfo->pRes->info.uid, sizeof(int64_t)); - if (groupId != NULL) { - pInfo->pRes->info.groupId = *groupId; - } - } else { - ASSERT(taosArrayGetSize(pTableList->pTableList) == 1); - STableKeyInfo* pKeyInfo = taosArrayGet(pTableList->pTableList, 0); - pInfo->pRes->info.groupId = pKeyInfo->groupId; + SExprSupp* pSup = &pInfo->pseudoExprSup; + int32_t code = addTagPseudoColumnData(&pInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pRes, + pRes->info.rows, GET_TASKID(pTaskInfo), NULL); + if (code != TSDB_CODE_SUCCESS) { + pTaskInfo->code = code; + return NULL; } + pRes->info.groupId = getTableGroupId(pTableList, pRes->info.uid); pInfo->indexOfBufferedRes += 1; - return pInfo->pRes; + return pRes; } else { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return NULL; } } else { - size_t totalGroups = taosArrayGetSize(pTableList->pGroupList); + size_t totalGroups = tableListGetOutputGroups(pTableList); while (pInfo->currentGroupIndex < totalGroups) { - SArray* pGroupTableList = taosArrayGetP(pTableList->pGroupList, pInfo->currentGroupIndex); + STableKeyInfo* pList = NULL; + int32_t num = 0; - tsdbCacherowsReaderOpen(pInfo->readHandle.vnode, pInfo->retrieveType, pGroupTableList, - taosArrayGetSize(pInfo->matchInfo.pList), pTableList->suid, &pInfo->pLastrowReader); + int32_t code = tableListGetGroupList(pTableList, pInfo->currentGroupIndex, &pList, &num); + if (code != TSDB_CODE_SUCCESS) { + T_LONG_JMP(pTaskInfo->env, code); + } + + tsdbCacherowsReaderOpen(pInfo->readHandle.vnode, pInfo->retrieveType, pList, num, + taosArrayGetSize(pInfo->matchInfo.pList), suid, &pInfo->pLastrowReader); taosArrayClear(pInfo->pUidList); - int32_t code = tsdbRetrieveCacheRows(pInfo->pLastrowReader, pInfo->pRes, pInfo->pSlotIds, pInfo->pUidList); + code = tsdbRetrieveCacheRows(pInfo->pLastrowReader, pInfo->pRes, pInfo->pSlotIds, pInfo->pUidList); if (code != TSDB_CODE_SUCCESS) { - longjmp(pTaskInfo->env, code); + T_LONG_JMP(pTaskInfo->env, code); } pInfo->currentGroupIndex += 1; @@ -206,15 +208,15 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) { if (pInfo->pseudoExprSup.numOfExprs > 0) { SExprSupp* pSup = &pInfo->pseudoExprSup; - STableKeyInfo* pKeyInfo = taosArrayGet(pGroupTableList, 0); + STableKeyInfo* pKeyInfo = &((STableKeyInfo*)pTableList)[0]; pInfo->pRes->info.groupId = pKeyInfo->groupId; if (taosArrayGetSize(pInfo->pUidList) > 0) { ASSERT((pInfo->retrieveType & CACHESCAN_RETRIEVE_LAST_ROW) == CACHESCAN_RETRIEVE_LAST_ROW); pInfo->pRes->info.uid = *(tb_uid_t*)taosArrayGet(pInfo->pUidList, 0); - code = addTagPseudoColumnData(&pInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pInfo->pRes, - GET_TASKID(pTaskInfo)); + code = addTagPseudoColumnData(&pInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pInfo->pRes, pInfo->pRes->info.rows, + GET_TASKID(pTaskInfo), NULL); if (code != TSDB_CODE_SUCCESS) { pTaskInfo->code = code; return NULL; @@ -227,7 +229,7 @@ SSDataBlock* doScanCache(SOperatorInfo* pOperator) { } } - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return NULL; } } diff --git a/source/libs/executor/src/dataDispatcher.c b/source/libs/executor/src/dataDispatcher.c index bc4ab9c468ccbcacce3eff00ebd4f4d37435d87c..3d9757c96f0e46f7c4aedd4c78833bba5f1ebdcd 100644 --- a/source/libs/executor/src/dataDispatcher.c +++ b/source/libs/executor/src/dataDispatcher.c @@ -76,7 +76,7 @@ static void toDataCacheEntry(SDataDispatchHandle* pHandle, const SInputData* pIn pEntry->dataLen = 0; pBuf->useSize = sizeof(SDataCacheEntry); - blockEncode(pInput->pData, pEntry->data, &pEntry->dataLen, numOfCols, pEntry->compressed); + pEntry->dataLen = blockEncode(pInput->pData, pEntry->data, numOfCols); ASSERT(pEntry->numOfRows == *(int32_t*)(pEntry->data + 8)); ASSERT(pEntry->numOfCols == *(int32_t*)(pEntry->data + 8 + 4)); diff --git a/source/libs/executor/src/exchangeoperator.c b/source/libs/executor/src/exchangeoperator.c new file mode 100644 index 0000000000000000000000000000000000000000..049de727dfda4ed6bc39960ae8e024f8807b3ad1 --- /dev/null +++ b/source/libs/executor/src/exchangeoperator.c @@ -0,0 +1,638 @@ +/* + * 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 . + */ + +#include "filter.h" +#include "function.h" +#include "functionMgt.h" +#include "os.h" +#include "querynodes.h" +#include "tfill.h" +#include "tname.h" +#include "tref.h" + +#include "tdatablock.h" +#include "tglobal.h" +#include "tmsg.h" +#include "tsort.h" +#include "ttime.h" + +#include "executorimpl.h" +#include "index.h" +#include "query.h" +#include "tcompare.h" +#include "thash.h" +#include "ttypes.h" +#include "vnode.h" + +typedef struct SFetchRspHandleWrapper { + uint32_t exchangeId; + int32_t sourceIndex; +} SFetchRspHandleWrapper; + +static void destroyExchangeOperatorInfo(void* param); +static void freeBlock(void* pParam); +static void freeSourceDataInfo(void* param); +static void* setAllSourcesCompleted(SOperatorInfo* pOperator, int64_t startTs); + +static int32_t loadRemoteDataCallback(void* param, SDataBuf* pMsg, int32_t code); +static int32_t doSendFetchDataRequest(SExchangeInfo* pExchangeInfo, SExecTaskInfo* pTaskInfo, int32_t sourceIndex); +static int32_t getCompletedSources(const SArray* pArray); +static int32_t prepareConcurrentlyLoad(SOperatorInfo* pOperator); +static int32_t seqLoadRemoteData(SOperatorInfo* pOperator); +static int32_t prepareLoadRemoteData(SOperatorInfo* pOperator); + +static void concurrentlyLoadRemoteDataImpl(SOperatorInfo* pOperator, SExchangeInfo* pExchangeInfo, + SExecTaskInfo* pTaskInfo) { + int32_t code = 0; + size_t totalSources = taosArrayGetSize(pExchangeInfo->pSourceDataInfo); + int32_t completed = getCompletedSources(pExchangeInfo->pSourceDataInfo); + if (completed == totalSources) { + setAllSourcesCompleted(pOperator, pExchangeInfo->openedTs); + return; + } + + while (1) { + tsem_wait(&pExchangeInfo->ready); + + for (int32_t i = 0; i < totalSources; ++i) { + SSourceDataInfo* pDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, i); + if (pDataInfo->status == EX_SOURCE_DATA_EXHAUSTED) { + continue; + } + + if (pDataInfo->status != EX_SOURCE_DATA_READY) { + continue; + } + + if (pDataInfo->code != TSDB_CODE_SUCCESS) { + code = pDataInfo->code; + goto _error; + } + + SRetrieveTableRsp* pRsp = pDataInfo->pRsp; + SDownstreamSourceNode* pSource = taosArrayGet(pExchangeInfo->pSources, i); + + // todo + SLoadRemoteDataInfo* pLoadInfo = &pExchangeInfo->loadInfo; + if (pRsp->numOfRows == 0) { + pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED; + qDebug("%s vgId:%d, taskId:0x%" PRIx64 " execId:%d index:%d completed, rowsOfSource:%" PRIu64 + ", totalRows:%" PRIu64 ", try next %d/%" PRIzu, + GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, i, pDataInfo->totalRows, + pExchangeInfo->loadInfo.totalRows, i + 1, totalSources); + taosMemoryFreeClear(pDataInfo->pRsp); + break; + } + + SRetrieveTableRsp* pRetrieveRsp = pDataInfo->pRsp; + int32_t index = 0; + char* pStart = pRetrieveRsp->data; + while (index++ < pRetrieveRsp->numOfBlocks) { + SSDataBlock* pb = createOneDataBlock(pExchangeInfo->pDummyBlock, false); + code = extractDataBlockFromFetchRsp(pb, pStart, NULL, &pStart); + if (code != 0) { + taosMemoryFreeClear(pDataInfo->pRsp); + goto _error; + } + + taosArrayPush(pExchangeInfo->pResultBlockList, &pb); + } + + updateLoadRemoteInfo(pLoadInfo, pRetrieveRsp->numOfRows, pRetrieveRsp->compLen, pExchangeInfo->openedTs, pOperator); + + if (pRsp->completed == 1) { + pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED; + qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 + " execId:%d index:%d completed, blocks:%d, numOfRows:%d, rowsOfSource:%" PRIu64 ", totalRows:%" PRIu64 + ", total:%.2f Kb, try next %d/%" PRIzu, + GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, i, pRsp->numOfBlocks, + pRsp->numOfRows, pDataInfo->totalRows, pLoadInfo->totalRows, pLoadInfo->totalSize / 1024.0, + i + 1, totalSources); + } else { + qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 + " execId:%d blocks:%d, numOfRows:%d, totalRows:%" PRIu64 ", total:%.2f Kb", + GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, pRsp->numOfBlocks, + pRsp->numOfRows, pLoadInfo->totalRows, pLoadInfo->totalSize / 1024.0); + } + + taosMemoryFreeClear(pDataInfo->pRsp); + + if (pDataInfo->status != EX_SOURCE_DATA_EXHAUSTED) { + pDataInfo->status = EX_SOURCE_DATA_NOT_READY; + code = doSendFetchDataRequest(pExchangeInfo, pTaskInfo, i); + if (code != TSDB_CODE_SUCCESS) { + taosMemoryFreeClear(pDataInfo->pRsp); + goto _error; + } + } + return; + } // end loop + + int32_t complete1 = getCompletedSources(pExchangeInfo->pSourceDataInfo); + if (complete1 == totalSources) { + qDebug("all sources are completed, %s", GET_TASKID(pTaskInfo)); + return; + } + } + + _error: + pTaskInfo->code = code; +} + +static SSDataBlock* doLoadRemoteDataImpl(SOperatorInfo* pOperator) { + SExchangeInfo* pExchangeInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + + pTaskInfo->code = pOperator->fpSet._openFn(pOperator); + if (pTaskInfo->code != TSDB_CODE_SUCCESS) { + return NULL; + } + + size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); + + SLoadRemoteDataInfo* pLoadInfo = &pExchangeInfo->loadInfo; + if (pOperator->status == OP_EXEC_DONE) { + qDebug("%s all %" PRIzu " source(s) are exhausted, total rows:%" PRIu64 " bytes:%" PRIu64 ", elapsed:%.2f ms", + GET_TASKID(pTaskInfo), totalSources, pLoadInfo->totalRows, pLoadInfo->totalSize, + pLoadInfo->totalElapsed / 1000.0); + return NULL; + } + + size_t size = taosArrayGetSize(pExchangeInfo->pResultBlockList); + if (size == 0 || pExchangeInfo->rspBlockIndex >= size) { + pExchangeInfo->rspBlockIndex = 0; + taosArrayClearEx(pExchangeInfo->pResultBlockList, freeBlock); + if (pExchangeInfo->seqLoadData) { + seqLoadRemoteData(pOperator); + } else { + concurrentlyLoadRemoteDataImpl(pOperator, pExchangeInfo, pTaskInfo); + } + + if (taosArrayGetSize(pExchangeInfo->pResultBlockList) == 0) { + return NULL; + } + } + + // we have buffered retrieved datablock, return it directly + return taosArrayGetP(pExchangeInfo->pResultBlockList, pExchangeInfo->rspBlockIndex++); +} + +static SSDataBlock* doLoadRemoteData(SOperatorInfo* pOperator) { + SExchangeInfo* pExchangeInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + + if (pOperator->status == OP_EXEC_DONE) { + return NULL; + } + + while (1) { + SSDataBlock* pBlock = doLoadRemoteDataImpl(pOperator); + if (pBlock == NULL) { + return NULL; + } + + SLimitInfo* pLimitInfo = &pExchangeInfo->limitInfo; + if (hasLimitOffsetInfo(pLimitInfo)) { + int32_t status = handleLimitOffset(pOperator, pLimitInfo, pBlock, false); + if (status == PROJECT_RETRIEVE_CONTINUE) { + continue; + } else if (status == PROJECT_RETRIEVE_DONE) { + size_t rows = pBlock->info.rows; + pExchangeInfo->limitInfo.numOfOutputRows += rows; + + if (rows == 0) { + setOperatorCompleted(pOperator); + return NULL; + } else { + return pBlock; + } + } + } else { + return pBlock; + } + } +} + +static int32_t initDataSource(int32_t numOfSources, SExchangeInfo* pInfo, const char* id) { + pInfo->pSourceDataInfo = taosArrayInit(numOfSources, sizeof(SSourceDataInfo)); + if (pInfo->pSourceDataInfo == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + for (int32_t i = 0; i < numOfSources; ++i) { + SSourceDataInfo dataInfo = {0}; + dataInfo.status = EX_SOURCE_DATA_NOT_READY; + dataInfo.taskId = id; + dataInfo.index = i; + SSourceDataInfo* pDs = taosArrayPush(pInfo->pSourceDataInfo, &dataInfo); + if (pDs == NULL) { + taosArrayDestroy(pInfo->pSourceDataInfo); + return TSDB_CODE_OUT_OF_MEMORY; + } + } + + return TSDB_CODE_SUCCESS; +} + +static int32_t initExchangeOperator(SExchangePhysiNode* pExNode, SExchangeInfo* pInfo, const char* id) { + size_t numOfSources = LIST_LENGTH(pExNode->pSrcEndPoints); + + if (numOfSources == 0) { + qError("%s invalid number: %d of sources in exchange operator", id, (int32_t)numOfSources); + return TSDB_CODE_INVALID_PARA; + } + + pInfo->pSources = taosArrayInit(numOfSources, sizeof(SDownstreamSourceNode)); + if (pInfo->pSources == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + for (int32_t i = 0; i < numOfSources; ++i) { + SDownstreamSourceNode* pNode = (SDownstreamSourceNode*)nodesListGetNode((SNodeList*)pExNode->pSrcEndPoints, i); + taosArrayPush(pInfo->pSources, pNode); + } + + initLimitInfo(pExNode->node.pLimit, pExNode->node.pSlimit, &pInfo->limitInfo); + pInfo->self = taosAddRef(exchangeObjRefPool, pInfo); + + return initDataSource(numOfSources, pInfo, id); +} + +SOperatorInfo* createExchangeOperatorInfo(void* pTransporter, SExchangePhysiNode* pExNode, SExecTaskInfo* pTaskInfo) { + SExchangeInfo* pInfo = taosMemoryCalloc(1, sizeof(SExchangeInfo)); + SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); + if (pInfo == NULL || pOperator == NULL) { + goto _error; + } + + int32_t code = initExchangeOperator(pExNode, pInfo, GET_TASKID(pTaskInfo)); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + + tsem_init(&pInfo->ready, 0, 0); + pInfo->pDummyBlock = createResDataBlock(pExNode->node.pOutputDataBlockDesc); + pInfo->pResultBlockList = taosArrayInit(1, POINTER_BYTES); + + pInfo->seqLoadData = false; + pInfo->pTransporter = pTransporter; + + setOperatorInfo(pOperator, "ExchangeOperator", QUERY_NODE_PHYSICAL_PLAN_EXCHANGE, false, OP_NOT_OPENED, pInfo, pTaskInfo); + pOperator->exprSupp.numOfExprs = taosArrayGetSize(pInfo->pDummyBlock->pDataBlock); + + pOperator->fpSet = createOperatorFpSet(prepareLoadRemoteData, doLoadRemoteData, NULL, destroyExchangeOperatorInfo, NULL); + return pOperator; + + _error: + if (pInfo != NULL) { + doDestroyExchangeOperatorInfo(pInfo); + } + + taosMemoryFreeClear(pOperator); + pTaskInfo->code = code; + return NULL; +} + +void destroyExchangeOperatorInfo(void* param) { + SExchangeInfo* pExInfo = (SExchangeInfo*)param; + taosRemoveRef(exchangeObjRefPool, pExInfo->self); +} + +void freeBlock(void* pParam) { + SSDataBlock* pBlock = *(SSDataBlock**)pParam; + blockDataDestroy(pBlock); +} + +void freeSourceDataInfo(void* p) { + SSourceDataInfo* pInfo = (SSourceDataInfo*)p; + taosMemoryFreeClear(pInfo->pRsp); +} + +void doDestroyExchangeOperatorInfo(void* param) { + SExchangeInfo* pExInfo = (SExchangeInfo*)param; + + taosArrayDestroy(pExInfo->pSources); + taosArrayDestroyEx(pExInfo->pSourceDataInfo, freeSourceDataInfo); + + if (pExInfo->pResultBlockList != NULL) { + taosArrayDestroyEx(pExInfo->pResultBlockList, freeBlock); + pExInfo->pResultBlockList = NULL; + } + + blockDataDestroy(pExInfo->pDummyBlock); + + tsem_destroy(&pExInfo->ready); + taosMemoryFreeClear(param); +} + +int32_t loadRemoteDataCallback(void* param, SDataBuf* pMsg, int32_t code) { + SFetchRspHandleWrapper* pWrapper = (SFetchRspHandleWrapper*)param; + + SExchangeInfo* pExchangeInfo = taosAcquireRef(exchangeObjRefPool, pWrapper->exchangeId); + if (pExchangeInfo == NULL) { + qWarn("failed to acquire exchange operator, since it may have been released"); + taosMemoryFree(pMsg->pData); + return TSDB_CODE_SUCCESS; + } + + int32_t index = pWrapper->sourceIndex; + SSourceDataInfo* pSourceDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, index); + + if (code == TSDB_CODE_SUCCESS) { + pSourceDataInfo->pRsp = pMsg->pData; + + SRetrieveTableRsp* pRsp = pSourceDataInfo->pRsp; + pRsp->numOfRows = htonl(pRsp->numOfRows); + pRsp->compLen = htonl(pRsp->compLen); + pRsp->numOfCols = htonl(pRsp->numOfCols); + pRsp->useconds = htobe64(pRsp->useconds); + pRsp->numOfBlocks = htonl(pRsp->numOfBlocks); + + ASSERT(pRsp != NULL); + qDebug("%s fetch rsp received, index:%d, blocks:%d, rows:%d", pSourceDataInfo->taskId, index, pRsp->numOfBlocks, + pRsp->numOfRows); + } else { + taosMemoryFree(pMsg->pData); + pSourceDataInfo->code = code; + qDebug("%s fetch rsp received, index:%d, error:%s", pSourceDataInfo->taskId, index, tstrerror(code)); + } + + pSourceDataInfo->status = EX_SOURCE_DATA_READY; + + tsem_post(&pExchangeInfo->ready); + taosReleaseRef(exchangeObjRefPool, pWrapper->exchangeId); + + return TSDB_CODE_SUCCESS; +} + +int32_t doSendFetchDataRequest(SExchangeInfo* pExchangeInfo, SExecTaskInfo* pTaskInfo, int32_t sourceIndex) { + size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); + + SDownstreamSourceNode* pSource = taosArrayGet(pExchangeInfo->pSources, sourceIndex); + SSourceDataInfo* pDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, sourceIndex); + + ASSERT(pDataInfo->status == EX_SOURCE_DATA_NOT_READY); + + SFetchRspHandleWrapper* pWrapper = taosMemoryCalloc(1, sizeof(SFetchRspHandleWrapper)); + pWrapper->exchangeId = pExchangeInfo->self; + pWrapper->sourceIndex = sourceIndex; + + if (pSource->localExec) { + SDataBuf pBuf = {0}; + int32_t code = + (*pTaskInfo->localFetch.fp)(pTaskInfo->localFetch.handle, pSource->schedId, pTaskInfo->id.queryId, + pSource->taskId, 0, pSource->execId, &pBuf.pData, pTaskInfo->localFetch.explainRes); + loadRemoteDataCallback(pWrapper, &pBuf, code); + taosMemoryFree(pWrapper); + } else { + SResFetchReq* pMsg = taosMemoryCalloc(1, sizeof(SResFetchReq)); + if (NULL == pMsg) { + pTaskInfo->code = TSDB_CODE_QRY_OUT_OF_MEMORY; + taosMemoryFree(pWrapper); + return pTaskInfo->code; + } + + qDebug("%s build fetch msg and send to vgId:%d, ep:%s, taskId:0x%" PRIx64 ", execId:%d, %d/%" PRIzu, + GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->addr.epSet.eps[0].fqdn, pSource->taskId, + pSource->execId, sourceIndex, totalSources); + + pMsg->header.vgId = htonl(pSource->addr.nodeId); + pMsg->sId = htobe64(pSource->schedId); + pMsg->taskId = htobe64(pSource->taskId); + pMsg->queryId = htobe64(pTaskInfo->id.queryId); + pMsg->execId = htonl(pSource->execId); + + // send the fetch remote task result reques + SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); + if (NULL == pMsgSendInfo) { + taosMemoryFreeClear(pMsg); + taosMemoryFree(pWrapper); + qError("%s prepare message %d failed", GET_TASKID(pTaskInfo), (int32_t)sizeof(SMsgSendInfo)); + pTaskInfo->code = TSDB_CODE_QRY_OUT_OF_MEMORY; + return pTaskInfo->code; + } + + pMsgSendInfo->param = pWrapper; + pMsgSendInfo->paramFreeFp = taosMemoryFree; + pMsgSendInfo->msgInfo.pData = pMsg; + pMsgSendInfo->msgInfo.len = sizeof(SResFetchReq); + pMsgSendInfo->msgType = pSource->fetchMsgType; + pMsgSendInfo->fp = loadRemoteDataCallback; + + int64_t transporterId = 0; + int32_t code = + asyncSendMsgToServer(pExchangeInfo->pTransporter, &pSource->addr.epSet, &transporterId, pMsgSendInfo); + } + + return TSDB_CODE_SUCCESS; +} + +void updateLoadRemoteInfo(SLoadRemoteDataInfo* pInfo, int32_t numOfRows, int32_t dataLen, int64_t startTs, + SOperatorInfo* pOperator) { + pInfo->totalRows += numOfRows; + pInfo->totalSize += dataLen; + pInfo->totalElapsed += (taosGetTimestampUs() - startTs); + pOperator->resultInfo.totalRows += numOfRows; +} + +int32_t extractDataBlockFromFetchRsp(SSDataBlock* pRes, char* pData, SArray* pColList, char** pNextStart) { + if (pColList == NULL) { // data from other sources + blockDataCleanup(pRes); + *pNextStart = (char*)blockDecode(pRes, pData); + } else { // extract data according to pColList + char* pStart = pData; + + int32_t numOfCols = htonl(*(int32_t*)pStart); + pStart += sizeof(int32_t); + + // todo refactor:extract method + SSysTableSchema* pSchema = (SSysTableSchema*)pStart; + for (int32_t i = 0; i < numOfCols; ++i) { + SSysTableSchema* p = (SSysTableSchema*)pStart; + + p->colId = htons(p->colId); + p->bytes = htonl(p->bytes); + pStart += sizeof(SSysTableSchema); + } + + SSDataBlock* pBlock = createDataBlock(); + for (int32_t i = 0; i < numOfCols; ++i) { + SColumnInfoData idata = createColumnInfoData(pSchema[i].type, pSchema[i].bytes, pSchema[i].colId); + blockDataAppendColInfo(pBlock, &idata); + } + + blockDecode(pBlock, pStart); + blockDataEnsureCapacity(pRes, pBlock->info.rows); + + // data from mnode + pRes->info.rows = pBlock->info.rows; + relocateColumnData(pRes, pColList, pBlock->pDataBlock, false); + blockDataDestroy(pBlock); + } + + // todo move this to time window aggregator, since the primary timestamp may not be known by exchange operator. + blockDataUpdateTsWindow(pRes, 0); + return TSDB_CODE_SUCCESS; +} + +void* setAllSourcesCompleted(SOperatorInfo* pOperator, int64_t startTs) { + SExchangeInfo* pExchangeInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + + int64_t el = taosGetTimestampUs() - startTs; + SLoadRemoteDataInfo* pLoadInfo = &pExchangeInfo->loadInfo; + + pLoadInfo->totalElapsed += el; + + size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); + qDebug("%s all %" PRIzu " sources are exhausted, total rows: %" PRIu64 " bytes:%" PRIu64 ", elapsed:%.2f ms", + GET_TASKID(pTaskInfo), totalSources, pLoadInfo->totalRows, pLoadInfo->totalSize, + pLoadInfo->totalElapsed / 1000.0); + + setOperatorCompleted(pOperator); + return NULL; +} + +int32_t getCompletedSources(const SArray* pArray) { + size_t total = taosArrayGetSize(pArray); + + int32_t completed = 0; + for (int32_t k = 0; k < total; ++k) { + SSourceDataInfo* p = taosArrayGet(pArray, k); + if (p->status == EX_SOURCE_DATA_EXHAUSTED) { + completed += 1; + } + } + + return completed; +} + +int32_t prepareConcurrentlyLoad(SOperatorInfo* pOperator) { + SExchangeInfo* pExchangeInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + + size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); + int64_t startTs = taosGetTimestampUs(); + + // Asynchronously send all fetch requests to all sources. + for (int32_t i = 0; i < totalSources; ++i) { + int32_t code = doSendFetchDataRequest(pExchangeInfo, pTaskInfo, i); + if (code != TSDB_CODE_SUCCESS) { + pTaskInfo->code = code; + return code; + } + } + + int64_t endTs = taosGetTimestampUs(); + qDebug("%s send all fetch requests to %" PRIzu " sources completed, elapsed:%.2fms", GET_TASKID(pTaskInfo), + totalSources, (endTs - startTs) / 1000.0); + + pOperator->status = OP_RES_TO_RETURN; + pOperator->cost.openCost = taosGetTimestampUs() - startTs; + + tsem_wait(&pExchangeInfo->ready); + tsem_post(&pExchangeInfo->ready); + return TSDB_CODE_SUCCESS; +} + +int32_t seqLoadRemoteData(SOperatorInfo* pOperator) { + SExchangeInfo* pExchangeInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + + size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); + int64_t startTs = taosGetTimestampUs(); + + while (1) { + if (pExchangeInfo->current >= totalSources) { + setAllSourcesCompleted(pOperator, startTs); + return TSDB_CODE_SUCCESS; + } + + doSendFetchDataRequest(pExchangeInfo, pTaskInfo, pExchangeInfo->current); + tsem_wait(&pExchangeInfo->ready); + + SSourceDataInfo* pDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, pExchangeInfo->current); + SDownstreamSourceNode* pSource = taosArrayGet(pExchangeInfo->pSources, pExchangeInfo->current); + + if (pDataInfo->code != TSDB_CODE_SUCCESS) { + qError("%s vgId:%d, taskID:0x%" PRIx64 " execId:%d error happens, code:%s", GET_TASKID(pTaskInfo), + pSource->addr.nodeId, pSource->taskId, pSource->execId, tstrerror(pDataInfo->code)); + pOperator->pTaskInfo->code = pDataInfo->code; + return pOperator->pTaskInfo->code; + } + + SRetrieveTableRsp* pRsp = pDataInfo->pRsp; + SLoadRemoteDataInfo* pLoadInfo = &pExchangeInfo->loadInfo; + if (pRsp->numOfRows == 0) { + qDebug("%s vgId:%d, taskID:0x%" PRIx64 " execId:%d %d of total completed, rowsOfSource:%" PRIu64 + ", totalRows:%" PRIu64 " try next", + GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, pExchangeInfo->current + 1, + pDataInfo->totalRows, pLoadInfo->totalRows); + + pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED; + pExchangeInfo->current += 1; + taosMemoryFreeClear(pDataInfo->pRsp); + continue; + } + + SRetrieveTableRsp* pRetrieveRsp = pDataInfo->pRsp; + + char* pStart = pRetrieveRsp->data; + int32_t code = extractDataBlockFromFetchRsp(NULL, pStart, NULL, &pStart); + + if (pRsp->completed == 1) { + qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " execId:%d numOfRows:%d, rowsOfSource:%" PRIu64 + ", totalRows:%" PRIu64 ", totalBytes:%" PRIu64 " try next %d/%" PRIzu, + GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, pRetrieveRsp->numOfRows, + pDataInfo->totalRows, pLoadInfo->totalRows, pLoadInfo->totalSize, pExchangeInfo->current + 1, + totalSources); + + pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED; + pExchangeInfo->current += 1; + } else { + qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " execId:%d numOfRows:%d, totalRows:%" PRIu64 + ", totalBytes:%" PRIu64, + GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, pRetrieveRsp->numOfRows, + pLoadInfo->totalRows, pLoadInfo->totalSize); + } + + updateLoadRemoteInfo(pLoadInfo, pRetrieveRsp->numOfRows, pRetrieveRsp->compLen, startTs, pOperator); + pDataInfo->totalRows += pRetrieveRsp->numOfRows; + + taosMemoryFreeClear(pDataInfo->pRsp); + return TSDB_CODE_SUCCESS; + } +} + +int32_t prepareLoadRemoteData(SOperatorInfo* pOperator) { + if (OPTR_IS_OPENED(pOperator)) { + return TSDB_CODE_SUCCESS; + } + + int64_t st = taosGetTimestampUs(); + + SExchangeInfo* pExchangeInfo = pOperator->info; + if (!pExchangeInfo->seqLoadData) { + int32_t code = prepareConcurrentlyLoad(pOperator); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + pExchangeInfo->openedTs = taosGetTimestampUs(); + } + + OPTR_SET_OPENED(pOperator); + pOperator->cost.openCost = (taosGetTimestampUs() - st) / 1000.0; + return TSDB_CODE_SUCCESS; +} diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 971b28eb09d3f3de5ba888925af061ebe285de40..d1046ff02cbbabcf31442e1c4b151a9006aaa836 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -26,9 +26,31 @@ #include "executorimpl.h" #include "tcompression.h" -static int32_t removeInvalidTable(SArray* list, SHashObj* tags); +// If the numOfOutputGroups is 1, the data blocks that belongs to different groups will be provided randomly +// The numOfOutputGroups is specified by physical plan. and will not be affect by numOfGroups +struct STableListInfo { + bool oneTableForEachGroup; + int32_t numOfOuputGroups; // the data block will be generated one by one + int32_t* groupOffset; // keep the offset value for each group in the tableList + SArray* pTableList; + SHashObj* map; // speedup acquire the tableQueryInfo by table uid + uint64_t suid; +}; + +typedef struct tagFilterAssist { + SHashObj* colHash; + int32_t index; + SArray* cInfoList; +} tagFilterAssist; + +static int32_t removeInvalidTable(SArray* uids, SHashObj* tags); static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list, SNode* pTagCond, SHashObj* tags); static int32_t optimizeTbnameInCondImpl(void* metaHandle, int64_t suid, SArray* list, SNode* pTagCond); +static int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, SNode* pTagCond, + SNode* pTagIndexCond, STableListInfo* pListInfo); + +static int64_t getLimit(const SNode* pLimit) { return NULL == pLimit ? -1 : ((SLimitNode*)pLimit)->limit; } +static int64_t getOffset(const SNode* pLimit) { return NULL == pLimit ? -1 : ((SLimitNode*)pLimit)->offset; } void initResultRowInfo(SResultRowInfo* pResultRowInfo) { pResultRowInfo->size = 0; @@ -301,12 +323,6 @@ int32_t isQualifiedTable(STableKeyInfo* info, SNode* pTagCond, void* metaHandle, return TSDB_CODE_SUCCESS; } -typedef struct tagFilterAssist { - SHashObj* colHash; - int32_t index; - SArray* cInfoList; -} tagFilterAssist; - static EDealRes getColumn(SNode** pNode, void* pContext) { SColumnNode* pSColumnNode = NULL; if (QUERY_NODE_COLUMN == nodeType((*pNode))) { @@ -363,7 +379,7 @@ static int32_t createResultData(SDataType* pType, int32_t numOfRows, SScalarPara pColumnData->info.scale = pType->scale; pColumnData->info.precision = pType->precision; - int32_t code = colInfoDataEnsureCapacity(pColumnData, numOfRows); + int32_t code = colInfoDataEnsureCapacity(pColumnData, numOfRows, true); if (code != TSDB_CODE_SUCCESS) { terrno = code; taosMemoryFree(pColumnData); @@ -405,7 +421,7 @@ static SColumnInfoData* getColInfoResult(void* metaHandle, int64_t suid, SArray* } for (int32_t i = 0; i < taosArrayGetSize(ctx.cInfoList); ++i) { - SColumnInfoData colInfo = {{0}, 0}; + SColumnInfoData colInfo = {0, {0}}; colInfo.info = *(SColumnInfo*)taosArrayGet(ctx.cInfoList, i); blockDataAppendColInfo(pResBlock, &colInfo); } @@ -482,6 +498,7 @@ static SColumnInfoData* getColInfoResult(void* metaHandle, int64_t suid, SArray* } } } + pResBlock->info.rows = rows; // int64_t st1 = taosGetTimestampUs(); @@ -544,6 +561,7 @@ int32_t getColInfoResultForGroupby(void* metaHandle, SNodeList* group, STableLis code = TSDB_CODE_OUT_OF_MEMORY; goto end; } + ctx.index = 0; ctx.cInfoList = taosArrayInit(4, sizeof(SColumnInfo)); if (ctx.cInfoList == NULL) { @@ -564,7 +582,7 @@ int32_t getColInfoResultForGroupby(void* metaHandle, SNodeList* group, STableLis } for (int32_t i = 0; i < taosArrayGetSize(ctx.cInfoList); ++i) { - SColumnInfoData colInfo = {{0}, 0}; + SColumnInfoData colInfo = {0, {0}}; colInfo.info = *(SColumnInfo*)taosArrayGet(ctx.cInfoList, i); blockDataAppendColInfo(pResBlock, &colInfo); } @@ -606,6 +624,7 @@ int32_t getColInfoResultForGroupby(void* metaHandle, SNodeList* group, STableLis } else { void* tag = taosHashGet(tags, uid, sizeof(int64_t)); ASSERT(tag); + STagVal tagVal = {0}; tagVal.cid = pColInfo->info.colId; const char* p = metaGetTableTagVal(tag, pColInfo->info.type, &tagVal); @@ -636,6 +655,7 @@ int32_t getColInfoResultForGroupby(void* metaHandle, SNodeList* group, STableLis } } } + pResBlock->info.rows = rows; // int64_t st1 = taosGetTimestampUs(); @@ -661,10 +681,12 @@ int32_t getColInfoResultForGroupby(void* metaHandle, SNodeList* group, STableLis } break; } + default: code = TSDB_CODE_OPS_NOT_SUPPORT; goto end; } + if (nodeType(pNode) == QUERY_NODE_COLUMN) { SColumnNode* pSColumnNode = (SColumnNode*)pNode; SColumnInfoData* pColInfo = (SColumnInfoData*)taosArrayGet(pResBlock->pDataBlock, pSColumnNode->slotId); @@ -674,10 +696,12 @@ int32_t getColInfoResultForGroupby(void* metaHandle, SNodeList* group, STableLis } else { code = scalarCalculate(pNode, pBlockList, &output); } + if (code != TSDB_CODE_SUCCESS) { releaseColInfoData(output.columnData); goto end; } + taosArrayPush(groupData, &output.columnData); } @@ -696,6 +720,7 @@ int32_t getColInfoResultForGroupby(void* metaHandle, SNodeList* group, STableLis code = TSDB_CODE_OUT_OF_MEMORY; goto end; } + for (int i = 0; i < rows; i++) { STableKeyInfo* info = taosArrayGet(pTableListInfo->pTableList, i); @@ -733,7 +758,6 @@ int32_t getColInfoResultForGroupby(void* metaHandle, SNodeList* group, STableLis int32_t len = (int32_t)(pStart - (char*)keyBuf); info->groupId = calcGroupId(keyBuf, len); - taosHashPut(pTableListInfo->map, &(info->uid), sizeof(uint64_t), &info->groupId, sizeof(uint64_t)); } // int64_t st2 = taosGetTimestampUs(); @@ -751,14 +775,70 @@ end: return code; } +static int32_t nameComparFn(const void* p1, const void* p2) { + const char* pName1 = *(const char**)p1; + const char* pName2 = *(const char**)p2; + + int32_t ret = strcmp(pName1, pName2); + if (ret == 0) { + return 0; + } else { + return (ret > 0) ? 1 : -1; + } +} + +static SArray* getTableNameList(const SNodeListNode* pList) { + int32_t len = LIST_LENGTH(pList->pNodeList); + SListCell* cell = pList->pNodeList->pHead; + + SArray* pTbList = taosArrayInit(len, POINTER_BYTES); + for (int i = 0; i < pList->pNodeList->length; i++) { + SValueNode* valueNode = (SValueNode*)cell->pNode; + if (!IS_VAR_DATA_TYPE(valueNode->node.resType.type)) { + terrno = TSDB_CODE_INVALID_PARA; + taosArrayDestroy(pTbList); + return NULL; + } + + char* name = varDataVal(valueNode->datum.p); + taosArrayPush(pTbList, &name); + cell = cell->pNext; + } + + size_t numOfTables = taosArrayGetSize(pTbList); + + // order the name + taosArraySort(pTbList, nameComparFn); + + // remove the duplicates + SArray* pNewList = taosArrayInit(taosArrayGetSize(pTbList), sizeof(void*)); + taosArrayPush(pNewList, taosArrayGet(pTbList, 0)); + + for (int32_t i = 1; i < numOfTables; ++i) { + char** name = taosArrayGetLast(pNewList); + char** nameInOldList = taosArrayGet(pTbList, i); + if (strcmp(*name, *nameInOldList) == 0) { + continue; + } + + taosArrayPush(pNewList, nameInOldList); + } + + taosArrayDestroy(pTbList); + return pNewList; +} + static int tableUidCompare(const void* a, const void* b) { - int64_t u1 = *(uint64_t*)a; - int64_t u2 = *(uint64_t*)b; + uint64_t u1 = *(uint64_t*)a; + uint64_t u2 = *(uint64_t*)b; + if (u1 == u2) { return 0; } + return u1 < u2 ? -1 : 1; } + static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list, SNode* cond, SHashObj* tags) { int32_t ret = -1; if (nodeType(cond) == QUERY_NODE_OPERATOR) { @@ -778,7 +858,9 @@ static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list SNodeList* pList = (SNodeList*)pNode->pParameterList; int32_t len = LIST_LENGTH(pList); - if (len <= 0) return ret; + if (len <= 0) { + return ret; + } SListCell* cell = pList->pHead; for (int i = 0; i < len; i++) { @@ -789,6 +871,7 @@ static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list } cell = cell->pNext; } + taosArraySort(list, tableUidCompare); taosArrayRemoveDuplicate(list, tableUidCompare, NULL); @@ -796,6 +879,7 @@ static int32_t optimizeTbnameInCond(void* metaHandle, int64_t suid, SArray* list ret = metaGetTableTagsByUids(metaHandle, suid, list, tags); removeInvalidTable(list, tags); } + return ret; } @@ -813,49 +897,57 @@ static int32_t removeInvalidTable(SArray* uids, SHashObj* tags) { taosArrayPush(validUid, uid); } } + taosArraySwap(uids, validUid); taosArrayDestroy(validUid); return 0; } + static int32_t optimizeTbnameInCondImpl(void* metaHandle, int64_t suid, SArray* list, SNode* pTagCond) { if (nodeType(pTagCond) != QUERY_NODE_OPERATOR) { return -1; } + SOperatorNode* pNode = (SOperatorNode*)pTagCond; if (pNode->opType != OP_TYPE_IN) { return -1; } + if ((pNode->pLeft != NULL && nodeType(pNode->pLeft) == QUERY_NODE_COLUMN && ((SColumnNode*)pNode->pLeft)->colType == COLUMN_TYPE_TBNAME) && (pNode->pRight != NULL && nodeType(pNode->pRight) == QUERY_NODE_NODE_LIST)) { SNodeListNode* pList = (SNodeListNode*)pNode->pRight; int32_t len = LIST_LENGTH(pList->pNodeList); - if (len <= 0) return -1; - - SListCell* cell = pList->pNodeList->pHead; + if (len <= 0) { + return -1; + } - SArray* pTbList = taosArrayInit(len, sizeof(void*)); - for (int i = 0; i < pList->pNodeList->length; i++) { - SValueNode* valueNode = (SValueNode*)cell->pNode; - if (!IS_VAR_DATA_TYPE(valueNode->node.resType.type)) { - taosArrayDestroy(pTbList); - return -1; + SArray* pTbList = getTableNameList(pList); + int32_t numOfTables = taosArrayGetSize(pTbList); + SHashObj *uHash = NULL; + size_t listlen = taosArrayGetSize(list); // len > 0 means there already have uids + if (listlen > 0) { + uHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); + for (int i = 0; i < listlen; i++) { + int64_t *uid = taosArrayGet(list, i); + taosHashPut(uHash, uid, sizeof(int64_t), &i, sizeof(i)); } - char* name = varDataVal(valueNode->datum.p); - taosArrayPush(pTbList, &name); - cell = cell->pNext; } - for (int i = 0; i < taosArrayGetSize(pTbList); i++) { - char* name = taosArrayGetP(pTbList, i); + for (int i = 0; i < numOfTables; i++) { + char* name = taosArrayGetP(pTbList, i); + uint64_t uid = 0; if (metaGetTableUidByName(metaHandle, name, &uid) == 0) { ETableType tbType = TSDB_TABLE_MAX; if (metaGetTableTypeByName(metaHandle, name, &tbType) == 0 && tbType == TSDB_CHILD_TABLE) { - taosArrayPush(list, &uid); + if (NULL == uHash || taosHashGet(uHash, &uid, sizeof(uid)) == NULL) { + taosArrayPush(list, &uid); + } } else { taosArrayDestroy(pTbList); + taosHashCleanup(uHash); return -1; } } else { @@ -863,20 +955,19 @@ static int32_t optimizeTbnameInCondImpl(void* metaHandle, int64_t suid, SArray* terrno = 0; } } + + taosHashCleanup(uHash); taosArrayDestroy(pTbList); return 0; } + return -1; } + int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, SNode* pTagCond, SNode* pTagIndexCond, STableListInfo* pListInfo) { int32_t code = TSDB_CODE_SUCCESS; - pListInfo->pTableList = taosArrayInit(8, sizeof(STableKeyInfo)); - if (pListInfo->pTableList == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - uint64_t tableUid = pScanNode->uid; pListInfo->suid = pScanNode->suid; SArray* res = taosArrayInit(8, sizeof(uint64_t)); @@ -936,24 +1027,17 @@ int32_t getTableList(void* metaHandle, void* pVnode, SScanPhysiNode* pScanNode, size_t numOfTables = taosArrayGetSize(res); for (int i = 0; i < numOfTables; i++) { STableKeyInfo info = {.uid = *(uint64_t*)taosArrayGet(res, i), .groupId = 0}; - void* p = taosArrayPush(pListInfo->pTableList, &info); + + void* p = taosArrayPush(pListInfo->pTableList, &info); if (p == NULL) { taosArrayDestroy(res); return TSDB_CODE_OUT_OF_MEMORY; } - qDebug("tagfilter get uid:%" PRId64 "", info.uid); + qDebug("tagfilter get uid:%" PRIu64 "", info.uid); } taosArrayDestroy(res); - - pListInfo->pGroupList = taosArrayInit(4, POINTER_BYTES); - if (pListInfo->pGroupList == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - - // put into list as default group, remove it if grouping sorting is required later - taosArrayPush(pListInfo->pGroupList, &pListInfo->pTableList); return code; } @@ -1068,7 +1152,7 @@ SArray* extractPartitionColInfo(SNodeList* pNodeList) { int32_t extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols, int32_t type, SColMatchInfo* pMatchInfo) { - size_t numOfCols = LIST_LENGTH(pNodeList); + size_t numOfCols = LIST_LENGTH(pNodeList); int32_t code = 0; pMatchInfo->matchType = type; @@ -1411,10 +1495,6 @@ void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray while (i < numOfSrcCols && j < taosArrayGetSize(pColMatchInfo)) { SColumnInfoData* p = taosArrayGet(pCols, i); SColMatchItem* pmInfo = taosArrayGet(pColMatchInfo, j); -/* if (!outputEveryColumn && pmInfo->reserved) { - j++; - continue; - }*/ if (p->info.colId == pmInfo->colId) { SColumnInfoData* pDst = taosArrayGet(pBlock->pDataBlock, pmInfo->dstSlotId); @@ -1592,9 +1672,6 @@ bool hasLimitOffsetInfo(SLimitInfo* pLimitInfo) { pLimitInfo->slimit.offset != -1); } -static int64_t getLimit(const SNode* pLimit) { return NULL == pLimit ? -1 : ((SLimitNode*)pLimit)->limit; } -static int64_t getOffset(const SNode* pLimit) { return NULL == pLimit ? -1 : ((SLimitNode*)pLimit)->offset; } - void initLimitInfo(const SNode* pLimit, const SNode* pSLimit, SLimitInfo* pLimitInfo) { SLimit limit = {.limit = getLimit(pLimit), .offset = getOffset(pLimit)}; SLimit slimit = {.limit = getLimit(pSLimit), .offset = getOffset(pSLimit)}; @@ -1604,3 +1681,257 @@ void initLimitInfo(const SNode* pLimit, const SNode* pSLimit, SLimitInfo* pLimit pLimitInfo->remainOffset = limit.offset; pLimitInfo->remainGroupOffset = slimit.offset; } + +uint64_t tableListGetSize(const STableListInfo* pTableList) { + ASSERT(taosArrayGetSize(pTableList->pTableList) == taosHashGetSize(pTableList->map)); + return taosArrayGetSize(pTableList->pTableList); +} + +uint64_t tableListGetSuid(const STableListInfo* pTableList) { return pTableList->suid; } + +STableKeyInfo* tableListGetInfo(const STableListInfo* pTableList, int32_t index) { + if (taosArrayGetSize(pTableList->pTableList) == 0) { + return NULL; + } + + return taosArrayGet(pTableList->pTableList, index); +} + +uint64_t getTableGroupId(const STableListInfo* pTableList, uint64_t tableUid) { + int32_t* slot = taosHashGet(pTableList->map, &tableUid, sizeof(tableUid)); + ASSERT(pTableList->map != NULL && slot != NULL); + + STableKeyInfo* pKeyInfo = taosArrayGet(pTableList->pTableList, *slot); + ASSERT(pKeyInfo->uid == tableUid); + + return pKeyInfo->groupId; +} + +// TODO handle the group offset info, fix it, the rule of group output will be broken by this function +int32_t tableListAddTableInfo(STableListInfo* pTableList, uint64_t uid, uint64_t gid) { + if (pTableList->map == NULL) { + ASSERT(taosArrayGetSize(pTableList->pTableList) == 0); + pTableList->map = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); + } + + STableKeyInfo keyInfo = {.uid = uid, .groupId = gid}; + taosArrayPush(pTableList->pTableList, &keyInfo); + + int32_t slot = (int32_t)taosArrayGetSize(pTableList->pTableList) - 1; + taosHashPut(pTableList->map, &uid, sizeof(uid), &slot, sizeof(slot)); + + qDebug("uid:%" PRIu64 ", groupId:%" PRIu64 " added into table list, slot:%d, total:%d", uid, gid, slot, slot + 1); + return TSDB_CODE_SUCCESS; +} + +int32_t tableListGetGroupList(const STableListInfo* pTableList, int32_t ordinalGroupIndex, STableKeyInfo** pKeyInfo, + int32_t* size) { + int32_t total = tableListGetOutputGroups(pTableList); + if (ordinalGroupIndex < 0 || ordinalGroupIndex >= total) { + return TSDB_CODE_INVALID_PARA; + } + + // here handle two special cases: + // 1. only one group exists, and 2. one table exists for each group. + if (total == 1) { + *size = tableListGetSize(pTableList); + *pKeyInfo = (*size == 0) ? NULL : taosArrayGet(pTableList->pTableList, 0); + return TSDB_CODE_SUCCESS; + } else if (total == tableListGetSize(pTableList)) { + *size = 1; + *pKeyInfo = taosArrayGet(pTableList->pTableList, ordinalGroupIndex); + return TSDB_CODE_SUCCESS; + } + + int32_t offset = pTableList->groupOffset[ordinalGroupIndex]; + if (ordinalGroupIndex < total - 1) { + *size = pTableList->groupOffset[offset + 1] - pTableList->groupOffset[offset]; + } else { + *size = total - pTableList->groupOffset[offset] - 1; + } + + *pKeyInfo = taosArrayGet(pTableList->pTableList, offset); + return TSDB_CODE_SUCCESS; +} + +int32_t tableListGetOutputGroups(const STableListInfo* pTableList) { return pTableList->numOfOuputGroups; } + +bool oneTableForEachGroup(const STableListInfo* pTableList) { return pTableList->oneTableForEachGroup; } + +STableListInfo* tableListCreate() { + STableListInfo* pListInfo = taosMemoryCalloc(1, sizeof(STableListInfo)); + if (pListInfo == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + + pListInfo->pTableList = taosArrayInit(4, sizeof(STableKeyInfo)); + if (pListInfo->pTableList == NULL) { + goto _error; + } + + pListInfo->map = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); + if (pListInfo->map == NULL) { + goto _error; + } + + pListInfo->numOfOuputGroups = 1; + return pListInfo; + +_error: + tableListDestroy(pListInfo); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; +} + +void* tableListDestroy(STableListInfo* pTableListInfo) { + if (pTableListInfo == NULL) { + return NULL; + } + + pTableListInfo->pTableList = taosArrayDestroy(pTableListInfo->pTableList); + taosMemoryFreeClear(pTableListInfo->groupOffset); + + taosHashCleanup(pTableListInfo->map); + + pTableListInfo->pTableList = NULL; + pTableListInfo->map = NULL; + taosMemoryFree(pTableListInfo); + return NULL; +} + +void tableListClear(STableListInfo* pTableListInfo) { + if (pTableListInfo == NULL) { + return; + } + + taosArrayClear(pTableListInfo->pTableList); + taosHashClear(pTableListInfo->map); + taosMemoryFree(pTableListInfo->groupOffset); + pTableListInfo->numOfOuputGroups = 1; + pTableListInfo->oneTableForEachGroup = false; +} + +static int32_t orderbyGroupIdComparFn(const void* p1, const void* p2) { + STableKeyInfo* pInfo1 = (STableKeyInfo*)p1; + STableKeyInfo* pInfo2 = (STableKeyInfo*)p2; + + if (pInfo1->groupId == pInfo2->groupId) { + return 0; + } else { + return pInfo1->groupId < pInfo2->groupId ? -1 : 1; + } +} + +static int32_t sortTableGroup(STableListInfo* pTableListInfo) { + taosArraySort(pTableListInfo->pTableList, orderbyGroupIdComparFn); + int32_t size = taosArrayGetSize(pTableListInfo->pTableList); + + SArray* pList = taosArrayInit(4, sizeof(int32_t)); + + STableKeyInfo* pInfo = taosArrayGet(pTableListInfo->pTableList, 0); + uint64_t gid = pInfo->groupId; + + int32_t start = 0; + taosArrayPush(pList, &start); + + for (int32_t i = 1; i < size; ++i) { + pInfo = taosArrayGet(pTableListInfo->pTableList, i); + if (pInfo->groupId != gid) { + taosArrayPush(pList, &i); + gid = pInfo->groupId; + } + } + + pTableListInfo->numOfOuputGroups = taosArrayGetSize(pList); + pTableListInfo->groupOffset = taosMemoryMalloc(sizeof(int32_t) * pTableListInfo->numOfOuputGroups); + if (pTableListInfo->groupOffset == NULL) { + taosArrayDestroy(pList); + return TSDB_CODE_OUT_OF_MEMORY; + } + + memcpy(pTableListInfo->groupOffset, taosArrayGet(pList, 0), sizeof(int32_t) * pTableListInfo->numOfOuputGroups); + taosArrayDestroy(pList); + return TDB_CODE_SUCCESS; +} + +int32_t buildGroupIdMapForAllTables(STableListInfo* pTableListInfo, SReadHandle* pHandle, SNodeList* group, + bool groupSort) { + int32_t code = TSDB_CODE_SUCCESS; + ASSERT(pTableListInfo->map != NULL); + + bool groupByTbname = groupbyTbname(group); + size_t numOfTables = taosArrayGetSize(pTableListInfo->pTableList); + if (group == NULL || groupByTbname) { + for (int32_t i = 0; i < numOfTables; i++) { + STableKeyInfo* info = taosArrayGet(pTableListInfo->pTableList, i); + info->groupId = groupByTbname ? info->uid : 0; + } + + pTableListInfo->oneTableForEachGroup = groupByTbname; + + if (groupSort && groupByTbname) { + taosArraySort(pTableListInfo->pTableList, orderbyGroupIdComparFn); + pTableListInfo->numOfOuputGroups = numOfTables; + } else { + pTableListInfo->numOfOuputGroups = 1; + } + } else { + code = getColInfoResultForGroupby(pHandle->meta, group, pTableListInfo); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + if (groupSort) { + code = sortTableGroup(pTableListInfo); + } + } + + // add all table entry in the hash map + size_t size = taosArrayGetSize(pTableListInfo->pTableList); + for (int32_t i = 0; i < size; ++i) { + STableKeyInfo* p = taosArrayGet(pTableListInfo->pTableList, i); + taosHashPut(pTableListInfo->map, &p->uid, sizeof(uint64_t), &i, sizeof(int32_t)); + } + + return code; +} + +int32_t createScanTableListInfo(SScanPhysiNode* pScanNode, SNodeList* pGroupTags, bool groupSort, SReadHandle* pHandle, + STableListInfo* pTableListInfo, SNode* pTagCond, SNode* pTagIndexCond, + struct SExecTaskInfo* pTaskInfo) { + int64_t st = taosGetTimestampUs(); + const char* idStr = GET_TASKID(pTaskInfo); + + if (pHandle == NULL) { + qError("invalid handle, in creating operator tree, %s", idStr); + return TSDB_CODE_INVALID_PARA; + } + + int32_t code = getTableList(pHandle->meta, pHandle->vnode, pScanNode, pTagCond, pTagIndexCond, pTableListInfo); + if (code != TSDB_CODE_SUCCESS) { + qError("failed to getTableList, code: %s", tstrerror(code)); + return code; + } + + ASSERT(pTableListInfo->numOfOuputGroups == 1); + + int64_t st1 = taosGetTimestampUs(); + pTaskInfo->cost.extractListTime = (st1 - st) / 1000.0; + qDebug("extract queried table list completed, elapsed time:%.2f ms %s", pTaskInfo->cost.extractListTime, idStr); + + if (taosArrayGetSize(pTableListInfo->pTableList) == 0) { + qDebug("no table qualified for query, %s" PRIx64, idStr); + return TSDB_CODE_SUCCESS; + } + + code = buildGroupIdMapForAllTables(pTableListInfo, pHandle, pGroupTags, groupSort); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + pTaskInfo->cost.groupIdMapTime = (taosGetTimestampUs() - st1) / 1000.0; + qDebug("generate group id map completed, elapsed time:%.2f ms %s", pTaskInfo->cost.groupIdMapTime, idStr); + + return TSDB_CODE_SUCCESS; +} diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index d7cec255afda106bd9d092c13a4cca298ae606cd..1aa9a3c61359cc3a0ad76df577c5ce3d6f061c8b 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -30,6 +30,66 @@ static void cleanupRefPool() { taosCloseRef(ref); } +static int32_t doSetSMABlock(SOperatorInfo* pOperator, void* input, size_t numOfBlocks, int32_t type, char* id) { + ASSERT(pOperator != NULL); + if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) { + if (pOperator->numOfDownstream == 0) { + qError("failed to find stream scan operator to set the input data block, %s" PRIx64, id); + return TSDB_CODE_QRY_APP_ERROR; + } + + if (pOperator->numOfDownstream > 1) { // not handle this in join query + qError("join not supported for stream block scan, %s" PRIx64, id); + return TSDB_CODE_QRY_APP_ERROR; + } + pOperator->status = OP_NOT_OPENED; + return doSetSMABlock(pOperator->pDownstream[0], input, numOfBlocks, type, id); + } else { + pOperator->status = OP_NOT_OPENED; + + SStreamScanInfo* pInfo = pOperator->info; + + if (type == STREAM_INPUT__MERGED_SUBMIT) { + for (int32_t i = 0; i < numOfBlocks; i++) { + SSubmitReq* pReq = *(void**)POINTER_SHIFT(input, i * sizeof(void*)); + taosArrayPush(pInfo->pBlockLists, &pReq); + } + pInfo->blockType = STREAM_INPUT__DATA_SUBMIT; + } else if (type == STREAM_INPUT__DATA_SUBMIT) { + taosArrayPush(pInfo->pBlockLists, &input); + pInfo->blockType = STREAM_INPUT__DATA_SUBMIT; + } else if (type == STREAM_INPUT__DATA_BLOCK) { + for (int32_t i = 0; i < numOfBlocks; ++i) { + SSDataBlock* pDataBlock = &((SSDataBlock*)input)[i]; + taosArrayPush(pInfo->pBlockLists, &pDataBlock); + } + pInfo->blockType = STREAM_INPUT__DATA_BLOCK; + } + + return TSDB_CODE_SUCCESS; + } +} + +static int32_t doSetStreamOpOpen(SOperatorInfo* pOperator, char* id) { + { + ASSERT(pOperator != NULL); + if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) { + if (pOperator->numOfDownstream == 0) { + qError("failed to find stream scan operator to set the input data block, %s" PRIx64, id); + return TSDB_CODE_QRY_APP_ERROR; + } + + if (pOperator->numOfDownstream > 1) { // not handle this in join query + qError("join not supported for stream block scan, %s" PRIx64, id); + return TSDB_CODE_QRY_APP_ERROR; + } + pOperator->status = OP_NOT_OPENED; + return doSetStreamOpOpen(pOperator->pDownstream[0], id); + } + } + return 0; +} + static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t numOfBlocks, int32_t type, char* id) { ASSERT(pOperator != NULL); if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) { @@ -77,7 +137,22 @@ static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t nu } } -static FORCE_INLINE void streamInputBlockDataDestory(void* pBlock) { blockDataDestroy((SSDataBlock*)pBlock); } +int32_t qSetStreamOpOpen(qTaskInfo_t tinfo) { + if (tinfo == NULL) { + return TSDB_CODE_QRY_APP_ERROR; + } + + SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; + + int32_t code = doSetStreamOpOpen(pTaskInfo->pRoot, GET_TASKID(pTaskInfo)); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed to set the stream block data", GET_TASKID(pTaskInfo)); + } else { + qDebug("%s set the stream block successfully", GET_TASKID(pTaskInfo)); + } + + return code; +} int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type) { if (tinfo == NULL) { @@ -100,6 +175,27 @@ int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numO return code; } +int32_t qSetSMAInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type) { + if (tinfo == NULL) { + return TSDB_CODE_QRY_APP_ERROR; + } + + if (pBlocks == NULL || numOfBlocks == 0) { + return TSDB_CODE_SUCCESS; + } + + SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; + + int32_t code = doSetSMABlock(pTaskInfo->pRoot, (void*)pBlocks, numOfBlocks, type, GET_TASKID(pTaskInfo)); + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed to set the sma block data", GET_TASKID(pTaskInfo)); + } else { + qDebug("%s set the sma block successfully", GET_TASKID(pTaskInfo)); + } + + return code; +} + qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* readers, int32_t* numOfCols, SSchemaWrapper** pSchema) { if (msg == NULL) { // create raw scan @@ -225,17 +321,12 @@ static SArray* filterUnqualifiedTables(const SStreamScanInfo* pScanInfo, const S } int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bool isAdd) { - SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; - STableListInfo* pListInfo = &pTaskInfo->tableqinfoList; + SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; if (isAdd) { qDebug("add %d tables id into query list, %s", (int32_t)taosArrayGetSize(tableIdList), pTaskInfo->id.str); } - if (pListInfo->map == NULL) { - pListInfo->map = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); - } - // traverse to the stream scanner node to add this table id SOperatorInfo* pInfo = pTaskInfo->pRoot; while (pInfo->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) { @@ -246,8 +337,10 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo SStreamScanInfo* pScanInfo = pInfo->info; if (isAdd) { // add new table id SArray* qa = filterUnqualifiedTables(pScanInfo, tableIdList, GET_TASKID(pTaskInfo)); + int32_t numOfQualifiedTables = taosArrayGetSize(qa); + + qDebug(" %d qualified child tables added into stream scanner", numOfQualifiedTables); - qDebug(" %d qualified child tables added into stream scanner", (int32_t)taosArrayGetSize(qa)); code = tqReaderAddTbUidList(pScanInfo->tqReader, qa); if (code != TSDB_CODE_SUCCESS) { taosArrayDestroy(qa); @@ -267,7 +360,9 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo } } - for (int32_t i = 0; i < taosArrayGetSize(qa); ++i) { + STableListInfo* pTableListInfo = pTaskInfo->pTableInfoList; + + for (int32_t i = 0; i < numOfQualifiedTables; ++i) { uint64_t* uid = taosArrayGet(qa, i); STableKeyInfo keyInfo = {.uid = *uid, .groupId = 0}; @@ -297,8 +392,8 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo if (!exists) { #endif - taosArrayPush(pTaskInfo->tableqinfoList.pTableList, &keyInfo); - taosHashPut(pTaskInfo->tableqinfoList.map, uid, sizeof(*uid), &keyInfo.groupId, sizeof(keyInfo.groupId)); + + tableListAddTableInfo(pTableListInfo, keyInfo.uid, keyInfo.groupId); } if (keyBuf != NULL) { @@ -646,8 +741,7 @@ int32_t qStreamInput(qTaskInfo_t tinfo, void* pItem) { int32_t qStreamSourceRecoverStep1(qTaskInfo_t tinfo, int64_t ver) { SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM); - pTaskInfo->streamInfo.recoverStartVer = 0; - pTaskInfo->streamInfo.recoverEndVer = ver; + pTaskInfo->streamInfo.fillHistoryVer1 = ver; pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__PREPARE1; return 0; } @@ -655,8 +749,7 @@ int32_t qStreamSourceRecoverStep1(qTaskInfo_t tinfo, int64_t ver) { int32_t qStreamSourceRecoverStep2(qTaskInfo_t tinfo, int64_t ver) { SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; ASSERT(pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM); - pTaskInfo->streamInfo.recoverStartVer = pTaskInfo->streamInfo.recoverEndVer; - pTaskInfo->streamInfo.recoverEndVer = ver; + pTaskInfo->streamInfo.fillHistoryVer2 = ver; pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__PREPARE2; return 0; } @@ -677,22 +770,44 @@ int32_t qStreamSetParamForRecover(qTaskInfo_t tinfo) { pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL || pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL) { SStreamIntervalOperatorInfo* pInfo = pOperator->info; - pTaskInfo->streamInfo.triggerSaved = pInfo->twAggSup.calTrigger; - pTaskInfo->streamInfo.deleteMarkSaved = pInfo->twAggSup.deleteMark; + ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE || + pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE); + ASSERT(pInfo->twAggSup.calTriggerSaved == 0); + ASSERT(pInfo->twAggSup.deleteMarkSaved == 0); + + qInfo("save stream param for interval: %d, %" PRId64, pInfo->twAggSup.calTrigger, pInfo->twAggSup.deleteMark); + + pInfo->twAggSup.calTriggerSaved = pInfo->twAggSup.calTrigger; + pInfo->twAggSup.deleteMarkSaved = pInfo->twAggSup.deleteMark; pInfo->twAggSup.calTrigger = STREAM_TRIGGER_AT_ONCE; pInfo->twAggSup.deleteMark = INT64_MAX; + } else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION || pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION || pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION) { SStreamSessionAggOperatorInfo* pInfo = pOperator->info; - pTaskInfo->streamInfo.triggerSaved = pInfo->twAggSup.calTrigger; - pTaskInfo->streamInfo.deleteMarkSaved = pInfo->twAggSup.deleteMark; + ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE || + pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE); + ASSERT(pInfo->twAggSup.calTriggerSaved == 0); + ASSERT(pInfo->twAggSup.deleteMarkSaved == 0); + + qInfo("save stream param for session: %d, %" PRId64, pInfo->twAggSup.calTrigger, pInfo->twAggSup.deleteMark); + + pInfo->twAggSup.calTriggerSaved = pInfo->twAggSup.calTrigger; + pInfo->twAggSup.deleteMarkSaved = pInfo->twAggSup.deleteMark; pInfo->twAggSup.calTrigger = STREAM_TRIGGER_AT_ONCE; pInfo->twAggSup.deleteMark = INT64_MAX; } else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE) { SStreamStateAggOperatorInfo* pInfo = pOperator->info; - pTaskInfo->streamInfo.triggerSaved = pInfo->twAggSup.calTrigger; - pTaskInfo->streamInfo.deleteMarkSaved = pInfo->twAggSup.deleteMark; + ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE || + pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE); + ASSERT(pInfo->twAggSup.calTriggerSaved == 0); + ASSERT(pInfo->twAggSup.deleteMarkSaved == 0); + + qInfo("save stream param for state: %d, %" PRId64, pInfo->twAggSup.calTrigger, pInfo->twAggSup.deleteMark); + + pInfo->twAggSup.calTriggerSaved = pInfo->twAggSup.calTrigger; + pInfo->twAggSup.deleteMarkSaved = pInfo->twAggSup.deleteMark; pInfo->twAggSup.calTrigger = STREAM_TRIGGER_AT_ONCE; pInfo->twAggSup.deleteMark = INT64_MAX; } @@ -722,21 +837,36 @@ int32_t qStreamRestoreParam(qTaskInfo_t tinfo) { pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL || pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL) { SStreamIntervalOperatorInfo* pInfo = pOperator->info; - - pInfo->twAggSup.calTrigger = pTaskInfo->streamInfo.triggerSaved; - pInfo->twAggSup.deleteMark = pTaskInfo->streamInfo.deleteMarkSaved; + ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE); + ASSERT(pInfo->twAggSup.deleteMark == INT64_MAX); + + pInfo->twAggSup.calTrigger = pInfo->twAggSup.calTriggerSaved; + pInfo->twAggSup.deleteMark = pInfo->twAggSup.deleteMarkSaved; + ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE || + pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE); + qInfo("restore stream param for interval: %d, %" PRId64, pInfo->twAggSup.calTrigger, pInfo->twAggSup.deleteMark); } else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION || pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION || pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION) { SStreamSessionAggOperatorInfo* pInfo = pOperator->info; - - pInfo->twAggSup.calTrigger = pTaskInfo->streamInfo.triggerSaved; - pInfo->twAggSup.deleteMark = pTaskInfo->streamInfo.deleteMarkSaved; + ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE); + ASSERT(pInfo->twAggSup.deleteMark == INT64_MAX); + + pInfo->twAggSup.calTrigger = pInfo->twAggSup.calTriggerSaved; + pInfo->twAggSup.deleteMark = pInfo->twAggSup.deleteMarkSaved; + ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE || + pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE); + qInfo("restore stream param for session: %d, %" PRId64, pInfo->twAggSup.calTrigger, pInfo->twAggSup.deleteMark); } else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE) { SStreamStateAggOperatorInfo* pInfo = pOperator->info; - - pInfo->twAggSup.calTrigger = pTaskInfo->streamInfo.triggerSaved; - pInfo->twAggSup.deleteMark = pTaskInfo->streamInfo.deleteMarkSaved; + ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE); + ASSERT(pInfo->twAggSup.deleteMark == INT64_MAX); + + pInfo->twAggSup.calTrigger = pInfo->twAggSup.calTriggerSaved; + pInfo->twAggSup.deleteMark = pInfo->twAggSup.deleteMarkSaved; + ASSERT(pInfo->twAggSup.calTrigger == STREAM_TRIGGER_AT_ONCE || + pInfo->twAggSup.calTrigger == STREAM_TRIGGER_WINDOW_CLOSE); + qInfo("restore stream param for state: %d, %" PRId64, pInfo->twAggSup.calTrigger, pInfo->twAggSup.deleteMark); } // iterate operator tree @@ -862,8 +992,8 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT int64_t ts = pOffset->ts; if (uid == 0) { - if (taosArrayGetSize(pTaskInfo->tableqinfoList.pTableList) != 0) { - STableKeyInfo* pTableInfo = taosArrayGet(pTaskInfo->tableqinfoList.pTableList, 0); + if (tableListGetSize(pTaskInfo->pTableInfoList) != 0) { + STableKeyInfo* pTableInfo = tableListGetInfo(pTaskInfo->pTableInfoList, 0); uid = pTableInfo->uid; ts = INT64_MIN; } else { @@ -874,7 +1004,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT /*if (pTaskInfo->streamInfo.lastStatus.type != TMQ_OFFSET__SNAPSHOT_DATA ||*/ /*pTaskInfo->streamInfo.lastStatus.uid != uid || pTaskInfo->streamInfo.lastStatus.ts != ts) {*/ STableScanInfo* pTableScanInfo = pInfo->pTableScanOp->info; - int32_t tableSz = taosArrayGetSize(pTaskInfo->tableqinfoList.pTableList); + int32_t numOfTables = tableListGetSize(pTaskInfo->pTableInfoList); #ifndef NDEBUG qDebug("switch to next table %" PRId64 " (cursor %d), %" PRId64 " rows returned", uid, @@ -883,8 +1013,8 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT #endif bool found = false; - for (int32_t i = 0; i < tableSz; i++) { - STableKeyInfo* pTableInfo = taosArrayGet(pTaskInfo->tableqinfoList.pTableList, i); + for (int32_t i = 0; i < numOfTables; i++) { + STableKeyInfo* pTableInfo = tableListGetInfo(pTaskInfo->pTableInfoList, i); if (pTableInfo->uid == uid) { found = true; pTableScanInfo->currentTable = i; @@ -896,14 +1026,18 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT ASSERT(found); if (pTableScanInfo->dataReader == NULL) { - if (tsdbReaderOpen(pTableScanInfo->readHandle.vnode, &pTableScanInfo->cond, - pTaskInfo->tableqinfoList.pTableList, &pTableScanInfo->dataReader, NULL) < 0 || + STableKeyInfo* pList = tableListGetInfo(pTaskInfo->pTableInfoList, 0); + int32_t num = tableListGetSize(pTaskInfo->pTableInfoList); + + if (tsdbReaderOpen(pTableScanInfo->readHandle.vnode, &pTableScanInfo->cond, pList, num, + &pTableScanInfo->dataReader, NULL) < 0 || pTableScanInfo->dataReader == NULL) { ASSERT(0); } } - tsdbSetTableId(pTableScanInfo->dataReader, uid); + STableKeyInfo tki = {.uid = uid}; + tsdbSetTableList(pTableScanInfo->dataReader, &tki, 1); int64_t oldSkey = pTableScanInfo->cond.twindows.skey; pTableScanInfo->cond.twindows.skey = ts + 1; tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond); @@ -911,7 +1045,7 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT pTableScanInfo->scanTimes = 0; qDebug("tsdb reader offset seek to uid %" PRId64 " ts %" PRId64 ", table cur set to %d , all table num %d", uid, - ts, pTableScanInfo->currentTable, tableSz); + ts, pTableScanInfo->currentTable, numOfTables); /*}*/ } else { ASSERT(0); @@ -927,16 +1061,28 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT SMetaTableInfo mtInfo = getUidfromSnapShot(sContext); tsdbReaderClose(pInfo->dataReader); pInfo->dataReader = NULL; + cleanupQueryTableDataCond(&pTaskInfo->streamInfo.tableCond); - taosArrayDestroy(pTaskInfo->tableqinfoList.pTableList); - if (mtInfo.uid == 0) return 0; // no data + tableListClear(pTaskInfo->pTableInfoList); + + if (mtInfo.uid == 0) { + return 0; // no data + } initQueryTableDataCondForTmq(&pTaskInfo->streamInfo.tableCond, sContext, &mtInfo); pTaskInfo->streamInfo.tableCond.twindows.skey = pOffset->ts; - pTaskInfo->tableqinfoList.pTableList = taosArrayInit(1, sizeof(STableKeyInfo)); - taosArrayPush(pTaskInfo->tableqinfoList.pTableList, &(STableKeyInfo){.uid = mtInfo.uid, .groupId = 0}); - tsdbReaderOpen(pInfo->vnode, &pTaskInfo->streamInfo.tableCond, pTaskInfo->tableqinfoList.pTableList, - &pInfo->dataReader, NULL); + + if (pTaskInfo->pTableInfoList == NULL) { + pTaskInfo->pTableInfoList = tableListCreate(); + } + + tableListAddTableInfo(pTaskInfo->pTableInfoList, mtInfo.uid, 0); + + STableKeyInfo* pList = tableListGetInfo(pTaskInfo->pTableInfoList, 0); + int32_t size = tableListGetSize(pTaskInfo->pTableInfoList); + ASSERT(size == 1); + + tsdbReaderOpen(pInfo->vnode, &pTaskInfo->streamInfo.tableCond, pList, size, &pInfo->dataReader, NULL); cleanupQueryTableDataCond(&pTaskInfo->streamInfo.tableCond); strcpy(pTaskInfo->streamInfo.tbName, mtInfo.tbName); @@ -960,3 +1106,24 @@ int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subT } return 0; } + +void qProcessRspMsg(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { + SMsgSendInfo* pSendInfo = (SMsgSendInfo*)pMsg->info.ahandle; + assert(pMsg->info.ahandle != NULL); + + SDataBuf buf = {.len = pMsg->contLen, .pData = NULL}; + + if (pMsg->contLen > 0) { + buf.pData = taosMemoryCalloc(1, pMsg->contLen); + if (buf.pData == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + pMsg->code = TSDB_CODE_OUT_OF_MEMORY; + } else { + memcpy(buf.pData, pMsg->pCont, pMsg->contLen); + } + } + + pSendInfo->fp(pSendInfo->param, &buf, pMsg->code); + rpcFreeCont(pMsg->pCont); + destroySendMsgInfo(pSendInfo); +} \ No newline at end of file diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 75db42fccc73f34214bbec7677df201116f210eb..709e981a1ff6bcb01a0f4765ec97eaf5c428c180 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -32,7 +32,6 @@ #include "index.h" #include "query.h" #include "tcompare.h" -#include "tcompression.h" #include "thash.h" #include "ttypes.h" #include "vnode.h" @@ -87,15 +86,15 @@ static void releaseQueryBuf(size_t numOfTables); static void destroyFillOperatorInfo(void* param); static void destroyProjectOperatorInfo(void* param); -static void destroyOrderOperatorInfo(void* param); +static void destroySortOperatorInfo(void* param); static void destroyAggOperatorInfo(void* param); static void destroyIntervalOperatorInfo(void* param); -static void destroyExchangeOperatorInfo(void* param); + static void destroyOperatorInfo(SOperatorInfo* pOperator); -void doSetOperatorCompleted(SOperatorInfo* pOperator) { +void setOperatorCompleted(SOperatorInfo* pOperator) { pOperator->status = OP_EXEC_DONE; ASSERT(pOperator->pTaskInfo != NULL); @@ -103,18 +102,27 @@ void doSetOperatorCompleted(SOperatorInfo* pOperator) { setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED); } +void setOperatorInfo(SOperatorInfo* pOperator, const char* name, int32_t type, bool blocking, int32_t status, + void* pInfo, SExecTaskInfo* pTaskInfo) { + pOperator->name = (char*)name; + pOperator->operatorType = type; + pOperator->blocking = blocking; + pOperator->status = status; + pOperator->info = pInfo; + pOperator->pTaskInfo = pTaskInfo; +} + int32_t operatorDummyOpenFn(SOperatorInfo* pOperator) { OPTR_SET_OPENED(pOperator); pOperator->cost.openCost = 0; return TSDB_CODE_SUCCESS; } -SOperatorFpSet createOperatorFpSet(__optr_open_fn_t openFn, __optr_fn_t nextFn, __optr_fn_t streamFn, - __optr_fn_t cleanup, __optr_close_fn_t closeFn, __optr_explain_fn_t explain) { +SOperatorFpSet createOperatorFpSet(__optr_open_fn_t openFn, __optr_fn_t nextFn, __optr_fn_t cleanup, + __optr_close_fn_t closeFn, __optr_explain_fn_t explain) { SOperatorFpSet fpSet = { ._openFn = openFn, .getNextFn = nextFn, - .getStreamResFn = streamFn, .cleanupFn = cleanup, .closeFn = closeFn, .getExplainFn = explain, @@ -322,7 +330,7 @@ void initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQueryWindow pColData->info.type = TSDB_DATA_TYPE_TIMESTAMP; pColData->info.bytes = sizeof(int64_t); - colInfoDataEnsureCapacity(pColData, 5); + colInfoDataEnsureCapacity(pColData, 5, false); colDataAppendInt64(pColData, 0, &pQueryWindow->skey); colDataAppendInt64(pColData, 1, &pQueryWindow->ekey); @@ -439,7 +447,7 @@ static int32_t doCreateConstantValColumnInfo(SInputColumnInfoData* pInput, SFunc pColInfo = pInput->pData[paramIndex]; } - colInfoDataEnsureCapacity(pColInfo, numOfRows); + colInfoDataEnsureCapacity(pColInfo, numOfRows, false); int8_t type = pFuncParam->param.nType; if (type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_UBIGINT) { @@ -494,7 +502,7 @@ static int32_t doSetInputDataBlock(SExprSupp* pExprSup, SSDataBlock* pBlock, int // todo: refactor this if (fmIsImplicitTsFunc(pCtx[i].functionId) && (j == pOneExpr->base.numOfParams - 1)) { pInput->pPTS = pInput->pData[j]; // in case of merge function, this is not always the ts column data. - // ASSERT(pInput->pPTS->info.type == TSDB_DATA_TYPE_TIMESTAMP); + // ASSERT(pInput->pPTS->info.type == TSDB_DATA_TYPE_TIMESTAMP); } ASSERT(pInput->pData[j] != NULL); } else if (pFuncParam->type == FUNC_PARAM_TYPE_VALUE) { @@ -574,6 +582,9 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc // if the source equals to the destination, it is to create a new column as the result of scalar // function or some operators. bool createNewColModel = (pResult == pSrcBlock); + if (createNewColModel) { + blockDataEnsureCapacity(pResult, pResult->info.rows); + } int32_t numOfRows = 0; @@ -623,6 +634,7 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc int32_t startOffset = createNewColModel ? 0 : pResult->info.rows; ASSERT(pResult->info.capacity > 0); + colDataMergeCol(pResColData, startOffset, (int32_t*)&pResult->info.capacity, &idata, dest.numOfRows); colDataDestroy(&idata); @@ -844,57 +856,6 @@ STimeWindow getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int return win; } -#if 0 -static bool overlapWithTimeWindow(STaskAttr* pQueryAttr, SDataBlockInfo* pBlockInfo) { - STimeWindow w = {0}; - - TSKEY sk = TMIN(pQueryAttr->window.skey, pQueryAttr->window.ekey); - TSKEY ek = TMAX(pQueryAttr->window.skey, pQueryAttr->window.ekey); - - if (true) { - // getAlignQueryTimeWindow(pQueryAttr, pBlockInfo->window.skey, sk, ek, &w); - assert(w.ekey >= pBlockInfo->window.skey); - - if (w.ekey < pBlockInfo->window.ekey) { - return true; - } - - while (1) { - // getNextTimeWindow(pQueryAttr, &w); - if (w.skey > pBlockInfo->window.ekey) { - break; - } - - assert(w.ekey > pBlockInfo->window.ekey); - if (w.skey <= pBlockInfo->window.ekey && w.skey > pBlockInfo->window.skey) { - return true; - } - } - } else { - // getAlignQueryTimeWindow(pQueryAttr, pBlockInfo->window.ekey, sk, ek, &w); - assert(w.skey <= pBlockInfo->window.ekey); - - if (w.skey > pBlockInfo->window.skey) { - return true; - } - - while (1) { - // getNextTimeWindow(pQueryAttr, &w); - if (w.ekey < pBlockInfo->window.skey) { - break; - } - - assert(w.skey < pBlockInfo->window.skey); - if (w.ekey < pBlockInfo->window.ekey && w.ekey >= pBlockInfo->window.skey) { - return true; - } - } - } - - return false; -} -#endif - int32_t loadDataBlockOnDemand(SExecTaskInfo* pTaskInfo, STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, uint32_t* status) { *status = BLK_DATA_NOT_LOAD; @@ -1086,41 +1047,24 @@ void setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numO static void extractQualifiedTupleByFilterResult(SSDataBlock* pBlock, const SColumnInfoData* p, bool keep, int32_t status); -void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock, SColMatchInfo* pColMatchInfo, SFilterInfo* pFilterInfo) { - if (pFilterNode == NULL || pBlock->info.rows == 0) { +void doFilter(SSDataBlock* pBlock, SFilterInfo* pFilterInfo, SColMatchInfo* pColMatchInfo) { + if (pFilterInfo == NULL || pBlock->info.rows == 0) { return; } - SFilterInfo* filter = pFilterInfo; - int64_t st = taosGetTimestampUs(); - - // pError("start filter"); - - // todo move to the initialization function - int32_t code = 0; - bool needFree = false; - if (filter == NULL) { - needFree = true; - code = filterInitFromNode((SNode*)pFilterNode, &filter, 0); - } - SFilterColumnParam param1 = {.numOfCols = taosArrayGetSize(pBlock->pDataBlock), .pDataBlock = pBlock->pDataBlock}; - code = filterSetDataFromSlotId(filter, ¶m1); + int32_t code = filterSetDataFromSlotId(pFilterInfo, ¶m1); SColumnInfoData* p = NULL; int32_t status = 0; // todo the keep seems never to be True?? - bool keep = filterExecute(filter, pBlock, &p, NULL, param1.numOfCols, &status); - - if (needFree) { - filterFreeInfo(filter); - } - + bool keep = filterExecute(pFilterInfo, pBlock, &p, NULL, param1.numOfCols, &status); extractQualifiedTupleByFilterResult(pBlock, p, keep, status); if (pColMatchInfo != NULL) { - for (int32_t i = 0; i < taosArrayGetSize(pColMatchInfo->pList); ++i) { + size_t size = taosArrayGetSize(pColMatchInfo->pList); + for (int32_t i = 0; i < size; ++i) { SColMatchItem* pInfo = taosArrayGet(pColMatchInfo->pList, i); if (pInfo->colId == PRIMARYKEY_TIMESTAMP_COL_ID) { SColumnInfoData* pColData = taosArrayGet(pBlock->pDataBlock, pInfo->dstSlotId); @@ -1447,40 +1391,18 @@ void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SG } } -static int32_t compressQueryColData(SColumnInfoData* pColRes, int32_t numOfRows, char* data, int8_t compressed) { - int32_t colSize = pColRes->info.bytes * numOfRows; - return (*(tDataTypes[pColRes->info.type].compFunc))(pColRes->pData, colSize, numOfRows, data, - colSize + COMP_OVERFLOW_BYTES, compressed, NULL, 0); -} - void queryCostStatis(SExecTaskInfo* pTaskInfo) { STaskCostInfo* pSummary = &pTaskInfo->cost; - // uint64_t hashSize = taosHashGetMemSize(pQInfo->runtimeEnv.pResultRowHashTable); - // hashSize += taosHashGetMemSize(pRuntimeEnv->tableqinfoGroupInfo.map); - // pSummary->hashSize = hashSize; - - // SResultRowPool* p = pTaskInfo->pool; - // if (p != NULL) { - // pSummary->winInfoSize = getResultRowPoolMemSize(p); - // pSummary->numOfTimeWindows = getNumOfAllocatedResultRows(p); - // } else { - // pSummary->winInfoSize = 0; - // pSummary->numOfTimeWindows = 0; - // } - SFileBlockLoadRecorder* pRecorder = pSummary->pRecoder; if (pSummary->pRecoder != NULL) { qDebug( - "%s :cost summary: elapsed time:%.2f ms, total blocks:%d, load block SMA:%d, load data block:%d, total " - "rows:%" PRId64 ", check rows:%" PRId64, - GET_TASKID(pTaskInfo), pSummary->elapsedTime / 1000.0, pRecorder->totalBlocks, pRecorder->loadBlockStatis, - pRecorder->loadBlocks, pRecorder->totalRows, pRecorder->totalCheckedRows); + "%s :cost summary: elapsed time:%.2f ms, extract tableList:%.2f ms, createGroupIdMap:%.2f ms, total blocks:%d, " + "load block SMA:%d, load data block:%d, total rows:%" PRId64 ", check rows:%" PRId64, + GET_TASKID(pTaskInfo), pSummary->elapsedTime / 1000.0, pSummary->extractListTime, pSummary->groupIdMapTime, + pRecorder->totalBlocks, pRecorder->loadBlockStatis, pRecorder->loadBlocks, pRecorder->totalRows, + pRecorder->totalCheckedRows); } - - // qDebug("QInfo:0x%"PRIx64" :cost summary: winResPool size:%.2f Kb, numOfWin:%"PRId64", tableInfoSize:%.2f Kb, - // hashTable:%.2f Kb", pQInfo->qId, pSummary->winInfoSize/1024.0, - // pSummary->numOfTimeWindows, pSummary->tableInfoSize/1024.0, pSummary->hashSize/1024.0); } // static void updateOffsetVal(STaskRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBlockInfo) { @@ -1739,582 +1661,6 @@ int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t return TSDB_CODE_SUCCESS; } -static void doDestroyTableList(STableListInfo* pTableqinfoList); - -typedef struct SFetchRspHandleWrapper { - uint32_t exchangeId; - int32_t sourceIndex; -} SFetchRspHandleWrapper; - -int32_t loadRemoteDataCallback(void* param, SDataBuf* pMsg, int32_t code) { - SFetchRspHandleWrapper* pWrapper = (SFetchRspHandleWrapper*)param; - - SExchangeInfo* pExchangeInfo = taosAcquireRef(exchangeObjRefPool, pWrapper->exchangeId); - if (pExchangeInfo == NULL) { - qWarn("failed to acquire exchange operator, since it may have been released"); - taosMemoryFree(pMsg->pData); - return TSDB_CODE_SUCCESS; - } - - int32_t index = pWrapper->sourceIndex; - SSourceDataInfo* pSourceDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, index); - - if (code == TSDB_CODE_SUCCESS) { - pSourceDataInfo->pRsp = pMsg->pData; - - SRetrieveTableRsp* pRsp = pSourceDataInfo->pRsp; - pRsp->numOfRows = htonl(pRsp->numOfRows); - pRsp->compLen = htonl(pRsp->compLen); - pRsp->numOfCols = htonl(pRsp->numOfCols); - pRsp->useconds = htobe64(pRsp->useconds); - pRsp->numOfBlocks = htonl(pRsp->numOfBlocks); - - ASSERT(pRsp != NULL); - qDebug("%s fetch rsp received, index:%d, blocks:%d, rows:%d", pSourceDataInfo->taskId, index, pRsp->numOfBlocks, - pRsp->numOfRows); - } else { - taosMemoryFree(pMsg->pData); - pSourceDataInfo->code = code; - qDebug("%s fetch rsp received, index:%d, error:%s", pSourceDataInfo->taskId, index, tstrerror(code)); - } - - pSourceDataInfo->status = EX_SOURCE_DATA_READY; - - tsem_post(&pExchangeInfo->ready); - taosReleaseRef(exchangeObjRefPool, pWrapper->exchangeId); - - return TSDB_CODE_SUCCESS; -} - -void qProcessRspMsg(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { - SMsgSendInfo* pSendInfo = (SMsgSendInfo*)pMsg->info.ahandle; - assert(pMsg->info.ahandle != NULL); - - SDataBuf buf = {.len = pMsg->contLen, .pData = NULL}; - - if (pMsg->contLen > 0) { - buf.pData = taosMemoryCalloc(1, pMsg->contLen); - if (buf.pData == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - pMsg->code = TSDB_CODE_OUT_OF_MEMORY; - } else { - memcpy(buf.pData, pMsg->pCont, pMsg->contLen); - } - } - - pSendInfo->fp(pSendInfo->param, &buf, pMsg->code); - rpcFreeCont(pMsg->pCont); - destroySendMsgInfo(pSendInfo); -} - -static int32_t doSendFetchDataRequest(SExchangeInfo* pExchangeInfo, SExecTaskInfo* pTaskInfo, int32_t sourceIndex) { - size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); - - SDownstreamSourceNode* pSource = taosArrayGet(pExchangeInfo->pSources, sourceIndex); - SSourceDataInfo* pDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, sourceIndex); - - ASSERT(pDataInfo->status == EX_SOURCE_DATA_NOT_READY); - - SFetchRspHandleWrapper* pWrapper = taosMemoryCalloc(1, sizeof(SFetchRspHandleWrapper)); - pWrapper->exchangeId = pExchangeInfo->self; - pWrapper->sourceIndex = sourceIndex; - - if (pSource->localExec) { - SDataBuf pBuf = {0}; - int32_t code = - (*pTaskInfo->localFetch.fp)(pTaskInfo->localFetch.handle, pSource->schedId, pTaskInfo->id.queryId, - pSource->taskId, 0, pSource->execId, &pBuf.pData, pTaskInfo->localFetch.explainRes); - loadRemoteDataCallback(pWrapper, &pBuf, code); - taosMemoryFree(pWrapper); - } else { - SResFetchReq* pMsg = taosMemoryCalloc(1, sizeof(SResFetchReq)); - if (NULL == pMsg) { - pTaskInfo->code = TSDB_CODE_QRY_OUT_OF_MEMORY; - taosMemoryFree(pWrapper); - return pTaskInfo->code; - } - - qDebug("%s build fetch msg and send to vgId:%d, ep:%s, taskId:0x%" PRIx64 ", execId:%d, %d/%" PRIzu, - GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->addr.epSet.eps[0].fqdn, pSource->taskId, - pSource->execId, sourceIndex, totalSources); - - pMsg->header.vgId = htonl(pSource->addr.nodeId); - pMsg->sId = htobe64(pSource->schedId); - pMsg->taskId = htobe64(pSource->taskId); - pMsg->queryId = htobe64(pTaskInfo->id.queryId); - pMsg->execId = htonl(pSource->execId); - - // send the fetch remote task result reques - SMsgSendInfo* pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); - if (NULL == pMsgSendInfo) { - taosMemoryFreeClear(pMsg); - taosMemoryFree(pWrapper); - qError("%s prepare message %d failed", GET_TASKID(pTaskInfo), (int32_t)sizeof(SMsgSendInfo)); - pTaskInfo->code = TSDB_CODE_QRY_OUT_OF_MEMORY; - return pTaskInfo->code; - } - - pMsgSendInfo->param = pWrapper; - pMsgSendInfo->paramFreeFp = taosMemoryFree; - pMsgSendInfo->msgInfo.pData = pMsg; - pMsgSendInfo->msgInfo.len = sizeof(SResFetchReq); - pMsgSendInfo->msgType = pSource->fetchMsgType; - pMsgSendInfo->fp = loadRemoteDataCallback; - - int64_t transporterId = 0; - int32_t code = - asyncSendMsgToServer(pExchangeInfo->pTransporter, &pSource->addr.epSet, &transporterId, pMsgSendInfo); - } - - return TSDB_CODE_SUCCESS; -} - -void updateLoadRemoteInfo(SLoadRemoteDataInfo* pInfo, int32_t numOfRows, int32_t dataLen, int64_t startTs, - SOperatorInfo* pOperator) { - pInfo->totalRows += numOfRows; - pInfo->totalSize += dataLen; - pInfo->totalElapsed += (taosGetTimestampUs() - startTs); - pOperator->resultInfo.totalRows += numOfRows; -} - -int32_t extractDataBlockFromFetchRsp(SSDataBlock* pRes, char* pData, SArray* pColList, char** pNextStart) { - if (pColList == NULL) { // data from other sources - blockDataCleanup(pRes); - *pNextStart = (char*)blockDecode(pRes, pData); - } else { // extract data according to pColList - char* pStart = pData; - - int32_t numOfCols = htonl(*(int32_t*)pStart); - pStart += sizeof(int32_t); - - // todo refactor:extract method - SSysTableSchema* pSchema = (SSysTableSchema*)pStart; - for (int32_t i = 0; i < numOfCols; ++i) { - SSysTableSchema* p = (SSysTableSchema*)pStart; - - p->colId = htons(p->colId); - p->bytes = htonl(p->bytes); - pStart += sizeof(SSysTableSchema); - } - - SSDataBlock* pBlock = createDataBlock(); - for (int32_t i = 0; i < numOfCols; ++i) { - SColumnInfoData idata = createColumnInfoData(pSchema[i].type, pSchema[i].bytes, pSchema[i].colId); - blockDataAppendColInfo(pBlock, &idata); - } - - blockDecode(pBlock, pStart); - blockDataEnsureCapacity(pRes, pBlock->info.rows); - - // data from mnode - pRes->info.rows = pBlock->info.rows; - relocateColumnData(pRes, pColList, pBlock->pDataBlock, false); - blockDataDestroy(pBlock); - } - - // todo move this to time window aggregator, since the primary timestamp may not be known by exchange operator. - blockDataUpdateTsWindow(pRes, 0); - return TSDB_CODE_SUCCESS; -} - -static void* setAllSourcesCompleted(SOperatorInfo* pOperator, int64_t startTs) { - SExchangeInfo* pExchangeInfo = pOperator->info; - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - - int64_t el = taosGetTimestampUs() - startTs; - SLoadRemoteDataInfo* pLoadInfo = &pExchangeInfo->loadInfo; - - pLoadInfo->totalElapsed += el; - - size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); - qDebug("%s all %" PRIzu " sources are exhausted, total rows: %" PRIu64 " bytes:%" PRIu64 ", elapsed:%.2f ms", - GET_TASKID(pTaskInfo), totalSources, pLoadInfo->totalRows, pLoadInfo->totalSize, - pLoadInfo->totalElapsed / 1000.0); - - doSetOperatorCompleted(pOperator); - return NULL; -} - -static void concurrentlyLoadRemoteDataImpl(SOperatorInfo* pOperator, SExchangeInfo* pExchangeInfo, - SExecTaskInfo* pTaskInfo) { - int32_t code = 0; - int64_t startTs = taosGetTimestampUs(); - size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); - - while (1) { - int32_t completed = 0; - for (int32_t i = 0; i < totalSources; ++i) { - SSourceDataInfo* pDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, i); - if (pDataInfo->status == EX_SOURCE_DATA_EXHAUSTED) { - completed += 1; - continue; - } - - if (pDataInfo->status != EX_SOURCE_DATA_READY) { - continue; - } - - if (pDataInfo->code != TSDB_CODE_SUCCESS) { - code = pDataInfo->code; - goto _error; - } - - SRetrieveTableRsp* pRsp = pDataInfo->pRsp; - SDownstreamSourceNode* pSource = taosArrayGet(pExchangeInfo->pSources, i); - - SLoadRemoteDataInfo* pLoadInfo = &pExchangeInfo->loadInfo; - if (pRsp->numOfRows == 0) { - qDebug("%s vgId:%d, taskId:0x%" PRIx64 " execId:%d index:%d completed, rowsOfSource:%" PRIu64 - ", totalRows:%" PRIu64 ", completed:%d try next %d/%" PRIzu, - GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, i, pDataInfo->totalRows, - pExchangeInfo->loadInfo.totalRows, completed + 1, i + 1, totalSources); - pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED; - completed += 1; - taosMemoryFreeClear(pDataInfo->pRsp); - continue; - } - - SRetrieveTableRsp* pRetrieveRsp = pDataInfo->pRsp; - int32_t index = 0; - char* pStart = pRetrieveRsp->data; - while (index++ < pRetrieveRsp->numOfBlocks) { - SSDataBlock* pb = createOneDataBlock(pExchangeInfo->pDummyBlock, false); - code = extractDataBlockFromFetchRsp(pb, pStart, NULL, &pStart); - if (code != 0) { - taosMemoryFreeClear(pDataInfo->pRsp); - goto _error; - } - - taosArrayPush(pExchangeInfo->pResultBlockList, &pb); - } - - updateLoadRemoteInfo(pLoadInfo, pRetrieveRsp->numOfRows, pRetrieveRsp->compLen, startTs, pOperator); - - if (pRsp->completed == 1) { - qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 - " execId:%d" - " index:%d completed, blocks:%d, numOfRows:%d, rowsOfSource:%" PRIu64 ", totalRows:%" PRIu64 - ", total:%.2f Kb," - " completed:%d try next %d/%" PRIzu, - GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, i, pRsp->numOfBlocks, - pRsp->numOfRows, pDataInfo->totalRows, pLoadInfo->totalRows, pLoadInfo->totalSize / 1024.0, - completed + 1, i + 1, totalSources); - completed += 1; - pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED; - } else { - qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 - " execId:%d blocks:%d, numOfRows:%d, totalRows:%" PRIu64 ", total:%.2f Kb", - GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, pRsp->numOfBlocks, - pRsp->numOfRows, pLoadInfo->totalRows, pLoadInfo->totalSize / 1024.0); - } - - taosMemoryFreeClear(pDataInfo->pRsp); - - if (pDataInfo->status != EX_SOURCE_DATA_EXHAUSTED) { - pDataInfo->status = EX_SOURCE_DATA_NOT_READY; - code = doSendFetchDataRequest(pExchangeInfo, pTaskInfo, i); - if (code != TSDB_CODE_SUCCESS) { - taosMemoryFreeClear(pDataInfo->pRsp); - goto _error; - } - } - - return; - } - - if (completed == totalSources) { - setAllSourcesCompleted(pOperator, startTs); - return; - } - - sched_yield(); - } - -_error: - pTaskInfo->code = code; -} - -static int32_t prepareConcurrentlyLoad(SOperatorInfo* pOperator) { - SExchangeInfo* pExchangeInfo = pOperator->info; - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - - size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); - int64_t startTs = taosGetTimestampUs(); - - // Asynchronously send all fetch requests to all sources. - for (int32_t i = 0; i < totalSources; ++i) { - int32_t code = doSendFetchDataRequest(pExchangeInfo, pTaskInfo, i); - if (code != TSDB_CODE_SUCCESS) { - pTaskInfo->code = code; - return code; - } - } - - int64_t endTs = taosGetTimestampUs(); - qDebug("%s send all fetch requests to %" PRIzu " sources completed, elapsed:%.2fms", GET_TASKID(pTaskInfo), - totalSources, (endTs - startTs) / 1000.0); - - pOperator->status = OP_RES_TO_RETURN; - pOperator->cost.openCost = taosGetTimestampUs() - startTs; - - tsem_wait(&pExchangeInfo->ready); - return TSDB_CODE_SUCCESS; -} - -static int32_t seqLoadRemoteData(SOperatorInfo* pOperator) { - SExchangeInfo* pExchangeInfo = pOperator->info; - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - - size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); - int64_t startTs = taosGetTimestampUs(); - - while (1) { - if (pExchangeInfo->current >= totalSources) { - setAllSourcesCompleted(pOperator, startTs); - return TSDB_CODE_SUCCESS; - } - - doSendFetchDataRequest(pExchangeInfo, pTaskInfo, pExchangeInfo->current); - tsem_wait(&pExchangeInfo->ready); - - SSourceDataInfo* pDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, pExchangeInfo->current); - SDownstreamSourceNode* pSource = taosArrayGet(pExchangeInfo->pSources, pExchangeInfo->current); - - if (pDataInfo->code != TSDB_CODE_SUCCESS) { - qError("%s vgId:%d, taskID:0x%" PRIx64 " execId:%d error happens, code:%s", GET_TASKID(pTaskInfo), - pSource->addr.nodeId, pSource->taskId, pSource->execId, tstrerror(pDataInfo->code)); - pOperator->pTaskInfo->code = pDataInfo->code; - return pOperator->pTaskInfo->code; - } - - SRetrieveTableRsp* pRsp = pDataInfo->pRsp; - SLoadRemoteDataInfo* pLoadInfo = &pExchangeInfo->loadInfo; - if (pRsp->numOfRows == 0) { - qDebug("%s vgId:%d, taskID:0x%" PRIx64 " execId:%d %d of total completed, rowsOfSource:%" PRIu64 - ", totalRows:%" PRIu64 " try next", - GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, pExchangeInfo->current + 1, - pDataInfo->totalRows, pLoadInfo->totalRows); - - pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED; - pExchangeInfo->current += 1; - taosMemoryFreeClear(pDataInfo->pRsp); - continue; - } - - SRetrieveTableRsp* pRetrieveRsp = pDataInfo->pRsp; - - char* pStart = pRetrieveRsp->data; - int32_t code = extractDataBlockFromFetchRsp(NULL, pStart, NULL, &pStart); - - if (pRsp->completed == 1) { - qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " execId:%d numOfRows:%d, rowsOfSource:%" PRIu64 - ", totalRows:%" PRIu64 ", totalBytes:%" PRIu64 " try next %d/%" PRIzu, - GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, pRetrieveRsp->numOfRows, - pDataInfo->totalRows, pLoadInfo->totalRows, pLoadInfo->totalSize, pExchangeInfo->current + 1, - totalSources); - - pDataInfo->status = EX_SOURCE_DATA_EXHAUSTED; - pExchangeInfo->current += 1; - } else { - qDebug("%s fetch msg rsp from vgId:%d, taskId:0x%" PRIx64 " execId:%d numOfRows:%d, totalRows:%" PRIu64 - ", totalBytes:%" PRIu64, - GET_TASKID(pTaskInfo), pSource->addr.nodeId, pSource->taskId, pSource->execId, pRetrieveRsp->numOfRows, - pLoadInfo->totalRows, pLoadInfo->totalSize); - } - - updateLoadRemoteInfo(pLoadInfo, pRetrieveRsp->numOfRows, pRetrieveRsp->compLen, startTs, pOperator); - pDataInfo->totalRows += pRetrieveRsp->numOfRows; - - taosMemoryFreeClear(pDataInfo->pRsp); - return TSDB_CODE_SUCCESS; - } -} - -static int32_t prepareLoadRemoteData(SOperatorInfo* pOperator) { - if (OPTR_IS_OPENED(pOperator)) { - return TSDB_CODE_SUCCESS; - } - - int64_t st = taosGetTimestampUs(); - - SExchangeInfo* pExchangeInfo = pOperator->info; - if (!pExchangeInfo->seqLoadData) { - int32_t code = prepareConcurrentlyLoad(pOperator); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - } - - OPTR_SET_OPENED(pOperator); - pOperator->cost.openCost = (taosGetTimestampUs() - st) / 1000.0; - return TSDB_CODE_SUCCESS; -} - -static void freeBlock(void* pParam) { - SSDataBlock* pBlock = *(SSDataBlock**)pParam; - blockDataDestroy(pBlock); -} - -static SSDataBlock* doLoadRemoteDataImpl(SOperatorInfo* pOperator) { - SExchangeInfo* pExchangeInfo = pOperator->info; - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - - pTaskInfo->code = pOperator->fpSet._openFn(pOperator); - if (pTaskInfo->code != TSDB_CODE_SUCCESS) { - return NULL; - } - - size_t totalSources = taosArrayGetSize(pExchangeInfo->pSources); - - SLoadRemoteDataInfo* pLoadInfo = &pExchangeInfo->loadInfo; - if (pOperator->status == OP_EXEC_DONE) { - qDebug("%s all %" PRIzu " source(s) are exhausted, total rows:%" PRIu64 " bytes:%" PRIu64 ", elapsed:%.2f ms", - GET_TASKID(pTaskInfo), totalSources, pLoadInfo->totalRows, pLoadInfo->totalSize, - pLoadInfo->totalElapsed / 1000.0); - return NULL; - } - - size_t size = taosArrayGetSize(pExchangeInfo->pResultBlockList); - if (size == 0 || pExchangeInfo->rspBlockIndex >= size) { - pExchangeInfo->rspBlockIndex = 0; - taosArrayClearEx(pExchangeInfo->pResultBlockList, freeBlock); - if (pExchangeInfo->seqLoadData) { - seqLoadRemoteData(pOperator); - } else { - concurrentlyLoadRemoteDataImpl(pOperator, pExchangeInfo, pTaskInfo); - } - - if (taosArrayGetSize(pExchangeInfo->pResultBlockList) == 0) { - return NULL; - } - } - - // we have buffered retrieved datablock, return it directly - return taosArrayGetP(pExchangeInfo->pResultBlockList, pExchangeInfo->rspBlockIndex++); -} - -static SSDataBlock* doLoadRemoteData(SOperatorInfo* pOperator) { - SExchangeInfo* pExchangeInfo = pOperator->info; - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - - if (pOperator->status == OP_EXEC_DONE) { - return NULL; - } - - while (1) { - SSDataBlock* pBlock = doLoadRemoteDataImpl(pOperator); - if (pBlock == NULL) { - return NULL; - } - - SLimitInfo* pLimitInfo = &pExchangeInfo->limitInfo; - if (hasLimitOffsetInfo(pLimitInfo)) { - int32_t status = handleLimitOffset(pOperator, pLimitInfo, pBlock, false); - if (status == PROJECT_RETRIEVE_CONTINUE) { - continue; - } else if (status == PROJECT_RETRIEVE_DONE) { - size_t rows = pBlock->info.rows; - pExchangeInfo->limitInfo.numOfOutputRows += rows; - - if (rows == 0) { - doSetOperatorCompleted(pOperator); - return NULL; - } else { - return pBlock; - } - } - } else { - return pBlock; - } - } -} - -static int32_t initDataSource(int32_t numOfSources, SExchangeInfo* pInfo, const char* id) { - pInfo->pSourceDataInfo = taosArrayInit(numOfSources, sizeof(SSourceDataInfo)); - if (pInfo->pSourceDataInfo == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - - for (int32_t i = 0; i < numOfSources; ++i) { - SSourceDataInfo dataInfo = {0}; - dataInfo.status = EX_SOURCE_DATA_NOT_READY; - dataInfo.taskId = id; - dataInfo.index = i; - SSourceDataInfo* pDs = taosArrayPush(pInfo->pSourceDataInfo, &dataInfo); - if (pDs == NULL) { - taosArrayDestroy(pInfo->pSourceDataInfo); - return TSDB_CODE_OUT_OF_MEMORY; - } - } - - return TSDB_CODE_SUCCESS; -} - -static int32_t initExchangeOperator(SExchangePhysiNode* pExNode, SExchangeInfo* pInfo, const char* id) { - size_t numOfSources = LIST_LENGTH(pExNode->pSrcEndPoints); - - if (numOfSources == 0) { - qError("%s invalid number: %d of sources in exchange operator", id, (int32_t)numOfSources); - return TSDB_CODE_INVALID_PARA; - } - - pInfo->pSources = taosArrayInit(numOfSources, sizeof(SDownstreamSourceNode)); - if (pInfo->pSources == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - - for (int32_t i = 0; i < numOfSources; ++i) { - SDownstreamSourceNode* pNode = (SDownstreamSourceNode*)nodesListGetNode((SNodeList*)pExNode->pSrcEndPoints, i); - taosArrayPush(pInfo->pSources, pNode); - } - - initLimitInfo(pExNode->node.pLimit, pExNode->node.pSlimit, &pInfo->limitInfo); - pInfo->self = taosAddRef(exchangeObjRefPool, pInfo); - - return initDataSource(numOfSources, pInfo, id); -} - -SOperatorInfo* createExchangeOperatorInfo(void* pTransporter, SExchangePhysiNode* pExNode, SExecTaskInfo* pTaskInfo) { - SExchangeInfo* pInfo = taosMemoryCalloc(1, sizeof(SExchangeInfo)); - SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - if (pInfo == NULL || pOperator == NULL) { - goto _error; - } - - int32_t code = initExchangeOperator(pExNode, pInfo, GET_TASKID(pTaskInfo)); - if (code != TSDB_CODE_SUCCESS) { - goto _error; - } - - tsem_init(&pInfo->ready, 0, 0); - pInfo->pDummyBlock = createResDataBlock(pExNode->node.pOutputDataBlockDesc); - pInfo->pResultBlockList = taosArrayInit(1, POINTER_BYTES); - - pInfo->seqLoadData = false; - pInfo->pTransporter = pTransporter; - - pOperator->name = "ExchangeOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_EXCHANGE; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->exprSupp.numOfExprs = taosArrayGetSize(pInfo->pDummyBlock->pDataBlock); - pOperator->pTaskInfo = pTaskInfo; - - pOperator->fpSet = - createOperatorFpSet(prepareLoadRemoteData, doLoadRemoteData, NULL, NULL, destroyExchangeOperatorInfo, NULL); - return pOperator; - -_error: - if (pInfo != NULL) { - doDestroyExchangeOperatorInfo(pInfo); - } - - taosMemoryFreeClear(pOperator); - pTaskInfo->code = code; - return NULL; -} - static int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t numOfOutput, size_t keyBufSize, const char* pKey); @@ -2459,17 +1805,17 @@ static SSDataBlock* getAggregateResult(SOperatorInfo* pOperator) { SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; pTaskInfo->code = pOperator->fpSet._openFn(pOperator); if (pTaskInfo->code != TSDB_CODE_SUCCESS) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return NULL; } blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); while (1) { doBuildResultDatablock(pOperator, pInfo, &pAggInfo->groupResInfo, pAggInfo->aggSup.pResultBuf); - doFilter(pAggInfo->pCondition, pInfo->pRes, NULL, NULL); + doFilter(pInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL); if (!hasRemainResults(&pAggInfo->groupResInfo)) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); break; } @@ -2718,7 +2064,7 @@ static SSDataBlock* doFillImpl(SOperatorInfo* pOperator) { SSDataBlock* pBlock = pDownstream->fpSet.getNextFn(pDownstream); if (pBlock == NULL) { if (pInfo->totalInputRows == 0) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return NULL; } @@ -2795,11 +2141,11 @@ static SSDataBlock* doFill(SOperatorInfo* pOperator) { while (true) { fillResult = doFillImpl(pOperator); if (fillResult == NULL) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); break; } - doFilter(pInfo->pCondition, fillResult, &pInfo->matchInfo, NULL); + doFilter(fillResult, pOperator->exprSupp.pFilterInfo, &pInfo->matchInfo ); if (fillResult->info.rows > 0) { break; } @@ -2854,8 +2200,10 @@ int32_t getBufferPgSize(int32_t rowSize, uint32_t* defaultPgsz, uint32_t* defaul *defaultPgsz <<= 1u; } + // The default buffer for each operator in query is 10MB. // at least four pages need to be in buffer - *defaultBufsz = 4096 * 256; + // TODO: make this variable to be configurable. + *defaultBufsz = 4096 * 2560; if ((*defaultBufsz) <= (*defaultPgsz)) { (*defaultBufsz) = (*defaultPgsz) * 4; } @@ -3016,18 +2364,17 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SAggPhysiN goto _error; } + code = filterInitFromNode((SNode*)pAggNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + pInfo->binfo.mergeResultBlock = pAggNode->mergeDataBlock; pInfo->groupId = UINT64_MAX; - pInfo->pCondition = pAggNode->node.pConditions; - pOperator->name = "TableAggregate"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_HASH_AGG; - pOperator->blocking = true; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; + setOperatorInfo(pOperator, "TableAggregate", QUERY_NODE_PHYSICAL_PLAN_HASH_AGG, true, OP_NOT_OPENED, pInfo, pTaskInfo); pOperator->fpSet = - createOperatorFpSet(doOpenAggregateOptr, getAggregateResult, NULL, NULL, destroyAggOperatorInfo, NULL); + createOperatorFpSet(doOpenAggregateOptr, getAggregateResult, NULL, destroyAggOperatorInfo, NULL); if (downstream->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) { STableScanInfo* pTableScanInfo = downstream->info; @@ -3052,7 +2399,7 @@ _error: } taosMemoryFreeClear(pOperator); - pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; + pTaskInfo->code = code; return NULL; } @@ -3091,33 +2438,6 @@ void destroyFillOperatorInfo(void* param) { taosMemoryFreeClear(param); } -void destroyExchangeOperatorInfo(void* param) { - SExchangeInfo* pExInfo = (SExchangeInfo*)param; - taosRemoveRef(exchangeObjRefPool, pExInfo->self); -} - -void freeSourceDataInfo(void* p) { - SSourceDataInfo* pInfo = (SSourceDataInfo*)p; - taosMemoryFreeClear(pInfo->pRsp); -} - -void doDestroyExchangeOperatorInfo(void* param) { - SExchangeInfo* pExInfo = (SExchangeInfo*)param; - - taosArrayDestroy(pExInfo->pSources); - taosArrayDestroyEx(pExInfo->pSourceDataInfo, freeSourceDataInfo); - - if (pExInfo->pResultBlockList != NULL) { - taosArrayDestroyEx(pExInfo->pResultBlockList, freeBlock); - pExInfo->pResultBlockList = NULL; - } - - blockDataDestroy(pExInfo->pDummyBlock); - - tsem_destroy(&pExInfo->ready); - taosMemoryFreeClear(param); -} - static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t numOfCols, SExprInfo* pNotFillExpr, int32_t numOfNotFillCols, SNodeListNode* pValNode, STimeWindow win, int32_t capacity, const char* id, SInterval* pInterval, int32_t fillType, int32_t order) { @@ -3244,16 +2564,14 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SFillPhysiNode* pInfo->pFinalRes = createOneDataBlock(pInfo->pRes, false); blockDataEnsureCapacity(pInfo->pFinalRes, pOperator->resultInfo.capacity); - pInfo->pCondition = pPhyFillNode->node.pConditions; - pOperator->name = "FillOperator"; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_FILL; - pOperator->exprSupp.numOfExprs = pInfo->numOfExpr; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; + code = filterInitFromNode((SNode*)pPhyFillNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doFill, NULL, NULL, destroyFillOperatorInfo, NULL); + setOperatorInfo(pOperator, "FillOperator", QUERY_NODE_PHYSICAL_PLAN_FILL, false, OP_NOT_OPENED, pInfo, pTaskInfo); + pOperator->exprSupp.numOfExprs = pInfo->numOfExpr; + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doFill, NULL, destroyFillOperatorInfo, NULL); code = appendDownstream(pOperator, &downstream, 1); return pOperator; @@ -3263,18 +2581,25 @@ _error: destroyFillOperatorInfo(pInfo); } + pTaskInfo->code = code; taosMemoryFreeClear(pOperator); return NULL; } static SExecTaskInfo* createExecTaskInfo(uint64_t queryId, uint64_t taskId, EOPTR_EXEC_MODEL model, char* dbFName) { SExecTaskInfo* pTaskInfo = taosMemoryCalloc(1, sizeof(SExecTaskInfo)); + if (pTaskInfo == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED); pTaskInfo->schemaInfo.dbname = strdup(dbFName); pTaskInfo->cost.created = taosGetTimestampMs(); pTaskInfo->id.queryId = queryId; pTaskInfo->execModel = model; + pTaskInfo->pTableInfoList = tableListCreate(); char* p = taosMemoryCalloc(1, 128); snprintf(p, 128, "TID:0x%" PRIx64 " QID:0x%" PRIx64, taskId, queryId); @@ -3366,64 +2691,6 @@ static void cleanupTableSchemaInfo(SSchemaInfo* pSchemaInfo) { static void cleanupStreamInfo(SStreamTaskInfo* pStreamInfo) { tDeleteSSchemaWrapper(pStreamInfo->schema); } -static int32_t sortTableGroup(STableListInfo* pTableListInfo) { - taosArrayClear(pTableListInfo->pGroupList); - SArray* sortSupport = taosArrayInit(16, sizeof(uint64_t)); - if (sortSupport == NULL) return TSDB_CODE_OUT_OF_MEMORY; - for (int32_t i = 0; i < taosArrayGetSize(pTableListInfo->pTableList); i++) { - STableKeyInfo* info = taosArrayGet(pTableListInfo->pTableList, i); - uint64_t* groupId = taosHashGet(pTableListInfo->map, &info->uid, sizeof(uint64_t)); - - int32_t index = taosArraySearchIdx(sortSupport, groupId, compareUint64Val, TD_EQ); - if (index == -1) { - void* p = taosArraySearch(sortSupport, groupId, compareUint64Val, TD_GT); - SArray* tGroup = taosArrayInit(8, sizeof(STableKeyInfo)); - if (tGroup == NULL) { - taosArrayDestroy(sortSupport); - return TSDB_CODE_OUT_OF_MEMORY; - } - if (taosArrayPush(tGroup, info) == NULL) { - qError("taos push info array error"); - taosArrayDestroy(sortSupport); - return TSDB_CODE_QRY_APP_ERROR; - } - if (p == NULL) { - if (taosArrayPush(sortSupport, groupId) == NULL) { - qError("taos push support array error"); - taosArrayDestroy(sortSupport); - return TSDB_CODE_QRY_APP_ERROR; - } - if (taosArrayPush(pTableListInfo->pGroupList, &tGroup) == NULL) { - qError("taos push group array error"); - taosArrayDestroy(sortSupport); - return TSDB_CODE_QRY_APP_ERROR; - } - } else { - int32_t pos = TARRAY_ELEM_IDX(sortSupport, p); - if (taosArrayInsert(sortSupport, pos, groupId) == NULL) { - qError("taos insert support array error"); - taosArrayDestroy(sortSupport); - return TSDB_CODE_QRY_APP_ERROR; - } - if (taosArrayInsert(pTableListInfo->pGroupList, pos, &tGroup) == NULL) { - qError("taos insert group array error"); - taosArrayDestroy(sortSupport); - return TSDB_CODE_QRY_APP_ERROR; - } - } - } else { - SArray* tGroup = (SArray*)taosArrayGetP(pTableListInfo->pGroupList, index); - if (taosArrayPush(tGroup, info) == NULL) { - qError("taos push uid array error"); - taosArrayDestroy(sortSupport); - return TSDB_CODE_QRY_APP_ERROR; - } - } - } - taosArrayDestroy(sortSupport); - return TDB_CODE_SUCCESS; -} - bool groupbyTbname(SNodeList* pGroupList) { bool bytbname = false; if (LIST_LENGTH(pGroupList) == 1) { @@ -3437,80 +2704,29 @@ bool groupbyTbname(SNodeList* pGroupList) { return bytbname; } -int32_t generateGroupIdMap(STableListInfo* pTableListInfo, SReadHandle* pHandle, SNodeList* group) { - if (group == NULL) { - return TDB_CODE_SUCCESS; - } - - pTableListInfo->map = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); - if (pTableListInfo->map == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - - bool assignUid = groupbyTbname(group); - - size_t numOfTables = taosArrayGetSize(pTableListInfo->pTableList); - - if (assignUid) { - for (int32_t i = 0; i < numOfTables; i++) { - STableKeyInfo* info = taosArrayGet(pTableListInfo->pTableList, i); - info->groupId = info->uid; - taosHashPut(pTableListInfo->map, &(info->uid), sizeof(uint64_t), &info->groupId, sizeof(uint64_t)); - } - } else { - int32_t code = getColInfoResultForGroupby(pHandle->meta, group, pTableListInfo); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - } - - if (pTableListInfo->needSortTableByGroupId) { - return sortTableGroup(pTableListInfo); - } - - return TDB_CODE_SUCCESS; -} - -static int32_t initTableblockDistQueryCond(uint64_t uid, SQueryTableDataCond* pCond) { - memset(pCond, 0, sizeof(SQueryTableDataCond)); - - pCond->order = TSDB_ORDER_ASC; - pCond->numOfCols = 1; - pCond->colList = taosMemoryCalloc(1, sizeof(SColumnInfo)); - if (pCond->colList == NULL) { - terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; - return terrno; - } - - pCond->colList->colId = 1; - pCond->colList->type = TSDB_DATA_TYPE_TIMESTAMP; - pCond->colList->bytes = sizeof(TSKEY); - - pCond->twindows = (STimeWindow){.skey = INT64_MIN, .ekey = INT64_MAX}; - pCond->suid = uid; - pCond->type = TIMEWINDOW_RANGE_CONTAINED; - pCond->startVersion = -1; - pCond->endVersion = -1; - - return TSDB_CODE_SUCCESS; -} - -SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, - STableListInfo* pTableListInfo, SNode* pTagCond, SNode* pTagIndexCond, - const char* pUser) { - int32_t type = nodeType(pPhyNode); +SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo, SReadHandle* pHandle, SNode* pTagCond, + SNode* pTagIndexCond, const char* pUser) { + int32_t type = nodeType(pPhyNode); + STableListInfo* pTableListInfo = pTaskInfo->pTableInfoList; + const char* idstr = GET_TASKID(pTaskInfo); if (pPhyNode->pChildren == NULL || LIST_LENGTH(pPhyNode->pChildren) == 0) { SOperatorInfo* pOperator = NULL; if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == type) { STableScanPhysiNode* pTableScanNode = (STableScanPhysiNode*)pPhyNode; + // NOTE: this is an patch to fix the physical plan + // TODO remove it later + if (pTableScanNode->scan.node.pLimit != NULL) { + pTableScanNode->groupSort = true; + } + int32_t code = createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort, pHandle, - pTableListInfo, pTagCond, pTagIndexCond, GET_TASKID(pTaskInfo)); + pTableListInfo, pTagCond, pTagIndexCond, pTaskInfo); if (code) { pTaskInfo->code = code; - qError("failed to createScanTableListInfo, code:%s, %s", tstrerror(code), GET_TASKID(pTaskInfo)); + qError("failed to createScanTableListInfo, code:%s, %s", tstrerror(code), idstr); return NULL; } @@ -3521,13 +2737,18 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo } pOperator = createTableScanOperatorInfo(pTableScanNode, pHandle, pTaskInfo); + if (NULL == pOperator) { + pTaskInfo->code = terrno; + return NULL; + } + STableScanInfo* pScanInfo = pOperator->info; pTaskInfo->cost.pRecoder = &pScanInfo->readRecorder; } else if (QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == type) { STableMergeScanPhysiNode* pTableScanNode = (STableMergeScanPhysiNode*)pPhyNode; - int32_t code = - createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort, pHandle, - pTableListInfo, pTagCond, pTagIndexCond, GET_TASKID(pTaskInfo)); + + int32_t code = createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, true, pHandle, + pTableListInfo, pTagCond, pTagIndexCond, pTaskInfo); if (code) { pTaskInfo->code = code; qError("failed to createScanTableListInfo, code: %s", tstrerror(code)); @@ -3541,6 +2762,10 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo } pOperator = createTableMergeScanOperatorInfo(pTableScanNode, pTableListInfo, pHandle, pTaskInfo); + if (NULL == pOperator) { + pTaskInfo->code = terrno; + return NULL; + } STableScanInfo* pScanInfo = pOperator->info; pTaskInfo->cost.pRecoder = &pScanInfo->readRecorder; @@ -3552,7 +2777,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo if (pHandle->vnode) { int32_t code = createScanTableListInfo(&pTableScanNode->scan, pTableScanNode->pGroupTags, pTableScanNode->groupSort, - pHandle, pTableListInfo, pTagCond, pTagIndexCond, GET_TASKID(pTaskInfo)); + pHandle, pTableListInfo, pTagCond, pTagIndexCond, pTaskInfo); if (code) { pTaskInfo->code = code; qError("failed to createScanTableListInfo, code: %s", tstrerror(code)); @@ -3560,10 +2785,12 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo } #ifndef NDEBUG - int32_t sz = taosArrayGetSize(pTableListInfo->pTableList); + int32_t sz = tableListGetSize(pTableListInfo); + qDebug("create stream task, total:%d", sz); + for (int32_t i = 0; i < sz; i++) { - STableKeyInfo* pKeyInfo = taosArrayGet(pTableListInfo->pTableList, i); - qDebug("creating stream task: add table %" PRId64, pKeyInfo->uid); + STableKeyInfo* pKeyInfo = tableListGetInfo(pTableListInfo, i); + qDebug("add table uid:%" PRIu64 ", gid:%" PRIu64, pKeyInfo->uid, pKeyInfo->groupId); } #endif } @@ -3575,7 +2802,9 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo pOperator = createSysTableScanOperatorInfo(pHandle, pSysScanPhyNode, pUser, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN == type) { STagScanPhysiNode* pScanPhyNode = (STagScanPhysiNode*)pPhyNode; - int32_t code = getTableList(pHandle->meta, pHandle->vnode, pScanPhyNode, pTagCond, pTagIndexCond, pTableListInfo); + + int32_t code = createScanTableListInfo(pScanPhyNode, NULL, false, pHandle, pTableListInfo, pTagCond, + pTagIndexCond, pTaskInfo); if (code != TSDB_CODE_SUCCESS) { pTaskInfo->code = code; qError("failed to getTableList, code: %s", tstrerror(code)); @@ -3585,35 +2814,30 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo pOperator = createTagScanOperatorInfo(pHandle, pScanPhyNode, pTableListInfo, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN == type) { SBlockDistScanPhysiNode* pBlockNode = (SBlockDistScanPhysiNode*)pPhyNode; - pTableListInfo->pTableList = taosArrayInit(4, sizeof(STableKeyInfo)); if (pBlockNode->tableType == TSDB_SUPER_TABLE) { - int32_t code = vnodeGetAllTableList(pHandle->vnode, pBlockNode->uid, pTableListInfo->pTableList); + SArray* pList = taosArrayInit(4, sizeof(STableKeyInfo)); + int32_t code = vnodeGetAllTableList(pHandle->vnode, pBlockNode->uid, pList); if (code != TSDB_CODE_SUCCESS) { pTaskInfo->code = terrno; return NULL; } - } else { // Create one table group. - STableKeyInfo info = {.uid = pBlockNode->uid, .groupId = 0}; - taosArrayPush(pTableListInfo->pTableList, &info); - } - SQueryTableDataCond cond = {0}; - int32_t code = initTableblockDistQueryCond(pBlockNode->suid, &cond); - if (code != TSDB_CODE_SUCCESS) { - return NULL; + for (int32_t i = 0; i < tableListGetSize(pTableListInfo); ++i) { + STableKeyInfo* p = taosArrayGet(pList, i); + tableListAddTableInfo(pTableListInfo, p->uid, 0); + } + taosArrayDestroy(pList); + } else { // Create group with only one table + tableListAddTableInfo(pTableListInfo, pBlockNode->uid, 0); } - STsdbReader* pReader = NULL; - tsdbReaderOpen(pHandle->vnode, &cond, pTableListInfo->pTableList, &pReader, ""); - cleanupQueryTableDataCond(&cond); - - pOperator = createDataBlockInfoScanOperator(pReader, pHandle, cond.suid, pBlockNode, pTaskInfo); + pOperator = createDataBlockInfoScanOperator(pHandle, pBlockNode, pTaskInfo); } else if (QUERY_NODE_PHYSICAL_PLAN_LAST_ROW_SCAN == type) { SLastRowScanPhysiNode* pScanNode = (SLastRowScanPhysiNode*)pPhyNode; int32_t code = createScanTableListInfo(&pScanNode->scan, pScanNode->pGroupTags, true, pHandle, pTableListInfo, - pTagCond, pTagIndexCond, GET_TASKID(pTaskInfo)); + pTagCond, pTagIndexCond, pTaskInfo); if (code != TSDB_CODE_SUCCESS) { pTaskInfo->code = code; return NULL; @@ -3641,15 +2865,17 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo size_t size = LIST_LENGTH(pPhyNode->pChildren); SOperatorInfo** ops = taosMemoryCalloc(size, POINTER_BYTES); + if (ops == NULL) { + return NULL; + } + for (int32_t i = 0; i < size; ++i) { SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, i); - ops[i] = createOperatorTree(pChildNode, pTaskInfo, pHandle, pTableListInfo, pTagCond, pTagIndexCond, pUser); + ops[i] = createOperatorTree(pChildNode, pTaskInfo, pHandle, pTagCond, pTagIndexCond, pUser); if (ops[i] == NULL) { taosMemoryFree(ops); return NULL; } - - ops[i]->resultDataBlockId = pChildNode->pOutputDataBlockDesc->dataBlockId; } SOperatorInfo* pOptr = NULL; @@ -3914,15 +3140,18 @@ int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, qTaskInfo_t* pT if (NULL == pDeleterParam) { return TSDB_CODE_OUT_OF_MEMORY; } - int32_t tbNum = taosArrayGetSize(pTask->tableqinfoList.pTableList); - pDeleterParam->suid = pTask->tableqinfoList.suid; + int32_t tbNum = tableListGetSize(pTask->pTableInfoList); + pDeleterParam->suid = tableListGetSuid(pTask->pTableInfoList); + + // TODO extract uid list pDeleterParam->pUidList = taosArrayInit(tbNum, sizeof(uint64_t)); if (NULL == pDeleterParam->pUidList) { taosMemoryFree(pDeleterParam); return TSDB_CODE_OUT_OF_MEMORY; } + for (int32_t i = 0; i < tbNum; ++i) { - STableKeyInfo* pTable = taosArrayGet(pTask->tableqinfoList.pTableList, i); + STableKeyInfo* pTable = tableListGetInfo(pTask->pTableInfoList, i); taosArrayPush(pDeleterParam->pUidList, &pTable->uid); } @@ -3940,10 +3169,8 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead char* sql, EOPTR_EXEC_MODEL model) { uint64_t queryId = pPlan->id.queryId; - int32_t code = TSDB_CODE_SUCCESS; *pTaskInfo = createExecTaskInfo(queryId, taskId, model, pPlan->dbFName); if (*pTaskInfo == NULL) { - code = TSDB_CODE_QRY_OUT_OF_MEMORY; goto _complete; } @@ -3958,45 +3185,26 @@ int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SRead sql = NULL; (*pTaskInfo)->pSubplan = pPlan; - (*pTaskInfo)->pRoot = createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, &(*pTaskInfo)->tableqinfoList, - pPlan->pTagCond, pPlan->pTagIndexCond, pPlan->user); + (*pTaskInfo)->pRoot = + createOperatorTree(pPlan->pNode, *pTaskInfo, pHandle, pPlan->pTagCond, pPlan->pTagIndexCond, pPlan->user); if (NULL == (*pTaskInfo)->pRoot) { - code = (*pTaskInfo)->code; + terrno = (*pTaskInfo)->code; goto _complete; } - return code; + return TSDB_CODE_SUCCESS; _complete: taosMemoryFree(sql); doDestroyTask(*pTaskInfo); - terrno = code; - return code; -} - -void doDestroyTableList(STableListInfo* pTableqinfoList) { - taosArrayDestroy(pTableqinfoList->pTableList); - taosHashCleanup(pTableqinfoList->map); - if (pTableqinfoList->needSortTableByGroupId) { - for (int32_t i = 0; i < taosArrayGetSize(pTableqinfoList->pGroupList); i++) { - SArray* tmp = taosArrayGetP(pTableqinfoList->pGroupList, i); - if (tmp == pTableqinfoList->pTableList) { - continue; - } - taosArrayDestroy(tmp); - } - } - taosArrayDestroy(pTableqinfoList->pGroupList); - - pTableqinfoList->pTableList = NULL; - pTableqinfoList->map = NULL; + return terrno; } void doDestroyTask(SExecTaskInfo* pTaskInfo) { qDebug("%s execTask is freed", GET_TASKID(pTaskInfo)); - doDestroyTableList(&pTaskInfo->tableqinfoList); + pTaskInfo->pTableInfoList = tableListDestroy(pTaskInfo->pTableInfoList); destroyOperatorInfo(pTaskInfo->pRoot); cleanupTableSchemaInfo(&pTaskInfo->schemaInfo); cleanupStreamInfo(&pTaskInfo->streamInfo); diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index 644f02f60dff5af916d40c1a20a0f2f583157319..e31c8f588f38a435c2a820b07ec1c0528bbb0b43 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#include "filter.h" #include "function.h" #include "os.h" #include "tname.h" @@ -62,7 +63,7 @@ static int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char** int32_t numOfGroupCols = taosArrayGetSize(pGroupColList); for (int32_t i = 0; i < numOfGroupCols; ++i) { - SColumn* pCol = (SColumn*) taosArrayGet(pGroupColList, i); + SColumn* pCol = (SColumn*)taosArrayGet(pGroupColList, i); (*keyLen) += pCol->bytes; // actual data + null_flag SGroupKeys key = {0}; @@ -312,10 +313,10 @@ static SSDataBlock* buildGroupResultDataBlock(SOperatorInfo* pOperator) { SSDataBlock* pRes = pInfo->binfo.pRes; while (1) { doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); - doFilter(pInfo->pCondition, pRes, NULL, NULL); + doFilter(pRes, pOperator->exprSupp.pFilterInfo, NULL); if (!hasRemainResults(&pInfo->groupResInfo)) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); break; } @@ -336,8 +337,6 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) { SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SGroupbyOperatorInfo* pInfo = pOperator->info; - SSDataBlock* pRes = pInfo->binfo.pRes; - if (pOperator->status == OP_RES_TO_RETURN) { return buildGroupResultDataBlock(pOperator); } @@ -390,14 +389,13 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) { } } #endif - blockDataEnsureCapacity(pRes, pOperator->resultInfo.capacity); initGroupedResultInfo(&pInfo->groupResInfo, pInfo->aggSup.pResultRowHashTable, 0); pOperator->cost.openCost = (taosGetTimestampUs() - st) / 1000.0; return buildGroupResultDataBlock(pOperator); } -SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode *pAggNode, SExecTaskInfo* pTaskInfo) { +SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pAggNode, SExecTaskInfo* pTaskInfo) { SGroupbyOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SGroupbyOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { @@ -414,14 +412,14 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode } pInfo->pGroupCols = extractColumnInfo(pAggNode->pGroupKeys); - pInfo->pCondition = pAggNode->node.pConditions; - int32_t code = initExprSupp(&pInfo->scalarSup, pScalarExprInfo, numOfScalarExpr); if (code != TSDB_CODE_SUCCESS) { goto _error; } initResultSizeInfo(&pOperator->resultInfo, 4096); + blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity); + code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pInfo->pGroupCols); if (code != TSDB_CODE_SUCCESS) { goto _error; @@ -434,16 +432,16 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode goto _error; } - initResultRowInfo(&pInfo->binfo.resultRowInfo); + code = filterInitFromNode((SNode*)pAggNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } - pOperator->name = "GroupbyAggOperator"; - pOperator->blocking = true; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; + initResultRowInfo(&pInfo->binfo.resultRowInfo); + setOperatorInfo(pOperator, "GroupbyAggOperator", 0, true, OP_NOT_OPENED, pInfo, pTaskInfo); - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, hashGroupbyAggregate, NULL, NULL, - destroyGroupOperatorInfo, NULL); + pOperator->fpSet = + createOperatorFpSet(operatorDummyOpenFn, hashGroupbyAggregate, NULL, destroyGroupOperatorInfo, NULL); code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { goto _error; @@ -621,9 +619,10 @@ int32_t* setupColumnOffset(const SSDataBlock* pBlock, int32_t rowCapacity) { } static void clearPartitionOperator(SPartitionOperatorInfo* pInfo) { - void* ite = NULL; - while ((ite = taosHashIterate(pInfo->pGroupSet, ite)) != NULL) { - taosArrayDestroy(((SDataGroupInfo*)ite)->pPageList); + int32_t size = taosArrayGetSize(pInfo->sortedGroupArray); + for (int32_t i = 0; i < size; i++) { + SDataGroupInfo* pGp = taosArrayGet(pInfo->sortedGroupArray, i); + taosArrayDestroy(pGp->pPageList); } taosArrayClear(pInfo->sortedGroupArray); clearDiskbasedBuf(pInfo->pBuf); @@ -650,7 +649,7 @@ static SSDataBlock* buildPartitionResult(SOperatorInfo* pOperator) { // try next group data ++pInfo->groupIndex; if (pInfo->groupIndex >= taosArrayGetSize(pInfo->sortedGroupArray)) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); clearPartitionOperator(pInfo); return NULL; } @@ -749,6 +748,14 @@ static void destroyPartitionOperatorInfo(void* param) { taosArrayDestroy(pInfo->pGroupColVals); taosMemoryFree(pInfo->keyBuf); taosArrayDestroy(pInfo->sortedGroupArray); + + void* pGroupIter = taosHashIterate(pInfo->pGroupSet, NULL); + while (pGroupIter != NULL) { + SDataGroupInfo* pGroupInfo = pGroupIter; + taosArrayDestroy(pGroupInfo->pPageList); + pGroupIter = taosHashIterate(pInfo->pGroupSet, pGroupIter); + } + taosHashCleanup(pInfo->pGroupSet); taosMemoryFree(pInfo->columnOffset); @@ -765,7 +772,6 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition goto _error; } - int32_t numOfCols = 0; SExprInfo* pExprInfo = createExprInfo(pPartNode->pTargets, NULL, &numOfCols); pInfo->pGroupCols = extractPartitionColInfo(pPartNode->pPartitionKeys); @@ -810,17 +816,12 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition goto _error; } - pOperator->name = "PartitionOperator"; - pOperator->blocking = true; - pOperator->status = OP_NOT_OPENED; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_PARTITION; + setOperatorInfo(pOperator, "PartitionOperator", QUERY_NODE_PHYSICAL_PLAN_PARTITION, false, OP_NOT_OPENED, pInfo, pTaskInfo); pOperator->exprSupp.numOfExprs = numOfCols; pOperator->exprSupp.pExprInfo = pExprInfo; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, hashPartition, NULL, NULL, destroyPartitionOperatorInfo, - NULL); + pOperator->fpSet = + createOperatorFpSet(operatorDummyOpenFn, hashPartition, NULL, destroyPartitionOperatorInfo, NULL); code = appendDownstream(pOperator, &downstream, 1); return pOperator; @@ -907,6 +908,8 @@ static SSDataBlock* buildStreamPartitionResult(SOperatorInfo* pOperator) { blockDataDestroy(pResBlock); } } + taosArrayDestroy(pParInfo->rowIds); + pParInfo->rowIds = NULL; blockDataUpdateTsWindow(pDest, pInfo->tsColIndex); pDest->info.groupId = pParInfo->groupId; pOperator->resultInfo.totalRows += pDest->info.rows; @@ -952,7 +955,7 @@ static SSDataBlock* doStreamHashPartition(SOperatorInfo* pOperator) { pInfo->pInputDataBlock = NULL; SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream); if (pBlock == NULL) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return NULL; } printDataBlock(pBlock, "stream partitionby recv"); @@ -965,6 +968,7 @@ static SSDataBlock* doStreamHashPartition(SOperatorInfo* pOperator) { case STREAM_DELETE_DATA: { copyDataBlock(pInfo->pDelRes, pBlock); pInfo->pDelRes->info.type = STREAM_DELETE_RESULT; + printDataBlock(pInfo->pDelRes, "stream partitionby delete"); return pInfo->pDelRes; } break; default: @@ -1004,6 +1008,7 @@ static void destroyStreamPartitionOperatorInfo(void* param) { cleanupExprSupp(&pInfo->tbnameCalSup); cleanupExprSupp(&pInfo->tagCalSup); blockDataDestroy(pInfo->pDelRes); + taosHashCleanup(pInfo->pPartitions); taosMemoryFreeClear(param); } @@ -1014,6 +1019,9 @@ void initParDownStream(SOperatorInfo* downstream, SPartitionBySupporter* pParSup SStreamScanInfo* pScanInfo = downstream->info; pScanInfo->partitionSup = *pParSup; pScanInfo->pPartScalarSup = pExpr; + if (!pScanInfo->pUpdateInfo) { + pScanInfo->pUpdateInfo = updateInfoInit(60000, TSDB_TIME_PRECISION_MILLI, 0); + } } SOperatorInfo* createStreamPartitionOperatorInfo(SOperatorInfo* downstream, SStreamPartitionPhysiNode* pPartNode, @@ -1070,14 +1078,16 @@ SOperatorInfo* createStreamPartitionOperatorInfo(SOperatorInfo* downstream, SStr } pInfo->partitionSup.needCalc = true; - SSDataBlock* pResBlock = createResDataBlock(pPartNode->part.node.pOutputDataBlockDesc); - if (!pResBlock) { + pInfo->binfo.pRes = createResDataBlock(pPartNode->part.node.pOutputDataBlockDesc); + if (pInfo->binfo.pRes == NULL) { goto _error; } - blockDataEnsureCapacity(pResBlock, 4096); - pInfo->binfo.pRes = pResBlock; + + blockDataEnsureCapacity(pInfo->binfo.pRes, 4096); + pInfo->parIte = NULL; pInfo->pInputDataBlock = NULL; + _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY); pInfo->pPartitions = taosHashInit(1024, hashFn, false, HASH_NO_LOCK); pInfo->tsColIndex = 0; @@ -1086,15 +1096,10 @@ SOperatorInfo* createStreamPartitionOperatorInfo(SOperatorInfo* downstream, SStr int32_t numOfCols = 0; SExprInfo* pExprInfo = createExprInfo(pPartNode->part.pTargets, NULL, &numOfCols); - pOperator->name = "StreamPartitionOperator"; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION; + setOperatorInfo(pOperator, "StreamPartitionOperator", QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION, false, OP_NOT_OPENED, pInfo, pTaskInfo); pOperator->exprSupp.numOfExprs = numOfCols; pOperator->exprSupp.pExprInfo = pExprInfo; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamHashPartition, NULL, NULL, + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamHashPartition, NULL, destroyStreamPartitionOperatorInfo, NULL); initParDownStream(downstream, &pInfo->partitionSup, &pInfo->scalarSup); @@ -1108,7 +1113,6 @@ _error: return NULL; } - SArray* extractColumnInfo(SNodeList* pNodeList) { size_t numOfCols = LIST_LENGTH(pNodeList); SArray* pList = taosArrayInit(numOfCols, sizeof(SColumn)); diff --git a/source/libs/executor/src/joinoperator.c b/source/libs/executor/src/joinoperator.c index 8dac44684f0ffd992974bbf3f72b59e8d3f9efe9..4e1daac6431ea1c9f6c16a2e619157dfea6010b9 100644 --- a/source/libs/executor/src/joinoperator.c +++ b/source/libs/executor/src/joinoperator.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#include "filter.h" #include "executorimpl.h" #include "function.h" #include "os.h" @@ -72,14 +73,10 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t initResultSizeInfo(&pOperator->resultInfo, 4096); pInfo->pRes = pResBlock; - pOperator->name = "MergeJoinOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; + + setOperatorInfo(pOperator, "MergeJoinOperator", QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN, false, OP_NOT_OPENED, pInfo, pTaskInfo); pOperator->exprSupp.pExprInfo = pExprInfo; pOperator->exprSupp.numOfExprs = numOfCols; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; extractTimeCondition(pInfo, pDownstream, numOfDownstream, pJoinNode); @@ -108,6 +105,11 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t pInfo->pCondAfterMerge = NULL; } + code = filterInitFromNode(pInfo->pCondAfterMerge, &pOperator->exprSupp.pFilterInfo, 0); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + pInfo->inputOrder = TSDB_ORDER_ASC; if (pJoinNode->inputTsOrder == ORDER_ASC) { pInfo->inputOrder = TSDB_ORDER_ASC; @@ -115,8 +117,7 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t pInfo->inputOrder = TSDB_ORDER_DESC; } - pOperator->fpSet = - createOperatorFpSet(operatorDummyOpenFn, doMergeJoin, NULL, NULL, destroyMergeJoinOperator, NULL); + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doMergeJoin, NULL, destroyMergeJoinOperator, NULL); code = appendDownstream(pOperator, pDownstream, numOfDownstream); if (code != TSDB_CODE_SUCCESS) { goto _error; @@ -366,13 +367,13 @@ static void doMergeJoinImpl(struct SOperatorInfo* pOperator, SSDataBlock* pRes) if (leftTs == rightTs) { mergeJoinJoinDownstreamTsRanges(pOperator, leftTs, pRes, &nrows); - } else if (asc && leftTs < rightTs || !asc && leftTs > rightTs) { + } else if ((asc && leftTs < rightTs) || (!asc && leftTs > rightTs)) { pJoinInfo->leftPos += 1; if (pJoinInfo->leftPos >= pJoinInfo->pLeft->info.rows) { continue; } - } else if (asc && leftTs > rightTs || !asc && leftTs < rightTs) { + } else if ((asc && leftTs > rightTs) || (!asc && leftTs < rightTs)) { pJoinInfo->rightPos += 1; if (pJoinInfo->rightPos >= pJoinInfo->pRight->info.rows) { continue; @@ -400,8 +401,8 @@ SSDataBlock* doMergeJoin(struct SOperatorInfo* pOperator) { if (numOfNewRows == 0) { break; } - if (pJoinInfo->pCondAfterMerge != NULL) { - doFilter(pJoinInfo->pCondAfterMerge, pRes, NULL, NULL); + if (pOperator->exprSupp.pFilterInfo != NULL) { + doFilter(pRes, pOperator->exprSupp.pFilterInfo, NULL); } if (pRes->info.rows >= pOperator->resultInfo.threshold) { break; diff --git a/source/libs/executor/src/projectoperator.c b/source/libs/executor/src/projectoperator.c index b3ea7a5573049492ee0bb4d728928e804703351b..ce1d13775caab667517237b29947749b52464908 100644 --- a/source/libs/executor/src/projectoperator.c +++ b/source/libs/executor/src/projectoperator.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#include "filter.h" #include "executorimpl.h" #include "functionMgt.h" @@ -71,13 +72,7 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SProjectPhys pInfo->binfo.pRes = pResBlock; pInfo->pFinalRes = createOneDataBlock(pResBlock, false); - pInfo->pFilterNode = pProjPhyNode->node.pConditions; - - if (pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM) { - pInfo->mergeDataBlocks = false; - } else { - pInfo->mergeDataBlocks = pProjPhyNode->mergeDataBlock; - } + pInfo->mergeDataBlocks = (pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM)? false:pProjPhyNode->mergeDataBlock; int32_t numOfRows = 4096; size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; @@ -97,14 +92,15 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SProjectPhys initBasicInfo(&pInfo->binfo, pResBlock); setFunctionResultOutput(pOperator, &pInfo->binfo, &pInfo->aggSup, MAIN_SCAN, numOfCols); + code = filterInitFromNode((SNode*)pProjPhyNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + pInfo->pPseudoColInfo = setRowTsColumnOutputInfo(pOperator->exprSupp.pCtx, numOfCols); - pOperator->name = "ProjectOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_PROJECT; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doProjectOperation, NULL, NULL, + setOperatorInfo(pOperator, "ProjectOperator", QUERY_NODE_PHYSICAL_PLAN_PROJECT, false, OP_NOT_OPENED, pInfo, pTaskInfo); + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doProjectOperation, NULL, destroyProjectOperatorInfo, NULL); code = appendDownstream(pOperator, &downstream, 1); @@ -153,7 +149,7 @@ static int32_t setInfoForNewGroup(SSDataBlock* pBlock, SLimitInfo* pLimitInfo, S if (pLimitInfo->currentGroupId != 0 && pLimitInfo->currentGroupId != pBlock->info.groupId) { pLimitInfo->numOfOutputGroups += 1; if ((pLimitInfo->slimit.limit > 0) && (pLimitInfo->slimit.limit <= pLimitInfo->numOfOutputGroups)) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return PROJECT_RETRIEVE_DONE; } @@ -187,7 +183,7 @@ static int32_t doIngroupLimitOffset(SLimitInfo* pLimitInfo, uint64_t groupId, SS // TODO: optimize it later when partition by + limit if ((pLimitInfo->slimit.limit == -1 && pLimitInfo->currentGroupId == 0) || (pLimitInfo->slimit.limit > 0 && pLimitInfo->slimit.limit <= pLimitInfo->numOfOutputGroups)) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); } } @@ -210,8 +206,6 @@ SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) { pOperator->status = OP_OPENED; } - qDebug("enter project"); - if (pOperator->status == OP_EXEC_DONE) { if (pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE) { pOperator->status = OP_OPENED; @@ -254,7 +248,7 @@ SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) { } qDebug("set op close, exec %d, status %d rows %d", pTaskInfo->execModel, pOperator->status, pFinalRes->info.rows); - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); break; } if (pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE) { @@ -315,7 +309,7 @@ SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) { } // do apply filter - doFilter(pProjectInfo->pFilterNode, pFinalRes, NULL, NULL); + doFilter(pFinalRes, pOperator->exprSupp.pFilterInfo, NULL); // when apply the limit/offset for each group, pRes->info.rows may be 0, due to limit constraint. if (pFinalRes->info.rows > 0 || (pOperator->status == OP_EXEC_DONE)) { @@ -325,7 +319,7 @@ SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) { } else { // do apply filter if (pRes->info.rows > 0) { - doFilter(pProjectInfo->pFilterNode, pRes, NULL, NULL); + doFilter(pRes, pOperator->exprSupp.pFilterInfo, NULL); if (pRes->info.rows == 0) { continue; } @@ -386,6 +380,7 @@ SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhy initBasicInfo(&pInfo->binfo, pResBlock); initResultSizeInfo(&pOperator->resultInfo, numOfRows); + blockDataEnsureCapacity(pResBlock, numOfRows); int32_t code = initAggInfo(pSup, &pInfo->aggSup, pExprInfo, numOfExpr, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { @@ -393,19 +388,16 @@ SOperatorInfo* createIndefinitOutputOperatorInfo(SOperatorInfo* downstream, SPhy } setFunctionResultOutput(pOperator, &pInfo->binfo, &pInfo->aggSup, MAIN_SCAN, numOfExpr); + code = filterInitFromNode((SNode*)pPhyNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } pInfo->binfo.pRes = pResBlock; - pInfo->pCondition = pPhyNode->node.pConditions; pInfo->pPseudoColInfo = setRowTsColumnOutputInfo(pSup->pCtx, numOfExpr); - pOperator->name = "IndefinitOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doApplyIndefinitFunction, NULL, NULL, - destroyIndefinitOperatorInfo, NULL); + setOperatorInfo(pOperator, "IndefinitOperator", QUERY_NODE_PHYSICAL_PLAN_INDEF_ROWS_FUNC, false, OP_NOT_OPENED, pInfo, pTaskInfo); + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doApplyIndefinitFunction, NULL, destroyIndefinitOperatorInfo, NULL); code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -497,7 +489,7 @@ SSDataBlock* doApplyIndefinitFunction(SOperatorInfo* pOperator) { // The downstream exec may change the value of the newgroup, so use a local variable instead. SSDataBlock* pBlock = downstream->fpSet.getNextFn(downstream); if (pBlock == NULL) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); break; } @@ -518,7 +510,7 @@ SSDataBlock* doApplyIndefinitFunction(SOperatorInfo* pOperator) { } } - doFilter(pIndefInfo->pCondition, pInfo->pRes, NULL, NULL); + doFilter(pInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL); size_t rows = pInfo->pRes->info.rows; if (rows > 0 || pOperator->status == OP_EXEC_DONE) { break; @@ -620,13 +612,13 @@ SSDataBlock* doGenerateSourceData(SOperatorInfo* pOperator) { } pRes->info.rows = 1; - doFilter(pProjectInfo->pFilterNode, pRes, NULL, NULL); + doFilter(pRes, pOperator->exprSupp.pFilterInfo, NULL); /*int32_t status = */ doIngroupLimitOffset(&pProjectInfo->limitInfo, 0, pRes, pOperator); pOperator->resultInfo.totalRows += pRes->info.rows; - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); if (pOperator->cost.openCost == 0) { pOperator->cost.openCost = (taosGetTimestampUs() - st) / 1000.0; } diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index a7af6ca96caec8354de90c85dedb153ee49d5147..4f8d0ec6aeb451d12f61c0faf116b760edadce88 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#include #include "executorimpl.h" #include "filter.h" #include "function.h" @@ -42,7 +43,7 @@ static int32_t buildDbTableInfoBlock(bool sysInfo, const SSDataBlock* p, const S static char* SYSTABLE_IDX_COLUMN[] = {"table_name", "db_name", "create_time", "columns", "ttl", "stable_name", "vgroup_id', 'uid", "type"}; -static char* SYSTABLE_IDX_EXCEPT[] = {"db_name", "vgroup_id"}; +static char* SYSTABLE_SPECIAL_COL[] = {"db_name", "vgroup_id"}; typedef int32_t (*__sys_filte)(void* pMeta, SNode* cond, SArray* result); typedef int32_t (*__sys_check)(SNode* cond); @@ -58,6 +59,18 @@ typedef struct { void* pVnode; } SSTabFltArg; +typedef struct STableMergeScanExecInfo { + SFileBlockLoadRecorder blockRecorder; + SSortExecInfo sortExecInfo; +} STableMergeScanExecInfo; + +typedef struct STableMergeScanSortSourceParam { + SOperatorInfo* pOperator; + int32_t readerIdx; + uint64_t uid; + SSDataBlock* inputBlock; +} STableMergeScanSortSourceParam; + static int32_t sysChkFilter__Comm(SNode* pNode); static int32_t sysChkFilter__DBName(SNode* pNode); static int32_t sysChkFilter__VgroupId(SNode* pNode); @@ -69,15 +82,15 @@ static int32_t sysChkFilter__STableName(SNode* pNode); static int32_t sysChkFilter__Uid(SNode* pNode); static int32_t sysChkFilter__Type(SNode* pNode); -static int32_t sysFilte__DbName(void* pMeta, SNode* pNode, SArray* result); -static int32_t sysFilte__VgroupId(void* pMeta, SNode* pNode, SArray* result); -static int32_t sysFilte__TableName(void* pMeta, SNode* pNode, SArray* result); -static int32_t sysFilte__CreateTime(void* pMeta, SNode* pNode, SArray* result); -static int32_t sysFilte__Ncolumn(void* pMeta, SNode* pNode, SArray* result); -static int32_t sysFilte__Ttl(void* pMeta, SNode* pNode, SArray* result); -static int32_t sysFilte__STableName(void* pMeta, SNode* pNode, SArray* result); -static int32_t sysFilte__Uid(void* pMeta, SNode* pNode, SArray* result); -static int32_t sysFilte__Type(void* pMeta, SNode* pNode, SArray* result); +static int32_t sysFilte__DbName(void* arg, SNode* pNode, SArray* result); +static int32_t sysFilte__VgroupId(void* arg, SNode* pNode, SArray* result); +static int32_t sysFilte__TableName(void* arg, SNode* pNode, SArray* result); +static int32_t sysFilte__CreateTime(void* arg, SNode* pNode, SArray* result); +static int32_t sysFilte__Ncolumn(void* arg, SNode* pNode, SArray* result); +static int32_t sysFilte__Ttl(void* arg, SNode* pNode, SArray* result); +static int32_t sysFilte__STableName(void* arg, SNode* pNode, SArray* result); +static int32_t sysFilte__Uid(void* arg, SNode* pNode, SArray* result); +static int32_t sysFilte__Type(void* arg, SNode* pNode, SArray* result); const SSTabFltFuncDef filterDict[] = { {.name = "table_name", .chkFunc = sysChkFilter__TableName, .fltFunc = sysFilte__TableName}, @@ -95,7 +108,7 @@ const SSTabFltFuncDef filterDict[] = { static int32_t optSysTabFilte(void* arg, SNode* cond, SArray* result); static int32_t optSysTabFilteImpl(void* arg, SNode* cond, SArray* result); static int32_t optSysCheckOper(SNode* pOpear); -static int32_t optSysMergeRslt(SArray* multiRslt, SArray* reslt); +static int32_t optSysMergeRslt(SArray* mRslt, SArray* rslt); static bool processBlockWithProbability(const SSampleExecInfo* pInfo); @@ -103,8 +116,10 @@ static int32_t sysTableUserTagsFillOneTableTags(const SSysTableScanInfo* pInfo, SMetaReader* smrChildTable, const char* dbname, const char* tableName, int32_t* pNumOfRows, const SSDataBlock* dataBlock); -static void relocateAndFilterSysTagsScanResult(SSysTableScanInfo* pInfo, int32_t numOfRows, SSDataBlock* dataBlock); -bool processBlockWithProbability(const SSampleExecInfo* pInfo) { +static void relocateAndFilterSysTagsScanResult(SSysTableScanInfo* pInfo, int32_t numOfRows, SSDataBlock* dataBlock, + SFilterInfo* pFilterInfo); + +bool processBlockWithProbability(const SSampleExecInfo* pInfo) { #if 0 if (pInfo->sampleRatio == 1) { return true; @@ -123,29 +138,6 @@ static void switchCtxOrder(SqlFunctionCtx* pCtx, int32_t numOfOutput) { } } -static void setupQueryRangeForReverseScan(STableScanInfo* pTableScanInfo) { -#if 0 - int32_t numOfGroups = (int32_t)(GET_NUM_OF_TABLEGROUP(pRuntimeEnv)); - for(int32_t i = 0; i < numOfGroups; ++i) { - SArray *group = GET_TABLEGROUP(pRuntimeEnv, i); - SArray *tableKeyGroup = taosArrayGetP(pQueryAttr->tableGroupInfo.pGroupList, i); - - size_t t = taosArrayGetSize(group); - for (int32_t j = 0; j < t; ++j) { - STableQueryInfo *pCheckInfo = taosArrayGetP(group, j); - updateTableQueryInfoForReverseScan(pCheckInfo); - - // update the last key in tableKeyInfo list, the tableKeyInfo is used to build the tsdbQueryHandle and decide - // the start check timestamp of tsdbQueryHandle -// STableKeyInfo *pTableKeyInfo = taosArrayGet(tableKeyGroup, j); -// pTableKeyInfo->lastKey = pCheckInfo->lastKey; -// -// assert(pCheckInfo->pTable == pTableKeyInfo->pTable); - } - } -#endif -} - static void getNextTimeWindow(SInterval* pInterval, STimeWindow* tw, int32_t order) { int32_t factor = GET_FORWARD_DIRECTION_FACTOR(order); if (pInterval->intervalUnit != 'n' && pInterval->intervalUnit != 'y') { @@ -291,19 +283,13 @@ static int32_t doDynamicPruneDataBlock(SOperatorInfo* pOperator, SDataBlockInfo* return TSDB_CODE_SUCCESS; } -static FORCE_INLINE bool doFilterByBlockSMA(const SNode* pFilterNode, SColumnDataAgg** pColsAgg, int32_t numOfCols, +static bool doFilterByBlockSMA(SFilterInfo* pFilterInfo, SColumnDataAgg** pColsAgg, int32_t numOfCols, int32_t numOfRows) { - if (pColsAgg == NULL || pFilterNode == NULL) { + if (pColsAgg == NULL || pFilterInfo == NULL) { return true; } - SFilterInfo* filter = NULL; - - // todo move to the initialization function - int32_t code = filterInitFromNode((SNode*)pFilterNode, &filter, 0); - bool keep = filterRangeExecute(filter, pColsAgg, numOfCols, numOfRows); - - filterFreeInfo(filter); + bool keep = filterRangeExecute(pFilterInfo, pColsAgg, numOfCols, numOfRows); return keep; } @@ -331,7 +317,8 @@ static bool doLoadBlockSMA(STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, } } - for (int32_t i = 0; i < taosArrayGetSize(pTableScanInfo->matchInfo.pList); ++i) { + size_t num = taosArrayGetSize(pTableScanInfo->matchInfo.pList); + for (int32_t i = 0; i < num; ++i) { SColMatchItem* pColMatchInfo = taosArrayGet(pTableScanInfo->matchInfo.pList, i); if (!pColMatchInfo->needOutput) { continue; @@ -343,18 +330,46 @@ static bool doLoadBlockSMA(STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, return true; } -static void doSetTagColumnData(STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo) { +static void doSetTagColumnData(STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo, + int32_t rows) { if (pTableScanInfo->pseudoSup.numOfExprs > 0) { SExprSupp* pSup = &pTableScanInfo->pseudoSup; - int32_t code = addTagPseudoColumnData(&pTableScanInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pBlock, - GET_TASKID(pTaskInfo)); + int32_t code = addTagPseudoColumnData(&pTableScanInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pBlock, rows, + GET_TASKID(pTaskInfo), &pTableScanInfo->metaCache); if (code != TSDB_CODE_SUCCESS) { T_LONG_JMP(pTaskInfo->env, code); } } } +// todo handle the slimit info +void applyLimitOffset(SLimitInfo* pLimitInfo, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo, SOperatorInfo* pOperator) { + SLimit* pLimit = &pLimitInfo->limit; + const char* id = GET_TASKID(pTaskInfo); + + if (pLimit->offset > 0 && pLimitInfo->remainOffset > 0) { + if (pLimitInfo->remainOffset >= pBlock->info.rows) { + pLimitInfo->remainOffset -= pBlock->info.rows; + pBlock->info.rows = 0; + qDebug("current block ignore due to offset, current:%" PRId64 ", %s", pLimitInfo->remainOffset, id); + } else { + blockDataTrimFirstNRows(pBlock, pLimitInfo->remainOffset); + pLimitInfo->remainOffset = 0; + } + } + + if (pLimit->limit != -1 && pLimit->limit <= (pLimitInfo->numOfOutputRows + pBlock->info.rows)) { + // limit the output rows + int32_t overflowRows = pLimitInfo->numOfOutputRows + pBlock->info.rows - pLimit->limit; + int32_t keep = pBlock->info.rows - overflowRows; + + blockDataKeepFirstNRows(pBlock, keep); + qDebug("output limit %" PRId64 " has reached, %s", pLimit->limit, id); + pOperator->status = OP_EXEC_DONE; + } +} + static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, uint32_t* status) { SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; @@ -364,10 +379,11 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableSca pCost->totalBlocks += 1; pCost->totalRows += pBlock->info.rows; + bool loadSMA = false; *status = pInfo->dataBlockLoadFlag; - if (pTableScanInfo->pFilterNode != NULL || + if (pOperator->exprSupp.pFilterInfo != NULL || overlapWithTimeWindow(&pTableScanInfo->pdInfo.interval, &pBlock->info, pTableScanInfo->cond.order)) { (*status) = FUNC_DATA_REQUIRED_DATA_LOAD; } @@ -379,22 +395,22 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableSca qDebug("%s data block filter out, brange:%" PRId64 "-%" PRId64 ", rows:%d", GET_TASKID(pTaskInfo), pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows); pCost->filterOutBlocks += 1; + pCost->totalRows += pBlock->info.rows; return TSDB_CODE_SUCCESS; } else if (*status == FUNC_DATA_REQUIRED_NOT_LOAD) { qDebug("%s data block skipped, brange:%" PRId64 "-%" PRId64 ", rows:%d", GET_TASKID(pTaskInfo), pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows); - - doSetTagColumnData(pTableScanInfo, pBlock, pTaskInfo); + doSetTagColumnData(pTableScanInfo, pBlock, pTaskInfo, 1); pCost->skipBlocks += 1; return TSDB_CODE_SUCCESS; - } else if (*status == FUNC_DATA_REQUIRED_STATIS_LOAD) { + } else if (*status == FUNC_DATA_REQUIRED_SMA_LOAD) { pCost->loadBlockStatis += 1; loadSMA = true; // mark the operation of load sma; bool success = doLoadBlockSMA(pTableScanInfo, pBlock, pTaskInfo); if (success) { // failed to load the block sma data, data block statistics does not exist, load data block instead qDebug("%s data block SMA loaded, brange:%" PRId64 "-%" PRId64 ", rows:%d", GET_TASKID(pTaskInfo), pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows); - doSetTagColumnData(pTableScanInfo, pBlock, pTaskInfo); + doSetTagColumnData(pTableScanInfo, pBlock, pTaskInfo, 1); return TSDB_CODE_SUCCESS; } else { qDebug("%s failed to load SMA, since not all columns have SMA", GET_TASKID(pTaskInfo)); @@ -405,11 +421,11 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableSca ASSERT(*status == FUNC_DATA_REQUIRED_DATA_LOAD); // try to filter data block according to sma info - if (pTableScanInfo->pFilterNode != NULL && (!loadSMA)) { + if (pOperator->exprSupp.pFilterInfo != NULL && (!loadSMA)) { bool success = doLoadBlockSMA(pTableScanInfo, pBlock, pTaskInfo); if (success) { size_t size = taosArrayGetSize(pBlock->pDataBlock); - bool keep = doFilterByBlockSMA(pTableScanInfo->pFilterNode, pBlock->pBlockAgg, size, pBlockInfo->rows); + bool keep = doFilterByBlockSMA(pOperator->exprSupp.pFilterInfo, pBlock->pBlockAgg, size, pBlockInfo->rows); if (!keep) { qDebug("%s data block filter out by block SMA, brange:%" PRId64 "-%" PRId64 ", rows:%d", GET_TASKID(pTaskInfo), pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows); @@ -444,11 +460,14 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableSca } relocateColumnData(pBlock, pTableScanInfo->matchInfo.pList, pCols, true); - doSetTagColumnData(pTableScanInfo, pBlock, pTaskInfo); + doSetTagColumnData(pTableScanInfo, pBlock, pTaskInfo, pBlock->info.rows); - if (pTableScanInfo->pFilterNode != NULL) { + // restore the previous value + pCost->totalRows -= pBlock->info.rows; + + if (pOperator->exprSupp.pFilterInfo != NULL) { int64_t st = taosGetTimestampUs(); - doFilter(pTableScanInfo->pFilterNode, pBlock, &pTableScanInfo->matchInfo, pOperator->exprSupp.pFilterInfo); + doFilter(pBlock, pOperator->exprSupp.pFilterInfo, &pTableScanInfo->matchInfo); double el = (taosGetTimestampUs() - st) / 1000.0; pTableScanInfo->readRecorder.filterTime += el; @@ -462,6 +481,10 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableSca } } + applyLimitOffset(&pInfo->limitInfo, pBlock, pTaskInfo, pOperator); + + pCost->totalRows += pBlock->info.rows; + pInfo->limitInfo.numOfOutputRows = pCost->totalRows; return TSDB_CODE_SUCCESS; } @@ -469,48 +492,128 @@ static void prepareForDescendingScan(STableScanInfo* pTableScanInfo, SqlFunction SET_REVERSE_SCAN_FLAG(pTableScanInfo); switchCtxOrder(pCtx, numOfOutput); - // setupQueryRangeForReverseScan(pTableScanInfo); - pTableScanInfo->cond.order = TSDB_ORDER_DESC; STimeWindow* pTWindow = &pTableScanInfo->cond.twindows; TSWAP(pTWindow->skey, pTWindow->ekey); } -int32_t addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int32_t numOfPseudoExpr, - SSDataBlock* pBlock, const char* idStr) { +typedef struct STableCachedVal { + const char* pName; + STag* pTags; +} STableCachedVal; + +static void freeTableCachedVal(void* param) { + if (param == NULL) { + return; + } + + STableCachedVal* pVal = param; + taosMemoryFree((void*)pVal->pName); + taosMemoryFree(pVal->pTags); + taosMemoryFree(pVal); +} + +//const void *key, size_t keyLen, void *value +static void freeCachedMetaItem(const void *key, size_t keyLen, void *value) { + freeTableCachedVal(value); +} + +int32_t addTagPseudoColumnData(SReadHandle* pHandle, const SExprInfo* pExpr, int32_t numOfExpr, + SSDataBlock* pBlock, int32_t rows, const char* idStr, STableMetaCacheInfo* pCache) { // currently only the tbname pseudo column - if (numOfPseudoExpr == 0) { + if (numOfExpr <= 0) { return TSDB_CODE_SUCCESS; } + int32_t code = 0; + + // backup the rows + int32_t backupRows = pBlock->info.rows; + pBlock->info.rows = rows; + + bool freeReader = false; + STableCachedVal val = {0}; + SMetaReader mr = {0}; - metaReaderInit(&mr, pHandle->meta, 0); - int32_t code = metaGetTableEntryByUid(&mr, pBlock->info.uid); - if (code != TSDB_CODE_SUCCESS) { - qError("failed to get table meta, uid:0x%" PRIx64 ", code:%s, %s", pBlock->info.uid, tstrerror(terrno), idStr); - metaReaderClear(&mr); - return terrno; - } + LRUHandle* h = NULL; + + // 1. check if it is existed in meta cache + if (pCache == NULL) { + metaReaderInit(&mr, pHandle->meta, 0); + code = metaGetTableEntryByUid(&mr, pBlock->info.uid); + if (code != TSDB_CODE_SUCCESS) { + qError("failed to get table meta, uid:0x%" PRIx64 ", code:%s, %s", pBlock->info.uid, tstrerror(terrno), idStr); + metaReaderClear(&mr); + return terrno; + } + + metaReaderReleaseLock(&mr); + + val.pName = mr.me.name; + val.pTags = (STag*)mr.me.ctbEntry.pTags; + + freeReader = true; + } else { + pCache->metaFetch += 1; + + h = taosLRUCacheLookup(pCache->pTableMetaEntryCache, &pBlock->info.uid, sizeof(pBlock->info.uid)); + if (h == NULL) { + metaReaderInit(&mr, pHandle->meta, 0); + code = metaGetTableEntryByUid(&mr, pBlock->info.uid); + if (code != TSDB_CODE_SUCCESS) { + qError("failed to get table meta, uid:0x%" PRIx64 ", code:%s, %s", pBlock->info.uid, tstrerror(terrno), idStr); + metaReaderClear(&mr); + return terrno; + } + + metaReaderReleaseLock(&mr); - metaReaderReleaseLock(&mr); + STableCachedVal* pVal = taosMemoryMalloc(sizeof(STableCachedVal)); + pVal->pName = strdup(mr.me.name); + pVal->pTags = NULL; - for (int32_t j = 0; j < numOfPseudoExpr; ++j) { - SExprInfo* pExpr = &pPseudoExpr[j]; + // only child table has tag value + if (mr.me.type == TSDB_CHILD_TABLE) { + STag* pTag = (STag*)mr.me.ctbEntry.pTags; + pVal->pTags = taosMemoryMalloc(pTag->len); + memcpy(pVal->pTags, mr.me.ctbEntry.pTags, pTag->len); + } + + val = *pVal; + freeReader = true; - int32_t dstSlotId = pExpr->base.resSchema.slotId; + int32_t ret = taosLRUCacheInsert(pCache->pTableMetaEntryCache, &pBlock->info.uid, sizeof(uint64_t), pVal, sizeof(STableCachedVal), freeCachedMetaItem, NULL, TAOS_LRU_PRIORITY_LOW); + if (ret != TAOS_LRU_STATUS_OK) { + qError("failed to put meta into lru cache, code:%d, %s", ret, idStr); + freeTableCachedVal(pVal); + } + } else { + pCache->cacheHit += 1; + STableCachedVal* pVal = taosLRUCacheValue(pCache->pTableMetaEntryCache, h); + val = *pVal; + taosLRUCacheRelease(pCache->pTableMetaEntryCache, h, false); + } + + qDebug("retrieve table meta from cache:%"PRIu64", hit:%"PRIu64 " miss:%"PRIu64", %s", pCache->metaFetch, pCache->cacheHit, + (pCache->metaFetch - pCache->cacheHit), idStr); + } + + for (int32_t j = 0; j < numOfExpr; ++j) { + const SExprInfo* pExpr1 = &pExpr[j]; + int32_t dstSlotId = pExpr1->base.resSchema.slotId; SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, dstSlotId); colInfoDataCleanup(pColInfoData, pBlock->info.rows); - int32_t functionId = pExpr->pExpr->_function.functionId; + int32_t functionId = pExpr1->pExpr->_function.functionId; // this is to handle the tbname if (fmIsScanPseudoColumnFunc(functionId)) { - setTbNameColData(pHandle->meta, pBlock, pColInfoData, functionId); + setTbNameColData(pBlock, pColInfoData, functionId, val.pName); } else { // these are tags STagVal tagVal = {0}; - tagVal.cid = pExpr->base.pParam[0].pCol->colId; - const char* p = metaGetTableTagVal(mr.me.ctbEntry.pTags, pColInfoData->info.type, &tagVal); + tagVal.cid = pExpr1->base.pParam[0].pCol->colId; + const char* p = metaGetTableTagVal(val.pTags, pColInfoData->info.type, &tagVal); char* data = NULL; if (pColInfoData->info.type != TSDB_DATA_TYPE_JSON && p != NULL) { @@ -535,20 +638,29 @@ int32_t addTagPseudoColumnData(SReadHandle* pHandle, SExprInfo* pPseudoExpr, int } } - metaReaderClear(&mr); + // restore the rows + pBlock->info.rows = backupRows; + if (freeReader) { + metaReaderClear(&mr); + } + return TSDB_CODE_SUCCESS; } -void setTbNameColData(void* pMeta, const SSDataBlock* pBlock, SColumnInfoData* pColInfoData, int32_t functionId) { +void setTbNameColData(const SSDataBlock* pBlock, SColumnInfoData* pColInfoData, int32_t functionId, const char* name) { struct SScalarFuncExecFuncs fpSet = {0}; fmGetScalarFuncExecFuncs(functionId, &fpSet); - SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_BIGINT, sizeof(uint64_t), 1); - colInfoDataEnsureCapacity(&infoData, 1); + size_t len = TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE; + char buf[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(buf, name) - colDataAppendInt64(&infoData, 0, (int64_t*)&pBlock->info.uid); - SScalarParam srcParam = {.numOfRows = pBlock->info.rows, .param = pMeta, .columnData = &infoData}; + SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, len, 1); + colInfoDataEnsureCapacity(&infoData, 1, false); + colDataAppend(&infoData, 0, buf, false); + + SScalarParam srcParam = {.numOfRows = pBlock->info.rows, .columnData = &infoData}; SScalarParam param = {.columnData = pColInfoData}; if (fpSet.process != NULL) { @@ -579,19 +691,16 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) { } blockDataCleanup(pBlock); + SDataBlockInfo* pBInfo = &pBlock->info; - SDataBlockInfo binfo = pBlock->info; - tsdbRetrieveDataBlockInfo(pTableScanInfo->dataReader, &binfo); + int32_t rows = 0; + tsdbRetrieveDataBlockInfo(pTableScanInfo->dataReader, &rows, &pBInfo->uid, &pBInfo->window); - binfo.capacity = binfo.rows; - blockDataEnsureCapacity(pBlock, binfo.rows); - pBlock->info = binfo; - ASSERT(binfo.uid != 0); + blockDataEnsureCapacity(pBlock, rows); // todo remove it latter + pBInfo->rows = rows; - uint64_t* groupId = taosHashGet(pTaskInfo->tableqinfoList.map, &pBlock->info.uid, sizeof(int64_t)); - if (groupId) { - pBlock->info.groupId = *groupId; - } + ASSERT(pBInfo->uid != 0); + pBlock->info.groupId = getTableGroupId(pTaskInfo->pTableInfoList, pBlock->info.uid); uint32_t status = 0; int32_t code = loadDataBlock(pOperator, pTableScanInfo, pBlock, &status); @@ -623,7 +732,7 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator) { return NULL; } -static SSDataBlock* doTableScanGroup(SOperatorInfo* pOperator) { +static SSDataBlock* doGroupedTableScan(SOperatorInfo* pOperator) { STableScanInfo* pTableScanInfo = pOperator->info; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; @@ -636,7 +745,6 @@ static SSDataBlock* doTableScanGroup(SOperatorInfo* pOperator) { while (pTableScanInfo->scanTimes < pTableScanInfo->scanInfo.numOfAsc) { SSDataBlock* p = doTableScanImpl(pOperator); if (p != NULL) { - ASSERT(p->info.uid != 0); return p; } @@ -645,10 +753,7 @@ static SSDataBlock* doTableScanGroup(SOperatorInfo* pOperator) { if (pTableScanInfo->scanTimes < pTableScanInfo->scanInfo.numOfAsc) { setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED); pTableScanInfo->scanFlag = REPEAT_SCAN; - qDebug( - "%s start to repeat ascending order scan data SELECT last_row(*),hostname from cpu group by hostname;blocks " - "due to query func required", - GET_TASKID(pTaskInfo)); + qDebug("start to repeat ascending order scan data blocks due to query func required, %s", GET_TASKID(pTaskInfo)); // do prepare for the next round table scan operation tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond); @@ -675,8 +780,7 @@ static SSDataBlock* doTableScanGroup(SOperatorInfo* pOperator) { setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED); pTableScanInfo->scanFlag = REPEAT_SCAN; - qDebug("%s start to repeat descending order scan data blocks due to query func required", - GET_TASKID(pTaskInfo)); + qDebug("%s start to repeat descending order scan data blocks", GET_TASKID(pTaskInfo)); tsdbReaderReset(pTableScanInfo->dataReader, &pTableScanInfo->cond); } } @@ -689,16 +793,12 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) { STableScanInfo* pInfo = pOperator->info; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - // if scan table by table + // scan table one by one sequentially if (pInfo->scanMode == TABLE_SCAN__TABLE_ORDER) { - if (pInfo->noTable) { - return NULL; - } - - int32_t numOfTables = taosArrayGetSize(pTaskInfo->tableqinfoList.pTableList); + int32_t numOfTables = tableListGetSize(pTaskInfo->pTableInfoList); while (1) { - SSDataBlock* result = doTableScanGroup(pOperator); + SSDataBlock* result = doGroupedTableScan(pOperator); if (result) { return result; } @@ -709,59 +809,65 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator) { return NULL; } - STableKeyInfo* pTableInfo = taosArrayGet(pTaskInfo->tableqinfoList.pTableList, pInfo->currentTable); - tsdbSetTableId(pInfo->dataReader, pTableInfo->uid); + STableKeyInfo* pTableInfo = tableListGetInfo(pTaskInfo->pTableInfoList, pInfo->currentTable); + tsdbSetTableList(pInfo->dataReader, pTableInfo, 1); qDebug("set uid:%" PRIu64 " into scanner, total tables:%d, index:%d %s", pTableInfo->uid, numOfTables, pInfo->currentTable, pTaskInfo->id.str); tsdbReaderReset(pInfo->dataReader, &pInfo->cond); pInfo->scanTimes = 0; } - } + } else { // scan table group by group sequentially + if (pInfo->currentGroupId == -1) { + if ((++pInfo->currentGroupId) >= tableListGetOutputGroups(pTaskInfo->pTableInfoList)) { + setOperatorCompleted(pOperator); + return NULL; + } - if (pInfo->currentGroupId == -1) { - pInfo->currentGroupId++; - if (pInfo->currentGroupId >= taosArrayGetSize(pTaskInfo->tableqinfoList.pGroupList)) { - setTaskStatus(pTaskInfo, TASK_COMPLETED); - return NULL; - } + int32_t num = 0; + STableKeyInfo* pList = NULL; + tableListGetGroupList(pTaskInfo->pTableInfoList, pInfo->currentGroupId, &pList, &num); + ASSERT(pInfo->dataReader == NULL); - SArray* tableList = taosArrayGetP(pTaskInfo->tableqinfoList.pGroupList, pInfo->currentGroupId); + int32_t code = tsdbReaderOpen(pInfo->readHandle.vnode, &pInfo->cond, pList, num, + (STsdbReader**)&pInfo->dataReader, GET_TASKID(pTaskInfo)); + if (code != TSDB_CODE_SUCCESS) { + T_LONG_JMP(pTaskInfo->env, code); + } + } - tsdbReaderClose(pInfo->dataReader); + SSDataBlock* result = doGroupedTableScan(pOperator); + if (result != NULL) { + ASSERT(result->info.uid != 0); + return result; + } - int32_t code = tsdbReaderOpen(pInfo->readHandle.vnode, &pInfo->cond, tableList, (STsdbReader**)&pInfo->dataReader, - GET_TASKID(pTaskInfo)); - if (code != TSDB_CODE_SUCCESS) { - T_LONG_JMP(pTaskInfo->env, code); + if ((++pInfo->currentGroupId) >= tableListGetOutputGroups(pTaskInfo->pTableInfoList)) { + setOperatorCompleted(pOperator); return NULL; } - } - SSDataBlock* result = doTableScanGroup(pOperator); - if (result) { - return result; - } + // reset value for the next group data output + pOperator->status = OP_OPENED; + pInfo->limitInfo.numOfOutputRows = 0; + pInfo->limitInfo.remainOffset = pInfo->limitInfo.limit.offset; - pInfo->currentGroupId++; - if (pInfo->currentGroupId >= taosArrayGetSize(pTaskInfo->tableqinfoList.pGroupList)) { - setTaskStatus(pTaskInfo, TASK_COMPLETED); - return NULL; - } + int32_t num = 0; + STableKeyInfo* pList = NULL; + tableListGetGroupList(pTaskInfo->pTableInfoList, pInfo->currentGroupId, &pList, &num); - SArray* tableList = taosArrayGetP(pTaskInfo->tableqinfoList.pGroupList, pInfo->currentGroupId); - // tsdbSetTableList(pInfo->dataReader, tableList); + tsdbSetTableList(pInfo->dataReader, pList, num); + tsdbReaderReset(pInfo->dataReader, &pInfo->cond); + pInfo->scanTimes = 0; - tsdbReaderReset(pInfo->dataReader, &pInfo->cond); - pInfo->scanTimes = 0; + result = doGroupedTableScan(pOperator); + if (result != NULL) { + return result; + } - result = doTableScanGroup(pOperator); - if (result) { - return result; + setOperatorCompleted(pOperator); + return NULL; } - - setTaskStatus(pTaskInfo, TASK_COMPLETED); - return NULL; } static int32_t getTableScannerExecInfo(struct SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len) { @@ -785,6 +891,7 @@ static void destroyTableScanOperatorInfo(void* param) { taosArrayDestroy(pTableScanInfo->matchInfo.pList); } + taosLRUCacheCleanup(pTableScanInfo->metaCache.pTableMetaEntryCache); cleanupExprSupp(&pTableScanInfo->pseudoSup); taosMemoryFreeClear(param); } @@ -797,19 +904,25 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, goto _error; } - SDataBlockDescNode* pDescNode = pTableScanNode->scan.node.pOutputDataBlockDesc; - int32_t numOfCols = 0; - int32_t code = extractColMatchInfo(pTableScanNode->scan.pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID, + SScanPhysiNode* pScanNode = &pTableScanNode->scan; + SDataBlockDescNode* pDescNode = pScanNode->node.pOutputDataBlockDesc; + + int32_t numOfCols = 0; + int32_t code = extractColMatchInfo(pScanNode->pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID, &pInfo->matchInfo); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + initLimitInfo(pScanNode->node.pLimit, pScanNode->node.pSlimit, &pInfo->limitInfo); code = initQueryTableDataCond(&pInfo->cond, pTableScanNode); if (code != TSDB_CODE_SUCCESS) { goto _error; } - if (pTableScanNode->scan.pScanPseudoCols != NULL) { + if (pScanNode->pScanPseudoCols != NULL) { SExprSupp* pSup = &pInfo->pseudoSup; - pSup->pExprInfo = createExprInfo(pTableScanNode->scan.pScanPseudoCols, NULL, &pSup->numOfExprs); + pSup->pExprInfo = createExprInfo(pScanNode->pScanPseudoCols, NULL, &pSup->numOfExprs); pSup->pCtx = createSqlFunctionCtx(pSup->pExprInfo, pSup->numOfExprs, &pSup->rowEntryInfoOffset); } @@ -820,26 +933,31 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, pInfo->sample.seed = taosGetTimestampSec(); pInfo->dataBlockLoadFlag = pTableScanNode->dataRequired; + + initResultSizeInfo(&pOperator->resultInfo, 4096); pInfo->pResBlock = createResDataBlock(pDescNode); - pInfo->pFilterNode = pTableScanNode->scan.node.pConditions; + blockDataEnsureCapacity(pInfo->pResBlock, pOperator->resultInfo.capacity); - if (pInfo->pFilterNode != NULL) { - code = filterInitFromNode((SNode*)pInfo->pFilterNode, &pOperator->exprSupp.pFilterInfo, 0); + code = filterInitFromNode((SNode*)pTableScanNode->scan.node.pConditions, &pOperator->exprSupp.pFilterInfo, 0); + if (code != TSDB_CODE_SUCCESS) { + goto _error; } pInfo->scanFlag = MAIN_SCAN; pInfo->currentGroupId = -1; pInfo->assignBlockUid = pTableScanNode->assignBlockUid; - pOperator->name = "TableScanOperator"; // for debug purpose - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; + setOperatorInfo(pOperator, "TableScanOperator", QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN, false, OP_NOT_OPENED, pInfo, pTaskInfo); pOperator->exprSupp.numOfExprs = numOfCols; - pOperator->pTaskInfo = pTaskInfo; - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScan, NULL, NULL, destroyTableScanOperatorInfo, + pInfo->metaCache.pTableMetaEntryCache = taosLRUCacheInit(1024*128, -1, .5); + if (pInfo->metaCache.pTableMetaEntryCache == NULL) { + code = terrno; + goto _error; + } + + taosLRUCacheSetStrictCapacity(pInfo->metaCache.pTableMetaEntryCache, false); + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScan, NULL, destroyTableScanOperatorInfo, getTableScannerExecInfo); // for non-blocking operator, the open cost is always 0 @@ -847,10 +965,12 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode, return pOperator; _error: - taosMemoryFreeClear(pInfo); - taosMemoryFreeClear(pOperator); + if (pInfo != NULL) { + destroyTableScanOperatorInfo(pInfo); + } - pTaskInfo->code = TSDB_CODE_QRY_OUT_OF_MEMORY; + taosMemoryFreeClear(pOperator); + pTaskInfo->code = code; return NULL; } @@ -861,14 +981,8 @@ SOperatorInfo* createTableSeqScanOperatorInfo(void* pReadHandle, SExecTaskInfo* pInfo->dataReader = pReadHandle; // pInfo->prevGroupId = -1; - pOperator->name = "TableSeqScanOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; - - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScanImpl, NULL, NULL, NULL, NULL); + setOperatorInfo(pOperator, "TableSeqScanOperator", QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN, false, OP_NOT_OPENED, pInfo, pTaskInfo); + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScanImpl, NULL, NULL, NULL); return pOperator; } @@ -924,7 +1038,7 @@ static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator) { SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; STableBlockDistInfo blockDistInfo = {.minRows = INT_MAX, .maxRows = INT_MIN}; - int32_t code = doGetTableRowSize(pBlockScanInfo->readHandle.meta, pBlockScanInfo->uid, &blockDistInfo.rowSize, + int32_t code = doGetTableRowSize(pBlockScanInfo->readHandle.meta, pBlockScanInfo->uid, (int32_t*)&blockDistInfo.rowSize, GET_TASKID(pTaskInfo)); if (code != TSDB_CODE_SUCCESS) { T_LONG_JMP(pTaskInfo->env, code); @@ -943,12 +1057,10 @@ static SSDataBlock* doBlockInfoScan(SOperatorInfo* pOperator) { tSerializeBlockDistInfo(varDataVal(p), len, &blockDistInfo); varDataSetLen(p, len); - blockDataEnsureCapacity(pBlock, 1); colDataAppend(pColInfo, 0, p, false); taosMemoryFree(p); pBlock->info.rows = 1; - pOperator->status = OP_EXEC_DONE; return pBlock; } @@ -960,8 +1072,32 @@ static void destroyBlockDistScanOperatorInfo(void* param) { taosMemoryFreeClear(param); } -SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SReadHandle* readHandle, uint64_t uid, - SBlockDistScanPhysiNode* pBlockScanNode, SExecTaskInfo* pTaskInfo) { +static int32_t initTableblockDistQueryCond(uint64_t uid, SQueryTableDataCond* pCond) { + memset(pCond, 0, sizeof(SQueryTableDataCond)); + + pCond->order = TSDB_ORDER_ASC; + pCond->numOfCols = 1; + pCond->colList = taosMemoryCalloc(1, sizeof(SColumnInfo)); + if (pCond->colList == NULL) { + terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; + return terrno; + } + + pCond->colList->colId = 1; + pCond->colList->type = TSDB_DATA_TYPE_TIMESTAMP; + pCond->colList->bytes = sizeof(TSKEY); + + pCond->twindows = (STimeWindow){.skey = INT64_MIN, .ekey = INT64_MAX}; + pCond->suid = uid; + pCond->type = TIMEWINDOW_RANGE_CONTAINED; + pCond->startVersion = -1; + pCond->endVersion = -1; + + return TSDB_CODE_SUCCESS; +} + +SOperatorInfo* createDataBlockInfoScanOperator(SReadHandle* readHandle, SBlockDistScanPhysiNode* pBlockScanNode, + SExecTaskInfo* pTaskInfo) { SBlockDistInfo* pInfo = taosMemoryCalloc(1, sizeof(SBlockDistInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); if (pInfo == NULL || pOperator == NULL) { @@ -969,10 +1105,30 @@ SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SReadHandle* re goto _error; } - pInfo->pHandle = dataReader; + { + SQueryTableDataCond cond = {0}; + + int32_t code = initTableblockDistQueryCond(pBlockScanNode->suid, &cond); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + + STableListInfo* pTableListInfo = pTaskInfo->pTableInfoList; + size_t num = tableListGetSize(pTableListInfo); + void* pList = tableListGetInfo(pTableListInfo, 0); + + code = tsdbReaderOpen(readHandle->vnode, &cond, pList, num, &pInfo->pHandle, pTaskInfo->id.str); + cleanupQueryTableDataCond(&cond); + if (code != 0) { + goto _error; + } + } + pInfo->readHandle = *readHandle; - pInfo->uid = uid; + pInfo->uid = pBlockScanNode->suid; + pInfo->pResBlock = createResDataBlock(pBlockScanNode->node.pOutputDataBlockDesc); + blockDataEnsureCapacity(pInfo->pResBlock, 1); int32_t numOfCols = 0; SExprInfo* pExprInfo = createExprInfo(pBlockScanNode->pScanPseudoCols, NULL, &numOfCols); @@ -981,15 +1137,8 @@ SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SReadHandle* re goto _error; } - pOperator->name = "DataBlockDistScanOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; - - pOperator->fpSet = - createOperatorFpSet(operatorDummyOpenFn, doBlockInfoScan, NULL, NULL, destroyBlockDistScanOperatorInfo, NULL); + setOperatorInfo(pOperator, "DataBlockDistScanOperator", QUERY_NODE_PHYSICAL_PLAN_BLOCK_DIST_SCAN, false, OP_NOT_OPENED, pInfo, pTaskInfo); + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doBlockInfoScan, NULL, destroyBlockDistScanOperatorInfo, NULL); return pOperator; _error: @@ -1036,39 +1185,58 @@ void resetTableScanInfo(STableScanInfo* pTableScanInfo, STimeWindow* pWin) { pTableScanInfo->cond.twindows = *pWin; pTableScanInfo->scanTimes = 0; pTableScanInfo->currentGroupId = -1; -} - -static void freeArray(void* array) { taosArrayDestroy(array); } - -static void resetTableScanOperator(SOperatorInfo* pTableScanOp) { - STableScanInfo* pTableScanInfo = pTableScanOp->info; - pTableScanInfo->cond.startVersion = -1; - pTableScanInfo->cond.endVersion = -1; - SArray* gpTbls = pTableScanOp->pTaskInfo->tableqinfoList.pGroupList; - SArray* allTbls = pTableScanOp->pTaskInfo->tableqinfoList.pTableList; - taosArrayClearP(gpTbls, freeArray); - taosArrayPush(gpTbls, &allTbls); - STimeWindow win = {.skey = INT64_MIN, .ekey = INT64_MAX}; - resetTableScanInfo(pTableScanOp->info, &win); + tsdbReaderClose(pTableScanInfo->dataReader); + pTableScanInfo->dataReader = NULL; } static SSDataBlock* readPreVersionData(SOperatorInfo* pTableScanOp, uint64_t tbUid, TSKEY startTs, TSKEY endTs, int64_t maxVersion) { - SArray* gpTbls = pTableScanOp->pTaskInfo->tableqinfoList.pGroupList; - taosArrayClear(gpTbls); STableKeyInfo tblInfo = {.uid = tbUid, .groupId = 0}; - SArray* tbls = taosArrayInit(1, sizeof(STableKeyInfo)); - taosArrayPush(tbls, &tblInfo); - taosArrayPush(gpTbls, &tbls); - STimeWindow win = {.skey = startTs, .ekey = endTs}; - STableScanInfo* pTableScanInfo = pTableScanOp->info; - pTableScanInfo->cond.startVersion = -1; - pTableScanInfo->cond.endVersion = maxVersion; - resetTableScanInfo(pTableScanOp->info, &win); - SSDataBlock* pRes = doTableScan(pTableScanOp); - resetTableScanOperator(pTableScanOp); - return pRes; + STableScanInfo* pTableScanInfo = pTableScanOp->info; + SQueryTableDataCond cond = pTableScanInfo->cond; + + cond.startVersion = -1; + cond.endVersion = maxVersion; + cond.twindows = (STimeWindow){.skey = startTs, .ekey = endTs}; + + SExecTaskInfo* pTaskInfo = pTableScanOp->pTaskInfo; + + SSDataBlock* pBlock = pTableScanInfo->pResBlock; + blockDataCleanup(pBlock); + + STsdbReader* pReader = NULL; + int32_t code = tsdbReaderOpen(pTableScanInfo->readHandle.vnode, &cond, &tblInfo, 1, (STsdbReader**)&pReader, + GET_TASKID(pTaskInfo)); + if (code != TSDB_CODE_SUCCESS) { + terrno = code; + T_LONG_JMP(pTaskInfo->env, code); + return NULL; + } + + bool hasBlock = tsdbNextDataBlock(pReader); + if (hasBlock) { + SDataBlockInfo* pBInfo = &pBlock->info; + + int32_t rows = 0; + tsdbRetrieveDataBlockInfo(pReader, &rows, &pBInfo->uid, &pBInfo->window); + + SArray* pCols = tsdbRetrieveDataBlock(pReader, NULL); + blockDataEnsureCapacity(pBlock, rows); + pBlock->info.rows = rows; + + relocateColumnData(pBlock, pTableScanInfo->matchInfo.pList, pCols, true); + doSetTagColumnData(pTableScanInfo, pBlock, pTaskInfo, rows); + + pBlock->info.groupId = getTableGroupId(pTaskInfo->pTableInfoList, pBInfo->uid); + } + + tsdbReaderClose(pReader); + qDebug("retrieve prev rows:%d, skey:%" PRId64 ", ekey:%" PRId64 " uid:%" PRIu64 ", max ver:%" PRId64 + ", suid:%" PRIu64, + pBlock->info.rows, startTs, endTs, tbUid, maxVersion, cond.suid); + + return pBlock->info.rows > 0 ? pBlock : NULL; } static uint64_t getGroupIdByCol(SStreamScanInfo* pInfo, uint64_t uid, TSKEY ts, int64_t maxVersion) { @@ -1081,12 +1249,7 @@ static uint64_t getGroupIdByCol(SStreamScanInfo* pInfo, uint64_t uid, TSKEY ts, } static uint64_t getGroupIdByUid(SStreamScanInfo* pInfo, uint64_t uid) { - SHashObj* map = pInfo->pTableScanOp->pTaskInfo->tableqinfoList.map; - uint64_t* groupId = taosHashGet(map, &uid, sizeof(int64_t)); - if (groupId) { - return *groupId; - } - return 0; + return getTableGroupId(pInfo->pTableScanOp->pTaskInfo->pTableInfoList, uid); } static uint64_t getGroupIdByData(SStreamScanInfo* pInfo, uint64_t uid, TSKEY ts, int64_t maxVersion) { @@ -1195,7 +1358,7 @@ static SSDataBlock* doRangeScan(SStreamScanInfo* pInfo, SSDataBlock* pSDB, int32 return NULL; } - doFilter(pInfo->pCondition, pResult, NULL, NULL); + doFilter(pResult, pInfo->pTableScanOp->exprSupp.pFilterInfo, NULL); if (pResult->info.rows == 0) { continue; } @@ -1257,7 +1420,7 @@ static int32_t generateSessionScanRange(SStreamScanInfo* pInfo, SSDataBlock* pSr uint64_t groupId = getGroupIdByData(pInfo, uidCol[i], startData[i], version); // gap must be 0. SSessionKey startWin = {0}; - getCurSessionWindow(pInfo->windowSup.pStreamAggSup, startData[i], endData[i], groupId, &startWin); + getCurSessionWindow(pInfo->windowSup.pStreamAggSup, startData[i], startData[i], groupId, &startWin); if (IS_INVALID_SESSION_WIN_KEY(startWin)) { // window has been closed. continue; @@ -1283,7 +1446,7 @@ static int32_t generateIntervalScanRange(SStreamScanInfo* pInfo, SSDataBlock* pS if (rows == 0) { return TSDB_CODE_SUCCESS; } - int32_t code = blockDataEnsureCapacity(pDestBlock, rows * 2); + int32_t code = blockDataEnsureCapacity(pDestBlock, rows); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -1326,39 +1489,33 @@ static int32_t generateIntervalScanRange(SStreamScanInfo* pInfo, SSDataBlock* pS } static int32_t generateDeleteResultBlock(SStreamScanInfo* pInfo, SSDataBlock* pSrcBlock, SSDataBlock* pDestBlock) { - if (pSrcBlock->info.rows == 0) { + blockDataCleanup(pDestBlock); + int32_t rows = pSrcBlock->info.rows; + if (rows == 0) { return TSDB_CODE_SUCCESS; } - blockDataCleanup(pDestBlock); - int32_t code = blockDataEnsureCapacity(pDestBlock, pSrcBlock->info.rows); + int32_t code = blockDataEnsureCapacity(pDestBlock, rows); if (code != TSDB_CODE_SUCCESS) { return code; } - ASSERT(taosArrayGetSize(pSrcBlock->pDataBlock) >= 3); - SColumnInfoData* pStartTsCol = taosArrayGet(pSrcBlock->pDataBlock, START_TS_COLUMN_INDEX); - TSKEY* startData = (TSKEY*)pStartTsCol->pData; - SColumnInfoData* pEndTsCol = taosArrayGet(pSrcBlock->pDataBlock, END_TS_COLUMN_INDEX); - TSKEY* endData = (TSKEY*)pEndTsCol->pData; - SColumnInfoData* pUidCol = taosArrayGet(pSrcBlock->pDataBlock, UID_COLUMN_INDEX); - uint64_t* uidCol = (uint64_t*)pUidCol->pData; - SColumnInfoData* pDestStartCol = taosArrayGet(pDestBlock->pDataBlock, START_TS_COLUMN_INDEX); - SColumnInfoData* pDestEndCol = taosArrayGet(pDestBlock->pDataBlock, END_TS_COLUMN_INDEX); - SColumnInfoData* pDestUidCol = taosArrayGet(pDestBlock->pDataBlock, UID_COLUMN_INDEX); - SColumnInfoData* pDestGpCol = taosArrayGet(pDestBlock->pDataBlock, GROUPID_COLUMN_INDEX); - SColumnInfoData* pDestCalStartTsCol = taosArrayGet(pDestBlock->pDataBlock, CALCULATE_START_TS_COLUMN_INDEX); - SColumnInfoData* pDestCalEndTsCol = taosArrayGet(pDestBlock->pDataBlock, CALCULATE_END_TS_COLUMN_INDEX); - int32_t dummy = 0; - int64_t version = pSrcBlock->info.version - 1; + SColumnInfoData* pSrcStartTsCol = (SColumnInfoData*)taosArrayGet(pSrcBlock->pDataBlock, START_TS_COLUMN_INDEX); + SColumnInfoData* pSrcEndTsCol = (SColumnInfoData*)taosArrayGet(pSrcBlock->pDataBlock, END_TS_COLUMN_INDEX); + SColumnInfoData* pSrcUidCol = taosArrayGet(pSrcBlock->pDataBlock, UID_COLUMN_INDEX); + uint64_t* srcUidData = (uint64_t*)pSrcUidCol->pData; + SColumnInfoData* pSrcGpCol = taosArrayGet(pSrcBlock->pDataBlock, GROUPID_COLUMN_INDEX); + uint64_t* srcGp = (uint64_t*)pSrcGpCol->pData; + ASSERT(pSrcStartTsCol->info.type == TSDB_DATA_TYPE_TIMESTAMP); + TSKEY* srcStartTsCol = (TSKEY*)pSrcStartTsCol->pData; + TSKEY* srcEndTsCol = (TSKEY*)pSrcEndTsCol->pData; + int64_t version = pSrcBlock->info.version - 1; for (int32_t i = 0; i < pSrcBlock->info.rows; i++) { - uint64_t groupId = getGroupIdByData(pInfo, uidCol[i], startData[i], version); - colDataAppend(pDestStartCol, i, (const char*)(startData + i), false); - colDataAppend(pDestEndCol, i, (const char*)(endData + i), false); - colDataAppendNULL(pDestUidCol, i); - colDataAppend(pDestGpCol, i, (const char*)&groupId, false); - colDataAppendNULL(pDestCalStartTsCol, i); - colDataAppendNULL(pDestCalEndTsCol, i); - pDestBlock->info.rows++; + uint64_t srcUid = srcUidData[i]; + uint64_t groupId = srcGp[i]; + if (groupId == 0) { + groupId = getGroupIdByData(pInfo, srcUid, srcStartTsCol[i], version); + } + appendOneRowToStreamSpecialBlock(pDestBlock, srcStartTsCol + i, srcEndTsCol + i, srcUidData + i, &groupId, NULL); } return TSDB_CODE_SUCCESS; } @@ -1369,6 +1526,8 @@ static int32_t generateScanRange(SStreamScanInfo* pInfo, SSDataBlock* pSrcBlock, code = generateIntervalScanRange(pInfo, pSrcBlock, pDestBlock); } else if (isSessionWindow(pInfo) || isStateWindow(pInfo)) { code = generateSessionScanRange(pInfo, pSrcBlock, pDestBlock); + } else { + code = generateDeleteResultBlock(pInfo, pSrcBlock, pDestBlock); } pDestBlock->info.type = STREAM_CLEAR; pDestBlock->info.version = pSrcBlock->info.version; @@ -1505,12 +1664,7 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock pInfo->pRes->info.type = STREAM_NORMAL; pInfo->pRes->info.version = pBlock->info.version; - uint64_t* groupIdPre = taosHashGet(pTaskInfo->tableqinfoList.map, &pBlock->info.uid, sizeof(int64_t)); - if (groupIdPre) { - pInfo->pRes->info.groupId = *groupIdPre; - } else { - pInfo->pRes->info.groupId = 0; - } + pInfo->pRes->info.groupId = getTableGroupId(pTaskInfo->pTableInfoList, pBlock->info.uid); // todo extract method for (int32_t i = 0; i < taosArrayGetSize(pInfo->matchInfo.pList); ++i) { @@ -1540,7 +1694,7 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock // currently only the tbname pseudo column if (pInfo->numOfPseudoExpr > 0) { int32_t code = addTagPseudoColumnData(&pInfo->readHandle, pInfo->pPseudoExpr, pInfo->numOfPseudoExpr, pInfo->pRes, - GET_TASKID(pTaskInfo)); + pInfo->pRes->info.rows, GET_TASKID(pTaskInfo), NULL); if (code != TSDB_CODE_SUCCESS) { blockDataFreeRes((SSDataBlock*)pBlock); T_LONG_JMP(pTaskInfo->env, code); @@ -1548,13 +1702,13 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock } if (filter) { - doFilter(pInfo->pCondition, pInfo->pRes, NULL, NULL); + doFilter(pInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL); } + blockDataUpdateTsWindow(pInfo->pRes, pInfo->primaryTsIndex); blockDataFreeRes((SSDataBlock*)pBlock); calBlockTbName(&pInfo->tbnameCalSup, pInfo->pRes); - return 0; } @@ -1655,7 +1809,7 @@ static SSDataBlock* doQueueScan(SOperatorInfo* pOperator) { } } #if 0 - } else if (pTaskInfo->streamInfo.prepareStatus.type == TMQ_OFFSET__SNAPSHOT_DATA) { + } else if (pTaskInfo->streamInfo.prepareStatus.type == TMQ_OFFSET__SNAPSHOT_DATA) { SSDataBlock* pResult = doTableScan(pInfo->pTableScanOp); if (pResult && pResult->info.rows > 0) { qDebug("stream scan tsdb return %d rows", pResult->info.rows); @@ -1698,8 +1852,10 @@ static int32_t filterDelBlockByUid(SSDataBlock* pDst, const SSDataBlock* pSrc, S j++; } } + uint32_t cap = pDst->info.capacity; pDst->info = pSrc->info; pDst->info.rows = j; + pDst->info.capacity = cap; return 0; } @@ -1770,18 +1926,26 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) { } #endif -#if 1 if (pTaskInfo->streamInfo.recoverStep == STREAM_RECOVER_STEP__PREPARE1 || pTaskInfo->streamInfo.recoverStep == STREAM_RECOVER_STEP__PREPARE2) { STableScanInfo* pTSInfo = pInfo->pTableScanOp->info; memcpy(&pTSInfo->cond, &pTaskInfo->streamInfo.tableCond, sizeof(SQueryTableDataCond)); if (pTaskInfo->streamInfo.recoverStep == STREAM_RECOVER_STEP__PREPARE1) { - pTSInfo->cond.startVersion = -1; + pTSInfo->cond.startVersion = 0; pTSInfo->cond.endVersion = pTaskInfo->streamInfo.fillHistoryVer1; + qDebug("stream recover step 1, from %" PRId64 " to %" PRId64, pTSInfo->cond.startVersion, + pTSInfo->cond.endVersion); } else { pTSInfo->cond.startVersion = pTaskInfo->streamInfo.fillHistoryVer1 + 1; pTSInfo->cond.endVersion = pTaskInfo->streamInfo.fillHistoryVer2; + qDebug("stream recover step 2, from %" PRId64 " to %" PRId64, pTSInfo->cond.startVersion, + pTSInfo->cond.endVersion); } + + /*resetTableScanInfo(pTSInfo, pWin);*/ + tsdbReaderClose(pTSInfo->dataReader); + pTSInfo->dataReader = NULL; + pTSInfo->scanTimes = 0; pTSInfo->currentGroupId = -1; pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__SCAN; @@ -1792,15 +1956,22 @@ static SSDataBlock* doStreamScan(SOperatorInfo* pOperator) { if (pBlock != NULL) { calBlockTbName(&pInfo->tbnameCalSup, pBlock); updateInfoFillBlockData(pInfo->pUpdateInfo, pBlock, pInfo->primaryTsIndex); + qDebug("stream recover scan get block, rows %d", pBlock->info.rows); return pBlock; } pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__NONE; + STableScanInfo* pTSInfo = pInfo->pTableScanOp->info; + tsdbReaderClose(pTSInfo->dataReader); + pTSInfo->dataReader = NULL; + + pTSInfo->cond.startVersion = -1; + pTSInfo->cond.endVersion = -1; + return NULL; } -#endif size_t total = taosArrayGetSize(pInfo->pBlockLists); - // TODO: refactor +// TODO: refactor FETCH_NEXT_BLOCK: if (pInfo->blockType == STREAM_INPUT__DATA_BLOCK) { if (pInfo->validBlockIndex >= total) { @@ -1983,7 +2154,7 @@ FETCH_NEXT_BLOCK: } } - doFilter(pInfo->pCondition, pInfo->pRes, NULL, NULL); + doFilter(pInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL); blockDataUpdateTsWindow(pInfo->pRes, pInfo->primaryTsIndex); if (pBlockInfo->rows > 0 || pInfo->pUpdateDataRes->info.rows > 0) { @@ -2020,12 +2191,13 @@ FETCH_NEXT_BLOCK: } } -static SArray* extractTableIdList(const STableListInfo* pTableGroupInfo) { +static SArray* extractTableIdList(const STableListInfo* pTableListInfo) { SArray* tableIdList = taosArrayInit(4, sizeof(uint64_t)); // Transfer the Array of STableKeyInfo into uid list. - for (int32_t i = 0; i < taosArrayGetSize(pTableGroupInfo->pTableList); ++i) { - STableKeyInfo* pkeyInfo = taosArrayGet(pTableGroupInfo->pTableList, i); + size_t size = tableListGetSize(pTableListInfo); + for (int32_t i = 0; i < size; ++i) { + STableKeyInfo* pkeyInfo = tableListGetInfo(pTableListInfo, i); taosArrayPush(tableIdList, &pkeyInfo->uid); } @@ -2048,7 +2220,9 @@ static SSDataBlock* doRawScan(SOperatorInfo* pOperator) { longjmp(pTaskInfo->env, TSDB_CODE_TSC_QUERY_CANCELLED); } - tsdbRetrieveDataBlockInfo(pInfo->dataReader, &pBlock->info); + int32_t rows = 0; + tsdbRetrieveDataBlockInfo(pInfo->dataReader, &rows, &pBlock->info.uid, &pBlock->info.window); + pBlock->info.rows = rows; SArray* pCols = tsdbRetrieveDataBlock(pInfo->dataReader, NULL); pBlock->pDataBlock = pCols; @@ -2176,11 +2350,9 @@ SOperatorInfo* createRawScanOperatorInfo(SReadHandle* pHandle, SExecTaskInfo* pT pInfo->vnode = pHandle->vnode; pInfo->sContext = pHandle->sContext; - pOperator->name = "RawStreamScanOperator"; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; + setOperatorInfo(pOperator, "RawScanOperator", QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN, false, OP_NOT_OPENED, pInfo, pTaskInfo); - pOperator->fpSet = createOperatorFpSet(NULL, doRawScan, NULL, NULL, destroyRawScanOperatorInfo, NULL); + pOperator->fpSet = createOperatorFpSet(NULL, doRawScan, NULL, destroyRawScanOperatorInfo, NULL); return pOperator; _end: @@ -2237,6 +2409,9 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys int32_t numOfCols = 0; int32_t code = extractColMatchInfo(pScanPhyNode->pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID, &pInfo->matchInfo); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } int32_t numOfOutput = taosArrayGetSize(pInfo->matchInfo.pList); SArray* pColIds = taosArrayInit(numOfOutput, sizeof(int16_t)); @@ -2289,12 +2464,17 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys pTSInfo->cond.endVersion = pHandle->version; } - SArray* tableList = taosArrayGetP(pTaskInfo->tableqinfoList.pGroupList, 0); + STableKeyInfo* pList = NULL; + int32_t num = 0; + tableListGetGroupList(pTaskInfo->pTableInfoList, 0, &pList, &num); + if (pHandle->initTableReader) { pTSInfo->scanMode = TABLE_SCAN__TABLE_ORDER; pTSInfo->dataReader = NULL; - if (tsdbReaderOpen(pHandle->vnode, &pTSInfo->cond, tableList, &pTSInfo->dataReader, NULL) < 0) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + code = tsdbReaderOpen(pHandle->vnode, &pTSInfo->cond, pList, num, &pTSInfo->dataReader, NULL); + if (code != 0) { + terrno = code; + destroyTableScanOperatorInfo(pTableScanOp); goto _error; } } @@ -2320,8 +2500,8 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys // set the extract column id to streamHandle tqReaderSetColIdList(pInfo->tqReader, pColIds); - SArray* tableIdList = extractTableIdList(&pTaskInfo->tableqinfoList); - int32_t code = tqReaderSetTbUidList(pInfo->tqReader, tableIdList); + SArray* tableIdList = extractTableIdList(pTaskInfo->pTableInfoList); + code = tqReaderSetTbUidList(pInfo->tqReader, tableIdList); if (code != 0) { taosArrayDestroy(tableIdList); goto _error; @@ -2337,9 +2517,13 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys pInfo->pPseudoExpr = createExprInfo(pTableScanNode->scan.pScanPseudoCols, NULL, &pInfo->numOfPseudoExpr); } + code = filterInitFromNode((SNode*)pScanPhyNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + pInfo->pRes = createResDataBlock(pDescNode); pInfo->pUpdateRes = createSpecialDataBlock(STREAM_CLEAR); - pInfo->pCondition = pScanPhyNode->node.pConditions; pInfo->scanMode = STREAM_SCAN_FROM_READERHANDLE; pInfo->windowSup = (SWindowSupporter){.pStreamAggSup = NULL, .gap = -1, .parentType = QUERY_NODE_PHYSICAL_PLAN}; pInfo->groupId = 0; @@ -2352,16 +2536,11 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys pInfo->assignBlockUid = pTableScanNode->assignBlockUid; pInfo->partitionSup.needCalc = false; - pOperator->name = "StreamScanOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; + setOperatorInfo(pOperator, "StreamScanOperator", QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, false, OP_NOT_OPENED, pInfo, pTaskInfo); pOperator->exprSupp.numOfExprs = taosArrayGetSize(pInfo->pRes->pDataBlock); - pOperator->pTaskInfo = pTaskInfo; __optr_fn_t nextFn = pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM ? doStreamScan : doQueueScan; - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, nextFn, NULL, NULL, destroyStreamScanOperatorInfo, NULL); + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, nextFn, NULL, destroyStreamScanOperatorInfo, NULL); return pOperator; @@ -2480,13 +2659,13 @@ static int32_t loadSysTableCallback(void* param, SDataBuf* pMsg, int32_t code) { return TSDB_CODE_SUCCESS; } -static SSDataBlock* doFilterResult(SSysTableScanInfo* pInfo) { - if (pInfo->pCondition == NULL) { - return pInfo->pRes->info.rows == 0 ? NULL : pInfo->pRes; +static SSDataBlock* doFilterResult(SSDataBlock* pDataBlock, SFilterInfo* pFilterInfo) { + if (pFilterInfo == NULL) { + return pDataBlock->info.rows == 0 ? NULL : pDataBlock; } - doFilter(pInfo->pCondition, pInfo->pRes, NULL, NULL); - return pInfo->pRes->info.rows == 0 ? NULL : pInfo->pRes; + doFilter(pDataBlock, pFilterInfo, NULL); + return pDataBlock->info.rows == 0 ? NULL : pDataBlock; } static SSDataBlock* buildInfoSchemaTableMetaBlock(char* tableName) { @@ -2691,12 +2870,12 @@ static SSDataBlock* sysTableScanUserTags(SOperatorInfo* pOperator) { metaReaderClear(&smrSuperTable); metaReaderClear(&smrChildTable); if (numOfRows > 0) { - relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock); + relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock, pOperator->exprSupp.pFilterInfo); numOfRows = 0; } blockDataDestroy(dataBlock); pInfo->loadInfo.totalRows += pInfo->pRes->info.rows; - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; } @@ -2731,7 +2910,7 @@ static SSDataBlock* sysTableScanUserTags(SOperatorInfo* pOperator) { metaReaderClear(&smrSuperTable); if (numOfRows >= pOperator->resultInfo.capacity) { - relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock); + relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock, pOperator->exprSupp.pFilterInfo); numOfRows = 0; if (pInfo->pRes->info.rows > 0) { @@ -2741,7 +2920,7 @@ static SSDataBlock* sysTableScanUserTags(SOperatorInfo* pOperator) { } if (numOfRows > 0) { - relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock); + relocateAndFilterSysTagsScanResult(pInfo, numOfRows, dataBlock, pOperator->exprSupp.pFilterInfo); numOfRows = 0; } @@ -2749,20 +2928,20 @@ static SSDataBlock* sysTableScanUserTags(SOperatorInfo* pOperator) { if (ret != 0) { metaCloseTbCursor(pInfo->pCur); pInfo->pCur = NULL; - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); } pInfo->loadInfo.totalRows += pInfo->pRes->info.rows; return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; } -static void relocateAndFilterSysTagsScanResult(SSysTableScanInfo* pInfo, int32_t numOfRows, SSDataBlock* dataBlock) { +void relocateAndFilterSysTagsScanResult(SSysTableScanInfo* pInfo, int32_t numOfRows, SSDataBlock* dataBlock, + SFilterInfo* pFilterInfo) { dataBlock->info.rows = numOfRows; pInfo->pRes->info.rows = numOfRows; relocateColumnData(pInfo->pRes, pInfo->matchInfo.pList, dataBlock->pDataBlock, false); - doFilterResult(pInfo); - + doFilterResult(pInfo->pRes, pFilterInfo); blockDataCleanup(dataBlock); } @@ -3206,15 +3385,79 @@ static int tableUidCompare(const void* a, const void* b) { } return u1 < u2 ? -1 : 1; } + +typedef struct MergeIndex { + int idx; + int len; +} MergeIndex; + +static FORCE_INLINE int optSysBinarySearch(SArray* arr, int s, int e, uint64_t k) { + uint64_t v; + int32_t m; + while (s <= e) { + m = s + (e - s) / 2; + v = *(uint64_t*)taosArrayGet(arr, m); + if (v >= k) { + e = m - 1; + } else { + s = m + 1; + } + } + return s; +} + +void optSysIntersection(SArray* in, SArray* out) { + int32_t sz = (int32_t)taosArrayGetSize(in); + if (sz <= 0) { + return; + } + MergeIndex* mi = taosMemoryCalloc(sz, sizeof(MergeIndex)); + for (int i = 0; i < sz; i++) { + SArray* t = taosArrayGetP(in, i); + mi[i].len = (int32_t)taosArrayGetSize(t); + mi[i].idx = 0; + } + + SArray* base = taosArrayGetP(in, 0); + for (int i = 0; i < taosArrayGetSize(base); i++) { + uint64_t tgt = *(uint64_t*)taosArrayGet(base, i); + bool has = true; + for (int j = 1; j < taosArrayGetSize(in); j++) { + SArray* oth = taosArrayGetP(in, j); + int mid = optSysBinarySearch(oth, mi[j].idx, mi[j].len - 1, tgt); + if (mid >= 0 && mid < mi[j].len) { + uint64_t val = *(uint64_t*)taosArrayGet(oth, mid); + has = (val == tgt ? true : false); + mi[j].idx = mid; + } else { + has = false; + } + } + if (has == true) { + taosArrayPush(out, &tgt); + } + } + taosMemoryFreeClear(mi); +} + static int32_t optSysMergeRslt(SArray* mRslt, SArray* rslt) { // TODO, find comm mem from mRslt for (int i = 0; i < taosArrayGetSize(mRslt); i++) { - SArray* aRslt = taosArrayGetP(mRslt, i); - taosArrayAddAll(rslt, aRslt); + SArray* arslt = taosArrayGetP(mRslt, i); + taosArraySort(arslt, tableUidCompare); } - taosArraySort(rslt, tableUidCompare); - taosArrayRemoveDuplicate(rslt, tableUidCompare, NULL); + optSysIntersection(mRslt, rslt); + return 0; +} +static int32_t optSysSpecialColumn(SNode* cond) { + SOperatorNode* pOper = (SOperatorNode*)cond; + SColumnNode* pCol = (SColumnNode*)pOper->pLeft; + for (int i = 0; i < sizeof(SYSTABLE_SPECIAL_COL) / sizeof(SYSTABLE_SPECIAL_COL[0]); i++) { + if (0 == strcmp(pCol->colName, SYSTABLE_SPECIAL_COL[i])) { + return 1; + } + } return 0; } @@ -3241,7 +3484,6 @@ static int32_t optSysTabFilte(void* arg, SNode* cond, SArray* result) { SNodeList* pList = (SNodeList*)pNode->pParameterList; int32_t len = LIST_LENGTH(pList); - if (len <= 0) return ret; bool hasIdx = false; bool hasRslt = true; @@ -3257,7 +3499,12 @@ static int32_t optSysTabFilte(void* arg, SNode* cond, SArray* result) { if (ret == 0) { // has index hasIdx = true; - taosArrayPush(mRslt, &aRslt); + if (optSysSpecialColumn(cell->pNode) == 0) { + taosArrayPush(mRslt, &aRslt); + } else { + // db_name/vgroup not result + taosArrayDestroy(aRslt); + } } else if (ret == -2) { // current vg hasIdx = true; @@ -3328,7 +3575,7 @@ static SSDataBlock* sysTableBuildUserTablesByUids(SOperatorInfo* pOperator) { SMetaReader mr = {0}; metaReaderInit(&mr, pInfo->readHandle.meta, 0); - int32_t ret = metaGetTableEntryByUid(&mr, *uid); + ret = metaGetTableEntryByUid(&mr, *uid); if (ret < 0) { metaReaderClear(&mr); continue; @@ -3448,7 +3695,7 @@ static SSDataBlock* sysTableBuildUserTablesByUids(SOperatorInfo* pOperator) { pInfo->pRes->info.rows = numOfRows; relocateColumnData(pInfo->pRes, pInfo->matchInfo.pList, p->pDataBlock, false); - doFilterResult(pInfo); + doFilterResult(pInfo->pRes, pOperator->exprSupp.pFilterInfo); blockDataCleanup(p); numOfRows = 0; @@ -3464,14 +3711,14 @@ static SSDataBlock* sysTableBuildUserTablesByUids(SOperatorInfo* pOperator) { pInfo->pRes->info.rows = numOfRows; relocateColumnData(pInfo->pRes, pInfo->matchInfo.pList, p->pDataBlock, false); - doFilterResult(pInfo); + doFilterResult(pInfo->pRes, pOperator->exprSupp.pFilterInfo); blockDataCleanup(p); numOfRows = 0; } if (i >= taosArrayGetSize(pIdx->uids)) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); } else { pIdx->lastIdx = i + 1; } @@ -3481,10 +3728,10 @@ static SSDataBlock* sysTableBuildUserTablesByUids(SOperatorInfo* pOperator) { pInfo->loadInfo.totalRows += pInfo->pRes->info.rows; return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; } + static SSDataBlock* sysTableBuildUserTables(SOperatorInfo* pOperator) { SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - qError("%p buildUserTable", pTaskInfo); SSysTableScanInfo* pInfo = pOperator->info; if (pInfo->pCur == NULL) { pInfo->pCur = metaOpenTbCursor(pInfo->readHandle.meta); @@ -3625,7 +3872,7 @@ static SSDataBlock* sysTableBuildUserTables(SOperatorInfo* pOperator) { pInfo->pRes->info.rows = numOfRows; relocateColumnData(pInfo->pRes, pInfo->matchInfo.pList, p->pDataBlock, false); - doFilterResult(pInfo); + doFilterResult(pInfo->pRes, pOperator->exprSupp.pFilterInfo); blockDataCleanup(p); numOfRows = 0; @@ -3641,7 +3888,7 @@ static SSDataBlock* sysTableBuildUserTables(SOperatorInfo* pOperator) { pInfo->pRes->info.rows = numOfRows; relocateColumnData(pInfo->pRes, pInfo->matchInfo.pList, p->pDataBlock, false); - doFilterResult(pInfo); + doFilterResult(pInfo->pRes, pOperator->exprSupp.pFilterInfo); blockDataCleanup(p); numOfRows = 0; @@ -3653,7 +3900,7 @@ static SSDataBlock* sysTableBuildUserTables(SOperatorInfo* pOperator) { if (ret != 0) { metaCloseTbCursor(pInfo->pCur); pInfo->pCur = NULL; - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); } pInfo->loadInfo.totalRows += pInfo->pRes->info.rows; @@ -3672,11 +3919,10 @@ static SSDataBlock* sysTableScanUserTables(SOperatorInfo* pOperator) { // the retrieve is executed on the mnode, so return tables that belongs to the information schema database. if (pInfo->readHandle.mnd != NULL) { buildSysDbTableInfo(pInfo, pOperator->resultInfo.capacity); - - doFilterResult(pInfo); + doFilterResult(pInfo->pRes, pOperator->exprSupp.pFilterInfo); pInfo->loadInfo.totalRows += pInfo->pRes->info.rows; - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return (pInfo->pRes->info.rows == 0) ? NULL : pInfo->pRes; } else { if (pInfo->showRewrite == false) { @@ -3808,7 +4054,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { updateLoadRemoteInfo(&pInfo->loadInfo, pRsp->numOfRows, pRsp->compLen, startTs, pOperator); // todo log the filter info - doFilterResult(pInfo); + doFilterResult(pInfo->pRes, pOperator->exprSupp.pFilterInfo); taosMemoryFree(pRsp); if (pInfo->pRes->info.rows > 0) { return pInfo->pRes; @@ -3892,21 +4138,29 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScan goto _error; } - SScanPhysiNode* pScanNode = &pScanPhyNode->scan; - + SScanPhysiNode* pScanNode = &pScanPhyNode->scan; SDataBlockDescNode* pDescNode = pScanNode->node.pOutputDataBlockDesc; int32_t num = 0; int32_t code = extractColMatchInfo(pScanNode->pScanCols, pDescNode, &num, COL_MATCH_FROM_COL_ID, &pInfo->matchInfo); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } pInfo->accountId = pScanPhyNode->accountId; pInfo->pUser = taosMemoryStrDup((void*)pUser); pInfo->sysInfo = pScanPhyNode->sysInfo; pInfo->showRewrite = pScanPhyNode->showRewrite; pInfo->pRes = createResDataBlock(pDescNode); + pInfo->pCondition = pScanNode->node.pConditions; + code = filterInitFromNode(pScanNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } initResultSizeInfo(&pOperator->resultInfo, 4096); + blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); tNameAssign(&pInfo->name, &pScanNode->tableName); const char* name = tNameGetTableName(&pInfo->name); @@ -3914,29 +4168,23 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSystemTableScan if (strncasecmp(name, TSDB_INS_TABLE_TABLES, TSDB_TABLE_FNAME_LEN) == 0 || strncasecmp(name, TSDB_INS_TABLE_TAGS, TSDB_TABLE_FNAME_LEN) == 0) { pInfo->readHandle = *(SReadHandle*)readHandle; - blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); } else { tsem_init(&pInfo->ready, 0, 0); pInfo->epSet = pScanPhyNode->mgmtEpSet; pInfo->readHandle = *(SReadHandle*)readHandle; } - pOperator->name = "SysTableScanOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; + setOperatorInfo(pOperator, "SysTableScanOperator", QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN, false, OP_NOT_OPENED, pInfo, pTaskInfo); pOperator->exprSupp.numOfExprs = taosArrayGetSize(pInfo->pRes->pDataBlock); - pOperator->pTaskInfo = pTaskInfo; - - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doSysTableScan, NULL, NULL, destroySysScanOperator, NULL); - + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doSysTableScan, NULL, destroySysScanOperator, NULL); return pOperator; _error: - taosMemoryFreeClear(pInfo); + if (pInfo != NULL) { + destroySysScanOperator(pInfo); + } taosMemoryFreeClear(pOperator); - terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; + pTaskInfo->code = code; return NULL; } @@ -3952,7 +4200,7 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator) { SSDataBlock* pRes = pInfo->pRes; blockDataCleanup(pRes); - int32_t size = taosArrayGetSize(pInfo->pTableList->pTableList); + int32_t size = tableListGetSize(pTaskInfo->pTableInfoList); if (size == 0) { setTaskStatus(pTaskInfo, TASK_COMPLETED); return NULL; @@ -3964,7 +4212,7 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator) { metaReaderInit(&mr, pInfo->readHandle.meta, 0); while (pInfo->curPos < size && count < pOperator->resultInfo.capacity) { - STableKeyInfo* item = taosArrayGet(pInfo->pTableList->pTableList, pInfo->curPos); + STableKeyInfo* item = tableListGetInfo(pInfo->pTableList, pInfo->curPos); int32_t code = metaGetTableEntryByUid(&mr, item->uid); tDecoderClear(&mr.coder); if (code != TSDB_CODE_SUCCESS) { @@ -4004,7 +4252,7 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator) { count += 1; if (++pInfo->curPos >= size) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); } } @@ -4038,13 +4286,15 @@ SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysi SDataBlockDescNode* pDescNode = pPhyNode->node.pOutputDataBlockDesc; - int32_t num = 0; int32_t numOfExprs = 0; SExprInfo* pExprInfo = createExprInfo(pPhyNode->pScanPseudoCols, NULL, &numOfExprs); - int32_t code = - extractColMatchInfo(pPhyNode->pScanPseudoCols, pDescNode, &num, COL_MATCH_FROM_COL_ID, &pInfo->matchInfo); + int32_t code = initExprSupp(&pOperator->exprSupp, pExprInfo, numOfExprs); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } - code = initExprSupp(&pOperator->exprSupp, pExprInfo, numOfExprs); + int32_t num = 0; + code = extractColMatchInfo(pPhyNode->pScanPseudoCols, pDescNode, &num, COL_MATCH_FROM_COL_ID, &pInfo->matchInfo); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -4054,18 +4304,11 @@ SOperatorInfo* createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysi pInfo->readHandle = *pReadHandle; pInfo->curPos = 0; - pOperator->name = "TagScanOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN; - - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; - + setOperatorInfo(pOperator, "TagScanOperator", QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN, false, OP_NOT_OPENED, pInfo, pTaskInfo); initResultSizeInfo(&pOperator->resultInfo, 4096); blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTagScan, NULL, NULL, destroyTagScanOperatorInfo, NULL); + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTagScan, NULL, destroyTagScanOperatorInfo, NULL); return pOperator; @@ -4076,61 +4319,9 @@ _error: return NULL; } -int32_t createScanTableListInfo(SScanPhysiNode* pScanNode, SNodeList* pGroupTags, bool groupSort, SReadHandle* pHandle, - STableListInfo* pTableListInfo, SNode* pTagCond, SNode* pTagIndexCond, - const char* idStr) { - int64_t st = taosGetTimestampUs(); - - if (pHandle == NULL) { - qError("invalid handle, in creating operator tree, %s", idStr); - return TSDB_CODE_INVALID_PARA; - } - - int32_t code = getTableList(pHandle->meta, pHandle->vnode, pScanNode, pTagCond, pTagIndexCond, pTableListInfo); - if (code != TSDB_CODE_SUCCESS) { - qError("failed to getTableList, code: %s", tstrerror(code)); - return code; - } - - int64_t st1 = taosGetTimestampUs(); - qDebug("generate queried table list completed, elapsed time:%.2f ms %s", (st1 - st) / 1000.0, idStr); - - if (taosArrayGetSize(pTableListInfo->pTableList) == 0) { - qDebug("no table qualified for query, %s" PRIx64, idStr); - return TSDB_CODE_SUCCESS; - } - - pTableListInfo->needSortTableByGroupId = groupSort; - code = generateGroupIdMap(pTableListInfo, pHandle, pGroupTags); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - - int64_t st2 = taosGetTimestampUs(); - qDebug("generate group id map completed, elapsed time:%.2f ms %s", (st2 - st1) / 1000.0, idStr); - - return TSDB_CODE_SUCCESS; -} - -int32_t createMultipleDataReaders(SQueryTableDataCond* pQueryCond, SReadHandle* pHandle, STableListInfo* pTableListInfo, - int32_t tableStartIdx, int32_t tableEndIdx, SArray* arrayReader, const char* idstr) { - for (int32_t i = tableStartIdx; i <= tableEndIdx; ++i) { - SArray* subTableList = taosArrayInit(1, sizeof(STableKeyInfo)); - taosArrayPush(subTableList, taosArrayGet(pTableListInfo->pTableList, i)); - - STsdbReader* pReader = NULL; - tsdbReaderOpen(pHandle->vnode, pQueryCond, subTableList, &pReader, idstr); - taosArrayPush(arrayReader, &pReader); - - taosArrayDestroy(subTableList); - } - - return TSDB_CODE_SUCCESS; -} - // todo refactor static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeScanInfo* pTableScanInfo, - int32_t readerIdx, SSDataBlock* pBlock, uint32_t* status) { + SSDataBlock* pBlock, uint32_t* status) { SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; STableMergeScanInfo* pInfo = pOperator->info; @@ -4140,7 +4331,7 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc pCost->totalRows += pBlock->info.rows; *status = pInfo->dataBlockLoadFlag; - if (pTableScanInfo->pFilterNode != NULL || + if (pOperator->exprSupp.pFilterInfo != NULL || overlapWithTimeWindow(&pTableScanInfo->interval, &pBlock->info, pTableScanInfo->cond.order)) { (*status) = FUNC_DATA_REQUIRED_DATA_LOAD; } @@ -4165,13 +4356,11 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc } return TSDB_CODE_SUCCESS; - } else if (*status == FUNC_DATA_REQUIRED_STATIS_LOAD) { + } else if (*status == FUNC_DATA_REQUIRED_SMA_LOAD) { pCost->loadBlockStatis += 1; bool allColumnsHaveAgg = true; SColumnDataAgg** pColAgg = NULL; - STsdbReader* reader = taosArrayGetP(pTableScanInfo->dataReaders, readerIdx); - tsdbRetrieveDatablockSMA(reader, &pColAgg, &allColumnsHaveAgg); if (allColumnsHaveAgg == true) { int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); @@ -4211,7 +4400,7 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc pCost->totalCheckedRows += pBlock->info.rows; pCost->loadBlocks += 1; - STsdbReader* reader = taosArrayGetP(pTableScanInfo->dataReaders, readerIdx); + STsdbReader* reader = pTableScanInfo->pReader; SArray* pCols = tsdbRetrieveDataBlock(reader, NULL); if (pCols == NULL) { return terrno; @@ -4220,17 +4409,17 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc relocateColumnData(pBlock, pTableScanInfo->matchInfo.pList, pCols, true); // currently only the tbname pseudo column - if (pTableScanInfo->pseudoSup.numOfExprs > 0) { - int32_t code = addTagPseudoColumnData(&pTableScanInfo->readHandle, pTableScanInfo->pseudoSup.pExprInfo, - pTableScanInfo->pseudoSup.numOfExprs, pBlock, GET_TASKID(pTaskInfo)); - if (code != TSDB_CODE_SUCCESS) { - T_LONG_JMP(pTaskInfo->env, code); - } + SExprSupp* pSup = &pTableScanInfo->pseudoSup; + + int32_t code = addTagPseudoColumnData(&pTableScanInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pBlock, + pBlock->info.rows, GET_TASKID(pTaskInfo), NULL); + if (code != TSDB_CODE_SUCCESS) { + T_LONG_JMP(pTaskInfo->env, code); } - if (pTableScanInfo->pFilterNode != NULL) { + if (pOperator->exprSupp.pFilterInfo!= NULL) { int64_t st = taosGetTimestampMs(); - doFilter(pTableScanInfo->pFilterNode, pBlock, &pTableScanInfo->matchInfo, NULL); + doFilter(pBlock, pOperator->exprSupp.pFilterInfo, &pTableScanInfo->matchInfo); double el = (taosGetTimestampUs() - st) / 1000.0; pTableScanInfo->readRecorder.filterTime += el; @@ -4247,27 +4436,32 @@ static int32_t loadDataBlockFromOneTable(SOperatorInfo* pOperator, STableMergeSc return TSDB_CODE_SUCCESS; } -typedef struct STableMergeScanSortSourceParam { - SOperatorInfo* pOperator; - int32_t readerIdx; - SSDataBlock* inputBlock; -} STableMergeScanSortSourceParam; - -static SSDataBlock* getTableDataBlock(void* param) { +static SSDataBlock* getTableDataBlockImpl(void* param) { STableMergeScanSortSourceParam* source = param; SOperatorInfo* pOperator = source->pOperator; - int32_t readerIdx = source->readerIdx; + STableMergeScanInfo* pInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + int32_t readIdx = source->readerIdx; SSDataBlock* pBlock = source->inputBlock; STableMergeScanInfo* pTableScanInfo = pOperator->info; + SQueryTableDataCond* pQueryCond = taosArrayGet(pTableScanInfo->queryConds, readIdx); + blockDataCleanup(pBlock); + int64_t st = taosGetTimestampUs(); - blockDataCleanup(pBlock); + void* p = tableListGetInfo(pInfo->tableListInfo, readIdx + pInfo->tableStartIndex); + SReadHandle* pHandle = &pInfo->readHandle; - STsdbReader* reader = taosArrayGetP(pTableScanInfo->dataReaders, readerIdx); + int32_t code = tsdbReaderOpen(pHandle->vnode, pQueryCond, p, 1, &pInfo->pReader, GET_TASKID(pTaskInfo)); + if (code != 0) { + T_LONG_JMP(pTaskInfo->env, code); + } + + STsdbReader* reader = pInfo->pReader; while (tsdbNextDataBlock(reader)) { - if (isTaskKilled(pOperator->pTaskInfo)) { - T_LONG_JMP(pOperator->pTaskInfo->env, TSDB_CODE_TSC_QUERY_CANCELLED); + if (isTaskKilled(pTaskInfo)) { + T_LONG_JMP(pTaskInfo->env, TSDB_CODE_TSC_QUERY_CANCELLED); } // process this data block based on the probabilities @@ -4277,20 +4471,22 @@ static SSDataBlock* getTableDataBlock(void* param) { } blockDataCleanup(pBlock); - SDataBlockInfo binfo = pBlock->info; - tsdbRetrieveDataBlockInfo(reader, &binfo); - blockDataEnsureCapacity(pBlock, binfo.rows); - pBlock->info.type = binfo.type; - pBlock->info.uid = binfo.uid; - pBlock->info.window = binfo.window; - pBlock->info.rows = binfo.rows; + int32_t rows = 0; + tsdbRetrieveDataBlockInfo(reader, &rows, &pBlock->info.uid, &pBlock->info.window); + blockDataEnsureCapacity(pBlock, rows); + pBlock->info.rows = rows; + + if (pQueryCond->order == TSDB_ORDER_ASC) { + pQueryCond->twindows.skey = pBlock->info.window.ekey + 1; + } else { + pQueryCond->twindows.ekey = pBlock->info.window.skey - 1; + } uint32_t status = 0; - int32_t code = loadDataBlockFromOneTable(pOperator, pTableScanInfo, readerIdx, pBlock, &status); - // int32_t code = loadDataBlockOnDemand(pOperator->pRuntimeEnv, pTableScanInfo, pBlock, &status); + code = loadDataBlockFromOneTable(pOperator, pTableScanInfo, pBlock, &status); if (code != TSDB_CODE_SUCCESS) { - T_LONG_JMP(pOperator->pTaskInfo->env, code); + T_LONG_JMP(pTaskInfo->env, code); } // current block is filter out according to filter condition, continue load the next block @@ -4298,16 +4494,18 @@ static SSDataBlock* getTableDataBlock(void* param) { continue; } - uint64_t* groupId = taosHashGet(pOperator->pTaskInfo->tableqinfoList.map, &pBlock->info.uid, sizeof(int64_t)); - if (groupId) { - pBlock->info.groupId = *groupId; - } + pBlock->info.groupId = getTableGroupId(pTaskInfo->pTableInfoList, pBlock->info.uid); - pOperator->resultInfo.totalRows = pTableScanInfo->readRecorder.totalRows; + pOperator->resultInfo.totalRows += pBlock->info.rows; pTableScanInfo->readRecorder.elapsedTime += (taosGetTimestampUs() - st) / 1000.0; + tsdbReaderClose(pInfo->pReader); + pInfo->pReader = NULL; return pBlock; } + + tsdbReaderClose(pInfo->pReader); + pInfo->pReader = NULL; return NULL; } @@ -4331,15 +4529,24 @@ SArray* generateSortByTsInfo(SArray* colMatchInfo, int32_t order) { return pList; } +int32_t dumpSQueryTableCond(const SQueryTableDataCond* src, SQueryTableDataCond* dst) { + memcpy((void*)dst, (void*)src, sizeof(SQueryTableDataCond)); + dst->colList = taosMemoryCalloc(src->numOfCols, sizeof(SColumnInfo)); + for (int i = 0; i < src->numOfCols; i++) { + dst->colList[i] = src->colList[i]; + } + return 0; +} + int32_t startGroupTableMergeScan(SOperatorInfo* pOperator) { STableMergeScanInfo* pInfo = pOperator->info; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; { - size_t tableListSize = taosArrayGetSize(pInfo->tableListInfo->pTableList); + size_t numOfTables = tableListGetSize(pInfo->tableListInfo); int32_t i = pInfo->tableStartIndex + 1; - for (; i < tableListSize; ++i) { - STableKeyInfo* tableKeyInfo = taosArrayGet(pInfo->tableListInfo->pTableList, i); + for (; i < numOfTables; ++i) { + STableKeyInfo* tableKeyInfo = tableListGetInfo(pInfo->tableListInfo, i); if (tableKeyInfo->groupId != pInfo->groupId) { break; } @@ -4350,10 +4557,7 @@ int32_t startGroupTableMergeScan(SOperatorInfo* pOperator) { int32_t tableStartIdx = pInfo->tableStartIndex; int32_t tableEndIdx = pInfo->tableEndIndex; - STableListInfo* tableListInfo = pInfo->tableListInfo; - pInfo->dataReaders = taosArrayInit(64, POINTER_BYTES); - createMultipleDataReaders(&pInfo->cond, &pInfo->readHandle, tableListInfo, tableStartIdx, tableEndIdx, - pInfo->dataReaders, GET_TASKID(pTaskInfo)); + pInfo->pReader = NULL; // todo the total available buffer should be determined by total capacity of buffer of this task. // the additional one is reserved for merge result @@ -4362,18 +4566,25 @@ int32_t startGroupTableMergeScan(SOperatorInfo* pOperator) { pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, SORT_MULTISOURCE_MERGE, pInfo->bufPageSize, numOfBufPage, pInfo->pSortInputBlock, pTaskInfo->id.str); - tsortSetFetchRawDataFp(pInfo->pSortHandle, getTableDataBlock, NULL, NULL); + tsortSetFetchRawDataFp(pInfo->pSortHandle, getTableDataBlockImpl, NULL, NULL); - size_t numReaders = taosArrayGetSize(pInfo->dataReaders); - for (int32_t i = 0; i < numReaders; ++i) { + // one table has one data block + int32_t numOfTable = tableEndIdx - tableStartIdx + 1; + pInfo->queryConds = taosArrayInit(numOfTable, sizeof(SQueryTableDataCond)); + + for (int32_t i = 0; i < numOfTable; ++i) { STableMergeScanSortSourceParam param = {0}; param.readerIdx = i; param.pOperator = pOperator; param.inputBlock = createOneDataBlock(pInfo->pResBlock, false); taosArrayPush(pInfo->sortSourceParams, ¶m); + + SQueryTableDataCond cond; + dumpSQueryTableCond(&pInfo->cond, &cond); + taosArrayPush(pInfo->queryConds, &cond); } - for (int32_t i = 0; i < numReaders; ++i) { + for (int32_t i = 0; i < numOfTable; ++i) { SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource)); STableMergeScanSortSourceParam* param = taosArrayGet(pInfo->sortSourceParams, i); ps->param = param; @@ -4393,7 +4604,7 @@ int32_t stopGroupTableMergeScan(SOperatorInfo* pOperator) { STableMergeScanInfo* pInfo = pOperator->info; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - size_t numReaders = taosArrayGetSize(pInfo->dataReaders); + int32_t numOfTable = taosArrayGetSize(pInfo->queryConds); SSortExecInfo sortExecInfo = tsortGetSortExecInfo(pInfo->pSortHandle); pInfo->sortExecInfo.sortMethod = sortExecInfo.sortMethod; @@ -4402,7 +4613,7 @@ int32_t stopGroupTableMergeScan(SOperatorInfo* pOperator) { pInfo->sortExecInfo.readBytes += sortExecInfo.readBytes; pInfo->sortExecInfo.writeBytes += sortExecInfo.writeBytes; - for (int32_t i = 0; i < numReaders; ++i) { + for (int32_t i = 0; i < numOfTable; ++i) { STableMergeScanSortSourceParam* param = taosArrayGet(pInfo->sortSourceParams, i); blockDataDestroy(param->inputBlock); } @@ -4410,12 +4621,13 @@ int32_t stopGroupTableMergeScan(SOperatorInfo* pOperator) { tsortDestroySortHandle(pInfo->pSortHandle); - for (int32_t i = 0; i < numReaders; ++i) { - STsdbReader* reader = taosArrayGetP(pInfo->dataReaders, i); - tsdbReaderClose(reader); + for (int32_t i = 0; i < taosArrayGetSize(pInfo->queryConds); i++) { + SQueryTableDataCond* cond = taosArrayGet(pInfo->queryConds, i); + taosMemoryFree(cond->colList); } - taosArrayDestroy(pInfo->dataReaders); - pInfo->dataReaders = NULL; + taosArrayDestroy(pInfo->queryConds); + pInfo->queryConds = NULL; + return TSDB_CODE_SUCCESS; } @@ -4425,7 +4637,6 @@ SSDataBlock* getSortedTableMergeScanBlockData(SSortHandle* pHandle, SSDataBlock* SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; blockDataCleanup(pResBlock); - blockDataEnsureCapacity(pResBlock, capacity); while (1) { STupleHandle* pTupleHandle = tsortNextTuple(pHandle); @@ -4440,6 +4651,9 @@ SSDataBlock* getSortedTableMergeScanBlockData(SSortHandle* pHandle, SSDataBlock* } qDebug("%s get sorted row blocks, rows:%d", GET_TASKID(pTaskInfo), pResBlock->info.rows); + applyLimitOffset(&pInfo->limitInfo, pResBlock, pTaskInfo, pOperator); + pInfo->limitInfo.numOfOutputRows += pResBlock->info.rows; + return (pResBlock->info.rows > 0) ? pResBlock : NULL; } @@ -4455,18 +4669,20 @@ SSDataBlock* doTableMergeScan(SOperatorInfo* pOperator) { if (code != TSDB_CODE_SUCCESS) { T_LONG_JMP(pTaskInfo->env, code); } - size_t tableListSize = taosArrayGetSize(pInfo->tableListInfo->pTableList); + + size_t tableListSize = tableListGetSize(pInfo->tableListInfo); if (!pInfo->hasGroupId) { pInfo->hasGroupId = true; if (tableListSize == 0) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return NULL; } pInfo->tableStartIndex = 0; - pInfo->groupId = ((STableKeyInfo*)taosArrayGet(pInfo->tableListInfo->pTableList, pInfo->tableStartIndex))->groupId; + pInfo->groupId = ((STableKeyInfo*)tableListGetInfo(pInfo->tableListInfo, pInfo->tableStartIndex))->groupId; startGroupTableMergeScan(pOperator); } + SSDataBlock* pBlock = NULL; while (pInfo->tableStartIndex < tableListSize) { pBlock = getSortedTableMergeScanBlockData(pInfo->pSortHandle, pInfo->pResBlock, pOperator->resultInfo.capacity, @@ -4478,12 +4694,11 @@ SSDataBlock* doTableMergeScan(SOperatorInfo* pOperator) { } else { stopGroupTableMergeScan(pOperator); if (pInfo->tableEndIndex >= tableListSize - 1) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); break; } pInfo->tableStartIndex = pInfo->tableEndIndex + 1; - pInfo->groupId = - ((STableKeyInfo*)taosArrayGet(pInfo->tableListInfo->pTableList, pInfo->tableStartIndex))->groupId; + pInfo->groupId = tableListGetInfo(pInfo->tableListInfo, pInfo->tableStartIndex)->groupId; startGroupTableMergeScan(pOperator); } } @@ -4494,13 +4709,24 @@ SSDataBlock* doTableMergeScan(SOperatorInfo* pOperator) { void destroyTableMergeScanOperatorInfo(void* param) { STableMergeScanInfo* pTableScanInfo = (STableMergeScanInfo*)param; cleanupQueryTableDataCond(&pTableScanInfo->cond); + + int32_t numOfTable = taosArrayGetSize(pTableScanInfo->queryConds); + + for (int32_t i = 0; i < numOfTable; i++) { + STableMergeScanSortSourceParam* p = taosArrayGet(pTableScanInfo->sortSourceParams, i); + blockDataDestroy(p->inputBlock); + } + taosArrayDestroy(pTableScanInfo->sortSourceParams); - for (int32_t i = 0; i < taosArrayGetSize(pTableScanInfo->dataReaders); ++i) { - STsdbReader* reader = taosArrayGetP(pTableScanInfo->dataReaders, i); - tsdbReaderClose(reader); + tsdbReaderClose(pTableScanInfo->pReader); + pTableScanInfo->pReader = NULL; + + for (int i = 0; i < taosArrayGetSize(pTableScanInfo->queryConds); i++) { + SQueryTableDataCond* pCond = taosArrayGet(pTableScanInfo->queryConds, i); + taosMemoryFree(pCond->colList); } - taosArrayDestroy(pTableScanInfo->dataReaders); + taosArrayDestroy(pTableScanInfo->queryConds); if (pTableScanInfo->matchInfo.pList != NULL) { taosArrayDestroy(pTableScanInfo->matchInfo.pList); @@ -4516,11 +4742,6 @@ void destroyTableMergeScanOperatorInfo(void* param) { taosMemoryFreeClear(param); } -typedef struct STableMergeScanExecInfo { - SFileBlockLoadRecorder blockRecorder; - SSortExecInfo sortExecInfo; -} STableMergeScanExecInfo; - int32_t getTableMergeScanExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len) { ASSERT(pOptr != NULL); // TODO: merge these two info into one struct @@ -4535,18 +4756,6 @@ int32_t getTableMergeScanExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExpla return TSDB_CODE_SUCCESS; } -int32_t compareTableKeyInfoByGid(const void* p1, const void* p2) { - const STableKeyInfo* info1 = p1; - const STableKeyInfo* info2 = p2; - if (info1->groupId < info2->groupId) { - return -1; - } else if (info1->groupId > info2->groupId) { - return 1; - } else { - return 0; - } -} - SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanNode, STableListInfo* pTableListInfo, SReadHandle* readHandle, SExecTaskInfo* pTaskInfo) { STableMergeScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableMergeScanInfo)); @@ -4554,15 +4763,15 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN if (pInfo == NULL || pOperator == NULL) { goto _error; } - if (pTableScanNode->pGroupTags) { - taosArraySort(pTableListInfo->pTableList, compareTableKeyInfoByGid); - } SDataBlockDescNode* pDescNode = pTableScanNode->scan.node.pOutputDataBlockDesc; int32_t numOfCols = 0; int32_t code = extractColMatchInfo(pTableScanNode->scan.pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID, &pInfo->matchInfo); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } code = initQueryTableDataCond(&pInfo->cond, pTableScanNode); if (code != TSDB_CODE_SUCCESS) { @@ -4583,29 +4792,33 @@ SOperatorInfo* createTableMergeScanOperatorInfo(STableScanPhysiNode* pTableScanN pInfo->sample.sampleRatio = pTableScanNode->ratio; pInfo->sample.seed = taosGetTimestampSec(); pInfo->dataBlockLoadFlag = pTableScanNode->dataRequired; - pInfo->pFilterNode = pTableScanNode->scan.node.pConditions; + + + code = filterInitFromNode((SNode*)pTableScanNode->scan.node.pConditions, &pOperator->exprSupp.pFilterInfo, 0); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + pInfo->tableListInfo = pTableListInfo; pInfo->scanFlag = MAIN_SCAN; + initResultSizeInfo(&pOperator->resultInfo, 1024); pInfo->pResBlock = createResDataBlock(pDescNode); + blockDataEnsureCapacity(pInfo->pResBlock, pOperator->resultInfo.capacity); + pInfo->sortSourceParams = taosArrayInit(64, sizeof(STableMergeScanSortSourceParam)); pInfo->pSortInfo = generateSortByTsInfo(pInfo->matchInfo.pList, pInfo->cond.order); pInfo->pSortInputBlock = createOneDataBlock(pInfo->pResBlock, false); + initLimitInfo(pTableScanNode->scan.node.pLimit, pTableScanNode->scan.node.pSlimit, &pInfo->limitInfo); int32_t rowSize = pInfo->pResBlock->info.rowSize; pInfo->bufPageSize = getProperSortPageSize(rowSize); - pOperator->name = "TableMergeScanOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; + setOperatorInfo(pOperator, "TableMergeScanOperator", QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN, false, OP_NOT_OPENED, pInfo, pTaskInfo); pOperator->exprSupp.numOfExprs = numOfCols; - pOperator->pTaskInfo = pTaskInfo; - initResultSizeInfo(&pOperator->resultInfo, 1024); - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableMergeScan, NULL, NULL, + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableMergeScan, NULL, destroyTableMergeScanOperatorInfo, getTableMergeScanExplainExecInfo); pOperator->cost.openCost = 0; return pOperator; diff --git a/source/libs/executor/src/sortoperator.c b/source/libs/executor/src/sortoperator.c index 04f86d90d5eeb07d19feb15adbf65b04d9eb23cd..fc53623d44607ad17503d43351340348ace6b3fb 100644 --- a/source/libs/executor/src/sortoperator.c +++ b/source/libs/executor/src/sortoperator.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#include "filter.h" #include "executorimpl.h" #include "tdatablock.h" @@ -20,7 +21,7 @@ static SSDataBlock* doSort(SOperatorInfo* pOperator); static int32_t doOpenSortOperator(SOperatorInfo* pOperator); static int32_t getExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len); -static void destroyOrderOperatorInfo(void* param); +static void destroySortOperatorInfo(void* param); // todo add limit/offset impl SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode* pSortNode, SExecTaskInfo* pTaskInfo) { @@ -38,22 +39,21 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode* SExprInfo* pExprInfo = createExprInfo(pSortNode->pExprs, NULL, &numOfCols); int32_t numOfOutputCols = 0; - int32_t code = extractColMatchInfo(pSortNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID, &pInfo->matchInfo); + int32_t code = + extractColMatchInfo(pSortNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID, &pInfo->matchInfo); pOperator->exprSupp.pCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pOperator->exprSupp.rowEntryInfoOffset); - initResultSizeInfo(&pOperator->resultInfo, 1024); + code = filterInitFromNode((SNode*)pSortNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } pInfo->binfo.pRes = pResBlock; pInfo->pSortInfo = createSortInfo(pSortNode->pSortKeys); - pInfo->pCondition = pSortNode->node.pConditions; initLimitInfo(pSortNode->node.pLimit, pSortNode->node.pSlimit, &pInfo->limitInfo); - pOperator->name = "SortOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SORT; - pOperator->blocking = true; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; + setOperatorInfo(pOperator, "SortOperator", QUERY_NODE_PHYSICAL_PLAN_SORT, true, OP_NOT_OPENED, pInfo, pTaskInfo); pOperator->exprSupp.pExprInfo = pExprInfo; pOperator->exprSupp.numOfExprs = numOfCols; @@ -62,8 +62,8 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSortPhysiNode* // there are headers, so pageSize = rowSize + header pInfo->sortBufSize = pInfo->bufPageSize * 16; // TODO dynamic set the available sort buffer - pOperator->fpSet = createOperatorFpSet(doOpenSortOperator, doSort, NULL, NULL, destroyOrderOperatorInfo, - getExplainExecInfo); + pOperator->fpSet = + createOperatorFpSet(doOpenSortOperator, doSort, NULL, destroySortOperatorInfo, getExplainExecInfo); code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -126,7 +126,7 @@ SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, i int32_t numOfCols = taosArrayGetSize(pColMatchInfo); for (int32_t i = 0; i < numOfCols; ++i) { SColMatchItem* pmInfo = taosArrayGet(pColMatchInfo, i); -// ASSERT(pmInfo->matchType == COL_MATCH_FROM_SLOT_ID); + // ASSERT(pmInfo->matchType == COL_MATCH_FROM_SLOT_ID); SColumnInfoData* pSrc = taosArrayGet(p->pDataBlock, pmInfo->srcSlotId); SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->dstSlotId); @@ -210,11 +210,11 @@ SSDataBlock* doSort(SOperatorInfo* pOperator) { pBlock = getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, pInfo->matchInfo.pList, pInfo); if (pBlock == NULL) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return NULL; } - doFilter(pInfo->pCondition, pBlock, &pInfo->matchInfo, NULL); + doFilter(pBlock, pOperator->exprSupp.pFilterInfo, &pInfo->matchInfo); if (blockDataGetNumOfRows(pBlock) == 0) { continue; } @@ -248,7 +248,7 @@ SSDataBlock* doSort(SOperatorInfo* pOperator) { return blockDataGetNumOfRows(pBlock) > 0 ? pBlock : NULL; } -void destroyOrderOperatorInfo(void* param) { +void destroySortOperatorInfo(void* param) { SSortOperatorInfo* pInfo = (SSortOperatorInfo*)param; pInfo->binfo.pRes = blockDataDestroy(pInfo->binfo.pRes); @@ -316,7 +316,7 @@ SSDataBlock* getGroupSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlo int32_t numOfCols = taosArrayGetSize(pColMatchInfo); for (int32_t i = 0; i < numOfCols; ++i) { SColMatchItem* pmInfo = taosArrayGet(pColMatchInfo, i); -// ASSERT(pmInfo->matchType == COL_MATCH_FROM_SLOT_ID); + // ASSERT(pmInfo->matchType == COL_MATCH_FROM_SLOT_ID); SColumnInfoData* pSrc = taosArrayGet(p->pDataBlock, pmInfo->srcSlotId); SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->dstSlotId); @@ -424,7 +424,7 @@ SSDataBlock* doGroupSort(SOperatorInfo* pOperator) { pInfo->prefetchedSortInput = pOperator->pDownstream[0]->fpSet.getNextFn(pOperator->pDownstream[0]); if (pInfo->prefetchedSortInput == NULL) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return NULL; } pInfo->currGroupId = pInfo->prefetchedSortInput->info.groupId; @@ -449,7 +449,7 @@ SSDataBlock* doGroupSort(SOperatorInfo* pOperator) { beginSortGroup(pOperator); } else if (pInfo->childOpStatus == CHILD_OP_FINISHED) { finishSortGroup(pOperator); - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return NULL; } } @@ -478,37 +478,35 @@ SOperatorInfo* createGroupSortOperatorInfo(SOperatorInfo* downstream, SGroupSort SExecTaskInfo* pTaskInfo) { SGroupSortOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SGroupSortOperatorInfo)); SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo)); - if (pInfo == NULL || pOperator == NULL /* || rowSize > 100 * 1024 * 1024*/) { + if (pInfo == NULL || pOperator == NULL) { goto _error; } + SExprSupp* pSup = &pOperator->exprSupp; SDataBlockDescNode* pDescNode = pSortPhyNode->node.pOutputDataBlockDesc; int32_t numOfCols = 0; - SSDataBlock* pResBlock = createResDataBlock(pDescNode); SExprInfo* pExprInfo = createExprInfo(pSortPhyNode->pExprs, NULL, &numOfCols); - int32_t numOfOutputCols = 0; - int32_t code = extractColMatchInfo(pSortPhyNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID, - &pInfo->matchInfo); - - pOperator->exprSupp.pCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pOperator->exprSupp.rowEntryInfoOffset); - pInfo->binfo.pRes = pResBlock; + pSup->pExprInfo = pExprInfo; + pSup->numOfExprs = numOfCols; initResultSizeInfo(&pOperator->resultInfo, 1024); + pOperator->exprSupp.pCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pOperator->exprSupp.rowEntryInfoOffset); - pInfo->pSortInfo = createSortInfo(pSortPhyNode->pSortKeys); + pInfo->binfo.pRes = createResDataBlock(pDescNode); + blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity); - pOperator->name = "GroupSortOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->exprSupp.pExprInfo = pExprInfo; - pOperator->exprSupp.numOfExprs = numOfCols; - pOperator->pTaskInfo = pTaskInfo; + int32_t numOfOutputCols = 0; + int32_t code = extractColMatchInfo(pSortPhyNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID, + &pInfo->matchInfo); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doGroupSort, NULL, NULL, destroyGroupSortOperatorInfo, + pInfo->pSortInfo = createSortInfo(pSortPhyNode->pSortKeys); + setOperatorInfo(pOperator, "GroupSortOperator", QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT, false, OP_NOT_OPENED, pInfo, pTaskInfo); + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doGroupSort, NULL, destroyGroupSortOperatorInfo, getGroupSortExplainExecInfo); code = appendDownstream(pOperator, &downstream, 1); @@ -519,8 +517,10 @@ SOperatorInfo* createGroupSortOperatorInfo(SOperatorInfo* downstream, SGroupSort return pOperator; _error: - pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; - taosMemoryFree(pInfo); + pTaskInfo->code = code; + if (pInfo != NULL) { + destroyGroupSortOperatorInfo(pInfo); + } taosMemoryFree(pOperator); return NULL; } @@ -531,7 +531,7 @@ typedef struct SMultiwayMergeOperatorInfo { SOptrBasicInfo binfo; int32_t bufPageSize; uint32_t sortBufSize; // max buffer size for in-memory sort - + SLimitInfo limitInfo; SArray* pSortInfo; SSortHandle* pSortHandle; SColMatchInfo matchInfo; @@ -578,19 +578,7 @@ int32_t doOpenMultiwayMergeOperator(SOperatorInfo* pOperator) { return TSDB_CODE_SUCCESS; } -SSDataBlock* getMultiwaySortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity, - SArray* pColMatchInfo, SOperatorInfo* pOperator) { - SMultiwayMergeOperatorInfo* pInfo = pOperator->info; - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - - blockDataCleanup(pDataBlock); - - SSDataBlock* p = tsortGetSortedDataBlock(pHandle); - if (p == NULL) { - return NULL; - } - - blockDataEnsureCapacity(p, capacity); +static void doGetSortedBlockData(SMultiwayMergeOperatorInfo* pInfo, SSortHandle* pHandle, int32_t capacity, SSDataBlock* p) { while (1) { STupleHandle* pTupleHandle = NULL; @@ -626,33 +614,66 @@ SSDataBlock* getMultiwaySortedBlockData(SSortHandle* pHandle, SSDataBlock* pData } else { appendOneRowToDataBlock(p, pTupleHandle); } + if (p->info.rows >= capacity) { break; } } + if (pInfo->groupSort) { pInfo->hasGroupId = false; } - if (p->info.rows > 0) { // todo extract method - blockDataEnsureCapacity(pDataBlock, p->info.rows); + +} + +SSDataBlock* getMultiwaySortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, SArray* pColMatchInfo, + SOperatorInfo* pOperator) { + SMultiwayMergeOperatorInfo* pInfo = pOperator->info; + + int32_t capacity = pOperator->resultInfo.capacity; + + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + blockDataCleanup(pDataBlock); + + SSDataBlock* p = tsortGetSortedDataBlock(pHandle); + if (p == NULL) { + return NULL; + } + + blockDataEnsureCapacity(p, capacity); + while (1) { + doGetSortedBlockData(pInfo, pHandle, capacity, p); + if (p->info.rows == 0) { + break; + } + + if (p->info.rows > 0) { + applyLimitOffset(&pInfo->limitInfo, p, pTaskInfo, pOperator); + if (p->info.rows > 0) { + break; + } + } + } + + if (p->info.rows > 0) { int32_t numOfCols = taosArrayGetSize(pColMatchInfo); for (int32_t i = 0; i < numOfCols; ++i) { SColMatchItem* pmInfo = taosArrayGet(pColMatchInfo, i); -// ASSERT(pColMatchInfo-> == COL_MATCH_FROM_SLOT_ID); SColumnInfoData* pSrc = taosArrayGet(p->pDataBlock, pmInfo->srcSlotId); SColumnInfoData* pDst = taosArrayGet(pDataBlock->pDataBlock, pmInfo->dstSlotId); colDataAssign(pDst, pSrc, p->info.rows, &pDataBlock->info); } + pInfo->limitInfo.numOfOutputRows += p->info.rows; pDataBlock->info.rows = p->info.rows; pDataBlock->info.groupId = pInfo->groupId; } blockDataDestroy(p); - qDebug("%s get sorted block, groupId:0x%" PRIx64 " rows:%d", GET_TASKID(pTaskInfo), pDataBlock->info.groupId, pDataBlock->info.rows); + return (pDataBlock->info.rows > 0) ? pDataBlock : NULL; } @@ -669,13 +690,13 @@ SSDataBlock* doMultiwayMerge(SOperatorInfo* pOperator) { T_LONG_JMP(pTaskInfo->env, code); } - SSDataBlock* pBlock = getMultiwaySortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, - pOperator->resultInfo.capacity, pInfo->matchInfo.pList, pOperator); + SSDataBlock* pBlock = getMultiwaySortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pInfo->matchInfo.pList, pOperator); if (pBlock != NULL) { pOperator->resultInfo.totalRows += pBlock->info.rows; } else { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); } + return pBlock; } @@ -717,32 +738,33 @@ SOperatorInfo* createMultiwayMergeOperatorInfo(SOperatorInfo** downStreams, size goto _error; } + initLimitInfo(pMergePhyNode->node.pLimit, pMergePhyNode->node.pSlimit, &pInfo->limitInfo); pInfo->binfo.pRes = createResDataBlock(pDescNode); + int32_t rowSize = pInfo->binfo.pRes->info.rowSize; ASSERT(rowSize < 100 * 1024 * 1024); - SArray* pSortInfo = createSortInfo(pMergePhyNode->pMergeKeys); int32_t numOfOutputCols = 0; + code = extractColMatchInfo(pMergePhyNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID, + &pInfo->matchInfo); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } - code = extractColMatchInfo(pMergePhyNode->pTargets, pDescNode, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID, &pInfo->matchInfo); SPhysiNode* pChildNode = (SPhysiNode*)nodesListGetNode(pPhyNode->pChildren, 0); SSDataBlock* pInputBlock = createResDataBlock(pChildNode->pOutputDataBlockDesc); + initResultSizeInfo(&pOperator->resultInfo, 1024); + blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity); pInfo->groupSort = pMergePhyNode->groupSort; - pInfo->pSortInfo = pSortInfo; + pInfo->pSortInfo = createSortInfo(pMergePhyNode->pMergeKeys); pInfo->pInputBlock = pInputBlock; pInfo->bufPageSize = getProperSortPageSize(rowSize); pInfo->sortBufSize = pInfo->bufPageSize * (numStreams + 1); // one additional is reserved for merged result. - pOperator->name = "MultiwayMerge"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_MERGE; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; - - pOperator->fpSet = createOperatorFpSet(doOpenMultiwayMergeOperator, doMultiwayMerge, NULL, NULL, + setOperatorInfo(pOperator, "MultiwayMergeOperator", QUERY_NODE_PHYSICAL_PLAN_MERGE, false, OP_NOT_OPENED, pInfo, pTaskInfo); + pOperator->fpSet = createOperatorFpSet(doOpenMultiwayMergeOperator, doMultiwayMerge, NULL, destroyMultiwayMergeOperatorInfo, getMultiwayMergeExplainExecInfo); code = appendDownstream(pOperator, downStreams, numStreams); @@ -752,11 +774,11 @@ SOperatorInfo* createMultiwayMergeOperatorInfo(SOperatorInfo** downStreams, size return pOperator; _error: - pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY; if (pInfo != NULL) { destroyMultiwayMergeOperatorInfo(pInfo); } + pTaskInfo->code = code; taosMemoryFree(pOperator); return NULL; } diff --git a/source/libs/executor/src/tfill.c b/source/libs/executor/src/tfill.c index 23847928da7eab945418ee636eeb56e25e06483b..7c9d73ad137d168f749c2aba4d02067952da0e8c 100644 --- a/source/libs/executor/src/tfill.c +++ b/source/libs/executor/src/tfill.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#include "filter.h" #include "os.h" #include "query.h" #include "taosdef.h" @@ -1442,7 +1443,7 @@ static SSDataBlock* doStreamFill(SOperatorInfo* pOperator) { printDataBlock(pInfo->pRes, "stream fill"); return pInfo->pRes; } - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); resetStreamFillInfo(pInfo); return NULL; } @@ -1499,7 +1500,7 @@ static SSDataBlock* doStreamFill(SOperatorInfo* pOperator) { } doStreamFillImpl(pOperator); - doFilter(pInfo->pCondition, pInfo->pRes, &pInfo->matchInfo, NULL); + doFilter(pInfo->pRes, pOperator->exprSupp.pFilterInfo, &pInfo->matchInfo); memcpy(pInfo->pRes->info.parTbName, pInfo->pSrcBlock->info.parTbName, TSDB_TABLE_NAME_LEN); pOperator->resultInfo.totalRows += pInfo->pRes->info.rows; if (pInfo->pRes->info.rows > 0) { @@ -1511,7 +1512,7 @@ static SSDataBlock* doStreamFill(SOperatorInfo* pOperator) { } if (pInfo->pRes->info.rows == 0) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); resetStreamFillInfo(pInfo); return NULL; } @@ -1677,22 +1678,21 @@ SOperatorInfo* createStreamFillOperatorInfo(SOperatorInfo* downstream, SStreamFi int32_t numOfOutputCols = 0; int32_t code = extractColMatchInfo(pPhyFillNode->pFillExprs, pPhyFillNode->node.pOutputDataBlockDesc, &numOfOutputCols, COL_MATCH_FROM_SLOT_ID, &pInfo->matchInfo); - pInfo->pCondition = pPhyFillNode->node.pConditions; + + code = filterInitFromNode((SNode*)pPhyFillNode->node.pConditions, &pOperator->exprSupp.pFilterInfo, 0); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + code = initExprSupp(&pOperator->exprSupp, pFillExprInfo, numOfFillCols); if (code != TSDB_CODE_SUCCESS) { goto _error; } pInfo->srcRowIndex = 0; - - pOperator->name = "FillOperator"; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_FILL; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamFill, NULL, NULL, destroyStreamFillOperatorInfo, - NULL); + setOperatorInfo(pOperator, "StreamFillOperator", QUERY_NODE_PHYSICAL_PLAN_STREAM_FILL, false, OP_NOT_OPENED, pInfo, pTaskInfo); + pOperator->fpSet = + createOperatorFpSet(operatorDummyOpenFn, doStreamFill, NULL, destroyStreamFillOperatorInfo, NULL); code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index 8e1b15f3154d59b509b7b486dc39b924294659c7..f0310a45d8fc899bc447060170db56e1f873e63b 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ #include "executorimpl.h" +#include "filter.h" #include "function.h" #include "functionMgt.h" #include "tcommon.h" @@ -985,7 +986,8 @@ void doCloseWindow(SResultRowInfo* pResultRowInfo, const SIntervalAggOperatorInf // current result is done in computing final results. if (pInfo->timeWindowInterpo && isResultRowInterpolated(pResult, RESULT_ROW_END_INTERP)) { closeResultRow(pResult); - tdListPopHead(pResultRowInfo->openWindow); + SListNode* pNode = tdListPopHead(pResultRowInfo->openWindow); + taosMemoryFree(pNode); } } @@ -1219,18 +1221,18 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator) { pTaskInfo->code = pOperator->fpSet._openFn(pOperator); if (pTaskInfo->code != TSDB_CODE_SUCCESS) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return NULL; } blockDataEnsureCapacity(pBInfo->pRes, pOperator->resultInfo.capacity); while (1) { doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); - doFilter(pInfo->pCondition, pBInfo->pRes, NULL, NULL); + doFilter(pBInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL); bool hasRemain = hasRemainResults(&pInfo->groupResInfo); if (!hasRemain) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); break; } @@ -1253,35 +1255,33 @@ static SSDataBlock* doBuildIntervalResult(SOperatorInfo* pOperator) { SSDataBlock* pBlock = pInfo->binfo.pRes; - if (pInfo->execModel == OPTR_EXEC_MODEL_STREAM) { - return pOperator->fpSet.getStreamResFn(pOperator); - } else { - pTaskInfo->code = pOperator->fpSet._openFn(pOperator); - if (pTaskInfo->code != TSDB_CODE_SUCCESS) { - return NULL; - } + ASSERT(pInfo->execModel == OPTR_EXEC_MODEL_BATCH); - blockDataEnsureCapacity(pBlock, pOperator->resultInfo.capacity); - while (1) { - doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); - doFilter(pInfo->pCondition, pBlock, NULL, NULL); + pTaskInfo->code = pOperator->fpSet._openFn(pOperator); + if (pTaskInfo->code != TSDB_CODE_SUCCESS) { + return NULL; + } - bool hasRemain = hasRemainResults(&pInfo->groupResInfo); - if (!hasRemain) { - doSetOperatorCompleted(pOperator); - break; - } + blockDataEnsureCapacity(pBlock, pOperator->resultInfo.capacity); + while (1) { + doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); + doFilter(pBlock, pOperator->exprSupp.pFilterInfo, NULL); - if (pBlock->info.rows > 0) { - break; - } + bool hasRemain = hasRemainResults(&pInfo->groupResInfo); + if (!hasRemain) { + setOperatorCompleted(pOperator); + break; } - size_t rows = pBlock->info.rows; - pOperator->resultInfo.totalRows += rows; - - return (rows == 0) ? NULL : pBlock; + if (pBlock->info.rows > 0) { + break; + } } + + size_t rows = pBlock->info.rows; + pOperator->resultInfo.totalRows += rows; + + return (rows == 0) ? NULL : pBlock; } static void setInverFunction(SqlFunctionCtx* pCtx, int32_t num, EStreamType type) { @@ -1687,7 +1687,9 @@ void initIntervalDownStream(SOperatorInfo* downstream, uint16_t type, SAggSuppor SStreamScanInfo* pScanInfo = downstream->info; pScanInfo->windowSup.parentType = type; pScanInfo->windowSup.pIntervalAggSup = pSup; - pScanInfo->pUpdateInfo = updateInfoInitP(pInterval, pTwSup->waterMark); + if (!pScanInfo->pUpdateInfo) { + pScanInfo->pUpdateInfo = updateInfoInitP(pInterval, pTwSup->waterMark); + } pScanInfo->interval = *pInterval; pScanInfo->twAggSup = *pTwSup; } @@ -1737,14 +1739,12 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SIntervalPh ASSERT(as.calTrigger != STREAM_TRIGGER_MAX_DELAY); - pOperator->pTaskInfo = pTaskInfo; pInfo->win = pTaskInfo->window; pInfo->inputOrder = (pPhyNode->window.inputTsOrder == ORDER_ASC) ? TSDB_ORDER_ASC : TSDB_ORDER_DESC; pInfo->resultTsOrder = (pPhyNode->window.outputTsOrder == ORDER_ASC) ? TSDB_ORDER_ASC : TSDB_ORDER_DESC; pInfo->interval = interval; pInfo->execModel = pTaskInfo->execModel; pInfo->twAggSup = as; - pInfo->pCondition = pPhyNode->window.node.pConditions; pInfo->binfo.mergeResultBlock = pPhyNode->window.mergeDataBlock; if (pPhyNode->window.pExprs != NULL) { @@ -1756,6 +1756,11 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SIntervalPh } } + code = filterInitFromNode((SNode*)pPhyNode->window.node.pConditions, &pOperator->exprSupp.pFilterInfo, 0); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + if (isStream) { ASSERT(num > 0); initStreamFunciton(pSup->pCtx, pSup->numOfExprs); @@ -1771,15 +1776,10 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SIntervalPh } initResultRowInfo(&pInfo->binfo.resultRowInfo); - - pOperator->name = "TimeIntervalAggOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL; - pOperator->blocking = true; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; + setOperatorInfo(pOperator, "TimeIntervalAggOperator", QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL, true, OP_NOT_OPENED, pInfo, pTaskInfo); pOperator->fpSet = - createOperatorFpSet(doOpenIntervalAgg, doBuildIntervalResult, NULL, NULL, destroyIntervalOperatorInfo, NULL); + createOperatorFpSet(doOpenIntervalAgg, doBuildIntervalResult, NULL, destroyIntervalOperatorInfo, NULL); code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -1880,11 +1880,11 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator) { if (pOperator->status == OP_RES_TO_RETURN) { while (1) { doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); - doFilter(pInfo->pCondition, pBInfo->pRes, NULL, NULL); + doFilter(pBInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL); bool hasRemain = hasRemainResults(&pInfo->groupResInfo); if (!hasRemain) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); break; } @@ -1923,11 +1923,11 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator) { blockDataEnsureCapacity(pBInfo->pRes, pOperator->resultInfo.capacity); while (1) { doBuildResultDatablock(pOperator, &pInfo->binfo, &pInfo->groupResInfo, pInfo->aggSup.pResultBuf); - doFilter(pInfo->pCondition, pBInfo->pRes, NULL, NULL); + doFilter(pBInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL); bool hasRemain = hasRemainResults(&pInfo->groupResInfo); if (!hasRemain) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); break; } @@ -2275,7 +2275,7 @@ static SSDataBlock* doTimeslice(SOperatorInfo* pOperator) { } if (pSliceInfo->current > pSliceInfo->win.ekey) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); break; } @@ -2324,7 +2324,7 @@ static SSDataBlock* doTimeslice(SOperatorInfo* pOperator) { } if (pSliceInfo->current > pSliceInfo->win.ekey) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); break; } } @@ -2336,7 +2336,7 @@ static SSDataBlock* doTimeslice(SOperatorInfo* pOperator) { pSliceInfo->current = taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision); if (pSliceInfo->current > pSliceInfo->win.ekey) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); break; } } @@ -2359,7 +2359,7 @@ static SSDataBlock* doTimeslice(SOperatorInfo* pOperator) { } if (pSliceInfo->current > pSliceInfo->win.ekey) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); break; } } @@ -2380,7 +2380,7 @@ static SSDataBlock* doTimeslice(SOperatorInfo* pOperator) { } if (pSliceInfo->current > pSliceInfo->win.ekey) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); break; } } else { @@ -2442,7 +2442,7 @@ static SSDataBlock* doTimeslice(SOperatorInfo* pOperator) { } if (pSliceInfo->current > pSliceInfo->win.ekey) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); break; } } @@ -2453,12 +2453,11 @@ static SSDataBlock* doTimeslice(SOperatorInfo* pOperator) { } else { // non-linear interpolation pSliceInfo->current = taosTimeAdd(pSliceInfo->current, pInterval->interval, pInterval->intervalUnit, pInterval->precision); - } } if (pSliceInfo->current > pSliceInfo->win.ekey) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); break; } } @@ -2552,15 +2551,9 @@ SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SPhysiNode pScanInfo->cond.twindows = pInfo->win; pScanInfo->cond.type = TIMEWINDOW_RANGE_EXTERNAL; - pOperator->name = "TimeSliceOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->pTaskInfo = pTaskInfo; - + setOperatorInfo(pOperator, "TimeSliceOperator", QUERY_NODE_PHYSICAL_PLAN_INTERP_FUNC, false, OP_NOT_OPENED, pInfo, pTaskInfo); pOperator->fpSet = - createOperatorFpSet(operatorDummyOpenFn, doTimeslice, NULL, NULL, destroyTimeSliceOperatorInfo, NULL); + createOperatorFpSet(operatorDummyOpenFn, doTimeslice, NULL, destroyTimeSliceOperatorInfo, NULL); blockDataEnsureCapacity(pInfo->pRes, pOperator->resultInfo.capacity); @@ -2598,17 +2591,22 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SStateWi pInfo->stateKey.type = pInfo->stateCol.type; pInfo->stateKey.bytes = pInfo->stateCol.bytes; pInfo->stateKey.pData = taosMemoryCalloc(1, pInfo->stateCol.bytes); - pInfo->pCondition = pStateNode->window.node.pConditions; if (pInfo->stateKey.pData == NULL) { goto _error; } + int32_t code = filterInitFromNode((SNode*)pStateNode->window.node.pConditions, &pOperator->exprSupp.pFilterInfo, 0); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + size_t keyBufSize = sizeof(int64_t) + sizeof(int64_t) + POINTER_BYTES; int32_t num = 0; SExprInfo* pExprInfo = createExprInfo(pStateNode->window.pFuncs, NULL, &num); initResultSizeInfo(&pOperator->resultInfo, 4096); - int32_t code = initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str); + + code = initAggInfo(&pOperator->exprSupp, &pInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -2623,15 +2621,10 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SStateWi initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pTaskInfo->window); pInfo->tsSlotId = tsSlotId; - pOperator->name = "StateWindowOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE; - pOperator->blocking = true; - pOperator->status = OP_NOT_OPENED; - pOperator->pTaskInfo = pTaskInfo; - pOperator->info = pInfo; + setOperatorInfo(pOperator, "StateWindowOperator", QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE, true, OP_NOT_OPENED, pInfo, pTaskInfo); pOperator->fpSet = - createOperatorFpSet(openStateWindowAggOptr, doStateWindowAgg, NULL, NULL, destroyStateWindowOperatorInfo, NULL); + createOperatorFpSet(openStateWindowAggOptr, doStateWindowAgg, NULL, destroyStateWindowOperatorInfo, NULL); code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -2696,16 +2689,14 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SSessionW pInfo->binfo.pRes = pResBlock; pInfo->winSup.prevTs = INT64_MIN; pInfo->reptScan = false; - pInfo->pCondition = pSessionNode->window.node.pConditions; - - pOperator->name = "SessionWindowAggOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION; - pOperator->blocking = true; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; + code = filterInitFromNode((SNode*)pSessionNode->window.node.pConditions, &pOperator->exprSupp.pFilterInfo, 0); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + setOperatorInfo(pOperator, "SessionWindowAggOperator", QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION, true, OP_NOT_OPENED, pInfo, pTaskInfo); pOperator->fpSet = - createOperatorFpSet(operatorDummyOpenFn, doSessionWindowAgg, NULL, NULL, destroySWindowOperatorInfo, NULL); + createOperatorFpSet(operatorDummyOpenFn, doSessionWindowAgg, NULL, destroySWindowOperatorInfo, NULL); pOperator->pTaskInfo = pTaskInfo; code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -3121,7 +3112,7 @@ static SSDataBlock* doStreamFinalIntervalAgg(SOperatorInfo* pOperator) { return pInfo->binfo.pRes; } - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); if (!IS_FINAL_OP(pInfo)) { clearFunctionContext(&pOperator->exprSupp); // semi interval operator clear disk buffer @@ -3302,6 +3293,8 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream, // for test 315360000000 .deleteMark = 1000LL * 60LL * 60LL * 24LL * 365LL * 10LL, // .deleteMark = INT64_MAX, + .deleteMarkSaved = 0, + .calTriggerSaved = 0, }; ASSERT(pInfo->twAggSup.calTrigger != STREAM_TRIGGER_MAX_DELAY); pInfo->primaryTsIndex = ((SColumnNode*)pIntervalPhyNode->window.pTspk)->slotId; @@ -3388,7 +3381,7 @@ SOperatorInfo* createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream, pOperator->info = pInfo; pOperator->fpSet = - createOperatorFpSet(NULL, doStreamFinalIntervalAgg, NULL, NULL, destroyStreamFinalIntervalOperatorInfo, NULL); + createOperatorFpSet(NULL, doStreamFinalIntervalAgg, NULL, destroyStreamFinalIntervalOperatorInfo, NULL); if (pPhyNode->type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL) { initIntervalDownStream(downstream, pPhyNode->type, &pInfo->aggSup, &pInfo->interval, &pInfo->twAggSup); } @@ -3535,7 +3528,7 @@ void getCurSessionWindow(SStreamAggSupporter* pAggSup, TSKEY startTs, TSKEY endT pKey->win.skey = startTs; pKey->win.ekey = endTs; pKey->groupId = groupId; - int32_t code = streamStateSessionGetKey(pAggSup->pState, pKey, pKey); + int32_t code = streamStateSessionGetKeyByRange(pAggSup->pState, pKey, pKey); if (code != TSDB_CODE_SUCCESS) { SET_SESSION_WIN_KEY_INVALID(pKey); } @@ -3546,10 +3539,11 @@ bool isInvalidSessionWin(SResultWindowInfo* pWinInfo) { return pWinInfo->session void setSessionOutputBuf(SStreamAggSupporter* pAggSup, TSKEY startTs, TSKEY endTs, uint64_t groupId, SResultWindowInfo* pCurWin) { pCurWin->sessionWin.groupId = groupId; - pCurWin->sessionWin.win.skey = startTs - pAggSup->gap; - pCurWin->sessionWin.win.ekey = endTs + pAggSup->gap; + pCurWin->sessionWin.win.skey = startTs; + pCurWin->sessionWin.win.ekey = endTs; int32_t size = pAggSup->resultRowSize; - int32_t code = streamStateSessionAddIfNotExist(pAggSup->pState, &pCurWin->sessionWin, &pCurWin->pOutputBuf, &size); + int32_t code = + streamStateSessionAddIfNotExist(pAggSup->pState, &pCurWin->sessionWin, pAggSup->gap, &pCurWin->pOutputBuf, &size); if (code == TSDB_CODE_SUCCESS) { pCurWin->isOutput = true; } else { @@ -3560,7 +3554,7 @@ void setSessionOutputBuf(SStreamAggSupporter* pAggSup, TSKEY startTs, TSKEY endT int32_t getSessionWinBuf(SStreamAggSupporter* pAggSup, SStreamStateCur* pCur, SResultWindowInfo* pWinInfo) { int32_t size = 0; - int32_t code = streamStateSessionGetKVByCur(pCur, &pWinInfo->sessionWin, (const void**)&pWinInfo->pOutputBuf, &size); + int32_t code = streamStateSessionGetKVByCur(pCur, &pWinInfo->sessionWin, &pWinInfo->pOutputBuf, &size); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -3665,7 +3659,7 @@ SStreamStateCur* getNextSessionWinInfo(SStreamAggSupporter* pAggSup, SSHashObj* setSessionWinOutputInfo(pStUpdated, pNextWin); int32_t size = 0; pNextWin->sessionWin = pCurWin->sessionWin; - int32_t code = streamStateSessionGetKVByCur(pCur, &pNextWin->sessionWin, (const void**)&pNextWin->pOutputBuf, &size); + int32_t code = streamStateSessionGetKVByCur(pCur, &pNextWin->sessionWin, &pNextWin->pOutputBuf, &size); if (code != TSDB_CODE_SUCCESS) { SET_SESSION_WIN_INVALID(*pNextWin); } @@ -3879,9 +3873,11 @@ static void rebuildSessionWindow(SOperatorInfo* pOperator, SArray* pWinArray, SS SOperatorInfo* pChild = taosArrayGetP(pInfo->pChildren, j); SStreamSessionAggOperatorInfo* pChInfo = pChild->info; SStreamAggSupporter* pChAggSup = &pChInfo->streamAggSup; - SStreamStateCur* pCur = streamStateSessionGetCur(pChAggSup->pState, pWinKey); - SResultRow* pResult = NULL; - SResultRow* pChResult = NULL; + SSessionKey chWinKey = *pWinKey; + chWinKey.win.ekey = chWinKey.win.skey; + SStreamStateCur* pCur = streamStateSessionSeekKeyCurrentNext(pChAggSup->pState, &chWinKey); + SResultRow* pResult = NULL; + SResultRow* pChResult = NULL; while (1) { SResultWindowInfo childWin = {0}; childWin.sessionWin = *pWinKey; @@ -4009,7 +4005,7 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) { return pBInfo->pRes; } - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return NULL; } @@ -4097,6 +4093,12 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) { initGroupResInfoFromArrayList(&pInfo->groupResInfo, pUpdated); blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity); +#if 0 + char* pBuf = streamStateSessionDump(pAggSup->pState); + qDebug("===stream===final session%s", pBuf); + taosMemoryFree(pBuf); +#endif + doBuildDeleteDataBlock(pInfo->pStDeleted, pInfo->pDelRes, &pInfo->pDelIterator); if (pInfo->pDelRes->info.rows > 0) { printDataBlock(pInfo->pDelRes, IS_FINAL_OP(pInfo) ? "final session" : "single session"); @@ -4109,7 +4111,7 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) { return pBInfo->pRes; } - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return NULL; } @@ -4176,13 +4178,11 @@ SOperatorInfo* createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPh pInfo->pGroupIdTbNameMap = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_NO_LOCK); - pOperator->name = "StreamSessionWindowAggOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION; - pOperator->blocking = true; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamSessionAgg, NULL, NULL, - destroyStreamSessionAggOperatorInfo, NULL); + setOperatorInfo(pOperator, "StreamSessionWindowAggOperator", QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION, true, + OP_NOT_OPENED, pInfo, pTaskInfo); + pOperator->fpSet = + createOperatorFpSet(operatorDummyOpenFn, doStreamSessionAgg, NULL, destroyStreamSessionAggOperatorInfo, NULL); + if (downstream) { initDownStream(downstream, &pInfo->streamAggSup, pInfo->twAggSup.waterMark, pOperator->operatorType, pInfo->primaryTsIndex); @@ -4233,7 +4233,7 @@ static SSDataBlock* doStreamSessionSemiAgg(SOperatorInfo* pOperator) { clearFunctionContext(&pOperator->exprSupp); // semi interval operator clear disk buffer clearStreamSessionOperator(pInfo); - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return NULL; } } @@ -4291,6 +4291,12 @@ static SSDataBlock* doStreamSessionSemiAgg(SOperatorInfo* pOperator) { initGroupResInfoFromArrayList(&pInfo->groupResInfo, pUpdated); blockDataEnsureCapacity(pBInfo->pRes, pOperator->resultInfo.capacity); +#if 0 + char* pBuf = streamStateSessionDump(pAggSup->pState); + qDebug("===stream===semi session%s", pBuf); + taosMemoryFree(pBuf); +#endif + doBuildSessionResult(pOperator, pAggSup->pState, &pInfo->groupResInfo, pBInfo->pRes); if (pBInfo->pRes->info.rows > 0) { printDataBlock(pBInfo->pRes, "semi session"); @@ -4306,7 +4312,7 @@ static SSDataBlock* doStreamSessionSemiAgg(SOperatorInfo* pOperator) { clearFunctionContext(&pOperator->exprSupp); // semi interval operator clear disk buffer clearStreamSessionOperator(pInfo); - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return NULL; } @@ -4317,20 +4323,21 @@ SOperatorInfo* createStreamFinalSessionAggOperatorInfo(SOperatorInfo* downstream if (pOperator == NULL) { goto _error; } + SStreamSessionAggOperatorInfo* pInfo = pOperator->info; - if (pPhyNode->type == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION) { - pInfo->isFinal = true; - pOperator->name = "StreamSessionFinalAggOperator"; - } else { - pInfo->isFinal = false; + pInfo->isFinal = (pPhyNode->type == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION); + char* name = (pInfo->isFinal)? "StreamSessionFinalAggOperator":"StreamSessionSemiAggOperator"; + + if (pPhyNode->type != QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION) { pInfo->pUpdateRes = createSpecialDataBlock(STREAM_CLEAR); blockDataEnsureCapacity(pInfo->pUpdateRes, 128); - pOperator->name = "StreamSessionSemiAggOperator"; - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamSessionSemiAgg, NULL, NULL, + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamSessionSemiAgg, NULL, destroyStreamSessionAggOperatorInfo, NULL); } + setOperatorInfo(pOperator, name, pPhyNode->type , false, OP_NOT_OPENED, pInfo, pTaskInfo); + pInfo->pGroupIdTbNameMap = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_NO_LOCK); @@ -4560,7 +4567,7 @@ static SSDataBlock* doStreamStateAgg(SOperatorInfo* pOperator) { return pBInfo->pRes; } - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return NULL; } @@ -4626,7 +4633,7 @@ static SSDataBlock* doStreamStateAgg(SOperatorInfo* pOperator) { printDataBlock(pBInfo->pRes, "single state"); return pBInfo->pRes; } - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); return NULL; } @@ -4691,14 +4698,9 @@ SOperatorInfo* createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhys pInfo->pGroupIdTbNameMap = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_NO_LOCK); - pOperator->name = "StreamStateAggOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE; - pOperator->blocking = true; - pOperator->status = OP_NOT_OPENED; - pOperator->pTaskInfo = pTaskInfo; - pOperator->info = pInfo; + setOperatorInfo(pOperator, "StreamStateAggOperator", QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE, true, OP_NOT_OPENED, pInfo, pTaskInfo); pOperator->fpSet = - createOperatorFpSet(operatorDummyOpenFn, doStreamStateAgg, NULL, NULL, destroyStreamStateOperatorInfo, NULL); + createOperatorFpSet(operatorDummyOpenFn, doStreamStateAgg, NULL, destroyStreamStateOperatorInfo, NULL); initDownStream(downstream, &pInfo->streamAggSup, pInfo->twAggSup.waterMark, pOperator->operatorType, pInfo->primaryTsIndex); code = appendDownstream(pOperator, &downstream, 1); @@ -4846,7 +4848,7 @@ static void doMergeAlignedIntervalAgg(SOperatorInfo* pOperator) { cleanupAfterGroupResultGen(pMiaInfo, pRes); } - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); break; } @@ -4873,7 +4875,7 @@ static void doMergeAlignedIntervalAgg(SOperatorInfo* pOperator) { setInputDataBlock(pSup, pBlock, pIaInfo->inputOrder, scanFlag, true); doMergeAlignedIntervalAggImpl(pOperator, &pIaInfo->binfo.resultRowInfo, pBlock, pRes); - doFilter(pMiaInfo->pCondition, pRes, NULL, NULL); + doFilter(pRes, pOperator->exprSupp.pFilterInfo, NULL); if (pRes->info.rows >= pOperator->resultInfo.capacity) { break; } @@ -4936,7 +4938,11 @@ SOperatorInfo* createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream, SIntervalAggOperatorInfo* iaInfo = miaInfo->intervalAggOperatorInfo; SExprSupp* pSup = &pOperator->exprSupp; - miaInfo->pCondition = pNode->window.node.pConditions; + int32_t code = filterInitFromNode((SNode*)pNode->window.node.pConditions, &pOperator->exprSupp.pFilterInfo, 0); + if (code != TSDB_CODE_SUCCESS) { + goto _error; + } + miaInfo->curTs = INT64_MIN; iaInfo->win = pTaskInfo->window; iaInfo->inputOrder = TSDB_ORDER_ASC; @@ -4950,7 +4956,8 @@ SOperatorInfo* createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream, int32_t num = 0; SExprInfo* pExprInfo = createExprInfo(pNode->window.pFuncs, NULL, &num); - int32_t code = initAggInfo(&pOperator->exprSupp, &iaInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str); + + code = initAggInfo(&pOperator->exprSupp, &iaInfo->aggSup, pExprInfo, num, keyBufSize, pTaskInfo->id.str); if (code != TSDB_CODE_SUCCESS) { goto _error; } @@ -4966,16 +4973,10 @@ SOperatorInfo* createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream, initResultRowInfo(&iaInfo->binfo.resultRowInfo); blockDataEnsureCapacity(iaInfo->binfo.pRes, pOperator->resultInfo.capacity); - - pOperator->name = "TimeMergeAlignedIntervalAggOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->pTaskInfo = pTaskInfo; - pOperator->info = miaInfo; + setOperatorInfo(pOperator, "TimeMergeAlignedIntervalAggOperator", QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL, false, OP_NOT_OPENED, miaInfo, pTaskInfo); pOperator->fpSet = - createOperatorFpSet(operatorDummyOpenFn, mergeAlignedIntervalAgg, NULL, NULL, destroyMAIOperatorInfo, NULL); + createOperatorFpSet(operatorDummyOpenFn, mergeAlignedIntervalAgg, NULL, destroyMAIOperatorInfo, NULL); code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -5219,7 +5220,7 @@ static SSDataBlock* doMergeIntervalAgg(SOperatorInfo* pOperator) { } if (pRes->info.rows == 0) { - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); } size_t rows = pRes->info.rows; @@ -5278,16 +5279,9 @@ SOperatorInfo* createMergeIntervalOperatorInfo(SOperatorInfo* downstream, SMerge } initResultRowInfo(&pIntervalInfo->binfo.resultRowInfo); - - pOperator->name = "TimeMergeIntervalAggOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL; - pOperator->blocking = false; - pOperator->status = OP_NOT_OPENED; - pOperator->pTaskInfo = pTaskInfo; - pOperator->info = pMergeIntervalInfo; - + setOperatorInfo(pOperator, "TimeMergeIntervalAggOperator", QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL, false, OP_NOT_OPENED, pMergeIntervalInfo, pTaskInfo); pOperator->fpSet = - createOperatorFpSet(operatorDummyOpenFn, doMergeIntervalAgg, NULL, NULL, destroyMergeIntervalOperatorInfo, NULL); + createOperatorFpSet(operatorDummyOpenFn, doMergeIntervalAgg, NULL, destroyMergeIntervalOperatorInfo, NULL); code = appendDownstream(pOperator, &downstream, 1); if (code != TSDB_CODE_SUCCESS) { @@ -5331,7 +5325,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) { } deleteIntervalDiscBuf(pInfo->pState, NULL, pInfo->twAggSup.maxTs - pInfo->twAggSup.deleteMark, &pInfo->interval, &pInfo->delKey); - doSetOperatorCompleted(pOperator); + setOperatorCompleted(pOperator); streamStateCommit(pTaskInfo->streamInfo.pState); return NULL; } @@ -5384,6 +5378,7 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) { maxTs = TMAX(maxTs, pBlock->info.window.ekey); minTs = TMIN(minTs, pBlock->info.window.skey); + doStreamIntervalAggImpl(pOperator, pBlock, pBlock->info.groupId, pUpdatedMap); } pInfo->twAggSup.maxTs = TMAX(pInfo->twAggSup.maxTs, maxTs); @@ -5514,12 +5509,8 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhys pInfo->pGroupIdTbNameMap = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), false, HASH_NO_LOCK); - pOperator->name = "StreamIntervalOperator"; - pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL; - pOperator->blocking = true; - pOperator->status = OP_NOT_OPENED; - pOperator->info = pInfo; - pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamIntervalAgg, NULL, NULL, + setOperatorInfo(pOperator, "StreamIntervalOperator", QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL, true, OP_NOT_OPENED, pInfo, pTaskInfo); + pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doStreamIntervalAgg, NULL, destroyStreamFinalIntervalOperatorInfo, NULL); initIntervalDownStream(downstream, pPhyNode->type, &pInfo->aggSup, &pInfo->interval, &pInfo->twAggSup); diff --git a/source/libs/function/CMakeLists.txt b/source/libs/function/CMakeLists.txt index 913dd24a491748829e19cd7ff486b3eadfa78520..fa241dc6efe919b5b351186013e4dae81c622587 100644 --- a/source/libs/function/CMakeLists.txt +++ b/source/libs/function/CMakeLists.txt @@ -12,6 +12,17 @@ target_include_directories( PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) +IF (TD_LINUX_64 AND JEMALLOC_ENABLED) + ADD_DEFINITIONS(-DTD_JEMALLOC_ENABLED -I${CMAKE_BINARY_DIR}/build/include -L${CMAKE_BINARY_DIR}/build/lib -Wl,-rpath,${CMAKE_BINARY_DIR}/build/lib -ljemalloc) + SET(LINK_JEMALLOC "-L${CMAKE_BINARY_DIR}/build/lib -ljemalloc") +ELSE () + SET(LINK_JEMALLOC "") +ENDIF () + +IF (TD_LINUX_64 AND JEMALLOC_ENABLED) + ADD_DEPENDENCIES(function jemalloc) +ENDIF () + target_link_libraries( function PRIVATE os @@ -21,7 +32,7 @@ target_link_libraries( PRIVATE qcom PRIVATE scalar PRIVATE transport - PRIVATE stream + PRIVATE stream ${LINK_JEMALLOC} PUBLIC uv_a ) @@ -37,10 +48,15 @@ target_include_directories( "${TD_SOURCE_DIR}/include/os" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) + +IF (TD_LINUX_64 AND JEMALLOC_ENABLED) + ADD_DEPENDENCIES(runUdf jemalloc) +ENDIF () + target_link_libraries( runUdf PUBLIC uv_a - PRIVATE os util common nodes function + PRIVATE os util common nodes function ${LINK_JEMALLOC} ) add_library(udf1 STATIC MODULE test/udf1.c) @@ -54,8 +70,13 @@ target_include_directories( "${TD_SOURCE_DIR}/include/os" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) + +IF (TD_LINUX_64 AND JEMALLOC_ENABLED) + ADD_DEPENDENCIES(udf1 jemalloc) +ENDIF () + target_link_libraries( - udf1 PUBLIC os) + udf1 PUBLIC os ${LINK_JEMALLOC}) add_library(udf2 STATIC MODULE test/udf2.c) target_include_directories( @@ -68,8 +89,13 @@ target_include_directories( "${TD_SOURCE_DIR}/include/os" PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) + +IF (TD_LINUX_64 AND JEMALLOC_ENABLED) + ADD_DEPENDENCIES(udf2 jemalloc) +ENDIF () + target_link_libraries( - udf2 PUBLIC os + udf2 PUBLIC os ${LINK_JEMALLOC} ) #SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/build/bin) @@ -86,9 +112,13 @@ target_include_directories( PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) +IF (TD_LINUX_64 AND JEMALLOC_ENABLED) + ADD_DEPENDENCIES(udfd jemalloc) +ENDIF () + target_link_libraries( - udfd - PUBLIC uv_a - PRIVATE os util common nodes function -) + udfd + PUBLIC uv_a + PRIVATE os util common nodes function ${LINK_JEMALLOC} + ) diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index f1022ac2bbc6e61a637c8ae330678d93e4e4937a..d3f03e8e9ce592a41d60cb1673545633fd3a380c 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -1651,7 +1651,7 @@ static int32_t translateMode(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { static int32_t translateDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t len) { int32_t numOfParams = LIST_LENGTH(pFunc->pParameterList); - if (numOfParams == 0 || numOfParams > 2) { + if (numOfParams > 2) { return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName); } @@ -2734,7 +2734,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { { .name = "mode", .type = FUNCTION_TYPE_MODE, - .classification = FUNC_MGT_AGG_FUNC, + .classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC, .translateFunc = translateMode, .getEnvFunc = getModeFuncEnv, .initFunc = modeFunctionSetup, diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index 40e3e7c35d68eb392e41f4ffc50abac31d9b95b5..079e553b07472cda2142f0d13673dab782ddfbc6 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -181,6 +181,7 @@ typedef enum { UNKNOWN_BIN = 0, USER_INPUT_BIN, LINEAR_BIN, LOG_BIN } EHistoBinT typedef struct SHLLFuncInfo { uint64_t result; + uint64_t totalCount; uint8_t buckets[HLL_BUCKETS]; } SHLLInfo; @@ -254,8 +255,9 @@ typedef struct SUniqueInfo { } SUniqueInfo; typedef struct SModeItem { - int64_t count; - char data[]; + int64_t count; + STuplePos tuplePos; + char data[]; } SModeItem; typedef struct SModeInfo { @@ -263,6 +265,10 @@ typedef struct SModeInfo { uint8_t colType; int16_t colBytes; SHashObj* pHash; + + STuplePos nullTuplePos; + bool nullTupleSaved; + char pItems[]; } SModeInfo; @@ -380,7 +386,7 @@ typedef struct SGroupKeyInfo { numOfElem += 1; \ pStddevRes->count -= 1; \ sumT -= plist[i]; \ - pStddevRes->quadraticISum -= plist[i] * plist[i]; \ + pStddevRes->quadraticISum -= (int64_t)(plist[i] * plist[i]); \ } \ } while (0) @@ -489,7 +495,7 @@ EFuncDataRequired countDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWind if (QUERY_NODE_COLUMN == nodeType(pParam) && PRIMARYKEY_TIMESTAMP_COL_ID == ((SColumnNode*)pParam)->colId) { return FUNC_DATA_REQUIRED_NOT_LOAD; } - return FUNC_DATA_REQUIRED_STATIS_LOAD; + return FUNC_DATA_REQUIRED_SMA_LOAD; } bool getCountFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { @@ -497,7 +503,7 @@ bool getCountFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) { return true; } -static FORCE_INLINE int32_t getNumOfElems(SqlFunctionCtx* pCtx) { +static int32_t getNumOfElems(SqlFunctionCtx* pCtx) { int32_t numOfElem = 0; /* @@ -551,7 +557,7 @@ int32_t countFunction(SqlFunctionCtx* pCtx) { if (tsCountAlwaysReturnValue) { pResInfo->numOfRes = 1; } else { - SET_VAL(pResInfo, 1, 1); + SET_VAL(pResInfo, *((int64_t*)buf), 1); } return TSDB_CODE_SUCCESS; @@ -905,6 +911,7 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) { case TSDB_DATA_TYPE_FLOAT: { float* plist = (float*)pCol->pData; +// float val = 0; for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { continue; @@ -912,8 +919,9 @@ int32_t avgFunction(SqlFunctionCtx* pCtx) { numOfElem += 1; pAvgRes->count += 1; - pAvgRes->sum.dsum += plist[i]; + pAvgRes->sum.dsum += plist[i]; } +// pAvgRes->sum.dsum = val; break; } @@ -1103,7 +1111,7 @@ int32_t avgPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { } EFuncDataRequired statisDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) { - return FUNC_DATA_REQUIRED_STATIS_LOAD; + return FUNC_DATA_REQUIRED_SMA_LOAD; } bool minmaxFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) { @@ -1272,14 +1280,20 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { pBuf->assign = true; } else { // ignore the equivalent data value - if ((*val) == pData[i]) { - continue; - } - - if ((*val < pData[i]) ^ isMinFunc) { - *val = pData[i]; - if (pCtx->subsidiaries.num > 0) { - updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + // NOTE: An faster version to avoid one additional comparison with FPU. + if (isMinFunc) { // min + if (*val > pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } + } + } else { // max + if (*val < pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } } } } @@ -1303,14 +1317,20 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { pBuf->assign = true; } else { // ignore the equivalent data value - if ((*val) == pData[i]) { - continue; - } - - if ((*val < pData[i]) ^ isMinFunc) { - *val = pData[i]; - if (pCtx->subsidiaries.num > 0) { - updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + // NOTE: An faster version to avoid one additional comparison with FPU. + if (isMinFunc) { // min + if (*val > pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } + } + } else { // max + if (*val < pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } } } } @@ -1334,14 +1354,20 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { pBuf->assign = true; } else { // ignore the equivalent data value - if ((*val) == pData[i]) { - continue; - } - - if ((*val < pData[i]) ^ isMinFunc) { - *val = pData[i]; - if (pCtx->subsidiaries.num > 0) { - updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + // NOTE: An faster version to avoid one additional comparison with FPU. + if (isMinFunc) { // min + if (*val > pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } + } + } else { // max + if (*val < pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } } } } @@ -1365,14 +1391,20 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { pBuf->assign = true; } else { // ignore the equivalent data value - if ((*val) == pData[i]) { - continue; - } - - if ((*val < pData[i]) ^ isMinFunc) { - *val = pData[i]; - if (pCtx->subsidiaries.num > 0) { - updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + // NOTE: An faster version to avoid one additional comparison with FPU. + if (isMinFunc) { // min + if (*val > pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } + } + } else { // max + if (*val < pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } } } } @@ -1398,14 +1430,20 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { pBuf->assign = true; } else { // ignore the equivalent data value - if ((*val) == pData[i]) { - continue; - } - - if ((*val < pData[i]) ^ isMinFunc) { - *val = pData[i]; - if (pCtx->subsidiaries.num > 0) { - updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + // NOTE: An faster version to avoid one additional comparison with FPU. + if (isMinFunc) { // min + if (*val > pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } + } + } else { // max + if (*val < pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } } } } @@ -1429,14 +1467,20 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { pBuf->assign = true; } else { // ignore the equivalent data value - if ((*val) == pData[i]) { - continue; - } - - if ((*val < pData[i]) ^ isMinFunc) { - *val = pData[i]; - if (pCtx->subsidiaries.num > 0) { - updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + // NOTE: An faster version to avoid one additional comparison with FPU. + if (isMinFunc) { // min + if (*val > pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } + } + } else { // max + if (*val < pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } } } } @@ -1460,14 +1504,20 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { pBuf->assign = true; } else { // ignore the equivalent data value - if ((*val) == pData[i]) { - continue; - } - - if ((*val < pData[i]) ^ isMinFunc) { - *val = pData[i]; - if (pCtx->subsidiaries.num > 0) { - updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + // NOTE: An faster version to avoid one additional comparison with FPU. + if (isMinFunc) { // min + if (*val > pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } + } + } else { // max + if (*val < pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } } } } @@ -1491,14 +1541,20 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { pBuf->assign = true; } else { // ignore the equivalent data value - if ((*val) == pData[i]) { - continue; - } - - if ((*val < pData[i]) ^ isMinFunc) { - *val = pData[i]; - if (pCtx->subsidiaries.num > 0) { - updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + // NOTE: An faster version to avoid one additional comparison with FPU. + if (isMinFunc) { // min + if (*val > pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } + } + } else { // max + if (*val < pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } } } } @@ -1523,14 +1579,20 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { pBuf->assign = true; } else { // ignore the equivalent data value - if ((*val) == pData[i]) { - continue; - } - - if ((*val < pData[i]) ^ isMinFunc) { - *val = pData[i]; - if (pCtx->subsidiaries.num > 0) { - updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + // NOTE: An faster version to avoid one additional comparison with FPU. + if (isMinFunc) { // min + if (*val > pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } + } + } else { // max + if (*val < pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } } } } @@ -1553,7 +1615,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { } pBuf->assign = true; } else { - // ignore the equivalent data value +#if 0 if ((*val) == pData[i]) { continue; } @@ -1564,6 +1626,23 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) { updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); } } +#endif + // NOTE: An faster version to avoid one additional comparison with FPU. + if (isMinFunc) { // min + if (*val > pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } + } + } else { // max + if (*val < pData[i]) { + *val = pData[i]; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos); + } + } + } } numOfElems += 1; @@ -2194,6 +2273,56 @@ int32_t leastSQRFunction(SqlFunctionCtx* pCtx) { break; } + case TSDB_DATA_TYPE_UTINYINT: { + uint8_t* plist = (uint8_t*)pCol->pData; + for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { + if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { + continue; + } + numOfElem++; + LEASTSQR_CAL(param, x, plist, i, pInfo->stepVal); + } + break; + } + case TSDB_DATA_TYPE_USMALLINT: { + uint16_t* plist = (uint16_t*)pCol->pData; + for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { + if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { + continue; + } + + numOfElem++; + LEASTSQR_CAL(param, x, plist, i, pInfo->stepVal); + } + break; + } + + case TSDB_DATA_TYPE_UINT: { + uint32_t* plist = (uint32_t*)pCol->pData; + for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { + if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { + continue; + } + + numOfElem++; + LEASTSQR_CAL(param, x, plist, i, pInfo->stepVal); + } + break; + } + + case TSDB_DATA_TYPE_UBIGINT: { + uint64_t* plist = (uint64_t*)pCol->pData; + for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { + if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) { + continue; + } + + numOfElem++; + LEASTSQR_CAL(param, x, plist, i, pInfo->stepVal); + } + break; + } + case TSDB_DATA_TYPE_FLOAT: { float* plist = (float*)pCol->pData; for (int32_t i = start; i < numOfRows + pInput->startRowIndex; ++i) { @@ -2257,6 +2386,12 @@ int32_t leastSQRFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { double param00 = param[0][0] - param[1][0] * (param[0][1] / param[1][1]); double param02 = param[0][2] - param[1][2] * (param[0][1] / param[1][1]); + + if (0 == param00) { + colDataAppendNULL(pCol, currentRow); + return 0; + } + // param[0][1] = 0; double param12 = param[1][2] - param02 * (param[1][0] / param00); // param[1][0] = 0; @@ -2526,8 +2661,9 @@ int32_t apercentileFunction(SqlFunctionCtx* pCtx) { // might be a race condition here that pHisto can be overwritten or setup function // has not been called, need to relink the buffer pHisto points to. buildHistogramInfo(pInfo); - qDebug("%s before add %d elements into histogram, total:%" PRId64 ", numOfEntry:%d, pHisto:%p, elems: %p", __FUNCTION__, - numOfElems, pInfo->pHisto->numOfElems, pInfo->pHisto->numOfEntries, pInfo->pHisto, pInfo->pHisto->elems); + qDebug("%s before add %d elements into histogram, total:%" PRId64 ", numOfEntry:%d, pHisto:%p, elems: %p", + __FUNCTION__, numOfElems, pInfo->pHisto->numOfElems, pInfo->pHisto->numOfEntries, pInfo->pHisto, + pInfo->pHisto->elems); for (int32_t i = start; i < pInput->numOfRows + start; ++i) { if (colDataIsNull_f(pCol->nullbitmap, i)) { continue; @@ -2656,7 +2792,9 @@ int32_t apercentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { taosMemoryFree(res); } else { // no need to free // setNull(pCtx->pOutput, pCtx->outputType, pCtx->outputBytes); - return TSDB_CODE_SUCCESS; + // return TSDB_CODE_SUCCESS; + qDebug("%s get the final res, elements:%" PRId64 ", numOfEntry:%d. result is null", __FUNCTION__, + pInfo->pHisto->numOfElems, pInfo->pHisto->numOfEntries); } } @@ -2869,6 +3007,7 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) { } } #else + int64_t* pts = (int64_t*) pInput->pPTS->pData; for (int32_t i = pInput->startRowIndex; i < pInput->startRowIndex + pInput->numOfRows; ++i) { if (pInputCol->hasNull && colDataIsNull(pInputCol, pInput->totalRows, i, pColAgg)) { continue; @@ -2877,13 +3016,14 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) { numOfElems++; char* data = colDataGetData(pInputCol, i); - TSKEY cts = getRowPTs(pInput->pPTS, i); + TSKEY cts = pts[i]; if (pResInfo->numOfRes == 0 || pInfo->ts > cts) { doSaveCurrentVal(pCtx, i, cts, pInputCol->info.type, data); pResInfo->numOfRes = 1; } } #endif + if (numOfElems == 0) { // save selectivity value for column consisted of all null values firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo); @@ -2955,26 +3095,87 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) { } } #else - for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex; ++i) { - if (pInputCol->hasNull && colDataIsNull(pInputCol, pInput->totalRows, i, pColAgg)) { - continue; + int64_t* pts = (int64_t*)pInput->pPTS->pData; + +#if 0 + for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex; ++i) { + if (pInputCol->hasNull && colDataIsNull(pInputCol, pInput->totalRows, i, pColAgg)) { + continue; + } + + numOfElems++; + if (pResInfo->numOfRes == 0 || pInfo->ts < pts[i]) { + char* data = colDataGetData(pInputCol, i); + doSaveCurrentVal(pCtx, i, pts[i], type, data); + pResInfo->numOfRes = 1; + } } +#else + if (!pInputCol->hasNull) { + numOfElems = 1; - numOfElems++; + int32_t round = pInput->numOfRows >> 2; + int32_t reminder = pInput->numOfRows & 0x03; - char* data = colDataGetData(pInputCol, i); - TSKEY cts = getRowPTs(pInput->pPTS, i); - if (pResInfo->numOfRes == 0 || pInfo->ts < cts) { - doSaveCurrentVal(pCtx, i, cts, type, data); - pResInfo->numOfRes = 1; + int32_t tick = 0; + for (int32_t i = pInput->startRowIndex; tick < round; i += 4, tick += 1) { + int64_t cts = pts[i]; + int32_t chosen = i; + + if (cts < pts[i + 1]) { + cts = pts[i + 1]; + chosen = i + 1; + } + + if (cts < pts[i + 2]) { + cts = pts[i + 2]; + chosen = i + 2; + } + + if (cts < pts[i + 3]) { + cts = pts[i + 3]; + chosen = i + 3; + } + + if (pResInfo->numOfRes == 0 || pInfo->ts < cts) { + char* data = colDataGetData(pInputCol, chosen); + doSaveCurrentVal(pCtx, i, cts, type, data); + pResInfo->numOfRes = 1; + } + } + + for (int32_t i = pInput->startRowIndex + round * 4; i < pInput->startRowIndex + pInput->numOfRows; ++i) { + if (pResInfo->numOfRes == 0 || pInfo->ts < pts[i]) { + char* data = colDataGetData(pInputCol, i); + doSaveCurrentVal(pCtx, i, pts[i], type, data); + pResInfo->numOfRes = 1; + } + } + } else { + for (int32_t i = pInput->startRowIndex; i < pInput->startRowIndex + pInput->numOfRows; ++i) { + if (pInputCol->hasNull && colDataIsNull(pInputCol, pInput->totalRows, i, pColAgg)) { + continue; + } + + numOfElems++; + + if (pResInfo->numOfRes == 0 || pInfo->ts < pts[i]) { + char* data = colDataGetData(pInputCol, i); + doSaveCurrentVal(pCtx, i, pts[i], type, data); + pResInfo->numOfRes = 1; + } + } } - } #endif + +#endif + + // save selectivity value for column consisted of all null values if (numOfElems == 0) { - // save selectivity value for column consisted of all null values firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo); } - SET_VAL(pResInfo, numOfElems, 1); + +// SET_VAL(pResInfo, numOfElems, 1); return TSDB_CODE_SUCCESS; } @@ -3124,8 +3325,8 @@ int32_t lastRowFunction(SqlFunctionCtx* pCtx) { #if 0 int32_t blockDataOrder = (startKey <= endKey) ? TSDB_ORDER_ASC : TSDB_ORDER_DESC; - // the optimized version only function if all tuples in one block are monotonious increasing or descreasing. - // this is NOT always works if project operator exists in downstream. + // the optimized version only valid if all tuples in one block are monotonious increasing or descreasing. + // this assumption is NOT always works if project operator exists in downstream. if (blockDataOrder == TSDB_ORDER_ASC) { for (int32_t i = pInput->numOfRows + pInput->startRowIndex - 1; i >= pInput->startRowIndex; --i) { char* data = colDataGetData(pInputCol, i); @@ -3151,11 +3352,13 @@ int32_t lastRowFunction(SqlFunctionCtx* pCtx) { } } #else + + int64_t* pts = (int64_t*)pInput->pPTS->pData; for (int32_t i = pInput->startRowIndex; i < pInput->numOfRows + pInput->startRowIndex; ++i) { char* data = colDataGetData(pInputCol, i); - TSKEY cts = getRowPTs(pInput->pPTS, i); - numOfElems++; + TSKEY cts = pts[i]; + numOfElems++; if (pResInfo->numOfRes == 0 || pInfo->ts < cts) { doSaveLastrow(pCtx, data, i, cts, pInfo); pResInfo->numOfRes = 1; @@ -4546,7 +4749,14 @@ int32_t hllFunction(SqlFunctionCtx* pCtx) { } } - SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1); + pInfo->totalCount += numOfElems; + + if (pInfo->totalCount == 0 && !tsCountAlwaysReturnValue) { + SET_VAL(GET_RES_INFO(pCtx), 0, 1); + } else { + SET_VAL(GET_RES_INFO(pCtx), 1, 1); + } + return TSDB_CODE_SUCCESS; } @@ -4556,6 +4766,7 @@ static void hllTransferInfo(SHLLInfo* pInput, SHLLInfo* pOutput) { pOutput->buckets[k] = pInput->buckets[k]; } } + pOutput->totalCount += pInput->totalCount; } int32_t hllFunctionMerge(SqlFunctionCtx* pCtx) { @@ -4573,7 +4784,12 @@ int32_t hllFunctionMerge(SqlFunctionCtx* pCtx) { hllTransferInfo(pInputInfo, pInfo); } - SET_VAL(GET_RES_INFO(pCtx), 1, 1); + if (pInfo->totalCount == 0 && !tsCountAlwaysReturnValue) { + SET_VAL(GET_RES_INFO(pCtx), 0, 1); + } else { + SET_VAL(GET_RES_INFO(pCtx), 1, 1); + } + return TSDB_CODE_SUCCESS; } @@ -5318,10 +5534,13 @@ bool modeFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo) { } else { pInfo->pHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); } + pInfo->nullTupleSaved = false; + pInfo->nullTuplePos.pageId = -1; + return true; } -static void doModeAdd(SModeInfo* pInfo, char* data) { +static void doModeAdd(SModeInfo* pInfo, int32_t rowIndex, SqlFunctionCtx* pCtx, char* data) { int32_t hashKeyBytes = IS_STR_DATA_TYPE(pInfo->colType) ? varDataTLen(data) : pInfo->colBytes; SModeItem** pHashItem = taosHashGet(pInfo->pHash, data, hashKeyBytes); if (pHashItem == NULL) { @@ -5330,10 +5549,17 @@ static void doModeAdd(SModeInfo* pInfo, char* data) { memcpy(pItem->data, data, hashKeyBytes); pItem->count += 1; + if (pCtx->subsidiaries.num > 0) { + pItem->tuplePos = saveTupleData(pCtx, rowIndex, pCtx->pSrcBlock, NULL); + } + taosHashPut(pInfo->pHash, data, hashKeyBytes, &pItem, sizeof(SModeItem*)); pInfo->numOfPoints++; } else { (*pHashItem)->count += 1; + if (pCtx->subsidiaries.num > 0) { + updateTupleData(pCtx, rowIndex, pCtx->pSrcBlock, &((*pHashItem)->tuplePos)); + } } } @@ -5355,7 +5581,7 @@ int32_t modeFunction(SqlFunctionCtx* pCtx) { } numOfElems++; - doModeAdd(pInfo, data); + doModeAdd(pInfo, i, pCtx, data); if (sizeof(SModeInfo) + pInfo->numOfPoints * (sizeof(SModeItem) + pInfo->colBytes) >= MODE_MAX_RESULT_SIZE) { taosHashCleanup(pInfo->pHash); @@ -5363,6 +5589,11 @@ int32_t modeFunction(SqlFunctionCtx* pCtx) { } } + if (numOfElems == 0 && pCtx->subsidiaries.num > 0 && !pInfo->nullTupleSaved) { + pInfo->nullTuplePos = saveTupleData(pCtx, pInput->startRowIndex, pCtx->pSrcBlock, NULL); + pInfo->nullTupleSaved = true; + } + SET_VAL(pResInfo, numOfElems, 1); return TSDB_CODE_SUCCESS; @@ -5388,10 +5619,14 @@ int32_t modeFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { if (maxCount != 0) { SModeItem* pResItem = (SModeItem*)(pInfo->pItems + resIndex * (sizeof(SModeItem) + pInfo->colBytes)); colDataAppend(pCol, currentRow, pResItem->data, false); + setSelectivityValue(pCtx, pBlock, &pResItem->tuplePos, currentRow); } else { colDataAppendNULL(pCol, currentRow); + setSelectivityValue(pCtx, pBlock, &pInfo->nullTuplePos, currentRow); } + taosHashCleanup(pInfo->pHash); + return pResInfo->numOfRes; } diff --git a/source/libs/function/src/functionMgt.c b/source/libs/function/src/functionMgt.c index bae005f5c4258fdff154cd75785cf3ebc83e9302..6ab91a4483eeaf0dabf5968c6f0cd424cb80fb96 100644 --- a/source/libs/function/src/functionMgt.c +++ b/source/libs/function/src/functionMgt.c @@ -241,7 +241,11 @@ bool fmIsNotNullOutputFunc(int32_t funcId) { FUNCTION_TYPE_LAST_MERGE == funcMgtBuiltins[funcId].type || FUNCTION_TYPE_FIRST == funcMgtBuiltins[funcId].type || FUNCTION_TYPE_FIRST_PARTIAL == funcMgtBuiltins[funcId].type || - FUNCTION_TYPE_FIRST_MERGE == funcMgtBuiltins[funcId].type; + FUNCTION_TYPE_FIRST_MERGE == funcMgtBuiltins[funcId].type || + FUNCTION_TYPE_COUNT == funcMgtBuiltins[funcId].type || + FUNCTION_TYPE_HYPERLOGLOG == funcMgtBuiltins[funcId].type || + FUNCTION_TYPE_HYPERLOGLOG_PARTIAL == funcMgtBuiltins[funcId].type || + FUNCTION_TYPE_HYPERLOGLOG_MERGE == funcMgtBuiltins[funcId].type; } bool fmIsSelectValueFunc(int32_t funcId) { @@ -251,6 +255,13 @@ bool fmIsSelectValueFunc(int32_t funcId) { return FUNCTION_TYPE_SELECT_VALUE == funcMgtBuiltins[funcId].type; } +bool fmIsGroupKeyFunc(int32_t funcId) { + if (funcId < 0 || funcId >= funcMgtBuiltinsNum) { + return false; + } + return FUNCTION_TYPE_GROUP_KEY == funcMgtBuiltins[funcId].type; +} + void fmFuncMgtDestroy() { void* m = gFunMgtService.pFuncNameHashTable; if (m != NULL && atomic_val_compare_exchange_ptr((void**)&gFunMgtService.pFuncNameHashTable, m, 0) == m) { diff --git a/source/libs/function/src/tudf.c b/source/libs/function/src/tudf.c index ea59e92e98b5938dd4be954d2837128825c5a747..8715aa0be18a547e22e865b8325ee23901bccabd 100644 --- a/source/libs/function/src/tudf.c +++ b/source/libs/function/src/tudf.c @@ -117,10 +117,33 @@ static int32_t udfSpawnUdfd(SUdfdData *pData) { char dnodeIdEnvItem[32] = {0}; char thrdPoolSizeEnvItem[32] = {0}; snprintf(dnodeIdEnvItem, 32, "%s=%d", "DNODE_ID", pData->dnodeId); + float numCpuCores = 4; taosGetCpuCores(&numCpuCores); snprintf(thrdPoolSizeEnvItem, 32, "%s=%d", "UV_THREADPOOL_SIZE", (int)numCpuCores * 2); - char *envUdfd[] = {dnodeIdEnvItem, thrdPoolSizeEnvItem, NULL}; + + char pathTaosdLdLib[512] = {0}; + size_t taosdLdLibPathLen = sizeof(pathTaosdLdLib); + int ret = uv_os_getenv("LD_LIBRARY_PATH", pathTaosdLdLib, &taosdLdLibPathLen); + if (ret != UV_ENOBUFS) { + taosdLdLibPathLen = strlen(pathTaosdLdLib); + } + + char udfdPathLdLib[1024] = {0}; + size_t udfdLdLibPathLen = strlen(tsUdfdLdLibPath); + strncpy(udfdPathLdLib, tsUdfdLdLibPath, tListLen(udfdPathLdLib)); + + udfdPathLdLib[udfdLdLibPathLen] = ':'; + strncpy(udfdPathLdLib + udfdLdLibPathLen + 1, pathTaosdLdLib, sizeof(udfdPathLdLib) - udfdLdLibPathLen - 1); + if (udfdLdLibPathLen + taosdLdLibPathLen < 1024) { + fnInfo("udfd LD_LIBRARY_PATH: %s", udfdPathLdLib); + } else { + fnError("can not set correct udfd LD_LIBRARY_PATH"); + } + char ldLibPathEnvItem[1024 + 32] = {0}; + snprintf(ldLibPathEnvItem, 1024 + 32, "%s=%s", "LD_LIBRARY_PATH", udfdPathLdLib); + + char *envUdfd[] = {dnodeIdEnvItem, thrdPoolSizeEnvItem, ldLibPathEnvItem, NULL}; options.env = envUdfd; int err = uv_spawn(&pData->loop, &pData->process, &options); @@ -340,7 +363,7 @@ typedef struct SUdfcProxy { SArray *udfStubs; // SUdfcFuncStub uv_mutex_t udfcUvMutex; - int8_t initialized; + int8_t initialized; } SUdfcProxy; SUdfcProxy gUdfcProxy = {0}; diff --git a/source/libs/index/src/indexFstFile.c b/source/libs/index/src/indexFstFile.c index 33960ad8c233bdbae32bb7847bdddaf26439d132..5538584754a92f8e11ef0deecbfb28aee12ef8a9 100644 --- a/source/libs/index/src/indexFstFile.c +++ b/source/libs/index/src/indexFstFile.c @@ -152,7 +152,7 @@ IFileCtx* idxFileCtxCreate(WriterType type, const char* path, bool readOnly, int if (ctx->type == TFILE) { // ugly code, refactor later ctx->file.readOnly = readOnly; - memcpy(ctx->file.buf, path, sizeof(ctx->file.buf)); + memcpy(ctx->file.buf, path, strlen(path)); if (readOnly == false) { ctx->file.pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); taosFtruncateFile(ctx->file.pFile, 0); diff --git a/source/libs/index/src/indexTfile.c b/source/libs/index/src/indexTfile.c index 4fdf6d9e57309897fef1a3b378966c8b667f8fbe..e002ff9c32a42580300ea134dc764bd03283a693 100644 --- a/source/libs/index/src/indexTfile.c +++ b/source/libs/index/src/indexTfile.c @@ -617,8 +617,6 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { indexError("failed to write data: %s, offset: %d len: %d", v->colVal, v->offset, (int)taosArrayGetSize(v->tableId)); } else { - indexInfo("success to write data: %s, offset: %d len: %d", v->colVal, v->offset, - (int)taosArrayGetSize(v->tableId)); } } fstBuilderDestroy(tw->fb); diff --git a/source/libs/index/test/index_executor_tests.cpp b/source/libs/index/test/index_executor_tests.cpp index 8b03f3b251da4ae8698bf976753f6f7e3a86ab96..bcc474dc8b9e93f564d53b9b82000edf55110371 100644 --- a/source/libs/index/test/index_executor_tests.cpp +++ b/source/libs/index/test/index_executor_tests.cpp @@ -86,8 +86,7 @@ void sifAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *sl SColumnInfoData idata = {0}; idata.info = *colInfo; - colInfoDataEnsureCapacity(&idata, rows); - + colInfoDataEnsureCapacity(&idata, rows, true); taosArrayPush(res->pDataBlock, &idata); *dataBlockId = taosArrayGetSize(pBlockList) - 1; diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index f0f1fc99756bacf892e9a7ce48677b94a06c0fd3..172c7694334d9a5199716434d169724c449eb037 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -111,6 +111,8 @@ const char* nodesNodeName(ENodeType type) { return "DropSuperTableStmt"; case QUERY_NODE_ALTER_TABLE_STMT: return "AlterTableStmt"; + case QUERY_NODE_ALTER_SUPER_TABLE_STMT: + return "AlterSuperTableStmt"; case QUERY_NODE_CREATE_USER_STMT: return "CreateUserStmt"; case QUERY_NODE_ALTER_USER_STMT: @@ -669,7 +671,7 @@ static int32_t logicProjectNodeToJson(const void* pObj, SJson* pJson) { code = nodeListToJson(pJson, jkProjectLogicPlanProjections, pNode->pProjections); } if (TSDB_CODE_SUCCESS == code) { - code = tjsonAddIntegerToObject(pJson, jkProjectLogicPlanIgnoreGroupId, pNode->ignoreGroupId); + code = tjsonAddBoolToObject(pJson, jkProjectLogicPlanIgnoreGroupId, pNode->ignoreGroupId); } return code; @@ -2632,6 +2634,7 @@ static const char* jkSubplanRootNode = "RootNode"; static const char* jkSubplanDataSink = "DataSink"; static const char* jkSubplanTagCond = "TagCond"; static const char* jkSubplanTagIndexCond = "TagIndexCond"; +static const char* jkSubplanShowRewrite = "ShowRewrite"; static int32_t subplanToJson(const void* pObj, SJson* pJson) { const SSubplan* pNode = (const SSubplan*)pObj; @@ -2667,6 +2670,9 @@ static int32_t subplanToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddObject(pJson, jkSubplanTagIndexCond, nodeToJson, pNode->pTagIndexCond); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddBoolToObject(pJson, jkSubplanShowRewrite, pNode->showRewrite); + } return code; } @@ -2705,6 +2711,9 @@ static int32_t jsonToSubplan(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = jsonToNodeObject(pJson, jkSubplanTagIndexCond, (SNode**)&pNode->pTagIndexCond); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBoolValue(pJson, jkSubplanShowRewrite, &pNode->showRewrite); + } return code; } @@ -2758,6 +2767,20 @@ static int32_t logicAggNodeToJson(const void* pObj, SJson* pJson) { return code; } +static int32_t jsonToLogicAggNode(const SJson* pJson, void* pObj) { + SAggLogicNode* pNode = (SAggLogicNode*)pObj; + + int32_t code = jsonToLogicPlanNode(pJson, pObj); + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeList(pJson, jkAggLogicPlanGroupKeys, &pNode->pGroupKeys); + } + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeList(pJson, jkAggLogicPlanAggFuncs, &pNode->pAggFuncs); + } + + return code; +} + static const char* jkDataTypeType = "Type"; static const char* jkDataTypePrecision = "Precision"; static const char* jkDataTypeScale = "Scale"; @@ -4735,6 +4758,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { return jsonToDeleteStmt(pJson, pObj); case QUERY_NODE_LOGIC_PLAN_SCAN: return jsonToLogicScanNode(pJson, pObj); + case QUERY_NODE_LOGIC_PLAN_AGG: + return jsonToLogicAggNode(pJson, pObj); case QUERY_NODE_LOGIC_PLAN_PROJECT: return jsonToLogicProjectNode(pJson, pObj); case QUERY_NODE_LOGIC_PLAN_VNODE_MODIFY: diff --git a/source/libs/nodes/src/nodesMsgFuncs.c b/source/libs/nodes/src/nodesMsgFuncs.c index 5b10e11dedb7e1b32b32ce2b96cbbf4aca1de839..2879d55167f82821399b5296c16514af306d8dd6 100644 --- a/source/libs/nodes/src/nodesMsgFuncs.c +++ b/source/libs/nodes/src/nodesMsgFuncs.c @@ -1969,7 +1969,12 @@ static int32_t msgToPhysiScanNode(STlvDecoder* pDecoder, void* pObj) { return code; } -enum { PHY_LAST_ROW_SCAN_CODE_SCAN = 1, PHY_LAST_ROW_SCAN_CODE_GROUP_TAGS, PHY_LAST_ROW_SCAN_CODE_GROUP_SORT, PHY_LAST_ROW_SCAN_CODE_IGNULL }; +enum { + PHY_LAST_ROW_SCAN_CODE_SCAN = 1, + PHY_LAST_ROW_SCAN_CODE_GROUP_TAGS, + PHY_LAST_ROW_SCAN_CODE_GROUP_SORT, + PHY_LAST_ROW_SCAN_CODE_IGNULL +}; static int32_t physiLastRowScanNodeToMsg(const void* pObj, STlvEncoder* pEncoder) { const SLastRowScanPhysiNode* pNode = (const SLastRowScanPhysiNode*)pObj; @@ -3433,6 +3438,9 @@ static int32_t subplanInlineToMsg(const void* pObj, STlvEncoder* pEncoder) { if (TSDB_CODE_SUCCESS == code) { code = queryNodeAddrInlineToMsg(&pNode->execNode, pEncoder); } + if (TSDB_CODE_SUCCESS == code) { + code = tlvEncodeValueBool(pEncoder, pNode->showRewrite); + } return code; } @@ -3479,6 +3487,9 @@ static int32_t msgToSubplanInline(STlvDecoder* pDecoder, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = msgToQueryNodeAddrInline(pDecoder, &pNode->execNode); } + if (TSDB_CODE_SUCCESS == code) { + code = tlvDecodeValueBool(pDecoder, &pNode->showRewrite); + } return code; } diff --git a/source/libs/nodes/src/nodesTraverseFuncs.c b/source/libs/nodes/src/nodesTraverseFuncs.c index 9f851f6a3f763d8d3d87797ffb6826e908ddba4a..106812d55f1cdd08120cb100e338b0b82244e752 100644 --- a/source/libs/nodes/src/nodesTraverseFuncs.c +++ b/source/libs/nodes/src/nodesTraverseFuncs.c @@ -438,210 +438,3 @@ void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewrit return; } - -static EDealRes walkPhysiNode(SPhysiNode* pNode, ETraversalOrder order, FNodeWalker walker, void* pContext) { - EDealRes res = walkPhysiPlan((SNode*)pNode->pOutputDataBlockDesc, order, walker, pContext); - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlan(pNode->pConditions, order, walker, pContext); - } - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlans(pNode->pChildren, order, walker, pContext); - } - return res; -} - -static EDealRes walkScanPhysi(SScanPhysiNode* pScan, ETraversalOrder order, FNodeWalker walker, void* pContext) { - EDealRes res = walkPhysiNode((SPhysiNode*)pScan, order, walker, pContext); - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlans(pScan->pScanCols, order, walker, pContext); - } - return res; -} - -static EDealRes walkTableScanPhysi(STableScanPhysiNode* pScan, ETraversalOrder order, FNodeWalker walker, - void* pContext) { - EDealRes res = walkScanPhysi((SScanPhysiNode*)pScan, order, walker, pContext); - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlans(pScan->pDynamicScanFuncs, order, walker, pContext); - } - return res; -} - -static EDealRes walkWindowPhysi(SWinodwPhysiNode* pWindow, ETraversalOrder order, FNodeWalker walker, void* pContext) { - EDealRes res = walkPhysiNode((SPhysiNode*)pWindow, order, walker, pContext); - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlans(pWindow->pExprs, order, walker, pContext); - } - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlans(pWindow->pFuncs, order, walker, pContext); - } - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlan(pWindow->pTspk, order, walker, pContext); - } - return res; -} - -static EDealRes dispatchPhysiPlan(SNode* pNode, ETraversalOrder order, FNodeWalker walker, void* pContext) { - EDealRes res = DEAL_RES_CONTINUE; - - switch (nodeType(pNode)) { - case QUERY_NODE_NODE_LIST: - res = walkPhysiPlans(((SNodeListNode*)pNode)->pNodeList, order, walker, pContext); - break; - case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN: - res = walkScanPhysi((SScanPhysiNode*)pNode, order, walker, pContext); - break; - case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN: - res = walkTableScanPhysi((STableScanPhysiNode*)pNode, order, walker, pContext); - break; - case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN: - res = walkTableScanPhysi((STableScanPhysiNode*)pNode, order, walker, pContext); - break; - case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN: - res = walkScanPhysi((SScanPhysiNode*)pNode, order, walker, pContext); - break; - case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN: - res = walkScanPhysi((SScanPhysiNode*)pNode, order, walker, pContext); - break; - case QUERY_NODE_PHYSICAL_PLAN_PROJECT: { - SProjectPhysiNode* pProject = (SProjectPhysiNode*)pNode; - res = walkPhysiNode((SPhysiNode*)pNode, order, walker, pContext); - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlans(pProject->pProjections, order, walker, pContext); - } - break; - } - case QUERY_NODE_PHYSICAL_PLAN_MERGE_JOIN: { - SSortMergeJoinPhysiNode* pJoin = (SSortMergeJoinPhysiNode*)pNode; - res = walkPhysiNode((SPhysiNode*)pNode, order, walker, pContext); - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlan(pJoin->pMergeCondition, order, walker, pContext); - } - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlan(pJoin->pOnConditions, order, walker, pContext); - } - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlans(pJoin->pTargets, order, walker, pContext); - } - break; - } - case QUERY_NODE_PHYSICAL_PLAN_HASH_AGG: { - SAggPhysiNode* pAgg = (SAggPhysiNode*)pNode; - res = walkPhysiNode((SPhysiNode*)pNode, order, walker, pContext); - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlans(pAgg->pExprs, order, walker, pContext); - } - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlans(pAgg->pGroupKeys, order, walker, pContext); - } - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlans(pAgg->pAggFuncs, order, walker, pContext); - } - break; - } - case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE: { - SExchangePhysiNode* pExchange = (SExchangePhysiNode*)pNode; - res = walkPhysiNode((SPhysiNode*)pNode, order, walker, pContext); - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlans(pExchange->pSrcEndPoints, order, walker, pContext); - } - break; - } - case QUERY_NODE_PHYSICAL_PLAN_SORT: - case QUERY_NODE_PHYSICAL_PLAN_GROUP_SORT: { - SSortPhysiNode* pSort = (SSortPhysiNode*)pNode; - res = walkPhysiNode((SPhysiNode*)pNode, order, walker, pContext); - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlans(pSort->pExprs, order, walker, pContext); - } - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlans(pSort->pSortKeys, order, walker, pContext); - } - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlans(pSort->pTargets, order, walker, pContext); - } - break; - } - case QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL: - case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL: - res = walkWindowPhysi((SWinodwPhysiNode*)pNode, order, walker, pContext); - break; - case QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION: - case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION: - res = walkWindowPhysi((SWinodwPhysiNode*)pNode, order, walker, pContext); - break; - case QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE: - case QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE: { - SStateWinodwPhysiNode* pState = (SStateWinodwPhysiNode*)pNode; - res = walkWindowPhysi((SWinodwPhysiNode*)pNode, order, walker, pContext); - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlan(pState->pStateKey, order, walker, pContext); - } - break; - } - case QUERY_NODE_PHYSICAL_PLAN_PARTITION: - case QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION: { - SPartitionPhysiNode* pPart = (SPartitionPhysiNode*)pNode; - res = walkPhysiNode((SPhysiNode*)pNode, order, walker, pContext); - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlans(pPart->pExprs, order, walker, pContext); - } - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlans(pPart->pPartitionKeys, order, walker, pContext); - } - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlans(pPart->pTargets, order, walker, pContext); - } - break; - } - case QUERY_NODE_PHYSICAL_PLAN_DISPATCH: - res = walkPhysiPlan((SNode*)(((SDataSinkNode*)pNode)->pInputDataBlockDesc), order, walker, pContext); - break; - case QUERY_NODE_PHYSICAL_PLAN_INSERT: - res = walkPhysiPlan((SNode*)(((SDataSinkNode*)pNode)->pInputDataBlockDesc), order, walker, pContext); - break; - case QUERY_NODE_PHYSICAL_SUBPLAN: { - SSubplan* pSubplan = (SSubplan*)pNode; - res = walkPhysiPlans(pSubplan->pChildren, order, walker, pContext); - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlan((SNode*)pSubplan->pNode, order, walker, pContext); - } - if (DEAL_RES_ERROR != res && DEAL_RES_END != res) { - res = walkPhysiPlan((SNode*)pSubplan->pDataSink, order, walker, pContext); - } - break; - } - case QUERY_NODE_PHYSICAL_PLAN: { - SQueryPlan* pPlan = (SQueryPlan*)pNode; - if (NULL != pPlan->pSubplans) { - // only need to walk the top-level subplans, because they will recurse to all the subplans below - walkPhysiPlan(nodesListGetNode(pPlan->pSubplans, 0), order, walker, pContext); - } - break; - } - default: - res = dispatchExpr(pNode, order, walker, pContext); - break; - } - - return res; -} - -static EDealRes walkPhysiPlan(SNode* pNode, ETraversalOrder order, FNodeWalker walker, void* pContext) { - return walkNode(pNode, order, walker, pContext, dispatchPhysiPlan); -} - -static EDealRes walkPhysiPlans(SNodeList* pNodeList, ETraversalOrder order, FNodeWalker walker, void* pContext) { - SNode* node; - FOREACH(node, pNodeList) { - EDealRes res = walkPhysiPlan(node, order, walker, pContext); - if (DEAL_RES_ERROR == res || DEAL_RES_END == res) { - return res; - } - } - return DEAL_RES_CONTINUE; -} - -void nodesWalkPhysiPlan(SNode* pNode, FNodeWalker walker, void* pContext) { - (void)walkPhysiPlan(pNode, TRAVERSAL_PREORDER, walker, pContext); -} diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 0c13dd822b54155cf94f6a0c89a01bf43b1ad247..c5b2dfed66f39edc206c9ae05d9157a304b5e515 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -328,6 +328,7 @@ SNode* nodesMakeNode(ENodeType type) { case QUERY_NODE_DROP_SUPER_TABLE_STMT: return makeNode(type, sizeof(SDropSuperTableStmt)); case QUERY_NODE_ALTER_TABLE_STMT: + case QUERY_NODE_ALTER_SUPER_TABLE_STMT: return makeNode(type, sizeof(SAlterTableStmt)); case QUERY_NODE_CREATE_USER_STMT: return makeNode(type, sizeof(SCreateUserStmt)); @@ -791,9 +792,24 @@ void nodesDestroyNode(SNode* pNode) { nodesDestroyNode((SNode*)pStmt->pSlimit); break; } - case QUERY_NODE_VNODE_MODIF_STMT: - destroyVgDataBlockArray(((SVnodeModifOpStmt*)pNode)->pDataBlocks); + case QUERY_NODE_VNODE_MODIF_STMT: { + SVnodeModifOpStmt* pStmt = (SVnodeModifOpStmt*)pNode; + destroyVgDataBlockArray(pStmt->pDataBlocks); + taosMemoryFreeClear(pStmt->pTableMeta); + taosHashCleanup(pStmt->pVgroupsHashObj); + taosHashCleanup(pStmt->pSubTableHashObj); + taosHashCleanup(pStmt->pTableNameHashObj); + taosHashCleanup(pStmt->pDbFNameHashObj); + if (pStmt->freeHashFunc) { + pStmt->freeHashFunc(pStmt->pTableBlockHashObj); + } + if (pStmt->freeArrayFunc) { + pStmt->freeArrayFunc(pStmt->pVgDataBlocks); + } + tdDestroySVCreateTbReq(&pStmt->createTblReq); + taosCloseFile(&pStmt->fp); break; + } case QUERY_NODE_CREATE_DATABASE_STMT: nodesDestroyNode((SNode*)((SCreateDatabaseStmt*)pNode)->pOptions); break; diff --git a/source/libs/nodes/test/CMakeLists.txt b/source/libs/nodes/test/CMakeLists.txt index 2be8e78d066d20372e2f0d211240940a16fda2ef..bf3e458ca471dff8f3eb79cf950ef84ebc5d4aa4 100644 --- a/source/libs/nodes/test/CMakeLists.txt +++ b/source/libs/nodes/test/CMakeLists.txt @@ -1,19 +1,26 @@ MESSAGE(STATUS "build nodes unit test") -# GoogleTest requires at least C++11 -SET(CMAKE_CXX_STANDARD 11) -AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) - -ADD_EXECUTABLE(nodesTest ${SOURCE_LIST}) - -TARGET_INCLUDE_DIRECTORIES( +IF(NOT TD_DARWIN) + # GoogleTest requires at least C++11 + SET(CMAKE_CXX_STANDARD 11) + AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) + + ADD_EXECUTABLE(nodesTest ${SOURCE_LIST}) + + TARGET_INCLUDE_DIRECTORIES( nodesTest PUBLIC "${TD_SOURCE_DIR}/include/nodes/" PRIVATE "${TD_SOURCE_DIR}/source/nodes/inc" -) - -TARGET_LINK_LIBRARIES( + ) + + TARGET_LINK_LIBRARIES( nodesTest - PUBLIC os util common nodes gtest -) + PUBLIC os util common nodes qcom gtest + ) + + add_test( + NAME nodesTest + COMMAND nodesTest + ) +ENDIF() diff --git a/source/libs/nodes/test/nodesCloneTest.cpp b/source/libs/nodes/test/nodesCloneTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e1e99abab3a8c04541432cdf6c870e24f7cd5a8b --- /dev/null +++ b/source/libs/nodes/test/nodesCloneTest.cpp @@ -0,0 +1,299 @@ +/* + * 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 . + */ + +#include + +#include "nodes.h" +#include "plannodes.h" +#include "querynodes.h" + +class NodesCloneTest : public testing::Test { + public: + void registerCheckFunc(const std::function& func) { checkFunc_ = func; } + + void run(const SNode* pSrc) { + std::unique_ptr pDst(nodesCloneNode(pSrc), nodesDestroyNode); + checkFunc_(pSrc, pDst.get()); + } + + private: + std::function checkFunc_; +}; + +TEST_F(NodesCloneTest, tempTable) { + registerCheckFunc([](const SNode* pSrc, const SNode* pDst) { + ASSERT_EQ(nodeType(pSrc), nodeType(pDst)); + STempTableNode* pSrcNode = (STempTableNode*)pSrc; + STempTableNode* pDstNode = (STempTableNode*)pDst; + ASSERT_EQ(nodeType(pSrcNode->pSubquery), nodeType(pDstNode->pSubquery)); + }); + + std::unique_ptr srcNode(nullptr, nodesDestroyNode); + + run([&]() { + srcNode.reset(nodesMakeNode(QUERY_NODE_TEMP_TABLE)); + STempTableNode* pNode = (STempTableNode*)srcNode.get(); + pNode->pSubquery = nodesMakeNode(QUERY_NODE_SELECT_STMT); + return srcNode.get(); + }()); +} + +TEST_F(NodesCloneTest, joinTable) { + registerCheckFunc([](const SNode* pSrc, const SNode* pDst) { + ASSERT_EQ(nodeType(pSrc), nodeType(pDst)); + SJoinTableNode* pSrcNode = (SJoinTableNode*)pSrc; + SJoinTableNode* pDstNode = (SJoinTableNode*)pDst; + ASSERT_EQ(pSrcNode->joinType, pDstNode->joinType); + ASSERT_EQ(nodeType(pSrcNode->pLeft), nodeType(pDstNode->pLeft)); + ASSERT_EQ(nodeType(pSrcNode->pRight), nodeType(pDstNode->pRight)); + if (NULL != pSrcNode->pOnCond) { + ASSERT_EQ(nodeType(pSrcNode->pOnCond), nodeType(pDstNode->pOnCond)); + } + }); + + std::unique_ptr srcNode(nullptr, nodesDestroyNode); + + run([&]() { + srcNode.reset(nodesMakeNode(QUERY_NODE_JOIN_TABLE)); + SJoinTableNode* pNode = (SJoinTableNode*)srcNode.get(); + pNode->joinType = JOIN_TYPE_INNER; + pNode->pLeft = nodesMakeNode(QUERY_NODE_REAL_TABLE); + pNode->pRight = nodesMakeNode(QUERY_NODE_REAL_TABLE); + pNode->pOnCond = nodesMakeNode(QUERY_NODE_OPERATOR); + return srcNode.get(); + }()); +} + +TEST_F(NodesCloneTest, stateWindow) { + registerCheckFunc([](const SNode* pSrc, const SNode* pDst) { + ASSERT_EQ(nodeType(pSrc), nodeType(pDst)); + SStateWindowNode* pSrcNode = (SStateWindowNode*)pSrc; + SStateWindowNode* pDstNode = (SStateWindowNode*)pDst; + ASSERT_EQ(nodeType(pSrcNode->pCol), nodeType(pDstNode->pCol)); + ASSERT_EQ(nodeType(pSrcNode->pExpr), nodeType(pDstNode->pExpr)); + }); + + std::unique_ptr srcNode(nullptr, nodesDestroyNode); + + run([&]() { + srcNode.reset(nodesMakeNode(QUERY_NODE_STATE_WINDOW)); + SStateWindowNode* pNode = (SStateWindowNode*)srcNode.get(); + pNode->pCol = nodesMakeNode(QUERY_NODE_COLUMN); + pNode->pExpr = nodesMakeNode(QUERY_NODE_OPERATOR); + return srcNode.get(); + }()); +} + +TEST_F(NodesCloneTest, sessionWindow) { + registerCheckFunc([](const SNode* pSrc, const SNode* pDst) { + ASSERT_EQ(nodeType(pSrc), nodeType(pDst)); + SSessionWindowNode* pSrcNode = (SSessionWindowNode*)pSrc; + SSessionWindowNode* pDstNode = (SSessionWindowNode*)pDst; + ASSERT_EQ(nodeType(pSrcNode->pCol), nodeType(pDstNode->pCol)); + ASSERT_EQ(nodeType(pSrcNode->pGap), nodeType(pDstNode->pGap)); + }); + + std::unique_ptr srcNode(nullptr, nodesDestroyNode); + + run([&]() { + srcNode.reset(nodesMakeNode(QUERY_NODE_SESSION_WINDOW)); + SSessionWindowNode* pNode = (SSessionWindowNode*)srcNode.get(); + pNode->pCol = (SColumnNode*)nodesMakeNode(QUERY_NODE_COLUMN); + pNode->pGap = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE); + return srcNode.get(); + }()); +} + +TEST_F(NodesCloneTest, intervalWindow) { + registerCheckFunc([](const SNode* pSrc, const SNode* pDst) { + ASSERT_EQ(nodeType(pSrc), nodeType(pDst)); + SIntervalWindowNode* pSrcNode = (SIntervalWindowNode*)pSrc; + SIntervalWindowNode* pDstNode = (SIntervalWindowNode*)pDst; + ASSERT_EQ(nodeType(pSrcNode->pInterval), nodeType(pDstNode->pInterval)); + if (NULL != pSrcNode->pOffset) { + ASSERT_EQ(nodeType(pSrcNode->pOffset), nodeType(pDstNode->pOffset)); + } + if (NULL != pSrcNode->pSliding) { + ASSERT_EQ(nodeType(pSrcNode->pSliding), nodeType(pDstNode->pSliding)); + } + if (NULL != pSrcNode->pFill) { + ASSERT_EQ(nodeType(pSrcNode->pFill), nodeType(pDstNode->pFill)); + } + }); + + std::unique_ptr srcNode(nullptr, nodesDestroyNode); + + run([&]() { + srcNode.reset(nodesMakeNode(QUERY_NODE_INTERVAL_WINDOW)); + SIntervalWindowNode* pNode = (SIntervalWindowNode*)srcNode.get(); + pNode->pInterval = nodesMakeNode(QUERY_NODE_VALUE); + pNode->pOffset = nodesMakeNode(QUERY_NODE_VALUE); + pNode->pSliding = nodesMakeNode(QUERY_NODE_VALUE); + pNode->pFill = nodesMakeNode(QUERY_NODE_FILL); + return srcNode.get(); + }()); +} + +TEST_F(NodesCloneTest, fill) { + registerCheckFunc([](const SNode* pSrc, const SNode* pDst) { + ASSERT_EQ(nodeType(pSrc), nodeType(pDst)); + SFillNode* pSrcNode = (SFillNode*)pSrc; + SFillNode* pDstNode = (SFillNode*)pDst; + ASSERT_EQ(pSrcNode->mode, pDstNode->mode); + if (NULL != pSrcNode->pValues) { + ASSERT_EQ(nodeType(pSrcNode->pValues), nodeType(pDstNode->pValues)); + } + ASSERT_EQ(nodeType(pSrcNode->pWStartTs), nodeType(pDstNode->pWStartTs)); + ASSERT_EQ(pSrcNode->timeRange.skey, pDstNode->timeRange.skey); + ASSERT_EQ(pSrcNode->timeRange.ekey, pDstNode->timeRange.ekey); + }); + + std::unique_ptr srcNode(nullptr, nodesDestroyNode); + + run([&]() { + srcNode.reset(nodesMakeNode(QUERY_NODE_FILL)); + SFillNode* pNode = (SFillNode*)srcNode.get(); + pNode->mode = FILL_MODE_VALUE; + pNode->pValues = nodesMakeNode(QUERY_NODE_NODE_LIST); + pNode->pWStartTs = nodesMakeNode(QUERY_NODE_COLUMN); + pNode->timeRange.skey = 1666756692907; + pNode->timeRange.ekey = 1666756699907; + return srcNode.get(); + }()); +} + +TEST_F(NodesCloneTest, logicSubplan) { + registerCheckFunc([](const SNode* pSrc, const SNode* pDst) { + ASSERT_EQ(nodeType(pSrc), nodeType(pDst)); + SLogicSubplan* pSrcNode = (SLogicSubplan*)pSrc; + SLogicSubplan* pDstNode = (SLogicSubplan*)pDst; + ASSERT_EQ(pSrcNode->subplanType, pDstNode->subplanType); + ASSERT_EQ(pSrcNode->level, pDstNode->level); + ASSERT_EQ(pSrcNode->splitFlag, pDstNode->splitFlag); + ASSERT_EQ(pSrcNode->numOfComputeNodes, pDstNode->numOfComputeNodes); + }); + + std::unique_ptr srcNode(nullptr, nodesDestroyNode); + + run([&]() { + srcNode.reset(nodesMakeNode(QUERY_NODE_LOGIC_SUBPLAN)); + SLogicSubplan* pNode = (SLogicSubplan*)srcNode.get(); + return srcNode.get(); + }()); +} + +TEST_F(NodesCloneTest, physiScan) { + registerCheckFunc([](const SNode* pSrc, const SNode* pDst) { + ASSERT_EQ(nodeType(pSrc), nodeType(pDst)); + STagScanPhysiNode* pSrcNode = (STagScanPhysiNode*)pSrc; + STagScanPhysiNode* pDstNode = (STagScanPhysiNode*)pDst; + ASSERT_EQ(pSrcNode->uid, pDstNode->uid); + ASSERT_EQ(pSrcNode->suid, pDstNode->suid); + ASSERT_EQ(pSrcNode->tableType, pDstNode->tableType); + }); + + std::unique_ptr srcNode(nullptr, nodesDestroyNode); + + run([&]() { + srcNode.reset(nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN)); + STagScanPhysiNode* pNode = (STagScanPhysiNode*)srcNode.get(); + return srcNode.get(); + }()); +} + +TEST_F(NodesCloneTest, physiSystemTableScan) { + registerCheckFunc([](const SNode* pSrc, const SNode* pDst) { + ASSERT_EQ(nodeType(pSrc), nodeType(pDst)); + SSystemTableScanPhysiNode* pSrcNode = (SSystemTableScanPhysiNode*)pSrc; + SSystemTableScanPhysiNode* pDstNode = (SSystemTableScanPhysiNode*)pDst; + ASSERT_EQ(pSrcNode->showRewrite, pDstNode->showRewrite); + ASSERT_EQ(pSrcNode->accountId, pDstNode->accountId); + ASSERT_EQ(pSrcNode->sysInfo, pDstNode->sysInfo); + }); + + std::unique_ptr srcNode(nullptr, nodesDestroyNode); + + run([&]() { + srcNode.reset(nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN)); + SSystemTableScanPhysiNode* pNode = (SSystemTableScanPhysiNode*)srcNode.get(); + return srcNode.get(); + }()); +} + +TEST_F(NodesCloneTest, physiStreamSemiSessionWinodw) { + registerCheckFunc([](const SNode* pSrc, const SNode* pDst) { + ASSERT_EQ(nodeType(pSrc), nodeType(pDst)); + SStreamSemiSessionWinodwPhysiNode* pSrcNode = (SStreamSemiSessionWinodwPhysiNode*)pSrc; + SStreamSemiSessionWinodwPhysiNode* pDstNode = (SStreamSemiSessionWinodwPhysiNode*)pDst; + ASSERT_EQ(pSrcNode->gap, pDstNode->gap); + }); + + std::unique_ptr srcNode(nullptr, nodesDestroyNode); + + run([&]() { + srcNode.reset(nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION)); + SStreamSemiSessionWinodwPhysiNode* pNode = (SStreamSemiSessionWinodwPhysiNode*)srcNode.get(); + return srcNode.get(); + }()); +} + +TEST_F(NodesCloneTest, physiStreamFinalSessionWinodw) { + registerCheckFunc([](const SNode* pSrc, const SNode* pDst) { + ASSERT_EQ(nodeType(pSrc), nodeType(pDst)); + SStreamFinalSessionWinodwPhysiNode* pSrcNode = (SStreamFinalSessionWinodwPhysiNode*)pSrc; + SStreamFinalSessionWinodwPhysiNode* pDstNode = (SStreamFinalSessionWinodwPhysiNode*)pDst; + ASSERT_EQ(pSrcNode->gap, pDstNode->gap); + }); + + std::unique_ptr srcNode(nullptr, nodesDestroyNode); + + run([&]() { + srcNode.reset(nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION)); + SStreamFinalSessionWinodwPhysiNode* pNode = (SStreamFinalSessionWinodwPhysiNode*)srcNode.get(); + return srcNode.get(); + }()); +} + +TEST_F(NodesCloneTest, physiStreamPartition) { + registerCheckFunc([](const SNode* pSrc, const SNode* pDst) { + ASSERT_EQ(nodeType(pSrc), nodeType(pDst)); + SStreamPartitionPhysiNode* pSrcNode = (SStreamPartitionPhysiNode*)pSrc; + SStreamPartitionPhysiNode* pDstNode = (SStreamPartitionPhysiNode*)pDst; + }); + + std::unique_ptr srcNode(nullptr, nodesDestroyNode); + + run([&]() { + srcNode.reset(nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_STREAM_PARTITION)); + SStreamPartitionPhysiNode* pNode = (SStreamPartitionPhysiNode*)srcNode.get(); + return srcNode.get(); + }()); +} + +TEST_F(NodesCloneTest, physiPartition) { + registerCheckFunc([](const SNode* pSrc, const SNode* pDst) { + ASSERT_EQ(nodeType(pSrc), nodeType(pDst)); + SPartitionPhysiNode* pSrcNode = (SPartitionPhysiNode*)pSrc; + SPartitionPhysiNode* pDstNode = (SPartitionPhysiNode*)pDst; + }); + + std::unique_ptr srcNode(nullptr, nodesDestroyNode); + + run([&]() { + srcNode.reset(nodesMakeNode(QUERY_NODE_PHYSICAL_PLAN_PARTITION)); + SPartitionPhysiNode* pNode = (SPartitionPhysiNode*)srcNode.get(); + return srcNode.get(); + }()); +} diff --git a/source/libs/nodes/test/nodesTest.cpp b/source/libs/nodes/test/nodesTestMain.cpp similarity index 100% rename from source/libs/nodes/test/nodesTest.cpp rename to source/libs/nodes/test/nodesTestMain.cpp diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index 09d1a5e77223712447f97ff77cd53319db85ff3e..86940a9d7a5153631ca6893ac44c25433f9aca4f 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -182,7 +182,7 @@ SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const ST SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t alterType, const SToken* pVal); SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName); SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort); -SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode); +SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, bool force); SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig, const SToken* pValue); SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SNode* pIndexName, SNode* pRealTable, SNodeList* pCols, SNode* pOptions); diff --git a/source/libs/parser/inc/parInsertUtil.h b/source/libs/parser/inc/parInsertUtil.h index 1e941632e78f83fd81e31db812a4b94e231b7135..09d55d369fc0d711b4a4301c74a0cb0d7002c347 100644 --- a/source/libs/parser/inc/parInsertUtil.h +++ b/source/libs/parser/inc/parInsertUtil.h @@ -79,29 +79,6 @@ typedef struct SInsertParseBaseContext { SMsgBuf msg; } SInsertParseBaseContext; -typedef struct SInsertParseContext { - SParseContext *pComCxt; // input - char *pSql; // input - SMsgBuf msg; // input - STableMeta *pTableMeta; // each table - SParsedDataColInfo tags; // each table - SVCreateTbReq createTblReq; // each table - SHashObj *pVgroupsHashObj; // global - SHashObj *pTableBlockHashObj; // global - SHashObj *pSubTableHashObj; // global - SArray *pVgDataBlocks; // global - SHashObj *pTableNameHashObj; // global - SHashObj *pDbFNameHashObj; // global - int32_t totalNum; - SVnodeModifOpStmt *pOutput; - SStmtCallback *pStmtCb; - SParseMetaCache *pMetaCache; - char sTableName[TSDB_TABLE_NAME_LEN]; - char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW]; - int64_t memElapsed; - int64_t parRowElapsed; -} SInsertParseContext; - typedef struct SInsertParseSyntaxCxt { SParseContext *pComCxt; char *pSql; @@ -142,7 +119,7 @@ typedef struct STableDataBlocks { int32_t insGetExtendedRowSize(STableDataBlocks *pBlock); void insGetSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo *spd, col_id_t idx, int32_t *toffset, col_id_t *colIdx); -int32_t insSetBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks *dataBuf, int32_t numOfRows); +int32_t insSetBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks *dataBuf, int32_t numOfRows, SMsgBuf *pMsg); int32_t insSchemaIdxCompar(const void *lhs, const void *rhs); int32_t insBoundIdxCompar(const void *lhs, const void *rhs); void insSetBoundColumnInfo(SParsedDataColInfo *pColList, SSchema *pSchema, col_id_t numOfCols); @@ -161,7 +138,7 @@ void insBuildCreateTbReq(SVCreateTbReq *pTbReq, const char *tname, STag *pTag SArray *tagName, uint8_t tagNum); int32_t insMemRowAppend(SMsgBuf *pMsgBuf, const void *value, int32_t len, void *param); int32_t insCheckTimestamp(STableDataBlocks *pDataBlocks, const char *start); -int32_t insBuildOutput(SInsertParseContext *pCxt); +int32_t insBuildOutput(SHashObj *pVgroupsHashObj, SArray *pVgDataBlocks, SArray **pDataBlocks); void insDestroyDataBlock(STableDataBlocks *pDataBlock); #endif // TDENGINE_PAR_INSERT_UTIL_H diff --git a/source/libs/parser/inc/parInt.h b/source/libs/parser/inc/parInt.h index b799fa98558a12584244ab730db213c8be35eacb..66aec272d787df6fc4e04248d4833bda78b98a65 100644 --- a/source/libs/parser/inc/parInt.h +++ b/source/libs/parser/inc/parInt.h @@ -27,8 +27,7 @@ extern "C" { #define QUERY_SMA_OPTIMIZE_DISABLE 0 #define QUERY_SMA_OPTIMIZE_ENABLE 1 -int32_t parseInsertSyntax(SParseContext* pContext, SQuery** pQuery, SParseMetaCache* pMetaCache); -int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery, SParseMetaCache* pMetaCache); +int32_t parseInsertSql(SParseContext* pCxt, SQuery** pQuery, SCatalogReq* pCatalogReq, const SMetaData* pMetaData); int32_t parse(SParseContext* pParseCxt, SQuery** pQuery); int32_t collectMetaKey(SParseContext* pParseCxt, SQuery* pQuery, SParseMetaCache* pMetaCache); int32_t authenticate(SParseContext* pParseCxt, SQuery* pQuery, SParseMetaCache* pMetaCache); diff --git a/source/libs/parser/inc/parUtil.h b/source/libs/parser/inc/parUtil.h index 75b631ec9d7330219f7ca1364385eab43e61d2a3..10a86866d584b4307bc4ff9801bac49c379a0dfc 100644 --- a/source/libs/parser/inc/parUtil.h +++ b/source/libs/parser/inc/parUtil.h @@ -60,22 +60,17 @@ typedef struct SInsertTablesMetaReq { } SInsertTablesMetaReq; typedef struct SParseMetaCache { - SHashObj* pTableMeta; // key is tbFName, element is STableMeta* - SHashObj* pDbVgroup; // key is dbFName, element is SArray* - SHashObj* pTableVgroup; // key is tbFName, element is SVgroupInfo* - SHashObj* pDbCfg; // key is tbFName, element is SDbCfgInfo* - SHashObj* pDbInfo; // key is tbFName, element is SDbInfo* - SHashObj* pUserAuth; // key is SUserAuthInfo serialized string, element is bool indicating whether or not to pass - SHashObj* pUdf; // key is funcName, element is SFuncInfo* - SHashObj* pTableIndex; // key is tbFName, element is SArray* - SHashObj* pTableCfg; // key is tbFName, element is STableCfg* - SArray* pDnodes; // element is SEpSet - bool dnodeRequired; - SHashObj* pInsertTables; // key is dbName, element is SInsertTablesMetaReq*, for insert - const char* pUser; - const SArray* pTableMetaData; // pRes = STableMeta* - const SArray* pTableVgroupData; // pRes = SVgroupInfo* - int32_t sqlTableNum; + SHashObj* pTableMeta; // key is tbFName, element is STableMeta* + SHashObj* pDbVgroup; // key is dbFName, element is SArray* + SHashObj* pTableVgroup; // key is tbFName, element is SVgroupInfo* + SHashObj* pDbCfg; // key is tbFName, element is SDbCfgInfo* + SHashObj* pDbInfo; // key is tbFName, element is SDbInfo* + SHashObj* pUserAuth; // key is SUserAuthInfo serialized string, element is bool indicating whether or not to pass + SHashObj* pUdf; // key is funcName, element is SFuncInfo* + SHashObj* pTableIndex; // key is tbFName, element is SArray* + SHashObj* pTableCfg; // key is tbFName, element is STableCfg* + SArray* pDnodes; // element is SEpSet + bool dnodeRequired; } SParseMetaCache; int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...); @@ -93,9 +88,8 @@ STableMeta* tableMetaDup(const STableMeta* pTableMeta); int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen); int32_t getInsTagsTableTargetName(int32_t acctId, SNode* pWhere, SName* pName); -int32_t buildCatalogReq(SParseContext* pCxt, const SParseMetaCache* pMetaCache, SCatalogReq* pCatalogReq); -int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMetaData, SParseMetaCache* pMetaCache, - bool insertValuesStmt); +int32_t buildCatalogReq(const SParseMetaCache* pMetaCache, SCatalogReq* pCatalogReq); +int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMetaData, SParseMetaCache* pMetaCache); int32_t reserveTableMetaInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache); int32_t reserveTableMetaInCacheExt(const SName* pName, SParseMetaCache* pMetaCache); int32_t reserveDbVgInfoInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache); @@ -122,12 +116,6 @@ int32_t getUdfInfoFromCache(SParseMetaCache* pMetaCache, const char* pFunc, SFun int32_t getTableIndexFromCache(SParseMetaCache* pMetaCache, const SName* pName, SArray** pIndexes); int32_t getTableCfgFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableCfg** pOutput); int32_t getDnodeListFromCache(SParseMetaCache* pMetaCache, SArray** pDnodes); -int32_t reserveTableMetaInCacheForInsert(const SName* pName, ECatalogReqType reqType, int32_t tableNo, - SParseMetaCache* pMetaCache); -int32_t getTableMetaFromCacheForInsert(SArray* pTableMetaPos, SParseMetaCache* pMetaCache, int32_t tableNo, - STableMeta** pMeta); -int32_t getTableVgroupFromCacheForInsert(SArray* pTableVgroupPos, SParseMetaCache* pMetaCache, int32_t tableNo, - SVgroupInfo* pVgroup); void destoryParseMetaCache(SParseMetaCache* pMetaCache, bool request); #ifdef __cplusplus diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 845fd4262f5abe6bd87c9ae72f1ab1ebbb810478..b143f1624edcc88a836e411d58cf487bbf739bee 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -120,8 +120,8 @@ priv_level(A) ::= db_name(B) NK_DOT NK_STAR. /************************************************ create/drop/alter dnode *********************************************/ cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL); } cmd ::= CREATE DNODE dnode_endpoint(A) PORT NK_INTEGER(B). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, &B); } -cmd ::= DROP DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A); } -cmd ::= DROP DNODE dnode_endpoint(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A); } +cmd ::= DROP DNODE NK_INTEGER(A) force_opt(B). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A, B); } +cmd ::= DROP DNODE dnode_endpoint(A) force_opt(B). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A, B); } cmd ::= ALTER DNODE NK_INTEGER(A) NK_STRING(B). { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &A, &B, NULL); } cmd ::= ALTER DNODE NK_INTEGER(A) NK_STRING(B) NK_STRING(C). { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &A, &B, &C); } cmd ::= ALTER ALL DNODES NK_STRING(A). { pCxt->pRootNode = createAlterDnodeStmt(pCxt, NULL, &A, NULL); } @@ -133,6 +133,11 @@ dnode_endpoint(A) ::= NK_STRING(B). dnode_endpoint(A) ::= NK_ID(B). { A = B; } dnode_endpoint(A) ::= NK_IPTOKEN(B). { A = B; } +%type force_opt { bool } +%destructor force_opt { } +force_opt(A) ::= . { A = false; } +force_opt(A) ::= FORCE. { A = true; } + /************************************************ alter local *********************************************************/ cmd ::= ALTER LOCAL NK_STRING(A). { pCxt->pRootNode = createAlterLocalStmt(pCxt, &A, NULL); } cmd ::= ALTER LOCAL NK_STRING(A) NK_STRING(B). { pCxt->pRootNode = createAlterLocalStmt(pCxt, &A, &B); } @@ -518,6 +523,7 @@ stream_options(A) ::= stream_options(B) TRIGGER WINDOW_CLOSE. stream_options(A) ::= stream_options(B) TRIGGER MAX_DELAY duration_literal(C). { ((SStreamOptions*)B)->triggerType = STREAM_TRIGGER_MAX_DELAY; ((SStreamOptions*)B)->pDelay = releaseRawExprNode(pCxt, C); A = B; } stream_options(A) ::= stream_options(B) WATERMARK duration_literal(C). { ((SStreamOptions*)B)->pWatermark = releaseRawExprNode(pCxt, C); A = B; } stream_options(A) ::= stream_options(B) IGNORE EXPIRED NK_INTEGER(C). { ((SStreamOptions*)B)->ignoreExpired = taosStr2Int8(C.z, NULL, 10); A = B; } +stream_options(A) ::= stream_options(B) FILL_HISTORY NK_INTEGER(C). { ((SStreamOptions*)B)->fillHistory = taosStr2Int8(C.z, NULL, 10); A = B; } subtable_opt(A) ::= . { A = NULL; } subtable_opt(A) ::= SUBTABLE NK_LP expression(B) NK_RP. { A = releaseRawExprNode(pCxt, B); } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index f7c92cc9440452e89ceb87857b538bdb35e325df..49685112a9f48f73d347f995bcd533619e1fda42 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -1457,7 +1457,7 @@ SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const return (SNode*)pStmt; } -SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode) { +SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, bool force) { CHECK_PARSER_STATUS(pCxt); SDropDnodeStmt* pStmt = (SDropDnodeStmt*)nodesMakeNode(QUERY_NODE_DROP_DNODE_STMT); CHECK_OUT_OF_MEM(pStmt); @@ -1469,6 +1469,7 @@ SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode) { return NULL; } } + pStmt->force = force; return (SNode*)pStmt; } @@ -1702,6 +1703,7 @@ SNode* createStreamOptions(SAstCreateContext* pCxt) { SStreamOptions* pOptions = (SStreamOptions*)nodesMakeNode(QUERY_NODE_STREAM_OPTIONS); CHECK_OUT_OF_MEM(pOptions); pOptions->triggerType = STREAM_TRIGGER_AT_ONCE; + pOptions->fillHistory = STREAM_DEFAULT_FILL_HISTORY; pOptions->ignoreExpired = STREAM_DEFAULT_IGNORE_EXPIRED; return (SNode*)pOptions; } diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index 28dc6179f9988d67108e6fbf2a67ac1bb330479e..bb3d1a2cb31d0f5394e880579a384c5dbff4b73d 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -84,6 +84,7 @@ abort_parse: (*pQuery)->pRoot = cxt.pRootNode; (*pQuery)->placeholderNum = cxt.placeholderNo; TSWAP((*pQuery)->pPlaceholderValues, cxt.pPlaceholderValues); + (*pQuery)->execStage = QUERY_EXEC_STAGE_ANALYSE; } taosArrayDestroy(cxt.pPlaceholderValues); return cxt.errCode; diff --git a/source/libs/parser/src/parInsertSml.c b/source/libs/parser/src/parInsertSml.c index 8be5b86b37bd51a0ae1eb1f7c66584b0c8366c55..d18b11ad57e25a863c7a507d95da92ef05d19cc3 100644 --- a/source/libs/parser/src/parInsertSml.c +++ b/source/libs/parser/src/parInsertSml.c @@ -333,11 +333,7 @@ int32_t smlBindData(void* handle, SArray* tags, SArray* colsSchema, SArray* cols } SSubmitBlk* pBlocks = (SSubmitBlk*)(pDataBlock->pData); - if (TSDB_CODE_SUCCESS != insSetBlockInfo(pBlocks, pDataBlock, rowNum)) { - return buildInvalidOperationMsg(&pBuf, "too many rows in sql, total number of rows should be less than INT32_MAX"); - } - - return TSDB_CODE_SUCCESS; + return insSetBlockInfo(pBlocks, pDataBlock, rowNum, &pBuf); } void* smlInitHandle(SQuery* pQuery) { diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c index 1ccb34cd1fd485c4334b1cff1515718c02b740e8..7a38f48cb2fd81d52d9da1feb08895b41ad0689a 100644 --- a/source/libs/parser/src/parInsertSql.c +++ b/source/libs/parser/src/parInsertSql.c @@ -18,123 +18,247 @@ #include "tglobal.h" #include "ttime.h" -#define NEXT_TOKEN_WITH_PREV(pSql, sToken) \ - do { \ - int32_t index = 0; \ - sToken = tStrGetToken(pSql, &index, true); \ - pSql += index; \ +#define NEXT_TOKEN_WITH_PREV(pSql, token) \ + do { \ + int32_t index = 0; \ + token = tStrGetToken(pSql, &index, true); \ + pSql += index; \ } while (0) -#define NEXT_TOKEN_KEEP_SQL(pSql, sToken, index) \ - do { \ - sToken = tStrGetToken(pSql, &index, false); \ +#define NEXT_TOKEN_KEEP_SQL(pSql, token, index) \ + do { \ + token = tStrGetToken(pSql, &index, false); \ } while (0) -#define NEXT_VALID_TOKEN(pSql, sToken) \ - do { \ - sToken.n = tGetToken(pSql, &sToken.type); \ - sToken.z = pSql; \ - pSql += sToken.n; \ - } while (TK_NK_SPACE == sToken.type) +#define NEXT_VALID_TOKEN(pSql, token) \ + do { \ + (token).n = tGetToken(pSql, &(token).type); \ + (token).z = (char*)pSql; \ + pSql += (token).n; \ + } while (TK_NK_SPACE == (token).type) + +typedef struct SInsertParseContext { + SParseContext* pComCxt; + SMsgBuf msg; + char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW]; + SParsedDataColInfo tags; // for stmt + bool missCache; + bool usingDuplicateTable; +} SInsertParseContext; typedef int32_t (*_row_append_fn_t)(SMsgBuf* pMsgBuf, const void* value, int32_t len, void* param); static uint8_t TRUE_VALUE = (uint8_t)TSDB_TRUE; static uint8_t FALSE_VALUE = (uint8_t)TSDB_FALSE; -static int32_t skipInsertInto(char** pSql, SMsgBuf* pMsg) { - SToken sToken; - NEXT_TOKEN(*pSql, sToken); - if (TK_INSERT != sToken.type && TK_IMPORT != sToken.type) { - return buildSyntaxErrMsg(pMsg, "keyword INSERT is expected", sToken.z); +static bool isNullStr(SToken* pToken) { + return ((pToken->type == TK_NK_STRING) && (strlen(TSDB_DATA_NULL_STR_L) == pToken->n) && + (strncasecmp(TSDB_DATA_NULL_STR_L, pToken->z, pToken->n) == 0)); +} + +static bool isNullValue(int8_t dataType, SToken* pToken) { + return TK_NULL == pToken->type || (!IS_STR_DATA_TYPE(dataType) && isNullStr(pToken)); +} + +static FORCE_INLINE int32_t toDouble(SToken* pToken, double* value, char** endPtr) { + errno = 0; + *value = taosStr2Double(pToken->z, endPtr); + + // not a valid integer number, return error + if ((*endPtr - pToken->z) != pToken->n) { + return TK_NK_ILLEGAL; + } + + return pToken->type; +} + +static int32_t skipInsertInto(const char** pSql, SMsgBuf* pMsg) { + SToken token; + NEXT_TOKEN(*pSql, token); + if (TK_INSERT != token.type && TK_IMPORT != token.type) { + return buildSyntaxErrMsg(pMsg, "keyword INSERT is expected", token.z); } - NEXT_TOKEN(*pSql, sToken); - if (TK_INTO != sToken.type) { - return buildSyntaxErrMsg(pMsg, "keyword INTO is expected", sToken.z); + NEXT_TOKEN(*pSql, token); + if (TK_INTO != token.type) { + return buildSyntaxErrMsg(pMsg, "keyword INTO is expected", token.z); } return TSDB_CODE_SUCCESS; } -static int32_t checkAuth(SInsertParseContext* pCxt, char* pDbFname, bool* pPass) { - SParseContext* pBasicCtx = pCxt->pComCxt; - if (pBasicCtx->async) { - return getUserAuthFromCache(pCxt->pMetaCache, pBasicCtx->pUser, pDbFname, AUTH_TYPE_WRITE, pPass); +static int32_t skipParentheses(SInsertParseContext* pCxt, const char** pSql) { + SToken token; + int32_t expectRightParenthesis = 1; + while (1) { + NEXT_TOKEN(*pSql, token); + if (TK_NK_LP == token.type) { + ++expectRightParenthesis; + } else if (TK_NK_RP == token.type && 0 == --expectRightParenthesis) { + break; + } + if (0 == token.n) { + return buildSyntaxErrMsg(&pCxt->msg, ") expected", NULL); + } } - SRequestConnInfo conn = {.pTrans = pBasicCtx->pTransporter, - .requestId = pBasicCtx->requestId, - .requestObjRefId = pBasicCtx->requestRid, - .mgmtEps = pBasicCtx->mgmtEpSet}; + return TSDB_CODE_SUCCESS; +} - return catalogChkAuth(pBasicCtx->pCatalog, &conn, pBasicCtx->pUser, pDbFname, AUTH_TYPE_WRITE, pPass); +static int32_t skipTableOptions(SInsertParseContext* pCxt, const char** pSql) { + do { + int32_t index = 0; + SToken token; + NEXT_TOKEN_KEEP_SQL(*pSql, token, index); + if (TK_TTL == token.type || TK_COMMENT == token.type) { + *pSql += index; + NEXT_TOKEN_WITH_PREV(*pSql, token); + } else { + break; + } + } while (1); + return TSDB_CODE_SUCCESS; } -static int32_t getTableSchema(SInsertParseContext* pCxt, int32_t tbNo, SName* pTbName, bool isStb, - STableMeta** pTableMeta) { - SParseContext* pBasicCtx = pCxt->pComCxt; - if (pBasicCtx->async) { - return getTableMetaFromCacheForInsert(pBasicCtx->pTableMetaPos, pCxt->pMetaCache, tbNo, pTableMeta); +// pSql -> stb_name [(tag1_name, ...)] TAGS (tag1_value, ...) +static int32_t ignoreUsingClause(SInsertParseContext* pCxt, const char** pSql) { + int32_t code = TSDB_CODE_SUCCESS; + SToken token; + NEXT_TOKEN(*pSql, token); + + NEXT_TOKEN(*pSql, token); + if (TK_NK_LP == token.type) { + code = skipParentheses(pCxt, pSql); + if (TSDB_CODE_SUCCESS == code) { + NEXT_TOKEN(*pSql, token); + } } - SRequestConnInfo conn = {.pTrans = pBasicCtx->pTransporter, - .requestId = pBasicCtx->requestId, - .requestObjRefId = pBasicCtx->requestRid, - .mgmtEps = pBasicCtx->mgmtEpSet}; - if (isStb) { - return catalogGetSTableMeta(pBasicCtx->pCatalog, &conn, pTbName, pTableMeta); + // pSql -> TAGS (tag1_value, ...) + if (TSDB_CODE_SUCCESS == code) { + if (TK_TAGS != token.type) { + code = buildSyntaxErrMsg(&pCxt->msg, "TAGS is expected", token.z); + } else { + NEXT_TOKEN(*pSql, token); + } + } + if (TSDB_CODE_SUCCESS == code) { + if (TK_NK_LP != token.type) { + code = buildSyntaxErrMsg(&pCxt->msg, "( is expected", token.z); + } else { + code = skipParentheses(pCxt, pSql); + } } - return catalogGetTableMeta(pBasicCtx->pCatalog, &conn, pTbName, pTableMeta); -} -static int32_t getTableVgroup(SInsertParseContext* pCxt, int32_t tbNo, SName* pTbName, SVgroupInfo* pVg) { - SParseContext* pBasicCtx = pCxt->pComCxt; - if (pBasicCtx->async) { - return getTableVgroupFromCacheForInsert(pBasicCtx->pTableVgroupPos, pCxt->pMetaCache, tbNo, pVg); + if (TSDB_CODE_SUCCESS == code) { + code = skipTableOptions(pCxt, pSql); } - SRequestConnInfo conn = {.pTrans = pBasicCtx->pTransporter, - .requestId = pBasicCtx->requestId, - .requestObjRefId = pBasicCtx->requestRid, - .mgmtEps = pBasicCtx->mgmtEpSet}; - return catalogGetTableHashVgroup(pBasicCtx->pCatalog, &conn, pTbName, pVg); + + return code; } -static int32_t getTableMetaImpl(SInsertParseContext* pCxt, int32_t tbNo, SName* name, bool isStb) { - CHECK_CODE(getTableSchema(pCxt, tbNo, name, isStb, &pCxt->pTableMeta)); - if (!isStb) { - SVgroupInfo vg; - CHECK_CODE(getTableVgroup(pCxt, tbNo, name, &vg)); - CHECK_CODE(taosHashPut(pCxt->pVgroupsHashObj, (const char*)&vg.vgId, sizeof(vg.vgId), (char*)&vg, sizeof(vg))); +static int32_t parseDuplicateUsingClause(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt, bool* pDuplicate) { + *pDuplicate = false; + + char tbFName[TSDB_TABLE_FNAME_LEN]; + tNameExtractFullName(&pStmt->targetTableName, tbFName); + STableMeta** pMeta = taosHashGet(pStmt->pSubTableHashObj, tbFName, strlen(tbFName)); + if (NULL != pMeta) { + *pDuplicate = true; + int32_t code = ignoreUsingClause(pCxt, &pStmt->pSql); + if (TSDB_CODE_SUCCESS == code) { + return cloneTableMeta(*pMeta, &pStmt->pTableMeta); + } } + return TSDB_CODE_SUCCESS; } -static int32_t getTableMeta(SInsertParseContext* pCxt, int32_t tbNo, SName* name) { - return getTableMetaImpl(pCxt, tbNo, name, false); -} +// pStmt->pSql -> field1_name, ...) +static int32_t parseBoundColumns(SInsertParseContext* pCxt, const char** pSql, SParsedDataColInfo* pColList, + SSchema* pSchema) { + col_id_t nCols = pColList->numOfCols; -static int32_t getSTableMeta(SInsertParseContext* pCxt, int32_t tbNo, SName* name) { - return getTableMetaImpl(pCxt, tbNo, name, true); -} + pColList->numOfBound = 0; + pColList->boundNullLen = 0; + memset(pColList->boundColumns, 0, sizeof(col_id_t) * nCols); + for (col_id_t i = 0; i < nCols; ++i) { + pColList->cols[i].valStat = VAL_STAT_NONE; + } -static int32_t getDBCfg(SInsertParseContext* pCxt, const char* pDbFName, SDbCfgInfo* pInfo) { - SParseContext* pBasicCtx = pCxt->pComCxt; - if (pBasicCtx->async) { - CHECK_CODE(getDbCfgFromCache(pCxt->pMetaCache, pDbFName, pInfo)); - } else { - SRequestConnInfo conn = {.pTrans = pBasicCtx->pTransporter, - .requestId = pBasicCtx->requestId, - .requestObjRefId = pBasicCtx->requestRid, - .mgmtEps = pBasicCtx->mgmtEpSet}; - CHECK_CODE(catalogGetDBCfg(pBasicCtx->pCatalog, &conn, pDbFName, pInfo)); + SToken token; + bool isOrdered = true; + col_id_t lastColIdx = -1; // last column found + while (1) { + NEXT_TOKEN(*pSql, token); + + if (TK_NK_RP == token.type) { + break; + } + + char tmpTokenBuf[TSDB_COL_NAME_LEN + 2] = {0}; // used for deleting Escape character backstick(`) + strncpy(tmpTokenBuf, token.z, token.n); + token.z = tmpTokenBuf; + token.n = strdequote(token.z); + + col_id_t t = lastColIdx + 1; + col_id_t index = insFindCol(&token, t, nCols, pSchema); + if (index < 0 && t > 0) { + index = insFindCol(&token, 0, t, pSchema); + isOrdered = false; + } + if (index < 0) { + return generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_INVALID_COLUMN, token.z); + } + if (pColList->cols[index].valStat == VAL_STAT_HAS) { + return buildSyntaxErrMsg(&pCxt->msg, "duplicated column name", token.z); + } + lastColIdx = index; + pColList->cols[index].valStat = VAL_STAT_HAS; + pColList->boundColumns[pColList->numOfBound] = index; + ++pColList->numOfBound; + switch (pSchema[t].type) { + case TSDB_DATA_TYPE_BINARY: + pColList->boundNullLen += (sizeof(VarDataOffsetT) + VARSTR_HEADER_SIZE + CHAR_BYTES); + break; + case TSDB_DATA_TYPE_NCHAR: + pColList->boundNullLen += (sizeof(VarDataOffsetT) + VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE); + break; + default: + pColList->boundNullLen += TYPE_BYTES[pSchema[t].type]; + break; + } + } + + pColList->orderStatus = isOrdered ? ORDER_STATUS_ORDERED : ORDER_STATUS_DISORDERED; + + if (!isOrdered) { + pColList->colIdxInfo = taosMemoryCalloc(pColList->numOfBound, sizeof(SBoundIdxInfo)); + if (NULL == pColList->colIdxInfo) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + SBoundIdxInfo* pColIdx = pColList->colIdxInfo; + for (col_id_t i = 0; i < pColList->numOfBound; ++i) { + pColIdx[i].schemaColIdx = pColList->boundColumns[i]; + pColIdx[i].boundIdx = i; + } + taosSort(pColIdx, pColList->numOfBound, sizeof(SBoundIdxInfo), insSchemaIdxCompar); + for (col_id_t i = 0; i < pColList->numOfBound; ++i) { + pColIdx[i].finalIdx = i; + } + taosSort(pColIdx, pColList->numOfBound, sizeof(SBoundIdxInfo), insBoundIdxCompar); + } + + if (pColList->numOfCols > pColList->numOfBound) { + memset(&pColList->boundColumns[pColList->numOfBound], 0, + sizeof(col_id_t) * (pColList->numOfCols - pColList->numOfBound)); } + return TSDB_CODE_SUCCESS; } -static int parseTime(char** end, SToken* pToken, int16_t timePrec, int64_t* time, SMsgBuf* pMsgBuf) { - int32_t index = 0; - SToken sToken; - int64_t interval; - int64_t ts = 0; - char* pTokenEnd = *end; +static int parseTime(const char** end, SToken* pToken, int16_t timePrec, int64_t* time, SMsgBuf* pMsgBuf) { + int32_t index = 0; + int64_t interval; + int64_t ts = 0; + const char* pTokenEnd = *end; if (pToken->type == TK_NOW) { ts = taosGetTimestamp(timePrec); @@ -172,18 +296,17 @@ static int parseTime(char** end, SToken* pToken, int16_t timePrec, int64_t* time * time expression: * e.g., now+12a, now-5h */ - SToken valueToken; index = 0; - sToken = tStrGetToken(pTokenEnd, &index, false); + SToken token = tStrGetToken(pTokenEnd, &index, false); pTokenEnd += index; - if (sToken.type == TK_NK_MINUS || sToken.type == TK_NK_PLUS) { + if (token.type == TK_NK_MINUS || token.type == TK_NK_PLUS) { index = 0; - valueToken = tStrGetToken(pTokenEnd, &index, false); + SToken valueToken = tStrGetToken(pTokenEnd, &index, false); pTokenEnd += index; if (valueToken.n < 2) { - return buildSyntaxErrMsg(pMsgBuf, "value expected in timestamp", sToken.z); + return buildSyntaxErrMsg(pMsgBuf, "value expected in timestamp", token.z); } char unit = 0; @@ -191,7 +314,7 @@ static int parseTime(char** end, SToken* pToken, int16_t timePrec, int64_t* time return TSDB_CODE_TSC_INVALID_OPERATION; } - if (sToken.type == TK_NK_PLUS) { + if (token.type == TK_NK_PLUS) { ts += interval; } else { ts = ts - interval; @@ -204,92 +327,42 @@ static int parseTime(char** end, SToken* pToken, int16_t timePrec, int64_t* time return TSDB_CODE_SUCCESS; } -static FORCE_INLINE int32_t checkAndTrimValue(SToken* pToken, char* tmpTokenBuf, SMsgBuf* pMsgBuf) { - if ((pToken->type != TK_NOW && pToken->type != TK_TODAY && pToken->type != TK_NK_INTEGER && - pToken->type != TK_NK_STRING && pToken->type != TK_NK_FLOAT && pToken->type != TK_NK_BOOL && - pToken->type != TK_NULL && pToken->type != TK_NK_HEX && pToken->type != TK_NK_OCT && - pToken->type != TK_NK_BIN) || - (pToken->n == 0) || (pToken->type == TK_NK_RP)) { - return buildSyntaxErrMsg(pMsgBuf, "invalid data or symbol", pToken->z); - } - - // Remove quotation marks - if (TK_NK_STRING == pToken->type) { - if (pToken->n >= TSDB_MAX_BYTES_PER_ROW) { - return buildSyntaxErrMsg(pMsgBuf, "too long string", pToken->z); - } - - int32_t len = trimString(pToken->z, pToken->n, tmpTokenBuf, TSDB_MAX_BYTES_PER_ROW); - pToken->z = tmpTokenBuf; - pToken->n = len; - } - - return TSDB_CODE_SUCCESS; -} - -static bool isNullStr(SToken* pToken) { - return ((pToken->type == TK_NK_STRING) && (strlen(TSDB_DATA_NULL_STR_L) == pToken->n) && - (strncasecmp(TSDB_DATA_NULL_STR_L, pToken->z, pToken->n) == 0)); -} - -static bool isNullValue(int8_t dataType, SToken* pToken) { - return TK_NULL == pToken->type || (!IS_STR_DATA_TYPE(dataType) && isNullStr(pToken)); -} - -static FORCE_INLINE int32_t toDouble(SToken* pToken, double* value, char** endPtr) { - errno = 0; - *value = taosStr2Double(pToken->z, endPtr); - - // not a valid integer number, return error - if ((*endPtr - pToken->z) != pToken->n) { - return TK_NK_ILLEGAL; - } - - return pToken->type; -} - -static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int16_t timePrec, char* tmpTokenBuf, - _row_append_fn_t func, void* param, SMsgBuf* pMsgBuf) { +static int32_t parseTagToken(const char** end, SToken* pToken, SSchema* pSchema, int16_t timePrec, STagVal* val, + SMsgBuf* pMsgBuf) { int64_t iv; uint64_t uv; char* endptr = NULL; - int32_t code = checkAndTrimValue(pToken, tmpTokenBuf, pMsgBuf); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - if (isNullValue(pSchema->type, pToken)) { if (TSDB_DATA_TYPE_TIMESTAMP == pSchema->type && PRIMARYKEY_TIMESTAMP_COL_ID == pSchema->colId) { return buildSyntaxErrMsg(pMsgBuf, "primary timestamp should not be null", pToken->z); } - return func(pMsgBuf, NULL, 0, param); + return TSDB_CODE_SUCCESS; } - if (IS_NUMERIC_TYPE(pSchema->type) && pToken->n == 0) { - return buildSyntaxErrMsg(pMsgBuf, "invalid numeric data", pToken->z); - } + // strcpy(val->colName, pSchema->name); + val->cid = pSchema->colId; + val->type = pSchema->type; switch (pSchema->type) { case TSDB_DATA_TYPE_BOOL: { if ((pToken->type == TK_NK_BOOL || pToken->type == TK_NK_STRING) && (pToken->n != 0)) { if (strncmp(pToken->z, "true", pToken->n) == 0) { - return func(pMsgBuf, &TRUE_VALUE, pSchema->bytes, param); + *(int8_t*)(&val->i64) = TRUE_VALUE; } else if (strncmp(pToken->z, "false", pToken->n) == 0) { - return func(pMsgBuf, &FALSE_VALUE, pSchema->bytes, param); + *(int8_t*)(&val->i64) = FALSE_VALUE; } else { return buildSyntaxErrMsg(pMsgBuf, "invalid bool data", pToken->z); } } else if (pToken->type == TK_NK_INTEGER) { - return func(pMsgBuf, ((taosStr2Int64(pToken->z, NULL, 10) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, - param); + *(int8_t*)(&val->i64) = ((taosStr2Int64(pToken->z, NULL, 10) == 0) ? FALSE_VALUE : TRUE_VALUE); } else if (pToken->type == TK_NK_FLOAT) { - return func(pMsgBuf, ((taosStr2Double(pToken->z, NULL) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, - param); + *(int8_t*)(&val->i64) = ((taosStr2Double(pToken->z, NULL) == 0) ? FALSE_VALUE : TRUE_VALUE); } else { return buildSyntaxErrMsg(pMsgBuf, "invalid bool data", pToken->z); } + break; } case TSDB_DATA_TYPE_TINYINT: { @@ -299,8 +372,8 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int return buildSyntaxErrMsg(pMsgBuf, "tinyint data overflow", pToken->z); } - uint8_t tmpVal = (uint8_t)iv; - return func(pMsgBuf, &tmpVal, pSchema->bytes, param); + *(int8_t*)(&val->i64) = iv; + break; } case TSDB_DATA_TYPE_UTINYINT: { @@ -309,8 +382,8 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int } else if (uv > UINT8_MAX) { return buildSyntaxErrMsg(pMsgBuf, "unsigned tinyint data overflow", pToken->z); } - uint8_t tmpVal = (uint8_t)uv; - return func(pMsgBuf, &tmpVal, pSchema->bytes, param); + *(uint8_t*)(&val->i64) = uv; + break; } case TSDB_DATA_TYPE_SMALLINT: { @@ -319,8 +392,8 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int } else if (!IS_VALID_SMALLINT(iv)) { return buildSyntaxErrMsg(pMsgBuf, "smallint data overflow", pToken->z); } - int16_t tmpVal = (int16_t)iv; - return func(pMsgBuf, &tmpVal, pSchema->bytes, param); + *(int16_t*)(&val->i64) = iv; + break; } case TSDB_DATA_TYPE_USMALLINT: { @@ -329,8 +402,8 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int } else if (uv > UINT16_MAX) { return buildSyntaxErrMsg(pMsgBuf, "unsigned smallint data overflow", pToken->z); } - uint16_t tmpVal = (uint16_t)uv; - return func(pMsgBuf, &tmpVal, pSchema->bytes, param); + *(uint16_t*)(&val->i64) = uv; + break; } case TSDB_DATA_TYPE_INT: { @@ -339,8 +412,8 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int } else if (!IS_VALID_INT(iv)) { return buildSyntaxErrMsg(pMsgBuf, "int data overflow", pToken->z); } - int32_t tmpVal = (int32_t)iv; - return func(pMsgBuf, &tmpVal, pSchema->bytes, param); + *(int32_t*)(&val->i64) = iv; + break; } case TSDB_DATA_TYPE_UINT: { @@ -349,22 +422,24 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int } else if (uv > UINT32_MAX) { return buildSyntaxErrMsg(pMsgBuf, "unsigned int data overflow", pToken->z); } - uint32_t tmpVal = (uint32_t)uv; - return func(pMsgBuf, &tmpVal, pSchema->bytes, param); + *(uint32_t*)(&val->i64) = uv; + break; } case TSDB_DATA_TYPE_BIGINT: { if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &iv)) { return buildSyntaxErrMsg(pMsgBuf, "invalid bigint data", pToken->z); } - return func(pMsgBuf, &iv, pSchema->bytes, param); + val->i64 = iv; + break; } case TSDB_DATA_TYPE_UBIGINT: { if (TSDB_CODE_SUCCESS != toUInteger(pToken->z, pToken->n, 10, &uv)) { return buildSyntaxErrMsg(pMsgBuf, "invalid unsigned bigint data", pToken->z); } - return func(pMsgBuf, &uv, pSchema->bytes, param); + *(uint64_t*)(&val->i64) = uv; + break; } case TSDB_DATA_TYPE_FLOAT: { @@ -376,8 +451,8 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int isnan(dv)) { return buildSyntaxErrMsg(pMsgBuf, "illegal float data", pToken->z); } - float tmpVal = (float)dv; - return func(pMsgBuf, &tmpVal, pSchema->bytes, param); + *(float*)(&val->i64) = dv; + break; } case TSDB_DATA_TYPE_DOUBLE: { @@ -388,7 +463,9 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || isinf(dv) || isnan(dv)) { return buildSyntaxErrMsg(pMsgBuf, "illegal double data", pToken->z); } - return func(pMsgBuf, &dv, pSchema->bytes, param); + + *(double*)(&val->i64) = dv; + break; } case TSDB_DATA_TYPE_BINARY: { @@ -396,583 +473,751 @@ static int32_t parseValueToken(char** end, SToken* pToken, SSchema* pSchema, int if (pToken->n + VARSTR_HEADER_SIZE > pSchema->bytes) { return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name); } - - return func(pMsgBuf, pToken->z, pToken->n, param); + val->pData = strdup(pToken->z); + val->nData = pToken->n; + break; } case TSDB_DATA_TYPE_NCHAR: { - return func(pMsgBuf, pToken->z, pToken->n, param); - } - case TSDB_DATA_TYPE_JSON: { - if (pToken->n > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) { - return buildSyntaxErrMsg(pMsgBuf, "json string too long than 4095", pToken->z); + int32_t output = 0; + void* p = taosMemoryCalloc(1, pSchema->bytes - VARSTR_HEADER_SIZE); + if (p == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + if (!taosMbsToUcs4(pToken->z, pToken->n, (TdUcs4*)(p), pSchema->bytes - VARSTR_HEADER_SIZE, &output)) { + if (errno == E2BIG) { + taosMemoryFree(p); + return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name); + } + char buf[512] = {0}; + snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(errno)); + taosMemoryFree(p); + return buildSyntaxErrMsg(pMsgBuf, buf, pToken->z); } - return func(pMsgBuf, pToken->z, pToken->n, param); + val->pData = p; + val->nData = output; + break; } case TSDB_DATA_TYPE_TIMESTAMP: { - int64_t tmpVal; - if (parseTime(end, pToken, timePrec, &tmpVal, pMsgBuf) != TSDB_CODE_SUCCESS) { + if (parseTime(end, pToken, timePrec, &iv, pMsgBuf) != TSDB_CODE_SUCCESS) { return buildSyntaxErrMsg(pMsgBuf, "invalid timestamp", pToken->z); } - return func(pMsgBuf, &tmpVal, pSchema->bytes, param); + val->i64 = iv; + break; } } - return TSDB_CODE_FAILED; + return TSDB_CODE_SUCCESS; } -// pSql -> tag1_name, ...) -static int32_t parseBoundColumns(SInsertParseContext* pCxt, SParsedDataColInfo* pColList, SSchema* pSchema) { - col_id_t nCols = pColList->numOfCols; +// input pStmt->pSql: [(tag1_name, ...)] TAGS (tag1_value, ...) ... +// output pStmt->pSql: TAGS (tag1_value, ...) ... +static int32_t parseBoundTagsClause(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + SSchema* pTagsSchema = getTableTagSchema(pStmt->pTableMeta); + insSetBoundColumnInfo(&pCxt->tags, pTagsSchema, getNumOfTags(pStmt->pTableMeta)); - pColList->numOfBound = 0; - pColList->boundNullLen = 0; - memset(pColList->boundColumns, 0, sizeof(col_id_t) * nCols); - for (col_id_t i = 0; i < nCols; ++i) { - pColList->cols[i].valStat = VAL_STAT_NONE; + SToken token; + int32_t index = 0; + NEXT_TOKEN_KEEP_SQL(pStmt->pSql, token, index); + if (TK_NK_LP != token.type) { + return TSDB_CODE_SUCCESS; } - SToken sToken; - bool isOrdered = true; - col_id_t lastColIdx = -1; // last column found - while (1) { - NEXT_TOKEN(pCxt->pSql, sToken); + pStmt->pSql += index; + return parseBoundColumns(pCxt, &pStmt->pSql, &pCxt->tags, pTagsSchema); +} - if (TK_NK_RP == sToken.type) { - break; +static int32_t parseTagValue(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt, SSchema* pTagSchema, SToken* pToken, + SArray* pTagName, SArray* pTagVals, STag** pTag) { + if (!isNullValue(pTagSchema->type, pToken)) { + taosArrayPush(pTagName, pTagSchema->name); + } + + if (pTagSchema->type == TSDB_DATA_TYPE_JSON) { + if (pToken->n > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) { + return buildSyntaxErrMsg(&pCxt->msg, "json string too long than 4095", pToken->z); } - char tmpTokenBuf[TSDB_COL_NAME_LEN + 2] = {0}; // used for deleting Escape character backstick(`) - strncpy(tmpTokenBuf, sToken.z, sToken.n); - sToken.z = tmpTokenBuf; - sToken.n = strdequote(sToken.z); + if (isNullValue(pTagSchema->type, pToken)) { + return tTagNew(pTagVals, 1, true, pTag); + } else { + return parseJsontoTagData(pToken->z, pTagVals, pTag, &pCxt->msg); + } + } - col_id_t t = lastColIdx + 1; - col_id_t index = insFindCol(&sToken, t, nCols, pSchema); - if (index < 0 && t > 0) { - index = insFindCol(&sToken, 0, t, pSchema); - isOrdered = false; + STagVal val = {0}; + int32_t code = + parseTagToken(&pStmt->pSql, pToken, pTagSchema, pStmt->pTableMeta->tableInfo.precision, &val, &pCxt->msg); + if (TSDB_CODE_SUCCESS == code) { + taosArrayPush(pTagVals, &val); + } + + return code; +} + +static void buildCreateTbReq(SVnodeModifOpStmt* pStmt, STag* pTag, SArray* pTagName) { + insBuildCreateTbReq(&pStmt->createTblReq, pStmt->targetTableName.tname, pTag, pStmt->pTableMeta->suid, + pStmt->usingTableName.tname, pTagName, pStmt->pTableMeta->tableInfo.numOfTags); +} + +static int32_t checkAndTrimValue(SToken* pToken, char* tmpTokenBuf, SMsgBuf* pMsgBuf) { + if ((pToken->type != TK_NOW && pToken->type != TK_TODAY && pToken->type != TK_NK_INTEGER && + pToken->type != TK_NK_STRING && pToken->type != TK_NK_FLOAT && pToken->type != TK_NK_BOOL && + pToken->type != TK_NULL && pToken->type != TK_NK_HEX && pToken->type != TK_NK_OCT && + pToken->type != TK_NK_BIN) || + (pToken->n == 0) || (pToken->type == TK_NK_RP)) { + return buildSyntaxErrMsg(pMsgBuf, "invalid data or symbol", pToken->z); + } + + // Remove quotation marks + if (TK_NK_STRING == pToken->type) { + if (pToken->n >= TSDB_MAX_BYTES_PER_ROW) { + return buildSyntaxErrMsg(pMsgBuf, "too long string", pToken->z); } - if (index < 0) { - return generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_INVALID_COLUMN, sToken.z); + + int32_t len = trimString(pToken->z, pToken->n, tmpTokenBuf, TSDB_MAX_BYTES_PER_ROW); + pToken->z = tmpTokenBuf; + pToken->n = len; + } + + return TSDB_CODE_SUCCESS; +} + +// pSql -> tag1_value, ...) +static int32_t parseTagsClauseImpl(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + int32_t code = TSDB_CODE_SUCCESS; + SSchema* pSchema = getTableTagSchema(pStmt->pTableMeta); + SArray* pTagVals = taosArrayInit(pCxt->tags.numOfBound, sizeof(STagVal)); + SArray* pTagName = taosArrayInit(8, TSDB_COL_NAME_LEN); + SToken token; + bool isParseBindParam = false; + bool isJson = false; + STag* pTag = NULL; + for (int i = 0; TSDB_CODE_SUCCESS == code && i < pCxt->tags.numOfBound; ++i) { + NEXT_TOKEN_WITH_PREV(pStmt->pSql, token); + + if (token.type == TK_NK_QUESTION) { + isParseBindParam = true; + if (NULL == pCxt->pComCxt->pStmtCb) { + code = buildSyntaxErrMsg(&pCxt->msg, "? only used in stmt", token.z); + break; + } + + continue; } - if (pColList->cols[index].valStat == VAL_STAT_HAS) { - return buildSyntaxErrMsg(&pCxt->msg, "duplicated column name", sToken.z); + + if (isParseBindParam) { + code = buildInvalidOperationMsg(&pCxt->msg, "no mix usage for ? and tag values"); + break; } - lastColIdx = index; - pColList->cols[index].valStat = VAL_STAT_HAS; - pColList->boundColumns[pColList->numOfBound] = index; - ++pColList->numOfBound; - switch (pSchema[t].type) { - case TSDB_DATA_TYPE_BINARY: - pColList->boundNullLen += (sizeof(VarDataOffsetT) + VARSTR_HEADER_SIZE + CHAR_BYTES); - break; - case TSDB_DATA_TYPE_NCHAR: - pColList->boundNullLen += (sizeof(VarDataOffsetT) + VARSTR_HEADER_SIZE + TSDB_NCHAR_SIZE); - break; - default: - pColList->boundNullLen += TYPE_BYTES[pSchema[t].type]; - break; + + SSchema* pTagSchema = &pSchema[pCxt->tags.boundColumns[i]]; + isJson = pTagSchema->type == TSDB_DATA_TYPE_JSON; + code = checkAndTrimValue(&token, pCxt->tmpTokenBuf, &pCxt->msg); + if (TSDB_CODE_SUCCESS == code) { + code = parseTagValue(pCxt, pStmt, pTagSchema, &token, pTagName, pTagVals, &pTag); } } - pColList->orderStatus = isOrdered ? ORDER_STATUS_ORDERED : ORDER_STATUS_DISORDERED; + if (TSDB_CODE_SUCCESS == code && !isParseBindParam && !isJson) { + code = tTagNew(pTagVals, 1, false, &pTag); + } - if (!isOrdered) { - pColList->colIdxInfo = taosMemoryCalloc(pColList->numOfBound, sizeof(SBoundIdxInfo)); - if (NULL == pColList->colIdxInfo) { - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - SBoundIdxInfo* pColIdx = pColList->colIdxInfo; - for (col_id_t i = 0; i < pColList->numOfBound; ++i) { - pColIdx[i].schemaColIdx = pColList->boundColumns[i]; - pColIdx[i].boundIdx = i; + if (TSDB_CODE_SUCCESS == code && !isParseBindParam) { + buildCreateTbReq(pStmt, pTag, pTagName); + pTag = NULL; + } + + for (int i = 0; i < taosArrayGetSize(pTagVals); ++i) { + STagVal* p = (STagVal*)taosArrayGet(pTagVals, i); + if (IS_VAR_DATA_TYPE(p->type)) { + taosMemoryFreeClear(p->pData); } - taosSort(pColIdx, pColList->numOfBound, sizeof(SBoundIdxInfo), insSchemaIdxCompar); - for (col_id_t i = 0; i < pColList->numOfBound; ++i) { - pColIdx[i].finalIdx = i; + } + taosArrayDestroy(pTagVals); + taosArrayDestroy(pTagName); + tTagFree(pTag); + return code; +} + +// input pStmt->pSql: TAGS (tag1_value, ...) [table_options] ... +// output pStmt->pSql: [table_options] ... +static int32_t parseTagsClause(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + SToken token; + NEXT_TOKEN(pStmt->pSql, token); + if (TK_TAGS != token.type) { + return buildSyntaxErrMsg(&pCxt->msg, "TAGS is expected", token.z); + } + + NEXT_TOKEN(pStmt->pSql, token); + if (TK_NK_LP != token.type) { + return buildSyntaxErrMsg(&pCxt->msg, "( is expected", token.z); + } + + int32_t code = parseTagsClauseImpl(pCxt, pStmt); + if (TSDB_CODE_SUCCESS == code) { + NEXT_VALID_TOKEN(pStmt->pSql, token); + if (TK_NK_COMMA == token.type) { + code = generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_TAGS_NOT_MATCHED); + } else if (TK_NK_RP != token.type) { + code = buildSyntaxErrMsg(&pCxt->msg, ") is expected", token.z); } - taosSort(pColIdx, pColList->numOfBound, sizeof(SBoundIdxInfo), insBoundIdxCompar); } + return code; +} - if (pColList->numOfCols > pColList->numOfBound) { - memset(&pColList->boundColumns[pColList->numOfBound], 0, - sizeof(col_id_t) * (pColList->numOfCols - pColList->numOfBound)); +static int32_t storeTableMeta(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + pStmt->pTableMeta->suid = pStmt->pTableMeta->uid; + pStmt->pTableMeta->uid = pStmt->totalTbNum; + pStmt->pTableMeta->tableType = TSDB_CHILD_TABLE; + + STableMeta* pBackup = NULL; + if (TSDB_CODE_SUCCESS != cloneTableMeta(pStmt->pTableMeta, &pBackup)) { + return TSDB_CODE_OUT_OF_MEMORY; } + char tbFName[TSDB_TABLE_FNAME_LEN]; + tNameExtractFullName(&pStmt->targetTableName, tbFName); + return taosHashPut(pStmt->pSubTableHashObj, tbFName, strlen(tbFName), &pBackup, POINTER_BYTES); +} + +static int32_t parseTableOptions(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + do { + int32_t index = 0; + SToken token; + NEXT_TOKEN_KEEP_SQL(pStmt->pSql, token, index); + if (TK_TTL == token.type) { + pStmt->pSql += index; + NEXT_TOKEN_WITH_PREV(pStmt->pSql, token); + if (TK_NK_INTEGER != token.type) { + return buildSyntaxErrMsg(&pCxt->msg, "Invalid option ttl", token.z); + } + pStmt->createTblReq.ttl = taosStr2Int32(token.z, NULL, 10); + if (pStmt->createTblReq.ttl < 0) { + return buildSyntaxErrMsg(&pCxt->msg, "Invalid option ttl", token.z); + } + } else if (TK_COMMENT == token.type) { + pStmt->pSql += index; + NEXT_TOKEN(pStmt->pSql, token); + if (TK_NK_STRING != token.type) { + return buildSyntaxErrMsg(&pCxt->msg, "Invalid option comment", token.z); + } + if (token.n >= TSDB_TB_COMMENT_LEN) { + return buildSyntaxErrMsg(&pCxt->msg, "comment too long", token.z); + } + int32_t len = trimString(token.z, token.n, pCxt->tmpTokenBuf, TSDB_TB_COMMENT_LEN); + pStmt->createTblReq.comment = strndup(pCxt->tmpTokenBuf, len); + if (NULL == pStmt->createTblReq.comment) { + return TSDB_CODE_OUT_OF_MEMORY; + } + pStmt->createTblReq.commentLen = len; + } else { + break; + } + } while (1); return TSDB_CODE_SUCCESS; } -static int32_t parseTagToken(char** end, SToken* pToken, SSchema* pSchema, int16_t timePrec, STagVal* val, - SMsgBuf* pMsgBuf) { - int64_t iv; - uint64_t uv; - char* endptr = NULL; +// input pStmt->pSql: +// 1. [(tag1_name, ...)] ... +// 2. VALUES ... | FILE ... +// output pStmt->pSql: +// 1. [(field1_name, ...)] +// 2. VALUES ... | FILE ... +static int32_t parseUsingClauseBottom(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + if (!pStmt->usingTableProcessing || pCxt->usingDuplicateTable) { + return TSDB_CODE_SUCCESS; + } - if (isNullValue(pSchema->type, pToken)) { - if (TSDB_DATA_TYPE_TIMESTAMP == pSchema->type && PRIMARYKEY_TIMESTAMP_COL_ID == pSchema->colId) { - return buildSyntaxErrMsg(pMsgBuf, "primary timestamp should not be null", pToken->z); + int32_t code = parseBoundTagsClause(pCxt, pStmt); + if (TSDB_CODE_SUCCESS == code) { + code = parseTagsClause(pCxt, pStmt); + } + if (TSDB_CODE_SUCCESS == code) { + code = parseTableOptions(pCxt, pStmt); + } + + return code; +} + +static int32_t checkAuth(SParseContext* pCxt, SName* pTbName, bool* pMissCache) { + char dbFName[TSDB_DB_FNAME_LEN]; + tNameGetFullDbName(pTbName, dbFName); + int32_t code = TSDB_CODE_SUCCESS; + bool pass = true; + bool exists = true; + if (pCxt->async) { + code = catalogChkAuthFromCache(pCxt->pCatalog, pCxt->pUser, dbFName, AUTH_TYPE_WRITE, &pass, &exists); + } else { + SRequestConnInfo conn = {.pTrans = pCxt->pTransporter, + .requestId = pCxt->requestId, + .requestObjRefId = pCxt->requestRid, + .mgmtEps = pCxt->mgmtEpSet}; + code = catalogChkAuth(pCxt->pCatalog, &conn, pCxt->pUser, dbFName, AUTH_TYPE_WRITE, &pass); + } + if (TSDB_CODE_SUCCESS == code) { + if (!exists) { + *pMissCache = true; + } else if (!pass) { + code = TSDB_CODE_PAR_PERMISSION_DENIED; } + } + return code; +} +static int32_t getTableMeta(SInsertParseContext* pCxt, SName* pTbName, bool isStb, STableMeta** pTableMeta, + bool* pMissCache) { + SParseContext* pComCxt = pCxt->pComCxt; + int32_t code = TSDB_CODE_SUCCESS; + if (pComCxt->async) { + if (isStb) { + code = catalogGetCachedSTableMeta(pComCxt->pCatalog, pTbName, pTableMeta); + } else { + code = catalogGetCachedTableMeta(pComCxt->pCatalog, pTbName, pTableMeta); + } + } else { + SRequestConnInfo conn = {.pTrans = pComCxt->pTransporter, + .requestId = pComCxt->requestId, + .requestObjRefId = pComCxt->requestRid, + .mgmtEps = pComCxt->mgmtEpSet}; + if (isStb) { + code = catalogGetSTableMeta(pComCxt->pCatalog, &conn, pTbName, pTableMeta); + } else { + code = catalogGetTableMeta(pComCxt->pCatalog, &conn, pTbName, pTableMeta); + } + } + if (TSDB_CODE_SUCCESS == code) { + if (NULL == *pTableMeta) { + *pMissCache = true; + } else if (isStb && TSDB_SUPER_TABLE != (*pTableMeta)->tableType) { + code = buildInvalidOperationMsg(&pCxt->msg, "create table only from super table is allowed"); + } + } + return code; +} + +static int32_t getTableVgroup(SParseContext* pCxt, SVnodeModifOpStmt* pStmt, bool isStb, bool* pMissCache) { + int32_t code = TSDB_CODE_SUCCESS; + SVgroupInfo vg; + bool exists = true; + if (pCxt->async) { + code = catalogGetCachedTableHashVgroup(pCxt->pCatalog, &pStmt->targetTableName, &vg, &exists); + } else { + SRequestConnInfo conn = {.pTrans = pCxt->pTransporter, + .requestId = pCxt->requestId, + .requestObjRefId = pCxt->requestRid, + .mgmtEps = pCxt->mgmtEpSet}; + code = catalogGetTableHashVgroup(pCxt->pCatalog, &conn, &pStmt->targetTableName, &vg); + } + if (TSDB_CODE_SUCCESS == code) { + if (exists) { + if (isStb) { + pStmt->pTableMeta->vgId = vg.vgId; + } + code = taosHashPut(pStmt->pVgroupsHashObj, (const char*)&vg.vgId, sizeof(vg.vgId), (char*)&vg, sizeof(vg)); + } + *pMissCache = !exists; + } + return code; +} + +static int32_t getTargetTableSchema(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + int32_t code = checkAuth(pCxt->pComCxt, &pStmt->targetTableName, &pCxt->missCache); + if (TSDB_CODE_SUCCESS == code && !pCxt->missCache) { + code = getTableMeta(pCxt, &pStmt->targetTableName, false, &pStmt->pTableMeta, &pCxt->missCache); + } + if (TSDB_CODE_SUCCESS == code && !pCxt->missCache) { + code = getTableVgroup(pCxt->pComCxt, pStmt, false, &pCxt->missCache); + } + return code; +} + +static int32_t preParseUsingTableName(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt, SToken* pTbName) { + return insCreateSName(&pStmt->usingTableName, pTbName, pCxt->pComCxt->acctId, pCxt->pComCxt->db, &pCxt->msg); +} + +static int32_t getUsingTableSchema(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + int32_t code = checkAuth(pCxt->pComCxt, &pStmt->targetTableName, &pCxt->missCache); + if (TSDB_CODE_SUCCESS == code && !pCxt->missCache) { + code = getTableMeta(pCxt, &pStmt->usingTableName, true, &pStmt->pTableMeta, &pCxt->missCache); + } + if (TSDB_CODE_SUCCESS == code && !pCxt->missCache) { + code = getTableVgroup(pCxt->pComCxt, pStmt, true, &pCxt->missCache); + } + return code; +} + +static int32_t parseUsingTableNameImpl(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + SToken token; + NEXT_TOKEN(pStmt->pSql, token); + int32_t code = preParseUsingTableName(pCxt, pStmt, &token); + if (TSDB_CODE_SUCCESS == code) { + code = getUsingTableSchema(pCxt, pStmt); + } + if (TSDB_CODE_SUCCESS == code && !pCxt->missCache) { + code = storeTableMeta(pCxt, pStmt); + } + return code; +} + +// input pStmt->pSql: +// 1(care). [USING stb_name [(tag1_name, ...)] TAGS (tag1_value, ...) [table_options]] ... +// 2. VALUES ... | FILE ... +// output pStmt->pSql: +// 1. [(tag1_name, ...)] TAGS (tag1_value, ...) [table_options]] ... +// 2. VALUES ... | FILE ... +static int32_t parseUsingTableName(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + SToken token; + int32_t index = 0; + NEXT_TOKEN_KEEP_SQL(pStmt->pSql, token, index); + if (TK_USING != token.type) { + return getTargetTableSchema(pCxt, pStmt); + } + + pStmt->usingTableProcessing = true; + // pStmt->pSql -> stb_name [(tag1_name, ...) + pStmt->pSql += index; + int32_t code = parseDuplicateUsingClause(pCxt, pStmt, &pCxt->usingDuplicateTable); + if (TSDB_CODE_SUCCESS == code && !pCxt->usingDuplicateTable) { + return parseUsingTableNameImpl(pCxt, pStmt); + } + return code; +} + +static int32_t preParseTargetTableName(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt, SToken* pTbName) { + return insCreateSName(&pStmt->targetTableName, pTbName, pCxt->pComCxt->acctId, pCxt->pComCxt->db, &pCxt->msg); +} + +// input pStmt->pSql: +// 1(care). [(field1_name, ...)] ... +// 2. [ USING ... ] ... +// 3. VALUES ... | FILE ... +// output pStmt->pSql: +// 1. [ USING ... ] ... +// 2. VALUES ... | FILE ... +static int32_t preParseBoundColumnsClause(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + SToken token; + int32_t index = 0; + NEXT_TOKEN_KEEP_SQL(pStmt->pSql, token, index); + if (TK_NK_LP != token.type) { return TSDB_CODE_SUCCESS; } - // strcpy(val->colName, pSchema->name); - val->cid = pSchema->colId; - val->type = pSchema->type; + // pStmt->pSql -> field1_name, ...) + pStmt->pSql += index; + pStmt->pBoundCols = pStmt->pSql; + return skipParentheses(pCxt, &pStmt->pSql); +} + +static int32_t getTableDataBlocks(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt, STableDataBlocks** pDataBuf) { + if (pCxt->pComCxt->async) { + return insGetDataBlockFromList(pStmt->pTableBlockHashObj, &pStmt->pTableMeta->uid, sizeof(pStmt->pTableMeta->uid), + TSDB_DEFAULT_PAYLOAD_SIZE, sizeof(SSubmitBlk), + getTableInfo(pStmt->pTableMeta).rowSize, pStmt->pTableMeta, pDataBuf, NULL, + &pStmt->createTblReq); + } + char tbFName[TSDB_TABLE_FNAME_LEN]; + tNameExtractFullName(&pStmt->targetTableName, tbFName); + return insGetDataBlockFromList(pStmt->pTableBlockHashObj, tbFName, strlen(tbFName), TSDB_DEFAULT_PAYLOAD_SIZE, + sizeof(SSubmitBlk), getTableInfo(pStmt->pTableMeta).rowSize, pStmt->pTableMeta, + pDataBuf, NULL, &pStmt->createTblReq); +} + +static int32_t parseBoundColumnsClause(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt, + STableDataBlocks* pDataBuf) { + SToken token; + int32_t index = 0; + NEXT_TOKEN_KEEP_SQL(pStmt->pSql, token, index); + if (TK_NK_LP == token.type) { + pStmt->pSql += index; + if (NULL != pStmt->pBoundCols) { + return buildSyntaxErrMsg(&pCxt->msg, "keyword VALUES or FILE is expected", token.z); + } + // pStmt->pSql -> field1_name, ...) + return parseBoundColumns(pCxt, &pStmt->pSql, &pDataBuf->boundColumnInfo, getTableColumnSchema(pStmt->pTableMeta)); + } + + if (NULL != pStmt->pBoundCols) { + return parseBoundColumns(pCxt, &pStmt->pBoundCols, &pDataBuf->boundColumnInfo, + getTableColumnSchema(pStmt->pTableMeta)); + } + + return TSDB_CODE_SUCCESS; +} + +// input pStmt->pSql: +// 1. [(tag1_name, ...)] ... +// 2. VALUES ... | FILE ... +// output pStmt->pSql: VALUES ... | FILE ... +static int32_t parseSchemaClauseBottom(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt, + STableDataBlocks** pDataBuf) { + int32_t code = parseUsingClauseBottom(pCxt, pStmt); + if (TSDB_CODE_SUCCESS == code) { + code = getTableDataBlocks(pCxt, pStmt, pDataBuf); + } + if (TSDB_CODE_SUCCESS == code) { + code = parseBoundColumnsClause(pCxt, pStmt, *pDataBuf); + } + return code; +} + +// input pStmt->pSql: [(field1_name, ...)] [ USING ... ] VALUES ... | FILE ... +// output pStmt->pSql: +// 1. [(tag1_name, ...)] ... +// 2. VALUES ... | FILE ... +static int32_t parseSchemaClauseTop(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt, SToken* pTbName) { + int32_t code = preParseTargetTableName(pCxt, pStmt, pTbName); + if (TSDB_CODE_SUCCESS == code) { + // option: [(field1_name, ...)] + code = preParseBoundColumnsClause(pCxt, pStmt); + } + if (TSDB_CODE_SUCCESS == code) { + // option: [USING stb_name] + code = parseUsingTableName(pCxt, pStmt); + } + return code; +} + +static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql, SToken* pToken, SSchema* pSchema, + int16_t timePrec, _row_append_fn_t func, void* param) { + int64_t iv; + uint64_t uv; + char* endptr = NULL; switch (pSchema->type) { case TSDB_DATA_TYPE_BOOL: { if ((pToken->type == TK_NK_BOOL || pToken->type == TK_NK_STRING) && (pToken->n != 0)) { if (strncmp(pToken->z, "true", pToken->n) == 0) { - *(int8_t*)(&val->i64) = TRUE_VALUE; + return func(&pCxt->msg, &TRUE_VALUE, pSchema->bytes, param); } else if (strncmp(pToken->z, "false", pToken->n) == 0) { - *(int8_t*)(&val->i64) = FALSE_VALUE; + return func(&pCxt->msg, &FALSE_VALUE, pSchema->bytes, param); } else { - return buildSyntaxErrMsg(pMsgBuf, "invalid bool data", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "invalid bool data", pToken->z); } } else if (pToken->type == TK_NK_INTEGER) { - *(int8_t*)(&val->i64) = ((taosStr2Int64(pToken->z, NULL, 10) == 0) ? FALSE_VALUE : TRUE_VALUE); + return func(&pCxt->msg, ((taosStr2Int64(pToken->z, NULL, 10) == 0) ? &FALSE_VALUE : &TRUE_VALUE), + pSchema->bytes, param); } else if (pToken->type == TK_NK_FLOAT) { - *(int8_t*)(&val->i64) = ((taosStr2Double(pToken->z, NULL) == 0) ? FALSE_VALUE : TRUE_VALUE); + return func(&pCxt->msg, ((taosStr2Double(pToken->z, NULL) == 0) ? &FALSE_VALUE : &TRUE_VALUE), pSchema->bytes, + param); } else { - return buildSyntaxErrMsg(pMsgBuf, "invalid bool data", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "invalid bool data", pToken->z); } - break; } case TSDB_DATA_TYPE_TINYINT: { if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &iv)) { - return buildSyntaxErrMsg(pMsgBuf, "invalid tinyint data", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "invalid tinyint data", pToken->z); } else if (!IS_VALID_TINYINT(iv)) { - return buildSyntaxErrMsg(pMsgBuf, "tinyint data overflow", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "tinyint data overflow", pToken->z); } - *(int8_t*)(&val->i64) = iv; - break; + uint8_t tmpVal = (uint8_t)iv; + return func(&pCxt->msg, &tmpVal, pSchema->bytes, param); } case TSDB_DATA_TYPE_UTINYINT: { if (TSDB_CODE_SUCCESS != toUInteger(pToken->z, pToken->n, 10, &uv)) { - return buildSyntaxErrMsg(pMsgBuf, "invalid unsigned tinyint data", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned tinyint data", pToken->z); } else if (uv > UINT8_MAX) { - return buildSyntaxErrMsg(pMsgBuf, "unsigned tinyint data overflow", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "unsigned tinyint data overflow", pToken->z); } - *(uint8_t*)(&val->i64) = uv; - break; + uint8_t tmpVal = (uint8_t)uv; + return func(&pCxt->msg, &tmpVal, pSchema->bytes, param); } case TSDB_DATA_TYPE_SMALLINT: { if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &iv)) { - return buildSyntaxErrMsg(pMsgBuf, "invalid smallint data", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "invalid smallint data", pToken->z); } else if (!IS_VALID_SMALLINT(iv)) { - return buildSyntaxErrMsg(pMsgBuf, "smallint data overflow", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "smallint data overflow", pToken->z); } - *(int16_t*)(&val->i64) = iv; - break; + int16_t tmpVal = (int16_t)iv; + return func(&pCxt->msg, &tmpVal, pSchema->bytes, param); } case TSDB_DATA_TYPE_USMALLINT: { if (TSDB_CODE_SUCCESS != toUInteger(pToken->z, pToken->n, 10, &uv)) { - return buildSyntaxErrMsg(pMsgBuf, "invalid unsigned smallint data", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned smallint data", pToken->z); } else if (uv > UINT16_MAX) { - return buildSyntaxErrMsg(pMsgBuf, "unsigned smallint data overflow", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "unsigned smallint data overflow", pToken->z); } - *(uint16_t*)(&val->i64) = uv; - break; + uint16_t tmpVal = (uint16_t)uv; + return func(&pCxt->msg, &tmpVal, pSchema->bytes, param); } case TSDB_DATA_TYPE_INT: { if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &iv)) { - return buildSyntaxErrMsg(pMsgBuf, "invalid int data", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "invalid int data", pToken->z); } else if (!IS_VALID_INT(iv)) { - return buildSyntaxErrMsg(pMsgBuf, "int data overflow", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "int data overflow", pToken->z); } - *(int32_t*)(&val->i64) = iv; - break; + int32_t tmpVal = (int32_t)iv; + return func(&pCxt->msg, &tmpVal, pSchema->bytes, param); } case TSDB_DATA_TYPE_UINT: { if (TSDB_CODE_SUCCESS != toUInteger(pToken->z, pToken->n, 10, &uv)) { - return buildSyntaxErrMsg(pMsgBuf, "invalid unsigned int data", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned int data", pToken->z); } else if (uv > UINT32_MAX) { - return buildSyntaxErrMsg(pMsgBuf, "unsigned int data overflow", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "unsigned int data overflow", pToken->z); } - *(uint32_t*)(&val->i64) = uv; - break; + uint32_t tmpVal = (uint32_t)uv; + return func(&pCxt->msg, &tmpVal, pSchema->bytes, param); } case TSDB_DATA_TYPE_BIGINT: { if (TSDB_CODE_SUCCESS != toInteger(pToken->z, pToken->n, 10, &iv)) { - return buildSyntaxErrMsg(pMsgBuf, "invalid bigint data", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "invalid bigint data", pToken->z); } - val->i64 = iv; - break; + return func(&pCxt->msg, &iv, pSchema->bytes, param); } case TSDB_DATA_TYPE_UBIGINT: { if (TSDB_CODE_SUCCESS != toUInteger(pToken->z, pToken->n, 10, &uv)) { - return buildSyntaxErrMsg(pMsgBuf, "invalid unsigned bigint data", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "invalid unsigned bigint data", pToken->z); } - *(uint64_t*)(&val->i64) = uv; - break; + return func(&pCxt->msg, &uv, pSchema->bytes, param); } case TSDB_DATA_TYPE_FLOAT: { double dv; if (TK_NK_ILLEGAL == toDouble(pToken, &dv, &endptr)) { - return buildSyntaxErrMsg(pMsgBuf, "illegal float data", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "illegal float data", pToken->z); } if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || dv > FLT_MAX || dv < -FLT_MAX || isinf(dv) || isnan(dv)) { - return buildSyntaxErrMsg(pMsgBuf, "illegal float data", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "illegal float data", pToken->z); } - *(float*)(&val->i64) = dv; - break; + float tmpVal = (float)dv; + return func(&pCxt->msg, &tmpVal, pSchema->bytes, param); } case TSDB_DATA_TYPE_DOUBLE: { double dv; if (TK_NK_ILLEGAL == toDouble(pToken, &dv, &endptr)) { - return buildSyntaxErrMsg(pMsgBuf, "illegal double data", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "illegal double data", pToken->z); } if (((dv == HUGE_VAL || dv == -HUGE_VAL) && errno == ERANGE) || isinf(dv) || isnan(dv)) { - return buildSyntaxErrMsg(pMsgBuf, "illegal double data", pToken->z); + return buildSyntaxErrMsg(&pCxt->msg, "illegal double data", pToken->z); } - - *(double*)(&val->i64) = dv; - break; + return func(&pCxt->msg, &dv, pSchema->bytes, param); } case TSDB_DATA_TYPE_BINARY: { // Too long values will raise the invalid sql error message if (pToken->n + VARSTR_HEADER_SIZE > pSchema->bytes) { - return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name); + return generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name); } - val->pData = strdup(pToken->z); - val->nData = pToken->n; - break; + + return func(&pCxt->msg, pToken->z, pToken->n, param); } case TSDB_DATA_TYPE_NCHAR: { - int32_t output = 0; - void* p = taosMemoryCalloc(1, pSchema->bytes - VARSTR_HEADER_SIZE); - if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; - } - if (!taosMbsToUcs4(pToken->z, pToken->n, (TdUcs4*)(p), pSchema->bytes - VARSTR_HEADER_SIZE, &output)) { - if (errno == E2BIG) { - taosMemoryFree(p); - return generateSyntaxErrMsg(pMsgBuf, TSDB_CODE_PAR_VALUE_TOO_LONG, pSchema->name); - } - char buf[512] = {0}; - snprintf(buf, tListLen(buf), " taosMbsToUcs4 error:%s", strerror(errno)); - taosMemoryFree(p); - return buildSyntaxErrMsg(pMsgBuf, buf, pToken->z); + return func(&pCxt->msg, pToken->z, pToken->n, param); + } + case TSDB_DATA_TYPE_JSON: { + if (pToken->n > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) { + return buildSyntaxErrMsg(&pCxt->msg, "json string too long than 4095", pToken->z); } - val->pData = p; - val->nData = output; - break; + return func(&pCxt->msg, pToken->z, pToken->n, param); } case TSDB_DATA_TYPE_TIMESTAMP: { - if (parseTime(end, pToken, timePrec, &iv, pMsgBuf) != TSDB_CODE_SUCCESS) { - return buildSyntaxErrMsg(pMsgBuf, "invalid timestamp", pToken->z); + int64_t tmpVal; + if (parseTime(pSql, pToken, timePrec, &tmpVal, &pCxt->msg) != TSDB_CODE_SUCCESS) { + return buildSyntaxErrMsg(&pCxt->msg, "invalid timestamp", pToken->z); } - val->i64 = iv; - break; + return func(&pCxt->msg, &tmpVal, pSchema->bytes, param); } } - return TSDB_CODE_SUCCESS; + return TSDB_CODE_FAILED; } -// pSql -> tag1_value, ...) -static int32_t parseTagsClause(SInsertParseContext* pCxt, SSchema* pSchema, uint8_t precision, const char* tName) { - int32_t code = TSDB_CODE_SUCCESS; - SArray* pTagVals = taosArrayInit(pCxt->tags.numOfBound, sizeof(STagVal)); - SArray* tagName = taosArrayInit(8, TSDB_COL_NAME_LEN); - SToken sToken; - bool isParseBindParam = false; - bool isJson = false; - STag* pTag = NULL; - for (int i = 0; i < pCxt->tags.numOfBound; ++i) { - NEXT_TOKEN_WITH_PREV(pCxt->pSql, sToken); - - if (sToken.type == TK_NK_QUESTION) { - isParseBindParam = true; - if (NULL == pCxt->pStmtCb) { - code = buildSyntaxErrMsg(&pCxt->msg, "? only used in stmt", sToken.z); - break; - } - - continue; - } - - if (isParseBindParam) { - code = buildInvalidOperationMsg(&pCxt->msg, "no mix usage for ? and tag values"); - break; - } - - SSchema* pTagSchema = &pSchema[pCxt->tags.boundColumns[i]]; - char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW] = {0}; // todo this can be optimize with parse column - code = checkAndTrimValue(&sToken, tmpTokenBuf, &pCxt->msg); - if (TSDB_CODE_SUCCESS == code) { - if (!isNullValue(pTagSchema->type, &sToken)) { - taosArrayPush(tagName, pTagSchema->name); - } - if (pTagSchema->type == TSDB_DATA_TYPE_JSON) { - isJson = true; - if (sToken.n > (TSDB_MAX_JSON_TAG_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) { - code = buildSyntaxErrMsg(&pCxt->msg, "json string too long than 4095", sToken.z); - break; - } - if (isNullValue(pTagSchema->type, &sToken)) { - code = tTagNew(pTagVals, 1, true, &pTag); - } else { - code = parseJsontoTagData(sToken.z, pTagVals, &pTag, &pCxt->msg); - } - } else { - STagVal val = {0}; - code = parseTagToken(&pCxt->pSql, &sToken, pTagSchema, precision, &val, &pCxt->msg); - if (TSDB_CODE_SUCCESS == code) { - taosArrayPush(pTagVals, &val); - } - } - } - if (TSDB_CODE_SUCCESS != code) { - break; +static int32_t parseValueToken(SInsertParseContext* pCxt, const char** pSql, SToken* pToken, SSchema* pSchema, + int16_t timePrec, _row_append_fn_t func, void* param) { + int32_t code = checkAndTrimValue(pToken, pCxt->tmpTokenBuf, &pCxt->msg); + if (TSDB_CODE_SUCCESS == code && isNullValue(pSchema->type, pToken)) { + if (TSDB_DATA_TYPE_TIMESTAMP == pSchema->type && PRIMARYKEY_TIMESTAMP_COL_ID == pSchema->colId) { + return buildSyntaxErrMsg(&pCxt->msg, "primary timestamp should not be null", pToken->z); } - } - - if (TSDB_CODE_SUCCESS == code && !isParseBindParam && !isJson) { - code = tTagNew(pTagVals, 1, false, &pTag); - } - if (TSDB_CODE_SUCCESS == code && !isParseBindParam) { - insBuildCreateTbReq(&pCxt->createTblReq, tName, pTag, pCxt->pTableMeta->suid, pCxt->sTableName, tagName, - pCxt->pTableMeta->tableInfo.numOfTags); - pTag = NULL; - } - - for (int i = 0; i < taosArrayGetSize(pTagVals); ++i) { - STagVal* p = (STagVal*)taosArrayGet(pTagVals, i); - if (IS_VAR_DATA_TYPE(p->type)) { - taosMemoryFreeClear(p->pData); - } + return func(&pCxt->msg, NULL, 0, param); } - taosArrayDestroy(pTagVals); - taosArrayDestroy(tagName); - tTagFree(pTag); - return code; -} -static int32_t storeTableMeta(SInsertParseContext* pCxt, SHashObj* pHash, int32_t tbNo, SName* pTableName, - const char* pName, int32_t len, STableMeta* pMeta) { - SVgroupInfo vg; - CHECK_CODE(getTableVgroup(pCxt, tbNo, pTableName, &vg)); - CHECK_CODE(taosHashPut(pCxt->pVgroupsHashObj, (const char*)&vg.vgId, sizeof(vg.vgId), (char*)&vg, sizeof(vg))); - - pMeta->uid = tbNo; - pMeta->vgId = vg.vgId; - pMeta->tableType = TSDB_CHILD_TABLE; - - STableMeta* pBackup = NULL; - if (TSDB_CODE_SUCCESS != cloneTableMeta(pMeta, &pBackup)) { - return TSDB_CODE_TSC_OUT_OF_MEMORY; + if (TSDB_CODE_SUCCESS == code && IS_NUMERIC_TYPE(pSchema->type) && pToken->n == 0) { + return buildSyntaxErrMsg(&pCxt->msg, "invalid numeric data", pToken->z); } - return taosHashPut(pHash, pName, len, &pBackup, POINTER_BYTES); -} -static int32_t skipParentheses(SInsertParseSyntaxCxt* pCxt) { - SToken sToken; - int32_t expectRightParenthesis = 1; - while (1) { - NEXT_TOKEN(pCxt->pSql, sToken); - if (TK_NK_LP == sToken.type) { - ++expectRightParenthesis; - } else if (TK_NK_RP == sToken.type && 0 == --expectRightParenthesis) { - break; - } - if (0 == sToken.n) { - return buildSyntaxErrMsg(&pCxt->msg, ") expected", NULL); - } + if (TSDB_CODE_SUCCESS == code) { + code = parseValueTokenImpl(pCxt, pSql, pToken, pSchema, timePrec, func, param); } - return TSDB_CODE_SUCCESS; -} - -static int32_t skipBoundColumns(SInsertParseSyntaxCxt* pCxt) { return skipParentheses(pCxt); } - -static int32_t ignoreBoundColumns(SInsertParseContext* pCxt) { - SInsertParseSyntaxCxt cxt = {.pComCxt = pCxt->pComCxt, .pSql = pCxt->pSql, .msg = pCxt->msg, .pMetaCache = NULL}; - int32_t code = skipBoundColumns(&cxt); - pCxt->pSql = cxt.pSql; - return code; -} - -static int32_t skipUsingClause(SInsertParseSyntaxCxt* pCxt); -// pSql -> stb_name [(tag1_name, ...)] TAGS (tag1_value, ...) -static int32_t ignoreAutoCreateTableClause(SInsertParseContext* pCxt) { - SToken sToken; - NEXT_TOKEN(pCxt->pSql, sToken); - SInsertParseSyntaxCxt cxt = {.pComCxt = pCxt->pComCxt, .pSql = pCxt->pSql, .msg = pCxt->msg, .pMetaCache = NULL}; - int32_t code = skipUsingClause(&cxt); - pCxt->pSql = cxt.pSql; return code; } -static int32_t parseTableOptions(SInsertParseContext* pCxt) { - do { - int32_t index = 0; - SToken sToken; - NEXT_TOKEN_KEEP_SQL(pCxt->pSql, sToken, index); - if (TK_TTL == sToken.type) { - pCxt->pSql += index; - NEXT_TOKEN_WITH_PREV(pCxt->pSql, sToken); - if (TK_NK_INTEGER != sToken.type) { - return buildSyntaxErrMsg(&pCxt->msg, "Invalid option ttl", sToken.z); - } - pCxt->createTblReq.ttl = taosStr2Int32(sToken.z, NULL, 10); - if (pCxt->createTblReq.ttl < 0) { - return buildSyntaxErrMsg(&pCxt->msg, "Invalid option ttl", sToken.z); - } - } else if (TK_COMMENT == sToken.type) { - pCxt->pSql += index; - NEXT_TOKEN(pCxt->pSql, sToken); - if (TK_NK_STRING != sToken.type) { - return buildSyntaxErrMsg(&pCxt->msg, "Invalid option comment", sToken.z); - } - if (sToken.n >= TSDB_TB_COMMENT_LEN) { - return buildSyntaxErrMsg(&pCxt->msg, "comment too long", sToken.z); - } - int32_t len = trimString(sToken.z, sToken.n, pCxt->tmpTokenBuf, TSDB_TB_COMMENT_LEN); - pCxt->createTblReq.comment = strndup(pCxt->tmpTokenBuf, len); - if (NULL == pCxt->createTblReq.comment) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCxt->createTblReq.commentLen = len; - } else { - break; - } - } while (1); - return TSDB_CODE_SUCCESS; -} - -// pSql -> stb_name [(tag1_name, ...)] TAGS (tag1_value, ...) -static int32_t parseUsingClause(SInsertParseContext* pCxt, int32_t tbNo, SName* name, char* tbFName) { - int32_t len = strlen(tbFName); - STableMeta** pMeta = taosHashGet(pCxt->pSubTableHashObj, tbFName, len); - if (NULL != pMeta) { - CHECK_CODE(ignoreAutoCreateTableClause(pCxt)); - return cloneTableMeta(*pMeta, &pCxt->pTableMeta); - } - - SToken sToken; - // pSql -> stb_name [(tag1_name, ...)] TAGS (tag1_value, ...) - NEXT_TOKEN(pCxt->pSql, sToken); - - SName sname; - CHECK_CODE(insCreateSName(&sname, &sToken, pCxt->pComCxt->acctId, pCxt->pComCxt->db, &pCxt->msg)); - char dbFName[TSDB_DB_FNAME_LEN]; - tNameGetFullDbName(&sname, dbFName); - strcpy(pCxt->sTableName, sname.tname); - - CHECK_CODE(getSTableMeta(pCxt, tbNo, &sname)); - if (TSDB_SUPER_TABLE != pCxt->pTableMeta->tableType) { - return buildInvalidOperationMsg(&pCxt->msg, "create table only from super table is allowed"); - } - CHECK_CODE(storeTableMeta(pCxt, pCxt->pSubTableHashObj, tbNo, name, tbFName, len, pCxt->pTableMeta)); - - SSchema* pTagsSchema = getTableTagSchema(pCxt->pTableMeta); - insSetBoundColumnInfo(&pCxt->tags, pTagsSchema, getNumOfTags(pCxt->pTableMeta)); - - // pSql -> [(tag1_name, ...)] TAGS (tag1_value, ...) - NEXT_TOKEN(pCxt->pSql, sToken); - if (TK_NK_LP == sToken.type) { - CHECK_CODE(parseBoundColumns(pCxt, &pCxt->tags, pTagsSchema)); - NEXT_TOKEN(pCxt->pSql, sToken); - } - - if (TK_TAGS != sToken.type) { - return buildSyntaxErrMsg(&pCxt->msg, "TAGS is expected", sToken.z); - } - // pSql -> (tag1_value, ...) - NEXT_TOKEN(pCxt->pSql, sToken); - if (TK_NK_LP != sToken.type) { - return buildSyntaxErrMsg(&pCxt->msg, "( is expected", sToken.z); - } - CHECK_CODE(parseTagsClause(pCxt, pTagsSchema, getTableInfo(pCxt->pTableMeta).precision, name->tname)); - NEXT_VALID_TOKEN(pCxt->pSql, sToken); - if (TK_NK_COMMA == sToken.type) { - return generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_TAGS_NOT_MATCHED); - } else if (TK_NK_RP != sToken.type) { - return buildSyntaxErrMsg(&pCxt->msg, ") is expected", sToken.z); - } - - return parseTableOptions(pCxt); -} - -static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, int16_t timePrec, bool* gotRow, - char* tmpTokenBuf) { - SParsedDataColInfo* spd = &pDataBlocks->boundColumnInfo; - SRowBuilder* pBuilder = &pDataBlocks->rowBuilder; - STSRow* row = (STSRow*)(pDataBlocks->pData + pDataBlocks->size); // skip the SSubmitBlk header +static int parseOneRow(SInsertParseContext* pCxt, const char** pSql, STableDataBlocks* pDataBuf, bool* pGotRow, + SToken* pToken) { + SRowBuilder* pBuilder = &pDataBuf->rowBuilder; + STSRow* row = (STSRow*)(pDataBuf->pData + pDataBuf->size); // skip the SSubmitBlk header + SParsedDataColInfo* pCols = &pDataBuf->boundColumnInfo; + bool isParseBindParam = false; + SSchema* pSchemas = getTableColumnSchema(pDataBuf->pTableMeta); + SMemParam param = {.rb = pBuilder}; - tdSRowResetBuf(pBuilder, row); - - bool isParseBindParam = false; - SSchema* schema = getTableColumnSchema(pDataBlocks->pTableMeta); - SMemParam param = {.rb = pBuilder}; - SToken sToken = {0}; + int32_t code = tdSRowResetBuf(pBuilder, row); // 1. set the parsed value from sql string - for (int i = 0; i < spd->numOfBound; ++i) { - NEXT_TOKEN_WITH_PREV(pCxt->pSql, sToken); - SSchema* pSchema = &schema[spd->boundColumns[i]]; + for (int i = 0; i < pCols->numOfBound && TSDB_CODE_SUCCESS == code; ++i) { + NEXT_TOKEN_WITH_PREV(*pSql, *pToken); + SSchema* pSchema = &pSchemas[pCols->boundColumns[i]]; - if (sToken.type == TK_NK_QUESTION) { + if (pToken->type == TK_NK_QUESTION) { isParseBindParam = true; - if (NULL == pCxt->pStmtCb) { - return buildSyntaxErrMsg(&pCxt->msg, "? only used in stmt", sToken.z); + if (NULL == pCxt->pComCxt->pStmtCb) { + code = buildSyntaxErrMsg(&pCxt->msg, "? only used in stmt", pToken->z); } - continue; } - if (TK_NK_RP == sToken.type) { - return generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_INVALID_COLUMNS_NUM); + if (TSDB_CODE_SUCCESS == code && TK_NK_RP == pToken->type) { + code = generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_INVALID_COLUMNS_NUM); } - if (isParseBindParam) { - return buildInvalidOperationMsg(&pCxt->msg, "no mix usage for ? and values"); + if (TSDB_CODE_SUCCESS == code && isParseBindParam) { + code = buildInvalidOperationMsg(&pCxt->msg, "no mix usage for ? and values"); } - param.schema = pSchema; - insGetSTSRowAppendInfo(pBuilder->rowType, spd, i, ¶m.toffset, ¶m.colIdx); - CHECK_CODE( - parseValueToken(&pCxt->pSql, &sToken, pSchema, timePrec, tmpTokenBuf, insMemRowAppend, ¶m, &pCxt->msg)); + if (TSDB_CODE_SUCCESS == code) { + param.schema = pSchema; + insGetSTSRowAppendInfo(pBuilder->rowType, pCols, i, ¶m.toffset, ¶m.colIdx); + code = parseValueToken(pCxt, pSql, pToken, pSchema, getTableInfo(pDataBuf->pTableMeta).precision, insMemRowAppend, + ¶m); + } - if (i < spd->numOfBound - 1) { - NEXT_VALID_TOKEN(pCxt->pSql, sToken); - if (TK_NK_COMMA != sToken.type) { - return buildSyntaxErrMsg(&pCxt->msg, ", expected", sToken.z); + if (TSDB_CODE_SUCCESS == code && i < pCols->numOfBound - 1) { + NEXT_VALID_TOKEN(*pSql, *pToken); + if (TK_NK_COMMA != pToken->type) { + code = buildSyntaxErrMsg(&pCxt->msg, ", expected", pToken->z); } } } - TSKEY tsKey = TD_ROW_KEY(row); - insCheckTimestamp(pDataBlocks, (const char*)&tsKey); + if (TSDB_CODE_SUCCESS == code) { + TSKEY tsKey = TD_ROW_KEY(row); + code = insCheckTimestamp(pDataBuf, (const char*)&tsKey); + } - if (!isParseBindParam) { + if (TSDB_CODE_SUCCESS == code && !isParseBindParam) { // set the null value for the columns that do not assign values - if ((spd->numOfBound < spd->numOfCols) && TD_IS_TP_ROW(row)) { + if ((pCols->numOfBound < pCols->numOfCols) && TD_IS_TP_ROW(row)) { pBuilder->hasNone = true; } tdSRowEnd(pBuilder); - *gotRow = true; + *pGotRow = true; #ifdef TD_DEBUG_PRINT_ROW STSchema* pSTSchema = tdGetSTSChemaFromSSChema(schema, spd->numOfCols, 1); @@ -981,8 +1226,7 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, #endif } - // *len = pBuilder->extendedRowSize; - return TSDB_CODE_SUCCESS; + return code; } static int32_t allocateMemIfNeed(STableDataBlocks* pDataBlock, int32_t rowSize, int32_t* numOfRows) { @@ -1014,84 +1258,82 @@ static int32_t allocateMemIfNeed(STableDataBlocks* pDataBlock, int32_t rowSize, } // pSql -> (field1_value, ...) [(field1_value2, ...) ...] -static int32_t parseValues(SInsertParseContext* pCxt, STableDataBlocks* pDataBlock, int maxRows, int32_t* numOfRows) { - STableComInfo tinfo = getTableInfo(pDataBlock->pTableMeta); - int32_t extendedRowSize = insGetExtendedRowSize(pDataBlock); - CHECK_CODE( - insInitRowBuilder(&pDataBlock->rowBuilder, pDataBlock->pTableMeta->sversion, &pDataBlock->boundColumnInfo)); - - (*numOfRows) = 0; - // char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW] = {0}; // used for deleting Escape character: \\, \', \" - SToken sToken; - while (1) { +static int32_t parseValues(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt, STableDataBlocks* pDataBuf, + int32_t maxRows, int32_t* pNumOfRows, SToken* pToken) { + int32_t code = insInitRowBuilder(&pDataBuf->rowBuilder, pDataBuf->pTableMeta->sversion, &pDataBuf->boundColumnInfo); + + int32_t extendedRowSize = insGetExtendedRowSize(pDataBuf); + (*pNumOfRows) = 0; + while (TSDB_CODE_SUCCESS == code) { int32_t index = 0; - NEXT_TOKEN_KEEP_SQL(pCxt->pSql, sToken, index); - if (TK_NK_LP != sToken.type) { + NEXT_TOKEN_KEEP_SQL(pStmt->pSql, *pToken, index); + if (TK_NK_LP != pToken->type) { break; } - pCxt->pSql += index; + pStmt->pSql += index; - if ((*numOfRows) >= maxRows || pDataBlock->size + extendedRowSize >= pDataBlock->nAllocSize) { - int32_t tSize; - CHECK_CODE(allocateMemIfNeed(pDataBlock, extendedRowSize, &tSize)); - ASSERT(tSize >= maxRows); - maxRows = tSize; + if ((*pNumOfRows) >= maxRows || pDataBuf->size + extendedRowSize >= pDataBuf->nAllocSize) { + code = allocateMemIfNeed(pDataBuf, extendedRowSize, &maxRows); } bool gotRow = false; - CHECK_CODE(parseOneRow(pCxt, pDataBlock, tinfo.precision, &gotRow, pCxt->tmpTokenBuf)); - if (gotRow) { - pDataBlock->size += extendedRowSize; // len; + if (TSDB_CODE_SUCCESS == code) { + code = parseOneRow(pCxt, &pStmt->pSql, pDataBuf, &gotRow, pToken); } - NEXT_VALID_TOKEN(pCxt->pSql, sToken); - if (TK_NK_COMMA == sToken.type) { - return generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_INVALID_COLUMNS_NUM); - } else if (TK_NK_RP != sToken.type) { - return buildSyntaxErrMsg(&pCxt->msg, ") expected", sToken.z); + if (TSDB_CODE_SUCCESS == code) { + NEXT_VALID_TOKEN(pStmt->pSql, *pToken); + if (TK_NK_COMMA == pToken->type) { + code = generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_INVALID_COLUMNS_NUM); + } else if (TK_NK_RP != pToken->type) { + code = buildSyntaxErrMsg(&pCxt->msg, ") expected", pToken->z); + } } - if (gotRow) { - (*numOfRows)++; + if (TSDB_CODE_SUCCESS == code && gotRow) { + pDataBuf->size += extendedRowSize; + (*pNumOfRows)++; } } - if (0 == (*numOfRows) && (!TSDB_QUERY_HAS_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT))) { - return buildSyntaxErrMsg(&pCxt->msg, "no any data points", NULL); + if (TSDB_CODE_SUCCESS == code && 0 == (*pNumOfRows) && + (!TSDB_QUERY_HAS_TYPE(pStmt->insertType, TSDB_QUERY_TYPE_STMT_INSERT))) { + code = buildSyntaxErrMsg(&pCxt->msg, "no any data points", NULL); } - return TSDB_CODE_SUCCESS; + return code; } -static int32_t parseValuesClause(SInsertParseContext* pCxt, STableDataBlocks* dataBuf) { - int32_t maxNumOfRows; - CHECK_CODE(allocateMemIfNeed(dataBuf, insGetExtendedRowSize(dataBuf), &maxNumOfRows)); - +// VALUES (field1_value, ...) [(field1_value2, ...) ...] +static int32_t parseValuesClause(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt, STableDataBlocks* pDataBuf, + SToken* pToken) { + int32_t maxNumOfRows = 0; int32_t numOfRows = 0; - CHECK_CODE(parseValues(pCxt, dataBuf, maxNumOfRows, &numOfRows)); - - SSubmitBlk* pBlocks = (SSubmitBlk*)(dataBuf->pData); - if (TSDB_CODE_SUCCESS != insSetBlockInfo(pBlocks, dataBuf, numOfRows)) { - return buildInvalidOperationMsg(&pCxt->msg, - "too many rows in sql, total number of rows should be less than INT32_MAX"); + int32_t code = allocateMemIfNeed(pDataBuf, insGetExtendedRowSize(pDataBuf), &maxNumOfRows); + if (TSDB_CODE_SUCCESS == code) { + code = parseValues(pCxt, pStmt, pDataBuf, maxNumOfRows, &numOfRows, pToken); } - - dataBuf->numOfTables = 1; - pCxt->totalNum += numOfRows; - return TSDB_CODE_SUCCESS; + if (TSDB_CODE_SUCCESS == code) { + code = insSetBlockInfo((SSubmitBlk*)(pDataBuf->pData), pDataBuf, numOfRows, &pCxt->msg); + } + if (TSDB_CODE_SUCCESS == code) { + pDataBuf->numOfTables = 1; + pStmt->totalRowsNum += numOfRows; + pStmt->totalTbNum += 1; + TSDB_QUERY_SET_TYPE(pStmt->insertType, TSDB_QUERY_TYPE_INSERT); + } + return code; } -static int32_t parseCsvFile(SInsertParseContext* pCxt, TdFilePtr fp, STableDataBlocks* pDataBlock, int maxRows, - int32_t* numOfRows) { - STableComInfo tinfo = getTableInfo(pDataBlock->pTableMeta); - int32_t extendedRowSize = insGetExtendedRowSize(pDataBlock); - CHECK_CODE( - insInitRowBuilder(&pDataBlock->rowBuilder, pDataBlock->pTableMeta->sversion, &pDataBlock->boundColumnInfo)); +static int32_t parseCsvFile(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt, STableDataBlocks* pDataBuf, + int maxRows, int32_t* pNumOfRows) { + int32_t code = insInitRowBuilder(&pDataBuf->rowBuilder, pDataBuf->pTableMeta->sversion, &pDataBuf->boundColumnInfo); - (*numOfRows) = 0; - char tmpTokenBuf[TSDB_MAX_BYTES_PER_ROW] = {0}; // used for deleting Escape character: \\, \', \" + int32_t extendedRowSize = insGetExtendedRowSize(pDataBuf); + (*pNumOfRows) = 0; char* pLine = NULL; int64_t readLen = 0; - while ((readLen = taosGetLineFile(fp, &pLine)) != -1) { + pStmt->fileProcessing = false; + while (TSDB_CODE_SUCCESS == code && (readLen = taosGetLineFile(pStmt->fp, &pLine)) != -1) { if (('\r' == pLine[readLen - 1]) || ('\n' == pLine[readLen - 1])) { pLine[--readLen] = '\0'; } @@ -1100,588 +1342,570 @@ static int32_t parseCsvFile(SInsertParseContext* pCxt, TdFilePtr fp, STableDataB continue; } - if ((*numOfRows) >= maxRows || pDataBlock->size + extendedRowSize >= pDataBlock->nAllocSize) { - int32_t tSize; - CHECK_CODE(allocateMemIfNeed(pDataBlock, extendedRowSize, &tSize)); - ASSERT(tSize >= maxRows); - maxRows = tSize; + if ((*pNumOfRows) >= maxRows || pDataBuf->size + extendedRowSize >= pDataBuf->nAllocSize) { + code = allocateMemIfNeed(pDataBuf, extendedRowSize, &maxRows); } - strtolower(pLine, pLine); - char* pRawSql = pCxt->pSql; - pCxt->pSql = pLine; - bool gotRow = false; - int32_t code = parseOneRow(pCxt, pDataBlock, tinfo.precision, &gotRow, tmpTokenBuf); - if (TSDB_CODE_SUCCESS != code) { - pCxt->pSql = pRawSql; - return code; + bool gotRow = false; + if (TSDB_CODE_SUCCESS == code) { + SToken token; + strtolower(pLine, pLine); + const char* pRow = pLine; + code = parseOneRow(pCxt, (const char**)&pRow, pDataBuf, &gotRow, &token); } - if (gotRow) { - pDataBlock->size += extendedRowSize; // len; - (*numOfRows)++; + + if (TSDB_CODE_SUCCESS == code && gotRow) { + pDataBuf->size += extendedRowSize; + (*pNumOfRows)++; } - pCxt->pSql = pRawSql; - if (pDataBlock->nAllocSize > tsMaxMemUsedByInsert * 1024 * 1024) { + if (TSDB_CODE_SUCCESS == code && pDataBuf->nAllocSize > tsMaxMemUsedByInsert * 1024 * 1024) { + pStmt->fileProcessing = true; break; } } - if (0 == (*numOfRows) && (!TSDB_QUERY_HAS_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT))) { - return buildSyntaxErrMsg(&pCxt->msg, "no any data points", NULL); + if (TSDB_CODE_SUCCESS == code && 0 == (*pNumOfRows) && + (!TSDB_QUERY_HAS_TYPE(pStmt->insertType, TSDB_QUERY_TYPE_STMT_INSERT)) && !pStmt->fileProcessing) { + code = buildSyntaxErrMsg(&pCxt->msg, "no any data points", NULL); } - return TSDB_CODE_SUCCESS; + return code; } -static int32_t parseDataFromFileAgain(SInsertParseContext* pCxt, int16_t tableNo, const SName* pTableName, - STableDataBlocks* dataBuf) { - int32_t maxNumOfRows; - CHECK_CODE(allocateMemIfNeed(dataBuf, insGetExtendedRowSize(dataBuf), &maxNumOfRows)); - +static int32_t parseDataFromFileImpl(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt, STableDataBlocks* pDataBuf) { + int32_t maxNumOfRows = 0; int32_t numOfRows = 0; - CHECK_CODE(parseCsvFile(pCxt, pCxt->pComCxt->csvCxt.fp, dataBuf, maxNumOfRows, &numOfRows)); - - SSubmitBlk* pBlocks = (SSubmitBlk*)(dataBuf->pData); - if (TSDB_CODE_SUCCESS != insSetBlockInfo(pBlocks, dataBuf, numOfRows)) { - return buildInvalidOperationMsg(&pCxt->msg, - "too many rows in sql, total number of rows should be less than INT32_MAX"); + int32_t code = allocateMemIfNeed(pDataBuf, insGetExtendedRowSize(pDataBuf), &maxNumOfRows); + if (TSDB_CODE_SUCCESS == code) { + code = parseCsvFile(pCxt, pStmt, pDataBuf, maxNumOfRows, &numOfRows); } - - if (!taosEOFFile(pCxt->pComCxt->csvCxt.fp)) { - pCxt->pComCxt->needMultiParse = true; - pCxt->pComCxt->csvCxt.tableNo = tableNo; - memcpy(&pCxt->pComCxt->csvCxt.tableName, pTableName, sizeof(SName)); - pCxt->pComCxt->csvCxt.pLastSqlPos = pCxt->pSql; + if (TSDB_CODE_SUCCESS == code) { + code = insSetBlockInfo((SSubmitBlk*)(pDataBuf->pData), pDataBuf, numOfRows, &pCxt->msg); } - - dataBuf->numOfTables = 1; - pCxt->totalNum += numOfRows; - return TSDB_CODE_SUCCESS; + if (TSDB_CODE_SUCCESS == code) { + pDataBuf->numOfTables = 1; + pStmt->totalRowsNum += numOfRows; + pStmt->totalTbNum += 1; + TSDB_QUERY_SET_TYPE(pStmt->insertType, TSDB_QUERY_TYPE_FILE_INSERT); + if (!pStmt->fileProcessing) { + taosCloseFile(&pStmt->fp); + } else { + parserDebug("0x%" PRIx64 " insert from csv. File is too large, do it in batches.", pCxt->pComCxt->requestId); + } + } + return code; } -static int32_t parseDataFromFile(SInsertParseContext* pCxt, int16_t tableNo, const SName* pTableName, SToken filePath, - STableDataBlocks* dataBuf) { +static int32_t parseDataFromFile(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt, SToken* pFilePath, + STableDataBlocks* pDataBuf) { char filePathStr[TSDB_FILENAME_LEN] = {0}; - if (TK_NK_STRING == filePath.type) { - trimString(filePath.z, filePath.n, filePathStr, sizeof(filePathStr)); + if (TK_NK_STRING == pFilePath->type) { + trimString(pFilePath->z, pFilePath->n, filePathStr, sizeof(filePathStr)); } else { - strncpy(filePathStr, filePath.z, filePath.n); + strncpy(filePathStr, pFilePath->z, pFilePath->n); } - pCxt->pComCxt->csvCxt.fp = taosOpenFile(filePathStr, TD_FILE_READ | TD_FILE_STREAM); - if (NULL == pCxt->pComCxt->csvCxt.fp) { + pStmt->fp = taosOpenFile(filePathStr, TD_FILE_READ | TD_FILE_STREAM); + if (NULL == pStmt->fp) { return TAOS_SYSTEM_ERROR(errno); } - return parseDataFromFileAgain(pCxt, tableNo, pTableName, dataBuf); + return parseDataFromFileImpl(pCxt, pStmt, pDataBuf); } -static void destroyInsertParseContextForTable(SInsertParseContext* pCxt) { - if (!pCxt->pComCxt->needMultiParse) { - taosCloseFile(&pCxt->pComCxt->csvCxt.fp); +static int32_t parseFileClause(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt, STableDataBlocks* pDataBuf, + SToken* pToken) { + NEXT_TOKEN(pStmt->pSql, *pToken); + if (0 == pToken->n || (TK_NK_STRING != pToken->type && TK_NK_ID != pToken->type)) { + return buildSyntaxErrMsg(&pCxt->msg, "file path is required following keyword FILE", pToken->z); } - taosMemoryFreeClear(pCxt->pTableMeta); - destroyBoundColumnInfo(&pCxt->tags); - tdDestroySVCreateTbReq(&pCxt->createTblReq); + return parseDataFromFile(pCxt, pStmt, pToken, pDataBuf); } -static void destroySubTableHashElem(void* p) { taosMemoryFree(*(STableMeta**)p); } - -static void destroyInsertParseContext(SInsertParseContext* pCxt) { - destroyInsertParseContextForTable(pCxt); - taosHashCleanup(pCxt->pVgroupsHashObj); - taosHashCleanup(pCxt->pSubTableHashObj); - taosHashCleanup(pCxt->pTableNameHashObj); - taosHashCleanup(pCxt->pDbFNameHashObj); - - insDestroyBlockHashmap(pCxt->pTableBlockHashObj); - insDestroyBlockArrayList(pCxt->pVgDataBlocks); +// VALUES (field1_value, ...) [(field1_value2, ...) ...] | FILE csv_file_path +static int32_t parseDataClause(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt, STableDataBlocks* pDataBuf) { + SToken token; + NEXT_TOKEN(pStmt->pSql, token); + switch (token.type) { + case TK_VALUES: + return parseValuesClause(pCxt, pStmt, pDataBuf, &token); + case TK_FILE: + return parseFileClause(pCxt, pStmt, pDataBuf, &token); + default: + break; + } + return buildSyntaxErrMsg(&pCxt->msg, "keyword VALUES or FILE is expected", token.z); } -static int32_t parseTableName(SInsertParseContext* pCxt, SToken* pTbnameToken, SName* pName, char* pDbFName, - char* pTbFName) { - int32_t code = insCreateSName(pName, pTbnameToken, pCxt->pComCxt->acctId, pCxt->pComCxt->db, &pCxt->msg); +// input pStmt->pSql: +// 1. [(tag1_name, ...)] ... +// 2. VALUES ... | FILE ... +static int32_t parseInsertTableClauseBottom(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + STableDataBlocks* pDataBuf = NULL; + int32_t code = parseSchemaClauseBottom(pCxt, pStmt, &pDataBuf); if (TSDB_CODE_SUCCESS == code) { - tNameExtractFullName(pName, pTbFName); - code = taosHashPut(pCxt->pTableNameHashObj, pTbFName, strlen(pTbFName), pName, sizeof(SName)); - } - if (TSDB_CODE_SUCCESS == code) { - tNameGetFullDbName(pName, pDbFName); - code = taosHashPut(pCxt->pDbFNameHashObj, pDbFName, strlen(pDbFName), pDbFName, TSDB_DB_FNAME_LEN); + code = parseDataClause(pCxt, pStmt, pDataBuf); } return code; } -// tb_name -// [USING stb_name [(tag1_name, ...)] TAGS (tag1_value, ...)] -// [(field1_name, ...)] -// VALUES (field1_value, ...) [(field1_value2, ...) ...] | FILE csv_file_path -// [...]; -static int32_t parseInsertBody(SInsertParseContext* pCxt) { - int32_t tbNum = 0; - SName name; - char tbFName[TSDB_TABLE_FNAME_LEN]; - char dbFName[TSDB_DB_FNAME_LEN]; - bool autoCreateTbl = false; - - // for each table - while (1) { - SToken sToken; - char* tbName = NULL; - - // pSql -> tb_name ... - NEXT_TOKEN(pCxt->pSql, sToken); - - // no data in the sql string anymore. - if (sToken.n == 0) { - if (sToken.type && pCxt->pSql[0]) { - return buildSyntaxErrMsg(&pCxt->msg, "invalid charactor in SQL", sToken.z); - } +static void resetEnvPreTable(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + destroyBoundColumnInfo(&pCxt->tags); + taosMemoryFreeClear(pStmt->pTableMeta); + tdDestroySVCreateTbReq(&pStmt->createTblReq); + pCxt->missCache = false; + pCxt->usingDuplicateTable = false; + pStmt->pBoundCols = NULL; + pStmt->usingTableProcessing = false; + pStmt->fileProcessing = false; +} - if (0 == pCxt->totalNum && (!TSDB_QUERY_HAS_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT)) && - !pCxt->pComCxt->needMultiParse) { - return buildInvalidOperationMsg(&pCxt->msg, "no data in sql"); - } - break; - } +// input pStmt->pSql: [(field1_name, ...)] [ USING ... ] VALUES ... | FILE ... +static int32_t parseInsertTableClause(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt, SToken* pTbName) { + resetEnvPreTable(pCxt, pStmt); + int32_t code = parseSchemaClauseTop(pCxt, pStmt, pTbName); + if (TSDB_CODE_SUCCESS == code && !pCxt->missCache) { + code = parseInsertTableClauseBottom(pCxt, pStmt); + } + return code; +} - if (TSDB_QUERY_HAS_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT) && tbNum > 0) { - return buildInvalidOperationMsg(&pCxt->msg, "single table allowed in one stmt"); +static int32_t checkTableClauseFirstToken(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt, SToken* pTbName, + bool* pHasData) { + // no data in the sql string anymore. + if (0 == pTbName->n) { + if (0 != pTbName->type && '\0' != pStmt->pSql[0]) { + return buildSyntaxErrMsg(&pCxt->msg, "invalid charactor in SQL", pTbName->z); } - destroyInsertParseContextForTable(pCxt); - - if (TK_NK_QUESTION == sToken.type) { - if (pCxt->pStmtCb) { - CHECK_CODE((*pCxt->pStmtCb->getTbNameFn)(pCxt->pStmtCb->pStmt, &tbName)); - - sToken.z = tbName; - sToken.n = strlen(tbName); - } else { - return buildSyntaxErrMsg(&pCxt->msg, "? only used in stmt", sToken.z); - } + if (0 == pStmt->totalRowsNum && (!TSDB_QUERY_HAS_TYPE(pStmt->insertType, TSDB_QUERY_TYPE_STMT_INSERT))) { + return buildInvalidOperationMsg(&pCxt->msg, "no data in sql"); } - SToken tbnameToken = sToken; - NEXT_TOKEN(pCxt->pSql, sToken); + *pHasData = false; + return TSDB_CODE_SUCCESS; + } - if (!pCxt->pComCxt->async || TK_USING == sToken.type) { - CHECK_CODE(parseTableName(pCxt, &tbnameToken, &name, dbFName, tbFName)); - } + if (TSDB_QUERY_HAS_TYPE(pStmt->insertType, TSDB_QUERY_TYPE_STMT_INSERT) && pStmt->totalTbNum > 0) { + return buildInvalidOperationMsg(&pCxt->msg, "single table allowed in one stmt"); + } - bool existedUsing = false; - // USING clause - if (TK_USING == sToken.type) { - existedUsing = true; - CHECK_CODE(parseUsingClause(pCxt, tbNum, &name, tbFName)); - NEXT_TOKEN(pCxt->pSql, sToken); - autoCreateTbl = true; + if (TK_NK_QUESTION == pTbName->type) { + if (NULL == pCxt->pComCxt->pStmtCb) { + return buildSyntaxErrMsg(&pCxt->msg, "? only used in stmt", pTbName->z); } - char* pBoundColsStart = NULL; - if (TK_NK_LP == sToken.type) { - // pSql -> field1_name, ...) - pBoundColsStart = pCxt->pSql; - CHECK_CODE(ignoreBoundColumns(pCxt)); - NEXT_TOKEN(pCxt->pSql, sToken); + char* tbName = NULL; + int32_t code = (*pCxt->pComCxt->pStmtCb->getTbNameFn)(pCxt->pComCxt->pStmtCb->pStmt, &tbName); + if (TSDB_CODE_SUCCESS == code) { + pTbName->z = tbName; + pTbName->n = strlen(tbName); + } else { + return code; } + } - if (TK_USING == sToken.type) { - if (pCxt->pComCxt->async) { - CHECK_CODE(parseTableName(pCxt, &tbnameToken, &name, dbFName, tbFName)); - } - CHECK_CODE(parseUsingClause(pCxt, tbNum, &name, tbFName)); - NEXT_TOKEN(pCxt->pSql, sToken); - autoCreateTbl = true; - } else if (!existedUsing) { - CHECK_CODE(getTableMeta(pCxt, tbNum, &name)); - if (TSDB_SUPER_TABLE == pCxt->pTableMeta->tableType) { - return buildInvalidOperationMsg(&pCxt->msg, "insert data into super table is not supported"); - } - } + *pHasData = true; + return TSDB_CODE_SUCCESS; +} - STableDataBlocks* dataBuf = NULL; - if (pCxt->pComCxt->async) { - CHECK_CODE(insGetDataBlockFromList(pCxt->pTableBlockHashObj, &pCxt->pTableMeta->uid, - sizeof(pCxt->pTableMeta->uid), TSDB_DEFAULT_PAYLOAD_SIZE, sizeof(SSubmitBlk), - getTableInfo(pCxt->pTableMeta).rowSize, pCxt->pTableMeta, &dataBuf, NULL, - &pCxt->createTblReq)); - } else { - CHECK_CODE(insGetDataBlockFromList(pCxt->pTableBlockHashObj, tbFName, strlen(tbFName), TSDB_DEFAULT_PAYLOAD_SIZE, - sizeof(SSubmitBlk), getTableInfo(pCxt->pTableMeta).rowSize, pCxt->pTableMeta, - &dataBuf, NULL, &pCxt->createTblReq)); - } +static int32_t setStmtInfo(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + SParsedDataColInfo* tags = taosMemoryMalloc(sizeof(pCxt->tags)); + if (NULL == tags) { + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } + memcpy(tags, &pCxt->tags, sizeof(pCxt->tags)); - if (NULL != pBoundColsStart) { - char* pCurrPos = pCxt->pSql; - pCxt->pSql = pBoundColsStart; - CHECK_CODE(parseBoundColumns(pCxt, &dataBuf->boundColumnInfo, getTableColumnSchema(pCxt->pTableMeta))); - pCxt->pSql = pCurrPos; - } + SStmtCallback* pStmtCb = pCxt->pComCxt->pStmtCb; + char tbFName[TSDB_TABLE_FNAME_LEN]; + tNameExtractFullName(&pStmt->targetTableName, tbFName); + int32_t code = (*pStmtCb->setInfoFn)(pStmtCb->pStmt, pStmt->pTableMeta, tags, tbFName, pStmt->usingTableProcessing, + pStmt->pVgroupsHashObj, pStmt->pTableBlockHashObj, pStmt->usingTableName.tname); - if (TK_VALUES == sToken.type) { - // pSql -> (field1_value, ...) [(field1_value2, ...) ...] - CHECK_CODE(parseValuesClause(pCxt, dataBuf)); - TSDB_QUERY_SET_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_INSERT); + memset(&pCxt->tags, 0, sizeof(pCxt->tags)); + pStmt->pVgroupsHashObj = NULL; + pStmt->pTableBlockHashObj = NULL; + return code; +} - tbNum++; - continue; - } +static int32_t parseInsertBodyBottom(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + if (TSDB_QUERY_HAS_TYPE(pStmt->insertType, TSDB_QUERY_TYPE_STMT_INSERT)) { + return setStmtInfo(pCxt, pStmt); + } - // FILE csv_file_path - if (TK_FILE == sToken.type) { - // pSql -> csv_file_path - NEXT_TOKEN(pCxt->pSql, sToken); - if (0 == sToken.n || (TK_NK_STRING != sToken.type && TK_NK_ID != sToken.type)) { - return buildSyntaxErrMsg(&pCxt->msg, "file path is required following keyword FILE", sToken.z); - } - CHECK_CODE(parseDataFromFile(pCxt, tbNum, &name, sToken, dataBuf)); - pCxt->pOutput->insertType = TSDB_QUERY_TYPE_FILE_INSERT; + // merge according to vgId + int32_t code = TSDB_CODE_SUCCESS; + if (taosHashGetSize(pStmt->pTableBlockHashObj) > 0) { + code = insMergeTableDataBlocks(pStmt->pTableBlockHashObj, &pStmt->pVgDataBlocks); + } + if (TSDB_CODE_SUCCESS == code) { + code = insBuildOutput(pStmt->pVgroupsHashObj, pStmt->pVgDataBlocks, &pStmt->pDataBlocks); + } + return code; +} - tbNum++; - if (!pCxt->pComCxt->needMultiParse) { - continue; - } else { - parserDebug("0x%" PRIx64 " insert from csv. File is too large, do it in batches.", pCxt->pComCxt->requestId); - break; - } +// tb_name +// [USING stb_name [(tag1_name, ...)] TAGS (tag1_value, ...)] +// [(field1_name, ...)] +// VALUES (field1_value, ...) [(field1_value2, ...) ...] | FILE csv_file_path +// [...]; +static int32_t parseInsertBody(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + SToken token; + int32_t code = TSDB_CODE_SUCCESS; + bool hasData = true; + // for each table + while (TSDB_CODE_SUCCESS == code && hasData && !pCxt->missCache && !pStmt->fileProcessing) { + // pStmt->pSql -> tb_name ... + NEXT_TOKEN(pStmt->pSql, token); + code = checkTableClauseFirstToken(pCxt, pStmt, &token, &hasData); + if (TSDB_CODE_SUCCESS == code && hasData) { + code = parseInsertTableClause(pCxt, pStmt, &token); } - - return buildSyntaxErrMsg(&pCxt->msg, "keyword VALUES or FILE is expected", sToken.z); } - parserDebug("0x%" PRIx64 " insert input rows: %d", pCxt->pComCxt->requestId, pCxt->totalNum); + if (TSDB_CODE_SUCCESS == code && !pCxt->missCache) { + code = parseInsertBodyBottom(pCxt, pStmt); + } + return code; +} - if (TSDB_QUERY_HAS_TYPE(pCxt->pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT)) { - SParsedDataColInfo* tags = taosMemoryMalloc(sizeof(pCxt->tags)); - if (NULL == tags) { - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - memcpy(tags, &pCxt->tags, sizeof(pCxt->tags)); - (*pCxt->pStmtCb->setInfoFn)(pCxt->pStmtCb->pStmt, pCxt->pTableMeta, tags, tbFName, autoCreateTbl, - pCxt->pVgroupsHashObj, pCxt->pTableBlockHashObj, pCxt->sTableName); +static void destroySubTableHashElem(void* p) { taosMemoryFree(*(STableMeta**)p); } - memset(&pCxt->tags, 0, sizeof(pCxt->tags)); - pCxt->pVgroupsHashObj = NULL; - pCxt->pTableBlockHashObj = NULL; +static int32_t createVnodeModifOpStmt(SParseContext* pCxt, bool reentry, SNode** pOutput) { + SVnodeModifOpStmt* pStmt = (SVnodeModifOpStmt*)nodesMakeNode(QUERY_NODE_VNODE_MODIF_STMT); + if (NULL == pStmt) { + return TSDB_CODE_OUT_OF_MEMORY; + } - return TSDB_CODE_SUCCESS; + if (pCxt->pStmtCb) { + TSDB_QUERY_SET_TYPE(pStmt->insertType, TSDB_QUERY_TYPE_STMT_INSERT); } + pStmt->pSql = pCxt->pSql; + pStmt->freeHashFunc = insDestroyBlockHashmap; + pStmt->freeArrayFunc = insDestroyBlockArrayList; - // merge according to vgId - if (taosHashGetSize(pCxt->pTableBlockHashObj) > 0) { - CHECK_CODE(insMergeTableDataBlocks(pCxt->pTableBlockHashObj, &pCxt->pVgDataBlocks)); - } - return insBuildOutput(pCxt); -} - -static int32_t parseInsertBodyAgain(SInsertParseContext* pCxt) { - STableDataBlocks* dataBuf = NULL; - CHECK_CODE(getTableMeta(pCxt, pCxt->pComCxt->csvCxt.tableNo, &pCxt->pComCxt->csvCxt.tableName)); - CHECK_CODE(insGetDataBlockFromList(pCxt->pTableBlockHashObj, &pCxt->pTableMeta->uid, sizeof(pCxt->pTableMeta->uid), - TSDB_DEFAULT_PAYLOAD_SIZE, sizeof(SSubmitBlk), - getTableInfo(pCxt->pTableMeta).rowSize, pCxt->pTableMeta, &dataBuf, NULL, - &pCxt->createTblReq)); - CHECK_CODE(parseDataFromFileAgain(pCxt, pCxt->pComCxt->csvCxt.tableNo, &pCxt->pComCxt->csvCxt.tableName, dataBuf)); - if (taosEOFFile(pCxt->pComCxt->csvCxt.fp)) { - CHECK_CODE(parseInsertBody(pCxt)); - pCxt->pComCxt->needMultiParse = false; - return TSDB_CODE_SUCCESS; + if (!reentry) { + pStmt->pVgroupsHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); + pStmt->pTableBlockHashObj = + taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); } - parserDebug("0x%" PRIx64 " insert again input rows: %d", pCxt->pComCxt->requestId, pCxt->totalNum); - // merge according to vgId - if (taosHashGetSize(pCxt->pTableBlockHashObj) > 0) { - CHECK_CODE(insMergeTableDataBlocks(pCxt->pTableBlockHashObj, &pCxt->pVgDataBlocks)); + pStmt->pSubTableHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_NO_LOCK); + pStmt->pTableNameHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_NO_LOCK); + pStmt->pDbFNameHashObj = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_NO_LOCK); + if ((!reentry && (NULL == pStmt->pVgroupsHashObj || NULL == pStmt->pTableBlockHashObj)) || + NULL == pStmt->pSubTableHashObj || NULL == pStmt->pTableNameHashObj || NULL == pStmt->pDbFNameHashObj) { + nodesDestroyNode((SNode*)pStmt); + return TSDB_CODE_OUT_OF_MEMORY; } - return insBuildOutput(pCxt); + + taosHashSetFreeFp(pStmt->pSubTableHashObj, destroySubTableHashElem); + + *pOutput = (SNode*)pStmt; + return TSDB_CODE_SUCCESS; } -// INSERT INTO -// tb_name -// [USING stb_name [(tag1_name, ...)] TAGS (tag1_value, ...)] -// [(field1_name, ...)] -// VALUES (field1_value, ...) [(field1_value2, ...) ...] | FILE csv_file_path -// [...]; -int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery, SParseMetaCache* pMetaCache) { - SInsertParseContext context = { - .pComCxt = pContext, - .pSql = pContext->needMultiParse ? (char*)pContext->csvCxt.pLastSqlPos : (char*)pContext->pSql, - .msg = {.buf = pContext->pMsg, .len = pContext->msgLen}, - .pTableMeta = NULL, - .createTblReq = {0}, - .pSubTableHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_NO_LOCK), - .pTableNameHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_NO_LOCK), - .pDbFNameHashObj = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_NO_LOCK), - .totalNum = 0, - .pOutput = (SVnodeModifOpStmt*)nodesMakeNode(QUERY_NODE_VNODE_MODIF_STMT), - .pStmtCb = pContext->pStmtCb, - .pMetaCache = pMetaCache, - .memElapsed = 0, - .parRowElapsed = 0}; - - if (pContext->pStmtCb && *pQuery) { - (*pContext->pStmtCb->getExecInfoFn)(pContext->pStmtCb->pStmt, &context.pVgroupsHashObj, - &context.pTableBlockHashObj); - if (NULL == context.pVgroupsHashObj) { - context.pVgroupsHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); - } - if (NULL == context.pTableBlockHashObj) { - context.pTableBlockHashObj = - taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); - } - } else { - context.pVgroupsHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); - context.pTableBlockHashObj = - taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); +static int32_t createInsertQuery(SParseContext* pCxt, SQuery** pOutput) { + SQuery* pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY); + if (NULL == pQuery) { + return TSDB_CODE_OUT_OF_MEMORY; } - if (NULL == context.pVgroupsHashObj || NULL == context.pTableBlockHashObj || NULL == context.pSubTableHashObj || - NULL == context.pTableNameHashObj || NULL == context.pDbFNameHashObj || NULL == context.pOutput) { - return TSDB_CODE_TSC_OUT_OF_MEMORY; - } - taosHashSetFreeFp(context.pSubTableHashObj, destroySubTableHashElem); + pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE; + pQuery->haveResultSet = false; + pQuery->msgType = TDMT_VND_SUBMIT; - if (pContext->pStmtCb) { - TSDB_QUERY_SET_TYPE(context.pOutput->insertType, TSDB_QUERY_TYPE_STMT_INSERT); + int32_t code = createVnodeModifOpStmt(pCxt, false, &pQuery->pRoot); + if (TSDB_CODE_SUCCESS == code) { + *pOutput = pQuery; + } else { + nodesDestroyNode((SNode*)pQuery); } + return code; +} - if (NULL == *pQuery) { - *pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY); - if (NULL == *pQuery) { - return TSDB_CODE_OUT_OF_MEMORY; - } - } else { - nodesDestroyNode((*pQuery)->pRoot); +static int32_t checkAuthFromMetaData(const SArray* pUsers) { + if (1 != taosArrayGetSize(pUsers)) { + return TSDB_CODE_FAILED; } - (*pQuery)->execMode = QUERY_EXEC_MODE_SCHEDULE; - (*pQuery)->haveResultSet = false; - (*pQuery)->msgType = TDMT_VND_SUBMIT; - (*pQuery)->pRoot = (SNode*)context.pOutput; + SMetaRes* pRes = taosArrayGet(pUsers, 0); + if (TSDB_CODE_SUCCESS == pRes->code) { + return (*(bool*)pRes->pRes) ? TSDB_CODE_SUCCESS : TSDB_CODE_PAR_PERMISSION_DENIED; + } + return pRes->code; +} - if (NULL == (*pQuery)->pTableList) { - (*pQuery)->pTableList = taosArrayInit(taosHashGetSize(context.pTableNameHashObj), sizeof(SName)); - if (NULL == (*pQuery)->pTableList) { +static int32_t getTableMetaFromMetaData(const SArray* pTables, STableMeta** pMeta) { + if (1 != taosArrayGetSize(pTables)) { + return TSDB_CODE_FAILED; + } + SMetaRes* pRes = taosArrayGet(pTables, 0); + if (TSDB_CODE_SUCCESS == pRes->code) { + *pMeta = tableMetaDup((const STableMeta*)pRes->pRes); + if (NULL == *pMeta) { return TSDB_CODE_OUT_OF_MEMORY; } } + return pRes->code; +} - if (NULL == (*pQuery)->pDbList) { - (*pQuery)->pDbList = taosArrayInit(taosHashGetSize(context.pDbFNameHashObj), TSDB_DB_FNAME_LEN); - if (NULL == (*pQuery)->pDbList) { - return TSDB_CODE_OUT_OF_MEMORY; - } +static int32_t getTableVgroupFromMetaData(const SArray* pTables, SVnodeModifOpStmt* pStmt, bool isStb) { + if (1 != taosArrayGetSize(pTables)) { + return TSDB_CODE_FAILED; } - int32_t code = TSDB_CODE_SUCCESS; - if (!context.pComCxt->needMultiParse) { - code = skipInsertInto(&context.pSql, &context.msg); - if (TSDB_CODE_SUCCESS == code) { - code = parseInsertBody(&context); - } - } else { - code = parseInsertBodyAgain(&context); + SMetaRes* pRes = taosArrayGet(pTables, 0); + if (TSDB_CODE_SUCCESS != pRes->code) { + return pRes->code; } - if (TSDB_CODE_SUCCESS == code || NEED_CLIENT_HANDLE_ERROR(code)) { - SName* pTable = taosHashIterate(context.pTableNameHashObj, NULL); - while (NULL != pTable) { - taosArrayPush((*pQuery)->pTableList, pTable); - pTable = taosHashIterate(context.pTableNameHashObj, pTable); - } + SVgroupInfo* pVg = pRes->pRes; + if (isStb) { + pStmt->pTableMeta->vgId = pVg->vgId; + } + return taosHashPut(pStmt->pVgroupsHashObj, (const char*)&pVg->vgId, sizeof(pVg->vgId), (char*)pVg, + sizeof(SVgroupInfo)); +} - char* pDb = taosHashIterate(context.pDbFNameHashObj, NULL); - while (NULL != pDb) { - taosArrayPush((*pQuery)->pDbList, pDb); - pDb = taosHashIterate(context.pDbFNameHashObj, pDb); - } +static int32_t getTableSchemaFromMetaData(const SMetaData* pMetaData, SVnodeModifOpStmt* pStmt, bool isStb) { + int32_t code = checkAuthFromMetaData(pMetaData->pUser); + if (TSDB_CODE_SUCCESS == code) { + code = getTableMetaFromMetaData(pMetaData->pTableMeta, &pStmt->pTableMeta); } - if (pContext->pStmtCb) { - context.pVgroupsHashObj = NULL; - context.pTableBlockHashObj = NULL; + if (TSDB_CODE_SUCCESS == code) { + code = getTableVgroupFromMetaData(pMetaData->pTableHash, pStmt, isStb); } - destroyInsertParseContext(&context); return code; } -// pSql -> (field1_value, ...) [(field1_value2, ...) ...] -static int32_t skipValuesClause(SInsertParseSyntaxCxt* pCxt) { - int32_t numOfRows = 0; - SToken sToken; - while (1) { - int32_t index = 0; - NEXT_TOKEN_KEEP_SQL(pCxt->pSql, sToken, index); - if (TK_NK_LP != sToken.type) { - break; - } - pCxt->pSql += index; +static void destoryTablesReq(void* p) { + STablesReq* pRes = (STablesReq*)p; + taosArrayDestroy(pRes->pTables); +} - CHECK_CODE(skipParentheses(pCxt)); - ++numOfRows; +static void clearCatalogReq(SCatalogReq* pCatalogReq) { + if (NULL == pCatalogReq) { + return; } - if (0 == numOfRows) { - return buildSyntaxErrMsg(&pCxt->msg, "no any data points", NULL); + + taosArrayDestroyEx(pCatalogReq->pTableMeta, destoryTablesReq); + pCatalogReq->pTableMeta = NULL; + taosArrayDestroyEx(pCatalogReq->pTableHash, destoryTablesReq); + pCatalogReq->pTableHash = NULL; + taosArrayDestroy(pCatalogReq->pUser); + pCatalogReq->pUser = NULL; +} + +static int32_t setVnodeModifOpStmt(SParseContext* pCxt, SCatalogReq* pCatalogReq, const SMetaData* pMetaData, + SVnodeModifOpStmt* pStmt) { + clearCatalogReq(pCatalogReq); + + if (pStmt->usingTableProcessing) { + return getTableSchemaFromMetaData(pMetaData, pStmt, true); } - return TSDB_CODE_SUCCESS; + return getTableSchemaFromMetaData(pMetaData, pStmt, false); } -static int32_t skipTagsClause(SInsertParseSyntaxCxt* pCxt) { return skipParentheses(pCxt); } +static int32_t resetVnodeModifOpStmt(SParseContext* pCxt, SQuery* pQuery) { + nodesDestroyNode(pQuery->pRoot); -static int32_t skipTableOptions(SInsertParseSyntaxCxt* pCxt) { - do { - int32_t index = 0; - SToken sToken; - NEXT_TOKEN_KEEP_SQL(pCxt->pSql, sToken, index); - if (TK_TTL == sToken.type || TK_COMMENT == sToken.type) { - pCxt->pSql += index; - NEXT_TOKEN_WITH_PREV(pCxt->pSql, sToken); - } else { - break; + int32_t code = createVnodeModifOpStmt(pCxt, true, &pQuery->pRoot); + if (TSDB_CODE_SUCCESS == code) { + SVnodeModifOpStmt* pStmt = (SVnodeModifOpStmt*)pQuery->pRoot; + + (*pCxt->pStmtCb->getExecInfoFn)(pCxt->pStmtCb->pStmt, &pStmt->pVgroupsHashObj, &pStmt->pTableBlockHashObj); + if (NULL == pStmt->pVgroupsHashObj) { + pStmt->pVgroupsHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); } - } while (1); - return TSDB_CODE_SUCCESS; + if (NULL == pStmt->pTableBlockHashObj) { + pStmt->pTableBlockHashObj = + taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); + } + if (NULL == pStmt->pVgroupsHashObj || NULL == pStmt->pTableBlockHashObj) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + } + + return code; } -// pSql -> [(tag1_name, ...)] TAGS (tag1_value, ...) -static int32_t skipUsingClause(SInsertParseSyntaxCxt* pCxt) { - SToken sToken; - NEXT_TOKEN(pCxt->pSql, sToken); - if (TK_NK_LP == sToken.type) { - CHECK_CODE(skipBoundColumns(pCxt)); - NEXT_TOKEN(pCxt->pSql, sToken); +static int32_t initInsertQuery(SParseContext* pCxt, SCatalogReq* pCatalogReq, const SMetaData* pMetaData, + SQuery** pQuery) { + if (NULL == *pQuery) { + return createInsertQuery(pCxt, pQuery); } - if (TK_TAGS != sToken.type) { - return buildSyntaxErrMsg(&pCxt->msg, "TAGS is expected", sToken.z); + if (NULL != pCxt->pStmtCb) { + return resetVnodeModifOpStmt(pCxt, *pQuery); } - // pSql -> (tag1_value, ...) - NEXT_TOKEN(pCxt->pSql, sToken); - if (TK_NK_LP != sToken.type) { - return buildSyntaxErrMsg(&pCxt->msg, "( is expected", sToken.z); + + SVnodeModifOpStmt* pStmt = (SVnodeModifOpStmt*)(*pQuery)->pRoot; + + if (!pStmt->fileProcessing) { + return setVnodeModifOpStmt(pCxt, pCatalogReq, pMetaData, pStmt); } - CHECK_CODE(skipTagsClause(pCxt)); - CHECK_CODE(skipTableOptions(pCxt)); return TSDB_CODE_SUCCESS; } -static int32_t collectTableMetaKey(SInsertParseSyntaxCxt* pCxt, bool isStable, int32_t tableNo, SToken* pTbToken) { - SName name = {0}; - CHECK_CODE(insCreateSName(&name, pTbToken, pCxt->pComCxt->acctId, pCxt->pComCxt->db, &pCxt->msg)); - CHECK_CODE(reserveTableMetaInCacheForInsert(&name, isStable ? CATALOG_REQ_TYPE_META : CATALOG_REQ_TYPE_BOTH, tableNo, - pCxt->pMetaCache)); +static int32_t setRefreshMate(SQuery* pQuery) { + SVnodeModifOpStmt* pStmt = (SVnodeModifOpStmt*)pQuery->pRoot; + SName* pTable = taosHashIterate(pStmt->pTableNameHashObj, NULL); + while (NULL != pTable) { + taosArrayPush(pQuery->pTableList, pTable); + pTable = taosHashIterate(pStmt->pTableNameHashObj, pTable); + } + + char* pDb = taosHashIterate(pStmt->pDbFNameHashObj, NULL); + while (NULL != pDb) { + taosArrayPush(pQuery->pDbList, pDb); + pDb = taosHashIterate(pStmt->pDbFNameHashObj, pDb); + } + return TSDB_CODE_SUCCESS; } -static int32_t checkTableName(const char* pTableName, SMsgBuf* pMsgBuf) { - if (NULL != strchr(pTableName, '.')) { - return generateSyntaxErrMsgExt(pMsgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, "The table name cannot contain '.'"); +// INSERT INTO +// tb_name +// [USING stb_name [(tag1_name, ...)] TAGS (tag1_value, ...) [table_options]] +// [(field1_name, ...)] +// VALUES (field1_value, ...) [(field1_value2, ...) ...] | FILE csv_file_path +// [...]; +static int32_t parseInsertSqlFromStart(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + int32_t code = skipInsertInto(&pStmt->pSql, &pCxt->msg); + if (TSDB_CODE_SUCCESS == code) { + code = parseInsertBody(pCxt, pStmt); } - return TSDB_CODE_SUCCESS; + return code; } -static int32_t collectAutoCreateTableMetaKey(SInsertParseSyntaxCxt* pCxt, int32_t tableNo, SToken* pTbToken) { - SName name = {0}; - CHECK_CODE(insCreateSName(&name, pTbToken, pCxt->pComCxt->acctId, pCxt->pComCxt->db, &pCxt->msg)); - CHECK_CODE(checkTableName(name.tname, &pCxt->msg)); - CHECK_CODE(reserveTableMetaInCacheForInsert(&name, CATALOG_REQ_TYPE_VGROUP, tableNo, pCxt->pMetaCache)); - return TSDB_CODE_SUCCESS; +static int32_t parseInsertSqlFromCsv(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + STableDataBlocks* pDataBuf = NULL; + int32_t code = getTableDataBlocks(pCxt, pStmt, &pDataBuf); + if (TSDB_CODE_SUCCESS == code) { + code = parseDataFromFileImpl(pCxt, pStmt, pDataBuf); + } + + if (TSDB_CODE_SUCCESS == code) { + if (pStmt->fileProcessing) { + code = parseInsertBodyBottom(pCxt, pStmt); + } else { + code = parseInsertBody(pCxt, pStmt); + } + } + + return code; } -static int32_t parseInsertBodySyntax(SInsertParseSyntaxCxt* pCxt) { - bool hasData = false; - int32_t tableNo = 0; - // for each table - while (1) { - SToken sToken; +static int32_t parseInsertSqlFromTable(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + int32_t code = parseInsertTableClauseBottom(pCxt, pStmt); + if (TSDB_CODE_SUCCESS == code) { + code = parseInsertBody(pCxt, pStmt); + } + return code; +} - // pSql -> tb_name ... - NEXT_TOKEN(pCxt->pSql, sToken); +static int32_t parseInsertSqlImpl(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt) { + if (pStmt->pSql == pCxt->pComCxt->pSql || NULL != pCxt->pComCxt->pStmtCb) { + return parseInsertSqlFromStart(pCxt, pStmt); + } - // no data in the sql string anymore. - if (sToken.n == 0) { - if (sToken.type && pCxt->pSql[0]) { - return buildSyntaxErrMsg(&pCxt->msg, "invalid charactor in SQL", sToken.z); - } + if (pStmt->fileProcessing) { + return parseInsertSqlFromCsv(pCxt, pStmt); + } - if (!hasData) { - return buildInvalidOperationMsg(&pCxt->msg, "no data in sql"); - } - break; - } + return parseInsertSqlFromTable(pCxt, pStmt); +} - hasData = false; +static int32_t buildInsertTableReq(SName* pName, SArray** pTables) { + *pTables = taosArrayInit(1, sizeof(SName)); + if (NULL == *pTables) { + return TSDB_CODE_OUT_OF_MEMORY; + } - SToken tbnameToken = sToken; - NEXT_TOKEN(pCxt->pSql, sToken); + taosArrayPush(*pTables, pName); + return TSDB_CODE_SUCCESS; +} - bool existedUsing = false; - // USING clause - if (TK_USING == sToken.type) { - existedUsing = true; - CHECK_CODE(collectAutoCreateTableMetaKey(pCxt, tableNo, &tbnameToken)); - NEXT_TOKEN(pCxt->pSql, sToken); - CHECK_CODE(collectTableMetaKey(pCxt, true, tableNo, &sToken)); - CHECK_CODE(skipUsingClause(pCxt)); - NEXT_TOKEN(pCxt->pSql, sToken); +static int32_t buildInsertDbReq(SName* pName, SArray** pDbs) { + if (NULL == *pDbs) { + *pDbs = taosArrayInit(1, sizeof(STablesReq)); + if (NULL == *pDbs) { + return TSDB_CODE_OUT_OF_MEMORY; } + } - if (TK_NK_LP == sToken.type) { - // pSql -> field1_name, ...) - CHECK_CODE(skipBoundColumns(pCxt)); - NEXT_TOKEN(pCxt->pSql, sToken); - } + STablesReq req = {0}; + tNameGetFullDbName(pName, req.dbFName); + buildInsertTableReq(pName, &req.pTables); + taosArrayPush(*pDbs, &req); - if (TK_USING == sToken.type && !existedUsing) { - existedUsing = true; - CHECK_CODE(collectAutoCreateTableMetaKey(pCxt, tableNo, &tbnameToken)); - NEXT_TOKEN(pCxt->pSql, sToken); - CHECK_CODE(collectTableMetaKey(pCxt, true, tableNo, &sToken)); - CHECK_CODE(skipUsingClause(pCxt)); - NEXT_TOKEN(pCxt->pSql, sToken); - } else if (!existedUsing) { - CHECK_CODE(collectTableMetaKey(pCxt, false, tableNo, &tbnameToken)); - } + return TSDB_CODE_SUCCESS; +} - ++tableNo; +static int32_t buildInsertUserAuthReq(const char* pUser, SName* pName, SArray** pUserAuth) { + *pUserAuth = taosArrayInit(1, sizeof(SUserAuthInfo)); + if (NULL == *pUserAuth) { + return TSDB_CODE_OUT_OF_MEMORY; + } - if (TK_VALUES == sToken.type) { - // pSql -> (field1_value, ...) [(field1_value2, ...) ...] - CHECK_CODE(skipValuesClause(pCxt)); - hasData = true; - continue; - } + SUserAuthInfo userAuth = {.type = AUTH_TYPE_WRITE}; + snprintf(userAuth.user, sizeof(userAuth.user), "%s", pUser); + tNameGetFullDbName(pName, userAuth.dbFName); + taosArrayPush(*pUserAuth, &userAuth); - // FILE csv_file_path - if (TK_FILE == sToken.type) { - // pSql -> csv_file_path - NEXT_TOKEN(pCxt->pSql, sToken); - if (0 == sToken.n || (TK_NK_STRING != sToken.type && TK_NK_ID != sToken.type)) { - return buildSyntaxErrMsg(&pCxt->msg, "file path is required following keyword FILE", sToken.z); - } - hasData = true; - continue; + return TSDB_CODE_SUCCESS; +} + +static int32_t buildInsertCatalogReq(SInsertParseContext* pCxt, SVnodeModifOpStmt* pStmt, SCatalogReq* pCatalogReq) { + int32_t code = buildInsertUserAuthReq(pCxt->pComCxt->pUser, &pStmt->targetTableName, &pCatalogReq->pUser); + if (TSDB_CODE_SUCCESS == code) { + if (0 == pStmt->usingTableName.type) { + code = buildInsertDbReq(&pStmt->targetTableName, &pCatalogReq->pTableMeta); + } else { + code = buildInsertDbReq(&pStmt->usingTableName, &pCatalogReq->pTableMeta); } + } + if (TSDB_CODE_SUCCESS == code) { + code = buildInsertDbReq(&pStmt->targetTableName, &pCatalogReq->pTableHash); + } + return code; +} + +static int32_t setNextStageInfo(SInsertParseContext* pCxt, SQuery* pQuery, SCatalogReq* pCatalogReq) { + if (pCxt->missCache) { + parserDebug("0x%" PRIx64 " %d rows have been inserted before cache miss", pCxt->pComCxt->requestId, + ((SVnodeModifOpStmt*)pQuery->pRoot)->totalRowsNum); - return buildSyntaxErrMsg(&pCxt->msg, "keyword VALUES or FILE is expected", sToken.z); + pQuery->execStage = QUERY_EXEC_STAGE_PARSE; + return buildInsertCatalogReq(pCxt, (SVnodeModifOpStmt*)pQuery->pRoot, pCatalogReq); } + parserDebug("0x%" PRIx64 " %d rows have been inserted", pCxt->pComCxt->requestId, + ((SVnodeModifOpStmt*)pQuery->pRoot)->totalRowsNum); + + pQuery->execStage = QUERY_EXEC_STAGE_SCHEDULE; return TSDB_CODE_SUCCESS; } -int32_t parseInsertSyntax(SParseContext* pContext, SQuery** pQuery, SParseMetaCache* pMetaCache) { - SInsertParseSyntaxCxt context = {.pComCxt = pContext, - .pSql = (char*)pContext->pSql, - .msg = {.buf = pContext->pMsg, .len = pContext->msgLen}, - .pMetaCache = pMetaCache}; - int32_t code = skipInsertInto(&context.pSql, &context.msg); +int32_t parseInsertSql(SParseContext* pCxt, SQuery** pQuery, SCatalogReq* pCatalogReq, const SMetaData* pMetaData) { + SInsertParseContext context = { + .pComCxt = pCxt, + .msg = {.buf = pCxt->pMsg, .len = pCxt->msgLen}, + .missCache = false, + .usingDuplicateTable = false, + }; + + int32_t code = initInsertQuery(pCxt, pCatalogReq, pMetaData, pQuery); if (TSDB_CODE_SUCCESS == code) { - code = parseInsertBodySyntax(&context); + code = parseInsertSqlImpl(&context, (SVnodeModifOpStmt*)(*pQuery)->pRoot); } if (TSDB_CODE_SUCCESS == code) { - *pQuery = (SQuery*)nodesMakeNode(QUERY_NODE_QUERY); - if (NULL == *pQuery) { - return TSDB_CODE_OUT_OF_MEMORY; - } + code = setNextStageInfo(&context, *pQuery, pCatalogReq); + } + if ((TSDB_CODE_SUCCESS == code || NEED_CLIENT_HANDLE_ERROR(code)) && + QUERY_EXEC_STAGE_SCHEDULE == (*pQuery)->execStage) { + code = setRefreshMate(*pQuery); } + destroyBoundColumnInfo(&context.tags); return code; } diff --git a/source/libs/parser/src/parInsertStmt.c b/source/libs/parser/src/parInsertStmt.c index f85ceccf6ef2ba23ad4bf3b8c08e98df47fd0a8f..9a5f349d8fe1f9da5bd2290832b3d5ab61cb7688 100644 --- a/source/libs/parser/src/parInsertStmt.c +++ b/source/libs/parser/src/parInsertStmt.c @@ -30,23 +30,17 @@ typedef struct SKvParam { } SKvParam; int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash) { - SVnodeModifOpStmt* modifyNode = (SVnodeModifOpStmt*)pQuery->pRoot; - int32_t code = 0; - SInsertParseContext insertCtx = { - .pVgroupsHashObj = pVgHash, - .pTableBlockHashObj = pBlockHash, - .pOutput = (SVnodeModifOpStmt*)pQuery->pRoot, - }; - + int32_t code = TSDB_CODE_SUCCESS; + SArray* pVgDataBlocks = NULL; // merge according to vgId - if (taosHashGetSize(insertCtx.pTableBlockHashObj) > 0) { - CHECK_CODE(insMergeTableDataBlocks(insertCtx.pTableBlockHashObj, &insertCtx.pVgDataBlocks)); + if (taosHashGetSize(pBlockHash) > 0) { + code = insMergeTableDataBlocks(pBlockHash, &pVgDataBlocks); } - - CHECK_CODE(insBuildOutput(&insertCtx)); - - insDestroyBlockArrayList(insertCtx.pVgDataBlocks); - return TSDB_CODE_SUCCESS; + if (TSDB_CODE_SUCCESS == code) { + code = insBuildOutput(pVgHash, pVgDataBlocks, &((SVnodeModifOpStmt*)pQuery->pRoot)->pDataBlocks); + } + insDestroyBlockArrayList(pVgDataBlocks); + return code; } int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const char* sTableName, char* tName, @@ -222,11 +216,7 @@ int32_t qBindStmtColsValue(void* pBlock, TAOS_MULTI_BIND* bind, char* msgBuf, in } SSubmitBlk* pBlocks = (SSubmitBlk*)(pDataBlock->pData); - if (TSDB_CODE_SUCCESS != insSetBlockInfo(pBlocks, pDataBlock, bind->num)) { - return buildInvalidOperationMsg(&pBuf, "too many rows in sql, total number of rows should be less than INT32_MAX"); - } - - return TSDB_CODE_SUCCESS; + return insSetBlockInfo(pBlocks, pDataBlock, bind->num, &pBuf); } int32_t qBindStmtSingleColValue(void* pBlock, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen, int32_t colIdx, @@ -308,10 +298,7 @@ int32_t qBindStmtSingleColValue(void* pBlock, TAOS_MULTI_BIND* bind, char* msgBu pDataBlock->size += extendedRowSize * bind->num; SSubmitBlk* pBlocks = (SSubmitBlk*)(pDataBlock->pData); - if (TSDB_CODE_SUCCESS != insSetBlockInfo(pBlocks, pDataBlock, bind->num)) { - return buildInvalidOperationMsg(&pBuf, - "too many rows in sql, total number of rows should be less than INT32_MAX"); - } + CHECK_CODE(insSetBlockInfo(pBlocks, pDataBlock, bind->num, &pBuf)); } return TSDB_CODE_SUCCESS; diff --git a/source/libs/parser/src/parInsertUtil.c b/source/libs/parser/src/parInsertUtil.c index 570a6f9859875c2b5af6929236c8eab0cb16fb26..bc09163753d91e883d4e0f176bb97733cfca2c33 100644 --- a/source/libs/parser/src/parInsertUtil.c +++ b/source/libs/parser/src/parInsertUtil.c @@ -110,18 +110,17 @@ void insGetSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo* spd, col_id_t i } } -int32_t insSetBlockInfo(SSubmitBlk* pBlocks, STableDataBlocks* dataBuf, int32_t numOfRows) { +int32_t insSetBlockInfo(SSubmitBlk* pBlocks, STableDataBlocks* dataBuf, int32_t numOfRows, SMsgBuf* pMsg) { pBlocks->suid = (TSDB_NORMAL_TABLE == dataBuf->pTableMeta->tableType ? 0 : dataBuf->pTableMeta->suid); pBlocks->uid = dataBuf->pTableMeta->uid; pBlocks->sversion = dataBuf->pTableMeta->sversion; pBlocks->schemaLen = dataBuf->createTbReqLen; if (pBlocks->numOfRows + numOfRows >= INT32_MAX) { - return TSDB_CODE_TSC_INVALID_OPERATION; - } else { - pBlocks->numOfRows += numOfRows; - return TSDB_CODE_SUCCESS; + return buildInvalidOperationMsg(pMsg, "too many rows in sql, total number of rows should be less than INT32_MAX"); } + pBlocks->numOfRows += numOfRows; + return TSDB_CODE_SUCCESS; } void insSetBoundColumnInfo(SParsedDataColInfo* pColList, SSchema* pSchema, col_id_t numOfCols) { @@ -271,12 +270,8 @@ void insDestroyDataBlock(STableDataBlocks* pDataBlock) { } taosMemoryFreeClear(pDataBlock->pData); - // if (!pDataBlock->cloned) { - // free the refcount for metermeta taosMemoryFreeClear(pDataBlock->pTableMeta); - destroyBoundColumnInfo(&pDataBlock->boundColumnInfo); - // } taosMemoryFreeClear(pDataBlock); } @@ -312,20 +307,6 @@ int32_t insGetDataBlockFromList(SHashObj* pHashList, void* id, int32_t idLen, in return TSDB_CODE_SUCCESS; } -#if 0 -static int32_t getRowExpandSize(STableMeta* pTableMeta) { - int32_t result = TD_ROW_HEAD_LEN - sizeof(TSKEY); - int32_t columns = getNumOfColumns(pTableMeta); - SSchema* pSchema = getTableColumnSchema(pTableMeta); - for (int32_t i = 0; i < columns; ++i) { - if (IS_VAR_DATA_TYPE((pSchema + i)->type)) { - result += TYPE_BYTES[TSDB_DATA_TYPE_BINARY]; - } - } - result += (int32_t)TD_BITMAP_BYTES(columns - 1); - return result; -} -#endif void insDestroyBlockArrayList(SArray* pDataBlockList) { if (pDataBlockList == NULL) { @@ -357,51 +338,6 @@ void insDestroyBlockHashmap(SHashObj* pDataBlockHash) { taosHashCleanup(pDataBlockHash); } -#if 0 -// data block is disordered, sort it in ascending order -void sortRemoveDataBlockDupRowsRaw(STableDataBlocks* dataBuf) { - SSubmitBlk* pBlocks = (SSubmitBlk*)dataBuf->pData; - - // size is less than the total size, since duplicated rows may be removed yet. - assert(pBlocks->numOfRows * dataBuf->rowSize + sizeof(SSubmitBlk) == dataBuf->size); - - if (!dataBuf->ordered) { - char* pBlockData = pBlocks->data; - - // todo. qsort is unstable, if timestamp is same, should get the last one - taosSort(pBlockData, pBlocks->numOfRows, dataBuf->rowSize, rowDataCompar); - - int32_t i = 0; - int32_t j = 1; - - // delete rows with timestamp conflicts - while (j < pBlocks->numOfRows) { - TSKEY ti = *(TSKEY*)(pBlockData + dataBuf->rowSize * i); - TSKEY tj = *(TSKEY*)(pBlockData + dataBuf->rowSize * j); - - if (ti == tj) { - ++j; - continue; - } - - int32_t nextPos = (++i); - if (nextPos != j) { - memmove(pBlockData + dataBuf->rowSize * nextPos, pBlockData + dataBuf->rowSize * j, dataBuf->rowSize); - } - - ++j; - } - - dataBuf->ordered = true; - - pBlocks->numOfRows = i + 1; - dataBuf->size = sizeof(SSubmitBlk) + dataBuf->rowSize * pBlocks->numOfRows; - } - - dataBuf->prevTS = INT64_MIN; -} -#endif - // data block is disordered, sort it in ascending order static int sortRemoveDataBlockDupRows(STableDataBlocks* dataBuf, SBlockKeyInfo* pBlkKeyInfo) { SSubmitBlk* pBlocks = (SSubmitBlk*)dataBuf->pData; @@ -896,6 +832,10 @@ int32_t insCreateSName(SName* pName, SToken* pTableName, int32_t acctId, const c } } + if (NULL != strchr(pName->tname, '.')) { + code = generateSyntaxErrMsgExt(pMsgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, "The table name cannot contain '.'"); + } + return code; } @@ -994,24 +934,24 @@ static void buildMsgHeader(STableDataBlocks* src, SVgDataBlocks* blocks) { } } -int32_t insBuildOutput(SInsertParseContext* pCxt) { - size_t numOfVg = taosArrayGetSize(pCxt->pVgDataBlocks); - pCxt->pOutput->pDataBlocks = taosArrayInit(numOfVg, POINTER_BYTES); - if (NULL == pCxt->pOutput->pDataBlocks) { +int32_t insBuildOutput(SHashObj* pVgroupsHashObj, SArray* pVgDataBlocks, SArray** pDataBlocks) { + size_t numOfVg = taosArrayGetSize(pVgDataBlocks); + *pDataBlocks = taosArrayInit(numOfVg, POINTER_BYTES); + if (NULL == *pDataBlocks) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } for (size_t i = 0; i < numOfVg; ++i) { - STableDataBlocks* src = taosArrayGetP(pCxt->pVgDataBlocks, i); + STableDataBlocks* src = taosArrayGetP(pVgDataBlocks, i); SVgDataBlocks* dst = taosMemoryCalloc(1, sizeof(SVgDataBlocks)); if (NULL == dst) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } - taosHashGetDup(pCxt->pVgroupsHashObj, (const char*)&src->vgId, sizeof(src->vgId), &dst->vg); + taosHashGetDup(pVgroupsHashObj, (const char*)&src->vgId, sizeof(src->vgId), &dst->vg); dst->numOfTables = src->numOfTables; dst->size = src->size; TSWAP(dst->pData, src->pData); buildMsgHeader(src, dst); - taosArrayPush(pCxt->pOutput->pDataBlocks, &dst); + taosArrayPush(*pDataBlocks, &dst); } return TSDB_CODE_SUCCESS; } diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index afcd3610f467d27c89e38a1845e37d5056fd3e4b..88a1d39ff25aa554a78346fb363dd19d2180d82e 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -92,10 +92,12 @@ static SKeyword keywordTable[] = { {"EVERY", TK_EVERY}, {"FILE", TK_FILE}, {"FILL", TK_FILL}, + {"FILL_HISTORY", TK_FILL_HISTORY}, {"FIRST", TK_FIRST}, {"FLOAT", TK_FLOAT}, {"FLUSH", TK_FLUSH}, {"FROM", TK_FROM}, + {"FORCE", TK_FORCE}, {"FUNCTION", TK_FUNCTION}, {"FUNCTIONS", TK_FUNCTIONS}, {"GRANT", TK_GRANT}, diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 48e360d61ea856c893c66f34e315ec68c62e6c59..82170a27d813577cd44294517fbdbb71e93e006c 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -674,6 +674,10 @@ static bool isSelectFunc(const SNode* pNode) { return (QUERY_NODE_FUNCTION == nodeType(pNode) && fmIsSelectFunc(((SFunctionNode*)pNode)->funcId)); } +static bool isWindowPseudoColumnFunc(const SNode* pNode) { + return (QUERY_NODE_FUNCTION == nodeType(pNode) && fmIsWindowPseudoColumnFunc(((SFunctionNode*)pNode)->funcId)); +} + static bool isTimelineFunc(const SNode* pNode) { return (QUERY_NODE_FUNCTION == nodeType(pNode) && fmIsTimelineFunc(((SFunctionNode*)pNode)->funcId)); } @@ -1264,10 +1268,7 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) { } static EDealRes haveVectorFunction(SNode* pNode, void* pContext) { - if (isAggFunc(pNode)) { - *((bool*)pContext) = true; - return DEAL_RES_END; - } else if (isIndefiniteRowsFunc(pNode)) { + if (isAggFunc(pNode) || isIndefiniteRowsFunc(pNode) || isWindowPseudoColumnFunc(pNode)) { *((bool*)pContext) = true; return DEAL_RES_END; } @@ -2180,7 +2181,8 @@ static int32_t getTagsTableVgroupListImpl(STranslateContext* pCxt, SName* pTarge if (TSDB_DB_NAME_T == pTargetName->type) { int32_t code = getDBVgInfoImpl(pCxt, pTargetName, pVgroupList); - if (TSDB_CODE_MND_DB_NOT_EXIST == code) { + if (TSDB_CODE_MND_DB_NOT_EXIST == code || TSDB_CODE_MND_DB_IN_CREATING == code || + TSDB_CODE_MND_DB_IN_DROPPING == code) { code = TSDB_CODE_SUCCESS; } return code; @@ -2195,7 +2197,8 @@ static int32_t getTagsTableVgroupListImpl(STranslateContext* pCxt, SName* pTarge } else { taosArrayPush(*pVgroupList, &vgInfo); } - } else if (TSDB_CODE_MND_DB_NOT_EXIST == code) { + } else if (TSDB_CODE_MND_DB_NOT_EXIST == code || TSDB_CODE_MND_DB_IN_CREATING == code || + TSDB_CODE_MND_DB_IN_DROPPING == code) { code = TSDB_CODE_SUCCESS; } return code; @@ -2390,6 +2393,9 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) { if (TSDB_SUPER_TABLE == pRealTable->pMeta->tableType) { pCxt->stableQuery = true; } + if (TSDB_SYSTEM_TABLE == pRealTable->pMeta->tableType && isSelectStmt(pCxt->pCurrStmt)) { + ((SSelectStmt*)pCxt->pCurrStmt)->isTimeLineResult = false; + } code = addNamespace(pCxt, pRealTable); } break; @@ -3020,20 +3026,17 @@ static int32_t translateIntervalWindow(STranslateContext* pCxt, SSelectStmt* pSe return code; } -static EDealRes checkStateExpr(SNode* pNode, void* pContext) { - if (QUERY_NODE_COLUMN == nodeType(pNode)) { - STranslateContext* pCxt = pContext; - SColumnNode* pCol = (SColumnNode*)pNode; +static int32_t checkStateExpr(STranslateContext* pCxt, SNode* pNode) { + int32_t type = ((SExprNode*)pNode)->resType.type; + if (!IS_INTEGER_TYPE(type) && type != TSDB_DATA_TYPE_BOOL && !IS_VAR_DATA_TYPE(type)) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STATE_WIN_TYPE); + } - int32_t type = pCol->node.resType.type; - if (!IS_INTEGER_TYPE(type) && type != TSDB_DATA_TYPE_BOOL && !IS_VAR_DATA_TYPE(type)) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_TYPE); - } - if (COLUMN_TYPE_TAG == pCol->colType) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_COL); - } + if (QUERY_NODE_COLUMN == nodeType(pNode) && COLUMN_TYPE_TAG == ((SColumnNode*)pNode)->colType) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STATE_WIN_COL); } - return DEAL_RES_CONTINUE; + + return TSDB_CODE_SUCCESS; } static bool hasPartitionByTbname(SNodeList* pPartitionByList) { @@ -3065,11 +3068,11 @@ static int32_t translateStateWindow(STranslateContext* pCxt, SSelectStmt* pSelec } SStateWindowNode* pState = (SStateWindowNode*)pSelect->pWindow; - nodesWalkExprPostOrder(pState->pExpr, checkStateExpr, pCxt); - if (TSDB_CODE_SUCCESS == pCxt->errCode) { - pCxt->errCode = checkStateWindowForStream(pCxt, pSelect); + int32_t code = checkStateExpr(pCxt, pState->pExpr); + if (TSDB_CODE_SUCCESS == code) { + code = checkStateWindowForStream(pCxt, pSelect); } - return pCxt->errCode; + return code; } static int32_t translateSessionWindow(STranslateContext* pCxt, SSelectStmt* pSelect) { @@ -3428,6 +3431,19 @@ static SNode* createSetOperProject(const char* pTableAlias, SNode* pNode) { return (SNode*)pCol; } +// 0 means equal, 1 means the left shall prevail, -1 means the right shall prevail +static int32_t dataTypeComp(const SDataType* l, const SDataType* r) { + if (l->type != r->type) { + return 1; + } + + if (l->bytes != r->bytes) { + return l->bytes > r->bytes ? 1 : -1; + } + + return (l->precision == r->precision && l->scale == r->scale) ? 0 : 1; +} + static int32_t translateSetOperProject(STranslateContext* pCxt, SSetOperator* pSetOperator) { SNodeList* pLeftProjections = getProjectList(pSetOperator->pLeft); SNodeList* pRightProjections = getProjectList(pSetOperator->pRight); @@ -3440,7 +3456,8 @@ static int32_t translateSetOperProject(STranslateContext* pCxt, SSetOperator* pS FORBOTH(pLeft, pLeftProjections, pRight, pRightProjections) { SExprNode* pLeftExpr = (SExprNode*)pLeft; SExprNode* pRightExpr = (SExprNode*)pRight; - if (!dataTypeEqual(&pLeftExpr->resType, &pRightExpr->resType)) { + int32_t comp = dataTypeComp(&pLeftExpr->resType, &pRightExpr->resType); + if (comp > 0) { SNode* pRightFunc = NULL; int32_t code = createCastFunc(pCxt, pRight, pLeftExpr->resType, &pRightFunc); if (TSDB_CODE_SUCCESS != code) { @@ -3448,9 +3465,20 @@ static int32_t translateSetOperProject(STranslateContext* pCxt, SSetOperator* pS } REPLACE_LIST2_NODE(pRightFunc); pRightExpr = (SExprNode*)pRightFunc; - } - strcpy(pRightExpr->aliasName, pLeftExpr->aliasName); - pRightExpr->aliasName[strlen(pLeftExpr->aliasName)] = '\0'; + } else if (comp < 0) { + SNode* pLeftFunc = NULL; + int32_t code = createCastFunc(pCxt, pLeft, pRightExpr->resType, &pLeftFunc); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + REPLACE_LIST1_NODE(pLeftFunc); + SExprNode* pLeftFuncExpr = (SExprNode*)pLeftFunc; + snprintf(pLeftFuncExpr->aliasName, sizeof(pLeftFuncExpr->aliasName), "%s", pLeftExpr->aliasName); + snprintf(pLeftFuncExpr->userAlias, sizeof(pLeftFuncExpr->userAlias), "%s", pLeftExpr->userAlias); + pLeft = pLeftFunc; + pLeftExpr = pLeftFuncExpr; + } + snprintf(pRightExpr->aliasName, sizeof(pRightExpr->aliasName), "%s", pLeftExpr->aliasName); if (TSDB_CODE_SUCCESS != nodesListMakeStrictAppend(&pSetOperator->pProjectionList, createSetOperProject(pSetOperator->stmtName, pLeft))) { return TSDB_CODE_OUT_OF_MEMORY; @@ -4995,6 +5023,7 @@ static int32_t translateDropDnode(STranslateContext* pCxt, SDropDnodeStmt* pStmt dropReq.dnodeId = pStmt->dnodeId; strcpy(dropReq.fqdn, pStmt->fqdn); dropReq.port = pStmt->port; + dropReq.force = pStmt->force; return buildCmdMsg(pCxt, TDMT_MND_DROP_DNODE, (FSerializeFunc)tSerializeSDropDnodeReq, &dropReq); } @@ -5158,7 +5187,7 @@ static int32_t translateCreateIndex(STranslateContext* pCxt, SCreateIndexStmt* p static int32_t translateDropIndex(STranslateContext* pCxt, SDropIndexStmt* pStmt) { SMDropSmaReq dropSmaReq = {0}; SName name; - tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pCxt->pParseCxt->db, pStmt->indexName, &name), dropSmaReq.name); + tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pStmt->indexDbName, pStmt->indexName, &name), dropSmaReq.name); dropSmaReq.igNotExists = pStmt->ignoreNotExists; return buildCmdMsg(pCxt, TDMT_MND_DROP_SMA, (FSerializeFunc)tSerializeSMDropSmaReq, &dropSmaReq); } @@ -5279,7 +5308,7 @@ static int32_t translateCreateTopic(STranslateContext* pCxt, SCreateTopicStmt* p code = buildCreateTopicReq(pCxt, pStmt, &createReq); } if (TSDB_CODE_SUCCESS == code) { - code = buildCmdMsg(pCxt, TDMT_MND_CREATE_TOPIC, (FSerializeFunc)tSerializeSCMCreateTopicReq, &createReq); + code = buildCmdMsg(pCxt, TDMT_MND_TMQ_CREATE_TOPIC, (FSerializeFunc)tSerializeSCMCreateTopicReq, &createReq); } tFreeSCMCreateTopicReq(&createReq); return code; @@ -5293,7 +5322,7 @@ static int32_t translateDropTopic(STranslateContext* pCxt, SDropTopicStmt* pStmt tNameGetFullDbName(&name, dropReq.name); dropReq.igNotExists = pStmt->ignoreNotExists; - return buildCmdMsg(pCxt, TDMT_MND_DROP_TOPIC, (FSerializeFunc)tSerializeSMDropTopicReq, &dropReq); + return buildCmdMsg(pCxt, TDMT_MND_TMQ_DROP_TOPIC, (FSerializeFunc)tSerializeSMDropTopicReq, &dropReq); } static int32_t translateDropCGroup(STranslateContext* pCxt, SDropCGroupStmt* pStmt) { @@ -5305,7 +5334,7 @@ static int32_t translateDropCGroup(STranslateContext* pCxt, SDropCGroupStmt* pSt dropReq.igNotExists = pStmt->ignoreNotExists; strcpy(dropReq.cgroup, pStmt->cgroup); - return buildCmdMsg(pCxt, TDMT_MND_MQ_DROP_CGROUP, (FSerializeFunc)tSerializeSMDropCgroupReq, &dropReq); + return buildCmdMsg(pCxt, TDMT_MND_TMQ_DROP_CGROUP, (FSerializeFunc)tSerializeSMDropCgroupReq, &dropReq); } static int32_t translateAlterLocal(STranslateContext* pCxt, SAlterLocalStmt* pStmt) { @@ -5542,6 +5571,7 @@ static int32_t buildCreateStreamReq(STranslateContext* pCxt, SCreateStreamStmt* pReq->triggerType = pStmt->pOptions->triggerType; pReq->maxDelay = (NULL != pStmt->pOptions->pDelay ? ((SValueNode*)pStmt->pOptions->pDelay)->datum.i : 0); pReq->watermark = (NULL != pStmt->pOptions->pWatermark ? ((SValueNode*)pStmt->pOptions->pWatermark)->datum.i : 0); + pReq->fillHistory = pStmt->pOptions->fillHistory; pReq->igExpired = pStmt->pOptions->ignoreExpired; columnDefNodeToField(pStmt->pTags, &pReq->pTags); pReq->numOfTags = LIST_LENGTH(pStmt->pTags); diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index d98d513d5d8891baed2a6bd30590fd2e6964aacb..466c6edd2488a5ec65ca5918a8ee0d21df24fa33 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -612,62 +612,7 @@ static int32_t buildUdfReq(SHashObj* pUdfHash, SArray** pUdf) { return TSDB_CODE_SUCCESS; } -static int32_t buildCatalogReqForInsert(SParseContext* pCxt, const SParseMetaCache* pMetaCache, - SCatalogReq* pCatalogReq) { - int32_t ndbs = taosHashGetSize(pMetaCache->pInsertTables); - pCatalogReq->pTableMeta = taosArrayInit(ndbs, sizeof(STablesReq)); - if (NULL == pCatalogReq->pTableMeta) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCatalogReq->pTableHash = taosArrayInit(ndbs, sizeof(STablesReq)); - if (NULL == pCatalogReq->pTableHash) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pCatalogReq->pUser = taosArrayInit(ndbs, sizeof(SUserAuthInfo)); - if (NULL == pCatalogReq->pUser) { - return TSDB_CODE_OUT_OF_MEMORY; - } - - pCxt->pTableMetaPos = taosArrayInit(pMetaCache->sqlTableNum, sizeof(int32_t)); - pCxt->pTableVgroupPos = taosArrayInit(pMetaCache->sqlTableNum, sizeof(int32_t)); - - int32_t metaReqNo = 0; - int32_t vgroupReqNo = 0; - SInsertTablesMetaReq* p = taosHashIterate(pMetaCache->pInsertTables, NULL); - while (NULL != p) { - STablesReq req = {0}; - strcpy(req.dbFName, p->dbFName); - TSWAP(req.pTables, p->pTableMetaReq); - taosArrayPush(pCatalogReq->pTableMeta, &req); - - req.pTables = NULL; - TSWAP(req.pTables, p->pTableVgroupReq); - taosArrayPush(pCatalogReq->pTableHash, &req); - - int32_t ntables = taosArrayGetSize(p->pTableMetaPos); - for (int32_t i = 0; i < ntables; ++i) { - taosArrayInsert(pCxt->pTableMetaPos, *(int32_t*)taosArrayGet(p->pTableMetaPos, i), &metaReqNo); - ++metaReqNo; - } - - ntables = taosArrayGetSize(p->pTableVgroupPos); - for (int32_t i = 0; i < ntables; ++i) { - taosArrayInsert(pCxt->pTableVgroupPos, *(int32_t*)taosArrayGet(p->pTableVgroupPos, i), &vgroupReqNo); - ++vgroupReqNo; - } - - SUserAuthInfo auth = {0}; - snprintf(auth.user, sizeof(auth.user), "%s", pCxt->pUser); - snprintf(auth.dbFName, sizeof(auth.dbFName), "%s", p->dbFName); - auth.type = AUTH_TYPE_WRITE; - taosArrayPush(pCatalogReq->pUser, &auth); - - p = taosHashIterate(pMetaCache->pInsertTables, p); - } - return TSDB_CODE_SUCCESS; -} - -int32_t buildCatalogReqForQuery(const SParseMetaCache* pMetaCache, SCatalogReq* pCatalogReq) { +int32_t buildCatalogReq(const SParseMetaCache* pMetaCache, SCatalogReq* pCatalogReq) { int32_t code = buildTableReqFromDb(pMetaCache->pTableMeta, &pCatalogReq->pTableMeta); if (TSDB_CODE_SUCCESS == code) { code = buildDbReq(pMetaCache->pDbVgroup, &pCatalogReq->pDbVgroup); @@ -697,13 +642,6 @@ int32_t buildCatalogReqForQuery(const SParseMetaCache* pMetaCache, SCatalogReq* return code; } -int32_t buildCatalogReq(SParseContext* pCxt, const SParseMetaCache* pMetaCache, SCatalogReq* pCatalogReq) { - if (NULL != pMetaCache->pInsertTables) { - return buildCatalogReqForInsert(pCxt, pMetaCache, pCatalogReq); - } - return buildCatalogReqForQuery(pMetaCache, pCatalogReq); -} - static int32_t putMetaDataToHash(const char* pKey, int32_t len, const SArray* pData, int32_t index, SHashObj** pHash) { if (NULL == *pHash) { *pHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); @@ -791,8 +729,7 @@ static int32_t putUdfToCache(const SArray* pUdfReq, const SArray* pUdfData, SHas return TSDB_CODE_SUCCESS; } -int32_t putMetaDataToCacheForQuery(const SCatalogReq* pCatalogReq, const SMetaData* pMetaData, - SParseMetaCache* pMetaCache) { +int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMetaData, SParseMetaCache* pMetaCache) { int32_t code = putDbTableDataToCache(pCatalogReq->pTableMeta, pMetaData->pTableMeta, &pMetaCache->pTableMeta); if (TSDB_CODE_SUCCESS == code) { code = putDbDataToCache(pCatalogReq->pDbVgroup, pMetaData->pDbVgroup, &pMetaCache->pDbVgroup); @@ -822,30 +759,6 @@ int32_t putMetaDataToCacheForQuery(const SCatalogReq* pCatalogReq, const SMetaDa return code; } -int32_t putMetaDataToCacheForInsert(const SMetaData* pMetaData, SParseMetaCache* pMetaCache) { - int32_t ndbs = taosArrayGetSize(pMetaData->pUser); - for (int32_t i = 0; i < ndbs; ++i) { - SMetaRes* pRes = taosArrayGet(pMetaData->pUser, i); - if (TSDB_CODE_SUCCESS != pRes->code) { - return pRes->code; - } - if (!(*(bool*)pRes->pRes)) { - return TSDB_CODE_PAR_PERMISSION_DENIED; - } - } - pMetaCache->pTableMetaData = pMetaData->pTableMeta; - pMetaCache->pTableVgroupData = pMetaData->pTableHash; - return TSDB_CODE_SUCCESS; -} - -int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMetaData, SParseMetaCache* pMetaCache, - bool insertValuesStmt) { - if (insertValuesStmt) { - return putMetaDataToCacheForInsert(pMetaData, pMetaCache); - } - return putMetaDataToCacheForQuery(pCatalogReq, pMetaData, pMetaCache); -} - static int32_t reserveTableReqInCacheImpl(const char* pTbFName, int32_t len, SHashObj** pTables) { if (NULL == *pTables) { *pTables = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); @@ -1146,82 +1059,6 @@ int32_t getDnodeListFromCache(SParseMetaCache* pMetaCache, SArray** pDnodes) { return TSDB_CODE_SUCCESS; } -static int32_t reserveTableReqInCacheForInsert(const SName* pName, ECatalogReqType reqType, int32_t tableNo, - SInsertTablesMetaReq* pReq) { - switch (reqType) { - case CATALOG_REQ_TYPE_META: - taosArrayPush(pReq->pTableMetaReq, pName); - taosArrayPush(pReq->pTableMetaPos, &tableNo); - break; - case CATALOG_REQ_TYPE_VGROUP: - taosArrayPush(pReq->pTableVgroupReq, pName); - taosArrayPush(pReq->pTableVgroupPos, &tableNo); - break; - case CATALOG_REQ_TYPE_BOTH: - taosArrayPush(pReq->pTableMetaReq, pName); - taosArrayPush(pReq->pTableMetaPos, &tableNo); - taosArrayPush(pReq->pTableVgroupReq, pName); - taosArrayPush(pReq->pTableVgroupPos, &tableNo); - break; - default: - break; - } - return TSDB_CODE_SUCCESS; -} - -static int32_t reserveTableReqInDbCacheForInsert(const SName* pName, ECatalogReqType reqType, int32_t tableNo, - SHashObj* pDbs) { - SInsertTablesMetaReq req = {.pTableMetaReq = taosArrayInit(4, sizeof(SName)), - .pTableMetaPos = taosArrayInit(4, sizeof(int32_t)), - .pTableVgroupReq = taosArrayInit(4, sizeof(SName)), - .pTableVgroupPos = taosArrayInit(4, sizeof(int32_t))}; - tNameGetFullDbName(pName, req.dbFName); - int32_t code = reserveTableReqInCacheForInsert(pName, reqType, tableNo, &req); - if (TSDB_CODE_SUCCESS == code) { - code = taosHashPut(pDbs, pName->dbname, strlen(pName->dbname), &req, sizeof(SInsertTablesMetaReq)); - } - return code; -} - -int32_t reserveTableMetaInCacheForInsert(const SName* pName, ECatalogReqType reqType, int32_t tableNo, - SParseMetaCache* pMetaCache) { - if (NULL == pMetaCache->pInsertTables) { - pMetaCache->pInsertTables = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); - if (NULL == pMetaCache->pInsertTables) { - return TSDB_CODE_OUT_OF_MEMORY; - } - } - pMetaCache->sqlTableNum = tableNo; - SInsertTablesMetaReq* pReq = taosHashGet(pMetaCache->pInsertTables, pName->dbname, strlen(pName->dbname)); - if (NULL == pReq) { - return reserveTableReqInDbCacheForInsert(pName, reqType, tableNo, pMetaCache->pInsertTables); - } - return reserveTableReqInCacheForInsert(pName, reqType, tableNo, pReq); -} - -int32_t getTableMetaFromCacheForInsert(SArray* pTableMetaPos, SParseMetaCache* pMetaCache, int32_t tableNo, - STableMeta** pMeta) { - int32_t reqIndex = *(int32_t*)taosArrayGet(pTableMetaPos, tableNo); - SMetaRes* pRes = taosArrayGet(pMetaCache->pTableMetaData, reqIndex); - if (TSDB_CODE_SUCCESS == pRes->code) { - *pMeta = tableMetaDup((const STableMeta*)pRes->pRes); - if (NULL == *pMeta) { - return TSDB_CODE_OUT_OF_MEMORY; - } - } - return pRes->code; -} - -int32_t getTableVgroupFromCacheForInsert(SArray* pTableVgroupPos, SParseMetaCache* pMetaCache, int32_t tableNo, - SVgroupInfo* pVgroup) { - int32_t reqIndex = *(int32_t*)taosArrayGet(pTableVgroupPos, tableNo); - SMetaRes* pRes = taosArrayGet(pMetaCache->pTableVgroupData, reqIndex); - if (TSDB_CODE_SUCCESS == pRes->code) { - memcpy(pVgroup, pRes->pRes, sizeof(SVgroupInfo)); - } - return pRes->code; -} - void destoryParseTablesMetaReqHash(SHashObj* pHash) { SParseTablesMetaReq* p = taosHashIterate(pHash, NULL); while (NULL != p) { @@ -1239,16 +1076,6 @@ void destoryParseMetaCache(SParseMetaCache* pMetaCache, bool request) { taosHashCleanup(pMetaCache->pTableMeta); taosHashCleanup(pMetaCache->pTableVgroup); } - SInsertTablesMetaReq* p = taosHashIterate(pMetaCache->pInsertTables, NULL); - while (NULL != p) { - taosArrayDestroy(p->pTableMetaPos); - taosArrayDestroy(p->pTableMetaReq); - taosArrayDestroy(p->pTableVgroupPos); - taosArrayDestroy(p->pTableVgroupReq); - - p = taosHashIterate(pMetaCache->pInsertTables, p); - } - taosHashCleanup(pMetaCache->pInsertTables); taosHashCleanup(pMetaCache->pDbVgroup); taosHashCleanup(pMetaCache->pDbCfg); taosHashCleanup(pMetaCache->pDbInfo); diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index 748478778adf2a16434c7290b213a21fab8b1ea2..cf338d63ff43182330d2f1e229aa2a03070feb6a 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -167,7 +167,7 @@ static void rewriteExprAlias(SNode* pRoot) { int32_t qParseSql(SParseContext* pCxt, SQuery** pQuery) { int32_t code = TSDB_CODE_SUCCESS; if (qIsInsertValuesSql(pCxt->pSql, pCxt->sqlLen)) { - code = parseInsertSql(pCxt, pQuery, NULL); + code = parseInsertSql(pCxt, pQuery, NULL, NULL); } else { code = parseSqlIntoAst(pCxt, pQuery); } @@ -175,21 +175,26 @@ int32_t qParseSql(SParseContext* pCxt, SQuery** pQuery) { return code; } -int32_t qParseSqlSyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq) { +static int32_t parseQuerySyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq) { SParseMetaCache metaCache = {0}; - int32_t code = nodesAcquireAllocator(pCxt->allocatorId); + int32_t code = parseSqlSyntax(pCxt, pQuery, &metaCache); + if (TSDB_CODE_SUCCESS == code) { + code = buildCatalogReq(&metaCache, pCatalogReq); + } + destoryParseMetaCache(&metaCache, true); + return code; +} + +int32_t qParseSqlSyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq) { + int32_t code = nodesAcquireAllocator(pCxt->allocatorId); if (TSDB_CODE_SUCCESS == code) { if (qIsInsertValuesSql(pCxt->pSql, pCxt->sqlLen)) { - code = parseInsertSyntax(pCxt, pQuery, &metaCache); + code = parseInsertSql(pCxt, pQuery, pCatalogReq, NULL); } else { - code = parseSqlSyntax(pCxt, pQuery, &metaCache); + code = parseQuerySyntax(pCxt, pQuery, pCatalogReq); } } - if (TSDB_CODE_SUCCESS == code) { - code = buildCatalogReq(pCxt, &metaCache, pCatalogReq); - } nodesReleaseAllocator(pCxt->allocatorId); - destoryParseMetaCache(&metaCache, true); terrno = code; return code; } @@ -199,14 +204,10 @@ int32_t qAnalyseSqlSemantic(SParseContext* pCxt, const struct SCatalogReq* pCata SParseMetaCache metaCache = {0}; int32_t code = nodesAcquireAllocator(pCxt->allocatorId); if (TSDB_CODE_SUCCESS == code) { - code = putMetaDataToCache(pCatalogReq, pMetaData, &metaCache, NULL == pQuery->pRoot); + code = putMetaDataToCache(pCatalogReq, pMetaData, &metaCache); } if (TSDB_CODE_SUCCESS == code) { - if (NULL == pQuery->pRoot) { - code = parseInsertSql(pCxt, &pQuery, &metaCache); - } else { - code = analyseSemantic(pCxt, pQuery, &metaCache); - } + code = analyseSemantic(pCxt, pQuery, &metaCache); } nodesReleaseAllocator(pCxt->allocatorId); destoryParseMetaCache(&metaCache, false); @@ -214,6 +215,11 @@ int32_t qAnalyseSqlSemantic(SParseContext* pCxt, const struct SCatalogReq* pCata return code; } +int32_t qContinueParseSql(SParseContext* pCxt, struct SCatalogReq* pCatalogReq, const struct SMetaData* pMetaData, + SQuery* pQuery) { + return parseInsertSql(pCxt, &pQuery, pCatalogReq, pMetaData); +} + void qDestroyParseContext(SParseContext* pCxt) { if (NULL == pCxt) { return; diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index a7f335ee26134487d71cda2c9be15a487004fe03..292060515cf78652164466af5a93e9229cbe0806 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -104,26 +104,26 @@ #endif /************* Begin control #defines *****************************************/ #define YYCODETYPE unsigned short int -#define YYNOCODE 449 +#define YYNOCODE 452 #define YYACTIONTYPE unsigned short int #define ParseTOKENTYPE SToken typedef union { int yyinit; ParseTOKENTYPE yy0; - EOrder yy14; - bool yy39; - SToken yy181; - EJoinType yy202; - int32_t yy276; - SNodeList* yy282; - int8_t yy293; - ENullOrder yy305; - SDataType yy380; - EFillMode yy381; - SAlterOption yy645; - EOperatorType yy682; - SNode* yy778; - int64_t yy831; + EOperatorType yy4; + int64_t yy37; + SAlterOption yy101; + SNode* yy232; + SDataType yy264; + SNodeList* yy288; + SToken yy481; + int8_t yy607; + EFillMode yy614; + int32_t yy692; + EJoinType yy700; + bool yy777; + ENullOrder yy833; + EOrder yy866; } YYMINORTYPE; #ifndef YYSTACKDEPTH #define YYSTACKDEPTH 100 @@ -139,17 +139,17 @@ typedef union { #define ParseCTX_FETCH #define ParseCTX_STORE #define YYFALLBACK 1 -#define YYNSTATE 698 -#define YYNRULE 525 -#define YYNTOKEN 317 -#define YY_MAX_SHIFT 697 -#define YY_MIN_SHIFTREDUCE 1031 -#define YY_MAX_SHIFTREDUCE 1555 -#define YY_ERROR_ACTION 1556 -#define YY_ACCEPT_ACTION 1557 -#define YY_NO_ACTION 1558 -#define YY_MIN_REDUCE 1559 -#define YY_MAX_REDUCE 2083 +#define YYNSTATE 701 +#define YYNRULE 528 +#define YYNTOKEN 319 +#define YY_MAX_SHIFT 700 +#define YY_MIN_SHIFTREDUCE 1036 +#define YY_MAX_SHIFTREDUCE 1563 +#define YY_ERROR_ACTION 1564 +#define YY_ACCEPT_ACTION 1565 +#define YY_NO_ACTION 1566 +#define YY_MIN_REDUCE 1567 +#define YY_MAX_REDUCE 2094 /************* End control #defines *******************************************/ #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) @@ -216,755 +216,861 @@ typedef union { ** yy_default[] Default action for each state. ** *********** Begin parsing tables **********************************************/ -#define YY_ACTTAB_COUNT (2819) +#define YY_ACTTAB_COUNT (3333) static const YYACTIONTYPE yy_action[] = { - /* 0 */ 1885, 34, 268, 1885, 157, 1064, 1571, 1899, 62, 536, - /* 10 */ 1701, 1881, 44, 42, 1881, 448, 336, 449, 1594, 1811, - /* 20 */ 351, 1881, 1336, 43, 41, 40, 39, 38, 590, 156, - /* 30 */ 167, 1557, 1361, 1416, 1663, 1334, 1917, 1877, 1883, 339, - /* 40 */ 1877, 1883, 345, 1749, 591, 1068, 1069, 1877, 1883, 1867, - /* 50 */ 597, 603, 30, 597, 447, 1582, 1411, 451, 37, 36, - /* 60 */ 597, 17, 43, 41, 40, 39, 38, 1899, 1342, 44, - /* 70 */ 42, 1486, 1897, 1581, 507, 590, 1933, 351, 575, 1336, - /* 80 */ 97, 1898, 1900, 607, 1902, 1903, 602, 77, 597, 517, - /* 90 */ 1416, 366, 1334, 168, 1, 1986, 1917, 1867, 58, 344, - /* 100 */ 1982, 125, 46, 219, 604, 587, 58, 2054, 532, 1867, - /* 110 */ 1705, 603, 173, 1411, 536, 1867, 694, 510, 17, 1580, - /* 120 */ 2012, 504, 574, 171, 1812, 1342, 218, 2055, 576, 1362, - /* 130 */ 1418, 1419, 605, 2059, 132, 587, 1933, 2054, 396, 1579, - /* 140 */ 98, 350, 1900, 607, 1902, 1903, 602, 456, 597, 449, - /* 150 */ 1594, 1, 2060, 171, 1081, 1986, 1080, 2055, 576, 315, - /* 160 */ 1982, 1867, 2054, 64, 132, 7, 63, 58, 1490, 484, - /* 170 */ 2054, 130, 337, 694, 1361, 1337, 311, 1335, 2058, 220, - /* 180 */ 154, 1867, 2055, 2057, 1082, 574, 171, 1418, 1419, 1712, - /* 190 */ 2055, 576, 589, 169, 1994, 1995, 1362, 1999, 465, 1340, - /* 200 */ 1341, 121, 1391, 1392, 1394, 1395, 1396, 1397, 1398, 1399, - /* 210 */ 1400, 1401, 599, 595, 1409, 1410, 1412, 1413, 1414, 1415, - /* 220 */ 1417, 1420, 3, 265, 1994, 586, 1687, 585, 1756, 1757, - /* 230 */ 2054, 1426, 1337, 385, 1335, 79, 313, 1361, 390, 539, - /* 240 */ 174, 1512, 498, 497, 174, 574, 171, 389, 174, 388, - /* 250 */ 2055, 576, 174, 387, 383, 532, 1340, 1341, 58, 1391, - /* 260 */ 1392, 1394, 1395, 1396, 1397, 1398, 1399, 1400, 1401, 599, - /* 270 */ 595, 1409, 1410, 1412, 1413, 1414, 1415, 1417, 1420, 3, - /* 280 */ 44, 42, 697, 182, 2054, 234, 235, 1361, 351, 77, - /* 290 */ 1336, 562, 1510, 1511, 1513, 1514, 275, 549, 1899, 2060, - /* 300 */ 171, 1416, 549, 1334, 2055, 576, 1230, 1231, 2059, 52, - /* 310 */ 165, 1886, 1706, 174, 120, 687, 683, 679, 675, 273, - /* 320 */ 74, 486, 1881, 73, 1411, 221, 1710, 1917, 1740, 17, - /* 330 */ 356, 1710, 638, 1755, 1757, 604, 1342, 44, 42, 1081, - /* 340 */ 1867, 1080, 603, 313, 590, 351, 539, 1336, 1877, 1883, - /* 350 */ 565, 145, 144, 635, 634, 633, 95, 1393, 1416, 241, - /* 360 */ 1334, 597, 1, 605, 453, 1479, 549, 1933, 638, 1082, - /* 370 */ 1359, 295, 350, 1900, 607, 1902, 1903, 602, 120, 597, - /* 380 */ 47, 1411, 1560, 397, 694, 491, 17, 145, 144, 635, - /* 390 */ 634, 633, 546, 1342, 455, 1710, 398, 451, 1418, 1419, - /* 400 */ 1545, 2054, 1336, 110, 174, 433, 109, 108, 107, 106, - /* 410 */ 105, 104, 103, 102, 101, 1334, 574, 171, 46, 1, - /* 420 */ 1393, 2055, 576, 110, 230, 549, 109, 108, 107, 106, - /* 430 */ 105, 104, 103, 102, 101, 571, 566, 176, 502, 501, - /* 440 */ 500, 694, 1308, 1337, 223, 1335, 126, 496, 1342, 1578, - /* 450 */ 154, 495, 494, 1762, 1710, 1418, 1419, 493, 499, 1713, - /* 460 */ 338, 186, 185, 492, 1148, 1068, 1069, 1340, 1341, 1760, - /* 470 */ 1391, 1392, 1394, 1395, 1396, 1397, 1398, 1399, 1400, 1401, - /* 480 */ 599, 595, 1409, 1410, 1412, 1413, 1414, 1415, 1417, 1420, - /* 490 */ 3, 1867, 11, 40, 39, 38, 694, 1150, 2006, 1479, - /* 500 */ 1337, 1624, 1335, 233, 570, 1447, 1188, 629, 628, 627, - /* 510 */ 1192, 626, 1194, 1195, 625, 1197, 622, 640, 1203, 619, - /* 520 */ 1205, 1206, 616, 613, 1340, 1341, 174, 1391, 1392, 1394, - /* 530 */ 1395, 1396, 1397, 1398, 1399, 1400, 1401, 599, 595, 1409, - /* 540 */ 1410, 1412, 1413, 1414, 1415, 1417, 1420, 3, 44, 42, - /* 550 */ 1804, 354, 1917, 2059, 2001, 1337, 351, 1335, 1336, 154, - /* 560 */ 569, 179, 1314, 1315, 502, 501, 500, 632, 1712, 1416, - /* 570 */ 1363, 1334, 126, 496, 549, 31, 228, 495, 494, 1340, - /* 580 */ 1341, 1899, 1998, 493, 499, 1452, 394, 1688, 1814, 492, - /* 590 */ 37, 36, 1411, 1360, 43, 41, 40, 39, 38, 568, - /* 600 */ 1899, 1762, 1342, 1710, 1342, 44, 42, 1421, 355, 549, - /* 610 */ 1917, 48, 4, 351, 58, 1336, 81, 1760, 604, 549, - /* 620 */ 11, 395, 9, 1867, 357, 603, 1416, 1762, 1334, 1917, - /* 630 */ 8, 405, 154, 128, 320, 2059, 1957, 604, 1710, 549, - /* 640 */ 1577, 1712, 1867, 1760, 603, 1545, 1897, 465, 1710, 1411, - /* 650 */ 1933, 419, 694, 535, 158, 1898, 1900, 607, 1902, 1903, - /* 660 */ 602, 1342, 597, 1483, 2054, 1897, 1418, 1419, 1710, 1933, - /* 670 */ 532, 549, 575, 97, 1898, 1900, 607, 1902, 1903, 602, - /* 680 */ 2058, 597, 1867, 420, 2055, 2056, 2074, 8, 1986, 551, - /* 690 */ 516, 1958, 344, 1982, 1762, 554, 2023, 665, 663, 2054, - /* 700 */ 1710, 2054, 2020, 514, 1686, 512, 553, 11, 1958, 694, - /* 710 */ 1761, 1337, 267, 1335, 2060, 171, 574, 171, 1361, 2055, - /* 720 */ 576, 2055, 576, 1418, 1419, 37, 36, 13, 12, 43, - /* 730 */ 41, 40, 39, 38, 1854, 1340, 1341, 1364, 1391, 1392, - /* 740 */ 1394, 1395, 1396, 1397, 1398, 1399, 1400, 1401, 599, 595, - /* 750 */ 1409, 1410, 1412, 1413, 1414, 1415, 1417, 1420, 3, 1559, - /* 760 */ 174, 652, 1363, 1804, 640, 1810, 1804, 308, 1337, 653, - /* 770 */ 1335, 1680, 87, 327, 180, 1699, 174, 184, 1576, 527, - /* 780 */ 1809, 373, 308, 119, 118, 117, 116, 115, 114, 113, - /* 790 */ 112, 111, 1340, 1341, 1703, 1391, 1392, 1394, 1395, 1396, - /* 800 */ 1397, 1398, 1399, 1400, 1401, 599, 595, 1409, 1410, 1412, - /* 810 */ 1413, 1414, 1415, 1417, 1420, 3, 44, 42, 1791, 549, - /* 820 */ 1867, 1459, 636, 364, 351, 1753, 1336, 2001, 2001, 637, - /* 830 */ 579, 463, 1753, 328, 1575, 326, 325, 1416, 488, 1334, - /* 840 */ 532, 363, 490, 94, 490, 1364, 37, 36, 1710, 1899, - /* 850 */ 43, 41, 40, 39, 38, 1997, 1996, 127, 532, 549, - /* 860 */ 1411, 1695, 2058, 549, 489, 1702, 489, 1574, 1899, 2054, - /* 870 */ 549, 464, 1342, 44, 42, 1707, 1867, 1697, 1917, 244, - /* 880 */ 143, 351, 137, 1336, 2060, 171, 604, 2054, 1710, 2055, - /* 890 */ 576, 1867, 1710, 603, 1416, 1693, 1334, 1917, 8, 1710, - /* 900 */ 1482, 1393, 2060, 171, 267, 604, 224, 2055, 576, 1867, - /* 910 */ 1867, 598, 603, 280, 1897, 1573, 1740, 1411, 1933, 549, - /* 920 */ 694, 1899, 159, 1898, 1900, 607, 1902, 1903, 602, 1342, - /* 930 */ 597, 528, 51, 1897, 1418, 1419, 1570, 1933, 1569, 549, - /* 940 */ 1611, 97, 1898, 1900, 607, 1902, 1903, 602, 1710, 597, - /* 950 */ 1917, 533, 50, 531, 2074, 1, 1986, 1867, 604, 549, - /* 960 */ 344, 1982, 503, 1867, 549, 603, 414, 631, 1710, 582, - /* 970 */ 2048, 238, 549, 93, 577, 2075, 545, 694, 1867, 1337, - /* 980 */ 1867, 1335, 1685, 90, 547, 1664, 1897, 243, 1710, 404, - /* 990 */ 1933, 1418, 1419, 1710, 159, 1898, 1900, 607, 1902, 1903, - /* 1000 */ 602, 1710, 597, 1340, 1341, 1552, 1391, 1392, 1394, 1395, - /* 1010 */ 1396, 1397, 1398, 1399, 1400, 1401, 599, 595, 1409, 1410, - /* 1020 */ 1412, 1413, 1414, 1415, 1417, 1420, 3, 37, 36, 206, - /* 1030 */ 549, 43, 41, 40, 39, 38, 1337, 72, 1335, 1554, - /* 1040 */ 1555, 211, 548, 161, 209, 1568, 580, 2076, 482, 478, - /* 1050 */ 474, 470, 205, 1567, 213, 13, 12, 212, 1572, 1710, - /* 1060 */ 1340, 1341, 1621, 1391, 1392, 1394, 1395, 1396, 1397, 1398, - /* 1070 */ 1399, 1400, 1401, 599, 595, 1409, 1410, 1412, 1413, 1414, - /* 1080 */ 1415, 1417, 1420, 3, 310, 262, 1359, 1867, 638, 78, - /* 1090 */ 227, 215, 203, 427, 214, 1867, 438, 1606, 37, 36, - /* 1100 */ 1551, 2026, 43, 41, 40, 39, 38, 145, 144, 635, - /* 1110 */ 634, 633, 563, 411, 1522, 439, 578, 413, 1566, 505, - /* 1120 */ 1345, 217, 1565, 1564, 216, 671, 670, 669, 668, 361, - /* 1130 */ 80, 667, 666, 133, 661, 660, 659, 658, 657, 656, - /* 1140 */ 655, 654, 147, 650, 649, 648, 360, 359, 645, 644, - /* 1150 */ 643, 642, 641, 155, 202, 196, 1563, 201, 286, 323, - /* 1160 */ 1867, 461, 37, 36, 1867, 1867, 43, 41, 40, 39, - /* 1170 */ 38, 400, 284, 66, 1604, 45, 65, 194, 594, 232, - /* 1180 */ 483, 138, 142, 256, 1562, 1502, 143, 583, 60, 1918, - /* 1190 */ 1595, 248, 190, 444, 442, 1899, 508, 26, 1867, 437, - /* 1200 */ 362, 60, 432, 431, 430, 429, 426, 425, 424, 423, - /* 1210 */ 422, 418, 417, 416, 415, 324, 408, 407, 406, 1750, - /* 1220 */ 402, 401, 322, 549, 1917, 2016, 1867, 1285, 45, 58, - /* 1230 */ 1108, 236, 604, 542, 240, 269, 1600, 1867, 1181, 603, - /* 1240 */ 1509, 37, 36, 251, 32, 43, 41, 40, 39, 38, - /* 1250 */ 37, 36, 1710, 1453, 43, 41, 40, 39, 38, 264, - /* 1260 */ 1897, 261, 1348, 1109, 1933, 1888, 549, 96, 97, 1898, - /* 1270 */ 1900, 607, 1902, 1903, 602, 1344, 597, 1899, 358, 129, - /* 1280 */ 1402, 141, 1957, 1986, 689, 37, 36, 344, 1982, 43, - /* 1290 */ 41, 40, 39, 38, 316, 1710, 45, 611, 588, 5, - /* 1300 */ 2, 520, 71, 70, 393, 367, 1917, 178, 372, 142, - /* 1310 */ 1301, 334, 143, 1890, 604, 646, 1437, 122, 532, 1867, - /* 1320 */ 321, 603, 142, 647, 309, 276, 183, 381, 1899, 379, - /* 1330 */ 375, 371, 368, 365, 399, 403, 1445, 1128, 435, 409, - /* 1340 */ 1359, 421, 1897, 1806, 587, 1126, 1933, 2054, 279, 1209, - /* 1350 */ 302, 1898, 1900, 607, 1902, 1903, 602, 1917, 597, 428, - /* 1360 */ 587, 1213, 2060, 171, 1220, 591, 434, 2055, 576, 1218, - /* 1370 */ 1867, 436, 603, 132, 146, 174, 441, 440, 187, 443, - /* 1380 */ 445, 1365, 446, 454, 1367, 457, 458, 193, 195, 132, - /* 1390 */ 1446, 1366, 1368, 1897, 459, 460, 198, 1933, 466, 200, - /* 1400 */ 462, 97, 1898, 1900, 607, 1902, 1903, 602, 75, 597, - /* 1410 */ 130, 76, 204, 485, 168, 99, 1986, 1347, 487, 519, - /* 1420 */ 344, 1982, 1700, 208, 1696, 312, 130, 210, 521, 277, - /* 1430 */ 148, 149, 170, 1994, 1995, 1698, 1999, 1694, 150, 153, - /* 1440 */ 222, 2013, 151, 522, 225, 1845, 1899, 523, 172, 1994, - /* 1450 */ 1995, 529, 1999, 534, 229, 561, 526, 543, 537, 84, - /* 1460 */ 33, 348, 1440, 1441, 1442, 1443, 1444, 1448, 1449, 1450, - /* 1470 */ 1451, 333, 139, 1844, 1816, 1917, 140, 540, 335, 544, - /* 1480 */ 86, 1364, 557, 604, 1711, 278, 2017, 564, 1867, 6, - /* 1490 */ 603, 2027, 2032, 246, 250, 559, 560, 2031, 573, 558, - /* 1500 */ 556, 162, 255, 340, 567, 555, 260, 341, 584, 2008, - /* 1510 */ 581, 1897, 257, 1899, 1479, 1933, 131, 1363, 57, 97, - /* 1520 */ 1898, 1900, 607, 1902, 1903, 602, 88, 597, 258, 1967, - /* 1530 */ 609, 259, 2074, 1754, 1986, 1899, 1681, 2002, 344, 1982, - /* 1540 */ 281, 272, 1917, 690, 2053, 691, 2077, 263, 2005, 693, - /* 1550 */ 604, 307, 49, 293, 283, 1867, 304, 603, 1861, 303, - /* 1560 */ 1860, 68, 1859, 1858, 1917, 285, 69, 1855, 369, 370, - /* 1570 */ 1328, 1329, 604, 177, 374, 1853, 376, 1867, 1897, 603, - /* 1580 */ 377, 378, 1933, 1852, 380, 1851, 97, 1898, 1900, 607, - /* 1590 */ 1902, 1903, 602, 1899, 597, 1850, 382, 1849, 384, 1961, - /* 1600 */ 1897, 1986, 1304, 386, 1933, 344, 1982, 391, 97, 1898, - /* 1610 */ 1900, 607, 1902, 1903, 602, 1899, 597, 1303, 1827, 347, - /* 1620 */ 346, 1959, 1917, 1986, 1826, 392, 1825, 344, 1982, 1350, - /* 1630 */ 604, 1824, 1273, 1799, 1798, 1867, 134, 603, 1796, 1795, - /* 1640 */ 1416, 1794, 1343, 1797, 1917, 135, 1793, 1792, 1790, 1789, - /* 1650 */ 1788, 181, 604, 1787, 410, 1786, 412, 1867, 1897, 603, - /* 1660 */ 1785, 1784, 1933, 1411, 1783, 1782, 97, 1898, 1900, 607, - /* 1670 */ 1902, 1903, 602, 1781, 597, 1342, 1780, 1779, 1778, 552, - /* 1680 */ 1897, 1986, 1777, 1776, 1933, 344, 1982, 136, 98, 1898, - /* 1690 */ 1900, 607, 1902, 1903, 602, 1775, 597, 1774, 1773, 1772, - /* 1700 */ 1771, 1770, 1769, 1986, 1768, 1767, 1275, 1985, 1982, 1766, - /* 1710 */ 1765, 1764, 1763, 1626, 1156, 188, 1625, 1623, 189, 1591, - /* 1720 */ 123, 1071, 1899, 593, 1590, 1840, 450, 191, 1070, 166, - /* 1730 */ 192, 124, 1834, 1823, 452, 197, 199, 1822, 1808, 1689, - /* 1740 */ 1622, 1620, 1618, 467, 1616, 469, 1614, 1603, 1602, 1587, - /* 1750 */ 468, 1917, 1691, 1101, 59, 471, 475, 473, 479, 604, - /* 1760 */ 1690, 1320, 472, 1612, 1867, 477, 603, 481, 207, 476, - /* 1770 */ 1224, 1147, 1223, 1145, 480, 1607, 1605, 662, 1146, 506, - /* 1780 */ 1144, 1586, 1351, 1138, 1346, 100, 329, 1897, 1143, 1140, - /* 1790 */ 1899, 1933, 1139, 1137, 330, 98, 1898, 1900, 607, 1902, - /* 1800 */ 1903, 602, 664, 597, 509, 331, 1354, 1356, 511, 1899, - /* 1810 */ 1986, 1585, 513, 1584, 592, 1982, 515, 1839, 53, 1917, - /* 1820 */ 595, 1409, 1410, 1412, 1413, 1414, 1415, 601, 1310, 1833, - /* 1830 */ 152, 524, 1867, 525, 603, 1821, 1819, 332, 1917, 1820, - /* 1840 */ 2059, 1818, 1817, 1318, 538, 1815, 604, 242, 226, 25, - /* 1850 */ 18, 1867, 1807, 603, 541, 1897, 237, 530, 83, 1933, - /* 1860 */ 1428, 231, 82, 301, 1898, 1900, 607, 1902, 1903, 602, - /* 1870 */ 600, 597, 550, 1951, 1897, 90, 1899, 19, 1933, 10, - /* 1880 */ 85, 1427, 98, 1898, 1900, 607, 1902, 1903, 602, 239, - /* 1890 */ 597, 20, 27, 1899, 1524, 247, 245, 1986, 1506, 249, - /* 1900 */ 56, 1508, 1983, 253, 160, 1917, 252, 15, 28, 254, - /* 1910 */ 1501, 1888, 89, 601, 21, 29, 1544, 1545, 1867, 61, - /* 1920 */ 603, 22, 1917, 1539, 1538, 342, 1543, 1542, 343, 266, - /* 1930 */ 604, 1887, 163, 1476, 12, 1867, 1899, 603, 1475, 55, - /* 1940 */ 1352, 1897, 1384, 1936, 596, 1933, 1406, 164, 1404, 301, - /* 1950 */ 1898, 1900, 607, 1902, 1903, 602, 1899, 597, 1897, 1952, - /* 1960 */ 35, 14, 1933, 1403, 23, 1917, 158, 1898, 1900, 607, - /* 1970 */ 1902, 1903, 602, 604, 597, 175, 1376, 1210, 1867, 1438, - /* 1980 */ 603, 24, 608, 606, 610, 1917, 353, 614, 612, 615, - /* 1990 */ 349, 617, 1207, 604, 1204, 1198, 618, 620, 1867, 621, - /* 2000 */ 603, 1897, 1196, 623, 624, 1933, 1187, 1899, 2024, 297, - /* 2010 */ 1898, 1900, 607, 1902, 1903, 602, 54, 597, 16, 630, - /* 2020 */ 91, 1897, 1202, 1219, 1201, 1933, 1200, 1199, 92, 302, - /* 2030 */ 1898, 1900, 607, 1902, 1903, 602, 1917, 597, 67, 270, - /* 2040 */ 1215, 352, 1099, 639, 604, 1134, 1133, 1132, 1131, 1867, - /* 2050 */ 1130, 603, 1129, 572, 1127, 1125, 1124, 1123, 1154, 271, - /* 2060 */ 651, 1121, 1120, 1119, 1118, 1117, 1116, 1115, 1114, 1151, - /* 2070 */ 1149, 1111, 1897, 1110, 1107, 1106, 1933, 1105, 1619, 1104, - /* 2080 */ 302, 1898, 1900, 607, 1902, 1903, 602, 1899, 597, 673, - /* 2090 */ 674, 672, 1617, 676, 677, 1615, 678, 680, 682, 681, - /* 2100 */ 1613, 684, 686, 1601, 688, 1899, 1061, 685, 1583, 274, - /* 2110 */ 692, 1558, 1338, 282, 695, 1558, 1917, 696, 1558, 1558, - /* 2120 */ 1558, 1558, 1558, 1558, 604, 1558, 1558, 1558, 1558, 1867, - /* 2130 */ 1558, 603, 1558, 1558, 1917, 1558, 1558, 1558, 1558, 1558, - /* 2140 */ 1558, 1558, 604, 1558, 1558, 1558, 1558, 1867, 1899, 603, - /* 2150 */ 1558, 1558, 518, 1558, 1558, 1558, 1933, 1558, 1558, 1558, - /* 2160 */ 295, 1898, 1900, 607, 1902, 1903, 602, 1899, 597, 1558, - /* 2170 */ 1897, 1558, 1558, 1558, 1933, 1558, 1558, 1917, 287, 1898, - /* 2180 */ 1900, 607, 1902, 1903, 602, 604, 597, 1558, 1558, 1558, - /* 2190 */ 1867, 1899, 603, 1558, 1558, 1558, 1917, 1558, 1558, 1558, - /* 2200 */ 1558, 1558, 1558, 1558, 604, 1558, 1558, 1558, 1558, 1867, - /* 2210 */ 1558, 603, 1558, 1897, 1558, 1558, 1558, 1933, 1558, 1558, - /* 2220 */ 1917, 288, 1898, 1900, 607, 1902, 1903, 602, 604, 597, - /* 2230 */ 1558, 1558, 1897, 1867, 1899, 603, 1933, 1558, 1558, 1558, - /* 2240 */ 289, 1898, 1900, 607, 1902, 1903, 602, 1558, 597, 1558, - /* 2250 */ 1558, 1899, 1558, 1558, 1558, 1558, 1897, 1558, 1558, 1558, - /* 2260 */ 1933, 1558, 1558, 1917, 296, 1898, 1900, 607, 1902, 1903, - /* 2270 */ 602, 604, 597, 1558, 1558, 1558, 1867, 1899, 603, 1558, - /* 2280 */ 1917, 1558, 1558, 1558, 1558, 1558, 1558, 1558, 604, 1558, - /* 2290 */ 1558, 1558, 1558, 1867, 1899, 603, 1558, 1558, 1558, 1897, - /* 2300 */ 1558, 1558, 1558, 1933, 1558, 1558, 1917, 298, 1898, 1900, - /* 2310 */ 607, 1902, 1903, 602, 604, 597, 1897, 1558, 1558, 1867, - /* 2320 */ 1933, 603, 1558, 1917, 290, 1898, 1900, 607, 1902, 1903, - /* 2330 */ 602, 604, 597, 1558, 1558, 1558, 1867, 1558, 603, 1558, - /* 2340 */ 1558, 1558, 1897, 1558, 1558, 1558, 1933, 1558, 1558, 1558, - /* 2350 */ 299, 1898, 1900, 607, 1902, 1903, 602, 1899, 597, 1897, - /* 2360 */ 1558, 1558, 1558, 1933, 1558, 1558, 1558, 291, 1898, 1900, - /* 2370 */ 607, 1902, 1903, 602, 1899, 597, 1558, 1558, 1558, 1558, - /* 2380 */ 1558, 1558, 1558, 1558, 1558, 1558, 1917, 1558, 1558, 1558, - /* 2390 */ 1558, 1558, 1558, 1558, 604, 1558, 1558, 1558, 1558, 1867, - /* 2400 */ 1558, 603, 1558, 1917, 1558, 1558, 1558, 1558, 1558, 1558, - /* 2410 */ 1558, 604, 1558, 1558, 1558, 1558, 1867, 1558, 603, 1558, - /* 2420 */ 1558, 1558, 1897, 1558, 1558, 1558, 1933, 1558, 1558, 1558, - /* 2430 */ 300, 1898, 1900, 607, 1902, 1903, 602, 1899, 597, 1897, - /* 2440 */ 1558, 1558, 1558, 1933, 1558, 1558, 1558, 292, 1898, 1900, - /* 2450 */ 607, 1902, 1903, 602, 1558, 597, 1558, 1558, 1558, 1558, - /* 2460 */ 1558, 1558, 1558, 1899, 1558, 1558, 1917, 1558, 1558, 1558, - /* 2470 */ 1558, 1558, 1558, 1558, 604, 1558, 1558, 1558, 1558, 1867, - /* 2480 */ 1558, 603, 1558, 1558, 1558, 1558, 1558, 1558, 1558, 1558, - /* 2490 */ 1558, 1558, 1917, 1558, 1558, 1558, 1558, 1558, 1558, 1558, - /* 2500 */ 604, 1558, 1897, 1558, 1558, 1867, 1933, 603, 1558, 1558, - /* 2510 */ 305, 1898, 1900, 607, 1902, 1903, 602, 1899, 597, 1558, - /* 2520 */ 1558, 1558, 1558, 1558, 1558, 1558, 1558, 1558, 1897, 1558, - /* 2530 */ 1558, 1558, 1933, 1558, 1899, 1558, 306, 1898, 1900, 607, - /* 2540 */ 1902, 1903, 602, 1558, 597, 1558, 1917, 1558, 1558, 1558, - /* 2550 */ 1558, 1558, 1558, 1558, 604, 1558, 1558, 1558, 1558, 1867, - /* 2560 */ 1558, 603, 1558, 1917, 1558, 1558, 1558, 1558, 1558, 1558, - /* 2570 */ 1558, 604, 1558, 1558, 1558, 1558, 1867, 1899, 603, 1558, - /* 2580 */ 1558, 1558, 1897, 1558, 1558, 1558, 1933, 1558, 1558, 1558, - /* 2590 */ 1911, 1898, 1900, 607, 1902, 1903, 602, 1899, 597, 1897, - /* 2600 */ 1558, 1558, 1558, 1933, 1558, 1558, 1917, 1910, 1898, 1900, - /* 2610 */ 607, 1902, 1903, 602, 604, 597, 1558, 1558, 1558, 1867, - /* 2620 */ 1558, 603, 1558, 1558, 1558, 1558, 1917, 1558, 1558, 1558, - /* 2630 */ 1558, 1558, 1558, 1558, 604, 1558, 1558, 1558, 1558, 1867, - /* 2640 */ 1899, 603, 1897, 1558, 1558, 1558, 1933, 1558, 1558, 1558, - /* 2650 */ 1909, 1898, 1900, 607, 1902, 1903, 602, 1899, 597, 1558, - /* 2660 */ 1558, 1558, 1897, 1558, 1558, 1558, 1933, 1558, 1558, 1917, - /* 2670 */ 317, 1898, 1900, 607, 1902, 1903, 602, 604, 597, 1558, - /* 2680 */ 1558, 1558, 1867, 1558, 603, 1558, 1917, 1558, 1558, 1558, - /* 2690 */ 1558, 1558, 1558, 1558, 604, 1558, 1558, 1558, 1558, 1867, - /* 2700 */ 1558, 603, 1558, 1558, 1558, 1897, 1558, 1558, 1558, 1933, - /* 2710 */ 1558, 1558, 1558, 318, 1898, 1900, 607, 1902, 1903, 602, - /* 2720 */ 1899, 597, 1897, 1558, 1558, 1558, 1933, 1558, 1558, 1558, - /* 2730 */ 314, 1898, 1900, 607, 1902, 1903, 602, 1899, 597, 1558, - /* 2740 */ 1558, 1558, 1558, 1558, 1558, 1558, 1558, 1558, 1558, 1917, - /* 2750 */ 1558, 1558, 1558, 1558, 1558, 1558, 1558, 604, 1558, 1558, - /* 2760 */ 1558, 1558, 1867, 1558, 603, 1558, 1917, 1558, 1558, 1558, - /* 2770 */ 1558, 1558, 1558, 1558, 604, 1558, 1558, 1558, 1558, 1867, - /* 2780 */ 1558, 603, 1558, 1558, 1558, 1897, 1558, 1558, 1558, 1933, - /* 2790 */ 1558, 1558, 1558, 319, 1898, 1900, 607, 1902, 1903, 602, - /* 2800 */ 1558, 597, 1897, 1558, 1558, 1558, 1933, 1558, 1558, 1558, - /* 2810 */ 294, 1898, 1900, 607, 1902, 1903, 602, 1558, 597, + /* 0 */ 450, 167, 451, 1602, 77, 458, 1711, 451, 1602, 538, + /* 10 */ 1824, 552, 44, 42, 1759, 339, 338, 1892, 1069, 1821, + /* 20 */ 353, 1568, 1344, 154, 120, 552, 1896, 1716, 593, 1897, + /* 30 */ 1910, 488, 1722, 1424, 156, 1342, 593, 1892, 52, 1673, + /* 40 */ 1892, 1720, 110, 1888, 1894, 109, 108, 107, 106, 105, + /* 50 */ 104, 103, 102, 101, 590, 1720, 600, 1419, 1073, 1074, + /* 60 */ 1928, 1370, 17, 1888, 1894, 341, 1888, 1894, 607, 1350, + /* 70 */ 44, 42, 1494, 1878, 449, 606, 600, 453, 353, 600, + /* 80 */ 1344, 467, 37, 36, 132, 1772, 43, 41, 40, 39, + /* 90 */ 38, 1424, 1910, 1342, 1372, 1, 608, 157, 552, 1579, + /* 100 */ 1944, 1771, 1896, 46, 98, 352, 1911, 610, 1913, 1914, + /* 110 */ 605, 176, 600, 1892, 58, 1419, 552, 697, 1910, 1997, + /* 120 */ 17, 130, 1928, 317, 1993, 398, 1698, 1350, 1720, 120, + /* 130 */ 607, 1426, 1427, 635, 2065, 1878, 493, 606, 47, 1888, + /* 140 */ 1894, 347, 592, 169, 2005, 2006, 1720, 2010, 1928, 577, + /* 150 */ 171, 455, 600, 1, 2066, 579, 607, 1367, 1908, 77, + /* 160 */ 1590, 1878, 1944, 606, 313, 329, 97, 1909, 1911, 610, + /* 170 */ 1913, 1914, 605, 125, 600, 697, 1345, 129, 1343, 141, + /* 180 */ 1968, 1997, 1715, 1928, 1908, 346, 1993, 467, 1944, 1426, + /* 190 */ 1427, 572, 159, 1909, 1911, 610, 1913, 1914, 605, 435, + /* 200 */ 600, 1348, 1349, 1878, 1399, 1400, 1402, 1403, 1404, 1405, + /* 210 */ 1406, 1407, 1408, 1409, 602, 598, 1417, 1418, 1420, 1421, + /* 220 */ 1422, 1423, 1425, 1428, 3, 1565, 330, 1369, 328, 327, + /* 230 */ 571, 490, 222, 573, 1345, 492, 1343, 246, 457, 236, + /* 240 */ 237, 453, 174, 110, 580, 2086, 109, 108, 107, 106, + /* 250 */ 105, 104, 103, 102, 101, 186, 185, 491, 182, 1348, + /* 260 */ 1349, 174, 1399, 1400, 1402, 1403, 1404, 1405, 1406, 1407, + /* 270 */ 1408, 1409, 602, 598, 1417, 1418, 1420, 1421, 1422, 1423, + /* 280 */ 1425, 1428, 3, 44, 42, 174, 368, 1371, 79, 315, + /* 290 */ 643, 353, 542, 1344, 540, 74, 1696, 315, 73, 593, + /* 300 */ 542, 1910, 540, 534, 1424, 2070, 1342, 1195, 632, 631, + /* 310 */ 630, 1199, 629, 1201, 1202, 628, 1204, 625, 230, 1210, + /* 320 */ 622, 1212, 1213, 619, 616, 11, 358, 9, 1419, 1765, + /* 330 */ 1767, 1928, 2065, 17, 2065, 2012, 62, 1498, 87, 607, + /* 340 */ 1350, 44, 42, 1369, 1878, 1865, 606, 2071, 171, 353, + /* 350 */ 2069, 1344, 2066, 579, 2066, 2068, 58, 643, 81, 700, + /* 360 */ 1713, 58, 1424, 2009, 1342, 1520, 1, 608, 387, 7, + /* 370 */ 1086, 1944, 1085, 277, 46, 297, 352, 1911, 610, 1913, + /* 380 */ 1914, 605, 1567, 600, 1368, 207, 1419, 165, 697, 389, + /* 390 */ 385, 17, 375, 690, 686, 682, 678, 275, 1350, 1491, + /* 400 */ 1087, 1155, 1426, 1427, 11, 2065, 119, 118, 117, 116, + /* 410 */ 115, 114, 113, 112, 111, 565, 1518, 1519, 1521, 1522, + /* 420 */ 577, 171, 1772, 1350, 1, 2066, 579, 58, 1589, 322, + /* 430 */ 269, 504, 503, 502, 95, 1157, 1434, 243, 1770, 126, + /* 440 */ 498, 391, 1369, 390, 497, 496, 697, 1345, 655, 1343, + /* 450 */ 495, 501, 392, 1697, 1369, 1370, 494, 1814, 37, 36, + /* 460 */ 1426, 1427, 43, 41, 40, 39, 38, 578, 179, 534, + /* 470 */ 549, 1878, 1348, 1349, 1709, 1399, 1400, 1402, 1403, 1404, + /* 480 */ 1405, 1406, 1407, 1408, 1409, 602, 598, 1417, 1418, 1420, + /* 490 */ 1421, 1422, 1423, 1425, 1428, 3, 2065, 11, 2065, 1772, + /* 500 */ 34, 270, 232, 174, 1705, 1345, 340, 1343, 174, 1707, + /* 510 */ 94, 577, 171, 2071, 171, 1770, 2066, 579, 2066, 579, + /* 520 */ 1315, 174, 225, 229, 127, 1766, 1767, 1910, 1401, 58, + /* 530 */ 1348, 1349, 1712, 1399, 1400, 1402, 1403, 1404, 1405, 1406, + /* 540 */ 1407, 1408, 1409, 602, 598, 1417, 1418, 1420, 1421, 1422, + /* 550 */ 1423, 1425, 1428, 3, 44, 42, 2070, 1928, 500, 499, + /* 560 */ 641, 356, 353, 80, 1344, 607, 1237, 1238, 568, 154, + /* 570 */ 1878, 1487, 606, 1371, 174, 1424, 1814, 1342, 1722, 145, + /* 580 */ 144, 638, 637, 636, 37, 36, 1910, 180, 43, 41, + /* 590 */ 40, 39, 38, 1908, 554, 552, 1969, 1944, 1086, 1419, + /* 600 */ 1085, 158, 1909, 1911, 610, 1913, 1914, 605, 396, 600, + /* 610 */ 1772, 1350, 44, 42, 1429, 1455, 1928, 357, 1560, 518, + /* 620 */ 353, 336, 1344, 552, 607, 1720, 1770, 1401, 1087, 1878, + /* 630 */ 1703, 606, 516, 1424, 514, 1342, 397, 8, 1490, 235, + /* 640 */ 37, 36, 557, 2034, 43, 41, 40, 39, 38, 1553, + /* 650 */ 359, 226, 1908, 1720, 574, 569, 1944, 1419, 154, 697, + /* 660 */ 304, 1909, 1911, 610, 1913, 1914, 605, 1722, 600, 1350, + /* 670 */ 349, 348, 1530, 1426, 1427, 1344, 174, 37, 36, 552, + /* 680 */ 1358, 43, 41, 40, 39, 38, 31, 223, 1342, 552, + /* 690 */ 1750, 1424, 407, 1351, 30, 8, 1460, 2012, 1321, 1322, + /* 700 */ 37, 36, 421, 538, 43, 41, 40, 39, 38, 1720, + /* 710 */ 2012, 552, 26, 1822, 1559, 1419, 269, 697, 1345, 1720, + /* 720 */ 1343, 2069, 1350, 32, 422, 2008, 399, 1350, 1510, 37, + /* 730 */ 36, 1426, 1427, 43, 41, 40, 39, 38, 2007, 400, + /* 740 */ 2070, 1720, 128, 1348, 1349, 1968, 1399, 1400, 1402, 1403, + /* 750 */ 1404, 1405, 1406, 1407, 1408, 1409, 602, 598, 1417, 1418, + /* 760 */ 1420, 1421, 1422, 1423, 1425, 1428, 3, 13, 12, 2065, + /* 770 */ 697, 40, 39, 38, 601, 596, 1345, 641, 1343, 43, + /* 780 */ 41, 40, 39, 38, 174, 2069, 634, 37, 36, 2066, + /* 790 */ 2067, 43, 41, 40, 39, 38, 145, 144, 638, 637, + /* 800 */ 636, 1348, 1349, 143, 1399, 1400, 1402, 1403, 1404, 1405, + /* 810 */ 1406, 1407, 1408, 1409, 602, 598, 1417, 1418, 1420, 1421, + /* 820 */ 1422, 1423, 1425, 1428, 3, 44, 42, 492, 552, 1345, + /* 830 */ 1820, 1343, 308, 353, 1359, 1344, 1354, 585, 556, 552, + /* 840 */ 1969, 465, 668, 666, 529, 1588, 1424, 1587, 1342, 491, + /* 850 */ 552, 537, 466, 1814, 1348, 1349, 51, 1910, 1720, 1362, + /* 860 */ 1364, 1369, 1467, 1717, 184, 1073, 1074, 1586, 534, 1720, + /* 870 */ 1419, 1585, 1674, 598, 1417, 1418, 1420, 1421, 1422, 1423, + /* 880 */ 1720, 552, 1350, 44, 42, 552, 552, 1928, 1878, 1580, + /* 890 */ 1878, 353, 366, 1344, 137, 607, 1634, 2065, 530, 535, + /* 900 */ 1878, 656, 606, 1690, 1424, 1584, 1342, 406, 8, 534, + /* 910 */ 1878, 1720, 2071, 171, 1878, 1720, 1720, 2066, 579, 1621, + /* 920 */ 1819, 1583, 308, 1908, 1582, 2017, 1487, 1944, 1419, 1581, + /* 930 */ 697, 98, 1909, 1911, 610, 1913, 1914, 605, 2065, 600, + /* 940 */ 1350, 505, 153, 1578, 1426, 1427, 1997, 1577, 1878, 1614, + /* 950 */ 1996, 1993, 552, 2071, 171, 72, 1576, 552, 2066, 579, + /* 960 */ 504, 503, 502, 45, 1878, 240, 1, 1878, 126, 498, + /* 970 */ 360, 507, 1878, 497, 496, 639, 2037, 581, 1763, 495, + /* 980 */ 501, 206, 1720, 1372, 208, 494, 1878, 1720, 697, 1345, + /* 990 */ 1878, 1343, 365, 1695, 522, 582, 1575, 264, 161, 1878, + /* 1000 */ 1574, 1573, 1426, 1427, 484, 480, 476, 472, 205, 534, + /* 1010 */ 640, 534, 234, 1763, 1348, 1349, 1292, 1399, 1400, 1402, + /* 1020 */ 1403, 1404, 1405, 1406, 1407, 1408, 1409, 602, 598, 1417, + /* 1030 */ 1418, 1420, 1421, 1422, 1423, 1425, 1428, 3, 2065, 1878, + /* 1040 */ 2065, 154, 566, 1878, 1878, 78, 1401, 1345, 203, 1343, + /* 1050 */ 1723, 48, 4, 2071, 171, 2071, 171, 586, 2066, 579, + /* 1060 */ 2066, 579, 37, 36, 1572, 238, 43, 41, 40, 39, + /* 1070 */ 38, 1571, 1348, 1349, 1631, 1399, 1400, 1402, 1403, 1404, + /* 1080 */ 1405, 1406, 1407, 1408, 1409, 602, 598, 1417, 1418, 1420, + /* 1090 */ 1421, 1422, 1423, 1425, 1428, 3, 312, 1801, 1367, 282, + /* 1100 */ 641, 590, 1750, 50, 533, 429, 590, 1878, 440, 213, + /* 1110 */ 202, 196, 211, 201, 1878, 215, 138, 463, 214, 145, + /* 1120 */ 144, 638, 637, 636, 1570, 413, 245, 441, 142, 217, + /* 1130 */ 415, 132, 216, 194, 219, 143, 132, 218, 674, 673, + /* 1140 */ 672, 671, 363, 258, 670, 669, 133, 664, 663, 662, + /* 1150 */ 661, 660, 659, 658, 657, 147, 653, 652, 651, 362, + /* 1160 */ 361, 648, 647, 646, 645, 644, 155, 1878, 130, 545, + /* 1170 */ 552, 288, 325, 130, 597, 1562, 1563, 13, 12, 60, + /* 1180 */ 1353, 242, 2070, 548, 402, 286, 66, 1612, 1188, 65, + /* 1190 */ 170, 2005, 2006, 1608, 2010, 172, 2005, 2006, 250, 2010, + /* 1200 */ 1720, 60, 1929, 45, 364, 45, 190, 446, 444, 510, + /* 1210 */ 614, 142, 439, 583, 1910, 434, 433, 432, 431, 428, + /* 1220 */ 427, 426, 425, 424, 420, 419, 418, 417, 326, 410, + /* 1230 */ 409, 408, 1517, 404, 403, 324, 1352, 1603, 1899, 1760, + /* 1240 */ 552, 692, 552, 58, 1928, 143, 416, 552, 2027, 122, + /* 1250 */ 591, 253, 594, 550, 1461, 551, 1410, 1878, 281, 606, + /* 1260 */ 271, 37, 36, 1216, 1220, 43, 41, 40, 39, 38, + /* 1270 */ 1720, 509, 1720, 93, 266, 1553, 590, 1720, 263, 2, + /* 1280 */ 1908, 96, 578, 90, 1944, 5, 519, 1901, 97, 1909, + /* 1290 */ 1911, 610, 1913, 1914, 605, 1115, 600, 142, 1227, 369, + /* 1300 */ 221, 168, 1225, 1997, 374, 323, 132, 346, 1993, 1308, + /* 1310 */ 278, 2065, 649, 1445, 512, 318, 71, 70, 395, 506, + /* 1320 */ 173, 178, 183, 1356, 220, 1910, 577, 171, 2023, 1116, + /* 1330 */ 650, 2066, 579, 401, 1135, 437, 405, 411, 1367, 311, + /* 1340 */ 430, 423, 383, 121, 381, 377, 373, 370, 367, 1816, + /* 1350 */ 146, 1910, 1133, 436, 438, 1928, 442, 1453, 443, 1373, + /* 1360 */ 448, 64, 187, 594, 63, 267, 2005, 589, 1878, 588, + /* 1370 */ 606, 456, 2065, 445, 1375, 447, 459, 193, 1374, 1355, + /* 1380 */ 460, 1928, 1376, 195, 461, 462, 198, 577, 171, 607, + /* 1390 */ 174, 1908, 2066, 579, 1878, 1944, 606, 464, 200, 97, + /* 1400 */ 1909, 1911, 610, 1913, 1914, 605, 75, 600, 1089, 468, + /* 1410 */ 76, 1454, 168, 485, 1997, 204, 486, 1908, 346, 1993, + /* 1420 */ 487, 1944, 489, 99, 1710, 97, 1909, 1911, 610, 1913, + /* 1430 */ 1914, 605, 314, 600, 210, 1706, 521, 523, 2085, 2024, + /* 1440 */ 1997, 212, 148, 149, 346, 1993, 1708, 1704, 279, 224, + /* 1450 */ 150, 151, 1855, 524, 2031, 528, 227, 531, 536, 231, + /* 1460 */ 564, 525, 546, 1910, 84, 335, 539, 1854, 1826, 543, + /* 1470 */ 280, 337, 86, 1721, 1372, 139, 560, 567, 2043, 562, + /* 1480 */ 140, 2042, 33, 350, 1448, 1449, 1450, 1451, 1452, 1456, + /* 1490 */ 1457, 1458, 1459, 1928, 547, 248, 6, 563, 342, 252, + /* 1500 */ 2019, 607, 2028, 570, 2038, 576, 1878, 561, 606, 559, + /* 1510 */ 558, 257, 343, 587, 2064, 2088, 584, 1487, 1371, 262, + /* 1520 */ 57, 131, 88, 1691, 2013, 612, 283, 274, 1764, 1908, + /* 1530 */ 1910, 693, 694, 1944, 696, 49, 295, 97, 1909, 1911, + /* 1540 */ 610, 1913, 1914, 605, 307, 600, 306, 162, 259, 260, + /* 1550 */ 2085, 1978, 1997, 285, 261, 305, 346, 1993, 287, 1872, + /* 1560 */ 1928, 1871, 265, 68, 1870, 1869, 2059, 69, 607, 371, + /* 1570 */ 372, 1336, 1337, 1878, 1866, 606, 177, 376, 1864, 378, + /* 1580 */ 379, 380, 1863, 382, 1910, 1862, 384, 1861, 386, 1860, + /* 1590 */ 388, 1311, 1310, 1837, 1836, 393, 1908, 394, 1835, 1834, + /* 1600 */ 1944, 1809, 1280, 1808, 97, 1909, 1911, 610, 1913, 1914, + /* 1610 */ 605, 1806, 600, 134, 1928, 1805, 1804, 2085, 1807, 1997, + /* 1620 */ 181, 135, 607, 346, 1993, 1803, 1802, 1878, 1800, 606, + /* 1630 */ 1799, 1798, 412, 2016, 1797, 414, 1796, 1795, 1910, 1794, + /* 1640 */ 1793, 1792, 1791, 1790, 1789, 1788, 1787, 1786, 1785, 1784, + /* 1650 */ 1908, 1783, 1782, 1781, 1944, 136, 1780, 1779, 97, 1909, + /* 1660 */ 1911, 610, 1913, 1914, 605, 1778, 600, 1777, 1928, 1776, + /* 1670 */ 1775, 1972, 1282, 1997, 188, 1635, 607, 346, 1993, 1774, + /* 1680 */ 1773, 1878, 1636, 606, 189, 1633, 1599, 1076, 1598, 1163, + /* 1690 */ 1075, 1910, 1108, 199, 1832, 1818, 1699, 191, 123, 1850, + /* 1700 */ 1844, 166, 192, 124, 1908, 1833, 452, 454, 1944, 1632, + /* 1710 */ 197, 1630, 97, 1909, 1911, 610, 1913, 1914, 605, 469, + /* 1720 */ 600, 1928, 471, 1628, 470, 1970, 473, 1997, 474, 607, + /* 1730 */ 1626, 346, 1993, 1624, 1878, 1611, 606, 475, 477, 481, + /* 1740 */ 478, 479, 1610, 1595, 1910, 483, 1701, 1231, 482, 1230, + /* 1750 */ 1700, 1154, 1153, 1152, 1151, 1150, 665, 1908, 667, 1147, + /* 1760 */ 1146, 1944, 1145, 1144, 1622, 97, 1909, 1911, 610, 1913, + /* 1770 */ 1914, 605, 59, 600, 1928, 331, 1615, 332, 555, 1613, + /* 1780 */ 1997, 508, 607, 333, 346, 1993, 511, 1878, 1594, 606, + /* 1790 */ 1593, 209, 513, 515, 1592, 517, 1849, 100, 53, 1843, + /* 1800 */ 1317, 152, 526, 1328, 1831, 1910, 1829, 1830, 2070, 25, + /* 1810 */ 1908, 1828, 1827, 18, 1944, 1825, 1326, 233, 98, 1909, + /* 1820 */ 1911, 610, 1913, 1914, 605, 1817, 600, 1325, 532, 1910, + /* 1830 */ 83, 239, 228, 1997, 82, 1928, 85, 595, 1993, 90, + /* 1840 */ 19, 527, 15, 604, 244, 20, 241, 27, 1878, 1436, + /* 1850 */ 606, 56, 1532, 334, 541, 247, 255, 1435, 544, 1928, + /* 1860 */ 10, 29, 249, 1514, 251, 256, 1516, 607, 1509, 160, + /* 1870 */ 1899, 1908, 1878, 254, 606, 1944, 61, 28, 89, 303, + /* 1880 */ 1909, 1911, 610, 1913, 1914, 605, 603, 600, 553, 1962, + /* 1890 */ 22, 1910, 1547, 1546, 344, 1908, 1552, 1553, 1551, 1944, + /* 1900 */ 1550, 345, 268, 98, 1909, 1911, 610, 1913, 1914, 605, + /* 1910 */ 1484, 600, 1483, 55, 1898, 163, 12, 1360, 1997, 1414, + /* 1920 */ 164, 1928, 1947, 1994, 599, 175, 35, 1446, 1412, 604, + /* 1930 */ 1411, 14, 23, 1392, 1878, 1384, 606, 24, 613, 611, + /* 1940 */ 609, 1217, 1910, 355, 615, 617, 1214, 618, 620, 1211, + /* 1950 */ 621, 623, 626, 1194, 21, 624, 16, 1908, 1205, 1209, + /* 1960 */ 1203, 1944, 54, 1208, 1226, 303, 1909, 1911, 610, 1913, + /* 1970 */ 1914, 605, 1928, 600, 1222, 1963, 272, 627, 91, 633, + /* 1980 */ 607, 92, 67, 1106, 642, 1878, 1207, 606, 1141, 1140, + /* 1990 */ 1206, 1139, 1138, 1137, 1136, 1134, 1910, 1132, 1131, 1130, + /* 2000 */ 1128, 1161, 1127, 1126, 654, 1125, 1124, 1123, 1908, 273, + /* 2010 */ 1122, 1121, 1944, 1158, 1910, 1156, 158, 1909, 1911, 610, + /* 2020 */ 1913, 1914, 605, 1118, 600, 1117, 1928, 1114, 1113, 1112, + /* 2030 */ 1111, 1629, 675, 677, 607, 1627, 676, 679, 680, 1878, + /* 2040 */ 681, 606, 1625, 683, 1928, 684, 1623, 687, 685, 689, + /* 2050 */ 688, 1609, 607, 691, 1066, 1591, 276, 1878, 2035, 606, + /* 2060 */ 695, 1566, 1908, 1346, 699, 284, 1944, 1566, 698, 1566, + /* 2070 */ 299, 1909, 1911, 610, 1913, 1914, 605, 1566, 600, 1566, + /* 2080 */ 1908, 1566, 1566, 1566, 1944, 1566, 1566, 1566, 159, 1909, + /* 2090 */ 1911, 610, 1913, 1914, 605, 1566, 600, 1910, 1566, 1566, + /* 2100 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 2110 */ 1566, 1566, 1566, 1566, 575, 1566, 1566, 1566, 1566, 1566, + /* 2120 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1928, 1566, 1566, + /* 2130 */ 1566, 1566, 351, 1566, 1566, 607, 1566, 1566, 1566, 1566, + /* 2140 */ 1878, 2087, 606, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 2150 */ 1566, 1566, 1910, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 2160 */ 1566, 1566, 1566, 1908, 1566, 1566, 1566, 1944, 1566, 1566, + /* 2170 */ 1566, 304, 1909, 1911, 610, 1913, 1914, 605, 1566, 600, + /* 2180 */ 1566, 1566, 1928, 1566, 1566, 1566, 1566, 354, 1566, 1566, + /* 2190 */ 607, 1566, 1566, 1566, 1566, 1878, 1566, 606, 1566, 1566, + /* 2200 */ 1566, 1566, 1566, 1910, 1566, 1566, 1566, 1566, 1566, 1566, + /* 2210 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1908, 1566, + /* 2220 */ 1566, 1566, 1944, 1566, 1566, 1566, 304, 1909, 1911, 610, + /* 2230 */ 1913, 1914, 605, 1928, 600, 1566, 1566, 1566, 1566, 1566, + /* 2240 */ 1566, 607, 1566, 1566, 1566, 1566, 1878, 1566, 606, 1566, + /* 2250 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1910, 1566, 1566, + /* 2260 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 520, + /* 2270 */ 1566, 1566, 1566, 1944, 1566, 1566, 1566, 297, 1909, 1911, + /* 2280 */ 610, 1913, 1914, 605, 1566, 600, 1566, 1928, 1566, 1566, + /* 2290 */ 1566, 1566, 1566, 1566, 1566, 607, 1566, 1566, 1566, 1566, + /* 2300 */ 1878, 1566, 606, 1566, 1566, 1566, 1566, 1566, 1910, 1566, + /* 2310 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 2320 */ 1566, 1566, 1566, 1908, 1566, 1566, 1566, 1944, 1566, 1566, + /* 2330 */ 1566, 289, 1909, 1911, 610, 1913, 1914, 605, 1928, 600, + /* 2340 */ 1566, 1566, 1566, 1566, 1566, 1566, 607, 1566, 1566, 1566, + /* 2350 */ 1566, 1878, 1566, 606, 1566, 1566, 1566, 1566, 1566, 1566, + /* 2360 */ 1566, 1566, 1910, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 2370 */ 1566, 1566, 1566, 1566, 1908, 1566, 1566, 1566, 1944, 1566, + /* 2380 */ 1910, 1566, 290, 1909, 1911, 610, 1913, 1914, 605, 1566, + /* 2390 */ 600, 1566, 1928, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 2400 */ 607, 1566, 1566, 1566, 1566, 1878, 1566, 606, 1566, 1566, + /* 2410 */ 1928, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 607, 1566, + /* 2420 */ 1566, 1566, 1566, 1878, 1566, 606, 1566, 1566, 1908, 1566, + /* 2430 */ 1566, 1566, 1944, 1566, 1566, 1566, 291, 1909, 1911, 610, + /* 2440 */ 1913, 1914, 605, 1566, 600, 1566, 1908, 1566, 1566, 1566, + /* 2450 */ 1944, 1566, 1566, 1566, 298, 1909, 1911, 610, 1913, 1914, + /* 2460 */ 605, 1566, 600, 1910, 1566, 1566, 1566, 1566, 1566, 1566, + /* 2470 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 2480 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 2490 */ 1566, 1566, 1566, 1928, 1566, 1566, 1566, 1566, 1566, 1566, + /* 2500 */ 1566, 607, 1566, 1566, 1566, 1566, 1878, 1566, 606, 1566, + /* 2510 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1910, 1566, + /* 2520 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1908, + /* 2530 */ 1566, 1566, 1566, 1944, 1566, 1566, 1566, 300, 1909, 1911, + /* 2540 */ 610, 1913, 1914, 605, 1566, 600, 1566, 1566, 1928, 1566, + /* 2550 */ 1566, 1566, 1566, 1566, 1566, 1566, 607, 1566, 1566, 1566, + /* 2560 */ 1566, 1878, 1566, 606, 1566, 1566, 1566, 1566, 1566, 1910, + /* 2570 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 2580 */ 1566, 1566, 1566, 1566, 1908, 1566, 1566, 1566, 1944, 1566, + /* 2590 */ 1566, 1566, 292, 1909, 1911, 610, 1913, 1914, 605, 1928, + /* 2600 */ 600, 1566, 1566, 1566, 1566, 1566, 1566, 607, 1566, 1566, + /* 2610 */ 1566, 1566, 1878, 1566, 606, 1566, 1566, 1566, 1566, 1566, + /* 2620 */ 1566, 1566, 1566, 1910, 1566, 1566, 1566, 1566, 1566, 1566, + /* 2630 */ 1566, 1566, 1566, 1566, 1566, 1908, 1566, 1566, 1566, 1944, + /* 2640 */ 1566, 1566, 1566, 301, 1909, 1911, 610, 1913, 1914, 605, + /* 2650 */ 1566, 600, 1566, 1928, 1566, 1566, 1566, 1566, 1566, 1566, + /* 2660 */ 1566, 607, 1566, 1566, 1566, 1566, 1878, 1566, 606, 1566, + /* 2670 */ 1566, 1566, 1566, 1566, 1910, 1566, 1566, 1566, 1566, 1566, + /* 2680 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1908, + /* 2690 */ 1566, 1566, 1566, 1944, 1566, 1566, 1566, 293, 1909, 1911, + /* 2700 */ 610, 1913, 1914, 605, 1928, 600, 1566, 1566, 1566, 1566, + /* 2710 */ 1566, 1566, 607, 1566, 1566, 1566, 1566, 1878, 1566, 606, + /* 2720 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1910, 1566, + /* 2730 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 2740 */ 1908, 1566, 1566, 1566, 1944, 1566, 1910, 1566, 302, 1909, + /* 2750 */ 1911, 610, 1913, 1914, 605, 1566, 600, 1566, 1928, 1566, + /* 2760 */ 1566, 1566, 1566, 1566, 1566, 1566, 607, 1566, 1566, 1566, + /* 2770 */ 1566, 1878, 1566, 606, 1566, 1566, 1928, 1566, 1566, 1566, + /* 2780 */ 1566, 1566, 1566, 1566, 607, 1566, 1566, 1566, 1566, 1878, + /* 2790 */ 1566, 606, 1566, 1566, 1908, 1566, 1566, 1566, 1944, 1566, + /* 2800 */ 1566, 1566, 294, 1909, 1911, 610, 1913, 1914, 605, 1566, + /* 2810 */ 600, 1566, 1908, 1566, 1566, 1566, 1944, 1566, 1566, 1566, + /* 2820 */ 309, 1909, 1911, 610, 1913, 1914, 605, 1566, 600, 1910, + /* 2830 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 2840 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 2850 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1928, + /* 2860 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 607, 1566, 1566, + /* 2870 */ 1566, 1566, 1878, 1566, 606, 1566, 1566, 1566, 1566, 1566, + /* 2880 */ 1566, 1566, 1566, 1566, 1910, 1566, 1566, 1566, 1566, 1566, + /* 2890 */ 1566, 1566, 1566, 1566, 1566, 1908, 1566, 1566, 1566, 1944, + /* 2900 */ 1566, 1566, 1566, 310, 1909, 1911, 610, 1913, 1914, 605, + /* 2910 */ 1566, 600, 1566, 1566, 1928, 1566, 1566, 1566, 1566, 1566, + /* 2920 */ 1566, 1566, 607, 1566, 1566, 1566, 1566, 1878, 1566, 606, + /* 2930 */ 1566, 1566, 1566, 1566, 1566, 1910, 1566, 1566, 1566, 1566, + /* 2940 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 2950 */ 1908, 1566, 1566, 1566, 1944, 1566, 1566, 1566, 1922, 1909, + /* 2960 */ 1911, 610, 1913, 1914, 605, 1928, 600, 1566, 1566, 1566, + /* 2970 */ 1566, 1566, 1566, 607, 1566, 1566, 1566, 1566, 1878, 1566, + /* 2980 */ 606, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1910, + /* 2990 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 3000 */ 1566, 1908, 1566, 1566, 1566, 1944, 1566, 1566, 1566, 1921, + /* 3010 */ 1909, 1911, 610, 1913, 1914, 605, 1566, 600, 1566, 1928, + /* 3020 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 607, 1566, 1566, + /* 3030 */ 1566, 1566, 1878, 1566, 606, 1566, 1566, 1566, 1566, 1566, + /* 3040 */ 1910, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 3050 */ 1566, 1566, 1566, 1566, 1566, 1908, 1566, 1566, 1566, 1944, + /* 3060 */ 1566, 1566, 1566, 1920, 1909, 1911, 610, 1913, 1914, 605, + /* 3070 */ 1928, 600, 1566, 1566, 1566, 1566, 1566, 1566, 607, 1566, + /* 3080 */ 1566, 1566, 1566, 1878, 1566, 606, 1566, 1566, 1566, 1566, + /* 3090 */ 1566, 1566, 1566, 1566, 1910, 1566, 1566, 1566, 1566, 1566, + /* 3100 */ 1566, 1566, 1566, 1566, 1566, 1566, 1908, 1566, 1566, 1566, + /* 3110 */ 1944, 1566, 1910, 1566, 319, 1909, 1911, 610, 1913, 1914, + /* 3120 */ 605, 1566, 600, 1566, 1928, 1566, 1566, 1566, 1566, 1566, + /* 3130 */ 1566, 1566, 607, 1566, 1566, 1566, 1566, 1878, 1566, 606, + /* 3140 */ 1566, 1566, 1928, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 3150 */ 607, 1566, 1566, 1566, 1566, 1878, 1566, 606, 1566, 1566, + /* 3160 */ 1908, 1566, 1566, 1566, 1944, 1566, 1566, 1566, 320, 1909, + /* 3170 */ 1911, 610, 1913, 1914, 605, 1566, 600, 1566, 1908, 1566, + /* 3180 */ 1566, 1566, 1944, 1566, 1566, 1566, 316, 1909, 1911, 610, + /* 3190 */ 1913, 1914, 605, 1566, 600, 1910, 1566, 1566, 1566, 1566, + /* 3200 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 3210 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 3220 */ 1566, 1566, 1566, 1566, 1566, 1928, 1566, 1566, 1566, 1566, + /* 3230 */ 1566, 1566, 1566, 607, 1566, 1566, 1566, 1566, 1878, 1566, + /* 3240 */ 606, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 3250 */ 1910, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 3260 */ 1566, 1908, 1566, 1566, 1566, 1944, 1566, 1566, 1566, 321, + /* 3270 */ 1909, 1911, 610, 1913, 1914, 605, 1566, 600, 1566, 1566, + /* 3280 */ 1928, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 607, 1566, + /* 3290 */ 1566, 1566, 1566, 1878, 1566, 606, 1566, 1566, 1566, 1566, + /* 3300 */ 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, 1566, + /* 3310 */ 1566, 1566, 1566, 1566, 1566, 1566, 1908, 1566, 1566, 1566, + /* 3320 */ 1944, 1566, 1566, 1566, 296, 1909, 1911, 610, 1913, 1914, + /* 3330 */ 605, 1566, 600, }; static const YYCODETYPE yy_lookahead[] = { - /* 0 */ 351, 409, 410, 351, 319, 4, 321, 320, 4, 364, - /* 10 */ 351, 362, 12, 13, 362, 324, 371, 326, 327, 374, - /* 20 */ 20, 362, 22, 12, 13, 14, 15, 16, 20, 333, - /* 30 */ 348, 317, 20, 33, 338, 35, 349, 388, 389, 390, - /* 40 */ 388, 389, 390, 361, 357, 44, 45, 388, 389, 362, - /* 50 */ 401, 364, 2, 401, 325, 320, 56, 328, 8, 9, - /* 60 */ 401, 61, 12, 13, 14, 15, 16, 320, 68, 12, - /* 70 */ 13, 14, 385, 320, 4, 20, 389, 20, 394, 22, - /* 80 */ 393, 394, 395, 396, 397, 398, 399, 332, 401, 19, - /* 90 */ 33, 377, 35, 406, 94, 408, 349, 362, 94, 412, - /* 100 */ 413, 346, 94, 33, 357, 328, 94, 423, 394, 362, - /* 110 */ 355, 364, 425, 56, 364, 362, 116, 47, 61, 320, - /* 120 */ 433, 51, 438, 439, 374, 68, 56, 443, 444, 20, - /* 130 */ 130, 131, 385, 394, 357, 328, 389, 423, 328, 320, - /* 140 */ 393, 394, 395, 396, 397, 398, 399, 324, 401, 326, - /* 150 */ 327, 94, 438, 439, 20, 408, 22, 443, 444, 412, - /* 160 */ 413, 362, 423, 93, 357, 39, 96, 94, 14, 35, - /* 170 */ 423, 394, 341, 116, 20, 175, 366, 177, 439, 126, - /* 180 */ 349, 362, 443, 444, 50, 438, 439, 130, 131, 358, - /* 190 */ 443, 444, 415, 416, 417, 418, 20, 420, 60, 199, - /* 200 */ 200, 394, 202, 203, 204, 205, 206, 207, 208, 209, + /* 0 */ 326, 351, 328, 329, 335, 326, 354, 328, 329, 367, + /* 10 */ 0, 330, 12, 13, 364, 344, 374, 365, 4, 377, + /* 20 */ 20, 0, 22, 352, 343, 330, 354, 358, 20, 354, + /* 30 */ 322, 350, 361, 33, 336, 35, 20, 365, 343, 341, + /* 40 */ 365, 360, 21, 391, 392, 24, 25, 26, 27, 28, + /* 50 */ 29, 30, 31, 32, 330, 360, 404, 57, 44, 45, + /* 60 */ 352, 20, 62, 391, 392, 393, 391, 392, 360, 69, + /* 70 */ 12, 13, 14, 365, 327, 367, 404, 330, 20, 404, + /* 80 */ 22, 61, 8, 9, 360, 352, 12, 13, 14, 15, + /* 90 */ 16, 33, 322, 35, 20, 95, 388, 321, 330, 323, + /* 100 */ 392, 368, 354, 95, 396, 397, 398, 399, 400, 401, + /* 110 */ 402, 343, 404, 365, 95, 57, 330, 117, 322, 411, + /* 120 */ 62, 397, 352, 415, 416, 330, 0, 69, 360, 343, + /* 130 */ 360, 131, 132, 106, 426, 365, 350, 367, 95, 391, + /* 140 */ 392, 393, 418, 419, 420, 421, 360, 423, 352, 441, + /* 150 */ 442, 14, 404, 95, 446, 447, 360, 20, 388, 335, + /* 160 */ 322, 365, 392, 367, 369, 37, 396, 397, 398, 399, + /* 170 */ 400, 401, 402, 349, 404, 117, 176, 407, 178, 409, + /* 180 */ 410, 411, 358, 352, 388, 415, 416, 61, 392, 131, + /* 190 */ 132, 360, 396, 397, 398, 399, 400, 401, 402, 79, + /* 200 */ 404, 201, 202, 365, 204, 205, 206, 207, 208, 209, /* 210 */ 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, - /* 220 */ 220, 221, 222, 416, 417, 418, 0, 420, 363, 364, - /* 230 */ 423, 14, 175, 170, 177, 182, 183, 20, 377, 186, - /* 240 */ 240, 199, 335, 336, 240, 438, 439, 174, 240, 176, - /* 250 */ 443, 444, 240, 190, 191, 394, 199, 200, 94, 202, - /* 260 */ 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, - /* 270 */ 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, - /* 280 */ 12, 13, 19, 56, 423, 125, 126, 20, 20, 332, - /* 290 */ 22, 249, 250, 251, 252, 253, 33, 328, 320, 438, - /* 300 */ 439, 33, 328, 35, 443, 444, 130, 131, 3, 340, - /* 310 */ 47, 351, 355, 240, 340, 52, 53, 54, 55, 56, - /* 320 */ 93, 347, 362, 96, 56, 342, 357, 349, 345, 61, - /* 330 */ 360, 357, 106, 363, 364, 357, 68, 12, 13, 20, - /* 340 */ 362, 22, 364, 183, 20, 20, 186, 22, 388, 389, - /* 350 */ 160, 125, 126, 127, 128, 129, 93, 203, 33, 96, - /* 360 */ 35, 401, 94, 385, 14, 239, 328, 389, 106, 50, - /* 370 */ 20, 393, 394, 395, 396, 397, 398, 399, 340, 401, - /* 380 */ 94, 56, 0, 22, 116, 347, 61, 125, 126, 127, - /* 390 */ 128, 129, 129, 68, 325, 357, 35, 328, 130, 131, - /* 400 */ 95, 423, 22, 21, 240, 78, 24, 25, 26, 27, - /* 410 */ 28, 29, 30, 31, 32, 35, 438, 439, 94, 94, - /* 420 */ 203, 443, 444, 21, 161, 328, 24, 25, 26, 27, - /* 430 */ 28, 29, 30, 31, 32, 245, 246, 340, 63, 64, - /* 440 */ 65, 116, 179, 175, 181, 177, 71, 72, 68, 320, - /* 450 */ 349, 76, 77, 349, 357, 130, 131, 82, 83, 358, - /* 460 */ 356, 134, 135, 88, 35, 44, 45, 199, 200, 365, - /* 470 */ 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, - /* 480 */ 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, - /* 490 */ 222, 362, 224, 14, 15, 16, 116, 68, 238, 239, - /* 500 */ 175, 0, 177, 125, 20, 157, 107, 108, 109, 110, - /* 510 */ 111, 112, 113, 114, 115, 116, 117, 60, 119, 120, - /* 520 */ 121, 122, 123, 124, 199, 200, 240, 202, 203, 204, - /* 530 */ 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, - /* 540 */ 215, 216, 217, 218, 219, 220, 221, 222, 12, 13, - /* 550 */ 357, 341, 349, 3, 391, 175, 20, 177, 22, 349, - /* 560 */ 357, 368, 184, 185, 63, 64, 65, 105, 358, 33, - /* 570 */ 20, 35, 71, 72, 328, 227, 56, 76, 77, 199, - /* 580 */ 200, 320, 419, 82, 83, 237, 340, 0, 0, 88, - /* 590 */ 8, 9, 56, 20, 12, 13, 14, 15, 16, 396, - /* 600 */ 320, 349, 68, 357, 68, 12, 13, 14, 356, 328, - /* 610 */ 349, 42, 43, 20, 94, 22, 96, 365, 357, 328, - /* 620 */ 224, 340, 226, 362, 341, 364, 33, 349, 35, 349, - /* 630 */ 94, 340, 349, 404, 356, 394, 407, 357, 357, 328, - /* 640 */ 320, 358, 362, 365, 364, 95, 385, 60, 357, 56, - /* 650 */ 389, 340, 116, 377, 393, 394, 395, 396, 397, 398, - /* 660 */ 399, 68, 401, 4, 423, 385, 130, 131, 357, 389, - /* 670 */ 394, 328, 394, 393, 394, 395, 396, 397, 398, 399, - /* 680 */ 439, 401, 362, 340, 443, 444, 406, 94, 408, 405, - /* 690 */ 21, 407, 412, 413, 349, 434, 435, 335, 336, 423, - /* 700 */ 357, 423, 422, 34, 0, 36, 405, 224, 407, 116, - /* 710 */ 365, 175, 162, 177, 438, 439, 438, 439, 20, 443, - /* 720 */ 444, 443, 444, 130, 131, 8, 9, 1, 2, 12, - /* 730 */ 13, 14, 15, 16, 0, 199, 200, 20, 202, 203, - /* 740 */ 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, - /* 750 */ 214, 215, 216, 217, 218, 219, 220, 221, 222, 0, - /* 760 */ 240, 68, 20, 357, 60, 373, 357, 375, 175, 337, - /* 770 */ 177, 339, 330, 37, 368, 350, 240, 368, 320, 381, - /* 780 */ 373, 47, 375, 24, 25, 26, 27, 28, 29, 30, - /* 790 */ 31, 32, 199, 200, 352, 202, 203, 204, 205, 206, - /* 800 */ 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, - /* 810 */ 217, 218, 219, 220, 221, 222, 12, 13, 0, 328, - /* 820 */ 362, 95, 359, 377, 20, 362, 22, 391, 391, 359, - /* 830 */ 43, 340, 362, 97, 320, 99, 100, 33, 102, 35, - /* 840 */ 394, 377, 106, 330, 106, 20, 8, 9, 357, 320, - /* 850 */ 12, 13, 14, 15, 16, 419, 419, 344, 394, 328, - /* 860 */ 56, 350, 3, 328, 128, 352, 128, 320, 320, 423, - /* 870 */ 328, 340, 68, 12, 13, 340, 362, 350, 349, 162, - /* 880 */ 43, 20, 340, 22, 438, 439, 357, 423, 357, 443, - /* 890 */ 444, 362, 357, 364, 33, 350, 35, 349, 94, 357, - /* 900 */ 241, 203, 438, 439, 162, 357, 350, 443, 444, 362, - /* 910 */ 362, 350, 364, 342, 385, 320, 345, 56, 389, 328, - /* 920 */ 116, 320, 393, 394, 395, 396, 397, 398, 399, 68, - /* 930 */ 401, 340, 95, 385, 130, 131, 320, 389, 320, 328, - /* 940 */ 0, 393, 394, 395, 396, 397, 398, 399, 357, 401, - /* 950 */ 349, 340, 162, 163, 406, 94, 408, 362, 357, 328, - /* 960 */ 412, 413, 22, 362, 328, 364, 148, 350, 357, 43, - /* 970 */ 422, 340, 328, 94, 445, 446, 340, 116, 362, 175, - /* 980 */ 362, 177, 0, 104, 340, 338, 385, 162, 357, 105, - /* 990 */ 389, 130, 131, 357, 393, 394, 395, 396, 397, 398, - /* 1000 */ 399, 357, 401, 199, 200, 167, 202, 203, 204, 205, - /* 1010 */ 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, - /* 1020 */ 216, 217, 218, 219, 220, 221, 222, 8, 9, 33, - /* 1030 */ 328, 12, 13, 14, 15, 16, 175, 153, 177, 130, - /* 1040 */ 131, 98, 340, 47, 101, 320, 259, 446, 52, 53, - /* 1050 */ 54, 55, 56, 320, 98, 1, 2, 101, 321, 357, - /* 1060 */ 199, 200, 0, 202, 203, 204, 205, 206, 207, 208, - /* 1070 */ 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, - /* 1080 */ 219, 220, 221, 222, 18, 447, 20, 362, 106, 93, - /* 1090 */ 56, 98, 96, 27, 101, 362, 30, 0, 8, 9, - /* 1100 */ 262, 392, 12, 13, 14, 15, 16, 125, 126, 127, - /* 1110 */ 128, 129, 436, 47, 95, 49, 257, 51, 320, 22, - /* 1120 */ 35, 98, 320, 320, 101, 63, 64, 65, 66, 67, - /* 1130 */ 96, 69, 70, 71, 72, 73, 74, 75, 76, 77, - /* 1140 */ 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, - /* 1150 */ 88, 89, 90, 18, 158, 159, 320, 161, 23, 93, - /* 1160 */ 362, 165, 8, 9, 362, 362, 12, 13, 14, 15, - /* 1170 */ 16, 105, 37, 38, 0, 43, 41, 181, 61, 43, - /* 1180 */ 329, 43, 43, 430, 320, 95, 43, 261, 43, 349, - /* 1190 */ 327, 43, 57, 58, 59, 320, 22, 43, 362, 133, - /* 1200 */ 329, 43, 136, 137, 138, 139, 140, 141, 142, 143, - /* 1210 */ 144, 145, 146, 147, 148, 149, 150, 151, 152, 361, - /* 1220 */ 154, 155, 156, 328, 349, 392, 362, 95, 43, 94, - /* 1230 */ 35, 95, 357, 95, 95, 340, 0, 362, 95, 364, - /* 1240 */ 95, 8, 9, 95, 2, 12, 13, 14, 15, 16, - /* 1250 */ 8, 9, 357, 95, 12, 13, 14, 15, 16, 440, - /* 1260 */ 385, 414, 177, 68, 389, 46, 328, 132, 393, 394, - /* 1270 */ 395, 396, 397, 398, 399, 35, 401, 320, 340, 404, - /* 1280 */ 95, 406, 407, 408, 48, 8, 9, 412, 413, 12, - /* 1290 */ 13, 14, 15, 16, 61, 357, 43, 43, 421, 242, - /* 1300 */ 424, 377, 167, 168, 169, 387, 349, 172, 47, 43, - /* 1310 */ 173, 354, 43, 94, 357, 13, 199, 43, 394, 362, - /* 1320 */ 386, 364, 43, 13, 189, 379, 42, 192, 320, 194, - /* 1330 */ 195, 196, 197, 198, 369, 369, 103, 35, 157, 367, - /* 1340 */ 20, 328, 385, 328, 328, 35, 389, 423, 95, 95, - /* 1350 */ 393, 394, 395, 396, 397, 398, 399, 349, 401, 369, - /* 1360 */ 328, 95, 438, 439, 95, 357, 367, 443, 444, 95, - /* 1370 */ 362, 367, 364, 357, 95, 240, 334, 92, 328, 328, - /* 1380 */ 328, 20, 322, 322, 20, 383, 364, 332, 332, 357, - /* 1390 */ 157, 20, 20, 385, 376, 378, 332, 389, 328, 332, - /* 1400 */ 376, 393, 394, 395, 396, 397, 398, 399, 332, 401, - /* 1410 */ 394, 332, 332, 322, 406, 328, 408, 177, 349, 188, - /* 1420 */ 412, 413, 349, 349, 349, 322, 394, 349, 384, 383, - /* 1430 */ 349, 349, 416, 417, 418, 349, 420, 349, 349, 162, - /* 1440 */ 330, 433, 349, 180, 330, 362, 320, 382, 416, 417, - /* 1450 */ 418, 328, 420, 328, 330, 247, 364, 159, 362, 330, - /* 1460 */ 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, - /* 1470 */ 237, 376, 372, 362, 362, 349, 372, 362, 362, 370, - /* 1480 */ 330, 20, 362, 357, 357, 345, 392, 248, 362, 254, - /* 1490 */ 364, 392, 429, 372, 372, 362, 362, 429, 166, 256, - /* 1500 */ 255, 429, 431, 362, 362, 243, 387, 263, 260, 432, - /* 1510 */ 258, 385, 428, 320, 239, 389, 357, 20, 94, 393, - /* 1520 */ 394, 395, 396, 397, 398, 399, 94, 401, 427, 411, - /* 1530 */ 353, 426, 406, 362, 408, 320, 339, 391, 412, 413, - /* 1540 */ 328, 330, 349, 36, 442, 323, 448, 441, 422, 322, - /* 1550 */ 357, 375, 380, 343, 331, 362, 343, 364, 0, 343, - /* 1560 */ 0, 182, 0, 0, 349, 318, 42, 0, 35, 193, - /* 1570 */ 35, 35, 357, 35, 193, 0, 35, 362, 385, 364, - /* 1580 */ 35, 193, 389, 0, 193, 0, 393, 394, 395, 396, - /* 1590 */ 397, 398, 399, 320, 401, 0, 35, 0, 22, 406, - /* 1600 */ 385, 408, 177, 35, 389, 412, 413, 171, 393, 394, - /* 1610 */ 395, 396, 397, 398, 399, 320, 401, 175, 0, 12, - /* 1620 */ 13, 406, 349, 408, 0, 170, 0, 412, 413, 22, - /* 1630 */ 357, 0, 46, 0, 0, 362, 42, 364, 0, 0, - /* 1640 */ 33, 0, 35, 0, 349, 42, 0, 0, 0, 0, - /* 1650 */ 0, 148, 357, 0, 35, 0, 148, 362, 385, 364, - /* 1660 */ 0, 0, 389, 56, 0, 0, 393, 394, 395, 396, - /* 1670 */ 397, 398, 399, 0, 401, 68, 0, 0, 0, 406, - /* 1680 */ 385, 408, 0, 0, 389, 412, 413, 42, 393, 394, - /* 1690 */ 395, 396, 397, 398, 399, 0, 401, 0, 0, 0, - /* 1700 */ 0, 0, 0, 408, 0, 0, 22, 412, 413, 0, - /* 1710 */ 0, 0, 0, 0, 35, 56, 0, 0, 56, 0, - /* 1720 */ 39, 14, 320, 116, 0, 0, 46, 42, 14, 43, - /* 1730 */ 40, 39, 0, 0, 46, 39, 166, 0, 0, 0, - /* 1740 */ 0, 0, 0, 35, 0, 39, 0, 0, 0, 0, - /* 1750 */ 47, 349, 0, 62, 103, 35, 35, 39, 35, 357, - /* 1760 */ 0, 95, 47, 0, 362, 39, 364, 39, 101, 47, - /* 1770 */ 35, 35, 22, 22, 47, 0, 0, 43, 35, 49, - /* 1780 */ 35, 0, 175, 22, 177, 20, 22, 385, 35, 35, - /* 1790 */ 320, 389, 35, 35, 22, 393, 394, 395, 396, 397, - /* 1800 */ 398, 399, 43, 401, 35, 22, 199, 200, 35, 320, - /* 1810 */ 408, 0, 35, 0, 412, 413, 22, 0, 162, 349, - /* 1820 */ 213, 214, 215, 216, 217, 218, 219, 357, 35, 0, - /* 1830 */ 178, 22, 362, 162, 364, 0, 0, 162, 349, 0, - /* 1840 */ 3, 0, 0, 35, 187, 0, 357, 46, 159, 94, - /* 1850 */ 94, 362, 0, 364, 160, 385, 94, 164, 39, 389, - /* 1860 */ 223, 95, 94, 393, 394, 395, 396, 397, 398, 399, - /* 1870 */ 400, 401, 402, 403, 385, 104, 320, 43, 389, 225, - /* 1880 */ 94, 223, 393, 394, 395, 396, 397, 398, 399, 158, - /* 1890 */ 401, 43, 94, 320, 95, 95, 94, 408, 95, 94, - /* 1900 */ 43, 95, 413, 43, 94, 349, 94, 244, 94, 46, - /* 1910 */ 95, 46, 94, 357, 244, 43, 95, 95, 362, 3, - /* 1920 */ 364, 43, 349, 35, 35, 35, 35, 35, 35, 46, - /* 1930 */ 357, 46, 46, 95, 2, 362, 320, 364, 95, 43, - /* 1940 */ 22, 385, 22, 94, 94, 389, 95, 46, 95, 393, - /* 1950 */ 394, 395, 396, 397, 398, 399, 320, 401, 385, 403, - /* 1960 */ 94, 94, 389, 95, 94, 349, 393, 394, 395, 396, - /* 1970 */ 397, 398, 399, 357, 401, 46, 95, 95, 362, 199, - /* 1980 */ 364, 94, 105, 201, 35, 349, 35, 35, 94, 94, - /* 1990 */ 354, 35, 95, 357, 95, 95, 94, 35, 362, 94, - /* 2000 */ 364, 385, 95, 35, 94, 389, 22, 320, 435, 393, - /* 2010 */ 394, 395, 396, 397, 398, 399, 238, 401, 244, 106, - /* 2020 */ 94, 385, 118, 35, 118, 389, 118, 118, 94, 393, - /* 2030 */ 394, 395, 396, 397, 398, 399, 349, 401, 94, 43, - /* 2040 */ 22, 354, 62, 61, 357, 35, 35, 35, 35, 362, - /* 2050 */ 35, 364, 35, 437, 35, 35, 35, 35, 68, 43, - /* 2060 */ 91, 35, 35, 22, 35, 22, 35, 35, 35, 68, - /* 2070 */ 35, 35, 385, 35, 35, 35, 389, 22, 0, 35, - /* 2080 */ 393, 394, 395, 396, 397, 398, 399, 320, 401, 47, - /* 2090 */ 39, 35, 0, 35, 47, 0, 39, 35, 39, 47, - /* 2100 */ 0, 35, 39, 0, 35, 320, 35, 47, 0, 22, - /* 2110 */ 21, 449, 22, 22, 21, 449, 349, 20, 449, 449, - /* 2120 */ 449, 449, 449, 449, 357, 449, 449, 449, 449, 362, - /* 2130 */ 449, 364, 449, 449, 349, 449, 449, 449, 449, 449, - /* 2140 */ 449, 449, 357, 449, 449, 449, 449, 362, 320, 364, - /* 2150 */ 449, 449, 385, 449, 449, 449, 389, 449, 449, 449, - /* 2160 */ 393, 394, 395, 396, 397, 398, 399, 320, 401, 449, - /* 2170 */ 385, 449, 449, 449, 389, 449, 449, 349, 393, 394, - /* 2180 */ 395, 396, 397, 398, 399, 357, 401, 449, 449, 449, - /* 2190 */ 362, 320, 364, 449, 449, 449, 349, 449, 449, 449, - /* 2200 */ 449, 449, 449, 449, 357, 449, 449, 449, 449, 362, - /* 2210 */ 449, 364, 449, 385, 449, 449, 449, 389, 449, 449, - /* 2220 */ 349, 393, 394, 395, 396, 397, 398, 399, 357, 401, - /* 2230 */ 449, 449, 385, 362, 320, 364, 389, 449, 449, 449, - /* 2240 */ 393, 394, 395, 396, 397, 398, 399, 449, 401, 449, - /* 2250 */ 449, 320, 449, 449, 449, 449, 385, 449, 449, 449, - /* 2260 */ 389, 449, 449, 349, 393, 394, 395, 396, 397, 398, - /* 2270 */ 399, 357, 401, 449, 449, 449, 362, 320, 364, 449, - /* 2280 */ 349, 449, 449, 449, 449, 449, 449, 449, 357, 449, - /* 2290 */ 449, 449, 449, 362, 320, 364, 449, 449, 449, 385, - /* 2300 */ 449, 449, 449, 389, 449, 449, 349, 393, 394, 395, - /* 2310 */ 396, 397, 398, 399, 357, 401, 385, 449, 449, 362, - /* 2320 */ 389, 364, 449, 349, 393, 394, 395, 396, 397, 398, - /* 2330 */ 399, 357, 401, 449, 449, 449, 362, 449, 364, 449, - /* 2340 */ 449, 449, 385, 449, 449, 449, 389, 449, 449, 449, - /* 2350 */ 393, 394, 395, 396, 397, 398, 399, 320, 401, 385, - /* 2360 */ 449, 449, 449, 389, 449, 449, 449, 393, 394, 395, - /* 2370 */ 396, 397, 398, 399, 320, 401, 449, 449, 449, 449, - /* 2380 */ 449, 449, 449, 449, 449, 449, 349, 449, 449, 449, - /* 2390 */ 449, 449, 449, 449, 357, 449, 449, 449, 449, 362, - /* 2400 */ 449, 364, 449, 349, 449, 449, 449, 449, 449, 449, - /* 2410 */ 449, 357, 449, 449, 449, 449, 362, 449, 364, 449, - /* 2420 */ 449, 449, 385, 449, 449, 449, 389, 449, 449, 449, - /* 2430 */ 393, 394, 395, 396, 397, 398, 399, 320, 401, 385, - /* 2440 */ 449, 449, 449, 389, 449, 449, 449, 393, 394, 395, - /* 2450 */ 396, 397, 398, 399, 449, 401, 449, 449, 449, 449, - /* 2460 */ 449, 449, 449, 320, 449, 449, 349, 449, 449, 449, - /* 2470 */ 449, 449, 449, 449, 357, 449, 449, 449, 449, 362, - /* 2480 */ 449, 364, 449, 449, 449, 449, 449, 449, 449, 449, - /* 2490 */ 449, 449, 349, 449, 449, 449, 449, 449, 449, 449, - /* 2500 */ 357, 449, 385, 449, 449, 362, 389, 364, 449, 449, - /* 2510 */ 393, 394, 395, 396, 397, 398, 399, 320, 401, 449, - /* 2520 */ 449, 449, 449, 449, 449, 449, 449, 449, 385, 449, - /* 2530 */ 449, 449, 389, 449, 320, 449, 393, 394, 395, 396, - /* 2540 */ 397, 398, 399, 449, 401, 449, 349, 449, 449, 449, - /* 2550 */ 449, 449, 449, 449, 357, 449, 449, 449, 449, 362, - /* 2560 */ 449, 364, 449, 349, 449, 449, 449, 449, 449, 449, - /* 2570 */ 449, 357, 449, 449, 449, 449, 362, 320, 364, 449, - /* 2580 */ 449, 449, 385, 449, 449, 449, 389, 449, 449, 449, - /* 2590 */ 393, 394, 395, 396, 397, 398, 399, 320, 401, 385, - /* 2600 */ 449, 449, 449, 389, 449, 449, 349, 393, 394, 395, - /* 2610 */ 396, 397, 398, 399, 357, 401, 449, 449, 449, 362, - /* 2620 */ 449, 364, 449, 449, 449, 449, 349, 449, 449, 449, - /* 2630 */ 449, 449, 449, 449, 357, 449, 449, 449, 449, 362, - /* 2640 */ 320, 364, 385, 449, 449, 449, 389, 449, 449, 449, - /* 2650 */ 393, 394, 395, 396, 397, 398, 399, 320, 401, 449, - /* 2660 */ 449, 449, 385, 449, 449, 449, 389, 449, 449, 349, - /* 2670 */ 393, 394, 395, 396, 397, 398, 399, 357, 401, 449, - /* 2680 */ 449, 449, 362, 449, 364, 449, 349, 449, 449, 449, - /* 2690 */ 449, 449, 449, 449, 357, 449, 449, 449, 449, 362, - /* 2700 */ 449, 364, 449, 449, 449, 385, 449, 449, 449, 389, - /* 2710 */ 449, 449, 449, 393, 394, 395, 396, 397, 398, 399, - /* 2720 */ 320, 401, 385, 449, 449, 449, 389, 449, 449, 449, - /* 2730 */ 393, 394, 395, 396, 397, 398, 399, 320, 401, 449, - /* 2740 */ 449, 449, 449, 449, 449, 449, 449, 449, 449, 349, - /* 2750 */ 449, 449, 449, 449, 449, 449, 449, 357, 449, 449, - /* 2760 */ 449, 449, 362, 449, 364, 449, 349, 449, 449, 449, - /* 2770 */ 449, 449, 449, 449, 357, 449, 449, 449, 449, 362, - /* 2780 */ 449, 364, 449, 449, 449, 385, 449, 449, 449, 389, - /* 2790 */ 449, 449, 449, 393, 394, 395, 396, 397, 398, 399, - /* 2800 */ 449, 401, 385, 449, 449, 449, 389, 449, 449, 449, - /* 2810 */ 393, 394, 395, 396, 397, 398, 399, 449, 401, + /* 220 */ 220, 221, 222, 223, 224, 319, 98, 20, 100, 101, + /* 230 */ 399, 103, 127, 20, 176, 107, 178, 163, 327, 126, + /* 240 */ 127, 330, 242, 21, 448, 449, 24, 25, 26, 27, + /* 250 */ 28, 29, 30, 31, 32, 135, 136, 129, 57, 201, + /* 260 */ 202, 242, 204, 205, 206, 207, 208, 209, 210, 211, + /* 270 */ 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, + /* 280 */ 222, 223, 224, 12, 13, 242, 380, 20, 183, 184, + /* 290 */ 61, 20, 187, 22, 189, 94, 0, 184, 97, 20, + /* 300 */ 187, 322, 189, 397, 33, 397, 35, 108, 109, 110, + /* 310 */ 111, 112, 113, 114, 115, 116, 117, 118, 57, 120, + /* 320 */ 121, 122, 123, 124, 125, 226, 363, 228, 57, 366, + /* 330 */ 367, 352, 426, 62, 426, 394, 4, 14, 333, 360, + /* 340 */ 69, 12, 13, 20, 365, 0, 367, 441, 442, 20, + /* 350 */ 442, 22, 446, 447, 446, 447, 95, 61, 97, 19, + /* 360 */ 355, 95, 33, 422, 35, 201, 95, 388, 171, 39, + /* 370 */ 20, 392, 22, 33, 95, 396, 397, 398, 399, 400, + /* 380 */ 401, 402, 0, 404, 20, 35, 57, 47, 117, 192, + /* 390 */ 193, 62, 47, 53, 54, 55, 56, 57, 69, 4, + /* 400 */ 50, 35, 131, 132, 226, 426, 24, 25, 26, 27, + /* 410 */ 28, 29, 30, 31, 32, 251, 252, 253, 254, 255, + /* 420 */ 441, 442, 352, 69, 95, 446, 447, 95, 322, 359, + /* 430 */ 163, 64, 65, 66, 94, 69, 14, 97, 368, 72, + /* 440 */ 73, 175, 20, 177, 77, 78, 117, 176, 69, 178, + /* 450 */ 83, 84, 380, 0, 20, 20, 89, 360, 8, 9, + /* 460 */ 131, 132, 12, 13, 14, 15, 16, 397, 371, 397, + /* 470 */ 130, 365, 201, 202, 353, 204, 205, 206, 207, 208, + /* 480 */ 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, + /* 490 */ 219, 220, 221, 222, 223, 224, 426, 226, 426, 352, + /* 500 */ 412, 413, 162, 242, 353, 176, 359, 178, 242, 353, + /* 510 */ 333, 441, 442, 441, 442, 368, 446, 447, 446, 447, + /* 520 */ 180, 242, 182, 57, 347, 366, 367, 322, 205, 95, + /* 530 */ 201, 202, 355, 204, 205, 206, 207, 208, 209, 210, + /* 540 */ 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, + /* 550 */ 221, 222, 223, 224, 12, 13, 3, 352, 338, 339, + /* 560 */ 107, 344, 20, 97, 22, 360, 131, 132, 161, 352, + /* 570 */ 365, 241, 367, 20, 242, 33, 360, 35, 361, 126, + /* 580 */ 127, 128, 129, 130, 8, 9, 322, 371, 12, 13, + /* 590 */ 14, 15, 16, 388, 408, 330, 410, 392, 20, 57, + /* 600 */ 22, 396, 397, 398, 399, 400, 401, 402, 343, 404, + /* 610 */ 352, 69, 12, 13, 14, 158, 352, 359, 168, 21, + /* 620 */ 20, 357, 22, 330, 360, 360, 368, 205, 50, 365, + /* 630 */ 353, 367, 34, 33, 36, 35, 343, 95, 243, 126, + /* 640 */ 8, 9, 437, 438, 12, 13, 14, 15, 16, 96, + /* 650 */ 344, 353, 388, 360, 247, 248, 392, 57, 352, 117, + /* 660 */ 396, 397, 398, 399, 400, 401, 402, 361, 404, 69, + /* 670 */ 12, 13, 96, 131, 132, 22, 242, 8, 9, 330, + /* 680 */ 22, 12, 13, 14, 15, 16, 229, 345, 35, 330, + /* 690 */ 348, 33, 343, 35, 2, 95, 239, 394, 185, 186, + /* 700 */ 8, 9, 343, 367, 12, 13, 14, 15, 16, 360, + /* 710 */ 394, 330, 43, 377, 264, 57, 163, 117, 176, 360, + /* 720 */ 178, 3, 69, 2, 343, 422, 22, 69, 96, 8, + /* 730 */ 9, 131, 132, 12, 13, 14, 15, 16, 422, 35, + /* 740 */ 397, 360, 407, 201, 202, 410, 204, 205, 206, 207, + /* 750 */ 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, + /* 760 */ 218, 219, 220, 221, 222, 223, 224, 1, 2, 426, + /* 770 */ 117, 14, 15, 16, 353, 117, 176, 107, 178, 12, + /* 780 */ 13, 14, 15, 16, 242, 442, 353, 8, 9, 446, + /* 790 */ 447, 12, 13, 14, 15, 16, 126, 127, 128, 129, + /* 800 */ 130, 201, 202, 43, 204, 205, 206, 207, 208, 209, + /* 810 */ 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, + /* 820 */ 220, 221, 222, 223, 224, 12, 13, 107, 330, 176, + /* 830 */ 376, 178, 378, 20, 176, 22, 178, 43, 408, 330, + /* 840 */ 410, 343, 338, 339, 384, 322, 33, 322, 35, 129, + /* 850 */ 330, 380, 343, 360, 201, 202, 96, 322, 360, 201, + /* 860 */ 202, 20, 96, 343, 371, 44, 45, 322, 397, 360, + /* 870 */ 57, 322, 341, 215, 216, 217, 218, 219, 220, 221, + /* 880 */ 360, 330, 69, 12, 13, 330, 330, 352, 365, 323, + /* 890 */ 365, 20, 380, 22, 343, 360, 0, 426, 343, 343, + /* 900 */ 365, 340, 367, 342, 33, 322, 35, 106, 95, 397, + /* 910 */ 365, 360, 441, 442, 365, 360, 360, 446, 447, 0, + /* 920 */ 376, 322, 378, 388, 322, 240, 241, 392, 57, 322, + /* 930 */ 117, 396, 397, 398, 399, 400, 401, 402, 426, 404, + /* 940 */ 69, 22, 163, 322, 131, 132, 411, 322, 365, 0, + /* 950 */ 415, 416, 330, 441, 442, 154, 322, 330, 446, 447, + /* 960 */ 64, 65, 66, 43, 365, 343, 95, 365, 72, 73, + /* 970 */ 343, 22, 365, 77, 78, 362, 395, 259, 365, 83, + /* 980 */ 84, 331, 360, 20, 33, 89, 365, 360, 117, 176, + /* 990 */ 365, 178, 380, 0, 380, 43, 322, 450, 47, 365, + /* 1000 */ 322, 322, 131, 132, 53, 54, 55, 56, 57, 397, + /* 1010 */ 362, 397, 43, 365, 201, 202, 96, 204, 205, 206, + /* 1020 */ 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, + /* 1030 */ 217, 218, 219, 220, 221, 222, 223, 224, 426, 365, + /* 1040 */ 426, 352, 439, 365, 365, 94, 205, 176, 97, 178, + /* 1050 */ 361, 42, 43, 441, 442, 441, 442, 263, 446, 447, + /* 1060 */ 446, 447, 8, 9, 322, 96, 12, 13, 14, 15, + /* 1070 */ 16, 322, 201, 202, 0, 204, 205, 206, 207, 208, + /* 1080 */ 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, + /* 1090 */ 219, 220, 221, 222, 223, 224, 18, 0, 20, 345, + /* 1100 */ 107, 330, 348, 163, 164, 27, 330, 365, 30, 99, + /* 1110 */ 159, 160, 102, 162, 365, 99, 43, 166, 102, 126, + /* 1120 */ 127, 128, 129, 130, 322, 47, 163, 49, 43, 99, + /* 1130 */ 52, 360, 102, 182, 99, 43, 360, 102, 64, 65, + /* 1140 */ 66, 67, 68, 433, 70, 71, 72, 73, 74, 75, + /* 1150 */ 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, + /* 1160 */ 86, 87, 88, 89, 90, 91, 18, 365, 397, 96, + /* 1170 */ 330, 23, 94, 397, 62, 131, 132, 1, 2, 43, + /* 1180 */ 35, 96, 3, 343, 106, 37, 38, 0, 96, 41, + /* 1190 */ 419, 420, 421, 0, 423, 419, 420, 421, 43, 423, + /* 1200 */ 360, 43, 352, 43, 331, 43, 58, 59, 60, 22, + /* 1210 */ 43, 43, 134, 261, 322, 137, 138, 139, 140, 141, + /* 1220 */ 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, + /* 1230 */ 152, 153, 96, 155, 156, 157, 35, 329, 46, 364, + /* 1240 */ 330, 48, 330, 95, 352, 43, 149, 330, 395, 43, + /* 1250 */ 424, 96, 360, 343, 96, 343, 96, 365, 96, 367, + /* 1260 */ 343, 8, 9, 96, 96, 12, 13, 14, 15, 16, + /* 1270 */ 360, 4, 360, 95, 443, 96, 330, 360, 417, 427, + /* 1280 */ 388, 133, 397, 105, 392, 244, 19, 95, 396, 397, + /* 1290 */ 398, 399, 400, 401, 402, 35, 404, 43, 96, 390, + /* 1300 */ 33, 409, 96, 411, 47, 389, 360, 415, 416, 174, + /* 1310 */ 382, 426, 13, 201, 47, 62, 168, 169, 170, 52, + /* 1320 */ 428, 173, 42, 178, 57, 322, 441, 442, 436, 69, + /* 1330 */ 13, 446, 447, 372, 35, 158, 372, 370, 20, 191, + /* 1340 */ 372, 330, 194, 397, 196, 197, 198, 199, 200, 330, + /* 1350 */ 96, 322, 35, 370, 370, 352, 93, 104, 337, 20, + /* 1360 */ 324, 94, 330, 360, 97, 419, 420, 421, 365, 423, + /* 1370 */ 367, 324, 426, 330, 20, 330, 386, 335, 20, 178, + /* 1380 */ 367, 352, 20, 335, 379, 381, 335, 441, 442, 360, + /* 1390 */ 242, 388, 446, 447, 365, 392, 367, 379, 335, 396, + /* 1400 */ 397, 398, 399, 400, 401, 402, 335, 404, 51, 330, + /* 1410 */ 335, 158, 409, 332, 411, 335, 332, 388, 415, 416, + /* 1420 */ 324, 392, 352, 330, 352, 396, 397, 398, 399, 400, + /* 1430 */ 401, 402, 324, 404, 352, 352, 190, 387, 409, 436, + /* 1440 */ 411, 352, 352, 352, 415, 416, 352, 352, 386, 333, + /* 1450 */ 352, 352, 365, 181, 425, 367, 333, 330, 330, 333, + /* 1460 */ 249, 385, 160, 322, 333, 379, 365, 365, 365, 365, + /* 1470 */ 348, 365, 333, 360, 20, 375, 365, 250, 432, 365, + /* 1480 */ 375, 432, 229, 230, 231, 232, 233, 234, 235, 236, + /* 1490 */ 237, 238, 239, 352, 373, 375, 256, 365, 365, 375, + /* 1500 */ 435, 360, 395, 365, 395, 167, 365, 258, 367, 257, + /* 1510 */ 245, 434, 265, 262, 445, 451, 260, 241, 20, 390, + /* 1520 */ 95, 360, 95, 342, 394, 356, 330, 333, 365, 388, + /* 1530 */ 322, 36, 325, 392, 324, 383, 346, 396, 397, 398, + /* 1540 */ 399, 400, 401, 402, 378, 404, 346, 432, 431, 430, + /* 1550 */ 409, 414, 411, 334, 429, 346, 415, 416, 320, 0, + /* 1560 */ 352, 0, 444, 183, 0, 0, 425, 42, 360, 35, + /* 1570 */ 195, 35, 35, 365, 0, 367, 35, 195, 0, 35, + /* 1580 */ 35, 195, 0, 195, 322, 0, 35, 0, 22, 0, + /* 1590 */ 35, 178, 176, 0, 0, 172, 388, 171, 0, 0, + /* 1600 */ 392, 0, 46, 0, 396, 397, 398, 399, 400, 401, + /* 1610 */ 402, 0, 404, 42, 352, 0, 0, 409, 0, 411, + /* 1620 */ 149, 42, 360, 415, 416, 0, 0, 365, 0, 367, + /* 1630 */ 0, 0, 35, 425, 0, 149, 0, 0, 322, 0, + /* 1640 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + /* 1650 */ 388, 0, 0, 0, 392, 42, 0, 0, 396, 397, + /* 1660 */ 398, 399, 400, 401, 402, 0, 404, 0, 352, 0, + /* 1670 */ 0, 409, 22, 411, 57, 0, 360, 415, 416, 0, + /* 1680 */ 0, 365, 0, 367, 57, 0, 0, 14, 0, 35, + /* 1690 */ 14, 322, 63, 167, 0, 0, 0, 42, 39, 0, + /* 1700 */ 0, 43, 40, 39, 388, 0, 46, 46, 392, 0, + /* 1710 */ 39, 0, 396, 397, 398, 399, 400, 401, 402, 35, + /* 1720 */ 404, 352, 39, 0, 47, 409, 35, 411, 47, 360, + /* 1730 */ 0, 415, 416, 0, 365, 0, 367, 39, 35, 35, + /* 1740 */ 47, 39, 0, 0, 322, 39, 0, 35, 47, 22, + /* 1750 */ 0, 35, 35, 22, 35, 35, 43, 388, 43, 35, + /* 1760 */ 35, 392, 22, 35, 0, 396, 397, 398, 399, 400, + /* 1770 */ 401, 402, 104, 404, 352, 22, 0, 22, 409, 0, + /* 1780 */ 411, 49, 360, 22, 415, 416, 35, 365, 0, 367, + /* 1790 */ 0, 102, 35, 35, 0, 22, 0, 20, 163, 0, + /* 1800 */ 35, 179, 22, 96, 0, 322, 0, 0, 3, 95, + /* 1810 */ 388, 0, 0, 95, 392, 0, 35, 96, 396, 397, + /* 1820 */ 398, 399, 400, 401, 402, 0, 404, 35, 165, 322, + /* 1830 */ 39, 95, 160, 411, 95, 352, 95, 415, 416, 105, + /* 1840 */ 43, 163, 246, 360, 46, 43, 159, 95, 365, 225, + /* 1850 */ 367, 43, 96, 163, 188, 95, 43, 225, 161, 352, + /* 1860 */ 227, 43, 96, 96, 95, 46, 96, 360, 96, 95, + /* 1870 */ 46, 388, 365, 95, 367, 392, 3, 95, 95, 396, + /* 1880 */ 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, + /* 1890 */ 43, 322, 35, 35, 35, 388, 96, 96, 35, 392, + /* 1900 */ 35, 35, 46, 396, 397, 398, 399, 400, 401, 402, + /* 1910 */ 96, 404, 96, 43, 46, 46, 2, 22, 411, 96, + /* 1920 */ 46, 352, 95, 416, 95, 46, 95, 201, 96, 360, + /* 1930 */ 96, 95, 95, 22, 365, 96, 367, 95, 35, 106, + /* 1940 */ 203, 96, 322, 35, 95, 35, 96, 95, 35, 96, + /* 1950 */ 95, 35, 35, 22, 246, 95, 246, 388, 96, 119, + /* 1960 */ 96, 392, 240, 119, 35, 396, 397, 398, 399, 400, + /* 1970 */ 401, 402, 352, 404, 22, 406, 43, 95, 95, 107, + /* 1980 */ 360, 95, 95, 63, 62, 365, 119, 367, 35, 35, + /* 1990 */ 119, 35, 35, 35, 35, 35, 322, 35, 35, 35, + /* 2000 */ 35, 69, 35, 22, 92, 35, 22, 35, 388, 43, + /* 2010 */ 35, 35, 392, 69, 322, 35, 396, 397, 398, 399, + /* 2020 */ 400, 401, 402, 35, 404, 35, 352, 35, 35, 22, + /* 2030 */ 35, 0, 35, 39, 360, 0, 47, 35, 47, 365, + /* 2040 */ 39, 367, 0, 35, 352, 47, 0, 35, 39, 39, + /* 2050 */ 47, 0, 360, 35, 35, 0, 22, 365, 438, 367, + /* 2060 */ 21, 452, 388, 22, 20, 22, 392, 452, 21, 452, + /* 2070 */ 396, 397, 398, 399, 400, 401, 402, 452, 404, 452, + /* 2080 */ 388, 452, 452, 452, 392, 452, 452, 452, 396, 397, + /* 2090 */ 398, 399, 400, 401, 402, 452, 404, 322, 452, 452, + /* 2100 */ 452, 452, 452, 452, 452, 452, 452, 452, 452, 452, + /* 2110 */ 452, 452, 452, 452, 440, 452, 452, 452, 452, 452, + /* 2120 */ 452, 452, 452, 452, 452, 452, 452, 352, 452, 452, + /* 2130 */ 452, 452, 357, 452, 452, 360, 452, 452, 452, 452, + /* 2140 */ 365, 449, 367, 452, 452, 452, 452, 452, 452, 452, + /* 2150 */ 452, 452, 322, 452, 452, 452, 452, 452, 452, 452, + /* 2160 */ 452, 452, 452, 388, 452, 452, 452, 392, 452, 452, + /* 2170 */ 452, 396, 397, 398, 399, 400, 401, 402, 452, 404, + /* 2180 */ 452, 452, 352, 452, 452, 452, 452, 357, 452, 452, + /* 2190 */ 360, 452, 452, 452, 452, 365, 452, 367, 452, 452, + /* 2200 */ 452, 452, 452, 322, 452, 452, 452, 452, 452, 452, + /* 2210 */ 452, 452, 452, 452, 452, 452, 452, 452, 388, 452, + /* 2220 */ 452, 452, 392, 452, 452, 452, 396, 397, 398, 399, + /* 2230 */ 400, 401, 402, 352, 404, 452, 452, 452, 452, 452, + /* 2240 */ 452, 360, 452, 452, 452, 452, 365, 452, 367, 452, + /* 2250 */ 452, 452, 452, 452, 452, 452, 452, 322, 452, 452, + /* 2260 */ 452, 452, 452, 452, 452, 452, 452, 452, 452, 388, + /* 2270 */ 452, 452, 452, 392, 452, 452, 452, 396, 397, 398, + /* 2280 */ 399, 400, 401, 402, 452, 404, 452, 352, 452, 452, + /* 2290 */ 452, 452, 452, 452, 452, 360, 452, 452, 452, 452, + /* 2300 */ 365, 452, 367, 452, 452, 452, 452, 452, 322, 452, + /* 2310 */ 452, 452, 452, 452, 452, 452, 452, 452, 452, 452, + /* 2320 */ 452, 452, 452, 388, 452, 452, 452, 392, 452, 452, + /* 2330 */ 452, 396, 397, 398, 399, 400, 401, 402, 352, 404, + /* 2340 */ 452, 452, 452, 452, 452, 452, 360, 452, 452, 452, + /* 2350 */ 452, 365, 452, 367, 452, 452, 452, 452, 452, 452, + /* 2360 */ 452, 452, 322, 452, 452, 452, 452, 452, 452, 452, + /* 2370 */ 452, 452, 452, 452, 388, 452, 452, 452, 392, 452, + /* 2380 */ 322, 452, 396, 397, 398, 399, 400, 401, 402, 452, + /* 2390 */ 404, 452, 352, 452, 452, 452, 452, 452, 452, 452, + /* 2400 */ 360, 452, 452, 452, 452, 365, 452, 367, 452, 452, + /* 2410 */ 352, 452, 452, 452, 452, 452, 452, 452, 360, 452, + /* 2420 */ 452, 452, 452, 365, 452, 367, 452, 452, 388, 452, + /* 2430 */ 452, 452, 392, 452, 452, 452, 396, 397, 398, 399, + /* 2440 */ 400, 401, 402, 452, 404, 452, 388, 452, 452, 452, + /* 2450 */ 392, 452, 452, 452, 396, 397, 398, 399, 400, 401, + /* 2460 */ 402, 452, 404, 322, 452, 452, 452, 452, 452, 452, + /* 2470 */ 452, 452, 452, 452, 452, 452, 452, 452, 452, 452, + /* 2480 */ 452, 452, 452, 452, 452, 452, 452, 452, 452, 452, + /* 2490 */ 452, 452, 452, 352, 452, 452, 452, 452, 452, 452, + /* 2500 */ 452, 360, 452, 452, 452, 452, 365, 452, 367, 452, + /* 2510 */ 452, 452, 452, 452, 452, 452, 452, 452, 322, 452, + /* 2520 */ 452, 452, 452, 452, 452, 452, 452, 452, 452, 388, + /* 2530 */ 452, 452, 452, 392, 452, 452, 452, 396, 397, 398, + /* 2540 */ 399, 400, 401, 402, 452, 404, 452, 452, 352, 452, + /* 2550 */ 452, 452, 452, 452, 452, 452, 360, 452, 452, 452, + /* 2560 */ 452, 365, 452, 367, 452, 452, 452, 452, 452, 322, + /* 2570 */ 452, 452, 452, 452, 452, 452, 452, 452, 452, 452, + /* 2580 */ 452, 452, 452, 452, 388, 452, 452, 452, 392, 452, + /* 2590 */ 452, 452, 396, 397, 398, 399, 400, 401, 402, 352, + /* 2600 */ 404, 452, 452, 452, 452, 452, 452, 360, 452, 452, + /* 2610 */ 452, 452, 365, 452, 367, 452, 452, 452, 452, 452, + /* 2620 */ 452, 452, 452, 322, 452, 452, 452, 452, 452, 452, + /* 2630 */ 452, 452, 452, 452, 452, 388, 452, 452, 452, 392, + /* 2640 */ 452, 452, 452, 396, 397, 398, 399, 400, 401, 402, + /* 2650 */ 452, 404, 452, 352, 452, 452, 452, 452, 452, 452, + /* 2660 */ 452, 360, 452, 452, 452, 452, 365, 452, 367, 452, + /* 2670 */ 452, 452, 452, 452, 322, 452, 452, 452, 452, 452, + /* 2680 */ 452, 452, 452, 452, 452, 452, 452, 452, 452, 388, + /* 2690 */ 452, 452, 452, 392, 452, 452, 452, 396, 397, 398, + /* 2700 */ 399, 400, 401, 402, 352, 404, 452, 452, 452, 452, + /* 2710 */ 452, 452, 360, 452, 452, 452, 452, 365, 452, 367, + /* 2720 */ 452, 452, 452, 452, 452, 452, 452, 452, 322, 452, + /* 2730 */ 452, 452, 452, 452, 452, 452, 452, 452, 452, 452, + /* 2740 */ 388, 452, 452, 452, 392, 452, 322, 452, 396, 397, + /* 2750 */ 398, 399, 400, 401, 402, 452, 404, 452, 352, 452, + /* 2760 */ 452, 452, 452, 452, 452, 452, 360, 452, 452, 452, + /* 2770 */ 452, 365, 452, 367, 452, 452, 352, 452, 452, 452, + /* 2780 */ 452, 452, 452, 452, 360, 452, 452, 452, 452, 365, + /* 2790 */ 452, 367, 452, 452, 388, 452, 452, 452, 392, 452, + /* 2800 */ 452, 452, 396, 397, 398, 399, 400, 401, 402, 452, + /* 2810 */ 404, 452, 388, 452, 452, 452, 392, 452, 452, 452, + /* 2820 */ 396, 397, 398, 399, 400, 401, 402, 452, 404, 322, + /* 2830 */ 452, 452, 452, 452, 452, 452, 452, 452, 452, 452, + /* 2840 */ 452, 452, 452, 452, 452, 452, 452, 452, 452, 452, + /* 2850 */ 452, 452, 452, 452, 452, 452, 452, 452, 452, 352, + /* 2860 */ 452, 452, 452, 452, 452, 452, 452, 360, 452, 452, + /* 2870 */ 452, 452, 365, 452, 367, 452, 452, 452, 452, 452, + /* 2880 */ 452, 452, 452, 452, 322, 452, 452, 452, 452, 452, + /* 2890 */ 452, 452, 452, 452, 452, 388, 452, 452, 452, 392, + /* 2900 */ 452, 452, 452, 396, 397, 398, 399, 400, 401, 402, + /* 2910 */ 452, 404, 452, 452, 352, 452, 452, 452, 452, 452, + /* 2920 */ 452, 452, 360, 452, 452, 452, 452, 365, 452, 367, + /* 2930 */ 452, 452, 452, 452, 452, 322, 452, 452, 452, 452, + /* 2940 */ 452, 452, 452, 452, 452, 452, 452, 452, 452, 452, + /* 2950 */ 388, 452, 452, 452, 392, 452, 452, 452, 396, 397, + /* 2960 */ 398, 399, 400, 401, 402, 352, 404, 452, 452, 452, + /* 2970 */ 452, 452, 452, 360, 452, 452, 452, 452, 365, 452, + /* 2980 */ 367, 452, 452, 452, 452, 452, 452, 452, 452, 322, + /* 2990 */ 452, 452, 452, 452, 452, 452, 452, 452, 452, 452, + /* 3000 */ 452, 388, 452, 452, 452, 392, 452, 452, 452, 396, + /* 3010 */ 397, 398, 399, 400, 401, 402, 452, 404, 452, 352, + /* 3020 */ 452, 452, 452, 452, 452, 452, 452, 360, 452, 452, + /* 3030 */ 452, 452, 365, 452, 367, 452, 452, 452, 452, 452, + /* 3040 */ 322, 452, 452, 452, 452, 452, 452, 452, 452, 452, + /* 3050 */ 452, 452, 452, 452, 452, 388, 452, 452, 452, 392, + /* 3060 */ 452, 452, 452, 396, 397, 398, 399, 400, 401, 402, + /* 3070 */ 352, 404, 452, 452, 452, 452, 452, 452, 360, 452, + /* 3080 */ 452, 452, 452, 365, 452, 367, 452, 452, 452, 452, + /* 3090 */ 452, 452, 452, 452, 322, 452, 452, 452, 452, 452, + /* 3100 */ 452, 452, 452, 452, 452, 452, 388, 452, 452, 452, + /* 3110 */ 392, 452, 322, 452, 396, 397, 398, 399, 400, 401, + /* 3120 */ 402, 452, 404, 452, 352, 452, 452, 452, 452, 452, + /* 3130 */ 452, 452, 360, 452, 452, 452, 452, 365, 452, 367, + /* 3140 */ 452, 452, 352, 452, 452, 452, 452, 452, 452, 452, + /* 3150 */ 360, 452, 452, 452, 452, 365, 452, 367, 452, 452, + /* 3160 */ 388, 452, 452, 452, 392, 452, 452, 452, 396, 397, + /* 3170 */ 398, 399, 400, 401, 402, 452, 404, 452, 388, 452, + /* 3180 */ 452, 452, 392, 452, 452, 452, 396, 397, 398, 399, + /* 3190 */ 400, 401, 402, 452, 404, 322, 452, 452, 452, 452, + /* 3200 */ 452, 452, 452, 452, 452, 452, 452, 452, 452, 452, + /* 3210 */ 452, 452, 452, 452, 452, 452, 452, 452, 452, 452, + /* 3220 */ 452, 452, 452, 452, 452, 352, 452, 452, 452, 452, + /* 3230 */ 452, 452, 452, 360, 452, 452, 452, 452, 365, 452, + /* 3240 */ 367, 452, 452, 452, 452, 452, 452, 452, 452, 452, + /* 3250 */ 322, 452, 452, 452, 452, 452, 452, 452, 452, 452, + /* 3260 */ 452, 388, 452, 452, 452, 392, 452, 452, 452, 396, + /* 3270 */ 397, 398, 399, 400, 401, 402, 452, 404, 452, 452, + /* 3280 */ 352, 452, 452, 452, 452, 452, 452, 452, 360, 452, + /* 3290 */ 452, 452, 452, 365, 452, 367, 452, 452, 452, 452, + /* 3300 */ 452, 452, 452, 452, 452, 452, 452, 452, 452, 452, + /* 3310 */ 452, 452, 452, 452, 452, 452, 388, 452, 452, 452, + /* 3320 */ 392, 452, 452, 452, 396, 397, 398, 399, 400, 401, + /* 3330 */ 402, 452, 404, }; -#define YY_SHIFT_COUNT (697) +#define YY_SHIFT_COUNT (700) #define YY_SHIFT_MIN (0) -#define YY_SHIFT_MAX (2108) +#define YY_SHIFT_MAX (2055) static const unsigned short int yy_shift_ofst[] = { - /* 0 */ 1135, 0, 57, 268, 57, 325, 325, 325, 536, 325, - /* 10 */ 325, 325, 325, 325, 593, 804, 804, 861, 804, 804, - /* 20 */ 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, - /* 30 */ 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, - /* 40 */ 804, 804, 804, 804, 804, 804, 8, 12, 324, 73, - /* 50 */ 520, 164, 286, 164, 324, 324, 1607, 1607, 164, 1607, - /* 60 */ 1607, 4, 164, 55, 55, 1, 1, 176, 55, 55, - /* 70 */ 55, 55, 55, 55, 55, 55, 55, 55, 138, 55, - /* 80 */ 55, 55, 109, 55, 55, 267, 55, 55, 267, 484, - /* 90 */ 55, 267, 267, 267, 55, 457, 1066, 1233, 1233, 375, - /* 100 */ 402, 380, 380, 380, 380, 380, 380, 380, 380, 380, - /* 110 */ 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, - /* 120 */ 736, 550, 176, 350, 350, 587, 429, 704, 396, 396, - /* 130 */ 742, 742, 742, 429, 573, 573, 573, 462, 109, 588, - /* 140 */ 588, 483, 267, 267, 534, 534, 462, 693, 399, 399, - /* 150 */ 399, 399, 399, 399, 399, 263, 501, 382, 717, 838, - /* 160 */ 42, 134, 190, 154, 217, 319, 421, 738, 825, 260, - /* 170 */ 126, 859, 260, 569, 659, 698, 1057, 1261, 1137, 1284, - /* 180 */ 1284, 1181, 1320, 1320, 1284, 1181, 1181, 1285, 1320, 1320, - /* 190 */ 1320, 1361, 1361, 1364, 138, 109, 138, 1371, 1372, 138, - /* 200 */ 1371, 138, 138, 138, 1320, 138, 1361, 267, 267, 267, - /* 210 */ 267, 267, 267, 267, 267, 267, 267, 267, 1320, 1361, - /* 220 */ 534, 1231, 1364, 457, 1263, 109, 457, 1320, 1320, 1371, - /* 230 */ 457, 1208, 534, 534, 534, 534, 1208, 534, 1298, 457, - /* 240 */ 462, 457, 573, 1461, 1461, 534, 1239, 1208, 534, 534, - /* 250 */ 1239, 1208, 534, 534, 267, 1235, 1332, 1239, 1243, 1245, - /* 260 */ 1262, 1057, 1244, 1248, 1252, 1275, 573, 1497, 1424, 1432, - /* 270 */ 534, 693, 1320, 457, 1507, 1361, 2819, 2819, 2819, 2819, - /* 280 */ 2819, 2819, 2819, 1062, 996, 759, 70, 1019, 1154, 1090, - /* 290 */ 50, 1242, 1277, 226, 582, 582, 582, 582, 582, 582, - /* 300 */ 582, 582, 582, 982, 262, 11, 11, 53, 160, 63, - /* 310 */ 227, 327, 669, 378, 479, 726, 348, 479, 479, 479, - /* 320 */ 837, 734, 361, 884, 818, 943, 956, 993, 1023, 940, - /* 330 */ 1097, 1174, 1034, 790, 1132, 1136, 1138, 1139, 1143, 1145, - /* 340 */ 1148, 909, 787, 926, 1054, 1158, 1085, 1240, 1117, 1185, - /* 350 */ 305, 1219, 1253, 1254, 1266, 1269, 1274, 1279, 879, 1302, - /* 360 */ 1310, 1195, 1236, 1558, 1560, 1379, 1562, 1563, 1524, 1567, - /* 370 */ 1533, 1376, 1535, 1536, 1538, 1381, 1575, 1541, 1545, 1388, - /* 380 */ 1583, 1391, 1585, 1561, 1595, 1576, 1597, 1568, 1425, 1442, - /* 390 */ 1618, 1624, 1436, 1455, 1626, 1631, 1586, 1633, 1634, 1638, - /* 400 */ 1594, 1639, 1641, 1643, 1603, 1646, 1647, 1648, 1649, 1650, - /* 410 */ 1503, 1619, 1653, 1508, 1655, 1660, 1661, 1664, 1665, 1673, - /* 420 */ 1676, 1677, 1678, 1682, 1683, 1695, 1697, 1698, 1699, 1645, - /* 430 */ 1700, 1701, 1702, 1704, 1705, 1684, 1709, 1710, 1711, 1712, - /* 440 */ 1679, 1713, 1659, 1716, 1662, 1717, 1719, 1685, 1681, 1686, - /* 450 */ 1707, 1680, 1714, 1688, 1724, 1690, 1692, 1725, 1732, 1733, - /* 460 */ 1696, 1570, 1737, 1738, 1739, 1691, 1740, 1741, 1708, 1703, - /* 470 */ 1706, 1742, 1720, 1715, 1718, 1744, 1721, 1722, 1726, 1746, - /* 480 */ 1723, 1727, 1728, 1747, 1748, 1749, 1752, 1651, 1667, 1735, - /* 490 */ 1750, 1760, 1736, 1743, 1751, 1745, 1753, 1734, 1759, 1754, - /* 500 */ 1757, 1761, 1758, 1763, 1764, 1775, 1772, 1730, 1776, 1783, - /* 510 */ 1769, 1781, 1773, 1811, 1777, 1813, 1794, 1765, 1666, 1755, - /* 520 */ 1817, 1656, 1793, 1829, 1652, 1809, 1671, 1689, 1835, 1836, - /* 530 */ 1675, 1693, 1837, 1839, 1841, 1842, 1756, 1766, 1808, 1657, - /* 540 */ 1845, 1762, 1694, 1768, 1852, 1819, 1731, 1786, 1771, 1801, - /* 550 */ 1834, 1637, 1654, 1658, 1848, 1663, 1798, 1799, 1802, 1800, - /* 560 */ 1803, 1805, 1857, 1806, 1810, 1812, 1814, 1815, 1860, 1863, - /* 570 */ 1865, 1818, 1872, 1670, 1821, 1822, 1916, 1878, 1774, 1888, - /* 580 */ 1889, 1890, 1891, 1892, 1893, 1838, 1843, 1883, 1778, 1896, - /* 590 */ 1885, 1886, 1932, 1918, 1780, 1849, 1851, 1850, 1853, 1866, - /* 600 */ 1868, 1901, 1867, 1870, 1929, 1881, 1920, 1782, 1887, 1877, - /* 610 */ 1882, 1949, 1951, 1894, 1897, 1952, 1895, 1899, 1956, 1902, - /* 620 */ 1900, 1962, 1905, 1907, 1968, 1910, 1904, 1906, 1908, 1909, - /* 630 */ 1984, 1913, 1926, 1934, 1988, 1944, 1996, 1996, 2018, 1980, - /* 640 */ 1982, 2010, 2011, 2012, 2013, 2015, 2017, 2019, 2020, 2021, - /* 650 */ 2022, 1990, 1969, 2016, 2026, 2027, 2041, 2029, 2043, 2031, - /* 660 */ 2032, 2033, 2001, 1734, 2035, 1759, 2036, 2038, 2039, 2040, - /* 670 */ 2055, 2044, 2078, 2056, 2042, 2051, 2092, 2058, 2047, 2057, - /* 680 */ 2095, 2062, 2052, 2059, 2100, 2066, 2060, 2063, 2103, 2069, - /* 690 */ 2071, 2108, 2087, 2089, 2090, 2091, 2093, 2097, + /* 0 */ 1148, 0, 58, 271, 58, 329, 329, 329, 542, 329, + /* 10 */ 329, 329, 329, 329, 600, 813, 813, 871, 813, 813, + /* 20 */ 813, 813, 813, 813, 813, 813, 813, 813, 813, 813, + /* 30 */ 813, 813, 813, 813, 813, 813, 813, 813, 813, 813, + /* 40 */ 813, 813, 813, 813, 813, 813, 279, 434, 8, 266, + /* 50 */ 261, 19, 43, 19, 8, 8, 658, 658, 19, 658, + /* 60 */ 658, 332, 19, 16, 16, 14, 14, 435, 16, 16, + /* 70 */ 16, 16, 16, 16, 16, 16, 16, 16, 20, 16, + /* 80 */ 16, 16, 41, 16, 16, 207, 16, 16, 207, 213, + /* 90 */ 16, 207, 207, 207, 16, 229, 1078, 1253, 1253, 367, + /* 100 */ 222, 653, 653, 653, 653, 653, 653, 653, 653, 653, + /* 110 */ 653, 653, 653, 653, 653, 653, 653, 653, 653, 653, + /* 120 */ 128, 553, 435, 137, 137, 126, 366, 296, 99, 99, + /* 130 */ 267, 267, 267, 366, 364, 364, 364, 27, 41, 10, + /* 140 */ 10, 178, 207, 207, 354, 354, 27, 379, 199, 199, + /* 150 */ 199, 199, 199, 199, 199, 340, 896, 21, 74, 450, + /* 160 */ 164, 350, 407, 323, 422, 578, 821, 720, 963, 685, + /* 170 */ 330, 718, 685, 1009, 395, 841, 1041, 1257, 1135, 1280, + /* 180 */ 1280, 1177, 1318, 1318, 1280, 1177, 1177, 1263, 1318, 1318, + /* 190 */ 1318, 1339, 1339, 1354, 20, 41, 20, 1358, 1362, 20, + /* 200 */ 1358, 20, 20, 20, 1318, 20, 1357, 1357, 1339, 207, + /* 210 */ 207, 207, 207, 207, 207, 207, 207, 207, 207, 207, + /* 220 */ 1318, 1339, 354, 1246, 1354, 229, 1272, 41, 229, 1318, + /* 230 */ 1318, 1358, 229, 1211, 354, 354, 354, 354, 1211, 354, + /* 240 */ 1302, 229, 27, 229, 364, 1454, 1454, 354, 1227, 1211, + /* 250 */ 354, 354, 1227, 1211, 354, 354, 207, 1240, 1338, 1227, + /* 260 */ 1249, 1252, 1265, 1041, 1247, 1251, 1256, 1276, 364, 1498, + /* 270 */ 1425, 1427, 354, 379, 1318, 229, 1495, 1339, 3333, 3333, + /* 280 */ 3333, 3333, 3333, 3333, 3333, 1074, 951, 382, 1267, 576, + /* 290 */ 669, 632, 692, 721, 779, 453, 1054, 1054, 1054, 1054, + /* 300 */ 1054, 1054, 1054, 1054, 1054, 993, 670, 105, 113, 767, + /* 310 */ 767, 197, 201, 120, 598, 513, 757, 766, 457, 757, + /* 320 */ 757, 757, 760, 345, 704, 801, 1097, 1010, 1016, 1030, + /* 330 */ 1035, 919, 949, 1187, 466, 940, 920, 969, 1073, 1085, + /* 340 */ 1092, 1136, 1155, 1044, 952, 794, 1176, 1158, 1145, 1201, + /* 350 */ 1112, 1160, 1179, 1192, 1162, 1167, 1168, 1202, 1206, 1254, + /* 360 */ 1178, 1299, 1317, 1260, 1193, 1559, 1561, 1380, 1564, 1565, + /* 370 */ 1525, 1574, 1534, 1375, 1536, 1537, 1541, 1382, 1578, 1544, + /* 380 */ 1545, 1386, 1582, 1388, 1585, 1551, 1587, 1566, 1589, 1555, + /* 390 */ 1413, 1416, 1593, 1594, 1423, 1426, 1598, 1599, 1556, 1601, + /* 400 */ 1603, 1611, 1571, 1615, 1616, 1618, 1579, 1625, 1626, 1628, + /* 410 */ 1630, 1631, 1471, 1597, 1634, 1486, 1636, 1637, 1639, 1640, + /* 420 */ 1641, 1642, 1643, 1644, 1645, 1646, 1647, 1648, 1649, 1651, + /* 430 */ 1652, 1613, 1653, 1656, 1657, 1665, 1667, 1650, 1669, 1670, + /* 440 */ 1679, 1680, 1654, 1682, 1617, 1675, 1627, 1685, 1686, 1655, + /* 450 */ 1659, 1658, 1673, 1660, 1676, 1661, 1688, 1662, 1664, 1699, + /* 460 */ 1700, 1705, 1671, 1526, 1694, 1695, 1696, 1629, 1709, 1711, + /* 470 */ 1684, 1677, 1683, 1723, 1691, 1681, 1698, 1730, 1703, 1693, + /* 480 */ 1702, 1733, 1704, 1701, 1706, 1735, 1742, 1743, 1746, 1668, + /* 490 */ 1689, 1712, 1727, 1750, 1716, 1717, 1731, 1719, 1720, 1713, + /* 500 */ 1715, 1724, 1725, 1740, 1728, 1764, 1753, 1776, 1755, 1732, + /* 510 */ 1779, 1761, 1751, 1788, 1757, 1790, 1758, 1794, 1773, 1777, + /* 520 */ 1707, 1714, 1796, 1635, 1765, 1799, 1622, 1780, 1678, 1672, + /* 530 */ 1804, 1806, 1690, 1663, 1805, 1807, 1811, 1812, 1718, 1721, + /* 540 */ 1781, 1792, 1666, 1815, 1736, 1697, 1739, 1825, 1791, 1687, + /* 550 */ 1741, 1734, 1798, 1797, 1624, 1633, 1632, 1802, 1596, 1752, + /* 560 */ 1756, 1760, 1766, 1767, 1769, 1808, 1770, 1774, 1778, 1782, + /* 570 */ 1772, 1813, 1819, 1824, 1783, 1818, 1708, 1800, 1801, 1873, + /* 580 */ 1847, 1710, 1857, 1858, 1859, 1863, 1865, 1866, 1814, 1816, + /* 590 */ 1856, 1722, 1870, 1868, 1869, 1914, 1895, 1726, 1827, 1823, + /* 600 */ 1829, 1832, 1831, 1834, 1874, 1836, 1837, 1879, 1839, 1911, + /* 610 */ 1737, 1842, 1833, 1845, 1903, 1908, 1849, 1850, 1910, 1852, + /* 620 */ 1853, 1913, 1855, 1862, 1916, 1860, 1864, 1917, 1882, 1840, + /* 630 */ 1844, 1867, 1871, 1931, 1872, 1883, 1886, 1929, 1887, 1933, + /* 640 */ 1933, 1952, 1920, 1922, 1953, 1954, 1956, 1957, 1958, 1959, + /* 650 */ 1960, 1962, 1963, 1964, 1932, 1912, 1966, 1965, 1967, 1981, + /* 660 */ 1970, 1984, 1972, 1975, 1976, 1944, 1713, 1980, 1715, 1988, + /* 670 */ 1990, 1992, 1993, 2007, 1995, 2031, 1997, 1989, 1994, 2035, + /* 680 */ 2002, 1991, 2001, 2042, 2008, 1998, 2009, 2046, 2012, 2003, + /* 690 */ 2010, 2051, 2018, 2019, 2055, 2034, 2039, 2041, 2043, 2047, + /* 700 */ 2044, }; -#define YY_REDUCE_COUNT (282) -#define YY_REDUCE_MIN (-408) -#define YY_REDUCE_MAX (2417) +#define YY_REDUCE_COUNT (284) +#define YY_REDUCE_MIN (-358) +#define YY_REDUCE_MAX (2928) static const short yy_reduce_ofst[] = { - /* 0 */ -286, -253, -313, 875, 1008, 280, 548, 1126, -22, 1193, - /* 10 */ 1215, 1273, 1295, 1402, 1470, 261, 529, 1489, 957, 1556, - /* 20 */ 1573, 1616, 601, 1636, 1687, 1767, 1785, 1828, 1847, 1871, - /* 30 */ 1914, 1931, 1957, 1974, 2037, 2054, 2117, 2143, 2197, 2214, - /* 40 */ 2257, 2277, 2320, 2337, 2400, 2417, -193, 278, -223, -139, - /* 50 */ 276, 446, 464, 924, 1016, 1032, -351, -348, -316, -341, - /* 60 */ -40, -261, 241, -26, 38, -309, -177, -30, -31, 97, - /* 70 */ 246, 281, 291, 311, 343, 491, 531, 535, -245, 542, - /* 80 */ 591, 611, -355, 631, 636, -169, 644, 702, 104, 203, - /* 90 */ 895, 210, 252, 283, 938, 513, -190, -408, -408, -304, - /* 100 */ -315, -265, -247, -201, -181, 129, 320, 458, 514, 547, - /* 110 */ 595, 616, 618, 725, 733, 798, 802, 803, 836, 864, - /* 120 */ -318, 163, -135, -271, 69, -43, -93, 442, 284, 301, - /* 130 */ 163, 436, 437, 362, 193, 406, 409, -17, -250, 392, - /* 140 */ 407, 229, 101, 345, 463, 470, 571, 432, 425, 511, - /* 150 */ 527, 545, 556, 561, 617, 398, 647, 737, 709, 638, - /* 160 */ 676, 851, 753, 840, 840, 871, 863, 858, 833, 877, - /* 170 */ 877, 819, 877, 847, 876, 840, 918, 934, 946, 965, - /* 180 */ 966, 972, 1013, 1015, 990, 999, 1004, 1042, 1050, 1051, - /* 190 */ 1052, 1060, 1061, 1002, 1055, 1022, 1056, 1018, 1017, 1064, - /* 200 */ 1024, 1067, 1076, 1079, 1070, 1080, 1091, 1069, 1073, 1074, - /* 210 */ 1075, 1078, 1081, 1082, 1086, 1088, 1089, 1093, 1087, 1103, - /* 220 */ 1083, 1044, 1046, 1110, 1065, 1092, 1114, 1123, 1125, 1095, - /* 230 */ 1124, 1100, 1096, 1111, 1112, 1115, 1104, 1116, 1109, 1129, - /* 240 */ 1140, 1150, 1127, 1094, 1099, 1120, 1063, 1121, 1133, 1134, - /* 250 */ 1068, 1122, 1141, 1142, 840, 1077, 1071, 1072, 1084, 1101, - /* 260 */ 1105, 1119, 1098, 1102, 1106, 877, 1159, 1146, 1118, 1177, - /* 270 */ 1171, 1197, 1212, 1211, 1222, 1227, 1172, 1176, 1210, 1213, - /* 280 */ 1216, 1223, 1247, + /* 0 */ -94, -292, 892, -230, 1003, 1029, 1141, 1208, -21, 1262, + /* 10 */ 1316, 1369, 535, 1422, 1483, 205, -204, 1507, 264, 1569, + /* 20 */ 1620, 1674, 1692, 1775, 1830, 1881, 1935, 1986, 2040, 2058, + /* 30 */ 2141, 2196, 2247, 2301, 2352, 2406, 2424, 2507, 2562, 2613, + /* 40 */ 2667, 2718, 2772, 2790, 2873, 2928, 946, 70, -276, 72, + /* 50 */ 471, 512, 612, 614, 771, 776, -328, -252, 885, -348, + /* 60 */ -325, -92, 343, -319, -214, -326, -321, -37, -305, -232, + /* 70 */ 265, 293, 349, 359, 381, 498, 509, 520, -176, 551, + /* 80 */ 555, 556, -358, 622, 840, -329, 910, 912, 147, -169, + /* 90 */ 917, 217, 258, 306, 627, 177, -205, 88, 88, -302, + /* 100 */ -224, -162, 106, 523, 525, 545, 549, 583, 599, 602, + /* 110 */ 607, 621, 625, 634, 674, 678, 679, 742, 749, 802, + /* 120 */ -350, -59, 159, -253, -89, -331, 220, 5, 186, 430, + /* 130 */ -59, 303, 316, 504, 97, 216, 493, 342, 336, 454, + /* 140 */ 544, 335, 689, -267, 613, 648, 754, 561, 121, 151, + /* 150 */ 156, 277, 298, 421, 433, 460, 531, 566, 581, 547, + /* 160 */ 603, 650, 710, 850, 850, 873, 908, 875, 853, 826, + /* 170 */ 826, 831, 826, 861, 852, 850, 909, 916, 928, 961, + /* 180 */ 964, 967, 1011, 1019, 968, 983, 984, 1021, 1032, 1043, + /* 190 */ 1045, 1036, 1047, 990, 1042, 1013, 1048, 1005, 1004, 1051, + /* 200 */ 1018, 1063, 1071, 1075, 1079, 1080, 1081, 1084, 1096, 1070, + /* 210 */ 1072, 1082, 1083, 1089, 1090, 1091, 1094, 1095, 1098, 1099, + /* 220 */ 1093, 1108, 1087, 1050, 1062, 1116, 1076, 1088, 1123, 1127, + /* 230 */ 1128, 1086, 1126, 1100, 1101, 1102, 1103, 1104, 1105, 1106, + /* 240 */ 1121, 1131, 1122, 1139, 1113, 1107, 1109, 1111, 1046, 1120, + /* 250 */ 1114, 1132, 1049, 1124, 1133, 1138, 850, 1065, 1077, 1115, + /* 260 */ 1117, 1119, 1125, 1129, 1064, 1069, 1118, 826, 1161, 1130, + /* 270 */ 1137, 1169, 1163, 1181, 1196, 1194, 1207, 1210, 1152, 1166, + /* 280 */ 1190, 1200, 1209, 1219, 1238, }; static const YYACTIONTYPE yy_default[] = { - /* 0 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 10 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 20 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 30 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 40 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 50 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 60 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 70 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1630, 1556, - /* 80 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 90 */ 1556, 1556, 1556, 1556, 1556, 1628, 1800, 1988, 1556, 1556, - /* 100 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 110 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 120 */ 1556, 2000, 1556, 1556, 1556, 1630, 1556, 1628, 1960, 1960, - /* 130 */ 2000, 2000, 2000, 1556, 1556, 1556, 1556, 1739, 1556, 1841, - /* 140 */ 1841, 1556, 1556, 1556, 1556, 1556, 1739, 1556, 1556, 1556, - /* 150 */ 1556, 1556, 1556, 1556, 1556, 1835, 1556, 1556, 2025, 2078, - /* 160 */ 1556, 1556, 2028, 1556, 1556, 1556, 1556, 1692, 2015, 1992, - /* 170 */ 2006, 2062, 1993, 1990, 2009, 1556, 2019, 1556, 1828, 1805, - /* 180 */ 1805, 1802, 1556, 1556, 1805, 1802, 1802, 1683, 1556, 1556, - /* 190 */ 1556, 1556, 1556, 1556, 1630, 1556, 1630, 1556, 1556, 1630, - /* 200 */ 1556, 1630, 1630, 1630, 1556, 1630, 1556, 1556, 1556, 1556, - /* 210 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 220 */ 1556, 1847, 1556, 1628, 1837, 1556, 1628, 1556, 1556, 1556, - /* 230 */ 1628, 2033, 1556, 1556, 1556, 1556, 2033, 1556, 1556, 1628, - /* 240 */ 1556, 1628, 1556, 1556, 1556, 1556, 2035, 2033, 1556, 1556, - /* 250 */ 2035, 2033, 1556, 1556, 1556, 2047, 2043, 2035, 2051, 2049, - /* 260 */ 2021, 2019, 2081, 2068, 2064, 2006, 1556, 1556, 1556, 1708, - /* 270 */ 1556, 1556, 1556, 1628, 1588, 1556, 1830, 1841, 1742, 1742, - /* 280 */ 1742, 1631, 1561, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 290 */ 1556, 1556, 1556, 1556, 1916, 1556, 2046, 2045, 1964, 1963, - /* 300 */ 1962, 1953, 1915, 1556, 1704, 1914, 1913, 1556, 1556, 1556, - /* 310 */ 1556, 1556, 1556, 1556, 1907, 1556, 1556, 1908, 1906, 1905, - /* 320 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 330 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 340 */ 1556, 1556, 2065, 2069, 1989, 1556, 1556, 1556, 1556, 1556, - /* 350 */ 1898, 1889, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 360 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 370 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 380 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 390 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 400 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 410 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 420 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 430 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 440 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1593, - /* 450 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 460 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 470 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 480 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 490 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1670, 1669, 1556, - /* 500 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 510 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1897, 1556, - /* 520 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 530 */ 1556, 1556, 2061, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 540 */ 1845, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 550 */ 1950, 1556, 1556, 1556, 2022, 1556, 1556, 1556, 1556, 1556, - /* 560 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 570 */ 1889, 1556, 2044, 1556, 1556, 2059, 1556, 2063, 1556, 1556, - /* 580 */ 1556, 1556, 1556, 1556, 1556, 1999, 1995, 1556, 1556, 1991, - /* 590 */ 1888, 1556, 1984, 1556, 1556, 1935, 1556, 1556, 1556, 1556, - /* 600 */ 1556, 1556, 1556, 1556, 1556, 1897, 1556, 1901, 1556, 1556, - /* 610 */ 1556, 1556, 1556, 1736, 1556, 1556, 1556, 1556, 1556, 1556, - /* 620 */ 1556, 1556, 1556, 1556, 1556, 1556, 1721, 1719, 1718, 1717, - /* 630 */ 1556, 1714, 1556, 1556, 1556, 1556, 1745, 1744, 1556, 1556, - /* 640 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 650 */ 1556, 1556, 1556, 1650, 1556, 1556, 1556, 1556, 1556, 1556, - /* 660 */ 1556, 1556, 1556, 1641, 1556, 1640, 1556, 1556, 1556, 1556, - /* 670 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 680 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, - /* 690 */ 1556, 1556, 1556, 1556, 1556, 1556, 1556, 1556, + /* 0 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 10 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 20 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 30 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 40 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 50 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 60 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 70 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1640, 1564, + /* 80 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 90 */ 1564, 1564, 1564, 1564, 1564, 1638, 1810, 1999, 1564, 1564, + /* 100 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 110 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 120 */ 1564, 2011, 1564, 1564, 1564, 1640, 1564, 1638, 1971, 1971, + /* 130 */ 2011, 2011, 2011, 1564, 1564, 1564, 1564, 1749, 1564, 1851, + /* 140 */ 1851, 1564, 1564, 1564, 1564, 1564, 1749, 1564, 1564, 1564, + /* 150 */ 1564, 1564, 1564, 1564, 1564, 1845, 1564, 1564, 2036, 2089, + /* 160 */ 1564, 1564, 2039, 1564, 1564, 1564, 1564, 1702, 2026, 2003, + /* 170 */ 2017, 2073, 2004, 2001, 2020, 1564, 2030, 1564, 1838, 1815, + /* 180 */ 1815, 1812, 1564, 1564, 1815, 1812, 1812, 1693, 1564, 1564, + /* 190 */ 1564, 1564, 1564, 1564, 1640, 1564, 1640, 1564, 1564, 1640, + /* 200 */ 1564, 1640, 1640, 1640, 1564, 1640, 1619, 1619, 1564, 1564, + /* 210 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 220 */ 1564, 1564, 1564, 1858, 1564, 1638, 1847, 1564, 1638, 1564, + /* 230 */ 1564, 1564, 1638, 2044, 1564, 1564, 1564, 1564, 2044, 1564, + /* 240 */ 1564, 1638, 1564, 1638, 1564, 1564, 1564, 1564, 2046, 2044, + /* 250 */ 1564, 1564, 2046, 2044, 1564, 1564, 1564, 2058, 2054, 2046, + /* 260 */ 2062, 2060, 2032, 2030, 2092, 2079, 2075, 2017, 1564, 1564, + /* 270 */ 1564, 1718, 1564, 1564, 1564, 1638, 1596, 1564, 1840, 1851, + /* 280 */ 1752, 1752, 1752, 1641, 1569, 1564, 1564, 1564, 1564, 1564, + /* 290 */ 1564, 1564, 1564, 1564, 1564, 1564, 1927, 1564, 2057, 2056, + /* 300 */ 1975, 1974, 1973, 1964, 1926, 1564, 1714, 1564, 1564, 1925, + /* 310 */ 1924, 1564, 1564, 1564, 1564, 1564, 1918, 1564, 1564, 1919, + /* 320 */ 1917, 1916, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 330 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 340 */ 1564, 1564, 1564, 1564, 2076, 2080, 2000, 1564, 1564, 1564, + /* 350 */ 1564, 1564, 1909, 1900, 1564, 1564, 1564, 1564, 1564, 1564, + /* 360 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 370 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 380 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 390 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 400 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 410 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 420 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 430 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 440 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 450 */ 1564, 1601, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 460 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 470 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 480 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 490 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1680, + /* 500 */ 1679, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 510 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 520 */ 1908, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 530 */ 1564, 1564, 1564, 1564, 2072, 1564, 1564, 1564, 1564, 1564, + /* 540 */ 1564, 1564, 1564, 1855, 1564, 1564, 1564, 1564, 1564, 1564, + /* 550 */ 1564, 1564, 1564, 1961, 1564, 1564, 1564, 2033, 1564, 1564, + /* 560 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 570 */ 1564, 1564, 1564, 1900, 1564, 2055, 1564, 1564, 2070, 1564, + /* 580 */ 2074, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 2010, 2006, + /* 590 */ 1564, 1564, 2002, 1899, 1564, 1995, 1564, 1564, 1946, 1564, + /* 600 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1908, 1564, + /* 610 */ 1912, 1564, 1564, 1564, 1564, 1564, 1746, 1564, 1564, 1564, + /* 620 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1731, + /* 630 */ 1729, 1728, 1727, 1564, 1724, 1564, 1564, 1564, 1564, 1755, + /* 640 */ 1754, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 650 */ 1564, 1564, 1564, 1564, 1564, 1564, 1660, 1564, 1564, 1564, + /* 660 */ 1564, 1564, 1564, 1564, 1564, 1564, 1651, 1564, 1650, 1564, + /* 670 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 680 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 690 */ 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, 1564, + /* 700 */ 1564, }; /********** End of lemon-generated parsing tables *****************************/ @@ -1035,6 +1141,7 @@ static const YYCODETYPE yyFallback[] = { 0, /* PORT => nothing */ 0, /* DNODES => nothing */ 0, /* NK_IPTOKEN => nothing */ + 0, /* FORCE => nothing */ 0, /* LOCAL => nothing */ 0, /* QNODE => nothing */ 0, /* BNODE => nothing */ @@ -1172,6 +1279,7 @@ static const YYCODETYPE yyFallback[] = { 0, /* WINDOW_CLOSE => nothing */ 0, /* IGNORE => nothing */ 0, /* EXPIRED => nothing */ + 0, /* FILL_HISTORY => nothing */ 0, /* SUBTABLE => nothing */ 0, /* KILL => nothing */ 0, /* CONNECTION => nothing */ @@ -1207,7 +1315,7 @@ static const YYCODETYPE yyFallback[] = { 0, /* COUNT => nothing */ 0, /* LAST_ROW => nothing */ 0, /* CASE => nothing */ - 264, /* END => ABORT */ + 266, /* END => ABORT */ 0, /* WHEN => nothing */ 0, /* THEN => nothing */ 0, /* ELSE => nothing */ @@ -1249,58 +1357,58 @@ static const YYCODETYPE yyFallback[] = { 0, /* ASC => nothing */ 0, /* NULLS => nothing */ 0, /* ABORT => nothing */ - 264, /* AFTER => ABORT */ - 264, /* ATTACH => ABORT */ - 264, /* BEFORE => ABORT */ - 264, /* BEGIN => ABORT */ - 264, /* BITAND => ABORT */ - 264, /* BITNOT => ABORT */ - 264, /* BITOR => ABORT */ - 264, /* BLOCKS => ABORT */ - 264, /* CHANGE => ABORT */ - 264, /* COMMA => ABORT */ - 264, /* COMPACT => ABORT */ - 264, /* CONCAT => ABORT */ - 264, /* CONFLICT => ABORT */ - 264, /* COPY => ABORT */ - 264, /* DEFERRED => ABORT */ - 264, /* DELIMITERS => ABORT */ - 264, /* DETACH => ABORT */ - 264, /* DIVIDE => ABORT */ - 264, /* DOT => ABORT */ - 264, /* EACH => ABORT */ - 264, /* FAIL => ABORT */ - 264, /* FILE => ABORT */ - 264, /* FOR => ABORT */ - 264, /* GLOB => ABORT */ - 264, /* ID => ABORT */ - 264, /* IMMEDIATE => ABORT */ - 264, /* IMPORT => ABORT */ - 264, /* INITIALLY => ABORT */ - 264, /* INSTEAD => ABORT */ - 264, /* ISNULL => ABORT */ - 264, /* KEY => ABORT */ - 264, /* MODULES => ABORT */ - 264, /* NK_BITNOT => ABORT */ - 264, /* NK_SEMI => ABORT */ - 264, /* NOTNULL => ABORT */ - 264, /* OF => ABORT */ - 264, /* PLUS => ABORT */ - 264, /* PRIVILEGE => ABORT */ - 264, /* RAISE => ABORT */ - 264, /* REPLACE => ABORT */ - 264, /* RESTRICT => ABORT */ - 264, /* ROW => ABORT */ - 264, /* SEMI => ABORT */ - 264, /* STAR => ABORT */ - 264, /* STATEMENT => ABORT */ - 264, /* STRING => ABORT */ - 264, /* TIMES => ABORT */ - 264, /* UPDATE => ABORT */ - 264, /* VALUES => ABORT */ - 264, /* VARIABLE => ABORT */ - 264, /* VIEW => ABORT */ - 264, /* WAL => ABORT */ + 266, /* AFTER => ABORT */ + 266, /* ATTACH => ABORT */ + 266, /* BEFORE => ABORT */ + 266, /* BEGIN => ABORT */ + 266, /* BITAND => ABORT */ + 266, /* BITNOT => ABORT */ + 266, /* BITOR => ABORT */ + 266, /* BLOCKS => ABORT */ + 266, /* CHANGE => ABORT */ + 266, /* COMMA => ABORT */ + 266, /* COMPACT => ABORT */ + 266, /* CONCAT => ABORT */ + 266, /* CONFLICT => ABORT */ + 266, /* COPY => ABORT */ + 266, /* DEFERRED => ABORT */ + 266, /* DELIMITERS => ABORT */ + 266, /* DETACH => ABORT */ + 266, /* DIVIDE => ABORT */ + 266, /* DOT => ABORT */ + 266, /* EACH => ABORT */ + 266, /* FAIL => ABORT */ + 266, /* FILE => ABORT */ + 266, /* FOR => ABORT */ + 266, /* GLOB => ABORT */ + 266, /* ID => ABORT */ + 266, /* IMMEDIATE => ABORT */ + 266, /* IMPORT => ABORT */ + 266, /* INITIALLY => ABORT */ + 266, /* INSTEAD => ABORT */ + 266, /* ISNULL => ABORT */ + 266, /* KEY => ABORT */ + 266, /* MODULES => ABORT */ + 266, /* NK_BITNOT => ABORT */ + 266, /* NK_SEMI => ABORT */ + 266, /* NOTNULL => ABORT */ + 266, /* OF => ABORT */ + 266, /* PLUS => ABORT */ + 266, /* PRIVILEGE => ABORT */ + 266, /* RAISE => ABORT */ + 266, /* REPLACE => ABORT */ + 266, /* RESTRICT => ABORT */ + 266, /* ROW => ABORT */ + 266, /* SEMI => ABORT */ + 266, /* STAR => ABORT */ + 266, /* STATEMENT => ABORT */ + 266, /* STRING => ABORT */ + 266, /* TIMES => ABORT */ + 266, /* UPDATE => ABORT */ + 266, /* VALUES => ABORT */ + 266, /* VARIABLE => ABORT */ + 266, /* VIEW => ABORT */ + 266, /* WAL => ABORT */ }; #endif /* YYFALLBACK */ @@ -1439,404 +1547,407 @@ static const char *const yyTokenName[] = { /* 48 */ "PORT", /* 49 */ "DNODES", /* 50 */ "NK_IPTOKEN", - /* 51 */ "LOCAL", - /* 52 */ "QNODE", - /* 53 */ "BNODE", - /* 54 */ "SNODE", - /* 55 */ "MNODE", - /* 56 */ "DATABASE", - /* 57 */ "USE", - /* 58 */ "FLUSH", - /* 59 */ "TRIM", - /* 60 */ "IF", - /* 61 */ "NOT", - /* 62 */ "EXISTS", - /* 63 */ "BUFFER", - /* 64 */ "CACHEMODEL", - /* 65 */ "CACHESIZE", - /* 66 */ "COMP", - /* 67 */ "DURATION", - /* 68 */ "NK_VARIABLE", - /* 69 */ "MAXROWS", - /* 70 */ "MINROWS", - /* 71 */ "KEEP", - /* 72 */ "PAGES", - /* 73 */ "PAGESIZE", - /* 74 */ "TSDB_PAGESIZE", - /* 75 */ "PRECISION", - /* 76 */ "REPLICA", - /* 77 */ "STRICT", - /* 78 */ "VGROUPS", - /* 79 */ "SINGLE_STABLE", - /* 80 */ "RETENTIONS", - /* 81 */ "SCHEMALESS", - /* 82 */ "WAL_LEVEL", - /* 83 */ "WAL_FSYNC_PERIOD", - /* 84 */ "WAL_RETENTION_PERIOD", - /* 85 */ "WAL_RETENTION_SIZE", - /* 86 */ "WAL_ROLL_PERIOD", - /* 87 */ "WAL_SEGMENT_SIZE", - /* 88 */ "STT_TRIGGER", - /* 89 */ "TABLE_PREFIX", - /* 90 */ "TABLE_SUFFIX", - /* 91 */ "NK_COLON", - /* 92 */ "MAX_SPEED", - /* 93 */ "TABLE", - /* 94 */ "NK_LP", - /* 95 */ "NK_RP", - /* 96 */ "STABLE", - /* 97 */ "ADD", - /* 98 */ "COLUMN", - /* 99 */ "MODIFY", - /* 100 */ "RENAME", - /* 101 */ "TAG", - /* 102 */ "SET", - /* 103 */ "NK_EQ", - /* 104 */ "USING", - /* 105 */ "TAGS", - /* 106 */ "COMMENT", - /* 107 */ "BOOL", - /* 108 */ "TINYINT", - /* 109 */ "SMALLINT", - /* 110 */ "INT", - /* 111 */ "INTEGER", - /* 112 */ "BIGINT", - /* 113 */ "FLOAT", - /* 114 */ "DOUBLE", - /* 115 */ "BINARY", - /* 116 */ "TIMESTAMP", - /* 117 */ "NCHAR", - /* 118 */ "UNSIGNED", - /* 119 */ "JSON", - /* 120 */ "VARCHAR", - /* 121 */ "MEDIUMBLOB", - /* 122 */ "BLOB", - /* 123 */ "VARBINARY", - /* 124 */ "DECIMAL", - /* 125 */ "MAX_DELAY", - /* 126 */ "WATERMARK", - /* 127 */ "ROLLUP", - /* 128 */ "TTL", - /* 129 */ "SMA", - /* 130 */ "FIRST", - /* 131 */ "LAST", - /* 132 */ "SHOW", - /* 133 */ "DATABASES", - /* 134 */ "TABLES", - /* 135 */ "STABLES", - /* 136 */ "MNODES", - /* 137 */ "QNODES", - /* 138 */ "FUNCTIONS", - /* 139 */ "INDEXES", - /* 140 */ "ACCOUNTS", - /* 141 */ "APPS", - /* 142 */ "CONNECTIONS", - /* 143 */ "LICENCES", - /* 144 */ "GRANTS", - /* 145 */ "QUERIES", - /* 146 */ "SCORES", - /* 147 */ "TOPICS", - /* 148 */ "VARIABLES", - /* 149 */ "CLUSTER", - /* 150 */ "BNODES", - /* 151 */ "SNODES", - /* 152 */ "TRANSACTIONS", - /* 153 */ "DISTRIBUTED", - /* 154 */ "CONSUMERS", - /* 155 */ "SUBSCRIPTIONS", - /* 156 */ "VNODES", - /* 157 */ "LIKE", - /* 158 */ "INDEX", - /* 159 */ "FUNCTION", - /* 160 */ "INTERVAL", - /* 161 */ "TOPIC", - /* 162 */ "AS", - /* 163 */ "WITH", - /* 164 */ "META", - /* 165 */ "CONSUMER", - /* 166 */ "GROUP", - /* 167 */ "DESC", - /* 168 */ "DESCRIBE", - /* 169 */ "RESET", - /* 170 */ "QUERY", - /* 171 */ "CACHE", - /* 172 */ "EXPLAIN", - /* 173 */ "ANALYZE", - /* 174 */ "VERBOSE", - /* 175 */ "NK_BOOL", - /* 176 */ "RATIO", - /* 177 */ "NK_FLOAT", - /* 178 */ "OUTPUTTYPE", - /* 179 */ "AGGREGATE", - /* 180 */ "BUFSIZE", - /* 181 */ "STREAM", - /* 182 */ "INTO", - /* 183 */ "TRIGGER", - /* 184 */ "AT_ONCE", - /* 185 */ "WINDOW_CLOSE", - /* 186 */ "IGNORE", - /* 187 */ "EXPIRED", - /* 188 */ "SUBTABLE", - /* 189 */ "KILL", - /* 190 */ "CONNECTION", - /* 191 */ "TRANSACTION", - /* 192 */ "BALANCE", - /* 193 */ "VGROUP", - /* 194 */ "MERGE", - /* 195 */ "REDISTRIBUTE", - /* 196 */ "SPLIT", - /* 197 */ "DELETE", - /* 198 */ "INSERT", - /* 199 */ "NULL", - /* 200 */ "NK_QUESTION", - /* 201 */ "NK_ARROW", - /* 202 */ "ROWTS", - /* 203 */ "TBNAME", - /* 204 */ "QSTART", - /* 205 */ "QEND", - /* 206 */ "QDURATION", - /* 207 */ "WSTART", - /* 208 */ "WEND", - /* 209 */ "WDURATION", - /* 210 */ "IROWTS", - /* 211 */ "QTAGS", - /* 212 */ "CAST", - /* 213 */ "NOW", - /* 214 */ "TODAY", - /* 215 */ "TIMEZONE", - /* 216 */ "CLIENT_VERSION", - /* 217 */ "SERVER_VERSION", - /* 218 */ "SERVER_STATUS", - /* 219 */ "CURRENT_USER", - /* 220 */ "COUNT", - /* 221 */ "LAST_ROW", - /* 222 */ "CASE", - /* 223 */ "END", - /* 224 */ "WHEN", - /* 225 */ "THEN", - /* 226 */ "ELSE", - /* 227 */ "BETWEEN", - /* 228 */ "IS", - /* 229 */ "NK_LT", - /* 230 */ "NK_GT", - /* 231 */ "NK_LE", - /* 232 */ "NK_GE", - /* 233 */ "NK_NE", - /* 234 */ "MATCH", - /* 235 */ "NMATCH", - /* 236 */ "CONTAINS", - /* 237 */ "IN", - /* 238 */ "JOIN", - /* 239 */ "INNER", - /* 240 */ "SELECT", - /* 241 */ "DISTINCT", - /* 242 */ "WHERE", - /* 243 */ "PARTITION", - /* 244 */ "BY", - /* 245 */ "SESSION", - /* 246 */ "STATE_WINDOW", - /* 247 */ "SLIDING", - /* 248 */ "FILL", - /* 249 */ "VALUE", - /* 250 */ "NONE", - /* 251 */ "PREV", - /* 252 */ "LINEAR", - /* 253 */ "NEXT", - /* 254 */ "HAVING", - /* 255 */ "RANGE", - /* 256 */ "EVERY", - /* 257 */ "ORDER", - /* 258 */ "SLIMIT", - /* 259 */ "SOFFSET", - /* 260 */ "LIMIT", - /* 261 */ "OFFSET", - /* 262 */ "ASC", - /* 263 */ "NULLS", - /* 264 */ "ABORT", - /* 265 */ "AFTER", - /* 266 */ "ATTACH", - /* 267 */ "BEFORE", - /* 268 */ "BEGIN", - /* 269 */ "BITAND", - /* 270 */ "BITNOT", - /* 271 */ "BITOR", - /* 272 */ "BLOCKS", - /* 273 */ "CHANGE", - /* 274 */ "COMMA", - /* 275 */ "COMPACT", - /* 276 */ "CONCAT", - /* 277 */ "CONFLICT", - /* 278 */ "COPY", - /* 279 */ "DEFERRED", - /* 280 */ "DELIMITERS", - /* 281 */ "DETACH", - /* 282 */ "DIVIDE", - /* 283 */ "DOT", - /* 284 */ "EACH", - /* 285 */ "FAIL", - /* 286 */ "FILE", - /* 287 */ "FOR", - /* 288 */ "GLOB", - /* 289 */ "ID", - /* 290 */ "IMMEDIATE", - /* 291 */ "IMPORT", - /* 292 */ "INITIALLY", - /* 293 */ "INSTEAD", - /* 294 */ "ISNULL", - /* 295 */ "KEY", - /* 296 */ "MODULES", - /* 297 */ "NK_BITNOT", - /* 298 */ "NK_SEMI", - /* 299 */ "NOTNULL", - /* 300 */ "OF", - /* 301 */ "PLUS", - /* 302 */ "PRIVILEGE", - /* 303 */ "RAISE", - /* 304 */ "REPLACE", - /* 305 */ "RESTRICT", - /* 306 */ "ROW", - /* 307 */ "SEMI", - /* 308 */ "STAR", - /* 309 */ "STATEMENT", - /* 310 */ "STRING", - /* 311 */ "TIMES", - /* 312 */ "UPDATE", - /* 313 */ "VALUES", - /* 314 */ "VARIABLE", - /* 315 */ "VIEW", - /* 316 */ "WAL", - /* 317 */ "cmd", - /* 318 */ "account_options", - /* 319 */ "alter_account_options", - /* 320 */ "literal", - /* 321 */ "alter_account_option", - /* 322 */ "user_name", - /* 323 */ "sysinfo_opt", - /* 324 */ "privileges", - /* 325 */ "priv_level", - /* 326 */ "priv_type_list", - /* 327 */ "priv_type", - /* 328 */ "db_name", - /* 329 */ "dnode_endpoint", - /* 330 */ "not_exists_opt", - /* 331 */ "db_options", - /* 332 */ "exists_opt", - /* 333 */ "alter_db_options", - /* 334 */ "speed_opt", - /* 335 */ "integer_list", - /* 336 */ "variable_list", - /* 337 */ "retention_list", - /* 338 */ "alter_db_option", - /* 339 */ "retention", - /* 340 */ "full_table_name", - /* 341 */ "column_def_list", - /* 342 */ "tags_def_opt", - /* 343 */ "table_options", - /* 344 */ "multi_create_clause", - /* 345 */ "tags_def", - /* 346 */ "multi_drop_clause", - /* 347 */ "alter_table_clause", - /* 348 */ "alter_table_options", - /* 349 */ "column_name", - /* 350 */ "type_name", - /* 351 */ "signed_literal", - /* 352 */ "create_subtable_clause", - /* 353 */ "specific_cols_opt", - /* 354 */ "expression_list", - /* 355 */ "drop_table_clause", - /* 356 */ "col_name_list", - /* 357 */ "table_name", - /* 358 */ "column_def", - /* 359 */ "duration_list", - /* 360 */ "rollup_func_list", - /* 361 */ "alter_table_option", - /* 362 */ "duration_literal", - /* 363 */ "rollup_func_name", - /* 364 */ "function_name", - /* 365 */ "col_name", - /* 366 */ "db_name_cond_opt", - /* 367 */ "like_pattern_opt", - /* 368 */ "table_name_cond", - /* 369 */ "from_db_opt", - /* 370 */ "index_options", - /* 371 */ "func_list", - /* 372 */ "sliding_opt", - /* 373 */ "sma_stream_opt", - /* 374 */ "func", - /* 375 */ "stream_options", - /* 376 */ "topic_name", - /* 377 */ "query_or_subquery", - /* 378 */ "cgroup_name", - /* 379 */ "analyze_opt", - /* 380 */ "explain_options", - /* 381 */ "agg_func_opt", - /* 382 */ "bufsize_opt", - /* 383 */ "stream_name", - /* 384 */ "subtable_opt", - /* 385 */ "expression", - /* 386 */ "dnode_list", - /* 387 */ "where_clause_opt", - /* 388 */ "signed", - /* 389 */ "literal_func", - /* 390 */ "literal_list", - /* 391 */ "table_alias", - /* 392 */ "column_alias", - /* 393 */ "expr_or_subquery", - /* 394 */ "subquery", - /* 395 */ "pseudo_column", - /* 396 */ "column_reference", - /* 397 */ "function_expression", - /* 398 */ "case_when_expression", - /* 399 */ "star_func", - /* 400 */ "star_func_para_list", - /* 401 */ "noarg_func", - /* 402 */ "other_para_list", - /* 403 */ "star_func_para", - /* 404 */ "when_then_list", - /* 405 */ "case_when_else_opt", - /* 406 */ "common_expression", - /* 407 */ "when_then_expr", - /* 408 */ "predicate", - /* 409 */ "compare_op", - /* 410 */ "in_op", - /* 411 */ "in_predicate_value", - /* 412 */ "boolean_value_expression", - /* 413 */ "boolean_primary", - /* 414 */ "from_clause_opt", - /* 415 */ "table_reference_list", - /* 416 */ "table_reference", - /* 417 */ "table_primary", - /* 418 */ "joined_table", - /* 419 */ "alias_opt", - /* 420 */ "parenthesized_joined_table", - /* 421 */ "join_type", - /* 422 */ "search_condition", - /* 423 */ "query_specification", - /* 424 */ "set_quantifier_opt", - /* 425 */ "select_list", - /* 426 */ "partition_by_clause_opt", - /* 427 */ "range_opt", - /* 428 */ "every_opt", - /* 429 */ "fill_opt", - /* 430 */ "twindow_clause_opt", - /* 431 */ "group_by_clause_opt", - /* 432 */ "having_clause_opt", - /* 433 */ "select_item", - /* 434 */ "partition_list", - /* 435 */ "partition_item", - /* 436 */ "fill_mode", - /* 437 */ "group_by_list", - /* 438 */ "query_expression", - /* 439 */ "query_simple", - /* 440 */ "order_by_clause_opt", - /* 441 */ "slimit_clause_opt", - /* 442 */ "limit_clause_opt", - /* 443 */ "union_query_expression", - /* 444 */ "query_simple_or_subquery", - /* 445 */ "sort_specification_list", - /* 446 */ "sort_specification", - /* 447 */ "ordering_specification_opt", - /* 448 */ "null_ordering_opt", + /* 51 */ "FORCE", + /* 52 */ "LOCAL", + /* 53 */ "QNODE", + /* 54 */ "BNODE", + /* 55 */ "SNODE", + /* 56 */ "MNODE", + /* 57 */ "DATABASE", + /* 58 */ "USE", + /* 59 */ "FLUSH", + /* 60 */ "TRIM", + /* 61 */ "IF", + /* 62 */ "NOT", + /* 63 */ "EXISTS", + /* 64 */ "BUFFER", + /* 65 */ "CACHEMODEL", + /* 66 */ "CACHESIZE", + /* 67 */ "COMP", + /* 68 */ "DURATION", + /* 69 */ "NK_VARIABLE", + /* 70 */ "MAXROWS", + /* 71 */ "MINROWS", + /* 72 */ "KEEP", + /* 73 */ "PAGES", + /* 74 */ "PAGESIZE", + /* 75 */ "TSDB_PAGESIZE", + /* 76 */ "PRECISION", + /* 77 */ "REPLICA", + /* 78 */ "STRICT", + /* 79 */ "VGROUPS", + /* 80 */ "SINGLE_STABLE", + /* 81 */ "RETENTIONS", + /* 82 */ "SCHEMALESS", + /* 83 */ "WAL_LEVEL", + /* 84 */ "WAL_FSYNC_PERIOD", + /* 85 */ "WAL_RETENTION_PERIOD", + /* 86 */ "WAL_RETENTION_SIZE", + /* 87 */ "WAL_ROLL_PERIOD", + /* 88 */ "WAL_SEGMENT_SIZE", + /* 89 */ "STT_TRIGGER", + /* 90 */ "TABLE_PREFIX", + /* 91 */ "TABLE_SUFFIX", + /* 92 */ "NK_COLON", + /* 93 */ "MAX_SPEED", + /* 94 */ "TABLE", + /* 95 */ "NK_LP", + /* 96 */ "NK_RP", + /* 97 */ "STABLE", + /* 98 */ "ADD", + /* 99 */ "COLUMN", + /* 100 */ "MODIFY", + /* 101 */ "RENAME", + /* 102 */ "TAG", + /* 103 */ "SET", + /* 104 */ "NK_EQ", + /* 105 */ "USING", + /* 106 */ "TAGS", + /* 107 */ "COMMENT", + /* 108 */ "BOOL", + /* 109 */ "TINYINT", + /* 110 */ "SMALLINT", + /* 111 */ "INT", + /* 112 */ "INTEGER", + /* 113 */ "BIGINT", + /* 114 */ "FLOAT", + /* 115 */ "DOUBLE", + /* 116 */ "BINARY", + /* 117 */ "TIMESTAMP", + /* 118 */ "NCHAR", + /* 119 */ "UNSIGNED", + /* 120 */ "JSON", + /* 121 */ "VARCHAR", + /* 122 */ "MEDIUMBLOB", + /* 123 */ "BLOB", + /* 124 */ "VARBINARY", + /* 125 */ "DECIMAL", + /* 126 */ "MAX_DELAY", + /* 127 */ "WATERMARK", + /* 128 */ "ROLLUP", + /* 129 */ "TTL", + /* 130 */ "SMA", + /* 131 */ "FIRST", + /* 132 */ "LAST", + /* 133 */ "SHOW", + /* 134 */ "DATABASES", + /* 135 */ "TABLES", + /* 136 */ "STABLES", + /* 137 */ "MNODES", + /* 138 */ "QNODES", + /* 139 */ "FUNCTIONS", + /* 140 */ "INDEXES", + /* 141 */ "ACCOUNTS", + /* 142 */ "APPS", + /* 143 */ "CONNECTIONS", + /* 144 */ "LICENCES", + /* 145 */ "GRANTS", + /* 146 */ "QUERIES", + /* 147 */ "SCORES", + /* 148 */ "TOPICS", + /* 149 */ "VARIABLES", + /* 150 */ "CLUSTER", + /* 151 */ "BNODES", + /* 152 */ "SNODES", + /* 153 */ "TRANSACTIONS", + /* 154 */ "DISTRIBUTED", + /* 155 */ "CONSUMERS", + /* 156 */ "SUBSCRIPTIONS", + /* 157 */ "VNODES", + /* 158 */ "LIKE", + /* 159 */ "INDEX", + /* 160 */ "FUNCTION", + /* 161 */ "INTERVAL", + /* 162 */ "TOPIC", + /* 163 */ "AS", + /* 164 */ "WITH", + /* 165 */ "META", + /* 166 */ "CONSUMER", + /* 167 */ "GROUP", + /* 168 */ "DESC", + /* 169 */ "DESCRIBE", + /* 170 */ "RESET", + /* 171 */ "QUERY", + /* 172 */ "CACHE", + /* 173 */ "EXPLAIN", + /* 174 */ "ANALYZE", + /* 175 */ "VERBOSE", + /* 176 */ "NK_BOOL", + /* 177 */ "RATIO", + /* 178 */ "NK_FLOAT", + /* 179 */ "OUTPUTTYPE", + /* 180 */ "AGGREGATE", + /* 181 */ "BUFSIZE", + /* 182 */ "STREAM", + /* 183 */ "INTO", + /* 184 */ "TRIGGER", + /* 185 */ "AT_ONCE", + /* 186 */ "WINDOW_CLOSE", + /* 187 */ "IGNORE", + /* 188 */ "EXPIRED", + /* 189 */ "FILL_HISTORY", + /* 190 */ "SUBTABLE", + /* 191 */ "KILL", + /* 192 */ "CONNECTION", + /* 193 */ "TRANSACTION", + /* 194 */ "BALANCE", + /* 195 */ "VGROUP", + /* 196 */ "MERGE", + /* 197 */ "REDISTRIBUTE", + /* 198 */ "SPLIT", + /* 199 */ "DELETE", + /* 200 */ "INSERT", + /* 201 */ "NULL", + /* 202 */ "NK_QUESTION", + /* 203 */ "NK_ARROW", + /* 204 */ "ROWTS", + /* 205 */ "TBNAME", + /* 206 */ "QSTART", + /* 207 */ "QEND", + /* 208 */ "QDURATION", + /* 209 */ "WSTART", + /* 210 */ "WEND", + /* 211 */ "WDURATION", + /* 212 */ "IROWTS", + /* 213 */ "QTAGS", + /* 214 */ "CAST", + /* 215 */ "NOW", + /* 216 */ "TODAY", + /* 217 */ "TIMEZONE", + /* 218 */ "CLIENT_VERSION", + /* 219 */ "SERVER_VERSION", + /* 220 */ "SERVER_STATUS", + /* 221 */ "CURRENT_USER", + /* 222 */ "COUNT", + /* 223 */ "LAST_ROW", + /* 224 */ "CASE", + /* 225 */ "END", + /* 226 */ "WHEN", + /* 227 */ "THEN", + /* 228 */ "ELSE", + /* 229 */ "BETWEEN", + /* 230 */ "IS", + /* 231 */ "NK_LT", + /* 232 */ "NK_GT", + /* 233 */ "NK_LE", + /* 234 */ "NK_GE", + /* 235 */ "NK_NE", + /* 236 */ "MATCH", + /* 237 */ "NMATCH", + /* 238 */ "CONTAINS", + /* 239 */ "IN", + /* 240 */ "JOIN", + /* 241 */ "INNER", + /* 242 */ "SELECT", + /* 243 */ "DISTINCT", + /* 244 */ "WHERE", + /* 245 */ "PARTITION", + /* 246 */ "BY", + /* 247 */ "SESSION", + /* 248 */ "STATE_WINDOW", + /* 249 */ "SLIDING", + /* 250 */ "FILL", + /* 251 */ "VALUE", + /* 252 */ "NONE", + /* 253 */ "PREV", + /* 254 */ "LINEAR", + /* 255 */ "NEXT", + /* 256 */ "HAVING", + /* 257 */ "RANGE", + /* 258 */ "EVERY", + /* 259 */ "ORDER", + /* 260 */ "SLIMIT", + /* 261 */ "SOFFSET", + /* 262 */ "LIMIT", + /* 263 */ "OFFSET", + /* 264 */ "ASC", + /* 265 */ "NULLS", + /* 266 */ "ABORT", + /* 267 */ "AFTER", + /* 268 */ "ATTACH", + /* 269 */ "BEFORE", + /* 270 */ "BEGIN", + /* 271 */ "BITAND", + /* 272 */ "BITNOT", + /* 273 */ "BITOR", + /* 274 */ "BLOCKS", + /* 275 */ "CHANGE", + /* 276 */ "COMMA", + /* 277 */ "COMPACT", + /* 278 */ "CONCAT", + /* 279 */ "CONFLICT", + /* 280 */ "COPY", + /* 281 */ "DEFERRED", + /* 282 */ "DELIMITERS", + /* 283 */ "DETACH", + /* 284 */ "DIVIDE", + /* 285 */ "DOT", + /* 286 */ "EACH", + /* 287 */ "FAIL", + /* 288 */ "FILE", + /* 289 */ "FOR", + /* 290 */ "GLOB", + /* 291 */ "ID", + /* 292 */ "IMMEDIATE", + /* 293 */ "IMPORT", + /* 294 */ "INITIALLY", + /* 295 */ "INSTEAD", + /* 296 */ "ISNULL", + /* 297 */ "KEY", + /* 298 */ "MODULES", + /* 299 */ "NK_BITNOT", + /* 300 */ "NK_SEMI", + /* 301 */ "NOTNULL", + /* 302 */ "OF", + /* 303 */ "PLUS", + /* 304 */ "PRIVILEGE", + /* 305 */ "RAISE", + /* 306 */ "REPLACE", + /* 307 */ "RESTRICT", + /* 308 */ "ROW", + /* 309 */ "SEMI", + /* 310 */ "STAR", + /* 311 */ "STATEMENT", + /* 312 */ "STRING", + /* 313 */ "TIMES", + /* 314 */ "UPDATE", + /* 315 */ "VALUES", + /* 316 */ "VARIABLE", + /* 317 */ "VIEW", + /* 318 */ "WAL", + /* 319 */ "cmd", + /* 320 */ "account_options", + /* 321 */ "alter_account_options", + /* 322 */ "literal", + /* 323 */ "alter_account_option", + /* 324 */ "user_name", + /* 325 */ "sysinfo_opt", + /* 326 */ "privileges", + /* 327 */ "priv_level", + /* 328 */ "priv_type_list", + /* 329 */ "priv_type", + /* 330 */ "db_name", + /* 331 */ "dnode_endpoint", + /* 332 */ "force_opt", + /* 333 */ "not_exists_opt", + /* 334 */ "db_options", + /* 335 */ "exists_opt", + /* 336 */ "alter_db_options", + /* 337 */ "speed_opt", + /* 338 */ "integer_list", + /* 339 */ "variable_list", + /* 340 */ "retention_list", + /* 341 */ "alter_db_option", + /* 342 */ "retention", + /* 343 */ "full_table_name", + /* 344 */ "column_def_list", + /* 345 */ "tags_def_opt", + /* 346 */ "table_options", + /* 347 */ "multi_create_clause", + /* 348 */ "tags_def", + /* 349 */ "multi_drop_clause", + /* 350 */ "alter_table_clause", + /* 351 */ "alter_table_options", + /* 352 */ "column_name", + /* 353 */ "type_name", + /* 354 */ "signed_literal", + /* 355 */ "create_subtable_clause", + /* 356 */ "specific_cols_opt", + /* 357 */ "expression_list", + /* 358 */ "drop_table_clause", + /* 359 */ "col_name_list", + /* 360 */ "table_name", + /* 361 */ "column_def", + /* 362 */ "duration_list", + /* 363 */ "rollup_func_list", + /* 364 */ "alter_table_option", + /* 365 */ "duration_literal", + /* 366 */ "rollup_func_name", + /* 367 */ "function_name", + /* 368 */ "col_name", + /* 369 */ "db_name_cond_opt", + /* 370 */ "like_pattern_opt", + /* 371 */ "table_name_cond", + /* 372 */ "from_db_opt", + /* 373 */ "index_options", + /* 374 */ "func_list", + /* 375 */ "sliding_opt", + /* 376 */ "sma_stream_opt", + /* 377 */ "func", + /* 378 */ "stream_options", + /* 379 */ "topic_name", + /* 380 */ "query_or_subquery", + /* 381 */ "cgroup_name", + /* 382 */ "analyze_opt", + /* 383 */ "explain_options", + /* 384 */ "agg_func_opt", + /* 385 */ "bufsize_opt", + /* 386 */ "stream_name", + /* 387 */ "subtable_opt", + /* 388 */ "expression", + /* 389 */ "dnode_list", + /* 390 */ "where_clause_opt", + /* 391 */ "signed", + /* 392 */ "literal_func", + /* 393 */ "literal_list", + /* 394 */ "table_alias", + /* 395 */ "column_alias", + /* 396 */ "expr_or_subquery", + /* 397 */ "subquery", + /* 398 */ "pseudo_column", + /* 399 */ "column_reference", + /* 400 */ "function_expression", + /* 401 */ "case_when_expression", + /* 402 */ "star_func", + /* 403 */ "star_func_para_list", + /* 404 */ "noarg_func", + /* 405 */ "other_para_list", + /* 406 */ "star_func_para", + /* 407 */ "when_then_list", + /* 408 */ "case_when_else_opt", + /* 409 */ "common_expression", + /* 410 */ "when_then_expr", + /* 411 */ "predicate", + /* 412 */ "compare_op", + /* 413 */ "in_op", + /* 414 */ "in_predicate_value", + /* 415 */ "boolean_value_expression", + /* 416 */ "boolean_primary", + /* 417 */ "from_clause_opt", + /* 418 */ "table_reference_list", + /* 419 */ "table_reference", + /* 420 */ "table_primary", + /* 421 */ "joined_table", + /* 422 */ "alias_opt", + /* 423 */ "parenthesized_joined_table", + /* 424 */ "join_type", + /* 425 */ "search_condition", + /* 426 */ "query_specification", + /* 427 */ "set_quantifier_opt", + /* 428 */ "select_list", + /* 429 */ "partition_by_clause_opt", + /* 430 */ "range_opt", + /* 431 */ "every_opt", + /* 432 */ "fill_opt", + /* 433 */ "twindow_clause_opt", + /* 434 */ "group_by_clause_opt", + /* 435 */ "having_clause_opt", + /* 436 */ "select_item", + /* 437 */ "partition_list", + /* 438 */ "partition_item", + /* 439 */ "fill_mode", + /* 440 */ "group_by_list", + /* 441 */ "query_expression", + /* 442 */ "query_simple", + /* 443 */ "order_by_clause_opt", + /* 444 */ "slimit_clause_opt", + /* 445 */ "limit_clause_opt", + /* 446 */ "union_query_expression", + /* 447 */ "query_simple_or_subquery", + /* 448 */ "sort_specification_list", + /* 449 */ "sort_specification", + /* 450 */ "ordering_specification_opt", + /* 451 */ "null_ordering_opt", }; #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ @@ -1887,8 +1998,8 @@ static const char *const yyRuleName[] = { /* 40 */ "priv_level ::= db_name NK_DOT NK_STAR", /* 41 */ "cmd ::= CREATE DNODE dnode_endpoint", /* 42 */ "cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER", - /* 43 */ "cmd ::= DROP DNODE NK_INTEGER", - /* 44 */ "cmd ::= DROP DNODE dnode_endpoint", + /* 43 */ "cmd ::= DROP DNODE NK_INTEGER force_opt", + /* 44 */ "cmd ::= DROP DNODE dnode_endpoint force_opt", /* 45 */ "cmd ::= ALTER DNODE NK_INTEGER NK_STRING", /* 46 */ "cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING", /* 47 */ "cmd ::= ALTER ALL DNODES NK_STRING", @@ -1896,479 +2007,482 @@ static const char *const yyRuleName[] = { /* 49 */ "dnode_endpoint ::= NK_STRING", /* 50 */ "dnode_endpoint ::= NK_ID", /* 51 */ "dnode_endpoint ::= NK_IPTOKEN", - /* 52 */ "cmd ::= ALTER LOCAL NK_STRING", - /* 53 */ "cmd ::= ALTER LOCAL NK_STRING NK_STRING", - /* 54 */ "cmd ::= CREATE QNODE ON DNODE NK_INTEGER", - /* 55 */ "cmd ::= DROP QNODE ON DNODE NK_INTEGER", - /* 56 */ "cmd ::= CREATE BNODE ON DNODE NK_INTEGER", - /* 57 */ "cmd ::= DROP BNODE ON DNODE NK_INTEGER", - /* 58 */ "cmd ::= CREATE SNODE ON DNODE NK_INTEGER", - /* 59 */ "cmd ::= DROP SNODE ON DNODE NK_INTEGER", - /* 60 */ "cmd ::= CREATE MNODE ON DNODE NK_INTEGER", - /* 61 */ "cmd ::= DROP MNODE ON DNODE NK_INTEGER", - /* 62 */ "cmd ::= CREATE DATABASE not_exists_opt db_name db_options", - /* 63 */ "cmd ::= DROP DATABASE exists_opt db_name", - /* 64 */ "cmd ::= USE db_name", - /* 65 */ "cmd ::= ALTER DATABASE db_name alter_db_options", - /* 66 */ "cmd ::= FLUSH DATABASE db_name", - /* 67 */ "cmd ::= TRIM DATABASE db_name speed_opt", - /* 68 */ "not_exists_opt ::= IF NOT EXISTS", - /* 69 */ "not_exists_opt ::=", - /* 70 */ "exists_opt ::= IF EXISTS", - /* 71 */ "exists_opt ::=", - /* 72 */ "db_options ::=", - /* 73 */ "db_options ::= db_options BUFFER NK_INTEGER", - /* 74 */ "db_options ::= db_options CACHEMODEL NK_STRING", - /* 75 */ "db_options ::= db_options CACHESIZE NK_INTEGER", - /* 76 */ "db_options ::= db_options COMP NK_INTEGER", - /* 77 */ "db_options ::= db_options DURATION NK_INTEGER", - /* 78 */ "db_options ::= db_options DURATION NK_VARIABLE", - /* 79 */ "db_options ::= db_options MAXROWS NK_INTEGER", - /* 80 */ "db_options ::= db_options MINROWS NK_INTEGER", - /* 81 */ "db_options ::= db_options KEEP integer_list", - /* 82 */ "db_options ::= db_options KEEP variable_list", - /* 83 */ "db_options ::= db_options PAGES NK_INTEGER", - /* 84 */ "db_options ::= db_options PAGESIZE NK_INTEGER", - /* 85 */ "db_options ::= db_options TSDB_PAGESIZE NK_INTEGER", - /* 86 */ "db_options ::= db_options PRECISION NK_STRING", - /* 87 */ "db_options ::= db_options REPLICA NK_INTEGER", - /* 88 */ "db_options ::= db_options STRICT NK_STRING", - /* 89 */ "db_options ::= db_options VGROUPS NK_INTEGER", - /* 90 */ "db_options ::= db_options SINGLE_STABLE NK_INTEGER", - /* 91 */ "db_options ::= db_options RETENTIONS retention_list", - /* 92 */ "db_options ::= db_options SCHEMALESS NK_INTEGER", - /* 93 */ "db_options ::= db_options WAL_LEVEL NK_INTEGER", - /* 94 */ "db_options ::= db_options WAL_FSYNC_PERIOD NK_INTEGER", - /* 95 */ "db_options ::= db_options WAL_RETENTION_PERIOD NK_INTEGER", - /* 96 */ "db_options ::= db_options WAL_RETENTION_PERIOD NK_MINUS NK_INTEGER", - /* 97 */ "db_options ::= db_options WAL_RETENTION_SIZE NK_INTEGER", - /* 98 */ "db_options ::= db_options WAL_RETENTION_SIZE NK_MINUS NK_INTEGER", - /* 99 */ "db_options ::= db_options WAL_ROLL_PERIOD NK_INTEGER", - /* 100 */ "db_options ::= db_options WAL_SEGMENT_SIZE NK_INTEGER", - /* 101 */ "db_options ::= db_options STT_TRIGGER NK_INTEGER", - /* 102 */ "db_options ::= db_options TABLE_PREFIX NK_INTEGER", - /* 103 */ "db_options ::= db_options TABLE_SUFFIX NK_INTEGER", - /* 104 */ "alter_db_options ::= alter_db_option", - /* 105 */ "alter_db_options ::= alter_db_options alter_db_option", - /* 106 */ "alter_db_option ::= BUFFER NK_INTEGER", - /* 107 */ "alter_db_option ::= CACHEMODEL NK_STRING", - /* 108 */ "alter_db_option ::= CACHESIZE NK_INTEGER", - /* 109 */ "alter_db_option ::= WAL_FSYNC_PERIOD NK_INTEGER", - /* 110 */ "alter_db_option ::= KEEP integer_list", - /* 111 */ "alter_db_option ::= KEEP variable_list", - /* 112 */ "alter_db_option ::= PAGES NK_INTEGER", - /* 113 */ "alter_db_option ::= REPLICA NK_INTEGER", - /* 114 */ "alter_db_option ::= STRICT NK_STRING", - /* 115 */ "alter_db_option ::= WAL_LEVEL NK_INTEGER", - /* 116 */ "alter_db_option ::= STT_TRIGGER NK_INTEGER", - /* 117 */ "integer_list ::= NK_INTEGER", - /* 118 */ "integer_list ::= integer_list NK_COMMA NK_INTEGER", - /* 119 */ "variable_list ::= NK_VARIABLE", - /* 120 */ "variable_list ::= variable_list NK_COMMA NK_VARIABLE", - /* 121 */ "retention_list ::= retention", - /* 122 */ "retention_list ::= retention_list NK_COMMA retention", - /* 123 */ "retention ::= NK_VARIABLE NK_COLON NK_VARIABLE", - /* 124 */ "speed_opt ::=", - /* 125 */ "speed_opt ::= MAX_SPEED NK_INTEGER", - /* 126 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", - /* 127 */ "cmd ::= CREATE TABLE multi_create_clause", - /* 128 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", - /* 129 */ "cmd ::= DROP TABLE multi_drop_clause", - /* 130 */ "cmd ::= DROP STABLE exists_opt full_table_name", - /* 131 */ "cmd ::= ALTER TABLE alter_table_clause", - /* 132 */ "cmd ::= ALTER STABLE alter_table_clause", - /* 133 */ "alter_table_clause ::= full_table_name alter_table_options", - /* 134 */ "alter_table_clause ::= full_table_name ADD COLUMN column_name type_name", - /* 135 */ "alter_table_clause ::= full_table_name DROP COLUMN column_name", - /* 136 */ "alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name", - /* 137 */ "alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name", - /* 138 */ "alter_table_clause ::= full_table_name ADD TAG column_name type_name", - /* 139 */ "alter_table_clause ::= full_table_name DROP TAG column_name", - /* 140 */ "alter_table_clause ::= full_table_name MODIFY TAG column_name type_name", - /* 141 */ "alter_table_clause ::= full_table_name RENAME TAG column_name column_name", - /* 142 */ "alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal", - /* 143 */ "multi_create_clause ::= create_subtable_clause", - /* 144 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", - /* 145 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options", - /* 146 */ "multi_drop_clause ::= drop_table_clause", - /* 147 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", - /* 148 */ "drop_table_clause ::= exists_opt full_table_name", - /* 149 */ "specific_cols_opt ::=", - /* 150 */ "specific_cols_opt ::= NK_LP col_name_list NK_RP", - /* 151 */ "full_table_name ::= table_name", - /* 152 */ "full_table_name ::= db_name NK_DOT table_name", - /* 153 */ "column_def_list ::= column_def", - /* 154 */ "column_def_list ::= column_def_list NK_COMMA column_def", - /* 155 */ "column_def ::= column_name type_name", - /* 156 */ "column_def ::= column_name type_name COMMENT NK_STRING", - /* 157 */ "type_name ::= BOOL", - /* 158 */ "type_name ::= TINYINT", - /* 159 */ "type_name ::= SMALLINT", - /* 160 */ "type_name ::= INT", - /* 161 */ "type_name ::= INTEGER", - /* 162 */ "type_name ::= BIGINT", - /* 163 */ "type_name ::= FLOAT", - /* 164 */ "type_name ::= DOUBLE", - /* 165 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", - /* 166 */ "type_name ::= TIMESTAMP", - /* 167 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", - /* 168 */ "type_name ::= TINYINT UNSIGNED", - /* 169 */ "type_name ::= SMALLINT UNSIGNED", - /* 170 */ "type_name ::= INT UNSIGNED", - /* 171 */ "type_name ::= BIGINT UNSIGNED", - /* 172 */ "type_name ::= JSON", - /* 173 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", - /* 174 */ "type_name ::= MEDIUMBLOB", - /* 175 */ "type_name ::= BLOB", - /* 176 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", - /* 177 */ "type_name ::= DECIMAL", - /* 178 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", - /* 179 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", - /* 180 */ "tags_def_opt ::=", - /* 181 */ "tags_def_opt ::= tags_def", - /* 182 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", - /* 183 */ "table_options ::=", - /* 184 */ "table_options ::= table_options COMMENT NK_STRING", - /* 185 */ "table_options ::= table_options MAX_DELAY duration_list", - /* 186 */ "table_options ::= table_options WATERMARK duration_list", - /* 187 */ "table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP", - /* 188 */ "table_options ::= table_options TTL NK_INTEGER", - /* 189 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", - /* 190 */ "alter_table_options ::= alter_table_option", - /* 191 */ "alter_table_options ::= alter_table_options alter_table_option", - /* 192 */ "alter_table_option ::= COMMENT NK_STRING", - /* 193 */ "alter_table_option ::= TTL NK_INTEGER", - /* 194 */ "duration_list ::= duration_literal", - /* 195 */ "duration_list ::= duration_list NK_COMMA duration_literal", - /* 196 */ "rollup_func_list ::= rollup_func_name", - /* 197 */ "rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name", - /* 198 */ "rollup_func_name ::= function_name", - /* 199 */ "rollup_func_name ::= FIRST", - /* 200 */ "rollup_func_name ::= LAST", - /* 201 */ "col_name_list ::= col_name", - /* 202 */ "col_name_list ::= col_name_list NK_COMMA col_name", - /* 203 */ "col_name ::= column_name", - /* 204 */ "cmd ::= SHOW DNODES", - /* 205 */ "cmd ::= SHOW USERS", - /* 206 */ "cmd ::= SHOW DATABASES", - /* 207 */ "cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt", - /* 208 */ "cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt", - /* 209 */ "cmd ::= SHOW db_name_cond_opt VGROUPS", - /* 210 */ "cmd ::= SHOW MNODES", - /* 211 */ "cmd ::= SHOW QNODES", - /* 212 */ "cmd ::= SHOW FUNCTIONS", - /* 213 */ "cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt", - /* 214 */ "cmd ::= SHOW STREAMS", - /* 215 */ "cmd ::= SHOW ACCOUNTS", - /* 216 */ "cmd ::= SHOW APPS", - /* 217 */ "cmd ::= SHOW CONNECTIONS", - /* 218 */ "cmd ::= SHOW LICENCES", - /* 219 */ "cmd ::= SHOW GRANTS", - /* 220 */ "cmd ::= SHOW CREATE DATABASE db_name", - /* 221 */ "cmd ::= SHOW CREATE TABLE full_table_name", - /* 222 */ "cmd ::= SHOW CREATE STABLE full_table_name", - /* 223 */ "cmd ::= SHOW QUERIES", - /* 224 */ "cmd ::= SHOW SCORES", - /* 225 */ "cmd ::= SHOW TOPICS", - /* 226 */ "cmd ::= SHOW VARIABLES", - /* 227 */ "cmd ::= SHOW CLUSTER VARIABLES", - /* 228 */ "cmd ::= SHOW LOCAL VARIABLES", - /* 229 */ "cmd ::= SHOW DNODE NK_INTEGER VARIABLES like_pattern_opt", - /* 230 */ "cmd ::= SHOW BNODES", - /* 231 */ "cmd ::= SHOW SNODES", - /* 232 */ "cmd ::= SHOW CLUSTER", - /* 233 */ "cmd ::= SHOW TRANSACTIONS", - /* 234 */ "cmd ::= SHOW TABLE DISTRIBUTED full_table_name", - /* 235 */ "cmd ::= SHOW CONSUMERS", - /* 236 */ "cmd ::= SHOW SUBSCRIPTIONS", - /* 237 */ "cmd ::= SHOW TAGS FROM table_name_cond from_db_opt", - /* 238 */ "cmd ::= SHOW TABLE TAGS FROM table_name_cond from_db_opt", - /* 239 */ "cmd ::= SHOW VNODES NK_INTEGER", - /* 240 */ "cmd ::= SHOW VNODES NK_STRING", - /* 241 */ "db_name_cond_opt ::=", - /* 242 */ "db_name_cond_opt ::= db_name NK_DOT", - /* 243 */ "like_pattern_opt ::=", - /* 244 */ "like_pattern_opt ::= LIKE NK_STRING", - /* 245 */ "table_name_cond ::= table_name", - /* 246 */ "from_db_opt ::=", - /* 247 */ "from_db_opt ::= FROM db_name", - /* 248 */ "cmd ::= CREATE SMA INDEX not_exists_opt full_table_name ON full_table_name index_options", - /* 249 */ "cmd ::= DROP INDEX exists_opt full_table_name", - /* 250 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt", - /* 251 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt", - /* 252 */ "func_list ::= func", - /* 253 */ "func_list ::= func_list NK_COMMA func", - /* 254 */ "func ::= function_name NK_LP expression_list NK_RP", - /* 255 */ "sma_stream_opt ::=", - /* 256 */ "sma_stream_opt ::= stream_options WATERMARK duration_literal", - /* 257 */ "sma_stream_opt ::= stream_options MAX_DELAY duration_literal", - /* 258 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_or_subquery", - /* 259 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name", - /* 260 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name", - /* 261 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name", - /* 262 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name", - /* 263 */ "cmd ::= DROP TOPIC exists_opt topic_name", - /* 264 */ "cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name", - /* 265 */ "cmd ::= DESC full_table_name", - /* 266 */ "cmd ::= DESCRIBE full_table_name", - /* 267 */ "cmd ::= RESET QUERY CACHE", - /* 268 */ "cmd ::= EXPLAIN analyze_opt explain_options query_or_subquery", - /* 269 */ "analyze_opt ::=", - /* 270 */ "analyze_opt ::= ANALYZE", - /* 271 */ "explain_options ::=", - /* 272 */ "explain_options ::= explain_options VERBOSE NK_BOOL", - /* 273 */ "explain_options ::= explain_options RATIO NK_FLOAT", - /* 274 */ "cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", - /* 275 */ "cmd ::= DROP FUNCTION exists_opt function_name", - /* 276 */ "agg_func_opt ::=", - /* 277 */ "agg_func_opt ::= AGGREGATE", - /* 278 */ "bufsize_opt ::=", - /* 279 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", - /* 280 */ "cmd ::= CREATE STREAM not_exists_opt stream_name stream_options INTO full_table_name tags_def_opt subtable_opt AS query_or_subquery", - /* 281 */ "cmd ::= DROP STREAM exists_opt stream_name", - /* 282 */ "stream_options ::=", - /* 283 */ "stream_options ::= stream_options TRIGGER AT_ONCE", - /* 284 */ "stream_options ::= stream_options TRIGGER WINDOW_CLOSE", - /* 285 */ "stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal", - /* 286 */ "stream_options ::= stream_options WATERMARK duration_literal", - /* 287 */ "stream_options ::= stream_options IGNORE EXPIRED NK_INTEGER", - /* 288 */ "subtable_opt ::=", - /* 289 */ "subtable_opt ::= SUBTABLE NK_LP expression NK_RP", - /* 290 */ "cmd ::= KILL CONNECTION NK_INTEGER", - /* 291 */ "cmd ::= KILL QUERY NK_STRING", - /* 292 */ "cmd ::= KILL TRANSACTION NK_INTEGER", - /* 293 */ "cmd ::= BALANCE VGROUP", - /* 294 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", - /* 295 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", - /* 296 */ "cmd ::= SPLIT VGROUP NK_INTEGER", - /* 297 */ "dnode_list ::= DNODE NK_INTEGER", - /* 298 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", - /* 299 */ "cmd ::= DELETE FROM full_table_name where_clause_opt", - /* 300 */ "cmd ::= query_or_subquery", - /* 301 */ "cmd ::= INSERT INTO full_table_name NK_LP col_name_list NK_RP query_or_subquery", - /* 302 */ "cmd ::= INSERT INTO full_table_name query_or_subquery", - /* 303 */ "literal ::= NK_INTEGER", - /* 304 */ "literal ::= NK_FLOAT", - /* 305 */ "literal ::= NK_STRING", - /* 306 */ "literal ::= NK_BOOL", - /* 307 */ "literal ::= TIMESTAMP NK_STRING", - /* 308 */ "literal ::= duration_literal", - /* 309 */ "literal ::= NULL", - /* 310 */ "literal ::= NK_QUESTION", - /* 311 */ "duration_literal ::= NK_VARIABLE", - /* 312 */ "signed ::= NK_INTEGER", - /* 313 */ "signed ::= NK_PLUS NK_INTEGER", - /* 314 */ "signed ::= NK_MINUS NK_INTEGER", - /* 315 */ "signed ::= NK_FLOAT", - /* 316 */ "signed ::= NK_PLUS NK_FLOAT", - /* 317 */ "signed ::= NK_MINUS NK_FLOAT", - /* 318 */ "signed_literal ::= signed", - /* 319 */ "signed_literal ::= NK_STRING", - /* 320 */ "signed_literal ::= NK_BOOL", - /* 321 */ "signed_literal ::= TIMESTAMP NK_STRING", - /* 322 */ "signed_literal ::= duration_literal", - /* 323 */ "signed_literal ::= NULL", - /* 324 */ "signed_literal ::= literal_func", - /* 325 */ "signed_literal ::= NK_QUESTION", - /* 326 */ "literal_list ::= signed_literal", - /* 327 */ "literal_list ::= literal_list NK_COMMA signed_literal", - /* 328 */ "db_name ::= NK_ID", - /* 329 */ "table_name ::= NK_ID", - /* 330 */ "column_name ::= NK_ID", - /* 331 */ "function_name ::= NK_ID", - /* 332 */ "table_alias ::= NK_ID", - /* 333 */ "column_alias ::= NK_ID", - /* 334 */ "user_name ::= NK_ID", - /* 335 */ "topic_name ::= NK_ID", - /* 336 */ "stream_name ::= NK_ID", - /* 337 */ "cgroup_name ::= NK_ID", - /* 338 */ "expr_or_subquery ::= expression", - /* 339 */ "expr_or_subquery ::= subquery", - /* 340 */ "expression ::= literal", - /* 341 */ "expression ::= pseudo_column", - /* 342 */ "expression ::= column_reference", - /* 343 */ "expression ::= function_expression", - /* 344 */ "expression ::= case_when_expression", - /* 345 */ "expression ::= NK_LP expression NK_RP", - /* 346 */ "expression ::= NK_PLUS expr_or_subquery", - /* 347 */ "expression ::= NK_MINUS expr_or_subquery", - /* 348 */ "expression ::= expr_or_subquery NK_PLUS expr_or_subquery", - /* 349 */ "expression ::= expr_or_subquery NK_MINUS expr_or_subquery", - /* 350 */ "expression ::= expr_or_subquery NK_STAR expr_or_subquery", - /* 351 */ "expression ::= expr_or_subquery NK_SLASH expr_or_subquery", - /* 352 */ "expression ::= expr_or_subquery NK_REM expr_or_subquery", - /* 353 */ "expression ::= column_reference NK_ARROW NK_STRING", - /* 354 */ "expression ::= expr_or_subquery NK_BITAND expr_or_subquery", - /* 355 */ "expression ::= expr_or_subquery NK_BITOR expr_or_subquery", - /* 356 */ "expression_list ::= expr_or_subquery", - /* 357 */ "expression_list ::= expression_list NK_COMMA expr_or_subquery", - /* 358 */ "column_reference ::= column_name", - /* 359 */ "column_reference ::= table_name NK_DOT column_name", - /* 360 */ "pseudo_column ::= ROWTS", - /* 361 */ "pseudo_column ::= TBNAME", - /* 362 */ "pseudo_column ::= table_name NK_DOT TBNAME", - /* 363 */ "pseudo_column ::= QSTART", - /* 364 */ "pseudo_column ::= QEND", - /* 365 */ "pseudo_column ::= QDURATION", - /* 366 */ "pseudo_column ::= WSTART", - /* 367 */ "pseudo_column ::= WEND", - /* 368 */ "pseudo_column ::= WDURATION", - /* 369 */ "pseudo_column ::= IROWTS", - /* 370 */ "pseudo_column ::= QTAGS", - /* 371 */ "function_expression ::= function_name NK_LP expression_list NK_RP", - /* 372 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", - /* 373 */ "function_expression ::= CAST NK_LP expr_or_subquery AS type_name NK_RP", - /* 374 */ "function_expression ::= literal_func", - /* 375 */ "literal_func ::= noarg_func NK_LP NK_RP", - /* 376 */ "literal_func ::= NOW", - /* 377 */ "noarg_func ::= NOW", - /* 378 */ "noarg_func ::= TODAY", - /* 379 */ "noarg_func ::= TIMEZONE", - /* 380 */ "noarg_func ::= DATABASE", - /* 381 */ "noarg_func ::= CLIENT_VERSION", - /* 382 */ "noarg_func ::= SERVER_VERSION", - /* 383 */ "noarg_func ::= SERVER_STATUS", - /* 384 */ "noarg_func ::= CURRENT_USER", - /* 385 */ "noarg_func ::= USER", - /* 386 */ "star_func ::= COUNT", - /* 387 */ "star_func ::= FIRST", - /* 388 */ "star_func ::= LAST", - /* 389 */ "star_func ::= LAST_ROW", - /* 390 */ "star_func_para_list ::= NK_STAR", - /* 391 */ "star_func_para_list ::= other_para_list", - /* 392 */ "other_para_list ::= star_func_para", - /* 393 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", - /* 394 */ "star_func_para ::= expr_or_subquery", - /* 395 */ "star_func_para ::= table_name NK_DOT NK_STAR", - /* 396 */ "case_when_expression ::= CASE when_then_list case_when_else_opt END", - /* 397 */ "case_when_expression ::= CASE common_expression when_then_list case_when_else_opt END", - /* 398 */ "when_then_list ::= when_then_expr", - /* 399 */ "when_then_list ::= when_then_list when_then_expr", - /* 400 */ "when_then_expr ::= WHEN common_expression THEN common_expression", - /* 401 */ "case_when_else_opt ::=", - /* 402 */ "case_when_else_opt ::= ELSE common_expression", - /* 403 */ "predicate ::= expr_or_subquery compare_op expr_or_subquery", - /* 404 */ "predicate ::= expr_or_subquery BETWEEN expr_or_subquery AND expr_or_subquery", - /* 405 */ "predicate ::= expr_or_subquery NOT BETWEEN expr_or_subquery AND expr_or_subquery", - /* 406 */ "predicate ::= expr_or_subquery IS NULL", - /* 407 */ "predicate ::= expr_or_subquery IS NOT NULL", - /* 408 */ "predicate ::= expr_or_subquery in_op in_predicate_value", - /* 409 */ "compare_op ::= NK_LT", - /* 410 */ "compare_op ::= NK_GT", - /* 411 */ "compare_op ::= NK_LE", - /* 412 */ "compare_op ::= NK_GE", - /* 413 */ "compare_op ::= NK_NE", - /* 414 */ "compare_op ::= NK_EQ", - /* 415 */ "compare_op ::= LIKE", - /* 416 */ "compare_op ::= NOT LIKE", - /* 417 */ "compare_op ::= MATCH", - /* 418 */ "compare_op ::= NMATCH", - /* 419 */ "compare_op ::= CONTAINS", - /* 420 */ "in_op ::= IN", - /* 421 */ "in_op ::= NOT IN", - /* 422 */ "in_predicate_value ::= NK_LP literal_list NK_RP", - /* 423 */ "boolean_value_expression ::= boolean_primary", - /* 424 */ "boolean_value_expression ::= NOT boolean_primary", - /* 425 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", - /* 426 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", - /* 427 */ "boolean_primary ::= predicate", - /* 428 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", - /* 429 */ "common_expression ::= expr_or_subquery", - /* 430 */ "common_expression ::= boolean_value_expression", - /* 431 */ "from_clause_opt ::=", - /* 432 */ "from_clause_opt ::= FROM table_reference_list", - /* 433 */ "table_reference_list ::= table_reference", - /* 434 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", - /* 435 */ "table_reference ::= table_primary", - /* 436 */ "table_reference ::= joined_table", - /* 437 */ "table_primary ::= table_name alias_opt", - /* 438 */ "table_primary ::= db_name NK_DOT table_name alias_opt", - /* 439 */ "table_primary ::= subquery alias_opt", - /* 440 */ "table_primary ::= parenthesized_joined_table", - /* 441 */ "alias_opt ::=", - /* 442 */ "alias_opt ::= table_alias", - /* 443 */ "alias_opt ::= AS table_alias", - /* 444 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", - /* 445 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", - /* 446 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", - /* 447 */ "join_type ::=", - /* 448 */ "join_type ::= INNER", - /* 449 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt", - /* 450 */ "set_quantifier_opt ::=", - /* 451 */ "set_quantifier_opt ::= DISTINCT", - /* 452 */ "set_quantifier_opt ::= ALL", - /* 453 */ "select_list ::= select_item", - /* 454 */ "select_list ::= select_list NK_COMMA select_item", - /* 455 */ "select_item ::= NK_STAR", - /* 456 */ "select_item ::= common_expression", - /* 457 */ "select_item ::= common_expression column_alias", - /* 458 */ "select_item ::= common_expression AS column_alias", - /* 459 */ "select_item ::= table_name NK_DOT NK_STAR", - /* 460 */ "where_clause_opt ::=", - /* 461 */ "where_clause_opt ::= WHERE search_condition", - /* 462 */ "partition_by_clause_opt ::=", - /* 463 */ "partition_by_clause_opt ::= PARTITION BY partition_list", - /* 464 */ "partition_list ::= partition_item", - /* 465 */ "partition_list ::= partition_list NK_COMMA partition_item", - /* 466 */ "partition_item ::= expr_or_subquery", - /* 467 */ "partition_item ::= expr_or_subquery column_alias", - /* 468 */ "partition_item ::= expr_or_subquery AS column_alias", - /* 469 */ "twindow_clause_opt ::=", - /* 470 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", - /* 471 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expr_or_subquery NK_RP", - /* 472 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", - /* 473 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", - /* 474 */ "sliding_opt ::=", - /* 475 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", - /* 476 */ "fill_opt ::=", - /* 477 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", - /* 478 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", - /* 479 */ "fill_mode ::= NONE", - /* 480 */ "fill_mode ::= PREV", - /* 481 */ "fill_mode ::= NULL", - /* 482 */ "fill_mode ::= LINEAR", - /* 483 */ "fill_mode ::= NEXT", - /* 484 */ "group_by_clause_opt ::=", - /* 485 */ "group_by_clause_opt ::= GROUP BY group_by_list", - /* 486 */ "group_by_list ::= expr_or_subquery", - /* 487 */ "group_by_list ::= group_by_list NK_COMMA expr_or_subquery", - /* 488 */ "having_clause_opt ::=", - /* 489 */ "having_clause_opt ::= HAVING search_condition", - /* 490 */ "range_opt ::=", - /* 491 */ "range_opt ::= RANGE NK_LP expr_or_subquery NK_COMMA expr_or_subquery NK_RP", - /* 492 */ "every_opt ::=", - /* 493 */ "every_opt ::= EVERY NK_LP duration_literal NK_RP", - /* 494 */ "query_expression ::= query_simple order_by_clause_opt slimit_clause_opt limit_clause_opt", - /* 495 */ "query_simple ::= query_specification", - /* 496 */ "query_simple ::= union_query_expression", - /* 497 */ "union_query_expression ::= query_simple_or_subquery UNION ALL query_simple_or_subquery", - /* 498 */ "union_query_expression ::= query_simple_or_subquery UNION query_simple_or_subquery", - /* 499 */ "query_simple_or_subquery ::= query_simple", - /* 500 */ "query_simple_or_subquery ::= subquery", - /* 501 */ "query_or_subquery ::= query_expression", - /* 502 */ "query_or_subquery ::= subquery", - /* 503 */ "order_by_clause_opt ::=", - /* 504 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", - /* 505 */ "slimit_clause_opt ::=", - /* 506 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", - /* 507 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", - /* 508 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 509 */ "limit_clause_opt ::=", - /* 510 */ "limit_clause_opt ::= LIMIT NK_INTEGER", - /* 511 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", - /* 512 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", - /* 513 */ "subquery ::= NK_LP query_expression NK_RP", - /* 514 */ "subquery ::= NK_LP subquery NK_RP", - /* 515 */ "search_condition ::= common_expression", - /* 516 */ "sort_specification_list ::= sort_specification", - /* 517 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", - /* 518 */ "sort_specification ::= expr_or_subquery ordering_specification_opt null_ordering_opt", - /* 519 */ "ordering_specification_opt ::=", - /* 520 */ "ordering_specification_opt ::= ASC", - /* 521 */ "ordering_specification_opt ::= DESC", - /* 522 */ "null_ordering_opt ::=", - /* 523 */ "null_ordering_opt ::= NULLS FIRST", - /* 524 */ "null_ordering_opt ::= NULLS LAST", + /* 52 */ "force_opt ::=", + /* 53 */ "force_opt ::= FORCE", + /* 54 */ "cmd ::= ALTER LOCAL NK_STRING", + /* 55 */ "cmd ::= ALTER LOCAL NK_STRING NK_STRING", + /* 56 */ "cmd ::= CREATE QNODE ON DNODE NK_INTEGER", + /* 57 */ "cmd ::= DROP QNODE ON DNODE NK_INTEGER", + /* 58 */ "cmd ::= CREATE BNODE ON DNODE NK_INTEGER", + /* 59 */ "cmd ::= DROP BNODE ON DNODE NK_INTEGER", + /* 60 */ "cmd ::= CREATE SNODE ON DNODE NK_INTEGER", + /* 61 */ "cmd ::= DROP SNODE ON DNODE NK_INTEGER", + /* 62 */ "cmd ::= CREATE MNODE ON DNODE NK_INTEGER", + /* 63 */ "cmd ::= DROP MNODE ON DNODE NK_INTEGER", + /* 64 */ "cmd ::= CREATE DATABASE not_exists_opt db_name db_options", + /* 65 */ "cmd ::= DROP DATABASE exists_opt db_name", + /* 66 */ "cmd ::= USE db_name", + /* 67 */ "cmd ::= ALTER DATABASE db_name alter_db_options", + /* 68 */ "cmd ::= FLUSH DATABASE db_name", + /* 69 */ "cmd ::= TRIM DATABASE db_name speed_opt", + /* 70 */ "not_exists_opt ::= IF NOT EXISTS", + /* 71 */ "not_exists_opt ::=", + /* 72 */ "exists_opt ::= IF EXISTS", + /* 73 */ "exists_opt ::=", + /* 74 */ "db_options ::=", + /* 75 */ "db_options ::= db_options BUFFER NK_INTEGER", + /* 76 */ "db_options ::= db_options CACHEMODEL NK_STRING", + /* 77 */ "db_options ::= db_options CACHESIZE NK_INTEGER", + /* 78 */ "db_options ::= db_options COMP NK_INTEGER", + /* 79 */ "db_options ::= db_options DURATION NK_INTEGER", + /* 80 */ "db_options ::= db_options DURATION NK_VARIABLE", + /* 81 */ "db_options ::= db_options MAXROWS NK_INTEGER", + /* 82 */ "db_options ::= db_options MINROWS NK_INTEGER", + /* 83 */ "db_options ::= db_options KEEP integer_list", + /* 84 */ "db_options ::= db_options KEEP variable_list", + /* 85 */ "db_options ::= db_options PAGES NK_INTEGER", + /* 86 */ "db_options ::= db_options PAGESIZE NK_INTEGER", + /* 87 */ "db_options ::= db_options TSDB_PAGESIZE NK_INTEGER", + /* 88 */ "db_options ::= db_options PRECISION NK_STRING", + /* 89 */ "db_options ::= db_options REPLICA NK_INTEGER", + /* 90 */ "db_options ::= db_options STRICT NK_STRING", + /* 91 */ "db_options ::= db_options VGROUPS NK_INTEGER", + /* 92 */ "db_options ::= db_options SINGLE_STABLE NK_INTEGER", + /* 93 */ "db_options ::= db_options RETENTIONS retention_list", + /* 94 */ "db_options ::= db_options SCHEMALESS NK_INTEGER", + /* 95 */ "db_options ::= db_options WAL_LEVEL NK_INTEGER", + /* 96 */ "db_options ::= db_options WAL_FSYNC_PERIOD NK_INTEGER", + /* 97 */ "db_options ::= db_options WAL_RETENTION_PERIOD NK_INTEGER", + /* 98 */ "db_options ::= db_options WAL_RETENTION_PERIOD NK_MINUS NK_INTEGER", + /* 99 */ "db_options ::= db_options WAL_RETENTION_SIZE NK_INTEGER", + /* 100 */ "db_options ::= db_options WAL_RETENTION_SIZE NK_MINUS NK_INTEGER", + /* 101 */ "db_options ::= db_options WAL_ROLL_PERIOD NK_INTEGER", + /* 102 */ "db_options ::= db_options WAL_SEGMENT_SIZE NK_INTEGER", + /* 103 */ "db_options ::= db_options STT_TRIGGER NK_INTEGER", + /* 104 */ "db_options ::= db_options TABLE_PREFIX NK_INTEGER", + /* 105 */ "db_options ::= db_options TABLE_SUFFIX NK_INTEGER", + /* 106 */ "alter_db_options ::= alter_db_option", + /* 107 */ "alter_db_options ::= alter_db_options alter_db_option", + /* 108 */ "alter_db_option ::= BUFFER NK_INTEGER", + /* 109 */ "alter_db_option ::= CACHEMODEL NK_STRING", + /* 110 */ "alter_db_option ::= CACHESIZE NK_INTEGER", + /* 111 */ "alter_db_option ::= WAL_FSYNC_PERIOD NK_INTEGER", + /* 112 */ "alter_db_option ::= KEEP integer_list", + /* 113 */ "alter_db_option ::= KEEP variable_list", + /* 114 */ "alter_db_option ::= PAGES NK_INTEGER", + /* 115 */ "alter_db_option ::= REPLICA NK_INTEGER", + /* 116 */ "alter_db_option ::= STRICT NK_STRING", + /* 117 */ "alter_db_option ::= WAL_LEVEL NK_INTEGER", + /* 118 */ "alter_db_option ::= STT_TRIGGER NK_INTEGER", + /* 119 */ "integer_list ::= NK_INTEGER", + /* 120 */ "integer_list ::= integer_list NK_COMMA NK_INTEGER", + /* 121 */ "variable_list ::= NK_VARIABLE", + /* 122 */ "variable_list ::= variable_list NK_COMMA NK_VARIABLE", + /* 123 */ "retention_list ::= retention", + /* 124 */ "retention_list ::= retention_list NK_COMMA retention", + /* 125 */ "retention ::= NK_VARIABLE NK_COLON NK_VARIABLE", + /* 126 */ "speed_opt ::=", + /* 127 */ "speed_opt ::= MAX_SPEED NK_INTEGER", + /* 128 */ "cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options", + /* 129 */ "cmd ::= CREATE TABLE multi_create_clause", + /* 130 */ "cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options", + /* 131 */ "cmd ::= DROP TABLE multi_drop_clause", + /* 132 */ "cmd ::= DROP STABLE exists_opt full_table_name", + /* 133 */ "cmd ::= ALTER TABLE alter_table_clause", + /* 134 */ "cmd ::= ALTER STABLE alter_table_clause", + /* 135 */ "alter_table_clause ::= full_table_name alter_table_options", + /* 136 */ "alter_table_clause ::= full_table_name ADD COLUMN column_name type_name", + /* 137 */ "alter_table_clause ::= full_table_name DROP COLUMN column_name", + /* 138 */ "alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name", + /* 139 */ "alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name", + /* 140 */ "alter_table_clause ::= full_table_name ADD TAG column_name type_name", + /* 141 */ "alter_table_clause ::= full_table_name DROP TAG column_name", + /* 142 */ "alter_table_clause ::= full_table_name MODIFY TAG column_name type_name", + /* 143 */ "alter_table_clause ::= full_table_name RENAME TAG column_name column_name", + /* 144 */ "alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal", + /* 145 */ "multi_create_clause ::= create_subtable_clause", + /* 146 */ "multi_create_clause ::= multi_create_clause create_subtable_clause", + /* 147 */ "create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options", + /* 148 */ "multi_drop_clause ::= drop_table_clause", + /* 149 */ "multi_drop_clause ::= multi_drop_clause drop_table_clause", + /* 150 */ "drop_table_clause ::= exists_opt full_table_name", + /* 151 */ "specific_cols_opt ::=", + /* 152 */ "specific_cols_opt ::= NK_LP col_name_list NK_RP", + /* 153 */ "full_table_name ::= table_name", + /* 154 */ "full_table_name ::= db_name NK_DOT table_name", + /* 155 */ "column_def_list ::= column_def", + /* 156 */ "column_def_list ::= column_def_list NK_COMMA column_def", + /* 157 */ "column_def ::= column_name type_name", + /* 158 */ "column_def ::= column_name type_name COMMENT NK_STRING", + /* 159 */ "type_name ::= BOOL", + /* 160 */ "type_name ::= TINYINT", + /* 161 */ "type_name ::= SMALLINT", + /* 162 */ "type_name ::= INT", + /* 163 */ "type_name ::= INTEGER", + /* 164 */ "type_name ::= BIGINT", + /* 165 */ "type_name ::= FLOAT", + /* 166 */ "type_name ::= DOUBLE", + /* 167 */ "type_name ::= BINARY NK_LP NK_INTEGER NK_RP", + /* 168 */ "type_name ::= TIMESTAMP", + /* 169 */ "type_name ::= NCHAR NK_LP NK_INTEGER NK_RP", + /* 170 */ "type_name ::= TINYINT UNSIGNED", + /* 171 */ "type_name ::= SMALLINT UNSIGNED", + /* 172 */ "type_name ::= INT UNSIGNED", + /* 173 */ "type_name ::= BIGINT UNSIGNED", + /* 174 */ "type_name ::= JSON", + /* 175 */ "type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP", + /* 176 */ "type_name ::= MEDIUMBLOB", + /* 177 */ "type_name ::= BLOB", + /* 178 */ "type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP", + /* 179 */ "type_name ::= DECIMAL", + /* 180 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP", + /* 181 */ "type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP", + /* 182 */ "tags_def_opt ::=", + /* 183 */ "tags_def_opt ::= tags_def", + /* 184 */ "tags_def ::= TAGS NK_LP column_def_list NK_RP", + /* 185 */ "table_options ::=", + /* 186 */ "table_options ::= table_options COMMENT NK_STRING", + /* 187 */ "table_options ::= table_options MAX_DELAY duration_list", + /* 188 */ "table_options ::= table_options WATERMARK duration_list", + /* 189 */ "table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP", + /* 190 */ "table_options ::= table_options TTL NK_INTEGER", + /* 191 */ "table_options ::= table_options SMA NK_LP col_name_list NK_RP", + /* 192 */ "alter_table_options ::= alter_table_option", + /* 193 */ "alter_table_options ::= alter_table_options alter_table_option", + /* 194 */ "alter_table_option ::= COMMENT NK_STRING", + /* 195 */ "alter_table_option ::= TTL NK_INTEGER", + /* 196 */ "duration_list ::= duration_literal", + /* 197 */ "duration_list ::= duration_list NK_COMMA duration_literal", + /* 198 */ "rollup_func_list ::= rollup_func_name", + /* 199 */ "rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name", + /* 200 */ "rollup_func_name ::= function_name", + /* 201 */ "rollup_func_name ::= FIRST", + /* 202 */ "rollup_func_name ::= LAST", + /* 203 */ "col_name_list ::= col_name", + /* 204 */ "col_name_list ::= col_name_list NK_COMMA col_name", + /* 205 */ "col_name ::= column_name", + /* 206 */ "cmd ::= SHOW DNODES", + /* 207 */ "cmd ::= SHOW USERS", + /* 208 */ "cmd ::= SHOW DATABASES", + /* 209 */ "cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt", + /* 210 */ "cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt", + /* 211 */ "cmd ::= SHOW db_name_cond_opt VGROUPS", + /* 212 */ "cmd ::= SHOW MNODES", + /* 213 */ "cmd ::= SHOW QNODES", + /* 214 */ "cmd ::= SHOW FUNCTIONS", + /* 215 */ "cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt", + /* 216 */ "cmd ::= SHOW STREAMS", + /* 217 */ "cmd ::= SHOW ACCOUNTS", + /* 218 */ "cmd ::= SHOW APPS", + /* 219 */ "cmd ::= SHOW CONNECTIONS", + /* 220 */ "cmd ::= SHOW LICENCES", + /* 221 */ "cmd ::= SHOW GRANTS", + /* 222 */ "cmd ::= SHOW CREATE DATABASE db_name", + /* 223 */ "cmd ::= SHOW CREATE TABLE full_table_name", + /* 224 */ "cmd ::= SHOW CREATE STABLE full_table_name", + /* 225 */ "cmd ::= SHOW QUERIES", + /* 226 */ "cmd ::= SHOW SCORES", + /* 227 */ "cmd ::= SHOW TOPICS", + /* 228 */ "cmd ::= SHOW VARIABLES", + /* 229 */ "cmd ::= SHOW CLUSTER VARIABLES", + /* 230 */ "cmd ::= SHOW LOCAL VARIABLES", + /* 231 */ "cmd ::= SHOW DNODE NK_INTEGER VARIABLES like_pattern_opt", + /* 232 */ "cmd ::= SHOW BNODES", + /* 233 */ "cmd ::= SHOW SNODES", + /* 234 */ "cmd ::= SHOW CLUSTER", + /* 235 */ "cmd ::= SHOW TRANSACTIONS", + /* 236 */ "cmd ::= SHOW TABLE DISTRIBUTED full_table_name", + /* 237 */ "cmd ::= SHOW CONSUMERS", + /* 238 */ "cmd ::= SHOW SUBSCRIPTIONS", + /* 239 */ "cmd ::= SHOW TAGS FROM table_name_cond from_db_opt", + /* 240 */ "cmd ::= SHOW TABLE TAGS FROM table_name_cond from_db_opt", + /* 241 */ "cmd ::= SHOW VNODES NK_INTEGER", + /* 242 */ "cmd ::= SHOW VNODES NK_STRING", + /* 243 */ "db_name_cond_opt ::=", + /* 244 */ "db_name_cond_opt ::= db_name NK_DOT", + /* 245 */ "like_pattern_opt ::=", + /* 246 */ "like_pattern_opt ::= LIKE NK_STRING", + /* 247 */ "table_name_cond ::= table_name", + /* 248 */ "from_db_opt ::=", + /* 249 */ "from_db_opt ::= FROM db_name", + /* 250 */ "cmd ::= CREATE SMA INDEX not_exists_opt full_table_name ON full_table_name index_options", + /* 251 */ "cmd ::= DROP INDEX exists_opt full_table_name", + /* 252 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt", + /* 253 */ "index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt", + /* 254 */ "func_list ::= func", + /* 255 */ "func_list ::= func_list NK_COMMA func", + /* 256 */ "func ::= function_name NK_LP expression_list NK_RP", + /* 257 */ "sma_stream_opt ::=", + /* 258 */ "sma_stream_opt ::= stream_options WATERMARK duration_literal", + /* 259 */ "sma_stream_opt ::= stream_options MAX_DELAY duration_literal", + /* 260 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_or_subquery", + /* 261 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name", + /* 262 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name", + /* 263 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name", + /* 264 */ "cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name", + /* 265 */ "cmd ::= DROP TOPIC exists_opt topic_name", + /* 266 */ "cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name", + /* 267 */ "cmd ::= DESC full_table_name", + /* 268 */ "cmd ::= DESCRIBE full_table_name", + /* 269 */ "cmd ::= RESET QUERY CACHE", + /* 270 */ "cmd ::= EXPLAIN analyze_opt explain_options query_or_subquery", + /* 271 */ "analyze_opt ::=", + /* 272 */ "analyze_opt ::= ANALYZE", + /* 273 */ "explain_options ::=", + /* 274 */ "explain_options ::= explain_options VERBOSE NK_BOOL", + /* 275 */ "explain_options ::= explain_options RATIO NK_FLOAT", + /* 276 */ "cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt", + /* 277 */ "cmd ::= DROP FUNCTION exists_opt function_name", + /* 278 */ "agg_func_opt ::=", + /* 279 */ "agg_func_opt ::= AGGREGATE", + /* 280 */ "bufsize_opt ::=", + /* 281 */ "bufsize_opt ::= BUFSIZE NK_INTEGER", + /* 282 */ "cmd ::= CREATE STREAM not_exists_opt stream_name stream_options INTO full_table_name tags_def_opt subtable_opt AS query_or_subquery", + /* 283 */ "cmd ::= DROP STREAM exists_opt stream_name", + /* 284 */ "stream_options ::=", + /* 285 */ "stream_options ::= stream_options TRIGGER AT_ONCE", + /* 286 */ "stream_options ::= stream_options TRIGGER WINDOW_CLOSE", + /* 287 */ "stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal", + /* 288 */ "stream_options ::= stream_options WATERMARK duration_literal", + /* 289 */ "stream_options ::= stream_options IGNORE EXPIRED NK_INTEGER", + /* 290 */ "stream_options ::= stream_options FILL_HISTORY NK_INTEGER", + /* 291 */ "subtable_opt ::=", + /* 292 */ "subtable_opt ::= SUBTABLE NK_LP expression NK_RP", + /* 293 */ "cmd ::= KILL CONNECTION NK_INTEGER", + /* 294 */ "cmd ::= KILL QUERY NK_STRING", + /* 295 */ "cmd ::= KILL TRANSACTION NK_INTEGER", + /* 296 */ "cmd ::= BALANCE VGROUP", + /* 297 */ "cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER", + /* 298 */ "cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list", + /* 299 */ "cmd ::= SPLIT VGROUP NK_INTEGER", + /* 300 */ "dnode_list ::= DNODE NK_INTEGER", + /* 301 */ "dnode_list ::= dnode_list DNODE NK_INTEGER", + /* 302 */ "cmd ::= DELETE FROM full_table_name where_clause_opt", + /* 303 */ "cmd ::= query_or_subquery", + /* 304 */ "cmd ::= INSERT INTO full_table_name NK_LP col_name_list NK_RP query_or_subquery", + /* 305 */ "cmd ::= INSERT INTO full_table_name query_or_subquery", + /* 306 */ "literal ::= NK_INTEGER", + /* 307 */ "literal ::= NK_FLOAT", + /* 308 */ "literal ::= NK_STRING", + /* 309 */ "literal ::= NK_BOOL", + /* 310 */ "literal ::= TIMESTAMP NK_STRING", + /* 311 */ "literal ::= duration_literal", + /* 312 */ "literal ::= NULL", + /* 313 */ "literal ::= NK_QUESTION", + /* 314 */ "duration_literal ::= NK_VARIABLE", + /* 315 */ "signed ::= NK_INTEGER", + /* 316 */ "signed ::= NK_PLUS NK_INTEGER", + /* 317 */ "signed ::= NK_MINUS NK_INTEGER", + /* 318 */ "signed ::= NK_FLOAT", + /* 319 */ "signed ::= NK_PLUS NK_FLOAT", + /* 320 */ "signed ::= NK_MINUS NK_FLOAT", + /* 321 */ "signed_literal ::= signed", + /* 322 */ "signed_literal ::= NK_STRING", + /* 323 */ "signed_literal ::= NK_BOOL", + /* 324 */ "signed_literal ::= TIMESTAMP NK_STRING", + /* 325 */ "signed_literal ::= duration_literal", + /* 326 */ "signed_literal ::= NULL", + /* 327 */ "signed_literal ::= literal_func", + /* 328 */ "signed_literal ::= NK_QUESTION", + /* 329 */ "literal_list ::= signed_literal", + /* 330 */ "literal_list ::= literal_list NK_COMMA signed_literal", + /* 331 */ "db_name ::= NK_ID", + /* 332 */ "table_name ::= NK_ID", + /* 333 */ "column_name ::= NK_ID", + /* 334 */ "function_name ::= NK_ID", + /* 335 */ "table_alias ::= NK_ID", + /* 336 */ "column_alias ::= NK_ID", + /* 337 */ "user_name ::= NK_ID", + /* 338 */ "topic_name ::= NK_ID", + /* 339 */ "stream_name ::= NK_ID", + /* 340 */ "cgroup_name ::= NK_ID", + /* 341 */ "expr_or_subquery ::= expression", + /* 342 */ "expr_or_subquery ::= subquery", + /* 343 */ "expression ::= literal", + /* 344 */ "expression ::= pseudo_column", + /* 345 */ "expression ::= column_reference", + /* 346 */ "expression ::= function_expression", + /* 347 */ "expression ::= case_when_expression", + /* 348 */ "expression ::= NK_LP expression NK_RP", + /* 349 */ "expression ::= NK_PLUS expr_or_subquery", + /* 350 */ "expression ::= NK_MINUS expr_or_subquery", + /* 351 */ "expression ::= expr_or_subquery NK_PLUS expr_or_subquery", + /* 352 */ "expression ::= expr_or_subquery NK_MINUS expr_or_subquery", + /* 353 */ "expression ::= expr_or_subquery NK_STAR expr_or_subquery", + /* 354 */ "expression ::= expr_or_subquery NK_SLASH expr_or_subquery", + /* 355 */ "expression ::= expr_or_subquery NK_REM expr_or_subquery", + /* 356 */ "expression ::= column_reference NK_ARROW NK_STRING", + /* 357 */ "expression ::= expr_or_subquery NK_BITAND expr_or_subquery", + /* 358 */ "expression ::= expr_or_subquery NK_BITOR expr_or_subquery", + /* 359 */ "expression_list ::= expr_or_subquery", + /* 360 */ "expression_list ::= expression_list NK_COMMA expr_or_subquery", + /* 361 */ "column_reference ::= column_name", + /* 362 */ "column_reference ::= table_name NK_DOT column_name", + /* 363 */ "pseudo_column ::= ROWTS", + /* 364 */ "pseudo_column ::= TBNAME", + /* 365 */ "pseudo_column ::= table_name NK_DOT TBNAME", + /* 366 */ "pseudo_column ::= QSTART", + /* 367 */ "pseudo_column ::= QEND", + /* 368 */ "pseudo_column ::= QDURATION", + /* 369 */ "pseudo_column ::= WSTART", + /* 370 */ "pseudo_column ::= WEND", + /* 371 */ "pseudo_column ::= WDURATION", + /* 372 */ "pseudo_column ::= IROWTS", + /* 373 */ "pseudo_column ::= QTAGS", + /* 374 */ "function_expression ::= function_name NK_LP expression_list NK_RP", + /* 375 */ "function_expression ::= star_func NK_LP star_func_para_list NK_RP", + /* 376 */ "function_expression ::= CAST NK_LP expr_or_subquery AS type_name NK_RP", + /* 377 */ "function_expression ::= literal_func", + /* 378 */ "literal_func ::= noarg_func NK_LP NK_RP", + /* 379 */ "literal_func ::= NOW", + /* 380 */ "noarg_func ::= NOW", + /* 381 */ "noarg_func ::= TODAY", + /* 382 */ "noarg_func ::= TIMEZONE", + /* 383 */ "noarg_func ::= DATABASE", + /* 384 */ "noarg_func ::= CLIENT_VERSION", + /* 385 */ "noarg_func ::= SERVER_VERSION", + /* 386 */ "noarg_func ::= SERVER_STATUS", + /* 387 */ "noarg_func ::= CURRENT_USER", + /* 388 */ "noarg_func ::= USER", + /* 389 */ "star_func ::= COUNT", + /* 390 */ "star_func ::= FIRST", + /* 391 */ "star_func ::= LAST", + /* 392 */ "star_func ::= LAST_ROW", + /* 393 */ "star_func_para_list ::= NK_STAR", + /* 394 */ "star_func_para_list ::= other_para_list", + /* 395 */ "other_para_list ::= star_func_para", + /* 396 */ "other_para_list ::= other_para_list NK_COMMA star_func_para", + /* 397 */ "star_func_para ::= expr_or_subquery", + /* 398 */ "star_func_para ::= table_name NK_DOT NK_STAR", + /* 399 */ "case_when_expression ::= CASE when_then_list case_when_else_opt END", + /* 400 */ "case_when_expression ::= CASE common_expression when_then_list case_when_else_opt END", + /* 401 */ "when_then_list ::= when_then_expr", + /* 402 */ "when_then_list ::= when_then_list when_then_expr", + /* 403 */ "when_then_expr ::= WHEN common_expression THEN common_expression", + /* 404 */ "case_when_else_opt ::=", + /* 405 */ "case_when_else_opt ::= ELSE common_expression", + /* 406 */ "predicate ::= expr_or_subquery compare_op expr_or_subquery", + /* 407 */ "predicate ::= expr_or_subquery BETWEEN expr_or_subquery AND expr_or_subquery", + /* 408 */ "predicate ::= expr_or_subquery NOT BETWEEN expr_or_subquery AND expr_or_subquery", + /* 409 */ "predicate ::= expr_or_subquery IS NULL", + /* 410 */ "predicate ::= expr_or_subquery IS NOT NULL", + /* 411 */ "predicate ::= expr_or_subquery in_op in_predicate_value", + /* 412 */ "compare_op ::= NK_LT", + /* 413 */ "compare_op ::= NK_GT", + /* 414 */ "compare_op ::= NK_LE", + /* 415 */ "compare_op ::= NK_GE", + /* 416 */ "compare_op ::= NK_NE", + /* 417 */ "compare_op ::= NK_EQ", + /* 418 */ "compare_op ::= LIKE", + /* 419 */ "compare_op ::= NOT LIKE", + /* 420 */ "compare_op ::= MATCH", + /* 421 */ "compare_op ::= NMATCH", + /* 422 */ "compare_op ::= CONTAINS", + /* 423 */ "in_op ::= IN", + /* 424 */ "in_op ::= NOT IN", + /* 425 */ "in_predicate_value ::= NK_LP literal_list NK_RP", + /* 426 */ "boolean_value_expression ::= boolean_primary", + /* 427 */ "boolean_value_expression ::= NOT boolean_primary", + /* 428 */ "boolean_value_expression ::= boolean_value_expression OR boolean_value_expression", + /* 429 */ "boolean_value_expression ::= boolean_value_expression AND boolean_value_expression", + /* 430 */ "boolean_primary ::= predicate", + /* 431 */ "boolean_primary ::= NK_LP boolean_value_expression NK_RP", + /* 432 */ "common_expression ::= expr_or_subquery", + /* 433 */ "common_expression ::= boolean_value_expression", + /* 434 */ "from_clause_opt ::=", + /* 435 */ "from_clause_opt ::= FROM table_reference_list", + /* 436 */ "table_reference_list ::= table_reference", + /* 437 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", + /* 438 */ "table_reference ::= table_primary", + /* 439 */ "table_reference ::= joined_table", + /* 440 */ "table_primary ::= table_name alias_opt", + /* 441 */ "table_primary ::= db_name NK_DOT table_name alias_opt", + /* 442 */ "table_primary ::= subquery alias_opt", + /* 443 */ "table_primary ::= parenthesized_joined_table", + /* 444 */ "alias_opt ::=", + /* 445 */ "alias_opt ::= table_alias", + /* 446 */ "alias_opt ::= AS table_alias", + /* 447 */ "parenthesized_joined_table ::= NK_LP joined_table NK_RP", + /* 448 */ "parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP", + /* 449 */ "joined_table ::= table_reference join_type JOIN table_reference ON search_condition", + /* 450 */ "join_type ::=", + /* 451 */ "join_type ::= INNER", + /* 452 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt", + /* 453 */ "set_quantifier_opt ::=", + /* 454 */ "set_quantifier_opt ::= DISTINCT", + /* 455 */ "set_quantifier_opt ::= ALL", + /* 456 */ "select_list ::= select_item", + /* 457 */ "select_list ::= select_list NK_COMMA select_item", + /* 458 */ "select_item ::= NK_STAR", + /* 459 */ "select_item ::= common_expression", + /* 460 */ "select_item ::= common_expression column_alias", + /* 461 */ "select_item ::= common_expression AS column_alias", + /* 462 */ "select_item ::= table_name NK_DOT NK_STAR", + /* 463 */ "where_clause_opt ::=", + /* 464 */ "where_clause_opt ::= WHERE search_condition", + /* 465 */ "partition_by_clause_opt ::=", + /* 466 */ "partition_by_clause_opt ::= PARTITION BY partition_list", + /* 467 */ "partition_list ::= partition_item", + /* 468 */ "partition_list ::= partition_list NK_COMMA partition_item", + /* 469 */ "partition_item ::= expr_or_subquery", + /* 470 */ "partition_item ::= expr_or_subquery column_alias", + /* 471 */ "partition_item ::= expr_or_subquery AS column_alias", + /* 472 */ "twindow_clause_opt ::=", + /* 473 */ "twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP", + /* 474 */ "twindow_clause_opt ::= STATE_WINDOW NK_LP expr_or_subquery NK_RP", + /* 475 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt", + /* 476 */ "twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt", + /* 477 */ "sliding_opt ::=", + /* 478 */ "sliding_opt ::= SLIDING NK_LP duration_literal NK_RP", + /* 479 */ "fill_opt ::=", + /* 480 */ "fill_opt ::= FILL NK_LP fill_mode NK_RP", + /* 481 */ "fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP", + /* 482 */ "fill_mode ::= NONE", + /* 483 */ "fill_mode ::= PREV", + /* 484 */ "fill_mode ::= NULL", + /* 485 */ "fill_mode ::= LINEAR", + /* 486 */ "fill_mode ::= NEXT", + /* 487 */ "group_by_clause_opt ::=", + /* 488 */ "group_by_clause_opt ::= GROUP BY group_by_list", + /* 489 */ "group_by_list ::= expr_or_subquery", + /* 490 */ "group_by_list ::= group_by_list NK_COMMA expr_or_subquery", + /* 491 */ "having_clause_opt ::=", + /* 492 */ "having_clause_opt ::= HAVING search_condition", + /* 493 */ "range_opt ::=", + /* 494 */ "range_opt ::= RANGE NK_LP expr_or_subquery NK_COMMA expr_or_subquery NK_RP", + /* 495 */ "every_opt ::=", + /* 496 */ "every_opt ::= EVERY NK_LP duration_literal NK_RP", + /* 497 */ "query_expression ::= query_simple order_by_clause_opt slimit_clause_opt limit_clause_opt", + /* 498 */ "query_simple ::= query_specification", + /* 499 */ "query_simple ::= union_query_expression", + /* 500 */ "union_query_expression ::= query_simple_or_subquery UNION ALL query_simple_or_subquery", + /* 501 */ "union_query_expression ::= query_simple_or_subquery UNION query_simple_or_subquery", + /* 502 */ "query_simple_or_subquery ::= query_simple", + /* 503 */ "query_simple_or_subquery ::= subquery", + /* 504 */ "query_or_subquery ::= query_expression", + /* 505 */ "query_or_subquery ::= subquery", + /* 506 */ "order_by_clause_opt ::=", + /* 507 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", + /* 508 */ "slimit_clause_opt ::=", + /* 509 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER", + /* 510 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER", + /* 511 */ "slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 512 */ "limit_clause_opt ::=", + /* 513 */ "limit_clause_opt ::= LIMIT NK_INTEGER", + /* 514 */ "limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER", + /* 515 */ "limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER", + /* 516 */ "subquery ::= NK_LP query_expression NK_RP", + /* 517 */ "subquery ::= NK_LP subquery NK_RP", + /* 518 */ "search_condition ::= common_expression", + /* 519 */ "sort_specification_list ::= sort_specification", + /* 520 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", + /* 521 */ "sort_specification ::= expr_or_subquery ordering_specification_opt null_ordering_opt", + /* 522 */ "ordering_specification_opt ::=", + /* 523 */ "ordering_specification_opt ::= ASC", + /* 524 */ "ordering_specification_opt ::= DESC", + /* 525 */ "null_ordering_opt ::=", + /* 526 */ "null_ordering_opt ::= NULLS FIRST", + /* 527 */ "null_ordering_opt ::= NULLS LAST", }; #endif /* NDEBUG */ @@ -2495,190 +2609,191 @@ static void yy_destructor( */ /********* Begin destructor definitions ***************************************/ /* Default NON-TERMINAL Destructor */ - case 317: /* cmd */ - case 320: /* literal */ - case 331: /* db_options */ - case 333: /* alter_db_options */ - case 339: /* retention */ - case 340: /* full_table_name */ - case 343: /* table_options */ - case 347: /* alter_table_clause */ - case 348: /* alter_table_options */ - case 351: /* signed_literal */ - case 352: /* create_subtable_clause */ - case 355: /* drop_table_clause */ - case 358: /* column_def */ - case 362: /* duration_literal */ - case 363: /* rollup_func_name */ - case 365: /* col_name */ - case 366: /* db_name_cond_opt */ - case 367: /* like_pattern_opt */ - case 368: /* table_name_cond */ - case 369: /* from_db_opt */ - case 370: /* index_options */ - case 372: /* sliding_opt */ - case 373: /* sma_stream_opt */ - case 374: /* func */ - case 375: /* stream_options */ - case 377: /* query_or_subquery */ - case 380: /* explain_options */ - case 384: /* subtable_opt */ - case 385: /* expression */ - case 387: /* where_clause_opt */ - case 388: /* signed */ - case 389: /* literal_func */ - case 393: /* expr_or_subquery */ - case 394: /* subquery */ - case 395: /* pseudo_column */ - case 396: /* column_reference */ - case 397: /* function_expression */ - case 398: /* case_when_expression */ - case 403: /* star_func_para */ - case 405: /* case_when_else_opt */ - case 406: /* common_expression */ - case 407: /* when_then_expr */ - case 408: /* predicate */ - case 411: /* in_predicate_value */ - case 412: /* boolean_value_expression */ - case 413: /* boolean_primary */ - case 414: /* from_clause_opt */ - case 415: /* table_reference_list */ - case 416: /* table_reference */ - case 417: /* table_primary */ - case 418: /* joined_table */ - case 420: /* parenthesized_joined_table */ - case 422: /* search_condition */ - case 423: /* query_specification */ - case 427: /* range_opt */ - case 428: /* every_opt */ - case 429: /* fill_opt */ - case 430: /* twindow_clause_opt */ - case 432: /* having_clause_opt */ - case 433: /* select_item */ - case 435: /* partition_item */ - case 438: /* query_expression */ - case 439: /* query_simple */ - case 441: /* slimit_clause_opt */ - case 442: /* limit_clause_opt */ - case 443: /* union_query_expression */ - case 444: /* query_simple_or_subquery */ - case 446: /* sort_specification */ + case 319: /* cmd */ + case 322: /* literal */ + case 334: /* db_options */ + case 336: /* alter_db_options */ + case 342: /* retention */ + case 343: /* full_table_name */ + case 346: /* table_options */ + case 350: /* alter_table_clause */ + case 351: /* alter_table_options */ + case 354: /* signed_literal */ + case 355: /* create_subtable_clause */ + case 358: /* drop_table_clause */ + case 361: /* column_def */ + case 365: /* duration_literal */ + case 366: /* rollup_func_name */ + case 368: /* col_name */ + case 369: /* db_name_cond_opt */ + case 370: /* like_pattern_opt */ + case 371: /* table_name_cond */ + case 372: /* from_db_opt */ + case 373: /* index_options */ + case 375: /* sliding_opt */ + case 376: /* sma_stream_opt */ + case 377: /* func */ + case 378: /* stream_options */ + case 380: /* query_or_subquery */ + case 383: /* explain_options */ + case 387: /* subtable_opt */ + case 388: /* expression */ + case 390: /* where_clause_opt */ + case 391: /* signed */ + case 392: /* literal_func */ + case 396: /* expr_or_subquery */ + case 397: /* subquery */ + case 398: /* pseudo_column */ + case 399: /* column_reference */ + case 400: /* function_expression */ + case 401: /* case_when_expression */ + case 406: /* star_func_para */ + case 408: /* case_when_else_opt */ + case 409: /* common_expression */ + case 410: /* when_then_expr */ + case 411: /* predicate */ + case 414: /* in_predicate_value */ + case 415: /* boolean_value_expression */ + case 416: /* boolean_primary */ + case 417: /* from_clause_opt */ + case 418: /* table_reference_list */ + case 419: /* table_reference */ + case 420: /* table_primary */ + case 421: /* joined_table */ + case 423: /* parenthesized_joined_table */ + case 425: /* search_condition */ + case 426: /* query_specification */ + case 430: /* range_opt */ + case 431: /* every_opt */ + case 432: /* fill_opt */ + case 433: /* twindow_clause_opt */ + case 435: /* having_clause_opt */ + case 436: /* select_item */ + case 438: /* partition_item */ + case 441: /* query_expression */ + case 442: /* query_simple */ + case 444: /* slimit_clause_opt */ + case 445: /* limit_clause_opt */ + case 446: /* union_query_expression */ + case 447: /* query_simple_or_subquery */ + case 449: /* sort_specification */ { - nodesDestroyNode((yypminor->yy778)); + nodesDestroyNode((yypminor->yy232)); } break; - case 318: /* account_options */ - case 319: /* alter_account_options */ - case 321: /* alter_account_option */ - case 334: /* speed_opt */ - case 382: /* bufsize_opt */ + case 320: /* account_options */ + case 321: /* alter_account_options */ + case 323: /* alter_account_option */ + case 337: /* speed_opt */ + case 385: /* bufsize_opt */ { } break; - case 322: /* user_name */ - case 325: /* priv_level */ - case 328: /* db_name */ - case 329: /* dnode_endpoint */ - case 349: /* column_name */ - case 357: /* table_name */ - case 364: /* function_name */ - case 376: /* topic_name */ - case 378: /* cgroup_name */ - case 383: /* stream_name */ - case 391: /* table_alias */ - case 392: /* column_alias */ - case 399: /* star_func */ - case 401: /* noarg_func */ - case 419: /* alias_opt */ + case 324: /* user_name */ + case 327: /* priv_level */ + case 330: /* db_name */ + case 331: /* dnode_endpoint */ + case 352: /* column_name */ + case 360: /* table_name */ + case 367: /* function_name */ + case 379: /* topic_name */ + case 381: /* cgroup_name */ + case 386: /* stream_name */ + case 394: /* table_alias */ + case 395: /* column_alias */ + case 402: /* star_func */ + case 404: /* noarg_func */ + case 422: /* alias_opt */ { } break; - case 323: /* sysinfo_opt */ + case 325: /* sysinfo_opt */ { } break; - case 324: /* privileges */ - case 326: /* priv_type_list */ - case 327: /* priv_type */ + case 326: /* privileges */ + case 328: /* priv_type_list */ + case 329: /* priv_type */ { } break; - case 330: /* not_exists_opt */ - case 332: /* exists_opt */ - case 379: /* analyze_opt */ - case 381: /* agg_func_opt */ - case 424: /* set_quantifier_opt */ + case 332: /* force_opt */ + case 333: /* not_exists_opt */ + case 335: /* exists_opt */ + case 382: /* analyze_opt */ + case 384: /* agg_func_opt */ + case 427: /* set_quantifier_opt */ { } break; - case 335: /* integer_list */ - case 336: /* variable_list */ - case 337: /* retention_list */ - case 341: /* column_def_list */ - case 342: /* tags_def_opt */ - case 344: /* multi_create_clause */ - case 345: /* tags_def */ - case 346: /* multi_drop_clause */ - case 353: /* specific_cols_opt */ - case 354: /* expression_list */ - case 356: /* col_name_list */ - case 359: /* duration_list */ - case 360: /* rollup_func_list */ - case 371: /* func_list */ - case 386: /* dnode_list */ - case 390: /* literal_list */ - case 400: /* star_func_para_list */ - case 402: /* other_para_list */ - case 404: /* when_then_list */ - case 425: /* select_list */ - case 426: /* partition_by_clause_opt */ - case 431: /* group_by_clause_opt */ - case 434: /* partition_list */ - case 437: /* group_by_list */ - case 440: /* order_by_clause_opt */ - case 445: /* sort_specification_list */ + case 338: /* integer_list */ + case 339: /* variable_list */ + case 340: /* retention_list */ + case 344: /* column_def_list */ + case 345: /* tags_def_opt */ + case 347: /* multi_create_clause */ + case 348: /* tags_def */ + case 349: /* multi_drop_clause */ + case 356: /* specific_cols_opt */ + case 357: /* expression_list */ + case 359: /* col_name_list */ + case 362: /* duration_list */ + case 363: /* rollup_func_list */ + case 374: /* func_list */ + case 389: /* dnode_list */ + case 393: /* literal_list */ + case 403: /* star_func_para_list */ + case 405: /* other_para_list */ + case 407: /* when_then_list */ + case 428: /* select_list */ + case 429: /* partition_by_clause_opt */ + case 434: /* group_by_clause_opt */ + case 437: /* partition_list */ + case 440: /* group_by_list */ + case 443: /* order_by_clause_opt */ + case 448: /* sort_specification_list */ { - nodesDestroyList((yypminor->yy282)); + nodesDestroyList((yypminor->yy288)); } break; - case 338: /* alter_db_option */ - case 361: /* alter_table_option */ + case 341: /* alter_db_option */ + case 364: /* alter_table_option */ { } break; - case 350: /* type_name */ + case 353: /* type_name */ { } break; - case 409: /* compare_op */ - case 410: /* in_op */ + case 412: /* compare_op */ + case 413: /* in_op */ { } break; - case 421: /* join_type */ + case 424: /* join_type */ { } break; - case 436: /* fill_mode */ + case 439: /* fill_mode */ { } break; - case 447: /* ordering_specification_opt */ + case 450: /* ordering_specification_opt */ { } break; - case 448: /* null_ordering_opt */ + case 451: /* null_ordering_opt */ { } @@ -2977,531 +3092,534 @@ 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[] = { - { 317, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ - { 317, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ - { 318, 0 }, /* (2) account_options ::= */ - { 318, -3 }, /* (3) account_options ::= account_options PPS literal */ - { 318, -3 }, /* (4) account_options ::= account_options TSERIES literal */ - { 318, -3 }, /* (5) account_options ::= account_options STORAGE literal */ - { 318, -3 }, /* (6) account_options ::= account_options STREAMS literal */ - { 318, -3 }, /* (7) account_options ::= account_options QTIME literal */ - { 318, -3 }, /* (8) account_options ::= account_options DBS literal */ - { 318, -3 }, /* (9) account_options ::= account_options USERS literal */ - { 318, -3 }, /* (10) account_options ::= account_options CONNS literal */ - { 318, -3 }, /* (11) account_options ::= account_options STATE literal */ - { 319, -1 }, /* (12) alter_account_options ::= alter_account_option */ - { 319, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ - { 321, -2 }, /* (14) alter_account_option ::= PASS literal */ - { 321, -2 }, /* (15) alter_account_option ::= PPS literal */ - { 321, -2 }, /* (16) alter_account_option ::= TSERIES literal */ - { 321, -2 }, /* (17) alter_account_option ::= STORAGE literal */ - { 321, -2 }, /* (18) alter_account_option ::= STREAMS literal */ - { 321, -2 }, /* (19) alter_account_option ::= QTIME literal */ - { 321, -2 }, /* (20) alter_account_option ::= DBS literal */ - { 321, -2 }, /* (21) alter_account_option ::= USERS literal */ - { 321, -2 }, /* (22) alter_account_option ::= CONNS literal */ - { 321, -2 }, /* (23) alter_account_option ::= STATE literal */ - { 317, -6 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING sysinfo_opt */ - { 317, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ - { 317, -5 }, /* (26) cmd ::= ALTER USER user_name ENABLE NK_INTEGER */ - { 317, -5 }, /* (27) cmd ::= ALTER USER user_name SYSINFO NK_INTEGER */ - { 317, -3 }, /* (28) cmd ::= DROP USER user_name */ - { 323, 0 }, /* (29) sysinfo_opt ::= */ - { 323, -2 }, /* (30) sysinfo_opt ::= SYSINFO NK_INTEGER */ - { 317, -6 }, /* (31) cmd ::= GRANT privileges ON priv_level TO user_name */ - { 317, -6 }, /* (32) cmd ::= REVOKE privileges ON priv_level FROM user_name */ - { 324, -1 }, /* (33) privileges ::= ALL */ - { 324, -1 }, /* (34) privileges ::= priv_type_list */ - { 326, -1 }, /* (35) priv_type_list ::= priv_type */ - { 326, -3 }, /* (36) priv_type_list ::= priv_type_list NK_COMMA priv_type */ - { 327, -1 }, /* (37) priv_type ::= READ */ - { 327, -1 }, /* (38) priv_type ::= WRITE */ - { 325, -3 }, /* (39) priv_level ::= NK_STAR NK_DOT NK_STAR */ - { 325, -3 }, /* (40) priv_level ::= db_name NK_DOT NK_STAR */ - { 317, -3 }, /* (41) cmd ::= CREATE DNODE dnode_endpoint */ - { 317, -5 }, /* (42) cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER */ - { 317, -3 }, /* (43) cmd ::= DROP DNODE NK_INTEGER */ - { 317, -3 }, /* (44) cmd ::= DROP DNODE dnode_endpoint */ - { 317, -4 }, /* (45) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ - { 317, -5 }, /* (46) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ - { 317, -4 }, /* (47) cmd ::= ALTER ALL DNODES NK_STRING */ - { 317, -5 }, /* (48) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ - { 329, -1 }, /* (49) dnode_endpoint ::= NK_STRING */ - { 329, -1 }, /* (50) dnode_endpoint ::= NK_ID */ - { 329, -1 }, /* (51) dnode_endpoint ::= NK_IPTOKEN */ - { 317, -3 }, /* (52) cmd ::= ALTER LOCAL NK_STRING */ - { 317, -4 }, /* (53) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ - { 317, -5 }, /* (54) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ - { 317, -5 }, /* (55) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ - { 317, -5 }, /* (56) cmd ::= CREATE BNODE ON DNODE NK_INTEGER */ - { 317, -5 }, /* (57) cmd ::= DROP BNODE ON DNODE NK_INTEGER */ - { 317, -5 }, /* (58) cmd ::= CREATE SNODE ON DNODE NK_INTEGER */ - { 317, -5 }, /* (59) cmd ::= DROP SNODE ON DNODE NK_INTEGER */ - { 317, -5 }, /* (60) cmd ::= CREATE MNODE ON DNODE NK_INTEGER */ - { 317, -5 }, /* (61) cmd ::= DROP MNODE ON DNODE NK_INTEGER */ - { 317, -5 }, /* (62) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ - { 317, -4 }, /* (63) cmd ::= DROP DATABASE exists_opt db_name */ - { 317, -2 }, /* (64) cmd ::= USE db_name */ - { 317, -4 }, /* (65) cmd ::= ALTER DATABASE db_name alter_db_options */ - { 317, -3 }, /* (66) cmd ::= FLUSH DATABASE db_name */ - { 317, -4 }, /* (67) cmd ::= TRIM DATABASE db_name speed_opt */ - { 330, -3 }, /* (68) not_exists_opt ::= IF NOT EXISTS */ - { 330, 0 }, /* (69) not_exists_opt ::= */ - { 332, -2 }, /* (70) exists_opt ::= IF EXISTS */ - { 332, 0 }, /* (71) exists_opt ::= */ - { 331, 0 }, /* (72) db_options ::= */ - { 331, -3 }, /* (73) db_options ::= db_options BUFFER NK_INTEGER */ - { 331, -3 }, /* (74) db_options ::= db_options CACHEMODEL NK_STRING */ - { 331, -3 }, /* (75) db_options ::= db_options CACHESIZE NK_INTEGER */ - { 331, -3 }, /* (76) db_options ::= db_options COMP NK_INTEGER */ - { 331, -3 }, /* (77) db_options ::= db_options DURATION NK_INTEGER */ - { 331, -3 }, /* (78) db_options ::= db_options DURATION NK_VARIABLE */ - { 331, -3 }, /* (79) db_options ::= db_options MAXROWS NK_INTEGER */ - { 331, -3 }, /* (80) db_options ::= db_options MINROWS NK_INTEGER */ - { 331, -3 }, /* (81) db_options ::= db_options KEEP integer_list */ - { 331, -3 }, /* (82) db_options ::= db_options KEEP variable_list */ - { 331, -3 }, /* (83) db_options ::= db_options PAGES NK_INTEGER */ - { 331, -3 }, /* (84) db_options ::= db_options PAGESIZE NK_INTEGER */ - { 331, -3 }, /* (85) db_options ::= db_options TSDB_PAGESIZE NK_INTEGER */ - { 331, -3 }, /* (86) db_options ::= db_options PRECISION NK_STRING */ - { 331, -3 }, /* (87) db_options ::= db_options REPLICA NK_INTEGER */ - { 331, -3 }, /* (88) db_options ::= db_options STRICT NK_STRING */ - { 331, -3 }, /* (89) db_options ::= db_options VGROUPS NK_INTEGER */ - { 331, -3 }, /* (90) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ - { 331, -3 }, /* (91) db_options ::= db_options RETENTIONS retention_list */ - { 331, -3 }, /* (92) db_options ::= db_options SCHEMALESS NK_INTEGER */ - { 331, -3 }, /* (93) db_options ::= db_options WAL_LEVEL NK_INTEGER */ - { 331, -3 }, /* (94) db_options ::= db_options WAL_FSYNC_PERIOD NK_INTEGER */ - { 331, -3 }, /* (95) db_options ::= db_options WAL_RETENTION_PERIOD NK_INTEGER */ - { 331, -4 }, /* (96) db_options ::= db_options WAL_RETENTION_PERIOD NK_MINUS NK_INTEGER */ - { 331, -3 }, /* (97) db_options ::= db_options WAL_RETENTION_SIZE NK_INTEGER */ - { 331, -4 }, /* (98) db_options ::= db_options WAL_RETENTION_SIZE NK_MINUS NK_INTEGER */ - { 331, -3 }, /* (99) db_options ::= db_options WAL_ROLL_PERIOD NK_INTEGER */ - { 331, -3 }, /* (100) db_options ::= db_options WAL_SEGMENT_SIZE NK_INTEGER */ - { 331, -3 }, /* (101) db_options ::= db_options STT_TRIGGER NK_INTEGER */ - { 331, -3 }, /* (102) db_options ::= db_options TABLE_PREFIX NK_INTEGER */ - { 331, -3 }, /* (103) db_options ::= db_options TABLE_SUFFIX NK_INTEGER */ - { 333, -1 }, /* (104) alter_db_options ::= alter_db_option */ - { 333, -2 }, /* (105) alter_db_options ::= alter_db_options alter_db_option */ - { 338, -2 }, /* (106) alter_db_option ::= BUFFER NK_INTEGER */ - { 338, -2 }, /* (107) alter_db_option ::= CACHEMODEL NK_STRING */ - { 338, -2 }, /* (108) alter_db_option ::= CACHESIZE NK_INTEGER */ - { 338, -2 }, /* (109) alter_db_option ::= WAL_FSYNC_PERIOD NK_INTEGER */ - { 338, -2 }, /* (110) alter_db_option ::= KEEP integer_list */ - { 338, -2 }, /* (111) alter_db_option ::= KEEP variable_list */ - { 338, -2 }, /* (112) alter_db_option ::= PAGES NK_INTEGER */ - { 338, -2 }, /* (113) alter_db_option ::= REPLICA NK_INTEGER */ - { 338, -2 }, /* (114) alter_db_option ::= STRICT NK_STRING */ - { 338, -2 }, /* (115) alter_db_option ::= WAL_LEVEL NK_INTEGER */ - { 338, -2 }, /* (116) alter_db_option ::= STT_TRIGGER NK_INTEGER */ - { 335, -1 }, /* (117) integer_list ::= NK_INTEGER */ - { 335, -3 }, /* (118) integer_list ::= integer_list NK_COMMA NK_INTEGER */ - { 336, -1 }, /* (119) variable_list ::= NK_VARIABLE */ - { 336, -3 }, /* (120) variable_list ::= variable_list NK_COMMA NK_VARIABLE */ - { 337, -1 }, /* (121) retention_list ::= retention */ - { 337, -3 }, /* (122) retention_list ::= retention_list NK_COMMA retention */ - { 339, -3 }, /* (123) retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ - { 334, 0 }, /* (124) speed_opt ::= */ - { 334, -2 }, /* (125) speed_opt ::= MAX_SPEED NK_INTEGER */ - { 317, -9 }, /* (126) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - { 317, -3 }, /* (127) cmd ::= CREATE TABLE multi_create_clause */ - { 317, -9 }, /* (128) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ - { 317, -3 }, /* (129) cmd ::= DROP TABLE multi_drop_clause */ - { 317, -4 }, /* (130) cmd ::= DROP STABLE exists_opt full_table_name */ - { 317, -3 }, /* (131) cmd ::= ALTER TABLE alter_table_clause */ - { 317, -3 }, /* (132) cmd ::= ALTER STABLE alter_table_clause */ - { 347, -2 }, /* (133) alter_table_clause ::= full_table_name alter_table_options */ - { 347, -5 }, /* (134) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ - { 347, -4 }, /* (135) alter_table_clause ::= full_table_name DROP COLUMN column_name */ - { 347, -5 }, /* (136) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ - { 347, -5 }, /* (137) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ - { 347, -5 }, /* (138) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ - { 347, -4 }, /* (139) alter_table_clause ::= full_table_name DROP TAG column_name */ - { 347, -5 }, /* (140) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ - { 347, -5 }, /* (141) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ - { 347, -6 }, /* (142) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ - { 344, -1 }, /* (143) multi_create_clause ::= create_subtable_clause */ - { 344, -2 }, /* (144) multi_create_clause ::= multi_create_clause create_subtable_clause */ - { 352, -10 }, /* (145) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options */ - { 346, -1 }, /* (146) multi_drop_clause ::= drop_table_clause */ - { 346, -2 }, /* (147) multi_drop_clause ::= multi_drop_clause drop_table_clause */ - { 355, -2 }, /* (148) drop_table_clause ::= exists_opt full_table_name */ - { 353, 0 }, /* (149) specific_cols_opt ::= */ - { 353, -3 }, /* (150) specific_cols_opt ::= NK_LP col_name_list NK_RP */ - { 340, -1 }, /* (151) full_table_name ::= table_name */ - { 340, -3 }, /* (152) full_table_name ::= db_name NK_DOT table_name */ - { 341, -1 }, /* (153) column_def_list ::= column_def */ - { 341, -3 }, /* (154) column_def_list ::= column_def_list NK_COMMA column_def */ - { 358, -2 }, /* (155) column_def ::= column_name type_name */ - { 358, -4 }, /* (156) column_def ::= column_name type_name COMMENT NK_STRING */ - { 350, -1 }, /* (157) type_name ::= BOOL */ - { 350, -1 }, /* (158) type_name ::= TINYINT */ - { 350, -1 }, /* (159) type_name ::= SMALLINT */ - { 350, -1 }, /* (160) type_name ::= INT */ - { 350, -1 }, /* (161) type_name ::= INTEGER */ - { 350, -1 }, /* (162) type_name ::= BIGINT */ - { 350, -1 }, /* (163) type_name ::= FLOAT */ - { 350, -1 }, /* (164) type_name ::= DOUBLE */ - { 350, -4 }, /* (165) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ - { 350, -1 }, /* (166) type_name ::= TIMESTAMP */ - { 350, -4 }, /* (167) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ - { 350, -2 }, /* (168) type_name ::= TINYINT UNSIGNED */ - { 350, -2 }, /* (169) type_name ::= SMALLINT UNSIGNED */ - { 350, -2 }, /* (170) type_name ::= INT UNSIGNED */ - { 350, -2 }, /* (171) type_name ::= BIGINT UNSIGNED */ - { 350, -1 }, /* (172) type_name ::= JSON */ - { 350, -4 }, /* (173) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ - { 350, -1 }, /* (174) type_name ::= MEDIUMBLOB */ - { 350, -1 }, /* (175) type_name ::= BLOB */ - { 350, -4 }, /* (176) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ - { 350, -1 }, /* (177) type_name ::= DECIMAL */ - { 350, -4 }, /* (178) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ - { 350, -6 }, /* (179) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ - { 342, 0 }, /* (180) tags_def_opt ::= */ - { 342, -1 }, /* (181) tags_def_opt ::= tags_def */ - { 345, -4 }, /* (182) tags_def ::= TAGS NK_LP column_def_list NK_RP */ - { 343, 0 }, /* (183) table_options ::= */ - { 343, -3 }, /* (184) table_options ::= table_options COMMENT NK_STRING */ - { 343, -3 }, /* (185) table_options ::= table_options MAX_DELAY duration_list */ - { 343, -3 }, /* (186) table_options ::= table_options WATERMARK duration_list */ - { 343, -5 }, /* (187) table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ - { 343, -3 }, /* (188) table_options ::= table_options TTL NK_INTEGER */ - { 343, -5 }, /* (189) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ - { 348, -1 }, /* (190) alter_table_options ::= alter_table_option */ - { 348, -2 }, /* (191) alter_table_options ::= alter_table_options alter_table_option */ - { 361, -2 }, /* (192) alter_table_option ::= COMMENT NK_STRING */ - { 361, -2 }, /* (193) alter_table_option ::= TTL NK_INTEGER */ - { 359, -1 }, /* (194) duration_list ::= duration_literal */ - { 359, -3 }, /* (195) duration_list ::= duration_list NK_COMMA duration_literal */ - { 360, -1 }, /* (196) rollup_func_list ::= rollup_func_name */ - { 360, -3 }, /* (197) rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ - { 363, -1 }, /* (198) rollup_func_name ::= function_name */ - { 363, -1 }, /* (199) rollup_func_name ::= FIRST */ - { 363, -1 }, /* (200) rollup_func_name ::= LAST */ - { 356, -1 }, /* (201) col_name_list ::= col_name */ - { 356, -3 }, /* (202) col_name_list ::= col_name_list NK_COMMA col_name */ - { 365, -1 }, /* (203) col_name ::= column_name */ - { 317, -2 }, /* (204) cmd ::= SHOW DNODES */ - { 317, -2 }, /* (205) cmd ::= SHOW USERS */ - { 317, -2 }, /* (206) cmd ::= SHOW DATABASES */ - { 317, -4 }, /* (207) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ - { 317, -4 }, /* (208) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ - { 317, -3 }, /* (209) cmd ::= SHOW db_name_cond_opt VGROUPS */ - { 317, -2 }, /* (210) cmd ::= SHOW MNODES */ - { 317, -2 }, /* (211) cmd ::= SHOW QNODES */ - { 317, -2 }, /* (212) cmd ::= SHOW FUNCTIONS */ - { 317, -5 }, /* (213) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ - { 317, -2 }, /* (214) cmd ::= SHOW STREAMS */ - { 317, -2 }, /* (215) cmd ::= SHOW ACCOUNTS */ - { 317, -2 }, /* (216) cmd ::= SHOW APPS */ - { 317, -2 }, /* (217) cmd ::= SHOW CONNECTIONS */ - { 317, -2 }, /* (218) cmd ::= SHOW LICENCES */ - { 317, -2 }, /* (219) cmd ::= SHOW GRANTS */ - { 317, -4 }, /* (220) cmd ::= SHOW CREATE DATABASE db_name */ - { 317, -4 }, /* (221) cmd ::= SHOW CREATE TABLE full_table_name */ - { 317, -4 }, /* (222) cmd ::= SHOW CREATE STABLE full_table_name */ - { 317, -2 }, /* (223) cmd ::= SHOW QUERIES */ - { 317, -2 }, /* (224) cmd ::= SHOW SCORES */ - { 317, -2 }, /* (225) cmd ::= SHOW TOPICS */ - { 317, -2 }, /* (226) cmd ::= SHOW VARIABLES */ - { 317, -3 }, /* (227) cmd ::= SHOW CLUSTER VARIABLES */ - { 317, -3 }, /* (228) cmd ::= SHOW LOCAL VARIABLES */ - { 317, -5 }, /* (229) cmd ::= SHOW DNODE NK_INTEGER VARIABLES like_pattern_opt */ - { 317, -2 }, /* (230) cmd ::= SHOW BNODES */ - { 317, -2 }, /* (231) cmd ::= SHOW SNODES */ - { 317, -2 }, /* (232) cmd ::= SHOW CLUSTER */ - { 317, -2 }, /* (233) cmd ::= SHOW TRANSACTIONS */ - { 317, -4 }, /* (234) cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ - { 317, -2 }, /* (235) cmd ::= SHOW CONSUMERS */ - { 317, -2 }, /* (236) cmd ::= SHOW SUBSCRIPTIONS */ - { 317, -5 }, /* (237) cmd ::= SHOW TAGS FROM table_name_cond from_db_opt */ - { 317, -6 }, /* (238) cmd ::= SHOW TABLE TAGS FROM table_name_cond from_db_opt */ - { 317, -3 }, /* (239) cmd ::= SHOW VNODES NK_INTEGER */ - { 317, -3 }, /* (240) cmd ::= SHOW VNODES NK_STRING */ - { 366, 0 }, /* (241) db_name_cond_opt ::= */ - { 366, -2 }, /* (242) db_name_cond_opt ::= db_name NK_DOT */ - { 367, 0 }, /* (243) like_pattern_opt ::= */ - { 367, -2 }, /* (244) like_pattern_opt ::= LIKE NK_STRING */ - { 368, -1 }, /* (245) table_name_cond ::= table_name */ - { 369, 0 }, /* (246) from_db_opt ::= */ - { 369, -2 }, /* (247) from_db_opt ::= FROM db_name */ - { 317, -8 }, /* (248) cmd ::= CREATE SMA INDEX not_exists_opt full_table_name ON full_table_name index_options */ - { 317, -4 }, /* (249) cmd ::= DROP INDEX exists_opt full_table_name */ - { 370, -10 }, /* (250) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */ - { 370, -12 }, /* (251) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */ - { 371, -1 }, /* (252) func_list ::= func */ - { 371, -3 }, /* (253) func_list ::= func_list NK_COMMA func */ - { 374, -4 }, /* (254) func ::= function_name NK_LP expression_list NK_RP */ - { 373, 0 }, /* (255) sma_stream_opt ::= */ - { 373, -3 }, /* (256) sma_stream_opt ::= stream_options WATERMARK duration_literal */ - { 373, -3 }, /* (257) sma_stream_opt ::= stream_options MAX_DELAY duration_literal */ - { 317, -6 }, /* (258) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_or_subquery */ - { 317, -7 }, /* (259) cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ - { 317, -9 }, /* (260) cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */ - { 317, -7 }, /* (261) cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ - { 317, -9 }, /* (262) cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name */ - { 317, -4 }, /* (263) cmd ::= DROP TOPIC exists_opt topic_name */ - { 317, -7 }, /* (264) cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ - { 317, -2 }, /* (265) cmd ::= DESC full_table_name */ - { 317, -2 }, /* (266) cmd ::= DESCRIBE full_table_name */ - { 317, -3 }, /* (267) cmd ::= RESET QUERY CACHE */ - { 317, -4 }, /* (268) cmd ::= EXPLAIN analyze_opt explain_options query_or_subquery */ - { 379, 0 }, /* (269) analyze_opt ::= */ - { 379, -1 }, /* (270) analyze_opt ::= ANALYZE */ - { 380, 0 }, /* (271) explain_options ::= */ - { 380, -3 }, /* (272) explain_options ::= explain_options VERBOSE NK_BOOL */ - { 380, -3 }, /* (273) explain_options ::= explain_options RATIO NK_FLOAT */ - { 317, -10 }, /* (274) cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ - { 317, -4 }, /* (275) cmd ::= DROP FUNCTION exists_opt function_name */ - { 381, 0 }, /* (276) agg_func_opt ::= */ - { 381, -1 }, /* (277) agg_func_opt ::= AGGREGATE */ - { 382, 0 }, /* (278) bufsize_opt ::= */ - { 382, -2 }, /* (279) bufsize_opt ::= BUFSIZE NK_INTEGER */ - { 317, -11 }, /* (280) cmd ::= CREATE STREAM not_exists_opt stream_name stream_options INTO full_table_name tags_def_opt subtable_opt AS query_or_subquery */ - { 317, -4 }, /* (281) cmd ::= DROP STREAM exists_opt stream_name */ - { 375, 0 }, /* (282) stream_options ::= */ - { 375, -3 }, /* (283) stream_options ::= stream_options TRIGGER AT_ONCE */ - { 375, -3 }, /* (284) stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ - { 375, -4 }, /* (285) stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ - { 375, -3 }, /* (286) stream_options ::= stream_options WATERMARK duration_literal */ - { 375, -4 }, /* (287) stream_options ::= stream_options IGNORE EXPIRED NK_INTEGER */ - { 384, 0 }, /* (288) subtable_opt ::= */ - { 384, -4 }, /* (289) subtable_opt ::= SUBTABLE NK_LP expression NK_RP */ - { 317, -3 }, /* (290) cmd ::= KILL CONNECTION NK_INTEGER */ - { 317, -3 }, /* (291) cmd ::= KILL QUERY NK_STRING */ - { 317, -3 }, /* (292) cmd ::= KILL TRANSACTION NK_INTEGER */ - { 317, -2 }, /* (293) cmd ::= BALANCE VGROUP */ - { 317, -4 }, /* (294) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ - { 317, -4 }, /* (295) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ - { 317, -3 }, /* (296) cmd ::= SPLIT VGROUP NK_INTEGER */ - { 386, -2 }, /* (297) dnode_list ::= DNODE NK_INTEGER */ - { 386, -3 }, /* (298) dnode_list ::= dnode_list DNODE NK_INTEGER */ - { 317, -4 }, /* (299) cmd ::= DELETE FROM full_table_name where_clause_opt */ - { 317, -1 }, /* (300) cmd ::= query_or_subquery */ - { 317, -7 }, /* (301) cmd ::= INSERT INTO full_table_name NK_LP col_name_list NK_RP query_or_subquery */ - { 317, -4 }, /* (302) cmd ::= INSERT INTO full_table_name query_or_subquery */ - { 320, -1 }, /* (303) literal ::= NK_INTEGER */ - { 320, -1 }, /* (304) literal ::= NK_FLOAT */ - { 320, -1 }, /* (305) literal ::= NK_STRING */ - { 320, -1 }, /* (306) literal ::= NK_BOOL */ - { 320, -2 }, /* (307) literal ::= TIMESTAMP NK_STRING */ - { 320, -1 }, /* (308) literal ::= duration_literal */ - { 320, -1 }, /* (309) literal ::= NULL */ - { 320, -1 }, /* (310) literal ::= NK_QUESTION */ - { 362, -1 }, /* (311) duration_literal ::= NK_VARIABLE */ - { 388, -1 }, /* (312) signed ::= NK_INTEGER */ - { 388, -2 }, /* (313) signed ::= NK_PLUS NK_INTEGER */ - { 388, -2 }, /* (314) signed ::= NK_MINUS NK_INTEGER */ - { 388, -1 }, /* (315) signed ::= NK_FLOAT */ - { 388, -2 }, /* (316) signed ::= NK_PLUS NK_FLOAT */ - { 388, -2 }, /* (317) signed ::= NK_MINUS NK_FLOAT */ - { 351, -1 }, /* (318) signed_literal ::= signed */ - { 351, -1 }, /* (319) signed_literal ::= NK_STRING */ - { 351, -1 }, /* (320) signed_literal ::= NK_BOOL */ - { 351, -2 }, /* (321) signed_literal ::= TIMESTAMP NK_STRING */ - { 351, -1 }, /* (322) signed_literal ::= duration_literal */ - { 351, -1 }, /* (323) signed_literal ::= NULL */ - { 351, -1 }, /* (324) signed_literal ::= literal_func */ - { 351, -1 }, /* (325) signed_literal ::= NK_QUESTION */ - { 390, -1 }, /* (326) literal_list ::= signed_literal */ - { 390, -3 }, /* (327) literal_list ::= literal_list NK_COMMA signed_literal */ - { 328, -1 }, /* (328) db_name ::= NK_ID */ - { 357, -1 }, /* (329) table_name ::= NK_ID */ - { 349, -1 }, /* (330) column_name ::= NK_ID */ - { 364, -1 }, /* (331) function_name ::= NK_ID */ - { 391, -1 }, /* (332) table_alias ::= NK_ID */ - { 392, -1 }, /* (333) column_alias ::= NK_ID */ - { 322, -1 }, /* (334) user_name ::= NK_ID */ - { 376, -1 }, /* (335) topic_name ::= NK_ID */ - { 383, -1 }, /* (336) stream_name ::= NK_ID */ - { 378, -1 }, /* (337) cgroup_name ::= NK_ID */ - { 393, -1 }, /* (338) expr_or_subquery ::= expression */ - { 393, -1 }, /* (339) expr_or_subquery ::= subquery */ - { 385, -1 }, /* (340) expression ::= literal */ - { 385, -1 }, /* (341) expression ::= pseudo_column */ - { 385, -1 }, /* (342) expression ::= column_reference */ - { 385, -1 }, /* (343) expression ::= function_expression */ - { 385, -1 }, /* (344) expression ::= case_when_expression */ - { 385, -3 }, /* (345) expression ::= NK_LP expression NK_RP */ - { 385, -2 }, /* (346) expression ::= NK_PLUS expr_or_subquery */ - { 385, -2 }, /* (347) expression ::= NK_MINUS expr_or_subquery */ - { 385, -3 }, /* (348) expression ::= expr_or_subquery NK_PLUS expr_or_subquery */ - { 385, -3 }, /* (349) expression ::= expr_or_subquery NK_MINUS expr_or_subquery */ - { 385, -3 }, /* (350) expression ::= expr_or_subquery NK_STAR expr_or_subquery */ - { 385, -3 }, /* (351) expression ::= expr_or_subquery NK_SLASH expr_or_subquery */ - { 385, -3 }, /* (352) expression ::= expr_or_subquery NK_REM expr_or_subquery */ - { 385, -3 }, /* (353) expression ::= column_reference NK_ARROW NK_STRING */ - { 385, -3 }, /* (354) expression ::= expr_or_subquery NK_BITAND expr_or_subquery */ - { 385, -3 }, /* (355) expression ::= expr_or_subquery NK_BITOR expr_or_subquery */ - { 354, -1 }, /* (356) expression_list ::= expr_or_subquery */ - { 354, -3 }, /* (357) expression_list ::= expression_list NK_COMMA expr_or_subquery */ - { 396, -1 }, /* (358) column_reference ::= column_name */ - { 396, -3 }, /* (359) column_reference ::= table_name NK_DOT column_name */ - { 395, -1 }, /* (360) pseudo_column ::= ROWTS */ - { 395, -1 }, /* (361) pseudo_column ::= TBNAME */ - { 395, -3 }, /* (362) pseudo_column ::= table_name NK_DOT TBNAME */ - { 395, -1 }, /* (363) pseudo_column ::= QSTART */ - { 395, -1 }, /* (364) pseudo_column ::= QEND */ - { 395, -1 }, /* (365) pseudo_column ::= QDURATION */ - { 395, -1 }, /* (366) pseudo_column ::= WSTART */ - { 395, -1 }, /* (367) pseudo_column ::= WEND */ - { 395, -1 }, /* (368) pseudo_column ::= WDURATION */ - { 395, -1 }, /* (369) pseudo_column ::= IROWTS */ - { 395, -1 }, /* (370) pseudo_column ::= QTAGS */ - { 397, -4 }, /* (371) function_expression ::= function_name NK_LP expression_list NK_RP */ - { 397, -4 }, /* (372) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ - { 397, -6 }, /* (373) function_expression ::= CAST NK_LP expr_or_subquery AS type_name NK_RP */ - { 397, -1 }, /* (374) function_expression ::= literal_func */ - { 389, -3 }, /* (375) literal_func ::= noarg_func NK_LP NK_RP */ - { 389, -1 }, /* (376) literal_func ::= NOW */ - { 401, -1 }, /* (377) noarg_func ::= NOW */ - { 401, -1 }, /* (378) noarg_func ::= TODAY */ - { 401, -1 }, /* (379) noarg_func ::= TIMEZONE */ - { 401, -1 }, /* (380) noarg_func ::= DATABASE */ - { 401, -1 }, /* (381) noarg_func ::= CLIENT_VERSION */ - { 401, -1 }, /* (382) noarg_func ::= SERVER_VERSION */ - { 401, -1 }, /* (383) noarg_func ::= SERVER_STATUS */ - { 401, -1 }, /* (384) noarg_func ::= CURRENT_USER */ - { 401, -1 }, /* (385) noarg_func ::= USER */ - { 399, -1 }, /* (386) star_func ::= COUNT */ - { 399, -1 }, /* (387) star_func ::= FIRST */ - { 399, -1 }, /* (388) star_func ::= LAST */ - { 399, -1 }, /* (389) star_func ::= LAST_ROW */ - { 400, -1 }, /* (390) star_func_para_list ::= NK_STAR */ - { 400, -1 }, /* (391) star_func_para_list ::= other_para_list */ - { 402, -1 }, /* (392) other_para_list ::= star_func_para */ - { 402, -3 }, /* (393) other_para_list ::= other_para_list NK_COMMA star_func_para */ - { 403, -1 }, /* (394) star_func_para ::= expr_or_subquery */ - { 403, -3 }, /* (395) star_func_para ::= table_name NK_DOT NK_STAR */ - { 398, -4 }, /* (396) case_when_expression ::= CASE when_then_list case_when_else_opt END */ - { 398, -5 }, /* (397) case_when_expression ::= CASE common_expression when_then_list case_when_else_opt END */ - { 404, -1 }, /* (398) when_then_list ::= when_then_expr */ - { 404, -2 }, /* (399) when_then_list ::= when_then_list when_then_expr */ - { 407, -4 }, /* (400) when_then_expr ::= WHEN common_expression THEN common_expression */ - { 405, 0 }, /* (401) case_when_else_opt ::= */ - { 405, -2 }, /* (402) case_when_else_opt ::= ELSE common_expression */ - { 408, -3 }, /* (403) predicate ::= expr_or_subquery compare_op expr_or_subquery */ - { 408, -5 }, /* (404) predicate ::= expr_or_subquery BETWEEN expr_or_subquery AND expr_or_subquery */ - { 408, -6 }, /* (405) predicate ::= expr_or_subquery NOT BETWEEN expr_or_subquery AND expr_or_subquery */ - { 408, -3 }, /* (406) predicate ::= expr_or_subquery IS NULL */ - { 408, -4 }, /* (407) predicate ::= expr_or_subquery IS NOT NULL */ - { 408, -3 }, /* (408) predicate ::= expr_or_subquery in_op in_predicate_value */ - { 409, -1 }, /* (409) compare_op ::= NK_LT */ - { 409, -1 }, /* (410) compare_op ::= NK_GT */ - { 409, -1 }, /* (411) compare_op ::= NK_LE */ - { 409, -1 }, /* (412) compare_op ::= NK_GE */ - { 409, -1 }, /* (413) compare_op ::= NK_NE */ - { 409, -1 }, /* (414) compare_op ::= NK_EQ */ - { 409, -1 }, /* (415) compare_op ::= LIKE */ - { 409, -2 }, /* (416) compare_op ::= NOT LIKE */ - { 409, -1 }, /* (417) compare_op ::= MATCH */ - { 409, -1 }, /* (418) compare_op ::= NMATCH */ - { 409, -1 }, /* (419) compare_op ::= CONTAINS */ - { 410, -1 }, /* (420) in_op ::= IN */ - { 410, -2 }, /* (421) in_op ::= NOT IN */ - { 411, -3 }, /* (422) in_predicate_value ::= NK_LP literal_list NK_RP */ - { 412, -1 }, /* (423) boolean_value_expression ::= boolean_primary */ - { 412, -2 }, /* (424) boolean_value_expression ::= NOT boolean_primary */ - { 412, -3 }, /* (425) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ - { 412, -3 }, /* (426) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ - { 413, -1 }, /* (427) boolean_primary ::= predicate */ - { 413, -3 }, /* (428) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ - { 406, -1 }, /* (429) common_expression ::= expr_or_subquery */ - { 406, -1 }, /* (430) common_expression ::= boolean_value_expression */ - { 414, 0 }, /* (431) from_clause_opt ::= */ - { 414, -2 }, /* (432) from_clause_opt ::= FROM table_reference_list */ - { 415, -1 }, /* (433) table_reference_list ::= table_reference */ - { 415, -3 }, /* (434) table_reference_list ::= table_reference_list NK_COMMA table_reference */ - { 416, -1 }, /* (435) table_reference ::= table_primary */ - { 416, -1 }, /* (436) table_reference ::= joined_table */ - { 417, -2 }, /* (437) table_primary ::= table_name alias_opt */ - { 417, -4 }, /* (438) table_primary ::= db_name NK_DOT table_name alias_opt */ - { 417, -2 }, /* (439) table_primary ::= subquery alias_opt */ - { 417, -1 }, /* (440) table_primary ::= parenthesized_joined_table */ - { 419, 0 }, /* (441) alias_opt ::= */ - { 419, -1 }, /* (442) alias_opt ::= table_alias */ - { 419, -2 }, /* (443) alias_opt ::= AS table_alias */ - { 420, -3 }, /* (444) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - { 420, -3 }, /* (445) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ - { 418, -6 }, /* (446) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ - { 421, 0 }, /* (447) join_type ::= */ - { 421, -1 }, /* (448) join_type ::= INNER */ - { 423, -12 }, /* (449) query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ - { 424, 0 }, /* (450) set_quantifier_opt ::= */ - { 424, -1 }, /* (451) set_quantifier_opt ::= DISTINCT */ - { 424, -1 }, /* (452) set_quantifier_opt ::= ALL */ - { 425, -1 }, /* (453) select_list ::= select_item */ - { 425, -3 }, /* (454) select_list ::= select_list NK_COMMA select_item */ - { 433, -1 }, /* (455) select_item ::= NK_STAR */ - { 433, -1 }, /* (456) select_item ::= common_expression */ - { 433, -2 }, /* (457) select_item ::= common_expression column_alias */ - { 433, -3 }, /* (458) select_item ::= common_expression AS column_alias */ - { 433, -3 }, /* (459) select_item ::= table_name NK_DOT NK_STAR */ - { 387, 0 }, /* (460) where_clause_opt ::= */ - { 387, -2 }, /* (461) where_clause_opt ::= WHERE search_condition */ - { 426, 0 }, /* (462) partition_by_clause_opt ::= */ - { 426, -3 }, /* (463) partition_by_clause_opt ::= PARTITION BY partition_list */ - { 434, -1 }, /* (464) partition_list ::= partition_item */ - { 434, -3 }, /* (465) partition_list ::= partition_list NK_COMMA partition_item */ - { 435, -1 }, /* (466) partition_item ::= expr_or_subquery */ - { 435, -2 }, /* (467) partition_item ::= expr_or_subquery column_alias */ - { 435, -3 }, /* (468) partition_item ::= expr_or_subquery AS column_alias */ - { 430, 0 }, /* (469) twindow_clause_opt ::= */ - { 430, -6 }, /* (470) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ - { 430, -4 }, /* (471) twindow_clause_opt ::= STATE_WINDOW NK_LP expr_or_subquery NK_RP */ - { 430, -6 }, /* (472) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ - { 430, -8 }, /* (473) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ - { 372, 0 }, /* (474) sliding_opt ::= */ - { 372, -4 }, /* (475) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ - { 429, 0 }, /* (476) fill_opt ::= */ - { 429, -4 }, /* (477) fill_opt ::= FILL NK_LP fill_mode NK_RP */ - { 429, -6 }, /* (478) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ - { 436, -1 }, /* (479) fill_mode ::= NONE */ - { 436, -1 }, /* (480) fill_mode ::= PREV */ - { 436, -1 }, /* (481) fill_mode ::= NULL */ - { 436, -1 }, /* (482) fill_mode ::= LINEAR */ - { 436, -1 }, /* (483) fill_mode ::= NEXT */ - { 431, 0 }, /* (484) group_by_clause_opt ::= */ - { 431, -3 }, /* (485) group_by_clause_opt ::= GROUP BY group_by_list */ - { 437, -1 }, /* (486) group_by_list ::= expr_or_subquery */ - { 437, -3 }, /* (487) group_by_list ::= group_by_list NK_COMMA expr_or_subquery */ - { 432, 0 }, /* (488) having_clause_opt ::= */ - { 432, -2 }, /* (489) having_clause_opt ::= HAVING search_condition */ - { 427, 0 }, /* (490) range_opt ::= */ - { 427, -6 }, /* (491) range_opt ::= RANGE NK_LP expr_or_subquery NK_COMMA expr_or_subquery NK_RP */ - { 428, 0 }, /* (492) every_opt ::= */ - { 428, -4 }, /* (493) every_opt ::= EVERY NK_LP duration_literal NK_RP */ - { 438, -4 }, /* (494) query_expression ::= query_simple order_by_clause_opt slimit_clause_opt limit_clause_opt */ - { 439, -1 }, /* (495) query_simple ::= query_specification */ - { 439, -1 }, /* (496) query_simple ::= union_query_expression */ - { 443, -4 }, /* (497) union_query_expression ::= query_simple_or_subquery UNION ALL query_simple_or_subquery */ - { 443, -3 }, /* (498) union_query_expression ::= query_simple_or_subquery UNION query_simple_or_subquery */ - { 444, -1 }, /* (499) query_simple_or_subquery ::= query_simple */ - { 444, -1 }, /* (500) query_simple_or_subquery ::= subquery */ - { 377, -1 }, /* (501) query_or_subquery ::= query_expression */ - { 377, -1 }, /* (502) query_or_subquery ::= subquery */ - { 440, 0 }, /* (503) order_by_clause_opt ::= */ - { 440, -3 }, /* (504) order_by_clause_opt ::= ORDER BY sort_specification_list */ - { 441, 0 }, /* (505) slimit_clause_opt ::= */ - { 441, -2 }, /* (506) slimit_clause_opt ::= SLIMIT NK_INTEGER */ - { 441, -4 }, /* (507) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - { 441, -4 }, /* (508) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 442, 0 }, /* (509) limit_clause_opt ::= */ - { 442, -2 }, /* (510) limit_clause_opt ::= LIMIT NK_INTEGER */ - { 442, -4 }, /* (511) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ - { 442, -4 }, /* (512) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - { 394, -3 }, /* (513) subquery ::= NK_LP query_expression NK_RP */ - { 394, -3 }, /* (514) subquery ::= NK_LP subquery NK_RP */ - { 422, -1 }, /* (515) search_condition ::= common_expression */ - { 445, -1 }, /* (516) sort_specification_list ::= sort_specification */ - { 445, -3 }, /* (517) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ - { 446, -3 }, /* (518) sort_specification ::= expr_or_subquery ordering_specification_opt null_ordering_opt */ - { 447, 0 }, /* (519) ordering_specification_opt ::= */ - { 447, -1 }, /* (520) ordering_specification_opt ::= ASC */ - { 447, -1 }, /* (521) ordering_specification_opt ::= DESC */ - { 448, 0 }, /* (522) null_ordering_opt ::= */ - { 448, -2 }, /* (523) null_ordering_opt ::= NULLS FIRST */ - { 448, -2 }, /* (524) null_ordering_opt ::= NULLS LAST */ + { 319, -6 }, /* (0) cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ + { 319, -4 }, /* (1) cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ + { 320, 0 }, /* (2) account_options ::= */ + { 320, -3 }, /* (3) account_options ::= account_options PPS literal */ + { 320, -3 }, /* (4) account_options ::= account_options TSERIES literal */ + { 320, -3 }, /* (5) account_options ::= account_options STORAGE literal */ + { 320, -3 }, /* (6) account_options ::= account_options STREAMS literal */ + { 320, -3 }, /* (7) account_options ::= account_options QTIME literal */ + { 320, -3 }, /* (8) account_options ::= account_options DBS literal */ + { 320, -3 }, /* (9) account_options ::= account_options USERS literal */ + { 320, -3 }, /* (10) account_options ::= account_options CONNS literal */ + { 320, -3 }, /* (11) account_options ::= account_options STATE literal */ + { 321, -1 }, /* (12) alter_account_options ::= alter_account_option */ + { 321, -2 }, /* (13) alter_account_options ::= alter_account_options alter_account_option */ + { 323, -2 }, /* (14) alter_account_option ::= PASS literal */ + { 323, -2 }, /* (15) alter_account_option ::= PPS literal */ + { 323, -2 }, /* (16) alter_account_option ::= TSERIES literal */ + { 323, -2 }, /* (17) alter_account_option ::= STORAGE literal */ + { 323, -2 }, /* (18) alter_account_option ::= STREAMS literal */ + { 323, -2 }, /* (19) alter_account_option ::= QTIME literal */ + { 323, -2 }, /* (20) alter_account_option ::= DBS literal */ + { 323, -2 }, /* (21) alter_account_option ::= USERS literal */ + { 323, -2 }, /* (22) alter_account_option ::= CONNS literal */ + { 323, -2 }, /* (23) alter_account_option ::= STATE literal */ + { 319, -6 }, /* (24) cmd ::= CREATE USER user_name PASS NK_STRING sysinfo_opt */ + { 319, -5 }, /* (25) cmd ::= ALTER USER user_name PASS NK_STRING */ + { 319, -5 }, /* (26) cmd ::= ALTER USER user_name ENABLE NK_INTEGER */ + { 319, -5 }, /* (27) cmd ::= ALTER USER user_name SYSINFO NK_INTEGER */ + { 319, -3 }, /* (28) cmd ::= DROP USER user_name */ + { 325, 0 }, /* (29) sysinfo_opt ::= */ + { 325, -2 }, /* (30) sysinfo_opt ::= SYSINFO NK_INTEGER */ + { 319, -6 }, /* (31) cmd ::= GRANT privileges ON priv_level TO user_name */ + { 319, -6 }, /* (32) cmd ::= REVOKE privileges ON priv_level FROM user_name */ + { 326, -1 }, /* (33) privileges ::= ALL */ + { 326, -1 }, /* (34) privileges ::= priv_type_list */ + { 328, -1 }, /* (35) priv_type_list ::= priv_type */ + { 328, -3 }, /* (36) priv_type_list ::= priv_type_list NK_COMMA priv_type */ + { 329, -1 }, /* (37) priv_type ::= READ */ + { 329, -1 }, /* (38) priv_type ::= WRITE */ + { 327, -3 }, /* (39) priv_level ::= NK_STAR NK_DOT NK_STAR */ + { 327, -3 }, /* (40) priv_level ::= db_name NK_DOT NK_STAR */ + { 319, -3 }, /* (41) cmd ::= CREATE DNODE dnode_endpoint */ + { 319, -5 }, /* (42) cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER */ + { 319, -4 }, /* (43) cmd ::= DROP DNODE NK_INTEGER force_opt */ + { 319, -4 }, /* (44) cmd ::= DROP DNODE dnode_endpoint force_opt */ + { 319, -4 }, /* (45) cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ + { 319, -5 }, /* (46) cmd ::= ALTER DNODE NK_INTEGER NK_STRING NK_STRING */ + { 319, -4 }, /* (47) cmd ::= ALTER ALL DNODES NK_STRING */ + { 319, -5 }, /* (48) cmd ::= ALTER ALL DNODES NK_STRING NK_STRING */ + { 331, -1 }, /* (49) dnode_endpoint ::= NK_STRING */ + { 331, -1 }, /* (50) dnode_endpoint ::= NK_ID */ + { 331, -1 }, /* (51) dnode_endpoint ::= NK_IPTOKEN */ + { 332, 0 }, /* (52) force_opt ::= */ + { 332, -1 }, /* (53) force_opt ::= FORCE */ + { 319, -3 }, /* (54) cmd ::= ALTER LOCAL NK_STRING */ + { 319, -4 }, /* (55) cmd ::= ALTER LOCAL NK_STRING NK_STRING */ + { 319, -5 }, /* (56) cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ + { 319, -5 }, /* (57) cmd ::= DROP QNODE ON DNODE NK_INTEGER */ + { 319, -5 }, /* (58) cmd ::= CREATE BNODE ON DNODE NK_INTEGER */ + { 319, -5 }, /* (59) cmd ::= DROP BNODE ON DNODE NK_INTEGER */ + { 319, -5 }, /* (60) cmd ::= CREATE SNODE ON DNODE NK_INTEGER */ + { 319, -5 }, /* (61) cmd ::= DROP SNODE ON DNODE NK_INTEGER */ + { 319, -5 }, /* (62) cmd ::= CREATE MNODE ON DNODE NK_INTEGER */ + { 319, -5 }, /* (63) cmd ::= DROP MNODE ON DNODE NK_INTEGER */ + { 319, -5 }, /* (64) cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ + { 319, -4 }, /* (65) cmd ::= DROP DATABASE exists_opt db_name */ + { 319, -2 }, /* (66) cmd ::= USE db_name */ + { 319, -4 }, /* (67) cmd ::= ALTER DATABASE db_name alter_db_options */ + { 319, -3 }, /* (68) cmd ::= FLUSH DATABASE db_name */ + { 319, -4 }, /* (69) cmd ::= TRIM DATABASE db_name speed_opt */ + { 333, -3 }, /* (70) not_exists_opt ::= IF NOT EXISTS */ + { 333, 0 }, /* (71) not_exists_opt ::= */ + { 335, -2 }, /* (72) exists_opt ::= IF EXISTS */ + { 335, 0 }, /* (73) exists_opt ::= */ + { 334, 0 }, /* (74) db_options ::= */ + { 334, -3 }, /* (75) db_options ::= db_options BUFFER NK_INTEGER */ + { 334, -3 }, /* (76) db_options ::= db_options CACHEMODEL NK_STRING */ + { 334, -3 }, /* (77) db_options ::= db_options CACHESIZE NK_INTEGER */ + { 334, -3 }, /* (78) db_options ::= db_options COMP NK_INTEGER */ + { 334, -3 }, /* (79) db_options ::= db_options DURATION NK_INTEGER */ + { 334, -3 }, /* (80) db_options ::= db_options DURATION NK_VARIABLE */ + { 334, -3 }, /* (81) db_options ::= db_options MAXROWS NK_INTEGER */ + { 334, -3 }, /* (82) db_options ::= db_options MINROWS NK_INTEGER */ + { 334, -3 }, /* (83) db_options ::= db_options KEEP integer_list */ + { 334, -3 }, /* (84) db_options ::= db_options KEEP variable_list */ + { 334, -3 }, /* (85) db_options ::= db_options PAGES NK_INTEGER */ + { 334, -3 }, /* (86) db_options ::= db_options PAGESIZE NK_INTEGER */ + { 334, -3 }, /* (87) db_options ::= db_options TSDB_PAGESIZE NK_INTEGER */ + { 334, -3 }, /* (88) db_options ::= db_options PRECISION NK_STRING */ + { 334, -3 }, /* (89) db_options ::= db_options REPLICA NK_INTEGER */ + { 334, -3 }, /* (90) db_options ::= db_options STRICT NK_STRING */ + { 334, -3 }, /* (91) db_options ::= db_options VGROUPS NK_INTEGER */ + { 334, -3 }, /* (92) db_options ::= db_options SINGLE_STABLE NK_INTEGER */ + { 334, -3 }, /* (93) db_options ::= db_options RETENTIONS retention_list */ + { 334, -3 }, /* (94) db_options ::= db_options SCHEMALESS NK_INTEGER */ + { 334, -3 }, /* (95) db_options ::= db_options WAL_LEVEL NK_INTEGER */ + { 334, -3 }, /* (96) db_options ::= db_options WAL_FSYNC_PERIOD NK_INTEGER */ + { 334, -3 }, /* (97) db_options ::= db_options WAL_RETENTION_PERIOD NK_INTEGER */ + { 334, -4 }, /* (98) db_options ::= db_options WAL_RETENTION_PERIOD NK_MINUS NK_INTEGER */ + { 334, -3 }, /* (99) db_options ::= db_options WAL_RETENTION_SIZE NK_INTEGER */ + { 334, -4 }, /* (100) db_options ::= db_options WAL_RETENTION_SIZE NK_MINUS NK_INTEGER */ + { 334, -3 }, /* (101) db_options ::= db_options WAL_ROLL_PERIOD NK_INTEGER */ + { 334, -3 }, /* (102) db_options ::= db_options WAL_SEGMENT_SIZE NK_INTEGER */ + { 334, -3 }, /* (103) db_options ::= db_options STT_TRIGGER NK_INTEGER */ + { 334, -3 }, /* (104) db_options ::= db_options TABLE_PREFIX NK_INTEGER */ + { 334, -3 }, /* (105) db_options ::= db_options TABLE_SUFFIX NK_INTEGER */ + { 336, -1 }, /* (106) alter_db_options ::= alter_db_option */ + { 336, -2 }, /* (107) alter_db_options ::= alter_db_options alter_db_option */ + { 341, -2 }, /* (108) alter_db_option ::= BUFFER NK_INTEGER */ + { 341, -2 }, /* (109) alter_db_option ::= CACHEMODEL NK_STRING */ + { 341, -2 }, /* (110) alter_db_option ::= CACHESIZE NK_INTEGER */ + { 341, -2 }, /* (111) alter_db_option ::= WAL_FSYNC_PERIOD NK_INTEGER */ + { 341, -2 }, /* (112) alter_db_option ::= KEEP integer_list */ + { 341, -2 }, /* (113) alter_db_option ::= KEEP variable_list */ + { 341, -2 }, /* (114) alter_db_option ::= PAGES NK_INTEGER */ + { 341, -2 }, /* (115) alter_db_option ::= REPLICA NK_INTEGER */ + { 341, -2 }, /* (116) alter_db_option ::= STRICT NK_STRING */ + { 341, -2 }, /* (117) alter_db_option ::= WAL_LEVEL NK_INTEGER */ + { 341, -2 }, /* (118) alter_db_option ::= STT_TRIGGER NK_INTEGER */ + { 338, -1 }, /* (119) integer_list ::= NK_INTEGER */ + { 338, -3 }, /* (120) integer_list ::= integer_list NK_COMMA NK_INTEGER */ + { 339, -1 }, /* (121) variable_list ::= NK_VARIABLE */ + { 339, -3 }, /* (122) variable_list ::= variable_list NK_COMMA NK_VARIABLE */ + { 340, -1 }, /* (123) retention_list ::= retention */ + { 340, -3 }, /* (124) retention_list ::= retention_list NK_COMMA retention */ + { 342, -3 }, /* (125) retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ + { 337, 0 }, /* (126) speed_opt ::= */ + { 337, -2 }, /* (127) speed_opt ::= MAX_SPEED NK_INTEGER */ + { 319, -9 }, /* (128) cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + { 319, -3 }, /* (129) cmd ::= CREATE TABLE multi_create_clause */ + { 319, -9 }, /* (130) cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ + { 319, -3 }, /* (131) cmd ::= DROP TABLE multi_drop_clause */ + { 319, -4 }, /* (132) cmd ::= DROP STABLE exists_opt full_table_name */ + { 319, -3 }, /* (133) cmd ::= ALTER TABLE alter_table_clause */ + { 319, -3 }, /* (134) cmd ::= ALTER STABLE alter_table_clause */ + { 350, -2 }, /* (135) alter_table_clause ::= full_table_name alter_table_options */ + { 350, -5 }, /* (136) alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ + { 350, -4 }, /* (137) alter_table_clause ::= full_table_name DROP COLUMN column_name */ + { 350, -5 }, /* (138) alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ + { 350, -5 }, /* (139) alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ + { 350, -5 }, /* (140) alter_table_clause ::= full_table_name ADD TAG column_name type_name */ + { 350, -4 }, /* (141) alter_table_clause ::= full_table_name DROP TAG column_name */ + { 350, -5 }, /* (142) alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ + { 350, -5 }, /* (143) alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ + { 350, -6 }, /* (144) alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ + { 347, -1 }, /* (145) multi_create_clause ::= create_subtable_clause */ + { 347, -2 }, /* (146) multi_create_clause ::= multi_create_clause create_subtable_clause */ + { 355, -10 }, /* (147) create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options */ + { 349, -1 }, /* (148) multi_drop_clause ::= drop_table_clause */ + { 349, -2 }, /* (149) multi_drop_clause ::= multi_drop_clause drop_table_clause */ + { 358, -2 }, /* (150) drop_table_clause ::= exists_opt full_table_name */ + { 356, 0 }, /* (151) specific_cols_opt ::= */ + { 356, -3 }, /* (152) specific_cols_opt ::= NK_LP col_name_list NK_RP */ + { 343, -1 }, /* (153) full_table_name ::= table_name */ + { 343, -3 }, /* (154) full_table_name ::= db_name NK_DOT table_name */ + { 344, -1 }, /* (155) column_def_list ::= column_def */ + { 344, -3 }, /* (156) column_def_list ::= column_def_list NK_COMMA column_def */ + { 361, -2 }, /* (157) column_def ::= column_name type_name */ + { 361, -4 }, /* (158) column_def ::= column_name type_name COMMENT NK_STRING */ + { 353, -1 }, /* (159) type_name ::= BOOL */ + { 353, -1 }, /* (160) type_name ::= TINYINT */ + { 353, -1 }, /* (161) type_name ::= SMALLINT */ + { 353, -1 }, /* (162) type_name ::= INT */ + { 353, -1 }, /* (163) type_name ::= INTEGER */ + { 353, -1 }, /* (164) type_name ::= BIGINT */ + { 353, -1 }, /* (165) type_name ::= FLOAT */ + { 353, -1 }, /* (166) type_name ::= DOUBLE */ + { 353, -4 }, /* (167) type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ + { 353, -1 }, /* (168) type_name ::= TIMESTAMP */ + { 353, -4 }, /* (169) type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ + { 353, -2 }, /* (170) type_name ::= TINYINT UNSIGNED */ + { 353, -2 }, /* (171) type_name ::= SMALLINT UNSIGNED */ + { 353, -2 }, /* (172) type_name ::= INT UNSIGNED */ + { 353, -2 }, /* (173) type_name ::= BIGINT UNSIGNED */ + { 353, -1 }, /* (174) type_name ::= JSON */ + { 353, -4 }, /* (175) type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ + { 353, -1 }, /* (176) type_name ::= MEDIUMBLOB */ + { 353, -1 }, /* (177) type_name ::= BLOB */ + { 353, -4 }, /* (178) type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ + { 353, -1 }, /* (179) type_name ::= DECIMAL */ + { 353, -4 }, /* (180) type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ + { 353, -6 }, /* (181) type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ + { 345, 0 }, /* (182) tags_def_opt ::= */ + { 345, -1 }, /* (183) tags_def_opt ::= tags_def */ + { 348, -4 }, /* (184) tags_def ::= TAGS NK_LP column_def_list NK_RP */ + { 346, 0 }, /* (185) table_options ::= */ + { 346, -3 }, /* (186) table_options ::= table_options COMMENT NK_STRING */ + { 346, -3 }, /* (187) table_options ::= table_options MAX_DELAY duration_list */ + { 346, -3 }, /* (188) table_options ::= table_options WATERMARK duration_list */ + { 346, -5 }, /* (189) table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ + { 346, -3 }, /* (190) table_options ::= table_options TTL NK_INTEGER */ + { 346, -5 }, /* (191) table_options ::= table_options SMA NK_LP col_name_list NK_RP */ + { 351, -1 }, /* (192) alter_table_options ::= alter_table_option */ + { 351, -2 }, /* (193) alter_table_options ::= alter_table_options alter_table_option */ + { 364, -2 }, /* (194) alter_table_option ::= COMMENT NK_STRING */ + { 364, -2 }, /* (195) alter_table_option ::= TTL NK_INTEGER */ + { 362, -1 }, /* (196) duration_list ::= duration_literal */ + { 362, -3 }, /* (197) duration_list ::= duration_list NK_COMMA duration_literal */ + { 363, -1 }, /* (198) rollup_func_list ::= rollup_func_name */ + { 363, -3 }, /* (199) rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ + { 366, -1 }, /* (200) rollup_func_name ::= function_name */ + { 366, -1 }, /* (201) rollup_func_name ::= FIRST */ + { 366, -1 }, /* (202) rollup_func_name ::= LAST */ + { 359, -1 }, /* (203) col_name_list ::= col_name */ + { 359, -3 }, /* (204) col_name_list ::= col_name_list NK_COMMA col_name */ + { 368, -1 }, /* (205) col_name ::= column_name */ + { 319, -2 }, /* (206) cmd ::= SHOW DNODES */ + { 319, -2 }, /* (207) cmd ::= SHOW USERS */ + { 319, -2 }, /* (208) cmd ::= SHOW DATABASES */ + { 319, -4 }, /* (209) cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ + { 319, -4 }, /* (210) cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ + { 319, -3 }, /* (211) cmd ::= SHOW db_name_cond_opt VGROUPS */ + { 319, -2 }, /* (212) cmd ::= SHOW MNODES */ + { 319, -2 }, /* (213) cmd ::= SHOW QNODES */ + { 319, -2 }, /* (214) cmd ::= SHOW FUNCTIONS */ + { 319, -5 }, /* (215) cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ + { 319, -2 }, /* (216) cmd ::= SHOW STREAMS */ + { 319, -2 }, /* (217) cmd ::= SHOW ACCOUNTS */ + { 319, -2 }, /* (218) cmd ::= SHOW APPS */ + { 319, -2 }, /* (219) cmd ::= SHOW CONNECTIONS */ + { 319, -2 }, /* (220) cmd ::= SHOW LICENCES */ + { 319, -2 }, /* (221) cmd ::= SHOW GRANTS */ + { 319, -4 }, /* (222) cmd ::= SHOW CREATE DATABASE db_name */ + { 319, -4 }, /* (223) cmd ::= SHOW CREATE TABLE full_table_name */ + { 319, -4 }, /* (224) cmd ::= SHOW CREATE STABLE full_table_name */ + { 319, -2 }, /* (225) cmd ::= SHOW QUERIES */ + { 319, -2 }, /* (226) cmd ::= SHOW SCORES */ + { 319, -2 }, /* (227) cmd ::= SHOW TOPICS */ + { 319, -2 }, /* (228) cmd ::= SHOW VARIABLES */ + { 319, -3 }, /* (229) cmd ::= SHOW CLUSTER VARIABLES */ + { 319, -3 }, /* (230) cmd ::= SHOW LOCAL VARIABLES */ + { 319, -5 }, /* (231) cmd ::= SHOW DNODE NK_INTEGER VARIABLES like_pattern_opt */ + { 319, -2 }, /* (232) cmd ::= SHOW BNODES */ + { 319, -2 }, /* (233) cmd ::= SHOW SNODES */ + { 319, -2 }, /* (234) cmd ::= SHOW CLUSTER */ + { 319, -2 }, /* (235) cmd ::= SHOW TRANSACTIONS */ + { 319, -4 }, /* (236) cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ + { 319, -2 }, /* (237) cmd ::= SHOW CONSUMERS */ + { 319, -2 }, /* (238) cmd ::= SHOW SUBSCRIPTIONS */ + { 319, -5 }, /* (239) cmd ::= SHOW TAGS FROM table_name_cond from_db_opt */ + { 319, -6 }, /* (240) cmd ::= SHOW TABLE TAGS FROM table_name_cond from_db_opt */ + { 319, -3 }, /* (241) cmd ::= SHOW VNODES NK_INTEGER */ + { 319, -3 }, /* (242) cmd ::= SHOW VNODES NK_STRING */ + { 369, 0 }, /* (243) db_name_cond_opt ::= */ + { 369, -2 }, /* (244) db_name_cond_opt ::= db_name NK_DOT */ + { 370, 0 }, /* (245) like_pattern_opt ::= */ + { 370, -2 }, /* (246) like_pattern_opt ::= LIKE NK_STRING */ + { 371, -1 }, /* (247) table_name_cond ::= table_name */ + { 372, 0 }, /* (248) from_db_opt ::= */ + { 372, -2 }, /* (249) from_db_opt ::= FROM db_name */ + { 319, -8 }, /* (250) cmd ::= CREATE SMA INDEX not_exists_opt full_table_name ON full_table_name index_options */ + { 319, -4 }, /* (251) cmd ::= DROP INDEX exists_opt full_table_name */ + { 373, -10 }, /* (252) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */ + { 373, -12 }, /* (253) index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */ + { 374, -1 }, /* (254) func_list ::= func */ + { 374, -3 }, /* (255) func_list ::= func_list NK_COMMA func */ + { 377, -4 }, /* (256) func ::= function_name NK_LP expression_list NK_RP */ + { 376, 0 }, /* (257) sma_stream_opt ::= */ + { 376, -3 }, /* (258) sma_stream_opt ::= stream_options WATERMARK duration_literal */ + { 376, -3 }, /* (259) sma_stream_opt ::= stream_options MAX_DELAY duration_literal */ + { 319, -6 }, /* (260) cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_or_subquery */ + { 319, -7 }, /* (261) cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ + { 319, -9 }, /* (262) cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */ + { 319, -7 }, /* (263) cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ + { 319, -9 }, /* (264) cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name */ + { 319, -4 }, /* (265) cmd ::= DROP TOPIC exists_opt topic_name */ + { 319, -7 }, /* (266) cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ + { 319, -2 }, /* (267) cmd ::= DESC full_table_name */ + { 319, -2 }, /* (268) cmd ::= DESCRIBE full_table_name */ + { 319, -3 }, /* (269) cmd ::= RESET QUERY CACHE */ + { 319, -4 }, /* (270) cmd ::= EXPLAIN analyze_opt explain_options query_or_subquery */ + { 382, 0 }, /* (271) analyze_opt ::= */ + { 382, -1 }, /* (272) analyze_opt ::= ANALYZE */ + { 383, 0 }, /* (273) explain_options ::= */ + { 383, -3 }, /* (274) explain_options ::= explain_options VERBOSE NK_BOOL */ + { 383, -3 }, /* (275) explain_options ::= explain_options RATIO NK_FLOAT */ + { 319, -10 }, /* (276) cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ + { 319, -4 }, /* (277) cmd ::= DROP FUNCTION exists_opt function_name */ + { 384, 0 }, /* (278) agg_func_opt ::= */ + { 384, -1 }, /* (279) agg_func_opt ::= AGGREGATE */ + { 385, 0 }, /* (280) bufsize_opt ::= */ + { 385, -2 }, /* (281) bufsize_opt ::= BUFSIZE NK_INTEGER */ + { 319, -11 }, /* (282) cmd ::= CREATE STREAM not_exists_opt stream_name stream_options INTO full_table_name tags_def_opt subtable_opt AS query_or_subquery */ + { 319, -4 }, /* (283) cmd ::= DROP STREAM exists_opt stream_name */ + { 378, 0 }, /* (284) stream_options ::= */ + { 378, -3 }, /* (285) stream_options ::= stream_options TRIGGER AT_ONCE */ + { 378, -3 }, /* (286) stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ + { 378, -4 }, /* (287) stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ + { 378, -3 }, /* (288) stream_options ::= stream_options WATERMARK duration_literal */ + { 378, -4 }, /* (289) stream_options ::= stream_options IGNORE EXPIRED NK_INTEGER */ + { 378, -3 }, /* (290) stream_options ::= stream_options FILL_HISTORY NK_INTEGER */ + { 387, 0 }, /* (291) subtable_opt ::= */ + { 387, -4 }, /* (292) subtable_opt ::= SUBTABLE NK_LP expression NK_RP */ + { 319, -3 }, /* (293) cmd ::= KILL CONNECTION NK_INTEGER */ + { 319, -3 }, /* (294) cmd ::= KILL QUERY NK_STRING */ + { 319, -3 }, /* (295) cmd ::= KILL TRANSACTION NK_INTEGER */ + { 319, -2 }, /* (296) cmd ::= BALANCE VGROUP */ + { 319, -4 }, /* (297) cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + { 319, -4 }, /* (298) cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ + { 319, -3 }, /* (299) cmd ::= SPLIT VGROUP NK_INTEGER */ + { 389, -2 }, /* (300) dnode_list ::= DNODE NK_INTEGER */ + { 389, -3 }, /* (301) dnode_list ::= dnode_list DNODE NK_INTEGER */ + { 319, -4 }, /* (302) cmd ::= DELETE FROM full_table_name where_clause_opt */ + { 319, -1 }, /* (303) cmd ::= query_or_subquery */ + { 319, -7 }, /* (304) cmd ::= INSERT INTO full_table_name NK_LP col_name_list NK_RP query_or_subquery */ + { 319, -4 }, /* (305) cmd ::= INSERT INTO full_table_name query_or_subquery */ + { 322, -1 }, /* (306) literal ::= NK_INTEGER */ + { 322, -1 }, /* (307) literal ::= NK_FLOAT */ + { 322, -1 }, /* (308) literal ::= NK_STRING */ + { 322, -1 }, /* (309) literal ::= NK_BOOL */ + { 322, -2 }, /* (310) literal ::= TIMESTAMP NK_STRING */ + { 322, -1 }, /* (311) literal ::= duration_literal */ + { 322, -1 }, /* (312) literal ::= NULL */ + { 322, -1 }, /* (313) literal ::= NK_QUESTION */ + { 365, -1 }, /* (314) duration_literal ::= NK_VARIABLE */ + { 391, -1 }, /* (315) signed ::= NK_INTEGER */ + { 391, -2 }, /* (316) signed ::= NK_PLUS NK_INTEGER */ + { 391, -2 }, /* (317) signed ::= NK_MINUS NK_INTEGER */ + { 391, -1 }, /* (318) signed ::= NK_FLOAT */ + { 391, -2 }, /* (319) signed ::= NK_PLUS NK_FLOAT */ + { 391, -2 }, /* (320) signed ::= NK_MINUS NK_FLOAT */ + { 354, -1 }, /* (321) signed_literal ::= signed */ + { 354, -1 }, /* (322) signed_literal ::= NK_STRING */ + { 354, -1 }, /* (323) signed_literal ::= NK_BOOL */ + { 354, -2 }, /* (324) signed_literal ::= TIMESTAMP NK_STRING */ + { 354, -1 }, /* (325) signed_literal ::= duration_literal */ + { 354, -1 }, /* (326) signed_literal ::= NULL */ + { 354, -1 }, /* (327) signed_literal ::= literal_func */ + { 354, -1 }, /* (328) signed_literal ::= NK_QUESTION */ + { 393, -1 }, /* (329) literal_list ::= signed_literal */ + { 393, -3 }, /* (330) literal_list ::= literal_list NK_COMMA signed_literal */ + { 330, -1 }, /* (331) db_name ::= NK_ID */ + { 360, -1 }, /* (332) table_name ::= NK_ID */ + { 352, -1 }, /* (333) column_name ::= NK_ID */ + { 367, -1 }, /* (334) function_name ::= NK_ID */ + { 394, -1 }, /* (335) table_alias ::= NK_ID */ + { 395, -1 }, /* (336) column_alias ::= NK_ID */ + { 324, -1 }, /* (337) user_name ::= NK_ID */ + { 379, -1 }, /* (338) topic_name ::= NK_ID */ + { 386, -1 }, /* (339) stream_name ::= NK_ID */ + { 381, -1 }, /* (340) cgroup_name ::= NK_ID */ + { 396, -1 }, /* (341) expr_or_subquery ::= expression */ + { 396, -1 }, /* (342) expr_or_subquery ::= subquery */ + { 388, -1 }, /* (343) expression ::= literal */ + { 388, -1 }, /* (344) expression ::= pseudo_column */ + { 388, -1 }, /* (345) expression ::= column_reference */ + { 388, -1 }, /* (346) expression ::= function_expression */ + { 388, -1 }, /* (347) expression ::= case_when_expression */ + { 388, -3 }, /* (348) expression ::= NK_LP expression NK_RP */ + { 388, -2 }, /* (349) expression ::= NK_PLUS expr_or_subquery */ + { 388, -2 }, /* (350) expression ::= NK_MINUS expr_or_subquery */ + { 388, -3 }, /* (351) expression ::= expr_or_subquery NK_PLUS expr_or_subquery */ + { 388, -3 }, /* (352) expression ::= expr_or_subquery NK_MINUS expr_or_subquery */ + { 388, -3 }, /* (353) expression ::= expr_or_subquery NK_STAR expr_or_subquery */ + { 388, -3 }, /* (354) expression ::= expr_or_subquery NK_SLASH expr_or_subquery */ + { 388, -3 }, /* (355) expression ::= expr_or_subquery NK_REM expr_or_subquery */ + { 388, -3 }, /* (356) expression ::= column_reference NK_ARROW NK_STRING */ + { 388, -3 }, /* (357) expression ::= expr_or_subquery NK_BITAND expr_or_subquery */ + { 388, -3 }, /* (358) expression ::= expr_or_subquery NK_BITOR expr_or_subquery */ + { 357, -1 }, /* (359) expression_list ::= expr_or_subquery */ + { 357, -3 }, /* (360) expression_list ::= expression_list NK_COMMA expr_or_subquery */ + { 399, -1 }, /* (361) column_reference ::= column_name */ + { 399, -3 }, /* (362) column_reference ::= table_name NK_DOT column_name */ + { 398, -1 }, /* (363) pseudo_column ::= ROWTS */ + { 398, -1 }, /* (364) pseudo_column ::= TBNAME */ + { 398, -3 }, /* (365) pseudo_column ::= table_name NK_DOT TBNAME */ + { 398, -1 }, /* (366) pseudo_column ::= QSTART */ + { 398, -1 }, /* (367) pseudo_column ::= QEND */ + { 398, -1 }, /* (368) pseudo_column ::= QDURATION */ + { 398, -1 }, /* (369) pseudo_column ::= WSTART */ + { 398, -1 }, /* (370) pseudo_column ::= WEND */ + { 398, -1 }, /* (371) pseudo_column ::= WDURATION */ + { 398, -1 }, /* (372) pseudo_column ::= IROWTS */ + { 398, -1 }, /* (373) pseudo_column ::= QTAGS */ + { 400, -4 }, /* (374) function_expression ::= function_name NK_LP expression_list NK_RP */ + { 400, -4 }, /* (375) function_expression ::= star_func NK_LP star_func_para_list NK_RP */ + { 400, -6 }, /* (376) function_expression ::= CAST NK_LP expr_or_subquery AS type_name NK_RP */ + { 400, -1 }, /* (377) function_expression ::= literal_func */ + { 392, -3 }, /* (378) literal_func ::= noarg_func NK_LP NK_RP */ + { 392, -1 }, /* (379) literal_func ::= NOW */ + { 404, -1 }, /* (380) noarg_func ::= NOW */ + { 404, -1 }, /* (381) noarg_func ::= TODAY */ + { 404, -1 }, /* (382) noarg_func ::= TIMEZONE */ + { 404, -1 }, /* (383) noarg_func ::= DATABASE */ + { 404, -1 }, /* (384) noarg_func ::= CLIENT_VERSION */ + { 404, -1 }, /* (385) noarg_func ::= SERVER_VERSION */ + { 404, -1 }, /* (386) noarg_func ::= SERVER_STATUS */ + { 404, -1 }, /* (387) noarg_func ::= CURRENT_USER */ + { 404, -1 }, /* (388) noarg_func ::= USER */ + { 402, -1 }, /* (389) star_func ::= COUNT */ + { 402, -1 }, /* (390) star_func ::= FIRST */ + { 402, -1 }, /* (391) star_func ::= LAST */ + { 402, -1 }, /* (392) star_func ::= LAST_ROW */ + { 403, -1 }, /* (393) star_func_para_list ::= NK_STAR */ + { 403, -1 }, /* (394) star_func_para_list ::= other_para_list */ + { 405, -1 }, /* (395) other_para_list ::= star_func_para */ + { 405, -3 }, /* (396) other_para_list ::= other_para_list NK_COMMA star_func_para */ + { 406, -1 }, /* (397) star_func_para ::= expr_or_subquery */ + { 406, -3 }, /* (398) star_func_para ::= table_name NK_DOT NK_STAR */ + { 401, -4 }, /* (399) case_when_expression ::= CASE when_then_list case_when_else_opt END */ + { 401, -5 }, /* (400) case_when_expression ::= CASE common_expression when_then_list case_when_else_opt END */ + { 407, -1 }, /* (401) when_then_list ::= when_then_expr */ + { 407, -2 }, /* (402) when_then_list ::= when_then_list when_then_expr */ + { 410, -4 }, /* (403) when_then_expr ::= WHEN common_expression THEN common_expression */ + { 408, 0 }, /* (404) case_when_else_opt ::= */ + { 408, -2 }, /* (405) case_when_else_opt ::= ELSE common_expression */ + { 411, -3 }, /* (406) predicate ::= expr_or_subquery compare_op expr_or_subquery */ + { 411, -5 }, /* (407) predicate ::= expr_or_subquery BETWEEN expr_or_subquery AND expr_or_subquery */ + { 411, -6 }, /* (408) predicate ::= expr_or_subquery NOT BETWEEN expr_or_subquery AND expr_or_subquery */ + { 411, -3 }, /* (409) predicate ::= expr_or_subquery IS NULL */ + { 411, -4 }, /* (410) predicate ::= expr_or_subquery IS NOT NULL */ + { 411, -3 }, /* (411) predicate ::= expr_or_subquery in_op in_predicate_value */ + { 412, -1 }, /* (412) compare_op ::= NK_LT */ + { 412, -1 }, /* (413) compare_op ::= NK_GT */ + { 412, -1 }, /* (414) compare_op ::= NK_LE */ + { 412, -1 }, /* (415) compare_op ::= NK_GE */ + { 412, -1 }, /* (416) compare_op ::= NK_NE */ + { 412, -1 }, /* (417) compare_op ::= NK_EQ */ + { 412, -1 }, /* (418) compare_op ::= LIKE */ + { 412, -2 }, /* (419) compare_op ::= NOT LIKE */ + { 412, -1 }, /* (420) compare_op ::= MATCH */ + { 412, -1 }, /* (421) compare_op ::= NMATCH */ + { 412, -1 }, /* (422) compare_op ::= CONTAINS */ + { 413, -1 }, /* (423) in_op ::= IN */ + { 413, -2 }, /* (424) in_op ::= NOT IN */ + { 414, -3 }, /* (425) in_predicate_value ::= NK_LP literal_list NK_RP */ + { 415, -1 }, /* (426) boolean_value_expression ::= boolean_primary */ + { 415, -2 }, /* (427) boolean_value_expression ::= NOT boolean_primary */ + { 415, -3 }, /* (428) boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + { 415, -3 }, /* (429) boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + { 416, -1 }, /* (430) boolean_primary ::= predicate */ + { 416, -3 }, /* (431) boolean_primary ::= NK_LP boolean_value_expression NK_RP */ + { 409, -1 }, /* (432) common_expression ::= expr_or_subquery */ + { 409, -1 }, /* (433) common_expression ::= boolean_value_expression */ + { 417, 0 }, /* (434) from_clause_opt ::= */ + { 417, -2 }, /* (435) from_clause_opt ::= FROM table_reference_list */ + { 418, -1 }, /* (436) table_reference_list ::= table_reference */ + { 418, -3 }, /* (437) table_reference_list ::= table_reference_list NK_COMMA table_reference */ + { 419, -1 }, /* (438) table_reference ::= table_primary */ + { 419, -1 }, /* (439) table_reference ::= joined_table */ + { 420, -2 }, /* (440) table_primary ::= table_name alias_opt */ + { 420, -4 }, /* (441) table_primary ::= db_name NK_DOT table_name alias_opt */ + { 420, -2 }, /* (442) table_primary ::= subquery alias_opt */ + { 420, -1 }, /* (443) table_primary ::= parenthesized_joined_table */ + { 422, 0 }, /* (444) alias_opt ::= */ + { 422, -1 }, /* (445) alias_opt ::= table_alias */ + { 422, -2 }, /* (446) alias_opt ::= AS table_alias */ + { 423, -3 }, /* (447) parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + { 423, -3 }, /* (448) parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ + { 421, -6 }, /* (449) joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ + { 424, 0 }, /* (450) join_type ::= */ + { 424, -1 }, /* (451) join_type ::= INNER */ + { 426, -12 }, /* (452) query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + { 427, 0 }, /* (453) set_quantifier_opt ::= */ + { 427, -1 }, /* (454) set_quantifier_opt ::= DISTINCT */ + { 427, -1 }, /* (455) set_quantifier_opt ::= ALL */ + { 428, -1 }, /* (456) select_list ::= select_item */ + { 428, -3 }, /* (457) select_list ::= select_list NK_COMMA select_item */ + { 436, -1 }, /* (458) select_item ::= NK_STAR */ + { 436, -1 }, /* (459) select_item ::= common_expression */ + { 436, -2 }, /* (460) select_item ::= common_expression column_alias */ + { 436, -3 }, /* (461) select_item ::= common_expression AS column_alias */ + { 436, -3 }, /* (462) select_item ::= table_name NK_DOT NK_STAR */ + { 390, 0 }, /* (463) where_clause_opt ::= */ + { 390, -2 }, /* (464) where_clause_opt ::= WHERE search_condition */ + { 429, 0 }, /* (465) partition_by_clause_opt ::= */ + { 429, -3 }, /* (466) partition_by_clause_opt ::= PARTITION BY partition_list */ + { 437, -1 }, /* (467) partition_list ::= partition_item */ + { 437, -3 }, /* (468) partition_list ::= partition_list NK_COMMA partition_item */ + { 438, -1 }, /* (469) partition_item ::= expr_or_subquery */ + { 438, -2 }, /* (470) partition_item ::= expr_or_subquery column_alias */ + { 438, -3 }, /* (471) partition_item ::= expr_or_subquery AS column_alias */ + { 433, 0 }, /* (472) twindow_clause_opt ::= */ + { 433, -6 }, /* (473) twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ + { 433, -4 }, /* (474) twindow_clause_opt ::= STATE_WINDOW NK_LP expr_or_subquery NK_RP */ + { 433, -6 }, /* (475) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ + { 433, -8 }, /* (476) twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ + { 375, 0 }, /* (477) sliding_opt ::= */ + { 375, -4 }, /* (478) sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ + { 432, 0 }, /* (479) fill_opt ::= */ + { 432, -4 }, /* (480) fill_opt ::= FILL NK_LP fill_mode NK_RP */ + { 432, -6 }, /* (481) fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ + { 439, -1 }, /* (482) fill_mode ::= NONE */ + { 439, -1 }, /* (483) fill_mode ::= PREV */ + { 439, -1 }, /* (484) fill_mode ::= NULL */ + { 439, -1 }, /* (485) fill_mode ::= LINEAR */ + { 439, -1 }, /* (486) fill_mode ::= NEXT */ + { 434, 0 }, /* (487) group_by_clause_opt ::= */ + { 434, -3 }, /* (488) group_by_clause_opt ::= GROUP BY group_by_list */ + { 440, -1 }, /* (489) group_by_list ::= expr_or_subquery */ + { 440, -3 }, /* (490) group_by_list ::= group_by_list NK_COMMA expr_or_subquery */ + { 435, 0 }, /* (491) having_clause_opt ::= */ + { 435, -2 }, /* (492) having_clause_opt ::= HAVING search_condition */ + { 430, 0 }, /* (493) range_opt ::= */ + { 430, -6 }, /* (494) range_opt ::= RANGE NK_LP expr_or_subquery NK_COMMA expr_or_subquery NK_RP */ + { 431, 0 }, /* (495) every_opt ::= */ + { 431, -4 }, /* (496) every_opt ::= EVERY NK_LP duration_literal NK_RP */ + { 441, -4 }, /* (497) query_expression ::= query_simple order_by_clause_opt slimit_clause_opt limit_clause_opt */ + { 442, -1 }, /* (498) query_simple ::= query_specification */ + { 442, -1 }, /* (499) query_simple ::= union_query_expression */ + { 446, -4 }, /* (500) union_query_expression ::= query_simple_or_subquery UNION ALL query_simple_or_subquery */ + { 446, -3 }, /* (501) union_query_expression ::= query_simple_or_subquery UNION query_simple_or_subquery */ + { 447, -1 }, /* (502) query_simple_or_subquery ::= query_simple */ + { 447, -1 }, /* (503) query_simple_or_subquery ::= subquery */ + { 380, -1 }, /* (504) query_or_subquery ::= query_expression */ + { 380, -1 }, /* (505) query_or_subquery ::= subquery */ + { 443, 0 }, /* (506) order_by_clause_opt ::= */ + { 443, -3 }, /* (507) order_by_clause_opt ::= ORDER BY sort_specification_list */ + { 444, 0 }, /* (508) slimit_clause_opt ::= */ + { 444, -2 }, /* (509) slimit_clause_opt ::= SLIMIT NK_INTEGER */ + { 444, -4 }, /* (510) slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + { 444, -4 }, /* (511) slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 445, 0 }, /* (512) limit_clause_opt ::= */ + { 445, -2 }, /* (513) limit_clause_opt ::= LIMIT NK_INTEGER */ + { 445, -4 }, /* (514) limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ + { 445, -4 }, /* (515) limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + { 397, -3 }, /* (516) subquery ::= NK_LP query_expression NK_RP */ + { 397, -3 }, /* (517) subquery ::= NK_LP subquery NK_RP */ + { 425, -1 }, /* (518) search_condition ::= common_expression */ + { 448, -1 }, /* (519) sort_specification_list ::= sort_specification */ + { 448, -3 }, /* (520) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ + { 449, -3 }, /* (521) sort_specification ::= expr_or_subquery ordering_specification_opt null_ordering_opt */ + { 450, 0 }, /* (522) ordering_specification_opt ::= */ + { 450, -1 }, /* (523) ordering_specification_opt ::= ASC */ + { 450, -1 }, /* (524) ordering_specification_opt ::= DESC */ + { 451, 0 }, /* (525) null_ordering_opt ::= */ + { 451, -2 }, /* (526) null_ordering_opt ::= NULLS FIRST */ + { 451, -2 }, /* (527) null_ordering_opt ::= NULLS LAST */ }; static void yy_accept(yyParser*); /* Forward Declaration */ @@ -3590,11 +3708,11 @@ static YYACTIONTYPE yy_reduce( YYMINORTYPE yylhsminor; case 0: /* cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */ { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,318,&yymsp[0].minor); + yy_destructor(yypParser,320,&yymsp[0].minor); break; case 1: /* cmd ::= ALTER ACCOUNT NK_ID alter_account_options */ { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } - yy_destructor(yypParser,319,&yymsp[0].minor); + yy_destructor(yypParser,321,&yymsp[0].minor); break; case 2: /* account_options ::= */ { } @@ -3608,20 +3726,20 @@ static YYACTIONTYPE yy_reduce( case 9: /* account_options ::= account_options USERS literal */ yytestcase(yyruleno==9); case 10: /* account_options ::= account_options CONNS literal */ yytestcase(yyruleno==10); case 11: /* account_options ::= account_options STATE literal */ yytestcase(yyruleno==11); -{ yy_destructor(yypParser,318,&yymsp[-2].minor); +{ yy_destructor(yypParser,320,&yymsp[-2].minor); { } - yy_destructor(yypParser,320,&yymsp[0].minor); + yy_destructor(yypParser,322,&yymsp[0].minor); } break; case 12: /* alter_account_options ::= alter_account_option */ -{ yy_destructor(yypParser,321,&yymsp[0].minor); +{ yy_destructor(yypParser,323,&yymsp[0].minor); { } } break; case 13: /* alter_account_options ::= alter_account_options alter_account_option */ -{ yy_destructor(yypParser,319,&yymsp[-1].minor); +{ yy_destructor(yypParser,321,&yymsp[-1].minor); { } - yy_destructor(yypParser,321,&yymsp[0].minor); + yy_destructor(yypParser,323,&yymsp[0].minor); } break; case 14: /* alter_account_option ::= PASS literal */ @@ -3635,72 +3753,72 @@ static YYACTIONTYPE yy_reduce( case 22: /* alter_account_option ::= CONNS literal */ yytestcase(yyruleno==22); case 23: /* alter_account_option ::= STATE literal */ yytestcase(yyruleno==23); { } - yy_destructor(yypParser,320,&yymsp[0].minor); + yy_destructor(yypParser,322,&yymsp[0].minor); break; case 24: /* cmd ::= CREATE USER user_name PASS NK_STRING sysinfo_opt */ -{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-3].minor.yy181, &yymsp[-1].minor.yy0, yymsp[0].minor.yy293); } +{ pCxt->pRootNode = createCreateUserStmt(pCxt, &yymsp[-3].minor.yy481, &yymsp[-1].minor.yy0, yymsp[0].minor.yy607); } break; case 25: /* cmd ::= ALTER USER user_name PASS NK_STRING */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy181, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy481, TSDB_ALTER_USER_PASSWD, &yymsp[0].minor.yy0); } break; case 26: /* cmd ::= ALTER USER user_name ENABLE NK_INTEGER */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy181, TSDB_ALTER_USER_ENABLE, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy481, TSDB_ALTER_USER_ENABLE, &yymsp[0].minor.yy0); } break; case 27: /* cmd ::= ALTER USER user_name SYSINFO NK_INTEGER */ -{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy181, TSDB_ALTER_USER_SYSINFO, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createAlterUserStmt(pCxt, &yymsp[-2].minor.yy481, TSDB_ALTER_USER_SYSINFO, &yymsp[0].minor.yy0); } break; case 28: /* cmd ::= DROP USER user_name */ -{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy181); } +{ pCxt->pRootNode = createDropUserStmt(pCxt, &yymsp[0].minor.yy481); } break; case 29: /* sysinfo_opt ::= */ -{ yymsp[1].minor.yy293 = 1; } +{ yymsp[1].minor.yy607 = 1; } break; case 30: /* sysinfo_opt ::= SYSINFO NK_INTEGER */ -{ yymsp[-1].minor.yy293 = taosStr2Int8(yymsp[0].minor.yy0.z, NULL, 10); } +{ yymsp[-1].minor.yy607 = taosStr2Int8(yymsp[0].minor.yy0.z, NULL, 10); } break; case 31: /* cmd ::= GRANT privileges ON priv_level TO user_name */ -{ pCxt->pRootNode = createGrantStmt(pCxt, yymsp[-4].minor.yy831, &yymsp[-2].minor.yy181, &yymsp[0].minor.yy181); } +{ pCxt->pRootNode = createGrantStmt(pCxt, yymsp[-4].minor.yy37, &yymsp[-2].minor.yy481, &yymsp[0].minor.yy481); } break; case 32: /* cmd ::= REVOKE privileges ON priv_level FROM user_name */ -{ pCxt->pRootNode = createRevokeStmt(pCxt, yymsp[-4].minor.yy831, &yymsp[-2].minor.yy181, &yymsp[0].minor.yy181); } +{ pCxt->pRootNode = createRevokeStmt(pCxt, yymsp[-4].minor.yy37, &yymsp[-2].minor.yy481, &yymsp[0].minor.yy481); } break; case 33: /* privileges ::= ALL */ -{ yymsp[0].minor.yy831 = PRIVILEGE_TYPE_ALL; } +{ yymsp[0].minor.yy37 = PRIVILEGE_TYPE_ALL; } break; case 34: /* privileges ::= priv_type_list */ case 35: /* priv_type_list ::= priv_type */ yytestcase(yyruleno==35); -{ yylhsminor.yy831 = yymsp[0].minor.yy831; } - yymsp[0].minor.yy831 = yylhsminor.yy831; +{ yylhsminor.yy37 = yymsp[0].minor.yy37; } + yymsp[0].minor.yy37 = yylhsminor.yy37; break; case 36: /* priv_type_list ::= priv_type_list NK_COMMA priv_type */ -{ yylhsminor.yy831 = yymsp[-2].minor.yy831 | yymsp[0].minor.yy831; } - yymsp[-2].minor.yy831 = yylhsminor.yy831; +{ yylhsminor.yy37 = yymsp[-2].minor.yy37 | yymsp[0].minor.yy37; } + yymsp[-2].minor.yy37 = yylhsminor.yy37; break; case 37: /* priv_type ::= READ */ -{ yymsp[0].minor.yy831 = PRIVILEGE_TYPE_READ; } +{ yymsp[0].minor.yy37 = PRIVILEGE_TYPE_READ; } break; case 38: /* priv_type ::= WRITE */ -{ yymsp[0].minor.yy831 = PRIVILEGE_TYPE_WRITE; } +{ yymsp[0].minor.yy37 = PRIVILEGE_TYPE_WRITE; } break; case 39: /* priv_level ::= NK_STAR NK_DOT NK_STAR */ -{ yylhsminor.yy181 = yymsp[-2].minor.yy0; } - yymsp[-2].minor.yy181 = yylhsminor.yy181; +{ yylhsminor.yy481 = yymsp[-2].minor.yy0; } + yymsp[-2].minor.yy481 = yylhsminor.yy481; break; case 40: /* priv_level ::= db_name NK_DOT NK_STAR */ -{ yylhsminor.yy181 = yymsp[-2].minor.yy181; } - yymsp[-2].minor.yy181 = yylhsminor.yy181; +{ yylhsminor.yy481 = yymsp[-2].minor.yy481; } + yymsp[-2].minor.yy481 = yylhsminor.yy481; break; case 41: /* cmd ::= CREATE DNODE dnode_endpoint */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy181, NULL); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[0].minor.yy481, NULL); } break; case 42: /* cmd ::= CREATE DNODE dnode_endpoint PORT NK_INTEGER */ -{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy181, &yymsp[0].minor.yy0); } +{ pCxt->pRootNode = createCreateDnodeStmt(pCxt, &yymsp[-2].minor.yy481, &yymsp[0].minor.yy0); } break; - case 43: /* cmd ::= DROP DNODE NK_INTEGER */ -{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy0); } + case 43: /* cmd ::= DROP DNODE NK_INTEGER force_opt */ +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy777); } break; - case 44: /* cmd ::= DROP DNODE dnode_endpoint */ -{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[0].minor.yy181); } + case 44: /* cmd ::= DROP DNODE dnode_endpoint force_opt */ +{ pCxt->pRootNode = createDropDnodeStmt(pCxt, &yymsp[-1].minor.yy481, yymsp[0].minor.yy777); } break; case 45: /* cmd ::= ALTER DNODE NK_INTEGER NK_STRING */ { pCxt->pRootNode = createAlterDnodeStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, NULL); } @@ -3717,1384 +3835,1390 @@ static YYACTIONTYPE yy_reduce( case 49: /* dnode_endpoint ::= NK_STRING */ case 50: /* dnode_endpoint ::= NK_ID */ yytestcase(yyruleno==50); case 51: /* dnode_endpoint ::= NK_IPTOKEN */ yytestcase(yyruleno==51); - case 328: /* db_name ::= NK_ID */ yytestcase(yyruleno==328); - case 329: /* table_name ::= NK_ID */ yytestcase(yyruleno==329); - case 330: /* column_name ::= NK_ID */ yytestcase(yyruleno==330); - case 331: /* function_name ::= NK_ID */ yytestcase(yyruleno==331); - case 332: /* table_alias ::= NK_ID */ yytestcase(yyruleno==332); - case 333: /* column_alias ::= NK_ID */ yytestcase(yyruleno==333); - case 334: /* user_name ::= NK_ID */ yytestcase(yyruleno==334); - case 335: /* topic_name ::= NK_ID */ yytestcase(yyruleno==335); - case 336: /* stream_name ::= NK_ID */ yytestcase(yyruleno==336); - case 337: /* cgroup_name ::= NK_ID */ yytestcase(yyruleno==337); - case 377: /* noarg_func ::= NOW */ yytestcase(yyruleno==377); - case 378: /* noarg_func ::= TODAY */ yytestcase(yyruleno==378); - case 379: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==379); - case 380: /* noarg_func ::= DATABASE */ yytestcase(yyruleno==380); - case 381: /* noarg_func ::= CLIENT_VERSION */ yytestcase(yyruleno==381); - case 382: /* noarg_func ::= SERVER_VERSION */ yytestcase(yyruleno==382); - case 383: /* noarg_func ::= SERVER_STATUS */ yytestcase(yyruleno==383); - case 384: /* noarg_func ::= CURRENT_USER */ yytestcase(yyruleno==384); - case 385: /* noarg_func ::= USER */ yytestcase(yyruleno==385); - case 386: /* star_func ::= COUNT */ yytestcase(yyruleno==386); - case 387: /* star_func ::= FIRST */ yytestcase(yyruleno==387); - case 388: /* star_func ::= LAST */ yytestcase(yyruleno==388); - case 389: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==389); -{ yylhsminor.yy181 = yymsp[0].minor.yy0; } - yymsp[0].minor.yy181 = yylhsminor.yy181; - break; - case 52: /* cmd ::= ALTER LOCAL NK_STRING */ + case 331: /* db_name ::= NK_ID */ yytestcase(yyruleno==331); + case 332: /* table_name ::= NK_ID */ yytestcase(yyruleno==332); + case 333: /* column_name ::= NK_ID */ yytestcase(yyruleno==333); + case 334: /* function_name ::= NK_ID */ yytestcase(yyruleno==334); + case 335: /* table_alias ::= NK_ID */ yytestcase(yyruleno==335); + case 336: /* column_alias ::= NK_ID */ yytestcase(yyruleno==336); + case 337: /* user_name ::= NK_ID */ yytestcase(yyruleno==337); + case 338: /* topic_name ::= NK_ID */ yytestcase(yyruleno==338); + case 339: /* stream_name ::= NK_ID */ yytestcase(yyruleno==339); + case 340: /* cgroup_name ::= NK_ID */ yytestcase(yyruleno==340); + case 380: /* noarg_func ::= NOW */ yytestcase(yyruleno==380); + case 381: /* noarg_func ::= TODAY */ yytestcase(yyruleno==381); + case 382: /* noarg_func ::= TIMEZONE */ yytestcase(yyruleno==382); + case 383: /* noarg_func ::= DATABASE */ yytestcase(yyruleno==383); + case 384: /* noarg_func ::= CLIENT_VERSION */ yytestcase(yyruleno==384); + case 385: /* noarg_func ::= SERVER_VERSION */ yytestcase(yyruleno==385); + case 386: /* noarg_func ::= SERVER_STATUS */ yytestcase(yyruleno==386); + case 387: /* noarg_func ::= CURRENT_USER */ yytestcase(yyruleno==387); + case 388: /* noarg_func ::= USER */ yytestcase(yyruleno==388); + case 389: /* star_func ::= COUNT */ yytestcase(yyruleno==389); + case 390: /* star_func ::= FIRST */ yytestcase(yyruleno==390); + case 391: /* star_func ::= LAST */ yytestcase(yyruleno==391); + case 392: /* star_func ::= LAST_ROW */ yytestcase(yyruleno==392); +{ yylhsminor.yy481 = yymsp[0].minor.yy0; } + yymsp[0].minor.yy481 = yylhsminor.yy481; + break; + case 52: /* force_opt ::= */ + case 71: /* not_exists_opt ::= */ yytestcase(yyruleno==71); + case 73: /* exists_opt ::= */ yytestcase(yyruleno==73); + case 271: /* analyze_opt ::= */ yytestcase(yyruleno==271); + case 278: /* agg_func_opt ::= */ yytestcase(yyruleno==278); + case 453: /* set_quantifier_opt ::= */ yytestcase(yyruleno==453); +{ yymsp[1].minor.yy777 = false; } + break; + case 53: /* force_opt ::= FORCE */ + case 272: /* analyze_opt ::= ANALYZE */ yytestcase(yyruleno==272); + case 279: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==279); + case 454: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==454); +{ yymsp[0].minor.yy777 = true; } + break; + case 54: /* cmd ::= ALTER LOCAL NK_STRING */ { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 53: /* cmd ::= ALTER LOCAL NK_STRING NK_STRING */ + case 55: /* cmd ::= ALTER LOCAL NK_STRING NK_STRING */ { pCxt->pRootNode = createAlterLocalStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; - case 54: /* cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ + case 56: /* cmd ::= CREATE QNODE ON DNODE NK_INTEGER */ { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_QNODE_STMT, &yymsp[0].minor.yy0); } break; - case 55: /* cmd ::= DROP QNODE ON DNODE NK_INTEGER */ + case 57: /* cmd ::= DROP QNODE ON DNODE NK_INTEGER */ { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_QNODE_STMT, &yymsp[0].minor.yy0); } break; - case 56: /* cmd ::= CREATE BNODE ON DNODE NK_INTEGER */ + case 58: /* cmd ::= CREATE BNODE ON DNODE NK_INTEGER */ { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_BNODE_STMT, &yymsp[0].minor.yy0); } break; - case 57: /* cmd ::= DROP BNODE ON DNODE NK_INTEGER */ + case 59: /* cmd ::= DROP BNODE ON DNODE NK_INTEGER */ { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_BNODE_STMT, &yymsp[0].minor.yy0); } break; - case 58: /* cmd ::= CREATE SNODE ON DNODE NK_INTEGER */ + case 60: /* cmd ::= CREATE SNODE ON DNODE NK_INTEGER */ { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_SNODE_STMT, &yymsp[0].minor.yy0); } break; - case 59: /* cmd ::= DROP SNODE ON DNODE NK_INTEGER */ + case 61: /* cmd ::= DROP SNODE ON DNODE NK_INTEGER */ { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_SNODE_STMT, &yymsp[0].minor.yy0); } break; - case 60: /* cmd ::= CREATE MNODE ON DNODE NK_INTEGER */ + case 62: /* cmd ::= CREATE MNODE ON DNODE NK_INTEGER */ { pCxt->pRootNode = createCreateComponentNodeStmt(pCxt, QUERY_NODE_CREATE_MNODE_STMT, &yymsp[0].minor.yy0); } break; - case 61: /* cmd ::= DROP MNODE ON DNODE NK_INTEGER */ + case 63: /* cmd ::= DROP MNODE ON DNODE NK_INTEGER */ { pCxt->pRootNode = createDropComponentNodeStmt(pCxt, QUERY_NODE_DROP_MNODE_STMT, &yymsp[0].minor.yy0); } break; - case 62: /* cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ -{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy39, &yymsp[-1].minor.yy181, yymsp[0].minor.yy778); } - break; - case 63: /* cmd ::= DROP DATABASE exists_opt db_name */ -{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy39, &yymsp[0].minor.yy181); } + case 64: /* cmd ::= CREATE DATABASE not_exists_opt db_name db_options */ +{ pCxt->pRootNode = createCreateDatabaseStmt(pCxt, yymsp[-2].minor.yy777, &yymsp[-1].minor.yy481, yymsp[0].minor.yy232); } break; - case 64: /* cmd ::= USE db_name */ -{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy181); } + case 65: /* cmd ::= DROP DATABASE exists_opt db_name */ +{ pCxt->pRootNode = createDropDatabaseStmt(pCxt, yymsp[-1].minor.yy777, &yymsp[0].minor.yy481); } break; - case 65: /* cmd ::= ALTER DATABASE db_name alter_db_options */ -{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy181, yymsp[0].minor.yy778); } + case 66: /* cmd ::= USE db_name */ +{ pCxt->pRootNode = createUseDatabaseStmt(pCxt, &yymsp[0].minor.yy481); } break; - case 66: /* cmd ::= FLUSH DATABASE db_name */ -{ pCxt->pRootNode = createFlushDatabaseStmt(pCxt, &yymsp[0].minor.yy181); } + case 67: /* cmd ::= ALTER DATABASE db_name alter_db_options */ +{ pCxt->pRootNode = createAlterDatabaseStmt(pCxt, &yymsp[-1].minor.yy481, yymsp[0].minor.yy232); } break; - case 67: /* cmd ::= TRIM DATABASE db_name speed_opt */ -{ pCxt->pRootNode = createTrimDatabaseStmt(pCxt, &yymsp[-1].minor.yy181, yymsp[0].minor.yy276); } + case 68: /* cmd ::= FLUSH DATABASE db_name */ +{ pCxt->pRootNode = createFlushDatabaseStmt(pCxt, &yymsp[0].minor.yy481); } break; - case 68: /* not_exists_opt ::= IF NOT EXISTS */ -{ yymsp[-2].minor.yy39 = true; } + case 69: /* cmd ::= TRIM DATABASE db_name speed_opt */ +{ pCxt->pRootNode = createTrimDatabaseStmt(pCxt, &yymsp[-1].minor.yy481, yymsp[0].minor.yy692); } break; - case 69: /* not_exists_opt ::= */ - case 71: /* exists_opt ::= */ yytestcase(yyruleno==71); - case 269: /* analyze_opt ::= */ yytestcase(yyruleno==269); - case 276: /* agg_func_opt ::= */ yytestcase(yyruleno==276); - case 450: /* set_quantifier_opt ::= */ yytestcase(yyruleno==450); -{ yymsp[1].minor.yy39 = false; } + case 70: /* not_exists_opt ::= IF NOT EXISTS */ +{ yymsp[-2].minor.yy777 = true; } break; - case 70: /* exists_opt ::= IF EXISTS */ -{ yymsp[-1].minor.yy39 = true; } + case 72: /* exists_opt ::= IF EXISTS */ +{ yymsp[-1].minor.yy777 = true; } break; - case 72: /* db_options ::= */ -{ yymsp[1].minor.yy778 = createDefaultDatabaseOptions(pCxt); } + case 74: /* db_options ::= */ +{ yymsp[1].minor.yy232 = createDefaultDatabaseOptions(pCxt); } break; - case 73: /* db_options ::= db_options BUFFER NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_BUFFER, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 75: /* db_options ::= db_options BUFFER NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_BUFFER, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 74: /* db_options ::= db_options CACHEMODEL NK_STRING */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_CACHEMODEL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 76: /* db_options ::= db_options CACHEMODEL NK_STRING */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_CACHEMODEL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 75: /* db_options ::= db_options CACHESIZE NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_CACHESIZE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 77: /* db_options ::= db_options CACHESIZE NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_CACHESIZE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 76: /* db_options ::= db_options COMP NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_COMP, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 78: /* db_options ::= db_options COMP NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_COMP, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 77: /* db_options ::= db_options DURATION NK_INTEGER */ - case 78: /* db_options ::= db_options DURATION NK_VARIABLE */ yytestcase(yyruleno==78); -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 79: /* db_options ::= db_options DURATION NK_INTEGER */ + case 80: /* db_options ::= db_options DURATION NK_VARIABLE */ yytestcase(yyruleno==80); +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_DAYS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 79: /* db_options ::= db_options MAXROWS NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 81: /* db_options ::= db_options MAXROWS NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_MAXROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 80: /* db_options ::= db_options MINROWS NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 82: /* db_options ::= db_options MINROWS NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_MINROWS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 81: /* db_options ::= db_options KEEP integer_list */ - case 82: /* db_options ::= db_options KEEP variable_list */ yytestcase(yyruleno==82); -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_KEEP, yymsp[0].minor.yy282); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 83: /* db_options ::= db_options KEEP integer_list */ + case 84: /* db_options ::= db_options KEEP variable_list */ yytestcase(yyruleno==84); +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_KEEP, yymsp[0].minor.yy288); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 83: /* db_options ::= db_options PAGES NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_PAGES, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 85: /* db_options ::= db_options PAGES NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_PAGES, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 84: /* db_options ::= db_options PAGESIZE NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_PAGESIZE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 86: /* db_options ::= db_options PAGESIZE NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_PAGESIZE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 85: /* db_options ::= db_options TSDB_PAGESIZE NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_TSDB_PAGESIZE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 87: /* db_options ::= db_options TSDB_PAGESIZE NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_TSDB_PAGESIZE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 86: /* db_options ::= db_options PRECISION NK_STRING */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 88: /* db_options ::= db_options PRECISION NK_STRING */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_PRECISION, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 87: /* db_options ::= db_options REPLICA NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 89: /* db_options ::= db_options REPLICA NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_REPLICA, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 88: /* db_options ::= db_options STRICT NK_STRING */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_STRICT, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 90: /* db_options ::= db_options STRICT NK_STRING */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_STRICT, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 89: /* db_options ::= db_options VGROUPS NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 91: /* db_options ::= db_options VGROUPS NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_VGROUPS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 90: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 92: /* db_options ::= db_options SINGLE_STABLE NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_SINGLE_STABLE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 91: /* db_options ::= db_options RETENTIONS retention_list */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_RETENTIONS, yymsp[0].minor.yy282); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 93: /* db_options ::= db_options RETENTIONS retention_list */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_RETENTIONS, yymsp[0].minor.yy288); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 92: /* db_options ::= db_options SCHEMALESS NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_SCHEMALESS, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 94: /* db_options ::= db_options SCHEMALESS NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_SCHEMALESS, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 93: /* db_options ::= db_options WAL_LEVEL NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_WAL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 95: /* db_options ::= db_options WAL_LEVEL NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_WAL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 94: /* db_options ::= db_options WAL_FSYNC_PERIOD NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 96: /* db_options ::= db_options WAL_FSYNC_PERIOD NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_FSYNC, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 95: /* db_options ::= db_options WAL_RETENTION_PERIOD NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_WAL_RETENTION_PERIOD, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 97: /* db_options ::= db_options WAL_RETENTION_PERIOD NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_WAL_RETENTION_PERIOD, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 96: /* db_options ::= db_options WAL_RETENTION_PERIOD NK_MINUS NK_INTEGER */ + case 98: /* db_options ::= db_options WAL_RETENTION_PERIOD NK_MINUS NK_INTEGER */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-3].minor.yy778, DB_OPTION_WAL_RETENTION_PERIOD, &t); + yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-3].minor.yy232, DB_OPTION_WAL_RETENTION_PERIOD, &t); } - yymsp[-3].minor.yy778 = yylhsminor.yy778; + yymsp[-3].minor.yy232 = yylhsminor.yy232; break; - case 97: /* db_options ::= db_options WAL_RETENTION_SIZE NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_WAL_RETENTION_SIZE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 99: /* db_options ::= db_options WAL_RETENTION_SIZE NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_WAL_RETENTION_SIZE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 98: /* db_options ::= db_options WAL_RETENTION_SIZE NK_MINUS NK_INTEGER */ + case 100: /* db_options ::= db_options WAL_RETENTION_SIZE NK_MINUS NK_INTEGER */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-3].minor.yy778, DB_OPTION_WAL_RETENTION_SIZE, &t); + yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-3].minor.yy232, DB_OPTION_WAL_RETENTION_SIZE, &t); } - yymsp[-3].minor.yy778 = yylhsminor.yy778; - break; - case 99: /* db_options ::= db_options WAL_ROLL_PERIOD NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_WAL_ROLL_PERIOD, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; - break; - case 100: /* db_options ::= db_options WAL_SEGMENT_SIZE NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_WAL_SEGMENT_SIZE, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; - break; - case 101: /* db_options ::= db_options STT_TRIGGER NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_STT_TRIGGER, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; - break; - case 102: /* db_options ::= db_options TABLE_PREFIX NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_TABLE_PREFIX, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; - break; - case 103: /* db_options ::= db_options TABLE_SUFFIX NK_INTEGER */ -{ yylhsminor.yy778 = setDatabaseOption(pCxt, yymsp[-2].minor.yy778, DB_OPTION_TABLE_SUFFIX, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; - break; - case 104: /* alter_db_options ::= alter_db_option */ -{ yylhsminor.yy778 = createAlterDatabaseOptions(pCxt); yylhsminor.yy778 = setAlterDatabaseOption(pCxt, yylhsminor.yy778, &yymsp[0].minor.yy645); } - yymsp[0].minor.yy778 = yylhsminor.yy778; - break; - case 105: /* alter_db_options ::= alter_db_options alter_db_option */ -{ yylhsminor.yy778 = setAlterDatabaseOption(pCxt, yymsp[-1].minor.yy778, &yymsp[0].minor.yy645); } - yymsp[-1].minor.yy778 = yylhsminor.yy778; - break; - case 106: /* alter_db_option ::= BUFFER NK_INTEGER */ -{ yymsp[-1].minor.yy645.type = DB_OPTION_BUFFER; yymsp[-1].minor.yy645.val = yymsp[0].minor.yy0; } - break; - case 107: /* alter_db_option ::= CACHEMODEL NK_STRING */ -{ yymsp[-1].minor.yy645.type = DB_OPTION_CACHEMODEL; yymsp[-1].minor.yy645.val = yymsp[0].minor.yy0; } - break; - case 108: /* alter_db_option ::= CACHESIZE NK_INTEGER */ -{ yymsp[-1].minor.yy645.type = DB_OPTION_CACHESIZE; yymsp[-1].minor.yy645.val = yymsp[0].minor.yy0; } - break; - case 109: /* alter_db_option ::= WAL_FSYNC_PERIOD NK_INTEGER */ -{ yymsp[-1].minor.yy645.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy645.val = yymsp[0].minor.yy0; } - break; - case 110: /* alter_db_option ::= KEEP integer_list */ - case 111: /* alter_db_option ::= KEEP variable_list */ yytestcase(yyruleno==111); -{ yymsp[-1].minor.yy645.type = DB_OPTION_KEEP; yymsp[-1].minor.yy645.pList = yymsp[0].minor.yy282; } - break; - case 112: /* alter_db_option ::= PAGES NK_INTEGER */ -{ yymsp[-1].minor.yy645.type = DB_OPTION_PAGES; yymsp[-1].minor.yy645.val = yymsp[0].minor.yy0; } - break; - case 113: /* alter_db_option ::= REPLICA NK_INTEGER */ -{ yymsp[-1].minor.yy645.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy645.val = yymsp[0].minor.yy0; } - break; - case 114: /* alter_db_option ::= STRICT NK_STRING */ -{ yymsp[-1].minor.yy645.type = DB_OPTION_STRICT; yymsp[-1].minor.yy645.val = yymsp[0].minor.yy0; } - break; - case 115: /* alter_db_option ::= WAL_LEVEL NK_INTEGER */ -{ yymsp[-1].minor.yy645.type = DB_OPTION_WAL; yymsp[-1].minor.yy645.val = yymsp[0].minor.yy0; } - break; - case 116: /* alter_db_option ::= STT_TRIGGER NK_INTEGER */ -{ yymsp[-1].minor.yy645.type = DB_OPTION_STT_TRIGGER; yymsp[-1].minor.yy645.val = yymsp[0].minor.yy0; } - break; - case 117: /* integer_list ::= NK_INTEGER */ -{ yylhsminor.yy282 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy282 = yylhsminor.yy282; - break; - case 118: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ - case 298: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==298); -{ yylhsminor.yy282 = addNodeToList(pCxt, yymsp[-2].minor.yy282, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy282 = yylhsminor.yy282; - break; - case 119: /* variable_list ::= NK_VARIABLE */ -{ yylhsminor.yy282 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy282 = yylhsminor.yy282; - break; - case 120: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */ -{ yylhsminor.yy282 = addNodeToList(pCxt, yymsp[-2].minor.yy282, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy282 = yylhsminor.yy282; - break; - case 121: /* retention_list ::= retention */ - case 143: /* multi_create_clause ::= create_subtable_clause */ yytestcase(yyruleno==143); - case 146: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==146); - case 153: /* column_def_list ::= column_def */ yytestcase(yyruleno==153); - case 196: /* rollup_func_list ::= rollup_func_name */ yytestcase(yyruleno==196); - case 201: /* col_name_list ::= col_name */ yytestcase(yyruleno==201); - case 252: /* func_list ::= func */ yytestcase(yyruleno==252); - case 326: /* literal_list ::= signed_literal */ yytestcase(yyruleno==326); - case 392: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==392); - case 398: /* when_then_list ::= when_then_expr */ yytestcase(yyruleno==398); - case 453: /* select_list ::= select_item */ yytestcase(yyruleno==453); - case 464: /* partition_list ::= partition_item */ yytestcase(yyruleno==464); - case 516: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==516); -{ yylhsminor.yy282 = createNodeList(pCxt, yymsp[0].minor.yy778); } - yymsp[0].minor.yy282 = yylhsminor.yy282; - break; - case 122: /* retention_list ::= retention_list NK_COMMA retention */ - case 154: /* column_def_list ::= column_def_list NK_COMMA column_def */ yytestcase(yyruleno==154); - case 197: /* rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ yytestcase(yyruleno==197); - case 202: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==202); - case 253: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==253); - case 327: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==327); - case 393: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==393); - case 454: /* select_list ::= select_list NK_COMMA select_item */ yytestcase(yyruleno==454); - case 465: /* partition_list ::= partition_list NK_COMMA partition_item */ yytestcase(yyruleno==465); - case 517: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==517); -{ yylhsminor.yy282 = addNodeToList(pCxt, yymsp[-2].minor.yy282, yymsp[0].minor.yy778); } - yymsp[-2].minor.yy282 = yylhsminor.yy282; - break; - case 123: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ -{ yylhsminor.yy778 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; - break; - case 124: /* speed_opt ::= */ - case 278: /* bufsize_opt ::= */ yytestcase(yyruleno==278); -{ yymsp[1].minor.yy276 = 0; } - break; - case 125: /* speed_opt ::= MAX_SPEED NK_INTEGER */ - case 279: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ yytestcase(yyruleno==279); -{ yymsp[-1].minor.yy276 = taosStr2Int32(yymsp[0].minor.yy0.z, NULL, 10); } - break; - case 126: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ - case 128: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==128); -{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy39, yymsp[-5].minor.yy778, yymsp[-3].minor.yy282, yymsp[-1].minor.yy282, yymsp[0].minor.yy778); } - break; - case 127: /* cmd ::= CREATE TABLE multi_create_clause */ -{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy282); } - break; - case 129: /* cmd ::= DROP TABLE multi_drop_clause */ -{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy282); } - break; - case 130: /* cmd ::= DROP STABLE exists_opt full_table_name */ -{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy39, yymsp[0].minor.yy778); } - break; - case 131: /* cmd ::= ALTER TABLE alter_table_clause */ - case 300: /* cmd ::= query_or_subquery */ yytestcase(yyruleno==300); -{ pCxt->pRootNode = yymsp[0].minor.yy778; } - break; - case 132: /* cmd ::= ALTER STABLE alter_table_clause */ -{ pCxt->pRootNode = setAlterSuperTableType(yymsp[0].minor.yy778); } - break; - case 133: /* alter_table_clause ::= full_table_name alter_table_options */ -{ yylhsminor.yy778 = createAlterTableModifyOptions(pCxt, yymsp[-1].minor.yy778, yymsp[0].minor.yy778); } - yymsp[-1].minor.yy778 = yylhsminor.yy778; - break; - case 134: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ -{ yylhsminor.yy778 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy778, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy181, yymsp[0].minor.yy380); } - yymsp[-4].minor.yy778 = yylhsminor.yy778; - break; - case 135: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ -{ yylhsminor.yy778 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy778, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy181); } - yymsp[-3].minor.yy778 = yylhsminor.yy778; - break; - case 136: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ -{ yylhsminor.yy778 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy778, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy181, yymsp[0].minor.yy380); } - yymsp[-4].minor.yy778 = yylhsminor.yy778; - break; - case 137: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ -{ yylhsminor.yy778 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy778, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy181, &yymsp[0].minor.yy181); } - yymsp[-4].minor.yy778 = yylhsminor.yy778; - break; - case 138: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ -{ yylhsminor.yy778 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy778, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy181, yymsp[0].minor.yy380); } - yymsp[-4].minor.yy778 = yylhsminor.yy778; - break; - case 139: /* alter_table_clause ::= full_table_name DROP TAG column_name */ -{ yylhsminor.yy778 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy778, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy181); } - yymsp[-3].minor.yy778 = yylhsminor.yy778; - break; - case 140: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ -{ yylhsminor.yy778 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy778, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy181, yymsp[0].minor.yy380); } - yymsp[-4].minor.yy778 = yylhsminor.yy778; - break; - case 141: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ -{ yylhsminor.yy778 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy778, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy181, &yymsp[0].minor.yy181); } - yymsp[-4].minor.yy778 = yylhsminor.yy778; - break; - case 142: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ -{ yylhsminor.yy778 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy778, &yymsp[-2].minor.yy181, yymsp[0].minor.yy778); } - yymsp[-5].minor.yy778 = yylhsminor.yy778; - break; - case 144: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ - case 147: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==147); - case 399: /* when_then_list ::= when_then_list when_then_expr */ yytestcase(yyruleno==399); -{ yylhsminor.yy282 = addNodeToList(pCxt, yymsp[-1].minor.yy282, yymsp[0].minor.yy778); } - yymsp[-1].minor.yy282 = yylhsminor.yy282; + yymsp[-3].minor.yy232 = yylhsminor.yy232; + break; + case 101: /* db_options ::= db_options WAL_ROLL_PERIOD NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_WAL_ROLL_PERIOD, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; + break; + case 102: /* db_options ::= db_options WAL_SEGMENT_SIZE NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_WAL_SEGMENT_SIZE, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; + break; + case 103: /* db_options ::= db_options STT_TRIGGER NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_STT_TRIGGER, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; + break; + case 104: /* db_options ::= db_options TABLE_PREFIX NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_TABLE_PREFIX, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; + break; + case 105: /* db_options ::= db_options TABLE_SUFFIX NK_INTEGER */ +{ yylhsminor.yy232 = setDatabaseOption(pCxt, yymsp[-2].minor.yy232, DB_OPTION_TABLE_SUFFIX, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; + break; + case 106: /* alter_db_options ::= alter_db_option */ +{ yylhsminor.yy232 = createAlterDatabaseOptions(pCxt); yylhsminor.yy232 = setAlterDatabaseOption(pCxt, yylhsminor.yy232, &yymsp[0].minor.yy101); } + yymsp[0].minor.yy232 = yylhsminor.yy232; + break; + case 107: /* alter_db_options ::= alter_db_options alter_db_option */ +{ yylhsminor.yy232 = setAlterDatabaseOption(pCxt, yymsp[-1].minor.yy232, &yymsp[0].minor.yy101); } + yymsp[-1].minor.yy232 = yylhsminor.yy232; + break; + case 108: /* alter_db_option ::= BUFFER NK_INTEGER */ +{ yymsp[-1].minor.yy101.type = DB_OPTION_BUFFER; yymsp[-1].minor.yy101.val = yymsp[0].minor.yy0; } + break; + case 109: /* alter_db_option ::= CACHEMODEL NK_STRING */ +{ yymsp[-1].minor.yy101.type = DB_OPTION_CACHEMODEL; yymsp[-1].minor.yy101.val = yymsp[0].minor.yy0; } + break; + case 110: /* alter_db_option ::= CACHESIZE NK_INTEGER */ +{ yymsp[-1].minor.yy101.type = DB_OPTION_CACHESIZE; yymsp[-1].minor.yy101.val = yymsp[0].minor.yy0; } + break; + case 111: /* alter_db_option ::= WAL_FSYNC_PERIOD NK_INTEGER */ +{ yymsp[-1].minor.yy101.type = DB_OPTION_FSYNC; yymsp[-1].minor.yy101.val = yymsp[0].minor.yy0; } + break; + case 112: /* alter_db_option ::= KEEP integer_list */ + case 113: /* alter_db_option ::= KEEP variable_list */ yytestcase(yyruleno==113); +{ yymsp[-1].minor.yy101.type = DB_OPTION_KEEP; yymsp[-1].minor.yy101.pList = yymsp[0].minor.yy288; } + break; + case 114: /* alter_db_option ::= PAGES NK_INTEGER */ +{ yymsp[-1].minor.yy101.type = DB_OPTION_PAGES; yymsp[-1].minor.yy101.val = yymsp[0].minor.yy0; } + break; + case 115: /* alter_db_option ::= REPLICA NK_INTEGER */ +{ yymsp[-1].minor.yy101.type = DB_OPTION_REPLICA; yymsp[-1].minor.yy101.val = yymsp[0].minor.yy0; } + break; + case 116: /* alter_db_option ::= STRICT NK_STRING */ +{ yymsp[-1].minor.yy101.type = DB_OPTION_STRICT; yymsp[-1].minor.yy101.val = yymsp[0].minor.yy0; } + break; + case 117: /* alter_db_option ::= WAL_LEVEL NK_INTEGER */ +{ yymsp[-1].minor.yy101.type = DB_OPTION_WAL; yymsp[-1].minor.yy101.val = yymsp[0].minor.yy0; } + break; + case 118: /* alter_db_option ::= STT_TRIGGER NK_INTEGER */ +{ yymsp[-1].minor.yy101.type = DB_OPTION_STT_TRIGGER; yymsp[-1].minor.yy101.val = yymsp[0].minor.yy0; } + break; + case 119: /* integer_list ::= NK_INTEGER */ +{ yylhsminor.yy288 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy288 = yylhsminor.yy288; + break; + case 120: /* integer_list ::= integer_list NK_COMMA NK_INTEGER */ + case 301: /* dnode_list ::= dnode_list DNODE NK_INTEGER */ yytestcase(yyruleno==301); +{ yylhsminor.yy288 = addNodeToList(pCxt, yymsp[-2].minor.yy288, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy288 = yylhsminor.yy288; + break; + case 121: /* variable_list ::= NK_VARIABLE */ +{ yylhsminor.yy288 = createNodeList(pCxt, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy288 = yylhsminor.yy288; + break; + case 122: /* variable_list ::= variable_list NK_COMMA NK_VARIABLE */ +{ yylhsminor.yy288 = addNodeToList(pCxt, yymsp[-2].minor.yy288, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy288 = yylhsminor.yy288; + break; + case 123: /* retention_list ::= retention */ + case 145: /* multi_create_clause ::= create_subtable_clause */ yytestcase(yyruleno==145); + case 148: /* multi_drop_clause ::= drop_table_clause */ yytestcase(yyruleno==148); + case 155: /* column_def_list ::= column_def */ yytestcase(yyruleno==155); + case 198: /* rollup_func_list ::= rollup_func_name */ yytestcase(yyruleno==198); + case 203: /* col_name_list ::= col_name */ yytestcase(yyruleno==203); + case 254: /* func_list ::= func */ yytestcase(yyruleno==254); + case 329: /* literal_list ::= signed_literal */ yytestcase(yyruleno==329); + case 395: /* other_para_list ::= star_func_para */ yytestcase(yyruleno==395); + case 401: /* when_then_list ::= when_then_expr */ yytestcase(yyruleno==401); + case 456: /* select_list ::= select_item */ yytestcase(yyruleno==456); + case 467: /* partition_list ::= partition_item */ yytestcase(yyruleno==467); + case 519: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==519); +{ yylhsminor.yy288 = createNodeList(pCxt, yymsp[0].minor.yy232); } + yymsp[0].minor.yy288 = yylhsminor.yy288; + break; + case 124: /* retention_list ::= retention_list NK_COMMA retention */ + case 156: /* column_def_list ::= column_def_list NK_COMMA column_def */ yytestcase(yyruleno==156); + case 199: /* rollup_func_list ::= rollup_func_list NK_COMMA rollup_func_name */ yytestcase(yyruleno==199); + case 204: /* col_name_list ::= col_name_list NK_COMMA col_name */ yytestcase(yyruleno==204); + case 255: /* func_list ::= func_list NK_COMMA func */ yytestcase(yyruleno==255); + case 330: /* literal_list ::= literal_list NK_COMMA signed_literal */ yytestcase(yyruleno==330); + case 396: /* other_para_list ::= other_para_list NK_COMMA star_func_para */ yytestcase(yyruleno==396); + case 457: /* select_list ::= select_list NK_COMMA select_item */ yytestcase(yyruleno==457); + case 468: /* partition_list ::= partition_list NK_COMMA partition_item */ yytestcase(yyruleno==468); + case 520: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==520); +{ yylhsminor.yy288 = addNodeToList(pCxt, yymsp[-2].minor.yy288, yymsp[0].minor.yy232); } + yymsp[-2].minor.yy288 = yylhsminor.yy288; + break; + case 125: /* retention ::= NK_VARIABLE NK_COLON NK_VARIABLE */ +{ yylhsminor.yy232 = createNodeListNodeEx(pCxt, createDurationValueNode(pCxt, &yymsp[-2].minor.yy0), createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; + break; + case 126: /* speed_opt ::= */ + case 280: /* bufsize_opt ::= */ yytestcase(yyruleno==280); +{ yymsp[1].minor.yy692 = 0; } + break; + case 127: /* speed_opt ::= MAX_SPEED NK_INTEGER */ + case 281: /* bufsize_opt ::= BUFSIZE NK_INTEGER */ yytestcase(yyruleno==281); +{ yymsp[-1].minor.yy692 = taosStr2Int32(yymsp[0].minor.yy0.z, NULL, 10); } + break; + case 128: /* cmd ::= CREATE TABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def_opt table_options */ + case 130: /* cmd ::= CREATE STABLE not_exists_opt full_table_name NK_LP column_def_list NK_RP tags_def table_options */ yytestcase(yyruleno==130); +{ pCxt->pRootNode = createCreateTableStmt(pCxt, yymsp[-6].minor.yy777, yymsp[-5].minor.yy232, yymsp[-3].minor.yy288, yymsp[-1].minor.yy288, yymsp[0].minor.yy232); } + break; + case 129: /* cmd ::= CREATE TABLE multi_create_clause */ +{ pCxt->pRootNode = createCreateMultiTableStmt(pCxt, yymsp[0].minor.yy288); } + break; + case 131: /* cmd ::= DROP TABLE multi_drop_clause */ +{ pCxt->pRootNode = createDropTableStmt(pCxt, yymsp[0].minor.yy288); } + break; + case 132: /* cmd ::= DROP STABLE exists_opt full_table_name */ +{ pCxt->pRootNode = createDropSuperTableStmt(pCxt, yymsp[-1].minor.yy777, yymsp[0].minor.yy232); } + break; + case 133: /* cmd ::= ALTER TABLE alter_table_clause */ + case 303: /* cmd ::= query_or_subquery */ yytestcase(yyruleno==303); +{ pCxt->pRootNode = yymsp[0].minor.yy232; } + break; + case 134: /* cmd ::= ALTER STABLE alter_table_clause */ +{ pCxt->pRootNode = setAlterSuperTableType(yymsp[0].minor.yy232); } + break; + case 135: /* alter_table_clause ::= full_table_name alter_table_options */ +{ yylhsminor.yy232 = createAlterTableModifyOptions(pCxt, yymsp[-1].minor.yy232, yymsp[0].minor.yy232); } + yymsp[-1].minor.yy232 = yylhsminor.yy232; + break; + case 136: /* alter_table_clause ::= full_table_name ADD COLUMN column_name type_name */ +{ yylhsminor.yy232 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy232, TSDB_ALTER_TABLE_ADD_COLUMN, &yymsp[-1].minor.yy481, yymsp[0].minor.yy264); } + yymsp[-4].minor.yy232 = yylhsminor.yy232; + break; + case 137: /* alter_table_clause ::= full_table_name DROP COLUMN column_name */ +{ yylhsminor.yy232 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy232, TSDB_ALTER_TABLE_DROP_COLUMN, &yymsp[0].minor.yy481); } + yymsp[-3].minor.yy232 = yylhsminor.yy232; + break; + case 138: /* alter_table_clause ::= full_table_name MODIFY COLUMN column_name type_name */ +{ yylhsminor.yy232 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy232, TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES, &yymsp[-1].minor.yy481, yymsp[0].minor.yy264); } + yymsp[-4].minor.yy232 = yylhsminor.yy232; + break; + case 139: /* alter_table_clause ::= full_table_name RENAME COLUMN column_name column_name */ +{ yylhsminor.yy232 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy232, TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME, &yymsp[-1].minor.yy481, &yymsp[0].minor.yy481); } + yymsp[-4].minor.yy232 = yylhsminor.yy232; + break; + case 140: /* alter_table_clause ::= full_table_name ADD TAG column_name type_name */ +{ yylhsminor.yy232 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy232, TSDB_ALTER_TABLE_ADD_TAG, &yymsp[-1].minor.yy481, yymsp[0].minor.yy264); } + yymsp[-4].minor.yy232 = yylhsminor.yy232; + break; + case 141: /* alter_table_clause ::= full_table_name DROP TAG column_name */ +{ yylhsminor.yy232 = createAlterTableDropCol(pCxt, yymsp[-3].minor.yy232, TSDB_ALTER_TABLE_DROP_TAG, &yymsp[0].minor.yy481); } + yymsp[-3].minor.yy232 = yylhsminor.yy232; + break; + case 142: /* alter_table_clause ::= full_table_name MODIFY TAG column_name type_name */ +{ yylhsminor.yy232 = createAlterTableAddModifyCol(pCxt, yymsp[-4].minor.yy232, TSDB_ALTER_TABLE_UPDATE_TAG_BYTES, &yymsp[-1].minor.yy481, yymsp[0].minor.yy264); } + yymsp[-4].minor.yy232 = yylhsminor.yy232; + break; + case 143: /* alter_table_clause ::= full_table_name RENAME TAG column_name column_name */ +{ yylhsminor.yy232 = createAlterTableRenameCol(pCxt, yymsp[-4].minor.yy232, TSDB_ALTER_TABLE_UPDATE_TAG_NAME, &yymsp[-1].minor.yy481, &yymsp[0].minor.yy481); } + yymsp[-4].minor.yy232 = yylhsminor.yy232; + break; + case 144: /* alter_table_clause ::= full_table_name SET TAG column_name NK_EQ signed_literal */ +{ yylhsminor.yy232 = createAlterTableSetTag(pCxt, yymsp[-5].minor.yy232, &yymsp[-2].minor.yy481, yymsp[0].minor.yy232); } + yymsp[-5].minor.yy232 = yylhsminor.yy232; + break; + case 146: /* multi_create_clause ::= multi_create_clause create_subtable_clause */ + case 149: /* multi_drop_clause ::= multi_drop_clause drop_table_clause */ yytestcase(yyruleno==149); + case 402: /* when_then_list ::= when_then_list when_then_expr */ yytestcase(yyruleno==402); +{ yylhsminor.yy288 = addNodeToList(pCxt, yymsp[-1].minor.yy288, yymsp[0].minor.yy232); } + yymsp[-1].minor.yy288 = yylhsminor.yy288; break; - case 145: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options */ -{ yylhsminor.yy778 = createCreateSubTableClause(pCxt, yymsp[-9].minor.yy39, yymsp[-8].minor.yy778, yymsp[-6].minor.yy778, yymsp[-5].minor.yy282, yymsp[-2].minor.yy282, yymsp[0].minor.yy778); } - yymsp[-9].minor.yy778 = yylhsminor.yy778; + case 147: /* create_subtable_clause ::= not_exists_opt full_table_name USING full_table_name specific_cols_opt TAGS NK_LP expression_list NK_RP table_options */ +{ yylhsminor.yy232 = createCreateSubTableClause(pCxt, yymsp[-9].minor.yy777, yymsp[-8].minor.yy232, yymsp[-6].minor.yy232, yymsp[-5].minor.yy288, yymsp[-2].minor.yy288, yymsp[0].minor.yy232); } + yymsp[-9].minor.yy232 = yylhsminor.yy232; break; - case 148: /* drop_table_clause ::= exists_opt full_table_name */ -{ yylhsminor.yy778 = createDropTableClause(pCxt, yymsp[-1].minor.yy39, yymsp[0].minor.yy778); } - yymsp[-1].minor.yy778 = yylhsminor.yy778; + case 150: /* drop_table_clause ::= exists_opt full_table_name */ +{ yylhsminor.yy232 = createDropTableClause(pCxt, yymsp[-1].minor.yy777, yymsp[0].minor.yy232); } + yymsp[-1].minor.yy232 = yylhsminor.yy232; break; - case 149: /* specific_cols_opt ::= */ - case 180: /* tags_def_opt ::= */ yytestcase(yyruleno==180); - case 462: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==462); - case 484: /* group_by_clause_opt ::= */ yytestcase(yyruleno==484); - case 503: /* order_by_clause_opt ::= */ yytestcase(yyruleno==503); -{ yymsp[1].minor.yy282 = NULL; } + case 151: /* specific_cols_opt ::= */ + case 182: /* tags_def_opt ::= */ yytestcase(yyruleno==182); + case 465: /* partition_by_clause_opt ::= */ yytestcase(yyruleno==465); + case 487: /* group_by_clause_opt ::= */ yytestcase(yyruleno==487); + case 506: /* order_by_clause_opt ::= */ yytestcase(yyruleno==506); +{ yymsp[1].minor.yy288 = NULL; } break; - case 150: /* specific_cols_opt ::= NK_LP col_name_list NK_RP */ -{ yymsp[-2].minor.yy282 = yymsp[-1].minor.yy282; } + case 152: /* specific_cols_opt ::= NK_LP col_name_list NK_RP */ +{ yymsp[-2].minor.yy288 = yymsp[-1].minor.yy288; } break; - case 151: /* full_table_name ::= table_name */ -{ yylhsminor.yy778 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy181, NULL); } - yymsp[0].minor.yy778 = yylhsminor.yy778; + case 153: /* full_table_name ::= table_name */ +{ yylhsminor.yy232 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy481, NULL); } + yymsp[0].minor.yy232 = yylhsminor.yy232; break; - case 152: /* full_table_name ::= db_name NK_DOT table_name */ -{ yylhsminor.yy778 = createRealTableNode(pCxt, &yymsp[-2].minor.yy181, &yymsp[0].minor.yy181, NULL); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 154: /* full_table_name ::= db_name NK_DOT table_name */ +{ yylhsminor.yy232 = createRealTableNode(pCxt, &yymsp[-2].minor.yy481, &yymsp[0].minor.yy481, NULL); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 155: /* column_def ::= column_name type_name */ -{ yylhsminor.yy778 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy181, yymsp[0].minor.yy380, NULL); } - yymsp[-1].minor.yy778 = yylhsminor.yy778; + case 157: /* column_def ::= column_name type_name */ +{ yylhsminor.yy232 = createColumnDefNode(pCxt, &yymsp[-1].minor.yy481, yymsp[0].minor.yy264, NULL); } + yymsp[-1].minor.yy232 = yylhsminor.yy232; break; - case 156: /* column_def ::= column_name type_name COMMENT NK_STRING */ -{ yylhsminor.yy778 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy181, yymsp[-2].minor.yy380, &yymsp[0].minor.yy0); } - yymsp[-3].minor.yy778 = yylhsminor.yy778; + case 158: /* column_def ::= column_name type_name COMMENT NK_STRING */ +{ yylhsminor.yy232 = createColumnDefNode(pCxt, &yymsp[-3].minor.yy481, yymsp[-2].minor.yy264, &yymsp[0].minor.yy0); } + yymsp[-3].minor.yy232 = yylhsminor.yy232; break; - case 157: /* type_name ::= BOOL */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_BOOL); } + case 159: /* type_name ::= BOOL */ +{ yymsp[0].minor.yy264 = createDataType(TSDB_DATA_TYPE_BOOL); } break; - case 158: /* type_name ::= TINYINT */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_TINYINT); } + case 160: /* type_name ::= TINYINT */ +{ yymsp[0].minor.yy264 = createDataType(TSDB_DATA_TYPE_TINYINT); } break; - case 159: /* type_name ::= SMALLINT */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_SMALLINT); } + case 161: /* type_name ::= SMALLINT */ +{ yymsp[0].minor.yy264 = createDataType(TSDB_DATA_TYPE_SMALLINT); } break; - case 160: /* type_name ::= INT */ - case 161: /* type_name ::= INTEGER */ yytestcase(yyruleno==161); -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_INT); } + case 162: /* type_name ::= INT */ + case 163: /* type_name ::= INTEGER */ yytestcase(yyruleno==163); +{ yymsp[0].minor.yy264 = createDataType(TSDB_DATA_TYPE_INT); } break; - case 162: /* type_name ::= BIGINT */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_BIGINT); } + case 164: /* type_name ::= BIGINT */ +{ yymsp[0].minor.yy264 = createDataType(TSDB_DATA_TYPE_BIGINT); } break; - case 163: /* type_name ::= FLOAT */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_FLOAT); } + case 165: /* type_name ::= FLOAT */ +{ yymsp[0].minor.yy264 = createDataType(TSDB_DATA_TYPE_FLOAT); } break; - case 164: /* type_name ::= DOUBLE */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_DOUBLE); } + case 166: /* type_name ::= DOUBLE */ +{ yymsp[0].minor.yy264 = createDataType(TSDB_DATA_TYPE_DOUBLE); } break; - case 165: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy380 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } + case 167: /* type_name ::= BINARY NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy264 = createVarLenDataType(TSDB_DATA_TYPE_BINARY, &yymsp[-1].minor.yy0); } break; - case 166: /* type_name ::= TIMESTAMP */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } + case 168: /* type_name ::= TIMESTAMP */ +{ yymsp[0].minor.yy264 = createDataType(TSDB_DATA_TYPE_TIMESTAMP); } break; - case 167: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy380 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } + case 169: /* type_name ::= NCHAR NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy264 = createVarLenDataType(TSDB_DATA_TYPE_NCHAR, &yymsp[-1].minor.yy0); } break; - case 168: /* type_name ::= TINYINT UNSIGNED */ -{ yymsp[-1].minor.yy380 = createDataType(TSDB_DATA_TYPE_UTINYINT); } + case 170: /* type_name ::= TINYINT UNSIGNED */ +{ yymsp[-1].minor.yy264 = createDataType(TSDB_DATA_TYPE_UTINYINT); } break; - case 169: /* type_name ::= SMALLINT UNSIGNED */ -{ yymsp[-1].minor.yy380 = createDataType(TSDB_DATA_TYPE_USMALLINT); } + case 171: /* type_name ::= SMALLINT UNSIGNED */ +{ yymsp[-1].minor.yy264 = createDataType(TSDB_DATA_TYPE_USMALLINT); } break; - case 170: /* type_name ::= INT UNSIGNED */ -{ yymsp[-1].minor.yy380 = createDataType(TSDB_DATA_TYPE_UINT); } + case 172: /* type_name ::= INT UNSIGNED */ +{ yymsp[-1].minor.yy264 = createDataType(TSDB_DATA_TYPE_UINT); } break; - case 171: /* type_name ::= BIGINT UNSIGNED */ -{ yymsp[-1].minor.yy380 = createDataType(TSDB_DATA_TYPE_UBIGINT); } + case 173: /* type_name ::= BIGINT UNSIGNED */ +{ yymsp[-1].minor.yy264 = createDataType(TSDB_DATA_TYPE_UBIGINT); } break; - case 172: /* type_name ::= JSON */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_JSON); } + case 174: /* type_name ::= JSON */ +{ yymsp[0].minor.yy264 = createDataType(TSDB_DATA_TYPE_JSON); } break; - case 173: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy380 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } + case 175: /* type_name ::= VARCHAR NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy264 = createVarLenDataType(TSDB_DATA_TYPE_VARCHAR, &yymsp[-1].minor.yy0); } break; - case 174: /* type_name ::= MEDIUMBLOB */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } + case 176: /* type_name ::= MEDIUMBLOB */ +{ yymsp[0].minor.yy264 = createDataType(TSDB_DATA_TYPE_MEDIUMBLOB); } break; - case 175: /* type_name ::= BLOB */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_BLOB); } + case 177: /* type_name ::= BLOB */ +{ yymsp[0].minor.yy264 = createDataType(TSDB_DATA_TYPE_BLOB); } break; - case 176: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy380 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } + case 178: /* type_name ::= VARBINARY NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy264 = createVarLenDataType(TSDB_DATA_TYPE_VARBINARY, &yymsp[-1].minor.yy0); } break; - case 177: /* type_name ::= DECIMAL */ -{ yymsp[0].minor.yy380 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 179: /* type_name ::= DECIMAL */ +{ yymsp[0].minor.yy264 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 178: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ -{ yymsp[-3].minor.yy380 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 180: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_RP */ +{ yymsp[-3].minor.yy264 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 179: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ -{ yymsp[-5].minor.yy380 = createDataType(TSDB_DATA_TYPE_DECIMAL); } + case 181: /* type_name ::= DECIMAL NK_LP NK_INTEGER NK_COMMA NK_INTEGER NK_RP */ +{ yymsp[-5].minor.yy264 = createDataType(TSDB_DATA_TYPE_DECIMAL); } break; - case 181: /* tags_def_opt ::= tags_def */ - case 391: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==391); -{ yylhsminor.yy282 = yymsp[0].minor.yy282; } - yymsp[0].minor.yy282 = yylhsminor.yy282; + case 183: /* tags_def_opt ::= tags_def */ + case 394: /* star_func_para_list ::= other_para_list */ yytestcase(yyruleno==394); +{ yylhsminor.yy288 = yymsp[0].minor.yy288; } + yymsp[0].minor.yy288 = yylhsminor.yy288; break; - case 182: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ -{ yymsp[-3].minor.yy282 = yymsp[-1].minor.yy282; } + case 184: /* tags_def ::= TAGS NK_LP column_def_list NK_RP */ +{ yymsp[-3].minor.yy288 = yymsp[-1].minor.yy288; } break; - case 183: /* table_options ::= */ -{ yymsp[1].minor.yy778 = createDefaultTableOptions(pCxt); } + case 185: /* table_options ::= */ +{ yymsp[1].minor.yy232 = createDefaultTableOptions(pCxt); } break; - case 184: /* table_options ::= table_options COMMENT NK_STRING */ -{ yylhsminor.yy778 = setTableOption(pCxt, yymsp[-2].minor.yy778, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 186: /* table_options ::= table_options COMMENT NK_STRING */ +{ yylhsminor.yy232 = setTableOption(pCxt, yymsp[-2].minor.yy232, TABLE_OPTION_COMMENT, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 185: /* table_options ::= table_options MAX_DELAY duration_list */ -{ yylhsminor.yy778 = setTableOption(pCxt, yymsp[-2].minor.yy778, TABLE_OPTION_MAXDELAY, yymsp[0].minor.yy282); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 187: /* table_options ::= table_options MAX_DELAY duration_list */ +{ yylhsminor.yy232 = setTableOption(pCxt, yymsp[-2].minor.yy232, TABLE_OPTION_MAXDELAY, yymsp[0].minor.yy288); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 186: /* table_options ::= table_options WATERMARK duration_list */ -{ yylhsminor.yy778 = setTableOption(pCxt, yymsp[-2].minor.yy778, TABLE_OPTION_WATERMARK, yymsp[0].minor.yy282); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 188: /* table_options ::= table_options WATERMARK duration_list */ +{ yylhsminor.yy232 = setTableOption(pCxt, yymsp[-2].minor.yy232, TABLE_OPTION_WATERMARK, yymsp[0].minor.yy288); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 187: /* table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ -{ yylhsminor.yy778 = setTableOption(pCxt, yymsp[-4].minor.yy778, TABLE_OPTION_ROLLUP, yymsp[-1].minor.yy282); } - yymsp[-4].minor.yy778 = yylhsminor.yy778; + case 189: /* table_options ::= table_options ROLLUP NK_LP rollup_func_list NK_RP */ +{ yylhsminor.yy232 = setTableOption(pCxt, yymsp[-4].minor.yy232, TABLE_OPTION_ROLLUP, yymsp[-1].minor.yy288); } + yymsp[-4].minor.yy232 = yylhsminor.yy232; break; - case 188: /* table_options ::= table_options TTL NK_INTEGER */ -{ yylhsminor.yy778 = setTableOption(pCxt, yymsp[-2].minor.yy778, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 190: /* table_options ::= table_options TTL NK_INTEGER */ +{ yylhsminor.yy232 = setTableOption(pCxt, yymsp[-2].minor.yy232, TABLE_OPTION_TTL, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 189: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ -{ yylhsminor.yy778 = setTableOption(pCxt, yymsp[-4].minor.yy778, TABLE_OPTION_SMA, yymsp[-1].minor.yy282); } - yymsp[-4].minor.yy778 = yylhsminor.yy778; + case 191: /* table_options ::= table_options SMA NK_LP col_name_list NK_RP */ +{ yylhsminor.yy232 = setTableOption(pCxt, yymsp[-4].minor.yy232, TABLE_OPTION_SMA, yymsp[-1].minor.yy288); } + yymsp[-4].minor.yy232 = yylhsminor.yy232; break; - case 190: /* alter_table_options ::= alter_table_option */ -{ yylhsminor.yy778 = createAlterTableOptions(pCxt); yylhsminor.yy778 = setTableOption(pCxt, yylhsminor.yy778, yymsp[0].minor.yy645.type, &yymsp[0].minor.yy645.val); } - yymsp[0].minor.yy778 = yylhsminor.yy778; + case 192: /* alter_table_options ::= alter_table_option */ +{ yylhsminor.yy232 = createAlterTableOptions(pCxt); yylhsminor.yy232 = setTableOption(pCxt, yylhsminor.yy232, yymsp[0].minor.yy101.type, &yymsp[0].minor.yy101.val); } + yymsp[0].minor.yy232 = yylhsminor.yy232; break; - case 191: /* alter_table_options ::= alter_table_options alter_table_option */ -{ yylhsminor.yy778 = setTableOption(pCxt, yymsp[-1].minor.yy778, yymsp[0].minor.yy645.type, &yymsp[0].minor.yy645.val); } - yymsp[-1].minor.yy778 = yylhsminor.yy778; + case 193: /* alter_table_options ::= alter_table_options alter_table_option */ +{ yylhsminor.yy232 = setTableOption(pCxt, yymsp[-1].minor.yy232, yymsp[0].minor.yy101.type, &yymsp[0].minor.yy101.val); } + yymsp[-1].minor.yy232 = yylhsminor.yy232; break; - case 192: /* alter_table_option ::= COMMENT NK_STRING */ -{ yymsp[-1].minor.yy645.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy645.val = yymsp[0].minor.yy0; } + case 194: /* alter_table_option ::= COMMENT NK_STRING */ +{ yymsp[-1].minor.yy101.type = TABLE_OPTION_COMMENT; yymsp[-1].minor.yy101.val = yymsp[0].minor.yy0; } break; - case 193: /* alter_table_option ::= TTL NK_INTEGER */ -{ yymsp[-1].minor.yy645.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy645.val = yymsp[0].minor.yy0; } + case 195: /* alter_table_option ::= TTL NK_INTEGER */ +{ yymsp[-1].minor.yy101.type = TABLE_OPTION_TTL; yymsp[-1].minor.yy101.val = yymsp[0].minor.yy0; } break; - case 194: /* duration_list ::= duration_literal */ - case 356: /* expression_list ::= expr_or_subquery */ yytestcase(yyruleno==356); -{ yylhsminor.yy282 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy778)); } - yymsp[0].minor.yy282 = yylhsminor.yy282; + case 196: /* duration_list ::= duration_literal */ + case 359: /* expression_list ::= expr_or_subquery */ yytestcase(yyruleno==359); +{ yylhsminor.yy288 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy232)); } + yymsp[0].minor.yy288 = yylhsminor.yy288; break; - case 195: /* duration_list ::= duration_list NK_COMMA duration_literal */ - case 357: /* expression_list ::= expression_list NK_COMMA expr_or_subquery */ yytestcase(yyruleno==357); -{ yylhsminor.yy282 = addNodeToList(pCxt, yymsp[-2].minor.yy282, releaseRawExprNode(pCxt, yymsp[0].minor.yy778)); } - yymsp[-2].minor.yy282 = yylhsminor.yy282; + case 197: /* duration_list ::= duration_list NK_COMMA duration_literal */ + case 360: /* expression_list ::= expression_list NK_COMMA expr_or_subquery */ yytestcase(yyruleno==360); +{ yylhsminor.yy288 = addNodeToList(pCxt, yymsp[-2].minor.yy288, releaseRawExprNode(pCxt, yymsp[0].minor.yy232)); } + yymsp[-2].minor.yy288 = yylhsminor.yy288; break; - case 198: /* rollup_func_name ::= function_name */ -{ yylhsminor.yy778 = createFunctionNode(pCxt, &yymsp[0].minor.yy181, NULL); } - yymsp[0].minor.yy778 = yylhsminor.yy778; + case 200: /* rollup_func_name ::= function_name */ +{ yylhsminor.yy232 = createFunctionNode(pCxt, &yymsp[0].minor.yy481, NULL); } + yymsp[0].minor.yy232 = yylhsminor.yy232; break; - case 199: /* rollup_func_name ::= FIRST */ - case 200: /* rollup_func_name ::= LAST */ yytestcase(yyruleno==200); -{ yylhsminor.yy778 = createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL); } - yymsp[0].minor.yy778 = yylhsminor.yy778; + case 201: /* rollup_func_name ::= FIRST */ + case 202: /* rollup_func_name ::= LAST */ yytestcase(yyruleno==202); +{ yylhsminor.yy232 = createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL); } + yymsp[0].minor.yy232 = yylhsminor.yy232; break; - case 203: /* col_name ::= column_name */ -{ yylhsminor.yy778 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy181); } - yymsp[0].minor.yy778 = yylhsminor.yy778; + case 205: /* col_name ::= column_name */ +{ yylhsminor.yy232 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy481); } + yymsp[0].minor.yy232 = yylhsminor.yy232; break; - case 204: /* cmd ::= SHOW DNODES */ + case 206: /* cmd ::= SHOW DNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT); } break; - case 205: /* cmd ::= SHOW USERS */ + case 207: /* cmd ::= SHOW USERS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT); } break; - case 206: /* cmd ::= SHOW DATABASES */ + case 208: /* cmd ::= SHOW DATABASES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT); } break; - case 207: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy778, yymsp[0].minor.yy778, OP_TYPE_LIKE); } + case 209: /* cmd ::= SHOW db_name_cond_opt TABLES like_pattern_opt */ +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLES_STMT, yymsp[-2].minor.yy232, yymsp[0].minor.yy232, OP_TYPE_LIKE); } break; - case 208: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy778, yymsp[0].minor.yy778, OP_TYPE_LIKE); } + case 210: /* cmd ::= SHOW db_name_cond_opt STABLES like_pattern_opt */ +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_STABLES_STMT, yymsp[-2].minor.yy232, yymsp[0].minor.yy232, OP_TYPE_LIKE); } break; - case 209: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ -{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy778, NULL, OP_TYPE_LIKE); } + case 211: /* cmd ::= SHOW db_name_cond_opt VGROUPS */ +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, yymsp[-1].minor.yy232, NULL, OP_TYPE_LIKE); } break; - case 210: /* cmd ::= SHOW MNODES */ + case 212: /* cmd ::= SHOW MNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_MNODES_STMT); } break; - case 211: /* cmd ::= SHOW QNODES */ + case 213: /* cmd ::= SHOW QNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QNODES_STMT); } break; - case 212: /* cmd ::= SHOW FUNCTIONS */ + case 214: /* cmd ::= SHOW FUNCTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT); } break; - case 213: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ -{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[0].minor.yy778, yymsp[-1].minor.yy778, OP_TYPE_EQUAL); } + case 215: /* cmd ::= SHOW INDEXES FROM table_name_cond from_db_opt */ +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, yymsp[0].minor.yy232, yymsp[-1].minor.yy232, OP_TYPE_EQUAL); } break; - case 214: /* cmd ::= SHOW STREAMS */ + case 216: /* cmd ::= SHOW STREAMS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT); } break; - case 215: /* cmd ::= SHOW ACCOUNTS */ + case 217: /* cmd ::= SHOW ACCOUNTS */ { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); } break; - case 216: /* cmd ::= SHOW APPS */ + case 218: /* cmd ::= SHOW APPS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT); } break; - case 217: /* cmd ::= SHOW CONNECTIONS */ + case 219: /* cmd ::= SHOW CONNECTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT); } break; - case 218: /* cmd ::= SHOW LICENCES */ - case 219: /* cmd ::= SHOW GRANTS */ yytestcase(yyruleno==219); + case 220: /* cmd ::= SHOW LICENCES */ + case 221: /* cmd ::= SHOW GRANTS */ yytestcase(yyruleno==221); { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCES_STMT); } break; - case 220: /* cmd ::= SHOW CREATE DATABASE db_name */ -{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy181); } + case 222: /* cmd ::= SHOW CREATE DATABASE db_name */ +{ pCxt->pRootNode = createShowCreateDatabaseStmt(pCxt, &yymsp[0].minor.yy481); } break; - case 221: /* cmd ::= SHOW CREATE TABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy778); } + case 223: /* cmd ::= SHOW CREATE TABLE full_table_name */ +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_TABLE_STMT, yymsp[0].minor.yy232); } break; - case 222: /* cmd ::= SHOW CREATE STABLE full_table_name */ -{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy778); } + case 224: /* cmd ::= SHOW CREATE STABLE full_table_name */ +{ pCxt->pRootNode = createShowCreateTableStmt(pCxt, QUERY_NODE_SHOW_CREATE_STABLE_STMT, yymsp[0].minor.yy232); } break; - case 223: /* cmd ::= SHOW QUERIES */ + case 225: /* cmd ::= SHOW QUERIES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_QUERIES_STMT); } break; - case 224: /* cmd ::= SHOW SCORES */ + case 226: /* cmd ::= SHOW SCORES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SCORES_STMT); } break; - case 225: /* cmd ::= SHOW TOPICS */ + case 227: /* cmd ::= SHOW TOPICS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TOPICS_STMT); } break; - case 226: /* cmd ::= SHOW VARIABLES */ - case 227: /* cmd ::= SHOW CLUSTER VARIABLES */ yytestcase(yyruleno==227); + case 228: /* cmd ::= SHOW VARIABLES */ + case 229: /* cmd ::= SHOW CLUSTER VARIABLES */ yytestcase(yyruleno==229); { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VARIABLES_STMT); } break; - case 228: /* cmd ::= SHOW LOCAL VARIABLES */ + case 230: /* cmd ::= SHOW LOCAL VARIABLES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT); } break; - case 229: /* cmd ::= SHOW DNODE NK_INTEGER VARIABLES like_pattern_opt */ -{ pCxt->pRootNode = createShowDnodeVariablesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[-2].minor.yy0), yymsp[0].minor.yy778); } + case 231: /* cmd ::= SHOW DNODE NK_INTEGER VARIABLES like_pattern_opt */ +{ pCxt->pRootNode = createShowDnodeVariablesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[-2].minor.yy0), yymsp[0].minor.yy232); } break; - case 230: /* cmd ::= SHOW BNODES */ + case 232: /* cmd ::= SHOW BNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_BNODES_STMT); } break; - case 231: /* cmd ::= SHOW SNODES */ + case 233: /* cmd ::= SHOW SNODES */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT); } break; - case 232: /* cmd ::= SHOW CLUSTER */ + case 234: /* cmd ::= SHOW CLUSTER */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT); } break; - case 233: /* cmd ::= SHOW TRANSACTIONS */ + case 235: /* cmd ::= SHOW TRANSACTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TRANSACTIONS_STMT); } break; - case 234: /* cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ -{ pCxt->pRootNode = createShowTableDistributedStmt(pCxt, yymsp[0].minor.yy778); } + case 236: /* cmd ::= SHOW TABLE DISTRIBUTED full_table_name */ +{ pCxt->pRootNode = createShowTableDistributedStmt(pCxt, yymsp[0].minor.yy232); } break; - case 235: /* cmd ::= SHOW CONSUMERS */ + case 237: /* cmd ::= SHOW CONSUMERS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONSUMERS_STMT); } break; - case 236: /* cmd ::= SHOW SUBSCRIPTIONS */ + case 238: /* cmd ::= SHOW SUBSCRIPTIONS */ { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT); } break; - case 237: /* cmd ::= SHOW TAGS FROM table_name_cond from_db_opt */ -{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TAGS_STMT, yymsp[0].minor.yy778, yymsp[-1].minor.yy778, OP_TYPE_EQUAL); } + case 239: /* cmd ::= SHOW TAGS FROM table_name_cond from_db_opt */ +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TAGS_STMT, yymsp[0].minor.yy232, yymsp[-1].minor.yy232, OP_TYPE_EQUAL); } break; - case 238: /* cmd ::= SHOW TABLE TAGS FROM table_name_cond from_db_opt */ -{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLE_TAGS_STMT, yymsp[0].minor.yy778, yymsp[-1].minor.yy778, OP_TYPE_EQUAL); } + case 240: /* cmd ::= SHOW TABLE TAGS FROM table_name_cond from_db_opt */ +{ pCxt->pRootNode = createShowStmtWithCond(pCxt, QUERY_NODE_SHOW_TABLE_TAGS_STMT, yymsp[0].minor.yy232, yymsp[-1].minor.yy232, OP_TYPE_EQUAL); } break; - case 239: /* cmd ::= SHOW VNODES NK_INTEGER */ + case 241: /* cmd ::= SHOW VNODES NK_INTEGER */ { pCxt->pRootNode = createShowVnodesStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0), NULL); } break; - case 240: /* cmd ::= SHOW VNODES NK_STRING */ + case 242: /* cmd ::= SHOW VNODES NK_STRING */ { pCxt->pRootNode = createShowVnodesStmt(pCxt, NULL, createValueNode(pCxt, TSDB_DATA_TYPE_VARCHAR, &yymsp[0].minor.yy0)); } break; - case 241: /* db_name_cond_opt ::= */ - case 246: /* from_db_opt ::= */ yytestcase(yyruleno==246); -{ yymsp[1].minor.yy778 = createDefaultDatabaseCondValue(pCxt); } + case 243: /* db_name_cond_opt ::= */ + case 248: /* from_db_opt ::= */ yytestcase(yyruleno==248); +{ yymsp[1].minor.yy232 = createDefaultDatabaseCondValue(pCxt); } break; - case 242: /* db_name_cond_opt ::= db_name NK_DOT */ -{ yylhsminor.yy778 = createIdentifierValueNode(pCxt, &yymsp[-1].minor.yy181); } - yymsp[-1].minor.yy778 = yylhsminor.yy778; + case 244: /* db_name_cond_opt ::= db_name NK_DOT */ +{ yylhsminor.yy232 = createIdentifierValueNode(pCxt, &yymsp[-1].minor.yy481); } + yymsp[-1].minor.yy232 = yylhsminor.yy232; break; - case 243: /* like_pattern_opt ::= */ - case 288: /* subtable_opt ::= */ yytestcase(yyruleno==288); - case 401: /* case_when_else_opt ::= */ yytestcase(yyruleno==401); - case 431: /* from_clause_opt ::= */ yytestcase(yyruleno==431); - case 460: /* where_clause_opt ::= */ yytestcase(yyruleno==460); - case 469: /* twindow_clause_opt ::= */ yytestcase(yyruleno==469); - case 474: /* sliding_opt ::= */ yytestcase(yyruleno==474); - case 476: /* fill_opt ::= */ yytestcase(yyruleno==476); - case 488: /* having_clause_opt ::= */ yytestcase(yyruleno==488); - case 490: /* range_opt ::= */ yytestcase(yyruleno==490); - case 492: /* every_opt ::= */ yytestcase(yyruleno==492); - case 505: /* slimit_clause_opt ::= */ yytestcase(yyruleno==505); - case 509: /* limit_clause_opt ::= */ yytestcase(yyruleno==509); -{ yymsp[1].minor.yy778 = NULL; } + case 245: /* like_pattern_opt ::= */ + case 291: /* subtable_opt ::= */ yytestcase(yyruleno==291); + case 404: /* case_when_else_opt ::= */ yytestcase(yyruleno==404); + case 434: /* from_clause_opt ::= */ yytestcase(yyruleno==434); + case 463: /* where_clause_opt ::= */ yytestcase(yyruleno==463); + case 472: /* twindow_clause_opt ::= */ yytestcase(yyruleno==472); + case 477: /* sliding_opt ::= */ yytestcase(yyruleno==477); + case 479: /* fill_opt ::= */ yytestcase(yyruleno==479); + case 491: /* having_clause_opt ::= */ yytestcase(yyruleno==491); + case 493: /* range_opt ::= */ yytestcase(yyruleno==493); + case 495: /* every_opt ::= */ yytestcase(yyruleno==495); + case 508: /* slimit_clause_opt ::= */ yytestcase(yyruleno==508); + case 512: /* limit_clause_opt ::= */ yytestcase(yyruleno==512); +{ yymsp[1].minor.yy232 = NULL; } break; - case 244: /* like_pattern_opt ::= LIKE NK_STRING */ -{ yymsp[-1].minor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + case 246: /* like_pattern_opt ::= LIKE NK_STRING */ +{ yymsp[-1].minor.yy232 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } break; - case 245: /* table_name_cond ::= table_name */ -{ yylhsminor.yy778 = createIdentifierValueNode(pCxt, &yymsp[0].minor.yy181); } - yymsp[0].minor.yy778 = yylhsminor.yy778; + case 247: /* table_name_cond ::= table_name */ +{ yylhsminor.yy232 = createIdentifierValueNode(pCxt, &yymsp[0].minor.yy481); } + yymsp[0].minor.yy232 = yylhsminor.yy232; break; - case 247: /* from_db_opt ::= FROM db_name */ -{ yymsp[-1].minor.yy778 = createIdentifierValueNode(pCxt, &yymsp[0].minor.yy181); } + case 249: /* from_db_opt ::= FROM db_name */ +{ yymsp[-1].minor.yy232 = createIdentifierValueNode(pCxt, &yymsp[0].minor.yy481); } break; - case 248: /* cmd ::= CREATE SMA INDEX not_exists_opt full_table_name ON full_table_name index_options */ -{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy39, yymsp[-3].minor.yy778, yymsp[-1].minor.yy778, NULL, yymsp[0].minor.yy778); } + case 250: /* cmd ::= CREATE SMA INDEX not_exists_opt full_table_name ON full_table_name index_options */ +{ pCxt->pRootNode = createCreateIndexStmt(pCxt, INDEX_TYPE_SMA, yymsp[-4].minor.yy777, yymsp[-3].minor.yy232, yymsp[-1].minor.yy232, NULL, yymsp[0].minor.yy232); } break; - case 249: /* cmd ::= DROP INDEX exists_opt full_table_name */ -{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-1].minor.yy39, yymsp[0].minor.yy778); } + case 251: /* cmd ::= DROP INDEX exists_opt full_table_name */ +{ pCxt->pRootNode = createDropIndexStmt(pCxt, yymsp[-1].minor.yy777, yymsp[0].minor.yy232); } break; - case 250: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */ -{ yymsp[-9].minor.yy778 = createIndexOption(pCxt, yymsp[-7].minor.yy282, releaseRawExprNode(pCxt, yymsp[-3].minor.yy778), NULL, yymsp[-1].minor.yy778, yymsp[0].minor.yy778); } + case 252: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt sma_stream_opt */ +{ yymsp[-9].minor.yy232 = createIndexOption(pCxt, yymsp[-7].minor.yy288, releaseRawExprNode(pCxt, yymsp[-3].minor.yy232), NULL, yymsp[-1].minor.yy232, yymsp[0].minor.yy232); } break; - case 251: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */ -{ yymsp[-11].minor.yy778 = createIndexOption(pCxt, yymsp[-9].minor.yy282, releaseRawExprNode(pCxt, yymsp[-5].minor.yy778), releaseRawExprNode(pCxt, yymsp[-3].minor.yy778), yymsp[-1].minor.yy778, yymsp[0].minor.yy778); } + case 253: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt sma_stream_opt */ +{ yymsp[-11].minor.yy232 = createIndexOption(pCxt, yymsp[-9].minor.yy288, releaseRawExprNode(pCxt, yymsp[-5].minor.yy232), releaseRawExprNode(pCxt, yymsp[-3].minor.yy232), yymsp[-1].minor.yy232, yymsp[0].minor.yy232); } break; - case 254: /* func ::= function_name NK_LP expression_list NK_RP */ -{ yylhsminor.yy778 = createFunctionNode(pCxt, &yymsp[-3].minor.yy181, yymsp[-1].minor.yy282); } - yymsp[-3].minor.yy778 = yylhsminor.yy778; + case 256: /* func ::= function_name NK_LP expression_list NK_RP */ +{ yylhsminor.yy232 = createFunctionNode(pCxt, &yymsp[-3].minor.yy481, yymsp[-1].minor.yy288); } + yymsp[-3].minor.yy232 = yylhsminor.yy232; break; - case 255: /* sma_stream_opt ::= */ - case 282: /* stream_options ::= */ yytestcase(yyruleno==282); -{ yymsp[1].minor.yy778 = createStreamOptions(pCxt); } + case 257: /* sma_stream_opt ::= */ + case 284: /* stream_options ::= */ yytestcase(yyruleno==284); +{ yymsp[1].minor.yy232 = createStreamOptions(pCxt); } break; - case 256: /* sma_stream_opt ::= stream_options WATERMARK duration_literal */ - case 286: /* stream_options ::= stream_options WATERMARK duration_literal */ yytestcase(yyruleno==286); -{ ((SStreamOptions*)yymsp[-2].minor.yy778)->pWatermark = releaseRawExprNode(pCxt, yymsp[0].minor.yy778); yylhsminor.yy778 = yymsp[-2].minor.yy778; } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 258: /* sma_stream_opt ::= stream_options WATERMARK duration_literal */ + case 288: /* stream_options ::= stream_options WATERMARK duration_literal */ yytestcase(yyruleno==288); +{ ((SStreamOptions*)yymsp[-2].minor.yy232)->pWatermark = releaseRawExprNode(pCxt, yymsp[0].minor.yy232); yylhsminor.yy232 = yymsp[-2].minor.yy232; } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 257: /* sma_stream_opt ::= stream_options MAX_DELAY duration_literal */ -{ ((SStreamOptions*)yymsp[-2].minor.yy778)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy778); yylhsminor.yy778 = yymsp[-2].minor.yy778; } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 259: /* sma_stream_opt ::= stream_options MAX_DELAY duration_literal */ +{ ((SStreamOptions*)yymsp[-2].minor.yy232)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy232); yylhsminor.yy232 = yymsp[-2].minor.yy232; } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 258: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_or_subquery */ -{ pCxt->pRootNode = createCreateTopicStmtUseQuery(pCxt, yymsp[-3].minor.yy39, &yymsp[-2].minor.yy181, yymsp[0].minor.yy778); } + case 260: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS query_or_subquery */ +{ pCxt->pRootNode = createCreateTopicStmtUseQuery(pCxt, yymsp[-3].minor.yy777, &yymsp[-2].minor.yy481, yymsp[0].minor.yy232); } break; - case 259: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ -{ pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, yymsp[-4].minor.yy39, &yymsp[-3].minor.yy181, &yymsp[0].minor.yy181, false); } + case 261: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS DATABASE db_name */ +{ pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, yymsp[-4].minor.yy777, &yymsp[-3].minor.yy481, &yymsp[0].minor.yy481, false); } break; - case 260: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */ -{ pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, yymsp[-6].minor.yy39, &yymsp[-5].minor.yy181, &yymsp[0].minor.yy181, true); } + case 262: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS DATABASE db_name */ +{ pCxt->pRootNode = createCreateTopicStmtUseDb(pCxt, yymsp[-6].minor.yy777, &yymsp[-5].minor.yy481, &yymsp[0].minor.yy481, true); } break; - case 261: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ -{ pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, yymsp[-4].minor.yy39, &yymsp[-3].minor.yy181, yymsp[0].minor.yy778, false); } + case 263: /* cmd ::= CREATE TOPIC not_exists_opt topic_name AS STABLE full_table_name */ +{ pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, yymsp[-4].minor.yy777, &yymsp[-3].minor.yy481, yymsp[0].minor.yy232, false); } break; - case 262: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name */ -{ pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, yymsp[-6].minor.yy39, &yymsp[-5].minor.yy181, yymsp[0].minor.yy778, true); } + case 264: /* cmd ::= CREATE TOPIC not_exists_opt topic_name WITH META AS STABLE full_table_name */ +{ pCxt->pRootNode = createCreateTopicStmtUseTable(pCxt, yymsp[-6].minor.yy777, &yymsp[-5].minor.yy481, yymsp[0].minor.yy232, true); } break; - case 263: /* cmd ::= DROP TOPIC exists_opt topic_name */ -{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy39, &yymsp[0].minor.yy181); } + case 265: /* cmd ::= DROP TOPIC exists_opt topic_name */ +{ pCxt->pRootNode = createDropTopicStmt(pCxt, yymsp[-1].minor.yy777, &yymsp[0].minor.yy481); } break; - case 264: /* cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ -{ pCxt->pRootNode = createDropCGroupStmt(pCxt, yymsp[-3].minor.yy39, &yymsp[-2].minor.yy181, &yymsp[0].minor.yy181); } + case 266: /* cmd ::= DROP CONSUMER GROUP exists_opt cgroup_name ON topic_name */ +{ pCxt->pRootNode = createDropCGroupStmt(pCxt, yymsp[-3].minor.yy777, &yymsp[-2].minor.yy481, &yymsp[0].minor.yy481); } break; - case 265: /* cmd ::= DESC full_table_name */ - case 266: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==266); -{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy778); } + case 267: /* cmd ::= DESC full_table_name */ + case 268: /* cmd ::= DESCRIBE full_table_name */ yytestcase(yyruleno==268); +{ pCxt->pRootNode = createDescribeStmt(pCxt, yymsp[0].minor.yy232); } break; - case 267: /* cmd ::= RESET QUERY CACHE */ + case 269: /* cmd ::= RESET QUERY CACHE */ { pCxt->pRootNode = createResetQueryCacheStmt(pCxt); } break; - case 268: /* cmd ::= EXPLAIN analyze_opt explain_options query_or_subquery */ -{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy39, yymsp[-1].minor.yy778, yymsp[0].minor.yy778); } + case 270: /* cmd ::= EXPLAIN analyze_opt explain_options query_or_subquery */ +{ pCxt->pRootNode = createExplainStmt(pCxt, yymsp[-2].minor.yy777, yymsp[-1].minor.yy232, yymsp[0].minor.yy232); } break; - case 270: /* analyze_opt ::= ANALYZE */ - case 277: /* agg_func_opt ::= AGGREGATE */ yytestcase(yyruleno==277); - case 451: /* set_quantifier_opt ::= DISTINCT */ yytestcase(yyruleno==451); -{ yymsp[0].minor.yy39 = true; } + case 273: /* explain_options ::= */ +{ yymsp[1].minor.yy232 = createDefaultExplainOptions(pCxt); } break; - case 271: /* explain_options ::= */ -{ yymsp[1].minor.yy778 = createDefaultExplainOptions(pCxt); } + case 274: /* explain_options ::= explain_options VERBOSE NK_BOOL */ +{ yylhsminor.yy232 = setExplainVerbose(pCxt, yymsp[-2].minor.yy232, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 272: /* explain_options ::= explain_options VERBOSE NK_BOOL */ -{ yylhsminor.yy778 = setExplainVerbose(pCxt, yymsp[-2].minor.yy778, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 275: /* explain_options ::= explain_options RATIO NK_FLOAT */ +{ yylhsminor.yy232 = setExplainRatio(pCxt, yymsp[-2].minor.yy232, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 273: /* explain_options ::= explain_options RATIO NK_FLOAT */ -{ yylhsminor.yy778 = setExplainRatio(pCxt, yymsp[-2].minor.yy778, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 276: /* cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ +{ pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-6].minor.yy777, yymsp[-8].minor.yy777, &yymsp[-5].minor.yy481, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy264, yymsp[0].minor.yy692); } break; - case 274: /* cmd ::= CREATE agg_func_opt FUNCTION not_exists_opt function_name AS NK_STRING OUTPUTTYPE type_name bufsize_opt */ -{ pCxt->pRootNode = createCreateFunctionStmt(pCxt, yymsp[-6].minor.yy39, yymsp[-8].minor.yy39, &yymsp[-5].minor.yy181, &yymsp[-3].minor.yy0, yymsp[-1].minor.yy380, yymsp[0].minor.yy276); } + case 277: /* cmd ::= DROP FUNCTION exists_opt function_name */ +{ pCxt->pRootNode = createDropFunctionStmt(pCxt, yymsp[-1].minor.yy777, &yymsp[0].minor.yy481); } break; - case 275: /* cmd ::= DROP FUNCTION exists_opt function_name */ -{ pCxt->pRootNode = createDropFunctionStmt(pCxt, yymsp[-1].minor.yy39, &yymsp[0].minor.yy181); } + case 282: /* cmd ::= CREATE STREAM not_exists_opt stream_name stream_options INTO full_table_name tags_def_opt subtable_opt AS query_or_subquery */ +{ pCxt->pRootNode = createCreateStreamStmt(pCxt, yymsp[-8].minor.yy777, &yymsp[-7].minor.yy481, yymsp[-4].minor.yy232, yymsp[-6].minor.yy232, yymsp[-3].minor.yy288, yymsp[-2].minor.yy232, yymsp[0].minor.yy232); } break; - case 280: /* cmd ::= CREATE STREAM not_exists_opt stream_name stream_options INTO full_table_name tags_def_opt subtable_opt AS query_or_subquery */ -{ pCxt->pRootNode = createCreateStreamStmt(pCxt, yymsp[-8].minor.yy39, &yymsp[-7].minor.yy181, yymsp[-4].minor.yy778, yymsp[-6].minor.yy778, yymsp[-3].minor.yy282, yymsp[-2].minor.yy778, yymsp[0].minor.yy778); } + case 283: /* cmd ::= DROP STREAM exists_opt stream_name */ +{ pCxt->pRootNode = createDropStreamStmt(pCxt, yymsp[-1].minor.yy777, &yymsp[0].minor.yy481); } break; - case 281: /* cmd ::= DROP STREAM exists_opt stream_name */ -{ pCxt->pRootNode = createDropStreamStmt(pCxt, yymsp[-1].minor.yy39, &yymsp[0].minor.yy181); } + case 285: /* stream_options ::= stream_options TRIGGER AT_ONCE */ +{ ((SStreamOptions*)yymsp[-2].minor.yy232)->triggerType = STREAM_TRIGGER_AT_ONCE; yylhsminor.yy232 = yymsp[-2].minor.yy232; } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 283: /* stream_options ::= stream_options TRIGGER AT_ONCE */ -{ ((SStreamOptions*)yymsp[-2].minor.yy778)->triggerType = STREAM_TRIGGER_AT_ONCE; yylhsminor.yy778 = yymsp[-2].minor.yy778; } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 286: /* stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ +{ ((SStreamOptions*)yymsp[-2].minor.yy232)->triggerType = STREAM_TRIGGER_WINDOW_CLOSE; yylhsminor.yy232 = yymsp[-2].minor.yy232; } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 284: /* stream_options ::= stream_options TRIGGER WINDOW_CLOSE */ -{ ((SStreamOptions*)yymsp[-2].minor.yy778)->triggerType = STREAM_TRIGGER_WINDOW_CLOSE; yylhsminor.yy778 = yymsp[-2].minor.yy778; } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 287: /* stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ +{ ((SStreamOptions*)yymsp[-3].minor.yy232)->triggerType = STREAM_TRIGGER_MAX_DELAY; ((SStreamOptions*)yymsp[-3].minor.yy232)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy232); yylhsminor.yy232 = yymsp[-3].minor.yy232; } + yymsp[-3].minor.yy232 = yylhsminor.yy232; break; - case 285: /* stream_options ::= stream_options TRIGGER MAX_DELAY duration_literal */ -{ ((SStreamOptions*)yymsp[-3].minor.yy778)->triggerType = STREAM_TRIGGER_MAX_DELAY; ((SStreamOptions*)yymsp[-3].minor.yy778)->pDelay = releaseRawExprNode(pCxt, yymsp[0].minor.yy778); yylhsminor.yy778 = yymsp[-3].minor.yy778; } - yymsp[-3].minor.yy778 = yylhsminor.yy778; + case 289: /* stream_options ::= stream_options IGNORE EXPIRED NK_INTEGER */ +{ ((SStreamOptions*)yymsp[-3].minor.yy232)->ignoreExpired = taosStr2Int8(yymsp[0].minor.yy0.z, NULL, 10); yylhsminor.yy232 = yymsp[-3].minor.yy232; } + yymsp[-3].minor.yy232 = yylhsminor.yy232; break; - case 287: /* stream_options ::= stream_options IGNORE EXPIRED NK_INTEGER */ -{ ((SStreamOptions*)yymsp[-3].minor.yy778)->ignoreExpired = taosStr2Int8(yymsp[0].minor.yy0.z, NULL, 10); yylhsminor.yy778 = yymsp[-3].minor.yy778; } - yymsp[-3].minor.yy778 = yylhsminor.yy778; + case 290: /* stream_options ::= stream_options FILL_HISTORY NK_INTEGER */ +{ ((SStreamOptions*)yymsp[-2].minor.yy232)->fillHistory = taosStr2Int8(yymsp[0].minor.yy0.z, NULL, 10); yylhsminor.yy232 = yymsp[-2].minor.yy232; } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 289: /* subtable_opt ::= SUBTABLE NK_LP expression NK_RP */ - case 475: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ yytestcase(yyruleno==475); - case 493: /* every_opt ::= EVERY NK_LP duration_literal NK_RP */ yytestcase(yyruleno==493); -{ yymsp[-3].minor.yy778 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy778); } + case 292: /* subtable_opt ::= SUBTABLE NK_LP expression NK_RP */ + case 478: /* sliding_opt ::= SLIDING NK_LP duration_literal NK_RP */ yytestcase(yyruleno==478); + case 496: /* every_opt ::= EVERY NK_LP duration_literal NK_RP */ yytestcase(yyruleno==496); +{ yymsp[-3].minor.yy232 = releaseRawExprNode(pCxt, yymsp[-1].minor.yy232); } break; - case 290: /* cmd ::= KILL CONNECTION NK_INTEGER */ + case 293: /* cmd ::= KILL CONNECTION NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_CONNECTION_STMT, &yymsp[0].minor.yy0); } break; - case 291: /* cmd ::= KILL QUERY NK_STRING */ + case 294: /* cmd ::= KILL QUERY NK_STRING */ { pCxt->pRootNode = createKillQueryStmt(pCxt, &yymsp[0].minor.yy0); } break; - case 292: /* cmd ::= KILL TRANSACTION NK_INTEGER */ + case 295: /* cmd ::= KILL TRANSACTION NK_INTEGER */ { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_TRANSACTION_STMT, &yymsp[0].minor.yy0); } break; - case 293: /* cmd ::= BALANCE VGROUP */ + case 296: /* cmd ::= BALANCE VGROUP */ { pCxt->pRootNode = createBalanceVgroupStmt(pCxt); } break; - case 294: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ + case 297: /* cmd ::= MERGE VGROUP NK_INTEGER NK_INTEGER */ { pCxt->pRootNode = createMergeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0); } break; - case 295: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ -{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy282); } + case 298: /* cmd ::= REDISTRIBUTE VGROUP NK_INTEGER dnode_list */ +{ pCxt->pRootNode = createRedistributeVgroupStmt(pCxt, &yymsp[-1].minor.yy0, yymsp[0].minor.yy288); } break; - case 296: /* cmd ::= SPLIT VGROUP NK_INTEGER */ + case 299: /* cmd ::= SPLIT VGROUP NK_INTEGER */ { pCxt->pRootNode = createSplitVgroupStmt(pCxt, &yymsp[0].minor.yy0); } break; - case 297: /* dnode_list ::= DNODE NK_INTEGER */ -{ yymsp[-1].minor.yy282 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } - break; - case 299: /* cmd ::= DELETE FROM full_table_name where_clause_opt */ -{ pCxt->pRootNode = createDeleteStmt(pCxt, yymsp[-1].minor.yy778, yymsp[0].minor.yy778); } - break; - case 301: /* cmd ::= INSERT INTO full_table_name NK_LP col_name_list NK_RP query_or_subquery */ -{ pCxt->pRootNode = createInsertStmt(pCxt, yymsp[-4].minor.yy778, yymsp[-2].minor.yy282, yymsp[0].minor.yy778); } - break; - case 302: /* cmd ::= INSERT INTO full_table_name query_or_subquery */ -{ pCxt->pRootNode = createInsertStmt(pCxt, yymsp[-1].minor.yy778, NULL, yymsp[0].minor.yy778); } - break; - case 303: /* literal ::= NK_INTEGER */ -{ yylhsminor.yy778 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy778 = yylhsminor.yy778; - break; - case 304: /* literal ::= NK_FLOAT */ -{ yylhsminor.yy778 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy778 = yylhsminor.yy778; - break; - case 305: /* literal ::= NK_STRING */ -{ yylhsminor.yy778 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy778 = yylhsminor.yy778; - break; - case 306: /* literal ::= NK_BOOL */ -{ yylhsminor.yy778 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy778 = yylhsminor.yy778; - break; - case 307: /* literal ::= TIMESTAMP NK_STRING */ -{ yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } - yymsp[-1].minor.yy778 = yylhsminor.yy778; - break; - case 308: /* literal ::= duration_literal */ - case 318: /* signed_literal ::= signed */ yytestcase(yyruleno==318); - case 338: /* expr_or_subquery ::= expression */ yytestcase(yyruleno==338); - case 339: /* expr_or_subquery ::= subquery */ yytestcase(yyruleno==339); - case 340: /* expression ::= literal */ yytestcase(yyruleno==340); - case 341: /* expression ::= pseudo_column */ yytestcase(yyruleno==341); - case 342: /* expression ::= column_reference */ yytestcase(yyruleno==342); - case 343: /* expression ::= function_expression */ yytestcase(yyruleno==343); - case 344: /* expression ::= case_when_expression */ yytestcase(yyruleno==344); - case 374: /* function_expression ::= literal_func */ yytestcase(yyruleno==374); - case 423: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==423); - case 427: /* boolean_primary ::= predicate */ yytestcase(yyruleno==427); - case 429: /* common_expression ::= expr_or_subquery */ yytestcase(yyruleno==429); - case 430: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==430); - case 433: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==433); - case 435: /* table_reference ::= table_primary */ yytestcase(yyruleno==435); - case 436: /* table_reference ::= joined_table */ yytestcase(yyruleno==436); - case 440: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==440); - case 495: /* query_simple ::= query_specification */ yytestcase(yyruleno==495); - case 496: /* query_simple ::= union_query_expression */ yytestcase(yyruleno==496); - case 499: /* query_simple_or_subquery ::= query_simple */ yytestcase(yyruleno==499); - case 501: /* query_or_subquery ::= query_expression */ yytestcase(yyruleno==501); -{ yylhsminor.yy778 = yymsp[0].minor.yy778; } - yymsp[0].minor.yy778 = yylhsminor.yy778; - break; - case 309: /* literal ::= NULL */ -{ yylhsminor.yy778 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy778 = yylhsminor.yy778; - break; - case 310: /* literal ::= NK_QUESTION */ -{ yylhsminor.yy778 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy778 = yylhsminor.yy778; - break; - case 311: /* duration_literal ::= NK_VARIABLE */ -{ yylhsminor.yy778 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy778 = yylhsminor.yy778; - break; - case 312: /* signed ::= NK_INTEGER */ -{ yylhsminor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy778 = yylhsminor.yy778; - break; - case 313: /* signed ::= NK_PLUS NK_INTEGER */ -{ yymsp[-1].minor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &yymsp[0].minor.yy0); } - break; - case 314: /* signed ::= NK_MINUS NK_INTEGER */ + case 300: /* dnode_list ::= DNODE NK_INTEGER */ +{ yymsp[-1].minor.yy288 = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); } + break; + case 302: /* cmd ::= DELETE FROM full_table_name where_clause_opt */ +{ pCxt->pRootNode = createDeleteStmt(pCxt, yymsp[-1].minor.yy232, yymsp[0].minor.yy232); } + break; + case 304: /* cmd ::= INSERT INTO full_table_name NK_LP col_name_list NK_RP query_or_subquery */ +{ pCxt->pRootNode = createInsertStmt(pCxt, yymsp[-4].minor.yy232, yymsp[-2].minor.yy288, yymsp[0].minor.yy232); } + break; + case 305: /* cmd ::= INSERT INTO full_table_name query_or_subquery */ +{ pCxt->pRootNode = createInsertStmt(pCxt, yymsp[-1].minor.yy232, NULL, yymsp[0].minor.yy232); } + break; + case 306: /* literal ::= NK_INTEGER */ +{ yylhsminor.yy232 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy232 = yylhsminor.yy232; + break; + case 307: /* literal ::= NK_FLOAT */ +{ yylhsminor.yy232 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy232 = yylhsminor.yy232; + break; + case 308: /* literal ::= NK_STRING */ +{ yylhsminor.yy232 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy232 = yylhsminor.yy232; + break; + case 309: /* literal ::= NK_BOOL */ +{ yylhsminor.yy232 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy232 = yylhsminor.yy232; + break; + case 310: /* literal ::= TIMESTAMP NK_STRING */ +{ yylhsminor.yy232 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); } + yymsp[-1].minor.yy232 = yylhsminor.yy232; + break; + case 311: /* literal ::= duration_literal */ + case 321: /* signed_literal ::= signed */ yytestcase(yyruleno==321); + case 341: /* expr_or_subquery ::= expression */ yytestcase(yyruleno==341); + case 342: /* expr_or_subquery ::= subquery */ yytestcase(yyruleno==342); + case 343: /* expression ::= literal */ yytestcase(yyruleno==343); + case 344: /* expression ::= pseudo_column */ yytestcase(yyruleno==344); + case 345: /* expression ::= column_reference */ yytestcase(yyruleno==345); + case 346: /* expression ::= function_expression */ yytestcase(yyruleno==346); + case 347: /* expression ::= case_when_expression */ yytestcase(yyruleno==347); + case 377: /* function_expression ::= literal_func */ yytestcase(yyruleno==377); + case 426: /* boolean_value_expression ::= boolean_primary */ yytestcase(yyruleno==426); + case 430: /* boolean_primary ::= predicate */ yytestcase(yyruleno==430); + case 432: /* common_expression ::= expr_or_subquery */ yytestcase(yyruleno==432); + case 433: /* common_expression ::= boolean_value_expression */ yytestcase(yyruleno==433); + case 436: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==436); + case 438: /* table_reference ::= table_primary */ yytestcase(yyruleno==438); + case 439: /* table_reference ::= joined_table */ yytestcase(yyruleno==439); + case 443: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==443); + case 498: /* query_simple ::= query_specification */ yytestcase(yyruleno==498); + case 499: /* query_simple ::= union_query_expression */ yytestcase(yyruleno==499); + case 502: /* query_simple_or_subquery ::= query_simple */ yytestcase(yyruleno==502); + case 504: /* query_or_subquery ::= query_expression */ yytestcase(yyruleno==504); +{ yylhsminor.yy232 = yymsp[0].minor.yy232; } + yymsp[0].minor.yy232 = yylhsminor.yy232; + break; + case 312: /* literal ::= NULL */ +{ yylhsminor.yy232 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy232 = yylhsminor.yy232; + break; + case 313: /* literal ::= NK_QUESTION */ +{ yylhsminor.yy232 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy232 = yylhsminor.yy232; + break; + case 314: /* duration_literal ::= NK_VARIABLE */ +{ yylhsminor.yy232 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy232 = yylhsminor.yy232; + break; + case 315: /* signed ::= NK_INTEGER */ +{ yylhsminor.yy232 = createValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy232 = yylhsminor.yy232; + break; + case 316: /* signed ::= NK_PLUS NK_INTEGER */ +{ yymsp[-1].minor.yy232 = createValueNode(pCxt, TSDB_DATA_TYPE_UBIGINT, &yymsp[0].minor.yy0); } + break; + case 317: /* signed ::= NK_MINUS NK_INTEGER */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); + yylhsminor.yy232 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &t); } - yymsp[-1].minor.yy778 = yylhsminor.yy778; + yymsp[-1].minor.yy232 = yylhsminor.yy232; break; - case 315: /* signed ::= NK_FLOAT */ -{ yylhsminor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy778 = yylhsminor.yy778; + case 318: /* signed ::= NK_FLOAT */ +{ yylhsminor.yy232 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy232 = yylhsminor.yy232; break; - case 316: /* signed ::= NK_PLUS NK_FLOAT */ -{ yymsp[-1].minor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } + case 319: /* signed ::= NK_PLUS NK_FLOAT */ +{ yymsp[-1].minor.yy232 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); } break; - case 317: /* signed ::= NK_MINUS NK_FLOAT */ + case 320: /* signed ::= NK_MINUS NK_FLOAT */ { SToken t = yymsp[-1].minor.yy0; t.n = (yymsp[0].minor.yy0.z + yymsp[0].minor.yy0.n) - yymsp[-1].minor.yy0.z; - yylhsminor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); + yylhsminor.yy232 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &t); } - yymsp[-1].minor.yy778 = yylhsminor.yy778; - break; - case 319: /* signed_literal ::= NK_STRING */ -{ yylhsminor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy778 = yylhsminor.yy778; - break; - case 320: /* signed_literal ::= NK_BOOL */ -{ yylhsminor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy778 = yylhsminor.yy778; - break; - case 321: /* signed_literal ::= TIMESTAMP NK_STRING */ -{ yymsp[-1].minor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } - break; - case 322: /* signed_literal ::= duration_literal */ - case 324: /* signed_literal ::= literal_func */ yytestcase(yyruleno==324); - case 394: /* star_func_para ::= expr_or_subquery */ yytestcase(yyruleno==394); - case 456: /* select_item ::= common_expression */ yytestcase(yyruleno==456); - case 466: /* partition_item ::= expr_or_subquery */ yytestcase(yyruleno==466); - case 500: /* query_simple_or_subquery ::= subquery */ yytestcase(yyruleno==500); - case 502: /* query_or_subquery ::= subquery */ yytestcase(yyruleno==502); - case 515: /* search_condition ::= common_expression */ yytestcase(yyruleno==515); -{ yylhsminor.yy778 = releaseRawExprNode(pCxt, yymsp[0].minor.yy778); } - yymsp[0].minor.yy778 = yylhsminor.yy778; - break; - case 323: /* signed_literal ::= NULL */ -{ yylhsminor.yy778 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy778 = yylhsminor.yy778; - break; - case 325: /* signed_literal ::= NK_QUESTION */ -{ yylhsminor.yy778 = createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy778 = yylhsminor.yy778; - break; - case 345: /* expression ::= NK_LP expression NK_RP */ - case 428: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==428); - case 514: /* subquery ::= NK_LP subquery NK_RP */ yytestcase(yyruleno==514); -{ yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy778)); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; - break; - case 346: /* expression ::= NK_PLUS expr_or_subquery */ + yymsp[-1].minor.yy232 = yylhsminor.yy232; + break; + case 322: /* signed_literal ::= NK_STRING */ +{ yylhsminor.yy232 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy232 = yylhsminor.yy232; + break; + case 323: /* signed_literal ::= NK_BOOL */ +{ yylhsminor.yy232 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy232 = yylhsminor.yy232; + break; + case 324: /* signed_literal ::= TIMESTAMP NK_STRING */ +{ yymsp[-1].minor.yy232 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); } + break; + case 325: /* signed_literal ::= duration_literal */ + case 327: /* signed_literal ::= literal_func */ yytestcase(yyruleno==327); + case 397: /* star_func_para ::= expr_or_subquery */ yytestcase(yyruleno==397); + case 459: /* select_item ::= common_expression */ yytestcase(yyruleno==459); + case 469: /* partition_item ::= expr_or_subquery */ yytestcase(yyruleno==469); + case 503: /* query_simple_or_subquery ::= subquery */ yytestcase(yyruleno==503); + case 505: /* query_or_subquery ::= subquery */ yytestcase(yyruleno==505); + case 518: /* search_condition ::= common_expression */ yytestcase(yyruleno==518); +{ yylhsminor.yy232 = releaseRawExprNode(pCxt, yymsp[0].minor.yy232); } + yymsp[0].minor.yy232 = yylhsminor.yy232; + break; + case 326: /* signed_literal ::= NULL */ +{ yylhsminor.yy232 = createValueNode(pCxt, TSDB_DATA_TYPE_NULL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy232 = yylhsminor.yy232; + break; + case 328: /* signed_literal ::= NK_QUESTION */ +{ yylhsminor.yy232 = createPlaceholderValueNode(pCxt, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy232 = yylhsminor.yy232; + break; + case 348: /* expression ::= NK_LP expression NK_RP */ + case 431: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==431); + case 517: /* subquery ::= NK_LP subquery NK_RP */ yytestcase(yyruleno==517); +{ yylhsminor.yy232 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy232)); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; + break; + case 349: /* expression ::= NK_PLUS expr_or_subquery */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); - yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy778)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy232); + yylhsminor.yy232 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy232)); } - yymsp[-1].minor.yy778 = yylhsminor.yy778; + yymsp[-1].minor.yy232 = yylhsminor.yy232; break; - case 347: /* expression ::= NK_MINUS expr_or_subquery */ + case 350: /* expression ::= NK_MINUS expr_or_subquery */ { - SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); - yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy778), NULL)); + SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy232); + yylhsminor.yy232 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_MINUS, releaseRawExprNode(pCxt, yymsp[0].minor.yy232), NULL)); } - yymsp[-1].minor.yy778 = yylhsminor.yy778; + yymsp[-1].minor.yy232 = yylhsminor.yy232; break; - case 348: /* expression ::= expr_or_subquery NK_PLUS expr_or_subquery */ + case 351: /* expression ::= expr_or_subquery NK_PLUS expr_or_subquery */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); - yylhsminor.yy778 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), releaseRawExprNode(pCxt, yymsp[0].minor.yy778))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy232); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy232); + yylhsminor.yy232 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy232), releaseRawExprNode(pCxt, yymsp[0].minor.yy232))); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 349: /* expression ::= expr_or_subquery NK_MINUS expr_or_subquery */ + case 352: /* expression ::= expr_or_subquery NK_MINUS expr_or_subquery */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); - yylhsminor.yy778 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), releaseRawExprNode(pCxt, yymsp[0].minor.yy778))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy232); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy232); + yylhsminor.yy232 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy232), releaseRawExprNode(pCxt, yymsp[0].minor.yy232))); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 350: /* expression ::= expr_or_subquery NK_STAR expr_or_subquery */ + case 353: /* expression ::= expr_or_subquery NK_STAR expr_or_subquery */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); - yylhsminor.yy778 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), releaseRawExprNode(pCxt, yymsp[0].minor.yy778))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy232); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy232); + yylhsminor.yy232 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy232), releaseRawExprNode(pCxt, yymsp[0].minor.yy232))); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 351: /* expression ::= expr_or_subquery NK_SLASH expr_or_subquery */ + case 354: /* expression ::= expr_or_subquery NK_SLASH expr_or_subquery */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); - yylhsminor.yy778 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), releaseRawExprNode(pCxt, yymsp[0].minor.yy778))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy232); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy232); + yylhsminor.yy232 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy232), releaseRawExprNode(pCxt, yymsp[0].minor.yy232))); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 352: /* expression ::= expr_or_subquery NK_REM expr_or_subquery */ + case 355: /* expression ::= expr_or_subquery NK_REM expr_or_subquery */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); - yylhsminor.yy778 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_REM, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), releaseRawExprNode(pCxt, yymsp[0].minor.yy778))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy232); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy232); + yylhsminor.yy232 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_REM, releaseRawExprNode(pCxt, yymsp[-2].minor.yy232), releaseRawExprNode(pCxt, yymsp[0].minor.yy232))); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 353: /* expression ::= column_reference NK_ARROW NK_STRING */ + case 356: /* expression ::= column_reference NK_ARROW NK_STRING */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); - yylhsminor.yy778 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy232); + yylhsminor.yy232 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, yymsp[-2].minor.yy232), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0))); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 354: /* expression ::= expr_or_subquery NK_BITAND expr_or_subquery */ + case 357: /* expression ::= expr_or_subquery NK_BITAND expr_or_subquery */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); - yylhsminor.yy778 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), releaseRawExprNode(pCxt, yymsp[0].minor.yy778))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy232); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy232); + yylhsminor.yy232 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy232), releaseRawExprNode(pCxt, yymsp[0].minor.yy232))); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 355: /* expression ::= expr_or_subquery NK_BITOR expr_or_subquery */ + case 358: /* expression ::= expr_or_subquery NK_BITOR expr_or_subquery */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); - yylhsminor.yy778 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), releaseRawExprNode(pCxt, yymsp[0].minor.yy778))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy232); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy232); + yylhsminor.yy232 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_BIT_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy232), releaseRawExprNode(pCxt, yymsp[0].minor.yy232))); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; - break; - case 358: /* column_reference ::= column_name */ -{ yylhsminor.yy778 = createRawExprNode(pCxt, &yymsp[0].minor.yy181, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy181)); } - yymsp[0].minor.yy778 = yylhsminor.yy778; - break; - case 359: /* column_reference ::= table_name NK_DOT column_name */ -{ yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy181, &yymsp[0].minor.yy181, createColumnNode(pCxt, &yymsp[-2].minor.yy181, &yymsp[0].minor.yy181)); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; - break; - case 360: /* pseudo_column ::= ROWTS */ - case 361: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==361); - case 363: /* pseudo_column ::= QSTART */ yytestcase(yyruleno==363); - case 364: /* pseudo_column ::= QEND */ yytestcase(yyruleno==364); - case 365: /* pseudo_column ::= QDURATION */ yytestcase(yyruleno==365); - case 366: /* pseudo_column ::= WSTART */ yytestcase(yyruleno==366); - case 367: /* pseudo_column ::= WEND */ yytestcase(yyruleno==367); - case 368: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==368); - case 369: /* pseudo_column ::= IROWTS */ yytestcase(yyruleno==369); - case 370: /* pseudo_column ::= QTAGS */ yytestcase(yyruleno==370); - case 376: /* literal_func ::= NOW */ yytestcase(yyruleno==376); -{ yylhsminor.yy778 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } - yymsp[0].minor.yy778 = yylhsminor.yy778; - break; - case 362: /* pseudo_column ::= table_name NK_DOT TBNAME */ -{ yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy181, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-2].minor.yy181)))); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; - break; - case 371: /* function_expression ::= function_name NK_LP expression_list NK_RP */ - case 372: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==372); -{ yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy181, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy181, yymsp[-1].minor.yy282)); } - yymsp[-3].minor.yy778 = yylhsminor.yy778; - break; - case 373: /* function_expression ::= CAST NK_LP expr_or_subquery AS type_name NK_RP */ -{ yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy778), yymsp[-1].minor.yy380)); } - yymsp[-5].minor.yy778 = yylhsminor.yy778; - break; - case 375: /* literal_func ::= noarg_func NK_LP NK_RP */ -{ yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy181, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-2].minor.yy181, NULL)); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; - break; - case 390: /* star_func_para_list ::= NK_STAR */ -{ yylhsminor.yy282 = createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0)); } - yymsp[0].minor.yy282 = yylhsminor.yy282; - break; - case 395: /* star_func_para ::= table_name NK_DOT NK_STAR */ - case 459: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==459); -{ yylhsminor.yy778 = createColumnNode(pCxt, &yymsp[-2].minor.yy181, &yymsp[0].minor.yy0); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; - break; - case 396: /* case_when_expression ::= CASE when_then_list case_when_else_opt END */ -{ yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, createCaseWhenNode(pCxt, NULL, yymsp[-2].minor.yy282, yymsp[-1].minor.yy778)); } - yymsp[-3].minor.yy778 = yylhsminor.yy778; - break; - case 397: /* case_when_expression ::= CASE common_expression when_then_list case_when_else_opt END */ -{ yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0, createCaseWhenNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy778), yymsp[-2].minor.yy282, yymsp[-1].minor.yy778)); } - yymsp[-4].minor.yy778 = yylhsminor.yy778; - break; - case 400: /* when_then_expr ::= WHEN common_expression THEN common_expression */ -{ yymsp[-3].minor.yy778 = createWhenThenNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), releaseRawExprNode(pCxt, yymsp[0].minor.yy778)); } - break; - case 402: /* case_when_else_opt ::= ELSE common_expression */ -{ yymsp[-1].minor.yy778 = releaseRawExprNode(pCxt, yymsp[0].minor.yy778); } - break; - case 403: /* predicate ::= expr_or_subquery compare_op expr_or_subquery */ - case 408: /* predicate ::= expr_or_subquery in_op in_predicate_value */ yytestcase(yyruleno==408); + yymsp[-2].minor.yy232 = yylhsminor.yy232; + break; + case 361: /* column_reference ::= column_name */ +{ yylhsminor.yy232 = createRawExprNode(pCxt, &yymsp[0].minor.yy481, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy481)); } + yymsp[0].minor.yy232 = yylhsminor.yy232; + break; + case 362: /* column_reference ::= table_name NK_DOT column_name */ +{ yylhsminor.yy232 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy481, &yymsp[0].minor.yy481, createColumnNode(pCxt, &yymsp[-2].minor.yy481, &yymsp[0].minor.yy481)); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; + break; + case 363: /* pseudo_column ::= ROWTS */ + case 364: /* pseudo_column ::= TBNAME */ yytestcase(yyruleno==364); + case 366: /* pseudo_column ::= QSTART */ yytestcase(yyruleno==366); + case 367: /* pseudo_column ::= QEND */ yytestcase(yyruleno==367); + case 368: /* pseudo_column ::= QDURATION */ yytestcase(yyruleno==368); + case 369: /* pseudo_column ::= WSTART */ yytestcase(yyruleno==369); + case 370: /* pseudo_column ::= WEND */ yytestcase(yyruleno==370); + case 371: /* pseudo_column ::= WDURATION */ yytestcase(yyruleno==371); + case 372: /* pseudo_column ::= IROWTS */ yytestcase(yyruleno==372); + case 373: /* pseudo_column ::= QTAGS */ yytestcase(yyruleno==373); + case 379: /* literal_func ::= NOW */ yytestcase(yyruleno==379); +{ yylhsminor.yy232 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, NULL)); } + yymsp[0].minor.yy232 = yylhsminor.yy232; + break; + case 365: /* pseudo_column ::= table_name NK_DOT TBNAME */ +{ yylhsminor.yy232 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy481, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[0].minor.yy0, createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[-2].minor.yy481)))); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; + break; + case 374: /* function_expression ::= function_name NK_LP expression_list NK_RP */ + case 375: /* function_expression ::= star_func NK_LP star_func_para_list NK_RP */ yytestcase(yyruleno==375); +{ yylhsminor.yy232 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy481, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy481, yymsp[-1].minor.yy288)); } + yymsp[-3].minor.yy232 = yylhsminor.yy232; + break; + case 376: /* function_expression ::= CAST NK_LP expr_or_subquery AS type_name NK_RP */ +{ yylhsminor.yy232 = createRawExprNodeExt(pCxt, &yymsp[-5].minor.yy0, &yymsp[0].minor.yy0, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy232), yymsp[-1].minor.yy264)); } + yymsp[-5].minor.yy232 = yylhsminor.yy232; + break; + case 378: /* literal_func ::= noarg_func NK_LP NK_RP */ +{ yylhsminor.yy232 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy481, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-2].minor.yy481, NULL)); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; + break; + case 393: /* star_func_para_list ::= NK_STAR */ +{ yylhsminor.yy288 = createNodeList(pCxt, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0)); } + yymsp[0].minor.yy288 = yylhsminor.yy288; + break; + case 398: /* star_func_para ::= table_name NK_DOT NK_STAR */ + case 462: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==462); +{ yylhsminor.yy232 = createColumnNode(pCxt, &yymsp[-2].minor.yy481, &yymsp[0].minor.yy0); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; + break; + case 399: /* case_when_expression ::= CASE when_then_list case_when_else_opt END */ +{ yylhsminor.yy232 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy0, &yymsp[0].minor.yy0, createCaseWhenNode(pCxt, NULL, yymsp[-2].minor.yy288, yymsp[-1].minor.yy232)); } + yymsp[-3].minor.yy232 = yylhsminor.yy232; + break; + case 400: /* case_when_expression ::= CASE common_expression when_then_list case_when_else_opt END */ +{ yylhsminor.yy232 = createRawExprNodeExt(pCxt, &yymsp[-4].minor.yy0, &yymsp[0].minor.yy0, createCaseWhenNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy232), yymsp[-2].minor.yy288, yymsp[-1].minor.yy232)); } + yymsp[-4].minor.yy232 = yylhsminor.yy232; + break; + case 403: /* when_then_expr ::= WHEN common_expression THEN common_expression */ +{ yymsp[-3].minor.yy232 = createWhenThenNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy232), releaseRawExprNode(pCxt, yymsp[0].minor.yy232)); } + break; + case 405: /* case_when_else_opt ::= ELSE common_expression */ +{ yymsp[-1].minor.yy232 = releaseRawExprNode(pCxt, yymsp[0].minor.yy232); } + break; + case 406: /* predicate ::= expr_or_subquery compare_op expr_or_subquery */ + case 411: /* predicate ::= expr_or_subquery in_op in_predicate_value */ yytestcase(yyruleno==411); { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); - yylhsminor.yy778 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy682, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), releaseRawExprNode(pCxt, yymsp[0].minor.yy778))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy232); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy232); + yylhsminor.yy232 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, yymsp[-1].minor.yy4, releaseRawExprNode(pCxt, yymsp[-2].minor.yy232), releaseRawExprNode(pCxt, yymsp[0].minor.yy232))); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 404: /* predicate ::= expr_or_subquery BETWEEN expr_or_subquery AND expr_or_subquery */ + case 407: /* predicate ::= expr_or_subquery BETWEEN expr_or_subquery AND expr_or_subquery */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy778); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); - yylhsminor.yy778 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy778), releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), releaseRawExprNode(pCxt, yymsp[0].minor.yy778))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-4].minor.yy232); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy232); + yylhsminor.yy232 = createRawExprNodeExt(pCxt, &s, &e, createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy232), releaseRawExprNode(pCxt, yymsp[-2].minor.yy232), releaseRawExprNode(pCxt, yymsp[0].minor.yy232))); } - yymsp[-4].minor.yy778 = yylhsminor.yy778; + yymsp[-4].minor.yy232 = yylhsminor.yy232; break; - case 405: /* predicate ::= expr_or_subquery NOT BETWEEN expr_or_subquery AND expr_or_subquery */ + case 408: /* predicate ::= expr_or_subquery NOT BETWEEN expr_or_subquery AND expr_or_subquery */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy778); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); - yylhsminor.yy778 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy778), releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), releaseRawExprNode(pCxt, yymsp[0].minor.yy778))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-5].minor.yy232); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy232); + yylhsminor.yy232 = createRawExprNodeExt(pCxt, &s, &e, createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy232), releaseRawExprNode(pCxt, yymsp[-2].minor.yy232), releaseRawExprNode(pCxt, yymsp[0].minor.yy232))); } - yymsp[-5].minor.yy778 = yylhsminor.yy778; + yymsp[-5].minor.yy232 = yylhsminor.yy232; break; - case 406: /* predicate ::= expr_or_subquery IS NULL */ + case 409: /* predicate ::= expr_or_subquery IS NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); - yylhsminor.yy778 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy232); + yylhsminor.yy232 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NULL, releaseRawExprNode(pCxt, yymsp[-2].minor.yy232), NULL)); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 407: /* predicate ::= expr_or_subquery IS NOT NULL */ + case 410: /* predicate ::= expr_or_subquery IS NOT NULL */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy778); - yylhsminor.yy778 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy778), NULL)); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-3].minor.yy232); + yylhsminor.yy232 = createRawExprNodeExt(pCxt, &s, &yymsp[0].minor.yy0, createOperatorNode(pCxt, OP_TYPE_IS_NOT_NULL, releaseRawExprNode(pCxt, yymsp[-3].minor.yy232), NULL)); } - yymsp[-3].minor.yy778 = yylhsminor.yy778; + yymsp[-3].minor.yy232 = yylhsminor.yy232; break; - case 409: /* compare_op ::= NK_LT */ -{ yymsp[0].minor.yy682 = OP_TYPE_LOWER_THAN; } + case 412: /* compare_op ::= NK_LT */ +{ yymsp[0].minor.yy4 = OP_TYPE_LOWER_THAN; } break; - case 410: /* compare_op ::= NK_GT */ -{ yymsp[0].minor.yy682 = OP_TYPE_GREATER_THAN; } + case 413: /* compare_op ::= NK_GT */ +{ yymsp[0].minor.yy4 = OP_TYPE_GREATER_THAN; } break; - case 411: /* compare_op ::= NK_LE */ -{ yymsp[0].minor.yy682 = OP_TYPE_LOWER_EQUAL; } + case 414: /* compare_op ::= NK_LE */ +{ yymsp[0].minor.yy4 = OP_TYPE_LOWER_EQUAL; } break; - case 412: /* compare_op ::= NK_GE */ -{ yymsp[0].minor.yy682 = OP_TYPE_GREATER_EQUAL; } + case 415: /* compare_op ::= NK_GE */ +{ yymsp[0].minor.yy4 = OP_TYPE_GREATER_EQUAL; } break; - case 413: /* compare_op ::= NK_NE */ -{ yymsp[0].minor.yy682 = OP_TYPE_NOT_EQUAL; } + case 416: /* compare_op ::= NK_NE */ +{ yymsp[0].minor.yy4 = OP_TYPE_NOT_EQUAL; } break; - case 414: /* compare_op ::= NK_EQ */ -{ yymsp[0].minor.yy682 = OP_TYPE_EQUAL; } + case 417: /* compare_op ::= NK_EQ */ +{ yymsp[0].minor.yy4 = OP_TYPE_EQUAL; } break; - case 415: /* compare_op ::= LIKE */ -{ yymsp[0].minor.yy682 = OP_TYPE_LIKE; } + case 418: /* compare_op ::= LIKE */ +{ yymsp[0].minor.yy4 = OP_TYPE_LIKE; } break; - case 416: /* compare_op ::= NOT LIKE */ -{ yymsp[-1].minor.yy682 = OP_TYPE_NOT_LIKE; } + case 419: /* compare_op ::= NOT LIKE */ +{ yymsp[-1].minor.yy4 = OP_TYPE_NOT_LIKE; } break; - case 417: /* compare_op ::= MATCH */ -{ yymsp[0].minor.yy682 = OP_TYPE_MATCH; } + case 420: /* compare_op ::= MATCH */ +{ yymsp[0].minor.yy4 = OP_TYPE_MATCH; } break; - case 418: /* compare_op ::= NMATCH */ -{ yymsp[0].minor.yy682 = OP_TYPE_NMATCH; } + case 421: /* compare_op ::= NMATCH */ +{ yymsp[0].minor.yy4 = OP_TYPE_NMATCH; } break; - case 419: /* compare_op ::= CONTAINS */ -{ yymsp[0].minor.yy682 = OP_TYPE_JSON_CONTAINS; } + case 422: /* compare_op ::= CONTAINS */ +{ yymsp[0].minor.yy4 = OP_TYPE_JSON_CONTAINS; } break; - case 420: /* in_op ::= IN */ -{ yymsp[0].minor.yy682 = OP_TYPE_IN; } + case 423: /* in_op ::= IN */ +{ yymsp[0].minor.yy4 = OP_TYPE_IN; } break; - case 421: /* in_op ::= NOT IN */ -{ yymsp[-1].minor.yy682 = OP_TYPE_NOT_IN; } + case 424: /* in_op ::= NOT IN */ +{ yymsp[-1].minor.yy4 = OP_TYPE_NOT_IN; } break; - case 422: /* in_predicate_value ::= NK_LP literal_list NK_RP */ -{ yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy282)); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 425: /* in_predicate_value ::= NK_LP literal_list NK_RP */ +{ yylhsminor.yy232 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, createNodeListNode(pCxt, yymsp[-1].minor.yy288)); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 424: /* boolean_value_expression ::= NOT boolean_primary */ + case 427: /* boolean_value_expression ::= NOT boolean_primary */ { - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); - yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy778), NULL)); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy232); + yylhsminor.yy232 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_NOT, releaseRawExprNode(pCxt, yymsp[0].minor.yy232), NULL)); } - yymsp[-1].minor.yy778 = yylhsminor.yy778; + yymsp[-1].minor.yy232 = yylhsminor.yy232; break; - case 425: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ + case 428: /* boolean_value_expression ::= boolean_value_expression OR boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); - yylhsminor.yy778 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), releaseRawExprNode(pCxt, yymsp[0].minor.yy778))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy232); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy232); + yylhsminor.yy232 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, releaseRawExprNode(pCxt, yymsp[-2].minor.yy232), releaseRawExprNode(pCxt, yymsp[0].minor.yy232))); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 426: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ + case 429: /* boolean_value_expression ::= boolean_value_expression AND boolean_value_expression */ { - SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy778); - SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy778); - yylhsminor.yy778 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), releaseRawExprNode(pCxt, yymsp[0].minor.yy778))); + SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy232); + SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy232); + yylhsminor.yy232 = createRawExprNodeExt(pCxt, &s, &e, createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, releaseRawExprNode(pCxt, yymsp[-2].minor.yy232), releaseRawExprNode(pCxt, yymsp[0].minor.yy232))); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 432: /* from_clause_opt ::= FROM table_reference_list */ - case 461: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==461); - case 489: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==489); -{ yymsp[-1].minor.yy778 = yymsp[0].minor.yy778; } + case 435: /* from_clause_opt ::= FROM table_reference_list */ + case 464: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==464); + case 492: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==492); +{ yymsp[-1].minor.yy232 = yymsp[0].minor.yy232; } break; - case 434: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ -{ yylhsminor.yy778 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy778, yymsp[0].minor.yy778, NULL); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 437: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ +{ yylhsminor.yy232 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy232, yymsp[0].minor.yy232, NULL); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 437: /* table_primary ::= table_name alias_opt */ -{ yylhsminor.yy778 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy181, &yymsp[0].minor.yy181); } - yymsp[-1].minor.yy778 = yylhsminor.yy778; + case 440: /* table_primary ::= table_name alias_opt */ +{ yylhsminor.yy232 = createRealTableNode(pCxt, NULL, &yymsp[-1].minor.yy481, &yymsp[0].minor.yy481); } + yymsp[-1].minor.yy232 = yylhsminor.yy232; break; - case 438: /* table_primary ::= db_name NK_DOT table_name alias_opt */ -{ yylhsminor.yy778 = createRealTableNode(pCxt, &yymsp[-3].minor.yy181, &yymsp[-1].minor.yy181, &yymsp[0].minor.yy181); } - yymsp[-3].minor.yy778 = yylhsminor.yy778; + case 441: /* table_primary ::= db_name NK_DOT table_name alias_opt */ +{ yylhsminor.yy232 = createRealTableNode(pCxt, &yymsp[-3].minor.yy481, &yymsp[-1].minor.yy481, &yymsp[0].minor.yy481); } + yymsp[-3].minor.yy232 = yylhsminor.yy232; break; - case 439: /* table_primary ::= subquery alias_opt */ -{ yylhsminor.yy778 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy778), &yymsp[0].minor.yy181); } - yymsp[-1].minor.yy778 = yylhsminor.yy778; + case 442: /* table_primary ::= subquery alias_opt */ +{ yylhsminor.yy232 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy232), &yymsp[0].minor.yy481); } + yymsp[-1].minor.yy232 = yylhsminor.yy232; break; - case 441: /* alias_opt ::= */ -{ yymsp[1].minor.yy181 = nil_token; } + case 444: /* alias_opt ::= */ +{ yymsp[1].minor.yy481 = nil_token; } break; - case 442: /* alias_opt ::= table_alias */ -{ yylhsminor.yy181 = yymsp[0].minor.yy181; } - yymsp[0].minor.yy181 = yylhsminor.yy181; + case 445: /* alias_opt ::= table_alias */ +{ yylhsminor.yy481 = yymsp[0].minor.yy481; } + yymsp[0].minor.yy481 = yylhsminor.yy481; break; - case 443: /* alias_opt ::= AS table_alias */ -{ yymsp[-1].minor.yy181 = yymsp[0].minor.yy181; } + case 446: /* alias_opt ::= AS table_alias */ +{ yymsp[-1].minor.yy481 = yymsp[0].minor.yy481; } break; - case 444: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ - case 445: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==445); -{ yymsp[-2].minor.yy778 = yymsp[-1].minor.yy778; } + case 447: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ + case 448: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==448); +{ yymsp[-2].minor.yy232 = yymsp[-1].minor.yy232; } break; - case 446: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ -{ yylhsminor.yy778 = createJoinTableNode(pCxt, yymsp[-4].minor.yy202, yymsp[-5].minor.yy778, yymsp[-2].minor.yy778, yymsp[0].minor.yy778); } - yymsp[-5].minor.yy778 = yylhsminor.yy778; + case 449: /* joined_table ::= table_reference join_type JOIN table_reference ON search_condition */ +{ yylhsminor.yy232 = createJoinTableNode(pCxt, yymsp[-4].minor.yy700, yymsp[-5].minor.yy232, yymsp[-2].minor.yy232, yymsp[0].minor.yy232); } + yymsp[-5].minor.yy232 = yylhsminor.yy232; break; - case 447: /* join_type ::= */ -{ yymsp[1].minor.yy202 = JOIN_TYPE_INNER; } + case 450: /* join_type ::= */ +{ yymsp[1].minor.yy700 = JOIN_TYPE_INNER; } break; - case 448: /* join_type ::= INNER */ -{ yymsp[0].minor.yy202 = JOIN_TYPE_INNER; } + case 451: /* join_type ::= INNER */ +{ yymsp[0].minor.yy700 = JOIN_TYPE_INNER; } break; - case 449: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ + case 452: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause_opt where_clause_opt partition_by_clause_opt range_opt every_opt fill_opt twindow_clause_opt group_by_clause_opt having_clause_opt */ { - yymsp[-11].minor.yy778 = createSelectStmt(pCxt, yymsp[-10].minor.yy39, yymsp[-9].minor.yy282, yymsp[-8].minor.yy778); - yymsp[-11].minor.yy778 = addWhereClause(pCxt, yymsp[-11].minor.yy778, yymsp[-7].minor.yy778); - yymsp[-11].minor.yy778 = addPartitionByClause(pCxt, yymsp[-11].minor.yy778, yymsp[-6].minor.yy282); - yymsp[-11].minor.yy778 = addWindowClauseClause(pCxt, yymsp[-11].minor.yy778, yymsp[-2].minor.yy778); - yymsp[-11].minor.yy778 = addGroupByClause(pCxt, yymsp[-11].minor.yy778, yymsp[-1].minor.yy282); - yymsp[-11].minor.yy778 = addHavingClause(pCxt, yymsp[-11].minor.yy778, yymsp[0].minor.yy778); - yymsp[-11].minor.yy778 = addRangeClause(pCxt, yymsp[-11].minor.yy778, yymsp[-5].minor.yy778); - yymsp[-11].minor.yy778 = addEveryClause(pCxt, yymsp[-11].minor.yy778, yymsp[-4].minor.yy778); - yymsp[-11].minor.yy778 = addFillClause(pCxt, yymsp[-11].minor.yy778, yymsp[-3].minor.yy778); + yymsp[-11].minor.yy232 = createSelectStmt(pCxt, yymsp[-10].minor.yy777, yymsp[-9].minor.yy288, yymsp[-8].minor.yy232); + yymsp[-11].minor.yy232 = addWhereClause(pCxt, yymsp[-11].minor.yy232, yymsp[-7].minor.yy232); + yymsp[-11].minor.yy232 = addPartitionByClause(pCxt, yymsp[-11].minor.yy232, yymsp[-6].minor.yy288); + yymsp[-11].minor.yy232 = addWindowClauseClause(pCxt, yymsp[-11].minor.yy232, yymsp[-2].minor.yy232); + yymsp[-11].minor.yy232 = addGroupByClause(pCxt, yymsp[-11].minor.yy232, yymsp[-1].minor.yy288); + yymsp[-11].minor.yy232 = addHavingClause(pCxt, yymsp[-11].minor.yy232, yymsp[0].minor.yy232); + yymsp[-11].minor.yy232 = addRangeClause(pCxt, yymsp[-11].minor.yy232, yymsp[-5].minor.yy232); + yymsp[-11].minor.yy232 = addEveryClause(pCxt, yymsp[-11].minor.yy232, yymsp[-4].minor.yy232); + yymsp[-11].minor.yy232 = addFillClause(pCxt, yymsp[-11].minor.yy232, yymsp[-3].minor.yy232); } break; - case 452: /* set_quantifier_opt ::= ALL */ -{ yymsp[0].minor.yy39 = false; } + case 455: /* set_quantifier_opt ::= ALL */ +{ yymsp[0].minor.yy777 = false; } break; - case 455: /* select_item ::= NK_STAR */ -{ yylhsminor.yy778 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0); } - yymsp[0].minor.yy778 = yylhsminor.yy778; + case 458: /* select_item ::= NK_STAR */ +{ yylhsminor.yy232 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0); } + yymsp[0].minor.yy232 = yylhsminor.yy232; break; - case 457: /* select_item ::= common_expression column_alias */ - case 467: /* partition_item ::= expr_or_subquery column_alias */ yytestcase(yyruleno==467); -{ yylhsminor.yy778 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy778), &yymsp[0].minor.yy181); } - yymsp[-1].minor.yy778 = yylhsminor.yy778; + case 460: /* select_item ::= common_expression column_alias */ + case 470: /* partition_item ::= expr_or_subquery column_alias */ yytestcase(yyruleno==470); +{ yylhsminor.yy232 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy232), &yymsp[0].minor.yy481); } + yymsp[-1].minor.yy232 = yylhsminor.yy232; break; - case 458: /* select_item ::= common_expression AS column_alias */ - case 468: /* partition_item ::= expr_or_subquery AS column_alias */ yytestcase(yyruleno==468); -{ yylhsminor.yy778 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), &yymsp[0].minor.yy181); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 461: /* select_item ::= common_expression AS column_alias */ + case 471: /* partition_item ::= expr_or_subquery AS column_alias */ yytestcase(yyruleno==471); +{ yylhsminor.yy232 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy232), &yymsp[0].minor.yy481); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 463: /* partition_by_clause_opt ::= PARTITION BY partition_list */ - case 485: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==485); - case 504: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==504); -{ yymsp[-2].minor.yy282 = yymsp[0].minor.yy282; } + case 466: /* partition_by_clause_opt ::= PARTITION BY partition_list */ + case 488: /* group_by_clause_opt ::= GROUP BY group_by_list */ yytestcase(yyruleno==488); + case 507: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ yytestcase(yyruleno==507); +{ yymsp[-2].minor.yy288 = yymsp[0].minor.yy288; } break; - case 470: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ -{ yymsp[-5].minor.yy778 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy778), releaseRawExprNode(pCxt, yymsp[-1].minor.yy778)); } + case 473: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA duration_literal NK_RP */ +{ yymsp[-5].minor.yy232 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy232), releaseRawExprNode(pCxt, yymsp[-1].minor.yy232)); } break; - case 471: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expr_or_subquery NK_RP */ -{ yymsp[-3].minor.yy778 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy778)); } + case 474: /* twindow_clause_opt ::= STATE_WINDOW NK_LP expr_or_subquery NK_RP */ +{ yymsp[-3].minor.yy232 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy232)); } break; - case 472: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-5].minor.yy778 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy778), NULL, yymsp[-1].minor.yy778, yymsp[0].minor.yy778); } + case 475: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-5].minor.yy232 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy232), NULL, yymsp[-1].minor.yy232, yymsp[0].minor.yy232); } break; - case 473: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ -{ yymsp[-7].minor.yy778 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy778), releaseRawExprNode(pCxt, yymsp[-3].minor.yy778), yymsp[-1].minor.yy778, yymsp[0].minor.yy778); } + case 476: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt fill_opt */ +{ yymsp[-7].minor.yy232 = createIntervalWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-5].minor.yy232), releaseRawExprNode(pCxt, yymsp[-3].minor.yy232), yymsp[-1].minor.yy232, yymsp[0].minor.yy232); } break; - case 477: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ -{ yymsp[-3].minor.yy778 = createFillNode(pCxt, yymsp[-1].minor.yy381, NULL); } + case 480: /* fill_opt ::= FILL NK_LP fill_mode NK_RP */ +{ yymsp[-3].minor.yy232 = createFillNode(pCxt, yymsp[-1].minor.yy614, NULL); } break; - case 478: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ -{ yymsp[-5].minor.yy778 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy282)); } + case 481: /* fill_opt ::= FILL NK_LP VALUE NK_COMMA literal_list NK_RP */ +{ yymsp[-5].minor.yy232 = createFillNode(pCxt, FILL_MODE_VALUE, createNodeListNode(pCxt, yymsp[-1].minor.yy288)); } break; - case 479: /* fill_mode ::= NONE */ -{ yymsp[0].minor.yy381 = FILL_MODE_NONE; } + case 482: /* fill_mode ::= NONE */ +{ yymsp[0].minor.yy614 = FILL_MODE_NONE; } break; - case 480: /* fill_mode ::= PREV */ -{ yymsp[0].minor.yy381 = FILL_MODE_PREV; } + case 483: /* fill_mode ::= PREV */ +{ yymsp[0].minor.yy614 = FILL_MODE_PREV; } break; - case 481: /* fill_mode ::= NULL */ -{ yymsp[0].minor.yy381 = FILL_MODE_NULL; } + case 484: /* fill_mode ::= NULL */ +{ yymsp[0].minor.yy614 = FILL_MODE_NULL; } break; - case 482: /* fill_mode ::= LINEAR */ -{ yymsp[0].minor.yy381 = FILL_MODE_LINEAR; } + case 485: /* fill_mode ::= LINEAR */ +{ yymsp[0].minor.yy614 = FILL_MODE_LINEAR; } break; - case 483: /* fill_mode ::= NEXT */ -{ yymsp[0].minor.yy381 = FILL_MODE_NEXT; } + case 486: /* fill_mode ::= NEXT */ +{ yymsp[0].minor.yy614 = FILL_MODE_NEXT; } break; - case 486: /* group_by_list ::= expr_or_subquery */ -{ yylhsminor.yy282 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy778))); } - yymsp[0].minor.yy282 = yylhsminor.yy282; + case 489: /* group_by_list ::= expr_or_subquery */ +{ yylhsminor.yy288 = createNodeList(pCxt, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy232))); } + yymsp[0].minor.yy288 = yylhsminor.yy288; break; - case 487: /* group_by_list ::= group_by_list NK_COMMA expr_or_subquery */ -{ yylhsminor.yy282 = addNodeToList(pCxt, yymsp[-2].minor.yy282, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy778))); } - yymsp[-2].minor.yy282 = yylhsminor.yy282; + case 490: /* group_by_list ::= group_by_list NK_COMMA expr_or_subquery */ +{ yylhsminor.yy288 = addNodeToList(pCxt, yymsp[-2].minor.yy288, createGroupingSetNode(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy232))); } + yymsp[-2].minor.yy288 = yylhsminor.yy288; break; - case 491: /* range_opt ::= RANGE NK_LP expr_or_subquery NK_COMMA expr_or_subquery NK_RP */ -{ yymsp[-5].minor.yy778 = createInterpTimeRange(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy778), releaseRawExprNode(pCxt, yymsp[-1].minor.yy778)); } + case 494: /* range_opt ::= RANGE NK_LP expr_or_subquery NK_COMMA expr_or_subquery NK_RP */ +{ yymsp[-5].minor.yy232 = createInterpTimeRange(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy232), releaseRawExprNode(pCxt, yymsp[-1].minor.yy232)); } break; - case 494: /* query_expression ::= query_simple order_by_clause_opt slimit_clause_opt limit_clause_opt */ + case 497: /* query_expression ::= query_simple order_by_clause_opt slimit_clause_opt limit_clause_opt */ { - yylhsminor.yy778 = addOrderByClause(pCxt, yymsp[-3].minor.yy778, yymsp[-2].minor.yy282); - yylhsminor.yy778 = addSlimitClause(pCxt, yylhsminor.yy778, yymsp[-1].minor.yy778); - yylhsminor.yy778 = addLimitClause(pCxt, yylhsminor.yy778, yymsp[0].minor.yy778); + yylhsminor.yy232 = addOrderByClause(pCxt, yymsp[-3].minor.yy232, yymsp[-2].minor.yy288); + yylhsminor.yy232 = addSlimitClause(pCxt, yylhsminor.yy232, yymsp[-1].minor.yy232); + yylhsminor.yy232 = addLimitClause(pCxt, yylhsminor.yy232, yymsp[0].minor.yy232); } - yymsp[-3].minor.yy778 = yylhsminor.yy778; + yymsp[-3].minor.yy232 = yylhsminor.yy232; break; - case 497: /* union_query_expression ::= query_simple_or_subquery UNION ALL query_simple_or_subquery */ -{ yylhsminor.yy778 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy778, yymsp[0].minor.yy778); } - yymsp[-3].minor.yy778 = yylhsminor.yy778; + case 500: /* union_query_expression ::= query_simple_or_subquery UNION ALL query_simple_or_subquery */ +{ yylhsminor.yy232 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy232, yymsp[0].minor.yy232); } + yymsp[-3].minor.yy232 = yylhsminor.yy232; break; - case 498: /* union_query_expression ::= query_simple_or_subquery UNION query_simple_or_subquery */ -{ yylhsminor.yy778 = createSetOperator(pCxt, SET_OP_TYPE_UNION, yymsp[-2].minor.yy778, yymsp[0].minor.yy778); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 501: /* union_query_expression ::= query_simple_or_subquery UNION query_simple_or_subquery */ +{ yylhsminor.yy232 = createSetOperator(pCxt, SET_OP_TYPE_UNION, yymsp[-2].minor.yy232, yymsp[0].minor.yy232); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 506: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ - case 510: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==510); -{ yymsp[-1].minor.yy778 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } + case 509: /* slimit_clause_opt ::= SLIMIT NK_INTEGER */ + case 513: /* limit_clause_opt ::= LIMIT NK_INTEGER */ yytestcase(yyruleno==513); +{ yymsp[-1].minor.yy232 = createLimitNode(pCxt, &yymsp[0].minor.yy0, NULL); } break; - case 507: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ - case 511: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==511); -{ yymsp[-3].minor.yy778 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } + case 510: /* slimit_clause_opt ::= SLIMIT NK_INTEGER SOFFSET NK_INTEGER */ + case 514: /* limit_clause_opt ::= LIMIT NK_INTEGER OFFSET NK_INTEGER */ yytestcase(yyruleno==514); +{ yymsp[-3].minor.yy232 = createLimitNode(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0); } break; - case 508: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ - case 512: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==512); -{ yymsp[-3].minor.yy778 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } + case 511: /* slimit_clause_opt ::= SLIMIT NK_INTEGER NK_COMMA NK_INTEGER */ + case 515: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==515); +{ yymsp[-3].minor.yy232 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); } break; - case 513: /* subquery ::= NK_LP query_expression NK_RP */ -{ yylhsminor.yy778 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy778); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 516: /* subquery ::= NK_LP query_expression NK_RP */ +{ yylhsminor.yy232 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy232); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 518: /* sort_specification ::= expr_or_subquery ordering_specification_opt null_ordering_opt */ -{ yylhsminor.yy778 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy778), yymsp[-1].minor.yy14, yymsp[0].minor.yy305); } - yymsp[-2].minor.yy778 = yylhsminor.yy778; + case 521: /* sort_specification ::= expr_or_subquery ordering_specification_opt null_ordering_opt */ +{ yylhsminor.yy232 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy232), yymsp[-1].minor.yy866, yymsp[0].minor.yy833); } + yymsp[-2].minor.yy232 = yylhsminor.yy232; break; - case 519: /* ordering_specification_opt ::= */ -{ yymsp[1].minor.yy14 = ORDER_ASC; } + case 522: /* ordering_specification_opt ::= */ +{ yymsp[1].minor.yy866 = ORDER_ASC; } break; - case 520: /* ordering_specification_opt ::= ASC */ -{ yymsp[0].minor.yy14 = ORDER_ASC; } + case 523: /* ordering_specification_opt ::= ASC */ +{ yymsp[0].minor.yy866 = ORDER_ASC; } break; - case 521: /* ordering_specification_opt ::= DESC */ -{ yymsp[0].minor.yy14 = ORDER_DESC; } + case 524: /* ordering_specification_opt ::= DESC */ +{ yymsp[0].minor.yy866 = ORDER_DESC; } break; - case 522: /* null_ordering_opt ::= */ -{ yymsp[1].minor.yy305 = NULL_ORDER_DEFAULT; } + case 525: /* null_ordering_opt ::= */ +{ yymsp[1].minor.yy833 = NULL_ORDER_DEFAULT; } break; - case 523: /* null_ordering_opt ::= NULLS FIRST */ -{ yymsp[-1].minor.yy305 = NULL_ORDER_FIRST; } + case 526: /* null_ordering_opt ::= NULLS FIRST */ +{ yymsp[-1].minor.yy833 = NULL_ORDER_FIRST; } break; - case 524: /* null_ordering_opt ::= NULLS LAST */ -{ yymsp[-1].minor.yy305 = NULL_ORDER_LAST; } + case 527: /* null_ordering_opt ::= NULLS LAST */ +{ yymsp[-1].minor.yy833 = NULL_ORDER_LAST; } break; default: break; diff --git a/source/libs/parser/test/mockCatalog.cpp b/source/libs/parser/test/mockCatalog.cpp index 7f18a7b28215192dc9f073018e795a205fbac929..4f5ddd9a51242563c4ea785a2dc88d182bc4be71 100644 --- a/source/libs/parser/test/mockCatalog.cpp +++ b/source/libs/parser/test/mockCatalog.cpp @@ -228,11 +228,21 @@ int32_t __catalogGetTableMeta(struct SCatalog* pCatalog, SRequestConnInfo* pConn return g_mockCatalogService->catalogGetTableMeta(pTableName, pTableMeta); } +int32_t __catalogGetCachedTableMeta(SCatalog* pCtg, const SName* pTableName, STableMeta** pTableMeta) { + return g_mockCatalogService->catalogGetTableMeta(pTableName, pTableMeta, true); +} + int32_t __catalogGetTableHashVgroup(struct SCatalog* pCatalog, SRequestConnInfo* pConn, const SName* pTableName, SVgroupInfo* vgInfo) { return g_mockCatalogService->catalogGetTableHashVgroup(pTableName, vgInfo); } +int32_t __catalogGetCachedTableHashVgroup(SCatalog* pCtg, const SName* pTableName, SVgroupInfo* pVgroup, bool* exists) { + int32_t code = g_mockCatalogService->catalogGetTableHashVgroup(pTableName, pVgroup, true); + *exists = 0 != pVgroup->vgId; + return code; +} + int32_t __catalogGetTableDistVgInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTableName, SArray** pVgList) { return g_mockCatalogService->catalogGetTableDistVgInfo(pTableName, pVgList); @@ -257,6 +267,13 @@ int32_t __catalogChkAuth(SCatalog* pCtg, SRequestConnInfo* pConn, const char* us return 0; } +int32_t __catalogChkAuthFromCache(SCatalog* pCtg, const char* user, const char* dbFName, AUTH_TYPE type, bool* pass, + bool* exists) { + *pass = true; + *exists = true; + return 0; +} + int32_t __catalogGetUdfInfo(SCatalog* pCtg, SRequestConnInfo* pConn, const char* funcName, SFuncInfo* pInfo) { return g_mockCatalogService->catalogGetUdfInfo(funcName, pInfo); } @@ -289,13 +306,17 @@ void initMetaDataEnv() { static Stub stub; stub.set(catalogGetHandle, __catalogGetHandle); stub.set(catalogGetTableMeta, __catalogGetTableMeta); + stub.set(catalogGetCachedTableMeta, __catalogGetCachedTableMeta); stub.set(catalogGetSTableMeta, __catalogGetTableMeta); + stub.set(catalogGetCachedSTableMeta, __catalogGetCachedTableMeta); stub.set(catalogGetTableHashVgroup, __catalogGetTableHashVgroup); + stub.set(catalogGetCachedTableHashVgroup, __catalogGetCachedTableHashVgroup); stub.set(catalogGetTableDistVgInfo, __catalogGetTableDistVgInfo); stub.set(catalogGetDBVgVersion, __catalogGetDBVgVersion); stub.set(catalogGetDBVgList, __catalogGetDBVgList); stub.set(catalogGetDBCfg, __catalogGetDBCfg); stub.set(catalogChkAuth, __catalogChkAuth); + stub.set(catalogChkAuthFromCache, __catalogChkAuthFromCache); stub.set(catalogGetUdfInfo, __catalogGetUdfInfo); stub.set(catalogRefreshGetTableMeta, __catalogRefreshGetTableMeta); stub.set(catalogRemoveTableMeta, __catalogRemoveTableMeta); diff --git a/source/libs/parser/test/mockCatalogService.cpp b/source/libs/parser/test/mockCatalogService.cpp index f2cebcb08d157a724e45bb4c5eebc7ba2873c4a9..95f7af435de89954b054b4ed0d19ca9b97d3953d 100644 --- a/source/libs/parser/test/mockCatalogService.cpp +++ b/source/libs/parser/test/mockCatalogService.cpp @@ -91,7 +91,7 @@ class MockCatalogServiceImpl { public: static const int32_t numOfDataTypes = sizeof(tDataTypes) / sizeof(tDataTypes[0]); - MockCatalogServiceImpl() : id_(1) {} + MockCatalogServiceImpl() : id_(1), havaCache_(true) {} ~MockCatalogServiceImpl() { for (auto& cfg : dbCfg_) { @@ -106,7 +106,11 @@ class MockCatalogServiceImpl { int32_t catalogGetHandle() const { return 0; } - int32_t catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const { + int32_t catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta, bool onlyCache = false) const { + if (onlyCache && !havaCache_) { + return TSDB_CODE_SUCCESS; + } + std::unique_ptr table; char db[TSDB_DB_NAME_LEN] = {0}; @@ -121,7 +125,12 @@ class MockCatalogServiceImpl { return TSDB_CODE_SUCCESS; } - int32_t catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo) const { + int32_t catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo, bool onlyCache = false) const { + if (onlyCache && !havaCache_) { + vgInfo->vgId = 0; + return TSDB_CODE_SUCCESS; + } + vgInfo->vgId = 1; return TSDB_CODE_SUCCESS; } @@ -618,6 +627,7 @@ class MockCatalogServiceImpl { IndexMetaCache index_; DnodeCache dnode_; DbCfgCache dbCfg_; + bool havaCache_; }; MockCatalogService::MockCatalogService() : impl_(new MockCatalogServiceImpl()) {} @@ -651,12 +661,14 @@ void MockCatalogService::createDatabase(const std::string& db, bool rollup, int8 impl_->createDatabase(db, rollup, cacheLast); } -int32_t MockCatalogService::catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const { - return impl_->catalogGetTableMeta(pTableName, pTableMeta); +int32_t MockCatalogService::catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta, + bool onlyCache) const { + return impl_->catalogGetTableMeta(pTableName, pTableMeta, onlyCache); } -int32_t MockCatalogService::catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo) const { - return impl_->catalogGetTableHashVgroup(pTableName, vgInfo); +int32_t MockCatalogService::catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo, + bool onlyCache) const { + return impl_->catalogGetTableHashVgroup(pTableName, vgInfo, onlyCache); } int32_t MockCatalogService::catalogGetTableDistVgInfo(const SName* pTableName, SArray** pVgList) const { diff --git a/source/libs/parser/test/mockCatalogService.h b/source/libs/parser/test/mockCatalogService.h index d9d2185728305ce4c4205f3c55ac10cda5231cb4..acd7fab8e17e2f9843d8b9beb3848f4f32c64c2b 100644 --- a/source/libs/parser/test/mockCatalogService.h +++ b/source/libs/parser/test/mockCatalogService.h @@ -67,8 +67,8 @@ class MockCatalogService { void createDnode(int32_t dnodeId, const std::string& host, int16_t port); void createDatabase(const std::string& db, bool rollup = false, int8_t cacheLast = 0); - int32_t catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta) const; - int32_t catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo) const; + int32_t catalogGetTableMeta(const SName* pTableName, STableMeta** pTableMeta, bool onlyCache = false) const; + int32_t catalogGetTableHashVgroup(const SName* pTableName, SVgroupInfo* vgInfo, bool onlyCache = false) const; int32_t catalogGetTableDistVgInfo(const SName* pTableName, SArray** pVgList) const; int32_t catalogGetDBVgList(const char* pDbFName, SArray** pVgList) const; int32_t catalogGetDBCfg(const char* pDbFName, SDbCfgInfo* pDbCfg) const; diff --git a/source/libs/parser/test/parInitialCTest.cpp b/source/libs/parser/test/parInitialCTest.cpp index 3ea6ae3db46eaac4a84c670cec781891541d4bf9..634fd3e1275cbe094920bb7958523dc8b8ad1d76 100644 --- a/source/libs/parser/test/parInitialCTest.cpp +++ b/source/libs/parser/test/parInitialCTest.cpp @@ -576,10 +576,10 @@ TEST_F(ParserInitialCTest, createStream) { memset(&expect, 0, sizeof(SCMCreateStreamReq)); }; - auto setCreateStreamReqFunc = [&](const char* pStream, const char* pSrcDb, const char* pSql, const char* pDstStb, - int8_t igExists = 0, int8_t triggerType = STREAM_TRIGGER_AT_ONCE, - int64_t maxDelay = 0, int64_t watermark = 0, - int8_t igExpired = STREAM_DEFAULT_IGNORE_EXPIRED) { + auto setCreateStreamReq = [&](const char* pStream, const char* pSrcDb, const char* pSql, const char* pDstStb, + int8_t igExists = 0, int8_t triggerType = STREAM_TRIGGER_AT_ONCE, int64_t maxDelay = 0, + int64_t watermark = 0, int8_t igExpired = STREAM_DEFAULT_IGNORE_EXPIRED, + int8_t fillHistory = STREAM_DEFAULT_FILL_HISTORY) { snprintf(expect.name, sizeof(expect.name), "0.%s", pStream); snprintf(expect.sourceDB, sizeof(expect.sourceDB), "0.%s", pSrcDb); snprintf(expect.targetStbFullName, sizeof(expect.targetStbFullName), "0.test.%s", pDstStb); @@ -588,6 +588,7 @@ TEST_F(ParserInitialCTest, createStream) { expect.triggerType = triggerType; expect.maxDelay = maxDelay; expect.watermark = watermark; + expect.fillHistory = fillHistory; expect.igExpired = igExpired; }; @@ -619,6 +620,7 @@ TEST_F(ParserInitialCTest, createStream) { ASSERT_EQ(req.triggerType, expect.triggerType); ASSERT_EQ(req.maxDelay, expect.maxDelay); ASSERT_EQ(req.watermark, expect.watermark); + ASSERT_EQ(req.fillHistory, expect.fillHistory); ASSERT_EQ(req.igExpired, expect.igExpired); ASSERT_EQ(req.numOfTags, expect.numOfTags); if (expect.numOfTags > 0) { @@ -636,24 +638,24 @@ TEST_F(ParserInitialCTest, createStream) { tFreeSCMCreateStreamReq(&req); }); - setCreateStreamReqFunc("s1", "test", "create stream s1 into st1 as select count(*) from t1 interval(10s)", "st1"); + setCreateStreamReq("s1", "test", "create stream s1 into st1 as select count(*) from t1 interval(10s)", "st1"); run("CREATE STREAM s1 INTO st1 AS SELECT COUNT(*) FROM t1 INTERVAL(10S)"); clearCreateStreamReq(); - setCreateStreamReqFunc("s1", "test", - "create stream if not exists s1 trigger max_delay 20s watermark 10s ignore expired 0 into st1 " - "as select count(*) from t1 interval(10s)", - "st1", 1, STREAM_TRIGGER_MAX_DELAY, 20 * MILLISECOND_PER_SECOND, 10 * MILLISECOND_PER_SECOND, - 0); - run("CREATE STREAM IF NOT EXISTS s1 TRIGGER MAX_DELAY 20s WATERMARK 10s IGNORE EXPIRED 0 INTO st1 AS SELECT COUNT(*) " + setCreateStreamReq( + "s1", "test", + "create stream if not exists s1 trigger max_delay 20s watermark 10s ignore expired 0 fill_history 1 into st1 " + "as select count(*) from t1 interval(10s)", + "st1", 1, STREAM_TRIGGER_MAX_DELAY, 20 * MILLISECOND_PER_SECOND, 10 * MILLISECOND_PER_SECOND, 0, 1); + run("CREATE STREAM IF NOT EXISTS s1 TRIGGER MAX_DELAY 20s WATERMARK 10s IGNORE EXPIRED 0 FILL_HISTORY 1 INTO st1 AS " + "SELECT COUNT(*) " "FROM t1 INTERVAL(10S)"); clearCreateStreamReq(); - setCreateStreamReqFunc( - "s1", "test", - "create stream s1 into st3 tags(tname varchar(10), id int) subtable(concat('new-', tname)) as " - "select _wstart wstart, count(*) cnt from st1 partition by tbname tname, tag1 id interval(10s)", - "st3"); + setCreateStreamReq("s1", "test", + "create stream s1 into st3 tags(tname varchar(10), id int) subtable(concat('new-', tname)) as " + "select _wstart wstart, count(*) cnt from st1 partition by tbname tname, tag1 id interval(10s)", + "st3"); addTag("tname", TSDB_DATA_TYPE_VARCHAR, 10 + VARSTR_HEADER_SIZE); addTag("id", TSDB_DATA_TYPE_INT); run("CREATE STREAM s1 INTO st3 TAGS(tname VARCHAR(10), id INT) SUBTABLE(CONCAT('new-', tname)) " diff --git a/source/libs/parser/test/parInitialDTest.cpp b/source/libs/parser/test/parInitialDTest.cpp index c7865f3da37438e81ded4627bb8d278d203cbd91..3ded71242b961ceaf12abbdff44272c7fa6cb32c 100644 --- a/source/libs/parser/test/parInitialDTest.cpp +++ b/source/libs/parser/test/parInitialDTest.cpp @@ -87,7 +87,6 @@ TEST_F(ParserInitialDTest, dropConsumerGroup) { // todo DROP database -// todo DROP dnode TEST_F(ParserInitialDTest, dropDnode) { useDb("root", "test"); @@ -95,11 +94,15 @@ TEST_F(ParserInitialDTest, dropDnode) { auto clearDropDnodeReq = [&]() { memset(&expect, 0, sizeof(SDropDnodeReq)); }; - auto setDropDnodeReqById = [&](int32_t dnodeId) { expect.dnodeId = dnodeId; }; + auto setDropDnodeReqById = [&](int32_t dnodeId, bool force = false) { + expect.dnodeId = dnodeId; + expect.force = force; + }; - auto setDropDnodeReqByEndpoint = [&](const char* pFqdn, int32_t port) { + auto setDropDnodeReqByEndpoint = [&](const char* pFqdn, int32_t port, bool force = false) { strcpy(expect.fqdn, pFqdn); expect.port = port; + expect.force = force; }; setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) { @@ -110,15 +113,24 @@ TEST_F(ParserInitialDTest, dropDnode) { ASSERT_EQ(req.dnodeId, expect.dnodeId); ASSERT_EQ(std::string(req.fqdn), std::string(expect.fqdn)); ASSERT_EQ(req.port, expect.port); + ASSERT_EQ(req.force, expect.force); }); setDropDnodeReqById(1); run("DROP DNODE 1"); clearDropDnodeReq(); + setDropDnodeReqById(2, true); + run("DROP DNODE 2 FORCE"); + clearDropDnodeReq(); + setDropDnodeReqByEndpoint("host1", 7030); run("DROP DNODE 'host1:7030'"); clearDropDnodeReq(); + + setDropDnodeReqByEndpoint("host2", 8030, true); + run("DROP DNODE 'host2:8030' FORCE"); + clearDropDnodeReq(); } // todo DROP function diff --git a/source/libs/parser/test/parSelectTest.cpp b/source/libs/parser/test/parSelectTest.cpp index 0027ac9ca1967e4945c816471b989733820d500b..fcd8dd1f2635040f7f4b7e59f07302246f0a7630 100644 --- a/source/libs/parser/test/parSelectTest.cpp +++ b/source/libs/parser/test/parSelectTest.cpp @@ -425,6 +425,8 @@ TEST_F(ParserSelectTest, informationSchema) { run("SELECT * FROM ins_databases WHERE name = 'information_schema'"); run("SELECT * FROM ins_tags WHERE db_name = 'test' and table_name = 'st1'"); + + run("SELECT * FROM (SELECT table_name FROM ins_tables) t WHERE table_name = 'a'"); } TEST_F(ParserSelectTest, withoutFrom) { diff --git a/source/libs/parser/test/parTestUtil.cpp b/source/libs/parser/test/parTestUtil.cpp index bf27fd2e13191cbdae8bdefc478e5f8f0bc86375..dbae302e426fb0c842c175ae17b71a1f1767e65d 100644 --- a/source/libs/parser/test/parTestUtil.cpp +++ b/source/libs/parser/test/parTestUtil.cpp @@ -233,16 +233,15 @@ class ParserTestBaseImpl { } void doBuildCatalogReq(SParseContext* pCxt, const SParseMetaCache* pMetaCache, SCatalogReq* pCatalogReq) { - DO_WITH_THROW(buildCatalogReq, pCxt, pMetaCache, pCatalogReq); + DO_WITH_THROW(buildCatalogReq, pMetaCache, pCatalogReq); } void doGetAllMeta(const SCatalogReq* pCatalogReq, SMetaData* pMetaData) { DO_WITH_THROW(g_mockCatalogService->catalogGetAllMeta, pCatalogReq, pMetaData); } - void doPutMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMetaData, SParseMetaCache* pMetaCache, - bool isInsertValues) { - DO_WITH_THROW(putMetaDataToCache, pCatalogReq, pMetaData, pMetaCache, isInsertValues); + void doPutMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMetaData, SParseMetaCache* pMetaCache) { + DO_WITH_THROW(putMetaDataToCache, pCatalogReq, pMetaData, pMetaCache); } void doAuthenticate(SParseContext* pCxt, SQuery* pQuery, SParseMetaCache* pMetaCache) { @@ -280,21 +279,24 @@ class ParserTestBaseImpl { res_.calcConstAst_ = toString(pQuery->pRoot); } - void doParseInsertSql(SParseContext* pCxt, SQuery** pQuery, SParseMetaCache* pMetaCache) { - DO_WITH_THROW(parseInsertSql, pCxt, pQuery, pMetaCache); + void doParseInsertSql(SParseContext* pCxt, SQuery** pQuery, SCatalogReq* pCatalogReq, const SMetaData* pMetaData) { + DO_WITH_THROW(parseInsertSql, pCxt, pQuery, pCatalogReq, pMetaData); ASSERT_NE(*pQuery, nullptr); res_.parsedAst_ = toString((*pQuery)->pRoot); } - void doParseInsertSyntax(SParseContext* pCxt, SQuery** pQuery, SParseMetaCache* pMetaCache) { - DO_WITH_THROW(parseInsertSyntax, pCxt, pQuery, pMetaCache); - ASSERT_NE(*pQuery, nullptr); + void doContinueParseSql(SParseContext* pCxt, SCatalogReq* pCatalogReq, const SMetaData* pMetaData, SQuery* pQuery) { + DO_WITH_THROW(qContinueParseSql, pCxt, pCatalogReq, pMetaData, pQuery); } string toString(const SNode* pRoot) { char* pStr = NULL; int32_t len = 0; DO_WITH_THROW(nodesNodeToString, pRoot, false, &pStr, &len) + // check toObject + SNode* pCopy = NULL; + DO_WITH_THROW(nodesStringToNode, pStr, &pCopy) + nodesDestroyNode(pCopy); string str(pStr); taosMemoryFreeClear(pStr); return str; @@ -310,7 +312,7 @@ class ParserTestBaseImpl { if (qIsInsertValuesSql(cxt.pSql, cxt.sqlLen)) { unique_ptr query((SQuery**)taosMemoryCalloc(1, sizeof(SQuery*)), destroyQuery); - doParseInsertSql(&cxt, query.get(), nullptr); + doParseInsertSql(&cxt, query.get(), nullptr, nullptr); } else { unique_ptr query((SQuery**)taosMemoryCalloc(1, sizeof(SQuery*)), destroyQuery); doParse(&cxt, query.get()); @@ -356,61 +358,102 @@ class ParserTestBaseImpl { } } - void runAsyncInternalFuncs(const string& sql, int32_t expect, ParserStage checkStage) { - reset(expect, checkStage, TEST_INTERFACE_ASYNC_INTERNAL); - try { - unique_ptr > cxt(new SParseContext(), destoryParseContext); - setParseContext(sql, cxt.get(), true); - - unique_ptr query((SQuery**)taosMemoryCalloc(1, sizeof(SQuery*)), destroyQuery); - bool request = true; - unique_ptr > metaCache( - new SParseMetaCache(), bind(destoryParseMetaCacheWarpper, _1, cref(request))); - bool isInsertValues = qIsInsertValuesSql(cxt->pSql, cxt->sqlLen); - if (isInsertValues) { - doParseInsertSyntax(cxt.get(), query.get(), metaCache.get()); - } else { - doParse(cxt.get(), query.get()); - doCollectMetaKey(cxt.get(), *(query.get()), metaCache.get()); + void runQueryAsyncInternalFuncs(SParseContext* pParCxt) { + unique_ptr query((SQuery**)taosMemoryCalloc(1, sizeof(SQuery*)), destroyQuery); + bool request = true; + unique_ptr > metaCache( + new SParseMetaCache(), bind(destoryParseMetaCacheWarpper, _1, cref(request))); + doParse(pParCxt, query.get()); + doCollectMetaKey(pParCxt, *(query.get()), metaCache.get()); + + SQuery* pQuery = *(query.get()); + + unique_ptr catalogReq(new SCatalogReq(), + MockCatalogService::destoryCatalogReq); + doBuildCatalogReq(pParCxt, metaCache.get(), catalogReq.get()); + + string err; + thread t1([&]() { + try { + unique_ptr metaData(new SMetaData(), MockCatalogService::destoryMetaData); + doGetAllMeta(catalogReq.get(), metaData.get()); + + metaCache.reset(new SParseMetaCache()); + request = false; + doPutMetaDataToCache(catalogReq.get(), metaData.get(), metaCache.get()); + + doAuthenticate(pParCxt, pQuery, metaCache.get()); + + doTranslate(pParCxt, pQuery, metaCache.get()); + + doCalculateConstant(pParCxt, pQuery); + } catch (const TerminateFlag& e) { + // success and terminate + } catch (const runtime_error& e) { + err = e.what(); + } catch (...) { + err = "unknown error"; } + }); - SQuery* pQuery = *(query.get()); - - unique_ptr catalogReq(new SCatalogReq(), - MockCatalogService::destoryCatalogReq); - doBuildCatalogReq(cxt.get(), metaCache.get(), catalogReq.get()); + t1.join(); + if (!err.empty()) { + throw runtime_error(err); + } + } - string err; - thread t1([&]() { - try { - unique_ptr metaData(new SMetaData(), MockCatalogService::destoryMetaData); - doGetAllMeta(catalogReq.get(), metaData.get()); + void runInsertAsyncInternalFuncsImpl(SParseContext* pParCxt, SQuery** pQuery, SCatalogReq* pCatalogReq, + SMetaData* pMetaData) { + doParseInsertSql(pParCxt, pQuery, pCatalogReq, pMetaData); - metaCache.reset(new SParseMetaCache()); - request = false; - doPutMetaDataToCache(catalogReq.get(), metaData.get(), metaCache.get(), isInsertValues); + if (QUERY_EXEC_STAGE_SCHEDULE == (*pQuery)->execStage) { + return; + } - if (isInsertValues) { - doParseInsertSql(cxt.get(), query.get(), metaCache.get()); - } else { - doAuthenticate(cxt.get(), pQuery, metaCache.get()); + string err; + thread t1([&]() { + try { + doGetAllMeta(pCatalogReq, pMetaData); - doTranslate(cxt.get(), pQuery, metaCache.get()); + doParseInsertSql(pParCxt, pQuery, pCatalogReq, pMetaData); - doCalculateConstant(cxt.get(), pQuery); - } - } catch (const TerminateFlag& e) { - // success and terminate - } catch (const runtime_error& e) { - err = e.what(); - } catch (...) { - err = "unknown error"; + if (QUERY_EXEC_STAGE_SCHEDULE != (*pQuery)->execStage) { + runInsertAsyncInternalFuncsImpl(pParCxt, pQuery, pCatalogReq, pMetaData); } - }); + } catch (const TerminateFlag& e) { + // success and terminate + } catch (const runtime_error& e) { + err = e.what(); + } catch (...) { + err = "unknown error"; + } + }); + + t1.join(); + if (!err.empty()) { + throw runtime_error(err); + } + } + + void runInsertAsyncInternalFuncs(SParseContext* pParCxt) { + unique_ptr query((SQuery**)taosMemoryCalloc(1, sizeof(SQuery*)), destroyQuery); + unique_ptr catalogReq(new SCatalogReq(), + MockCatalogService::destoryCatalogReq); + unique_ptr metaData(new SMetaData(), MockCatalogService::destoryMetaData); + runInsertAsyncInternalFuncsImpl(pParCxt, query.get(), catalogReq.get(), metaData.get()); + } + + void runAsyncInternalFuncs(const string& sql, int32_t expect, ParserStage checkStage) { + reset(expect, checkStage, TEST_INTERFACE_ASYNC_INTERNAL); + try { + unique_ptr > cxt(new SParseContext(), destoryParseContext); + setParseContext(sql, cxt.get(), true); - t1.join(); - if (!err.empty()) { - throw runtime_error(err); + bool isInsertValues = qIsInsertValuesSql(cxt->pSql, cxt->sqlLen); + if (isInsertValues) { + runInsertAsyncInternalFuncs(cxt.get()); + } else { + runQueryAsyncInternalFuncs(cxt.get()); } if (g_dump) { @@ -437,25 +480,39 @@ class ParserTestBaseImpl { doParseSqlSyntax(cxt.get(), query.get(), catalogReq.get()); SQuery* pQuery = *(query.get()); - string err; - thread t1([&]() { - try { - unique_ptr metaData(new SMetaData(), MockCatalogService::destoryMetaData); - doGetAllMeta(catalogReq.get(), metaData.get()); - - doAnalyseSqlSemantic(cxt.get(), catalogReq.get(), metaData.get(), pQuery); - } catch (const TerminateFlag& e) { - // success and terminate - } catch (const runtime_error& e) { - err = e.what(); - } catch (...) { - err = "unknown error"; + switch (pQuery->execStage) { + case QUERY_EXEC_STAGE_PARSE: + case QUERY_EXEC_STAGE_ANALYSE: { + string err; + thread t1([&]() { + try { + unique_ptr metaData(new SMetaData(), + MockCatalogService::destoryMetaData); + doGetAllMeta(catalogReq.get(), metaData.get()); + if (QUERY_EXEC_STAGE_PARSE == pQuery->execStage) { + doContinueParseSql(cxt.get(), catalogReq.get(), metaData.get(), pQuery); + } else { + doAnalyseSqlSemantic(cxt.get(), catalogReq.get(), metaData.get(), pQuery); + } + } catch (const TerminateFlag& e) { + // success and terminate + } catch (const runtime_error& e) { + err = e.what(); + } catch (...) { + err = "unknown error"; + } + }); + + t1.join(); + if (!err.empty()) { + throw runtime_error(err); + } + break; } - }); - - t1.join(); - if (!err.empty()) { - throw runtime_error(err); + case QUERY_EXEC_STAGE_SCHEDULE: + break; + default: + break; } if (g_dump) { diff --git a/source/libs/planner/src/planLogicCreater.c b/source/libs/planner/src/planLogicCreater.c index a047495e6105349bba201f5fee0c2ea74940c85c..275983f8699ae97fc708055ee4aa739852ae4de8 100644 --- a/source/libs/planner/src/planLogicCreater.c +++ b/source/libs/planner/src/planLogicCreater.c @@ -339,29 +339,6 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect return code; } -static int32_t createColumnByLastRow(SNodeList* pFuncs, SNodeList** pOutput) { - int32_t code = TSDB_CODE_SUCCESS; - SNodeList* pCols = NULL; - SNode* pFunc = NULL; - FOREACH(pFunc, pFuncs) { - SFunctionNode* pLastRow = (SFunctionNode*)pFunc; - SColumnNode* pCol = (SColumnNode*)nodesListGetNode(pLastRow->pParameterList, 0); - snprintf(pCol->colName, sizeof(pCol->colName), "%s", pLastRow->node.aliasName); - snprintf(pCol->node.aliasName, sizeof(pCol->colName), "%s", pLastRow->node.aliasName); - NODES_CLEAR_LIST(pLastRow->pParameterList); - code = nodesListMakeStrictAppend(&pCols, (SNode*)pCol); - if (TSDB_CODE_SUCCESS != code) { - break; - } - } - if (TSDB_CODE_SUCCESS == code) { - *pOutput = pCols; - } else { - nodesDestroyList(pCols); - } - return code; -} - static int32_t createSubqueryLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, STempTableNode* pTable, SLogicNode** pLogicNode) { return createQueryLogicNode(pCxt, pTable->pSubquery, pLogicNode); @@ -491,20 +468,6 @@ static SNode* createGroupingSetNode(SNode* pExpr) { return (SNode*)pGroupingSet; } -static int32_t createGroupKeysFromPartKeys(SNodeList* pPartKeys, SNodeList** pOutput) { - SNodeList* pGroupKeys = NULL; - SNode* pPartKey = NULL; - FOREACH(pPartKey, pPartKeys) { - int32_t code = nodesListMakeStrictAppend(&pGroupKeys, createGroupingSetNode(pPartKey)); - if (TSDB_CODE_SUCCESS != code) { - nodesDestroyList(pGroupKeys); - return code; - } - } - *pOutput = pGroupKeys; - return TSDB_CODE_SUCCESS; -} - static EGroupAction getGroupAction(SLogicPlanContext* pCxt, SSelectStmt* pSelect) { return (pCxt->pPlanCxt->streamQuery || NULL != pSelect->pLimit || NULL != pSelect->pSlimit) ? GROUP_ACTION_KEEP : GROUP_ACTION_NONE; @@ -624,6 +587,10 @@ static int32_t createIndefRowsFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt return code; } +static bool isInterpFunc(int32_t funcId) { + return fmIsInterpFunc(funcId) || fmIsInterpPseudoColumnFunc(funcId) || fmIsGroupKeyFunc(funcId); +} + static int32_t createInterpFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) { if (!pSelect->hasInterpFunc) { return TSDB_CODE_SUCCESS; @@ -639,7 +606,7 @@ static int32_t createInterpFuncLogicNode(SLogicPlanContext* pCxt, SSelectStmt* p pInterpFunc->node.resultDataOrder = pInterpFunc->node.requireDataOrder; // interp functions and _group_key functions - int32_t code = nodesCollectFuncs(pSelect, SQL_CLAUSE_SELECT, fmIsVectorFunc, &pInterpFunc->pFuncs); + int32_t code = nodesCollectFuncs(pSelect, SQL_CLAUSE_SELECT, isInterpFunc, &pInterpFunc->pFuncs); if (TSDB_CODE_SUCCESS == code) { code = rewriteExprsForSelect(pInterpFunc->pFuncs, pSelect, SQL_CLAUSE_SELECT); } diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 9c9a7cfebbcf8fd52c5295879dfdd0f66e5ab156..79f33f3ac33fb1586780578d63d5a09d1b878a25 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -279,7 +279,7 @@ static EFuncDataRequired scanPathOptPromoteDataRequired(EFuncDataRequired l, EFu switch (l) { case FUNC_DATA_REQUIRED_DATA_LOAD: return l; - case FUNC_DATA_REQUIRED_STATIS_LOAD: + case FUNC_DATA_REQUIRED_SMA_LOAD: return FUNC_DATA_REQUIRED_DATA_LOAD == r ? r : l; case FUNC_DATA_REQUIRED_NOT_LOAD: return FUNC_DATA_REQUIRED_FILTEROUT == r ? l : r; @@ -596,18 +596,6 @@ static int32_t pushDownCondOptPushCondToOnCond(SOptimizeContext* pCxt, SJoinLogi return pushDownCondOptAppendCond(&pJoin->pOnConditions, pCond); } -static int32_t pushDownCondOptPushCondToScan(SOptimizeContext* pCxt, SScanLogicNode* pScan, SNode** pCond) { - return pushDownCondOptAppendCond(&pScan->node.pConditions, pCond); -} - -static int32_t pushDownCondOptPushCondToProject(SOptimizeContext* pCxt, SProjectLogicNode* pProject, SNode** pCond) { - return pushDownCondOptAppendCond(&pProject->node.pConditions, pCond); -} - -static int32_t pushDownCondOptPushCondToJoin(SOptimizeContext* pCxt, SJoinLogicNode* pJoin, SNode** pCond) { - return pushDownCondOptAppendCond(&pJoin->node.pConditions, pCond); -} - static int32_t pushDownCondOptPushCondToChild(SOptimizeContext* pCxt, SLogicNode* pChild, SNode** pCond) { return pushDownCondOptAppendCond(&pChild->pConditions, pCond); } @@ -1201,40 +1189,6 @@ static bool smaIndexOptMayBeOptimized(SLogicNode* pNode) { return true; } -static int32_t smaIndexOptCreateMerge(SLogicNode* pChild, SNodeList* pMergeKeys, SNodeList* pTargets, - SLogicNode** pOutput) { - SMergeLogicNode* pMerge = (SMergeLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_MERGE); - if (NULL == pMerge) { - return TSDB_CODE_OUT_OF_MEMORY; - } - pMerge->node.precision = pChild->precision; - pMerge->numOfChannels = 2; - pMerge->pMergeKeys = pMergeKeys; - pMerge->node.pTargets = pTargets; - pMerge->pInputs = nodesCloneList(pChild->pTargets); - if (NULL == pMerge->pInputs) { - nodesDestroyNode((SNode*)pMerge); - return TSDB_CODE_OUT_OF_MEMORY; - } - - *pOutput = (SLogicNode*)pMerge; - return TSDB_CODE_SUCCESS; -} - -static int32_t smaIndexOptRecombinationNode(SLogicSubplan* pLogicSubplan, SLogicNode* pInterval, SLogicNode* pMerge, - SLogicNode* pSmaScan) { - int32_t code = nodesListMakeAppend(&pMerge->pChildren, (SNode*)pInterval); - if (TSDB_CODE_SUCCESS == code) { - code = nodesListMakeAppend(&pMerge->pChildren, (SNode*)pSmaScan); - } - if (TSDB_CODE_SUCCESS == code) { - code = replaceLogicNode(pLogicSubplan, pInterval, pMerge); - pSmaScan->pParent = pMerge; - pInterval->pParent = pMerge; - } - return code; -} - static int32_t smaIndexOptCreateSmaScan(SScanLogicNode* pScan, STableIndexInfo* pIndex, SNodeList* pCols, SLogicNode** pOutput) { SScanLogicNode* pSmaScan = (SScanLogicNode*)nodesMakeNode(QUERY_NODE_LOGIC_PLAN_SCAN); @@ -1770,7 +1724,7 @@ static int32_t rewriteTailOptCreateLimit(SNode* pLimit, SNode* pOffset, SNode** return TSDB_CODE_OUT_OF_MEMORY; } pLimitNode->limit = NULL == pLimit ? -1 : ((SValueNode*)pLimit)->datum.i; - pLimitNode->offset = NULL == pOffset ? -1 : ((SValueNode*)pOffset)->datum.i; + pLimitNode->offset = NULL == pOffset ? 0 : ((SValueNode*)pOffset)->datum.i; *pOutput = (SNode*)pLimitNode; return TSDB_CODE_SUCCESS; } @@ -2498,7 +2452,7 @@ static const SOptimizeRule optimizeRuleSet[] = { {.pName = "RewriteUnique", .optimizeFunc = rewriteUniqueOptimize}, {.pName = "LastRowScan", .optimizeFunc = lastRowScanOptimize}, {.pName = "TagScan", .optimizeFunc = tagScanOptimize}, - // {.pName = "PushDownLimit", .optimizeFunc = pushDownLimitOptimize} + {.pName = "PushDownLimit", .optimizeFunc = pushDownLimitOptimize} }; // clang-format on diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 8ff8538c0dbe934ba22beda84dce6c5fdc99749f..72f3d995bc9bf7edfd5cc9b585bd24f3069342c4 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -584,6 +584,7 @@ static int32_t createSystemTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* return TSDB_CODE_OUT_OF_MEMORY; } + pSubplan->showRewrite = pScanLogicNode->showRewrite; pScan->showRewrite = pScanLogicNode->showRewrite; pScan->accountId = pCxt->pPlanCxt->acctId; pScan->sysInfo = pCxt->pPlanCxt->sysInfo; diff --git a/source/libs/planner/src/planSpliter.c b/source/libs/planner/src/planSpliter.c index 62c7eaef552365513cfdfdb4c061b65b27fcc1bf..249ba1815de6067274d2cdd6a5d8782cfcd47d66 100644 --- a/source/libs/planner/src/planSpliter.c +++ b/source/libs/planner/src/planSpliter.c @@ -66,16 +66,36 @@ static SLogicSubplan* splCreateScanSubplan(SSplitContext* pCxt, SLogicNode* pNod return pSubplan; } -static SLogicSubplan* splCreateSubplan(SSplitContext* pCxt, SLogicNode* pNode, ESubplanType subplanType) { +static bool splHasScan(SLogicNode* pNode) { + if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode)) { + return true; + } + + SNode* pChild = NULL; + FOREACH(pChild, pNode->pChildren) { + if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pChild)) { + return true; + } + return splHasScan((SLogicNode*)pChild); + } + + return false; +} + +static void splSetSubplanType(SLogicSubplan* pSubplan) { + pSubplan->subplanType = splHasScan(pSubplan->pNode) ? SUBPLAN_TYPE_SCAN : SUBPLAN_TYPE_MERGE; +} + +static SLogicSubplan* splCreateSubplan(SSplitContext* pCxt, SLogicNode* pNode) { SLogicSubplan* pSubplan = (SLogicSubplan*)nodesMakeNode(QUERY_NODE_LOGIC_SUBPLAN); if (NULL == pSubplan) { return NULL; } pSubplan->id.queryId = pCxt->queryId; pSubplan->id.groupId = pCxt->groupId; - pSubplan->subplanType = subplanType; pSubplan->pNode = pNode; pNode->pParent = NULL; + splSetSubplanType(pSubplan); return pSubplan; } @@ -97,6 +117,7 @@ static int32_t splCreateExchangeNode(SSplitContext* pCxt, SLogicNode* pChild, SE if (NULL == pExchange->node.pLimit) { return TSDB_CODE_OUT_OF_MEMORY; } + ((SLimitNode*)pChild->pLimit)->limit += ((SLimitNode*)pChild->pLimit)->offset; ((SLimitNode*)pChild->pLimit)->offset = 0; } @@ -470,6 +491,12 @@ static int32_t stbSplCreateMergeNode(SSplitContext* pCxt, SLogicSubplan* pSubpla if (NULL == pMerge->node.pTargets || NULL == pMerge->pInputs) { code = TSDB_CODE_OUT_OF_MEMORY; } + if (TSDB_CODE_SUCCESS == code && NULL != pSplitNode->pLimit) { + pMerge->node.pLimit = nodesCloneNode(pSplitNode->pLimit); + if (NULL == pMerge->node.pLimit) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + } if (TSDB_CODE_SUCCESS == code) { if (NULL == pSubplan) { code = nodesListMakeAppend(&pSplitNode->pChildren, (SNode*)pMerge); @@ -934,6 +961,7 @@ static int32_t stbSplSplitScanNodeWithoutPartTags(SSplitContext* pCxt, SStableSp if (NULL == pSplitNode->pLimit) { return TSDB_CODE_OUT_OF_MEMORY; } + ((SLimitNode*)pInfo->pSplitNode->pLimit)->limit += ((SLimitNode*)pInfo->pSplitNode->pLimit)->offset; ((SLimitNode*)pInfo->pSplitNode->pLimit)->offset = 0; } } @@ -1021,6 +1049,10 @@ static int32_t stbSplSplitMergeScanNode(SSplitContext* pCxt, SLogicSubplan* pSub SNodeList* pMergeKeys = NULL; int32_t code = stbSplCreateMergeScanNode(pScan, &pMergeScan, &pMergeKeys); if (TSDB_CODE_SUCCESS == code) { + if (NULL != pMergeScan->pLimit) { + ((SLimitNode*)pMergeScan->pLimit)->limit += ((SLimitNode*)pMergeScan->pLimit)->offset; + ((SLimitNode*)pMergeScan->pLimit)->offset = 0; + } code = stbSplCreateMergeNode(pCxt, pSubplan, (SLogicNode*)pScan, pMergeKeys, pMergeScan, groupSort); } if (TSDB_CODE_SUCCESS == code) { @@ -1192,7 +1224,7 @@ static int32_t unionSplitSubplan(SSplitContext* pCxt, SLogicSubplan* pUnionSubpl SNode* pChild = NULL; FOREACH(pChild, pSplitNode->pChildren) { - SLogicSubplan* pNewSubplan = splCreateSubplan(pCxt, (SLogicNode*)pChild, pUnionSubplan->subplanType); + SLogicSubplan* pNewSubplan = splCreateSubplan(pCxt, (SLogicNode*)pChild); code = nodesListMakeStrictAppend(&pUnionSubplan->pChildren, (SNode*)pNewSubplan); if (TSDB_CODE_SUCCESS == code) { REPLACE_NODE(NULL); @@ -1378,10 +1410,9 @@ static int32_t insertSelectSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) { SLogicSubplan* pNewSubplan = NULL; SNodeList* pSubplanChildren = info.pSubplan->pChildren; - ESubplanType subplanType = info.pSubplan->subplanType; int32_t code = splCreateExchangeNodeForSubplan(pCxt, info.pSubplan, info.pQueryRoot, SUBPLAN_TYPE_MODIFY); if (TSDB_CODE_SUCCESS == code) { - pNewSubplan = splCreateSubplan(pCxt, info.pQueryRoot, subplanType); + pNewSubplan = splCreateSubplan(pCxt, info.pQueryRoot); if (NULL == pNewSubplan) { code = TSDB_CODE_OUT_OF_MEMORY; } @@ -1407,7 +1438,8 @@ typedef struct SQnodeSplitInfo { static bool qndSplFindSplitNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SLogicNode* pNode, SQnodeSplitInfo* pInfo) { if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode) && NULL != pNode->pParent && - ((SScanLogicNode*)pNode)->scanSeq[0] < 1 && ((SScanLogicNode*)pNode)->scanSeq[1] < 1) { + QUERY_NODE_LOGIC_PLAN_INTERP_FUNC != nodeType(pNode->pParent) && ((SScanLogicNode*)pNode)->scanSeq[0] <= 1 && + ((SScanLogicNode*)pNode)->scanSeq[1] <= 1) { pInfo->pSplitNode = pNode; pInfo->pSubplan = pSubplan; return true; diff --git a/source/libs/planner/src/planner.c b/source/libs/planner/src/planner.c index 53549c122d958bbb043f2e9c885d91ea2b742ad1..c6a4a97f6ed9179cbae090c8b16f7e298b9ea0ba 100644 --- a/source/libs/planner/src/planner.c +++ b/source/libs/planner/src/planner.c @@ -142,15 +142,6 @@ int32_t qMsgToSubplan(const char* pStr, int32_t len, SSubplan** pSubplan) { return nodesMsgToNode(pStr, len, (SNode**)pSubplan); } -char* qQueryPlanToString(const SQueryPlan* pPlan) { - char* pStr = NULL; - int32_t len = 0; - if (TSDB_CODE_SUCCESS != nodesNodeToString((SNode*)pPlan, false, &pStr, &len)) { - return NULL; - } - return pStr; -} - SQueryPlan* qStringToQueryPlan(const char* pStr) { SQueryPlan* pPlan = NULL; if (TSDB_CODE_SUCCESS != nodesStringToNode(pStr, (SNode**)&pPlan)) { diff --git a/source/libs/planner/test/planStateTest.cpp b/source/libs/planner/test/planStateTest.cpp index 6985bc88070e2340af28b51c716b1da3db54f0cb..3dafaa8bf556212382a4a0e8c2ec27e818415290 100644 --- a/source/libs/planner/test/planStateTest.cpp +++ b/source/libs/planner/test/planStateTest.cpp @@ -29,7 +29,7 @@ TEST_F(PlanStateTest, basic) { TEST_F(PlanStateTest, stateExpr) { useDb("root", "test"); - run("SELECT COUNT(*) FROM t1 STATE_WINDOW(c1 + 10)"); + run("SELECT COUNT(*) FROM t1 STATE_WINDOW(CASE WHEN c1 > 10 THEN 1 ELSE 0 END)"); } TEST_F(PlanStateTest, selectFunc) { diff --git a/source/libs/planner/test/planTestUtil.cpp b/source/libs/planner/test/planTestUtil.cpp index 73d695195cab5b1d5257c1b783e0c3a5dfe05840..b3620cedfb120bc25304f2d3c53cbac117b9adac 100644 --- a/source/libs/planner/test/planTestUtil.cpp +++ b/source/libs/planner/test/planTestUtil.cpp @@ -466,8 +466,13 @@ class PlannerTestBaseImpl { char* pStr = NULL; int32_t len = 0; DO_WITH_THROW(nodesNodeToString, pRoot, false, &pStr, &len) + // check toObject + SNode* pCopy = NULL; + DO_WITH_THROW(nodesStringToNode, pStr, &pCopy) + nodesDestroyNode(pCopy); string str(pStr); taosMemoryFreeClear(pStr); + return str; } diff --git a/source/libs/qcom/src/queryUtil.c b/source/libs/qcom/src/queryUtil.c index 23f177ffe273a0e7db6f44bc17cecfff1a1ca67c..cf064881c27659c9fbcc048329d91049ca6d4bee 100644 --- a/source/libs/qcom/src/queryUtil.c +++ b/source/libs/qcom/src/queryUtil.c @@ -202,6 +202,7 @@ char* jobTaskStatusStr(int32_t status) { return "UNKNOWN"; } +#if 0 SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* name) { SSchema s = {0}; s.type = type; @@ -211,6 +212,7 @@ SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* nam tstrncpy(s.name, name, tListLen(s.name)); return s; } +#endif void freeSTableMetaRspPointer(void *p) { tFreeSTableMetaRsp(*(void**)p); @@ -454,6 +456,7 @@ int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst) { (*pDst)->vgHash = taosHashInit(taosHashGetSize(pSrc->vgHash), taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); if (NULL == (*pDst)->vgHash) { + taosMemoryFreeClear(*pDst); return TSDB_CODE_TSC_OUT_OF_MEMORY; } diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index 953abd595695a3616e3cf89fa89994f3306283d0..181abc2247be09dd9d2f0a66b4782c674a2264be 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -306,6 +306,15 @@ int32_t queryProcessUseDBRsp(void *output, char *msg, int32_t msgSize) { goto PROCESS_USEDB_OVER; } + qTrace("db:%s, usedbRsp received, numOfVgroups:%d", usedbRsp.db, usedbRsp.vgNum); + for (int32_t i = 0; i < usedbRsp.vgNum; ++i) { + SVgroupInfo *pInfo = taosArrayGet(usedbRsp.pVgroupInfos, i); + qTrace("vgId:%d, numOfEps:%d inUse:%d ", pInfo->vgId, pInfo->epSet.numOfEps, pInfo->epSet.inUse); + for (int32_t j = 0; j < pInfo->epSet.numOfEps; ++j) { + qTrace("vgId:%d, index:%d epset:%s:%u", pInfo->vgId, j, pInfo->epSet.eps[j].fqdn, pInfo->epSet.eps[j].port); + } + } + code = queryBuildUseDbOutput(pOut, &usedbRsp); PROCESS_USEDB_OVER: diff --git a/source/libs/qworker/src/qwDbg.c b/source/libs/qworker/src/qwDbg.c index 6997bdfd9c937d19698e65f461b0f23472d9e359..18713162601660c28e037d2bf57d00980b110017 100644 --- a/source/libs/qworker/src/qwDbg.c +++ b/source/libs/qworker/src/qwDbg.c @@ -253,7 +253,7 @@ int32_t qwDbgEnableDebug(char *option) { } if (0 == strcasecmp(option, "dead")) { - gQWDebug.sleepSimulate = true; + gQWDebug.deadSimulate = true; qError("qw dead debug enabled"); return TSDB_CODE_SUCCESS; } diff --git a/source/libs/qworker/src/qwMsg.c b/source/libs/qworker/src/qwMsg.c index 24ab45be2c156210989800cba01cea9300b36aae..7e7f71b1764f79f6c6b52a77d8e981d285f12add 100644 --- a/source/libs/qworker/src/qwMsg.c +++ b/source/libs/qworker/src/qwMsg.c @@ -8,6 +8,7 @@ #include "tcommon.h" #include "tmsg.h" #include "tname.h" +#include "tgrant.h" int32_t qwMallocFetchRsp(int8_t rpcMalloc, int32_t length, SRetrieveTableRsp **rsp) { int32_t msgSize = sizeof(SRetrieveTableRsp) + length; @@ -146,6 +147,7 @@ int32_t qwBuildAndSendFetchRsp(int32_t rspType, SRpcHandleInfo *pConn, SRetrieve return TSDB_CODE_SUCCESS; } +#if 0 int32_t qwBuildAndSendCancelRsp(SRpcHandleInfo *pConn, int32_t code) { STaskCancelRsp *pRsp = (STaskCancelRsp *)rpcMallocCont(sizeof(STaskCancelRsp)); pRsp->code = code; @@ -177,6 +179,7 @@ int32_t qwBuildAndSendDropRsp(SRpcHandleInfo *pConn, int32_t code) { tmsgSendRsp(&rpcRsp); return TSDB_CODE_SUCCESS; } +#endif int32_t qwBuildAndSendDropMsg(QW_FPARAMS_DEF, SRpcHandleInfo *pConn) { STaskDropReq *req = (STaskDropReq *)rpcMallocCont(sizeof(STaskDropReq)); @@ -303,7 +306,7 @@ int32_t qwRegisterHbBrokenLinkArg(SQWorker *mgmt, uint64_t sId, SRpcHandleInfo * return TSDB_CODE_SUCCESS; } -int32_t qWorkerPreprocessQueryMsg(void *qWorkerMgmt, SRpcMsg *pMsg) { +int32_t qWorkerPreprocessQueryMsg(void *qWorkerMgmt, SRpcMsg *pMsg, bool chkGrant) { if (NULL == qWorkerMgmt || NULL == pMsg) { QW_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); } @@ -324,6 +327,12 @@ int32_t qWorkerPreprocessQueryMsg(void *qWorkerMgmt, SRpcMsg *pMsg) { msg->execId = ntohl(msg->execId); msg->phyLen = ntohl(msg->phyLen); msg->sqlLen = ntohl(msg->sqlLen); + msg->msgMask = ntohl(msg->msgMask); + + if (chkGrant && (!TEST_SHOW_REWRITE_MASK(msg->msgMask)) && (grantCheck(TSDB_GRANT_TIME) != TSDB_CODE_SUCCESS)) { + QW_ELOG("query failed cause of grant expired, msgMask:%d", msg->msgMask); + QW_ERR_RET(TSDB_CODE_GRANT_EXPIRED); + } uint64_t sId = msg->sId; uint64_t qId = msg->queryId; @@ -490,6 +499,7 @@ int32_t qWorkerProcessRspMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int64 return TSDB_CODE_SUCCESS; } +#if 0 int32_t qWorkerProcessCancelMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int64_t ts) { if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) { return TSDB_CODE_QRY_INVALID_INPUT; @@ -530,6 +540,7 @@ _return: return TSDB_CODE_SUCCESS; } +#endif int32_t qWorkerProcessDropMsg(void *node, void *qWorkerMgmt, SRpcMsg *pMsg, int64_t ts) { if (NULL == node || NULL == qWorkerMgmt || NULL == pMsg) { diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index 001a1972a02b33cf1a076bca7c1ca31bf57a75c1..a7cd3db82432f9e148ba02bfcc4e5faa02f8b119 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -644,11 +644,13 @@ _return: input.msgType = qwMsg->msgType; code = qwHandlePostPhaseEvents(QW_FPARAMS(), QW_PHASE_POST_QUERY, &input, NULL); - if (ctx != NULL && QW_EVENT_RECEIVED(ctx, QW_EVENT_FETCH)) { + if (QUERY_RSP_POLICY_QUICK == tsQueryRspPolicy && ctx != NULL && QW_EVENT_RECEIVED(ctx, QW_EVENT_FETCH)) { void *rsp = NULL; int32_t dataLen = 0; SOutputData sOutput = {0}; - QW_ERR_JRET(qwGetQueryResFromSink(QW_FPARAMS(), ctx, &dataLen, &rsp, &sOutput)); + if (qwGetQueryResFromSink(QW_FPARAMS(), ctx, &dataLen, &rsp, &sOutput)) { + return TSDB_CODE_SUCCESS; + } if (rsp) { bool qComplete = (DS_BUF_EMPTY == sOutput.bufStatus && sOutput.queryEnd); diff --git a/source/libs/qworker/test/qworkerTests.cpp b/source/libs/qworker/test/qworkerTests.cpp index c855f005e779e9871ccb7216130bb23b90f8772e..6078a2a3ac44b226e722c253521031afc0fb4eda 100644 --- a/source/libs/qworker/test/qworkerTests.cpp +++ b/source/libs/qworker/test/qworkerTests.cpp @@ -796,7 +796,7 @@ void *fetchQueueThread(void *param) { qWorkerProcessFetchMsg(mockPointer, mgmt, fetchRpc, 0); break; case TDMT_SCH_CANCEL_TASK: - qWorkerProcessCancelMsg(mockPointer, mgmt, fetchRpc, 0); + //qWorkerProcessCancelMsg(mockPointer, mgmt, fetchRpc, 0); break; case TDMT_SCH_DROP_TASK: qWorkerProcessDropMsg(mockPointer, mgmt, fetchRpc, 0); diff --git a/source/libs/scalar/CMakeLists.txt b/source/libs/scalar/CMakeLists.txt index c34c5e2877951cd6ba4d3b6ae72b321bd9dc6231..193a6971e54b52b1c59749c0b41eefe6b9bbb2fb 100644 --- a/source/libs/scalar/CMakeLists.txt +++ b/source/libs/scalar/CMakeLists.txt @@ -14,7 +14,6 @@ target_link_libraries(scalar PRIVATE nodes PRIVATE function PRIVATE qcom - PRIVATE vnode ) if(${BUILD_TEST}) diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 426274a20fbf0a2c5cc1393f341b72f9ca57fff3..df9a818fee5bc79fe324b35c92ec306acfe110fa 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -912,8 +912,8 @@ int32_t filterDetachCnfGroups(SArray *group, SArray *left, SArray *right) { if (taosArrayGetSize(left) <= 0) { if (taosArrayGetSize(right) <= 0) { - fltError("both groups are empty"); - FLT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + fltDebug("both groups are empty"); + return TSDB_CODE_SUCCESS; } SFilterGroup *gp = NULL; @@ -1087,7 +1087,7 @@ int32_t filterAddUnitImpl(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, if (tmp == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } - info->units = tmp; + info->units = (SFilterUnit*)tmp; memset(info->units + psize, 0, sizeof(*info->units) * FILTER_DEFAULT_UNIT_SIZE); } @@ -1169,7 +1169,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode *tree, SArray *group) { SScalarParam out = {.columnData = taosMemoryCalloc(1, sizeof(SColumnInfoData))}; out.columnData->info.type = type; - out.columnData->info.bytes = tDataTypes[type].bytes; + out.columnData->info.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes; //reserved space for simple_copy for (int32_t i = 0; i < listNode->pNodeList->length; ++i) { SValueNode *valueNode = (SValueNode *)cell->pNode; @@ -1191,7 +1191,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode *tree, SArray *group) { filterAddField(info, NULL, (void **)&out.columnData->pData, FLD_TYPE_VALUE, &right, len, true); out.columnData->pData = NULL; } else { - void *data = taosMemoryCalloc(1, tDataTypes[type].bytes); + void *data = taosMemoryCalloc(1, tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes); //reserved space for simple_copy if (NULL == data) { FLT_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); } @@ -1633,12 +1633,12 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options) SValueNode *var = (SValueNode *)field->desc; SDataType *dType = &var->node.resType; - if (dType->type == TSDB_DATA_TYPE_VALUE_ARRAY) { - qDebug("VAL%d => [type:TS][val:[%" PRIi64 "] - [%" PRId64 "]]", i, *(int64_t *)field->data, - *(((int64_t *)field->data) + 1)); - } else { + //if (dType->type == TSDB_DATA_TYPE_VALUE_ARRAY) { + // qDebug("VAL%d => [type:TS][val:[%" PRIi64 "] - [%" PRId64 "]]", i, *(int64_t *)field->data, + // *(((int64_t *)field->data) + 1)); + //} else { qDebug("VAL%d => [type:%d][val:%" PRIx64 "]", i, dType->type, var->datum.i); // TODO - } + //} } else if (field->data) { qDebug("VAL%d => [type:NIL][val:NIL]", i); // TODO } @@ -3994,9 +3994,12 @@ int32_t filterSetDataFromColId(SFilterInfo *info, void *param) { } int32_t filterInitFromNode(SNode *pNode, SFilterInfo **pInfo, uint32_t options) { - int32_t code = 0; SFilterInfo *info = NULL; + if (pNode == NULL) { + return TSDB_CODE_SUCCESS; + } + int32_t code = 0; if (pNode == NULL || pInfo == NULL) { fltError("invalid param"); FLT_ERR_RET(TSDB_CODE_QRY_APP_ERROR); @@ -4034,9 +4037,7 @@ int32_t filterInitFromNode(SNode *pNode, SFilterInfo **pInfo, uint32_t options) _return: filterFreeInfo(*pInfo); - *pInfo = NULL; - FLT_RET(code); } @@ -4059,11 +4060,13 @@ bool filterExecute(SFilterInfo *info, SSDataBlock *pSrc, SColumnInfoData **p, SC SArray *pList = taosArrayInit(1, POINTER_BYTES); taosArrayPush(pList, &pSrc); - FLT_ERR_RET(scalarCalculate(info->sclCtx.node, pList, &output)); - *p = output.columnData; - + int32_t code = scalarCalculate(info->sclCtx.node, pList, &output); taosArrayDestroy(pList); + FLT_ERR_RET(code); + + *p = output.columnData; + if (output.numOfQualified == output.numOfRows) { *pResultStatus = FILTER_RESULT_ALL_QUALIFIED; } else if (output.numOfQualified == 0) { diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index 70d1bb2685024e31f2c561846154d05fdac76d74..fa71009365019014e8cacf70c66010bb5a5fa0c5 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -49,7 +49,7 @@ int32_t sclCreateColumnInfoData(SDataType *pType, int32_t numOfRows, SScalarPara pColumnData->info.scale = pType->scale; pColumnData->info.precision = pType->precision; - int32_t code = colInfoDataEnsureCapacity(pColumnData, numOfRows); + int32_t code = colInfoDataEnsureCapacity(pColumnData, numOfRows, true); if (code != TSDB_CODE_SUCCESS) { terrno = TSDB_CODE_OUT_OF_MEMORY; taosMemoryFree(pColumnData); @@ -70,7 +70,7 @@ int32_t sclConvertValueToSclParam(SValueNode* pValueNode, SScalarParam* out, int colDataAppend(in.columnData, 0, nodesGetValueFromNode(pValueNode), false); - colInfoDataEnsureCapacity(out->columnData, 1); + colInfoDataEnsureCapacity(out->columnData, 1, true); code = vectorConvertSingleColImpl(&in, out, overflow, -1, -1); sclFreeParam(&in); @@ -88,7 +88,7 @@ int32_t sclExtendResRows(SScalarParam *pDst, SScalarParam *pSrc, SArray *pBlockL pLeft->numOfRows = pb->info.rows; if (pDst->numOfRows < pb->info.rows) { - colInfoDataEnsureCapacity(pDst->columnData, pb->info.rows); + colInfoDataEnsureCapacity(pDst->columnData, pb->info.rows, true); } _bin_scalar_fn_t OperatorFn = getBinScalarOperatorFn(OP_TYPE_ASSIGN); @@ -896,6 +896,10 @@ int32_t sclExecCaseWhen(SCaseWhenNode *node, SScalarCtx *ctx, SScalarParam *outp SCL_ERR_JRET(sclGetNodeRes(pWhenThen->pWhen, ctx, &pWhen)); SCL_ERR_JRET(sclGetNodeRes(pWhenThen->pThen, ctx, &pThen)); + if (NULL == pWhen || NULL == pThen) { + sclError("invalid when/then in whenThen list"); + SCL_ERR_JRET(TSDB_CODE_INVALID_PARA); + } if (pCase) { vectorCompare(pCase, pWhen, &comp, TSDB_ORDER_ASC, OP_TYPE_EQUAL); @@ -1600,7 +1604,7 @@ int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) { if (1 == res->numOfRows) { SCL_ERR_JRET(sclExtendResRows(pDst, res, pBlockList)); } else { - colInfoDataEnsureCapacity(pDst->columnData, res->numOfRows); + colInfoDataEnsureCapacity(pDst->columnData, res->numOfRows, true); colDataAssign(pDst->columnData, res->columnData, res->numOfRows, NULL); pDst->numOfRows = res->numOfRows; pDst->numOfQualified = res->numOfQualified; diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 7e93c9173c0d21edca583c40caab11a30f5c146f..22fa99d75d3229aba0f97d92c280b938f068875f 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -6,7 +6,6 @@ #include "tdatablock.h" #include "tjson.h" #include "ttime.h" -#include "vnode.h" typedef float (*_float_fn)(float); typedef double (*_double_fn)(double); @@ -1029,11 +1028,11 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam * int32_t type = GET_PARAM_TYPE(pInput); bool tzPresent = (inputNum == 2) ? true : false; - char *tz; - int32_t tzLen; + char tz[20] = {0}; + int32_t tzLen = 0; if (tzPresent) { - tz = varDataVal(pInput[1].columnData->pData); tzLen = varDataLen(pInput[1].columnData->pData); + memcpy(tz, varDataVal(pInput[1].columnData->pData), tzLen); } for (int32_t i = 0; i < pInput[0].numOfRows; ++i) { @@ -1072,8 +1071,10 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam * int32_t len = (int32_t)strlen(buf); // add timezone string - snprintf(buf + len, tzLen + 1, "%s", tz); - len += tzLen; + if (tzLen > 0) { + snprintf(buf + len, tzLen + 1, "%s", tz); + len += tzLen; + } if (hasFraction) { int32_t fracLen = (int32_t)strlen(fraction) + 1; @@ -1718,12 +1719,9 @@ int32_t winEndTsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p int32_t qTbnameFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) { ASSERT(inputNum == 1); + char* p = colDataGetVarData(pInput->columnData, 0); - uint64_t uid = *(uint64_t *)colDataGetData(pInput->columnData, 0); - - char str[TSDB_TABLE_FNAME_LEN + VARSTR_HEADER_SIZE] = {0}; - metaGetTableNameByUid(pInput->param, uid, str); - colDataAppendNItems(pOutput->columnData, pOutput->numOfRows, str, pInput->numOfRows); + colDataAppendNItems(pOutput->columnData, pOutput->numOfRows, p, pInput->numOfRows); pOutput->numOfRows += pInput->numOfRows; return TSDB_CODE_SUCCESS; } diff --git a/source/libs/scalar/test/scalar/scalarTests.cpp b/source/libs/scalar/test/scalar/scalarTests.cpp index 39055b534d937ca74ecde5d017710534112fc91a..0fd0c98c1ab23b6457683dec02147c5637523af1 100644 --- a/source/libs/scalar/test/scalar/scalarTests.cpp +++ b/source/libs/scalar/test/scalar/scalarTests.cpp @@ -87,7 +87,7 @@ void scltAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *s SColumnInfoData idata = {0}; idata.info = *colInfo; - colInfoDataEnsureCapacity(&idata, rows); + colInfoDataEnsureCapacity(&idata, rows, true); blockDataAppendColInfo(res, &idata); @@ -104,7 +104,7 @@ void scltAppendReservedSlot(SArray *pBlockList, int16_t *dataBlockId, int16_t *s SSDataBlock *res = *(SSDataBlock **)taosArrayGetLast(pBlockList); SColumnInfoData idata = {0}; idata.info = *colInfo; - colInfoDataEnsureCapacity(&idata, rows); + colInfoDataEnsureCapacity(&idata, rows, true); blockDataAppendColInfo(res, &idata); *dataBlockId = taosArrayGetSize(pBlockList) - 1; @@ -146,12 +146,12 @@ void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in SSDataBlock *res = createDataBlock(); for (int32_t i = 0; i < 2; ++i) { SColumnInfoData idata = createColumnInfoData(TSDB_DATA_TYPE_INT, 10, i + 1); - colInfoDataEnsureCapacity(&idata, rowNum); + colInfoDataEnsureCapacity(&idata, rowNum, true); blockDataAppendColInfo(res, &idata); } SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 3); - colInfoDataEnsureCapacity(&idata, rowNum); + colInfoDataEnsureCapacity(&idata, rowNum, true); blockDataAppendColInfo(res, &idata); res->info.capacity = rowNum; @@ -175,7 +175,7 @@ void scltMakeColumnNode(SNode **pNode, SSDataBlock **block, int32_t dataType, in int32_t idx = taosArrayGetSize(res->pDataBlock); SColumnInfoData idata = createColumnInfoData(dataType, dataBytes, 1 + idx); - colInfoDataEnsureCapacity(&idata, rowNum); + colInfoDataEnsureCapacity(&idata, rowNum, true); res->info.capacity = rowNum; blockDataAppendColInfo(res, &idata); @@ -2022,7 +2022,7 @@ void scltMakeDataBlock(SScalarParam **pInput, int32_t type, void *pVal, int32_t input->numOfRows = num; input->columnData->info = createColumnInfo(0, type, bytes); - colInfoDataEnsureCapacity(input->columnData, num); + colInfoDataEnsureCapacity(input->columnData, num, true); if (setVal) { for (int32_t i = 0; i < num; ++i) { diff --git a/source/libs/scheduler/src/schRemote.c b/source/libs/scheduler/src/schRemote.c index d1d0680e651f6f1c5d1d745df2a4272bb7da839b..801f38bd1a265dbf6359d8d053dcab716da1d1d8 100644 --- a/source/libs/scheduler/src/schRemote.c +++ b/source/libs/scheduler/src/schRemote.c @@ -185,12 +185,12 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa code = rsp->code; } } - SCH_UNLOCK(SCH_WRITE, &pJob->resLock); if (taosArrayGetSize((SArray*)pJob->execRes.res) <= 0) { taosArrayDestroy((SArray*)pJob->execRes.res); pJob->execRes.res = NULL; } + SCH_UNLOCK(SCH_WRITE, &pJob->resLock); } tDecoderClear(&coder); @@ -280,7 +280,7 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t execId, SDa } atomic_add_fetch_32(&pJob->resNumOfRows, rsp->affectedRows); - SCH_TASK_DLOG("submit succeed, affectedRows:%d", rsp->affectedRows); + SCH_TASK_DLOG("submit succeed, affectedRows:%d, blocks:%d", rsp->affectedRows, rsp->nBlocks); SCH_LOCK(SCH_WRITE, &pJob->resLock); if (pJob->execRes.res) { @@ -1057,6 +1057,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, pMsg->needFetch = SCH_TASK_NEED_FETCH(pTask); pMsg->phyLen = htonl(pTask->msgLen); pMsg->sqlLen = htonl(len); + pMsg->msgMask = htonl((pTask->plan->showRewrite) ? QUERY_MSG_MASK_SHOW_REWRITE() : 0); memcpy(pMsg->msg, pJob->sql, len); memcpy(pMsg->msg + len, pTask->msg, pTask->msgLen); @@ -1156,6 +1157,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, SCH_ERR_RET(schAppendTaskExecNode(pJob, pTask, addr, pTask->execId)); } } else { + taosMemoryFree(msg); SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask)); } #endif diff --git a/source/libs/scheduler/src/schTask.c b/source/libs/scheduler/src/schTask.c index de6063fbbc06cc60bf2528a4e18f67e0a4dda67d..dbdccff302df58fb09e5149f17c39600a2feec7c 100644 --- a/source/libs/scheduler/src/schTask.c +++ b/source/libs/scheduler/src/schTask.c @@ -915,7 +915,7 @@ int32_t schLaunchRemoteTask(SSchJob *pJob, SSchTask *pTask) { SCH_ERR_RET(schSetTaskCandidateAddrs(pJob, pTask)); if (SCH_IS_QUERY_JOB(pJob)) { -// SCH_ERR_RET(schEnsureHbConnection(pJob, pTask)); + SCH_ERR_RET(schEnsureHbConnection(pJob, pTask)); } SCH_RET(schBuildAndSendMsg(pJob, pTask, NULL, plan->msgType)); diff --git a/source/libs/scheduler/src/schUtil.c b/source/libs/scheduler/src/schUtil.c index e20ed9d58e329967016dd0d05e13073c1cb5ea44..1f1288fcfd79613ecc855dd9e0ab4b5592d817d5 100644 --- a/source/libs/scheduler/src/schUtil.c +++ b/source/libs/scheduler/src/schUtil.c @@ -17,6 +17,7 @@ #include "command.h" #include "query.h" #include "schInt.h" +#include "tglobal.h" #include "tmsg.h" #include "tref.h" #include "trpc.h" @@ -184,6 +185,10 @@ void schDeregisterTaskHb(SSchJob *pJob, SSchTask *pTask) { } int32_t schEnsureHbConnection(SSchJob *pJob, SSchTask *pTask) { + if (!tsEnableQueryHb) { + return TSDB_CODE_SUCCESS; + } + SQueryNodeAddr *addr = taosArrayGet(pTask->candidateAddrs, pTask->candidateIdx); SQueryNodeEpId epId = {0}; diff --git a/source/libs/stream/inc/streamInc.h b/source/libs/stream/inc/streamInc.h index e9d4fbeaaa80c1e5f73f201698412a1b682e9204..0fc75c4798c2e24f92893a763077dea373ccade1 100644 --- a/source/libs/stream/inc/streamInc.h +++ b/source/libs/stream/inc/streamInc.h @@ -32,8 +32,6 @@ typedef struct { static SStreamGlobalEnv streamEnv; -// int32_t streamPipelineExec(SStreamTask* pTask, int32_t batchNum, bool dispatch); - int32_t streamDispatch(SStreamTask* pTask); int32_t streamDispatchReqToData(const SStreamDispatchReq* pReq, SStreamDataBlock* pData); int32_t streamRetrieveReqToData(const SStreamRetrieveReq* pReq, SStreamDataBlock* pData); @@ -43,6 +41,11 @@ int32_t streamBroadcastToChildren(SStreamTask* pTask, const SSDataBlock* pBlock) int32_t tEncodeStreamRetrieveReq(SEncoder* pEncoder, const SStreamRetrieveReq* pReq); +int32_t streamDispatchOneCheckReq(SStreamTask* pTask, const SStreamTaskCheckReq* pReq, int32_t nodeId, SEpSet* pEpSet); + +int32_t streamDispatchOneRecoverFinishReq(SStreamTask* pTask, const SStreamRecoverFinishReq* pReq, int32_t vgId, + SEpSet* pEpSet); + SStreamQueueItem* streamMergeQueueItem(SStreamQueueItem* dst, SStreamQueueItem* elem); void streamFreeQitem(SStreamQueueItem* data); diff --git a/source/libs/stream/src/stream.c b/source/libs/stream/src/stream.c index ee317d0751c90f4f63669a228ce35f640b5bde1b..e6d5859163f56150d4ede3a3903daaf79a3be4f5 100644 --- a/source/libs/stream/src/stream.c +++ b/source/libs/stream/src/stream.c @@ -135,8 +135,11 @@ int32_t streamTaskEnqueue(SStreamTask* pTask, const SStreamDispatchReq* pReq, SR ((SMsgHead*)buf)->vgId = htonl(pReq->upstreamNodeId); SStreamDispatchRsp* pCont = POINTER_SHIFT(buf, sizeof(SMsgHead)); pCont->inputStatus = status; - pCont->streamId = pReq->streamId; - pCont->taskId = pReq->upstreamTaskId; + pCont->streamId = htobe64(pReq->streamId); + pCont->upstreamNodeId = htonl(pReq->upstreamNodeId); + pCont->upstreamTaskId = htonl(pReq->upstreamTaskId); + pCont->downstreamNodeId = htonl(pTask->nodeId); + pCont->downstreamTaskId = htonl(pTask->taskId); pRsp->pCont = buf; pRsp->contLen = sizeof(SMsgHead) + sizeof(SStreamDispatchRsp); tmsgSendRsp(pRsp); @@ -203,10 +206,10 @@ int32_t streamProcessDispatchReq(SStreamTask* pTask, SStreamDispatchReq* pReq, S return 0; } -int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp) { +int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, int32_t code) { ASSERT(pRsp->inputStatus == TASK_OUTPUT_STATUS__NORMAL || pRsp->inputStatus == TASK_OUTPUT_STATUS__BLOCKED); - qDebug("task %d receive dispatch rsp", pTask->taskId); + qDebug("task %d receive dispatch rsp, code: %x", pTask->taskId, code); if (pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) { int32_t leftRsp = atomic_sub_fetch_32(&pTask->shuffleDispatcher.waitingRspCnt, 1); @@ -237,43 +240,6 @@ int32_t streamProcessRunReq(SStreamTask* pTask) { return 0; } -#if 0 -int32_t streamProcessRecoverReq(SStreamTask* pTask, SStreamTaskRecoverReq* pReq, SRpcMsg* pRsp) { - void* buf = rpcMallocCont(sizeof(SMsgHead) + sizeof(SStreamTaskRecoverRsp)); - ((SMsgHead*)buf)->vgId = htonl(pReq->upstreamNodeId); - - SStreamTaskRecoverRsp* pCont = POINTER_SHIFT(buf, sizeof(SMsgHead)); - pCont->inputStatus = pTask->inputStatus; - pCont->streamId = pTask->streamId; - pCont->reqTaskId = pTask->taskId; - pCont->rspTaskId = pReq->upstreamTaskId; - - pRsp->pCont = buf; - pRsp->contLen = sizeof(SMsgHead) + sizeof(SStreamTaskRecoverRsp); - tmsgSendRsp(pRsp); - return 0; -} - -int32_t streamProcessRecoverRsp(SStreamMeta* pMeta, SStreamTask* pTask, SStreamRecoverDownstreamRsp* pRsp) { - streamProcessRunReq(pTask); - - if (pTask->taskLevel == TASK_LEVEL__SOURCE) { - // scan data to recover - pTask->inputStatus = TASK_INPUT_STATUS__RECOVER; - pTask->taskStatus = TASK_STATUS__RECOVER_SELF; - qStreamPrepareRecover(pTask->exec.executor, pTask->startVer, pTask->recoverSnapVer); - if (streamPipelineExec(pTask, 100, true) < 0) { - return -1; - } - } else { - pTask->inputStatus = TASK_INPUT_STATUS__NORMAL; - pTask->taskStatus = TASK_STATUS__NORMAL; - } - - return 0; -} -#endif - int32_t streamProcessRetrieveReq(SStreamTask* pTask, SStreamRetrieveReq* pReq, SRpcMsg* pRsp) { qDebug("task %d receive retrieve req from node %d task %d", pTask->taskId, pReq->srcNodeId, pReq->srcTaskId); diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index 417ddfa80dbd5130d011f63533ac3d5bd4ed4da3..573a1ea31f10f4b04b87dc387a4c4ebe101ed4b8 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -118,8 +118,7 @@ int32_t streamBroadcastToChildren(SStreamTask* pTask, const SSDataBlock* pBlock) pRetrieve->ekey = htobe64(pBlock->info.window.ekey); pRetrieve->version = htobe64(pBlock->info.version); - int32_t actualLen = 0; - blockEncode(pBlock, pRetrieve->data, &actualLen, numOfCols, false); + int32_t actualLen = blockEncode(pBlock, pRetrieve->data, numOfCols); SStreamRetrieveReq req = { .streamId = pTask->streamId, @@ -200,8 +199,7 @@ static int32_t streamAddBlockToDispatchMsg(const SSDataBlock* pBlock, SStreamDis int32_t numOfCols = (int32_t)taosArrayGetSize(pBlock->pDataBlock); pRetrieve->numOfCols = htonl(numOfCols); - int32_t actualLen = 0; - blockEncode(pBlock, pRetrieve->data, &actualLen, numOfCols, false); + int32_t actualLen = blockEncode(pBlock, pRetrieve->data, numOfCols); actualLen += sizeof(SRetrieveTableRsp); ASSERT(actualLen <= dataStrLen); taosArrayPush(pReq->dataLen, &actualLen); @@ -210,6 +208,46 @@ static int32_t streamAddBlockToDispatchMsg(const SSDataBlock* pBlock, SStreamDis return 0; } +int32_t streamDispatchOneCheckReq(SStreamTask* pTask, const SStreamTaskCheckReq* pReq, int32_t nodeId, SEpSet* pEpSet) { + void* buf = NULL; + int32_t code = -1; + SRpcMsg msg = {0}; + + int32_t tlen; + tEncodeSize(tEncodeSStreamTaskCheckReq, pReq, tlen, code); + if (code < 0) { + return -1; + } + + buf = rpcMallocCont(sizeof(SMsgHead) + tlen); + if (buf == NULL) { + return -1; + } + + ((SMsgHead*)buf)->vgId = htonl(nodeId); + void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); + + SEncoder encoder; + tEncoderInit(&encoder, abuf, tlen); + if ((code = tEncodeSStreamTaskCheckReq(&encoder, pReq)) < 0) { + goto FAIL; + } + tEncoderClear(&encoder); + + msg.contLen = tlen + sizeof(SMsgHead); + msg.pCont = buf; + msg.msgType = TDMT_STREAM_TASK_CHECK; + + qDebug("dispatch from task %d to task %d node %d: check msg", pTask->taskId, pReq->downstreamTaskId, nodeId); + + tmsgSendReq(pEpSet, &msg); + + return 0; +FAIL: + if (buf) rpcFreeCont(buf); + return code; +} + int32_t streamDispatchOneRecoverFinishReq(SStreamTask* pTask, const SStreamRecoverFinishReq* pReq, int32_t vgId, SEpSet* pEpSet) { void* buf = NULL; @@ -239,18 +277,19 @@ int32_t streamDispatchOneRecoverFinishReq(SStreamTask* pTask, const SStreamRecov msg.contLen = tlen + sizeof(SMsgHead); msg.pCont = buf; - msg.msgType = TDMT_VND_STREAM_RECOVER_FINISH; + msg.msgType = TDMT_STREAM_RECOVER_FINISH; tmsgSendReq(pEpSet, &msg); - code = 0; + qDebug("dispatch from task %d to task %d node %d: recover finish msg", pTask->taskId, pReq->taskId, vgId); + return 0; FAIL: if (buf) rpcFreeCont(buf); return code; } -int32_t streamDispatchOneReq(SStreamTask* pTask, const SStreamDispatchReq* pReq, int32_t vgId, SEpSet* pEpSet) { +int32_t streamDispatchOneDataReq(SStreamTask* pTask, const SStreamDispatchReq* pReq, int32_t vgId, SEpSet* pEpSet) { void* buf = NULL; int32_t code = -1; SRpcMsg msg = {0}; @@ -279,7 +318,7 @@ int32_t streamDispatchOneReq(SStreamTask* pTask, const SStreamDispatchReq* pReq, msg.pCont = buf; msg.msgType = pTask->dispatchMsgType; - qDebug("dispatch from task %d to task %d node %d", pTask->taskId, pReq->taskId, vgId); + qDebug("dispatch from task %d to task %d node %d: data msg", pTask->taskId, pReq->taskId, vgId); tmsgSendReq(pEpSet, &msg); @@ -292,13 +331,19 @@ FAIL: int32_t streamSearchAndAddBlock(SStreamTask* pTask, SStreamDispatchReq* pReqs, SSDataBlock* pDataBlock, int32_t vgSz, int64_t groupId) { - char* ctbName; + char* ctbName = taosMemoryCalloc(1, TSDB_TABLE_FNAME_LEN); + if (ctbName == NULL) { + return -1; + } + if (pDataBlock->info.parTbName[0]) { - ctbName = taosMemoryCalloc(1, TSDB_TABLE_NAME_LEN); snprintf(ctbName, TSDB_TABLE_NAME_LEN, "%s.%s", pTask->shuffleDispatcher.dbInfo.db, pDataBlock->info.parTbName); } else { - ctbName = buildCtbNameByGroupId(pTask->shuffleDispatcher.stbFullName, groupId); + char* ctbShortName = buildCtbNameByGroupId(pTask->shuffleDispatcher.stbFullName, groupId); + snprintf(ctbName, TSDB_TABLE_NAME_LEN, "%s.%s", pTask->shuffleDispatcher.dbInfo.db, ctbShortName); + taosMemoryFree(ctbShortName); } + SArray* vgInfo = pTask->shuffleDispatcher.dbInfo.pVgroupInfos; /*uint32_t hashValue = MurmurHash3_32(ctbName, strlen(ctbName));*/ @@ -365,7 +410,7 @@ int32_t streamDispatchAllBlocks(SStreamTask* pTask, const SStreamDataBlock* pDat qDebug("dispatch from task %d (child id %d) to down stream task %d in vnode %d", pTask->taskId, pTask->selfChildId, downstreamTaskId, vgId); - if (streamDispatchOneReq(pTask, &req, vgId, pEpSet) < 0) { + if (streamDispatchOneDataReq(pTask, &req, vgId, pEpSet) < 0) { goto FAIL_FIXED_DISPATCH; } code = 0; @@ -427,7 +472,7 @@ int32_t streamDispatchAllBlocks(SStreamTask* pTask, const SStreamDataBlock* pDat if (pReqs[i].blockNum > 0) { // send SVgroupInfo* pVgInfo = taosArrayGet(vgInfo, i); - if (streamDispatchOneReq(pTask, &pReqs[i], pVgInfo->vgId, &pVgInfo->epSet) < 0) { + if (streamDispatchOneDataReq(pTask, &pReqs[i], pVgInfo->vgId, &pVgInfo->epSet) < 0) { goto FAIL_SHUFFLE_DISPATCH; } } diff --git a/source/libs/stream/src/streamExec.c b/source/libs/stream/src/streamExec.c index 6e37810004305d7ccb00f3a01c1dd5af8d119b01..e7f2b60704b7c6d17af8390b6d724fed77dbbd44 100644 --- a/source/libs/stream/src/streamExec.c +++ b/source/libs/stream/src/streamExec.c @@ -90,6 +90,8 @@ int32_t streamScanExec(SStreamTask* pTask, int32_t batchSz) { void* exec = pTask->exec.executor; + qSetStreamOpOpen(exec); + while (1) { SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock)); if (pRes == NULL) { @@ -127,69 +129,48 @@ int32_t streamScanExec(SStreamTask* pTask, int32_t batchSz) { qRes->type = STREAM_INPUT__DATA_BLOCK; qRes->blocks = pRes; streamTaskOutput(pTask, qRes); - // TODO stream sched dispatch + + if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH || pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) { + streamDispatch(pTask); + } } return 0; } #if 0 -int32_t streamPipelineExec(SStreamTask* pTask, int32_t batchNum, bool dispatch) { - ASSERT(pTask->taskLevel != TASK_LEVEL__SINK); - - void* exec = pTask->exec.executor; - - while (1) { - SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock)); - if (pRes == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - int32_t batchCnt = 0; - while (1) { - SSDataBlock* output = NULL; - uint64_t ts = 0; - if (qExecTask(exec, &output, &ts) < 0) { - ASSERT(0); - } - if (output == NULL) break; - - SSDataBlock block = {0}; - assignOneDataBlock(&block, output); - block.info.childId = pTask->selfChildId; - taosArrayPush(pRes, &block); - - if (++batchCnt >= batchNum) break; - } - if (taosArrayGetSize(pRes) == 0) { - taosArrayDestroy(pRes); - break; +int32_t streamBatchExec(SStreamTask* pTask, int32_t batchLimit) { + // fetch all queue item, merge according to batchLimit + int32_t numOfItems = taosReadAllQitems(pTask->inputQueue1, pTask->inputQall); + if (numOfItems == 0) { + qDebug("task: %d, stream task exec over, queue empty", pTask->taskId); + return 0; + } + SStreamQueueItem* pMerged = NULL; + SStreamQueueItem* pItem = NULL; + taosGetQitem(pTask->inputQall, (void**)&pItem); + if (pItem == NULL) { + if (pMerged != NULL) { + // process merged item + } else { + return 0; } - if (dispatch) { - SStreamDataBlock* qRes = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM); - if (qRes == NULL) { - taosArrayDestroyEx(pRes, (FDelete)blockDataFreeRes); - return -1; - } - - qRes->type = STREAM_INPUT__DATA_BLOCK; - qRes->blocks = pRes; - qRes->childId = pTask->selfChildId; + } - if (streamTaskOutput(pTask, qRes) < 0) { - taosArrayDestroyEx(pRes, (FDelete)blockDataFreeRes); - taosFreeQitem(qRes); - return -1; - } + // if drop + if (pItem->type == STREAM_INPUT__DESTROY) { + // set status drop + return -1; + } - if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH || pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) { - streamDispatch(pTask); - } - } else { - taosArrayDestroyEx(pRes, (FDelete)blockDataFreeRes); - } + if (pTask->taskLevel == TASK_LEVEL__SINK) { + ASSERT(((SStreamQueueItem*)pItem)->type == STREAM_INPUT__DATA_BLOCK); + streamTaskOutput(pTask, (SStreamDataBlock*)pItem); } + // exec impl + + // output + // try dispatch return 0; } #endif @@ -197,83 +178,83 @@ int32_t streamPipelineExec(SStreamTask* pTask, int32_t batchNum, bool dispatch) int32_t streamExecForAll(SStreamTask* pTask) { while (1) { int32_t batchCnt = 1; - void* data = NULL; + void* input = NULL; while (1) { SStreamQueueItem* qItem = streamQueueNextItem(pTask->inputQueue); if (qItem == NULL) { qDebug("stream task exec over, queue empty, task: %d", pTask->taskId); break; } - if (data == NULL) { - data = qItem; + if (input == NULL) { + input = qItem; streamQueueProcessSuccess(pTask->inputQueue); if (pTask->taskLevel == TASK_LEVEL__SINK) { break; } } else { void* newRet; - if ((newRet = streamMergeQueueItem(data, qItem)) == NULL) { + if ((newRet = streamMergeQueueItem(input, qItem)) == NULL) { streamQueueProcessFail(pTask->inputQueue); break; } else { batchCnt++; - data = newRet; + input = newRet; streamQueueProcessSuccess(pTask->inputQueue); } } } if (pTask->taskStatus == TASK_STATUS__DROPPING) { - if (data) streamFreeQitem(data); + if (input) streamFreeQitem(input); return 0; } - if (data == NULL) { + if (input == NULL) { break; } if (pTask->taskLevel == TASK_LEVEL__SINK) { - ASSERT(((SStreamQueueItem*)data)->type == STREAM_INPUT__DATA_BLOCK); - streamTaskOutput(pTask, data); + ASSERT(((SStreamQueueItem*)input)->type == STREAM_INPUT__DATA_BLOCK); + streamTaskOutput(pTask, input); continue; } SArray* pRes = taosArrayInit(0, sizeof(SSDataBlock)); qDebug("stream task %d exec begin, msg batch: %d", pTask->taskId, batchCnt); - streamTaskExecImpl(pTask, data, pRes); + streamTaskExecImpl(pTask, input, pRes); qDebug("stream task %d exec end", pTask->taskId); if (taosArrayGetSize(pRes) != 0) { SStreamDataBlock* qRes = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM); if (qRes == NULL) { taosArrayDestroyEx(pRes, (FDelete)blockDataFreeRes); - streamFreeQitem(data); + streamFreeQitem(input); return -1; } qRes->type = STREAM_INPUT__DATA_BLOCK; qRes->blocks = pRes; - if (((SStreamQueueItem*)data)->type == STREAM_INPUT__DATA_SUBMIT) { - SStreamDataSubmit* pSubmit = (SStreamDataSubmit*)data; + if (((SStreamQueueItem*)input)->type == STREAM_INPUT__DATA_SUBMIT) { + SStreamDataSubmit* pSubmit = (SStreamDataSubmit*)input; qRes->childId = pTask->selfChildId; qRes->sourceVer = pSubmit->ver; - } else if (((SStreamQueueItem*)data)->type == STREAM_INPUT__MERGED_SUBMIT) { - SStreamMergedSubmit* pMerged = (SStreamMergedSubmit*)data; + } else if (((SStreamQueueItem*)input)->type == STREAM_INPUT__MERGED_SUBMIT) { + SStreamMergedSubmit* pMerged = (SStreamMergedSubmit*)input; qRes->childId = pTask->selfChildId; qRes->sourceVer = pMerged->ver; } if (streamTaskOutput(pTask, qRes) < 0) { taosArrayDestroyEx(pRes, (FDelete)blockDataFreeRes); - streamFreeQitem(data); + streamFreeQitem(input); taosFreeQitem(qRes); return -1; } } else { taosArrayDestroy(pRes); } - streamFreeQitem(data); + streamFreeQitem(input); } return 0; } diff --git a/source/libs/stream/src/streamMeta.c b/source/libs/stream/src/streamMeta.c index 98e4e77cb015e30cc81043b45b3d6beef18217dd..682bfbaf8d0489409f49962decafbbc71faf5a1f 100644 --- a/source/libs/stream/src/streamMeta.c +++ b/source/libs/stream/src/streamMeta.c @@ -70,6 +70,7 @@ _err: void streamMetaClose(SStreamMeta* pMeta) { tdbCommit(pMeta->db, &pMeta->txn); + tdbPostCommit(pMeta->db, &pMeta->txn); tdbTbClose(pMeta->pTaskDb); tdbTbClose(pMeta->pCheckpointDb); tdbClose(pMeta->db); diff --git a/source/libs/stream/src/streamRecover.c b/source/libs/stream/src/streamRecover.c index 12de2fafc1ef86401f6e86fa0350410055365248..2a2784afea67386ab2b75d8230f107f596f79efd 100644 --- a/source/libs/stream/src/streamRecover.c +++ b/source/libs/stream/src/streamRecover.c @@ -15,6 +15,148 @@ #include "streamInc.h" +int32_t streamTaskLaunchRecover(SStreamTask* pTask, int64_t version) { + qDebug("task %d at node %d launch recover", pTask->taskId, pTask->nodeId); + if (pTask->taskLevel == TASK_LEVEL__SOURCE) { + atomic_store_8(&pTask->taskStatus, TASK_STATUS__RECOVER_PREPARE); + streamSetParamForRecover(pTask); + streamSourceRecoverPrepareStep1(pTask, version); + + SStreamRecoverStep1Req req; + streamBuildSourceRecover1Req(pTask, &req); + int32_t len = sizeof(SStreamRecoverStep1Req); + + void* serializedReq = rpcMallocCont(len); + if (serializedReq == NULL) { + return -1; + } + + memcpy(serializedReq, &req, len); + + SRpcMsg rpcMsg = { + .contLen = len, + .pCont = serializedReq, + .msgType = TDMT_VND_STREAM_RECOVER_STEP1, + }; + + if (tmsgPutToQueue(pTask->pMsgCb, STREAM_QUEUE, &rpcMsg) < 0) { + /*ASSERT(0);*/ + } + + } else if (pTask->taskLevel == TASK_LEVEL__AGG) { + atomic_store_8(&pTask->taskStatus, TASK_STATUS__NORMAL); + streamSetParamForRecover(pTask); + streamAggRecoverPrepare(pTask); + } else if (pTask->taskLevel == TASK_LEVEL__SINK) { + atomic_store_8(&pTask->taskStatus, TASK_STATUS__NORMAL); + } + return 0; +} + +// checkstatus +int32_t streamTaskCheckDownstream(SStreamTask* pTask, int64_t version) { + SStreamTaskCheckReq req = { + .streamId = pTask->streamId, + .upstreamTaskId = pTask->taskId, + .upstreamNodeId = pTask->nodeId, + .childId = pTask->selfChildId, + }; + // serialize + if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH) { + req.reqId = tGenIdPI64(); + req.downstreamNodeId = pTask->fixedEpDispatcher.nodeId; + req.downstreamTaskId = pTask->fixedEpDispatcher.taskId; + pTask->checkReqId = req.reqId; + + qDebug("task %d at node %d check downstream task %d at node %d", pTask->taskId, pTask->nodeId, req.downstreamTaskId, + req.downstreamNodeId); + streamDispatchOneCheckReq(pTask, &req, pTask->fixedEpDispatcher.nodeId, &pTask->fixedEpDispatcher.epSet); + } else if (pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) { + SArray* vgInfo = pTask->shuffleDispatcher.dbInfo.pVgroupInfos; + int32_t vgSz = taosArrayGetSize(vgInfo); + pTask->recoverTryingDownstream = vgSz; + pTask->checkReqIds = taosArrayInit(vgSz, sizeof(int64_t)); + + for (int32_t i = 0; i < vgSz; i++) { + SVgroupInfo* pVgInfo = taosArrayGet(vgInfo, i); + req.reqId = tGenIdPI64(); + taosArrayPush(pTask->checkReqIds, &req.reqId); + req.downstreamNodeId = pVgInfo->vgId; + req.downstreamTaskId = pVgInfo->taskId; + qDebug("task %d at node %d check downstream task %d at node %d (shuffle)", pTask->taskId, pTask->nodeId, + req.downstreamTaskId, req.downstreamNodeId); + streamDispatchOneCheckReq(pTask, &req, pVgInfo->vgId, &pVgInfo->epSet); + } + } else { + qDebug("task %d at node %d direct launch recover since no downstream", pTask->taskId, pTask->nodeId); + streamTaskLaunchRecover(pTask, version); + } + return 0; +} + +int32_t streamRecheckOneDownstream(SStreamTask* pTask, const SStreamTaskCheckRsp* pRsp) { + SStreamTaskCheckReq req = { + .reqId = pRsp->reqId, + .streamId = pRsp->streamId, + .upstreamTaskId = pRsp->upstreamTaskId, + .upstreamNodeId = pRsp->upstreamNodeId, + .downstreamTaskId = pRsp->downstreamTaskId, + .downstreamNodeId = pRsp->downstreamNodeId, + .childId = pRsp->childId, + }; + qDebug("task %d at node %d check downstream task %d at node %d (recheck)", pTask->taskId, pTask->nodeId, + req.downstreamTaskId, req.downstreamNodeId); + if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH) { + streamDispatchOneCheckReq(pTask, &req, pRsp->downstreamNodeId, &pTask->fixedEpDispatcher.epSet); + } else if (pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) { + SArray* vgInfo = pTask->shuffleDispatcher.dbInfo.pVgroupInfos; + int32_t vgSz = taosArrayGetSize(vgInfo); + for (int32_t i = 0; i < vgSz; i++) { + SVgroupInfo* pVgInfo = taosArrayGet(vgInfo, i); + if (pVgInfo->taskId == req.downstreamTaskId) { + streamDispatchOneCheckReq(pTask, &req, pRsp->downstreamNodeId, &pVgInfo->epSet); + } + } + } + return 0; +} + +int32_t streamProcessTaskCheckReq(SStreamTask* pTask, const SStreamTaskCheckReq* pReq) { + return atomic_load_8(&pTask->taskStatus) == TASK_STATUS__NORMAL; +} + +int32_t streamProcessTaskCheckRsp(SStreamTask* pTask, const SStreamTaskCheckRsp* pRsp, int64_t version) { + qDebug("task %d at node %d recv check rsp from task %d at node %d: status %d", pRsp->upstreamTaskId, + pRsp->upstreamNodeId, pRsp->downstreamTaskId, pRsp->downstreamNodeId, pRsp->status); + if (pRsp->status == 1) { + if (pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) { + bool found = false; + for (int32_t i = 0; i < taosArrayGetSize(pTask->checkReqIds); i++) { + int64_t reqId = *(int64_t*)taosArrayGet(pTask->checkReqIds, i); + if (reqId == pRsp->reqId) { + found = true; + break; + } + } + if (!found) return -1; + int32_t left = atomic_sub_fetch_32(&pTask->recoverTryingDownstream, 1); + ASSERT(left >= 0); + if (left == 0) { + taosArrayDestroy(pTask->checkReqIds); + streamTaskLaunchRecover(pTask, version); + } + } else if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH) { + if (pRsp->reqId != pTask->checkReqId) return -1; + streamTaskLaunchRecover(pTask, version); + } else { + ASSERT(0); + } + } else { + streamRecheckOneDownstream(pTask, pRsp); + } + return 0; +} + // common int32_t streamSetParamForRecover(SStreamTask* pTask) { void* exec = pTask->exec.executor; @@ -36,6 +178,7 @@ int32_t streamSourceRecoverPrepareStep1(SStreamTask* pTask, int64_t ver) { } int32_t streamBuildSourceRecover1Req(SStreamTask* pTask, SStreamRecoverStep1Req* pReq) { + pReq->msgHead.vgId = pTask->nodeId; pReq->streamId = pTask->streamId; pReq->taskId = pTask->taskId; return 0; @@ -44,10 +187,10 @@ int32_t streamBuildSourceRecover1Req(SStreamTask* pTask, SStreamRecoverStep1Req* int32_t streamSourceRecoverScanStep1(SStreamTask* pTask) { // return streamScanExec(pTask, 100); - // TODO next: dispatch msg to launch scan step2 } int32_t streamBuildSourceRecover2Req(SStreamTask* pTask, SStreamRecoverStep2Req* pReq) { + pReq->msgHead.vgId = pTask->nodeId; pReq->streamId = pTask->streamId; pReq->taskId = pTask->taskId; return 0; @@ -64,11 +207,20 @@ int32_t streamSourceRecoverScanStep2(SStreamTask* pTask, int64_t ver) { int32_t streamDispatchRecoverFinishReq(SStreamTask* pTask) { SStreamRecoverFinishReq req = { .streamId = pTask->streamId, - .taskId = pTask->taskId, .childId = pTask->selfChildId, }; + // serialize if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH) { + req.taskId = pTask->fixedEpDispatcher.taskId; + streamDispatchOneRecoverFinishReq(pTask, &req, pTask->fixedEpDispatcher.nodeId, &pTask->fixedEpDispatcher.epSet); } else if (pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) { + SArray* vgInfo = pTask->shuffleDispatcher.dbInfo.pVgroupInfos; + int32_t vgSz = taosArrayGetSize(vgInfo); + for (int32_t i = 0; i < vgSz; i++) { + SVgroupInfo* pVgInfo = taosArrayGet(vgInfo, i); + req.taskId = pVgInfo->taskId; + streamDispatchOneRecoverFinishReq(pTask, &req, pVgInfo->vgId, &pVgInfo->epSet); + } } return 0; } @@ -76,10 +228,7 @@ int32_t streamDispatchRecoverFinishReq(SStreamTask* pTask) { // agg int32_t streamAggRecoverPrepare(SStreamTask* pTask) { void* exec = pTask->exec.executor; - if (qStreamSetParamForRecover(exec) < 0) { - return -1; - } - pTask->recoverWaitingChild = taosArrayGetSize(pTask->childEpInfo); + pTask->recoverWaitingUpstream = taosArrayGetSize(pTask->childEpInfo); return 0; } @@ -96,103 +245,86 @@ int32_t streamAggChildrenRecoverFinish(SStreamTask* pTask) { } int32_t streamProcessRecoverFinishReq(SStreamTask* pTask, int32_t childId) { - int32_t left = atomic_sub_fetch_32(&pTask->recoverWaitingChild, 1); - ASSERT(left >= 0); - if (left == 0) { - streamAggChildrenRecoverFinish(pTask); + if (pTask->taskLevel == TASK_LEVEL__AGG) { + int32_t left = atomic_sub_fetch_32(&pTask->recoverWaitingUpstream, 1); + ASSERT(left >= 0); + if (left == 0) { + streamAggChildrenRecoverFinish(pTask); + } } return 0; } -int32_t tEncodeSStreamRecoverFinishReq(SEncoder* pEncoder, const SStreamRecoverFinishReq* pReq) { +int32_t tEncodeSStreamTaskCheckReq(SEncoder* pEncoder, const SStreamTaskCheckReq* pReq) { if (tStartEncode(pEncoder) < 0) return -1; + if (tEncodeI64(pEncoder, pReq->reqId) < 0) return -1; if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->taskId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->childId) < 0) return -1; - tEndEncode(pEncoder); - return pEncoder->pos; -} -int32_t tDecodeSStreamRecoverFinishReq(SDecoder* pDecoder, SStreamRecoverFinishReq* pReq) { - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->taskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->childId) < 0) return -1; - tEndDecode(pDecoder); - return 0; -} -#if 0 -int32_t tEncodeStreamTaskRecoverReq(SEncoder* pEncoder, const SStreamTaskRecoverReq* pReq) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->taskId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->upstreamTaskId) < 0) return -1; if (tEncodeI32(pEncoder, pReq->upstreamNodeId) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->upstreamTaskId) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->downstreamNodeId) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->downstreamTaskId) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->childId) < 0) return -1; tEndEncode(pEncoder); return pEncoder->pos; } -int32_t tDecodeStreamTaskRecoverReq(SDecoder* pDecoder, SStreamTaskRecoverReq* pReq) { +int32_t tDecodeSStreamTaskCheckReq(SDecoder* pDecoder, SStreamTaskCheckReq* pReq) { if (tStartDecode(pDecoder) < 0) return -1; + if (tDecodeI64(pDecoder, &pReq->reqId) < 0) return -1; if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->taskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->upstreamTaskId) < 0) return -1; if (tDecodeI32(pDecoder, &pReq->upstreamNodeId) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->upstreamTaskId) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->downstreamNodeId) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->downstreamTaskId) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->childId) < 0) return -1; tEndDecode(pDecoder); return 0; } -int32_t tEncodeStreamTaskRecoverRsp(SEncoder* pEncoder, const SStreamTaskRecoverRsp* pRsp) { +int32_t tEncodeSStreamTaskCheckRsp(SEncoder* pEncoder, const SStreamTaskCheckRsp* pRsp) { if (tStartEncode(pEncoder) < 0) return -1; + if (tEncodeI64(pEncoder, pRsp->reqId) < 0) return -1; if (tEncodeI64(pEncoder, pRsp->streamId) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->reqTaskId) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->rspTaskId) < 0) return -1; - if (tEncodeI8(pEncoder, pRsp->inputStatus) < 0) return -1; + if (tEncodeI32(pEncoder, pRsp->upstreamNodeId) < 0) return -1; + if (tEncodeI32(pEncoder, pRsp->upstreamTaskId) < 0) return -1; + if (tEncodeI32(pEncoder, pRsp->downstreamNodeId) < 0) return -1; + if (tEncodeI32(pEncoder, pRsp->downstreamTaskId) < 0) return -1; + if (tEncodeI32(pEncoder, pRsp->childId) < 0) return -1; + if (tEncodeI8(pEncoder, pRsp->status) < 0) return -1; tEndEncode(pEncoder); return pEncoder->pos; } -int32_t tDecodeStreamTaskRecoverRsp(SDecoder* pDecoder, SStreamTaskRecoverRsp* pReq) { +int32_t tDecodeSStreamTaskCheckRsp(SDecoder* pDecoder, SStreamTaskCheckRsp* pRsp) { if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->reqTaskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->rspTaskId) < 0) return -1; - if (tDecodeI8(pDecoder, &pReq->inputStatus) < 0) return -1; + if (tDecodeI64(pDecoder, &pRsp->reqId) < 0) return -1; + if (tDecodeI64(pDecoder, &pRsp->streamId) < 0) return -1; + if (tDecodeI32(pDecoder, &pRsp->upstreamNodeId) < 0) return -1; + if (tDecodeI32(pDecoder, &pRsp->upstreamTaskId) < 0) return -1; + if (tDecodeI32(pDecoder, &pRsp->downstreamNodeId) < 0) return -1; + if (tDecodeI32(pDecoder, &pRsp->downstreamTaskId) < 0) return -1; + if (tDecodeI32(pDecoder, &pRsp->childId) < 0) return -1; + if (tDecodeI8(pDecoder, &pRsp->status) < 0) return -1; tEndDecode(pDecoder); return 0; } -int32_t tEncodeSMStreamTaskRecoverReq(SEncoder* pEncoder, const SMStreamTaskRecoverReq* pReq) { +int32_t tEncodeSStreamRecoverFinishReq(SEncoder* pEncoder, const SStreamRecoverFinishReq* pReq) { if (tStartEncode(pEncoder) < 0) return -1; if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1; if (tEncodeI32(pEncoder, pReq->taskId) < 0) return -1; + if (tEncodeI32(pEncoder, pReq->childId) < 0) return -1; tEndEncode(pEncoder); return pEncoder->pos; } - -int32_t tDecodeSMStreamTaskRecoverReq(SDecoder* pDecoder, SMStreamTaskRecoverReq* pReq) { - if (tStartDecode(pDecoder) < 0) return -1; - if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->taskId) < 0) return -1; - tEndDecode(pDecoder); - return 0; -} - -int32_t tEncodeSMStreamTaskRecoverRsp(SEncoder* pEncoder, const SMStreamTaskRecoverRsp* pRsp) { - if (tStartEncode(pEncoder) < 0) return -1; - if (tEncodeI64(pEncoder, pRsp->streamId) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->taskId) < 0) return -1; - tEndEncode(pEncoder); - return pEncoder->pos; -} - -int32_t tDecodeSMStreamTaskRecoverRsp(SDecoder* pDecoder, SMStreamTaskRecoverRsp* pReq) { +int32_t tDecodeSStreamRecoverFinishReq(SDecoder* pDecoder, SStreamRecoverFinishReq* pReq) { if (tStartDecode(pDecoder) < 0) return -1; if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1; if (tDecodeI32(pDecoder, &pReq->taskId) < 0) return -1; + if (tDecodeI32(pDecoder, &pReq->childId) < 0) return -1; tEndDecode(pDecoder); return 0; } -#endif int32_t tEncodeSStreamCheckpointInfo(SEncoder* pEncoder, const SStreamCheckpointInfo* pCheckpoint) { if (tEncodeI32(pEncoder, pCheckpoint->srcNodeId) < 0) return -1; @@ -236,308 +368,3 @@ int32_t tDecodeSStreamMultiVgCheckpointInfo(SDecoder* pDecoder, SStreamMultiVgCh } return 0; } - -#if 0 -int32_t tEncodeSStreamTaskRecoverReq(SEncoder* pEncoder, const SStreamRecoverDownstreamReq* pReq) { - if (tEncodeI64(pEncoder, pReq->streamId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->downstreamTaskId) < 0) return -1; - if (tEncodeI32(pEncoder, pReq->taskId) < 0) return -1; - return 0; -} - -int32_t tDecodeSStreamTaskRecoverReq(SDecoder* pDecoder, SStreamRecoverDownstreamReq* pReq) { - if (tDecodeI64(pDecoder, &pReq->streamId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->downstreamTaskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pReq->taskId) < 0) return -1; - return 0; -} - -int32_t tEncodeSStreamTaskRecoverRsp(SEncoder* pEncoder, const SStreamRecoverDownstreamRsp* pRsp) { - if (tEncodeI64(pEncoder, pRsp->streamId) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->downstreamTaskId) < 0) return -1; - if (tEncodeI32(pEncoder, pRsp->taskId) < 0) return -1; - int32_t sz = taosArrayGetSize(pRsp->checkpointVer); - if (tEncodeI32(pEncoder, sz) < 0) return -1; - for (int32_t i = 0; i < sz; i++) { - SStreamCheckpointInfo* pInfo = taosArrayGet(pRsp->checkpointVer, i); - if (tEncodeSStreamCheckpointInfo(pEncoder, pInfo) < 0) return -1; - } - return 0; -} - -int32_t tDecodeSStreamTaskRecoverRsp(SDecoder* pDecoder, SStreamRecoverDownstreamRsp* pRsp) { - if (tDecodeI64(pDecoder, &pRsp->streamId) < 0) return -1; - if (tDecodeI32(pDecoder, &pRsp->downstreamTaskId) < 0) return -1; - if (tDecodeI32(pDecoder, &pRsp->taskId) < 0) return -1; - int32_t sz; - if (tDecodeI32(pDecoder, &sz) < 0) return -1; - pRsp->checkpointVer = taosArrayInit(sz, sizeof(SStreamCheckpointInfo)); - if (pRsp->checkpointVer == NULL) return -1; - for (int32_t i = 0; i < sz; i++) { - SStreamCheckpointInfo info; - if (tDecodeSStreamCheckpointInfo(pDecoder, &info) < 0) return -1; - taosArrayPush(pRsp->checkpointVer, &info); - } - return 0; -} -#endif - -int32_t streamSaveStateInfo(SStreamMeta* pMeta, SStreamTask* pTask) { -#if 0 - void* buf = NULL; - - ASSERT(pTask->taskLevel == TASK_LEVEL__SINK); - - SStreamMultiVgCheckpointInfo checkpoint; - checkpoint.checkpointId = atomic_fetch_add_32(&pTask->nextCheckId, 1); - checkpoint.checkTs = taosGetTimestampMs(); - checkpoint.streamId = pTask->streamId; - checkpoint.taskId = pTask->taskId; - checkpoint.checkpointVer = pTask->checkpointInfo; - - int32_t len; - int32_t code; - tEncodeSize(tEncodeSStreamMultiVgCheckpointInfo, &checkpoint, len, code); - if (code < 0) { - return -1; - } - - buf = taosMemoryCalloc(1, len); - if (buf == NULL) { - return -1; - } - SEncoder encoder; - tEncoderInit(&encoder, buf, len); - tEncodeSStreamMultiVgCheckpointInfo(&encoder, &checkpoint); - tEncoderClear(&encoder); - - SStreamCheckpointKey key = { - .taskId = pTask->taskId, - .checkpointId = checkpoint.checkpointId, - }; - - if (tdbTbUpsert(pMeta->pStateDb, &key, sizeof(SStreamCheckpointKey), buf, len, &pMeta->txn) < 0) { - ASSERT(0); - goto FAIL; - } - - int32_t sz = taosArrayGetSize(pTask->checkpointInfo); - for (int32_t i = 0; i < sz; i++) { - SStreamCheckpointInfo* pCheck = taosArrayGet(pTask->checkpointInfo, i); - pCheck->stateSaveVer = pCheck->stateProcessedVer; - } - - taosMemoryFree(buf); - return 0; -FAIL: - if (buf) taosMemoryFree(buf); - return -1; -#endif - return 0; -} - -int32_t streamLoadStateInfo(SStreamMeta* pMeta, SStreamTask* pTask) { -#if 0 - void* pVal = NULL; - int32_t vLen = 0; - if (tdbTbGet(pMeta->pStateDb, &pTask->taskId, sizeof(void*), &pVal, &vLen) < 0) { - return -1; - } - SDecoder decoder; - tDecoderInit(&decoder, pVal, vLen); - SStreamMultiVgCheckpointInfo aggCheckpoint; - tDecodeSStreamMultiVgCheckpointInfo(&decoder, &aggCheckpoint); - tDecoderClear(&decoder); - - pTask->nextCheckId = aggCheckpoint.checkpointId + 1; - pTask->checkpointInfo = aggCheckpoint.checkpointVer; -#endif - return 0; -} - -int32_t streamSaveSinkLevel(SStreamMeta* pMeta, SStreamTask* pTask) { - ASSERT(pTask->taskLevel == TASK_LEVEL__SINK); - return streamSaveStateInfo(pMeta, pTask); -} - -int32_t streamRecoverSinkLevel(SStreamMeta* pMeta, SStreamTask* pTask) { - ASSERT(pTask->taskLevel == TASK_LEVEL__SINK); - return streamLoadStateInfo(pMeta, pTask); -} - -int32_t streamSaveAggLevel(SStreamMeta* pMeta, SStreamTask* pTask) { - ASSERT(pTask->taskLevel == TASK_LEVEL__AGG); - // TODO save and copy state - - // save state info - if (streamSaveStateInfo(pMeta, pTask) < 0) { - return -1; - } - return 0; -} - -#if 0 -int32_t streamFetchRecoverStatus(SStreamTask* pTask, const SVgroupInfo* pVgInfo) { - int32_t taskId = pVgInfo->taskId; - int32_t nodeId = pVgInfo->vgId; - SStreamRecoverDownstreamReq req = { - .streamId = pTask->taskId, - .downstreamTaskId = taskId, - .taskId = pTask->taskId, - }; - int32_t tlen; - int32_t code; - tEncodeSize(tEncodeSStreamTaskRecoverReq, &req, tlen, code); - if (code < 0) { - return -1; - } - void* buf = taosMemoryCalloc(1, sizeof(SMsgHead) + tlen); - if (buf == NULL) { - return -1; - } - void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); - SEncoder encoder; - tEncoderInit(&encoder, abuf, tlen); - if (tEncodeSStreamTaskRecoverReq(&encoder, &req) < 0) { - tEncoderClear(&encoder); - taosMemoryFree(buf); - return -1; - } - tEncoderClear(&encoder); - - ((SMsgHead*)buf)->vgId = htonl(nodeId); - SRpcMsg msg = { - .pCont = buf, .contLen = sizeof(SMsgHead) + tlen, - /*.msgType = */ - }; - tmsgSendReq(&pVgInfo->epSet, &msg); - - return 0; -} - -int32_t streamFetchDownstreamStatus(SStreamMeta* pMeta, SStreamTask* pTask) { - // set self status to recover_phase1 - SStreamRecoverStatus* pRecover; - atomic_store_8(&pTask->taskStatus, TASK_STATUS__RECOVER_DOWNSTREAM); - pRecover = taosHashGet(pMeta->pRecoverStatus, &pTask->taskId, sizeof(int32_t)); - if (pRecover == NULL) { - pRecover = taosMemoryCalloc(1, sizeof(SStreamRecoverStatus)); - if (pRecover == NULL) { - return -1; - } - pRecover->info = taosArrayInit(0, sizeof(void*)); - if (pRecover->info == NULL) { - taosMemoryFree(pRecover); - return -1; - } - taosHashPut(pMeta->pRecoverStatus, &pTask->taskId, sizeof(int32_t), &pRecover, sizeof(void*)); - } - - if (pTask->outputType == TASK_OUTPUT__FIXED_DISPATCH) { - pRecover->totReq = 1; - } else if (pTask->outputType == TASK_OUTPUT__SHUFFLE_DISPATCH) { - int32_t numOfDownstream = taosArrayGetSize(pTask->shuffleDispatcher.dbInfo.pVgroupInfos); - pRecover->totReq = numOfDownstream; - for (int32_t i = 0; i < numOfDownstream; i++) { - SVgroupInfo* pVgInfo = taosArrayGet(pTask->shuffleDispatcher.dbInfo.pVgroupInfos, i); - streamFetchRecoverStatus(pTask, pVgInfo); - } - } else { - ASSERT(0); - } - return 0; -} -#endif - -#if 0 -int32_t streamProcessFetchStatusRsp(SStreamMeta* pMeta, SStreamTask* pTask, SStreamRecoverDownstreamRsp* pRsp) { - // if failed, set timer and retry - // if successful - int32_t taskId = pTask->taskId; - SStreamRecoverStatus* pRecover = taosHashGet(pMeta->pRecoverStatus, &taskId, sizeof(int32_t)); - if (pRecover == NULL) { - return -1; - } - - taosArrayPush(pRecover->info, &pRsp->checkpointVer); - - int32_t leftRsp = atomic_sub_fetch_32(&pRecover->waitingRspCnt, 1); - ASSERT(leftRsp >= 0); - - if (leftRsp == 0) { - ASSERT(taosArrayGetSize(pRecover->info) == pRecover->totReq); - - // srcNodeId -> SStreamCheckpointInfo* - SHashObj* pFinalChecks = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); - if (pFinalChecks == NULL) return -1; - - for (int32_t i = 0; i < pRecover->totReq; i++) { - SArray* pChecks = taosArrayGetP(pRecover->info, i); - int32_t sz = taosArrayGetSize(pChecks); - for (int32_t j = 0; j < sz; j++) { - SStreamCheckpointInfo* pOneCheck = taosArrayGet(pChecks, j); - SStreamCheckpointInfo* pCheck = taosHashGet(pFinalChecks, &pOneCheck->srcNodeId, sizeof(int32_t)); - if (pCheck == NULL) { - pCheck = taosMemoryCalloc(1, sizeof(SStreamCheckpointInfo)); - pCheck->srcNodeId = pOneCheck->srcNodeId; - pCheck->srcChildId = pOneCheck->srcChildId; - pCheck->stateProcessedVer = pOneCheck->stateProcessedVer; - taosHashPut(pFinalChecks, &pCheck->srcNodeId, sizeof(int32_t), &pCheck, sizeof(void*)); - } else { - pCheck->stateProcessedVer = TMIN(pCheck->stateProcessedVer, pOneCheck->stateProcessedVer); - } - } - } - // load local state - // - // recover - // - if (pTask->taskLevel == TASK_LEVEL__SOURCE) { - qStreamPrepareRecover(pTask->exec.executor, pTask->startVer, pTask->recoverSnapVer); - if (streamPipelineExec(pTask, 10000, true) < 0) { - return -1; - } - } - taosHashCleanup(pFinalChecks); - taosHashRemove(pMeta->pRecoverStatus, &taskId, sizeof(int32_t)); - atomic_store_8(&pTask->taskStatus, TASK_STATUS__NORMAL); - } - return 0; -} - -int32_t streamRecoverAggLevel(SStreamMeta* pMeta, SStreamTask* pTask) { - ASSERT(pTask->taskLevel == TASK_LEVEL__AGG); - // recover sink level - // after all sink level recovered - // choose suitable state to recover - return 0; -} - -int32_t streamSaveSourceLevel(SStreamMeta* pMeta, SStreamTask* pTask) { - ASSERT(pTask->taskLevel == TASK_LEVEL__SOURCE); - // TODO: save and copy state - return 0; -} - -int32_t streamRecoverSourceLevel(SStreamMeta* pMeta, SStreamTask* pTask) { - ASSERT(pTask->taskLevel == TASK_LEVEL__SOURCE); - // if totLevel == 3 - // fetch agg state - // recover from local state to agg state, not send msg - // recover from agg state to most recent log v1 - // enable input queue, set status recover_phase2 - // recover from v1 to queue msg v2, set status normal - - // if totLevel == 2 - // fetch sink state - // recover from local state to sink state v1, send msg - // enable input queue, set status recover_phase2 - // recover from v1 to queue msg v2, set status normal - return 0; -} - -int32_t streamRecoverTask(SStreamTask* pTask) { - // - return 0; -} -#endif diff --git a/source/libs/stream/src/streamState.c b/source/libs/stream/src/streamState.c index ea429a76b0357d85b295fb1fbcc24c685290464f..ccb0dd4a92e12ee51bbdba6ffb4777ae663cae8e 100644 --- a/source/libs/stream/src/streamState.c +++ b/source/libs/stream/src/streamState.c @@ -29,7 +29,7 @@ typedef struct SStateSessionKey { int64_t opNum; } SStateSessionKey; -static inline int sessionKeyCmpr(const SSessionKey* pWin1, const SSessionKey* pWin2) { +static inline int sessionRangeKeyCmpr(const SSessionKey* pWin1, const SSessionKey* pWin2) { if (pWin1->groupId > pWin2->groupId) { return 1; } else if (pWin1->groupId < pWin2->groupId) { @@ -45,6 +45,28 @@ static inline int sessionKeyCmpr(const SSessionKey* pWin1, const SSessionKey* pW return 0; } +static inline int sessionWinKeyCmpr(const SSessionKey* pWin1, const SSessionKey* pWin2) { + if (pWin1->groupId > pWin2->groupId) { + return 1; + } else if (pWin1->groupId < pWin2->groupId) { + return -1; + } + + if (pWin1->win.skey > pWin2->win.skey) { + return 1; + } else if (pWin1->win.skey < pWin2->win.skey) { + return -1; + } + + if (pWin1->win.ekey > pWin2->win.ekey) { + return 1; + } else if (pWin1->win.ekey < pWin2->win.ekey) { + return -1; + } + + return 0; +} + static inline int stateSessionKeyCmpr(const void* pKey1, int kLen1, const void* pKey2, int kLen2) { SStateSessionKey* pWin1 = (SStateSessionKey*)pKey1; SStateSessionKey* pWin2 = (SStateSessionKey*)pKey2; @@ -55,7 +77,7 @@ static inline int stateSessionKeyCmpr(const void* pKey1, int kLen1, const void* return -1; } - return sessionKeyCmpr(&pWin1->key, &pWin2->key); + return sessionWinKeyCmpr(&pWin1->key, &pWin2->key); } static inline int stateKeyCmpr(const void* pKey1, int kLen1, const void* pKey2, int kLen2) { @@ -142,6 +164,7 @@ _err: void streamStateClose(SStreamState* pState) { tdbCommit(pState->db, &pState->txn); + tdbPostCommit(pState->db, &pState->txn); tdbTbClose(pState->pStateDb); tdbTbClose(pState->pFuncStateDb); tdbTbClose(pState->pFillStateDb); @@ -168,6 +191,9 @@ int32_t streamStateCommit(SStreamState* pState) { if (tdbCommit(pState->db, &pState->txn) < 0) { return -1; } + if (tdbPostCommit(pState->db, &pState->txn) < 0) { + return -1; + } memset(&pState->txn, 0, sizeof(TXN)); if (tdbTxnOpen(&pState->txn, 0, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED) < 0) { @@ -396,7 +422,6 @@ SStreamStateCur* streamStateSeekKeyNext(SStreamState* pState, const SWinKey* key SStateKey sKey = {.key = *key, .opNum = pState->number}; int32_t c = 0; if (tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateKey), &c) < 0) { - tdbTbcClose(pCur->pCur); streamStateFreeCur(pCur); return NULL; } @@ -422,7 +447,6 @@ SStreamStateCur* streamStateFillSeekKeyNext(SStreamState* pState, const SWinKey* int32_t c = 0; if (tdbTbcMoveTo(pCur->pCur, key, sizeof(SWinKey), &c) < 0) { - tdbTbcClose(pCur->pCur); streamStateFreeCur(pCur); return NULL; } @@ -448,7 +472,6 @@ SStreamStateCur* streamStateFillSeekKeyPrev(SStreamState* pState, const SWinKey* int32_t c = 0; if (tdbTbcMoveTo(pCur->pCur, key, sizeof(SWinKey), &c) < 0) { - tdbTbcClose(pCur->pCur); streamStateFreeCur(pCur); return NULL; } @@ -492,33 +515,18 @@ int32_t streamStateSessionPut(SStreamState* pState, const SSessionKey* key, cons return tdbTbUpsert(pState->pSessionStateDb, &sKey, sizeof(SStateSessionKey), value, vLen, &pState->txn); } -SStreamStateCur* streamStateSessionGetRanomCur(SStreamState* pState, const SSessionKey* key) { - SStreamStateCur* pCur = taosMemoryCalloc(1, sizeof(SStreamStateCur)); - if (pCur == NULL) return NULL; - tdbTbcOpen(pState->pSessionStateDb, &pCur->pCur, NULL); - - int32_t c = 0; - SStateSessionKey sKey = {.key = *key, .opNum = pState->number}; - tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateSessionKey), &c); - if (c != 0) { - streamStateFreeCur(pCur); - return NULL; - } - pCur->number = pState->number; - return pCur; -} - int32_t streamStateSessionGet(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen) { - SStreamStateCur* pCur = streamStateSessionGetRanomCur(pState, key); + SStreamStateCur* pCur = streamStateSessionSeekKeyCurrentNext(pState, key); + SSessionKey resKey = *key; void* tmp = NULL; - if (streamStateSessionGetKVByCur(pCur, key, (const void**)&tmp, pVLen) == 0) { + int32_t code = streamStateSessionGetKVByCur(pCur, &resKey, &tmp, pVLen); + if (code == 0) { + *key = resKey; *pVal = tdbRealloc(NULL, *pVLen); memcpy(*pVal, tmp, *pVLen); - streamStateFreeCur(pCur); - return 0; } streamStateFreeCur(pCur); - return -1; + return code; } int32_t streamStateSessionDel(SStreamState* pState, const SSessionKey* key) { @@ -540,7 +548,6 @@ SStreamStateCur* streamStateSessionSeekKeyCurrentPrev(SStreamState* pState, cons SStateSessionKey sKey = {.key = *key, .opNum = pState->number}; int32_t c = 0; if (tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateSessionKey), &c) < 0) { - tdbTbcClose(pCur->pCur); streamStateFreeCur(pCur); return NULL; } @@ -554,6 +561,34 @@ SStreamStateCur* streamStateSessionSeekKeyCurrentPrev(SStreamState* pState, cons return pCur; } +SStreamStateCur* streamStateSessionSeekKeyCurrentNext(SStreamState* pState, const SSessionKey* key) { + SStreamStateCur* pCur = taosMemoryCalloc(1, sizeof(SStreamStateCur)); + if (pCur == NULL) { + return NULL; + } + pCur->number = pState->number; + if (tdbTbcOpen(pState->pSessionStateDb, &pCur->pCur, NULL) < 0) { + streamStateFreeCur(pCur); + return NULL; + } + + SStateSessionKey sKey = {.key = *key, .opNum = pState->number}; + int32_t c = 0; + if (tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateSessionKey), &c) < 0) { + streamStateFreeCur(pCur); + return NULL; + } + + if (c <= 0) return pCur; + + if (tdbTbcMoveToNext(pCur->pCur) < 0) { + streamStateFreeCur(pCur); + return NULL; + } + + return pCur; +} + SStreamStateCur* streamStateSessionSeekKeyNext(SStreamState* pState, const SSessionKey* key) { SStreamStateCur* pCur = taosMemoryCalloc(1, sizeof(SStreamStateCur)); if (pCur == NULL) { @@ -568,7 +603,6 @@ SStreamStateCur* streamStateSessionSeekKeyNext(SStreamState* pState, const SSess SStateSessionKey sKey = {.key = *key, .opNum = pState->number}; int32_t c = 0; if (tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateSessionKey), &c) < 0) { - tdbTbcClose(pCur->pCur); streamStateFreeCur(pCur); return NULL; } @@ -582,13 +616,13 @@ SStreamStateCur* streamStateSessionSeekKeyNext(SStreamState* pState, const SSess return pCur; } -int32_t streamStateSessionGetKVByCur(SStreamStateCur* pCur, SSessionKey* pKey, const void** pVal, int32_t* pVLen) { +int32_t streamStateSessionGetKVByCur(SStreamStateCur* pCur, SSessionKey* pKey, void** pVal, int32_t* pVLen) { if (!pCur) { return -1; } - const SStateSessionKey* pKTmp = NULL; - int32_t kLen; - if (tdbTbcGet(pCur->pCur, (const void**)&pKTmp, &kLen, pVal, pVLen) < 0) { + SStateSessionKey* pKTmp = NULL; + int32_t kLen; + if (tdbTbcGet(pCur->pCur, (const void**)&pKTmp, &kLen, (const void**)pVal, pVLen) < 0) { return -1; } if (pKTmp->opNum != pCur->number) { @@ -602,15 +636,15 @@ int32_t streamStateSessionGetKVByCur(SStreamStateCur* pCur, SSessionKey* pKey, c } int32_t streamStateSessionClear(SStreamState* pState) { - SSessionKey key = {.win.skey = 0, .win.ekey = 0, .groupId = 0}; - streamStateSessionPut(pState, &key, NULL, 0); - SStreamStateCur* pCur = streamStateSessionSeekKeyNext(pState, &key); + SSessionKey key = {.win.skey = 0, .win.ekey = 0, .groupId = 0}; + SStreamStateCur* pCur = streamStateSessionSeekKeyCurrentNext(pState, &key); while (1) { SSessionKey delKey = {0}; void* buf = NULL; int32_t size = 0; - int32_t code = streamStateSessionGetKVByCur(pCur, &delKey, buf, &size); + int32_t code = streamStateSessionGetKVByCur(pCur, &delKey, &buf, &size); if (code == 0) { + ASSERT(size > 0); memset(buf, 0, size); streamStateSessionPut(pState, &delKey, buf, size); } else { @@ -619,61 +653,104 @@ int32_t streamStateSessionClear(SStreamState* pState) { streamStateCurNext(pState, pCur); } streamStateFreeCur(pCur); - streamStateSessionDel(pState, &key); return 0; } -SStreamStateCur* streamStateSessionGetCur(SStreamState* pState, const SSessionKey* key) { - SStreamStateCur* pCur = streamStateSessionGetRanomCur(pState, key); - SSessionKey resKey = *key; - while (1) { - streamStateCurPrev(pState, pCur); - SSessionKey tmpKey = *key; - int32_t code = streamStateSessionGetKVByCur(pCur, &tmpKey, NULL, 0); - if (code == 0 && sessionKeyCmpr(key, &tmpKey) == 0) { - resKey = tmpKey; - } else { - break; - } +int32_t streamStateSessionGetKeyByRange(SStreamState* pState, const SSessionKey* key, SSessionKey* curKey) { + SStreamStateCur* pCur = taosMemoryCalloc(1, sizeof(SStreamStateCur)); + if (pCur == NULL) { + return -1; + } + pCur->number = pState->number; + if (tdbTbcOpen(pState->pSessionStateDb, &pCur->pCur, NULL) < 0) { + streamStateFreeCur(pCur); + return -1; } - streamStateFreeCur(pCur); - return streamStateSessionGetRanomCur(pState, &resKey); -} -int32_t streamStateSessionGetKey(SStreamState* pState, const SSessionKey* key, SSessionKey* curKey) { - SStreamStateCur* pCur = streamStateSessionGetRanomCur(pState, key); - SSessionKey resKey = *key; - int32_t res = -1; - while (1) { - SSessionKey tmpKey = *key; - int32_t code = streamStateSessionGetKVByCur(pCur, &tmpKey, NULL, 0); - if (code == 0 && sessionKeyCmpr(key, &tmpKey) == 0) { - res = 0; - resKey = tmpKey; - streamStateCurPrev(pState, pCur); - } else { - break; + SStateSessionKey sKey = {.key = *key, .opNum = pState->number}; + int32_t c = 0; + if (tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateSessionKey), &c) < 0) { + streamStateFreeCur(pCur); + return -1; + } + + SSessionKey resKey = *key; + int32_t code = streamStateSessionGetKVByCur(pCur, &resKey, NULL, 0); + if (code == 0 && sessionRangeKeyCmpr(key, &resKey) == 0) { + *curKey = resKey; + streamStateFreeCur(pCur); + return code; + } + + if (c > 0) { + streamStateCurNext(pState, pCur); + code = streamStateSessionGetKVByCur(pCur, &resKey, NULL, 0); + if (code == 0 && sessionRangeKeyCmpr(key, &resKey) == 0) { + *curKey = resKey; + streamStateFreeCur(pCur); + return code; + } + } else if (c < 0) { + streamStateCurPrev(pState, pCur); + code = streamStateSessionGetKVByCur(pCur, &resKey, NULL, 0); + if (code == 0 && sessionRangeKeyCmpr(key, &resKey) == 0) { + *curKey = resKey; + streamStateFreeCur(pCur); + return code; } } - *curKey = resKey; + streamStateFreeCur(pCur); - return res; + return -1; } -int32_t streamStateSessionAddIfNotExist(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen) { +int32_t streamStateSessionAddIfNotExist(SStreamState* pState, SSessionKey* key, TSKEY gap, void** pVal, + int32_t* pVLen) { // todo refactor - SStreamStateCur* pCur = streamStateSessionGetRanomCur(pState, key); - int32_t size = *pVLen; - void* tmp = NULL; - *pVal = tdbRealloc(NULL, size); - memset(*pVal, 0, size); - if (streamStateSessionGetKVByCur(pCur, key, (const void**)&tmp, pVLen) == 0) { - memcpy(*pVal, tmp, *pVLen); + int32_t res = 0; + SSessionKey originKey = *key; + SSessionKey searchKey = *key; + searchKey.win.skey = key->win.skey - gap; + searchKey.win.ekey = key->win.ekey + gap; + int32_t valSize = *pVLen; + void* tmp = tdbRealloc(NULL, valSize); + if (!tmp) { + return -1; + } + + SStreamStateCur* pCur = streamStateSessionSeekKeyCurrentPrev(pState, key); + int32_t code = streamStateSessionGetKVByCur(pCur, key, pVal, pVLen); + if (code == 0) { + if (sessionRangeKeyCmpr(&searchKey, key) == 0) { + memcpy(tmp, *pVal, valSize); + streamStateSessionDel(pState, key); + goto _end; + } + streamStateCurNext(pState, pCur); + } else { + *key = originKey; streamStateFreeCur(pCur); - return 0; + pCur = streamStateSessionSeekKeyNext(pState, key); + } + + code = streamStateSessionGetKVByCur(pCur, key, pVal, pVLen); + if (code == 0) { + if (sessionRangeKeyCmpr(&searchKey, key) == 0) { + memcpy(tmp, *pVal, valSize); + streamStateSessionDel(pState, key); + goto _end; + } } + + *key = originKey; + res = 1; + memset(tmp, 0, valSize); + +_end: + + *pVal = tmp; streamStateFreeCur(pCur); - return 1; + return res; } int32_t streamStateStateAddIfNotExist(SStreamState* pState, SSessionKey* key, char* pKeyData, int32_t keyDataLen, @@ -688,16 +765,18 @@ int32_t streamStateStateAddIfNotExist(SStreamState* pState, SSessionKey* key, ch } SStreamStateCur* pCur = streamStateSessionSeekKeyCurrentPrev(pState, key); - int32_t code = streamStateSessionGetKVByCur(pCur, key, (const void**)pVal, pVLen); + int32_t code = streamStateSessionGetKVByCur(pCur, key, pVal, pVLen); if (code == 0) { if (key->win.skey <= tmpKey.win.skey && tmpKey.win.ekey <= key->win.ekey) { memcpy(tmp, *pVal, valSize); + streamStateSessionDel(pState, key); goto _end; } void* stateKey = (char*)(*pVal) + (valSize - keyDataLen); if (fn(pKeyData, stateKey) == true) { memcpy(tmp, *pVal, valSize); + streamStateSessionDel(pState, key); goto _end; } @@ -708,11 +787,12 @@ int32_t streamStateStateAddIfNotExist(SStreamState* pState, SSessionKey* key, ch pCur = streamStateSessionSeekKeyNext(pState, key); } - code = streamStateSessionGetKVByCur(pCur, key, (const void**)pVal, pVLen); + code = streamStateSessionGetKVByCur(pCur, key, pVal, pVLen); if (code == 0) { void* stateKey = (char*)(*pVal) + (valSize - keyDataLen); if (fn(pKeyData, stateKey) == true) { memcpy(tmp, *pVal, valSize); + streamStateSessionDel(pState, key); goto _end; } } @@ -727,3 +807,48 @@ _end: streamStateFreeCur(pCur); return res; } + +#if 0 +char* streamStateSessionDump(SStreamState* pState) { + SStreamStateCur* pCur = taosMemoryCalloc(1, sizeof(SStreamStateCur)); + if (pCur == NULL) { + return NULL; + } + pCur->number = pState->number; + if (tdbTbcOpen(pState->pSessionStateDb, &pCur->pCur, NULL) < 0) { + streamStateFreeCur(pCur); + return NULL; + } + tdbTbcMoveToFirst(pCur->pCur); + + SSessionKey key = {0}; + void* buf = NULL; + int32_t bufSize = 0; + int32_t code = streamStateSessionGetKVByCur(pCur, &key, &buf, &bufSize); + if (code != 0) { + streamStateFreeCur(pCur); + return NULL; + } + + int32_t size = 2048; + char* dumpBuf = taosMemoryCalloc(size, 1); + int64_t len = 0; + len += snprintf(dumpBuf + len, size - len, "||s:%15" PRId64 ",", key.win.skey); + len += snprintf(dumpBuf + len, size - len, "e:%15" PRId64 ",", key.win.ekey); + len += snprintf(dumpBuf + len, size - len, "g:%15" PRId64 "||", key.groupId); + while (1) { + tdbTbcMoveToNext(pCur->pCur); + key = (SSessionKey){0}; + code = streamStateSessionGetKVByCur(pCur, &key, NULL, 0); + if (code != 0) { + streamStateFreeCur(pCur); + return dumpBuf; + } + len += snprintf(dumpBuf + len, size - len, "||s:%15" PRId64 ",", key.win.skey); + len += snprintf(dumpBuf + len, size - len, "e:%15" PRId64 ",", key.win.ekey); + len += snprintf(dumpBuf + len, size - len, "g:%15" PRId64 "||", key.groupId); + } + streamStateFreeCur(pCur); + return dumpBuf; +} +#endif diff --git a/source/libs/sync/inc/syncCommit.h b/source/libs/sync/inc/syncCommit.h index c76236d5bfd3ca3050c7dbe3900a5644c4388911..7458ce28ab8e02196d74b9adbac80deb6acb7690 100644 --- a/source/libs/sync/inc/syncCommit.h +++ b/source/libs/sync/inc/syncCommit.h @@ -49,6 +49,7 @@ extern "C" { // IN commitIndex' = [commitIndex EXCEPT ![i] = newCommitIndex] // /\ UNCHANGED <> // +void syncOneReplicaAdvance(SSyncNode* pSyncNode); void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode); bool syncAgreeIndex(SSyncNode* pSyncNode, SRaftId* pRaftId, SyncIndex index); bool syncAgree(SSyncNode* pSyncNode, SyncIndex index); diff --git a/source/libs/sync/inc/syncEnv.h b/source/libs/sync/inc/syncEnv.h index 2a37e000e259c85f5a7de333b35e5a8822422647..cf4e3309f1f7c26ce43a357eff9c73dbc9d0b357 100644 --- a/source/libs/sync/inc/syncEnv.h +++ b/source/libs/sync/inc/syncEnv.h @@ -20,21 +20,15 @@ extern "C" { #endif -#include -#include -#include #include "syncInt.h" -#include "taosdef.h" -#include "trpc.h" -#include "ttimer.h" -#define TIMER_MAX_MS 0x7FFFFFFF -#define ENV_TICK_TIMER_MS 1000 -#define PING_TIMER_MS 5000 -#define ELECT_TIMER_MS_MIN 5000 -#define ELECT_TIMER_MS_MAX (ELECT_TIMER_MS_MIN * 2) +#define TIMER_MAX_MS 0x7FFFFFFF +#define ENV_TICK_TIMER_MS 1000 +#define PING_TIMER_MS 5000 +#define ELECT_TIMER_MS_MIN 2500 +#define ELECT_TIMER_MS_MAX (ELECT_TIMER_MS_MIN * 2) #define ELECT_TIMER_MS_RANGE (ELECT_TIMER_MS_MAX - ELECT_TIMER_MS_MIN) -#define HEARTBEAT_TIMER_MS 900 +#define HEARTBEAT_TIMER_MS 1000 #define EMPTY_RAFT_ID ((SRaftId){.addr = 0, .vgId = 0}) @@ -57,12 +51,13 @@ typedef struct SSyncEnv { } SSyncEnv; -extern SSyncEnv* gSyncEnv; +SSyncEnv* syncEnv(); +bool syncIsInit(); -int32_t syncEnvStart(); -int32_t syncEnvStop(); -int32_t syncEnvStartTimer(); -int32_t syncEnvStopTimer(); +int64_t syncNodeAdd(SSyncNode* pNode); +void syncNodeRemove(int64_t rid); +SSyncNode* syncNodeAcquire(int64_t rid); +void syncNodeRelease(SSyncNode* pNode); #ifdef __cplusplus } diff --git a/source/libs/sync/inc/syncInt.h b/source/libs/sync/inc/syncInt.h index ae053328ab4f93656a8977ea180470f748c55218..8a951ba38d08d4fc5f7a117780ef6a1e218924a4 100644 --- a/source/libs/sync/inc/syncInt.h +++ b/source/libs/sync/inc/syncInt.h @@ -22,22 +22,48 @@ extern "C" { #include "sync.h" #include "syncTools.h" +#include "taosdef.h" #include "tlog.h" +#include "trpc.h" #include "ttimer.h" // clang-format off -#define sFatal(...) do { if (sDebugFlag & DEBUG_FATAL) { taosPrintLog("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) -#define sError(...) do { if (sDebugFlag & DEBUG_ERROR) { taosPrintLog("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) -#define sWarn(...) do { if (sDebugFlag & DEBUG_WARN) { taosPrintLog("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) -#define sInfo(...) do { if (sDebugFlag & DEBUG_INFO) { taosPrintLog("SYN ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) -#define sDebug(...) do { if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("SYN ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); }} while(0) -#define sTrace(...) do { if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("SYN ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); }} while(0) -#define sFatalLong(...) do { if (sDebugFlag & DEBUG_FATAL) { taosPrintLongString("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while(0) -#define sErrorLong(...) do { if (sDebugFlag & DEBUG_ERROR) { taosPrintLongString("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while(0) -#define sWarnLong(...) do { if (sDebugFlag & DEBUG_WARN) { taosPrintLongString("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while(0) -#define sInfoLong(...) do { if (sDebugFlag & DEBUG_INFO) { taosPrintLongString("SYN ", DEBUG_INFO, 255, __VA_ARGS__); }} while(0) -#define sDebugLong(...) do { if (sDebugFlag & DEBUG_DEBUG) { taosPrintLongString("SYN ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); }} while(0) -#define sTraceLong(...) do { if (sDebugFlag & DEBUG_TRACE) { taosPrintLongString("SYN ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); }} while(0) + +#define sFatal(...) if (sDebugFlag & DEBUG_FATAL) { taosPrintLog("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); } +#define sError(...) if (sDebugFlag & DEBUG_ERROR) { taosPrintLog("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); } +#define sWarn(...) if (sDebugFlag & DEBUG_WARN) { taosPrintLog("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); } +#define sInfo(...) if (sDebugFlag & DEBUG_INFO) { taosPrintLog("SYN ", DEBUG_INFO, 255, __VA_ARGS__); } +#define sDebug(...) if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("SYN ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); } +#define sTrace(...) if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("SYN ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); } + +#define sLFatal(...) if (sDebugFlag & DEBUG_FATAL) { taosPrintLongString("SYN FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); } +#define sLError(...) if (sDebugFlag & DEBUG_ERROR) { taosPrintLongString("SYN ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); } +#define sLWarn(...) if (sDebugFlag & DEBUG_WARN) { taosPrintLongString("SYN WARN ", DEBUG_WARN, 255, __VA_ARGS__); } +#define sLInfo(...) if (sDebugFlag & DEBUG_INFO) { taosPrintLongString("SYN ", DEBUG_INFO, 255, __VA_ARGS__); } +#define sLDebug(...) if (sDebugFlag & DEBUG_DEBUG) { taosPrintLongString("SYN ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); } +#define sLTrace(...) if (sDebugFlag & DEBUG_TRACE) { taosPrintLongString("SYN ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); } + +#define sNFatal(pNode, ...) if (sDebugFlag & DEBUG_FATAL) { syncPrintNodeLog("SYN FATAL ", DEBUG_FATAL, 255, pNode, __VA_ARGS__); } +#define sNError(pNode, ...) if (sDebugFlag & DEBUG_ERROR) { syncPrintNodeLog("SYN ERROR ", DEBUG_ERROR, 255, pNode, __VA_ARGS__); } +#define sNWarn(pNode, ...) if (sDebugFlag & DEBUG_WARN) { syncPrintNodeLog("SYN WARN ", DEBUG_WARN, 255, pNode, __VA_ARGS__); } +#define sNInfo(pNode, ...) if (sDebugFlag & DEBUG_INFO) { syncPrintNodeLog("SYN ", DEBUG_INFO, 255, pNode, __VA_ARGS__); } +#define sNDebug(pNode, ...) if (sDebugFlag & DEBUG_DEBUG) { syncPrintNodeLog("SYN ", DEBUG_DEBUG, sDebugFlag, pNode, __VA_ARGS__); } +#define sNTrace(pNode, ...) if (sDebugFlag & DEBUG_TRACE) { syncPrintNodeLog("SYN ", DEBUG_TRACE, sDebugFlag, pNode, __VA_ARGS__); } + +#define sSFatal(pSender, ...) if (sDebugFlag & DEBUG_FATAL) { syncPrintSnapshotSenderLog("SYN FATAL ", DEBUG_FATAL, 255, pSender, __VA_ARGS__); } +#define sSError(pSender, ...) if (sDebugFlag & DEBUG_ERROR) { syncPrintSnapshotSenderLog("SYN ERROR ", DEBUG_ERROR, 255, pSender, __VA_ARGS__); } +#define sSWarn(pSender, ...) if (sDebugFlag & DEBUG_WARN) { syncPrintSnapshotSenderLog("SYN WARN ", DEBUG_WARN, 255, pSender, __VA_ARGS__); } +#define sSInfo(pSender, ...) if (sDebugFlag & DEBUG_INFO) { syncPrintSnapshotSenderLog("SYN ", DEBUG_INFO, 255, pSender, __VA_ARGS__); } +#define sSDebug(pSender, ...) if (sDebugFlag & DEBUG_DEBUG) { syncPrintSnapshotSenderLog("SYN ", DEBUG_DEBUG, sDebugFlag, pSender, __VA_ARGS__); } +#define sSTrace(pSender, ...) if (sDebugFlag & DEBUG_TRACE) { syncPrintSnapshotSenderLog("SYN ", DEBUG_TRACE, sDebugFlag, pSender, __VA_ARGS__); } + +#define sRFatal(pReceiver, ...) if (sDebugFlag & DEBUG_FATAL) { syncPrintSnapshotReceiverLog("SYN FATAL ", DEBUG_FATAL, 255, pReceiver, __VA_ARGS__); } +#define sRError(pReceiver, ...) if (sDebugFlag & DEBUG_ERROR) { syncPrintSnapshotReceiverLog("SYN ERROR ", DEBUG_ERROR, 255, pReceiver, __VA_ARGS__); } +#define sRWarn(pReceiver, ...) if (sDebugFlag & DEBUG_WARN) { syncPrintSnapshotReceiverLog("SYN WARN ", DEBUG_WARN, 255, pReceiver, __VA_ARGS__); } +#define sRInfo(pReceiver, ...) if (sDebugFlag & DEBUG_INFO) { syncPrintSnapshotReceiverLog("SYN ", DEBUG_INFO, 255, pReceiver, __VA_ARGS__); } +#define sRDebug(pReceiver, ...) if (sDebugFlag & DEBUG_DEBUG) { syncPrintSnapshotReceiverLog("SYN ", DEBUG_DEBUG, sDebugFlag, pReceiver, __VA_ARGS__); } +#define sRTrace(pReceiver, ...) if (sDebugFlag & DEBUG_TRACE) { syncPrintSnapshotReceiverLog("SYN ", DEBUG_TRACE, sDebugFlag, pReceiver, __VA_ARGS__); } + // clang-format on typedef struct SyncTimeout SyncTimeout; @@ -85,10 +111,6 @@ typedef struct SElectTimer { void* pData; } SElectTimer; -int32_t syncHbTimerInit(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer, SRaftId destId); -int32_t syncHbTimerStart(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer); -int32_t syncHbTimerStop(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer); - typedef struct SPeerState { SyncIndex lastSendIndex; int64_t lastSendTime; @@ -105,9 +127,9 @@ typedef struct SSyncNode { // sync io SWal* pWal; const SMsgCb* msgcb; - int32_t (*FpSendMsg)(const SEpSet* pEpSet, SRpcMsg* pMsg); - int32_t (*FpEqMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg); - int32_t (*FpEqCtrlMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg); + int32_t (*syncSendMSg)(const SEpSet* pEpSet, SRpcMsg* pMsg); + int32_t (*syncEqMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg); + int32_t (*syncEqCtrlMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg); // init internal SNodeInfo myNodeInfo; @@ -216,6 +238,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo); void syncNodeStart(SSyncNode* pSyncNode); void syncNodeStartStandBy(SSyncNode* pSyncNode); void syncNodeClose(SSyncNode* pSyncNode); +void syncNodePreClose(SSyncNode* pSyncNode); int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak); // option @@ -245,18 +268,10 @@ int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode); // utils -------------- int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg); int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, SRpcMsg* pMsg); -cJSON* syncNode2Json(const SSyncNode* pSyncNode); -char* syncNode2Str(const SSyncNode* pSyncNode); -void syncNodeEventLog(const SSyncNode* pSyncNode, char* str); -void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str); char* syncNode2SimpleStr(const SSyncNode* pSyncNode); bool syncNodeInConfig(SSyncNode* pSyncNode, const SSyncCfg* config); void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* newConfig, SyncIndex lastConfigChangeIndex); SyncIndex syncMinMatchIndex(SSyncNode* pSyncNode); -char* syncNodePeerState2Str(const SSyncNode* pSyncNode); - -SSyncNode* syncNodeAcquire(int64_t rid); -void syncNodeRelease(SSyncNode* pNode); // raft state change -------------- void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term); @@ -302,11 +317,7 @@ bool syncNodeNeedSendAppendEntries(SSyncNode* ths, const SRaftId* pDestId, const int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta); int32_t syncGetSnapshotMetaByIndex(int64_t rid, SyncIndex snapshotIndex, struct SSnapshotMeta* sMeta); -void syncStartNormal(int64_t rid); -void syncStartStandBy(int64_t rid); - bool syncNodeCanChange(SSyncNode* pSyncNode); -bool syncNodeCheckNewConfig(SSyncNode* pSyncNode, const SSyncCfg* pNewCfg); int32_t syncNodeLeaderTransfer(SSyncNode* pSyncNode); int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader); @@ -319,6 +330,7 @@ int32_t syncNodePeerStateInit(SSyncNode* pSyncNode); // trace log void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const char* s); +void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const char* s); void syncLogSendRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s); void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s); @@ -341,12 +353,24 @@ void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s); void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s); -// for debug -------------- -void syncNodePrint(SSyncNode* pObj); -void syncNodePrint2(char* s, SSyncNode* pObj); -void syncNodeLog(SSyncNode* pObj); -void syncNodeLog2(char* s, SSyncNode* pObj); -void syncNodeLog3(char* s, SSyncNode* pObj); +void syncLogSendSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s); +void syncLogRecvSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s); + +void syncLogSendSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s); +void syncLogRecvSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s); + +void syncLogSendSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s); +void syncLogRecvSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s); + +void syncLogSendSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s); +void syncLogRecvSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s); + +// syncUtil.h +void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNode* pNode, const char* format, ...); +void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotSender* pSender, + const char* format, ...); +void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotReceiver* pReceiver, + const char* format, ...); #ifdef __cplusplus } diff --git a/source/libs/sync/inc/syncRaftCfg.h b/source/libs/sync/inc/syncRaftCfg.h index e193e16c02d3b811216bed03b1ad17899ebe04da..15ca82664a8682f99e66a0a827562c56b8529b2b 100644 --- a/source/libs/sync/inc/syncRaftCfg.h +++ b/source/libs/sync/inc/syncRaftCfg.h @@ -45,8 +45,8 @@ int32_t raftCfgIndexClose(SRaftCfgIndex *pRaftCfgIndex); int32_t raftCfgIndexPersist(SRaftCfgIndex *pRaftCfgIndex); int32_t raftCfgIndexAddConfigIndex(SRaftCfgIndex *pRaftCfgIndex, SyncIndex configIndex); -cJSON * raftCfgIndex2Json(SRaftCfgIndex *pRaftCfgIndex); -char * raftCfgIndex2Str(SRaftCfgIndex *pRaftCfgIndex); +cJSON *raftCfgIndex2Json(SRaftCfgIndex *pRaftCfgIndex); +char *raftCfgIndex2Str(SRaftCfgIndex *pRaftCfgIndex); int32_t raftCfgIndexFromJson(const cJSON *pRoot, SRaftCfgIndex *pRaftCfgIndex); int32_t raftCfgIndexFromStr(const char *s, SRaftCfgIndex *pRaftCfgIndex); @@ -73,14 +73,14 @@ int32_t raftCfgClose(SRaftCfg *pRaftCfg); int32_t raftCfgPersist(SRaftCfg *pRaftCfg); int32_t raftCfgAddConfigIndex(SRaftCfg *pRaftCfg, SyncIndex configIndex); -cJSON * syncCfg2Json(SSyncCfg *pSyncCfg); -char * syncCfg2Str(SSyncCfg *pSyncCfg); -char * syncCfg2SimpleStr(SSyncCfg *pSyncCfg); +cJSON *syncCfg2Json(SSyncCfg *pSyncCfg); +char *syncCfg2Str(SSyncCfg *pSyncCfg); +void syncCfg2SimpleStr(const SSyncCfg *pCfg, char *str, int32_t bufLen); int32_t syncCfgFromJson(const cJSON *pRoot, SSyncCfg *pSyncCfg); int32_t syncCfgFromStr(const char *s, SSyncCfg *pSyncCfg); -cJSON * raftCfg2Json(SRaftCfg *pRaftCfg); -char * raftCfg2Str(SRaftCfg *pRaftCfg); +cJSON *raftCfg2Json(SRaftCfg *pRaftCfg); +char *raftCfg2Str(SRaftCfg *pRaftCfg); int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg); int32_t raftCfgFromStr(const char *s, SRaftCfg *pRaftCfg); @@ -93,23 +93,6 @@ typedef struct SRaftCfgMeta { int32_t raftCfgCreateFile(SSyncCfg *pCfg, SRaftCfgMeta meta, const char *path); -// for debug ---------------------- -void syncCfgPrint(SSyncCfg *pCfg); -void syncCfgPrint2(char *s, SSyncCfg *pCfg); -void syncCfgLog(SSyncCfg *pCfg); -void syncCfgLog2(char *s, SSyncCfg *pCfg); -void syncCfgLog3(char *s, SSyncCfg *pCfg); - -void raftCfgPrint(SRaftCfg *pCfg); -void raftCfgPrint2(char *s, SRaftCfg *pCfg); -void raftCfgLog(SRaftCfg *pCfg); -void raftCfgLog2(char *s, SRaftCfg *pCfg); - -void raftCfgIndexPrint(SRaftCfgIndex *pCfg); -void raftCfgIndexPrint2(char *s, SRaftCfgIndex *pCfg); -void raftCfgIndexLog(SRaftCfgIndex *pCfg); -void raftCfgIndexLog2(char *s, SRaftCfgIndex *pCfg); - #ifdef __cplusplus } #endif diff --git a/source/libs/sync/inc/syncRaftEntry.h b/source/libs/sync/inc/syncRaftEntry.h index bab1dcc661a90c0d9747d37699d64b747526495d..8b8ab41b53019528c4c9cbfe48f4f52441421fea 100644 --- a/source/libs/sync/inc/syncRaftEntry.h +++ b/source/libs/sync/inc/syncRaftEntry.h @@ -42,25 +42,14 @@ typedef struct SSyncRaftEntry { char data[]; // origin RpcMsg.pCont } SSyncRaftEntry; -SSyncRaftEntry* syncEntryBuild(uint32_t dataLen); -SSyncRaftEntry* syncEntryBuild2(SyncClientRequest* pMsg, SyncTerm term, SyncIndex index); // step 4 -SSyncRaftEntry* syncEntryBuild3(SyncClientRequest* pMsg, SyncTerm term, SyncIndex index); -SSyncRaftEntry* syncEntryBuild4(SRpcMsg* pOriginalMsg, SyncTerm term, SyncIndex index); +SSyncRaftEntry* syncEntryBuild(int32_t dataLen); +SSyncRaftEntry* syncEntryBuildFromClientRequest(const SyncClientRequest* pMsg, SyncTerm term, SyncIndex index); +SSyncRaftEntry* syncEntryBuildFromRpcMsg(const SRpcMsg* pMsg, SyncTerm term, SyncIndex index); +SSyncRaftEntry* syncEntryBuildFromAppendEntries(const SyncAppendEntries* pMsg); SSyncRaftEntry* syncEntryBuildNoop(SyncTerm term, SyncIndex index, int32_t vgId); void syncEntryDestory(SSyncRaftEntry* pEntry); -char* syncEntrySerialize(const SSyncRaftEntry* pEntry, uint32_t* len); // step 5 -SSyncRaftEntry* syncEntryDeserialize(const char* buf, uint32_t len); // step 6 -cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry); -char* syncEntry2Str(const SSyncRaftEntry* pEntry); void syncEntry2OriginalRpc(const SSyncRaftEntry* pEntry, SRpcMsg* pRpcMsg); // step 7 -// for debug ---------------------- -void syncEntryPrint(const SSyncRaftEntry* pObj); -void syncEntryPrint2(char* s, const SSyncRaftEntry* pObj); -void syncEntryLog(const SSyncRaftEntry* pObj); -void syncEntryLog2(char* s, const SSyncRaftEntry* pObj); - -//----------------------------------- typedef struct SRaftEntryHashCache { SHashObj* pEntryHash; int32_t maxCount; @@ -78,14 +67,6 @@ int32_t raftCacheDelEntry(struct SRaftEntryHashCache* pCache, SyncI int32_t raftCacheGetAndDel(struct SRaftEntryHashCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry); int32_t raftCacheClear(struct SRaftEntryHashCache* pCache); -cJSON* raftCache2Json(SRaftEntryHashCache* pObj); -char* raftCache2Str(SRaftEntryHashCache* pObj); -void raftCachePrint(SRaftEntryHashCache* pObj); -void raftCachePrint2(char* s, SRaftEntryHashCache* pObj); -void raftCacheLog(SRaftEntryHashCache* pObj); -void raftCacheLog2(char* s, SRaftEntryHashCache* pObj); - -//----------------------------------- typedef struct SRaftEntryCache { SSkipList* pSkipList; int32_t maxCount; @@ -102,13 +83,6 @@ int32_t raftEntryCacheGetEntry(struct SRaftEntryCache* pCache, SyncInde int32_t raftEntryCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry); int32_t raftEntryCacheClear(struct SRaftEntryCache* pCache, int32_t count); -cJSON* raftEntryCache2Json(SRaftEntryCache* pObj); -char* raftEntryCache2Str(SRaftEntryCache* pObj); -void raftEntryCachePrint(SRaftEntryCache* pObj); -void raftEntryCachePrint2(char* s, SRaftEntryCache* pObj); -void raftEntryCacheLog(SRaftEntryCache* pObj); -void raftEntryCacheLog2(char* s, SRaftEntryCache* pObj); - #ifdef __cplusplus } #endif diff --git a/source/libs/sync/inc/syncRaftLog.h b/source/libs/sync/inc/syncRaftLog.h index ff59189a9d6a96566e3246a5ed8fa25ca819e440..c25d4ae34e5c1033ea727e097bc82a7d2f63270c 100644 --- a/source/libs/sync/inc/syncRaftLog.h +++ b/source/libs/sync/inc/syncRaftLog.h @@ -40,25 +40,19 @@ typedef struct SSyncLogStoreData { SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode); void logStoreDestory(SSyncLogStore* pLogStore); -cJSON* logStore2Json(SSyncLogStore* pLogStore); -char* logStore2Str(SSyncLogStore* pLogStore); -cJSON* logStoreSimple2Json(SSyncLogStore* pLogStore); -char* logStoreSimple2Str(SSyncLogStore* pLogStore); SyncIndex logStoreFirstIndex(SSyncLogStore* pLogStore); SyncIndex logStoreWalCommitVer(SSyncLogStore* pLogStore); -// for debug -void logStorePrint(SSyncLogStore* pLogStore); -void logStorePrint2(char* s, SSyncLogStore* pLogStore); -void logStoreLog(SSyncLogStore* pLogStore); -void logStoreLog2(char* s, SSyncLogStore* pLogStore); - -void logStoreSimplePrint(SSyncLogStore* pLogStore); -void logStoreSimplePrint2(char* s, SSyncLogStore* pLogStore); -void logStoreSimpleLog(SSyncLogStore* pLogStore); -void logStoreSimpleLog2(char* s, SSyncLogStore* pLogStore); +SyncIndex raftLogWriteIndex(struct SSyncLogStore* pLogStore); +bool raftLogIsEmpty(struct SSyncLogStore* pLogStore); +SyncIndex raftLogBeginIndex(struct SSyncLogStore* pLogStore); +SyncIndex raftLogEndIndex(struct SSyncLogStore* pLogStore); +int32_t raftLogEntryCount(struct SSyncLogStore* pLogStore); +SyncIndex raftLogLastIndex(struct SSyncLogStore* pLogStore); +SyncTerm raftLogLastTerm(struct SSyncLogStore* pLogStore); +int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry** ppEntry); #ifdef __cplusplus } diff --git a/source/libs/sync/inc/syncRespMgr.h b/source/libs/sync/inc/syncRespMgr.h index 22e1005e5c495c6f4f17c452418d8b028d0cfffa..9026ecb66efc02f4e0e01d392063c1bdf4a5bdcb 100644 --- a/source/libs/sync/inc/syncRespMgr.h +++ b/source/libs/sync/inc/syncRespMgr.h @@ -41,13 +41,12 @@ typedef struct SSyncRespMgr { SSyncRespMgr *syncRespMgrCreate(void *data, int64_t ttl); void syncRespMgrDestroy(SSyncRespMgr *pObj); -int64_t syncRespMgrAdd(SSyncRespMgr *pObj, SRespStub *pStub); -int32_t syncRespMgrDel(SSyncRespMgr *pObj, uint64_t index); -int32_t syncRespMgrGet(SSyncRespMgr *pObj, uint64_t index, SRespStub *pStub); -int32_t syncRespMgrGetAndDel(SSyncRespMgr *pObj, uint64_t index, SRespStub *pStub); +uint64_t syncRespMgrAdd(SSyncRespMgr *pObj, const SRespStub *pStub); +int32_t syncRespMgrDel(SSyncRespMgr *pObj, uint64_t seq); +int32_t syncRespMgrGet(SSyncRespMgr *pObj, uint64_t seq, SRespStub *pStub); +int32_t syncRespMgrGetAndDel(SSyncRespMgr *pObj, uint64_t seq, SRpcHandleInfo *pInfo); void syncRespClean(SSyncRespMgr *pObj); void syncRespCleanRsp(SSyncRespMgr *pObj); -void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp); #ifdef __cplusplus } diff --git a/source/libs/sync/inc/syncSnapshot.h b/source/libs/sync/inc/syncSnapshot.h index b8b7af2dda614b9f7e53cdb64e26fc941e295472..5594fe46ed4c1071c69a1db06b8714027162be94 100644 --- a/source/libs/sync/inc/syncSnapshot.h +++ b/source/libs/sync/inc/syncSnapshot.h @@ -28,10 +28,11 @@ extern "C" { #include "syncMessage.h" #include "taosdef.h" -#define SYNC_SNAPSHOT_SEQ_INVALID -1 -#define SYNC_SNAPSHOT_SEQ_FORCE_CLOSE -2 -#define SYNC_SNAPSHOT_SEQ_BEGIN 0 -#define SYNC_SNAPSHOT_SEQ_END 0x7FFFFFFF +#define SYNC_SNAPSHOT_SEQ_INVALID -2 +#define SYNC_SNAPSHOT_SEQ_FORCE_CLOSE -3 +#define SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT -1 +#define SYNC_SNAPSHOT_SEQ_BEGIN 0 +#define SYNC_SNAPSHOT_SEQ_END 0x7FFFFFFF #define SYNC_SNAPSHOT_RETRY_MS 5000 @@ -47,26 +48,25 @@ typedef struct SSyncSnapshotSender { SSnapshot snapshot; SSyncCfg lastConfig; int64_t sendingMS; - SSyncNode *pSyncNode; - int32_t replicaIndex; SyncTerm term; - SyncTerm privateTerm; int64_t startTime; bool finish; + + // init when create + SSyncNode *pSyncNode; + int32_t replicaIndex; } SSyncSnapshotSender; SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaIndex); void snapshotSenderDestroy(SSyncSnapshotSender *pSender); bool snapshotSenderIsStart(SSyncSnapshotSender *pSender); -int32_t snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshotParam snapshotParam, SSnapshot snapshot, - void *pReader); +int32_t snapshotSenderStart(SSyncSnapshotSender *pSender); int32_t snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish); int32_t snapshotSend(SSyncSnapshotSender *pSender); int32_t snapshotReSend(SSyncSnapshotSender *pSender); cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender); char *snapshotSender2Str(SSyncSnapshotSender *pSender); -char *snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event); int32_t syncNodeStartSnapshot(SSyncNode *pSyncNode, SRaftId *pDestId); @@ -76,11 +76,13 @@ typedef struct SSyncSnapshotReceiver { int32_t ack; void *pWriter; SyncTerm term; - SyncTerm privateTerm; SSnapshotParam snapshotParam; SSnapshot snapshot; SRaftId fromId; - SSyncNode *pSyncNode; + int64_t startTime; + + // init when create + SSyncNode *pSyncNode; } SSyncSnapshotReceiver; @@ -93,7 +95,6 @@ void snapshotReceiverForceStop(SSyncSnapshotReceiver *pReceive cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver); char *snapshotReceiver2Str(SSyncSnapshotReceiver *pReceiver); -char *snapshotReceiver2SimpleStr(SSyncSnapshotReceiver *pReceiver, char *event); //--------------------------------------------------- // on message diff --git a/include/libs/sync/syncTools.h b/source/libs/sync/inc/syncTools.h similarity index 83% rename from include/libs/sync/syncTools.h rename to source/libs/sync/inc/syncTools.h index d5c015bfb2aa688bbd12fee325ac28cb4956707d..6a760ecd873b16fe944168b5238c286bcb8dc0f1 100644 --- a/include/libs/sync/syncTools.h +++ b/source/libs/sync/inc/syncTools.h @@ -20,34 +20,12 @@ extern "C" { #endif -#include "trpc.h" - // ------------------ ds ------------------- typedef struct SRaftId { SyncNodeId addr; SyncGroupId vgId; } SRaftId; -// ------------------ control ------------------- -SSyncNode* syncNodeAcquire(int64_t rid); -void syncNodeRelease(SSyncNode* pNode); - -int32_t syncGetRespRpc(int64_t rid, uint64_t index, SRpcMsg* msg); -int32_t syncGetAndDelRespRpc(int64_t rid, uint64_t index, SRpcHandleInfo* pInfo); -void syncSetMsgCb(int64_t rid, const SMsgCb* msgcb); -char* sync2SimpleStr(int64_t rid); - -// set timer ms -void setPingTimerMS(int64_t rid, int32_t pingTimerMS); -void setElectTimerMS(int64_t rid, int32_t electTimerMS); -void setHeartbeatTimerMS(int64_t rid, int32_t hbTimerMS); - -// for compatibility, the same as syncPropose -int32_t syncForwardToPeer(int64_t rid, SRpcMsg* pMsg, bool isWeak); - -// utils -const char* syncUtilState2String(ESyncState state); - // ------------------ for debug ------------------- void syncRpcMsgPrint(SRpcMsg* pMsg); void syncRpcMsgPrint2(char* s, SRpcMsg* pMsg); @@ -201,19 +179,14 @@ typedef struct SyncClientRequest { char data[]; // origin RpcMsg.pCont } SyncClientRequest; -SyncClientRequest* syncClientRequestBuild(uint32_t dataLen); -SyncClientRequest* syncClientRequestBuild2(const SRpcMsg* pOriginalRpcMsg, uint64_t seqNum, bool isWeak, - int32_t vgId); // step 1 -void syncClientRequestDestroy(SyncClientRequest* pMsg); -void syncClientRequestSerialize(const SyncClientRequest* pMsg, char* buf, uint32_t bufLen); -void syncClientRequestDeserialize(const char* buf, uint32_t len, SyncClientRequest* pMsg); -char* syncClientRequestSerialize2(const SyncClientRequest* pMsg, uint32_t* len); -SyncClientRequest* syncClientRequestDeserialize2(const char* buf, uint32_t len); -void syncClientRequest2RpcMsg(const SyncClientRequest* pMsg, SRpcMsg* pRpcMsg); // step 2 -void syncClientRequestFromRpcMsg(const SRpcMsg* pRpcMsg, SyncClientRequest* pMsg); -SyncClientRequest* syncClientRequestFromRpcMsg2(const SRpcMsg* pRpcMsg); // step 3 -cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg); -char* syncClientRequest2Str(const SyncClientRequest* pMsg); +SyncClientRequest* syncClientRequestAlloc(uint32_t dataLen); +int32_t syncClientRequestBuildFromRpcMsg(SRpcMsg* pClientRequestRpcMsg, const SRpcMsg* pOriginalRpcMsg, uint64_t seqNum, + bool isWeak, int32_t vgId); +int32_t syncClientRequestBuildFromNoopEntry(SRpcMsg* pClientRequestRpcMsg, const SSyncRaftEntry* pEntry, int32_t vgId); +void syncClientRequest2RpcMsg(const SyncClientRequest* pMsg, SRpcMsg* pRpcMsg); // step 2 +void syncClientRequestFromRpcMsg(const SRpcMsg* pRpcMsg, SyncClientRequest* pMsg); +cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg); +char* syncClientRequest2Str(const SyncClientRequest* pMsg); // for debug ---------------------- void syncClientRequestPrint(const SyncClientRequest* pMsg); @@ -404,14 +377,6 @@ SyncAppendEntriesBatch* syncAppendEntriesBatchDeserialize2(const char* buf, uint void syncAppendEntriesBatch2RpcMsg(const SyncAppendEntriesBatch* pMsg, SRpcMsg* pRpcMsg); void syncAppendEntriesBatchFromRpcMsg(const SRpcMsg* pRpcMsg, SyncAppendEntriesBatch* pMsg); SyncAppendEntriesBatch* syncAppendEntriesBatchFromRpcMsg2(const SRpcMsg* pRpcMsg); -cJSON* syncAppendEntriesBatch2Json(const SyncAppendEntriesBatch* pMsg); -char* syncAppendEntriesBatch2Str(const SyncAppendEntriesBatch* pMsg); - -// for debug ---------------------- -void syncAppendEntriesBatchPrint(const SyncAppendEntriesBatch* pMsg); -void syncAppendEntriesBatchPrint2(char* s, const SyncAppendEntriesBatch* pMsg); -void syncAppendEntriesBatchLog(const SyncAppendEntriesBatch* pMsg); -void syncAppendEntriesBatchLog2(char* s, const SyncAppendEntriesBatch* pMsg); // --------------------------------------------- typedef struct SyncAppendEntriesReply { @@ -513,6 +478,69 @@ void syncHeartbeatReplyPrint2(char* s, const SyncHeartbeatReply* pMsg); void syncHeartbeatReplyLog(const SyncHeartbeatReply* pMsg); void syncHeartbeatReplyLog2(char* s, const SyncHeartbeatReply* pMsg); +// --------------------------------------------- +typedef struct SyncPreSnapshot { + uint32_t bytes; + int32_t vgId; + uint32_t msgType; + SRaftId srcId; + SRaftId destId; + + // private data + SyncTerm term; + +} SyncPreSnapshot; + +SyncPreSnapshot* syncPreSnapshotBuild(int32_t vgId); +void syncPreSnapshotDestroy(SyncPreSnapshot* pMsg); +void syncPreSnapshotSerialize(const SyncPreSnapshot* pMsg, char* buf, uint32_t bufLen); +void syncPreSnapshotDeserialize(const char* buf, uint32_t len, SyncPreSnapshot* pMsg); +char* syncPreSnapshotSerialize2(const SyncPreSnapshot* pMsg, uint32_t* len); +SyncPreSnapshot* syncPreSnapshotDeserialize2(const char* buf, uint32_t len); +void syncPreSnapshot2RpcMsg(const SyncPreSnapshot* pMsg, SRpcMsg* pRpcMsg); +void syncPreSnapshotFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPreSnapshot* pMsg); +SyncPreSnapshot* syncPreSnapshotFromRpcMsg2(const SRpcMsg* pRpcMsg); +cJSON* syncPreSnapshot2Json(const SyncPreSnapshot* pMsg); +char* syncPreSnapshot2Str(const SyncPreSnapshot* pMsg); + +// for debug ---------------------- +void syncPreSnapshotPrint(const SyncPreSnapshot* pMsg); +void syncPreSnapshotPrint2(char* s, const SyncPreSnapshot* pMsg); +void syncPreSnapshotLog(const SyncPreSnapshot* pMsg); +void syncPreSnapshotLog2(char* s, const SyncPreSnapshot* pMsg); + +// --------------------------------------------- +typedef struct SyncPreSnapshotReply { + uint32_t bytes; + int32_t vgId; + uint32_t msgType; + SRaftId srcId; + SRaftId destId; + + // private data + SyncTerm term; + SyncIndex snapStart; + +} SyncPreSnapshotReply; + +SyncPreSnapshotReply* syncPreSnapshotReplyBuild(int32_t vgId); +void syncPreSnapshotReplyDestroy(SyncPreSnapshotReply* pMsg); +void syncPreSnapshotReplySerialize(const SyncPreSnapshotReply* pMsg, char* buf, uint32_t bufLen); +void syncPreSnapshotReplyDeserialize(const char* buf, uint32_t len, SyncPreSnapshotReply* pMsg); +char* syncPreSnapshotReplySerialize2(const SyncPreSnapshotReply* pMsg, uint32_t* len); +SyncPreSnapshotReply* syncPreSnapshotReplyDeserialize2(const char* buf, uint32_t len); +void syncPreSnapshotReply2RpcMsg(const SyncPreSnapshotReply* pMsg, SRpcMsg* pRpcMsg); +void syncPreSnapshotReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPreSnapshotReply* pMsg); +SyncPreSnapshotReply* syncPreSnapshotReplyFromRpcMsg2(const SRpcMsg* pRpcMsg); +cJSON* syncPreSnapshotReply2Json(const SyncPreSnapshotReply* pMsg); +char* syncPreSnapshotReply2Str(const SyncPreSnapshotReply* pMsg); + +// for debug ---------------------- +void syncPreSnapshotReplyPrint(const SyncPreSnapshotReply* pMsg); +void syncPreSnapshotReplyPrint2(char* s, const SyncPreSnapshotReply* pMsg); +void syncPreSnapshotReplyLog(const SyncPreSnapshotReply* pMsg); +void syncPreSnapshotReplyLog2(char* s, const SyncPreSnapshotReply* pMsg); + // --------------------------------------------- typedef struct SyncApplyMsg { uint32_t bytes; @@ -558,7 +586,7 @@ typedef struct SyncSnapshotSend { SyncTerm lastTerm; // snapshot.lastTerm SyncIndex lastConfigIndex; // snapshot.lastConfigIndex SSyncCfg lastConfig; - SyncTerm privateTerm; + int64_t startTime; int32_t seq; uint32_t dataLen; char data[]; @@ -593,9 +621,10 @@ typedef struct SyncSnapshotRsp { SyncTerm term; SyncIndex lastIndex; SyncTerm lastTerm; - SyncTerm privateTerm; + int64_t startTime; int32_t ack; int32_t code; + SyncIndex snapBeginIndex; // when ack = SYNC_SNAPSHOT_SEQ_BEGIN, it's valid } SyncSnapshotRsp; SyncSnapshotRsp* syncSnapshotRspBuild(int32_t vgId); @@ -641,65 +670,71 @@ SyncLeaderTransfer* syncLeaderTransferFromRpcMsg2(const SRpcMsg* pRpcMsg); cJSON* syncLeaderTransfer2Json(const SyncLeaderTransfer* pMsg); char* syncLeaderTransfer2Str(const SyncLeaderTransfer* pMsg); -// for debug ---------------------- -void syncLeaderTransferPrint(const SyncLeaderTransfer* pMsg); -void syncLeaderTransferPrint2(char* s, const SyncLeaderTransfer* pMsg); -void syncLeaderTransferLog(const SyncLeaderTransfer* pMsg); -void syncLeaderTransferLog2(char* s, const SyncLeaderTransfer* pMsg); +typedef enum { + SYNC_LOCAL_CMD_STEP_DOWN = 100, + SYNC_LOCAL_CMD_FOLLOWER_CMT, +} ESyncLocalCmd; -// --------------------------------------------- -typedef struct SyncReconfigFinish { - uint32_t bytes; - int32_t vgId; - uint32_t msgType; - SSyncCfg oldCfg; - SSyncCfg newCfg; - SyncIndex newCfgIndex; - SyncTerm newCfgTerm; - uint64_t newCfgSeqNum; - -} SyncReconfigFinish; - -SyncReconfigFinish* syncReconfigFinishBuild(int32_t vgId); -void syncReconfigFinishDestroy(SyncReconfigFinish* pMsg); -void syncReconfigFinishSerialize(const SyncReconfigFinish* pMsg, char* buf, uint32_t bufLen); -void syncReconfigFinishDeserialize(const char* buf, uint32_t len, SyncReconfigFinish* pMsg); -char* syncReconfigFinishSerialize2(const SyncReconfigFinish* pMsg, uint32_t* len); -SyncReconfigFinish* syncReconfigFinishDeserialize2(const char* buf, uint32_t len); -void syncReconfigFinish2RpcMsg(const SyncReconfigFinish* pMsg, SRpcMsg* pRpcMsg); -void syncReconfigFinishFromRpcMsg(const SRpcMsg* pRpcMsg, SyncReconfigFinish* pMsg); -SyncReconfigFinish* syncReconfigFinishFromRpcMsg2(const SRpcMsg* pRpcMsg); -cJSON* syncReconfigFinish2Json(const SyncReconfigFinish* pMsg); -char* syncReconfigFinish2Str(const SyncReconfigFinish* pMsg); +const char* syncLocalCmdGetStr(int32_t cmd); + +typedef struct SyncLocalCmd { + uint32_t bytes; + int32_t vgId; + uint32_t msgType; + SRaftId srcId; + SRaftId destId; + + int32_t cmd; + SyncTerm sdNewTerm; // step down new term + SyncIndex fcIndex;// follower commit index + +} SyncLocalCmd; + +SyncLocalCmd* syncLocalCmdBuild(int32_t vgId); +void syncLocalCmdDestroy(SyncLocalCmd* pMsg); +void syncLocalCmdSerialize(const SyncLocalCmd* pMsg, char* buf, uint32_t bufLen); +void syncLocalCmdDeserialize(const char* buf, uint32_t len, SyncLocalCmd* pMsg); +char* syncLocalCmdSerialize2(const SyncLocalCmd* pMsg, uint32_t* len); +SyncLocalCmd* syncLocalCmdDeserialize2(const char* buf, uint32_t len); +void syncLocalCmd2RpcMsg(const SyncLocalCmd* pMsg, SRpcMsg* pRpcMsg); +void syncLocalCmdFromRpcMsg(const SRpcMsg* pRpcMsg, SyncLocalCmd* pMsg); +SyncLocalCmd* syncLocalCmdFromRpcMsg2(const SRpcMsg* pRpcMsg); +cJSON* syncLocalCmd2Json(const SyncLocalCmd* pMsg); +char* syncLocalCmd2Str(const SyncLocalCmd* pMsg); // for debug ---------------------- -void syncReconfigFinishPrint(const SyncReconfigFinish* pMsg); -void syncReconfigFinishPrint2(char* s, const SyncReconfigFinish* pMsg); -void syncReconfigFinishLog(const SyncReconfigFinish* pMsg); -void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg); +void syncLocalCmdPrint(const SyncLocalCmd* pMsg); +void syncLocalCmdPrint2(char* s, const SyncLocalCmd* pMsg); +void syncLocalCmdLog(const SyncLocalCmd* pMsg); +void syncLocalCmdLog2(char* s, const SyncLocalCmd* pMsg); // on message ---------------------- -int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg); -int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg); -int32_t syncNodeOnTimer(SSyncNode* ths, SyncTimeout* pMsg); +int32_t syncNodeOnPing(SSyncNode* ths, SyncPing* pMsg); +int32_t syncNodeOnPingReply(SSyncNode* ths, SyncPingReply* pMsg); -int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg); -int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, SyncHeartbeatReply* pMsg); -int32_t syncNodeOnClientRequest(SSyncNode* ths, SyncClientRequest* pMsg, SyncIndex* pRetIndex); int32_t syncNodeOnRequestVote(SSyncNode* ths, SyncRequestVote* pMsg); int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, SyncRequestVoteReply* pMsg); + int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg); int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, SyncAppendEntriesReply* pMsg); + +int32_t syncNodeOnPreSnapshot(SSyncNode* ths, SyncPreSnapshot* pMsg); +int32_t syncNodeOnPreSnapshotReply(SSyncNode* ths, SyncPreSnapshotReply* pMsg); + int32_t syncNodeOnSnapshot(SSyncNode* ths, SyncSnapshotSend* pMsg); int32_t syncNodeOnSnapshotReply(SSyncNode* ths, SyncSnapshotRsp* pMsg); int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg); int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, SyncHeartbeatReply* pMsg); +int32_t syncNodeOnClientRequest(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRetIndex); +int32_t syncNodeOnTimer(SSyncNode* ths, SyncTimeout* pMsg); +int32_t syncNodeOnLocalCmd(SSyncNode* ths, SyncLocalCmd* pMsg); + // ----------------------------------------- typedef int32_t (*FpOnPingCb)(SSyncNode* ths, SyncPing* pMsg); typedef int32_t (*FpOnPingReplyCb)(SSyncNode* ths, SyncPingReply* pMsg); -typedef int32_t (*FpOnClientRequestCb)(SSyncNode* ths, SyncClientRequest* pMsg, SyncIndex* pRetIndex); +typedef int32_t (*FpOnClientRequestCb)(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRetIndex); typedef int32_t (*FpOnRequestVoteCb)(SSyncNode* ths, SyncRequestVote* pMsg); typedef int32_t (*FpOnRequestVoteReplyCb)(SSyncNode* ths, SyncRequestVoteReply* pMsg); typedef int32_t (*FpOnAppendEntriesCb)(SSyncNode* ths, SyncAppendEntries* pMsg); diff --git a/source/libs/sync/inc/syncUtil.h b/source/libs/sync/inc/syncUtil.h index 96e22720e8b2b0fb4defc5d5b46e8d765fc54efb..7f241e827daa99d5f26c9de832d4f6504ab04e7c 100644 --- a/source/libs/sync/inc/syncUtil.h +++ b/source/libs/sync/inc/syncUtil.h @@ -20,48 +20,35 @@ extern "C" { #endif -#include -#include -#include #include "syncInt.h" -#include "syncMessage.h" -#include "taosdef.h" -// ---- encode / decode uint64_t syncUtilAddr2U64(const char* host, uint16_t port); -void syncUtilU642Addr(uint64_t u64, char* host, size_t len, uint16_t* port); -void syncUtilnodeInfo2EpSet(const SNodeInfo* pNodeInfo, SEpSet* pEpSet); +void syncUtilU642Addr(uint64_t u64, char* host, int64_t len, uint16_t* port); +void syncUtilnodeInfo2EpSet(const SNodeInfo* pInfo, SEpSet* pEpSet); void syncUtilraftId2EpSet(const SRaftId* raftId, SEpSet* pEpSet); -bool syncUtilnodeInfo2raftId(const SNodeInfo* pNodeInfo, SyncGroupId vgId, SRaftId* raftId); +bool syncUtilnodeInfo2raftId(const SNodeInfo* pInfo, SyncGroupId vgId, SRaftId* raftId); bool syncUtilSameId(const SRaftId* pId1, const SRaftId* pId2); bool syncUtilEmptyId(const SRaftId* pId); -// ---- SSyncBuffer ---- -void syncUtilbufBuild(SSyncBuffer* syncBuf, size_t len); -void syncUtilbufDestroy(SSyncBuffer* syncBuf); -void syncUtilbufCopy(const SSyncBuffer* src, SSyncBuffer* dest); -void syncUtilbufCopyDeep(const SSyncBuffer* src, SSyncBuffer* dest); - -// ---- misc ---- -int32_t syncUtilRand(int32_t max); int32_t syncUtilElectRandomMS(int32_t min, int32_t max); int32_t syncUtilQuorum(int32_t replicaNum); cJSON* syncUtilNodeInfo2Json(const SNodeInfo* p); cJSON* syncUtilRaftId2Json(const SRaftId* p); char* syncUtilRaftId2Str(const SRaftId* p); -const char* syncUtilState2String(ESyncState state); -bool syncUtilCanPrint(char c); -char* syncUtilprintBin(char* ptr, uint32_t len); -char* syncUtilprintBin2(char* ptr, uint32_t len); -SyncIndex syncUtilMinIndex(SyncIndex a, SyncIndex b); -SyncIndex syncUtilMaxIndex(SyncIndex a, SyncIndex b); +const char* syncStr(ESyncState state); +char* syncUtilPrintBin(char* ptr, uint32_t len); +char* syncUtilPrintBin2(char* ptr, uint32_t len); void syncUtilMsgHtoN(void* msg); void syncUtilMsgNtoH(void* msg); -bool syncUtilIsData(tmsg_t msgType); bool syncUtilUserPreCommit(tmsg_t msgType); bool syncUtilUserCommit(tmsg_t msgType); bool syncUtilUserRollback(tmsg_t msgType); -void syncUtilJson2Line(char* jsonStr); + +void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNode* pNode, const char* format, ...); +void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotSender* pSender, + const char* format, ...); +void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotReceiver* pReceiver, + const char* format, ...); #ifdef __cplusplus } diff --git a/source/libs/sync/inc/syncVoteMgr.h b/source/libs/sync/inc/syncVoteMgr.h index aa245ce32c20a02ea450581daed949076704e446..d894e91600349bf0bf2bd506cf3369771f6cebce 100644 --- a/source/libs/sync/inc/syncVoteMgr.h +++ b/source/libs/sync/inc/syncVoteMgr.h @@ -20,15 +20,8 @@ extern "C" { #endif -#include -#include -#include #include "syncInt.h" -#include "syncMessage.h" -#include "syncUtil.h" -#include "taosdef.h" -// SVotesGranted ----------------------------- typedef struct SVotesGranted { SRaftId (*replicas)[TSDB_MAX_REPLICA]; bool isGranted[TSDB_MAX_REPLICA]; @@ -49,13 +42,6 @@ void voteGrantedReset(SVotesGranted *pVotesGranted, SyncTerm term); cJSON *voteGranted2Json(SVotesGranted *pVotesGranted); char *voteGranted2Str(SVotesGranted *pVotesGranted); -// for debug ------------------- -void voteGrantedPrint(SVotesGranted *pObj); -void voteGrantedPrint2(char *s, SVotesGranted *pObj); -void voteGrantedLog(SVotesGranted *pObj); -void voteGrantedLog2(char *s, SVotesGranted *pObj); - -// SVotesRespond ----------------------------- typedef struct SVotesRespond { SRaftId (*replicas)[TSDB_MAX_REPLICA]; bool isRespond[TSDB_MAX_REPLICA]; @@ -73,12 +59,6 @@ void votesRespondReset(SVotesRespond *pVotesRespond, SyncTerm term); cJSON *votesRespond2Json(SVotesRespond *pVotesRespond); char *votesRespond2Str(SVotesRespond *pVotesRespond); -// for debug ------------------- -void votesRespondPrint(SVotesRespond *pObj); -void votesRespondPrint2(char *s, SVotesRespond *pObj); -void votesRespondLog(SVotesRespond *pObj); -void votesRespondLog2(char *s, SVotesRespond *pObj); - #ifdef __cplusplus } #endif diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index 80e0cbbf99fe30706a3d8a84dc5b177ea1e6c1dd..792ce67cd4c9be0eef09fe6b11ba0857ffb92f1d 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -89,189 +89,12 @@ // /\ UNCHANGED <> // -static int32_t syncNodeMakeLogSame(SSyncNode* ths, SyncAppendEntries* pMsg) { - int32_t code; - - SyncIndex delBegin = pMsg->prevLogIndex + 1; - SyncIndex delEnd = ths->pLogStore->syncLogLastIndex(ths->pLogStore); - - // invert roll back! - for (SyncIndex index = delEnd; index >= delBegin; --index) { - if (ths->pFsm->FpRollBackCb != NULL) { - SSyncRaftEntry* pRollBackEntry; - code = ths->pLogStore->syncLogGetEntry(ths->pLogStore, index, &pRollBackEntry); - ASSERT(code == 0); - ASSERT(pRollBackEntry != NULL); - - if (syncUtilUserRollback(pRollBackEntry->msgType)) { - SRpcMsg rpcMsg; - syncEntry2OriginalRpc(pRollBackEntry, &rpcMsg); - - SFsmCbMeta cbMeta = {0}; - cbMeta.index = pRollBackEntry->index; - cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, cbMeta.index); - cbMeta.isWeak = pRollBackEntry->isWeak; - cbMeta.code = 0; - cbMeta.state = ths->state; - cbMeta.seqNum = pRollBackEntry->seqNum; - ths->pFsm->FpRollBackCb(ths->pFsm, &rpcMsg, cbMeta); - rpcFreeCont(rpcMsg.pCont); - } - - syncEntryDestory(pRollBackEntry); - } - } - - // delete confict entries - code = ths->pLogStore->syncLogTruncate(ths->pLogStore, delBegin); - ASSERT(code == 0); - - return code; -} - -// if FromIndex > walCommitVer, return 0 -// else return num of pass entries -static int32_t syncNodeDoMakeLogSame(SSyncNode* ths, SyncIndex FromIndex) { - int32_t code = 0; - int32_t pass = 0; - - SyncIndex delBegin = FromIndex; - SyncIndex delEnd = ths->pLogStore->syncLogLastIndex(ths->pLogStore); - - // invert roll back! - for (SyncIndex index = delEnd; index >= delBegin; --index) { - if (ths->pFsm->FpRollBackCb != NULL) { - SSyncRaftEntry* pRollBackEntry; - code = ths->pLogStore->syncLogGetEntry(ths->pLogStore, index, &pRollBackEntry); - ASSERT(code == 0); - ASSERT(pRollBackEntry != NULL); - - if (syncUtilUserRollback(pRollBackEntry->msgType)) { - SRpcMsg rpcMsg; - syncEntry2OriginalRpc(pRollBackEntry, &rpcMsg); - - SFsmCbMeta cbMeta = {0}; - cbMeta.index = pRollBackEntry->index; - cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, cbMeta.index); - cbMeta.isWeak = pRollBackEntry->isWeak; - cbMeta.code = 0; - cbMeta.state = ths->state; - cbMeta.seqNum = pRollBackEntry->seqNum; - ths->pFsm->FpRollBackCb(ths->pFsm, &rpcMsg, cbMeta); - rpcFreeCont(rpcMsg.pCont); - } - - syncEntryDestory(pRollBackEntry); - } - } - - // update delete begin - SyncIndex walCommitVer = logStoreWalCommitVer(ths->pLogStore); - - if (delBegin <= walCommitVer) { - delBegin = walCommitVer + 1; - pass = walCommitVer - delBegin + 1; - - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "update delete begin to %" PRId64, delBegin); - syncNodeEventLog(ths, logBuf); - } while (0); - } - - // delete confict entries - code = ths->pLogStore->syncLogTruncate(ths->pLogStore, delBegin); - ASSERT(code == 0); - - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "make log same from:%" PRId64 ", delbegin:%" PRId64 ", pass:%d", FromIndex, - delBegin, pass); - syncNodeEventLog(ths, logBuf); - } while (0); - - return pass; -} - -int32_t syncNodePreCommit(SSyncNode* ths, SSyncRaftEntry* pEntry, int32_t code) { - SRpcMsg rpcMsg; - syncEntry2OriginalRpc(pEntry, &rpcMsg); - - // leader transfer - if (pEntry->originalRpcType == TDMT_SYNC_LEADER_TRANSFER) { - int32_t code = syncDoLeaderTransfer(ths, &rpcMsg, pEntry); - ASSERT(code == 0); - } - - if (ths->pFsm != NULL) { - if (ths->pFsm->FpPreCommitCb != NULL && syncUtilUserPreCommit(pEntry->originalRpcType)) { - SFsmCbMeta cbMeta = {0}; - cbMeta.index = pEntry->index; - cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, cbMeta.index); - cbMeta.isWeak = pEntry->isWeak; - cbMeta.code = code; - cbMeta.state = ths->state; - cbMeta.seqNum = pEntry->seqNum; - ths->pFsm->FpPreCommitCb(ths->pFsm, &rpcMsg, cbMeta); - } - } - rpcFreeCont(rpcMsg.pCont); - return 0; -} - -static bool syncNodeOnAppendEntriesBatchLogOK(SSyncNode* pSyncNode, SyncAppendEntriesBatch* pMsg) { - if (pMsg->prevLogIndex == SYNC_INDEX_INVALID) { - return true; - } - - SyncIndex myLastIndex = syncNodeGetLastIndex(pSyncNode); - if (pMsg->prevLogIndex > myLastIndex) { - sDebug("vgId:%d, sync log not ok, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); - return false; - } - - SyncTerm myPreLogTerm = syncNodeGetPreTerm(pSyncNode, pMsg->prevLogIndex + 1); - if (myPreLogTerm == SYNC_TERM_INVALID) { - sDebug("vgId:%d, sync log not ok2, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); - return false; - } - - if (pMsg->prevLogIndex <= myLastIndex && pMsg->prevLogTerm == myPreLogTerm) { - return true; - } - - sDebug("vgId:%d, sync log not ok3, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); - return false; -} - -// really pre log match -// prevLogIndex == -1 -static bool syncNodeOnAppendEntriesLogOK(SSyncNode* pSyncNode, SyncAppendEntries* pMsg) { - if (pMsg->prevLogIndex == SYNC_INDEX_INVALID) { - return true; - } - - SyncIndex myLastIndex = syncNodeGetLastIndex(pSyncNode); - if (pMsg->prevLogIndex > myLastIndex) { - sDebug("vgId:%d, sync log not ok, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); - return false; - } - - SyncTerm myPreLogTerm = syncNodeGetPreTerm(pSyncNode, pMsg->prevLogIndex + 1); - if (myPreLogTerm == SYNC_TERM_INVALID) { - sDebug("vgId:%d, sync log not ok2, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); - return false; - } - - if (pMsg->prevLogIndex <= myLastIndex && pMsg->prevLogTerm == myPreLogTerm) { - return true; +int32_t syncNodeFollowerCommit(SSyncNode* ths, SyncIndex newCommitIndex) { + if (ths->state != TAOS_SYNC_STATE_FOLLOWER) { + sNTrace(ths, "can not do follower commit"); + return -1; } - sDebug("vgId:%d, sync log not ok3, preindex:%" PRId64, pSyncNode->vgId, pMsg->prevLogIndex); - return false; -} - -int32_t syncNodeFollowerCommit(SSyncNode* ths, SyncIndex newCommitIndex) { // maybe update commit index, leader notice me if (newCommitIndex > ths->commitIndex) { // has commit entry in local @@ -283,11 +106,7 @@ int32_t syncNodeFollowerCommit(SSyncNode* ths, SyncIndex newCommitIndex) { SyncIndex commitBegin = ths->commitIndex; SyncIndex commitEnd = snapshot.lastApplyIndex; ths->commitIndex = snapshot.lastApplyIndex; - - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "commit by snapshot from index:%" PRId64 " to index:%" PRId64, commitBegin, - commitEnd); - syncNodeEventLog(ths, eventLog); + sNTrace(ths, "commit by snapshot from index:%" PRId64 " to index:%" PRId64, commitBegin, commitEnd); } SyncIndex beginIndex = ths->commitIndex + 1; @@ -324,7 +143,6 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) { // pReply->matchIndex = ths->pLogStore->syncLogLastIndex(ths->pLogStore); pReply->matchIndex = SYNC_INDEX_INVALID; pReply->lastSendIndex = pMsg->prevLogIndex + 1; - pReply->privateTerm = ths->pNewNodeReceiver->privateTerm; pReply->startTime = ths->startTime; if (pMsg->term < ths->pRaftStore->currentTerm) { @@ -361,7 +179,7 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) { pReply->success = true; bool hasAppendEntries = pMsg->dataLen > 0; if (hasAppendEntries) { - SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen); + SSyncRaftEntry* pAppendEntry = syncEntryBuildFromAppendEntries(pMsg); ASSERT(pAppendEntry != NULL); SyncIndex appendIndex = pMsg->prevLogIndex + 1; @@ -370,11 +188,7 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) { if (code == 0) { if (pLocalEntry->term == pAppendEntry->term) { // do nothing - - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "log match, do nothing, index:%" PRId64, appendIndex); - syncNodeEventLog(ths, logBuf); - + sNTrace(ths, "log match, do nothing, index:%" PRId64, appendIndex); } else { // truncate code = ths->pLogStore->syncLogTruncate(ths->pLogStore, appendIndex); @@ -432,7 +246,8 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) { } else { // error char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "ignore, get local entry error, append-index:%" PRId64, appendIndex); + snprintf(logBuf, sizeof(logBuf), "ignore, get local entry error, append-index:%" PRId64 " err:%d", appendIndex, + terrno); syncLogRecvAppendEntries(ths, pMsg, logBuf); syncEntryDestory(pLocalEntry); diff --git a/source/libs/sync/src/syncAppendEntriesReply.c b/source/libs/sync/src/syncAppendEntriesReply.c index 5e6c9f153422cf9e6f3baeaec8cf93ca8f0339ab..cf7c391a1d6c69b358b193666c7edc2d7f434fab 100644 --- a/source/libs/sync/src/syncAppendEntriesReply.c +++ b/source/libs/sync/src/syncAppendEntriesReply.c @@ -43,12 +43,7 @@ static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, SyncTerm lastApplyTerm, SyncAppendEntriesReply* pMsg) { if (beginIndex > endIndex) { - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "snapshot param error, start:%" PRId64 ", end:%" PRId64, beginIndex, endIndex); - syncNodeErrorLog(ths, logBuf); - } while (0); - + sNError(ths, "snapshot param error, start:%" PRId64 ", end:%" PRId64, beginIndex, endIndex); return; } @@ -57,12 +52,7 @@ static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, Sync ASSERT(pSender != NULL); if (snapshotSenderIsStart(pSender)) { - do { - char* eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender already start"); - syncNodeErrorLog(ths, eventLog); - taosMemoryFree(eventLog); - } while (0); - + sSError(pSender, "snapshot sender already start"); return; } @@ -73,6 +63,7 @@ static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, Sync int32_t code = ths->pFsm->FpSnapshotStartRead(ths->pFsm, &readerParam, &pReader); ASSERT(code == 0); +#if 0 if (pMsg->privateTerm < pSender->privateTerm) { ASSERT(pReader != NULL); snapshotSenderStart(pSender, readerParam, snapshot, pReader); @@ -82,6 +73,7 @@ static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, Sync ths->pFsm->FpSnapshotStopRead(ths->pFsm, pReader); } } +#endif } int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, SyncAppendEntriesReply* pMsg) { diff --git a/source/libs/sync/src/syncCommit.c b/source/libs/sync/src/syncCommit.c index 3aeb2d30b54552040bb47b19f6cc66ef24838964..a951b78e1ea44cbcad16e12739c6006e33d2c7e1 100644 --- a/source/libs/sync/src/syncCommit.c +++ b/source/libs/sync/src/syncCommit.c @@ -44,6 +44,46 @@ // IN commitIndex' = [commitIndex EXCEPT ![i] = newCommitIndex] // /\ UNCHANGED <> // +void syncOneReplicaAdvance(SSyncNode* pSyncNode) { + if (pSyncNode == NULL) { + sError("pSyncNode is NULL"); + return; + } + + if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) { + sNError(pSyncNode, "not leader, can not advance commit index"); + return; + } + + if (pSyncNode->replicaNum != 1) { + sNError(pSyncNode, "not one replica, can not advance commit index"); + return; + } + + // advance commit index to snapshot first + SSnapshot snapshot; + pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); + if (snapshot.lastApplyIndex > 0 && snapshot.lastApplyIndex > pSyncNode->commitIndex) { + SyncIndex commitBegin = pSyncNode->commitIndex; + SyncIndex commitEnd = snapshot.lastApplyIndex; + pSyncNode->commitIndex = snapshot.lastApplyIndex; + sNTrace(pSyncNode, "commit by snapshot from index:%" PRId64 " to index:%" PRId64, commitBegin, commitEnd); + } + + // advance commit index as large as possible + SyncIndex lastIndex = syncNodeGetLastIndex(pSyncNode); + if (lastIndex > pSyncNode->commitIndex) { + sNTrace(pSyncNode, "commit by wal from index:%" PRId64 " to index:%" PRId64, pSyncNode->commitIndex + 1, lastIndex); + pSyncNode->commitIndex = lastIndex; + } + + // call back Wal + SyncIndex walCommitVer = logStoreWalCommitVer(pSyncNode->pLogStore); + if (pSyncNode->commitIndex > walCommitVer) { + pSyncNode->pLogStore->syncLogUpdateCommitIndex(pSyncNode->pLogStore, pSyncNode->commitIndex); + } +} + void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { if (pSyncNode == NULL) { sError("pSyncNode is NULL"); @@ -51,7 +91,7 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { } if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) { - syncNodeErrorLog(pSyncNode, "not leader, can not advance commit index"); + sNError(pSyncNode, "not leader, can not advance commit index"); return; } @@ -62,11 +102,7 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { SyncIndex commitBegin = pSyncNode->commitIndex; SyncIndex commitEnd = snapshot.lastApplyIndex; pSyncNode->commitIndex = snapshot.lastApplyIndex; - - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "commit by snapshot from index:%" PRId64 " to index:%" PRId64, commitBegin, - commitEnd); - syncNodeEventLog(pSyncNode, eventLog); + sNTrace(pSyncNode, "commit by snapshot from index:%" PRId64 " to index:%" PRId64, commitBegin, commitEnd); } // update commit index @@ -84,9 +120,7 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { } else { int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, index, &pEntry); if (code != 0) { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "advance commit index error, read wal index:%" PRId64, index); - syncNodeErrorLog(pSyncNode, logBuf); + sNError(pSyncNode, "advance commit index error, read wal index:%" PRId64, index); return; } } @@ -103,12 +137,8 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { break; } else { - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "can not commit due to term not equal, index:%" PRId64 ", term:%" PRIu64, - pEntry->index, pEntry->term); - syncNodeEventLog(pSyncNode, logBuf); - } while (0); + sNTrace(pSyncNode, "can not commit due to term not equal, index:%" PRId64 ", term:%" PRIu64, pEntry->index, + pEntry->term); } if (h) { @@ -140,10 +170,8 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { if (pSyncNode->pFsm != NULL) { int32_t code = syncNodeDoCommit(pSyncNode, beginIndex, endIndex, pSyncNode->state); if (code != 0) { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "advance commit index error, do commit begin:%" PRId64 ", end:%" PRId64, - beginIndex, endIndex); - syncNodeErrorLog(pSyncNode, logBuf); + sNError(pSyncNode, "advance commit index error, do commit begin:%" PRId64 ", end:%" PRId64, beginIndex, + endIndex); return; } } diff --git a/source/libs/sync/src/syncElection.c b/source/libs/sync/src/syncElection.c index b428f4d2f2b3844f446f0ad9a0dde4fd3175f0f1..85e45728775b57b674a2f11a6feb72580e9f279f 100644 --- a/source/libs/sync/src/syncElection.c +++ b/source/libs/sync/src/syncElection.c @@ -13,11 +13,13 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE #include "syncElection.h" #include "syncMessage.h" #include "syncRaftCfg.h" #include "syncRaftStore.h" #include "syncVoteMgr.h" +#include "syncUtil.h" // TLA+ Spec // RequestVote(i, j) == @@ -32,7 +34,7 @@ // /\ UNCHANGED <> int32_t syncNodeElect(SSyncNode* pSyncNode) { - syncNodeEventLog(pSyncNode, "begin election"); + sNTrace(pSyncNode, "begin election"); int32_t ret = 0; if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) { @@ -40,7 +42,7 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) { } if (pSyncNode->state != TAOS_SYNC_STATE_CANDIDATE) { - syncNodeErrorLog(pSyncNode, "not candidate, can not elect"); + sNError(pSyncNode, "not candidate, can not elect"); return -1; } @@ -82,7 +84,7 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) { int32_t syncNodeRequestVotePeers(SSyncNode* pSyncNode) { if (pSyncNode->state != TAOS_SYNC_STATE_CANDIDATE) { - syncNodeEventLog(pSyncNode, "not candidate, stop elect"); + sNTrace(pSyncNode, "not candidate, stop elect"); return 0; } diff --git a/source/libs/sync/src/syncEnv.c b/source/libs/sync/src/syncEnv.c index fb0bfb8bef318c2f8d2d53f12cfabcfa4fb30ef2..3f3b794f46cb5c3b82b7d5476f400b71aa066c8e 100644 --- a/source/libs/sync/src/syncEnv.c +++ b/source/libs/sync/src/syncEnv.c @@ -13,118 +13,112 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE #include "syncEnv.h" -// #include +#include "tref.h" -SSyncEnv *gSyncEnv = NULL; +static SSyncEnv gSyncEnv = {0}; +static int32_t gNodeRefId = -1; +bool gRaftDetailLog = false; +static void syncEnvTick(void *param, void *tmrId); -// local function ----------------- -static SSyncEnv *doSyncEnvStart(); -static int32_t doSyncEnvStop(SSyncEnv *pSyncEnv); -static int32_t doSyncEnvStartTimer(SSyncEnv *pSyncEnv); -static int32_t doSyncEnvStopTimer(SSyncEnv *pSyncEnv); -static void syncEnvTick(void *param, void *tmrId); -// -------------------------------- +SSyncEnv *syncEnv() { return &gSyncEnv; } -bool syncEnvIsStart() { - if (gSyncEnv == NULL) { - return false; - } +bool syncIsInit() { return atomic_load_8(&gSyncEnv.isStart); } - return atomic_load_8(&(gSyncEnv->isStart)); -} +int32_t syncInit() { + if (syncIsInit()) return 0; -int32_t syncEnvStart() { - int32_t ret = 0; uint32_t seed = (uint32_t)(taosGetTimestampNs() & 0x00000000FFFFFFFF); taosSeedRand(seed); - // gSyncEnv = doSyncEnvStart(gSyncEnv); - gSyncEnv = doSyncEnvStart(); - ASSERT(gSyncEnv != NULL); - sTrace("sync env start ok"); - return ret; -} -int32_t syncEnvStop() { - int32_t ret = doSyncEnvStop(gSyncEnv); - return ret; -} + memset(&gSyncEnv, 0, sizeof(SSyncEnv)); + gSyncEnv.envTickTimerCounter = 0; + gSyncEnv.envTickTimerMS = ENV_TICK_TIMER_MS; + gSyncEnv.FpEnvTickTimer = syncEnvTick; + atomic_store_64(&gSyncEnv.envTickTimerLogicClock, 0); + atomic_store_64(&gSyncEnv.envTickTimerLogicClockUser, 0); -int32_t syncEnvStartTimer() { - int32_t ret = doSyncEnvStartTimer(gSyncEnv); - return ret; -} + // start tmr thread + gSyncEnv.pTimerManager = taosTmrInit(1000, 50, 10000, "SYNC-ENV"); + atomic_store_8(&gSyncEnv.isStart, 1); + + gNodeRefId = taosOpenRef(200, (RefFp)syncNodeClose); + if (gNodeRefId < 0) { + sError("failed to init node ref"); + syncCleanUp(); + return -1; + } -int32_t syncEnvStopTimer() { - int32_t ret = doSyncEnvStopTimer(gSyncEnv); - return ret; + sDebug("sync rsetId:%d is open", gNodeRefId); + return 0; } -// local function ----------------- -static void syncEnvTick(void *param, void *tmrId) { - SSyncEnv *pSyncEnv = (SSyncEnv *)param; - if (atomic_load_64(&pSyncEnv->envTickTimerLogicClockUser) <= atomic_load_64(&pSyncEnv->envTickTimerLogicClock)) { - ++(pSyncEnv->envTickTimerCounter); - sTrace("syncEnvTick do ... envTickTimerLogicClockUser:%" PRIu64 ", envTickTimerLogicClock:%" PRIu64 - ", envTickTimerCounter:%" PRIu64 - ", " - "envTickTimerMS:%d, tmrId:%p", - pSyncEnv->envTickTimerLogicClockUser, pSyncEnv->envTickTimerLogicClock, pSyncEnv->envTickTimerCounter, - pSyncEnv->envTickTimerMS, tmrId); +void syncCleanUp() { + atomic_store_8(&gSyncEnv.isStart, 0); + taosTmrCleanUp(gSyncEnv.pTimerManager); + memset(&gSyncEnv, 0, sizeof(SSyncEnv)); - // do something, tick ... - taosTmrReset(syncEnvTick, pSyncEnv->envTickTimerMS, pSyncEnv, pSyncEnv->pTimerManager, &pSyncEnv->pEnvTickTimer); - } else { - sTrace("syncEnvTick pass ... envTickTimerLogicClockUser:%" PRIu64 ", envTickTimerLogicClock:%" PRIu64 - ", envTickTimerCounter:%" PRIu64 - ", " - "envTickTimerMS:%d, tmrId:%p", - pSyncEnv->envTickTimerLogicClockUser, pSyncEnv->envTickTimerLogicClock, pSyncEnv->envTickTimerCounter, - pSyncEnv->envTickTimerMS, tmrId); + if (gNodeRefId != -1) { + sDebug("sync rsetId:%d is closed", gNodeRefId); + taosCloseRef(gNodeRefId); + gNodeRefId = -1; } } -static SSyncEnv *doSyncEnvStart() { - SSyncEnv *pSyncEnv = (SSyncEnv *)taosMemoryMalloc(sizeof(SSyncEnv)); - ASSERT(pSyncEnv != NULL); - memset(pSyncEnv, 0, sizeof(SSyncEnv)); +int64_t syncNodeAdd(SSyncNode *pNode) { + pNode->rid = taosAddRef(gNodeRefId, pNode); + if (pNode->rid < 0) return -1; - pSyncEnv->envTickTimerCounter = 0; - pSyncEnv->envTickTimerMS = ENV_TICK_TIMER_MS; - pSyncEnv->FpEnvTickTimer = syncEnvTick; - atomic_store_64(&pSyncEnv->envTickTimerLogicClock, 0); - atomic_store_64(&pSyncEnv->envTickTimerLogicClockUser, 0); + sDebug("vgId:%d, sync rid:%" PRId64 " is added to rsetId:%d", pNode->vgId, pNode->rid, gNodeRefId); + return pNode->rid; +} - // start tmr thread - pSyncEnv->pTimerManager = taosTmrInit(1000, 50, 10000, "SYNC-ENV"); +void syncNodeRemove(int64_t rid) { taosRemoveRef(gNodeRefId, rid); } + +SSyncNode *syncNodeAcquire(int64_t rid) { + SSyncNode *pNode = taosAcquireRef(gNodeRefId, rid); + if (pNode == NULL) { + sError("failed to acquire node from refId:%" PRId64, rid); + terrno = TSDB_CODE_SYN_INTERNAL_ERROR; + } - atomic_store_8(&(pSyncEnv->isStart), 1); - return pSyncEnv; + return pNode; } -static int32_t doSyncEnvStop(SSyncEnv *pSyncEnv) { - ASSERT(pSyncEnv == gSyncEnv); - if (pSyncEnv != NULL) { - atomic_store_8(&(pSyncEnv->isStart), 0); - taosTmrCleanUp(pSyncEnv->pTimerManager); - taosMemoryFree(pSyncEnv); - } - gSyncEnv = NULL; - return 0; +void syncNodeRelease(SSyncNode *pNode) { taosReleaseRef(gNodeRefId, pNode->rid); } + +#if 0 +void syncEnvStartTimer() { + taosTmrReset(gSyncEnv.FpEnvTickTimer, gSyncEnv.envTickTimerMS, &gSyncEnv, gSyncEnv.pTimerManager, + &gSyncEnv.pEnvTickTimer); + atomic_store_64(&gSyncEnv.envTickTimerLogicClock, gSyncEnv.envTickTimerLogicClockUser); } -static int32_t doSyncEnvStartTimer(SSyncEnv *pSyncEnv) { +void syncEnvStopTimer() { int32_t ret = 0; - taosTmrReset(pSyncEnv->FpEnvTickTimer, pSyncEnv->envTickTimerMS, pSyncEnv, pSyncEnv->pTimerManager, - &pSyncEnv->pEnvTickTimer); - atomic_store_64(&pSyncEnv->envTickTimerLogicClock, pSyncEnv->envTickTimerLogicClockUser); + atomic_add_fetch_64(&gSyncEnv.envTickTimerLogicClockUser, 1); + taosTmrStop(gSyncEnv.pEnvTickTimer); + gSyncEnv.pEnvTickTimer = NULL; return ret; } +#endif -static int32_t doSyncEnvStopTimer(SSyncEnv *pSyncEnv) { - int32_t ret = 0; - atomic_add_fetch_64(&pSyncEnv->envTickTimerLogicClockUser, 1); - taosTmrStop(pSyncEnv->pEnvTickTimer); - pSyncEnv->pEnvTickTimer = NULL; - return ret; +static void syncEnvTick(void *param, void *tmrId) { + SSyncEnv *pSyncEnv = param; + if (atomic_load_64(&gSyncEnv.envTickTimerLogicClockUser) <= atomic_load_64(&gSyncEnv.envTickTimerLogicClock)) { + gSyncEnv.envTickTimerCounter++; + sTrace("syncEnvTick do ... envTickTimerLogicClockUser:%" PRIu64 ", envTickTimerLogicClock:%" PRIu64 + ", envTickTimerCounter:%" PRIu64 ", envTickTimerMS:%d, tmrId:%p", + gSyncEnv.envTickTimerLogicClockUser, gSyncEnv.envTickTimerLogicClock, gSyncEnv.envTickTimerCounter, + gSyncEnv.envTickTimerMS, tmrId); + + // do something, tick ... + taosTmrReset(syncEnvTick, gSyncEnv.envTickTimerMS, pSyncEnv, gSyncEnv.pTimerManager, &gSyncEnv.pEnvTickTimer); + } else { + sTrace("syncEnvTick pass ... envTickTimerLogicClockUser:%" PRIu64 ", envTickTimerLogicClock:%" PRIu64 + ", envTickTimerCounter:%" PRIu64 ", envTickTimerMS:%d, tmrId:%p", + gSyncEnv.envTickTimerLogicClockUser, gSyncEnv.envTickTimerLogicClock, gSyncEnv.envTickTimerCounter, + gSyncEnv.envTickTimerMS, tmrId); + } } diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 44c19f543197e0294740f9cca65f45738f5cd68b..252d5d021920b29f5c8dc0960914b8d87752a2df 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE #include "sync.h" #include "syncAppendEntries.h" #include "syncAppendEntriesReply.h" @@ -33,59 +34,17 @@ #include "syncTimeout.h" #include "syncUtil.h" #include "syncVoteMgr.h" -#include "tref.h" -bool gRaftDetailLog = false; - -static int32_t tsNodeRefId = -1; - -// ------ local funciton --------- -// enqueue message ---- static void syncNodeEqPingTimer(void* param, void* tmrId); static void syncNodeEqElectTimer(void* param, void* tmrId); static void syncNodeEqHeartbeatTimer(void* param, void* tmrId); static int32_t syncNodeEqNoop(SSyncNode* ths); static int32_t syncNodeAppendNoop(SSyncNode* ths); static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId); - -// process message ---- -int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg); -int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg); - -// --------------------------------- -static void syncNodeFreeCb(void* param) { - syncNodeClose(param); - param = NULL; -} - -int32_t syncInit() { - int32_t ret = 0; - - if (!syncEnvIsStart()) { - tsNodeRefId = taosOpenRef(200, syncNodeFreeCb); - if (tsNodeRefId < 0) { - sError("failed to init node ref"); - syncCleanUp(); - ret = -1; - } else { - sDebug("sync rsetId:%d is open", tsNodeRefId); - ret = syncEnvStart(); - } - } - - return ret; -} - -void syncCleanUp() { - int32_t ret = syncEnvStop(); - ASSERT(ret == 0); - - if (tsNodeRefId != -1) { - sDebug("sync rsetId:%d is closed", tsNodeRefId); - taosCloseRef(tsNodeRefId); - tsNodeRefId = -1; - } -} +static bool syncIsConfigChanged(const SSyncCfg* pOldCfg, const SSyncCfg* pNewCfg); +static int32_t syncHbTimerInit(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer, SRaftId destId); +static int32_t syncHbTimerStart(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer); +static int32_t syncHbTimerStop(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer); int64_t syncOpen(SSyncInfo* pSyncInfo) { SSyncNode* pSyncNode = syncNodeOpen(pSyncInfo); @@ -94,215 +53,151 @@ int64_t syncOpen(SSyncInfo* pSyncInfo) { return -1; } - pSyncNode->rid = taosAddRef(tsNodeRefId, pSyncNode); + pSyncNode->rid = syncNodeAdd(pSyncNode); if (pSyncNode->rid < 0) { syncNodeClose(pSyncNode); - pSyncNode = NULL; return -1; } - sDebug("vgId:%d, sync rid:%" PRId64 " is added to rsetId:%d", pSyncInfo->vgId, pSyncNode->rid, tsNodeRefId); + pSyncNode->pingBaseLine = pSyncInfo->pingMs; + pSyncNode->pingTimerMS = pSyncInfo->pingMs; + pSyncNode->electBaseLine = pSyncInfo->electMs; + pSyncNode->hbBaseLine = pSyncInfo->heartbeatMs; + pSyncNode->heartbeatTimerMS = pSyncInfo->heartbeatMs; + pSyncNode->msgcb = pSyncInfo->msgcb; return pSyncNode->rid; } void syncStart(int64_t rid) { - SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - return; - } - - if (pSyncNode->pRaftCfg->isStandBy) { - syncNodeStartStandBy(pSyncNode); - } else { + SSyncNode* pSyncNode = syncNodeAcquire(rid); + if (pSyncNode != NULL) { syncNodeStart(pSyncNode); + syncNodeRelease(pSyncNode); } - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); -} - -void syncStartNormal(int64_t rid) { - SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - return; - } - syncNodeStart(pSyncNode); - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); -} - -void syncStartStandBy(int64_t rid) { - SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - return; - } - syncNodeStartStandBy(pSyncNode); - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); } void syncStop(int64_t rid) { - SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) return; - int32_t vgId = pSyncNode->vgId; - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - - taosRemoveRef(tsNodeRefId, rid); - sDebug("vgId:%d, sync rid:%" PRId64 " is removed from rsetId:%d", vgId, rid, tsNodeRefId); -} - -int32_t syncSetStandby(int64_t rid) { - SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - sError("failed to set standby since accquire ref error, rid:%" PRId64, rid); - return -1; - } - - if (pSyncNode->state != TAOS_SYNC_STATE_FOLLOWER) { - if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { - terrno = TSDB_CODE_SYN_IS_LEADER; - } else { - terrno = TSDB_CODE_SYN_STANDBY_NOT_READY; - } - sError("failed to set standby since it is not follower, state:%s rid:%" PRId64, syncStr(pSyncNode->state), rid); - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - return -1; + SSyncNode* pSyncNode = syncNodeAcquire(rid); + if (pSyncNode != NULL) { + syncNodeRelease(pSyncNode); + syncNodeRemove(rid); } - - // state change - pSyncNode->state = TAOS_SYNC_STATE_FOLLOWER; - syncNodeStopHeartbeatTimer(pSyncNode); - - // reset elect timer, long enough - int32_t electMS = TIMER_MAX_MS; - int32_t ret = syncNodeRestartElectTimer(pSyncNode, electMS); - ASSERT(ret == 0); - - pSyncNode->pRaftCfg->isStandBy = 1; - raftCfgPersist(pSyncNode->pRaftCfg); - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - sInfo("vgId:%d, set to standby", pSyncNode->vgId); - return 0; } -bool syncNodeCheckNewConfig(SSyncNode* pSyncNode, const SSyncCfg* pNewCfg) { - bool IamInNew = syncNodeInConfig(pSyncNode, pNewCfg); - if (!IamInNew) { - return false; - } - - if (pNewCfg->replicaNum > pSyncNode->replicaNum + 1) { - return false; - } - - if (pNewCfg->replicaNum < pSyncNode->replicaNum - 1) { - return false; +void syncPreStop(int64_t rid) { + SSyncNode* pSyncNode = syncNodeAcquire(rid); + if (pSyncNode != NULL) { + syncNodePreClose(pSyncNode); + syncNodeRelease(pSyncNode); } - - return true; } -int32_t syncReconfigBuild(int64_t rid, const SSyncCfg* pNewCfg, SRpcMsg* pRpcMsg) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - return -1; - } - ASSERT(rid == pSyncNode->rid); - int32_t ret = 0; - - if (!syncNodeCheckNewConfig(pSyncNode, pNewCfg)) { - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - terrno = TSDB_CODE_SYN_NEW_CONFIG_ERROR; - sError("invalid new config. vgId:%d", pSyncNode->vgId); - return -1; - } - - char* newconfig = syncCfg2Str((SSyncCfg*)pNewCfg); - pRpcMsg->msgType = TDMT_SYNC_CONFIG_CHANGE; - pRpcMsg->info.noResp = 1; - pRpcMsg->contLen = strlen(newconfig) + 1; - pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen); - snprintf(pRpcMsg->pCont, pRpcMsg->contLen, "%s", newconfig); - taosMemoryFree(newconfig); - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - return ret; +static bool syncNodeCheckNewConfig(SSyncNode* pSyncNode, const SSyncCfg* pCfg) { + if (!syncNodeInConfig(pSyncNode, pCfg)) return false; + return abs(pCfg->replicaNum - pSyncNode->replicaNum) <= 1; } int32_t syncReconfig(int64_t rid, SSyncCfg* pNewCfg) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - return -1; - } - ASSERT(rid == pSyncNode->rid); + SSyncNode* pSyncNode = syncNodeAcquire(rid); + if (pSyncNode == NULL) return -1; if (!syncNodeCheckNewConfig(pSyncNode, pNewCfg)) { - taosReleaseRef(tsNodeRefId, pSyncNode->rid); + syncNodeRelease(pSyncNode); terrno = TSDB_CODE_SYN_NEW_CONFIG_ERROR; - sError("invalid new config. vgId:%d", pSyncNode->vgId); + sError("vgId:%d, failed to reconfig since invalid new config", pSyncNode->vgId); return -1; } -#if 0 - char* newconfig = syncCfg2Str((SSyncCfg*)pNewCfg); - int32_t ret = 0; - - SRpcMsg rpcMsg = {0}; - rpcMsg.msgType = TDMT_SYNC_CONFIG_CHANGE; - rpcMsg.info.noResp = 1; - rpcMsg.contLen = strlen(newconfig) + 1; - rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen); - snprintf(rpcMsg.pCont, rpcMsg.contLen, "%s", newconfig); - taosMemoryFree(newconfig); - ret = syncNodePropose(pSyncNode, &rpcMsg, false); - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - return ret; -#else syncNodeUpdateNewConfigIndex(pSyncNode, pNewCfg); syncNodeDoConfigChange(pSyncNode, pNewCfg, SYNC_INDEX_INVALID); + if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { syncNodeStopHeartbeatTimer(pSyncNode); for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { - syncHbTimerInit(pSyncNode, &(pSyncNode->peerHeartbeatTimerArr[i]), (pSyncNode->replicasId)[i]); + syncHbTimerInit(pSyncNode, &pSyncNode->peerHeartbeatTimerArr[i], pSyncNode->replicasId[i]); } syncNodeStartHeartbeatTimer(pSyncNode); - syncNodeReplicate(pSyncNode); } - taosReleaseRef(tsNodeRefId, pSyncNode->rid); + + syncNodeRelease(pSyncNode); return 0; -#endif } -int32_t syncLeaderTransfer(int64_t rid) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - return -1; +int32_t syncProcessMsg(int64_t rid, SRpcMsg* pMsg) { + int32_t code = -1; + if (!syncIsInit()) return code; + + SSyncNode* pSyncNode = syncNodeAcquire(rid); + if (pSyncNode == NULL) return code; + + if (pMsg->msgType == TDMT_SYNC_HEARTBEAT) { + SyncHeartbeat* pSyncMsg = syncHeartbeatFromRpcMsg2(pMsg); + code = syncNodeOnHeartbeat(pSyncNode, pSyncMsg); + syncHeartbeatDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_HEARTBEAT_REPLY) { + SyncHeartbeatReply* pSyncMsg = syncHeartbeatReplyFromRpcMsg2(pMsg); + code = syncNodeOnHeartbeatReply(pSyncNode, pSyncMsg); + syncHeartbeatReplyDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_TIMEOUT) { + SyncTimeout* pSyncMsg = syncTimeoutFromRpcMsg2(pMsg); + code = syncNodeOnTimer(pSyncNode, pSyncMsg); + syncTimeoutDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_PING) { + SyncPing* pSyncMsg = syncPingFromRpcMsg2(pMsg); + code = syncNodeOnPing(pSyncNode, pSyncMsg); + syncPingDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) { + SyncPingReply* pSyncMsg = syncPingReplyFromRpcMsg2(pMsg); + code = syncNodeOnPingReply(pSyncNode, pSyncMsg); + syncPingReplyDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) { + code = syncNodeOnClientRequest(pSyncNode, pMsg, NULL); + } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) { + SyncRequestVote* pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg); + code = syncNodeOnRequestVote(pSyncNode, pSyncMsg); + syncRequestVoteDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) { + SyncRequestVoteReply* pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg); + code = syncNodeOnRequestVoteReply(pSyncNode, pSyncMsg); + syncRequestVoteReplyDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) { + SyncAppendEntries* pSyncMsg = syncAppendEntriesFromRpcMsg2(pMsg); + code = syncNodeOnAppendEntries(pSyncNode, pSyncMsg); + syncAppendEntriesDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) { + SyncAppendEntriesReply* pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg); + code = syncNodeOnAppendEntriesReply(pSyncNode, pSyncMsg); + syncAppendEntriesReplyDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) { + SyncSnapshotSend* pSyncMsg = syncSnapshotSendFromRpcMsg2(pMsg); + code = syncNodeOnSnapshot(pSyncNode, pSyncMsg); + syncSnapshotSendDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) { + SyncSnapshotRsp* pSyncMsg = syncSnapshotRspFromRpcMsg2(pMsg); + code = syncNodeOnSnapshotReply(pSyncNode, pSyncMsg); + syncSnapshotRspDestroy(pSyncMsg); + } else if (pMsg->msgType == TDMT_SYNC_LOCAL_CMD) { + SyncLocalCmd* pSyncMsg = syncLocalCmdFromRpcMsg2(pMsg); + code = syncNodeOnLocalCmd(pSyncNode, pSyncMsg); + syncLocalCmdDestroy(pSyncMsg); + } else { + sError("vgId:%d, failed to process msg:%p since invalid type:%s", pSyncNode->vgId, pMsg, TMSG_INFO(pMsg->msgType)); + code = -1; } - ASSERT(rid == pSyncNode->rid); - int32_t ret = syncNodeLeaderTransfer(pSyncNode); - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - return ret; + syncNodeRelease(pSyncNode); + return code; } -int32_t syncLeaderTransferTo(int64_t rid, SNodeInfo newLeader) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - return -1; - } - ASSERT(rid == pSyncNode->rid); +int32_t syncLeaderTransfer(int64_t rid) { + SSyncNode* pSyncNode = syncNodeAcquire(rid); + if (pSyncNode == NULL) return -1; - int32_t ret = syncNodeLeaderTransferTo(pSyncNode, newLeader); - taosReleaseRef(tsNodeRefId, pSyncNode->rid); + int32_t ret = syncNodeLeaderTransfer(pSyncNode); + syncNodeRelease(pSyncNode); return ret; } @@ -322,48 +217,13 @@ SyncIndex syncMinMatchIndex(SSyncNode* pSyncNode) { return minMatchIndex; } -char* syncNodePeerState2Str(const SSyncNode* pSyncNode) { - int32_t len = 128; - int32_t useLen = 0; - int32_t leftLen = len - useLen; - char* pStr = taosMemoryMalloc(len); - memset(pStr, 0, len); - - char* p = pStr; - int32_t use = snprintf(p, leftLen, "{"); - useLen += use; - leftLen -= use; - - for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) { - SPeerState* pState = syncNodeGetPeerState((SSyncNode*)pSyncNode, &(pSyncNode->replicasId[i])); - if (pState == NULL) { - sError("vgId:%d, replica maybe dropped", pSyncNode->vgId); - break; - } - - p = pStr + useLen; - use = snprintf(p, leftLen, "%d:%" PRId64 " ,%" PRId64, i, pState->lastSendIndex, pState->lastSendTime); - useLen += use; - leftLen -= use; - } - - p = pStr + useLen; - use = snprintf(p, leftLen, "}"); - useLen += use; - leftLen -= use; - - // sTrace("vgId:%d, ------------------ syncNodePeerState2Str:%s", pSyncNode->vgId, pStr); - - return pStr; -} - int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); + SSyncNode* pSyncNode = syncNodeAcquire(rid); if (pSyncNode == NULL) { - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; + sError("sync begin snapshot error"); return -1; } - ASSERT(rid == pSyncNode->rid); + int32_t code = 0; if (syncNodeIsMnode(pSyncNode)) { @@ -376,13 +236,9 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) { bool isEmpty = pSyncNode->pLogStore->syncLogIsEmpty(pSyncNode->pLogStore); if (isEmpty || (!isEmpty && logNum < logRetention)) { - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "new-snapshot-index:%" PRId64 ", log-num:%" PRId64 ", empty:%d, do not delete wal", lastApplyIndex, - logNum, isEmpty); - syncNodeEventLog(pSyncNode, logBuf); - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); + sNTrace(pSyncNode, "new-snapshot-index:%" PRId64 ", log-num:%" PRId64 ", empty:%d, do not delete wal", + lastApplyIndex, logNum, isEmpty); + syncNodeRelease(pSyncNode); return 0; } @@ -403,46 +259,34 @@ int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex) { char host[64]; uint16_t port; syncUtilU642Addr(pSyncNode->peersId[i].addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "new-snapshot-index:%" PRId64 " is greater than match-index:%" PRId64 - " of %s:%d, do not delete wal", - lastApplyIndex, matchIndex, host, port); - syncNodeEventLog(pSyncNode, logBuf); + sNTrace(pSyncNode, + "new-snapshot-index:%" PRId64 " is greater than match-index:%" PRId64 + " of %s:%d, do not delete wal", + lastApplyIndex, matchIndex, host, port); } while (0); - taosReleaseRef(tsNodeRefId, pSyncNode->rid); + syncNodeRelease(pSyncNode); return 0; } } } else if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) { if (lastApplyIndex > pSyncNode->minMatchIndex) { - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "new-snapshot-index:%" PRId64 " is greater than min-match-index:%" PRId64 ", do not delete wal", - lastApplyIndex, pSyncNode->minMatchIndex); - syncNodeEventLog(pSyncNode, logBuf); - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); + sNTrace(pSyncNode, + "new-snapshot-index:%" PRId64 " is greater than min-match-index:%" PRId64 ", do not delete wal", + lastApplyIndex, pSyncNode->minMatchIndex); + syncNodeRelease(pSyncNode); return 0; } } else if (pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE) { - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "new-snapshot-index:%" PRId64 " candidate, do not delete wal", lastApplyIndex); - syncNodeEventLog(pSyncNode, logBuf); - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); + sNTrace(pSyncNode, "new-snapshot-index:%" PRId64 " candidate, do not delete wal", lastApplyIndex); + syncNodeRelease(pSyncNode); return 0; } else { - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "new-snapshot-index:%" PRId64 " unknown state, do not delete wal", - lastApplyIndex); - syncNodeEventLog(pSyncNode, logBuf); - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); + sNTrace(pSyncNode, "new-snapshot-index:%" PRId64 " unknown state, do not delete wal", lastApplyIndex); + syncNodeRelease(pSyncNode); return 0; } @@ -467,67 +311,107 @@ _DEL_WAL: SSyncLogStoreData* pData = pSyncNode->pLogStore->data; code = walBeginSnapshot(pData->pWal, lastApplyIndex); if (code == 0) { - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "wal snapshot begin, index:%" PRId64 ", last apply index:%" PRId64, - pSyncNode->snapshottingIndex, lastApplyIndex); - syncNodeEventLog(pSyncNode, logBuf); - + sNTrace(pSyncNode, "wal snapshot begin, index:%" PRId64 ", last apply index:%" PRId64, + pSyncNode->snapshottingIndex, lastApplyIndex); } else { - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "wal snapshot begin error since:%s, index:%" PRId64 ", last apply index:%" PRId64, terrstr(terrno), - pSyncNode->snapshottingIndex, lastApplyIndex); - syncNodeErrorLog(pSyncNode, logBuf); - + sNError(pSyncNode, "wal snapshot begin error since:%s, index:%" PRId64 ", last apply index:%" PRId64, + terrstr(terrno), pSyncNode->snapshottingIndex, lastApplyIndex); atomic_store_64(&pSyncNode->snapshottingIndex, SYNC_INDEX_INVALID); } } else { - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "snapshotting for %" PRId64 ", do not delete wal for new-snapshot-index:%" PRId64, snapshottingIndex, - lastApplyIndex); - syncNodeEventLog(pSyncNode, logBuf); + sNTrace(pSyncNode, "snapshotting for %" PRId64 ", do not delete wal for new-snapshot-index:%" PRId64, + snapshottingIndex, lastApplyIndex); } } while (0); - taosReleaseRef(tsNodeRefId, pSyncNode->rid); + syncNodeRelease(pSyncNode); return code; } int32_t syncEndSnapshot(int64_t rid) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); + SSyncNode* pSyncNode = syncNodeAcquire(rid); if (pSyncNode == NULL) { - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; + sError("sync end snapshot error"); return -1; } - ASSERT(rid == pSyncNode->rid); int32_t code = 0; if (atomic_load_64(&pSyncNode->snapshottingIndex) != SYNC_INDEX_INVALID) { SSyncLogStoreData* pData = pSyncNode->pLogStore->data; code = walEndSnapshot(pData->pWal); if (code != 0) { - sError("vgId:%d, wal snapshot end error since:%s", pSyncNode->vgId, terrstr(terrno)); - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); + sNError(pSyncNode, "wal snapshot end error since:%s", terrstr()); + syncNodeRelease(pSyncNode); return -1; } else { - do { - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "wal snapshot end, index:%" PRId64, - atomic_load_64(&pSyncNode->snapshottingIndex)); - syncNodeEventLog(pSyncNode, logBuf); - } while (0); - + sNTrace(pSyncNode, "wal snapshot end, index:%" PRId64, atomic_load_64(&pSyncNode->snapshottingIndex)); atomic_store_64(&pSyncNode->snapshottingIndex, SYNC_INDEX_INVALID); } } - taosReleaseRef(tsNodeRefId, pSyncNode->rid); + syncNodeRelease(pSyncNode); return code; } +int32_t syncStepDown(int64_t rid, SyncTerm newTerm) { + SSyncNode* pSyncNode = syncNodeAcquire(rid); + if (pSyncNode == NULL) { + sError("sync step down error"); + return -1; + } + + syncNodeStepDown(pSyncNode, newTerm); + syncNodeRelease(pSyncNode); + return 0; +} + +bool syncIsReadyForRead(int64_t rid) { + SSyncNode* pSyncNode = syncNodeAcquire(rid); + if (pSyncNode == NULL) { + sError("sync ready for read error"); + return false; + } + + if (pSyncNode->state == TAOS_SYNC_STATE_LEADER && pSyncNode->restoreFinish) { + syncNodeRelease(pSyncNode); + return true; + } + + bool ready = false; + if (pSyncNode->state == TAOS_SYNC_STATE_LEADER && !pSyncNode->restoreFinish) { + if (!pSyncNode->pFsm->FpApplyQueueEmptyCb(pSyncNode->pFsm)) { + // apply queue not empty + ready = false; + + } else { + if (!pSyncNode->pLogStore->syncLogIsEmpty(pSyncNode->pLogStore)) { + SSyncRaftEntry* pEntry = NULL; + int32_t code = pSyncNode->pLogStore->syncLogGetEntry( + pSyncNode->pLogStore, pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore), &pEntry); + if (code == 0 && pEntry != NULL) { + if (pEntry->originalRpcType == TDMT_SYNC_NOOP && pEntry->term == pSyncNode->pRaftStore->currentTerm) { + ready = true; + } + + syncEntryDestory(pEntry); + } + } + } + } + + if (!ready) { + if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) { + terrno = TSDB_CODE_SYN_NOT_LEADER; + } else { + terrno = TSDB_CODE_APP_NOT_READY; + } + } + + syncNodeRelease(pSyncNode); + return ready; +} + int32_t syncNodeLeaderTransfer(SSyncNode* pSyncNode) { if (pSyncNode->peersNum == 0) { sDebug("only one replica, cannot leader transfer"); @@ -535,25 +419,23 @@ int32_t syncNodeLeaderTransfer(SSyncNode* pSyncNode) { return -1; } - SNodeInfo newLeader = (pSyncNode->peersNodeInfo)[0]; - int32_t ret = syncNodeLeaderTransferTo(pSyncNode, newLeader); + int32_t ret = 0; + if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { + SNodeInfo newLeader = (pSyncNode->peersNodeInfo)[0]; + ret = syncNodeLeaderTransferTo(pSyncNode, newLeader); + } + return ret; } int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader) { - int32_t ret = 0; - if (pSyncNode->replicaNum == 1) { sDebug("only one replica, cannot leader transfer"); terrno = TSDB_CODE_SYN_ONE_REPLICA; return -1; } - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "begin leader transfer to %s:%u", newLeader.nodeFqdn, newLeader.nodePort); - syncNodeEventLog(pSyncNode, logBuf); - } while (0); + sNTrace(pSyncNode, "begin leader transfer to %s:%u", newLeader.nodeFqdn, newLeader.nodePort); SyncLeaderTransfer* pMsg = syncLeaderTransferBuild(pSyncNode->vgId); pMsg->newLeaderId.addr = syncUtilAddr2U64(newLeader.nodeFqdn, newLeader.nodePort); @@ -564,97 +446,30 @@ int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader) { syncLeaderTransfer2RpcMsg(pMsg, &rpcMsg); syncLeaderTransferDestroy(pMsg); - ret = syncNodePropose(pSyncNode, &rpcMsg, false); + int32_t ret = syncNodePropose(pSyncNode, &rpcMsg, false); return ret; } -bool syncCanLeaderTransfer(int64_t rid) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - return false; - } - ASSERT(rid == pSyncNode->rid); - - if (pSyncNode->replicaNum == 1) { - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - return false; - } - - if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) { - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - return true; - } - - bool matchOK = true; - if (pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE || pSyncNode->state == TAOS_SYNC_STATE_LEADER) { - SyncIndex myCommitIndex = pSyncNode->commitIndex; - for (int i = 0; i < pSyncNode->peersNum; ++i) { - SyncIndex peerMatchIndex = syncIndexMgrGetIndex(pSyncNode->pMatchIndex, &(pSyncNode->peersId)[i]); - if (peerMatchIndex < myCommitIndex) { - matchOK = false; - } - } - } +SSyncState syncGetState(int64_t rid) { + SSyncState state = {.state = TAOS_SYNC_STATE_ERROR}; - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - return matchOK; -} - -int32_t syncForwardToPeer(int64_t rid, SRpcMsg* pMsg, bool isWeak) { - int32_t ret = syncPropose(rid, pMsg, isWeak); - return ret; -} - -ESyncState syncGetMyRole(int64_t rid) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - return TAOS_SYNC_STATE_ERROR; + SSyncNode* pSyncNode = syncNodeAcquire(rid); + if (pSyncNode != NULL) { + state.state = pSyncNode->state; + state.restored = pSyncNode->restoreFinish; + syncNodeRelease(pSyncNode); } - ASSERT(rid == pSyncNode->rid); - ESyncState state = pSyncNode->state; - taosReleaseRef(tsNodeRefId, pSyncNode->rid); return state; } -bool syncIsReady(int64_t rid) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - return false; - } - ASSERT(rid == pSyncNode->rid); - bool b = (pSyncNode->state == TAOS_SYNC_STATE_LEADER) && pSyncNode->restoreFinish; - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - - // if false, set error code - if (false == b) { - if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) { - terrno = TSDB_CODE_SYN_NOT_LEADER; - } else { - terrno = TSDB_CODE_APP_NOT_READY; - } - } - return b; -} - -bool syncIsRestoreFinish(int64_t rid) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - return false; - } - ASSERT(rid == pSyncNode->rid); - bool b = pSyncNode->restoreFinish; - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - return b; -} - +#if 0 int32_t syncGetSnapshotByIndex(int64_t rid, SyncIndex index, SSnapshot* pSnapshot) { if (index < SYNC_INDEX_BEGIN) { return -1; } - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); + SSyncNode* pSyncNode = syncNodeAcquire(rid); if (pSyncNode == NULL) { return -1; } @@ -666,7 +481,7 @@ int32_t syncGetSnapshotByIndex(int64_t rid, SyncIndex index, SSnapshot* pSnapsho if (pEntry != NULL) { syncEntryDestory(pEntry); } - taosReleaseRef(tsNodeRefId, pSyncNode->rid); + syncNodeRelease(pSyncNode); return -1; } ASSERT(pEntry != NULL); @@ -677,12 +492,12 @@ int32_t syncGetSnapshotByIndex(int64_t rid, SyncIndex index, SSnapshot* pSnapsho pSnapshot->lastConfigIndex = syncNodeGetSnapshotConfigIndex(pSyncNode, index); syncEntryDestory(pEntry); - taosReleaseRef(tsNodeRefId, pSyncNode->rid); + syncNodeRelease(pSyncNode); return 0; } int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); + SSyncNode* pSyncNode = syncNodeAcquire(rid); if (pSyncNode == NULL) { return -1; } @@ -691,12 +506,12 @@ int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta) { sTrace("vgId:%d, get snapshot meta, lastConfigIndex:%" PRId64, pSyncNode->vgId, pSyncNode->pRaftCfg->lastConfigIndex); - taosReleaseRef(tsNodeRefId, pSyncNode->rid); + syncNodeRelease(pSyncNode); return 0; } int32_t syncGetSnapshotMetaByIndex(int64_t rid, SyncIndex snapshotIndex, struct SSnapshotMeta* sMeta) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); + SSyncNode* pSyncNode = syncNodeAcquire(rid); if (pSyncNode == NULL) { return -1; } @@ -705,7 +520,7 @@ int32_t syncGetSnapshotMetaByIndex(int64_t rid, SyncIndex snapshotIndex, struct ASSERT(pSyncNode->pRaftCfg->configIndexCount >= 1); SyncIndex lastIndex = (pSyncNode->pRaftCfg->configIndexArr)[0]; - for (int i = 0; i < pSyncNode->pRaftCfg->configIndexCount; ++i) { + for (int32_t i = 0; i < pSyncNode->pRaftCfg->configIndexCount; ++i) { if ((pSyncNode->pRaftCfg->configIndexArr)[i] > lastIndex && (pSyncNode->pRaftCfg->configIndexArr)[i] <= snapshotIndex) { lastIndex = (pSyncNode->pRaftCfg->configIndexArr)[i]; @@ -715,15 +530,16 @@ int32_t syncGetSnapshotMetaByIndex(int64_t rid, SyncIndex snapshotIndex, struct sTrace("vgId:%d, get snapshot meta by index:%" PRId64 " lcindex:%" PRId64, pSyncNode->vgId, snapshotIndex, sMeta->lastConfigIndex); - taosReleaseRef(tsNodeRefId, pSyncNode->rid); + syncNodeRelease(pSyncNode); return 0; } +#endif SyncIndex syncNodeGetSnapshotConfigIndex(SSyncNode* pSyncNode, SyncIndex snapshotLastApplyIndex) { ASSERT(pSyncNode->pRaftCfg->configIndexCount >= 1); SyncIndex lastIndex = (pSyncNode->pRaftCfg->configIndexArr)[0]; - for (int i = 0; i < pSyncNode->pRaftCfg->configIndexCount; ++i) { + for (int32_t i = 0; i < pSyncNode->pRaftCfg->configIndexCount; ++i) { if ((pSyncNode->pRaftCfg->configIndexArr)[i] > lastIndex && (pSyncNode->pRaftCfg->configIndexArr)[i] <= snapshotLastApplyIndex) { lastIndex = (pSyncNode->pRaftCfg->configIndexArr)[i]; @@ -735,330 +551,93 @@ SyncIndex syncNodeGetSnapshotConfigIndex(SSyncNode* pSyncNode, SyncIndex snapsho return lastIndex; } -const char* syncGetMyRoleStr(int64_t rid) { - const char* s = syncUtilState2String(syncGetMyRole(rid)); - return s; -} - -bool syncRestoreFinish(int64_t rid) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - return false; - } - ASSERT(rid == pSyncNode->rid); - bool restoreFinish = pSyncNode->restoreFinish; - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - return restoreFinish; -} - -SyncTerm syncGetMyTerm(int64_t rid) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - return TAOS_SYNC_STATE_ERROR; - } - ASSERT(rid == pSyncNode->rid); - SyncTerm term = pSyncNode->pRaftStore->currentTerm; - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - return term; -} - -SyncIndex syncGetLastIndex(int64_t rid) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - return SYNC_INDEX_INVALID; - } - ASSERT(rid == pSyncNode->rid); - SyncIndex lastIndex = syncNodeGetLastIndex(pSyncNode); - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - return lastIndex; -} - -SyncIndex syncGetCommitIndex(int64_t rid) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - return SYNC_INDEX_INVALID; - } - ASSERT(rid == pSyncNode->rid); - SyncIndex cmtIndex = pSyncNode->commitIndex; - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - return cmtIndex; -} - -SyncGroupId syncGetVgId(int64_t rid) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - return TAOS_SYNC_STATE_ERROR; - } - ASSERT(rid == pSyncNode->rid); - SyncGroupId vgId = pSyncNode->vgId; - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - return vgId; -} - -void syncGetEpSet(int64_t rid, SEpSet* pEpSet) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - memset(pEpSet, 0, sizeof(*pEpSet)); - return; - } - ASSERT(rid == pSyncNode->rid); +void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet) { pEpSet->numOfEps = 0; - for (int i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { - snprintf(pEpSet->eps[i].fqdn, sizeof(pEpSet->eps[i].fqdn), "%s", (pSyncNode->pRaftCfg->cfg.nodeInfo)[i].nodeFqdn); - pEpSet->eps[i].port = (pSyncNode->pRaftCfg->cfg.nodeInfo)[i].nodePort; - (pEpSet->numOfEps)++; - sInfo("vgId:%d, sync get epset: index:%d %s:%d", pSyncNode->vgId, i, pEpSet->eps[i].fqdn, pEpSet->eps[i].port); - } - pEpSet->inUse = pSyncNode->pRaftCfg->cfg.myIndex; - sInfo("vgId:%d, sync get epset in-use:%d", pSyncNode->vgId, pEpSet->inUse); - taosReleaseRef(tsNodeRefId, pSyncNode->rid); -} + SSyncNode* pSyncNode = syncNodeAcquire(rid); + if (pSyncNode == NULL) return; -void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - memset(pEpSet, 0, sizeof(*pEpSet)); - return; - } - ASSERT(rid == pSyncNode->rid); - pEpSet->numOfEps = 0; - for (int i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { - snprintf(pEpSet->eps[i].fqdn, sizeof(pEpSet->eps[i].fqdn), "%s", (pSyncNode->pRaftCfg->cfg.nodeInfo)[i].nodeFqdn); - pEpSet->eps[i].port = (pSyncNode->pRaftCfg->cfg.nodeInfo)[i].nodePort; - (pEpSet->numOfEps)++; - sInfo("vgId:%d, sync get retry epset: index:%d %s:%d", pSyncNode->vgId, i, pEpSet->eps[i].fqdn, - pEpSet->eps[i].port); + for (int32_t i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { + SEp* pEp = &pEpSet->eps[i]; + tstrncpy(pEp->fqdn, pSyncNode->pRaftCfg->cfg.nodeInfo[i].nodeFqdn, TSDB_FQDN_LEN); + pEp->port = (pSyncNode->pRaftCfg->cfg.nodeInfo)[i].nodePort; + pEpSet->numOfEps++; + sInfo("vgId:%d, sync get retry epset, index:%d %s:%d", pSyncNode->vgId, i, pEp->fqdn, pEp->port); } if (pEpSet->numOfEps > 0) { pEpSet->inUse = (pSyncNode->pRaftCfg->cfg.myIndex + 1) % pEpSet->numOfEps; } - sInfo("vgId:%d, sync get retry epset in-use:%d", pSyncNode->vgId, pEpSet->inUse); - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); -} - -int32_t syncGetRespRpc(int64_t rid, uint64_t index, SRpcMsg* msg) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - return TAOS_SYNC_STATE_ERROR; - } - ASSERT(rid == pSyncNode->rid); - - SRespStub stub; - int32_t ret = syncRespMgrGet(pSyncNode->pSyncRespMgr, index, &stub); - if (ret == 1) { - memcpy(msg, &(stub.rpcMsg), sizeof(SRpcMsg)); - } - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - return ret; -} - -int32_t syncGetAndDelRespRpc(int64_t rid, uint64_t index, SRpcHandleInfo* pInfo) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - return TAOS_SYNC_STATE_ERROR; - } - ASSERT(rid == pSyncNode->rid); - - SRespStub stub; - int32_t ret = syncRespMgrGetAndDel(pSyncNode->pSyncRespMgr, index, &stub); - if (ret == 1) { - *pInfo = stub.rpcMsg.info; - } - - sTrace("vgId:%d, get seq:%" PRIu64 " rpc handle:%p", pSyncNode->vgId, index, pInfo->handle); - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - return ret; -} - -void syncSetMsgCb(int64_t rid, const SMsgCb* msgcb) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - sTrace("syncSetQ get pSyncNode is NULL, rid:%" PRId64, rid); - return; - } - ASSERT(rid == pSyncNode->rid); - pSyncNode->msgcb = msgcb; - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); -} - -char* sync2SimpleStr(int64_t rid) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - sTrace("syncSetRpc get pSyncNode is NULL, rid:%" PRId64, rid); - return NULL; - } - ASSERT(rid == pSyncNode->rid); - char* s = syncNode2SimpleStr(pSyncNode); - taosReleaseRef(tsNodeRefId, pSyncNode->rid); - - return s; -} - -void setPingTimerMS(int64_t rid, int32_t pingTimerMS) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - return; - } - ASSERT(rid == pSyncNode->rid); - pSyncNode->pingBaseLine = pingTimerMS; - pSyncNode->pingTimerMS = pingTimerMS; - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); -} - -void setElectTimerMS(int64_t rid, int32_t electTimerMS) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - return; - } - ASSERT(rid == pSyncNode->rid); - pSyncNode->electBaseLine = electTimerMS; - taosReleaseRef(tsNodeRefId, pSyncNode->rid); -} - -void setHeartbeatTimerMS(int64_t rid, int32_t hbTimerMS) { - SSyncNode* pSyncNode = (SSyncNode*)taosAcquireRef(tsNodeRefId, rid); - if (pSyncNode == NULL) { - return; - } - ASSERT(rid == pSyncNode->rid); - pSyncNode->hbBaseLine = hbTimerMS; - pSyncNode->heartbeatTimerMS = hbTimerMS; - - taosReleaseRef(tsNodeRefId, pSyncNode->rid); + sInfo("vgId:%d, sync get retry epset numOfEps:%d inUse:%d", pSyncNode->vgId, pEpSet->numOfEps, pEpSet->inUse); + syncNodeRelease(pSyncNode); } int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) { - SSyncNode* pSyncNode = taosAcquireRef(tsNodeRefId, rid); + SSyncNode* pSyncNode = syncNodeAcquire(rid); if (pSyncNode == NULL) { - taosReleaseRef(tsNodeRefId, rid); - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; + sError("sync propose error"); return -1; } - ASSERT(rid == pSyncNode->rid); int32_t ret = syncNodePropose(pSyncNode, pMsg, isWeak); - taosReleaseRef(tsNodeRefId, pSyncNode->rid); + syncNodeRelease(pSyncNode); return ret; } -static bool syncNodeBatchOK(SRpcMsg** pMsgPArr, int32_t arrSize) { - for (int32_t i = 0; i < arrSize; ++i) { - if (pMsgPArr[i]->msgType == TDMT_SYNC_CONFIG_CHANGE) { - return false; - } - - if (pMsgPArr[i]->msgType == TDMT_SYNC_CONFIG_CHANGE_FINISH) { - return false; - } - } - - return true; -} - int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) { - int32_t ret = 0; - - do { - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "propose message, type:%s", TMSG_INFO(pMsg->msgType)); - syncNodeEventLog(pSyncNode, eventLog); - } while (0); + if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) { + terrno = TSDB_CODE_SYN_NOT_LEADER; + sNError(pSyncNode, "sync propose not leader, %s, type:%s", syncStr(pSyncNode->state), TMSG_INFO(pMsg->msgType)); + return -1; + } - if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { - if (pSyncNode->changing && pMsg->msgType != TDMT_SYNC_CONFIG_CHANGE_FINISH) { - ret = -1; - terrno = TSDB_CODE_SYN_PROPOSE_NOT_READY; - sError("vgId:%d, failed to sync propose since not ready, type:%s", pSyncNode->vgId, TMSG_INFO(pMsg->msgType)); - goto _END; - } - - // config change - if (pMsg->msgType == TDMT_SYNC_CONFIG_CHANGE) { - if (!syncNodeCanChange(pSyncNode)) { - ret = -1; - terrno = TSDB_CODE_SYN_RECONFIG_NOT_READY; - sError("vgId:%d, failed to sync reconfig since not ready, type:%s", pSyncNode->vgId, TMSG_INFO(pMsg->msgType)); - goto _END; - } + // not restored, vnode enable + if (!pSyncNode->restoreFinish && pSyncNode->vgId != 1) { + terrno = TSDB_CODE_SYN_PROPOSE_NOT_READY; + sNError(pSyncNode, "failed to sync propose since not ready, type:%s, last:%" PRId64 ", cmt:%" PRId64, + TMSG_INFO(pMsg->msgType), syncNodeGetLastIndex(pSyncNode), pSyncNode->commitIndex); + return -1; + } - ASSERT(!pSyncNode->changing); - pSyncNode->changing = true; + // optimized one replica + if (syncNodeIsOptimizedOneReplica(pSyncNode, pMsg)) { + SyncIndex retIndex; + int32_t code = syncNodeOnClientRequest(pSyncNode, pMsg, &retIndex); + if (code == 0) { + pMsg->info.conn.applyIndex = retIndex; + pMsg->info.conn.applyTerm = pSyncNode->pRaftStore->currentTerm; + sTrace("vgId:%d, propose optimized msg, index:%" PRId64 " type:%s", pSyncNode->vgId, retIndex, + TMSG_INFO(pMsg->msgType)); + return 1; + } else { + terrno = TSDB_CODE_SYN_INTERNAL_ERROR; + sError("vgId:%d, failed to propose optimized msg, index:%" PRId64 " type:%s", pSyncNode->vgId, retIndex, + TMSG_INFO(pMsg->msgType)); + return -1; } - - // not restored, vnode enable - if (!pSyncNode->restoreFinish && pSyncNode->vgId != 1) { - ret = -1; - terrno = TSDB_CODE_SYN_PROPOSE_NOT_READY; - sError("vgId:%d, failed to sync propose since not ready, type:%s, last:%" PRId64 ", cmt:%" PRId64, - pSyncNode->vgId, TMSG_INFO(pMsg->msgType), syncNodeGetLastIndex(pSyncNode), pSyncNode->commitIndex); - goto _END; + } else { + SRespStub stub = {.createTime = taosGetTimestampMs(), .rpcMsg = *pMsg}; + uint64_t seqNum = syncRespMgrAdd(pSyncNode->pSyncRespMgr, &stub); + SRpcMsg rpcMsg = {0}; + int32_t code = syncClientRequestBuildFromRpcMsg(&rpcMsg, pMsg, seqNum, isWeak, pSyncNode->vgId); + if (code != 0) { + sError("vgId:%d, failed to propose msg while serialize since %s", pSyncNode->vgId, terrstr()); + (void)syncRespMgrDel(pSyncNode->pSyncRespMgr, seqNum); + return -1; } - SRespStub stub; - stub.createTime = taosGetTimestampMs(); - stub.rpcMsg = *pMsg; - uint64_t seqNum = syncRespMgrAdd(pSyncNode->pSyncRespMgr, &stub); - - SyncClientRequest* pSyncMsg = syncClientRequestBuild2(pMsg, seqNum, isWeak, pSyncNode->vgId); - SRpcMsg rpcMsg; - syncClientRequest2RpcMsg(pSyncMsg, &rpcMsg); - - // optimized one replica - if (syncNodeIsOptimizedOneReplica(pSyncNode, pMsg)) { - SyncIndex retIndex; - int32_t code = syncNodeOnClientRequest(pSyncNode, pSyncMsg, &retIndex); - if (code == 0) { - pMsg->info.conn.applyIndex = retIndex; - pMsg->info.conn.applyTerm = pSyncNode->pRaftStore->currentTerm; - rpcFreeCont(rpcMsg.pCont); - syncRespMgrDel(pSyncNode->pSyncRespMgr, seqNum); - ret = 1; - sDebug("vgId:%d, sync optimize index:%" PRId64 ", type:%s", pSyncNode->vgId, retIndex, - TMSG_INFO(pMsg->msgType)); - } else { - ret = -1; - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - sError("vgId:%d, failed to sync optimize index:%" PRId64 ", type:%s", pSyncNode->vgId, retIndex, - TMSG_INFO(pMsg->msgType)); - } - - } else { - if (pSyncNode->FpEqMsg != NULL && (*pSyncNode->FpEqMsg)(pSyncNode->msgcb, &rpcMsg) == 0) { - ret = 0; - } else { - ret = -1; - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; - sError("vgId:%d, failed to enqueue msg since its null", pSyncNode->vgId); - } + sNTrace(pSyncNode, "propose msg, type:%s", TMSG_INFO(pMsg->msgType)); + code = (*pSyncNode->syncEqMsg)(pSyncNode->msgcb, &rpcMsg); + if (code != 0) { + sError("vgId:%d, failed to propose msg while enqueue since %s", pSyncNode->vgId, terrstr()); + (void)syncRespMgrDel(pSyncNode->pSyncRespMgr, seqNum); } - syncClientRequestDestroy(pSyncMsg); - goto _END; - - } else { - ret = -1; - terrno = TSDB_CODE_SYN_NOT_LEADER; - sError("vgId:%d, sync propose not leader, %s, type:%s", pSyncNode->vgId, syncUtilState2String(pSyncNode->state), - TMSG_INFO(pMsg->msgType)); - goto _END; + return code; } - -_END: - return ret; } -int32_t syncHbTimerInit(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer, SRaftId destId) { +static int32_t syncHbTimerInit(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer, SRaftId destId) { pSyncTimer->pTimer = NULL; pSyncTimer->counter = 0; pSyncTimer->timerMS = pSyncNode->hbBaseLine; @@ -1068,9 +647,9 @@ int32_t syncHbTimerInit(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer, SRaftId de return 0; } -int32_t syncHbTimerStart(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer) { +static int32_t syncHbTimerStart(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer) { int32_t ret = 0; - if (syncEnvIsStart()) { + if (syncIsInit()) { SSyncHbTimerData* pData = taosMemoryMalloc(sizeof(SSyncHbTimerData)); pData->pSyncNode = pSyncNode; pData->pTimer = pSyncTimer; @@ -1078,14 +657,14 @@ int32_t syncHbTimerStart(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer) { pData->logicClock = pSyncTimer->logicClock; pSyncTimer->pData = pData; - taosTmrReset(pSyncTimer->timerCb, pSyncTimer->timerMS, pData, gSyncEnv->pTimerManager, &pSyncTimer->pTimer); + taosTmrReset(pSyncTimer->timerCb, pSyncTimer->timerMS, pData, syncEnv()->pTimerManager, &pSyncTimer->pTimer); } else { sError("vgId:%d, start ctrl hb timer error, sync env is stop", pSyncNode->vgId); } return ret; } -int32_t syncHbTimerStop(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer) { +static int32_t syncHbTimerStop(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer) { int32_t ret = 0; atomic_add_fetch_64(&pSyncTimer->logicClock, 1); taosTmrStop(pSyncTimer->pTimer); @@ -1132,7 +711,8 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { sError("vgId:%d, failed to open raft cfg file at %s", pSyncNode->vgId, pSyncNode->configPath); goto _error; } - if (pSyncInfo->syncCfg.replicaNum > 0 && pSyncInfo->syncCfg.replicaNum != pSyncNode->pRaftCfg->cfg.replicaNum) { + + if (pSyncInfo->syncCfg.replicaNum > 0 && syncIsConfigChanged(&pSyncNode->pRaftCfg->cfg, &pSyncInfo->syncCfg)) { sInfo("vgId:%d, use sync config from input options and write to cfg file", pSyncNode->vgId); pSyncNode->pRaftCfg->cfg = pSyncInfo->syncCfg; if (raftCfgPersist(pSyncNode->pRaftCfg) != 0) { @@ -1148,6 +728,8 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { pSyncNode->pRaftCfg = NULL; } + // init by SSyncInfo + pSyncNode->vgId = pSyncInfo->vgId; SSyncCfg* pCfg = &pSyncInfo->syncCfg; sDebug("vgId:%d, replica:%d selfIndex:%d", pSyncNode->vgId, pCfg->replicaNum, pCfg->myIndex); for (int32_t i = 0; i < pCfg->replicaNum; ++i) { @@ -1155,8 +737,6 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { sDebug("vgId:%d, index:%d ep:%s:%u", pSyncNode->vgId, i, pNode->nodeFqdn, pNode->nodePort); } - // init by SSyncInfo - pSyncNode->vgId = pSyncInfo->vgId; memcpy(pSyncNode->path, pSyncInfo->path, sizeof(pSyncNode->path)); snprintf(pSyncNode->raftStorePath, sizeof(pSyncNode->raftStorePath), "%s%sraft_store.json", pSyncInfo->path, TD_DIRSEP); @@ -1164,9 +744,9 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { pSyncNode->pWal = pSyncInfo->pWal; pSyncNode->msgcb = pSyncInfo->msgcb; - pSyncNode->FpSendMsg = pSyncInfo->FpSendMsg; - pSyncNode->FpEqMsg = pSyncInfo->FpEqMsg; - pSyncNode->FpEqCtrlMsg = pSyncInfo->FpEqCtrlMsg; + pSyncNode->syncSendMSg = pSyncInfo->syncSendMSg; + pSyncNode->syncEqMsg = pSyncInfo->syncEqMsg; + pSyncNode->syncEqCtrlMsg = pSyncInfo->syncEqCtrlMsg; // init raft config pSyncNode->pRaftCfg = raftCfgOpen(pSyncNode->configPath); @@ -1184,14 +764,14 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { // init peersNum, peers, peersId pSyncNode->peersNum = pSyncNode->pRaftCfg->cfg.replicaNum - 1; - int j = 0; - for (int i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { + int32_t j = 0; + for (int32_t i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { if (i != pSyncNode->pRaftCfg->cfg.myIndex) { pSyncNode->peersNodeInfo[j] = pSyncNode->pRaftCfg->cfg.nodeInfo[i]; j++; } } - for (int i = 0; i < pSyncNode->peersNum; ++i) { + for (int32_t i = 0; i < pSyncNode->peersNum; ++i) { if (!syncUtilnodeInfo2raftId(&pSyncNode->peersNodeInfo[i], pSyncNode->vgId, &pSyncNode->peersId[i])) { sError("vgId:%d, failed to determine raft member id, peer:%d", pSyncNode->vgId, i); goto _error; @@ -1200,7 +780,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { // init replicaNum, replicasId pSyncNode->replicaNum = pSyncNode->pRaftCfg->cfg.replicaNum; - for (int i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { + for (int32_t i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { if (!syncUtilnodeInfo2raftId(&pSyncNode->pRaftCfg->cfg.nodeInfo[i], pSyncNode->vgId, &pSyncNode->replicasId[i])) { sError("vgId:%d, failed to determine raft member id, replica:%d", pSyncNode->vgId, i); goto _error; @@ -1288,7 +868,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { } if (snapshot.lastApplyIndex > commitIndex) { commitIndex = snapshot.lastApplyIndex; - syncNodeEventLog(pSyncNode, "reset commit index by snapshot"); + sNTrace(pSyncNode, "reset commit index by snapshot"); } } pSyncNode->commitIndex = commitIndex; @@ -1327,8 +907,8 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { } // init callback - pSyncNode->FpOnPing = syncNodeOnPingCb; - pSyncNode->FpOnPingReply = syncNodeOnPingReplyCb; + pSyncNode->FpOnPing = syncNodeOnPing; + pSyncNode->FpOnPingReply = syncNodeOnPingReply; pSyncNode->FpOnClientRequest = syncNodeOnClientRequest; pSyncNode->FpOnTimeout = syncNodeOnTimer; pSyncNode->FpOnSnapshot = syncNodeOnSnapshot; @@ -1349,7 +929,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { pSyncNode->restoreFinish = false; // snapshot senders - for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { + for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { SSyncSnapshotSender* pSender = snapshotSenderCreate(pSyncNode, i); // ASSERT(pSender != NULL); (pSyncNode->senders)[i] = pSender; @@ -1379,7 +959,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) { // snapshotting atomic_store_64(&pSyncNode->snapshottingIndex, SYNC_INDEX_INVALID); - syncNodeEventLog(pSyncNode, "sync open"); + sNTrace(pSyncNode, "sync open"); return pSyncNode; @@ -1438,16 +1018,25 @@ void syncNodeStartStandBy(SSyncNode* pSyncNode) { ASSERT(ret == 0); } +void syncNodePreClose(SSyncNode* pSyncNode) { + // stop elect timer + syncNodeStopElectTimer(pSyncNode); + + // stop heartbeat timer + syncNodeStopHeartbeatTimer(pSyncNode); +} + void syncNodeClose(SSyncNode* pSyncNode) { if (pSyncNode == NULL) { return; } int32_t ret; - syncNodeEventLog(pSyncNode, "sync close"); + sNTrace(pSyncNode, "sync close"); ret = raftStoreClose(pSyncNode->pRaftStore); ASSERT(ret == 0); + pSyncNode->pRaftStore = NULL; syncRespMgrDestroy(pSyncNode->pSyncRespMgr); pSyncNode->pSyncRespMgr = NULL; @@ -1472,7 +1061,7 @@ void syncNodeClose(SSyncNode* pSyncNode) { taosMemoryFree(pSyncNode->pFsm); } - for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { + for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { if ((pSyncNode->senders)[i] != NULL) { snapshotSenderDestroy((pSyncNode->senders)[i]); (pSyncNode->senders)[i] = NULL; @@ -1492,58 +1081,11 @@ void syncNodeClose(SSyncNode* pSyncNode) { ESyncStrategy syncNodeStrategy(SSyncNode* pSyncNode) { return pSyncNode->pRaftCfg->snapshotStrategy; } -// ping -------------- -int32_t syncNodePing(SSyncNode* pSyncNode, const SRaftId* destRaftId, SyncPing* pMsg) { - syncPingLog2((char*)"==syncNodePing==", pMsg); - int32_t ret = 0; - - SRpcMsg rpcMsg; - syncPing2RpcMsg(pMsg, &rpcMsg); - syncRpcMsgLog2((char*)"==syncNodePing==", &rpcMsg); - - ret = syncNodeSendMsgById(destRaftId, pSyncNode, &rpcMsg); - return ret; -} - -int32_t syncNodePingSelf(SSyncNode* pSyncNode) { - int32_t ret = 0; - SyncPing* pMsg = syncPingBuild3(&pSyncNode->myRaftId, &pSyncNode->myRaftId, pSyncNode->vgId); - ret = syncNodePing(pSyncNode, &pMsg->destId, pMsg); - ASSERT(ret == 0); - - syncPingDestroy(pMsg); - return ret; -} - -int32_t syncNodePingPeers(SSyncNode* pSyncNode) { - int32_t ret = 0; - for (int i = 0; i < pSyncNode->peersNum; ++i) { - SRaftId* destId = &(pSyncNode->peersId[i]); - SyncPing* pMsg = syncPingBuild3(&pSyncNode->myRaftId, destId, pSyncNode->vgId); - ret = syncNodePing(pSyncNode, destId, pMsg); - ASSERT(ret == 0); - syncPingDestroy(pMsg); - } - return ret; -} - -int32_t syncNodePingAll(SSyncNode* pSyncNode) { - int32_t ret = 0; - for (int i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { - SRaftId* destId = &(pSyncNode->replicasId[i]); - SyncPing* pMsg = syncPingBuild3(&pSyncNode->myRaftId, destId, pSyncNode->vgId); - ret = syncNodePing(pSyncNode, destId, pMsg); - ASSERT(ret == 0); - syncPingDestroy(pMsg); - } - return ret; -} - // timer control -------------- int32_t syncNodeStartPingTimer(SSyncNode* pSyncNode) { int32_t ret = 0; - if (syncEnvIsStart()) { - taosTmrReset(pSyncNode->FpPingTimerCB, pSyncNode->pingTimerMS, pSyncNode, gSyncEnv->pTimerManager, + if (syncIsInit()) { + taosTmrReset(pSyncNode->FpPingTimerCB, pSyncNode->pingTimerMS, pSyncNode, syncEnv()->pTimerManager, &pSyncNode->pPingTimer); atomic_store_64(&pSyncNode->pingTimerLogicClock, pSyncNode->pingTimerLogicClockUser); } else { @@ -1562,7 +1104,7 @@ int32_t syncNodeStopPingTimer(SSyncNode* pSyncNode) { int32_t syncNodeStartElectTimer(SSyncNode* pSyncNode, int32_t ms) { int32_t ret = 0; - if (syncEnvIsStart()) { + if (syncIsInit()) { pSyncNode->electTimerMS = ms; SElectTimer* pElectTimer = taosMemoryMalloc(sizeof(SElectTimer)); @@ -1570,7 +1112,7 @@ int32_t syncNodeStartElectTimer(SSyncNode* pSyncNode, int32_t ms) { pElectTimer->pSyncNode = pSyncNode; pElectTimer->pData = NULL; - taosTmrReset(pSyncNode->FpElectTimerCB, pSyncNode->electTimerMS, pElectTimer, gSyncEnv->pTimerManager, + taosTmrReset(pSyncNode->FpElectTimerCB, pSyncNode->electTimerMS, pElectTimer, syncEnv()->pTimerManager, &pSyncNode->pElectTimer); } else { @@ -1606,32 +1148,22 @@ int32_t syncNodeResetElectTimer(SSyncNode* pSyncNode) { } ret = syncNodeRestartElectTimer(pSyncNode, electMS); - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "reset elect timer, min:%d, max:%d, ms:%d", pSyncNode->electBaseLine, - 2 * pSyncNode->electBaseLine, electMS); - syncNodeEventLog(pSyncNode, logBuf); - } while (0); - + sNTrace(pSyncNode, "reset elect timer, min:%d, max:%d, ms:%d", pSyncNode->electBaseLine, 2 * pSyncNode->electBaseLine, + electMS); return ret; } static int32_t syncNodeDoStartHeartbeatTimer(SSyncNode* pSyncNode) { int32_t ret = 0; - if (syncEnvIsStart()) { - taosTmrReset(pSyncNode->FpHeartbeatTimerCB, pSyncNode->heartbeatTimerMS, pSyncNode, gSyncEnv->pTimerManager, + if (syncIsInit()) { + taosTmrReset(pSyncNode->FpHeartbeatTimerCB, pSyncNode->heartbeatTimerMS, pSyncNode, syncEnv()->pTimerManager, &pSyncNode->pHeartbeatTimer); atomic_store_64(&pSyncNode->heartbeatTimerLogicClock, pSyncNode->heartbeatTimerLogicClockUser); } else { sError("vgId:%d, start heartbeat timer error, sync env is stop", pSyncNode->vgId); } - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "start heartbeat timer, ms:%d", pSyncNode->heartbeatTimerMS); - syncNodeEventLog(pSyncNode, logBuf); - } while (0); - + sNTrace(pSyncNode, "start heartbeat timer, ms:%d", pSyncNode->heartbeatTimerMS); return ret; } @@ -1643,9 +1175,11 @@ int32_t syncNodeStartHeartbeatTimer(SSyncNode* pSyncNode) { ret = syncNodeDoStartHeartbeatTimer(pSyncNode); #endif - for (int i = 0; i < pSyncNode->peersNum; ++i) { + for (int32_t i = 0; i < pSyncNode->peersNum; ++i) { SSyncTimer* pSyncTimer = syncNodeGetHbTimer(pSyncNode, &(pSyncNode->peersId[i])); - syncHbTimerStart(pSyncNode, pSyncTimer); + if (pSyncTimer != NULL) { + syncHbTimerStart(pSyncNode, pSyncTimer); + } } return ret; @@ -1660,400 +1194,60 @@ int32_t syncNodeStopHeartbeatTimer(SSyncNode* pSyncNode) { pSyncNode->pHeartbeatTimer = NULL; #endif - for (int i = 0; i < pSyncNode->peersNum; ++i) { - SSyncTimer* pSyncTimer = syncNodeGetHbTimer(pSyncNode, &(pSyncNode->peersId[i])); - syncHbTimerStop(pSyncNode, pSyncTimer); - } - - return ret; -} - -int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode) { - syncNodeStopHeartbeatTimer(pSyncNode); - syncNodeStartHeartbeatTimer(pSyncNode); - return 0; -} - -// utils -------------- -int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg) { - SEpSet epSet; - syncUtilraftId2EpSet(destRaftId, &epSet); - if (pSyncNode->FpSendMsg != NULL) { - // htonl - syncUtilMsgHtoN(pMsg->pCont); - - pMsg->info.noResp = 1; - pSyncNode->FpSendMsg(&epSet, pMsg); - } else { - sError("vgId:%d, sync send msg by id error, fp-send-msg is null", pSyncNode->vgId); - return -1; - } - - return 0; -} - -int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, SRpcMsg* pMsg) { - SEpSet epSet; - syncUtilnodeInfo2EpSet(nodeInfo, &epSet); - if (pSyncNode->FpSendMsg != NULL) { - // htonl - syncUtilMsgHtoN(pMsg->pCont); - - pMsg->info.noResp = 1; - pSyncNode->FpSendMsg(&epSet, pMsg); - } else { - sError("vgId:%d, sync send msg by info error, fp-send-msg is null", pSyncNode->vgId); - } - return 0; -} - -cJSON* syncNode2Json(const SSyncNode* pSyncNode) { - char u64buf[128] = {0}; - cJSON* pRoot = cJSON_CreateObject(); - - if (pSyncNode != NULL) { - // init by SSyncInfo - cJSON_AddNumberToObject(pRoot, "vgId", pSyncNode->vgId); - cJSON_AddItemToObject(pRoot, "SRaftCfg", raftCfg2Json(pSyncNode->pRaftCfg)); - cJSON_AddStringToObject(pRoot, "path", pSyncNode->path); - cJSON_AddStringToObject(pRoot, "raftStorePath", pSyncNode->raftStorePath); - cJSON_AddStringToObject(pRoot, "configPath", pSyncNode->configPath); - - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pWal); - cJSON_AddStringToObject(pRoot, "pWal", u64buf); - - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->msgcb); - cJSON_AddStringToObject(pRoot, "rpcClient", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpSendMsg); - cJSON_AddStringToObject(pRoot, "FpSendMsg", u64buf); - - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->msgcb); - cJSON_AddStringToObject(pRoot, "queue", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpEqMsg); - cJSON_AddStringToObject(pRoot, "FpEqMsg", u64buf); - - // init internal - cJSON* pMe = syncUtilNodeInfo2Json(&pSyncNode->myNodeInfo); - cJSON_AddItemToObject(pRoot, "myNodeInfo", pMe); - cJSON* pRaftId = syncUtilRaftId2Json(&pSyncNode->myRaftId); - cJSON_AddItemToObject(pRoot, "myRaftId", pRaftId); - - cJSON_AddNumberToObject(pRoot, "peersNum", pSyncNode->peersNum); - cJSON* pPeers = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "peersNodeInfo", pPeers); - for (int i = 0; i < pSyncNode->peersNum; ++i) { - cJSON_AddItemToArray(pPeers, syncUtilNodeInfo2Json(&pSyncNode->peersNodeInfo[i])); - } - cJSON* pPeersId = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "peersId", pPeersId); - for (int i = 0; i < pSyncNode->peersNum; ++i) { - cJSON_AddItemToArray(pPeersId, syncUtilRaftId2Json(&pSyncNode->peersId[i])); - } - - cJSON_AddNumberToObject(pRoot, "replicaNum", pSyncNode->replicaNum); - cJSON* pReplicasId = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "replicasId", pReplicasId); - for (int i = 0; i < pSyncNode->replicaNum; ++i) { - cJSON_AddItemToArray(pReplicasId, syncUtilRaftId2Json(&pSyncNode->replicasId[i])); - } - - // raft algorithm - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pFsm); - cJSON_AddStringToObject(pRoot, "pFsm", u64buf); - cJSON_AddNumberToObject(pRoot, "quorum", pSyncNode->quorum); - cJSON* pLaderCache = syncUtilRaftId2Json(&pSyncNode->leaderCache); - cJSON_AddItemToObject(pRoot, "leaderCache", pLaderCache); - - // life cycle - snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->rid); - cJSON_AddStringToObject(pRoot, "rid", u64buf); - - // tla+ server vars - cJSON_AddNumberToObject(pRoot, "state", pSyncNode->state); - cJSON_AddStringToObject(pRoot, "state_str", syncUtilState2String(pSyncNode->state)); - cJSON_AddItemToObject(pRoot, "pRaftStore", raftStore2Json(pSyncNode->pRaftStore)); - - // tla+ candidate vars - cJSON_AddItemToObject(pRoot, "pVotesGranted", voteGranted2Json(pSyncNode->pVotesGranted)); - cJSON_AddItemToObject(pRoot, "pVotesRespond", votesRespond2Json(pSyncNode->pVotesRespond)); - - // tla+ leader vars - cJSON_AddItemToObject(pRoot, "pNextIndex", syncIndexMgr2Json(pSyncNode->pNextIndex)); - cJSON_AddItemToObject(pRoot, "pMatchIndex", syncIndexMgr2Json(pSyncNode->pMatchIndex)); - - // tla+ log vars - cJSON_AddItemToObject(pRoot, "pLogStore", logStore2Json(pSyncNode->pLogStore)); - snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->commitIndex); - cJSON_AddStringToObject(pRoot, "commitIndex", u64buf); - - // timer ms init - cJSON_AddNumberToObject(pRoot, "pingBaseLine", pSyncNode->pingBaseLine); - cJSON_AddNumberToObject(pRoot, "electBaseLine", pSyncNode->electBaseLine); - cJSON_AddNumberToObject(pRoot, "hbBaseLine", pSyncNode->hbBaseLine); - - // ping timer - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pPingTimer); - cJSON_AddStringToObject(pRoot, "pPingTimer", u64buf); - cJSON_AddNumberToObject(pRoot, "pingTimerMS", pSyncNode->pingTimerMS); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->pingTimerLogicClock); - cJSON_AddStringToObject(pRoot, "pingTimerLogicClock", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->pingTimerLogicClockUser); - cJSON_AddStringToObject(pRoot, "pingTimerLogicClockUser", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpPingTimerCB); - cJSON_AddStringToObject(pRoot, "FpPingTimerCB", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->pingTimerCounter); - cJSON_AddStringToObject(pRoot, "pingTimerCounter", u64buf); - - // elect timer - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pElectTimer); - cJSON_AddStringToObject(pRoot, "pElectTimer", u64buf); - cJSON_AddNumberToObject(pRoot, "electTimerMS", pSyncNode->electTimerMS); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->electTimerLogicClock); - cJSON_AddStringToObject(pRoot, "electTimerLogicClock", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpElectTimerCB); - cJSON_AddStringToObject(pRoot, "FpElectTimerCB", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->electTimerCounter); - cJSON_AddStringToObject(pRoot, "electTimerCounter", u64buf); - - // heartbeat timer - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pHeartbeatTimer); - cJSON_AddStringToObject(pRoot, "pHeartbeatTimer", u64buf); - cJSON_AddNumberToObject(pRoot, "heartbeatTimerMS", pSyncNode->heartbeatTimerMS); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->heartbeatTimerLogicClock); - cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClock", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->heartbeatTimerLogicClockUser); - cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClockUser", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpHeartbeatTimerCB); - cJSON_AddStringToObject(pRoot, "FpHeartbeatTimerCB", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->heartbeatTimerCounter); - cJSON_AddStringToObject(pRoot, "heartbeatTimerCounter", u64buf); - - // callback - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnPing); - cJSON_AddStringToObject(pRoot, "FpOnPing", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnPingReply); - cJSON_AddStringToObject(pRoot, "FpOnPingReply", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnRequestVote); - cJSON_AddStringToObject(pRoot, "FpOnRequestVote", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnRequestVoteReply); - cJSON_AddStringToObject(pRoot, "FpOnRequestVoteReply", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnAppendEntries); - cJSON_AddStringToObject(pRoot, "FpOnAppendEntries", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnAppendEntriesReply); - cJSON_AddStringToObject(pRoot, "FpOnAppendEntriesReply", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnTimeout); - cJSON_AddStringToObject(pRoot, "FpOnTimeout", u64buf); - - // restoreFinish - cJSON_AddNumberToObject(pRoot, "restoreFinish", pSyncNode->restoreFinish); - - // snapshot senders - cJSON* pSenders = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "senders", pSenders); - for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { - cJSON_AddItemToArray(pSenders, snapshotSender2Json((pSyncNode->senders)[i])); - } - - // snapshot receivers - cJSON* pReceivers = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "receiver", snapshotReceiver2Json(pSyncNode->pNewNodeReceiver)); - - // changing - cJSON_AddNumberToObject(pRoot, "changing", pSyncNode->changing); - } - - cJSON* pJson = cJSON_CreateObject(); - cJSON_AddItemToObject(pJson, "SSyncNode", pRoot); - return pJson; -} - -char* syncNode2Str(const SSyncNode* pSyncNode) { - cJSON* pJson = syncNode2Json(pSyncNode); - char* serialized = cJSON_Print(pJson); - cJSON_Delete(pJson); - return serialized; -} - -inline void syncNodeEventLog(const SSyncNode* pSyncNode, char* str) { - if (pSyncNode == NULL) { - return; - } - - SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0}; - if (pSyncNode->pFsm != NULL && pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { - pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); - } - - SyncIndex logLastIndex = SYNC_INDEX_INVALID; - SyncIndex logBeginIndex = SYNC_INDEX_INVALID; - if (pSyncNode->pLogStore != NULL) { - logLastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore); - logBeginIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore); - } - - char* pCfgStr = syncCfg2SimpleStr(&(pSyncNode->pRaftCfg->cfg)); - char* printStr = ""; - if (pCfgStr != NULL) { - printStr = pCfgStr; - } - - char* peerStateStr = syncNodePeerState2Str(pSyncNode); - int32_t userStrLen = strlen(str) + strlen(peerStateStr); - - if (userStrLen < 256) { - char logBuf[256 + 256]; - if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { - snprintf(logBuf, sizeof(logBuf), - "vgId:%d, sync %s %s, tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 - ", snap:%" PRId64 ", snap-tm:%" PRIu64 - ", sby:%d, " - "stgy:%d, bch:%d, " - "r-num:%d, " - "lcfg:%" PRId64 ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s", - pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, - pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex, - snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy, - pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, - pSyncNode->changing, pSyncNode->restoreFinish, syncNodeDynamicQuorum(pSyncNode), - pSyncNode->electTimerLogicClock, pSyncNode->heartbeatTimerLogicClockUser, peerStateStr, printStr); - } else { - snprintf(logBuf, sizeof(logBuf), "%s", str); - } - // sDebug("%s", logBuf); - // sInfo("%s", logBuf); - sTrace("%s", logBuf); - - } else { - int len = 256 + userStrLen; - char* s = (char*)taosMemoryMalloc(len); - if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { - snprintf(s, len, - "vgId:%d, sync %s %s, tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 - ", snap:%" PRId64 ", snap-tm:%" PRIu64 - ", sby:%d, " - "stgy:%d, bch:%d, " - "r-num:%d, " - "lcfg:%" PRId64 ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s", - pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, - pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex, - snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy, - pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, - pSyncNode->changing, pSyncNode->restoreFinish, syncNodeDynamicQuorum(pSyncNode), - pSyncNode->electTimerLogicClock, pSyncNode->heartbeatTimerLogicClockUser, peerStateStr, printStr); - } else { - snprintf(s, len, "%s", str); - } - // sDebug("%s", s); - // sInfo("%s", s); - sTrace("%s", s); - taosMemoryFree(s); - } - - taosMemoryFree(peerStateStr); - taosMemoryFree(pCfgStr); -} - -inline void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str) { - if (pSyncNode == NULL) { - return; + for (int32_t i = 0; i < pSyncNode->peersNum; ++i) { + SSyncTimer* pSyncTimer = syncNodeGetHbTimer(pSyncNode, &(pSyncNode->peersId[i])); + if (pSyncTimer != NULL) { + syncHbTimerStop(pSyncNode, pSyncTimer); + } } - int32_t userStrLen = strlen(str); + return ret; +} - SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0}; - if (pSyncNode->pFsm != NULL && pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { - pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); - } +int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode) { + syncNodeStopHeartbeatTimer(pSyncNode); + syncNodeStartHeartbeatTimer(pSyncNode); + return 0; +} - SyncIndex logLastIndex = SYNC_INDEX_INVALID; - SyncIndex logBeginIndex = SYNC_INDEX_INVALID; - if (pSyncNode->pLogStore != NULL) { - logLastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore); - logBeginIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore); - } - - char* pCfgStr = syncCfg2SimpleStr(&(pSyncNode->pRaftCfg->cfg)); - char* printStr = ""; - if (pCfgStr != NULL) { - printStr = pCfgStr; - } - - if (userStrLen < 256) { - char logBuf[256 + 256]; - if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { - snprintf(logBuf, sizeof(logBuf), - "vgId:%d, sync %s %s, tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 - ", snap:%" PRId64 ", snap-tm:%" PRIu64 - ", sby:%d, " - "stgy:%d, bch:%d, " - "r-num:%d, " - "lcfg:%" PRId64 ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s", - pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, - pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex, - snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy, - pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, - pSyncNode->changing, pSyncNode->restoreFinish, syncNodeDynamicQuorum(pSyncNode), - pSyncNode->electTimerLogicClock, pSyncNode->heartbeatTimerLogicClockUser, printStr); - } else { - snprintf(logBuf, sizeof(logBuf), "%s", str); - } - sError("%s", logBuf); +// utils -------------- +int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg) { + SEpSet epSet; + syncUtilraftId2EpSet(destRaftId, &epSet); + if (pSyncNode->syncSendMSg != NULL) { + // htonl + syncUtilMsgHtoN(pMsg->pCont); + pMsg->info.noResp = 1; + pSyncNode->syncSendMSg(&epSet, pMsg); } else { - int len = 256 + userStrLen; - char* s = (char*)taosMemoryMalloc(len); - if (pSyncNode != NULL && pSyncNode->pRaftCfg != NULL && pSyncNode->pRaftStore != NULL) { - snprintf(s, len, - "vgId:%d, sync %s %s, tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 - ", snap:%" PRId64 ", snap-tm:%" PRIu64 - ", sby:%d, " - "stgy:%d, bch:%d, " - "r-num:%d, " - "lcfg:%" PRId64 ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s", - pSyncNode->vgId, syncUtilState2String(pSyncNode->state), str, pSyncNode->pRaftStore->currentTerm, - pSyncNode->commitIndex, logBeginIndex, logLastIndex, pSyncNode->minMatchIndex, snapshot.lastApplyIndex, - snapshot.lastApplyTerm, pSyncNode->pRaftCfg->isStandBy, pSyncNode->pRaftCfg->snapshotStrategy, - pSyncNode->pRaftCfg->batchSize, pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, - pSyncNode->changing, pSyncNode->restoreFinish, syncNodeDynamicQuorum(pSyncNode), - pSyncNode->electTimerLogicClock, pSyncNode->heartbeatTimerLogicClockUser, printStr); - } else { - snprintf(s, len, "%s", str); - } - sError("%s", s); - taosMemoryFree(s); + sError("vgId:%d, sync send msg by id error, fp-send-msg is null", pSyncNode->vgId); + return -1; } - taosMemoryFree(pCfgStr); + return 0; } -inline char* syncNode2SimpleStr(const SSyncNode* pSyncNode) { - int len = 256; - char* s = (char*)taosMemoryMalloc(len); +int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, SRpcMsg* pMsg) { + SEpSet epSet; + syncUtilnodeInfo2EpSet(nodeInfo, &epSet); + if (pSyncNode->syncSendMSg != NULL) { + // htonl + syncUtilMsgHtoN(pMsg->pCont); - SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0}; - if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { - pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); + pMsg->info.noResp = 1; + pSyncNode->syncSendMSg(&epSet, pMsg); + } else { + sError("vgId:%d, sync send msg by info error, fp-send-msg is null", pSyncNode->vgId); } - SyncIndex logLastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore); - SyncIndex logBeginIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore); - - snprintf(s, len, - "vgId:%d, sync %s, tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", snap:%" PRId64 - ", sby:%d, " - "r-num:%d, " - "lcfg:%" PRId64 ", chging:%d, rsto:%d", - pSyncNode->vgId, syncUtilState2String(pSyncNode->state), pSyncNode->pRaftStore->currentTerm, - pSyncNode->commitIndex, logBeginIndex, logLastIndex, snapshot.lastApplyIndex, pSyncNode->pRaftCfg->isStandBy, - pSyncNode->replicaNum, pSyncNode->pRaftCfg->lastConfigIndex, pSyncNode->changing, pSyncNode->restoreFinish); - - return s; + return 0; } inline bool syncNodeInConfig(SSyncNode* pSyncNode, const SSyncCfg* config) { bool b1 = false; bool b2 = false; - for (int i = 0; i < config->replicaNum; ++i) { + for (int32_t i = 0; i < config->replicaNum; ++i) { if (strcmp((config->nodeInfo)[i].nodeFqdn, pSyncNode->myNodeInfo.nodeFqdn) == 0 && (config->nodeInfo)[i].nodePort == pSyncNode->myNodeInfo.nodePort) { b1 = true; @@ -2061,7 +1255,7 @@ inline bool syncNodeInConfig(SSyncNode* pSyncNode, const SSyncCfg* config) { } } - for (int i = 0; i < config->replicaNum; ++i) { + for (int32_t i = 0; i < config->replicaNum; ++i) { SRaftId raftId; raftId.addr = syncUtilAddr2U64((config->nodeInfo)[i].nodeFqdn, (config->nodeInfo)[i].nodePort); raftId.vgId = pSyncNode->vgId; @@ -2091,12 +1285,11 @@ static bool syncIsConfigChanged(const SSyncCfg* pOldCfg, const SSyncCfg* pNewCfg void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncIndex lastConfigChangeIndex) { SSyncCfg oldConfig = pSyncNode->pRaftCfg->cfg; -#if 1 if (!syncIsConfigChanged(&oldConfig, pNewConfig)) { sInfo("vgId:1, sync not reconfig since not changed"); return; } -#endif + pSyncNode->pRaftCfg->cfg = *pNewConfig; pSyncNode->pRaftCfg->lastConfigIndex = lastConfigChangeIndex; @@ -2119,15 +1312,11 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde } // log begin config change - do { - char eventLog[256]; - char* pOldCfgStr = syncCfg2SimpleStr(&oldConfig); - char* pNewCfgStr = syncCfg2SimpleStr(pNewConfig); - snprintf(eventLog, sizeof(eventLog), "begin do config change, from %s to %s", pOldCfgStr, pNewCfgStr); - syncNodeEventLog(pSyncNode, eventLog); - taosMemoryFree(pOldCfgStr); - taosMemoryFree(pNewCfgStr); - } while (0); + char oldCfgStr[1024] = {0}; + char newCfgStr[1024] = {0}; + syncCfg2SimpleStr(&oldConfig, oldCfgStr, sizeof(oldCfgStr)); + syncCfg2SimpleStr(pNewConfig, oldCfgStr, sizeof(oldCfgStr)); + sNTrace(pSyncNode, "begin do config change, from %s to %s", oldCfgStr, oldCfgStr); if (IamInNew) { pSyncNode->pRaftCfg->isStandBy = 0; // change isStandBy to normal @@ -2148,12 +1337,9 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde SRaftId oldReplicasId[TSDB_MAX_REPLICA]; memcpy(oldReplicasId, pSyncNode->replicasId, sizeof(oldReplicasId)); SSyncSnapshotSender* oldSenders[TSDB_MAX_REPLICA]; - for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { + for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { oldSenders[i] = (pSyncNode->senders)[i]; - - char* eventLog = snapshotSender2SimpleStr(oldSenders[i], "snapshot sender save old"); - syncNodeEventLog(pSyncNode, eventLog); - taosMemoryFree(eventLog); + sSTrace(oldSenders[i], "snapshot sender save old"); } // init internal @@ -2162,20 +1348,20 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde // init peersNum, peers, peersId pSyncNode->peersNum = pSyncNode->pRaftCfg->cfg.replicaNum - 1; - int j = 0; - for (int i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { + int32_t j = 0; + for (int32_t i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { if (i != pSyncNode->pRaftCfg->cfg.myIndex) { pSyncNode->peersNodeInfo[j] = pSyncNode->pRaftCfg->cfg.nodeInfo[i]; j++; } } - for (int i = 0; i < pSyncNode->peersNum; ++i) { + for (int32_t i = 0; i < pSyncNode->peersNum; ++i) { syncUtilnodeInfo2raftId(&pSyncNode->peersNodeInfo[i], pSyncNode->vgId, &pSyncNode->peersId[i]); } // init replicaNum, replicasId pSyncNode->replicaNum = pSyncNode->pRaftCfg->cfg.replicaNum; - for (int i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { + for (int32_t i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { syncUtilnodeInfo2raftId(&pSyncNode->pRaftCfg->cfg.nodeInfo[i], pSyncNode->vgId, &pSyncNode->replicasId[i]); } @@ -2190,26 +1376,21 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde // reset snapshot senders // clear new - for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { + for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { (pSyncNode->senders)[i] = NULL; } // reset new - for (int i = 0; i < pSyncNode->replicaNum; ++i) { + for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) { // reset sender bool reset = false; - for (int j = 0; j < TSDB_MAX_REPLICA; ++j) { + for (int32_t j = 0; j < TSDB_MAX_REPLICA; ++j) { if (syncUtilSameId(&(pSyncNode->replicasId)[i], &oldReplicasId[j])) { char host[128]; uint16_t port; syncUtilU642Addr((pSyncNode->replicasId)[i].addr, host, sizeof(host), &port); - - do { - char eventLog[256]; - snprintf(eventLog, sizeof(eventLog), "snapshot sender reset for: %" PRIu64 ", newIndex:%d, %s:%d, %p", - (pSyncNode->replicasId)[i].addr, i, host, port, oldSenders[j]); - syncNodeEventLog(pSyncNode, eventLog); - } while (0); + sNTrace(pSyncNode, "snapshot sender reset for: %" PRId64 ", newIndex:%d, %s:%d, %p", + (pSyncNode->replicasId)[i].addr, i, host, port, oldSenders[j]); (pSyncNode->senders)[i] = oldSenders[j]; oldSenders[j] = NULL; @@ -2219,39 +1400,25 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde int32_t oldreplicaIndex = (pSyncNode->senders)[i]->replicaIndex; (pSyncNode->senders)[i]->replicaIndex = i; - do { - char eventLog[256]; - snprintf(eventLog, sizeof(eventLog), - "snapshot sender udpate replicaIndex from %d to %d, %s:%d, %p, reset:%d", oldreplicaIndex, i, host, - port, (pSyncNode->senders)[i], reset); - syncNodeEventLog(pSyncNode, eventLog); - } while (0); + sNTrace(pSyncNode, "snapshot sender udpate replicaIndex from %d to %d, %s:%d, %p, reset:%d", oldreplicaIndex, + i, host, port, (pSyncNode->senders)[i], reset); } } } // create new - for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { + for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { if ((pSyncNode->senders)[i] == NULL) { (pSyncNode->senders)[i] = snapshotSenderCreate(pSyncNode, i); - - char* eventLog = snapshotSender2SimpleStr((pSyncNode->senders)[i], "snapshot sender create new"); - syncNodeEventLog(pSyncNode, eventLog); - taosMemoryFree(eventLog); + sSTrace((pSyncNode->senders)[i], "snapshot sender create new"); } } // free old - for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { + for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { if (oldSenders[i] != NULL) { snapshotSenderDestroy(oldSenders[i]); - - do { - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "snapshot sender delete old %p replica-index:%d", oldSenders[i], i); - syncNodeEventLog(pSyncNode, eventLog); - } while (0); - + sNTrace(pSyncNode, "snapshot sender delete old %p replica-index:%d", oldSenders[i], i); oldSenders[i] = NULL; } } @@ -2259,13 +1426,9 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde // persist cfg raftCfgPersist(pSyncNode->pRaftCfg); - char tmpbuf[512]; - char* oldStr = syncCfg2SimpleStr(&oldConfig); - char* newStr = syncCfg2SimpleStr(pNewConfig); + char tmpbuf[1024] = {0}; snprintf(tmpbuf, sizeof(tmpbuf), "config change from %d to %d, index:%" PRId64 ", %s --> %s", - oldConfig.replicaNum, pNewConfig->replicaNum, lastConfigChangeIndex, oldStr, newStr); - taosMemoryFree(oldStr); - taosMemoryFree(newStr); + oldConfig.replicaNum, pNewConfig->replicaNum, lastConfigChangeIndex, oldCfgStr, newCfgStr); // change isStandBy to normal (election timeout) if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { @@ -2281,49 +1444,21 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde } else { // persist cfg raftCfgPersist(pSyncNode->pRaftCfg); - - char tmpbuf[512]; - char* oldStr = syncCfg2SimpleStr(&oldConfig); - char* newStr = syncCfg2SimpleStr(pNewConfig); - snprintf(tmpbuf, sizeof(tmpbuf), "do not config change from %d to %d, index:%" PRId64 ", %s --> %s", - oldConfig.replicaNum, pNewConfig->replicaNum, lastConfigChangeIndex, oldStr, newStr); - taosMemoryFree(oldStr); - taosMemoryFree(newStr); - syncNodeEventLog(pSyncNode, tmpbuf); + sNTrace(pSyncNode, "do not config change from %d to %d, index:%" PRId64 ", %s --> %s", oldConfig.replicaNum, + pNewConfig->replicaNum, lastConfigChangeIndex, oldCfgStr, newCfgStr); } _END: - // log end config change - do { - char eventLog[256]; - char* pOldCfgStr = syncCfg2SimpleStr(&oldConfig); - char* pNewCfgStr = syncCfg2SimpleStr(pNewConfig); - snprintf(eventLog, sizeof(eventLog), "end do config change, from %s to %s", pOldCfgStr, pNewCfgStr); - syncNodeEventLog(pSyncNode, eventLog); - taosMemoryFree(pOldCfgStr); - taosMemoryFree(pNewCfgStr); - } while (0); - return; -} - -SSyncNode* syncNodeAcquire(int64_t rid) { - SSyncNode* pNode = taosAcquireRef(tsNodeRefId, rid); - if (pNode == NULL) { - sTrace("failed to acquire node from refId:%" PRId64, rid); - } - - return pNode; + sNTrace(pSyncNode, "end do config change, from %s to %s", oldCfgStr, newCfgStr); } -void syncNodeRelease(SSyncNode* pNode) { taosReleaseRef(tsNodeRefId, pNode->rid); } - // raft state change -------------- void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term) { if (term > pSyncNode->pRaftStore->currentTerm) { raftStoreSetTerm(pSyncNode->pRaftStore, term); char tmpBuf[64]; - snprintf(tmpBuf, sizeof(tmpBuf), "update term to %" PRIu64, term); + snprintf(tmpBuf, sizeof(tmpBuf), "update term to %" PRId64, term); syncNodeBecomeFollower(pSyncNode, tmpBuf); raftStoreClearVote(pSyncNode->pRaftStore); } @@ -2336,19 +1471,21 @@ void syncNodeUpdateTermWithoutStepDown(SSyncNode* pSyncNode, SyncTerm term) { } void syncNodeStepDown(SSyncNode* pSyncNode, SyncTerm newTerm) { - ASSERT(pSyncNode->pRaftStore->currentTerm <= newTerm); + if (pSyncNode->pRaftStore->currentTerm > newTerm) { + sNTrace(pSyncNode, "step down, ignore, new-term:%" PRId64 ", current-term:%" PRId64, newTerm, + pSyncNode->pRaftStore->currentTerm); + return; + } do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "step down, new-term:%" PRIu64 ", current-term:%" PRIu64, newTerm, - pSyncNode->pRaftStore->currentTerm); - syncNodeEventLog(pSyncNode, logBuf); + sNTrace(pSyncNode, "step down, new-term:%" PRId64 ", current-term:%" PRId64, newTerm, + pSyncNode->pRaftStore->currentTerm); } while (0); if (pSyncNode->pRaftStore->currentTerm < newTerm) { raftStoreSetTerm(pSyncNode->pRaftStore, newTerm); char tmpBuf[64]; - snprintf(tmpBuf, sizeof(tmpBuf), "step down, update term to %" PRIu64, newTerm); + snprintf(tmpBuf, sizeof(tmpBuf), "step down, update term to %" PRId64, newTerm); syncNodeBecomeFollower(pSyncNode, tmpBuf); raftStoreClearVote(pSyncNode->pRaftStore); @@ -2386,19 +1523,7 @@ void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr) { pSyncNode->minMatchIndex = SYNC_INDEX_INVALID; // trace log - do { - int32_t debugStrLen = strlen(debugStr); - if (debugStrLen < 256) { - char eventLog[256 + 64]; - snprintf(eventLog, sizeof(eventLog), "become follower %s", debugStr); - syncNodeEventLog(pSyncNode, eventLog); - } else { - char* eventLog = taosMemoryMalloc(debugStrLen + 64); - snprintf(eventLog, debugStrLen, "become follower %s", debugStr); - syncNodeEventLog(pSyncNode, eventLog); - taosMemoryFree(eventLog); - } - } while (0); + sNTrace(pSyncNode, "become follower %s", debugStr); } // TLA+ Spec @@ -2431,7 +1556,7 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) { // set leader cache pSyncNode->leaderCache = pSyncNode->myRaftId; - for (int i = 0; i < pSyncNode->pNextIndex->replicaNum; ++i) { + for (int32_t i = 0; i < pSyncNode->pNextIndex->replicaNum; ++i) { // maybe overwrite myself, no harm // just do it! @@ -2445,7 +1570,7 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) { pSyncNode->pNextIndex->index[i] = lastIndex + 1; } - for (int i = 0; i < pSyncNode->pMatchIndex->replicaNum; ++i) { + for (int32_t i = 0; i < pSyncNode->pMatchIndex->replicaNum; ++i) { // maybe overwrite myself, no harm // just do it! pSyncNode->pMatchIndex->index[i] = SYNC_INDEX_INVALID; @@ -2454,16 +1579,18 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) { // init peer mgr syncNodePeerStateInit(pSyncNode); +#if 0 // update sender private term SSyncSnapshotSender* pMySender = syncNodeGetSnapshotSender(pSyncNode, &(pSyncNode->myRaftId)); if (pMySender != NULL) { - for (int i = 0; i < pSyncNode->pMatchIndex->replicaNum; ++i) { + for (int32_t i = 0; i < pSyncNode->pMatchIndex->replicaNum; ++i) { if ((pSyncNode->senders)[i]->privateTerm > pMySender->privateTerm) { pMySender->privateTerm = (pSyncNode->senders)[i]->privateTerm; } } (pMySender->privateTerm) += 100; } +#endif // close receiver if (snapshotReceiverIsStart(pSyncNode->pNewNodeReceiver)) { @@ -2488,19 +1615,7 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) { pSyncNode->minMatchIndex = SYNC_INDEX_INVALID; // trace log - do { - int32_t debugStrLen = strlen(debugStr); - if (debugStrLen < 256) { - char eventLog[256 + 64]; - snprintf(eventLog, sizeof(eventLog), "become leader %s", debugStr); - syncNodeEventLog(pSyncNode, eventLog); - } else { - char* eventLog = taosMemoryMalloc(debugStrLen + 64); - snprintf(eventLog, debugStrLen, "become leader %s", debugStr); - syncNodeEventLog(pSyncNode, eventLog); - taosMemoryFree(eventLog); - } - } while (0); + sNTrace(pSyncNode, "become leader %s", debugStr); } void syncNodeCandidate2Leader(SSyncNode* pSyncNode) { @@ -2508,7 +1623,7 @@ void syncNodeCandidate2Leader(SSyncNode* pSyncNode) { ASSERT(voteGrantedMajority(pSyncNode->pVotesGranted)); syncNodeBecomeLeader(pSyncNode, "candidate to leader"); - syncNodeLog2("==state change syncNodeCandidate2Leader==", pSyncNode); + sNTrace(pSyncNode, "state change syncNodeCandidate2Leader"); // Raft 3.6.2 Committing entries from previous terms syncNodeAppendNoop(pSyncNode); @@ -2522,7 +1637,7 @@ void syncNodeCandidate2Leader(SSyncNode* pSyncNode) { bool syncNodeIsMnode(SSyncNode* pSyncNode) { return (pSyncNode->vgId == 1); } int32_t syncNodePeerStateInit(SSyncNode* pSyncNode) { - for (int i = 0; i < TSDB_MAX_REPLICA; ++i) { + for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { pSyncNode->peerStates[i].lastSendIndex = SYNC_INDEX_INVALID; pSyncNode->peerStates[i].lastSendTime = 0; } @@ -2533,22 +1648,19 @@ int32_t syncNodePeerStateInit(SSyncNode* pSyncNode) { void syncNodeFollower2Candidate(SSyncNode* pSyncNode) { ASSERT(pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER); pSyncNode->state = TAOS_SYNC_STATE_CANDIDATE; - - syncNodeEventLog(pSyncNode, "follower to candidate"); + sNTrace(pSyncNode, "follower to candidate"); } void syncNodeLeader2Follower(SSyncNode* pSyncNode) { ASSERT(pSyncNode->state == TAOS_SYNC_STATE_LEADER); syncNodeBecomeFollower(pSyncNode, "leader to follower"); - - syncNodeEventLog(pSyncNode, "leader to follower"); + sNTrace(pSyncNode, "leader to follower"); } void syncNodeCandidate2Follower(SSyncNode* pSyncNode) { ASSERT(pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE); syncNodeBecomeFollower(pSyncNode, "candidate to follower"); - - syncNodeEventLog(pSyncNode, "candidate to follower"); + sNTrace(pSyncNode, "candidate to follower"); } // raft vote -------------- @@ -2692,14 +1804,8 @@ SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) { } } - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), - "sync node get pre term error, index:%" PRId64 ", snap-index:%" PRId64 ", snap-term:%" PRIu64, index, - snapshot.lastApplyIndex, snapshot.lastApplyTerm); - syncNodeErrorLog(pSyncNode, logBuf); - } while (0); - + sNError(pSyncNode, "sync node get pre term error, index:%" PRId64 ", snap-index:%" PRId64 ", snap-term:%" PRId64, + index, snapshot.lastApplyIndex, snapshot.lastApplyTerm); return SYNC_TERM_INVALID; } @@ -2710,43 +1816,6 @@ int32_t syncNodeGetPreIndexTerm(SSyncNode* pSyncNode, SyncIndex index, SyncIndex return 0; } -// for debug -------------- -void syncNodePrint(SSyncNode* pObj) { - char* serialized = syncNode2Str(pObj); - printf("syncNodePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncNodePrint2(char* s, SSyncNode* pObj) { - char* serialized = syncNode2Str(pObj); - printf("syncNodePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncNodeLog(SSyncNode* pObj) { - char* serialized = syncNode2Str(pObj); - sTraceLong("syncNodeLog | len:%d | %s", (int32_t)strlen(serialized), serialized); - taosMemoryFree(serialized); -} - -void syncNodeLog2(char* s, SSyncNode* pObj) { - if (gRaftDetailLog) { - char* serialized = syncNode2Str(pObj); - sTraceLong("syncNodeLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); - taosMemoryFree(serialized); - } -} - -void syncNodeLog3(char* s, SSyncNode* pObj) { - char* serialized = syncNode2Str(pObj); - sTraceLong("syncNodeLog3 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); - taosMemoryFree(serialized); -} - -// ------ local funciton --------- -// enqueue message ---- static void syncNodeEqPingTimer(void* param, void* tmrId) { SSyncNode* pSyncNode = (SSyncNode*)param; if (atomic_load_64(&pSyncNode->pingTimerLogicClockUser) <= atomic_load_64(&pSyncNode->pingTimerLogicClock)) { @@ -2754,9 +1823,9 @@ static void syncNodeEqPingTimer(void* param, void* tmrId) { pSyncNode->pingTimerMS, pSyncNode->vgId, pSyncNode); SRpcMsg rpcMsg; syncTimeout2RpcMsg(pSyncMsg, &rpcMsg); - syncRpcMsgLog2((char*)"==syncNodeEqPingTimer==", &rpcMsg); - if (pSyncNode->FpEqMsg != NULL) { - int32_t code = pSyncNode->FpEqMsg(pSyncNode->msgcb, &rpcMsg); + sNTrace(pSyncNode, "enqueue ping timer"); + if (pSyncNode->syncEqMsg != NULL) { + int32_t code = pSyncNode->syncEqMsg(pSyncNode->msgcb, &rpcMsg); if (code != 0) { sError("vgId:%d, sync enqueue ping msg error, code:%d", pSyncNode->vgId, code); rpcFreeCont(rpcMsg.pCont); @@ -2764,19 +1833,19 @@ static void syncNodeEqPingTimer(void* param, void* tmrId) { return; } } else { - sTrace("syncNodeEqPingTimer pSyncNode->FpEqMsg is NULL"); + sTrace("syncNodeEqPingTimer pSyncNode->syncEqMsg is NULL"); } syncTimeoutDestroy(pSyncMsg); - if (syncEnvIsStart()) { - taosTmrReset(syncNodeEqPingTimer, pSyncNode->pingTimerMS, pSyncNode, gSyncEnv->pTimerManager, + if (syncIsInit()) { + taosTmrReset(syncNodeEqPingTimer, pSyncNode->pingTimerMS, pSyncNode, syncEnv()->pTimerManager, &pSyncNode->pPingTimer); } else { sError("sync env is stop, syncNodeEqPingTimer"); } } else { - sTrace("==syncNodeEqPingTimer== pingTimerLogicClock:%" PRIu64 ", pingTimerLogicClockUser:%" PRIu64, + sTrace("==syncNodeEqPingTimer== pingTimerLogicClock:%" PRId64 ", pingTimerLogicClockUser:%" PRId64, pSyncNode->pingTimerLogicClock, pSyncNode->pingTimerLogicClockUser); } } @@ -2789,8 +1858,8 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) { pSyncNode->vgId, pSyncNode); SRpcMsg rpcMsg; syncTimeout2RpcMsg(pSyncMsg, &rpcMsg); - if (pSyncNode->FpEqMsg != NULL) { - int32_t code = pSyncNode->FpEqMsg(pSyncNode->msgcb, &rpcMsg); + if (pSyncNode->syncEqMsg != NULL && pSyncNode->msgcb != NULL && pSyncNode->msgcb->putToQueueFp != NULL) { + int32_t code = pSyncNode->syncEqMsg(pSyncNode->msgcb, &rpcMsg); if (code != 0) { sError("vgId:%d, sync enqueue elect msg error, code:%d", pSyncNode->vgId, code); rpcFreeCont(rpcMsg.pCont); @@ -2798,15 +1867,9 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) { taosMemoryFree(pElectTimer); return; } - - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "eq elect timer lc:%" PRIu64, pSyncMsg->logicClock); - syncNodeEventLog(pSyncNode, logBuf); - } while (0); - + sNTrace(pSyncNode, "eq elect timer lc:%" PRId64, pSyncMsg->logicClock); } else { - sTrace("syncNodeEqElectTimer FpEqMsg is NULL"); + sTrace("syncNodeEqElectTimer syncEqMsg is NULL"); } syncTimeoutDestroy(pSyncMsg); @@ -2814,9 +1877,9 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) { #if 0 // reset timer ms - if (syncEnvIsStart() && pSyncNode->electBaseLine > 0) { + if (syncIsInit() && pSyncNode->electBaseLine > 0) { pSyncNode->electTimerMS = syncUtilElectRandomMS(pSyncNode->electBaseLine, 2 * pSyncNode->electBaseLine); - taosTmrReset(syncNodeEqElectTimer, pSyncNode->electTimerMS, pSyncNode, gSyncEnv->pTimerManager, + taosTmrReset(syncNodeEqElectTimer, pSyncNode->electTimerMS, pSyncNode, syncEnv()->pTimerManager, &pSyncNode->pElectTimer); } else { sError("sync env is stop, syncNodeEqElectTimer"); @@ -2826,8 +1889,7 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) { static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) { SSyncNode* pSyncNode = (SSyncNode*)param; - - syncNodeEventLog(pSyncNode, "eq hb timer"); + sNTrace(pSyncNode, "eq hb timer"); if (pSyncNode->replicaNum > 1) { if (atomic_load_64(&pSyncNode->heartbeatTimerLogicClockUser) <= @@ -2837,9 +1899,9 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) { pSyncNode->heartbeatTimerMS, pSyncNode->vgId, pSyncNode); SRpcMsg rpcMsg; syncTimeout2RpcMsg(pSyncMsg, &rpcMsg); - syncRpcMsgLog2((char*)"==syncNodeEqHeartbeatTimer==", &rpcMsg); - if (pSyncNode->FpEqMsg != NULL) { - int32_t code = pSyncNode->FpEqMsg(pSyncNode->msgcb, &rpcMsg); + sNTrace(pSyncNode, "enqueue heartbeat timer"); + if (pSyncNode->syncEqMsg != NULL) { + int32_t code = pSyncNode->syncEqMsg(pSyncNode->msgcb, &rpcMsg); if (code != 0) { sError("vgId:%d, sync enqueue timer msg error, code:%d", pSyncNode->vgId, code); rpcFreeCont(rpcMsg.pCont); @@ -2847,18 +1909,18 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) { return; } } else { - sError("vgId:%d, enqueue msg cb ptr (i.e. FpEqMsg) not set.", pSyncNode->vgId); + sError("vgId:%d, enqueue msg cb ptr (i.e. syncEqMsg) not set.", pSyncNode->vgId); } syncTimeoutDestroy(pSyncMsg); - if (syncEnvIsStart()) { - taosTmrReset(syncNodeEqHeartbeatTimer, pSyncNode->heartbeatTimerMS, pSyncNode, gSyncEnv->pTimerManager, + if (syncIsInit()) { + taosTmrReset(syncNodeEqHeartbeatTimer, pSyncNode->heartbeatTimerMS, pSyncNode, syncEnv()->pTimerManager, &pSyncNode->pHeartbeatTimer); } else { sError("sync env is stop, syncNodeEqHeartbeatTimer"); } } else { - sTrace("==syncNodeEqHeartbeatTimer== heartbeatTimerLogicClock:%" PRIu64 ", heartbeatTimerLogicClockUser:%" PRIu64 + sTrace("==syncNodeEqHeartbeatTimer== heartbeatTimerLogicClock:%" PRId64 ", heartbeatTimerLogicClockUser:%" PRId64 "", pSyncNode->heartbeatTimerLogicClock, pSyncNode->heartbeatTimerLogicClockUser); } @@ -2870,11 +1932,19 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) { SSyncNode* pSyncNode = pData->pSyncNode; SSyncTimer* pSyncTimer = pData->pTimer; + if (pSyncNode == NULL) { + return; + } + if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) { return; } - // syncNodeEventLog(pSyncNode, "eq peer hb timer"); + if (pSyncNode->pRaftStore == NULL) { + return; + } + + // sNTrace(pSyncNode, "eq peer hb timer"); int64_t timerLogicClock = atomic_load_64(&pSyncTimer->logicClock); int64_t msgLogicClock = atomic_load_64(&pData->logicClock); @@ -2894,8 +1964,8 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) { // eq msg #if 0 - if (pSyncNode->FpEqCtrlMsg != NULL) { - int32_t code = pSyncNode->FpEqCtrlMsg(pSyncNode->msgcb, &rpcMsg); + if (pSyncNode->syncEqCtrlMsg != NULL) { + int32_t code = pSyncNode->syncEqCtrlMsg(pSyncNode->msgcb, &rpcMsg); if (code != 0) { sError("vgId:%d, sync ctrl enqueue timer msg error, code:%d", pSyncNode->vgId, code); rpcFreeCont(rpcMsg.pCont); @@ -2903,7 +1973,7 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) { return; } } else { - sError("vgId:%d, enqueue ctrl msg cb ptr (i.e. FpEqMsg) not set.", pSyncNode->vgId); + sError("vgId:%d, enqueue ctrl msg cb ptr (i.e. syncEqMsg) not set.", pSyncNode->vgId); } #endif @@ -2912,55 +1982,49 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) { syncHeartbeatDestroy(pSyncMsg); - if (syncEnvIsStart()) { - taosTmrReset(syncNodeEqPeerHeartbeatTimer, pSyncTimer->timerMS, pData, gSyncEnv->pTimerManager, + if (syncIsInit()) { + taosTmrReset(syncNodeEqPeerHeartbeatTimer, pSyncTimer->timerMS, pData, syncEnv()->pTimerManager, &pSyncTimer->pTimer); } else { sError("sync env is stop, syncNodeEqHeartbeatTimer"); } } else { - sTrace("==syncNodeEqPeerHeartbeatTimer== timerLogicClock:%" PRIu64 ", msgLogicClock:%" PRIu64 "", timerLogicClock, + sTrace("==syncNodeEqPeerHeartbeatTimer== timerLogicClock:%" PRId64 ", msgLogicClock:%" PRId64 "", timerLogicClock, msgLogicClock); } } } -static int32_t syncNodeEqNoop(SSyncNode* ths) { - int32_t ret = 0; - ASSERT(ths->state == TAOS_SYNC_STATE_LEADER); - - SyncIndex index = ths->pLogStore->syncLogWriteIndex(ths->pLogStore); - SyncTerm term = ths->pRaftStore->currentTerm; - SSyncRaftEntry* pEntry = syncEntryBuildNoop(term, index, ths->vgId); - ASSERT(pEntry != NULL); +static int32_t syncNodeEqNoop(SSyncNode* pNode) { + if (pNode->state == TAOS_SYNC_STATE_LEADER) { + terrno = TSDB_CODE_SYN_NOT_LEADER; + return -1; + } - uint32_t entryLen; - char* serialized = syncEntrySerialize(pEntry, &entryLen); - SyncClientRequest* pSyncMsg = syncClientRequestBuild(entryLen); - ASSERT(pSyncMsg->dataLen == entryLen); - memcpy(pSyncMsg->data, serialized, entryLen); + SyncIndex index = pNode->pLogStore->syncLogWriteIndex(pNode->pLogStore); + SyncTerm term = pNode->pRaftStore->currentTerm; + SSyncRaftEntry* pEntry = syncEntryBuildNoop(term, index, pNode->vgId); + if (pEntry == NULL) return -1; SRpcMsg rpcMsg = {0}; - syncClientRequest2RpcMsg(pSyncMsg, &rpcMsg); - if (ths->FpEqMsg != NULL) { - ths->FpEqMsg(ths->msgcb, &rpcMsg); - } else { - sTrace("syncNodeEqNoop pSyncNode->FpEqMsg is NULL"); - } - + int32_t code = syncClientRequestBuildFromNoopEntry(&rpcMsg, pEntry, pNode->vgId); syncEntryDestory(pEntry); - taosMemoryFree(serialized); - syncClientRequestDestroy(pSyncMsg); - return ret; + sNTrace(pNode, "propose msg, type:noop"); + code = (*pNode->syncEqMsg)(pNode->msgcb, &rpcMsg); + if (code != 0) { + sNError(pNode, "failed to propose noop msg while enqueue since %s", terrstr()); + } + + return code; } static void deleteCacheEntry(const void* key, size_t keyLen, void* value) { taosMemoryFree(value); } static int32_t syncCacheEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry, LRUHandle** h) { - int code = 0; - int entryLen = sizeof(*pEntry) + pEntry->dataLen; + int32_t code = 0; + int32_t entryLen = sizeof(*pEntry) + pEntry->dataLen; LRUStatus status = taosLRUCacheInsert(pLogStore->pCache, &pEntry->index, sizeof(pEntry->index), pEntry, entryLen, deleteCacheEntry, h, TAOS_LRU_PRIORITY_LOW); if (status != TAOS_LRU_STATUS_OK) { @@ -2984,7 +2048,7 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths) { if (ths->state == TAOS_SYNC_STATE_LEADER) { int32_t code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pEntry); if (code != 0) { - syncNodeErrorLog(ths, "append noop error"); + sNError(ths, "append noop error"); return -1; } } @@ -2999,18 +2063,19 @@ static int32_t syncNodeAppendNoop(SSyncNode* ths) { } // on message ---- -int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg) { - // log state +int32_t syncNodeOnPing(SSyncNode* ths, SyncPing* pMsg) { + sTrace("vgId:%d, recv sync-ping", ths->vgId); + SyncPingReply* pMsgReply = syncPingReplyBuild3(&ths->myRaftId, &pMsg->srcId, ths->vgId); SRpcMsg rpcMsg; syncPingReply2RpcMsg(pMsgReply, &rpcMsg); /* - // htonl - SMsgHead* pHead = rpcMsg.pCont; - pHead->contLen = htonl(pHead->contLen); - pHead->vgId = htonl(pHead->vgId); -*/ + // htonl + SMsgHead* pHead = rpcMsg.pCont; + pHead->contLen = htonl(pHead->contLen); + pHead->vgId = htonl(pHead->vgId); + */ syncNodeSendMsgById(&pMsgReply->destId, ths, &rpcMsg); syncPingReplyDestroy(pMsgReply); @@ -3018,9 +2083,9 @@ int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg) { return 0; } -int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg) { +int32_t syncNodeOnPingReply(SSyncNode* ths, SyncPingReply* pMsg) { int32_t ret = 0; - syncPingReplyLog2("==syncNodeOnPingReplyCb==", pMsg); + sTrace("vgId:%d, recv sync-ping-reply", ths->vgId); return ret; } @@ -3036,21 +2101,51 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg) { SRpcMsg rpcMsg; syncHeartbeatReply2RpcMsg(pMsgReply, &rpcMsg); -#if 1 - if (pMsg->term >= ths->pRaftStore->currentTerm && ths->state != TAOS_SYNC_STATE_FOLLOWER) { - syncNodeStepDown(ths, pMsg->term); - } -#endif - if (pMsg->term == ths->pRaftStore->currentTerm && ths->state != TAOS_SYNC_STATE_LEADER) { syncNodeResetElectTimer(ths); ths->minMatchIndex = pMsg->minMatchIndex; -#if 0 if (ths->state == TAOS_SYNC_STATE_FOLLOWER) { - syncNodeFollowerCommit(ths, pMsg->commitIndex); + // syncNodeFollowerCommit(ths, pMsg->commitIndex); + SyncLocalCmd* pSyncMsg = syncLocalCmdBuild(ths->vgId); + pSyncMsg->cmd = SYNC_LOCAL_CMD_FOLLOWER_CMT; + pSyncMsg->fcIndex = pMsg->commitIndex; + + SRpcMsg rpcMsgLocalCmd; + syncLocalCmd2RpcMsg(pSyncMsg, &rpcMsgLocalCmd); + + if (ths->syncEqMsg != NULL && ths->msgcb != NULL) { + int32_t code = ths->syncEqMsg(ths->msgcb, &rpcMsgLocalCmd); + if (code != 0) { + sError("vgId:%d, sync enqueue fc-commit msg error, code:%d", ths->vgId, code); + rpcFreeCont(rpcMsgLocalCmd.pCont); + } else { + sTrace("vgId:%d, sync enqueue fc-commit msg, fc-index:%" PRId64, ths->vgId, pSyncMsg->fcIndex); + } + } } -#endif + } + + if (pMsg->term >= ths->pRaftStore->currentTerm && ths->state != TAOS_SYNC_STATE_FOLLOWER) { + // syncNodeStepDown(ths, pMsg->term); + SyncLocalCmd* pSyncMsg = syncLocalCmdBuild(ths->vgId); + pSyncMsg->cmd = SYNC_LOCAL_CMD_STEP_DOWN; + pSyncMsg->sdNewTerm = pMsg->term; + + SRpcMsg rpcMsgLocalCmd; + syncLocalCmd2RpcMsg(pSyncMsg, &rpcMsgLocalCmd); + + if (ths->syncEqMsg != NULL && ths->msgcb != NULL) { + int32_t code = ths->syncEqMsg(ths->msgcb, &rpcMsgLocalCmd); + if (code != 0) { + sError("vgId:%d, sync enqueue step-down msg error, code:%d", ths->vgId, code); + rpcFreeCont(rpcMsgLocalCmd.pCont); + } else { + sTrace("vgId:%d, sync enqueue step-down msg, new-term: %" PRId64, ths->vgId, pSyncMsg->sdNewTerm); + } + } + + syncLocalCmdDestroy(pSyncMsg); } /* @@ -3076,6 +2171,22 @@ int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, SyncHeartbeatReply* pMsg) { return 0; } +int32_t syncNodeOnLocalCmd(SSyncNode* ths, SyncLocalCmd* pMsg) { + syncLogRecvLocalCmd(ths, pMsg, ""); + + if (pMsg->cmd == SYNC_LOCAL_CMD_STEP_DOWN) { + syncNodeStepDown(ths, pMsg->sdNewTerm); + + } else if (pMsg->cmd == SYNC_LOCAL_CMD_FOLLOWER_CMT) { + syncNodeFollowerCommit(ths, pMsg->fcIndex); + + } else { + sNError(ths, "error local cmd"); + } + + return 0; +} + // TLA+ Spec // ClientRequest(i, v) == // /\ state[i] = Leader @@ -3087,16 +2198,21 @@ int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, SyncHeartbeatReply* pMsg) { // leaderVars, commitIndex>> // -int32_t syncNodeOnClientRequest(SSyncNode* ths, SyncClientRequest* pMsg, SyncIndex* pRetIndex) { - syncNodeEventLog(ths, "on client request"); +int32_t syncNodeOnClientRequest(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRetIndex) { + sNTrace(ths, "on client request"); int32_t ret = 0; int32_t code = 0; SyncIndex index = ths->pLogStore->syncLogWriteIndex(ths->pLogStore); SyncTerm term = ths->pRaftStore->currentTerm; - SSyncRaftEntry* pEntry = syncEntryBuild2((SyncClientRequest*)pMsg, term, index); - ASSERT(pEntry != NULL); + SSyncRaftEntry* pEntry; + + if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) { + pEntry = syncEntryBuildFromClientRequest(pMsg->pCont, term, index); + } else { + pEntry = syncEntryBuildFromRpcMsg(pMsg, term, index); + } LRUHandle* h = NULL; syncCacheEntry(ths->pLogStore, pEntry, &h); @@ -3105,9 +2221,38 @@ int32_t syncNodeOnClientRequest(SSyncNode* ths, SyncClientRequest* pMsg, SyncInd // append entry code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pEntry); if (code != 0) { - // del resp mgr, call FpCommitCb - ASSERT(0); - return -1; + if (ths->replicaNum == 1) { + if (h) { + taosLRUCacheRelease(ths->pLogStore->pCache, h, false); + } else { + syncEntryDestory(pEntry); + } + + return -1; + + } else { + // del resp mgr, call FpCommitCb + SFsmCbMeta cbMeta = { + .index = pEntry->index, + .lastConfigIndex = SYNC_INDEX_INVALID, + .isWeak = pEntry->isWeak, + .code = -1, + .state = ths->state, + .seqNum = pEntry->seqNum, + .term = pEntry->term, + .currentTerm = ths->pRaftStore->currentTerm, + .flag = 0, + }; + ths->pFsm->FpCommitCb(ths->pFsm, pMsg, &cbMeta); + + if (h) { + taosLRUCacheRelease(ths->pLogStore->pCache, h, false); + } else { + syncEntryDestory(pEntry); + } + + return -1; + } } // if mulit replica, start replicate right now @@ -3117,7 +2262,11 @@ int32_t syncNodeOnClientRequest(SSyncNode* ths, SyncClientRequest* pMsg, SyncInd // if only myself, maybe commit right now if (ths->replicaNum == 1) { - syncMaybeAdvanceCommitIndex(ths); + if (syncNodeIsMnode(ths)) { + syncMaybeAdvanceCommitIndex(ths); + } else { + syncOneReplicaAdvance(ths); + } } } @@ -3153,43 +2302,34 @@ const char* syncStr(ESyncState state) { int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* pEntry) { if (ths->state != TAOS_SYNC_STATE_FOLLOWER) { - syncNodeEventLog(ths, "I am not follower, can not do leader transfer"); + sNTrace(ths, "I am not follower, can not do leader transfer"); return 0; } if (!ths->restoreFinish) { - syncNodeEventLog(ths, "restore not finish, can not do leader transfer"); + sNTrace(ths, "restore not finish, can not do leader transfer"); return 0; } if (pEntry->term < ths->pRaftStore->currentTerm) { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "little term:%" PRIu64 ", can not do leader transfer", pEntry->term); - syncNodeEventLog(ths, logBuf); + sNTrace(ths, "little term:%" PRId64 ", can not do leader transfer", pEntry->term); return 0; } if (pEntry->index < syncNodeGetLastIndex(ths)) { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "little index:%" PRId64 ", can not do leader transfer", pEntry->index); - syncNodeEventLog(ths, logBuf); + sNTrace(ths, "little index:%" PRId64 ", can not do leader transfer", pEntry->index); return 0; } /* if (ths->vgId > 1) { - syncNodeEventLog(ths, "I am vnode, can not do leader transfer"); + sNTrace(ths, "I am vnode, can not do leader transfer"); return 0; } */ SyncLeaderTransfer* pSyncLeaderTransfer = syncLeaderTransferFromRpcMsg2(pRpcMsg); - - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "do leader transfer, index:%" PRId64, pEntry->index); - syncNodeEventLog(ths, logBuf); - } while (0); + sNTrace(ths, "do leader transfer, index:%" PRId64, pEntry->index); bool sameId = syncUtilSameId(&(pSyncLeaderTransfer->newLeaderId), &(ths->myRaftId)); bool sameNodeInfo = strcmp(pSyncLeaderTransfer->newNodeInfo.nodeFqdn, ths->myNodeInfo.nodeFqdn) == 0 && @@ -3202,25 +2342,23 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p int32_t ret = syncNodeRestartElectTimer(ths, electMS); ASSERT(ret == 0); - char eventLog[256]; - snprintf(eventLog, sizeof(eventLog), "maybe leader transfer to %s:%d %" PRIu64, - pSyncLeaderTransfer->newNodeInfo.nodeFqdn, pSyncLeaderTransfer->newNodeInfo.nodePort, - pSyncLeaderTransfer->newLeaderId.addr); - syncNodeEventLog(ths, eventLog); + sNTrace(ths, "maybe leader transfer to %s:%d %" PRId64, pSyncLeaderTransfer->newNodeInfo.nodeFqdn, + pSyncLeaderTransfer->newNodeInfo.nodePort, pSyncLeaderTransfer->newLeaderId.addr); } if (ths->pFsm->FpLeaderTransferCb != NULL) { - SFsmCbMeta cbMeta = {0}; - cbMeta.code = 0; - cbMeta.currentTerm = ths->pRaftStore->currentTerm; - cbMeta.flag = 0; - cbMeta.index = pEntry->index; - cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, cbMeta.index); - cbMeta.isWeak = pEntry->isWeak; - cbMeta.seqNum = pEntry->seqNum; - cbMeta.state = ths->state; - cbMeta.term = pEntry->term; - ths->pFsm->FpLeaderTransferCb(ths->pFsm, pRpcMsg, cbMeta); + SFsmCbMeta cbMeta = { + .code = 0, + .currentTerm = ths->pRaftStore->currentTerm, + .flag = 0, + .index = pEntry->index, + .lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, pEntry->index), + .isWeak = pEntry->isWeak, + .seqNum = pEntry->seqNum, + .state = ths->state, + .term = pEntry->term, + }; + ths->pFsm->FpLeaderTransferCb(ths->pFsm, pRpcMsg, &cbMeta); } syncLeaderTransferDestroy(pSyncLeaderTransfer); @@ -3228,7 +2366,7 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p } int32_t syncNodeUpdateNewConfigIndex(SSyncNode* ths, SSyncCfg* pNewCfg) { - for (int i = 0; i < pNewCfg->replicaNum; ++i) { + for (int32_t i = 0; i < pNewCfg->replicaNum; ++i) { SRaftId raftId; raftId.addr = syncUtilAddr2U64((pNewCfg->nodeInfo)[i].nodeFqdn, (pNewCfg->nodeInfo)[i].nodePort); raftId.vgId = ths->vgId; @@ -3242,89 +2380,6 @@ int32_t syncNodeUpdateNewConfigIndex(SSyncNode* ths, SSyncCfg* pNewCfg) { return -1; } -static int32_t syncNodeConfigChangeFinish(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* pEntry) { - SyncReconfigFinish* pFinish = syncReconfigFinishFromRpcMsg2(pRpcMsg); - ASSERT(pFinish); - - if (ths->pFsm->FpReConfigCb != NULL) { - SReConfigCbMeta cbMeta = {0}; - cbMeta.code = 0; - cbMeta.index = pEntry->index; - cbMeta.term = pEntry->term; - cbMeta.seqNum = pEntry->seqNum; - cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, pEntry->index); - cbMeta.state = ths->state; - cbMeta.currentTerm = ths->pRaftStore->currentTerm; - cbMeta.isWeak = pEntry->isWeak; - cbMeta.flag = 0; - - cbMeta.oldCfg = pFinish->oldCfg; - cbMeta.newCfg = pFinish->newCfg; - cbMeta.newCfgIndex = pFinish->newCfgIndex; - cbMeta.newCfgTerm = pFinish->newCfgTerm; - cbMeta.newCfgSeqNum = pFinish->newCfgSeqNum; - - ths->pFsm->FpReConfigCb(ths->pFsm, pRpcMsg, &cbMeta); - } - - // clear changing - ths->changing = false; - - char tmpbuf[512]; - char* oldStr = syncCfg2SimpleStr(&(pFinish->oldCfg)); - char* newStr = syncCfg2SimpleStr(&(pFinish->newCfg)); - snprintf(tmpbuf, sizeof(tmpbuf), "config change finish from %d to %d, index:%" PRId64 ", %s --> %s", - pFinish->oldCfg.replicaNum, pFinish->newCfg.replicaNum, pFinish->newCfgIndex, oldStr, newStr); - taosMemoryFree(oldStr); - taosMemoryFree(newStr); - syncNodeEventLog(ths, tmpbuf); - - syncReconfigFinishDestroy(pFinish); - - return 0; -} - -static int32_t syncNodeConfigChange(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* pEntry, - SyncReconfigFinish* pFinish) { - // set changing - ths->changing = true; - - // old config - SSyncCfg oldSyncCfg = ths->pRaftCfg->cfg; - - // new config - SSyncCfg newSyncCfg; - int32_t ret = syncCfgFromStr(pRpcMsg->pCont, &newSyncCfg); - ASSERT(ret == 0); - - // update new config myIndex - syncNodeUpdateNewConfigIndex(ths, &newSyncCfg); - - // do config change - syncNodeDoConfigChange(ths, &newSyncCfg, pEntry->index); - - // set pFinish - pFinish->oldCfg = oldSyncCfg; - pFinish->newCfg = newSyncCfg; - pFinish->newCfgIndex = pEntry->index; - pFinish->newCfgTerm = pEntry->term; - pFinish->newCfgSeqNum = pEntry->seqNum; - - return 0; -} - -static int32_t syncNodeProposeConfigChangeFinish(SSyncNode* ths, SyncReconfigFinish* pFinish) { - SRpcMsg rpcMsg; - syncReconfigFinish2RpcMsg(pFinish, &rpcMsg); - - int32_t code = syncNodePropose(ths, &rpcMsg, false); - if (code != 0) { - sError("syncNodeProposeConfigChangeFinish error"); - ths->changing = false; - } - return 0; -} - bool syncNodeIsOptimizedOneReplica(SSyncNode* ths, SRpcMsg* pMsg) { return (ths->replicaNum == 1 && syncUtilUserCommit(pMsg->msgType) && ths->vgId != 1); } @@ -3343,10 +2398,7 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde SSnapshot snapshot = {0}; ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot); if (snapshot.lastApplyIndex >= 0 && snapshot.lastApplyIndex >= beginIndex) { - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "commit by snapshot from index:%" PRId64 " to index:%" PRId64, beginIndex, - snapshot.lastApplyIndex); - syncNodeEventLog(ths, eventLog); + sNTrace(ths, "commit by snapshot from index:%" PRId64 " to index:%" PRId64, beginIndex, snapshot.lastApplyIndex); // update begin index beginIndex = snapshot.lastApplyIndex + 1; @@ -3356,9 +2408,7 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde int32_t code = 0; ESyncState state = flag; - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "commit by wal from index:%" PRId64 " to index:%" PRId64, beginIndex, endIndex); - syncNodeEventLog(ths, eventLog); + sNTrace(ths, "commit by wal from index:%" PRId64 " to index:%" PRId64, beginIndex, endIndex); // execute fsm if (ths->pFsm != NULL) { @@ -3371,11 +2421,16 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde pEntry = (SSyncRaftEntry*)taosLRUCacheValue(pCache, h); } else { code = ths->pLogStore->syncLogGetEntry(ths->pLogStore, i, &pEntry); - ASSERT(code == 0); - ASSERT(pEntry != NULL); + // ASSERT(code == 0); + // ASSERT(pEntry != NULL); + if (code != 0 || pEntry == NULL) { + sNError(ths, "get log entry error"); + sFatal("vgId:%d, get log entry %" PRId64 " error when commit since %s", ths->vgId, i, terrstr()); + continue; + } } - SRpcMsg rpcMsg; + SRpcMsg rpcMsg = {0}; syncEntry2OriginalRpc(pEntry, &rpcMsg); // user commit @@ -3385,48 +2440,24 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde internalExecute = false; } - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "commit index:%" PRId64 ", internal:%d", i, internalExecute); - syncNodeEventLog(ths, logBuf); - } while (0); + sNTrace(ths, "commit index:%" PRId64 ", internal:%d", i, internalExecute); // execute fsm in apply thread, or execute outside syncPropose if (internalExecute) { - SFsmCbMeta cbMeta = {0}; - cbMeta.index = pEntry->index; - cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, cbMeta.index); - cbMeta.isWeak = pEntry->isWeak; - cbMeta.code = 0; - cbMeta.state = ths->state; - cbMeta.seqNum = pEntry->seqNum; - cbMeta.term = pEntry->term; - cbMeta.currentTerm = ths->pRaftStore->currentTerm; - cbMeta.flag = flag; - - ths->pFsm->FpCommitCb(ths->pFsm, &rpcMsg, cbMeta); - } - } - - // config change - if (pEntry->originalRpcType == TDMT_SYNC_CONFIG_CHANGE) { - SyncReconfigFinish* pFinish = syncReconfigFinishBuild(ths->vgId); - ASSERT(pFinish != NULL); - - code = syncNodeConfigChange(ths, &rpcMsg, pEntry, pFinish); - ASSERT(code == 0); - - if (ths->state == TAOS_SYNC_STATE_LEADER) { - syncNodeProposeConfigChangeFinish(ths, pFinish); - } - syncReconfigFinishDestroy(pFinish); - } - - // config change finish - if (pEntry->originalRpcType == TDMT_SYNC_CONFIG_CHANGE_FINISH) { - if (rpcMsg.pCont != NULL) { - code = syncNodeConfigChangeFinish(ths, &rpcMsg, pEntry); - ASSERT(code == 0); + SFsmCbMeta cbMeta = { + .index = pEntry->index, + .lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, pEntry->index), + .isWeak = pEntry->isWeak, + .code = 0, + .state = ths->state, + .seqNum = pEntry->seqNum, + .term = pEntry->term, + .currentTerm = ths->pRaftStore->currentTerm, + .flag = flag, + }; + + syncRespMgrGetAndDel(ths->pSyncRespMgr, cbMeta.seqNum, &rpcMsg.info); + ths->pFsm->FpCommitCb(ths->pFsm, &rpcMsg, &cbMeta); } } @@ -3449,11 +2480,7 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde ths->restoreFinish = true; int64_t restoreDelay = taosGetTimestampMs() - ths->leaderTime; - - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "restore finish, index:%" PRId64 ", elapsed:%" PRId64 " ms, ", - pEntry->index, restoreDelay); - syncNodeEventLog(ths, eventLog); + sNTrace(ths, "restore finish, index:%" PRId64 ", elapsed:%" PRId64 " ms", pEntry->index, restoreDelay); } } @@ -3470,7 +2497,7 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde } bool syncNodeInRaftGroup(SSyncNode* ths, SRaftId* pRaftId) { - for (int i = 0; i < ths->replicaNum; ++i) { + for (int32_t i = 0; i < ths->replicaNum; ++i) { if (syncUtilSameId(&((ths->replicasId)[i]), pRaftId)) { return true; } @@ -3480,7 +2507,7 @@ bool syncNodeInRaftGroup(SSyncNode* ths, SRaftId* pRaftId) { SSyncSnapshotSender* syncNodeGetSnapshotSender(SSyncNode* ths, SRaftId* pDestId) { SSyncSnapshotSender* pSender = NULL; - for (int i = 0; i < ths->replicaNum; ++i) { + for (int32_t i = 0; i < ths->replicaNum; ++i) { if (syncUtilSameId(pDestId, &((ths->replicasId)[i]))) { pSender = (ths->senders)[i]; } @@ -3490,7 +2517,7 @@ SSyncSnapshotSender* syncNodeGetSnapshotSender(SSyncNode* ths, SRaftId* pDestId) SSyncTimer* syncNodeGetHbTimer(SSyncNode* ths, SRaftId* pDestId) { SSyncTimer* pTimer = NULL; - for (int i = 0; i < ths->replicaNum; ++i) { + for (int32_t i = 0; i < ths->replicaNum; ++i) { if (syncUtilSameId(pDestId, &((ths->replicasId)[i]))) { pTimer = &((ths->peerHeartbeatTimerArr)[i]); } @@ -3500,7 +2527,7 @@ SSyncTimer* syncNodeGetHbTimer(SSyncNode* ths, SRaftId* pDestId) { SPeerState* syncNodeGetPeerState(SSyncNode* ths, const SRaftId* pDestId) { SPeerState* pState = NULL; - for (int i = 0; i < ths->replicaNum; ++i) { + for (int32_t i = 0; i < ths->replicaNum; ++i) { if (syncUtilSameId(pDestId, &((ths->replicasId)[i]))) { pState = &((ths->peerStates)[i]); } @@ -3539,7 +2566,7 @@ bool syncNodeCanChange(SSyncNode* pSyncNode) { } } - for (int i = 0; i < pSyncNode->peersNum; ++i) { + for (int32_t i = 0; i < pSyncNode->peersNum; ++i) { SSyncSnapshotSender* pSender = syncNodeGetSnapshotSender(pSyncNode, &(pSyncNode->peersId)[i]); if (pSender != NULL && pSender->start) { sError("sync cannot change3"); @@ -3563,21 +2590,16 @@ const char* syncTimerTypeStr(enum ESyncTimeoutType timerType) { } void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const char* s) { - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "recv sync-timer {type:%s, lc:%" PRIu64 ", ms:%d, data:%p}, %s", - syncTimerTypeStr(pMsg->timeoutType), pMsg->logicClock, pMsg->timerMS, pMsg->data, s); - syncNodeEventLog(pSyncNode, logBuf); + sNTrace(pSyncNode, "recv sync-timer {type:%s, lc:%" PRId64 ", ms:%d, data:%p}, %s", + syncTimerTypeStr(pMsg->timeoutType), pMsg->logicClock, pMsg->timerMS, pMsg->data, s); } void syncLogSendRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s) { char host[64]; uint16_t port; syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "send sync-request-vote to %s:%d {term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 "}, %s", host, port, - pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s); - syncNodeEventLog(pSyncNode, logBuf); + sNTrace(pSyncNode, "send sync-request-vote to %s:%d {term:%" PRId64 ", lindex:%" PRId64 ", lterm:%" PRId64 "}, %s", + host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s); } void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s) { @@ -3585,152 +2607,173 @@ void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, c char host[64]; uint16_t port; syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - snprintf(logBuf, sizeof(logBuf), - "recv sync-request-vote from %s:%d, {term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 "}, %s", host, - port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s); - syncNodeEventLog(pSyncNode, logBuf); + sNTrace(pSyncNode, "recv sync-request-vote from %s:%d, {term:%" PRId64 ", lindex:%" PRId64 ", lterm:%" PRId64 "}, %s", + host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s); } void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s) { char host[64]; uint16_t port; syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "send sync-request-vote-reply to %s:%d {term:%" PRIu64 ", grant:%d}, %s", host, port, - pMsg->term, pMsg->voteGranted, s); - syncNodeEventLog(pSyncNode, logBuf); + sNTrace(pSyncNode, "send sync-request-vote-reply to %s:%d {term:%" PRId64 ", grant:%d}, %s", host, port, pMsg->term, + pMsg->voteGranted, s); } void syncLogRecvRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteReply* pMsg, const char* s) { char host[64]; uint16_t port; syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "recv sync-request-vote-reply from %s:%d {term:%" PRIu64 ", grant:%d}, %s", host, - port, pMsg->term, pMsg->voteGranted, s); - syncNodeEventLog(pSyncNode, logBuf); + sNTrace(pSyncNode, "recv sync-request-vote-reply from %s:%d {term:%" PRId64 ", grant:%d}, %s", host, port, pMsg->term, + pMsg->voteGranted, s); } void syncLogSendAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s) { char host[64]; uint16_t port; syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "send sync-append-entries to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 - ", pterm:%" PRIu64 ", cmt:%" PRId64 - ", " - "datalen:%d}, %s", - host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex, - pMsg->dataLen, s); - syncNodeEventLog(pSyncNode, logBuf); + sNTrace(pSyncNode, + "send sync-append-entries to %s:%d, {term:%" PRId64 ", pre-index:%" PRId64 ", pre-term:%" PRId64 + ", pterm:%" PRId64 ", cmt:%" PRId64 ", datalen:%d}, %s", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex, + pMsg->dataLen, s); } void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMsg, const char* s) { char host[64]; uint16_t port; syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries from %s:%d {term:%" PRIu64 ", pre-index:%" PRIu64 ", pre-term:%" PRIu64 - ", cmt:%" PRIu64 ", pterm:%" PRIu64 - ", " - "datalen:%d}, %s", - host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, - pMsg->dataLen, s); - syncNodeEventLog(pSyncNode, logBuf); + + sNTrace(pSyncNode, + "recv sync-append-entries from %s:%d {term:%" PRId64 ", pre-index:%" PRId64 ", pre-term:%" PRId64 + ", cmt:%" PRId64 ", pterm:%" PRId64 ", datalen:%d}, %s", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm, + pMsg->dataLen, s); } void syncLogSendAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntriesBatch* pMsg, const char* s) { char host[64]; uint16_t port; syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "send sync-append-entries-batch to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 - ", pterm:%" PRIu64 ", cmt:%" PRId64 ", datalen:%d, count:%d}, %s", - host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex, - pMsg->dataLen, pMsg->dataCount, s); - syncNodeEventLog(pSyncNode, logBuf); + + sNTrace(pSyncNode, + "send sync-append-entries-batch to %s:%d, {term:%" PRId64 ", pre-index:%" PRId64 ", pre-term:%" PRId64 + ", pterm:%" PRId64 ", cmt:%" PRId64 ", datalen:%d, count:%d}, %s", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex, + pMsg->dataLen, pMsg->dataCount, s); } void syncLogRecvAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntriesBatch* pMsg, const char* s) { char host[64]; uint16_t port; syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-batch from %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64 - ", pterm:%" PRIu64 ", cmt:%" PRId64 ", datalen:%d, count:%d}, %s", - host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex, - pMsg->dataLen, pMsg->dataCount, s); - syncNodeEventLog(pSyncNode, logBuf); + + sNTrace(pSyncNode, + "recv sync-append-entries-batch from %s:%d, {term:%" PRId64 ", pre-index:%" PRId64 ", pre-term:%" PRId64 + ", pterm:%" PRId64 ", cmt:%" PRId64 ", datalen:%d, count:%d}, %s", + host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex, + pMsg->dataLen, pMsg->dataCount, s); } void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) { char host[64]; uint16_t port; syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 ", success:%d, match:%" PRId64 - "}, %s", - host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s); - syncNodeEventLog(pSyncNode, logBuf); + + sNTrace(pSyncNode, + "send sync-append-entries-reply to %s:%d, {term:%" PRId64 ", pterm:%" PRId64 ", success:%d, match:%" PRId64 + "}, %s", + host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s); } void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntriesReply* pMsg, const char* s) { char host[64]; uint16_t port; syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-append-entries-reply from %s:%d {term:%" PRIu64 ", pterm:%" PRIu64 ", success:%d, match:%" PRId64 - "}, %s", - host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s); - syncNodeEventLog(pSyncNode, logBuf); + + sNTrace(pSyncNode, + "recv sync-append-entries-reply from %s:%d {term:%" PRId64 ", pterm:%" PRId64 ", success:%d, match:%" PRId64 + "}, %s", + host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s); } void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s) { char host[64]; uint16_t port; syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "send sync-heartbeat to %s:%d {term:%" PRIu64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", pterm:%" PRIu64 - "}, %s", - host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->privateTerm, s); - syncNodeEventLog(pSyncNode, logBuf); + + sNTrace(pSyncNode, + "send sync-heartbeat to %s:%d {term:%" PRId64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", pterm:%" PRId64 + "}, %s", + host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->privateTerm, s); } void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const char* s) { char host[64]; uint16_t port; syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), - "recv sync-heartbeat from %s:%d {term:%" PRIu64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", pterm:%" PRIu64 - "}, %s", - host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->privateTerm, s); - syncNodeEventLog(pSyncNode, logBuf); + + sNTrace(pSyncNode, + "recv sync-heartbeat from %s:%d {term:%" PRId64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", pterm:%" PRId64 + "}, %s", + host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->privateTerm, s); } void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s) { char host[64]; uint16_t port; syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "send sync-heartbeat-reply from %s:%d {term:%" PRIu64 ", pterm:%" PRIu64 "}, %s", - host, port, pMsg->term, pMsg->privateTerm, s); - syncNodeEventLog(pSyncNode, logBuf); + + sNTrace(pSyncNode, "send sync-heartbeat-reply from %s:%d {term:%" PRId64 ", pterm:%" PRId64 "}, %s", host, port, + pMsg->term, pMsg->privateTerm, s); } void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* pMsg, const char* s) { char host[64]; uint16_t port; syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "recv sync-heartbeat-reply from %s:%d {term:%" PRIu64 ", pterm:%" PRIu64 "}, %s", - host, port, pMsg->term, pMsg->privateTerm, s); - syncNodeEventLog(pSyncNode, logBuf); -} \ No newline at end of file + sNTrace(pSyncNode, "recv sync-heartbeat-reply from %s:%d {term:%" PRId64 ", pterm:%" PRId64 "}, %s", host, port, + pMsg->term, pMsg->privateTerm, s); +} + +void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const char* s) { + sNTrace(pSyncNode, "recv sync-local-cmd {cmd:%d-%s, sd-new-term:%" PRId64 ", fc-index:%" PRId64 "}, %s", pMsg->cmd, + syncLocalCmdGetStr(pMsg->cmd), pMsg->sdNewTerm, pMsg->fcIndex, s); +} + +void syncLogSendSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s) { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); + sNTrace(pSyncNode, "send sync-pre-snapshot to %s:%d {term:%" PRId64 "}, %s", host, port, pMsg->term, s); +} + +void syncLogRecvSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s) { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + sNTrace(pSyncNode, "recv sync-pre-snapshot from %s:%d {term:%" PRId64 "}, %s", host, port, pMsg->term, s); +} + +void syncLogSendSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s) { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port); + sNTrace(pSyncNode, "send sync-pre-snapshot-reply to %s:%d {term:%" PRId64 ", snap-start:%" PRId64 "}, %s", host, port, + pMsg->term, pMsg->snapStart, s); +} + +void syncLogRecvSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s) { + char host[64]; + uint16_t port; + syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port); + sNTrace(pSyncNode, "recv sync-pre-snapshot-reply from %s:%d {term:%" PRId64 ", snap-start:%" PRId64 "}, %s", host, + port, pMsg->term, pMsg->snapStart, s); +} + +void syncLogSendSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s) {} + +void syncLogRecvSyncSnapshotSend(SSyncNode* pSyncNode, const SyncSnapshotSend* pMsg, const char* s) {} + +void syncLogSendSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s) {} + +void syncLogRecvSyncSnapshotRsp(SSyncNode* pSyncNode, const SyncSnapshotRsp* pMsg, const char* s) {} diff --git a/source/libs/sync/src/syncMessage.c b/source/libs/sync/src/syncMessage.c index 4001a955fb01435db30073546c085a021a752964..3fcb563f3bced428398525c189fc2ead28b57dec 100644 --- a/source/libs/sync/src/syncMessage.c +++ b/source/libs/sync/src/syncMessage.c @@ -19,146 +19,6 @@ #include "syncUtil.h" #include "tcoding.h" -// --------------------------------------------- -cJSON* syncRpcMsg2Json(SRpcMsg* pRpcMsg) { - cJSON* pRoot; - - // in compiler optimization, switch case = if else constants - if (pRpcMsg->msgType == TDMT_SYNC_TIMEOUT) { - SyncTimeout* pSyncMsg = syncTimeoutDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); - pRoot = syncTimeout2Json(pSyncMsg); - syncTimeoutDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_PING) { - SyncPing* pSyncMsg = syncPingDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); - pRoot = syncPing2Json(pSyncMsg); - syncPingDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_PING_REPLY) { - SyncPingReply* pSyncMsg = syncPingReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); - pRoot = syncPingReply2Json(pSyncMsg); - syncPingReplyDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) { - SyncClientRequest* pSyncMsg = syncClientRequestDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); - pRoot = syncClientRequest2Json(pSyncMsg); - syncClientRequestDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_CLIENT_REQUEST_REPLY) { - pRoot = syncRpcUnknownMsg2Json(); - - } else if (pRpcMsg->msgType == TDMT_SYNC_REQUEST_VOTE) { - SyncRequestVote* pSyncMsg = syncRequestVoteDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); - pRoot = syncRequestVote2Json(pSyncMsg); - syncRequestVoteDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) { - SyncRequestVoteReply* pSyncMsg = syncRequestVoteReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); - pRoot = syncRequestVoteReply2Json(pSyncMsg); - syncRequestVoteReplyDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) { - SyncAppendEntries* pSyncMsg = syncAppendEntriesDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); - pRoot = syncAppendEntries2Json(pSyncMsg); - syncAppendEntriesDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) { - SyncAppendEntriesReply* pSyncMsg = syncAppendEntriesReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); - pRoot = syncAppendEntriesReply2Json(pSyncMsg); - syncAppendEntriesReplyDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) { - SyncSnapshotSend* pSyncMsg = syncSnapshotSendDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); - pRoot = syncSnapshotSend2Json(pSyncMsg); - syncSnapshotSendDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) { - SyncSnapshotRsp* pSyncMsg = syncSnapshotRspDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); - pRoot = syncSnapshotRsp2Json(pSyncMsg); - syncSnapshotRspDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_LEADER_TRANSFER) { - SyncLeaderTransfer* pSyncMsg = syncLeaderTransferDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); - pRoot = syncLeaderTransfer2Json(pSyncMsg); - syncLeaderTransferDestroy(pSyncMsg); - - } else if (pRpcMsg->msgType == TDMT_SYNC_COMMON_RESPONSE) { - pRoot = cJSON_CreateObject(); - char* s; - s = syncUtilprintBin((char*)(pRpcMsg->pCont), pRpcMsg->contLen); - cJSON_AddStringToObject(pRoot, "pCont", s); - taosMemoryFree(s); - s = syncUtilprintBin2((char*)(pRpcMsg->pCont), pRpcMsg->contLen); - cJSON_AddStringToObject(pRoot, "pCont2", s); - taosMemoryFree(s); - - } else { - pRoot = cJSON_CreateObject(); - char* s; - s = syncUtilprintBin((char*)(pRpcMsg->pCont), pRpcMsg->contLen); - cJSON_AddStringToObject(pRoot, "pCont", s); - taosMemoryFree(s); - s = syncUtilprintBin2((char*)(pRpcMsg->pCont), pRpcMsg->contLen); - cJSON_AddStringToObject(pRoot, "pCont2", s); - taosMemoryFree(s); - } - - cJSON_AddNumberToObject(pRoot, "msgType", pRpcMsg->msgType); - cJSON_AddNumberToObject(pRoot, "contLen", pRpcMsg->contLen); - cJSON_AddNumberToObject(pRoot, "code", pRpcMsg->code); - // cJSON_AddNumberToObject(pRoot, "persist", pRpcMsg->persist); - - cJSON* pJson = cJSON_CreateObject(); - cJSON_AddItemToObject(pJson, "RpcMsg", pRoot); - return pJson; -} - -cJSON* syncRpcUnknownMsg2Json() { - cJSON* pRoot = cJSON_CreateObject(); - cJSON_AddNumberToObject(pRoot, "msgType", TDMT_SYNC_UNKNOWN); - cJSON_AddStringToObject(pRoot, "data", "unknown message"); - - cJSON* pJson = cJSON_CreateObject(); - cJSON_AddItemToObject(pJson, "SyncUnknown", pRoot); - return pJson; -} - -char* syncRpcMsg2Str(SRpcMsg* pRpcMsg) { - cJSON* pJson = syncRpcMsg2Json(pRpcMsg); - char* serialized = cJSON_Print(pJson); - cJSON_Delete(pJson); - return serialized; -} - -// for debug ---------------------- -void syncRpcMsgPrint(SRpcMsg* pMsg) { - char* serialized = syncRpcMsg2Str(pMsg); - printf("syncRpcMsgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncRpcMsgPrint2(char* s, SRpcMsg* pMsg) { - char* serialized = syncRpcMsg2Str(pMsg); - printf("syncRpcMsgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncRpcMsgLog(SRpcMsg* pMsg) { - char* serialized = syncRpcMsg2Str(pMsg); - sTrace("syncRpcMsgLog | len:%d | %s", (int32_t)strlen(serialized), serialized); - taosMemoryFree(serialized); -} - -void syncRpcMsgLog2(char* s, SRpcMsg* pMsg) { - if (gRaftDetailLog) { - char* serialized = syncRpcMsg2Str(pMsg); - sTrace("syncRpcMsgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); - taosMemoryFree(serialized); - } -} - // ---- message process SyncTimeout---- SyncTimeout* syncTimeoutBuild() { uint32_t bytes = sizeof(SyncTimeout); @@ -511,10 +371,10 @@ cJSON* syncPing2Json(const SyncPing* pMsg) { cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); char* s; - s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); + s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen); cJSON_AddStringToObject(pRoot, "data", s); taosMemoryFree(s); - s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); + s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen); cJSON_AddStringToObject(pRoot, "data2", s); taosMemoryFree(s); } @@ -781,10 +641,10 @@ cJSON* syncPingReply2Json(const SyncPingReply* pMsg) { cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); char* s; - s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); + s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen); cJSON_AddStringToObject(pRoot, "data", s); taosMemoryFree(s); - s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); + s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen); cJSON_AddStringToObject(pRoot, "data2", s); taosMemoryFree(s); } @@ -831,82 +691,58 @@ void syncPingReplyLog2(char* s, const SyncPingReply* pMsg) { } // ---- message process SyncClientRequest---- -SyncClientRequest* syncClientRequestBuild(uint32_t dataLen) { +SyncClientRequest* syncClientRequestAlloc(uint32_t dataLen) { uint32_t bytes = sizeof(SyncClientRequest) + dataLen; - SyncClientRequest* pMsg = taosMemoryMalloc(bytes); - memset(pMsg, 0, bytes); + SyncClientRequest* pMsg = taosMemoryCalloc(1, bytes); pMsg->bytes = bytes; pMsg->msgType = TDMT_SYNC_CLIENT_REQUEST; - pMsg->seqNum = 0; - pMsg->isWeak = false; pMsg->dataLen = dataLen; return pMsg; } -// step 1. original SRpcMsg => SyncClientRequest, add seqNum, isWeak -SyncClientRequest* syncClientRequestBuild2(const SRpcMsg* pOriginalRpcMsg, uint64_t seqNum, bool isWeak, int32_t vgId) { - SyncClientRequest* pMsg = syncClientRequestBuild(pOriginalRpcMsg->contLen); - pMsg->vgId = vgId; - pMsg->originalRpcType = pOriginalRpcMsg->msgType; - pMsg->seqNum = seqNum; - pMsg->isWeak = isWeak; - memcpy(pMsg->data, pOriginalRpcMsg->pCont, pOriginalRpcMsg->contLen); - return pMsg; -} - -void syncClientRequestDestroy(SyncClientRequest* pMsg) { - if (pMsg != NULL) { - taosMemoryFree(pMsg); +int32_t syncClientRequestBuildFromRpcMsg(SRpcMsg* pClientRequestRpcMsg, const SRpcMsg* pOriginalRpcMsg, uint64_t seqNum, + bool isWeak, int32_t vgId) { + int32_t bytes = sizeof(SyncClientRequest) + pOriginalRpcMsg->contLen; + pClientRequestRpcMsg->pCont = rpcMallocCont(bytes); + if (pClientRequestRpcMsg->pCont == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; } -} -void syncClientRequestSerialize(const SyncClientRequest* pMsg, char* buf, uint32_t bufLen) { - ASSERT(pMsg->bytes <= bufLen); - memcpy(buf, pMsg, pMsg->bytes); -} + SyncClientRequest* pClientRequest = pClientRequestRpcMsg->pCont; + pClientRequest->bytes = bytes; + pClientRequest->vgId = vgId; + pClientRequest->msgType = TDMT_SYNC_CLIENT_REQUEST; + pClientRequest->originalRpcType = pOriginalRpcMsg->msgType; + pClientRequest->seqNum = seqNum; + pClientRequest->isWeak = isWeak; + pClientRequest->dataLen = pOriginalRpcMsg->contLen; + memcpy(pClientRequest->data, (char*)pOriginalRpcMsg->pCont, pOriginalRpcMsg->contLen); -void syncClientRequestDeserialize(const char* buf, uint32_t len, SyncClientRequest* pMsg) { - memcpy(pMsg, buf, len); - ASSERT(len == pMsg->bytes); + pClientRequestRpcMsg->msgType = TDMT_SYNC_CLIENT_REQUEST; + pClientRequestRpcMsg->contLen = bytes; + return 0; } -char* syncClientRequestSerialize2(const SyncClientRequest* pMsg, uint32_t* len) { - char* buf = taosMemoryMalloc(pMsg->bytes); - ASSERT(buf != NULL); - syncClientRequestSerialize(pMsg, buf, pMsg->bytes); - if (len != NULL) { - *len = pMsg->bytes; +int32_t syncClientRequestBuildFromNoopEntry(SRpcMsg* pClientRequestRpcMsg, const SSyncRaftEntry* pEntry, int32_t vgId) { + int32_t bytes = sizeof(SyncClientRequest) + pEntry->bytes; + pClientRequestRpcMsg->pCont = rpcMallocCont(bytes); + if (pClientRequestRpcMsg->pCont == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; } - return buf; -} - -SyncClientRequest* syncClientRequestDeserialize2(const char* buf, uint32_t len) { - uint32_t bytes = *((uint32_t*)buf); - SyncClientRequest* pMsg = taosMemoryMalloc(bytes); - ASSERT(pMsg != NULL); - syncClientRequestDeserialize(buf, len, pMsg); - ASSERT(len == pMsg->bytes); - return pMsg; -} -// step 2. SyncClientRequest => RpcMsg, to queue -void syncClientRequest2RpcMsg(const SyncClientRequest* pMsg, SRpcMsg* pRpcMsg) { - memset(pRpcMsg, 0, sizeof(*pRpcMsg)); - pRpcMsg->msgType = pMsg->msgType; - pRpcMsg->contLen = pMsg->bytes; - pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen); - syncClientRequestSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen); -} - -void syncClientRequestFromRpcMsg(const SRpcMsg* pRpcMsg, SyncClientRequest* pMsg) { - syncClientRequestDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg); -} + SyncClientRequest* pClientRequest = pClientRequestRpcMsg->pCont; + pClientRequest->bytes = bytes; + pClientRequest->vgId = vgId; + pClientRequest->msgType = TDMT_SYNC_CLIENT_REQUEST; + pClientRequest->originalRpcType = TDMT_SYNC_NOOP; + pClientRequest->dataLen = pEntry->bytes; + memcpy(pClientRequest->data, (char*)pEntry, pEntry->bytes); -// step 3. RpcMsg => SyncClientRequest, from queue -SyncClientRequest* syncClientRequestFromRpcMsg2(const SRpcMsg* pRpcMsg) { - SyncClientRequest* pMsg = syncClientRequestDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); - ASSERT(pMsg != NULL); - return pMsg; + pClientRequestRpcMsg->msgType = TDMT_SYNC_CLIENT_REQUEST; + pClientRequestRpcMsg->contLen = bytes; + return 0; } cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg) { @@ -924,10 +760,10 @@ cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg) { cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); char* s; - s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); + s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen); cJSON_AddStringToObject(pRoot, "data", s); taosMemoryFree(s); - s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); + s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen); cJSON_AddStringToObject(pRoot, "data2", s); taosMemoryFree(s); } @@ -944,35 +780,6 @@ char* syncClientRequest2Str(const SyncClientRequest* pMsg) { return serialized; } -// for debug ---------------------- -void syncClientRequestPrint(const SyncClientRequest* pMsg) { - char* serialized = syncClientRequest2Str(pMsg); - printf("syncClientRequestPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncClientRequestPrint2(char* s, const SyncClientRequest* pMsg) { - char* serialized = syncClientRequest2Str(pMsg); - printf("syncClientRequestPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncClientRequestLog(const SyncClientRequest* pMsg) { - char* serialized = syncClientRequest2Str(pMsg); - sTrace("syncClientRequestLog | len:%d | %s", (int32_t)strlen(serialized), serialized); - taosMemoryFree(serialized); -} - -void syncClientRequestLog2(char* s, const SyncClientRequest* pMsg) { - if (gRaftDetailLog) { - char* serialized = syncClientRequest2Str(pMsg); - sTrace("syncClientRequestLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); - taosMemoryFree(serialized); - } -} - // ---- message process SyncClientRequestBatch---- // block1: @@ -1063,86 +870,6 @@ SyncClientRequestBatch* syncClientRequestBatchFromRpcMsg(const SRpcMsg* pRpcMsg) return pSyncMsg; } -cJSON* syncClientRequestBatch2Json(const SyncClientRequestBatch* pMsg) { - char u64buf[128] = {0}; - cJSON* pRoot = cJSON_CreateObject(); - - if (pMsg != NULL) { - cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); - cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId); - cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); - cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); - cJSON_AddNumberToObject(pRoot, "dataCount", pMsg->dataCount); - - SRaftMeta* metaArr = syncClientRequestBatchMetaArr(pMsg); - SRpcMsg* msgArr = syncClientRequestBatchRpcMsgArr(pMsg); - - cJSON* pMetaArr = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "metaArr", pMetaArr); - for (int i = 0; i < pMsg->dataCount; ++i) { - cJSON* pMeta = cJSON_CreateObject(); - cJSON_AddNumberToObject(pMeta, "seqNum", metaArr[i].seqNum); - cJSON_AddNumberToObject(pMeta, "isWeak", metaArr[i].isWeak); - cJSON_AddItemToArray(pMetaArr, pMeta); - } - - cJSON* pMsgArr = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "msgArr", pMsgArr); - for (int i = 0; i < pMsg->dataCount; ++i) { - cJSON* pRpcMsgJson = syncRpcMsg2Json(&msgArr[i]); - cJSON_AddItemToArray(pMsgArr, pRpcMsgJson); - } - - char* s; - s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); - cJSON_AddStringToObject(pRoot, "data", s); - taosMemoryFree(s); - s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); - cJSON_AddStringToObject(pRoot, "data2", s); - taosMemoryFree(s); - } - - cJSON* pJson = cJSON_CreateObject(); - cJSON_AddItemToObject(pJson, "SyncClientRequestBatch", pRoot); - return pJson; -} - -char* syncClientRequestBatch2Str(const SyncClientRequestBatch* pMsg) { - cJSON* pJson = syncClientRequestBatch2Json(pMsg); - char* serialized = cJSON_Print(pJson); - cJSON_Delete(pJson); - return serialized; -} - -// for debug ---------------------- -void syncClientRequestBatchPrint(const SyncClientRequestBatch* pMsg) { - char* serialized = syncClientRequestBatch2Str(pMsg); - printf("syncClientRequestBatchPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncClientRequestBatchPrint2(char* s, const SyncClientRequestBatch* pMsg) { - char* serialized = syncClientRequestBatch2Str(pMsg); - printf("syncClientRequestBatchPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncClientRequestBatchLog(const SyncClientRequestBatch* pMsg) { - char* serialized = syncClientRequestBatch2Str(pMsg); - sTrace("syncClientRequestBatchLog | len:%d | %s", (int32_t)strlen(serialized), serialized); - taosMemoryFree(serialized); -} - -void syncClientRequestBatchLog2(char* s, const SyncClientRequestBatch* pMsg) { - if (gRaftDetailLog) { - char* serialized = syncClientRequestBatch2Str(pMsg); - sTraceLong("syncClientRequestBatchLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); - taosMemoryFree(serialized); - } -} - // ---- message process SyncRequestVote---- SyncRequestVote* syncRequestVoteBuild(int32_t vgId) { uint32_t bytes = sizeof(SyncRequestVote); @@ -1564,10 +1291,10 @@ cJSON* syncAppendEntries2Json(const SyncAppendEntries* pMsg) { cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); char* s; - s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); + s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen); cJSON_AddStringToObject(pRoot, "data", s); taosMemoryFree(s); - s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); + s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen); cJSON_AddStringToObject(pRoot, "data2", s); taosMemoryFree(s); } @@ -1720,138 +1447,6 @@ SyncAppendEntriesBatch* syncAppendEntriesBatchFromRpcMsg2(const SRpcMsg* pRpcMsg return pMsg; } -cJSON* syncAppendEntriesBatch2Json(const SyncAppendEntriesBatch* pMsg) { - char u64buf[128] = {0}; - cJSON* pRoot = cJSON_CreateObject(); - - if (pMsg != NULL) { - cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); - cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId); - cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); - - cJSON* pSrcId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr); - cJSON_AddStringToObject(pSrcId, "addr", u64buf); - { - uint64_t u64 = pMsg->srcId.addr; - cJSON* pTmp = pSrcId; - char host[128] = {0}; - uint16_t port; - syncUtilU642Addr(u64, host, sizeof(host), &port); - cJSON_AddStringToObject(pTmp, "addr_host", host); - cJSON_AddNumberToObject(pTmp, "addr_port", port); - } - cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId); - cJSON_AddItemToObject(pRoot, "srcId", pSrcId); - - cJSON* pDestId = cJSON_CreateObject(); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr); - cJSON_AddStringToObject(pDestId, "addr", u64buf); - { - uint64_t u64 = pMsg->destId.addr; - cJSON* pTmp = pDestId; - char host[128] = {0}; - uint16_t port; - syncUtilU642Addr(u64, host, sizeof(host), &port); - cJSON_AddStringToObject(pTmp, "addr_host", host); - cJSON_AddNumberToObject(pTmp, "addr_port", port); - } - cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); - cJSON_AddItemToObject(pRoot, "destId", pDestId); - - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term); - cJSON_AddStringToObject(pRoot, "term", u64buf); - - snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->prevLogIndex); - cJSON_AddStringToObject(pRoot, "prevLogIndex", u64buf); - - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->prevLogTerm); - cJSON_AddStringToObject(pRoot, "prevLogTerm", u64buf); - - snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->commitIndex); - cJSON_AddStringToObject(pRoot, "commitIndex", u64buf); - - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm); - cJSON_AddStringToObject(pRoot, "privateTerm", u64buf); - - cJSON_AddNumberToObject(pRoot, "dataCount", pMsg->dataCount); - cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); - - int32_t metaArrayLen = sizeof(SOffsetAndContLen) * pMsg->dataCount; // - int32_t entryArrayLen = pMsg->dataLen - metaArrayLen; - - cJSON_AddNumberToObject(pRoot, "metaArrayLen", metaArrayLen); - cJSON_AddNumberToObject(pRoot, "entryArrayLen", entryArrayLen); - - SOffsetAndContLen* metaArr = (SOffsetAndContLen*)(pMsg->data); - - cJSON* pMetaArr = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "metaArr", pMetaArr); - for (int i = 0; i < pMsg->dataCount; ++i) { - cJSON* pMeta = cJSON_CreateObject(); - cJSON_AddNumberToObject(pMeta, "offset", metaArr[i].offset); - cJSON_AddNumberToObject(pMeta, "contLen", metaArr[i].contLen); - cJSON_AddItemToArray(pMetaArr, pMeta); - } - - cJSON* pEntryArr = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "entryArr", pEntryArr); - for (int i = 0; i < pMsg->dataCount; ++i) { - SSyncRaftEntry* pEntry = (SSyncRaftEntry*)(pMsg->data + metaArr[i].offset); - cJSON* pEntryJson = syncEntry2Json(pEntry); - cJSON_AddItemToArray(pEntryArr, pEntryJson); - } - - char* s; - s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); - cJSON_AddStringToObject(pRoot, "data", s); - taosMemoryFree(s); - s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); - cJSON_AddStringToObject(pRoot, "data2", s); - taosMemoryFree(s); - } - - cJSON* pJson = cJSON_CreateObject(); - cJSON_AddItemToObject(pJson, "SyncAppendEntriesBatch", pRoot); - return pJson; -} - -char* syncAppendEntriesBatch2Str(const SyncAppendEntriesBatch* pMsg) { - cJSON* pJson = syncAppendEntriesBatch2Json(pMsg); - char* serialized = cJSON_Print(pJson); - cJSON_Delete(pJson); - return serialized; -} - -// for debug ---------------------- -void syncAppendEntriesBatchPrint(const SyncAppendEntriesBatch* pMsg) { - char* serialized = syncAppendEntriesBatch2Str(pMsg); - printf("syncAppendEntriesBatchPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncAppendEntriesBatchPrint2(char* s, const SyncAppendEntriesBatch* pMsg) { - char* serialized = syncAppendEntriesBatch2Str(pMsg); - printf("syncAppendEntriesBatchPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncAppendEntriesBatchLog(const SyncAppendEntriesBatch* pMsg) { - char* serialized = syncAppendEntriesBatch2Str(pMsg); - sTrace("syncAppendEntriesBatchLog | len:%d | %s", (int32_t)strlen(serialized), serialized); - taosMemoryFree(serialized); -} - -void syncAppendEntriesBatchLog2(char* s, const SyncAppendEntriesBatch* pMsg) { - if (gRaftDetailLog) { - char* serialized = syncAppendEntriesBatch2Str(pMsg); - sTraceLong("syncAppendEntriesBatchLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); - taosMemoryFree(serialized); - } -} - // ---- message process SyncAppendEntriesReply---- SyncAppendEntriesReply* syncAppendEntriesReplyBuild(int32_t vgId) { uint32_t bytes = sizeof(SyncAppendEntriesReply); @@ -2315,90 +1910,71 @@ void syncHeartbeatReplyLog2(char* s, const SyncHeartbeatReply* pMsg) { } } -// ---- message process SyncApplyMsg---- -SyncApplyMsg* syncApplyMsgBuild(uint32_t dataLen) { - uint32_t bytes = sizeof(SyncApplyMsg) + dataLen; - SyncApplyMsg* pMsg = taosMemoryMalloc(bytes); +// ---- message process SyncPreSnapshot---- +SyncPreSnapshot* syncPreSnapshotBuild(int32_t vgId) { + uint32_t bytes = sizeof(SyncPreSnapshot); + SyncPreSnapshot* pMsg = taosMemoryMalloc(bytes); memset(pMsg, 0, bytes); pMsg->bytes = bytes; - pMsg->msgType = TDMT_SYNC_APPLY_MSG; - pMsg->dataLen = dataLen; - return pMsg; -} - -SyncApplyMsg* syncApplyMsgBuild2(const SRpcMsg* pOriginalRpcMsg, int32_t vgId, SFsmCbMeta* pMeta) { - SyncApplyMsg* pMsg = syncApplyMsgBuild(pOriginalRpcMsg->contLen); pMsg->vgId = vgId; - pMsg->originalRpcType = pOriginalRpcMsg->msgType; - pMsg->fsmMeta = *pMeta; - memcpy(pMsg->data, pOriginalRpcMsg->pCont, pOriginalRpcMsg->contLen); + pMsg->msgType = TDMT_SYNC_PRE_SNAPSHOT; return pMsg; } -void syncApplyMsgDestroy(SyncApplyMsg* pMsg) { +void syncPreSnapshotDestroy(SyncPreSnapshot* pMsg) { if (pMsg != NULL) { taosMemoryFree(pMsg); } } -void syncApplyMsgSerialize(const SyncApplyMsg* pMsg, char* buf, uint32_t bufLen) { +void syncPreSnapshotSerialize(const SyncPreSnapshot* pMsg, char* buf, uint32_t bufLen) { ASSERT(pMsg->bytes <= bufLen); memcpy(buf, pMsg, pMsg->bytes); } -void syncApplyMsgDeserialize(const char* buf, uint32_t len, SyncApplyMsg* pMsg) { +void syncPreSnapshotDeserialize(const char* buf, uint32_t len, SyncPreSnapshot* pMsg) { memcpy(pMsg, buf, len); ASSERT(len == pMsg->bytes); } -char* syncApplyMsgSerialize2(const SyncApplyMsg* pMsg, uint32_t* len) { +char* syncPreSnapshotSerialize2(const SyncPreSnapshot* pMsg, uint32_t* len) { char* buf = taosMemoryMalloc(pMsg->bytes); ASSERT(buf != NULL); - syncApplyMsgSerialize(pMsg, buf, pMsg->bytes); + syncPreSnapshotSerialize(pMsg, buf, pMsg->bytes); if (len != NULL) { *len = pMsg->bytes; } return buf; } -SyncApplyMsg* syncApplyMsgDeserialize2(const char* buf, uint32_t len) { - uint32_t bytes = *((uint32_t*)buf); - SyncApplyMsg* pMsg = taosMemoryMalloc(bytes); +SyncPreSnapshot* syncPreSnapshotDeserialize2(const char* buf, uint32_t len) { + uint32_t bytes = *((uint32_t*)buf); + SyncPreSnapshot* pMsg = taosMemoryMalloc(bytes); ASSERT(pMsg != NULL); - syncApplyMsgDeserialize(buf, len, pMsg); + syncPreSnapshotDeserialize(buf, len, pMsg); ASSERT(len == pMsg->bytes); return pMsg; } -// SyncApplyMsg to SRpcMsg, put it into ApplyQ -void syncApplyMsg2RpcMsg(const SyncApplyMsg* pMsg, SRpcMsg* pRpcMsg) { +void syncPreSnapshot2RpcMsg(const SyncPreSnapshot* pMsg, SRpcMsg* pRpcMsg) { memset(pRpcMsg, 0, sizeof(*pRpcMsg)); pRpcMsg->msgType = pMsg->msgType; pRpcMsg->contLen = pMsg->bytes; pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen); - syncApplyMsgSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen); + syncPreSnapshotSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen); } -// get SRpcMsg from ApplyQ, to SyncApplyMsg -void syncApplyMsgFromRpcMsg(const SRpcMsg* pRpcMsg, SyncApplyMsg* pMsg) { - syncApplyMsgDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg); +void syncPreSnapshotFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPreSnapshot* pMsg) { + syncPreSnapshotDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg); } -SyncApplyMsg* syncApplyMsgFromRpcMsg2(const SRpcMsg* pRpcMsg) { - SyncApplyMsg* pMsg = syncApplyMsgDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); +SyncPreSnapshot* syncPreSnapshotFromRpcMsg2(const SRpcMsg* pRpcMsg) { + SyncPreSnapshot* pMsg = syncPreSnapshotDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); + ASSERT(pMsg != NULL); return pMsg; } -// SyncApplyMsg to OriginalRpcMsg -void syncApplyMsg2OriginalRpcMsg(const SyncApplyMsg* pMsg, SRpcMsg* pOriginalRpcMsg) { - memset(pOriginalRpcMsg, 0, sizeof(*pOriginalRpcMsg)); - pOriginalRpcMsg->msgType = pMsg->originalRpcType; - pOriginalRpcMsg->contLen = pMsg->dataLen; - pOriginalRpcMsg->pCont = rpcMallocCont(pOriginalRpcMsg->contLen); - memcpy(pOriginalRpcMsg->pCont, pMsg->data, pOriginalRpcMsg->contLen); -} - -cJSON* syncApplyMsg2Json(const SyncApplyMsg* pMsg) { +cJSON* syncPreSnapshot2Json(const SyncPreSnapshot* pMsg) { char u64buf[128] = {0}; cJSON* pRoot = cJSON_CreateObject(); @@ -2406,136 +1982,147 @@ cJSON* syncApplyMsg2Json(const SyncApplyMsg* pMsg) { cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId); cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); - cJSON_AddNumberToObject(pRoot, "originalRpcType", pMsg->originalRpcType); - snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->fsmMeta.index); - cJSON_AddStringToObject(pRoot, "fsmMeta.index", u64buf); - cJSON_AddNumberToObject(pRoot, "fsmMeta.isWeak", pMsg->fsmMeta.isWeak); - cJSON_AddNumberToObject(pRoot, "fsmMeta.code", pMsg->fsmMeta.code); - cJSON_AddNumberToObject(pRoot, "fsmMeta.state", pMsg->fsmMeta.state); - cJSON_AddStringToObject(pRoot, "fsmMeta.state.str", syncUtilState2String(pMsg->fsmMeta.state)); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->fsmMeta.seqNum); - cJSON_AddStringToObject(pRoot, "fsmMeta.seqNum", u64buf); + cJSON* pSrcId = cJSON_CreateObject(); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr); + cJSON_AddStringToObject(pSrcId, "addr", u64buf); + { + uint64_t u64 = pMsg->srcId.addr; + cJSON* pTmp = pSrcId; + char host[128] = {0}; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId); + cJSON_AddItemToObject(pRoot, "srcId", pSrcId); - cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); - char* s; - s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); - cJSON_AddStringToObject(pRoot, "data", s); - taosMemoryFree(s); - s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); - cJSON_AddStringToObject(pRoot, "data2", s); - taosMemoryFree(s); + cJSON* pDestId = cJSON_CreateObject(); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr); + cJSON_AddStringToObject(pDestId, "addr", u64buf); + { + uint64_t u64 = pMsg->destId.addr; + cJSON* pTmp = pDestId; + char host[128] = {0}; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); + cJSON_AddItemToObject(pRoot, "destId", pDestId); + + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term); + cJSON_AddStringToObject(pRoot, "term", u64buf); } cJSON* pJson = cJSON_CreateObject(); - cJSON_AddItemToObject(pJson, "SyncApplyMsg", pRoot); + cJSON_AddItemToObject(pJson, "SyncPreSnapshot", pRoot); return pJson; } -char* syncApplyMsg2Str(const SyncApplyMsg* pMsg) { - cJSON* pJson = syncApplyMsg2Json(pMsg); +char* syncPreSnapshot2Str(const SyncPreSnapshot* pMsg) { + cJSON* pJson = syncPreSnapshot2Json(pMsg); char* serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } -// for debug ---------------------- -void syncApplyMsgPrint(const SyncApplyMsg* pMsg) { - char* serialized = syncApplyMsg2Str(pMsg); - printf("syncApplyMsgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); +void syncPreSnapshotPrint(const SyncPreSnapshot* pMsg) { + char* serialized = syncPreSnapshot2Str(pMsg); + printf("syncPreSnapshotPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } -void syncApplyMsgPrint2(char* s, const SyncApplyMsg* pMsg) { - char* serialized = syncApplyMsg2Str(pMsg); - printf("syncApplyMsgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); +void syncPreSnapshotPrint2(char* s, const SyncPreSnapshot* pMsg) { + char* serialized = syncPreSnapshot2Str(pMsg); + printf("syncPreSnapshotPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } -void syncApplyMsgLog(const SyncApplyMsg* pMsg) { - char* serialized = syncApplyMsg2Str(pMsg); - sTrace("ssyncApplyMsgLog | len:%d | %s", (int32_t)strlen(serialized), serialized); +void syncPreSnapshotLog(const SyncPreSnapshot* pMsg) { + char* serialized = syncPreSnapshot2Str(pMsg); + sTrace("syncPreSnapshotLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } -void syncApplyMsgLog2(char* s, const SyncApplyMsg* pMsg) { +void syncPreSnapshotLog2(char* s, const SyncPreSnapshot* pMsg) { if (gRaftDetailLog) { - char* serialized = syncApplyMsg2Str(pMsg); - sTrace("syncApplyMsgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); + char* serialized = syncPreSnapshot2Str(pMsg); + sTrace("syncPreSnapshotLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } -// --------------------------------------------- -SyncSnapshotSend* syncSnapshotSendBuild(uint32_t dataLen, int32_t vgId) { - uint32_t bytes = sizeof(SyncSnapshotSend) + dataLen; - SyncSnapshotSend* pMsg = taosMemoryMalloc(bytes); +// ---- message process SyncPreSnapshotReply---- +SyncPreSnapshotReply* syncPreSnapshotReplyBuild(int32_t vgId) { + uint32_t bytes = sizeof(SyncPreSnapshotReply); + SyncPreSnapshotReply* pMsg = taosMemoryMalloc(bytes); memset(pMsg, 0, bytes); pMsg->bytes = bytes; pMsg->vgId = vgId; - pMsg->msgType = TDMT_SYNC_SNAPSHOT_SEND; - pMsg->dataLen = dataLen; + pMsg->msgType = TDMT_SYNC_PRE_SNAPSHOT_REPLY; return pMsg; } -void syncSnapshotSendDestroy(SyncSnapshotSend* pMsg) { +void syncPreSnapshotReplyDestroy(SyncPreSnapshotReply* pMsg) { if (pMsg != NULL) { taosMemoryFree(pMsg); } } -void syncSnapshotSendSerialize(const SyncSnapshotSend* pMsg, char* buf, uint32_t bufLen) { +void syncPreSnapshotReplySerialize(const SyncPreSnapshotReply* pMsg, char* buf, uint32_t bufLen) { ASSERT(pMsg->bytes <= bufLen); memcpy(buf, pMsg, pMsg->bytes); } -void syncSnapshotSendDeserialize(const char* buf, uint32_t len, SyncSnapshotSend* pMsg) { +void syncPreSnapshotReplyDeserialize(const char* buf, uint32_t len, SyncPreSnapshotReply* pMsg) { memcpy(pMsg, buf, len); ASSERT(len == pMsg->bytes); - ASSERT(pMsg->bytes == sizeof(SyncSnapshotSend) + pMsg->dataLen); } -char* syncSnapshotSendSerialize2(const SyncSnapshotSend* pMsg, uint32_t* len) { +char* syncPreSnapshotReplySerialize2(const SyncPreSnapshotReply* pMsg, uint32_t* len) { char* buf = taosMemoryMalloc(pMsg->bytes); ASSERT(buf != NULL); - syncSnapshotSendSerialize(pMsg, buf, pMsg->bytes); + syncPreSnapshotReplySerialize(pMsg, buf, pMsg->bytes); if (len != NULL) { *len = pMsg->bytes; } return buf; } -SyncSnapshotSend* syncSnapshotSendDeserialize2(const char* buf, uint32_t len) { - uint32_t bytes = *((uint32_t*)buf); - SyncSnapshotSend* pMsg = taosMemoryMalloc(bytes); +SyncPreSnapshotReply* syncPreSnapshotReplyDeserialize2(const char* buf, uint32_t len) { + uint32_t bytes = *((uint32_t*)buf); + SyncPreSnapshotReply* pMsg = taosMemoryMalloc(bytes); ASSERT(pMsg != NULL); - syncSnapshotSendDeserialize(buf, len, pMsg); + syncPreSnapshotReplyDeserialize(buf, len, pMsg); ASSERT(len == pMsg->bytes); return pMsg; } -void syncSnapshotSend2RpcMsg(const SyncSnapshotSend* pMsg, SRpcMsg* pRpcMsg) { +void syncPreSnapshotReply2RpcMsg(const SyncPreSnapshotReply* pMsg, SRpcMsg* pRpcMsg) { memset(pRpcMsg, 0, sizeof(*pRpcMsg)); pRpcMsg->msgType = pMsg->msgType; pRpcMsg->contLen = pMsg->bytes; pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen); - syncSnapshotSendSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen); + syncPreSnapshotReplySerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen); } -void syncSnapshotSendFromRpcMsg(const SRpcMsg* pRpcMsg, SyncSnapshotSend* pMsg) { - syncSnapshotSendDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg); +void syncPreSnapshotReplyFromRpcMsg(const SRpcMsg* pRpcMsg, SyncPreSnapshotReply* pMsg) { + syncPreSnapshotReplyDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg); } -SyncSnapshotSend* syncSnapshotSendFromRpcMsg2(const SRpcMsg* pRpcMsg) { - SyncSnapshotSend* pMsg = syncSnapshotSendDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); +SyncPreSnapshotReply* syncPreSnapshotReplyFromRpcMsg2(const SRpcMsg* pRpcMsg) { + SyncPreSnapshotReply* pMsg = syncPreSnapshotReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); ASSERT(pMsg != NULL); return pMsg; } -cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg) { - char u64buf[128]; +cJSON* syncPreSnapshotReply2Json(const SyncPreSnapshotReply* pMsg) { + char u64buf[128] = {0}; cJSON* pRoot = cJSON_CreateObject(); if (pMsg != NULL) { @@ -2549,7 +2136,7 @@ cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg) { { uint64_t u64 = pMsg->srcId.addr; cJSON* pTmp = pSrcId; - char host[128]; + char host[128] = {0}; uint16_t port; syncUtilU642Addr(u64, host, sizeof(host), &port); cJSON_AddStringToObject(pTmp, "addr_host", host); @@ -2564,7 +2151,7 @@ cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg) { { uint64_t u64 = pMsg->destId.addr; cJSON* pTmp = pDestId; - char host[128]; + char host[128] = {0}; uint16_t port; syncUtilU642Addr(u64, host, sizeof(host), &port); cJSON_AddStringToObject(pTmp, "addr_host", host); @@ -2576,76 +2163,269 @@ cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg) { snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term); cJSON_AddStringToObject(pRoot, "term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm); - cJSON_AddStringToObject(pRoot, "privateTerm", u64buf); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->snapStart); + cJSON_AddStringToObject(pRoot, "snap-start", u64buf); + } - snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->beginIndex); - cJSON_AddStringToObject(pRoot, "beginIndex", u64buf); + cJSON* pJson = cJSON_CreateObject(); + cJSON_AddItemToObject(pJson, "SyncPreSnapshotReply", pRoot); + return pJson; +} - snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->lastIndex); - cJSON_AddStringToObject(pRoot, "lastIndex", u64buf); +char* syncPreSnapshotReply2Str(const SyncPreSnapshotReply* pMsg) { + cJSON* pJson = syncPreSnapshotReply2Json(pMsg); + char* serialized = cJSON_Print(pJson); + cJSON_Delete(pJson); + return serialized; +} - snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->lastConfigIndex); - cJSON_AddStringToObject(pRoot, "lastConfigIndex", u64buf); - cJSON_AddItemToObject(pRoot, "lastConfig", syncCfg2Json((SSyncCfg*)&(pMsg->lastConfig))); +void syncPreSnapshotReplyPrint(const SyncPreSnapshotReply* pMsg) { + char* serialized = syncPreSnapshotReply2Str(pMsg); + printf("syncPreSnapshotReplyPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); + fflush(NULL); + taosMemoryFree(serialized); +} - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->lastTerm); - cJSON_AddStringToObject(pRoot, "lastTerm", u64buf); +void syncPreSnapshotReplyPrint2(char* s, const SyncPreSnapshotReply* pMsg) { + char* serialized = syncPreSnapshotReply2Str(pMsg); + printf("syncPreSnapshotReplyPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void syncPreSnapshotReplyLog(const SyncPreSnapshotReply* pMsg) { + char* serialized = syncPreSnapshotReply2Str(pMsg); + sTrace("syncPreSnapshotReplyLog | len:%d | %s", (int32_t)strlen(serialized), serialized); + taosMemoryFree(serialized); +} + +void syncPreSnapshotReplyLog2(char* s, const SyncPreSnapshotReply* pMsg) { + if (gRaftDetailLog) { + char* serialized = syncPreSnapshotReply2Str(pMsg); + sTrace("syncPreSnapshotReplyLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); + taosMemoryFree(serialized); + } +} + +// ---- message process SyncApplyMsg---- +SyncApplyMsg* syncApplyMsgBuild(uint32_t dataLen) { + uint32_t bytes = sizeof(SyncApplyMsg) + dataLen; + SyncApplyMsg* pMsg = taosMemoryMalloc(bytes); + memset(pMsg, 0, bytes); + pMsg->bytes = bytes; + pMsg->msgType = TDMT_SYNC_APPLY_MSG; + pMsg->dataLen = dataLen; + return pMsg; +} - cJSON_AddNumberToObject(pRoot, "seq", pMsg->seq); +SyncApplyMsg* syncApplyMsgBuild2(const SRpcMsg* pOriginalRpcMsg, int32_t vgId, SFsmCbMeta* pMeta) { + SyncApplyMsg* pMsg = syncApplyMsgBuild(pOriginalRpcMsg->contLen); + pMsg->vgId = vgId; + pMsg->originalRpcType = pOriginalRpcMsg->msgType; + pMsg->fsmMeta = *pMeta; + memcpy(pMsg->data, pOriginalRpcMsg->pCont, pOriginalRpcMsg->contLen); + return pMsg; +} + +void syncApplyMsgDestroy(SyncApplyMsg* pMsg) { + if (pMsg != NULL) { + taosMemoryFree(pMsg); + } +} + +void syncApplyMsgSerialize(const SyncApplyMsg* pMsg, char* buf, uint32_t bufLen) { + ASSERT(pMsg->bytes <= bufLen); + memcpy(buf, pMsg, pMsg->bytes); +} + +void syncApplyMsgDeserialize(const char* buf, uint32_t len, SyncApplyMsg* pMsg) { + memcpy(pMsg, buf, len); + ASSERT(len == pMsg->bytes); +} + +char* syncApplyMsgSerialize2(const SyncApplyMsg* pMsg, uint32_t* len) { + char* buf = taosMemoryMalloc(pMsg->bytes); + ASSERT(buf != NULL); + syncApplyMsgSerialize(pMsg, buf, pMsg->bytes); + if (len != NULL) { + *len = pMsg->bytes; + } + return buf; +} + +SyncApplyMsg* syncApplyMsgDeserialize2(const char* buf, uint32_t len) { + uint32_t bytes = *((uint32_t*)buf); + SyncApplyMsg* pMsg = taosMemoryMalloc(bytes); + ASSERT(pMsg != NULL); + syncApplyMsgDeserialize(buf, len, pMsg); + ASSERT(len == pMsg->bytes); + return pMsg; +} + +// SyncApplyMsg to SRpcMsg, put it into ApplyQ +void syncApplyMsg2RpcMsg(const SyncApplyMsg* pMsg, SRpcMsg* pRpcMsg) { + memset(pRpcMsg, 0, sizeof(*pRpcMsg)); + pRpcMsg->msgType = pMsg->msgType; + pRpcMsg->contLen = pMsg->bytes; + pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen); + syncApplyMsgSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen); +} + +// get SRpcMsg from ApplyQ, to SyncApplyMsg +void syncApplyMsgFromRpcMsg(const SRpcMsg* pRpcMsg, SyncApplyMsg* pMsg) { + syncApplyMsgDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg); +} + +SyncApplyMsg* syncApplyMsgFromRpcMsg2(const SRpcMsg* pRpcMsg) { + SyncApplyMsg* pMsg = syncApplyMsgDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); + return pMsg; +} + +// SyncApplyMsg to OriginalRpcMsg +void syncApplyMsg2OriginalRpcMsg(const SyncApplyMsg* pMsg, SRpcMsg* pOriginalRpcMsg) { + memset(pOriginalRpcMsg, 0, sizeof(*pOriginalRpcMsg)); + pOriginalRpcMsg->msgType = pMsg->originalRpcType; + pOriginalRpcMsg->contLen = pMsg->dataLen; + pOriginalRpcMsg->pCont = rpcMallocCont(pOriginalRpcMsg->contLen); + memcpy(pOriginalRpcMsg->pCont, pMsg->data, pOriginalRpcMsg->contLen); +} + +cJSON* syncApplyMsg2Json(const SyncApplyMsg* pMsg) { + char u64buf[128] = {0}; + cJSON* pRoot = cJSON_CreateObject(); + + if (pMsg != NULL) { + cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); + cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId); + cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); + cJSON_AddNumberToObject(pRoot, "originalRpcType", pMsg->originalRpcType); + + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->fsmMeta.index); + cJSON_AddStringToObject(pRoot, "fsmMeta.index", u64buf); + cJSON_AddNumberToObject(pRoot, "fsmMeta.isWeak", pMsg->fsmMeta.isWeak); + cJSON_AddNumberToObject(pRoot, "fsmMeta.code", pMsg->fsmMeta.code); + cJSON_AddNumberToObject(pRoot, "fsmMeta.state", pMsg->fsmMeta.state); + cJSON_AddStringToObject(pRoot, "fsmMeta.state.str", syncStr(pMsg->fsmMeta.state)); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->fsmMeta.seqNum); + cJSON_AddStringToObject(pRoot, "fsmMeta.seqNum", u64buf); cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); char* s; - s = syncUtilprintBin((char*)(pMsg->data), pMsg->dataLen); + s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen); cJSON_AddStringToObject(pRoot, "data", s); taosMemoryFree(s); - s = syncUtilprintBin2((char*)(pMsg->data), pMsg->dataLen); + s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen); cJSON_AddStringToObject(pRoot, "data2", s); taosMemoryFree(s); } cJSON* pJson = cJSON_CreateObject(); - cJSON_AddItemToObject(pJson, "SyncSnapshotSend", pRoot); + cJSON_AddItemToObject(pJson, "SyncApplyMsg", pRoot); return pJson; } -char* syncSnapshotSend2Str(const SyncSnapshotSend* pMsg) { - cJSON* pJson = syncSnapshotSend2Json(pMsg); +char* syncApplyMsg2Str(const SyncApplyMsg* pMsg) { + cJSON* pJson = syncApplyMsg2Json(pMsg); char* serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } // for debug ---------------------- -void syncSnapshotSendPrint(const SyncSnapshotSend* pMsg) { - char* serialized = syncSnapshotSend2Str(pMsg); - printf("syncSnapshotSendPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); +void syncApplyMsgPrint(const SyncApplyMsg* pMsg) { + char* serialized = syncApplyMsg2Str(pMsg); + printf("syncApplyMsgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } -void syncSnapshotSendPrint2(char* s, const SyncSnapshotSend* pMsg) { - char* serialized = syncSnapshotSend2Str(pMsg); - printf("syncSnapshotSendPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); +void syncApplyMsgPrint2(char* s, const SyncApplyMsg* pMsg) { + char* serialized = syncApplyMsg2Str(pMsg); + printf("syncApplyMsgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } -void syncSnapshotSendLog(const SyncSnapshotSend* pMsg) { - char* serialized = syncSnapshotSend2Str(pMsg); - sTrace("syncSnapshotSendLog | len:%d | %s", (int32_t)strlen(serialized), serialized); +void syncApplyMsgLog(const SyncApplyMsg* pMsg) { + char* serialized = syncApplyMsg2Str(pMsg); + sTrace("ssyncApplyMsgLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } -void syncSnapshotSendLog2(char* s, const SyncSnapshotSend* pMsg) { +void syncApplyMsgLog2(char* s, const SyncApplyMsg* pMsg) { if (gRaftDetailLog) { - char* serialized = syncSnapshotSend2Str(pMsg); - sTrace("syncSnapshotSendLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); + char* serialized = syncApplyMsg2Str(pMsg); + sTrace("syncApplyMsgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } } // --------------------------------------------- +SyncSnapshotSend* syncSnapshotSendBuild(uint32_t dataLen, int32_t vgId) { + uint32_t bytes = sizeof(SyncSnapshotSend) + dataLen; + SyncSnapshotSend* pMsg = taosMemoryMalloc(bytes); + memset(pMsg, 0, bytes); + pMsg->bytes = bytes; + pMsg->vgId = vgId; + pMsg->msgType = TDMT_SYNC_SNAPSHOT_SEND; + pMsg->dataLen = dataLen; + return pMsg; +} + +void syncSnapshotSendDestroy(SyncSnapshotSend* pMsg) { + if (pMsg != NULL) { + taosMemoryFree(pMsg); + } +} + +void syncSnapshotSendSerialize(const SyncSnapshotSend* pMsg, char* buf, uint32_t bufLen) { + ASSERT(pMsg->bytes <= bufLen); + memcpy(buf, pMsg, pMsg->bytes); +} + +void syncSnapshotSendDeserialize(const char* buf, uint32_t len, SyncSnapshotSend* pMsg) { + memcpy(pMsg, buf, len); + ASSERT(len == pMsg->bytes); + ASSERT(pMsg->bytes == sizeof(SyncSnapshotSend) + pMsg->dataLen); +} + +char* syncSnapshotSendSerialize2(const SyncSnapshotSend* pMsg, uint32_t* len) { + char* buf = taosMemoryMalloc(pMsg->bytes); + ASSERT(buf != NULL); + syncSnapshotSendSerialize(pMsg, buf, pMsg->bytes); + if (len != NULL) { + *len = pMsg->bytes; + } + return buf; +} + +SyncSnapshotSend* syncSnapshotSendDeserialize2(const char* buf, uint32_t len) { + uint32_t bytes = *((uint32_t*)buf); + SyncSnapshotSend* pMsg = taosMemoryMalloc(bytes); + ASSERT(pMsg != NULL); + syncSnapshotSendDeserialize(buf, len, pMsg); + ASSERT(len == pMsg->bytes); + return pMsg; +} + +void syncSnapshotSend2RpcMsg(const SyncSnapshotSend* pMsg, SRpcMsg* pRpcMsg) { + memset(pRpcMsg, 0, sizeof(*pRpcMsg)); + pRpcMsg->msgType = pMsg->msgType; + pRpcMsg->contLen = pMsg->bytes; + pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen); + syncSnapshotSendSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen); +} + +void syncSnapshotSendFromRpcMsg(const SRpcMsg* pRpcMsg, SyncSnapshotSend* pMsg) { + syncSnapshotSendDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg); +} + +SyncSnapshotSend* syncSnapshotSendFromRpcMsg2(const SRpcMsg* pRpcMsg) { + SyncSnapshotSend* pMsg = syncSnapshotSendDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); + ASSERT(pMsg != NULL); + return pMsg; +} + SyncSnapshotRsp* syncSnapshotRspBuild(int32_t vgId) { uint32_t bytes = sizeof(SyncSnapshotRsp); SyncSnapshotRsp* pMsg = taosMemoryMalloc(bytes); @@ -2751,8 +2531,8 @@ cJSON* syncSnapshotRsp2Json(const SyncSnapshotRsp* pMsg) { snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term); cJSON_AddStringToObject(pRoot, "term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm); - cJSON_AddStringToObject(pRoot, "privateTerm", u64buf); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->startTime); + cJSON_AddStringToObject(pRoot, "startTime", u64buf); snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->lastIndex); cJSON_AddStringToObject(pRoot, "lastIndex", u64buf); @@ -2762,6 +2542,9 @@ cJSON* syncSnapshotRsp2Json(const SyncSnapshotRsp* pMsg) { cJSON_AddNumberToObject(pRoot, "ack", pMsg->ack); cJSON_AddNumberToObject(pRoot, "code", pMsg->code); + + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->snapBeginIndex); + cJSON_AddStringToObject(pRoot, "snap-begin", u64buf); } cJSON* pJson = cJSON_CreateObject(); @@ -2938,100 +2721,80 @@ char* syncLeaderTransfer2Str(const SyncLeaderTransfer* pMsg) { return serialized; } -// for debug ---------------------- -void syncLeaderTransferPrint(const SyncLeaderTransfer* pMsg) { - char* serialized = syncLeaderTransfer2Str(pMsg); - printf("syncLeaderTransferPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncLeaderTransferPrint2(char* s, const SyncLeaderTransfer* pMsg) { - char* serialized = syncLeaderTransfer2Str(pMsg); - printf("syncLeaderTransferPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncLeaderTransferLog(const SyncLeaderTransfer* pMsg) { - char* serialized = syncLeaderTransfer2Str(pMsg); - sTrace("syncLeaderTransferLog | len:%d | %s", (int32_t)strlen(serialized), serialized); - taosMemoryFree(serialized); -} - -void syncLeaderTransferLog2(char* s, const SyncLeaderTransfer* pMsg) { - if (gRaftDetailLog) { - char* serialized = syncLeaderTransfer2Str(pMsg); - sTrace("syncLeaderTransferLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); - taosMemoryFree(serialized); +const char* syncLocalCmdGetStr(int32_t cmd) { + if (cmd == SYNC_LOCAL_CMD_STEP_DOWN) { + return "step-down"; + } else if (cmd == SYNC_LOCAL_CMD_FOLLOWER_CMT) { + return "follower-commit"; } + + return "unknown-local-cmd"; } -// --------------------------------------------- -SyncReconfigFinish* syncReconfigFinishBuild(int32_t vgId) { - uint32_t bytes = sizeof(SyncReconfigFinish); - SyncReconfigFinish* pMsg = taosMemoryMalloc(bytes); +SyncLocalCmd* syncLocalCmdBuild(int32_t vgId) { + uint32_t bytes = sizeof(SyncLocalCmd); + SyncLocalCmd* pMsg = taosMemoryMalloc(bytes); memset(pMsg, 0, bytes); pMsg->bytes = bytes; pMsg->vgId = vgId; - pMsg->msgType = TDMT_SYNC_CONFIG_CHANGE_FINISH; + pMsg->msgType = TDMT_SYNC_LOCAL_CMD; return pMsg; } -void syncReconfigFinishDestroy(SyncReconfigFinish* pMsg) { +void syncLocalCmdDestroy(SyncLocalCmd* pMsg) { if (pMsg != NULL) { taosMemoryFree(pMsg); } } -void syncReconfigFinishSerialize(const SyncReconfigFinish* pMsg, char* buf, uint32_t bufLen) { +void syncLocalCmdSerialize(const SyncLocalCmd* pMsg, char* buf, uint32_t bufLen) { ASSERT(pMsg->bytes <= bufLen); memcpy(buf, pMsg, pMsg->bytes); } -void syncReconfigFinishDeserialize(const char* buf, uint32_t len, SyncReconfigFinish* pMsg) { +void syncLocalCmdDeserialize(const char* buf, uint32_t len, SyncLocalCmd* pMsg) { memcpy(pMsg, buf, len); ASSERT(len == pMsg->bytes); } -char* syncReconfigFinishSerialize2(const SyncReconfigFinish* pMsg, uint32_t* len) { +char* syncLocalCmdSerialize2(const SyncLocalCmd* pMsg, uint32_t* len) { char* buf = taosMemoryMalloc(pMsg->bytes); ASSERT(buf != NULL); - syncReconfigFinishSerialize(pMsg, buf, pMsg->bytes); + syncLocalCmdSerialize(pMsg, buf, pMsg->bytes); if (len != NULL) { *len = pMsg->bytes; } return buf; } -SyncReconfigFinish* syncReconfigFinishDeserialize2(const char* buf, uint32_t len) { - uint32_t bytes = *((uint32_t*)buf); - SyncReconfigFinish* pMsg = taosMemoryMalloc(bytes); +SyncLocalCmd* syncLocalCmdDeserialize2(const char* buf, uint32_t len) { + uint32_t bytes = *((uint32_t*)buf); + SyncLocalCmd* pMsg = taosMemoryMalloc(bytes); ASSERT(pMsg != NULL); - syncReconfigFinishDeserialize(buf, len, pMsg); + syncLocalCmdDeserialize(buf, len, pMsg); ASSERT(len == pMsg->bytes); return pMsg; } -void syncReconfigFinish2RpcMsg(const SyncReconfigFinish* pMsg, SRpcMsg* pRpcMsg) { +void syncLocalCmd2RpcMsg(const SyncLocalCmd* pMsg, SRpcMsg* pRpcMsg) { memset(pRpcMsg, 0, sizeof(*pRpcMsg)); pRpcMsg->msgType = pMsg->msgType; pRpcMsg->contLen = pMsg->bytes; pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen); - syncReconfigFinishSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen); + syncLocalCmdSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen); } -void syncReconfigFinishFromRpcMsg(const SRpcMsg* pRpcMsg, SyncReconfigFinish* pMsg) { - syncReconfigFinishDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg); +void syncLocalCmdFromRpcMsg(const SRpcMsg* pRpcMsg, SyncLocalCmd* pMsg) { + syncLocalCmdDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg); } -SyncReconfigFinish* syncReconfigFinishFromRpcMsg2(const SRpcMsg* pRpcMsg) { - SyncReconfigFinish* pMsg = syncReconfigFinishDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); +SyncLocalCmd* syncLocalCmdFromRpcMsg2(const SRpcMsg* pRpcMsg) { + SyncLocalCmd* pMsg = syncLocalCmdDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); ASSERT(pMsg != NULL); return pMsg; } -cJSON* syncReconfigFinish2Json(const SyncReconfigFinish* pMsg) { +cJSON* syncLocalCmd2Json(const SyncLocalCmd* pMsg) { char u64buf[128]; cJSON* pRoot = cJSON_CreateObject(); @@ -3040,58 +2803,82 @@ cJSON* syncReconfigFinish2Json(const SyncReconfigFinish* pMsg) { cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId); cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); - cJSON* pOldCfg = syncCfg2Json((SSyncCfg*)(&(pMsg->oldCfg))); - cJSON* pNewCfg = syncCfg2Json((SSyncCfg*)(&(pMsg->newCfg))); - cJSON_AddItemToObject(pRoot, "oldCfg", pOldCfg); - cJSON_AddItemToObject(pRoot, "newCfg", pNewCfg); + cJSON* pSrcId = cJSON_CreateObject(); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr); + cJSON_AddStringToObject(pSrcId, "addr", u64buf); + { + uint64_t u64 = pMsg->srcId.addr; + cJSON* pTmp = pSrcId; + char host[128]; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId); + cJSON_AddItemToObject(pRoot, "srcId", pSrcId); + + cJSON* pDestId = cJSON_CreateObject(); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr); + cJSON_AddStringToObject(pDestId, "addr", u64buf); + { + uint64_t u64 = pMsg->destId.addr; + cJSON* pTmp = pDestId; + char host[128]; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); + cJSON_AddItemToObject(pRoot, "destId", pDestId); - snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->newCfgIndex); - cJSON_AddStringToObject(pRoot, "newCfgIndex", u64buf); + cJSON_AddNumberToObject(pRoot, "cmd", pMsg->cmd); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->newCfgTerm); - cJSON_AddStringToObject(pRoot, "newCfgTerm", u64buf); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->sdNewTerm); + cJSON_AddStringToObject(pRoot, "sd-new-term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->newCfgSeqNum); - cJSON_AddStringToObject(pRoot, "newCfgSeqNum", u64buf); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->fcIndex); + cJSON_AddStringToObject(pRoot, "fc-index", u64buf); } cJSON* pJson = cJSON_CreateObject(); - cJSON_AddItemToObject(pJson, "SyncReconfigFinish", pRoot); + cJSON_AddItemToObject(pJson, "SyncLocalCmd2Json", pRoot); return pJson; } -char* syncReconfigFinish2Str(const SyncReconfigFinish* pMsg) { - cJSON* pJson = syncReconfigFinish2Json(pMsg); +char* syncLocalCmd2Str(const SyncLocalCmd* pMsg) { + cJSON* pJson = syncLocalCmd2Json(pMsg); char* serialized = cJSON_Print(pJson); cJSON_Delete(pJson); return serialized; } // for debug ---------------------- -void syncReconfigFinishPrint(const SyncReconfigFinish* pMsg) { - char* serialized = syncReconfigFinish2Str(pMsg); - printf("syncReconfigFinishPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); +void syncLocalCmdPrint(const SyncLocalCmd* pMsg) { + char* serialized = syncLocalCmd2Str(pMsg); + printf("syncLocalCmdPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); fflush(NULL); taosMemoryFree(serialized); } -void syncReconfigFinishPrint2(char* s, const SyncReconfigFinish* pMsg) { - char* serialized = syncReconfigFinish2Str(pMsg); - printf("syncReconfigFinishPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); +void syncLocalCmdPrint2(char* s, const SyncLocalCmd* pMsg) { + char* serialized = syncLocalCmd2Str(pMsg); + printf("syncLocalCmdPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); fflush(NULL); taosMemoryFree(serialized); } -void syncReconfigFinishLog(const SyncReconfigFinish* pMsg) { - char* serialized = syncReconfigFinish2Str(pMsg); - sTrace("syncReconfigFinishLog | len:%d | %s", (int32_t)strlen(serialized), serialized); +void syncLocalCmdLog(const SyncLocalCmd* pMsg) { + char* serialized = syncLocalCmd2Str(pMsg); + sTrace("syncLocalCmdLog | len:%d | %s", (int32_t)strlen(serialized), serialized); taosMemoryFree(serialized); } -void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg) { +void syncLocalCmdLog2(char* s, const SyncLocalCmd* pMsg) { if (gRaftDetailLog) { - char* serialized = syncReconfigFinish2Str(pMsg); - sTrace("syncReconfigFinishLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); + char* serialized = syncLocalCmd2Str(pMsg); + sTrace("syncLocalCmdLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); taosMemoryFree(serialized); } -} +} \ No newline at end of file diff --git a/source/libs/sync/src/syncRaftCfg.c b/source/libs/sync/src/syncRaftCfg.c index 7c8f503de6b3ffec9cb118cf9972bbf17ff412ee..66c399d15af671634a2a86da9ccc13b1894f8ff4 100644 --- a/source/libs/sync/src/syncRaftCfg.c +++ b/source/libs/sync/src/syncRaftCfg.c @@ -249,33 +249,6 @@ char *syncCfg2Str(SSyncCfg *pSyncCfg) { return serialized; } -char *syncCfg2SimpleStr(SSyncCfg *pSyncCfg) { - if (pSyncCfg != NULL) { - int32_t len = 512; - char *s = taosMemoryMalloc(len); - memset(s, 0, len); - - snprintf(s, len, "{r-num:%d, my:%d, ", pSyncCfg->replicaNum, pSyncCfg->myIndex); - char *p = s + strlen(s); - for (int i = 0; i < pSyncCfg->replicaNum; ++i) { - /* - if (p + 128 + 32 > s + len) { - break; - } - */ - char buf[128 + 32]; - snprintf(buf, sizeof(buf), "%s:%d, ", pSyncCfg->nodeInfo[i].nodeFqdn, pSyncCfg->nodeInfo[i].nodePort); - strncpy(p, buf, sizeof(buf)); - p = s + strlen(s); - } - strcpy(p - 2, "}"); - - return s; - } - - return NULL; -} - int32_t syncCfgFromJson(const cJSON *pRoot, SSyncCfg *pSyncCfg) { memset(pSyncCfg, 0, sizeof(SSyncCfg)); // cJSON *pJson = cJSON_GetObjectItem(pRoot, "SSyncCfg"); @@ -442,88 +415,3 @@ int32_t raftCfgFromStr(const char *s, SRaftCfg *pRaftCfg) { return 0; } -// for debug ---------------------- -void syncCfgPrint(SSyncCfg *pCfg) { - char *serialized = syncCfg2Str(pCfg); - printf("syncCfgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncCfgPrint2(char *s, SSyncCfg *pCfg) { - char *serialized = syncCfg2Str(pCfg); - printf("syncCfgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncCfgLog(SSyncCfg *pCfg) { - char *serialized = syncCfg2Str(pCfg); - sTrace("syncCfgLog | len:%d | %s", (int32_t)strlen(serialized), serialized); - taosMemoryFree(serialized); -} - -void syncCfgLog2(char *s, SSyncCfg *pCfg) { - char *serialized = syncCfg2Str(pCfg); - sTrace("syncCfgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); - taosMemoryFree(serialized); -} - -void syncCfgLog3(char *s, SSyncCfg *pCfg) { - char *serialized = syncCfg2SimpleStr(pCfg); - sTrace("syncCfgLog3 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); - taosMemoryFree(serialized); -} - -void raftCfgPrint(SRaftCfg *pCfg) { - char *serialized = raftCfg2Str(pCfg); - printf("raftCfgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void raftCfgPrint2(char *s, SRaftCfg *pCfg) { - char *serialized = raftCfg2Str(pCfg); - printf("raftCfgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void raftCfgLog(SRaftCfg *pCfg) { - char *serialized = raftCfg2Str(pCfg); - sTrace("raftCfgLog | len:%d | %s", (int32_t)strlen(serialized), serialized); - taosMemoryFree(serialized); -} - -void raftCfgLog2(char *s, SRaftCfg *pCfg) { - char *serialized = raftCfg2Str(pCfg); - sTrace("raftCfgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); - taosMemoryFree(serialized); -} - -// --------- -void raftCfgIndexPrint(SRaftCfgIndex *pCfg) { - char *serialized = raftCfgIndex2Str(pCfg); - printf("raftCfgIndexPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void raftCfgIndexPrint2(char *s, SRaftCfgIndex *pCfg) { - char *serialized = raftCfgIndex2Str(pCfg); - printf("raftCfgIndexPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void raftCfgIndexLog(SRaftCfgIndex *pCfg) { - char *serialized = raftCfgIndex2Str(pCfg); - sTrace("raftCfgIndexLog | len:%d | %s", (int32_t)strlen(serialized), serialized); - taosMemoryFree(serialized); -} - -void raftCfgIndexLog2(char *s, SRaftCfgIndex *pCfg) { - char *serialized = raftCfgIndex2Str(pCfg); - sTrace("raftCfgIndexLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); - taosMemoryFree(serialized); -} diff --git a/source/libs/sync/src/syncRaftEntry.c b/source/libs/sync/src/syncRaftEntry.c index 6d372acf2fd1b349e60309ecc0dcc87e995a8d01..c5b1399c8caf8b53eeb7ca16c1f505ef575e7ea4 100644 --- a/source/libs/sync/src/syncRaftEntry.c +++ b/source/libs/sync/src/syncRaftEntry.c @@ -13,31 +13,28 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE #include "syncRaftEntry.h" #include "syncUtil.h" -SSyncRaftEntry* syncEntryBuild(uint32_t dataLen) { - uint32_t bytes = sizeof(SSyncRaftEntry) + dataLen; +SSyncRaftEntry* syncEntryBuild(int32_t dataLen) { + int32_t bytes = sizeof(SSyncRaftEntry) + dataLen; SSyncRaftEntry* pEntry = taosMemoryMalloc(bytes); - ASSERT(pEntry != NULL); - memset(pEntry, 0, bytes); + if (pEntry == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } + pEntry->bytes = bytes; pEntry->dataLen = dataLen; pEntry->rid = -1; - return pEntry; -} - -// step 4. SyncClientRequest => SSyncRaftEntry, add term, index -SSyncRaftEntry* syncEntryBuild2(SyncClientRequest* pMsg, SyncTerm term, SyncIndex index) { - SSyncRaftEntry* pEntry = syncEntryBuild3(pMsg, term, index); - ASSERT(pEntry != NULL); return pEntry; } -SSyncRaftEntry* syncEntryBuild3(SyncClientRequest* pMsg, SyncTerm term, SyncIndex index) { +SSyncRaftEntry* syncEntryBuildFromClientRequest(const SyncClientRequest* pMsg, SyncTerm term, SyncIndex index) { SSyncRaftEntry* pEntry = syncEntryBuild(pMsg->dataLen); - ASSERT(pEntry != NULL); + if (pEntry == NULL) return NULL; pEntry->msgType = pMsg->msgType; pEntry->originalRpcType = pMsg->originalRpcType; @@ -45,42 +42,37 @@ SSyncRaftEntry* syncEntryBuild3(SyncClientRequest* pMsg, SyncTerm term, SyncInde pEntry->isWeak = pMsg->isWeak; pEntry->term = term; pEntry->index = index; - pEntry->dataLen = pMsg->dataLen; memcpy(pEntry->data, pMsg->data, pMsg->dataLen); return pEntry; } -SSyncRaftEntry* syncEntryBuild4(SRpcMsg* pOriginalMsg, SyncTerm term, SyncIndex index) { - SSyncRaftEntry* pEntry = syncEntryBuild(pOriginalMsg->contLen); - ASSERT(pEntry != NULL); +SSyncRaftEntry* syncEntryBuildFromRpcMsg(const SRpcMsg* pMsg, SyncTerm term, SyncIndex index) { + SSyncRaftEntry* pEntry = syncEntryBuild(pMsg->contLen); + if (pEntry == NULL) return NULL; pEntry->msgType = TDMT_SYNC_CLIENT_REQUEST; - pEntry->originalRpcType = pOriginalMsg->msgType; + pEntry->originalRpcType = pMsg->msgType; pEntry->seqNum = 0; pEntry->isWeak = 0; pEntry->term = term; pEntry->index = index; - pEntry->dataLen = pOriginalMsg->contLen; - memcpy(pEntry->data, pOriginalMsg->pCont, pOriginalMsg->contLen); + memcpy(pEntry->data, pMsg->pCont, pMsg->contLen); + + return pEntry; +} + +SSyncRaftEntry* syncEntryBuildFromAppendEntries(const SyncAppendEntries* pMsg) { + SSyncRaftEntry* pEntry = syncEntryBuild(pMsg->dataLen); + if (pEntry == NULL) return NULL; + memcpy(pEntry, pMsg->data, pMsg->dataLen); return pEntry; } SSyncRaftEntry* syncEntryBuildNoop(SyncTerm term, SyncIndex index, int32_t vgId) { - // init rpcMsg - SMsgHead head; - head.vgId = vgId; - head.contLen = sizeof(SMsgHead); - SRpcMsg rpcMsg; - memset(&rpcMsg, 0, sizeof(SRpcMsg)); - rpcMsg.contLen = head.contLen; - rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen); - rpcMsg.msgType = TDMT_SYNC_NOOP; - memcpy(rpcMsg.pCont, &head, sizeof(head)); - - SSyncRaftEntry* pEntry = syncEntryBuild(rpcMsg.contLen); - ASSERT(pEntry != NULL); + SSyncRaftEntry* pEntry = syncEntryBuild(sizeof(SMsgHead)); + if (pEntry == NULL) return NULL; pEntry->msgType = TDMT_SYNC_CLIENT_REQUEST; pEntry->originalRpcType = TDMT_SYNC_NOOP; @@ -89,9 +81,9 @@ SSyncRaftEntry* syncEntryBuildNoop(SyncTerm term, SyncIndex index, int32_t vgId) pEntry->term = term; pEntry->index = index; - ASSERT(pEntry->dataLen == rpcMsg.contLen); - memcpy(pEntry->data, rpcMsg.pCont, rpcMsg.contLen); - rpcFreeCont(rpcMsg.pCont); + SMsgHead* pHead = (SMsgHead*)pEntry->data; + pHead->vgId = vgId; + pHead->contLen = sizeof(SMsgHead); return pEntry; } @@ -102,104 +94,13 @@ void syncEntryDestory(SSyncRaftEntry* pEntry) { } } -// step 5. SSyncRaftEntry => bin, to raft log -char* syncEntrySerialize(const SSyncRaftEntry* pEntry, uint32_t* len) { - char* buf = taosMemoryMalloc(pEntry->bytes); - ASSERT(buf != NULL); - memcpy(buf, pEntry, pEntry->bytes); - if (len != NULL) { - *len = pEntry->bytes; - } - return buf; -} - -// step 6. bin => SSyncRaftEntry, from raft log -SSyncRaftEntry* syncEntryDeserialize(const char* buf, uint32_t len) { - uint32_t bytes = *((uint32_t*)buf); - SSyncRaftEntry* pEntry = taosMemoryMalloc(bytes); - ASSERT(pEntry != NULL); - memcpy(pEntry, buf, len); - ASSERT(len == pEntry->bytes); - return pEntry; -} - -cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry) { - char u64buf[128] = {0}; - cJSON* pRoot = cJSON_CreateObject(); - - if (pEntry != NULL) { - cJSON_AddNumberToObject(pRoot, "bytes", pEntry->bytes); - cJSON_AddNumberToObject(pRoot, "msgType", pEntry->msgType); - cJSON_AddNumberToObject(pRoot, "originalRpcType", pEntry->originalRpcType); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pEntry->seqNum); - cJSON_AddStringToObject(pRoot, "seqNum", u64buf); - cJSON_AddNumberToObject(pRoot, "isWeak", pEntry->isWeak); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pEntry->term); - cJSON_AddStringToObject(pRoot, "term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pEntry->index); - cJSON_AddStringToObject(pRoot, "index", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pEntry->rid); - cJSON_AddStringToObject(pRoot, "rid", u64buf); - cJSON_AddNumberToObject(pRoot, "dataLen", pEntry->dataLen); - - char* s; - s = syncUtilprintBin((char*)(pEntry->data), pEntry->dataLen); - cJSON_AddStringToObject(pRoot, "data", s); - taosMemoryFree(s); - - s = syncUtilprintBin2((char*)(pEntry->data), pEntry->dataLen); - cJSON_AddStringToObject(pRoot, "data2", s); - taosMemoryFree(s); - } - - cJSON* pJson = cJSON_CreateObject(); - cJSON_AddItemToObject(pJson, "SSyncRaftEntry", pRoot); - return pJson; -} - -char* syncEntry2Str(const SSyncRaftEntry* pEntry) { - cJSON* pJson = syncEntry2Json(pEntry); - char* serialized = cJSON_Print(pJson); - cJSON_Delete(pJson); - return serialized; -} - -// step 7. SSyncRaftEntry => original SRpcMsg, commit to user, delete seqNum, isWeak, term, index void syncEntry2OriginalRpc(const SSyncRaftEntry* pEntry, SRpcMsg* pRpcMsg) { - memset(pRpcMsg, 0, sizeof(*pRpcMsg)); pRpcMsg->msgType = pEntry->originalRpcType; pRpcMsg->contLen = pEntry->dataLen; pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen); memcpy(pRpcMsg->pCont, pEntry->data, pRpcMsg->contLen); } -// for debug ---------------------- -void syncEntryPrint(const SSyncRaftEntry* pObj) { - char* serialized = syncEntry2Str(pObj); - printf("syncEntryPrint | len:%zu | %s \n", strlen(serialized), serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncEntryPrint2(char* s, const SSyncRaftEntry* pObj) { - char* serialized = syncEntry2Str(pObj); - printf("syncEntryPrint2 | len:%zu | %s | %s \n", strlen(serialized), s, serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void syncEntryLog(const SSyncRaftEntry* pObj) { - char* serialized = syncEntry2Str(pObj); - sTrace("syncEntryLog | len:%zu | %s", strlen(serialized), serialized); - taosMemoryFree(serialized); -} - -void syncEntryLog2(char* s, const SSyncRaftEntry* pObj) { - char* serialized = syncEntry2Str(pObj); - sTrace("syncEntryLog2 | len:%zu | %s | %s", strlen(serialized), s, serialized); - taosMemoryFree(serialized); -} - //----------------------------------- SRaftEntryHashCache* raftCacheCreate(SSyncNode* pSyncNode, int32_t maxCount) { SRaftEntryHashCache* pCache = taosMemoryMalloc(sizeof(SRaftEntryHashCache)); @@ -225,9 +126,9 @@ SRaftEntryHashCache* raftCacheCreate(SSyncNode* pSyncNode, int32_t maxCount) { void raftCacheDestroy(SRaftEntryHashCache* pCache) { if (pCache != NULL) { - taosThreadMutexLock(&(pCache->mutex)); + taosThreadMutexLock(&pCache->mutex); taosHashCleanup(pCache->pEntryHash); - taosThreadMutexUnlock(&(pCache->mutex)); + taosThreadMutexUnlock(&pCache->mutex); taosThreadMutexDestroy(&(pCache->mutex)); taosMemoryFree(pCache); } @@ -237,25 +138,20 @@ void raftCacheDestroy(SRaftEntryHashCache* pCache) { // max count, return 0 // error, return -1 int32_t raftCachePutEntry(struct SRaftEntryHashCache* pCache, SSyncRaftEntry* pEntry) { - taosThreadMutexLock(&(pCache->mutex)); + taosThreadMutexLock(&pCache->mutex); if (pCache->currentCount >= pCache->maxCount) { - taosThreadMutexUnlock(&(pCache->mutex)); + taosThreadMutexUnlock(&pCache->mutex); return 0; } taosHashPut(pCache->pEntryHash, &(pEntry->index), sizeof(pEntry->index), pEntry, pEntry->bytes); ++(pCache->currentCount); - do { - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "raft cache add, type:%s,%d, type2:%s,%d, index:%" PRId64 ", bytes:%d", - TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType, - pEntry->index, pEntry->bytes); - syncNodeEventLog(pCache->pSyncNode, eventLog); - } while (0); - - taosThreadMutexUnlock(&(pCache->mutex)); + sNTrace(pCache->pSyncNode, "raft cache add, type:%s,%d, type2:%s,%d, index:%" PRId64 ", bytes:%d", + TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType, + pEntry->index, pEntry->bytes); + taosThreadMutexUnlock(&pCache->mutex); return 1; } @@ -268,26 +164,21 @@ int32_t raftCacheGetEntry(struct SRaftEntryHashCache* pCache, SyncIndex index, S } *ppEntry = NULL; - taosThreadMutexLock(&(pCache->mutex)); + taosThreadMutexLock(&pCache->mutex); void* pTmp = taosHashGet(pCache->pEntryHash, &index, sizeof(index)); if (pTmp != NULL) { SSyncRaftEntry* pEntry = pTmp; *ppEntry = taosMemoryMalloc(pEntry->bytes); memcpy(*ppEntry, pTmp, pEntry->bytes); - do { - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "raft cache get, type:%s,%d, type2:%s,%d, index:%" PRId64, - TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType), - (*ppEntry)->originalRpcType, (*ppEntry)->index); - syncNodeEventLog(pCache->pSyncNode, eventLog); - } while (0); - - taosThreadMutexUnlock(&(pCache->mutex)); + sNTrace(pCache->pSyncNode, "raft cache get, type:%s,%d, type2:%s,%d, index:%" PRId64, + TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType), + (*ppEntry)->originalRpcType, (*ppEntry)->index); + taosThreadMutexUnlock(&pCache->mutex); return 0; } - taosThreadMutexUnlock(&(pCache->mutex)); + taosThreadMutexUnlock(&pCache->mutex); terrno = TSDB_CODE_WAL_LOG_NOT_EXIST; return -1; } @@ -301,34 +192,29 @@ int32_t raftCacheGetEntryP(struct SRaftEntryHashCache* pCache, SyncIndex index, } *ppEntry = NULL; - taosThreadMutexLock(&(pCache->mutex)); + taosThreadMutexLock(&pCache->mutex); void* pTmp = taosHashGet(pCache->pEntryHash, &index, sizeof(index)); if (pTmp != NULL) { SSyncRaftEntry* pEntry = pTmp; *ppEntry = pEntry; - do { - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "raft cache get, type:%s,%d, type2:%s,%d, index:%" PRId64, - TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType), - (*ppEntry)->originalRpcType, (*ppEntry)->index); - syncNodeEventLog(pCache->pSyncNode, eventLog); - } while (0); - - taosThreadMutexUnlock(&(pCache->mutex)); + sNTrace(pCache->pSyncNode, "raft cache get, type:%s,%d, type2:%s,%d, index:%" PRId64, + TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType), + (*ppEntry)->originalRpcType, (*ppEntry)->index); + taosThreadMutexUnlock(&pCache->mutex); return 0; } - taosThreadMutexUnlock(&(pCache->mutex)); + taosThreadMutexUnlock(&pCache->mutex); terrno = TSDB_CODE_WAL_LOG_NOT_EXIST; return -1; } int32_t raftCacheDelEntry(struct SRaftEntryHashCache* pCache, SyncIndex index) { - taosThreadMutexLock(&(pCache->mutex)); + taosThreadMutexLock(&pCache->mutex); taosHashRemove(pCache->pEntryHash, &index, sizeof(index)); --(pCache->currentCount); - taosThreadMutexUnlock(&(pCache->mutex)); + taosThreadMutexUnlock(&pCache->mutex); return 0; } @@ -338,111 +224,37 @@ int32_t raftCacheGetAndDel(struct SRaftEntryHashCache* pCache, SyncIndex index, } *ppEntry = NULL; - taosThreadMutexLock(&(pCache->mutex)); + taosThreadMutexLock(&pCache->mutex); void* pTmp = taosHashGet(pCache->pEntryHash, &index, sizeof(index)); if (pTmp != NULL) { SSyncRaftEntry* pEntry = pTmp; *ppEntry = taosMemoryMalloc(pEntry->bytes); memcpy(*ppEntry, pTmp, pEntry->bytes); - do { - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "raft cache get-and-del, type:%s,%d, type2:%s,%d, index:%" PRId64, - TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType), - (*ppEntry)->originalRpcType, (*ppEntry)->index); - syncNodeEventLog(pCache->pSyncNode, eventLog); - } while (0); + sNTrace(pCache->pSyncNode, "raft cache get-and-del, type:%s,%d, type2:%s,%d, index:%" PRId64, + TMSG_INFO((*ppEntry)->msgType), (*ppEntry)->msgType, TMSG_INFO((*ppEntry)->originalRpcType), + (*ppEntry)->originalRpcType, (*ppEntry)->index); taosHashRemove(pCache->pEntryHash, &index, sizeof(index)); --(pCache->currentCount); - taosThreadMutexUnlock(&(pCache->mutex)); + taosThreadMutexUnlock(&pCache->mutex); return 0; } - taosThreadMutexUnlock(&(pCache->mutex)); + taosThreadMutexUnlock(&pCache->mutex); terrno = TSDB_CODE_WAL_LOG_NOT_EXIST; return -1; } int32_t raftCacheClear(struct SRaftEntryHashCache* pCache) { - taosThreadMutexLock(&(pCache->mutex)); + taosThreadMutexLock(&pCache->mutex); taosHashClear(pCache->pEntryHash); pCache->currentCount = 0; - taosThreadMutexUnlock(&(pCache->mutex)); + taosThreadMutexUnlock(&pCache->mutex); return 0; } -//----------------------------------- -cJSON* raftCache2Json(SRaftEntryHashCache* pCache) { - char u64buf[128] = {0}; - cJSON* pRoot = cJSON_CreateObject(); - - if (pCache != NULL) { - taosThreadMutexLock(&(pCache->mutex)); - - snprintf(u64buf, sizeof(u64buf), "%p", pCache->pSyncNode); - cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); - cJSON_AddNumberToObject(pRoot, "currentCount", pCache->currentCount); - cJSON_AddNumberToObject(pRoot, "maxCount", pCache->maxCount); - cJSON* pEntries = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "entries", pEntries); - - SSyncRaftEntry* pIter = (SSyncRaftEntry*)taosHashIterate(pCache->pEntryHash, NULL); - if (pIter != NULL) { - SSyncRaftEntry* pEntry = (SSyncRaftEntry*)pIter; - cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry)); - } - while (pIter) { - pIter = taosHashIterate(pCache->pEntryHash, pIter); - if (pIter != NULL) { - SSyncRaftEntry* pEntry = (SSyncRaftEntry*)pIter; - cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry)); - } - } - - taosThreadMutexUnlock(&(pCache->mutex)); - } - - cJSON* pJson = cJSON_CreateObject(); - cJSON_AddItemToObject(pJson, "SRaftEntryHashCache", pRoot); - return pJson; -} - -char* raftCache2Str(SRaftEntryHashCache* pCache) { - cJSON* pJson = raftCache2Json(pCache); - char* serialized = cJSON_Print(pJson); - cJSON_Delete(pJson); - return serialized; -} - -void raftCachePrint(SRaftEntryHashCache* pCache) { - char* serialized = raftCache2Str(pCache); - printf("raftCachePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void raftCachePrint2(char* s, SRaftEntryHashCache* pCache) { - char* serialized = raftCache2Str(pCache); - printf("raftCachePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void raftCacheLog(SRaftEntryHashCache* pCache) { - char* serialized = raftCache2Str(pCache); - sTrace("raftCacheLog | len:%d | %s", (int32_t)strlen(serialized), serialized); - taosMemoryFree(serialized); -} - -void raftCacheLog2(char* s, SRaftEntryHashCache* pCache) { - if (gRaftDetailLog) { - char* serialized = raftCache2Str(pCache); - sTraceLong("raftCacheLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); - taosMemoryFree(serialized); - } -} //----------------------------------- static char* keyFn(const void* pData) { @@ -482,13 +294,13 @@ SRaftEntryCache* raftEntryCacheCreate(SSyncNode* pSyncNode, int32_t maxCount) { void raftEntryCacheDestroy(SRaftEntryCache* pCache) { if (pCache != NULL) { - taosThreadMutexLock(&(pCache->mutex)); + taosThreadMutexLock(&pCache->mutex); tSkipListDestroy(pCache->pSkipList); if (pCache->refMgr != -1) { taosCloseRef(pCache->refMgr); pCache->refMgr = -1; } - taosThreadMutexUnlock(&(pCache->mutex)); + taosThreadMutexUnlock(&pCache->mutex); taosThreadMutexDestroy(&(pCache->mutex)); taosMemoryFree(pCache); } @@ -498,10 +310,10 @@ void raftEntryCacheDestroy(SRaftEntryCache* pCache) { // max count, return 0 // error, return -1 int32_t raftEntryCachePutEntry(struct SRaftEntryCache* pCache, SSyncRaftEntry* pEntry) { - taosThreadMutexLock(&(pCache->mutex)); + taosThreadMutexLock(&pCache->mutex); if (pCache->currentCount >= pCache->maxCount) { - taosThreadMutexUnlock(&(pCache->mutex)); + taosThreadMutexUnlock(&pCache->mutex); return 0; } @@ -512,15 +324,10 @@ int32_t raftEntryCachePutEntry(struct SRaftEntryCache* pCache, SSyncRaftEntry* p pEntry->rid = taosAddRef(pCache->refMgr, pEntry); ASSERT(pEntry->rid >= 0); - do { - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "raft cache add, type:%s,%d, type2:%s,%d, index:%" PRId64 ", bytes:%d", - TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType, - pEntry->index, pEntry->bytes); - syncNodeEventLog(pCache->pSyncNode, eventLog); - } while (0); - - taosThreadMutexUnlock(&(pCache->mutex)); + sNTrace(pCache->pSyncNode, "raft cache add, type:%s,%d, type2:%s,%d, index:%" PRId64 ", bytes:%d", + TMSG_INFO(pEntry->msgType), pEntry->msgType, TMSG_INFO(pEntry->originalRpcType), pEntry->originalRpcType, + pEntry->index, pEntry->bytes); + taosThreadMutexUnlock(&pCache->mutex); return 1; } @@ -545,7 +352,7 @@ int32_t raftEntryCacheGetEntry(struct SRaftEntryCache* pCache, SyncIndex index, // not found, return 0 // error, return -1 int32_t raftEntryCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry) { - taosThreadMutexLock(&(pCache->mutex)); + taosThreadMutexLock(&pCache->mutex); SyncIndex index2 = index; int32_t code = 0; @@ -569,7 +376,7 @@ int32_t raftEntryCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index, } taosArrayDestroy(entryPArray); - taosThreadMutexUnlock(&(pCache->mutex)); + taosThreadMutexUnlock(&pCache->mutex); return code; } @@ -578,7 +385,7 @@ int32_t raftEntryCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index, // return -1, error // return delete count int32_t raftEntryCacheClear(struct SRaftEntryCache* pCache, int32_t count) { - taosThreadMutexLock(&(pCache->mutex)); + taosThreadMutexLock(&pCache->mutex); int32_t returnCnt = 0; if (count == -1) { @@ -633,72 +440,6 @@ int32_t raftEntryCacheClear(struct SRaftEntryCache* pCache, int32_t count) { } pCache->currentCount -= returnCnt; - taosThreadMutexUnlock(&(pCache->mutex)); + taosThreadMutexUnlock(&pCache->mutex); return returnCnt; } - -cJSON* raftEntryCache2Json(SRaftEntryCache* pCache) { - char u64buf[128] = {0}; - cJSON* pRoot = cJSON_CreateObject(); - - if (pCache != NULL) { - taosThreadMutexLock(&(pCache->mutex)); - - snprintf(u64buf, sizeof(u64buf), "%p", pCache->pSyncNode); - cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); - cJSON_AddNumberToObject(pRoot, "currentCount", pCache->currentCount); - cJSON_AddNumberToObject(pRoot, "maxCount", pCache->maxCount); - cJSON* pEntries = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "entries", pEntries); - - SSkipListIterator* pIter = tSkipListCreateIter(pCache->pSkipList); - while (tSkipListIterNext(pIter)) { - SSkipListNode* pNode = tSkipListIterGet(pIter); - ASSERT(pNode != NULL); - SSyncRaftEntry* pEntry = (SSyncRaftEntry*)SL_GET_NODE_DATA(pNode); - cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry)); - } - tSkipListDestroyIter(pIter); - - taosThreadMutexUnlock(&(pCache->mutex)); - } - - cJSON* pJson = cJSON_CreateObject(); - cJSON_AddItemToObject(pJson, "SRaftEntryCache", pRoot); - return pJson; -} - -char* raftEntryCache2Str(SRaftEntryCache* pObj) { - cJSON* pJson = raftEntryCache2Json(pObj); - char* serialized = cJSON_Print(pJson); - cJSON_Delete(pJson); - return serialized; -} - -void raftEntryCachePrint(SRaftEntryCache* pObj) { - char* serialized = raftEntryCache2Str(pObj); - printf("raftEntryCachePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void raftEntryCachePrint2(char* s, SRaftEntryCache* pObj) { - char* serialized = raftEntryCache2Str(pObj); - printf("raftEntryCachePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void raftEntryCacheLog(SRaftEntryCache* pObj) { - char* serialized = raftEntryCache2Str(pObj); - sTrace("raftEntryCacheLog | len:%d | %s", (int32_t)strlen(serialized), serialized); - taosMemoryFree(serialized); -} - -void raftEntryCacheLog2(char* s, SRaftEntryCache* pObj) { - if (gRaftDetailLog) { - char* serialized = raftEntryCache2Str(pObj); - sTraceLong("raftEntryCacheLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); - taosMemoryFree(serialized); - } -} diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c index 23d076cfbc1affd3f52f1f6e1902bf27d2618519..d4a1d35c743b2808472408d01afe10e679b3b0e4 100644 --- a/source/libs/sync/src/syncRaftLog.c +++ b/source/libs/sync/src/syncRaftLog.c @@ -22,15 +22,8 @@ // public function static int32_t raftLogRestoreFromSnapshot(struct SSyncLogStore* pLogStore, SyncIndex snapshotIndex); -static SyncIndex raftLogBeginIndex(struct SSyncLogStore* pLogStore); -static SyncIndex raftLogEndIndex(struct SSyncLogStore* pLogStore); -static SyncIndex raftLogWriteIndex(struct SSyncLogStore* pLogStore); -static bool raftLogIsEmpty(struct SSyncLogStore* pLogStore); -static int32_t raftLogEntryCount(struct SSyncLogStore* pLogStore); -static SyncIndex raftLogLastIndex(struct SSyncLogStore* pLogStore); -static SyncTerm raftLogLastTerm(struct SSyncLogStore* pLogStore); + static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry); -static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry** ppEntry); static int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex fromIndex); static bool raftLogExist(struct SSyncLogStore* pLogStore, SyncIndex index); static int32_t raftLogUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index); @@ -117,41 +110,38 @@ static int32_t raftLogRestoreFromSnapshot(struct SSyncLogStore* pLogStore, SyncI int32_t sysErr = errno; const char* sysErrStr = strerror(errno); - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), - "wal restore from snapshot error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", - snapshotIndex, err, err, errStr, sysErr, sysErrStr); - syncNodeErrorLog(pData->pSyncNode, logBuf); - + sNError(pData->pSyncNode, + "wal restore from snapshot error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + snapshotIndex, err, err, errStr, sysErr, sysErrStr); return -1; } return 0; } -static SyncIndex raftLogBeginIndex(struct SSyncLogStore* pLogStore) { +SyncIndex raftLogBeginIndex(struct SSyncLogStore* pLogStore) { SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; SyncIndex firstVer = walGetFirstVer(pWal); return firstVer; } -static SyncIndex raftLogEndIndex(struct SSyncLogStore* pLogStore) { return raftLogLastIndex(pLogStore); } +SyncIndex raftLogEndIndex(struct SSyncLogStore* pLogStore) { return raftLogLastIndex(pLogStore); } -static bool raftLogIsEmpty(struct SSyncLogStore* pLogStore) { +bool raftLogIsEmpty(struct SSyncLogStore* pLogStore) { SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; return walIsEmpty(pWal); } -static int32_t raftLogEntryCount(struct SSyncLogStore* pLogStore) { +int32_t raftLogEntryCount(struct SSyncLogStore* pLogStore) { SyncIndex beginIndex = raftLogBeginIndex(pLogStore); SyncIndex endIndex = raftLogEndIndex(pLogStore); int32_t count = endIndex - beginIndex + 1; return count > 0 ? count : 0; } -static SyncIndex raftLogLastIndex(struct SSyncLogStore* pLogStore) { +SyncIndex raftLogLastIndex(struct SSyncLogStore* pLogStore) { SyncIndex lastIndex; SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; @@ -160,7 +150,7 @@ static SyncIndex raftLogLastIndex(struct SSyncLogStore* pLogStore) { return lastVer; } -static SyncIndex raftLogWriteIndex(struct SSyncLogStore* pLogStore) { +SyncIndex raftLogWriteIndex(struct SSyncLogStore* pLogStore) { SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; SyncIndex lastVer = walGetLastVer(pWal); @@ -177,7 +167,7 @@ static bool raftLogExist(struct SSyncLogStore* pLogStore, SyncIndex index) { // if success, return last term // if not log, return 0 // if error, return SYNC_TERM_INVALID -static SyncTerm raftLogLastTerm(struct SSyncLogStore* pLogStore) { +SyncTerm raftLogLastTerm(struct SSyncLogStore* pLogStore) { SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; if (walIsEmpty(pWal)) { @@ -214,30 +204,21 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr int32_t sysErr = errno; const char* sysErrStr = strerror(errno); - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "wal write error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", - pEntry->index, err, err, errStr, sysErr, sysErrStr); - syncNodeErrorLog(pData->pSyncNode, logBuf); - - ASSERT(0); + sNError(pData->pSyncNode, "wal write error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", + pEntry->index, err, err, errStr, sysErr, sysErrStr); return -1; } pEntry->index = index; - do { - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "write index:%" PRId64 ", type:%s, origin type:%s", pEntry->index, - TMSG_INFO(pEntry->msgType), TMSG_INFO(pEntry->originalRpcType)); - syncNodeEventLog(pData->pSyncNode, eventLog); - } while (0); - + sNTrace(pData->pSyncNode, "write index:%" PRId64 ", type:%s, origin type:%s", pEntry->index, + TMSG_INFO(pEntry->msgType), TMSG_INFO(pEntry->originalRpcType)); return 0; } // entry found, return 0 // entry not found, return -1, terrno = TSDB_CODE_WAL_LOG_NOT_EXIST // other error, return -1 -static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry** ppEntry) { +int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry** ppEntry) { SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; int32_t code = 0; @@ -248,6 +229,8 @@ static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SWalReader* pWalHandle = pData->pWalHandle; if (pWalHandle == NULL) { terrno = TSDB_CODE_SYN_INTERNAL_ERROR; + sError("vgId:%d, wal handle is NULL", pData->pSyncNode->vgId); + return -1; } @@ -261,20 +244,13 @@ static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, int32_t sysErr = errno; const char* sysErrStr = strerror(errno); - do { - char logBuf[128]; - if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) { - snprintf(logBuf, sizeof(logBuf), - "wal read not exist, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", index, err, err, - errStr, sysErr, sysErrStr); - syncNodeEventLog(pData->pSyncNode, logBuf); - - } else { - snprintf(logBuf, sizeof(logBuf), "wal read error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", - index, err, err, errStr, sysErr, sysErrStr); - syncNodeErrorLog(pData->pSyncNode, logBuf); - } - } while (0); + if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) { + sNTrace(pData->pSyncNode, "wal read not exist, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", index, + err, err, errStr, sysErr, sysErrStr); + } else { + sNTrace(pData->pSyncNode, "wal read error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", index, + err, err, errStr, sysErr, sysErrStr); + } /* int32_t saveErr = terrno; @@ -318,6 +294,12 @@ static int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex fromIn return 0; } + // need not truncate + SyncIndex walCommitVer = walGetCommittedVer(pWal); + if (fromIndex <= walCommitVer) { + return 0; + } + int32_t code = walRollback(pWal, fromIndex); if (code != 0) { int32_t err = terrno; @@ -327,16 +309,11 @@ static int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex fromIn sError("vgId:%d, wal truncate error, from-index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", pData->pSyncNode->vgId, fromIndex, err, err, errStr, sysErr, sysErrStr); - ASSERT(0); + // ASSERT(0); } // event log - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "log truncate, from-index:%" PRId64, fromIndex); - syncNodeEventLog(pData->pSyncNode, logBuf); - } while (0); - + sNTrace(pData->pSyncNode, "log truncate, from-index:%" PRId64, fromIndex); return code; } @@ -376,6 +353,7 @@ int32_t raftLogUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index) { pData->pSyncNode->vgId, index, err, err, errStr, sysErr, sysErrStr); ASSERT(0); + return -1; } return 0; } @@ -385,111 +363,6 @@ SyncIndex raftlogCommitIndex(SSyncLogStore* pLogStore) { return pData->pSyncNode->commitIndex; } -cJSON* logStore2Json(SSyncLogStore* pLogStore) { - char u64buf[128] = {0}; - SSyncLogStoreData* pData = (SSyncLogStoreData*)pLogStore->data; - cJSON* pRoot = cJSON_CreateObject(); - - if (pData != NULL && pData->pWal != NULL) { - snprintf(u64buf, sizeof(u64buf), "%p", pData->pSyncNode); - cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pData->pWal); - cJSON_AddStringToObject(pRoot, "pWal", u64buf); - - SyncIndex beginIndex = raftLogBeginIndex(pLogStore); - snprintf(u64buf, sizeof(u64buf), "%" PRId64, beginIndex); - cJSON_AddStringToObject(pRoot, "beginIndex", u64buf); - - SyncIndex endIndex = raftLogEndIndex(pLogStore); - snprintf(u64buf, sizeof(u64buf), "%" PRId64, endIndex); - cJSON_AddStringToObject(pRoot, "endIndex", u64buf); - - int32_t count = raftLogEntryCount(pLogStore); - cJSON_AddNumberToObject(pRoot, "entryCount", count); - - snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogWriteIndex(pLogStore)); - cJSON_AddStringToObject(pRoot, "WriteIndex", u64buf); - - snprintf(u64buf, sizeof(u64buf), "%d", raftLogIsEmpty(pLogStore)); - cJSON_AddStringToObject(pRoot, "IsEmpty", u64buf); - - snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogLastIndex(pLogStore)); - cJSON_AddStringToObject(pRoot, "LastIndex", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, raftLogLastTerm(pLogStore)); - cJSON_AddStringToObject(pRoot, "LastTerm", u64buf); - - cJSON* pEntries = cJSON_CreateArray(); - cJSON_AddItemToObject(pRoot, "pEntries", pEntries); - - if (!raftLogIsEmpty(pLogStore)) { - for (SyncIndex i = beginIndex; i <= endIndex; ++i) { - SSyncRaftEntry* pEntry = NULL; - raftLogGetEntry(pLogStore, i, &pEntry); - - cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry)); - syncEntryDestory(pEntry); - } - } - } - - cJSON* pJson = cJSON_CreateObject(); - cJSON_AddItemToObject(pJson, "SSyncLogStore", pRoot); - return pJson; -} - -char* logStore2Str(SSyncLogStore* pLogStore) { - cJSON* pJson = logStore2Json(pLogStore); - char* serialized = cJSON_Print(pJson); - cJSON_Delete(pJson); - return serialized; -} - -cJSON* logStoreSimple2Json(SSyncLogStore* pLogStore) { - char u64buf[128] = {0}; - SSyncLogStoreData* pData = (SSyncLogStoreData*)pLogStore->data; - cJSON* pRoot = cJSON_CreateObject(); - - if (pData != NULL && pData->pWal != NULL) { - snprintf(u64buf, sizeof(u64buf), "%p", pData->pSyncNode); - cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); - snprintf(u64buf, sizeof(u64buf), "%p", pData->pWal); - cJSON_AddStringToObject(pRoot, "pWal", u64buf); - - SyncIndex beginIndex = raftLogBeginIndex(pLogStore); - snprintf(u64buf, sizeof(u64buf), "%" PRId64, beginIndex); - cJSON_AddStringToObject(pRoot, "beginIndex", u64buf); - - SyncIndex endIndex = raftLogEndIndex(pLogStore); - snprintf(u64buf, sizeof(u64buf), "%" PRId64, endIndex); - cJSON_AddStringToObject(pRoot, "endIndex", u64buf); - - int32_t count = raftLogEntryCount(pLogStore); - cJSON_AddNumberToObject(pRoot, "entryCount", count); - - snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogWriteIndex(pLogStore)); - cJSON_AddStringToObject(pRoot, "WriteIndex", u64buf); - - snprintf(u64buf, sizeof(u64buf), "%d", raftLogIsEmpty(pLogStore)); - cJSON_AddStringToObject(pRoot, "IsEmpty", u64buf); - - snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogLastIndex(pLogStore)); - cJSON_AddStringToObject(pRoot, "LastIndex", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, raftLogLastTerm(pLogStore)); - cJSON_AddStringToObject(pRoot, "LastTerm", u64buf); - } - - cJSON* pJson = cJSON_CreateObject(); - cJSON_AddItemToObject(pJson, "SSyncLogStoreSimple", pRoot); - return pJson; -} - -char* logStoreSimple2Str(SSyncLogStore* pLogStore) { - cJSON* pJson = logStoreSimple2Json(pLogStore); - char* serialized = cJSON_Print(pJson); - cJSON_Delete(pJson); - return serialized; -} - SyncIndex logStoreFirstIndex(SSyncLogStore* pLogStore) { SSyncLogStoreData* pData = pLogStore->data; SWal* pWal = pData->pWal; @@ -501,63 +374,3 @@ SyncIndex logStoreWalCommitVer(SSyncLogStore* pLogStore) { SWal* pWal = pData->pWal; return walGetCommittedVer(pWal); } - -// for debug ----------------- -void logStorePrint(SSyncLogStore* pLogStore) { - char* serialized = logStore2Str(pLogStore); - printf("logStorePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void logStorePrint2(char* s, SSyncLogStore* pLogStore) { - char* serialized = logStore2Str(pLogStore); - printf("logStorePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void logStoreLog(SSyncLogStore* pLogStore) { - if (gRaftDetailLog) { - char* serialized = logStore2Str(pLogStore); - sTraceLong("logStoreLog | len:%d | %s", (int32_t)strlen(serialized), serialized); - taosMemoryFree(serialized); - } -} - -void logStoreLog2(char* s, SSyncLogStore* pLogStore) { - if (gRaftDetailLog) { - char* serialized = logStore2Str(pLogStore); - sTraceLong("logStoreLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); - taosMemoryFree(serialized); - } -} - -// for debug ----------------- -void logStoreSimplePrint(SSyncLogStore* pLogStore) { - char* serialized = logStoreSimple2Str(pLogStore); - printf("logStoreSimplePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void logStoreSimplePrint2(char* s, SSyncLogStore* pLogStore) { - char* serialized = logStoreSimple2Str(pLogStore); - printf("logStoreSimplePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void logStoreSimpleLog(SSyncLogStore* pLogStore) { - char* serialized = logStoreSimple2Str(pLogStore); - sTrace("logStoreSimpleLog | len:%d | %s", (int32_t)strlen(serialized), serialized); - taosMemoryFree(serialized); -} - -void logStoreSimpleLog2(char* s, SSyncLogStore* pLogStore) { - if (gRaftDetailLog) { - char* serialized = logStoreSimple2Str(pLogStore); - sTrace("logStoreSimpleLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); - taosMemoryFree(serialized); - } -} diff --git a/source/libs/sync/src/syncReplication.c b/source/libs/sync/src/syncReplication.c index 7296e30e0253193d9a1d5a261546650dbae13c79..3f22a1f2cd046545e66a4d6f67e694fbf739a215 100644 --- a/source/libs/sync/src/syncReplication.c +++ b/source/libs/sync/src/syncReplication.c @@ -56,14 +56,10 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId) { SyncIndex logStartIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore); SyncIndex logEndIndex = pSyncNode->pLogStore->syncLogEndIndex(pSyncNode->pLogStore); if (nextIndex < logStartIndex || nextIndex - 1 > logEndIndex) { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "start snapshot for next-index:%" PRId64 ", start:%" PRId64 ", end:%" PRId64, - nextIndex, logStartIndex, logEndIndex); - syncNodeEventLog(pSyncNode, logBuf); - + sNTrace(pSyncNode, "maybe start snapshot for next-index:%" PRId64 ", start:%" PRId64 ", end:%" PRId64, nextIndex, + logStartIndex, logEndIndex); // start snapshot - int32_t code = syncNodeStartSnapshot(pSyncNode, pDestId); - ASSERT(code == 0); + // int32_t code = syncNodeStartSnapshot(pSyncNode, pDestId); return 0; } @@ -82,14 +78,7 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId) { pMsg = syncAppendEntriesBuild(pEntry->bytes, pSyncNode->vgId); ASSERT(pMsg != NULL); - - // add pEntry into msg - uint32_t len; - char* serialized = syncEntrySerialize(pEntry, &len); - ASSERT(len == pEntry->bytes); - memcpy(pMsg->data, serialized, len); - - taosMemoryFree(serialized); + memcpy(pMsg->data, pEntry, pEntry->bytes); syncEntryDestory(pEntry); } else { @@ -103,10 +92,7 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId) { char host[64]; uint16_t port; syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port); - - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "replicate to %s:%d error, next-index:%" PRId64, host, port, nextIndex); - syncNodeErrorLog(pSyncNode, logBuf); + sNError(pSyncNode, "replicate to %s:%d error, next-index:%" PRId64, host, port, nextIndex); } while (0); syncAppendEntriesDestroy(pMsg); @@ -137,7 +123,7 @@ int32_t syncNodeReplicate(SSyncNode* pSyncNode) { return -1; } - syncNodeEventLog(pSyncNode, "do replicate"); + sNTrace(pSyncNode, "do replicate"); int32_t ret = 0; for (int i = 0; i < pSyncNode->peersNum; ++i) { @@ -186,9 +172,7 @@ int32_t syncNodeMaybeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* dest char host[64]; int16_t port; syncUtilU642Addr(destRaftId->addr, host, sizeof(host), &port); - - snprintf(logBuf, sizeof(logBuf), "do not repcate to %s:%d for index:%" PRId64, host, port, pMsg->prevLogIndex + 1); - syncNodeEventLog(pSyncNode, logBuf); + sNTrace(pSyncNode, "do not repcate to %s:%d for index:%" PRId64, host, port, pMsg->prevLogIndex + 1); } return ret; diff --git a/source/libs/sync/src/syncRequestVote.c b/source/libs/sync/src/syncRequestVote.c index 074e4fca647e223d85905b46dbf65a26c2914455..7e2587372b9a84e9dd130a12c3bb6817fc84f54b 100644 --- a/source/libs/sync/src/syncRequestVote.c +++ b/source/libs/sync/src/syncRequestVote.c @@ -47,54 +47,43 @@ static bool syncNodeOnRequestVoteLogOK(SSyncNode* pSyncNode, SyncRequestVote* pM SyncTerm myLastTerm = syncNodeGetLastTerm(pSyncNode); SyncIndex myLastIndex = syncNodeGetLastIndex(pSyncNode); - if (myLastTerm == SYNC_TERM_INVALID) { - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), - "logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64 - ", recv-term:%" PRIu64 "}", - myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term); - syncNodeEventLog(pSyncNode, logBuf); - } while (0); + if (pMsg->lastLogIndex < pSyncNode->commitIndex) { + sNTrace(pSyncNode, + "logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64 + ", recv-term:%" PRIu64 "}", + myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term); return false; } - if (pMsg->lastLogTerm > myLastTerm) { - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), - "logok:1, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64 - ", recv-term:%" PRIu64 "}", - myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term); - syncNodeEventLog(pSyncNode, logBuf); - } while (0); + if (myLastTerm == SYNC_TERM_INVALID) { + sNTrace(pSyncNode, + "logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64 + ", recv-term:%" PRIu64 "}", + myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term); + return false; + } + if (pMsg->lastLogTerm > myLastTerm) { + sNTrace(pSyncNode, + "logok:1, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64 + ", recv-term:%" PRIu64 "}", + myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term); return true; } if (pMsg->lastLogTerm == myLastTerm && pMsg->lastLogIndex >= myLastIndex) { - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), - "logok:1, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64 - ", recv-term:%" PRIu64 "}", - myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term); - syncNodeEventLog(pSyncNode, logBuf); - } while (0); - + sNTrace(pSyncNode, + "logok:1, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64 + ", recv-term:%" PRIu64 "}", + myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term); return true; } - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), - "logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64 - ", recv-term:%" PRIu64 "}", - myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term); - syncNodeEventLog(pSyncNode, logBuf); - } while (0); - + sNTrace(pSyncNode, + "logok:0, {my-lterm:%" PRIu64 ", my-lindex:%" PRId64 ", recv-lterm:%" PRIu64 ", recv-lindex:%" PRId64 + ", recv-term:%" PRIu64 "}", + myLastTerm, myLastIndex, pMsg->lastLogTerm, pMsg->lastLogIndex, pMsg->term); return false; } diff --git a/source/libs/sync/src/syncRequestVoteReply.c b/source/libs/sync/src/syncRequestVoteReply.c index a9c325625813ff9285673579945d6ac16780b6da..44efaa068a19814d4fe73685724051c0b21faa41 100644 --- a/source/libs/sync/src/syncRequestVoteReply.c +++ b/source/libs/sync/src/syncRequestVoteReply.c @@ -71,10 +71,8 @@ int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, SyncRequestVoteReply* pMsg) { // but they won't be looked at, so it doesn't matter. if (ths->state == TAOS_SYNC_STATE_CANDIDATE) { if (ths->pVotesRespond->term != pMsg->term) { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "vote respond error vote-respond-mgr term:%" PRIu64 ", msg term:%" PRIu64 "", - ths->pVotesRespond->term, pMsg->term); - syncNodeErrorLog(ths, logBuf); + sNError(ths, "vote respond error vote-respond-mgr term:%" PRIu64 ", msg term:%" PRIu64 "", + ths->pVotesRespond->term, pMsg->term); return -1; } diff --git a/source/libs/sync/src/syncRespMgr.c b/source/libs/sync/src/syncRespMgr.c index 88af5746d403e62db38fe49a0886854e53a82f4d..de8f1927ae4d4d1afe0ce7b744f35796d315157a 100644 --- a/source/libs/sync/src/syncRespMgr.c +++ b/source/libs/sync/src/syncRespMgr.c @@ -13,21 +13,22 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE #include "syncRespMgr.h" #include "syncRaftEntry.h" #include "syncRaftStore.h" SSyncRespMgr *syncRespMgrCreate(void *data, int64_t ttl) { - SSyncRespMgr *pObj = (SSyncRespMgr *)taosMemoryMalloc(sizeof(SSyncRespMgr)); + SSyncRespMgr *pObj = taosMemoryCalloc(1, sizeof(SSyncRespMgr)); if (pObj == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } - memset(pObj, 0, sizeof(SSyncRespMgr)); pObj->pRespHash = taosHashInit(sizeof(uint64_t), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); - ASSERT(pObj->pRespHash != NULL); + if (pObj->pRespHash == NULL) return NULL; + pObj->ttl = ttl; pObj->data = data; pObj->seqNum = 0; @@ -38,105 +39,84 @@ SSyncRespMgr *syncRespMgrCreate(void *data, int64_t ttl) { void syncRespMgrDestroy(SSyncRespMgr *pObj) { if (pObj != NULL) { - taosThreadMutexLock(&(pObj->mutex)); + taosThreadMutexLock(&pObj->mutex); taosHashCleanup(pObj->pRespHash); - taosThreadMutexUnlock(&(pObj->mutex)); + taosThreadMutexUnlock(&pObj->mutex); taosThreadMutexDestroy(&(pObj->mutex)); taosMemoryFree(pObj); } } -int64_t syncRespMgrAdd(SSyncRespMgr *pObj, SRespStub *pStub) { - taosThreadMutexLock(&(pObj->mutex)); - - uint64_t keyCode = ++(pObj->seqNum); - taosHashPut(pObj->pRespHash, &keyCode, sizeof(keyCode), pStub, sizeof(SRespStub)); +uint64_t syncRespMgrAdd(SSyncRespMgr *pObj, const SRespStub *pStub) { + taosThreadMutexLock(&pObj->mutex); - SSyncNode *pSyncNode = pObj->data; - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "save message handle, type:%s seq:%" PRIu64 " handle:%p", - TMSG_INFO(pStub->rpcMsg.msgType), keyCode, pStub->rpcMsg.info.handle); - syncNodeEventLog(pSyncNode, eventLog); + uint64_t seq = ++(pObj->seqNum); + int32_t code = taosHashPut(pObj->pRespHash, &seq, sizeof(uint64_t), pStub, sizeof(SRespStub)); + sNTrace(pObj->data, "save message handle:%p, type:%s seq:%" PRIu64 " code:0x%x", pStub->rpcMsg.info.handle, + TMSG_INFO(pStub->rpcMsg.msgType), seq, code); - taosThreadMutexUnlock(&(pObj->mutex)); - return keyCode; + taosThreadMutexUnlock(&pObj->mutex); + return seq; } -int32_t syncRespMgrDel(SSyncRespMgr *pObj, uint64_t index) { - taosThreadMutexLock(&(pObj->mutex)); +int32_t syncRespMgrDel(SSyncRespMgr *pObj, uint64_t seq) { + taosThreadMutexLock(&pObj->mutex); - taosHashRemove(pObj->pRespHash, &index, sizeof(index)); + int32_t code = taosHashRemove(pObj->pRespHash, &seq, sizeof(seq)); + sNTrace(pObj->data, "remove message handle, seq:%" PRIu64 " code:%d", seq, code); - taosThreadMutexUnlock(&(pObj->mutex)); - return 0; + taosThreadMutexUnlock(&pObj->mutex); + return code; } -int32_t syncRespMgrGet(SSyncRespMgr *pObj, uint64_t index, SRespStub *pStub) { - taosThreadMutexLock(&(pObj->mutex)); +int32_t syncRespMgrGet(SSyncRespMgr *pObj, uint64_t seq, SRespStub *pStub) { + taosThreadMutexLock(&pObj->mutex); - void *pTmp = taosHashGet(pObj->pRespHash, &index, sizeof(index)); + SRespStub *pTmp = taosHashGet(pObj->pRespHash, &seq, sizeof(uint64_t)); if (pTmp != NULL) { memcpy(pStub, pTmp, sizeof(SRespStub)); + sNTrace(pObj->data, "get message handle, type:%s seq:%" PRIu64 " handle:%p", TMSG_INFO(pStub->rpcMsg.msgType), seq, + pStub->rpcMsg.info.handle); - SSyncNode *pSyncNode = pObj->data; - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "get message handle, type:%s seq:%" PRIu64 " handle:%p", - TMSG_INFO(pStub->rpcMsg.msgType), index, pStub->rpcMsg.info.handle); - syncNodeEventLog(pSyncNode, eventLog); - - taosThreadMutexUnlock(&(pObj->mutex)); + taosThreadMutexUnlock(&pObj->mutex); return 1; // get one object } - taosThreadMutexUnlock(&(pObj->mutex)); + + taosThreadMutexUnlock(&pObj->mutex); return 0; // get none object } -int32_t syncRespMgrGetAndDel(SSyncRespMgr *pObj, uint64_t index, SRespStub *pStub) { - taosThreadMutexLock(&(pObj->mutex)); - - void *pTmp = taosHashGet(pObj->pRespHash, &index, sizeof(index)); - if (pTmp != NULL) { - memcpy(pStub, pTmp, sizeof(SRespStub)); +int32_t syncRespMgrGetAndDel(SSyncRespMgr *pObj, uint64_t seq, SRpcHandleInfo *pInfo) { + taosThreadMutexLock(&pObj->mutex); - SSyncNode *pSyncNode = pObj->data; - char eventLog[128]; - snprintf(eventLog, sizeof(eventLog), "get-and-del message handle, type:%s seq:%" PRIu64 " handle:%p", - TMSG_INFO(pStub->rpcMsg.msgType), index, pStub->rpcMsg.info.handle); - syncNodeEventLog(pSyncNode, eventLog); + SRespStub *pStub = taosHashGet(pObj->pRespHash, &seq, sizeof(uint64_t)); + if (pStub != NULL) { + *pInfo = pStub->rpcMsg.info; + sNTrace(pObj->data, "get-and-del message handle:%p, type:%s seq:%" PRIu64, pStub->rpcMsg.info.handle, + TMSG_INFO(pStub->rpcMsg.msgType), seq); + taosHashRemove(pObj->pRespHash, &seq, sizeof(uint64_t)); - taosHashRemove(pObj->pRespHash, &index, sizeof(index)); - taosThreadMutexUnlock(&(pObj->mutex)); + taosThreadMutexUnlock(&pObj->mutex); return 1; // get one object } - taosThreadMutexUnlock(&(pObj->mutex)); - return 0; // get none object -} - -void syncRespCleanRsp(SSyncRespMgr *pObj) { - taosThreadMutexLock(&(pObj->mutex)); - syncRespCleanByTTL(pObj, -1, true); - taosThreadMutexUnlock(&(pObj->mutex)); -} -void syncRespClean(SSyncRespMgr *pObj) { - taosThreadMutexLock(&(pObj->mutex)); - syncRespCleanByTTL(pObj, pObj->ttl, false); - taosThreadMutexUnlock(&(pObj->mutex)); + taosThreadMutexUnlock(&pObj->mutex); + return 0; // get none object } -void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp) { +static void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp) { SRespStub *pStub = (SRespStub *)taosHashIterate(pObj->pRespHash, NULL); int cnt = 0; int sum = 0; SSyncNode *pSyncNode = pObj->data; - SArray *delIndexArray = taosArrayInit(0, sizeof(uint64_t)); - ASSERT(delIndexArray != NULL); - sDebug("vgId:%d, resp mgr begin clean by ttl", pSyncNode->vgId); + SArray *delIndexArray = taosArrayInit(4, sizeof(uint64_t)); + if (delIndexArray == NULL) return; + sDebug("vgId:%d, resp mgr begin clean by ttl", pSyncNode->vgId); while (pStub) { size_t len; - void * key = taosHashGetKey(pStub, &len); + void *key = taosHashGetKey(pStub, &len); uint64_t *pSeqNum = (uint64_t *)key; sum++; @@ -145,30 +125,31 @@ void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp) { taosArrayPush(delIndexArray, pSeqNum); cnt++; - SFsmCbMeta cbMeta = {0}; - cbMeta.index = SYNC_INDEX_INVALID; - cbMeta.lastConfigIndex = SYNC_INDEX_INVALID; - cbMeta.isWeak = false; - cbMeta.code = TSDB_CODE_SYN_TIMEOUT; - cbMeta.state = pSyncNode->state; - cbMeta.seqNum = *pSeqNum; - cbMeta.term = SYNC_TERM_INVALID; - cbMeta.currentTerm = pSyncNode->pRaftStore->currentTerm; - cbMeta.flag = 0; + SFsmCbMeta cbMeta = { + .index = SYNC_INDEX_INVALID, + .lastConfigIndex = SYNC_INDEX_INVALID, + .isWeak = false, + .code = TSDB_CODE_SYN_TIMEOUT, + .state = pSyncNode->state, + .seqNum = *pSeqNum, + .term = SYNC_TERM_INVALID, + .currentTerm = pSyncNode->pRaftStore->currentTerm, + .flag = 0, + }; pStub->rpcMsg.pCont = NULL; pStub->rpcMsg.contLen = 0; // TODO: and make rpcMsg body, call commit cb - // pSyncNode->pFsm->FpCommitCb(pSyncNode->pFsm, &(pStub->rpcMsg), cbMeta); + // pSyncNode->pFsm->FpCommitCb(pSyncNode->pFsm, &pStub->rpcMsg, cbMeta); pStub->rpcMsg.code = TSDB_CODE_SYN_NOT_LEADER; if (pStub->rpcMsg.info.handle != NULL) { - tmsgSendRsp(&(pStub->rpcMsg)); + tmsgSendRsp(&pStub->rpcMsg); } } - pStub = (SRespStub *)taosHashIterate(pObj->pRespHash, pStub); + pStub = taosHashIterate(pObj->pRespHash, pStub); } int32_t arraySize = taosArrayGetSize(delIndexArray); @@ -181,3 +162,15 @@ void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp) { } taosArrayDestroy(delIndexArray); } + +void syncRespCleanRsp(SSyncRespMgr *pObj) { + taosThreadMutexLock(&pObj->mutex); + syncRespCleanByTTL(pObj, -1, true); + taosThreadMutexUnlock(&pObj->mutex); +} + +void syncRespClean(SSyncRespMgr *pObj) { + taosThreadMutexLock(&pObj->mutex); + syncRespCleanByTTL(pObj, pObj->ttl, false); + taosThreadMutexUnlock(&pObj->mutex); +} diff --git a/source/libs/sync/src/syncSnapshot.c b/source/libs/sync/src/syncSnapshot.c index a7bafa9f28f2b6bdeeb568477cc524648d67cd05..78413bbeffb5a4fa46f7843b84b7cff099a9a6c2 100644 --- a/source/libs/sync/src/syncSnapshot.c +++ b/source/libs/sync/src/syncSnapshot.c @@ -41,8 +41,6 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI } memset(pSender, 0, sizeof(*pSender)); - int64_t timeNow = taosGetTimestampMs(); - pSender->start = false; pSender->seq = SYNC_SNAPSHOT_SEQ_INVALID; pSender->ack = SYNC_SNAPSHOT_SEQ_INVALID; @@ -53,8 +51,7 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI pSender->pSyncNode = pSyncNode; pSender->replicaIndex = replicaIndex; pSender->term = pSyncNode->pRaftStore->currentTerm; - pSender->privateTerm = timeNow + 100; - pSender->startTime = timeNow; + pSender->startTime = 0; pSender->pSyncNode->pFsm->FpGetSnapshotInfo(pSender->pSyncNode->pFsm, &(pSender->snapshot)); pSender->finish = false; } else { @@ -76,7 +73,7 @@ void snapshotSenderDestroy(SSyncSnapshotSender *pSender) { if (pSender->pReader != NULL) { int32_t ret = pSender->pSyncNode->pFsm->FpSnapshotStopRead(pSender->pSyncNode->pFsm, pSender->pReader); if (ret != 0) { - syncNodeErrorLog(pSender->pSyncNode, "stop reader error"); + sNError(pSender->pSyncNode, "stop reader error"); } pSender->pReader = NULL; } @@ -88,88 +85,30 @@ void snapshotSenderDestroy(SSyncSnapshotSender *pSender) { bool snapshotSenderIsStart(SSyncSnapshotSender *pSender) { return pSender->start; } -// begin send snapshot by param, snapshot, pReader -// -// action: -// 1. assert reader not start -// 2. update state -// 3. send first snapshot block -int32_t snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshotParam snapshotParam, SSnapshot snapshot, - void *pReader) { +int32_t snapshotSenderStart(SSyncSnapshotSender *pSender) { ASSERT(!snapshotSenderIsStart(pSender)); - // init snapshot, parm, reader - ASSERT(pSender->pReader == NULL); - pSender->pReader = pReader; - pSender->snapshot = snapshot; - pSender->snapshotParam = snapshotParam; - - // init current block - if (pSender->pCurrentBlock != NULL) { - taosMemoryFree(pSender->pCurrentBlock); - } - pSender->blockLen = 0; - - // update term - pSender->term = pSender->pSyncNode->pRaftStore->currentTerm; - ++(pSender->privateTerm); // increase private term - - // update state - pSender->finish = false; pSender->start = true; pSender->seq = SYNC_SNAPSHOT_SEQ_BEGIN; pSender->ack = SYNC_SNAPSHOT_SEQ_INVALID; + pSender->pReader = NULL; + pSender->pCurrentBlock = NULL; + pSender->blockLen = 0; - // init last config - if (pSender->snapshot.lastConfigIndex != SYNC_INDEX_INVALID) { - int32_t code = 0; - SSyncRaftEntry *pEntry = NULL; - bool getLastConfig = false; - - code = pSender->pSyncNode->pLogStore->syncLogGetEntry(pSender->pSyncNode->pLogStore, - pSender->snapshot.lastConfigIndex, &pEntry); - if (code == 0 && pEntry != NULL) { - SRpcMsg rpcMsg; - syncEntry2OriginalRpc(pEntry, &rpcMsg); - - SSyncCfg lastConfig; - int32_t ret = syncCfgFromStr(rpcMsg.pCont, &lastConfig); - ASSERT(ret == 0); - pSender->lastConfig = lastConfig; - getLastConfig = true; - - rpcFreeCont(rpcMsg.pCont); - syncEntryDestory(pEntry); - } else { - if (pSender->snapshot.lastConfigIndex == pSender->pSyncNode->pRaftCfg->lastConfigIndex) { - sTrace("vgId:%d, sync sender get cfg from local", pSender->pSyncNode->vgId); - pSender->lastConfig = pSender->pSyncNode->pRaftCfg->cfg; - getLastConfig = true; - } - } + pSender->snapshotParam.start = SYNC_INDEX_INVALID; + pSender->snapshotParam.end = SYNC_INDEX_INVALID; - // last config not found in wal, update to -1 - if (!getLastConfig) { - SyncIndex oldLastConfigIndex = pSender->snapshot.lastConfigIndex; - SyncIndex newLastConfigIndex = SYNC_INDEX_INVALID; - pSender->snapshot.lastConfigIndex = SYNC_INDEX_INVALID; - memset(&(pSender->lastConfig), 0, sizeof(SSyncCfg)); - - // event log - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "snapshot sender update lcindex from %" PRId64 " to %" PRId64, - oldLastConfigIndex, newLastConfigIndex); - char *eventLog = snapshotSender2SimpleStr(pSender, logBuf); - syncNodeEventLog(pSender->pSyncNode, eventLog); - taosMemoryFree(eventLog); - } while (0); - } + pSender->snapshot.data = NULL; + pSender->snapshotParam.end = SYNC_INDEX_INVALID; + pSender->snapshot.lastApplyIndex = SYNC_INDEX_INVALID; + pSender->snapshot.lastApplyTerm = SYNC_TERM_INVALID; + pSender->snapshot.lastConfigIndex = SYNC_INDEX_INVALID; - } else { - // no last config - memset(&(pSender->lastConfig), 0, sizeof(SSyncCfg)); - } + memset(&(pSender->lastConfig), 0, sizeof(pSender->lastConfig)); + pSender->sendingMS = 0; + pSender->term = pSender->pSyncNode->pRaftStore->currentTerm; + pSender->startTime = taosGetTimestampMs(); + pSender->finish = false; // build begin msg SyncSnapshotSend *pMsg = syncSnapshotSendBuild(0, pSender->pSyncNode->vgId); @@ -181,8 +120,8 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshotParam snapsho pMsg->lastTerm = pSender->snapshot.lastApplyTerm; pMsg->lastConfigIndex = pSender->snapshot.lastConfigIndex; pMsg->lastConfig = pSender->lastConfig; - pMsg->seq = pSender->seq; // SYNC_SNAPSHOT_SEQ_BEGIN - pMsg->privateTerm = pSender->privateTerm; + pMsg->startTime = pSender->startTime; + pMsg->seq = SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT; // send msg SRpcMsg rpcMsg; @@ -191,16 +130,15 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender, SSnapshotParam snapsho syncSnapshotSendDestroy(pMsg); // event log - do { - char *eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender start"); - syncNodeEventLog(pSender->pSyncNode, eventLog); - taosMemoryFree(eventLog); - } while (0); - + sSTrace(pSender, "snapshot sender start"); return 0; } int32_t snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish) { + // update flag + pSender->start = false; + pSender->finish = finish; + // close reader if (pSender->pReader != NULL) { int32_t ret = pSender->pSyncNode->pFsm->FpSnapshotStopRead(pSender->pSyncNode->pFsm, pSender->pReader); @@ -215,19 +153,8 @@ int32_t snapshotSenderStop(SSyncSnapshotSender *pSender, bool finish) { pSender->blockLen = 0; } - // update flag - pSender->start = false; - pSender->finish = finish; - - // do not update term, maybe print - // event log - do { - char *eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender stop"); - syncNodeEventLog(pSender->pSyncNode, eventLog); - taosMemoryFree(eventLog); - } while (0); - + sSTrace(pSender, "snapshot sender stop"); return 0; } @@ -263,7 +190,9 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) { pMsg->lastConfigIndex = pSender->snapshot.lastConfigIndex; pMsg->lastConfig = pSender->lastConfig; pMsg->seq = pSender->seq; - pMsg->privateTerm = pSender->privateTerm; + + // pMsg->privateTerm = pSender->privateTerm; + memcpy(pMsg->data, pSender->pCurrentBlock, pSender->blockLen); // send msg @@ -273,17 +202,11 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) { syncSnapshotSendDestroy(pMsg); // event log - do { - char *eventLog = NULL; - if (pSender->seq == SYNC_SNAPSHOT_SEQ_END) { - eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender finish"); - } else { - eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender sending"); - } - syncNodeEventLog(pSender->pSyncNode, eventLog); - taosMemoryFree(eventLog); - } while (0); - + if (pSender->seq == SYNC_SNAPSHOT_SEQ_END) { + sSTrace(pSender, "snapshot sender finish"); + } else { + sSTrace(pSender, "snapshot sender sending"); + } return 0; } @@ -302,7 +225,9 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) { pMsg->lastConfigIndex = pSender->snapshot.lastConfigIndex; pMsg->lastConfig = pSender->lastConfig; pMsg->seq = pSender->seq; - pMsg->privateTerm = pSender->privateTerm; + + // pMsg->privateTerm = pSender->privateTerm; + memcpy(pMsg->data, pSender->pCurrentBlock, pSender->blockLen); // send msg @@ -312,11 +237,7 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) { syncSnapshotSendDestroy(pMsg); // event log - do { - char *eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender resend"); - syncNodeEventLog(pSender->pSyncNode, eventLog); - taosMemoryFree(eventLog); - } while (0); + sSTrace(pSender, "snapshot sender resend"); } return 0; @@ -346,10 +267,10 @@ cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender) { if (pSender->pCurrentBlock != NULL) { char *s; - s = syncUtilprintBin((char *)(pSender->pCurrentBlock), pSender->blockLen); + s = syncUtilPrintBin((char *)(pSender->pCurrentBlock), pSender->blockLen); cJSON_AddStringToObject(pRoot, "pCurrentBlock", s); taosMemoryFree(s); - s = syncUtilprintBin2((char *)(pSender->pCurrentBlock), pSender->blockLen); + s = syncUtilPrintBin2((char *)(pSender->pCurrentBlock), pSender->blockLen); cJSON_AddStringToObject(pRoot, "pCurrentBlock2", s); taosMemoryFree(s); } @@ -367,8 +288,10 @@ cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender) { cJSON_AddNumberToObject(pRoot, "replicaIndex", pSender->replicaIndex); snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSender->term); cJSON_AddStringToObject(pRoot, "term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSender->privateTerm); - cJSON_AddStringToObject(pRoot, "privateTerm", u64buf); + + // snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSender->privateTerm); + // cJSON_AddStringToObject(pRoot, "privateTerm", u64buf); + cJSON_AddNumberToObject(pRoot, "finish", pSender->finish); } @@ -384,41 +307,30 @@ char *snapshotSender2Str(SSyncSnapshotSender *pSender) { return serialized; } -char *snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event) { - int32_t len = 256; - char *s = taosMemoryMalloc(len); - - SRaftId destId = pSender->pSyncNode->replicasId[pSender->replicaIndex]; - char host[64]; - uint16_t port; - syncUtilU642Addr(destId.addr, host, sizeof(host), &port); - - snprintf(s, len, - "%s {%p s-param:%" PRId64 " e-param:%" PRId64 " laindex:%" PRId64 " laterm:%" PRIu64 " lcindex:%" PRId64 - " seq:%d ack:%d finish:%d pterm:%" PRIu64 - " " - "replica-index:%d %s:%d}", - event, pSender, pSender->snapshotParam.start, pSender->snapshotParam.end, pSender->snapshot.lastApplyIndex, - pSender->snapshot.lastApplyTerm, pSender->snapshot.lastConfigIndex, pSender->seq, pSender->ack, - pSender->finish, pSender->privateTerm, pSender->replicaIndex, host, port); - - return s; -} - int32_t syncNodeStartSnapshot(SSyncNode *pSyncNode, SRaftId *pDestId) { - // calculate index - - syncNodeEventLog(pSyncNode, "start snapshot ..."); + sNTrace(pSyncNode, "starting snapshot ..."); SSyncSnapshotSender *pSender = syncNodeGetSnapshotSender(pSyncNode, pDestId); if (pSender == NULL) { - // create sender - } else { - // if is same - // return 0; + sNError(pSyncNode, "start snapshot error, sender is null"); + return -1; } - // send begin msg + int32_t code = 0; + + if (snapshotSenderIsStart(pSender)) { + code = snapshotSenderStop(pSender, false); + if (code != 0) { + sNError(pSyncNode, "snapshot sender stop error"); + return -1; + } + } + + code = snapshotSenderStart(pSender); + if (code != 0) { + sNError(pSyncNode, "snapshot sender start error"); + return -1; + } return 0; } @@ -440,7 +352,6 @@ SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId from pReceiver->pSyncNode = pSyncNode; pReceiver->fromId = fromId; pReceiver->term = pSyncNode->pRaftStore->currentTerm; - pReceiver->privateTerm = 0; pReceiver->snapshot.data = NULL; pReceiver->snapshot.lastApplyIndex = SYNC_INDEX_INVALID; pReceiver->snapshot.lastApplyTerm = 0; @@ -474,32 +385,30 @@ bool snapshotReceiverIsStart(SSyncSnapshotReceiver *pReceiver) { return pReceive // receive first snapshot data // write first block data static void snapshotReceiverDoStart(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pBeginMsg) { - // update state - pReceiver->term = pReceiver->pSyncNode->pRaftStore->currentTerm; - pReceiver->privateTerm = pBeginMsg->privateTerm; + pReceiver->start = true; pReceiver->ack = SYNC_SNAPSHOT_SEQ_BEGIN; + + // start writer + ASSERT(pReceiver->pWriter == NULL); + int32_t ret = pReceiver->pSyncNode->pFsm->FpSnapshotStartWrite(pReceiver->pSyncNode->pFsm, + &(pReceiver->snapshotParam), &(pReceiver->pWriter)); + ASSERT(ret == 0); + + pReceiver->term = pReceiver->pSyncNode->pRaftStore->currentTerm; + pReceiver->snapshotParam.start = pBeginMsg->beginIndex; + pReceiver->snapshotParam.end = pBeginMsg->lastIndex; + pReceiver->fromId = pBeginMsg->srcId; - pReceiver->start = true; // update snapshot pReceiver->snapshot.lastApplyIndex = pBeginMsg->lastIndex; pReceiver->snapshot.lastApplyTerm = pBeginMsg->lastTerm; pReceiver->snapshot.lastConfigIndex = pBeginMsg->lastConfigIndex; - pReceiver->snapshotParam.start = pBeginMsg->beginIndex; - pReceiver->snapshotParam.end = pBeginMsg->lastIndex; - // start writer - ASSERT(pReceiver->pWriter == NULL); - int32_t ret = pReceiver->pSyncNode->pFsm->FpSnapshotStartWrite(pReceiver->pSyncNode->pFsm, - &(pReceiver->snapshotParam), &(pReceiver->pWriter)); - ASSERT(ret == 0); + pReceiver->startTime = pBeginMsg->startTime; // event log - do { - char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver start"); - syncNodeEventLog(pReceiver->pSyncNode, eventLog); - taosMemoryFree(eventLog); - } while (0); + sRTrace(pReceiver, "snapshot receiver start"); } // force stop @@ -515,30 +424,13 @@ void snapshotReceiverForceStop(SSyncSnapshotReceiver *pReceiver) { pReceiver->start = false; // event log - do { - char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver force stop"); - syncNodeEventLog(pReceiver->pSyncNode, eventLog); - taosMemoryFree(eventLog); - } while (0); + sRTrace(pReceiver, "snapshot receiver force stop"); } // if receiver receive msg from seq = SYNC_SNAPSHOT_SEQ_BEGIN, start receiver -// if already start, force close, start again int32_t snapshotReceiverStart(SSyncSnapshotReceiver *pReceiver, SyncSnapshotSend *pBeginMsg) { - if (!snapshotReceiverIsStart(pReceiver)) { - // first start - snapshotReceiverDoStart(pReceiver, pBeginMsg); - - } else { - // already start - sInfo("vgId:%d, snapshot recv, receiver already start", pReceiver->pSyncNode->vgId); - - // force close, abandon incomplete data - snapshotReceiverForceStop(pReceiver); - - // start again - snapshotReceiverDoStart(pReceiver, pBeginMsg); - } + ASSERT(!snapshotReceiverIsStart(pReceiver)); + snapshotReceiverDoStart(pReceiver, pBeginMsg); return 0; } @@ -556,14 +448,7 @@ int32_t snapshotReceiverStop(SSyncSnapshotReceiver *pReceiver) { pReceiver->start = false; // event log - do { - SSnapshot snapshot; - pReceiver->pSyncNode->pFsm->FpGetSnapshotInfo(pReceiver->pSyncNode->pFsm, &snapshot); - char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver stop"); - syncNodeEventLog(pReceiver->pSyncNode, eventLog); - taosMemoryFree(eventLog); - } while (0); - + sRTrace(pReceiver, "snapshot receiver stop"); return 0; } @@ -578,7 +463,7 @@ static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnap code = pReceiver->pSyncNode->pFsm->FpSnapshotDoWrite(pReceiver->pSyncNode->pFsm, pReceiver->pWriter, pMsg->data, pMsg->dataLen); if (code != 0) { - syncNodeErrorLog(pReceiver->pSyncNode, "snapshot write error"); + sNError(pReceiver->pSyncNode, "snapshot write error"); return -1; } } @@ -587,7 +472,7 @@ static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnap code = pReceiver->pSyncNode->pLogStore->syncLogRestoreFromSnapshot(pReceiver->pSyncNode->pLogStore, pMsg->lastIndex); if (code != 0) { - syncNodeErrorLog(pReceiver->pSyncNode, "wal restore from snapshot error"); + sNError(pReceiver->pSyncNode, "wal restore from snapshot error"); return -1; } @@ -606,8 +491,7 @@ static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnap code = pReceiver->pSyncNode->pFsm->FpSnapshotStopWrite(pReceiver->pSyncNode->pFsm, pReceiver->pWriter, true, &(pReceiver->snapshot)); if (code != 0) { - syncNodeErrorLog(pReceiver->pSyncNode, "snapshot stop writer true error"); - // ASSERT(0); + sNError(pReceiver->pSyncNode, "snapshot stop writer true error"); return -1; } pReceiver->pWriter = NULL; @@ -616,19 +500,12 @@ static int32_t snapshotReceiverFinish(SSyncSnapshotReceiver *pReceiver, SyncSnap pReceiver->ack = SYNC_SNAPSHOT_SEQ_END; } else { - syncNodeErrorLog(pReceiver->pSyncNode, "snapshot stop writer true error"); + sNError(pReceiver->pSyncNode, "snapshot stop writer true error"); return -1; } // event log - do { - SSnapshot snapshot; - pReceiver->pSyncNode->pFsm->FpGetSnapshotInfo(pReceiver->pSyncNode->pFsm, &snapshot); - char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver got last data, finish, apply snapshot"); - syncNodeEventLog(pReceiver->pSyncNode, eventLog); - taosMemoryFree(eventLog); - } while (0); - + sRTrace(pReceiver, "snapshot receiver got last data, finish, apply snapshot"); return 0; } @@ -649,11 +526,7 @@ static void snapshotReceiverGotData(SSyncSnapshotReceiver *pReceiver, SyncSnapsh pReceiver->ack = pMsg->seq; // event log - do { - char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver receiving"); - syncNodeEventLog(pReceiver->pSyncNode, eventLog); - taosMemoryFree(eventLog); - } while (0); + sRTrace(pReceiver, "snapshot receiver receiving"); } } @@ -698,8 +571,8 @@ cJSON *snapshotReceiver2Json(SSyncSnapshotReceiver *pReceiver) { snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pReceiver->term); cJSON_AddStringToObject(pRoot, "term", u64buf); - snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pReceiver->privateTerm); - cJSON_AddStringToObject(pRoot, "privateTerm", u64buf); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pReceiver->startTime); + cJSON_AddStringToObject(pRoot, "startTime", u64buf); } cJSON *pJson = cJSON_CreateObject(); @@ -714,48 +587,190 @@ char *snapshotReceiver2Str(SSyncSnapshotReceiver *pReceiver) { return serialized; } -char *snapshotReceiver2SimpleStr(SSyncSnapshotReceiver *pReceiver, char *event) { - int32_t len = 256; - char *s = taosMemoryMalloc(len); - - SRaftId fromId = pReceiver->fromId; - char host[128]; - uint16_t port; - syncUtilU642Addr(fromId.addr, host, sizeof(host), &port); - - snprintf(s, len, - "%s {%p start:%d ack:%d term:%" PRIu64 " pterm:%" PRIu64 " from:%s:%d s-param:%" PRId64 " e-param:%" PRId64 - " laindex:%" PRId64 " laterm:%" PRIu64 - " " - "lcindex:%" PRId64 "}", - event, pReceiver, pReceiver->start, pReceiver->ack, pReceiver->term, pReceiver->privateTerm, host, port, - pReceiver->snapshotParam.start, pReceiver->snapshotParam.end, pReceiver->snapshot.lastApplyIndex, - pReceiver->snapshot.lastApplyTerm, pReceiver->snapshot.lastConfigIndex); - - return s; +SyncIndex syncNodeGetSnapBeginIndex(SSyncNode *ths) { + SyncIndex snapStart = SYNC_INDEX_INVALID; + + if (syncNodeIsMnode(ths)) { + snapStart = SYNC_INDEX_BEGIN; + + } else { + SSyncLogStoreData *pData = ths->pLogStore->data; + SWal *pWal = pData->pWal; + + bool isEmpty = ths->pLogStore->syncLogIsEmpty(ths->pLogStore); + int64_t walCommitVer = walGetCommittedVer(pWal); + + if (!isEmpty && ths->commitIndex != walCommitVer) { + sNError(ths, "commit not same, wal-commit:%" PRId64 ", commit:%" PRId64 ", ignore", walCommitVer, + ths->commitIndex); + snapStart = walCommitVer + 1; + } else { + snapStart = ths->commitIndex + 1; + } + } + + return snapStart; +} + +static int32_t syncNodeOnSnapshotPre(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { + SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver; + + if (snapshotReceiverIsStart(pReceiver)) { + // already start + + if (pMsg->startTime > pReceiver->startTime) { + goto _START_RECEIVER; + + } else if (pMsg->startTime == pReceiver->startTime) { + goto _SEND_REPLY; + + } else { + // ignore + return 0; + } + + } else { + // start new + goto _START_RECEIVER; + } + +_START_RECEIVER: + if (taosGetTimestampMs() - pMsg->startTime > SNAPSHOT_MAX_CLOCK_SKEW_MS) { + sNError(pSyncNode, "snapshot receiver time skew too much"); + return -1; + } else { + // waiting for clock match + while (taosGetTimestampMs() > pMsg->startTime) { + taosMsleep(10); + } + + snapshotReceiverStart(pReceiver, pMsg); // set start-time same with sender + } + +_SEND_REPLY: + // build msg + ; // make complier happy + SyncSnapshotRsp *pRspMsg = syncSnapshotRspBuild(pSyncNode->vgId); + pRspMsg->srcId = pSyncNode->myRaftId; + pRspMsg->destId = pMsg->srcId; + pRspMsg->term = pSyncNode->pRaftStore->currentTerm; + pRspMsg->lastIndex = pMsg->lastIndex; + pRspMsg->lastTerm = pMsg->lastTerm; + pRspMsg->startTime = pReceiver->startTime; + pRspMsg->ack = pMsg->seq; // receiver maybe already closed + pRspMsg->code = 0; + pRspMsg->snapBeginIndex = syncNodeGetSnapBeginIndex(pSyncNode); + + // send msg + SRpcMsg rpcMsg; + syncSnapshotRsp2RpcMsg(pRspMsg, &rpcMsg); + syncNodeSendMsgById(&(pRspMsg->destId), pSyncNode, &rpcMsg); + syncSnapshotRspDestroy(pRspMsg); + + return 0; +} + +static int32_t syncNodeOnSnapshotBegin(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { + // condition 1 + SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver; + + if (snapshotReceiverIsStart(pReceiver)) { + if (pMsg->startTime > pReceiver->startTime) { + snapshotReceiverStop(pReceiver); + + } else if (pMsg->startTime == pReceiver->startTime) { + return 0; + } else { + // ignore + sNTrace(pSyncNode, "msg ignore"); + return 0; + } + } + +_START_RECEIVER: + if (taosGetTimestampMs() - pMsg->startTime > SNAPSHOT_MAX_CLOCK_SKEW_MS) { + sNError(pSyncNode, "snapshot receiver time skew too much"); + return -1; + } else { + // waiting for clock match + while (taosGetTimestampMs() > pMsg->startTime) { + taosMsleep(10); + } + + snapshotReceiverStart(pReceiver, pMsg); + + // build msg + SyncSnapshotRsp *pRspMsg = syncSnapshotRspBuild(pSyncNode->vgId); + pRspMsg->srcId = pSyncNode->myRaftId; + pRspMsg->destId = pMsg->srcId; + pRspMsg->term = pSyncNode->pRaftStore->currentTerm; + pRspMsg->lastIndex = pMsg->lastIndex; + pRspMsg->lastTerm = pMsg->lastTerm; + pRspMsg->ack = pReceiver->ack; // receiver maybe already closed + pRspMsg->code = 0; + + // send msg + SRpcMsg rpcMsg; + syncSnapshotRsp2RpcMsg(pRspMsg, &rpcMsg); + syncNodeSendMsgById(&(pRspMsg->destId), pSyncNode, &rpcMsg); + syncSnapshotRspDestroy(pRspMsg); + } + + return 0; } +static int32_t syncNodeOnSnapshotTransfer(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { return 0; } + +static int32_t syncNodeOnSnapshotEnd(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { return 0; } + // receiver on message // -// condition 1, recv SYNC_SNAPSHOT_SEQ_BEGIN, start receiver, update privateTerm -// condition 2, recv SYNC_SNAPSHOT_SEQ_END, finish receiver(apply snapshot data, update commit index, maybe reconfig) -// condition 3, recv SYNC_SNAPSHOT_SEQ_FORCE_CLOSE, force close -// condition 4, got data, update ack +// condition 1, recv SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT +// if receiver already start +// if sender.start-time > receiver.start-time, restart receiver(reply snapshot start) +// if sender.start-time = receiver.start-time, maybe duplicate msg +// if sender.start-time < receiver.start-time, ignore +// else +// waiting for clock match +// start receiver(reply snapshot start) +// +// condition 2, recv SYNC_SNAPSHOT_SEQ_BEGIN +// a. create writer with +// +// condition 3, recv SYNC_SNAPSHOT_SEQ_END, finish receiver(apply snapshot data, update commit index, maybe reconfig) +// +// condition 4, recv SYNC_SNAPSHOT_SEQ_FORCE_CLOSE, force close +// +// condition 5, got data, update ack // int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { - // get receiver - SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver; - bool needRsp = false; + // if already drop replica, do not process + if (!syncNodeInRaftGroup(pSyncNode, &(pMsg->srcId))) { + syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "not in my config"); + return 0; + } + + if (pMsg->term < pSyncNode->pRaftStore->currentTerm) { + syncLogRecvSyncSnapshotSend(pSyncNode, pMsg, "reject, small term"); + return 0; + } + + if (pMsg->term > pSyncNode->pRaftStore->currentTerm) { + syncNodeStepDown(pSyncNode, pMsg->term); + } + syncNodeResetElectTimer(pSyncNode); + int32_t code = 0; + SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver; // state, term, seq/ack if (pSyncNode->state == TAOS_SYNC_STATE_FOLLOWER) { if (pMsg->term == pSyncNode->pRaftStore->currentTerm) { - if (pMsg->seq == SYNC_SNAPSHOT_SEQ_BEGIN) { - // condition 1 - // begin, no data - snapshotReceiverStart(pReceiver, pMsg); - needRsp = true; + if (pMsg->seq == SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT) { + syncNodeOnSnapshotPre(pSyncNode, pMsg); + + } else if (pMsg->seq == SYNC_SNAPSHOT_SEQ_BEGIN) { + syncNodeOnSnapshotBegin(pSyncNode, pMsg); } else if (pMsg->seq == SYNC_SNAPSHOT_SEQ_END) { // condition 2 @@ -764,7 +779,7 @@ int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { if (code == 0) { snapshotReceiverStop(pReceiver); } - needRsp = true; + bool needRsp = true; // maybe update lastconfig if (pMsg->lastConfigIndex >= SYNC_INDEX_BEGIN) { @@ -782,7 +797,7 @@ int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { // condition 3 // force close snapshotReceiverForceStop(pReceiver); - needRsp = false; + bool needRsp = false; } else if (pMsg->seq > SYNC_SNAPSHOT_SEQ_BEGIN && pMsg->seq < SYNC_SNAPSHOT_SEQ_END) { // condition 4 @@ -790,62 +805,71 @@ int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { if (pMsg->seq == pReceiver->ack + 1) { snapshotReceiverGotData(pReceiver, pMsg); } - needRsp = true; + bool needRsp = true; } else { // error log - do { - char logBuf[96]; - snprintf(logBuf, sizeof(logBuf), "snapshot receiver recv error seq:%d, my ack:%d", pMsg->seq, pReceiver->ack); - char *eventLog = snapshotReceiver2SimpleStr(pReceiver, logBuf); - syncNodeErrorLog(pSyncNode, eventLog); - taosMemoryFree(eventLog); - } while (0); - + sRTrace(pReceiver, "snapshot receiver recv error seq:%d, my ack:%d", pMsg->seq, pReceiver->ack); return -1; } - // send ack - if (needRsp) { - // build msg - SyncSnapshotRsp *pRspMsg = syncSnapshotRspBuild(pSyncNode->vgId); - pRspMsg->srcId = pSyncNode->myRaftId; - pRspMsg->destId = pMsg->srcId; - pRspMsg->term = pSyncNode->pRaftStore->currentTerm; - pRspMsg->lastIndex = pMsg->lastIndex; - pRspMsg->lastTerm = pMsg->lastTerm; - pRspMsg->ack = pReceiver->ack; // receiver maybe already closed - pRspMsg->code = 0; - pRspMsg->privateTerm = pReceiver->privateTerm; // receiver maybe already closed - - // send msg - SRpcMsg rpcMsg; - syncSnapshotRsp2RpcMsg(pRspMsg, &rpcMsg); - syncNodeSendMsgById(&(pRspMsg->destId), pSyncNode, &rpcMsg); - syncSnapshotRspDestroy(pRspMsg); - } - } else { // error log - do { - char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver term not equal"); - syncNodeErrorLog(pSyncNode, eventLog); - taosMemoryFree(eventLog); - } while (0); - + sRTrace(pReceiver, "snapshot receiver term not equal"); return -1; } } else { // error log - do { - char *eventLog = snapshotReceiver2SimpleStr(pReceiver, "snapshot receiver not follower"); - syncNodeErrorLog(pSyncNode, eventLog); - taosMemoryFree(eventLog); - } while (0); + sRTrace(pReceiver, "snapshot receiver not follower"); + return -1; + } + + return 0; +} + +int32_t syncNodeOnSnapshotReplyPre(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) { + // get sender + SSyncSnapshotSender *pSender = syncNodeGetSnapshotSender(pSyncNode, &(pMsg->srcId)); + ASSERT(pSender != NULL); + + SSnapshot snapshot; + pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); + // prepare + pSender->snapshotParam.start = pMsg->snapBeginIndex; + pSender->snapshotParam.end = snapshot.lastApplyIndex; + + if (pMsg->snapBeginIndex > snapshot.lastApplyIndex) { + sNError(pSyncNode, "snapshot last index too small"); return -1; } + // start reader + int32_t code = pSyncNode->pFsm->FpSnapshotStartRead(pSyncNode->pFsm, &(pSender->snapshotParam), &(pSender->pReader)); + if (code != 0) { + sNError(pSyncNode, "create snapshot reader error"); + return -1; + } + + // build begin msg + SyncSnapshotSend *pSendMsg = syncSnapshotSendBuild(0, pSender->pSyncNode->vgId); + pSendMsg->srcId = pSender->pSyncNode->myRaftId; + pSendMsg->destId = (pSender->pSyncNode->replicasId)[pSender->replicaIndex]; + pSendMsg->term = pSender->pSyncNode->pRaftStore->currentTerm; + pSendMsg->beginIndex = pSender->snapshotParam.start; + pSendMsg->lastIndex = pSender->snapshot.lastApplyIndex; + pSendMsg->lastTerm = pSender->snapshot.lastApplyTerm; + pSendMsg->lastConfigIndex = pSender->snapshot.lastConfigIndex; + pSendMsg->lastConfig = pSender->lastConfig; + pSendMsg->startTime = pSender->startTime; + pSendMsg->seq = SYNC_SNAPSHOT_SEQ_BEGIN; + + // send msg + SRpcMsg rpcMsg; + syncSnapshotSend2RpcMsg(pSendMsg, &rpcMsg); + syncNodeSendMsgById(&(pSendMsg->destId), pSender->pSyncNode, &rpcMsg); + syncSnapshotSendDestroy(pSendMsg); + return 0; } @@ -857,8 +881,8 @@ int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) { // int32_t syncNodeOnSnapshotReply(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) { // if already drop replica, do not process - if (!syncNodeInRaftGroup(pSyncNode, &(pMsg->srcId)) && pSyncNode->state == TAOS_SYNC_STATE_LEADER) { - sError("vgId:%d, recv sync-snapshot-rsp, maybe replica already dropped", pSyncNode->vgId); + if (!syncNodeInRaftGroup(pSyncNode, &(pMsg->srcId))) { + syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "maybe replica already dropped"); return -1; } @@ -866,17 +890,26 @@ int32_t syncNodeOnSnapshotReply(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) { SSyncSnapshotSender *pSender = syncNodeGetSnapshotSender(pSyncNode, &(pMsg->srcId)); ASSERT(pSender != NULL); + if (pMsg->startTime != pSender->startTime) { + syncLogRecvSyncSnapshotRsp(pSyncNode, pMsg, "sender/receiver start time not match"); + return -1; + } + // state, term, seq/ack if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { if (pMsg->term == pSyncNode->pRaftStore->currentTerm) { - // condition 1 + // prepare , send begin msg + if (pMsg->ack == SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT) { + syncNodeOnSnapshotReplyPre(pSyncNode, pMsg); + return 0; + } + // receive ack is finish, close sender if (pMsg->ack == SYNC_SNAPSHOT_SEQ_END) { snapshotSenderStop(pSender, true); return 0; } - // condition 2 // send next msg if (pMsg->ack == pSender->seq) { // update sender ack @@ -889,36 +922,76 @@ int32_t syncNodeOnSnapshotReply(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) { } else { // error log - do { - char logBuf[96]; - snprintf(logBuf, sizeof(logBuf), "snapshot sender recv error ack:%d, my seq:%d", pMsg->ack, pSender->seq); - char *eventLog = snapshotSender2SimpleStr(pSender, logBuf); - syncNodeErrorLog(pSyncNode, eventLog); - taosMemoryFree(eventLog); - } while (0); - + sSError(pSender, "snapshot sender recv error ack:%d, my seq:%d", pMsg->ack, pSender->seq); return -1; } } else { // error log - do { - char *eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender term not equal"); - syncNodeErrorLog(pSyncNode, eventLog); - taosMemoryFree(eventLog); - } while (0); - + sSError(pSender, "snapshot sender term not equal"); return -1; } } else { // error log - do { - char *eventLog = snapshotSender2SimpleStr(pSender, "snapshot sender not leader"); - syncNodeErrorLog(pSyncNode, eventLog); - taosMemoryFree(eventLog); - } while (0); - + sSError(pSender, "snapshot sender not leader"); return -1; } return 0; } + +int32_t syncNodeOnPreSnapshot(SSyncNode *ths, SyncPreSnapshot *pMsg) { + syncLogRecvSyncPreSnapshot(ths, pMsg, ""); + + SyncPreSnapshotReply *pMsgReply = syncPreSnapshotReplyBuild(ths->vgId); + pMsgReply->srcId = ths->myRaftId; + pMsgReply->destId = pMsg->srcId; + pMsgReply->term = ths->pRaftStore->currentTerm; + + SSyncLogStoreData *pData = ths->pLogStore->data; + SWal *pWal = pData->pWal; + + if (syncNodeIsMnode(ths)) { + pMsgReply->snapStart = SYNC_INDEX_BEGIN; + + } else { + bool isEmpty = ths->pLogStore->syncLogIsEmpty(ths->pLogStore); + int64_t walCommitVer = walGetCommittedVer(pWal); + + if (!isEmpty && ths->commitIndex != walCommitVer) { + sNError(ths, "commit not same, wal-commit:%" PRId64 ", commit:%" PRId64 ", ignore", walCommitVer, + ths->commitIndex); + goto _IGNORE; + } + + pMsgReply->snapStart = ths->commitIndex + 1; + + // make local log clean + int32_t code = ths->pLogStore->syncLogTruncate(ths->pLogStore, pMsgReply->snapStart); + if (code != 0) { + sNError(ths, "truncate wal error"); + goto _IGNORE; + } + } + + // can not write behind _RESPONSE + SRpcMsg rpcMsg; + +_RESPONSE: + syncPreSnapshotReply2RpcMsg(pMsgReply, &rpcMsg); + syncNodeSendMsgById(&pMsgReply->destId, ths, &rpcMsg); + + syncPreSnapshotReplyDestroy(pMsgReply); + return 0; + +_IGNORE: + syncPreSnapshotReplyDestroy(pMsgReply); + return 0; +} + +int32_t syncNodeOnPreSnapshotReply(SSyncNode *ths, SyncPreSnapshotReply *pMsg) { + syncLogRecvSyncPreSnapshotReply(ths, pMsg, ""); + + // start snapshot + + return 0; +} \ No newline at end of file diff --git a/source/libs/sync/src/syncTimeout.c b/source/libs/sync/src/syncTimeout.c index 5ff73a6406d87234944711fa50d15e38fa24e5c7..30e0617f4397275635548e64fdadc73ce835af9b 100644 --- a/source/libs/sync/src/syncTimeout.c +++ b/source/libs/sync/src/syncTimeout.c @@ -49,17 +49,12 @@ static void syncNodeCleanConfigIndex(SSyncNode* ths) { int32_t code = raftCfgPersist(ths->pRaftCfg); ASSERT(code == 0); - do { - char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "clean config index arr, old-cnt:%d, new-cnt:%d", oldCnt, - ths->pRaftCfg->configIndexCount); - syncNodeEventLog(ths, logBuf); - } while (0); + sNTrace(ths, "clean config index arr, old-cnt:%d, new-cnt:%d", oldCnt, ths->pRaftCfg->configIndexCount); } } int32_t syncNodeTimerRoutine(SSyncNode* ths) { - syncNodeEventLog(ths, "timer routines"); + sNTrace(ths, "timer routines"); // timer replicate syncNodeReplicate(ths); @@ -76,15 +71,10 @@ int32_t syncNodeTimerRoutine(SSyncNode* ths) { SSyncLogStoreData* pData = ths->pLogStore->data; int32_t code = walEndSnapshot(pData->pWal); if (code != 0) { - sError("vgId:%d, wal snapshot end error since:%s", ths->vgId, terrstr(terrno)); + sError("vgId:%d, timer wal snapshot end error since:%s", ths->vgId, terrstr()); return -1; } else { - do { - char logBuf[256]; - snprintf(logBuf, sizeof(logBuf), "wal snapshot end, index:%" PRId64, atomic_load_64(&ths->snapshottingIndex)); - syncNodeEventLog(ths, logBuf); - } while (0); - + sNTrace(ths, "wal snapshot end, index:%" PRId64, atomic_load_64(&ths->snapshottingIndex)); atomic_store_64(&ths->snapshottingIndex, SYNC_INDEX_INVALID); } } diff --git a/source/libs/sync/src/syncUtil.c b/source/libs/sync/src/syncUtil.c index f152201901952fb57cc5a5c16ecfe3737184d039..1a00b0f5a43fda87d3e250c8a02bc00cc71bc498 100644 --- a/source/libs/sync/src/syncUtil.c +++ b/source/libs/sync/src/syncUtil.c @@ -13,59 +13,38 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE #include "syncUtil.h" -#include +#include "syncRaftCfg.h" +#include "syncRaftStore.h" +#include "syncSnapshot.h" -#include "syncEnv.h" +extern void addEpIntoEpSet(SEpSet* pEpSet, const char* fqdn, uint16_t port); -void addEpIntoEpSet(SEpSet* pEpSet, const char* fqdn, uint16_t port); - -// ---- encode / decode uint64_t syncUtilAddr2U64(const char* host, uint16_t port) { - uint64_t u64; - uint32_t hostU32 = taosGetIpv4FromFqdn(host); if (hostU32 == (uint32_t)-1) { - sError("failed to resolve ipv4 addr. host:%s", host); + sError("failed to resolve ipv4 addr, host:%s", host); terrno = TSDB_CODE_TSC_INVALID_FQDN; return -1; } - /* - uint32_t hostU32 = (uint32_t)taosInetAddr(host); - if (hostU32 == (uint32_t)-1) { - struct hostent* hostEnt = gethostbyname(host); - if (hostEnt == NULL) { - sError("Get IP address error"); - return -1; - } - - const char* newHost = taosInetNtoa(*(struct in_addr*)(hostEnt->h_addr_list[0])); - hostU32 = (uint32_t)taosInetAddr(newHost); - if (hostU32 == (uint32_t)-1) { - sError("change %s to id, error", newHost); - } - // ASSERT(hostU32 != (uint32_t)-1); - } - */ - - u64 = (((uint64_t)hostU32) << 32) | (((uint32_t)port) << 16); + uint64_t u64 = (((uint64_t)hostU32) << 32) | (((uint32_t)port) << 16); return u64; } -void syncUtilU642Addr(uint64_t u64, char* host, size_t len, uint16_t* port) { +void syncUtilU642Addr(uint64_t u64, char* host, int64_t len, uint16_t* port) { uint32_t hostU32 = (uint32_t)((u64 >> 32) & 0x00000000FFFFFFFF); - struct in_addr addr; - addr.s_addr = hostU32; + struct in_addr addr = {.s_addr = hostU32}; taosInetNtoa(addr, host, len); *port = (uint16_t)((u64 & 0x00000000FFFF0000) >> 16); } -void syncUtilnodeInfo2EpSet(const SNodeInfo* pNodeInfo, SEpSet* pEpSet) { +void syncUtilnodeInfo2EpSet(const SNodeInfo* pInfo, SEpSet* pEpSet) { pEpSet->inUse = 0; pEpSet->numOfEps = 0; - addEpIntoEpSet(pEpSet, pNodeInfo->nodeFqdn, pNodeInfo->nodePort); + addEpIntoEpSet(pEpSet, pInfo->nodeFqdn, pInfo->nodePort); } void syncUtilraftId2EpSet(const SRaftId* raftId, SEpSet* pEpSet) { @@ -73,28 +52,22 @@ void syncUtilraftId2EpSet(const SRaftId* raftId, SEpSet* pEpSet) { uint16_t port; syncUtilU642Addr(raftId->addr, host, sizeof(host), &port); - - /* - pEpSet->numOfEps = 1; - pEpSet->inUse = 0; - pEpSet->eps[0].port = port; - snprintf(pEpSet->eps[0].fqdn, sizeof(pEpSet->eps[0].fqdn), "%s", host); - */ pEpSet->inUse = 0; pEpSet->numOfEps = 0; addEpIntoEpSet(pEpSet, host, port); } -bool syncUtilnodeInfo2raftId(const SNodeInfo* pNodeInfo, SyncGroupId vgId, SRaftId* raftId) { - uint32_t ipv4 = taosGetIpv4FromFqdn(pNodeInfo->nodeFqdn); +bool syncUtilnodeInfo2raftId(const SNodeInfo* pInfo, SyncGroupId vgId, SRaftId* raftId) { + uint32_t ipv4 = taosGetIpv4FromFqdn(pInfo->nodeFqdn); if (ipv4 == 0xFFFFFFFF || ipv4 == 1) { - sError("failed to resolve ipv4 addr. fqdn: %s", pNodeInfo->nodeFqdn); + sError("failed to resolve ipv4 addr, fqdn: %s", pInfo->nodeFqdn); terrno = TSDB_CODE_TSC_INVALID_FQDN; return false; } + char ipbuf[128] = {0}; tinet_ntoa(ipbuf, ipv4); - raftId->addr = syncUtilAddr2U64(ipbuf, pNodeInfo->nodePort); + raftId->addr = syncUtilAddr2U64(ipbuf, pInfo->nodePort); raftId->vgId = vgId; return true; } @@ -106,31 +79,9 @@ bool syncUtilSameId(const SRaftId* pId1, const SRaftId* pId2) { bool syncUtilEmptyId(const SRaftId* pId) { return (pId->addr == 0 && pId->vgId == 0); } -// ---- SSyncBuffer ----- -void syncUtilbufBuild(SSyncBuffer* syncBuf, size_t len) { - syncBuf->len = len; - syncBuf->data = taosMemoryMalloc(syncBuf->len); -} - -void syncUtilbufDestroy(SSyncBuffer* syncBuf) { taosMemoryFree(syncBuf->data); } - -void syncUtilbufCopy(const SSyncBuffer* src, SSyncBuffer* dest) { - dest->len = src->len; - dest->data = src->data; -} - -void syncUtilbufCopyDeep(const SSyncBuffer* src, SSyncBuffer* dest) { - dest->len = src->len; - dest->data = taosMemoryMalloc(dest->len); - memcpy(dest->data, src->data, dest->len); -} - -// ---- misc ---- - -int32_t syncUtilRand(int32_t max) { return taosRand() % max; } +static inline int32_t syncUtilRand(int32_t max) { return taosRand() % max; } int32_t syncUtilElectRandomMS(int32_t min, int32_t max) { - ASSERT(min > 0 && max > 0 && max >= min); int32_t rdm = min + syncUtilRand(max - min); // sDebug("random min:%d, max:%d, rdm:%d", min, max, rdm); @@ -176,31 +127,7 @@ char* syncUtilRaftId2Str(const SRaftId* p) { return serialized; } -const char* syncUtilState2String(ESyncState state) { - /* - if (state == TAOS_SYNC_STATE_FOLLOWER) { - return "TAOS_SYNC_STATE_FOLLOWER"; - } else if (state == TAOS_SYNC_STATE_CANDIDATE) { - return "TAOS_SYNC_STATE_CANDIDATE"; - } else if (state == TAOS_SYNC_STATE_LEADER) { - return "TAOS_SYNC_STATE_LEADER"; - } else { - return "TAOS_SYNC_STATE_UNKNOWN"; - } - */ - - if (state == TAOS_SYNC_STATE_FOLLOWER) { - return "follower"; - } else if (state == TAOS_SYNC_STATE_CANDIDATE) { - return "candidate"; - } else if (state == TAOS_SYNC_STATE_LEADER) { - return "leader"; - } else { - return "state_error"; - } -} - -bool syncUtilCanPrint(char c) { +static inline bool syncUtilCanPrint(char c) { if (c >= 32 && c <= 126) { return true; } else { @@ -208,14 +135,14 @@ bool syncUtilCanPrint(char c) { } } -char* syncUtilprintBin(char* ptr, uint32_t len) { +char* syncUtilPrintBin(char* ptr, uint32_t len) { int64_t memLen = (int64_t)(len + 1); char* s = taosMemoryMalloc(memLen); ASSERT(s != NULL); memset(s, 0, len + 1); memcpy(s, ptr, len); - for (int i = 0; i < len; ++i) { + for (int32_t i = 0; i < len; ++i) { if (!syncUtilCanPrint(s[i])) { s[i] = '.'; } @@ -223,30 +150,20 @@ char* syncUtilprintBin(char* ptr, uint32_t len) { return s; } -char* syncUtilprintBin2(char* ptr, uint32_t len) { +char* syncUtilPrintBin2(char* ptr, uint32_t len) { uint32_t len2 = len * 4 + 1; char* s = taosMemoryMalloc(len2); ASSERT(s != NULL); memset(s, 0, len2); char* p = s; - for (int i = 0; i < len; ++i) { - int n = sprintf(p, "%d,", ptr[i]); + for (int32_t i = 0; i < len; ++i) { + int32_t n = sprintf(p, "%d,", ptr[i]); p += n; } return s; } -SyncIndex syncUtilMinIndex(SyncIndex a, SyncIndex b) { - SyncIndex r = a < b ? a : b; - return r; -} - -SyncIndex syncUtilMaxIndex(SyncIndex a, SyncIndex b) { - SyncIndex r = a > b ? a : b; - return r; -} - void syncUtilMsgHtoN(void* msg) { // htonl SMsgHead* pHead = msg; @@ -261,60 +178,192 @@ void syncUtilMsgNtoH(void* msg) { pHead->vgId = ntohl(pHead->vgId); } -#if 0 -bool syncUtilIsData(tmsg_t msgType) { - if (msgType == TDMT_SYNC_NOOP || msgType == TDMT_SYNC_CONFIG_CHANGE) { - return false; +bool syncUtilUserPreCommit(tmsg_t msgType) { return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER; } + +bool syncUtilUserCommit(tmsg_t msgType) { return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER; } + +bool syncUtilUserRollback(tmsg_t msgType) { return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER; } + +void syncCfg2SimpleStr(const SSyncCfg* pCfg, char* buf, int32_t bufLen) { + int32_t len = snprintf(buf, bufLen, "{r-num:%d, my:%d, ", pCfg->replicaNum, pCfg->myIndex); + + for (int32_t i = 0; i < pCfg->replicaNum; ++i) { + if (i < pCfg->replicaNum - 1) { + len += snprintf(buf + len, bufLen - len, "%s:%d, ", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort); + } else { + len += snprintf(buf + len, bufLen - len, "%s:%d}", pCfg->nodeInfo[i].nodeFqdn, pCfg->nodeInfo[i].nodePort); + } } - return true; } -#endif -bool syncUtilUserPreCommit(tmsg_t msgType) { - if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_CONFIG_CHANGE && msgType != TDMT_SYNC_CONFIG_CHANGE_FINISH && - msgType != TDMT_SYNC_LEADER_TRANSFER) { - return true; - } +static void syncPeerState2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) { + int32_t len = 1; - return false; + for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) { + SPeerState* pState = syncNodeGetPeerState(pSyncNode, &(pSyncNode->replicasId[i])); + if (pState == NULL) break; + + if (i < pSyncNode->replicaNum - 1) { + len += snprintf(buf + len, bufLen - len, "%d:%" PRId64 " %" PRId64 ", ", i, pState->lastSendIndex, + pState->lastSendTime); + } else { + len += snprintf(buf + len, bufLen - len, "%d:%" PRId64 " %" PRId64 "}", i, pState->lastSendIndex, + pState->lastSendTime); + } + } } -bool syncUtilUserCommit(tmsg_t msgType) { - if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_CONFIG_CHANGE && msgType != TDMT_SYNC_CONFIG_CHANGE_FINISH && - msgType != TDMT_SYNC_LEADER_TRANSFER) { - return true; +void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNode* pNode, const char* format, ...) { + if (pNode == NULL || pNode->pRaftCfg != NULL && pNode->pRaftStore == NULL || pNode->pLogStore == NULL) return; + + // save error code, otherwise it will be overwritten + int32_t errCode = terrno; + + SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0}; + if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) { + pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot); + } + + SyncIndex logLastIndex = SYNC_INDEX_INVALID; + SyncIndex logBeginIndex = SYNC_INDEX_INVALID; + if (pNode->pLogStore != NULL) { + logLastIndex = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore); + logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore); } - return false; + char cfgStr[1024]; + syncCfg2SimpleStr(&(pNode->pRaftCfg->cfg), cfgStr, sizeof(cfgStr)); + + char peerStr[1024] = "{"; + syncPeerState2Str(pNode, peerStr, sizeof(peerStr)); + + int32_t quorum = syncNodeDynamicQuorum(pNode); + + char eventLog[512]; // {0}; + va_list argpointer; + va_start(argpointer, format); + int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer); + va_end(argpointer); + + int32_t aqItems = pNode->pFsm->FpApplyQueueItems(pNode->pFsm); + + // restore error code + terrno = errCode; + + taosPrintLog(flags, level, dflag, + "vgId:%d, sync %s " + "%s" + ", tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64 + ", snap-tm:%" PRIu64 ", sby:%d, aq:%d, bch:%d, r-num:%d, lcfg:%" PRId64 + ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s", + pNode->vgId, syncStr(pNode->state), eventLog, pNode->pRaftStore->currentTerm, pNode->commitIndex, + logBeginIndex, logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm, + pNode->pRaftCfg->isStandBy, aqItems, pNode->pRaftCfg->batchSize, pNode->replicaNum, + pNode->pRaftCfg->lastConfigIndex, pNode->changing, pNode->restoreFinish, quorum, + pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, peerStr, cfgStr); } -bool syncUtilUserRollback(tmsg_t msgType) { - if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_CONFIG_CHANGE && msgType != TDMT_SYNC_CONFIG_CHANGE_FINISH && - msgType != TDMT_SYNC_LEADER_TRANSFER) { - return true; +void syncPrintSnapshotSenderLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotSender* pSender, + const char* format, ...) { + SSyncNode* pNode = pSender->pSyncNode; + if (pNode == NULL || pNode->pRaftCfg != NULL && pNode->pRaftStore == NULL || pNode->pLogStore == NULL) return; + + SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0}; + if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) { + pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot); + } + + SyncIndex logLastIndex = SYNC_INDEX_INVALID; + SyncIndex logBeginIndex = SYNC_INDEX_INVALID; + if (pNode->pLogStore != NULL) { + logLastIndex = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore); + logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore); } - return false; + char cfgStr[1024]; + syncCfg2SimpleStr(&(pNode->pRaftCfg->cfg), cfgStr, sizeof(cfgStr)); + + char peerStr[1024] = "{"; + syncPeerState2Str(pNode, peerStr, sizeof(peerStr)); + + int32_t quorum = syncNodeDynamicQuorum(pNode); + SRaftId destId = pNode->replicasId[pSender->replicaIndex]; + char host[64]; + uint16_t port; + syncUtilU642Addr(destId.addr, host, sizeof(host), &port); + + char eventLog[512]; // {0}; + va_list argpointer; + va_start(argpointer, format); + int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer); + va_end(argpointer); + + taosPrintLog(flags, level, dflag, + "vgId:%d, sync %s " + "%s {%p s-param:%" PRId64 " e-param:%" PRId64 " laindex:%" PRId64 " laterm:%" PRIu64 " lcindex:%" PRId64 + " seq:%d ack:%d finish:%d replica-index:%d %s:%d}" + ", tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64 + ", snap-tm:%" PRIu64 ", sby:%d, stgy:%d, bch:%d, r-num:%d, lcfg:%" PRId64 + ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s", + pNode->vgId, syncStr(pNode->state), eventLog, pSender, pSender->snapshotParam.start, + pSender->snapshotParam.end, pSender->snapshot.lastApplyIndex, pSender->snapshot.lastApplyTerm, + pSender->snapshot.lastConfigIndex, pSender->seq, pSender->ack, pSender->finish, pSender->replicaIndex, + host, port, pNode->pRaftStore->currentTerm, pNode->commitIndex, logBeginIndex, logLastIndex, + pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm, pNode->pRaftCfg->isStandBy, + pNode->pRaftCfg->snapshotStrategy, pNode->pRaftCfg->batchSize, pNode->replicaNum, + pNode->pRaftCfg->lastConfigIndex, pNode->changing, pNode->restoreFinish, quorum, + pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, peerStr, cfgStr); } -void syncUtilJson2Line(char* jsonStr) { - int p, q, len; - p = 0; - q = 1; - len = strlen(jsonStr); - while (1) { - if (jsonStr[q] == '\0') { - jsonStr[p + 1] = '\0'; - break; - } +void syncPrintSnapshotReceiverLog(const char* flags, ELogLevel level, int32_t dflag, SSyncSnapshotReceiver* pReceiver, + const char* format, ...) { + SSyncNode* pNode = pReceiver->pSyncNode; + if (pNode == NULL || pNode->pRaftCfg != NULL && pNode->pRaftStore == NULL || pNode->pLogStore == NULL) return; - if (jsonStr[q] == '\n' || jsonStr[q] == ' ' || jsonStr[q] == '\t') { - q++; - continue; - } else { - jsonStr[p + 1] = jsonStr[q]; - p++; - q++; - } + SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0}; + if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) { + pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot); + } + + SyncIndex logLastIndex = SYNC_INDEX_INVALID; + SyncIndex logBeginIndex = SYNC_INDEX_INVALID; + if (pNode->pLogStore != NULL) { + logLastIndex = pNode->pLogStore->syncLogLastIndex(pNode->pLogStore); + logBeginIndex = pNode->pLogStore->syncLogBeginIndex(pNode->pLogStore); } + + char cfgStr[1024]; + syncCfg2SimpleStr(&(pNode->pRaftCfg->cfg), cfgStr, sizeof(cfgStr)); + + char peerStr[1024] = "{"; + syncPeerState2Str(pNode, peerStr, sizeof(peerStr)); + + int32_t quorum = syncNodeDynamicQuorum(pNode); + SRaftId fromId = pReceiver->fromId; + char host[128]; + uint16_t port; + syncUtilU642Addr(fromId.addr, host, sizeof(host), &port); + + char eventLog[512]; // {0}; + va_list argpointer; + va_start(argpointer, format); + int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer); + va_end(argpointer); + + taosPrintLog(flags, level, dflag, + "vgId:%d, sync %s " + "%s {%p start:%d ack:%d term:%" PRIu64 " start-time:%" PRId64 " from:%s:%d s-param:%" PRId64 + " e-param:%" PRId64 " laindex:%" PRId64 " laterm:%" PRIu64 " lcindex:%" PRId64 + "}" + ", tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64 + ", snap-tm:%" PRIu64 ", sby:%d, stgy:%d, bch:%d, r-num:%d, lcfg:%" PRId64 + ", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s", + pNode->vgId, syncStr(pNode->state), eventLog, pReceiver, pReceiver->start, pReceiver->ack, + pReceiver->term, pReceiver->startTime, host, port, pReceiver->snapshotParam.start, + pReceiver->snapshotParam.end, pReceiver->snapshot.lastApplyIndex, pReceiver->snapshot.lastApplyTerm, + pReceiver->snapshot.lastConfigIndex, pNode->pRaftStore->currentTerm, pNode->commitIndex, logBeginIndex, + logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm, + pNode->pRaftCfg->isStandBy, pNode->pRaftCfg->snapshotStrategy, pNode->pRaftCfg->batchSize, + pNode->replicaNum, pNode->pRaftCfg->lastConfigIndex, pNode->changing, pNode->restoreFinish, quorum, + pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, peerStr, cfgStr); } diff --git a/source/libs/sync/src/syncVoteMgr.c b/source/libs/sync/src/syncVoteMgr.c index ce72935221a81731e73273d2c1496929d18b710a..ee1f83ee6acc572a8c999a265bda1ad5f292a844 100644 --- a/source/libs/sync/src/syncVoteMgr.c +++ b/source/libs/sync/src/syncVoteMgr.c @@ -13,10 +13,10 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE #include "syncVoteMgr.h" #include "syncUtil.h" -// SVotesGranted ----------------------------- static void voteGrantedClearVotes(SVotesGranted *pVotesGranted) { memset(pVotesGranted->isGranted, 0, sizeof(pVotesGranted->isGranted)); pVotesGranted->votes = 0; @@ -68,14 +68,14 @@ void voteGrantedVote(SVotesGranted *pVotesGranted, SyncRequestVoteReply *pMsg) { ASSERT(pMsg->voteGranted == true); if (pMsg->term != pVotesGranted->term) { - syncNodeEventLog(pVotesGranted->pSyncNode, "vote grant vnode error"); + sNTrace(pVotesGranted->pSyncNode, "vote grant vnode error"); return; } ASSERT(syncUtilSameId(&pVotesGranted->pSyncNode->myRaftId, &pMsg->destId)); - int j = -1; - for (int i = 0; i < pVotesGranted->replicaNum; ++i) { + int32_t j = -1; + for (int32_t i = 0; i < pVotesGranted->replicaNum; ++i) { if (syncUtilSameId(&((*(pVotesGranted->replicas))[i]), &(pMsg->srcId))) { j = i; break; @@ -105,11 +105,11 @@ cJSON *voteGranted2Json(SVotesGranted *pVotesGranted) { cJSON_AddNumberToObject(pRoot, "replicaNum", pVotesGranted->replicaNum); cJSON *pReplicas = cJSON_CreateArray(); cJSON_AddItemToObject(pRoot, "replicas", pReplicas); - for (int i = 0; i < pVotesGranted->replicaNum; ++i) { + for (int32_t i = 0; i < pVotesGranted->replicaNum; ++i) { cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pVotesGranted->replicas))[i])); } - int *arr = (int *)taosMemoryMalloc(sizeof(int) * pVotesGranted->replicaNum); - for (int i = 0; i < pVotesGranted->replicaNum; ++i) { + int32_t *arr = (int32_t *)taosMemoryMalloc(sizeof(int32_t) * pVotesGranted->replicaNum); + for (int32_t i = 0; i < pVotesGranted->replicaNum; ++i) { arr[i] = pVotesGranted->isGranted[i]; } cJSON *pIsGranted = cJSON_CreateIntArray(arr, pVotesGranted->replicaNum); @@ -140,34 +140,6 @@ char *voteGranted2Str(SVotesGranted *pVotesGranted) { return serialized; } -// for debug ------------------- -void voteGrantedPrint(SVotesGranted *pObj) { - char *serialized = voteGranted2Str(pObj); - printf("voteGrantedPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void voteGrantedPrint2(char *s, SVotesGranted *pObj) { - char *serialized = voteGranted2Str(pObj); - printf("voteGrantedPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void voteGrantedLog(SVotesGranted *pObj) { - char *serialized = voteGranted2Str(pObj); - sTrace("voteGrantedLog | len:%d | %s", (int32_t)strlen(serialized), serialized); - taosMemoryFree(serialized); -} - -void voteGrantedLog2(char *s, SVotesGranted *pObj) { - char *serialized = voteGranted2Str(pObj); - sTrace("voteGrantedLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); - taosMemoryFree(serialized); -} - -// SVotesRespond ----------------------------- SVotesRespond *votesRespondCreate(SSyncNode *pSyncNode) { SVotesRespond *pVotesRespond = taosMemoryMalloc(sizeof(SVotesRespond)); ASSERT(pVotesRespond != NULL); @@ -196,7 +168,7 @@ void votesRespondUpdate(SVotesRespond *pVotesRespond, SSyncNode *pSyncNode) { bool votesResponded(SVotesRespond *pVotesRespond, const SRaftId *pRaftId) { bool ret = false; - for (int i = 0; i < pVotesRespond->replicaNum; ++i) { + for (int32_t i = 0; i < pVotesRespond->replicaNum; ++i) { if (syncUtilSameId(&(*pVotesRespond->replicas)[i], pRaftId) && pVotesRespond->isRespond[i]) { ret = true; break; @@ -207,11 +179,11 @@ bool votesResponded(SVotesRespond *pVotesRespond, const SRaftId *pRaftId) { void votesRespondAdd(SVotesRespond *pVotesRespond, const SyncRequestVoteReply *pMsg) { if (pVotesRespond->term != pMsg->term) { - syncNodeEventLog(pVotesRespond->pSyncNode, "vote respond add error"); + sNTrace(pVotesRespond->pSyncNode, "vote respond add error"); return; } - for (int i = 0; i < pVotesRespond->replicaNum; ++i) { + for (int32_t i = 0; i < pVotesRespond->replicaNum; ++i) { if (syncUtilSameId(&((*(pVotesRespond->replicas))[i]), &pMsg->srcId)) { // ASSERT(pVotesRespond->isRespond[i] == false); pVotesRespond->isRespond[i] = true; @@ -225,7 +197,7 @@ void votesRespondReset(SVotesRespond *pVotesRespond, SyncTerm term) { pVotesRespond->term = term; memset(pVotesRespond->isRespond, 0, sizeof(pVotesRespond->isRespond)); /* - for (int i = 0; i < pVotesRespond->replicaNum; ++i) { + for (int32_t i = 0; i < pVotesRespond->replicaNum; ++i) { pVotesRespond->isRespond[i] = false; } */ @@ -239,12 +211,12 @@ cJSON *votesRespond2Json(SVotesRespond *pVotesRespond) { cJSON_AddNumberToObject(pRoot, "replicaNum", pVotesRespond->replicaNum); cJSON *pReplicas = cJSON_CreateArray(); cJSON_AddItemToObject(pRoot, "replicas", pReplicas); - for (int i = 0; i < pVotesRespond->replicaNum; ++i) { + for (int32_t i = 0; i < pVotesRespond->replicaNum; ++i) { cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pVotesRespond->replicas))[i])); } - int respondNum = 0; - int *arr = (int *)taosMemoryMalloc(sizeof(int) * pVotesRespond->replicaNum); - for (int i = 0; i < pVotesRespond->replicaNum; ++i) { + int32_t respondNum = 0; + int32_t *arr = (int32_t *)taosMemoryMalloc(sizeof(int32_t) * pVotesRespond->replicaNum); + for (int32_t i = 0; i < pVotesRespond->replicaNum; ++i) { arr[i] = pVotesRespond->isRespond[i]; if (pVotesRespond->isRespond[i]) { respondNum++; @@ -272,30 +244,3 @@ char *votesRespond2Str(SVotesRespond *pVotesRespond) { cJSON_Delete(pJson); return serialized; } - -// for debug ------------------- -void votesRespondPrint(SVotesRespond *pObj) { - char *serialized = votesRespond2Str(pObj); - printf("votesRespondPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void votesRespondPrint2(char *s, SVotesRespond *pObj) { - char *serialized = votesRespond2Str(pObj); - printf("votesRespondPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); - fflush(NULL); - taosMemoryFree(serialized); -} - -void votesRespondLog(SVotesRespond *pObj) { - char *serialized = votesRespond2Str(pObj); - sTrace("votesRespondLog | len:%d | %s", (int32_t)strlen(serialized), serialized); - taosMemoryFree(serialized); -} - -void votesRespondLog2(char *s, SVotesRespond *pObj) { - char *serialized = votesRespond2Str(pObj); - sTrace("votesRespondLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); - taosMemoryFree(serialized); -} diff --git a/source/libs/sync/test/CMakeLists.txt b/source/libs/sync/test/CMakeLists.txt index b9cc7a391dde35e2569f30000752b3ef175fc824..7a22d96972eca3c6f73908cae302b2806df5eed1 100644 --- a/source/libs/sync/test/CMakeLists.txt +++ b/source/libs/sync/test/CMakeLists.txt @@ -1,3 +1,4 @@ +add_subdirectory(sync_test_lib) add_executable(syncTest "") add_executable(syncRaftIdCheck "") add_executable(syncEnvTest "") @@ -24,8 +25,6 @@ add_executable(syncRequestVoteReplyTest "") add_executable(syncAppendEntriesTest "") add_executable(syncAppendEntriesBatchTest "") add_executable(syncAppendEntriesReplyTest "") -add_executable(syncClientRequestTest "") -add_executable(syncClientRequestBatchTest "") add_executable(syncTimeoutTest "") add_executable(syncPingTest "") add_executable(syncPingReplyTest "") @@ -54,11 +53,13 @@ add_executable(syncRaftLogTest "") add_executable(syncRaftLogTest2 "") add_executable(syncRaftLogTest3 "") add_executable(syncLeaderTransferTest "") -add_executable(syncReconfigFinishTest "") add_executable(syncRestoreFromSnapshot "") add_executable(syncRaftCfgIndexTest "") add_executable(syncHeartbeatTest "") add_executable(syncHeartbeatReplyTest "") +add_executable(syncLocalCmdTest "") +add_executable(syncPreSnapshotTest "") +add_executable(syncPreSnapshotReplyTest "") target_sources(syncTest @@ -165,14 +166,6 @@ target_sources(syncAppendEntriesReplyTest PRIVATE "syncAppendEntriesReplyTest.cpp" ) -target_sources(syncClientRequestTest - PRIVATE - "syncClientRequestTest.cpp" -) -target_sources(syncClientRequestBatchTest - PRIVATE - "syncClientRequestBatchTest.cpp" -) target_sources(syncTimeoutTest PRIVATE "syncTimeoutTest.cpp" @@ -285,10 +278,6 @@ target_sources(syncLeaderTransferTest PRIVATE "syncLeaderTransferTest.cpp" ) -target_sources(syncReconfigFinishTest - PRIVATE - "syncReconfigFinishTest.cpp" -) target_sources(syncRestoreFromSnapshot PRIVATE "syncRestoreFromSnapshot.cpp" @@ -305,6 +294,18 @@ target_sources(syncHeartbeatReplyTest PRIVATE "syncHeartbeatReplyTest.cpp" ) +target_sources(syncLocalCmdTest + PRIVATE + "syncLocalCmdTest.cpp" +) +target_sources(syncPreSnapshotTest + PRIVATE + "syncPreSnapshotTest.cpp" +) +target_sources(syncPreSnapshotReplyTest + PRIVATE + "syncPreSnapshotReplyTest.cpp" +) target_include_directories(syncTest @@ -437,16 +438,6 @@ target_include_directories(syncAppendEntriesReplyTest "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) -target_include_directories(syncClientRequestTest - PUBLIC - "${TD_SOURCE_DIR}/include/libs/sync" - "${CMAKE_CURRENT_SOURCE_DIR}/../inc" -) -target_include_directories(syncClientRequestBatchTest - PUBLIC - "${TD_SOURCE_DIR}/include/libs/sync" - "${CMAKE_CURRENT_SOURCE_DIR}/../inc" -) target_include_directories(syncTimeoutTest PUBLIC "${TD_SOURCE_DIR}/include/libs/sync" @@ -587,11 +578,6 @@ target_include_directories(syncLeaderTransferTest "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) -target_include_directories(syncReconfigFinishTest - PUBLIC - "${TD_SOURCE_DIR}/include/libs/sync" - "${CMAKE_CURRENT_SOURCE_DIR}/../inc" -) target_include_directories(syncRestoreFromSnapshot PUBLIC "${TD_SOURCE_DIR}/include/libs/sync" @@ -612,250 +598,265 @@ target_include_directories(syncHeartbeatReplyTest "${TD_SOURCE_DIR}/include/libs/sync" "${CMAKE_CURRENT_SOURCE_DIR}/../inc" ) +target_include_directories(syncLocalCmdTest + PUBLIC + "${TD_SOURCE_DIR}/include/libs/sync" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" +) +target_include_directories(syncPreSnapshotTest + PUBLIC + "${TD_SOURCE_DIR}/include/libs/sync" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" +) +target_include_directories(syncPreSnapshotReplyTest + PUBLIC + "${TD_SOURCE_DIR}/include/libs/sync" + "${CMAKE_CURRENT_SOURCE_DIR}/../inc" +) target_link_libraries(syncTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncRaftIdCheck - sync + sync_test_lib gtest_main ) target_link_libraries(syncEnvTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncPingTimerTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncIOTickQTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncIOTickPingTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncIOSendMsgTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncIOClientTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncIOServerTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncRaftStoreTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncEnqTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncIndexTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncInitTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncUtilTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncVotesGrantedTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncVotesRespondTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncIndexMgrTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncLogStoreTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncEntryTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncEntryCacheTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncHashCacheTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncRequestVoteTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncRequestVoteReplyTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncAppendEntriesTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncAppendEntriesBatchTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncAppendEntriesReplyTest - sync - gtest_main -) -target_link_libraries(syncClientRequestTest - sync - gtest_main -) -target_link_libraries(syncClientRequestBatchTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncTimeoutTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncPingTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncPingReplyTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncRpcMsgTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncPingTimerTest2 - sync + sync_test_lib gtest_main ) target_link_libraries(syncPingSelfTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncElectTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncEncodeTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncWriteTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncReplicateTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncRefTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncLogStoreCheck - sync + sync_test_lib gtest_main ) target_link_libraries(syncLogStoreCheck2 - sync + sync_test_lib gtest_main ) target_link_libraries(syncRaftCfgTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncRespMgrTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncSnapshotTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncApplyMsgTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncConfigChangeTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncConfigChangeSnapshotTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncSnapshotSendTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncSnapshotRspTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncSnapshotSenderTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncSnapshotReceiverTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncTestTool - sync + sync_test_lib gtest_main ) target_link_libraries(syncRaftLogTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncRaftLogTest2 - sync + sync_test_lib gtest_main ) target_link_libraries(syncRaftLogTest3 - sync + sync_test_lib gtest_main ) target_link_libraries(syncLeaderTransferTest - sync - gtest_main -) -target_link_libraries(syncReconfigFinishTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncRestoreFromSnapshot - sync + sync_test_lib gtest_main ) target_link_libraries(syncRaftCfgIndexTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncHeartbeatTest - sync + sync_test_lib gtest_main ) target_link_libraries(syncHeartbeatReplyTest - sync + sync_test_lib + gtest_main +) +target_link_libraries(syncLocalCmdTest + sync_test_lib + gtest_main +) +target_link_libraries(syncPreSnapshotTest + sync_test_lib + gtest_main +) +target_link_libraries(syncPreSnapshotReplyTest + sync_test_lib gtest_main ) diff --git a/source/libs/sync/test/syncAppendEntriesBatchTest.cpp b/source/libs/sync/test/syncAppendEntriesBatchTest.cpp index f2544d8fec7afcf707207e792376488986834380..98b8654734e937384338e42ee7c404d298f887b2 100644 --- a/source/libs/sync/test/syncAppendEntriesBatchTest.cpp +++ b/source/libs/sync/test/syncAppendEntriesBatchTest.cpp @@ -6,6 +6,7 @@ #include "syncRaftEntry.h" #include "syncUtil.h" #include "trpc.h" +#include "syncTest.h" void logTest() { sTrace("--- sync log test: trace"); diff --git a/source/libs/sync/test/syncApplyMsgTest.cpp b/source/libs/sync/test/syncApplyMsgTest.cpp index 9d5e7dd8e1de635ea5cbc64352eb25bafa40d99d..ce129015c6853dedca846e317c8cedb47731bf25 100644 --- a/source/libs/sync/test/syncApplyMsgTest.cpp +++ b/source/libs/sync/test/syncApplyMsgTest.cpp @@ -81,7 +81,7 @@ void test4() { void test5() { SyncApplyMsg *pMsg = createMsg(); - SRpcMsg rpcMsg; + SRpcMsg rpcMsg = {0}; syncApplyMsg2RpcMsg(pMsg, &rpcMsg); SyncApplyMsg *pMsg2 = syncApplyMsgFromRpcMsg2(&rpcMsg); syncApplyMsgLog2((char *)"test5: syncClientRequest2RpcMsg -> syncApplyMsgFromRpcMsg2 ", pMsg2); diff --git a/source/libs/sync/test/syncClientRequestBatchTest.cpp b/source/libs/sync/test/syncClientRequestBatchTest.cpp deleted file mode 100644 index 5586b7a6ce55c8f4f6aa6aebbd5c295e6562e1d4..0000000000000000000000000000000000000000 --- a/source/libs/sync/test/syncClientRequestBatchTest.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#include -#include -#include "syncIO.h" -#include "syncInt.h" -#include "syncMessage.h" -#include "syncUtil.h" - -void logTest() { - sTrace("--- sync log test: trace"); - sDebug("--- sync log test: debug"); - sInfo("--- sync log test: info"); - sWarn("--- sync log test: warn"); - sError("--- sync log test: error"); - sFatal("--- sync log test: fatal"); -} - -SRpcMsg *createRpcMsg(int32_t i, int32_t dataLen) { - SyncPing *pSyncMsg = syncPingBuild(20); - snprintf(pSyncMsg->data, pSyncMsg->dataLen, "value_%d", i); - - SRpcMsg *pRpcMsg = (SRpcMsg *)taosMemoryMalloc(sizeof(SRpcMsg)); - memset(pRpcMsg, 0, sizeof(SRpcMsg)); - pRpcMsg->code = 10 * i; - syncPing2RpcMsg(pSyncMsg, pRpcMsg); - - syncPingDestroy(pSyncMsg); - return pRpcMsg; -} - -SyncClientRequestBatch *createMsg() { - SRpcMsg *rpcMsgPArr[5]; - memset(rpcMsgPArr, 0, sizeof(rpcMsgPArr)); - for (int32_t i = 0; i < 5; ++i) { - SRpcMsg *pRpcMsg = createRpcMsg(i, 20); - rpcMsgPArr[i] = pRpcMsg; - // taosMemoryFree(pRpcMsg); - } - - SRaftMeta raftArr[5]; - memset(raftArr, 0, sizeof(raftArr)); - for (int32_t i = 0; i < 5; ++i) { - raftArr[i].seqNum = i * 10; - raftArr[i].isWeak = i % 2; - } - - SyncClientRequestBatch *pMsg = syncClientRequestBatchBuild(rpcMsgPArr, raftArr, 5, 1234); - return pMsg; -} - -void test1() { - SyncClientRequestBatch *pMsg = createMsg(); - syncClientRequestBatchLog2((char *)"==test1==", pMsg); - syncClientRequestBatchDestroyDeep(pMsg); -} - -/* -void test2() { - SyncClientRequest *pMsg = createMsg(); - uint32_t len = pMsg->bytes; - char * serialized = (char *)taosMemoryMalloc(len); - syncClientRequestSerialize(pMsg, serialized, len); - SyncClientRequest *pMsg2 = syncClientRequestBuild(pMsg->dataLen); - syncClientRequestDeserialize(serialized, len, pMsg2); - syncClientRequestLog2((char *)"test2: syncClientRequestSerialize -> syncClientRequestDeserialize ", pMsg2); - - taosMemoryFree(serialized); - syncClientRequestDestroy(pMsg); - syncClientRequestDestroy(pMsg2); -} - -void test3() { - SyncClientRequest *pMsg = createMsg(); - uint32_t len; - char * serialized = syncClientRequestSerialize2(pMsg, &len); - SyncClientRequest *pMsg2 = syncClientRequestDeserialize2(serialized, len); - syncClientRequestLog2((char *)"test3: syncClientRequestSerialize3 -> syncClientRequestDeserialize2 ", pMsg2); - - taosMemoryFree(serialized); - syncClientRequestDestroy(pMsg); - syncClientRequestDestroy(pMsg2); -} - -void test4() { - SyncClientRequest *pMsg = createMsg(); - SRpcMsg rpcMsg; - syncClientRequest2RpcMsg(pMsg, &rpcMsg); - SyncClientRequest *pMsg2 = (SyncClientRequest *)taosMemoryMalloc(rpcMsg.contLen); - syncClientRequestFromRpcMsg(&rpcMsg, pMsg2); - syncClientRequestLog2((char *)"test4: syncClientRequest2RpcMsg -> syncClientRequestFromRpcMsg ", pMsg2); - - rpcFreeCont(rpcMsg.pCont); - syncClientRequestDestroy(pMsg); - syncClientRequestDestroy(pMsg2); -} - -void test5() { - SyncClientRequest *pMsg = createMsg(); - SRpcMsg rpcMsg; - syncClientRequest2RpcMsg(pMsg, &rpcMsg); - SyncClientRequest *pMsg2 = syncClientRequestFromRpcMsg2(&rpcMsg); - syncClientRequestLog2((char *)"test5: syncClientRequest2RpcMsg -> syncClientRequestFromRpcMsg2 ", pMsg2); - - rpcFreeCont(rpcMsg.pCont); - syncClientRequestDestroy(pMsg); - syncClientRequestDestroy(pMsg2); -} -*/ - -int main() { - gRaftDetailLog = true; - tsAsyncLog = 0; - sDebugFlag = DEBUG_DEBUG + DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE; - logTest(); - - test1(); - - /* -test2(); -test3(); -test4(); -test5(); -*/ - - return 0; -} diff --git a/source/libs/sync/test/syncClientRequestTest.cpp b/source/libs/sync/test/syncClientRequestTest.cpp deleted file mode 100644 index 56e53cc1c93bbb5d024797c47936d10bf8fa8a3b..0000000000000000000000000000000000000000 --- a/source/libs/sync/test/syncClientRequestTest.cpp +++ /dev/null @@ -1,98 +0,0 @@ -#include -#include -#include "syncIO.h" -#include "syncInt.h" -#include "syncMessage.h" -#include "syncUtil.h" - -void logTest() { - sTrace("--- sync log test: trace"); - sDebug("--- sync log test: debug"); - sInfo("--- sync log test: info"); - sWarn("--- sync log test: warn"); - sError("--- sync log test: error"); - sFatal("--- sync log test: fatal"); -} - -SyncClientRequest *createMsg() { - SRpcMsg rpcMsg; - memset(&rpcMsg, 0, sizeof(rpcMsg)); - rpcMsg.msgType = 12345; - rpcMsg.contLen = 20; - rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen); - strcpy((char *)rpcMsg.pCont, "hello rpc"); - SyncClientRequest *pMsg = syncClientRequestBuild2(&rpcMsg, 123, true, 1000); - rpcFreeCont(rpcMsg.pCont); - return pMsg; -} - -void test1() { - SyncClientRequest *pMsg = createMsg(); - syncClientRequestLog2((char *)"test1:", pMsg); - syncClientRequestDestroy(pMsg); -} - -void test2() { - SyncClientRequest *pMsg = createMsg(); - uint32_t len = pMsg->bytes; - char *serialized = (char *)taosMemoryMalloc(len); - syncClientRequestSerialize(pMsg, serialized, len); - SyncClientRequest *pMsg2 = syncClientRequestBuild(pMsg->dataLen); - syncClientRequestDeserialize(serialized, len, pMsg2); - syncClientRequestLog2((char *)"test2: syncClientRequestSerialize -> syncClientRequestDeserialize ", pMsg2); - - taosMemoryFree(serialized); - syncClientRequestDestroy(pMsg); - syncClientRequestDestroy(pMsg2); -} - -void test3() { - SyncClientRequest *pMsg = createMsg(); - uint32_t len; - char *serialized = syncClientRequestSerialize2(pMsg, &len); - SyncClientRequest *pMsg2 = syncClientRequestDeserialize2(serialized, len); - syncClientRequestLog2((char *)"test3: syncClientRequestSerialize3 -> syncClientRequestDeserialize2 ", pMsg2); - - taosMemoryFree(serialized); - syncClientRequestDestroy(pMsg); - syncClientRequestDestroy(pMsg2); -} - -void test4() { - SyncClientRequest *pMsg = createMsg(); - SRpcMsg rpcMsg; - syncClientRequest2RpcMsg(pMsg, &rpcMsg); - SyncClientRequest *pMsg2 = (SyncClientRequest *)taosMemoryMalloc(rpcMsg.contLen); - syncClientRequestFromRpcMsg(&rpcMsg, pMsg2); - syncClientRequestLog2((char *)"test4: syncClientRequest2RpcMsg -> syncClientRequestFromRpcMsg ", pMsg2); - - rpcFreeCont(rpcMsg.pCont); - syncClientRequestDestroy(pMsg); - syncClientRequestDestroy(pMsg2); -} - -void test5() { - SyncClientRequest *pMsg = createMsg(); - SRpcMsg rpcMsg; - syncClientRequest2RpcMsg(pMsg, &rpcMsg); - SyncClientRequest *pMsg2 = syncClientRequestFromRpcMsg2(&rpcMsg); - syncClientRequestLog2((char *)"test5: syncClientRequest2RpcMsg -> syncClientRequestFromRpcMsg2 ", pMsg2); - - rpcFreeCont(rpcMsg.pCont); - syncClientRequestDestroy(pMsg); - syncClientRequestDestroy(pMsg2); -} - -int main() { - tsAsyncLog = 0; - sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE; - logTest(); - - test1(); - test2(); - test3(); - test4(); - test5(); - - return 0; -} diff --git a/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp b/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp index 95677e592bb7a4d16f9e7670c5bc4d77ab5a6538..dcf7249d30abd5c012715ddb7f7f464988108128 100644 --- a/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp +++ b/source/libs/sync/test/syncConfigChangeSnapshotTest.cpp @@ -47,8 +47,8 @@ void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { snprintf(logBuf, sizeof(logBuf), "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s, flag:%" PRIu64 ", term:%" PRIu64 " \n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), - cbMeta.flag, cbMeta.term); + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state), cbMeta.flag, + cbMeta.term); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } else { sTrace("==callback== ==CommitCb== do not apply again %" PRId64, cbMeta.index); @@ -57,10 +57,10 @@ void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { void PreCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256] = {0}; - snprintf( - logBuf, sizeof(logBuf), - "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag); + snprintf(logBuf, sizeof(logBuf), + "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 + "\n", + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state), cbMeta.flag); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } @@ -68,8 +68,7 @@ void RollBackCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), - cbMeta.flag); + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state), cbMeta.flag); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } @@ -158,6 +157,7 @@ SSyncFSM* createFsm() { SSyncFSM* pFsm = (SSyncFSM*)taosMemoryMalloc(sizeof(SSyncFSM)); memset(pFsm, 0, sizeof(*pFsm)); +#if 0 pFsm->FpCommitCb = CommitCb; pFsm->FpPreCommitCb = PreCommitCb; pFsm->FpRollBackCb = RollBackCb; @@ -172,6 +172,7 @@ SSyncFSM* createFsm() { pFsm->FpSnapshotDoWrite = SnapshotDoWrite; pFsm->FpReConfigCb = ReConfigCb; +#endif return pFsm; } @@ -195,8 +196,8 @@ int64_t createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWal* SSyncInfo syncInfo; syncInfo.vgId = vgId; syncInfo.msgcb = &gSyncIO->msgcb; - syncInfo.FpSendMsg = syncIOSendMsg; - syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.syncSendMSg = syncIOSendMsg; + syncInfo.syncEqMsg = syncIOEqMsg; syncInfo.pFsm = createFsm(); snprintf(syncInfo.path, sizeof(syncInfo.path), "%s_sync_replica%d_index%d", path, replicaNum, myIndex); syncInfo.pWal = pWal; @@ -270,7 +271,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) { pMsg->msgType = 9999; pMsg->contLen = 256; pMsg->pCont = rpcMallocCont(pMsg->contLen); - snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count, + snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-%" PRId64, myIndex, i, count, taosGetTimestampMs()); return pMsg; } diff --git a/source/libs/sync/test/syncConfigChangeTest.cpp b/source/libs/sync/test/syncConfigChangeTest.cpp index c04ab9b000e1f595d03838e36e555eff9541c08f..c5548d25d45c2974016ff1622429db8b62f086fe 100644 --- a/source/libs/sync/test/syncConfigChangeTest.cpp +++ b/source/libs/sync/test/syncConfigChangeTest.cpp @@ -33,7 +33,7 @@ void init() { void cleanup() { walCleanUp(); } -void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { +void CommitCb(const struct SSyncFSM* pFsm, const SRpcMsg* pMsg, const SFsmCbMeta cbMeta) { SyncIndex beginIndex = SYNC_INDEX_INVALID; if (pFsm->FpGetSnapshotInfo != NULL) { SSnapshot snapshot; @@ -45,33 +45,31 @@ void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256] = {0}; snprintf(logBuf, sizeof(logBuf), "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), - cbMeta.flag); + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state), cbMeta.flag); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } else { sTrace("==callback== ==CommitCb== do not apply again %" PRId64, cbMeta.index); } } -void PreCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { +void PreCommitCb(const struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256] = {0}; - snprintf( - logBuf, sizeof(logBuf), - "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), cbMeta.flag); + snprintf(logBuf, sizeof(logBuf), + "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 + "\n", + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state), cbMeta.flag); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } -void RollBackCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { +void RollBackCb(const struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s flag:%" PRIu64 "\n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), - cbMeta.flag); + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state), cbMeta.flag); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } -int32_t GetSnapshotCb(struct SSyncFSM* pFsm, SSnapshot* pSnapshot) { +int32_t GetSnapshotCb(const struct SSyncFSM* pFsm, SSnapshot* pSnapshot) { pSnapshot->data = NULL; pSnapshot->lastApplyIndex = gSnapshotLastApplyIndex; pSnapshot->lastApplyTerm = 100; @@ -89,6 +87,7 @@ SSyncFSM* createFsm() { SSyncFSM* pFsm = (SSyncFSM*)taosMemoryMalloc(sizeof(SSyncFSM)); memset(pFsm, 0, sizeof(*pFsm)); +#if 0 pFsm->FpCommitCb = CommitCb; pFsm->FpPreCommitCb = PreCommitCb; pFsm->FpRollBackCb = RollBackCb; @@ -97,6 +96,7 @@ SSyncFSM* createFsm() { pFsm->FpRestoreFinishCb = RestoreFinishCb; pFsm->FpReConfigCb = ReConfigCb; +#endif return pFsm; } @@ -120,8 +120,8 @@ int64_t createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWal* SSyncInfo syncInfo; syncInfo.vgId = vgId; syncInfo.msgcb = &gSyncIO->msgcb; - syncInfo.FpSendMsg = syncIOSendMsg; - syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.syncSendMSg = syncIOSendMsg; + syncInfo.syncEqMsg = syncIOEqMsg; syncInfo.pFsm = createFsm(); snprintf(syncInfo.path, sizeof(syncInfo.path), "%s_sync_replica%d_index%d", path, replicaNum, myIndex); syncInfo.pWal = pWal; @@ -191,7 +191,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) { pMsg->msgType = 9999; pMsg->contLen = 256; pMsg->pCont = rpcMallocCont(pMsg->contLen); - snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count, + snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-%" PRId64, myIndex, i, count, taosGetTimestampMs()); return pMsg; } diff --git a/source/libs/sync/test/syncElectTest.cpp b/source/libs/sync/test/syncElectTest.cpp index 862f7bd0baebed56d2e103c56ae1a88e9074c8ea..5cdbb2cc8875c9cc845c7e1b84816af4c0aaf2e2 100644 --- a/source/libs/sync/test/syncElectTest.cpp +++ b/source/libs/sync/test/syncElectTest.cpp @@ -45,8 +45,8 @@ SSyncNode* createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWa SSyncInfo syncInfo; syncInfo.vgId = vgId; syncInfo.msgcb = &gSyncIO->msgcb; - syncInfo.FpSendMsg = syncIOSendMsg; - syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.syncSendMSg = syncIOSendMsg; + syncInfo.syncEqMsg = syncIOEqMsg; syncInfo.pFsm = NULL; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s_sync_replica%d_index%d", path, replicaNum, myIndex); syncInfo.pWal = pWal; @@ -98,7 +98,7 @@ int main(int argc, char** argv) { init(); int32_t ret = syncIOStart((char*)"127.0.0.1", gPorts[myIndex]); assert(ret == 0); - ret = syncEnvStart(); + ret = syncInit(); assert(ret == 0); char walPath[128]; @@ -107,7 +107,7 @@ int main(int argc, char** argv) { SSyncNode* pSyncNode = createSyncNode(replicaNum, myIndex, gVgId, pWal, (char*)gDir); assert(pSyncNode != NULL); - syncNodeLog2((char*)"==syncElectTest==", pSyncNode); + sNTrace(pSyncNode, "==syncElectTest=="); //--------------------------- while (1) { diff --git a/source/libs/sync/test/syncEncodeTest.cpp b/source/libs/sync/test/syncEncodeTest.cpp index 8b209c4c9ef6e9f2951c5ca28abedd434459bd89..216291c1d897a3eeaad8b13be503a81511e41b05 100644 --- a/source/libs/sync/test/syncEncodeTest.cpp +++ b/source/libs/sync/test/syncEncodeTest.cpp @@ -7,9 +7,11 @@ #include "syncRaftEntry.h" #include "syncRaftLog.h" #include "syncRaftStore.h" +#include "syncTest.h" #include "syncUtil.h" #include "wal.h" +#if 0 void logTest() { sTrace("--- sync log test: trace"); sDebug("--- sync log test: debug"); @@ -32,8 +34,8 @@ SSyncNode *pSyncNode; SSyncNode *syncNodeInit() { syncInfo.vgId = 1234; syncInfo.msgcb = &gSyncIO->msgcb; - syncInfo.FpSendMsg = syncIOSendMsg; - syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.syncSendMSg = syncIOSendMsg; + syncInfo.syncEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./"); @@ -102,12 +104,12 @@ SRpcMsg *step0() { } SyncClientRequest *step1(const SRpcMsg *pMsg) { - SyncClientRequest *pRetMsg = syncClientRequestBuild2(pMsg, 123, true, 1000); + SyncClientRequest *pRetMsg = syncClientRequestBuild(pMsg, 123, true, 1000); return pRetMsg; } SRpcMsg *step2(const SyncClientRequest *pMsg) { - SRpcMsg *pRetMsg = (SRpcMsg *)taosMemoryMalloc(sizeof(SRpcMsg)); + SRpcMsg *pRetMsg = (SRpcMsg *)taosMemoryCalloc(sizeof(SRpcMsg), 1); syncClientRequest2RpcMsg(pMsg, pRetMsg); return pRetMsg; } @@ -118,17 +120,7 @@ SyncClientRequest *step3(const SRpcMsg *pMsg) { } SSyncRaftEntry *step4(const SyncClientRequest *pMsg) { - SSyncRaftEntry *pRetMsg = syncEntryBuild2((SyncClientRequest *)pMsg, 100, 0); - return pRetMsg; -} - -char *step5(const SSyncRaftEntry *pMsg, uint32_t *len) { - char *pRetMsg = syncEntrySerialize(pMsg, len); - return pRetMsg; -} - -SSyncRaftEntry *step6(const char *pMsg, uint32_t len) { - SSyncRaftEntry *pRetMsg = syncEntryDeserialize(pMsg, len); + SSyncRaftEntry *pRetMsg = syncEntryBuildFromClientRequest((SyncClientRequest *)pMsg, 100, 0); return pRetMsg; } @@ -137,13 +129,14 @@ SRpcMsg *step7(const SSyncRaftEntry *pMsg) { syncEntry2OriginalRpc(pMsg, pRetMsg); return pRetMsg; } - +#endif int main(int argc, char **argv) { // taosInitLog((char *)"syncTest.log", 100000, 10); tsAsyncLog = 0; sDebugFlag = 143 + 64; void logTest(); +#if 0 myIndex = 0; if (argc >= 2) { myIndex = atoi(argv[1]); @@ -152,7 +145,7 @@ int main(int argc, char **argv) { int32_t ret = syncIOStart((char *)"127.0.0.1", ports[myIndex]); assert(ret == 0); - ret = syncEnvStart(); + ret = syncInit(); assert(ret == 0); taosRemoveDir("./wal_test"); @@ -186,22 +179,11 @@ int main(int argc, char **argv) { int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, pEntry->index, &pEntry); ASSERT(code == 0); - syncEntryLog2((char *)"==pEntry2==", pEntry2); - - // step5 - uint32_t len; - char *pMsg5 = step5(pMsg4, &len); - char *s = syncUtilprintBin(pMsg5, len); - printf("==step5== [%s] \n", s); - taosMemoryFree(s); - - // step6 - SSyncRaftEntry *pMsg6 = step6(pMsg5, len); - syncEntryLog2((char *)"==step6==", pMsg6); + syncEntryLog2((char *)"==pEntry==", pEntry); // step7 SRpcMsg *pMsg7 = step7(pMsg6); syncRpcMsgLog2((char *)"==step7==", pMsg7); - +#endif return 0; } diff --git a/source/libs/sync/test/syncEnqTest.cpp b/source/libs/sync/test/syncEnqTest.cpp index 8461bfe9b7403c70d45a79f59474ad5d0ca43b2a..bb5f968dc6a84ed4607c10b7f674dcd83cdb7fa9 100644 --- a/source/libs/sync/test/syncEnqTest.cpp +++ b/source/libs/sync/test/syncEnqTest.cpp @@ -25,8 +25,8 @@ SSyncFSM* pFsm; SSyncNode* syncNodeInit() { syncInfo.vgId = 1234; - syncInfo.FpSendMsg = syncIOSendMsg; - syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.syncSendMSg = syncIOSendMsg; + syncInfo.syncEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./"); @@ -81,13 +81,13 @@ int main(int argc, char** argv) { int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]); assert(ret == 0); - ret = syncEnvStart(); + ret = syncInit(); assert(ret == 0); SSyncNode* pSyncNode = syncInitTest(); assert(pSyncNode != NULL); - syncNodeLog2((char*)"syncInitTest", pSyncNode); + sNTrace(pSyncNode, "syncInitTest"); initRaftId(pSyncNode); @@ -97,7 +97,7 @@ int main(int argc, char** argv) { SyncPingReply* pSyncMsg = syncPingReplyBuild2(&pSyncNode->myRaftId, &pSyncNode->myRaftId, 1000, "syncEnqTest"); SRpcMsg rpcMsg; syncPingReply2RpcMsg(pSyncMsg, &rpcMsg); - pSyncNode->FpEqMsg(pSyncNode->msgcb, &rpcMsg); + pSyncNode->syncEqMsg(pSyncNode->msgcb, &rpcMsg); taosMsleep(1000); } diff --git a/source/libs/sync/test/syncEntryCacheTest.cpp b/source/libs/sync/test/syncEntryCacheTest.cpp index 3ee28ce96b00e0722402af586bdad30269af8e31..56b3d6da2e5bb7baea5253207c4dc52d9672b2db 100644 --- a/source/libs/sync/test/syncEntryCacheTest.cpp +++ b/source/libs/sync/test/syncEntryCacheTest.cpp @@ -7,6 +7,7 @@ #include "syncUtil.h" #include "tref.h" #include "tskiplist.h" +#include "syncTest.h" void logTest() { sTrace("--- sync log test: trace"); diff --git a/source/libs/sync/test/syncEntryTest.cpp b/source/libs/sync/test/syncEntryTest.cpp index 53ae91fc60a1876b81402031a76866f861f0cdeb..e94755195b97088a6d396ee08563454576c0c187 100644 --- a/source/libs/sync/test/syncEntryTest.cpp +++ b/source/libs/sync/test/syncEntryTest.cpp @@ -6,6 +6,7 @@ #include "syncRaftLog.h" #include "syncRaftStore.h" #include "syncUtil.h" +#include "syncTest.h" void logTest() { sTrace("--- sync log test: trace"); @@ -32,30 +33,30 @@ void test1() { } void test2() { - SyncClientRequest* pSyncMsg = syncClientRequestBuild(10); + SyncClientRequest* pSyncMsg = syncClientRequestAlloc(10); pSyncMsg->originalRpcType = 33; pSyncMsg->seqNum = 11; pSyncMsg->isWeak = 1; strcpy(pSyncMsg->data, "test2"); - SSyncRaftEntry* pEntry = syncEntryBuild2(pSyncMsg, 100, 200); + SSyncRaftEntry* pEntry = syncEntryBuildFromClientRequest(pSyncMsg, 100, 200); syncEntryPrint(pEntry); - syncClientRequestDestroy(pSyncMsg); + taosMemoryFree(pSyncMsg); syncEntryDestory(pEntry); } void test3() { - SyncClientRequest* pSyncMsg = syncClientRequestBuild(10); + SyncClientRequest* pSyncMsg = syncClientRequestAlloc(10); pSyncMsg->originalRpcType = 33; pSyncMsg->seqNum = 11; pSyncMsg->isWeak = 1; strcpy(pSyncMsg->data, "test3"); - SSyncRaftEntry* pEntry = syncEntryBuild3(pSyncMsg, 100, 200); + SSyncRaftEntry* pEntry = syncEntryBuildFromClientRequest(pSyncMsg, 100, 200); syncEntryPrint(pEntry); - syncClientRequestDestroy(pSyncMsg); + taosMemoryFree(pSyncMsg); syncEntryDestory(pEntry); } @@ -71,14 +72,7 @@ void test4() { strcpy(pEntry->data, "test4"); syncEntryPrint(pEntry); - uint32_t len; - char* serialized = syncEntrySerialize(pEntry, &len); - assert(serialized != NULL); - SSyncRaftEntry* pEntry2 = syncEntryDeserialize(serialized, len); - syncEntryPrint(pEntry2); - - taosMemoryFree(serialized); - syncEntryDestory(pEntry2); + // syncEntryDestory(pEntry2); syncEntryDestory(pEntry); } diff --git a/source/libs/sync/test/syncEnvTest.cpp b/source/libs/sync/test/syncEnvTest.cpp index a7a819e0465b34de466c132934bc2b4c209b2fd1..a220c2aed4bf0c3cb815f5ee8a646d94f3999d07 100644 --- a/source/libs/sync/test/syncEnvTest.cpp +++ b/source/libs/sync/test/syncEnvTest.cpp @@ -22,23 +22,21 @@ int main() { logTest(); - ret = syncEnvStart(); + ret = syncInit(); assert(ret == 0); for (int i = 0; i < 5; ++i) { - ret = syncEnvStartTimer(); + //ret = syncEnvStartTimer(); assert(ret == 0); taosMsleep(5000); - ret = syncEnvStopTimer(); + //ret = syncEnvStopTimer(); assert(ret == 0); taosMsleep(5000); } - ret = syncEnvStop(); - assert(ret == 0); - + syncCleanUp(); return 0; } diff --git a/source/libs/sync/test/syncHashCacheTest.cpp b/source/libs/sync/test/syncHashCacheTest.cpp index 7d822971da61462a7f9f65321bb2e72103fa3c27..2f5bb07f9a58fc8fe866eb177f5f009d1103c520 100644 --- a/source/libs/sync/test/syncHashCacheTest.cpp +++ b/source/libs/sync/test/syncHashCacheTest.cpp @@ -4,6 +4,7 @@ #include "syncInt.h" #include "syncRaftLog.h" #include "syncRaftStore.h" +#include "syncTest.h" #include "syncUtil.h" #include "tskiplist.h" diff --git a/source/libs/sync/test/syncIOSendMsgTest.cpp b/source/libs/sync/test/syncIOSendMsgTest.cpp index 630d96054bef043134b76233683551abe682bd6c..f88e4f240d09ade214a0f91d69934af4a25a4af0 100644 --- a/source/libs/sync/test/syncIOSendMsgTest.cpp +++ b/source/libs/sync/test/syncIOSendMsgTest.cpp @@ -26,8 +26,8 @@ SSyncFSM* pFsm; SSyncNode* syncNodeInit() { syncInfo.vgId = 1234; syncInfo.msgcb = &gSyncIO->msgcb; - syncInfo.FpSendMsg = syncIOSendMsg; - syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.syncSendMSg = syncIOSendMsg; + syncInfo.syncEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./"); @@ -82,13 +82,13 @@ int main(int argc, char** argv) { int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]); assert(ret == 0); - ret = syncEnvStart(); + ret = syncInit(); assert(ret == 0); SSyncNode* pSyncNode = syncInitTest(); assert(pSyncNode != NULL); - syncNodeLog2((char*)"syncInitTest", pSyncNode); + sNTrace(pSyncNode, "syncInitTest"); initRaftId(pSyncNode); @@ -103,7 +103,7 @@ int main(int argc, char** argv) { SEpSet epSet; syncUtilnodeInfo2EpSet(&pSyncNode->myNodeInfo, &epSet); rpcMsg.info.noResp = 1; - pSyncNode->FpSendMsg(&epSet, &rpcMsg); + pSyncNode->syncSendMSg(&epSet, &rpcMsg); taosMsleep(1000); } diff --git a/source/libs/sync/test/syncIndexTest.cpp b/source/libs/sync/test/syncIndexTest.cpp index 93cd5f79f07ab5da62f0255b2b7409b43547b9a3..763117c0c9cf04d97bffd89b010a87984042fc51 100644 --- a/source/libs/sync/test/syncIndexTest.cpp +++ b/source/libs/sync/test/syncIndexTest.cpp @@ -13,7 +13,7 @@ void print(SHashObj *pNextIndex) { SRaftId *pRaftId = (SRaftId *)key; - printf("key:<" PRIu64 ", %d>, value:%" PRIu64 " \n", pRaftId->addr, pRaftId->vgId, *p); + printf("key:<%" PRIu64 ", %d>, value:%" PRIu64 " \n", pRaftId->addr, pRaftId->vgId, *p); p = (uint64_t *)taosHashIterate(pNextIndex, p); } } diff --git a/source/libs/sync/test/syncInitTest.cpp b/source/libs/sync/test/syncInitTest.cpp index d0843151f4b3b04c2c67d44b4cdce3a48e78d6d8..2fe5dd7e18e76559a95154b93bbbbe0d9c95ee5c 100644 --- a/source/libs/sync/test/syncInitTest.cpp +++ b/source/libs/sync/test/syncInitTest.cpp @@ -26,8 +26,8 @@ SSyncFSM* pFsm; SSyncNode* syncNodeInit() { syncInfo.vgId = 1234; syncInfo.msgcb = &gSyncIO->msgcb; - syncInfo.FpSendMsg = syncIOSendMsg; - syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.syncSendMSg = syncIOSendMsg; + syncInfo.syncEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./sync_init_test"); @@ -81,17 +81,17 @@ int main(int argc, char** argv) { int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]); assert(ret == 0); - ret = syncEnvStart(); + ret = syncInit(); assert(ret == 0); SSyncNode* pSyncNode = syncInitTest(); assert(pSyncNode != NULL); - syncNodeLog2((char*)"syncInitTest", pSyncNode); + sNTrace(pSyncNode, "syncInitTest"); initRaftId(pSyncNode); syncNodeClose(pSyncNode); - syncEnvStop(); + syncCleanUp(); // syncIOStop(); // taosCloseLog(); diff --git a/source/libs/sync/test/syncLeaderTransferTest.cpp b/source/libs/sync/test/syncLeaderTransferTest.cpp index 62a9106c159123545f412d7040619af64c5a7ef2..bd1f22edffd80eb6b65f7afec50f30417e81c2df 100644 --- a/source/libs/sync/test/syncLeaderTransferTest.cpp +++ b/source/libs/sync/test/syncLeaderTransferTest.cpp @@ -27,6 +27,35 @@ SyncLeaderTransfer *createMsg() { return pMsg; } +// for debug ---------------------- +void syncLeaderTransferPrint(const SyncLeaderTransfer *pMsg) { + char *serialized = syncLeaderTransfer2Str(pMsg); + printf("syncLeaderTransferPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void syncLeaderTransferPrint2(char *s, const SyncLeaderTransfer *pMsg) { + char *serialized = syncLeaderTransfer2Str(pMsg); + printf("syncLeaderTransferPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void syncLeaderTransferLog(const SyncLeaderTransfer *pMsg) { + char *serialized = syncLeaderTransfer2Str(pMsg); + sTrace("syncLeaderTransferLog | len:%d | %s", (int32_t)strlen(serialized), serialized); + taosMemoryFree(serialized); +} + +void syncLeaderTransferLog2(char *s, const SyncLeaderTransfer *pMsg) { + if (gRaftDetailLog) { + char *serialized = syncLeaderTransfer2Str(pMsg); + sTrace("syncLeaderTransferLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); + taosMemoryFree(serialized); + } +} + void test1() { SyncLeaderTransfer *pMsg = createMsg(); syncLeaderTransferLog2((char *)"test1:", pMsg); diff --git a/source/libs/sync/test/syncLocalCmdTest.cpp b/source/libs/sync/test/syncLocalCmdTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b42626df29cfdf01b70a512c573daaf922d40f4a --- /dev/null +++ b/source/libs/sync/test/syncLocalCmdTest.cpp @@ -0,0 +1,101 @@ +#include +#include +#include "syncIO.h" +#include "syncInt.h" +#include "syncMessage.h" +#include "syncUtil.h" + +void logTest() { + sTrace("--- sync log test: trace"); + sDebug("--- sync log test: debug"); + sInfo("--- sync log test: info"); + sWarn("--- sync log test: warn"); + sError("--- sync log test: error"); + sFatal("--- sync log test: fatal"); +} + +SyncLocalCmd *createMsg() { + SyncLocalCmd *pMsg = syncLocalCmdBuild(1000); + pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234); + pMsg->srcId.vgId = 100; + pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678); + pMsg->destId.vgId = 100; + pMsg->sdNewTerm = 123; + pMsg->fcIndex = 456; + pMsg->cmd = SYNC_LOCAL_CMD_STEP_DOWN; + + return pMsg; +} + +void test1() { + SyncLocalCmd *pMsg = createMsg(); + syncLocalCmdLog2((char *)"test1:", pMsg); + syncLocalCmdDestroy(pMsg); +} + +void test2() { + SyncLocalCmd *pMsg = createMsg(); + uint32_t len = pMsg->bytes; + char *serialized = (char *)taosMemoryMalloc(len); + syncLocalCmdSerialize(pMsg, serialized, len); + SyncLocalCmd *pMsg2 = syncLocalCmdBuild(1000); + syncLocalCmdDeserialize(serialized, len, pMsg2); + syncLocalCmdLog2((char *)"test2: syncLocalCmdSerialize -> syncLocalCmdDeserialize ", pMsg2); + + taosMemoryFree(serialized); + syncLocalCmdDestroy(pMsg); + syncLocalCmdDestroy(pMsg2); +} + +void test3() { + SyncLocalCmd *pMsg = createMsg(); + uint32_t len; + char *serialized = syncLocalCmdSerialize2(pMsg, &len); + SyncLocalCmd *pMsg2 = syncLocalCmdDeserialize2(serialized, len); + syncLocalCmdLog2((char *)"test3: syncLocalCmdSerialize3 -> syncLocalCmdDeserialize2 ", pMsg2); + + taosMemoryFree(serialized); + syncLocalCmdDestroy(pMsg); + syncLocalCmdDestroy(pMsg2); +} + +void test4() { + SyncLocalCmd *pMsg = createMsg(); + SRpcMsg rpcMsg; + syncLocalCmd2RpcMsg(pMsg, &rpcMsg); + SyncLocalCmd *pMsg2 = (SyncLocalCmd *)taosMemoryMalloc(rpcMsg.contLen); + syncLocalCmdFromRpcMsg(&rpcMsg, pMsg2); + syncLocalCmdLog2((char *)"test4: syncLocalCmd2RpcMsg -> syncLocalCmdFromRpcMsg ", pMsg2); + + rpcFreeCont(rpcMsg.pCont); + syncLocalCmdDestroy(pMsg); + syncLocalCmdDestroy(pMsg2); +} + +void test5() { + SyncLocalCmd *pMsg = createMsg(); + SRpcMsg rpcMsg; + syncLocalCmd2RpcMsg(pMsg, &rpcMsg); + SyncLocalCmd *pMsg2 = syncLocalCmdFromRpcMsg2(&rpcMsg); + syncLocalCmdLog2((char *)"test5: syncLocalCmd2RpcMsg -> syncLocalCmdFromRpcMsg2 ", pMsg2); + + rpcFreeCont(rpcMsg.pCont); + syncLocalCmdDestroy(pMsg); + syncLocalCmdDestroy(pMsg2); +} + +int main() { + gRaftDetailLog = true; + + tsAsyncLog = 0; + sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE; + logTest(); + + test1(); + test2(); + test3(); + test4(); + test5(); + + return 0; +} diff --git a/source/libs/sync/test/syncLogStoreCheck.cpp b/source/libs/sync/test/syncLogStoreCheck.cpp index 431b291ca797847a00556f5aeb6d231f48061dc6..0161160a75d5e2f5f9b116b10a2d4cbd7b64a36f 100644 --- a/source/libs/sync/test/syncLogStoreCheck.cpp +++ b/source/libs/sync/test/syncLogStoreCheck.cpp @@ -5,6 +5,7 @@ #include "syncInt.h" #include "syncRaftLog.h" #include "syncRaftStore.h" +#include "syncTest.h" #include "syncUtil.h" #include "wal.h" diff --git a/source/libs/sync/test/syncLogStoreCheck2.cpp b/source/libs/sync/test/syncLogStoreCheck2.cpp index 80679bc85c4067fef291dcc583b727f1f3e909c3..29ad0610e7d8b23594cbd932a85bf60dd7488cf8 100644 --- a/source/libs/sync/test/syncLogStoreCheck2.cpp +++ b/source/libs/sync/test/syncLogStoreCheck2.cpp @@ -7,6 +7,7 @@ #include "syncRaftStore.h" #include "syncUtil.h" #include "wal.h" +#include "syncTest.h" void logTest() { sTrace("--- sync log test: trace"); diff --git a/source/libs/sync/test/syncLogStoreTest.cpp b/source/libs/sync/test/syncLogStoreTest.cpp index 9ff0ed208957efc55ad66733d5a1543f44ef795e..832b42bf806280aac04b1116d27dc534012faae8 100644 --- a/source/libs/sync/test/syncLogStoreTest.cpp +++ b/source/libs/sync/test/syncLogStoreTest.cpp @@ -5,6 +5,7 @@ #include "syncInt.h" #include "syncRaftLog.h" #include "syncRaftStore.h" +#include "syncTest.h" #include "syncUtil.h" #include "wal.h" diff --git a/source/libs/sync/test/syncPingSelfTest.cpp b/source/libs/sync/test/syncPingSelfTest.cpp index 99287bf7b0fd23c350e7d5f8503b17efee641b7e..781ffc31db8007927e0483242e146105d7a3d69e 100644 --- a/source/libs/sync/test/syncPingSelfTest.cpp +++ b/source/libs/sync/test/syncPingSelfTest.cpp @@ -26,8 +26,8 @@ SSyncFSM* pFsm; SSyncNode* syncNodeInit() { syncInfo.vgId = 1234; syncInfo.msgcb = &gSyncIO->msgcb; - syncInfo.FpSendMsg = syncIOSendMsg; - syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.syncSendMSg = syncIOSendMsg; + syncInfo.syncEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./"); @@ -81,12 +81,12 @@ int main(int argc, char** argv) { int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]); assert(ret == 0); - ret = syncEnvStart(); + ret = syncInit(); assert(ret == 0); SSyncNode* pSyncNode = syncInitTest(); assert(pSyncNode != NULL); - syncNodeLog2((char*)"", pSyncNode); + sNTrace(pSyncNode, ""); initRaftId(pSyncNode); diff --git a/source/libs/sync/test/syncPingTimerTest.cpp b/source/libs/sync/test/syncPingTimerTest.cpp index cd9440e3e280b71820ca5db8ed40bcc8b2c37d26..5a0b5e9953da2f192094106bfca339e121ccfd79 100644 --- a/source/libs/sync/test/syncPingTimerTest.cpp +++ b/source/libs/sync/test/syncPingTimerTest.cpp @@ -26,8 +26,8 @@ SSyncFSM* pFsm; SSyncNode* syncNodeInit() { syncInfo.vgId = 1234; syncInfo.msgcb = &gSyncIO->msgcb; - syncInfo.FpSendMsg = syncIOSendMsg; - syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.syncSendMSg = syncIOSendMsg; + syncInfo.syncEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./"); @@ -81,12 +81,12 @@ int main(int argc, char** argv) { int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]); assert(ret == 0); - ret = syncEnvStart(); + ret = syncInit(); assert(ret == 0); SSyncNode* pSyncNode = syncInitTest(); assert(pSyncNode != NULL); - syncNodeLog2((char*)"----1", pSyncNode); + sNTrace(pSyncNode, "----1"); initRaftId(pSyncNode); @@ -95,7 +95,7 @@ int main(int argc, char** argv) { sTrace("syncNodeStartPingTimer ..."); ret = syncNodeStartPingTimer(pSyncNode); assert(ret == 0); - syncNodeLog2((char*)"----2", pSyncNode); + sNTrace(pSyncNode, "----2"); sTrace("sleep ..."); taosMsleep(10000); @@ -103,7 +103,7 @@ int main(int argc, char** argv) { sTrace("syncNodeStopPingTimer ..."); ret = syncNodeStopPingTimer(pSyncNode); assert(ret == 0); - syncNodeLog2((char*)"----3", pSyncNode); + sNTrace(pSyncNode, "----3"); sTrace("sleep ..."); taosMsleep(5000); @@ -111,7 +111,7 @@ int main(int argc, char** argv) { sTrace("syncNodeStartPingTimer ..."); ret = syncNodeStartPingTimer(pSyncNode); assert(ret == 0); - syncNodeLog2((char*)"----4", pSyncNode); + sNTrace(pSyncNode, "----4"); sTrace("sleep ..."); taosMsleep(10000); @@ -119,7 +119,7 @@ int main(int argc, char** argv) { sTrace("syncNodeStopPingTimer ..."); ret = syncNodeStopPingTimer(pSyncNode); assert(ret == 0); - syncNodeLog2((char*)"----5", pSyncNode); + sNTrace(pSyncNode, "----5"); while (1) { sTrace("while 1 sleep ..."); diff --git a/source/libs/sync/test/syncPingTimerTest2.cpp b/source/libs/sync/test/syncPingTimerTest2.cpp index fa09d04368178e7b7ab6c94cd53c7672174bdf7b..09f56815cd848d1252116efbcb67eaf46fb9d93c 100644 --- a/source/libs/sync/test/syncPingTimerTest2.cpp +++ b/source/libs/sync/test/syncPingTimerTest2.cpp @@ -26,8 +26,8 @@ SSyncFSM* pFsm; SSyncNode* syncNodeInit() { syncInfo.vgId = 1234; syncInfo.msgcb = &gSyncIO->msgcb; - syncInfo.FpSendMsg = syncIOSendMsg; - syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.syncSendMSg = syncIOSendMsg; + syncInfo.syncEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./"); @@ -81,12 +81,12 @@ int main(int argc, char** argv) { int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]); assert(ret == 0); - ret = syncEnvStart(); + ret = syncInit(); assert(ret == 0); SSyncNode* pSyncNode = syncInitTest(); assert(pSyncNode != NULL); - syncNodeLog2((char*)"", pSyncNode); + sNTrace(pSyncNode, ""); initRaftId(pSyncNode); diff --git a/source/libs/sync/test/syncPreSnapshotReplyTest.cpp b/source/libs/sync/test/syncPreSnapshotReplyTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a30dcc2c545640a7bfe181727465a922107713a5 --- /dev/null +++ b/source/libs/sync/test/syncPreSnapshotReplyTest.cpp @@ -0,0 +1,99 @@ + +#include +#include +#include "syncIO.h" +#include "syncInt.h" +#include "syncMessage.h" +#include "syncUtil.h" + +void logTest() { + sTrace("--- sync log test: trace"); + sDebug("--- sync log test: debug"); + sInfo("--- sync log test: info"); + sWarn("--- sync log test: warn"); + sError("--- sync log test: error"); + sFatal("--- sync log test: fatal"); +} + +SyncPreSnapshotReply *createMsg() { + SyncPreSnapshotReply *pMsg = syncPreSnapshotReplyBuild(789); + pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234); + pMsg->srcId.vgId = 100; + pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678); + pMsg->destId.vgId = 100; + pMsg->term = 9527; + pMsg->snapStart = 12306; + return pMsg; +} + +void test1() { + SyncPreSnapshotReply *pMsg = createMsg(); + syncPreSnapshotReplyLog2((char *)"test1:", pMsg); + syncPreSnapshotReplyDestroy(pMsg); +} + +void test2() { + SyncPreSnapshotReply *pMsg = createMsg(); + uint32_t len = pMsg->bytes; + char * serialized = (char *)taosMemoryMalloc(len); + syncPreSnapshotReplySerialize(pMsg, serialized, len); + SyncPreSnapshotReply *pMsg2 = syncPreSnapshotReplyBuild(789); + syncPreSnapshotReplyDeserialize(serialized, len, pMsg2); + syncPreSnapshotReplyLog2((char *)"test2: syncPreSnapshotReplySerialize -> syncPreSnapshotReplyDeserialize ", pMsg2); + + taosMemoryFree(serialized); + syncPreSnapshotReplyDestroy(pMsg); + syncPreSnapshotReplyDestroy(pMsg2); +} + +void test3() { + SyncPreSnapshotReply *pMsg = createMsg(); + uint32_t len; + char * serialized = syncPreSnapshotReplySerialize2(pMsg, &len); + SyncPreSnapshotReply *pMsg2 = syncPreSnapshotReplyDeserialize2(serialized, len); + syncPreSnapshotReplyLog2((char *)"test3: syncPreSnapshotReplySerialize2 -> syncPreSnapshotReplyDeserialize2 ", pMsg2); + + taosMemoryFree(serialized); + syncPreSnapshotReplyDestroy(pMsg); + syncPreSnapshotReplyDestroy(pMsg2); +} + +void test4() { + SyncPreSnapshotReply *pMsg = createMsg(); + SRpcMsg rpcMsg; + syncPreSnapshotReply2RpcMsg(pMsg, &rpcMsg); + SyncPreSnapshotReply *pMsg2 = (SyncPreSnapshotReply *)taosMemoryMalloc(rpcMsg.contLen); + syncPreSnapshotReplyFromRpcMsg(&rpcMsg, pMsg2); + syncPreSnapshotReplyLog2((char *)"test4: syncPreSnapshotReply2RpcMsg -> syncPreSnapshotReplyFromRpcMsg ", pMsg2); + + rpcFreeCont(rpcMsg.pCont); + syncPreSnapshotReplyDestroy(pMsg); + syncPreSnapshotReplyDestroy(pMsg2); +} + +void test5() { + SyncPreSnapshotReply *pMsg = createMsg(); + SRpcMsg rpcMsg; + syncPreSnapshotReply2RpcMsg(pMsg, &rpcMsg); + SyncPreSnapshotReply *pMsg2 = syncPreSnapshotReplyFromRpcMsg2(&rpcMsg); + syncPreSnapshotReplyLog2((char *)"test5: syncPreSnapshotReply2RpcMsg -> syncPreSnapshotReplyFromRpcMsg2 ", pMsg2); + + rpcFreeCont(rpcMsg.pCont); + syncPreSnapshotReplyDestroy(pMsg); + syncPreSnapshotReplyDestroy(pMsg2); +} + +int main() { + tsAsyncLog = 0; + sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE; + gRaftDetailLog = true; + logTest(); + + test1(); + test2(); + test3(); + test4(); + test5(); + + return 0; +} diff --git a/source/libs/sync/test/syncPreSnapshotTest.cpp b/source/libs/sync/test/syncPreSnapshotTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..03894dfa84f246de85c934556e00370ca2d20549 --- /dev/null +++ b/source/libs/sync/test/syncPreSnapshotTest.cpp @@ -0,0 +1,97 @@ +#include +#include +#include "syncIO.h" +#include "syncInt.h" +#include "syncMessage.h" +#include "syncUtil.h" + +void logTest() { + sTrace("--- sync log test: trace"); + sDebug("--- sync log test: debug"); + sInfo("--- sync log test: info"); + sWarn("--- sync log test: warn"); + sError("--- sync log test: error"); + sFatal("--- sync log test: fatal"); +} + +SyncPreSnapshot *createMsg() { + SyncPreSnapshot *pMsg = syncPreSnapshotBuild(789); + pMsg->srcId.addr = syncUtilAddr2U64("127.0.0.1", 1234); + pMsg->srcId.vgId = 100; + pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678); + pMsg->destId.vgId = 100; + pMsg->term = 9527; + return pMsg; +} + +void test1() { + SyncPreSnapshot *pMsg = createMsg(); + syncPreSnapshotLog2((char *)"test1:", pMsg); + syncPreSnapshotDestroy(pMsg); +} + +void test2() { + SyncPreSnapshot *pMsg = createMsg(); + uint32_t len = pMsg->bytes; + char * serialized = (char *)taosMemoryMalloc(len); + syncPreSnapshotSerialize(pMsg, serialized, len); + SyncPreSnapshot *pMsg2 = syncPreSnapshotBuild(789); + syncPreSnapshotDeserialize(serialized, len, pMsg2); + syncPreSnapshotLog2((char *)"test2: syncPreSnapshotSerialize -> syncPreSnapshotDeserialize ", pMsg2); + + taosMemoryFree(serialized); + syncPreSnapshotDestroy(pMsg); + syncPreSnapshotDestroy(pMsg2); +} + +void test3() { + SyncPreSnapshot *pMsg = createMsg(); + uint32_t len; + char * serialized = syncPreSnapshotSerialize2(pMsg, &len); + SyncPreSnapshot *pMsg2 = syncPreSnapshotDeserialize2(serialized, len); + syncPreSnapshotLog2((char *)"test3: syncPreSnapshotSerialize2 -> syncPreSnapshotDeserialize2 ", pMsg2); + + taosMemoryFree(serialized); + syncPreSnapshotDestroy(pMsg); + syncPreSnapshotDestroy(pMsg2); +} + +void test4() { + SyncPreSnapshot *pMsg = createMsg(); + SRpcMsg rpcMsg; + syncPreSnapshot2RpcMsg(pMsg, &rpcMsg); + SyncPreSnapshot *pMsg2 = (SyncPreSnapshot *)taosMemoryMalloc(rpcMsg.contLen); + syncPreSnapshotFromRpcMsg(&rpcMsg, pMsg2); + syncPreSnapshotLog2((char *)"test4: syncPreSnapshot2RpcMsg -> syncPreSnapshotFromRpcMsg ", pMsg2); + + rpcFreeCont(rpcMsg.pCont); + syncPreSnapshotDestroy(pMsg); + syncPreSnapshotDestroy(pMsg2); +} + +void test5() { + SyncPreSnapshot *pMsg = createMsg(); + SRpcMsg rpcMsg; + syncPreSnapshot2RpcMsg(pMsg, &rpcMsg); + SyncPreSnapshot *pMsg2 = syncPreSnapshotFromRpcMsg2(&rpcMsg); + syncPreSnapshotLog2((char *)"test5: syncPreSnapshot2RpcMsg -> syncPreSnapshotFromRpcMsg2 ", pMsg2); + + rpcFreeCont(rpcMsg.pCont); + syncPreSnapshotDestroy(pMsg); + syncPreSnapshotDestroy(pMsg2); +} + +int main() { + tsAsyncLog = 0; + sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE; + gRaftDetailLog = true; + logTest(); + + test1(); + test2(); + test3(); + test4(); + test5(); + + return 0; +} diff --git a/source/libs/sync/test/syncRaftCfgIndexTest.cpp b/source/libs/sync/test/syncRaftCfgIndexTest.cpp index bd8ffc45b6bcaf5780aa6f7a5331316cc37224fe..522da159b5ad091a8fe1e2ed570469320f9dfd36 100644 --- a/source/libs/sync/test/syncRaftCfgIndexTest.cpp +++ b/source/libs/sync/test/syncRaftCfgIndexTest.cpp @@ -60,7 +60,6 @@ void test1() { ASSERT(code == 0); SRaftCfgIndex* pRaftCfgIndex = raftCfgIndexOpen(pFile); - raftCfgIndexLog2((char*)"==test1==", pRaftCfgIndex); raftCfgIndexClose(pRaftCfgIndex); } @@ -71,15 +70,11 @@ void test2() { raftCfgIndexAddConfigIndex(pRaftCfgIndex, i); } raftCfgIndexPersist(pRaftCfgIndex); - - raftCfgIndexLog2((char*)"==test2==", pRaftCfgIndex); raftCfgIndexClose(pRaftCfgIndex); } void test3() { SRaftCfgIndex* pRaftCfgIndex = raftCfgIndexOpen(pFile); - - raftCfgIndexLog2((char*)"==test3==", pRaftCfgIndex); raftCfgIndexClose(pRaftCfgIndex); } diff --git a/source/libs/sync/test/syncRaftCfgTest.cpp b/source/libs/sync/test/syncRaftCfgTest.cpp index 2823a7826b8908e907261d2e830e3230a8373ed7..b1f820c78e29aa347534a7f1c8e2b90c50428ef7 100644 --- a/source/libs/sync/test/syncRaftCfgTest.cpp +++ b/source/libs/sync/test/syncRaftCfgTest.cpp @@ -53,14 +53,6 @@ SSyncCfg* createSyncCfg() { return pCfg; } -void test1() { - SSyncCfg* pCfg = createSyncCfg(); - syncCfgLog2((char*)__FUNCTION__, pCfg); - syncCfgLog3((char*)__FUNCTION__, pCfg); - - taosMemoryFree(pCfg); -} - void test2() { SSyncCfg* pCfg = createSyncCfg(); char* s = syncCfg2Str(pCfg); @@ -68,7 +60,6 @@ void test2() { SSyncCfg* pCfg2 = (SSyncCfg*)taosMemoryMalloc(sizeof(SSyncCfg)); int32_t ret = syncCfgFromStr(s, pCfg2); assert(ret == 0); - syncCfgLog2((char*)__FUNCTION__, pCfg2); taosMemoryFree(pCfg); taosMemoryFree(s); @@ -98,8 +89,6 @@ void test4() { SRaftCfg* pCfg = raftCfgOpen("./test3_raft_cfg.json"); assert(pCfg != NULL); - raftCfgLog2((char*)__FUNCTION__, pCfg); - int32_t ret = raftCfgClose(pCfg); assert(ret == 0); } @@ -135,7 +124,6 @@ int main() { sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE; logTest(); - test1(); test2(); test3(); test4(); diff --git a/source/libs/sync/test/syncRaftIdCheck.cpp b/source/libs/sync/test/syncRaftIdCheck.cpp index 65da0f6631e925bc0cf16a2b9bc6b2fa9a0ff561..e7ef69da20f0d7c3a02a26bff076f133ef0e4a09 100644 --- a/source/libs/sync/test/syncRaftIdCheck.cpp +++ b/source/libs/sync/test/syncRaftIdCheck.cpp @@ -15,7 +15,7 @@ int main(int argc, char** argv) { char host[128]; uint16_t port; syncUtilU642Addr(u64, host, sizeof(host), &port); - printf("" PRIu64 " -> %s:%d \n", u64, host, port); + printf("%" PRIu64 " -> %s:%d \n", u64, host, port); } else if (argc == 3) { uint64_t u64; diff --git a/source/libs/sync/test/syncRaftLogTest2.cpp b/source/libs/sync/test/syncRaftLogTest2.cpp index 0cb9b51fba35d0457cc42b9992c472ed64831c36..3d50b63ff9feb3eaa1edb3b018023d911c456ef1 100644 --- a/source/libs/sync/test/syncRaftLogTest2.cpp +++ b/source/libs/sync/test/syncRaftLogTest2.cpp @@ -5,6 +5,7 @@ #include "syncInt.h" #include "syncRaftLog.h" #include "syncRaftStore.h" +#include "syncTest.h" #include "syncUtil.h" #include "wal.h" @@ -25,7 +26,7 @@ const char* pWalPath = "./syncLogStoreTest_wal"; SyncIndex gSnapshotLastApplyIndex; SyncIndex gSnapshotLastApplyTerm; -int32_t GetSnapshotCb(struct SSyncFSM* pFsm, SSnapshot* pSnapshot) { +int32_t GetSnapshotCb(const struct SSyncFSM* pFsm, SSnapshot* pSnapshot) { pSnapshot->data = NULL; pSnapshot->lastApplyIndex = gSnapshotLastApplyIndex; pSnapshot->lastApplyTerm = gSnapshotLastApplyTerm; diff --git a/source/libs/sync/test/syncRaftLogTest3.cpp b/source/libs/sync/test/syncRaftLogTest3.cpp index fd4cade31cbcc34fd4bb9368c9c149f108f512aa..31c06625aa8eaa443a214b19bcac17463e63bda8 100644 --- a/source/libs/sync/test/syncRaftLogTest3.cpp +++ b/source/libs/sync/test/syncRaftLogTest3.cpp @@ -1,12 +1,5 @@ #include -#include -#include "syncEnv.h" -#include "syncIO.h" -#include "syncInt.h" -#include "syncRaftLog.h" -#include "syncRaftStore.h" -#include "syncUtil.h" -#include "wal.h" +#include "syncTest.h" void logTest() { sTrace("--- sync log test: trace"); @@ -27,7 +20,7 @@ const char* pWalPath = "./syncLogStoreTest_wal"; SyncIndex gSnapshotLastApplyIndex; SyncIndex gSnapshotLastApplyTerm; -int32_t GetSnapshotCb(struct SSyncFSM* pFsm, SSnapshot* pSnapshot) { +int32_t GetSnapshotCb(const struct SSyncFSM* pFsm, SSnapshot* pSnapshot) { pSnapshot->data = NULL; pSnapshot->lastApplyIndex = gSnapshotLastApplyIndex; pSnapshot->lastApplyTerm = gSnapshotLastApplyTerm; @@ -97,8 +90,8 @@ void test1() { sTrace("lastIndex: %" PRId64, lastIndex); sTrace("lastTerm: %" PRIu64, lastTerm); sTrace("syncStartIndex: %" PRId64, syncStartIndex); - sTrace("" PRId64 "'s preIndex: %" PRId64, testIndex, preIndex); - sTrace("" PRId64 "'s preTerm: %" PRIu64, testIndex, preTerm); + sTrace("testIndex: %" PRId64 " preIndex: %" PRId64, testIndex, preIndex); + sTrace("testIndex: %" PRId64 " preTerm: %" PRIu64, testIndex, preTerm); if (gAssert) { assert(lastIndex == -1); @@ -170,8 +163,8 @@ void test2() { SyncIndex preIndex = syncNodeGetPreIndex(pSyncNode, i); SyncTerm preTerm = syncNodeGetPreTerm(pSyncNode, i); - sTrace("" PRId64 "'s preIndex: %" PRId64, i, preIndex); - sTrace("" PRId64 "'s preTerm: %" PRIu64, i, preTerm); + sTrace("i: %" PRId64 " preIndex: %" PRId64, i, preIndex); + sTrace("i: %" PRId64 " preTerm: %" PRIu64, i, preTerm); if (gAssert) { SyncIndex preIndexArr[12] = {-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; @@ -292,8 +285,8 @@ void test4() { SyncIndex preIndex = syncNodeGetPreIndex(pSyncNode, i); SyncTerm preTerm = syncNodeGetPreTerm(pSyncNode, i); - sTrace("" PRId64 "'s preIndex: %" PRId64, i, preIndex); - sTrace("" PRId64 "'s preTerm: %" PRIu64, i, preTerm); + sTrace("i: %" PRId64 " preIndex: %" PRId64, i, preIndex); + sTrace("i: %" PRId64 " preTerm: %" PRIu64, i, preTerm); } logStoreDestory(pLogStore); @@ -354,8 +347,8 @@ void test5() { SyncIndex preIndex = syncNodeGetPreIndex(pSyncNode, i); SyncTerm preTerm = syncNodeGetPreTerm(pSyncNode, i); - sTrace("" PRId64 "'s preIndex: %" PRId64, i, preIndex); - sTrace("" PRId64 "'s preTerm: %" PRIu64, i, preTerm); + sTrace("i: %" PRId64 " preIndex: %" PRId64, i, preIndex); + sTrace("i: %" PRId64 " preTerm: %" PRIu64, i, preTerm); if (gAssert) { SyncIndex preIndexArr[12] = {9999, 9999, 9999, 9999, 9999, 9999, 5, 6, 7, 8, 9, 10}; diff --git a/source/libs/sync/test/syncReconfigFinishTest.cpp b/source/libs/sync/test/syncReconfigFinishTest.cpp deleted file mode 100644 index 5b283c5829464891e6a2529a1b038bd2a1501c48..0000000000000000000000000000000000000000 --- a/source/libs/sync/test/syncReconfigFinishTest.cpp +++ /dev/null @@ -1,133 +0,0 @@ -#include -#include -#include "syncIO.h" -#include "syncInt.h" -#include "syncMessage.h" -#include "syncUtil.h" - -void logTest() { - sTrace("--- sync log test: trace"); - sDebug("--- sync log test: debug"); - sInfo("--- sync log test: info"); - sWarn("--- sync log test: warn"); - sError("--- sync log test: error"); - sFatal("--- sync log test: fatal"); -} - -SSyncCfg *createSyncOldCfg() { - SSyncCfg *pCfg = (SSyncCfg *)taosMemoryMalloc(sizeof(SSyncCfg)); - memset(pCfg, 0, sizeof(SSyncCfg)); - - pCfg->replicaNum = 3; - pCfg->myIndex = 1; - for (int i = 0; i < pCfg->replicaNum; ++i) { - ((pCfg->nodeInfo)[i]).nodePort = i * 100; - snprintf(((pCfg->nodeInfo)[i]).nodeFqdn, sizeof(((pCfg->nodeInfo)[i]).nodeFqdn), "100.200.300.%d", i); - } - - return pCfg; -} - -SSyncCfg *createSyncNewCfg() { - SSyncCfg *pCfg = (SSyncCfg *)taosMemoryMalloc(sizeof(SSyncCfg)); - memset(pCfg, 0, sizeof(SSyncCfg)); - - pCfg->replicaNum = 3; - pCfg->myIndex = 1; - for (int i = 0; i < pCfg->replicaNum; ++i) { - ((pCfg->nodeInfo)[i]).nodePort = i * 100; - snprintf(((pCfg->nodeInfo)[i]).nodeFqdn, sizeof(((pCfg->nodeInfo)[i]).nodeFqdn), "500.600.700.%d", i); - } - - return pCfg; -} - -SyncReconfigFinish *createMsg() { - SyncReconfigFinish *pMsg = syncReconfigFinishBuild(1234); - - SSyncCfg *pOld = createSyncOldCfg(); - SSyncCfg *pNew = createSyncNewCfg(); - pMsg->oldCfg = *pOld; - pMsg->newCfg = *pNew; - - pMsg->newCfgIndex = 11; - pMsg->newCfgTerm = 22; - pMsg->newCfgSeqNum = 33; - - taosMemoryFree(pOld); - taosMemoryFree(pNew); - - return pMsg; -} - -void test1() { - SyncReconfigFinish *pMsg = createMsg(); - syncReconfigFinishLog2((char *)"test1:", pMsg); - syncReconfigFinishDestroy(pMsg); -} - -void test2() { - SyncReconfigFinish *pMsg = createMsg(); - uint32_t len = pMsg->bytes; - char *serialized = (char *)taosMemoryMalloc(len); - syncReconfigFinishSerialize(pMsg, serialized, len); - SyncReconfigFinish *pMsg2 = syncReconfigFinishBuild(1000); - syncReconfigFinishDeserialize(serialized, len, pMsg2); - syncReconfigFinishLog2((char *)"test2: syncReconfigFinishSerialize -> syncReconfigFinishDeserialize ", pMsg2); - - taosMemoryFree(serialized); - syncReconfigFinishDestroy(pMsg); - syncReconfigFinishDestroy(pMsg2); -} - -void test3() { - SyncReconfigFinish *pMsg = createMsg(); - uint32_t len; - char *serialized = syncReconfigFinishSerialize2(pMsg, &len); - SyncReconfigFinish *pMsg2 = syncReconfigFinishDeserialize2(serialized, len); - syncReconfigFinishLog2((char *)"test3: SyncReconfigFinishSerialize2 -> syncReconfigFinishDeserialize2 ", pMsg2); - - taosMemoryFree(serialized); - syncReconfigFinishDestroy(pMsg); - syncReconfigFinishDestroy(pMsg2); -} - -void test4() { - SyncReconfigFinish *pMsg = createMsg(); - SRpcMsg rpcMsg; - syncReconfigFinish2RpcMsg(pMsg, &rpcMsg); - SyncReconfigFinish *pMsg2 = (SyncReconfigFinish *)taosMemoryMalloc(rpcMsg.contLen); - syncReconfigFinishFromRpcMsg(&rpcMsg, pMsg2); - syncReconfigFinishLog2((char *)"test4: syncReconfigFinish2RpcMsg -> syncReconfigFinishFromRpcMsg ", pMsg2); - - rpcFreeCont(rpcMsg.pCont); - syncReconfigFinishDestroy(pMsg); - syncReconfigFinishDestroy(pMsg2); -} - -void test5() { - SyncReconfigFinish *pMsg = createMsg(); - SRpcMsg rpcMsg; - syncReconfigFinish2RpcMsg(pMsg, &rpcMsg); - SyncReconfigFinish *pMsg2 = syncReconfigFinishFromRpcMsg2(&rpcMsg); - syncReconfigFinishLog2((char *)"test5: syncReconfigFinish2RpcMsg -> syncReconfigFinishFromRpcMsg2 ", pMsg2); - - rpcFreeCont(rpcMsg.pCont); - syncReconfigFinishDestroy(pMsg); - syncReconfigFinishDestroy(pMsg2); -} - -int main() { - gRaftDetailLog = true; - tsAsyncLog = 0; - sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE; - logTest(); - - test1(); - test2(); - test3(); - test4(); - test5(); - - return 0; -} diff --git a/source/libs/sync/test/syncReplicateTest.cpp b/source/libs/sync/test/syncReplicateTest.cpp index d3ba4bc13601a7f19c836b7ee52f4cc09aafca23..7506ae19bdf1a6f43e354a3d7e4eff792d2bb00f 100644 --- a/source/libs/sync/test/syncReplicateTest.cpp +++ b/source/libs/sync/test/syncReplicateTest.cpp @@ -42,7 +42,7 @@ void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, - cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } else { sTrace("==callback== ==CommitCb== do not apply again %" PRId64, cbMeta.index); @@ -53,7 +53,7 @@ void PreCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) char logBuf[256]; snprintf(logBuf, sizeof(logBuf), "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, - cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } @@ -61,7 +61,7 @@ void RollBackCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, - cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } @@ -74,10 +74,14 @@ int32_t GetSnapshotCb(struct SSyncFSM* pFsm, SSnapshot* pSnapshot) { SSyncFSM* createFsm() { SSyncFSM* pFsm = (SSyncFSM*)taosMemoryMalloc(sizeof(SSyncFSM)); + +#if 0 pFsm->FpCommitCb = CommitCb; pFsm->FpPreCommitCb = PreCommitCb; pFsm->FpRollBackCb = RollBackCb; pFsm->FpGetSnapshotInfo = GetSnapshotCb; +#endif + return pFsm; } @@ -100,8 +104,8 @@ int64_t createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWal* SSyncInfo syncInfo; syncInfo.vgId = vgId; syncInfo.msgcb = &gSyncIO->msgcb; - syncInfo.FpSendMsg = syncIOSendMsg; - syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.syncSendMSg = syncIOSendMsg; + syncInfo.syncEqMsg = syncIOEqMsg; syncInfo.pFsm = createFsm(); snprintf(syncInfo.path, sizeof(syncInfo.path), "%s_sync_replica%d_index%d", path, replicaNum, myIndex); syncInfo.pWal = pWal; @@ -145,7 +149,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) { pMsg->msgType = 9999; pMsg->contLen = 256; pMsg->pCont = rpcMallocCont(pMsg->contLen); - snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count, + snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-%" PRId64, myIndex, i, count, taosGetTimestampMs()); return pMsg; } diff --git a/source/libs/sync/test/syncRespMgrTest.cpp b/source/libs/sync/test/syncRespMgrTest.cpp index 35daff796f546d2dd675fec99bb9f42f8a25c76b..8d709e8c81b5d84cf1cd9e414940ece1ce9f5823 100644 --- a/source/libs/sync/test/syncRespMgrTest.cpp +++ b/source/libs/sync/test/syncRespMgrTest.cpp @@ -1,8 +1,4 @@ -#include "syncRespMgr.h" -//#include -#include -#include "syncIO.h" -#include "syncInt.h" +#include "syncTest.h" void logTest() { sTrace("--- sync log test: trace"); @@ -58,19 +54,19 @@ void syncRespMgrGetTest(uint64_t i) { if (ret == 1) { printStub(&stub); } else if (ret == 0) { - printf("" PRId64 " notFound \n", i); + printf("%" PRId64 " notFound \n", i); } } void syncRespMgrGetAndDelTest(uint64_t i) { - printf("------syncRespMgrGetAndDelTest-------" PRIu64 "-- \n", i); - SRespStub stub; - int32_t ret = syncRespMgrGetAndDel(pMgr, i, &stub); - if (ret == 1) { - printStub(&stub); - } else if (ret == 0) { - printf("" PRId64 " notFound \n", i); - } + printf("------syncRespMgrGetAndDelTest-------%" PRIu64 "-- \n", i); + // SRespStub stub; + // int32_t ret = syncRespMgrGetAndDel(pMgr, i, &stub); + // if (ret == 1) { + // printStub(&stub); + // } else if (ret == 0) { + // printf("%" PRId64 " notFound \n", i); + // } } SSyncNode *createSyncNode() { diff --git a/source/libs/sync/test/syncRpcMsgTest.cpp b/source/libs/sync/test/syncRpcMsgTest.cpp index 0b21f4108061ac97fb79dc4dfc79ae40d47ede7a..127d8e1c4148caa0d7e12f3cc13b70a7e4ea3d22 100644 --- a/source/libs/sync/test/syncRpcMsgTest.cpp +++ b/source/libs/sync/test/syncRpcMsgTest.cpp @@ -47,7 +47,11 @@ SyncClientRequest *createSyncClientRequest() { rpcMsg.contLen = 20; rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen); strcpy((char *)rpcMsg.pCont, "hello rpc"); - SyncClientRequest *pMsg = syncClientRequestBuild2(&rpcMsg, 123, true, 1000); + + SRpcMsg clientRequestMsg; + syncClientRequestBuildFromRpcMsg(&clientRequestMsg, &rpcMsg, 123, true, 1000); + SyncClientRequest *pMsg = (SyncClientRequest *)taosMemoryMalloc(clientRequestMsg.contLen); + memcpy(pMsg->data, clientRequestMsg.pCont, clientRequestMsg.contLen); return pMsg; } @@ -155,11 +159,13 @@ void test7() { } void test8() { +#if 0 SyncClientRequest *pMsg = createSyncClientRequest(); - SRpcMsg rpcMsg; + SRpcMsg rpcMsg = {0}; syncClientRequest2RpcMsg(pMsg, &rpcMsg); syncRpcMsgLog2((char *)"test8", &rpcMsg); - syncClientRequestDestroy(pMsg); + taosMemoryFree(pMsg); +#endif } int main() { diff --git a/source/libs/sync/test/syncSnapshotReceiverTest.cpp b/source/libs/sync/test/syncSnapshotReceiverTest.cpp index 0f8e76f12167d71ea6c5919dbff5e567033b580a..6eb854874073c14e04ac86fc9640eba105d6058c 100644 --- a/source/libs/sync/test/syncSnapshotReceiverTest.cpp +++ b/source/libs/sync/test/syncSnapshotReceiverTest.cpp @@ -37,9 +37,12 @@ SSyncSnapshotReceiver* createReceiver() { SSyncNode* pSyncNode = (SSyncNode*)taosMemoryMalloc(sizeof(*pSyncNode)); pSyncNode->pRaftStore = (SRaftStore*)taosMemoryMalloc(sizeof(*(pSyncNode->pRaftStore))); pSyncNode->pFsm = (SSyncFSM*)taosMemoryMalloc(sizeof(*(pSyncNode->pFsm))); + +#if 0 pSyncNode->pFsm->FpSnapshotStartWrite = SnapshotStartWrite; pSyncNode->pFsm->FpSnapshotStopWrite = SnapshotStopWrite; pSyncNode->pFsm->FpSnapshotDoWrite = SnapshotDoWrite; +#endif SRaftId id; id.addr = syncUtilAddr2U64("1.2.3.4", 99); @@ -50,7 +53,6 @@ SSyncSnapshotReceiver* createReceiver() { pReceiver->ack = 20; pReceiver->pWriter = (void*)0x11; pReceiver->term = 66; - pReceiver->privateTerm = 99; return pReceiver; } diff --git a/source/libs/sync/test/syncSnapshotRspTest.cpp b/source/libs/sync/test/syncSnapshotRspTest.cpp index 89348da6175403f36d9edf25d70a587e3e3617f7..63905c2182e1fc9b2c66bcfd0a8429d62305d9e0 100644 --- a/source/libs/sync/test/syncSnapshotRspTest.cpp +++ b/source/libs/sync/test/syncSnapshotRspTest.cpp @@ -21,7 +21,7 @@ SyncSnapshotRsp *createMsg() { pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678); pMsg->destId.vgId = 100; pMsg->term = 11; - pMsg->privateTerm = 99; + pMsg->startTime = 99; pMsg->lastIndex = 22; pMsg->lastTerm = 33; pMsg->ack = 44; diff --git a/source/libs/sync/test/syncSnapshotSendTest.cpp b/source/libs/sync/test/syncSnapshotSendTest.cpp index 6fcfa6f6c490134e13a581963b200e0d7c466d42..83f1dfebb3893cc73ea36826c3ee353932042e14 100644 --- a/source/libs/sync/test/syncSnapshotSendTest.cpp +++ b/source/libs/sync/test/syncSnapshotSendTest.cpp @@ -21,7 +21,6 @@ SyncSnapshotSend *createMsg() { pMsg->destId.addr = syncUtilAddr2U64("127.0.0.1", 5678); pMsg->destId.vgId = 100; pMsg->term = 11; - pMsg->privateTerm = 99; pMsg->lastIndex = 22; pMsg->lastTerm = 33; diff --git a/source/libs/sync/test/syncSnapshotSenderTest.cpp b/source/libs/sync/test/syncSnapshotSenderTest.cpp index 8d1f83b3b19cae7527dc83be0cf6d70f9748bae6..7b2c13463cf28321add905f6baa729d21e27f2d3 100644 --- a/source/libs/sync/test/syncSnapshotSenderTest.cpp +++ b/source/libs/sync/test/syncSnapshotSenderTest.cpp @@ -37,10 +37,13 @@ SSyncSnapshotSender* createSender() { SSyncNode* pSyncNode = (SSyncNode*)taosMemoryMalloc(sizeof(*pSyncNode)); pSyncNode->pRaftStore = (SRaftStore*)taosMemoryMalloc(sizeof(*(pSyncNode->pRaftStore))); pSyncNode->pFsm = (SSyncFSM*)taosMemoryMalloc(sizeof(*(pSyncNode->pFsm))); + + #if 0 pSyncNode->pFsm->FpSnapshotStartRead = SnapshotStartRead; pSyncNode->pFsm->FpSnapshotStopRead = SnapshotStopRead; pSyncNode->pFsm->FpSnapshotDoRead = SnapshotDoRead; pSyncNode->pFsm->FpGetSnapshotInfo = GetSnapshot; +#endif SSyncSnapshotSender* pSender = snapshotSenderCreate(pSyncNode, 2); pSender->start = true; @@ -55,7 +58,8 @@ SSyncSnapshotSender* createSender() { pSender->snapshot.lastApplyTerm = 88; pSender->sendingMS = 77; pSender->term = 66; - pSender->privateTerm = 99; + + //pSender->privateTerm = 99; return pSender; } diff --git a/source/libs/sync/test/syncSnapshotTest.cpp b/source/libs/sync/test/syncSnapshotTest.cpp index 3dc85180728c4a287758156b47309e48a7cc01cd..e2264fd08c4cd7bf80981aee66eec4a0377aa0b3 100644 --- a/source/libs/sync/test/syncSnapshotTest.cpp +++ b/source/libs/sync/test/syncSnapshotTest.cpp @@ -33,7 +33,7 @@ SyncIndex snapshotLastApplyIndex = SYNC_INDEX_INVALID; const char *pDir = "./syncSnapshotTest"; const char *pWalDir = "./syncSnapshotTest_wal"; -void CommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { +void CommitCb(const struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { SyncIndex beginIndex = SYNC_INDEX_INVALID; if (pFsm->FpGetSnapshotInfo != NULL) { SSnapshot snapshot; @@ -45,30 +45,30 @@ void CommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, - cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); } else { sTrace("==callback== ==CommitCb== do not apply again %" PRId64, cbMeta.index); } } -void PreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { +void PreCommitCb(const struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, - cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); } -void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { +void RollBackCb(const struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, - cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); } -int32_t GetSnapshotCb(struct SSyncFSM *pFsm, SSnapshot *pSnapshot) { +int32_t GetSnapshotCb(const struct SSyncFSM *pFsm, SSnapshot *pSnapshot) { pSnapshot->data = NULL; pSnapshot->lastApplyIndex = snapshotLastApplyIndex; pSnapshot->lastApplyTerm = 100; @@ -78,17 +78,21 @@ int32_t GetSnapshotCb(struct SSyncFSM *pFsm, SSnapshot *pSnapshot) { void initFsm() { pFsm = (SSyncFSM *)taosMemoryMalloc(sizeof(SSyncFSM)); memset(pFsm, 0, sizeof(*pFsm)); + +#if 0 pFsm->FpCommitCb = CommitCb; pFsm->FpPreCommitCb = PreCommitCb; pFsm->FpRollBackCb = RollBackCb; pFsm->FpGetSnapshotInfo = GetSnapshotCb; +#endif + } SSyncNode *syncNodeInit() { syncInfo.vgId = 1234; syncInfo.msgcb = &gSyncIO->msgcb; - syncInfo.FpSendMsg = syncIOSendMsg; - syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.syncSendMSg = syncIOSendMsg; + syncInfo.syncEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", pDir); @@ -158,8 +162,11 @@ SRpcMsg *step0() { } SyncClientRequest *step1(const SRpcMsg *pMsg) { - SyncClientRequest *pRetMsg = syncClientRequestBuild2(pMsg, 123, true, 1000); - return pRetMsg; + SRpcMsg clientRequestMsg; + syncClientRequestBuildFromRpcMsg(&clientRequestMsg, pMsg, 123, true, 1000); + SyncClientRequest *pMsg2 = (SyncClientRequest *)taosMemoryMalloc(clientRequestMsg.contLen); + memcpy(pMsg2->data, clientRequestMsg.pCont, clientRequestMsg.contLen); + return pMsg2; } int main(int argc, char **argv) { @@ -179,7 +186,7 @@ int main(int argc, char **argv) { int32_t ret = syncIOStart((char *)"127.0.0.1", ports[myIndex]); assert(ret == 0); - ret = syncEnvStart(); + ret = syncInit(); assert(ret == 0); // taosRemoveDir(pWalDir); @@ -188,7 +195,7 @@ int main(int argc, char **argv) { gSyncNode = syncInitTest(); assert(gSyncNode != NULL); - syncNodeLog2((char *)"", gSyncNode); + sNTrace(gSyncNode, ""); initRaftId(gSyncNode); @@ -202,9 +209,9 @@ int main(int argc, char **argv) { for (int i = 0; i < 10; ++i) { SyncClientRequest *pSyncClientRequest = pMsg1; - SRpcMsg rpcMsg; - syncClientRequest2RpcMsg(pSyncClientRequest, &rpcMsg); - gSyncNode->FpEqMsg(gSyncNode->msgcb, &rpcMsg); + SRpcMsg rpcMsg = {0}; + // syncClientRequest2RpcMsg(pSyncClientRequest, &rpcMsg); + // gSyncNode->syncEqMsg(gSyncNode->msgcb, &rpcMsg); taosMsleep(1000); } diff --git a/source/libs/sync/test/syncTestTool.cpp b/source/libs/sync/test/syncTestTool.cpp index 1cdecfe5b37663671799ede7bcf17556a15fc096..e6f6006410307ffd8f524e0919b7a2b6dac150cc 100644 --- a/source/libs/sync/test/syncTestTool.cpp +++ b/source/libs/sync/test/syncTestTool.cpp @@ -44,8 +44,8 @@ void CommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { ", term:%" PRIu64 " " "currentTerm:%" PRIu64 " \n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), - cbMeta.flag, cbMeta.term, cbMeta.currentTerm); + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state), cbMeta.flag, + cbMeta.term, cbMeta.currentTerm); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } @@ -56,8 +56,8 @@ void PreCommitCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) ", term:%" PRIu64 " " "currentTerm:%" PRIu64 " \n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), - cbMeta.flag, cbMeta.term, cbMeta.currentTerm); + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state), cbMeta.flag, + cbMeta.term, cbMeta.currentTerm); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } @@ -68,8 +68,8 @@ void RollBackCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbMeta) { ", term:%" PRIu64 " " "currentTerm:%" PRIu64 " \n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), - cbMeta.flag, cbMeta.term, cbMeta.currentTerm); + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state), cbMeta.flag, + cbMeta.term, cbMeta.currentTerm); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } @@ -154,7 +154,7 @@ int32_t SnapshotDoWrite(struct SSyncFSM* pFsm, void* pWriter, void* pBuf, int32_ void RestoreFinishCb(struct SSyncFSM* pFsm) { sTrace("==callback== ==RestoreFinishCb== pFsm:%p", pFsm); } void ReConfigCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SReConfigCbMeta* cbMeta) { - char* s = syncCfg2Str(&(cbMeta.newCfg)); + char* s = syncCfg2Str(&(cbMeta->newCfg)); sTrace("==callback== ==ReConfigCb== flag:0x%lX, index:%" PRId64 ", code:%d, currentTerm:%" PRIu64 ", term:%" PRIu64 ", newCfg:%s", cbMeta->flag, cbMeta->index, cbMeta->code, cbMeta->currentTerm, cbMeta->term, s); @@ -168,8 +168,8 @@ void LeaderTransferCb(struct SSyncFSM* pFsm, const SRpcMsg* pMsg, SFsmCbMeta cbM ", isWeak:%d, code:%d, state:%d %s, flag:%" PRIu64 ", term:%" PRIu64 " " "currentTerm:%" PRIu64 " \n", - pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state), - cbMeta.flag, cbMeta.term, cbMeta.currentTerm); + pFsm, cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state), cbMeta.flag, + cbMeta.term, cbMeta.currentTerm); syncRpcMsgLog2(logBuf, (SRpcMsg*)pMsg); } @@ -177,6 +177,7 @@ SSyncFSM* createFsm() { SSyncFSM* pFsm = (SSyncFSM*)taosMemoryMalloc(sizeof(SSyncFSM)); memset(pFsm, 0, sizeof(*pFsm)); +#if 0 pFsm->FpCommitCb = CommitCb; pFsm->FpPreCommitCb = PreCommitCb; pFsm->FpRollBackCb = RollBackCb; @@ -193,6 +194,7 @@ SSyncFSM* createFsm() { pFsm->FpSnapshotDoWrite = SnapshotDoWrite; pFsm->FpLeaderTransferCb = LeaderTransferCb; +#endif return pFsm; } @@ -217,8 +219,8 @@ int64_t createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWal* SSyncInfo syncInfo; syncInfo.vgId = vgId; syncInfo.msgcb = &gSyncIO->msgcb; - syncInfo.FpSendMsg = syncIOSendMsg; - syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.syncSendMSg = syncIOSendMsg; + syncInfo.syncEqMsg = syncIOEqMsg; syncInfo.pFsm = createFsm(); snprintf(syncInfo.path, sizeof(syncInfo.path), "%s_sync_replica%d_index%d", path, replicaNum, myIndex); syncInfo.pWal = pWal; @@ -308,7 +310,7 @@ SRpcMsg* createRpcMsg(int i, int count, int myIndex) { pMsg->msgType = TDMT_VND_SUBMIT; pMsg->contLen = 256; pMsg->pCont = rpcMallocCont(pMsg->contLen); - snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-" PRId64, myIndex, i, count, + snprintf((char*)(pMsg->pCont), pMsg->contLen, "value-myIndex:%u-%d-%d-%" PRId64, myIndex, i, count, taosGetTimestampMs()); return pMsg; } diff --git a/source/libs/sync/test/syncTimeoutTest.cpp b/source/libs/sync/test/syncTimeoutTest.cpp index bb0d71f00327722644273a62a3dd592b88207561..bae5e0ea888900eeb40fd6a649b7b84014847a27 100644 --- a/source/libs/sync/test/syncTimeoutTest.cpp +++ b/source/libs/sync/test/syncTimeoutTest.cpp @@ -78,6 +78,28 @@ void test5() { syncTimeoutDestroy(pMsg2); } +void syncUtilJson2Line(char *jsonStr) { + int p, q, len; + p = 0; + q = 1; + len = strlen(jsonStr); + while (1) { + if (jsonStr[q] == '\0') { + jsonStr[p + 1] = '\0'; + break; + } + + if (jsonStr[q] == '\n' || jsonStr[q] == ' ' || jsonStr[q] == '\t') { + q++; + continue; + } else { + jsonStr[p + 1] = jsonStr[q]; + p++; + q++; + } + } +} + void test6() { SyncTimeout *pMsg = createMsg(); char *jsonStr = syncTimeout2Str(pMsg); diff --git a/source/libs/sync/test/syncVotesGrantedTest.cpp b/source/libs/sync/test/syncVotesGrantedTest.cpp index d4885d0316b3a099f1b1e1c0bca45b4f1f471849..6a8404308b4985ab026c22499b68e39c7601a034 100644 --- a/source/libs/sync/test/syncVotesGrantedTest.cpp +++ b/source/libs/sync/test/syncVotesGrantedTest.cpp @@ -6,6 +6,7 @@ #include "syncRaftStore.h" #include "syncUtil.h" #include "syncVoteMgr.h" +#include "syncTest.h" void logTest() { sTrace("--- sync log test: trace"); @@ -28,8 +29,8 @@ SSyncNode* pSyncNode; SSyncNode* syncNodeInit() { syncInfo.vgId = 1234; syncInfo.msgcb = &gSyncIO->msgcb; - syncInfo.FpSendMsg = syncIOSendMsg; - syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.syncSendMSg = syncIOSendMsg; + syncInfo.syncEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./"); @@ -82,7 +83,7 @@ int main(int argc, char** argv) { int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]); assert(ret == 0); - ret = syncEnvStart(); + ret = syncInit(); assert(ret == 0); SSyncNode* pSyncNode = syncInitTest(); diff --git a/source/libs/sync/test/syncVotesRespondTest.cpp b/source/libs/sync/test/syncVotesRespondTest.cpp index 77262dfc65e0f134af75e8a11be674c40a1437ab..d5e7d71030d0346b2d32cb1e1df4b966a4833fb7 100644 --- a/source/libs/sync/test/syncVotesRespondTest.cpp +++ b/source/libs/sync/test/syncVotesRespondTest.cpp @@ -6,6 +6,8 @@ #include "syncRaftStore.h" #include "syncUtil.h" #include "syncVoteMgr.h" +#include "syncTest.h" + void logTest() { sTrace("--- sync log test: trace"); @@ -28,8 +30,8 @@ SSyncNode* pSyncNode; SSyncNode* syncNodeInit() { syncInfo.vgId = 1234; syncInfo.msgcb = &gSyncIO->msgcb; - syncInfo.FpSendMsg = syncIOSendMsg; - syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.syncSendMSg = syncIOSendMsg; + syncInfo.syncEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", "./"); @@ -82,7 +84,7 @@ int main(int argc, char** argv) { int32_t ret = syncIOStart((char*)"127.0.0.1", ports[myIndex]); assert(ret == 0); - ret = syncEnvStart(); + ret = syncInit(); assert(ret == 0); SSyncNode* pSyncNode = syncInitTest(); diff --git a/source/libs/sync/test/syncWriteTest.cpp b/source/libs/sync/test/syncWriteTest.cpp index b185f52f7547d1a60541177f3a7374f3ed694081..2e5c26719ba39ab67fa1408937e9082ec3a9d5fa 100644 --- a/source/libs/sync/test/syncWriteTest.cpp +++ b/source/libs/sync/test/syncWriteTest.cpp @@ -7,6 +7,7 @@ #include "syncRaftEntry.h" #include "syncRaftLog.h" #include "syncRaftStore.h" +#include "syncTest.h" #include "syncUtil.h" #include "wal.h" @@ -35,7 +36,7 @@ void CommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), "==callback== ==CommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, - cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); } @@ -43,7 +44,7 @@ void PreCommitCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) char logBuf[256]; snprintf(logBuf, sizeof(logBuf), "==callback== ==PreCommitCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, - cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); } @@ -51,22 +52,26 @@ void RollBackCb(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) { char logBuf[256]; snprintf(logBuf, sizeof(logBuf), "==callback== ==RollBackCb== pFsm:%p, index:%" PRId64 ", isWeak:%d, code:%d, state:%d %s \n", pFsm, - cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncUtilState2String(cbMeta.state)); + cbMeta.index, cbMeta.isWeak, cbMeta.code, cbMeta.state, syncStr(cbMeta.state)); syncRpcMsgLog2(logBuf, (SRpcMsg *)pMsg); } void initFsm() { pFsm = (SSyncFSM *)taosMemoryMalloc(sizeof(SSyncFSM)); + +#if 0 pFsm->FpCommitCb = CommitCb; pFsm->FpPreCommitCb = PreCommitCb; pFsm->FpRollBackCb = RollBackCb; +#endif + } SSyncNode *syncNodeInit() { syncInfo.vgId = 1234; syncInfo.msgcb = &gSyncIO->msgcb; - syncInfo.FpSendMsg = syncIOSendMsg; - syncInfo.FpEqMsg = syncIOEqMsg; + syncInfo.syncSendMSg = syncIOSendMsg; + syncInfo.syncEqMsg = syncIOEqMsg; syncInfo.pFsm = pFsm; snprintf(syncInfo.path, sizeof(syncInfo.path), "%s", pDir); @@ -136,7 +141,8 @@ SRpcMsg *step0() { } SyncClientRequest *step1(const SRpcMsg *pMsg) { - SyncClientRequest *pRetMsg = syncClientRequestBuild2(pMsg, 123, true, 1000); + SyncClientRequest *pRetMsg = NULL; + // syncClientRequestBuild(pMsg, 123, true, 1000); return pRetMsg; } @@ -154,7 +160,7 @@ int main(int argc, char **argv) { int32_t ret = syncIOStart((char *)"127.0.0.1", ports[myIndex]); assert(ret == 0); - ret = syncEnvStart(); + ret = syncInit(); assert(ret == 0); taosRemoveDir("./wal_test"); @@ -163,7 +169,7 @@ int main(int argc, char **argv) { gSyncNode = syncInitTest(); assert(gSyncNode != NULL); - syncNodeLog2((char *)"", gSyncNode); + sNTrace(gSyncNode, ""); initRaftId(gSyncNode); @@ -175,14 +181,14 @@ int main(int argc, char **argv) { SyncClientRequest *pMsg1 = step1(pMsg0); syncClientRequestLog2((char *)"==step1==", pMsg1); - for (int i = 0; i < 10; ++i) { - SyncClientRequest *pSyncClientRequest = pMsg1; - SRpcMsg rpcMsg; - syncClientRequest2RpcMsg(pSyncClientRequest, &rpcMsg); - gSyncNode->FpEqMsg(gSyncNode->msgcb, &rpcMsg); + // for (int i = 0; i < 10; ++i) { + // SyncClientRequest *pSyncClientRequest = pMsg1; + // SRpcMsg rpcMsg = {0}; + // syncClientRequest2RpcMsg(pSyncClientRequest, &rpcMsg); + // gSyncNode->syncEqMsg(gSyncNode->msgcb, &rpcMsg); - taosMsleep(1000); - } + // taosMsleep(1000); + // } while (1) { sTrace("while 1 sleep"); diff --git a/source/libs/sync/test/sync_test_lib/CMakeLists.txt b/source/libs/sync/test/sync_test_lib/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..db775c3662025be3f94ef33f32db0da28ec0cd60 --- /dev/null +++ b/source/libs/sync/test/sync_test_lib/CMakeLists.txt @@ -0,0 +1,14 @@ +aux_source_directory(src SYNC_TEST_SRC) +add_library(sync_test_lib STATIC ${SYNC_TEST_SRC}) + +target_link_libraries( + sync_test_lib + PUBLIC sync +) + +target_include_directories( + sync_test_lib + PUBLIC "${TD_SOURCE_DIR}/include/libs/sync" + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../../inc" + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) diff --git a/source/libs/sync/inc/syncIO.h b/source/libs/sync/test/sync_test_lib/inc/syncIO.h similarity index 95% rename from source/libs/sync/inc/syncIO.h rename to source/libs/sync/test/sync_test_lib/inc/syncIO.h index cfc4dd247263a3c3eb877a814d6da00ed956589a..955a832b6862321b723e422f6969be8bc798f653 100644 --- a/source/libs/sync/inc/syncIO.h +++ b/source/libs/sync/test/sync_test_lib/inc/syncIO.h @@ -50,7 +50,7 @@ typedef struct SSyncIO { void *pSyncNode; int32_t (*FpOnSyncPing)(SSyncNode *pSyncNode, SyncPing *pMsg); int32_t (*FpOnSyncPingReply)(SSyncNode *pSyncNode, SyncPingReply *pMsg); - int32_t (*FpOnSyncClientRequest)(SSyncNode *pSyncNode, SyncClientRequest *pMsg, SyncIndex *pRetIndex); + int32_t (*FpOnSyncClientRequest)(SSyncNode *pSyncNode, SRpcMsg *pMsg, SyncIndex *pRetIndex); int32_t (*FpOnSyncRequestVote)(SSyncNode *pSyncNode, SyncRequestVote *pMsg); int32_t (*FpOnSyncRequestVoteReply)(SSyncNode *pSyncNode, SyncRequestVoteReply *pMsg); int32_t (*FpOnSyncAppendEntries)(SSyncNode *pSyncNode, SyncAppendEntries *pMsg); diff --git a/source/libs/sync/test/sync_test_lib/inc/syncTest.h b/source/libs/sync/test/sync_test_lib/inc/syncTest.h new file mode 100644 index 0000000000000000000000000000000000000000..3a490742724c51387676ec29a485fce0be90f84f --- /dev/null +++ b/source/libs/sync/test/sync_test_lib/inc/syncTest.h @@ -0,0 +1,90 @@ +/* + * 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_LIBS_SYNC_TEST_H +#define _TD_LIBS_SYNC_TEST_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "syncInt.h" + +#include "wal.h" + +#include "syncEnv.h" +#include "syncIO.h" +#include "syncIndexMgr.h" +#include "syncInt.h" +#include "syncMessage.h" +#include "syncRaftCfg.h" +#include "syncRaftEntry.h" +#include "syncRaftLog.h" +#include "syncRaftStore.h" +#include "syncRespMgr.h" +#include "syncSnapshot.h" +#include "syncUtil.h" +#include "syncVoteMgr.h" + +cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry); +char* syncEntry2Str(const SSyncRaftEntry* pEntry); +void syncEntryPrint(const SSyncRaftEntry* pObj); +void syncEntryPrint2(char* s, const SSyncRaftEntry* pObj); +void syncEntryLog(const SSyncRaftEntry* pObj); +void syncEntryLog2(char* s, const SSyncRaftEntry* pObj); + +cJSON* raftCache2Json(SRaftEntryHashCache* pObj); +char* raftCache2Str(SRaftEntryHashCache* pObj); +void raftCachePrint(SRaftEntryHashCache* pObj); +void raftCachePrint2(char* s, SRaftEntryHashCache* pObj); +void raftCacheLog(SRaftEntryHashCache* pObj); +void raftCacheLog2(char* s, SRaftEntryHashCache* pObj); + +cJSON* raftEntryCache2Json(SRaftEntryCache* pObj); +char* raftEntryCache2Str(SRaftEntryCache* pObj); +void raftEntryCachePrint(SRaftEntryCache* pObj); +void raftEntryCachePrint2(char* s, SRaftEntryCache* pObj); +void raftEntryCacheLog(SRaftEntryCache* pObj); +void raftEntryCacheLog2(char* s, SRaftEntryCache* pObj); + +cJSON* syncAppendEntriesBatch2Json(const SyncAppendEntriesBatch* pMsg); +char* syncAppendEntriesBatch2Str(const SyncAppendEntriesBatch* pMsg); +void syncAppendEntriesBatchPrint(const SyncAppendEntriesBatch* pMsg); +void syncAppendEntriesBatchPrint2(char* s, const SyncAppendEntriesBatch* pMsg); +void syncAppendEntriesBatchLog(const SyncAppendEntriesBatch* pMsg); +void syncAppendEntriesBatchLog2(char* s, const SyncAppendEntriesBatch* pMsg); + +cJSON* logStore2Json(SSyncLogStore* pLogStore); +char* logStore2Str(SSyncLogStore* pLogStore); +cJSON* logStoreSimple2Json(SSyncLogStore* pLogStore); +char* logStoreSimple2Str(SSyncLogStore* pLogStore); +void logStorePrint(SSyncLogStore* pLogStore); +void logStorePrint2(char* s, SSyncLogStore* pLogStore); +void logStoreLog(SSyncLogStore* pLogStore); +void logStoreLog2(char* s, SSyncLogStore* pLogStore); +void logStoreSimplePrint(SSyncLogStore* pLogStore); +void logStoreSimplePrint2(char* s, SSyncLogStore* pLogStore); +void logStoreSimpleLog(SSyncLogStore* pLogStore); +void logStoreSimpleLog2(char* s, SSyncLogStore* pLogStore); + +cJSON* syncNode2Json(const SSyncNode* pSyncNode); +char* syncNode2Str(const SSyncNode* pSyncNode); + + +#ifdef __cplusplus +} +#endif + +#endif /*_TD_LIBS_SYNC_RAFT_ENTRY_H*/ diff --git a/source/libs/sync/src/syncIO.c b/source/libs/sync/test/sync_test_lib/src/syncIO.c similarity index 98% rename from source/libs/sync/src/syncIO.c rename to source/libs/sync/test/sync_test_lib/src/syncIO.c index afa2d43e13a90000da15093b658ca480b285791f..14adc18c66f3255a49aee91376e767e610735ae4 100644 --- a/source/libs/sync/src/syncIO.c +++ b/source/libs/sync/test/sync_test_lib/src/syncIO.c @@ -279,10 +279,7 @@ static void *syncIOConsumerFunc(void *param) { } else if (pRpcMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) { if (io->FpOnSyncClientRequest != NULL) { - SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pRpcMsg); - ASSERT(pSyncMsg != NULL); - io->FpOnSyncClientRequest(io->pSyncNode, pSyncMsg, NULL); - syncClientRequestDestroy(pSyncMsg); + io->FpOnSyncClientRequest(io->pSyncNode, pRpcMsg, NULL); } } else if (pRpcMsg->msgType == TDMT_SYNC_REQUEST_VOTE) { diff --git a/source/libs/sync/test/sync_test_lib/src/syncMainDebug.c b/source/libs/sync/test/sync_test_lib/src/syncMainDebug.c new file mode 100644 index 0000000000000000000000000000000000000000..5e1a9be164745aa26f1ad0a483dc0c4deca02af1 --- /dev/null +++ b/source/libs/sync/test/sync_test_lib/src/syncMainDebug.c @@ -0,0 +1,255 @@ +/* + * 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 . + */ + +#define _DEFAULT_SOURCE +#include "syncTest.h" + +cJSON* syncNode2Json(const SSyncNode* pSyncNode) { + char u64buf[128] = {0}; + cJSON* pRoot = cJSON_CreateObject(); + + if (pSyncNode != NULL) { + // init by SSyncInfo + cJSON_AddNumberToObject(pRoot, "vgId", pSyncNode->vgId); + cJSON_AddItemToObject(pRoot, "SRaftCfg", raftCfg2Json(pSyncNode->pRaftCfg)); + cJSON_AddStringToObject(pRoot, "path", pSyncNode->path); + cJSON_AddStringToObject(pRoot, "raftStorePath", pSyncNode->raftStorePath); + cJSON_AddStringToObject(pRoot, "configPath", pSyncNode->configPath); + + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pWal); + cJSON_AddStringToObject(pRoot, "pWal", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->msgcb); + cJSON_AddStringToObject(pRoot, "rpcClient", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->syncSendMSg); + cJSON_AddStringToObject(pRoot, "syncSendMSg", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->msgcb); + cJSON_AddStringToObject(pRoot, "queue", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->syncEqMsg); + cJSON_AddStringToObject(pRoot, "syncEqMsg", u64buf); + + // init internal + cJSON* pMe = syncUtilNodeInfo2Json(&pSyncNode->myNodeInfo); + cJSON_AddItemToObject(pRoot, "myNodeInfo", pMe); + cJSON* pRaftId = syncUtilRaftId2Json(&pSyncNode->myRaftId); + cJSON_AddItemToObject(pRoot, "myRaftId", pRaftId); + + cJSON_AddNumberToObject(pRoot, "peersNum", pSyncNode->peersNum); + cJSON* pPeers = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "peersNodeInfo", pPeers); + for (int32_t i = 0; i < pSyncNode->peersNum; ++i) { + cJSON_AddItemToArray(pPeers, syncUtilNodeInfo2Json(&pSyncNode->peersNodeInfo[i])); + } + cJSON* pPeersId = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "peersId", pPeersId); + for (int32_t i = 0; i < pSyncNode->peersNum; ++i) { + cJSON_AddItemToArray(pPeersId, syncUtilRaftId2Json(&pSyncNode->peersId[i])); + } + + cJSON_AddNumberToObject(pRoot, "replicaNum", pSyncNode->replicaNum); + cJSON* pReplicasId = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "replicasId", pReplicasId); + for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) { + cJSON_AddItemToArray(pReplicasId, syncUtilRaftId2Json(&pSyncNode->replicasId[i])); + } + + // raft algorithm + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pFsm); + cJSON_AddStringToObject(pRoot, "pFsm", u64buf); + cJSON_AddNumberToObject(pRoot, "quorum", pSyncNode->quorum); + cJSON* pLaderCache = syncUtilRaftId2Json(&pSyncNode->leaderCache); + cJSON_AddItemToObject(pRoot, "leaderCache", pLaderCache); + + // life cycle + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->rid); + cJSON_AddStringToObject(pRoot, "rid", u64buf); + + // tla+ server vars + cJSON_AddNumberToObject(pRoot, "state", pSyncNode->state); + cJSON_AddStringToObject(pRoot, "state_str", syncStr(pSyncNode->state)); + cJSON_AddItemToObject(pRoot, "pRaftStore", raftStore2Json(pSyncNode->pRaftStore)); + + // tla+ candidate vars + cJSON_AddItemToObject(pRoot, "pVotesGranted", voteGranted2Json(pSyncNode->pVotesGranted)); + cJSON_AddItemToObject(pRoot, "pVotesRespond", votesRespond2Json(pSyncNode->pVotesRespond)); + + // tla+ leader vars + cJSON_AddItemToObject(pRoot, "pNextIndex", syncIndexMgr2Json(pSyncNode->pNextIndex)); + cJSON_AddItemToObject(pRoot, "pMatchIndex", syncIndexMgr2Json(pSyncNode->pMatchIndex)); + + // tla+ log vars + cJSON_AddItemToObject(pRoot, "pLogStore", logStore2Json(pSyncNode->pLogStore)); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->commitIndex); + cJSON_AddStringToObject(pRoot, "commitIndex", u64buf); + + // timer ms init + cJSON_AddNumberToObject(pRoot, "pingBaseLine", pSyncNode->pingBaseLine); + cJSON_AddNumberToObject(pRoot, "electBaseLine", pSyncNode->electBaseLine); + cJSON_AddNumberToObject(pRoot, "hbBaseLine", pSyncNode->hbBaseLine); + + // ping timer + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pPingTimer); + cJSON_AddStringToObject(pRoot, "pPingTimer", u64buf); + cJSON_AddNumberToObject(pRoot, "pingTimerMS", pSyncNode->pingTimerMS); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->pingTimerLogicClock); + cJSON_AddStringToObject(pRoot, "pingTimerLogicClock", u64buf); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->pingTimerLogicClockUser); + cJSON_AddStringToObject(pRoot, "pingTimerLogicClockUser", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpPingTimerCB); + cJSON_AddStringToObject(pRoot, "FpPingTimerCB", u64buf); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->pingTimerCounter); + cJSON_AddStringToObject(pRoot, "pingTimerCounter", u64buf); + + // elect timer + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pElectTimer); + cJSON_AddStringToObject(pRoot, "pElectTimer", u64buf); + cJSON_AddNumberToObject(pRoot, "electTimerMS", pSyncNode->electTimerMS); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->electTimerLogicClock); + cJSON_AddStringToObject(pRoot, "electTimerLogicClock", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpElectTimerCB); + cJSON_AddStringToObject(pRoot, "FpElectTimerCB", u64buf); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->electTimerCounter); + cJSON_AddStringToObject(pRoot, "electTimerCounter", u64buf); + + // heartbeat timer + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pHeartbeatTimer); + cJSON_AddStringToObject(pRoot, "pHeartbeatTimer", u64buf); + cJSON_AddNumberToObject(pRoot, "heartbeatTimerMS", pSyncNode->heartbeatTimerMS); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->heartbeatTimerLogicClock); + cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClock", u64buf); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->heartbeatTimerLogicClockUser); + cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClockUser", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpHeartbeatTimerCB); + cJSON_AddStringToObject(pRoot, "FpHeartbeatTimerCB", u64buf); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->heartbeatTimerCounter); + cJSON_AddStringToObject(pRoot, "heartbeatTimerCounter", u64buf); + + // callback + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnPing); + cJSON_AddStringToObject(pRoot, "FpOnPing", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnPingReply); + cJSON_AddStringToObject(pRoot, "FpOnPingReply", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnRequestVote); + cJSON_AddStringToObject(pRoot, "FpOnRequestVote", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnRequestVoteReply); + cJSON_AddStringToObject(pRoot, "FpOnRequestVoteReply", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnAppendEntries); + cJSON_AddStringToObject(pRoot, "FpOnAppendEntries", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnAppendEntriesReply); + cJSON_AddStringToObject(pRoot, "FpOnAppendEntriesReply", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnTimeout); + cJSON_AddStringToObject(pRoot, "FpOnTimeout", u64buf); + + // restoreFinish + cJSON_AddNumberToObject(pRoot, "restoreFinish", pSyncNode->restoreFinish); + + // snapshot senders + cJSON* pSenders = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "senders", pSenders); + for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) { + cJSON_AddItemToArray(pSenders, snapshotSender2Json((pSyncNode->senders)[i])); + } + + // snapshot receivers + cJSON* pReceivers = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "receiver", snapshotReceiver2Json(pSyncNode->pNewNodeReceiver)); + + // changing + cJSON_AddNumberToObject(pRoot, "changing", pSyncNode->changing); + } + + cJSON* pJson = cJSON_CreateObject(); + cJSON_AddItemToObject(pJson, "SSyncNode", pRoot); + return pJson; +} + +char* syncNode2Str(const SSyncNode* pSyncNode) { + cJSON* pJson = syncNode2Json(pSyncNode); + char* serialized = cJSON_Print(pJson); + cJSON_Delete(pJson); + return serialized; +} + +inline char* syncNode2SimpleStr(const SSyncNode* pSyncNode) { + int32_t len = 256; + char* s = (char*)taosMemoryMalloc(len); + + SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0}; + if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { + pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); + } + SyncIndex logLastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore); + SyncIndex logBeginIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore); + + snprintf(s, len, + "vgId:%d, sync %s, tm:%" PRId64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", snap:%" PRId64 + ", sby:%d, " + "r-num:%d, " + "lcfg:%" PRId64 ", chging:%d, rsto:%d", + pSyncNode->vgId, syncStr(pSyncNode->state), pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex, + logBeginIndex, logLastIndex, snapshot.lastApplyIndex, pSyncNode->pRaftCfg->isStandBy, pSyncNode->replicaNum, + pSyncNode->pRaftCfg->lastConfigIndex, pSyncNode->changing, pSyncNode->restoreFinish); + + return s; +} + +// ping -------------- +int32_t syncNodePing(SSyncNode* pSyncNode, const SRaftId* destRaftId, SyncPing* pMsg) { + syncPingLog2((char*)"==syncNodePing==", pMsg); + int32_t ret = 0; + + SRpcMsg rpcMsg; + syncPing2RpcMsg(pMsg, &rpcMsg); + syncRpcMsgLog2((char*)"==syncNodePing==", &rpcMsg); + + ret = syncNodeSendMsgById(destRaftId, pSyncNode, &rpcMsg); + return ret; +} + +int32_t syncNodePingSelf(SSyncNode* pSyncNode) { + int32_t ret = 0; + SyncPing* pMsg = syncPingBuild3(&pSyncNode->myRaftId, &pSyncNode->myRaftId, pSyncNode->vgId); + ret = syncNodePing(pSyncNode, &pMsg->destId, pMsg); + ASSERT(ret == 0); + + syncPingDestroy(pMsg); + return ret; +} + +int32_t syncNodePingPeers(SSyncNode* pSyncNode) { + int32_t ret = 0; + for (int32_t i = 0; i < pSyncNode->peersNum; ++i) { + SRaftId* destId = &(pSyncNode->peersId[i]); + SyncPing* pMsg = syncPingBuild3(&pSyncNode->myRaftId, destId, pSyncNode->vgId); + ret = syncNodePing(pSyncNode, destId, pMsg); + ASSERT(ret == 0); + syncPingDestroy(pMsg); + } + return ret; +} + +int32_t syncNodePingAll(SSyncNode* pSyncNode) { + int32_t ret = 0; + for (int32_t i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) { + SRaftId* destId = &(pSyncNode->replicasId[i]); + SyncPing* pMsg = syncPingBuild3(&pSyncNode->myRaftId, destId, pSyncNode->vgId); + ret = syncNodePing(pSyncNode, destId, pMsg); + ASSERT(ret == 0); + syncPingDestroy(pMsg); + } + return ret; +} + diff --git a/source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c b/source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c new file mode 100644 index 0000000000000000000000000000000000000000..012382d69d3bcda0a4f6cd2c2daae6f9b7830a99 --- /dev/null +++ b/source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c @@ -0,0 +1,508 @@ +/* + * 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 . + */ + +#define _DEFAULT_SOURCE +#include "syncTest.h" + +// --------------------------------------------- +cJSON* syncRpcMsg2Json(SRpcMsg* pRpcMsg) { + cJSON* pRoot; + + // in compiler optimization, switch case = if else constants + if (pRpcMsg->msgType == TDMT_SYNC_TIMEOUT) { + SyncTimeout* pSyncMsg = syncTimeoutDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); + pRoot = syncTimeout2Json(pSyncMsg); + syncTimeoutDestroy(pSyncMsg); + + } else if (pRpcMsg->msgType == TDMT_SYNC_PING) { + SyncPing* pSyncMsg = syncPingDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); + pRoot = syncPing2Json(pSyncMsg); + syncPingDestroy(pSyncMsg); + + } else if (pRpcMsg->msgType == TDMT_SYNC_PING_REPLY) { + SyncPingReply* pSyncMsg = syncPingReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); + pRoot = syncPingReply2Json(pSyncMsg); + syncPingReplyDestroy(pSyncMsg); + + } else if (pRpcMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) { + SyncClientRequest* pSyncMsg = pRpcMsg->pCont; + pRoot = syncClientRequest2Json(pSyncMsg); + + } else if (pRpcMsg->msgType == TDMT_SYNC_CLIENT_REQUEST_REPLY) { + pRoot = syncRpcUnknownMsg2Json(); + + } else if (pRpcMsg->msgType == TDMT_SYNC_REQUEST_VOTE) { + SyncRequestVote* pSyncMsg = syncRequestVoteDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); + pRoot = syncRequestVote2Json(pSyncMsg); + syncRequestVoteDestroy(pSyncMsg); + + } else if (pRpcMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) { + SyncRequestVoteReply* pSyncMsg = syncRequestVoteReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); + pRoot = syncRequestVoteReply2Json(pSyncMsg); + syncRequestVoteReplyDestroy(pSyncMsg); + + } else if (pRpcMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) { + SyncAppendEntries* pSyncMsg = syncAppendEntriesDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); + pRoot = syncAppendEntries2Json(pSyncMsg); + syncAppendEntriesDestroy(pSyncMsg); + + } else if (pRpcMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) { + SyncAppendEntriesReply* pSyncMsg = syncAppendEntriesReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); + pRoot = syncAppendEntriesReply2Json(pSyncMsg); + syncAppendEntriesReplyDestroy(pSyncMsg); + + } else if (pRpcMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) { + SyncSnapshotSend* pSyncMsg = syncSnapshotSendDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); + pRoot = syncSnapshotSend2Json(pSyncMsg); + syncSnapshotSendDestroy(pSyncMsg); + + } else if (pRpcMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) { + SyncSnapshotRsp* pSyncMsg = syncSnapshotRspDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); + pRoot = syncSnapshotRsp2Json(pSyncMsg); + syncSnapshotRspDestroy(pSyncMsg); + + } else if (pRpcMsg->msgType == TDMT_SYNC_LEADER_TRANSFER) { + SyncLeaderTransfer* pSyncMsg = syncLeaderTransferDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen); + pRoot = syncLeaderTransfer2Json(pSyncMsg); + syncLeaderTransferDestroy(pSyncMsg); + + } else if (pRpcMsg->msgType == TDMT_SYNC_COMMON_RESPONSE) { + pRoot = cJSON_CreateObject(); + char* s; + s = syncUtilPrintBin((char*)(pRpcMsg->pCont), pRpcMsg->contLen); + cJSON_AddStringToObject(pRoot, "pCont", s); + taosMemoryFree(s); + s = syncUtilPrintBin2((char*)(pRpcMsg->pCont), pRpcMsg->contLen); + cJSON_AddStringToObject(pRoot, "pCont2", s); + taosMemoryFree(s); + + } else { + pRoot = cJSON_CreateObject(); + char* s; + s = syncUtilPrintBin((char*)(pRpcMsg->pCont), pRpcMsg->contLen); + cJSON_AddStringToObject(pRoot, "pCont", s); + taosMemoryFree(s); + s = syncUtilPrintBin2((char*)(pRpcMsg->pCont), pRpcMsg->contLen); + cJSON_AddStringToObject(pRoot, "pCont2", s); + taosMemoryFree(s); + } + + cJSON_AddNumberToObject(pRoot, "msgType", pRpcMsg->msgType); + cJSON_AddNumberToObject(pRoot, "contLen", pRpcMsg->contLen); + cJSON_AddNumberToObject(pRoot, "code", pRpcMsg->code); + // cJSON_AddNumberToObject(pRoot, "persist", pRpcMsg->persist); + + cJSON* pJson = cJSON_CreateObject(); + cJSON_AddItemToObject(pJson, "RpcMsg", pRoot); + return pJson; +} + +cJSON* syncRpcUnknownMsg2Json() { + cJSON* pRoot = cJSON_CreateObject(); + cJSON_AddNumberToObject(pRoot, "msgType", TDMT_SYNC_UNKNOWN); + cJSON_AddStringToObject(pRoot, "data", "unknown message"); + + cJSON* pJson = cJSON_CreateObject(); + cJSON_AddItemToObject(pJson, "SyncUnknown", pRoot); + return pJson; +} + +char* syncRpcMsg2Str(SRpcMsg* pRpcMsg) { + cJSON* pJson = syncRpcMsg2Json(pRpcMsg); + char* serialized = cJSON_Print(pJson); + cJSON_Delete(pJson); + return serialized; +} + +// for debug ---------------------- +void syncRpcMsgPrint(SRpcMsg* pMsg) { + char* serialized = syncRpcMsg2Str(pMsg); + printf("syncRpcMsgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void syncRpcMsgPrint2(char* s, SRpcMsg* pMsg) { + char* serialized = syncRpcMsg2Str(pMsg); + printf("syncRpcMsgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void syncRpcMsgLog(SRpcMsg* pMsg) { + char* serialized = syncRpcMsg2Str(pMsg); + sTrace("syncRpcMsgLog | len:%d | %s", (int32_t)strlen(serialized), serialized); + taosMemoryFree(serialized); +} + +void syncRpcMsgLog2(char* s, SRpcMsg* pMsg) { + if (gRaftDetailLog) { + char* serialized = syncRpcMsg2Str(pMsg); + sTrace("syncRpcMsgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); + taosMemoryFree(serialized); + } +} + +cJSON* syncAppendEntriesBatch2Json(const SyncAppendEntriesBatch* pMsg) { + char u64buf[128] = {0}; + cJSON* pRoot = cJSON_CreateObject(); + + if (pMsg != NULL) { + cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); + cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId); + cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); + + cJSON* pSrcId = cJSON_CreateObject(); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr); + cJSON_AddStringToObject(pSrcId, "addr", u64buf); + { + uint64_t u64 = pMsg->srcId.addr; + cJSON* pTmp = pSrcId; + char host[128] = {0}; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId); + cJSON_AddItemToObject(pRoot, "srcId", pSrcId); + + cJSON* pDestId = cJSON_CreateObject(); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr); + cJSON_AddStringToObject(pDestId, "addr", u64buf); + { + uint64_t u64 = pMsg->destId.addr; + cJSON* pTmp = pDestId; + char host[128] = {0}; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); + cJSON_AddItemToObject(pRoot, "destId", pDestId); + + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term); + cJSON_AddStringToObject(pRoot, "term", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->prevLogIndex); + cJSON_AddStringToObject(pRoot, "prevLogIndex", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->prevLogTerm); + cJSON_AddStringToObject(pRoot, "prevLogTerm", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->commitIndex); + cJSON_AddStringToObject(pRoot, "commitIndex", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm); + cJSON_AddStringToObject(pRoot, "privateTerm", u64buf); + + cJSON_AddNumberToObject(pRoot, "dataCount", pMsg->dataCount); + cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); + + int32_t metaArrayLen = sizeof(SOffsetAndContLen) * pMsg->dataCount; // + int32_t entryArrayLen = pMsg->dataLen - metaArrayLen; + + cJSON_AddNumberToObject(pRoot, "metaArrayLen", metaArrayLen); + cJSON_AddNumberToObject(pRoot, "entryArrayLen", entryArrayLen); + + SOffsetAndContLen* metaArr = (SOffsetAndContLen*)(pMsg->data); + + cJSON* pMetaArr = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "metaArr", pMetaArr); + for (int i = 0; i < pMsg->dataCount; ++i) { + cJSON* pMeta = cJSON_CreateObject(); + cJSON_AddNumberToObject(pMeta, "offset", metaArr[i].offset); + cJSON_AddNumberToObject(pMeta, "contLen", metaArr[i].contLen); + cJSON_AddItemToArray(pMetaArr, pMeta); + } + + cJSON* pEntryArr = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "entryArr", pEntryArr); + for (int i = 0; i < pMsg->dataCount; ++i) { + SSyncRaftEntry* pEntry = (SSyncRaftEntry*)(pMsg->data + metaArr[i].offset); + cJSON* pEntryJson = syncEntry2Json(pEntry); + cJSON_AddItemToArray(pEntryArr, pEntryJson); + } + + char* s; + s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen); + cJSON_AddStringToObject(pRoot, "data", s); + taosMemoryFree(s); + s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen); + cJSON_AddStringToObject(pRoot, "data2", s); + taosMemoryFree(s); + } + + cJSON* pJson = cJSON_CreateObject(); + cJSON_AddItemToObject(pJson, "SyncAppendEntriesBatch", pRoot); + return pJson; +} + +char* syncAppendEntriesBatch2Str(const SyncAppendEntriesBatch* pMsg) { + cJSON* pJson = syncAppendEntriesBatch2Json(pMsg); + char* serialized = cJSON_Print(pJson); + cJSON_Delete(pJson); + return serialized; +} + +// for debug ---------------------- +void syncAppendEntriesBatchPrint(const SyncAppendEntriesBatch* pMsg) { + char* serialized = syncAppendEntriesBatch2Str(pMsg); + printf("syncAppendEntriesBatchPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void syncAppendEntriesBatchPrint2(char* s, const SyncAppendEntriesBatch* pMsg) { + char* serialized = syncAppendEntriesBatch2Str(pMsg); + printf("syncAppendEntriesBatchPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void syncAppendEntriesBatchLog(const SyncAppendEntriesBatch* pMsg) { + char* serialized = syncAppendEntriesBatch2Str(pMsg); + sTrace("syncAppendEntriesBatchLog | len:%d | %s", (int32_t)strlen(serialized), serialized); + taosMemoryFree(serialized); +} + +void syncAppendEntriesBatchLog2(char* s, const SyncAppendEntriesBatch* pMsg) { + if (gRaftDetailLog) { + char* serialized = syncAppendEntriesBatch2Str(pMsg); + sLTrace("syncAppendEntriesBatchLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); + taosMemoryFree(serialized); + } +} + +cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg) { + char u64buf[128]; + cJSON* pRoot = cJSON_CreateObject(); + + if (pMsg != NULL) { + cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); + cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId); + cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); + + cJSON* pSrcId = cJSON_CreateObject(); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr); + cJSON_AddStringToObject(pSrcId, "addr", u64buf); + { + uint64_t u64 = pMsg->srcId.addr; + cJSON* pTmp = pSrcId; + char host[128]; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId); + cJSON_AddItemToObject(pRoot, "srcId", pSrcId); + + cJSON* pDestId = cJSON_CreateObject(); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr); + cJSON_AddStringToObject(pDestId, "addr", u64buf); + { + uint64_t u64 = pMsg->destId.addr; + cJSON* pTmp = pDestId; + char host[128]; + uint16_t port; + syncUtilU642Addr(u64, host, sizeof(host), &port); + cJSON_AddStringToObject(pTmp, "addr_host", host); + cJSON_AddNumberToObject(pTmp, "addr_port", port); + } + cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId); + cJSON_AddItemToObject(pRoot, "destId", pDestId); + + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term); + cJSON_AddStringToObject(pRoot, "term", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->startTime); + cJSON_AddStringToObject(pRoot, "startTime", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->beginIndex); + cJSON_AddStringToObject(pRoot, "beginIndex", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->lastIndex); + cJSON_AddStringToObject(pRoot, "lastIndex", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->lastConfigIndex); + cJSON_AddStringToObject(pRoot, "lastConfigIndex", u64buf); + cJSON_AddItemToObject(pRoot, "lastConfig", syncCfg2Json((SSyncCfg*)&(pMsg->lastConfig))); + + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->lastTerm); + cJSON_AddStringToObject(pRoot, "lastTerm", u64buf); + + cJSON_AddNumberToObject(pRoot, "seq", pMsg->seq); + + cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); + char* s; + s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen); + cJSON_AddStringToObject(pRoot, "data", s); + taosMemoryFree(s); + s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen); + cJSON_AddStringToObject(pRoot, "data2", s); + taosMemoryFree(s); + } + + cJSON* pJson = cJSON_CreateObject(); + cJSON_AddItemToObject(pJson, "SyncSnapshotSend", pRoot); + return pJson; +} + +char* syncSnapshotSend2Str(const SyncSnapshotSend* pMsg) { + cJSON* pJson = syncSnapshotSend2Json(pMsg); + char* serialized = cJSON_Print(pJson); + cJSON_Delete(pJson); + return serialized; +} + +// for debug ---------------------- +void syncSnapshotSendPrint(const SyncSnapshotSend* pMsg) { + char* serialized = syncSnapshotSend2Str(pMsg); + printf("syncSnapshotSendPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void syncSnapshotSendPrint2(char* s, const SyncSnapshotSend* pMsg) { + char* serialized = syncSnapshotSend2Str(pMsg); + printf("syncSnapshotSendPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void syncSnapshotSendLog(const SyncSnapshotSend* pMsg) { + char* serialized = syncSnapshotSend2Str(pMsg); + sTrace("syncSnapshotSendLog | len:%d | %s", (int32_t)strlen(serialized), serialized); + taosMemoryFree(serialized); +} + +void syncSnapshotSendLog2(char* s, const SyncSnapshotSend* pMsg) { + if (gRaftDetailLog) { + char* serialized = syncSnapshotSend2Str(pMsg); + sTrace("syncSnapshotSendLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); + taosMemoryFree(serialized); + } +} + +cJSON* syncClientRequestBatch2Json(const SyncClientRequestBatch* pMsg) { + char u64buf[128] = {0}; + cJSON* pRoot = cJSON_CreateObject(); + + if (pMsg != NULL) { + cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes); + cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId); + cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType); + cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen); + cJSON_AddNumberToObject(pRoot, "dataCount", pMsg->dataCount); + + SRaftMeta* metaArr = syncClientRequestBatchMetaArr(pMsg); + SRpcMsg* msgArr = syncClientRequestBatchRpcMsgArr(pMsg); + + cJSON* pMetaArr = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "metaArr", pMetaArr); + for (int i = 0; i < pMsg->dataCount; ++i) { + cJSON* pMeta = cJSON_CreateObject(); + cJSON_AddNumberToObject(pMeta, "seqNum", metaArr[i].seqNum); + cJSON_AddNumberToObject(pMeta, "isWeak", metaArr[i].isWeak); + cJSON_AddItemToArray(pMetaArr, pMeta); + } + + cJSON* pMsgArr = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "msgArr", pMsgArr); + for (int i = 0; i < pMsg->dataCount; ++i) { + cJSON* pRpcMsgJson = syncRpcMsg2Json(&msgArr[i]); + cJSON_AddItemToArray(pMsgArr, pRpcMsgJson); + } + + char* s; + s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen); + cJSON_AddStringToObject(pRoot, "data", s); + taosMemoryFree(s); + s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen); + cJSON_AddStringToObject(pRoot, "data2", s); + taosMemoryFree(s); + } + + cJSON* pJson = cJSON_CreateObject(); + cJSON_AddItemToObject(pJson, "SyncClientRequestBatch", pRoot); + return pJson; +} + +char* syncClientRequestBatch2Str(const SyncClientRequestBatch* pMsg) { + cJSON* pJson = syncClientRequestBatch2Json(pMsg); + char* serialized = cJSON_Print(pJson); + cJSON_Delete(pJson); + return serialized; +} + +// for debug ---------------------- +void syncClientRequestBatchPrint(const SyncClientRequestBatch* pMsg) { + char* serialized = syncClientRequestBatch2Str(pMsg); + printf("syncClientRequestBatchPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void syncClientRequestBatchPrint2(char* s, const SyncClientRequestBatch* pMsg) { + char* serialized = syncClientRequestBatch2Str(pMsg); + printf("syncClientRequestBatchPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void syncClientRequestBatchLog(const SyncClientRequestBatch* pMsg) { + char* serialized = syncClientRequestBatch2Str(pMsg); + sTrace("syncClientRequestBatchLog | len:%d | %s", (int32_t)strlen(serialized), serialized); + taosMemoryFree(serialized); +} + +void syncClientRequestBatchLog2(char* s, const SyncClientRequestBatch* pMsg) { + if (gRaftDetailLog) { + char* serialized = syncClientRequestBatch2Str(pMsg); + sLTrace("syncClientRequestBatchLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); + taosMemoryFree(serialized); + } +} + +// for debug ---------------------- +void syncClientRequestPrint(const SyncClientRequest* pMsg) { + char* serialized = syncClientRequest2Str(pMsg); + printf("syncClientRequestPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void syncClientRequestPrint2(char* s, const SyncClientRequest* pMsg) { + char* serialized = syncClientRequest2Str(pMsg); + printf("syncClientRequestPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void syncClientRequestLog(const SyncClientRequest* pMsg) { + char* serialized = syncClientRequest2Str(pMsg); + sTrace("syncClientRequestLog | len:%d | %s", (int32_t)strlen(serialized), serialized); + taosMemoryFree(serialized); +} + +void syncClientRequestLog2(char* s, const SyncClientRequest* pMsg) { + if (gRaftDetailLog) { + char* serialized = syncClientRequest2Str(pMsg); + sTrace("syncClientRequestLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); + taosMemoryFree(serialized); + } +} diff --git a/source/libs/sync/test/sync_test_lib/src/syncRaftCfgDebug.c b/source/libs/sync/test/sync_test_lib/src/syncRaftCfgDebug.c new file mode 100644 index 0000000000000000000000000000000000000000..88b697fbf14e463772c48ac569e81876175624c4 --- /dev/null +++ b/source/libs/sync/test/sync_test_lib/src/syncRaftCfgDebug.c @@ -0,0 +1,19 @@ +/* + * 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 . + */ + +#define _DEFAULT_SOURCE +#include "syncTest.h" + + diff --git a/source/libs/sync/test/sync_test_lib/src/syncRaftEntryDebug.c b/source/libs/sync/test/sync_test_lib/src/syncRaftEntryDebug.c new file mode 100644 index 0000000000000000000000000000000000000000..8179b24d29644e47abf7fc6d1807d37d561c490c --- /dev/null +++ b/source/libs/sync/test/sync_test_lib/src/syncRaftEntryDebug.c @@ -0,0 +1,222 @@ +/* + * 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 . + */ + +#define _DEFAULT_SOURCE +#include "syncTest.h" + +cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry) { + char u64buf[128] = {0}; + cJSON* pRoot = cJSON_CreateObject(); + + if (pEntry != NULL) { + cJSON_AddNumberToObject(pRoot, "bytes", pEntry->bytes); + cJSON_AddNumberToObject(pRoot, "msgType", pEntry->msgType); + cJSON_AddNumberToObject(pRoot, "originalRpcType", pEntry->originalRpcType); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pEntry->seqNum); + cJSON_AddStringToObject(pRoot, "seqNum", u64buf); + cJSON_AddNumberToObject(pRoot, "isWeak", pEntry->isWeak); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pEntry->term); + cJSON_AddStringToObject(pRoot, "term", u64buf); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pEntry->index); + cJSON_AddStringToObject(pRoot, "index", u64buf); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pEntry->rid); + cJSON_AddStringToObject(pRoot, "rid", u64buf); + cJSON_AddNumberToObject(pRoot, "dataLen", pEntry->dataLen); + + char* s; + s = syncUtilPrintBin((char*)(pEntry->data), pEntry->dataLen); + cJSON_AddStringToObject(pRoot, "data", s); + taosMemoryFree(s); + + s = syncUtilPrintBin2((char*)(pEntry->data), pEntry->dataLen); + cJSON_AddStringToObject(pRoot, "data2", s); + taosMemoryFree(s); + } + + cJSON* pJson = cJSON_CreateObject(); + cJSON_AddItemToObject(pJson, "SSyncRaftEntry", pRoot); + return pJson; +} + +char* syncEntry2Str(const SSyncRaftEntry* pEntry) { + cJSON* pJson = syncEntry2Json(pEntry); + char* serialized = cJSON_Print(pJson); + cJSON_Delete(pJson); + return serialized; +} + +// for debug ---------------------- +void syncEntryPrint(const SSyncRaftEntry* pObj) { + char* serialized = syncEntry2Str(pObj); + printf("syncEntryPrint | len:%zu | %s \n", strlen(serialized), serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void syncEntryPrint2(char* s, const SSyncRaftEntry* pObj) { + char* serialized = syncEntry2Str(pObj); + printf("syncEntryPrint2 | len:%zu | %s | %s \n", strlen(serialized), s, serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void syncEntryLog(const SSyncRaftEntry* pObj) { + char* serialized = syncEntry2Str(pObj); + sTrace("syncEntryLog | len:%zu | %s", strlen(serialized), serialized); + taosMemoryFree(serialized); +} + +void syncEntryLog2(char* s, const SSyncRaftEntry* pObj) { + char* serialized = syncEntry2Str(pObj); + sTrace("syncEntryLog2 | len:%zu | %s | %s", strlen(serialized), s, serialized); + taosMemoryFree(serialized); +} + +//----------------------------------- +cJSON* raftCache2Json(SRaftEntryHashCache* pCache) { + char u64buf[128] = {0}; + cJSON* pRoot = cJSON_CreateObject(); + + if (pCache != NULL) { + taosThreadMutexLock(&pCache->mutex); + + snprintf(u64buf, sizeof(u64buf), "%p", pCache->pSyncNode); + cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); + cJSON_AddNumberToObject(pRoot, "currentCount", pCache->currentCount); + cJSON_AddNumberToObject(pRoot, "maxCount", pCache->maxCount); + cJSON* pEntries = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "entries", pEntries); + + SSyncRaftEntry* pIter = (SSyncRaftEntry*)taosHashIterate(pCache->pEntryHash, NULL); + if (pIter != NULL) { + SSyncRaftEntry* pEntry = (SSyncRaftEntry*)pIter; + cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry)); + } + while (pIter) { + pIter = taosHashIterate(pCache->pEntryHash, pIter); + if (pIter != NULL) { + SSyncRaftEntry* pEntry = (SSyncRaftEntry*)pIter; + cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry)); + } + } + + taosThreadMutexUnlock(&pCache->mutex); + } + + cJSON* pJson = cJSON_CreateObject(); + cJSON_AddItemToObject(pJson, "SRaftEntryHashCache", pRoot); + return pJson; +} + +char* raftCache2Str(SRaftEntryHashCache* pCache) { + cJSON* pJson = raftCache2Json(pCache); + char* serialized = cJSON_Print(pJson); + cJSON_Delete(pJson); + return serialized; +} + +void raftCachePrint(SRaftEntryHashCache* pCache) { + char* serialized = raftCache2Str(pCache); + printf("raftCachePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void raftCachePrint2(char* s, SRaftEntryHashCache* pCache) { + char* serialized = raftCache2Str(pCache); + printf("raftCachePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void raftCacheLog(SRaftEntryHashCache* pCache) { + char* serialized = raftCache2Str(pCache); + sTrace("raftCacheLog | len:%d | %s", (int32_t)strlen(serialized), serialized); + taosMemoryFree(serialized); +} + +void raftCacheLog2(char* s, SRaftEntryHashCache* pCache) { + if (gRaftDetailLog) { + char* serialized = raftCache2Str(pCache); + sLTrace("raftCacheLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); + taosMemoryFree(serialized); + } +} + +cJSON* raftEntryCache2Json(SRaftEntryCache* pCache) { + char u64buf[128] = {0}; + cJSON* pRoot = cJSON_CreateObject(); + + if (pCache != NULL) { + taosThreadMutexLock(&pCache->mutex); + + snprintf(u64buf, sizeof(u64buf), "%p", pCache->pSyncNode); + cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); + cJSON_AddNumberToObject(pRoot, "currentCount", pCache->currentCount); + cJSON_AddNumberToObject(pRoot, "maxCount", pCache->maxCount); + cJSON* pEntries = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "entries", pEntries); + + SSkipListIterator* pIter = tSkipListCreateIter(pCache->pSkipList); + while (tSkipListIterNext(pIter)) { + SSkipListNode* pNode = tSkipListIterGet(pIter); + ASSERT(pNode != NULL); + SSyncRaftEntry* pEntry = (SSyncRaftEntry*)SL_GET_NODE_DATA(pNode); + cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry)); + } + tSkipListDestroyIter(pIter); + + taosThreadMutexUnlock(&pCache->mutex); + } + + cJSON* pJson = cJSON_CreateObject(); + cJSON_AddItemToObject(pJson, "SRaftEntryCache", pRoot); + return pJson; +} + +char* raftEntryCache2Str(SRaftEntryCache* pObj) { + cJSON* pJson = raftEntryCache2Json(pObj); + char* serialized = cJSON_Print(pJson); + cJSON_Delete(pJson); + return serialized; +} + +void raftEntryCachePrint(SRaftEntryCache* pObj) { + char* serialized = raftEntryCache2Str(pObj); + printf("raftEntryCachePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void raftEntryCachePrint2(char* s, SRaftEntryCache* pObj) { + char* serialized = raftEntryCache2Str(pObj); + printf("raftEntryCachePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void raftEntryCacheLog(SRaftEntryCache* pObj) { + char* serialized = raftEntryCache2Str(pObj); + sTrace("raftEntryCacheLog | len:%d | %s", (int32_t)strlen(serialized), serialized); + taosMemoryFree(serialized); +} + +void raftEntryCacheLog2(char* s, SRaftEntryCache* pObj) { + if (gRaftDetailLog) { + char* serialized = raftEntryCache2Str(pObj); + sLTrace("raftEntryCacheLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); + taosMemoryFree(serialized); + } +} diff --git a/source/libs/sync/test/sync_test_lib/src/syncRaftLogDebug.c b/source/libs/sync/test/sync_test_lib/src/syncRaftLogDebug.c new file mode 100644 index 0000000000000000000000000000000000000000..53e414ccfd8824dce7d0cff7779c67d40ff93cd9 --- /dev/null +++ b/source/libs/sync/test/sync_test_lib/src/syncRaftLogDebug.c @@ -0,0 +1,182 @@ +/* + * 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 . + */ + +#define _DEFAULT_SOURCE +#include "syncTest.h" + +cJSON* logStore2Json(SSyncLogStore* pLogStore) { + char u64buf[128] = {0}; + SSyncLogStoreData* pData = (SSyncLogStoreData*)pLogStore->data; + cJSON* pRoot = cJSON_CreateObject(); + + if (pData != NULL && pData->pWal != NULL) { + snprintf(u64buf, sizeof(u64buf), "%p", pData->pSyncNode); + cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pData->pWal); + cJSON_AddStringToObject(pRoot, "pWal", u64buf); + + SyncIndex beginIndex = raftLogBeginIndex(pLogStore); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, beginIndex); + cJSON_AddStringToObject(pRoot, "beginIndex", u64buf); + + SyncIndex endIndex = raftLogEndIndex(pLogStore); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, endIndex); + cJSON_AddStringToObject(pRoot, "endIndex", u64buf); + + int32_t count = raftLogEntryCount(pLogStore); + cJSON_AddNumberToObject(pRoot, "entryCount", count); + + snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogWriteIndex(pLogStore)); + cJSON_AddStringToObject(pRoot, "WriteIndex", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%d", raftLogIsEmpty(pLogStore)); + cJSON_AddStringToObject(pRoot, "IsEmpty", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogLastIndex(pLogStore)); + cJSON_AddStringToObject(pRoot, "LastIndex", u64buf); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, raftLogLastTerm(pLogStore)); + cJSON_AddStringToObject(pRoot, "LastTerm", u64buf); + + cJSON* pEntries = cJSON_CreateArray(); + cJSON_AddItemToObject(pRoot, "pEntries", pEntries); + + if (!raftLogIsEmpty(pLogStore)) { + for (SyncIndex i = beginIndex; i <= endIndex; ++i) { + SSyncRaftEntry* pEntry = NULL; + raftLogGetEntry(pLogStore, i, &pEntry); + + cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry)); + syncEntryDestory(pEntry); + } + } + } + + cJSON* pJson = cJSON_CreateObject(); + cJSON_AddItemToObject(pJson, "SSyncLogStore", pRoot); + return pJson; +} + +char* logStore2Str(SSyncLogStore* pLogStore) { + cJSON* pJson = logStore2Json(pLogStore); + char* serialized = cJSON_Print(pJson); + cJSON_Delete(pJson); + return serialized; +} + +cJSON* logStoreSimple2Json(SSyncLogStore* pLogStore) { + char u64buf[128] = {0}; + SSyncLogStoreData* pData = (SSyncLogStoreData*)pLogStore->data; + cJSON* pRoot = cJSON_CreateObject(); + + if (pData != NULL && pData->pWal != NULL) { + snprintf(u64buf, sizeof(u64buf), "%p", pData->pSyncNode); + cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf); + snprintf(u64buf, sizeof(u64buf), "%p", pData->pWal); + cJSON_AddStringToObject(pRoot, "pWal", u64buf); + + SyncIndex beginIndex = raftLogBeginIndex(pLogStore); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, beginIndex); + cJSON_AddStringToObject(pRoot, "beginIndex", u64buf); + + SyncIndex endIndex = raftLogEndIndex(pLogStore); + snprintf(u64buf, sizeof(u64buf), "%" PRId64, endIndex); + cJSON_AddStringToObject(pRoot, "endIndex", u64buf); + + int32_t count = raftLogEntryCount(pLogStore); + cJSON_AddNumberToObject(pRoot, "entryCount", count); + + snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogWriteIndex(pLogStore)); + cJSON_AddStringToObject(pRoot, "WriteIndex", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%d", raftLogIsEmpty(pLogStore)); + cJSON_AddStringToObject(pRoot, "IsEmpty", u64buf); + + snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogLastIndex(pLogStore)); + cJSON_AddStringToObject(pRoot, "LastIndex", u64buf); + snprintf(u64buf, sizeof(u64buf), "%" PRIu64, raftLogLastTerm(pLogStore)); + cJSON_AddStringToObject(pRoot, "LastTerm", u64buf); + } + + cJSON* pJson = cJSON_CreateObject(); + cJSON_AddItemToObject(pJson, "SSyncLogStoreSimple", pRoot); + return pJson; +} + +char* logStoreSimple2Str(SSyncLogStore* pLogStore) { + cJSON* pJson = logStoreSimple2Json(pLogStore); + char* serialized = cJSON_Print(pJson); + cJSON_Delete(pJson); + return serialized; +} + +// for debug ----------------- +void logStorePrint(SSyncLogStore* pLogStore) { + char* serialized = logStore2Str(pLogStore); + printf("logStorePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void logStorePrint2(char* s, SSyncLogStore* pLogStore) { + char* serialized = logStore2Str(pLogStore); + printf("logStorePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void logStoreLog(SSyncLogStore* pLogStore) { + if (gRaftDetailLog) { + char* serialized = logStore2Str(pLogStore); + sLTrace("logStoreLog | len:%d | %s", (int32_t)strlen(serialized), serialized); + taosMemoryFree(serialized); + } +} + +void logStoreLog2(char* s, SSyncLogStore* pLogStore) { + if (gRaftDetailLog) { + char* serialized = logStore2Str(pLogStore); + sLTrace("logStoreLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); + taosMemoryFree(serialized); + } +} + +// for debug ----------------- +void logStoreSimplePrint(SSyncLogStore* pLogStore) { + char* serialized = logStoreSimple2Str(pLogStore); + printf("logStoreSimplePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void logStoreSimplePrint2(char* s, SSyncLogStore* pLogStore) { + char* serialized = logStoreSimple2Str(pLogStore); + printf("logStoreSimplePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized); + fflush(NULL); + taosMemoryFree(serialized); +} + +void logStoreSimpleLog(SSyncLogStore* pLogStore) { + char* serialized = logStoreSimple2Str(pLogStore); + sTrace("logStoreSimpleLog | len:%d | %s", (int32_t)strlen(serialized), serialized); + taosMemoryFree(serialized); +} + +void logStoreSimpleLog2(char* s, SSyncLogStore* pLogStore) { + if (gRaftDetailLog) { + char* serialized = logStoreSimple2Str(pLogStore); + sTrace("logStoreSimpleLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized); + taosMemoryFree(serialized); + } +} diff --git a/source/libs/tdb/inc/tdb.h b/source/libs/tdb/inc/tdb.h index 3d92d164b49c1a2804fd3eab3452ff5d386b080c..7ab2bc399579ffd5dc07dc81628a9da85ce9bbad 100644 --- a/source/libs/tdb/inc/tdb.h +++ b/source/libs/tdb/inc/tdb.h @@ -36,6 +36,7 @@ int32_t tdbClose(TDB *pDb); int32_t tdbBegin(TDB *pDb, TXN *pTxn); int32_t tdbCommit(TDB *pDb, TXN *pTxn); int32_t tdbPostCommit(TDB *pDb, TXN *pTxn); +int32_t tdbPrepareAsyncCommit(TDB *pDb, TXN *pTxn); int32_t tdbAbort(TDB *pDb, TXN *pTxn); int32_t tdbAlter(TDB *pDb, int pages); diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 19580d486a7242166cf67024bf02f3e193eefb62..e3860f85c6f0c199e441c24ee710bdb656fca088 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -140,6 +140,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, char const *tbname, SPg // tdbUnrefPage(pPage); tdbPCacheRelease(pPager->pCache, pPage, &txn); tdbCommit(pPager->pEnv, &txn); + tdbPostCommit(pPager->pEnv, &txn); tdbTxnClose(&txn); } @@ -1715,16 +1716,20 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) { memcpy(pKey, cd.pKey, cd.kLen); if (ppVal) { - // TODO: vLen may be zero - pVal = tdbRealloc(*ppVal, cd.vLen); - if (pVal == NULL) { - tdbFree(pKey); - return -1; + if (cd.vLen > 0) { + pVal = tdbRealloc(*ppVal, cd.vLen); + if (pVal == NULL) { + tdbFree(pKey); + return -1; + } + + memcpy(pVal, cd.pVal, cd.vLen); + } else { + pVal = NULL; } *ppVal = pVal; *vLen = cd.vLen; - memcpy(pVal, cd.pVal, cd.vLen); } ret = tdbBtcMoveToNext(pBtc); diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 855e3510f2355729ab66a9e17dc32b91cd78e913..5aff5b7bb2d649d0caad06433419dd19b4f34013 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -138,7 +138,24 @@ int32_t tdbPostCommit(TDB *pDb, TXN *pTxn) { for (pPager = pDb->pgrList; pPager; pPager = pPager->pNext) { ret = tdbPagerPostCommit(pPager, pTxn); if (ret < 0) { - tdbError("failed to commit pager since %s. dbName:%s, txnId:%" PRId64, tstrerror(terrno), pDb->dbName, pTxn->txnId); + tdbError("failed to commit pager since %s. dbName:%s, txnId:%" PRId64, tstrerror(terrno), pDb->dbName, + pTxn->txnId); + return -1; + } + } + + return 0; +} + +int32_t tdbPrepareAsyncCommit(TDB *pDb, TXN *pTxn) { + SPager *pPager; + int ret; + + for (pPager = pDb->pgrList; pPager; pPager = pPager->pNext) { + ret = tdbPagerPrepareAsyncCommit(pPager, pTxn); + if (ret < 0) { + tdbError("failed to commit pager since %s. dbName:%s, txnId:%" PRId64, tstrerror(terrno), pDb->dbName, + pTxn->txnId); return -1; } } diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index cee54c1a73f43fb12865a06a94f5c888e134280f..c3ae1dc7395cbef32b153741b7548d365203eb4e 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -287,6 +287,10 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) { return -1; } + return 0; +} + +int tdbPagerPostCommit(SPager *pPager, TXN *pTxn) { // remove the journal file if (tdbOsClose(pPager->jfd) < 0) { tdbError("failed to close jfd due to %s. file:%s", strerror(errno), pPager->jFileName); @@ -305,15 +309,54 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) { return 0; } -int tdbPagerPostCommit(SPager *pPager, TXN *pTxn) { - if (tdbOsRemove(pPager->jFileName) < 0 && errno != ENOENT) { - tdbError("failed to remove file due to %s. file:%s", strerror(errno), pPager->jFileName); +int tdbPagerPrepareAsyncCommit(SPager *pPager, TXN *pTxn) { + SPage *pPage; + int ret; + + // sync the journal file + ret = tdbOsFSync(pPager->jfd); + if (ret < 0) { + tdbError("failed to fsync jfd due to %s. jFileName:%s", strerror(errno), pPager->jFileName); terrno = TAOS_SYSTEM_ERROR(errno); return -1; } - pPager->inTran = 0; + // loop to write the dirty pages to file + SRBTreeIter iter = tRBTreeIterCreate(&pPager->rbt, 1); + SRBTreeNode *pNode = NULL; + while ((pNode = tRBTreeIterNext(&iter)) != NULL) { + pPage = (SPage *)pNode; + if (pPage->isLocal) continue; + ret = tdbPagerWritePageToDB(pPager, pPage); + if (ret < 0) { + tdbError("failed to write page to db since %s", tstrerror(terrno)); + return -1; + } + } + + tdbTrace("tdbttl commit:%p, %d/%d", pPager, pPager->dbOrigSize, pPager->dbFileSize); + pPager->dbOrigSize = pPager->dbFileSize; + + // release the page + iter = tRBTreeIterCreate(&pPager->rbt, 1); + while ((pNode = tRBTreeIterNext(&iter)) != NULL) { + pPage = (SPage *)pNode; + if (pPage->isLocal) continue; + pPage->isDirty = 0; + + tRBTreeDrop(&pPager->rbt, (SRBTreeNode *)pPage); + tdbPCacheRelease(pPager->pCache, pPage, pTxn); + } + /* + tRBTreeCreate(&pPager->rbt, pageCmpFn); + // sync the db file + if (tdbOsFSync(pPager->fd) < 0) { + tdbError("failed to fsync fd due to %s. file:%s", strerror(errno), pPager->dbFileName); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + */ return 0; } diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index b45747c9726aa49857843f859b2c66f20374c214..e5ece98b28d24eca7c2f9d72f1a72888807b6bb1 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -191,6 +191,7 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage); int tdbPagerBegin(SPager *pPager, TXN *pTxn); int tdbPagerCommit(SPager *pPager, TXN *pTxn); int tdbPagerPostCommit(SPager *pPager, TXN *pTxn); +int tdbPagerPrepareAsyncCommit(SPager *pPager, TXN *pTxn); int tdbPagerAbort(SPager *pPager, TXN *pTxn); int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage)(SPage *, void *, int), void *arg, TXN *pTxn); diff --git a/source/libs/tfs/test/tfsTest.cpp b/source/libs/tfs/test/tfsTest.cpp index f4b0adf1f7256618f80e09ce234997719edbb004..df37630fd784e0e561b2675202a9a714370865cc 100644 --- a/source/libs/tfs/test/tfsTest.cpp +++ b/source/libs/tfs/test/tfsTest.cpp @@ -42,7 +42,7 @@ TEST_F(TfsTest, 01_Open_Close) { STfs *pTfs = tfsOpen(&dCfg, 1); ASSERT_EQ(pTfs, nullptr); - taosMkDir(root); + taosMulMkDir(root); pTfs = tfsOpen(&dCfg, 1); ASSERT_NE(pTfs, nullptr); diff --git a/source/libs/transport/inc/transComm.h b/source/libs/transport/inc/transComm.h index b83f84e3f2ea1a0e008a1277599848b6c3b6ea43..2354f0f95943223601d780321b9f375408ac589d 100644 --- a/source/libs/transport/inc/transComm.h +++ b/source/libs/transport/inc/transComm.h @@ -428,6 +428,7 @@ void transDestoryExHandle(void* handle); int32_t transGetRefMgt(); int32_t transGetInstMgt(); +void transHttpEnvDestroy(); #ifdef __cplusplus } #endif diff --git a/source/libs/transport/src/thttp.c b/source/libs/transport/src/thttp.c index 92989a45f5cb61600aa45c599ae919e95313c24b..00854b5ee596dd8af75b3bc6abe5e1f59b5aa1ed 100644 --- a/source/libs/transport/src/thttp.c +++ b/source/libs/transport/src/thttp.c @@ -20,21 +20,52 @@ #include "thttp.h" #include "taoserror.h" #include "tlog.h" +#include "transComm.h" // clang-format on #define HTTP_RECV_BUF_SIZE 1024 +typedef struct SHttpModule { + uv_loop_t* loop; + SAsyncPool* asyncPool; + TdThread thread; +} SHttpModule; + +typedef struct SHttpMsg { + queue q; + char* server; + int32_t port; + char* cont; + int32_t len; + EHttpCompFlag flag; + int8_t quit; + SHttpModule* http; + +} SHttpMsg; + typedef struct SHttpClient { - uv_connect_t conn; - uv_tcp_t tcp; - uv_write_t req; - uv_buf_t* wbuf; - char* rbuf; - char* addr; - uint16_t port; + uv_connect_t conn; + uv_tcp_t tcp; + uv_write_t req; + uv_buf_t* wbuf; + char* rbuf; + char* addr; + uint16_t port; + struct sockaddr_in dest; } SHttpClient; +static TdThreadOnce transHttpInit = PTHREAD_ONCE_INIT; +static SHttpModule* thttp = NULL; +static void transHttpEnvInit(); + +static void httpHandleReq(SHttpMsg* msg); +static void httpHandleQuit(SHttpMsg* msg); +static int32_t httpSendQuit(); + +static int32_t taosSendHttpReportImpl(const char* server, uint16_t port, char* pCont, int32_t contLen, + EHttpCompFlag flag); + static int32_t taosBuildHttpHeader(const char* server, int32_t contLen, char* pHead, int32_t headLen, EHttpCompFlag flag) { if (flag == HTTP_FLAT) { @@ -53,6 +84,7 @@ static int32_t taosBuildHttpHeader(const char* server, int32_t contLen, char* pH "Content-Length: %d\n\n", server, contLen); } else { + terrno = TSDB_CODE_INVALID_CFG; return -1; } } @@ -126,116 +158,217 @@ _OVER: return code; } +static FORCE_INLINE int32_t taosBuildDstAddr(const char* server, uint16_t port, struct sockaddr_in* dest) { + uint32_t ip = taosGetIpv4FromFqdn(server); + if (ip == 0xffffffff) { + tError("http-report failed to get http server:%s since %s", server, errno == 0 ? "invalid http server" : terrstr()); + return -1; + } + char buf[128] = {0}; + tinet_ntoa(buf, ip); + uv_ip4_addr(buf, port, dest); + return 0; +} + +static void* httpThread(void* arg) { + SHttpModule* http = (SHttpModule*)arg; + setThreadName("http-cli-send-thread"); + uv_run(http->loop, UV_RUN_DEFAULT); + return NULL; +} + +static void httpDestroyMsg(SHttpMsg* msg) { + if (msg == NULL) return; + + taosMemoryFree(msg->server); + taosMemoryFree(msg->cont); + taosMemoryFree(msg); +} +static void httpAsyncCb(uv_async_t* handle) { + SAsyncItem* item = handle->data; + SHttpModule* http = item->pThrd; + + SHttpMsg *msg = NULL, *quitMsg = NULL; + + queue wq; + taosThreadMutexLock(&item->mtx); + QUEUE_MOVE(&item->qmsg, &wq); + taosThreadMutexUnlock(&item->mtx); + + int count = 0; + while (!QUEUE_IS_EMPTY(&wq)) { + queue* h = QUEUE_HEAD(&wq); + QUEUE_REMOVE(h); + msg = QUEUE_DATA(h, SHttpMsg, q); + if (msg->quit) { + quitMsg = msg; + } else { + httpHandleReq(msg); + } + } + if (quitMsg) httpHandleQuit(quitMsg); +} + static FORCE_INLINE void destroyHttpClient(SHttpClient* cli) { + taosMemoryFree(cli->wbuf[0].base); + taosMemoryFree(cli->wbuf[1].base); taosMemoryFree(cli->wbuf); taosMemoryFree(cli->rbuf); taosMemoryFree(cli->addr); taosMemoryFree(cli); } + static FORCE_INLINE void clientCloseCb(uv_handle_t* handle) { SHttpClient* cli = handle->data; destroyHttpClient(cli); } + static FORCE_INLINE void clientAllocBuffCb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { SHttpClient* cli = handle->data; buf->base = cli->rbuf; buf->len = HTTP_RECV_BUF_SIZE; } + static FORCE_INLINE void clientRecvCb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) { SHttpClient* cli = handle->data; if (nread < 0) { - uError("http-report recv error:%s", uv_err_name(nread)); + tError("http-report recv error:%s", uv_err_name(nread)); } else { - uTrace("http-report succ to recv %d bytes", (int32_t)nread); + tTrace("http-report succ to recv %d bytes", (int32_t)nread); } if (!uv_is_closing((uv_handle_t*)&cli->tcp)) { uv_close((uv_handle_t*)&cli->tcp, clientCloseCb); - } else { - destroyHttpClient(cli); } } static void clientSentCb(uv_write_t* req, int32_t status) { SHttpClient* cli = req->data; if (status != 0) { - terrno = TAOS_SYSTEM_ERROR(status); - uError("http-report failed to send data %s", uv_strerror(status)); + tError("http-report failed to send data, reason: %s, dst:%s:%d", uv_strerror(status), cli->addr, cli->port); if (!uv_is_closing((uv_handle_t*)&cli->tcp)) { uv_close((uv_handle_t*)&cli->tcp, clientCloseCb); - } else { - destroyHttpClient(cli); } return; } else { - uTrace("http-report succ to send data"); + tTrace("http-report succ to send data"); } status = uv_read_start((uv_stream_t*)&cli->tcp, clientAllocBuffCb, clientRecvCb); if (status != 0) { - terrno = TAOS_SYSTEM_ERROR(status); - uError("http-report failed to recv data,reason:%s, dst:%s:%d", uv_strerror(status), cli->addr, cli->port); + tError("http-report failed to recv data,reason:%s, dst:%s:%d", uv_strerror(status), cli->addr, cli->port); if (!uv_is_closing((uv_handle_t*)&cli->tcp)) { uv_close((uv_handle_t*)&cli->tcp, clientCloseCb); - } else { - destroyHttpClient(cli); } } } static void clientConnCb(uv_connect_t* req, int32_t status) { SHttpClient* cli = req->data; if (status != 0) { - terrno = TAOS_SYSTEM_ERROR(status); - uError("http-report failed to conn to server, reason:%s, dst:%s:%d", uv_strerror(status), cli->addr, cli->port); + tError("http-report failed to conn to server, reason:%s, dst:%s:%d", uv_strerror(status), cli->addr, cli->port); if (!uv_is_closing((uv_handle_t*)&cli->tcp)) { uv_close((uv_handle_t*)&cli->tcp, clientCloseCb); - } else { - destroyHttpClient(cli); } return; } status = uv_write(&cli->req, (uv_stream_t*)&cli->tcp, cli->wbuf, 2, clientSentCb); if (0 != status) { - terrno = TAOS_SYSTEM_ERROR(status); - uError("http-report failed to send data,reason:%s, dst:%s:%d", uv_strerror(status), cli->addr, cli->port); + tError("http-report failed to send data,reason:%s, dst:%s:%d", uv_strerror(status), cli->addr, cli->port); if (!uv_is_closing((uv_handle_t*)&cli->tcp)) { uv_close((uv_handle_t*)&cli->tcp, clientCloseCb); - } else { - destroyHttpClient(cli); } } } -static FORCE_INLINE int32_t taosBuildDstAddr(const char* server, uint16_t port, struct sockaddr_in* dest) { - uint32_t ip = taosGetIpv4FromFqdn(server); - if (ip == 0xffffffff) { - terrno = TAOS_SYSTEM_ERROR(errno); - uError("http-report failed to get http server:%s since %s", server, errno == 0 ? "invalid http server" : terrstr()); +int32_t httpSendQuit() { + SHttpMsg* msg = taosMemoryCalloc(1, sizeof(SHttpMsg)); + msg->quit = 1; + + SHttpModule* load = atomic_load_ptr(&thttp); + if (load == NULL) { + httpDestroyMsg(msg); + tError("http-report already released"); return -1; + } else { + msg->http = load; } - char buf[128] = {0}; - tinet_ntoa(buf, ip); - uv_ip4_addr(buf, port, dest); + transAsyncSend(load->asyncPool, &(msg->q)); return 0; } -int32_t taosSendHttpReport(const char* server, uint16_t port, char* pCont, int32_t contLen, EHttpCompFlag flag) { - struct sockaddr_in dest = {0}; - if (taosBuildDstAddr(server, port, &dest) < 0) { + +static int32_t taosSendHttpReportImpl(const char* server, uint16_t port, char* pCont, int32_t contLen, + EHttpCompFlag flag) { + SHttpMsg* msg = taosMemoryMalloc(sizeof(SHttpMsg)); + msg->server = strdup(server); + msg->port = port; + msg->cont = taosMemoryMalloc(contLen); + memcpy(msg->cont, pCont, contLen); + msg->len = contLen; + msg->flag = flag; + msg->quit = 0; + + SHttpModule* load = atomic_load_ptr(&thttp); + if (load == NULL) { + httpDestroyMsg(msg); + tError("http-report already released"); return -1; + } else { + msg->http = load; + transAsyncSend(load->asyncPool, &(msg->q)); + } + + return 0; +} + +static void httpDestroyClientCb(uv_handle_t* handle) { + SHttpClient* http = handle->data; + destroyHttpClient(http); +} +static void httpWalkCb(uv_handle_t* handle, void* arg) { + // impl later + if (!uv_is_closing(handle)) { + uv_handle_type type = uv_handle_get_type(handle); + if (uv_handle_get_type(handle) == UV_TCP) { + uv_close(handle, httpDestroyClientCb); + } else { + uv_close(handle, NULL); + } } - if (flag == HTTP_GZIP) { - int32_t dstLen = taosCompressHttpRport(pCont, contLen); + return; +} +static void httpHandleQuit(SHttpMsg* msg) { + SHttpModule* http = msg->http; + taosMemoryFree(msg); + + uv_walk(http->loop, httpWalkCb, NULL); +} +static void httpHandleReq(SHttpMsg* msg) { + SHttpModule* http = msg->http; + + struct sockaddr_in dest = {0}; + if (taosBuildDstAddr(msg->server, msg->port, &dest) < 0) { + goto END; + } + if (msg->flag == HTTP_GZIP) { + int32_t dstLen = taosCompressHttpRport(msg->cont, msg->len); if (dstLen > 0) { - contLen = dstLen; + msg->len = dstLen; } else { - flag = HTTP_FLAT; + msg->flag = HTTP_FLAT; + } + if (dstLen < 0) { + goto END; } } - terrno = 0; - char header[2048] = {0}; - int32_t headLen = taosBuildHttpHeader(server, contLen, header, sizeof(header), flag); + int32_t len = 2048; + char* header = taosMemoryCalloc(1, len); + int32_t headLen = taosBuildHttpHeader(msg->server, msg->len, header, len, msg->flag); + if (headLen < 0) { + taosMemoryFree(header); + goto END; + } uv_buf_t* wb = taosMemoryCalloc(2, sizeof(uv_buf_t)); - wb[0] = uv_buf_init((char*)header, headLen); // stack var - wb[1] = uv_buf_init((char*)pCont, contLen); // heap var + wb[0] = uv_buf_init((char*)header, strlen(header)); // heap var + wb[1] = uv_buf_init((char*)msg->cont, msg->len); // heap var SHttpClient* cli = taosMemoryCalloc(1, sizeof(SHttpClient)); cli->conn.data = cli; @@ -243,41 +376,71 @@ int32_t taosSendHttpReport(const char* server, uint16_t port, char* pCont, int32 cli->req.data = cli; cli->wbuf = wb; cli->rbuf = taosMemoryCalloc(1, HTTP_RECV_BUF_SIZE); - cli->addr = tstrdup(server); - cli->port = port; + cli->addr = msg->server; + cli->port = msg->port; + cli->dest = dest; + + taosMemoryFree(msg); + + uv_tcp_init(http->loop, &cli->tcp); - uv_loop_t* loop = taosMemoryMalloc(sizeof(uv_loop_t)); - int err = uv_loop_init(loop); - if (err != 0) { - uError("http-report failed to init uv_loop, reason: %s", uv_strerror(err)); - taosMemoryFree(loop); - terrno = TAOS_SYSTEM_ERROR(err); - destroyHttpClient(cli); - return terrno; - } - uv_tcp_init(loop, &cli->tcp); // set up timeout to avoid stuck; int32_t fd = taosCreateSocketWithTimeout(5); + int ret = uv_tcp_open((uv_tcp_t*)&cli->tcp, fd); + if (ret != 0) { + tError("http-report failed to open socket, reason:%s, dst:%s:%d", uv_strerror(ret), cli->addr, cli->port); + destroyHttpClient(cli); + return; + } - int ret = uv_tcp_open((uv_tcp_t*)&cli->tcp, fd); + ret = uv_tcp_connect(&cli->conn, &cli->tcp, (const struct sockaddr*)&cli->dest, clientConnCb); if (ret != 0) { - uError("http-report failed to open socket, reason:%s, dst:%s:%d", uv_strerror(ret), cli->addr, cli->port); + tError("http-report failed to connect to http-server, reason:%s, dst:%s:%d", uv_strerror(ret), cli->addr, + cli->port); destroyHttpClient(cli); - uv_stop(loop); - terrno = TAOS_SYSTEM_ERROR(ret); - } else { - ret = uv_tcp_connect(&cli->conn, &cli->tcp, (const struct sockaddr*)&dest, clientConnCb); - if (ret != 0) { - uError("http-report failed to connect to http-server, reason:%s, dst:%s:%d", uv_strerror(ret), cli->addr, - cli->port); - destroyHttpClient(cli); - uv_stop(loop); - terrno = TAOS_SYSTEM_ERROR(ret); - } } + return; + +END: + tError("http-report failed to report, reason: %s, addr: %s:%d", terrstr(), msg->server, msg->port); + httpDestroyMsg(msg); +} + +int32_t taosSendHttpReport(const char* server, uint16_t port, char* pCont, int32_t contLen, EHttpCompFlag flag) { + taosThreadOnce(&transHttpInit, transHttpEnvInit); + return taosSendHttpReportImpl(server, port, pCont, contLen, flag); +} + +static void transHttpEnvInit() { + SHttpModule* http = taosMemoryMalloc(sizeof(SHttpModule)); + + http->loop = taosMemoryMalloc(sizeof(uv_loop_t)); + uv_loop_init(http->loop); + + http->asyncPool = transAsyncPoolCreate(http->loop, 1, http, httpAsyncCb); + + int err = taosThreadCreate(&http->thread, NULL, httpThread, (void*)http); + if (err != 0) { + taosMemoryFree(http->loop); + taosMemoryFree(http); + http = NULL; + } + atomic_store_ptr(&thttp, http); +} + +void transHttpEnvDestroy() { + SHttpModule* load = atomic_load_ptr(&thttp); + if (load == NULL) { + return; + } + httpSendQuit(); + taosThreadJoin(load->thread, NULL); + + TRANS_DESTROY_ASYNC_POOL_MSG(load->asyncPool, SHttpMsg, httpDestroyMsg); + transAsyncPoolDestroy(load->asyncPool); + uv_loop_close(load->loop); + taosMemoryFree(load->loop); + taosMemoryFree(load); - uv_run(loop, UV_RUN_DEFAULT); - uv_loop_close(loop); - taosMemoryFree(loop); - return terrno; + atomic_store_ptr(&thttp, NULL); } diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index 756a8ff2cf7202e7a94eb4bd6ce4186f1d68c27f..d3db4879d10d1307688d75c1fb29a4c9085f4468 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -172,6 +172,8 @@ int32_t rpcInit() { } void rpcCleanup(void) { transCleanup(); + transHttpEnvDestroy(); + return; } diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 126b0b638e4c7611d9e48de0d367aead086b3d17..c3abfa971ec70a173b1f8d38634e29163bc276b5 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -187,18 +187,8 @@ static void cliReleaseUnfinishedMsg(SCliConn* conn) { snprintf(key, sizeof(key), "%s:%d", ip, (int)port); \ } while (0) -#define CONN_HOST_THREAD_IDX1(idx, exh, refId, pThrd) \ - do { \ - if (exh == NULL) { \ - idx = -1; \ - } else { \ - ASYNC_CHECK_HANDLE((exh), refId); \ - pThrd = (SCliThrd*)(exh)->pThrd; \ - } \ - } while (0) -#define CONN_PERSIST_TIME(para) ((para) <= 90000 ? 90000 : (para)) -#define CONN_GET_HOST_THREAD(conn) (conn ? ((SCliConn*)conn)->hostThrd : NULL) -#define CONN_GET_INST_LABEL(conn) (((STrans*)(((SCliThrd*)(conn)->hostThrd)->pTransInst))->label) +#define CONN_PERSIST_TIME(para) ((para) <= 90000 ? 90000 : (para)) +#define CONN_GET_INST_LABEL(conn) (((STrans*)(((SCliThrd*)(conn)->hostThrd)->pTransInst))->label) #define CONN_GET_MSGCTX_BY_AHANDLE(conn, ahandle) \ do { \ @@ -217,6 +207,7 @@ static void cliReleaseUnfinishedMsg(SCliConn* conn) { tDebug("msg found, %" PRIu64 "", ahandle); \ } \ } while (0) + #define CONN_GET_NEXT_SENDMSG(conn) \ do { \ int i = 0; \ @@ -231,21 +222,6 @@ static void cliReleaseUnfinishedMsg(SCliConn* conn) { } \ } while (0) -#define CONN_HANDLE_THREAD_QUIT(thrd) \ - do { \ - if (thrd->quit) { \ - return; \ - } \ - } while (0) - -#define CONN_HANDLE_BROKEN(conn) \ - do { \ - if (conn->broken) { \ - cliHandleExcept(conn); \ - return; \ - } \ - } while (0) - #define CONN_SET_PERSIST_BY_APP(conn) \ do { \ if (conn->status == ConnNormal) { \ @@ -451,7 +427,7 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) { if (pCtx == NULL || pCtx->pSem == NULL) { if (transMsg.info.ahandle == NULL) { - if (REQUEST_NO_RESP(&pMsg->msg) || pMsg->type == Release) destroyCmsg(pMsg); + if (pMsg == NULL || REQUEST_NO_RESP(&pMsg->msg) || pMsg->type == Release) destroyCmsg(pMsg); once = true; continue; } @@ -498,7 +474,7 @@ void* destroyConnPool(void* pool) { } static SCliConn* getConnFromPool(void* pool, char* ip, uint32_t port) { - char key[32] = {0}; + char key[TSDB_FQDN_LEN + 64] = {0}; CONN_CONSTRUCT_HASH_KEY(key, ip, port); SConnList* plist = taosHashGet((SHashObj*)pool, key, strlen(key)); @@ -549,7 +525,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { conn->status = ConnInPool; if (conn->list == NULL) { - char key[32] = {0}; + char key[TSDB_FQDN_LEN + 64] = {0}; CONN_CONSTRUCT_HASH_KEY(key, conn->ip, conn->port); tTrace("%s conn %p added to conn pool, read buf cap:%d", CONN_GET_INST_LABEL(conn), conn, conn->readBuf.cap); conn->list = taosHashGet((SHashObj*)pool, key, strlen(key)); @@ -742,8 +718,10 @@ static void cliSendCb(uv_write_t* req, int status) { if (status == 0) { tTrace("%s conn %p data already was written out", CONN_GET_INST_LABEL(pConn), pConn); } else { - tError("%s conn %p failed to write:%s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(status)); - cliHandleExcept(pConn); + if (!uv_is_closing((uv_handle_t*)&pConn->stream)) { + tError("%s conn %p failed to write:%s", CONN_GET_INST_LABEL(pConn), pConn, uv_err_name(status)); + cliHandleExcept(pConn); + } return; } if (cliHandleNoResp(pConn) == true) { @@ -1203,7 +1181,7 @@ static SCliThrd* createThrdObj(void* trans) { pThrd->loop = (uv_loop_t*)taosMemoryMalloc(sizeof(uv_loop_t)); uv_loop_init(pThrd->loop); - pThrd->asyncPool = transAsyncPoolCreate(pThrd->loop, 5, pThrd, cliAsyncCb); + pThrd->asyncPool = transAsyncPoolCreate(pThrd->loop, 8, pThrd, cliAsyncCb); pThrd->prepare = taosMemoryCalloc(1, sizeof(uv_prepare_t)); uv_prepare_init(pThrd->loop, pThrd->prepare); @@ -1275,11 +1253,14 @@ void cliWalkCb(uv_handle_t* handle, void* arg) { } FORCE_INLINE int cliRBChoseIdx(STrans* pTransInst) { - int8_t index = pTransInst->index; + int32_t index = pTransInst->index; if (pTransInst->numOfThreads == 0) { return -1; } - if (pTransInst->index++ >= pTransInst->numOfThreads) { + /* + * no lock, and to avoid CPU load imbalance, set limit pTransInst->numOfThreads * 2000; + */ + if (pTransInst->index++ >= pTransInst->numOfThreads * 2000) { pTransInst->index = 0; } return index % pTransInst->numOfThreads; @@ -1293,7 +1274,7 @@ static FORCE_INLINE void doDelayTask(void* param) { static void doCloseIdleConn(void* param) { STaskArg* arg = param; SCliConn* conn = arg->param1; - tTrace("%s conn %p idle, close it", CONN_GET_INST_LABEL(conn), conn); + tDebug("%s conn %p idle, close it", CONN_GET_INST_LABEL(conn), conn); conn->task = NULL; cliDestroyConn(conn, true); taosMemoryFree(arg); @@ -1612,8 +1593,8 @@ int transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) { SCvtAddr cvtAddr = {0}; if (ip != NULL && fqdn != NULL) { - if (strlen(ip) <= sizeof(cvtAddr.ip)) memcpy(cvtAddr.ip, ip, strlen(ip)); - if (strlen(fqdn) <= sizeof(cvtAddr.fqdn)) memcpy(cvtAddr.fqdn, fqdn, strlen(fqdn)); + tstrncpy(cvtAddr.ip, ip, sizeof(cvtAddr.ip)); + tstrncpy(cvtAddr.fqdn, fqdn, sizeof(cvtAddr.fqdn)); cvtAddr.cvt = true; } for (int i = 0; i < pTransInst->numOfThreads; i++) { diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 4ae1a1083afddcd00beb42e753090088a91f1c0f..18b812f314da7860c721c8834bc9ff89616e5aa3 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -249,10 +249,10 @@ int transAsyncSend(SAsyncPool* pool, queue* q) { if (atomic_load_8(&pool->stop) == 1) { return -1; } - int idx = pool->index; - idx = idx % pool->nAsync; + int idx = pool->index % pool->nAsync; + // no need mutex here - if (pool->index++ > pool->nAsync) { + if (pool->index++ > pool->nAsync * 2000) { pool->index = 0; } uv_async_t* async = &(pool->asyncs[idx]); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 6819068b64812f9057c6d230491096464185e593..5f36d910238dab5a2a69cba6a23e191d7eca32b8 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -127,7 +127,7 @@ static void uvFreeCb(uv_handle_t* handle); static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg); -static void uvPrepareSendData(SSvrMsg* msg, uv_buf_t* wb); +static int uvPrepareSendData(SSvrMsg* msg, uv_buf_t* wb); static void uvStartSendResp(SSvrMsg* msg); static void uvNotifyLinkBrokenToApp(SSvrConn* conn); @@ -363,9 +363,11 @@ void uvOnSendCb(uv_write_t* req, int status) { } transUnrefSrvHandle(conn); } else { - tError("conn %p failed to write data, %s", conn, uv_err_name(status)); - conn->broken = true; - transUnrefSrvHandle(conn); + if (!uv_is_closing((uv_handle_t*)(conn->pTcp))) { + tError("conn %p failed to write data, %s", conn, uv_err_name(status)); + conn->broken = true; + transUnrefSrvHandle(conn); + } } } static void uvOnPipeWriteCb(uv_write_t* req, int status) { @@ -382,7 +384,7 @@ static void uvOnPipeWriteCb(uv_write_t* req, int status) { taosMemoryFree(req); } -static void uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { +static int uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { SSvrConn* pConn = smsg->pConn; STransMsg* pMsg = &smsg->msg; if (pMsg->pCont == 0) { @@ -395,6 +397,13 @@ static void uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { pHead->hasEpSet = pMsg->info.hasEpSet; pHead->magicNum = htonl(TRANS_MAGIC_NUM); + // handle invalid drop_task resp, TD-20098 + if (pMsg->msgType == TDMT_SCH_DROP_TASK && pMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID) { + transQueuePop(&pConn->srvMsgs); + destroySmsg(smsg); + return -1; + } + if (pConn->status == ConnNormal) { pHead->msgType = (0 == pMsg->msgType ? pConn->inType + 1 : pMsg->msgType); if (smsg->type == Release) pHead->msgType = 0; @@ -429,6 +438,7 @@ static void uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { wb->base = (char*)pHead; wb->len = len; + return 0; } static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg) { @@ -438,7 +448,9 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg) { } uv_buf_t wb; - uvPrepareSendData(smsg, &wb); + if (uvPrepareSendData(smsg, &wb) < 0) { + return; + } transRefSrvHandle(pConn); uv_write_t* req = transReqQueuePush(&pConn->wreqQueue); @@ -449,8 +461,9 @@ static void uvStartSendResp(SSvrMsg* smsg) { SSvrConn* pConn = smsg->pConn; if (pConn->broken == true) { // persist by - transFreeMsg(smsg->msg.pCont); - taosMemoryFree(smsg); + destroySmsg(smsg); + // transFreeMsg(smsg->msg.pCont); + // taosMemoryFree(smsg); transUnrefSrvHandle(pConn); return; } @@ -655,7 +668,7 @@ void uvOnAcceptCb(uv_stream_t* stream, int status) { uv_tcp_init(pObj->loop, cli); if (uv_accept(stream, (uv_stream_t*)cli) == 0) { -#ifdef WINDOWS +#if defined(WINDOWS) || defined(DARWIN) if (pObj->numOfWorkerReady < pObj->numOfThreads) { tError("worker-threads are not ready for all, need %d instead of %d.", pObj->numOfThreads, pObj->numOfWorkerReady); @@ -746,10 +759,11 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { return; } transSockInfo2Str(&sockname, pConn->src); - struct sockaddr_in addr = *(struct sockaddr_in*)&sockname; + struct sockaddr_in addr = *(struct sockaddr_in*)&peername; pConn->clientIp = addr.sin_addr.s_addr; pConn->port = ntohs(addr.sin_port); + uv_read_start((uv_stream_t*)(pConn->pTcp), uvAllocRecvBufferCb, uvOnRecvCb); } else { @@ -779,7 +793,7 @@ static bool addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName) { return false; } -#ifdef WINDOWS +#if defined(WINDOWS) || defined(DARWIN) uv_pipe_init(pThrd->loop, pThrd->pipe, 1); #else uv_pipe_init(pThrd->loop, pThrd->pipe, 1); @@ -798,8 +812,8 @@ static bool addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName) { // conn set QUEUE_INIT(&pThrd->conn); - pThrd->asyncPool = transAsyncPoolCreate(pThrd->loop, 5, pThrd, uvWorkerAsyncCb); -#ifdef WINDOWS + pThrd->asyncPool = transAsyncPoolCreate(pThrd->loop, 8, pThrd, uvWorkerAsyncCb); +#if defined(WINDOWS) || defined(DARWIN) uv_pipe_connect(&pThrd->connect_req, pThrd->pipe, pipeName, uvOnPipeConnectionCb); #else uv_read_start((uv_stream_t*)pThrd->pipe, uvAllocConnBufferCb, uvOnConnectionCb); @@ -976,17 +990,18 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, uv_loop_init(srv->loop); char pipeName[PATH_MAX]; -#ifdef WINDOWS +#if defined(WINDOWS) || defined(DARWIN) int ret = uv_pipe_init(srv->loop, &srv->pipeListen, 0); if (ret != 0) { tError("failed to init pipe, errmsg: %s", uv_err_name(ret)); goto End; } - +#if defined(WINDOWS) snprintf(pipeName, sizeof(pipeName), "\\\\?\\pipe\\trans.rpc.%d-%" PRIu64, taosSafeRand(), GetCurrentProcessId()); - // char pipeName[PATH_MAX] = {0}; - // snprintf(pipeName, sizeof(pipeName), "%s%spipe.trans.rpc.%08d-%" PRIu64, tsTempDir, TD_DIRSEP, taosSafeRand(), - // taosGetSelfPthreadId()); +#elif defined(DARWIN) + snprintf(pipeName, sizeof(pipeName), "%s%spipe.trans.rpc.%08d-%" PRIu64, tsTempDir, TD_DIRSEP, taosSafeRand(), + taosGetSelfPthreadId()); +#endif ret = uv_pipe_bind(&srv->pipeListen, pipeName); if (ret != 0) { @@ -1036,7 +1051,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, srv->pThreadObj[i] = thrd; uv_os_sock_t fds[2]; - if (uv_socketpair(AF_UNIX, SOCK_STREAM, fds, UV_NONBLOCK_PIPE, UV_NONBLOCK_PIPE) != 0) { + if (uv_socketpair(SOCK_STREAM, 0, fds, UV_NONBLOCK_PIPE, UV_NONBLOCK_PIPE) != 0) { goto End; } @@ -1059,8 +1074,8 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, goto End; } } - #endif + if (false == taosValidIpAndPort(srv->ip, srv->port)) { terrno = TAOS_SYSTEM_ERROR(errno); tError("invalid ip/port, %d:%d, reason:%s", srv->ip, srv->port, terrstr()); diff --git a/source/libs/transport/test/cliBench.c b/source/libs/transport/test/cliBench.c index a296625acef45ae05e4e7b489bdf364a97cebfbc..01e88b99888080ab3162669b8d8ee0083fbf2edd 100644 --- a/source/libs/transport/test/cliBench.c +++ b/source/libs/transport/test/cliBench.c @@ -32,6 +32,22 @@ typedef struct { void *pRpc; } SInfo; + +void initLogEnv() { + const char *logDir = "/tmp/trans_cli"; + const char* defaultLogFileNamePrefix = "taoslog"; + const int32_t maxLogFileNum = 10000; + tsAsyncLog = 0; + //idxDebugFlag = 143; + strcpy(tsLogDir, (char *)logDir); + taosRemoveDir(tsLogDir); + taosMkDir(tsLogDir); + + if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) { + printf("failed to open log file in directory:%s\n", tsLogDir); + } +} + static void processResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) { SInfo *pInfo = (SInfo *)pMsg->info.ahandle; tDebug("thread:%d, response is received, type:%d contLen:%d code:0x%x", pInfo->index, pMsg->msgType, pMsg->contLen, @@ -98,7 +114,7 @@ int main(int argc, char *argv[]) { rpcInit.user = "michael"; rpcInit.connType = TAOS_CONN_CLIENT; - rpcDebugFlag = 131; + rpcDebugFlag = 135; for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "-p") == 0 && i < argc - 1) { } else if (strcmp(argv[i], "-i") == 0 && i < argc - 1) { @@ -132,7 +148,9 @@ int main(int argc, char *argv[]) { exit(0); } } - taosInitLog("client.log", 100000); + + + initLogEnv(); void *pRpc = rpcOpen(&rpcInit); if (pRpc == NULL) { diff --git a/source/libs/transport/test/svrBench.c b/source/libs/transport/test/svrBench.c index ce465d989a82078532bd230477b6565cbd098fb2..464559c1e05b6ef1325ae428f6d55d8e30c6f63d 100644 --- a/source/libs/transport/test/svrBench.c +++ b/source/libs/transport/test/svrBench.c @@ -26,7 +26,40 @@ TdFilePtr pDataFile = NULL; STaosQueue *qhandle = NULL; STaosQset *qset = NULL; -void processShellMsg() { +int32_t balance = 0; + +typedef struct { + int32_t numOfThread; + STaosQueue **qhandle; + STaosQset **qset; + +} MultiThreadQhandle; + +typedef struct TThread { + TdThread thread; + int idx; +} TThread; + +MultiThreadQhandle *multiQ = NULL; + +void initLogEnv() { + const char *logDir = "/tmp/trans_svr"; + const char *defaultLogFileNamePrefix = "taoslog"; + const int32_t maxLogFileNum = 10000; + tsAsyncLog = 0; + // idxDebugFlag = 143; + strcpy(tsLogDir, logDir); + taosRemoveDir(tsLogDir); + taosMkDir(tsLogDir); + + if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) { + printf("failed to open log file in directory:%s\n", tsLogDir); + } +} +void *processShellMsg(void *arg) { + TThread *thread = (TThread *)arg; + + int32_t idx = thread->idx; static int num = 0; STaosQall *qall; SRpcMsg *pRpcMsg, rpcMsg; @@ -36,7 +69,7 @@ void processShellMsg() { qall = taosAllocateQall(); while (1) { - int numOfMsgs = taosReadAllQitemsFromQset(qset, qall, &qinfo); + int numOfMsgs = taosReadAllQitemsFromQset(multiQ->qset[idx], qall, &qinfo); tDebug("%d shell msgs are received", numOfMsgs); if (numOfMsgs <= 0) break; @@ -89,6 +122,7 @@ void processShellMsg() { } taosFreeQall(qall); + return NULL; } void processRequestMsg(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet) { @@ -97,8 +131,11 @@ void processRequestMsg(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet) { pTemp = taosAllocateQitem(sizeof(SRpcMsg), DEF_QITEM); memcpy(pTemp, pMsg, sizeof(SRpcMsg)); + int32_t idx = balance % multiQ->numOfThread; tDebug("request is received, type:%d, contLen:%d, item:%p", pMsg->msgType, pMsg->contLen, pTemp); - taosWriteQitem(qhandle, pTemp); + taosWriteQitem(multiQ->qhandle[idx], pTemp); + balance++; + if (balance >= multiQ->numOfThread) balance = 0; } int main(int argc, char *argv[]) { @@ -147,9 +184,9 @@ int main(int argc, char *argv[]) { } } - tsAsyncLog = 0; rpcInit.connType = TAOS_CONN_SERVER; - taosInitLog("server.log", 100000); + + initLogEnv(); void *pRpc = rpcOpen(&rpcInit); if (pRpc == NULL) { @@ -164,16 +201,35 @@ int main(int argc, char *argv[]) { pDataFile = taosOpenFile(dataName, TD_FILE_APPEND | TD_FILE_CREATE | TD_FILE_WRITE); if (pDataFile == NULL) tInfo("failed to open data file, reason:%s", strerror(errno)); } - qhandle = taosOpenQueue(); - qset = taosOpenQset(); - taosAddIntoQset(qset, qhandle, NULL); - processShellMsg(); + int32_t numOfAthread = 5; + multiQ = taosMemoryMalloc(sizeof(numOfAthread)); + multiQ->numOfThread = numOfAthread; + multiQ->qhandle = (STaosQueue **)taosMemoryMalloc(sizeof(STaosQueue *) * numOfAthread); + multiQ->qset = (STaosQset **)taosMemoryMalloc(sizeof(STaosQset *) * numOfAthread); + + for (int i = 0; i < numOfAthread; i++) { + multiQ->qhandle[i] = taosOpenQueue(); + multiQ->qset[i] = taosOpenQset(); + taosAddIntoQset(multiQ->qset[i], multiQ->qhandle[i], NULL); + } + TThread *threads = taosMemoryMalloc(sizeof(TThread) * numOfAthread); + for (int i = 0; i < numOfAthread; i++) { + threads[i].idx = i; + taosThreadCreate(&(threads[i].thread), NULL, processShellMsg, (void *)&threads[i]); + } + // qhandle = taosOpenQueue(); + // qset = taosOpenQset(); + // taosAddIntoQset(qset, qhandle, NULL); + + // processShellMsg(); if (pDataFile != NULL) { taosCloseFile(&pDataFile); taosRemoveFile(dataName); } + int ch = getchar(); + UNUSED(ch); return 0; } diff --git a/source/libs/wal/inc/walInt.h b/source/libs/wal/inc/walInt.h index 1aea0e81484c2a7b0fc4740d2baa5572d3da15d6..6dc99229816a1dd5233419b6b10c6d68d052ab53 100644 --- a/source/libs/wal/inc/walInt.h +++ b/source/libs/wal/inc/walInt.h @@ -34,6 +34,7 @@ typedef struct { int64_t createTs; int64_t closeTs; int64_t fileSize; + int64_t syncedOffset; } SWalFileInfo; typedef struct WalIdxEntry { @@ -66,6 +67,12 @@ static inline int64_t walGetLastFileSize(SWal* pWal) { return pInfo->fileSize; } +static inline int64_t walGetLastFileCachedSize(SWal* pWal) { + if (taosArrayGetSize(pWal->fileInfoSet) == 0) return 0; + SWalFileInfo* pInfo = (SWalFileInfo*)taosArrayGetLast(pWal->fileInfoSet); + return (pInfo->fileSize - pInfo->syncedOffset); +} + static inline int64_t walGetLastFileFirstVer(SWal* pWal) { if (taosArrayGetSize(pWal->fileInfoSet) == 0) return -1; SWalFileInfo* pInfo = (SWalFileInfo*)taosArrayGetLast(pWal->fileInfoSet); diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index bf3aef340c5d46406fea5b54519eb135dc4d9608..1c6e1a2e1791c54eff789517d394421d7bc67f2c 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -16,6 +16,7 @@ #include "cJSON.h" #include "os.h" #include "taoserror.h" +#include "tglobal.h" #include "tutil.h" #include "walInt.h" @@ -65,32 +66,43 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx) { // ensure size as non-negative pFileInfo->fileSize = TMAX(0, pFileInfo->fileSize); + int64_t stepSize = WAL_SCAN_BUF_SIZE; uint64_t magic = WAL_MAGIC; int64_t walCkHeadSz = sizeof(SWalCkHead); int64_t end = fileSize; - int64_t offset = 0; int64_t capacity = 0; int64_t readSize = 0; char* buf = NULL; - char* found = NULL; bool firstTrial = pFileInfo->fileSize < fileSize; + int64_t offset = TMIN(pFileInfo->fileSize, fileSize); + int64_t offsetForward = offset - stepSize + walCkHeadSz - 1; + int64_t offsetBackward = offset; + int64_t retVer = -1; + int64_t lastEntryBeginOffset = 0; + int64_t lastEntryEndOffset = 0; + + // check recover size + if (2 * tsWalFsyncDataSizeLimit + offset < end) { + wWarn("vgId:%d, possibly corrupted WAL range exceeds size limit (i.e. %" PRId64 " bytes). offset:%" PRId64 + ", end:%" PRId64 ", file:%s", + pWal->cfg.vgId, 2 * tsWalFsyncDataSizeLimit, offset, end, fnameStr); + } // search for the valid last WAL entry, e.g. block by block while (1) { - offset = (firstTrial) ? pFileInfo->fileSize : TMAX(0, end - WAL_SCAN_BUF_SIZE); + offset = (firstTrial) ? TMIN(fileSize, offsetForward + stepSize - walCkHeadSz + 1) + : TMAX(0, offsetBackward - stepSize + walCkHeadSz - 1); + end = TMIN(offset + stepSize, fileSize); + if (firstTrial) { + offsetForward = offset; + } else { + offsetBackward = offset; + } + ASSERT(offset <= end); readSize = end - offset; capacity = readSize + sizeof(magic); - int64_t limit = WAL_RECOV_SIZE_LIMIT; - if (limit < readSize) { - wError("vgId:%d, possibly corrupted WAL range exceeds size limit (i.e. %" PRId64 " bytes). offset:%" PRId64 - ", end:%" PRId64 ", file:%s", - pWal->cfg.vgId, limit, offset, end, fnameStr); - terrno = TSDB_CODE_WAL_SIZE_LIMIT; - goto _err; - } - void* ptr = taosMemoryRealloc(buf, capacity); if (ptr == NULL) { terrno = TSDB_CODE_WAL_OUT_OF_MEMORY; @@ -114,18 +126,23 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx) { char* candidate = NULL; char* haystack = buf; + int64_t pos = 0; + SWalCkHead* logContent = NULL; while ((candidate = tmemmem(haystack, readSize - (haystack - buf), (char*)&magic, sizeof(magic))) != NULL) { + pos = candidate - buf; + // validate head - int64_t len = readSize - (candidate - buf); + int64_t len = readSize - pos; if (len < walCkHeadSz) { break; } - SWalCkHead* logContent = (SWalCkHead*)candidate; + logContent = (SWalCkHead*)(buf + pos); if (walValidHeadCksum(logContent) != 0) { + terrno = TSDB_CODE_WAL_CHKSUM_MISMATCH; wWarn("vgId:%d, failed to validate checksum of wal entry header. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, - offset + ((char*)(logContent)-buf), fnameStr); - haystack = candidate + 1; + offset + pos, fnameStr); + haystack = buf + pos + 1; if (firstTrial) { break; } else { @@ -160,11 +177,13 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx) { break; } } + + logContent = (SWalCkHead*)(buf + pos); if (walValidBodyCksum(logContent) != 0) { terrno = TSDB_CODE_WAL_CHKSUM_MISMATCH; wWarn("vgId:%d, failed to validate checksum of wal entry body. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, - offset + ((char*)(logContent)-buf), fnameStr); - haystack = candidate + 1; + offset + pos, fnameStr); + haystack = buf + pos + 1; if (firstTrial) { break; } else { @@ -173,46 +192,47 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx) { } // found one - found = candidate; - haystack = candidate + 1; - } + retVer = logContent->head.version; + lastEntryBeginOffset = offset + pos; + lastEntryEndOffset = offset + pos + sizeof(SWalCkHead) + logContent->head.bodyLen; - if (found || offset == 0) break; + // try next + haystack = buf + pos + 1; + } - // go backwards, e.g. by at most one WAL scan buf size - end = offset + walCkHeadSz - 1; - firstTrial = false; + if (end == fileSize) firstTrial = false; + if (firstTrial) { + if (terrno == TSDB_CODE_SUCCESS) { + continue; + } else { + firstTrial = false; + } + } + if (retVer >= 0 || offset == 0) break; } - // determine end of last entry - SWalCkHead* lastEntry = (SWalCkHead*)found; - int64_t retVer = -1; - int64_t lastEntryBeginOffset = 0; - int64_t lastEntryEndOffset = 0; - - if (lastEntry == NULL) { + if (retVer < 0) { terrno = TSDB_CODE_WAL_LOG_NOT_EXIST; - } else { - retVer = lastEntry->head.version; - lastEntryBeginOffset = offset + (int64_t)((char*)lastEntry - (char*)buf); - lastEntryEndOffset = lastEntryBeginOffset + sizeof(SWalCkHead) + lastEntry->head.bodyLen; } // truncate file if (lastEntryEndOffset != fileSize) { wWarn("vgId:%d, repair meta truncate file %s to %" PRId64 ", orig size %" PRId64, pWal->cfg.vgId, fnameStr, lastEntryEndOffset, fileSize); + if (taosFtruncateFile(pFile, lastEntryEndOffset) < 0) { wError("failed to truncate file due to %s. file:%s", strerror(errno), fnameStr); terrno = TAOS_SYSTEM_ERROR(errno); goto _err; } + if (taosFsyncFile(pFile) < 0) { wError("failed to fsync file due to %s. file:%s", strerror(errno), fnameStr); terrno = TAOS_SYSTEM_ERROR(errno); goto _err; } } + pFileInfo->fileSize = lastEntryEndOffset; taosCloseFile(&pFile); @@ -282,6 +302,33 @@ void walAlignVersions(SWal* pWal) { pWal->vers.appliedVer = TMIN(pWal->vers.commitVer, pWal->vers.appliedVer); } +bool walLogEntriesComplete(const SWal* pWal) { + int32_t sz = taosArrayGetSize(pWal->fileInfoSet); + bool complete = true; + int32_t fileIdx = -1; + int64_t index = pWal->vers.firstVer; + + while (++fileIdx < sz) { + SWalFileInfo* pFileInfo = taosArrayGet(pWal->fileInfoSet, fileIdx); + if (pFileInfo->firstVer != index) { + break; + } + index = pFileInfo->lastVer + ((fileIdx + 1 < sz) ? 1 : 0); + } + // empty is regarded as complete + if (sz != 0) { + complete = (index == pWal->vers.lastVer); + } + + if (!complete) { + wError("vgId:%d, WAL log entries incomplete in range [%" PRId64 ", %" PRId64 "], aligned with snaphotVer:%" PRId64, + pWal->cfg.vgId, pWal->vers.firstVer, pWal->vers.lastVer, pWal->vers.snapshotVer); + terrno = TSDB_CODE_WAL_LOG_INCOMPLETE; + } + + return complete; +} + int walCheckAndRepairMeta(SWal* pWal) { // load log files, get first/snapshot/last version info const char* logPattern = "^[0-9]+.log$"; @@ -395,6 +442,11 @@ int walCheckAndRepairMeta(SWal* pWal) { if (updateMeta) { (void)walSaveMeta(pWal); } + + if (!walLogEntriesComplete(pWal)) { + return -1; + } + return 0; } @@ -583,6 +635,7 @@ int walRollFileInfo(SWal* pWal) { pNewInfo->createTs = ts; pNewInfo->closeTs = -1; pNewInfo->fileSize = 0; + pNewInfo->syncedOffset = 0; taosArrayPush(pArray, pNewInfo); taosMemoryFree(pNewInfo); return 0; @@ -733,6 +786,12 @@ static int walFindCurMetaVer(SWal* pWal) { return metaVer; } +void walUpdateSyncedOffset(SWal* pWal) { + SWalFileInfo* pFileInfo = walGetCurFileInfo(pWal); + if (pFileInfo == NULL) return; + pFileInfo->syncedOffset = pFileInfo->fileSize; +} + int walSaveMeta(SWal* pWal) { int metaVer = walFindCurMetaVer(pWal); char fnameStr[WAL_FILE_LEN]; @@ -752,6 +811,9 @@ int walSaveMeta(SWal* pWal) { return -1; } + // update synced offset + (void)walUpdateSyncedOffset(pWal); + // flush to a tmpfile n = walBuildTmpMetaName(pWal, tmpFnameStr); ASSERT(n < sizeof(tmpFnameStr) && "Buffer overflow of file name"); diff --git a/source/libs/wal/src/walMgmt.c b/source/libs/wal/src/walMgmt.c index 0df1a6b3878863d16a6ff4b831081e71759f324d..1a70a3038f4351016cf4098f9497253e7e75fb9f 100644 --- a/source/libs/wal/src/walMgmt.c +++ b/source/libs/wal/src/walMgmt.c @@ -187,6 +187,13 @@ int32_t walAlter(SWal *pWal, SWalCfg *pCfg) { return 0; } +int32_t walPersist(SWal *pWal) { + taosThreadMutexLock(&pWal->mutex); + int32_t ret = walSaveMeta(pWal); + taosThreadMutexUnlock(&pWal->mutex); + return ret; +} + void walClose(SWal *pWal) { taosThreadMutexLock(&pWal->mutex); (void)walSaveMeta(pWal); diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index 8f493ddd85a23a67e1bc2f11412cfc991a4cdeca..1350ca0c37616c2f748a01a87de26b77b3c36823 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -198,7 +198,7 @@ int32_t walReadSeekVerImpl(SWalReader *pReader, int64_t ver) { return -1; } - wDebug("vgId:%d, wal version reset from index:%" PRId64 "(invalid:%d) to index:%" PRId64, pReader->pWal->cfg.vgId, + wDebug("vgId:%d, wal version reset from %" PRId64 "(invalid:%d) to %" PRId64, pReader->pWal->cfg.vgId, pReader->curVersion, pReader->curInvalid, ver); pReader->curVersion = ver; @@ -347,22 +347,47 @@ static int32_t walSkipFetchBodyNew(SWalReader *pRead) { int32_t walFetchHead(SWalReader *pRead, int64_t ver, SWalCkHead *pHead) { int64_t code; + int64_t contLen; + bool seeked = false; + + wDebug("vgId:%d try to fetch ver %" PRId64 ", first ver:%" PRId64 ", commit ver:%" PRId64 ", last ver:%" PRId64 + ", applied ver:%" PRId64, + pRead->pWal->cfg.vgId, ver, pRead->pWal->vers.firstVer, pRead->pWal->vers.commitVer, pRead->pWal->vers.lastVer, + pRead->pWal->vers.appliedVer); // TODO: valid ver - if (ver > pRead->pWal->vers.commitVer) { + if (ver > pRead->pWal->vers.appliedVer) { return -1; } if (pRead->curInvalid || pRead->curVersion != ver) { code = walReadSeekVer(pRead, ver); - if (code < 0) return -1; + if (code < 0) { + pRead->curVersion = ver; + pRead->curInvalid = 1; + return -1; + } + seeked = true; } - ASSERT(taosValidFile(pRead->pLogFile) == true); - - code = taosReadFile(pRead->pLogFile, pHead, sizeof(SWalCkHead)); - if (code != sizeof(SWalCkHead)) { - return -1; + while (1) { + contLen = taosReadFile(pRead->pLogFile, pHead, sizeof(SWalCkHead)); + if (contLen == sizeof(SWalCkHead)) { + break; + } else if (contLen == 0 && !seeked) { + walReadSeekVerImpl(pRead, ver); + seeked = true; + continue; + } else { + if (contLen < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + } else { + terrno = TSDB_CODE_WAL_FILE_CORRUPTED; + } + ASSERT(0); + pRead->curInvalid = 1; + return -1; + } } code = walValidHeadCksum(pHead); @@ -373,13 +398,20 @@ int32_t walFetchHead(SWalReader *pRead, int64_t ver, SWalCkHead *pHead) { return -1; } + pRead->curInvalid = 0; return 0; } int32_t walSkipFetchBody(SWalReader *pRead, const SWalCkHead *pHead) { int64_t code; - // ASSERT(pRead->curVersion == pHead->head.version); + wDebug("vgId:%d skip fetch body %" PRId64 ", first ver:%" PRId64 ", commit ver:%" PRId64 ", last ver:%" PRId64 + ", applied ver:%" PRId64, + pRead->pWal->cfg.vgId, pHead->head.version, pRead->pWal->vers.firstVer, pRead->pWal->vers.commitVer, + pRead->pWal->vers.lastVer, pRead->pWal->vers.appliedVer); + + ASSERT(pRead->curVersion == pHead->head.version); + ASSERT(pRead->curInvalid == 0); code = taosLSeekFile(pRead->pLogFile, pHead->head.bodyLen, SEEK_CUR); if (code < 0) { @@ -397,6 +429,11 @@ int32_t walFetchBody(SWalReader *pRead, SWalCkHead **ppHead) { SWalCont *pReadHead = &((*ppHead)->head); int64_t ver = pReadHead->version; + wDebug("vgId:%d fetch body %" PRId64 ", first ver:%" PRId64 ", commit ver:%" PRId64 ", last ver:%" PRId64 + ", applied ver:%" PRId64, + pRead->pWal->cfg.vgId, ver, pRead->pWal->vers.firstVer, pRead->pWal->vers.commitVer, pRead->pWal->vers.lastVer, + pRead->pWal->vers.appliedVer); + if (pRead->capacity < pReadHead->bodyLen) { SWalCkHead *ptr = (SWalCkHead *)taosMemoryRealloc(*ppHead, sizeof(SWalCkHead) + pReadHead->bodyLen); if (ptr == NULL) { @@ -409,19 +446,32 @@ int32_t walFetchBody(SWalReader *pRead, SWalCkHead **ppHead) { } if (pReadHead->bodyLen != taosReadFile(pRead->pLogFile, pReadHead->body, pReadHead->bodyLen)) { + if (pReadHead->bodyLen < 0) { + ASSERT(0); + terrno = TAOS_SYSTEM_ERROR(errno); + wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64 ", since %s", + pRead->pWal->cfg.vgId, pReadHead->version, ver, tstrerror(terrno)); + } else { + wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64 ", since file corrupted", + pRead->pWal->cfg.vgId, pReadHead->version, ver); + terrno = TSDB_CODE_WAL_FILE_CORRUPTED; + } + pRead->curInvalid = 1; ASSERT(0); return -1; } if (pReadHead->version != ver) { + ASSERT(0); wError("vgId:%d, wal fetch body error, index:%" PRId64 ", read request index:%" PRId64, pRead->pWal->cfg.vgId, - pRead->pHead->head.version, ver); + pReadHead->version, ver); pRead->curInvalid = 1; terrno = TSDB_CODE_WAL_FILE_CORRUPTED; return -1; } if (walValidBodyCksum(*ppHead) != 0) { + ASSERT(0); wError("vgId:%d, wal fetch body error, index:%" PRId64 ", since body checksum not passed", pRead->pWal->cfg.vgId, ver); pRead->curInvalid = 1; diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index 527ffa005623af34d76e6b68644b01b0a66b3163..b683ba19263f32406f52beef51a0ba1ca452ef58 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -16,6 +16,7 @@ #include "os.h" #include "taoserror.h" #include "tchecksum.h" +#include "tglobal.h" #include "walInt.h" int32_t walRestoreFromSnapshot(SWal *pWal, int64_t ver) { @@ -101,7 +102,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) { taosThreadMutexLock(&pWal->mutex); int64_t code; char fnameStr[WAL_FILE_LEN]; - if (ver > pWal->vers.lastVer || ver < pWal->vers.commitVer) { + if (ver > pWal->vers.lastVer || ver < pWal->vers.commitVer || ver <= pWal->vers.snapshotVer) { terrno = TSDB_CODE_WAL_INVALID_VER; taosThreadMutexUnlock(&pWal->mutex); return -1; @@ -252,23 +253,36 @@ static FORCE_INLINE int32_t walCheckAndRoll(SWal *pWal) { } } + if (walGetLastFileCachedSize(pWal) > tsWalFsyncDataSizeLimit) { + if (walSaveMeta(pWal) < 0) { + return -1; + } + } + return 0; } int32_t walBeginSnapshot(SWal *pWal, int64_t ver) { + taosThreadMutexLock(&pWal->mutex); + pWal->vers.verInSnapshotting = ver; wDebug("vgId:%d, wal begin snapshot for version %" PRId64 ", first ver %" PRId64 ", last ver %" PRId64, pWal->cfg.vgId, ver, pWal->vers.firstVer, pWal->vers.lastVer); // check file rolling if (pWal->cfg.retentionPeriod == 0) { - taosThreadMutexLock(&pWal->mutex); if (walGetLastFileSize(pWal) != 0) { - walRollImpl(pWal); + if (walRollImpl(pWal) < 0) { + wError("vgId:%d, failed to roll wal files since %s", pWal->cfg.vgId, terrstr()); + goto _err; + } } - taosThreadMutexUnlock(&pWal->mutex); } - + taosThreadMutexUnlock(&pWal->mutex); return 0; + +_err: + taosThreadMutexUnlock(&pWal->mutex); + return -1; } int32_t walEndSnapshot(SWal *pWal) { @@ -468,7 +482,8 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy pWal->writeHead.cksumHead = walCalcHeadCksum(&pWal->writeHead); pWal->writeHead.cksumBody = walCalcBodyCksum(body, bodyLen); - wDebug("vgId:%d, wal write log %" PRId64 ", msgType: %s", pWal->cfg.vgId, index, TMSG_INFO(msgType)); + wDebug("vgId:%d, wal write log %" PRId64 ", msgType: %s, cksum head %u cksum body %u", pWal->cfg.vgId, index, + TMSG_INFO(msgType), pWal->writeHead.cksumHead, pWal->writeHead.cksumBody); code = walWriteIndex(pWal, index, offset); if (code < 0) { diff --git a/source/libs/wal/test/walMetaTest.cpp b/source/libs/wal/test/walMetaTest.cpp index d98826a3849a612f3588a2be01b393fdf7db08de..891e7dcdaedd753d139ae30c8e1efef1c733733f 100644 --- a/source/libs/wal/test/walMetaTest.cpp +++ b/source/libs/wal/test/walMetaTest.cpp @@ -274,17 +274,17 @@ TEST_F(WalCleanEnv, rollbackMultiFile) { code = walRollback(pWal, 9); ASSERT_EQ(code, 0); ASSERT_EQ(pWal->vers.lastVer, 8); - code = walRollback(pWal, 5); - ASSERT_EQ(code, 0); - ASSERT_EQ(pWal->vers.lastVer, 4); - code = walRollback(pWal, 3); + code = walRollback(pWal, 6); ASSERT_EQ(code, 0); + ASSERT_EQ(pWal->vers.lastVer, 5); + code = walRollback(pWal, 5); + ASSERT_EQ(code, -1); - ASSERT_EQ(pWal->vers.lastVer, 2); + ASSERT_EQ(pWal->vers.lastVer, 5); - code = walWrite(pWal, 3, 3, (void*)ranStr, ranStrLen); + code = walWrite(pWal, 6, 6, (void*)ranStr, ranStrLen); ASSERT_EQ(code, 0); - ASSERT_EQ(pWal->vers.lastVer, 3); + ASSERT_EQ(pWal->vers.lastVer, 6); code = walSaveMeta(pWal); ASSERT_EQ(code, 0); diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index ca997427734ff7a5c817a8e439909cabd68dff64..5e85e40594a27c0b614b39864929e55977b5534c 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -158,7 +158,7 @@ int32_t taosMulMkDir(const char *dirname) { #ifdef WINDOWS code = _mkdir(temp, 0755); #elif defined(DARWIN) - code = mkdir(dirname, 0777); + code = mkdir(temp, 0777); #else code = mkdir(temp, 0755); #endif diff --git a/source/os/src/osMemory.c b/source/os/src/osMemory.c index 75a963d5c7551ad290d1d2190c24ab07e1ed0953..78fa362179051fafe4adc3f618a2fdd08ed5ec10 100644 --- a/source/os/src/osMemory.c +++ b/source/os/src/osMemory.c @@ -336,3 +336,12 @@ int64_t taosMemorySize(void *ptr) { #endif #endif } + +void taosMemoryTrim(int32_t size) { +#if defined(WINDOWS) || defined(DARWIN) + // do nothing + return; +#else + malloc_trim(size); +#endif +} diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index 0a6dad4819a302af7e3c491ec69fee06ac648095..e5ca9faacbe31bfc7812e8880cc1c9a3cd27b298 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -227,9 +227,7 @@ void taosGetSystemInfo() { #ifdef WINDOWS taosGetCpuCores(&tsNumOfCores); taosGetTotalMemory(&tsTotalMemoryKB); - - double tmp1, tmp2, tmp3, tmp4; - taosGetCpuUsage(&tmp1, &tmp2); + taosGetCpuUsage(NULL, NULL); #elif defined(_TD_DARWIN_64) long physical_pages = sysconf(_SC_PHYS_PAGES); long page_size = sysconf(_SC_PAGESIZE); @@ -240,9 +238,7 @@ void taosGetSystemInfo() { taosGetProcIOnfos(); taosGetCpuCores(&tsNumOfCores); taosGetTotalMemory(&tsTotalMemoryKB); - - double tmp1, tmp2, tmp3, tmp4; - taosGetCpuUsage(&tmp1, &tmp2); + taosGetCpuUsage(NULL, NULL); #endif } @@ -447,8 +443,8 @@ void taosGetCpuUsage(double *cpu_system, double *cpu_engine) { static int64_t curSysTotal = 0; static int64_t curProcTotal = 0; - *cpu_system = 0; - *cpu_engine = 0; + if (cpu_system != NULL) *cpu_system = 0; + if (cpu_engine != NULL) *cpu_engine = 0; SysCpuInfo sysCpu = {0}; ProcCpuInfo procCpu = {0}; @@ -458,8 +454,12 @@ void taosGetCpuUsage(double *cpu_system, double *cpu_engine) { curProcTotal = procCpu.utime + procCpu.stime + procCpu.cutime + procCpu.cstime; if (curSysTotal > lastSysTotal && curSysUsed >= lastSysUsed && curProcTotal >= lastProcTotal) { - *cpu_engine = (curSysUsed - lastSysUsed) / (double)(curSysTotal - lastSysTotal) * 100; - *cpu_system = (curProcTotal - lastProcTotal) / (double)(curSysTotal - lastSysTotal) * 100; + if (cpu_system != NULL) { + *cpu_system = (curSysUsed - lastSysUsed) / (double)(curSysTotal - lastSysTotal) * 100; + } + if (cpu_engine != NULL) { + *cpu_engine = (curProcTotal - lastProcTotal) / (double)(curSysTotal - lastSysTotal) * 100; + } } lastSysUsed = curSysUsed; diff --git a/source/util/src/tarray.c b/source/util/src/tarray.c index 309e6b30aef6247f3e351b324c60437c258a6923..95065972a3a890c253004033b1b33c5b76dd0467 100644 --- a/source/util/src/tarray.c +++ b/source/util/src/tarray.c @@ -26,12 +26,14 @@ SArray* taosArrayInit(size_t size, size_t elemSize) { SArray* pArray = taosMemoryMalloc(sizeof(SArray)); if (pArray == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } pArray->size = 0; pArray->pData = taosMemoryCalloc(size, elemSize); if (pArray->pData == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; taosMemoryFree(pArray); return NULL; } diff --git a/source/util/src/tcompare.c b/source/util/src/tcompare.c index 5d73a1464b9fbfda2ef84a289681243ed49fd470..d84a3d25c604d0089e1abc5ca2778a255a13c859 100644 --- a/source/util/src/tcompare.c +++ b/source/util/src/tcompare.c @@ -249,7 +249,7 @@ int32_t compareJsonVal(const void *pLeft, const void *pRight) { } int32_t compareInt8Int16(const void *pLeft, const void *pRight) { - int8_t left = GET_INT32_VAL(pLeft); + int8_t left = GET_INT8_VAL(pLeft); int16_t right = GET_INT16_VAL(pRight); if (left > right) return 1; if (left < right) return -1; @@ -257,7 +257,7 @@ int32_t compareInt8Int16(const void *pLeft, const void *pRight) { } int32_t compareInt8Int32(const void *pLeft, const void *pRight) { - int8_t left = GET_INT32_VAL(pLeft); + int8_t left = GET_INT8_VAL(pLeft); int32_t right = GET_INT32_VAL(pRight); if (left > right) return 1; if (left < right) return -1; @@ -265,7 +265,7 @@ int32_t compareInt8Int32(const void *pLeft, const void *pRight) { } int32_t compareInt8Int64(const void *pLeft, const void *pRight) { - int8_t left = GET_INT32_VAL(pLeft); + int8_t left = GET_INT8_VAL(pLeft); int64_t right = GET_INT64_VAL(pRight); if (left > right) return 1; if (left < right) return -1; @@ -273,7 +273,7 @@ int32_t compareInt8Int64(const void *pLeft, const void *pRight) { } int32_t compareInt8Float(const void *pLeft, const void *pRight) { - int8_t left = GET_INT32_VAL(pLeft); + int8_t left = GET_INT8_VAL(pLeft); float right = GET_FLOAT_VAL(pRight); if (left > right) return 1; if (left < right) return -1; @@ -281,7 +281,7 @@ int32_t compareInt8Float(const void *pLeft, const void *pRight) { } int32_t compareInt8Double(const void *pLeft, const void *pRight) { - int8_t left = GET_INT32_VAL(pLeft); + int8_t left = GET_INT8_VAL(pLeft); double right = GET_DOUBLE_VAL(pRight); if (left > right) return 1; if (left < right) return -1; @@ -289,7 +289,7 @@ int32_t compareInt8Double(const void *pLeft, const void *pRight) { } int32_t compareInt8Uint8(const void *pLeft, const void *pRight) { - int8_t left = GET_INT32_VAL(pLeft); + int8_t left = GET_INT8_VAL(pLeft); uint8_t right = GET_UINT8_VAL(pRight); if (left > right) return 1; if (left < right) return -1; @@ -297,7 +297,7 @@ int32_t compareInt8Uint8(const void *pLeft, const void *pRight) { } int32_t compareInt8Uint16(const void *pLeft, const void *pRight) { - int8_t left = GET_INT32_VAL(pLeft); + int8_t left = GET_INT8_VAL(pLeft); uint16_t right = GET_UINT16_VAL(pRight); if (left > right) return 1; if (left < right) return -1; @@ -305,7 +305,7 @@ int32_t compareInt8Uint16(const void *pLeft, const void *pRight) { } int32_t compareInt8Uint32(const void *pLeft, const void *pRight) { - int8_t left = GET_INT32_VAL(pLeft); + int8_t left = GET_INT8_VAL(pLeft); uint32_t right = GET_UINT32_VAL(pRight); if (left > right) return 1; if (left < right) return -1; @@ -313,7 +313,7 @@ int32_t compareInt8Uint32(const void *pLeft, const void *pRight) { } int32_t compareInt8Uint64(const void *pLeft, const void *pRight) { - int8_t left = GET_INT32_VAL(pLeft); + int8_t left = GET_INT8_VAL(pLeft); uint64_t right = GET_UINT64_VAL(pRight); if (left > right) return 1; if (left < right) return -1; @@ -321,7 +321,7 @@ int32_t compareInt8Uint64(const void *pLeft, const void *pRight) { } int32_t compareInt16Int8(const void *pLeft, const void *pRight) { - int16_t left = GET_INT32_VAL(pLeft); + int16_t left = GET_INT16_VAL(pLeft); int8_t right = GET_INT8_VAL(pRight); if (left > right) return 1; if (left < right) return -1; @@ -329,7 +329,7 @@ int32_t compareInt16Int8(const void *pLeft, const void *pRight) { } int32_t compareInt16Int32(const void *pLeft, const void *pRight) { - int16_t left = GET_INT32_VAL(pLeft); + int16_t left = GET_INT16_VAL(pLeft); int32_t right = GET_INT32_VAL(pRight); if (left > right) return 1; if (left < right) return -1; @@ -337,7 +337,7 @@ int32_t compareInt16Int32(const void *pLeft, const void *pRight) { } int32_t compareInt16Int64(const void *pLeft, const void *pRight) { - int16_t left = GET_INT32_VAL(pLeft); + int16_t left = GET_INT16_VAL(pLeft); int64_t right = GET_INT64_VAL(pRight); if (left > right) return 1; if (left < right) return -1; @@ -345,7 +345,7 @@ int32_t compareInt16Int64(const void *pLeft, const void *pRight) { } int32_t compareInt16Float(const void *pLeft, const void *pRight) { - int16_t left = GET_INT32_VAL(pLeft); + int16_t left = GET_INT16_VAL(pLeft); float right = GET_FLOAT_VAL(pRight); if (left > right) return 1; if (left < right) return -1; @@ -353,7 +353,7 @@ int32_t compareInt16Float(const void *pLeft, const void *pRight) { } int32_t compareInt16Double(const void *pLeft, const void *pRight) { - int16_t left = GET_INT32_VAL(pLeft); + int16_t left = GET_INT16_VAL(pLeft); double right = GET_DOUBLE_VAL(pRight); if (left > right) return 1; if (left < right) return -1; @@ -361,7 +361,7 @@ int32_t compareInt16Double(const void *pLeft, const void *pRight) { } int32_t compareInt16Uint8(const void *pLeft, const void *pRight) { - int16_t left = GET_INT32_VAL(pLeft); + int16_t left = GET_INT16_VAL(pLeft); uint8_t right = GET_UINT8_VAL(pRight); if (left > right) return 1; if (left < right) return -1; @@ -369,7 +369,7 @@ int32_t compareInt16Uint8(const void *pLeft, const void *pRight) { } int32_t compareInt16Uint16(const void *pLeft, const void *pRight) { - int16_t left = GET_INT32_VAL(pLeft); + int16_t left = GET_INT16_VAL(pLeft); uint16_t right = GET_UINT16_VAL(pRight); if (left > right) return 1; if (left < right) return -1; @@ -377,7 +377,7 @@ int32_t compareInt16Uint16(const void *pLeft, const void *pRight) { } int32_t compareInt16Uint32(const void *pLeft, const void *pRight) { - int16_t left = GET_INT32_VAL(pLeft); + int16_t left = GET_INT16_VAL(pLeft); uint32_t right = GET_UINT32_VAL(pRight); if (left > right) return 1; if (left < right) return -1; @@ -385,7 +385,7 @@ int32_t compareInt16Uint32(const void *pLeft, const void *pRight) { } int32_t compareInt16Uint64(const void *pLeft, const void *pRight) { - int16_t left = GET_INT32_VAL(pLeft); + int16_t left = GET_INT16_VAL(pLeft); uint64_t right = GET_UINT64_VAL(pRight); if (left > right) return 1; if (left < right) return -1; diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index 0bf9e7cc3365240f34fe2b8697559cf60f5fdfe9..c1fee376103a15407e84d4ef988a01676884c468 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -722,13 +722,13 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) { const char *filepath = ".env"; if (envFile != NULL && strlen(envFile) > 0) { if (!taosCheckExistFile(envFile)) { - uError("failed to load env file: %s", envFile); + uError("failed to load env file:%s", envFile); return -1; } filepath = envFile; } else { if (!taosCheckExistFile(filepath)) { - uInfo("failed to load env file: %s", filepath); + uInfo("env file:%s not load", filepath); return 0; } } @@ -915,7 +915,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { int32_t olen, vlen, vlen2, vlen3; int32_t code = 0; if (url == NULL || strlen(url) == 0) { - uInfo("fail to load apoll url"); + uInfo("apoll url not load"); return 0; } @@ -929,7 +929,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { if (strncmp(url, "jsonFile", 8) == 0) { char *filepath = p; if (!taosCheckExistFile(filepath)) { - uError("failed to load json file: %s", filepath); + uError("failed to load json file:%s", filepath); return -1; } @@ -1056,13 +1056,13 @@ int32_t cfgGetApollUrl(const char **envCmd, const char *envFile, char *apolloUrl const char *filepath = ".env"; if (envFile != NULL && strlen(envFile) > 0) { if (!taosCheckExistFile(envFile)) { - uError("failed to load env file: %s", envFile); + uError("failed to load env file:%s", envFile); return -1; } filepath = envFile; } else { if (!taosCheckExistFile(filepath)) { - uInfo("failed to load env file: %s", filepath); + uInfo("env file:%s not load", filepath); return 0; } } diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 37f9734eab20482755b8305a6cb2be6a08407493..0e6568d692996b84d0996c315ab8934a73aaf64d 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -94,6 +94,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_INVALID_TIMESTAMP, "Invalid timestamp for TAOS_DEFINE_ERROR(TSDB_CODE_MSG_DECODE_ERROR, "Msg decode error") TAOS_DEFINE_ERROR(TSDB_CODE_NO_AVAIL_DISK, "No available disk") TAOS_DEFINE_ERROR(TSDB_CODE_NOT_FOUND, "Not found") +TAOS_DEFINE_ERROR(TSDB_CODE_NO_DISKSPACE, "Out of disk space") //client TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_OPERATION, "Invalid operation") @@ -109,7 +110,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_DB_LENGTH, "Database name too lon TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_TABLE_ID_LENGTH, "Table name too long") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_CONNECTION, "Invalid connection") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_OUT_OF_MEMORY, "System out of memory") -TAOS_DEFINE_ERROR(TSDB_CODE_TSC_NO_DISKSPACE, "System out of disk space") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_QUERY_CACHE_ERASED, "Query cache erased") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_QUERY_CANCELLED, "Query terminated") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_SORTED_RES_TOO_MANY, "Result set too large to be sorted") // too many result for ordered super table projection query @@ -225,11 +225,13 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_ALREADY_EXIST, "Database already exis TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DB_OPTION, "Invalid database options") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DB, "Invalid database name") TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_DATABASES, "Too many databases for account") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_IN_DROPPING, "Database in dropping status") TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_NOT_EXIST, "Database not exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_DB_ACCT, "Invalid database account") TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_OPTION_UNCHANGED, "Database options not changed") TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_INDEX_NOT_EXIST, "Index not exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_SYS_TABLENAME, "Invalid system table name") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_IN_CREATING, "Database in creating status") // mnode-node TAOS_DEFINE_ERROR(TSDB_CODE_MND_MNODE_ALREADY_EXIST, "Mnode already exists") @@ -305,35 +307,14 @@ TAOS_DEFINE_ERROR(TSDB_CODE_NODE_ALREADY_DEPLOYED, "Node already deployed TAOS_DEFINE_ERROR(TSDB_CODE_NODE_NOT_DEPLOYED, "Node not deployed") // vnode -TAOS_DEFINE_ERROR(TSDB_CODE_VND_ACTION_IN_PROGRESS, "Action in progress") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_MSG_NOT_PROCESSED, "Message not processed") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_ACTION_NEED_REPROCESSED, "Action need to be reprocessed") TAOS_DEFINE_ERROR(TSDB_CODE_VND_INVALID_VGROUP_ID, "Invalid Vgroup ID") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_INIT_FAILED, "Vnode initialization failed") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_DISKSPACE, "System out of disk space") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_DISK_PERMISSIONS, "No write permission for disk files") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_SUCH_FILE_OR_DIR, "Missing data file") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_OUT_OF_MEMORY, "Out of memory") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_APP_ERROR, "Unexpected generic error in vnode") - -TAOS_DEFINE_ERROR(TSDB_CODE_VND_IS_FLOWCTRL, "Database memory is full") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_IS_DROPPING, "Database is dropping") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_IS_UPDATING, "Database is updating") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_IS_CLOSING, "Database is closing") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_NOT_SYNCED, "Database suspended") TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_WRITE_AUTH, "Database write operation denied") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_IS_SYNCING, "Database is syncing") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_INVALID_TSDB_STATE, "Invalid tsdb state") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_TB_NOT_EXIST, "Table not exists") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_SMA_NOT_EXIST, "SMA not exists") TAOS_DEFINE_ERROR(TSDB_CODE_VND_HASH_MISMATCH, "Hash value mismatch") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_TABLE_NOT_EXIST, "Table does not exists") TAOS_DEFINE_ERROR(TSDB_CODE_VND_INVALID_TABLE_ACTION, "Invalid table action") TAOS_DEFINE_ERROR(TSDB_CODE_VND_COL_ALREADY_EXISTS, "Table column already exists") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_TABLE_COL_NOT_EXISTS, "Table column not exists") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_COL_NOT_EXISTS, "Table column not exists") TAOS_DEFINE_ERROR(TSDB_CODE_VND_COL_SUBSCRIBED, "Table column is subscribed") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_INVALID_CFG_FILE, "Invalid config file") -TAOS_DEFINE_ERROR(TSDB_CODE_VND_INVALID_TERM_FILE, "Invalid term file") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_NO_AVAIL_BUFPOOL, "No availabe buffer pool") // tsdb TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_TABLE_ID, "Invalid table ID") @@ -342,7 +323,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TDB_IVD_TB_SCHEMA_VERSION, "Invalid table schema TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TABLE_ALREADY_EXIST, "Table already exists") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_CONFIG, "Invalid configuration") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INIT_FAILED, "Tsdb init failed") -TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_DISKSPACE, "No diskspace for tsdb") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_DISK_PERMISSIONS, "No permission for disk files") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_FILE_CORRUPTED, "Data file(s) corrupted") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_OUT_OF_MEMORY, "Out of memory") @@ -362,13 +342,12 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TDB_NO_CACHE_LAST_ROW, "TSDB no cache last ro TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TABLE_NOT_EXIST, "Table not exists") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_STB_ALREADY_EXIST, "Stable already exists") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_STB_NOT_EXIST, "Stable not exists") -TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TABLE_RECREATED, "Table re-created") +TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_TABLE_SCHEMA_VER, "Table schema is old") TAOS_DEFINE_ERROR(TSDB_CODE_TDB_TDB_ENV_OPEN_ERROR, "TDB env open error") // query TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INVALID_QHANDLE, "Invalid handle") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INVALID_MSG, "Invalid message") // failed to validate the sql expression msg by vnode -TAOS_DEFINE_ERROR(TSDB_CODE_QRY_NO_DISKSPACE, "No diskspace for query") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_OUT_OF_MEMORY, "System out of memory") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_APP_ERROR, "Unexpected generic error in query") TAOS_DEFINE_ERROR(TSDB_CODE_QRY_DUP_JOIN_KEY, "Duplicated join key") @@ -431,7 +410,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_SYN_INTERNAL_ERROR, "Sync internal error") //tq TAOS_DEFINE_ERROR(TSDB_CODE_TQ_INVALID_CONFIG, "TQ invalid config") TAOS_DEFINE_ERROR(TSDB_CODE_TQ_INIT_FAILED, "TQ init falied") -TAOS_DEFINE_ERROR(TSDB_CODE_TQ_NO_DISKSPACE, "TQ no disk space") TAOS_DEFINE_ERROR(TSDB_CODE_TQ_NO_DISK_PERMISSIONS, "TQ no disk permissions") TAOS_DEFINE_ERROR(TSDB_CODE_TQ_FILE_CORRUPTED, "TQ file corrupted") TAOS_DEFINE_ERROR(TSDB_CODE_TQ_OUT_OF_MEMORY, "TQ out of memory") @@ -452,6 +430,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_WAL_INVALID_VER, "WAL use invalid versi TAOS_DEFINE_ERROR(TSDB_CODE_WAL_OUT_OF_MEMORY, "WAL out of memory") TAOS_DEFINE_ERROR(TSDB_CODE_WAL_LOG_NOT_EXIST, "WAL log not exist") TAOS_DEFINE_ERROR(TSDB_CODE_WAL_CHKSUM_MISMATCH, "WAL checksum mismatch") +TAOS_DEFINE_ERROR(TSDB_CODE_WAL_LOG_INCOMPLETE, "WAL log incomplete") // tfs TAOS_DEFINE_ERROR(TSDB_CODE_FS_INVLD_CFG, "tfs invalid mount config") @@ -632,6 +611,9 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TMQ_INVALID_MSG, "Invalid message") TAOS_DEFINE_ERROR(TSDB_CODE_TMQ_CONSUMER_MISMATCH, "Consumer mismatch") TAOS_DEFINE_ERROR(TSDB_CODE_TMQ_CONSUMER_CLOSED, "Consumer closed") +// stream +TAOS_DEFINE_ERROR(TSDB_CODE_STREAM_TASK_NOT_EXIST, "Stream task not exist") + // TDLite TAOS_DEFINE_ERROR(TSDB_CODE_TDLITE_IVLD_OPEN_FLAGS, "Invalid TDLite open flags") TAOS_DEFINE_ERROR(TSDB_CODE_TDLITE_IVLD_OPEN_DIR, "Invalid TDLite open directory") diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 618b80760f385187bcbab952079e8b6e76620aa7..f7949048ca052e25a800ffcd1a3f5021a87b804d 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -81,25 +81,25 @@ int64_t tsNumOfDebugLogs = 0; int64_t tsNumOfTraceLogs = 0; // log -int32_t dDebugFlag = 135; -int32_t vDebugFlag = 135; -int32_t mDebugFlag = 135; +int32_t dDebugFlag = 131; +int32_t vDebugFlag = 131; +int32_t mDebugFlag = 131; int32_t cDebugFlag = 131; int32_t jniDebugFlag = 131; int32_t tmrDebugFlag = 131; int32_t uDebugFlag = 131; int32_t rpcDebugFlag = 131; int32_t qDebugFlag = 131; -int32_t wDebugFlag = 135; -int32_t sDebugFlag = 135; +int32_t wDebugFlag = 131; +int32_t sDebugFlag = 131; int32_t tsdbDebugFlag = 131; int32_t tdbDebugFlag = 131; -int32_t tqDebugFlag = 135; -int32_t fsDebugFlag = 135; -int32_t metaDebugFlag = 135; -int32_t udfDebugFlag = 135; +int32_t tqDebugFlag = 131; +int32_t fsDebugFlag = 131; +int32_t metaDebugFlag = 131; +int32_t udfDebugFlag = 131; int32_t smaDebugFlag = 131; -int32_t idxDebugFlag = 135; +int32_t idxDebugFlag = 131; int64_t dbgEmptyW = 0; int64_t dbgWN = 0; @@ -317,14 +317,14 @@ static void taosGetLogFileName(char *fn) { for (int32_t i = 0; i < tsLogObj.fileNum; i++) { char fileName[LOG_FILE_NAME_LEN]; - sprintf(fileName, "%s%d.0", fn, i); + snprintf(fileName, LOG_FILE_NAME_LEN, "%s%d.0", fn, i); bool file1open = taosCheckFileIsOpen(fileName); - sprintf(fileName, "%s%d.1", fn, i); + snprintf(fileName, LOG_FILE_NAME_LEN, "%s%d.1", fn, i); bool file2open = taosCheckFileIsOpen(fileName); if (!file1open && !file2open) { - sprintf(tsLogObj.logName, "%s%d", fn, i); + snprintf(tsLogObj.logName, LOG_FILE_NAME_LEN, "%s%d", fn, i); return; } } @@ -586,7 +586,7 @@ static int32_t taosPushLogBuffer(SLogBuff *pLogBuf, const char *msg, int32_t msg int32_t end = 0; int32_t remainSize = 0; static int64_t lostLine = 0; - char tmpBuf[40] = {0}; + char tmpBuf[128] = {0}; int32_t tmpBufLen = 0; if (pLogBuf == NULL || pLogBuf->stop) return -1; @@ -598,7 +598,7 @@ static int32_t taosPushLogBuffer(SLogBuff *pLogBuf, const char *msg, int32_t msg remainSize = (start > end) ? (start - end - 1) : (start + LOG_BUF_SIZE(pLogBuf) - end - 1); if (lostLine > 0) { - sprintf(tmpBuf, "...Lost %" PRId64 " lines here...\n", lostLine); + snprintf(tmpBuf, tListLen(tmpBuf), "...Lost %" PRId64 " lines here...\n", lostLine); tmpBufLen = (int32_t)strlen(tmpBuf); } diff --git a/source/util/src/tlrucache.c b/source/util/src/tlrucache.c index 0ea7258828daae1422efc868b5b7d666e4c65fe8..264883be4e71c99f1f3f3a1fbc872bf0c522728e 100644 --- a/source/util/src/tlrucache.c +++ b/source/util/src/tlrucache.c @@ -630,13 +630,16 @@ static int getDefaultCacheShardBits(size_t capacity) { SLRUCache *taosLRUCacheInit(size_t capacity, int numShardBits, double highPriPoolRatio) { if (numShardBits >= 20) { + terrno = TSDB_CODE_INVALID_PARA; return NULL; } if (highPriPoolRatio < 0.0 || highPriPoolRatio > 1.0) { + terrno = TSDB_CODE_INVALID_PARA; return NULL; } SLRUCache *cache = taosMemoryCalloc(1, sizeof(SLRUCache)); if (!cache) { + terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } @@ -648,7 +651,7 @@ SLRUCache *taosLRUCacheInit(size_t capacity, int numShardBits, double highPriPoo cache->shards = taosMemoryCalloc(numShards, sizeof(SLRUCacheShard)); if (!cache->shards) { taosMemoryFree(cache); - + terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } diff --git a/source/util/src/tqueue.c b/source/util/src/tqueue.c index 19b9b89caba70b8769de2e79a9902ec8721f7784..0f992184b579fa8ab1e4855f43e61f81b772c07c 100644 --- a/source/util/src/tqueue.c +++ b/source/util/src/tqueue.c @@ -21,46 +21,6 @@ int64_t tsRpcQueueMemoryAllowed = 0; int64_t tsRpcQueueMemoryUsed = 0; -typedef struct STaosQnode STaosQnode; - -typedef struct STaosQnode { - STaosQnode *next; - STaosQueue *queue; - int64_t timestamp; - int32_t size; - int8_t itype; - int8_t reserved[3]; - char item[]; -} STaosQnode; - -typedef struct STaosQueue { - STaosQnode *head; - STaosQnode *tail; - STaosQueue *next; // for queue set - STaosQset *qset; // for queue set - void *ahandle; // for queue set - FItem itemFp; - FItems itemsFp; - TdThreadMutex mutex; - int64_t memOfItems; - int32_t numOfItems; -} STaosQueue; - -typedef struct STaosQset { - STaosQueue *head; - STaosQueue *current; - TdThreadMutex mutex; - tsem_t sem; - int32_t numOfQueues; - int32_t numOfItems; -} STaosQset; - -typedef struct STaosQall { - STaosQnode *current; - STaosQnode *start; - int32_t numOfItems; -} STaosQall; - STaosQueue *taosOpenQueue() { STaosQueue *queue = taosMemoryCalloc(1, sizeof(STaosQueue)); if (queue == NULL) { @@ -248,7 +208,7 @@ STaosQall *taosAllocateQall() { void taosFreeQall(STaosQall *qall) { taosMemoryFree(qall); } int32_t taosReadAllQitems(STaosQueue *queue, STaosQall *qall) { - int32_t code = 0; + int32_t numOfItems = 0; bool empty; taosThreadMutexLock(&queue->mutex); @@ -259,13 +219,14 @@ int32_t taosReadAllQitems(STaosQueue *queue, STaosQall *qall) { qall->current = queue->head; qall->start = queue->head; qall->numOfItems = queue->numOfItems; - code = qall->numOfItems; + numOfItems = qall->numOfItems; queue->head = NULL; queue->tail = NULL; queue->numOfItems = 0; queue->memOfItems = 0; - uTrace("read %d items from queue:%p, items:%d mem:%" PRId64, code, queue, queue->numOfItems, queue->memOfItems); + uTrace("read %d items from queue:%p, items:%d mem:%" PRId64, numOfItems, queue, queue->numOfItems, + queue->memOfItems); if (queue->qset) atomic_sub_fetch_32(&queue->qset->numOfItems, qall->numOfItems); } @@ -277,7 +238,7 @@ int32_t taosReadAllQitems(STaosQueue *queue, STaosQall *qall) { qall->start = NULL; qall->numOfItems = 0; } - return code; + return numOfItems; } int32_t taosGetQitem(STaosQall *qall, void **ppItem) { diff --git a/source/util/src/tref.c b/source/util/src/tref.c index c984ef3f34dd50b669acf12f14233d6f7374f3b5..b4322464e2107b71a19acf5a36dd7ee9a51278df 100644 --- a/source/util/src/tref.c +++ b/source/util/src/tref.c @@ -57,7 +57,7 @@ static void taosIncRsetCount(SRefSet *pSet); static void taosDecRsetCount(SRefSet *pSet); static int32_t taosDecRefCount(int32_t rsetId, int64_t rid, int32_t remove); -int32_t taosOpenRef(int32_t max, void (*fp)(void *)) { +int32_t taosOpenRef(int32_t max, RefFp fp) { SRefNode **nodeList; SRefSet *pSet; int64_t *lockedBy; @@ -361,7 +361,7 @@ int32_t taosListRef() { if (pSet->state == TSDB_REF_STATE_EMPTY) continue; - uInfo("rsetId:%d state:%d count::%d", i, pSet->state, pSet->count); + uInfo("rsetId:%d state:%d count:%d", i, pSet->state, pSet->count); for (int32_t j = 0; j < pSet->max; ++j) { pNode = pSet->nodeList[j]; diff --git a/source/util/src/tworker.c b/source/util/src/tworker.c index f7d4173d3fcb4e30c927543436acb83596bf7339..863cee9b08ced50308afc11db48a5f15c49f8162 100644 --- a/source/util/src/tworker.c +++ b/source/util/src/tworker.c @@ -36,14 +36,13 @@ int32_t tQWorkerInit(SQWorkerPool *pool) { worker->pool = pool; } - uInfo("worker:%s is initialized, min:%d max:%d", pool->name, pool->min, pool->max); + uDebug("worker:%s is initialized, min:%d max:%d", pool->name, pool->min, pool->max); return 0; } void tQWorkerCleanup(SQWorkerPool *pool) { for (int32_t i = 0; i < pool->max; ++i) { SQWorker *worker = pool->workers + i; - // if (worker == NULL) continue; if (taosCheckPthreadValid(worker->thread)) { taosQsetThreadResume(pool->qset); } @@ -51,7 +50,6 @@ void tQWorkerCleanup(SQWorkerPool *pool) { for (int32_t i = 0; i < pool->max; ++i) { SQWorker *worker = pool->workers + i; - // if (worker == NULL) continue; if (taosCheckPthreadValid(worker->thread)) { taosThreadJoin(worker->thread, NULL); taosThreadClear(&worker->thread); @@ -73,11 +71,13 @@ static void *tQWorkerThreadFp(SQWorker *worker) { taosBlockSIGPIPE(); setThreadName(pool->name); - uDebug("worker:%s:%d is running", pool->name, worker->id); + worker->pid = taosGetSelfPthreadId(); + uInfo("worker:%s:%d is running, thread:%08" PRId64, pool->name, worker->id, worker->pid); while (1) { if (taosReadQitemFromQset(pool->qset, (void **)&msg, &qinfo) == 0) { - uDebug("worker:%s:%d qset:%p, got no message and exiting", pool->name, worker->id, pool->qset); + uInfo("worker:%s:%d qset:%p, got no message and exiting, thread:%08" PRId64, pool->name, worker->id, pool->qset, + worker->pid); break; } @@ -124,7 +124,7 @@ STaosQueue *tQWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp) { } taosThreadMutexUnlock(&pool->mutex); - uDebug("worker:%s, queue:%p is allocated, ahandle:%p", pool->name, queue, ahandle); + uInfo("worker:%s, queue:%p is allocated, ahandle:%p", pool->name, queue, ahandle); return queue; } @@ -191,12 +191,14 @@ static void *tWWorkerThreadFp(SWWorker *worker) { taosBlockSIGPIPE(); setThreadName(pool->name); - uDebug("worker:%s:%d is running", pool->name, worker->id); + worker->pid = taosGetSelfPthreadId(); + uInfo("worker:%s:%d is running, thread:%08" PRId64, pool->name, worker->id, worker->pid); while (1) { numOfMsgs = taosReadAllQitemsFromQset(worker->qset, worker->qall, &qinfo); if (numOfMsgs == 0) { - uDebug("worker:%s:%d qset:%p, got no message and exiting", pool->name, worker->id, worker->qset); + uInfo("worker:%s:%d qset:%p, got no message and exiting, thread:%08" PRId64, pool->name, worker->id, worker->qset, + worker->pid); break; } @@ -244,7 +246,6 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) { pool->nextId = (pool->nextId + 1) % pool->max; } - uDebug("worker:%s, queue:%p is allocated, ahandle:%p", pool->name, queue, ahandle); code = 0; _OVER: @@ -256,6 +257,9 @@ _OVER: if (worker->qall != NULL) taosFreeQall(worker->qall); return NULL; } else { + while (worker->pid <= 0) taosMsleep(10); + queue->threadId = worker->pid; + uInfo("worker:%s, queue:%p is allocated, ahandle:%p thread:%08" PRId64, pool->name, queue, ahandle, queue->threadId); return queue; } } diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/auto_create_table_json.py b/tests/develop-test/5-taos-tools/taosbenchmark/auto_create_table_json.py index 8509136a3443a1bc13bbaac0cc073363c14a7186..4e3c9d07ce8d0242201cccc234abb8854552e8b0 100644 --- a/tests/develop-test/5-taos-tools/taosbenchmark/auto_create_table_json.py +++ b/tests/develop-test/5-taos-tools/taosbenchmark/auto_create_table_json.py @@ -25,7 +25,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/commandline.py b/tests/develop-test/5-taos-tools/taosbenchmark/commandline.py index 1d21c517e60715f88ddab265a1a380d4601edd80..163cdd0055640d2ff4261096801ed2813747a42c 100644 --- a/tests/develop-test/5-taos-tools/taosbenchmark/commandline.py +++ b/tests/develop-test/5-taos-tools/taosbenchmark/commandline.py @@ -27,7 +27,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/custom_col_tag.py b/tests/develop-test/5-taos-tools/taosbenchmark/custom_col_tag.py index 9104d6309611916cbd88a1d61a1446bf54a25859..0fb39c210c96d9a5db7b2f4216fe023499002f01 100644 --- a/tests/develop-test/5-taos-tools/taosbenchmark/custom_col_tag.py +++ b/tests/develop-test/5-taos-tools/taosbenchmark/custom_col_tag.py @@ -24,7 +24,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/default_json.py b/tests/develop-test/5-taos-tools/taosbenchmark/default_json.py index c68375894c6f34bdccc33789384f6113aeb6e105..7599c82483509807d222d73557d3164c35159403 100644 --- a/tests/develop-test/5-taos-tools/taosbenchmark/default_json.py +++ b/tests/develop-test/5-taos-tools/taosbenchmark/default_json.py @@ -23,7 +23,8 @@ class TDTestCase: [TD-11510] taosBenchmark test cases """ - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/demo.py b/tests/develop-test/5-taos-tools/taosbenchmark/demo.py index a44ad4c1d0b5cc8e4ba181c1bf941454929f2df6..6be5117b08e8976c11e86b8cbb8072a3e3f8f876 100644 --- a/tests/develop-test/5-taos-tools/taosbenchmark/demo.py +++ b/tests/develop-test/5-taos-tools/taosbenchmark/demo.py @@ -27,7 +27,8 @@ class TDTestCase: """ return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/insert_alltypes_json.py b/tests/develop-test/5-taos-tools/taosbenchmark/insert_alltypes_json.py index 38332f7b64003c2595910fc7632c2a88fc3d9747..e63908ce339c0d7757ec750422ae1933cb23fc36 100644 --- a/tests/develop-test/5-taos-tools/taosbenchmark/insert_alltypes_json.py +++ b/tests/develop-test/5-taos-tools/taosbenchmark/insert_alltypes_json.py @@ -24,7 +24,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/invalid_commandline.py b/tests/develop-test/5-taos-tools/taosbenchmark/invalid_commandline.py index ebddff56436c53ca1f15b714e58204aaeeee6c89..73894d5e333704e10e6190a417396ee5eefd24a8 100644 --- a/tests/develop-test/5-taos-tools/taosbenchmark/invalid_commandline.py +++ b/tests/develop-test/5-taos-tools/taosbenchmark/invalid_commandline.py @@ -24,7 +24,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/json/queryInsertdata.json b/tests/develop-test/5-taos-tools/taosbenchmark/json/queryInsertdata.json new file mode 100644 index 0000000000000000000000000000000000000000..7e3ffe16973429200301aef7996119d3082cf7c1 --- /dev/null +++ b/tests/develop-test/5-taos-tools/taosbenchmark/json/queryInsertdata.json @@ -0,0 +1,74 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "thread_count": 4, + "thread_count_create_tbl": 4, + "result_file": "./insert_res.txt", + "confirm_parameter_prompt": "no", + "insert_interval": 0, + "interlace_rows": 0, + "num_of_records_per_req": 3000, + "max_sql_len": 1024000, + "databases": [{ + "dbinfo": { + "name": "db", + "drop": "yes", + "replica": 1, + "precision": "ms" + }, + "super_tables": [{ + "name": "stb0", + "child_table_exists":"no", + "childtable_count": 10, + "childtable_prefix": "stb00_", + "auto_create_table": "no", + "batch_create_tbl_num": 10, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 100, + "childtable_limit": 0, + "childtable_offset": 0, + "interlace_rows": 0, + "insert_interval": 0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-11-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "BINARY", "len": 1, "count":1}, {"type": "BINARY", "len": 3, "count":1}, {"type": "INT"}, {"type": "DOUBLE", "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":5}] + }, + { + "name": "stb1", + "child_table_exists":"no", + "childtable_count": 10, + "childtable_prefix": "stb01_", + "auto_create_table": "no", + "batch_create_tbl_num": 10, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 200, + "childtable_limit": 0, + "childtable_offset": 0, + "interlace_rows": 0 , + "insert_interval": 0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-11-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":6}, {"type": "BINARY", "len": 1, "count":3}, {"type": "BINARY", "len": 2, "count":6}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":5}] + }] + }] +} diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/json/queryInsertrestdata.json b/tests/develop-test/5-taos-tools/taosbenchmark/json/queryInsertrestdata.json new file mode 100644 index 0000000000000000000000000000000000000000..67144977665c0140d2e613d1f14bb72301217a78 --- /dev/null +++ b/tests/develop-test/5-taos-tools/taosbenchmark/json/queryInsertrestdata.json @@ -0,0 +1,73 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "thread_count": 4, + "thread_count_create_tbl": 4, + "result_file": "./insert_res.txt", + "confirm_parameter_prompt": "no", + "insert_interval": 0, + "interlace_rows": 0, + "num_of_records_per_req": 3000, + "max_sql_len": 1024000, + "databases": [{ + "dbinfo": { + "name": "db", + "drop": "yes", + "precision": "ms" + }, + "super_tables": [{ + "name": "stb0", + "child_table_exists":"no", + "childtable_count": 2, + "childtable_prefix": "stb00_", + "auto_create_table": "no", + "batch_create_tbl_num": 10, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 10, + "childtable_limit": 0, + "childtable_offset": 0, + "interlace_rows": 0, + "insert_interval": 0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-11-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "BINARY", "len": 1, "count":1}, {"type": "BINARY", "len": 3, "count":1}, {"type": "INT"}, {"type": "DOUBLE", "count":1}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":5}] + }, + { + "name": "stb1", + "child_table_exists":"no", + "childtable_count": 2, + "childtable_prefix": "stb01_", + "auto_create_table": "no", + "batch_create_tbl_num": 10, + "data_source": "rand", + "insert_mode": "taosc", + "insert_rows": 5, + "childtable_limit": 0, + "childtable_offset": 0, + "interlace_rows": 0 , + "insert_interval": 0, + "max_sql_len": 1024000, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1, + "start_timestamp": "2020-11-01 00:00:00.000", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [{"type": "INT"}, {"type": "DOUBLE", "count":6}, {"type": "BINARY", "len": 1, "count":3}, {"type": "BINARY", "len": 2, "count":6}], + "tags": [{"type": "TINYINT", "count":2}, {"type": "BINARY", "len": 16, "count":5}] + }] + }] +} diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/json/queryQps.json b/tests/develop-test/5-taos-tools/taosbenchmark/json/queryQps.json new file mode 100644 index 0000000000000000000000000000000000000000..9e75d52a6cd360674e633be886f348556e470342 --- /dev/null +++ b/tests/develop-test/5-taos-tools/taosbenchmark/json/queryQps.json @@ -0,0 +1,35 @@ +{ + "filetype": "query", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "confirm_parameter_prompt": "no", + "databases": "db", + "query_times": 1, + "specified_table_query": { + "query_interval": 10, + "threads": 4, + "sqls": [ + { + "sql": "select last_row(*) from stb00_0", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_9 ", + "result": "./query_res1.txt" + }] + }, + "super_table_query": { + "stblname": "stb1", + "query_interval":20, + "threads": 4, + "sqls": [ + { + "sql": "select last_row(ts) from xxxx", + "result": "./query_res2.txt" + } + ] + } +} diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/json/queryRestful.json b/tests/develop-test/5-taos-tools/taosbenchmark/json/queryRestful.json new file mode 100644 index 0000000000000000000000000000000000000000..5de560fd217d17ca94690bc39c98a5f903ad1634 --- /dev/null +++ b/tests/develop-test/5-taos-tools/taosbenchmark/json/queryRestful.json @@ -0,0 +1,38 @@ +{ + "filetype": "query", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "confirm_parameter_prompt": "no", + "databases": "db", + "query_times": 2, + "query_mode": "rest", + "specified_table_query": { + "query_interval": 1, + "threads": 3, + "sqls": [ + { + "sql": "select last_row(*) from db.stb0 ", + "result": "./query_res0.txt" + }, + { + "sql": "select count(*) from db.stb00_1", + "result": "./query_res1.txt" + } + ] + }, + "super_table_query": { + "stblname": "stb1", + "query_interval": 1, + "threads": 3, + "sqls": [ + { + "sql": "select last_row(ts) from xxxx", + "result": "./query_res2.txt" + } + ] + } + } + diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/json/querySpeciMutisql100.json b/tests/develop-test/5-taos-tools/taosbenchmark/json/querySpeciMutisql100.json new file mode 100644 index 0000000000000000000000000000000000000000..a86d22d69dc4365e072e04233b27db1c87c5225e --- /dev/null +++ b/tests/develop-test/5-taos-tools/taosbenchmark/json/querySpeciMutisql100.json @@ -0,0 +1,429 @@ +{ + "filetype": "query", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "confirm_parameter_prompt": "no", + "databases": "db", + "query_times": 2, + "specified_table_query": { + "query_interval": 1, + "threads": 3, + "sqls": [ + { + "sql": "select last_row(*) from stb00_0", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_1", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_2", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_3", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_4", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_5", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_6", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_7", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_8", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_9", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_10 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_11 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_12 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_13 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_14 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_15 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_16 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_17 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_18 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_19 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_20 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_21 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_22 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_23 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_24 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_25 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_26 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_27 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_28 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_29 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_30 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_31 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_32 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_33 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_34 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_35 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_36 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_37 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_38 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_39 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_40 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_41 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_42 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_43 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_44 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_45 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_46 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_47 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_48 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_49 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_50 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_51 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_52 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_53 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_54 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_55 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_56 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_57 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_58 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_59 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_60", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_61", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_62", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_63", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_64", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_65", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_66", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_67", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_68", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_69", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_70 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_71 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_72 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_73 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_74 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_75 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_76 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_77 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_78 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_79 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_80 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_81 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_82 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_83 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_84 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_85 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_86 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_87 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_88 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_89 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_90 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_91 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_92 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_93 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_94 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_95 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_96 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_97 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_98 ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from stb00_99 ", + "result": "./query_res0.txt" + + }] + }, + "super_table_query": { + "stblname": "stb1", + "query_interval": 1, + "threads": 3, + "sqls": [ + { + "sql": "select last_row(ts) from xxxx", + "result": "./query_res2.txt" + } + ] + } +} + \ No newline at end of file diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/json/querySuperMutisql100.json b/tests/develop-test/5-taos-tools/taosbenchmark/json/querySuperMutisql100.json new file mode 100644 index 0000000000000000000000000000000000000000..0f21df47e668d4e8cb5c137bf497192dc915f2f5 --- /dev/null +++ b/tests/develop-test/5-taos-tools/taosbenchmark/json/querySuperMutisql100.json @@ -0,0 +1,419 @@ +{ + "filetype": "query", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "confirm_parameter_prompt": "no", + "databases": "db", + "query_times": 3, + "super_table_query": { + "stblname": "stb0", + "query_interval": 10, + "threads": 9, + "sqls": [ + { + "sql": "select last_row(*) from xxxx", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select last_row(*) from xxxx ", + "result": "./query_res0.txt" + }, + { + "sql": "select * from xxxx ", + "result": "./query_res0.txt" + + }] + } +} + diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/json/queryTaosc.json b/tests/develop-test/5-taos-tools/taosbenchmark/json/queryTaosc.json new file mode 100644 index 0000000000000000000000000000000000000000..9ce423766047e0ab7394c622ab110b7574edf013 --- /dev/null +++ b/tests/develop-test/5-taos-tools/taosbenchmark/json/queryTaosc.json @@ -0,0 +1,37 @@ +{ + "filetype": "query", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "confirm_parameter_prompt": "no", + "databases": "db", + "query_times": 2, + "query_mode": "taosc", + "specified_table_query": { + "query_interval": 1, + "threads": 3, + "sqls": [ + { + "sql": "select last_row(*) from stb0 ", + "result": "./query_res0.txt" + }, + { + "sql": "select count(*) from stb00_1", + "result": "./query_res1.txt" + } + ] + }, + "super_table_query": { + "stblname": "stb1", + "query_interval": 1, + "threads": 3, + "sqls": [ + { + "sql": "select last_row(ts) from xxxx", + "result": "./query_res2.txt" + } + ] + } +} diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/json_tag.py b/tests/develop-test/5-taos-tools/taosbenchmark/json_tag.py index 5f25e0229b1033a13c12b82b06669d43a156cf8e..afefabef66ef8b242a98874d5c15442e173f2df9 100644 --- a/tests/develop-test/5-taos-tools/taosbenchmark/json_tag.py +++ b/tests/develop-test/5-taos-tools/taosbenchmark/json_tag.py @@ -24,7 +24,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/limit_offset_json.py b/tests/develop-test/5-taos-tools/taosbenchmark/limit_offset_json.py index 47a60e475725123f877b055d699ab217bbb77236..d95e6741f8af4ee837fe903dbc60fee894bebd7f 100644 --- a/tests/develop-test/5-taos-tools/taosbenchmark/limit_offset_json.py +++ b/tests/develop-test/5-taos-tools/taosbenchmark/limit_offset_json.py @@ -24,7 +24,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/query_json.py b/tests/develop-test/5-taos-tools/taosbenchmark/query_json.py index 84d9433967abb07baecb5da0870d97ff9c066f20..375113c3efa5c49be41afd7aab69a1d3a1a799a3 100644 --- a/tests/develop-test/5-taos-tools/taosbenchmark/query_json.py +++ b/tests/develop-test/5-taos-tools/taosbenchmark/query_json.py @@ -29,7 +29,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/sample_csv_json.py b/tests/develop-test/5-taos-tools/taosbenchmark/sample_csv_json.py index 772bb11df4e43171d5bffd3668a6124a0bf6bd12..fd79f1e01b4ad28f8dfb75a13d114113ab1604ea 100644 --- a/tests/develop-test/5-taos-tools/taosbenchmark/sample_csv_json.py +++ b/tests/develop-test/5-taos-tools/taosbenchmark/sample_csv_json.py @@ -24,7 +24,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/sml_interlace.py b/tests/develop-test/5-taos-tools/taosbenchmark/sml_interlace.py index fec93765297c715b2aa33846c0a9b15fccd7ec1f..200a3c0e69bc5b2e6c3b3dd6926885c5ca8d6f8f 100644 --- a/tests/develop-test/5-taos-tools/taosbenchmark/sml_interlace.py +++ b/tests/develop-test/5-taos-tools/taosbenchmark/sml_interlace.py @@ -24,7 +24,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/sml_json_alltypes.py b/tests/develop-test/5-taos-tools/taosbenchmark/sml_json_alltypes.py index 557d2a4884f674c15e602a665836c46564e00d47..2c6d09b0f5b4782c692dab2af7e790a864a405bf 100644 --- a/tests/develop-test/5-taos-tools/taosbenchmark/sml_json_alltypes.py +++ b/tests/develop-test/5-taos-tools/taosbenchmark/sml_json_alltypes.py @@ -24,7 +24,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/sml_telnet_alltypes.py b/tests/develop-test/5-taos-tools/taosbenchmark/sml_telnet_alltypes.py index 8ff56b533902c70f9b2ac72b680446c14488fffc..241c6d63593d9cc5f203e88d7515d1085e446122 100644 --- a/tests/develop-test/5-taos-tools/taosbenchmark/sml_telnet_alltypes.py +++ b/tests/develop-test/5-taos-tools/taosbenchmark/sml_telnet_alltypes.py @@ -24,7 +24,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/taosadapter_json.py b/tests/develop-test/5-taos-tools/taosbenchmark/taosadapter_json.py index 3f0a05b66590bf1af74cc35676a4cbf3caacfe72..4d0adde1922bb62c8987133f14d0b7647c12b504 100644 --- a/tests/develop-test/5-taos-tools/taosbenchmark/taosadapter_json.py +++ b/tests/develop-test/5-taos-tools/taosbenchmark/taosadapter_json.py @@ -25,7 +25,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/taosdemoTestQueryWithJson.py b/tests/develop-test/5-taos-tools/taosbenchmark/taosdemoTestQueryWithJson.py new file mode 100644 index 0000000000000000000000000000000000000000..19500c7dca946f3c0a1887eaa3d4bdcfa35390ef --- /dev/null +++ b/tests/develop-test/5-taos-tools/taosbenchmark/taosdemoTestQueryWithJson.py @@ -0,0 +1,241 @@ +################################################################### +# 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 +from util.log import * +from util.cases import * +from util.sql import * +from util.dnodes import * +import time +from datetime import datetime +import ast +import re + +# from assertpy import assert_that +import subprocess + + +class TDTestCase: + def init(self, conn, logSql, replicaVarl=1): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def getPath(self, tool="taosBenchmark"): + selfPath = os.path.dirname(os.path.realpath(__file__)) + + if "community" in selfPath: + projPath = selfPath[: selfPath.find("community")] + elif "src" in selfPath: + projPath = selfPath[: selfPath.find("src")] + elif "/tools/" in selfPath: + projPath = selfPath[: selfPath.find("/tools/")] + elif "/tests/" in selfPath: + projPath = selfPath[: selfPath.find("/tests/")] + else: + tdLog.info("cannot found %s in path: %s, use system's" % (tool, selfPath)) + projPath = "/usr/local/taos/bin/" + + paths = [] + for root, dirs, files in os.walk(projPath): + if (tool) in files: + rootRealPath = os.path.dirname(os.path.realpath(root)) + if "packaging" not in rootRealPath: + paths.append(os.path.join(root, tool)) + break + if len(paths) == 0: + return "" + return paths[0] + + # 获取taosc接口查询的结果文件中的内容,返回每行数据,并断言数据的第一列内容。 + def assertfileDataTaosc(self, filename, expectResult): + self.filename = filename + self.expectResult = expectResult + with open("%s" % filename, "r+") as f1: + for line in f1.readlines(): + queryResultTaosc = line.strip().split()[0] + self.assertCheck(filename, queryResultTaosc, expectResult) + + # 获取restful接口查询的结果文件中的关键内容,目前的关键内容找到第一个key就跳出循,所以就只有一个数据。后续再修改多个结果文件。 + def getfileDataRestful(self, filename): + self.filename = filename + with open("%s" % filename, "r+") as f1: + for line in f1.readlines(): + contents = line.strip() + if contents.find("data") != -1: + pattern = re.compile("{.*}") + contents = pattern.search(contents).group() + contentsDict = ast.literal_eval(contents) # 字符串转换为字典 + queryResultRest = contentsDict["data"][0][0] + break + else: + queryResultRest = "" + return queryResultRest + + # 获取taosc接口查询次数 + def queryTimesTaosc(self, filename): + self.filename = filename + command = "cat %s |wc -l" % filename + times = int(subprocess.getstatusoutput(command)[1]) + return times + + # 获取restful接口查询次数 + def queryTimesRestful(self, filename): + self.filename = filename + command = 'cat %s |grep "200 OK" |wc -l' % filename + times = int(subprocess.getstatusoutput(command)[1]) + return times + + # 定义断言结果是否正确。不正确返回错误结果,正确即通过。 + def assertCheck(self, filename, queryResult, expectResult): + self.filename = filename + self.queryResult = queryResult + self.expectResult = expectResult + args0 = (filename, queryResult, expectResult) + assert queryResult == expectResult, ( + "Queryfile:%s ,result is %s != expect: %s" % args0 + ) + + def run(self): + binPath = self.getPath() + if binPath == "": + tdLog.exit("taosBenchmark not found!") + else: + tdLog.info("taosBenchmark use %s" % binPath) + + # delete useless files + os.system("rm -rf ./query_res*") + os.system("rm -rf ./all_query*") + + # taosc query: query specified table and query super table + os.system("%s -f ./5-taos-tools/taosbenchmark/json/queryInsertdata.json" % binPath) + os.system("%s -f ./5-taos-tools/taosbenchmark/json/queryTaosc.json" % binPath) + os.system("cat query_res0.txt* > all_query_res0_taosc.txt") + os.system("cat query_res1.txt* > all_query_res1_taosc.txt") + os.system("cat query_res2.txt* > all_query_res2_taosc.txt") + + # correct Times testcases + queryTimes0Taosc = self.queryTimesTaosc("all_query_res0_taosc.txt") + self.assertCheck("all_query_res0_taosc.txt", queryTimes0Taosc, 6) + + queryTimes1Taosc = self.queryTimesTaosc("all_query_res1_taosc.txt") + self.assertCheck("all_query_res1_taosc.txt", queryTimes1Taosc, 6) + + queryTimes2Taosc = self.queryTimesTaosc("all_query_res2_taosc.txt") + self.assertCheck("all_query_res2_taosc.txt", queryTimes2Taosc, 20) + + # correct data testcase + self.assertfileDataTaosc("all_query_res0_taosc.txt", "1604160000099") + self.assertfileDataTaosc("all_query_res1_taosc.txt", "100") + self.assertfileDataTaosc("all_query_res2_taosc.txt", "1604160000199") + + # delete useless files + os.system("rm -rf ./query_res*") + os.system("rm -rf ./all_query*") + + # use restful api to query + os.system("%s -f ./5-taos-tools/taosbenchmark/json/queryInsertrestdata.json" % binPath) + os.system("%s -f ./5-taos-tools/taosbenchmark/json/queryRestful.json" % binPath) + os.system("cat query_res0.txt* > all_query_res0_rest.txt") + os.system("cat query_res1.txt* > all_query_res1_rest.txt") + os.system("cat query_res2.txt* > all_query_res2_rest.txt") + + # correct Times testcases + queryTimes0Restful = self.queryTimesRestful("all_query_res0_rest.txt") + self.assertCheck("all_query_res0_rest.txt", queryTimes0Restful, 6) + + queryTimes1Restful = self.queryTimesRestful("all_query_res1_rest.txt") + self.assertCheck("all_query_res1_rest.txt", queryTimes1Restful, 6) + + queryTimes2Restful = self.queryTimesRestful("all_query_res2_rest.txt") + self.assertCheck("all_query_res2_rest.txt", queryTimes2Restful, 4) + + # correct data testcase + data0 = self.getfileDataRestful("all_query_res0_rest.txt") + if data0 != "2020-11-01 00:00:00.009" and data0 != "2020-10-31T16:00:00.009Z": + tdLog.exit( + "data0 is not 2020-11-01 00:00:00.009 and 2020-10-31T16:00:00.009Z" + ) + + data1 = self.getfileDataRestful("all_query_res1_rest.txt") + self.assertCheck("all_query_res1_rest.txt", data1, 10) + + data2 = self.getfileDataRestful("all_query_res2_rest.txt") + if data2 != "2020-11-01 00:00:00.004" and data2 != "2020-10-31T16:00:00.004Z": + tdLog.exit( + "data2 is not 2020-11-01 00:00:00.004 and 2020-10-31T16:00:00.004Z" + ) + + # query times less than or equal to 100 + assert ( + os.system("%s -f ./5-taos-tools/taosbenchmark/json/queryInsertdata.json" % binPath) == 0 + ) + assert ( + os.system("%s -f ./5-taos-tools/taosbenchmark/json/querySpeciMutisql100.json" % binPath) + != 0 + ) + assert ( + os.system("%s -f ./5-taos-tools/taosbenchmark/json/querySuperMutisql100.json" % binPath) + == 0 + ) + + # query result print QPS + os.system("%s -f ./5-taos-tools/taosbenchmark/json/queryInsertdata.json" % binPath) + exceptcode = os.system("%s -f ./5-taos-tools/taosbenchmark/json/queryQps.json" % binPath) + assert exceptcode == 0 + + # 2021.02.09 need modify taosBenchmakr code + # use illegal or out of range parameters query json file + os.system("%s -f ./5-taos-tools/taosbenchmark/json/queryInsertdata.json" % binPath) + # 2021.02.09 need modify taosBenchmakr code + # exceptcode = os.system( + # "%s -f ./taosbenchmark/json/queryTimes0.json" % + # binPath) + # assert exceptcode != 0 + + # 2021.02.09 need modify taosBenchmakr code + # exceptcode0 = os.system( + # "%s -f ./taosbenchmark/json/queryTimesless0.json" % + # binPath) + # assert exceptcode0 != 0 + + # exceptcode1 = os.system( + # "%s -f ./taosbenchmark/json/queryConcurrent0.json" % + # binPath) + # assert exceptcode2 != 0 + + # exceptcode3 = os.system( + # "%s -f ./taosbenchmark/json/querrThreadsless0.json" % + # binPath) + # assert exceptcode3 != 0 + + # exceptcode4 = os.system( + # "%s -f ./taosbenchmark/json/querrThreads0.json" % + # binPath) + # assert exceptcode4 != 0 + + # delete useless files + os.system("rm -rf ./insert_res.txt") + os.system("rm -rf 5-taos-tools/taosbenchmark/*.py.sql") + os.system("rm -rf ./querySystemInfo*") + os.system("rm -rf ./query_res*") + os.system("rm -rf ./all_query*") + os.system("rm -rf ./test_query_res0.txt") + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/develop-test/5-taos-tools/taosbenchmark/telnet_tcp.py b/tests/develop-test/5-taos-tools/taosbenchmark/telnet_tcp.py index 7aa0575f77625685631b691e578dcb365d94b1a6..78cb49846e9b6908ce8400508aa8da2c64fdff8b 100644 --- a/tests/develop-test/5-taos-tools/taosbenchmark/telnet_tcp.py +++ b/tests/develop-test/5-taos-tools/taosbenchmark/telnet_tcp.py @@ -25,7 +25,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestInspect.py b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestInspect.py index 33ba4034ec07925574c5c8bd23a2d7951010980c..a6c2062d6cefb5f41023ae7c5e1926e05c6dfb83 100644 --- a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestInspect.py +++ b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestInspect.py @@ -27,7 +27,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) self.tmpdir = "tmp" @@ -52,7 +53,7 @@ class TDTestCase: return paths[0] def run(self): - tdSql.prepare() + tdSql.prepare(replica=f"{self.replicaVar}") tdSql.execute("drop database if exists db") tdSql.execute("create database db days 11 keep 3649 blocks 8 ") diff --git a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeBigInt.py b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeBigInt.py index 75885edf9f2984504c01ecc02b2aa079db34fbaf..d10734abd7bfb08b8188534d3a7541cb5019adf6 100644 --- a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeBigInt.py +++ b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeBigInt.py @@ -27,7 +27,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) self.tmpdir = "tmp" @@ -50,7 +51,7 @@ class TDTestCase: return buildPath def run(self): - tdSql.prepare() + tdSql.prepare(replica=f"{self.replicaVar}") tdSql.execute("drop database if exists db") tdSql.execute("create database db days 11 keep 3649 blocks 8 ") diff --git a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeBinary.py b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeBinary.py index 41d4ba128d9d1c3c5d749e4696b71303cf15e2e7..98a128b4890895873126ddcd53d79a91248d8b8b 100644 --- a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeBinary.py +++ b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeBinary.py @@ -27,7 +27,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) self.tmpdir = "tmp" @@ -50,7 +51,7 @@ class TDTestCase: return buildPath def run(self): - tdSql.prepare() + tdSql.prepare(replica=f"{self.replicaVar}") tdSql.execute("drop database if exists db") tdSql.execute("create database db days 11 keep 3649 blocks 8 ") diff --git a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeBool.py b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeBool.py index 043fb49af3cdb24b78a327bd7ca06d524218e8fb..1342295d7df856002989f79c9a390d5ec85f0227 100644 --- a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeBool.py +++ b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeBool.py @@ -27,7 +27,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) self.tmpdir = "tmp" @@ -50,7 +51,7 @@ class TDTestCase: return buildPath def run(self): - tdSql.prepare() + tdSql.prepare(replica=f"{self.replicaVar}") tdSql.execute("drop database if exists db") tdSql.execute("create database db days 11 keep 3649 blocks 8 ") diff --git a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeDouble.py b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeDouble.py index 1eaa2bbfff541e1e76be0fa74a13de77b20873f9..f3de1c762800055b8d2b4463f4ce95922830380a 100644 --- a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeDouble.py +++ b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeDouble.py @@ -28,7 +28,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) self.tmpdir = "tmp" @@ -51,7 +52,7 @@ class TDTestCase: return buildPath def run(self): - tdSql.prepare() + tdSql.prepare(replica=f"{self.replicaVar}") tdSql.execute("drop database if exists db") tdSql.execute("create database db days 11 keep 3649 blocks 8 ") diff --git a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeFloat.py b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeFloat.py index 4373aa56694d5ac4b6d5d529b6eb5d3e3edf358c..1133c1d1a5e004ae25821d3096513a47daa89896 100644 --- a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeFloat.py +++ b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeFloat.py @@ -28,7 +28,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) self.tmpdir = "tmp" @@ -51,7 +52,7 @@ class TDTestCase: return buildPath def run(self): - tdSql.prepare() + tdSql.prepare(replica=f"{self.replicaVar}") tdSql.execute("drop database if exists db") tdSql.execute("create database db days 11 keep 3649 blocks 8 ") diff --git a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeInt.py b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeInt.py index 45009a716a5da3389f0f37713d73372a06ce4b21..933bc41bae65be318d59e618b2babe0f4227d411 100644 --- a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeInt.py +++ b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeInt.py @@ -27,7 +27,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) self.tmpdir = "tmp" @@ -50,7 +51,7 @@ class TDTestCase: return buildPath def run(self): - tdSql.prepare() + tdSql.prepare(replica=f"{self.replicaVar}") tdSql.execute("drop database if exists db") tdSql.execute("create database db days 11 keep 3649 blocks 8 ") diff --git a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeJson.py b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeJson.py index d1c4313c40375a8589ca05216856bb275d56c8b8..77dd3d39386ba0bceb3979f28f777d2ecb951063 100644 --- a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeJson.py +++ b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeJson.py @@ -27,7 +27,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) self.tmpdir = "tmp" @@ -50,7 +51,7 @@ class TDTestCase: return buildPath def run(self): - tdSql.prepare() + tdSql.prepare(replica=f"{self.replicaVar}") tdSql.execute("drop database if exists db") tdSql.execute("create database db days 11 keep 3649 blocks 8 ") diff --git a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeSmallInt.py b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeSmallInt.py index 941de25683ccb52e66992e8c6b15f337b53b19c5..5568c3679f0d1e32eb7779c3193be9b814d384ad 100644 --- a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeSmallInt.py +++ b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeSmallInt.py @@ -27,7 +27,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) self.tmpdir = "tmp" @@ -49,7 +50,7 @@ class TDTestCase: return buildPath def run(self): - tdSql.prepare() + tdSql.prepare(replica=f"{self.replicaVar}") tdSql.execute("drop database if exists db") tdSql.execute("create database db days 11 keep 3649 blocks 8 ") diff --git a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeTinyInt.py b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeTinyInt.py index e5392d38feaecee8d3e7d420b37717c6a03050bc..852aa17dc5e62084da0b377d4a01fb6aa9c0f4f6 100644 --- a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeTinyInt.py +++ b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeTinyInt.py @@ -27,7 +27,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) self.tmpdir = "tmp" @@ -49,7 +50,7 @@ class TDTestCase: return buildPath def run(self): - tdSql.prepare() + tdSql.prepare(replica=f"{self.replicaVar}") tdSql.execute("drop database if exists db") tdSql.execute("create database db days 11 keep 3649 blocks 8 ") diff --git a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeUnsignedBigInt.py b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeUnsignedBigInt.py index dd8dd5d76db4afd24b9948bf5ff3a708a33e319b..ab61b48c8f084abdf1d55586ed6ec48a593a0be1 100644 --- a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeUnsignedBigInt.py +++ b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeUnsignedBigInt.py @@ -27,7 +27,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) self.tmpdir = "tmp" @@ -50,7 +51,7 @@ class TDTestCase: return buildPath def run(self): - tdSql.prepare() + tdSql.prepare(replica=f"{self.replicaVar}") tdSql.execute("drop database if exists db") tdSql.execute("create database db days 11 keep 3649 blocks 8 ") diff --git a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeUnsignedInt.py b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeUnsignedInt.py index eacd1bb7ddcc9429959dea76f4bcb465b3041d1c..ae895712c0fbde605c8396a9aef0dee7524748b6 100644 --- a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeUnsignedInt.py +++ b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeUnsignedInt.py @@ -27,7 +27,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) self.tmpdir = "tmp" @@ -50,7 +51,7 @@ class TDTestCase: return buildPath def run(self): - tdSql.prepare() + tdSql.prepare(replica=f"{self.replicaVar}") tdSql.execute("drop database if exists db") tdSql.execute("create database db days 11 keep 3649 blocks 8 ") diff --git a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeUnsignedSmallInt.py b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeUnsignedSmallInt.py index ea362ad2b4179e114a5f0605bebd78b78a14706e..86bcfd92f21921bcb1228d45201053b66d3d9d6c 100644 --- a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeUnsignedSmallInt.py +++ b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeUnsignedSmallInt.py @@ -27,7 +27,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) self.tmpdir = "tmp" @@ -50,7 +51,7 @@ class TDTestCase: return buildPath def run(self): - tdSql.prepare() + tdSql.prepare(replica=f"{self.replicaVar}") tdSql.execute("drop database if exists db") tdSql.execute("create database db days 11 keep 3649 blocks 8 ") diff --git a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeUnsignedTinyInt.py b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeUnsignedTinyInt.py index a3ffc13d625e3390cbb4797883b62c84078d6026..d67dfea4081b396d310d9d6a23ae32f906d9e128 100644 --- a/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeUnsignedTinyInt.py +++ b/tests/develop-test/5-taos-tools/taosdump/taosdumpTestTypeUnsignedTinyInt.py @@ -27,7 +27,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) self.tmpdir = "tmp" @@ -50,7 +51,7 @@ class TDTestCase: return buildPath def run(self): - tdSql.prepare() + tdSql.prepare(replica=f"{self.replicaVar}") tdSql.execute("drop database if exists db") tdSql.execute("create database db days 11 keep 3649 blocks 8 ") diff --git a/tests/develop-test/fulltest.sh b/tests/develop-test/fulltest.sh index 69cade3855b087fc7638eea22b4926d088b5d86b..e986ed69663b6333110251273330a1ead19db4e6 100644 --- a/tests/develop-test/fulltest.sh +++ b/tests/develop-test/fulltest.sh @@ -18,3 +18,4 @@ python3 ./test.py -f 5-taos-tools/taosbenchmark/sml_json_alltypes.py #python3 ./test.py -f 5-taos-tools/taosbenchmark/sml_telnet_alltypes.py #python3 ./test.py -f 5-taos-tools/taosbenchmark/taosadapter_json.py #python3 ./test.py -f 5-taos-tools/taosbenchmark/telnet_tcp.py +python3 ./test.py -f 5-taos-tools/taosbenchmark/taosdemoTestQueryWithJson.py -R diff --git a/tests/develop-test/test.py b/tests/develop-test/test.py index 5dc6139410bf7d53da8e8fd36e047bb81a7e5eae..062e48b94b013d370f8be1dd785fdee35c74aef0 100644 --- a/tests/develop-test/test.py +++ b/tests/develop-test/test.py @@ -24,6 +24,7 @@ import socket import threading import toml + sys.path.append("../pytest") from util.log import * from util.dnodes import * @@ -34,14 +35,16 @@ from util.taosadapter import * import taos import taosrest + def checkRunTimeError(): import win32gui + timeCount = 0 while 1: time.sleep(1) timeCount = timeCount + 1 - print("checkRunTimeError",timeCount) - if (timeCount>600): + print("checkRunTimeError", timeCount) + if timeCount > 600: print("stop the test.") os.system("TASKKILL /F /IM taosd.exe") os.system("TASKKILL /F /IM taos.exe") @@ -53,6 +56,7 @@ def checkRunTimeError(): if hwnd: os.system("TASKKILL /F /IM taosd.exe") + if __name__ == "__main__": fileName = "all" @@ -72,102 +76,127 @@ if __name__ == "__main__": queryPolicy = 1 createDnodeNums = 1 restful = False - opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghrd:k:e:N:M:Q:C:RD:', [ - 'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help', 'restart', 'updateCfgDict', 'killv', 'execCmd','dnodeNums','mnodeNums','queryPolicy','createDnodeNums','restful','adaptercfgupdate']) + replicaVar = 1 + opts, args = getopt.gnu_getopt( + sys.argv[1:], + "f:p:m:l:scghrd:k:e:N:M:Q:C:RD:n:", + [ + "file=", + "path=", + "master", + "logSql", + "stop", + "cluster", + "valgrind", + "help", + "restart", + "updateCfgDict", + "killv", + "execCmd", + "dnodeNums", + "mnodeNums", + "queryPolicy", + "createDnodeNums", + "restful", + "adaptercfgupdate", + "replicaVar", + ], + ) for key, value in opts: - if key in ['-h', '--help']: - tdLog.printNoPrefix( - 'A collection of test cases written using Python') - tdLog.printNoPrefix('-f Name of test case file written by Python') - tdLog.printNoPrefix('-p Deploy Path for Simulator') - tdLog.printNoPrefix('-m Master Ip for Simulator') - tdLog.printNoPrefix('-l logSql Flag') - tdLog.printNoPrefix('-s stop All dnodes') - tdLog.printNoPrefix('-c Test Cluster Flag') - tdLog.printNoPrefix('-g valgrind Test Flag') - tdLog.printNoPrefix('-r taosd restart test') - tdLog.printNoPrefix('-d update cfg dict, base64 json str') - tdLog.printNoPrefix('-k not kill valgrind processer') - tdLog.printNoPrefix('-e eval str to run') - tdLog.printNoPrefix('-N start dnodes numbers in clusters') - tdLog.printNoPrefix('-M create mnode numbers in clusters') - tdLog.printNoPrefix('-Q set queryPolicy in one dnode') - tdLog.printNoPrefix('-C create Dnode Numbers in one cluster') - tdLog.printNoPrefix('-R restful realization form') - tdLog.printNoPrefix('-D taosadapter update cfg dict ') - - + if key in ["-h", "--help"]: + tdLog.printNoPrefix("A collection of test cases written using Python") + tdLog.printNoPrefix("-f Name of test case file written by Python") + tdLog.printNoPrefix("-p Deploy Path for Simulator") + tdLog.printNoPrefix("-m Master Ip for Simulator") + tdLog.printNoPrefix("-l logSql Flag") + tdLog.printNoPrefix("-s stop All dnodes") + tdLog.printNoPrefix("-c Test Cluster Flag") + tdLog.printNoPrefix("-g valgrind Test Flag") + tdLog.printNoPrefix("-r taosd restart test") + tdLog.printNoPrefix("-d update cfg dict, base64 json str") + tdLog.printNoPrefix("-k not kill valgrind processer") + tdLog.printNoPrefix("-e eval str to run") + tdLog.printNoPrefix("-N start dnodes numbers in clusters") + tdLog.printNoPrefix("-M create mnode numbers in clusters") + tdLog.printNoPrefix("-Q set queryPolicy in one dnode") + tdLog.printNoPrefix("-C create Dnode Numbers in one cluster") + tdLog.printNoPrefix("-R restful realization form") + tdLog.printNoPrefix("-D taosadapter update cfg dict ") + tdLog.printNoPrefix("-n the number of replicas") sys.exit(0) - if key in ['-r', '--restart']: + if key in ["-r", "--restart"]: restart = True - if key in ['-f', '--file']: + if key in ["-f", "--file"]: fileName = value - if key in ['-p', '--path']: + if key in ["-p", "--path"]: deployPath = value - if key in ['-m', '--master']: + if key in ["-m", "--master"]: masterIp = value - if key in ['-l', '--logSql']: - if (value.upper() == "TRUE"): + if key in ["-l", "--logSql"]: + if value.upper() == "TRUE": logSql = True - elif (value.upper() == "FALSE"): + elif value.upper() == "FALSE": logSql = False else: tdLog.printNoPrefix("logSql value %s is invalid" % logSql) sys.exit(0) - if key in ['-c', '--cluster']: + if key in ["-c", "--cluster"]: testCluster = True - if key in ['-g', '--valgrind']: + if key in ["-g", "--valgrind"]: valgrind = 1 - if key in ['-s', '--stop']: + if key in ["-s", "--stop"]: stop = 1 - if key in ['-d', '--updateCfgDict']: + if key in ["-d", "--updateCfgDict"]: try: updateCfgDict = eval(base64.b64decode(value.encode()).decode()) except: - print('updateCfgDict convert fail.') + print("updateCfgDict convert fail.") sys.exit(0) - if key in ['-k', '--killValgrind']: + if key in ["-k", "--killValgrind"]: killValgrind = 0 - if key in ['-e', '--execCmd']: + if key in ["-e", "--execCmd"]: try: execCmd = base64.b64decode(value.encode()).decode() except: - print('execCmd run fail.') + print("execCmd run fail.") sys.exit(0) - if key in ['-N', '--dnodeNums']: + if key in ["-N", "--dnodeNums"]: dnodeNums = value - if key in ['-M', '--mnodeNums']: + if key in ["-M", "--mnodeNums"]: mnodeNums = value - if key in ['-Q', '--queryPolicy']: + if key in ["-Q", "--queryPolicy"]: queryPolicy = value - if key in ['-C', '--createDnodeNums']: + if key in ["-C", "--createDnodeNums"]: createDnodeNums = value - if key in ['-R', '--restful']: + if key in ["-R", "--restful"]: restful = True - if key in ['-D', '--adaptercfgupdate']: + if key in ["-D", "--adaptercfgupdate"]: try: adaptercfgupdate = eval(base64.b64decode(value.encode()).decode()) except: - print('adapter cfg update convert fail.') + print("adapter cfg update convert fail.") sys.exit(0) + if key in ["-n", "--replicaVar"]: + replicaVar = value + if not execCmd == "": if restful: tAdapter.init(deployPath) @@ -177,24 +206,27 @@ if __name__ == "__main__": exec(execCmd) quit() - if (stop != 0): - if (valgrind == 0): + if stop != 0: + if valgrind == 0: toBeKilled = "taosd" else: toBeKilled = "valgrind.bin" - killCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -TERM > /dev/null 2>&1" % toBeKilled + killCmd = ( + "ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -TERM > /dev/null 2>&1" + % toBeKilled + ) psCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % toBeKilled processID = subprocess.check_output(psCmd, shell=True) - while(processID): + while processID: os.system(killCmd) time.sleep(1) processID = subprocess.check_output(psCmd, shell=True) for port in range(6030, 6041): - usePortPID = "lsof -i tcp:%d | grep LISTEn | awk '{print $2}'" % port + usePortPID = "lsof -i tcp:%d | grep LISTEN | awk '{print $2}'" % port processID = subprocess.check_output(usePortPID, shell=True) if processID: @@ -206,31 +238,33 @@ if __name__ == "__main__": time.sleep(2) if restful: - toBeKilled = "taosadapter" + toBeKilled = "taosadapt" - killCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -TERM > /dev/null 2>&1" % toBeKilled + # killCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -TERM > /dev/null 2>&1" % toBeKilled + killCmd = f"pkill {toBeKilled}" psCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % toBeKilled + # psCmd = f"pgrep {toBeKilled}" processID = subprocess.check_output(psCmd, shell=True) - while(processID): + while processID: os.system(killCmd) time.sleep(1) processID = subprocess.check_output(psCmd, shell=True) - for port in range(6030, 6041): - usePortPID = "lsof -i tcp:%d | grep LISTEn | awk '{print $2}'" % port - processID = subprocess.check_output(usePortPID, shell=True) + port = 6041 + usePortPID = f"lsof -i tcp:{port} | grep LISTEN | awk '{{print $2}}'" + processID = subprocess.check_output(usePortPID, shell=True) - if processID: - killCmd = "kill -TERM %s" % processID - os.system(killCmd) - fuserCmd = "fuser -k -n tcp %d" % port - os.system(fuserCmd) + if processID: + killCmd = f"kill -TERM {processID}" + os.system(killCmd) + fuserCmd = f"fuser -k -n tcp {port}" + os.system(fuserCmd) - tdLog.info('stop taosadapter') + tdLog.info("stop taosadapter") - tdLog.info('stop All dnodes') + tdLog.info("stop All dnodes") if masterIp == "": host = socket.gethostname() @@ -242,33 +276,40 @@ if __name__ == "__main__": host = masterIp tdLog.info("Procedures for tdengine deployed in %s" % (host)) - if platform.system().lower() == 'windows': + if platform.system().lower() == "windows": fileName = fileName.replace("/", os.sep) - if (masterIp == "" and not fileName == "0-others\\udf_create.py"): - threading.Thread(target=checkRunTimeError,daemon=True).start() + if masterIp == "" and not fileName == "0-others\\udf_create.py": + threading.Thread(target=checkRunTimeError, daemon=True).start() tdLog.info("Procedures for testing self-deployment") tdDnodes.init(deployPath, masterIp) tdDnodes.setTestCluster(testCluster) tdDnodes.setValgrind(valgrind) tdDnodes.stopAll() - key_word = 'tdCases.addWindows' + key_word = "tdCases.addWindows" is_test_framework = 0 try: - if key_word in open(fileName, encoding='UTF-8').read(): + if key_word in open(fileName, encoding="UTF-8").read(): is_test_framework = 1 except Exception as r: print(r) - updateCfgDictStr = '' + updateCfgDictStr = "" # adapter_cfg_dict_str = '' if is_test_framework: moduleName = fileName.replace(".py", "").replace(os.sep, ".") uModule = importlib.import_module(moduleName) try: ucase = uModule.TDTestCase() - if ((json.dumps(updateCfgDict) == '{}') and hasattr(ucase, 'updatecfgDict')): + if (json.dumps(updateCfgDict) == "{}") and hasattr( + ucase, "updatecfgDict" + ): updateCfgDict = ucase.updatecfgDict - updateCfgDictStr = "-d %s"%base64.b64encode(json.dumps(updateCfgDict).encode()).decode() - if ((json.dumps(adapter_cfg_dict) == '{}') and hasattr(ucase, 'taosadapter_cfg_dict')): + updateCfgDictStr = ( + "-d %s" + % base64.b64encode(json.dumps(updateCfgDict).encode()).decode() + ) + if (json.dumps(adapter_cfg_dict) == "{}") and hasattr( + ucase, "taosadapter_cfg_dict" + ): adapter_cfg_dict = ucase.taosadapter_cfg_dict # adapter_cfg_dict_str = f"-D {base64.b64encode(toml.dumps(adapter_cfg_dict).encode()).decode()}" except Exception as r: @@ -279,8 +320,8 @@ if __name__ == "__main__": tAdapter.init(deployPath, masterIp) tAdapter.stop(force_kill=True) - if dnodeNums == 1 : - tdDnodes.deploy(1,updateCfgDict) + if dnodeNums == 1: + tdDnodes.deploy(1, updateCfgDict) tdDnodes.start(1) tdCases.logSql(logSql) if restful: @@ -288,11 +329,11 @@ if __name__ == "__main__": tAdapter.start() if queryPolicy != 1: - queryPolicy=int(queryPolicy) + queryPolicy = int(queryPolicy) if restful: conn = taosrest.connect(url=f"http://{host}:6041") else: - conn = taos.connect(host,config=tdDnodes.getSimCfgPath()) + conn = taos.connect(host, config=tdDnodes.getSimCfgPath()) cursor = conn.cursor() cursor.execute("create qnode on dnode 1") @@ -300,22 +341,29 @@ if __name__ == "__main__": cursor.execute("show local variables") res = cursor.fetchall() for i in range(cursor.rowcount): - if res[i][0] == "queryPolicy" : + if res[i][0] == "queryPolicy": if int(res[i][1]) == int(queryPolicy): - tdLog.success(f'alter queryPolicy to {queryPolicy} successfully') + tdLog.success( + f"alter queryPolicy to {queryPolicy} successfully" + ) else: tdLog.debug(res) tdLog.exit(f"alter queryPolicy to {queryPolicy} failed") - else : - tdLog.debug("create an cluster with %s nodes and make %s dnode as independent mnode"%(dnodeNums,mnodeNums)) - dnodeslist = cluster.configure_cluster(dnodeNums=dnodeNums,mnodeNums=mnodeNums) + else: + tdLog.debug( + "create an cluster with %s nodes and make %s dnode as independent mnode" + % (dnodeNums, mnodeNums) + ) + dnodeslist = cluster.configure_cluster( + dnodeNums=dnodeNums, mnodeNums=mnodeNums + ) tdDnodes = ClusterDnodes(dnodeslist) tdDnodes.init(deployPath, masterIp) tdDnodes.setTestCluster(testCluster) tdDnodes.setValgrind(valgrind) tdDnodes.stopAll() for dnode in tdDnodes.dnodes: - tdDnodes.deploy(dnode.index,{}) + tdDnodes.deploy(dnode.index, {}) for dnode in tdDnodes.dnodes: tdDnodes.starttaosd(dnode.index) tdCases.logSql(logSql) @@ -325,25 +373,47 @@ if __name__ == "__main__": tAdapter.start() if not restful: - conn = taos.connect(host,config=tdDnodes.getSimCfgPath()) + conn = taos.connect(host, config=tdDnodes.getSimCfgPath()) else: conn = taosrest.connect(url=f"http://{host}:6041") # tdLog.info(tdDnodes.getSimCfgPath(),host) if createDnodeNums == 1: - createDnodeNums=dnodeNums + createDnodeNums = dnodeNums else: - createDnodeNums=createDnodeNums - cluster.create_dnode(conn,createDnodeNums) + createDnodeNums = createDnodeNums + cluster.create_dnode(conn, createDnodeNums) try: - if cluster.check_dnode(conn) : + if cluster.check_dnode(conn): print("check dnode ready") except Exception as r: print(r) - if ucase is not None and hasattr(ucase, 'noConn') and ucase.noConn == True: + if queryPolicy != 1: + queryPolicy = int(queryPolicy) + if restful: + conn = taosrest.connect(url=f"http://{host}:6041") + else: + conn = taos.connect(host, config=tdDnodes.getSimCfgPath()) + + cursor = conn.cursor() + cursor.execute("create qnode on dnode 1") + cursor.execute(f'alter local "queryPolicy" "{queryPolicy}"') + cursor.execute("show local variables") + res = cursor.fetchall() + for i in range(cursor.rowcount): + if res[i][0] == "queryPolicy": + if int(res[i][1]) == int(queryPolicy): + tdLog.success( + f"alter queryPolicy to {queryPolicy} successfully" + ) + else: + tdLog.debug(res) + tdLog.exit(f"alter queryPolicy to {queryPolicy} failed") + + if ucase is not None and hasattr(ucase, "noConn") and ucase.noConn == True: conn = None else: if not restful: - conn = taos.connect(host="%s"%(host), config=tdDnodes.sim.getCfgDir()) + conn = taos.connect(host="%s" % (host), config=tdDnodes.sim.getCfgDir()) else: conn = taosrest.connect(url=f"http://{host}:6041") if is_test_framework: @@ -357,7 +427,7 @@ if __name__ == "__main__": tdDnodes.setValgrind(valgrind) tdDnodes.stopAll() is_test_framework = 0 - key_word = 'tdCases.addLinux' + key_word = "tdCases.addLinux" try: if key_word in open(fileName).read(): is_test_framework = 1 @@ -368,9 +438,9 @@ if __name__ == "__main__": uModule = importlib.import_module(moduleName) try: ucase = uModule.TDTestCase() - if (json.dumps(updateCfgDict) == '{}'): + if json.dumps(updateCfgDict) == "{}": updateCfgDict = ucase.updatecfgDict - if (json.dumps(adapter_cfg_dict) == '{}'): + if json.dumps(adapter_cfg_dict) == "{}": adapter_cfg_dict = ucase.taosadapter_cfg_dict except: pass @@ -379,8 +449,8 @@ if __name__ == "__main__": tAdapter.init(deployPath, masterIp) tAdapter.stop(force_kill=True) - if dnodeNums == 1 : - tdDnodes.deploy(1,updateCfgDict) + if dnodeNums == 1: + tdDnodes.deploy(1, updateCfgDict) tdDnodes.start(1) tdCases.logSql(logSql) @@ -389,9 +459,9 @@ if __name__ == "__main__": tAdapter.start() if queryPolicy != 1: - queryPolicy=int(queryPolicy) + queryPolicy = int(queryPolicy) if not restful: - conn = taos.connect(host,config=tdDnodes.getSimCfgPath()) + conn = taos.connect(host, config=tdDnodes.getSimCfgPath()) else: conn = taosrest.connect(url=f"http://{host}:6041") # tdSql.init(conn.cursor()) @@ -412,23 +482,30 @@ if __name__ == "__main__": cursor.execute("show local variables") res = cursor.fetchall() for i in range(cursor.rowcount): - if res[i][0] == "queryPolicy" : + if res[i][0] == "queryPolicy": if int(res[i][1]) == int(queryPolicy): - tdLog.success(f'alter queryPolicy to {queryPolicy} successfully') + tdLog.success( + f"alter queryPolicy to {queryPolicy} successfully" + ) else: tdLog.debug(res) tdLog.exit(f"alter queryPolicy to {queryPolicy} failed") - else : - tdLog.debug("create an cluster with %s nodes and make %s dnode as independent mnode"%(dnodeNums,mnodeNums)) - dnodeslist = cluster.configure_cluster(dnodeNums=dnodeNums,mnodeNums=mnodeNums) + else: + tdLog.debug( + "create an cluster with %s nodes and make %s dnode as independent mnode" + % (dnodeNums, mnodeNums) + ) + dnodeslist = cluster.configure_cluster( + dnodeNums=dnodeNums, mnodeNums=mnodeNums + ) tdDnodes = ClusterDnodes(dnodeslist) tdDnodes.init(deployPath, masterIp) tdDnodes.setTestCluster(testCluster) tdDnodes.setValgrind(valgrind) tdDnodes.stopAll() for dnode in tdDnodes.dnodes: - tdDnodes.deploy(dnode.index,{}) + tdDnodes.deploy(dnode.index, {}) for dnode in tdDnodes.dnodes: tdDnodes.starttaosd(dnode.index) tdCases.logSql(logSql) @@ -438,21 +515,42 @@ if __name__ == "__main__": tAdapter.start() if not restful: - conn = taos.connect(host,config=tdDnodes.getSimCfgPath()) + conn = taos.connect(host, config=tdDnodes.getSimCfgPath()) else: conn = taosrest.connect(url=f"http://{host}:6041") - print(tdDnodes.getSimCfgPath(),host) + print(tdDnodes.getSimCfgPath(), host) if createDnodeNums == 1: - createDnodeNums=dnodeNums + createDnodeNums = dnodeNums else: - createDnodeNums=createDnodeNums - cluster.create_dnode(conn,createDnodeNums) + createDnodeNums = createDnodeNums + cluster.create_dnode(conn, createDnodeNums) try: - if cluster.check_dnode(conn) : + if cluster.check_dnode(conn): print("check dnode ready") except Exception as r: print(r) + if queryPolicy != 1: + queryPolicy = int(queryPolicy) + if restful: + conn = taosrest.connect(url=f"http://{host}:6041") + else: + conn = taos.connect(host, config=tdDnodes.getSimCfgPath()) + + cursor = conn.cursor() + cursor.execute("create qnode on dnode 1") + cursor.execute(f'alter local "queryPolicy" "{queryPolicy}"') + cursor.execute("show local variables") + res = cursor.fetchall() + for i in range(cursor.rowcount): + if res[i][0] == "queryPolicy": + if int(res[i][1]) == int(queryPolicy): + tdLog.success( + f"alter queryPolicy to {queryPolicy} successfully" + ) + else: + tdLog.debug(res) + tdLog.exit(f"alter queryPolicy to {queryPolicy} failed") if testCluster: tdLog.info("Procedures for testing cluster") @@ -463,14 +561,14 @@ if __name__ == "__main__": else: tdLog.info("Procedures for testing self-deployment") if not restful: - conn = taos.connect(host,config=tdDnodes.getSimCfgPath()) + conn = taos.connect(host, config=tdDnodes.getSimCfgPath()) else: conn = taosrest.connect(url=f"http://{host}:6041") if fileName == "all": tdCases.runAllLinux(conn) else: - tdCases.runOneLinux(conn, fileName) + tdCases.runOneLinux(conn, fileName, replicaVar) if restart: if fileName == "all": @@ -482,12 +580,12 @@ if __name__ == "__main__": tdDnodes.start(1) time.sleep(1) if not restful: - conn = taos.connect( host, config=tdDnodes.getSimCfgPath()) + conn = taos.connect(host, config=tdDnodes.getSimCfgPath()) else: conn = taosrest.connect(url=f"http://{host}:6041") tdLog.info("Procedures for tdengine deployed in %s" % (host)) tdLog.info("query test after taosd restart") - tdCases.runOneLinux(conn, sp[0] + "_" + "restart.py") + tdCases.runOneLinux(conn, sp[0] + "_" + "restart.py", replicaVar) else: tdLog.info("not need to query") diff --git a/tests/docs-examples-test/csharp.sh b/tests/docs-examples-test/csharp.sh index 8d1031ab8f8367e260804a58ecc2ae4f9822550c..21c19b9b3d7dae0680381b112e84f44a2023f5dd 100644 --- a/tests/docs-examples-test/csharp.sh +++ b/tests/docs-examples-test/csharp.sh @@ -27,11 +27,11 @@ dotnet run --project optsTelnet/optstelnet.csproj taos -s "drop database if exists test" dotnet run --project optsJSON/optsJSON.csproj -taos -s "create database if exists test" -dotnet run --project wsConnect/wsConnect.csproj -dotnet run --project wsInsert/wsInsert.csproj -dotnet run --project wsStmt/wsStmt.csproj -dotnet run --project wsQuery/wsQuery.csproj +taos -s "create database if not exists test" +# dotnet run --project wsConnect/wsConnect.csproj +# dotnet run --project wsInsert/wsInsert.csproj +# dotnet run --project wsStmt/wsStmt.csproj +# dotnet run --project wsQuery/wsQuery.csproj taos -s "drop database if exists test" taos -s "drop database if exists power" \ No newline at end of file diff --git a/tests/parallel_test/container_build.sh b/tests/parallel_test/container_build.sh index deaea4fa4078b5ec480b711d1ac5865bb2e67dac..52864d668fc865d8f5e0b8bef589c0d01eaa0252 100755 --- a/tests/parallel_test/container_build.sh +++ b/tests/parallel_test/container_build.sh @@ -52,7 +52,7 @@ fi docker run \ -v $REP_MOUNT_PARAM \ - --rm --ulimit core=-1 taos_test:v1.0 sh -c "cd $REP_DIR;rm -rf debug;mkdir -p debug;cd debug;cmake .. -DBUILD_HTTP=false -DBUILD_TOOLS=true -DWEBSOCKET=true;make -j $THREAD_COUNT" + --rm --ulimit core=-1 taos_test:v1.0 sh -c "cd $REP_DIR;rm -rf debug;mkdir -p debug;cd debug;cmake .. -DBUILD_HTTP=false -DBUILD_TOOLS=true -DBUILD_TEST=true -DWEBSOCKET=true;make -j $THREAD_COUNT" ret=$? exit $ret diff --git a/tests/pytest/concurrent_inquiry.py b/tests/pytest/concurrent_inquiry.py index 1bb2081d7f936ccd6df0e6c85d3d451d9c0d9e44..0d281674f557b12fcffce12f11c8a7200e3ca4dd 100644 --- a/tests/pytest/concurrent_inquiry.py +++ b/tests/pytest/concurrent_inquiry.py @@ -21,43 +21,52 @@ import argparse import datetime import string from requests.auth import HTTPBasicAuth -func_list=['avg','count','twa','sum','stddev','leastsquares','min', -'max','first','last','top','bottom','percentile','apercentile', -'last_row','diff','spread','distinct'] -condition_list=[ + +func_list = ['abs', 'acos', 'asin', 'atan', 'ceil', 'cos', 'floor', 'log', 'pow', 'round', 'sin', 'sqrt', 'tan', + 'char_length', 'concat', 'concat_ws', 'length', 'lower', 'ltrim', 'rtrim', 'substr', 'upper', + 'cast', 'to_iso8601', 'to_json', 'to_unixtimestamp', 'now', 'timediff', 'timetruncate', 'timezone', 'today', + 'apercentile', 'avg', 'count', 'elapsed', 'leastsquares', 'spread', 'stddev', 'sum', 'hyperloglog', 'histogram', 'percentile', + 'bottom', 'first', 'interp', 'last', 'last_row', 'max', 'min', 'mode', 'sample', 'tail', 'top', 'unique', + 'csum', 'derivative', 'diff', 'irate', 'mavg', 'statecount', 'stateduration', 'twa', + 'database', 'client_version', 'server_version', 'server_status'] + +condition_list = [ "where _c0 > now -10d ", 'interval(10s)', 'limit 10', 'group by', + 'partition by', 'order by', 'fill(null)' - ] -where_list = ['_c0>now-10d',' <50','like',' is null','in'] + +where_list = ['_c0>now-10d', ' <50', 'like', ' is null', 'in'] + + class ConcurrentInquiry: # def __init__(self,ts=1500000001000,host='127.0.0.1',user='root',password='taosdata',dbname='test', # stb_prefix='st',subtb_prefix='t',n_Therads=10,r_Therads=10,probabilities=0.05,loop=5, - # stableNum = 2,subtableNum = 1000,insertRows = 100): - def __init__(self,ts,host,user,password,dbname, - stb_prefix,subtb_prefix,n_Therads,r_Therads,probabilities,loop, - stableNum ,subtableNum ,insertRows ,mix_table, replay): + # stableNum = 2,subtableNum = 1000,insertRows = 100): + def __init__(self, ts, host, user, password, dbname, + stb_prefix, subtb_prefix, n_Therads, r_Therads, probabilities, loop, + stableNum, subtableNum, insertRows, mix_table, replay): self.n_numOfTherads = n_Therads self.r_numOfTherads = r_Therads - self.ts=ts + self.ts = ts self.host = host self.user = user self.password = password - self.dbname=dbname + self.dbname = dbname self.stb_prefix = stb_prefix self.subtb_prefix = subtb_prefix - self.stb_list=[] - self.subtb_list=[] - self.stb_stru_list=[] - self.subtb_stru_list=[] - self.stb_tag_list=[] - self.subtb_tag_list=[] - self.probabilities = [1-probabilities,probabilities] - self.ifjoin = [1,0] + self.stb_list = [] + self.subtb_list = [] + self.stb_stru_list = [] + self.subtb_stru_list = [] + self.stb_tag_list = [] + self.subtb_tag_list = [] + self.probabilities = [1-probabilities, probabilities] + self.ifjoin = [1, 0] self.loop = loop self.stableNum = stableNum self.subtableNum = subtableNum @@ -66,253 +75,276 @@ class ConcurrentInquiry: self.max_ts = datetime.datetime.now() self.min_ts = datetime.datetime.now() - datetime.timedelta(days=5) self.replay = replay - def SetThreadsNum(self,num): - self.numOfTherads=num - def ret_fcol(self,cl,sql): #返回结果的第一列 + def SetThreadsNum(self, num): + self.numOfTherads = num + + def ret_fcol(self, cl, sql): # 返回结果的第一列 cl.execute(sql) - fcol_list=[] + fcol_list = [] for data in cl: fcol_list.append(data[0]) return fcol_list - def r_stb_list(self,cl): #返回超级表列表 - sql='show '+self.dbname+'.stables' - self.stb_list=self.ret_fcol(cl,sql) + def r_stb_list(self, cl): # 返回超级表列表 + sql = 'show '+self.dbname+'.stables' + self.stb_list = self.ret_fcol(cl, sql) - def r_subtb_list(self,cl,stablename): #每个超级表返回2个子表 - sql='select tbname from '+self.dbname+'.'+stablename+' limit 2;' - self.subtb_list+=self.ret_fcol(cl,sql) + def r_subtb_list(self, cl, stablename): # 每个超级表返回2个子表 + sql = 'select tbname from '+self.dbname+'.'+stablename+' limit 2;' + self.subtb_list += self.ret_fcol(cl, sql) - def cal_struct(self,cl,tbname): #查看表结构 - tb=[] - tag=[] - sql='describe '+self.dbname+'.'+tbname+';' + def cal_struct(self, cl, tbname): # 查看表结构 + tb = [] + tag = [] + sql = 'describe '+self.dbname+'.'+tbname+';' cl.execute(sql) for data in cl: if data[3]: tag.append(data[0]) else: tb.append(data[0]) - return tb,tag + return tb, tag - def r_stb_stru(self,cl): #获取所有超级表的表结构 + def r_stb_stru(self, cl): # 获取所有超级表的表结构 for i in self.stb_list: - tb,tag=self.cal_struct(cl,i) + tb, tag = self.cal_struct(cl, i) self.stb_stru_list.append(tb) self.stb_tag_list.append(tag) - def r_subtb_stru(self,cl): #返回所有子表的表结构 + def r_subtb_stru(self, cl): # 返回所有子表的表结构 for i in self.subtb_list: - tb,tag=self.cal_struct(cl,i) + tb, tag = self.cal_struct(cl, i) self.subtb_stru_list.append(tb) self.subtb_tag_list.append(tag) - def get_timespan(self,cl): #获取时间跨度(仅第一个超级表) - sql = 'select first(_c0),last(_c0) from ' + self.dbname + '.' + self.stb_list[0] + ';' + def get_timespan(self, cl): # 获取时间跨度(仅第一个超级表) + sql = 'select first(_c0),last(_c0) from ' + \ + self.dbname + '.' + self.stb_list[0] + ';' print(sql) cl.execute(sql) for data in cl: self.max_ts = data[1] self.min_ts = data[0] - def get_full(self): #获取所有的表、表结构 + def get_full(self): # 获取所有的表、表结构 host = self.host user = self.user password = self.password conn = taos.connect( - host, - user, - password, - ) + host='%s' % host, + user='%s' % user, + password='%s' % password, + ) cl = conn.cursor() self.r_stb_list(cl) for i in self.stb_list: - self.r_subtb_list(cl,i) + self.r_subtb_list(cl, i) self.r_stb_stru(cl) self.r_subtb_stru(cl) self.get_timespan(cl) cl.close() - conn.close() - - #query condition - def con_where(self,tlist,col_list,tag_list): - l=[] - for i in range(random.randint(0,len(tlist))): + conn.close() + + # query condition + def con_where(self, tlist, col_list, tag_list): + l = [] + for i in range(random.randint(0, len(tlist))): c = random.choice(where_list) if c == '_c0>now-10d': - rdate = self.min_ts + (self.max_ts - self.min_ts)/10 * random.randint(-11,11) - conlist = ' _c0 ' + random.choice(['<','>','>=','<=','<>']) + "'" + str(rdate) + "'" + rdate = self.min_ts + \ + (self.max_ts - self.min_ts)/10 * random.randint(-11, 11) + conlist = ' _c0 ' + \ + random.choice(['<', '>', '>=', '<=', '<>'] + ) + "'" + str(rdate) + "'" if self.random_pick(): l.append(conlist) - else: l.append(c) + else: + l.append(c) elif '<50' in c: - conlist = ' ' + random.choice(tlist) + random.choice(['<','>','>=','<=','<>']) + str(random.randrange(-100,100)) - l.append(conlist) + conlist = ' ' + random.choice(tlist) + random.choice( + ['<', '>', '>=', '<=', '<>']) + str(random.randrange(-100, 100)) + l.append(conlist) elif 'is null' in c: - conlist = ' ' + random.choice(tlist) + random.choice([' is null',' is not null']) - l.append(conlist) + conlist = ' ' + \ + random.choice(tlist) + \ + random.choice([' is null', ' is not null']) + l.append(conlist) elif 'in' in c: in_list = [] temp = [] - for i in range(random.randint(0,100)): - temp.append(random.randint(-10000,10000)) + for i in range(random.randint(0, 100)): + temp.append(random.randint(-10000, 10000)) temp = (str(i) for i in temp) in_list.append(temp) temp1 = [] - for i in range(random.randint(0,100)): - temp1.append("'" + ''.join(random.sample(string.ascii_letters, random.randint(0,10))) + "'") - in_list.append(temp1) - in_list.append(['NULL','NULL']) - conlist = ' ' + random.choice(tlist) + ' in (' + ','.join(random.choice(in_list)) + ')' + for i in range(random.randint(0, 100)): + temp1.append( + "'" + ''.join(random.sample(string.ascii_letters, random.randint(0, 10))) + "'") + in_list.append(temp1) + in_list.append(['NULL', 'NULL']) + conlist = ' ' + \ + random.choice(tlist) + ' in (' + \ + ','.join(random.choice(in_list)) + ')' l.append(conlist) else: s_all = string.ascii_letters - conlist = ' ' + random.choice(tlist) + " like \'%" + random.choice(s_all) + "%\' " + conlist = ' ' + \ + random.choice(tlist) + " like \'%" + \ + random.choice(s_all) + "%\' " l.append(conlist) - return 'where '+random.choice([' and ',' or ']).join(l) + return 'where '+random.choice([' and ', ' or ']).join(l) - def con_interval(self,tlist,col_list,tag_list): - interval = 'interval(' + str(random.randint(0,20)) + random.choice(['a','s','d','w','n','y']) + ')' + def con_interval(self, tlist, col_list, tag_list): + interval = 'interval(' + str(random.randint(0, 20)) + \ + random.choice(['a', 's', 'd', 'w', 'n', 'y']) + ')' return interval - def con_limit(self,tlist,col_list,tag_list): - rand1 = str(random.randint(0,1000)) - rand2 = str(random.randint(0,1000)) - return random.choice(['limit ' + rand1,'limit ' + rand1 + ' offset '+rand2, - ' slimit ' + rand1,' slimit ' + rand1 + ' offset ' + rand2,'limit '+rand1 + ' slimit '+ rand2, - 'limit '+ rand1 + ' offset' + rand2 + ' slimit '+ rand1 + ' soffset ' + rand2 ]) - - def con_fill(self,tlist,col_list,tag_list): - return random.choice(['fill(null)','fill(prev)','fill(none)','fill(LINEAR)']) - - def con_group(self,tlist,col_list,tag_list): - rand_tag = random.randint(0,5) - rand_col = random.randint(0,1) + def con_limit(self, tlist, col_list, tag_list): + rand1 = str(random.randint(0, 1000)) + rand2 = str(random.randint(0, 1000)) + return random.choice(['limit ' + rand1, 'limit ' + rand1 + ' offset '+rand2, + ' slimit ' + rand1, ' slimit ' + rand1 + ' offset ' + + rand2, 'limit '+rand1 + ' slimit ' + rand2, + 'limit ' + rand1 + ' offset' + rand2 + ' slimit ' + rand1 + ' soffset ' + rand2]) + + def con_fill(self, tlist, col_list, tag_list): + return random.choice(['fill(null)', 'fill(prev)', 'fill(none)', 'fill(LINEAR)']) + + def con_group(self, tlist, col_list, tag_list): + rand_tag = random.randint(0, 5) + rand_col = random.randint(0, 1) if len(tag_list): - return 'group by '+','.join(random.sample(col_list,rand_col) + random.sample(tag_list,rand_tag)) + return 'group by '+','.join(random.sample(col_list, rand_col) + random.sample(tag_list, rand_tag)) else: - return 'group by '+','.join(random.sample(col_list,rand_col)) + return 'group by '+','.join(random.sample(col_list, rand_col)) - def con_order(self,tlist,col_list,tag_list): + def con_order(self, tlist, col_list, tag_list): return 'order by '+random.choice(tlist) - def con_state_window(self,tlist,col_list,tag_list): + def con_state_window(self, tlist, col_list, tag_list): return 'state_window(' + random.choice(tlist + tag_list) + ')' - def con_session_window(self,tlist,col_list,tag_list): - session_window = 'session_window(' + random.choice(tlist + tag_list) + ',' + str(random.randint(0,20)) + random.choice(['a','s','d','w','n','y']) + ')' + def con_session_window(self, tlist, col_list, tag_list): + session_window = 'session_window(' + random.choice(tlist + tag_list) + ',' + str( + random.randint(0, 20)) + random.choice(['a', 's', 'd', 'w', 'n', 'y']) + ')' return session_window def gen_subquery_sql(self): - subsql ,col_num = self.gen_query_sql(1) + subsql, col_num = self.gen_query_sql(1) if col_num == 0: return 0 - col_list=[] - tag_list=[] + col_list = [] + tag_list = [] for i in range(col_num): - col_list.append("taosd%d"%i) - - tlist=col_list+['abc'] #增加不存在的域'abc',是否会引起新bug - con_rand=random.randint(0,len(condition_list)) - func_rand=random.randint(0,len(func_list)) - col_rand=random.randint(0,len(col_list)) - t_rand=random.randint(0,len(tlist)) - sql='select ' #select + col_list.append("taosd%d" % i) + + tlist = col_list+['abc'] # 增加不存在的域'abc',是否会引起新bug + con_rand = random.randint(0, len(condition_list)) + func_rand = random.randint(0, len(func_list)) + col_rand = random.randint(0, len(col_list)) + t_rand = random.randint(0, len(tlist)) + sql = 'select ' # select random.shuffle(col_list) random.shuffle(func_list) - sel_col_list=[] - col_rand=random.randint(0,len(col_list)) + sel_col_list = [] + col_rand = random.randint(0, len(col_list)) loop = 0 - for i,j in zip(col_list[0:col_rand],func_list): #决定每个被查询col的函数 - alias = ' as '+ 'sub%d ' % loop + for i, j in zip(col_list[0:col_rand], func_list): # 决定每个被查询col的函数 + alias = ' as ' + 'sub%d ' % loop loop += 1 pick_func = '' if j == 'leastsquares': - pick_func=j+'('+i+',1,1)' + pick_func = j+'('+i+',1,1)' elif j == 'top' or j == 'bottom' or j == 'percentile' or j == 'apercentile': - pick_func=j+'('+i+',1)' + pick_func = j+'('+i+',1)' else: - pick_func=j+'('+i+')' - if bool(random.getrandbits(1)) : - pick_func+=alias + pick_func = j+'('+i+')' + if bool(random.getrandbits(1)): + pick_func += alias sel_col_list.append(pick_func) if col_rand == 0: - sql = sql + '*' - else: - sql=sql+','.join(sel_col_list) #select col & func - sql = sql + ' from ('+ subsql +') ' - con_func=[self.con_where,self.con_interval,self.con_limit,self.con_group,self.con_order,self.con_fill,self.con_state_window,self.con_session_window] - sel_con=random.sample(con_func,random.randint(0,len(con_func))) - sel_con_list=[] + sql = sql + '*' + else: + sql = sql+','.join(sel_col_list) # select col & func + sql = sql + ' from (' + subsql + ') ' + con_func = [self.con_where, self.con_interval, self.con_limit, self.con_group, + self.con_order, self.con_fill, self.con_state_window, self.con_session_window] + sel_con = random.sample(con_func, random.randint(0, len(con_func))) + sel_con_list = [] for i in sel_con: - sel_con_list.append(i(tlist,col_list,tag_list)) #获取对应的条件函数 - sql+=' '.join(sel_con_list) # condition - #print(sql) + sel_con_list.append(i(tlist, col_list, tag_list)) # 获取对应的条件函数 + # condition + sql += ' '.join(sel_con_list) + # print(sql) return sql - - def gen_query_sql(self,subquery=0): #生成查询语句 - tbi=random.randint(0,len(self.subtb_list)+len(self.stb_list)) #随机决定查询哪张表 - tbname='' - col_list=[] - tag_list=[] - is_stb=0 - if tbi>len(self.stb_list) : - tbi=tbi-len(self.stb_list) - tbname=self.subtb_list[tbi-1] - col_list=self.subtb_stru_list[tbi-1] - tag_list=self.subtb_tag_list[tbi-1] + + def gen_query_sql(self, subquery=0): # 生成查询语句 + tbi = random.randint(0, len(self.subtb_list) + + len(self.stb_list)) # 随机决定查询哪张表 + tbname = '' + col_list = [] + tag_list = [] + is_stb = 0 + if tbi > len(self.stb_list): + tbi = tbi-len(self.stb_list) + tbname = self.subtb_list[tbi-1] + col_list = self.subtb_stru_list[tbi-1] + tag_list = self.subtb_tag_list[tbi-1] else: - tbname=self.stb_list[tbi-1] - col_list=self.stb_stru_list[tbi-1] - tag_list=self.stb_tag_list[tbi-1] - is_stb=1 - tlist=col_list+tag_list+['abc'] #增加不存在的域'abc',是否会引起新bug - con_rand=random.randint(0,len(condition_list)) - func_rand=random.randint(0,len(func_list)) - col_rand=random.randint(0,len(col_list)) - tag_rand=random.randint(0,len(tag_list)) - t_rand=random.randint(0,len(tlist)) - sql='select ' #select + tbname = self.stb_list[tbi-1] + col_list = self.stb_stru_list[tbi-1] + tag_list = self.stb_tag_list[tbi-1] + is_stb = 1 + tlist = col_list+tag_list+['abc'] # 增加不存在的域'abc',是否会引起新bug + con_rand = random.randint(0, len(condition_list)) + func_rand = random.randint(0, len(func_list)) + col_rand = random.randint(0, len(col_list)) + tag_rand = random.randint(0, len(tag_list)) + t_rand = random.randint(0, len(tlist)) + sql = 'select ' # select random.shuffle(col_list) random.shuffle(func_list) - sel_col_list=[] - col_rand=random.randint(0,len(col_list)) + sel_col_list = [] + col_rand = random.randint(0, len(col_list)) loop = 0 - for i,j in zip(col_list[0:col_rand],func_list): #决定每个被查询col的函数 - alias = ' as '+ 'taos%d ' % loop + for i, j in zip(col_list[0:col_rand], func_list): # 决定每个被查询col的函数 + alias = ' as ' + 'taos%d ' % loop loop += 1 pick_func = '' if j == 'leastsquares': - pick_func=j+'('+i+',1,1)' + pick_func = j+'('+i+',1,1)' elif j == 'top' or j == 'bottom' or j == 'percentile' or j == 'apercentile': - pick_func=j+'('+i+',1)' + pick_func = j+'('+i+',1)' else: - pick_func=j+'('+i+')' - if bool(random.getrandbits(1)) | subquery : - pick_func+=alias + pick_func = j+'('+i+')' + if bool(random.getrandbits(1)) | subquery: + pick_func += alias sel_col_list.append(pick_func) - if col_rand == 0 & subquery : - sql = sql + '*' - else: - sql=sql+','.join(sel_col_list) #select col & func + if col_rand == 0 & subquery: + sql = sql + '*' + else: + sql = sql+','.join(sel_col_list) # select col & func if self.mix_table == 0: - sql = sql + ' from '+random.choice(self.stb_list+self.subtb_list)+' ' + sql = sql + ' from ' + \ + random.choice(self.stb_list+self.subtb_list)+' ' elif self.mix_table == 1: sql = sql + ' from '+random.choice(self.subtb_list)+' ' else: - sql = sql + ' from '+random.choice(self.stb_list)+' ' - con_func=[self.con_where,self.con_interval,self.con_limit,self.con_group,self.con_order,self.con_fill,self.con_state_window,self.con_session_window] - sel_con=random.sample(con_func,random.randint(0,len(con_func))) - sel_con_list=[] + sql = sql + ' from '+random.choice(self.stb_list)+' ' + con_func = [self.con_where, self.con_interval, self.con_limit, self.con_group, + self.con_order, self.con_fill, self.con_state_window, self.con_session_window] + sel_con = random.sample(con_func, random.randint(0, len(con_func))) + sel_con_list = [] for i in sel_con: - sel_con_list.append(i(tlist,col_list,tag_list)) #获取对应的条件函数 - sql+=' '.join(sel_con_list) # condition - #print(sql) - return (sql,loop) + sel_con_list.append(i(tlist, col_list, tag_list)) # 获取对应的条件函数 + # condition + sql += ' '.join(sel_con_list) + # print(sql) + return (sql, loop) - def gen_query_join(self): #生成join查询语句 - tbname = [] + def gen_query_join(self): # 生成join查询语句 + tbname = [] col_list = [] tag_list = [] col_intersection = [] @@ -321,88 +353,105 @@ class ConcurrentInquiry: if self.mix_table == 0: if bool(random.getrandbits(1)): subtable = True - tbname = random.sample(self.subtb_list,2) + tbname = random.sample(self.subtb_list, 2) for i in tbname: - col_list.append(self.subtb_stru_list[self.subtb_list.index(i)]) - tag_list.append(self.subtb_stru_list[self.subtb_list.index(i)]) - col_intersection = list(set(col_list[0]).intersection(set(col_list[1]))) - tag_intersection = list(set(tag_list[0]).intersection(set(tag_list[1]))) + col_list.append( + self.subtb_stru_list[self.subtb_list.index(i)]) + tag_list.append( + self.subtb_stru_list[self.subtb_list.index(i)]) + col_intersection = list( + set(col_list[0]).intersection(set(col_list[1]))) + tag_intersection = list( + set(tag_list[0]).intersection(set(tag_list[1]))) else: - tbname = random.sample(self.stb_list,2) + tbname = random.sample(self.stb_list, 2) for i in tbname: col_list.append(self.stb_stru_list[self.stb_list.index(i)]) tag_list.append(self.stb_stru_list[self.stb_list.index(i)]) - col_intersection = list(set(col_list[0]).intersection(set(col_list[1]))) - tag_intersection = list(set(tag_list[0]).intersection(set(tag_list[1]))) + col_intersection = list( + set(col_list[0]).intersection(set(col_list[1]))) + tag_intersection = list( + set(tag_list[0]).intersection(set(tag_list[1]))) elif self.mix_table == 1: subtable = True - tbname = random.sample(self.subtb_list,2) + tbname = random.sample(self.subtb_list, 2) for i in tbname: col_list.append(self.subtb_stru_list[self.subtb_list.index(i)]) tag_list.append(self.subtb_stru_list[self.subtb_list.index(i)]) - col_intersection = list(set(col_list[0]).intersection(set(col_list[1]))) - tag_intersection = list(set(tag_list[0]).intersection(set(tag_list[1]))) + col_intersection = list( + set(col_list[0]).intersection(set(col_list[1]))) + tag_intersection = list( + set(tag_list[0]).intersection(set(tag_list[1]))) else: - tbname = random.sample(self.stb_list,2) + tbname = random.sample(self.stb_list, 2) for i in tbname: col_list.append(self.stb_stru_list[self.stb_list.index(i)]) tag_list.append(self.stb_stru_list[self.stb_list.index(i)]) - col_intersection = list(set(col_list[0]).intersection(set(col_list[1]))) - tag_intersection = list(set(tag_list[0]).intersection(set(tag_list[1]))) - con_rand=random.randint(0,len(condition_list)) - col_rand=random.randint(0,len(col_list)) - tag_rand=random.randint(0,len(tag_list)) - sql='select ' #select - - sel_col_tag=[] - col_rand=random.randint(0,len(col_list)) + col_intersection = list( + set(col_list[0]).intersection(set(col_list[1]))) + tag_intersection = list( + set(tag_list[0]).intersection(set(tag_list[1]))) + con_rand = random.randint(0, len(condition_list)) + col_rand = random.randint(0, len(col_list)) + tag_rand = random.randint(0, len(tag_list)) + sql = 'select ' # select + + sel_col_tag = [] + col_rand = random.randint(0, len(col_list)) if bool(random.getrandbits(1)): sql += '*' else: - sel_col_tag.append('t1.' + str(random.choice(col_list[0] + tag_list[0]))) - sel_col_tag.append('t2.' + str(random.choice(col_list[1] + tag_list[1]))) + sel_col_tag.append( + 't1.' + str(random.choice(col_list[0] + tag_list[0]))) + sel_col_tag.append( + 't2.' + str(random.choice(col_list[1] + tag_list[1]))) sel_col_list = [] random.shuffle(func_list) if self.random_pick(): loop = 0 - for i,j in zip(sel_col_tag,func_list): #决定每个被查询col的函数 - alias = ' as '+ 'taos%d ' % loop + for i, j in zip(sel_col_tag, func_list): # 决定每个被查询col的函数 + alias = ' as ' + 'taos%d ' % loop loop += 1 pick_func = '' if j == 'leastsquares': - pick_func=j+'('+i+',1,1)' + pick_func = j+'('+i+',1,1)' elif j == 'top' or j == 'bottom' or j == 'percentile' or j == 'apercentile': - pick_func=j+'('+i+',1)' + pick_func = j+'('+i+',1)' else: - pick_func=j+'('+i+')' + pick_func = j+'('+i+')' if bool(random.getrandbits(1)): - pick_func+=alias + pick_func += alias sel_col_list.append(pick_func) sql += ','.join(sel_col_list) else: sql += ','.join(sel_col_tag) - sql = sql + ' from '+ str(tbname[0]) +' t1,' + str(tbname[1]) + ' t2 ' #select col & func + sql = sql + ' from ' + \ + str(tbname[0]) + ' t1,' + str(tbname[1]) + \ + ' t2 ' # select col & func join_section = None temp = None if subtable: temp = random.choices(col_intersection) join_section = temp.pop() - sql += 'where t1._c0 = t2._c0 and ' + 't1.' + str(join_section) + '=t2.' + str(join_section) + sql += 'where t1._c0 = t2._c0 and ' + 't1.' + \ + str(join_section) + '=t2.' + str(join_section) else: temp = random.choices(col_intersection+tag_intersection) join_section = temp.pop() - sql += 'where t1._c0 = t2._c0 and ' + 't1.' + str(join_section) + '=t2.' + str(join_section) + sql += 'where t1._c0 = t2._c0 and ' + 't1.' + \ + str(join_section) + '=t2.' + str(join_section) return sql - def random_pick(self): - x = random.uniform(0,1) - cumulative_probability = 0.0 - for item, item_probability in zip(self.ifjoin, self.probabilities): - cumulative_probability += item_probability - if x < cumulative_probability:break + def random_pick(self): + x = random.uniform(0, 1) + cumulative_probability = 0.0 + for item, item_probability in zip(self.ifjoin, self.probabilities): + cumulative_probability += item_probability + if x < cumulative_probability: + break return item - + def gen_data(self): stableNum = self.stableNum subtableNum = self.subtableNum @@ -412,52 +461,54 @@ class ConcurrentInquiry: user = self.user password = self.password conn = taos.connect( - host, - user, - password, - ) + host='%s' % host, + user='%s' % user, + password='%s' % password, + ) cl = conn.cursor() - cl.execute("drop database if exists %s;" %self.dbname) - cl.execute("create database if not exists %s;" %self.dbname) + cl.execute("drop database if exists %s;" % self.dbname) + cl.execute("create database if not exists %s;" % self.dbname) cl.execute("use %s" % self.dbname) for k in range(stableNum): - sql="create table %s (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool,c8 binary(20),c9 nchar(20),c11 int unsigned,c12 smallint unsigned,c13 tinyint unsigned,c14 bigint unsigned) \ + sql = "create table %s (ts timestamp, c1 int, c2 float, c3 bigint, c4 smallint, c5 tinyint, c6 double, c7 bool,c8 binary(20),c9 nchar(20),c11 int unsigned,c12 smallint unsigned,c13 tinyint unsigned,c14 bigint unsigned) \ tags(t1 int, t2 float, t3 bigint, t4 smallint, t5 tinyint, t6 double, t7 bool,t8 binary(20),t9 nchar(20), t11 int unsigned , t12 smallint unsigned , t13 tinyint unsigned , t14 bigint unsigned)" % (self.stb_prefix+str(k)) cl.execute(sql) for j in range(subtableNum): if j % 100 == 0: sql = "create table %s using %s tags(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)" % \ - (self.subtb_prefix+str(k)+'_'+str(j),self.stb_prefix+str(k)) + (self.subtb_prefix+str(k)+'_' + + str(j), self.stb_prefix+str(k)) else: sql = "create table %s using %s tags(%d,%d,%d,%d,%d,%d,%d,'%s','%s',%d,%d,%d,%d)" % \ - (self.subtb_prefix+str(k)+'_'+str(j),self.stb_prefix+str(k),j,j/2.0,j%41,j%51,j%53,j*1.0,j%2,'taos'+str(j),'涛思'+str(j), j%43, j%23 , j%17 , j%3167) + (self.subtb_prefix+str(k)+'_'+str(j), self.stb_prefix+str(k), j, j/2.0, j % 41, j % + 51, j % 53, j*1.0, j % 2, 'taos'+str(j), '涛思'+str(j), j % 43, j % 23, j % 17, j % 3167) print(sql) cl.execute(sql) for i in range(insertRows): - if i % 100 == 0 : + if i % 100 == 0: ret = cl.execute( - "insert into %s values (%d , NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)" % - (self.subtb_prefix+str(k)+'_'+str(j), t0+i)) + "insert into %s values (%d , NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)" % + (self.subtb_prefix+str(k)+'_'+str(j), t0+i)) else: ret = cl.execute( "insert into %s values (%d , %d,%d,%d,%d,%d,%d,%d,'%s','%s',%d,%d,%d,%d)" % - (self.subtb_prefix+str(k)+'_'+str(j), t0+i, i%100, i/2.0, i%41, i%51, i%53, i*1.0, i%2,'taos'+str(i),'涛思'+str(i), i%43, i%23 , i%17 , i%3167)) + (self.subtb_prefix+str(k)+'_'+str(j), t0+i, i % 100, i/2.0, i % 41, i % 51, i % 53, i*1.0, i % 2, 'taos'+str(i), '涛思'+str(i), i % 43, i % 23, i % 17, i % 3167)) cl.close() conn.close() - - def rest_query(self,sql): #rest 接口 + + def rest_query(self, sql): # rest 接口 host = self.host user = self.user password = self.password - port =6041 - url = "http://{}:{}/rest/sql".format(host, port ) + port = 6041 + url = "http://{}:{}/rest/sql".format(host, port) try: - r = requests.post(url, - data = 'use %s' % self.dbname, - auth = HTTPBasicAuth('root', 'taosdata')) - r = requests.post(url, - data = sql, - auth = HTTPBasicAuth('root', 'taosdata')) + r = requests.post(url, + data='use %s' % self.dbname, + auth=HTTPBasicAuth('root', 'taosdata')) + r = requests.post(url, + data=sql, + auth=HTTPBasicAuth('root', 'taosdata')) except: print("REST API Failure (TODO: more info here)") raise @@ -481,165 +532,171 @@ class ConcurrentInquiry: nRows = rj['rows'] if ('rows' in rj) else 0 return nRows - - def query_thread_n(self,threadID): #使用原生python接口查询 + def query_thread_n(self, threadID): # 使用原生python接口查询 host = self.host user = self.user password = self.password conn = taos.connect( - host, - user, - password, - ) + host='%s' % host, + user='%s' % user, + password='%s' % password, + ) cl = conn.cursor() cl.execute("use %s;" % self.dbname) - fo = open('bak_sql_n_%d'%threadID,'w+') + fo = open('bak_sql_n_%d' % threadID, 'w+') print("Thread %d: starting" % threadID) loop = self.loop while loop: - - try: + + try: + if self.random_pick(): if self.random_pick(): - if self.random_pick(): - sql,temp=self.gen_query_sql() - else: - sql = self.gen_subquery_sql() + sql, temp = self.gen_query_sql() else: - sql = self.gen_query_join() - print("sql is ",sql) - fo.write(sql+'\n') - start = time.time() - cl.execute(sql) - cl.fetchall() - end = time.time() - print("time cost :",end-start) - except Exception as e: - print('-'*40) - print( - "Failure thread%d, sql: %s \nexception: %s" % - (threadID, str(sql),str(e))) - err_uec='Unable to establish connection' - if err_uec in str(e) and loop >0: - exit(-1) - loop -= 1 - if loop == 0: break - fo.close() + sql = self.gen_subquery_sql() + else: + sql = self.gen_query_join() + print("sql is ", sql) + fo.write(sql+'\n') + start = time.time() + cl.execute(sql) + cl.fetchall() + end = time.time() + print("time cost :", end-start) + except Exception as e: + print('-'*40) + print( + "Failure thread%d, sql: %s \nexception: %s" % + (threadID, str(sql), str(e))) + err_uec = 'Unable to establish connection' + if err_uec in str(e) and loop > 0: + exit(-1) + loop -= 1 + if loop == 0: + break + fo.close() cl.close() - conn.close() + conn.close() print("Thread %d: finishing" % threadID) - def query_thread_nr(self,threadID): #使用原生python接口进行重放 + def query_thread_nr(self, threadID): # 使用原生python接口进行重放 host = self.host user = self.user password = self.password conn = taos.connect( - host, - user, - password, - ) + host='%s' % host, + user='%s' % user, + password='%s' % password, + ) cl = conn.cursor() cl.execute("use %s;" % self.dbname) replay_sql = [] - with open('bak_sql_n_%d'%threadID,'r') as f: + with open('bak_sql_n_%d' % threadID, 'r') as f: replay_sql = f.readlines() print("Replay Thread %d: starting" % threadID) for sql in replay_sql: try: - print("sql is ",sql) + print("sql is ", sql) start = time.time() cl.execute(sql) cl.fetchall() end = time.time() - print("time cost :",end-start) + print("time cost :", end-start) except Exception as e: print('-'*40) print( - "Failure thread%d, sql: %s \nexception: %s" % - (threadID, str(sql),str(e))) - err_uec='Unable to establish connection' - if err_uec in str(e) and loop >0: - exit(-1) + "Failure thread%d, sql: %s \nexception: %s" % + (threadID, str(sql), str(e))) + err_uec = 'Unable to establish connection' + if err_uec in str(e) and loop > 0: + exit(-1) cl.close() - conn.close() + conn.close() print("Replay Thread %d: finishing" % threadID) - - def query_thread_r(self,threadID): #使用rest接口查询 + + def query_thread_r(self, threadID): # 使用rest接口查询 print("Thread %d: starting" % threadID) - fo = open('bak_sql_r_%d'%threadID,'w+') + fo = open('bak_sql_r_%d' % threadID, 'w+') loop = self.loop while loop: try: if self.random_pick(): if self.random_pick(): - sql,temp=self.gen_query_sql() + sql, temp = self.gen_query_sql() else: sql = self.gen_subquery_sql() else: sql = self.gen_query_join() - print("sql is ",sql) + print("sql is ", sql) fo.write(sql+'\n') start = time.time() self.rest_query(sql) end = time.time() - print("time cost :",end-start) + print("time cost :", end-start) except Exception as e: print('-'*40) print( - "Failure thread%d, sql: %s \nexception: %s" % - (threadID, str(sql),str(e))) - err_uec='Unable to establish connection' - if err_uec in str(e) and loop >0: + "Failure thread%d, sql: %s \nexception: %s" % + (threadID, str(sql), str(e))) + err_uec = 'Unable to establish connection' + if err_uec in str(e) and loop > 0: exit(-1) - loop -= 1 - if loop == 0: break - fo.close() - print("Thread %d: finishing" % threadID) + loop -= 1 + if loop == 0: + break + fo.close() + print("Thread %d: finishing" % threadID) - def query_thread_rr(self,threadID): #使用rest接口重放 + def query_thread_rr(self, threadID): # 使用rest接口重放 print("Replay Thread %d: starting" % threadID) replay_sql = [] - with open('bak_sql_r_%d'%threadID,'r') as f: + with open('bak_sql_r_%d' % threadID, 'r') as f: replay_sql = f.readlines() for sql in replay_sql: try: - print("sql is ",sql) + print("sql is ", sql) start = time.time() self.rest_query(sql) end = time.time() - print("time cost :",end-start) + print("time cost :", end-start) except Exception as e: print('-'*40) print( - "Failure thread%d, sql: %s \nexception: %s" % - (threadID, str(sql),str(e))) - err_uec='Unable to establish connection' - if err_uec in str(e) and loop >0: - exit(-1) - print("Replay Thread %d: finishing" % threadID) + "Failure thread%d, sql: %s \nexception: %s" % + (threadID, str(sql), str(e))) + err_uec = 'Unable to establish connection' + if err_uec in str(e) and loop > 0: + exit(-1) + print("Replay Thread %d: finishing" % threadID) def run(self): - print(self.n_numOfTherads,self.r_numOfTherads) + print(self.n_numOfTherads, self.r_numOfTherads) threads = [] - if self.replay: #whether replay + if self.replay: # whether replay for i in range(self.n_numOfTherads): - thread = threading.Thread(target=self.query_thread_nr, args=(i,)) + thread = threading.Thread( + target=self.query_thread_nr, args=(i,)) threads.append(thread) - thread.start() + thread.start() for i in range(self.r_numOfTherads): - thread = threading.Thread(target=self.query_thread_rr, args=(i,)) + thread = threading.Thread( + target=self.query_thread_rr, args=(i,)) threads.append(thread) thread.start() else: for i in range(self.n_numOfTherads): - thread = threading.Thread(target=self.query_thread_n, args=(i,)) + thread = threading.Thread( + target=self.query_thread_n, args=(i,)) threads.append(thread) - thread.start() + thread.start() for i in range(self.r_numOfTherads): - thread = threading.Thread(target=self.query_thread_r, args=(i,)) + thread = threading.Thread( + target=self.query_thread_r, args=(i,)) threads.append(thread) thread.start() - + + parser = argparse.ArgumentParser() parser.add_argument( '-H', @@ -721,17 +778,17 @@ parser.add_argument( parser.add_argument( '-u', '--user', - action='store', + action='store', default='root', type=str, help='user name') parser.add_argument( '-w', '--password', - action='store', - default='root', + action='store', + default='taosdata', type=str, - help='user name') + help='password') parser.add_argument( '-n', '--number-of-tables', @@ -763,15 +820,14 @@ parser.add_argument( args = parser.parse_args() q = ConcurrentInquiry( - args.ts,args.host_name,args.user,args.password,args.db_name, - args.stb_name_prefix,args.subtb_name_prefix,args.number_of_native_threads,args.number_of_rest_threads, - args.probabilities,args.loop_per_thread,args.number_of_stables,args.number_of_tables ,args.number_of_records, - args.mix_stable_subtable, args.replay ) + args.ts, args.host_name, args.user, args.password, args.db_name, + args.stb_name_prefix, args.subtb_name_prefix, args.number_of_native_threads, args.number_of_rest_threads, + args.probabilities, args.loop_per_thread, args.number_of_stables, args.number_of_tables, args.number_of_records, + args.mix_stable_subtable, args.replay) -if args.create_table: +if args.create_table: q.gen_data() q.get_full() -#q.gen_query_sql() +# q.gen_query_sql() q.run() - diff --git a/tests/pytest/util/cases.py b/tests/pytest/util/cases.py index 2bfd8efdcd96979d25b58d7af50bb706d91fd91d..3eb5cf25484b377e7941f22f5605efdc6234198d 100644 --- a/tests/pytest/util/cases.py +++ b/tests/pytest/util/cases.py @@ -63,14 +63,14 @@ class TDCases: tdLog.info("total %d Linux test case(s) executed" % (runNum)) - def runOneLinux(self, conn, fileName): + def runOneLinux(self, conn, fileName, replicaVar): testModule = self.__dynamicLoadModule(fileName) runNum = 0 for tmp in self.linuxCases: if tmp.name.find(fileName) != -1: case = testModule.TDTestCase() - case.init(conn, self._logSql) + case.init(conn, self._logSql, replicaVar) try: case.run() except Exception as e: diff --git a/tests/pytest/util/cluster.py b/tests/pytest/util/cluster.py index 2b9af8de25751f536f143f3fc957afc1956029fe..72b7e1fddff7fcfce3c9fb83eeb74f2cefc01f18 100644 --- a/tests/pytest/util/cluster.py +++ b/tests/pytest/util/cluster.py @@ -36,7 +36,7 @@ class ConfigureyCluster: self.portStep = 100 self.mnodeNums = 0 - def configure_cluster(self ,dnodeNums=5,mnodeNums=0,startPort=6030,portStep=100,hostname="%s"%hostname): + def configure_cluster(self ,dnodeNums=5,mnodeNums=0,independentMnode=True,startPort=6030,portStep=100,hostname="%s"%hostname): self.startPort=int(startPort) self.portStep=int(portStep) self.hostname=hostname @@ -52,7 +52,7 @@ class ConfigureyCluster: dnode.addExtraCfg("secondEp", f"{hostname}:{startPort_sec}") # configure dnoe of independent mnodes - if num <= self.mnodeNums and self.mnodeNums != 0 : + if num <= self.mnodeNums and self.mnodeNums != 0 and independentMnode == True : dnode.addExtraCfg("supportVnodes", 0) # print(dnode) self.dnodes.append(dnode) @@ -67,6 +67,13 @@ class ConfigureyCluster: tdSql.execute(" create dnode '%s';"%dnode_id) + def create_mnode(self,conn,mnodeNums): + tdSql.init(conn.cursor()) + mnodeNums=int(mnodeNums) + for i in range(2,mnodeNums+1): + tdSql.execute(" create mnode on dnode %d;"%i) + + def check_dnode(self,conn): tdSql.init(conn.cursor()) diff --git a/tests/pytest/util/dnodes.py b/tests/pytest/util/dnodes.py index b9504875e55dfc36487f23d951fc2da26f48719f..b762f8c77fc511c09b3a4e79952d41d896e86fa4 100644 --- a/tests/pytest/util/dnodes.py +++ b/tests/pytest/util/dnodes.py @@ -40,6 +40,7 @@ class TDSimClient: "jniDebugFlag": "143", "qDebugFlag": "143", "supportVnodes": "1024", + "enableQueryHb": "1", "telemetryReporting": "0", } @@ -136,6 +137,7 @@ class TDDnode: "wDebugFlag": "143", "numOfLogLines": "100000000", "statusInterval": "1", + "enableQueryHb": "1", "supportVnodes": "1024", "telemetryReporting": "0" } @@ -416,7 +418,7 @@ class TDDnode: if i > 50: break with open(logFile) as f: - timeout = time.time() + 60 * 2 + timeout = time.time() + 10 * 2 while True: line = f.readline().encode('utf-8') if bkey in line: diff --git a/tests/script/api/makefile b/tests/script/api/makefile index 52c9fcbdf8f43010c6801be5d7bbb9661cb08f00..75a2273f12dc2809ac0cec4fa090caf3231e9ba1 100644 --- a/tests/script/api/makefile +++ b/tests/script/api/makefile @@ -17,6 +17,5 @@ exe: clean: rm $(ROOT)batchprepare - rm $(ROOT)stmtBatchTest - rm $(ROOT)stmtTest - rm $(ROOT)stmt_function + rm $(ROOT)stopquery + rm $(ROOT)dbTableRoute diff --git a/tests/script/api/stopquery.c b/tests/script/api/stopquery.c index 082d987a22461725411c6528729d3de7f8e33c7c..ff830b3291a5df6f8a00704011d6954d8c68ad85 100644 --- a/tests/script/api/stopquery.c +++ b/tests/script/api/stopquery.c @@ -36,7 +36,7 @@ int64_t st, et; char hostName[128]; char dbName[128]; char tbName[128]; -int32_t runTimes = 1000; +int32_t runTimes = 10; typedef struct { int id; @@ -657,7 +657,6 @@ int sqConCleanupAsyncQuery(bool fetch) { void sqRunAllCase(void) { -#if 1 sqStopSyncQuery(false); sqStopSyncQuery(true); sqStopAsyncQuery(false); @@ -678,33 +677,33 @@ void sqRunAllCase(void) { sqConCloseAsyncQuery(false); sqConCloseAsyncQuery(true); - sqKillSyncQuery(false); sqKillSyncQuery(true); sqKillAsyncQuery(false); sqKillAsyncQuery(true); +#if 0 + /* sqConKillSyncQuery(false); sqConKillSyncQuery(true); sqConKillAsyncQuery(false); sqConKillAsyncQuery(true); -#endif - /* sqConCleanupSyncQuery(false); sqConCleanupSyncQuery(true); sqConCleanupAsyncQuery(false); sqConCleanupAsyncQuery(true); */ - +#endif + int32_t l = 5; while (l) { printf("%d\n", l--); sleep(1); } + printf("test done\n"); } - int main(int argc, char *argv[]) { if (argc != 4) { printf("usage: %s server-ip dbname tablename\n", argv[0]); diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 26162579c162d0207bafa1d780d080155f510129..e6fdecf35ecc90ccf886e7e9f1cac03896f54f2c 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -25,7 +25,6 @@ ./test.sh -f tsim/db/delete_reusevnode2.sim ./test.sh -f tsim/db/delete_writing1.sim ./test.sh -f tsim/db/delete_writing2.sim -# unsupport ./test.sh -f tsim/db/dropdnodes.sim ./test.sh -f tsim/db/error1.sim ./test.sh -f tsim/db/keep.sim ./test.sh -f tsim/db/len.sim @@ -36,27 +35,30 @@ ./test.sh -f tsim/db/taosdlog.sim # ---- dnode -# unsupport ./test.sh -f tsim/dnode/balance_replica1.sim -# unsupport ./test.sh -f tsim/dnode/balance_replica3.sim -# unsupport ./test.sh -f tsim/dnode/balance1.sim -# unsupport ./test.sh -f tsim/dnode/balance2.sim -# unsupport ./test.sh -f tsim/dnode/balance3.sim -# unsupport ./test.sh -f tsim/dnode/balancex.sim +./test.sh -f tsim/dnode/balance_replica1.sim +./test.sh -f tsim/dnode/balance_replica3.sim +./test.sh -f tsim/dnode/balance1.sim +./test.sh -f tsim/dnode/balance2.sim +./test.sh -f tsim/dnode/balance3.sim +./test.sh -f tsim/dnode/balancex.sim ./test.sh -f tsim/dnode/create_dnode.sim ./test.sh -f tsim/dnode/drop_dnode_has_mnode.sim -# unsupport ./test.sh -f tsim/dnode/drop_dnode_has_qnode_snode.sim -# unsupport ./test.sh -f tsim/dnode/drop_dnode_has_vnode_replica1.sim -# unsupport ./test.sh -f tsim/dnode/drop_dnode_has_vnode_replica3.sim -# unsupport ./test.sh -f tsim/dnode/drop_dnode_has_multi_vnode_replica1.sim -# unsupport ./test.sh -f tsim/dnode/drop_dnode_has_multi_vnode_replica3.sim +./test.sh -f tsim/dnode/drop_dnode_has_qnode_snode.sim +./test.sh -f tsim/dnode/drop_dnode_has_vnode_replica1.sim +./test.sh -f tsim/dnode/drop_dnode_has_vnode_replica3.sim +./test.sh -f tsim/dnode/drop_dnode_has_multi_vnode_replica1.sim +./test.sh -f tsim/dnode/drop_dnode_has_multi_vnode_replica3.sim +./test.sh -f tsim/dnode/drop_dnode_force.sim ./test.sh -f tsim/dnode/offline_reason.sim ./test.sh -f tsim/dnode/redistribute_vgroup_replica1.sim ./test.sh -f tsim/dnode/redistribute_vgroup_replica3_v1_leader.sim ./test.sh -f tsim/dnode/redistribute_vgroup_replica3_v1_follower.sim ./test.sh -f tsim/dnode/redistribute_vgroup_replica3_v2.sim ./test.sh -f tsim/dnode/redistribute_vgroup_replica3_v3.sim -# unsupport ./test.sh -f tsim/dnode/vnode_clean.sim +./test.sh -f tsim/dnode/vnode_clean.sim ./test.sh -f tsim/dnode/use_dropped_dnode.sim +./test.sh -f tsim/dnode/split_vgroup_replica1.sim +./test.sh -f tsim/dnode/split_vgroup_replica3.sim # ---- import ---- ./test.sh -f tsim/import/basic.sim @@ -155,7 +157,7 @@ ./test.sh -f tsim/parser/select_with_tags.sim ./test.sh -f tsim/parser/selectResNum.sim ./test.sh -f tsim/parser/set_tag_vals.sim -# TD-19572 ./test.sh -f tsim/parser/single_row_in_tb.sim +./test.sh -f tsim/parser/single_row_in_tb.sim ./test.sh -f tsim/parser/sliding.sim ./test.sh -f tsim/parser/slimit_alter_tags.sim ./test.sh -f tsim/parser/slimit.sim @@ -185,7 +187,7 @@ ./test.sh -f tsim/qnode/basic1.sim # ---- snode ---- -# unsupport ./test.sh -f tsim/snode/basic1.sim +./test.sh -f tsim/snode/basic1.sim # ---- mnode ./test.sh -f tsim/mnode/basic1.sim @@ -228,10 +230,13 @@ ./test.sh -f tsim/table/vgroup.sim # ---- stream -./test.sh -f tsim/stream/basic0.sim -v -./test.sh -f tsim/stream/basic1.sim +./test.sh -f tsim/stream/basic0.sim -g +# TD-20201 ./test.sh -f tsim/stream/basic1.sim ./test.sh -f tsim/stream/basic2.sim ./test.sh -f tsim/stream/drop_stream.sim +./test.sh -f tsim/stream/fillHistoryBasic1.sim +./test.sh -f tsim/stream/fillHistoryBasic2.sim +./test.sh -f tsim/stream/fillHistoryBasic3.sim ./test.sh -f tsim/stream/distributeInterval0.sim ./test.sh -f tsim/stream/distributeIntervalRetrive0.sim ./test.sh -f tsim/stream/distributeSession0.sim @@ -242,7 +247,7 @@ ./test.sh -f tsim/stream/triggerSession0.sim ./test.sh -f tsim/stream/partitionby.sim ./test.sh -f tsim/stream/partitionby1.sim -# unsupport ./test.sh -f tsim/stream/schedSnode.sim +./test.sh -f tsim/stream/schedSnode.sim ./test.sh -f tsim/stream/windowClose.sim ./test.sh -f tsim/stream/ignoreExpiredData.sim ./test.sh -f tsim/stream/sliding.sim @@ -303,7 +308,6 @@ # --- sma ./test.sh -f tsim/sma/drop_sma.sim ./test.sh -f tsim/sma/tsmaCreateInsertQuery.sim -# temp disable ./test.sh -f tsim/sma/rsmaCreateInsertQuery.sim ./test.sh -f tsim/sma/rsmaPersistenceRecovery.sim @@ -319,13 +323,13 @@ ./test.sh -f tsim/valgrind/checkUdf.sim # --- vnode ---- -# unsupport ./test.sh -f tsim/vnode/replica3_basic.sim -# unsupport ./test.sh -f tsim/vnode/replica3_repeat.sim -# unsupport ./test.sh -f tsim/vnode/replica3_vgroup.sim -# unsupport ./test.sh -f tsim/vnode/replica3_many.sim -# unsupport ./test.sh -f tsim/vnode/replica3_import.sim -# unsupport ./test.sh -f tsim/vnode/stable_balance_replica1.sim -# unsupport ./test.sh -f tsim/vnode/stable_dnode2_stop.sim +./test.sh -f tsim/vnode/replica3_basic.sim +./test.sh -f tsim/vnode/replica3_repeat.sim +./test.sh -f tsim/vnode/replica3_vgroup.sim +./test.sh -f tsim/vnode/replica3_many.sim +./test.sh -f tsim/vnode/replica3_import.sim +./test.sh -f tsim/vnode/stable_balance_replica1.sim +./test.sh -f tsim/vnode/stable_dnode2_stop.sim ./test.sh -f tsim/vnode/stable_dnode2.sim ./test.sh -f tsim/vnode/stable_dnode3.sim ./test.sh -f tsim/vnode/stable_replica3_dnode6.sim @@ -447,6 +451,7 @@ ./test.sh -f tsim/tag/smallint.sim ./test.sh -f tsim/tag/tinyint.sim ./test.sh -f tsim/tag/drop_tag.sim +./test.sh -f tsim/tag/tbNameIn.sim - +./test.sh -f tmp/monitor.sim #======================b1-end=============== diff --git a/tests/script/sh/deploy.sh b/tests/script/sh/deploy.sh index cc707b2ed0b9dcbb1f3725a9ac06a07b9ffc8e18..662c4a1a6c1fb5dba105f4996203885f77e61247 100755 --- a/tests/script/sh/deploy.sh +++ b/tests/script/sh/deploy.sh @@ -139,7 +139,7 @@ echo "fsDebugFlag 143" >> $TAOS_CFG echo "idxDebugFlag 143" >> $TAOS_CFG echo "udfDebugFlag 143" >> $TAOS_CFG echo "smaDebugFlag 143" >> $TAOS_CFG -echo "idxDebugFlag 143" >> $TAOS_CFG +echo "metaDebugFlag 143" >> $TAOS_CFG echo "numOfLogLines 20000000" >> $TAOS_CFG echo "asyncLog 0" >> $TAOS_CFG echo "locale en_US.UTF-8" >> $TAOS_CFG diff --git a/tests/script/test.sh b/tests/script/test.sh index 15305679876625b150aa4d53038f025e0acb7ff6..b38d331715eb1de63c6819fc76990bfcced09a9e 100755 --- a/tests/script/test.sh +++ b/tests/script/test.sh @@ -15,7 +15,7 @@ VALGRIND=0 UNIQUE=0 UNAME_BIN=`which uname` OS_TYPE=`$UNAME_BIN` -while getopts "f:avum" arg +while getopts "f:agvum" arg do case $arg in f) @@ -27,6 +27,9 @@ do u) UNIQUE=1 ;; + g) + VALGRIND=2 + ;; ?) echo "unknow argument" ;; @@ -125,6 +128,9 @@ if [ -n "$FILE_NAME" ]; then FLAG="-v" echo valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --child-silent-after-fork=yes --show-leak-kinds=all --num-callers=20 -v --workaround-gcc296-bugs=yes --log-file=${LOG_DIR}/valgrind-tsim.log $PROGRAM -c $CFG_DIR -f $FILE_NAME $FLAG valgrind --tool=memcheck --leak-check=full --show-reachable=no --track-origins=yes --child-silent-after-fork=yes --show-leak-kinds=all --num-callers=20 -v --workaround-gcc296-bugs=yes --log-file=${LOG_DIR}/valgrind-tsim.log $PROGRAM -c $CFG_DIR -f $FILE_NAME $FLAG + elif [ $VALGRIND -eq 2 ]; then + echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f $FILE_NAME -v + $PROGRAM -c $CFG_DIR -f $FILE_NAME -v else echo "ExcuteCmd:" $PROGRAM -c $CFG_DIR -f $FILE_NAME $PROGRAM -c $CFG_DIR -f $FILE_NAME diff --git a/tests/script/tmp/data.sim b/tests/script/tmp/data.sim index c59a43263b22fd10fa94193c0d291a171abbde00..cdabc97c09ce6f64478742991afeb84395a33a89 100644 --- a/tests/script/tmp/data.sim +++ b/tests/script/tmp/data.sim @@ -45,74 +45,9 @@ if $data(4)[4] != ready then goto step1 endi -return - +return print =============== step2: create database -sql create database db vgroups 1 replica 3 -sql select * from information_schema.ins_databases -if $rows != 3 then - return -1 -endi -if $data(db)[4] != 3 then - return -1 -endi - -sql select * from information_schema.ins_dnodes -if $data(2)[2] != 1 then - return -1 -endi -if $data(3)[2] != 1 then - return -1 -endi -if $data(4)[2] != 1 then - return -1 -endi - -# vnodes -sql select * from information_schema.ins_dnodes -if $data(2)[2] != 1 then - return -1 -endi -if $data(3)[2] != 1 then - return -1 -endi -if $data(4)[2] != 1 then - return -1 -endi - -# v1_dnode -$hasleader = 0 -$x = 0 -step2: - $x = $x + 1 - sleep 1000 - if $x == 20 then - print ====> dnode not ready! - return -1 - endi -sql show db.vgroups -print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 -if $data(2)[3] != 2 then - return -1 -endi -if $data(2)[5] != 3 then - return -1 -endi -if $data(2)[7] != 4 then - return -1 -endi -if $data(2)[4] == leader then - $hasleader = 1 -endi -if $data(2)[6] == leader then - $hasleader = 1 -endi -if $data(2)[8] == leader then - $hasleader = 1 -endi -if $hasleader != 1 then - goto step2 -endi +sql create database db vgroups 33 replica 3 sql use db; sql create table stb (ts timestamp, c int) tags (t int); @@ -122,6 +57,8 @@ sql select * from information_schema.ins_stables where db_name = 'db'; sql select * from information_schema.ins_tables where db_name = 'db'; sql show db.vgroups; +system sh/exec.sh -n dnode2 -s stop + return print ======== start back run_back tmp/back.sim diff --git a/tests/script/tmp/monitor.sim b/tests/script/tmp/monitor.sim index 1734b9a1a7ae20f9d4b4cdfe882d2355ce98d824..a8d805e672fd3ecb96070a06c229eeaf8ae6cb80 100644 --- a/tests/script/tmp/monitor.sim +++ b/tests/script/tmp/monitor.sim @@ -24,3 +24,5 @@ print =============== create drop qnode 1 sql create qnode on dnode 1 #sql create snode on dnode 1 +sleep 10000 +system sh/exec.sh -n dnode1 -s stop diff --git a/tests/script/tsim/db/alter_option.sim b/tests/script/tsim/db/alter_option.sim index 3d260235f26d1bccd9094d118deebeceb35e82e5..63018aea8c261532650cb1eed8a69667d5ccd509 100644 --- a/tests/script/tsim/db/alter_option.sim +++ b/tests/script/tsim/db/alter_option.sim @@ -38,7 +38,7 @@ endi print ============= create database #database_option: { -# | BUFFER value [3~16384, default: 96] +# | BUFFER value [3~16384, default: 256] # | PAGES value [64~16384, default: 256] # | CACHEMODEL value ['node', 'last_row', 'last_value', 'both'] # | WAL_FSYNC_PERIOD value [0 ~ 180000 ms] @@ -78,7 +78,7 @@ endi if $data7_db != 1440000m,1440000m,1440000m then # keep return -1 endi -if $data8_db != 96 then # buffer +if $data8_db != 256 then # buffer return -1 endi if $data9_db != 4 then # pagesize @@ -111,13 +111,13 @@ endi if $data21_db != 1000 then # wal_level fsyncperiod return -1 endi -if $data22_db != 345600 then # wal_retention_period +if $data22_db != 0 then # wal_retention_period return -1 endi -if $data23_db != -1 then # wal_retention_size +if $data23_db != 0 then # wal_retention_size return -1 endi -if $data24_db != 86400 then # wal_roll_period +if $data24_db != 0 then # wal_roll_period return -1 endi if $data25_db != 0 then # wal_segment_size diff --git a/tests/script/tsim/db/create_all_options.sim b/tests/script/tsim/db/create_all_options.sim index 5ac2ee6c4ea7ce37ee3421c5e453ab7e9f801d5c..7012fbac6c0edf9000c030d297bfc79a99eed119 100644 --- a/tests/script/tsim/db/create_all_options.sim +++ b/tests/script/tsim/db/create_all_options.sim @@ -37,7 +37,7 @@ endi print ============= create database with all options #database_option: { -# | BUFFER value [3~16384, default: 96] +# | BUFFER value [3~16384, default: 256] # | PAGES value [64~16384, default: 256] # | PAGESIZE value [1~16384, default: 4] # | CACHEMODEL value ['node', 'last_row', 'last_value', 'both', default: 'node'] @@ -98,7 +98,7 @@ endi if $data7_db != 5256000m,5256000m,5256000m then # keep return -1 endi -if $data8_db != 96 then # buffer +if $data8_db != 256 then # buffer return -1 endi if $data9_db != 4 then # pagesize diff --git a/tests/script/tsim/db/dropdnodes.sim b/tests/script/tsim/db/dropdnodes.sim deleted file mode 100644 index 20b4a136df102d4ec419b4a109192feb3768beef..0000000000000000000000000000000000000000 --- a/tests/script/tsim/db/dropdnodes.sim +++ /dev/null @@ -1,107 +0,0 @@ -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/deploy.sh -n dnode2 -i 2 -system sh/cfg.sh -n dnode1 -c walLevel -v 2 -system sh/cfg.sh -n dnode1 -c maxTablesPerVnode -v 4 -system sh/cfg.sh -n dnode2 -c maxTablesPerVnode -v 4 - -print ========== prepare data -system sh/exec.sh -n dnode1 -s start -system sh/exec.sh -n dnode2 -s start - -sleep 2000 -sql connect - -sql create dnode $hostname2 -sleep 2000 - -sql create database db -sql use db - -print ========== step1 -sql create table mt (ts timestamp, tbcol int) TAGS(tgcol int) -sql create table db.t1 using db.mt tags(1) -sql create table db.t2 using db.mt tags(2) -sql create table db.t3 using db.mt tags(3) -sql create table db.t4 using db.mt tags(4) -sql create table db.t5 using db.mt tags(5) -sql create table db.t6 using db.mt tags(6) -sql create table db.t7 using db.mt tags(7) -sql create table db.t8 using db.mt tags(8) -sql create table db.t9 using db.mt tags(9) -sql create table db.t10 using db.mt tags(10) -sql create table db.t11 using db.mt tags(11) -sql create table db.t12 using db.mt tags(12) -sql create table db.t13 using db.mt tags(13) -sql create table db.t14 using db.mt tags(14) -sql create table db.t15 using db.mt tags(15) -sql create table db.t16 using db.mt tags(16) - -sql insert into db.t1 values(now, 1) -sql insert into db.t2 values(now, 1) -sql insert into db.t3 values(now, 1) -sql insert into db.t4 values(now, 1) -sql insert into db.t5 values(now, 1) -sql insert into db.t6 values(now, 1) -sql insert into db.t7 values(now, 1) -sql insert into db.t8 values(now, 1) -sql insert into db.t9 values(now, 1) -sql insert into db.t10 values(now, 1) -sql insert into db.t11 values(now, 1) -sql insert into db.t12 values(now, 1) -sql insert into db.t13 values(now, 1) -sql insert into db.t14 values(now, 1) -sql insert into db.t15 values(now, 1) -sql insert into db.t16 values(now, 1) - -print ========== step2 -sql show tables -print $rows -if $rows != 16 then - return -1 -endi - -sql select * from mt -print $rows -if $rows != 16 then - return -1 -endi - -print ========== step3 - -system sh/exec.sh -n dnode2 -s stop -x SIGINT -sleep 3000 -sql drop dnode $hostname2 -sleep 2000 - -print ========== step3 - -sql show tables -print $rows -if $rows != 8 then - return -1 -endi - -sql select * from mt -print $rows -if $rows != 8 then - return -1 -endi - -sql select * from db.t5 -if $rows != 1 then - return -1 -endi - -sql select * from db.t13 -if $rows != 1 then - return -1 -endi - -sql_error select * from db.t1 -sql_error select * from db.t9 - -system sh/exec.sh -n dnode1 -s stop -x SIGINT -system sh/exec.sh -n dnode2 -s stop -x SIGINT diff --git a/tests/script/tsim/dnode/balance1.sim b/tests/script/tsim/dnode/balance1.sim index d91f5146458e07b97b5ff565b9049fb527435276..2b0154c8e5fdb975ec993b959d365a04ec7a7c5d 100644 --- a/tests/script/tsim/dnode/balance1.sim +++ b/tests/script/tsim/dnode/balance1.sim @@ -81,6 +81,42 @@ if $data(2)[2] != 2 then return -1 endi +sql select * from d1.t1 order by t desc +print $data01 $data11 $data21 $data31 $data41 +if $data01 != 11 then + return -1 +endi +if $data11 != 12 then + return -1 +endi +if $data21 != 13 then + return -1 +endi +if $data31 != 14 then + return -1 +endi +if $data41 != 15 then + return -1 +endi + +sql select * from d2.t2 order by t desc +print $data01 $data11 $data21 $data31 $data41 +if $data01 != 21 then + return -1 +endi +if $data11 != 22 then + return -1 +endi +if $data21 != 23 then + return -1 +endi +if $data31 != 24 then + return -1 +endi +if $data41 != 25 then + return -1 +endi + print ========== step4 sql drop dnode 2 sql select * from information_schema.ins_dnodes @@ -93,6 +129,42 @@ if $data(2)[2] != null then return -1 endi +sql select * from d1.t1 order by t desc +print $data01 $data11 $data21 $data31 $data41 +if $data01 != 11 then + return -1 +endi +if $data11 != 12 then + return -1 +endi +if $data21 != 13 then + return -1 +endi +if $data31 != 14 then + return -1 +endi +if $data41 != 15 then + return -1 +endi + +sql select * from d2.t2 order by t desc +print $data01 $data11 $data21 $data31 $data41 +if $data01 != 21 then + return -1 +endi +if $data11 != 22 then + return -1 +endi +if $data21 != 23 then + return -1 +endi +if $data31 != 24 then + return -1 +endi +if $data41 != 25 then + return -1 +endi + system sh/exec.sh -n dnode2 -s stop -x SIGINT print ========== step5 @@ -131,6 +203,42 @@ if $data(3)[2] != 1 then return -1 endi +sql select * from d1.t1 order by t desc +print $data01 $data11 $data21 $data31 $data41 +if $data01 != 11 then + return -1 +endi +if $data11 != 12 then + return -1 +endi +if $data21 != 13 then + return -1 +endi +if $data31 != 14 then + return -1 +endi +if $data41 != 15 then + return -1 +endi + +sql select * from d2.t2 order by t desc +print $data01 $data11 $data21 $data31 $data41 +if $data01 != 21 then + return -1 +endi +if $data11 != 22 then + return -1 +endi +if $data21 != 23 then + return -1 +endi +if $data31 != 24 then + return -1 +endi +if $data41 != 25 then + return -1 +endi + print ========== step6 sql create database d3 vgroups 1 sql create table d3.t3 (t timestamp, i int) diff --git a/tests/script/tsim/dnode/drop_dnode_force.sim b/tests/script/tsim/dnode/drop_dnode_force.sim new file mode 100644 index 0000000000000000000000000000000000000000..10edacf3aa18cbb3fbcb3cef0093ef281d3785a3 --- /dev/null +++ b/tests/script/tsim/dnode/drop_dnode_force.sim @@ -0,0 +1,301 @@ +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 supportVnodes -v 0 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +system sh/exec.sh -n dnode4 -s start +sql connect + +print =============== step1 create dnode2 dnode3 dnode4 dnode 5 +sql create dnode $hostname port 7200 +sql create dnode $hostname port 7300 +sql create dnode $hostname port 7400 +sql create dnode $hostname port 7500 + +$x = 0 +step1: + $ = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not online! + return -1 + endi +sql select * from information_schema.ins_dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 5 then + return -1 +endi +if $data(1)[4] != ready then + goto step1 +endi +if $data(2)[4] != ready then + goto step1 +endi +if $data(3)[4] != ready then + goto step1 +endi +if $data(4)[4] != ready then + goto step1 +endi +if $data(5)[4] != offline then + goto step1 +endi + +print =============== step2 create database +sql create database d1 vgroups 1 replica 3 +sql use d1 +sql create table d1.st0 (ts timestamp, i int) tags (j int) +sql create table d1.c0 using st0 tags(0) +sql create table d1.c1 using st0 tags(1) +sql create table d1.c2 using st0 tags(2) +sql create table d1.c3 using st0 tags(3) +sql create table d1.c4 using st0 tags(4) +sql create table d1.c5 using st0 tags(5) +sql create table d1.c6 using st0 tags(6) +sql create table d1.c7 using st0 tags(7) +sql create table d1.c8 using st0 tags(8) +sql create table d1.c9 using st0 tags(9) +sql show d1.tables +if $rows != 10 then + return -1 +endi +print d1.rows ===> $rows +sql select * from information_schema.ins_tables where stable_name = 'st0' and db_name = 'd1' +if $rows != 10 then + return -1 +endi + +sql create database d2 vgroups 3 replica 1 +sql use d2 +sql create table d2.st1 (ts timestamp, i int) tags (j int) +sql create table d2.c10 using st1 tags(0) +sql create table d2.c11 using st1 tags(1) +sql create table d2.c12 using st1 tags(2) +sql create table d2.c13 using st1 tags(3) +sql create table d2.c14 using st1 tags(4) +sql create table d2.c15 using st1 tags(5) +sql create table d2.c16 using st1 tags(6) +sql create table d2.c17 using st1 tags(7) +sql create table d2.c18 using st1 tags(8) +sql create table d2.c19 using st1 tags(9) +sql create table d2.c190 using st1 tags(9) +sql show d2.tables +if $rows != 11 then + return -1 +endi +sql reset query cache +sql select * from information_schema.ins_tables where stable_name = 'st1' and db_name = 'd2' +print d2.st1.tables ===> $rows +if $rows != 11 then + return -1 +endi + +sql create table d2.st2 (ts timestamp, i int) tags (j int) +sql create table d2.c20 using st2 tags(0) +sql create table d2.c21 using st2 tags(1) +sql create table d2.c22 using st2 tags(2) +sql create table d2.c23 using st2 tags(3) +sql create table d2.c24 using st2 tags(4) +sql create table d2.c25 using st2 tags(5) +sql create table d2.c26 using st2 tags(6) +sql create table d2.c27 using st2 tags(7) +sql create table d2.c28 using st2 tags(8) +sql create table d2.c29 using st2 tags(9) +sql create table d2.c290 using st2 tags(9) +sql create table d2.c291 using st2 tags(9) +sql show d2.tables +if $rows != 23 then + return -1 +endi +sql reset query cache +sql select * from information_schema.ins_tables where stable_name = 'st2' and db_name = 'd2' +print d2.st2.tables ===> $rows +if $rows != 12 then + return -1 +endi + +print =============== step3: create qnode snode on dnode 2 +sql create qnode on dnode 2 +sql create snode on dnode 2 +sql select * from information_schema.ins_qnodes +if $rows != 1 then + return -1 +endi +sql show snodes +if $rows != 1 then + return -1 +endi + +print =============== step4: create mnode on dnode 2 +sql create mnode on dnode 3 +sql create mnode on dnode 2 +$x = 0 +step4: + $x = $x + 1 + sleep 1000 + if $x == 10 then + return -1 + endi +sql select * from information_schema.ins_mnodes -x step4 +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] +print $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[1][4] +#if $data(1)[2] != leader then +# goto step4 +#endi +if $data(2)[2] != follower then + goto step4 +endi +#if $data(3)[2] != follower then +# goto step4 +#endi + +print =============== step5: create dnode 5 +system sh/exec.sh -n dnode2 -s stop -x SIGINT +system sh/exec.sh -n dnode5 -s start +$x = 0 +step5: + $ = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not online! + return -1 + endi +sql select * from information_schema.ins_dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +print ===> $data20 $data21 $data22 $data23 $data24 $data25 +print ===> $data30 $data31 $data32 $data33 $data34 $data35 +print ===> $data40 $data41 $data42 $data43 $data44 $data45 +if $rows != 5 then + return -1 +endi +if $data(1)[4] != ready then + goto step5 +endi +if $data(2)[4] != offline then + goto step5 +endi +if $data(3)[4] != ready then + goto step5 +endi +if $data(4)[4] != ready then + goto step5 +endi +if $data(5)[4] != ready then + goto step5 +endi + +print =============== step5: drop dnode 2 +sql_error drop dnode 2 +sql drop dnode 2 force + +print select * from information_schema.ins_dnodes; +sql select * from information_schema.ins_dnodes; +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] +if $rows != 4 then + return -1 +endi + +print select * from information_schema.ins_mnodes; +sql select * from information_schema.ins_mnodes +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] +print $data[1][0] $data[1][1] $data[1][2] $data[1][3] $data[1][4] +if $rows != 2 then + return -1 +endi +if $data(1)[2] != leader then + return -1 +endi + +sql select * from information_schema.ins_qnodes +if $rows != 0 then + return -1 +endi +sql show snodes +if $rows != 0 then + return -1 +endi + +print =============== step6: check d1 +sql reset query cache +sql show d1.tables +if $rows != 10 then + return -1 +endi + +print =============== step7: check d2 +sql show d2.tables +print ===> d2.tables: $rows remained +if $rows > 23 then + return -1 +endi +if $rows <= 0 then + return -1 +endi + +print =============== step8: drop stable and recreate it +sql select * from information_schema.ins_tables where stable_name = 'st2' and db_name = 'd2' +print d2.st2.tables ==> $rows + +sql drop table d2.st2; +sql create table d2.st2 (ts timestamp, i int) tags (j int) +sql create table d2.c20 using st2 tags(0) +sql create table d2.c21 using st2 tags(1) +sql create table d2.c22 using st2 tags(2) +sql create table d2.c23 using st2 tags(3) +sql create table d2.c24 using st2 tags(4) +sql create table d2.c25 using st2 tags(5) +sql create table d2.c26 using st2 tags(6) +sql create table d2.c27 using st2 tags(7) +sql create table d2.c28 using st2 tags(8) +sql create table d2.c29 using st2 tags(9) +sql create table d2.c30 using st2 tags(9) +sql create table d2.c31 using st2 tags(9) +sql create table d2.c32 using st2 tags(9) + +sql select * from information_schema.ins_tables where stable_name = 'st2' and db_name = 'd2' +print d2.st2.tables ==> $rows +if $rows != 13 then + return -1 +endi + +print =============== step9: alter stable +return +print By modifying the stable, the missing stable information can be reconstructed in the vnode. +print However, currently, getting the stable meta from the vnode, and return the table not exist +print To handle this, we need to modify the way stable-meta is fetched + +sql select * from information_schema.ins_tables where stable_name = 'st1' and db_name = 'd2' +print d2.st1.tables ==> $rows +$remains = $rows + +sql alter table d2.st1 add column b smallint +return +sql create table d2.c30 using st tags(0) +sql create table d2.c31 using st tags(1) +sql create table d2.c32 using st tags(2) +sql create table d2.c33 using st tags(3) +sql create table d2.c34 using st tags(4) +sql create table d2.c35 using st tags(5) +sql create table d2.c36 using st tags(6) +sql create table d2.c37 using st tags(7) +sql create table d2.c38 using st tags(8) +sql create table d2.c39 using st tags(9) +sql show d2.tables +print d2.st1.tables ==> $rows + +$total = $remains + 10 +if $rows != $total then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode2 -s stop -x SIGINT diff --git a/tests/script/tsim/dnode/split_vgroup_replica1.sim b/tests/script/tsim/dnode/split_vgroup_replica1.sim new file mode 100644 index 0000000000000000000000000000000000000000..1bdd322714a1e8e7443d337daacc69d3ce2a4792 --- /dev/null +++ b/tests/script/tsim/dnode/split_vgroup_replica1.sim @@ -0,0 +1,87 @@ +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 transPullupInterval -v 1 +system sh/cfg.sh -n dnode2 -c transPullupInterval -v 1 +system sh/cfg.sh -n dnode3 -c transPullupInterval -v 1 +system sh/cfg.sh -n dnode4 -c transPullupInterval -v 1 +system sh/cfg.sh -n dnode1 -c supportVnodes -v 0 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +sql connect +sql create user u1 pass 'taosdata' + +print =============== step1 create dnode2 +sql create dnode $hostname port 7200 +sql create dnode $hostname port 7300 + +$x = 0 +step1: + $x = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not ready! + return -1 + endi +sql select * from information_schema.ins_dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +print ===> $data20 $data21 $data22 $data23 $data24 $data25 +print ===> $data30 $data31 $data32 $data33 $data34 $data35 +if $rows != 3 then + return -1 +endi +if $data(1)[4] != ready then + goto step1 +endi +if $data(2)[4] != ready then + goto step1 +endi + +print =============== step2: create db +sql create database d1 vgroups 1 replica 1 + +system sh/exec.sh -n dnode3 -s start +$x = 0 +step2: + $x = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not ready! + return -1 + endi +sql select * from information_schema.ins_dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +print ===> $data20 $data21 $data22 $data23 $data24 $data25 +if $rows != 3 then + return -1 +endi +if $data(1)[4] != ready then + goto step2 +endi +if $data(2)[4] != ready then + goto step2 +endi +if $data(3)[4] != ready then + goto step2 +endi + +print =============== step3: create database +sql use d1 +sql create table d1.st (ts timestamp, i int) tags (j int) +sql create table d1.c1 using st tags(1) +sql show d1.tables +if $rows != 1 then + return -1 +endi + +print =============== step4: split +print split vgroup 2 +sql split vgroup 2 + +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 diff --git a/tests/script/tsim/dnode/split_vgroup_replica3.sim b/tests/script/tsim/dnode/split_vgroup_replica3.sim new file mode 100644 index 0000000000000000000000000000000000000000..b79369987b72a99c89faaedd16125bf38491facf --- /dev/null +++ b/tests/script/tsim/dnode/split_vgroup_replica3.sim @@ -0,0 +1,67 @@ +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 transPullupInterval -v 1 +system sh/cfg.sh -n dnode2 -c transPullupInterval -v 1 +system sh/cfg.sh -n dnode3 -c transPullupInterval -v 1 +system sh/cfg.sh -n dnode4 -c transPullupInterval -v 1 +system sh/cfg.sh -n dnode5 -c transPullupInterval -v 1 +system sh/cfg.sh -n dnode1 -c supportVnodes -v 0 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start +system sh/exec.sh -n dnode3 -s start +system sh/exec.sh -n dnode4 -s start +#system sh/exec.sh -n dnode5 -s start +sql connect +sql create user u1 pass 'taosdata' + +print =============== step1 create dnode2 +sql create dnode $hostname port 7200 +sql create dnode $hostname port 7300 +sql create dnode $hostname port 7400 + +$x = 0 +step1: + $x = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not ready! + return -1 + endi +sql select * from information_schema.ins_dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +print ===> $data20 $data21 $data22 $data23 $data24 $data25 +print ===> $data30 $data31 $data32 $data33 $data34 $data35 +print ===> $data40 $data41 $data42 $data43 $data44 $data45 +if $rows != 4 then + return -1 +endi +if $data(1)[4] != ready then + goto step1 +endi +if $data(2)[4] != ready then + goto step1 +endi +if $data(3)[4] != ready then + goto step1 +endi +if $data(4)[4] != ready then + goto step1 +endi + +print =============== step2: create db +sql create database d1 vgroups 1 replica 3 + +print =============== step3: split +print split vgroup 2 +sql split vgroup 2 + +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 diff --git a/tests/script/tsim/insert/basic.sim b/tests/script/tsim/insert/basic.sim index ec8a61bb04561da2ffdf06cfdb55f483f5f13de8..f910fa9c233e59dbac1d30840c1cfd1481a8f2b7 100644 --- a/tests/script/tsim/insert/basic.sim +++ b/tests/script/tsim/insert/basic.sim @@ -50,6 +50,7 @@ print $data[1000][1000] $a1 = 0 $a2 = 0 $a3 = $a1 % $a2 +$a4 = $a1 / $a2 print $a3 $val = \\\1 diff --git a/tests/script/tsim/parser/auto_create_tb.sim b/tests/script/tsim/parser/auto_create_tb.sim index 312964a1ab3d11e6b361eeb805870844c4b90313..7803557bdce930ba60b6c1ed34d849ba5b09df09 100644 --- a/tests/script/tsim/parser/auto_create_tb.sim +++ b/tests/script/tsim/parser/auto_create_tb.sim @@ -186,6 +186,7 @@ endi sql select t1, count(*), first(c9) from $stb partition by t1 order by t1 asc slimit 3 if $rows != 3 then + print expect 3, actual: $rows return -1 endi if $data(1)[1] != 1 then diff --git a/tests/script/tsim/parser/function.sim b/tests/script/tsim/parser/function.sim index 0002a5d09555083569fc7a6ff32a376e56746dfe..ec9cdf2666617c52192685a445d0d7334d4a6387 100644 --- a/tests/script/tsim/parser/function.sim +++ b/tests/script/tsim/parser/function.sim @@ -995,3 +995,86 @@ endi if $data00 != 0.000000000 then return -1 endi + +sql create table ft1(ts timestamp, a int, b int , c int, d double); + +sql insert into ft1 values(1648791213000,1,2,3,1.0); +sql_error select sum(_wduration), a from ft1 state_window(a); + +sql_error select count(_wduration), a from ft1 state_window(a); + +sql_error select max(_wduration), a from ft1 state_window(a); + +sql_error select sum(1 + _wduration), a from ft1 state_window(a); + +sql_error select sum(cast(_wstart as bigint)), a from ft1 state_window(a); + +sql_error select sum(cast(_wend as bigint)), a from ft1 state_window(a); + +sql_error create stream streams1 trigger at_once into streamt as select _wstart, sum(_wduration) from ft1 interval(10s); + +sql_error create stream streams1 trigger at_once into streamt as select _wstart, sum(cast(_wend as bigint)) from ft1 interval(10s); + +sql create database test vgroups 1; +sql use test; +sql create table t1(ts timestamp, a int, b int , c int, d double); +sql insert into t1 values(1648791213000,1,1,3,1.0); +sql insert into t1 values(1648791223000,1,2,NULL,NULL); + +sleep 200 + +sql select apercentile(c, 50), apercentile(d, 50, "t-digest") from t1; + +if $data00 != 3.000000000 then + print ======data00=$data00 + return -1 +endi + +if $data01 != 1.000000000 then + print ======data01=$data01 + return -1 +endi + +sql select apercentile(c, 50) a, apercentile(d, 50, "t-digest") from t1 partition by b session(ts, 5s) order by a desc; + +if $data00 != 3.000000000 then + print ======data00=$data00 + return -1 +endi + +if $data01 != 1.000000000 then + print ======data01=$data01 + return -1 +endi + +if $data10 != NULL then + print ======data10=$data10 + return -1 +endi + +if $data11 != NULL then + print ======data11=$data11 + return -1 +endi + +sql select apercentile(c, 50) a, apercentile(d, 50, "t-digest") from t1 state_window(b) order by a desc; + +if $data00 != 3.000000000 then + print ======data00=$data00 + return -1 +endi + +if $data01 != 1.000000000 then + print ======data01=$data01 + return -1 +endi + +if $data10 != NULL then + print ======data10=$data10 + return -1 +endi + +if $data11 != NULL then + print ======data11=$data11 + return -1 +endi \ No newline at end of file diff --git a/tests/script/tsim/parser/having_child.sim b/tests/script/tsim/parser/having_child.sim index ae78c806cae1d8cc13cc096285dd51d048473160..db9a25365ec1d120fbba7557ecf045c1b5098696 100644 --- a/tests/script/tsim/parser/having_child.sim +++ b/tests/script/tsim/parser/having_child.sim @@ -733,6 +733,7 @@ sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),LEASTSQUARES(f1,1,1) from tb1 sql select avg(f1),count(tb1.*),sum(f1),stddev(f1),LEASTSQUARES(f1,1,1) from tb1 group by f1 having sum(f1) > 2 order by f1; if $rows != 3 then + print expect 3 , actual: $rows return -1 endi if $data00 != 2.000000000 then diff --git a/tests/script/tsim/parser/limit_stb.sim b/tests/script/tsim/parser/limit_stb.sim index 2ecb2e1518a1404f197d247adcabe6f8a16c3ea4..6950df9ee1b41816feca5c8753efd14489fda063 100644 --- a/tests/script/tsim/parser/limit_stb.sim +++ b/tests/script/tsim/parser/limit_stb.sim @@ -39,9 +39,9 @@ endi if $data01 != 1 then return -1 endi -if $data41 != 5 then - return -1 -endi +#if $data41 != 5 then +# return -1 +#endi sql select * from $stb order by ts desc limit 5 if $rows != 5 then diff --git a/tests/script/tsim/stream/basic1.sim b/tests/script/tsim/stream/basic1.sim index b20e2e35921d957a58d947724f20038f3e524728..bb6604687c7c950ca8dbce16998d6df11d39e5f3 100644 --- a/tests/script/tsim/stream/basic1.sim +++ b/tests/script/tsim/stream/basic1.sim @@ -23,443 +23,516 @@ sql insert into t1 values(1648791223001,2,2,3,1.1); sql insert into t1 values(1648791233002,3,2,3,2.1); sql insert into t1 values(1648791243003,4,2,3,3.1); sql insert into t1 values(1648791213004,4,2,3,4.1); -sleep 1000 + +$loop_count = 0 + +loop0: +sleep 200 + sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; -if $rows != 4 then - print ======$rows +$loop_count = $loop_count + 1 +if $loop_count == 20 then return -1 endi +if $rows != 4 then + print =====rows=$rows + goto loop0 +endi + # row 0 if $data01 != 2 then - print ======$data01 - return -1 + print =====data01=$data01 + goto loop0 endi if $data02 != 2 then - print ======$data02 - return -1 + print =====data02=$data02 + goto loop0 endi if $data03 != 5 then - print ======$data03 - return -1 + print =====data03=$data03 + goto loop0 endi if $data04 != 2 then - print ======$data04 - return -1 + print =====data04=$data04 + goto loop0 endi if $data05 != 3 then - print ======$data05 - return -1 + print =====data05=$data05 + goto loop0 endi # row 1 if $data11 != 1 then - print ======$data11 - return -1 + print =====data11=$data11 + goto loop0 endi if $data12 != 1 then - print ======$data12 - return -1 + print =====data12=$data12 + goto loop0 endi if $data13 != 2 then - print ======$data13 - return -1 + print =====data13=$data13 + goto loop0 endi if $data14 != 2 then - print ======$data14 - return -1 + print =====data14=$data14 + goto loop0 endi if $data15 != 3 then - print ======$data15 - return -1 + print =====data15=$data15 + goto loop0 endi # row 2 if $data21 != 1 then - print ======$data21 + print =====data21=$data21 return -1 endi if $data22 != 1 then - print ======$data22 + print =====data22=$data22 return -1 endi if $data23 != 3 then - print ======$data23 + print =====data23=$data23 return -1 endi if $data24 != 2 then - print ======$data24 + print =====data24=$data24 return -1 endi if $data25 != 3 then - print ======$data25 + print =====data25=$data25 return -1 endi # row 3 if $data31 != 1 then - print ======$data31 + print =====data31=$data31 return -1 endi if $data32 != 1 then - print ======$data32 + print =====data32=$data32 return -1 endi if $data33 != 4 then - print ======$data33 + print =====data33=$data33 return -1 endi if $data34 != 2 then - print ======$data34 + print =====data34=$data34 return -1 endi if $data35 != 3 then - print ======$data35 + print =====data35=$data35 return -1 endi sql insert into t1 values(1648791223001,12,14,13,11.1); -sleep 500 + +$loop_count = 0 +loop1: +sleep 200 + sql select * from streamt; +$loop_count = $loop_count + 1 +if $loop_count == 20 then + return -1 +endi + print count(*) , count(d) , sum(a) , max(b) , min(c) print 0: $data00 , $data01 , $data02 , $data03 , $data04 , $data05 print 1: $data10 , $data11 , $data12 , $data13 , $data14 , $data15 if $rows != 4 then print ======$rows - return -1 + goto loop1 endi # row 0 if $data01 != 2 then - print ======$data01 - return -1 + print =====data01=$data01 + goto loop1 endi if $data02 != 2 then - print ======$data02 - return -1 + print =====data02=$data02 + goto loop1 endi if $data03 != 5 then - print ======$data03 - return -1 + print =====data03=$data03 + goto loop1 endi if $data04 != 2 then - print ======$data04 - return -1 + print =====data04=$data04 + goto loop1 endi if $data05 != 3 then - print ======$data05 - return -1 + print =====data05=$data05 + goto loop1 endi # row 1 if $data11 != 1 then - print ======$data11 - return -1 + print =====data11=$data11 + goto loop1 endi if $data12 != 1 then - print ======$data12 - return -1 + print =====data12=$data12 + goto loop1 endi if $data13 != 12 then - print ======$data13 - return -1 + print =====data13=$data13 + goto loop1 endi if $data14 != 14 then - print ======$data14 - return -1 + print =====data14=$data14 + goto loop1 endi if $data15 != 13 then - print ======$data15 - return -1 + print =====data15=$data15 + goto loop1 endi # row 2 if $data21 != 1 then - print ======$data21 + print =====data21=$data21 return -1 endi if $data22 != 1 then - print ======$data22 + print =====data22=$data22 return -1 endi if $data23 != 3 then - print ======$data23 + print =====data23=$data23 return -1 endi if $data24 != 2 then - print ======$data24 + print =====data24=$data24 return -1 endi if $data25 != 3 then - print ======$data25 + print =====data25=$data25 return -1 endi # row 3 if $data31 != 1 then - print ======$data31 + print =====data31=$data31 return -1 endi if $data32 != 1 then - print ======$data32 + print =====data32=$data32 return -1 endi if $data33 != 4 then - print ======$data33 + print =====data33=$data33 return -1 endi if $data34 != 2 then - print ======$data34 + print =====data34=$data34 return -1 endi if $data35 != 3 then - print ======$data35 + print =====data35=$data35 return -1 endi sql insert into t1 values(1648791223002,12,14,13,11.1); -sleep 100 + +$loop_count = 0 +loop2: +sleep 200 + sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; +$loop_count = $loop_count + 1 +if $loop_count == 20 then + return -1 +endi + # row 1 if $data11 != 2 then - print ======$data11 - return -1 + print =====data11=$data11 + goto loop2 endi if $data12 != 2 then - print ======$data12 - return -1 + print =====data12=$data12 + goto loop2 endi if $data13 != 24 then - print ======$data13 - return -1 + print =====data13=$data13 + goto loop2 endi if $data14 != 14 then - print ======$data14 - return -1 + print =====data14=$data14 + goto loop2 endi if $data15 != 13 then - print ======$data15 - return -1 + print =====data15=$data15 + goto loop2 endi sql insert into t1 values(1648791223003,12,14,13,11.1); -sleep 100 + +$loop_count = 0 +loop3: +sleep 200 + sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; +$loop_count = $loop_count + 1 +if $loop_count == 20 then + return -1 +endi + # row 1 if $data11 != 3 then - print ======$data11 - return -1 + print =====data11=$data11 + goto loop3 endi if $data12 != 3 then - print ======$data12 - return -1 + print =====data12=$data12 + goto loop3 endi if $data13 != 36 then - print ======$data13 - return -1 + print =====data13=$data13 + goto loop3 endi if $data14 != 14 then - print ======$data14 - return -1 + print =====data14=$data14 + goto loop3 endi if $data15 != 13 then - print ======$data15 - return -1 + print =====data15=$data15 + goto loop3 endi sql insert into t1 values(1648791223001,1,1,1,1.1); sql insert into t1 values(1648791223002,2,2,2,2.1); sql insert into t1 values(1648791223003,3,3,3,3.1); -sleep 100 + +$loop_count = 0 +loop4: +sleep 200 + sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; +$loop_count = $loop_count + 1 +if $loop_count == 20 then + return -1 +endi + # row 1 if $data11 != 3 then - print ======$data11 - return -1 + print =====data11=$data11 + goto loop4 endi if $data12 != 3 then - print ======$data12 - return -1 + print =====data12=$data12 + goto loop4 endi if $data13 != 6 then - print ======$data13 - return -1 + print =====data13=$data13 + goto loop4 endi if $data14 != 3 then - print ======$data14 - return -1 + print =====data14=$data14 + goto loop4 endi if $data15 != 1 then - print ======$data15 - return -1 + print =====data15=$data15 + goto loop4 endi sql insert into t1 values(1648791233003,3,2,3,2.1); sql insert into t1 values(1648791233002,5,6,7,8.1); sql insert into t1 values(1648791233002,3,2,3,2.1); -sleep 100 + +$loop_count = 0 +loop5: +sleep 200 + sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; +$loop_count = $loop_count + 1 +if $loop_count == 20 then + return -1 +endi + # row 2 if $data21 != 2 then - print ======$data21 - return -1 + print =====data21=$data21 + goto loop5 endi if $data22 != 2 then - print ======$data22 - return -1 + print =====data22=$data22 + goto loop5 endi if $data23 != 6 then - print ======$data23 - return -1 + print =====data23=$data23 + goto loop5 endi if $data24 != 2 then - print ======$data24 - return -1 + print =====data24=$data24 + goto loop5 endi if $data25 != 3 then - print ======$data25 - return -1 + print =====data25=$data25 + goto loop5 endi sql insert into t1 values(1648791213004,4,2,3,4.1) (1648791213006,5,4,7,9.1) (1648791213004,40,20,30,40.1) (1648791213005,4,2,3,4.1); -sleep 100 + +$loop_count = 0 +loop6: +sleep 200 + sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; +$loop_count = $loop_count + 1 +if $loop_count == 20 then + return -1 +endi + # row 0 if $data01 != 4 then - print ======$data01 - return -1 + print =====data01=$data01 + goto loop6 endi if $data02 != 4 then - print ======$data02 - return -1 + print =====data02=$data02 + goto loop6 endi if $data03 != 50 then - print ======$data03 != 50 - return -1 + print =====data03=$data03 != 50 + goto loop6 endi if $data04 != 20 then - print ======$data04 != 20 - return -1 + print =====data04=$data04 != 20 + goto loop6 endi if $data05 != 3 then - print ======$data05 - return -1 + print =====data05=$data05 + goto loop6 endi sql insert into t1 values(1648791223004,4,2,3,4.1) (1648791233006,5,4,7,9.1) (1648791223004,40,20,30,40.1) (1648791233005,4,2,3,4.1); -sleep 100 + +$loop_count = 0 +loop7: +sleep 200 + sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; +$loop_count = $loop_count + 1 +if $loop_count == 20 then + return -1 +endi + # row 1 if $data11 != 4 then - print ======$data11 - return -1 + print =====data11=$data11 + goto loop7 endi if $data12 != 4 then - print ======$data12 - return -1 + print =====data12=$data12 + goto loop7 endi if $data13 != 46 then - print ======$data13 != 46 - return -1 + print =====data13=$data13 != 46 + goto loop7 endi if $data14 != 20 then - print ======$data14 != 20 - return -1 + print =====data14=$data14 != 20 + goto loop7 endi if $data15 != 1 then - print ======$data15 - return -1 + print =====data15=$data15 + goto loop7 endi # row 2 if $data21 != 4 then - print ======$data21 - return -1 + print =====data21=$data21 + goto loop7 endi if $data22 != 4 then - print ======$data22 - return -1 + print =====data22=$data22 + goto loop7 endi if $data23 != 15 then - print ======$data23 - return -1 + print =====data23=$data23 + goto loop7 endi if $data24 != 4 then - print ======$data24 - return -1 + print =====data24=$data24 + goto loop7 endi if $data25 != 3 then - print ======$data25 - return -1 + print =====data25=$data25 + goto loop7 endi sql create database test2 vgroups 1; @@ -479,11 +552,11 @@ sql insert into t1 values(1648791213000,1,1,1,1.0) t2 values(1648791213000,2,2,2 $loop_count = 0 -loop0: -sleep 300 +loop8: +sleep 200 $loop_count = $loop_count + 1 -if $loop_count == 10 then +if $loop_count == 20 then return -1 endi @@ -491,7 +564,7 @@ sql select * from streamt; if $rows != 4 then print =====rows=$rows - goto loop0 + goto loop8 endi sql insert into t1 values(1648791213000,5,5,5,5.0) t2 values(1648791213000,6,6,6,6.0) t5 values(1648791213000,7,7,7,7.0); @@ -499,11 +572,11 @@ sql insert into t1 values(1648791213000,5,5,5,5.0) t2 values(1648791213000,6,6,6 $loop_count = 0 -loop1: -sleep 300 +loop9: +sleep 200 $loop_count = $loop_count + 1 -if $loop_count == 10 then +if $loop_count == 20 then return -1 endi @@ -511,51 +584,51 @@ sql select * from streamt order by c4 desc; if $rows != 5 then print =====rows=$rows - goto loop1 + goto loop9 endi # row 0 if $data01 != 1 then print =====data01=$data01 - goto loop1 + goto loop9 endi if $data02 != 7 then print =====data02=$data02 - goto loop1 + goto loop9 endi # row 1 if $data11 != 1 then print =====data11=$data11 - goto loop1 + goto loop9 endi if $data12 != 6 then print =====data12=$data12 - goto loop1 + goto loop9 endi # row 2 if $data21 != 1 then print =====data21=$data21 - goto loop1 + goto loop9 endi if $data22 != 5 then print =====data22=$data22 - goto loop1 + goto loop9 endi sql insert into t1 values(1648791213000,8,8,8,8.0); $loop_count = 0 -loop2: -sleep 300 +loop10: +sleep 200 $loop_count = $loop_count + 1 -if $loop_count == 10 then +if $loop_count == 20 then return -1 endi @@ -564,28 +637,29 @@ sql select * from streamt order by c4 desc; # row 0 if $data01 != 1 then print =====data01=$data01 - goto loop2 + goto loop10 endi if $data02 != 8 then print =====data02=$data02 - goto loop2 + goto loop10 endi $loop_count = 0 -loop3: -sleep 300 +loop11: +sleep 200 + +sql select count(*) from streamt3; $loop_count = $loop_count + 1 -if $loop_count == 10 then +if $loop_count == 20 then return -1 endi -sql select count(*) from streamt3; # row 0 if $data00 != 5 then print =====data00=$data00 - goto loop3 + goto loop11 endi #max,min selectivity @@ -601,25 +675,26 @@ sql insert into ts1 values(1648791222001,2,2,3); sleep 50 $loop_count = 0 -loop3: +loop12: +sleep 200 + sql select * from streamtST3; -sleep 300 $loop_count = $loop_count + 1 -if $loop_count == 10 then +if $loop_count == 20 then return -1 endi # row 0 if $data02 != 1 then print =====data02=$data02 - goto loop3 + goto loop12 endi # row 1 if $data12 != 2 then print =====data12=$data12 - goto loop3 + goto loop12 endi @@ -629,19 +704,22 @@ sql create table t1(ts timestamp, a int, b int , c int, d double); sql create stream streams4 trigger at_once into streamt4 as select _wstart, count(*) c1 from t1 where a > 5 interval(10s); sql insert into t1 values(1648791213000,1,2,3,1.0); +$loop_count = 0 +loop13: sleep 200 + sql select * from streamt4; # row 0 if $rows != 0 then print =====rows=$rows - return -1 + goto loop13 endi sql insert into t1 values(1648791213000,6,2,3,1.0); $loop_count = 0 -loop4: +loop14: sleep 200 sql select * from streamt4; @@ -652,13 +730,13 @@ endi if $data01 != 1 then print =====data01=$data01 - goto loop4 + goto loop14 endi sql insert into t1 values(1648791213000,2,2,3,1.0); $loop_count = 0 -loop5: +loop15: sleep 200 sql select * from streamt4; @@ -669,7 +747,7 @@ endi if $rows != 0 then print =====rows=$rows - goto loop5 + goto loop15 endi diff --git a/tests/script/tsim/stream/fillHistoryBasic1.sim b/tests/script/tsim/stream/fillHistoryBasic1.sim new file mode 100644 index 0000000000000000000000000000000000000000..772a09c0176512ca1617e53cc87e16ec20fb2a4a --- /dev/null +++ b/tests/script/tsim/stream/fillHistoryBasic1.sim @@ -0,0 +1,923 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sleep 50 +sql connect + +print =============== create database +sql create database test vgroups 1; +sql select * from information_schema.ins_databases +if $rows != 3 then + return -1 +endi + +print $data00 $data01 $data02 + +sql use test; + +sql create table t1(ts timestamp, a int, b int , c int, d double); + +sql create stream stream1 trigger at_once fill_history 1 into streamt as select _wstart, count(*) c1, count(d) c2 , sum(a) c3 , max(b) c4, min(c) c5 from t1 interval(10s); + +sql insert into t1 values(1648791213000,1,2,3,1.0); +sql insert into t1 values(1648791223001,2,2,3,1.1); +sql insert into t1 values(1648791233002,3,2,3,2.1); +sql insert into t1 values(1648791243003,4,2,3,3.1); +sql insert into t1 values(1648791213004,4,2,3,4.1); + + +sleep 5000 +sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; + +if $rows != 4 then + print ======$rows + return -1 +endi + +# row 0 +if $data01 != 2 then + print ======$data01 + return -1 +endi + +if $data02 != 2 then + print ======$data02 + return -1 +endi + +if $data03 != 5 then + print ======$data03 + return -1 +endi + +if $data04 != 2 then + print ======$data04 + return -1 +endi + +if $data05 != 3 then + print ======$data05 + return -1 +endi + +# row 1 +if $data11 != 1 then + print ======$data11 + return -1 +endi + +if $data12 != 1 then + print ======$data12 + return -1 +endi + +if $data13 != 2 then + print ======$data13 + return -1 +endi + +if $data14 != 2 then + print ======$data14 + return -1 +endi + +if $data15 != 3 then + print ======$data15 + return -1 +endi + +# row 2 +if $data21 != 1 then + print ======$data21 + return -1 +endi + +if $data22 != 1 then + print ======$data22 + return -1 +endi + +if $data23 != 3 then + print ======$data23 + return -1 +endi + +if $data24 != 2 then + print ======$data24 + return -1 +endi + +if $data25 != 3 then + print ======$data25 + return -1 +endi + +# row 3 +if $data31 != 1 then + print ======$data31 + return -1 +endi + +if $data32 != 1 then + print ======$data32 + return -1 +endi + +if $data33 != 4 then + print ======$data33 + return -1 +endi + +if $data34 != 2 then + print ======$data34 + return -1 +endi + +if $data35 != 3 then + print ======$data35 + return -1 +endi + +sql insert into t1 values(1648791223001,12,14,13,11.1); +sleep 1000 +sql select * from streamt; + +print count(*) , count(d) , sum(a) , max(b) , min(c) +print 0: $data00 , $data01 , $data02 , $data03 , $data04 , $data05 +print 1: $data10 , $data11 , $data12 , $data13 , $data14 , $data15 + +if $rows != 4 then + print ======$rows + return -1 +endi + +# row 0 +if $data01 != 2 then + print ======$data01 + return -1 +endi + +if $data02 != 2 then + print ======$data02 + return -1 +endi + +if $data03 != 5 then + print ======$data03 + return -1 +endi + +if $data04 != 2 then + print ======$data04 + return -1 +endi + +if $data05 != 3 then + print ======$data05 + return -1 +endi + +# row 1 +if $data11 != 1 then + print ======$data11 + return -1 +endi + +if $data12 != 1 then + print ======$data12 + return -1 +endi + +if $data13 != 12 then + print ======$data13 + return -1 +endi + +if $data14 != 14 then + print ======$data14 + return -1 +endi + +if $data15 != 13 then + print ======$data15 + return -1 +endi + +# row 2 +if $data21 != 1 then + print ======$data21 + return -1 +endi + +if $data22 != 1 then + print ======$data22 + return -1 +endi + +if $data23 != 3 then + print ======$data23 + return -1 +endi + +if $data24 != 2 then + print ======$data24 + return -1 +endi + +if $data25 != 3 then + print ======$data25 + return -1 +endi + +# row 3 +if $data31 != 1 then + print ======$data31 + return -1 +endi + +if $data32 != 1 then + print ======$data32 + return -1 +endi + +if $data33 != 4 then + print ======$data33 + return -1 +endi + +if $data34 != 2 then + print ======$data34 + return -1 +endi + +if $data35 != 3 then + print ======$data35 + return -1 +endi + +sql insert into t1 values(1648791223002,12,14,13,11.1); +sleep 1000 +sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; + +# row 1 +if $data11 != 2 then + print ======$data11 + return -1 +endi + +if $data12 != 2 then + print ======$data12 + return -1 +endi + +if $data13 != 24 then + print ======$data13 + return -1 +endi + +if $data14 != 14 then + print ======$data14 + return -1 +endi + +if $data15 != 13 then + print ======$data15 + return -1 +endi + +sql insert into t1 values(1648791223003,12,14,13,11.1); +sleep 1000 +sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; + +# row 1 +if $data11 != 3 then + print ======$data11 + return -1 +endi + +if $data12 != 3 then + print ======$data12 + return -1 +endi + +if $data13 != 36 then + print ======$data13 + return -1 +endi + +if $data14 != 14 then + print ======$data14 + return -1 +endi + +if $data15 != 13 then + print ======$data15 + return -1 +endi + +sql insert into t1 values(1648791223001,1,1,1,1.1); +sql insert into t1 values(1648791223002,2,2,2,2.1); +sql insert into t1 values(1648791223003,3,3,3,3.1); +sleep 1000 +sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; + +# row 1 +if $data11 != 3 then + print ======$data11 + return -1 +endi + +if $data12 != 3 then + print ======$data12 + return -1 +endi + +if $data13 != 6 then + print ======$data13 + return -1 +endi + +if $data14 != 3 then + print ======$data14 + return -1 +endi + +if $data15 != 1 then + print ======$data15 + return -1 +endi + +sql insert into t1 values(1648791233003,3,2,3,2.1); +sql insert into t1 values(1648791233002,5,6,7,8.1); +sql insert into t1 values(1648791233002,3,2,3,2.1); +sleep 1000 +sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; + +# row 2 +if $data21 != 2 then + print ======$data21 + return -1 +endi + +if $data22 != 2 then + print ======$data22 + return -1 +endi + +if $data23 != 6 then + print ======$data23 + return -1 +endi + +if $data24 != 2 then + print ======$data24 + return -1 +endi + +if $data25 != 3 then + print ======$data25 + return -1 +endi + +sql insert into t1 values(1648791213004,4,2,3,4.1) (1648791213006,5,4,7,9.1) (1648791213004,40,20,30,40.1) (1648791213005,4,2,3,4.1); +sleep 1000 +sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; + +# row 0 +if $data01 != 4 then + print ======$data01 + return -1 +endi + +if $data02 != 4 then + print ======$data02 + return -1 +endi + +if $data03 != 50 then + print ======$data03 != 50 + return -1 +endi + +if $data04 != 20 then + print ======$data04 != 20 + return -1 +endi + +if $data05 != 3 then + print ======$data05 + return -1 +endi + +sql insert into t1 values(1648791223004,4,2,3,4.1) (1648791233006,5,4,7,9.1) (1648791223004,40,20,30,40.1) (1648791233005,4,2,3,4.1); +sleep 1000 +sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; + +# row 1 +if $data11 != 4 then + print ======$data11 + return -1 +endi + +if $data12 != 4 then + print ======$data12 + return -1 +endi + +if $data13 != 46 then + print ======$data13 != 46 + return -1 +endi + +if $data14 != 20 then + print ======$data14 != 20 + return -1 +endi + +if $data15 != 1 then + print ======$data15 + return -1 +endi + +# row 2 +if $data21 != 4 then + print ======$data21 + return -1 +endi + +if $data22 != 4 then + print ======$data22 + return -1 +endi + +if $data23 != 15 then + print ======$data23 + return -1 +endi + +if $data24 != 4 then + print ======$data24 + return -1 +endi + +if $data25 != 3 then + print ======$data25 + return -1 +endi + + +sql create database test2 vgroups 1; +sql select * from information_schema.ins_databases; + +sql use test2; + +sql create table t1(ts timestamp, a int, b int , c int, d double); + +sql insert into t1 values(1648791213000,1,2,3,1.0); +sql insert into t1 values(1648791223001,2,2,3,1.1); +sql insert into t1 values(1648791233002,3,2,3,2.1); +sql insert into t1 values(1648791243003,4,2,3,3.1); +sql insert into t1 values(1648791213004,4,2,3,4.1); + +sql create stream stream2 trigger at_once fill_history 1 into streamt as select _wstart, count(*) c1, count(d) c2 , sum(a) c3 , max(b) c4, min(c) c5 from t1 interval(10s); + +sleep 5000 +sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; + +if $rows != 4 then + print ======$rows + return -1 +endi + +# row 0 +if $data01 != 2 then + print ======$data01 + return -1 +endi + +if $data02 != 2 then + print ======$data02 + return -1 +endi + +if $data03 != 5 then + print ======$data03 + return -1 +endi + +if $data04 != 2 then + print ======$data04 + return -1 +endi + +if $data05 != 3 then + print ======$data05 + return -1 +endi + +# row 1 +if $data11 != 1 then + print ======$data11 + return -1 +endi + +if $data12 != 1 then + print ======$data12 + return -1 +endi + +if $data13 != 2 then + print ======$data13 + return -1 +endi + +if $data14 != 2 then + print ======$data14 + return -1 +endi + +if $data15 != 3 then + print ======$data15 + return -1 +endi + +# row 2 +if $data21 != 1 then + print ======$data21 + return -1 +endi + +if $data22 != 1 then + print ======$data22 + return -1 +endi + +if $data23 != 3 then + print ======$data23 + return -1 +endi + +if $data24 != 2 then + print ======$data24 + return -1 +endi + +if $data25 != 3 then + print ======$data25 + return -1 +endi + +# row 3 +if $data31 != 1 then + print ======$data31 + return -1 +endi + +if $data32 != 1 then + print ======$data32 + return -1 +endi + +if $data33 != 4 then + print ======$data33 + return -1 +endi + +if $data34 != 2 then + print ======$data34 + return -1 +endi + +if $data35 != 3 then + print ======$data35 + return -1 +endi + +sql insert into t1 values(1648791223001,12,14,13,11.1); +sleep 1000 +sql select * from streamt; + +print count(*) , count(d) , sum(a) , max(b) , min(c) +print 0: $data00 , $data01 , $data02 , $data03 , $data04 , $data05 +print 1: $data10 , $data11 , $data12 , $data13 , $data14 , $data15 + +if $rows != 4 then + print ======$rows + return -1 +endi + +# row 0 +if $data01 != 2 then + print ======$data01 + return -1 +endi + +if $data02 != 2 then + print ======$data02 + return -1 +endi + +if $data03 != 5 then + print ======$data03 + return -1 +endi + +if $data04 != 2 then + print ======$data04 + return -1 +endi + +if $data05 != 3 then + print ======$data05 + return -1 +endi + +# row 1 +if $data11 != 1 then + print ======$data11 + return -1 +endi + +if $data12 != 1 then + print ======$data12 + return -1 +endi + +if $data13 != 12 then + print ======$data13 + return -1 +endi + +if $data14 != 14 then + print ======$data14 + return -1 +endi + +if $data15 != 13 then + print ======$data15 + return -1 +endi + +# row 2 +if $data21 != 1 then + print ======$data21 + return -1 +endi + +if $data22 != 1 then + print ======$data22 + return -1 +endi + +if $data23 != 3 then + print ======$data23 + return -1 +endi + +if $data24 != 2 then + print ======$data24 + return -1 +endi + +if $data25 != 3 then + print ======$data25 + return -1 +endi + +# row 3 +if $data31 != 1 then + print ======$data31 + return -1 +endi + +if $data32 != 1 then + print ======$data32 + return -1 +endi + +if $data33 != 4 then + print ======$data33 + return -1 +endi + +if $data34 != 2 then + print ======$data34 + return -1 +endi + +if $data35 != 3 then + print ======$data35 + return -1 +endi + +sql insert into t1 values(1648791223002,12,14,13,11.1); +sleep 1000 +sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; + +# row 1 +if $data11 != 2 then + print ======$data11 + return -1 +endi + +if $data12 != 2 then + print ======$data12 + return -1 +endi + +if $data13 != 24 then + print ======$data13 + return -1 +endi + +if $data14 != 14 then + print ======$data14 + return -1 +endi + +if $data15 != 13 then + print ======$data15 + return -1 +endi + +sql insert into t1 values(1648791223003,12,14,13,11.1); +sleep 1000 +sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; + +# row 1 +if $data11 != 3 then + print ======$data11 + return -1 +endi + +if $data12 != 3 then + print ======$data12 + return -1 +endi + +if $data13 != 36 then + print ======$data13 + return -1 +endi + +if $data14 != 14 then + print ======$data14 + return -1 +endi + +if $data15 != 13 then + print ======$data15 + return -1 +endi + +sql insert into t1 values(1648791223001,1,1,1,1.1); +sql insert into t1 values(1648791223002,2,2,2,2.1); +sql insert into t1 values(1648791223003,3,3,3,3.1); +sleep 1000 +sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; + +# row 1 +if $data11 != 3 then + print ======$data11 + return -1 +endi + +if $data12 != 3 then + print ======$data12 + return -1 +endi + +if $data13 != 6 then + print ======$data13 + return -1 +endi + +if $data14 != 3 then + print ======$data14 + return -1 +endi + +if $data15 != 1 then + print ======$data15 + return -1 +endi + +sql insert into t1 values(1648791233003,3,2,3,2.1); +sql insert into t1 values(1648791233002,5,6,7,8.1); +sql insert into t1 values(1648791233002,3,2,3,2.1); +sleep 1000 +sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; + +# row 2 +if $data21 != 2 then + print ======$data21 + return -1 +endi + +if $data22 != 2 then + print ======$data22 + return -1 +endi + +if $data23 != 6 then + print ======$data23 + return -1 +endi + +if $data24 != 2 then + print ======$data24 + return -1 +endi + +if $data25 != 3 then + print ======$data25 + return -1 +endi + +sql insert into t1 values(1648791213004,4,2,3,4.1) (1648791213006,5,4,7,9.1) (1648791213004,40,20,30,40.1) (1648791213005,4,2,3,4.1); +sleep 1000 +sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; + +# row 0 +if $data01 != 4 then + print ======$data01 + return -1 +endi + +if $data02 != 4 then + print ======$data02 + return -1 +endi + +if $data03 != 50 then + print ======$data03 != 50 + return -1 +endi + +if $data04 != 20 then + print ======$data04 != 20 + return -1 +endi + +if $data05 != 3 then + print ======$data05 + return -1 +endi + +sql insert into t1 values(1648791223004,4,2,3,4.1) (1648791233006,5,4,7,9.1) (1648791223004,40,20,30,40.1) (1648791233005,4,2,3,4.1); +sleep 1000 +sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt; + +# row 1 +if $data11 != 4 then + print ======$data11 + return -1 +endi + +if $data12 != 4 then + print ======$data12 + return -1 +endi + +if $data13 != 46 then + print ======$data13 != 46 + return -1 +endi + +if $data14 != 20 then + print ======$data14 != 20 + return -1 +endi + +if $data15 != 1 then + print ======$data15 + return -1 +endi + +# row 2 +if $data21 != 4 then + print ======$data21 + return -1 +endi + +if $data22 != 4 then + print ======$data22 + return -1 +endi + +if $data23 != 15 then + print ======$data23 + return -1 +endi + +if $data24 != 4 then + print ======$data24 + return -1 +endi + +if $data25 != 3 then + print ======$data25 + return -1 +endi + + diff --git a/tests/script/tsim/stream/fillHistoryBasic2.sim b/tests/script/tsim/stream/fillHistoryBasic2.sim new file mode 100644 index 0000000000000000000000000000000000000000..3af198259d2c7bb4c5c39af3acd39d222f217d1c --- /dev/null +++ b/tests/script/tsim/stream/fillHistoryBasic2.sim @@ -0,0 +1,277 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/deploy.sh -n dnode2 -i 2 + +system sh/exec.sh -n dnode1 -s start +sleep 50 +sql connect + +sql create dnode $hostname2 port 7200 + +system sh/exec.sh -n dnode2 -s start + +print ===== step1 +$x = 0 +step1: + $x = $x + 1 + sleep 1000 + if $x == 10 then + print ====> dnode not ready! + return -1 + endi +sql select * from information_schema.ins_dnodes +print ===> $data00 $data01 $data02 $data03 $data04 $data05 +print ===> $data10 $data11 $data12 $data13 $data14 $data15 +if $rows != 2 then + return -1 +endi +if $data(1)[4] != ready then + goto step1 +endi +if $data(2)[4] != ready then + goto step1 +endi + +print ===== step2 +sql drop stream if exists stream_t1; +sql drop database if exists test; +sql create database test vgroups 4; +sql use test; +sql create stable st(ts timestamp, a int, b int , c int, d double) tags(ta int,tb int,tc int); +sql create table ts1 using st tags(1,1,1); +sql create table ts2 using st tags(2,2,2); +sql create table ts3 using st tags(3,2,2); +sql create table ts4 using st tags(4,2,2); + +sql insert into ts1 values(1648791213001,1,12,3,1.0); +sql insert into ts2 values(1648791213001,1,12,3,1.0); + +sql insert into ts3 values(1648791213001,1,12,3,1.0); +sql insert into ts4 values(1648791213001,1,12,3,1.0); + +sql insert into ts1 values(1648791213002,NULL,NULL,NULL,NULL); +sql insert into ts2 values(1648791213002,NULL,NULL,NULL,NULL); + +sql insert into ts3 values(1648791213002,NULL,NULL,NULL,NULL); +sql insert into ts4 values(1648791213002,NULL,NULL,NULL,NULL); + +sql insert into ts1 values(1648791223002,2,2,3,1.1); +sql insert into ts1 values(1648791233003,3,2,3,2.1); +sql insert into ts2 values(1648791243004,4,2,43,73.1); +sql insert into ts1 values(1648791213002,24,22,23,4.1); +sql insert into ts1 values(1648791243005,4,20,3,3.1); +sql insert into ts2 values(1648791243006,4,2,3,3.1) (1648791243007,4,2,3,3.1) ; +sql insert into ts1 values(1648791243008,4,2,30,3.1) (1648791243009,4,2,3,3.1) (1648791243010,4,2,3,3.1) ; +sql insert into ts2 values(1648791243011,4,2,3,3.1) (1648791243012,34,32,33,3.1) (1648791243013,4,2,3,3.1) (1648791243014,4,2,13,3.1); +sql insert into ts1 values(1648791243005,4,42,3,3.1) (1648791243003,4,2,33,3.1) (1648791243006,4,2,3,3.1) (1648791213001,1,52,13,1.0) (1648791223001,22,22,83,1.1) ; +sql insert into ts2 values(1648791243005,4,42,3,3.1) (1648791243003,4,2,33,3.1) (1648791243006,4,2,3,3.1) (1648791213001,1,52,13,1.0) (1648791223001,22,22,83,1.1) (1648791233004,13,12,13,2.1) ; +sql insert into ts1 values(1648791243006,4,2,3,3.1) (1648791213001,1,52,13,1.0) (1648791223001,22,22,83,1.1) ; + +sql insert into ts3 values(1648791223002,2,2,3,1.1); +sql insert into ts4 values(1648791233003,3,2,3,2.1); +sql insert into ts3 values(1648791243004,4,2,43,73.1); +sql insert into ts4 values(1648791213002,24,22,23,4.1); +sql insert into ts3 values(1648791243005,4,20,3,3.1); +sql insert into ts4 values(1648791243006,4,2,3,3.1) (1648791243007,4,2,3,3.1) ; +sql insert into ts3 values(1648791243008,4,2,30,3.1) (1648791243009,4,2,3,3.1) (1648791243010,4,2,3,3.1) ; +sql insert into ts4 values(1648791243011,4,2,3,3.1) (1648791243012,34,32,33,3.1) (1648791243013,4,2,3,3.1) (1648791243014,4,2,13,3.1); +sql insert into ts3 values(1648791243005,4,42,3,3.1) (1648791243003,4,2,33,3.1) (1648791243006,4,2,3,3.1) (1648791213001,1,52,13,1.0) (1648791223001,22,22,83,1.1) ; +sql insert into ts4 values(1648791243005,4,42,3,3.1) (1648791243003,4,2,33,3.1) (1648791243006,4,2,3,3.1) (1648791213001,1,52,13,1.0) (1648791223001,22,22,83,1.1) (1648791233004,13,12,13,2.1) ; +sql insert into ts3 values(1648791243006,4,2,3,3.1) (1648791213001,1,52,13,1.0) (1648791223001,22,22,83,1.1) ; + +sql create stream stream_t1 trigger at_once fill_history 1 watermark 1d into streamtST1 as select _wstart, count(*) c1, count(d) c2 , sum(a) c3 , max(b) c4, min(c) c5 from st interval(10s); + +sleep 1000 + +$loop_count = 0 +loop1: +sleep 300 +sql select * from streamtST1; + +$loop_count = $loop_count + 1 +if $loop_count == 10 then + return -1 +endi + +# row 0 +if $data01 != 8 then + print =====data01=$data01 + goto loop1 +endi + +if $data02 != 6 then + print =====data02=$data02 + goto loop1 +endi + +if $data03 != 52 then + print ======data03=$data03 + goto loop1 +endi + +if $data04 != 52 then + print ======data04=$data04 + goto loop1 +endi + +if $data05 != 13 then + print ======data05=$data05 + goto loop1 +endi + +# row 1 +if $data11 != 6 then + print =====data11=$data11 + goto loop1 +endi + +if $data12 != 6 then + print =====data12=$data12 + goto loop1 +endi + +if $data13 != 92 then + print ======$data13 + return -1 +endi + +if $data14 != 22 then + print ======$data14 + return -1 +endi + +if $data15 != 3 then + print ======$data15 + return -1 +endi + +# row 2 +if $data21 != 4 then + print =====data21=$data21 + goto loop1 +endi + +if $data22 != 4 then + print =====data22=$data22 + goto loop1 +endi + +if $data23 != 32 then + print ======$data23 + return -1 +endi + +if $data24 != 12 then + print ======$data24 + return -1 +endi + +if $data25 != 3 then + print ======$data25 + return -1 +endi + +# row 3 +if $data31 != 30 then + print =====data31=$data31 + goto loop1 +endi + +if $data32 != 30 then + print =====data32=$data32 + goto loop1 +endi + +if $data33 != 180 then + print ======$data33 + return -1 +endi + +if $data34 != 42 then + print ======$data34 + return -1 +endi + +if $data35 != 3 then + print ======$data35 + return -1 +endi + +sql select _wstart, count(*) c1, count(d) c2 , sum(a) c3 , max(b) c4, min(c) c5, avg(d) from st interval(10s); + + +sql create database test1 vgroups 4; +sql use test1; +sql create stable st(ts timestamp, a int, b int , c int) tags(ta int,tb int,tc int); +sql create table ts1 using st tags(1,1,1); +sql create table ts2 using st tags(2,2,2); + +sql insert into ts1 values(1648791211000,1,2,3); +sql insert into ts1 values(1648791222001,2,2,3); +sql insert into ts2 values(1648791211000,1,2,3); +sql insert into ts2 values(1648791222001,2,2,3); + +sql create stream stream_t2 trigger at_once fill_history 1 watermark 20s into streamtST1 as select _wstart, count(*) c1, count(a) c2 , sum(a) c3 , max(b) c5, min(c) c6 from st interval(10s) ; + +$loop_count = 0 +loop2: +sql select * from streamtST1; + +sleep 300 +$loop_count = $loop_count + 1 +if $loop_count == 10 then + return -1 +endi + +# row 0 +if $data01 != 2 then + print =====data01=$data01 + goto loop2 +endi + +#rows 1 +if $data11 != 2 then + print =====data11=$data11 + goto loop2 +endi + +#max,min selectivity +sql create database test3 vgroups 4; +sql use test3; +sql create stable st(ts timestamp, a int, b int , c int) tags(ta int,tb int,tc int); +sql create table ts1 using st tags(1,1,1); +sql create table ts2 using st tags(2,2,2); +sql create stream stream_t3 trigger at_once into streamtST3 as select ts, min(a) c6, a, b, c, ta, tb, tc from st interval(10s) ; + +sql insert into ts1 values(1648791211000,1,2,3); +sleep 50 +sql insert into ts1 values(1648791222001,2,2,3); +sleep 50 +sql insert into ts2 values(1648791211000,1,2,3); +sleep 50 +sql insert into ts2 values(1648791222001,2,2,3); +sleep 50 + +$loop_count = 0 +loop3: +sql select * from streamtST3; + +sleep 300 +$loop_count = $loop_count + 1 +if $loop_count == 10 then + return -1 +endi + +# row 0 +if $data02 != 1 then + print =====data02=$data02 + goto loop3 +endi + +# row 1 +if $data12 != 2 then + print =====data12=$data12 + goto loop3 +endi + +system sh/stop_dnodes.sh diff --git a/tests/script/tsim/stream/fillHistoryBasic3.sim b/tests/script/tsim/stream/fillHistoryBasic3.sim new file mode 100644 index 0000000000000000000000000000000000000000..db8d6bc2d0ac7ae9b8c5d182b3d6eea63c02c7dd --- /dev/null +++ b/tests/script/tsim/stream/fillHistoryBasic3.sim @@ -0,0 +1,203 @@ +$loop_all = 0 +looptest: + +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sleep 50 +sql connect + +sql create database test vgroups 1; +sql create database test2 vgroups 4; +sql use test2; +sql create stable st(ts timestamp, a int, b int, c int, d double) tags(ta int,tb int,tc int); +sql create table t1 using st tags(1,1,1); +sql create table t2 using st tags(2,2,2); + +sql insert into t1 values(1648791213000,NULL,NULL,NULL,NULL); +sql insert into t2 values(1648791213000,NULL,NULL,NULL,NULL); + +sql create stream streams2 trigger at_once fill_history 1 into test.streamt2 as select _wstart c1, count(*) c2, max(a) c3 from st partition by a interval(10s); + +sleep 3000 + +$loop_count = 0 + +loop7: +sleep 50 +sql select * from test.streamt2 order by c1, c2, c3; + +$loop_count = $loop_count + 1 +if $loop_count == 20 then + return -1 +endi + +if $data01 != 2 then + print =====data01=$data01 + goto loop7 +endi + +if $data02 != NULL then + print =====data02=$data02 + goto loop7 +endi + +sql insert into t1 values(1648791213000,1,2,3,1.0); +sql insert into t2 values(1648791213000,1,2,3,1.0); + +$loop_count = 0 + +loop8: +sleep 50 +sql select * from test.streamt2 order by c1, c2, c3; + +$loop_count = $loop_count + 1 +if $loop_count == 20 then + return -1 +endi + +if $data01 != 2 then + print =====data01=$data01 + goto loop8 +endi + +if $data02 != 1 then + print =====data02=$data02 + goto loop8 +endi + +sql insert into t1 values(1648791213000,2,2,3,1.0); +sql insert into t2 values(1648791213000,2,2,3,1.0); + +$loop_count = 0 + +loop9: +sleep 50 +sql select * from test.streamt2 order by c1, c2, c3; + +$loop_count = $loop_count + 1 +if $loop_count == 20 then + return -1 +endi + +if $data01 != 2 then + print =====data01=$data01 + goto loop9 +endi + +if $data02 != 2 then + print =====data02=$data02 + goto loop9 +endi + +sql insert into t1 values(1648791213000,2,2,3,1.0); +sql insert into t1 values(1648791213001,2,2,3,1.0); +sql insert into t1 values(1648791213002,2,2,3,1.0); +sql insert into t1 values(1648791213002,1,2,3,1.0); +sql insert into t2 values(1648791213000,2,2,3,1.0); +sql insert into t2 values(1648791213001,2,2,3,1.0); +sql insert into t2 values(1648791213002,2,2,3,1.0); +sql insert into t2 values(1648791213002,1,2,3,1.0); + +$loop_count = 0 + +loop10: +sleep 50 +sql select * from test.streamt2 order by c1, c2, c3; + +$loop_count = $loop_count + 1 +if $loop_count == 20 then + return -1 +endi + +if $data01 != 2 then + print =====data01=$data01 + goto loop10 +endi + +if $data02 != 1 then + print =====data02=$data02 + goto loop10 +endi + +if $data11 != 4 thenloop4 + print =====data11=$data11 + goto loop10 +endi + +if $data12 != 2 then + print =====data12=$data12 + goto loop10 +endi + +sql insert into t1 values(1648791223000,1,2,3,1.0); +sql insert into t1 values(1648791223001,1,2,3,1.0); +sql insert into t1 values(1648791223002,3,2,3,1.0); +sql insert into t1 values(1648791223003,3,2,3,1.0); +sql insert into t1 values(1648791213001,1,2,3,1.0) (1648791223001,2,2,3,1.0) (1648791223003,1,2,3,1.0); +sql insert into t2 values(1648791223000,1,2,3,1.0); +sql insert into t2 values(1648791223001,1,2,3,1.0); +sql insert into t2 values(1648791223002,3,2,3,1.0); +sql insert into t2 values(1648791223003,3,2,3,1.0); +sql insert into t2 values(1648791213001,1,2,3,1.0) (1648791223001,2,2,3,1.0) (1648791223003,1,2,3,1.0); + +$loop_count = 0 + +loop11: +sleep 50 +sql select * from test.streamt2 order by c1, c2, c3; + +$loop_count = $loop_count + 1 +if $loop_count == 20 then + return -1 +endi + +if $data01 != 2 then + print =====data01=$data01 + goto loop11 +endi + +if $data02 != 2 then + print =====data02=$data02 + goto loop11 +endi + +if $data11 != 4 then + print =====data11=$data11 + goto loop11 +endi + +if $data12 != 1 then + print =====data12=$data12 + goto loop11 +endi + +if $data21 != 2 then + print =====data21=$data21 + goto loop11 +endi + +if $data22 != 2 then + print =====data22=$data22 + goto loop11 +endi + +if $data31 != 2 then + print =====data31=$data31 + goto loop11 +endi + +if $data32 != 3 then + print =====data32=$data32 + goto loop11 +endi + +if $data41 != 4 then + print =====data41=$data41 + goto loop11 +endi + +if $data42 != 1 then + print =====data42=$data42 + goto loop11 +endi diff --git a/tests/script/tsim/stream/partitionbyColumnInterval.sim b/tests/script/tsim/stream/partitionbyColumnInterval.sim index 8375df5064c8bc591c601f1b46d9fac4e87f021e..2e57e8d699ec1b04a303c4888083a3408130b724 100644 --- a/tests/script/tsim/stream/partitionbyColumnInterval.sim +++ b/tests/script/tsim/stream/partitionbyColumnInterval.sim @@ -599,12 +599,62 @@ if $loop_count == 20 then endi if $rows != 4 then - print =====rows=$rows - print =====rows=$rows - print =====rows=$rows - #goto loop15 + print ======rows=$rows + goto loop15 +endi + +sql insert into t1 values(1648791223001,11,2,3,1.0); +sql insert into t2 values(1648791223001,21,2,3,1.0); +sql insert into t3 values(1648791223001,31,2,3,1.0); +sql insert into t4 values(1648791223001,41,2,3,1.0); + +sleep 300 + +sql delete from st where ts = 1648791223001; + +$loop_count = 0 + +loop16: +sleep 50 +sql select * from test.streamt5 order by c1, c2, c3; + +$loop_count = $loop_count + 1 +if $loop_count == 20 then + print ======rows=$rows + return -1 +endi + +if $rows != 4 then + goto loop16 +endi + +sql insert into t1 values(1648791223001,12,2,3,1.0); +sql insert into t2 values(1648791223001,22,2,3,1.0); +sql insert into t3 values(1648791223001,32,2,3,1.0); +sql insert into t4 values(1648791223001,42,2,3,1.0); + +sleep 300 + +sql delete from st where ts = 1648791223001; + +$loop_count = 0 + +loop17: +sleep 50 +sql select * from test.streamt5 order by c1, c2, c3; + +$loop_count = $loop_count + 1 +if $loop_count == 20 then + return -1 endi +if $rows != 4 then + print ======rows=$rows + print ======rows=$rows + print ======rows=$rows + return 1 + #goto loop17 +endi $loop_all = $loop_all + 1 print ============loop_all=$loop_all diff --git a/tests/script/tsim/stream/scalar.sim b/tests/script/tsim/stream/scalar.sim new file mode 100644 index 0000000000000000000000000000000000000000..e211357276eef87101244bd9a1376c0446edffa1 --- /dev/null +++ b/tests/script/tsim/stream/scalar.sim @@ -0,0 +1,94 @@ +$loop_all = 0 +looptest: + +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sleep 50 +sql connect + +sql drop database if exists test; +sql create database test vgroups 1; +sql use test; +sql create stable st(ts timestamp,a int,b int,c int, d double) tags(ta int,tb int,tc int); +sql create table t1 using st tags(1,1,1); +sql create table t2 using st tags(2,2,2); +sql create stream streams0 into streamt0 as select ts c1, a, abs(b) c4 from t1 partition by a; +sql create stream streams1 into streamt1 as select ts c1, a, abs(b) c4 from t1; +sql create stream streams2 into streamt2 as select ts c1, a, abs(b) c4 from st partition by tbname; + +sql insert into t1 values(1648791213000,1,1,1,1); +sql insert into t1 values(1648791213001,1,1,1,1); +sql insert into t1 values(1648791213002,1,1,1,1); + +sql insert into t2 values(1648791213000,1,2,2,2); +sql insert into t2 values(1648791213001,1,1,1,1); +sql insert into t2 values(1648791213002,1,1,1,1); + +sql insert into t1 values(1648791213001,2,11,11,11); + + +$loop_count = 0 +loop1: + +sleep 200 + +sql select * from streamt0 order by a desc; + +$loop_count = $loop_count + 1 + +if $loop_count == 10 then + return -1 +endi + +if $rows != 3 then + print ======streamt0=rows=$rows + goto loop1 +endi + +if $data01 != 2 then + print ======streamt0=data01=$data01 + goto loop1 +endi + +if $data02 != 11 then + print ======streamt0=data02=$data02 + goto loop1 +endi + + +sql select * from streamt1 order by a desc; + +if $rows != 3 then + print ======streamt1=rows=$rows + goto loop1 +endi + +if $data01 != 2 then + print ======streamt1=data01=$data01 + goto loop1 +endi + +if $data02 != 11 then + print ======streamt1=data02=$data02 + goto loop1 +endi + +sql select * from streamt2 order by a desc; + +if $rows != 6 then + print ======streamt2=rows=$rows + goto loop1 +endi + +if $data01 != 2 then + print ======streamt2=data01=$data01 + goto loop1 +endi + +if $data02 != 11 then + print ======streamt2=data02=$data02 + goto loop1 +endi + +system sh/stop_dnodes.sh \ No newline at end of file diff --git a/tests/script/tsim/stream/schedSnode.sim b/tests/script/tsim/stream/schedSnode.sim index 61f01baf399b0fa4aad3adee9e006ecda60a72a5..2caecf50a202db447b6b45e37ce99cd50ed4ec7f 100644 --- a/tests/script/tsim/stream/schedSnode.sim +++ b/tests/script/tsim/stream/schedSnode.sim @@ -6,10 +6,14 @@ system sh/exec.sh -n dnode1 -s start sleep 50 sql connect -sql create snode on dnode 1 +sleep 50 + -sql create database test vgroups 1; +sql create database test vgroups 2; sql create database target vgroups 1; + +sql create snode on dnode 1 + sql use test; sql create stable st(ts timestamp, a int, b int , c int, d double) tags(ta int,tb int,tc int); sql create table ts1 using st tags(1,1,1); @@ -72,23 +76,23 @@ if $data01 != 8 then goto loop1 endi -if $data02 != 4 then +if $data02 != 6 then print =====data02=$data02 goto loop1 endi -if $data03 != 4 then - print ======$data03 +if $data03 != 52 then + print ======data03=$data03 goto loop1 endi if $data04 != 52 then - print ======$data04 + print ======data04=$data04 goto loop1 endi if $data05 != 13 then - print ======$data05 + print ======data05=$data05 goto loop1 endi @@ -104,17 +108,17 @@ if $data12 != 6 then endi if $data13 != 92 then - print ======$data13 + print ======data13=$data13 return -1 endi if $data14 != 22 then - print ======$data14 + print ======data14=$data14 return -1 endi if $data15 != 3 then - print ======$data15 + print ======data15=$data15 return -1 endi @@ -130,17 +134,17 @@ if $data22 != 4 then endi if $data23 != 32 then - print ======$data23 + print ======data23=$data23 return -1 endi if $data24 != 12 then - print ======$data24 + print ======data24=$data24 return -1 endi if $data25 != 3 then - print ======$data25 + print ======data25=$data25 return -1 endi @@ -156,17 +160,17 @@ if $data32 != 30 then endi if $data33 != 180 then - print ======$data33 + print ======data33=$data33 return -1 endi if $data34 != 42 then - print ======$data34 + print ======data34=$data34 return -1 endi if $data35 != 3 then - print ======$data35 + print ======data35=$data35 return -1 endi diff --git a/tests/script/tsim/stream/session0.sim b/tests/script/tsim/stream/session0.sim index afae8ef5da64d6d54b28b8898fbe9a5a973620fc..5e95428e0a2d34adaf830fc74019e320513d2586 100644 --- a/tests/script/tsim/stream/session0.sim +++ b/tests/script/tsim/stream/session0.sim @@ -201,7 +201,7 @@ if $loop_count == 10 then endi if $rows != 1 then - print ======$rows + print =====rows=$rows goto loop2 endi diff --git a/tests/script/tsim/tag/tbNameIn.sim b/tests/script/tsim/tag/tbNameIn.sim new file mode 100644 index 0000000000000000000000000000000000000000..1af4bd6a9e34dbb33298ddcab5c28d0d1b716745 --- /dev/null +++ b/tests/script/tsim/tag/tbNameIn.sim @@ -0,0 +1,102 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sql connect + +print ======== step1 +sql drop database if exists db1; +sql create database db1 vgroups 3; +sql use db1; +sql create stable st1 (ts timestamp, f1 int) tags(tg1 int); +sql create table tb1 using st1 tags(1); +sql create table tb2 using st1 tags(2); +sql create table tb3 using st1 tags(3); +sql create table tb4 using st1 tags(4); +sql create table tb5 using st1 tags(5); +sql create table tb6 using st1 tags(6); +sql create table tb7 using st1 tags(7); +sql create table tb8 using st1 tags(8); + +sql insert into tb1 values ('2022-07-10 16:31:01', 1); +sql insert into tb2 values ('2022-07-10 16:31:02', 2); +sql insert into tb3 values ('2022-07-10 16:31:03', 3); +sql insert into tb4 values ('2022-07-10 16:31:04', 4); +sql insert into tb5 values ('2022-07-10 16:31:05', 5); +sql insert into tb6 values ('2022-07-10 16:31:06', 6); +sql insert into tb7 values ('2022-07-10 16:31:07', 7); +sql insert into tb8 values ('2022-07-10 16:31:08', 8); + +sql select * from tb1 where tbname in ('tb1'); +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from tb1 where tbname in ('tb1','tb1'); +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from tb1 where tbname in ('tb1','tb2','tb1'); +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from tb1 where tbname in ('tb1','tb2','st1'); +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from tb1 where tbname = 'tb1'; +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from tb1 where tbname > 'tb1'; +if $rows != 0 then + return -1 +endi +sql select * from st1 where tbname in ('tb1'); +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from st1 where tbname in ('tb1','tb1'); +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from st1 where tbname in ('tb1','tb2','tb1'); +if $rows != 2 then + return -1 +endi +sql select * from st1 where tbname in ('tb1','tb2','st1'); +if $rows != 2 then + return -1 +endi +sql select * from st1 where tbname = 'tb1'; +if $rows != 1 then + return -1 +endi +if $data01 != 1 then + return -1 +endi +sql select * from st1 where tbname > 'tb1'; +if $rows != 7 then + return -1 +endi + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/vnode/replica3_many.sim b/tests/script/tsim/vnode/replica3_many.sim index 00bce3017a6622fe4482233f0a3f8fda04c607f6..fbce960b09cd8548dbad40a6cedb979945ca0c2f 100644 --- a/tests/script/tsim/vnode/replica3_many.sim +++ b/tests/script/tsim/vnode/replica3_many.sim @@ -59,7 +59,7 @@ step12: print ====> db not ready! return -1 endi -sql show d1.vgroups +sql show db1.vgroups print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 $leaderExist = 0 if $rows != 1 then @@ -87,19 +87,19 @@ step13: print ====> db not ready! return -1 endi -sql show d1.vgroups +sql show db1.vgroups print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 $leaderExist = 0 if $rows != 1 then return -1 endi -if $data(3)[4] == leader then +if $data(2)[4] == leader then $leaderExist = 1 endi -if $data(3)[6] == leader then +if $data(2)[6] == leader then $leaderExist = 1 endi -if $data(3)[8] == leader then +if $data(2)[8] == leader then $leaderExist = 1 endi if $leaderExist != 1 then @@ -115,16 +115,16 @@ step14: print ====> db not ready! return -1 endi -sql show d1.vgroups +sql show db1.vgroups print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 $leaderExist = 0 -if $data(4)[4] == leader then +if $data(2)[4] == leader then $leaderExist = 1 endi -if $data(4)[6] == leader then +if $data(2)[6] == leader then $leaderExist = 1 endi -if $data(4)[8] == leader then +if $data(2)[8] == leader then $leaderExist = 1 endi if $leaderExist != 1 then @@ -140,16 +140,16 @@ step15: print ====> db not ready! return -1 endi -sql show d1.vgroups +sql show db1.vgroups print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 $leaderExist = 0 -if $data(4)[4] == leader then +if $data(2)[4] == leader then $leaderExist = 1 endi -if $data(4)[6] == leader then +if $data(2)[6] == leader then $leaderExist = 1 endi -if $data(4)[8] == leader then +if $data(2)[8] == leader then $leaderExist = 1 endi if $leaderExist != 1 then diff --git a/tests/script/tsim/vnode/replica3_repeat.sim b/tests/script/tsim/vnode/replica3_repeat.sim index 83b0ccedb7dafe5e616092dd883a696e9fe80164..8efba515ae5778afdf6cd3f36079d4426741601d 100644 --- a/tests/script/tsim/vnode/replica3_repeat.sim +++ b/tests/script/tsim/vnode/replica3_repeat.sim @@ -56,7 +56,7 @@ step1: endi sql show db.vgroups print ===> $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09 -if $rows != 4 then +if $rows != 1 then return -1 endi if $data(2)[4] == leader then @@ -107,9 +107,18 @@ system sh/exec.sh -n dnode2 -s stop sleep 3000 print ======== step7 -sql select count(*) from db.tb +$x = 0 +step7: + $x = $x + 1 + sleep 1000 + if $x == 30 then + print ====> dnode not ready! + return -1 + endi +sql select count(*) from db.tb -x step7 + print select count(*) from db.tb ==> $data00 $lastRows -if $data00 <= $lastRows then +if $data00 < $lastRows then return -1 endi diff --git a/tests/system-test/0-others/cachemodel.py b/tests/system-test/0-others/cachemodel.py index 42c52a2f3c241eea3460fda7fa0b7f7102acb451..a8efd0d719b9040dfc730dfdf66225ae29e5d7e2 100644 --- a/tests/system-test/0-others/cachemodel.py +++ b/tests/system-test/0-others/cachemodel.py @@ -14,7 +14,8 @@ class TDTestCase: updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), True) diff --git a/tests/system-test/0-others/compa4096.json b/tests/system-test/0-others/compa4096.json new file mode 100644 index 0000000000000000000000000000000000000000..5cc5d2084dd52ccc198446698f9a745664aeb054 --- /dev/null +++ b/tests/system-test/0-others/compa4096.json @@ -0,0 +1,76 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "localhost", + "port": 6030, + "rest_port": 6041, + "user": "root", + "password": "taosdata", + "thread_count": 100, + "create_table_thread_count": 24, + "result_file": "taosBenchmark_result.log", + "confirm_parameter_prompt": "no", + "insert_interval": 0, + "num_of_records_per_req": 1000000, + "max_sql_len": 1024000, + "databases": [ + { + "dbinfo": { + "name": "db4096", + "drop": "yes", + "replica": 1, + "duration": 10, + "precision": "ms", + "keep": 3650, + "comp": 2, + "vgroups": 2, + "buffer": 1000 + }, + "super_tables": [ + { + "name": "stb0", + "child_table_exists": "no", + "childtable_count": 5, + "childtable_prefix": "ctb0", + "escape_character": "no", + "auto_create_table": "no", + "batch_create_tbl_num": 500, + "data_source": "rand", + "insert_mode": "taosc", + "rollup": null, + "interlace_rows": 0, + "line_protocol": null, + "tcp_transfer": "no", + "insert_rows": 10000, + "childtable_limit": 0, + "childtable_offset": 0, + "rows_per_tbl": 0, + "max_sql_len": 1048576, + "disorder_ratio": 0, + "disorder_range": 1000, + "timestamp_step": 1000, + "start_timestamp": "2022-10-22 17:20:36", + "sample_format": "csv", + "sample_file": "./sample.csv", + "tags_file": "", + "columns": [ + { + "type": "INT", + "count": 4094 + } + ], + "tags": [ + { + "type": "TINYINT", + "count": 1 + } + ] + } + ] + } + ], + "prepare_rand": 10000, + "chinese": "no", + "streams": false, + "test_log": "/root/testlog/" +} diff --git a/tests/system-test/0-others/compatibility.py b/tests/system-test/0-others/compatibility.py index e81579a9e4ca3f2f72b9aff3892f1ed2878855a1..30513ac020b6f41cad58d1284673d2ebb46e9792 100644 --- a/tests/system-test/0-others/compatibility.py +++ b/tests/system-test/0-others/compatibility.py @@ -22,7 +22,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) @@ -92,6 +93,7 @@ class TDTestCase: oldServerVersion=tdsqlF.queryResult[0][0] tdLog.info(f"Base server version is {oldServerVersion}") tdsqlF.query(f"SELECT CLIENT_VERSION();") + # the oldClientVersion can't be updated in the same python process,so the version is new compiled verison oldClientVersion=tdsqlF.queryResult[0][0] tdLog.info(f"Base client version is {oldClientVersion}") @@ -104,7 +106,16 @@ class TDTestCase: # tdsqlF.query(f"select count(*) from {stb}") # tdsqlF.checkData(0,0,tableNumbers*recordNumbers1) os.system("pkill taosd") - sleep(1) + sleep(2) + + print(f"start taosd: nohup taosd -c {cPath} & ") + os.system(f" nohup taosd -c {cPath} & " ) + sleep(10) + tdLog.info(" LD_LIBRARY_PATH=/usr/lib taosBenchmark -f 0-others/compa4096.json -y ") + os.system("LD_LIBRARY_PATH=/usr/lib taosBenchmark -f 0-others/compa4096.json -y") + os.system("pkill -9 taosd") + + tdLog.printNoPrefix("==========step2:update new version ") self.buildTaosd(bPath) diff --git a/tests/system-test/0-others/fsync.py b/tests/system-test/0-others/fsync.py index 6eefc3db24be8f47bce1b362d8b97f5550cbb461..04a9f5c9413ac03f12f5e2e2db035ef0016787ae 100644 --- a/tests/system-test/0-others/fsync.py +++ b/tests/system-test/0-others/fsync.py @@ -26,7 +26,8 @@ TS_TYPE_COL = [ TS_COL, ] class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/0-others/show.py b/tests/system-test/0-others/show.py index c25d1d1f33ba98c2fb7bb6924f7a24c55b81e744..b5d6a0d1a34e570c2ffe0f61d67538f2ec881dfd 100644 --- a/tests/system-test/0-others/show.py +++ b/tests/system-test/0-others/show.py @@ -20,7 +20,8 @@ from util.sqlset import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.setsql = TDSetSql() diff --git a/tests/system-test/0-others/sysinfo.py b/tests/system-test/0-others/sysinfo.py index a4716dd5444efa6d6644b03c0e5e2ab10aa1a0b1..4ddae42ac5498263245c9cf38046881f17719d2f 100644 --- a/tests/system-test/0-others/sysinfo.py +++ b/tests/system-test/0-others/sysinfo.py @@ -20,7 +20,8 @@ from util.common import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.dbname = 'db' diff --git a/tests/system-test/0-others/taosShell.py b/tests/system-test/0-others/taosShell.py index 879d78e7ac12271e5d5fc859d9782f11962e08d5..e3095e8b934cabeda50ad9b7976a5418512cef6a 100644 --- a/tests/system-test/0-others/taosShell.py +++ b/tests/system-test/0-others/taosShell.py @@ -108,7 +108,8 @@ class TDTestCase: print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/0-others/taosShellError.py b/tests/system-test/0-others/taosShellError.py index 0dca5ff40f6cea3ccdd65783dd5d8f2246eb258f..5e6a590806a963554afc6d9febef4d0f7c6106d0 100644 --- a/tests/system-test/0-others/taosShellError.py +++ b/tests/system-test/0-others/taosShellError.py @@ -110,7 +110,8 @@ class TDTestCase: print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/0-others/taosShellNetChk.py b/tests/system-test/0-others/taosShellNetChk.py index 80f6a6bc3007bdb2f5a2dfaca2b0fe71d9ea2042..781fcae63898cf55579f7082cec92547f9907fe2 100644 --- a/tests/system-test/0-others/taosShellNetChk.py +++ b/tests/system-test/0-others/taosShellNetChk.py @@ -110,7 +110,8 @@ class TDTestCase: print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/0-others/taosdMonitor.py b/tests/system-test/0-others/taosdMonitor.py index 96e057c9f815b19a20ef98b87d58c3ec7fdfe51d..944ff52d5bacf386369c80b8561229f48d554008 100644 --- a/tests/system-test/0-others/taosdMonitor.py +++ b/tests/system-test/0-others/taosdMonitor.py @@ -284,7 +284,8 @@ class TDTestCase: print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/0-others/taosdShell.py b/tests/system-test/0-others/taosdShell.py index e09c8edce957915b60fe24864599c7f41800308c..b743783a4f42e067365abd6e2561fba36ad57d84 100644 --- a/tests/system-test/0-others/taosdShell.py +++ b/tests/system-test/0-others/taosdShell.py @@ -44,7 +44,8 @@ class TDTestCase: # print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) @@ -90,7 +91,7 @@ class TDTestCase: break else: tdLog.info( "wait start taosd ,times: %d "%i) - sleep + time.sleep(1) i+= 1 else : tdLog.exit("taosd %s is not running "%startAction) @@ -134,7 +135,11 @@ class TDTestCase: tdSql.query("create stream s1 into source_db.output_stb as select _wstart AS start, min(k), max(k), sum(k) from source_db.stb interval(10m);") + #TD-19944 -Q=3 + tdsqlN=tdCom.newTdSql() + tdsqlN.query("select * from source_db.stb") + tdsqlN.query("select * from db0.stb") def run(self): # tdSql.prepare() @@ -164,6 +169,7 @@ class TDTestCase: startAction = " -s -c " + taosdCfgPath tdLog.printNoPrefix("================================ parameter: %s"%startAction) self.taosdCommandExe(startAction,taosdCmdRun) + os.system(" rm -rf sdb.json ") startAction = " --help" @@ -198,7 +204,7 @@ class TDTestCase: startAction=" -E taosdCaseTmp/.env" tdLog.printNoPrefix("================================ parameter: %s"%startAction) - os.system(" mkdir -p taosdCaseTmp/.env ") + os.system(" mkdir -p taosdCaseTmp ") os.system("echo \'TAOS_QUERY_POLICY=3\' > taosdCaseTmp/.env ") self.taosdCommandStop(startAction,taosdCmdRun) os.system(" rm -rf taosdCaseTmp/.env ") diff --git a/tests/system-test/0-others/taosdlog.py b/tests/system-test/0-others/taosdlog.py index bd3d6b9b4c0a97f72bac88e6626d00b4591b6abe..d4698960cd87ea2ec43d3dd83e94bbb9829e59a6 100644 --- a/tests/system-test/0-others/taosdlog.py +++ b/tests/system-test/0-others/taosdlog.py @@ -10,7 +10,8 @@ from util.dnodes import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/0-others/telemetry.py b/tests/system-test/0-others/telemetry.py index 812b8b40c54a30fc478c18eb220639d9ef8117a3..bc5d276faa92e2ec6226a7b36c4ac5b0b3d46420 100644 --- a/tests/system-test/0-others/telemetry.py +++ b/tests/system-test/0-others/telemetry.py @@ -173,7 +173,8 @@ class TDTestCase: print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/0-others/udfTest.py b/tests/system-test/0-others/udfTest.py index c4c40348b8b5bd5e75b62ba1c914f2e7f0e29c8b..15253df0c4eda40378ed2c875f01a8448f73003d 100644 --- a/tests/system-test/0-others/udfTest.py +++ b/tests/system-test/0-others/udfTest.py @@ -13,7 +13,8 @@ import subprocess class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), logSql) @@ -279,7 +280,6 @@ class TDTestCase: tdSql.error("select udf1(num1) , irate(num1) from tb;") tdSql.error("select udf1(num1) , sum(num1) from tb;") tdSql.error("select udf1(num1) , stddev(num1) from tb;") - tdSql.error("select udf1(num1) , mode(num1) from tb;") tdSql.error("select udf1(num1) , HYPERLOGLOG(num1) from tb;") # stable tdSql.error("select udf1(c1) , count(c1) from stb1;") @@ -288,7 +288,6 @@ class TDTestCase: tdSql.error("select udf1(c1) , irate(c1) from stb1;") tdSql.error("select udf1(c1) , sum(c1) from stb1;") tdSql.error("select udf1(c1) , stddev(c1) from stb1;") - tdSql.error("select udf1(c1) , mode(c1) from stb1;") tdSql.error("select udf1(c1) , HYPERLOGLOG(c1) from stb1;") # regular table with select functions diff --git a/tests/system-test/0-others/udf_cfg1.py b/tests/system-test/0-others/udf_cfg1.py index e6ab57b4882e5d66de0560d29908b54bb93e5357..35d43ea9b73eedc7b9432cf0590d90927ad2932c 100644 --- a/tests/system-test/0-others/udf_cfg1.py +++ b/tests/system-test/0-others/udf_cfg1.py @@ -15,7 +15,8 @@ class TDTestCase: updatecfgDict = {'debugFlag': 143, "cDebugFlag": 143, "uDebugFlag": 143, "rpcDebugFlag": 143, "tmrDebugFlag": 143, "jniDebugFlag": 143, "simDebugFlag": 143, "dDebugFlag": 143, "dDebugFlag": 143, "vDebugFlag": 143, "mDebugFlag": 143, "qDebugFlag": 143, "wDebugFlag": 143, "sDebugFlag": 143, "tsdbDebugFlag": 143, "tqDebugFlag": 143, "fsDebugFlag": 143, "fnDebugFlag": 143 ,"udf":0} - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), logSql) diff --git a/tests/system-test/0-others/udf_cfg2.py b/tests/system-test/0-others/udf_cfg2.py index 3f8ba37491edd4c15e41c7903d2fb942009b36c2..869cb098e2e0415acf931179dc4e6887aa781f4a 100644 --- a/tests/system-test/0-others/udf_cfg2.py +++ b/tests/system-test/0-others/udf_cfg2.py @@ -15,7 +15,8 @@ class TDTestCase: updatecfgDict = {'debugFlag': 143, "cDebugFlag": 143, "uDebugFlag": 143, "rpcDebugFlag": 143, "tmrDebugFlag": 143, "jniDebugFlag": 143, "simDebugFlag": 143, "dDebugFlag": 143, "dDebugFlag": 143, "vDebugFlag": 143, "mDebugFlag": 143, "qDebugFlag": 143, "wDebugFlag": 143, "sDebugFlag": 143, "tsdbDebugFlag": 143, "tqDebugFlag": 143, "fsDebugFlag": 143, "fnDebugFlag": 143 ,"udf":1} - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), logSql) @@ -281,7 +282,6 @@ class TDTestCase: tdSql.error("select udf1(num1) , irate(num1) from tb;") tdSql.error("select udf1(num1) , sum(num1) from tb;") tdSql.error("select udf1(num1) , stddev(num1) from tb;") - tdSql.error("select udf1(num1) , mode(num1) from tb;") tdSql.error("select udf1(num1) , HYPERLOGLOG(num1) from tb;") # stable tdSql.error("select udf1(c1) , count(c1) from stb1;") @@ -290,7 +290,6 @@ class TDTestCase: tdSql.error("select udf1(c1) , irate(c1) from stb1;") tdSql.error("select udf1(c1) , sum(c1) from stb1;") tdSql.error("select udf1(c1) , stddev(c1) from stb1;") - tdSql.error("select udf1(c1) , mode(c1) from stb1;") tdSql.error("select udf1(c1) , HYPERLOGLOG(c1) from stb1;") # regular table with select functions diff --git a/tests/system-test/0-others/udf_cluster.py b/tests/system-test/0-others/udf_cluster.py index 1ca17383326b8f5ccf2b3fc628d0f69aa0003ab3..90b6df16ff50027396ddffef8d8f0389a469bbab 100644 --- a/tests/system-test/0-others/udf_cluster.py +++ b/tests/system-test/0-others/udf_cluster.py @@ -19,7 +19,8 @@ class MyDnodes(TDDnodes): class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") self.TDDnodes = None self.depoly_cluster(3) diff --git a/tests/system-test/0-others/udf_create.py b/tests/system-test/0-others/udf_create.py index 788202eb1b9d39447dec1076dbb3091f2440dd33..65dad6400041e8c52d39d0ff4e484bdc29099894 100644 --- a/tests/system-test/0-others/udf_create.py +++ b/tests/system-test/0-others/udf_create.py @@ -15,7 +15,8 @@ import threading class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), logSql) @@ -281,7 +282,6 @@ class TDTestCase: tdSql.error("select udf1(num1) , irate(num1) from tb;") tdSql.error("select udf1(num1) , sum(num1) from tb;") tdSql.error("select udf1(num1) , stddev(num1) from tb;") - tdSql.error("select udf1(num1) , mode(num1) from tb;") tdSql.error("select udf1(num1) , HYPERLOGLOG(num1) from tb;") # stable tdSql.error("select udf1(c1) , count(c1) from stb1;") @@ -290,7 +290,6 @@ class TDTestCase: tdSql.error("select udf1(c1) , irate(c1) from stb1;") tdSql.error("select udf1(c1) , sum(c1) from stb1;") tdSql.error("select udf1(c1) , stddev(c1) from stb1;") - tdSql.error("select udf1(c1) , mode(c1) from stb1;") tdSql.error("select udf1(c1) , HYPERLOGLOG(c1) from stb1;") # regular table with select functions diff --git a/tests/system-test/0-others/udf_restart_taosd.py b/tests/system-test/0-others/udf_restart_taosd.py index b860a0dfabeb562c1e2e83a02c613aaa1cb29f17..dae707520f55e2e2c6b02c60e5d9015f8c613d3d 100644 --- a/tests/system-test/0-others/udf_restart_taosd.py +++ b/tests/system-test/0-others/udf_restart_taosd.py @@ -12,7 +12,8 @@ import subprocess class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), logSql) @@ -278,7 +279,6 @@ class TDTestCase: tdSql.error("select udf1(num1) , irate(num1) from tb;") tdSql.error("select udf1(num1) , sum(num1) from tb;") tdSql.error("select udf1(num1) , stddev(num1) from tb;") - tdSql.error("select udf1(num1) , mode(num1) from tb;") tdSql.error("select udf1(num1) , HYPERLOGLOG(num1) from tb;") # stable tdSql.error("select udf1(c1) , count(c1) from stb1;") @@ -287,7 +287,6 @@ class TDTestCase: tdSql.error("select udf1(c1) , irate(c1) from stb1;") tdSql.error("select udf1(c1) , sum(c1) from stb1;") tdSql.error("select udf1(c1) , stddev(c1) from stb1;") - tdSql.error("select udf1(c1) , mode(c1) from stb1;") tdSql.error("select udf1(c1) , HYPERLOGLOG(c1) from stb1;") # regular table with select functions diff --git a/tests/system-test/0-others/user_control.py b/tests/system-test/0-others/user_control.py index a20b7b17bccf9a04d52e46d56af2a2d0b0e489fb..3918828646e8cfe1415b809561514d31bf88a274 100644 --- a/tests/system-test/0-others/user_control.py +++ b/tests/system-test/0-others/user_control.py @@ -154,7 +154,8 @@ class User: class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/1-insert/alter_database.py b/tests/system-test/1-insert/alter_database.py index d3a55ee0a6d97c23097c442321a079836c78d49f..aec18a1cf1905d3076b3d93c5b08a0f169a89af4 100644 --- a/tests/system-test/1-insert/alter_database.py +++ b/tests/system-test/1-insert/alter_database.py @@ -10,36 +10,43 @@ from util.sql import * from util.cases import * from util.dnodes import * + class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(),logSql) - self.buffer_boundary = [3,4097,8193,12289,16384] - self.buffer_error = [self.buffer_boundary[0]-1,self.buffer_boundary[-1]+1,12289,96] + tdSql.init(conn.cursor(), logSql) + self.buffer_boundary = [3, 4097, 8193, 12289, 16384] + self.buffer_error = [self.buffer_boundary[0] - + 1, self.buffer_boundary[-1]+1, 12289, 256] # pages_boundary >= 64 - self.pages_boundary = [64,128,512] + self.pages_boundary = [64, 128, 512] self.pages_error = [self.pages_boundary[0]-1] + def alter_buffer(self): tdSql.execute('create database db') for buffer in self.buffer_boundary: tdSql.execute(f'alter database db buffer {buffer}') - tdSql.query('select * from information_schema.ins_databases where name = "db"') - tdSql.checkEqual(tdSql.queryResult[0][8],buffer) + tdSql.query( + 'select * from information_schema.ins_databases where name = "db"') + tdSql.checkEqual(tdSql.queryResult[0][8], buffer) tdSql.execute('drop database db') tdSql.execute('create database db vgroups 10') for buffer in self.buffer_error: tdSql.error(f'alter database db buffer {buffer}') tdSql.execute('drop database db') - + def alter_pages(self): tdSql.execute('create database db') for pages in self.pages_boundary: tdSql.execute(f'alter database db pages {pages}') - tdSql.query('select * from information_schema.ins_databases where name = "db"') - tdSql.checkEqual(tdSql.queryResult[0][10],pages) + tdSql.query( + 'select * from information_schema.ins_databases where name = "db"') + tdSql.checkEqual(tdSql.queryResult[0][10], pages) tdSql.execute('drop database db') tdSql.execute('create database db') - tdSql.query('select * from information_schema.ins_databases where name = "db"') + tdSql.query( + 'select * from information_schema.ins_databases where name = "db"') self.pages_error.append(tdSql.queryResult[0][10]) for pages in self.pages_error: tdSql.error(f'alter database db pages {pages}') @@ -54,5 +61,6 @@ class TDTestCase: tdSql.close() tdLog.success(f"{__file__} successfully executed") + tdCases.addLinux(__file__, TDTestCase()) -tdCases.addWindows(__file__, TDTestCase()) \ No newline at end of file +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/1-insert/alter_stable.py b/tests/system-test/1-insert/alter_stable.py index b66cbb89c0796416d033294a1c9ae9d92afb1dc1..3e82b573b108319f8ee0e5172537fb38b790bd85 100644 --- a/tests/system-test/1-insert/alter_stable.py +++ b/tests/system-test/1-insert/alter_stable.py @@ -20,7 +20,8 @@ from util.sqlset import * from util import constant from util.common import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.setsql = TDSetSql() diff --git a/tests/system-test/1-insert/alter_table.py b/tests/system-test/1-insert/alter_table.py index 5fbfff9909d91c1213858618cbdf8f8fd20e9bd4..6a437d460105a91e4fb75caca71e69667753e092 100644 --- a/tests/system-test/1-insert/alter_table.py +++ b/tests/system-test/1-insert/alter_table.py @@ -21,7 +21,8 @@ from util.common import * from util.sqlset import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.setsql = TDSetSql() diff --git a/tests/system-test/1-insert/block_wise.py b/tests/system-test/1-insert/block_wise.py index 083eff34e62c3773dc9b8abe12900e10468acf51..0e17a01d051975512e6a363f81507b0b07571e44 100644 --- a/tests/system-test/1-insert/block_wise.py +++ b/tests/system-test/1-insert/block_wise.py @@ -142,7 +142,8 @@ class BSMAschema: class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) self.precision = "ms" @@ -426,7 +427,17 @@ class TDTestCase: tdDnodes.stop(1) tdDnodes.start(1) - tdLog.printNoPrefix("==========step3:insert and flush in rollup database") + + tdLog.printNoPrefix("==========step3: sleep 20s for catalogUpdateTableIndex") + tdSql.execute("create database db_s20") + tdSql.execute("use db_s20") + tdSql.execute(f"create stable stb1 (ts timestamp, c1 int) tags (t1 int) sma(c1);") + tdSql.execute("alter stable stb1 add column tinyint_col tinyint") + time.sleep(20) + tdSql.query("select count(*) from stb1") + tdSql.execute("drop database if exists db_s20 ") + + tdLog.printNoPrefix("==========step4:insert and flush in rollup database") tdSql.execute("create database db4 retentions 1s:4m,2s:8m,3s:12m") tdSql.execute("use db4") self.__create_tb(rollup="first") @@ -435,7 +446,7 @@ class TDTestCase: tdSql.execute(f'flush database db4') - tdLog.printNoPrefix("==========step4:after wal, all check again ") + tdLog.printNoPrefix("==========step5:after wal, all check again ") tdSql.prepare() self.__create_tb() self.__insert_data() diff --git a/tests/system-test/1-insert/create_retentions.py b/tests/system-test/1-insert/create_retentions.py index 54abcec391f423b9a367d1fa8cb601c449a00673..e673815c73a5cc9e358dc25164c433a17086e719 100644 --- a/tests/system-test/1-insert/create_retentions.py +++ b/tests/system-test/1-insert/create_retentions.py @@ -44,9 +44,10 @@ NTBNAME = "nt1" class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") - tdSql.init(conn.cursor(), False) + tdSql.init(conn.cursor(), True) @property def create_databases_sql_err(self): diff --git a/tests/system-test/1-insert/database_pre_suf.py b/tests/system-test/1-insert/database_pre_suf.py index fc4bf7f5de2bffd5ad83f9936b633af7d0513169..862edbdde9b795f151b9d17f3c74abc8ebc4de63 100755 --- a/tests/system-test/1-insert/database_pre_suf.py +++ b/tests/system-test/1-insert/database_pre_suf.py @@ -28,7 +28,8 @@ class TDTestCase: "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"fnDebugFlag":143} - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) @@ -184,6 +185,7 @@ class TDTestCase: tdSql.query("select count(*) from hn_table_1_r;") tdSql.checkData(0,0,num_random*n) + sleep(5) # stream data check tdSql.query("select start,wend,max_int from stream_max_stable_1 ;") tdSql.checkRows(20) diff --git a/tests/system-test/1-insert/db_tb_name_check.py b/tests/system-test/1-insert/db_tb_name_check.py index 5017fde68a8bbf249ce599ba9b5ef882433ed73d..23bb53962038a416590a28b99bdd2763bf52a954 100644 --- a/tests/system-test/1-insert/db_tb_name_check.py +++ b/tests/system-test/1-insert/db_tb_name_check.py @@ -31,7 +31,8 @@ from util.common import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.special_name = ['!','@','#','$','%','^','&','*','(',')','[',']','{','}',\ diff --git a/tests/system-test/1-insert/delete_childtable.py b/tests/system-test/1-insert/delete_childtable.py new file mode 100644 index 0000000000000000000000000000000000000000..584e88330cc12ede792619c80a489efd8588adc0 --- /dev/null +++ b/tests/system-test/1-insert/delete_childtable.py @@ -0,0 +1,232 @@ + +################################################################### +# 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 random +import string + +from numpy import logspace +from util import constant +from util.log import * +from util.cases import * +from util.sql import * +from util.common import * +from util.sqlset import TDSetSql + +class TDTestCase: + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + self.dbname = 'db_test' + self.setsql = TDSetSql() + self.stbname = 'stb' + self.ntbname = 'ntb' + self.rowNum = 5 + self.tbnum = 2 + self.ts = 1537146000000 + self.binary_str = 'taosdata' + self.nchar_str = '涛思数据' + self.str_length = 20 + self.column_dict = { + 'col1': 'tinyint', + 'col2': 'smallint', + 'col3': 'int', + 'col4': 'bigint', + 'col5': 'tinyint unsigned', + 'col6': 'smallint unsigned', + 'col7': 'int unsigned', + 'col8': 'bigint unsigned', + 'col9': 'float', + 'col10': 'double', + 'col11': 'bool', + 'col12': f'binary({self.str_length})', + 'col13': f'nchar({self.str_length})', + + } + + self.tinyint_val = random.randint(constant.TINYINT_MIN,constant.TINYINT_MAX) + self.smallint_val = random.randint(constant.SMALLINT_MIN,constant.SMALLINT_MAX) + self.int_val = random.randint(constant.INT_MIN,constant.INT_MAX) + self.bigint_val = random.randint(constant.BIGINT_MIN,constant.BIGINT_MAX) + self.untingint_val = random.randint(constant.TINYINT_UN_MIN,constant.TINYINT_UN_MAX) + self.unsmallint_val = random.randint(constant.SMALLINT_UN_MIN,constant.SMALLINT_UN_MAX) + self.unint_val = random.randint(constant.INT_UN_MIN,constant.INT_MAX) + self.unbigint_val = random.randint(constant.BIGINT_UN_MIN,constant.BIGINT_UN_MAX) + self.float_val = random.uniform(constant.FLOAT_MIN,constant.FLOAT_MAX) + self.double_val = random.uniform(constant.DOUBLE_MIN*(1E-300),constant.DOUBLE_MAX*(1E-300)) + self.bool_val = random.randint(0,100)%2 + self.binary_val = tdCom.getLongName(random.randint(0,self.str_length)) + self.nchar_val = tdCom.getLongName(random.randint(0,self.str_length)) + self.base_data = { + 'tinyint':self.tinyint_val, + 'smallint':self.smallint_val, + 'int':self.int_val, + 'bigint':self.bigint_val, + 'tinyint unsigned':self.untingint_val, + 'smallint unsigned':self.unsmallint_val, + 'int unsigned':self.unint_val, + 'bigint unsigned':self.unbigint_val, + 'bool':self.bool_val, + 'float':self.float_val, + 'double':self.double_val, + 'binary':self.binary_val, + 'nchar':self.nchar_val + } + + def insert_base_data(self,col_type,tbname,rows,base_data): + for i in range(rows): + if col_type.lower() == 'tinyint': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["tinyint"]})') + elif col_type.lower() == 'smallint': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["smallint"]})') + elif col_type.lower() == 'int': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["int"]})') + elif col_type.lower() == 'bigint': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["bigint"]})') + elif col_type.lower() == 'tinyint unsigned': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["tinyint unsigned"]})') + elif col_type.lower() == 'smallint unsigned': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["smallint unsigned"]})') + elif col_type.lower() == 'int unsigned': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["int unsigned"]})') + elif col_type.lower() == 'bigint unsigned': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["bigint unsigned"]})') + elif col_type.lower() == 'bool': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["bool"]})') + elif col_type.lower() == 'float': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["float"]})') + elif col_type.lower() == 'double': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["double"]})') + elif 'binary' in col_type.lower(): + tdSql.execute(f'''insert into {tbname} values({self.ts+i},"{base_data['binary']}")''') + elif 'nchar' in col_type.lower(): + tdSql.execute(f'''insert into {tbname} values({self.ts+i},"{base_data['nchar']}")''') + def delete_all_data(self,tbname,col_type,row_num,base_data,dbname,tb_num=1,stbname=''): + tdSql.query(f'select count(*) from {tbname}') + tdSql.execute(f'delete from {tbname}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select * from {tbname}') + tdSql.checkRows(0) + tdSql.query(f'select count(*) from {stbname}') + if tb_num <= 1: + if len(tdSql.queryResult) != 0: + tdLog.exit('delete case failure!') + else: + tdSql.checkEqual(tdSql.queryResult[0][0],(tb_num-1)*row_num) + self.insert_base_data(col_type,tbname,row_num,base_data) + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select * from {tbname}') + tdSql.checkRows(row_num) + def delete_one_row(self,tbname,column_type,column_name,base_data,row_num,dbname,tb_num=1): + tdSql.execute(f'delete from {tbname} where ts={self.ts}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {column_name} from {tbname}') + tdSql.checkRows(row_num-1) + tdSql.query(f'select {column_name} from {tbname} where ts={self.ts}') + tdSql.checkRows(0) + if 'binary' in column_type.lower(): + tdSql.execute(f'''insert into {tbname} values({self.ts},"{base_data['binary']}")''') + elif 'nchar' in column_type.lower(): + tdSql.execute(f'''insert into {tbname} values({self.ts},"{base_data['nchar']}")''') + else: + tdSql.execute(f'insert into {tbname} values({self.ts},{base_data[column_type]})') + tdSql.query(f'select {column_name} from {tbname} where ts={self.ts}') + if column_type.lower() == 'float' or column_type.lower() == 'double': + if abs(tdSql.queryResult[0][0] - base_data[column_type]) / base_data[column_type] <= 0.0001: + tdSql.checkEqual(tdSql.queryResult[0][0],tdSql.queryResult[0][0]) + else: + tdLog.exit(f'{column_type} data check failure') + elif 'binary' in column_type.lower(): + tdSql.checkEqual(tdSql.queryResult[0][0],base_data['binary']) + elif 'nchar' in column_type.lower(): + tdSql.checkEqual(tdSql.queryResult[0][0],base_data['nchar']) + else: + tdSql.checkEqual(tdSql.queryResult[0][0],base_data[column_type]) + def delete_rows(self,dbname,tbname,col_name,col_type,base_data,row_num,tb_num=1): + for i in range(row_num): + tdSql.execute(f'delete from {tbname} where ts>{self.ts+i}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows(i+1) + self.insert_base_data(col_type,tbname,row_num,base_data) + for i in range(row_num): + tdSql.execute(f'delete from {tbname} where ts>={self.ts+i}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows(i) + self.insert_base_data(col_type,tbname,row_num,base_data) + for i in range(row_num): + tdSql.execute(f'delete from {tbname} where ts<={self.ts+i}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows(row_num-i-1) + self.insert_base_data(col_type,tbname,row_num,base_data) + for i in range(row_num): + tdSql.execute(f'delete from {tbname} where ts<{self.ts+i}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows(row_num-i) + self.insert_base_data(col_type,tbname,row_num,base_data) + for i in range(row_num): + tdSql.execute(f'delete from {tbname} where ts between {self.ts} and {self.ts+i}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows(row_num - i-1) + self.insert_base_data(col_type,tbname,row_num,base_data) + tdSql.execute(f'delete from {tbname} where ts between {self.ts+i+1} and {self.ts}') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows(row_num) + def delete_error(self,tbname,column_name,column_type,base_data): + for error_list in ['',f'ts = {self.ts} and',f'ts = {self.ts} or']: + if 'binary' in column_type.lower(): + tdSql.error(f'''delete from {tbname} where {error_list} {column_name} ="{base_data['binary']}"''') + elif 'nchar' in column_type.lower(): + tdSql.error(f'''delete from {tbname} where {error_list} {column_name} ="{base_data['nchar']}"''') + else: + tdSql.error(f'delete from {tbname} where {error_list} {column_name} = {base_data[column_type]}') + + def delete_data_ctb(self): + tdSql.execute(f'create database if not exists {self.dbname}') + tdSql.execute(f'use {self.dbname}') + for col_name,col_type in self.column_dict.items(): + tdSql.execute(f'create table {self.stbname} (ts timestamp,{col_name} {col_type}) tags(t1 int)') + for i in range(self.tbnum): + tdSql.execute(f'create table {self.stbname}_{i} using {self.stbname} tags(1)') + self.insert_base_data(col_type,f'{self.stbname}_{i}',self.rowNum,self.base_data) + self.delete_one_row(f'{self.stbname}_{i}',col_type,col_name,self.base_data,self.rowNum,self.dbname,) + self.delete_all_data(f'{self.stbname}_{i}',col_type,self.rowNum,self.base_data,self.dbname,i+1,self.stbname) + self.delete_error(f'{self.stbname}_{i}',col_name,col_type,self.base_data) + self.delete_rows(self.dbname,f'{self.stbname}_{i}',col_name,col_type,self.base_data,self.rowNum) + for func in ['first','last']: + tdSql.query(f'select {func}(*) from {self.stbname}_{i}') + tdSql.execute(f'drop table {self.stbname}') + def run(self): + self.delete_data_ctb() + tdDnodes.stoptaosd(1) + tdDnodes.starttaosd(1) + self.delete_data_ctb() + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file diff --git a/tests/system-test/1-insert/delete_data.py b/tests/system-test/1-insert/delete_data.py index f620a4b18a0d7ddf5a0d65c902d0411c270e6463..aaad723b891201c2fe509e9c575caacafdab57ee 100644 --- a/tests/system-test/1-insert/delete_data.py +++ b/tests/system-test/1-insert/delete_data.py @@ -1,3 +1,4 @@ + ################################################################### # Copyright (c) 2016 by TAOS Technologies, Inc. # All rights reserved. @@ -23,15 +24,16 @@ from util.common import * from util.sqlset import TDSetSql class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.dbname = 'db_test' self.setsql = TDSetSql() self.stbname = 'stb' self.ntbname = 'ntb' - self.rowNum = 5 - self.tbnum = 2 + self.rowNum = 10 + self.tbnum = 3 self.ts = 1537146000000 self.binary_str = 'taosdata' self.nchar_str = '涛思数据' @@ -110,13 +112,22 @@ class TDTestCase: tdSql.execute(f'''insert into {tbname} values({self.ts+i},"{base_data['binary']}")''') elif 'nchar' in col_type.lower(): tdSql.execute(f'''insert into {tbname} values({self.ts+i},"{base_data['nchar']}")''') - def delete_all_data(self,tbname,col_type,row_num,base_data,dbname,tb_type,tb_num=1): + def delete_all_data(self,tbname,col_type,row_num,base_data,dbname,tb_type,tb_num=1,stbname=''): + tdSql.query(f'select count(*) from {tbname}') tdSql.execute(f'delete from {tbname}') tdSql.execute(f'flush database {dbname}') tdSql.execute('reset query cache') tdSql.query(f'select * from {tbname}') tdSql.checkRows(0) if tb_type == 'ntb' or tb_type == 'ctb': + if tb_type == 'ctb': + tdSql.query(f'select count(*) from {stbname}') + if tb_num <= 1: + if len(tdSql.queryResult) != 0: + tdLog.exit('delete case failure!') + else: + tdSql.checkEqual(tdSql.queryResult[0][0],(tb_num-1)*row_num) + self.insert_base_data(col_type,tbname,row_num,base_data) elif tb_type == 'stb': for i in range(tb_num): @@ -265,7 +276,7 @@ class TDTestCase: tdSql.execute(f'create table {self.stbname}_{i} using {self.stbname} tags(1)') self.insert_base_data(col_type,f'{self.stbname}_{i}',self.rowNum,self.base_data) self.delete_one_row(f'{self.stbname}_{i}',col_type,col_name,self.base_data,self.rowNum,self.dbname,'ctb') - self.delete_all_data(f'{self.stbname}_{i}',col_type,self.rowNum,self.base_data,self.dbname,'ctb') + self.delete_all_data(f'{self.stbname}_{i}',col_type,self.rowNum,self.base_data,self.dbname,'ctb',i+1,self.stbname) self.delete_error(f'{self.stbname}_{i}',col_name,col_type,self.base_data) self.delete_rows(self.dbname,f'{self.stbname}_{i}',col_name,col_type,self.base_data,self.rowNum,'ctb') for func in ['first','last']: @@ -299,4 +310,4 @@ class TDTestCase: tdLog.success("%s successfully executed" % __file__) tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file diff --git a/tests/system-test/1-insert/delete_normaltable.py b/tests/system-test/1-insert/delete_normaltable.py new file mode 100644 index 0000000000000000000000000000000000000000..66ef91d95576a1b330e022923f058d9b2fc27e9e --- /dev/null +++ b/tests/system-test/1-insert/delete_normaltable.py @@ -0,0 +1,224 @@ + +################################################################### +# 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 random +import string + +from numpy import logspace +from util import constant +from util.log import * +from util.cases import * +from util.sql import * +from util.common import * +from util.sqlset import TDSetSql + +class TDTestCase: + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(),True) + self.dbname = 'db_test' + self.setsql = TDSetSql() + self.ntbname = 'ntb' + self.rowNum = 10 + self.tbnum = 3 + self.ts = 1537146000000 + self.binary_str = 'taosdata' + self.nchar_str = '涛思数据' + self.str_length = 20 + self.column_dict = { + 'col1': 'tinyint', + 'col2': 'smallint', + 'col3': 'int', + 'col4': 'bigint', + 'col5': 'tinyint unsigned', + 'col6': 'smallint unsigned', + 'col7': 'int unsigned', + 'col8': 'bigint unsigned', + 'col9': 'float', + 'col10': 'double', + 'col11': 'bool', + 'col12': f'binary({self.str_length})', + 'col13': f'nchar({self.str_length})', + + } + + self.tinyint_val = random.randint(constant.TINYINT_MIN,constant.TINYINT_MAX) + self.smallint_val = random.randint(constant.SMALLINT_MIN,constant.SMALLINT_MAX) + self.int_val = random.randint(constant.INT_MIN,constant.INT_MAX) + self.bigint_val = random.randint(constant.BIGINT_MIN,constant.BIGINT_MAX) + self.untingint_val = random.randint(constant.TINYINT_UN_MIN,constant.TINYINT_UN_MAX) + self.unsmallint_val = random.randint(constant.SMALLINT_UN_MIN,constant.SMALLINT_UN_MAX) + self.unint_val = random.randint(constant.INT_UN_MIN,constant.INT_MAX) + self.unbigint_val = random.randint(constant.BIGINT_UN_MIN,constant.BIGINT_UN_MAX) + self.float_val = random.uniform(constant.FLOAT_MIN,constant.FLOAT_MAX) + self.double_val = random.uniform(constant.DOUBLE_MIN*(1E-300),constant.DOUBLE_MAX*(1E-300)) + self.bool_val = random.randint(0,100)%2 + self.binary_val = tdCom.getLongName(random.randint(0,self.str_length)) + self.nchar_val = tdCom.getLongName(random.randint(0,self.str_length)) + self.base_data = { + 'tinyint':self.tinyint_val, + 'smallint':self.smallint_val, + 'int':self.int_val, + 'bigint':self.bigint_val, + 'tinyint unsigned':self.untingint_val, + 'smallint unsigned':self.unsmallint_val, + 'int unsigned':self.unint_val, + 'bigint unsigned':self.unbigint_val, + 'bool':self.bool_val, + 'float':self.float_val, + 'double':self.double_val, + 'binary':self.binary_val, + 'nchar':self.nchar_val + } + + def insert_base_data(self,col_type,tbname,rows,base_data): + for i in range(rows): + if col_type.lower() == 'tinyint': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["tinyint"]})') + elif col_type.lower() == 'smallint': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["smallint"]})') + elif col_type.lower() == 'int': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["int"]})') + elif col_type.lower() == 'bigint': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["bigint"]})') + elif col_type.lower() == 'tinyint unsigned': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["tinyint unsigned"]})') + elif col_type.lower() == 'smallint unsigned': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["smallint unsigned"]})') + elif col_type.lower() == 'int unsigned': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["int unsigned"]})') + elif col_type.lower() == 'bigint unsigned': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["bigint unsigned"]})') + elif col_type.lower() == 'bool': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["bool"]})') + elif col_type.lower() == 'float': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["float"]})') + elif col_type.lower() == 'double': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["double"]})') + elif 'binary' in col_type.lower(): + tdSql.execute(f'''insert into {tbname} values({self.ts+i},"{base_data['binary']}")''') + elif 'nchar' in col_type.lower(): + tdSql.execute(f'''insert into {tbname} values({self.ts+i},"{base_data['nchar']}")''') + def delete_all_data(self,tbname,col_type,row_num,base_data,dbname,tb_num=1,stbname=''): + tdSql.query(f'select count(*) from {tbname}') + tdSql.execute(f'delete from {tbname}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select * from {tbname}') + tdSql.checkRows(0) + self.insert_base_data(col_type,tbname,row_num,base_data) + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select * from {tbname}') + tdSql.checkRows(row_num) + def delete_one_row(self,tbname,column_type,column_name,base_data,row_num,dbname,tb_num=1): + tdSql.execute(f'delete from {tbname} where ts={self.ts}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {column_name} from {tbname}') + tdSql.checkRows(row_num-1) + tdSql.query(f'select {column_name} from {tbname} where ts={self.ts}') + tdSql.checkRows(0) + if 'binary' in column_type.lower(): + tdSql.execute(f'''insert into {tbname} values({self.ts},"{base_data['binary']}")''') + elif 'nchar' in column_type.lower(): + tdSql.execute(f'''insert into {tbname} values({self.ts},"{base_data['nchar']}")''') + else: + tdSql.execute(f'insert into {tbname} values({self.ts},{base_data[column_type]})') + tdSql.query(f'select {column_name} from {tbname} where ts={self.ts}') + if column_type.lower() == 'float' or column_type.lower() == 'double': + if abs(tdSql.queryResult[0][0] - base_data[column_type]) / base_data[column_type] <= 0.0001: + tdSql.checkEqual(tdSql.queryResult[0][0],tdSql.queryResult[0][0]) + else: + tdLog.exit(f'{column_type} data check failure') + elif 'binary' in column_type.lower(): + tdSql.checkEqual(tdSql.queryResult[0][0],base_data['binary']) + elif 'nchar' in column_type.lower(): + tdSql.checkEqual(tdSql.queryResult[0][0],base_data['nchar']) + else: + tdSql.checkEqual(tdSql.queryResult[0][0],base_data[column_type]) + def delete_rows(self,dbname,tbname,col_name,col_type,base_data,row_num,tb_num=1): + for i in range(row_num): + tdSql.execute(f'delete from {tbname} where ts>{self.ts+i}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows(i+1) + self.insert_base_data(col_type,tbname,row_num,base_data) + for i in range(row_num): + tdSql.execute(f'delete from {tbname} where ts>={self.ts+i}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows(i) + self.insert_base_data(col_type,tbname,row_num,base_data) + for i in range(row_num): + tdSql.execute(f'delete from {tbname} where ts<={self.ts+i}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows(row_num-i-1) + self.insert_base_data(col_type,tbname,row_num,base_data) + for i in range(row_num): + tdSql.execute(f'delete from {tbname} where ts<{self.ts+i}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows(row_num-i) + self.insert_base_data(col_type,tbname,row_num,base_data) + for i in range(row_num): + tdSql.execute(f'delete from {tbname} where ts between {self.ts} and {self.ts+i}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows(row_num - i-1) + self.insert_base_data(col_type,tbname,row_num,base_data) + tdSql.execute(f'delete from {tbname} where ts between {self.ts+i+1} and {self.ts}') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows(row_num) + def delete_error(self,tbname,column_name,column_type,base_data): + for error_list in ['',f'ts = {self.ts} and',f'ts = {self.ts} or']: + if 'binary' in column_type.lower(): + tdSql.error(f'''delete from {tbname} where {error_list} {column_name} ="{base_data['binary']}"''') + elif 'nchar' in column_type.lower(): + tdSql.error(f'''delete from {tbname} where {error_list} {column_name} ="{base_data['nchar']}"''') + else: + tdSql.error(f'delete from {tbname} where {error_list} {column_name} = {base_data[column_type]}') + + def delete_data_ntb(self): + tdSql.execute(f'create database if not exists {self.dbname}') + tdSql.execute(f'use {self.dbname}') + for col_name,col_type in self.column_dict.items(): + tdSql.execute(f'create table {self.ntbname} (ts timestamp,{col_name} {col_type})') + self.insert_base_data(col_type,self.ntbname,self.rowNum,self.base_data) + self.delete_one_row(self.ntbname,col_type,col_name,self.base_data,self.rowNum,self.dbname) + self.delete_all_data(self.ntbname,col_type,self.rowNum,self.base_data,self.dbname) + self.delete_error(self.ntbname,col_name,col_type,self.base_data) + self.delete_rows(self.dbname,self.ntbname,col_name,col_type,self.base_data,self.rowNum) + for func in ['first','last']: + tdSql.query(f'select {func}(*) from {self.ntbname}') + tdSql.execute(f'drop table {self.ntbname}') + tdSql.execute(f'drop database {self.dbname}') + def run(self): + self.delete_data_ntb() + tdDnodes.stoptaosd(1) + tdDnodes.starttaosd(1) + self.delete_data_ntb() + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file diff --git a/tests/system-test/1-insert/delete_stable.py b/tests/system-test/1-insert/delete_stable.py new file mode 100644 index 0000000000000000000000000000000000000000..313b6ce731fe98aaed6fdfe1f9fe71fa4313d3cd --- /dev/null +++ b/tests/system-test/1-insert/delete_stable.py @@ -0,0 +1,233 @@ + +################################################################### +# 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 random +import string + +from numpy import logspace +from util import constant +from util.log import * +from util.cases import * +from util.sql import * +from util.common import * +from util.sqlset import TDSetSql + +class TDTestCase: + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor()) + self.dbname = 'db_test' + self.setsql = TDSetSql() + self.stbname = 'stb' + self.ntbname = 'ntb' + self.rowNum = 10 + self.tbnum = 3 + self.ts = 1537146000000 + self.binary_str = 'taosdata' + self.nchar_str = '涛思数据' + self.str_length = 20 + self.column_dict = { + 'col1': 'tinyint', + 'col2': 'smallint', + 'col3': 'int', + 'col4': 'bigint', + 'col5': 'tinyint unsigned', + 'col6': 'smallint unsigned', + 'col7': 'int unsigned', + 'col8': 'bigint unsigned', + 'col9': 'float', + 'col10': 'double', + 'col11': 'bool', + 'col12': f'binary({self.str_length})', + 'col13': f'nchar({self.str_length})', + + } + + self.tinyint_val = random.randint(constant.TINYINT_MIN,constant.TINYINT_MAX) + self.smallint_val = random.randint(constant.SMALLINT_MIN,constant.SMALLINT_MAX) + self.int_val = random.randint(constant.INT_MIN,constant.INT_MAX) + self.bigint_val = random.randint(constant.BIGINT_MIN,constant.BIGINT_MAX) + self.untingint_val = random.randint(constant.TINYINT_UN_MIN,constant.TINYINT_UN_MAX) + self.unsmallint_val = random.randint(constant.SMALLINT_UN_MIN,constant.SMALLINT_UN_MAX) + self.unint_val = random.randint(constant.INT_UN_MIN,constant.INT_MAX) + self.unbigint_val = random.randint(constant.BIGINT_UN_MIN,constant.BIGINT_UN_MAX) + self.float_val = random.uniform(constant.FLOAT_MIN,constant.FLOAT_MAX) + self.double_val = random.uniform(constant.DOUBLE_MIN*(1E-300),constant.DOUBLE_MAX*(1E-300)) + self.bool_val = random.randint(0,100)%2 + self.binary_val = tdCom.getLongName(random.randint(0,self.str_length)) + self.nchar_val = tdCom.getLongName(random.randint(0,self.str_length)) + self.base_data = { + 'tinyint':self.tinyint_val, + 'smallint':self.smallint_val, + 'int':self.int_val, + 'bigint':self.bigint_val, + 'tinyint unsigned':self.untingint_val, + 'smallint unsigned':self.unsmallint_val, + 'int unsigned':self.unint_val, + 'bigint unsigned':self.unbigint_val, + 'bool':self.bool_val, + 'float':self.float_val, + 'double':self.double_val, + 'binary':self.binary_val, + 'nchar':self.nchar_val + } + + def insert_base_data(self,col_type,tbname,rows,base_data): + for i in range(rows): + if col_type.lower() == 'tinyint': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["tinyint"]})') + elif col_type.lower() == 'smallint': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["smallint"]})') + elif col_type.lower() == 'int': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["int"]})') + elif col_type.lower() == 'bigint': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["bigint"]})') + elif col_type.lower() == 'tinyint unsigned': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["tinyint unsigned"]})') + elif col_type.lower() == 'smallint unsigned': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["smallint unsigned"]})') + elif col_type.lower() == 'int unsigned': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["int unsigned"]})') + elif col_type.lower() == 'bigint unsigned': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["bigint unsigned"]})') + elif col_type.lower() == 'bool': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["bool"]})') + elif col_type.lower() == 'float': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["float"]})') + elif col_type.lower() == 'double': + tdSql.execute(f'insert into {tbname} values({self.ts+i},{base_data["double"]})') + elif 'binary' in col_type.lower(): + tdSql.execute(f'''insert into {tbname} values({self.ts+i},"{base_data['binary']}")''') + elif 'nchar' in col_type.lower(): + tdSql.execute(f'''insert into {tbname} values({self.ts+i},"{base_data['nchar']}")''') + def delete_all_data(self,tbname,col_type,row_num,base_data,dbname,tb_num=1): + tdSql.query(f'select count(*) from {tbname}') + tdSql.execute(f'delete from {tbname}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select * from {tbname}') + tdSql.checkRows(0) + for i in range(tb_num): + self.insert_base_data(col_type,f'{tbname}_{i}',row_num,base_data) + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select * from {tbname}') + tdSql.checkRows(row_num*tb_num) + def delete_one_row(self,tbname,column_type,column_name,base_data,row_num,dbname,tb_num=1): + tdSql.execute(f'delete from {tbname} where ts={self.ts}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {column_name} from {tbname}') + tdSql.checkRows((row_num-1)*tb_num) + tdSql.query(f'select {column_name} from {tbname} where ts={self.ts}') + tdSql.checkRows(0) + for i in range(tb_num): + if 'binary' in column_type.lower(): + tdSql.execute(f'''insert into {tbname}_{i} values({self.ts},"{base_data['binary']}")''') + elif 'nchar' in column_type.lower(): + tdSql.execute(f'''insert into {tbname}_{i} values({self.ts},"{base_data['nchar']}")''') + else: + tdSql.execute(f'insert into {tbname}_{i} values({self.ts},{base_data[column_type]})') + tdSql.query(f'select {column_name} from {tbname} where ts={self.ts}') + if column_type.lower() == 'float' or column_type.lower() == 'double': + if abs(tdSql.queryResult[0][0] - base_data[column_type]) / base_data[column_type] <= 0.0001: + tdSql.checkEqual(tdSql.queryResult[0][0],tdSql.queryResult[0][0]) + else: + tdLog.exit(f'{column_type} data check failure') + elif 'binary' in column_type.lower(): + tdSql.checkEqual(tdSql.queryResult[0][0],base_data['binary']) + elif 'nchar' in column_type.lower(): + tdSql.checkEqual(tdSql.queryResult[0][0],base_data['nchar']) + else: + tdSql.checkEqual(tdSql.queryResult[0][0],base_data[column_type]) + def delete_rows(self,dbname,tbname,col_name,col_type,base_data,row_num,tb_num=1): + for i in range(row_num): + tdSql.execute(f'delete from {tbname} where ts>{self.ts+i}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows((i+1)*tb_num) + for j in range(tb_num): + self.insert_base_data(col_type,f'{tbname}_{j}',row_num,base_data) + for i in range(row_num): + tdSql.execute(f'delete from {tbname} where ts>={self.ts+i}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows(i*tb_num) + for j in range(tb_num): + self.insert_base_data(col_type,f'{tbname}_{j}',row_num,base_data) + for i in range(row_num): + tdSql.execute(f'delete from {tbname} where ts<={self.ts+i}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows((row_num-i-1)*tb_num) + for j in range(tb_num): + self.insert_base_data(col_type,f'{tbname}_{j}',row_num,base_data) + for i in range(row_num): + tdSql.execute(f'delete from {tbname} where ts<{self.ts+i}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows((row_num-i)*tb_num) + for j in range(tb_num): + self.insert_base_data(col_type,f'{tbname}_{j}',row_num,base_data) + for i in range(row_num): + tdSql.execute(f'delete from {tbname} where ts between {self.ts} and {self.ts+i}') + tdSql.execute(f'flush database {dbname}') + tdSql.execute('reset query cache') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows(tb_num*(row_num - i-1)) + for j in range(tb_num): + self.insert_base_data(col_type,f'{tbname}_{j}',row_num,base_data) + tdSql.execute(f'delete from {tbname} where ts between {self.ts+i+1} and {self.ts}') + tdSql.query(f'select {col_name} from {tbname}') + tdSql.checkRows(tb_num*row_num) + def delete_error(self,tbname,column_name,column_type,base_data): + for error_list in ['',f'ts = {self.ts} and',f'ts = {self.ts} or']: + if 'binary' in column_type.lower(): + tdSql.error(f'''delete from {tbname} where {error_list} {column_name} ="{base_data['binary']}"''') + elif 'nchar' in column_type.lower(): + tdSql.error(f'''delete from {tbname} where {error_list} {column_name} ="{base_data['nchar']}"''') + else: + tdSql.error(f'delete from {tbname} where {error_list} {column_name} = {base_data[column_type]}') + def delete_data_stb(self): + tdSql.execute(f'create database if not exists {self.dbname}') + tdSql.execute(f'use {self.dbname}') + for col_name,col_type in self.column_dict.items(): + tdSql.execute(f'create table {self.stbname} (ts timestamp,{col_name} {col_type}) tags(t1 int)') + for i in range(self.tbnum): + tdSql.execute(f'create table {self.stbname}_{i} using {self.stbname} tags(1)') + self.insert_base_data(col_type,f'{self.stbname}_{i}',self.rowNum,self.base_data) + self.delete_error(self.stbname,col_name,col_type,self.base_data) + self.delete_one_row(self.stbname,col_type,col_name,self.base_data,self.rowNum,self.dbname,self.tbnum) + self.delete_all_data(self.stbname,col_type,self.rowNum,self.base_data,self.dbname,self.tbnum) + self.delete_rows(self.dbname,self.stbname,col_name,col_type,self.base_data,self.rowNum,self.tbnum) + for func in ['first','last']: + tdSql.query(f'select {func}(*) from {self.stbname}') + tdSql.execute(f'drop table {self.stbname}') + tdSql.execute(f'drop database {self.dbname}') + def run(self): + self.delete_data_stb() + tdDnodes.stoptaosd(1) + tdDnodes.starttaosd(1) + self.delete_data_stb() + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file diff --git a/tests/system-test/1-insert/influxdb_line_taosc_insert.py b/tests/system-test/1-insert/influxdb_line_taosc_insert.py index cae4294bc90c16ad3fed032eff610f5b943d789e..637250248404bdb03f2e1fbbc23a2783d1183a35 100644 --- a/tests/system-test/1-insert/influxdb_line_taosc_insert.py +++ b/tests/system-test/1-insert/influxdb_line_taosc_insert.py @@ -29,7 +29,8 @@ if platform.system().lower() == 'windows': sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8') class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), False) self._conn = conn diff --git a/tests/system-test/1-insert/insertWithMoreVgroup.py b/tests/system-test/1-insert/insertWithMoreVgroup.py index b80a5f9a4ac855f8e8bd70e53b0bcdcd28420f94..2356835ce894133df3313352f4575d3486cc7c5c 100644 --- a/tests/system-test/1-insert/insertWithMoreVgroup.py +++ b/tests/system-test/1-insert/insertWithMoreVgroup.py @@ -62,7 +62,8 @@ class TDTestCase: return buildPath # init - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) # tdSql.prepare() diff --git a/tests/system-test/1-insert/insert_drop.py b/tests/system-test/1-insert/insert_drop.py index 3e30e94a6b4b6845c826fb75bed43126d20387d8..029d013d5bd82a00511df1fcef9755b9dee99259 100644 --- a/tests/system-test/1-insert/insert_drop.py +++ b/tests/system-test/1-insert/insert_drop.py @@ -8,7 +8,8 @@ import threading class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/system-test/1-insert/keep_expired.py b/tests/system-test/1-insert/keep_expired.py index 09db1e45ba5c0ebab7d9054b43fa722e6ff0084c..0cb6d841ed997d5aed27bf4665bde4f81f9ba52c 100644 --- a/tests/system-test/1-insert/keep_expired.py +++ b/tests/system-test/1-insert/keep_expired.py @@ -7,7 +7,8 @@ import time class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) self.dbname = "test" @@ -29,6 +30,7 @@ class TDTestCase: time.sleep(self.offset_time * 2) tdSql.query(f'select * from {self.dbname}.{self.ctbname}') tdSql.checkEqual(tdSql.queryRows, 0) + tdSql.execute(f'TRIM DATABASE {self.dbname}') def stop(self): tdSql.close() diff --git a/tests/system-test/1-insert/mutil_stage.py b/tests/system-test/1-insert/mutil_stage.py index 63317e8036b6455984231bf634b23f7238935642..3e2bec130ef50181c58537abdd5abafe9f3d9c32 100644 --- a/tests/system-test/1-insert/mutil_stage.py +++ b/tests/system-test/1-insert/mutil_stage.py @@ -57,7 +57,8 @@ DATA_PRE2 = f"data2" class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) self.taos_cfg_path = tdDnodes.dnodes[0].cfgPath diff --git a/tests/system-test/1-insert/mutipythonnodebugtaosd.py b/tests/system-test/1-insert/mutipythonnodebugtaosd.py index 8aea53cd921c2199c91387fdd907f2e8f5bb026b..042d88165845d899871415eb1470871efdc94e44 100644 --- a/tests/system-test/1-insert/mutipythonnodebugtaosd.py +++ b/tests/system-test/1-insert/mutipythonnodebugtaosd.py @@ -60,7 +60,8 @@ class TDTestCase: return buildPath # init - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) # tdSql.init(conn.cursor()) # tdSql.prepare() diff --git a/tests/system-test/1-insert/opentsdb_json_taosc_insert.py b/tests/system-test/1-insert/opentsdb_json_taosc_insert.py index 3b01784000b74c1f6bb072f24e8be36e99d37f4f..44243fe029233dc3458a7b6822600bc198e11824 100644 --- a/tests/system-test/1-insert/opentsdb_json_taosc_insert.py +++ b/tests/system-test/1-insert/opentsdb_json_taosc_insert.py @@ -24,7 +24,8 @@ import threading import json class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) self._conn = conn diff --git a/tests/system-test/1-insert/opentsdb_telnet_line_taosc_insert.py b/tests/system-test/1-insert/opentsdb_telnet_line_taosc_insert.py index 209cfb724e460207493dc2ca1ab0dd3522eb333b..f58882720610b32794fc48e4cd652ae70e63b5d7 100644 --- a/tests/system-test/1-insert/opentsdb_telnet_line_taosc_insert.py +++ b/tests/system-test/1-insert/opentsdb_telnet_line_taosc_insert.py @@ -28,7 +28,8 @@ if platform.system().lower() == 'windows': sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8') class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), False) self._conn = conn diff --git a/tests/system-test/1-insert/table_comment.py b/tests/system-test/1-insert/table_comment.py index a0ae364fcd85eae1fcf11480f920d2c1febf3b31..270e0ca4240e53fd5b86f2958bf14ba65865f980 100644 --- a/tests/system-test/1-insert/table_comment.py +++ b/tests/system-test/1-insert/table_comment.py @@ -20,7 +20,8 @@ from util.sql import * from util.common import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) # prepare data diff --git a/tests/system-test/1-insert/table_param_ttl.py b/tests/system-test/1-insert/table_param_ttl.py index 21c591b07e3091a69d1cc211cc790785d807d92a..51d7d596cd9d94e6078fc7d448583c91a27e1780 100644 --- a/tests/system-test/1-insert/table_param_ttl.py +++ b/tests/system-test/1-insert/table_param_ttl.py @@ -18,7 +18,8 @@ from util.common import * class TDTestCase: updatecfgDict = {'ttlUnit':5,'ttlPushInterval':3} - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.ntbname = 'ntb' diff --git a/tests/system-test/1-insert/tb_100w_data_order.py b/tests/system-test/1-insert/tb_100w_data_order.py index d489ba21bc540f6547c7e531277bac00da6f98c7..ec166f5f6c3755aba18e12318af3adb87362f777 100644 --- a/tests/system-test/1-insert/tb_100w_data_order.py +++ b/tests/system-test/1-insert/tb_100w_data_order.py @@ -5,7 +5,8 @@ from util.common import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.ts = 1537146000000 diff --git a/tests/system-test/1-insert/test_stmt_muti_insert_query.py b/tests/system-test/1-insert/test_stmt_muti_insert_query.py index 7ddc0e60bd3ba6a48a96f86171c1995f49451b92..d75e04d2db229e73eee946086615b54a3c01980b 100644 --- a/tests/system-test/1-insert/test_stmt_muti_insert_query.py +++ b/tests/system-test/1-insert/test_stmt_muti_insert_query.py @@ -57,7 +57,8 @@ class TDTestCase: return buildPath # init - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) # tdSql.prepare() diff --git a/tests/system-test/1-insert/test_stmt_set_tbname_tag.py b/tests/system-test/1-insert/test_stmt_set_tbname_tag.py index 321dc88cd7ecfe147a07b9c7ee358025a754bdf0..afd9d45b5699006d3ed24477dbc2d9887a99701c 100644 --- a/tests/system-test/1-insert/test_stmt_set_tbname_tag.py +++ b/tests/system-test/1-insert/test_stmt_set_tbname_tag.py @@ -57,7 +57,8 @@ class TDTestCase: return buildPath # init - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) # tdSql.prepare() diff --git a/tests/system-test/1-insert/time_range_wise.py b/tests/system-test/1-insert/time_range_wise.py index 31885831814bc9ff840672315efbe67b729a92c1..3d5c9197d1dbad6740e91dcc378dff2939e75d77 100644 --- a/tests/system-test/1-insert/time_range_wise.py +++ b/tests/system-test/1-insert/time_range_wise.py @@ -134,7 +134,8 @@ class SMAschema: class TDTestCase: updatecfgDict = {"querySmaOptimize": 1} - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) self.precision = "ms" diff --git a/tests/system-test/1-insert/update_data.py b/tests/system-test/1-insert/update_data.py index 417adc39acc306fbd7b2d74518653d0347fb27cb..6fcd987ea42293d05c863cb2aed91a1d02b72ce7 100644 --- a/tests/system-test/1-insert/update_data.py +++ b/tests/system-test/1-insert/update_data.py @@ -12,7 +12,6 @@ # -*- coding: utf-8 -*- import random -import string from datetime import datetime from util import constant from util.log import * @@ -21,7 +20,8 @@ from util.sql import * from util.common import * from util.sqlset import TDSetSql class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(),logSql) self.setsql = TDSetSql() @@ -31,6 +31,7 @@ class TDTestCase: self.ctbname = 'ctb' self.ts = 1537146000000 self.str_length = 20 + self.block_update_times = 10000 self.column_dict = { 'col1': 'tinyint', 'col2': 'smallint', @@ -47,6 +48,14 @@ class TDTestCase: 'col13': f'nchar({self.str_length})', 'col_ts' : 'timestamp' } + self.tag_dict = { + 't0':'int' + } + # The number of tag_values should be same as tbnum + self.tag_values = [ + f'10', + f'100' + ] def data_check(self,tbname,col_name,col_type,value): tdSql.query(f'select {col_name} from {tbname}') @@ -248,11 +257,26 @@ class TDTestCase: self.error_check(self.ntbname,self.column_dict,'ntb') self.error_check(self.ctbname,self.column_dict,'ctb',self.stbname) + def update_10000times_and_query(self): + new_column_dict = {"ts": "timestamp"} + new_column_dict.update(self.column_dict) + tdSql.execute(f'drop database if exists {self.dbname}') + tdSql.execute(f'create database {self.dbname}') + tdSql.execute(f'use {self.dbname}') + tdSql.execute(self.setsql.set_create_stable_sql(self.stbname,new_column_dict,self.tag_dict)) + tdSql.execute(f'create table {self.stbname}_1 using {self.stbname} tags({self.tag_values[0]})') + tdSql.execute(f'insert into {self.stbname}_1 values ({self.ts}, {random.randint(1, 127)}, {random.randint(1, 127)}, {random.randint(1, 127)}, {random.randint(1, 127)}, {random.randint(1, 127)}, {random.randint(1, 127)}, {random.randint(1, 127)}, {random.randint(1, 127)}, {random.randint(1, 127)}, {random.randint(1, 127)}, {random.choice(["True", "FALSE"])}, {random.randint(1, 127)}, {random.randint(1, 127)}, now)') + for i in range(self.block_update_times): + tdSql.execute(f'insert into {self.stbname}_1 values ({self.ts}, {random.randint(1, 127)}, {random.randint(1, 127)}, {random.randint(1, 127)}, {random.randint(1, 127)}, {random.randint(1, 127)}, {random.randint(1, 127)}, {random.randint(1, 127)}, {random.randint(1, 127)}, {random.randint(1, 127)}, {random.randint(1, 127)}, {random.choice(["True", "FALSE"])}, {random.randint(1, 127)}, {random.randint(1, 127)}, now)') + tdSql.query(f'select count(*) from {self.stbname}') + tdSql.query(f'select * from {self.stbname}') + def run(self): #!bug TD-17708 and TD-17709 # for i in range(10): self.update_check() self.update_check_error() + self.update_10000times_and_query() # i+=1 def stop(self): diff --git a/tests/system-test/1-insert/update_data_muti_rows.py b/tests/system-test/1-insert/update_data_muti_rows.py index 623dc497ea127c904e8c8e3dede6e9d13dd76976..67406f327e7d7f401732f33a573603dea3ac186d 100644 --- a/tests/system-test/1-insert/update_data_muti_rows.py +++ b/tests/system-test/1-insert/update_data_muti_rows.py @@ -23,7 +23,8 @@ from util.common import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.dbname = 'db_test' diff --git a/tests/system-test/2-query/Now.py b/tests/system-test/2-query/Now.py index 35291856f2389a1aad47cdae8ccd762bde9f8f0f..db97cdad64785eb910845c35f715f7bccf05b8d9 100644 --- a/tests/system-test/2-query/Now.py +++ b/tests/system-test/2-query/Now.py @@ -7,7 +7,8 @@ from util.sqlset import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.setsql = TDSetSql() diff --git a/tests/system-test/2-query/Timediff.py b/tests/system-test/2-query/Timediff.py index 1f73215dd5b5aab6dec6569c2a72971494a54e6f..4e72c07b303499145c24cec63138367d54750a34 100644 --- a/tests/system-test/2-query/Timediff.py +++ b/tests/system-test/2-query/Timediff.py @@ -4,7 +4,8 @@ from util.cases import * from util.gettime import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.get_time = GetTime() diff --git a/tests/system-test/2-query/To_iso8601.py b/tests/system-test/2-query/To_iso8601.py index ccc26e9b1b4efc14570d002711d8054b46a41fce..92aacbb3501bd003eef597224442a142da2b2a36 100644 --- a/tests/system-test/2-query/To_iso8601.py +++ b/tests/system-test/2-query/To_iso8601.py @@ -10,7 +10,8 @@ import os class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.rowNum = 10 diff --git a/tests/system-test/2-query/To_unixtimestamp.py b/tests/system-test/2-query/To_unixtimestamp.py index 64f7b18e4102e39fe5171df902babab10cb78640..8ee2007450328b2edbb02822a68fa4ac9d9ca9a7 100644 --- a/tests/system-test/2-query/To_unixtimestamp.py +++ b/tests/system-test/2-query/To_unixtimestamp.py @@ -10,7 +10,8 @@ from util.sqlset import TDSetSql class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.setsql = TDSetSql() diff --git a/tests/system-test/2-query/Today.py b/tests/system-test/2-query/Today.py index 0124c5bbac937f46e78096cc3a55f873a80ad15b..08f6ba6bafa8029a20ef3b5e80fc6e9e90ea68b7 100644 --- a/tests/system-test/2-query/Today.py +++ b/tests/system-test/2-query/Today.py @@ -10,7 +10,8 @@ import pandas as pd class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.today_date = datetime.datetime.strptime(datetime.datetime.now().strftime("%Y-%m-%d"), "%Y-%m-%d") diff --git a/tests/system-test/2-query/abs.py b/tests/system-test/2-query/abs.py index c9fc025b9799863a5460fa077d20db88d92a803e..d7478a55a88c2f3dc18fb26b6dee92ed57c248ae 100644 --- a/tests/system-test/2-query/abs.py +++ b/tests/system-test/2-query/abs.py @@ -14,13 +14,15 @@ class TDTestCase: # "jniDebugFlag": 143, "simDebugFlag": 143, "dDebugFlag": 143, "dDebugFlag": 143, "vDebugFlag": 143, "mDebugFlag": 143, "qDebugFlag": 143, # "wDebugFlag": 143, "sDebugFlag": 143, "tsdbDebugFlag": 143, "tqDebugFlag": 143, "fsDebugFlag": 143, "udfDebugFlag": 143} - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) self.tb_nums = 10 self.row_nums = 20 self.ts = 1434938400000 self.time_step = 1000 + self.replicaVar = int(replicaVar) def insert_datas_and_check_abs(self ,tbnums , rownums , time_step ): tdLog.info(" prepare datas for auto check abs function ") @@ -28,7 +30,7 @@ class TDTestCase: stbname = f"{dbname}.stb" ctbname_pre = f"{dbname}.sub_tb_" - tdSql.execute(f" create database {dbname} ") + tdSql.execute(f" create database {dbname} replica {self.replicaVar} ") tdSql.execute(f" use {dbname} ") tdSql.execute(f" create stable {stbname} (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint,\ c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) tags (t1 int)") @@ -125,7 +127,7 @@ class TDTestCase: def prepare_tag_datas(self, dbname="testdb"): # prepare datas tdSql.execute( - f"create database if not exists {dbname} keep 3650 duration 1000") + f"create database if not exists {dbname} keep 3650 duration 1000 replica {self.replicaVar} ") tdSql.execute(" use testdb ") tdSql.execute( f'''create table {dbname}.stb1 @@ -456,7 +458,7 @@ class TDTestCase: dbname = "bound_test" tdSql.execute(f"drop database if exists {dbname}") - tdSql.execute(f"create database if not exists {dbname}") + tdSql.execute(f"create database if not exists {dbname} replica {self.replicaVar} ") time.sleep(3) tdSql.execute(f"use {dbname}") tdSql.execute( @@ -589,7 +591,7 @@ class TDTestCase: def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring - tdSql.prepare() + tdSql.prepare(replica=f"{self.replicaVar}") tdLog.printNoPrefix("==========step1:create table ==============") diff --git a/tests/system-test/2-query/and_or_for_byte.py b/tests/system-test/2-query/and_or_for_byte.py index 7d156da3790b1f5b005dd03543aafc8d197a9b82..479918f2f9dd3b8b995473bad38286edc7f2461b 100644 --- a/tests/system-test/2-query/and_or_for_byte.py +++ b/tests/system-test/2-query/and_or_for_byte.py @@ -14,7 +14,8 @@ class TDTestCase: # "jniDebugFlag": 143, "simDebugFlag": 143, "dDebugFlag": 143, "dDebugFlag": 143, "vDebugFlag": 143, "mDebugFlag": 143, "qDebugFlag": 143, # "wDebugFlag": 143, "sDebugFlag": 143, "tsdbDebugFlag": 143, "tqDebugFlag": 143, "fsDebugFlag": 143, "udfDebugFlag": 143} - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) self.tb_nums = 10 diff --git a/tests/system-test/2-query/apercentile.py b/tests/system-test/2-query/apercentile.py index 128a03937a21ebf36e45d977eae367c9c4dc5793..e190bf9374d6acbf4caa8753ab2a78c16e3ce442 100644 --- a/tests/system-test/2-query/apercentile.py +++ b/tests/system-test/2-query/apercentile.py @@ -18,7 +18,8 @@ import numpy as np from util.sqlset import TDSetSql class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(),False) self.rowNum = 10 diff --git a/tests/system-test/2-query/arccos.py b/tests/system-test/2-query/arccos.py index 1787521517ea8bb586908ee06b74aec8fed04191..ed717741c5c13af584b33e19f81d4b06593473d0 100644 --- a/tests/system-test/2-query/arccos.py +++ b/tests/system-test/2-query/arccos.py @@ -12,7 +12,8 @@ class TDTestCase: # updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , # "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, # "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} - def init(self, conn, powSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/arcsin.py b/tests/system-test/2-query/arcsin.py index 127419029b6851720ffb126c4741a9b4a8b62b95..71de08897936f2ba8e9d58ba7bd8e750205d6d7e 100644 --- a/tests/system-test/2-query/arcsin.py +++ b/tests/system-test/2-query/arcsin.py @@ -12,7 +12,8 @@ class TDTestCase: # updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , # "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, # "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} - def init(self, conn, powSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/arctan.py b/tests/system-test/2-query/arctan.py index e6ae16b8d9a9e22f3ea9a38da314b91e02d7db6e..9780f9855bbf0f3beb305768c5691d78dc16588a 100644 --- a/tests/system-test/2-query/arctan.py +++ b/tests/system-test/2-query/arctan.py @@ -12,7 +12,8 @@ class TDTestCase: # updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , # "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, # "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} - def init(self, conn, powSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/avg.py b/tests/system-test/2-query/avg.py index 5ba0a91a7e68c2aad9b2d5c2deb8984a9ba79095..ec7ec34ed3547b6d0d005e05903b5214b5b3d284 100644 --- a/tests/system-test/2-query/avg.py +++ b/tests/system-test/2-query/avg.py @@ -10,7 +10,8 @@ class TDTestCase: # updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , # "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, # "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) self.setsql = TDSetSql() diff --git a/tests/system-test/2-query/between.py b/tests/system-test/2-query/between.py index a9dde5617d589aaa97ae420217a31e6210e6d545..719852ff275d628abb73d2f62c4be3407379f56d 100644 --- a/tests/system-test/2-query/between.py +++ b/tests/system-test/2-query/between.py @@ -9,7 +9,8 @@ from util.cases import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/bottom.py b/tests/system-test/2-query/bottom.py index e75fde3ed44a11c3d1853177d437cf4b95dc108e..76052301d93bd5dd35ed96568c57666a127f412e 100644 --- a/tests/system-test/2-query/bottom.py +++ b/tests/system-test/2-query/bottom.py @@ -21,7 +21,8 @@ from util.sqlset import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.dbname = 'db_test' diff --git a/tests/system-test/2-query/cast.py b/tests/system-test/2-query/cast.py index 4045b6ad88106e9fed718d00f08b3c113236ac91..e6542c7c2bc6b91e501098baf45562cadb07b599 100644 --- a/tests/system-test/2-query/cast.py +++ b/tests/system-test/2-query/cast.py @@ -12,9 +12,10 @@ from util.dnodes import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") - tdSql.init(conn.cursor()) + tdSql.init(conn.cursor(), True) self.dbname = "db" def __cast_to_bigint(self, col_name, tbname): @@ -653,6 +654,58 @@ class TDTestCase: tdSql.query(f"select cast(c9 as timestamp ) as b from {self.dbname}.ct4") tdSql.query(f"select cast(c9 as binary(64) ) as b from {self.dbname}.ct4") + # enh of cast function about coverage + + tdSql.query(f"select cast(c1 as int) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c1 as bool) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c1 as tinyint) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c1 as smallint) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c1 as float) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c1 as double) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c1 as tinyint unsigned) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c1 as smallint unsigned) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c1 as int unsigned) as b from {self.dbname}.stb1") + + tdSql.query(f"select cast(c2 as int) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c3 as bool) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c4 as tinyint) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c5 as smallint) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c6 as float) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c7 as double) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c8 as tinyint unsigned) as b from {self.dbname}.stb1") + + tdSql.query(f"select cast(c8 as timestamp ) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c9 as timestamp ) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c9 as binary(64) ) as b from {self.dbname}.stb1") + + tdSql.query(f"select cast(abs(c2) as int) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c3 as bool) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(floor(c4) as tinyint) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c5+2 as smallint) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(2 as float) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c7 as double) as b from {self.dbname}.stb1") + tdSql.query(f"select cast('123' as tinyint unsigned) as b from {self.dbname}.stb1") + + tdSql.query(f"select max(cast(abs(c2) as int)) as b from {self.dbname}.stb1") + tdSql.query(f"select log(cast(c3 as int),2) as b from {self.dbname}.stb1") + tdSql.query(f"select abs(cast(floor(c4) as tinyint)) as b from {self.dbname}.stb1") + tdSql.query(f"select last(cast(c5+2 as smallint)) as b from {self.dbname}.stb1") + tdSql.query(f"select mavg(cast(2 as float),3) as b from {self.dbname}.stb1 partition by tbname") + tdSql.query(f"select cast(c7 as double) as b from {self.dbname}.stb1 partition by tbname order by tbname") + tdSql.query(f"select cast('123' as tinyint unsigned) as b from {self.dbname}.stb1 partition by tbname") + + # uion with cast and common cols + + tdSql.query(f"select cast(c2 as int) as b from {self.dbname}.stb1 union all select c1 from {self.dbname}.stb1 ") + tdSql.query(f"select cast(c3 as bool) as b from {self.dbname}.stb1 union all select c7 from {self.dbname}.ct1 ") + tdSql.query(f"select cast(c4 as tinyint) as b from {self.dbname}.stb1 union all select c4 from {self.dbname}.stb1") + tdSql.query(f"select cast(c5 as smallint) as b from {self.dbname}.stb1 union all select cast(c5 as smallint) as b from {self.dbname}.stb1") + tdSql.query(f"select cast(c6 as float) as b from {self.dbname}.stb1 union all select c5 from {self.dbname}.stb1") + tdSql.query(f"select cast(c7 as double) as b from {self.dbname}.stb1 union all select 123 from {self.dbname}.stb1 ") + tdSql.query(f"select cast(c8 as tinyint unsigned) as b from {self.dbname}.stb1 union all select last(cast(c8 as tinyint unsigned)) from {self.dbname}.stb1") + + + def run(self): tdSql.prepare() diff --git a/tests/system-test/2-query/ceil.py b/tests/system-test/2-query/ceil.py index 6777b449f9c5fb396c5f62673c2ef933e9bd4eaf..fffd484720b2ce7396340e2c75dd9acabe44c248 100644 --- a/tests/system-test/2-query/ceil.py +++ b/tests/system-test/2-query/ceil.py @@ -13,7 +13,8 @@ class TDTestCase: # "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, # "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/char_length.py b/tests/system-test/2-query/char_length.py index c0883e665ec84d7c63108c274cecd3956bb8d4b2..e42e5e4f2cb14aeb42a861853fe0f780d9ce378a 100644 --- a/tests/system-test/2-query/char_length.py +++ b/tests/system-test/2-query/char_length.py @@ -26,7 +26,8 @@ TS_TYPE_COL = [TS_COL] class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/check_tsdb.py b/tests/system-test/2-query/check_tsdb.py index f504a55dcd74ccc078eab1545164d1ee8353a9d2..b3ff259cc5c2d845968e1616b92b978bb2389fdd 100644 --- a/tests/system-test/2-query/check_tsdb.py +++ b/tests/system-test/2-query/check_tsdb.py @@ -12,7 +12,8 @@ class TDTestCase: # updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , # "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, # "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/2-query/concat.py b/tests/system-test/2-query/concat.py index 23b964012ab24ae4eb4ed34b0fc679813a070e37..326f6940f615460d585c05c153d228b4eb751d9f 100644 --- a/tests/system-test/2-query/concat.py +++ b/tests/system-test/2-query/concat.py @@ -26,7 +26,8 @@ TS_TYPE_COL = [ TS_COL, ] class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/concat2.py b/tests/system-test/2-query/concat2.py index 544222007607e5dddb10f9347f86a603b6aebdd3..a7e61444fe94aef68be870b29e892d8bd87f805e 100644 --- a/tests/system-test/2-query/concat2.py +++ b/tests/system-test/2-query/concat2.py @@ -26,7 +26,8 @@ TS_TYPE_COL = [ TS_COL, ] class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/concat_ws.py b/tests/system-test/2-query/concat_ws.py index ad784d92ec28ffc8da74eaa5bffa15a78c46a019..26731715c1f62a12ba8586da5eebe5d7358c2f9a 100644 --- a/tests/system-test/2-query/concat_ws.py +++ b/tests/system-test/2-query/concat_ws.py @@ -26,7 +26,8 @@ TS_TYPE_COL = [ TS_COL, ] class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/concat_ws2.py b/tests/system-test/2-query/concat_ws2.py index caaae6cecb655a69bddb64919eb5509a4b4faa9a..bf340826b604c591d8127e412411b712ebaf7858 100644 --- a/tests/system-test/2-query/concat_ws2.py +++ b/tests/system-test/2-query/concat_ws2.py @@ -26,7 +26,8 @@ TS_TYPE_COL = [ TS_COL, ] class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/cos.py b/tests/system-test/2-query/cos.py index ab6814727e597f03b1989770bbb3e29af4ab2669..d6bddc4e84597e8ddda9405e68c381848a688750 100644 --- a/tests/system-test/2-query/cos.py +++ b/tests/system-test/2-query/cos.py @@ -12,7 +12,8 @@ class TDTestCase: # updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 , # "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, # "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"udfDebugFlag":143} - def init(self, conn, powSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/count.py b/tests/system-test/2-query/count.py index 4d2a1cf07ce530f0cfd156981f8dcf1c5d5f135a..254a8792af0078292b9860698a2f9054a14bafba 100644 --- a/tests/system-test/2-query/count.py +++ b/tests/system-test/2-query/count.py @@ -3,7 +3,8 @@ from util.sql import * from util.cases import * from util.sqlset import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(),False) self.setsql = TDSetSql() diff --git a/tests/system-test/2-query/countAlwaysReturnValue.py b/tests/system-test/2-query/countAlwaysReturnValue.py new file mode 100644 index 0000000000000000000000000000000000000000..08c5ae104f2a7472423345ee1e52dd3e89d53fd0 --- /dev/null +++ b/tests/system-test/2-query/countAlwaysReturnValue.py @@ -0,0 +1,115 @@ +import taos +import sys +import datetime +import inspect + +from util.log import * +from util.sql import * +from util.cases import * +import random + + +class TDTestCase: + updatecfgDict = {"countAlwaysReturnValue":0} + + def init(self, conn, logSql, replicaVar=1): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor(), False) + + def prepare_data(self, dbname="db"): + tdSql.execute( + f"create database if not exists {dbname} keep 3650 duration 1000") + tdSql.execute(f"use {dbname} ") + tdSql.execute( + f"create table {dbname}.tb (ts timestamp, c0 int)" + ) + tdSql.execute( + f"create table {dbname}.stb (ts timestamp, c0 int) tags (t0 int)" + ) + tdSql.execute( + f"create table {dbname}.ctb1 using {dbname}.stb tags (1)" + ) + tdSql.execute( + f"create table {dbname}.ctb2 using {dbname}.stb tags (2)" + ) + + tdSql.execute( + f"insert into {dbname}.tb values (now(), NULL)") + + tdSql.execute( + f"insert into {dbname}.ctb1 values (now(), NULL)") + + tdSql.execute( + f"insert into {dbname}.ctb2 values (now() + 1s, NULL)") + + def test_results(self, dbname="db"): + + # count + tdSql.query(f"select count(c0) from {dbname}.tb") + tdSql.checkRows(0) + + tdSql.query(f"select count(NULL) from {dbname}.tb") + tdSql.checkRows(0) + + tdSql.query(f"select c0,count(c0) from {dbname}.tb group by c0") + tdSql.checkRows(1) + tdSql.checkData(0, 0, None) + + tdSql.query(f"select count(c0) from {dbname}.stb") + tdSql.checkRows(0) + + tdSql.query(f"select count(NULL) from {dbname}.stb") + tdSql.checkRows(0) + + tdSql.query(f"select c0,count(c0) from {dbname}.stb group by c0") + tdSql.checkRows(1) + tdSql.checkData(0, 0, None) + + tdSql.query(f"select count(NULL)") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + # hyperloglog + tdSql.query(f"select hyperloglog(c0) from {dbname}.tb") + tdSql.checkRows(0) + + tdSql.query(f"select hyperloglog(NULL) from {dbname}.tb") + tdSql.checkRows(0) + + tdSql.query(f"select c0,hyperloglog(c0) from {dbname}.tb group by c0") + tdSql.checkRows(1) + tdSql.checkData(0, 0, None) + + tdSql.query(f"select hyperloglog(c0) from {dbname}.stb") + tdSql.checkRows(0) + + tdSql.query(f"select hyperloglog(NULL) from {dbname}.stb") + tdSql.checkRows(0) + + tdSql.query(f"select c0,hyperloglog(c0) from {dbname}.stb group by c0") + tdSql.checkRows(1) + tdSql.checkData(0, 0, None) + + tdSql.query(f"select hyperloglog(NULL)") + tdSql.checkRows(1) + tdSql.checkData(0, 0, 0) + + def run(self): + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:prepare data ==============") + + self.prepare_data() + + tdLog.printNoPrefix("==========step2:test results ==============") + + self.test_results() + + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/count_partition.py b/tests/system-test/2-query/count_partition.py index 90a6d9225b76fcc500c886645e9f304299d4180c..f59376a9799d0f8fcf2adfbf5738545ef322e6a3 100644 --- a/tests/system-test/2-query/count_partition.py +++ b/tests/system-test/2-query/count_partition.py @@ -4,7 +4,8 @@ from util.sql import * from util.cases import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/csum.py b/tests/system-test/2-query/csum.py index 83aaca8f12468671272c1c39e715ac6a66c24c49..e933eb54cba45cca46ef79f555ff12147ac4d6c7 100644 --- a/tests/system-test/2-query/csum.py +++ b/tests/system-test/2-query/csum.py @@ -26,7 +26,8 @@ from util.dnodes import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/system-test/2-query/db.py b/tests/system-test/2-query/db.py index f2d85ebf6599970f99c302f080cda0b3ef6f3320..7fe8b9615751dfb2086ddb9f0cc062d8fe2cc600 100644 --- a/tests/system-test/2-query/db.py +++ b/tests/system-test/2-query/db.py @@ -11,7 +11,8 @@ import random class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/2-query/diff.py b/tests/system-test/2-query/diff.py index ceef3f93ebe09b68f0e8760df7ad40678b35110f..d48a01db6af023966ec9fc8307d93cfab37c4f87 100644 --- a/tests/system-test/2-query/diff.py +++ b/tests/system-test/2-query/diff.py @@ -6,7 +6,8 @@ import numpy as np class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) @@ -93,8 +94,19 @@ class TDTestCase: tdSql.error(f"select diff(col12) from {dbname}.stb_1") tdSql.error(f"select diff(col13) from {dbname}.stb_1") tdSql.error(f"select diff(col14) from {dbname}.stb_1") + tdSql.error(f"select diff(col14) from {dbname}.stb_1") + tdSql.error(f"select diff(col1,col1,col1) from {dbname}.stb_1") + tdSql.error(f"select diff(col1,1,col1) from {dbname}.stb_1") + tdSql.error(f"select diff(col1,col1,col) from {dbname}.stb_1") + tdSql.error(f"select diff(col1,col1) from {dbname}.stb_1") + tdSql.error(f"select diff(col1,'123') from {dbname}.stb_1") + tdSql.error(f"select diff(col1,1.23) from {dbname}.stb_1") + tdSql.error(f"select diff(col1,-1) from {dbname}.stb_1") tdSql.query(f"select ts,diff(col1),ts from {dbname}.stb_1") + tdSql.query(f"select diff(ts) from {dbname}.stb_1") + tdSql.checkRows(10) + tdSql.query(f"select diff(col1) from {dbname}.stb_1") tdSql.checkRows(10) diff --git a/tests/system-test/2-query/distinct.py b/tests/system-test/2-query/distinct.py index 7214caec969f89090f7cc1db28ae787a5de84b17..5c07544d5d45cb99b6fdf05e63f6b0d04441ef8b 100644 --- a/tests/system-test/2-query/distinct.py +++ b/tests/system-test/2-query/distinct.py @@ -9,7 +9,8 @@ from util.cases import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/distribute_agg_apercentile.py b/tests/system-test/2-query/distribute_agg_apercentile.py index 9b8ec2ece83522311080f6cf055e222755e1428d..897580fbcc17b47ab0c8920c3136c3e8b77e3561 100644 --- a/tests/system-test/2-query/distribute_agg_apercentile.py +++ b/tests/system-test/2-query/distribute_agg_apercentile.py @@ -8,7 +8,8 @@ import random class TDTestCase: updatecfgDict = {"maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.vnode_disbutes = None diff --git a/tests/system-test/2-query/distribute_agg_avg.py b/tests/system-test/2-query/distribute_agg_avg.py index c54b89a2ba1909d4f9ed9dfc8367958544a17bd2..1cd24103f88cdb259070f73620e267db237e0f42 100644 --- a/tests/system-test/2-query/distribute_agg_avg.py +++ b/tests/system-test/2-query/distribute_agg_avg.py @@ -9,7 +9,8 @@ import platform class TDTestCase: updatecfgDict = {"maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.vnode_disbutes = None diff --git a/tests/system-test/2-query/distribute_agg_count.py b/tests/system-test/2-query/distribute_agg_count.py index f61b6d7c2e25548063d45d477d7ef9f9135bcebc..7d131cd77d7fb9616e9ececf2b4c2f4a8498104a 100644 --- a/tests/system-test/2-query/distribute_agg_count.py +++ b/tests/system-test/2-query/distribute_agg_count.py @@ -8,7 +8,8 @@ import random class TDTestCase: updatecfgDict = {"maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.vnode_disbutes = None diff --git a/tests/system-test/2-query/distribute_agg_max.py b/tests/system-test/2-query/distribute_agg_max.py index 51b0ad4f94838e517e340df0b27740e089bade12..fb91216c3ea692005ce8aab684525a915dfd42bc 100644 --- a/tests/system-test/2-query/distribute_agg_max.py +++ b/tests/system-test/2-query/distribute_agg_max.py @@ -9,7 +9,8 @@ class TDTestCase: updatecfgDict = {"maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.vnode_disbutes = None diff --git a/tests/system-test/2-query/distribute_agg_min.py b/tests/system-test/2-query/distribute_agg_min.py index 543142ddfa07bc3e42d24ffb41eb98d09a629f67..266779864011c0bc8573c6888914f52acf530b4b 100644 --- a/tests/system-test/2-query/distribute_agg_min.py +++ b/tests/system-test/2-query/distribute_agg_min.py @@ -9,7 +9,8 @@ class TDTestCase: updatecfgDict = {"maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.vnode_disbutes = None diff --git a/tests/system-test/2-query/distribute_agg_spread.py b/tests/system-test/2-query/distribute_agg_spread.py index 222bd7315e3f4a640e65d4c1531ae4ada25328bc..0247a91861a8bbe9689dabfc50c21f5a6f8d064e 100644 --- a/tests/system-test/2-query/distribute_agg_spread.py +++ b/tests/system-test/2-query/distribute_agg_spread.py @@ -8,7 +8,8 @@ import random class TDTestCase: updatecfgDict = {"maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to execute {__file__}") tdSql.init(conn.cursor()) self.vnode_disbutes = None diff --git a/tests/system-test/2-query/distribute_agg_stddev.py b/tests/system-test/2-query/distribute_agg_stddev.py index 6b77fc7368df1850d7ffc817a7fb1a1f4f40d1a8..80bab3082d3fe84fa39bfaedeca9d85e07f338c1 100644 --- a/tests/system-test/2-query/distribute_agg_stddev.py +++ b/tests/system-test/2-query/distribute_agg_stddev.py @@ -9,7 +9,8 @@ import math class TDTestCase: updatecfgDict = {"maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.vnode_disbutes = None diff --git a/tests/system-test/2-query/distribute_agg_sum.py b/tests/system-test/2-query/distribute_agg_sum.py index 9be4602fd93d8d6878b368d9c37df00fbb2aac96..da26fd58f9348b6995d6fc6bc2600ee63b4e4828 100644 --- a/tests/system-test/2-query/distribute_agg_sum.py +++ b/tests/system-test/2-query/distribute_agg_sum.py @@ -9,7 +9,8 @@ import platform class TDTestCase: updatecfgDict = {"maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.vnode_disbutes = None diff --git a/tests/system-test/2-query/elapsed.py b/tests/system-test/2-query/elapsed.py index 333c60286e68ea20daf465d4c8670a569377a852..dc89cd513d206cb5d74b540ba41d584785934552 100644 --- a/tests/system-test/2-query/elapsed.py +++ b/tests/system-test/2-query/elapsed.py @@ -20,7 +20,8 @@ from util.sql import * from util.dnodes import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) @@ -86,13 +87,20 @@ class TDTestCase: ''' return - def prepare_data(self): + def prepare_db(self,dbname,vgroupVar): + + tdLog.info (" ====================================== prepare db ==================================================") + tdSql.execute('drop database if exists testdb ;') + tdSql.execute('create database %s keep 36500 vgroups %d ;'%(dbname,vgroupVar)) + + + def prepare_data(self,dbname): tdLog.info (" ====================================== prepare data ==================================================") - tdSql.execute('drop database if exists testdb ;') - tdSql.execute('create database testdb keep 36500;') - tdSql.execute('use testdb;') + # tdSql.execute('drop database if exists testdb ;') + # tdSql.execute('create database testdb keep 36500;') + tdSql.execute('use %s;'%dbname) tdSql.execute('create stable stable_1(ts timestamp ,tscol timestamp, q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint, q_float float ,\ q_double double , bin_chars binary(20)) tags(loc nchar(20) ,ind int,tstag timestamp);') @@ -1305,17 +1313,26 @@ class TDTestCase: # ts can't be used at outer query - tdSql.query("select elapsed(ts,1s) from (select ts from regular_table_1 );") + tdSql.query("select elapsed(ts,1s) from (select ts from stable_1 );") # case : TD-12164 - tdSql.error("select elapsed(ts,1s) from (select qint ts from regular_table_1 );") - tdSql.error("select elapsed(tbname ,1s) from (select qint tbname from regular_table_1 );") - tdSql.error("select elapsed(tsc ,1s) from (select q_int tsc from regular_table_1) ;") - tdSql.error("select elapsed(tsv ,1s) from (select elapsed(ts,1s) tsv from regular_table_1);") - tdSql.error("select elapsed(ts ,1s) from (select elapsed(ts,1s) ts from regular_table_1);") + tdSql.error("select elapsed(ts,1s) from (select qint ts from stable_1 );") + tdSql.error("select elapsed(tbname ,1s) from (select qint tbname from stable_1 );") + tdSql.error("select elapsed(tsc ,1s) from (select q_int tsc from stable_1) ;") + tdSql.error("select elapsed(tsv ,1s) from (select elapsed(ts,1s) tsv from stable_1);") + tdSql.error("select elapsed(ts ,1s) from (select elapsed(ts,1s) ts from stable_1);") # # bug fix - tdSql.error("select elapsed(tsc ,1s) from (select tscol tsc from regular_table_1) ;") + tdSql.error("select elapsed(tsc ,1s) from (select tscol tsc from stable_1) ;") + + #TD-19911 + tdSql.error("select elapsed(ts,1s,123) from (select ts,tbname from stable_1 order by ts asc );") + tdSql.error("select elapsed() from (select ts,tbname from stable_1 order by ts asc );") + tdSql.error("select elapsed(tscol,1s) from (select ts,tbname from stable_1 order by ts asc );") + tdSql.error("select elapsed(ts,1n) from (select ts,tbname from stable_1 order by ts asc );") + tdSql.error("select elapsed(ts,1y) from (select ts,tbname from stable_1 order by ts asc );") + tdSql.error("select elapsed(ts,tscol) from (select ts,tbname from stable_1 order by ts asc );") + tdSql.error("select elapsed(bin_chars,tscol) from (select ts,tbname from stable_1 order by ts asc );") # case TD-12276 tdSql.query("select elapsed(ts,1s) from (select ts,tbname from regular_table_1 order by ts asc );") @@ -1525,7 +1542,6 @@ class TDTestCase: def query_precision(self): def generate_data(precision="ms"): - tdSql.execute("create database if not exists db_%s precision '%s';" %(precision, precision)) tdSql.execute("use db_%s;" %precision) tdSql.execute("create stable db_%s.st (ts timestamp , id int) tags(ind int);"%precision) @@ -1579,7 +1595,9 @@ class TDTestCase: def run(self): tdSql.prepare() - self.prepare_data() + dbNameTest="testdbV1" + self.prepare_db(dbNameTest,1) + self.prepare_data(dbNameTest) self.abnormal_common_test() self.abnormal_use_test() self.query_filter() @@ -1596,6 +1614,25 @@ class TDTestCase: self.continuous_query() self.query_precision() + dbNameTest="testdbV2" + self.prepare_db(dbNameTest,2) + self.prepare_data(dbNameTest) + self.abnormal_common_test() + self.abnormal_use_test() + self.query_filter() + # self.query_interval() + self.query_mix_common() + self.query_mix_Aggregate() + self.query_mix_select() + self.query_mix_compute() + self.query_mix_arithmetic() + # self.query_with_join() + # self.query_with_union() + self.query_nest() + self.query_session_windows() + self.continuous_query() + # self.query_precision() + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tests/system-test/2-query/explain.py b/tests/system-test/2-query/explain.py index 21e16fab43e34e0d1a8a778dd5590820477511b7..f164d3aedf0a4af3f7080aa299a185b4219297fb 100644 --- a/tests/system-test/2-query/explain.py +++ b/tests/system-test/2-query/explain.py @@ -30,7 +30,8 @@ ALL_COL = [ INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, BOOL_C DBNAME = "db" class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), logSql) diff --git a/tests/system-test/2-query/first.py b/tests/system-test/2-query/first.py index 1aa51f8bb7f512590f03b1edf79736e98e9ae2f8..5b5b596a572bd4dd3475d4c4058a1fc075c6c2cc 100644 --- a/tests/system-test/2-query/first.py +++ b/tests/system-test/2-query/first.py @@ -23,7 +23,8 @@ import numpy as np class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/floor.py b/tests/system-test/2-query/floor.py index 793a56c1e52bb9b3368dd297f6f429461bab9ff7..6a75872bcfa1115468568413ccfe483063591d08 100644 --- a/tests/system-test/2-query/floor.py +++ b/tests/system-test/2-query/floor.py @@ -12,7 +12,8 @@ DBNAME = "db" class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/function_diff.py b/tests/system-test/2-query/function_diff.py index 946453bb23137d6ebbb67f8d588a67e054f5c2f1..4abef0303730933f02b2bdc45248aa57d02d3bf5 100644 --- a/tests/system-test/2-query/function_diff.py +++ b/tests/system-test/2-query/function_diff.py @@ -26,7 +26,8 @@ from util.dnodes import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/function_null.py b/tests/system-test/2-query/function_null.py index 93b46d2da12136c6816740451b6e7cf708fa391d..44b86ee54357f69c98fda435dedf2234f0b9b75e 100644 --- a/tests/system-test/2-query/function_null.py +++ b/tests/system-test/2-query/function_null.py @@ -11,7 +11,8 @@ import random class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) self.tb_nums = 10 diff --git a/tests/system-test/2-query/function_stateduration.py b/tests/system-test/2-query/function_stateduration.py index fec09e786bc7fcc72559067f6e046398f8500cac..ad9b8b0d79f680ccd6a909e9f6a353d27b77328b 100644 --- a/tests/system-test/2-query/function_stateduration.py +++ b/tests/system-test/2-query/function_stateduration.py @@ -5,7 +5,8 @@ from util.cases import * DBNAME = "db" class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/histogram.py b/tests/system-test/2-query/histogram.py index 1dc5bdfa21dc468e28a5a9829ef0d9b39fabf885..cc6e8fe7e93c4c30040f15617a8fff2b749e2b85 100644 --- a/tests/system-test/2-query/histogram.py +++ b/tests/system-test/2-query/histogram.py @@ -48,10 +48,12 @@ DBNAME = "db" STBNAME = "stb1" CTBNAME = "ct1" NTBNAME = "nt1" +PARAINF = float("inf") @dataclass class Hsgschema: + func_type : str = "SELECT" from_clause : str = f"{STBNAME}" where_clause : str = None @@ -142,7 +144,8 @@ class Hsgschema: class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) @@ -269,7 +272,7 @@ class TDTestCase: else: tdLog.success(f"summary of result count is {sum_rate}!") - else: + def hsg_check_error(self, sma:Hsgschema, dbname=DBNAME): tdSql.error(self.__gen_sql(sma, dbname)) @property @@ -304,7 +307,9 @@ class TDTestCase: err_sqls.append( Hsgschema( col=INT_COL, bin_type="USER_INPUT", user_input="[0,3,6,9,'a']", normalized=1 ) ) err_sqls.append( Hsgschema( col=INT_COL, bin_type="USER_INPUT", user_input="['a']", normalized=1 ) ) err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin=['{"start": 1, "width": 3, "count": 10, "infinity": false}'], normalized=1 ) ) - err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='[{"start": 1, "width": 3, "count": 10, "infinity": false}]', normalized=1 ) ) + # err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "width": 2, "count": 10, "infinity": false}', normalized=1 , "123" ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "width": float("inf"), "count": 10, "infinity": false}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": float("inf"), "width": 10, "count": 10, "infinity": false}', normalized=1 ) ) err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"begin": 1, "width": 3, "count": 10, "infinity": false}', normalized=1 ) ) err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "length": 3, "count": 10, "infinity": false}', normalized=1 ) ) err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "width": 3, "num": 10, "infinity": false}', normalized=1 ) ) @@ -319,9 +324,15 @@ class TDTestCase: err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "width": 1, "count": -10, "infinity": false}', normalized=1 ) ) err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "width": 1, "count": 10, "infinity": "false"}', normalized=1 ) ) err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 1, "width": 1, "count": 10, "infinity": null}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin=['{"start": 1, "factor": 4, "count": 4, "infinity": true}'], normalized=1 ) ) err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='[{"start": 1, "factor": 4, "count": 4, "infinity": true}]', normalized=1 ) ) err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"begin": 1, "factor": 4, "count": 4, "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": -10, "count": 4, "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 0, "count": 4, "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 0, "count": 4, "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": -10, "width": NULL, "count": 4, "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "step": 4, "count": 4, "infinity": true}', normalized=1 ) ) err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 4, "num": 4, "infinity": true}', normalized=1 ) ) err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 4, "count": 4, "witgnull": true}', normalized=1 ) ) @@ -335,6 +346,13 @@ class TDTestCase: err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": -10, "count": 4, "infinity": true}', normalized=1 ) ) err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": 0, "infinity": true}', normalized=1 ) ) err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": -10, "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": 10001, "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": "123", "infinity": true}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": float("inf"), "infinity": false}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": float("inf"), "count": 10, "infinity": false}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": float("inf"), "factor": 10, "count": 10, "infinity": false}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": float("-inf"), "factor": 10, "count": 10, "infinity": false}', normalized=1 ) ) + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": 10, "infinity": "true"}', normalized=1 ) ) err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": 10, "infinity": null}', normalized=1 ) ) err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": 10, "infinity": false}', where_clause=f"count({INT_COL}) >= 0 ") ) @@ -347,6 +365,51 @@ class TDTestCase: err_sqls.append( Hsgschema( col=BOOL_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": 10, "count": 10, "infinity": false}') ) + # add testcase by chr + err_sqls.append( Hsgschema( col=INT_COL, bin_type="USER_INPUT", user_input="[]", normalized=1 ) ) + + err_sqls.append( Hsgschema( col=INT_COL, bin_type="USER_INPUT", user_input="[1,'listStr',2]", normalized=1 ) ) + + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": %f, "width": 10000000, "count": 10000000, "infinity": false}'%PARAINF, normalized=1 ) ) + + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 2000, "width": %f, "count": 10, "infinity": false}'%PARAINF, normalized=1 ) ) + + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 10, "width": 10, "count": %f, "infinity": false}'%PARAINF, normalized=1 ) ) + + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor": %f, "count": 10, "infinity": false}'%PARAINF, normalized=1 ) ) + + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": %f, "width": %f, "count": %f, "infinity": false}'%(PARAINF,PARAINF,PARAINF), normalized=1 ) ) + + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 10, "width": 10, "count": 0, "infinity": false}', normalized=1 ) ) + + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 10, "width": 10, "count": -10, "infinity": false}', normalized=1 ) ) + + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 10, "width": 10, "count": 1001, "infinity": false}', normalized=1 ) ) + + err_sqls.append( Hsgschema( col=INT_COL, bin_type="linear_bin", linear_bin='{"start": 10, "width": 10, "count": 1001, "infinity": false , "linerBinNumber":5}', normalized=1 ) ) + + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor":-100, "count": 10, "infinity": false}', normalized=1 ) ) + + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor":0, "count": 10, "infinity": false}', normalized=1 ) ) + + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor":1, "count": 10, "infinity": false}', normalized=1 ) ) + + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": %f, "factor":10, "count": 10, "infinity": false}'%PARAINF, normalized=1 ) ) + + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor":10, "count": %f, "infinity": false}'%PARAINF, normalized=1 ) ) + + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor":10, "count": %f, "infinity": false}'%PARAINF, normalized=1 ) ) + + err_sqls.append( Hsgschema( col=INT_COL, bin_type="log_bin", log_bin='{"start": 1, "factor":10, "count": %f, "infinity": false, "logBinNumber":5}', normalized=1 ) ) + + err_sqls.append( Hsgschema(col={"errorColType": INT_COL}, bin_type="USER_INPUT", user_input="[0,3,6,9]", normalized=1) ) + + # err_sqls.append( Hsgschema(col=INT_COL, bin_type=, user_input="[0,3,6,9]", normalized=1) ) + # err_sqls.append( Hsgschema(col=INT_COL, bin_type="USER_INPUT", user_input="[0,3,6,9]", normalized=1) ) + # err_sqls.append( Hsgschema(col=INT_COL, bin_type="USER_INPUT", user_input="[0,3,6,9]", normalized=1) ) + + + ### case 2: # current_set @@ -386,7 +449,7 @@ class TDTestCase: def test_histogram(self, dbname=DBNAME, ctb_num :int=20): err_sqls , cur_sqls = self.__hsg_querysql for err_sql in err_sqls: - self.hsg_check(err_sql, dbname) + self.hsg_check_error(err_sql, dbname) for cur_sql in cur_sqls: self.hsg_check(cur_sql, dbname) @@ -404,6 +467,44 @@ class TDTestCase: tdSql.checkData(0, 0, '{"lower_bin":0, "upper_bin":3, "count":3}') tdSql.checkData(1, 0, '{"lower_bin":3, "upper_bin":6, "count":3}') tdSql.checkData(2, 0, '{"lower_bin":6, "upper_bin":9, "count":3}') + + #error sql + # tdSql.error(f"SELECT HISTOGRAM(c_int, 'linear_bin', '{"start": -200, "width": 100, "count": 20, "infinity": false}', 0 ,1 ) from {dbname}.nt1 where c_int < 10") + + # tdSql.error(f"SELECT HISTOGRAM(c_int, 'linear_bin', '{"start": -200, "width": 100, "count": -10, "infinity": false}', 0 ) from {dbname}.nt1 where c_int < 10") + + # tdSql.error(f"SELECT HISTOGRAM(c_int, 'linear_bin', '{"start": -200, "width": 100, "count": 1001, "infinity": false}', 0 ) from {dbname}.nt1 where c_int < 10") + + tdSql.error(f"SELECT HISTOGRAM(c_int, 'log_bin', '[0,3,6,9]', 0 ,1 ) from {dbname}.nt1 where c_int < 10") + + tdSql.error(f"SELECT HISTOGRAM(c_int, 'USER_INPUT', '[0,3,6,9]', 0 ,1 ) from {dbname}.nt1 where c_int < 10") + tdSql.error(f"SELECT HISTOGRAM(c_int, 'USER_INPUT', '[0,3,6,9]' ) from {dbname}.nt1 where c_int < 10") + tdSql.error(f"SELECT HISTOGRAM('123', 'USER_INPUT', '[0,3,6,9]', 0 ) from {dbname}.nt1 where c_int < 10") + tdSql.error(f"SELECT HISTOGRAM('123', 123 ,123 ,123 ) from {dbname}.nt1 where c_int < 10") + tdSql.error(f"SELECT HISTOGRAM(123, '123' ,'123' ,'123' ) from {dbname}.nt1 where c_int < 10") + + # if (4 != numOfParams) + # tdSql.error("select HISTOGRAM(c_int, \"linear_bin\", \"{\"start\": -200, \"width\": 100, \"count\": 20, \"infinity\": false}\", 1 , InvalidNumber) from db.stb1 where c_int < 10") + tdSql.error('SELECT HISTOGRAM(c_int, "linear_bin", \'{"start": -200, "width": 100, "count": 20, "infinity": false}\', 0 ,InvalidNumber ) from %s.stb1 '%dbname) + tdSql.error('SELECT HISTOGRAM(c_int, "linear_bin", \'{"start": -200, "width": 100, "count": 20, "infinity": false}\' ) from %s.stb1 '%dbname) + tdSql.error('SELECT HISTOGRAM(c_int, 54321, "[0,3,6,9]", 1 ) from %s.stb1 '%dbname) + tdSql.error('SELECT HISTOGRAM(c_int, "USER_INPUT", 54321, 0 ) from %s.stb1'%dbname) + tdSql.error('SELECT HISTOGRAM(c_int, "USER_INPUT", "[0,3,6,9]", InvalidNumber ) from %s.stb1'%dbname) + tdSql.error('SELECT HISTOGRAM(c_int, "USER_INPUT", "[0,3,6,9]", -100 ) from %s.stb1'%dbname) + tdSql.error('SELECT HISTOGRAM(c_int, c_int, "[0,3,6,9]", 1 ) from %s.stb1'%dbname) + tdSql.error('SELECT HISTOGRAM(c_int, "USER_INPUT", c_int, 1 ) from %s.stb1'%dbname) + tdSql.error('SELECT HISTOGRAM(c_int, "USER_INPUT", "[0,3,6,9]", c_int ) from %s.stb1'%dbname) + tdSql.query('SELECT HISTOGRAM(123, "USER_INPUT", "[0,3,6,9]", 0 ) from %s.stb1'%dbname) + tdSql.error('SELECT HISTOGRAM(c_binary, "USER_INPUT", "[0,3,6,9]", 0 ) from %s.stb1'%dbname) + tdSql.error('SELECT HISTOGRAM("c_binary", "USER_INPUT", "[0,3,6,9]", 0 ) from %s.stb1'%dbname) + tdSql.query('SELECT HISTOGRAM(123, "linear_bin", \'{"start": 1, "width": 10, "count": 20, "infinity": false}\',0 ) from %s.stb1 '%dbname) + tdSql.error('SELECT HISTOGRAM(c_binary, "linear_bin", \'{"start": 1, "width": 10, "count": 20, "infinity": false}\',0 ) from %s.stb1 '%dbname) + tdSql.error('SELECT HISTOGRAM("c_binary", "linear_bin", \'{"start": 1, "width": 10, "count": 20, "infinity": false}\',0 ) from %s.stb1 '%dbname) + + tdSql.error('SELECT HISTOGRAM(c_int, "c_int", \'{"start": 1, "width": 10, "count": 20, "infinity": false}\',0 ) from %s.stb1 '%dbname) + tdSql.error('SELECT HISTOGRAM(c_int, "linear_bin", c_int,0 ) from %s.stb1 '%dbname) + tdSql.error('SELECT HISTOGRAM(c_int, "linear_bin", \'{"start": 1, "width": 10, "count": 20, "infinity": false}\',c_int ) from %s.stb1 '%dbname) + def all_test(self, dbname=DBNAME): self.test_histogram(dbname) diff --git a/tests/system-test/2-query/hyperloglog.py b/tests/system-test/2-query/hyperloglog.py index 68f7ebdf2e45e42011dbea806707581ebefff56b..b6779509487f12824518cb5ba553d7681466686c 100644 --- a/tests/system-test/2-query/hyperloglog.py +++ b/tests/system-test/2-query/hyperloglog.py @@ -28,10 +28,11 @@ ALL_COL = [ INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, BOOL_C DBNAME = "db" class TDTestCase: - + updatecfgDict = {"maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/interp.py b/tests/system-test/2-query/interp.py index 3a05583418cd3fe11a099dbc7a4d1e3d22aa532b..ce6b85c1cff7cbe263453db1e2c286f80f53ddb0 100644 --- a/tests/system-test/2-query/interp.py +++ b/tests/system-test/2-query/interp.py @@ -9,7 +9,8 @@ from util.cases import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") #tdSql.init(conn.cursor()) tdSql.init(conn.cursor(), logSql) # output sql.txt file @@ -36,7 +37,7 @@ class TDTestCase: tdSql.execute(f"insert into {dbname}.{tbname} values ('2020-02-01 00:00:05', 5, 5, 5, 5, 5.0, 5.0, true, 'varchar', 'nchar')") tdSql.execute(f"insert into {dbname}.{tbname} values ('2020-02-01 00:00:10', 10, 10, 10, 10, 10.0, 10.0, true, 'varchar', 'nchar')") tdSql.execute(f"insert into {dbname}.{tbname} values ('2020-02-01 00:00:15', 15, 15, 15, 15, 15.0, 15.0, true, 'varchar', 'nchar')") - + tdSql.execute(f"insert into {dbname}.{tbname} (ts) values (now)") tdLog.printNoPrefix("==========step3:fill null") @@ -886,7 +887,7 @@ class TDTestCase: tdSql.query(f"select interp(c0),interp(c1),interp(c2),interp(c3),interp(c4),interp(c5) from {dbname}.{tbname} range('2020-02-09 00:00:05', '2020-02-13 00:00:05') every(1d) fill(linear)") tdSql.checkRows(3) tdSql.checkCols(6) - + for i in range (tdSql.queryCols): tdSql.checkData(0, i, 13) diff --git a/tests/system-test/2-query/irate.py b/tests/system-test/2-query/irate.py index 408f4b374950be29c0f6df06593fb3b216ff409f..cee595d1862fa0e6d55d08029427ac4003d4fb9d 100644 --- a/tests/system-test/2-query/irate.py +++ b/tests/system-test/2-query/irate.py @@ -11,7 +11,8 @@ import random ,math class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) self.tb_nums = 10 diff --git a/tests/system-test/2-query/join.py b/tests/system-test/2-query/join.py index 9d30e1946a16c487f22e43fe03461d559dc7c945..120cc2eb3074fbb3b78ade55f4328b57ddd461f3 100644 --- a/tests/system-test/2-query/join.py +++ b/tests/system-test/2-query/join.py @@ -63,7 +63,8 @@ class DataSet: class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/2-query/join2.py b/tests/system-test/2-query/join2.py index 5c8fe0f0f96e6c28aa1ef70240b3ef4d5b0598fa..7ddc5e57badeca1bd7e11efdab6d5f2fa1286207 100644 --- a/tests/system-test/2-query/join2.py +++ b/tests/system-test/2-query/join2.py @@ -26,7 +26,8 @@ TS_TYPE_COL = [ TS_COL, ] class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/2-query/json_tag.py b/tests/system-test/2-query/json_tag.py index d9715579aed4878c1cf17642824718d412a77511..1c2a6055bcf21522031f1eae519d8c082b311f78 100644 --- a/tests/system-test/2-query/json_tag.py +++ b/tests/system-test/2-query/json_tag.py @@ -13,7 +13,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/2-query/json_tag_large_tables.py b/tests/system-test/2-query/json_tag_large_tables.py index 9164c108f94ec9f538ba8d12ecc45be3b3b60e06..ea3963640a999fe8555418f9294aca2320c9cd54 100644 --- a/tests/system-test/2-query/json_tag_large_tables.py +++ b/tests/system-test/2-query/json_tag_large_tables.py @@ -30,7 +30,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) self.testcasePath = os.path.split(__file__)[0] self.testcaseFilename = os.path.split(__file__)[-1] # os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) diff --git a/tests/system-test/2-query/last.py b/tests/system-test/2-query/last.py index 3bca9f167108e71b591a825ed3dc3b5abb46f5df..f4a1ab17904069831f24901d00fe72fbd5556e2b 100644 --- a/tests/system-test/2-query/last.py +++ b/tests/system-test/2-query/last.py @@ -8,7 +8,8 @@ import numpy as np class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) @@ -17,6 +18,14 @@ class TDTestCase: self.ts = 1537146000000 self.binary_str = 'taosdata' self.nchar_str = '涛思数据' + self.cachemodel = None + + def generateString(self, length): + chars = string.ascii_uppercase + string.ascii_lowercase + v = "" + for i in range(length): + v += random.choice(chars) + return v def set_create_normaltable_sql(self, ntbname, column_dict): column_sql = '' @@ -36,7 +45,8 @@ class TDTestCase: return create_stb_sql def last_check_stb_tb_base(self): - tdSql.prepare() + tdSql.execute( + f'create database if not exists db cachemodel "{self.cachemodel}"') stbname = f'db.{tdCom.getLongName(5, "letters")}' column_dict = { 'col1': 'tinyint', @@ -112,7 +122,8 @@ class TDTestCase: tdSql.execute('drop database db') def last_check_ntb_base(self): - tdSql.prepare() + tdSql.execute( + f'create database if not exists db cachemodel "{self.cachemodel}"') ntbname = f'db.{tdCom.getLongName(5, "letters")}' column_dict = { 'col1': 'tinyint', @@ -165,6 +176,8 @@ class TDTestCase: # nchar elif 'nchar' in v.lower(): tdSql.checkData(0, 0, f'{self.nchar_str}{self.rowNum}') + + tdSql.error( f"select {list(column_dict.keys())[0]} from {ntbname} where last({list(column_dict.keys())[9]})='涛思数据10'") @@ -191,7 +204,7 @@ class TDTestCase: } tdSql.execute( - f"create database if not exists {dbname} vgroups {vgroup_num}") + f'create database if not exists {dbname} vgroups {vgroup_num} cachemodel "{self.cachemodel}"') tdSql.execute(f'use {dbname}') # build 20 child tables,every table insert 10 rows @@ -243,10 +256,45 @@ class TDTestCase: tdSql.checkData(0, 0, f'{self.nchar_str}{self.rowNum}') tdSql.execute(f'drop database {dbname}') + def last_file_check(self): + dbname = tdCom.getLongName(10, "letters") + stbname = f'{dbname}.{tdCom.getLongName(5, "letters")}' + vgroup_num = 10 + buffer_size = 3 + tables = 100 + rows = 50 + str = self.generateString(1024) + column_dict = { + 'c1': 'int', + 'c2': 'binary(1024)', + 'c3': 'nchar(1024)' + } + tag_dict = { + 't1':'int' + } + + tdSql.execute( + f"create database if not exists {dbname} vgroups {vgroup_num} buffer {buffer_size}") + tdSql.execute(f'use {dbname}') + + create_ntb_sql = self.set_create_stable_sql(stbname, column_dict, tag_dict) + tdSql.execute(create_ntb_sql) + + for i in range(tables): + sql = f"create table {dbname}.sub_tb{i} using {stbname} tags({i})" + tdSql.execute(sql) + for j in range(rows): + tdSql.execute(f"insert into {dbname}.sub_tb{i} values(%d, %d, '%s', '%s')" % (self.ts + j, i, str, str)) + + tdSql.query(f"select * from {stbname}") + tdSql.checkRows(tables * rows) + + def run(self): self.last_check_stb_tb_base() self.last_check_ntb_base() self.last_check_stb_distribute() + self.last_file_check() def stop(self): tdSql.close() diff --git a/tests/system-test/2-query/last_row.py b/tests/system-test/2-query/last_row.py index 6286852641a20020d8b3c517618603c2b5c84c0a..f8d6ce4c6cc51b2e76c6e662cc91d2e6a595a200 100644 --- a/tests/system-test/2-query/last_row.py +++ b/tests/system-test/2-query/last_row.py @@ -11,7 +11,8 @@ import random class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), True) self.tb_nums = 10 diff --git a/tests/system-test/2-query/leastsquares.py b/tests/system-test/2-query/leastsquares.py index fe7188a54547d9c63ae962b3330c6316d5672bba..8ece4c46f0d430ec540468467e8b9e89b35e1349 100644 --- a/tests/system-test/2-query/leastsquares.py +++ b/tests/system-test/2-query/leastsquares.py @@ -29,7 +29,8 @@ ALL_COL = [ INT_COL, BINT_COL, SINT_COL, TINT_COL, FLOAT_COL, DOUBLE_COL, BOOL_C DBNAME = "db" class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/length.py b/tests/system-test/2-query/length.py index 1761572245a8ca5a1c814e21c566ffb1634e419a..161ee20a9a3e1677117a7b1d7642f3399c6855e7 100644 --- a/tests/system-test/2-query/length.py +++ b/tests/system-test/2-query/length.py @@ -23,7 +23,8 @@ DBNAME = "db" class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/log.py b/tests/system-test/2-query/log.py index 358d2b9551a1ee8db9446babd2588ee47404ac67..7305a44f56b7b1aea6f0922bf1f9d33dde399606 100644 --- a/tests/system-test/2-query/log.py +++ b/tests/system-test/2-query/log.py @@ -11,7 +11,8 @@ from util.cases import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) @@ -229,6 +230,36 @@ class TDTestCase: tdSql.query(f"select log(c6 ,2) from {dbname}.ct3") tdSql.checkRows(0) + # log used for different param types + + tdSql.query(f"select log(c1,c2) from {dbname}.ct1;") + tdSql.query(f"select log(c1,c2) from {dbname}.stb1 partition by tbname order by tbname;") + + tdSql.query(f"select log(c1,2) from {dbname}.ct1;") + tdSql.query(f"select log(c1,2) from {dbname}.stb1 partition by tbname order by tbname;") + + tdSql.query(f"select log(2,c2) from {dbname}.ct1;") + tdSql.query(f"select log(2,c2) from {dbname}.stb1 partition by tbname order by tbname;") + + tdSql.query(f"select log(2,1) from {dbname}.ct1;") + tdSql.query(f"select log(2,2) from {dbname}.stb1 partition by tbname order by tbname;") + + tdSql.query(f"select log(2,floor(1)) from {dbname}.ct1;") + tdSql.query(f"select log(2,floor(2)) from {dbname}.stb1 partition by tbname order by tbname;") + + tdSql.query(f"select log(abs(2),floor(1)) from {dbname}.ct1;") + tdSql.query(f"select log(abs(2),floor(2)) from {dbname}.stb1 partition by tbname order by tbname;") + + tdSql.query(f"select log(abs(c2),c1) from {dbname}.ct1;") + tdSql.query(f"select log(abs(c2),c1) from {dbname}.stb1 partition by tbname order by tbname;") + + tdSql.query(f"select log(c2,abs(c1)) from {dbname}.ct1;") + tdSql.query(f"select log(c2,abs(c1)) from {dbname}.stb1 partition by tbname order by tbname;") + + tdSql.query(f"select log(abs(c2),2) from {dbname}.ct1;") + tdSql.query(f"select log(abs(c2),2) from {dbname}.stb1 partition by tbname order by tbname;") + + # # used for regular table tdSql.query(f"select log(c1 ,2) from {dbname}.t1") @@ -291,6 +322,7 @@ class TDTestCase: tdSql.query(f"select log(c1, 2) from {dbname}.stb1") tdSql.checkRows(25) + # used for not exists table tdSql.error(f"select log(c1, 2) from {dbname}.stbbb1") diff --git a/tests/system-test/2-query/lower.py b/tests/system-test/2-query/lower.py index 0e33e3834ec9ecc50470f0793b29a3a4b84d4834..4499047a04c98395b58b787673df158b701d069f 100644 --- a/tests/system-test/2-query/lower.py +++ b/tests/system-test/2-query/lower.py @@ -22,7 +22,8 @@ TS_TYPE_COL = [TS_COL] class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/ltrim.py b/tests/system-test/2-query/ltrim.py index 330f688990d614c1a824fd25741f19966e227581..193aa45198085ad560be2f2863c300206b960fd2 100644 --- a/tests/system-test/2-query/ltrim.py +++ b/tests/system-test/2-query/ltrim.py @@ -27,7 +27,8 @@ DBNAME = "db" class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/mavg.py b/tests/system-test/2-query/mavg.py index b52217af9ac61e5a3c08d55b11e4219ec826b203..ec4a087a8e032105f8c89e8ec302affc35d50bac 100644 --- a/tests/system-test/2-query/mavg.py +++ b/tests/system-test/2-query/mavg.py @@ -27,7 +27,8 @@ from util.dnodes import * dbname = 'db' class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/max.py b/tests/system-test/2-query/max.py index 5cc9a2d9e888425763914c01baeababfeebc6166..b8da02b9a6da6bfadc93d301d135464a1c7566f1 100644 --- a/tests/system-test/2-query/max.py +++ b/tests/system-test/2-query/max.py @@ -6,7 +6,8 @@ import numpy as np class TDTestCase: updatecfgDict = {"maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) @@ -45,6 +46,22 @@ class TDTestCase: tdSql.query(f"select max(col1) from {dbname}.stb where col2<=5") tdSql.checkData(0,0,5) + tdSql.query(f"select ts, max(col1) from {dbname}.stb") + tdSql.checkRows(1) + tdSql.checkData(0, 1, np.max(intData)) + + tdSql.query(f"select ts, max(col1) from {dbname}.stb_1") + tdSql.checkRows(1) + tdSql.checkData(0, 1, np.max(intData)) + + tdSql.query(f"select ts, min(col9) from {dbname}.stb") + tdSql.checkRows(1) + tdSql.checkData(0, 1, np.min(floatData)) + + tdSql.query(f"select ts, min(col9) from {dbname}.stb_1") + tdSql.checkRows(1) + tdSql.checkData(0, 1, np.min(floatData)) + def max_check_ntb_base(self, dbname="db"): tdSql.prepare() intData = [] diff --git a/tests/system-test/2-query/max_partition.py b/tests/system-test/2-query/max_partition.py index 08bb7675add128f94f6ab5be0b9a7a8c90e49afe..a9b7a14eb025a4eda794b7af364a4cac74d306e5 100644 --- a/tests/system-test/2-query/max_partition.py +++ b/tests/system-test/2-query/max_partition.py @@ -4,7 +4,8 @@ from util.sql import * from util.cases import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/min.py b/tests/system-test/2-query/min.py index d97c4340f4022af6372134892dba25c371af1b51..bf9993da647939699d4a5ef54f2391153a116d9c 100644 --- a/tests/system-test/2-query/min.py +++ b/tests/system-test/2-query/min.py @@ -6,7 +6,8 @@ import numpy as np class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/mode.py b/tests/system-test/2-query/mode.py new file mode 100644 index 0000000000000000000000000000000000000000..72bae552618f7e772481035c079a2d9507045d79 --- /dev/null +++ b/tests/system-test/2-query/mode.py @@ -0,0 +1,208 @@ +from random import randint, random +from numpy import equal +import taos +import sys +import datetime +import inspect + +from util.log import * +from util.sql import * +from util.cases import * + +class TDTestCase: + + def init(self, conn, logSql, replicaVar=1): + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + + def prepare_datas(self, dbname="db"): + tdSql.execute( + f'''create table {dbname}.stb + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + tags (t1 int) + ''' + ) + + tdSql.execute( + f''' + create table {dbname}.tb + (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp) + ''' + ) + for i in range(2): + tdSql.execute(f'create table {dbname}.ctb{i+1} using {dbname}.stb tags ( {i+1} )') + + tdSql.execute(f"insert into {dbname}.ctb1 values ('2020-12-11 00:00:00.000', 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )") + tdSql.execute(f"insert into {dbname}.ctb1 values ('2020-12-11 00:00:01.000', 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ctb1 values ('2020-12-11 00:00:02.000', 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )") + tdSql.execute(f"insert into {dbname}.ctb1 values ('2020-12-11 00:00:03.000', 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )") + + tdSql.execute(f"insert into {dbname}.ctb2 values ('2020-12-12 00:00:00.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ctb2 values ('2020-12-12 00:00:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + tdSql.execute(f"insert into {dbname}.ctb2 values ('2020-12-12 00:00:02.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ") + + tdSql.execute( + f'''insert into {dbname}.tb values + ( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a ) + ( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a ) + ( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now()+3a ) + ( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now()+4a ) + ( '2021-07-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now()+5a ) + ( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a ) + ( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" ) + ( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" ) + ( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" ) + ( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) + ''' + ) + + def check_mode_function(self, dbname="db"): + + # normal table + tdSql.query(f"select ts,mode(c1) from {dbname}.tb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2022, 12, 31, 1, 1, 36)) + tdSql.checkData(0, 1, 9) + + tdSql.query(f"select ts,mode(c2) from {dbname}.tb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2022, 12, 31, 1, 1, 36)) + tdSql.checkData(0, 1, -99999999999999999) + + tdSql.query(f"select ts,mode(c3) from {dbname}.tb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2022, 12, 31, 1, 1, 36)) + tdSql.checkData(0, 1, -999) + + tdSql.query(f"select ts,mode(c4) from {dbname}.tb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2022, 12, 31, 1, 1, 36)) + tdSql.checkData(0, 1, -99) + + tdSql.query(f"select ts,mode(c5) from {dbname}.tb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2022, 12, 31, 1, 1, 36)) + tdSql.checkData(0, 1, -9.99) + + tdSql.query(f"select ts,mode(c6) from {dbname}.tb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2022, 12, 31, 1, 1, 36)) + tdSql.checkData(0, 1, -1e+21) + + tdSql.query(f"select ts,mode(c7) from {dbname}.tb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2022, 12, 31, 1, 1, 36)) + tdSql.checkData(0, 1, True) + + tdSql.query(f"select ts,mode(c8) from {dbname}.tb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2022, 12, 31, 1, 1, 36)) + tdSql.checkData(0, 1, 'binary9') + + tdSql.query(f"select ts,mode(c9) from {dbname}.tb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2022, 12, 31, 1, 1, 36)) + tdSql.checkData(0, 1, 'nchar9') + + tdSql.query(f"select ts,c3,c5,c8,mode(c1) from {dbname}.tb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2022, 12, 31, 1, 1, 36)) + tdSql.checkData(0, 1, -999) + tdSql.checkData(0, 2, -9.99) + tdSql.checkData(0, 3, 'binary9') + tdSql.checkData(0, 4, 9) + + # super table + tdSql.query(f"select ts,mode(c1) from {dbname}.stb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2020, 12, 11, 0, 0, 3)) + tdSql.checkData(0, 1, 9) + + tdSql.query(f"select ts,mode(c2) from {dbname}.stb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2020, 12, 11, 0, 0, 3)) + tdSql.checkData(0, 1, -99999) + + tdSql.query(f"select ts,mode(c3) from {dbname}.stb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2020, 12, 11, 0, 0, 3)) + tdSql.checkData(0, 1, -999) + + tdSql.query(f"select ts,mode(c4) from {dbname}.stb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2020, 12, 11, 0, 0, 2)) + tdSql.checkData(0, 1, -99) + + tdSql.query(f"select ts,mode(c5) from {dbname}.stb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2020, 12, 11, 0, 0, 3)) + tdSql.checkData(0, 1, -9.99) + + tdSql.query(f"select ts,mode(c6) from {dbname}.stb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2020, 12, 11, 0, 0, 3)) + tdSql.checkData(0, 1, -99.99) + + tdSql.query(f"select ts,mode(c7) from {dbname}.stb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2020, 12, 11, 0, 0, 3)) + tdSql.checkData(0, 1, True) + + tdSql.query(f"select ts,mode(c8) from {dbname}.stb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2020, 12, 11, 0, 0, 3)) + tdSql.checkData(0, 1, 'binary9') + + tdSql.query(f"select ts,mode(c9) from {dbname}.stb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2020, 12, 11, 0, 0, 3)) + tdSql.checkData(0, 1, 'nchar9') + + tdSql.query(f"select ts,mode(c1),c3,c5,c8 from {dbname}.stb") + tdSql.checkRows(1) + ts = tdSql.getData(0, 0) + tdSql.checkEqual(ts, datetime.datetime(2020, 12, 11, 0, 0, 3)) + tdSql.checkData(0, 1, 9) + tdSql.checkData(0, 2, -999) + tdSql.checkData(0, 3, -9.99) + tdSql.checkData(0, 4, 'binary9') + + def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring + tdSql.prepare() + + tdLog.printNoPrefix("==========step1:create table ==============") + + self.prepare_datas() + + tdLog.printNoPrefix("==========step2:test results ==============") + + self.check_mode_function() + + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/nestedQuery.py b/tests/system-test/2-query/nestedQuery.py index c6567a8e3be0ca5640baf158f53b6f65039045a0..b1008efa86552162693860da4cc10ed96fa7805c 100755 --- a/tests/system-test/2-query/nestedQuery.py +++ b/tests/system-test/2-query/nestedQuery.py @@ -28,7 +28,8 @@ class TDTestCase: "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"fnDebugFlag":143} - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/system-test/2-query/percentile.py b/tests/system-test/2-query/percentile.py index 3b027ed6a03e9e13f8782b91c36fdc5bb558c64d..935f55a8c21b9ac986fc10c9580ebfbc944c851d 100644 --- a/tests/system-test/2-query/percentile.py +++ b/tests/system-test/2-query/percentile.py @@ -21,7 +21,8 @@ from util.sqlset import TDSetSql class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/pow.py b/tests/system-test/2-query/pow.py index 0702d05c0b7bf0989046ab1cfdfaa0d812c78407..a067d6654743891e55a1235a20a1ffe3f6998bb6 100644 --- a/tests/system-test/2-query/pow.py +++ b/tests/system-test/2-query/pow.py @@ -10,7 +10,8 @@ from util.cases import * class TDTestCase: - def init(self, conn, powSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) @@ -216,6 +217,36 @@ class TDTestCase: tdSql.checkRows(0) + # pow used for different param types + + tdSql.query(f"select pow(c1,c2) from {dbname}.ct1;") + tdSql.query(f"select pow(c1,c2) from {dbname}.stb1 partition by tbname order by tbname;") + + tdSql.query(f"select pow(c1,2) from {dbname}.ct1;") + tdSql.query(f"select pow(c1,2) from {dbname}.stb1 partition by tbname order by tbname;") + + tdSql.query(f"select pow(2,c2) from {dbname}.ct1;") + tdSql.query(f"select pow(2,c2) from {dbname}.stb1 partition by tbname order by tbname;") + + tdSql.query(f"select pow(2,1) from {dbname}.ct1;") + tdSql.query(f"select pow(2,2) from {dbname}.stb1 partition by tbname order by tbname;") + + tdSql.query(f"select pow(2,floor(1)) from {dbname}.ct1;") + tdSql.query(f"select pow(2,floor(2)) from {dbname}.stb1 partition by tbname order by tbname;") + + tdSql.query(f"select pow(abs(2),floor(1)) from {dbname}.ct1;") + tdSql.query(f"select pow(abs(2),floor(2)) from {dbname}.stb1 partition by tbname order by tbname;") + + tdSql.query(f"select pow(abs(c2),c1) from {dbname}.ct1;") + tdSql.query(f"select pow(abs(c2),c1) from {dbname}.stb1 partition by tbname order by tbname;") + + tdSql.query(f"select pow(c2,abs(c1)) from {dbname}.ct1;") + tdSql.query(f"select pow(c2,abs(c1)) from {dbname}.stb1 partition by tbname order by tbname;") + + tdSql.query(f"select pow(abs(c2),2) from {dbname}.ct1;") + tdSql.query(f"select pow(abs(c2),2) from {dbname}.stb1 partition by tbname order by tbname;") + + # # used for regular table tdSql.query(f"select pow(c1 ,2) from {dbname}.t1") tdSql.checkData(0, 0, None) diff --git a/tests/system-test/2-query/qnodeCluster.py b/tests/system-test/2-query/qnodeCluster.py index 9e49bff9389deeb83839477c98e194c014a2a87f..d15ef89eb8438ee10eefe80b702a7a1d83e46790 100644 --- a/tests/system-test/2-query/qnodeCluster.py +++ b/tests/system-test/2-query/qnodeCluster.py @@ -26,7 +26,8 @@ class TDTestCase: updatecfgDict = {'keepColumnName': 1} updatecfgDict["clientCfg"] = clientCfgDict - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/2-query/queryQnode.py b/tests/system-test/2-query/queryQnode.py index 7bd573d7fc454ed7856be148ed526d44e273f4a9..fec553436c04f6b1cca231dc917874de4a883f5f 100644 --- a/tests/system-test/2-query/queryQnode.py +++ b/tests/system-test/2-query/queryQnode.py @@ -64,7 +64,8 @@ class TDTestCase: return buildPath # init - def init(self, conn, logSql=True): + def init(self, conn, logSql=True, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) # tdSql.prepare() diff --git a/tests/system-test/2-query/query_cols_tags_and_or.py b/tests/system-test/2-query/query_cols_tags_and_or.py index af3fbb83c070202368f317b119377035ac133e16..b8d4e3c3145640093b62e5e3e166b9f5326b2127 100644 --- a/tests/system-test/2-query/query_cols_tags_and_or.py +++ b/tests/system-test/2-query/query_cols_tags_and_or.py @@ -16,7 +16,8 @@ from util.sql import tdSql from util.common import tdCom import random class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) ## add for TD-6672 tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/2-query/round.py b/tests/system-test/2-query/round.py index 1d69d3c9afa1d7fffc3b8eac80c2b648a54bc74e..e3d98d698613c8620adfcaaeae0be72cec42fa15 100644 --- a/tests/system-test/2-query/round.py +++ b/tests/system-test/2-query/round.py @@ -9,7 +9,8 @@ from util.cases import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/rtrim.py b/tests/system-test/2-query/rtrim.py index 80307e8534787889b080baa0c25a32b638c49461..effb596e1d6d3ffd24d344cb2c0d945c1eddc9d9 100644 --- a/tests/system-test/2-query/rtrim.py +++ b/tests/system-test/2-query/rtrim.py @@ -26,7 +26,8 @@ TS_TYPE_COL = [ TS_COL, ] class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/sample.py b/tests/system-test/2-query/sample.py index 7f1d7ab8c0d62fb4db7386caf3b4eeca4b3f8cba..a09d6a2b856bca40f1df55673c7d8e555f1df0f6 100644 --- a/tests/system-test/2-query/sample.py +++ b/tests/system-test/2-query/sample.py @@ -24,7 +24,8 @@ DBNAME = "db" class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.ts = 1537146000000 diff --git a/tests/system-test/2-query/select_index.py b/tests/system-test/2-query/select_index.py new file mode 100755 index 0000000000000000000000000000000000000000..e18b688663bbd014acfe69403cff0b6f81fedb55 --- /dev/null +++ b/tests/system-test/2-query/select_index.py @@ -0,0 +1,721 @@ +################################################################### +# 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 random +import os +import time +import taos +import subprocess +from faker import Faker +from util.log import tdLog +from util.cases import tdCases +from util.sql import tdSql +from util.dnodes import tdDnodes +from util.dnodes import * + +class TDTestCase: + updatecfgDict = {'maxSQLLength':1048576,'debugFlag': 143 ,"querySmaOptimize":1} + + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + self.testcasePath = os.path.split(__file__)[0] + self.testcaseFilename = os.path.split(__file__)[-1] + os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) + + self.db = "ind_sel" + + def dropandcreateDB_random(self,database,n,vgroups): + ts = 1630000000000 + num_random = 100 + fake = Faker('zh_CN') + tdSql.execute('''drop database if exists %s ;''' %database) + tdSql.execute('''create database %s keep 36500 vgroups %d ;'''%(database,vgroups)) + tdSql.execute('''use %s;'''%database) + + tdSql.execute('''create stable %s.stable_1 (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ + q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ + q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \ + tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);'''%database) + tdSql.execute('''create stable %s.stable_2 (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) \ + tags(loc nchar(100) , t_int int , t_bigint bigint , t_smallint smallint , t_tinyint tinyint, t_bool bool , t_binary binary(100) , t_nchar nchar(100) ,t_float float , t_double double , t_ts timestamp);'''%database) + + for i in range(10*n): + tdSql.execute('''create table %s.bj_%d (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp ) ;'''%(database,i)) + tdSql.execute('''create table %s.sh_%d (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp ) ;'''%(database,i)) + tdSql.execute('''create table %s.bj_table_%d_r (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp ) ;'''%(database,i)) + tdSql.execute('''create table %s.sh_table_%d_r (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp ) ;'''%(database,i)) + tdSql.execute('''create table %s.hn_table_%d_r \ + (ts timestamp , q_int int , q_bigint bigint , q_smallint smallint , q_tinyint tinyint , q_float float , q_double double , q_bool bool , q_binary binary(100) , q_nchar nchar(100) , q_ts timestamp , \ + q_binary1 binary(100) , q_nchar1 nchar(100) ,q_binary2 binary(100) , q_nchar2 nchar(100) ,q_binary3 binary(100) , q_nchar3 nchar(100) ,q_binary4 binary(100) , q_nchar4 nchar(100) ,\ + q_binary5 binary(100) , q_nchar5 nchar(100) ,q_binary6 binary(100) , q_nchar6 nchar(100) ,q_binary7 binary(100) , q_nchar7 nchar(100) ,q_binary8 binary(100) , q_nchar8 nchar(100) ,\ + q_int_null int , q_bigint_null bigint , q_smallint_null smallint , q_tinyint_null tinyint, q_float_null float , q_double_null double , q_bool_null bool , q_binary_null binary(20) , q_nchar_null nchar(20) , q_ts_null timestamp) ;'''%(database,i)) + tdSql.execute('''create table %s.bj_stable_1_%d using %s.stable_1 tags('bj_stable_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' + %(database,i,database,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) + tdSql.execute('''create table %s.sh_table_%d_a using %s.stable_1 tags('sh_a_table_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' + %(database,i,database,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) + tdSql.execute('''create table %s.sh_table_%d_b using %s.stable_1 tags('sh_b_table_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' + %(database,i,database,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) + tdSql.execute('''create table %s.sh_table_%d_c using %s.stable_1 tags('sh_c_table_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' + %(database,i,database,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) + + tdSql.execute('''create table %s.bj_table_%d_a using %s.stable_1 tags('bj_a_table_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' + %(database,i,database,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) + tdSql.execute('''create table %s.bj_table_%d_b using %s.stable_1 tags('bj_b_table_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' + %(database,i,database,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) + tdSql.execute('''create table %s.bj_table_%d_c using %s.stable_1 tags('bj_c_table_1_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' + %(database,i,database,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) + + + tdSql.execute('''create table %s.tj_table_%d_a using %s.stable_2 tags('tj_a_table_2_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' + %(database,i,database,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) + tdSql.execute('''create table %s.tj_table_%d_b using %s.stable_2 tags('tj_b_table_2_%d', '%d' , '%d', '%d' , '%d' , 1 , 'binary1.%s' , 'nchar1.%s' , '%f', '%f' ,'%d') ;''' + %(database,i,database,i,fake.random_int(min=-2147483647, max=2147483647, step=1), fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pystr() ,fake.pystr() ,fake.pyfloat(),fake.pyfloat(),fake.random_int(min=-2147483647, max=2147483647, step=1))) + + # insert data + for i in range(num_random*n): + tdSql.execute('''insert into %s.bj_stable_1_1 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double , q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (database,ts + i*1000, fake.random_int(min=-2147483647, max=2147483647, step=1), + fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1), + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + tdSql.execute('''insert into %s.hn_table_1_r (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (database,ts + i*1000, fake.random_int(min=-2147483647, max=2147483647, step=1) , + fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1) , + fake.random_int(min=-32767, max=32767, step=1) , fake.random_int(min=-127, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + + tdSql.execute('''insert into %s.bj_stable_1_2 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8)\ + values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (database,ts + i*1000, fake.random_int(min=0, max=2147483647, step=1), + fake.random_int(min=0, max=9223372036854775807, step=1), + fake.random_int(min=0, max=32767, step=1) , fake.random_int(min=0, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + tdSql.execute('''insert into %s.hn_table_2_r (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 1, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (database,ts + i*1000, fake.random_int(min=0, max=2147483647, step=1), + fake.random_int(min=0, max=9223372036854775807, step=1), + fake.random_int(min=0, max=32767, step=1) , fake.random_int(min=0, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + + tdSql.execute('''insert into %s.bj_stable_1_3 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (database,ts + i*1000, fake.random_int(min=-0, max=2147483647, step=1), + fake.random_int(min=-0, max=9223372036854775807, step=1), + fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + + tdSql.execute('''insert into %s.bj_stable_1_4 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (database,ts + i*1000 +1, fake.random_int(min=-0, max=2147483647, step=1), + fake.random_int(min=-0, max=9223372036854775807, step=1), + fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + + tdSql.execute('''insert into %s.bj_stable_1_5 (ts , q_int , q_bigint , q_smallint , q_tinyint , q_float , q_double, q_bool , q_binary , q_nchar, q_ts,\ + q_binary1 , q_nchar1 , q_binary2 , q_nchar2 , q_binary3 , q_nchar3 , q_binary4 , q_nchar4 , q_binary5 , q_nchar5 , q_binary6 , q_nchar6 , q_binary7 , q_nchar7, q_binary8 , q_nchar8) \ + values(%d, %d, %d, %d, %d, %f, %f, 0, 'binary.%s', 'nchar.%s', %d, 'binary1.%s', 'nchar1.%s', 'binary2.%s', 'nchar2.%s', 'binary3.%s', 'nchar3.%s', \ + 'binary4.%s', 'nchar4.%s', 'binary5.%s', 'nchar5.%s', 'binary6.%s', 'nchar6.%s', 'binary7.%s', 'nchar7.%s', 'binary8.%s', 'nchar8.%s') ;''' + % (database,ts + i*1000 +10, fake.random_int(min=-0, max=2147483647, step=1), + fake.random_int(min=-0, max=9223372036854775807, step=1), + fake.random_int(min=-0, max=32767, step=1) , fake.random_int(min=-0, max=127, step=1) , + fake.pyfloat() , fake.pyfloat() , fake.pystr() , fake.pystr() , ts + i, fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , + fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr() , fake.pystr())) + + tdSql.query("select count(*) from %s.stable_1;" %database) + tdSql.checkData(0,0,5*num_random*n) + tdSql.query("select count(*) from %s.hn_table_1_r;"%database) + tdSql.checkData(0,0,num_random*n) + + def func_index_check(self,database,func,column): + fake = Faker('zh_CN') + fake_data = fake.random_int(min=1, max=20, step=1) + tdLog.info("\n=============constant(%s)_check ====================\n" %func) + tdSql.execute(" create sma index sma_index_name1 on stable_1 function(%s(%s)) interval(%dm); " %(func,column,fake_data)) + sql = " select %s(%s) from %s.stable_1 interval(1m) "%(func,column,database) + tdLog.info(sql) + tdSql.query(sql) + queryRows = len(tdSql.queryResult) + for i in range(queryRows): + print("row=%d, result=%s " %(i,tdSql.queryResult[i][0])) + flush_before_value = tdSql.queryResult[i][0] + + tdLog.info("\n=============flush database ====================\n") + + tdSql.execute(" flush database %s;" %database) + + tdSql.query(sql) + queryRows = len(tdSql.queryResult) + for i in range(queryRows): + print("row=%d, result=%s " %(i,tdSql.queryResult[i][0])) + flush_after_value = tdSql.queryResult[i][0] + + self.value_check(flush_before_value,flush_after_value) + + tdLog.info("\n=============drop index ====================\n") + + tdSql.execute(" drop index sma_index_name1;") + + tdSql.query(sql) + queryRows = len(tdSql.queryResult) + for i in range(queryRows): + print("row=%d, result=%s " %(i,tdSql.queryResult[i][0])) + drop_index_value = tdSql.queryResult[i][0] + + self.value_check(flush_before_value,drop_index_value) + + + def constant_check(self,database,func,column): + tdLog.info("\n=============constant(%s)_check ====================\n" %column) + sql = " select %s(%s) from %s.stable_1 "%(func,column,database) + sql_no_from = " select %s(%s) "%(func,column) + + tdLog.info(sql) + tdSql.query(sql) + queryRows = len(tdSql.queryResult) + for i in range(queryRows): + print("row=%d, result=%s " %(i,tdSql.queryResult[i][0])) + flush_before_value = tdSql.queryResult[i][0] + + tdLog.info(sql_no_from) + tdSql.query(sql_no_from) + queryRows = len(tdSql.queryResult) + for i in range(queryRows): + print("row=%d, result=%s " %(i,tdSql.queryResult[i][0])) + flush_before_value_no_from = tdSql.queryResult[i][0] + + tdLog.info("\n=============flush database ====================\n") + + tdSql.execute(" flush database %s;" %database) + + tdSql.query(sql) + queryRows = len(tdSql.queryResult) + for i in range(queryRows): + print("row=%d, result=%s " %(i,tdSql.queryResult[i][0])) + flush_after_value = tdSql.queryResult[i][0] + + self.value_check(flush_before_value,flush_after_value) + + tdSql.query(sql_no_from) + queryRows = len(tdSql.queryResult) + for i in range(queryRows): + print("row=%d, result=%s " %(i,tdSql.queryResult[i][0])) + flush_after_value_no_from = tdSql.queryResult[i][0] + + self.value_check(flush_before_value_no_from,flush_after_value_no_from) + + def constant_table_check(self,database,func,column): + tdLog.info("\n=============constant(%s)_check ====================\n" %column) + sql = " select %s(%s) from %s.bj_stable_1_1 "%(func,column,database) + sql_no_from = " select %s(%s) "%(func,column) + + tdLog.info(sql) + tdSql.query(sql) + queryRows = len(tdSql.queryResult) + for i in range(queryRows): + print("row=%d, result=%s " %(i,tdSql.queryResult[i][0])) + flush_before_value = tdSql.queryResult[i][0] + + tdLog.info(sql_no_from) + tdSql.query(sql_no_from) + queryRows = len(tdSql.queryResult) + for i in range(queryRows): + print("row=%d, result=%s " %(i,tdSql.queryResult[i][0])) + flush_before_value_no_from = tdSql.queryResult[i][0] + + tdLog.info("\n=============flush database ====================\n") + + tdSql.execute(" flush database %s;" %database) + + tdSql.query(sql) + queryRows = len(tdSql.queryResult) + for i in range(queryRows): + print("row=%d, result=%s " %(i,tdSql.queryResult[i][0])) + flush_after_value = tdSql.queryResult[i][0] + + self.value_check(flush_before_value,flush_after_value) + + tdSql.query(sql_no_from) + queryRows = len(tdSql.queryResult) + for i in range(queryRows): + print("row=%d, result=%s " %(i,tdSql.queryResult[i][0])) + flush_after_value_no_from = tdSql.queryResult[i][0] + + self.value_check(flush_before_value_no_from,flush_after_value_no_from) + + def constant_str_check(self,database,func,column): + tdLog.info("\n=============constant(%s)_check ====================\n" %column) + sql = " select %s('%s') from %s.stable_1 "%(func,column,database) + tdLog.info(sql) + tdSql.query(sql) + queryRows = len(tdSql.queryResult) + for i in range(queryRows): + print("row=%d, result=%s " %(i,tdSql.queryResult[i][0])) + flush_before_value = tdSql.queryResult[i][0] + + tdLog.info("\n=============flush database ====================\n") + + tdSql.execute(" flush database %s;" %database) + + tdSql.query(sql) + queryRows = len(tdSql.queryResult) + for i in range(queryRows): + print("row=%d, result=%s " %(i,tdSql.queryResult[i][0])) + flush_after_value = tdSql.queryResult[i][0] + + self.value_check(flush_before_value,flush_after_value) + + + def constant_error_check(self,database,func,column): + tdLog.info("\n=============constant(%s)_check ====================\n" %column) + error_sql = " select %s('%s') "%(func,column) + tdLog.info(error_sql) + tdSql.error(error_sql) + + tdLog.info("\n=============flush database ====================\n") + + tdSql.execute(" flush database %s;" %database) + + tdSql.error(error_sql) + + error_sql1 = " select %s('%s') from %s.stable_1 "%(func,column,database) + tdLog.info(error_sql1) + tdSql.error(error_sql1) + error_sql2 = " select %s('%s') from %s.bj_stable_1_1 "%(func,column,database) + tdLog.info(error_sql2) + tdSql.error(error_sql2) + + def derivative_sql(self,database): + fake = Faker('zh_CN') + fake_data = fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1) + tdLog.info("\n=============derivative sql ====================\n" ) + sql = " select derivative(%s,%ds,0) from %s.stable_1 "%('q_smallint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,0) from %s.stable_1 "%('q_bigint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,0) from %s.stable_1 "%('q_tinyint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,0) from %s.stable_1 "%('q_int',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,0) from %s.stable_1 "%('q_float',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,0) from %s.stable_1 "%('q_double',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 "%('q_smallint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 "%('q_bigint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 "%('q_tinyint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 "%('q_int',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 "%('q_float',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 "%('q_double',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,0) from %s.stable_1 order by ts"%('q_smallint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,0) from %s.stable_1 order by ts "%('q_bigint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,0) from %s.stable_1 order by ts "%('q_tinyint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,0) from %s.stable_1 order by ts "%('q_int',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,0) from %s.stable_1 order by ts "%('q_float',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,0) from %s.stable_1 order by ts "%('q_double',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 order by ts "%('q_smallint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 order by ts "%('q_bigint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 order by ts "%('q_tinyint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 order by ts "%('q_int',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 order by ts "%('q_float',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 order by ts "%('q_double',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,0) from %s.stable_1 order by ts desc"%('q_smallint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,0) from %s.stable_1 order by ts desc "%('q_bigint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,0) from %s.stable_1 order by ts desc "%('q_tinyint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,0) from %s.stable_1 order by ts desc "%('q_int',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,0) from %s.stable_1 order by ts desc "%('q_float',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,0) from %s.stable_1 order by ts desc "%('q_double',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 order by ts desc "%('q_smallint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 order by ts desc "%('q_bigint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 order by ts desc "%('q_tinyint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 order by ts desc "%('q_int',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 order by ts desc "%('q_float',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 order by ts desc"%('q_double',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + + sql = " select derivative(%s,%ds,1) from %s.stable_1 order by ts desc limit 3000"%('q_smallint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 order by ts desc limit 3000 "%('q_bigint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 order by ts desc limit 3000 "%('q_tinyint',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 order by ts desc limit 3000 "%('q_int',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 order by ts desc limit 3000 "%('q_float',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + sql = " select derivative(%s,%ds,1) from %s.stable_1 order by ts desc limit 3000"%('q_double',fake_data,database) + self.derivative_data_check("%s" %self.db,"%s" %sql) + + def derivative_data_check(self,database,sql): + tdLog.info("\n=============derivative_data(%s)_check ====================\n" %sql) + tdLog.info(sql) + tdSql.query(sql) + queryRows = len(tdSql.queryResult) + for i in range(queryRows): + #print("row=%d, result=%s " %(i,tdSql.queryResult[i][0])) + flush_before_value = tdSql.queryResult[i][0] + #flush_before_value1 = tdSql.queryResult[i][1] + + tdLog.info("\n=============flush database ====================\n") + + tdSql.execute(" flush database %s;" %database) + + tdSql.query(sql) + queryRows = len(tdSql.queryResult) + for i in range(queryRows): + #print("row=%d, result=%s " %(i,tdSql.queryResult[i][0])) + flush_after_value = tdSql.queryResult[i][0] + #flush_after_value1 = tdSql.queryResult[i][1] + + self.value_check(flush_before_value,flush_after_value) + #self.value_check(flush_before_value1,flush_after_value1) + + + def value_check(self,flush_before_value,flush_after_value): + # if flush_before_value==flush_after_value: + # tdLog.info(f"checkEqual success, flush_before_value={flush_before_value},flush_after_value={flush_after_value}") + # else : + # tdLog.exit(f"checkEqual error, flush_before_value=={flush_before_value},flush_after_value={flush_after_value}") + pass + + def run(self): + fake = Faker('zh_CN') + fake_data = fake.random_int(min=-9223372036854775807, max=9223372036854775807, step=1) + fake_float = fake.pyfloat() + fake_str = fake.pystr() + + startTime = time.time() + + os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) + + self.dropandcreateDB_random("%s" %self.db, 1,2) + + #TD-19818 + self.func_index_check("%s" %self.db,'max','q_int') + self.func_index_check("%s" %self.db,'max','q_bigint') + self.func_index_check("%s" %self.db,'max','q_smallint') + self.func_index_check("%s" %self.db,'max','q_tinyint') + self.func_index_check("%s" %self.db,'max','q_float') + self.func_index_check("%s" %self.db,'max','q_double') + + self.func_index_check("%s" %self.db,'min','q_int') + self.func_index_check("%s" %self.db,'min','q_bigint') + self.func_index_check("%s" %self.db,'min','q_smallint') + self.func_index_check("%s" %self.db,'min','q_tinyint') + self.func_index_check("%s" %self.db,'min','q_float') + self.func_index_check("%s" %self.db,'min','q_double') + + self.func_index_check("%s" %self.db,'SUM','q_int') + self.func_index_check("%s" %self.db,'SUM','q_bigint') + self.func_index_check("%s" %self.db,'SUM','q_smallint') + self.func_index_check("%s" %self.db,'SUM','q_tinyint') + self.func_index_check("%s" %self.db,'SUM','q_float') + self.func_index_check("%s" %self.db,'SUM','q_double') + + #TD-19854 + self.constant_check("%s" %self.db,'count','%d' %fake_data) + self.constant_check("%s" %self.db,'count','%f' %fake_float) + self.constant_str_check("%s" %self.db,'count','%s' %fake_str) + self.constant_check("%s" %self.db,'count','(cast(%d as int))' %fake_data) + self.constant_check("%s" %self.db,'count','(cast(%f as int))' %fake_float) + self.constant_check("%s" %self.db,'count','(cast(%d as smallint))' %fake_data) + self.constant_check("%s" %self.db,'count','(cast(%f as smallint))' %fake_float) + self.constant_check("%s" %self.db,'count','(cast(%d as bigint))' %fake_data) + self.constant_check("%s" %self.db,'count','(cast(%f as bigint))' %fake_float) + self.constant_check("%s" %self.db,'count','(cast(%d as tinyint))' %fake_data) + self.constant_check("%s" %self.db,'count','(cast(%f as tinyint))' %fake_float) + self.constant_check("%s" %self.db,'count','(cast(%d as float))' %fake_data) + self.constant_check("%s" %self.db,'count','(cast(%f as float))' %fake_float) + self.constant_check("%s" %self.db,'count','(cast(%d as double))' %fake_data) + self.constant_check("%s" %self.db,'count','(cast(%f as double))' %fake_float) + + self.constant_check("%s" %self.db,'sum','%d' %fake_data) + self.constant_check("%s" %self.db,'sum','%f' %fake_float) + self.constant_error_check("%s" %self.db,'sum','%s' %fake_str) + self.constant_check("%s" %self.db,'sum','(cast(%d as int))' %fake_data) + self.constant_check("%s" %self.db,'sum','(cast(%f as int))' %fake_float) + self.constant_check("%s" %self.db,'sum','(cast(%d as smallint))' %fake_data) + self.constant_check("%s" %self.db,'sum','(cast(%f as smallint))' %fake_float) + self.constant_check("%s" %self.db,'sum','(cast(%d as bigint))' %fake_data) + self.constant_check("%s" %self.db,'sum','(cast(%f as bigint))' %fake_float) + self.constant_check("%s" %self.db,'sum','(cast(%d as tinyint))' %fake_data) + self.constant_check("%s" %self.db,'sum','(cast(%f as tinyint))' %fake_float) + self.constant_check("%s" %self.db,'sum','(cast(%d as float))' %fake_data) + self.constant_check("%s" %self.db,'sum','(cast(%f as float))' %fake_float) + self.constant_check("%s" %self.db,'sum','(cast(%d as double))' %fake_data) + self.constant_check("%s" %self.db,'sum','(cast(%f as double))' %fake_float) + + self.constant_check("%s" %self.db,'avg','%d' %fake_data) + self.constant_check("%s" %self.db,'avg','%f' %fake_float) + self.constant_error_check("%s" %self.db,'avg','%s' %fake_str) + self.constant_check("%s" %self.db,'avg','(cast(%d as int))' %fake_data) + self.constant_check("%s" %self.db,'avg','(cast(%f as int))' %fake_float) + self.constant_check("%s" %self.db,'avg','(cast(%d as smallint))' %fake_data) + self.constant_check("%s" %self.db,'avg','(cast(%f as smallint))' %fake_float) + self.constant_check("%s" %self.db,'avg','(cast(%d as bigint))' %fake_data) + self.constant_check("%s" %self.db,'avg','(cast(%f as bigint))' %fake_float) + self.constant_check("%s" %self.db,'avg','(cast(%d as tinyint))' %fake_data) + self.constant_check("%s" %self.db,'avg','(cast(%f as tinyint))' %fake_float) + self.constant_check("%s" %self.db,'avg','(cast(%d as float))' %fake_data) + self.constant_check("%s" %self.db,'avg','(cast(%f as float))' %fake_float) + self.constant_check("%s" %self.db,'avg','(cast(%d as double))' %fake_data) + self.constant_check("%s" %self.db,'avg','(cast(%f as double))' %fake_float) + + self.constant_check("%s" %self.db,'stddev','%d' %fake_data) + self.constant_check("%s" %self.db,'stddev','%f' %fake_float) + self.constant_error_check("%s" %self.db,'stddev','%s' %fake_str) + self.constant_check("%s" %self.db,'stddev','(cast(%d as int))' %fake_data) + self.constant_check("%s" %self.db,'stddev','(cast(%f as int))' %fake_float) + self.constant_check("%s" %self.db,'stddev','(cast(%d as smallint))' %fake_data) + self.constant_check("%s" %self.db,'stddev','(cast(%f as smallint))' %fake_float) + self.constant_check("%s" %self.db,'stddev','(cast(%d as bigint))' %fake_data) + self.constant_check("%s" %self.db,'stddev','(cast(%f as bigint))' %fake_float) + self.constant_check("%s" %self.db,'stddev','(cast(%d as tinyint))' %fake_data) + self.constant_check("%s" %self.db,'stddev','(cast(%f as tinyint))' %fake_float) + self.constant_check("%s" %self.db,'stddev','(cast(%d as float))' %fake_data) + self.constant_check("%s" %self.db,'stddev','(cast(%f as float))' %fake_float) + self.constant_check("%s" %self.db,'stddev','(cast(%d as double))' %fake_data) + self.constant_check("%s" %self.db,'stddev','(cast(%f as double))' %fake_float) + + self.constant_check("%s" %self.db,'spread','%d' %fake_data) + self.constant_check("%s" %self.db,'spread','%f' %fake_float) + self.constant_error_check("%s" %self.db,'spread','%s' %fake_str) + self.constant_check("%s" %self.db,'spread','(cast(%d as int))' %fake_data) + self.constant_check("%s" %self.db,'spread','(cast(%f as int))' %fake_float) + self.constant_check("%s" %self.db,'spread','(cast(%d as smallint))' %fake_data) + self.constant_check("%s" %self.db,'spread','(cast(%f as smallint))' %fake_float) + self.constant_check("%s" %self.db,'spread','(cast(%d as bigint))' %fake_data) + self.constant_check("%s" %self.db,'spread','(cast(%f as bigint))' %fake_float) + self.constant_check("%s" %self.db,'spread','(cast(%d as tinyint))' %fake_data) + self.constant_check("%s" %self.db,'spread','(cast(%f as tinyint))' %fake_float) + self.constant_check("%s" %self.db,'spread','(cast(%d as float))' %fake_data) + self.constant_check("%s" %self.db,'spread','(cast(%f as float))' %fake_float) + self.constant_check("%s" %self.db,'spread','(cast(%d as double))' %fake_data) + self.constant_check("%s" %self.db,'spread','(cast(%f as double))' %fake_float) + + self.constant_check("%s" %self.db,'hyperloglog','%d' %fake_data) + self.constant_check("%s" %self.db,'hyperloglog','%f' %fake_float) + self.constant_str_check("%s" %self.db,'hyperloglog','%s' %fake_str) + self.constant_check("%s" %self.db,'hyperloglog','(cast(%d as int))' %fake_data) + self.constant_check("%s" %self.db,'hyperloglog','(cast(%f as int))' %fake_float) + self.constant_check("%s" %self.db,'hyperloglog','(cast(%d as smallint))' %fake_data) + self.constant_check("%s" %self.db,'hyperloglog','(cast(%f as smallint))' %fake_float) + self.constant_check("%s" %self.db,'hyperloglog','(cast(%d as bigint))' %fake_data) + self.constant_check("%s" %self.db,'hyperloglog','(cast(%f as bigint))' %fake_float) + self.constant_check("%s" %self.db,'hyperloglog','(cast(%d as tinyint))' %fake_data) + self.constant_check("%s" %self.db,'hyperloglog','(cast(%f as tinyint))' %fake_float) + self.constant_check("%s" %self.db,'hyperloglog','(cast(%d as float))' %fake_data) + self.constant_check("%s" %self.db,'hyperloglog','(cast(%f as float))' %fake_float) + self.constant_check("%s" %self.db,'hyperloglog','(cast(%d as double))' %fake_data) + self.constant_check("%s" %self.db,'hyperloglog','(cast(%f as double))' %fake_float) + + self.constant_error_check("%s" %self.db,'elapsed','%d' %fake_data) + self.constant_error_check("%s" %self.db,'elapsed','%f' %fake_float) + self.constant_error_check("%s" %self.db,'elapsed','%s' %fake_str) + self.constant_error_check("%s" %self.db,'elapsed','(cast(%d as int))' %fake_data) + self.constant_error_check("%s" %self.db,'elapsed','(cast(%f as int))' %fake_float) + self.constant_error_check("%s" %self.db,'elapsed','(cast(%d as smallint))' %fake_data) + self.constant_error_check("%s" %self.db,'elapsed','(cast(%f as smallint))' %fake_float) + self.constant_error_check("%s" %self.db,'elapsed','(cast(%d as bigint))' %fake_data) + self.constant_error_check("%s" %self.db,'elapsed','(cast(%f as bigint))' %fake_float) + self.constant_error_check("%s" %self.db,'elapsed','(cast(%d as tinyint))' %fake_data) + self.constant_error_check("%s" %self.db,'elapsed','(cast(%f as tinyint))' %fake_float) + self.constant_error_check("%s" %self.db,'elapsed','(cast(%d as float))' %fake_data) + self.constant_error_check("%s" %self.db,'elapsed','(cast(%f as float))' %fake_float) + self.constant_error_check("%s" %self.db,'elapsed','(cast(%d as double))' %fake_data) + self.constant_error_check("%s" %self.db,'elapsed','(cast(%f as double))' %fake_float) + + percentile_data = fake.random_int(min=-0, max=100, step=1) + self.constant_table_check("%s" %self.db,'percentile','%d,%d' %(fake_data,percentile_data)) + self.constant_table_check("%s" %self.db,'percentile','%f,%d' %(fake_float,percentile_data)) + self.constant_error_check("%s" %self.db,'percentile','%s,%d' %(fake_str,percentile_data)) + self.constant_table_check("%s" %self.db,'percentile','(cast(%d as int)),%d' %(fake_data,percentile_data)) + self.constant_table_check("%s" %self.db,'percentile','(cast(%f as int)),%d' %(fake_float,percentile_data)) + self.constant_table_check("%s" %self.db,'percentile','(cast(%d as smallint)),%d' %(fake_data,percentile_data)) + self.constant_table_check("%s" %self.db,'percentile','(cast(%f as smallint)),%d' %(fake_float,percentile_data)) + self.constant_table_check("%s" %self.db,'percentile','(cast(%d as bigint)),%d' %(fake_data,percentile_data)) + self.constant_table_check("%s" %self.db,'percentile','(cast(%f as bigint)),%d' %(fake_float,percentile_data)) + self.constant_table_check("%s" %self.db,'percentile','(cast(%d as tinyint)),%d' %(fake_data,percentile_data)) + self.constant_table_check("%s" %self.db,'percentile','(cast(%f as tinyint)),%d' %(fake_float,percentile_data)) + self.constant_table_check("%s" %self.db,'percentile','(cast(%d as float)),%d' %(fake_data,percentile_data)) + self.constant_table_check("%s" %self.db,'percentile','(cast(%f as float)),%d' %(fake_float,percentile_data)) + self.constant_table_check("%s" %self.db,'percentile','(cast(%d as double)),%d' %(fake_data,percentile_data)) + self.constant_table_check("%s" %self.db,'percentile','(cast(%f as double)),%d' %(fake_float,percentile_data)) + + self.constant_table_check("%s" %self.db,'apercentile','%d,%d' %(fake_data,percentile_data)) + self.constant_check("%s" %self.db,'apercentile','%f,%d' %(fake_float,percentile_data)) + self.constant_error_check("%s" %self.db,'apercentile','%s,%d' %(fake_str,percentile_data)) + self.constant_table_check("%s" %self.db,'apercentile','(cast(%d as int)),%d' %(fake_data,percentile_data)) + self.constant_check("%s" %self.db,'apercentile','(cast(%f as int)),%d' %(fake_float,percentile_data)) + self.constant_check("%s" %self.db,'apercentile','(cast(%d as smallint)),%d' %(fake_data,percentile_data)) + self.constant_table_check("%s" %self.db,'apercentile','(cast(%f as smallint)),%d' %(fake_float,percentile_data)) + self.constant_table_check("%s" %self.db,'apercentile','(cast(%d as bigint)),%d' %(fake_data,percentile_data)) + self.constant_check("%s" %self.db,'apercentile','(cast(%f as bigint)),%d' %(fake_float,percentile_data)) + self.constant_check("%s" %self.db,'apercentile','(cast(%d as tinyint)),%d' %(fake_data,percentile_data)) + self.constant_table_check("%s" %self.db,'apercentile','(cast(%f as tinyint)),%d' %(fake_float,percentile_data)) + self.constant_table_check("%s" %self.db,'apercentile','(cast(%d as float)),%d' %(fake_data,percentile_data)) + self.constant_check("%s" %self.db,'apercentile','(cast(%f as float)),%d' %(fake_float,percentile_data)) + self.constant_check("%s" %self.db,'apercentile','(cast(%d as double)),%d' %(fake_data,percentile_data)) + self.constant_table_check("%s" %self.db,'apercentile','(cast(%f as double)),%d' %(fake_float,percentile_data)) + + percentile_data = fake.random_int(min=-0, max=1, step=1) + self.constant_table_check("%s" %self.db,'histogram',"%d,'user_input','[-10000,0,10000]',%d" %(fake_data,percentile_data)) + self.constant_check("%s" %self.db,'histogram',"%f,'user_input','[-10000,0,10000]',%d" %(fake_float,percentile_data)) + self.constant_error_check("%s" %self.db,'histogram',"%s,'user_input','[-10000,0,10000]',%d" %(fake_str,percentile_data)) + self.constant_table_check("%s" %self.db,'histogram',"(cast(%d as int)),'user_input','[-10000,0,10000]',%d" %(fake_data,percentile_data)) + self.constant_check("%s" %self.db,'histogram',"(cast(%f as int)),'user_input','[-10000,0,10000]',%d" %(fake_float,percentile_data)) + self.constant_check("%s" %self.db,'histogram',"(cast(%d as smallint)),'user_input','[-10000,0,10000]',%d" %(fake_data,percentile_data)) + self.constant_table_check("%s" %self.db,'histogram',"(cast(%f as smallint)),'user_input','[-10000,0,10000]',%d" %(fake_float,percentile_data)) + self.constant_table_check("%s" %self.db,'histogram',"(cast(%d as bigint)),'user_input','[-10000,0,10000]',%d" %(fake_data,percentile_data)) + self.constant_check("%s" %self.db,'histogram',"(cast(%f as bigint)),'user_input','[-10000,0,10000]',%d" %(fake_float,percentile_data)) + self.constant_check("%s" %self.db,'histogram',"(cast(%d as tinyint)),'user_input','[-10000,0,10000]',%d" %(fake_data,percentile_data)) + self.constant_table_check("%s" %self.db,'histogram',"(cast(%f as tinyint)),'user_input','[-10000,0,10000]',%d" %(fake_float,percentile_data)) + self.constant_table_check("%s" %self.db,'histogram',"(cast(%d as float)),'user_input','[-10000,0,10000]',%d" %(fake_data,percentile_data)) + self.constant_check("%s" %self.db,'histogram',"(cast(%f as float)),'user_input','[-10000,0,10000]',%d" %(fake_float,percentile_data)) + self.constant_check("%s" %self.db,'histogram',"(cast(%d as double)),'user_input','[-10000,0,10000]',%d" %(fake_data,percentile_data)) + self.constant_table_check("%s" %self.db,'histogram',"(cast(%f as double)),'user_input','[-10000,0,10000]',%d" %(fake_float,percentile_data)) + + #TD-19843 + self.derivative_sql("%s" %self.db) + + + #taos -f sql + print("taos -f sql start!") + taos_cmd1 = "taos -f %s/%s.sql" % (self.testcasePath,self.testcaseFilename) + _ = subprocess.check_output(taos_cmd1, shell=True) + print("taos -f sql over!") + + + endTime = time.time() + print("total time %ds" % (endTime - startTime)) + + + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/2-query/sin.py b/tests/system-test/2-query/sin.py index a1ba3354879eb9e1e0abe66ae445f7604734ad66..4fdec8fd731f3f93ea589cc5df9d2c8d731c9ecd 100644 --- a/tests/system-test/2-query/sin.py +++ b/tests/system-test/2-query/sin.py @@ -10,7 +10,8 @@ from util.cases import * class TDTestCase: - def init(self, conn, powSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/smaTest.py b/tests/system-test/2-query/smaTest.py index 0217b6c28c2f44deb87c032957ef749fc329742e..0390bae114306929605f404a0f8b1bb1eca10bec 100644 --- a/tests/system-test/2-query/smaTest.py +++ b/tests/system-test/2-query/smaTest.py @@ -31,7 +31,8 @@ class TDTestCase: # updatecfgDict = {'fqdn': 135} # init - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) tdSql.prepare() @@ -78,7 +79,7 @@ class TDTestCase: def insert_data(self, tbname, ts_start, count): pre_insert = "insert into %s values"%tbname sql = pre_insert - tdLog.debug("doing insert table %s rows=%d ..."%(tbname, count)) + tdLog.debug("insert table %s rows=%d ..."%(tbname, count)) for i in range(count): sql += " (%d,%d)"%(ts_start + i*1000, i ) if i >0 and i%30000 == 0: @@ -94,7 +95,7 @@ class TDTestCase: def insert_data1(self, tbname, ts_start, count): pre_insert = "insert into %s values"%tbname sql = pre_insert - tdLog.debug("doing insert table %s rows=%d ..."%(tbname, count)) + tdLog.debug("insert table %s rows=%d ..."%(tbname, count)) for i in range(count): sql += " (%d,%d,%d)"%(ts_start + i*1000, i , i+1) if i >0 and i%30000 == 0: diff --git a/tests/system-test/2-query/sml.py b/tests/system-test/2-query/sml.py index 4dae2ad6c0ec289e034929e6a949eed8b665c899..676bc0c127a3265b3a9b1cc77aaa2d2f13e4cfce 100644 --- a/tests/system-test/2-query/sml.py +++ b/tests/system-test/2-query/sml.py @@ -15,7 +15,8 @@ sys.path.append("./7-tmq") from tmqCommon import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/2-query/spread.py b/tests/system-test/2-query/spread.py index ffe86ff36304224e2d5f776f5088a16b445a5231..61fe6793f947284a5afee05ea4b91b22f4e82dd6 100644 --- a/tests/system-test/2-query/spread.py +++ b/tests/system-test/2-query/spread.py @@ -30,7 +30,8 @@ DBNAME = "db" class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/sqrt.py b/tests/system-test/2-query/sqrt.py index 9597375885cf5fdedf1d52a547d7558430cb46e4..9229444f74bfbbcdcc836dc66123faebb301ae00 100644 --- a/tests/system-test/2-query/sqrt.py +++ b/tests/system-test/2-query/sqrt.py @@ -10,7 +10,8 @@ from util.cases import * class TDTestCase: - def init(self, conn, powSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/stablity.py b/tests/system-test/2-query/stablity.py index b4343359702e0af4e5a9e2b9f29cba1700f8be35..569bee62ec68efa7d88c9550be9ede6d923afcee 100755 --- a/tests/system-test/2-query/stablity.py +++ b/tests/system-test/2-query/stablity.py @@ -28,7 +28,8 @@ class TDTestCase: "jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143, "wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"fnDebugFlag":143} - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/system-test/2-query/statecount.py b/tests/system-test/2-query/statecount.py index c73c955de405ee54e6924c25cd219aa8b8a7f4eb..2aa9194d378394421fe614356c22f56315bc313b 100644 --- a/tests/system-test/2-query/statecount.py +++ b/tests/system-test/2-query/statecount.py @@ -12,7 +12,8 @@ from util.cases import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.ts = 1420041600000 # 2015-01-01 00:00:00 this is begin time for first record diff --git a/tests/system-test/2-query/stateduration.py b/tests/system-test/2-query/stateduration.py index b6ddff4017ad61826801da9de3278be0f27d4af4..9c37dc68e7a81de603eddb2312e9ae8a35703b49 100644 --- a/tests/system-test/2-query/stateduration.py +++ b/tests/system-test/2-query/stateduration.py @@ -17,7 +17,8 @@ from util.sql import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.ts = 1537146000000 diff --git a/tests/system-test/2-query/stddev.py b/tests/system-test/2-query/stddev.py index 837353dfc9457bd332acdfa63066abc84a5d2a24..1a2118a966547a84566c159f765148ed0e2e7dc0 100644 --- a/tests/system-test/2-query/stddev.py +++ b/tests/system-test/2-query/stddev.py @@ -20,7 +20,8 @@ from util.sql import * from util.common import * from util.sqlset import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.dbname = 'db_test' diff --git a/tests/system-test/2-query/substr.py b/tests/system-test/2-query/substr.py index ea55c5e44e780c5acdd86b8be29e8654b8d1251e..302711b13de96e64bb1ef64ee8ca77c10c21dc89 100644 --- a/tests/system-test/2-query/substr.py +++ b/tests/system-test/2-query/substr.py @@ -29,7 +29,8 @@ LENS = 6 class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(),False) diff --git a/tests/system-test/2-query/sum.py b/tests/system-test/2-query/sum.py index dbc79e25f5ba230723f54507f47da91514698c69..27096fe5ad1eb52eb4b40a89291e5f67404a3bb1 100644 --- a/tests/system-test/2-query/sum.py +++ b/tests/system-test/2-query/sum.py @@ -24,7 +24,8 @@ DBNAME = "db" class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/tail.py b/tests/system-test/2-query/tail.py index 687023f57ec833248c2c7c472b751019a90f930f..f925380c092862ef89dc5d57a575b90afc2757d0 100644 --- a/tests/system-test/2-query/tail.py +++ b/tests/system-test/2-query/tail.py @@ -11,7 +11,8 @@ from util.cases import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/tan.py b/tests/system-test/2-query/tan.py index 683cee37ff7c81ca45b628852134ddbab6e342cf..27e6efb4751fb2f9e5ae25000f534dc9bded5b6c 100644 --- a/tests/system-test/2-query/tan.py +++ b/tests/system-test/2-query/tan.py @@ -10,7 +10,8 @@ from util.cases import * class TDTestCase: - def init(self, conn, powSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/timetruncate.py b/tests/system-test/2-query/timetruncate.py index 4cc6b27d64fb97c969539f7d0d5b186b6de435c1..32d6ef98e99a1d4ebf9650d20c5aa3968fcf9dd8 100644 --- a/tests/system-test/2-query/timetruncate.py +++ b/tests/system-test/2-query/timetruncate.py @@ -7,7 +7,8 @@ import time from datetime import datetime from util.gettime import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) print(conn) diff --git a/tests/system-test/2-query/timezone.py b/tests/system-test/2-query/timezone.py index 9a4953909c20a3812629dc79b49724bdc659f895..316e776cb1f706bee5dfddef0e9740a120359d19 100644 --- a/tests/system-test/2-query/timezone.py +++ b/tests/system-test/2-query/timezone.py @@ -11,7 +11,8 @@ if platform.system().lower() == 'windows': class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.setsql = TDSetSql() diff --git a/tests/system-test/2-query/top.py b/tests/system-test/2-query/top.py index 7fd143f6834511e810e3dfc2a8164e9dfbd8d8c4..d85e4dc76889965d9429a01a044b7215b862614d 100644 --- a/tests/system-test/2-query/top.py +++ b/tests/system-test/2-query/top.py @@ -19,7 +19,8 @@ from util.sql import * from util.sqlset import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.setsql = TDSetSql() diff --git a/tests/system-test/2-query/tsbsQuery.py b/tests/system-test/2-query/tsbsQuery.py index 04a80a74ad2d6ec21a97dc17bba05fb02df3830b..106d43ea388ed450766a811a525415c16954555b 100644 --- a/tests/system-test/2-query/tsbsQuery.py +++ b/tests/system-test/2-query/tsbsQuery.py @@ -20,7 +20,8 @@ class TDTestCase: updatecfgDict = {'keepColumnName': 1} updatecfgDict["clientCfg"] = clientCfgDict - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/2-query/ttl_comment.py b/tests/system-test/2-query/ttl_comment.py index 187df2e2d33846a2e61a7519cdec8c13b352f9da..3ae602fa2397a0e4c20ae8c4362104eea81cd730 100644 --- a/tests/system-test/2-query/ttl_comment.py +++ b/tests/system-test/2-query/ttl_comment.py @@ -24,7 +24,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/2-query/twa.py b/tests/system-test/2-query/twa.py index a499c17efb631ea0dc6621b0afad309bc08e4388..16b9779fa85b4a7d7ee1aa3f9c5e296834031a65 100644 --- a/tests/system-test/2-query/twa.py +++ b/tests/system-test/2-query/twa.py @@ -9,7 +9,8 @@ import math class TDTestCase: updatecfgDict = {"maxTablesPerVnode":2 ,"minTablesPerVnode":2,"tableIncStepPerVnode":2 } - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor()) self.vnode_disbutes = None diff --git a/tests/system-test/2-query/union.py b/tests/system-test/2-query/union.py index 4040bb71cbb92849dd63d11627c93a2954a4a0d1..82dcfe12e6da4882631eefc86de4589e9d29d95b 100644 --- a/tests/system-test/2-query/union.py +++ b/tests/system-test/2-query/union.py @@ -26,7 +26,8 @@ TS_TYPE_COL = [ TS_COL, ] class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/union1.py b/tests/system-test/2-query/union1.py index ea6940246e6fed6b9a2c8512f69fde4d3d3a6d70..8db5ce01f35a70985df57a7510d97eca4cabb925 100644 --- a/tests/system-test/2-query/union1.py +++ b/tests/system-test/2-query/union1.py @@ -26,7 +26,8 @@ TS_TYPE_COL = [ TS_COL, ] class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/union2.py b/tests/system-test/2-query/union2.py index 2d5e2f70bf01b277680c2fa14fe23a73ce61fd4b..b30d699482ea67b756aa695e7fef0564d4b7d1ea 100644 --- a/tests/system-test/2-query/union2.py +++ b/tests/system-test/2-query/union2.py @@ -26,7 +26,8 @@ TS_TYPE_COL = [ TS_COL, ] class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/union3.py b/tests/system-test/2-query/union3.py index 30a15e762470d90120f1cf997d390d2e659b6545..7e2bdf61438f7d82ddbd5d5e6748873a84d7ee1f 100644 --- a/tests/system-test/2-query/union3.py +++ b/tests/system-test/2-query/union3.py @@ -26,7 +26,8 @@ TS_TYPE_COL = [ TS_COL, ] class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/union4.py b/tests/system-test/2-query/union4.py index 4b2fba4272b3c957d1f09a656e82d547bea2c376..efb5b71c4d29d09b06c6e0f7a7a46b6bb527d406 100644 --- a/tests/system-test/2-query/union4.py +++ b/tests/system-test/2-query/union4.py @@ -26,7 +26,8 @@ TS_TYPE_COL = [ TS_COL, ] class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/unique.py b/tests/system-test/2-query/unique.py index ec77cbbcdc9d83d0a63b54fbe377c14d8645ce52..6c51854b43bd42118992be64c07fe1de216b600e 100644 --- a/tests/system-test/2-query/unique.py +++ b/tests/system-test/2-query/unique.py @@ -12,7 +12,8 @@ from util.cases import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) @@ -437,6 +438,10 @@ class TDTestCase: tdSql.checkData(0,0,4) tdSql.checkData(1,0,1) + # TD-19911 + tdSql.error("select unique(mode(12)) from (select _rowts , t1 , tbname from db.stb1 );") + tdSql.error("select unique(mode(t1,1)) from (select _rowts , t1 , tbname from db.stb1 );") + def check_boundary_values(self, dbname="bound_test"): tdSql.execute(f"drop database if exists {dbname}") diff --git a/tests/system-test/2-query/upper.py b/tests/system-test/2-query/upper.py index f15a6f3ba76d3acb5645f443cf068d4cce7d9755..e28483dc564763f08aba3eaa276b25c4c985840a 100644 --- a/tests/system-test/2-query/upper.py +++ b/tests/system-test/2-query/upper.py @@ -22,7 +22,8 @@ TS_TYPE_COL = [TS_COL] class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/2-query/varchar.py b/tests/system-test/2-query/varchar.py index 17c3ea633357cf16a8b17e52c180192d07e52a87..f0849010c6591125fe83a7549d3682c4397c745c 100644 --- a/tests/system-test/2-query/varchar.py +++ b/tests/system-test/2-query/varchar.py @@ -9,7 +9,8 @@ from util.cases import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) diff --git a/tests/system-test/5-taos-tools/TD-12478.py b/tests/system-test/5-taos-tools/TD-12478.py index 69849d3c7a7962955619a2674367402b5352376e..66f960338eff3bc323e5b0ca41ab74137c6c0a41 100644 --- a/tests/system-test/5-taos-tools/TD-12478.py +++ b/tests/system-test/5-taos-tools/TD-12478.py @@ -36,7 +36,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/system-test/5-taos-tools/taosdump/taosdumpTestColTag.py b/tests/system-test/5-taos-tools/taosdump/taosdumpTestColTag.py index 8c62f713b894308128c589b6ff569921d6db9589..cbc9e83ba8679abbf401f467e85f827117070cd5 100644 --- a/tests/system-test/5-taos-tools/taosdump/taosdumpTestColTag.py +++ b/tests/system-test/5-taos-tools/taosdump/taosdumpTestColTag.py @@ -28,7 +28,8 @@ class TDTestCase: ''' return - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(), logSql) diff --git a/tests/system-test/6-cluster/5dnode1mnode.py b/tests/system-test/6-cluster/5dnode1mnode.py index 367d0bfbd779aac64812376e7b9b4c21a812fcaa..f2c0bf9902bc7a3c82633da436776f282d04fb98 100644 --- a/tests/system-test/6-cluster/5dnode1mnode.py +++ b/tests/system-test/6-cluster/5dnode1mnode.py @@ -21,7 +21,7 @@ class MyDnodes(TDDnodes): class TDTestCase: noConn = True - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") self.TDDnodes = None self.depoly_cluster(5) diff --git a/tests/system-test/6-cluster/5dnode2mnode.py b/tests/system-test/6-cluster/5dnode2mnode.py index 7cbadde8bf96cd6857367fbb6854ce8e901c38ac..6054ef69f8738d52cd5547ed00a74537e0ddcbc1 100644 --- a/tests/system-test/6-cluster/5dnode2mnode.py +++ b/tests/system-test/6-cluster/5dnode2mnode.py @@ -20,7 +20,7 @@ from clusterCommonCreate import * from clusterCommonCheck import * class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/5dnode3mnodeAdd1Ddnoe.py b/tests/system-test/6-cluster/5dnode3mnodeAdd1Ddnoe.py index 909decc19562632bf1710190f250c4a867c41a92..d084432a1aa990b3afaa3969be4386f890266939 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeAdd1Ddnoe.py +++ b/tests/system-test/6-cluster/5dnode3mnodeAdd1Ddnoe.py @@ -26,11 +26,12 @@ import ctypes class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") self.TDDnodes = None tdSql.init(conn.cursor()) self.host = socket.gethostname() + self.replicaVar = int(replicaVar) def getBuildPath(self): @@ -118,20 +119,19 @@ class TDTestCase: rowsPerStb=paraDict["ctbNum"]*paraDict["rowsPerTbl"] rowsall=rowsPerStb*paraDict['stbNumbers'] dbNumbers = 1 + paraDict['replica'] = self.replicaVar tdLog.info("first check dnode and mnode") tdSql.query("select * from information_schema.ins_dnodes;") tdSql.checkData(0,1,'%s:6030'%self.host) tdSql.checkData(4,1,'%s:6430'%self.host) clusterComCheck.checkDnodes(dnodeNumbers) - clusterComCheck.checkMnodeStatus(1) - # fisr add three mnodes; - tdLog.info("fisr add three mnodes and check mnode status") - tdSql.execute("create mnode on dnode 2") - clusterComCheck.checkMnodeStatus(2) - tdSql.execute("create mnode on dnode 3") - clusterComCheck.checkMnodeStatus(3) + + #check mnode status + tdLog.info("check mnode status") + clusterComCheck.checkMnodeStatus(mnodeNums) + # add some error operations and tdLog.info("Confirm the status of the dnode again") @@ -167,8 +167,8 @@ class TDTestCase: threads.append(threading.Thread(target=clusterComCreate.insert_data, args=(newTdSql, paraDict["dbName"],stableName,paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"],paraDict["startTs"]))) for tr in threads: tr.start() - dnode6Port=int(6030+5*100) - tdSql.execute("create dnode '%s:%d'"%(hostname,dnode6Port)) + dnode7Port=int(6030+6*100) + tdSql.execute("create dnode '%s:%d'"%(hostname,dnode7Port)) clusterComCheck.checkDnodes(dnodeNumbers) for tr in threads: tr.join() @@ -219,7 +219,7 @@ class TDTestCase: tdSql.checkRows(rowsPerStb) def run(self): # print(self.master_dnode.cfgDict) - self.fiveDnodeThreeMnode(dnodeNumbers=5,mnodeNums=3,restartNumbers=2,stopRole='dnode') + self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=2,stopRole='dnode') def stop(self): tdSql.close() diff --git a/tests/system-test/6-cluster/5dnode3mnodeDrop.py b/tests/system-test/6-cluster/5dnode3mnodeDrop.py index 33dc3ebaac203dfa216a13e832560ac0918b9cb3..73c19b8cea82d78770f1c5152662182b07c27cff 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeDrop.py +++ b/tests/system-test/6-cluster/5dnode3mnodeDrop.py @@ -22,9 +22,10 @@ class MyDnodes(TDDnodes): class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") self.TDDnodes = None + self.replicaVar = int(replicaVar) def buildcluster(self,dnodenumber): self.depoly_cluster(dnodenumber) diff --git a/tests/system-test/6-cluster/5dnode3mnodeDropInsert.py b/tests/system-test/6-cluster/5dnode3mnodeDropInsert.py index 74a7c32206f4f492465ce107cba5fec6e7a2d360..2b013704f293020bbf4c49b57c4d1f6b929aafc9 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeDropInsert.py +++ b/tests/system-test/6-cluster/5dnode3mnodeDropInsert.py @@ -26,7 +26,7 @@ class MyDnodes(TDDnodes): class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") self.TDDnodes = None self.ts = 1500000000000 diff --git a/tests/system-test/6-cluster/5dnode3mnodeRecreateMnode.py b/tests/system-test/6-cluster/5dnode3mnodeRecreateMnode.py index 2e107561b51ef612dd9b903bf95696221eeaed10..41082baa3da6161d378e66923a0473d3e2c1951f 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeRecreateMnode.py +++ b/tests/system-test/6-cluster/5dnode3mnodeRecreateMnode.py @@ -26,7 +26,7 @@ import ctypes class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") self.TDDnodes = None tdSql.init(conn.cursor()) @@ -126,14 +126,11 @@ class TDTestCase: tdSql.checkData(0,1,'%s:6030'%self.host) tdSql.checkData(4,1,'%s:6430'%self.host) clusterComCheck.checkDnodes(dnodeNumbers) - clusterComCheck.checkMnodeStatus(1) - - # fisr add three mnodes; - tdLog.info("fisr add three mnodes and check mnode status") - tdSql.execute("create mnode on dnode 2") - clusterComCheck.checkMnodeStatus(2) - tdSql.execute("create mnode on dnode 3") - clusterComCheck.checkMnodeStatus(3) + + #check mnode status + tdLog.info("check mnode status") + clusterComCheck.checkMnodeStatus(mnodeNums) + # add some error operations and tdLog.info("Confirm the status of the dnode again") diff --git a/tests/system-test/6-cluster/5dnode3mnodeRestartDnodeInsertData.py b/tests/system-test/6-cluster/5dnode3mnodeRestartDnodeInsertData.py index 3fe6a689cba356125262dda89d8d2a9d7f6bf058..94e02b77b307281975ff7393298f182f233a7c65 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeRestartDnodeInsertData.py +++ b/tests/system-test/6-cluster/5dnode3mnodeRestartDnodeInsertData.py @@ -26,11 +26,12 @@ import ctypes class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") self.TDDnodes = None tdSql.init(conn.cursor()) self.host = socket.gethostname() + self.replicaVar = int(replicaVar) def getBuildPath(self): @@ -118,20 +119,18 @@ class TDTestCase: rowsPerStb=paraDict["ctbNum"]*paraDict["rowsPerTbl"] rowsall=rowsPerStb*paraDict['stbNumbers'] dbNumbers = 1 + paraDict['replica'] = self.replicaVar tdLog.info("first check dnode and mnode") tdSql.query("select * from information_schema.ins_dnodes;") tdSql.checkData(0,1,'%s:6030'%self.host) tdSql.checkData(4,1,'%s:6430'%self.host) clusterComCheck.checkDnodes(dnodeNumbers) - clusterComCheck.checkMnodeStatus(1) - - # fisr add three mnodes; - tdLog.info("fisr add three mnodes and check mnode status") - tdSql.execute("create mnode on dnode 2") - clusterComCheck.checkMnodeStatus(2) - tdSql.execute("create mnode on dnode 3") - clusterComCheck.checkMnodeStatus(3) + + #check mnode status + tdLog.info("check mnode status") + clusterComCheck.checkMnodeStatus(mnodeNums) + # add some error operations and tdLog.info("Confirm the status of the dnode again") @@ -157,7 +156,7 @@ class TDTestCase: stableName= '%s_%d'%(paraDict['stbName'],i) newTdSql=tdCom.newTdSql() clusterComCreate.create_ctable(newTdSql, paraDict["dbName"],stableName,stableName, paraDict['ctbNum']) - #insert date + #insert data for i in range(paraDict['stbNumbers']): stableName= '%s_%d'%(paraDict['stbName'],i) newTdSql=tdCom.newTdSql() @@ -203,17 +202,19 @@ class TDTestCase: clusterComCheck.checkDbRows(dbNumbers) # clusterComCheck.checkDb(dbNumbers,1,paraDict["dbName"]) - tdSql.execute("use %s" %(paraDict["dbName"])) - tdSql.query("show stables") - tdSql.checkRows(paraDict["stbNumbers"]) - # for i in range(paraDict['stbNumbers']): - # stableName= '%s_%d'%(paraDict['stbName'],i) - # tdSql.query("select * from %s"%stableName) - # tdSql.checkRows(rowsPerStb) + newTdSql=tdCom.newTdSql() + newTdSql.execute("reset query cache") + newTdSql.execute("use %s" %(paraDict["dbName"])) + newTdSql.query("show %s.stables"%(paraDict["dbName"])) + newTdSql.checkRows(paraDict["stbNumbers"]) + for i in range(paraDict['stbNumbers']): + stableName= '%s_%d'%(paraDict['stbName'],i) + newTdSql.query("select * from %s"%stableName) + newTdSql.checkRows(rowsPerStb) def run(self): # print(self.master_dnode.cfgDict) - self.fiveDnodeThreeMnode(dnodeNumbers=5,mnodeNums=3,restartNumbers=1,stopRole='dnode') + self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=2,stopRole='dnode') def stop(self): tdSql.close() diff --git a/tests/system-test/6-cluster/5dnode3mnodeRestartDnodeInsertDataAsync.py b/tests/system-test/6-cluster/5dnode3mnodeRestartDnodeInsertDataAsync.py index 0d56729280a313a6df41ed8b0743974106a026da..d6d06446a1ab60c0dabdf0a676f7067a3497c799 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeRestartDnodeInsertDataAsync.py +++ b/tests/system-test/6-cluster/5dnode3mnodeRestartDnodeInsertDataAsync.py @@ -26,11 +26,12 @@ import ctypes class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") self.TDDnodes = None tdSql.init(conn.cursor()) self.host = socket.gethostname() + self.replicaVar = int(replicaVar) def getBuildPath(self): @@ -118,20 +119,18 @@ class TDTestCase: rowsPerStb=paraDict["ctbNum"]*paraDict["rowsPerTbl"] rowsall=rowsPerStb*paraDict['stbNumbers'] dbNumbers = 1 + paraDict['replica'] = self.replicaVar tdLog.info("first check dnode and mnode") tdSql.query("select * from information_schema.ins_dnodes;") tdSql.checkData(0,1,'%s:6030'%self.host) tdSql.checkData(4,1,'%s:6430'%self.host) clusterComCheck.checkDnodes(dnodeNumbers) - clusterComCheck.checkMnodeStatus(1) - - # fisr add three mnodes; - tdLog.info("fisr add three mnodes and check mnode status") - tdSql.execute("create mnode on dnode 2") - clusterComCheck.checkMnodeStatus(2) - tdSql.execute("create mnode on dnode 3") - clusterComCheck.checkMnodeStatus(3) + + #check mnode status + tdLog.info("check mnode status") + clusterComCheck.checkMnodeStatus(mnodeNums) + # add some error operations and tdLog.info("Confirm the status of the dnode again") @@ -214,7 +213,7 @@ class TDTestCase: def run(self): # print(self.master_dnode.cfgDict) - self.fiveDnodeThreeMnode(dnodeNumbers=5,mnodeNums=3,restartNumbers=1,stopRole='dnode') + self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=1,stopRole='dnode') def stop(self): tdSql.close() diff --git a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateDb.py b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateDb.py index a215a74559e6bb894c3058534946099f9157d5a7..881f383b8c07b66987290e07cda6eda99d01dce5 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateDb.py +++ b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateDb.py @@ -25,12 +25,12 @@ import ctypes class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") self.TDDnodes = None tdSql.init(conn.cursor()) self.host = socket.gethostname() - + self.replicaVar=int(replicaVar) def getBuildPath(self): selfPath = os.path.dirname(os.path.realpath(__file__)) @@ -93,7 +93,7 @@ class TDTestCase: def fiveDnodeThreeMnode(self,dnodeNumbers,mnodeNums,restartNumbers,stopRole): tdLog.printNoPrefix("======== test case 1: ") paraDict = {'dbName': 'db', - 'dbNumbers': 8, + 'dbNumbers': 4, 'dropFlag': 1, 'event': '', 'vgroups': 4, @@ -109,24 +109,23 @@ class TDTestCase: } dnodeNumbers=int(dnodeNumbers) + dbNumbers=paraDict['dbNumbers'] mnodeNums=int(mnodeNums) + repeatNumber = 2 vnodeNumbers = int(dnodeNumbers-mnodeNums) - allDbNumbers=(paraDict['dbNumbers']*restartNumbers) + allDbNumbers=dbNumbers allStbNumbers=(paraDict['stbNumbers']*restartNumbers) + paraDict['replica'] = self.replicaVar tdLog.info("first check dnode and mnode") tdSql.query("select * from information_schema.ins_dnodes;") tdSql.checkData(0,1,'%s:6030'%self.host) tdSql.checkData(4,1,'%s:6430'%self.host) clusterComCheck.checkDnodes(dnodeNumbers) - clusterComCheck.checkMnodeStatus(1) - - # fisr add three mnodes; - tdLog.info("fisr add three mnodes and check mnode status") - tdSql.execute("create mnode on dnode 2") - clusterComCheck.checkMnodeStatus(2) - tdSql.execute("create mnode on dnode 3") - clusterComCheck.checkMnodeStatus(3) + + #check mnode status + tdLog.info("check mnode status") + clusterComCheck.checkMnodeStatus(mnodeNums) # add some error operations and tdLog.info("Confirm the status of the dnode again") @@ -141,10 +140,12 @@ class TDTestCase: tdDnodes=cluster.dnodes stopcount =0 threads=[] - for i in range(restartNumbers): + for i in range(dbNumbers): dbNameIndex = '%s%d'%(paraDict["dbName"],i) newTdSql=tdCom.newTdSql() - threads.append(threading.Thread(target=clusterComCreate.create_databases, args=(newTdSql, dbNameIndex,paraDict["dbNumbers"],paraDict["dropFlag"], paraDict["vgroups"],paraDict['replica']))) + # a11111=paraDict["dbNumbers"] + # print(f"==================={dbNameIndex},{a11111}") + threads.append(threading.Thread(target=clusterComCreate.createDeltedatabases, args=(newTdSql, dbNameIndex,repeatNumber,paraDict["dropFlag"], paraDict["vgroups"],paraDict['replica']))) for tr in threads: tr.start() @@ -198,7 +199,7 @@ class TDTestCase: def run(self): # print(self.master_dnode.cfgDict) - self.fiveDnodeThreeMnode(dnodeNumbers=5,mnodeNums=3,restartNumbers=10,stopRole='dnode') + self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=4,stopRole='dnode') def stop(self): tdSql.close() diff --git a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateStb.py b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateStb.py index 9df1ffb3df376e0916be4ff44420affd2b583f9a..97e61950372e2a79e8e94f0de296009351d701a0 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateStb.py +++ b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateStb.py @@ -25,12 +25,12 @@ import ctypes class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") self.TDDnodes = None tdSql.init(conn.cursor()) self.host = socket.gethostname() - + self.replicaVar = int(replicaVar) def getBuildPath(self): selfPath = os.path.dirname(os.path.realpath(__file__)) @@ -87,20 +87,17 @@ class TDTestCase: vnodeNumbers = int(dnodeNumbers-mnodeNums) allStbNumbers=(paraDict['stbNumbers']*restartNumbers) dbNumbers = 1 + paraDict['replica'] = self.replicaVar tdLog.info("first check dnode and mnode") tdSql.query("select * from information_schema.ins_dnodes;") tdSql.checkData(0,1,'%s:6030'%self.host) tdSql.checkData(4,1,'%s:6430'%self.host) clusterComCheck.checkDnodes(dnodeNumbers) - clusterComCheck.checkMnodeStatus(1) - - # fisr add three mnodes; - tdLog.info("fisr add three mnodes and check mnode status") - tdSql.execute("create mnode on dnode 2") - clusterComCheck.checkMnodeStatus(2) - tdSql.execute("create mnode on dnode 3") - clusterComCheck.checkMnodeStatus(3) + + #check mnode status + tdLog.info("check mnode status") + clusterComCheck.checkMnodeStatus(mnodeNums) # add some error operations and tdLog.info("Confirm the status of the dnode again") diff --git a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeInsertData.py b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeInsertData.py index caaf1dd898b1672f04624bf32ff2aad9b204a95c..265000bdc9d0c5530fdcbd7d4e6ed633c58b0a29 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeInsertData.py +++ b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopDnodeInsertData.py @@ -26,7 +26,7 @@ import ctypes class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") self.TDDnodes = None tdSql.init(conn.cursor()) @@ -124,14 +124,10 @@ class TDTestCase: tdSql.checkData(0,1,'%s:6030'%self.host) tdSql.checkData(4,1,'%s:6430'%self.host) clusterComCheck.checkDnodes(dnodeNumbers) - clusterComCheck.checkMnodeStatus(1) - - # fisr add three mnodes; - tdLog.info("fisr add three mnodes and check mnode status") - tdSql.execute("create mnode on dnode 2") - clusterComCheck.checkMnodeStatus(2) - tdSql.execute("create mnode on dnode 3") - clusterComCheck.checkMnodeStatus(3) + + #check mnode status + tdLog.info("check mnode status") + clusterComCheck.checkMnodeStatus(mnodeNums) # add some error operations and tdLog.info("Confirm the status of the dnode again") diff --git a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateDb.py b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateDb.py index 58ed8cde632b5fc513925f650dd5625de851c370..15d18d50909fde41aefb12fcfb6cb665f9a3eeb0 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateDb.py +++ b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateDb.py @@ -25,12 +25,12 @@ import ctypes class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") self.TDDnodes = None tdSql.init(conn.cursor()) self.host = socket.gethostname() - + self.replicaVar = int(replicaVar) def getBuildPath(self): selfPath = os.path.dirname(os.path.realpath(__file__)) @@ -85,25 +85,23 @@ class TDTestCase: dnodeNumbers=int(dnodeNumbers) mnodeNums=int(mnodeNums) + repeatNumber = 2 + dbNumbers=int(paraDict['dbNumbers']) + vnodeNumbers = int(dnodeNumbers-mnodeNums) - allDbNumbers=(paraDict['dbNumbers']*restartNumbers) + allDbNumbers=dbNumbers allStbNumbers=(paraDict['stbNumbers']*restartNumbers) + paraDict['replica'] = self.replicaVar tdLog.info("first check dnode and mnode") tdSql.query("select * from information_schema.ins_dnodes;") tdSql.checkData(0,1,'%s:6030'%self.host) tdSql.checkData(4,1,'%s:6430'%self.host) clusterComCheck.checkDnodes(dnodeNumbers) - clusterComCheck.checkMnodeStatus(1) - - # fisr add three mnodes; - tdLog.info("fisr add three mnodes and check mnode status") - tdLog.info("create mnode on dnode 2") - tdSql.execute("create mnode on dnode 2") - clusterComCheck.checkMnodeStatus(2) - tdLog.info("create mnode on dnode 3") - tdSql.execute("create mnode on dnode 3") - clusterComCheck.checkMnodeStatus(3) + + #check mnode status + tdLog.info("check mnode status") + clusterComCheck.checkMnodeStatus(mnodeNums) # add some error operations and tdLog.info("Confirm the status of the dnode again") @@ -116,10 +114,10 @@ class TDTestCase: tdDnodes=cluster.dnodes stopcount =0 threads=[] - for i in range(restartNumbers): + for i in range(dbNumbers): dbNameIndex = '%s%d'%(paraDict["dbName"],i) newTdSql=tdCom.newTdSql() - threads.append(threading.Thread(target=clusterComCreate.create_databases, args=(newTdSql, dbNameIndex,paraDict["dbNumbers"],paraDict["dropFlag"], paraDict["vgroups"],paraDict['replica']))) + threads.append(threading.Thread(target=clusterComCreate.createDeltedatabases, args=(newTdSql, dbNameIndex,repeatNumber,paraDict["dropFlag"], paraDict["vgroups"],paraDict['replica']))) for tr in threads: tr.start() @@ -172,7 +170,7 @@ class TDTestCase: def run(self): # print(self.master_dnode.cfgDict) - self.fiveDnodeThreeMnode(dnodeNumbers=5,mnodeNums=3,restartNumbers=5,stopRole='mnode') + self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=4,stopRole='mnode') def stop(self): tdSql.close() diff --git a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateDbRep3.py b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateDbRep3.py index 3dc3e7ec65327dd53d9a441fb80e44150d95f4b7..98842e3358fb29c19a59fcb671848168ba9a2f80 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateDbRep3.py +++ b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateDbRep3.py @@ -25,12 +25,12 @@ import ctypes class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") self.TDDnodes = None tdSql.init(conn.cursor()) self.host = socket.gethostname() - + self.replicaVar = replicaVar def getBuildPath(self): selfPath = os.path.dirname(os.path.realpath(__file__)) @@ -88,20 +88,16 @@ class TDTestCase: vnodeNumbers = int(dnodeNumbers-mnodeNums) allDbNumbers=(paraDict['dbNumbers']*restartNumbers) allStbNumbers=(paraDict['stbNumbers']*restartNumbers) - + paraDict['replica'] = self.replicaVar tdLog.info("first check dnode and mnode") tdSql.query("select * from information_schema.ins_dnodes;") tdSql.checkData(0,1,'%s:6030'%self.host) tdSql.checkData(4,1,'%s:6430'%self.host) clusterComCheck.checkDnodes(dnodeNumbers) - clusterComCheck.checkMnodeStatus(1) - - # fisr add three mnodes; - tdLog.info("fisr add three mnodes and check mnode status") - tdSql.execute("create mnode on dnode 2") - clusterComCheck.checkMnodeStatus(2) - tdSql.execute("create mnode on dnode 3") - clusterComCheck.checkMnodeStatus(3) + + #check mnode status + tdLog.info("check mnode status") + clusterComCheck.checkMnodeStatus(mnodeNums) # add some error operations and tdLog.info("Confirm the status of the dnode again") @@ -170,7 +166,7 @@ class TDTestCase: def run(self): # print(self.master_dnode.cfgDict) - self.fiveDnodeThreeMnode(dnodeNumbers=5,mnodeNums=3,restartNumbers=3,stopRole='mnode') + self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=3,stopRole='mnode') def stop(self): tdSql.close() diff --git a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateStb.py b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateStb.py index 9a94632a12ea7746cc2d2ff9a660f8c83dbdb9c6..cb160595242ae33b00feafbe6d5b57c3ae2c3e5b 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateStb.py +++ b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateStb.py @@ -25,12 +25,12 @@ import ctypes class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") self.TDDnodes = None tdSql.init(conn.cursor()) self.host = socket.gethostname() - + self.replicaVar = int(replicaVar) def getBuildPath(self): selfPath = os.path.dirname(os.path.realpath(__file__)) @@ -112,20 +112,17 @@ class TDTestCase: vnodeNumbers = int(dnodeNumbers-mnodeNums) allStbNumbers=(paraDict['stbNumbers']*restartNumbers) dbNumbers = 1 + paraDict['replica'] = self.replicaVar tdLog.info("first check dnode and mnode") tdSql.query("select * from information_schema.ins_dnodes;") tdSql.checkData(0,1,'%s:6030'%self.host) tdSql.checkData(4,1,'%s:6430'%self.host) clusterComCheck.checkDnodes(dnodeNumbers) - clusterComCheck.checkMnodeStatus(1) - - # fisr add three mnodes; - tdLog.info("fisr add three mnodes and check mnode status") - tdSql.execute("create mnode on dnode 2") - clusterComCheck.checkMnodeStatus(2) - tdSql.execute("create mnode on dnode 3") - clusterComCheck.checkMnodeStatus(3) + + #check mnode status + tdLog.info("check mnode status") + clusterComCheck.checkMnodeStatus(mnodeNums) # add some error operations and tdLog.info("Confirm the status of the dnode again") @@ -197,7 +194,7 @@ class TDTestCase: def run(self): # print(self.master_dnode.cfgDict) - self.fiveDnodeThreeMnode(dnodeNumbers=5,mnodeNums=3,restartNumbers=2,stopRole='mnode') + self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=2,stopRole='mnode') def stop(self): tdSql.close() diff --git a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateDb.py b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateDb.py index 6fbe262b8ed36e465b320a47ccd772a40040bc5f..21caf23ea63d641ab42d8aa2596416c6b7f01729 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateDb.py +++ b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateDb.py @@ -25,11 +25,12 @@ import ctypes class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") self.TDDnodes = None tdSql.init(conn.cursor()) self.host = socket.gethostname() + self.replicaVar = int(replicaVar) def getBuildPath(self): @@ -68,7 +69,7 @@ class TDTestCase: def fiveDnodeThreeMnode(self,dnodeNumbers,mnodeNums,restartNumbers,stopRole): tdLog.printNoPrefix("======== test case 1: ") paraDict = {'dbName': 'db', - 'dbNumbers': 8, + 'dbNumbers': 4, 'dropFlag': 1, 'event': '', 'vgroups': 2, @@ -84,24 +85,23 @@ class TDTestCase: } dnodeNumbers=int(dnodeNumbers) + dbNumbers=paraDict['dbNumbers'] + repeatNumber=3 mnodeNums=int(mnodeNums) vnodeNumbers = int(dnodeNumbers-mnodeNums) - allDbNumbers=(paraDict['dbNumbers']*restartNumbers) + allDbNumbers = int(dbNumbers) allStbNumbers=(paraDict['stbNumbers']*restartNumbers) + paraDict['replica'] = self.replicaVar tdLog.info("first check dnode and mnode") tdSql.query("select * from information_schema.ins_dnodes;") tdSql.checkData(0,1,'%s:6030'%self.host) tdSql.checkData(4,1,'%s:6430'%self.host) clusterComCheck.checkDnodes(dnodeNumbers) - clusterComCheck.checkMnodeStatus(1) - - # fisr add three mnodes; - tdLog.info("fisr add three mnodes and check mnode status") - tdSql.execute("create mnode on dnode 2") - clusterComCheck.checkMnodeStatus(2) - tdSql.execute("create mnode on dnode 3") - clusterComCheck.checkMnodeStatus(3) + + #check mnode status + tdLog.info("check mnode status") + clusterComCheck.checkMnodeStatus(mnodeNums) # add some error operations and tdLog.info("Confirm the status of the dnode again") @@ -116,15 +116,17 @@ class TDTestCase: tdDnodes=cluster.dnodes stopcount =0 threads=[] - for i in range(restartNumbers): + for i in range(dbNumbers): dbNameIndex = '%s%d'%(paraDict["dbName"],i) newTdSql=tdCom.newTdSql() - threads.append(threading.Thread(target=clusterComCreate.create_databases, args=(newTdSql, dbNameIndex,paraDict["dbNumbers"],paraDict["dropFlag"], paraDict["vgroups"],paraDict['replica']))) + threads.append(threading.Thread(target=clusterComCreate.createDeltedatabases, args=(newTdSql, dbNameIndex,repeatNumber,paraDict["dropFlag"], paraDict["vgroups"],paraDict['replica']))) for tr in threads: tr.start() + tdLog.info("Take turns stopping Mnodes ") + while stopcount < restartNumbers: tdLog.info(" restart loop: %d"%stopcount ) if stopRole == "mnode": @@ -159,19 +161,20 @@ class TDTestCase: for tr in threads: tr.join() clusterComCheck.checkDnodes(dnodeNumbers) - # tdSql.query("select * from information_schema.ins_databases") - # tdLog.debug("we find %d databases but exepect to create %d databases "%(tdSql.queryRows-2,allDbNumbers)) + tdSql.query("select * from information_schema.ins_databases") + tdLog.debug("we find %d databases but exepect to create %d databases "%(tdSql.queryRows-2,allDbNumbers)) # tdLog.info("check DB Rows:") - clusterComCheck.checkDbRows(allDbNumbers) + # clusterComCheck.checkDbRows(allDbNumbers) # tdLog.info("check DB Status on by on") # for i in range(restartNumbers): # clusterComCheck.checkDb(paraDict['dbNumbers'],restartNumbers,dbNameIndex = '%s%d'%(paraDict["dbName"],i)) + def run(self): # print(self.master_dnode.cfgDict) - self.fiveDnodeThreeMnode(dnodeNumbers=5,mnodeNums=3,restartNumbers=10,stopRole='vnode') + self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=4,stopRole='vnode') def stop(self): tdSql.close() diff --git a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateStb.py b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateStb.py index 56bafe8abc61be627f1b5af82cfb2fa77b96ccb7..84236529d146584b0305747ae1c93b484250b52c 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateStb.py +++ b/tests/system-test/6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateStb.py @@ -25,12 +25,12 @@ import ctypes class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") self.TDDnodes = None tdSql.init(conn.cursor()) self.host = socket.gethostname() - print(tdSql) + self.replicaVar = int(replicaVar) def getBuildPath(self): selfPath = os.path.dirname(os.path.realpath(__file__)) @@ -112,21 +112,17 @@ class TDTestCase: vnodeNumbers = int(dnodeNumbers-mnodeNums) allStbNumbers=(paraDict['stbNumbers']*restartNumbers) dbNumbers = 1 + paraDict['replica'] = self.replicaVar - print(tdSql) tdLog.info("first check dnode and mnode") tdSql.query("select * from information_schema.ins_dnodes;") tdSql.checkData(0,1,'%s:6030'%self.host) tdSql.checkData(4,1,'%s:6430'%self.host) clusterComCheck.checkDnodes(dnodeNumbers) - clusterComCheck.checkMnodeStatus(1) - - # fisr add three mnodes; - tdLog.info("fisr add three mnodes and check mnode status") - tdSql.execute("create mnode on dnode 2") - clusterComCheck.checkMnodeStatus(2) - tdSql.execute("create mnode on dnode 3") - clusterComCheck.checkMnodeStatus(3) + + #check mnode status + tdLog.info("check mnode status") + clusterComCheck.checkMnodeStatus(mnodeNums) # add some error operations and tdLog.info("Confirm the status of the dnode again") @@ -175,7 +171,7 @@ class TDTestCase: # dnodeNumbers don't include database of schema if clusterComCheck.checkDnodes(dnodeNumbers): - tdLog.info("123") + tdLog.info("check numbers of dnodes right ") else: print("456") @@ -192,14 +188,16 @@ class TDTestCase: tdSql.execute("use %s" %(paraDict["dbName"])) tdSql.query("show stables") - tdLog.debug("we find %d stables but exepect to create %d stables "%(tdSql.queryRows,allStbNumbers)) # # tdLog.info("check Stable Rows:") - tdSql.checkRows(allStbNumbers) - + if self.replicaVar==1: + # tdSql.checkRows(allStbNumbers) + tdLog.debug("we find %d stables but exepect to create %d stables "%(tdSql.queryRows,allStbNumbers)) + else: + tdLog.debug("we find %d stables but exepect to create %d stables "%(tdSql.queryRows,allStbNumbers)) def run(self): # print(self.master_dnode.cfgDict) - self.fiveDnodeThreeMnode(dnodeNumbers=5,mnodeNums=3,restartNumbers=2,stopRole='vnode') + self.fiveDnodeThreeMnode(dnodeNumbers=6,mnodeNums=3,restartNumbers=2,stopRole='vnode') def stop(self): tdSql.close() diff --git a/tests/system-test/6-cluster/5dnode3mnodeSeperate1VnodeStopInsert.py b/tests/system-test/6-cluster/5dnode3mnodeSeperate1VnodeStopInsert.py index 539e5e38a78f96ec745b27469d9ae53c0b53c64a..a34895ff42c94e5b4b201b0edbaf2d782eee3f60 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeSeperate1VnodeStopInsert.py +++ b/tests/system-test/6-cluster/5dnode3mnodeSeperate1VnodeStopInsert.py @@ -25,7 +25,7 @@ import ctypes class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") # tdSql.init(conn.cursor()) # self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/5dnode3mnodeStop.py b/tests/system-test/6-cluster/5dnode3mnodeStop.py index c43d41199bf22fb562d94f8b90786e4411df335e..522ba4c2fcfd713853e9fe2313c818507f5fa792 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeStop.py +++ b/tests/system-test/6-cluster/5dnode3mnodeStop.py @@ -24,7 +24,7 @@ from multiprocessing import Process class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() @@ -75,14 +75,17 @@ class TDTestCase: tdSql.checkData(0,1,'%s:6030'%self.host) tdSql.checkData(4,1,'%s:6430'%self.host) clusterComCheck.checkDnodes(dnodenumbers) - clusterComCheck.checkMnodeStatus(1) - - # fisr add three mnodes; - tdLog.info("fisr add three mnodes and check mnode status") - tdSql.execute("create mnode on dnode 2") - clusterComCheck.checkMnodeStatus(2) - tdSql.execute("create mnode on dnode 3") - clusterComCheck.checkMnodeStatus(3) + + #check mnode status + tdLog.info("check mnode status") + clusterComCheck.checkMnodeStatus(mnodeNums) + + # # fisr add three mnodes; + # tdLog.info("check mnode status") + # # tdSql.execute("create mnode on dnode 2") + # clusterComCheck.checkMnodeStatus(2) + # # tdSql.execute("create mnode on dnode 3") + # clusterComCheck.checkMnodeStatus(3) # add some error operations and tdLog.info("Confirm the status of the dnode again") diff --git a/tests/system-test/6-cluster/5dnode3mnodeStop2Follower.py b/tests/system-test/6-cluster/5dnode3mnodeStop2Follower.py index 584dd645f6f20c900b49404c15ec80b19427e90b..0596dd84edf2811ca382a58c75d642f9c1336fdb 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeStop2Follower.py +++ b/tests/system-test/6-cluster/5dnode3mnodeStop2Follower.py @@ -24,7 +24,7 @@ from multiprocessing import Process class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() @@ -75,14 +75,9 @@ class TDTestCase: tdSql.checkData(0,1,'%s:6030'%self.host) tdSql.checkData(4,1,'%s:6430'%self.host) clusterComCheck.checkDnodes(dnodenumbers) - clusterComCheck.checkMnodeStatus(1) - - # fisr add three mnodes; - tdLog.info("fisr add three mnodes and check mnode status") - tdSql.execute("create mnode on dnode 2") - clusterComCheck.checkMnodeStatus(2) - tdSql.execute("create mnode on dnode 3") - clusterComCheck.checkMnodeStatus(3) + + tdLog.info("check mnode status") + clusterComCheck.checkMnodeStatus(mnodeNums) # add some error operations and tdLog.info("Confirm the status of the dnode again") diff --git a/tests/system-test/6-cluster/5dnode3mnodeStopConnect.py b/tests/system-test/6-cluster/5dnode3mnodeStopConnect.py index 5638b01070c9547d0d5a0bde8a090d6bfd49eb43..2c735ed9b6230bbc52b446fcf0feba15fb9e1a44 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeStopConnect.py +++ b/tests/system-test/6-cluster/5dnode3mnodeStopConnect.py @@ -25,7 +25,7 @@ from multiprocessing import Process class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() @@ -75,15 +75,11 @@ class TDTestCase: tdSql.checkData(0,1,'%s:6030'%self.host) tdSql.checkData(4,1,'%s:6430'%self.host) clusterComCheck.checkDnodes(dnodenumbers) - clusterComCheck.checkMnodeStatus(1) - - # fisr add three mnodes; - tdLog.info("fisr add three mnodes and check mnode status") - tdSql.execute("create mnode on dnode 2") - clusterComCheck.checkMnodeStatus(2) - tdSql.execute("create mnode on dnode 3") - clusterComCheck.checkMnodeStatus(3) - + + #check mnode status + tdLog.info("check mnode status") + clusterComCheck.checkMnodeStatus(mnodeNums) + # add some error operations and tdLog.info("Confirm the status of the dnode again") tdSql.error("create mnode on dnode 2") diff --git a/tests/system-test/6-cluster/5dnode3mnodeStopFollowerLeader.py b/tests/system-test/6-cluster/5dnode3mnodeStopFollowerLeader.py index 6daa4c260a00e2956a8c0955c7e37e2b4aa829ad..d7176e142fa27007ad2d4940f0f8eb69078eb815 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeStopFollowerLeader.py +++ b/tests/system-test/6-cluster/5dnode3mnodeStopFollowerLeader.py @@ -24,7 +24,7 @@ from multiprocessing import Process class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() @@ -75,15 +75,11 @@ class TDTestCase: tdSql.checkData(0,1,'%s:6030'%self.host) tdSql.checkData(4,1,'%s:6430'%self.host) clusterComCheck.checkDnodes(dnodenumbers) - clusterComCheck.checkMnodeStatus(1) - - # fisr add three mnodes; - tdLog.info("fisr add three mnodes and check mnode status") - tdSql.execute("create mnode on dnode 2") - clusterComCheck.checkMnodeStatus(2) - tdSql.execute("create mnode on dnode 3") - clusterComCheck.checkMnodeStatus(3) - + + #check mnode status + tdLog.info("check mnode status") + clusterComCheck.checkMnodeStatus(mnodeNums) + # add some error operations and tdLog.info("Confirm the status of the dnode again") tdSql.error("create mnode on dnode 2") diff --git a/tests/system-test/6-cluster/5dnode3mnodeStopInsert.py b/tests/system-test/6-cluster/5dnode3mnodeStopInsert.py index dcd9e56a64470165962269825c62be65228d5bbb..780255604d58f2fdf27390278ac89d7d64d212ae 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeStopInsert.py +++ b/tests/system-test/6-cluster/5dnode3mnodeStopInsert.py @@ -26,7 +26,7 @@ class MyDnodes(TDDnodes): class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") self.TDDnodes = None diff --git a/tests/system-test/6-cluster/5dnode3mnodeStopLoop.py b/tests/system-test/6-cluster/5dnode3mnodeStopLoop.py index 1644686568d3c77c02c9dde98433b06d6184a0ea..52d61fb529b9893ba1de5f1594206eb421b4ffd4 100644 --- a/tests/system-test/6-cluster/5dnode3mnodeStopLoop.py +++ b/tests/system-test/6-cluster/5dnode3mnodeStopLoop.py @@ -24,7 +24,7 @@ from multiprocessing import Process class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() @@ -75,14 +75,10 @@ class TDTestCase: tdSql.checkData(0,1,'%s:6030'%self.host) tdSql.checkData(4,1,'%s:6430'%self.host) clusterComCheck.checkDnodes(dnodenumbers) - clusterComCheck.checkMnodeStatus(1) - # fisr add three mnodes; - tdLog.info("fisr add three mnodes and check mnode status") - tdSql.execute("create mnode on dnode 2") - clusterComCheck.checkMnodeStatus(2) - tdSql.execute("create mnode on dnode 3") - clusterComCheck.checkMnodeStatus(3) + #check mnode status + tdLog.info("check mnode status") + clusterComCheck.checkMnodeStatus(mnodeNums) # add some error operations and tdLog.info("Confirm the status of the dnode again") diff --git a/tests/system-test/6-cluster/clusterCommonCheck.py b/tests/system-test/6-cluster/clusterCommonCheck.py index 28c481083395c74c02238d380946bd00c0b74c0f..7cbe9d96806ad23c9234d2189e059e8ecefb1fd3 100644 --- a/tests/system-test/6-cluster/clusterCommonCheck.py +++ b/tests/system-test/6-cluster/clusterCommonCheck.py @@ -47,13 +47,14 @@ class ClusterComCheck: for i in range(dnodeNumbers): if tdSql.queryResult[i][4] == "ready": status+=1 - tdLog.info(status) + # tdLog.info(status) if status == dnodeNumbers: - tdLog.success("it find cluster with %d dnodes and check that all cluster dnodes are ready within %ds! " % (dnodeNumbers, count)) + tdLog.success("it find cluster with %d dnodes and check that all cluster dnodes are ready within %ds! " % (dnodeNumbers, count+1)) return True - count+=1 time.sleep(1) + count+=1 + else: tdSql.query("select * from information_schema.ins_dnodes") tdLog.debug(tdSql.queryResult) @@ -74,10 +75,10 @@ class ClusterComCheck: tdLog.debug(tdSql.queryResult) tdLog.exit("we find %d databases but expect %d in clusters! " %(tdSql.queryRows,dbNumbers)) - def checkDb(self,dbNumbers,restartNumber,dbNameIndex): + def checkDb(self,dbNumbers,restartNumber,dbNameIndex, timeout=100): count=0 alldbNumbers=(dbNumbers*restartNumber)+2 - while count < 5: + while count < timeout: query_status=0 for j in range(dbNumbers): for i in range(alldbNumbers): @@ -87,22 +88,24 @@ class ClusterComCheck: query_status+=1 tdLog.debug("check %s_%d that status is ready "%(dbNameIndex,j)) else: + sleep(1) continue # print(query_status) - count+=1 if query_status == dbNumbers: - tdLog.success(" check %d database and all databases are ready within 5s! " %dbNumbers) + tdLog.success(" check %d database and all databases are ready within %ds! " %(dbNumbers,count+1)) return True + count+=1 + else: tdLog.debug(tdSql.queryResult) tdLog.debug("query status is %d"%query_status) - tdLog.exit("database is not ready within 5s") + tdLog.exit("database is not ready within %ds"%(timeout+1)) def checkData(self,dbname,stbname,stableCount,CtableCount,rowsPerSTable,): tdSql.execute("use %s"%dbname) - tdSql.query("show stables") + tdSql.query("show %s.stables"%dbname) tdSql.checkRows(stableCount) - tdSql.query("show tables") + tdSql.query("show %s.tables"%dbname) tdSql.checkRows(CtableCount) for i in range(stableCount): tdSql.query("select count(*) from %s%d"%(stbname,i)) diff --git a/tests/system-test/6-cluster/clusterCommonCreate.py b/tests/system-test/6-cluster/clusterCommonCreate.py index 299829144e5ddafceacc828614fe1d7a0d2ed98a..236708cf072b72fed0381311e770252f58b82889 100644 --- a/tests/system-test/6-cluster/clusterCommonCreate.py +++ b/tests/system-test/6-cluster/clusterCommonCreate.py @@ -33,7 +33,7 @@ from util.common import * # INSERT_DATA = 3 class ClusterComCreate: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): tdSql.init(conn.cursor()) # tdSql.init(conn.cursor(), logSql) # output sql.txt file @@ -132,6 +132,17 @@ class ClusterComCreate: tdLog.debug("complete to create database %s_%d"%(dbNameIndex,i)) return + def createDeltedatabases(self,tsql,dbNameIndex,dbNumbers,dropFlag=1,vgroups=4,replica=1): + + # for i in range(dbNumbers): + for i in range(dbNumbers): + if dropFlag == 1: + tsql.execute("drop database if exists %s_%d"%(dbNameIndex,1)) + tdLog.debug("create database if not exists %s_%d vgroups %d replica %d"%(dbNameIndex,1, vgroups, replica)) + tsql.execute("create database if not exists %s_%d vgroups %d replica %d"%(dbNameIndex,1, vgroups, replica)) + tdLog.debug("complete to create database %s_%d"%(dbNameIndex,1)) + + def create_stable(self,tsql, dbName,stbName): tsql.execute("create table if not exists %s.%s (ts timestamp, c1 int, c2 int, c3 binary(16)) tags(t1 int, t2 binary(32))"%(dbName, stbName)) tdLog.debug("complete to create %s.%s" %(dbName, stbName)) diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_createDb_replica1.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_createDb_replica1.py index 8d07dc6b38b4a6c72f98849408388fb1fd3d4afc..9bdc0a2cf486451d74416384a1bbac2db1707570 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_createDb_replica1.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_createDb_replica1.py @@ -18,7 +18,8 @@ import subprocess sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica1_insertdatas.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica1_insertdatas.py index 470278cd8e5a0d778e4a268bbee60086db2dd6d5..d33a1b0d271a424945dee73054faa2db8728a40a 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica1_insertdatas.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica1_insertdatas.py @@ -18,7 +18,8 @@ import subprocess sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica1_insertdatas_querys.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica1_insertdatas_querys.py index 0484ee9f3307d0b5005eee19560dafc69418d7cc..75e01977fd5a11538f7dc07e6a43d55ccdcfc45b 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica1_insertdatas_querys.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica1_insertdatas_querys.py @@ -18,7 +18,8 @@ import subprocess ,threading sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas.py index 60e3167304205643ff2981db8dd687401f1b220d..77dcab90bff070468c4439fc32f8cf24c39b9fdd 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas.py @@ -18,7 +18,8 @@ import subprocess sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_force_stop_all_dnodes.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_force_stop_all_dnodes.py index 0557836ab215ef83f34e1d0a530910a5c5701504..1a2c31a311d421185ef7446c438fd61c05dbb2cd 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_force_stop_all_dnodes.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_force_stop_all_dnodes.py @@ -21,7 +21,8 @@ import threading sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys.py index 8523ac72a4021f247c694cb3d3670b48157a69da..a9fb9555e8489dc1ab7eb84d4bfdf99b02415a3a 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys.py @@ -18,7 +18,8 @@ import subprocess ,threading sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys_loop_restart_all_vnode.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys_loop_restart_all_vnode.py index 8e7ac388fb51cd101b9edf112c049664cb9d07b5..2eb631d433e26477f3dcefbd103859003f9c20a2 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys_loop_restart_all_vnode.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys_loop_restart_all_vnode.py @@ -18,7 +18,8 @@ import subprocess ,threading sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys_loop_restart_follower.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys_loop_restart_follower.py index 37c00c4b8daa94db8d2db299fcc9902c2135c116..6102a82b0434854070cb06fb52cdca83e6c5e596 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys_loop_restart_follower.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys_loop_restart_follower.py @@ -18,7 +18,8 @@ import subprocess ,threading sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys_loop_restart_leader.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys_loop_restart_leader.py index f1ff805f0808fbad779b54a560890ce1700bd43f..d87ec3d35e130b94309f1e51247a7ab598cc69df 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys_loop_restart_leader.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys_loop_restart_leader.py @@ -18,7 +18,8 @@ import subprocess ,threading sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_all_dnodes.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_all_dnodes.py index 07231555feb4a2d5ce81f117802df7bc8291fcdc..fc6d3c06830d457b3f89b9f932c91ba22686cfde 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_all_dnodes.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_all_dnodes.py @@ -21,7 +21,8 @@ import threading sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_follower_sync.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_follower_sync.py index 80d367db017b43fb741a6cf4b499991d211087c1..00b808b8b408a55e79da665b7e78adbf2c4c1c7e 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_follower_sync.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_follower_sync.py @@ -21,7 +21,8 @@ import threading sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_follower_unsync.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_follower_unsync.py index 55a2318817b09b9bb74360cc3dfda2a0a21a50b5..e64649189dcdcec1efda4cd2835b968d668deafd 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_follower_unsync.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_follower_unsync.py @@ -21,7 +21,8 @@ import threading sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_follower_unsync_force_stop.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_follower_unsync_force_stop.py index 489e2acd43c625eb9fc00a239b255589dd4c0ec3..b633887009f23882d8c47f9dc199b9e7bf99f7a3 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_follower_unsync_force_stop.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_follower_unsync_force_stop.py @@ -21,7 +21,8 @@ import threading sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_leader.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_leader.py index ee0ab26f4ce9dcac4e3d76ed9bd1779a484cb90f..6415da94b4d7386478db46b81c36369da4e34503 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_leader.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_leader.py @@ -19,7 +19,8 @@ import threading sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_leader_forece_stop.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_leader_forece_stop.py index c7895abe047a8a8d0dd34c9d5044e8cad6a19702..1b99c1e92bced00bd0fd08f6d20fad399b912634 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_leader_forece_stop.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_leader_forece_stop.py @@ -19,7 +19,8 @@ import threading sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_mnode3_insertdatas_querys.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_mnode3_insertdatas_querys.py index aca188824d65827ff7541c60e15f178efd225deb..ea5c4679a987cf00633fdb7565aca949f20cb9c8 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_mnode3_insertdatas_querys.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_mnode3_insertdatas_querys.py @@ -18,7 +18,8 @@ import subprocess ,threading sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_follower.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_follower.py index fa6964307962e78de0997391e0b4dc552b16f823..1dcaae452e8673f3e7c60ad8452f7970fb15c205 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_follower.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_follower.py @@ -21,7 +21,8 @@ import threading sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_follower_force_stop.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_follower_force_stop.py index 0ef8db9c0fb96f9515e81abac2d119e9824a8f59..945fcf2990daad786e4a53f969c53e2c6c85ead5 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_follower_force_stop.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_follower_force_stop.py @@ -21,7 +21,8 @@ import threading sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_leader.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_leader.py index f26df70c4efe0c6d2454595188ac4aa9aea1b895..6b87bee5a3c7a018336c46ca1f65eccddbe6bdce 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_leader.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_leader.py @@ -21,7 +21,8 @@ import threading sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_leader_force_stop.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_leader_force_stop.py index 2f57af39b019fed0bf1caf672555250cd20be5af..8ef151a385b7bbedf728fafa0f595add849be490 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_leader_force_stop.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_leader_force_stop.py @@ -21,7 +21,8 @@ import threading sys.path.append(os.path.dirname(__file__)) class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_vgroups.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_vgroups.py index 221053d16540816ec64a45916a72fa5e07459d46..49e5cafe96717159fa6225e672de5f96c12210c0 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_vgroups.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_vgroups.py @@ -17,7 +17,8 @@ import socket import subprocess class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_vgroups_stopOne.py b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_vgroups_stopOne.py index 05ec8efcd27ae2972955498f6b6696eaba944814..20cf7c583ae070d69244dcec37d9bd28bed4291c 100644 --- a/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_vgroups_stopOne.py +++ b/tests/system-test/6-cluster/vnode/4dnode1mnode_basic_replica3_vgroups_stopOne.py @@ -19,7 +19,8 @@ import socket import subprocess class TDTestCase: - def init(self,conn ,logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) self.host = socket.gethostname() diff --git a/tests/system-test/7-tmq/basic5.py b/tests/system-test/7-tmq/basic5.py index 9531541f137a0de2bea23cb7e87bde17b85430e5..7d42a3e81f60f2acfba6913e699c553be6a2c1d5 100644 --- a/tests/system-test/7-tmq/basic5.py +++ b/tests/system-test/7-tmq/basic5.py @@ -26,7 +26,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/create_wrong_topic.py b/tests/system-test/7-tmq/create_wrong_topic.py index d18cb0260e90c721c37202e5d08bbaaa0a48da10..39d519fec1be19009860408dd02d26630070af44 100644 --- a/tests/system-test/7-tmq/create_wrong_topic.py +++ b/tests/system-test/7-tmq/create_wrong_topic.py @@ -13,7 +13,8 @@ from util.dnodes import * from util.sqlset import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug("start to execute %s" % __file__) tdSql.init(conn.cursor(),logSql) self.setsql = TDSetSql() diff --git a/tests/system-test/7-tmq/dataFromTsdbNWal-multiCtb.py b/tests/system-test/7-tmq/dataFromTsdbNWal-multiCtb.py index 4add73ec2b7fb804d05c9ef45d6563f1c9edfe1b..808a4935e30ccec4d06863e54e5e2ff3e1ba635d 100644 --- a/tests/system-test/7-tmq/dataFromTsdbNWal-multiCtb.py +++ b/tests/system-test/7-tmq/dataFromTsdbNWal-multiCtb.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 100 self.rowsPerTbl = 1000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/dataFromTsdbNWal.py b/tests/system-test/7-tmq/dataFromTsdbNWal.py index 950c8fdcf6218fb6a0cc54573009bef41ffc0ffd..8386c22cd0430128a1b873f3f5150ef51704b245 100644 --- a/tests/system-test/7-tmq/dataFromTsdbNWal.py +++ b/tests/system-test/7-tmq/dataFromTsdbNWal.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 1 self.rowsPerTbl = 10000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/db.py b/tests/system-test/7-tmq/db.py index da5d7fefd2b2ca2f06ceaf81d6ceb116e8bbdfcd..04f5aac559b060e17b23618cea1007e41ffb858d 100644 --- a/tests/system-test/7-tmq/db.py +++ b/tests/system-test/7-tmq/db.py @@ -27,7 +27,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/dropDbR3ConflictTransaction.py b/tests/system-test/7-tmq/dropDbR3ConflictTransaction.py index fc4fdcecf9f31dc341f1a26d49b4d7efda5deae3..4371a909c253b3aaf1f7f4d5fad931ee35665519 100644 --- a/tests/system-test/7-tmq/dropDbR3ConflictTransaction.py +++ b/tests/system-test/7-tmq/dropDbR3ConflictTransaction.py @@ -26,7 +26,8 @@ class TDTestCase: self.ctbNum = 2 self.rowsPerTbl = 2 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/schema.py b/tests/system-test/7-tmq/schema.py index 34d36e57927ca8605b11deeac7a1c4165bbf9905..04224fbc7e86d177829f898855067986aae81746 100644 --- a/tests/system-test/7-tmq/schema.py +++ b/tests/system-test/7-tmq/schema.py @@ -27,7 +27,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/stbFilter.py b/tests/system-test/7-tmq/stbFilter.py index 4942a39db458f0e307649903e7449295d8909cc3..6b48a6d57076b4baf54d7c08db7cd8a625fab29c 100644 --- a/tests/system-test/7-tmq/stbFilter.py +++ b/tests/system-test/7-tmq/stbFilter.py @@ -15,7 +15,8 @@ sys.path.append("./7-tmq") from tmqCommon import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/stbTagFilter-1ctb.py b/tests/system-test/7-tmq/stbTagFilter-1ctb.py index 6cb152342be5c80b5f755d0b3f2f7e7bf1c7894a..c4a7c8cae5551c6374d683f941148f8f054dd53c 100644 --- a/tests/system-test/7-tmq/stbTagFilter-1ctb.py +++ b/tests/system-test/7-tmq/stbTagFilter-1ctb.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 1 self.rowsPerTbl = 10000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/stbTagFilter-multiCtb.py b/tests/system-test/7-tmq/stbTagFilter-multiCtb.py index 9053bf26206f73950018f41e05e247fe9e36c181..c380d201b2d8827c6e3d12f03a0168ed47af0362 100644 --- a/tests/system-test/7-tmq/stbTagFilter-multiCtb.py +++ b/tests/system-test/7-tmq/stbTagFilter-multiCtb.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 100 self.rowsPerTbl = 1000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/subscribeDb.py b/tests/system-test/7-tmq/subscribeDb.py index ba46f72695fb607ba14f48821db37cce1da1d441..fd06eedefdcd899fb71261bd4e97324ee0170a1b 100644 --- a/tests/system-test/7-tmq/subscribeDb.py +++ b/tests/system-test/7-tmq/subscribeDb.py @@ -20,7 +20,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file @@ -209,7 +210,7 @@ class TDTestCase: # wait for data ready prepareEnvThread.join() - tdLog.info("insert process end, and start to check consume result") + tdLog.info("1-insert process end, and start to check consume result") expectRows = 1 resultList = self.selectConsumeResult(expectRows) totalConsumeRows = 0 @@ -310,7 +311,7 @@ class TDTestCase: # wait for data ready prepareEnvThread.join() - tdLog.info("insert process end, and start to check consume result") + tdLog.info("2-insert process end, and start to check consume result") expectRows = 2 resultList = self.selectConsumeResult(expectRows) totalConsumeRows = 0 @@ -379,7 +380,7 @@ class TDTestCase: # wait for data ready prepareEnvThread.join() - tdLog.info("insert process end, and start to check consume result") + tdLog.info("3-insert process end, and start to check consume result") expectRows = 2 resultList = self.selectConsumeResult(expectRows) totalConsumeRows = 0 @@ -459,7 +460,7 @@ class TDTestCase: prepareEnvThread.join() prepareEnvThread2.join() - tdLog.info("insert process end, and start to check consume result") + tdLog.info("4-insert process end, and start to check consume result") expectRows = 1 resultList = self.selectConsumeResult(expectRows) totalConsumeRows = 0 diff --git a/tests/system-test/7-tmq/subscribeDb0.py b/tests/system-test/7-tmq/subscribeDb0.py index 7720001fbb79353e8c81eea89aded209f1a8fc99..d4c5e2f87fd6b06eb874f8398ce64ee6eb5947cc 100644 --- a/tests/system-test/7-tmq/subscribeDb0.py +++ b/tests/system-test/7-tmq/subscribeDb0.py @@ -20,7 +20,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/subscribeDb1.py b/tests/system-test/7-tmq/subscribeDb1.py index 404938158f55b5ff82958b73711054b5b9d5edc6..ea78c90abddebac86391af732750d8f670b80492 100644 --- a/tests/system-test/7-tmq/subscribeDb1.py +++ b/tests/system-test/7-tmq/subscribeDb1.py @@ -20,7 +20,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/subscribeDb2.py b/tests/system-test/7-tmq/subscribeDb2.py index 4702aef035081abcf51d619fda2a26f666174d1b..d045842e45f4f526e5916081774177b22847ef11 100644 --- a/tests/system-test/7-tmq/subscribeDb2.py +++ b/tests/system-test/7-tmq/subscribeDb2.py @@ -21,7 +21,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/subscribeDb3.py b/tests/system-test/7-tmq/subscribeDb3.py index 0ff609ab6bc1cbeac9c02dead2ed06b6b7d6f5d0..819588badcc2be26acd3461297caae5bec546c00 100644 --- a/tests/system-test/7-tmq/subscribeDb3.py +++ b/tests/system-test/7-tmq/subscribeDb3.py @@ -20,7 +20,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/subscribeDb4.py b/tests/system-test/7-tmq/subscribeDb4.py index d253c34a532eb122b9479537ff30129be20018fb..7f5169361c1e3130bef0c29fd8eef1e6837248d8 100644 --- a/tests/system-test/7-tmq/subscribeDb4.py +++ b/tests/system-test/7-tmq/subscribeDb4.py @@ -51,7 +51,8 @@ class TDTestCase: hostname = socket.gethostname() - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") logSql = False tdSql.init(conn.cursor(), logSql) diff --git a/tests/system-test/7-tmq/subscribeStb.py b/tests/system-test/7-tmq/subscribeStb.py index 2757e590a3904dfcd584ae8e35c5e861dcbbb9db..3ff0b25ff6b4585a8abc4061e7e46abced77d15e 100644 --- a/tests/system-test/7-tmq/subscribeStb.py +++ b/tests/system-test/7-tmq/subscribeStb.py @@ -27,7 +27,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/subscribeStb0.py b/tests/system-test/7-tmq/subscribeStb0.py index 26e834ae2c4ce898ee57971a8eb0066d0ad24838..1463cad627a23dd106d6afb78a4ee274345a840f 100644 --- a/tests/system-test/7-tmq/subscribeStb0.py +++ b/tests/system-test/7-tmq/subscribeStb0.py @@ -27,7 +27,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/subscribeStb1.py b/tests/system-test/7-tmq/subscribeStb1.py index 0c49636b158b9b3dc4c810bf4bfd10fac0cc4473..edbe1bc3c6dbcbef26a9068c3d644db03d1d9d12 100644 --- a/tests/system-test/7-tmq/subscribeStb1.py +++ b/tests/system-test/7-tmq/subscribeStb1.py @@ -27,7 +27,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/subscribeStb2.py b/tests/system-test/7-tmq/subscribeStb2.py index 2cbb16ec0027930c7f02ae7fc50a69117fb77f9f..6c3e122902cc907dacd8297d95f27c6289cad176 100644 --- a/tests/system-test/7-tmq/subscribeStb2.py +++ b/tests/system-test/7-tmq/subscribeStb2.py @@ -27,7 +27,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/subscribeStb3.py b/tests/system-test/7-tmq/subscribeStb3.py index 9c1b3fd241fffd1d3c09f914549291983a5f9505..025f403282e46eab4893062069bcea820124203b 100644 --- a/tests/system-test/7-tmq/subscribeStb3.py +++ b/tests/system-test/7-tmq/subscribeStb3.py @@ -27,7 +27,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/subscribeStb4.py b/tests/system-test/7-tmq/subscribeStb4.py index 33f4c4af1a87bfef576fc0fb702d65732711ab95..6aa3da66a46b316c55b2586bfc4c82f96fc33a8c 100644 --- a/tests/system-test/7-tmq/subscribeStb4.py +++ b/tests/system-test/7-tmq/subscribeStb4.py @@ -27,7 +27,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/tmq3mnodeSwitch.py b/tests/system-test/7-tmq/tmq3mnodeSwitch.py index 7ba914c05cdb9995080b0e5d856d22e970798631..a6bf01aa068ec44241e4397a3dab7ab56af83ea1 100644 --- a/tests/system-test/7-tmq/tmq3mnodeSwitch.py +++ b/tests/system-test/7-tmq/tmq3mnodeSwitch.py @@ -32,7 +32,8 @@ class TDTestCase: self.portStep = 100 self.dnodeOfLeader = 0 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/tmqAlterSchema.py b/tests/system-test/7-tmq/tmqAlterSchema.py index 232a1e11faaf0474ebd12cb8fa83e15bc94bf6da..a70678219f15ba94b7f9ceb1f81b9aa3881660d4 100644 --- a/tests/system-test/7-tmq/tmqAlterSchema.py +++ b/tests/system-test/7-tmq/tmqAlterSchema.py @@ -32,7 +32,8 @@ class TDTestCase: self.portStep = 100 self.dnodeOfLeader = 0 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/tmqAutoCreateTbl.py b/tests/system-test/7-tmq/tmqAutoCreateTbl.py index ce2cad4b148a22d15dbc831ff5824f9ed66d651e..41073d83ae13b5a3828bbc758d8d1d2c600f8ca6 100644 --- a/tests/system-test/7-tmq/tmqAutoCreateTbl.py +++ b/tests/system-test/7-tmq/tmqAutoCreateTbl.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 500 self.rowsPerTbl = 1000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqCheckData.py b/tests/system-test/7-tmq/tmqCheckData.py index 9338debfa6f5f9161cfa700dd2c3fdbdaa2fa8b7..04d0744ab595279ac834e62669cb100df113d253 100644 --- a/tests/system-test/7-tmq/tmqCheckData.py +++ b/tests/system-test/7-tmq/tmqCheckData.py @@ -15,7 +15,8 @@ sys.path.append("./7-tmq") from tmqCommon import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/tmqCheckData1.py b/tests/system-test/7-tmq/tmqCheckData1.py index 7c236bbe8bbfb6f0a1c66f3c7e1340081304a9f5..b9dac62833ba45dc63fca65e1b6f642265b655dd 100644 --- a/tests/system-test/7-tmq/tmqCheckData1.py +++ b/tests/system-test/7-tmq/tmqCheckData1.py @@ -15,7 +15,8 @@ sys.path.append("./7-tmq") from tmqCommon import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/tmqCommon.py b/tests/system-test/7-tmq/tmqCommon.py index b1455ebe48d03e314a5421fbb8fa3bd4d41ab9d9..c153e94caac3f79ebb61b0440486ed137f33c373 100644 --- a/tests/system-test/7-tmq/tmqCommon.py +++ b/tests/system-test/7-tmq/tmqCommon.py @@ -37,7 +37,8 @@ from util.common import * # INSERT_DATA = 3 class TMQCom: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdSql.init(conn.cursor()) # tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/tmqConsFromTsdb-1ctb-funcNFilter.py b/tests/system-test/7-tmq/tmqConsFromTsdb-1ctb-funcNFilter.py index 20b0c65c714cda7709ba80d6289c628d0de2922e..f372a2b7428a77b02b8dcdb5c4c546756ef7e1f7 100644 --- a/tests/system-test/7-tmq/tmqConsFromTsdb-1ctb-funcNFilter.py +++ b/tests/system-test/7-tmq/tmqConsFromTsdb-1ctb-funcNFilter.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 1 self.rowsPerTbl = 100000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqConsFromTsdb-1ctb.py b/tests/system-test/7-tmq/tmqConsFromTsdb-1ctb.py index 494952ecd5538b47d2bf59167cb6f4d934049f13..c7f95f6f41cbf72e8d64c3a9bd8218dfd7a1c6d5 100644 --- a/tests/system-test/7-tmq/tmqConsFromTsdb-1ctb.py +++ b/tests/system-test/7-tmq/tmqConsFromTsdb-1ctb.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 1 self.rowsPerTbl = 100000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqConsFromTsdb-mutilVg-mutilCtb-funcNFilter.py b/tests/system-test/7-tmq/tmqConsFromTsdb-mutilVg-mutilCtb-funcNFilter.py index 666ca6ca646937fb29ea9ec6346ebd97e5351dae..26dacf514d4f66273d36f6ac3fe49ee17602747a 100644 --- a/tests/system-test/7-tmq/tmqConsFromTsdb-mutilVg-mutilCtb-funcNFilter.py +++ b/tests/system-test/7-tmq/tmqConsFromTsdb-mutilVg-mutilCtb-funcNFilter.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 3000 self.rowsPerTbl = 150 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqConsFromTsdb-mutilVg-mutilCtb.py b/tests/system-test/7-tmq/tmqConsFromTsdb-mutilVg-mutilCtb.py index e4ce3b0f773218a78c411d1aae31aca8da11c350..d6f100041b15c205e8294cca964353d880b9ecc4 100644 --- a/tests/system-test/7-tmq/tmqConsFromTsdb-mutilVg-mutilCtb.py +++ b/tests/system-test/7-tmq/tmqConsFromTsdb-mutilVg-mutilCtb.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 3000 self.rowsPerTbl = 70 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqConsFromTsdb-mutilVg.py b/tests/system-test/7-tmq/tmqConsFromTsdb-mutilVg.py index da7d9e4651325c45ef071285bea03a4b4984c84c..9bfc01529fda135789e55cbe0d01b39e2a6c2639 100644 --- a/tests/system-test/7-tmq/tmqConsFromTsdb-mutilVg.py +++ b/tests/system-test/7-tmq/tmqConsFromTsdb-mutilVg.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 10 self.rowsPerTbl = 10000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqConsFromTsdb.py b/tests/system-test/7-tmq/tmqConsFromTsdb.py index b3bb5f84e43f8257eeb60e16a4f149e28d0a1496..975f89cbd7977df5640d2000a885eaf975a401e6 100644 --- a/tests/system-test/7-tmq/tmqConsFromTsdb.py +++ b/tests/system-test/7-tmq/tmqConsFromTsdb.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 10 self.rowsPerTbl = 10000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqConsFromTsdb1-1ctb-funcNFilter.py b/tests/system-test/7-tmq/tmqConsFromTsdb1-1ctb-funcNFilter.py index 07fb9c77515411f43035374ba8c46972777788cd..6a03f0f75192dda0b8b8394b1733bdec02222bda 100644 --- a/tests/system-test/7-tmq/tmqConsFromTsdb1-1ctb-funcNFilter.py +++ b/tests/system-test/7-tmq/tmqConsFromTsdb1-1ctb-funcNFilter.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 1 self.rowsPerTbl = 1000000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqConsFromTsdb1-1ctb.py b/tests/system-test/7-tmq/tmqConsFromTsdb1-1ctb.py index 313ff7476e3b2144470766741ef6ab2a77a14336..009862137f8ccbb45f0f9bbfa134ae1a5b0479f1 100644 --- a/tests/system-test/7-tmq/tmqConsFromTsdb1-1ctb.py +++ b/tests/system-test/7-tmq/tmqConsFromTsdb1-1ctb.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 1 self.rowsPerTbl = 100000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqConsFromTsdb1-mutilVg-mutilCtb-funcNFilter.py b/tests/system-test/7-tmq/tmqConsFromTsdb1-mutilVg-mutilCtb-funcNFilter.py index 05f7030169490c1e9bf2dbe321efee4cbe0bd7d0..95ce03e6533223288b2424dcc22932b1e9b54a5a 100644 --- a/tests/system-test/7-tmq/tmqConsFromTsdb1-mutilVg-mutilCtb-funcNFilter.py +++ b/tests/system-test/7-tmq/tmqConsFromTsdb1-mutilVg-mutilCtb-funcNFilter.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 4000 self.rowsPerTbl = 150 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqConsFromTsdb1-mutilVg-mutilCtb.py b/tests/system-test/7-tmq/tmqConsFromTsdb1-mutilVg-mutilCtb.py index 232d90848fc08c74c46308147942c90e85e7d509..8ff01444f81c5b5bdb52c3885970faca5b779a1b 100644 --- a/tests/system-test/7-tmq/tmqConsFromTsdb1-mutilVg-mutilCtb.py +++ b/tests/system-test/7-tmq/tmqConsFromTsdb1-mutilVg-mutilCtb.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 3000 self.rowsPerTbl = 70 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqConsFromTsdb1-mutilVg.py b/tests/system-test/7-tmq/tmqConsFromTsdb1-mutilVg.py index 5841c6d60534eef7a98c5fd6aa0abe629fc4ebb7..528b3a80887c3cc62b1092e5183249e962f5e8db 100644 --- a/tests/system-test/7-tmq/tmqConsFromTsdb1-mutilVg.py +++ b/tests/system-test/7-tmq/tmqConsFromTsdb1-mutilVg.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 10 self.rowsPerTbl = 10000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqConsFromTsdb1.py b/tests/system-test/7-tmq/tmqConsFromTsdb1.py index d0ab8d4fe30b8c39de75214b21c8daa6c3ff75e6..c0c459d315efa541115cf666b85203f69794b306 100644 --- a/tests/system-test/7-tmq/tmqConsFromTsdb1.py +++ b/tests/system-test/7-tmq/tmqConsFromTsdb1.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 10 self.rowsPerTbl = 10000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqConsumerGroup.py b/tests/system-test/7-tmq/tmqConsumerGroup.py index b5cbfb8a5115d5bc268e264ea9d9d5cdd1b6bef7..02093a2d889f1f7138e29055145bc63318dd2873 100644 --- a/tests/system-test/7-tmq/tmqConsumerGroup.py +++ b/tests/system-test/7-tmq/tmqConsumerGroup.py @@ -15,7 +15,8 @@ sys.path.append("./7-tmq") from tmqCommon import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/tmqDelete-1ctb.py b/tests/system-test/7-tmq/tmqDelete-1ctb.py index 8329b00145d71ab6df045f23fb20dc015034a2c2..4b45b1a83410437db56b1b9d89f0af3f55c06b01 100644 --- a/tests/system-test/7-tmq/tmqDelete-1ctb.py +++ b/tests/system-test/7-tmq/tmqDelete-1ctb.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 1 self.rowsPerTbl = 10000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqDelete-multiCtb.py b/tests/system-test/7-tmq/tmqDelete-multiCtb.py index c9d90b45bee55119ecce1f8950ec02461e769c97..3b72b4aea5d1df34e0230a98953d671536442cab 100644 --- a/tests/system-test/7-tmq/tmqDelete-multiCtb.py +++ b/tests/system-test/7-tmq/tmqDelete-multiCtb.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 100 self.rowsPerTbl = 1000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqDnode.py b/tests/system-test/7-tmq/tmqDnode.py index 802993e9247254b069383d67c050a4449ee7a1e4..e1d6d91e2d620fe6a1ca7b28a5762047eaaa9bed 100644 --- a/tests/system-test/7-tmq/tmqDnode.py +++ b/tests/system-test/7-tmq/tmqDnode.py @@ -27,7 +27,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/tmqDnodeRestart.py b/tests/system-test/7-tmq/tmqDnodeRestart.py index bcc672584897cb4bee8219b229ecdcf64700bf53..a44ff916e5a22c92e68d743333e4c4b921929111 100644 --- a/tests/system-test/7-tmq/tmqDnodeRestart.py +++ b/tests/system-test/7-tmq/tmqDnodeRestart.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 100 self.rowsPerTbl = 1000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) @@ -87,7 +88,7 @@ class TDTestCase: 'rowsPerTbl': 1000, 'batchNum': 100, 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 - 'pollDelay': 10, + 'pollDelay': 30, 'showMsg': 1, 'showRow': 1, 'snapshot': 0} @@ -173,7 +174,7 @@ class TDTestCase: 'rowsPerTbl': 1000, 'batchNum': 100, 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 - 'pollDelay': 20, + 'pollDelay': 30, 'showMsg': 1, 'showRow': 1, 'snapshot': 0} diff --git a/tests/system-test/7-tmq/tmqDnodeRestart1.py b/tests/system-test/7-tmq/tmqDnodeRestart1.py index bb3cee616a202d03966d699ebf8e1da44ac6126b..714f10b362f9a901252fcc63c790977e266b76d5 100644 --- a/tests/system-test/7-tmq/tmqDnodeRestart1.py +++ b/tests/system-test/7-tmq/tmqDnodeRestart1.py @@ -21,7 +21,7 @@ class TDTestCase: self.ctbNum = 100 self.rowsPerTbl = 1000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) @@ -40,9 +40,9 @@ class TDTestCase: 'ctbStartIdx': 0, 'ctbNum': 100, 'rowsPerTbl': 1000, - 'batchNum': 10, + 'batchNum': 100, 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 - 'pollDelay': 3, + 'pollDelay': 30, 'showMsg': 1, 'showRow': 1, 'snapshot': 0} @@ -87,7 +87,7 @@ class TDTestCase: 'rowsPerTbl': 1000, 'batchNum': 100, 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 - 'pollDelay': 10, + 'pollDelay': 30, 'showMsg': 1, 'showRow': 1, 'snapshot': 0} @@ -101,6 +101,7 @@ class TDTestCase: topicFromStb = 'topic_stb' queryString = "select * from %s.%s"%(paraDict['dbName'], paraDict['stbName']) sqlString = "create topic %s as stable %s.%s" %(topicFromStb, paraDict['dbName'], paraDict['stbName']) + #sqlString = "create topic %s as %s" %(topicFromStb, queryString) tdLog.info("create topic sql: %s"%sqlString) tdSql.execute(sqlString) @@ -111,7 +112,7 @@ class TDTestCase: ifManualCommit = 0 keyList = 'group.id:cgrp1,\ enable.auto.commit:true,\ - auto.commit.interval.ms:1000,\ + auto.commit.interval.ms:200,\ auto.offset.reset:latest' tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) @@ -119,7 +120,15 @@ class TDTestCase: tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) # time.sleep(3) - tmqCom.getStartCommitNotifyFromTmqsim() + tmqCom.getStartCommitNotifyFromTmqsim('cdb',1) + + tdLog.info("create some new child table and insert data for latest mode") + paraDict["batchNum"] = 100 + paraDict["ctbPrefix"] = 'newCtb' + paraDict["ctbNum"] = 10 + paraDict["rowsPerTbl"] = 10 + tmqCom.insert_data_with_autoCreateTbl(tdSql,paraDict["dbName"],paraDict["stbName"],paraDict["ctbPrefix"],paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"]) + tdLog.info("================= restart dnode ===========================") tdDnodes.stoptaosd(1) tdDnodes.starttaosd(1) @@ -132,8 +141,7 @@ class TDTestCase: for i in range(expectRows): totalConsumeRows += resultList[i] - tdSql.query(queryString) - totalRowsFromQury = tdSql.getRows() + totalRowsFromQury = paraDict["ctbNum"] * paraDict["rowsPerTbl"] tdLog.info("act consume rows: %d, act query rows: %d"%(totalConsumeRows, totalRowsFromQury)) if (totalConsumeRows < totalRowsFromQury): @@ -161,7 +169,7 @@ class TDTestCase: 'rowsPerTbl': 1000, 'batchNum': 100, 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 - 'pollDelay': 10, + 'pollDelay': 30, 'showMsg': 1, 'showRow': 1, 'snapshot': 0} @@ -185,19 +193,25 @@ class TDTestCase: ifManualCommit = 0 keyList = 'group.id:cgrp1,\ enable.auto.commit:true,\ - auto.commit.interval.ms:1000,\ + auto.commit.interval.ms:200,\ auto.offset.reset:latest' tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) tdLog.info("start consume processor") tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) - # time.sleep(3) - tmqCom.getStartCommitNotifyFromTmqsim() + tmqCom.getStartCommitNotifyFromTmqsim('cdb',1) + + tdLog.info("create some new child table and insert data for latest mode") + paraDict["batchNum"] = 100 + paraDict["ctbPrefix"] = 'newCtb' + paraDict["ctbNum"] = 10 + paraDict["rowsPerTbl"] = 10 + tmqCom.insert_data_with_autoCreateTbl(tdSql,paraDict["dbName"],paraDict["stbName"],paraDict["ctbPrefix"],paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"]) + tdLog.info("================= restart dnode ===========================") tdDnodes.stoptaosd(1) tdDnodes.starttaosd(1) - # time.sleep(3) tdLog.info(" restart taosd end and wait to check consume result") expectRows = 1 @@ -206,8 +220,7 @@ class TDTestCase: for i in range(expectRows): totalConsumeRows += resultList[i] - tdSql.query(queryString) - totalRowsFromQury = tdSql.getRows() + totalRowsFromQury = paraDict["ctbNum"] * paraDict["rowsPerTbl"] tdLog.info("act consume rows: %d, act query rows: %d"%(totalConsumeRows, totalRowsFromQury)) if (totalConsumeRows < totalRowsFromQury): diff --git a/tests/system-test/7-tmq/tmqDropNtb-snapshot0.py b/tests/system-test/7-tmq/tmqDropNtb-snapshot0.py index b952dc2d572aa85e1819519d40e563086df1c4a9..6c49fae299ac68aac99892acf5de3011df0ab1a0 100644 --- a/tests/system-test/7-tmq/tmqDropNtb-snapshot0.py +++ b/tests/system-test/7-tmq/tmqDropNtb-snapshot0.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 1000 self.rowsPerTbl = 10 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqDropNtb-snapshot1.py b/tests/system-test/7-tmq/tmqDropNtb-snapshot1.py index 4cb208b616097815ce8dfb099854c5c936fcf08c..3fc5a2fdc70b64ec95324c370625f5397287ae7d 100644 --- a/tests/system-test/7-tmq/tmqDropNtb-snapshot1.py +++ b/tests/system-test/7-tmq/tmqDropNtb-snapshot1.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 1000 self.rowsPerTbl = 10 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqDropStb.py b/tests/system-test/7-tmq/tmqDropStb.py index b172224c2a1651fabf3779e07e7d0ab5706b2ba9..3789632984c91e49358ea21124824138642162ea 100644 --- a/tests/system-test/7-tmq/tmqDropStb.py +++ b/tests/system-test/7-tmq/tmqDropStb.py @@ -51,7 +51,8 @@ class TDTestCase: hostname = socket.gethostname() - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") logSql = False tdSql.init(conn.cursor(), logSql) diff --git a/tests/system-test/7-tmq/tmqDropStbCtb.py b/tests/system-test/7-tmq/tmqDropStbCtb.py index 704811d083c47db53592cce8db85c71733a29057..c9e34136cc1e59af173205a8e0cb2796acb1a14a 100644 --- a/tests/system-test/7-tmq/tmqDropStbCtb.py +++ b/tests/system-test/7-tmq/tmqDropStbCtb.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 100 self.rowsPerTbl = 1000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqError.py b/tests/system-test/7-tmq/tmqError.py index 2d7b464025f0b014620bf9f3eaea03f01dce27bf..164e7f1c8c9b6d456b903d72c3555d2252a52298 100644 --- a/tests/system-test/7-tmq/tmqError.py +++ b/tests/system-test/7-tmq/tmqError.py @@ -11,6 +11,8 @@ from util.log import * from util.sql import * from util.cases import * from util.dnodes import * +sys.path.append("./7-tmq") +from tmqCommon import * class actionType(Enum): CREATE_DATABASE = 0 @@ -27,7 +29,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file @@ -193,32 +196,41 @@ class TDTestCase: and restart a consumption process to complete a consumption ''' tdLog.printNoPrefix("======== test case 1: ") - - self.initConsumerTable() - - # create and start thread - parameterDict = {'cfg': '', \ - 'actionType': 0, \ - 'dbName': 'db3', \ - 'dropFlag': 1, \ - 'vgroups': 4, \ - 'replica': 1, \ - 'stbName': 'stb1', \ - 'ctbNum': 10, \ - 'rowsPerTbl': 20000, \ - 'batchNum': 100, \ - 'startTs': 1640966400000} # 2022-01-01 00:00:00.000 - parameterDict['cfg'] = cfgPath - - self.create_database(tdSql, parameterDict["dbName"]) - self.create_stable(tdSql, parameterDict["dbName"], parameterDict["stbName"]) - self.create_ctables(tdSql, parameterDict["dbName"], parameterDict["stbName"], parameterDict["ctbNum"]) - self.insert_data(tdSql,parameterDict["dbName"],parameterDict["stbName"],parameterDict["ctbNum"],parameterDict["rowsPerTbl"],parameterDict["batchNum"]) + tmqCom.initConsumerTable() + + #self.initConsumerTable() + + # create and start thread + paraDict = {'dbName': 'dbt', + 'dropFlag': 1, + 'event': '', + 'vgroups': 4, + 'stbName': 'stb', + 'colPrefix': 'c', + 'tagPrefix': 't', + 'colSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1},{'type': 'TIMESTAMP', 'count':1}], + 'tagSchema': [{'type': 'INT', 'count':1},{'type': 'BIGINT', 'count':1},{'type': 'DOUBLE', 'count':1},{'type': 'BINARY', 'len':32, 'count':1},{'type': 'NCHAR', 'len':32, 'count':1}], + 'ctbPrefix': 'ctb', + 'ctbStartIdx': 0, + 'ctbNum': 10, + 'rowsPerTbl': 20000, + 'batchNum': 1000, + 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 + 'pollDelay': 30, + 'showMsg': 1, + 'showRow': 1, + 'snapshot': 0} + paraDict['cfg'] = cfgPath + + self.create_database(tdSql, paraDict["dbName"]) + self.create_stable(tdSql, paraDict["dbName"], paraDict["stbName"]) + self.create_ctables(tdSql, paraDict["dbName"], paraDict["stbName"], paraDict["ctbNum"]) + self.insert_data(tdSql,paraDict["dbName"],paraDict["stbName"],paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"]) tdLog.info("create topics from stb1") topicFromStb1 = 'topic_stb1' - tdSql.execute("create topic %s as select ts, c1, c2 from %s.%s" %(topicFromStb1, parameterDict['dbName'], parameterDict['stbName'])) + tdSql.execute("create topic %s as select ts, c1, c2 from %s.%s" %(topicFromStb1, paraDict['dbName'], paraDict['stbName'])) consumerId = 0 # expectrowcnt = parameterDict["rowsPerTbl"] * parameterDict["ctbNum"] expectrowcnt = 90000000000 @@ -229,41 +241,45 @@ class TDTestCase: enable.auto.commit:false,\ auto.commit.interval.ms:6000,\ auto.offset.reset:earliest' - self.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + #self.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) tdLog.info("start consume processor") - pollDelay = 9000000 # Forever loop + paraDict['pollDelay'] = 9000000 # Forever loop showMsg = 1 showRow = 1 - self.startTmqSimProcess(buildPath,cfgPath,pollDelay,parameterDict["dbName"],showMsg, showRow) + #self.startTmqSimProcess(buildPath,cfgPath,pollDelay,parameterDict["dbName"],showMsg, showRow) + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) - time.sleep(3) + #time.sleep(3) + tmqCom.getStartConsumeNotifyFromTmqsim() tdLog.info("================= stop dnode, and remove data file, then start dnode ===========================") tdDnodes.stop(1) - # time.sleep(5) + time.sleep(5) dataPath = buildPath + "/../sim/dnode1/data/*" shellCmd = 'rm -rf ' + dataPath tdLog.info(shellCmd) os.system(shellCmd) #tdDnodes.start(1) tdDnodes.starttaosd(1) - time.sleep(2) + time.sleep(5) ######### redo to consume self.initConsumerTable() - self.create_database(tdSql, parameterDict["dbName"]) - self.create_stable(tdSql, parameterDict["dbName"], parameterDict["stbName"]) - self.create_ctables(tdSql, parameterDict["dbName"], parameterDict["stbName"], parameterDict["ctbNum"]) - self.insert_data(tdSql,parameterDict["dbName"],parameterDict["stbName"],parameterDict["ctbNum"],parameterDict["rowsPerTbl"],parameterDict["batchNum"]) + self.create_database(tdSql, paraDict["dbName"]) + self.create_stable(tdSql, paraDict["dbName"], paraDict["stbName"]) + self.create_ctables(tdSql, paraDict["dbName"], paraDict["stbName"], paraDict["ctbNum"]) + self.insert_data(tdSql,paraDict["dbName"],paraDict["stbName"],paraDict["ctbNum"],paraDict["rowsPerTbl"],paraDict["batchNum"]) tdLog.info("create topics from stb1") topicFromStb1 = 'topic_stb1' - tdSql.execute("create topic %s as select ts, c1, c2 from %s.%s" %(topicFromStb1, parameterDict['dbName'], parameterDict['stbName'])) + tdSql.execute("create topic %s as select ts, c1, c2 from %s.%s" %(topicFromStb1, paraDict['dbName'], paraDict['stbName'])) consumerId = 0 - expectrowcnt = parameterDict["rowsPerTbl"] * parameterDict["ctbNum"] + expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] topicList = topicFromStb1 ifcheckdata = 0 ifManualCommit = 0 @@ -271,13 +287,17 @@ class TDTestCase: enable.auto.commit:false,\ auto.commit.interval.ms:6000,\ auto.offset.reset:earliest' - self.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + #self.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) + tmqCom.insertConsumerInfo(consumerId, expectrowcnt,topicList,keyList,ifcheckdata,ifManualCommit) tdLog.info("start consume processor") pollDelay = 20 showMsg = 1 showRow = 1 - self.startTmqSimProcess(buildPath,cfgPath,pollDelay,parameterDict["dbName"],showMsg, showRow) + paraDict['pollDelay'] = 20 + #self.startTmqSimProcess(buildPath,cfgPath,pollDelay,paraDict["dbName"],showMsg, showRow) + tdLog.info("start consume processor") + tmqCom.startTmqSimProcess(pollDelay=paraDict['pollDelay'],dbName=paraDict["dbName"],showMsg=paraDict['showMsg'], showRow=paraDict['showRow'],snapshot=paraDict['snapshot']) expectRows = 1 resultList = self.selectConsumeResult(expectRows) diff --git a/tests/system-test/7-tmq/tmqModule.py b/tests/system-test/7-tmq/tmqModule.py index 1ff47da15922c1ebc51c9ee72a2e155eaac81d4f..d6b4aff9380bb8f5337ce4b52088e105449a1d07 100644 --- a/tests/system-test/7-tmq/tmqModule.py +++ b/tests/system-test/7-tmq/tmqModule.py @@ -27,7 +27,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/tmqShow.py b/tests/system-test/7-tmq/tmqShow.py index 0691da678668df5a35b61691daebbf58b76b14d2..406fd9f7f37f4d663cfba5b61ab6d63f57d7421f 100644 --- a/tests/system-test/7-tmq/tmqShow.py +++ b/tests/system-test/7-tmq/tmqShow.py @@ -15,7 +15,8 @@ sys.path.append("./7-tmq") from tmqCommon import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file @@ -41,7 +42,7 @@ class TDTestCase: 'rowsPerTbl': 4000, 'batchNum': 15, 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 - 'pollDelay': 20, + 'pollDelay': 30, 'showMsg': 1, 'showRow': 1} @@ -124,7 +125,7 @@ class TDTestCase: tdLog.info("async insert data") pThread = tmqCom.asyncInsertData(paraDict) - tmqCom.getStartConsumeNotifyFromTmqsim(); + tmqCom.getStartConsumeNotifyFromTmqsim() #time.sleep(5) tdLog.info("check show consumers") tdSql.query("show consumers") @@ -138,8 +139,9 @@ class TDTestCase: tdSql.query("show subscriptions") # tdLog.debug(tdSql.queryResult) rows = tdSql.getRows() - tdLog.info("show subscriptions rows: %d"%rows) - if rows != paraDict['vgroups'] * len(topicNameList): + expectSubscriptions = paraDict['vgroups'] * len(topicNameList) + tdLog.info("show subscriptions rows: %d, expect Subscriptions: %d"%(rows,expectSubscriptions)) + if rows != expectSubscriptions: tdLog.exit("show subscriptions rows error") pThread.join() diff --git a/tests/system-test/7-tmq/tmqSubscribeStb-r3.py b/tests/system-test/7-tmq/tmqSubscribeStb-r3.py index c5f98bc3a004e8aa20918fe1482e38ef10705416..01f1ca5b15637e0daab772b5f5c9595bb9c0458c 100644 --- a/tests/system-test/7-tmq/tmqSubscribeStb-r3.py +++ b/tests/system-test/7-tmq/tmqSubscribeStb-r3.py @@ -16,8 +16,11 @@ from util.dnodes import TDDnodes from util.dnodes import TDDnode from util.cluster import * from util.common import * +sys.path.append("./6-cluster") sys.path.append("./7-tmq") from tmqCommon import * +from clusterCommonCreate import * +from clusterCommonCheck import clusterComCheck class TDTestCase: def __init__(self): @@ -26,8 +29,10 @@ class TDTestCase: self.vgroups = 4 self.ctbNum = 1000 self.rowsPerTbl = 100 + self.dnodeNumbers = 5 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file @@ -100,7 +105,7 @@ class TDTestCase: # tmqCom.insert_data_with_autoCreateTbl(tsql=tdSql,dbName=paraDict["dbName"],stbName=paraDict["stbName"],ctbPrefix="ctbx", # ctbNum=paraDict["ctbNum"],rowsPerTbl=paraDict["rowsPerTbl"],batchNum=paraDict["batchNum"], # startTs=paraDict["startTs"],ctbStartIdx=paraDict['ctbStartIdx']) - tmqCom.asyncInsertDataByInterlace(paraDict) + pThread = tmqCom.asyncInsertDataByInterlace(paraDict) tdLog.info("wait some data inserted") exitFlag = 1 @@ -118,16 +123,21 @@ class TDTestCase: tdLog.info("================= restart dnode 2===========================") cluster.dnodes[1].stoptaosd() cluster.dnodes[1].starttaosd() + clusterComCheck.checkDnodes(self.dnodeNumbers) tdLog.info("================= restart dnode 3===========================") cluster.dnodes[2].stoptaosd() cluster.dnodes[2].starttaosd() + clusterComCheck.checkDnodes(self.dnodeNumbers) tdLog.info("================= restart dnode 4===========================") cluster.dnodes[3].stoptaosd() cluster.dnodes[3].starttaosd() + clusterComCheck.checkDnodes(self.dnodeNumbers) tdLog.info("================= restart dnode 5===========================") cluster.dnodes[4].stoptaosd() cluster.dnodes[4].starttaosd() + clusterComCheck.checkDnodes(self.dnodeNumbers) + pThread.join() # tdLog.info("restart taosd to ensure that the data falls into the disk") # tdSql.query("flush database %s"%(paraDict['dbName'])) return @@ -191,9 +201,9 @@ class TDTestCase: tdSql.query(queryString) totalRowsFromQuery = tdSql.getRows() - tdLog.info("act consume rows: %d, act query rows: %d, expect consume rows: %d, "%(totalConsumeRows, totalRowsFromQuery, expectrowcnt)) + tdLog.info("act consume rows: %d, act query rows: %d "%(totalConsumeRows, totalRowsFromQuery)) - if totalConsumeRows != totalRowsFromQuery: + if totalConsumeRows < totalRowsFromQuery: tdLog.exit("tmq consume rows error!") # tmqCom.checkFileContent(consumerId, queryString) @@ -222,7 +232,7 @@ class TDTestCase: 'rowsPerTbl': 1000, 'batchNum': 100, 'startTs': 1640966400000, # 2022-01-01 00:00:00.000 - 'pollDelay': 15, + 'pollDelay': 30, 'showMsg': 1, 'showRow': 1, 'snapshot': 1} @@ -236,7 +246,10 @@ class TDTestCase: queryString = "select ts, c1, c2 from %s.%s where t4 == 'beijing' or t4 == 'changsha' "%(paraDict['dbName'], paraDict['stbName']) sqlString = "create topic %s as %s" %(topicFromStb1, queryString) tdLog.info("create topic sql: %s"%sqlString) - tdSql.execute(sqlString) + tdSql.execute(sqlString) + + tdSql.query(queryString) + totalRowsFromQuery = tdSql.getRows() consumerId = 0 expectrowcnt = paraDict["rowsPerTbl"] * paraDict["ctbNum"] @@ -255,15 +268,19 @@ class TDTestCase: tdLog.info("================= restart dnode 2===========================") cluster.dnodes[1].stoptaosd() cluster.dnodes[1].starttaosd() + clusterComCheck.checkDnodes(self.dnodeNumbers) tdLog.info("================= restart dnode 3===========================") cluster.dnodes[2].stoptaosd() cluster.dnodes[2].starttaosd() + clusterComCheck.checkDnodes(self.dnodeNumbers) tdLog.info("================= restart dnode 4===========================") cluster.dnodes[3].stoptaosd() cluster.dnodes[3].starttaosd() + clusterComCheck.checkDnodes(self.dnodeNumbers) tdLog.info("================= restart dnode 5===========================") cluster.dnodes[4].stoptaosd() cluster.dnodes[4].starttaosd() + clusterComCheck.checkDnodes(self.dnodeNumbers) tdLog.info("start to check consume result") expectRows = 1 @@ -272,12 +289,9 @@ class TDTestCase: for i in range(expectRows): totalConsumeRows += resultList[i] - tdSql.query(queryString) - totalRowsFromQuery = tdSql.getRows() - - tdLog.info("act consume rows: %d, act query rows: %d, expect consume rows: %d, "%(totalConsumeRows, totalRowsFromQuery, expectrowcnt)) + tdLog.info("act consume rows: %d, act query rows: %d "%(totalConsumeRows, totalRowsFromQuery)) - if totalConsumeRows != totalRowsFromQuery: + if totalConsumeRows < totalRowsFromQuery: tdLog.exit("tmq consume rows error!") # tmqCom.checkFileContent(consumerId, queryString) @@ -288,8 +302,9 @@ class TDTestCase: tdLog.printNoPrefix("======== test case 2 end ...... ") def run(self): + #self.prepareTestEnv() + #self.tmqCase1() self.prepareTestEnv() - self.tmqCase1() self.tmqCase2() def stop(self): diff --git a/tests/system-test/7-tmq/tmqUdf-multCtb-snapshot0.py b/tests/system-test/7-tmq/tmqUdf-multCtb-snapshot0.py index f70c6ad49bc259185231caecc04c05160b816f4c..297429b495b4bbc42e6d53a58295ef306b5d6903 100644 --- a/tests/system-test/7-tmq/tmqUdf-multCtb-snapshot0.py +++ b/tests/system-test/7-tmq/tmqUdf-multCtb-snapshot0.py @@ -23,7 +23,8 @@ class TDTestCase: self.ctbNum = 100 self.rowsPerTbl = 1000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/tmqUdf-multCtb-snapshot1.py b/tests/system-test/7-tmq/tmqUdf-multCtb-snapshot1.py index 58cdc775eed67e7db14e56f255e292f2d67e5948..9c139b50de71902d743236c503d6cca12cb8296a 100644 --- a/tests/system-test/7-tmq/tmqUdf-multCtb-snapshot1.py +++ b/tests/system-test/7-tmq/tmqUdf-multCtb-snapshot1.py @@ -23,7 +23,8 @@ class TDTestCase: self.ctbNum = 100 self.rowsPerTbl = 1000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/tmqUdf.py b/tests/system-test/7-tmq/tmqUdf.py index 5eac0ae69d643045777a2976de39d6b54d2e1cee..8593fd4f1e5969d9eb8083a66200301a6524d8c1 100644 --- a/tests/system-test/7-tmq/tmqUdf.py +++ b/tests/system-test/7-tmq/tmqUdf.py @@ -23,7 +23,8 @@ class TDTestCase: self.ctbNum = 1 self.rowsPerTbl = 1000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/7-tmq/tmqUpdate-1ctb.py b/tests/system-test/7-tmq/tmqUpdate-1ctb.py index 12de04cd9c525e4ae8bc9aaa70d45942e7c3c0e2..b974e4a41a2c60d4c882b2006400f500ec799efc 100644 --- a/tests/system-test/7-tmq/tmqUpdate-1ctb.py +++ b/tests/system-test/7-tmq/tmqUpdate-1ctb.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 1 self.rowsPerTbl = 10000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqUpdate-multiCtb-snapshot0.py b/tests/system-test/7-tmq/tmqUpdate-multiCtb-snapshot0.py index 02641d8bcb0603c7e2caf3e2486a577e62176269..d5df88cf43b1e207f3856807bb9b0bcf55b4b8c6 100644 --- a/tests/system-test/7-tmq/tmqUpdate-multiCtb-snapshot0.py +++ b/tests/system-test/7-tmq/tmqUpdate-multiCtb-snapshot0.py @@ -22,7 +22,8 @@ class TDTestCase: self.rowsPerTbl = 1000 self.autoCtbPrefix = 'aCtb' - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqUpdate-multiCtb-snapshot1.py b/tests/system-test/7-tmq/tmqUpdate-multiCtb-snapshot1.py index baeb70e65680aa731d9db4eb28385b24e67d9a47..6b8c10de271b28726639baad8648e2586c02f9a1 100644 --- a/tests/system-test/7-tmq/tmqUpdate-multiCtb-snapshot1.py +++ b/tests/system-test/7-tmq/tmqUpdate-multiCtb-snapshot1.py @@ -22,7 +22,8 @@ class TDTestCase: self.rowsPerTbl = 1000 self.autoCtbPrefix = 'aCtb' - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqUpdate-multiCtb.py b/tests/system-test/7-tmq/tmqUpdate-multiCtb.py index bde266e63401f27e1ff9bfb1085fc26636e0bc77..3975013e747f09d8cc0548b5e32f9f01c63fb9a4 100644 --- a/tests/system-test/7-tmq/tmqUpdate-multiCtb.py +++ b/tests/system-test/7-tmq/tmqUpdate-multiCtb.py @@ -22,7 +22,8 @@ class TDTestCase: self.rowsPerTbl = 1000 self.autoCtbPrefix = 'aCtb' - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmqUpdateWithConsume.py b/tests/system-test/7-tmq/tmqUpdateWithConsume.py index be07ba13a978a8705f014b04ee7c09ba37e3a33b..49a475ff16db96534c13107e94f5d42c8f10454c 100644 --- a/tests/system-test/7-tmq/tmqUpdateWithConsume.py +++ b/tests/system-test/7-tmq/tmqUpdateWithConsume.py @@ -21,7 +21,8 @@ class TDTestCase: self.ctbNum = 100 self.rowsPerTbl = 1000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/7-tmq/tmq_taosx.py b/tests/system-test/7-tmq/tmq_taosx.py index 626e935733a19b47a9524c474614ac816ef38bbe..f2fbd8486570e385332be5280f58f25af7ae4d75 100644 --- a/tests/system-test/7-tmq/tmq_taosx.py +++ b/tests/system-test/7-tmq/tmq_taosx.py @@ -15,7 +15,8 @@ sys.path.append("./7-tmq") from tmqCommon import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/99-TDcase/TD-15517.py b/tests/system-test/99-TDcase/TD-15517.py index fe2d9b9041f8a5b43f5a56189799e63105c9c809..db06700284d6de78139aef2f2678e2eb75d379fd 100644 --- a/tests/system-test/99-TDcase/TD-15517.py +++ b/tests/system-test/99-TDcase/TD-15517.py @@ -20,7 +20,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") #tdSql.init(conn.cursor()) tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/99-TDcase/TD-15554.py b/tests/system-test/99-TDcase/TD-15554.py index 16a34086b7854da1126c4e5dfe30cf49d3c180f1..51934ccd4408cc002060049f8c32fb6706a41fd3 100644 --- a/tests/system-test/99-TDcase/TD-15554.py +++ b/tests/system-test/99-TDcase/TD-15554.py @@ -19,7 +19,8 @@ class TDTestCase: #updatecfgDict["clientCfg"] = clientCfgDict #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") #tdSql.init(conn.cursor()) tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/99-TDcase/TD-15557.py b/tests/system-test/99-TDcase/TD-15557.py index 243a0a4d7e25f64ec0840127e9321d06527bcd17..884c028a6567d62ce5141eb5ad16240830168f51 100644 --- a/tests/system-test/99-TDcase/TD-15557.py +++ b/tests/system-test/99-TDcase/TD-15557.py @@ -20,7 +20,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") #tdSql.init(conn.cursor()) tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/99-TDcase/TD-15563.py b/tests/system-test/99-TDcase/TD-15563.py index 74b5472d89f70acf0ccf7bb0e0d0bb3bab0b253d..5ea652b4fb6fe5b441ea4a946026115431ec24b2 100644 --- a/tests/system-test/99-TDcase/TD-15563.py +++ b/tests/system-test/99-TDcase/TD-15563.py @@ -20,7 +20,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") #tdSql.init(conn.cursor()) tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/99-TDcase/TD-16025.py b/tests/system-test/99-TDcase/TD-16025.py index 4cf94f5dafa2145bf2ce761e508c38c521321114..8c9fa9319f8071db436e4f71a597dc7d5de8758e 100644 --- a/tests/system-test/99-TDcase/TD-16025.py +++ b/tests/system-test/99-TDcase/TD-16025.py @@ -27,7 +27,8 @@ class TDTestCase: #updatecfgDict["rpcDebugFlag"] = rpcDebugFlagVal #print ("===================: ", updatecfgDict) - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") #tdSql.init(conn.cursor()) tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/99-TDcase/TD-16821.py b/tests/system-test/99-TDcase/TD-16821.py index 31c1c34485daa75b469d2278f4b9b7dce3523fdd..f57fae752f8d2d07f730f791ce0b5a63eb7dc832 100644 --- a/tests/system-test/99-TDcase/TD-16821.py +++ b/tests/system-test/99-TDcase/TD-16821.py @@ -15,7 +15,8 @@ sys.path.append("./7-tmq") from tmqCommon import * class TDTestCase: - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor()) #tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/99-TDcase/TD-17255.py b/tests/system-test/99-TDcase/TD-17255.py index 5d18fee8d2cadd955ed7f5a38026b02b4fc16994..0f83468754783ee5adca78113c7a8df5c78bbe99 100644 --- a/tests/system-test/99-TDcase/TD-17255.py +++ b/tests/system-test/99-TDcase/TD-17255.py @@ -20,7 +20,8 @@ class TDTestCase: self.ctbNum = 100 self.rowsPerTbl = 10000 - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") tdSql.init(conn.cursor(), False) diff --git a/tests/system-test/99-TDcase/TD-17699.py b/tests/system-test/99-TDcase/TD-17699.py index 40650e4b924c52319241aaee1b9f20c43f60cf4f..2862f4a78d5391098f0493afa35e482c5a032817 100644 --- a/tests/system-test/99-TDcase/TD-17699.py +++ b/tests/system-test/99-TDcase/TD-17699.py @@ -52,7 +52,8 @@ class TDTestCase: hostname = socket.gethostname() - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") logSql = False tdSql.init(conn.cursor(), logSql) diff --git a/tests/system-test/99-TDcase/TD-19201.py b/tests/system-test/99-TDcase/TD-19201.py index 26caa27815e427364e9275502bf062236e6fca38..2a25d1ad7ec6bbe4eabbcb283ecdf6705eeb4fb6 100644 --- a/tests/system-test/99-TDcase/TD-19201.py +++ b/tests/system-test/99-TDcase/TD-19201.py @@ -13,7 +13,8 @@ from util.dnodes import * class TDTestCase: hostname = socket.gethostname() - def init(self, conn, logSql): + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) tdLog.debug(f"start to excute {__file__}") #tdSql.init(conn.cursor()) tdSql.init(conn.cursor(), logSql) # output sql.txt file diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh old mode 100644 new mode 100755 index bf91d27b46aa1ec370d42c5d3c00bdfcafbf58da..0729d36f12fbf504de6da858b8b0a3aba7a33bb6 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -17,7 +17,7 @@ python3 ./test.py -f 0-others/taosdShell.py -N 5 -M 3 -Q 3 python3 ./test.py -f 0-others/sysinfo.py python3 ./test.py -f 0-others/user_control.py python3 ./test.py -f 0-others/fsync.py -python3 ./test.py -f 0-others/compatibility.py +python3 ./test.py -f 0-others/compatibility.py python3 ./test.py -f 1-insert/alter_database.py python3 ./test.py -f 1-insert/influxdb_line_taosc_insert.py python3 ./test.py -f 1-insert/opentsdb_telnet_line_taosc_insert.py @@ -76,6 +76,8 @@ python3 ./test.py -f 2-query/count_partition.py python3 ./test.py -f 2-query/count_partition.py -R python3 ./test.py -f 2-query/count.py python3 ./test.py -f 2-query/count.py -R +python3 ./test.py -f 2-query/countAlwaysReturnValue.py +python3 ./test.py -f 2-query/countAlwaysReturnValue.py -R python3 ./test.py -f 2-query/db.py python3 ./test.py -f 2-query/db.py -R python3 ./test.py -f 2-query/diff.py @@ -140,6 +142,8 @@ python3 ./test.py -f 2-query/max.py python3 ./test.py -f 2-query/max.py -R python3 ./test.py -f 2-query/min.py python3 ./test.py -f 2-query/min.py -R +python3 ./test.py -f 2-query/mode.py +python3 ./test.py -f 2-query/mode.py -R python3 ./test.py -f 2-query/Now.py python3 ./test.py -f 2-query/Now.py -R python3 ./test.py -f 2-query/percentile.py @@ -209,7 +213,10 @@ python3 ./test.py -f 2-query/varchar.py -R python3 ./test.py -f 1-insert/update_data.py python3 ./test.py -f 1-insert/tb_100w_data_order.py -python3 ./test.py -f 1-insert/delete_data.py +# TD-20200 python3 ./test.py -f 1-insert/delete_data.py +python3 ./test.py -f 1-insert/delete_stable.py +python3 ./test.py -f 1-insert/delete_childtable.py +python3 ./test.py -f 1-insert/delete_normaltable.py python3 ./test.py -f 1-insert/keep_expired.py python3 ./test.py -f 2-query/join2.py @@ -232,27 +239,37 @@ python3 ./test.py -f 2-query/function_diff.py python3 ./test.py -f 2-query/queryQnode.py python3 ./test.py -f 6-cluster/5dnode1mnode.py -python3 ./test.py -f 6-cluster/5dnode2mnode.py -N 5 -M 3 +python3 ./test.py -f 6-cluster/5dnode2mnode.py -N 5 python3 ./test.py -f 6-cluster/5dnode3mnodeStop.py -N 5 -M 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeStop.py -N 5 -M 3 -i False python3 ./test.py -f 6-cluster/5dnode3mnodeStop2Follower.py -N 5 -M 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeStop2Follower.py -N 5 -M 3 -i False python3 ./test.py -f 6-cluster/5dnode3mnodeStopLoop.py -N 5 -M 3 -python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateDb.py -N 5 -M 3 -python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateDb.py -N 5 -M 3 -python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateDb.py -N 5 -M 3 -python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateDbRep3.py -N 5 -M 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateDb.py -N 6 -M 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateDb.py -N 6 -M 3 -n 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateDb.py -N 6 -M 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateDb.py -N 6 -M 3 -n 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateDb.py -N 6 -M 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateDb.py -N 6 -M 3 -n 3 -python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateStb.py -N 5 -M 3 -python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateStb.py -N 5 -M 3 -python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateStb.py -N 5 -M 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateStb.py -N 6 -M 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopDnodeCreateStb.py -N 6 -M 3 -n 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateStb.py -N 6 -M 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopMnodeCreateStb.py -N 6 -M 3 -n 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateStb.py -N 6 -M 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeSep1VnodeStopVnodeCreateStb.py -N 6 -M 3 -n 3 -python3 ./test.py -f 6-cluster/5dnode3mnodeRestartDnodeInsertData.py -N 5 -M 3 -python3 ./test.py -f 6-cluster/5dnode3mnodeRestartDnodeInsertDataAsync.py -N 5 -M 3 -# python3 ./test.py -f 6-cluster/5dnode3mnodeRestartMnodeInsertData.py -N 5 -M 3 -# python3 ./test.py -f 6-cluster/5dnode3mnodeRestartVnodeInsertData.py -N 5 -M 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeRestartDnodeInsertData.py -N 6 -M 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeRestartDnodeInsertData.py -N 6 -M 3 -n 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeRestartDnodeInsertDataAsync.py -N 6 -M 3 +python3 ./test.py -f 6-cluster/5dnode3mnodeRestartDnodeInsertDataAsync.py -N 6 -M 3 -n 3 + + +python3 ./test.py -f 6-cluster/5dnode3mnodeAdd1Ddnoe.py -N 7 -M 3 -C 6 +python3 ./test.py -f 6-cluster/5dnode3mnodeAdd1Ddnoe.py -N 7 -M 3 -C 6 -n 3 -python3 ./test.py -f 6-cluster/5dnode3mnodeAdd1Ddnoe.py -N 6 -M 3 -C 5 # BUG python3 ./test.py -f 6-cluster/5dnode3mnodeStopInsert.py -# TD-19646 python3 ./test.py -f 6-cluster/5dnode3mnodeDrop.py -N 5 +python3 ./test.py -f 6-cluster/5dnode3mnodeDrop.py -N 5 # TD-19646 python3 test.py -f 6-cluster/5dnode3mnodeStopConnect.py -N 5 -M 3 python3 ./test.py -f 6-cluster/5dnode3mnodeRecreateMnode.py -N 5 -M 3 @@ -263,28 +280,25 @@ python3 ./test.py -f 6-cluster/5dnode3mnodeStop2Follower.py -N 5 -M 3 python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_createDb_replica1.py -N 4 -M 1 python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica1_insertdatas.py -N 4 -M 1 python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica1_insertdatas_querys.py -N 4 -M 1 -python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_force_stop_all_dnodes.py -N 4 -M 1 +# python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_force_stop_all_dnodes.py -N 4 -M 1 python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas.py -N 4 -M 1 -python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys_loop_restart_all_vnode.py -N 4 -M 1 -python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys_loop_restart_follower.py -N 4 -M 1 -python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys_loop_restart_leader.py -N 4 -M 1 +# python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys_loop_restart_all_vnode.py -N 4 -M 1 +# python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys_loop_restart_follower.py -N 4 -M 1 +# python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys_loop_restart_leader.py -N 4 -M 1 python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_querys.py -N 4 -M 1 -python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_all_dnodes.py -N 4 -M 1 - - -python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_follower_sync.py -N 4 -M 1 +# python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_all_dnodes.py -N 4 -M 1 +# python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_follower_sync.py -N 4 -M 1 # python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_follower_unsync_force_stop.py -N 4 -M 1 # python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_follower_unsync.py -N 4 -M 1 -python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_leader_forece_stop.py -N 4 -M 1 +# python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_leader_forece_stop.py -N 4 -M 1 # python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_insertdatas_stop_leader.py -N 4 -M 1 # python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_mnode3_insertdatas_querys.py -N 4 -M 1 -python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_follower_force_stop.py -N 4 -M 1 -python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_follower.py -N 4 -M 1 +# python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_follower_force_stop.py -N 4 -M 1 +# python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_follower.py -N 4 -M 1 # python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_leader_force_stop.py -N 4 -M 1 -python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_leader.py -N 4 -M 1 +# python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_querydatas_stop_leader.py -N 4 -M 1 python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_vgroups.py -N 4 -M 1 -python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_vgroups_stopOne.py -N 4 -M 1 - +# python3 test.py -f 6-cluster/vnode/4dnode1mnode_basic_replica3_vgroups_stopOne.py -N 4 -M 1 python3 ./test.py -f 7-tmq/create_wrong_topic.py python3 ./test.py -f 7-tmq/dropDbR3ConflictTransaction.py -N 3 @@ -377,7 +391,9 @@ python3 ./test.py -f 2-query/Now.py -Q 2 python3 ./test.py -f 2-query/Today.py -Q 2 python3 ./test.py -f 2-query/max.py -Q 2 python3 ./test.py -f 2-query/min.py -Q 2 +python3 ./test.py -f 2-query/mode.py -Q 2 python3 ./test.py -f 2-query/count.py -Q 2 +python3 ./test.py -f 2-query/countAlwaysReturnValue.py -Q 2 python3 ./test.py -f 2-query/last.py -Q 2 python3 ./test.py -f 2-query/first.py -Q 2 python3 ./test.py -f 2-query/To_iso8601.py -Q 2 @@ -472,7 +488,9 @@ python3 ./test.py -f 2-query/Now.py -Q 3 python3 ./test.py -f 2-query/Today.py -Q 3 python3 ./test.py -f 2-query/max.py -Q 3 python3 ./test.py -f 2-query/min.py -Q 3 +python3 ./test.py -f 2-query/mode.py -Q 3 python3 ./test.py -f 2-query/count.py -Q 3 +python3 ./test.py -f 2-query/countAlwaysReturnValue.py -Q 3 python3 ./test.py -f 2-query/last.py -Q 3 python3 ./test.py -f 2-query/first.py -Q 3 python3 ./test.py -f 2-query/To_iso8601.py -Q 3 @@ -551,7 +569,7 @@ python3 ./test.py -f 2-query/upper.py -Q 4 python3 ./test.py -f 2-query/lower.py -Q 4 python3 ./test.py -f 2-query/join.py -Q 4 python3 ./test.py -f 2-query/join2.py -Q 4 -python3 ./test.py -f 2-query/cast.py -Q 4 +#python3 ./test.py -f 2-query/cast.py -Q 4 python3 ./test.py -f 2-query/substr.py -Q 4 python3 ./test.py -f 2-query/union.py -Q 4 python3 ./test.py -f 2-query/union1.py -Q 4 @@ -569,7 +587,9 @@ python3 ./test.py -f 2-query/Now.py -Q 4 python3 ./test.py -f 2-query/Today.py -Q 4 python3 ./test.py -f 2-query/max.py -Q 4 python3 ./test.py -f 2-query/min.py -Q 4 +python3 ./test.py -f 2-query/mode.py -Q 4 python3 ./test.py -f 2-query/count.py -Q 4 +python3 ./test.py -f 2-query/countAlwaysReturnValue.py -Q 4 python3 ./test.py -f 2-query/last.py -Q 4 python3 ./test.py -f 2-query/first.py -Q 4 python3 ./test.py -f 2-query/To_iso8601.py -Q 4 @@ -585,7 +605,7 @@ python3 ./test.py -f 2-query/apercentile.py -Q 4 python3 ./test.py -f 2-query/abs.py -Q 4 python3 ./test.py -f 2-query/ceil.py -Q 4 python3 ./test.py -f 2-query/floor.py -Q 4 -python3 ./test.py -f 2-query/round.py -Q 4 +python3 ./test.py -f 2-query/round.py -Q 4 python3 ./test.py -f 2-query/log.py -Q 4 python3 ./test.py -f 2-query/pow.py -Q 4 python3 ./test.py -f 2-query/sqrt.py -Q 4 diff --git a/tests/system-test/test.py b/tests/system-test/test.py index dd49f037bd9bc75f5db41c3a9c6a560a59910587..e171baa6563d82a9767236e10b1cc2abf98977d7 100644 --- a/tests/system-test/test.py +++ b/tests/system-test/test.py @@ -72,8 +72,10 @@ if __name__ == "__main__": queryPolicy = 1 createDnodeNums = 1 restful = False - opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghrd:k:e:N:M:Q:C:RD:', [ - 'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help', 'restart', 'updateCfgDict', 'killv', 'execCmd','dnodeNums','mnodeNums','queryPolicy','createDnodeNums','restful','adaptercfgupdate']) + replicaVar = 1 + independentMnode = True + opts, args = getopt.gnu_getopt(sys.argv[1:], 'f:p:m:l:scghrd:k:e:N:M:Q:C:RD:n:i:', [ + 'file=', 'path=', 'master', 'logSql', 'stop', 'cluster', 'valgrind', 'help', 'restart', 'updateCfgDict', 'killv', 'execCmd','dnodeNums','mnodeNums','queryPolicy','createDnodeNums','restful','adaptercfgupdate','replicaVar','independentMnode']) for key, value in opts: if key in ['-h', '--help']: tdLog.printNoPrefix( @@ -95,7 +97,8 @@ if __name__ == "__main__": tdLog.printNoPrefix('-C create Dnode Numbers in one cluster') tdLog.printNoPrefix('-R restful realization form') tdLog.printNoPrefix('-D taosadapter update cfg dict ') - + tdLog.printNoPrefix('-n the number of replicas') + tdLog.printNoPrefix('-i independentMnode Mnode') sys.exit(0) @@ -158,6 +161,9 @@ if __name__ == "__main__": if key in ['-C', '--createDnodeNums']: createDnodeNums = value + if key in ['-i', '--independentMnode']: + independentMnode = value + if key in ['-R', '--restful']: restful = True @@ -168,6 +174,9 @@ if __name__ == "__main__": print('adapter cfg update convert fail.') sys.exit(0) + if key in ['-n', '--replicaVar']: + replicaVar = value + if not execCmd == "": if restful: tAdapter.init(deployPath) @@ -310,7 +319,7 @@ if __name__ == "__main__": tdLog.exit(f"alter queryPolicy to {queryPolicy} failed") else : tdLog.debug("create an cluster with %s nodes and make %s dnode as independent mnode"%(dnodeNums,mnodeNums)) - dnodeslist = cluster.configure_cluster(dnodeNums=dnodeNums,mnodeNums=mnodeNums) + dnodeslist = cluster.configure_cluster(dnodeNums=dnodeNums, mnodeNums=mnodeNums, independentMnode=independentMnode) tdDnodes = ClusterDnodes(dnodeslist) tdDnodes.init(deployPath, masterIp) tdDnodes.setTestCluster(testCluster) @@ -336,6 +345,7 @@ if __name__ == "__main__": else: createDnodeNums=createDnodeNums cluster.create_dnode(conn,createDnodeNums) + cluster.create_mnode(conn,mnodeNums) try: if cluster.check_dnode(conn) : print("check dnode ready") @@ -443,7 +453,7 @@ if __name__ == "__main__": else : tdLog.debug("create an cluster with %s nodes and make %s dnode as independent mnode"%(dnodeNums,mnodeNums)) - dnodeslist = cluster.configure_cluster(dnodeNums=dnodeNums,mnodeNums=mnodeNums) + dnodeslist = cluster.configure_cluster(dnodeNums=dnodeNums, mnodeNums=mnodeNums, independentMnode=independentMnode) tdDnodes = ClusterDnodes(dnodeslist) tdDnodes.init(deployPath, masterIp) tdDnodes.setTestCluster(testCluster) @@ -469,6 +479,8 @@ if __name__ == "__main__": else: createDnodeNums=createDnodeNums cluster.create_dnode(conn,createDnodeNums) + cluster.create_mnode(conn,mnodeNums) + try: if cluster.check_dnode(conn) : print("check dnode ready") @@ -512,7 +524,7 @@ if __name__ == "__main__": if fileName == "all": tdCases.runAllLinux(conn) else: - tdCases.runOneLinux(conn, fileName) + tdCases.runOneLinux(conn, fileName, replicaVar) if restart: if fileName == "all": @@ -529,7 +541,7 @@ if __name__ == "__main__": conn = taosrest.connect(url=f"http://{host}:6041") tdLog.info("Procedures for tdengine deployed in %s" % (host)) tdLog.info("query test after taosd restart") - tdCases.runOneLinux(conn, sp[0] + "_" + "restart.py") + tdCases.runOneLinux(conn, sp[0] + "_" + "restart.py", replicaVar) else: tdLog.info("not need to query") diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 214e83ae0005fd9b1f7d4a4676a06e3b252c5921..79be05e9fccc8344a6cd46735a0b1b4f97badeab 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -12,7 +12,7 @@ IF (TD_WEBSOCKET) ExternalProject_Add(taosws-rs PREFIX "taosws-rs" SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/taosws-rs - BUILD_ALWAYS on + BUILD_ALWAYS off DEPENDS taos BUILD_IN_SOURCE 1 CONFIGURE_COMMAND cmake -E echo "taosws-rs no need cmake to config" @@ -85,95 +85,53 @@ ELSE () COMMAND cd .. ) MESSAGE("CURRENT SOURCE DIR ${CMAKE_CURRENT_SOURCE_DIR}") - IF (TD_LINUX) - include(ExternalProject) - set(_upx_prefix "$ENV{HOME}/.taos/externals/upx") - ExternalProject_Add(upx - PREFIX "${_upx_prefix}" - URL https://github.com/upx/upx/releases/download/v3.96/upx-3.96-${PLATFORM_ARCH_STR}_linux.tar.xz - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - ) + IF (TD_WINDOWS) + INCLUDE(ExternalProject) ExternalProject_Add(taosadapter - PREFIX "taosadapter" - SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/taosadapter - BUILD_ALWAYS off - DEPENDS taos upx - BUILD_IN_SOURCE 1 - CONFIGURE_COMMAND cmake -E echo "taosadapter no need cmake to config" - PATCH_COMMAND - COMMAND git clean -f -d - BUILD_COMMAND - COMMAND CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../include/client CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib go build -a -ldflags "-s -w -X github.com/taosdata/taosadapter/v3/version.Version=${taos_version} -X github.com/taosdata/taosadapter/v3/version.CommitID=${taosadapter_commit_sha1}" - COMMAND CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../include/client CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib go build -a -o taosadapter-debug -ldflags "-X github.com/taosdata/taosadapter/v3/version.Version=${taos_version} -X github.com/taosdata/taosadapter/v3/version.CommitID=${taosadapter_commit_sha1}" - INSTALL_COMMAND - COMMAND ${_upx_prefix}/src/upx/upx taosadapter - COMMAND cmake -E copy taosadapter ${CMAKE_BINARY_DIR}/build/bin - COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/test/cfg/ - COMMAND cmake -E copy ./example/config/taosadapter.toml ${CMAKE_BINARY_DIR}/test/cfg/ - COMMAND cmake -E copy ./taosadapter.service ${CMAKE_BINARY_DIR}/test/cfg/ - COMMAND cmake -E copy taosadapter-debug ${CMAKE_BINARY_DIR}/build/bin - ) - unset(_upx_prefix) - ELSEIF (TD_DARWIN) - include(ExternalProject) - ExternalProject_Add(taosadapter - PREFIX "taosadapter" - SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/taosadapter - BUILD_ALWAYS off - DEPENDS taos - BUILD_IN_SOURCE 1 - CONFIGURE_COMMAND cmake -E echo "taosadapter no need cmake to config" - PATCH_COMMAND - COMMAND git clean -f -d - BUILD_COMMAND - COMMAND CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../include/client CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib go build -a -ldflags "-s -w -X github.com/taosdata/taosadapter/v3/version.Version=${taos_version} -X github.com/taosdata/taosadapter/v3/version.CommitID=${taosadapter_commit_sha1}" - COMMAND CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../include/client CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib go build -a -o taosadapter-debug -ldflags "-X github.com/taosdata/taosadapter/v3/version.Version=${taos_version} -X github.com/taosdata/taosadapter/v3/version.CommitID=${taosadapter_commit_sha1}" - INSTALL_COMMAND - COMMAND cmake -E copy taosadapter ${CMAKE_BINARY_DIR}/build/bin - COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/test/cfg/ - COMMAND cmake -E copy ./example/config/taosadapter.toml ${CMAKE_BINARY_DIR}/test/cfg/ - COMMAND cmake -E copy ./taosadapter.service ${CMAKE_BINARY_DIR}/test/cfg/ - COMMAND cmake -E copy taosadapter-debug ${CMAKE_BINARY_DIR}/build/bin - ) -# unset(_upx_prefix) - ELSEIF (TD_WINDOWS) - include(ExternalProject) - set(_upx_prefix "${CMAKE_BINARY_DIR}/.taos/externals/upx") - ExternalProject_Add(upx - PREFIX "${_upx_prefix}" - URL https://github.com/upx/upx/releases/download/v3.96/upx-3.96-win32.zip - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - ) + PREFIX "taosadapter" + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/taosadapter + BUILD_ALWAYS off + DEPENDS taos + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND cmake -E echo "taosadapter no need cmake to config" + PATCH_COMMAND + COMMAND git clean -f -d + BUILD_COMMAND + COMMAND set CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../include/client + COMMAND set CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib + COMMAND go build -a -o taosadapter.exe -ldflags "-s -w -X github.com/taosdata/taosadapter/v3/version.Version=${taos_version} -X github.com/taosdata/taosadapter/v3/version.CommitID=${taosadapter_commit_sha1}" + COMMAND go build -a -o taosadapter-debug.exe -ldflags "-X github.com/taosdata/taosadapter/v3/version.Version=${taos_version} -X github.com/taosdata/taosadapter/v3/version.CommitID=${taosadapter_commit_sha1}" + INSTALL_COMMAND + COMMAND cmake -E time upx taosadapter ||: + COMMAND cmake -E copy taosadapter.exe ${CMAKE_BINARY_DIR}/build/bin + COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/test/cfg/ + COMMAND cmake -E copy ./example/config/taosadapter.toml ${CMAKE_BINARY_DIR}/test/cfg/ + COMMAND cmake -E copy ./taosadapter.service ${CMAKE_BINARY_DIR}/test/cfg/ + COMMAND cmake -E copy taosadapter-debug.exe ${CMAKE_BINARY_DIR}/build/bin + ) + ELSE (TD_WINDOWS) + INCLUDE(ExternalProject) ExternalProject_Add(taosadapter - PREFIX "taosadapter" - SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/taosadapter - BUILD_ALWAYS off - DEPENDS taos - BUILD_IN_SOURCE 1 - CONFIGURE_COMMAND cmake -E echo "taosadapter no need cmake to config" - PATCH_COMMAND - COMMAND git clean -f -d - BUILD_COMMAND - COMMAND set CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../include/client - COMMAND set CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib - COMMAND go build -a -o taosadapter.exe -ldflags "-s -w -X github.com/taosdata/taosadapter/v3/version.Version=${taos_version} -X github.com/taosdata/taosadapter/v3/version.CommitID=${taosadapter_commit_sha1}" - COMMAND go build -a -o taosadapter-debug.exe -ldflags "-X github.com/taosdata/taosadapter/v3/version.Version=${taos_version} -X github.com/taosdata/taosadapter/v3/version.CommitID=${taosadapter_commit_sha1}" - INSTALL_COMMAND - COMMAND ${_upx_prefix}/src/upx/upx taosadapter.exe - COMMAND cmake -E copy taosadapter.exe ${CMAKE_BINARY_DIR}/build/bin - COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/test/cfg/ - COMMAND cmake -E copy ./example/config/taosadapter.toml ${CMAKE_BINARY_DIR}/test/cfg/ - COMMAND cmake -E copy ./taosadapter.service ${CMAKE_BINARY_DIR}/test/cfg/ - COMMAND cmake -E copy taosadapter-debug.exe ${CMAKE_BINARY_DIR}/build/bin - ) - unset(_upx_prefix) - ELSE () - MESSAGE("${Yellow} taosAdapter Not supported yet ${ColourReset}") - ENDIF () + PREFIX "taosadapter" + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/taosadapter + BUILD_ALWAYS off + DEPENDS taos + BUILD_IN_SOURCE 1 + CONFIGURE_COMMAND cmake -E echo "taosadapter no need cmake to config" + PATCH_COMMAND + COMMAND git clean -f -d + BUILD_COMMAND + COMMAND CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../include/client CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib go build -a -ldflags "-s -w -X github.com/taosdata/taosadapter/v3/version.Version=${taos_version} -X github.com/taosdata/taosadapter/v3/version.CommitID=${taosadapter_commit_sha1}" + COMMAND CGO_CFLAGS=-I${CMAKE_CURRENT_SOURCE_DIR}/../include/client CGO_LDFLAGS=-L${CMAKE_BINARY_DIR}/build/lib go build -a -o taosadapter-debug -ldflags "-X github.com/taosdata/taosadapter/v3/version.Version=${taos_version} -X github.com/taosdata/taosadapter/v3/version.CommitID=${taosadapter_commit_sha1}" + INSTALL_COMMAND + COMMAND upx taosadapter || : + COMMAND cmake -E copy taosadapter ${CMAKE_BINARY_DIR}/build/bin + COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/test/cfg/ + COMMAND cmake -E copy ./example/config/taosadapter.toml ${CMAKE_BINARY_DIR}/test/cfg/ + COMMAND cmake -E copy ./taosadapter.service ${CMAKE_BINARY_DIR}/test/cfg/ + COMMAND cmake -E copy taosadapter-debug ${CMAKE_BINARY_DIR}/build/bin + ) + ENDIF (TD_WINDOWS) ENDIF () diff --git a/tools/shell/CMakeLists.txt b/tools/shell/CMakeLists.txt index 31dcde036d34f160f72de92cb8de3f72c0b9185c..1e7d0ed1406d9fc251ffdb6319fede131febef78 100644 --- a/tools/shell/CMakeLists.txt +++ b/tools/shell/CMakeLists.txt @@ -2,6 +2,14 @@ aux_source_directory(src SHELL_SRC) add_executable(shell ${SHELL_SRC}) +IF (TD_LINUX_64 AND JEMALLOC_ENABLED) + ADD_DEFINITIONS(-DTD_JEMALLOC_ENABLED -I${CMAKE_BINARY_DIR}/build/include -L${CMAKE_BINARY_DIR}/build/lib -Wl,-rpath,${CMAKE_BINARY_DIR}/build/lib -ljemalloc) + SET(LINK_JEMALLOC "-L${CMAKE_BINARY_DIR}/build/lib -ljemalloc") + ADD_DEPENDENCIES(shell jemalloc) +ELSE () + SET(LINK_JEMALLOC "") +ENDIF () + IF (TD_LINUX AND TD_WEBSOCKET) ADD_DEFINITIONS(-DWEBSOCKET -I${CMAKE_BINARY_DIR}/build/include -ltaosws) SET(LINK_WEBSOCKET "-L${CMAKE_BINARY_DIR}/build/lib -ltaosws") @@ -21,7 +29,7 @@ ENDIF () if(TD_WINDOWS) target_link_libraries(shell PUBLIC taos_static ${LINK_WEBSOCKET}) else() - target_link_libraries(shell PUBLIC taos ${LINK_WEBSOCKET}) + target_link_libraries(shell PUBLIC taos ${LINK_WEBSOCKET} ${LINK_JEMALLOC}) endif () target_link_libraries( shell diff --git a/tools/shell/src/shellEngine.c b/tools/shell/src/shellEngine.c index d4f6e15b167ebc839050f6b615d49e3310293f59..9bb02159f0edfa5ab2a461ba9a98915b7d8b3978 100644 --- a/tools/shell/src/shellEngine.c +++ b/tools/shell/src/shellEngine.c @@ -226,7 +226,7 @@ void shellRunSingleCommandImp(char *command) { int32_t num_rows_affacted = taos_affected_rows(pSql); taos_free_result(pSql); et = taosGetTimestampUs(); - printf("Query OK, %d row(s) affected in set (%.6fs)\r\n", num_rows_affacted, (et - st) / 1E6); + printf("Query OK, %d row(s) affected(%.6fs)\r\n", num_rows_affacted, (et - st) / 1E6); // call auto tab callbackAutoTab(command, NULL, false);