Merge branch 'feature/sync-mnode-integration' of https://github.com/taosdata/TDengine into feature/sync-mnode-integration
This commit is contained in:
commit
2dee385502
|
@ -71,8 +71,8 @@ ELSE ()
|
|||
ENDIF ()
|
||||
|
||||
IF (${SANITIZER} MATCHES "true")
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fsanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -g3")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-literal-suffix -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fsanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -g3")
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fsanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=shift-base -fno-sanitize=alignment -g3")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-literal-suffix -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fsanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=shift-base -fno-sanitize=alignment -g3")
|
||||
MESSAGE(STATUS "Will compile with Address Sanitizer!")
|
||||
ELSE ()
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3")
|
||||
|
|
|
@ -3,13 +3,13 @@ title: Data Types
|
|||
description: "The data types supported by TDengine include timestamp, float, JSON, etc"
|
||||
---
|
||||
|
||||
When using TDengine to store and query data, the most important part of the data is timestamp. Timestamp must be specified when creating and inserting data rows or querying data, timestamp must follow below rules:
|
||||
When using TDengine to store and query data, the most important part of the data is timestamp. Timestamp must be specified when creating and inserting data rows or querying data, timestamp must follow the rules below:
|
||||
|
||||
- the format must be `YYYY-MM-DD HH:mm:ss.MS`, the default time precision is millisecond (ms), for example `2017-08-12 18:25:58.128`
|
||||
- internal function `now` can be used to get the current timestamp of the client side
|
||||
- the current timestamp of the client side is applied when `now` is used to insert data
|
||||
- Epoch Time:timestamp can also be a long integer number, which means the number of seconds, milliseconds or nanoseconds, depending on the time precision, from 1970-01-01 00:00:00.000 (UTC/GMT)
|
||||
- timestamp can be applied with add/subtract operation, for example `now-2h` means 2 hours back from the time at which query is executed,the unit can be b(nanosecond), u(microsecond), a(millisecond), s(second), m(minute), h(hour), d(day), w(week.。 So `select * from t1 where ts > now-2w and ts <= now-1w` means the data between two weeks ago and one week ago. The time unit can also be n (calendar month) or y (calendar year) when specifying the time window for down sampling operation.
|
||||
- timestamp can be applied with add/subtract operation, for example `now-2h` means 2 hours back from the time at which query is executed,the unit can be b(nanosecond), u(microsecond), a(millisecond), s(second), m(minute), h(hour), d(day), or w(week). So `select * from t1 where ts > now-2w and ts <= now-1w` means the data between two weeks ago and one week ago. The time unit can also be n (calendar month) or y (calendar year) when specifying the time window for down sampling operation.
|
||||
|
||||
Time precision in TDengine can be set by the `PRECISION` parameter when executing `CREATE DATABASE`, like below, the default time precision is millisecond.
|
||||
|
||||
|
@ -17,7 +17,7 @@ Time precision in TDengine can be set by the `PRECISION` parameter when executin
|
|||
CREATE DATABASE db_name PRECISION 'ns';
|
||||
```
|
||||
|
||||
In TDengine, below data types can be used when specifying a column or tag.
|
||||
In TDengine, the data types below can be used when specifying a column or tag.
|
||||
|
||||
| # | **type** | **Bytes** | **Description** |
|
||||
| --- | :-------: | --------- | ------------------------- |
|
||||
|
@ -25,12 +25,12 @@ In TDengine, below data types can be used when specifying a column or tag.
|
|||
| 2 | INT | 4 | Integer, the value range is [-2^31+1, 2^31-1], while -2^31 is treated as NULL |
|
||||
| 3 | BIGINT | 8 | Long integer, the value range is [-2^63+1, 2^63-1], while -2^63 is treated as NULL |
|
||||
| 4 | FLOAT | 4 | Floating point number, the effective number of digits is 6-7, the value range is [-3.4E38, 3.4E38] |
|
||||
| 5 | DOUBLE | 8 | double precision floating point number, the effective number of digits is 15-16, the value range is [-1.7E308, 1.7E308] |
|
||||
| 5 | DOUBLE | 8 | Double precision floating point number, the effective number of digits is 15-16, the value range is [-1.7E308, 1.7E308] |
|
||||
| 6 | BINARY | User Defined | Single-byte string for ASCII visible characters. Length must be specified when defining a column or tag of binary type. The string length can be up to 16374 bytes. The string value must be quoted with single quotes. The literal single quote inside the string must be preceded with back slash like `\'` |
|
||||
| 7 | SMALLINT | 2 | Short integer, the value range is [-32767, 32767], while -32768 is treated as NULL |
|
||||
| 8 | TINYINT | 1 | Single-byte integer, the value range is [-127, 127], while -128 is treated as NULL |
|
||||
| 9 | BOOL | 1 | Bool, the value range is {true, false} |
|
||||
| 10 | NCHAR | User Defined| Multiple-Byte string that can include like Chinese characters. Each character of NCHAR type consumes 4 bytes storage. The string value should be quoted with single quotes. Literal single quote inside the string must be preceded with backslash, like `\’`. The length must be specified when defining a column or tag of NCHAR type, for example nchar(10) means it can store at most 10 characters of nchar type and will consume fixed storage of 40 bytes. Error will be reported the string value exceeds the length defined. |
|
||||
| 10 | NCHAR | User Defined| Multiple-Byte string that can include like Chinese characters. Each character of NCHAR type consumes 4 bytes storage. The string value should be quoted with single quotes. Literal single quote inside the string must be preceded with backslash, like `\’`. The length must be specified when defining a column or tag of NCHAR type, for example nchar(10) means it can store at most 10 characters of nchar type and will consume fixed storage of 40 bytes. An error will be reported if the string value exceeds the length defined. |
|
||||
| 11 | JSON | | json type can only be used on tag, a tag of json type is excluded with any other tags of any other type |
|
||||
|
||||
:::tip
|
||||
|
|
|
@ -35,7 +35,7 @@ CREATE DATABASE [IF NOT EXISTS] db_name [KEEP keep] [DAYS days] [UPDATE 1];
|
|||
- maxVgroupsPerDb: [Description](/reference/config/#maxvgroupsperdb)
|
||||
- comp: [Description](/reference/config/#comp)
|
||||
- precision: [Description](/reference/config/#precision)
|
||||
6. Please be noted that all of the parameters mentioned in this section can be configured in configuration file `taosd.cfg` at server side and used by default, can be override if they are specified in `create database` statement.
|
||||
6. Please note that all of the parameters mentioned in this section can be configured in configuration file `taosd.cfg` at server side and used by default, the default parameters can be overriden if they are specified in `create database` statement.
|
||||
|
||||
:::
|
||||
|
||||
|
@ -69,7 +69,7 @@ All data in the database will be deleted too. This command must be used with cau
|
|||
|
||||
## Change Database Configuration
|
||||
|
||||
Some examples are shown below to demonstrate how to change the configuration of a database. Please be noted that some configuration parameters can be changed after the database is created, but some others can't, for details of the configuration parameters of database please refer to [Configuration Parameters](/reference/config/).
|
||||
Some examples are shown below to demonstrate how to change the configuration of a database. Please note that some configuration parameters can be changed after the database is created, but some others can't, for details of the configuration parameters of database please refer to [Configuration Parameters](/reference/config/).
|
||||
|
||||
```
|
||||
ALTER DATABASE db_name COMP 2;
|
||||
|
@ -124,4 +124,4 @@ SHOW DATABASES;
|
|||
SHOW CREATE DATABASE db_name;
|
||||
```
|
||||
|
||||
This command is useful when migrating the data from one TDengine cluster to another one. Firstly this command can be used to get the CREATE statement, which in turn can be used in another TDengine to create an exactly same database.
|
||||
This command is useful when migrating the data from one TDengine cluster to another one. This command can be used to get the CREATE statement, which can be used in another TDengine to create the exact same database.
|
||||
|
|
|
@ -12,12 +12,12 @@ CREATE TABLE [IF NOT EXISTS] tb_name (timestamp_field_name TIMESTAMP, field1_nam
|
|||
|
||||
:::info
|
||||
|
||||
1. The first column of a table must be in TIMESTAMP type, and it will be set as primary key automatically
|
||||
2. The maximum length of table name is 192 bytes.
|
||||
3. The maximum length of each row is 16k bytes, please be notes that the extra 2 bytes used by each BINARY/NCHAR column are also counted in.
|
||||
4. The name of sub-table can only be consisted of English characters, digits and underscore, and can't be started with digit. Table names are case insensitive.
|
||||
5. The maximum length in bytes must be specified when using BINARY or NCHAR type.
|
||||
6. Escape character "\`" can be used to avoid the conflict between table names and reserved keywords, above rules will be bypassed when using escape character on table names, but the upper limit for name length is still valid. The table names specified using escape character are case sensitive. Only ASCII visible characters can be used with escape character.
|
||||
1. The first column of a table must be of TIMESTAMP type, and it will be set as the primary key automatically
|
||||
2. The maximum length of the table name is 192 bytes.
|
||||
3. The maximum length of each row is 16k bytes, please note that the extra 2 bytes used by each BINARY/NCHAR column are also counted.
|
||||
4. The name of the subtable can only consist of English characters, digits and underscore, and can't start with a digit. Table names are case insensitive.
|
||||
5. The maximum length in bytes must be specified when using BINARY or NCHAR types.
|
||||
6. Escape character "\`" can be used to avoid the conflict between table names and reserved keywords, above rules will be bypassed when using escape character on table names, but the upper limit for the name length is still valid. The table names specified using escape character are case sensitive. Only ASCII visible characters can be used with escape character.
|
||||
For example \`aBc\` and \`abc\` are different table names but `abc` and `aBc` are same table names because they are both converted to `abc` internally.
|
||||
|
||||
:::
|
||||
|
@ -28,9 +28,9 @@ CREATE TABLE [IF NOT EXISTS] tb_name (timestamp_field_name TIMESTAMP, field1_nam
|
|||
CREATE TABLE [IF NOT EXISTS] tb_name USING stb_name TAGS (tag_value1, ...);
|
||||
```
|
||||
|
||||
The above command creates a subtable using the specified super table as template and the specified tab values.
|
||||
The above command creates a subtable using the specified super table as a template and the specified tag values.
|
||||
|
||||
### Create Subtable Using STable As Template With A Part of Tags
|
||||
### Create Subtable Using STable As Template With A Subset of Tags
|
||||
|
||||
```
|
||||
CREATE TABLE [IF NOT EXISTS] tb_name USING stb_name (tag_name1, ...) TAGS (tag_value1, ...);
|
||||
|
@ -44,11 +44,11 @@ The tags for which no value is specified will be set to NULL.
|
|||
CREATE TABLE [IF NOT EXISTS] tb_name1 USING stb_name TAGS (tag_value1, ...) [IF NOT EXISTS] tb_name2 USING stb_name TAGS (tag_value2, ...) ...;
|
||||
```
|
||||
|
||||
This way can be used to create a lot of tables in a single SQL statement to accelerate the speed of the creating tables.
|
||||
This can be used to create a lot of tables in a single SQL statement to accelerate the speed of the creating tables.
|
||||
|
||||
:::info
|
||||
|
||||
- Creating tables in batch must use super table as template.
|
||||
- Creating tables in batch must use a super table as a template.
|
||||
- The length of single statement is suggested to be between 1,000 and 3,000 bytes for best performance.
|
||||
|
||||
:::
|
||||
|
@ -71,7 +71,7 @@ SHOW TABLES [LIKE tb_name_wildcard];
|
|||
SHOW CREATE TABLE tb_name;
|
||||
```
|
||||
|
||||
This way is useful when migrating the data in one TDengine cluster to another one because it can be used to create exactly same tables in the target database.
|
||||
This is useful when migrating the data in one TDengine cluster to another one because it can be used to create the exact same tables in the target database.
|
||||
|
||||
## Show Table Definition
|
||||
|
||||
|
@ -90,7 +90,7 @@ ALTER TABLE tb_name ADD COLUMN field_name data_type;
|
|||
:::info
|
||||
|
||||
1. The maximum number of columns is 4096, the minimum number of columns is 2.
|
||||
2. The maximum length of column name is 64 bytes.
|
||||
2. The maximum length of a column name is 64 bytes.
|
||||
|
||||
:::
|
||||
|
||||
|
@ -101,7 +101,7 @@ ALTER TABLE tb_name DROP COLUMN field_name;
|
|||
```
|
||||
|
||||
:::note
|
||||
If a table is created using a super table as template, the table definition can only be changed on the corresponding super table, but the change will be automatically applied to all the sub tables created using this super table as template. For tables created in normal way, the table definition can be changed directly on the table.
|
||||
If a table is created using a super table as template, the table definition can only be changed on the corresponding super table, and the change will be automatically applied to all the subtables created using this super table as template. For tables created in the normal way, the table definition can be changed directly on the table.
|
||||
|
||||
:::
|
||||
|
||||
|
@ -111,10 +111,10 @@ If a table is created using a super table as template, the table definition can
|
|||
ALTER TABLE tb_name MODIFY COLUMN field_name data_type(length);
|
||||
```
|
||||
|
||||
The the type of a column is variable length, like BINARY or NCHAR, this way can be used to change (or increase) the length of the column.
|
||||
The type of a column is variable length, like BINARY or NCHAR, this can be used to change (or increase) the length of the column.
|
||||
|
||||
:::note
|
||||
If a table is created using a super table as template, the table definition can only be changed on the corresponding super table, but the change will be automatically applied to all the sub tables created using this super table as template. For tables created in normal way, the table definition can be changed directly on the table.
|
||||
If a table is created using a super table as template, the table definition can only be changed on the corresponding super table, and the change will be automatically applied to all the subtables created using this super table as template. For tables created in the normal way, the table definition can be changed directly on the table.
|
||||
|
||||
:::
|
||||
|
||||
|
|
|
@ -15,14 +15,14 @@ Keyword `STable`, abbreviated for super table, is supported since version 2.0.15
|
|||
CREATE STable [IF NOT EXISTS] stb_name (timestamp_field_name TIMESTAMP, field1_name data_type1 [, field2_name data_type2 ...]) TAGS (tag1_name tag_type1, tag2_name tag_type2 [, tag3_name tag_type3]);
|
||||
```
|
||||
|
||||
The SQL statement of creating STable is similar to that of creating table, but a special column named as `TAGS` must be specified with the names and types of the tags.
|
||||
The SQL statement of creating a STable is similar to that of creating a table, but a special column set named `TAGS` must be specified with the names and types of the tags.
|
||||
|
||||
:::info
|
||||
|
||||
1. The tag types specified in TAGS should NOT be timestamp. Since 2.1.3.0 timestamp type can be used in TAGS column, but its value must be fixed and arithmetic operation can't be applied on it.
|
||||
2. The tag names specified in TAGS should NOT be same as other columns.
|
||||
3. The tag names specified in TAGS should NOT be same as any reserved keywords.(Please refer to [keywords](/taos-sql/keywords/)
|
||||
4. The maximum number of tags specified in TAGS is 128, but there must be at least one tag, and the total length of all tag columns should NOT exceed 16KB.
|
||||
2. The tag names specified in TAGS should NOT be the same as other columns.
|
||||
3. The tag names specified in TAGS should NOT be the same as any reserved keywords.(Please refer to [keywords](/taos-sql/keywords/)
|
||||
4. The maximum number of tags specified in TAGS is 128, there must be at least one tag, and the total length of all tag columns should NOT exceed 16KB.
|
||||
|
||||
:::
|
||||
|
||||
|
@ -32,7 +32,7 @@ The SQL statement of creating STable is similar to that of creating table, but a
|
|||
DROP STable [IF EXISTS] stb_name;
|
||||
```
|
||||
|
||||
All the sub-tables created using the deleted STable will be deleted automatically.
|
||||
All the subtables created using the deleted STable will be deleted automatically.
|
||||
|
||||
## Show All STables
|
||||
|
||||
|
@ -40,7 +40,7 @@ All the sub-tables created using the deleted STable will be deleted automaticall
|
|||
SHOW STableS [LIKE tb_name_wildcard];
|
||||
```
|
||||
|
||||
This command can be used to display the information of all STables in the current database, including name, creation time, number of columns, number of tags, number of tables created using this STable.
|
||||
This command can be used to display the information of all STables in the current database, including name, creation time, number of columns, number of tags, and number of tables created using this STable.
|
||||
|
||||
## Show The Create Statement of A STable
|
||||
|
||||
|
@ -48,7 +48,7 @@ This command can be used to display the information of all STables in the curren
|
|||
SHOW CREATE STable stb_name;
|
||||
```
|
||||
|
||||
This command is useful in migrating data from one TDengine cluster to another one because it can be used to create an exactly same STable in the target database.
|
||||
This command is useful in migrating data from one TDengine cluster to another because it can be used to create the exact same STable in the target database.
|
||||
|
||||
## Get STable Definition
|
||||
|
||||
|
@ -94,7 +94,7 @@ This command is used to add a new tag for a STable and specify the tag type.
|
|||
ALTER STable stb_name DROP TAG tag_name;
|
||||
```
|
||||
|
||||
The tag will be removed automatically from all the sub tables crated using the super table as template once a tag is removed from a super table.
|
||||
The tag will be removed automatically from all the subtables created using the super table as template once a tag is removed from a super table.
|
||||
|
||||
### Change A Tag
|
||||
|
||||
|
@ -102,7 +102,7 @@ The tag will be removed automatically from all the sub tables crated using the s
|
|||
ALTER STable stb_name CHANGE TAG old_tag_name new_tag_name;
|
||||
```
|
||||
|
||||
The tag name will be changed automatically from all the sub tables crated using the super table as template once a tag name is changed for a super table.
|
||||
The tag name will be changed automatically for all the subtables created using the super table as template once a tag name is changed for a super table.
|
||||
|
||||
### Change Tag Length
|
||||
|
||||
|
@ -113,6 +113,6 @@ ALTER STable stb_name MODIFY TAG tag_name data_type(length);
|
|||
This command can be used to change (or increase, more specifically) the length of a tag of variable length types, like BINARY or NCHAR.
|
||||
|
||||
:::note
|
||||
Changing tag value can be applied to only sub tables. All other tag operations, like add tag, remove tag, however, can be applied to only STable. If a new tag is added for a STable, the tag will be added with NULL value for all its sub tables.
|
||||
Changing tag values can be applied to only subtables. All other tag operations, like add tag, remove tag, however, can be applied to only STable. If a new tag is added for a STable, the tag will be added with NULL value for all its subtables.
|
||||
|
||||
:::
|
||||
|
|
|
@ -19,15 +19,15 @@ INSERT INTO
|
|||
|
||||
## Insert Single or Multiple Rows
|
||||
|
||||
Single row or multiple rows specified with VALUES can be inserted into a specific table. For example
|
||||
Single row or multiple rows specified with VALUES can be inserted into a specific table. For example:
|
||||
|
||||
Single row is inserted using below statement.
|
||||
A single row is inserted using the below statement.
|
||||
|
||||
```sq;
|
||||
INSERT INTO d1001 VALUES (NOW, 10.2, 219, 0.32);
|
||||
```
|
||||
|
||||
Double rows can be inserted using below statement.
|
||||
Double rows are inserted using the below statement.
|
||||
|
||||
```sql
|
||||
INSERT INTO d1001 VALUES ('2021-07-13 14:06:32.272', 10.2, 219, 0.32) (1626164208000, 10.15, 217, 0.33);
|
||||
|
@ -36,7 +36,7 @@ INSERT INTO d1001 VALUES ('2021-07-13 14:06:32.272', 10.2, 219, 0.32) (162616420
|
|||
:::note
|
||||
|
||||
1. In the second example above, different formats are used in the two rows to be inserted. In the first row, the timestamp format is a date and time string, which is interpreted from the string value only. In the second row, the timestamp format is a long integer, which will be interpreted based on the database time precision.
|
||||
2. When trying to insert multiple rows in single statement, only the timestamp of one row can be set as NOW, otherwise there will be duplicate timestamps among the rows and the result may be out of expectation because NOW will be interpreted as the time when the statement is executed.
|
||||
2. When trying to insert multiple rows in a single statement, only the timestamp of one row can be set as NOW, otherwise there will be duplicate timestamps among the rows and the result may be out of expectation because NOW will be interpreted as the time when the statement is executed.
|
||||
3. The oldest timestamp that is allowed is subtracting the KEEP parameter from current time.
|
||||
4. The newest timestamp that is allowed is adding the DAYS parameter to current time.
|
||||
|
||||
|
@ -51,13 +51,13 @@ INSERT INTO d1001 (ts, current, phase) VALUES ('2021-07-13 14:06:33.196', 10.27,
|
|||
```
|
||||
|
||||
:::info
|
||||
If no columns are explicitly specified, all the columns must be provided with values, this is called "all column mode". The insert performance of all column mode is much better than specifying a part of columns, so it's encouraged to use "all column mode" while providing NULL value explicitly for the columns for which no actual value can be provided.
|
||||
If no columns are explicitly specified, all the columns must be provided with values, this is called "all column mode". The insert performance of all column mode is much better than specifying a subset of columns, so it's encouraged to use "all column mode" while providing NULL value explicitly for the columns for which no actual value can be provided.
|
||||
|
||||
:::
|
||||
|
||||
## Insert Into Multiple Tables
|
||||
|
||||
One or multiple rows can be inserted into multiple tables in single SQL statement, with or without specifying specific columns.
|
||||
One or multiple rows can be inserted into multiple tables in a single SQL statement, with or without specifying specific columns.
|
||||
|
||||
```sql
|
||||
INSERT INTO d1001 VALUES ('2021-07-13 14:06:34.630', 10.2, 219, 0.32) ('2021-07-13 14:06:35.779', 10.15, 217, 0.33)
|
||||
|
@ -66,19 +66,19 @@ INSERT INTO d1001 VALUES ('2021-07-13 14:06:34.630', 10.2, 219, 0.32) ('2021-07-
|
|||
|
||||
## Automatically Create Table When Inserting
|
||||
|
||||
If it's not sure whether the table already exists, the table can be created automatically while inserting using below SQL statement. To use this functionality, a STable must be used as template and tag values must be provided.
|
||||
If it's unknown whether the table already exists, the table can be created automatically while inserting using the SQL statement below. To use this functionality, a STable must be used as template and tag values must be provided.
|
||||
|
||||
```sql
|
||||
INSERT INTO d21001 USING meters TAGS ('California.SanFrancisco', 2) VALUES ('2021-07-13 14:06:32.272', 10.2, 219, 0.32);
|
||||
```
|
||||
|
||||
It's not necessary to provide values for all tag when creating tables automatically, the tags without values provided will be set to NULL.
|
||||
It's not necessary to provide values for all tags when creating tables automatically, the tags without values provided will be set to NULL.
|
||||
|
||||
```sql
|
||||
INSERT INTO d21001 USING meters (groupId) TAGS (2) VALUES ('2021-07-13 14:06:33.196', 10.15, 217, 0.33);
|
||||
```
|
||||
|
||||
Multiple rows can also be inserted into same table in single SQL statement using this way.
|
||||
Multiple rows can also be inserted into the same table in a single SQL statement.
|
||||
|
||||
```sql
|
||||
INSERT INTO d21001 USING meters TAGS ('California.SanFrancisco', 2) VALUES ('2021-07-13 14:06:34.630', 10.2, 219, 0.32) ('2021-07-13 14:06:35.779', 10.15, 217, 0.33)
|
||||
|
@ -87,19 +87,19 @@ INSERT INTO d21001 USING meters TAGS ('California.SanFrancisco', 2) VALUES ('202
|
|||
```
|
||||
|
||||
:::info
|
||||
Prior to version 2.0.20.5, when using `INSERT` to create table automatically and specify the columns, the column names must follow the table name immediately. From version 2.0.20.5, the column names can follow the table name immediately, also can be put between `TAGS` and `VALUES`. In same SQL statement, however, these two ways of specifying column names can't be mixed.
|
||||
Prior to version 2.0.20.5, when using `INSERT` to create tables automatically and specifying the columns, the column names must follow the table name immediately. From version 2.0.20.5, the column names can follow the table name immediately, also can be put between `TAGS` and `VALUES`. In the same SQL statement, however, these two ways of specifying column names can't be mixed.
|
||||
:::
|
||||
|
||||
## Insert Rows From A File
|
||||
|
||||
Besides using `VALUES` to insert one or multiple rows, the data to be inserted can also be prepared in a CSV file with comma as separator and each field value quoted by single quotes. Table definition is not required in the CSV file. For example, if file "/tmp/csvfile.csv" contains below data:
|
||||
Besides using `VALUES` to insert one or multiple rows, the data to be inserted can also be prepared in a CSV file with comma as separator and each field value quoted by single quotes. Table definition is not required in the CSV file. For example, if file "/tmp/csvfile.csv" contains the below data:
|
||||
|
||||
```
|
||||
'2021-07-13 14:07:34.630', '10.2', '219', '0.32'
|
||||
'2021-07-13 14:07:35.779', '10.15', '217', '0.33'
|
||||
```
|
||||
|
||||
Then data in this file can be inserted by below SQL statement:
|
||||
Then data in this file can be inserted by the SQL statement below:
|
||||
|
||||
```sql
|
||||
INSERT INTO d1001 FILE '/tmp/csvfile.csv';
|
||||
|
@ -107,13 +107,13 @@ INSERT INTO d1001 FILE '/tmp/csvfile.csv';
|
|||
|
||||
## Create Tables Automatically and Insert Rows From File
|
||||
|
||||
From version 2.1.5.0, tables can be automatically created using a super table as template when inserting data from a CSV file, Like below:
|
||||
From version 2.1.5.0, tables can be automatically created using a super table as template when inserting data from a CSV file, like below:
|
||||
|
||||
```sql
|
||||
INSERT INTO d21001 USING meters TAGS ('California.SanFrancisco', 2) FILE '/tmp/csvfile.csv';
|
||||
```
|
||||
|
||||
Multiple tables can be automatically created and inserted in single SQL statement, like below:
|
||||
Multiple tables can be automatically created and inserted in a single SQL statement, like below:
|
||||
|
||||
```sql
|
||||
INSERT INTO d21001 USING meters TAGS ('California.SanFrancisco', 2) FILE '/tmp/csvfile_21001.csv'
|
||||
|
@ -122,15 +122,15 @@ INSERT INTO d21001 USING meters TAGS ('California.SanFrancisco', 2) FILE '/tmp/c
|
|||
|
||||
## More About Insert
|
||||
|
||||
For SQL statement like `insert`, stream parsing strategy is applied. That means before an error is found and the execution is aborted, the part prior to the error point has already been executed. Below is an experiment to help understand the behavior.
|
||||
For SQL statement like `insert`, a stream parsing strategy is applied. That means before an error is found and the execution is aborted, the part prior to the error point has already been executed. Below is an experiment to help understand the behavior.
|
||||
|
||||
Firstly, a super table is created.
|
||||
First, a super table is created.
|
||||
|
||||
```sql
|
||||
CREATE TABLE meters(ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS(location BINARY(30), groupId INT);
|
||||
```
|
||||
|
||||
It can be proved that the super table has been created by `SHOW STableS`, but no table exists by `SHOW TABLES`.
|
||||
It can be proven that the super table has been created by `SHOW STableS`, but no table exists using `SHOW TABLES`.
|
||||
|
||||
```
|
||||
taos> SHOW STableS;
|
||||
|
@ -161,4 +161,4 @@ taos> SHOW TABLES;
|
|||
Query OK, 1 row(s) in set (0.001091s)
|
||||
```
|
||||
|
||||
From the above experiment, we can see that even though the value to be inserted is invalid but the table is still created.
|
||||
From the above experiment, we can see that while the value to be inserted is invalid the table is still created.
|
||||
|
|
|
@ -96,7 +96,7 @@ Query OK, 1 row(s) in set (0.000849s)
|
|||
|
||||
## Tags
|
||||
|
||||
Starting from version 2.0.14, tag columns can be selected together with data columns when querying sub tables. Please be noted that, however, wildcard \* doesn't represent any tag column, that means tag columns must be specified explicitly like below example.
|
||||
Starting from version 2.0.14, tag columns can be selected together with data columns when querying sub tables. Please note that, however, wildcard \* doesn't represent any tag column, that means tag columns must be specified explicitly like the example below.
|
||||
|
||||
```
|
||||
taos> SELECT location, groupid, current FROM d1001 LIMIT 2;
|
||||
|
@ -109,7 +109,7 @@ Query OK, 2 row(s) in set (0.003112s)
|
|||
|
||||
## Get distinct values
|
||||
|
||||
`DISTINCT` keyword can be used to get all the unique values of tag columns from a super table, it can also be used to get all the unique values of data columns from a table or sub table.
|
||||
`DISTINCT` keyword can be used to get all the unique values of tag columns from a super table, it can also be used to get all the unique values of data columns from a table or subtable.
|
||||
|
||||
```sql
|
||||
SELECT DISTINCT tag_name [, tag_name ...] FROM stb_name;
|
||||
|
@ -120,7 +120,7 @@ SELECT DISTINCT col_name [, col_name ...] FROM tb_name;
|
|||
|
||||
1. Configuration parameter `maxNumOfDistinctRes` in `taos.cfg` is used to control the number of rows to output. The minimum configurable value is 100,000, the maximum configurable value is 100,000,000, the default value is 1000,000. If the actual number of rows exceeds the value of this parameter, only the number of rows specified by this parameter will be output.
|
||||
2. It can't be guaranteed that the results selected by using `DISTINCT` on columns of `FLOAT` or `DOUBLE` are exactly unique because of the precision nature of floating numbers.
|
||||
3. `DISTINCT` can't be used in the sub-query of a nested query statement, and can't be used together with aggregate functions, `GROUP BY` or `JOIN` in same SQL statement.
|
||||
3. `DISTINCT` can't be used in the sub-query of a nested query statement, and can't be used together with aggregate functions, `GROUP BY` or `JOIN` in the same SQL statement.
|
||||
|
||||
:::
|
||||
|
||||
|
@ -197,7 +197,7 @@ taos> SELECT SERVER_VERSION();
|
|||
Query OK, 1 row(s) in set (0.000077s)
|
||||
```
|
||||
|
||||
Below statement is used to check the server status. One integer, like `1`, is returned if the server status is OK, otherwise an error code is returned. This way is compatible with the status check for TDengine from connection pool or 3rd party tools, and can avoid the problem of losing connection from connection pool when using wrong heartbeat checking SQL statement.
|
||||
Below statement is used to check the server status. One integer, like `1`, is returned if the server status is OK, otherwise an error code is returned. This is compatible with the status check for TDengine from connection pool or 3rd party tools, and can avoid the problem of losing the connection from a connection pool when using the wrong heartbeat checking SQL statement.
|
||||
|
||||
```
|
||||
taos> SELECT SERVER_STATUS();
|
||||
|
@ -248,12 +248,12 @@ summary:
|
|||
|
||||
## Special Keywords in TAOS SQL
|
||||
|
||||
- `TBNAME`: it is treated as a special tag when selecting on a super table, representing the name of sub-tables in that super table.
|
||||
- `TBNAME`: it is treated as a special tag when selecting on a super table, representing the name of subtables in that super table.
|
||||
- `_c0`: represents the first column of a table or super table.
|
||||
|
||||
## Tips
|
||||
|
||||
To get all the sub tables and corresponding tag values from a super table:
|
||||
To get all the subtables and corresponding tag values from a super table:
|
||||
|
||||
```SQL
|
||||
SELECT TBNAME, location FROM meters;
|
||||
|
@ -271,8 +271,8 @@ Only filter on `TAGS` are allowed in the `where` clause for above two query stat
|
|||
taos> SELECT TBNAME, location FROM meters;
|
||||
tbname | location |
|
||||
==================================================================
|
||||
d1004 | California.LoSangeles |
|
||||
d1003 | California.LoSangeles |
|
||||
d1004 | California.LosAngeles |
|
||||
d1003 | California.LosAngeles |
|
||||
d1002 | California.SanFrancisco |
|
||||
d1001 | California.SanFrancisco |
|
||||
Query OK, 4 row(s) in set (0.000881s)
|
||||
|
@ -285,10 +285,10 @@ Query OK, 1 row(s) in set (0.001091s)
|
|||
```
|
||||
|
||||
- Wildcard \* can be used to get all columns, or specific column names can be specified. Arithmetic operation can be performed on columns of number types, columns can be renamed in the result set.
|
||||
- Arithmetic operation on columns can't be used in where clause. For example, `where a*2>6;` is not allowed but `where a>6/2;` can be used instead for same purpose.
|
||||
- Arithmetic operation on columns can't be used in where clause. For example, `where a*2>6;` is not allowed but `where a>6/2;` can be used instead for the same purpose.
|
||||
- Arithmetic operation on columns can't be used as the objectives of select statement. For example, `select min(2*a) from t;` is not allowed but `select 2*min(a) from t;` can be used instead.
|
||||
- Logical operation can be used in `WHERE` clause to filter numeric values, wildcard can be used to filter string values.
|
||||
- Result set are arranged in ascending order of the first column, i.e. timestamp, but it can be controlled to output as descending order of timestamp. If `order by` is used on other columns, the result may be not as expected. By the way, \_c0 is used to represent the first column, i.e. timestamp.
|
||||
- Result sets are arranged in ascending order of the first column, i.e. timestamp, but it can be controlled to output as descending order of timestamp. If `order by` is used on other columns, the result may not be as expected. By the way, \_c0 is used to represent the first column, i.e. timestamp.
|
||||
- `LIMIT` parameter is used to control the number of rows to output. `OFFSET` parameter is used to specify from which row to output. `LIMIT` and `OFFSET` are executed after `ORDER BY` in the query execution. A simple tip is that `LIMIT 5 OFFSET 2` can be abbreviated as `LIMIT 2, 5`.
|
||||
- What is controlled by `LIMIT` is the number of rows in each group when `GROUP BY` is used.
|
||||
- `SLIMIT` parameter is used to control the number of groups when `GROUP BY` is used. Similar to `LIMIT`, `SLIMIT 5 OFFSET 2` can be abbreviated as `SLIMIT 2, 5`.
|
||||
|
@ -296,7 +296,7 @@ Query OK, 1 row(s) in set (0.001091s)
|
|||
|
||||
## Where
|
||||
|
||||
Logical operations in below table can be used in `where` clause to filter the resulting rows.
|
||||
Logical operations in below table can be used in the `where` clause to filter the resulting rows.
|
||||
|
||||
| **Operation** | **Note** | **Applicable Data Types** |
|
||||
| ------------- | ------------------------ | ----------------------------------------- |
|
||||
|
@ -314,7 +314,7 @@ Logical operations in below table can be used in `where` clause to filter the re
|
|||
|
||||
**Explanations**:
|
||||
|
||||
- Operator `<\>` is equal to `!=`, please be noted that this operator can't be used on the first column of any table, i.e.timestamp column.
|
||||
- Operator `<\>` is equal to `!=`, please note that this operator can't be used on the first column of any table, i.e.timestamp column.
|
||||
- Operator `like` is used together with wildcards to match strings
|
||||
- '%' matches 0 or any number of characters, '\_' matches any single ASCII character.
|
||||
- `\_` is used to match the \_ in the string.
|
||||
|
@ -323,8 +323,8 @@ Logical operations in below table can be used in `where` clause to filter the re
|
|||
- For timestamp column, only one condition can be used; for other columns or tags, `OR` keyword can be used to combine multiple logical operators. For example, `((value > 20 AND value < 30) OR (value < 12))`.
|
||||
- From version 2.3.0.0, multiple conditions can be used on timestamp column, but the result set can only contain single time range.
|
||||
- From version 2.0.17.0, operator `BETWEEN AND` can be used in where clause, for example `WHERE col2 BETWEEN 1.5 AND 3.25` means the filter condition is equal to "1.5 ≤ col2 ≤ 3.25".
|
||||
- From version 2.1.4.0, operator `IN` can be used in where clause. For example, `WHERE city IN ('California.SanFrancisco', 'California.SanDieo')`. For bool type, both `{true, false}` and `{0, 1}` are allowed, but integers other than 0 or 1 are not allowed. FLOAT and DOUBLE types are impacted by floating precision, only values that match the condition within the tolerance will be selected. Non-primary key column of timestamp type can be used with `IN`.
|
||||
- From version 2.3.0.0, regular expression is supported in where clause with keyword `match` or `nmatch`, the regular expression is case insensitive.
|
||||
- From version 2.1.4.0, operator `IN` can be used in the where clause. For example, `WHERE city IN ('California.SanFrancisco', 'California.SanDiego')`. For bool type, both `{true, false}` and `{0, 1}` are allowed, but integers other than 0 or 1 are not allowed. FLOAT and DOUBLE types are impacted by floating precision, only values that match the condition within the tolerance will be selected. Non-primary key column of timestamp type can be used with `IN`.
|
||||
- From version 2.3.0.0, regular expression is supported in the where clause with keyword `match` or `nmatch`, the regular expression is case insensitive.
|
||||
|
||||
## Regular Expression
|
||||
|
||||
|
@ -342,11 +342,11 @@ The regular expression being used must be compliant with POSIX specification, pl
|
|||
|
||||
Regular expression can be used against only table names, i.e. `tbname`, and tags of binary/nchar types, but can't be used against data columns.
|
||||
|
||||
The maximum length of regular expression string is 128 bytes. Configuration parameter `maxRegexStringLen` can be used to set the maximum allowed regular expression. It's a configuration parameter on client side, and will take in effect after restarting the client.
|
||||
The maximum length of regular expression string is 128 bytes. Configuration parameter `maxRegexStringLen` can be used to set the maximum allowed regular expression. It's a configuration parameter on the client side, and will take effect after restarting the client.
|
||||
|
||||
## JOIN
|
||||
|
||||
From version 2.2.0.0, inner join is fully supported in TDengine. More specifically, the inner join between table and table, that between STable and STable, and that between sub query and sub query are supported.
|
||||
From version 2.2.0.0, inner join is fully supported in TDengine. More specifically, the inner join between table and table, between STable and STable, and between sub query and sub query are supported.
|
||||
|
||||
Only primary key, i.e. timestamp, can be used in the join operation between table and table. For example:
|
||||
|
||||
|
@ -369,7 +369,7 @@ Similary, join operation can be performed on the result set of multiple sub quer
|
|||
:::note
|
||||
Restrictions on join operation:
|
||||
|
||||
- The number of tables or STables in single join operation can't exceed 10.
|
||||
- The number of tables or STables in a single join operation can't exceed 10.
|
||||
- `FILL` is not allowed in the query statement that includes JOIN operation.
|
||||
- Arithmetic operation is not allowed on the result set of join operation.
|
||||
- `GROUP BY` is not allowed on a part of tables that participate in join operation.
|
||||
|
@ -382,7 +382,7 @@ Restrictions on join operation:
|
|||
|
||||
Nested query is also called sub query, that means in a single SQL statement the result of inner query can be used as the data source of the outer query.
|
||||
|
||||
From 2.2.0.0, unassociated sub query can be used in the `FROM` clause. unassociated means the sub query doesn't use the parameters in the parent query. More specifically, in the `tb_name_list` of `SELECT` statement, an independent SELECT statement can be used. So a complete nested query looks like:
|
||||
From 2.2.0.0, unassociated sub query can be used in the `FROM` clause. Unassociated means the sub query doesn't use the parameters in the parent query. More specifically, in the `tb_name_list` of `SELECT` statement, an independent SELECT statement can be used. So a complete nested query looks like:
|
||||
|
||||
```SQL
|
||||
SELECT ... FROM (SELECT ... FROM ...) ...;
|
||||
|
@ -414,7 +414,7 @@ UNION ALL SELECT ...
|
|||
[UNION ALL SELECT ...]
|
||||
```
|
||||
|
||||
`UNION ALL` operator can be used to combine the result set from multiple select statements as long as the result set of these select statements have exactly same columns. `UNION ALL` doesn't remove redundant rows from multiple result sets. In single SQL statement, at most 100 `UNION ALL` can be supported.
|
||||
`UNION ALL` operator can be used to combine the result set from multiple select statements as long as the result set of these select statements have exactly the same columns. `UNION ALL` doesn't remove redundant rows from multiple result sets. In a single SQL statement, at most 100 `UNION ALL` can be supported.
|
||||
|
||||
### Examples
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ title: Functions
|
|||
|
||||
## Aggregate Functions
|
||||
|
||||
Aggregate query is supported in TDengine by following aggregate functions and selection functions.
|
||||
Aggregate queries are supported in TDengine by the following aggregate functions and selection functions.
|
||||
|
||||
### COUNT
|
||||
|
||||
|
@ -12,11 +12,11 @@ Aggregate query is supported in TDengine by following aggregate functions and se
|
|||
SELECT COUNT([*|field_name]) FROM tb_name [WHERE clause];
|
||||
```
|
||||
|
||||
**Description**:Get the number of rows or the number of non-null values in a table or a super table.
|
||||
**Description**: Get the number of rows or the number of non-null values in a table or a super table.
|
||||
|
||||
**Return value type**:Long integer INT64
|
||||
**Return value type**: Long integer INT64
|
||||
|
||||
**Applicable column types**:All
|
||||
**Applicable column types**: All
|
||||
|
||||
**Applicable table types**: table, super table, sub table
|
||||
|
||||
|
@ -47,13 +47,13 @@ Query OK, 1 row(s) in set (0.001075s)
|
|||
SELECT AVG(field_name) FROM tb_name [WHERE clause];
|
||||
```
|
||||
|
||||
**Description**:Get the average value of a column in a table or STable
|
||||
**Description**: Get the average value of a column in a table or STable
|
||||
|
||||
**Return value type**:Double precision floating number
|
||||
**Return value type**: Double precision floating number
|
||||
|
||||
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
|
||||
**Applicable column types**: Data types except for timestamp, binary, nchar and bool
|
||||
|
||||
**Applicable table types**:table, STable
|
||||
**Applicable table types**: table, STable
|
||||
|
||||
**Examples**:
|
||||
|
||||
|
@ -77,13 +77,13 @@ Query OK, 1 row(s) in set (0.000943s)
|
|||
SELECT TWA(field_name) FROM tb_name WHERE clause;
|
||||
```
|
||||
|
||||
**Description**:Time weighted average on a specific column within a time range
|
||||
**Description**: Time weighted average on a specific column within a time range
|
||||
|
||||
**Return value type**:Double precision floating number
|
||||
**Return value type**: Double precision floating number
|
||||
|
||||
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
|
||||
**Applicable column types**: Data types except for timestamp, binary, nchar and bool
|
||||
|
||||
**Applicable table types**:table, STable
|
||||
**Applicable table types**: table, STable
|
||||
|
||||
**More explanations**:
|
||||
|
||||
|
@ -95,13 +95,13 @@ SELECT TWA(field_name) FROM tb_name WHERE clause;
|
|||
SELECT IRATE(field_name) FROM tb_name WHERE clause;
|
||||
```
|
||||
|
||||
**Description**:instantaneous rate on a specific column. The last two samples in the specified time range are used to calculate instantaneous rate. If the last sample value is smaller, then only the last sample value is used instead of the difference between the last two sample values.
|
||||
**Description**: instantaneous rate on a specific column. The last two samples in the specified time range are used to calculate instantaneous rate. If the last sample value is smaller, then only the last sample value is used instead of the difference between the last two sample values.
|
||||
|
||||
**Return value type**:Double precision floating number
|
||||
**Return value type**: Double precision floating number
|
||||
|
||||
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
|
||||
**Applicable column types**: Data types except for timestamp, binary, nchar and bool
|
||||
|
||||
**Applicable table types**:table, STable
|
||||
**Applicable table types**: table, STable
|
||||
|
||||
**More explanations**:
|
||||
|
||||
|
@ -113,13 +113,13 @@ SELECT IRATE(field_name) FROM tb_name WHERE clause;
|
|||
SELECT SUM(field_name) FROM tb_name [WHERE clause];
|
||||
```
|
||||
|
||||
**Description**:The sum of a specific column in a table or STable
|
||||
**Description**: The sum of a specific column in a table or STable
|
||||
|
||||
**Return value type**:Double precision floating number or long integer
|
||||
**Return value type**: Double precision floating number or long integer
|
||||
|
||||
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
|
||||
**Applicable column types**: Data types except for timestamp, binary, nchar and bool
|
||||
|
||||
**Applicable table types**:table, STable
|
||||
**Applicable table types**: table, STable
|
||||
|
||||
**Examples**:
|
||||
|
||||
|
@ -143,13 +143,13 @@ Query OK, 1 row(s) in set (0.000980s)
|
|||
SELECT STDDEV(field_name) FROM tb_name [WHERE clause];
|
||||
```
|
||||
|
||||
**Description**:Standard deviation of a specific column in a table or STable
|
||||
**Description**: Standard deviation of a specific column in a table or STable
|
||||
|
||||
**Return value type**:Double precision floating number
|
||||
**Return value type**: Double precision floating number
|
||||
|
||||
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
|
||||
**Applicable column types**: Data types except for timestamp, binary, nchar and bool
|
||||
|
||||
**Applicable table types**:table, STable (starting from version 2.0.15.1)
|
||||
**Applicable table types**: table, STable (starting from version 2.0.15.1)
|
||||
|
||||
**Examples**:
|
||||
|
||||
|
@ -261,7 +261,7 @@ Query OK, 1 row(s) in set (0.008388s)
|
|||
|
||||
## Selection Functions
|
||||
|
||||
When any selective function is used, timestamp column or tag columns including `tbname` can be specified to show that the selected value are from which rows.
|
||||
When any select function is used, timestamp column or tag columns including `tbname` can be specified to show that the selected value are from which rows.
|
||||
|
||||
### MIN
|
||||
|
||||
|
@ -269,13 +269,13 @@ When any selective function is used, timestamp column or tag columns including `
|
|||
SELECT MIN(field_name) FROM {tb_name | stb_name} [WHERE clause];
|
||||
```
|
||||
|
||||
**Description**:The minimum value of a specific column in a table or STable
|
||||
**Description**: The minimum value of a specific column in a table or STable
|
||||
|
||||
**Return value type**:Same as the data type of the column being operated
|
||||
**Return value type**: Same as the data type of the column being operated
|
||||
|
||||
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
|
||||
**Applicable column types**: Data types except for timestamp, binary, nchar and bool
|
||||
|
||||
**Applicable table types**:table, STable
|
||||
**Applicable table types**: table, STable
|
||||
|
||||
**Examples**:
|
||||
|
||||
|
@ -299,13 +299,13 @@ Query OK, 1 row(s) in set (0.000950s)
|
|||
SELECT MAX(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
```
|
||||
|
||||
**Description**:The maximum value of a specific column of a table or STable
|
||||
**Description**: The maximum value of a specific column of a table or STable
|
||||
|
||||
**Return value type**:Same as the data type of the column being operated
|
||||
**Return value type**: Same as the data type of the column being operated
|
||||
|
||||
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
|
||||
**Applicable column types**: Data types except for timestamp, binary, nchar and bool
|
||||
|
||||
**Applicable table types**:table, STable
|
||||
**Applicable table types**: table, STable
|
||||
|
||||
**Examples**:
|
||||
|
||||
|
@ -329,13 +329,13 @@ Query OK, 1 row(s) in set (0.000987s)
|
|||
SELECT FIRST(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
```
|
||||
|
||||
**Description**:The first non-null value of a specific column in a table or STable
|
||||
**Description**: The first non-null value of a specific column in a table or STable
|
||||
|
||||
**Return value type**:Same as the column being operated
|
||||
**Return value type**: Same as the column being operated
|
||||
|
||||
**Applicable column types**:Any data type
|
||||
**Applicable column types**: Any data type
|
||||
|
||||
**Applicable table types**:table, STable
|
||||
**Applicable table types**: table, STable
|
||||
|
||||
**More explanations**:
|
||||
|
||||
|
@ -365,13 +365,13 @@ Query OK, 1 row(s) in set (0.001023s)
|
|||
SELECT LAST(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
||||
```
|
||||
|
||||
**Description**:The last non-NULL value of a specific column in a table or STable
|
||||
**Description**: The last non-NULL value of a specific column in a table or STable
|
||||
|
||||
**Return value type**:Same as the column being operated
|
||||
**Return value type**: Same as the column being operated
|
||||
|
||||
**Applicable column types**:Any data type
|
||||
**Applicable column types**: Any data type
|
||||
|
||||
**Applicable table types**:table, STable
|
||||
**Applicable table types**: table, STable
|
||||
|
||||
**More explanations**:
|
||||
|
||||
|
@ -403,11 +403,11 @@ SELECT TOP(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
|
|||
|
||||
**Description**: The greatest _k_ values of a specific column in a table or STable. If a value has multiple occurrences in the column but counting all of them in will exceed the upper limit _k_, then a part of them will be returned randomly.
|
||||
|
||||
**Return value type**:Same as the column being operated
|
||||
**Return value type**: Same as the column being operated
|
||||
|
||||
**Applicable column types**:Data types except for timestamp, binary, nchar and bool
|
||||
**Applicable column types**: Data types except for timestamp, binary, nchar and bool
|
||||
|
||||
**Applicable table types**:table, STable
|
||||
**Applicable table types**: table, STable
|
||||
|
||||
**More explanations**:
|
||||
|
||||
|
@ -440,9 +440,9 @@ Query OK, 2 row(s) in set (0.000810s)
|
|||
SELECT BOTTOM(field_name, K) FROM { tb_name | stb_name } [WHERE clause];
|
||||
```
|
||||
|
||||
**Description**:The least _k_ values of a specific column in a table or STable. If a value has multiple occurrences in the column but counting all of them in will exceed the upper limit _k_, then a part of them will be returned randomly.
|
||||
**Description**: The least _k_ values of a specific column in a table or STable. If a value has multiple occurrences in the column but counting all of them in will exceed the upper limit _k_, then a part of them will be returned randomly.
|
||||
|
||||
**Return value type**:Same as the column being operated
|
||||
**Return value type**: Same as the column being operated
|
||||
|
||||
**Applicable column types**: Data types except for timestamp, binary, nchar and bool
|
||||
|
||||
|
@ -584,7 +584,7 @@ SELECT INTERP(field_name) FROM { tb_name | stb_name } [WHERE where_condition] [
|
|||
|
||||
**Description**: The value that matches the specified timestamp range is returned, if existing; or an interpolation value is returned.
|
||||
|
||||
**Return value type**: same as the column being operated
|
||||
**Return value type**: Same as the column being operated
|
||||
|
||||
**Applicable column types**: Numeric data types
|
||||
|
||||
|
@ -608,7 +608,7 @@ SELECT INTERP(field_name) FROM { tb_name | stb_name } [WHERE where_condition] [
|
|||
taos> SELECT INTERP(current) FROM t1 RANGE('2017-7-14 18:40:00','2017-7-14 18:40:00') FILL(LINEAR);
|
||||
```
|
||||
|
||||
- Get an original data every 5 seconds, no interpolation, between "2017-07-14 18:00:00" and "2017-07-14 19:00:00:
|
||||
- Get original data every 5 seconds, no interpolation, between "2017-07-14 18:00:00" and "2017-07-14 19:00:00:
|
||||
|
||||
```
|
||||
taos> SELECT INTERP(current) FROM t1 RANGE('2017-7-14 18:00:00','2017-7-14 19:00:00') EVERY(5s);
|
||||
|
@ -662,7 +662,7 @@ SELECT INTERP(field_name) FROM { tb_name | stb_name } WHERE ts='timestamp' [FILL
|
|||
Query OK, 1 row(s) in set (0.002652s)
|
||||
```
|
||||
|
||||
If there is not any data corresponding to the specified timestamp, an interpolation value is returned if interpolation policy is specified by `FILL` parameter; or nothing is returned\
|
||||
If there is no data corresponding to the specified timestamp, an interpolation value is returned if interpolation policy is specified by `FILL` parameter; or nothing is returned.
|
||||
|
||||
```
|
||||
taos> SELECT INTERP(*) FROM meters WHERE tbname IN ('d636') AND ts='2017-7-14 18:40:00.005';
|
||||
|
@ -819,7 +819,7 @@ SELECT DERIVATIVE(field_name, time_interval, ignore_negative) FROM tb_name [WHER
|
|||
|
||||
**More explanations**:
|
||||
|
||||
- It is available from version 2.1.3.0, the number of result rows is the number of total rows in the time range subtracted by one, no output for the first row.\
|
||||
- It is available from version 2.1.3.0, the number of result rows is the number of total rows in the time range subtracted by one, no output for the first row.
|
||||
- It can be used together with `GROUP BY tbname` against a STable.
|
||||
|
||||
**Examples**:
|
||||
|
@ -882,7 +882,7 @@ SELECT CEIL(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
|||
|
||||
**Applicable table types**: table, STable
|
||||
|
||||
**Applicable nested query**: inner query and outer query
|
||||
**Applicable nested query**: Inner query and outer query
|
||||
|
||||
**More explanations**:
|
||||
|
||||
|
|
|
@ -8,11 +8,11 @@ Window related clauses are used to divide the data set to be queried into subset
|
|||
|
||||
## Time Window
|
||||
|
||||
`INTERVAL` clause is used to generate time windows of same time interval, `SLIDING` is used to specify the time step for which the time window moves forward. The query is performed on one time window each time, and the time window moves forward with time. When defining continuous query both the size of time window and the step of forward sliding time need to be specified. As shown in the figure blow, [t0s, t0e] ,[t1s , t1e], [t2s, t2e] are respectively the time range of three time windows on which continuous queries are executed. The time step for which time window moves forward is marked by `sliding time`. Query, filter and aggregate operations are executed on each time window respectively. When the time step specified by `SLIDING` is same as the time interval specified by `INTERVAL`, the sliding time window is actually a flip time window.
|
||||
`INTERVAL` clause is used to generate time windows of the same time interval, `SLIDING` is used to specify the time step for which the time window moves forward. The query is performed on one time window each time, and the time window moves forward with time. When defining continuous query both the size of time window and the step of forward sliding time need to be specified. As shown in the figure blow, [t0s, t0e] ,[t1s , t1e], [t2s, t2e] are respectively the time ranges of three time windows on which continuous queries are executed. The time step for which time window moves forward is marked by `sliding time`. Query, filter and aggregate operations are executed on each time window respectively. When the time step specified by `SLIDING` is same as the time interval specified by `INTERVAL`, the sliding time window is actually a flip time window.
|
||||
|
||||

|
||||
|
||||
`INTERVAL` and `SLIDING` should be used with aggregate functions and selection functions. Below SQL statement is illegal because no aggregate or selection function is used with `INTERVAL`.
|
||||
`INTERVAL` and `SLIDING` should be used with aggregate functions and select functions. Below SQL statement is illegal because no aggregate or selection function is used with `INTERVAL`.
|
||||
|
||||
```
|
||||
SELECT * FROM temp_tb_1 INTERVAL(1m);
|
||||
|
@ -24,11 +24,11 @@ The time step specified by `SLIDING` can't exceed the time interval specified by
|
|||
SELECT COUNT(*) FROM temp_tb_1 INTERVAL(1m) SLIDING(2m);
|
||||
```
|
||||
|
||||
When the time length specified by `SLIDING` is same as that specified by `INTERVAL`, sliding window is actually flip window. The minimum time range specified by `INTERVAL` is 10 milliseconds (10a) prior to version 2.1.5.0. From version 2.1.5.0, the minimum time range by `INTERVAL` can be 1 microsecond (1u). However, if the DB precision is millisecond, the minimum time range is 1 millisecond (1a). Please be noted that the `timezone` parameter should be configured to same value in the `taos.cfg` configuration file on client side and server side.
|
||||
When the time length specified by `SLIDING` is the same as that specified by `INTERVAL`, the sliding window is actually a flip window. The minimum time range specified by `INTERVAL` is 10 milliseconds (10a) prior to version 2.1.5.0. From version 2.1.5.0, the minimum time range by `INTERVAL` can be 1 microsecond (1u). However, if the DB precision is millisecond, the minimum time range is 1 millisecond (1a). Please note that the `timezone` parameter should be configured to be the same value in the `taos.cfg` configuration file on client side and server side.
|
||||
|
||||
## Status Window
|
||||
|
||||
In case of using integer, bool, or string to represent the device status at a moment, the continuous rows with same status belong to same status window. Once the status changes, the status window closes. As shown in the following figure,there are two status windows according to status, [2019-04-28 14:22:07,2019-04-28 14:22:10] and [2019-04-28 14:22:11,2019-04-28 14:22:12]. Status window is not applicable to STable for now.
|
||||
In case of using integer, bool, or string to represent the device status at a moment, the continuous rows with same status belong to same status window. Once the status changes, the status window closes. As shown in the following figure, there are two status windows according to status, [2019-04-28 14:22:07,2019-04-28 14:22:10] and [2019-04-28 14:22:11,2019-04-28 14:22:12]. Status window is not applicable to STable for now.
|
||||
|
||||

|
||||
|
||||
|
@ -44,7 +44,7 @@ SELECT COUNT(*), FIRST(ts), status FROM temp_tb_1 STATE_WINDOW(status);
|
|||
SELECT COUNT(*), FIRST(ts) FROM temp_tb_1 SESSION(ts, tol_val);
|
||||
```
|
||||
|
||||
The primary key, i.e. timestamp, is used to determine which session window the row belongs to. If the time interval between two adjacent rows is within the time range specified by `tol_val`, they belong to same session window; otherwise they belong to two different time windows. As shown in the figure below, if the limit of time interval for 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.
|
||||
The primary key, i.e. timestamp, is used to determine which session window the row belongs to. If the time interval between two adjacent rows is within the time range specified by `tol_val`, they belong to the same session window; otherwise they belong to two different time windows. 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.
|
||||
|
||||

|
||||
|
||||
|
@ -54,7 +54,7 @@ If the time interval between two continuous rows are within the time interval sp
|
|||
|
||||
### Syntax
|
||||
|
||||
The full syntax of aggregate by window is as following:
|
||||
The full syntax of aggregate by window is as follows:
|
||||
|
||||
```sql
|
||||
SELECT function_list FROM tb_name
|
||||
|
@ -73,11 +73,11 @@ SELECT function_list FROM stb_name
|
|||
|
||||
### Restrictions
|
||||
|
||||
- Aggregate functions and selection functions can be used in `function_list`, with each function having only one output, for example COUNT, AVG, SUM, STDDEV, LEASTSQUARES, PERCENTILE, MIN, MAX, FIRST, LAST. Functions having multiple output can't be used, for example DIFF or arithmetic operations.
|
||||
- Aggregate functions and select functions can be used in `function_list`, with each function having only one output, for example COUNT, AVG, SUM, STDDEV, LEASTSQUARES, PERCENTILE, MIN, MAX, FIRST, LAST. Functions having multiple output can't be used, for example DIFF or arithmetic operations.
|
||||
- `LAST_ROW` can't be used together with window aggregate.
|
||||
- Scalar functions, like CEIL/FLOOR, can't be used with window aggregate.
|
||||
- `WHERE` clause can be used to specify the starting and ending time and other filter conditions
|
||||
- `FILL` clause is used to specify how to fill when there is data missing in any window, including: \
|
||||
- `FILL` clause is used to specify how to fill when there is data missing in any window, including:
|
||||
1. NONE: No fill (the default fill mode)
|
||||
2. VALUE:Fill with a fixed value, which should be specified together, for example `FILL(VALUE, 1.23)`
|
||||
3. PREV:Fill with the previous non-NULL value, `FILL(PREV)`
|
||||
|
@ -88,21 +88,22 @@ SELECT function_list FROM stb_name
|
|||
:::info
|
||||
|
||||
1. Huge volume of interpolation output may be returned using `FILL`, so it's recommended to specify the time range when using `FILL`. The maximum interpolation values that can be returned in single query is 10,000,000.
|
||||
2. The result set is in the ascending order of timestamp in aggregate by time window aggregate.
|
||||
2. The result set is in ascending order of timestamp in aggregate by time window aggregate.
|
||||
3. If aggregate by window is used on STable, the aggregate function is performed on all the rows matching the filter conditions. If `GROUP BY` is not used in the query, the result set will be returned in ascending order of timestamp; otherwise the result set is not exactly in the order of ascending timestamp in each group.
|
||||
:::
|
||||
|
||||
:::
|
||||
|
||||
Aggregate by time window is also used in continuous query, please refer to [Continuous Query](/develop/continuous-query).
|
||||
|
||||
## Examples
|
||||
|
||||
The table of intelligent meters can be created like below SQL statement:
|
||||
The table of intelligent meters can be created by the SQL statement below:
|
||||
|
||||
```sql
|
||||
CREATE TABLE meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT);
|
||||
```
|
||||
|
||||
The average current, maximum current and median of current in every 10 minutes of the past 24 hours can be calculated using below SQL statement, with missing value filled with the previous non-NULL value.
|
||||
The average current, maximum current and median of current in every 10 minutes for the past 24 hours can be calculated using the below SQL statement, with missing values filled with the previous non-NULL values.
|
||||
|
||||
```
|
||||
SELECT AVG(current), MAX(current), APERCENTILE(current, 50) FROM meters
|
||||
|
|
|
@ -5,8 +5,8 @@ title: Limits & Restrictions
|
|||
## Naming Rules
|
||||
|
||||
1. Only English characters, digits and underscore are allowed
|
||||
2. Can't be started with digits
|
||||
3. Case Insensitive without escape character "\`"
|
||||
2. Can't start with a digit
|
||||
3. Case insensitive without escape character "\`"
|
||||
4. Identifier with escape character "\`"
|
||||
To support more flexible table or column names, a new escape character "\`" is introduced. For more details please refer to [escape](/taos-sql/escape).
|
||||
|
||||
|
@ -18,7 +18,7 @@ The legal character set is `[a-zA-Z0-9!?$%^&*()_–+={[}]:;@~#|<,>.?/]`.
|
|||
|
||||
- Maximum length of database name is 32 bytes
|
||||
- Maximum length of table name is 192 bytes, excluding the database name prefix and the separator
|
||||
- Maximum length of each data row is 48K bytes from version 2.1.7.0 , before which the limit is 16K bytes. Please be noted that the upper limit includes the extra 2 bytes consumed by each column of BINARY/NCHAR type.
|
||||
- Maximum length of each data row is 48K bytes from version 2.1.7.0 , before which the limit is 16K bytes. Please note that the upper limit includes the extra 2 bytes consumed by each column of BINARY/NCHAR type.
|
||||
- Maximum of column name is 64.
|
||||
- Maximum number of columns is 4096. There must be at least 2 columns, and the first column must be timestamp.
|
||||
- Maximum length of tag name is 64.
|
||||
|
@ -26,7 +26,7 @@ The legal character set is `[a-zA-Z0-9!?$%^&*()_–+={[}]:;@~#|<,>.?/]`.
|
|||
- Maximum length of singe SQL statement is 1048576, i.e. 1 MB bytes. It can be configured in the parameter `maxSQLLength` in the client side, the applicable range is [65480, 1048576].
|
||||
- At most 4096 columns (or 1024 prior to 2.1.7.0) can be returned by `SELECT`, functions in the query statement may constitute columns. Error will be returned if the limit is exceeded.
|
||||
- Maximum numbers of databases, STables, tables are only depending on the system resources.
|
||||
- Maximum of database name is 32 bytes, can't include "." and special characters.
|
||||
- Maximum of database name is 32 bytes, and it can't include "." or special characters.
|
||||
- Maximum replica number of database is 3
|
||||
- Maximum length of user name is 23 bytes
|
||||
- Maximum length of password is 15 bytes
|
||||
|
@ -37,7 +37,7 @@ The legal character set is `[a-zA-Z0-9!?$%^&*()_–+={[}]:;@~#|<,>.?/]`.
|
|||
|
||||
## Restrictions of `GROUP BY`
|
||||
|
||||
`GROUP BY` can be performed on tags and `TBNAME`. It can be performed on data columns too, with one restriction that only one column and the number of unique values on that column is lower than 100,000. Please be noted that `GROUP BY` can't be performed on float or double type.
|
||||
`GROUP BY` can be performed on tags and `TBNAME`. It can be performed on data columns too, with one restriction that only one column and the number of unique values on that column is lower than 100,000. Please note that `GROUP BY` can't be performed on float or double types.
|
||||
|
||||
## Restrictions of `IS NOT NULL`
|
||||
|
||||
|
@ -45,7 +45,7 @@ The legal character set is `[a-zA-Z0-9!?$%^&*()_–+={[}]:;@~#|<,>.?/]`.
|
|||
|
||||
## Restrictions of `ORDER BY`
|
||||
|
||||
- Only one `order by` is allowed for normal table and sub table.
|
||||
- Only one `order by` is allowed for normal table and subtable.
|
||||
- At most two `order by` are allowed for STable, and the second one must be `ts`.
|
||||
- `order by tag` must be used with `group by tag` on same tag, this rule is also applicable to `tbname`.
|
||||
- `order by column` must be used with `group by column` or `top/bottom` on same column. This rule is applicable to table and STable.
|
||||
|
@ -56,11 +56,11 @@ The legal character set is `[a-zA-Z0-9!?$%^&*()_–+={[}]:;@~#|<,>.?/]`.
|
|||
|
||||
### Name Restrictions of Table/Column
|
||||
|
||||
The name of a table or column can only be composed of ASCII characters, digits and underscore, while digit can't be used as the beginning. The maximum length is 192 bytes. Names are case insensitive. The name mentioned in this rule doesn't include the database name prefix and the separator.
|
||||
The name of a table or column can only be composed of ASCII characters, digits and underscore, while it can't start with a digit. The maximum length is 192 bytes. Names are case insensitive. The name mentioned in this rule doesn't include the database name prefix and the separator.
|
||||
|
||||
### Name Restrictions After Escaping
|
||||
|
||||
To support more flexible table or column names, new escape character "`" is introduced in TDengine to avoid the conflict between table name and keywords and break the above restrictions for table name. The escape character is not counted in the length of table name.
|
||||
To support more flexible table or column names, new escape character "\`" is introduced in TDengine to avoid the conflict between table name and keywords and break the above restrictions for table names. The escape character is not counted in the length of table name.
|
||||
|
||||
With escaping, the string inside escape characters are case sensitive, i.e. will not be converted to lower case internally.
|
||||
|
||||
|
|
|
@ -52,13 +52,13 @@ title: JSON Type
|
|||
|
||||
4. Tag Operations
|
||||
|
||||
The value of JSON tag can be altered. Please be noted that the full JSON will be override when doing this.
|
||||
The value of JSON tag can be altered. Please note that the full JSON will be overriden when doing this.
|
||||
|
||||
The name of JSON tag can be altered. A tag of JSON type can't be added or removed. The column length of a JSON tag can't be changed.
|
||||
|
||||
## Other Restrictions
|
||||
|
||||
- JSON type can only be used for tag. There can be only one tag of JSON type, and it's exclusive to any other types of tag.
|
||||
- JSON type can only be used for a tag. There can be only one tag of JSON type, and it's exclusive to any other types of tags.
|
||||
|
||||
- The maximum length of keys in JSON is 256 bytes, and key must be printable ASCII characters. The maximum total length of a JSON is 4,096 bytes.
|
||||
|
||||
|
@ -74,7 +74,7 @@ title: JSON Type
|
|||
|
||||
- If a tag of JSON is the result of inner query, it can't be parsed and queried in the outer query.
|
||||
|
||||
For example, below SQL statements are not supported.
|
||||
For example, the below SQL statements are not supported.
|
||||
|
||||
```sql;
|
||||
select jtag->'key' from (select jtag from STable);
|
||||
|
|
|
@ -6,7 +6,7 @@ description: Install, Uninstall, Start, Stop and Upgrade
|
|||
import Tabs from "@theme/Tabs";
|
||||
import TabItem from "@theme/TabItem";
|
||||
|
||||
TDengine community version provides dev and rpm package for users to choose based on the system environment. deb supports Debian, Ubuntu and systems derived from them. rpm supports CentOS, RHEL, SUSE and systems derived from them. Furthermore, tar.gz package is provided for enterprise customers.
|
||||
TDengine community version provides dev and rpm packages for users to choose based on the system environment. deb supports Debian, Ubuntu and systems derived from them. rpm supports CentOS, RHEL, SUSE and systems derived from them. Furthermore, tar.gz package is provided for enterprise customers.
|
||||
|
||||
## Install
|
||||
|
||||
|
@ -14,7 +14,7 @@ TDengine community version provides dev and rpm package for users to choose base
|
|||
<TabItem label="Install Deb" value="debinst">
|
||||
|
||||
1. Download deb package from official website, for example TDengine-server-2.4.0.7-Linux-x64.deb
|
||||
2. In the directory where the package is located, execute below command
|
||||
2. In the directory where the package is located, execute the command below
|
||||
|
||||
```bash
|
||||
$ sudo dpkg -i TDengine-server-2.4.0.7-Linux-x64.deb
|
||||
|
@ -46,7 +46,7 @@ TDengine is installed successfully!
|
|||
<TabItem label="Install RPM" value="rpminst">
|
||||
|
||||
1. Download rpm package from official website, for example TDengine-server-2.4.0.7-Linux-x64.rpm;
|
||||
2. In the directory where the package is located, execute below command
|
||||
2. In the directory where the package is located, execute the command below
|
||||
|
||||
```
|
||||
$ sudo rpm -ivh TDengine-server-2.4.0.7-Linux-x64.rpm
|
||||
|
@ -77,7 +77,7 @@ TDengine is installed successfully!
|
|||
<TabItem label="Install tar.gz" value="tarinst">
|
||||
|
||||
1. Download the tar.gz package, for example TDengine-server-2.4.0.7-Linux-x64.tar.gz;
|
||||
2、In the directory where the package is located, firstly decompress the file, then switch to the sub-directory generated in decompressing, i.e. "TDengine-enterprise-server-2.4.0.7/" in this example, and execute the `install.sh` script.
|
||||
2. In the directory where the package is located, first decompress the file, then switch to the sub-directory generated in decompressing, i.e. "TDengine-enterprise-server-2.4.0.7/" in this example, and execute the `install.sh` script.
|
||||
|
||||
```bash
|
||||
$ tar xvzf TDengine-enterprise-server-2.4.0.7-Linux-x64.tar.gz
|
||||
|
@ -132,7 +132,7 @@ Some configuration will be prompted for users to provide when install.sh is exec
|
|||
</Tabs>
|
||||
|
||||
:::note
|
||||
When installing on the first node in the cluster, when "Enter FQDN:" is prompted, nothing needs to be provided. When installing on following nodes, when "Enter FQDN:" is prompted, the end point of the first dnode in the cluster can be input if it has been already up; or just ignore it and configure later after installation is done.
|
||||
When installing on the first node in the cluster, when "Enter FQDN:" is prompted, nothing needs to be provided. When installing on following nodes, when "Enter FQDN:" is prompted, the end point of the first dnode in the cluster can be input if it is already up; or just ignore it and configure later after installation is done.
|
||||
|
||||
:::
|
||||
|
||||
|
@ -181,14 +181,14 @@ taosKeeper is removed successfully!
|
|||
|
||||
:::note
|
||||
|
||||
- It's strongly suggested not to use multiple kinds of installation packages on single host TDengine
|
||||
- After deb package is installed, if the installation directory is removed manually so that uninstall or reinstall can't succeed, it can be resolved by cleaning up TDengine package information as below command and then reinstalling.
|
||||
- It's strongly suggested not to use multiple kinds of installation packages on a single host TDengine
|
||||
- After deb package is installed, if the installation directory is removed manually so that uninstall or reinstall can't succeed, it can be resolved by cleaning up TDengine package information as in the command below and then reinstalling.
|
||||
|
||||
```bash
|
||||
$ sudo rm -f /var/lib/dpkg/info/tdengine*
|
||||
```
|
||||
|
||||
- After rpm package is installed, if the installation directory is removed manually so that uninstall or reinstall can't succeed, it can be resolved by cleaning up TDengine package information as below command and then reinstalling.
|
||||
- After rpm package is installed, if the installation directory is removed manually so that uninstall or reinstall can't succeed, it can be resolved by cleaning up TDengine package information as in the command below and then reinstalling.
|
||||
|
||||
```bash
|
||||
$ sudo rpm -e --noscripts tdengine
|
||||
|
@ -228,14 +228,14 @@ During the installation process:
|
|||
|
||||
:::note
|
||||
|
||||
- When TDengine is uninstalled, the configuration /etc/taos/taos.cfg, data directory /var/lib/taos, log directory /var/log/taos are kept. They can be deleted manually with caution because data can't be recovered once
|
||||
- When TDengine is uninstalled, the configuration /etc/taos/taos.cfg, data directory /var/lib/taos, log directory /var/log/taos are kept. They can be deleted manually with caution because data can't be recovered
|
||||
- When reinstalling TDengine, if the default configuration file /etc/taos/taos.cfg exists, it will be kept and the configuration file in the installation package will be renamed to taos.cfg.orig and stored at /usr/local/taos/cfg to be used as configuration sample. Otherwise the configuration file in the installation package will be installed to /etc/taos/taos.cfg and used.
|
||||
|
||||
## Start and Stop
|
||||
|
||||
Linux system services `systemd`, `systemctl` or `service` is used to start, stop and restart TDengine. The server process of TDengine is `taosd`, which is started automatically after the Linux system is started. System operator can use `systemd`, `systemctl` or `service` to start, stop or restart TDengine server.
|
||||
Linux system services `systemd`, `systemctl` or `service` are used to start, stop and restart TDengine. The server process of TDengine is `taosd`, which is started automatically after the Linux system is started. System operators can use `systemd`, `systemctl` or `service` to start, stop or restart TDengine server.
|
||||
|
||||
For example, if using `systemctl` , the commands to start, stop, restart and check TDengine server are as below:
|
||||
For example, if using `systemctl` , the commands to start, stop, restart and check TDengine server are below:
|
||||
|
||||
- Start server:`systemctl start taosd`
|
||||
|
||||
|
@ -263,12 +263,12 @@ Active: inactive (dead)
|
|||
|
||||
There are two aspects in upgrade operation: upgrade installation package and upgrade a running server.
|
||||
|
||||
Upgrading package should follow the steps mentioned previously to firstly uninstall old version then install new version.
|
||||
Upgrading package should follow the steps mentioned previously to first uninstall the old version then install the new version.
|
||||
|
||||
Upgrading a running server is much more complex. Firstly please check the version number of old version and new version. The version number of TDengine consists of 4 sections, only the first 3 section match can the old version be upgraded to the new version. The steps of upgrading a running server are as below:
|
||||
Upgrading a running server is much more complex. First please check the version number of the old version and the new version. The version number of TDengine consists of 4 sections, only if the first 3 section match can the old version be upgraded to the new version. The steps of upgrading a running server are as below:
|
||||
|
||||
- Stop inserting data
|
||||
- Make sure all data persisted into disk
|
||||
- Make sure all data are persisted into disk
|
||||
- Stop the cluster of TDengine
|
||||
- Uninstall old version and install new version
|
||||
- Start the cluster of TDengine
|
||||
|
@ -277,6 +277,7 @@ Upgrading a running server is much more complex. Firstly please check the versio
|
|||
- Restore business data
|
||||
|
||||
:::warning
|
||||
|
||||
TDengine doesn't guarantee any lower version is compatible with the data generated by a higher version, so it's never recommended to downgrade the version.
|
||||
|
||||
:::
|
||||
|
|
|
@ -6,7 +6,7 @@ The computing and storage resources need to be planned if using TDengine to buil
|
|||
|
||||
## Memory Requirement of Server Side
|
||||
|
||||
The number of vgroups created for each database is same as the number of CPU cores by default and can be configured by parameter `maxVgroupsPerDb`, each vnode in a vgroup stores one replica. Each vnode consumes fixed size of memory, i.e. `blocks` \* `cache`. Besides, some memory is required for tag values associated with each table. A fixed amount of memory is required for each cluster. So, the memory required for each DB can be calculated using below formula:
|
||||
The number of vgroups created for each database is the same as the number of CPU cores by default and can be configured by parameter `maxVgroupsPerDb`, each vnode in a vgroup stores one replica. Each vnode consumes a fixed size of memory, i.e. `blocks` \* `cache`. Besides, some memory is required for tag values associated with each table. A fixed amount of memory is required for each cluster. So, the memory required for each DB can be calculated using the formula below:
|
||||
|
||||
```
|
||||
Database Memory Size = maxVgroupsPerDb * replica * (blocks * cache + 10MB) + numOfTables * (tagSizePerTable + 0.5KB)
|
||||
|
@ -14,7 +14,7 @@ Database Memory Size = maxVgroupsPerDb * replica * (blocks * cache + 10MB) + num
|
|||
|
||||
For example, assuming the default value of `maxVgroupPerDB` is 64, the default value of `cache` 16M, the default value of `blocks` is 6, there are 100,000 tables in a DB, the replica number is 1, total length of tag values is 256 bytes, the total memory required for this DB is: 64 \* 1 \* (16 \* 6 + 10) + 100000 \* (0.25 + 0.5) / 1000 = 6792M.
|
||||
|
||||
In real operation of TDengine, we are more concerned about the memory used by each TDengine server process `taosd`.
|
||||
In the real operation of TDengine, we are more concerned about the memory used by each TDengine server process `taosd`.
|
||||
|
||||
```
|
||||
taosd_memory = vnode_memory + mnode_memory + query_memory
|
||||
|
@ -25,26 +25,26 @@ In the above formula:
|
|||
1. "vnode_memory" of a `taosd` process is the memory used by all vnodes hosted by this `taosd` process. It can be roughly calculated by firstly adding up the total memory of all DBs whose memory usage can be derived according to the formula mentioned previously then dividing by number of dnodes and multiplying the number of replicas.
|
||||
|
||||
```
|
||||
vnode_memory = sum(Database memory) / number_of_dnodes \* replica
|
||||
vnode_memory = sum(Database memory) / number_of_dnodes * replica
|
||||
```
|
||||
|
||||
2. "mnode_memory" of a `taosd` process is the memory consumed by a mnode. If there is one (and only one) mnode hosted in a `taosd` process, the memory consumed by "mnode" is "0.2KB \* the total number of tables in the cluster".
|
||||
|
||||
3. "query_memory" is the memory used when processing query requests. Each ongoing query consumes at least "0.2 KB \* total number of involved tables".
|
||||
|
||||
Please be noted that the above formulas can only be used to estimate the minimum memory requirement, instead of maximum memory usage. In a real production environment, it's better to preserve some redundance beyond the estimated minimum memory requirement. If memory is abundant, it's suggested to increase the value of parameter `blocks` to speed up data insertion and data query.
|
||||
Please note that the above formulas can only be used to estimate the minimum memory requirement, instead of maximum memory usage. In a real production environment, it's better to reserve some redundance beyond the estimated minimum memory requirement. If memory is abundant, it's suggested to increase the value of parameter `blocks` to speed up data insertion and data query.
|
||||
|
||||
## Memory Requirement of Client Side
|
||||
|
||||
The client programs use TDengine client driver `taosc` to connect to the server side, there is also memory requirement for a client program.
|
||||
For the client programs using TDengine client driver `taosc` to connect to the server side there is a memory requirement as well.
|
||||
|
||||
The memory consumed by a client program is mainly about the SQL statements for data insertion, caching of table metadata, and some internal use. Assuming maximum number of tables is N (the memory consumed by the metadata of each table is 256 bytes), maximum number of threads for parallel insertion is T, maximum length of a SQL statement is S (normally 1 MB), the memory required by a client program can be estimated using below formula:
|
||||
The memory consumed by a client program is mainly about the SQL statements for data insertion, caching of table metadata, and some internal use. Assuming maximum number of tables is N (the memory consumed by the metadata of each table is 256 bytes), maximum number of threads for parallel insertion is T, maximum length of a SQL statement is S (normally 1 MB), the memory required by a client program can be estimated using the below formula:
|
||||
|
||||
```
|
||||
M = (T * S * 3 + (N / 4096) + 100)
|
||||
```
|
||||
|
||||
For example, if the number of parallel data insertion threads is 100, total number of tables is 10,000,000, then minimum memory requirement of a client program is:
|
||||
For example, if the number of parallel data insertion threads is 100, total number of tables is 10,000,000, then the minimum memory requirement of a client program is:
|
||||
|
||||
```
|
||||
100 * 3 + (10000000 / 4096) + 100 = 2741 (MBytes)
|
||||
|
@ -56,10 +56,10 @@ So, at least 3GB needs to be reserved for such a client.
|
|||
|
||||
The CPU resources required depend on two aspects:
|
||||
|
||||
- **Data Insertion** Each dnode of TDengine can process at least 10,000 insertion requests in one second, while each insertion request can have multiple rows. The computing resource consumed between inserting 1 row one time and inserting 10 rows one time is very small. So, the more the rows to insert one time, the higher the efficiency. Inserting in bach also exposes requirement for the client side which needs to cache rows and insert in batch once the cached rows reaches a threshold.
|
||||
- **Data Insertion** Each dnode of TDengine can process at least 10,000 insertion requests in one second, while each insertion request can have multiple rows. The computing resource consumed between inserting 1 row one time and inserting 10 rows one time is very small. So, the more the rows to insert one time, the higher the efficiency. Inserting in bach also exposes requirements for the client side which needs to cache rows and insert in batch once the cached rows reaches a threshold.
|
||||
- **Data Query** High efficiency query is provided in TDengine, but it's hard to estimate the CPU resource required because the queries used in different use cases and the frequency of queries vary significantly. It can only be verified with the query statements, query frequency, data size to be queried, etc provided by user.
|
||||
|
||||
In short words, the CPU resource required for data insertion can be estimated but it's hard to do so for query use cases. In real operation, it's suggested to control CPU usage below 50%. If this threshold is exceeded, it's a reminder for system operator to add more nodes in the cluster to expand resources.
|
||||
In short, the CPU resource required for data insertion can be estimated but it's hard to do so for query use cases. In real operation, it's suggested to control CPU usage below 50%. If this threshold is exceeded, it's a reminder for system operator to add more nodes in the cluster to expand resources.
|
||||
|
||||
## Disk Requirement
|
||||
|
||||
|
@ -69,14 +69,14 @@ The compression ratio in TDengine is much higher than that in RDBMS. In most cas
|
|||
Raw DataSize = numOfTables * rowSizePerTable * rowsPerTable
|
||||
```
|
||||
|
||||
For example, there are 10,000,000 meters, while each meter collects data every 15 minutes and the data size of each collection si 128 bytes, so the raw data size of one year is: 10000000 \* 128 \* 24 \* 60 / 15 \* 365 = 44.8512(TB). Assuming compression ratio is 5, the actual disk size is: 44.851 / 5 = 8.97024(TB).
|
||||
For example, there are 10,000,000 meters, while each meter collects data every 15 minutes and the data size of each collection is 128 bytes, so the raw data size of one year is: 10000000 \* 128 \* 24 \* 60 / 15 \* 365 = 44.8512(TB). Assuming compression ratio is 5, the actual disk size is: 44.851 / 5 = 8.97024(TB).
|
||||
|
||||
Parameter `keep` can be used to set how long the data will be kept on disk. To further reduce storage cost, multiple storage levels can be enabled in TDengine, with the coldest data stored on the cheapest storage device, and this is transparent to application programs.
|
||||
|
||||
To increase the performance, multiple disks can be setup for parallel data reading or data inserting. Please be noted that expensive disk array is not necessary because replications are used in TDengine to provide high availability.
|
||||
To increase the performance, multiple disks can be setup for parallel data reading or data inserting. Please note that an expensive disk array is not necessary because replications are used in TDengine to provide high availability.
|
||||
|
||||
## Number of Hosts
|
||||
|
||||
A host can be either physical or virtual. The total memory, total CPU, total disk required can be estimated according to the formulas mentioned previously. Then, according to the system resources that a single host can provide, assuming all hosts are same in resources, the number of hosts can be derived easily.
|
||||
A host can be either physical or virtual. The total memory, total CPU, total disk required can be estimated according to the formulas mentioned previously. Then, according to the system resources that a single host can provide, assuming all hosts have the same resources, the number of hosts can be derived easily.
|
||||
|
||||
**Quick Estimation for CPU, Memory and Disk** Please refer to [Resource Estimate](https://www.taosdata.com/config/config.html).
|
||||
|
|
|
@ -1,178 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "../../../include/client/taos.h" // include TDengine header file
|
||||
|
||||
typedef struct {
|
||||
char server_ip[64];
|
||||
char db_name[64];
|
||||
char tbl_name[64];
|
||||
} param;
|
||||
|
||||
int g_thread_exit_flag = 0;
|
||||
void* insert_rows(void *sarg);
|
||||
|
||||
void streamCallBack(void *param, TAOS_RES *res, TAOS_ROW row)
|
||||
{
|
||||
// in this simple demo, it just print out the result
|
||||
char temp[128];
|
||||
|
||||
TAOS_FIELD *fields = taos_fetch_fields(res);
|
||||
int numFields = taos_num_fields(res);
|
||||
|
||||
taos_print_row(temp, row, fields, numFields);
|
||||
|
||||
printf("\n%s\n", temp);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
TAOS *taos;
|
||||
char db_name[64];
|
||||
char tbl_name[64];
|
||||
char sql[1024] = { 0 };
|
||||
|
||||
if (argc != 4) {
|
||||
printf("usage: %s server-ip dbname tblname\n", argv[0]);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
strcpy(db_name, argv[2]);
|
||||
strcpy(tbl_name, argv[3]);
|
||||
|
||||
// create pthread to insert into row per second for stream calc
|
||||
param *t_param = (param *)malloc(sizeof(param));
|
||||
if (NULL == t_param)
|
||||
{
|
||||
printf("failed to malloc\n");
|
||||
exit(1);
|
||||
}
|
||||
memset(t_param, 0, sizeof(param));
|
||||
strcpy(t_param->server_ip, argv[1]);
|
||||
strcpy(t_param->db_name, db_name);
|
||||
strcpy(t_param->tbl_name, tbl_name);
|
||||
|
||||
pthread_t pid;
|
||||
pthread_create(&pid, NULL, (void * (*)(void *))insert_rows, t_param);
|
||||
|
||||
sleep(3); // waiting for database is created.
|
||||
// open connection to database
|
||||
taos = taos_connect(argv[1], "root", "taosdata", db_name, 0);
|
||||
if (taos == NULL) {
|
||||
printf("failed to connet to server:%s\n", argv[1]);
|
||||
free(t_param);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// starting stream calc,
|
||||
printf("please input stream SQL:[e.g., select count(*) from tblname interval(5s) sliding(2s);]\n");
|
||||
fgets(sql, sizeof(sql), stdin);
|
||||
if (sql[0] == 0) {
|
||||
printf("input NULL stream SQL, so exit!\n");
|
||||
free(t_param);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// param is set to NULL in this demo, it shall be set to the pointer to app context
|
||||
TAOS_STREAM *pStream = taos_open_stream(taos, sql, streamCallBack, 0, NULL, NULL);
|
||||
if (NULL == pStream) {
|
||||
printf("failed to create stream\n");
|
||||
free(t_param);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("presss any key to exit\n");
|
||||
getchar();
|
||||
|
||||
taos_close_stream(pStream);
|
||||
|
||||
g_thread_exit_flag = 1;
|
||||
pthread_join(pid, NULL);
|
||||
|
||||
taos_close(taos);
|
||||
free(t_param);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void* insert_rows(void *sarg)
|
||||
{
|
||||
TAOS *taos;
|
||||
char command[1024] = { 0 };
|
||||
param *winfo = (param * )sarg;
|
||||
|
||||
if (NULL == winfo){
|
||||
printf("para is null!\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
taos = taos_connect(winfo->server_ip, "root", "taosdata", NULL, 0);
|
||||
if (taos == NULL) {
|
||||
printf("failed to connet to server:%s\n", winfo->server_ip);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// drop database
|
||||
sprintf(command, "drop database %s;", winfo->db_name);
|
||||
if (taos_query(taos, command) != 0) {
|
||||
printf("failed to drop database, reason:%s\n", taos_errstr(taos));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// create database
|
||||
sprintf(command, "create database %s;", winfo->db_name);
|
||||
if (taos_query(taos, command) != 0) {
|
||||
printf("failed to create database, reason:%s\n", taos_errstr(taos));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// use database
|
||||
sprintf(command, "use %s;", winfo->db_name);
|
||||
if (taos_query(taos, command) != 0) {
|
||||
printf("failed to use database, reason:%s\n", taos_errstr(taos));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// create table
|
||||
sprintf(command, "create table %s (ts timestamp, speed int);", winfo->tbl_name);
|
||||
if (taos_query(taos, command) != 0) {
|
||||
printf("failed to create table, reason:%s\n", taos_errstr(taos));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// insert data
|
||||
int64_t begin = (int64_t)time(NULL);
|
||||
int index = 0;
|
||||
while (1) {
|
||||
if (g_thread_exit_flag) break;
|
||||
|
||||
index++;
|
||||
sprintf(command, "insert into %s values (%ld, %d)", winfo->tbl_name, (begin + index) * 1000, index);
|
||||
if (taos_query(taos, command)) {
|
||||
printf("failed to insert row [%s], reason:%s\n", command, taos_errstr(taos));
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
taos_close(taos);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -219,6 +219,16 @@ typedef struct {
|
|||
|
||||
#define GET_FORWARD_DIRECTION_FACTOR(ord) (((ord) == TSDB_ORDER_ASC) ? QUERY_ASC_FORWARD_STEP : QUERY_DESC_FORWARD_STEP)
|
||||
|
||||
#define SORT_QSORT_T 0x1
|
||||
#define SORT_SPILLED_MERGE_SORT_T 0x2
|
||||
typedef struct SSortExecInfo {
|
||||
int32_t sortMethod;
|
||||
int32_t sortBuffer;
|
||||
int32_t loops; // loop count
|
||||
int32_t writeBytes; // write io bytes
|
||||
int32_t readBytes; // read io bytes
|
||||
} SSortExecInfo;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -198,7 +198,7 @@ void colDataTrim(SColumnInfoData* pColumnInfoData);
|
|||
size_t blockDataGetNumOfCols(const SSDataBlock* pBlock);
|
||||
size_t blockDataGetNumOfRows(const SSDataBlock* pBlock);
|
||||
|
||||
int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc, SArray* pIndexMap);
|
||||
int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc);
|
||||
int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startIndex, int32_t* stopIndex,
|
||||
int32_t pageSize);
|
||||
int32_t blockDataToBuf(char* buf, const SSDataBlock* pBlock);
|
||||
|
|
|
@ -61,9 +61,10 @@ int32_t tTSRowBuilderGetRow(STSRowBuilder *pBuilder, const STSRow2 **ppRow);
|
|||
// STag
|
||||
int32_t tTagNew(STagVal *pTagVals, int16_t nTag, STag **ppTag);
|
||||
void tTagFree(STag *pTag);
|
||||
void tTagGet(STag *pTag, int16_t cid, int8_t type, uint8_t **ppData, int32_t *nData);
|
||||
int32_t tEncodeTag(SEncoder *pEncoder, STag *pTag);
|
||||
int32_t tDecodeTag(SDecoder *pDecoder, const STag **ppTag);
|
||||
int32_t tTagSet(STag *pTag, SSchema *pSchema, int32_t nCols, int iCol, uint8_t *pData, uint32_t nData, STag **ppTag);
|
||||
void tTagGet(STag *pTag, int16_t cid, int8_t type, uint8_t **ppData, uint32_t *nData);
|
||||
int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag);
|
||||
int32_t tDecodeTag(SDecoder *pDecoder, STag **ppTag);
|
||||
|
||||
// STRUCT =================
|
||||
struct STColumn {
|
||||
|
|
|
@ -660,8 +660,7 @@ typedef struct {
|
|||
int32_t tz; // query client timezone
|
||||
char intervalUnit;
|
||||
char slidingUnit;
|
||||
char
|
||||
offsetUnit; // TODO Remove it, the offset is the number of precision tickle, and it must be a immutable duration.
|
||||
char offsetUnit;
|
||||
int8_t precision;
|
||||
int64_t interval;
|
||||
int64_t sliding;
|
||||
|
@ -696,6 +695,7 @@ typedef struct {
|
|||
int8_t replications;
|
||||
int8_t strict;
|
||||
int8_t cacheLastRow;
|
||||
int8_t schemaless;
|
||||
int8_t ignoreExist;
|
||||
int32_t numOfRetensions;
|
||||
SArray* pRetensions; // SRetention
|
||||
|
@ -1274,7 +1274,6 @@ int32_t tSerializeSCreateDropMQSBNodeReq(void* buf, int32_t bufLen, SMCreateQnod
|
|||
int32_t tDeserializeSCreateDropMQSBNodeReq(void* buf, int32_t bufLen, SMCreateQnodeReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int32_t dnodeId;
|
||||
int8_t replica;
|
||||
SReplica replicas[TSDB_MAX_REPLICA];
|
||||
} SDCreateMnodeReq, SDAlterMnodeReq;
|
||||
|
|
|
@ -144,6 +144,7 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_MND_CREATE_TOPIC, "mnode-create-topic", SMCreateTopicReq, SMCreateTopicRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_ALTER_TOPIC, "mnode-alter-topic", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_TOPIC, "mnode-drop-topic", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_DROP_CGROUP, "mnode-drop-cgroup", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_SUBSCRIBE, "mnode-subscribe", SCMSubscribeReq, SCMSubscribeRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_ASK_EP, "mnode-mq-ask-ep", SMqAskEpReq, SMqAskEpRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_MND_MQ_TIMER, "mnode-mq-tmr", SMTimerReq, NULL)
|
||||
|
|
|
@ -93,166 +93,168 @@
|
|||
#define TK_VGROUPS 75
|
||||
#define TK_SINGLE_STABLE 76
|
||||
#define TK_RETENTIONS 77
|
||||
#define TK_NK_COLON 78
|
||||
#define TK_TABLE 79
|
||||
#define TK_NK_LP 80
|
||||
#define TK_NK_RP 81
|
||||
#define TK_STABLE 82
|
||||
#define TK_ADD 83
|
||||
#define TK_COLUMN 84
|
||||
#define TK_MODIFY 85
|
||||
#define TK_RENAME 86
|
||||
#define TK_TAG 87
|
||||
#define TK_SET 88
|
||||
#define TK_NK_EQ 89
|
||||
#define TK_USING 90
|
||||
#define TK_TAGS 91
|
||||
#define TK_COMMENT 92
|
||||
#define TK_BOOL 93
|
||||
#define TK_TINYINT 94
|
||||
#define TK_SMALLINT 95
|
||||
#define TK_INT 96
|
||||
#define TK_INTEGER 97
|
||||
#define TK_BIGINT 98
|
||||
#define TK_FLOAT 99
|
||||
#define TK_DOUBLE 100
|
||||
#define TK_BINARY 101
|
||||
#define TK_TIMESTAMP 102
|
||||
#define TK_NCHAR 103
|
||||
#define TK_UNSIGNED 104
|
||||
#define TK_JSON 105
|
||||
#define TK_VARCHAR 106
|
||||
#define TK_MEDIUMBLOB 107
|
||||
#define TK_BLOB 108
|
||||
#define TK_VARBINARY 109
|
||||
#define TK_DECIMAL 110
|
||||
#define TK_DELAY 111
|
||||
#define TK_FILE_FACTOR 112
|
||||
#define TK_NK_FLOAT 113
|
||||
#define TK_ROLLUP 114
|
||||
#define TK_TTL 115
|
||||
#define TK_SMA 116
|
||||
#define TK_SHOW 117
|
||||
#define TK_DATABASES 118
|
||||
#define TK_TABLES 119
|
||||
#define TK_STABLES 120
|
||||
#define TK_MNODES 121
|
||||
#define TK_MODULES 122
|
||||
#define TK_QNODES 123
|
||||
#define TK_FUNCTIONS 124
|
||||
#define TK_INDEXES 125
|
||||
#define TK_ACCOUNTS 126
|
||||
#define TK_APPS 127
|
||||
#define TK_CONNECTIONS 128
|
||||
#define TK_LICENCE 129
|
||||
#define TK_GRANTS 130
|
||||
#define TK_QUERIES 131
|
||||
#define TK_SCORES 132
|
||||
#define TK_TOPICS 133
|
||||
#define TK_VARIABLES 134
|
||||
#define TK_BNODES 135
|
||||
#define TK_SNODES 136
|
||||
#define TK_CLUSTER 137
|
||||
#define TK_TRANSACTIONS 138
|
||||
#define TK_LIKE 139
|
||||
#define TK_INDEX 140
|
||||
#define TK_FULLTEXT 141
|
||||
#define TK_FUNCTION 142
|
||||
#define TK_INTERVAL 143
|
||||
#define TK_TOPIC 144
|
||||
#define TK_AS 145
|
||||
#define TK_WITH 146
|
||||
#define TK_SCHEMA 147
|
||||
#define TK_DESC 148
|
||||
#define TK_DESCRIBE 149
|
||||
#define TK_RESET 150
|
||||
#define TK_QUERY 151
|
||||
#define TK_CACHE 152
|
||||
#define TK_EXPLAIN 153
|
||||
#define TK_ANALYZE 154
|
||||
#define TK_VERBOSE 155
|
||||
#define TK_NK_BOOL 156
|
||||
#define TK_RATIO 157
|
||||
#define TK_COMPACT 158
|
||||
#define TK_VNODES 159
|
||||
#define TK_IN 160
|
||||
#define TK_OUTPUTTYPE 161
|
||||
#define TK_AGGREGATE 162
|
||||
#define TK_BUFSIZE 163
|
||||
#define TK_STREAM 164
|
||||
#define TK_INTO 165
|
||||
#define TK_TRIGGER 166
|
||||
#define TK_AT_ONCE 167
|
||||
#define TK_WINDOW_CLOSE 168
|
||||
#define TK_WATERMARK 169
|
||||
#define TK_KILL 170
|
||||
#define TK_CONNECTION 171
|
||||
#define TK_TRANSACTION 172
|
||||
#define TK_MERGE 173
|
||||
#define TK_VGROUP 174
|
||||
#define TK_REDISTRIBUTE 175
|
||||
#define TK_SPLIT 176
|
||||
#define TK_SYNCDB 177
|
||||
#define TK_NULL 178
|
||||
#define TK_NK_QUESTION 179
|
||||
#define TK_NK_ARROW 180
|
||||
#define TK_ROWTS 181
|
||||
#define TK_TBNAME 182
|
||||
#define TK_QSTARTTS 183
|
||||
#define TK_QENDTS 184
|
||||
#define TK_WSTARTTS 185
|
||||
#define TK_WENDTS 186
|
||||
#define TK_WDURATION 187
|
||||
#define TK_CAST 188
|
||||
#define TK_NOW 189
|
||||
#define TK_TODAY 190
|
||||
#define TK_TIMEZONE 191
|
||||
#define TK_COUNT 192
|
||||
#define TK_FIRST 193
|
||||
#define TK_LAST 194
|
||||
#define TK_LAST_ROW 195
|
||||
#define TK_BETWEEN 196
|
||||
#define TK_IS 197
|
||||
#define TK_NK_LT 198
|
||||
#define TK_NK_GT 199
|
||||
#define TK_NK_LE 200
|
||||
#define TK_NK_GE 201
|
||||
#define TK_NK_NE 202
|
||||
#define TK_MATCH 203
|
||||
#define TK_NMATCH 204
|
||||
#define TK_CONTAINS 205
|
||||
#define TK_JOIN 206
|
||||
#define TK_INNER 207
|
||||
#define TK_SELECT 208
|
||||
#define TK_DISTINCT 209
|
||||
#define TK_WHERE 210
|
||||
#define TK_PARTITION 211
|
||||
#define TK_BY 212
|
||||
#define TK_SESSION 213
|
||||
#define TK_STATE_WINDOW 214
|
||||
#define TK_SLIDING 215
|
||||
#define TK_FILL 216
|
||||
#define TK_VALUE 217
|
||||
#define TK_NONE 218
|
||||
#define TK_PREV 219
|
||||
#define TK_LINEAR 220
|
||||
#define TK_NEXT 221
|
||||
#define TK_GROUP 222
|
||||
#define TK_HAVING 223
|
||||
#define TK_ORDER 224
|
||||
#define TK_SLIMIT 225
|
||||
#define TK_SOFFSET 226
|
||||
#define TK_LIMIT 227
|
||||
#define TK_OFFSET 228
|
||||
#define TK_ASC 229
|
||||
#define TK_NULLS 230
|
||||
#define TK_ID 231
|
||||
#define TK_NK_BITNOT 232
|
||||
#define TK_INSERT 233
|
||||
#define TK_VALUES 234
|
||||
#define TK_IMPORT 235
|
||||
#define TK_NK_SEMI 236
|
||||
#define TK_FILE 237
|
||||
#define TK_SCHEMALESS 78
|
||||
#define TK_NK_COLON 79
|
||||
#define TK_TABLE 80
|
||||
#define TK_NK_LP 81
|
||||
#define TK_NK_RP 82
|
||||
#define TK_STABLE 83
|
||||
#define TK_ADD 84
|
||||
#define TK_COLUMN 85
|
||||
#define TK_MODIFY 86
|
||||
#define TK_RENAME 87
|
||||
#define TK_TAG 88
|
||||
#define TK_SET 89
|
||||
#define TK_NK_EQ 90
|
||||
#define TK_USING 91
|
||||
#define TK_TAGS 92
|
||||
#define TK_COMMENT 93
|
||||
#define TK_BOOL 94
|
||||
#define TK_TINYINT 95
|
||||
#define TK_SMALLINT 96
|
||||
#define TK_INT 97
|
||||
#define TK_INTEGER 98
|
||||
#define TK_BIGINT 99
|
||||
#define TK_FLOAT 100
|
||||
#define TK_DOUBLE 101
|
||||
#define TK_BINARY 102
|
||||
#define TK_TIMESTAMP 103
|
||||
#define TK_NCHAR 104
|
||||
#define TK_UNSIGNED 105
|
||||
#define TK_JSON 106
|
||||
#define TK_VARCHAR 107
|
||||
#define TK_MEDIUMBLOB 108
|
||||
#define TK_BLOB 109
|
||||
#define TK_VARBINARY 110
|
||||
#define TK_DECIMAL 111
|
||||
#define TK_DELAY 112
|
||||
#define TK_FILE_FACTOR 113
|
||||
#define TK_NK_FLOAT 114
|
||||
#define TK_ROLLUP 115
|
||||
#define TK_TTL 116
|
||||
#define TK_SMA 117
|
||||
#define TK_SHOW 118
|
||||
#define TK_DATABASES 119
|
||||
#define TK_TABLES 120
|
||||
#define TK_STABLES 121
|
||||
#define TK_MNODES 122
|
||||
#define TK_MODULES 123
|
||||
#define TK_QNODES 124
|
||||
#define TK_FUNCTIONS 125
|
||||
#define TK_INDEXES 126
|
||||
#define TK_ACCOUNTS 127
|
||||
#define TK_APPS 128
|
||||
#define TK_CONNECTIONS 129
|
||||
#define TK_LICENCE 130
|
||||
#define TK_GRANTS 131
|
||||
#define TK_QUERIES 132
|
||||
#define TK_SCORES 133
|
||||
#define TK_TOPICS 134
|
||||
#define TK_VARIABLES 135
|
||||
#define TK_BNODES 136
|
||||
#define TK_SNODES 137
|
||||
#define TK_CLUSTER 138
|
||||
#define TK_TRANSACTIONS 139
|
||||
#define TK_LIKE 140
|
||||
#define TK_INDEX 141
|
||||
#define TK_FULLTEXT 142
|
||||
#define TK_FUNCTION 143
|
||||
#define TK_INTERVAL 144
|
||||
#define TK_TOPIC 145
|
||||
#define TK_AS 146
|
||||
#define TK_CGROUP 147
|
||||
#define TK_WITH 148
|
||||
#define TK_SCHEMA 149
|
||||
#define TK_DESC 150
|
||||
#define TK_DESCRIBE 151
|
||||
#define TK_RESET 152
|
||||
#define TK_QUERY 153
|
||||
#define TK_CACHE 154
|
||||
#define TK_EXPLAIN 155
|
||||
#define TK_ANALYZE 156
|
||||
#define TK_VERBOSE 157
|
||||
#define TK_NK_BOOL 158
|
||||
#define TK_RATIO 159
|
||||
#define TK_COMPACT 160
|
||||
#define TK_VNODES 161
|
||||
#define TK_IN 162
|
||||
#define TK_OUTPUTTYPE 163
|
||||
#define TK_AGGREGATE 164
|
||||
#define TK_BUFSIZE 165
|
||||
#define TK_STREAM 166
|
||||
#define TK_INTO 167
|
||||
#define TK_TRIGGER 168
|
||||
#define TK_AT_ONCE 169
|
||||
#define TK_WINDOW_CLOSE 170
|
||||
#define TK_WATERMARK 171
|
||||
#define TK_KILL 172
|
||||
#define TK_CONNECTION 173
|
||||
#define TK_TRANSACTION 174
|
||||
#define TK_MERGE 175
|
||||
#define TK_VGROUP 176
|
||||
#define TK_REDISTRIBUTE 177
|
||||
#define TK_SPLIT 178
|
||||
#define TK_SYNCDB 179
|
||||
#define TK_NULL 180
|
||||
#define TK_NK_QUESTION 181
|
||||
#define TK_NK_ARROW 182
|
||||
#define TK_ROWTS 183
|
||||
#define TK_TBNAME 184
|
||||
#define TK_QSTARTTS 185
|
||||
#define TK_QENDTS 186
|
||||
#define TK_WSTARTTS 187
|
||||
#define TK_WENDTS 188
|
||||
#define TK_WDURATION 189
|
||||
#define TK_CAST 190
|
||||
#define TK_NOW 191
|
||||
#define TK_TODAY 192
|
||||
#define TK_TIMEZONE 193
|
||||
#define TK_COUNT 194
|
||||
#define TK_FIRST 195
|
||||
#define TK_LAST 196
|
||||
#define TK_LAST_ROW 197
|
||||
#define TK_BETWEEN 198
|
||||
#define TK_IS 199
|
||||
#define TK_NK_LT 200
|
||||
#define TK_NK_GT 201
|
||||
#define TK_NK_LE 202
|
||||
#define TK_NK_GE 203
|
||||
#define TK_NK_NE 204
|
||||
#define TK_MATCH 205
|
||||
#define TK_NMATCH 206
|
||||
#define TK_CONTAINS 207
|
||||
#define TK_JOIN 208
|
||||
#define TK_INNER 209
|
||||
#define TK_SELECT 210
|
||||
#define TK_DISTINCT 211
|
||||
#define TK_WHERE 212
|
||||
#define TK_PARTITION 213
|
||||
#define TK_BY 214
|
||||
#define TK_SESSION 215
|
||||
#define TK_STATE_WINDOW 216
|
||||
#define TK_SLIDING 217
|
||||
#define TK_FILL 218
|
||||
#define TK_VALUE 219
|
||||
#define TK_NONE 220
|
||||
#define TK_PREV 221
|
||||
#define TK_LINEAR 222
|
||||
#define TK_NEXT 223
|
||||
#define TK_GROUP 224
|
||||
#define TK_HAVING 225
|
||||
#define TK_ORDER 226
|
||||
#define TK_SLIMIT 227
|
||||
#define TK_SOFFSET 228
|
||||
#define TK_LIMIT 229
|
||||
#define TK_OFFSET 230
|
||||
#define TK_ASC 231
|
||||
#define TK_NULLS 232
|
||||
#define TK_ID 233
|
||||
#define TK_NK_BITNOT 234
|
||||
#define TK_INSERT 235
|
||||
#define TK_VALUES 236
|
||||
#define TK_IMPORT 237
|
||||
#define TK_NK_SEMI 238
|
||||
#define TK_FILE 239
|
||||
|
||||
#define TK_NK_SPACE 300
|
||||
#define TK_NK_COMMENT 301
|
||||
|
|
|
@ -64,7 +64,7 @@ typedef struct SCatalogReq {
|
|||
} SCatalogReq;
|
||||
|
||||
typedef struct SMetaData {
|
||||
SArray *pTableMeta; // SArray<STableMeta>
|
||||
SArray *pTableMeta; // SArray<STableMeta*>
|
||||
SArray *pDbVgroup; // SArray<SArray<SVgroupInfo>*>
|
||||
SArray *pTableHash; // SArray<SVgroupInfo>
|
||||
SArray *pUdfList; // SArray<SFuncInfo>
|
||||
|
@ -248,6 +248,8 @@ int32_t catalogGetTableHashVgroup(SCatalog* pCatalog, void * pTransporter, const
|
|||
*/
|
||||
int32_t catalogGetAllMeta(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SCatalogReq* pReq, SMetaData* pRsp);
|
||||
|
||||
int32_t catalogAsyncGetAllMeta(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, uint64_t reqId, const SCatalogReq* pReq, catalogCallback fp, void* param, int64_t* jobId);
|
||||
|
||||
int32_t catalogGetQnodeList(SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, SArray* pQnodeList);
|
||||
|
||||
int32_t catalogGetExpiredSTables(SCatalog* pCatalog, SSTableMetaVersion **stables, uint32_t *num);
|
||||
|
@ -267,6 +269,9 @@ int32_t catalogChkAuth(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const
|
|||
int32_t catalogUpdateUserAuthInfo(SCatalog* pCtg, SGetUserAuthRsp* pAuth);
|
||||
|
||||
|
||||
int32_t ctgdLaunchAsyncCall(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, uint64_t reqId);
|
||||
|
||||
|
||||
/**
|
||||
* Destroy catalog and relase all resources
|
||||
*/
|
||||
|
|
|
@ -50,6 +50,7 @@ typedef struct SDatabaseOptions {
|
|||
int32_t numOfVgroups;
|
||||
int8_t singleStable;
|
||||
SNodeList* pRetentions;
|
||||
int8_t schemaless;
|
||||
} SDatabaseOptions;
|
||||
|
||||
typedef struct SCreateDatabaseStmt {
|
||||
|
@ -260,6 +261,13 @@ typedef struct SDropTopicStmt {
|
|||
bool ignoreNotExists;
|
||||
} SDropTopicStmt;
|
||||
|
||||
typedef struct SDropCGroupStmt {
|
||||
ENodeType type;
|
||||
char topicName[TSDB_TABLE_NAME_LEN];
|
||||
char cgroup[TSDB_CGROUP_LEN];
|
||||
bool ignoreNotExists;
|
||||
} SDropCGroupStmt;
|
||||
|
||||
typedef struct SAlterLocalStmt {
|
||||
ENodeType type;
|
||||
char config[TSDB_DNODE_CONFIG_LEN];
|
||||
|
|
|
@ -131,6 +131,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_DROP_MNODE_STMT,
|
||||
QUERY_NODE_CREATE_TOPIC_STMT,
|
||||
QUERY_NODE_DROP_TOPIC_STMT,
|
||||
QUERY_NODE_DROP_CGROUP_STMT,
|
||||
QUERY_NODE_ALTER_LOCAL_STMT,
|
||||
QUERY_NODE_EXPLAIN_STMT,
|
||||
QUERY_NODE_DESCRIBE_STMT,
|
||||
|
@ -243,7 +244,6 @@ typedef struct SNodeList {
|
|||
|
||||
#define SNodeptr void*
|
||||
|
||||
int32_t nodesNodeSize(ENodeType type);
|
||||
SNodeptr nodesMakeNode(ENodeType type);
|
||||
void nodesDestroyNode(SNodeptr pNode);
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ typedef struct SLogicNode {
|
|||
SNodeList* pChildren;
|
||||
struct SLogicNode* pParent;
|
||||
int32_t optimizedFlag;
|
||||
uint8_t precision;
|
||||
} SLogicNode;
|
||||
|
||||
typedef enum EScanType { SCAN_TYPE_TAG = 1, SCAN_TYPE_TABLE, SCAN_TYPE_SYSTEM_TABLE, SCAN_TYPE_STREAM } EScanType;
|
||||
|
@ -61,6 +62,7 @@ typedef struct SJoinLogicNode {
|
|||
SLogicNode node;
|
||||
EJoinType joinType;
|
||||
SNode* pOnConditions;
|
||||
bool isSingleTableJoin;
|
||||
} SJoinLogicNode;
|
||||
|
||||
typedef struct SAggLogicNode {
|
||||
|
|
|
@ -132,6 +132,7 @@ typedef struct STableNode {
|
|||
char tableName[TSDB_TABLE_NAME_LEN];
|
||||
char tableAlias[TSDB_TABLE_NAME_LEN];
|
||||
uint8_t precision;
|
||||
bool singleTable;
|
||||
} STableNode;
|
||||
|
||||
struct STableMeta;
|
||||
|
@ -242,6 +243,7 @@ typedef struct SSelectStmt {
|
|||
bool hasAggFuncs;
|
||||
bool hasRepeatScanFuncs;
|
||||
bool hasIndefiniteRowsFunc;
|
||||
bool hasSelectFunc;
|
||||
bool hasSelectValFunc;
|
||||
} SSelectStmt;
|
||||
|
||||
|
|
|
@ -180,7 +180,7 @@ char* jobTaskStatusStr(int32_t status);
|
|||
|
||||
SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* name);
|
||||
|
||||
extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char** msg, int32_t msgSize, int32_t* msgLen);
|
||||
extern int32_t (*queryBuildMsg[TDMT_MAX])(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallocFp)(int32_t));
|
||||
extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t msgSize);
|
||||
|
||||
#define SET_META_TYPE_NULL(t) (t) = META_TYPE_NULL_TABLE
|
||||
|
|
|
@ -54,8 +54,6 @@ typedef struct SQueryProfileSummary {
|
|||
typedef struct SQueryResult {
|
||||
int32_t code;
|
||||
uint64_t numOfRows;
|
||||
int32_t msgSize;
|
||||
char *msg;
|
||||
void *res;
|
||||
} SQueryResult;
|
||||
|
||||
|
@ -64,6 +62,10 @@ typedef struct STaskInfo {
|
|||
SSubQueryMsg *msg;
|
||||
} STaskInfo;
|
||||
|
||||
typedef void (*schedulerExecCallback)(SQueryResult* pResult, void* param, int32_t code);
|
||||
typedef void (*schedulerFetchCallback)(void* pResult, void* param, int32_t code);
|
||||
|
||||
|
||||
int32_t schedulerInit(SSchedulerCfg *cfg);
|
||||
|
||||
/**
|
||||
|
@ -80,7 +82,8 @@ int32_t schedulerExecJob(void *transport, SArray *nodeList, SQueryPlan *pDag, in
|
|||
* @param pNodeList Qnode/Vnode address list, element is SQueryNodeAddr
|
||||
* @return
|
||||
*/
|
||||
int32_t schedulerAsyncExecJob(void *transport, SArray *pNodeList, SQueryPlan* pDag, const char* sql, int64_t *pJob);
|
||||
int32_t schedulerAsyncExecJob(void *pTrans, SArray *pNodeList, SQueryPlan *pDag, int64_t *pJob, const char *sql,
|
||||
int64_t startTs, schedulerExecCallback fp, void* param);
|
||||
|
||||
/**
|
||||
* Fetch query result from the remote query executor
|
||||
|
@ -90,6 +93,8 @@ int32_t schedulerAsyncExecJob(void *transport, SArray *pNodeList, SQueryPlan* pD
|
|||
*/
|
||||
int32_t schedulerFetchRows(int64_t job, void **data);
|
||||
|
||||
int32_t schedulerAsyncFetchRows(int64_t job, schedulerFetchCallback fp, void* param);
|
||||
|
||||
int32_t schedulerGetTasksStatus(int64_t job, SArray *pSub);
|
||||
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ static FORCE_INLINE void streamDataSubmitRefDec(SStreamDataSubmit* pDataSubmit)
|
|||
if (ref == 0) {
|
||||
taosMemoryFree(pDataSubmit->data);
|
||||
taosMemoryFree(pDataSubmit->dataRef);
|
||||
// taosFreeQitem(pDataSubmit);
|
||||
taosFreeQitem(pDataSubmit);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -89,19 +89,18 @@ typedef struct SRpcInit {
|
|||
typedef struct {
|
||||
void *val;
|
||||
int32_t (*clone)(void *src, void **dst);
|
||||
void (*freeFunc)(const void *arg);
|
||||
} SRpcCtxVal;
|
||||
|
||||
typedef struct {
|
||||
int32_t msgType;
|
||||
void * val;
|
||||
int32_t (*clone)(void *src, void **dst);
|
||||
void (*freeFunc)(const void *arg);
|
||||
} SRpcBrokenlinkVal;
|
||||
|
||||
typedef struct {
|
||||
SHashObj * args;
|
||||
SRpcBrokenlinkVal brokenVal;
|
||||
void (*freeFunc)(const void *arg);
|
||||
} SRpcCtx;
|
||||
|
||||
int32_t rpcInit();
|
||||
|
|
|
@ -313,6 +313,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_VND_INVALID_TABLE_ACTION TAOS_DEF_ERROR_CODE(0, 0x0519)
|
||||
#define TSDB_CODE_VND_COL_ALREADY_EXISTS TAOS_DEF_ERROR_CODE(0, 0x051a)
|
||||
#define TSDB_CODE_VND_TABLE_COL_NOT_EXISTS TAOS_DEF_ERROR_CODE(0, 0x051b)
|
||||
#define TSDB_CODE_VND_READ_END TAOS_DEF_ERROR_CODE(0, 0x051c)
|
||||
|
||||
// tsdb
|
||||
#define TSDB_CODE_TDB_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0600)
|
||||
|
|
|
@ -334,9 +334,12 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_DB_STREAM_MODE_OFF 0
|
||||
#define TSDB_DB_STREAM_MODE_ON 1
|
||||
#define TSDB_DEFAULT_DB_STREAM_MODE 0
|
||||
#define TSDB_DB_SINGLE_STABLE_ON 0
|
||||
#define TSDB_DB_SINGLE_STABLE_OFF 1
|
||||
#define TSDB_DEFAULT_DB_SINGLE_STABLE 0
|
||||
#define TSDB_DB_SINGLE_STABLE_ON 1
|
||||
#define TSDB_DB_SINGLE_STABLE_OFF 0
|
||||
#define TSDB_DEFAULT_DB_SINGLE_STABLE TSDB_DB_SINGLE_STABLE_OFF
|
||||
#define TSDB_DB_SCHEMALESS_ON 1
|
||||
#define TSDB_DB_SCHEMALESS_OFF 0
|
||||
#define TSDB_DEFAULT_DB_SCHEMALESS TSDB_DB_SCHEMALESS_OFF
|
||||
|
||||
#define TSDB_MIN_ROLLUP_FILE_FACTOR 0
|
||||
#define TSDB_MAX_ROLLUP_FILE_FACTOR 1
|
||||
|
|
|
@ -140,7 +140,7 @@ static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) {
|
|||
STscObj *pTscObj = (STscObj *)acquireTscObj(pRsp->connKey.tscRid);
|
||||
if (NULL == pTscObj) {
|
||||
tscDebug("tscObj rid %" PRIx64 " not exist", pRsp->connKey.tscRid);
|
||||
} else {
|
||||
} else {
|
||||
if (pRsp->query->totalDnodes > 1 && !isEpsetEqual(&pTscObj->pAppInfo->mgmtEp.epSet, &pRsp->query->epSet)) {
|
||||
updateEpSet_s(&pTscObj->pAppInfo->mgmtEp, &pRsp->query->epSet);
|
||||
}
|
||||
|
@ -582,8 +582,15 @@ void hbClearReqInfo(SAppHbMgr *pAppHbMgr) {
|
|||
}
|
||||
}
|
||||
|
||||
void hbThreadFuncUnexpectedStopped(void) {
|
||||
atomic_store_8(&clientHbMgr.threadStop, 2);
|
||||
}
|
||||
|
||||
static void *hbThreadFunc(void *param) {
|
||||
setThreadName("hb");
|
||||
#ifdef WINDOWS
|
||||
atexit(hbThreadFuncUnexpectedStopped);
|
||||
#endif
|
||||
while (1) {
|
||||
int8_t threadStop = atomic_val_compare_exchange_8(&clientHbMgr.threadStop, 1, 2);
|
||||
if (1 == threadStop) {
|
||||
|
|
|
@ -292,7 +292,7 @@ void setResPrecision(SReqResultInfo* pResInfo, int32_t precision) {
|
|||
int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList, void** pRes) {
|
||||
void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter;
|
||||
|
||||
SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf};
|
||||
SQueryResult res = {.code = 0, .numOfRows = 0};
|
||||
int32_t code = schedulerExecJob(pTransporter, pNodeList, pDag, &pRequest->body.queryJob, pRequest->sqlstr,
|
||||
pRequest->metric.start, &res);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
|
|
@ -275,8 +275,10 @@ int32_t colDataMergeCol(SColumnInfoData* pColumnInfoData, uint32_t numOfRow1, in
|
|||
|
||||
doBitmapMerge(pColumnInfoData, numOfRow1, pSource, numOfRow2);
|
||||
|
||||
int32_t offset = pColumnInfoData->info.bytes * numOfRow1;
|
||||
memcpy(pColumnInfoData->pData + offset, pSource->pData, pSource->info.bytes * numOfRow2);
|
||||
if (pSource->pData) {
|
||||
int32_t offset = pColumnInfoData->info.bytes * numOfRow1;
|
||||
memcpy(pColumnInfoData->pData + offset, pSource->pData, pSource->info.bytes * numOfRow2);
|
||||
}
|
||||
}
|
||||
|
||||
return numOfRow1 + numOfRow2;
|
||||
|
@ -319,14 +321,16 @@ int32_t colDataAssign(SColumnInfoData* pColumnInfoData, const SColumnInfoData* p
|
|||
pColumnInfoData->nullbitmap = tmp;
|
||||
memcpy(pColumnInfoData->nullbitmap, pSource->nullbitmap, BitmapLen(numOfRows));
|
||||
|
||||
int32_t newSize = numOfRows * pColumnInfoData->info.bytes;
|
||||
tmp = taosMemoryRealloc(pColumnInfoData->pData, newSize);
|
||||
if (tmp == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
if (pSource->pData) {
|
||||
int32_t newSize = numOfRows * pColumnInfoData->info.bytes;
|
||||
tmp = taosMemoryRealloc(pColumnInfoData->pData, newSize);
|
||||
if (tmp == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pColumnInfoData->pData = tmp;
|
||||
memcpy(pColumnInfoData->pData, pSource->pData, pSource->info.bytes * numOfRows);
|
||||
pColumnInfoData->pData = tmp;
|
||||
memcpy(pColumnInfoData->pData, pSource->pData, pSource->info.bytes * numOfRows);
|
||||
}
|
||||
}
|
||||
|
||||
pColumnInfoData->hasNull = pSource->hasNull;
|
||||
|
@ -350,7 +354,7 @@ int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock, int32_t tsColumnIndex)
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t index = (tsColumnIndex == -1)? 0:tsColumnIndex;
|
||||
int32_t index = (tsColumnIndex == -1) ? 0 : tsColumnIndex;
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, index);
|
||||
if (pColInfoData->info.type != TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
return 0;
|
||||
|
@ -361,19 +365,13 @@ int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock, int32_t tsColumnIndex)
|
|||
return 0;
|
||||
}
|
||||
|
||||
// if pIndexMap = NULL, merger one column by on column
|
||||
int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc, SArray* pIndexMap) {
|
||||
int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc) {
|
||||
assert(pSrc != NULL && pDest != NULL);
|
||||
int32_t capacity = pDest->info.capacity;
|
||||
|
||||
for (int32_t i = 0; i < pDest->info.numOfCols; ++i) {
|
||||
int32_t mapIndex = i;
|
||||
// if (pIndexMap) {
|
||||
// mapIndex = *(int32_t*)taosArrayGet(pIndexMap, i);
|
||||
// }
|
||||
|
||||
SColumnInfoData* pCol2 = taosArrayGet(pDest->pDataBlock, i);
|
||||
SColumnInfoData* pCol1 = taosArrayGet(pSrc->pDataBlock, mapIndex);
|
||||
SColumnInfoData* pCol1 = taosArrayGet(pSrc->pDataBlock, i);
|
||||
|
||||
capacity = pDest->info.capacity;
|
||||
colDataMergeCol(pCol2, pDest->info.rows, &capacity, pCol1, pSrc->info.rows);
|
||||
|
@ -605,8 +603,8 @@ int32_t blockDataFromBuf(SSDataBlock* pBlock, const char* buf) {
|
|||
}
|
||||
|
||||
int32_t blockDataFromBuf1(SSDataBlock* pBlock, const char* buf, size_t capacity) {
|
||||
pBlock->info.rows = *(int32_t*) buf;
|
||||
pBlock->info.groupId = *(uint64_t*) (buf + sizeof(int32_t));
|
||||
pBlock->info.rows = *(int32_t*)buf;
|
||||
pBlock->info.groupId = *(uint64_t*)(buf + sizeof(int32_t));
|
||||
|
||||
int32_t numOfCols = pBlock->info.numOfCols;
|
||||
const char* pStart = buf + sizeof(uint32_t) + sizeof(uint64_t);
|
||||
|
@ -675,7 +673,7 @@ size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock) {
|
|||
return sizeof(int32_t) + sizeof(uint64_t) + pBlock->info.numOfCols * sizeof(int32_t);
|
||||
}
|
||||
|
||||
double blockDataGetSerialRowSize(const SSDataBlock* pBlock) {
|
||||
double blockDataGetSerialRowSize(const SSDataBlock* pBlock) {
|
||||
ASSERT(pBlock != NULL);
|
||||
double rowSize = 0;
|
||||
|
||||
|
@ -1238,7 +1236,7 @@ size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize) {
|
|||
|
||||
// the true value must be less than the value of nRows
|
||||
int32_t additional = 0;
|
||||
for(int32_t i = 0; i < pBlock->info.numOfCols; ++i) {
|
||||
for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) {
|
||||
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, i);
|
||||
if (IS_VAR_DATA_TYPE(pCol->info.type)) {
|
||||
additional += nRows * sizeof(int32_t);
|
||||
|
@ -1734,8 +1732,12 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo
|
|||
for (int32_t k = 0; k < pTSchema->numOfCols; k++) {
|
||||
const STColumn* pColumn = &pTSchema->columns[k];
|
||||
SColumnInfoData* pColData = taosArrayGet(pDataBlock->pDataBlock, k);
|
||||
void* data = colDataGetData(pColData, j);
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, data, true, pColumn->offset, k);
|
||||
if (colDataIsNull_s(pColData, j)) {
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NONE, NULL, false, pColumn->offset, k);
|
||||
} else {
|
||||
void* data = colDataGetData(pColData, j);
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, data, true, pColumn->offset, k);
|
||||
}
|
||||
}
|
||||
int32_t rowLen = TD_ROW_LEN(rowData);
|
||||
rowData = POINTER_SHIFT(rowData, rowLen);
|
||||
|
|
|
@ -581,7 +581,52 @@ void tTagFree(STag *pTag) {
|
|||
if (pTag) taosMemoryFree(pTag);
|
||||
}
|
||||
|
||||
void tTagGet(STag *pTag, int16_t cid, int8_t type, uint8_t **ppData, int32_t *nData) {
|
||||
int32_t tTagSet(STag *pTag, SSchema *pSchema, int32_t nCols, int iCol, uint8_t *pData, uint32_t nData, STag **ppTag) {
|
||||
STagVal *pTagVals;
|
||||
int16_t nTags = 0;
|
||||
SSchema *pColumn;
|
||||
uint8_t *p;
|
||||
uint32_t n;
|
||||
|
||||
pTagVals = (STagVal *)taosMemoryMalloc(sizeof(*pTagVals) * nCols);
|
||||
if (pTagVals == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < nCols; i++) {
|
||||
pColumn = &pSchema[i];
|
||||
|
||||
if (i == iCol) {
|
||||
p = pData;
|
||||
n = nData;
|
||||
} else {
|
||||
tTagGet(pTag, pColumn->colId, pColumn->type, &p, &n);
|
||||
}
|
||||
|
||||
if (p == NULL) continue;
|
||||
|
||||
ASSERT(IS_VAR_DATA_TYPE(pColumn->type) || n == pColumn->bytes);
|
||||
|
||||
pTagVals[nTags].cid = pColumn->colId;
|
||||
pTagVals[nTags].type = pColumn->type;
|
||||
pTagVals[nTags].nData = n;
|
||||
pTagVals[nTags].pData = p;
|
||||
|
||||
nTags++;
|
||||
}
|
||||
|
||||
// create new tag
|
||||
if (tTagNew(pTagVals, nTags, ppTag) < 0) {
|
||||
taosMemoryFree(pTagVals);
|
||||
return -1;
|
||||
}
|
||||
|
||||
taosMemoryFree(pTagVals);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tTagGet(STag *pTag, int16_t cid, int8_t type, uint8_t **ppData, uint32_t *nData) {
|
||||
STagIdx *pTagIdx = bsearch(&((STagIdx){.cid = cid}), pTag->idx, pTag->nTag, sizeof(STagIdx), tTagIdxCmprFn);
|
||||
if (pTagIdx == NULL) {
|
||||
*ppData = NULL;
|
||||
|
@ -597,18 +642,11 @@ void tTagGet(STag *pTag, int16_t cid, int8_t type, uint8_t **ppData, int32_t *nD
|
|||
}
|
||||
}
|
||||
|
||||
int32_t tEncodeTag(SEncoder *pEncoder, STag *pTag) {
|
||||
// return tEncodeBinary(pEncoder, (uint8_t *)pTag, pTag->len);
|
||||
ASSERT(0);
|
||||
return 0;
|
||||
int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag) {
|
||||
return tEncodeBinary(pEncoder, (const uint8_t *)pTag, pTag->len);
|
||||
}
|
||||
|
||||
int32_t tDecodeTag(SDecoder *pDecoder, const STag **ppTag) {
|
||||
// uint32_t n;
|
||||
// return tDecodeBinary(pDecoder, (const uint8_t **)ppTag, &n);
|
||||
ASSERT(0);
|
||||
return 0;
|
||||
}
|
||||
int32_t tDecodeTag(SDecoder *pDecoder, STag **ppTag) { return tDecodeBinary(pDecoder, (uint8_t **)ppTag, NULL); }
|
||||
|
||||
#if 1 // ===================================================================================================================
|
||||
static void dataColSetNEleNull(SDataCol *pCol, int nEle);
|
||||
|
@ -1087,7 +1125,7 @@ SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder) {
|
|||
kvRowSetNCols(row, pBuilder->nCols);
|
||||
kvRowSetLen(row, tlen);
|
||||
|
||||
if(pBuilder->nCols > 0){
|
||||
if (pBuilder->nCols > 0) {
|
||||
memcpy(kvRowColIdx(row), pBuilder->pColIdx, sizeof(SColIdx) * pBuilder->nCols);
|
||||
memcpy(kvRowValues(row), pBuilder->buf, pBuilder->size);
|
||||
}
|
||||
|
|
|
@ -1680,6 +1680,7 @@ int32_t tSerializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) {
|
|||
if (tEncodeI8(&encoder, pReq->replications) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->strict) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->cacheLastRow) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->schemaless) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->ignoreExist) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->numOfRetensions) < 0) return -1;
|
||||
for (int32_t i = 0; i < pReq->numOfRetensions; ++i) {
|
||||
|
@ -1720,6 +1721,7 @@ int32_t tDeserializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq)
|
|||
if (tDecodeI8(&decoder, &pReq->replications) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pReq->strict) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pReq->cacheLastRow) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pReq->schemaless) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pReq->ignoreExist) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->numOfRetensions) < 0) return -1;
|
||||
pReq->pRetensions = taosArrayInit(pReq->numOfRetensions, sizeof(SRetention));
|
||||
|
@ -3186,7 +3188,6 @@ int32_t tSerializeSDCreateMnodeReq(void *buf, int32_t bufLen, SDCreateMnodeReq *
|
|||
tEncoderInit(&encoder, buf, bufLen);
|
||||
|
||||
if (tStartEncode(&encoder) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, pReq->dnodeId) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->replica) < 0) return -1;
|
||||
for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
|
||||
SReplica *pReplica = &pReq->replicas[i];
|
||||
|
@ -3204,7 +3205,6 @@ int32_t tDeserializeSDCreateMnodeReq(void *buf, int32_t bufLen, SDCreateMnodeReq
|
|||
tDecoderInit(&decoder, buf, bufLen);
|
||||
|
||||
if (tStartDecode(&decoder) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &pReq->dnodeId) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pReq->replica) < 0) return -1;
|
||||
for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
|
||||
SReplica *pReplica = &pReq->replicas[i];
|
||||
|
@ -3352,7 +3352,8 @@ int32_t tDeserializeSExplainRsp(void *buf, int32_t bufLen, SExplainRsp *pRsp) {
|
|||
if (tDecodeDouble(&decoder, &pRsp->subplanInfo[i].totalCost) < 0) return -1;
|
||||
if (tDecodeU64(&decoder, &pRsp->subplanInfo[i].numOfRows) < 0) return -1;
|
||||
if (tDecodeU32(&decoder, &pRsp->subplanInfo[i].verboseLen) < 0) return -1;
|
||||
if (tDecodeBinary(&decoder, (uint8_t**) &pRsp->subplanInfo[i].verboseInfo, &pRsp->subplanInfo[i].verboseLen) < 0) return -1;
|
||||
if (tDecodeBinary(&decoder, (uint8_t **)&pRsp->subplanInfo[i].verboseInfo, &pRsp->subplanInfo[i].verboseLen) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
tEndDecode(&decoder);
|
||||
|
|
|
@ -79,7 +79,7 @@ int32_t mmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (createReq.replica <= 1 || (createReq.dnodeId != pInput->pData->dnodeId && pInput->pData->dnodeId != 0)) {
|
||||
if (createReq.replica != 1) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
dError("failed to create mnode since %s", terrstr());
|
||||
return -1;
|
||||
|
|
|
@ -3,7 +3,7 @@ if(${BUILD_TEST})
|
|||
add_subdirectory(qnode)
|
||||
add_subdirectory(bnode)
|
||||
add_subdirectory(snode)
|
||||
add_subdirectory(mnode)
|
||||
#add_subdirectory(mnode)
|
||||
add_subdirectory(vnode)
|
||||
add_subdirectory(sut)
|
||||
endif(${BUILD_TEST})
|
||||
|
|
|
@ -267,75 +267,83 @@ static int32_t mndSetCreateMnodeCommitLogs(SMnode *pMnode, STrans *pTrans, SMnod
|
|||
}
|
||||
|
||||
static int32_t mndSetCreateMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
int32_t numOfReplicas = 0;
|
||||
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
int32_t numOfReplicas = 0;
|
||||
SDAlterMnodeReq alterReq = {0};
|
||||
SDCreateMnodeReq createReq = {0};
|
||||
SEpSet alterEpset = {0};
|
||||
SEpSet createEpset = {0};
|
||||
|
||||
while (1) {
|
||||
SMnodeObj *pMObj = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
SReplica *pReplica = &createReq.replicas[numOfReplicas];
|
||||
pReplica->id = pMObj->id;
|
||||
pReplica->port = pMObj->pDnode->port;
|
||||
memcpy(pReplica->fqdn, pMObj->pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
numOfReplicas++;
|
||||
alterReq.replicas[numOfReplicas].id = pMObj->id;
|
||||
alterReq.replicas[numOfReplicas].port = pMObj->pDnode->port;
|
||||
memcpy(alterReq.replicas[numOfReplicas].fqdn, pMObj->pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
|
||||
alterEpset.eps[numOfReplicas].port = pMObj->pDnode->port;
|
||||
memcpy(alterEpset.eps[numOfReplicas].fqdn, pMObj->pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
if (pMObj->state == TAOS_SYNC_STATE_LEADER) {
|
||||
alterEpset.inUse = numOfReplicas;
|
||||
}
|
||||
|
||||
numOfReplicas++;
|
||||
sdbRelease(pSdb, pMObj);
|
||||
}
|
||||
|
||||
SReplica *pReplica = &createReq.replicas[numOfReplicas];
|
||||
pReplica->id = pDnode->id;
|
||||
pReplica->port = pDnode->port;
|
||||
memcpy(pReplica->fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
numOfReplicas++;
|
||||
alterReq.replica = numOfReplicas + 1;
|
||||
alterReq.replicas[numOfReplicas].id = pDnode->id;
|
||||
alterReq.replicas[numOfReplicas].port = pDnode->port;
|
||||
memcpy(alterReq.replicas[numOfReplicas].fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
|
||||
createReq.replica = numOfReplicas;
|
||||
alterEpset.numOfEps = numOfReplicas + 1;
|
||||
alterEpset.eps[numOfReplicas].port = pDnode->port;
|
||||
memcpy(alterEpset.eps[numOfReplicas].fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
|
||||
while (1) {
|
||||
SMnodeObj *pMObj = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj);
|
||||
if (pIter == NULL) break;
|
||||
createReq.replica = 1;
|
||||
createReq.replicas[0].id = pDnode->id;
|
||||
createReq.replicas[0].port = pDnode->port;
|
||||
memcpy(createReq.replicas[0].fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
|
||||
STransAction action = {0};
|
||||
createEpset.numOfEps = 1;
|
||||
createEpset.eps[0].port = pDnode->port;
|
||||
memcpy(createEpset.eps[0].fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
|
||||
createReq.dnodeId = pMObj->id;
|
||||
int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, &createReq);
|
||||
{
|
||||
int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, &alterReq);
|
||||
void *pReq = taosMemoryMalloc(contLen);
|
||||
tSerializeSDCreateMnodeReq(pReq, contLen, &createReq);
|
||||
tSerializeSDCreateMnodeReq(pReq, contLen, &alterReq);
|
||||
|
||||
action.epSet = mndGetDnodeEpset(pMObj->pDnode);
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_DND_ALTER_MNODE;
|
||||
action.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED;
|
||||
STransAction action = {
|
||||
.epSet = alterEpset,
|
||||
.pCont = pReq,
|
||||
.contLen = contLen,
|
||||
.msgType = TDMT_DND_ALTER_MNODE,
|
||||
.acceptableCode = 0,
|
||||
};
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
sdbRelease(pSdb, pMObj);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sdbRelease(pSdb, pMObj);
|
||||
}
|
||||
|
||||
{
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
|
||||
createReq.dnodeId = pObj->id;
|
||||
int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, &createReq);
|
||||
void *pReq = taosMemoryMalloc(contLen);
|
||||
tSerializeSDCreateMnodeReq(pReq, contLen, &createReq);
|
||||
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_DND_CREATE_MNODE;
|
||||
action.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED;
|
||||
STransAction action = {
|
||||
.epSet = createEpset,
|
||||
.pCont = pReq,
|
||||
.contLen = contLen,
|
||||
.msgType = TDMT_DND_CREATE_MNODE,
|
||||
.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED,
|
||||
};
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
|
@ -441,73 +449,77 @@ static int32_t mndSetDropMnodeCommitLogs(SMnode *pMnode, STrans *pTrans, SMnodeO
|
|||
}
|
||||
|
||||
static int32_t mndSetDropMnodeRedoActions(SMnode *pMnode, STrans *pTrans, SDnodeObj *pDnode, SMnodeObj *pObj) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
int32_t numOfReplicas = 0;
|
||||
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
int32_t numOfReplicas = 0;
|
||||
SDAlterMnodeReq alterReq = {0};
|
||||
SDDropMnodeReq dropReq = {0};
|
||||
SEpSet alterEpset = {0};
|
||||
SEpSet dropEpSet = {0};
|
||||
|
||||
while (1) {
|
||||
SMnodeObj *pMObj = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
if (pMObj->id != pObj->id) {
|
||||
SReplica *pReplica = &alterReq.replicas[numOfReplicas];
|
||||
pReplica->id = pMObj->id;
|
||||
pReplica->port = pMObj->pDnode->port;
|
||||
memcpy(pReplica->fqdn, pMObj->pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
numOfReplicas++;
|
||||
if (pMObj->id == pObj->id) {
|
||||
sdbRelease(pSdb, pMObj);
|
||||
continue;
|
||||
}
|
||||
|
||||
alterReq.replicas[numOfReplicas].id = pMObj->id;
|
||||
alterReq.replicas[numOfReplicas].port = pMObj->pDnode->port;
|
||||
memcpy(alterReq.replicas[numOfReplicas].fqdn, pMObj->pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
|
||||
alterEpset.eps[numOfReplicas].port = pMObj->pDnode->port;
|
||||
memcpy(alterEpset.eps[numOfReplicas].fqdn, pMObj->pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
if (pMObj->state == TAOS_SYNC_STATE_LEADER) {
|
||||
alterEpset.inUse = numOfReplicas;
|
||||
}
|
||||
|
||||
numOfReplicas++;
|
||||
sdbRelease(pSdb, pMObj);
|
||||
}
|
||||
|
||||
alterReq.replica = numOfReplicas;
|
||||
alterEpset.numOfEps = numOfReplicas;
|
||||
|
||||
while (1) {
|
||||
SMnodeObj *pMObj = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pMObj);
|
||||
if (pIter == NULL) break;
|
||||
if (pMObj->id != pObj->id) {
|
||||
STransAction action = {0};
|
||||
dropReq.dnodeId = pDnode->id;
|
||||
dropEpSet.numOfEps = 1;
|
||||
dropEpSet.eps[0].port = pDnode->port;
|
||||
memcpy(dropEpSet.eps[0].fqdn, pDnode->fqdn, TSDB_FQDN_LEN);
|
||||
|
||||
alterReq.dnodeId = pMObj->id;
|
||||
int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, &alterReq);
|
||||
void *pReq = taosMemoryMalloc(contLen);
|
||||
tSerializeSDCreateMnodeReq(pReq, contLen, &alterReq);
|
||||
{
|
||||
int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, &alterReq);
|
||||
void *pReq = taosMemoryMalloc(contLen);
|
||||
tSerializeSDCreateMnodeReq(pReq, contLen, &alterReq);
|
||||
|
||||
action.epSet = mndGetDnodeEpset(pMObj->pDnode);
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_DND_ALTER_MNODE;
|
||||
action.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED;
|
||||
STransAction action = {
|
||||
.epSet = alterEpset,
|
||||
.pCont = pReq,
|
||||
.contLen = contLen,
|
||||
.msgType = TDMT_DND_ALTER_MNODE,
|
||||
.acceptableCode = 0,
|
||||
};
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
sdbRelease(pSdb, pMObj);
|
||||
return -1;
|
||||
}
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sdbRelease(pSdb, pMObj);
|
||||
}
|
||||
|
||||
{
|
||||
STransAction action = {0};
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
|
||||
SDDropMnodeReq dropReq = {0};
|
||||
dropReq.dnodeId = pObj->id;
|
||||
int32_t contLen = tSerializeSCreateDropMQSBNodeReq(NULL, 0, &dropReq);
|
||||
void *pReq = taosMemoryMalloc(contLen);
|
||||
tSerializeSCreateDropMQSBNodeReq(pReq, contLen, &dropReq);
|
||||
|
||||
action.epSet = mndGetDnodeEpset(pDnode);
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_DND_DROP_MNODE;
|
||||
action.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED;
|
||||
STransAction action = {
|
||||
.epSet = dropEpSet,
|
||||
.pCont = pReq,
|
||||
.contLen = contLen,
|
||||
.msgType = TDMT_DND_DROP_MNODE,
|
||||
.acceptableCode = TSDB_CODE_NODE_NOT_DEPLOYED,
|
||||
};
|
||||
|
||||
if (mndTransAppendRedoAction(pTrans, &action) != 0) {
|
||||
taosMemoryFree(pReq);
|
||||
return -1;
|
||||
|
@ -662,7 +674,7 @@ static void mndCancelGetNextMnode(SMnode *pMnode, void *pIter) {
|
|||
}
|
||||
|
||||
static int32_t mndProcessAlterMnodeReq(SRpcMsg *pReq) {
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SMnode *pMnode = pReq->info.node;
|
||||
SDAlterMnodeReq alterReq = {0};
|
||||
|
||||
if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &alterReq) != 0) {
|
||||
|
@ -670,12 +682,6 @@ static int32_t mndProcessAlterMnodeReq(SRpcMsg *pReq) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (alterReq.dnodeId != pMnode->selfDnodeId) {
|
||||
terrno = TSDB_CODE_INVALID_OPTION;
|
||||
mError("failed to alter mnode since %s, input:%d cur:%d", terrstr(), alterReq.dnodeId, pMnode->selfDnodeId);
|
||||
return -1;
|
||||
}
|
||||
|
||||
SSyncCfg cfg = {.replicaNum = alterReq.replica, .myIndex = -1};
|
||||
for (int32_t i = 0; i < alterReq.replica; ++i) {
|
||||
SNodeInfo *pNode = &cfg.nodeInfo[i];
|
||||
|
|
|
@ -31,7 +31,8 @@ void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbM
|
|||
SMnode *pMnode = pFsm->data;
|
||||
SSdbRaw *pRaw = pMsg->pCont;
|
||||
|
||||
mTrace("raw:%p, apply to sdb, ver:%" PRId64 " role:%s", pRaw, cbMeta.index, syncStr(cbMeta.state));
|
||||
mTrace("raw:%p, apply to sdb, ver:%" PRId64 " term:%" PRId64 " role:%s", pRaw, cbMeta.index, cbMeta.term,
|
||||
syncStr(cbMeta.state));
|
||||
sdbWriteWithoutFree(pMnode->pSdb, pRaw);
|
||||
sdbSetApplyIndex(pMnode->pSdb, cbMeta.index);
|
||||
sdbSetApplyTerm(pMnode->pSdb, cbMeta.term);
|
||||
|
|
|
@ -13,6 +13,8 @@ target_sources(
|
|||
"src/vnd/vnodeModule.c"
|
||||
"src/vnd/vnodeSvr.c"
|
||||
"src/vnd/vnodeSync.c"
|
||||
"src/vnd/vnodeSnapshot.c"
|
||||
"src/vnd/vnodeUtil.c"
|
||||
|
||||
# meta
|
||||
"src/meta/metaOpen.c"
|
||||
|
@ -22,6 +24,7 @@ target_sources(
|
|||
"src/meta/metaQuery.c"
|
||||
"src/meta/metaCommit.c"
|
||||
"src/meta/metaEntry.c"
|
||||
"src/meta/metaSnapshot.c"
|
||||
|
||||
# sma
|
||||
"src/sma/sma.c"
|
||||
|
@ -44,6 +47,7 @@ target_sources(
|
|||
"src/tsdb/tsdbReadImpl.c"
|
||||
# "src/tsdb/tsdbSma.c"
|
||||
"src/tsdb/tsdbWrite.c"
|
||||
"src/tsdb/tsdbSnapshot.c"
|
||||
|
||||
# tq
|
||||
"src/tq/tq.c"
|
||||
|
|
|
@ -39,9 +39,10 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
// vnode
|
||||
typedef struct SVnode SVnode;
|
||||
typedef struct STsdbCfg STsdbCfg; // todo: remove
|
||||
typedef struct SVnodeCfg SVnodeCfg;
|
||||
typedef struct SVnode SVnode;
|
||||
typedef struct STsdbCfg STsdbCfg; // todo: remove
|
||||
typedef struct SVnodeCfg SVnodeCfg;
|
||||
typedef struct SVSnapshotReader SVSnapshotReader;
|
||||
|
||||
extern const SVnodeCfg vnodeCfgDefault;
|
||||
|
||||
|
@ -59,13 +60,14 @@ int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg);
|
|||
int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo);
|
||||
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad);
|
||||
int32_t vnodeValidateTableHash(SVnode *pVnode, char *tableFName);
|
||||
|
||||
int32_t vnodeStart(SVnode *pVnode);
|
||||
void vnodeStop(SVnode *pVnode);
|
||||
|
||||
int64_t vnodeGetSyncHandle(SVnode *pVnode);
|
||||
void vnodeGetSnapshot(SVnode *pVnode, SSnapshot *pSnapshot);
|
||||
void vnodeGetInfo(SVnode *pVnode, const char **dbname, int32_t *vgId);
|
||||
int32_t vnodeSnapshotReaderOpen(SVnode *pVnode, SVSnapshotReader **ppReader, int64_t sver, int64_t ever);
|
||||
int32_t vnodeSnapshotReaderClose(SVSnapshotReader *pReader);
|
||||
int32_t vnodeSnapshotRead(SVSnapshotReader *pReader, const void **ppData, uint32_t *nData);
|
||||
|
||||
// meta
|
||||
typedef struct SMeta SMeta; // todo: remove
|
||||
|
|
|
@ -40,8 +40,8 @@ typedef struct STable STable;
|
|||
|
||||
int tsdbMemTableCreate(STsdb *pTsdb, STsdbMemTable **ppMemTable);
|
||||
void tsdbMemTableDestroy(STsdb *pTsdb, STsdbMemTable *pMemTable);
|
||||
int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey, int maxRowsToRead, SDataCols *pCols,
|
||||
TKEY *filterKeys, int nFilterKeys, bool keepDup, SMergeInfo *pMergeInfo);
|
||||
int tsdbLoadDataFromCache(STsdb *pTsdb, STable *pTable, SSkipListIterator *pIter, TSKEY maxKey, int maxRowsToRead,
|
||||
SDataCols *pCols, TKEY *filterKeys, int nFilterKeys, bool keepDup, SMergeInfo *pMergeInfo);
|
||||
|
||||
// tsdbCommit ================
|
||||
|
||||
|
@ -179,7 +179,14 @@ struct STsdbFS {
|
|||
int tsdbLockRepo(STsdb *pTsdb);
|
||||
int tsdbUnlockRepo(STsdb *pTsdb);
|
||||
|
||||
static FORCE_INLINE STSchema *tsdbGetTableSchemaImpl(STable *pTable, bool lock, bool copy, int32_t version) {
|
||||
static FORCE_INLINE STSchema *tsdbGetTableSchemaImpl(STsdb *pTsdb, STable *pTable, bool lock, bool copy,
|
||||
int32_t version) {
|
||||
|
||||
if ((version != -1) && (schemaVersion(pTable->pSchema) != version)) {
|
||||
taosMemoryFreeClear(pTable->pSchema);
|
||||
pTable->pSchema = metaGetTbTSchema(REPO_META(pTsdb), pTable->uid, version);
|
||||
}
|
||||
|
||||
return pTable->pSchema;
|
||||
}
|
||||
|
||||
|
|
|
@ -47,15 +47,17 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SVnodeInfo SVnodeInfo;
|
||||
typedef struct SMeta SMeta;
|
||||
typedef struct SSma SSma;
|
||||
typedef struct STsdb STsdb;
|
||||
typedef struct STQ STQ;
|
||||
typedef struct SVState SVState;
|
||||
typedef struct SVBufPool SVBufPool;
|
||||
typedef struct SQWorker SQHandle;
|
||||
typedef struct STsdbKeepCfg STsdbKeepCfg;
|
||||
typedef struct SVnodeInfo SVnodeInfo;
|
||||
typedef struct SMeta SMeta;
|
||||
typedef struct SSma SSma;
|
||||
typedef struct STsdb STsdb;
|
||||
typedef struct STQ STQ;
|
||||
typedef struct SVState SVState;
|
||||
typedef struct SVBufPool SVBufPool;
|
||||
typedef struct SQWorker SQHandle;
|
||||
typedef struct STsdbKeepCfg STsdbKeepCfg;
|
||||
typedef struct SMetaSnapshotReader SMetaSnapshotReader;
|
||||
typedef struct STsdbSnapshotReader STsdbSnapshotReader;
|
||||
|
||||
#define VNODE_META_DIR "meta"
|
||||
#define VNODE_TSDB_DIR "tsdb"
|
||||
|
@ -67,8 +69,10 @@ typedef struct STsdbKeepCfg STsdbKeepCfg;
|
|||
#define VNODE_RSMA2_DIR "rsma2"
|
||||
|
||||
// vnd.h
|
||||
void* vnodeBufPoolMalloc(SVBufPool* pPool, int size);
|
||||
void vnodeBufPoolFree(SVBufPool* pPool, void* p);
|
||||
void* vnodeBufPoolMalloc(SVBufPool* pPool, int size);
|
||||
void vnodeBufPoolFree(SVBufPool* pPool, void* p);
|
||||
int32_t vnodeRealloc(void** pp, int32_t size);
|
||||
void vnodeFree(void* p);
|
||||
|
||||
// meta
|
||||
typedef struct SMCtbCursor SMCtbCursor;
|
||||
|
@ -95,6 +99,9 @@ STSma* metaGetSmaInfoByIndex(SMeta* pMeta, int64_t indexUid);
|
|||
STSmaWrapper* metaGetSmaInfoByTable(SMeta* pMeta, tb_uid_t uid, bool deepCopy);
|
||||
SArray* metaGetSmaIdsByTable(SMeta* pMeta, tb_uid_t uid);
|
||||
SArray* metaGetSmaTbUids(SMeta* pMeta);
|
||||
int32_t metaSnapshotReaderOpen(SMeta* pMeta, SMetaSnapshotReader** ppReader, int64_t sver, int64_t ever);
|
||||
int32_t metaSnapshotReaderClose(SMetaSnapshotReader* pReader);
|
||||
int32_t metaSnapshotRead(SMetaSnapshotReader* pReader, void** ppData, uint32_t* nData);
|
||||
|
||||
int32_t metaCreateTSma(SMeta* pMeta, int64_t version, SSmaCfg* pCfg);
|
||||
int32_t metaDropTSma(SMeta* pMeta, int64_t indexUid);
|
||||
|
@ -112,6 +119,9 @@ tsdbReaderT* tsdbQueryTables(SVnode* pVnode, SQueryTableDataCond* pCond, STableG
|
|||
tsdbReaderT tsdbQueryCacheLastT(STsdb* tsdb, SQueryTableDataCond* pCond, STableGroupInfo* groupList, uint64_t qId,
|
||||
void* pMemRef);
|
||||
int32_t tsdbGetTableGroupFromIdListT(STsdb* tsdb, SArray* pTableIdList, STableGroupInfo* pGroupInfo);
|
||||
int32_t tsdbSnapshotReaderOpen(STsdb* pTsdb, STsdbSnapshotReader** ppReader, int64_t sver, int64_t ever);
|
||||
int32_t tsdbSnapshotReaderClose(STsdbSnapshotReader* pReader);
|
||||
int32_t tsdbSnapshotRead(STsdbSnapshotReader* pReader, void** ppData, uint32_t* nData);
|
||||
|
||||
// tq
|
||||
STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal);
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "meta.h"
|
||||
|
||||
struct SMetaSnapshotReader {
|
||||
SMeta* pMeta;
|
||||
TBC* pTbc;
|
||||
int64_t sver;
|
||||
int64_t ever;
|
||||
};
|
||||
|
||||
int32_t metaSnapshotReaderOpen(SMeta* pMeta, SMetaSnapshotReader** ppReader, int64_t sver, int64_t ever) {
|
||||
int32_t code = 0;
|
||||
int32_t c = 0;
|
||||
SMetaSnapshotReader* pMetaReader = NULL;
|
||||
|
||||
pMetaReader = (SMetaSnapshotReader*)taosMemoryCalloc(1, sizeof(*pMetaReader));
|
||||
if (pMetaReader == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
}
|
||||
pMetaReader->pMeta = pMeta;
|
||||
pMetaReader->sver = sver;
|
||||
pMetaReader->ever = ever;
|
||||
code = tdbTbcOpen(pMeta->pTbDb, &pMetaReader->pTbc, NULL);
|
||||
if (code) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
code = tdbTbcMoveTo(pMetaReader->pTbc, &(STbDbKey){.version = sver, .uid = INT64_MIN}, sizeof(STbDbKey), &c);
|
||||
if (code) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
*ppReader = pMetaReader;
|
||||
return code;
|
||||
|
||||
_err:
|
||||
*ppReader = NULL;
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t metaSnapshotReaderClose(SMetaSnapshotReader* pReader) {
|
||||
if (pReader) {
|
||||
tdbTbcClose(pReader->pTbc);
|
||||
taosMemoryFree(pReader);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t metaSnapshotRead(SMetaSnapshotReader* pReader, void** ppData, uint32_t* nDatap) {
|
||||
const void* pKey = NULL;
|
||||
const void* pData = NULL;
|
||||
int32_t nKey = 0;
|
||||
int32_t nData = 0;
|
||||
int32_t code = 0;
|
||||
|
||||
for (;;) {
|
||||
code = tdbTbcGet(pReader->pTbc, &pKey, &nKey, &pData, &nData);
|
||||
if (code || ((STbDbKey*)pData)->version > pReader->ever) {
|
||||
return TSDB_CODE_VND_READ_END;
|
||||
}
|
||||
|
||||
if (((STbDbKey*)pData)->version < pReader->sver) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// copy the data
|
||||
if (vnodeRealloc(ppData, nData) < 0) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return code;
|
||||
}
|
||||
|
||||
memcpy(*ppData, pData, nData);
|
||||
*nDatap = nData;
|
||||
return code;
|
||||
}
|
|
@ -23,6 +23,7 @@ static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME);
|
|||
static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||
static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry);
|
||||
static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type);
|
||||
|
||||
int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
||||
SMetaEntry me = {0};
|
||||
|
@ -71,64 +72,71 @@ _err:
|
|||
}
|
||||
|
||||
int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq) {
|
||||
TBC *pNameIdxc = NULL;
|
||||
TBC *pUidIdxc = NULL;
|
||||
TBC *pCtbIdxc = NULL;
|
||||
SCtbIdxKey *pCtbIdxKey;
|
||||
const void *pKey = NULL;
|
||||
int nKey;
|
||||
const void *pData = NULL;
|
||||
int nData;
|
||||
int c, ret;
|
||||
void *pKey = NULL;
|
||||
int nKey = 0;
|
||||
void *pData = NULL;
|
||||
int nData = 0;
|
||||
int c = 0;
|
||||
int rc = 0;
|
||||
|
||||
// prepare uid idx cursor
|
||||
tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, &pMeta->txn);
|
||||
ret = tdbTbcMoveTo(pUidIdxc, &pReq->suid, sizeof(tb_uid_t), &c);
|
||||
if (ret < 0 || c != 0) {
|
||||
terrno = TSDB_CODE_VND_TB_NOT_EXIST;
|
||||
tdbTbcClose(pUidIdxc);
|
||||
goto _err;
|
||||
// check if super table exists
|
||||
rc = tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &pData, &nData);
|
||||
if (rc < 0 || *(tb_uid_t *)pData != pReq->suid) {
|
||||
terrno = TSDB_CODE_VND_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// prepare name idx cursor
|
||||
tdbTbcOpen(pMeta->pNameIdx, &pNameIdxc, &pMeta->txn);
|
||||
ret = tdbTbcMoveTo(pNameIdxc, pReq->name, strlen(pReq->name) + 1, &c);
|
||||
if (ret < 0 || c != 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
// drop all child tables
|
||||
TBC *pCtbIdxc = NULL;
|
||||
SArray *pArray = taosArrayInit(8, sizeof(tb_uid_t));
|
||||
|
||||
tdbTbcDelete(pUidIdxc);
|
||||
tdbTbcDelete(pNameIdxc);
|
||||
tdbTbcClose(pUidIdxc);
|
||||
tdbTbcClose(pNameIdxc);
|
||||
|
||||
// loop to drop each child table
|
||||
tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, &pMeta->txn);
|
||||
ret = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = pReq->suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c);
|
||||
if (ret < 0 || (c < 0 && tdbTbcMoveToNext(pCtbIdxc) < 0)) {
|
||||
rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = pReq->suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c);
|
||||
if (rc < 0) {
|
||||
tdbTbcClose(pCtbIdxc);
|
||||
goto _exit;
|
||||
metaWLock(pMeta);
|
||||
goto _drop_super_table;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
tdbTbcGet(pCtbIdxc, &pKey, &nKey, NULL, NULL);
|
||||
pCtbIdxKey = (SCtbIdxKey *)pKey;
|
||||
rc = tdbTbcNext(pCtbIdxc, &pKey, &nKey, NULL, NULL);
|
||||
if (rc < 0) break;
|
||||
|
||||
if (pCtbIdxKey->suid > pReq->suid) break;
|
||||
if (((SCtbIdxKey *)pKey)->suid < pReq->suid) {
|
||||
continue;
|
||||
} else if (((SCtbIdxKey *)pKey)->suid > pReq->suid) {
|
||||
break;
|
||||
}
|
||||
|
||||
// drop the child table (TODO)
|
||||
|
||||
if (tdbTbcMoveToNext(pCtbIdxc) < 0) break;
|
||||
taosArrayPush(pArray, &(((SCtbIdxKey *)pKey)->uid));
|
||||
}
|
||||
|
||||
tdbTbcClose(pCtbIdxc);
|
||||
|
||||
metaWLock(pMeta);
|
||||
|
||||
for (int32_t iChild = 0; iChild < taosArrayGetSize(pArray); iChild++) {
|
||||
tb_uid_t uid = *(tb_uid_t *)taosArrayGet(pArray, iChild);
|
||||
metaDropTableByUid(pMeta, uid, NULL);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pArray);
|
||||
|
||||
// drop super table
|
||||
_drop_super_table:
|
||||
tdbTbGet(pMeta->pUidIdx, &pReq->suid, sizeof(tb_uid_t), &pData, &nData);
|
||||
tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = *(int64_t *)pData, .uid = pReq->suid}, sizeof(STbDbKey),
|
||||
&pMeta->txn);
|
||||
tdbTbDelete(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &pMeta->txn);
|
||||
tdbTbDelete(pMeta->pUidIdx, &pReq->suid, sizeof(tb_uid_t), &pMeta->txn);
|
||||
|
||||
metaULock(pMeta);
|
||||
|
||||
_exit:
|
||||
tdbFree(pKey);
|
||||
tdbFree(pData);
|
||||
metaDebug("vgId:%d super table %s uid:%" PRId64 " is dropped", TD_VID(pMeta->pVnode), pReq->name, pReq->suid);
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
metaError("vgId:%d failed to drop super table %s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name,
|
||||
pReq->suid, tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
||||
|
@ -256,122 +264,63 @@ _err:
|
|||
}
|
||||
|
||||
int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUids) {
|
||||
TBC *pTbDbc = NULL;
|
||||
TBC *pUidIdxc = NULL;
|
||||
TBC *pNameIdxc = NULL;
|
||||
const void *pData;
|
||||
int nData;
|
||||
tb_uid_t uid;
|
||||
int64_t tver;
|
||||
SMetaEntry me = {0};
|
||||
SDecoder coder = {0};
|
||||
int8_t type;
|
||||
int64_t ctime;
|
||||
tb_uid_t suid;
|
||||
int c = 0, ret;
|
||||
void *pData = NULL;
|
||||
int nData = 0;
|
||||
int rc = 0;
|
||||
tb_uid_t uid;
|
||||
int type;
|
||||
|
||||
// search & delete the name idx
|
||||
tdbTbcOpen(pMeta->pNameIdx, &pNameIdxc, &pMeta->txn);
|
||||
ret = tdbTbcMoveTo(pNameIdxc, pReq->name, strlen(pReq->name) + 1, &c);
|
||||
if (ret < 0 || !tdbTbcIsValid(pNameIdxc) || c) {
|
||||
tdbTbcClose(pNameIdxc);
|
||||
rc = tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &pData, &nData);
|
||||
if (rc < 0) {
|
||||
terrno = TSDB_CODE_VND_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = tdbTbcGet(pNameIdxc, NULL, NULL, &pData, &nData);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
uid = *(tb_uid_t *)pData;
|
||||
|
||||
tdbTbcDelete(pNameIdxc);
|
||||
tdbTbcClose(pNameIdxc);
|
||||
metaWLock(pMeta);
|
||||
metaDropTableByUid(pMeta, uid, &type);
|
||||
metaULock(pMeta);
|
||||
|
||||
// search & delete uid idx
|
||||
tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, &pMeta->txn);
|
||||
ret = tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c);
|
||||
if (ret < 0 || c != 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
if (type == TSDB_CHILD_TABLE && tbUids) {
|
||||
taosArrayPush(tbUids, &uid);
|
||||
}
|
||||
|
||||
ret = tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
tdbFree(pData);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
|
||||
void *pData = NULL;
|
||||
int nData = 0;
|
||||
int rc = 0;
|
||||
int64_t version;
|
||||
SMetaEntry e = {0};
|
||||
SDecoder dc = {0};
|
||||
|
||||
rc = tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pData, &nData);
|
||||
version = *(int64_t *)pData;
|
||||
|
||||
tdbTbGet(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pData, &nData);
|
||||
|
||||
tDecoderInit(&dc, pData, nData);
|
||||
metaDecodeEntry(&dc, &e);
|
||||
|
||||
if (type) *type = e.type;
|
||||
|
||||
tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pMeta->txn);
|
||||
tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, &pMeta->txn);
|
||||
tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), &pMeta->txn);
|
||||
if (e.type == TSDB_CHILD_TABLE) {
|
||||
tdbTbDelete(pMeta->pCtbIdx, &(SCtbIdxKey){.suid = e.ctbEntry.suid, .uid = uid}, sizeof(SCtbIdxKey), &pMeta->txn);
|
||||
} else if (e.type == TSDB_NORMAL_TABLE) {
|
||||
// drop schema.db (todo)
|
||||
// drop ttl.idx (todo)
|
||||
} else if (e.type == TSDB_SUPER_TABLE) {
|
||||
// drop schema.db (todo)
|
||||
}
|
||||
|
||||
tver = *(int64_t *)pData;
|
||||
tdbTbcDelete(pUidIdxc);
|
||||
tdbTbcClose(pUidIdxc);
|
||||
|
||||
// search and get meta entry
|
||||
tdbTbcOpen(pMeta->pTbDb, &pTbDbc, &pMeta->txn);
|
||||
ret = tdbTbcMoveTo(pTbDbc, &(STbDbKey){.uid = uid, .version = tver}, sizeof(STbDbKey), &c);
|
||||
if (ret < 0 || c != 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// decode entry
|
||||
void *pDataCopy = taosMemoryMalloc(nData); // remove the copy (todo)
|
||||
memcpy(pDataCopy, pData, nData);
|
||||
tDecoderInit(&coder, pDataCopy, nData);
|
||||
ret = metaDecodeEntry(&coder, &me);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
type = me.type;
|
||||
if (type == TSDB_CHILD_TABLE) {
|
||||
ctime = me.ctbEntry.ctime;
|
||||
suid = me.ctbEntry.suid;
|
||||
taosArrayPush(tbUids, &me.uid);
|
||||
} else if (type == TSDB_NORMAL_TABLE) {
|
||||
ctime = me.ntbEntry.ctime;
|
||||
suid = 0;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
taosMemoryFree(pDataCopy);
|
||||
tDecoderClear(&coder);
|
||||
tdbTbcClose(pTbDbc);
|
||||
|
||||
if (type == TSDB_CHILD_TABLE) {
|
||||
// remove the pCtbIdx
|
||||
TBC *pCtbIdxc = NULL;
|
||||
tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, &pMeta->txn);
|
||||
|
||||
ret = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = uid}, sizeof(SCtbIdxKey), &c);
|
||||
if (ret < 0 || c != 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tdbTbcDelete(pCtbIdxc);
|
||||
tdbTbcClose(pCtbIdxc);
|
||||
|
||||
// remove tags from pTagIdx (todo)
|
||||
} else if (type == TSDB_NORMAL_TABLE) {
|
||||
// remove from pSkmDb
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
// remove from ttl (todo)
|
||||
if (ctime > 0) {
|
||||
}
|
||||
tDecoderClear(&dc);
|
||||
tdbFree(pData);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -608,14 +557,14 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
|||
// TODO : need to update tag index
|
||||
}
|
||||
ctbEntry.version = version;
|
||||
if(pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON){
|
||||
if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) {
|
||||
ctbEntry.ctbEntry.pTags = taosMemoryMalloc(pAlterTbReq->nTagVal);
|
||||
if(ctbEntry.ctbEntry.pTags == NULL){
|
||||
if (ctbEntry.ctbEntry.pTags == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
}
|
||||
memcpy((void*)ctbEntry.ctbEntry.pTags, pAlterTbReq->pTagVal, pAlterTbReq->nTagVal);
|
||||
}else{
|
||||
memcpy((void *)ctbEntry.ctbEntry.pTags, pAlterTbReq->pTagVal, pAlterTbReq->nTagVal);
|
||||
} else {
|
||||
SKVRowBuilder kvrb = {0};
|
||||
const SKVRow pOldTag = (const SKVRow)ctbEntry.ctbEntry.pTags;
|
||||
SKVRow pNewTag = NULL;
|
||||
|
@ -649,7 +598,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA
|
|||
|
||||
tDecoderClear(&dc1);
|
||||
tDecoderClear(&dc2);
|
||||
if (ctbEntry.ctbEntry.pTags) taosMemoryFree((void*)ctbEntry.ctbEntry.pTags);
|
||||
if (ctbEntry.ctbEntry.pTags) taosMemoryFree((void *)ctbEntry.ctbEntry.pTags);
|
||||
if (ctbEntry.pBuf) taosMemoryFree(ctbEntry.pBuf);
|
||||
if (stbEntry.pBuf) tdbFree(stbEntry.pBuf);
|
||||
tdbTbcClose(pTbDbc);
|
||||
|
|
|
@ -51,6 +51,47 @@ int tqExecKeyCompare(const void* pKey1, int32_t kLen1, const void* pKey2, int32_
|
|||
return strcmp(pKey1, pKey2);
|
||||
}
|
||||
|
||||
int32_t tqStoreExec(STQ* pTq, const char* key, const STqExec* pExec) {
|
||||
int32_t code;
|
||||
int32_t vlen;
|
||||
tEncodeSize(tEncodeSTqExec, pExec, vlen, code);
|
||||
ASSERT(code == 0);
|
||||
|
||||
void* buf = taosMemoryCalloc(1, vlen);
|
||||
if (buf == NULL) {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
SEncoder encoder;
|
||||
tEncoderInit(&encoder, buf, vlen);
|
||||
|
||||
if (tEncodeSTqExec(&encoder, pExec) < 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
TXN txn;
|
||||
|
||||
if (tdbTxnOpen(&txn, 0, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED) < 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
if (tdbBegin(pTq->pMetaStore, &txn) < 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
if (tdbTbUpsert(pTq->pExecStore, key, (int)strlen(key), buf, vlen, &txn) < 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
if (tdbCommit(pTq->pMetaStore, &txn) < 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
tEncoderClear(&encoder);
|
||||
taosMemoryFree(buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal) {
|
||||
STQ* pTq = taosMemoryMalloc(sizeof(STQ));
|
||||
if (pTq == NULL) {
|
||||
|
@ -96,8 +137,31 @@ STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal) {
|
|||
int vLen;
|
||||
|
||||
tdbTbcMoveToFirst(pCur);
|
||||
SDecoder decoder;
|
||||
while (tdbTbcNext(pCur, &pKey, &kLen, &pVal, &vLen) == 0) {
|
||||
// create, put into execsj
|
||||
STqExec exec;
|
||||
tDecoderInit(&decoder, (uint8_t*)pVal, vLen);
|
||||
tDecodeSTqExec(&decoder, &exec);
|
||||
exec.pWalReader = walOpenReadHandle(pTq->pVnode->pWal);
|
||||
if (exec.subType == TOPIC_SUB_TYPE__TABLE) {
|
||||
for (int32_t i = 0; i < 5; i++) {
|
||||
exec.pExecReader[i] = tqInitSubmitMsgScanner(pTq->pVnode->pMeta);
|
||||
|
||||
SReadHandle handle = {
|
||||
.reader = exec.pExecReader[i],
|
||||
.meta = pTq->pVnode->pMeta,
|
||||
.pMsgCb = &pTq->pVnode->msgCb,
|
||||
};
|
||||
exec.task[i] = qCreateStreamExecTaskInfo(exec.qmsg, &handle);
|
||||
ASSERT(exec.task[i]);
|
||||
}
|
||||
} else {
|
||||
for (int32_t i = 0; i < 5; i++) {
|
||||
exec.pExecReader[i] = tqInitSubmitMsgScanner(pTq->pVnode->pMeta);
|
||||
}
|
||||
exec.pDropTbUid = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
|
||||
}
|
||||
taosHashPut(pTq->execs, pKey, kLen, &exec, sizeof(STqExec));
|
||||
}
|
||||
|
||||
if (tdbTxnClose(&txn) < 0) {
|
||||
|
@ -604,7 +668,9 @@ int32_t tqProcessVgDeleteReq(STQ* pTq, char* msg, int32_t msgLen) {
|
|||
ASSERT(0);
|
||||
}
|
||||
|
||||
tdbTbDelete(pTq->pExecStore, pReq->subKey, (int)strlen(pReq->subKey), &txn);
|
||||
if (tdbTbDelete(pTq->pExecStore, pReq->subKey, (int)strlen(pReq->subKey), &txn) < 0) {
|
||||
/*ASSERT(0);*/
|
||||
}
|
||||
|
||||
if (tdbCommit(pTq->pMetaStore, &txn) < 0) {
|
||||
ASSERT(0);
|
||||
|
@ -659,60 +725,21 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) {
|
|||
}
|
||||
taosHashPut(pTq->execs, req.subKey, strlen(req.subKey), pExec, sizeof(STqExec));
|
||||
|
||||
int32_t code;
|
||||
int32_t vlen;
|
||||
tEncodeSize(tEncodeSTqExec, pExec, vlen, code);
|
||||
ASSERT(code == 0);
|
||||
|
||||
void* buf = taosMemoryCalloc(1, vlen);
|
||||
if (buf == NULL) {
|
||||
ASSERT(0);
|
||||
if (tqStoreExec(pTq, req.subKey, pExec) < 0) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
SEncoder encoder;
|
||||
tEncoderInit(&encoder, buf, vlen);
|
||||
|
||||
if (tEncodeSTqExec(&encoder, pExec) < 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
TXN txn;
|
||||
|
||||
if (tdbTxnOpen(&txn, 0, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED) < 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
if (tdbBegin(pTq->pMetaStore, &txn) < 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
if (tdbTbUpsert(pTq->pExecStore, req.subKey, (int)strlen(req.subKey), buf, vlen, &txn) < 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
if (tdbCommit(pTq->pMetaStore, &txn) < 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
tEncoderClear(&encoder);
|
||||
taosMemoryFree(buf);
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
/*if (req.newConsumerId != -1) {*/
|
||||
/*taosWLockLatch(&pExec->lock);*/
|
||||
ASSERT(pExec->consumerId == req.oldConsumerId);
|
||||
/*ASSERT(pExec->consumerId == req.oldConsumerId);*/
|
||||
// TODO handle qmsg and exec modification
|
||||
atomic_store_32(&pExec->epoch, -1);
|
||||
atomic_store_64(&pExec->consumerId, req.newConsumerId);
|
||||
atomic_add_fetch_32(&pExec->epoch, 1);
|
||||
/*taosWUnLockLatch(&pExec->lock);*/
|
||||
|
||||
if (tqStoreExec(pTq, req.subKey, pExec) < 0) {
|
||||
// TODO
|
||||
}
|
||||
return 0;
|
||||
/*} else {*/
|
||||
// TODO
|
||||
/*taosHashRemove(pTq->tqMetaNew, req.subKey, strlen(req.subKey));*/
|
||||
/*return 0;*/
|
||||
/*}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ static int tsdbMergeBlockData(SCommitH *pCommith, SCommitIter *pIter, SDataCols
|
|||
static void tsdbResetCommitTable(SCommitH *pCommith);
|
||||
static void tsdbCloseCommitFile(SCommitH *pCommith, bool hasError);
|
||||
static bool tsdbCanAddSubBlock(SCommitH *pCommith, SBlock *pBlock, SMergeInfo *pInfo);
|
||||
static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIter *pCommitIter, SDataCols *pTarget,
|
||||
static void tsdbLoadAndMergeFromCache(STsdb *pTsdb, SDataCols *pDataCols, int *iter, SCommitIter *pCommitIter, SDataCols *pTarget,
|
||||
TSKEY maxKey, int maxRows, int8_t update);
|
||||
int tsdbWriteBlockIdx(SDFile *pHeadf, SArray *pIdxA, void **ppBuf);
|
||||
|
||||
|
@ -301,7 +301,8 @@ static void tsdbSeekCommitIter(SCommitH *pCommith, TSKEY key) {
|
|||
SCommitIter *pIter = pCommith->iters + i;
|
||||
if (pIter->pTable == NULL || pIter->pIter == NULL) continue;
|
||||
|
||||
tsdbLoadDataFromCache(pIter->pTable, pIter->pIter, key - 1, INT32_MAX, NULL, NULL, 0, true, NULL);
|
||||
tsdbLoadDataFromCache(TSDB_COMMIT_REPO(pCommith), pIter->pTable, pIter->pIter, key - 1, INT32_MAX, NULL, NULL, 0,
|
||||
true, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -947,7 +948,7 @@ static int tsdbMoveBlkIdx(SCommitH *pCommith, SBlockIdx *pIdx) {
|
|||
}
|
||||
|
||||
static int tsdbSetCommitTable(SCommitH *pCommith, STable *pTable) {
|
||||
STSchema *pSchema = tsdbGetTableSchemaImpl(pTable, false, false, -1);
|
||||
STSchema *pSchema = tsdbGetTableSchemaImpl(TSDB_COMMIT_REPO(pCommith),pTable, false, false, -1);
|
||||
|
||||
pCommith->pTable = pTable;
|
||||
|
||||
|
@ -1254,8 +1255,8 @@ static int tsdbCommitMemData(SCommitH *pCommith, SCommitIter *pIter, TSKEY keyLi
|
|||
SBlock block;
|
||||
|
||||
while (true) {
|
||||
tsdbLoadDataFromCache(pIter->pTable, pIter->pIter, keyLimit, defaultRows, pCommith->pDataCols, NULL, 0,
|
||||
pCfg->update, &mInfo);
|
||||
tsdbLoadDataFromCache(TSDB_COMMIT_REPO(pCommith), pIter->pTable, pIter->pIter, keyLimit, defaultRows,
|
||||
pCommith->pDataCols, NULL, 0, pCfg->update, &mInfo);
|
||||
|
||||
if (pCommith->pDataCols->numOfRows <= 0) break;
|
||||
|
||||
|
@ -1298,8 +1299,9 @@ static int tsdbMergeMemData(SCommitH *pCommith, SCommitIter *pIter, int bidx) {
|
|||
SSkipListIterator titer = *(pIter->pIter);
|
||||
if (tsdbLoadBlockDataCols(&(pCommith->readh), pBlock, NULL, &colId, 1, false) < 0) return -1;
|
||||
|
||||
tsdbLoadDataFromCache(pIter->pTable, &titer, keyLimit, INT32_MAX, NULL, pCommith->readh.pDCols[0]->cols[0].pData,
|
||||
pCommith->readh.pDCols[0]->numOfRows, pCfg->update, &mInfo);
|
||||
tsdbLoadDataFromCache(TSDB_COMMIT_REPO(pCommith), pIter->pTable, &titer, keyLimit, INT32_MAX, NULL,
|
||||
pCommith->readh.pDCols[0]->cols[0].pData, pCommith->readh.pDCols[0]->numOfRows, pCfg->update,
|
||||
&mInfo);
|
||||
|
||||
if (mInfo.nOperations == 0) {
|
||||
// no new data to insert (all updates denied)
|
||||
|
@ -1313,9 +1315,9 @@ static int tsdbMergeMemData(SCommitH *pCommith, SCommitIter *pIter, int bidx) {
|
|||
*(pIter->pIter) = titer;
|
||||
} else if (tsdbCanAddSubBlock(pCommith, pBlock, &mInfo)) {
|
||||
// Add a sub-block
|
||||
tsdbLoadDataFromCache(pIter->pTable, pIter->pIter, keyLimit, INT32_MAX, pCommith->pDataCols,
|
||||
pCommith->readh.pDCols[0]->cols[0].pData, pCommith->readh.pDCols[0]->numOfRows, pCfg->update,
|
||||
&mInfo);
|
||||
tsdbLoadDataFromCache(TSDB_COMMIT_REPO(pCommith), pIter->pTable, pIter->pIter, keyLimit, INT32_MAX,
|
||||
pCommith->pDataCols, pCommith->readh.pDCols[0]->cols[0].pData,
|
||||
pCommith->readh.pDCols[0]->numOfRows, pCfg->update, &mInfo);
|
||||
if (pBlock->last) {
|
||||
pDFile = TSDB_COMMIT_LAST_FILE(pCommith);
|
||||
} else {
|
||||
|
@ -1420,7 +1422,7 @@ static int tsdbMergeBlockData(SCommitH *pCommith, SCommitIter *pIter, SDataCols
|
|||
|
||||
int biter = 0;
|
||||
while (true) {
|
||||
tsdbLoadAndMergeFromCache(pCommith->readh.pDCols[0], &biter, pIter, pCommith->pDataCols, keyLimit, defaultRows,
|
||||
tsdbLoadAndMergeFromCache(TSDB_COMMIT_REPO(pCommith), pCommith->readh.pDCols[0], &biter, pIter, pCommith->pDataCols, keyLimit, defaultRows,
|
||||
pCfg->update);
|
||||
|
||||
if (pCommith->pDataCols->numOfRows == 0) break;
|
||||
|
@ -1445,7 +1447,7 @@ static int tsdbMergeBlockData(SCommitH *pCommith, SCommitIter *pIter, SDataCols
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIter *pCommitIter, SDataCols *pTarget,
|
||||
static void tsdbLoadAndMergeFromCache(STsdb *pTsdb, SDataCols *pDataCols, int *iter, SCommitIter *pCommitIter, SDataCols *pTarget,
|
||||
TSKEY maxKey, int maxRows, int8_t update) {
|
||||
TSKEY key1 = INT64_MAX;
|
||||
TSKEY key2 = INT64_MAX;
|
||||
|
@ -1487,7 +1489,7 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt
|
|||
++(*iter);
|
||||
} else if (key1 > key2) {
|
||||
if (pSchema == NULL || schemaVersion(pSchema) != TD_ROW_SVER(row)) {
|
||||
pSchema = tsdbGetTableSchemaImpl(pCommitIter->pTable, false, false, TD_ROW_SVER(row));
|
||||
pSchema = tsdbGetTableSchemaImpl(pTsdb, pCommitIter->pTable, false, false, TD_ROW_SVER(row));
|
||||
ASSERT(pSchema != NULL);
|
||||
}
|
||||
|
||||
|
@ -1527,7 +1529,7 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt
|
|||
if (TD_SUPPORT_UPDATE(update)) {
|
||||
// copy mem data(Multi-Version)
|
||||
if (pSchema == NULL || schemaVersion(pSchema) != TD_ROW_SVER(row)) {
|
||||
pSchema = tsdbGetTableSchemaImpl(pCommitIter->pTable, false, false, TD_ROW_SVER(row));
|
||||
pSchema = tsdbGetTableSchemaImpl(pTsdb, pCommitIter->pTable, false, false, TD_ROW_SVER(row));
|
||||
ASSERT(pSchema != NULL);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,8 @@ static void tsdbFreeTbData(STbData *pTbData);
|
|||
static char *tsdbGetTsTupleKey(const void *data);
|
||||
static int tsdbTbDataComp(const void *arg1, const void *arg2);
|
||||
static char *tsdbTbDataGetUid(const void *arg);
|
||||
static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema **ppSchema, STSRow *row, bool merge);
|
||||
static int tsdbAppendTableRowToCols(STsdb *pTsdb, STable *pTable, SDataCols *pCols, STSchema **ppSchema, STSRow *row,
|
||||
bool merge);
|
||||
|
||||
int tsdbMemTableCreate(STsdb *pTsdb, STsdbMemTable **ppMemTable) {
|
||||
STsdbMemTable *pMemTable;
|
||||
|
@ -88,8 +89,8 @@ void tsdbMemTableDestroy(STsdb *pTsdb, STsdbMemTable *pMemTable) {
|
|||
*
|
||||
* The function tries to procceed AS MUCH AS POSSIBLE.
|
||||
*/
|
||||
int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey, int maxRowsToRead, SDataCols *pCols,
|
||||
TKEY *filterKeys, int nFilterKeys, bool keepDup, SMergeInfo *pMergeInfo) {
|
||||
int tsdbLoadDataFromCache(STsdb *pTsdb, STable *pTable, SSkipListIterator *pIter, TSKEY maxKey, int maxRowsToRead,
|
||||
SDataCols *pCols, TKEY *filterKeys, int nFilterKeys, bool keepDup, SMergeInfo *pMergeInfo) {
|
||||
ASSERT(maxRowsToRead > 0 && nFilterKeys >= 0);
|
||||
if (pIter == NULL) return 0;
|
||||
STSchema *pSchema = NULL;
|
||||
|
@ -222,12 +223,12 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey
|
|||
if (lastKey != TSKEY_INITIAL_VAL) {
|
||||
++pCols->numOfRows;
|
||||
}
|
||||
tsdbAppendTableRowToCols(pTable, pCols, &pSchema, row, false);
|
||||
tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, false);
|
||||
}
|
||||
lastKey = rowKey;
|
||||
} else {
|
||||
if (keepDup) {
|
||||
tsdbAppendTableRowToCols(pTable, pCols, &pSchema, row, true);
|
||||
tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, true);
|
||||
} else {
|
||||
// discard
|
||||
}
|
||||
|
@ -249,7 +250,7 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey
|
|||
if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break;
|
||||
pMergeInfo->rowsDeleteSucceed++;
|
||||
pMergeInfo->nOperations++;
|
||||
tsdbAppendTableRowToCols(pTable, pCols, &pSchema, row, false);
|
||||
tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, false);
|
||||
} else {
|
||||
if (keepDup) {
|
||||
if (pCols && pMergeInfo->nOperations >= pCols->maxPoints) break;
|
||||
|
@ -262,11 +263,11 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey
|
|||
if (lastKey != TSKEY_INITIAL_VAL) {
|
||||
++pCols->numOfRows;
|
||||
}
|
||||
tsdbAppendTableRowToCols(pTable, pCols, &pSchema, row, false);
|
||||
tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, false);
|
||||
}
|
||||
lastKey = rowKey;
|
||||
} else {
|
||||
tsdbAppendTableRowToCols(pTable, pCols, &pSchema, row, true);
|
||||
tsdbAppendTableRowToCols(pTsdb, pTable, pCols, &pSchema, row, true);
|
||||
}
|
||||
} else {
|
||||
pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, fKey);
|
||||
|
@ -321,7 +322,7 @@ int tsdbInsertTableData(STsdb *pTsdb, SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlo
|
|||
return -1;
|
||||
}
|
||||
strcat(pRsp->tblFName, mr.me.name);
|
||||
|
||||
|
||||
if (mr.me.type == TSDB_NORMAL_TABLE) {
|
||||
sverNew = mr.me.ntbEntry.schema.sver;
|
||||
} else {
|
||||
|
@ -431,10 +432,12 @@ static char *tsdbTbDataGetUid(const void *arg) {
|
|||
STbData *pTbData = (STbData *)arg;
|
||||
return (char *)(&(pTbData->uid));
|
||||
}
|
||||
static int tsdbAppendTableRowToCols(STable *pTable, SDataCols *pCols, STSchema **ppSchema, STSRow *row, bool merge) {
|
||||
|
||||
static int tsdbAppendTableRowToCols(STsdb *pTsdb, STable *pTable, SDataCols *pCols, STSchema **ppSchema, STSRow *row,
|
||||
bool merge) {
|
||||
if (pCols) {
|
||||
if (*ppSchema == NULL || schemaVersion(*ppSchema) != TD_ROW_SVER(row)) {
|
||||
*ppSchema = tsdbGetTableSchemaImpl(pTable, false, false, TD_ROW_SVER(row));
|
||||
*ppSchema = tsdbGetTableSchemaImpl(pTsdb, pTable, false, false, TD_ROW_SVER(row));
|
||||
if (*ppSchema == NULL) {
|
||||
ASSERT(false);
|
||||
return -1;
|
||||
|
|
|
@ -157,7 +157,7 @@ int tsdbLoadBlockIdx(SReadH *pReadh) {
|
|||
}
|
||||
|
||||
int tsdbSetReadTable(SReadH *pReadh, STable *pTable) {
|
||||
STSchema *pSchema = tsdbGetTableSchemaImpl(pTable, false, false, -1);
|
||||
STSchema *pSchema = tsdbGetTableSchemaImpl(TSDB_READ_REPO(pReadh), pTable, false, false, -1);
|
||||
|
||||
pReadh->pTable = pTable;
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "tsdb.h"
|
||||
|
||||
struct STsdbSnapshotReader {
|
||||
STsdb* pTsdb;
|
||||
// TODO
|
||||
};
|
||||
|
||||
int32_t tsdbSnapshotReaderOpen(STsdb* pTsdb, STsdbSnapshotReader** ppReader, int64_t sver, int64_t ever) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tsdbSnapshotReaderClose(STsdbSnapshotReader* pReader) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tsdbSnapshotRead(STsdbSnapshotReader* pReader, void** ppData, uint32_t* nData) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "vnodeInt.h"
|
||||
|
||||
struct SVSnapshotReader {
|
||||
SVnode *pVnode;
|
||||
int64_t sver;
|
||||
int64_t ever;
|
||||
int8_t isMetaEnd;
|
||||
int8_t isTsdbEnd;
|
||||
SMetaSnapshotReader *pMetaReader;
|
||||
STsdbSnapshotReader *pTsdbReader;
|
||||
void *pData;
|
||||
int32_t nData;
|
||||
};
|
||||
|
||||
int32_t vnodeSnapshotReaderOpen(SVnode *pVnode, SVSnapshotReader **ppReader, int64_t sver, int64_t ever) {
|
||||
SVSnapshotReader *pReader = NULL;
|
||||
|
||||
pReader = (SVSnapshotReader *)taosMemoryCalloc(1, sizeof(*pReader));
|
||||
if (pReader == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
}
|
||||
pReader->pVnode = pVnode;
|
||||
pReader->sver = sver;
|
||||
pReader->ever = ever;
|
||||
pReader->isMetaEnd = 0;
|
||||
pReader->isTsdbEnd = 0;
|
||||
|
||||
if (metaSnapshotReaderOpen(pVnode->pMeta, &pReader->pMetaReader, sver, ever) < 0) {
|
||||
taosMemoryFree(pReader);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
if (tsdbSnapshotReaderOpen(pVnode->pTsdb, &pReader->pTsdbReader, sver, ever) < 0) {
|
||||
metaSnapshotReaderClose(pReader->pMetaReader);
|
||||
taosMemoryFree(pReader);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
_exit:
|
||||
*ppReader = pReader;
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
*ppReader = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t vnodeSnapshotReaderClose(SVSnapshotReader *pReader) {
|
||||
if (pReader) {
|
||||
vnodeFree(pReader->pData);
|
||||
tsdbSnapshotReaderClose(pReader->pTsdbReader);
|
||||
metaSnapshotReaderClose(pReader->pMetaReader);
|
||||
taosMemoryFree(pReader);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t vnodeSnapshotRead(SVSnapshotReader *pReader, const void **ppData, uint32_t *nData) {
|
||||
int32_t code = 0;
|
||||
|
||||
if (!pReader->isMetaEnd) {
|
||||
code = metaSnapshotRead(pReader->pMetaReader, &pReader->pData, &pReader->nData);
|
||||
if (code) {
|
||||
if (code == TSDB_CODE_VND_READ_END) {
|
||||
pReader->isMetaEnd = 1;
|
||||
} else {
|
||||
return code;
|
||||
}
|
||||
} else {
|
||||
*ppData = pReader->pData;
|
||||
*nData = pReader->nData;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pReader->isTsdbEnd) {
|
||||
code = tsdbSnapshotRead(pReader->pTsdbReader, &pReader->pData, &pReader->nData);
|
||||
if (code) {
|
||||
if (code == TSDB_CODE_VND_READ_END) {
|
||||
pReader->isTsdbEnd = 1;
|
||||
} else {
|
||||
return code;
|
||||
}
|
||||
} else {
|
||||
*ppData = pReader->pData;
|
||||
*nData = pReader->nData;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
||||
code = TSDB_CODE_VND_READ_END;
|
||||
return code;
|
||||
}
|
|
@ -617,16 +617,18 @@ static int vnodeDebugPrintSingleSubmitMsg(SMeta *pMeta, SSubmitBlk *pBlock, SSub
|
|||
STSchema *pSchema = NULL;
|
||||
tb_uid_t suid = 0;
|
||||
STSRow *row = NULL;
|
||||
int32_t rv = -1;
|
||||
|
||||
tInitSubmitBlkIter(msgIter, pBlock, &blkIter);
|
||||
if (blkIter.row == NULL) return 0;
|
||||
if (!pSchema || (suid != msgIter->suid)) {
|
||||
if (!pSchema || (suid != msgIter->suid) || rv != TD_ROW_SVER(blkIter.row)) {
|
||||
if (pSchema) {
|
||||
taosMemoryFreeClear(pSchema);
|
||||
}
|
||||
pSchema = metaGetTbTSchema(pMeta, msgIter->suid, 1); // TODO: use the real schema
|
||||
pSchema = metaGetTbTSchema(pMeta, msgIter->suid, TD_ROW_SVER(blkIter.row)); // TODO: use the real schema
|
||||
if (pSchema) {
|
||||
suid = msgIter->suid;
|
||||
rv = TD_ROW_SVER(blkIter.row);
|
||||
}
|
||||
}
|
||||
if (!pSchema) {
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "vnd.h"
|
||||
|
||||
int32_t vnodeRealloc(void** pp, int32_t size) {
|
||||
uint8_t* p = NULL;
|
||||
int32_t csize = 0;
|
||||
|
||||
if (*pp) {
|
||||
p = (uint8_t*)(*pp) - sizeof(int32_t);
|
||||
csize = *(int32_t*)p;
|
||||
}
|
||||
|
||||
if (csize >= size) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
p = (uint8_t*)taosMemoryRealloc(p, size);
|
||||
if (p == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
*(int32_t*)p = size;
|
||||
*pp = p + sizeof(int32_t);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vnodeFree(void* p) {
|
||||
if (p) {
|
||||
taosMemoryFree(((uint8_t*)p) - sizeof(int32_t));
|
||||
}
|
||||
}
|
|
@ -171,7 +171,7 @@ typedef struct SCtgJob {
|
|||
uint64_t queryId;
|
||||
SCatalog* pCtg;
|
||||
void* pTrans;
|
||||
const SEpSet* pMgmtEps;
|
||||
SEpSet pMgmtEps;
|
||||
void* userParam;
|
||||
catalogCallback userFp;
|
||||
int32_t tbMetaNum;
|
||||
|
|
|
@ -540,12 +540,6 @@ int32_t catalogGetHandle(uint64_t clusterId, SCatalog** catalogHandle) {
|
|||
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
}
|
||||
|
||||
SHashObj *metaCache = taosHashInit(gCtgMgmt.cfg.maxTblCacheNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
|
||||
if (NULL == metaCache) {
|
||||
qError("taosHashInit failed, num:%d", gCtgMgmt.cfg.maxTblCacheNum);
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
}
|
||||
|
||||
code = taosHashPut(gCtgMgmt.pCluster, &clusterId, sizeof(clusterId), &clusterCtg, POINTER_BYTES);
|
||||
if (code) {
|
||||
if (HASH_NODE_EXIST(code)) {
|
||||
|
|
|
@ -21,173 +21,189 @@
|
|||
#include "tref.h"
|
||||
|
||||
int32_t ctgInitGetTbMetaTask(SCtgJob *pJob, int32_t taskIdx, SName *name) {
|
||||
SCtgTask *pTask = taosArrayGet(pJob->pTasks, taskIdx);
|
||||
SCtgTask task = {0};
|
||||
|
||||
pTask->type = CTG_TASK_GET_TB_META;
|
||||
pTask->taskId = taskIdx;
|
||||
pTask->pJob = pJob;
|
||||
task.type = CTG_TASK_GET_TB_META;
|
||||
task.taskId = taskIdx;
|
||||
task.pJob = pJob;
|
||||
|
||||
pTask->taskCtx = taosMemoryCalloc(1, sizeof(SCtgTbMetaCtx));
|
||||
if (NULL == pTask->taskCtx) {
|
||||
task.taskCtx = taosMemoryCalloc(1, sizeof(SCtgTbMetaCtx));
|
||||
if (NULL == task.taskCtx) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SCtgTbMetaCtx* ctx = pTask->taskCtx;
|
||||
SCtgTbMetaCtx* ctx = task.taskCtx;
|
||||
ctx->pName = taosMemoryMalloc(sizeof(*name));
|
||||
if (NULL == ctx->pName) {
|
||||
taosMemoryFree(pTask->taskCtx);
|
||||
taosMemoryFree(task.taskCtx);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
memcpy(ctx->pName, name, sizeof(*name));
|
||||
ctx->flag = CTG_FLAG_UNKNOWN_STB;
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, tableName:%s", pJob->queryId, taskIdx, pTask->type, name->tname);
|
||||
taosArrayPush(pJob->pTasks, &task);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, tableName:%s", pJob->queryId, taskIdx, task.type, name->tname);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgInitGetDbVgTask(SCtgJob *pJob, int32_t taskIdx, char *dbFName) {
|
||||
SCtgTask *pTask = taosArrayGet(pJob->pTasks, taskIdx);
|
||||
SCtgTask task = {0};
|
||||
|
||||
pTask->type = CTG_TASK_GET_DB_VGROUP;
|
||||
pTask->taskId = taskIdx;
|
||||
pTask->pJob = pJob;
|
||||
task.type = CTG_TASK_GET_DB_VGROUP;
|
||||
task.taskId = taskIdx;
|
||||
task.pJob = pJob;
|
||||
|
||||
pTask->taskCtx = taosMemoryCalloc(1, sizeof(SCtgDbVgCtx));
|
||||
if (NULL == pTask->taskCtx) {
|
||||
task.taskCtx = taosMemoryCalloc(1, sizeof(SCtgDbVgCtx));
|
||||
if (NULL == task.taskCtx) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SCtgDbVgCtx* ctx = pTask->taskCtx;
|
||||
SCtgDbVgCtx* ctx = task.taskCtx;
|
||||
|
||||
memcpy(ctx->dbFName, dbFName, sizeof(ctx->dbFName));
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, dbFName:%s", pJob->queryId, taskIdx, pTask->type, dbFName);
|
||||
taosArrayPush(pJob->pTasks, &task);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, dbFName:%s", pJob->queryId, taskIdx, task.type, dbFName);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgInitGetDbCfgTask(SCtgJob *pJob, int32_t taskIdx, char *dbFName) {
|
||||
SCtgTask *pTask = taosArrayGet(pJob->pTasks, taskIdx);
|
||||
SCtgTask task = {0};
|
||||
|
||||
pTask->type = CTG_TASK_GET_DB_CFG;
|
||||
pTask->taskId = taskIdx;
|
||||
pTask->pJob = pJob;
|
||||
task.type = CTG_TASK_GET_DB_CFG;
|
||||
task.taskId = taskIdx;
|
||||
task.pJob = pJob;
|
||||
|
||||
pTask->taskCtx = taosMemoryCalloc(1, sizeof(SCtgDbCfgCtx));
|
||||
if (NULL == pTask->taskCtx) {
|
||||
task.taskCtx = taosMemoryCalloc(1, sizeof(SCtgDbCfgCtx));
|
||||
if (NULL == task.taskCtx) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SCtgDbCfgCtx* ctx = pTask->taskCtx;
|
||||
SCtgDbCfgCtx* ctx = task.taskCtx;
|
||||
|
||||
memcpy(ctx->dbFName, dbFName, sizeof(ctx->dbFName));
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, dbFName:%s", pJob->queryId, taskIdx, pTask->type, dbFName);
|
||||
taosArrayPush(pJob->pTasks, &task);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, dbFName:%s", pJob->queryId, taskIdx, task.type, dbFName);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgInitGetTbHashTask(SCtgJob *pJob, int32_t taskIdx, SName *name) {
|
||||
SCtgTask *pTask = taosArrayGet(pJob->pTasks, taskIdx);
|
||||
SCtgTask task = {0};
|
||||
|
||||
pTask->type = CTG_TASK_GET_TB_HASH;
|
||||
pTask->taskId = taskIdx;
|
||||
pTask->pJob = pJob;
|
||||
task.type = CTG_TASK_GET_TB_HASH;
|
||||
task.taskId = taskIdx;
|
||||
task.pJob = pJob;
|
||||
|
||||
pTask->taskCtx = taosMemoryCalloc(1, sizeof(SCtgTbHashCtx));
|
||||
if (NULL == pTask->taskCtx) {
|
||||
task.taskCtx = taosMemoryCalloc(1, sizeof(SCtgTbHashCtx));
|
||||
if (NULL == task.taskCtx) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SCtgTbHashCtx* ctx = pTask->taskCtx;
|
||||
SCtgTbHashCtx* ctx = task.taskCtx;
|
||||
ctx->pName = taosMemoryMalloc(sizeof(*name));
|
||||
if (NULL == ctx->pName) {
|
||||
taosMemoryFree(pTask->taskCtx);
|
||||
taosMemoryFree(task.taskCtx);
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
memcpy(ctx->pName, name, sizeof(*name));
|
||||
tNameGetFullDbName(ctx->pName, ctx->dbFName);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, tableName:%s", pJob->queryId, taskIdx, pTask->type, name->tname);
|
||||
taosArrayPush(pJob->pTasks, &task);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, tableName:%s", pJob->queryId, taskIdx, task.type, name->tname);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgInitGetQnodeTask(SCtgJob *pJob, int32_t taskIdx) {
|
||||
SCtgTask *pTask = taosArrayGet(pJob->pTasks, taskIdx);
|
||||
SCtgTask task = {0};
|
||||
|
||||
pTask->type = CTG_TASK_GET_QNODE;
|
||||
pTask->taskId = taskIdx;
|
||||
pTask->pJob = pJob;
|
||||
pTask->taskCtx = NULL;
|
||||
task.type = CTG_TASK_GET_QNODE;
|
||||
task.taskId = taskIdx;
|
||||
task.pJob = pJob;
|
||||
task.taskCtx = NULL;
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized", pJob->queryId, taskIdx, pTask->type);
|
||||
taosArrayPush(pJob->pTasks, &task);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized", pJob->queryId, taskIdx, task.type);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgInitGetIndexTask(SCtgJob *pJob, int32_t taskIdx, char *name) {
|
||||
SCtgTask *pTask = taosArrayGet(pJob->pTasks, taskIdx);
|
||||
SCtgTask task = {0};
|
||||
|
||||
pTask->type = CTG_TASK_GET_INDEX;
|
||||
pTask->taskId = taskIdx;
|
||||
pTask->pJob = pJob;
|
||||
task.type = CTG_TASK_GET_INDEX;
|
||||
task.taskId = taskIdx;
|
||||
task.pJob = pJob;
|
||||
|
||||
pTask->taskCtx = taosMemoryCalloc(1, sizeof(SCtgIndexCtx));
|
||||
if (NULL == pTask->taskCtx) {
|
||||
task.taskCtx = taosMemoryCalloc(1, sizeof(SCtgIndexCtx));
|
||||
if (NULL == task.taskCtx) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SCtgIndexCtx* ctx = pTask->taskCtx;
|
||||
SCtgIndexCtx* ctx = task.taskCtx;
|
||||
|
||||
strcpy(ctx->indexFName, name);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, indexFName:%s", pJob->queryId, taskIdx, pTask->type, name);
|
||||
taosArrayPush(pJob->pTasks, &task);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, indexFName:%s", pJob->queryId, taskIdx, task.type, name);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgInitGetUdfTask(SCtgJob *pJob, int32_t taskIdx, char *name) {
|
||||
SCtgTask *pTask = taosArrayGet(pJob->pTasks, taskIdx);
|
||||
SCtgTask task = {0};
|
||||
|
||||
pTask->type = CTG_TASK_GET_UDF;
|
||||
pTask->taskId = taskIdx;
|
||||
pTask->pJob = pJob;
|
||||
task.type = CTG_TASK_GET_UDF;
|
||||
task.taskId = taskIdx;
|
||||
task.pJob = pJob;
|
||||
|
||||
pTask->taskCtx = taosMemoryCalloc(1, sizeof(SCtgUdfCtx));
|
||||
if (NULL == pTask->taskCtx) {
|
||||
task.taskCtx = taosMemoryCalloc(1, sizeof(SCtgUdfCtx));
|
||||
if (NULL == task.taskCtx) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SCtgUdfCtx* ctx = pTask->taskCtx;
|
||||
SCtgUdfCtx* ctx = task.taskCtx;
|
||||
|
||||
strcpy(ctx->udfName, name);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, udfName:%s", pJob->queryId, taskIdx, pTask->type, name);
|
||||
taosArrayPush(pJob->pTasks, &task);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, udfName:%s", pJob->queryId, taskIdx, task.type, name);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgInitGetUserTask(SCtgJob *pJob, int32_t taskIdx, SUserAuthInfo *user) {
|
||||
SCtgTask *pTask = taosArrayGet(pJob->pTasks, taskIdx);
|
||||
SCtgTask task = {0};
|
||||
|
||||
pTask->type = CTG_TASK_GET_USER;
|
||||
pTask->taskId = taskIdx;
|
||||
pTask->pJob = pJob;
|
||||
task.type = CTG_TASK_GET_USER;
|
||||
task.taskId = taskIdx;
|
||||
task.pJob = pJob;
|
||||
|
||||
pTask->taskCtx = taosMemoryCalloc(1, sizeof(SCtgUserCtx));
|
||||
if (NULL == pTask->taskCtx) {
|
||||
task.taskCtx = taosMemoryCalloc(1, sizeof(SCtgUserCtx));
|
||||
if (NULL == task.taskCtx) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SCtgUserCtx* ctx = pTask->taskCtx;
|
||||
SCtgUserCtx* ctx = task.taskCtx;
|
||||
|
||||
memcpy(&ctx->user, user, sizeof(*user));
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, user:%s", pJob->queryId, taskIdx, pTask->type, user->user);
|
||||
taosArrayPush(pJob->pTasks, &task);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d type %d initialized, user:%s", pJob->queryId, taskIdx, task.type, user->user);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -222,7 +238,7 @@ int32_t ctgInitJob(CTG_PARAMS, SCtgJob** job, uint64_t reqId, const SCatalogReq*
|
|||
pJob->userFp = fp;
|
||||
pJob->pCtg = pCtg;
|
||||
pJob->pTrans = pTrans;
|
||||
pJob->pMgmtEps = pMgmtEps;
|
||||
pJob->pMgmtEps = *pMgmtEps;
|
||||
pJob->userParam = param;
|
||||
|
||||
pJob->tbMetaNum = tbMetaNum;
|
||||
|
@ -303,15 +319,13 @@ _return:
|
|||
int32_t ctgDumpTbMetaRes(SCtgTask* pTask) {
|
||||
SCtgJob* pJob = pTask->pJob;
|
||||
if (NULL == pJob->jobRes.pTableMeta) {
|
||||
pJob->jobRes.pTableMeta = taosArrayInit(pJob->tbMetaNum, sizeof(STableMeta));
|
||||
pJob->jobRes.pTableMeta = taosArrayInit(pJob->tbMetaNum, POINTER_BYTES);
|
||||
if (NULL == pJob->jobRes.pTableMeta) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
|
||||
taosArrayPush(pJob->jobRes.pTableMeta, pTask->res);
|
||||
|
||||
taosMemoryFreeClear(pTask->res);
|
||||
taosArrayPush(pJob->jobRes.pTableMeta, &pTask->res);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -340,7 +354,7 @@ int32_t ctgDumpTbHashRes(SCtgTask* pTask) {
|
|||
}
|
||||
}
|
||||
|
||||
taosArrayPush(pJob->jobRes.pTableHash, &pTask->res);
|
||||
taosArrayPush(pJob->jobRes.pTableHash, pTask->res);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -376,7 +390,7 @@ int32_t ctgDumpDbCfgRes(SCtgTask* pTask) {
|
|||
}
|
||||
}
|
||||
|
||||
taosArrayPush(pJob->jobRes.pDbCfg, &pTask->res);
|
||||
taosArrayPush(pJob->jobRes.pDbCfg, pTask->res);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -451,7 +465,7 @@ int32_t ctgHandleGetTbMetaRsp(SCtgTask* pTask, int32_t reqType, const SDataBuf *
|
|||
SCtgTbMetaCtx* ctx = (SCtgTbMetaCtx*)pTask->taskCtx;
|
||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||
void *pTrans = pTask->pJob->pTrans;
|
||||
const SEpSet* pMgmtEps = pTask->pJob->pMgmtEps;
|
||||
const SEpSet* pMgmtEps = &pTask->pJob->pMgmtEps;
|
||||
|
||||
switch (reqType) {
|
||||
case TDMT_MND_USE_DB: {
|
||||
|
@ -529,7 +543,7 @@ int32_t ctgHandleGetTbMetaRsp(SCtgTask* pTask, int32_t reqType, const SDataBuf *
|
|||
|
||||
taosMemoryFreeClear(pOut->tbMeta);
|
||||
|
||||
CTG_ERR_JRET(ctgGetTbMetaFromMnode(CTG_PARAMS_LIST(), ctx->pName, NULL, pTask));
|
||||
CTG_RET(ctgGetTbMetaFromMnode(CTG_PARAMS_LIST(), ctx->pName, NULL, pTask));
|
||||
} else if (CTG_IS_META_BOTH(pOut->metaType)) {
|
||||
int32_t exist = 0;
|
||||
if (!CTG_FLAG_IS_FORCE_UPDATE(ctx->flag)) {
|
||||
|
@ -538,7 +552,7 @@ int32_t ctgHandleGetTbMetaRsp(SCtgTask* pTask, int32_t reqType, const SDataBuf *
|
|||
|
||||
if (0 == exist) {
|
||||
TSWAP(pTask->msgCtx.lastOut, pTask->msgCtx.out);
|
||||
CTG_ERR_JRET(ctgGetTbMetaFromMnodeImpl(CTG_PARAMS_LIST(), pOut->dbFName, pOut->tbName, NULL, pTask));
|
||||
CTG_RET(ctgGetTbMetaFromMnodeImpl(CTG_PARAMS_LIST(), pOut->dbFName, pOut->tbName, NULL, pTask));
|
||||
} else {
|
||||
taosMemoryFreeClear(pOut->tbMeta);
|
||||
|
||||
|
@ -598,7 +612,7 @@ int32_t ctgHandleGetDbVgRsp(SCtgTask* pTask, int32_t reqType, const SDataBuf *pM
|
|||
SCtgDbVgCtx* ctx = (SCtgDbVgCtx*)pTask->taskCtx;
|
||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||
void *pTrans = pTask->pJob->pTrans;
|
||||
const SEpSet* pMgmtEps = pTask->pJob->pMgmtEps;
|
||||
const SEpSet* pMgmtEps = &pTask->pJob->pMgmtEps;
|
||||
|
||||
switch (reqType) {
|
||||
case TDMT_MND_USE_DB: {
|
||||
|
@ -632,7 +646,7 @@ int32_t ctgHandleGetTbHashRsp(SCtgTask* pTask, int32_t reqType, const SDataBuf *
|
|||
SCtgTbHashCtx* ctx = (SCtgTbHashCtx*)pTask->taskCtx;
|
||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||
void *pTrans = pTask->pJob->pTrans;
|
||||
const SEpSet* pMgmtEps = pTask->pJob->pMgmtEps;
|
||||
const SEpSet* pMgmtEps = &pTask->pJob->pMgmtEps;
|
||||
|
||||
switch (reqType) {
|
||||
case TDMT_MND_USE_DB: {
|
||||
|
@ -724,7 +738,7 @@ int32_t ctgHandleGetUserRsp(SCtgTask* pTask, int32_t reqType, const SDataBuf *pM
|
|||
SCtgUserCtx* ctx = (SCtgUserCtx*)pTask->taskCtx;
|
||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||
void *pTrans = pTask->pJob->pTrans;
|
||||
const SEpSet* pMgmtEps = pTask->pJob->pMgmtEps;
|
||||
const SEpSet* pMgmtEps = &pTask->pJob->pMgmtEps;
|
||||
bool pass = false;
|
||||
SGetUserAuthRsp* pOut = (SGetUserAuthRsp*)pTask->msgCtx.out;
|
||||
|
||||
|
@ -756,7 +770,7 @@ _return:
|
|||
}
|
||||
|
||||
ctgPutUpdateUserToQueue(pCtg, pOut, false);
|
||||
pTask->msgCtx.out = NULL;
|
||||
taosMemoryFreeClear(pTask->msgCtx.out);
|
||||
|
||||
ctgHandleTaskEnd(pTask, code);
|
||||
|
||||
|
@ -766,7 +780,7 @@ _return:
|
|||
int32_t ctgAsyncRefreshTbMeta(SCtgTask *pTask) {
|
||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||
void *pTrans = pTask->pJob->pTrans;
|
||||
const SEpSet* pMgmtEps = pTask->pJob->pMgmtEps;
|
||||
const SEpSet* pMgmtEps = &pTask->pJob->pMgmtEps;
|
||||
int32_t code = 0;
|
||||
SCtgTbMetaCtx* ctx = (SCtgTbMetaCtx*)pTask->taskCtx;
|
||||
|
||||
|
@ -788,7 +802,7 @@ int32_t ctgAsyncRefreshTbMeta(SCtgTask *pTask) {
|
|||
tNameGetFullDbName(ctx->pName, dbFName);
|
||||
|
||||
CTG_ERR_RET(ctgAcquireVgInfoFromCache(pCtg, dbFName, &dbCache));
|
||||
if (NULL == dbCache) {
|
||||
if (dbCache) {
|
||||
SVgroupInfo vgInfo = {0};
|
||||
CTG_ERR_RET(ctgGetVgInfoFromHashValue(pCtg, dbCache->vgInfo, ctx->pName, &vgInfo));
|
||||
|
||||
|
@ -817,7 +831,7 @@ _return:
|
|||
int32_t ctgLaunchGetTbMetaTask(SCtgTask *pTask) {
|
||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||
void *pTrans = pTask->pJob->pTrans;
|
||||
const SEpSet* pMgmtEps = pTask->pJob->pMgmtEps;
|
||||
const SEpSet* pMgmtEps = &pTask->pJob->pMgmtEps;
|
||||
|
||||
CTG_ERR_RET(ctgGetTbMetaFromCache(CTG_PARAMS_LIST(), (SCtgTbMetaCtx*)pTask->taskCtx, (STableMeta**)&pTask->res));
|
||||
if (pTask->res) {
|
||||
|
@ -834,7 +848,7 @@ int32_t ctgLaunchGetDbVgTask(SCtgTask *pTask) {
|
|||
int32_t code = 0;
|
||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||
void *pTrans = pTask->pJob->pTrans;
|
||||
const SEpSet* pMgmtEps = pTask->pJob->pMgmtEps;
|
||||
const SEpSet* pMgmtEps = &pTask->pJob->pMgmtEps;
|
||||
SCtgDBCache *dbCache = NULL;
|
||||
SCtgDbVgCtx* pCtx = (SCtgDbVgCtx*)pTask->taskCtx;
|
||||
|
||||
|
@ -866,7 +880,7 @@ int32_t ctgLaunchGetTbHashTask(SCtgTask *pTask) {
|
|||
int32_t code = 0;
|
||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||
void *pTrans = pTask->pJob->pTrans;
|
||||
const SEpSet* pMgmtEps = pTask->pJob->pMgmtEps;
|
||||
const SEpSet* pMgmtEps = &pTask->pJob->pMgmtEps;
|
||||
SCtgDBCache *dbCache = NULL;
|
||||
SCtgTbHashCtx* pCtx = (SCtgTbHashCtx*)pTask->taskCtx;
|
||||
|
||||
|
@ -901,7 +915,7 @@ _return:
|
|||
int32_t ctgLaunchGetQnodeTask(SCtgTask *pTask) {
|
||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||
void *pTrans = pTask->pJob->pTrans;
|
||||
const SEpSet* pMgmtEps = pTask->pJob->pMgmtEps;
|
||||
const SEpSet* pMgmtEps = &pTask->pJob->pMgmtEps;
|
||||
|
||||
CTG_ERR_RET(ctgGetQnodeListFromMnode(CTG_PARAMS_LIST(), NULL, pTask));
|
||||
|
||||
|
@ -911,7 +925,7 @@ int32_t ctgLaunchGetQnodeTask(SCtgTask *pTask) {
|
|||
int32_t ctgLaunchGetDbCfgTask(SCtgTask *pTask) {
|
||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||
void *pTrans = pTask->pJob->pTrans;
|
||||
const SEpSet* pMgmtEps = pTask->pJob->pMgmtEps;
|
||||
const SEpSet* pMgmtEps = &pTask->pJob->pMgmtEps;
|
||||
SCtgDbCfgCtx* pCtx = (SCtgDbCfgCtx*)pTask->taskCtx;
|
||||
|
||||
CTG_ERR_RET(ctgGetDBCfgFromMnode(CTG_PARAMS_LIST(), pCtx->dbFName, NULL, pTask));
|
||||
|
@ -922,7 +936,7 @@ int32_t ctgLaunchGetDbCfgTask(SCtgTask *pTask) {
|
|||
int32_t ctgLaunchGetIndexTask(SCtgTask *pTask) {
|
||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||
void *pTrans = pTask->pJob->pTrans;
|
||||
const SEpSet* pMgmtEps = pTask->pJob->pMgmtEps;
|
||||
const SEpSet* pMgmtEps = &pTask->pJob->pMgmtEps;
|
||||
SCtgIndexCtx* pCtx = (SCtgIndexCtx*)pTask->taskCtx;
|
||||
|
||||
CTG_ERR_RET(ctgGetIndexInfoFromMnode(CTG_PARAMS_LIST(), pCtx->indexFName, NULL, pTask));
|
||||
|
@ -933,7 +947,7 @@ int32_t ctgLaunchGetIndexTask(SCtgTask *pTask) {
|
|||
int32_t ctgLaunchGetUdfTask(SCtgTask *pTask) {
|
||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||
void *pTrans = pTask->pJob->pTrans;
|
||||
const SEpSet* pMgmtEps = pTask->pJob->pMgmtEps;
|
||||
const SEpSet* pMgmtEps = &pTask->pJob->pMgmtEps;
|
||||
SCtgUdfCtx* pCtx = (SCtgUdfCtx*)pTask->taskCtx;
|
||||
|
||||
CTG_ERR_RET(ctgGetUdfInfoFromMnode(CTG_PARAMS_LIST(), pCtx->udfName, NULL, pTask));
|
||||
|
@ -944,7 +958,7 @@ int32_t ctgLaunchGetUdfTask(SCtgTask *pTask) {
|
|||
int32_t ctgLaunchGetUserTask(SCtgTask *pTask) {
|
||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||
void *pTrans = pTask->pJob->pTrans;
|
||||
const SEpSet* pMgmtEps = pTask->pJob->pMgmtEps;
|
||||
const SEpSet* pMgmtEps = &pTask->pJob->pMgmtEps;
|
||||
SCtgUserCtx* pCtx = (SCtgUserCtx*)pTask->taskCtx;
|
||||
bool inCache = false;
|
||||
bool pass = false;
|
||||
|
|
|
@ -248,7 +248,7 @@ int32_t ctgReadTbMetaFromCache(SCatalog* pCtg, SCtgTbMetaCtx* ctx, STableMeta**
|
|||
|
||||
ctgAcquireDBCache(pCtg, dbFName, &dbCache);
|
||||
if (NULL == dbCache) {
|
||||
ctgDebug("db %s not in cache", ctx->pName->tname);
|
||||
ctgDebug("db %d.%s not in cache", ctx->pName->acctId, ctx->pName->dbname);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -715,7 +715,7 @@ int32_t ctgPutUpdateUserToQueue(SCatalog* pCtg, SGetUserAuthRsp *pAuth, bool syn
|
|||
action.data = msg;
|
||||
|
||||
CTG_ERR_JRET(ctgPushAction(pCtg, &action));
|
||||
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
_return:
|
||||
|
@ -1457,10 +1457,15 @@ _return:
|
|||
CTG_RET(code);
|
||||
}
|
||||
|
||||
void ctgUpdateThreadFuncUnexpectedStopped(void) {
|
||||
if (CTG_IS_LOCKED(&gCtgMgmt.lock) > 0) CTG_UNLOCK(CTG_READ, &gCtgMgmt.lock);
|
||||
}
|
||||
|
||||
void* ctgUpdateThreadFunc(void* param) {
|
||||
setThreadName("catalog");
|
||||
|
||||
#ifdef WINDOWS
|
||||
atexit(ctgUpdateThreadFuncUnexpectedStopped);
|
||||
#endif
|
||||
qInfo("catalog update thread started");
|
||||
|
||||
CTG_LOCK(CTG_READ, &gCtgMgmt.lock);
|
||||
|
@ -1494,7 +1499,7 @@ void* ctgUpdateThreadFunc(void* param) {
|
|||
ctgdShowClusterCache(pCtg);
|
||||
}
|
||||
|
||||
CTG_UNLOCK(CTG_READ, &gCtgMgmt.lock);
|
||||
if (CTG_IS_LOCKED(&gCtgMgmt.lock)) CTG_UNLOCK(CTG_READ, &gCtgMgmt.lock);
|
||||
|
||||
qInfo("catalog update thread stopped");
|
||||
|
||||
|
|
|
@ -21,6 +21,179 @@
|
|||
extern SCatalogMgmt gCtgMgmt;
|
||||
SCtgDebug gCTGDebug = {0};
|
||||
|
||||
void ctgdUserCallback(SMetaData* pResult, void* param, int32_t code) {
|
||||
ASSERT(*(int32_t*)param == 1);
|
||||
taosMemoryFree(param);
|
||||
|
||||
qDebug("async call result: %s", tstrerror(code));
|
||||
if (NULL == pResult) {
|
||||
qDebug("empty meta result");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t num = 0;
|
||||
|
||||
if (pResult->pTableMeta && taosArrayGetSize(pResult->pTableMeta) > 0) {
|
||||
num = taosArrayGetSize(pResult->pTableMeta);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
STableMeta *p = *(STableMeta **)taosArrayGet(pResult->pTableMeta, i);
|
||||
STableComInfo *c = &p->tableInfo;
|
||||
|
||||
if (TSDB_CHILD_TABLE == p->tableType) {
|
||||
qDebug("table meta: type:%d, vgId:%d, uid:%" PRIx64 ",suid:%" PRIx64, p->tableType, p->vgId, p->uid, p->suid);
|
||||
} else {
|
||||
qDebug("table meta: type:%d, vgId:%d, uid:%" PRIx64 ",suid:%" PRIx64 ",sv:%d, tv:%d, tagNum:%d, precision:%d, colNum:%d, rowSize:%d",
|
||||
p->tableType, p->vgId, p->uid, p->suid, p->sversion, p->tversion, c->numOfTags, c->precision, c->numOfColumns, c->rowSize);
|
||||
}
|
||||
|
||||
int32_t colNum = c->numOfColumns + c->numOfTags;
|
||||
for (int32_t j = 0; j < colNum; ++j) {
|
||||
SSchema *s = &p->schema[j];
|
||||
qDebug("[%d] name:%s, type:%d, colId:%d, bytes:%d", j, s->name, s->type, s->colId, s->bytes);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
qDebug("empty table meta");
|
||||
}
|
||||
|
||||
if (pResult->pDbVgroup && taosArrayGetSize(pResult->pDbVgroup) > 0) {
|
||||
num = taosArrayGetSize(pResult->pDbVgroup);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
SArray *pDb = *(SArray**)taosArrayGet(pResult->pDbVgroup, i);
|
||||
int32_t vgNum = taosArrayGetSize(pDb);
|
||||
qDebug("db %d vgInfo:", i);
|
||||
for (int32_t j = 0; j < vgNum; ++j) {
|
||||
SVgroupInfo* pInfo = taosArrayGet(pDb, j);
|
||||
qDebug("vg %d info: vgId:%d", j, pInfo->vgId);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
qDebug("empty db vgroup");
|
||||
}
|
||||
|
||||
if (pResult->pTableHash && taosArrayGetSize(pResult->pTableHash) > 0) {
|
||||
num = taosArrayGetSize(pResult->pTableHash);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
SVgroupInfo* pInfo = taosArrayGet(pResult->pTableHash, i);
|
||||
qDebug("table %d vg info: vgId:%d", i, pInfo->vgId);
|
||||
}
|
||||
} else {
|
||||
qDebug("empty table hash vgroup");
|
||||
}
|
||||
|
||||
if (pResult->pUdfList && taosArrayGetSize(pResult->pUdfList) > 0) {
|
||||
num = taosArrayGetSize(pResult->pUdfList);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
SFuncInfo* pInfo = taosArrayGet(pResult->pUdfList, i);
|
||||
qDebug("udf %d info: name:%s, funcType:%d", i, pInfo->name, pInfo->funcType);
|
||||
}
|
||||
} else {
|
||||
qDebug("empty udf info");
|
||||
}
|
||||
|
||||
if (pResult->pDbCfg && taosArrayGetSize(pResult->pDbCfg) > 0) {
|
||||
num = taosArrayGetSize(pResult->pDbCfg);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
SDbCfgInfo* pInfo = taosArrayGet(pResult->pDbCfg, i);
|
||||
qDebug("db %d info: numOFVgroups:%d, numOfStables:%d", i, pInfo->numOfVgroups, pInfo->numOfStables);
|
||||
}
|
||||
} else {
|
||||
qDebug("empty db cfg info");
|
||||
}
|
||||
|
||||
if (pResult->pUser && taosArrayGetSize(pResult->pUser) > 0) {
|
||||
num = taosArrayGetSize(pResult->pUser);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
bool* auth = taosArrayGet(pResult->pUser, i);
|
||||
qDebug("user auth %d info: %d", i, *auth);
|
||||
}
|
||||
} else {
|
||||
qDebug("empty user auth info");
|
||||
}
|
||||
|
||||
if (pResult->pQnodeList && taosArrayGetSize(pResult->pQnodeList) > 0) {
|
||||
num = taosArrayGetSize(pResult->pQnodeList);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
SQueryNodeAddr* qaddr = taosArrayGet(pResult->pQnodeList, i);
|
||||
qDebug("qnode %d info: id:%d", i, qaddr->nodeId);
|
||||
}
|
||||
} else {
|
||||
qDebug("empty qnode info");
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ctgdLaunchAsyncCall(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, uint64_t reqId) {
|
||||
int32_t code = 0;
|
||||
SCatalogReq req = {0};
|
||||
req.pTableMeta = taosArrayInit(2, sizeof(SName));
|
||||
req.pDbVgroup = taosArrayInit(2, TSDB_DB_FNAME_LEN);
|
||||
req.pTableHash = taosArrayInit(2, sizeof(SName));
|
||||
req.pUdf = taosArrayInit(2, TSDB_FUNC_NAME_LEN);
|
||||
req.pDbCfg = taosArrayInit(2, TSDB_DB_FNAME_LEN);
|
||||
req.pIndex = NULL;//taosArrayInit(2, TSDB_INDEX_FNAME_LEN);
|
||||
req.pUser = taosArrayInit(2, sizeof(SUserAuthInfo));
|
||||
req.qNodeRequired = true;
|
||||
|
||||
SName name = {0};
|
||||
char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
||||
char funcName[TSDB_FUNC_NAME_LEN] = {0};
|
||||
SUserAuthInfo user = {0};
|
||||
|
||||
tNameFromString(&name, "1.db1.tb1", T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
taosArrayPush(req.pTableMeta, &name);
|
||||
taosArrayPush(req.pTableHash, &name);
|
||||
tNameFromString(&name, "1.db1.st1", T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
taosArrayPush(req.pTableMeta, &name);
|
||||
taosArrayPush(req.pTableHash, &name);
|
||||
|
||||
strcpy(dbFName, "1.db1");
|
||||
taosArrayPush(req.pDbVgroup, dbFName);
|
||||
taosArrayPush(req.pDbCfg, dbFName);
|
||||
strcpy(dbFName, "1.db2");
|
||||
taosArrayPush(req.pDbVgroup, dbFName);
|
||||
taosArrayPush(req.pDbCfg, dbFName);
|
||||
|
||||
strcpy(funcName, "udf1");
|
||||
taosArrayPush(req.pUdf, funcName);
|
||||
strcpy(funcName, "udf2");
|
||||
taosArrayPush(req.pUdf, funcName);
|
||||
|
||||
strcpy(user.user, "root");
|
||||
strcpy(user.dbFName, "1.db1");
|
||||
user.type = AUTH_TYPE_READ;
|
||||
taosArrayPush(req.pUser, &user);
|
||||
user.type = AUTH_TYPE_WRITE;
|
||||
taosArrayPush(req.pUser, &user);
|
||||
user.type = AUTH_TYPE_OTHER;
|
||||
taosArrayPush(req.pUser, &user);
|
||||
|
||||
strcpy(user.user, "user1");
|
||||
strcpy(user.dbFName, "1.db2");
|
||||
user.type = AUTH_TYPE_READ;
|
||||
taosArrayPush(req.pUser, &user);
|
||||
user.type = AUTH_TYPE_WRITE;
|
||||
taosArrayPush(req.pUser, &user);
|
||||
user.type = AUTH_TYPE_OTHER;
|
||||
taosArrayPush(req.pUser, &user);
|
||||
|
||||
int32_t *param = taosMemoryCalloc(1, sizeof(int32_t));
|
||||
*param = 1;
|
||||
|
||||
int64_t jobId = 0;
|
||||
CTG_ERR_JRET(catalogAsyncGetAllMeta(pCtg, pTrans, pMgmtEps, reqId, &req, ctgdUserCallback, param, &jobId));
|
||||
|
||||
_return:
|
||||
|
||||
taosArrayDestroy(req.pTableMeta);
|
||||
taosArrayDestroy(req.pDbVgroup);
|
||||
taosArrayDestroy(req.pTableHash);
|
||||
taosArrayDestroy(req.pUdf);
|
||||
taosArrayDestroy(req.pDbCfg);
|
||||
taosArrayDestroy(req.pUser);
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgdEnableDebug(char *option) {
|
||||
if (0 == strcasecmp(option, "lock")) {
|
||||
gCTGDebug.lockEnable = true;
|
||||
|
|
|
@ -264,10 +264,11 @@ int32_t ctgGetQnodeListFromMnode(CTG_PARAMS, SArray *out, SCtgTask* pTask) {
|
|||
char *msg = NULL;
|
||||
int32_t msgLen = 0;
|
||||
int32_t reqType = TDMT_MND_QNODE_LIST;
|
||||
void*(*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont;
|
||||
|
||||
ctgDebug("try to get qnode list from mnode, mgmtEpInUse:%d", pMgmtEps->inUse);
|
||||
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](NULL, &msg, 0, &msgLen);
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](NULL, &msg, 0, &msgLen, mallocFp);
|
||||
if (code) {
|
||||
ctgError("Build qnode list msg failed, error:%s", tstrerror(code));
|
||||
CTG_ERR_RET(code);
|
||||
|
@ -301,10 +302,11 @@ int32_t ctgGetDBVgInfoFromMnode(CTG_PARAMS, SBuildUseDBInput *input, SUseDbOutpu
|
|||
char *msg = NULL;
|
||||
int32_t msgLen = 0;
|
||||
int32_t reqType = TDMT_MND_USE_DB;
|
||||
void*(*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont;
|
||||
|
||||
ctgDebug("try to get db vgInfo from mnode, dbFName:%s", input->db);
|
||||
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](input, &msg, 0, &msgLen);
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](input, &msg, 0, &msgLen, mallocFp);
|
||||
if (code) {
|
||||
ctgError("Build use db msg failed, code:%x, db:%s", code, input->db);
|
||||
CTG_ERR_RET(code);
|
||||
|
@ -338,10 +340,11 @@ int32_t ctgGetDBCfgFromMnode(CTG_PARAMS, const char *dbFName, SDbCfgInfo *out, S
|
|||
char *msg = NULL;
|
||||
int32_t msgLen = 0;
|
||||
int32_t reqType = TDMT_MND_GET_DB_CFG;
|
||||
void*(*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont;
|
||||
|
||||
ctgDebug("try to get db cfg from mnode, dbFName:%s", dbFName);
|
||||
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void *)dbFName, &msg, 0, &msgLen);
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void *)dbFName, &msg, 0, &msgLen, mallocFp);
|
||||
if (code) {
|
||||
ctgError("Build get db cfg msg failed, code:%x, db:%s", code, dbFName);
|
||||
CTG_ERR_RET(code);
|
||||
|
@ -375,10 +378,11 @@ int32_t ctgGetIndexInfoFromMnode(CTG_PARAMS, const char *indexName, SIndexInfo *
|
|||
char *msg = NULL;
|
||||
int32_t msgLen = 0;
|
||||
int32_t reqType = TDMT_MND_GET_INDEX;
|
||||
void*(*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont;
|
||||
|
||||
ctgDebug("try to get index from mnode, indexName:%s", indexName);
|
||||
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void *)indexName, &msg, 0, &msgLen);
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void *)indexName, &msg, 0, &msgLen, mallocFp);
|
||||
if (code) {
|
||||
ctgError("Build get index msg failed, code:%x, db:%s", code, indexName);
|
||||
CTG_ERR_RET(code);
|
||||
|
@ -412,10 +416,11 @@ int32_t ctgGetUdfInfoFromMnode(CTG_PARAMS, const char *funcName, SFuncInfo *out,
|
|||
char *msg = NULL;
|
||||
int32_t msgLen = 0;
|
||||
int32_t reqType = TDMT_MND_RETRIEVE_FUNC;
|
||||
void*(*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont;
|
||||
|
||||
ctgDebug("try to get udf info from mnode, funcName:%s", funcName);
|
||||
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void *)funcName, &msg, 0, &msgLen);
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void *)funcName, &msg, 0, &msgLen, mallocFp);
|
||||
if (code) {
|
||||
ctgError("Build get udf msg failed, code:%x, db:%s", code, funcName);
|
||||
CTG_ERR_RET(code);
|
||||
|
@ -449,10 +454,11 @@ int32_t ctgGetUserDbAuthFromMnode(CTG_PARAMS, const char *user, SGetUserAuthRsp
|
|||
char *msg = NULL;
|
||||
int32_t msgLen = 0;
|
||||
int32_t reqType = TDMT_MND_GET_USER_AUTH;
|
||||
void*(*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont;
|
||||
|
||||
ctgDebug("try to get user auth from mnode, user:%s", user);
|
||||
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void *)user, &msg, 0, &msgLen);
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void *)user, &msg, 0, &msgLen, mallocFp);
|
||||
if (code) {
|
||||
ctgError("Build get user auth msg failed, code:%x, db:%s", code, user);
|
||||
CTG_ERR_RET(code);
|
||||
|
@ -491,10 +497,11 @@ int32_t ctgGetTbMetaFromMnodeImpl(CTG_PARAMS, char *dbFName, char* tbName, STabl
|
|||
int32_t reqType = TDMT_MND_TABLE_META;
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||
sprintf(tbFName, "%s.%s", dbFName, tbName);
|
||||
void*(*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont;
|
||||
|
||||
ctgDebug("try to get table meta from mnode, tbFName:%s", tbFName);
|
||||
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](&bInput, &msg, 0, &msgLen);
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](&bInput, &msg, 0, &msgLen, mallocFp);
|
||||
if (code) {
|
||||
ctgError("Build mnode stablemeta msg failed, code:%x", code);
|
||||
CTG_ERR_RET(code);
|
||||
|
@ -537,6 +544,7 @@ int32_t ctgGetTbMetaFromVnode(CTG_PARAMS, const SName* pTableName, SVgroupInfo *
|
|||
int32_t reqType = TDMT_VND_TABLE_META;
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||
sprintf(tbFName, "%s.%s", dbFName, pTableName->tname);
|
||||
void*(*mallocFp)(int32_t) = pTask ? taosMemoryMalloc : rpcMallocCont;
|
||||
|
||||
ctgDebug("try to get table meta from vnode, vgId:%d, tbFName:%s", vgroupInfo->vgId, tbFName);
|
||||
|
||||
|
@ -544,7 +552,7 @@ int32_t ctgGetTbMetaFromVnode(CTG_PARAMS, const SName* pTableName, SVgroupInfo *
|
|||
char *msg = NULL;
|
||||
int32_t msgLen = 0;
|
||||
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](&bInput, &msg, 0, &msgLen);
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](&bInput, &msg, 0, &msgLen, mallocFp);
|
||||
if (code) {
|
||||
ctgError("Build vnode tablemeta msg failed, code:%x, tbFName:%s", code, tbFName);
|
||||
CTG_ERR_RET(code);
|
||||
|
|
|
@ -35,7 +35,7 @@ void ctgFreeSMetaData(SMetaData* pData) {
|
|||
|
||||
taosArrayDestroy(pData->pUdfList);
|
||||
pData->pUdfList = NULL;
|
||||
|
||||
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pData->pDbCfg); ++i) {
|
||||
SDbCfgInfo* pInfo = taosArrayGet(pData->pDbCfg, i);
|
||||
taosArrayDestroy(pInfo->pRetensions);
|
||||
|
@ -167,12 +167,15 @@ void ctgFreeHandle(SCatalog* pCtg) {
|
|||
|
||||
|
||||
void ctgFreeSUseDbOutput(SUseDbOutput* pOutput) {
|
||||
if (NULL == pOutput || NULL == pOutput->dbVgroup) {
|
||||
if (NULL == pOutput) {
|
||||
return;
|
||||
}
|
||||
|
||||
taosHashCleanup(pOutput->dbVgroup->vgHash);
|
||||
taosMemoryFreeClear(pOutput->dbVgroup);
|
||||
if (pOutput->dbVgroup) {
|
||||
taosHashCleanup(pOutput->dbVgroup->vgHash);
|
||||
taosMemoryFreeClear(pOutput->dbVgroup);
|
||||
}
|
||||
|
||||
taosMemoryFree(pOutput);
|
||||
}
|
||||
|
||||
|
@ -267,6 +270,7 @@ void ctgFreeTask(SCtgTask* pTask) {
|
|||
switch (pTask->type) {
|
||||
case CTG_TASK_GET_QNODE: {
|
||||
taosArrayDestroy((SArray*)pTask->res);
|
||||
taosMemoryFreeClear(pTask->taskCtx);
|
||||
pTask->res = NULL;
|
||||
break;
|
||||
}
|
||||
|
@ -277,17 +281,19 @@ void ctgFreeTask(SCtgTask* pTask) {
|
|||
ctgFreeSTableMetaOutput((STableMetaOutput*)pTask->msgCtx.lastOut);
|
||||
pTask->msgCtx.lastOut = NULL;
|
||||
}
|
||||
taosMemoryFreeClear(pTask->taskCtx);
|
||||
taosMemoryFreeClear(pTask->res);
|
||||
break;
|
||||
}
|
||||
case CTG_TASK_GET_DB_VGROUP: {
|
||||
taosArrayDestroy((SArray*)pTask->res);
|
||||
taosMemoryFreeClear(pTask->taskCtx);
|
||||
pTask->res = NULL;
|
||||
break;
|
||||
}
|
||||
case CTG_TASK_GET_DB_CFG: {
|
||||
taosMemoryFreeClear(pTask->taskCtx);
|
||||
if (pTask->res) {
|
||||
taosArrayDestroy(((SDbCfgInfo*)pTask->res)->pRetensions);
|
||||
taosMemoryFreeClear(pTask->res);
|
||||
}
|
||||
break;
|
||||
|
@ -295,6 +301,7 @@ void ctgFreeTask(SCtgTask* pTask) {
|
|||
case CTG_TASK_GET_TB_HASH: {
|
||||
SCtgTbHashCtx* taskCtx = (SCtgTbHashCtx*)pTask->taskCtx;
|
||||
taosMemoryFreeClear(taskCtx->pName);
|
||||
taosMemoryFreeClear(pTask->taskCtx);
|
||||
taosMemoryFreeClear(pTask->res);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "commandInt.h"
|
||||
#include "plannodes.h"
|
||||
#include "query.h"
|
||||
#include "tcommon.h"
|
||||
|
||||
int32_t qExplainGenerateResNode(SPhysiNode *pNode, SExplainGroup *group, SExplainResNode **pRes);
|
||||
int32_t qExplainAppendGroupResRows(void *pCtx, int32_t groupId, int32_t level);
|
||||
|
@ -637,13 +638,48 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
|
|||
QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
}
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, pSortNode->pSortKeys->length);
|
||||
|
||||
SDataBlockDescNode* pDescNode = pSortNode->node.pOutputDataBlockDesc;
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, nodesGetOutputNumFromSlotList(pDescNode->pSlots));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pSortNode->node.pOutputDataBlockDesc->totalRowSize);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pDescNode->totalRowSize);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT);
|
||||
EXPLAIN_ROW_END();
|
||||
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level));
|
||||
|
||||
if (EXPLAIN_MODE_ANALYZE == ctx->mode) {
|
||||
// sort key
|
||||
EXPLAIN_ROW_NEW(level, "Sort Key: ");
|
||||
if (pResNode->pExecInfo) {
|
||||
for (int32_t i = 0; i < LIST_LENGTH(pSortNode->pSortKeys); ++i) {
|
||||
SOrderByExprNode *ptn = nodesListGetNode(pSortNode->pSortKeys, i);
|
||||
EXPLAIN_ROW_APPEND("%s ", nodesGetNameFromColumnNode(ptn->pExpr));
|
||||
}
|
||||
}
|
||||
|
||||
EXPLAIN_ROW_END();
|
||||
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level));
|
||||
|
||||
// sort method
|
||||
EXPLAIN_ROW_NEW(level, "Sort Method: ");
|
||||
|
||||
int32_t nodeNum = taosArrayGetSize(pResNode->pExecInfo);
|
||||
SExplainExecInfo *execInfo = taosArrayGet(pResNode->pExecInfo, 0);
|
||||
SSortExecInfo * pExecInfo = (SSortExecInfo *)execInfo->verboseInfo;
|
||||
EXPLAIN_ROW_APPEND("%s", pExecInfo->sortMethod == SORT_QSORT_T ? "quicksort" : "merge sort");
|
||||
if (pExecInfo->sortBuffer > 1024 * 1024) {
|
||||
EXPLAIN_ROW_APPEND(" Buffers:%.2f Mb", pExecInfo->sortBuffer / (1024 * 1024.0));
|
||||
} else if (pExecInfo->sortBuffer > 1024) {
|
||||
EXPLAIN_ROW_APPEND(" Buffers:%.2f Kb", pExecInfo->sortBuffer / (1024.0));
|
||||
} else {
|
||||
EXPLAIN_ROW_APPEND(" Buffers:%d b", pExecInfo->sortBuffer);
|
||||
}
|
||||
|
||||
EXPLAIN_ROW_APPEND(" loops:%d", pExecInfo->loops);
|
||||
EXPLAIN_ROW_END();
|
||||
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level));
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
EXPLAIN_ROW_NEW(level + 1, EXPLAIN_OUTPUT_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT,
|
||||
|
@ -792,13 +828,8 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
|
|||
QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen));
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
}
|
||||
// EXPLAIN_ROW_APPEND(EXPLAIN_FUNCTIONS_FORMAT, pPartNode->length);
|
||||
// EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pPartNode->node.pOutputDataBlockDesc->totalRowSize);
|
||||
// if (pPartNode->pGroupKeys) {
|
||||
// EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT);
|
||||
// EXPLAIN_ROW_APPEND(EXPLAIN_GROUPS_FORMAT, pPartNode->pGroupKeys->length);
|
||||
// }
|
||||
|
||||
EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT);
|
||||
EXPLAIN_ROW_END();
|
||||
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level));
|
||||
|
|
|
@ -622,18 +622,14 @@ typedef struct SSortedMergeOperatorInfo {
|
|||
|
||||
typedef struct SSortOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
uint32_t sortBufSize; // max buffer size for in-memory sort
|
||||
uint32_t sortBufSize; // max buffer size for in-memory sort
|
||||
SArray* pSortInfo;
|
||||
SSortHandle* pSortHandle;
|
||||
SArray* pColMatchInfo; // for index map from table scan output
|
||||
int32_t bufPageSize;
|
||||
|
||||
// TODO extact struct
|
||||
int64_t startTs; // sort start time
|
||||
uint64_t sortElapsed; // sort elapsed time, time to flush to disk not included.
|
||||
uint64_t totalSize; // total load bytes from remote
|
||||
uint64_t totalRows; // total number of rows
|
||||
uint64_t totalElapsed; // total elapsed time
|
||||
int64_t startTs; // sort start time
|
||||
uint64_t sortElapsed; // sort elapsed time, time to flush to disk not included.
|
||||
} SSortOperatorInfo;
|
||||
|
||||
typedef struct STagFilterOperatorInfo {
|
||||
|
|
|
@ -137,6 +137,14 @@ void* tsortGetValue(STupleHandle* pVHandle, int32_t colId);
|
|||
*/
|
||||
SSDataBlock* tsortGetSortedDataBlock(const SSortHandle* pSortHandle);
|
||||
|
||||
/**
|
||||
* return the sort execution information.
|
||||
*
|
||||
* @param pHandle
|
||||
* @return
|
||||
*/
|
||||
SSortExecInfo tsortGetSortExecInfo(SSortHandle* pHandle);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1747,8 +1747,7 @@ void setFunctionResultOutput(SOptrBasicInfo* pInfo, SAggSupporter* pSup, int32_t
|
|||
SResultRow* pRow = doSetResultOutBufByKey(pSup->pResultBuf, pResultRowInfo, (char*)&tid, sizeof(tid), true, groupId,
|
||||
pTaskInfo, false, pSup);
|
||||
|
||||
ASSERT(pDataBlock->info.numOfCols == numOfExprs);
|
||||
for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) {
|
||||
for (int32_t i = 0; i < numOfExprs; ++i) {
|
||||
struct SResultRowEntryInfo* pEntry = getResultCell(pRow, i, rowCellInfoOffset);
|
||||
cleanupResultRowEntry(pEntry);
|
||||
|
||||
|
@ -1756,7 +1755,7 @@ void setFunctionResultOutput(SOptrBasicInfo* pInfo, SAggSupporter* pSup, int32_t
|
|||
pCtx[i].scanFlag = stage;
|
||||
}
|
||||
|
||||
initCtxOutputBuffer(pCtx, pDataBlock->info.numOfCols);
|
||||
initCtxOutputBuffer(pCtx, numOfExprs);
|
||||
}
|
||||
|
||||
void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t* bufCapacity, int32_t numOfInputRows) {
|
||||
|
|
|
@ -806,7 +806,7 @@ static SSDataBlock* getDataFromCatch(SStreamBlockScanInfo* pInfo) {
|
|||
SSDataBlock* pDB = createOneDataBlock(pInfo->pRes, false);
|
||||
blockDataFromBuf(pDB, buf);
|
||||
SSDataBlock* pSub = blockDataExtractBlock(pDB, pos->rowId, 1);
|
||||
blockDataMerge(pInfo->pRes, pSub, NULL);
|
||||
blockDataMerge(pInfo->pRes, pSub);
|
||||
blockDataDestroy(pDB);
|
||||
blockDataDestroy(pSub);
|
||||
}
|
||||
|
@ -1046,8 +1046,9 @@ static void destroySysScanOperator(void* param, int32_t numOfOutput) {
|
|||
blockDataDestroy(pInfo->pRes);
|
||||
|
||||
const char* name = tNameGetTableName(&pInfo->name);
|
||||
if (strncasecmp(name, TSDB_INS_TABLE_USER_TABLES, TSDB_TABLE_FNAME_LEN) == 0) {
|
||||
if (strncasecmp(name, TSDB_INS_TABLE_USER_TABLES, TSDB_TABLE_FNAME_LEN) == 0 || pInfo->pCur != NULL) {
|
||||
metaCloseTbCursor(pInfo->pCur);
|
||||
pInfo->pCur = NULL;
|
||||
}
|
||||
|
||||
taosArrayDestroy(pInfo->scanCols);
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
#include "executorimpl.h"
|
||||
|
||||
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, int32_t numOfOutput);
|
||||
|
||||
SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
|
@ -35,7 +38,7 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pR
|
|||
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, doSort, NULL, NULL, destroyOrderOperatorInfo, NULL, NULL, NULL);
|
||||
createOperatorFpSet(doOpenSortOperator, doSort, NULL, NULL, destroyOrderOperatorInfo, NULL, NULL, getExplainExecInfo);
|
||||
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
return pOperator;
|
||||
|
@ -121,20 +124,17 @@ void applyScalarFunction(SSDataBlock* pBlock, void* param) {
|
|||
}
|
||||
}
|
||||
|
||||
SSDataBlock* doSort(SOperatorInfo* pOperator) {
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
int32_t doOpenSortOperator(SOperatorInfo* pOperator) {
|
||||
SSortOperatorInfo* pInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
if (pOperator->status == OP_RES_TO_RETURN) {
|
||||
return getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, pInfo->pColMatchInfo);
|
||||
if (OPTR_IS_OPENED(pOperator)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
// pInfo->binfo.pRes is not equalled to the input datablock.
|
||||
// int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize;
|
||||
pInfo->startTs = taosGetTimestampUs();
|
||||
|
||||
// pInfo->binfo.pRes is not equalled to the input datablock.
|
||||
pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, pInfo->pColMatchInfo, SORT_SINGLESOURCE_SORT,
|
||||
-1, -1, NULL, pTaskInfo->id.str);
|
||||
|
||||
|
@ -146,12 +146,39 @@ SSDataBlock* doSort(SOperatorInfo* pOperator) {
|
|||
|
||||
int32_t code = tsortOpen(pInfo->pSortHandle);
|
||||
taosMemoryFreeClear(ps);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
longjmp(pTaskInfo->env, terrno);
|
||||
}
|
||||
|
||||
pOperator->cost.openCost = (taosGetTimestampUs() - pInfo->startTs)/1000.0;
|
||||
pOperator->status = OP_RES_TO_RETURN;
|
||||
return getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, pInfo->pColMatchInfo);
|
||||
|
||||
OPTR_SET_OPENED(pOperator);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SSDataBlock* doSort(SOperatorInfo* pOperator) {
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
SSortOperatorInfo* pInfo = pOperator->info;
|
||||
|
||||
int32_t code = pOperator->fpSet._openFn(pOperator);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
longjmp(pTaskInfo->env, code);
|
||||
}
|
||||
|
||||
SSDataBlock* pBlock = getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, pInfo->pColMatchInfo);
|
||||
|
||||
if (pBlock != NULL) {
|
||||
pOperator->resultInfo.totalRows += pBlock->info.rows;
|
||||
} else {
|
||||
doSetOperatorCompleted(pOperator);
|
||||
}
|
||||
return pBlock;
|
||||
}
|
||||
|
||||
void destroyOrderOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
|
@ -161,3 +188,15 @@ void destroyOrderOperatorInfo(void* param, int32_t numOfOutput) {
|
|||
taosArrayDestroy(pInfo->pSortInfo);
|
||||
taosArrayDestroy(pInfo->pColMatchInfo);
|
||||
}
|
||||
|
||||
int32_t getExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len) {
|
||||
ASSERT(pOptr != NULL);
|
||||
SSortExecInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortExecInfo));
|
||||
|
||||
SSortOperatorInfo *pOperatorInfo = (SSortOperatorInfo*)pOptr->info;
|
||||
|
||||
*pInfo = tsortGetSortExecInfo(pOperatorInfo->pSortHandle);
|
||||
*pOptrExplain = pInfo;
|
||||
*len = sizeof(SSortExecInfo);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -31,20 +31,16 @@ struct STupleHandle {
|
|||
|
||||
struct SSortHandle {
|
||||
int32_t type;
|
||||
|
||||
int32_t pageSize;
|
||||
int32_t numOfPages;
|
||||
SDiskbasedBuf *pBuf;
|
||||
|
||||
SArray *pSortInfo;
|
||||
SArray *pIndexMap;
|
||||
SArray *pOrderedSource;
|
||||
|
||||
_sort_fetch_block_fn_t fetchfp;
|
||||
_sort_merge_compar_fn_t comparFn;
|
||||
SMultiwayMergeTreeInfo *pMergeTree;
|
||||
int64_t startTs;
|
||||
int32_t loops;
|
||||
uint64_t sortElapsed;
|
||||
int64_t startTs;
|
||||
uint64_t totalElapsed;
|
||||
|
||||
int32_t sourceId;
|
||||
|
@ -53,13 +49,15 @@ struct SSortHandle {
|
|||
int32_t numOfCompletedSources;
|
||||
bool opened;
|
||||
const char *idStr;
|
||||
|
||||
bool inMemSort;
|
||||
bool needAdjust;
|
||||
STupleHandle tupleHandle;
|
||||
|
||||
void *param;
|
||||
void (*beforeFp)(SSDataBlock* pBlock, void* param);
|
||||
|
||||
_sort_fetch_block_fn_t fetchfp;
|
||||
_sort_merge_compar_fn_t comparFn;
|
||||
SMultiwayMergeTreeInfo *pMergeTree;
|
||||
};
|
||||
|
||||
static int32_t msortComparFn(const void *pLeft, const void *pRight, void *param);
|
||||
|
@ -80,7 +78,7 @@ SSortHandle* tsortCreateSortHandle(SArray* pSortInfo, SArray* pIndexMap, int32_t
|
|||
pSortHandle->pageSize = pageSize;
|
||||
pSortHandle->numOfPages = numOfPages;
|
||||
pSortHandle->pSortInfo = pSortInfo;
|
||||
pSortHandle->pIndexMap = pIndexMap;
|
||||
pSortHandle->loops = 0;
|
||||
|
||||
if (pBlock != NULL) {
|
||||
pSortHandle->pDataBlock = createOneDataBlock(pBlock, false);
|
||||
|
@ -415,6 +413,9 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) {
|
|||
int32_t numOfRows = blockDataGetCapacityInRow(pHandle->pDataBlock, pHandle->pageSize);
|
||||
blockDataEnsureCapacity(pHandle->pDataBlock, numOfRows);
|
||||
|
||||
// the initial pass + sortPass + final mergePass
|
||||
pHandle->loops = sortPass + 2;
|
||||
|
||||
size_t numOfSorted = taosArrayGetSize(pHandle->pOrderedSource);
|
||||
for(int32_t t = 0; t < sortPass; ++t) {
|
||||
int64_t st = taosGetTimestampUs();
|
||||
|
@ -502,12 +503,13 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) {
|
||||
static int32_t createInitialSources(SSortHandle* pHandle) {
|
||||
size_t sortBufSize = pHandle->numOfPages * pHandle->pageSize;
|
||||
|
||||
if (pHandle->type == SORT_SINGLESOURCE_SORT) {
|
||||
SSortSource* source = taosArrayGetP(pHandle->pOrderedSource, 0);
|
||||
taosArrayClear(pHandle->pOrderedSource);
|
||||
|
||||
while (1) {
|
||||
SSDataBlock* pBlock = pHandle->fetchfp(source->param);
|
||||
if (pBlock == NULL) {
|
||||
|
@ -524,6 +526,7 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) {
|
|||
} else {
|
||||
pHandle->pageSize = 4096;
|
||||
}
|
||||
|
||||
// todo!!
|
||||
pHandle->numOfPages = 1024;
|
||||
sortBufSize = pHandle->numOfPages * pHandle->pageSize;
|
||||
|
@ -535,7 +538,7 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) {
|
|||
}
|
||||
|
||||
// todo relocate the columns
|
||||
int32_t code = blockDataMerge(pHandle->pDataBlock, pBlock, pHandle->pIndexMap);
|
||||
int32_t code = blockDataMerge(pHandle->pDataBlock, pBlock);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
|
@ -569,6 +572,7 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) {
|
|||
pHandle->cmpParam.numOfSources = 1;
|
||||
pHandle->inMemSort = true;
|
||||
|
||||
pHandle->loops = 1;
|
||||
pHandle->tupleHandle.rowIndex = -1;
|
||||
pHandle->tupleHandle.pBlock = pHandle->pDataBlock;
|
||||
return 0;
|
||||
|
@ -592,7 +596,7 @@ int32_t tsortOpen(SSortHandle* pHandle) {
|
|||
|
||||
pHandle->opened = true;
|
||||
|
||||
int32_t code = createInitialSortedMultiSources(pHandle);
|
||||
int32_t code = createInitialSources(pHandle);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
@ -692,3 +696,20 @@ void* tsortGetValue(STupleHandle* pVHandle, int32_t colIndex) {
|
|||
SColumnInfoData* pColInfo = TARRAY_GET_ELEM(pVHandle->pBlock->pDataBlock, colIndex);
|
||||
return colDataGetData(pColInfo, pVHandle->rowIndex);
|
||||
}
|
||||
|
||||
SSortExecInfo tsortGetSortExecInfo(SSortHandle* pHandle) {
|
||||
SSortExecInfo info = {0};
|
||||
|
||||
info.sortBuffer = pHandle->pageSize * pHandle->numOfPages;
|
||||
info.sortMethod = pHandle->inMemSort? SORT_QSORT_T:SORT_SPILLED_MERGE_SORT_T;
|
||||
info.loops = pHandle->loops;
|
||||
|
||||
if (pHandle->pBuf != NULL) {
|
||||
SDiskbasedBufStatis st = getDBufStatis(pHandle->pBuf);
|
||||
info.writeBytes = st.flushBytes;
|
||||
info.readBytes = st.loadBytes;
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
|
|
@ -276,7 +276,7 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len
|
|||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
//param0
|
||||
// param0
|
||||
SNode* pParaNode0 = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (QUERY_NODE_COLUMN != nodeType(pParaNode0)) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
|
@ -288,7 +288,7 @@ static int32_t translateElapsed(SFunctionNode* pFunc, char* pErrBuf, int32_t len
|
|||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
//param1
|
||||
// param1
|
||||
if (2 == numOfParams) {
|
||||
SNode* pParamNode1 = nodesListGetNode(pFunc->pParameterList, 1);
|
||||
if (QUERY_NODE_VALUE != nodeType(pParamNode1)) {
|
||||
|
@ -317,7 +317,7 @@ static int32_t translateLeastSQR(SFunctionNode* pFunc, char* pErrBuf, int32_t le
|
|||
|
||||
for (int32_t i = 0; i < numOfParams; ++i) {
|
||||
SNode* pParamNode = nodesListGetNode(pFunc->pParameterList, i);
|
||||
if (i > 0) { //param1 & param2
|
||||
if (i > 0) { // param1 & param2
|
||||
if (QUERY_NODE_VALUE != nodeType(pParamNode)) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
@ -333,7 +333,6 @@ static int32_t translateLeastSQR(SFunctionNode* pFunc, char* pErrBuf, int32_t le
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
pFunc->node.resType = (SDataType){.bytes = 64, .type = TSDB_DATA_TYPE_BINARY};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -344,7 +343,7 @@ static int32_t translateHistogram(SFunctionNode* pFunc, char* pErrBuf, int32_t l
|
|||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
//param0
|
||||
// param0
|
||||
SNode* pParaNode0 = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (QUERY_NODE_COLUMN != nodeType(pParaNode0)) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
|
@ -356,7 +355,7 @@ static int32_t translateHistogram(SFunctionNode* pFunc, char* pErrBuf, int32_t l
|
|||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
//param1 ~ param3
|
||||
// param1 ~ param3
|
||||
for (int32_t i = 1; i < numOfParams; ++i) {
|
||||
SNode* pParamNode = nodesListGetNode(pFunc->pParameterList, i);
|
||||
if (QUERY_NODE_VALUE != nodeType(pParamNode)) {
|
||||
|
@ -399,13 +398,13 @@ static int32_t translateStateCount(SFunctionNode* pFunc, char* pErrBuf, int32_t
|
|||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
//param0
|
||||
// param0
|
||||
uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||
if (!IS_NUMERIC_TYPE(colType)) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
//param1 & param2
|
||||
// param1 & param2
|
||||
for (int32_t i = 1; i < numOfParams; ++i) {
|
||||
SNode* pParamNode = nodesListGetNode(pFunc->pParameterList, i);
|
||||
if (QUERY_NODE_VALUE != nodeType(pParamNode)) {
|
||||
|
@ -423,7 +422,7 @@ static int32_t translateStateCount(SFunctionNode* pFunc, char* pErrBuf, int32_t
|
|||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
//set result type
|
||||
// set result type
|
||||
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -434,13 +433,13 @@ static int32_t translateStateDuration(SFunctionNode* pFunc, char* pErrBuf, int32
|
|||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
//param0
|
||||
// param0
|
||||
uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||
if (!IS_NUMERIC_TYPE(colType)) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
//param1, param2 & param3
|
||||
// param1, param2 & param3
|
||||
for (int32_t i = 1; i < numOfParams; ++i) {
|
||||
SNode* pParamNode = nodesListGetNode(pFunc->pParameterList, i);
|
||||
if (QUERY_NODE_VALUE != nodeType(pParamNode)) {
|
||||
|
@ -458,11 +457,12 @@ static int32_t translateStateDuration(SFunctionNode* pFunc, char* pErrBuf, int32
|
|||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
if (numOfParams == 4 && ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 3))->resType.type != TSDB_DATA_TYPE_BIGINT) {
|
||||
if (numOfParams == 4 &&
|
||||
((SExprNode*)nodesListGetNode(pFunc->pParameterList, 3))->resType.type != TSDB_DATA_TYPE_BIGINT) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
//set result type
|
||||
// set result type
|
||||
pFunc->node.resType = (SDataType){.bytes = tDataTypes[TSDB_DATA_TYPE_BIGINT].bytes, .type = TSDB_DATA_TYPE_BIGINT};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -503,7 +503,7 @@ static int32_t translateMavg(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
//param0
|
||||
// param0
|
||||
SNode* pParaNode0 = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (QUERY_NODE_COLUMN != nodeType(pParaNode0)) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
|
@ -512,7 +512,7 @@ static int32_t translateMavg(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
|
||||
uint8_t colType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||
|
||||
//param1
|
||||
// param1
|
||||
SNode* pParamNode1 = nodesListGetNode(pFunc->pParameterList, 1);
|
||||
if (QUERY_NODE_VALUE != nodeType(pParamNode1)) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
|
@ -539,7 +539,7 @@ static int32_t translateSample(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
|||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
//param0
|
||||
// param0
|
||||
SNode* pParamNode0 = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (QUERY_NODE_COLUMN != nodeType(pParamNode0)) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
|
@ -549,7 +549,7 @@ static int32_t translateSample(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
|||
SExprNode* pCol = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0);
|
||||
uint8_t colType = pCol->resType.type;
|
||||
|
||||
//param1
|
||||
// param1
|
||||
SNode* pParamNode1 = nodesListGetNode(pFunc->pParameterList, 1);
|
||||
if (QUERY_NODE_VALUE != nodeType(pParamNode1)) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
|
@ -567,7 +567,7 @@ static int32_t translateSample(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
|||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
//set result type
|
||||
// set result type
|
||||
if (IS_VAR_DATA_TYPE(colType)) {
|
||||
pFunc->node.resType = (SDataType){.bytes = pCol->resType.bytes, .type = colType};
|
||||
} else {
|
||||
|
@ -583,7 +583,7 @@ static int32_t translateTail(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
//param0
|
||||
// param0
|
||||
SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (QUERY_NODE_COLUMN != nodeType(pPara)) {
|
||||
return buildFuncErrMsg(pErrBuf, len, TSDB_CODE_FUNC_FUNTION_ERROR,
|
||||
|
@ -592,7 +592,7 @@ static int32_t translateTail(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
SExprNode* pCol = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0);
|
||||
uint8_t colType = pCol->resType.type;
|
||||
|
||||
//param1 & param2
|
||||
// param1 & param2
|
||||
for (int32_t i = 1; i < numOfParams; ++i) {
|
||||
SNode* pParamNode = nodesListGetNode(pFunc->pParameterList, i);
|
||||
if (QUERY_NODE_VALUE != nodeType(pParamNode)) {
|
||||
|
@ -613,7 +613,7 @@ static int32_t translateTail(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
}
|
||||
}
|
||||
|
||||
//set result type
|
||||
// set result type
|
||||
if (IS_VAR_DATA_TYPE(colType)) {
|
||||
pFunc->node.resType = (SDataType){.bytes = pCol->resType.bytes, .type = colType};
|
||||
} else {
|
||||
|
@ -978,7 +978,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "top",
|
||||
.type = FUNCTION_TYPE_TOP,
|
||||
.classification = FUNC_MGT_SELECT_FUNC | FUNC_MGT_INDEFINITE_ROWS_FUNC,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_INDEFINITE_ROWS_FUNC,
|
||||
.translateFunc = translateTop,
|
||||
.getEnvFunc = getTopBotFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
|
@ -988,7 +988,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "bottom",
|
||||
.type = FUNCTION_TYPE_BOTTOM,
|
||||
.classification = FUNC_MGT_SELECT_FUNC | FUNC_MGT_INDEFINITE_ROWS_FUNC,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC | FUNC_MGT_INDEFINITE_ROWS_FUNC,
|
||||
.translateFunc = translateBottom,
|
||||
.getEnvFunc = getTopBotFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
|
|
|
@ -191,6 +191,7 @@ static SNode* tableNodeCopy(const STableNode* pSrc, STableNode* pDst) {
|
|||
COPY_CHAR_ARRAY_FIELD(tableName);
|
||||
COPY_CHAR_ARRAY_FIELD(tableAlias);
|
||||
COPY_SCALAR_FIELD(precision);
|
||||
COPY_SCALAR_FIELD(singleTable);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
|
@ -326,6 +327,7 @@ static SNode* logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) {
|
|||
COPY_SCALAR_FIELD(sliding);
|
||||
COPY_SCALAR_FIELD(intervalUnit);
|
||||
COPY_SCALAR_FIELD(slidingUnit);
|
||||
CLONE_NODE_FIELD(pTagCond);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
|
@ -333,6 +335,7 @@ static SNode* logicJoinCopy(const SJoinLogicNode* pSrc, SJoinLogicNode* pDst) {
|
|||
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
|
||||
COPY_SCALAR_FIELD(joinType);
|
||||
CLONE_NODE_FIELD(pOnConditions);
|
||||
COPY_SCALAR_FIELD(isSingleTableJoin);
|
||||
return (SNode*)pDst;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,149 +21,160 @@
|
|||
#include "taoserror.h"
|
||||
#include "thash.h"
|
||||
|
||||
int32_t nodesNodeSize(ENodeType type) {
|
||||
static SNode* makeNode(ENodeType type, size_t size) {
|
||||
SNode* p = taosMemoryCalloc(1, size);
|
||||
if (NULL == p) {
|
||||
return NULL;
|
||||
}
|
||||
setNodeType(p, type);
|
||||
return p;
|
||||
}
|
||||
|
||||
SNodeptr nodesMakeNode(ENodeType type) {
|
||||
switch (type) {
|
||||
case QUERY_NODE_COLUMN:
|
||||
return sizeof(SColumnNode);
|
||||
return makeNode(type, sizeof(SColumnNode));
|
||||
case QUERY_NODE_VALUE:
|
||||
return sizeof(SValueNode);
|
||||
return makeNode(type, sizeof(SValueNode));
|
||||
case QUERY_NODE_OPERATOR:
|
||||
return sizeof(SOperatorNode);
|
||||
return makeNode(type, sizeof(SOperatorNode));
|
||||
case QUERY_NODE_LOGIC_CONDITION:
|
||||
return sizeof(SLogicConditionNode);
|
||||
return makeNode(type, sizeof(SLogicConditionNode));
|
||||
case QUERY_NODE_FUNCTION:
|
||||
return sizeof(SFunctionNode);
|
||||
return makeNode(type, sizeof(SFunctionNode));
|
||||
case QUERY_NODE_REAL_TABLE:
|
||||
return sizeof(SRealTableNode);
|
||||
return makeNode(type, sizeof(SRealTableNode));
|
||||
case QUERY_NODE_TEMP_TABLE:
|
||||
return sizeof(STempTableNode);
|
||||
return makeNode(type, sizeof(STempTableNode));
|
||||
case QUERY_NODE_JOIN_TABLE:
|
||||
return sizeof(SJoinTableNode);
|
||||
return makeNode(type, sizeof(SJoinTableNode));
|
||||
case QUERY_NODE_GROUPING_SET:
|
||||
return sizeof(SGroupingSetNode);
|
||||
return makeNode(type, sizeof(SGroupingSetNode));
|
||||
case QUERY_NODE_ORDER_BY_EXPR:
|
||||
return sizeof(SOrderByExprNode);
|
||||
return makeNode(type, sizeof(SOrderByExprNode));
|
||||
case QUERY_NODE_LIMIT:
|
||||
return sizeof(SLimitNode);
|
||||
return makeNode(type, sizeof(SLimitNode));
|
||||
case QUERY_NODE_STATE_WINDOW:
|
||||
return sizeof(SStateWindowNode);
|
||||
return makeNode(type, sizeof(SStateWindowNode));
|
||||
case QUERY_NODE_SESSION_WINDOW:
|
||||
return sizeof(SSessionWindowNode);
|
||||
return makeNode(type, sizeof(SSessionWindowNode));
|
||||
case QUERY_NODE_INTERVAL_WINDOW:
|
||||
return sizeof(SIntervalWindowNode);
|
||||
return makeNode(type, sizeof(SIntervalWindowNode));
|
||||
case QUERY_NODE_NODE_LIST:
|
||||
return sizeof(SNodeListNode);
|
||||
return makeNode(type, sizeof(SNodeListNode));
|
||||
case QUERY_NODE_FILL:
|
||||
return sizeof(SFillNode);
|
||||
return makeNode(type, sizeof(SFillNode));
|
||||
case QUERY_NODE_RAW_EXPR:
|
||||
return sizeof(SRawExprNode);
|
||||
return makeNode(type, sizeof(SRawExprNode));
|
||||
case QUERY_NODE_TARGET:
|
||||
return sizeof(STargetNode);
|
||||
return makeNode(type, sizeof(STargetNode));
|
||||
case QUERY_NODE_DATABLOCK_DESC:
|
||||
return sizeof(SDataBlockDescNode);
|
||||
return makeNode(type, sizeof(SDataBlockDescNode));
|
||||
case QUERY_NODE_SLOT_DESC:
|
||||
return sizeof(SSlotDescNode);
|
||||
return makeNode(type, sizeof(SSlotDescNode));
|
||||
case QUERY_NODE_COLUMN_DEF:
|
||||
return sizeof(SColumnDefNode);
|
||||
return makeNode(type, sizeof(SColumnDefNode));
|
||||
case QUERY_NODE_DOWNSTREAM_SOURCE:
|
||||
return sizeof(SDownstreamSourceNode);
|
||||
return makeNode(type, sizeof(SDownstreamSourceNode));
|
||||
case QUERY_NODE_DATABASE_OPTIONS:
|
||||
return sizeof(SDatabaseOptions);
|
||||
return makeNode(type, sizeof(SDatabaseOptions));
|
||||
case QUERY_NODE_TABLE_OPTIONS:
|
||||
return sizeof(STableOptions);
|
||||
return makeNode(type, sizeof(STableOptions));
|
||||
case QUERY_NODE_INDEX_OPTIONS:
|
||||
return sizeof(SIndexOptions);
|
||||
return makeNode(type, sizeof(SIndexOptions));
|
||||
case QUERY_NODE_EXPLAIN_OPTIONS:
|
||||
return sizeof(SExplainOptions);
|
||||
return makeNode(type, sizeof(SExplainOptions));
|
||||
case QUERY_NODE_STREAM_OPTIONS:
|
||||
return sizeof(SStreamOptions);
|
||||
return makeNode(type, sizeof(SStreamOptions));
|
||||
case QUERY_NODE_TOPIC_OPTIONS:
|
||||
return sizeof(STopicOptions);
|
||||
return makeNode(type, sizeof(STopicOptions));
|
||||
case QUERY_NODE_LEFT_VALUE:
|
||||
return sizeof(SLeftValueNode);
|
||||
return makeNode(type, sizeof(SLeftValueNode));
|
||||
case QUERY_NODE_SET_OPERATOR:
|
||||
return sizeof(SSetOperator);
|
||||
return makeNode(type, sizeof(SSetOperator));
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
return sizeof(SSelectStmt);
|
||||
return makeNode(type, sizeof(SSelectStmt));
|
||||
case QUERY_NODE_VNODE_MODIF_STMT:
|
||||
return sizeof(SVnodeModifOpStmt);
|
||||
return makeNode(type, sizeof(SVnodeModifOpStmt));
|
||||
case QUERY_NODE_CREATE_DATABASE_STMT:
|
||||
return sizeof(SCreateDatabaseStmt);
|
||||
return makeNode(type, sizeof(SCreateDatabaseStmt));
|
||||
case QUERY_NODE_DROP_DATABASE_STMT:
|
||||
return sizeof(SDropDatabaseStmt);
|
||||
return makeNode(type, sizeof(SDropDatabaseStmt));
|
||||
case QUERY_NODE_ALTER_DATABASE_STMT:
|
||||
return sizeof(SAlterDatabaseStmt);
|
||||
return makeNode(type, sizeof(SAlterDatabaseStmt));
|
||||
case QUERY_NODE_CREATE_TABLE_STMT:
|
||||
return sizeof(SCreateTableStmt);
|
||||
return makeNode(type, sizeof(SCreateTableStmt));
|
||||
case QUERY_NODE_CREATE_SUBTABLE_CLAUSE:
|
||||
return sizeof(SCreateSubTableClause);
|
||||
return makeNode(type, sizeof(SCreateSubTableClause));
|
||||
case QUERY_NODE_CREATE_MULTI_TABLE_STMT:
|
||||
return sizeof(SCreateMultiTableStmt);
|
||||
return makeNode(type, sizeof(SCreateMultiTableStmt));
|
||||
case QUERY_NODE_DROP_TABLE_CLAUSE:
|
||||
return sizeof(SDropTableClause);
|
||||
return makeNode(type, sizeof(SDropTableClause));
|
||||
case QUERY_NODE_DROP_TABLE_STMT:
|
||||
return sizeof(SDropTableStmt);
|
||||
return makeNode(type, sizeof(SDropTableStmt));
|
||||
case QUERY_NODE_DROP_SUPER_TABLE_STMT:
|
||||
return sizeof(SDropSuperTableStmt);
|
||||
return makeNode(type, sizeof(SDropSuperTableStmt));
|
||||
case QUERY_NODE_ALTER_TABLE_STMT:
|
||||
return sizeof(SAlterTableStmt);
|
||||
return makeNode(type, sizeof(SAlterTableStmt));
|
||||
case QUERY_NODE_CREATE_USER_STMT:
|
||||
return sizeof(SCreateUserStmt);
|
||||
return makeNode(type, sizeof(SCreateUserStmt));
|
||||
case QUERY_NODE_ALTER_USER_STMT:
|
||||
return sizeof(SAlterUserStmt);
|
||||
return makeNode(type, sizeof(SAlterUserStmt));
|
||||
case QUERY_NODE_DROP_USER_STMT:
|
||||
return sizeof(SDropUserStmt);
|
||||
return makeNode(type, sizeof(SDropUserStmt));
|
||||
case QUERY_NODE_USE_DATABASE_STMT:
|
||||
return sizeof(SUseDatabaseStmt);
|
||||
return makeNode(type, sizeof(SUseDatabaseStmt));
|
||||
case QUERY_NODE_CREATE_DNODE_STMT:
|
||||
return sizeof(SCreateDnodeStmt);
|
||||
return makeNode(type, sizeof(SCreateDnodeStmt));
|
||||
case QUERY_NODE_DROP_DNODE_STMT:
|
||||
return sizeof(SDropDnodeStmt);
|
||||
return makeNode(type, sizeof(SDropDnodeStmt));
|
||||
case QUERY_NODE_ALTER_DNODE_STMT:
|
||||
return sizeof(SAlterDnodeStmt);
|
||||
return makeNode(type, sizeof(SAlterDnodeStmt));
|
||||
case QUERY_NODE_CREATE_INDEX_STMT:
|
||||
return sizeof(SCreateIndexStmt);
|
||||
return makeNode(type, sizeof(SCreateIndexStmt));
|
||||
case QUERY_NODE_DROP_INDEX_STMT:
|
||||
return sizeof(SDropIndexStmt);
|
||||
return makeNode(type, sizeof(SDropIndexStmt));
|
||||
case QUERY_NODE_CREATE_QNODE_STMT:
|
||||
case QUERY_NODE_CREATE_BNODE_STMT:
|
||||
case QUERY_NODE_CREATE_SNODE_STMT:
|
||||
case QUERY_NODE_CREATE_MNODE_STMT:
|
||||
return sizeof(SCreateComponentNodeStmt);
|
||||
return makeNode(type, sizeof(SCreateComponentNodeStmt));
|
||||
case QUERY_NODE_DROP_QNODE_STMT:
|
||||
case QUERY_NODE_DROP_BNODE_STMT:
|
||||
case QUERY_NODE_DROP_SNODE_STMT:
|
||||
case QUERY_NODE_DROP_MNODE_STMT:
|
||||
return sizeof(SDropComponentNodeStmt);
|
||||
return makeNode(type, sizeof(SDropComponentNodeStmt));
|
||||
case QUERY_NODE_CREATE_TOPIC_STMT:
|
||||
return sizeof(SCreateTopicStmt);
|
||||
return makeNode(type, sizeof(SCreateTopicStmt));
|
||||
case QUERY_NODE_DROP_TOPIC_STMT:
|
||||
return sizeof(SDropTopicStmt);
|
||||
return makeNode(type, sizeof(SDropTopicStmt));
|
||||
case QUERY_NODE_DROP_CGROUP_STMT:
|
||||
return makeNode(type, sizeof(SDropCGroupStmt));
|
||||
case QUERY_NODE_EXPLAIN_STMT:
|
||||
return sizeof(SExplainStmt);
|
||||
return makeNode(type, sizeof(SExplainStmt));
|
||||
case QUERY_NODE_DESCRIBE_STMT:
|
||||
return sizeof(SDescribeStmt);
|
||||
return makeNode(type, sizeof(SDescribeStmt));
|
||||
case QUERY_NODE_RESET_QUERY_CACHE_STMT:
|
||||
return sizeof(SNode);
|
||||
return makeNode(type, sizeof(SNode));
|
||||
case QUERY_NODE_COMPACT_STMT:
|
||||
break;
|
||||
case QUERY_NODE_CREATE_FUNCTION_STMT:
|
||||
return sizeof(SCreateFunctionStmt);
|
||||
return makeNode(type, sizeof(SCreateFunctionStmt));
|
||||
case QUERY_NODE_DROP_FUNCTION_STMT:
|
||||
return sizeof(SDropFunctionStmt);
|
||||
return makeNode(type, sizeof(SDropFunctionStmt));
|
||||
case QUERY_NODE_CREATE_STREAM_STMT:
|
||||
return sizeof(SCreateStreamStmt);
|
||||
return makeNode(type, sizeof(SCreateStreamStmt));
|
||||
case QUERY_NODE_DROP_STREAM_STMT:
|
||||
return sizeof(SDropStreamStmt);
|
||||
return makeNode(type, sizeof(SDropStreamStmt));
|
||||
case QUERY_NODE_MERGE_VGROUP_STMT:
|
||||
case QUERY_NODE_REDISTRIBUTE_VGROUP_STMT:
|
||||
case QUERY_NODE_SPLIT_VGROUP_STMT:
|
||||
case QUERY_NODE_SYNCDB_STMT:
|
||||
break;
|
||||
case QUERY_NODE_GRANT_STMT:
|
||||
return sizeof(SGrantStmt);
|
||||
return makeNode(type, sizeof(SGrantStmt));
|
||||
case QUERY_NODE_REVOKE_STMT:
|
||||
return sizeof(SRevokeStmt);
|
||||
return makeNode(type, sizeof(SRevokeStmt));
|
||||
case QUERY_NODE_SHOW_DNODES_STMT:
|
||||
case QUERY_NODE_SHOW_MNODES_STMT:
|
||||
case QUERY_NODE_SHOW_MODULES_STMT:
|
||||
|
@ -194,91 +205,82 @@ int32_t nodesNodeSize(ENodeType type) {
|
|||
case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
|
||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||
case QUERY_NODE_SHOW_TRANSACTIONS_STMT:
|
||||
return sizeof(SShowStmt);
|
||||
return makeNode(type, sizeof(SShowStmt));
|
||||
case QUERY_NODE_KILL_CONNECTION_STMT:
|
||||
case QUERY_NODE_KILL_QUERY_STMT:
|
||||
case QUERY_NODE_KILL_TRANSACTION_STMT:
|
||||
return sizeof(SKillStmt);
|
||||
return makeNode(type, sizeof(SKillStmt));
|
||||
case QUERY_NODE_LOGIC_PLAN_SCAN:
|
||||
return sizeof(SScanLogicNode);
|
||||
return makeNode(type, sizeof(SScanLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_JOIN:
|
||||
return sizeof(SJoinLogicNode);
|
||||
return makeNode(type, sizeof(SJoinLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_AGG:
|
||||
return sizeof(SAggLogicNode);
|
||||
return makeNode(type, sizeof(SAggLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_PROJECT:
|
||||
return sizeof(SProjectLogicNode);
|
||||
return makeNode(type, sizeof(SProjectLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_VNODE_MODIF:
|
||||
return sizeof(SVnodeModifLogicNode);
|
||||
return makeNode(type, sizeof(SVnodeModifLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_EXCHANGE:
|
||||
return sizeof(SExchangeLogicNode);
|
||||
return makeNode(type, sizeof(SExchangeLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_WINDOW:
|
||||
return sizeof(SWindowLogicNode);
|
||||
return makeNode(type, sizeof(SWindowLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_FILL:
|
||||
return sizeof(SFillLogicNode);
|
||||
return makeNode(type, sizeof(SFillLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_SORT:
|
||||
return sizeof(SSortLogicNode);
|
||||
return makeNode(type, sizeof(SSortLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_PARTITION:
|
||||
return sizeof(SPartitionLogicNode);
|
||||
return makeNode(type, sizeof(SPartitionLogicNode));
|
||||
case QUERY_NODE_LOGIC_SUBPLAN:
|
||||
return sizeof(SLogicSubplan);
|
||||
return makeNode(type, sizeof(SLogicSubplan));
|
||||
case QUERY_NODE_LOGIC_PLAN:
|
||||
return sizeof(SQueryLogicPlan);
|
||||
return makeNode(type, sizeof(SQueryLogicPlan));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN:
|
||||
return sizeof(STagScanPhysiNode);
|
||||
return makeNode(type, sizeof(STagScanPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN:
|
||||
return sizeof(STableScanPhysiNode);
|
||||
return makeNode(type, sizeof(STableScanPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_TABLE_SEQ_SCAN:
|
||||
return sizeof(STableSeqScanPhysiNode);
|
||||
return makeNode(type, sizeof(STableSeqScanPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN:
|
||||
return sizeof(SStreamScanPhysiNode);
|
||||
return makeNode(type, sizeof(SStreamScanPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN:
|
||||
return sizeof(SSystemTableScanPhysiNode);
|
||||
return makeNode(type, sizeof(SSystemTableScanPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_PROJECT:
|
||||
return sizeof(SProjectPhysiNode);
|
||||
return makeNode(type, sizeof(SProjectPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_JOIN:
|
||||
return sizeof(SJoinPhysiNode);
|
||||
return makeNode(type, sizeof(SJoinPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_AGG:
|
||||
return sizeof(SAggPhysiNode);
|
||||
return makeNode(type, sizeof(SAggPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_EXCHANGE:
|
||||
return sizeof(SExchangePhysiNode);
|
||||
return makeNode(type, sizeof(SExchangePhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SORT:
|
||||
return sizeof(SSortPhysiNode);
|
||||
return makeNode(type, sizeof(SSortPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:
|
||||
return sizeof(SIntervalPhysiNode);
|
||||
return makeNode(type, sizeof(SIntervalPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
|
||||
return sizeof(SStreamIntervalPhysiNode);
|
||||
return makeNode(type, sizeof(SStreamIntervalPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_FILL:
|
||||
return sizeof(SFillPhysiNode);
|
||||
return makeNode(type, sizeof(SFillPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW:
|
||||
return sizeof(SSessionWinodwPhysiNode);
|
||||
return makeNode(type, sizeof(SSessionWinodwPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION_WINDOW:
|
||||
return sizeof(SStreamSessionWinodwPhysiNode);
|
||||
return makeNode(type, sizeof(SStreamSessionWinodwPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW:
|
||||
return sizeof(SStateWinodwPhysiNode);
|
||||
return makeNode(type, sizeof(SStateWinodwPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_PARTITION:
|
||||
return sizeof(SPartitionPhysiNode);
|
||||
return makeNode(type, sizeof(SPartitionPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_DISPATCH:
|
||||
return sizeof(SDataDispatcherNode);
|
||||
return makeNode(type, sizeof(SDataDispatcherNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INSERT:
|
||||
return sizeof(SDataInserterNode);
|
||||
return makeNode(type, sizeof(SDataInserterNode));
|
||||
case QUERY_NODE_PHYSICAL_SUBPLAN:
|
||||
return sizeof(SSubplan);
|
||||
return makeNode(type, sizeof(SSubplan));
|
||||
case QUERY_NODE_PHYSICAL_PLAN:
|
||||
return sizeof(SQueryPlan);
|
||||
return makeNode(type, sizeof(SQueryPlan));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
nodesError("nodesMakeNode unknown node = %s", nodesNodeName(type));
|
||||
return 0;
|
||||
}
|
||||
|
||||
SNodeptr nodesMakeNode(ENodeType type) {
|
||||
SNode* p = taosMemoryCalloc(1, nodesNodeSize(type));
|
||||
if (NULL == p) {
|
||||
return NULL;
|
||||
}
|
||||
setNodeType(p, type);
|
||||
return p;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void destroyVgDataBlockArray(SArray* pArray) {
|
||||
|
|
|
@ -53,7 +53,8 @@ typedef enum EDatabaseOptionType {
|
|||
DB_OPTION_WAL,
|
||||
DB_OPTION_VGROUPS,
|
||||
DB_OPTION_SINGLE_STABLE,
|
||||
DB_OPTION_RETENTIONS
|
||||
DB_OPTION_RETENTIONS,
|
||||
DB_OPTION_SCHEMALESS
|
||||
} EDatabaseOptionType;
|
||||
|
||||
typedef enum ETableOptionType {
|
||||
|
@ -169,6 +170,8 @@ SNode* createTopicOptions(SAstCreateContext* pCxt);
|
|||
SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery,
|
||||
const SToken* pSubscribeDbName, SNode* pOptions);
|
||||
SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pTopicName);
|
||||
SNode* createDropCGroupStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pCGroupId,
|
||||
const SToken* pTopicName);
|
||||
SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, const SToken* pValue);
|
||||
SNode* createDefaultExplainOptions(SAstCreateContext* pCxt);
|
||||
SNode* setExplainVerbose(SAstCreateContext* pCxt, SNode* pOptions, const SToken* pVal);
|
||||
|
|
|
@ -180,6 +180,7 @@ db_options(A) ::= db_options(B) WAL NK_INTEGER(C).
|
|||
db_options(A) ::= db_options(B) VGROUPS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_VGROUPS, &C); }
|
||||
db_options(A) ::= db_options(B) SINGLE_STABLE NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_SINGLE_STABLE, &C); }
|
||||
db_options(A) ::= db_options(B) RETENTIONS retention_list(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_RETENTIONS, C); }
|
||||
db_options(A) ::= db_options(B) SCHEMALESS NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_SCHEMALESS, &C); }
|
||||
|
||||
alter_db_options(A) ::= alter_db_option(B). { A = createAlterDatabaseOptions(pCxt); A = setAlterDatabaseOption(pCxt, A, &B); }
|
||||
alter_db_options(A) ::= alter_db_options(B) alter_db_option(C). { A = setAlterDatabaseOption(pCxt, B, &C); }
|
||||
|
@ -407,6 +408,7 @@ cmd ::= CREATE TOPIC not_exists_opt(A)
|
|||
cmd ::= CREATE TOPIC not_exists_opt(A)
|
||||
topic_name(B) topic_options(D) AS db_name(C). { pCxt->pRootNode = createCreateTopicStmt(pCxt, A, &B, NULL, &C, D); }
|
||||
cmd ::= DROP TOPIC exists_opt(A) topic_name(B). { pCxt->pRootNode = createDropTopicStmt(pCxt, A, &B); }
|
||||
cmd ::= DROP CGROUP exists_opt(A) cgroup_name(B) ON topic_name(C). { pCxt->pRootNode = createDropCGroupStmt(pCxt, A, &B, &C); }
|
||||
|
||||
topic_options(A) ::= . { A = createTopicOptions(pCxt); }
|
||||
topic_options(A) ::= topic_options(B) WITH TABLE. { ((STopicOptions*)B)->withTable = true; A = B; }
|
||||
|
@ -565,6 +567,10 @@ topic_name(A) ::= NK_ID(B).
|
|||
%destructor stream_name { }
|
||||
stream_name(A) ::= NK_ID(B). { A = B; }
|
||||
|
||||
%type cgroup_name { SToken }
|
||||
%destructor cgroup_name { }
|
||||
cgroup_name(A) ::= NK_ID(B). { A = B; }
|
||||
|
||||
/************************************************ expression **********************************************************/
|
||||
expression(A) ::= literal(B). { A = B; }
|
||||
expression(A) ::= pseudo_column(B). { A = B; }
|
||||
|
|
|
@ -29,12 +29,11 @@
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_RAW_EXPR_NODE(node) \
|
||||
do { \
|
||||
if (NULL == (node) || QUERY_NODE_RAW_EXPR != nodeType(node)) { \
|
||||
pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR; \
|
||||
return NULL; \
|
||||
} \
|
||||
#define CHECK_PARSER_STATUS(pCxt) \
|
||||
do { \
|
||||
if (TSDB_CODE_SUCCESS != pCxt->errCode) { \
|
||||
return NULL; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
SToken nil_token = {.type = TK_NK_NIL, .n = 0, .z = NULL};
|
||||
|
@ -206,6 +205,7 @@ static bool checkComment(SAstCreateContext* pCxt, const SToken* pCommentToken, b
|
|||
}
|
||||
|
||||
SNode* createRawExprNode(SAstCreateContext* pCxt, const SToken* pToken, SNode* pNode) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SRawExprNode* target = (SRawExprNode*)nodesMakeNode(QUERY_NODE_RAW_EXPR);
|
||||
CHECK_OUT_OF_MEM(target);
|
||||
target->p = pToken->z;
|
||||
|
@ -215,6 +215,7 @@ SNode* createRawExprNode(SAstCreateContext* pCxt, const SToken* pToken, SNode* p
|
|||
}
|
||||
|
||||
SNode* createRawExprNodeExt(SAstCreateContext* pCxt, const SToken* pStart, const SToken* pEnd, SNode* pNode) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SRawExprNode* target = (SRawExprNode*)nodesMakeNode(QUERY_NODE_RAW_EXPR);
|
||||
CHECK_OUT_OF_MEM(target);
|
||||
target->p = pStart->z;
|
||||
|
@ -224,7 +225,7 @@ SNode* createRawExprNodeExt(SAstCreateContext* pCxt, const SToken* pStart, const
|
|||
}
|
||||
|
||||
SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
|
||||
CHECK_RAW_EXPR_NODE(pNode);
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SRawExprNode* pRawExpr = (SRawExprNode*)pNode;
|
||||
SNode* pExpr = pRawExpr->pNode;
|
||||
if (nodesIsExprNode(pExpr)) {
|
||||
|
@ -247,6 +248,7 @@ SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
|
|||
}
|
||||
|
||||
SNodeList* createNodeList(SAstCreateContext* pCxt, SNode* pNode) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SNodeList* list = nodesMakeList();
|
||||
CHECK_OUT_OF_MEM(list);
|
||||
pCxt->errCode = nodesListAppend(list, pNode);
|
||||
|
@ -254,11 +256,13 @@ SNodeList* createNodeList(SAstCreateContext* pCxt, SNode* pNode) {
|
|||
}
|
||||
|
||||
SNodeList* addNodeToList(SAstCreateContext* pCxt, SNodeList* pList, SNode* pNode) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
pCxt->errCode = nodesListAppend(pList, pNode);
|
||||
return pList;
|
||||
}
|
||||
|
||||
SNode* createColumnNode(SAstCreateContext* pCxt, SToken* pTableAlias, SToken* pColumnName) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkTableName(pCxt, pTableAlias) || !checkColumnName(pCxt, pColumnName)) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -272,6 +276,7 @@ SNode* createColumnNode(SAstCreateContext* pCxt, SToken* pTableAlias, SToken* pC
|
|||
}
|
||||
|
||||
SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SValueNode* val = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||
CHECK_OUT_OF_MEM(val);
|
||||
val->literal = strndup(pLiteral->z, pLiteral->n);
|
||||
|
@ -291,6 +296,7 @@ SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken*
|
|||
}
|
||||
|
||||
SNode* createDurationValueNode(SAstCreateContext* pCxt, const SToken* pLiteral) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SValueNode* val = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||
CHECK_OUT_OF_MEM(val);
|
||||
val->literal = strndup(pLiteral->z, pLiteral->n);
|
||||
|
@ -304,6 +310,7 @@ SNode* createDurationValueNode(SAstCreateContext* pCxt, const SToken* pLiteral)
|
|||
}
|
||||
|
||||
SNode* createDefaultDatabaseCondValue(SAstCreateContext* pCxt) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (NULL == pCxt->pQueryCxt->db) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -321,6 +328,7 @@ SNode* createDefaultDatabaseCondValue(SAstCreateContext* pCxt) {
|
|||
}
|
||||
|
||||
SNode* createPlaceholderValueNode(SAstCreateContext* pCxt, const SToken* pLiteral) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SValueNode* val = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||
CHECK_OUT_OF_MEM(val);
|
||||
val->literal = strndup(pLiteral->z, pLiteral->n);
|
||||
|
@ -338,6 +346,7 @@ SNode* createPlaceholderValueNode(SAstCreateContext* pCxt, const SToken* pLitera
|
|||
}
|
||||
|
||||
SNode* createLogicConditionNode(SAstCreateContext* pCxt, ELogicConditionType type, SNode* pParam1, SNode* pParam2) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SLogicConditionNode* cond = (SLogicConditionNode*)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION);
|
||||
CHECK_OUT_OF_MEM(cond);
|
||||
cond->condType = type;
|
||||
|
@ -360,6 +369,7 @@ SNode* createLogicConditionNode(SAstCreateContext* pCxt, ELogicConditionType typ
|
|||
}
|
||||
|
||||
SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pLeft, SNode* pRight) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SOperatorNode* op = (SOperatorNode*)nodesMakeNode(QUERY_NODE_OPERATOR);
|
||||
CHECK_OUT_OF_MEM(op);
|
||||
op->opType = type;
|
||||
|
@ -369,17 +379,20 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL
|
|||
}
|
||||
|
||||
SNode* createBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
return createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND,
|
||||
createOperatorNode(pCxt, OP_TYPE_GREATER_EQUAL, pExpr, pLeft),
|
||||
createOperatorNode(pCxt, OP_TYPE_LOWER_EQUAL, nodesCloneNode(pExpr), pRight));
|
||||
}
|
||||
|
||||
SNode* createNotBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
return createLogicConditionNode(pCxt, LOGIC_COND_TYPE_OR, createOperatorNode(pCxt, OP_TYPE_LOWER_THAN, pExpr, pLeft),
|
||||
createOperatorNode(pCxt, OP_TYPE_GREATER_THAN, nodesCloneNode(pExpr), pRight));
|
||||
}
|
||||
|
||||
static SNode* createPrimaryKeyCol(SAstCreateContext* pCxt) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SColumnNode* pCol = nodesMakeNode(QUERY_NODE_COLUMN);
|
||||
CHECK_OUT_OF_MEM(pCol);
|
||||
pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
|
@ -388,6 +401,7 @@ static SNode* createPrimaryKeyCol(SAstCreateContext* pCxt) {
|
|||
}
|
||||
|
||||
SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (0 == strncasecmp("_rowts", pFuncName->z, pFuncName->n) || 0 == strncasecmp("_c0", pFuncName->z, pFuncName->n)) {
|
||||
return createPrimaryKeyCol(pCxt);
|
||||
}
|
||||
|
@ -399,6 +413,7 @@ SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNod
|
|||
}
|
||||
|
||||
SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType dt) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SFunctionNode* func = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||
CHECK_OUT_OF_MEM(func);
|
||||
strcpy(func->functionName, "cast");
|
||||
|
@ -413,6 +428,7 @@ SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType d
|
|||
}
|
||||
|
||||
SNode* createNodeListNode(SAstCreateContext* pCxt, SNodeList* pList) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SNodeListNode* list = (SNodeListNode*)nodesMakeNode(QUERY_NODE_NODE_LIST);
|
||||
CHECK_OUT_OF_MEM(list);
|
||||
list->pNodeList = pList;
|
||||
|
@ -420,6 +436,7 @@ SNode* createNodeListNode(SAstCreateContext* pCxt, SNodeList* pList) {
|
|||
}
|
||||
|
||||
SNode* createNodeListNodeEx(SAstCreateContext* pCxt, SNode* p1, SNode* p2) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SNodeListNode* list = (SNodeListNode*)nodesMakeNode(QUERY_NODE_NODE_LIST);
|
||||
CHECK_OUT_OF_MEM(list);
|
||||
list->pNodeList = nodesMakeList();
|
||||
|
@ -430,6 +447,7 @@ SNode* createNodeListNodeEx(SAstCreateContext* pCxt, SNode* p1, SNode* p2) {
|
|||
}
|
||||
|
||||
SNode* createRealTableNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pTableName, SToken* pTableAlias) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkDbName(pCxt, pDbName, true) || !checkTableName(pCxt, pTableName) || !checkTableName(pCxt, pTableAlias)) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -450,6 +468,7 @@ SNode* createRealTableNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pTa
|
|||
}
|
||||
|
||||
SNode* createTempTableNode(SAstCreateContext* pCxt, SNode* pSubquery, const SToken* pTableAlias) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
STempTableNode* tempTable = (STempTableNode*)nodesMakeNode(QUERY_NODE_TEMP_TABLE);
|
||||
CHECK_OUT_OF_MEM(tempTable);
|
||||
tempTable->pSubquery = pSubquery;
|
||||
|
@ -467,6 +486,7 @@ SNode* createTempTableNode(SAstCreateContext* pCxt, SNode* pSubquery, const STok
|
|||
}
|
||||
|
||||
SNode* createJoinTableNode(SAstCreateContext* pCxt, EJoinType type, SNode* pLeft, SNode* pRight, SNode* pJoinCond) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SJoinTableNode* joinTable = (SJoinTableNode*)nodesMakeNode(QUERY_NODE_JOIN_TABLE);
|
||||
CHECK_OUT_OF_MEM(joinTable);
|
||||
joinTable->joinType = type;
|
||||
|
@ -477,6 +497,7 @@ SNode* createJoinTableNode(SAstCreateContext* pCxt, EJoinType type, SNode* pLeft
|
|||
}
|
||||
|
||||
SNode* createLimitNode(SAstCreateContext* pCxt, const SToken* pLimit, const SToken* pOffset) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SLimitNode* limitNode = (SLimitNode*)nodesMakeNode(QUERY_NODE_LIMIT);
|
||||
CHECK_OUT_OF_MEM(limitNode);
|
||||
limitNode->limit = taosStr2Int64(pLimit->z, NULL, 10);
|
||||
|
@ -487,6 +508,7 @@ SNode* createLimitNode(SAstCreateContext* pCxt, const SToken* pLimit, const STok
|
|||
}
|
||||
|
||||
SNode* createOrderByExprNode(SAstCreateContext* pCxt, SNode* pExpr, EOrder order, ENullOrder nullOrder) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SOrderByExprNode* orderByExpr = (SOrderByExprNode*)nodesMakeNode(QUERY_NODE_ORDER_BY_EXPR);
|
||||
CHECK_OUT_OF_MEM(orderByExpr);
|
||||
orderByExpr->pExpr = pExpr;
|
||||
|
@ -499,6 +521,7 @@ SNode* createOrderByExprNode(SAstCreateContext* pCxt, SNode* pExpr, EOrder order
|
|||
}
|
||||
|
||||
SNode* createSessionWindowNode(SAstCreateContext* pCxt, SNode* pCol, SNode* pGap) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SSessionWindowNode* session = (SSessionWindowNode*)nodesMakeNode(QUERY_NODE_SESSION_WINDOW);
|
||||
CHECK_OUT_OF_MEM(session);
|
||||
session->pCol = (SColumnNode*)pCol;
|
||||
|
@ -507,6 +530,7 @@ SNode* createSessionWindowNode(SAstCreateContext* pCxt, SNode* pCol, SNode* pGap
|
|||
}
|
||||
|
||||
SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SStateWindowNode* state = (SStateWindowNode*)nodesMakeNode(QUERY_NODE_STATE_WINDOW);
|
||||
CHECK_OUT_OF_MEM(state);
|
||||
state->pCol = createPrimaryKeyCol(pCxt);
|
||||
|
@ -520,6 +544,7 @@ SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr) {
|
|||
|
||||
SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode* pOffset, SNode* pSliding,
|
||||
SNode* pFill) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SIntervalWindowNode* interval = (SIntervalWindowNode*)nodesMakeNode(QUERY_NODE_INTERVAL_WINDOW);
|
||||
CHECK_OUT_OF_MEM(interval);
|
||||
interval->pCol = createPrimaryKeyCol(pCxt);
|
||||
|
@ -535,6 +560,7 @@ SNode* createIntervalWindowNode(SAstCreateContext* pCxt, SNode* pInterval, SNode
|
|||
}
|
||||
|
||||
SNode* createFillNode(SAstCreateContext* pCxt, EFillMode mode, SNode* pValues) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SFillNode* fill = (SFillNode*)nodesMakeNode(QUERY_NODE_FILL);
|
||||
CHECK_OUT_OF_MEM(fill);
|
||||
fill->mode = mode;
|
||||
|
@ -549,6 +575,7 @@ SNode* createFillNode(SAstCreateContext* pCxt, EFillMode mode, SNode* pValues) {
|
|||
}
|
||||
|
||||
SNode* createGroupingSetNode(SAstCreateContext* pCxt, SNode* pNode) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SGroupingSetNode* groupingSet = (SGroupingSetNode*)nodesMakeNode(QUERY_NODE_GROUPING_SET);
|
||||
CHECK_OUT_OF_MEM(groupingSet);
|
||||
groupingSet->groupingSetType = GP_TYPE_NORMAL;
|
||||
|
@ -558,9 +585,7 @@ SNode* createGroupingSetNode(SAstCreateContext* pCxt, SNode* pNode) {
|
|||
}
|
||||
|
||||
SNode* setProjectionAlias(SAstCreateContext* pCxt, SNode* pNode, const SToken* pAlias) {
|
||||
if (NULL == pNode || TSDB_CODE_SUCCESS != pCxt->errCode) {
|
||||
return pNode;
|
||||
}
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
int32_t len = TMIN(sizeof(((SExprNode*)pNode)->aliasName) - 1, pAlias->n);
|
||||
strncpy(((SExprNode*)pNode)->aliasName, pAlias->z, len);
|
||||
((SExprNode*)pNode)->aliasName[len] = '\0';
|
||||
|
@ -570,6 +595,7 @@ SNode* setProjectionAlias(SAstCreateContext* pCxt, SNode* pNode, const SToken* p
|
|||
}
|
||||
|
||||
SNode* addWhereClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pWhere) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
((SSelectStmt*)pStmt)->pWhere = pWhere;
|
||||
}
|
||||
|
@ -577,6 +603,7 @@ SNode* addWhereClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pWhere) {
|
|||
}
|
||||
|
||||
SNode* addPartitionByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pPartitionByList) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
((SSelectStmt*)pStmt)->pPartitionByList = pPartitionByList;
|
||||
}
|
||||
|
@ -584,6 +611,7 @@ SNode* addPartitionByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pP
|
|||
}
|
||||
|
||||
SNode* addWindowClauseClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pWindow) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
((SSelectStmt*)pStmt)->pWindow = pWindow;
|
||||
}
|
||||
|
@ -591,6 +619,7 @@ SNode* addWindowClauseClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pWind
|
|||
}
|
||||
|
||||
SNode* addGroupByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pGroupByList) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
((SSelectStmt*)pStmt)->pGroupByList = pGroupByList;
|
||||
}
|
||||
|
@ -598,6 +627,7 @@ SNode* addGroupByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pGroup
|
|||
}
|
||||
|
||||
SNode* addHavingClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pHaving) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
((SSelectStmt*)pStmt)->pHaving = pHaving;
|
||||
}
|
||||
|
@ -605,6 +635,7 @@ SNode* addHavingClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pHaving) {
|
|||
}
|
||||
|
||||
SNode* addOrderByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pOrderByList) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
((SSelectStmt*)pStmt)->pOrderByList = pOrderByList;
|
||||
}
|
||||
|
@ -612,6 +643,7 @@ SNode* addOrderByClause(SAstCreateContext* pCxt, SNode* pStmt, SNodeList* pOrder
|
|||
}
|
||||
|
||||
SNode* addSlimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pSlimit) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
((SSelectStmt*)pStmt)->pSlimit = (SLimitNode*)pSlimit;
|
||||
}
|
||||
|
@ -619,6 +651,7 @@ SNode* addSlimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pSlimit) {
|
|||
}
|
||||
|
||||
SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
((SSelectStmt*)pStmt)->pLimit = (SLimitNode*)pLimit;
|
||||
}
|
||||
|
@ -626,6 +659,7 @@ SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit) {
|
|||
}
|
||||
|
||||
SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SSelectStmt* select = (SSelectStmt*)nodesMakeNode(QUERY_NODE_SELECT_STMT);
|
||||
CHECK_OUT_OF_MEM(select);
|
||||
select->isDistinct = isDistinct;
|
||||
|
@ -637,6 +671,7 @@ SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pPr
|
|||
}
|
||||
|
||||
SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SSetOperator* setOp = (SSetOperator*)nodesMakeNode(QUERY_NODE_SET_OPERATOR);
|
||||
CHECK_OUT_OF_MEM(setOp);
|
||||
setOp->opType = type;
|
||||
|
@ -647,6 +682,7 @@ SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode*
|
|||
}
|
||||
|
||||
SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SDatabaseOptions* pOptions = nodesMakeNode(QUERY_NODE_DATABASE_OPTIONS);
|
||||
CHECK_OUT_OF_MEM(pOptions);
|
||||
pOptions->buffer = TSDB_DEFAULT_BUFFER_PER_VNODE;
|
||||
|
@ -667,10 +703,12 @@ SNode* createDefaultDatabaseOptions(SAstCreateContext* pCxt) {
|
|||
pOptions->walLevel = TSDB_DEFAULT_WAL_LEVEL;
|
||||
pOptions->numOfVgroups = TSDB_DEFAULT_VN_PER_DB;
|
||||
pOptions->singleStable = TSDB_DEFAULT_DB_SINGLE_STABLE;
|
||||
pOptions->schemaless = TSDB_DEFAULT_DB_SCHEMALESS;
|
||||
return (SNode*)pOptions;
|
||||
}
|
||||
|
||||
SNode* createAlterDatabaseOptions(SAstCreateContext* pCxt) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SDatabaseOptions* pOptions = nodesMakeNode(QUERY_NODE_DATABASE_OPTIONS);
|
||||
CHECK_OUT_OF_MEM(pOptions);
|
||||
pOptions->buffer = -1;
|
||||
|
@ -691,10 +729,12 @@ SNode* createAlterDatabaseOptions(SAstCreateContext* pCxt) {
|
|||
pOptions->walLevel = -1;
|
||||
pOptions->numOfVgroups = -1;
|
||||
pOptions->singleStable = -1;
|
||||
pOptions->schemaless = -1;
|
||||
return (SNode*)pOptions;
|
||||
}
|
||||
|
||||
SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOptionType type, void* pVal) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
switch (type) {
|
||||
case DB_OPTION_BUFFER:
|
||||
((SDatabaseOptions*)pOptions)->buffer = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
|
||||
|
@ -754,6 +794,9 @@ SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOpti
|
|||
case DB_OPTION_RETENTIONS:
|
||||
((SDatabaseOptions*)pOptions)->pRetentions = pVal;
|
||||
break;
|
||||
case DB_OPTION_SCHEMALESS:
|
||||
((SDatabaseOptions*)pOptions)->schemaless = taosStr2Int8(((SToken*)pVal)->z, NULL, 10);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -761,6 +804,7 @@ SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOpti
|
|||
}
|
||||
|
||||
SNode* setAlterDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOption* pAlterOption) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
switch (pAlterOption->type) {
|
||||
case DB_OPTION_KEEP:
|
||||
case DB_OPTION_RETENTIONS:
|
||||
|
@ -772,6 +816,7 @@ SNode* setAlterDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, SAlterOp
|
|||
}
|
||||
|
||||
SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, SToken* pDbName, SNode* pOptions) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkDbName(pCxt, pDbName, false)) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -784,6 +829,7 @@ SNode* createCreateDatabaseStmt(SAstCreateContext* pCxt, bool ignoreExists, STok
|
|||
}
|
||||
|
||||
SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pDbName) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkDbName(pCxt, pDbName, false)) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -795,6 +841,7 @@ SNode* createDropDatabaseStmt(SAstCreateContext* pCxt, bool ignoreNotExists, STo
|
|||
}
|
||||
|
||||
SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode* pOptions) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkDbName(pCxt, pDbName, false)) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -806,6 +853,7 @@ SNode* createAlterDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName, SNode*
|
|||
}
|
||||
|
||||
SNode* createDefaultTableOptions(SAstCreateContext* pCxt) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
STableOptions* pOptions = nodesMakeNode(QUERY_NODE_TABLE_OPTIONS);
|
||||
CHECK_OUT_OF_MEM(pOptions);
|
||||
pOptions->delay = TSDB_DEFAULT_ROLLUP_DELAY;
|
||||
|
@ -815,6 +863,7 @@ SNode* createDefaultTableOptions(SAstCreateContext* pCxt) {
|
|||
}
|
||||
|
||||
SNode* createAlterTableOptions(SAstCreateContext* pCxt) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
STableOptions* pOptions = nodesMakeNode(QUERY_NODE_TABLE_OPTIONS);
|
||||
CHECK_OUT_OF_MEM(pOptions);
|
||||
pOptions->delay = -1;
|
||||
|
@ -824,6 +873,7 @@ SNode* createAlterTableOptions(SAstCreateContext* pCxt) {
|
|||
}
|
||||
|
||||
SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType type, void* pVal) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
switch (type) {
|
||||
case TABLE_OPTION_COMMENT:
|
||||
if (checkComment(pCxt, (SToken*)pVal, true)) {
|
||||
|
@ -853,6 +903,7 @@ SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType
|
|||
}
|
||||
|
||||
SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType dataType, const SToken* pComment) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkColumnName(pCxt, pColName) || !checkComment(pCxt, pComment, false)) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -879,9 +930,7 @@ SDataType createVarLenDataType(uint8_t type, const SToken* pLen) {
|
|||
|
||||
SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNodeList* pCols,
|
||||
SNodeList* pTags, SNode* pOptions) {
|
||||
if (NULL == pRealTable) {
|
||||
return NULL;
|
||||
}
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SCreateTableStmt* pStmt = (SCreateTableStmt*)nodesMakeNode(QUERY_NODE_CREATE_TABLE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
|
||||
|
@ -896,9 +945,7 @@ SNode* createCreateTableStmt(SAstCreateContext* pCxt, bool ignoreExists, SNode*
|
|||
|
||||
SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SNode* pRealTable, SNode* pUseRealTable,
|
||||
SNodeList* pSpecificTags, SNodeList* pValsOfTags, SNode* pOptions) {
|
||||
if (NULL == pRealTable) {
|
||||
return NULL;
|
||||
}
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SCreateSubTableClause* pStmt = nodesMakeNode(QUERY_NODE_CREATE_SUBTABLE_CLAUSE);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
|
||||
|
@ -914,6 +961,7 @@ SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SN
|
|||
}
|
||||
|
||||
SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SCreateMultiTableStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_MULTI_TABLE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->pSubTables = pSubTables;
|
||||
|
@ -921,9 +969,7 @@ SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables
|
|||
}
|
||||
|
||||
SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable) {
|
||||
if (NULL == pRealTable) {
|
||||
return NULL;
|
||||
}
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SDropTableClause* pStmt = nodesMakeNode(QUERY_NODE_DROP_TABLE_CLAUSE);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
|
||||
|
@ -934,6 +980,7 @@ SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNod
|
|||
}
|
||||
|
||||
SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SDropTableStmt* pStmt = nodesMakeNode(QUERY_NODE_DROP_TABLE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->pTables = pTables;
|
||||
|
@ -941,6 +988,7 @@ SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables) {
|
|||
}
|
||||
|
||||
SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SDropSuperTableStmt* pStmt = nodesMakeNode(QUERY_NODE_DROP_SUPER_TABLE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
|
||||
|
@ -958,9 +1006,7 @@ static SNode* createAlterTableStmtFinalize(SNode* pRealTable, SAlterTableStmt* p
|
|||
}
|
||||
|
||||
SNode* createAlterTableModifyOptions(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions) {
|
||||
if (NULL == pRealTable) {
|
||||
return NULL;
|
||||
}
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->alterType = TSDB_ALTER_TABLE_UPDATE_OPTIONS;
|
||||
|
@ -970,7 +1016,8 @@ SNode* createAlterTableModifyOptions(SAstCreateContext* pCxt, SNode* pRealTable,
|
|||
|
||||
SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pColName,
|
||||
SDataType dataType) {
|
||||
if (NULL == pRealTable || !checkColumnName(pCxt, pColName)) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkColumnName(pCxt, pColName)) {
|
||||
return NULL;
|
||||
}
|
||||
SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT);
|
||||
|
@ -982,7 +1029,8 @@ SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable,
|
|||
}
|
||||
|
||||
SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pColName) {
|
||||
if (NULL == pRealTable || !checkColumnName(pCxt, pColName)) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkColumnName(pCxt, pColName)) {
|
||||
return NULL;
|
||||
}
|
||||
SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT);
|
||||
|
@ -994,7 +1042,8 @@ SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_
|
|||
|
||||
SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pOldColName,
|
||||
SToken* pNewColName) {
|
||||
if (NULL == pRealTable || !checkColumnName(pCxt, pOldColName) || !checkColumnName(pCxt, pNewColName)) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkColumnName(pCxt, pOldColName) || !checkColumnName(pCxt, pNewColName)) {
|
||||
return NULL;
|
||||
}
|
||||
SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT);
|
||||
|
@ -1006,7 +1055,8 @@ SNode* createAlterTableRenameCol(SAstCreateContext* pCxt, SNode* pRealTable, int
|
|||
}
|
||||
|
||||
SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, SToken* pTagName, SNode* pVal) {
|
||||
if (NULL == pRealTable || !checkColumnName(pCxt, pTagName)) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkColumnName(pCxt, pTagName)) {
|
||||
return NULL;
|
||||
}
|
||||
SAlterTableStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_TABLE_STMT);
|
||||
|
@ -1018,6 +1068,7 @@ SNode* createAlterTableSetTag(SAstCreateContext* pCxt, SNode* pRealTable, SToken
|
|||
}
|
||||
|
||||
SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkDbName(pCxt, pDbName, false)) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1033,13 +1084,13 @@ static bool needDbShowStmt(ENodeType type) {
|
|||
}
|
||||
|
||||
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (needDbShowStmt(type) && NULL == pDbName && NULL == pCxt->pQueryCxt->db) {
|
||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "db not specified");
|
||||
pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
SShowStmt* pStmt = nodesMakeNode(type);
|
||||
;
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->pDbName = pDbName;
|
||||
pStmt->pTbNamePattern = pTbNamePattern;
|
||||
|
@ -1047,18 +1098,21 @@ SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, S
|
|||
}
|
||||
|
||||
SNode* createShowCreateDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SNode* pStmt = nodesMakeNode(QUERY_NODE_SHOW_CREATE_DATABASE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SNode* pStmt = nodesMakeNode(type);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
char password[TSDB_USET_PASSWORD_LEN] = {0};
|
||||
if (!checkUserName(pCxt, pUserName) || !checkPassword(pCxt, pPassword, password)) {
|
||||
return NULL;
|
||||
|
@ -1071,6 +1125,7 @@ SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const ST
|
|||
}
|
||||
|
||||
SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t alterType, const SToken* pVal) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkUserName(pCxt, pUserName)) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1090,6 +1145,7 @@ SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t al
|
|||
}
|
||||
|
||||
SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkUserName(pCxt, pUserName)) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1100,6 +1156,7 @@ SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName) {
|
|||
}
|
||||
|
||||
SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const SToken* pPort) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
int32_t port = 0;
|
||||
char fqdn[TSDB_FQDN_LEN] = {0};
|
||||
if (NULL == pPort) {
|
||||
|
@ -1121,6 +1178,7 @@ SNode* createCreateDnodeStmt(SAstCreateContext* pCxt, const SToken* pFqdn, const
|
|||
}
|
||||
|
||||
SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SDropDnodeStmt* pStmt = (SDropDnodeStmt*)nodesMakeNode(QUERY_NODE_DROP_DNODE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
if (TK_NK_INTEGER == pDnode->type) {
|
||||
|
@ -1136,6 +1194,7 @@ SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode) {
|
|||
|
||||
SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const SToken* pConfig,
|
||||
const SToken* pValue) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SAlterDnodeStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_DNODE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->dnodeId = taosStr2Int32(pDnode->z, NULL, 10);
|
||||
|
@ -1148,6 +1207,7 @@ SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const
|
|||
|
||||
SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool ignoreExists, SToken* pIndexName,
|
||||
SToken* pTableName, SNodeList* pCols, SNode* pOptions) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkIndexName(pCxt, pIndexName) || !checkTableName(pCxt, pTableName) || !checkDbName(pCxt, NULL, true)) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1164,6 +1224,7 @@ SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool igno
|
|||
|
||||
SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInterval, SNode* pOffset,
|
||||
SNode* pSliding) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SIndexOptions* pOptions = nodesMakeNode(QUERY_NODE_INDEX_OPTIONS);
|
||||
CHECK_OUT_OF_MEM(pOptions);
|
||||
pOptions->pFuncs = pFuncs;
|
||||
|
@ -1174,6 +1235,7 @@ SNode* createIndexOption(SAstCreateContext* pCxt, SNodeList* pFuncs, SNode* pInt
|
|||
}
|
||||
|
||||
SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken* pIndexName, SToken* pTableName) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkIndexName(pCxt, pIndexName) || !checkTableName(pCxt, pTableName)) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1186,6 +1248,7 @@ SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken
|
|||
}
|
||||
|
||||
SNode* createCreateComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SCreateComponentNodeStmt* pStmt = nodesMakeNode(type);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->dnodeId = taosStr2Int32(pDnodeId->z, NULL, 10);
|
||||
|
@ -1194,6 +1257,7 @@ SNode* createCreateComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, co
|
|||
}
|
||||
|
||||
SNode* createDropComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDnodeId) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SDropComponentNodeStmt* pStmt = nodesMakeNode(type);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->dnodeId = taosStr2Int32(pDnodeId->z, NULL, 10);
|
||||
|
@ -1202,6 +1266,7 @@ SNode* createDropComponentNodeStmt(SAstCreateContext* pCxt, ENodeType type, cons
|
|||
}
|
||||
|
||||
SNode* createTopicOptions(SAstCreateContext* pCxt) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
STopicOptions* pOptions = nodesMakeNode(QUERY_NODE_TOPIC_OPTIONS);
|
||||
CHECK_OUT_OF_MEM(pOptions);
|
||||
pOptions->withTable = false;
|
||||
|
@ -1212,6 +1277,7 @@ SNode* createTopicOptions(SAstCreateContext* pCxt) {
|
|||
|
||||
SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pTopicName, SNode* pQuery,
|
||||
const SToken* pSubscribeDbName, SNode* pOptions) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SCreateTopicStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_TOPIC_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
strncpy(pStmt->topicName, pTopicName->z, pTopicName->n);
|
||||
|
@ -1225,6 +1291,7 @@ SNode* createCreateTopicStmt(SAstCreateContext* pCxt, bool ignoreExists, const S
|
|||
}
|
||||
|
||||
SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pTopicName) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SDropTopicStmt* pStmt = nodesMakeNode(QUERY_NODE_DROP_TOPIC_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
strncpy(pStmt->topicName, pTopicName->z, pTopicName->n);
|
||||
|
@ -1232,7 +1299,19 @@ SNode* createDropTopicStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const
|
|||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createDropCGroupStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pCGroupId,
|
||||
const SToken* pTopicName) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SDropCGroupStmt* pStmt = nodesMakeNode(QUERY_NODE_DROP_CGROUP_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->ignoreNotExists = ignoreNotExists;
|
||||
strncpy(pStmt->topicName, pTopicName->z, pTopicName->n);
|
||||
strncpy(pStmt->cgroup, pCGroupId->z, pCGroupId->n);
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, const SToken* pValue) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SAlterLocalStmt* pStmt = nodesMakeNode(QUERY_NODE_ALTER_LOCAL_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
trimString(pConfig->z, pConfig->n, pStmt->config, sizeof(pStmt->config));
|
||||
|
@ -1243,6 +1322,7 @@ SNode* createAlterLocalStmt(SAstCreateContext* pCxt, const SToken* pConfig, cons
|
|||
}
|
||||
|
||||
SNode* createDefaultExplainOptions(SAstCreateContext* pCxt) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SExplainOptions* pOptions = nodesMakeNode(QUERY_NODE_EXPLAIN_OPTIONS);
|
||||
CHECK_OUT_OF_MEM(pOptions);
|
||||
pOptions->verbose = TSDB_DEFAULT_EXPLAIN_VERBOSE;
|
||||
|
@ -1251,16 +1331,19 @@ SNode* createDefaultExplainOptions(SAstCreateContext* pCxt) {
|
|||
}
|
||||
|
||||
SNode* setExplainVerbose(SAstCreateContext* pCxt, SNode* pOptions, const SToken* pVal) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
((SExplainOptions*)pOptions)->verbose = (0 == strncasecmp(pVal->z, "true", pVal->n));
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
SNode* setExplainRatio(SAstCreateContext* pCxt, SNode* pOptions, const SToken* pVal) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
((SExplainOptions*)pOptions)->ratio = taosStr2Double(pVal->z, NULL);
|
||||
return pOptions;
|
||||
}
|
||||
|
||||
SNode* createExplainStmt(SAstCreateContext* pCxt, bool analyze, SNode* pOptions, SNode* pQuery) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SExplainStmt* pStmt = nodesMakeNode(QUERY_NODE_EXPLAIN_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->analyze = analyze;
|
||||
|
@ -1270,9 +1353,7 @@ SNode* createExplainStmt(SAstCreateContext* pCxt, bool analyze, SNode* pOptions,
|
|||
}
|
||||
|
||||
SNode* createDescribeStmt(SAstCreateContext* pCxt, SNode* pRealTable) {
|
||||
if (NULL == pRealTable) {
|
||||
return NULL;
|
||||
}
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SDescribeStmt* pStmt = nodesMakeNode(QUERY_NODE_DESCRIBE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
|
||||
|
@ -1282,12 +1363,14 @@ SNode* createDescribeStmt(SAstCreateContext* pCxt, SNode* pRealTable) {
|
|||
}
|
||||
|
||||
SNode* createResetQueryCacheStmt(SAstCreateContext* pCxt) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SNode* pStmt = nodesMakeNode(QUERY_NODE_RESET_QUERY_CACHE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SNode* pStmt = nodesMakeNode(QUERY_NODE_COMPACT_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
return pStmt;
|
||||
|
@ -1295,6 +1378,7 @@ SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups) {
|
|||
|
||||
SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName,
|
||||
const SToken* pLibPath, SDataType dataType, int32_t bufSize) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (pLibPath->n <= 2) {
|
||||
pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
|
||||
return NULL;
|
||||
|
@ -1311,6 +1395,7 @@ SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool
|
|||
}
|
||||
|
||||
SNode* createDropFunctionStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pFuncName) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SDropFunctionStmt* pStmt = nodesMakeNode(QUERY_NODE_DROP_FUNCTION_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->ignoreNotExists = ignoreNotExists;
|
||||
|
@ -1319,6 +1404,7 @@ SNode* createDropFunctionStmt(SAstCreateContext* pCxt, bool ignoreNotExists, con
|
|||
}
|
||||
|
||||
SNode* createStreamOptions(SAstCreateContext* pCxt) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SStreamOptions* pOptions = nodesMakeNode(QUERY_NODE_STREAM_OPTIONS);
|
||||
CHECK_OUT_OF_MEM(pOptions);
|
||||
pOptions->triggerType = STREAM_TRIGGER_AT_ONCE;
|
||||
|
@ -1327,6 +1413,7 @@ SNode* createStreamOptions(SAstCreateContext* pCxt) {
|
|||
|
||||
SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pStreamName, SNode* pRealTable,
|
||||
SNode* pOptions, SNode* pQuery) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SCreateStreamStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_STREAM_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
strncpy(pStmt->streamName, pStreamName->z, pStreamName->n);
|
||||
|
@ -1342,6 +1429,7 @@ SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const
|
|||
}
|
||||
|
||||
SNode* createDropStreamStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pStreamName) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SDropStreamStmt* pStmt = nodesMakeNode(QUERY_NODE_DROP_STREAM_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
strncpy(pStmt->streamName, pStreamName->z, pStreamName->n);
|
||||
|
@ -1350,6 +1438,7 @@ SNode* createDropStreamStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const
|
|||
}
|
||||
|
||||
SNode* createKillStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pId) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SKillStmt* pStmt = nodesMakeNode(type);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
pStmt->targetId = taosStr2Int32(pId->z, NULL, 10);
|
||||
|
@ -1357,30 +1446,35 @@ SNode* createKillStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pId
|
|||
}
|
||||
|
||||
SNode* createMergeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId1, const SToken* pVgId2) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SNode* pStmt = nodesMakeNode(QUERY_NODE_MERGE_VGROUP_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* createRedistributeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId, SNodeList* pDnodes) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SNode* pStmt = nodesMakeNode(QUERY_NODE_REDISTRIBUTE_VGROUP_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* createSplitVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SNode* pStmt = nodesMakeNode(QUERY_NODE_SPLIT_VGROUP_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* createSyncdbStmt(SAstCreateContext* pCxt, const SToken* pDbName) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
SNode* pStmt = nodesMakeNode(QUERY_NODE_SYNCDB_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* createGrantStmt(SAstCreateContext* pCxt, int64_t privileges, SToken* pDbName, SToken* pUserName) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkDbName(pCxt, pDbName, false) || !checkUserName(pCxt, pUserName)) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1393,6 +1487,7 @@ SNode* createGrantStmt(SAstCreateContext* pCxt, int64_t privileges, SToken* pDbN
|
|||
}
|
||||
|
||||
SNode* createRevokeStmt(SAstCreateContext* pCxt, int64_t privileges, SToken* pDbName, SToken* pUserName) {
|
||||
CHECK_PARSER_STATUS(pCxt);
|
||||
if (!checkDbName(pCxt, pDbName, false) || !checkUserName(pCxt, pUserName)) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -176,11 +176,11 @@ static int32_t calcConstProject(SNode* pProject, SNode** pNew) {
|
|||
}
|
||||
|
||||
int32_t code = scalarCalculateConstants(pProject, pNew);
|
||||
if (TSDB_CODE_SUCCESS == code && QUERY_NODE_VALUE == nodeType(pNew) && NULL != pAssociation) {
|
||||
if (TSDB_CODE_SUCCESS == code && QUERY_NODE_VALUE == nodeType(*pNew) && NULL != pAssociation) {
|
||||
int32_t size = taosArrayGetSize(pAssociation);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SNode** pCol = taosArrayGet(pAssociation, i);
|
||||
*pCol = nodesCloneNode(pNew);
|
||||
SNode** pCol = taosArrayGetP(pAssociation, i);
|
||||
*pCol = nodesCloneNode(*pNew);
|
||||
if (NULL == *pCol) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -233,9 +233,9 @@ static int32_t calcConstGroupBy(SCalcConstContext* pCxt, SSelectStmt* pSelect) {
|
|||
}
|
||||
|
||||
static int32_t calcConstSelect(SCalcConstContext* pCxt, SSelectStmt* pSelect, bool subquery) {
|
||||
int32_t code = calcConstProjections(pCxt, pSelect, subquery);
|
||||
int32_t code = calcConstFromTable(pCxt, pSelect);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = calcConstFromTable(pCxt, pSelect);
|
||||
code = calcConstProjections(pCxt, pSelect, subquery);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = calcConstSelectCondition(pCxt, pSelect, &pSelect->pWhere);
|
||||
|
|
|
@ -189,6 +189,7 @@ static int32_t createSName(SName* pName, SToken* pTableName, int32_t acctId, con
|
|||
const char* msg1 = "name too long";
|
||||
const char* msg2 = "invalid database name";
|
||||
const char* msg3 = "db is not specified";
|
||||
const char* msg4 = "invalid table name";
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
char* p = strnchr(pTableName->z, TS_PATH_DELIMITER[0], pTableName->n, true);
|
||||
|
@ -207,6 +208,10 @@ static int32_t createSName(SName* pName, SToken* pTableName, int32_t acctId, con
|
|||
}
|
||||
|
||||
int32_t tbLen = pTableName->n - dbLen - 1;
|
||||
if (tbLen <= 0) {
|
||||
return buildInvalidOperationMsg(pMsgBuf, msg4);
|
||||
}
|
||||
|
||||
char tbname[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
strncpy(tbname, p + 1, tbLen);
|
||||
/*tbLen = */ strdequote(tbname);
|
||||
|
@ -1073,7 +1078,6 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
|
|||
int32_t tbNum = 0;
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||
bool autoCreateTbl = false;
|
||||
STableMeta* pMeta = NULL;
|
||||
|
||||
// for each table
|
||||
while (1) {
|
||||
|
@ -1136,12 +1140,10 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
|
|||
CHECK_CODE(getDataBlockFromList(pCxt->pTableBlockHashObj, tbFName, strlen(tbFName), TSDB_DEFAULT_PAYLOAD_SIZE,
|
||||
sizeof(SSubmitBlk), getTableInfo(pCxt->pTableMeta).rowSize, pCxt->pTableMeta,
|
||||
&dataBuf, NULL, &pCxt->createTblReq));
|
||||
pMeta = pCxt->pTableMeta;
|
||||
pCxt->pTableMeta = NULL;
|
||||
|
||||
if (TK_NK_LP == sToken.type) {
|
||||
// pSql -> field1_name, ...)
|
||||
CHECK_CODE(parseBoundColumns(pCxt, &dataBuf->boundColumnInfo, getTableColumnSchema(pMeta)));
|
||||
CHECK_CODE(parseBoundColumns(pCxt, &dataBuf->boundColumnInfo, getTableColumnSchema(pCxt->pTableMeta)));
|
||||
NEXT_TOKEN(pCxt->pSql, sToken);
|
||||
}
|
||||
|
||||
|
@ -1177,7 +1179,7 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
|
|||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
memcpy(tags, &pCxt->tags, sizeof(pCxt->tags));
|
||||
(*pCxt->pStmtCb->setInfoFn)(pCxt->pStmtCb->pStmt, pMeta, tags, tbFName, autoCreateTbl, pCxt->pVgroupsHashObj,
|
||||
(*pCxt->pStmtCb->setInfoFn)(pCxt->pStmtCb->pStmt, pCxt->pTableMeta, tags, tbFName, autoCreateTbl, pCxt->pVgroupsHashObj,
|
||||
pCxt->pTableBlockHashObj);
|
||||
|
||||
memset(&pCxt->tags, 0, sizeof(pCxt->tags));
|
||||
|
|
|
@ -53,6 +53,7 @@ static SKeyword keywordTable[] = {
|
|||
{"CACHE", TK_CACHE},
|
||||
{"CACHELAST", TK_CACHELAST},
|
||||
{"CAST", TK_CAST},
|
||||
{"CGROUP", TK_CGROUP},
|
||||
{"CLUSTER", TK_CLUSTER},
|
||||
{"COLUMN", TK_COLUMN},
|
||||
{"COMMENT", TK_COMMENT},
|
||||
|
@ -156,6 +157,7 @@ static SKeyword keywordTable[] = {
|
|||
{"REVOKE", TK_REVOKE},
|
||||
{"ROLLUP", TK_ROLLUP},
|
||||
{"SCHEMA", TK_SCHEMA},
|
||||
{"SCHEMALESS", TK_SCHEMALESS},
|
||||
{"SCORES", TK_SCORES},
|
||||
{"SELECT", TK_SELECT},
|
||||
{"SESSION", TK_SESSION},
|
||||
|
@ -605,12 +607,12 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
|
|||
}
|
||||
return i;
|
||||
}
|
||||
case '[': {
|
||||
for (i = 1; z[i] && z[i - 1] != ']'; i++) {
|
||||
}
|
||||
*tokenId = TK_NK_ID;
|
||||
return i;
|
||||
}
|
||||
// case '[': {
|
||||
// for (i = 1; z[i] && z[i - 1] != ']'; i++) {
|
||||
// }
|
||||
// *tokenId = TK_NK_ID;
|
||||
// return i;
|
||||
// }
|
||||
case 'T':
|
||||
case 't':
|
||||
case 'F':
|
||||
|
|
|
@ -342,12 +342,14 @@ static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* p
|
|||
}
|
||||
}
|
||||
|
||||
static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SColumnNode* pCol) {
|
||||
static void setColumnInfoByExpr(const STableNode* pTable, SExprNode* pExpr, SColumnNode** pColRef) {
|
||||
SColumnNode* pCol = *pColRef;
|
||||
|
||||
pCol->pProjectRef = (SNode*)pExpr;
|
||||
if (NULL == pExpr->pAssociation) {
|
||||
pExpr->pAssociation = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES);
|
||||
}
|
||||
taosArrayPush(pExpr->pAssociation, &pCol);
|
||||
taosArrayPush(pExpr->pAssociation, &pColRef);
|
||||
if (NULL != pTable) {
|
||||
strcpy(pCol->tableAlias, pTable->tableAlias);
|
||||
} else if (QUERY_NODE_COLUMN == nodeType(pExpr)) {
|
||||
|
@ -385,7 +387,7 @@ static int32_t createColumnsByTable(STranslateContext* pCxt, const STableNode* p
|
|||
if (NULL == pCol) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
setColumnInfoByExpr(pTable, (SExprNode*)pNode, pCol);
|
||||
setColumnInfoByExpr(pTable, (SExprNode*)pNode, &pCol);
|
||||
nodesListAppend(pList, (SNode*)pCol);
|
||||
}
|
||||
}
|
||||
|
@ -425,8 +427,9 @@ static bool isPrimaryKey(STempTableNode* pTable, SNode* pExpr) {
|
|||
return isPrimaryKeyImpl(pTable, pExpr);
|
||||
}
|
||||
|
||||
static bool findAndSetColumn(SColumnNode* pCol, const STableNode* pTable) {
|
||||
bool found = false;
|
||||
static bool findAndSetColumn(SColumnNode** pColRef, const STableNode* pTable) {
|
||||
SColumnNode* pCol = *pColRef;
|
||||
bool found = false;
|
||||
if (QUERY_NODE_REAL_TABLE == nodeType(pTable)) {
|
||||
const STableMeta* pMeta = ((SRealTableNode*)pTable)->pMeta;
|
||||
if (isInternalPrimaryKey(pCol)) {
|
||||
|
@ -448,7 +451,7 @@ static bool findAndSetColumn(SColumnNode* pCol, const STableNode* pTable) {
|
|||
SExprNode* pExpr = (SExprNode*)pNode;
|
||||
if (0 == strcmp(pCol->colName, pExpr->aliasName) ||
|
||||
(isPrimaryKey((STempTableNode*)pTable, pNode) && isInternalPrimaryKey(pCol))) {
|
||||
setColumnInfoByExpr(pTable, pExpr, pCol);
|
||||
setColumnInfoByExpr(pTable, pExpr, pColRef);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
@ -457,36 +460,36 @@ static bool findAndSetColumn(SColumnNode* pCol, const STableNode* pTable) {
|
|||
return found;
|
||||
}
|
||||
|
||||
static EDealRes translateColumnWithPrefix(STranslateContext* pCxt, SColumnNode* pCol) {
|
||||
static EDealRes translateColumnWithPrefix(STranslateContext* pCxt, SColumnNode** pCol) {
|
||||
SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel);
|
||||
size_t nums = taosArrayGetSize(pTables);
|
||||
bool foundTable = false;
|
||||
for (size_t i = 0; i < nums; ++i) {
|
||||
STableNode* pTable = taosArrayGetP(pTables, i);
|
||||
if (belongTable(pCxt->pParseCxt->db, pCol, pTable)) {
|
||||
if (belongTable(pCxt->pParseCxt->db, (*pCol), pTable)) {
|
||||
foundTable = true;
|
||||
if (findAndSetColumn(pCol, pTable)) {
|
||||
break;
|
||||
}
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_COLUMN, pCol->colName);
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_COLUMN, (*pCol)->colName);
|
||||
}
|
||||
}
|
||||
if (!foundTable) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_TABLE_NOT_EXIST, pCol->tableAlias);
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_TABLE_NOT_EXIST, (*pCol)->tableAlias);
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static EDealRes translateColumnWithoutPrefix(STranslateContext* pCxt, SColumnNode* pCol) {
|
||||
static EDealRes translateColumnWithoutPrefix(STranslateContext* pCxt, SColumnNode** pCol) {
|
||||
SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel);
|
||||
size_t nums = taosArrayGetSize(pTables);
|
||||
bool found = false;
|
||||
bool isInternalPk = isInternalPrimaryKey(pCol);
|
||||
bool isInternalPk = isInternalPrimaryKey(*pCol);
|
||||
for (size_t i = 0; i < nums; ++i) {
|
||||
STableNode* pTable = taosArrayGetP(pTables, i);
|
||||
if (findAndSetColumn(pCol, pTable)) {
|
||||
if (found) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_AMBIGUOUS_COLUMN, pCol->colName);
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_AMBIGUOUS_COLUMN, (*pCol)->colName);
|
||||
}
|
||||
found = true;
|
||||
if (isInternalPk) {
|
||||
|
@ -501,18 +504,18 @@ static EDealRes translateColumnWithoutPrefix(STranslateContext* pCxt, SColumnNod
|
|||
}
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_INTERNAL_PK);
|
||||
} else {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_COLUMN, pCol->colName);
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_COLUMN, (*pCol)->colName);
|
||||
}
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static bool translateColumnUseAlias(STranslateContext* pCxt, SColumnNode* pCol) {
|
||||
static bool translateColumnUseAlias(STranslateContext* pCxt, SColumnNode** pCol) {
|
||||
SNodeList* pProjectionList = pCxt->pCurrStmt->pProjectionList;
|
||||
SNode* pNode;
|
||||
FOREACH(pNode, pProjectionList) {
|
||||
SExprNode* pExpr = (SExprNode*)pNode;
|
||||
if (0 == strcmp(pCol->colName, pExpr->aliasName)) {
|
||||
if (0 == strcmp((*pCol)->colName, pExpr->aliasName)) {
|
||||
setColumnInfoByExpr(NULL, pExpr, pCol);
|
||||
return true;
|
||||
}
|
||||
|
@ -520,14 +523,14 @@ static bool translateColumnUseAlias(STranslateContext* pCxt, SColumnNode* pCol)
|
|||
return false;
|
||||
}
|
||||
|
||||
static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode* pCol) {
|
||||
static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode** pCol) {
|
||||
// count(*)/first(*)/last(*) and so on
|
||||
if (0 == strcmp(pCol->colName, "*")) {
|
||||
if (0 == strcmp((*pCol)->colName, "*")) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
EDealRes res = DEAL_RES_CONTINUE;
|
||||
if ('\0' != pCol->tableAlias[0]) {
|
||||
if ('\0' != (*pCol)->tableAlias[0]) {
|
||||
res = translateColumnWithPrefix(pCxt, pCol);
|
||||
} else {
|
||||
bool found = false;
|
||||
|
@ -870,6 +873,55 @@ static int32_t getFuncInfo(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
|||
return fmGetFuncInfo(¶m, pFunc);
|
||||
}
|
||||
|
||||
static int32_t translateAggFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||
if (beforeHaving(pCxt->currClause)) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION);
|
||||
}
|
||||
if (hasInvalidFuncNesting(pFunc->pParameterList)) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_AGG_FUNC_NESTING);
|
||||
}
|
||||
if (pCxt->pCurrStmt->hasIndefiniteRowsFunc) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC);
|
||||
}
|
||||
|
||||
if (isCountStar(pFunc)) {
|
||||
return rewriteCountStar(pCxt, pFunc);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateScanPseudoColumnFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||
if (0 == LIST_LENGTH(pFunc->pParameterList)) {
|
||||
if (QUERY_NODE_REAL_TABLE != nodeType(pCxt->pCurrStmt->pFromTable)) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TBNAME);
|
||||
}
|
||||
} else {
|
||||
SValueNode* pVal = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
STableNode* pTable = NULL;
|
||||
pCxt->errCode = findTable(pCxt, pVal->literal, &pTable);
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode && (NULL == pTable || QUERY_NODE_REAL_TABLE != nodeType(pTable))) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TBNAME);
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateIndefiniteRowsFunc(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||
if (SQL_CLAUSE_SELECT != pCxt->currClause || pCxt->pCurrStmt->hasIndefiniteRowsFunc || pCxt->pCurrStmt->hasAggFuncs) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC);
|
||||
}
|
||||
if (hasInvalidFuncNesting(pFunc->pParameterList)) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_AGG_FUNC_NESTING);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void setFuncClassification(SSelectStmt* pSelect, SFunctionNode* pFunc) {
|
||||
pSelect->hasAggFuncs = pSelect->hasAggFuncs ? true : fmIsAggFunc(pFunc->funcId);
|
||||
pSelect->hasRepeatScanFuncs = pSelect->hasRepeatScanFuncs ? true : fmIsRepeatScanFunc(pFunc->funcId);
|
||||
pSelect->hasIndefiniteRowsFunc = pSelect->hasIndefiniteRowsFunc ? true : fmIsIndefiniteRowsFunc(pFunc->funcId);
|
||||
}
|
||||
|
||||
static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||
SNode* pParam = NULL;
|
||||
FOREACH(pParam, pFunc->pParameterList) {
|
||||
|
@ -880,48 +932,16 @@ static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc)
|
|||
|
||||
pCxt->errCode = getFuncInfo(pCxt, pFunc);
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode && fmIsAggFunc(pFunc->funcId)) {
|
||||
if (beforeHaving(pCxt->currClause)) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION);
|
||||
}
|
||||
if (hasInvalidFuncNesting(pFunc->pParameterList)) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_AGG_FUNC_NESTING);
|
||||
}
|
||||
if (pCxt->pCurrStmt->hasIndefiniteRowsFunc) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_NOT_ALLOWED_FUNC);
|
||||
}
|
||||
|
||||
pCxt->pCurrStmt->hasAggFuncs = true;
|
||||
if (isCountStar(pFunc)) {
|
||||
pCxt->errCode = rewriteCountStar(pCxt, pFunc);
|
||||
}
|
||||
|
||||
if (fmIsRepeatScanFunc(pFunc->funcId)) {
|
||||
pCxt->pCurrStmt->hasRepeatScanFuncs = true;
|
||||
}
|
||||
pCxt->errCode = translateAggFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode && fmIsScanPseudoColumnFunc(pFunc->funcId)) {
|
||||
if (0 == LIST_LENGTH(pFunc->pParameterList)) {
|
||||
if (QUERY_NODE_REAL_TABLE != nodeType(pCxt->pCurrStmt->pFromTable)) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_TBNAME);
|
||||
}
|
||||
} else {
|
||||
SValueNode* pVal = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
STableNode* pTable = NULL;
|
||||
pCxt->errCode = findTable(pCxt, pVal->literal, &pTable);
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode && (NULL == pTable || QUERY_NODE_REAL_TABLE != nodeType(pTable))) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_TBNAME);
|
||||
}
|
||||
}
|
||||
pCxt->errCode = translateScanPseudoColumnFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode && fmIsIndefiniteRowsFunc(pFunc->funcId)) {
|
||||
if (SQL_CLAUSE_SELECT != pCxt->currClause || pCxt->pCurrStmt->hasIndefiniteRowsFunc ||
|
||||
pCxt->pCurrStmt->hasAggFuncs) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_NOT_ALLOWED_FUNC);
|
||||
}
|
||||
if (hasInvalidFuncNesting(pFunc->pParameterList)) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_AGG_FUNC_NESTING);
|
||||
}
|
||||
pCxt->pCurrStmt->hasIndefiniteRowsFunc = true;
|
||||
pCxt->errCode = translateIndefiniteRowsFunc(pCxt, pFunc);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||
setFuncClassification(pCxt->pCurrStmt, pFunc);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
|
||||
}
|
||||
|
@ -936,34 +956,34 @@ static EDealRes translateLogicCond(STranslateContext* pCxt, SLogicConditionNode*
|
|||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static EDealRes doTranslateExpr(SNode* pNode, void* pContext) {
|
||||
static EDealRes doTranslateExpr(SNode** pNode, void* pContext) {
|
||||
STranslateContext* pCxt = (STranslateContext*)pContext;
|
||||
switch (nodeType(pNode)) {
|
||||
switch (nodeType(*pNode)) {
|
||||
case QUERY_NODE_COLUMN:
|
||||
return translateColumn(pCxt, (SColumnNode*)pNode);
|
||||
return translateColumn(pCxt, (SColumnNode**)pNode);
|
||||
case QUERY_NODE_VALUE:
|
||||
return translateValue(pCxt, (SValueNode*)pNode);
|
||||
return translateValue(pCxt, (SValueNode*)*pNode);
|
||||
case QUERY_NODE_OPERATOR:
|
||||
return translateOperator(pCxt, (SOperatorNode*)pNode);
|
||||
return translateOperator(pCxt, (SOperatorNode*)*pNode);
|
||||
case QUERY_NODE_FUNCTION:
|
||||
return translateFunction(pCxt, (SFunctionNode*)pNode);
|
||||
return translateFunction(pCxt, (SFunctionNode*)*pNode);
|
||||
case QUERY_NODE_LOGIC_CONDITION:
|
||||
return translateLogicCond(pCxt, (SLogicConditionNode*)pNode);
|
||||
return translateLogicCond(pCxt, (SLogicConditionNode*)*pNode);
|
||||
case QUERY_NODE_TEMP_TABLE:
|
||||
return translateExprSubquery(pCxt, ((STempTableNode*)pNode)->pSubquery);
|
||||
return translateExprSubquery(pCxt, ((STempTableNode*)*pNode)->pSubquery);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static int32_t translateExpr(STranslateContext* pCxt, SNode* pNode) {
|
||||
nodesWalkExprPostOrder(pNode, doTranslateExpr, pCxt);
|
||||
static int32_t translateExpr(STranslateContext* pCxt, SNode** pNode) {
|
||||
nodesRewriteExprPostOrder(pNode, doTranslateExpr, pCxt);
|
||||
return pCxt->errCode;
|
||||
}
|
||||
|
||||
static int32_t translateExprList(STranslateContext* pCxt, SNodeList* pList) {
|
||||
nodesWalkExprsPostOrder(pList, doTranslateExpr, pCxt);
|
||||
nodesRewriteExprsPostOrder(pList, doTranslateExpr, pCxt);
|
||||
return pCxt->errCode;
|
||||
}
|
||||
|
||||
|
@ -1238,12 +1258,31 @@ static uint8_t getStmtPrecision(SNode* pStmt) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static bool stmtIsSingleTable(SNode* pStmt) {
|
||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||
return ((STableNode*)((SSelectStmt*)pStmt)->pFromTable)->singleTable;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static uint8_t getJoinTablePrecision(SJoinTableNode* pJoinTable) {
|
||||
uint8_t lp = ((STableNode*)pJoinTable->pLeft)->precision;
|
||||
uint8_t rp = ((STableNode*)pJoinTable->pRight)->precision;
|
||||
return (lp > rp ? rp : lp);
|
||||
}
|
||||
|
||||
static bool joinTableIsSingleTable(SJoinTableNode* pJoinTable) {
|
||||
return (((STableNode*)pJoinTable->pLeft)->singleTable && ((STableNode*)pJoinTable->pRight)->singleTable);
|
||||
}
|
||||
|
||||
static bool isSingleTable(SRealTableNode* pRealTable) {
|
||||
int8_t tableType = pRealTable->pMeta->tableType;
|
||||
if (TSDB_SYSTEM_TABLE == tableType) {
|
||||
return 0 != strcmp(pRealTable->table.tableName, TSDB_INS_TABLE_USER_TABLES);
|
||||
}
|
||||
return (TSDB_CHILD_TABLE == tableType || TSDB_NORMAL_TABLE == tableType);
|
||||
}
|
||||
|
||||
static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
switch (nodeType(pTable)) {
|
||||
|
@ -1262,6 +1301,7 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) {
|
|||
code = setTableVgroupList(pCxt, &name, pRealTable);
|
||||
}
|
||||
pRealTable->table.precision = pRealTable->pMeta->tableInfo.precision;
|
||||
pRealTable->table.singleTable = isSingleTable(pRealTable);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = addNamespace(pCxt, pRealTable);
|
||||
}
|
||||
|
@ -1272,6 +1312,7 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) {
|
|||
code = translateSubquery(pCxt, pTempTable->pSubquery);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pTempTable->table.precision = getStmtPrecision(pTempTable->pSubquery);
|
||||
pTempTable->table.singleTable = stmtIsSingleTable(pTempTable->pSubquery);
|
||||
code = addNamespace(pCxt, pTempTable);
|
||||
}
|
||||
break;
|
||||
|
@ -1284,7 +1325,8 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) {
|
|||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pJoinTable->table.precision = getJoinTablePrecision(pJoinTable);
|
||||
code = translateExpr(pCxt, pJoinTable->pOnCond);
|
||||
pJoinTable->table.singleTable = joinTableIsSingleTable(pJoinTable);
|
||||
code = translateExpr(pCxt, &pJoinTable->pOnCond);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1517,7 +1559,7 @@ static int32_t translateOrderByPosition(STranslateContext* pCxt, SNodeList* pPro
|
|||
if (NULL == pCol) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
setColumnInfoByExpr(NULL, (SExprNode*)nodesListGetNode(pProjectionList, pos - 1), pCol);
|
||||
setColumnInfoByExpr(NULL, (SExprNode*)nodesListGetNode(pProjectionList, pos - 1), &pCol);
|
||||
((SOrderByExprNode*)pNode)->pExpr = (SNode*)pCol;
|
||||
nodesDestroyNode(pExpr);
|
||||
}
|
||||
|
@ -1563,7 +1605,7 @@ static int32_t translateHaving(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
|||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_GROUPBY_LACK_EXPRESSION);
|
||||
}
|
||||
pCxt->currClause = SQL_CLAUSE_HAVING;
|
||||
int32_t code = translateExpr(pCxt, pSelect->pHaving);
|
||||
int32_t code = translateExpr(pCxt, &pSelect->pHaving);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = checkExprForGroupBy(pCxt, &pSelect->pHaving);
|
||||
}
|
||||
|
@ -1811,7 +1853,7 @@ static int32_t translateWindow(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
pCxt->currClause = SQL_CLAUSE_WINDOW;
|
||||
int32_t code = translateExpr(pCxt, pSelect->pWindow);
|
||||
int32_t code = translateExpr(pCxt, &pSelect->pWindow);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = checkWindow(pCxt, pSelect);
|
||||
}
|
||||
|
@ -1825,7 +1867,7 @@ static int32_t translatePartitionBy(STranslateContext* pCxt, SNodeList* pPartiti
|
|||
|
||||
static int32_t translateWhere(STranslateContext* pCxt, SNode* pWhere) {
|
||||
pCxt->currClause = SQL_CLAUSE_WHERE;
|
||||
return translateExpr(pCxt, pWhere);
|
||||
return translateExpr(pCxt, &pWhere);
|
||||
}
|
||||
|
||||
static int32_t translateFrom(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||
|
@ -1857,7 +1899,7 @@ static int32_t createPrimaryKeyColByTable(STranslateContext* pCxt, STableNode* p
|
|||
}
|
||||
pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
strcpy(pCol->colName, PK_TS_COL_INTERNAL_NAME);
|
||||
if (!findAndSetColumn(pCol, pTable)) {
|
||||
if (!findAndSetColumn(&pCol, pTable)) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_TIMELINE_FUNC);
|
||||
}
|
||||
*pPrimaryKey = (SNode*)pCol;
|
||||
|
@ -2075,6 +2117,7 @@ static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pS
|
|||
pReq->replications = pStmt->pOptions->replica;
|
||||
pReq->strict = pStmt->pOptions->strict;
|
||||
pReq->cacheLastRow = pStmt->pOptions->cachelast;
|
||||
pReq->schemaless = pStmt->pOptions->schemaless;
|
||||
pReq->ignoreExist = pStmt->ignoreExists;
|
||||
return buildCreateDbRetentions(pStmt->pOptions->pRetentions, pReq);
|
||||
}
|
||||
|
@ -2274,6 +2317,9 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = checkDbRetentionsOption(pCxt, pOptions->pRetentions);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = checkDbEnumOption(pCxt, "schemaless", pOptions->schemaless, TSDB_DB_SCHEMALESS_ON, TSDB_DB_SCHEMALESS_OFF);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = checkOptionsDependency(pCxt, pDbName, pOptions);
|
||||
}
|
||||
|
@ -2766,6 +2812,8 @@ static int32_t buildRollupAst(STranslateContext* pCxt, SCreateTableStmt* pStmt,
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
taosArrayDestroy(dbCfg.pRetensions);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -3267,6 +3315,18 @@ static int32_t translateDropTopic(STranslateContext* pCxt, SDropTopicStmt* pStmt
|
|||
return buildCmdMsg(pCxt, TDMT_MND_DROP_TOPIC, (FSerializeFunc)tSerializeSMDropTopicReq, &dropReq);
|
||||
}
|
||||
|
||||
static int32_t translateDropCGroup(STranslateContext* pCxt, SDropCGroupStmt* pStmt) {
|
||||
SMDropCgroupReq dropReq = {0};
|
||||
|
||||
SName name;
|
||||
tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->topicName, strlen(pStmt->topicName));
|
||||
tNameGetFullDbName(&name, dropReq.topic);
|
||||
dropReq.igNotExists = pStmt->ignoreNotExists;
|
||||
strcpy(dropReq.cgroup, pStmt->cgroup);
|
||||
|
||||
return buildCmdMsg(pCxt, TDMT_MND_DROP_CGROUP, (FSerializeFunc)tSerializeSMDropCgroupReq, &dropReq);
|
||||
}
|
||||
|
||||
static int32_t translateAlterLocal(STranslateContext* pCxt, SAlterLocalStmt* pStmt) {
|
||||
// todo
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -3326,6 +3386,8 @@ static int32_t buildCreateStreamReq(STranslateContext* pCxt, SCreateStreamStmt*
|
|||
pReq->igExists = pStmt->ignoreExists;
|
||||
|
||||
SName name;
|
||||
// tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->streamName, strlen(pStmt->streamName));
|
||||
// tNameGetFullDbName(&name, pReq->name);
|
||||
tNameExtractFullName(toName(pCxt->pParseCxt->acctId, pCxt->pParseCxt->db, pStmt->streamName, &name), pReq->name);
|
||||
|
||||
if ('\0' != pStmt->targetTabName[0]) {
|
||||
|
@ -3550,6 +3612,9 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
|||
case QUERY_NODE_DROP_TOPIC_STMT:
|
||||
code = translateDropTopic(pCxt, (SDropTopicStmt*)pNode);
|
||||
break;
|
||||
case QUERY_NODE_DROP_CGROUP_STMT:
|
||||
code = translateDropCGroup(pCxt, (SDropCGroupStmt*)pNode);
|
||||
break;
|
||||
case QUERY_NODE_ALTER_LOCAL_STMT:
|
||||
code = translateAlterLocal(pCxt, (SAlterLocalStmt*)pNode);
|
||||
break;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -90,6 +90,7 @@ TEST_F(ParserInitialCTest, createDatabase) {
|
|||
expect.walLevel = TSDB_DEFAULT_WAL_LEVEL;
|
||||
expect.numOfVgroups = TSDB_DEFAULT_VN_PER_DB;
|
||||
expect.numOfStables = TSDB_DEFAULT_DB_SINGLE_STABLE;
|
||||
expect.schemaless = TSDB_DEFAULT_DB_SCHEMALESS;
|
||||
};
|
||||
|
||||
auto setDbBufferFunc = [&](int32_t buffer) { expect.buffer = buffer; };
|
||||
|
@ -124,6 +125,7 @@ TEST_F(ParserInitialCTest, createDatabase) {
|
|||
taosArrayPush(expect.pRetensions, &retention);
|
||||
++expect.numOfRetensions;
|
||||
};
|
||||
auto setDbSchemalessFunc = [&](int8_t schemaless) { expect.schemaless = schemaless; };
|
||||
|
||||
setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
|
||||
ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_CREATE_DATABASE_STMT);
|
||||
|
@ -149,6 +151,7 @@ TEST_F(ParserInitialCTest, createDatabase) {
|
|||
ASSERT_EQ(req.replications, expect.replications);
|
||||
ASSERT_EQ(req.strict, expect.strict);
|
||||
ASSERT_EQ(req.cacheLastRow, expect.cacheLastRow);
|
||||
ASSERT_EQ(req.schemaless, expect.schemaless);
|
||||
ASSERT_EQ(req.ignoreExist, expect.ignoreExist);
|
||||
ASSERT_EQ(req.numOfRetensions, expect.numOfRetensions);
|
||||
if (expect.numOfRetensions > 0) {
|
||||
|
@ -188,6 +191,7 @@ TEST_F(ParserInitialCTest, createDatabase) {
|
|||
setDbWalLevelFunc(2);
|
||||
setDbVgroupsFunc(100);
|
||||
setDbSingleStableFunc(1);
|
||||
setDbSchemalessFunc(1);
|
||||
run("CREATE DATABASE IF NOT EXISTS wxy_db "
|
||||
"BUFFER 64 "
|
||||
"CACHELAST 2 "
|
||||
|
@ -205,7 +209,8 @@ TEST_F(ParserInitialCTest, createDatabase) {
|
|||
"STRICT 1 "
|
||||
"WAL 2 "
|
||||
"VGROUPS 100 "
|
||||
"SINGLE_STABLE 1 ");
|
||||
"SINGLE_STABLE 1 "
|
||||
"SCHEMALESS 1");
|
||||
|
||||
setCreateDbReqFunc("wxy_db", 1);
|
||||
setDbDaysFunc(100);
|
||||
|
|
|
@ -19,7 +19,7 @@ using namespace std;
|
|||
|
||||
namespace ParserTest {
|
||||
|
||||
class ParserInitialDTest : public ParserTestBase {};
|
||||
class ParserInitialDTest : public ParserDdlTest {};
|
||||
|
||||
// todo delete
|
||||
// todo desc
|
||||
|
@ -29,7 +29,37 @@ class ParserInitialDTest : public ParserTestBase {};
|
|||
TEST_F(ParserInitialDTest, dropBnode) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("drop bnode on dnode 1");
|
||||
run("DROP BNODE ON DNODE 1");
|
||||
}
|
||||
|
||||
// DROP CGROUP [ IF EXISTS ] cgroup_name ON topic_name
|
||||
TEST_F(ParserInitialDTest, dropCGroup) {
|
||||
useDb("root", "test");
|
||||
|
||||
SMDropCgroupReq expect = {0};
|
||||
|
||||
auto setDropCgroupReqFunc = [&](const char* pTopicName, const char* pCGroupName, int8_t igNotExists = 0) {
|
||||
memset(&expect, 0, sizeof(SMDropCgroupReq));
|
||||
snprintf(expect.topic, sizeof(expect.topic), "0.%s", pTopicName);
|
||||
strcpy(expect.cgroup, pCGroupName);
|
||||
expect.igNotExists = igNotExists;
|
||||
};
|
||||
|
||||
setCheckDdlFunc([&](const SQuery* pQuery, ParserStage stage) {
|
||||
ASSERT_EQ(nodeType(pQuery->pRoot), QUERY_NODE_DROP_CGROUP_STMT);
|
||||
SMDropCgroupReq req = {0};
|
||||
ASSERT_TRUE(TSDB_CODE_SUCCESS == tDeserializeSMDropCgroupReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req));
|
||||
|
||||
ASSERT_EQ(std::string(req.topic), std::string(expect.topic));
|
||||
ASSERT_EQ(std::string(req.cgroup), std::string(expect.cgroup));
|
||||
ASSERT_EQ(req.igNotExists, expect.igNotExists);
|
||||
});
|
||||
|
||||
setDropCgroupReqFunc("tp1", "cg1");
|
||||
run("DROP CGROUP cg1 ON tp1");
|
||||
|
||||
setDropCgroupReqFunc("tp1", "cg1", 1);
|
||||
run("DROP CGROUP IF EXISTS cg1 ON tp1");
|
||||
}
|
||||
|
||||
// todo drop database
|
||||
|
|
|
@ -121,13 +121,13 @@ TEST_F(ParserSelectTest, selectFunc) {
|
|||
run("SELECT MAX(c1), c2 FROM t1 STATE_WINDOW(c3)");
|
||||
}
|
||||
|
||||
TEST_F(ParserSelectTest, nonstdFunc) {
|
||||
TEST_F(ParserSelectTest, IndefiniteRowsFunc) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("SELECT DIFF(c1) FROM t1");
|
||||
}
|
||||
|
||||
TEST_F(ParserSelectTest, nonstdFuncSemanticCheck) {
|
||||
TEST_F(ParserSelectTest, IndefiniteRowsFuncSemanticCheck) {
|
||||
useDb("root", "test");
|
||||
|
||||
run("SELECT DIFF(c1), c2 FROM t1", TSDB_CODE_PAR_NOT_ALLOWED_FUNC, PARSER_STAGE_TRANSLATE);
|
||||
|
|
|
@ -321,6 +321,7 @@ static int32_t createJoinLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
|||
}
|
||||
|
||||
pJoin->joinType = pJoinTable->joinType;
|
||||
pJoin->isSingleTableJoin = pJoinTable->table.singleTable;
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -418,7 +419,7 @@ static SColumnNode* createColumnByExpr(const char* pStmtName, SExprNode* pExpr)
|
|||
}
|
||||
|
||||
static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SLogicNode** pLogicNode) {
|
||||
if (!pSelect->hasAggFuncs && !pSelect->hasIndefiniteRowsFunc && NULL == pSelect->pGroupByList) {
|
||||
if (!pSelect->hasAggFuncs && NULL == pSelect->pGroupByList) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -442,8 +443,8 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
|
|||
code = rewriteExprForSelect(pAgg->pGroupKeys, pSelect, SQL_CLAUSE_GROUP_BY);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && (pSelect->hasAggFuncs || pSelect->hasIndefiniteRowsFunc)) {
|
||||
code = nodesCollectFuncs(pSelect, SQL_CLAUSE_GROUP_BY, fmIsVectorFunc, &pAgg->pAggFuncs);
|
||||
if (TSDB_CODE_SUCCESS == code && pSelect->hasAggFuncs) {
|
||||
code = nodesCollectFuncs(pSelect, SQL_CLAUSE_GROUP_BY, fmIsAggFunc, &pAgg->pAggFuncs);
|
||||
}
|
||||
|
||||
// rewrite the expression in subsequent clauses
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#define SPLIT_FLAG_MASK(n) (1 << n)
|
||||
|
||||
#define SPLIT_FLAG_STS SPLIT_FLAG_MASK(0)
|
||||
#define SPLIT_FLAG_CTJ SPLIT_FLAG_MASK(1)
|
||||
|
||||
#define SPLIT_FLAG_SET_MASK(val, mask) (val) |= (mask)
|
||||
#define SPLIT_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0)
|
||||
|
@ -42,7 +41,8 @@ typedef struct SStsInfo {
|
|||
} SStsInfo;
|
||||
|
||||
typedef struct SCtjInfo {
|
||||
SScanLogicNode* pScan;
|
||||
SJoinLogicNode* pJoin;
|
||||
SLogicNode* pSplitNode;
|
||||
SLogicSubplan* pSubplan;
|
||||
} SCtjInfo;
|
||||
|
||||
|
@ -58,7 +58,7 @@ typedef struct SUnInfo {
|
|||
|
||||
typedef bool (*FSplFindSplitNode)(SLogicSubplan* pSubplan, void* pInfo);
|
||||
|
||||
static SLogicSubplan* splCreateScanSubplan(SSplitContext* pCxt, SScanLogicNode* pScan, int32_t flag) {
|
||||
static SLogicSubplan* splCreateSubplan(SSplitContext* pCxt, SLogicNode* pNode, int32_t flag) {
|
||||
SLogicSubplan* pSubplan = nodesMakeNode(QUERY_NODE_LOGIC_SUBPLAN);
|
||||
if (NULL == pSubplan) {
|
||||
return NULL;
|
||||
|
@ -66,35 +66,37 @@ static SLogicSubplan* splCreateScanSubplan(SSplitContext* pCxt, SScanLogicNode*
|
|||
pSubplan->id.queryId = pCxt->queryId;
|
||||
pSubplan->id.groupId = pCxt->groupId;
|
||||
pSubplan->subplanType = SUBPLAN_TYPE_SCAN;
|
||||
pSubplan->pNode = (SLogicNode*)nodesCloneNode(pScan);
|
||||
TSWAP(pSubplan->pVgroupList, ((SScanLogicNode*)pSubplan->pNode)->pVgroupList);
|
||||
pSubplan->pNode = (SLogicNode*)nodesCloneNode(pNode);
|
||||
if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode)) {
|
||||
TSWAP(pSubplan->pVgroupList, ((SScanLogicNode*)pSubplan->pNode)->pVgroupList);
|
||||
}
|
||||
SPLIT_FLAG_SET_MASK(pSubplan->splitFlag, flag);
|
||||
return pSubplan;
|
||||
}
|
||||
|
||||
static int32_t splCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SScanLogicNode* pScan,
|
||||
static int32_t splCreateExchangeNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SLogicNode* pSplitNode,
|
||||
ESubplanType subplanType) {
|
||||
SExchangeLogicNode* pExchange = nodesMakeNode(QUERY_NODE_LOGIC_PLAN_EXCHANGE);
|
||||
if (NULL == pExchange) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pExchange->srcGroupId = pCxt->groupId;
|
||||
pExchange->precision = pScan->pMeta->tableInfo.precision;
|
||||
pExchange->node.pTargets = nodesCloneList(pScan->node.pTargets);
|
||||
pExchange->precision = pSplitNode->precision;
|
||||
pExchange->node.pTargets = nodesCloneList(pSplitNode->pTargets);
|
||||
if (NULL == pExchange->node.pTargets) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
pSubplan->subplanType = SUBPLAN_TYPE_MERGE;
|
||||
pSubplan->subplanType = subplanType;
|
||||
|
||||
if (NULL == pScan->node.pParent) {
|
||||
if (NULL == pSplitNode->pParent) {
|
||||
pSubplan->pNode = (SLogicNode*)pExchange;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SNode* pNode;
|
||||
FOREACH(pNode, pScan->node.pParent->pChildren) {
|
||||
if (nodesEqualNode(pNode, pScan)) {
|
||||
FOREACH(pNode, pSplitNode->pParent->pChildren) {
|
||||
if (nodesEqualNode(pNode, pSplitNode)) {
|
||||
REPLACE_NODE(pExchange);
|
||||
nodesDestroyNode(pNode);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -148,33 +150,31 @@ static int32_t stsSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
|
|||
if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_STS, (FSplFindSplitNode)stsFindSplitNode, &info)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
int32_t code =
|
||||
nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_STS));
|
||||
int32_t code = nodesListMakeStrictAppend(&info.pSubplan->pChildren,
|
||||
splCreateSubplan(pCxt, (SLogicNode*)info.pScan, SPLIT_FLAG_STS));
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = splCreateExchangeNode(pCxt, info.pSubplan, info.pScan, SUBPLAN_TYPE_MERGE);
|
||||
code = splCreateExchangeNode(pCxt, info.pSubplan, (SLogicNode*)info.pScan, SUBPLAN_TYPE_MERGE);
|
||||
}
|
||||
++(pCxt->groupId);
|
||||
pCxt->split = true;
|
||||
return code;
|
||||
}
|
||||
|
||||
static bool ctjIsSingleTable(int8_t tableType) {
|
||||
return (TSDB_CHILD_TABLE == tableType || TSDB_NORMAL_TABLE == tableType);
|
||||
static bool needSplit(SJoinLogicNode* pJoin) {
|
||||
if (!pJoin->isSingleTableJoin) {
|
||||
return false;
|
||||
}
|
||||
return QUERY_NODE_LOGIC_PLAN_EXCHANGE != nodeType(nodesListGetNode(pJoin->node.pChildren, 0)) &&
|
||||
QUERY_NODE_LOGIC_PLAN_EXCHANGE != nodeType(nodesListGetNode(pJoin->node.pChildren, 1));
|
||||
}
|
||||
|
||||
static SLogicNode* ctjMatchByNode(SLogicNode* pNode) {
|
||||
if (QUERY_NODE_LOGIC_PLAN_JOIN == nodeType(pNode)) {
|
||||
SLogicNode* pLeft = (SLogicNode*)nodesListGetNode(pNode->pChildren, 0);
|
||||
SLogicNode* pRight = (SLogicNode*)nodesListGetNode(pNode->pChildren, 1);
|
||||
if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pLeft) && ctjIsSingleTable(((SScanLogicNode*)pLeft)->pMeta->tableType) &&
|
||||
QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pRight) &&
|
||||
ctjIsSingleTable(((SScanLogicNode*)pRight)->pMeta->tableType)) {
|
||||
return pRight;
|
||||
}
|
||||
static SJoinLogicNode* ctjMatchByNode(SLogicNode* pNode) {
|
||||
if (QUERY_NODE_LOGIC_PLAN_JOIN == nodeType(pNode) && needSplit((SJoinLogicNode*)pNode)) {
|
||||
return (SJoinLogicNode*)pNode;
|
||||
}
|
||||
SNode* pChild;
|
||||
FOREACH(pChild, pNode->pChildren) {
|
||||
SLogicNode* pSplitNode = ctjMatchByNode((SLogicNode*)pChild);
|
||||
SJoinLogicNode* pSplitNode = ctjMatchByNode((SLogicNode*)pChild);
|
||||
if (NULL != pSplitNode) {
|
||||
return pSplitNode;
|
||||
}
|
||||
|
@ -183,23 +183,23 @@ static SLogicNode* ctjMatchByNode(SLogicNode* pNode) {
|
|||
}
|
||||
|
||||
static bool ctjFindSplitNode(SLogicSubplan* pSubplan, SCtjInfo* pInfo) {
|
||||
SLogicNode* pSplitNode = ctjMatchByNode(pSubplan->pNode);
|
||||
if (NULL != pSplitNode) {
|
||||
pInfo->pScan = (SScanLogicNode*)pSplitNode;
|
||||
SJoinLogicNode* pJoin = ctjMatchByNode(pSubplan->pNode);
|
||||
if (NULL != pJoin) {
|
||||
pInfo->pJoin = pJoin;
|
||||
pInfo->pSplitNode = nodesListGetNode(pJoin->node.pChildren, 1);
|
||||
pInfo->pSubplan = pSubplan;
|
||||
}
|
||||
return NULL != pSplitNode;
|
||||
return NULL != pJoin;
|
||||
}
|
||||
|
||||
static int32_t ctjSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
|
||||
SCtjInfo info = {0};
|
||||
if (!splMatch(pCxt, pSubplan, SPLIT_FLAG_CTJ, (FSplFindSplitNode)ctjFindSplitNode, &info)) {
|
||||
if (!splMatch(pCxt, pSubplan, 0, (FSplFindSplitNode)ctjFindSplitNode, &info)) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
int32_t code =
|
||||
nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateScanSubplan(pCxt, info.pScan, SPLIT_FLAG_CTJ));
|
||||
int32_t code = nodesListMakeStrictAppend(&info.pSubplan->pChildren, splCreateSubplan(pCxt, info.pSplitNode, 0));
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = splCreateExchangeNode(pCxt, info.pSubplan, info.pScan, info.pSubplan->subplanType);
|
||||
code = splCreateExchangeNode(pCxt, info.pSubplan, info.pSplitNode, info.pSubplan->subplanType);
|
||||
}
|
||||
++(pCxt->groupId);
|
||||
pCxt->split = true;
|
||||
|
|
|
@ -26,6 +26,8 @@ TEST_F(PlanSubqeuryTest, basic) {
|
|||
run("SELECT * FROM (SELECT * FROM t1)");
|
||||
|
||||
run("SELECT LAST(c1) FROM (SELECT * FROM t1)");
|
||||
|
||||
run("SELECT c1 FROM (SELECT TODAY() AS c1 FROM t1)");
|
||||
}
|
||||
|
||||
TEST_F(PlanSubqeuryTest, doubleGroupBy) {
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat-truncation"
|
||||
|
||||
int32_t (*queryBuildMsg[TDMT_MAX])(void *input, char **msg, int32_t msgSize, int32_t *msgLen) = {0};
|
||||
int32_t (*queryBuildMsg[TDMT_MAX])(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallocFp)(int32_t)) = {0};
|
||||
int32_t (*queryProcessMsgRsp[TDMT_MAX])(void *output, char *msg, int32_t msgSize) = {0};
|
||||
|
||||
int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) {
|
||||
|
@ -58,7 +58,7 @@ int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen) {
|
||||
int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) {
|
||||
SBuildTableMetaInput *pInput = input;
|
||||
if (NULL == input || NULL == msg || NULL == msgLen) {
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
|
@ -72,7 +72,7 @@ int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int3
|
|||
tstrncpy(infoReq.tbName, pInput->tbName, TSDB_TABLE_NAME_LEN);
|
||||
|
||||
int32_t bufLen = tSerializeSTableInfoReq(NULL, 0, &infoReq);
|
||||
void *pBuf = rpcMallocCont(bufLen);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSTableInfoReq(pBuf, bufLen, &infoReq);
|
||||
|
||||
*msg = pBuf;
|
||||
|
@ -81,7 +81,7 @@ int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int3
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t queryBuildUseDbMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen) {
|
||||
int32_t queryBuildUseDbMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) {
|
||||
SBuildUseDBInput *pInput = input;
|
||||
if (NULL == pInput || NULL == msg || NULL == msgLen) {
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
|
@ -95,7 +95,7 @@ int32_t queryBuildUseDbMsg(void *input, char **msg, int32_t msgSize, int32_t *ms
|
|||
usedbReq.numOfTable = pInput->numOfTable;
|
||||
|
||||
int32_t bufLen = tSerializeSUseDbReq(NULL, 0, &usedbReq);
|
||||
void *pBuf = rpcMallocCont(bufLen);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSUseDbReq(pBuf, bufLen, &usedbReq);
|
||||
|
||||
*msg = pBuf;
|
||||
|
@ -104,7 +104,7 @@ int32_t queryBuildUseDbMsg(void *input, char **msg, int32_t msgSize, int32_t *ms
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen) {
|
||||
int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) {
|
||||
if (NULL == msg || NULL == msgLen) {
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t
|
|||
qnodeListReq.rowNum = -1;
|
||||
|
||||
int32_t bufLen = tSerializeSQnodeListReq(NULL, 0, &qnodeListReq);
|
||||
void *pBuf = rpcMallocCont(bufLen);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSQnodeListReq(pBuf, bufLen, &qnodeListReq);
|
||||
|
||||
*msg = pBuf;
|
||||
|
@ -122,7 +122,7 @@ int32_t queryBuildQnodeListMsg(void *input, char **msg, int32_t msgSize, int32_t
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen) {
|
||||
int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) {
|
||||
if (NULL == msg || NULL == msgLen) {
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t
|
|||
strcpy(dbCfgReq.db, input);
|
||||
|
||||
int32_t bufLen = tSerializeSDbCfgReq(NULL, 0, &dbCfgReq);
|
||||
void *pBuf = rpcMallocCont(bufLen);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSDbCfgReq(pBuf, bufLen, &dbCfgReq);
|
||||
|
||||
*msg = pBuf;
|
||||
|
@ -140,7 +140,7 @@ int32_t queryBuildGetDBCfgMsg(void *input, char **msg, int32_t msgSize, int32_t
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t queryBuildGetIndexMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen) {
|
||||
int32_t queryBuildGetIndexMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) {
|
||||
if (NULL == msg || NULL == msgLen) {
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ int32_t queryBuildGetIndexMsg(void *input, char **msg, int32_t msgSize, int32_t
|
|||
strcpy(indexReq.indexFName, input);
|
||||
|
||||
int32_t bufLen = tSerializeSUserIndexReq(NULL, 0, &indexReq);
|
||||
void *pBuf = rpcMallocCont(bufLen);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSUserIndexReq(pBuf, bufLen, &indexReq);
|
||||
|
||||
*msg = pBuf;
|
||||
|
@ -158,7 +158,7 @@ int32_t queryBuildGetIndexMsg(void *input, char **msg, int32_t msgSize, int32_t
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen) {
|
||||
int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) {
|
||||
if (NULL == msg || NULL == msgLen) {
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int3
|
|||
taosArrayPush(funcReq.pFuncNames, input);
|
||||
|
||||
int32_t bufLen = tSerializeSRetrieveFuncReq(NULL, 0, &funcReq);
|
||||
void *pBuf = rpcMallocCont(bufLen);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSRetrieveFuncReq(pBuf, bufLen, &funcReq);
|
||||
|
||||
taosArrayDestroy(funcReq.pFuncNames);
|
||||
|
@ -181,7 +181,7 @@ int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int3
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t queryBuildGetUserAuthMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen) {
|
||||
int32_t queryBuildGetUserAuthMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallcFp)(int32_t)) {
|
||||
if (NULL == msg || NULL == msgLen) {
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ int32_t queryBuildGetUserAuthMsg(void *input, char **msg, int32_t msgSize, int32
|
|||
strncpy(req.user, input, sizeof(req.user));
|
||||
|
||||
int32_t bufLen = tSerializeSGetUserAuthReq(NULL, 0, &req);
|
||||
void *pBuf = rpcMallocCont(bufLen);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
tSerializeSGetUserAuthReq(pBuf, bufLen, &req);
|
||||
|
||||
*msg = pBuf;
|
||||
|
|
|
@ -39,9 +39,14 @@ enum {
|
|||
SCH_WRITE,
|
||||
};
|
||||
|
||||
enum {
|
||||
SCH_EXEC_CB = 1,
|
||||
SCH_FETCH_CB,
|
||||
};
|
||||
|
||||
typedef struct SSchTrans {
|
||||
void *transInst;
|
||||
void *transHandle;
|
||||
void *pTrans;
|
||||
void *pHandle;
|
||||
} SSchTrans;
|
||||
|
||||
typedef struct SSchHbTrans {
|
||||
|
@ -74,12 +79,19 @@ typedef struct SSchJobStat {
|
|||
|
||||
} SSchJobStat;
|
||||
|
||||
typedef struct SSchedulerStat {
|
||||
typedef struct SSchStat {
|
||||
SSchApiStat api;
|
||||
SSchRuntimeStat runtime;
|
||||
SSchJobStat job;
|
||||
} SSchedulerStat;
|
||||
} SSchStat;
|
||||
|
||||
typedef struct SSchResInfo {
|
||||
SQueryResult* queryRes;
|
||||
void** fetchRes;
|
||||
schedulerExecCallback execFp;
|
||||
schedulerFetchCallback fetchFp;
|
||||
void* userParam;
|
||||
} SSchResInfo;
|
||||
|
||||
typedef struct SSchedulerMgmt {
|
||||
uint64_t taskId; // sequential taksId
|
||||
|
@ -89,7 +101,7 @@ typedef struct SSchedulerMgmt {
|
|||
bool exit;
|
||||
int32_t jobRef;
|
||||
int32_t jobNum;
|
||||
SSchedulerStat stat;
|
||||
SSchStat stat;
|
||||
SHashObj *hbConnections;
|
||||
} SSchedulerMgmt;
|
||||
|
||||
|
@ -108,7 +120,7 @@ typedef struct SSchTaskCallbackParam {
|
|||
typedef struct SSchHbCallbackParam {
|
||||
SSchCallbackParamHeader head;
|
||||
SQueryNodeEpId nodeEpId;
|
||||
void *transport;
|
||||
void *pTrans;
|
||||
} SSchHbCallbackParam;
|
||||
|
||||
typedef struct SSchFlowControl {
|
||||
|
@ -170,7 +182,7 @@ typedef struct SSchJob {
|
|||
SSchJobAttr attr;
|
||||
int32_t levelNum;
|
||||
int32_t taskNum;
|
||||
void *transport;
|
||||
void *pTrans;
|
||||
SArray *nodeList; // qnode/vnode list, SArray<SQueryNodeAddr>
|
||||
SArray *levels; // starting from 0. SArray<SSchLevel>
|
||||
SNodeList *subPlans; // subplan pointer copied from DAG, no need to free it in scheduler
|
||||
|
@ -191,12 +203,13 @@ typedef struct SSchJob {
|
|||
int32_t remoteFetch;
|
||||
SSchTask *fetchTask;
|
||||
int32_t errCode;
|
||||
SArray *errList; // SArray<SQueryErrorInfo>
|
||||
SRWLatch resLock;
|
||||
void *queryRes;
|
||||
void *resData; //TODO free it or not
|
||||
int32_t resNumOfRows;
|
||||
SSchResInfo userRes;
|
||||
const char *sql;
|
||||
int32_t userCb;
|
||||
SQueryProfileSummary summary;
|
||||
} SSchJob;
|
||||
|
||||
|
@ -292,15 +305,21 @@ int32_t schUpdateTaskExecNodeHandle(SSchTask *pTask, void *handle, int32_t rspCo
|
|||
void schFreeRpcCtxVal(const void *arg);
|
||||
int32_t schMakeBrokenLinkVal(SSchJob *pJob, SSchTask *pTask, SRpcBrokenlinkVal *brokenVal, bool isHb);
|
||||
int32_t schRecordTaskExecNode(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, void *handle);
|
||||
int32_t schExecStaticExplain(void *transport, SArray *pNodeList, SQueryPlan *pDag, int64_t *job, const char *sql,
|
||||
bool syncSchedule);
|
||||
int32_t schExecJobImpl(void *transport, SArray *pNodeList, SQueryPlan *pDag, int64_t *job, const char *sql,
|
||||
int64_t startTs, bool sync);
|
||||
int32_t schExecStaticExplainJob(void *pTrans, SArray *pNodeList, SQueryPlan *pDag, int64_t *job, const char *sql,
|
||||
SSchResInfo *pRes, bool sync);
|
||||
int32_t schExecJobImpl(void *pTrans, SArray *pNodeList, SQueryPlan *pDag, int64_t *job, const char *sql,
|
||||
SSchResInfo *pRes, int64_t startTs, bool sync);
|
||||
int32_t schChkUpdateJobStatus(SSchJob *pJob, int8_t newStatus);
|
||||
int32_t schCancelJob(SSchJob *pJob);
|
||||
int32_t schProcessOnJobDropped(SSchJob *pJob, int32_t errCode);
|
||||
uint64_t schGenTaskId(void);
|
||||
void schCloseJobRef(void);
|
||||
int32_t schExecJob(void *pTrans, SArray *pNodeList, SQueryPlan *pDag, int64_t *pJob, const char *sql,
|
||||
int64_t startTs, SSchResInfo *pRes);
|
||||
int32_t schAsyncExecJob(void *pTrans, SArray *pNodeList, SQueryPlan *pDag, int64_t *pJob, const char *sql,
|
||||
int64_t startTs, SSchResInfo *pRes);
|
||||
int32_t schFetchRows(SSchJob *pJob);
|
||||
int32_t schAsyncFetchRows(SSchJob *pJob);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -39,8 +39,8 @@ int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel *
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t schInitJob(SSchJob **pSchJob, SQueryPlan *pDag, void *transport, SArray *pNodeList, const char *sql,
|
||||
int64_t startTs, bool syncSchedule) {
|
||||
int32_t schInitJob(SSchJob **pSchJob, SQueryPlan *pDag, void *pTrans, SArray *pNodeList, const char *sql,
|
||||
SSchResInfo *pRes, int64_t startTs, bool syncSchedule) {
|
||||
int32_t code = 0;
|
||||
int64_t refId = -1;
|
||||
SSchJob *pJob = taosMemoryCalloc(1, sizeof(SSchJob));
|
||||
|
@ -51,9 +51,12 @@ int32_t schInitJob(SSchJob **pSchJob, SQueryPlan *pDag, void *transport, SArray
|
|||
|
||||
pJob->attr.explainMode = pDag->explainInfo.mode;
|
||||
pJob->attr.syncSchedule = syncSchedule;
|
||||
pJob->transport = transport;
|
||||
pJob->pTrans = pTrans;
|
||||
pJob->sql = sql;
|
||||
|
||||
if (pRes) {
|
||||
pJob->userRes = *pRes;
|
||||
}
|
||||
|
||||
if (pNodeList != NULL) {
|
||||
pJob->nodeList = taosArrayDup(pNodeList);
|
||||
}
|
||||
|
@ -458,6 +461,7 @@ int32_t schValidateAndBuildJob(SQueryPlan *pDag, SSchJob *pJob) {
|
|||
SCH_ERR_JRET(schBuildTaskRalation(pJob, planToTask));
|
||||
|
||||
_return:
|
||||
|
||||
if (planToTask) {
|
||||
taosHashCleanup(planToTask);
|
||||
}
|
||||
|
@ -727,6 +731,69 @@ _return:
|
|||
SCH_JOB_DLOG("job errCode updated to %x - %s", errCode, tstrerror(errCode));
|
||||
}
|
||||
|
||||
|
||||
int32_t schSetJobQueryRes(SSchJob* pJob, SQueryResult* pRes) {
|
||||
pRes->code = atomic_load_32(&pJob->errCode);
|
||||
pRes->numOfRows = pJob->resNumOfRows;
|
||||
pRes->res = pJob->queryRes;
|
||||
pJob->queryRes = NULL;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t schSetJobFetchRes(SSchJob* pJob, void** pData) {
|
||||
int32_t code = 0;
|
||||
if (pJob->resData && ((SRetrieveTableRsp *)pJob->resData)->completed) {
|
||||
SCH_ERR_RET(schChkUpdateJobStatus(pJob, JOB_TASK_STATUS_SUCCEED));
|
||||
}
|
||||
|
||||
while (true) {
|
||||
*pData = atomic_load_ptr(&pJob->resData);
|
||||
if (*pData != atomic_val_compare_exchange_ptr(&pJob->resData, *pData, NULL)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (NULL == *pData) {
|
||||
SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, sizeof(SRetrieveTableRsp));
|
||||
if (rsp) {
|
||||
rsp->completed = 1;
|
||||
}
|
||||
|
||||
*pData = rsp;
|
||||
SCH_JOB_DLOG("empty res and set query complete, code:%x", code);
|
||||
}
|
||||
|
||||
SCH_JOB_DLOG("fetch done, totalRows:%d", pJob->resNumOfRows);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t schNotifyUserQueryRes(SSchJob* pJob) {
|
||||
pJob->userRes.queryRes = taosMemoryCalloc(1, sizeof(*pJob->userRes.queryRes));
|
||||
if (pJob->userRes.queryRes) {
|
||||
schSetJobQueryRes(pJob, pJob->userRes.queryRes);
|
||||
}
|
||||
|
||||
(*pJob->userRes.execFp)(pJob->userRes.queryRes, pJob->userRes.userParam, atomic_load_32(&pJob->errCode));
|
||||
|
||||
pJob->userRes.queryRes = NULL;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t schNotifyUserFetchRes(SSchJob* pJob) {
|
||||
void* pRes = NULL;
|
||||
|
||||
SCH_ERR_RET(schSetJobFetchRes(pJob, &pRes));
|
||||
|
||||
(*pJob->userRes.fetchFp)(pRes, pJob->userRes.userParam, atomic_load_32(&pJob->errCode));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t schProcessOnJobFailureImpl(SSchJob *pJob, int32_t status, int32_t errCode) {
|
||||
// if already FAILED, no more processing
|
||||
SCH_ERR_RET(schChkUpdateJobStatus(pJob, status));
|
||||
|
@ -741,6 +808,14 @@ int32_t schProcessOnJobFailureImpl(SSchJob *pJob, int32_t status, int32_t errCod
|
|||
|
||||
SCH_JOB_DLOG("job failed with error: %s", tstrerror(code));
|
||||
|
||||
if (!pJob->attr.syncSchedule) {
|
||||
if (SCH_EXEC_CB == atomic_val_compare_exchange_32(&pJob->userCb, SCH_EXEC_CB, 0)) {
|
||||
schNotifyUserQueryRes(pJob);
|
||||
} else if (SCH_FETCH_CB == atomic_val_compare_exchange_32(&pJob->userCb, SCH_FETCH_CB, 0)) {
|
||||
schNotifyUserFetchRes(pJob);
|
||||
}
|
||||
}
|
||||
|
||||
SCH_RET(code);
|
||||
}
|
||||
|
||||
|
@ -762,6 +837,10 @@ int32_t schProcessOnJobPartialSuccess(SSchJob *pJob) {
|
|||
|
||||
if (pJob->attr.syncSchedule) {
|
||||
tsem_post(&pJob->rspSem);
|
||||
} else if (SCH_EXEC_CB == atomic_val_compare_exchange_32(&pJob->userCb, SCH_EXEC_CB, 0)) {
|
||||
schNotifyUserQueryRes(pJob);
|
||||
} else if (SCH_FETCH_CB == atomic_val_compare_exchange_32(&pJob->userCb, SCH_FETCH_CB, 0)) {
|
||||
schNotifyUserFetchRes(pJob);
|
||||
}
|
||||
|
||||
if (atomic_load_8(&pJob->userFetch)) {
|
||||
|
@ -1218,6 +1297,7 @@ void schFreeJobImpl(void *job) {
|
|||
tFreeSSubmitRsp((SSubmitRsp*)pJob->queryRes);
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(pJob->userRes.queryRes);
|
||||
taosMemoryFreeClear(pJob->resData);
|
||||
taosMemoryFreeClear(pJob);
|
||||
|
||||
|
@ -1228,8 +1308,8 @@ void schFreeJobImpl(void *job) {
|
|||
schCloseJobRef();
|
||||
}
|
||||
|
||||
int32_t schExecJobImpl(void *transport, SArray *pNodeList, SQueryPlan *pDag, int64_t *job, const char *sql,
|
||||
int64_t startTs, bool sync) {
|
||||
int32_t schExecJobImpl(void *pTrans, SArray *pNodeList, SQueryPlan *pDag, int64_t *job, const char *sql,
|
||||
SSchResInfo *pRes, int64_t startTs, bool sync) {
|
||||
qDebug("QID:0x%" PRIx64 " job started", pDag->queryId);
|
||||
|
||||
if (pNodeList == NULL || taosArrayGetSize(pNodeList) <= 0) {
|
||||
|
@ -1238,31 +1318,68 @@ int32_t schExecJobImpl(void *transport, SArray *pNodeList, SQueryPlan *pDag, int
|
|||
|
||||
int32_t code = 0;
|
||||
SSchJob *pJob = NULL;
|
||||
SCH_ERR_JRET(schInitJob(&pJob, pDag, transport, pNodeList, sql, startTs, sync));
|
||||
|
||||
SCH_ERR_JRET(schLaunchJob(pJob));
|
||||
SCH_ERR_RET(schInitJob(&pJob, pDag, pTrans, pNodeList, sql, pRes, startTs, sync));
|
||||
|
||||
*job = pJob->refId;
|
||||
|
||||
SCH_ERR_JRET(schLaunchJob(pJob));
|
||||
|
||||
if (sync) {
|
||||
SCH_JOB_DLOG("will wait for rsp now, job status:%s", SCH_GET_JOB_STATUS_STR(pJob));
|
||||
tsem_wait(&pJob->rspSem);
|
||||
} else {
|
||||
pJob->userCb = SCH_EXEC_CB;
|
||||
}
|
||||
|
||||
SCH_JOB_DLOG("job exec done, job status:%s", SCH_GET_JOB_STATUS_STR(pJob));
|
||||
|
||||
schReleaseJob(pJob->refId);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
_return:
|
||||
|
||||
schFreeJobImpl(pJob);
|
||||
schReleaseJob(pJob->refId);
|
||||
|
||||
SCH_RET(code);
|
||||
}
|
||||
|
||||
int32_t schExecStaticExplain(void *transport, SArray *pNodeList, SQueryPlan *pDag, int64_t *job, const char *sql,
|
||||
bool syncSchedule) {
|
||||
int32_t schExecJob(void *pTrans, SArray *pNodeList, SQueryPlan *pDag, int64_t *pJob, const char *sql,
|
||||
int64_t startTs, SSchResInfo *pRes) {
|
||||
int32_t code = 0;
|
||||
|
||||
*pJob = 0;
|
||||
|
||||
if (EXPLAIN_MODE_STATIC == pDag->explainInfo.mode) {
|
||||
SCH_ERR_JRET(schExecStaticExplainJob(pTrans, pNodeList, pDag, pJob, sql, NULL, true));
|
||||
} else {
|
||||
SCH_ERR_JRET(schExecJobImpl(pTrans, pNodeList, pDag, pJob, sql, NULL, startTs, true));
|
||||
}
|
||||
|
||||
_return:
|
||||
|
||||
if (*pJob) {
|
||||
SSchJob *job = schAcquireJob(*pJob);
|
||||
schSetJobQueryRes(job, pRes->queryRes);
|
||||
schReleaseJob(*pJob);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t schAsyncExecJob(void *pTrans, SArray *pNodeList, SQueryPlan *pDag, int64_t *pJob, const char *sql,
|
||||
int64_t startTs, SSchResInfo *pRes) {
|
||||
int32_t code = 0;
|
||||
|
||||
*pJob = 0;
|
||||
|
||||
if (EXPLAIN_MODE_STATIC == pDag->explainInfo.mode) {
|
||||
SCH_ERR_RET(schExecStaticExplainJob(pTrans, pNodeList, pDag, pJob, sql, pRes, false));
|
||||
} else {
|
||||
SCH_ERR_RET(schExecJobImpl(pTrans, pNodeList, pDag, pJob, sql, pRes, startTs, false));
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t schExecStaticExplainJob(void *pTrans, SArray *pNodeList, SQueryPlan *pDag, int64_t *job, const char *sql,
|
||||
SSchResInfo *pRes, bool sync) {
|
||||
qDebug("QID:0x%" PRIx64 " job started", pDag->queryId);
|
||||
|
||||
int32_t code = 0;
|
||||
|
@ -1274,10 +1391,14 @@ int32_t schExecStaticExplain(void *transport, SArray *pNodeList, SQueryPlan *pDa
|
|||
|
||||
pJob->sql = sql;
|
||||
pJob->attr.queryJob = true;
|
||||
pJob->attr.syncSchedule = sync;
|
||||
pJob->attr.explainMode = pDag->explainInfo.mode;
|
||||
pJob->queryId = pDag->queryId;
|
||||
pJob->subPlans = pDag->pSubplans;
|
||||
|
||||
if (pRes) {
|
||||
pJob->userRes = *pRes;
|
||||
}
|
||||
|
||||
SCH_ERR_JRET(qExecStaticExplain(pDag, (SRetrieveTableRsp **)&pJob->resData));
|
||||
|
||||
int64_t refId = taosAddRef(schMgmt.jobRef, pJob);
|
||||
|
@ -1288,7 +1409,7 @@ int32_t schExecStaticExplain(void *transport, SArray *pNodeList, SQueryPlan *pDa
|
|||
|
||||
if (NULL == schAcquireJob(refId)) {
|
||||
SCH_JOB_ELOG("schAcquireJob job failed, refId:%" PRIx64, refId);
|
||||
SCH_RET(TSDB_CODE_SCH_STATUS_ERROR);
|
||||
SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR);
|
||||
}
|
||||
|
||||
pJob->refId = refId;
|
||||
|
@ -1296,12 +1417,17 @@ int32_t schExecStaticExplain(void *transport, SArray *pNodeList, SQueryPlan *pDa
|
|||
SCH_JOB_DLOG("job refId:%" PRIx64, pJob->refId);
|
||||
|
||||
pJob->status = JOB_TASK_STATUS_PARTIAL_SUCCEED;
|
||||
|
||||
*job = pJob->refId;
|
||||
SCH_JOB_DLOG("job exec done, job status:%s", SCH_GET_JOB_STATUS_STR(pJob));
|
||||
|
||||
if (!pJob->attr.syncSchedule) {
|
||||
code = schNotifyUserQueryRes(pJob);
|
||||
}
|
||||
|
||||
schReleaseJob(pJob->refId);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
SCH_RET(code);
|
||||
|
||||
_return:
|
||||
|
||||
|
@ -1309,4 +1435,103 @@ _return:
|
|||
SCH_RET(code);
|
||||
}
|
||||
|
||||
int32_t schFetchRows(SSchJob *pJob) {
|
||||
int32_t code = 0;
|
||||
|
||||
int8_t status = SCH_GET_JOB_STATUS(pJob);
|
||||
if (status == JOB_TASK_STATUS_DROPPING) {
|
||||
SCH_JOB_ELOG("job is dropping, status:%s", jobTaskStatusStr(status));
|
||||
SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR);
|
||||
}
|
||||
|
||||
if (!SCH_JOB_NEED_FETCH(pJob)) {
|
||||
SCH_JOB_ELOG("no need to fetch data, status:%s", SCH_GET_JOB_STATUS_STR(pJob));
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||
}
|
||||
|
||||
if (atomic_val_compare_exchange_8(&pJob->userFetch, 0, 1) != 0) {
|
||||
SCH_JOB_ELOG("prior fetching not finished, userFetch:%d", atomic_load_8(&pJob->userFetch));
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||
}
|
||||
|
||||
if (JOB_TASK_STATUS_FAILED == status || JOB_TASK_STATUS_DROPPING == status) {
|
||||
SCH_JOB_ELOG("job failed or dropping, status:%s", jobTaskStatusStr(status));
|
||||
SCH_ERR_JRET(atomic_load_32(&pJob->errCode));
|
||||
} else if (status == JOB_TASK_STATUS_SUCCEED) {
|
||||
SCH_JOB_DLOG("job already succeed, status:%s", jobTaskStatusStr(status));
|
||||
goto _return;
|
||||
} else if (status != JOB_TASK_STATUS_PARTIAL_SUCCEED) {
|
||||
SCH_JOB_ELOG("job status error for fetch, status:%s", jobTaskStatusStr(status));
|
||||
SCH_ERR_JRET(TSDB_CODE_SCH_STATUS_ERROR);
|
||||
}
|
||||
|
||||
if (!(pJob->attr.explainMode == EXPLAIN_MODE_STATIC)) {
|
||||
SCH_ERR_JRET(schFetchFromRemote(pJob));
|
||||
tsem_wait(&pJob->rspSem);
|
||||
|
||||
status = SCH_GET_JOB_STATUS(pJob);
|
||||
if (JOB_TASK_STATUS_FAILED == status || JOB_TASK_STATUS_DROPPING == status) {
|
||||
SCH_JOB_ELOG("job failed or dropping, status:%s", jobTaskStatusStr(status));
|
||||
SCH_ERR_JRET(atomic_load_32(&pJob->errCode));
|
||||
}
|
||||
}
|
||||
|
||||
SCH_ERR_JRET(schSetJobFetchRes(pJob, pJob->userRes.fetchRes));
|
||||
|
||||
_return:
|
||||
|
||||
atomic_val_compare_exchange_8(&pJob->userFetch, 1, 0);
|
||||
|
||||
SCH_RET(code);
|
||||
}
|
||||
|
||||
int32_t schAsyncFetchRows(SSchJob *pJob) {
|
||||
int32_t code = 0;
|
||||
|
||||
int8_t status = SCH_GET_JOB_STATUS(pJob);
|
||||
if (status == JOB_TASK_STATUS_DROPPING) {
|
||||
SCH_JOB_ELOG("job is dropping, status:%s", jobTaskStatusStr(status));
|
||||
SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR);
|
||||
}
|
||||
|
||||
if (!SCH_JOB_NEED_FETCH(pJob)) {
|
||||
SCH_JOB_ELOG("no need to fetch data, status:%s", SCH_GET_JOB_STATUS_STR(pJob));
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||
}
|
||||
|
||||
if (atomic_val_compare_exchange_8(&pJob->userFetch, 0, 1) != 0) {
|
||||
SCH_JOB_ELOG("prior fetching not finished, userFetch:%d", atomic_load_8(&pJob->userFetch));
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||
}
|
||||
|
||||
if (JOB_TASK_STATUS_FAILED == status || JOB_TASK_STATUS_DROPPING == status) {
|
||||
SCH_JOB_ELOG("job failed or dropping, status:%s", jobTaskStatusStr(status));
|
||||
SCH_ERR_JRET(atomic_load_32(&pJob->errCode));
|
||||
} else if (status == JOB_TASK_STATUS_SUCCEED) {
|
||||
SCH_JOB_DLOG("job already succeed, status:%s", jobTaskStatusStr(status));
|
||||
goto _return;
|
||||
} else if (status != JOB_TASK_STATUS_PARTIAL_SUCCEED) {
|
||||
SCH_JOB_ELOG("job status error for fetch, status:%s", jobTaskStatusStr(status));
|
||||
SCH_ERR_JRET(TSDB_CODE_SCH_STATUS_ERROR);
|
||||
}
|
||||
|
||||
if (pJob->attr.explainMode == EXPLAIN_MODE_STATIC) {
|
||||
SCH_ERR_JRET(schNotifyUserFetchRes(pJob));
|
||||
|
||||
atomic_val_compare_exchange_8(&pJob->userFetch, 1, 0);
|
||||
} else {
|
||||
pJob->userCb = SCH_FETCH_CB;
|
||||
|
||||
SCH_ERR_JRET(schFetchFromRemote(pJob));
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
_return:
|
||||
|
||||
atomic_val_compare_exchange_8(&pJob->userFetch, 1, 0);
|
||||
|
||||
SCH_RET(code);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -396,6 +396,7 @@ int32_t schHandleCallback(void *param, const SDataBuf *pMsg, int32_t msgType, in
|
|||
SCH_ERR_JRET(schHandleResponseMsg(pJob, pTask, msgType, pMsg->pData, pMsg->len, rspCode));
|
||||
|
||||
_return:
|
||||
|
||||
if (pJob) {
|
||||
schReleaseJob(pParam->refId);
|
||||
}
|
||||
|
@ -450,7 +451,7 @@ int32_t schHandleLinkBrokenCallback(void *param, const SDataBuf *pMsg, int32_t c
|
|||
|
||||
if (head->isHbParam) {
|
||||
SSchHbCallbackParam *hbParam = (SSchHbCallbackParam *)param;
|
||||
SSchTrans trans = {.transInst = hbParam->transport, .transHandle = NULL};
|
||||
SSchTrans trans = {.pTrans = hbParam->pTrans, .pHandle = NULL};
|
||||
SCH_ERR_RET(schUpdateHbConnection(&hbParam->nodeEpId, &trans));
|
||||
|
||||
SCH_ERR_RET(schBuildAndSendHbMsg(&hbParam->nodeEpId));
|
||||
|
@ -481,7 +482,7 @@ int32_t schGenerateCallBackInfo(SSchJob *pJob, SSchTask *pTask, int32_t msgType,
|
|||
param->queryId = pJob->queryId;
|
||||
param->refId = pJob->refId;
|
||||
param->taskId = SCH_TASK_ID(pTask);
|
||||
param->transport = pJob->transport;
|
||||
param->transport = pJob->pTrans;
|
||||
|
||||
msgSendInfo->param = param;
|
||||
msgSendInfo->fp = fp;
|
||||
|
@ -556,7 +557,7 @@ int32_t schMakeHbCallbackParam(SSchJob *pJob, SSchTask *pTask, void **pParam) {
|
|||
|
||||
param->nodeEpId.nodeId = addr->nodeId;
|
||||
memcpy(¶m->nodeEpId.ep, SCH_GET_CUR_EP(addr), sizeof(SEp));
|
||||
param->transport = pJob->transport;
|
||||
param->pTrans = pJob->pTrans;
|
||||
|
||||
*pParam = param;
|
||||
|
||||
|
@ -565,8 +566,9 @@ int32_t schMakeHbCallbackParam(SSchJob *pJob, SSchTask *pTask, void **pParam) {
|
|||
|
||||
int32_t schCloneHbRpcCtx(SRpcCtx *pSrc, SRpcCtx *pDst) {
|
||||
int32_t code = 0;
|
||||
memcpy(&pDst->brokenVal, &pSrc->brokenVal, sizeof(pSrc->brokenVal));
|
||||
memcpy(pDst, pSrc, sizeof(SRpcCtx));
|
||||
pDst->brokenVal.val = NULL;
|
||||
pDst->args = NULL;
|
||||
|
||||
SCH_ERR_RET(schCloneSMsgSendInfo(pSrc->brokenVal.val, &pDst->brokenVal.val));
|
||||
|
||||
|
@ -589,7 +591,7 @@ int32_t schCloneHbRpcCtx(SRpcCtx *pSrc, SRpcCtx *pDst) {
|
|||
|
||||
if (taosHashPut(pDst->args, msgType, sizeof(*msgType), &dst, sizeof(dst))) {
|
||||
qError("taosHashPut msg %d to rpcCtx failed", *msgType);
|
||||
(*dst.freeFunc)(dst.val);
|
||||
(*pSrc->freeFunc)(dst.val);
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
|
@ -638,18 +640,19 @@ int32_t schMakeHbRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx) {
|
|||
SCH_ERR_JRET(schGetCallbackFp(TDMT_VND_QUERY_HEARTBEAT, &fp));
|
||||
|
||||
param->nodeEpId = epId;
|
||||
param->transport = pJob->transport;
|
||||
param->pTrans = pJob->pTrans;
|
||||
|
||||
pMsgSendInfo->param = param;
|
||||
pMsgSendInfo->fp = fp;
|
||||
|
||||
SRpcCtxVal ctxVal = {.val = pMsgSendInfo, .clone = schCloneSMsgSendInfo, .freeFunc = schFreeRpcCtxVal};
|
||||
SRpcCtxVal ctxVal = {.val = pMsgSendInfo, .clone = schCloneSMsgSendInfo};
|
||||
if (taosHashPut(pCtx->args, &msgType, sizeof(msgType), &ctxVal, sizeof(ctxVal))) {
|
||||
SCH_TASK_ELOG("taosHashPut msg %d to rpcCtx failed", msgType);
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SCH_ERR_JRET(schMakeBrokenLinkVal(pJob, pTask, &pCtx->brokenVal, true));
|
||||
pCtx->freeFunc = schFreeRpcCtxVal;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -666,7 +669,7 @@ int32_t schRegisterHbConnection(SSchJob *pJob, SSchTask *pTask, SQueryNodeEpId *
|
|||
int32_t code = 0;
|
||||
SSchHbTrans hb = {0};
|
||||
|
||||
hb.trans.transInst = pJob->transport;
|
||||
hb.trans.pTrans = pJob->pTrans;
|
||||
|
||||
SCH_ERR_RET(schMakeHbRpcCtx(pJob, pTask, &hb.rpcCtx));
|
||||
|
||||
|
@ -743,12 +746,12 @@ int32_t schBuildAndSendHbMsg(SQueryNodeEpId *nodeEpId) {
|
|||
__async_send_cb_fn_t fp = NULL;
|
||||
SCH_ERR_JRET(schGetCallbackFp(msgType, &fp));
|
||||
|
||||
param->transport = trans.transInst;
|
||||
param->transport = trans.pTrans;
|
||||
|
||||
pMsgSendInfo->param = param;
|
||||
pMsgSendInfo->msgInfo.pData = msg;
|
||||
pMsgSendInfo->msgInfo.len = msgSize;
|
||||
pMsgSendInfo->msgInfo.handle = trans.transHandle;
|
||||
pMsgSendInfo->msgInfo.handle = trans.pHandle;
|
||||
pMsgSendInfo->msgType = msgType;
|
||||
pMsgSendInfo->fp = fp;
|
||||
|
||||
|
@ -756,13 +759,13 @@ int32_t schBuildAndSendHbMsg(SQueryNodeEpId *nodeEpId) {
|
|||
SEpSet epSet = {.inUse = 0, .numOfEps = 1};
|
||||
memcpy(&epSet.eps[0], &nodeEpId->ep, sizeof(nodeEpId->ep));
|
||||
|
||||
qDebug("start to send hb msg, instance:%p, handle:%p, fqdn:%s, port:%d", trans.transInst, trans.transHandle,
|
||||
qDebug("start to send hb msg, pTrans:%p, pHandle:%p, fqdn:%s, port:%d", trans.pTrans, trans.pHandle,
|
||||
nodeEpId->ep.fqdn, nodeEpId->ep.port);
|
||||
|
||||
code = asyncSendMsgToServerExt(trans.transInst, &epSet, &transporterId, pMsgSendInfo, true, &rpcCtx);
|
||||
code = asyncSendMsgToServerExt(trans.pTrans, &epSet, &transporterId, pMsgSendInfo, true, &rpcCtx);
|
||||
if (code) {
|
||||
qError("fail to send hb msg, instance:%p, handle:%p, fqdn:%s, port:%d, error:%x - %s", trans.transInst,
|
||||
trans.transHandle, nodeEpId->ep.fqdn, nodeEpId->ep.port, code, tstrerror(code));
|
||||
qError("fail to send hb msg, pTrans:%p, pHandle:%p, fqdn:%s, port:%d, error:%x - %s", trans.pTrans,
|
||||
trans.pHandle, nodeEpId->ep.fqdn, nodeEpId->ep.port, code, tstrerror(code));
|
||||
SCH_ERR_JRET(code);
|
||||
}
|
||||
|
||||
|
@ -812,8 +815,8 @@ int32_t schUpdateHbConnection(SQueryNodeEpId *epId, SSchTrans *trans) {
|
|||
memcpy(&hb->trans, trans, sizeof(*trans));
|
||||
SCH_UNLOCK(SCH_WRITE, &hb->lock);
|
||||
|
||||
qDebug("hb connection updated, sId:%" PRIx64 ", nodeId:%d, fqdn:%s, port:%d, instance:%p, handle:%p", schMgmt.sId,
|
||||
epId->nodeId, epId->ep.fqdn, epId->ep.port, trans->transInst, trans->transHandle);
|
||||
qDebug("hb connection updated, sId:%" PRIx64 ", nodeId:%d, fqdn:%s, port:%d, pTrans:%p, pHandle:%p", schMgmt.sId,
|
||||
epId->nodeId, epId->ep.fqdn, epId->ep.port, trans->pTrans, trans->pHandle);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -833,8 +836,8 @@ int32_t schHandleHbCallback(void *param, const SDataBuf *pMsg, int32_t code) {
|
|||
}
|
||||
|
||||
SSchTrans trans = {0};
|
||||
trans.transInst = pParam->transport;
|
||||
trans.transHandle = pMsg->handle;
|
||||
trans.pTrans = pParam->transport;
|
||||
trans.pHandle = pMsg->handle;
|
||||
|
||||
SCH_ERR_JRET(schUpdateHbConnection(&rsp.epId, &trans));
|
||||
|
||||
|
@ -879,7 +882,7 @@ int32_t schMakeCallbackParam(SSchJob *pJob, SSchTask *pTask, void **pParam) {
|
|||
param->queryId = pJob->queryId;
|
||||
param->refId = pJob->refId;
|
||||
param->taskId = SCH_TASK_ID(pTask);
|
||||
param->transport = pJob->transport;
|
||||
param->transport = pJob->pTrans;
|
||||
|
||||
*pParam = param;
|
||||
|
||||
|
@ -911,7 +914,6 @@ int32_t schMakeBrokenLinkVal(SSchJob *pJob, SSchTask *pTask, SRpcBrokenlinkVal *
|
|||
brokenVal->msgType = msgType;
|
||||
brokenVal->val = pMsgSendInfo;
|
||||
brokenVal->clone = schCloneSMsgSendInfo;
|
||||
brokenVal->freeFunc = schFreeRpcCtxVal;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -938,7 +940,7 @@ int32_t schMakeQueryRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx) {
|
|||
SCH_ERR_JRET(schGenerateCallBackInfo(pJob, pTask, TDMT_VND_EXPLAIN, &pExplainMsgSendInfo));
|
||||
|
||||
int32_t msgType = TDMT_VND_RES_READY_RSP;
|
||||
SRpcCtxVal ctxVal = {.val = pReadyMsgSendInfo, .clone = schCloneSMsgSendInfo, .freeFunc = schFreeRpcCtxVal};
|
||||
SRpcCtxVal ctxVal = {.val = pReadyMsgSendInfo, .clone = schCloneSMsgSendInfo};
|
||||
if (taosHashPut(pCtx->args, &msgType, sizeof(msgType), &ctxVal, sizeof(ctxVal))) {
|
||||
SCH_TASK_ELOG("taosHashPut msg %d to rpcCtx failed", msgType);
|
||||
SCH_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
|
@ -952,6 +954,7 @@ int32_t schMakeQueryRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx) {
|
|||
}
|
||||
|
||||
SCH_ERR_JRET(schMakeBrokenLinkVal(pJob, pTask, &pCtx->brokenVal, false));
|
||||
pCtx->freeFunc = schFreeRpcCtxVal;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -1034,15 +1037,15 @@ int32_t schAsyncSendMsg(SSchJob *pJob, SSchTask *pTask, void *transport, SEpSet
|
|||
|
||||
pMsgSendInfo->msgInfo.pData = msg;
|
||||
pMsgSendInfo->msgInfo.len = msgSize;
|
||||
pMsgSendInfo->msgInfo.handle = trans->transHandle;
|
||||
pMsgSendInfo->msgInfo.handle = trans->pHandle;
|
||||
pMsgSendInfo->msgType = msgType;
|
||||
|
||||
qDebug("start to send %s msg to node[%d,%s,%d], refId:%" PRIx64 "instance:%p, handle:%p", TMSG_INFO(msgType),
|
||||
qDebug("start to send %s msg to node[%d,%s,%d], refId:%" PRIx64 "pTrans:%p, pHandle:%p", TMSG_INFO(msgType),
|
||||
ntohl(((SMsgHead *)msg)->vgId), epSet->eps[epSet->inUse].fqdn, epSet->eps[epSet->inUse].port, pJob->refId,
|
||||
trans->transInst, trans->transHandle);
|
||||
trans->pTrans, trans->pHandle);
|
||||
|
||||
int64_t transporterId = 0;
|
||||
code = asyncSendMsgToServerExt(trans->transInst, epSet, &transporterId, pMsgSendInfo, persistHandle, ctx);
|
||||
code = asyncSendMsgToServerExt(trans->pTrans, epSet, &transporterId, pMsgSendInfo, persistHandle, ctx);
|
||||
if (code) {
|
||||
SCH_ERR_JRET(code);
|
||||
}
|
||||
|
@ -1208,12 +1211,12 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr,
|
|||
|
||||
SCH_SET_TASK_LASTMSG_TYPE(pTask, msgType);
|
||||
|
||||
SSchTrans trans = {.transInst = pJob->transport, .transHandle = SCH_GET_TASK_HANDLE(pTask)};
|
||||
SSchTrans trans = {.pTrans = pJob->pTrans, .pHandle = SCH_GET_TASK_HANDLE(pTask)};
|
||||
SCH_ERR_JRET(schAsyncSendMsg(pJob, pTask, &trans, &epSet, msgType, msg, msgSize, persistHandle,
|
||||
(rpcCtx.args ? &rpcCtx : NULL)));
|
||||
|
||||
if (msgType == TDMT_VND_QUERY) {
|
||||
SCH_ERR_RET(schRecordTaskExecNode(pJob, pTask, addr, trans.transHandle));
|
||||
SCH_ERR_RET(schRecordTaskExecNode(pJob, pTask, addr, trans.pHandle));
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
|
|
@ -77,16 +77,14 @@ void schFreeRpcCtx(SRpcCtx *pCtx) {
|
|||
while (pIter) {
|
||||
SRpcCtxVal *ctxVal = (SRpcCtxVal *)pIter;
|
||||
|
||||
(*ctxVal->freeFunc)(ctxVal->val);
|
||||
(*pCtx->freeFunc)(ctxVal->val);
|
||||
|
||||
pIter = taosHashIterate(pCtx->args, pIter);
|
||||
}
|
||||
|
||||
taosHashCleanup(pCtx->args);
|
||||
|
||||
if (pCtx->brokenVal.freeFunc) {
|
||||
(*pCtx->brokenVal.freeFunc)(pCtx->brokenVal.val);
|
||||
}
|
||||
(*pCtx->freeFunc)(pCtx->brokenVal.val);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -67,50 +67,24 @@ int32_t schedulerInit(SSchedulerCfg *cfg) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t schedulerExecJob(void *transport, SArray *nodeList, SQueryPlan *pDag, int64_t *pJob, const char *sql,
|
||||
int32_t schedulerExecJob(void *pTrans, SArray *pNodeList, SQueryPlan *pDag, int64_t *pJob, const char *sql,
|
||||
int64_t startTs, SQueryResult *pRes) {
|
||||
if (NULL == transport || NULL == pDag || NULL == pDag->pSubplans || NULL == pJob || NULL == pRes) {
|
||||
if (NULL == pTrans || NULL == pDag || NULL == pDag->pSubplans || NULL == pJob || NULL == pRes) {
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
|
||||
*pJob = 0;
|
||||
|
||||
if (EXPLAIN_MODE_STATIC == pDag->explainInfo.mode) {
|
||||
SCH_ERR_RET(schExecStaticExplain(transport, nodeList, pDag, pJob, sql, true));
|
||||
} else {
|
||||
SCH_ERR_JRET(schExecJobImpl(transport, nodeList, pDag, pJob, sql, startTs, true));
|
||||
}
|
||||
|
||||
_return:
|
||||
|
||||
if (*pJob) {
|
||||
SSchJob *job = schAcquireJob(*pJob);
|
||||
|
||||
pRes->code = atomic_load_32(&job->errCode);
|
||||
pRes->numOfRows = job->resNumOfRows;
|
||||
pRes->res = job->queryRes;
|
||||
job->queryRes = NULL;
|
||||
|
||||
schReleaseJob(*pJob);
|
||||
}
|
||||
|
||||
return code;
|
||||
SSchResInfo resInfo = {.queryRes = pRes};
|
||||
SCH_RET(schExecJob(pTrans, pNodeList, pDag, pJob, sql, startTs, &resInfo));
|
||||
}
|
||||
|
||||
int32_t schedulerAsyncExecJob(void *transport, SArray *pNodeList, SQueryPlan *pDag, const char *sql, int64_t *pJob) {
|
||||
if (NULL == transport || NULL == pDag || NULL == pDag->pSubplans || NULL == pJob) {
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
|
||||
if (EXPLAIN_MODE_STATIC == pDag->explainInfo.mode) {
|
||||
SCH_ERR_RET(schExecStaticExplain(transport, pNodeList, pDag, pJob, sql, false));
|
||||
} else {
|
||||
SCH_ERR_RET(schExecJobImpl(transport, pNodeList, pDag, pJob, sql, 0, false));
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
int32_t schedulerAsyncExecJob(void *pTrans, SArray *pNodeList, SQueryPlan *pDag, int64_t *pJob, const char *sql,
|
||||
int64_t startTs, schedulerExecCallback fp, void* param) {
|
||||
if (NULL == pTrans || NULL == pDag || NULL == pDag->pSubplans || NULL == pJob || NULL == fp || NULL == param) {
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
|
||||
SSchResInfo resInfo = {.execFp = fp, .userParam = param};
|
||||
SCH_RET(schAsyncExecJob(pTrans, pNodeList, pDag, pJob, sql, startTs, &resInfo));
|
||||
}
|
||||
|
||||
int32_t schedulerFetchRows(int64_t job, void **pData) {
|
||||
|
@ -125,76 +99,32 @@ int32_t schedulerFetchRows(int64_t job, void **pData) {
|
|||
SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR);
|
||||
}
|
||||
|
||||
int8_t status = SCH_GET_JOB_STATUS(pJob);
|
||||
if (status == JOB_TASK_STATUS_DROPPING) {
|
||||
SCH_JOB_ELOG("job is dropping, status:%s", jobTaskStatusStr(status));
|
||||
schReleaseJob(job);
|
||||
pJob->attr.syncSchedule = true;
|
||||
pJob->userRes.fetchRes = pData;
|
||||
code = schFetchRows(pJob);
|
||||
|
||||
schReleaseJob(job);
|
||||
|
||||
SCH_RET(code);
|
||||
}
|
||||
|
||||
int32_t schedulerAsyncFetchRows(int64_t job, schedulerFetchCallback fp, void* param) {
|
||||
if (NULL == fp || NULL == param) {
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
|
||||
int32_t code = 0;
|
||||
SSchJob *pJob = schAcquireJob(job);
|
||||
if (NULL == pJob) {
|
||||
qError("acquire job from jobRef list failed, may be dropped, refId:%" PRIx64, job);
|
||||
SCH_ERR_RET(TSDB_CODE_SCH_STATUS_ERROR);
|
||||
}
|
||||
|
||||
if (!SCH_JOB_NEED_FETCH(pJob)) {
|
||||
SCH_JOB_ELOG("no need to fetch data, status:%s", SCH_GET_JOB_STATUS_STR(pJob));
|
||||
schReleaseJob(job);
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||
}
|
||||
|
||||
if (atomic_val_compare_exchange_8(&pJob->userFetch, 0, 1) != 0) {
|
||||
SCH_JOB_ELOG("prior fetching not finished, userFetch:%d", atomic_load_8(&pJob->userFetch));
|
||||
schReleaseJob(job);
|
||||
SCH_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||
}
|
||||
|
||||
if (JOB_TASK_STATUS_FAILED == status || JOB_TASK_STATUS_DROPPING == status) {
|
||||
SCH_JOB_ELOG("job failed or dropping, status:%s", jobTaskStatusStr(status));
|
||||
SCH_ERR_JRET(atomic_load_32(&pJob->errCode));
|
||||
} else if (status == JOB_TASK_STATUS_SUCCEED) {
|
||||
SCH_JOB_DLOG("job already succeed, status:%s", jobTaskStatusStr(status));
|
||||
goto _return;
|
||||
} else if (status == JOB_TASK_STATUS_PARTIAL_SUCCEED) {
|
||||
if (!(pJob->attr.explainMode == EXPLAIN_MODE_STATIC)) {
|
||||
SCH_ERR_JRET(schFetchFromRemote(pJob));
|
||||
tsem_wait(&pJob->rspSem);
|
||||
}
|
||||
} else {
|
||||
SCH_JOB_ELOG("job status error for fetch, status:%s", jobTaskStatusStr(status));
|
||||
SCH_ERR_JRET(TSDB_CODE_SCH_STATUS_ERROR);
|
||||
}
|
||||
|
||||
status = SCH_GET_JOB_STATUS(pJob);
|
||||
|
||||
if (JOB_TASK_STATUS_FAILED == status || JOB_TASK_STATUS_DROPPING == status) {
|
||||
SCH_JOB_ELOG("job failed or dropping, status:%s", jobTaskStatusStr(status));
|
||||
SCH_ERR_JRET(atomic_load_32(&pJob->errCode));
|
||||
}
|
||||
|
||||
if (pJob->resData && ((SRetrieveTableRsp *)pJob->resData)->completed) {
|
||||
SCH_ERR_JRET(schChkUpdateJobStatus(pJob, JOB_TASK_STATUS_SUCCEED));
|
||||
}
|
||||
|
||||
while (true) {
|
||||
*pData = atomic_load_ptr(&pJob->resData);
|
||||
if (*pData != atomic_val_compare_exchange_ptr(&pJob->resData, *pData, NULL)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (NULL == *pData) {
|
||||
SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, sizeof(SRetrieveTableRsp));
|
||||
if (rsp) {
|
||||
rsp->completed = 1;
|
||||
}
|
||||
|
||||
*pData = rsp;
|
||||
SCH_JOB_DLOG("empty res and set query complete, code:%x", code);
|
||||
}
|
||||
|
||||
SCH_JOB_DLOG("fetch done, totalRows:%d, code:%s", pJob->resNumOfRows, tstrerror(code));
|
||||
|
||||
_return:
|
||||
|
||||
atomic_val_compare_exchange_8(&pJob->userFetch, 1, 0);
|
||||
pJob->attr.syncSchedule = false;
|
||||
pJob->userRes.fetchFp = fp;
|
||||
pJob->userRes.userParam = param;
|
||||
|
||||
code = schFetchRows(pJob);
|
||||
|
||||
schReleaseJob(job);
|
||||
|
||||
|
|
|
@ -87,6 +87,11 @@ void schtInitLogFile() {
|
|||
|
||||
}
|
||||
|
||||
void schtQueryCb(SQueryResult* pResult, void* param, int32_t code) {
|
||||
assert(TSDB_CODE_SUCCESS == code);
|
||||
*(int32_t*)param = 1;
|
||||
}
|
||||
|
||||
|
||||
void schtBuildQueryDag(SQueryPlan *dag) {
|
||||
uint64_t qId = schtQueryId;
|
||||
|
@ -485,6 +490,7 @@ void* schtRunJobThread(void *aa) {
|
|||
SHashObj *execTasks = NULL;
|
||||
SDataBuf dataBuf = {0};
|
||||
uint32_t jobFinished = 0;
|
||||
int32_t queryDone = 0;
|
||||
|
||||
while (!schtTestStop) {
|
||||
schtBuildQueryDag(&dag);
|
||||
|
@ -496,7 +502,8 @@ void* schtRunJobThread(void *aa) {
|
|||
qnodeAddr.port = 6031;
|
||||
taosArrayPush(qnodeList, &qnodeAddr);
|
||||
|
||||
code = schedulerAsyncExecJob(mockPointer, qnodeList, &dag, "select * from tb", &queryJobRefId);
|
||||
queryDone = 0;
|
||||
code = schedulerAsyncExecJob(mockPointer, qnodeList, &dag, &queryJobRefId, "select * from tb", 0, schtQueryCb, &queryDone);
|
||||
assert(code == 0);
|
||||
|
||||
pJob = schAcquireJob(queryJobRefId);
|
||||
|
@ -595,6 +602,14 @@ void* schtRunJobThread(void *aa) {
|
|||
pIter = taosHashIterate(execTasks, pIter);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (queryDone) {
|
||||
break;
|
||||
}
|
||||
|
||||
taosUsleep(10000);
|
||||
}
|
||||
|
||||
atomic_store_32(&schtStartFetch, 1);
|
||||
|
||||
void *data = NULL;
|
||||
|
@ -667,8 +682,9 @@ TEST(queryTest, normalCase) {
|
|||
schtSetPlanToString();
|
||||
schtSetExecNode();
|
||||
schtSetAsyncSendMsgToServer();
|
||||
|
||||
code = schedulerAsyncExecJob(mockPointer, qnodeList, &dag, "select * from tb", &job);
|
||||
|
||||
int32_t queryDone = 0;
|
||||
code = schedulerAsyncExecJob(mockPointer, qnodeList, &dag, &job, "select * from tb", 0, schtQueryCb, &queryDone);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
|
||||
|
@ -718,6 +734,14 @@ TEST(queryTest, normalCase) {
|
|||
pIter = taosHashIterate(pJob->execTasks, pIter);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (queryDone) {
|
||||
break;
|
||||
}
|
||||
|
||||
taosUsleep(10000);
|
||||
}
|
||||
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
|
||||
|
@ -773,8 +797,9 @@ TEST(queryTest, readyFirstCase) {
|
|||
schtSetPlanToString();
|
||||
schtSetExecNode();
|
||||
schtSetAsyncSendMsgToServer();
|
||||
|
||||
code = schedulerAsyncExecJob(mockPointer, qnodeList, &dag, "select * from tb", &job);
|
||||
|
||||
int32_t queryDone = 0;
|
||||
code = schedulerAsyncExecJob(mockPointer, qnodeList, &dag, &job, "select * from tb", 0, schtQueryCb, &queryDone);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
|
||||
|
@ -824,6 +849,13 @@ TEST(queryTest, readyFirstCase) {
|
|||
pIter = taosHashIterate(pJob->execTasks, pIter);
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (queryDone) {
|
||||
break;
|
||||
}
|
||||
|
||||
taosUsleep(10000);
|
||||
}
|
||||
|
||||
|
||||
TdThreadAttr thattr;
|
||||
|
@ -885,16 +917,17 @@ TEST(queryTest, flowCtrlCase) {
|
|||
schtSetPlanToString();
|
||||
schtSetExecNode();
|
||||
schtSetAsyncSendMsgToServer();
|
||||
|
||||
code = schedulerAsyncExecJob(mockPointer, qnodeList, &dag, "select * from tb", &job);
|
||||
|
||||
int32_t queryDone = 0;
|
||||
code = schedulerAsyncExecJob(mockPointer, qnodeList, &dag, &job, "select * from tb", 0, schtQueryCb, &queryDone);
|
||||
ASSERT_EQ(code, 0);
|
||||
|
||||
|
||||
SSchJob *pJob = schAcquireJob(job);
|
||||
|
||||
bool queryDone = false;
|
||||
bool qDone = false;
|
||||
|
||||
while (!queryDone) {
|
||||
while (!qDone) {
|
||||
void *pIter = taosHashIterate(pJob->execTasks, NULL);
|
||||
if (NULL == pIter) {
|
||||
break;
|
||||
|
@ -915,7 +948,7 @@ TEST(queryTest, flowCtrlCase) {
|
|||
code = schHandleResponseMsg(pJob, task, TDMT_VND_RES_READY_RSP, (char *)&rsp, sizeof(rsp), 0);
|
||||
ASSERT_EQ(code, 0);
|
||||
} else {
|
||||
queryDone = true;
|
||||
qDone = true;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -923,6 +956,13 @@ TEST(queryTest, flowCtrlCase) {
|
|||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (queryDone) {
|
||||
break;
|
||||
}
|
||||
|
||||
taosUsleep(10000);
|
||||
}
|
||||
|
||||
TdThreadAttr thattr;
|
||||
taosThreadAttrInit(&thattr);
|
||||
|
|
|
@ -158,7 +158,9 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes)
|
|||
ASSERT(false);
|
||||
}
|
||||
if (output == NULL) break;
|
||||
taosArrayPush(pRes, output);
|
||||
// TODO: do we need free memory?
|
||||
SSDataBlock* outputCopy = createOneDataBlock(output, true);
|
||||
taosArrayPush(pRes, outputCopy);
|
||||
}
|
||||
|
||||
// destroy
|
||||
|
@ -166,6 +168,7 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes)
|
|||
streamDataSubmitRefDec((SStreamDataSubmit*)data);
|
||||
} else {
|
||||
taosArrayDestroyEx(((SStreamDataBlock*)data)->blocks, (FDelete)tDeleteSSDataBlock);
|
||||
taosFreeQitem(data);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -186,7 +189,7 @@ int32_t streamExec(SStreamTask* pTask, SMsgCb* pMsgCb) {
|
|||
|
||||
streamTaskExecImpl(pTask, data, pRes);
|
||||
|
||||
taosFreeQitem(data);
|
||||
/*taosFreeQitem(data);*/
|
||||
|
||||
if (taosArrayGetSize(pRes) != 0) {
|
||||
SStreamDataBlock* resQ = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM);
|
||||
|
@ -206,7 +209,7 @@ int32_t streamExec(SStreamTask* pTask, SMsgCb* pMsgCb) {
|
|||
|
||||
streamTaskExecImpl(pTask, data, pRes);
|
||||
|
||||
taosFreeQitem(data);
|
||||
/*taosFreeQitem(data);*/
|
||||
|
||||
if (taosArrayGetSize(pRes) != 0) {
|
||||
SStreamDataBlock* resQ = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM);
|
||||
|
@ -228,7 +231,7 @@ int32_t streamExec(SStreamTask* pTask, SMsgCb* pMsgCb) {
|
|||
|
||||
streamTaskExecImpl(pTask, data, pRes);
|
||||
|
||||
taosFreeQitem(data);
|
||||
/*taosFreeQitem(data);*/
|
||||
|
||||
if (taosArrayGetSize(pRes) != 0) {
|
||||
SStreamDataBlock* resQ = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM);
|
||||
|
|
|
@ -95,8 +95,8 @@ typedef void* queue[2];
|
|||
#define QUEUE_DATA(e, type, field) ((type*)((void*)((char*)(e)-offsetof(type, field))))
|
||||
|
||||
#define TRANS_RETRY_COUNT_LIMIT 100 // retry count limit
|
||||
#define TRANS_RETRY_INTERVAL 15 // ms retry interval
|
||||
#define TRANS_CONN_TIMEOUT 3 // connect timeout
|
||||
#define TRANS_RETRY_INTERVAL 15 // ms retry interval
|
||||
#define TRANS_CONN_TIMEOUT 3 // connect timeout
|
||||
|
||||
typedef SRpcMsg STransMsg;
|
||||
typedef SRpcCtx STransCtx;
|
||||
|
|
|
@ -131,6 +131,19 @@ static void destroyThrdObj(SCliThrdObj* pThrd);
|
|||
|
||||
static void cliWalkCb(uv_handle_t* handle, void* arg);
|
||||
|
||||
static void cliReleaseUnfinishedMsg(SCliConn* conn) {
|
||||
SCliMsg* pMsg = NULL;
|
||||
for (int i = 0; i < transQueueSize(&conn->cliMsgs); i++) {
|
||||
pMsg = transQueueGet(&conn->cliMsgs, i);
|
||||
if (pMsg != NULL && pMsg->ctx != NULL) {
|
||||
if (conn->ctx.freeFunc != NULL) {
|
||||
conn->ctx.freeFunc(pMsg->ctx->ahandle);
|
||||
}
|
||||
}
|
||||
destroyCmsg(pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
#define CLI_RELEASE_UV(loop) \
|
||||
do { \
|
||||
uv_walk(loop, cliWalkCb, NULL); \
|
||||
|
@ -161,6 +174,7 @@ static void cliWalkCb(uv_handle_t* handle, void* arg);
|
|||
transUnrefCliHandle(conn); \
|
||||
} \
|
||||
destroyCmsg(pMsg); \
|
||||
cliReleaseUnfinishedMsg(conn); \
|
||||
addConnToPool(((SCliThrdObj*)conn->hostThrd)->pool, conn); \
|
||||
return; \
|
||||
} \
|
||||
|
@ -465,8 +479,8 @@ static void addConnToPool(void* pool, SCliConn* conn) {
|
|||
|
||||
STrans* pTransInst = ((SCliThrdObj*)conn->hostThrd)->pTransInst;
|
||||
conn->expireTime = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime);
|
||||
transCtxCleanup(&conn->ctx);
|
||||
transQueueClear(&conn->cliMsgs);
|
||||
transCtxCleanup(&conn->ctx);
|
||||
conn->status = ConnInPool;
|
||||
|
||||
char key[128] = {0};
|
||||
|
|
|
@ -233,7 +233,7 @@ void transCtxCleanup(STransCtx* ctx) {
|
|||
|
||||
STransCtxVal* iter = taosHashIterate(ctx->args, NULL);
|
||||
while (iter) {
|
||||
iter->freeFunc(iter->val);
|
||||
ctx->freeFunc(iter->val);
|
||||
iter = taosHashIterate(ctx->args, iter);
|
||||
}
|
||||
|
||||
|
@ -245,6 +245,7 @@ void transCtxMerge(STransCtx* dst, STransCtx* src) {
|
|||
if (dst->args == NULL) {
|
||||
dst->args = src->args;
|
||||
dst->brokenVal = src->brokenVal;
|
||||
dst->freeFunc = src->freeFunc;
|
||||
src->args = NULL;
|
||||
return;
|
||||
}
|
||||
|
@ -257,7 +258,7 @@ void transCtxMerge(STransCtx* dst, STransCtx* src) {
|
|||
|
||||
STransCtxVal* dVal = taosHashGet(dst->args, key, klen);
|
||||
if (dVal) {
|
||||
dVal->freeFunc(dVal->val);
|
||||
dst->freeFunc(dVal->val);
|
||||
}
|
||||
taosHashPut(dst->args, key, klen, sVal, sizeof(*sVal));
|
||||
iter = taosHashIterate(src->args, iter);
|
||||
|
|
|
@ -156,80 +156,80 @@ int32_t cloneVal(void *src, void **dst) {
|
|||
memcpy(*dst, src, sz);
|
||||
return 0;
|
||||
}
|
||||
TEST_F(TransCtxEnv, mergeTest) {
|
||||
int key = 1;
|
||||
{
|
||||
STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
|
||||
transCtxInit(src);
|
||||
{
|
||||
STransCtxVal val1 = {NULL, NULL, (void (*)(const void *))taosMemoryFree};
|
||||
val1.val = taosMemoryMalloc(12);
|
||||
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
}
|
||||
{
|
||||
STransCtxVal val1 = {NULL, NULL, (void (*)(const void *))taosMemoryFree};
|
||||
val1.val = taosMemoryMalloc(12);
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
}
|
||||
transCtxMerge(ctx, src);
|
||||
taosMemoryFree(src);
|
||||
}
|
||||
EXPECT_EQ(2, taosHashGetSize(ctx->args));
|
||||
{
|
||||
STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
|
||||
transCtxInit(src);
|
||||
{
|
||||
STransCtxVal val1 = {NULL, NULL, (void (*)(const void *))taosMemoryFree};
|
||||
val1.val = taosMemoryMalloc(12);
|
||||
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
}
|
||||
{
|
||||
STransCtxVal val1 = {NULL, NULL, (void (*)(const void *))taosMemoryFree};
|
||||
val1.val = taosMemoryMalloc(12);
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
}
|
||||
transCtxMerge(ctx, src);
|
||||
taosMemoryFree(src);
|
||||
}
|
||||
std::string val("Hello");
|
||||
EXPECT_EQ(4, taosHashGetSize(ctx->args));
|
||||
{
|
||||
key = 1;
|
||||
STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
|
||||
transCtxInit(src);
|
||||
{
|
||||
STransCtxVal val1 = {NULL, NULL, (void (*)(const void *))taosMemoryFree};
|
||||
val1.val = taosMemoryCalloc(1, 11);
|
||||
val1.clone = cloneVal;
|
||||
memcpy(val1.val, val.c_str(), val.size());
|
||||
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
}
|
||||
{
|
||||
STransCtxVal val1 = {NULL, NULL, (void (*)(const void *))taosMemoryFree};
|
||||
val1.val = taosMemoryCalloc(1, 11);
|
||||
val1.clone = cloneVal;
|
||||
memcpy(val1.val, val.c_str(), val.size());
|
||||
taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
key++;
|
||||
}
|
||||
transCtxMerge(ctx, src);
|
||||
taosMemoryFree(src);
|
||||
}
|
||||
EXPECT_EQ(4, taosHashGetSize(ctx->args));
|
||||
|
||||
char *skey = (char *)transCtxDumpVal(ctx, 1);
|
||||
EXPECT_EQ(0, strcmp(skey, val.c_str()));
|
||||
taosMemoryFree(skey);
|
||||
|
||||
skey = (char *)transCtxDumpVal(ctx, 2);
|
||||
EXPECT_EQ(0, strcmp(skey, val.c_str()));
|
||||
}
|
||||
// TEST_F(TransCtxEnv, mergeTest) {
|
||||
// int key = 1;
|
||||
// {
|
||||
// STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
|
||||
// transCtxInit(src);
|
||||
// {
|
||||
// STransCtxVal val1 = {NULL, NULL, (void (*)(const void *))taosMemoryFree};
|
||||
// val1.val = taosMemoryMalloc(12);
|
||||
//
|
||||
// taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
// key++;
|
||||
// }
|
||||
// {
|
||||
// STransCtxVal val1 = {NULL, NULL, (void (*)(const void *))taosMemoryFree};
|
||||
// val1.val = taosMemoryMalloc(12);
|
||||
// taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
// key++;
|
||||
// }
|
||||
// transCtxMerge(ctx, src);
|
||||
// taosMemoryFree(src);
|
||||
// }
|
||||
// EXPECT_EQ(2, taosHashGetSize(ctx->args));
|
||||
// {
|
||||
// STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
|
||||
// transCtxInit(src);
|
||||
// {
|
||||
// STransCtxVal val1 = {NULL, NULL, (void (*)(const void *))taosMemoryFree};
|
||||
// val1.val = taosMemoryMalloc(12);
|
||||
//
|
||||
// taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
// key++;
|
||||
// }
|
||||
// {
|
||||
// STransCtxVal val1 = {NULL, NULL, (void (*)(const void *))taosMemoryFree};
|
||||
// val1.val = taosMemoryMalloc(12);
|
||||
// taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
// key++;
|
||||
// }
|
||||
// transCtxMerge(ctx, src);
|
||||
// taosMemoryFree(src);
|
||||
// }
|
||||
// std::string val("Hello");
|
||||
// EXPECT_EQ(4, taosHashGetSize(ctx->args));
|
||||
// {
|
||||
// key = 1;
|
||||
// STransCtx *src = (STransCtx *)taosMemoryCalloc(1, sizeof(STransCtx));
|
||||
// transCtxInit(src);
|
||||
// {
|
||||
// STransCtxVal val1 = {NULL, NULL, (void (*)(const void *))taosMemoryFree};
|
||||
// val1.val = taosMemoryCalloc(1, 11);
|
||||
// val1.clone = cloneVal;
|
||||
// memcpy(val1.val, val.c_str(), val.size());
|
||||
//
|
||||
// taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
// key++;
|
||||
// }
|
||||
// {
|
||||
// STransCtxVal val1 = {NULL, NULL, (void (*)(const void *))taosMemoryFree};
|
||||
// val1.val = taosMemoryCalloc(1, 11);
|
||||
// val1.clone = cloneVal;
|
||||
// memcpy(val1.val, val.c_str(), val.size());
|
||||
// taosHashPut(src->args, &key, sizeof(key), &val1, sizeof(val1));
|
||||
// key++;
|
||||
// }
|
||||
// transCtxMerge(ctx, src);
|
||||
// taosMemoryFree(src);
|
||||
// }
|
||||
// EXPECT_EQ(4, taosHashGetSize(ctx->args));
|
||||
//
|
||||
// char *skey = (char *)transCtxDumpVal(ctx, 1);
|
||||
// EXPECT_EQ(0, strcmp(skey, val.c_str()));
|
||||
// taosMemoryFree(skey);
|
||||
//
|
||||
// skey = (char *)transCtxDumpVal(ctx, 2);
|
||||
// EXPECT_EQ(0, strcmp(skey, val.c_str()));
|
||||
//}
|
||||
#endif
|
||||
|
|
|
@ -107,13 +107,14 @@ int32_t taosMkDir(const char *dirname) {
|
|||
int32_t taosMulMkDir(const char *dirname) {
|
||||
if (dirname == NULL) return -1;
|
||||
char temp[1024];
|
||||
char * pos = temp;
|
||||
int32_t code = 0;
|
||||
#ifdef WINDOWS
|
||||
taosRealPath(dirname, temp, sizeof(temp));
|
||||
if (temp[1] == ':') pos += 3;
|
||||
#else
|
||||
strcpy(temp, dirname);
|
||||
#endif
|
||||
char * pos = temp;
|
||||
int32_t code = 0;
|
||||
|
||||
if (taosDirExist(temp)) return code;
|
||||
|
||||
|
|
|
@ -69,7 +69,6 @@ void taosGetTmpfilePath(const char *inputTmpDir, const char *fileNamePrefix, cha
|
|||
}
|
||||
|
||||
strcpy(tmpPath + len, tdengineTmpFileNamePrefix);
|
||||
strcat(tmpPath, tdengineTmpFileNamePrefix);
|
||||
if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) {
|
||||
strcat(tmpPath, fileNamePrefix);
|
||||
strcat(tmpPath, "-%d-%s");
|
||||
|
|
|
@ -50,10 +50,15 @@ int32_t taosGetAppName(char* name, int32_t* len) {
|
|||
if (sub != NULL) {
|
||||
*sub = '\0';
|
||||
}
|
||||
strcpy(name, filepath);
|
||||
char* end = strrchr(filepath, TD_DIRSEP[0]);
|
||||
if (end == NULL) {
|
||||
end = filepath;
|
||||
}
|
||||
|
||||
strcpy(name, end);
|
||||
|
||||
if (len != NULL) {
|
||||
*len = (int32_t)strlen(filepath);
|
||||
*len = (int32_t)strlen(end);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue