Merge branch '3.0' of https://github.com/taosdata/TDengine into enh/-TD-31890-15
|
@ -90,7 +90,7 @@ If `maven` is used to manage the projects, what needs to be done is only adding
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>3.3.2</version>
|
<version>3.3.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>3.3.2</version>
|
<version>3.3.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.locationtech.jts</groupId>
|
<groupId>org.locationtech.jts</groupId>
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>3.3.2</version>
|
<version>3.3.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- druid -->
|
<!-- druid -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>3.3.2</version>
|
<version>3.3.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
|
|
|
@ -67,7 +67,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>3.3.2</version>
|
<version>3.3.3</version>
|
||||||
<!-- <scope>system</scope>-->
|
<!-- <scope>system</scope>-->
|
||||||
<!-- <systemPath>${project.basedir}/src/main/resources/lib/taos-jdbcdriver-2.0.15-dist.jar</systemPath>-->
|
<!-- <systemPath>${project.basedir}/src/main/resources/lib/taos-jdbcdriver-2.0.15-dist.jar</systemPath>-->
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>3.3.2</version>
|
<version>3.3.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- ANCHOR_END: dep-->
|
<!-- ANCHOR_END: dep-->
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,7 @@ package com.taos.example;
|
||||||
import com.taosdata.jdbc.TSDBPreparedStatement;
|
import com.taosdata.jdbc.TSDBPreparedStatement;
|
||||||
import com.taosdata.jdbc.utils.StringUtils;
|
import com.taosdata.jdbc.utils.StringUtils;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -16,15 +13,32 @@ public class ParameterBindingFullDemo {
|
||||||
|
|
||||||
private static final String host = "127.0.0.1";
|
private static final String host = "127.0.0.1";
|
||||||
private static final Random random = new Random(System.currentTimeMillis());
|
private static final Random random = new Random(System.currentTimeMillis());
|
||||||
private static final int BINARY_COLUMN_SIZE = 50;
|
private static final int BINARY_COLUMN_SIZE = 100;
|
||||||
private static final String[] schemaList = {
|
private static final String[] schemaList = {
|
||||||
"create table stable1(ts timestamp, f1 tinyint, f2 smallint, f3 int, f4 bigint) tags(t1 tinyint, t2 smallint, t3 int, t4 bigint)",
|
"drop database if exists example_all_type_stmt",
|
||||||
"create table stable2(ts timestamp, f1 float, f2 double) tags(t1 float, t2 double)",
|
"CREATE DATABASE IF NOT EXISTS example_all_type_stmt",
|
||||||
"create table stable3(ts timestamp, f1 bool) tags(t1 bool)",
|
"USE example_all_type_stmt",
|
||||||
"create table stable4(ts timestamp, f1 binary(" + BINARY_COLUMN_SIZE + ")) tags(t1 binary(" + BINARY_COLUMN_SIZE + "))",
|
"CREATE STABLE IF NOT EXISTS stb_json (" +
|
||||||
"create table stable5(ts timestamp, f1 nchar(" + BINARY_COLUMN_SIZE + ")) tags(t1 nchar(" + BINARY_COLUMN_SIZE + "))",
|
"ts TIMESTAMP, " +
|
||||||
"create table stable6(ts timestamp, f1 varbinary(" + BINARY_COLUMN_SIZE + ")) tags(t1 varbinary(" + BINARY_COLUMN_SIZE + "))",
|
"int_col INT) " +
|
||||||
"create table stable7(ts timestamp, f1 geometry(" + BINARY_COLUMN_SIZE + ")) tags(t1 geometry(" + BINARY_COLUMN_SIZE + "))",
|
"tags (json_tag json)",
|
||||||
|
"CREATE STABLE IF NOT EXISTS stb (" +
|
||||||
|
"ts TIMESTAMP, " +
|
||||||
|
"int_col INT, " +
|
||||||
|
"double_col DOUBLE, " +
|
||||||
|
"bool_col BOOL, " +
|
||||||
|
"binary_col BINARY(100), " +
|
||||||
|
"nchar_col NCHAR(100), " +
|
||||||
|
"varbinary_col VARBINARY(100), " +
|
||||||
|
"geometry_col GEOMETRY(100)) " +
|
||||||
|
"tags (" +
|
||||||
|
"int_tag INT, " +
|
||||||
|
"double_tag DOUBLE, " +
|
||||||
|
"bool_tag BOOL, " +
|
||||||
|
"binary_tag BINARY(100), " +
|
||||||
|
"nchar_tag NCHAR(100), " +
|
||||||
|
"varbinary_tag VARBINARY(100), " +
|
||||||
|
"geometry_tag GEOMETRY(100))"
|
||||||
};
|
};
|
||||||
private static final int numOfSubTable = 10, numOfRow = 10;
|
private static final int numOfSubTable = 10, numOfRow = 10;
|
||||||
|
|
||||||
|
@ -34,55 +48,37 @@ public class ParameterBindingFullDemo {
|
||||||
try (Connection conn = DriverManager.getConnection(jdbcUrl, "root", "taosdata")) {
|
try (Connection conn = DriverManager.getConnection(jdbcUrl, "root", "taosdata")) {
|
||||||
|
|
||||||
init(conn);
|
init(conn);
|
||||||
|
stmtJsonTag(conn);
|
||||||
|
stmtAll(conn);
|
||||||
|
|
||||||
bindInteger(conn);
|
|
||||||
bindFloat(conn);
|
|
||||||
bindBoolean(conn);
|
|
||||||
bindBytes(conn);
|
|
||||||
bindString(conn);
|
|
||||||
bindVarbinary(conn);
|
|
||||||
bindGeometry(conn);
|
|
||||||
|
|
||||||
clean(conn);
|
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
// handle any errors, please refer to the JDBC specifications for detailed exceptions info
|
// handle any errors, please refer to the JDBC specifications for detailed exceptions info
|
||||||
System.out.println("Failed to insert to table meters using stmt, url: " + jdbcUrl + "; ErrCode:" + ex.getErrorCode() + "; ErrMessage: " + ex.getMessage());
|
System.out.println("Failed to insert data using stmt, ErrCode:" + ex.getErrorCode() + "; ErrMessage: " + ex.getMessage());
|
||||||
throw ex;
|
throw ex;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.out.println("Failed to insert to table meters using stmt, url: " + jdbcUrl + "; ErrMessage: " + ex.getMessage());
|
System.out.println("Failed to insert data using stmt, ErrMessage: " + ex.getMessage());
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void init(Connection conn) throws SQLException {
|
private static void init(Connection conn) throws SQLException {
|
||||||
clean(conn);
|
|
||||||
try (Statement stmt = conn.createStatement()) {
|
try (Statement stmt = conn.createStatement()) {
|
||||||
stmt.execute("create database if not exists test_parabind");
|
|
||||||
stmt.execute("use test_parabind");
|
|
||||||
for (int i = 0; i < schemaList.length; i++) {
|
for (int i = 0; i < schemaList.length; i++) {
|
||||||
stmt.execute(schemaList[i]);
|
stmt.execute(schemaList[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static void clean(Connection conn) throws SQLException {
|
|
||||||
try (Statement stmt = conn.createStatement()) {
|
|
||||||
stmt.execute("drop database if exists test_parabind");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void bindInteger(Connection conn) throws SQLException {
|
private static void stmtJsonTag(Connection conn) throws SQLException {
|
||||||
String sql = "insert into ? using stable1 tags(?,?,?,?) values(?,?,?,?,?)";
|
String sql = "INSERT INTO ? using stb_json tags(?) VALUES (?,?)";
|
||||||
|
|
||||||
try (TSDBPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSDBPreparedStatement.class)) {
|
try (TSDBPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSDBPreparedStatement.class)) {
|
||||||
|
|
||||||
for (int i = 1; i <= numOfSubTable; i++) {
|
for (int i = 1; i <= numOfSubTable; i++) {
|
||||||
// set table name
|
// set table name
|
||||||
pstmt.setTableName("t1_" + i);
|
pstmt.setTableName("ntb_json_" + i);
|
||||||
// set tags
|
// set tags
|
||||||
pstmt.setTagByte(0, Byte.parseByte(Integer.toString(random.nextInt(Byte.MAX_VALUE))));
|
pstmt.setTagJson(0, "{\"device\":\"device_" + i + "\"}");
|
||||||
pstmt.setTagShort(1, Short.parseShort(Integer.toString(random.nextInt(Short.MAX_VALUE))));
|
|
||||||
pstmt.setTagInt(2, random.nextInt(Integer.MAX_VALUE));
|
|
||||||
pstmt.setTagLong(3, random.nextLong());
|
|
||||||
// set columns
|
// set columns
|
||||||
ArrayList<Long> tsList = new ArrayList<>();
|
ArrayList<Long> tsList = new ArrayList<>();
|
||||||
long current = System.currentTimeMillis();
|
long current = System.currentTimeMillis();
|
||||||
|
@ -90,45 +86,42 @@ public class ParameterBindingFullDemo {
|
||||||
tsList.add(current + j);
|
tsList.add(current + j);
|
||||||
pstmt.setTimestamp(0, tsList);
|
pstmt.setTimestamp(0, tsList);
|
||||||
|
|
||||||
ArrayList<Byte> f1List = new ArrayList<>();
|
ArrayList<Integer> f1List = new ArrayList<>();
|
||||||
for (int j = 0; j < numOfRow; j++)
|
for (int j = 0; j < numOfRow; j++)
|
||||||
f1List.add(Byte.parseByte(Integer.toString(random.nextInt(Byte.MAX_VALUE))));
|
f1List.add(random.nextInt(Integer.MAX_VALUE));
|
||||||
pstmt.setByte(1, f1List);
|
pstmt.setInt(1, f1List);
|
||||||
|
|
||||||
ArrayList<Short> f2List = new ArrayList<>();
|
|
||||||
for (int j = 0; j < numOfRow; j++)
|
|
||||||
f2List.add(Short.parseShort(Integer.toString(random.nextInt(Short.MAX_VALUE))));
|
|
||||||
pstmt.setShort(2, f2List);
|
|
||||||
|
|
||||||
ArrayList<Integer> f3List = new ArrayList<>();
|
|
||||||
for (int j = 0; j < numOfRow; j++)
|
|
||||||
f3List.add(random.nextInt(Integer.MAX_VALUE));
|
|
||||||
pstmt.setInt(3, f3List);
|
|
||||||
|
|
||||||
ArrayList<Long> f4List = new ArrayList<>();
|
|
||||||
for (int j = 0; j < numOfRow; j++)
|
|
||||||
f4List.add(random.nextLong());
|
|
||||||
pstmt.setLong(4, f4List);
|
|
||||||
|
|
||||||
// add column
|
// add column
|
||||||
pstmt.columnDataAddBatch();
|
pstmt.columnDataAddBatch();
|
||||||
}
|
}
|
||||||
// execute column
|
// execute column
|
||||||
pstmt.columnDataExecuteBatch();
|
pstmt.columnDataExecuteBatch();
|
||||||
|
System.out.println("Successfully inserted rows to example_all_type_stmt.ntb_json");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void bindFloat(Connection conn) throws SQLException {
|
private static void stmtAll(Connection conn) throws SQLException {
|
||||||
String sql = "insert into ? using stable2 tags(?,?) values(?,?,?)";
|
String sql = "INSERT INTO ? using stb tags(?,?,?,?,?,?,?) VALUES (?,?,?,?,?,?,?,?)";
|
||||||
|
|
||||||
TSDBPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSDBPreparedStatement.class);
|
TSDBPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSDBPreparedStatement.class);
|
||||||
|
|
||||||
for (int i = 1; i <= numOfSubTable; i++) {
|
for (int i = 1; i <= numOfSubTable; i++) {
|
||||||
// set table name
|
// set table name
|
||||||
pstmt.setTableName("t2_" + i);
|
pstmt.setTableName("ntb" + i);
|
||||||
// set tags
|
// set tags
|
||||||
pstmt.setTagFloat(0, random.nextFloat());
|
pstmt.setTagInt(0, i);
|
||||||
pstmt.setTagDouble(1, random.nextDouble());
|
pstmt.setTagDouble(1, 1.1);
|
||||||
|
pstmt.setTagBoolean(2, true);
|
||||||
|
pstmt.setTagString(3, "binary_value");
|
||||||
|
pstmt.setTagNString(4, "nchar_value");
|
||||||
|
pstmt.setTagVarbinary(5, new byte[]{(byte) 0x98, (byte) 0xf4, 0x6e});
|
||||||
|
pstmt.setTagGeometry(6, new byte[]{
|
||||||
|
0x01, 0x01, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x59,
|
||||||
|
0x40, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x59, 0x40});
|
||||||
|
|
||||||
// set columns
|
// set columns
|
||||||
ArrayList<Long> tsList = new ArrayList<>();
|
ArrayList<Long> tsList = new ArrayList<>();
|
||||||
long current = System.currentTimeMillis();
|
long current = System.currentTimeMillis();
|
||||||
|
@ -136,190 +129,54 @@ public class ParameterBindingFullDemo {
|
||||||
tsList.add(current + j);
|
tsList.add(current + j);
|
||||||
pstmt.setTimestamp(0, tsList);
|
pstmt.setTimestamp(0, tsList);
|
||||||
|
|
||||||
ArrayList<Float> f1List = new ArrayList<>();
|
ArrayList<Integer> f1List = new ArrayList<>();
|
||||||
for (int j = 0; j < numOfRow; j++)
|
for (int j = 0; j < numOfRow; j++)
|
||||||
f1List.add(random.nextFloat());
|
f1List.add(random.nextInt(Integer.MAX_VALUE));
|
||||||
pstmt.setFloat(1, f1List);
|
pstmt.setInt(1, f1List);
|
||||||
|
|
||||||
ArrayList<Double> f2List = new ArrayList<>();
|
ArrayList<Double> f2List = new ArrayList<>();
|
||||||
for (int j = 0; j < numOfRow; j++)
|
for (int j = 0; j < numOfRow; j++)
|
||||||
f2List.add(random.nextDouble());
|
f2List.add(random.nextDouble());
|
||||||
pstmt.setDouble(2, f2List);
|
pstmt.setDouble(2, f2List);
|
||||||
|
|
||||||
|
ArrayList<Boolean> f3List = new ArrayList<>();
|
||||||
|
for (int j = 0; j < numOfRow; j++)
|
||||||
|
f3List.add(true);
|
||||||
|
pstmt.setBoolean(3, f3List);
|
||||||
|
|
||||||
|
ArrayList<String> f4List = new ArrayList<>();
|
||||||
|
for (int j = 0; j < numOfRow; j++)
|
||||||
|
f4List.add("binary_value");
|
||||||
|
pstmt.setString(4, f4List, BINARY_COLUMN_SIZE);
|
||||||
|
|
||||||
|
ArrayList<String> f5List = new ArrayList<>();
|
||||||
|
for (int j = 0; j < numOfRow; j++)
|
||||||
|
f5List.add("nchar_value");
|
||||||
|
pstmt.setNString(5, f5List, BINARY_COLUMN_SIZE);
|
||||||
|
|
||||||
|
ArrayList<byte[]> f6List = new ArrayList<>();
|
||||||
|
for (int j = 0; j < numOfRow; j++)
|
||||||
|
f6List.add(new byte[]{(byte) 0x98, (byte) 0xf4, 0x6e});
|
||||||
|
pstmt.setVarbinary(6, f6List, BINARY_COLUMN_SIZE);
|
||||||
|
|
||||||
|
ArrayList<byte[]> f7List = new ArrayList<>();
|
||||||
|
for (int j = 0; j < numOfRow; j++)
|
||||||
|
f7List.add(new byte[]{
|
||||||
|
0x01, 0x01, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x59,
|
||||||
|
0x40, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x59, 0x40});
|
||||||
|
pstmt.setGeometry(7, f7List, BINARY_COLUMN_SIZE);
|
||||||
|
|
||||||
// add column
|
// add column
|
||||||
pstmt.columnDataAddBatch();
|
pstmt.columnDataAddBatch();
|
||||||
}
|
}
|
||||||
// execute
|
// execute
|
||||||
pstmt.columnDataExecuteBatch();
|
pstmt.columnDataExecuteBatch();
|
||||||
|
System.out.println("Successfully inserted rows to example_all_type_stmt.ntb");
|
||||||
// close if no try-with-catch statement is used
|
// close if no try-with-catch statement is used
|
||||||
pstmt.close();
|
pstmt.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void bindBoolean(Connection conn) throws SQLException {
|
|
||||||
String sql = "insert into ? using stable3 tags(?) values(?,?)";
|
|
||||||
|
|
||||||
try (TSDBPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSDBPreparedStatement.class)) {
|
|
||||||
for (int i = 1; i <= numOfSubTable; i++) {
|
|
||||||
// set table name
|
|
||||||
pstmt.setTableName("t3_" + i);
|
|
||||||
// set tags
|
|
||||||
pstmt.setTagBoolean(0, random.nextBoolean());
|
|
||||||
// set columns
|
|
||||||
ArrayList<Long> tsList = new ArrayList<>();
|
|
||||||
long current = System.currentTimeMillis();
|
|
||||||
for (int j = 0; j < numOfRow; j++)
|
|
||||||
tsList.add(current + j);
|
|
||||||
pstmt.setTimestamp(0, tsList);
|
|
||||||
|
|
||||||
ArrayList<Boolean> f1List = new ArrayList<>();
|
|
||||||
for (int j = 0; j < numOfRow; j++)
|
|
||||||
f1List.add(random.nextBoolean());
|
|
||||||
pstmt.setBoolean(1, f1List);
|
|
||||||
|
|
||||||
// add column
|
|
||||||
pstmt.columnDataAddBatch();
|
|
||||||
}
|
|
||||||
// execute
|
|
||||||
pstmt.columnDataExecuteBatch();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void bindBytes(Connection conn) throws SQLException {
|
|
||||||
String sql = "insert into ? using stable4 tags(?) values(?,?)";
|
|
||||||
|
|
||||||
try (TSDBPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSDBPreparedStatement.class)) {
|
|
||||||
|
|
||||||
for (int i = 1; i <= numOfSubTable; i++) {
|
|
||||||
// set table name
|
|
||||||
pstmt.setTableName("t4_" + i);
|
|
||||||
// set tags
|
|
||||||
pstmt.setTagString(0, new String("abc"));
|
|
||||||
|
|
||||||
// set columns
|
|
||||||
ArrayList<Long> tsList = new ArrayList<>();
|
|
||||||
long current = System.currentTimeMillis();
|
|
||||||
for (int j = 0; j < numOfRow; j++)
|
|
||||||
tsList.add(current + j);
|
|
||||||
pstmt.setTimestamp(0, tsList);
|
|
||||||
|
|
||||||
ArrayList<String> f1List = new ArrayList<>();
|
|
||||||
for (int j = 0; j < numOfRow; j++) {
|
|
||||||
f1List.add(new String("abc"));
|
|
||||||
}
|
|
||||||
pstmt.setString(1, f1List, BINARY_COLUMN_SIZE);
|
|
||||||
|
|
||||||
// add column
|
|
||||||
pstmt.columnDataAddBatch();
|
|
||||||
}
|
|
||||||
// execute
|
|
||||||
pstmt.columnDataExecuteBatch();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void bindString(Connection conn) throws SQLException {
|
|
||||||
String sql = "insert into ? using stable5 tags(?) values(?,?)";
|
|
||||||
|
|
||||||
try (TSDBPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSDBPreparedStatement.class)) {
|
|
||||||
|
|
||||||
for (int i = 1; i <= numOfSubTable; i++) {
|
|
||||||
// set table name
|
|
||||||
pstmt.setTableName("t5_" + i);
|
|
||||||
// set tags
|
|
||||||
pstmt.setTagNString(0, "California.SanFrancisco");
|
|
||||||
|
|
||||||
// set columns
|
|
||||||
ArrayList<Long> tsList = new ArrayList<>();
|
|
||||||
long current = System.currentTimeMillis();
|
|
||||||
for (int j = 0; j < numOfRow; j++)
|
|
||||||
tsList.add(current + j);
|
|
||||||
pstmt.setTimestamp(0, tsList);
|
|
||||||
|
|
||||||
ArrayList<String> f1List = new ArrayList<>();
|
|
||||||
for (int j = 0; j < numOfRow; j++) {
|
|
||||||
f1List.add("California.LosAngeles");
|
|
||||||
}
|
|
||||||
pstmt.setNString(1, f1List, BINARY_COLUMN_SIZE);
|
|
||||||
|
|
||||||
// add column
|
|
||||||
pstmt.columnDataAddBatch();
|
|
||||||
}
|
|
||||||
// execute
|
|
||||||
pstmt.columnDataExecuteBatch();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void bindVarbinary(Connection conn) throws SQLException {
|
|
||||||
String sql = "insert into ? using stable6 tags(?) values(?,?)";
|
|
||||||
|
|
||||||
try (TSDBPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSDBPreparedStatement.class)) {
|
|
||||||
|
|
||||||
for (int i = 1; i <= numOfSubTable; i++) {
|
|
||||||
// set table name
|
|
||||||
pstmt.setTableName("t6_" + i);
|
|
||||||
// set tags
|
|
||||||
byte[] bTag = new byte[]{0,2,3,4,5};
|
|
||||||
bTag[0] = (byte) i;
|
|
||||||
pstmt.setTagVarbinary(0, bTag);
|
|
||||||
|
|
||||||
// set columns
|
|
||||||
ArrayList<Long> tsList = new ArrayList<>();
|
|
||||||
long current = System.currentTimeMillis();
|
|
||||||
for (int j = 0; j < numOfRow; j++)
|
|
||||||
tsList.add(current + j);
|
|
||||||
pstmt.setTimestamp(0, tsList);
|
|
||||||
|
|
||||||
ArrayList<byte[]> f1List = new ArrayList<>();
|
|
||||||
for (int j = 0; j < numOfRow; j++) {
|
|
||||||
byte[] v = new byte[]{0,2,3,4,5,6};
|
|
||||||
v[0] = (byte)j;
|
|
||||||
f1List.add(v);
|
|
||||||
}
|
|
||||||
pstmt.setVarbinary(1, f1List, BINARY_COLUMN_SIZE);
|
|
||||||
|
|
||||||
// add column
|
|
||||||
pstmt.columnDataAddBatch();
|
|
||||||
}
|
|
||||||
// execute
|
|
||||||
pstmt.columnDataExecuteBatch();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void bindGeometry(Connection conn) throws SQLException {
|
|
||||||
String sql = "insert into ? using stable7 tags(?) values(?,?)";
|
|
||||||
|
|
||||||
try (TSDBPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSDBPreparedStatement.class)) {
|
|
||||||
|
|
||||||
byte[] g1 = StringUtils.hexToBytes("0101000000000000000000F03F0000000000000040");
|
|
||||||
byte[] g2 = StringUtils.hexToBytes("0102000020E610000002000000000000000000F03F000000000000004000000000000008400000000000001040");
|
|
||||||
List<byte[]> listGeo = new ArrayList<>();
|
|
||||||
listGeo.add(g1);
|
|
||||||
listGeo.add(g2);
|
|
||||||
|
|
||||||
for (int i = 1; i <= 2; i++) {
|
|
||||||
// set table name
|
|
||||||
pstmt.setTableName("t7_" + i);
|
|
||||||
// set tags
|
|
||||||
pstmt.setTagGeometry(0, listGeo.get(i - 1));
|
|
||||||
|
|
||||||
// set columns
|
|
||||||
ArrayList<Long> tsList = new ArrayList<>();
|
|
||||||
long current = System.currentTimeMillis();
|
|
||||||
for (int j = 0; j < numOfRow; j++)
|
|
||||||
tsList.add(current + j);
|
|
||||||
pstmt.setTimestamp(0, tsList);
|
|
||||||
|
|
||||||
ArrayList<byte[]> f1List = new ArrayList<>();
|
|
||||||
for (int j = 0; j < numOfRow; j++) {
|
|
||||||
f1List.add(listGeo.get(i - 1));
|
|
||||||
}
|
|
||||||
pstmt.setGeometry(1, f1List, BINARY_COLUMN_SIZE);
|
|
||||||
|
|
||||||
// add column
|
|
||||||
pstmt.columnDataAddBatch();
|
|
||||||
}
|
|
||||||
// execute
|
|
||||||
pstmt.columnDataExecuteBatch();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// ANCHOR_END: para_bind
|
// ANCHOR_END: para_bind
|
||||||
|
|
|
@ -11,11 +11,30 @@ public class WSParameterBindingFullDemo {
|
||||||
private static final Random random = new Random(System.currentTimeMillis());
|
private static final Random random = new Random(System.currentTimeMillis());
|
||||||
private static final int BINARY_COLUMN_SIZE = 30;
|
private static final int BINARY_COLUMN_SIZE = 30;
|
||||||
private static final String[] schemaList = {
|
private static final String[] schemaList = {
|
||||||
"create table stable1(ts timestamp, f1 tinyint, f2 smallint, f3 int, f4 bigint) tags(t1 tinyint, t2 smallint, t3 int, t4 bigint)",
|
"drop database if exists example_all_type_stmt",
|
||||||
"create table stable2(ts timestamp, f1 float, f2 double) tags(t1 float, t2 double)",
|
"CREATE DATABASE IF NOT EXISTS example_all_type_stmt",
|
||||||
"create table stable3(ts timestamp, f1 bool) tags(t1 bool)",
|
"USE example_all_type_stmt",
|
||||||
"create table stable4(ts timestamp, f1 binary(" + BINARY_COLUMN_SIZE + ")) tags(t1 binary(" + BINARY_COLUMN_SIZE + "))",
|
"CREATE STABLE IF NOT EXISTS stb_json (" +
|
||||||
"create table stable5(ts timestamp, f1 nchar(" + BINARY_COLUMN_SIZE + ")) tags(t1 nchar(" + BINARY_COLUMN_SIZE + "))"
|
"ts TIMESTAMP, " +
|
||||||
|
"int_col INT) " +
|
||||||
|
"tags (json_tag json)",
|
||||||
|
"CREATE STABLE IF NOT EXISTS stb (" +
|
||||||
|
"ts TIMESTAMP, " +
|
||||||
|
"int_col INT, " +
|
||||||
|
"double_col DOUBLE, " +
|
||||||
|
"bool_col BOOL, " +
|
||||||
|
"binary_col BINARY(100), " +
|
||||||
|
"nchar_col NCHAR(100), " +
|
||||||
|
"varbinary_col VARBINARY(100), " +
|
||||||
|
"geometry_col GEOMETRY(100)) " +
|
||||||
|
"tags (" +
|
||||||
|
"int_tag INT, " +
|
||||||
|
"double_tag DOUBLE, " +
|
||||||
|
"bool_tag BOOL, " +
|
||||||
|
"binary_tag BINARY(100), " +
|
||||||
|
"nchar_tag NCHAR(100), " +
|
||||||
|
"varbinary_tag VARBINARY(100), " +
|
||||||
|
"geometry_tag GEOMETRY(100))"
|
||||||
};
|
};
|
||||||
private static final int numOfSubTable = 10, numOfRow = 10;
|
private static final int numOfSubTable = 10, numOfRow = 10;
|
||||||
|
|
||||||
|
@ -27,153 +46,91 @@ public class WSParameterBindingFullDemo {
|
||||||
|
|
||||||
init(conn);
|
init(conn);
|
||||||
|
|
||||||
bindInteger(conn);
|
stmtJsonTag(conn);
|
||||||
|
|
||||||
bindFloat(conn);
|
stmtAll(conn);
|
||||||
|
|
||||||
bindBoolean(conn);
|
|
||||||
|
|
||||||
bindBytes(conn);
|
|
||||||
|
|
||||||
bindString(conn);
|
|
||||||
|
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
// handle any errors, please refer to the JDBC specifications for detailed exceptions info
|
// handle any errors, please refer to the JDBC specifications for detailed exceptions info
|
||||||
System.out.println("Failed to insert to table meters using stmt, url: " + jdbcUrl + "; ErrCode:" + ex.getErrorCode() + "; ErrMessage: " + ex.getMessage());
|
System.out.println("Failed to insert data using stmt, ErrCode:" + ex.getErrorCode() + "; ErrMessage: " + ex.getMessage());
|
||||||
throw ex;
|
throw ex;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.out.println("Failed to insert to table meters using stmt, url: " + jdbcUrl + "; ErrMessage: " + ex.getMessage());
|
System.out.println("Failed to insert data using stmt, ErrMessage: " + ex.getMessage());
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void init(Connection conn) throws SQLException {
|
private static void init(Connection conn) throws SQLException {
|
||||||
try (Statement stmt = conn.createStatement()) {
|
try (Statement stmt = conn.createStatement()) {
|
||||||
stmt.execute("drop database if exists test_ws_parabind");
|
|
||||||
stmt.execute("create database if not exists test_ws_parabind");
|
|
||||||
stmt.execute("use test_ws_parabind");
|
|
||||||
for (int i = 0; i < schemaList.length; i++) {
|
for (int i = 0; i < schemaList.length; i++) {
|
||||||
stmt.execute(schemaList[i]);
|
stmt.execute(schemaList[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void bindInteger(Connection conn) throws SQLException {
|
private static void stmtJsonTag(Connection conn) throws SQLException {
|
||||||
String sql = "insert into ? using stable1 tags(?,?,?,?) values(?,?,?,?,?)";
|
String sql = "INSERT INTO ? using stb_json tags(?) VALUES (?,?)";
|
||||||
|
|
||||||
try (TSWSPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSWSPreparedStatement.class)) {
|
try (TSWSPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSWSPreparedStatement.class)) {
|
||||||
|
|
||||||
for (int i = 1; i <= numOfSubTable; i++) {
|
for (int i = 1; i <= numOfSubTable; i++) {
|
||||||
// set table name
|
// set table name
|
||||||
pstmt.setTableName("t1_" + i);
|
pstmt.setTableName("ntb_json_" + i);
|
||||||
// set tags
|
// set tags
|
||||||
pstmt.setTagByte(1, Byte.parseByte(Integer.toString(random.nextInt(Byte.MAX_VALUE))));
|
pstmt.setTagJson(1, "{\"device\":\"device_" + i + "\"}");
|
||||||
pstmt.setTagShort(2, Short.parseShort(Integer.toString(random.nextInt(Short.MAX_VALUE))));
|
|
||||||
pstmt.setTagInt(3, random.nextInt(Integer.MAX_VALUE));
|
|
||||||
pstmt.setTagLong(4, random.nextLong());
|
|
||||||
// set columns
|
// set columns
|
||||||
long current = System.currentTimeMillis();
|
long current = System.currentTimeMillis();
|
||||||
for (int j = 0; j < numOfRow; j++) {
|
for (int j = 0; j < numOfRow; j++) {
|
||||||
pstmt.setTimestamp(1, new Timestamp(current + j));
|
pstmt.setTimestamp(1, new Timestamp(current + j));
|
||||||
pstmt.setByte(2, Byte.parseByte(Integer.toString(random.nextInt(Byte.MAX_VALUE))));
|
pstmt.setInt(2, j);
|
||||||
pstmt.setShort(3, Short.parseShort(Integer.toString(random.nextInt(Short.MAX_VALUE))));
|
|
||||||
pstmt.setInt(4, random.nextInt(Integer.MAX_VALUE));
|
|
||||||
pstmt.setLong(5, random.nextLong());
|
|
||||||
pstmt.addBatch();
|
pstmt.addBatch();
|
||||||
}
|
}
|
||||||
pstmt.executeBatch();
|
pstmt.executeBatch();
|
||||||
}
|
}
|
||||||
|
System.out.println("Successfully inserted rows to example_all_type_stmt.ntb_json");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void bindFloat(Connection conn) throws SQLException {
|
private static void stmtAll(Connection conn) throws SQLException {
|
||||||
String sql = "insert into ? using stable2 tags(?,?) values(?,?,?)";
|
String sql = "INSERT INTO ? using stb tags(?,?,?,?,?,?,?) VALUES (?,?,?,?,?,?,?,?)";
|
||||||
|
|
||||||
try (TSWSPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSWSPreparedStatement.class)) {
|
try (TSWSPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSWSPreparedStatement.class)) {
|
||||||
|
|
||||||
for (int i = 1; i <= numOfSubTable; i++) {
|
|
||||||
// set table name
|
// set table name
|
||||||
pstmt.setTableName("t2_" + i);
|
pstmt.setTableName("ntb");
|
||||||
// set tags
|
// set tags
|
||||||
pstmt.setTagFloat(1, random.nextFloat());
|
pstmt.setTagInt(1, 1);
|
||||||
pstmt.setTagDouble(2, random.nextDouble());
|
pstmt.setTagDouble(2, 1.1);
|
||||||
// set columns
|
pstmt.setTagBoolean(3, true);
|
||||||
|
pstmt.setTagString(4, "binary_value");
|
||||||
|
pstmt.setTagNString(5, "nchar_value");
|
||||||
|
pstmt.setTagVarbinary(6, new byte[]{(byte) 0x98, (byte) 0xf4, 0x6e});
|
||||||
|
pstmt.setTagGeometry(7, new byte[]{
|
||||||
|
0x01, 0x01, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x59,
|
||||||
|
0x40, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x59, 0x40});
|
||||||
|
|
||||||
long current = System.currentTimeMillis();
|
long current = System.currentTimeMillis();
|
||||||
for (int j = 0; j < numOfRow; j++) {
|
|
||||||
pstmt.setTimestamp(1, new Timestamp(current + j));
|
|
||||||
pstmt.setFloat(2, random.nextFloat());
|
pstmt.setTimestamp(1, new Timestamp(current));
|
||||||
pstmt.setDouble(3, random.nextDouble());
|
pstmt.setInt(2, 1);
|
||||||
|
pstmt.setDouble(3, 1.1);
|
||||||
|
pstmt.setBoolean(4, true);
|
||||||
|
pstmt.setString(5, "binary_value");
|
||||||
|
pstmt.setNString(6, "nchar_value");
|
||||||
|
pstmt.setVarbinary(7, new byte[]{(byte) 0x98, (byte) 0xf4, 0x6e});
|
||||||
|
pstmt.setGeometry(8, new byte[]{
|
||||||
|
0x01, 0x01, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x59,
|
||||||
|
0x40, 0x00, 0x00, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x59, 0x40});
|
||||||
pstmt.addBatch();
|
pstmt.addBatch();
|
||||||
}
|
|
||||||
pstmt.executeBatch();
|
pstmt.executeBatch();
|
||||||
}
|
System.out.println("Successfully inserted rows to example_all_type_stmt.ntb");
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void bindBoolean(Connection conn) throws SQLException {
|
|
||||||
String sql = "insert into ? using stable3 tags(?) values(?,?)";
|
|
||||||
|
|
||||||
try (TSWSPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSWSPreparedStatement.class)) {
|
|
||||||
for (int i = 1; i <= numOfSubTable; i++) {
|
|
||||||
// set table name
|
|
||||||
pstmt.setTableName("t3_" + i);
|
|
||||||
// set tags
|
|
||||||
pstmt.setTagBoolean(1, random.nextBoolean());
|
|
||||||
// set columns
|
|
||||||
long current = System.currentTimeMillis();
|
|
||||||
for (int j = 0; j < numOfRow; j++) {
|
|
||||||
pstmt.setTimestamp(1, new Timestamp(current + j));
|
|
||||||
pstmt.setBoolean(2, random.nextBoolean());
|
|
||||||
pstmt.addBatch();
|
|
||||||
}
|
|
||||||
pstmt.executeBatch();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void bindBytes(Connection conn) throws SQLException {
|
|
||||||
String sql = "insert into ? using stable4 tags(?) values(?,?)";
|
|
||||||
|
|
||||||
try (TSWSPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSWSPreparedStatement.class)) {
|
|
||||||
|
|
||||||
for (int i = 1; i <= numOfSubTable; i++) {
|
|
||||||
// set table name
|
|
||||||
pstmt.setTableName("t4_" + i);
|
|
||||||
// set tags
|
|
||||||
pstmt.setTagString(1, new String("abc"));
|
|
||||||
|
|
||||||
// set columns
|
|
||||||
long current = System.currentTimeMillis();
|
|
||||||
for (int j = 0; j < numOfRow; j++) {
|
|
||||||
pstmt.setTimestamp(1, new Timestamp(current + j));
|
|
||||||
pstmt.setString(2, "abc");
|
|
||||||
pstmt.addBatch();
|
|
||||||
}
|
|
||||||
pstmt.executeBatch();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void bindString(Connection conn) throws SQLException {
|
|
||||||
String sql = "insert into ? using stable5 tags(?) values(?,?)";
|
|
||||||
|
|
||||||
try (TSWSPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSWSPreparedStatement.class)) {
|
|
||||||
|
|
||||||
for (int i = 1; i <= numOfSubTable; i++) {
|
|
||||||
// set table name
|
|
||||||
pstmt.setTableName("t5_" + i);
|
|
||||||
// set tags
|
|
||||||
pstmt.setTagNString(1, "California.SanFrancisco");
|
|
||||||
|
|
||||||
// set columns
|
|
||||||
long current = System.currentTimeMillis();
|
|
||||||
for (int j = 0; j < numOfRow; j++) {
|
|
||||||
pstmt.setTimestamp(0, new Timestamp(current + j));
|
|
||||||
pstmt.setNString(1, "California.SanFrancisco");
|
|
||||||
pstmt.addBatch();
|
|
||||||
}
|
|
||||||
pstmt.executeBatch();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,36 +50,68 @@ public class TestAll {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRestInsert() throws SQLException {
|
public void testWsConnect() throws Exception {
|
||||||
dropDB("power");
|
WSConnectExample.main(args);
|
||||||
RestInsertExample.main(args);
|
|
||||||
RestQueryExample.main(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStmtInsert() throws SQLException {
|
public void testBase() throws Exception {
|
||||||
|
JdbcCreatDBDemo.main(args);
|
||||||
|
JdbcInsertDataDemo.main(args);
|
||||||
|
JdbcQueryDemo.main(args);
|
||||||
|
|
||||||
dropDB("power");
|
dropDB("power");
|
||||||
StmtInsertExample.main(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSubscribe() {
|
public void testWsSchemaless() throws Exception {
|
||||||
|
dropDB("power");
|
||||||
|
SchemalessWsTest.main(args);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testJniSchemaless() throws Exception {
|
||||||
|
dropDB("power");
|
||||||
|
SchemalessJniTest.main(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJniStmtBasic() throws Exception {
|
||||||
|
dropDB("power");
|
||||||
|
ParameterBindingBasicDemo.main(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJniStmtFull() throws Exception {
|
||||||
|
dropDB("power");
|
||||||
|
ParameterBindingFullDemo.main(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWsStmtBasic() throws Exception {
|
||||||
|
dropDB("power");
|
||||||
|
WSParameterBindingBasicDemo.main(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWsStmtFull() throws Exception {
|
||||||
|
dropDB("power");
|
||||||
|
WSParameterBindingFullDemo.main(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConsumer() throws Exception {
|
||||||
|
dropDB("power");
|
||||||
SubscribeDemo.main(args);
|
SubscribeDemo.main(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Test
|
||||||
@Test
|
// public void testSubscribeJni() throws SQLException, InterruptedException {
|
||||||
public void testSubscribeOverWebsocket() {
|
// dropDB("power");
|
||||||
WebsocketSubscribeDemo.main(args);
|
// ConsumerLoopFull.main(args);
|
||||||
}
|
// }
|
||||||
|
// @Test
|
||||||
@Test
|
// public void testSubscribeWs() throws SQLException, InterruptedException {
|
||||||
public void testSchemaless() throws SQLException {
|
// dropDB("power");
|
||||||
LineProtocolExample.main(args);
|
// WsConsumerLoopFull.main(args);
|
||||||
TelnetLineProtocolExample.main(args);
|
// }
|
||||||
// for json protocol, tags may be double type. but for telnet protocol tag must be nchar type.
|
|
||||||
// To avoid type mismatch, we delete database test.
|
|
||||||
dropDB("test");
|
|
||||||
JSONProtocolExample.main(args);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,98 @@
|
||||||
|
const taos = require("@tdengine/websocket");
|
||||||
|
|
||||||
|
let dsn = 'ws://localhost:6041';
|
||||||
|
async function json_tag_example() {
|
||||||
|
let wsSql = null;
|
||||||
|
try {
|
||||||
|
let conf = new taos.WSConfig(dsn);
|
||||||
|
conf.setUser('root');
|
||||||
|
conf.setPwd('taosdata');
|
||||||
|
wsSql = await taos.sqlConnect(conf);
|
||||||
|
console.log("Connected to " + dsn + " successfully.");
|
||||||
|
|
||||||
|
// create database
|
||||||
|
await wsSql.exec('CREATE DATABASE IF NOT EXISTS example_json_tag');
|
||||||
|
console.log("Create database example_json_tag successfully.");
|
||||||
|
|
||||||
|
// create table
|
||||||
|
await wsSql.exec('create table if not exists example_json_tag.stb (ts timestamp, v int) tags(jt json)');
|
||||||
|
|
||||||
|
console.log("Create stable example_json_tag.stb successfully");
|
||||||
|
|
||||||
|
let insertQuery = 'INSERT INTO ' +
|
||||||
|
'example_json_tag.tb1 USING example_json_tag.stb TAGS(\'{"name":"value"}\') ' +
|
||||||
|
"values(now, 1) ";
|
||||||
|
taosResult = await wsSql.exec(insertQuery);
|
||||||
|
console.log("Successfully inserted " + taosResult.getAffectRows() + " rows to example_json_tag.stb.");
|
||||||
|
|
||||||
|
let sql = 'SELECT ts, v, jt FROM example_json_tag.stb limit 100';
|
||||||
|
wsRows = await wsSql.query(sql);
|
||||||
|
while (await wsRows.next()) {
|
||||||
|
let row = wsRows.getData();
|
||||||
|
console.log('ts: ' + row[0] + ', v: ' + row[1] + ', jt: ' + row[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`Failed to create database example_json_tag or stable stb, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||||
|
} finally {
|
||||||
|
if (wsSql) {
|
||||||
|
await wsSql.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async function all_type_example() {
|
||||||
|
let wsSql = null;
|
||||||
|
try {
|
||||||
|
let conf = new taos.WSConfig(dsn);
|
||||||
|
conf.setUser('root');
|
||||||
|
conf.setPwd('taosdata');
|
||||||
|
wsSql = await taos.sqlConnect(conf);
|
||||||
|
console.log("Connected to " + dsn + " successfully.");
|
||||||
|
|
||||||
|
// create database
|
||||||
|
await wsSql.exec('CREATE DATABASE IF NOT EXISTS all_type_example');
|
||||||
|
console.log("Create database all_type_example successfully.");
|
||||||
|
|
||||||
|
// create table
|
||||||
|
await wsSql.exec('create table if not exists all_type_example.stb (ts timestamp, ' +
|
||||||
|
'int_col INT, double_col DOUBLE, bool_col BOOL, binary_col BINARY(100),' +
|
||||||
|
'nchar_col NCHAR(100), varbinary_col VARBINARY(100), geometry_col GEOMETRY(100)) ' +
|
||||||
|
'tags(int_tag INT, double_tag DOUBLE, bool_tag BOOL, binary_tag BINARY(100),' +
|
||||||
|
'nchar_tag NCHAR(100), varbinary_tag VARBINARY(100), geometry_tag GEOMETRY(100));');
|
||||||
|
|
||||||
|
console.log("Create stable all_type_example.stb successfully");
|
||||||
|
|
||||||
|
let insertQuery = "INSERT INTO all_type_example.tb1 using all_type_example.stb "
|
||||||
|
+ "tags(1, 1.1, true, 'binary_value', 'nchar_value', '\\x98f46e', 'POINT(100 100)') "
|
||||||
|
+ "values(now, 1, 1.1, true, 'binary_value', 'nchar_value', '\\x98f46e', 'POINT(100 100)')";
|
||||||
|
taosResult = await wsSql.exec(insertQuery);
|
||||||
|
console.log("Successfully inserted " + taosResult.getAffectRows() + " rows to all_type_example.stb.");
|
||||||
|
|
||||||
|
let sql = 'SELECT * FROM all_type_example.stb limit 100';
|
||||||
|
let wsRows = await wsSql.query(sql);
|
||||||
|
let meta = wsRows.getMeta();
|
||||||
|
console.log("wsRow:meta:=>", meta);
|
||||||
|
while (await wsRows.next()) {
|
||||||
|
let row = wsRows.getData();
|
||||||
|
console.log(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`Failed to create database all_type_example or stable stb, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||||
|
} finally {
|
||||||
|
if (wsSql) {
|
||||||
|
await wsSql.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async function test() {
|
||||||
|
await json_tag_example()
|
||||||
|
await all_type_example()
|
||||||
|
taos.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
test()
|
|
@ -0,0 +1,149 @@
|
||||||
|
const taos = require("@tdengine/websocket");
|
||||||
|
|
||||||
|
|
||||||
|
let dsn = 'ws://localhost:6041';
|
||||||
|
async function json_tag_example() {
|
||||||
|
let wsSql = null;
|
||||||
|
try {
|
||||||
|
let conf = new taos.WSConfig(dsn);
|
||||||
|
conf.setUser('root');
|
||||||
|
conf.setPwd('taosdata');
|
||||||
|
wsSql = await taos.sqlConnect(conf);
|
||||||
|
console.log("Connected to " + dsn + " successfully.");
|
||||||
|
|
||||||
|
// create database
|
||||||
|
await wsSql.exec('CREATE DATABASE IF NOT EXISTS example_json_tag');
|
||||||
|
console.log("Create database example_json_tag successfully.");
|
||||||
|
|
||||||
|
await wsSql.exec('use example_json_tag');
|
||||||
|
|
||||||
|
// create table
|
||||||
|
await wsSql.exec('create table if not exists stb (ts timestamp, v int) tags(jt json)');
|
||||||
|
|
||||||
|
console.log("Create stable example_json_tag.stb successfully");
|
||||||
|
|
||||||
|
let stmt = await wsSql.stmtInit();
|
||||||
|
await stmt.prepare("INSERT INTO ? using stb tags(?) VALUES (?,?)");
|
||||||
|
await stmt.setTableName(`tb1`);
|
||||||
|
let tagParams = stmt.newStmtParam();
|
||||||
|
tagParams.setJson(['{"name":"value"}'])
|
||||||
|
await stmt.setTags(tagParams);
|
||||||
|
let bindParams = stmt.newStmtParam();
|
||||||
|
const currentMillis = new Date().getTime();
|
||||||
|
bindParams.setTimestamp([currentMillis]);
|
||||||
|
bindParams.setInt([1]);
|
||||||
|
await stmt.bind(bindParams);
|
||||||
|
await stmt.batch();
|
||||||
|
await stmt.exec();
|
||||||
|
await stmt.close();
|
||||||
|
|
||||||
|
let sql = 'SELECT ts, v, jt FROM example_json_tag.stb limit 100';
|
||||||
|
wsRows = await wsSql.query(sql);
|
||||||
|
while (await wsRows.next()) {
|
||||||
|
let row = wsRows.getData();
|
||||||
|
console.log('ts: ' + row[0] + ', v: ' + row[1] + ', jt: ' + row[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`Failed to create database example_json_tag or stable stb, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||||
|
} finally {
|
||||||
|
if (wsSql) {
|
||||||
|
await wsSql.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
async function all_type_example() {
|
||||||
|
let wsSql = null;
|
||||||
|
let stmt = null;
|
||||||
|
try {
|
||||||
|
let conf = new taos.WSConfig(dsn);
|
||||||
|
conf.setUser('root');
|
||||||
|
conf.setPwd('taosdata');
|
||||||
|
wsSql = await taos.sqlConnect(conf);
|
||||||
|
console.log("Connected to " + dsn + " successfully.");
|
||||||
|
|
||||||
|
// create database
|
||||||
|
await wsSql.exec('CREATE DATABASE IF NOT EXISTS all_type_example');
|
||||||
|
console.log("Create database all_type_example successfully.");
|
||||||
|
|
||||||
|
await wsSql.exec('use all_type_example');
|
||||||
|
|
||||||
|
// create table
|
||||||
|
await wsSql.exec('create table if not exists stb (ts timestamp, ' +
|
||||||
|
'int_col INT, double_col DOUBLE, bool_col BOOL, binary_col BINARY(100),' +
|
||||||
|
'nchar_col NCHAR(100), varbinary_col VARBINARY(100), geometry_col GEOMETRY(100)) ' +
|
||||||
|
'tags(int_tag INT, double_tag DOUBLE, bool_tag BOOL, binary_tag BINARY(100),' +
|
||||||
|
'nchar_tag NCHAR(100), varbinary_tag VARBINARY(100), geometry_tag GEOMETRY(100));');
|
||||||
|
|
||||||
|
console.log("Create stable all_type_example.stb successfully");
|
||||||
|
|
||||||
|
let geometryData = new Uint8Array([0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||||
|
0x00,0x00,0x00,0x59,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x59,0x40,]).buffer;
|
||||||
|
|
||||||
|
const encoder = new TextEncoder();
|
||||||
|
let vbData = encoder.encode(`Hello, world!`).buffer;
|
||||||
|
|
||||||
|
stmt = await wsSql.stmtInit();
|
||||||
|
await stmt.prepare("INSERT INTO ? using stb tags(?,?,?,?,?,?,?) VALUES (?,?,?,?,?,?,?,?)");
|
||||||
|
await stmt.setTableName(`tb1`);
|
||||||
|
let tagParams = stmt.newStmtParam();
|
||||||
|
tagParams.setInt([1]);
|
||||||
|
tagParams.setDouble([1.1]);
|
||||||
|
tagParams.setBoolean([true]);
|
||||||
|
tagParams.setVarchar(["hello"]);
|
||||||
|
tagParams.setNchar(["stmt"]);
|
||||||
|
tagParams.setGeometry([geometryData]);
|
||||||
|
tagParams.setVarBinary([vbData]);
|
||||||
|
await stmt.setTags(tagParams);
|
||||||
|
|
||||||
|
|
||||||
|
let bindParams = stmt.newStmtParam();
|
||||||
|
const currentMillis = new Date().getTime();
|
||||||
|
bindParams.setTimestamp([currentMillis]);
|
||||||
|
bindParams.setInt([1]);
|
||||||
|
bindParams.setDouble([1.1]);
|
||||||
|
bindParams.setBoolean([true]);
|
||||||
|
bindParams.setVarchar(["hello"]);
|
||||||
|
bindParams.setNchar(["stmt"]);
|
||||||
|
bindParams.setGeometry([geometryData]);
|
||||||
|
bindParams.setVarBinary([vbData]);
|
||||||
|
|
||||||
|
await stmt.bind(bindParams);
|
||||||
|
await stmt.batch();
|
||||||
|
await stmt.exec();
|
||||||
|
|
||||||
|
let sql = 'SELECT * FROM all_type_example.stb limit 100';
|
||||||
|
let wsRows = await wsSql.query(sql);
|
||||||
|
let meta = wsRows.getMeta();
|
||||||
|
console.log("wsRow:meta:=>", meta);
|
||||||
|
while (await wsRows.next()) {
|
||||||
|
let row = wsRows.getData();
|
||||||
|
console.log(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error(`Failed to create database all_type_example or stable stb, ErrCode: ${err.code}, ErrMessage: ${err.message}`);
|
||||||
|
} finally {
|
||||||
|
if (stmt) {
|
||||||
|
await stmt.close();
|
||||||
|
}
|
||||||
|
if (wsSql) {
|
||||||
|
await wsSql.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async function test() {
|
||||||
|
taos.setLevel("debug")
|
||||||
|
await json_tag_example()
|
||||||
|
await all_type_example()
|
||||||
|
taos.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
test()
|
||||||
|
|
|
@ -24,13 +24,18 @@ async function createConnect() {
|
||||||
async function createDbAndTable() {
|
async function createDbAndTable() {
|
||||||
let wsSql = null;
|
let wsSql = null;
|
||||||
try {
|
try {
|
||||||
wsSql = await createConnect();
|
let conf = new taos.WSConfig(dsn);
|
||||||
|
conf.setUser('root');
|
||||||
|
conf.setPwd('taosdata');
|
||||||
|
conf.setDb('power');
|
||||||
|
wsSql = await taos.sqlConnect(conf);
|
||||||
|
console.log("Connected to " + dsn + " successfully.");
|
||||||
// create database
|
// create database
|
||||||
await wsSql.exec('CREATE DATABASE IF NOT EXISTS power');
|
await wsSql.exec('CREATE DATABASE IF NOT EXISTS power');
|
||||||
console.log("Create database power successfully.");
|
console.log("Create database power successfully.");
|
||||||
// create table
|
// create table
|
||||||
await wsSql.exec('CREATE STABLE IF NOT EXISTS power.meters ' +
|
await wsSql.exec('CREATE STABLE IF NOT EXISTS power.meters ' +
|
||||||
'(_ts timestamp, current float, voltage int, phase float) ' +
|
'(ts timestamp, current float, voltage int, phase float) ' +
|
||||||
'TAGS (location binary(64), groupId int);');
|
'TAGS (location binary(64), groupId int);');
|
||||||
|
|
||||||
console.log("Create stable power.meters successfully");
|
console.log("Create stable power.meters successfully");
|
||||||
|
|
|
@ -8,6 +8,7 @@ edition = "2021"
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
serde_json = "1.0"
|
||||||
tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread"] }
|
tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread"] }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
pretty_env_logger = "0.5.0"
|
pretty_env_logger = "0.5.0"
|
||||||
|
|
|
@ -0,0 +1,121 @@
|
||||||
|
use taos::*;
|
||||||
|
use taos_query::util::hex::hex_string_to_bytes;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> anyhow::Result<()> {
|
||||||
|
let dsn = "taos://";
|
||||||
|
let taos = TaosBuilder::from_dsn(dsn)?.build().await?;
|
||||||
|
|
||||||
|
taos.exec("DROP DATABASE IF EXISTS example_all_type_stmt")
|
||||||
|
.await?;
|
||||||
|
taos.create_database("example_all_type_stmt").await?;
|
||||||
|
taos.use_database("example_all_type_stmt").await?;
|
||||||
|
taos.exec(
|
||||||
|
r#"
|
||||||
|
CREATE STABLE IF NOT EXISTS stb (
|
||||||
|
ts TIMESTAMP,
|
||||||
|
int_col INT,
|
||||||
|
double_col DOUBLE,
|
||||||
|
bool_col BOOL,
|
||||||
|
binary_col BINARY(100),
|
||||||
|
nchar_col NCHAR(100),
|
||||||
|
varbinary_col VARBINARY(100),
|
||||||
|
geometry_col GEOMETRY(100))
|
||||||
|
TAGS (
|
||||||
|
int_tag INT,
|
||||||
|
double_tag DOUBLE,
|
||||||
|
bool_tag BOOL,
|
||||||
|
binary_tag BINARY(100),
|
||||||
|
nchar_tag NCHAR(100))
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let mut stmt = Stmt::init(&taos).await?;
|
||||||
|
stmt.prepare("INSERT INTO ? using stb tags(?,?,?,?,?) VALUES (?,?,?,?,?,?,?,?)")
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
const NUM_TABLES: usize = 10;
|
||||||
|
const NUM_ROWS: usize = 10;
|
||||||
|
for i in 0..NUM_TABLES {
|
||||||
|
let table_name = format!("d_bind_{}", i);
|
||||||
|
let tags = vec![
|
||||||
|
Value::Int(i as i32),
|
||||||
|
Value::Double(1.1),
|
||||||
|
Value::Bool(true),
|
||||||
|
Value::VarChar("binary_value".into()),
|
||||||
|
Value::NChar("nchar_value".into()),
|
||||||
|
// Value::VarBinary(vec![0x98, 0xf4, 0x6e].into()),
|
||||||
|
// Value::Geometry(
|
||||||
|
// vec![
|
||||||
|
// 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x40,
|
||||||
|
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x40,
|
||||||
|
// ]
|
||||||
|
// .into(),
|
||||||
|
// ),
|
||||||
|
];
|
||||||
|
|
||||||
|
// set table name and tags for the prepared statement.
|
||||||
|
match stmt.set_tbname_tags(&table_name, &tags).await {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!(
|
||||||
|
"Failed to set table name and tags, table_name:{}, tags:{:?}, ErrMessage: {}",
|
||||||
|
table_name, tags, err
|
||||||
|
);
|
||||||
|
return Err(err.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for j in 0..NUM_ROWS {
|
||||||
|
let values = vec![
|
||||||
|
ColumnView::from_millis_timestamp(vec![1648432611249 + j as i64]),
|
||||||
|
ColumnView::from_ints(vec![j as i32]),
|
||||||
|
ColumnView::from_doubles(vec![1.1]),
|
||||||
|
ColumnView::from_bools(vec![true]),
|
||||||
|
ColumnView::from_varchar(vec!["ABC"]),
|
||||||
|
ColumnView::from_nchar(vec!["涛思数据"]),
|
||||||
|
ColumnView::from_bytes(vec![hex_string_to_bytes("123456").to_vec()]),
|
||||||
|
ColumnView::from_geobytes(vec![hex_string_to_bytes(
|
||||||
|
"0101000000000000000000F03F0000000000000040",
|
||||||
|
)
|
||||||
|
.to_vec()]),
|
||||||
|
];
|
||||||
|
// bind values to the prepared statement.
|
||||||
|
match stmt.bind(&values).await {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!(
|
||||||
|
"Failed to bind values, values:{:?}, ErrMessage: {}",
|
||||||
|
values, err
|
||||||
|
);
|
||||||
|
return Err(err.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match stmt.add_batch().await {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Failed to add batch, ErrMessage: {}", err);
|
||||||
|
return Err(err.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// execute.
|
||||||
|
match stmt.execute().await {
|
||||||
|
Ok(affected_rows) => println!(
|
||||||
|
"Successfully inserted {} rows to example_all_type_stmt.stb.",
|
||||||
|
affected_rows
|
||||||
|
),
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!(
|
||||||
|
"Failed to insert to table stb using stmt, ErrMessage: {}",
|
||||||
|
err
|
||||||
|
);
|
||||||
|
return Err(err.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -0,0 +1,94 @@
|
||||||
|
use serde_json::json;
|
||||||
|
use taos::*;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> anyhow::Result<()> {
|
||||||
|
let dsn = "taos://";
|
||||||
|
let taos = TaosBuilder::from_dsn(dsn)?.build().await?;
|
||||||
|
|
||||||
|
taos.exec("DROP DATABASE IF EXISTS example_all_type_stmt")
|
||||||
|
.await?;
|
||||||
|
taos.create_database("example_all_type_stmt").await?;
|
||||||
|
taos.use_database("example_all_type_stmt").await?;
|
||||||
|
taos.exec(
|
||||||
|
r#"
|
||||||
|
CREATE STABLE IF NOT EXISTS stb_json (
|
||||||
|
ts TIMESTAMP,
|
||||||
|
int_col INT)
|
||||||
|
TAGS (
|
||||||
|
json_tag JSON)
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let mut stmt = Stmt::init(&taos).await?;
|
||||||
|
stmt.prepare("INSERT INTO ? using stb_json tags(?) VALUES (?,?)")
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
const NUM_TABLES: usize = 1;
|
||||||
|
const NUM_ROWS: usize = 1;
|
||||||
|
for i in 0..NUM_TABLES {
|
||||||
|
let table_name = format!("d_bind_{}", i);
|
||||||
|
let json_value: serde_json::Value = json!({
|
||||||
|
"name": "value"
|
||||||
|
});
|
||||||
|
|
||||||
|
dbg!(json_value.to_string());
|
||||||
|
|
||||||
|
let tags = vec![Value::Json(json_value)];
|
||||||
|
|
||||||
|
// set table name and tags for the prepared statement.
|
||||||
|
match stmt.set_tbname_tags(&table_name, &tags).await {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!(
|
||||||
|
"Failed to set table name and tags, table_name:{}, tags:{:?}, ErrMessage: {}",
|
||||||
|
table_name, tags, err
|
||||||
|
);
|
||||||
|
return Err(err.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for j in 0..NUM_ROWS {
|
||||||
|
let values = vec![
|
||||||
|
ColumnView::from_millis_timestamp(vec![1648432611249 + j as i64]),
|
||||||
|
ColumnView::from_ints(vec![j as i32]),
|
||||||
|
];
|
||||||
|
// bind values to the prepared statement.
|
||||||
|
match stmt.bind(&values).await {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!(
|
||||||
|
"Failed to bind values, values:{:?}, ErrMessage: {}",
|
||||||
|
values, err
|
||||||
|
);
|
||||||
|
return Err(err.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match stmt.add_batch().await {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Failed to add batch, ErrMessage: {}", err);
|
||||||
|
return Err(err.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// execute.
|
||||||
|
match stmt.execute().await {
|
||||||
|
Ok(affected_rows) => println!(
|
||||||
|
"Successfully inserted {} rows to example_all_type_stmt.stb_json.",
|
||||||
|
affected_rows
|
||||||
|
),
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!(
|
||||||
|
"Failed to insert to table stb_json using stmt, ErrMessage: {}",
|
||||||
|
err
|
||||||
|
);
|
||||||
|
return Err(err.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -0,0 +1,121 @@
|
||||||
|
use taos::*;
|
||||||
|
use taos_query::util::hex::hex_string_to_bytes;
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> anyhow::Result<()> {
|
||||||
|
let dsn = "ws://";
|
||||||
|
let taos = TaosBuilder::from_dsn(dsn)?.build().await?;
|
||||||
|
|
||||||
|
taos.exec("DROP DATABASE IF EXISTS example_all_type_stmt")
|
||||||
|
.await?;
|
||||||
|
taos.create_database("example_all_type_stmt").await?;
|
||||||
|
taos.use_database("example_all_type_stmt").await?;
|
||||||
|
taos.exec(
|
||||||
|
r#"
|
||||||
|
CREATE STABLE IF NOT EXISTS stb (
|
||||||
|
ts TIMESTAMP,
|
||||||
|
int_col INT,
|
||||||
|
double_col DOUBLE,
|
||||||
|
bool_col BOOL,
|
||||||
|
binary_col BINARY(100),
|
||||||
|
nchar_col NCHAR(100),
|
||||||
|
varbinary_col VARBINARY(100),
|
||||||
|
geometry_col GEOMETRY(100))
|
||||||
|
TAGS (
|
||||||
|
int_tag INT,
|
||||||
|
double_tag DOUBLE,
|
||||||
|
bool_tag BOOL,
|
||||||
|
binary_tag BINARY(100),
|
||||||
|
nchar_tag NCHAR(100))
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let mut stmt = Stmt::init(&taos).await?;
|
||||||
|
stmt.prepare("INSERT INTO ? using stb tags(?,?,?,?,?) VALUES (?,?,?,?,?,?,?,?)")
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
const NUM_TABLES: usize = 10;
|
||||||
|
const NUM_ROWS: usize = 10;
|
||||||
|
for i in 0..NUM_TABLES {
|
||||||
|
let table_name = format!("d_bind_{}", i);
|
||||||
|
let tags = vec![
|
||||||
|
Value::Int(i as i32),
|
||||||
|
Value::Double(1.1),
|
||||||
|
Value::Bool(true),
|
||||||
|
Value::VarChar("binary_value".into()),
|
||||||
|
Value::NChar("nchar_value".into()),
|
||||||
|
// Value::VarBinary(vec![0x98, 0xf4, 0x6e].into()),
|
||||||
|
// Value::Geometry(
|
||||||
|
// vec![
|
||||||
|
// 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x40,
|
||||||
|
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x40,
|
||||||
|
// ]
|
||||||
|
// .into(),
|
||||||
|
// ),
|
||||||
|
];
|
||||||
|
|
||||||
|
// set table name and tags for the prepared statement.
|
||||||
|
match stmt.set_tbname_tags(&table_name, &tags).await {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!(
|
||||||
|
"Failed to set table name and tags, table_name:{}, tags:{:?}, ErrMessage: {}",
|
||||||
|
table_name, tags, err
|
||||||
|
);
|
||||||
|
return Err(err.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for j in 0..NUM_ROWS {
|
||||||
|
let values = vec![
|
||||||
|
ColumnView::from_millis_timestamp(vec![1648432611249 + j as i64]),
|
||||||
|
ColumnView::from_ints(vec![j as i32]),
|
||||||
|
ColumnView::from_doubles(vec![1.1]),
|
||||||
|
ColumnView::from_bools(vec![true]),
|
||||||
|
ColumnView::from_varchar(vec!["ABC"]),
|
||||||
|
ColumnView::from_nchar(vec!["涛思数据"]),
|
||||||
|
ColumnView::from_bytes(vec![hex_string_to_bytes("123456").to_vec()]),
|
||||||
|
ColumnView::from_geobytes(vec![hex_string_to_bytes(
|
||||||
|
"0101000000000000000000F03F0000000000000040",
|
||||||
|
)
|
||||||
|
.to_vec()]),
|
||||||
|
];
|
||||||
|
// bind values to the prepared statement.
|
||||||
|
match stmt.bind(&values).await {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!(
|
||||||
|
"Failed to bind values, values:{:?}, ErrMessage: {}",
|
||||||
|
values, err
|
||||||
|
);
|
||||||
|
return Err(err.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
match stmt.add_batch().await {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Failed to add batch, ErrMessage: {}", err);
|
||||||
|
return Err(err.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// execute.
|
||||||
|
match stmt.execute().await {
|
||||||
|
Ok(affected_rows) => println!(
|
||||||
|
"Successfully inserted {} rows to example_all_type_stmt.stb.",
|
||||||
|
affected_rows
|
||||||
|
),
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!(
|
||||||
|
"Failed to insert to table stb using stmt, ErrMessage: {}",
|
||||||
|
err
|
||||||
|
);
|
||||||
|
return Err(err.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
|
@ -72,15 +72,30 @@ TDengine 可以通过 MQTT 连接器从 MQTT 代理订阅数据并将其写入 T
|
||||||
|
|
||||||
taosX 可以使用 JSON 提取器解析数据,并允许用户在数据库中指定数据模型,包括,指定表名称和超级表名,设置普通列和标签列等。
|
taosX 可以使用 JSON 提取器解析数据,并允许用户在数据库中指定数据模型,包括,指定表名称和超级表名,设置普通列和标签列等。
|
||||||
|
|
||||||
|
|
||||||
#### 6.1 解析
|
#### 6.1 解析
|
||||||
|
|
||||||
有三种获取示例数据的方法:
|
有三种获取示例数据的方法:
|
||||||
|
|
||||||
点击 **从服务器检索** 按钮,从 MQTT 获取示例数据。
|
点击 **从服务器检索** 按钮,从 MQTT 获取示例数据。
|
||||||
|
|
||||||
点击 **文件上传** 按钮,上传 CSV 文件,获取示例数据。
|
点击 **文件上传** 按钮,上传 CSV 文件,获取示例数据。
|
||||||
|
|
||||||
在 **消息体** 中填写 MQTT 消息体中的示例数据,例如:`{"id": 1, "message": "hello-word"}{"id": 2, "message": "hello-word"}`。之后会使用这条示例数据来配置提取和过滤条件。
|
在 **消息体** 中填写 MQTT 消息体中的示例数据。
|
||||||
|
|
||||||
|
json 数据支持 JSONObject 或者 JSONArray,使用 json 解析器可以解析一下数据:
|
||||||
|
|
||||||
|
``` json
|
||||||
|
{"id": 1, "message": "hello-word"}
|
||||||
|
{"id": 2, "message": "hello-word"}
|
||||||
|
```
|
||||||
|
|
||||||
|
或者
|
||||||
|
|
||||||
|
``` json
|
||||||
|
[{"id": 1, "message": "hello-word"},{"id": 2, "message": "hello-word"}]
|
||||||
|
```
|
||||||
|
|
||||||
|
解析结果如下所示:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
|
@ -80,13 +80,29 @@ TDengine 可以高效地从 Kafka 读取数据并将其写入 TDengine,以实
|
||||||
在 **Payload 解析** 区域填写 Payload 解析相关的配置参数。
|
在 **Payload 解析** 区域填写 Payload 解析相关的配置参数。
|
||||||
|
|
||||||
#### 7.1 解析
|
#### 7.1 解析
|
||||||
|
|
||||||
有三种获取示例数据的方法:
|
有三种获取示例数据的方法:
|
||||||
|
|
||||||
点击 **从服务器检索** 按钮,从 Kafka 获取示例数据。
|
点击 **从服务器检索** 按钮,从 Kafka 获取示例数据。
|
||||||
|
|
||||||
点击 **文件上传** 按钮,上传 CSV 文件,获取示例数据。
|
点击 **文件上传** 按钮,上传 CSV 文件,获取示例数据。
|
||||||
|
|
||||||
在 **消息体** 中填写 Kafka 消息体中的示例数据,例如:`{"id": 1, "message": "hello-word"}{"id": 2, "message": "hello-word"}`。之后会使用这条示例数据来配置提取和过滤条件。
|
在 **消息体** 中填写 Kafka 消息体中的示例数据。
|
||||||
|
|
||||||
|
json 数据支持 JSONObject 或者 JSONArray,使用 json 解析器可以解析一下数据:
|
||||||
|
|
||||||
|
``` json
|
||||||
|
{"id": 1, "message": "hello-word"}
|
||||||
|
{"id": 2, "message": "hello-word"}
|
||||||
|
```
|
||||||
|
|
||||||
|
或者
|
||||||
|
|
||||||
|
``` json
|
||||||
|
[{"id": 1, "message": "hello-word"},{"id": 2, "message": "hello-word"}]
|
||||||
|
```
|
||||||
|
|
||||||
|
解析结果如下所示:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ InfluxDB 是一种流行的开源时间序列数据库,它针对处理大量
|
||||||
|
|
||||||
在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示:
|
在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### 2. 配置基本信息
|
### 2. 配置基本信息
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ OpenTSDB 是一个架构在 HBase 系统之上的实时监控信息收集和展
|
||||||
|
|
||||||
在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示:
|
在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### 2. 配置基本信息
|
### 2. 配置基本信息
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ MySQL 是最流行的关系型数据库之一。很多系统都曾经或正在
|
||||||
|
|
||||||
在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示:
|
在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### 2. 配置基本信息
|
### 2. 配置基本信息
|
||||||
|
|
||||||
|
@ -56,11 +56,19 @@ MySQL 是最流行的关系型数据库之一。很多系统都曾经或正在
|
||||||
|
|
||||||
### 6. 配置 SQL 查询
|
### 6. 配置 SQL 查询
|
||||||
|
|
||||||
|
**子表字段** 用于拆分子表的字段,它是一条 select distinct 的 SQL 语句,查询指定字段组合的非重复项,通常与 transform 中的 tag 相对应:
|
||||||
|
> 此项配置主要为了解决数据迁移乱序问题,需要结合**SQL 模板**共同使用,否则不能达到预期效果,使用示例如下:
|
||||||
|
> 1. 子表字段填写语句 `select distinct col_name1, col_name2 from table`,它表示使用源表中的字段 col_name1 与 col_name2 拆分目标超级表的子表
|
||||||
|
> 2. 在**SQL 模板**中添加子表字段占位符,例如 `select * from table where ts >= ${start} and ts < ${end} and ${col_name1} and ${col_name2}` 中的 `${col_name1} and ${col_name2}` 部分
|
||||||
|
> 3. 在 **transform** 中配置 `col_name1` 与 `col_name2` 两个 tag 映射
|
||||||
|
|
||||||
**SQL 模板** 用于查询的 SQL 语句模板,SQL 语句中必须包含时间范围条件,且开始时间和结束时间必须成对出现。SQL 语句模板中定义的时间范围由源数据库中的某个代表时间的列和下面定义的占位符组成。
|
**SQL 模板** 用于查询的 SQL 语句模板,SQL 语句中必须包含时间范围条件,且开始时间和结束时间必须成对出现。SQL 语句模板中定义的时间范围由源数据库中的某个代表时间的列和下面定义的占位符组成。
|
||||||
> SQL使用不同的占位符表示不同的时间格式要求,具体有以下占位符格式:
|
> SQL使用不同的占位符表示不同的时间格式要求,具体有以下占位符格式:
|
||||||
> 1. `${start}`、`${end}`:表示 RFC3339 格式时间戳,如: 2024-03-14T08:00:00+0800
|
> 1. `${start}`、`${end}`:表示 RFC3339 格式时间戳,如: 2024-03-14T08:00:00+0800
|
||||||
> 2. `${start_no_tz}`、`${end_no_tz}`: 表示不带时区的 RFC3339 字符串:2024-03-14T08:00:00
|
> 2. `${start_no_tz}`、`${end_no_tz}`: 表示不带时区的 RFC3339 字符串:2024-03-14T08:00:00
|
||||||
> 3. `${start_date}`、`${end_date}`:表示仅日期,如:2024-03-14
|
> 3. `${start_date}`、`${end_date}`:表示仅日期,如:2024-03-14
|
||||||
|
>
|
||||||
|
> 为了解决迁移数据乱序的问题,应在查询语句中添加排序条件,例如 `order by ts asc`。
|
||||||
|
|
||||||
**起始时间** 迁移数据的起始时间,此项为必填字段。
|
**起始时间** 迁移数据的起始时间,此项为必填字段。
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ TDengine 可以高效地从 PostgreSQL 读取数据并将其写入 TDengine,
|
||||||
|
|
||||||
在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示:
|
在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### 2. 配置基本信息
|
### 2. 配置基本信息
|
||||||
|
|
||||||
|
@ -57,11 +57,19 @@ TDengine 可以高效地从 PostgreSQL 读取数据并将其写入 TDengine,
|
||||||
|
|
||||||
### 6. 配置 SQL 查询
|
### 6. 配置 SQL 查询
|
||||||
|
|
||||||
|
**子表字段** 用于拆分子表的字段,它是一条 select distinct 的 SQL 语句,查询指定字段组合的非重复项,通常与 transform 中的 tag 相对应:
|
||||||
|
> 此项配置主要为了解决数据迁移乱序问题,需要结合**SQL 模板**共同使用,否则不能达到预期效果,使用示例如下:
|
||||||
|
> 1. 子表字段填写语句 `select distinct col_name1, col_name2 from table`,它表示使用源表中的字段 col_name1 与 col_name2 拆分目标超级表的子表
|
||||||
|
> 2. 在**SQL 模板**中添加子表字段占位符,例如 `select * from table where ts >= ${start} and ts < ${end} and ${col_name1} and ${col_name2}` 中的 `${col_name1} and ${col_name2}` 部分
|
||||||
|
> 3. 在 **transform** 中配置 `col_name1` 与 `col_name2` 两个 tag 映射
|
||||||
|
|
||||||
**SQL 模板** 用于查询的 SQL 语句模板,SQL 语句中必须包含时间范围条件,且开始时间和结束时间必须成对出现。SQL 语句模板中定义的时间范围由源数据库中的某个代表时间的列和下面定义的占位符组成。
|
**SQL 模板** 用于查询的 SQL 语句模板,SQL 语句中必须包含时间范围条件,且开始时间和结束时间必须成对出现。SQL 语句模板中定义的时间范围由源数据库中的某个代表时间的列和下面定义的占位符组成。
|
||||||
> SQL使用不同的占位符表示不同的时间格式要求,具体有以下占位符格式:
|
> SQL使用不同的占位符表示不同的时间格式要求,具体有以下占位符格式:
|
||||||
> 1. `${start}`、`${end}`:表示 RFC3339 格式时间戳,如: 2024-03-14T08:00:00+0800
|
> 1. `${start}`、`${end}`:表示 RFC3339 格式时间戳,如: 2024-03-14T08:00:00+0800
|
||||||
> 2. `${start_no_tz}`、`${end_no_tz}`: 表示不带时区的 RFC3339 字符串:2024-03-14T08:00:00
|
> 2. `${start_no_tz}`、`${end_no_tz}`: 表示不带时区的 RFC3339 字符串:2024-03-14T08:00:00
|
||||||
> 3. `${start_date}`、`${end_date}`:表示仅日期,如:2024-03-14
|
> 3. `${start_date}`、`${end_date}`:表示仅日期,如:2024-03-14
|
||||||
|
>
|
||||||
|
> 为了解决迁移数据乱序的问题,应在查询语句中添加排序条件,例如 `order by ts asc`。
|
||||||
|
|
||||||
**起始时间** 迁移数据的起始时间,此项为必填字段。
|
**起始时间** 迁移数据的起始时间,此项为必填字段。
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ TDengine 可以高效地从 Oracle 读取数据并将其写入 TDengine,以实
|
||||||
|
|
||||||
在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示:
|
在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### 2. 配置基本信息
|
### 2. 配置基本信息
|
||||||
|
|
||||||
|
@ -49,11 +49,19 @@ TDengine 可以高效地从 Oracle 读取数据并将其写入 TDengine,以实
|
||||||
|
|
||||||
### 5. 配置 SQL 查询
|
### 5. 配置 SQL 查询
|
||||||
|
|
||||||
|
**子表字段** 用于拆分子表的字段,它是一条 select distinct 的 SQL 语句,查询指定字段组合的非重复项,通常与 transform 中的 tag 相对应:
|
||||||
|
> 此项配置主要为了解决数据迁移乱序问题,需要结合**SQL 模板**共同使用,否则不能达到预期效果,使用示例如下:
|
||||||
|
> 1. 子表字段填写语句 `select distinct col_name1, col_name2 from table`,它表示使用源表中的字段 col_name1 与 col_name2 拆分目标超级表的子表
|
||||||
|
> 2. 在**SQL 模板**中添加子表字段占位符,例如 `select * from table where ts >= ${start} and ts < ${end} and ${col_name1} and ${col_name2}` 中的 `${col_name1} and ${col_name2}` 部分
|
||||||
|
> 3. 在 **transform** 中配置 `col_name1` 与 `col_name2` 两个 tag 映射
|
||||||
|
|
||||||
**SQL 模板** 用于查询的 SQL 语句模板,SQL 语句中必须包含时间范围条件,且开始时间和结束时间必须成对出现。SQL 语句模板中定义的时间范围由源数据库中的某个代表时间的列和下面定义的占位符组成。
|
**SQL 模板** 用于查询的 SQL 语句模板,SQL 语句中必须包含时间范围条件,且开始时间和结束时间必须成对出现。SQL 语句模板中定义的时间范围由源数据库中的某个代表时间的列和下面定义的占位符组成。
|
||||||
> SQL使用不同的占位符表示不同的时间格式要求,具体有以下占位符格式:
|
> SQL使用不同的占位符表示不同的时间格式要求,具体有以下占位符格式:
|
||||||
> 1. `${start}`、`${end}`:表示 RFC3339 格式时间戳,如: 2024-03-14T08:00:00+0800
|
> 1. `${start}`、`${end}`:表示 RFC3339 格式时间戳,如: 2024-03-14T08:00:00+0800
|
||||||
> 2. `${start_no_tz}`、`${end_no_tz}`: 表示不带时区的 RFC3339 字符串:2024-03-14T08:00:00
|
> 2. `${start_no_tz}`、`${end_no_tz}`: 表示不带时区的 RFC3339 字符串:2024-03-14T08:00:00
|
||||||
> 3. `${start_date}`、`${end_date}`:表示仅日期,但 Oracle 中没有纯日期类型,所以它会带零时零分零秒,如:2024-03-14 00:00:00,所以使用 `date <= ${end_date}` 时需要注意,它不能包含 2024-03-14 当天数据
|
> 3. `${start_date}`、`${end_date}`:表示仅日期,但 Oracle 中没有纯日期类型,所以它会带零时零分零秒,如:2024-03-14 00:00:00,所以使用 `date <= ${end_date}` 时需要注意,它不能包含 2024-03-14 当天数据
|
||||||
|
>
|
||||||
|
> 为了解决迁移数据乱序的问题,应在查询语句中添加排序条件,例如 `order by ts asc`。
|
||||||
|
|
||||||
**起始时间** 迁移数据的起始时间,此项为必填字段。
|
**起始时间** 迁移数据的起始时间,此项为必填字段。
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ Microsoft SQL Server 是最流行的关系型数据库之一。很多系统都
|
||||||
|
|
||||||
在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示:
|
在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
### 2. 配置基本信息
|
### 2. 配置基本信息
|
||||||
|
|
||||||
|
@ -61,6 +61,12 @@ Microsoft SQL Server 是最流行的关系型数据库之一。很多系统都
|
||||||
|
|
||||||
### 6. 配置 SQL 查询
|
### 6. 配置 SQL 查询
|
||||||
|
|
||||||
|
**子表字段** 用于拆分子表的字段,它是一条 select distinct 的 SQL 语句,查询指定字段组合的非重复项,通常与 transform 中的 tag 相对应:
|
||||||
|
> 此项配置主要为了解决数据迁移乱序问题,需要结合**SQL 模板**共同使用,否则不能达到预期效果,使用示例如下:
|
||||||
|
> 1. 子表字段填写语句 `select distinct col_name1, col_name2 from table`,它表示使用源表中的字段 col_name1 与 col_name2 拆分目标超级表的子表
|
||||||
|
> 2. 在**SQL 模板**中添加子表字段占位符,例如 `select * from table where ts >= ${start} and ts < ${end} and ${col_name1} and ${col_name2}` 中的 `${col_name1} and ${col_name2}` 部分
|
||||||
|
> 3. 在 **transform** 中配置 `col_name1` 与 `col_name2` 两个 tag 映射
|
||||||
|
|
||||||
**SQL 模板** 用于查询的 SQL 语句模板,SQL 语句中必须包含时间范围条件,且开始时间和结束时间必须成对出现。SQL 语句模板中定义的时间范围由源数据库中的某个代表时间的列和下面定义的占位符组成。
|
**SQL 模板** 用于查询的 SQL 语句模板,SQL 语句中必须包含时间范围条件,且开始时间和结束时间必须成对出现。SQL 语句模板中定义的时间范围由源数据库中的某个代表时间的列和下面定义的占位符组成。
|
||||||
> SQL使用不同的占位符表示不同的时间格式要求,具体有以下占位符格式:
|
> SQL使用不同的占位符表示不同的时间格式要求,具体有以下占位符格式:
|
||||||
> 1. `${start}`、`${end}`:表示 RFC3339 格式时间戳,如: 2024-03-14T08:00:00+0800
|
> 1. `${start}`、`${end}`:表示 RFC3339 格式时间戳,如: 2024-03-14T08:00:00+0800
|
||||||
|
@ -68,6 +74,8 @@ Microsoft SQL Server 是最流行的关系型数据库之一。很多系统都
|
||||||
> 3. `${start_date}`、`${end_date}`:表示仅日期,如:2024-03-14
|
> 3. `${start_date}`、`${end_date}`:表示仅日期,如:2024-03-14
|
||||||
>
|
>
|
||||||
> 注意:只有 `datetime2` 与 `datetimeoffset` 支持使用 start/end 查询,`datetime` 与 `smalldatetime` 只能使用 start_no_tz/end_no_tz 查询,而 `timestamp` 不能用作查询条件。
|
> 注意:只有 `datetime2` 与 `datetimeoffset` 支持使用 start/end 查询,`datetime` 与 `smalldatetime` 只能使用 start_no_tz/end_no_tz 查询,而 `timestamp` 不能用作查询条件。
|
||||||
|
>
|
||||||
|
> 为了解决迁移数据乱序的问题,应在查询语句中添加排序条件,例如 `order by ts asc`。
|
||||||
|
|
||||||
**起始时间** 迁移数据的起始时间,此项为必填字段。
|
**起始时间** 迁移数据的起始时间,此项为必填字段。
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,135 @@
|
||||||
|
---
|
||||||
|
title: "MongoDB"
|
||||||
|
sidebar_label: "MongoDB"
|
||||||
|
---
|
||||||
|
|
||||||
|
本节讲述如何通过 Explorer 界面创建数据迁移任务,从 MongoDB 迁移数据到当前 TDengine 集群。
|
||||||
|
|
||||||
|
## 功能概述
|
||||||
|
|
||||||
|
MongoDB 是一个介于关系型数据库与非关系型数据库之间的产品,被广泛应用于内容管理系统、移动应用与物联网等众多领域。从 TDengine 企业版 3.3.3.0 开始,TDengine 可以高效地从 MongoDB 读取数据并将其写入 TDengine,以实现历史数据迁移或实时数据同步,解决业务面临的技术痛点。
|
||||||
|
|
||||||
|
## 创建任务
|
||||||
|
|
||||||
|
### 1. 新增数据源
|
||||||
|
|
||||||
|
在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 2. 配置基本信息
|
||||||
|
|
||||||
|
在 **名称** 字段中输入任务名称,例如 `test_mongodb_01` 。
|
||||||
|
|
||||||
|
选择 **类型** 下拉框中的 `MongoDB` ,如下图所示(选择完成后页面中的字段会发生变化)。
|
||||||
|
|
||||||
|
**代理** 是非必填项,如有需要,可以在下拉框中选择指定的代理,也可以先点击右侧的 **+创建新的代理** 按钮创建一个新的代理。
|
||||||
|
|
||||||
|
**目标数据库** 是必填项,可以在下拉框中选择指定的数据库,也可以先点击右侧的 **+创建数据库** 按钮创建一个新的数据库。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 3. 配置连接信息
|
||||||
|
|
||||||
|
在 **连接配置** 区域填写 *`源 MongoDB 数据库的连接信息`*,如下图所示:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 4. 配置认证信息
|
||||||
|
|
||||||
|
**用户** 输入源 MongoDB 数据库的用户,该用户必须在 MongoDB 系统中拥有读取权限。
|
||||||
|
|
||||||
|
**密码** 输入源 MongoDB 数据库中上方用户的登陆密码。
|
||||||
|
|
||||||
|
**认证数据库** MongoDB 中存储用户信息的数据库,默认为 admin。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 5. 配置连接选项
|
||||||
|
|
||||||
|
**应用名称** 设置应用程序名称,用于标识连接的应用程序。
|
||||||
|
|
||||||
|
**SSL 证书** 设置是否使用加密连接,默认关闭,如果开启,需要上传以下两个文件:
|
||||||
|
|
||||||
|
  1. **CA 文件** 上传 SSL 加密的证书授权文件。
|
||||||
|
|
||||||
|
  2. **证书文件** 上传 SSL 加密的证书文件。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
然后点击 **检查连通性** 按钮,用户可以点击此按钮检查上方填写的信息是否可以正常获取源 MongoDB 数据库的数据。
|
||||||
|
|
||||||
|
### 6. 配置数据查询
|
||||||
|
|
||||||
|
**数据库** MongoDB 中源数据库,可以使用占位符进行动态配置,例如 `database_${Y}`,可用占位符列表见下方表格。
|
||||||
|
|
||||||
|
**集合** MongoDB 中集合,可以使用占位符进行动态配置,例如 `collection_${md}`,可用占位符列表见下方表格。
|
||||||
|
|
||||||
|
|占位符|描述|示例数据|
|
||||||
|
| :-----: | :------------: |:--------:|
|
||||||
|
|Y|完整的公历年表示,零填充的 4 位整数|2024|
|
||||||
|
|y|公历年除以 100,零填充的 2 位整数|24|
|
||||||
|
|M|整数月份(1 - 12)|1|
|
||||||
|
|m|整数月份(01 - 12)|01|
|
||||||
|
|B|月份英文全拼|January|
|
||||||
|
|b|月份英文的缩写(3 个字母)|Jan|
|
||||||
|
|D|日期的数字表示(1 - 31)|1|
|
||||||
|
|d|日期的数字表示(01 - 31)|01|
|
||||||
|
|J|一年中的第几天(1 - 366)|1|
|
||||||
|
|j|一年中的第几天(001 - 366)|001|
|
||||||
|
|F|相当于 `${Y}-${m}-${d}`|2024-01-01|
|
||||||
|
|
||||||
|
**子表字段** 用于拆分子表的字段,通常与 transform 中的 tag 相对应,多个字段使用英文逗号分隔,例如 col_name1,col_name2。
|
||||||
|
此项配置主要为了解决数据迁移乱序问题,需要结合**查询模板**共同使用,否则不能达到预期效果,使用示例如下:
|
||||||
|
1. 配置两个子表字段 `col_name1,col_name2`
|
||||||
|
2. 在**查询模板**中添加子表字段占位符,例如 `{"ddate":{"$gte":${start_datetime},"$lt":${end_datetime}}, ${col_name1}, ${col_name2}}` 中的 `${col_name1}, ${col_name2}` 部分
|
||||||
|
3. 在 **transform** 中配置 `col_name1` 与 `col_name2` 两个 tag 映射
|
||||||
|
|
||||||
|
**查询模板** 用于查询数据的查询语句,JSON格式,语句中必须包含时间范围条件,且开始时间和结束时间必须成对出现。模板中定义的时间范围由源数据库中的某个代表时间的列和下面定义的占位符组成。
|
||||||
|
使用不同的占位符表示不同的时间格式要求,具体有以下占位符格式:
|
||||||
|
1. `${start_datetime}`、`${end_datetime}`:对应后端 datetime 类型字段的筛选,如:`{"ddate":{"$gte":${start_datetime},"$lt":${end_datetime}}}` 将被转换为 `{"ddate":{"$gte":{"$date":"2024-06-01T00:00:00+00:00"},"$lt":{"$date":"2024-07-01T00:00:00+00:00"}}}`
|
||||||
|
2. `${start_timestamp}`、`${end_timestamp}`: 对应后端 timestamp 类型字段的筛选,如:`{"ttime":{"$gte":${start_timestamp},"$lt":${end_timestamp}}}` 将被转换为 `{"ttime":{"$gte":{"$timestamp":{"t":123,"i":456}},"$lt":{"$timestamp":{"t":123,"i":456}}}}`
|
||||||
|
|
||||||
|
**查询排序** 执行查询时的排序条件,JSON格式,它必须符合 MongoDB 排序条件的格式规范,使用示例如下:
|
||||||
|
1. `{"createtime":1}`:MongoDB 查询结果按 createtime 正序返回。
|
||||||
|
2. `{"createdate":1, "createtime":1}`:MongoDB 查询结果按 createdate 正序、createtime 正序返回。
|
||||||
|
|
||||||
|
**起始时间** 迁移数据的起始时间,此项为必填字段。
|
||||||
|
|
||||||
|
**结束时间** 迁移数据的结束时间,可留空。如果设置,则迁移任务执行到结束时间后,任务完成自动停止;如果留空,则持续同步实时数据,任务不会自动停止。
|
||||||
|
|
||||||
|
**查询间隔** 分段查询数据的时间间隔,默认1天。为了避免查询数据量过大,一次数据同步子任务会使用查询间隔分时间段查询数据。
|
||||||
|
|
||||||
|
**延迟时长** 实时同步数据场景中,为了避免延迟写入的数据丢失,每次同步任务会读取延迟时长之前的数据。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 7. 配置数据映射
|
||||||
|
|
||||||
|
在 **Payload 转换** 区域填写数据映射相关的配置参数。
|
||||||
|
|
||||||
|
点击 **从服务器检索** 按钮,从 MongoDB 服务器获取示例数据。
|
||||||
|
|
||||||
|
在 **解析** 中选择 JSON/Regex/UDT 三种规则解析原始消息体,配置完成后点击右侧的 **预览** 按钮可以查看解析的结果。
|
||||||
|
|
||||||
|
在 **从列中提取或拆分** 中填写从消息体中提取或拆分的字段,例如:将 vValue 字段拆分成 `vValue_0` 和 `vValue_1` 这 2 个字段,选择 split 提取器,seperator 填写分割符 `,`, number 填写 2,配置完成后点击右侧的 **预览** 按钮可以查看转换的结果。
|
||||||
|
|
||||||
|
在 **过滤** 中,填写过滤条件,例如:填写 `Value > 0`,则只有 Value 大于 0 的数据才会被写入 TDengine,配置完成后点击右侧的 **预览** 按钮可以查看过滤的结果。
|
||||||
|
|
||||||
|
在 **映射** 中,选择要映射到 TDengine 的超级表,以及映射到超级表的列,配置完成后点击右侧的 **预览** 按钮可以查看映射的结果。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 8. 配置高级选项
|
||||||
|
|
||||||
|
**高级选项** 区域是默认折叠的,点击右侧 `>` 可以展开,如下图所示:
|
||||||
|
|
||||||
|
**最大读取并发数** 数据源连接数或读取线程数限制,当默认参数不满足需要或需要调整资源使用量时修改此参数。
|
||||||
|
|
||||||
|
**批次大小** 单次发送的最大消息数或行数。默认是 10000。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 9. 创建完成
|
||||||
|
|
||||||
|
点击 **提交** 按钮,完成创建 MongoDB 到 TDengine 的数据同步任务,回到**数据源列表**页面可查看任务执行情况。
|
|
@ -38,7 +38,6 @@ TDengine Enterprise 配备了一个强大的可视化数据管理工具—taosEx
|
||||||
|
|
||||||
下面详细讲解数据转换规则
|
下面详细讲解数据转换规则
|
||||||
|
|
||||||
|
|
||||||
### 解析
|
### 解析
|
||||||
|
|
||||||
仅非结构化的数据源需要这个步骤,目前 MQTT 和 Kafka 数据源会使用这个步骤提供的规则来解析非结构化数据,以初步获取结构化数据,即可以以字段描述的行列数据。在 explorer 中您需要提供示例数据和解析规则,来预览解析出以表格呈现的结构化数据。
|
仅非结构化的数据源需要这个步骤,目前 MQTT 和 Kafka 数据源会使用这个步骤提供的规则来解析非结构化数据,以初步获取结构化数据,即可以以字段描述的行列数据。在 explorer 中您需要提供示例数据和解析规则,来预览解析出以表格呈现的结构化数据。
|
||||||
|
@ -53,13 +52,15 @@ TDengine Enterprise 配备了一个强大的可视化数据管理工具—taosEx
|
||||||
2. 点击右侧按钮 “从服务器检索” 则从配置的服务器获取示例数据,并追加到示例数据 textarea 中;
|
2. 点击右侧按钮 “从服务器检索” 则从配置的服务器获取示例数据,并追加到示例数据 textarea 中;
|
||||||
3. 上传文件,将文件内容追加到示例数据 textarea 中。
|
3. 上传文件,将文件内容追加到示例数据 textarea 中。
|
||||||
|
|
||||||
|
每一条示例数据以回车符结尾。
|
||||||
|
|
||||||
#### 解析<a name="parse"></a>
|
#### 解析<a name="parse"></a>
|
||||||
|
|
||||||
解析就是通过解析规则,将非结构化字符串解析为结构化数据。消息体的解析规则目前支持 JSON、Regex 和 UDT。
|
解析就是通过解析规则,将非结构化字符串解析为结构化数据。消息体的解析规则目前支持 JSON、Regex 和 UDT。
|
||||||
|
|
||||||
##### JSON 解析
|
##### JSON 解析
|
||||||
|
|
||||||
如下 JSON 示例数据,可自动解析出字段:`groupid`、`voltage`、`current`、`ts`、`inuse`、`location`。
|
JSON 解析支持 JSONObject 或者 JSONArray。 如下 JSON 示例数据,可自动解析出字段:`groupid`、`voltage`、`current`、`ts`、`inuse`、`location`。
|
||||||
|
|
||||||
``` json
|
``` json
|
||||||
{"groupid": 170001, "voltage": "221V", "current": 12.3, "ts": "2023-12-18T22:12:00", "inuse": true, "location": "beijing.chaoyang.datun"}
|
{"groupid": 170001, "voltage": "221V", "current": 12.3, "ts": "2023-12-18T22:12:00", "inuse": true, "location": "beijing.chaoyang.datun"}
|
||||||
|
@ -67,6 +68,16 @@ TDengine Enterprise 配备了一个强大的可视化数据管理工具—taosEx
|
||||||
{"groupid": 170001, "voltage": "216V", "current": 12.5, "ts": "2023-12-18T22:12:04", "inuse": false, "location": "beijing.chaoyang.datun"}
|
{"groupid": 170001, "voltage": "216V", "current": 12.5, "ts": "2023-12-18T22:12:04", "inuse": false, "location": "beijing.chaoyang.datun"}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
或者
|
||||||
|
|
||||||
|
``` json
|
||||||
|
[{"groupid": 170001, "voltage": "221V", "current": 12.3, "ts": "2023-12-18T22:12:00", "inuse": true, "location": "beijing.chaoyang.datun"},
|
||||||
|
{"groupid": 170001, "voltage": "220V", "current": 12.2, "ts": "2023-12-18T22:12:02", "inuse": true, "location": "beijing.chaoyang.datun"},
|
||||||
|
{"groupid": 170001, "voltage": "216V", "current": 12.5, "ts": "2023-12-18T22:12:04", "inuse": false, "location": "beijing.chaoyang.datun"}]
|
||||||
|
```
|
||||||
|
|
||||||
|
后续示例仅以JSONObject 为例说明。
|
||||||
|
|
||||||
如下嵌套结构的 JSON 数据,可自动解析出字段`groupid`、`data_voltage`、`data_current`、`ts`、`inuse`、`location_0_province`、`location_0_city`、`location_0_datun`,也可以选择要解析的字段,并设置解析的别名。
|
如下嵌套结构的 JSON 数据,可自动解析出字段`groupid`、`data_voltage`、`data_current`、`ts`、`inuse`、`location_0_province`、`location_0_city`、`location_0_datun`,也可以选择要解析的字段,并设置解析的别名。
|
||||||
|
|
||||||
``` json
|
``` json
|
||||||
|
|
After Width: | Height: | Size: 91 KiB |
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 32 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 7.4 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 37 KiB |
After Width: | Height: | Size: 107 KiB |
After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 22 KiB After Width: | Height: | Size: 31 KiB |
|
@ -89,7 +89,7 @@ TDengine 提供了丰富的应用程序开发接口,为了便于用户快速
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>3.3.2</version>
|
<version>3.3.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ REST 连接支持所有能运行 Java 的平台。
|
||||||
|
|
||||||
| taos-jdbcdriver 版本 | 主要变化 | TDengine 版本 |
|
| taos-jdbcdriver 版本 | 主要变化 | TDengine 版本 |
|
||||||
| :------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------: |
|
| :------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------: |
|
||||||
|
| 3.3.3 | 1. 解决了 Websocket statement 关闭导致的内存泄漏 | - |
|
||||||
| 3.3.2 | 1. 优化 Websocket 连接下的参数绑定性能;2. 优化了对 mybatis 的支持 | - |
|
| 3.3.2 | 1. 优化 Websocket 连接下的参数绑定性能;2. 优化了对 mybatis 的支持 | - |
|
||||||
| 3.3.0 | 1. 优化 Websocket 连接下的数据传输性能;2. 支持跳过 SSL 验证,默认关闭 | 3.3.2.0 及更高版本 |
|
| 3.3.0 | 1. 优化 Websocket 连接下的数据传输性能;2. 支持跳过 SSL 验证,默认关闭 | 3.3.2.0 及更高版本 |
|
||||||
| 3.2.11 | 解决了 Native 连接关闭结果集 bug | - |
|
| 3.2.11 | 解决了 Native 连接关闭结果集 bug | - |
|
||||||
|
|
|
@ -63,10 +63,15 @@ TDengine 其他功能模块的报错,请参考 [错误码](../../../reference/
|
||||||
| BINARY | string |
|
| BINARY | string |
|
||||||
| NCHAR | string |
|
| NCHAR | string |
|
||||||
| JSON | []byte |
|
| JSON | []byte |
|
||||||
|
| GEOMETRY | []byte |
|
||||||
|
| VARBINARY | []byte |
|
||||||
|
|
||||||
**注意**:JSON 类型仅在 tag 中支持。
|
**注意**:JSON 类型仅在 tag 中支持。
|
||||||
|
GEOMETRY类型是 little endian 字节序的二进制数据,符合 WKB 规范。详细信息请参考 [数据类型](../../taos-sql/data-type/#数据类型)
|
||||||
|
WKB规范请参考[Well-Known Binary (WKB)](https://libgeos.org/specifications/wkb/)
|
||||||
|
|
||||||
## 示例程序汇总
|
## 示例程序汇总
|
||||||
|
|
||||||
示例程序源码请参考:[示例程序](https://github.com/taosdata/driver-go/tree/main/examples)
|
示例程序源码请参考:[示例程序](https://github.com/taosdata/driver-go/tree/main/examples)
|
||||||
|
|
||||||
## 常见问题
|
## 常见问题
|
||||||
|
|
|
@ -80,6 +80,8 @@ TDengine 目前支持时间戳、数字、字符、布尔类型,与 Rust 对
|
||||||
| BINARY | Vec\<u8> |
|
| BINARY | Vec\<u8> |
|
||||||
| NCHAR | String |
|
| NCHAR | String |
|
||||||
| JSON | serde_json::Value |
|
| JSON | serde_json::Value |
|
||||||
|
| VARBINARY | Bytes |
|
||||||
|
| GEOMETRY | Bytes |
|
||||||
|
|
||||||
**注意**:JSON 类型仅在 tag 中支持。
|
**注意**:JSON 类型仅在 tag 中支持。
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,8 @@ TDengine 目前支持时间戳、数字、字符、布尔类型,与 Python 对
|
||||||
|BINARY|str|
|
|BINARY|str|
|
||||||
|NCHAR|str|
|
|NCHAR|str|
|
||||||
|JSON|str|
|
|JSON|str|
|
||||||
|
|GEOMETRY|bytearray|
|
||||||
|
|VARBINARY|bytearray|
|
||||||
## 示例程序汇总
|
## 示例程序汇总
|
||||||
|
|
||||||
| 示例程序链接 | 示例程序内容 |
|
| 示例程序链接 | 示例程序内容 |
|
||||||
|
@ -113,6 +114,13 @@ TDengine 目前支持时间戳、数字、字符、布尔类型,与 Python 对
|
||||||
| [insert_lines.py](https://github.com/taosdata/taos-connector-python/blob/main/examples/insert-lines.py) | InfluxDB 行协议写入 |
|
| [insert_lines.py](https://github.com/taosdata/taos-connector-python/blob/main/examples/insert-lines.py) | InfluxDB 行协议写入 |
|
||||||
| [json_tag.py](https://github.com/taosdata/taos-connector-python/blob/main/examples/json-tag.py) | 使用 JSON 类型的标签 |
|
| [json_tag.py](https://github.com/taosdata/taos-connector-python/blob/main/examples/json-tag.py) | 使用 JSON 类型的标签 |
|
||||||
| [tmq_consumer.py](https://github.com/taosdata/taos-connector-python/blob/main/examples/tmq_consumer.py) | tmq 订阅 |
|
| [tmq_consumer.py](https://github.com/taosdata/taos-connector-python/blob/main/examples/tmq_consumer.py) | tmq 订阅 |
|
||||||
|
| [native_all_type_query.py](https://github.com/taosdata/taos-connector-python/blob/main/examples/native_all_type_query.py) | 支持全部类型示例 |
|
||||||
|
| [native_all_type_stmt.py](https://github.com/taosdata/taos-connector-python/blob/main/examples/native_all_type_stmt.py) | 参数绑定支持全部类型示例 |
|
||||||
|
|
||||||
|
示例程序源码请参考:
|
||||||
|
|
||||||
|
1. [原生更多示例程序](https://github.com/taosdata/taos-connector-python/tree/main/examples)
|
||||||
|
2. [WebSocket 更多示例程序](https://github.com/taosdata/taos-connector-python/tree/main/taos-ws-py/examples)
|
||||||
|
|
||||||
## 关于纳秒 (nanosecond)
|
## 关于纳秒 (nanosecond)
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,8 @@ Node.js 连接器目前仅支持 Websocket 连接器, 其通过 taosAdapter
|
||||||
| [telnet_line_example](https://github.com/taosdata/TDengine/tree/main/docs/examples/node/websocketexample/telnet_line_example.js) | OpenTSDB Telnet 行协议写入示例。 |
|
| [telnet_line_example](https://github.com/taosdata/TDengine/tree/main/docs/examples/node/websocketexample/telnet_line_example.js) | OpenTSDB Telnet 行协议写入示例。 |
|
||||||
| [json_line_example](https://github.com/taosdata/TDengine/tree/main/docs/examples/node/websocketexample/json_line_example.js) | OpenTSDB JSON 行协议写入示例。 |
|
| [json_line_example](https://github.com/taosdata/TDengine/tree/main/docs/examples/node/websocketexample/json_line_example.js) | OpenTSDB JSON 行协议写入示例。 |
|
||||||
| [tmq_example](https://github.com/taosdata/TDengine/tree/main/docs/examples/node/websocketexample/tmq_example.js) | 订阅的使用示例。 |
|
| [tmq_example](https://github.com/taosdata/TDengine/tree/main/docs/examples/node/websocketexample/tmq_example.js) | 订阅的使用示例。 |
|
||||||
|
| [all_type_query](https://github.com/taosdata/TDengine/tree/main/docs/examples/node/websocketexample/all_type_query.js) | 支持全部类型示例。 |
|
||||||
|
| [all_type_stmt](https://github.com/taosdata/TDengine/tree/main/docs/examples/node/websocketexample/all_type_stmt.js) | 参数绑定支持全部类型示例。 |
|
||||||
|
|
||||||
## 使用限制
|
## 使用限制
|
||||||
|
|
||||||
|
|
|
@ -67,9 +67,13 @@ TDengine 其他功能模块的报错,请参考 [错误码](../../../reference/
|
||||||
| VARBINARY | byte[] |
|
| VARBINARY | byte[] |
|
||||||
| GEOMETRY | byte[] |
|
| GEOMETRY | byte[] |
|
||||||
|
|
||||||
:::note
|
**注意**:JSON 类型仅在 tag 中支持。
|
||||||
JSON 类型仅在 tag 中支持。
|
GEOMETRY类型是 little endian 字节序的二进制数据,符合 WKB 规范。详细信息请参考 [数据类型](../../taos-sql/data-type/#数据类型)
|
||||||
:::
|
WKB规范请参考[Well-Known Binary (WKB)](https://libgeos.org/specifications/wkb/)
|
||||||
|
|
||||||
|
## 示例程序汇总
|
||||||
|
|
||||||
|
示例程序源码请参考:[示例程序](https://github.com/taosdata/taos-connector-dotnet/tree/3.0/examples)
|
||||||
|
|
||||||
## API 参考
|
## API 参考
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,11 @@ sidebar_label: ODBC
|
||||||
title: TDengine ODBC
|
title: TDengine ODBC
|
||||||
---
|
---
|
||||||
|
|
||||||
TDengine ODBC 是为 TDengine 实现的 ODBC 驱动程序,支持 Windows 系统的应用(如 [PowerBI](https://powerbi.microsoft.com/zh-cn/) 等)通过 ODBC 标准接口访问本地、远程和云服务的 TDengine 数据库。
|
TDengine ODBC 是为 TDengine 实现的 ODBC 驱动程序,支持 Windows 系统的应用(如 [PowerBI](https://powerbi.microsoft.com/zh-cn/) 等)通过 ODBC 标准接口访问本地、远程和云服务的 TDengine 数据库的数据表/视图。
|
||||||
|
|
||||||
TDengine ODBC 提供基于 WebSocket(推荐)和 原生连接两种方式连接 TDengine 数据库,使用时可以为 TDengine 数据源设置不同的连接方式。访问云服务时必须使用 WebSocket 连接方式。
|
TDengine ODBC 提供基于 WebSocket(推荐)和 原生连接两种方式连接 TDengine 数据库,使用时可以为 TDengine 数据源设置不同的连接方式。访问云服务时必须使用 WebSocket 连接方式。
|
||||||
|
|
||||||
注意:TDengine ODBC 只支持 64 位系统,调用 TDengine ODBC 必须通过 64 位的 ODBC 驱动管理器进行。因此调用 ODBC 的程序不能使用 32 位版本。
|
注意:TDengine ODBC 支持 32/64 位 Windows 系统,调用 TDengine ODBC 需要通过相应位数的 ODBC 驱动管理器进行。在 32 位 Windows 系统或者 64 位 Windows 系统的 32 位应用程序中,仅支持使用 WebSocket 连接方式访问 TDengine 数据库。
|
||||||
|
|
||||||
想更多了解 TDengine 时序时序数据库的使用,可访问 [TDengine官方文档](https://docs.taosdata.com/intro/)。
|
想更多了解 TDengine 时序时序数据库的使用,可访问 [TDengine官方文档](https://docs.taosdata.com/intro/)。
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ TDengine ODBC 提供基于 WebSocket(推荐)和 原生连接两种方式连
|
||||||
|
|
||||||
1. 仅支持 Windows 平台。Windows 上需要安装过 VC 运行时库,可在此下载安装 [VC运行时库](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170) 如果已经安装VS开发工具可忽略。
|
1. 仅支持 Windows 平台。Windows 上需要安装过 VC 运行时库,可在此下载安装 [VC运行时库](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170) 如果已经安装VS开发工具可忽略。
|
||||||
|
|
||||||
2. 安装 TDengine Windows 客户端,版本在 3.2.1.0 或以上,都会包含 TDengine 的 ODBC 驱动。
|
2. 安装 TDengine Windows 客户端。版本在 3.2.1.0 或以上,包含 TDengine 的 ODBC 64 位驱动;版本在 3.3.3.0 或以上,包含 TDengine 的 ODBC 32/64 位驱动。
|
||||||
|
|
||||||
## 配置数据源
|
## 配置数据源
|
||||||
|
|
||||||
|
@ -26,17 +26,19 @@ TDengine ODBC 提供基于 WebSocket(推荐)和 原生连接两种方式连
|
||||||
|
|
||||||
TDengine ODBC 支持两种连接 TDengine 数据库方式:Websocket 连接与 Native 连接,其区别如下:
|
TDengine ODBC 支持两种连接 TDengine 数据库方式:Websocket 连接与 Native 连接,其区别如下:
|
||||||
|
|
||||||
1. 只有 Websocket 支持连接云服务
|
1. 访问云服务仅支持使用 Websocket 连接方式。
|
||||||
|
|
||||||
2. Websocket 连接的兼容性更好,一般不需要随着 TDengine 数据库服务端升级而升级客户端的库。
|
2. 32 位应用程序仅支持使用 WebSocket 连接方式。
|
||||||
|
|
||||||
3. Native 连接通常性能更好一点,但是必须与 TDengine 数据库服务端的版本保持一致。
|
3. Websocket 连接的兼容性更好,一般不需要随着 TDengine 数据库服务端升级而升级客户端的库。
|
||||||
|
|
||||||
4. 对于一般用户,建议使用 **Websocket** 连接方式,性能与 Native 差别不大,兼容性更好。
|
4. Native 连接通常性能更好一点,但是必须与 TDengine 数据库服务端的版本保持一致。
|
||||||
|
|
||||||
|
5. 对于一般用户,建议使用 **Websocket** 连接方式,性能与 Native 差别不大,兼容性更好。
|
||||||
|
|
||||||
### WebSocket 连接
|
### WebSocket 连接
|
||||||
|
|
||||||
1. 【开始】菜单搜索打开【ODBC 数据源(64 位)】管理工具(注意不要选择ODBC 数据源(32 位))
|
1. 【开始】菜单搜索打开【ODBC 数据源(32 位)】或者【ODBC 数据源(64 位)】管理工具
|
||||||
|
|
||||||
2. 选中【用户 DSN】标签页,通过【添加(D)】按钮进入"创建数据源"界面
|
2. 选中【用户 DSN】标签页,通过【添加(D)】按钮进入"创建数据源"界面
|
||||||
|
|
||||||
|
@ -64,7 +66,7 @@ TDengine ODBC 支持两种连接 TDengine 数据库方式:Websocket 连接与
|
||||||
|
|
||||||
7. 也可以在第2步选择已经配置好的数据源名通过【配置】按钮进入配置页面,修改已有配置
|
7. 也可以在第2步选择已经配置好的数据源名通过【配置】按钮进入配置页面,修改已有配置
|
||||||
|
|
||||||
### 原生连接(不支持云服务)
|
### 原生连接(不支持云服务和 32 位应用程序)
|
||||||
|
|
||||||
1. 【开始】菜单搜索打开【ODBC 数据源(64 位)】管理工具(注意不要选择ODBC 数据源(32 位))
|
1. 【开始】菜单搜索打开【ODBC 数据源(64 位)】管理工具(注意不要选择ODBC 数据源(32 位))
|
||||||
|
|
||||||
|
|
|
@ -243,6 +243,7 @@ vi source-demo.json
|
||||||
"topic.per.stable": true,
|
"topic.per.stable": true,
|
||||||
"topic.ignore.db": false,
|
"topic.ignore.db": false,
|
||||||
"out.format": "line",
|
"out.format": "line",
|
||||||
|
"data.precision": "ms",
|
||||||
"key.converter": "org.apache.kafka.connect.storage.StringConverter",
|
"key.converter": "org.apache.kafka.connect.storage.StringConverter",
|
||||||
"value.converter": "org.apache.kafka.connect.storage.StringConverter"
|
"value.converter": "org.apache.kafka.connect.storage.StringConverter"
|
||||||
}
|
}
|
||||||
|
@ -332,14 +333,13 @@ curl -X DELETE http://localhost:8083/connectors/TDengineSourceConnector
|
||||||
1. 打开 KAFKA_HOME/config/producer.properties 配置文件。
|
1. 打开 KAFKA_HOME/config/producer.properties 配置文件。
|
||||||
2. 参数说明及配置建议如下:
|
2. 参数说明及配置建议如下:
|
||||||
| **参数** | **参数说明** | **设置建议** |
|
| **参数** | **参数说明** | **设置建议** |
|
||||||
| --------| --------------------------------- | -------------- |
|
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
|
||||||
| producer.type | 此参数用于设置消息的发送方式,默认值为 `sync` 表示同步发送,`async` 表示异步发送。采用异步发送能够提升消息发送的吞吐量。 | async |
|
| producer.type | 此参数用于设置消息的发送方式,默认值为 `sync` 表示同步发送,`async` 表示异步发送。采用异步发送能够提升消息发送的吞吐量。 | async |
|
||||||
| request.required.acks | 参数用于配置生产者发送消息后需要等待的确认数量。当设置为1时,表示只要领导者副本成功写入消息就会给生产者发送确认,而无需等待集群中的其他副本写入成功。这种设置可以在一定程度上保证消息的可靠性,同时也能保证一定的吞吐量。因为不需要等待所有副本都写入成功,所以可以减少生产者的等待时间,提高发送消息的效率。 | 1 |
|
| request.required.acks | 参数用于配置生产者发送消息后需要等待的确认数量。当设置为1时,表示只要领导者副本成功写入消息就会给生产者发送确认,而无需等待集群中的其他副本写入成功。这种设置可以在一定程度上保证消息的可靠性,同时也能保证一定的吞吐量。因为不需要等待所有副本都写入成功,所以可以减少生产者的等待时间,提高发送消息的效率。 | 1 |
|
||||||
| max.request.size | 该参数决定了生产者在一次请求中可以发送的最大数据量。其默认值为 1048576,也就是 1M。如果设置得太小,可能会导致频繁的网络请求,降低吞吐量。如果设置得太大,可能会导致内存占用过高,或者在网络状况不佳时增加请求失败的概率。建议设置为 100M。 | 104857600 |
|
| max.request.size | 该参数决定了生产者在一次请求中可以发送的最大数据量。其默认值为 1048576,也就是 1M。如果设置得太小,可能会导致频繁的网络请求,降低吞吐量。如果设置得太大,可能会导致内存占用过高,或者在网络状况不佳时增加请求失败的概率。建议设置为 100M。 | 104857600 |
|
||||||
| batch.size | 此参数用于设定 batch 的大小,默认值为 16384,即 16KB。在消息发送过程中,发送到 Kafka 缓冲区中的消息会被划分成一个个的 batch。故而减小 batch 大小有助于降低消息延迟,而增大 batch 大小则有利于提升吞吐量,可根据实际的数据量大小进行合理配置。可根据实际情况进行调整,建议设置为 512K。 | 524288 |
|
| batch.size | 此参数用于设定 batch 的大小,默认值为 16384,即 16KB。在消息发送过程中,发送到 Kafka 缓冲区中的消息会被划分成一个个的 batch。故而减小 batch 大小有助于降低消息延迟,而增大 batch 大小则有利于提升吞吐量,可根据实际的数据量大小进行合理配置。可根据实际情况进行调整,建议设置为 512K。 | 524288 |
|
||||||
| buffer.memory | 此参数用于设置生产者缓冲待发送消息的内存总量。较大的缓冲区可以允许生产者积累更多的消息后批量发送,提高吞吐量,但也会增加延迟和内存使用。可根据机器资源来配置,建议配置为 1G。 | 1073741824 |
|
| buffer.memory | 此参数用于设置生产者缓冲待发送消息的内存总量。较大的缓冲区可以允许生产者积累更多的消息后批量发送,提高吞吐量,但也会增加延迟和内存使用。可根据机器资源来配置,建议配置为 1G。 | 1073741824 |
|
||||||
|
|
||||||
|
|
||||||
## 配置参考
|
## 配置参考
|
||||||
|
|
||||||
### 通用配置
|
### 通用配置
|
||||||
|
@ -370,7 +370,7 @@ curl -X DELETE http://localhost:8083/connectors/TDengineSourceConnector
|
||||||
7. `data.precision`: 使用 InfluxDB 行协议格式时,时间戳的精度。可选值为:
|
7. `data.precision`: 使用 InfluxDB 行协议格式时,时间戳的精度。可选值为:
|
||||||
1. ms : 表示毫秒
|
1. ms : 表示毫秒
|
||||||
2. us : 表示微秒
|
2. us : 表示微秒
|
||||||
3. ns : 表示纳秒。默认为纳秒。
|
3. ns : 表示纳秒。
|
||||||
|
|
||||||
### TDengine Source Connector 特有的配置
|
### TDengine Source Connector 特有的配置
|
||||||
|
|
||||||
|
@ -381,12 +381,16 @@ curl -X DELETE http://localhost:8083/connectors/TDengineSourceConnector
|
||||||
5. `fetch.max.rows` : 检索数据库时最大检索条数。 默认为 100。
|
5. `fetch.max.rows` : 检索数据库时最大检索条数。 默认为 100。
|
||||||
6. `query.interval.ms`: 从 TDengine 一次读取数据的时间跨度,需要根据表中的数据特征合理配置,避免一次查询的数据量过大或过小;在具体的环境中建议通过测试设置一个较优值,默认值为 0,即获取到当前最新时间的所有数据。
|
6. `query.interval.ms`: 从 TDengine 一次读取数据的时间跨度,需要根据表中的数据特征合理配置,避免一次查询的数据量过大或过小;在具体的环境中建议通过测试设置一个较优值,默认值为 0,即获取到当前最新时间的所有数据。
|
||||||
7. `out.format` : 结果集输出格式。`line` 表示输出格式为 InfluxDB Line 协议格式,`json` 表示输出格式是 json。默认为 line。
|
7. `out.format` : 结果集输出格式。`line` 表示输出格式为 InfluxDB Line 协议格式,`json` 表示输出格式是 json。默认为 line。
|
||||||
8. `topic.per.stable`: 如果设置为 true,表示一个超级表对应一个 Kafka topic,topic的命名规则 `<topic.prefix><topic.delimiter><connection.database><topic.delimiter><stable.name>`;如果设置为 false,则指定的 DB 中的所有数据进入一个 Kafka topic,topic 的命名规则为 `<topic.prefix><topic.delimiter><connection.database>`
|
8. `data.precision`: 使用 InfluxDB 行协议格式时,时间戳的精度。可选值为:
|
||||||
9. `topic.ignore.db`: topic 命名规则是否包含 database 名称,true 表示规则为 `<topic.prefix><topic.delimiter><stable.name>`,false 表示规则为 `<topic.prefix><topic.delimiter><connection.database><topic.delimiter><stable.name>`,默认 false。此配置项在 `topic.per.stable` 设置为 false 时不生效。
|
1. ms : 表示毫秒,
|
||||||
10. `topic.delimiter`: topic 名称分割符,默认为 `-`。
|
2. us : 表示微秒
|
||||||
11. `read.method`: 从 TDengine 读取数据方式,query 或是 subscription。默认为 subscription。
|
3. ns : 表示纳秒。
|
||||||
12. `subscription.group.id`: 指定 TDengine 数据订阅的组 id,当 `read.method` 为 subscription 时,此项为必填项。
|
9. `topic.per.stable`: 如果设置为 true,表示一个超级表对应一个 Kafka topic,topic的命名规则 `<topic.prefix><topic.delimiter><connection.database><topic.delimiter><stable.name>`;如果设置为 false,则指定的 DB 中的所有数据进入一个 Kafka topic,topic 的命名规则为 `<topic.prefix><topic.delimiter><connection.database>`
|
||||||
13. `subscription.from`: 指定 TDengine 数据订阅起始位置,latest 或是 earliest。默认为 latest。
|
10. `topic.ignore.db`: topic 命名规则是否包含 database 名称,true 表示规则为 `<topic.prefix><topic.delimiter><stable.name>`,false 表示规则为 `<topic.prefix><topic.delimiter><connection.database><topic.delimiter><stable.name>`,默认 false。此配置项在 `topic.per.stable` 设置为 false 时不生效。
|
||||||
|
11. `topic.delimiter`: topic 名称分割符,默认为 `-`。
|
||||||
|
12. `read.method`: 从 TDengine 读取数据方式,query 或是 subscription。默认为 subscription。
|
||||||
|
13. `subscription.group.id`: 指定 TDengine 数据订阅的组 id,当 `read.method` 为 subscription 时,此项为必填项。
|
||||||
|
14. `subscription.from`: 指定 TDengine 数据订阅起始位置,latest 或是 earliest。默认为 latest。
|
||||||
|
|
||||||
## 其他说明
|
## 其他说明
|
||||||
|
|
||||||
|
|
|
@ -8,35 +8,35 @@ Power BI是由Microsoft提供的一种商业分析工具。通过配置使用ODB
|
||||||
|
|
||||||
## 前置条件
|
## 前置条件
|
||||||
|
|
||||||
安装完成Power BI Desktop软件并运行(如未安装,请从其官方地址下载最新的Windows操作系统X64版本)。
|
安装完成Power BI Desktop软件并运行(如未安装,请从其官方地址下载最新的Windows操作系统 32/64 位版本)。
|
||||||
|
|
||||||
## 安装 ODBC 驱动
|
## 安装 ODBC 驱动
|
||||||
|
|
||||||
从TDengine官网下载最新的Windows操作系统X64客户端驱动程序,并安装在运行Power BI的机器上。安装成功后可在“ODBC数据源(64位)”管理工具中看到 TAOS_ODBC_DSN”驱动程序。
|
从TDengine官网下载最新的Windows操作系统X64客户端驱动程序,并安装在运行Power BI的机器上。安装成功后可在“ODBC数据源(32位)”或者“ODBC数据源(64位)”管理工具中看到 TDengine 驱动程序。
|
||||||
|
|
||||||
## 配置ODBC数据源
|
## 配置ODBC数据源
|
||||||
|
|
||||||
配置ODBC数据源的操作步骤如下。
|
配置ODBC数据源的操作步骤如下。
|
||||||
|
|
||||||
第1步,在Windows操作系统的开始菜单中搜索并打开“ODBC数据源(64位)”管理工具。
|
第1步,在Windows操作系统的开始菜单中搜索并打开“ODBC数据源(32位)”或者“ODBC数据源(64位)”管理工具。
|
||||||
第2步,点击“用户DSN”选项卡→“添加”按钮,进入“创建新数据源”对话框。
|
第2步,点击“用户DSN”选项卡→“添加”按钮,进入“创建新数据源”对话框。
|
||||||
第3步,选择想要添加的数据源后选择“TDengine”,点击“完成”按钮,进入TDengine ODBC数据源配置页面。填写如下必要信息。
|
第3步,在“选择您想为其安装数据源的驱动程序”列表中选择“TDengine”,点击“完成”按钮,进入TDengine ODBC数据源配置页面。填写如下必要信息。
|
||||||
- DSN:数据源名称,必填,比如“MyTDengine”。
|
- DSN:数据源名称,必填,比如“MyTDengine”。
|
||||||
- 连接类型:勾选“WebSocket”复选框。
|
- 连接类型:勾选“WebSocket”复选框。
|
||||||
- 服务地址:输入“taos://127.0.0.1:6041”。
|
- URL:ODBC 数据源 URL,必填,比如“http://127.0.0.1:6041”。
|
||||||
- 数据库:表示需要连接的数据库,可选,比如“test”。
|
- 数据库:表示需要连接的数据库,可选,比如“test”。
|
||||||
- 用户名:输入用户名,如果不填,默认为“root”。
|
- 用户名:输入用户名,如果不填,默认为“root”。
|
||||||
- 密码:输入用户密码,如果不填,默认为“taosdata”。
|
- 密码:输入用户密码,如果不填,默认为“taosdata”。
|
||||||
第4步,点击“测试连接”按钮,测试连接情况,如果成功连接,则会提示“成功连接到taos://root:taosdata@127.0.0.1:6041”。
|
|
||||||
|
第4步,点击“测试连接”按钮,测试连接情况,如果成功连接,则会提示“成功连接到http://127.0.0.1:6041”。
|
||||||
第5步,点击“确定”按钮,即可保存配置并退出。
|
第5步,点击“确定”按钮,即可保存配置并退出。
|
||||||
|
|
||||||
## 导入TDengine数据到Power BI
|
## 导入TDengine数据到Power BI
|
||||||
|
|
||||||
将TDengine数据导入Power BI的操作步骤如下。
|
将TDengine数据导入Power BI的操作步骤如下:
|
||||||
|
|
||||||
第1步,打开Power BI并登录后,点击“主页”→“获取数据”→“其他”→“ODBC”→“连接”,添加数据源。
|
第1步,打开Power BI并登录后,点击“主页”→“获取数据”→“其他”→“ODBC”→“连接”,添加数据源。
|
||||||
第2步,选择刚才创建的数据源名称,比如“MyTDengine”,点击“确定”按钮。在弹出的“ODBC驱动程序”对话框中,在左侧导航栏中点击“默认或自定义”→“连接”按钮,即可连接到配置好的数据源。进入“导航器”后,可以浏览对应数据库的数据表并加载。
|
第2步,选择刚才创建的数据源名称,比如“MyTDengine”,如果需要输入SQL,则可以点击“高级选项”选项卡,在展开的对话框的编辑框中输入SQL语句。点击“确定”按钮,即可连接到配置好的数据源。
|
||||||
第3步,如果需要输入SQL,则可以点击“高级选项”选项卡,在展开的对话框中输入并加载数据。
|
第3步,进入“导航器”后,可以浏览对应数据库的数据表/视图并加载数据。
|
||||||
|
|
||||||
为了充分发挥Power BI在分析TDengine中数据方面的优势,用户需要先理解维度、度量、窗口切分查询、数据切分查询、时序和相关性等核心概念,之后通过自定义的SQL导入数据。
|
为了充分发挥Power BI在分析TDengine中数据方面的优势,用户需要先理解维度、度量、窗口切分查询、数据切分查询、时序和相关性等核心概念,之后通过自定义的SQL导入数据。
|
||||||
- 维度:通常是分类(文本)数据,描述设备、测点、型号等类别信息。在TDengine的超级表中,使用标签列存储数据的维度信息,可以通过形如“select distinct tbname, tag1, tag2 from supertable”的SQL语法快速获得维度信息。
|
- 维度:通常是分类(文本)数据,描述设备、测点、型号等类别信息。在TDengine的超级表中,使用标签列存储数据的维度信息,可以通过形如“select distinct tbname, tag1, tag2 from supertable”的SQL语法快速获得维度信息。
|
||||||
|
@ -57,7 +57,7 @@ TDengine采用了一种独特的数据模型,以优化时序数据的存储和
|
||||||
根据如下步骤,便可以体验通过Power BI生成时序数据报表的功能。
|
根据如下步骤,便可以体验通过Power BI生成时序数据报表的功能。
|
||||||
第1步,使用TDengine的taosBenchMark快速生成1000块智能电表3天的数据,采集频率为1s。
|
第1步,使用TDengine的taosBenchMark快速生成1000块智能电表3天的数据,采集频率为1s。
|
||||||
```shell
|
```shell
|
||||||
taosBenchmark-t1000-n259200-S1000-H200-y
|
taosBenchmark -t 1000 -n 259200 -S 1000 -y
|
||||||
```
|
```
|
||||||
第2步,导入维度数据。在Power BI中导入表的标签列,取名为tags,通过如下SQL获取超级表下所有智能电表的标签数据。
|
第2步,导入维度数据。在Power BI中导入表的标签列,取名为tags,通过如下SQL获取超级表下所有智能电表的标签数据。
|
||||||
```sql
|
```sql
|
||||||
|
@ -65,7 +65,7 @@ TDengine采用了一种独特的数据模型,以优化时序数据的存储和
|
||||||
```
|
```
|
||||||
第3步,导入度量数据。在Power BI中,按照1小时的时间窗口,导入每块智能电表的电流均值、电压均值、相位均值,取名为data,SQL如下。
|
第3步,导入度量数据。在Power BI中,按照1小时的时间窗口,导入每块智能电表的电流均值、电压均值、相位均值,取名为data,SQL如下。
|
||||||
```sql
|
```sql
|
||||||
第3步,导入度量数据。在Power BI中,按照1小时的时间窗口,导入每块智能电表的电流均值、电压均值、相位均值,取名为data,SQL如下。
|
select tbname, _wstart ws, avg(current), avg(voltage), avg(phase) from test.meters PARTITION by tbname interval(1h)
|
||||||
```
|
```
|
||||||
第4步,导入日期数据。按照1天的时间窗口,获得时序数据的时间范围及数据计数,SQL如下。需要在Power Query编辑器中将date列的格式从“文本”转化为“日期”。
|
第4步,导入日期数据。按照1天的时间窗口,获得时序数据的时间范围及数据计数,SQL如下。需要在Power Query编辑器中将date列的格式从“文本”转化为“日期”。
|
||||||
```sql
|
```sql
|
||||||
|
|
|
@ -176,6 +176,15 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define TAOS_CHECK_RETURN_WITH_RELEASE(CMD, PTR1, PTR2) \
|
||||||
|
do { \
|
||||||
|
int32_t __c = (CMD); \
|
||||||
|
if (__c != TSDB_CODE_SUCCESS) { \
|
||||||
|
sdbRelease(PTR1, PTR2); \
|
||||||
|
TAOS_RETURN(__c); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#define TAOS_CHECK_RETURN_WITH_FREE(CMD, PTR) \
|
#define TAOS_CHECK_RETURN_WITH_FREE(CMD, PTR) \
|
||||||
do { \
|
do { \
|
||||||
int32_t __c = (CMD); \
|
int32_t __c = (CMD); \
|
||||||
|
|
|
@ -215,7 +215,8 @@ static void reportSendProcess(void* param, void* tmrId) {
|
||||||
|
|
||||||
SEpSet ep = getEpSet_s(&pInst->mgmtEp);
|
SEpSet ep = getEpSet_s(&pInst->mgmtEp);
|
||||||
generateClusterReport(pMonitor->registry, pInst->pTransporter, &ep);
|
generateClusterReport(pMonitor->registry, pInst->pTransporter, &ep);
|
||||||
bool reset = taosTmrReset(reportSendProcess, pInst->monitorParas.tsMonitorInterval * 1000, param, monitorTimer, &tmrId);
|
bool reset =
|
||||||
|
taosTmrReset(reportSendProcess, pInst->monitorParas.tsMonitorInterval * 1000, param, monitorTimer, &tmrId);
|
||||||
tscDebug("reset timer, pMonitor:%p, %d", pMonitor, reset);
|
tscDebug("reset timer, pMonitor:%p, %d", pMonitor, reset);
|
||||||
taosRUnLockLatch(&monitorLock);
|
taosRUnLockLatch(&monitorLock);
|
||||||
}
|
}
|
||||||
|
@ -831,7 +832,7 @@ static int32_t tscMonitortInit() {
|
||||||
static void tscMonitorStop() {
|
static void tscMonitorStop() {
|
||||||
if (taosCheckPthreadValid(monitorThread)) {
|
if (taosCheckPthreadValid(monitorThread)) {
|
||||||
(void)taosThreadJoin(monitorThread, NULL);
|
(void)taosThreadJoin(monitorThread, NULL);
|
||||||
(void)taosThreadClear(&monitorThread);
|
taosThreadClear(&monitorThread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -347,14 +347,14 @@ int32_t dmStartAuditThread(SDnodeMgmt *pMgmt) {
|
||||||
void dmStopMonitorThread(SDnodeMgmt *pMgmt) {
|
void dmStopMonitorThread(SDnodeMgmt *pMgmt) {
|
||||||
if (taosCheckPthreadValid(pMgmt->monitorThread)) {
|
if (taosCheckPthreadValid(pMgmt->monitorThread)) {
|
||||||
(void)taosThreadJoin(pMgmt->monitorThread, NULL);
|
(void)taosThreadJoin(pMgmt->monitorThread, NULL);
|
||||||
(void)taosThreadClear(&pMgmt->monitorThread);
|
taosThreadClear(&pMgmt->monitorThread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dmStopAuditThread(SDnodeMgmt *pMgmt) {
|
void dmStopAuditThread(SDnodeMgmt *pMgmt) {
|
||||||
if (taosCheckPthreadValid(pMgmt->auditThread)) {
|
if (taosCheckPthreadValid(pMgmt->auditThread)) {
|
||||||
(void)taosThreadJoin(pMgmt->auditThread, NULL);
|
(void)taosThreadJoin(pMgmt->auditThread, NULL);
|
||||||
(void)taosThreadClear(&pMgmt->auditThread);
|
taosThreadClear(&pMgmt->auditThread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,7 +385,7 @@ void dmStopCrashReportThread(SDnodeMgmt *pMgmt) {
|
||||||
|
|
||||||
if (taosCheckPthreadValid(pMgmt->crashReportThread)) {
|
if (taosCheckPthreadValid(pMgmt->crashReportThread)) {
|
||||||
(void)taosThreadJoin(pMgmt->crashReportThread, NULL);
|
(void)taosThreadJoin(pMgmt->crashReportThread, NULL);
|
||||||
(void)taosThreadClear(&pMgmt->crashReportThread);
|
taosThreadClear(&pMgmt->crashReportThread);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndCluster.h"
|
|
||||||
#include "audit.h"
|
#include "audit.h"
|
||||||
|
#include "mndCluster.h"
|
||||||
#include "mndGrant.h"
|
#include "mndGrant.h"
|
||||||
#include "mndPrivilege.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
|
@ -257,7 +257,11 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
|
||||||
code = terrno;
|
code = terrno;
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
code = sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||||
|
if (code != 0) {
|
||||||
|
sdbFreeRaw(pRaw);
|
||||||
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
|
||||||
mInfo("cluster:%" PRId64 ", will be created when deploying, raw:%p", clusterObj.id, pRaw);
|
mInfo("cluster:%" PRId64 ", will be created when deploying, raw:%p", clusterObj.id, pRaw);
|
||||||
|
|
||||||
|
@ -275,7 +279,12 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
code = sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
||||||
|
if (code != 0) {
|
||||||
|
sdbFreeRaw(pRaw);
|
||||||
|
mndTransDrop(pTrans);
|
||||||
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
|
||||||
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
|
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
|
||||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||||
|
@ -317,7 +326,6 @@ static int32_t mndRetrieveClusters(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
COL_DATA_SET_VAL_GOTO((const char *)&pCluster->createdTime, false, pCluster, _OVER);
|
COL_DATA_SET_VAL_GOTO((const char *)&pCluster->createdTime, false, pCluster, _OVER);
|
||||||
|
|
||||||
|
|
||||||
char ver[12] = {0};
|
char ver[12] = {0};
|
||||||
STR_WITH_MAXSIZE_TO_VARSTR(ver, tsVersionName, pShow->pMeta->pSchemas[cols].bytes);
|
STR_WITH_MAXSIZE_TO_VARSTR(ver, tsVersionName, pShow->pMeta->pSchemas[cols].bytes);
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
|
@ -386,7 +394,12 @@ static int32_t mndProcessUptimeTimer(SRpcMsg *pReq) {
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
code = sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||||
|
if (code != 0) {
|
||||||
|
sdbFreeRaw(pCommitRaw);
|
||||||
|
mndTransDrop(pTrans);
|
||||||
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
|
||||||
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
|
if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
|
||||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||||
|
|
|
@ -67,22 +67,28 @@ int32_t mndRetrieveCompactDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
|
||||||
char tmpBuf[TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE] = {0};
|
char tmpBuf[TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->compactId, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->compactId, false),
|
||||||
|
pSdb, pCompactDetail);
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->vgId, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->vgId, false), pSdb,
|
||||||
|
pCompactDetail);
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->dnodeId, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->dnodeId, false),
|
||||||
|
pSdb, pCompactDetail);
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->numberFileset, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(
|
||||||
|
colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->numberFileset, false), pSdb, pCompactDetail);
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->finished, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->finished, false),
|
||||||
|
pSdb, pCompactDetail);
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->startTime, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)&pCompactDetail->startTime, false),
|
||||||
|
pSdb, pCompactDetail);
|
||||||
|
|
||||||
numOfRows++;
|
numOfRows++;
|
||||||
sdbRelease(pSdb, pCompactDetail);
|
sdbRelease(pSdb, pCompactDetail);
|
||||||
|
@ -302,7 +308,7 @@ int32_t mndAddCompactDetailToTran(SMnode *pMnode, STrans *pTrans, SCompactObj *p
|
||||||
if (terrno != 0) code = terrno;
|
if (terrno != 0) code = terrno;
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
(void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY);
|
code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY);
|
||||||
|
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
|
@ -621,8 +621,8 @@ static void *mnodeGenTypeStr(char *buf, int32_t buflen, uint8_t type, int32_t le
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_VARBINARY ||
|
if (type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_BINARY ||
|
||||||
type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_GEOMETRY) {
|
type == TSDB_DATA_TYPE_GEOMETRY) {
|
||||||
int32_t bytes = len > 0 ? (int32_t)(len - VARSTR_HEADER_SIZE) : len;
|
int32_t bytes = len > 0 ? (int32_t)(len - VARSTR_HEADER_SIZE) : len;
|
||||||
|
|
||||||
(void)snprintf(buf, buflen - 1, "%s(%d)", tDataTypes[type].name, type == TSDB_DATA_TYPE_NCHAR ? bytes / 4 : bytes);
|
(void)snprintf(buf, buflen - 1, "%s(%d)", tDataTypes[type].name, type == TSDB_DATA_TYPE_NCHAR ? bytes / 4 : bytes);
|
||||||
|
@ -640,6 +640,7 @@ static int32_t mndRetrieveFuncs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
|
||||||
int32_t numOfRows = 0;
|
int32_t numOfRows = 0;
|
||||||
SFuncObj *pFunc = NULL;
|
SFuncObj *pFunc = NULL;
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
|
int32_t code = 0;
|
||||||
char buf[TSDB_TYPE_STR_MAX_LEN];
|
char buf[TSDB_TYPE_STR_MAX_LEN];
|
||||||
|
|
||||||
while (numOfRows < rows) {
|
while (numOfRows < rows) {
|
||||||
|
@ -652,40 +653,51 @@ static int32_t mndRetrieveFuncs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
|
||||||
STR_WITH_MAXSIZE_TO_VARSTR(b1, pFunc->name, pShow->pMeta->pSchemas[cols].bytes);
|
STR_WITH_MAXSIZE_TO_VARSTR(b1, pFunc->name, pShow->pMeta->pSchemas[cols].bytes);
|
||||||
|
|
||||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)b1, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)b1, false), pSdb, pFunc);
|
||||||
|
|
||||||
if (pFunc->pComment) {
|
if (pFunc->pComment) {
|
||||||
char *b2 = taosMemoryCalloc(1, pShow->pMeta->pSchemas[cols].bytes);
|
char *b2 = taosMemoryCalloc(1, pShow->pMeta->pSchemas[cols].bytes);
|
||||||
STR_WITH_MAXSIZE_TO_VARSTR(b2, pFunc->pComment, pShow->pMeta->pSchemas[cols].bytes);
|
STR_WITH_MAXSIZE_TO_VARSTR(b2, pFunc->pComment, pShow->pMeta->pSchemas[cols].bytes);
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)b2, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)b2, false);
|
||||||
|
if (code != 0) {
|
||||||
|
sdbRelease(pSdb, pFunc);
|
||||||
|
taosMemoryFree(b2);
|
||||||
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
taosMemoryFree(b2);
|
taosMemoryFree(b2);
|
||||||
} else {
|
} else {
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, NULL, true);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, NULL, true), pSdb, pFunc);
|
||||||
|
if (code != 0) {
|
||||||
|
sdbRelease(pSdb, pFunc);
|
||||||
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t isAgg = (pFunc->funcType == TSDB_FUNC_TYPE_AGGREGATE) ? 1 : 0;
|
int32_t isAgg = (pFunc->funcType == TSDB_FUNC_TYPE_AGGREGATE) ? 1 : 0;
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&isAgg, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)&isAgg, false), pSdb, pFunc);
|
||||||
|
|
||||||
char b3[TSDB_TYPE_STR_MAX_LEN + 1] = {0};
|
char b3[TSDB_TYPE_STR_MAX_LEN + 1] = {0};
|
||||||
STR_WITH_MAXSIZE_TO_VARSTR(b3, mnodeGenTypeStr(buf, TSDB_TYPE_STR_MAX_LEN, pFunc->outputType, pFunc->outputLen),
|
STR_WITH_MAXSIZE_TO_VARSTR(b3, mnodeGenTypeStr(buf, TSDB_TYPE_STR_MAX_LEN, pFunc->outputType, pFunc->outputLen),
|
||||||
pShow->pMeta->pSchemas[cols].bytes);
|
pShow->pMeta->pSchemas[cols].bytes);
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)b3, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)b3, false), pSdb, pFunc);
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pFunc->createdTime, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)&pFunc->createdTime, false), pSdb,
|
||||||
|
pFunc);
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pFunc->codeSize, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)&pFunc->codeSize, false), pSdb,
|
||||||
|
pFunc);
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pFunc->bufSize, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)&pFunc->bufSize, false), pSdb,
|
||||||
|
pFunc);
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
char *language = "";
|
char *language = "";
|
||||||
|
@ -697,7 +709,7 @@ static int32_t mndRetrieveFuncs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
|
||||||
char varLang[TSDB_TYPE_STR_MAX_LEN + 1] = {0};
|
char varLang[TSDB_TYPE_STR_MAX_LEN + 1] = {0};
|
||||||
varDataSetLen(varLang, strlen(language));
|
varDataSetLen(varLang, strlen(language));
|
||||||
strcpy(varDataVal(varLang), language);
|
strcpy(varDataVal(varLang), language);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)varLang, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)varLang, false), pSdb, pFunc);
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
int32_t varCodeLen = (pFunc->codeSize + VARSTR_HEADER_SIZE) > TSDB_MAX_BINARY_LEN
|
int32_t varCodeLen = (pFunc->codeSize + VARSTR_HEADER_SIZE) > TSDB_MAX_BINARY_LEN
|
||||||
|
@ -706,11 +718,17 @@ static int32_t mndRetrieveFuncs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
|
||||||
char *b4 = taosMemoryMalloc(varCodeLen);
|
char *b4 = taosMemoryMalloc(varCodeLen);
|
||||||
(void)memcpy(varDataVal(b4), pFunc->pCode, varCodeLen - VARSTR_HEADER_SIZE);
|
(void)memcpy(varDataVal(b4), pFunc->pCode, varCodeLen - VARSTR_HEADER_SIZE);
|
||||||
varDataSetLen(b4, varCodeLen - VARSTR_HEADER_SIZE);
|
varDataSetLen(b4, varCodeLen - VARSTR_HEADER_SIZE);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)b4, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)b4, false);
|
||||||
|
if (code < 0) {
|
||||||
|
sdbRelease(pSdb, pFunc);
|
||||||
|
taosMemoryFree(b4);
|
||||||
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
taosMemoryFree(b4);
|
taosMemoryFree(b4);
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pFunc->funcVersion, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)&pFunc->funcVersion, false), pSdb,
|
||||||
|
pFunc);
|
||||||
|
|
||||||
numOfRows++;
|
numOfRows++;
|
||||||
sdbRelease(pSdb, pFunc);
|
sdbRelease(pSdb, pFunc);
|
||||||
|
|
|
@ -85,7 +85,9 @@ static void *mndBuildTimerMsg(int32_t *pContLen) {
|
||||||
void *pReq = rpcMallocCont(contLen);
|
void *pReq = rpcMallocCont(contLen);
|
||||||
if (pReq == NULL) return NULL;
|
if (pReq == NULL) return NULL;
|
||||||
|
|
||||||
(void)tSerializeSMTimerMsg(pReq, contLen, &timerReq);
|
if (tSerializeSMTimerMsg(pReq, contLen, &timerReq) < 0) {
|
||||||
|
mError("failed to serialize timer msg since %s", terrstr());
|
||||||
|
}
|
||||||
*pContLen = contLen;
|
*pContLen = contLen;
|
||||||
return pReq;
|
return pReq;
|
||||||
}
|
}
|
||||||
|
@ -97,7 +99,9 @@ static void mndPullupTrans(SMnode *pMnode) {
|
||||||
if (pReq != NULL) {
|
if (pReq != NULL) {
|
||||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRANS_TIMER, .pCont = pReq, .contLen = contLen};
|
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRANS_TIMER, .pCont = pReq, .contLen = contLen};
|
||||||
// TODO check return value
|
// TODO check return value
|
||||||
(void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
|
if (tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg) < 0) {
|
||||||
|
mError("failed to put into write-queue since %s, line:%d", terrstr(), __LINE__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +112,9 @@ static void mndPullupCompacts(SMnode *pMnode) {
|
||||||
if (pReq != NULL) {
|
if (pReq != NULL) {
|
||||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_COMPACT_TIMER, .pCont = pReq, .contLen = contLen};
|
SRpcMsg rpcMsg = {.msgType = TDMT_MND_COMPACT_TIMER, .pCont = pReq, .contLen = contLen};
|
||||||
// TODO check return value
|
// TODO check return value
|
||||||
(void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
|
if (tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg) < 0) {
|
||||||
|
mError("failed to put into write-queue since %s, line:%d", terrstr(), __LINE__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +124,9 @@ static void mndPullupTtl(SMnode *pMnode) {
|
||||||
void *pReq = mndBuildTimerMsg(&contLen);
|
void *pReq = mndBuildTimerMsg(&contLen);
|
||||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TTL_TIMER, .pCont = pReq, .contLen = contLen};
|
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TTL_TIMER, .pCont = pReq, .contLen = contLen};
|
||||||
// TODO check return value
|
// TODO check return value
|
||||||
(void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
|
if (tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg) < 0) {
|
||||||
|
mError("failed to put into write-queue since %s, line:%d", terrstr(), __LINE__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mndPullupTrimDb(SMnode *pMnode) {
|
static void mndPullupTrimDb(SMnode *pMnode) {
|
||||||
|
@ -127,7 +135,9 @@ static void mndPullupTrimDb(SMnode *pMnode) {
|
||||||
void *pReq = mndBuildTimerMsg(&contLen);
|
void *pReq = mndBuildTimerMsg(&contLen);
|
||||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRIM_DB_TIMER, .pCont = pReq, .contLen = contLen};
|
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRIM_DB_TIMER, .pCont = pReq, .contLen = contLen};
|
||||||
// TODO check return value
|
// TODO check return value
|
||||||
(void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
|
if (tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg) < 0) {
|
||||||
|
mError("failed to put into write-queue since %s, line:%d", terrstr(), __LINE__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mndPullupS3MigrateDb(SMnode *pMnode) {
|
static void mndPullupS3MigrateDb(SMnode *pMnode) {
|
||||||
|
@ -136,7 +146,9 @@ static void mndPullupS3MigrateDb(SMnode *pMnode) {
|
||||||
void *pReq = mndBuildTimerMsg(&contLen);
|
void *pReq = mndBuildTimerMsg(&contLen);
|
||||||
// TODO check return value
|
// TODO check return value
|
||||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_S3MIGRATE_DB_TIMER, .pCont = pReq, .contLen = contLen};
|
SRpcMsg rpcMsg = {.msgType = TDMT_MND_S3MIGRATE_DB_TIMER, .pCont = pReq, .contLen = contLen};
|
||||||
(void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
|
if (tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg) < 0) {
|
||||||
|
mError("failed to put into write-queue since %s, line:%d", terrstr(), __LINE__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mndPullupArbHeartbeat(SMnode *pMnode) {
|
static int32_t mndPullupArbHeartbeat(SMnode *pMnode) {
|
||||||
|
@ -160,7 +172,9 @@ static void mndCalMqRebalance(SMnode *pMnode) {
|
||||||
void *pReq = mndBuildTimerMsg(&contLen);
|
void *pReq = mndBuildTimerMsg(&contLen);
|
||||||
if (pReq != NULL) {
|
if (pReq != NULL) {
|
||||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TMQ_TIMER, .pCont = pReq, .contLen = contLen};
|
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TMQ_TIMER, .pCont = pReq, .contLen = contLen};
|
||||||
(void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
|
if (tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg) < 0) {
|
||||||
|
mError("failed to put into write-queue since %s, line:%d", terrstr(), __LINE__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +184,9 @@ static void mndStreamCheckpointTimer(SMnode *pMnode) {
|
||||||
int32_t size = sizeof(SMStreamDoCheckpointMsg);
|
int32_t size = sizeof(SMStreamDoCheckpointMsg);
|
||||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_STREAM_BEGIN_CHECKPOINT, .pCont = pMsg, .contLen = size};
|
SRpcMsg rpcMsg = {.msgType = TDMT_MND_STREAM_BEGIN_CHECKPOINT, .pCont = pMsg, .contLen = size};
|
||||||
// TODO check return value
|
// TODO check return value
|
||||||
(void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
|
if (tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg) < 0) {
|
||||||
|
mError("failed to put into write-queue since %s, line:%d", terrstr(), __LINE__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,7 +196,9 @@ static void mndStreamCheckNode(SMnode *pMnode) {
|
||||||
if (pReq != NULL) {
|
if (pReq != NULL) {
|
||||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_NODECHECK_TIMER, .pCont = pReq, .contLen = contLen};
|
SRpcMsg rpcMsg = {.msgType = TDMT_MND_NODECHECK_TIMER, .pCont = pReq, .contLen = contLen};
|
||||||
// TODO check return value
|
// TODO check return value
|
||||||
(void)tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg);
|
if (tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg) < 0) {
|
||||||
|
mError("failed to put into read-queue since %s, line:%d", terrstr(), __LINE__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +208,9 @@ static void mndStreamConsensusChkpt(SMnode *pMnode) {
|
||||||
if (pReq != NULL) {
|
if (pReq != NULL) {
|
||||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_STREAM_CONSEN_TIMER, .pCont = pReq, .contLen = contLen};
|
SRpcMsg rpcMsg = {.msgType = TDMT_MND_STREAM_CONSEN_TIMER, .pCont = pReq, .contLen = contLen};
|
||||||
// TODO check return value
|
// TODO check return value
|
||||||
(void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
|
if (tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg) < 0) {
|
||||||
|
mError("failed to put into write-queue since %s, line:%d", terrstr(), __LINE__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,7 +221,9 @@ static void mndPullupTelem(SMnode *pMnode) {
|
||||||
if (pReq != NULL) {
|
if (pReq != NULL) {
|
||||||
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TELEM_TIMER, .pCont = pReq, .contLen = contLen};
|
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TELEM_TIMER, .pCont = pReq, .contLen = contLen};
|
||||||
// TODO check return value
|
// TODO check return value
|
||||||
(void)tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg);
|
if (tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg) < 0) {
|
||||||
|
mError("failed to put into read-queue since %s, line:%d", terrstr(), __LINE__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +238,9 @@ static void mndPullupGrant(SMnode *pMnode) {
|
||||||
.info.notFreeAhandle = 1,
|
.info.notFreeAhandle = 1,
|
||||||
.info.ahandle = (void *)0x9527};
|
.info.ahandle = (void *)0x9527};
|
||||||
// TODO check return value
|
// TODO check return value
|
||||||
(void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
|
if (tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg) < 0) {
|
||||||
|
mError("failed to put into write-queue since %s, line:%d", terrstr(), __LINE__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +255,9 @@ static void mndIncreaseUpTime(SMnode *pMnode) {
|
||||||
.info.notFreeAhandle = 1,
|
.info.notFreeAhandle = 1,
|
||||||
.info.ahandle = (void *)0x9527};
|
.info.ahandle = (void *)0x9527};
|
||||||
// TODO check return value
|
// TODO check return value
|
||||||
(void)tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
|
if (tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg) < 0) {
|
||||||
|
mError("failed to put into write-queue since %s, line:%d", terrstr(), __LINE__);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -682,7 +708,13 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
|
||||||
}
|
}
|
||||||
|
|
||||||
char timestr[24] = "1970-01-01 00:00:00.00";
|
char timestr[24] = "1970-01-01 00:00:00.00";
|
||||||
(void)taosParseTime(timestr, &pMnode->checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
|
code = taosParseTime(timestr, &pMnode->checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("failed to parse time since %s", tstrerror(code));
|
||||||
|
(void)taosThreadRwlockDestroy(&pMnode->lock);
|
||||||
|
taosMemoryFree(pMnode);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
mndSetOptions(pMnode, pOption);
|
mndSetOptions(pMnode, pOption);
|
||||||
|
|
||||||
pMnode->deploy = pOption->deploy;
|
pMnode->deploy = pOption->deploy;
|
||||||
|
@ -727,10 +759,17 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
|
||||||
|
|
||||||
void mndPreClose(SMnode *pMnode) {
|
void mndPreClose(SMnode *pMnode) {
|
||||||
if (pMnode != NULL) {
|
if (pMnode != NULL) {
|
||||||
|
int32_t code = 0;
|
||||||
// TODO check return value
|
// TODO check return value
|
||||||
(void)syncLeaderTransfer(pMnode->syncMgmt.sync);
|
code = syncLeaderTransfer(pMnode->syncMgmt.sync);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("failed to transfer leader since %s", tstrerror(code));
|
||||||
|
}
|
||||||
syncPreStop(pMnode->syncMgmt.sync);
|
syncPreStop(pMnode->syncMgmt.sync);
|
||||||
(void)sdbWriteFile(pMnode->pSdb, 0);
|
code = sdbWriteFile(pMnode->pSdb, 0);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("failed to write sdb since %s", tstrerror(code));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -878,7 +917,9 @@ _OVER:
|
||||||
int32_t contLen = tSerializeSEpSet(NULL, 0, &epSet);
|
int32_t contLen = tSerializeSEpSet(NULL, 0, &epSet);
|
||||||
pMsg->info.rsp = rpcMallocCont(contLen);
|
pMsg->info.rsp = rpcMallocCont(contLen);
|
||||||
if (pMsg->info.rsp != NULL) {
|
if (pMsg->info.rsp != NULL) {
|
||||||
(void)tSerializeSEpSet(pMsg->info.rsp, contLen, &epSet);
|
if (tSerializeSEpSet(pMsg->info.rsp, contLen, &epSet) < 0) {
|
||||||
|
mError("failed to serialize ep set");
|
||||||
|
}
|
||||||
pMsg->info.hasEpSet = 1;
|
pMsg->info.hasEpSet = 1;
|
||||||
pMsg->info.rspLen = contLen;
|
pMsg->info.rspLen = contLen;
|
||||||
}
|
}
|
||||||
|
@ -1045,7 +1086,12 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr
|
||||||
desc.vgroup_id = pVgroup->vgId;
|
desc.vgroup_id = pVgroup->vgId;
|
||||||
|
|
||||||
SName name = {0};
|
SName name = {0};
|
||||||
(void)tNameFromString(&name, pVgroup->dbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
code = tNameFromString(&name, pVgroup->dbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("failed to get db name since %s", tstrerror(code));
|
||||||
|
sdbRelease(pSdb, pVgroup);
|
||||||
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
(void)tNameGetDbName(&name, desc.database_name);
|
(void)tNameGetDbName(&name, desc.database_name);
|
||||||
|
|
||||||
desc.tables_num = pVgroup->numOfTables;
|
desc.tables_num = pVgroup->numOfTables;
|
||||||
|
@ -1083,11 +1129,21 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr
|
||||||
SMonStbDesc desc = {0};
|
SMonStbDesc desc = {0};
|
||||||
|
|
||||||
SName name1 = {0};
|
SName name1 = {0};
|
||||||
(void)tNameFromString(&name1, pStb->db, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
code = tNameFromString(&name1, pStb->db, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("failed to get db name since %s", tstrerror(code));
|
||||||
|
sdbRelease(pSdb, pStb);
|
||||||
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
(void)tNameGetDbName(&name1, desc.database_name);
|
(void)tNameGetDbName(&name1, desc.database_name);
|
||||||
|
|
||||||
SName name2 = {0};
|
SName name2 = {0};
|
||||||
(void)tNameFromString(&name2, pStb->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
code = tNameFromString(&name2, pStb->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("failed to get table name since %s", tstrerror(code));
|
||||||
|
sdbRelease(pSdb, pStb);
|
||||||
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
tstrncpy(desc.stb_name, tNameGetTableName(&name2), TSDB_TABLE_NAME_LEN);
|
tstrncpy(desc.stb_name, tNameGetTableName(&name2), TSDB_TABLE_NAME_LEN);
|
||||||
|
|
||||||
if (taosArrayPush(pStbInfo->stbs, &desc) == NULL) {
|
if (taosArrayPush(pStbInfo->stbs, &desc) == NULL) {
|
||||||
|
|
|
@ -14,12 +14,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndProfile.h"
|
|
||||||
#include "audit.h"
|
#include "audit.h"
|
||||||
#include "mndDb.h"
|
#include "mndDb.h"
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndMnode.h"
|
#include "mndMnode.h"
|
||||||
#include "mndPrivilege.h"
|
#include "mndPrivilege.h"
|
||||||
|
#include "mndProfile.h"
|
||||||
#include "mndQnode.h"
|
#include "mndQnode.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
#include "mndSma.h"
|
#include "mndSma.h"
|
||||||
|
@ -377,7 +377,8 @@ static SAppObj *mndCreateApp(SMnode *pMnode, uint32_t clientIp, SAppHbReq *pReq)
|
||||||
(void)memcpy(&app.summary, &pReq->summary, sizeof(pReq->summary));
|
(void)memcpy(&app.summary, &pReq->summary, sizeof(pReq->summary));
|
||||||
app.lastAccessTimeMs = taosGetTimestampMs();
|
app.lastAccessTimeMs = taosGetTimestampMs();
|
||||||
|
|
||||||
SAppObj *pApp = taosCachePut(pMgmt->appCache, &pReq->appId, sizeof(pReq->appId), &app, sizeof(app), CACHE_OBJ_KEEP_TIME * 1000);
|
SAppObj *pApp =
|
||||||
|
taosCachePut(pMgmt->appCache, &pReq->appId, sizeof(pReq->appId), &app, sizeof(app), CACHE_OBJ_KEEP_TIME * 1000);
|
||||||
if (pApp == NULL) {
|
if (pApp == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
mError("failed to app %" PRIx64 " into cache since %s", pReq->appId, terrstr());
|
mError("failed to app %" PRIx64 " into cache since %s", pReq->appId, terrstr());
|
||||||
|
@ -841,6 +842,7 @@ static int32_t mndRetrieveConns(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
int32_t numOfRows = 0;
|
int32_t numOfRows = 0;
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
|
int32_t code = 0;
|
||||||
SConnObj *pConn = NULL;
|
SConnObj *pConn = NULL;
|
||||||
|
|
||||||
if (pShow->pIter == NULL) {
|
if (pShow->pIter == NULL) {
|
||||||
|
@ -863,32 +865,60 @@ static int32_t mndRetrieveConns(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
|
||||||
cols = 0;
|
cols = 0;
|
||||||
|
|
||||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->id, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->id, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set conn id:%u since %s", pConn->id, tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
char user[TSDB_USER_LEN + VARSTR_HEADER_SIZE] = {0};
|
char user[TSDB_USER_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
STR_TO_VARSTR(user, pConn->user);
|
STR_TO_VARSTR(user, pConn->user);
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)user, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)user, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set user since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
char app[TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE];
|
char app[TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE];
|
||||||
STR_TO_VARSTR(app, pConn->app);
|
STR_TO_VARSTR(app, pConn->app);
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)app, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)app, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set app since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->pid, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->pid, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set conn id:%u since %s", pConn->id, tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
char endpoint[TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE] = {0};
|
char endpoint[TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE] = {0};
|
||||||
(void)sprintf(&endpoint[VARSTR_HEADER_SIZE], "%s:%d", taosIpStr(pConn->ip), pConn->port);
|
(void)sprintf(&endpoint[VARSTR_HEADER_SIZE], "%s:%d", taosIpStr(pConn->ip), pConn->port);
|
||||||
varDataLen(endpoint) = strlen(&endpoint[VARSTR_HEADER_SIZE]);
|
varDataLen(endpoint) = strlen(&endpoint[VARSTR_HEADER_SIZE]);
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)endpoint, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)endpoint, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set endpoint since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->loginTimeMs, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->loginTimeMs, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set login time since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->lastAccessTimeMs, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->lastAccessTimeMs, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set last access time since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
numOfRows++;
|
numOfRows++;
|
||||||
}
|
}
|
||||||
|
@ -907,6 +937,7 @@ static int32_t mndRetrieveConns(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
|
||||||
static int32_t packQueriesIntoBlock(SShowObj *pShow, SConnObj *pConn, SSDataBlock *pBlock, uint32_t offset,
|
static int32_t packQueriesIntoBlock(SShowObj *pShow, SConnObj *pConn, SSDataBlock *pBlock, uint32_t offset,
|
||||||
uint32_t rowsToPack) {
|
uint32_t rowsToPack) {
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
|
int32_t code = 0;
|
||||||
taosRLockLatch(&pConn->queryLock);
|
taosRLockLatch(&pConn->queryLock);
|
||||||
int32_t numOfQueries = taosArrayGetSize(pConn->pQueries);
|
int32_t numOfQueries = taosArrayGetSize(pConn->pQueries);
|
||||||
if (NULL == pConn->pQueries || numOfQueries <= offset) {
|
if (NULL == pConn->pQueries || numOfQueries <= offset) {
|
||||||
|
@ -924,47 +955,107 @@ static int32_t packQueriesIntoBlock(SShowObj *pShow, SConnObj *pConn, SSDataBloc
|
||||||
(void)sprintf(&queryId[VARSTR_HEADER_SIZE], "%x:%" PRIx64, pConn->id, pQuery->reqRid);
|
(void)sprintf(&queryId[VARSTR_HEADER_SIZE], "%x:%" PRIx64, pConn->id, pQuery->reqRid);
|
||||||
varDataLen(queryId) = strlen(&queryId[VARSTR_HEADER_SIZE]);
|
varDataLen(queryId) = strlen(&queryId[VARSTR_HEADER_SIZE]);
|
||||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, curRowIndex, (const char *)queryId, false);
|
code = colDataSetVal(pColInfo, curRowIndex, (const char *)queryId, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set query id:%s since %s", queryId, tstrerror(code));
|
||||||
|
taosRUnLockLatch(&pConn->queryLock);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->queryId, false);
|
code = colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->queryId, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set query id:%" PRIx64 " since %s", pQuery->queryId, tstrerror(code));
|
||||||
|
taosRUnLockLatch(&pConn->queryLock);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, curRowIndex, (const char *)&pConn->id, false);
|
code = colDataSetVal(pColInfo, curRowIndex, (const char *)&pConn->id, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set conn id:%u since %s", pConn->id, tstrerror(code));
|
||||||
|
taosRUnLockLatch(&pConn->queryLock);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
char app[TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE];
|
char app[TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE];
|
||||||
STR_TO_VARSTR(app, pConn->app);
|
STR_TO_VARSTR(app, pConn->app);
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, curRowIndex, (const char *)app, false);
|
code = colDataSetVal(pColInfo, curRowIndex, (const char *)app, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set app since %s", tstrerror(code));
|
||||||
|
taosRUnLockLatch(&pConn->queryLock);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, curRowIndex, (const char *)&pConn->pid, false);
|
code = colDataSetVal(pColInfo, curRowIndex, (const char *)&pConn->pid, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set conn id:%u since %s", pConn->id, tstrerror(code));
|
||||||
|
taosRUnLockLatch(&pConn->queryLock);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
char user[TSDB_USER_LEN + VARSTR_HEADER_SIZE] = {0};
|
char user[TSDB_USER_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
STR_TO_VARSTR(user, pConn->user);
|
STR_TO_VARSTR(user, pConn->user);
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, curRowIndex, (const char *)user, false);
|
code = colDataSetVal(pColInfo, curRowIndex, (const char *)user, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set user since %s", tstrerror(code));
|
||||||
|
taosRUnLockLatch(&pConn->queryLock);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
char endpoint[TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE] = {0};
|
char endpoint[TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE] = {0};
|
||||||
(void)sprintf(&endpoint[VARSTR_HEADER_SIZE], "%s:%d", taosIpStr(pConn->ip), pConn->port);
|
(void)sprintf(&endpoint[VARSTR_HEADER_SIZE], "%s:%d", taosIpStr(pConn->ip), pConn->port);
|
||||||
varDataLen(endpoint) = strlen(&endpoint[VARSTR_HEADER_SIZE]);
|
varDataLen(endpoint) = strlen(&endpoint[VARSTR_HEADER_SIZE]);
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, curRowIndex, (const char *)endpoint, false);
|
code = colDataSetVal(pColInfo, curRowIndex, (const char *)endpoint, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set endpoint since %s", tstrerror(code));
|
||||||
|
taosRUnLockLatch(&pConn->queryLock);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->stime, false);
|
code = colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->stime, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set start time since %s", tstrerror(code));
|
||||||
|
taosRUnLockLatch(&pConn->queryLock);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->useconds, false);
|
code = colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->useconds, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set useconds since %s", tstrerror(code));
|
||||||
|
taosRUnLockLatch(&pConn->queryLock);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->stableQuery, false);
|
code = colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->stableQuery, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set stable query since %s", tstrerror(code));
|
||||||
|
taosRUnLockLatch(&pConn->queryLock);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->isSubQuery, false);
|
code = colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->isSubQuery, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set sub query since %s", tstrerror(code));
|
||||||
|
taosRUnLockLatch(&pConn->queryLock);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->subPlanNum, false);
|
code = colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->subPlanNum, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set sub plan num since %s", tstrerror(code));
|
||||||
|
taosRUnLockLatch(&pConn->queryLock);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
char subStatus[TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE] = {0};
|
char subStatus[TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
int64_t reserve = 64;
|
int64_t reserve = 64;
|
||||||
|
@ -983,12 +1074,22 @@ static int32_t packQueriesIntoBlock(SShowObj *pShow, SConnObj *pConn, SSDataBloc
|
||||||
}
|
}
|
||||||
varDataLen(subStatus) = strlen(&subStatus[VARSTR_HEADER_SIZE]);
|
varDataLen(subStatus) = strlen(&subStatus[VARSTR_HEADER_SIZE]);
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, curRowIndex, subStatus, (varDataLen(subStatus) == 0) ? true : false);
|
code = colDataSetVal(pColInfo, curRowIndex, subStatus, (varDataLen(subStatus) == 0) ? true : false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set sub status since %s", tstrerror(code));
|
||||||
|
taosRUnLockLatch(&pConn->queryLock);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
char sql[TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE] = {0};
|
char sql[TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
STR_TO_VARSTR(sql, pQuery->sql);
|
STR_TO_VARSTR(sql, pQuery->sql);
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, curRowIndex, (const char *)sql, false);
|
code = colDataSetVal(pColInfo, curRowIndex, (const char *)sql, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set sql since %s", tstrerror(code));
|
||||||
|
taosRUnLockLatch(&pConn->queryLock);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pBlock->info.rows++;
|
pBlock->info.rows++;
|
||||||
}
|
}
|
||||||
|
@ -1040,6 +1141,7 @@ static int32_t mndRetrieveApps(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlo
|
||||||
int32_t numOfRows = 0;
|
int32_t numOfRows = 0;
|
||||||
int32_t cols = 0;
|
int32_t cols = 0;
|
||||||
SAppObj *pApp = NULL;
|
SAppObj *pApp = NULL;
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
if (pShow->pIter == NULL) {
|
if (pShow->pIter == NULL) {
|
||||||
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
|
||||||
|
@ -1057,55 +1159,115 @@ static int32_t mndRetrieveApps(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlo
|
||||||
cols = 0;
|
cols = 0;
|
||||||
|
|
||||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->appId, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->appId, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set app id since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
char ip[TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE] = {0};
|
char ip[TSDB_IPv4ADDR_LEN + 6 + VARSTR_HEADER_SIZE] = {0};
|
||||||
(void)sprintf(&ip[VARSTR_HEADER_SIZE], "%s", taosIpStr(pApp->ip));
|
(void)sprintf(&ip[VARSTR_HEADER_SIZE], "%s", taosIpStr(pApp->ip));
|
||||||
varDataLen(ip) = strlen(&ip[VARSTR_HEADER_SIZE]);
|
varDataLen(ip) = strlen(&ip[VARSTR_HEADER_SIZE]);
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)ip, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)ip, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set ip since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->pid, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->pid, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set pid since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
char name[TSDB_APP_NAME_LEN + 6 + VARSTR_HEADER_SIZE] = {0};
|
char name[TSDB_APP_NAME_LEN + 6 + VARSTR_HEADER_SIZE] = {0};
|
||||||
(void)sprintf(&name[VARSTR_HEADER_SIZE], "%s", pApp->name);
|
(void)sprintf(&name[VARSTR_HEADER_SIZE], "%s", pApp->name);
|
||||||
varDataLen(name) = strlen(&name[VARSTR_HEADER_SIZE]);
|
varDataLen(name) = strlen(&name[VARSTR_HEADER_SIZE]);
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)name, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)name, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set app name since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->startTime, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->startTime, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set start time since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.numOfInsertsReq, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.numOfInsertsReq, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set insert req since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.numOfInsertRows, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.numOfInsertRows, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set insert rows since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.insertElapsedTime, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.insertElapsedTime, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set insert elapsed time since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.insertBytes, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.insertBytes, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set insert bytes since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.fetchBytes, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.fetchBytes, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set fetch bytes since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.queryElapsedTime, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.queryElapsedTime, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set query elapsed time since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.numOfSlowQueries, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.numOfSlowQueries, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set slow queries since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.totalRequests, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.totalRequests, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set total requests since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.currentRequests, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.currentRequests, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set current requests since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->lastAccessTimeMs, false);
|
code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->lastAccessTimeMs, false);
|
||||||
|
if (code != 0) {
|
||||||
|
mError("failed to set last access time since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
numOfRows++;
|
numOfRows++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,13 +14,13 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndQnode.h"
|
#include "audit.h"
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndPrivilege.h"
|
#include "mndPrivilege.h"
|
||||||
|
#include "mndQnode.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
#include "mndUser.h"
|
#include "mndUser.h"
|
||||||
#include "audit.h"
|
|
||||||
|
|
||||||
#define QNODE_VER_NUMBER 1
|
#define QNODE_VER_NUMBER 1
|
||||||
#define QNODE_RESERVE_SIZE 64
|
#define QNODE_RESERVE_SIZE 64
|
||||||
|
@ -209,9 +209,7 @@ int32_t mndSetCreateQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) {
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mndQnodeInDnode(SQnodeObj *pQnode, int32_t dnodeId) {
|
bool mndQnodeInDnode(SQnodeObj *pQnode, int32_t dnodeId) { return pQnode->pDnode->id == dnodeId; }
|
||||||
return pQnode->pDnode->id == dnodeId;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) {
|
int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
@ -224,8 +222,10 @@ int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeOb
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
(void)tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
|
code = tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("qnode:%d, failed to serialize create drop qnode request since %s", createReq.dnodeId, terrstr());
|
||||||
|
}
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
action.epSet = mndGetDnodeEpset(pDnode);
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
action.pCont = pReq;
|
action.pCont = pReq;
|
||||||
|
@ -252,7 +252,10 @@ static int32_t mndSetCreateQnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, S
|
||||||
code = terrno;
|
code = terrno;
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
(void)tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
|
code = tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("qnode:%d, failed to serialize create drop qnode request since %s", dropReq.dnodeId, terrstr());
|
||||||
|
}
|
||||||
|
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
action.epSet = mndGetDnodeEpset(pDnode);
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
|
@ -383,7 +386,10 @@ static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQn
|
||||||
code = terrno;
|
code = terrno;
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
(void)tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
|
code = tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("qnode:%d, failed to serialize create drop qnode request since %s", dropReq.dnodeId, terrstr());
|
||||||
|
}
|
||||||
|
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
action.epSet = mndGetDnodeEpset(pDnode);
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
|
@ -536,7 +542,10 @@ static int32_t mndProcessQnodeListReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)tSerializeSQnodeListRsp(pRsp, rspLen, &qlistRsp);
|
code = tSerializeSQnodeListRsp(pRsp, rspLen, &qlistRsp);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("failed to serialize qnode list response since %s", terrstr());
|
||||||
|
}
|
||||||
|
|
||||||
pReq->info.rspLen = rspLen;
|
pReq->info.rspLen = rspLen;
|
||||||
pReq->info.rsp = pRsp;
|
pReq->info.rsp = pRsp;
|
||||||
|
@ -561,15 +570,16 @@ static int32_t mndRetrieveQnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
|
||||||
|
|
||||||
cols = 0;
|
cols = 0;
|
||||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->id, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->id, false), pSdb, pObj);
|
||||||
|
|
||||||
char ep[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0};
|
char ep[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
STR_WITH_MAXSIZE_TO_VARSTR(ep, pObj->pDnode->ep, pShow->pMeta->pSchemas[cols].bytes);
|
STR_WITH_MAXSIZE_TO_VARSTR(ep, pObj->pDnode->ep, pShow->pMeta->pSchemas[cols].bytes);
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)ep, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)ep, false), pSdb, pObj);
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->createdTime, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->createdTime, false), pSdb,
|
||||||
|
pObj);
|
||||||
|
|
||||||
numOfRows++;
|
numOfRows++;
|
||||||
sdbRelease(pSdb, pObj);
|
sdbRelease(pSdb, pObj);
|
||||||
|
|
|
@ -14,10 +14,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "mndSnode.h"
|
|
||||||
#include "mndDnode.h"
|
#include "mndDnode.h"
|
||||||
#include "mndPrivilege.h"
|
#include "mndPrivilege.h"
|
||||||
#include "mndShow.h"
|
#include "mndShow.h"
|
||||||
|
#include "mndSnode.h"
|
||||||
#include "mndTrans.h"
|
#include "mndTrans.h"
|
||||||
#include "mndUser.h"
|
#include "mndUser.h"
|
||||||
|
|
||||||
|
@ -223,7 +223,10 @@ static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S
|
||||||
code = terrno;
|
code = terrno;
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
(void)tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
|
code = tSerializeSCreateDropMQSNodeReq(pReq, contLen, &createReq);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("snode:%d, failed to serialize create drop snode request since %s", createReq.dnodeId, terrstr());
|
||||||
|
}
|
||||||
|
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
action.epSet = mndGetDnodeEpset(pDnode);
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
|
@ -251,7 +254,10 @@ static int32_t mndSetCreateSnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, S
|
||||||
code = terrno;
|
code = terrno;
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
(void)tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
|
code = tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("snode:%d, failed to serialize create drop snode request since %s", dropReq.dnodeId, terrstr());
|
||||||
|
}
|
||||||
|
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
action.epSet = mndGetDnodeEpset(pDnode);
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
|
@ -383,7 +389,10 @@ static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSn
|
||||||
code = terrno;
|
code = terrno;
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
(void)tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
|
code = tSerializeSCreateDropMQSNodeReq(pReq, contLen, &dropReq);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("snode:%d, failed to serialize create drop snode request since %s", dropReq.dnodeId, terrstr());
|
||||||
|
}
|
||||||
|
|
||||||
STransAction action = {0};
|
STransAction action = {0};
|
||||||
action.epSet = mndGetDnodeEpset(pDnode);
|
action.epSet = mndGetDnodeEpset(pDnode);
|
||||||
|
@ -482,16 +491,17 @@ static int32_t mndRetrieveSnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
|
||||||
|
|
||||||
cols = 0;
|
cols = 0;
|
||||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->id, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->id, false), pSdb, pObj);
|
||||||
|
|
||||||
char ep[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0};
|
char ep[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
STR_WITH_MAXSIZE_TO_VARSTR(ep, pObj->pDnode->ep, pShow->pMeta->pSchemas[cols].bytes);
|
STR_WITH_MAXSIZE_TO_VARSTR(ep, pObj->pDnode->ep, pShow->pMeta->pSchemas[cols].bytes);
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)ep, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)ep, false), pSdb, pObj);
|
||||||
|
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->createdTime, false);
|
TAOS_CHECK_RETURN_WITH_RELEASE(colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->createdTime, false), pSdb,
|
||||||
|
pObj);
|
||||||
|
|
||||||
numOfRows++;
|
numOfRows++;
|
||||||
sdbRelease(pSdb, pObj);
|
sdbRelease(pSdb, pObj);
|
||||||
|
|
|
@ -221,13 +221,17 @@ _OVER:
|
||||||
}
|
}
|
||||||
int32_t ipWhiteMgtRemove(char *user) {
|
int32_t ipWhiteMgtRemove(char *user) {
|
||||||
bool update = true;
|
bool update = true;
|
||||||
|
int32_t code = 0;
|
||||||
(void)taosThreadRwlockWrlock(&ipWhiteMgt.rw);
|
(void)taosThreadRwlockWrlock(&ipWhiteMgt.rw);
|
||||||
SIpWhiteList **ppList = taosHashGet(ipWhiteMgt.pIpWhiteTab, user, strlen(user));
|
SIpWhiteList **ppList = taosHashGet(ipWhiteMgt.pIpWhiteTab, user, strlen(user));
|
||||||
if (ppList == NULL || *ppList == NULL) {
|
if (ppList == NULL || *ppList == NULL) {
|
||||||
update = false;
|
update = false;
|
||||||
} else {
|
} else {
|
||||||
taosMemoryFree(*ppList);
|
taosMemoryFree(*ppList);
|
||||||
(void)taosHashRemove(ipWhiteMgt.pIpWhiteTab, user, strlen(user));
|
code = taosHashRemove(ipWhiteMgt.pIpWhiteTab, user, strlen(user));
|
||||||
|
if (code != 0) {
|
||||||
|
update = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (update) ipWhiteMgt.ver++;
|
if (update) ipWhiteMgt.ver++;
|
||||||
|
@ -391,7 +395,9 @@ int32_t mndUpdateIpWhiteImpl(SHashObj *pIpWhiteTab, char *user, char *fqdn, int8
|
||||||
if (pList != NULL) {
|
if (pList != NULL) {
|
||||||
if (isRangeInWhiteList(pList, &range)) {
|
if (isRangeInWhiteList(pList, &range)) {
|
||||||
if (pList->num == 1) {
|
if (pList->num == 1) {
|
||||||
(void)taosHashRemove(pIpWhiteTab, user, strlen(user));
|
if (taosHashRemove(pIpWhiteTab, user, strlen(user)) < 0) {
|
||||||
|
mError("failed to remove ip-white-list for user: %s at line %d", user, lino);
|
||||||
|
}
|
||||||
taosMemoryFree(pList);
|
taosMemoryFree(pList);
|
||||||
} else {
|
} else {
|
||||||
int32_t idx = 0;
|
int32_t idx = 0;
|
||||||
|
@ -842,6 +848,7 @@ static int32_t createDefaultIpWhiteList(SIpWhiteList **ppWhiteList) {
|
||||||
|
|
||||||
static int32_t mndCreateDefaultUser(SMnode *pMnode, char *acct, char *user, char *pass) {
|
static int32_t mndCreateDefaultUser(SMnode *pMnode, char *acct, char *user, char *pass) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino = 0;
|
||||||
SUserObj userObj = {0};
|
SUserObj userObj = {0};
|
||||||
taosEncryptPass_c((uint8_t *)pass, strlen(pass), userObj.pass);
|
taosEncryptPass_c((uint8_t *)pass, strlen(pass), userObj.pass);
|
||||||
tstrncpy(userObj.user, user, TSDB_USER_LEN);
|
tstrncpy(userObj.user, user, TSDB_USER_LEN);
|
||||||
|
@ -859,7 +866,7 @@ static int32_t mndCreateDefaultUser(SMnode *pMnode, char *acct, char *user, char
|
||||||
|
|
||||||
SSdbRaw *pRaw = mndUserActionEncode(&userObj);
|
SSdbRaw *pRaw = mndUserActionEncode(&userObj);
|
||||||
if (pRaw == NULL) goto _ERROR;
|
if (pRaw == NULL) goto _ERROR;
|
||||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
TAOS_CHECK_GOTO(sdbSetRawStatus(pRaw, SDB_STATUS_READY), &lino, _ERROR);
|
||||||
|
|
||||||
mInfo("user:%s, will be created when deploying, raw:%p", userObj.user, pRaw);
|
mInfo("user:%s, will be created when deploying, raw:%p", userObj.user, pRaw);
|
||||||
|
|
||||||
|
@ -876,7 +883,7 @@ static int32_t mndCreateDefaultUser(SMnode *pMnode, char *acct, char *user, char
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
goto _ERROR;
|
goto _ERROR;
|
||||||
}
|
}
|
||||||
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
|
TAOS_CHECK_GOTO(sdbSetRawStatus(pRaw, SDB_STATUS_READY), &lino, _ERROR);
|
||||||
|
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||||
|
@ -1775,7 +1782,7 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, SCreateUserReq *pCreate
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER);
|
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER);
|
||||||
}
|
}
|
||||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
TAOS_CHECK_GOTO(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY), &lino, _OVER);
|
||||||
|
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||||
|
@ -1990,7 +1997,11 @@ static int32_t mndAlterUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SRpc
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
TAOS_RETURN(terrno);
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
code = sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||||
|
if (code < 0) {
|
||||||
|
mndTransDrop(pTrans);
|
||||||
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||||
|
@ -2189,7 +2200,10 @@ static int32_t mndProcessAlterUserPrivilegesReq(SAlterUserReq *pAlterReq, SMnode
|
||||||
mndReleaseDb(pMnode, pDb);
|
mndReleaseDb(pMnode, pDb);
|
||||||
TAOS_CHECK_GOTO(terrno, &lino, _OVER); // TODO: refactor the terrno to code
|
TAOS_CHECK_GOTO(terrno, &lino, _OVER); // TODO: refactor the terrno to code
|
||||||
}
|
}
|
||||||
(void)taosHashRemove(pNewUser->readDbs, pAlterReq->objname, len);
|
code = taosHashRemove(pNewUser->readDbs, pAlterReq->objname, len);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("read db:%s, failed to remove db:%s since %s", pNewUser->user, pAlterReq->objname, terrstr());
|
||||||
|
}
|
||||||
mndReleaseDb(pMnode, pDb);
|
mndReleaseDb(pMnode, pDb);
|
||||||
} else {
|
} else {
|
||||||
taosHashClear(pNewUser->readDbs);
|
taosHashClear(pNewUser->readDbs);
|
||||||
|
@ -2205,7 +2219,10 @@ static int32_t mndProcessAlterUserPrivilegesReq(SAlterUserReq *pAlterReq, SMnode
|
||||||
mndReleaseDb(pMnode, pDb);
|
mndReleaseDb(pMnode, pDb);
|
||||||
TAOS_CHECK_GOTO(terrno, &lino, _OVER); // TODO: refactor the terrno to code
|
TAOS_CHECK_GOTO(terrno, &lino, _OVER); // TODO: refactor the terrno to code
|
||||||
}
|
}
|
||||||
(void)taosHashRemove(pNewUser->writeDbs, pAlterReq->objname, len);
|
code = taosHashRemove(pNewUser->writeDbs, pAlterReq->objname, len);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("user:%s, failed to remove db:%s since %s", pNewUser->user, pAlterReq->objname, terrstr());
|
||||||
|
}
|
||||||
mndReleaseDb(pMnode, pDb);
|
mndReleaseDb(pMnode, pDb);
|
||||||
} else {
|
} else {
|
||||||
taosHashClear(pNewUser->writeDbs);
|
taosHashClear(pNewUser->writeDbs);
|
||||||
|
@ -2275,7 +2292,10 @@ static int32_t mndProcessAlterUserPrivilegesReq(SAlterUserReq *pAlterReq, SMnode
|
||||||
mndReleaseTopic(pMnode, pTopic);
|
mndReleaseTopic(pMnode, pTopic);
|
||||||
TAOS_CHECK_GOTO(code, &lino, _OVER);
|
TAOS_CHECK_GOTO(code, &lino, _OVER);
|
||||||
}
|
}
|
||||||
(void)taosHashRemove(pNewUser->topics, pAlterReq->objname, len);
|
code = taosHashRemove(pNewUser->topics, pAlterReq->objname, len);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("user:%s, failed to remove topic:%s since %s", pNewUser->user, pAlterReq->objname, tstrerror(code));
|
||||||
|
}
|
||||||
mndReleaseTopic(pMnode, pTopic);
|
mndReleaseTopic(pMnode, pTopic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2461,7 +2481,7 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
|
||||||
ALTER_USER_ADD_ALL_TB_PRIV(alterReq.alterType, alterReq.privileges, alterReq.tabName)) {
|
ALTER_USER_ADD_ALL_TB_PRIV(alterReq.alterType, alterReq.privileges, alterReq.tabName)) {
|
||||||
if (strcmp(alterReq.objname, "1.*") != 0) {
|
if (strcmp(alterReq.objname, "1.*") != 0) {
|
||||||
SName name = {0};
|
SName name = {0};
|
||||||
(void)tNameFromString(&name, alterReq.objname, T_NAME_ACCT | T_NAME_DB);
|
TAOS_CHECK_GOTO(tNameFromString(&name, alterReq.objname, T_NAME_ACCT | T_NAME_DB), &lino, _OVER);
|
||||||
auditRecord(pReq, pMnode->clusterId, "GrantPrivileges", name.dbname, alterReq.user, alterReq.sql,
|
auditRecord(pReq, pMnode->clusterId, "GrantPrivileges", name.dbname, alterReq.user, alterReq.sql,
|
||||||
alterReq.sqlLen);
|
alterReq.sqlLen);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2476,7 +2496,7 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
|
||||||
} else {
|
} else {
|
||||||
if (strcmp(alterReq.objname, "1.*") != 0) {
|
if (strcmp(alterReq.objname, "1.*") != 0) {
|
||||||
SName name = {0};
|
SName name = {0};
|
||||||
(void)tNameFromString(&name, alterReq.objname, T_NAME_ACCT | T_NAME_DB);
|
TAOS_CHECK_GOTO(tNameFromString(&name, alterReq.objname, T_NAME_ACCT | T_NAME_DB), &lino, _OVER);
|
||||||
auditRecord(pReq, pMnode->clusterId, "RevokePrivileges", name.dbname, alterReq.user, alterReq.sql,
|
auditRecord(pReq, pMnode->clusterId, "RevokePrivileges", name.dbname, alterReq.user, alterReq.sql,
|
||||||
alterReq.sqlLen);
|
alterReq.sqlLen);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2511,7 +2531,10 @@ static int32_t mndDropUser(SMnode *pMnode, SRpcMsg *pReq, SUserObj *pUser) {
|
||||||
mndTransDrop(pTrans);
|
mndTransDrop(pTrans);
|
||||||
TAOS_RETURN(terrno);
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED);
|
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) < 0) {
|
||||||
|
mndTransDrop(pTrans);
|
||||||
|
TAOS_RETURN(terrno);
|
||||||
|
}
|
||||||
|
|
||||||
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
if (mndTransPrepare(pMnode, pTrans) != 0) {
|
||||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||||
|
@ -2982,7 +3005,11 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
||||||
|
|
||||||
SName name = {0};
|
SName name = {0};
|
||||||
char objName[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
char objName[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
(void)tNameFromString(&name, db, T_NAME_ACCT | T_NAME_DB);
|
code = tNameFromString(&name, db, T_NAME_ACCT | T_NAME_DB);
|
||||||
|
if (code < 0) {
|
||||||
|
sdbRelease(pSdb, pUser);
|
||||||
|
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||||
|
}
|
||||||
(void)tNameGetDbName(&name, varDataVal(objName));
|
(void)tNameGetDbName(&name, varDataVal(objName));
|
||||||
varDataSetLen(objName, strlen(varDataVal(objName)));
|
varDataSetLen(objName, strlen(varDataVal(objName)));
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
|
@ -3026,7 +3053,11 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
|
||||||
|
|
||||||
SName name = {0};
|
SName name = {0};
|
||||||
char objName[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
char objName[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||||
(void)tNameFromString(&name, db, T_NAME_ACCT | T_NAME_DB);
|
code = tNameFromString(&name, db, T_NAME_ACCT | T_NAME_DB);
|
||||||
|
if (code < 0) {
|
||||||
|
sdbRelease(pSdb, pUser);
|
||||||
|
TAOS_CHECK_GOTO(code, &lino, _exit);
|
||||||
|
}
|
||||||
(void)tNameGetDbName(&name, varDataVal(objName));
|
(void)tNameGetDbName(&name, varDataVal(objName));
|
||||||
varDataSetLen(objName, strlen(varDataVal(objName)));
|
varDataSetLen(objName, strlen(varDataVal(objName)));
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
|
@ -3213,6 +3244,7 @@ _OVER:
|
||||||
|
|
||||||
int32_t mndUserRemoveDb(SMnode *pMnode, STrans *pTrans, char *db) {
|
int32_t mndUserRemoveDb(SMnode *pMnode, STrans *pTrans, char *db) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
int32_t lino = 0;
|
||||||
SSdb *pSdb = pMnode->pSdb;
|
SSdb *pSdb = pMnode->pSdb;
|
||||||
int32_t len = strlen(db) + 1;
|
int32_t len = strlen(db) + 1;
|
||||||
void *pIter = NULL;
|
void *pIter = NULL;
|
||||||
|
@ -3230,15 +3262,21 @@ int32_t mndUserRemoveDb(SMnode *pMnode, STrans *pTrans, char *db) {
|
||||||
bool inRead = (taosHashGet(newUser.readDbs, db, len) != NULL);
|
bool inRead = (taosHashGet(newUser.readDbs, db, len) != NULL);
|
||||||
bool inWrite = (taosHashGet(newUser.writeDbs, db, len) != NULL);
|
bool inWrite = (taosHashGet(newUser.writeDbs, db, len) != NULL);
|
||||||
if (inRead || inWrite) {
|
if (inRead || inWrite) {
|
||||||
(void)taosHashRemove(newUser.readDbs, db, len);
|
code = taosHashRemove(newUser.readDbs, db, len);
|
||||||
(void)taosHashRemove(newUser.writeDbs, db, len);
|
if (code < 0) {
|
||||||
|
mError("failed to remove readDbs:%s from user:%s", db, pUser->user);
|
||||||
|
}
|
||||||
|
code = taosHashRemove(newUser.writeDbs, db, len);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("failed to remove writeDbs:%s from user:%s", db, pUser->user);
|
||||||
|
}
|
||||||
|
|
||||||
SSdbRaw *pCommitRaw = mndUserActionEncode(&newUser);
|
SSdbRaw *pCommitRaw = mndUserActionEncode(&newUser);
|
||||||
if (pCommitRaw == NULL || (code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
|
if (pCommitRaw == NULL || (code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
TAOS_CHECK_GOTO(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY), &lino, _OVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
mndUserFreeObj(&newUser);
|
mndUserFreeObj(&newUser);
|
||||||
|
@ -3272,16 +3310,30 @@ int32_t mndUserRemoveStb(SMnode *pMnode, STrans *pTrans, char *stb) {
|
||||||
bool inWrite = (taosHashGet(newUser.writeTbs, stb, len) != NULL);
|
bool inWrite = (taosHashGet(newUser.writeTbs, stb, len) != NULL);
|
||||||
bool inAlter = (taosHashGet(newUser.alterTbs, stb, len) != NULL);
|
bool inAlter = (taosHashGet(newUser.alterTbs, stb, len) != NULL);
|
||||||
if (inRead || inWrite || inAlter) {
|
if (inRead || inWrite || inAlter) {
|
||||||
(void)taosHashRemove(newUser.readTbs, stb, len);
|
code = taosHashRemove(newUser.readTbs, stb, len);
|
||||||
(void)taosHashRemove(newUser.writeTbs, stb, len);
|
if (code < 0) {
|
||||||
(void)taosHashRemove(newUser.alterTbs, stb, len);
|
mError("failed to remove readTbs:%s from user:%s", stb, pUser->user);
|
||||||
|
}
|
||||||
|
code = taosHashRemove(newUser.writeTbs, stb, len);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("failed to remove writeTbs:%s from user:%s", stb, pUser->user);
|
||||||
|
}
|
||||||
|
code = taosHashRemove(newUser.alterTbs, stb, len);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("failed to remove alterTbs:%s from user:%s", stb, pUser->user);
|
||||||
|
}
|
||||||
|
|
||||||
SSdbRaw *pCommitRaw = mndUserActionEncode(&newUser);
|
SSdbRaw *pCommitRaw = mndUserActionEncode(&newUser);
|
||||||
if (pCommitRaw == NULL || (code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
|
if (pCommitRaw == NULL || (code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
code = sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||||
|
if (code != 0) {
|
||||||
|
mndUserFreeObj(&newUser);
|
||||||
|
sdbRelease(pSdb, pUser);
|
||||||
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mndUserFreeObj(&newUser);
|
mndUserFreeObj(&newUser);
|
||||||
|
@ -3314,16 +3366,30 @@ int32_t mndUserRemoveView(SMnode *pMnode, STrans *pTrans, char *view) {
|
||||||
bool inWrite = (taosHashGet(newUser.writeViews, view, len) != NULL);
|
bool inWrite = (taosHashGet(newUser.writeViews, view, len) != NULL);
|
||||||
bool inAlter = (taosHashGet(newUser.alterViews, view, len) != NULL);
|
bool inAlter = (taosHashGet(newUser.alterViews, view, len) != NULL);
|
||||||
if (inRead || inWrite || inAlter) {
|
if (inRead || inWrite || inAlter) {
|
||||||
(void)taosHashRemove(newUser.readViews, view, len);
|
code = taosHashRemove(newUser.readViews, view, len);
|
||||||
(void)taosHashRemove(newUser.writeViews, view, len);
|
if (code < 0) {
|
||||||
(void)taosHashRemove(newUser.alterViews, view, len);
|
mError("failed to remove readViews:%s from user:%s", view, pUser->user);
|
||||||
|
}
|
||||||
|
code = taosHashRemove(newUser.writeViews, view, len);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("failed to remove writeViews:%s from user:%s", view, pUser->user);
|
||||||
|
}
|
||||||
|
code = taosHashRemove(newUser.alterViews, view, len);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("failed to remove alterViews:%s from user:%s", view, pUser->user);
|
||||||
|
}
|
||||||
|
|
||||||
SSdbRaw *pCommitRaw = mndUserActionEncode(&newUser);
|
SSdbRaw *pCommitRaw = mndUserActionEncode(&newUser);
|
||||||
if (pCommitRaw == NULL || (code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
|
if (pCommitRaw == NULL || (code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
code = sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||||
|
if (code < 0) {
|
||||||
|
mndUserFreeObj(&newUser);
|
||||||
|
sdbRelease(pSdb, pUser);
|
||||||
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mndUserFreeObj(&newUser);
|
mndUserFreeObj(&newUser);
|
||||||
|
@ -3356,13 +3422,21 @@ int32_t mndUserRemoveTopic(SMnode *pMnode, STrans *pTrans, char *topic) {
|
||||||
|
|
||||||
bool inTopic = (taosHashGet(newUser.topics, topic, len) != NULL);
|
bool inTopic = (taosHashGet(newUser.topics, topic, len) != NULL);
|
||||||
if (inTopic) {
|
if (inTopic) {
|
||||||
(void)taosHashRemove(newUser.topics, topic, len);
|
code = taosHashRemove(newUser.topics, topic, len);
|
||||||
|
if (code < 0) {
|
||||||
|
mError("failed to remove topic:%s from user:%s", topic, pUser->user);
|
||||||
|
}
|
||||||
SSdbRaw *pCommitRaw = mndUserActionEncode(&newUser);
|
SSdbRaw *pCommitRaw = mndUserActionEncode(&newUser);
|
||||||
if (pCommitRaw == NULL || (code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
|
if (pCommitRaw == NULL || (code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
code = sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||||
|
if (code < 0) {
|
||||||
|
mndUserFreeObj(&newUser);
|
||||||
|
sdbRelease(pSdb, pUser);
|
||||||
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mndUserFreeObj(&newUser);
|
mndUserFreeObj(&newUser);
|
||||||
|
|
|
@ -314,7 +314,7 @@ int32_t metaSnapWriterClose(SMetaSnapWriter** ppWriter, int8_t rollback);
|
||||||
// STsdbSnapReader ========================================
|
// STsdbSnapReader ========================================
|
||||||
int32_t tsdbSnapReaderOpen(STsdb* pTsdb, int64_t sver, int64_t ever, int8_t type, void* pRanges,
|
int32_t tsdbSnapReaderOpen(STsdb* pTsdb, int64_t sver, int64_t ever, int8_t type, void* pRanges,
|
||||||
STsdbSnapReader** ppReader);
|
STsdbSnapReader** ppReader);
|
||||||
int32_t tsdbSnapReaderClose(STsdbSnapReader** ppReader);
|
void tsdbSnapReaderClose(STsdbSnapReader** ppReader);
|
||||||
int32_t tsdbSnapRead(STsdbSnapReader* pReader, uint8_t** ppData);
|
int32_t tsdbSnapRead(STsdbSnapReader* pReader, uint8_t** ppData);
|
||||||
// STsdbSnapWriter ========================================
|
// STsdbSnapWriter ========================================
|
||||||
int32_t tsdbSnapWriterOpen(STsdb* pTsdb, int64_t sver, int64_t ever, void* pRanges, STsdbSnapWriter** ppWriter);
|
int32_t tsdbSnapWriterOpen(STsdb* pTsdb, int64_t sver, int64_t ever, void* pRanges, STsdbSnapWriter** ppWriter);
|
||||||
|
@ -323,7 +323,7 @@ int32_t tsdbSnapWriterPrepareClose(STsdbSnapWriter* pWriter, bool rollback);
|
||||||
int32_t tsdbSnapWriterClose(STsdbSnapWriter** ppWriter, int8_t rollback);
|
int32_t tsdbSnapWriterClose(STsdbSnapWriter** ppWriter, int8_t rollback);
|
||||||
// STsdbSnapRAWReader ========================================
|
// STsdbSnapRAWReader ========================================
|
||||||
int32_t tsdbSnapRAWReaderOpen(STsdb* pTsdb, int64_t ever, int8_t type, STsdbSnapRAWReader** ppReader);
|
int32_t tsdbSnapRAWReaderOpen(STsdb* pTsdb, int64_t ever, int8_t type, STsdbSnapRAWReader** ppReader);
|
||||||
int32_t tsdbSnapRAWReaderClose(STsdbSnapRAWReader** ppReader);
|
void tsdbSnapRAWReaderClose(STsdbSnapRAWReader** ppReader);
|
||||||
int32_t tsdbSnapRAWRead(STsdbSnapRAWReader* pReader, uint8_t** ppData);
|
int32_t tsdbSnapRAWRead(STsdbSnapRAWReader* pReader, uint8_t** ppData);
|
||||||
// STsdbSnapRAWWriter ========================================
|
// STsdbSnapRAWWriter ========================================
|
||||||
int32_t tsdbSnapRAWWriterOpen(STsdb* pTsdb, int64_t ever, STsdbSnapRAWWriter** ppWriter);
|
int32_t tsdbSnapRAWWriterOpen(STsdb* pTsdb, int64_t ever, STsdbSnapRAWWriter** ppWriter);
|
||||||
|
@ -368,7 +368,7 @@ int32_t streamStateLoadTasks(SStreamStateWriter* pWriter);
|
||||||
// SStreamStateReader =====================================
|
// SStreamStateReader =====================================
|
||||||
// SRSmaSnapReader ========================================
|
// SRSmaSnapReader ========================================
|
||||||
int32_t rsmaSnapReaderOpen(SSma* pSma, int64_t sver, int64_t ever, SRSmaSnapReader** ppReader);
|
int32_t rsmaSnapReaderOpen(SSma* pSma, int64_t sver, int64_t ever, SRSmaSnapReader** ppReader);
|
||||||
int32_t rsmaSnapReaderClose(SRSmaSnapReader** ppReader);
|
void rsmaSnapReaderClose(SRSmaSnapReader** ppReader);
|
||||||
int32_t rsmaSnapRead(SRSmaSnapReader* pReader, uint8_t** ppData);
|
int32_t rsmaSnapRead(SRSmaSnapReader* pReader, uint8_t** ppData);
|
||||||
// SRSmaSnapWriter ========================================
|
// SRSmaSnapWriter ========================================
|
||||||
int32_t rsmaSnapWriterOpen(SSma* pSma, int64_t sver, int64_t ever, void** ppRanges, SRSmaSnapWriter** ppWriter);
|
int32_t rsmaSnapWriterOpen(SSma* pSma, int64_t sver, int64_t ever, void** ppRanges, SRSmaSnapWriter** ppWriter);
|
||||||
|
|
|
@ -94,12 +94,7 @@ int metaAbort(SMeta *pMeta) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int code = tdbAbort(pMeta->pEnv, pMeta->txn);
|
tdbAbort(pMeta->pEnv, pMeta->txn);
|
||||||
if (code) {
|
|
||||||
metaError("vgId:%d, failed to abort meta since %s", TD_VID(pMeta->pVnode), tstrerror(terrno));
|
|
||||||
} else {
|
|
||||||
pMeta->txn = NULL;
|
pMeta->txn = NULL;
|
||||||
}
|
return 0;
|
||||||
|
|
||||||
return code;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,30 +93,26 @@ int32_t rsmaSnapRead(SRSmaSnapReader* pReader, uint8_t** ppData) {
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
smaError("vgId:%d, %s failed at line %d since %s", SMA_VID(pReader->pSma), __func__, lino, tstrerror(code));
|
smaError("vgId:%d, %s failed at line %d since %s", SMA_VID(pReader->pSma), __func__, lino, tstrerror(code));
|
||||||
TAOS_UNUSED(rsmaSnapReaderClose(&pReader));
|
rsmaSnapReaderClose(&pReader);
|
||||||
} else {
|
} else {
|
||||||
smaInfo("vgId:%d, vnode snapshot rsma read succeed", SMA_VID(pReader->pSma));
|
smaInfo("vgId:%d, vnode snapshot rsma read succeed", SMA_VID(pReader->pSma));
|
||||||
}
|
}
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t rsmaSnapReaderClose(SRSmaSnapReader** ppReader) {
|
void rsmaSnapReaderClose(SRSmaSnapReader** ppReader) {
|
||||||
int32_t code = 0;
|
|
||||||
SRSmaSnapReader* pReader = *ppReader;
|
SRSmaSnapReader* pReader = *ppReader;
|
||||||
|
|
||||||
for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
|
for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
|
||||||
if (pReader->pDataReader[i]) {
|
if (pReader->pDataReader[i]) {
|
||||||
if ((code = tsdbSnapReaderClose(&pReader->pDataReader[i])) < 0) {
|
tsdbSnapReaderClose(&pReader->pDataReader[i]);
|
||||||
smaError("vgId:%d, vnode snapshot rsma , failed to close tsdbSnapReader since %s", SMA_VID(pReader->pSma),
|
|
||||||
tstrerror(code));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
smaInfo("vgId:%d, vnode snapshot rsma reader closed", SMA_VID(pReader->pSma));
|
smaInfo("vgId:%d, vnode snapshot rsma reader closed", SMA_VID(pReader->pSma));
|
||||||
|
|
||||||
taosMemoryFreeClear(*ppReader);
|
taosMemoryFreeClear(*ppReader);
|
||||||
TAOS_RETURN(code);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// SRSmaSnapWriter ========================================
|
// SRSmaSnapWriter ========================================
|
||||||
|
|
|
@ -132,7 +132,8 @@ int32_t tqSnapWriterOpen(STQ* pTq, int64_t sver, int64_t ever, STqSnapWriter** p
|
||||||
// alloc
|
// alloc
|
||||||
pWriter = (STqSnapWriter*)taosMemoryCalloc(1, sizeof(*pWriter));
|
pWriter = (STqSnapWriter*)taosMemoryCalloc(1, sizeof(*pWriter));
|
||||||
if (pWriter == NULL) {
|
if (pWriter == NULL) {
|
||||||
code = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);;
|
code = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
|
||||||
|
;
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
pWriter->pTq = pTq;
|
pWriter->pTq = pTq;
|
||||||
|
@ -160,7 +161,7 @@ int32_t tqSnapWriterClose(STqSnapWriter** ppWriter, int8_t rollback) {
|
||||||
STQ* pTq = pWriter->pTq;
|
STQ* pTq = pWriter->pTq;
|
||||||
|
|
||||||
if (rollback) {
|
if (rollback) {
|
||||||
(void)tdbAbort(pWriter->pTq->pMetaDB, pWriter->txn);
|
tdbAbort(pWriter->pTq->pMetaDB, pWriter->txn);
|
||||||
} else {
|
} else {
|
||||||
code = tdbCommit(pWriter->pTq->pMetaDB, pWriter->txn);
|
code = tdbCommit(pWriter->pTq->pMetaDB, pWriter->txn);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
@ -189,7 +190,8 @@ int32_t tqSnapHandleWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nData
|
||||||
code = tDecodeSTqHandle(pDecoder, &handle);
|
code = tDecodeSTqHandle(pDecoder, &handle);
|
||||||
if (code) goto end;
|
if (code) goto end;
|
||||||
taosWLockLatch(&pTq->lock);
|
taosWLockLatch(&pTq->lock);
|
||||||
code = tqMetaSaveInfo(pTq, pTq->pExecStore, handle.subKey, (int)strlen(handle.subKey), pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr));
|
code = tqMetaSaveInfo(pTq, pTq->pExecStore, handle.subKey, (int)strlen(handle.subKey), pData + sizeof(SSnapDataHdr),
|
||||||
|
nData - sizeof(SSnapDataHdr));
|
||||||
taosWUnLockLatch(&pTq->lock);
|
taosWUnLockLatch(&pTq->lock);
|
||||||
|
|
||||||
end:
|
end:
|
||||||
|
@ -208,7 +210,8 @@ int32_t tqSnapCheckInfoWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nD
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = tqMetaSaveInfo(pTq, pTq->pCheckStore, &info.topic, strlen(info.topic), pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr));
|
code = tqMetaSaveInfo(pTq, pTq->pCheckStore, &info.topic, strlen(info.topic), pData + sizeof(SSnapDataHdr),
|
||||||
|
nData - sizeof(SSnapDataHdr));
|
||||||
tDeleteSTqCheckInfo(&info);
|
tDeleteSTqCheckInfo(&info);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
|
@ -229,7 +232,8 @@ int32_t tqSnapOffsetWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nData
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = tqMetaSaveInfo(pTq, pTq->pOffsetStore, info.subKey, strlen(info.subKey), pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr));
|
code = tqMetaSaveInfo(pTq, pTq->pOffsetStore, info.subKey, strlen(info.subKey), pData + sizeof(SSnapDataHdr),
|
||||||
|
nData - sizeof(SSnapDataHdr));
|
||||||
tDeleteSTqOffset(&info);
|
tDeleteSTqOffset(&info);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
||||||
|
|
|
@ -210,7 +210,7 @@ int32_t streamTaskSnapWriterClose(SStreamTaskWriter* pWriter, int8_t rollback, i
|
||||||
streamMetaWLock(pTq->pStreamMeta);
|
streamMetaWLock(pTq->pStreamMeta);
|
||||||
tqDebug("vgId:%d, vnode stream-task snapshot writer closed", TD_VID(pTq->pVnode));
|
tqDebug("vgId:%d, vnode stream-task snapshot writer closed", TD_VID(pTq->pVnode));
|
||||||
if (rollback) {
|
if (rollback) {
|
||||||
(void)tdbAbort(pTq->pStreamMeta->db, pTq->pStreamMeta->txn);
|
tdbAbort(pTq->pStreamMeta->db, pTq->pStreamMeta->txn);
|
||||||
} else {
|
} else {
|
||||||
code = tdbCommit(pTq->pStreamMeta->db, pTq->pStreamMeta->txn);
|
code = tdbCommit(pTq->pStreamMeta->db, pTq->pStreamMeta->txn);
|
||||||
if (code) goto _err;
|
if (code) goto _err;
|
||||||
|
|
|
@ -440,9 +440,9 @@ _exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbSnapReaderClose(STsdbSnapReader** reader) {
|
void tsdbSnapReaderClose(STsdbSnapReader** reader) {
|
||||||
if (reader[0] == NULL) {
|
if (reader[0] == NULL) {
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
@ -469,7 +469,7 @@ int32_t tsdbSnapReaderClose(STsdbSnapReader** reader) {
|
||||||
taosMemoryFree(reader[0]);
|
taosMemoryFree(reader[0]);
|
||||||
reader[0] = NULL;
|
reader[0] = NULL;
|
||||||
|
|
||||||
return code;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbSnapRead(STsdbSnapReader* reader, uint8_t** data) {
|
int32_t tsdbSnapRead(STsdbSnapReader* reader, uint8_t** data) {
|
||||||
|
|
|
@ -75,8 +75,8 @@ _exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbSnapRAWReaderClose(STsdbSnapRAWReader** reader) {
|
void tsdbSnapRAWReaderClose(STsdbSnapRAWReader** reader) {
|
||||||
if (reader[0] == NULL) return 0;
|
if (reader[0] == NULL) return;
|
||||||
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
@ -87,14 +87,7 @@ int32_t tsdbSnapRAWReaderClose(STsdbSnapRAWReader** reader) {
|
||||||
tsdbFSDestroyRefSnapshot(&reader[0]->fsetArr);
|
tsdbFSDestroyRefSnapshot(&reader[0]->fsetArr);
|
||||||
taosMemoryFree(reader[0]);
|
taosMemoryFree(reader[0]);
|
||||||
reader[0] = NULL;
|
reader[0] = NULL;
|
||||||
|
return;
|
||||||
_exit:
|
|
||||||
if (code) {
|
|
||||||
TSDB_ERROR_LOG(TD_VID(tsdb->pVnode), lino, code);
|
|
||||||
} else {
|
|
||||||
tsdbDebug("vgId:%d %s done", TD_VID(tsdb->pVnode), __func__);
|
|
||||||
}
|
|
||||||
return code;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tsdbSnapRAWReadFileSetOpenReader(STsdbSnapRAWReader* reader) {
|
static int32_t tsdbSnapRAWReadFileSetOpenReader(STsdbSnapRAWReader* reader) {
|
||||||
|
|
|
@ -219,15 +219,15 @@ void vnodeSnapReaderClose(SVSnapReader *pReader) {
|
||||||
vnodeSnapReaderDestroyTsdbRanges(pReader);
|
vnodeSnapReaderDestroyTsdbRanges(pReader);
|
||||||
|
|
||||||
if (pReader->pRsmaReader) {
|
if (pReader->pRsmaReader) {
|
||||||
(void)rsmaSnapReaderClose(&pReader->pRsmaReader);
|
rsmaSnapReaderClose(&pReader->pRsmaReader);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pReader->pTsdbReader) {
|
if (pReader->pTsdbReader) {
|
||||||
(void)tsdbSnapReaderClose(&pReader->pTsdbReader);
|
tsdbSnapReaderClose(&pReader->pTsdbReader);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pReader->pTsdbRAWReader) {
|
if (pReader->pTsdbRAWReader) {
|
||||||
(void)tsdbSnapRAWReaderClose(&pReader->pTsdbRAWReader);
|
tsdbSnapRAWReaderClose(&pReader->pTsdbRAWReader);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pReader->pMetaReader) {
|
if (pReader->pMetaReader) {
|
||||||
|
@ -333,8 +333,7 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData)
|
||||||
goto _exit;
|
goto _exit;
|
||||||
} else {
|
} else {
|
||||||
pReader->tsdbDone = 1;
|
pReader->tsdbDone = 1;
|
||||||
code = tsdbSnapReaderClose(&pReader->pTsdbReader);
|
tsdbSnapReaderClose(&pReader->pTsdbReader);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,8 +350,7 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData)
|
||||||
goto _exit;
|
goto _exit;
|
||||||
} else {
|
} else {
|
||||||
pReader->tsdbRAWDone = 1;
|
pReader->tsdbRAWDone = 1;
|
||||||
code = tsdbSnapRAWReaderClose(&pReader->pTsdbRAWReader);
|
tsdbSnapRAWReaderClose(&pReader->pTsdbRAWReader);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,8 +461,7 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData)
|
||||||
goto _exit;
|
goto _exit;
|
||||||
} else {
|
} else {
|
||||||
pReader->rsmaDone = 1;
|
pReader->rsmaDone = 1;
|
||||||
code = rsmaSnapReaderClose(&pReader->pRsmaReader);
|
rsmaSnapReaderClose(&pReader->pRsmaReader);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -590,15 +587,15 @@ extern int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb);
|
||||||
extern void tsdbEnableBgTask(STsdb *pTsdb);
|
extern void tsdbEnableBgTask(STsdb *pTsdb);
|
||||||
|
|
||||||
static int32_t vnodeCancelAndDisableAllBgTask(SVnode *pVnode) {
|
static int32_t vnodeCancelAndDisableAllBgTask(SVnode *pVnode) {
|
||||||
(void)tsdbDisableAndCancelAllBgTask(pVnode->pTsdb);
|
TAOS_CHECK_RETURN(tsdbDisableAndCancelAllBgTask(pVnode->pTsdb));
|
||||||
(void)vnodeSyncCommit(pVnode);
|
TAOS_CHECK_RETURN(vnodeSyncCommit(pVnode));
|
||||||
(void)vnodeAChannelDestroy(&pVnode->commitChannel, true);
|
TAOS_CHECK_RETURN(vnodeAChannelDestroy(&pVnode->commitChannel, true));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t vnodeEnableBgTask(SVnode *pVnode) {
|
static int32_t vnodeEnableBgTask(SVnode *pVnode) {
|
||||||
tsdbEnableBgTask(pVnode->pTsdb);
|
tsdbEnableBgTask(pVnode->pTsdb);
|
||||||
(void)vnodeAChannelInit(1, &pVnode->commitChannel);
|
TAOS_CHECK_RETURN(vnodeAChannelInit(1, &pVnode->commitChannel));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -613,7 +610,9 @@ int32_t vnodeSnapWriterOpen(SVnode *pVnode, SSnapshotParam *pParam, SVSnapWriter
|
||||||
(void)taosThreadMutexLock(&pVnode->mutex);
|
(void)taosThreadMutexLock(&pVnode->mutex);
|
||||||
pVnode->disableWrite = true;
|
pVnode->disableWrite = true;
|
||||||
(void)taosThreadMutexUnlock(&pVnode->mutex);
|
(void)taosThreadMutexUnlock(&pVnode->mutex);
|
||||||
(void)vnodeCancelAndDisableAllBgTask(pVnode);
|
|
||||||
|
code = vnodeCancelAndDisableAllBgTask(pVnode);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
// alloc
|
// alloc
|
||||||
pWriter = (SVSnapWriter *)taosMemoryCalloc(1, sizeof(*pWriter));
|
pWriter = (SVSnapWriter *)taosMemoryCalloc(1, sizeof(*pWriter));
|
||||||
|
@ -661,15 +660,18 @@ int32_t vnodeSnapWriterClose(SVSnapWriter *pWriter, int8_t rollback, SSnapshot *
|
||||||
|
|
||||||
// prepare
|
// prepare
|
||||||
if (pWriter->pTsdbSnapWriter) {
|
if (pWriter->pTsdbSnapWriter) {
|
||||||
(void)tsdbSnapWriterPrepareClose(pWriter->pTsdbSnapWriter, rollback);
|
code = tsdbSnapWriterPrepareClose(pWriter->pTsdbSnapWriter, rollback);
|
||||||
|
if (code) goto _exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pWriter->pTsdbSnapRAWWriter) {
|
if (pWriter->pTsdbSnapRAWWriter) {
|
||||||
(void)tsdbSnapRAWWriterPrepareClose(pWriter->pTsdbSnapRAWWriter);
|
code = tsdbSnapRAWWriterPrepareClose(pWriter->pTsdbSnapRAWWriter);
|
||||||
|
if (code) goto _exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pWriter->pRsmaSnapWriter) {
|
if (pWriter->pRsmaSnapWriter) {
|
||||||
(void)rsmaSnapWriterPrepareClose(pWriter->pRsmaSnapWriter, rollback);
|
code = rsmaSnapWriterPrepareClose(pWriter->pRsmaSnapWriter, rollback);
|
||||||
|
if (code) goto _exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// commit json
|
// commit json
|
||||||
|
@ -743,7 +745,9 @@ int32_t vnodeSnapWriterClose(SVSnapWriter *pWriter, int8_t rollback, SSnapshot *
|
||||||
if (code) goto _exit;
|
if (code) goto _exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)vnodeBegin(pVnode);
|
code = vnodeBegin(pVnode);
|
||||||
|
if (code) goto _exit;
|
||||||
|
|
||||||
(void)taosThreadMutexLock(&pVnode->mutex);
|
(void)taosThreadMutexLock(&pVnode->mutex);
|
||||||
pVnode->disableWrite = false;
|
pVnode->disableWrite = false;
|
||||||
(void)taosThreadMutexUnlock(&pVnode->mutex);
|
(void)taosThreadMutexUnlock(&pVnode->mutex);
|
||||||
|
@ -755,7 +759,9 @@ _exit:
|
||||||
vInfo("vgId:%d, vnode snapshot writer closed, rollback:%d", TD_VID(pVnode), rollback);
|
vInfo("vgId:%d, vnode snapshot writer closed, rollback:%d", TD_VID(pVnode), rollback);
|
||||||
taosMemoryFree(pWriter);
|
taosMemoryFree(pWriter);
|
||||||
}
|
}
|
||||||
(void)vnodeEnableBgTask(pVnode);
|
if (vnodeEnableBgTask(pVnode) != 0) {
|
||||||
|
tsdbError("vgId:%d, failed to enable bg task", TD_VID(pVnode));
|
||||||
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -591,12 +591,15 @@ void streamMetaCloseImpl(void* arg) {
|
||||||
streamMetaWUnLock(pMeta);
|
streamMetaWUnLock(pMeta);
|
||||||
|
|
||||||
// already log the error, ignore here
|
// already log the error, ignore here
|
||||||
code = tdbAbort(pMeta->db, pMeta->txn);
|
tdbAbort(pMeta->db, pMeta->txn);
|
||||||
|
code = tdbTbClose(pMeta->pTaskDb);
|
||||||
if (code) {
|
if (code) {
|
||||||
stError("vgId:%d failed to jump of trans for tdb, code:%s", vgId, tstrerror(code));
|
stError("vgId:%d failed to close taskDb, code:%s", vgId, tstrerror(code));
|
||||||
|
}
|
||||||
|
code = tdbTbClose(pMeta->pCheckpointDb);
|
||||||
|
if (code) {
|
||||||
|
stError("vgId:%d failed to close checkpointDb, code:%s", vgId, tstrerror(code));
|
||||||
}
|
}
|
||||||
tdbTbClose(pMeta->pTaskDb);
|
|
||||||
tdbTbClose(pMeta->pCheckpointDb);
|
|
||||||
code = tdbClose(pMeta->db);
|
code = tdbClose(pMeta->db);
|
||||||
if (code) {
|
if (code) {
|
||||||
stError("vgId:%d failed to close db, code:%s", vgId, tstrerror(code));
|
stError("vgId:%d failed to close db, code:%s", vgId, tstrerror(code));
|
||||||
|
|
|
@ -40,7 +40,7 @@ int32_t tdbBegin(TDB *pDb, TXN **pTxn, void *(*xMalloc)(void *, size_t), void (*
|
||||||
int32_t tdbCommit(TDB *pDb, TXN *pTxn);
|
int32_t tdbCommit(TDB *pDb, TXN *pTxn);
|
||||||
int32_t tdbPostCommit(TDB *pDb, TXN *pTxn);
|
int32_t tdbPostCommit(TDB *pDb, TXN *pTxn);
|
||||||
int32_t tdbPrepareAsyncCommit(TDB *pDb, TXN *pTxn);
|
int32_t tdbPrepareAsyncCommit(TDB *pDb, TXN *pTxn);
|
||||||
int32_t tdbAbort(TDB *pDb, TXN *pTxn);
|
void tdbAbort(TDB *pDb, TXN *pTxn);
|
||||||
int32_t tdbAlter(TDB *pDb, int pages);
|
int32_t tdbAlter(TDB *pDb, int pages);
|
||||||
|
|
||||||
// TTB
|
// TTB
|
||||||
|
@ -79,10 +79,10 @@ int32_t tdbTbcUpsert(TBC *pTbc, const void *pKey, int nKey, const void *pData, i
|
||||||
|
|
||||||
int32_t tdbTxnOpen(TXN *pTxn, int64_t txnid, void *(*xMalloc)(void *, size_t), void (*xFree)(void *, void *),
|
int32_t tdbTxnOpen(TXN *pTxn, int64_t txnid, void *(*xMalloc)(void *, size_t), void (*xFree)(void *, void *),
|
||||||
void *xArg, int flags);
|
void *xArg, int flags);
|
||||||
int32_t tdbTxnCloseImpl(TXN *pTxn);
|
void tdbTxnCloseImpl(TXN *pTxn);
|
||||||
#define tdbTxnClose(pTxn) \
|
#define tdbTxnClose(pTxn) \
|
||||||
do { \
|
do { \
|
||||||
(void)tdbTxnCloseImpl(pTxn); \
|
tdbTxnCloseImpl(pTxn); \
|
||||||
(pTxn) = NULL; \
|
(pTxn) = NULL; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, char const *tbname, SPg
|
||||||
zArg.pBt = pBt;
|
zArg.pBt = pBt;
|
||||||
ret = tdbPagerFetchPage(pPager, &pgno, &pPage, tdbBtreeInitPage, &zArg, txn);
|
ret = tdbPagerFetchPage(pPager, &pgno, &pPage, tdbBtreeInitPage, &zArg, txn);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
(void)tdbAbort(pEnv, txn);
|
tdbAbort(pEnv, txn);
|
||||||
tdbOsFree(pBt);
|
tdbOsFree(pBt);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, char const *tbname, SPg
|
||||||
ret = tdbPagerWrite(pPager, pPage);
|
ret = tdbPagerWrite(pPager, pPage);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
tdbError("failed to write page since %s", terrstr());
|
tdbError("failed to write page since %s", terrstr());
|
||||||
(void)tdbAbort(pEnv, txn);
|
tdbAbort(pEnv, txn);
|
||||||
tdbOsFree(pBt);
|
tdbOsFree(pBt);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, char const *tbname, SPg
|
||||||
|
|
||||||
ret = tdbTbInsert(pPager->pEnv->pMainDb, tbname, strlen(tbname) + 1, &pBt->info, sizeof(pBt->info), txn);
|
ret = tdbTbInsert(pPager->pEnv->pMainDb, tbname, strlen(tbname) + 1, &pBt->info, sizeof(pBt->info), txn);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
(void)tdbAbort(pEnv, txn);
|
tdbAbort(pEnv, txn);
|
||||||
tdbOsFree(pBt);
|
tdbOsFree(pBt);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -513,7 +513,10 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild, TXN
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the root page content to the child page
|
// Copy the root page content to the child page
|
||||||
(void)tdbPageCopy(pRoot, pChild, 0);
|
ret = tdbPageCopy(pRoot, pChild, 0);
|
||||||
|
if (ret < 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
// Reinitialize the root page
|
// Reinitialize the root page
|
||||||
zArg.flags = TDB_BTREE_ROOT;
|
zArg.flags = TDB_BTREE_ROOT;
|
||||||
|
@ -633,14 +636,22 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)tdbPageDropCell(pParent, sIdx, pTxn, pBt);
|
ret = tdbPageDropCell(pParent, sIdx, pTxn, pBt);
|
||||||
|
if (ret < 0) {
|
||||||
|
tdbError("tdb/btree-balance: drop cell failed with ret: %d.", ret);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
if (!childNotLeaf) {
|
if (!childNotLeaf) {
|
||||||
SArray *ofps = pParent->pPager->ofps;
|
SArray *ofps = pParent->pPager->ofps;
|
||||||
if (ofps) {
|
if (ofps) {
|
||||||
for (int i = 0; i < TARRAY_SIZE(ofps); ++i) {
|
for (int i = 0; i < TARRAY_SIZE(ofps); ++i) {
|
||||||
SPage *ofp = *(SPage **)taosArrayGet(ofps, i);
|
SPage *ofp = *(SPage **)taosArrayGet(ofps, i);
|
||||||
(void)tdbPagerInsertFreePage(pParent->pPager, ofp, pTxn);
|
ret = tdbPagerInsertFreePage(pParent->pPager, ofp, pTxn);
|
||||||
|
if (ret < 0) {
|
||||||
|
tdbError("tdb/btree-balance: insert free page failed with ret: %d.", ret);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (destroyOfps) {
|
if (destroyOfps) {
|
||||||
|
@ -853,7 +864,11 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
||||||
if (iNew == nNews - 1 && pIntHdr->pgno == 0) {
|
if (iNew == nNews - 1 && pIntHdr->pgno == 0) {
|
||||||
pIntHdr->pgno = TDB_PAGE_PGNO(pNews[iNew]);
|
pIntHdr->pgno = TDB_PAGE_PGNO(pNews[iNew]);
|
||||||
} else {
|
} else {
|
||||||
(void)tdbBtreeDecodeCell(pPage, pCell, &cd, pTxn, pBt);
|
ret = tdbBtreeDecodeCell(pPage, pCell, &cd, pTxn, pBt);
|
||||||
|
if (ret < 0) {
|
||||||
|
tdbError("tdb/btree-balance: decode cell failed with ret: %d.", ret);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: pCell here may be inserted as an overflow cell, handle it
|
// TODO: pCell here may be inserted as an overflow cell, handle it
|
||||||
SCell *pNewCell = tdbOsMalloc(cd.kLen + 9);
|
SCell *pNewCell = tdbOsMalloc(cd.kLen + 9);
|
||||||
|
@ -863,8 +878,12 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
||||||
int szNewCell;
|
int szNewCell;
|
||||||
SPgno pgno;
|
SPgno pgno;
|
||||||
pgno = TDB_PAGE_PGNO(pNews[iNew]);
|
pgno = TDB_PAGE_PGNO(pNews[iNew]);
|
||||||
(void)tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&pgno, sizeof(SPgno), pNewCell, &szNewCell,
|
ret = tdbBtreeEncodeCell(pParent, cd.pKey, cd.kLen, (void *)&pgno, sizeof(SPgno), pNewCell, &szNewCell,
|
||||||
pTxn, pBt);
|
pTxn, pBt);
|
||||||
|
if (ret < 0) {
|
||||||
|
tdbError("tdb/btree-balance: encode cell failed with ret: %d.", ret);
|
||||||
|
return TSDB_CODE_FAILED;
|
||||||
|
}
|
||||||
ret = tdbPageInsertCell(pParent, sIdx++, pNewCell, szNewCell, 0);
|
ret = tdbPageInsertCell(pParent, sIdx++, pNewCell, szNewCell, 0);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
tdbError("tdb/btree-balance: insert cell failed with ret: %d.", ret);
|
tdbError("tdb/btree-balance: insert cell failed with ret: %d.", ret);
|
||||||
|
@ -979,7 +998,10 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
||||||
|
|
||||||
for (pageIdx = 0; pageIdx < nOlds; ++pageIdx) {
|
for (pageIdx = 0; pageIdx < nOlds; ++pageIdx) {
|
||||||
if (pageIdx >= nNews) {
|
if (pageIdx >= nNews) {
|
||||||
(void)tdbPagerInsertFreePage(pBt->pPager, pOlds[pageIdx], pTxn);
|
ret = tdbPagerInsertFreePage(pBt->pPager, pOlds[pageIdx], pTxn);
|
||||||
|
if (ret < 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
tdbPagerReturnPage(pBt->pPager, pOlds[pageIdx], pTxn);
|
tdbPagerReturnPage(pBt->pPager, pOlds[pageIdx], pTxn);
|
||||||
}
|
}
|
||||||
|
@ -2189,7 +2211,11 @@ int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int
|
||||||
}
|
}
|
||||||
|
|
||||||
pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx);
|
pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx);
|
||||||
(void)tdbBtreeDecodeCell(pBtc->pPage, pCell, &pBtc->coder, pBtc->pTxn, pBtc->pBt);
|
int32_t ret = tdbBtreeDecodeCell(pBtc->pPage, pCell, &pBtc->coder, pBtc->pTxn, pBtc->pBt);
|
||||||
|
if (ret < 0) {
|
||||||
|
tdbError("tdb/btc-get: decode cell failed with ret: %d.", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (ppKey) {
|
if (ppKey) {
|
||||||
*ppKey = (void *)pBtc->coder.pKey;
|
*ppKey = (void *)pBtc->coder.pKey;
|
||||||
|
@ -2238,13 +2264,19 @@ int tdbBtcDelete(SBTC *pBtc) {
|
||||||
destroyOfps = true;
|
destroyOfps = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)tdbPageDropCell(pBtc->pPage, idx, pBtc->pTxn, pBtc->pBt);
|
ret = tdbPageDropCell(pBtc->pPage, idx, pBtc->pTxn, pBtc->pBt);
|
||||||
|
if (ret < 0) {
|
||||||
|
tdbError("tdb/btc-delete: page drop cell failed with ret: %d.", ret);
|
||||||
|
}
|
||||||
|
|
||||||
SArray *ofps = pBtc->pPage->pPager->ofps;
|
SArray *ofps = pBtc->pPage->pPager->ofps;
|
||||||
if (ofps) {
|
if (ofps) {
|
||||||
for (int i = 0; i < TARRAY_SIZE(ofps); ++i) {
|
for (int i = 0; i < TARRAY_SIZE(ofps); ++i) {
|
||||||
SPage *ofp = *(SPage **)taosArrayGet(ofps, i);
|
SPage *ofp = *(SPage **)taosArrayGet(ofps, i);
|
||||||
(void)tdbPagerInsertFreePage(pBtc->pPage->pPager, ofp, pBtc->pTxn);
|
ret = tdbPagerInsertFreePage(pBtc->pPage->pPager, ofp, pBtc->pTxn);
|
||||||
|
if (ret < 0) {
|
||||||
|
tdbError("tdb/btc-delete: insert free page failed with ret: %d.", ret);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (destroyOfps) {
|
if (destroyOfps) {
|
||||||
|
@ -2282,7 +2314,10 @@ int tdbBtcDelete(SBTC *pBtc) {
|
||||||
tdbError("tdb/btc-delete: malloc failed.");
|
tdbError("tdb/btc-delete: malloc failed.");
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
(void)tdbBtreeEncodeCell(pPage, pKey, nKey, &pgno, sizeof(pgno), pCell, &szCell, pBtc->pTxn, pBtc->pBt);
|
ret = tdbBtreeEncodeCell(pPage, pKey, nKey, &pgno, sizeof(pgno), pCell, &szCell, pBtc->pTxn, pBtc->pBt);
|
||||||
|
if (ret < 0) {
|
||||||
|
tdbError("tdb/btc-delete: btree encode cell failed with ret: %d.", ret);
|
||||||
|
}
|
||||||
|
|
||||||
ret = tdbPageUpdateCell(pPage, idx, pCell, szCell, pBtc->pTxn, pBtc->pBt);
|
ret = tdbPageUpdateCell(pPage, idx, pCell, szCell, pBtc->pTxn, pBtc->pBt);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
|
|
@ -101,10 +101,10 @@ int tdbClose(TDB *pDb) {
|
||||||
|
|
||||||
for (pPager = pDb->pgrList; pPager; pPager = pDb->pgrList) {
|
for (pPager = pDb->pgrList; pPager; pPager = pDb->pgrList) {
|
||||||
pDb->pgrList = pPager->pNext;
|
pDb->pgrList = pPager->pNext;
|
||||||
(void)tdbPagerClose(pPager);
|
tdbPagerClose(pPager);
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)tdbPCacheClose(pDb->pCache);
|
tdbPCacheClose(pDb->pCache);
|
||||||
tdbOsFree(pDb->pgrHash);
|
tdbOsFree(pDb->pgrHash);
|
||||||
tdbOsFree(pDb);
|
tdbOsFree(pDb);
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ int32_t tdbPrepareAsyncCommit(TDB *pDb, TXN *pTxn) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tdbAbort(TDB *pDb, TXN *pTxn) {
|
void tdbAbort(TDB *pDb, TXN *pTxn) {
|
||||||
SPager *pPager;
|
SPager *pPager;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -208,13 +208,12 @@ int32_t tdbAbort(TDB *pDb, TXN *pTxn) {
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
tdbError("failed to abort pager since %s. dbName:%s, txnId:%" PRId64, tstrerror(terrno), pDb->dbName,
|
tdbError("failed to abort pager since %s. dbName:%s, txnId:%" PRId64, tstrerror(terrno), pDb->dbName,
|
||||||
pTxn->txnId);
|
pTxn->txnId);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tdbTxnClose(pTxn);
|
tdbTxnClose(pTxn);
|
||||||
|
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPager *tdbEnvGetPager(TDB *pDb, const char *fname) {
|
SPager *tdbEnvGetPager(TDB *pDb, const char *fname) {
|
||||||
|
|
|
@ -42,12 +42,31 @@ static void tdbPCachePinPage(SPCache *pCache, SPage *pPage);
|
||||||
static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage);
|
static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage);
|
||||||
static void tdbPCacheAddPageToHash(SPCache *pCache, SPage *pPage);
|
static void tdbPCacheAddPageToHash(SPCache *pCache, SPage *pPage);
|
||||||
static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage);
|
static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage);
|
||||||
static int tdbPCacheCloseImpl(SPCache *pCache);
|
static void tdbPCacheCloseImpl(SPCache *pCache);
|
||||||
|
|
||||||
static void tdbPCacheInitLock(SPCache *pCache) { (void)tdbMutexInit(&(pCache->mutex), NULL); }
|
static void tdbPCacheInitLock(SPCache *pCache) {
|
||||||
static void tdbPCacheDestroyLock(SPCache *pCache) { (void)tdbMutexDestroy(&(pCache->mutex)); }
|
if (tdbMutexInit(&(pCache->mutex), NULL) != 0) {
|
||||||
static void tdbPCacheLock(SPCache *pCache) { (void)tdbMutexLock(&(pCache->mutex)); }
|
tdbError("tdb/pcache: mutex init failed.");
|
||||||
static void tdbPCacheUnlock(SPCache *pCache) { (void)tdbMutexUnlock(&(pCache->mutex)); }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tdbPCacheDestroyLock(SPCache *pCache) {
|
||||||
|
if (tdbMutexDestroy(&(pCache->mutex)) != 0) {
|
||||||
|
tdbError("tdb/pcache: mutex destroy failed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tdbPCacheLock(SPCache *pCache) {
|
||||||
|
if (tdbMutexLock(&(pCache->mutex)) != 0) {
|
||||||
|
tdbError("tdb/pcache: mutex lock failed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void tdbPCacheUnlock(SPCache *pCache) {
|
||||||
|
if (tdbMutexUnlock(&(pCache->mutex)) != 0) {
|
||||||
|
tdbError("tdb/pcache: mutex unlock failed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) {
|
int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
@ -74,7 +93,7 @@ int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) {
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
tdbError("%s failed at %s:%d since %s", __func__, __FILE__, __LINE__, tstrerror(code));
|
tdbError("%s failed at %s:%d since %s", __func__, __FILE__, __LINE__, tstrerror(code));
|
||||||
(void)tdbPCacheClose(pCache);
|
tdbPCacheClose(pCache);
|
||||||
*ppCache = NULL;
|
*ppCache = NULL;
|
||||||
} else {
|
} else {
|
||||||
*ppCache = pCache;
|
*ppCache = pCache;
|
||||||
|
@ -82,13 +101,13 @@ _exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tdbPCacheClose(SPCache *pCache) {
|
void tdbPCacheClose(SPCache *pCache) {
|
||||||
if (pCache) {
|
if (pCache) {
|
||||||
(void)tdbPCacheCloseImpl(pCache);
|
tdbPCacheCloseImpl(pCache);
|
||||||
tdbOsFree(pCache->aPage);
|
tdbOsFree(pCache->aPage);
|
||||||
tdbOsFree(pCache);
|
tdbOsFree(pCache);
|
||||||
}
|
}
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
|
@ -514,7 +533,7 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tdbPCacheCloseImpl(SPCache *pCache) {
|
static void tdbPCacheCloseImpl(SPCache *pCache) {
|
||||||
// free free page
|
// free free page
|
||||||
for (SPage *pPage = pCache->pFree; pPage;) {
|
for (SPage *pPage = pCache->pFree; pPage;) {
|
||||||
SPage *pPageT = pPage->pFreeNext;
|
SPage *pPageT = pPage->pFreeNext;
|
||||||
|
@ -532,5 +551,5 @@ static int tdbPCacheCloseImpl(SPCache *pCache) {
|
||||||
|
|
||||||
tdbOsFree(pCache->pgHash);
|
tdbOsFree(pCache->pgHash);
|
||||||
tdbPCacheDestroyLock(pCache);
|
tdbPCacheDestroyLock(pCache);
|
||||||
return 0;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,10 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t)
|
||||||
memset(ptr, 0, size);
|
memset(ptr, 0, size);
|
||||||
pPage = (SPage *)(ptr + pageSize);
|
pPage = (SPage *)(ptr + pageSize);
|
||||||
|
|
||||||
(void)TDB_INIT_PAGE_LOCK(pPage);
|
int32_t code = TDB_INIT_PAGE_LOCK(pPage);
|
||||||
|
if (code) {
|
||||||
|
tdbError("tdb/page-create: init page lock failed.");
|
||||||
|
}
|
||||||
pPage->pageSize = pageSize;
|
pPage->pageSize = pageSize;
|
||||||
pPage->pData = ptr;
|
pPage->pData = ptr;
|
||||||
if (pageSize < 65536) {
|
if (pageSize < 65536) {
|
||||||
|
|
|
@ -95,7 +95,7 @@ static int hashset_add(hashset_t set, void *item) {
|
||||||
|
|
||||||
set->nitems = 0;
|
set->nitems = 0;
|
||||||
for (size_t i = 0; i < old_capacity; ++i) {
|
for (size_t i = 0; i < old_capacity; ++i) {
|
||||||
(void)hashset_add_member(set, (void *)old_items[i]);
|
int nt = hashset_add_member(set, (void *)old_items[i]);
|
||||||
}
|
}
|
||||||
tdbOsFree(old_items);
|
tdbOsFree(old_items);
|
||||||
}
|
}
|
||||||
|
@ -209,12 +209,15 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tdbPagerClose(SPager *pPager) {
|
void tdbPagerClose(SPager *pPager) {
|
||||||
if (pPager) {
|
if (pPager) {
|
||||||
(void)tdbOsClose(pPager->fd);
|
int32_t code = tdbOsClose(pPager->fd);
|
||||||
|
if (code) {
|
||||||
|
tdbWarn("failed to close file since %s", tstrerror(code));
|
||||||
|
}
|
||||||
tdbOsFree(pPager);
|
tdbOsFree(pPager);
|
||||||
}
|
}
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tdbPagerWrite(SPager *pPager, SPage *pPage) {
|
int tdbPagerWrite(SPager *pPager, SPage *pPage) {
|
||||||
|
@ -224,14 +227,14 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) {
|
||||||
if (pPage->isDirty) return 0;
|
if (pPage->isDirty) return 0;
|
||||||
|
|
||||||
// ref page one more time so the page will not be release
|
// ref page one more time so the page will not be release
|
||||||
(void)tdbRefPage(pPage);
|
int32_t nRef = tdbRefPage(pPage);
|
||||||
tdbTrace("pager/mdirty page %p/%d/%d", pPage, TDB_PAGE_PGNO(pPage), pPage->id);
|
tdbTrace("pager/mdirty page %p/%d/%d, ref:%d", pPage, TDB_PAGE_PGNO(pPage), pPage->id, nRef);
|
||||||
|
|
||||||
// Set page as dirty
|
// Set page as dirty
|
||||||
pPage->isDirty = 1;
|
pPage->isDirty = 1;
|
||||||
|
|
||||||
tdbTrace("tdb/pager-write: put page: %p %d to dirty tree: %p", pPage, TDB_PAGE_PGNO(pPage), &pPager->rbt);
|
tdbTrace("tdb/pager-write: put page: %p %d to dirty tree: %p", pPage, TDB_PAGE_PGNO(pPage), &pPager->rbt);
|
||||||
(void)tRBTreePut(&pPager->rbt, (SRBTreeNode *)pPage);
|
SRBTreeNode *tnode = tRBTreePut(&pPager->rbt, (SRBTreeNode *)pPage);
|
||||||
|
|
||||||
// Write page to journal if neccessary
|
// Write page to journal if neccessary
|
||||||
if (TDB_PAGE_PGNO(pPage) <= pPager->dbOrigSize &&
|
if (TDB_PAGE_PGNO(pPage) <= pPager->dbOrigSize &&
|
||||||
|
@ -244,7 +247,7 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pPager->pActiveTxn->jPageSet) {
|
if (pPager->pActiveTxn->jPageSet) {
|
||||||
(void)hashset_add(pPager->pActiveTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage)));
|
int32_t nt = hashset_add(pPager->pActiveTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,7 +343,7 @@ int tdbPagerCommit(SPager *pPager, TXN *pTxn) {
|
||||||
|
|
||||||
tRBTreeDrop(&pPager->rbt, (SRBTreeNode *)pPage);
|
tRBTreeDrop(&pPager->rbt, (SRBTreeNode *)pPage);
|
||||||
if (pTxn->jPageSet) {
|
if (pTxn->jPageSet) {
|
||||||
(void)hashset_remove(pTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage)));
|
int32_t nt = hashset_remove(pTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage)));
|
||||||
}
|
}
|
||||||
|
|
||||||
tdbTrace("tdb/pager-commit: remove page: %p %d from dirty tree: %p", pPage, TDB_PAGE_PGNO(pPage), &pPager->rbt);
|
tdbTrace("tdb/pager-commit: remove page: %p %d from dirty tree: %p", pPage, TDB_PAGE_PGNO(pPage), &pPager->rbt);
|
||||||
|
@ -577,7 +580,7 @@ int tdbPagerAbort(SPager *pPager, TXN *pTxn) {
|
||||||
pPage->isDirty = 0;
|
pPage->isDirty = 0;
|
||||||
|
|
||||||
tRBTreeDrop(&pPager->rbt, (SRBTreeNode *)pPage);
|
tRBTreeDrop(&pPager->rbt, (SRBTreeNode *)pPage);
|
||||||
(void)hashset_remove(pTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage)));
|
int32_t nt = hashset_remove(pTxn->jPageSet, (void *)((long)TDB_PAGE_PGNO(pPage)));
|
||||||
tdbPCacheMarkFree(pPager->pCache, pPage);
|
tdbPCacheMarkFree(pPager->pCache, pPage);
|
||||||
tdbPCacheRelease(pPager->pCache, pPage, pTxn);
|
tdbPCacheRelease(pPager->pCache, pPage, pTxn);
|
||||||
}
|
}
|
||||||
|
@ -699,7 +702,11 @@ int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPa
|
||||||
memcpy(&pgid, pPager->fid, TDB_FILE_ID_LEN);
|
memcpy(&pgid, pPager->fid, TDB_FILE_ID_LEN);
|
||||||
pgid.pgno = pgno;
|
pgid.pgno = pgno;
|
||||||
while ((pPage = tdbPCacheFetch(pPager->pCache, &pgid, pTxn)) == NULL) {
|
while ((pPage = tdbPCacheFetch(pPager->pCache, &pgid, pTxn)) == NULL) {
|
||||||
(void)tdbPagerFlushPage(pPager, pTxn);
|
int32_t code = tdbPagerFlushPage(pPager, pTxn);
|
||||||
|
if (code) {
|
||||||
|
tdbError("tdb/pager: %p, pPage: %p, flush page failed.", pPager, pPage);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tdbTrace("tdbttl fetch pager:%p", pPage->pPager);
|
tdbTrace("tdbttl fetch pager:%p", pPage->pPager);
|
||||||
|
@ -879,7 +886,9 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
|
||||||
lcode = TDB_TRY_LOCK_PAGE(pPage);
|
lcode = TDB_TRY_LOCK_PAGE(pPage);
|
||||||
if (lcode == P_LOCK_SUCC) {
|
if (lcode == P_LOCK_SUCC) {
|
||||||
if (TDB_PAGE_INITIALIZED(pPage)) {
|
if (TDB_PAGE_INITIALIZED(pPage)) {
|
||||||
(void)TDB_UNLOCK_PAGE(pPage);
|
if (TDB_UNLOCK_PAGE(pPage) != 0) {
|
||||||
|
tdbError("tdb/pager:%p, pgno:%d, unlock page failed.", pPager, pgno);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -893,7 +902,10 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
|
||||||
tdbTrace("tdb/pager:%p, pgno:%d, nRead:%" PRId64, pPager, pgno, nRead);
|
tdbTrace("tdb/pager:%p, pgno:%d, nRead:%" PRId64, pPager, pgno, nRead);
|
||||||
if (nRead < pPage->pageSize) {
|
if (nRead < pPage->pageSize) {
|
||||||
tdbError("tdb/pager:%p, pgno:%d, nRead:%" PRId64 "pgSize:%" PRId32, pPager, pgno, nRead, pPage->pageSize);
|
tdbError("tdb/pager:%p, pgno:%d, nRead:%" PRId64 "pgSize:%" PRId32, pPager, pgno, nRead, pPage->pageSize);
|
||||||
(void)TDB_UNLOCK_PAGE(pPage);
|
if (TDB_UNLOCK_PAGE(pPage) < 0) {
|
||||||
|
tdbError("tdb/pager:%p, pgno:%d, nRead:%" PRId64 "pgSize:%" PRId32 " unlock page failed.", pPager, pgno,
|
||||||
|
nRead, pPage->pageSize);
|
||||||
|
}
|
||||||
return TAOS_SYSTEM_ERROR(errno);
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -939,7 +951,10 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
tdbError("tdb/pager:%p, pgno:%d, nRead:%" PRId64 "pgSize:%" PRId32 " init page failed.", pPager, pgno, nRead,
|
tdbError("tdb/pager:%p, pgno:%d, nRead:%" PRId64 "pgSize:%" PRId32 " init page failed.", pPager, pgno, nRead,
|
||||||
pPage->pageSize);
|
pPage->pageSize);
|
||||||
(void)TDB_UNLOCK_PAGE(pPage);
|
if (TDB_UNLOCK_PAGE(pPage) != 0) {
|
||||||
|
tdbError("tdb/pager:%p, pgno:%d, nRead:%" PRId64 "pgSize:%" PRId32 " unlock page failed.", pPager, pgno, nRead,
|
||||||
|
pPage->pageSize);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -947,7 +962,10 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
|
||||||
|
|
||||||
pPage->pPager = pPager;
|
pPage->pPager = pPager;
|
||||||
|
|
||||||
(void)TDB_UNLOCK_PAGE(pPage);
|
if (TDB_UNLOCK_PAGE(pPage) != 0) {
|
||||||
|
tdbError("tdb/pager:%p, pgno:%d, nRead:%" PRId64 "pgSize:%" PRId32 " unlock page failed.", pPager, pgno, nRead,
|
||||||
|
pPage->pageSize);
|
||||||
|
}
|
||||||
} else if (lcode == P_LOCK_BUSY) {
|
} else if (lcode == P_LOCK_BUSY) {
|
||||||
nLoops = 0;
|
nLoops = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
|
@ -112,7 +112,11 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(void)tdbPagerRollback(pPager);
|
ret = tdbPagerRollback(pPager);
|
||||||
|
if (ret < 0) {
|
||||||
|
tdbOsFree(pTb);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// pTb->pBt
|
// pTb->pBt
|
||||||
|
@ -202,7 +206,7 @@ int tdbTbInsert(TTB *pTb, const void *pKey, int keyLen, const void *pVal, int va
|
||||||
int tdbTbDelete(TTB *pTb, const void *pKey, int kLen, TXN *pTxn) { return tdbBtreeDelete(pTb->pBt, pKey, kLen, pTxn); }
|
int tdbTbDelete(TTB *pTb, const void *pKey, int kLen, TXN *pTxn) { return tdbBtreeDelete(pTb->pBt, pKey, kLen, pTxn); }
|
||||||
|
|
||||||
int tdbTbUpsert(TTB *pTb, const void *pKey, int kLen, const void *pVal, int vLen, TXN *pTxn) {
|
int tdbTbUpsert(TTB *pTb, const void *pKey, int kLen, const void *pVal, int vLen, TXN *pTxn) {
|
||||||
(void)tdbTbDelete(pTb, pKey, kLen, pTxn);
|
TAOS_UNUSED(tdbTbDelete(pTb, pKey, kLen, pTxn));
|
||||||
return tdbTbInsert(pTb, pKey, kLen, pVal, vLen, pTxn);
|
return tdbTbInsert(pTb, pKey, kLen, pVal, vLen, pTxn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,7 +245,11 @@ int32_t tdbTbTraversal(TTB *pTb, void *data,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)tdbTbcMoveToFirst(pCur);
|
ret = tdbTbcMoveToFirst(pCur);
|
||||||
|
if (ret < 0) {
|
||||||
|
tdbTbcClose(pCur);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
void *pKey = NULL;
|
void *pKey = NULL;
|
||||||
int kLen = 0;
|
int kLen = 0;
|
||||||
|
|
|
@ -31,7 +31,7 @@ int tdbTxnOpen(TXN *pTxn, int64_t txnid, void *(*xMalloc)(void *, size_t), void
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int tdbTxnCloseImpl(TXN *pTxn) {
|
void tdbTxnCloseImpl(TXN *pTxn) {
|
||||||
if (pTxn) {
|
if (pTxn) {
|
||||||
if (pTxn->jPageSet) {
|
if (pTxn->jPageSet) {
|
||||||
hashset_destroy(pTxn->jPageSet);
|
hashset_destroy(pTxn->jPageSet);
|
||||||
|
@ -39,11 +39,14 @@ int tdbTxnCloseImpl(TXN *pTxn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pTxn->jfd) {
|
if (pTxn->jfd) {
|
||||||
TAOS_UNUSED(tdbOsClose(pTxn->jfd));
|
int32_t code = tdbOsClose(pTxn->jfd);
|
||||||
|
if (code) {
|
||||||
|
tdbError("tdb/txn: close journal file failed, code:%d", code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tdbOsFree(pTxn);
|
tdbOsFree(pTxn);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,7 +179,7 @@ int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int
|
||||||
// tdbPager.c ====================================
|
// tdbPager.c ====================================
|
||||||
|
|
||||||
int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager);
|
int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager);
|
||||||
int tdbPagerClose(SPager *pPager);
|
void tdbPagerClose(SPager *pPager);
|
||||||
int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate, SBTree *pBt);
|
int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate, SBTree *pBt);
|
||||||
int tdbPagerWrite(SPager *pPager, SPage *pPage);
|
int tdbPagerWrite(SPager *pPager, SPage *pPage);
|
||||||
int tdbPagerBegin(SPager *pPager, TXN *pTxn);
|
int tdbPagerBegin(SPager *pPager, TXN *pTxn);
|
||||||
|
@ -214,7 +214,7 @@ int tdbPagerRollback(SPager *pPager);
|
||||||
// For page ref
|
// For page ref
|
||||||
|
|
||||||
int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache);
|
int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache);
|
||||||
int tdbPCacheClose(SPCache *pCache);
|
void tdbPCacheClose(SPCache *pCache);
|
||||||
int tdbPCacheAlter(SPCache *pCache, int32_t nPage);
|
int tdbPCacheAlter(SPCache *pCache, int32_t nPage);
|
||||||
SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, TXN *pTxn);
|
SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, TXN *pTxn);
|
||||||
void tdbPCacheRelease(SPCache *pCache, SPage *pPage, TXN *pTxn);
|
void tdbPCacheRelease(SPCache *pCache, SPage *pPage, TXN *pTxn);
|
||||||
|
|
|
@ -112,7 +112,7 @@ void tEndEncode(SEncoder* pCoder) {
|
||||||
pCoder->size = pNode->size;
|
pCoder->size = pNode->size;
|
||||||
pCoder->pos = pNode->pos;
|
pCoder->pos = pNode->pos;
|
||||||
|
|
||||||
(void)tEncodeI32(pCoder, len);
|
int32_t ret = tEncodeI32(pCoder, len);
|
||||||
|
|
||||||
pCoder->pos += len;
|
pCoder->pos += len;
|
||||||
}
|
}
|
||||||
|
|
|
@ -391,14 +391,13 @@ void *taosHashGet(SHashObj *pHashObj, const void *key, size_t keyLen) {
|
||||||
|
|
||||||
int32_t taosHashGetDup(SHashObj *pHashObj, const void *key, size_t keyLen, void *destBuf) {
|
int32_t taosHashGetDup(SHashObj *pHashObj, const void *key, size_t keyLen, void *destBuf) {
|
||||||
terrno = 0;
|
terrno = 0;
|
||||||
(void)taosHashGetImpl(pHashObj, key, keyLen, &destBuf, 0, false);
|
void *data = taosHashGetImpl(pHashObj, key, keyLen, &destBuf, 0, false);
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosHashGetDup_m(SHashObj *pHashObj, const void *key, size_t keyLen, void **destBuf, int32_t *size) {
|
int32_t taosHashGetDup_m(SHashObj *pHashObj, const void *key, size_t keyLen, void **destBuf, int32_t *size) {
|
||||||
terrno = 0;
|
terrno = 0;
|
||||||
|
void *data = taosHashGetImpl(pHashObj, key, keyLen, destBuf, size, false);
|
||||||
(void)taosHashGetImpl(pHashObj, key, keyLen, destBuf, size, false);
|
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -257,10 +257,11 @@ static PriorityQueueNode* pqHeapify(PriorityQueue* pq, size_t from, size_t last)
|
||||||
|
|
||||||
static void pqBuildHeap(PriorityQueue* pq) {
|
static void pqBuildHeap(PriorityQueue* pq) {
|
||||||
if (pqContainerSize(pq) > 1) {
|
if (pqContainerSize(pq) > 1) {
|
||||||
|
PriorityQueueNode* node;
|
||||||
for (size_t i = pqContainerSize(pq) - 1; i > 0; --i) {
|
for (size_t i = pqContainerSize(pq) - 1; i > 0; --i) {
|
||||||
(void)pqHeapify(pq, i, pqContainerSize(pq));
|
node = pqHeapify(pq, i, pqContainerSize(pq));
|
||||||
}
|
}
|
||||||
(void)pqHeapify(pq, 0, pqContainerSize(pq));
|
node = pqHeapify(pq, 0, pqContainerSize(pq));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,23 +275,24 @@ static PriorityQueueNode* pqReverseHeapify(PriorityQueue* pq, size_t i) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pqUpdate(PriorityQueue* pq, size_t i) {
|
static void pqUpdate(PriorityQueue* pq, size_t i) {
|
||||||
|
PriorityQueueNode* node;
|
||||||
if (i == 0 || pq->fn(pqContainerGetEle(pq, i)->data, pqContainerGetEle(pq, pqParent(i))->data, pq->param)) {
|
if (i == 0 || pq->fn(pqContainerGetEle(pq, i)->data, pqContainerGetEle(pq, pqParent(i))->data, pq->param)) {
|
||||||
// if value in pos i is smaller than parent, heapify down from i to the end
|
// if value in pos i is smaller than parent, heapify down from i to the end
|
||||||
(void)pqHeapify(pq, i, pqContainerSize(pq));
|
node = pqHeapify(pq, i, pqContainerSize(pq));
|
||||||
} else {
|
} else {
|
||||||
// if value in pos i is big than parent, heapify up from i
|
// if value in pos i is big than parent, heapify up from i
|
||||||
(void)pqReverseHeapify(pq, i);
|
node = pqReverseHeapify(pq, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pqRemove(PriorityQueue* pq, size_t i) {
|
static void pqRemove(PriorityQueue* pq, size_t i) {
|
||||||
if (i == pqContainerSize(pq) - 1) {
|
if (i == pqContainerSize(pq) - 1) {
|
||||||
(void)taosArrayPop(pq->container);
|
void* tmp = taosArrayPop(pq->container);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArraySet(pq->container, i, taosArrayGet(pq->container, pqContainerSize(pq) - 1));
|
taosArraySet(pq->container, i, taosArrayGet(pq->container, pqContainerSize(pq) - 1));
|
||||||
(void)taosArrayPop(pq->container);
|
void* tmp = taosArrayPop(pq->container);
|
||||||
pqUpdate(pq, i);
|
pqUpdate(pq, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -305,7 +305,7 @@ static void taosLRUCacheShardEvictLRU(SLRUCacheShard *shard, size_t charge, SArr
|
||||||
SLRUEntry *old = shard->lru.next;
|
SLRUEntry *old = shard->lru.next;
|
||||||
|
|
||||||
taosLRUCacheShardLRURemove(shard, old);
|
taosLRUCacheShardLRURemove(shard, old);
|
||||||
(void)taosLRUEntryTableRemove(&shard->table, old->keyData, old->keyLength, old->hash);
|
SLRUEntry *tentry = taosLRUEntryTableRemove(&shard->table, old->keyData, old->keyLength, old->hash);
|
||||||
|
|
||||||
TAOS_LRU_ENTRY_SET_IN_CACHE(old, false);
|
TAOS_LRU_ENTRY_SET_IN_CACHE(old, false);
|
||||||
shard->usage -= old->totalCharge;
|
shard->usage -= old->totalCharge;
|
||||||
|
@ -529,7 +529,7 @@ static void taosLRUCacheShardEraseUnrefEntries(SLRUCacheShard *shard) {
|
||||||
while (shard->lru.next != &shard->lru) {
|
while (shard->lru.next != &shard->lru) {
|
||||||
SLRUEntry *old = shard->lru.next;
|
SLRUEntry *old = shard->lru.next;
|
||||||
taosLRUCacheShardLRURemove(shard, old);
|
taosLRUCacheShardLRURemove(shard, old);
|
||||||
(void)taosLRUEntryTableRemove(&shard->table, old->keyData, old->keyLength, old->hash);
|
SLRUEntry *tentry = taosLRUEntryTableRemove(&shard->table, old->keyData, old->keyLength, old->hash);
|
||||||
TAOS_LRU_ENTRY_SET_IN_CACHE(old, false);
|
TAOS_LRU_ENTRY_SET_IN_CACHE(old, false);
|
||||||
shard->usage -= old->totalCharge;
|
shard->usage -= old->totalCharge;
|
||||||
|
|
||||||
|
@ -574,7 +574,7 @@ static bool taosLRUCacheShardRelease(SLRUCacheShard *shard, LRUHandle *handle, b
|
||||||
lastReference = taosLRUEntryUnref(e);
|
lastReference = taosLRUEntryUnref(e);
|
||||||
if (lastReference && TAOS_LRU_ENTRY_IN_CACHE(e)) {
|
if (lastReference && TAOS_LRU_ENTRY_IN_CACHE(e)) {
|
||||||
if (shard->usage > shard->capacity || eraseIfLastRef) {
|
if (shard->usage > shard->capacity || eraseIfLastRef) {
|
||||||
(void)taosLRUEntryTableRemove(&shard->table, e->keyData, e->keyLength, e->hash);
|
SLRUEntry *tentry = taosLRUEntryTableRemove(&shard->table, e->keyData, e->keyLength, e->hash);
|
||||||
TAOS_LRU_ENTRY_SET_IN_CACHE(e, false);
|
TAOS_LRU_ENTRY_SET_IN_CACHE(e, false);
|
||||||
} else {
|
} else {
|
||||||
taosLRUCacheShardLRUInsert(shard, e);
|
taosLRUCacheShardLRUInsert(shard, e);
|
||||||
|
|
|
@ -32,9 +32,9 @@ static SSkipListNode *tSkipListNewNode(uint8_t level);
|
||||||
static SSkipListNode *tSkipListPutImpl(SSkipList *pSkipList, void *pData, SSkipListNode **direction, bool isForward,
|
static SSkipListNode *tSkipListPutImpl(SSkipList *pSkipList, void *pData, SSkipListNode **direction, bool isForward,
|
||||||
bool hasDup);
|
bool hasDup);
|
||||||
|
|
||||||
static FORCE_INLINE int32_t tSkipListWLock(SSkipList *pSkipList);
|
static FORCE_INLINE void tSkipListWLock(SSkipList *pSkipList);
|
||||||
static FORCE_INLINE int32_t tSkipListRLock(SSkipList *pSkipList);
|
static FORCE_INLINE void tSkipListRLock(SSkipList *pSkipList);
|
||||||
static FORCE_INLINE int32_t tSkipListUnlock(SSkipList *pSkipList);
|
static FORCE_INLINE void tSkipListUnlock(SSkipList *pSkipList);
|
||||||
static FORCE_INLINE int32_t getSkipListRandLevel(SSkipList *pSkipList);
|
static FORCE_INLINE int32_t getSkipListRandLevel(SSkipList *pSkipList);
|
||||||
|
|
||||||
SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, __compar_fn_t comparFn, uint8_t flags,
|
SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, __compar_fn_t comparFn, uint8_t flags,
|
||||||
|
@ -103,7 +103,7 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _
|
||||||
void tSkipListDestroy(SSkipList *pSkipList) {
|
void tSkipListDestroy(SSkipList *pSkipList) {
|
||||||
if (pSkipList == NULL) return;
|
if (pSkipList == NULL) return;
|
||||||
|
|
||||||
(void)tSkipListWLock(pSkipList);
|
tSkipListWLock(pSkipList);
|
||||||
|
|
||||||
SSkipListNode *pNode = SL_NODE_GET_FORWARD_POINTER(pSkipList->pHead, 0);
|
SSkipListNode *pNode = SL_NODE_GET_FORWARD_POINTER(pSkipList->pHead, 0);
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ void tSkipListDestroy(SSkipList *pSkipList) {
|
||||||
tSkipListFreeNode(pTemp);
|
tSkipListFreeNode(pTemp);
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)tSkipListUnlock(pSkipList);
|
tSkipListUnlock(pSkipList);
|
||||||
if (pSkipList->lock != NULL) {
|
if (pSkipList->lock != NULL) {
|
||||||
(void)taosThreadRwlockDestroy(pSkipList->lock);
|
(void)taosThreadRwlockDestroy(pSkipList->lock);
|
||||||
taosMemoryFreeClear(pSkipList->lock);
|
taosMemoryFreeClear(pSkipList->lock);
|
||||||
|
@ -130,12 +130,12 @@ SSkipListNode *tSkipListPut(SSkipList *pSkipList, void *pData) {
|
||||||
SSkipListNode *backward[MAX_SKIP_LIST_LEVEL] = {0};
|
SSkipListNode *backward[MAX_SKIP_LIST_LEVEL] = {0};
|
||||||
SSkipListNode *pNode = NULL;
|
SSkipListNode *pNode = NULL;
|
||||||
|
|
||||||
(void)tSkipListWLock(pSkipList);
|
tSkipListWLock(pSkipList);
|
||||||
|
|
||||||
bool hasDup = tSkipListGetPosToPut(pSkipList, backward, pData);
|
bool hasDup = tSkipListGetPosToPut(pSkipList, backward, pData);
|
||||||
pNode = tSkipListPutImpl(pSkipList, pData, backward, false, hasDup);
|
pNode = tSkipListPutImpl(pSkipList, pData, backward, false, hasDup);
|
||||||
|
|
||||||
(void)tSkipListUnlock(pSkipList);
|
tSkipListUnlock(pSkipList);
|
||||||
|
|
||||||
return pNode;
|
return pNode;
|
||||||
}
|
}
|
||||||
|
@ -293,11 +293,11 @@ SSkipListIterator *tSkipListCreateIterFromVal(SSkipList *pSkipList, const char *
|
||||||
return iter;
|
return iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)tSkipListRLock(pSkipList);
|
tSkipListRLock(pSkipList);
|
||||||
|
|
||||||
iter->cur = getPriorNode(pSkipList, val, order, &(iter->next));
|
iter->cur = getPriorNode(pSkipList, val, order, &(iter->next));
|
||||||
|
|
||||||
(void)tSkipListUnlock(pSkipList);
|
tSkipListUnlock(pSkipList);
|
||||||
|
|
||||||
return iter;
|
return iter;
|
||||||
}
|
}
|
||||||
|
@ -307,13 +307,13 @@ bool tSkipListIterNext(SSkipListIterator *iter) {
|
||||||
|
|
||||||
SSkipList *pSkipList = iter->pSkipList;
|
SSkipList *pSkipList = iter->pSkipList;
|
||||||
|
|
||||||
(void)tSkipListRLock(pSkipList);
|
tSkipListRLock(pSkipList);
|
||||||
|
|
||||||
if (iter->order == TSDB_ORDER_ASC) {
|
if (iter->order == TSDB_ORDER_ASC) {
|
||||||
// no data in the skip list
|
// no data in the skip list
|
||||||
if (iter->cur == pSkipList->pTail || iter->next == NULL) {
|
if (iter->cur == pSkipList->pTail || iter->next == NULL) {
|
||||||
iter->cur = pSkipList->pTail;
|
iter->cur = pSkipList->pTail;
|
||||||
(void)tSkipListUnlock(pSkipList);
|
tSkipListUnlock(pSkipList);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ bool tSkipListIterNext(SSkipListIterator *iter) {
|
||||||
} else {
|
} else {
|
||||||
if (iter->cur == pSkipList->pHead) {
|
if (iter->cur == pSkipList->pHead) {
|
||||||
iter->cur = pSkipList->pHead;
|
iter->cur = pSkipList->pHead;
|
||||||
(void)tSkipListUnlock(pSkipList);
|
tSkipListUnlock(pSkipList);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,7 +344,7 @@ bool tSkipListIterNext(SSkipListIterator *iter) {
|
||||||
iter->step++;
|
iter->step++;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)tSkipListUnlock(pSkipList);
|
tSkipListUnlock(pSkipList);
|
||||||
|
|
||||||
return (iter->order == TSDB_ORDER_ASC) ? (iter->cur != pSkipList->pTail) : (iter->cur != pSkipList->pHead);
|
return (iter->order == TSDB_ORDER_ASC) ? (iter->cur != pSkipList->pTail) : (iter->cur != pSkipList->pHead);
|
||||||
}
|
}
|
||||||
|
@ -413,25 +413,31 @@ static SSkipListIterator *doCreateSkipListIterator(SSkipList *pSkipList, int32_t
|
||||||
return iter;
|
return iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int32_t tSkipListWLock(SSkipList *pSkipList) {
|
static FORCE_INLINE void tSkipListWLock(SSkipList *pSkipList) {
|
||||||
if (pSkipList->lock) {
|
if (pSkipList->lock) {
|
||||||
return taosThreadRwlockWrlock(pSkipList->lock);
|
if (taosThreadRwlockWrlock(pSkipList->lock) != 0) {
|
||||||
|
uError("failed to lock skip list");
|
||||||
}
|
}
|
||||||
return 0;
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int32_t tSkipListRLock(SSkipList *pSkipList) {
|
static FORCE_INLINE void tSkipListRLock(SSkipList *pSkipList) {
|
||||||
if (pSkipList->lock) {
|
if (pSkipList->lock) {
|
||||||
return taosThreadRwlockRdlock(pSkipList->lock);
|
if (taosThreadRwlockRdlock(pSkipList->lock) != 0) {
|
||||||
|
uError("failed to lock skip list");
|
||||||
}
|
}
|
||||||
return 0;
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE int32_t tSkipListUnlock(SSkipList *pSkipList) {
|
static FORCE_INLINE void tSkipListUnlock(SSkipList *pSkipList) {
|
||||||
if (pSkipList->lock) {
|
if (pSkipList->lock) {
|
||||||
return taosThreadRwlockUnlock(pSkipList->lock);
|
if (taosThreadRwlockUnlock(pSkipList->lock) != 0) {
|
||||||
|
uError("failed to unlock skip list");
|
||||||
}
|
}
|
||||||
return 0;
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool tSkipListGetPosToPut(SSkipList *pSkipList, SSkipListNode **backward, void *pData) {
|
static bool tSkipListGetPosToPut(SSkipList *pSkipList, SSkipListNode **backward, void *pData) {
|
||||||
|
|
|
@ -59,7 +59,7 @@ void tQWorkerCleanup(SQWorkerPool *pool) {
|
||||||
if (taosCheckPthreadValid(worker->thread)) {
|
if (taosCheckPthreadValid(worker->thread)) {
|
||||||
uInfo("worker:%s:%d is stopping", pool->name, worker->id);
|
uInfo("worker:%s:%d is stopping", pool->name, worker->id);
|
||||||
(void)taosThreadJoin(worker->thread, NULL);
|
(void)taosThreadJoin(worker->thread, NULL);
|
||||||
(void)taosThreadClear(&worker->thread);
|
taosThreadClear(&worker->thread);
|
||||||
uInfo("worker:%s:%d is stopped", pool->name, worker->id);
|
uInfo("worker:%s:%d is stopped", pool->name, worker->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,11 @@ static void *tQWorkerThreadFp(SQueueWorker *worker) {
|
||||||
void *msg = NULL;
|
void *msg = NULL;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
(void)taosBlockSIGPIPE();
|
int32_t ret = taosBlockSIGPIPE();
|
||||||
|
if (ret < 0) {
|
||||||
|
uError("worker:%s:%d failed to block SIGPIPE", pool->name, worker->id);
|
||||||
|
}
|
||||||
|
|
||||||
setThreadName(pool->name);
|
setThreadName(pool->name);
|
||||||
worker->pid = taosGetSelfPthreadId();
|
worker->pid = taosGetSelfPthreadId();
|
||||||
uInfo("worker:%s:%d is running, thread:%08" PRId64, pool->name, worker->id, worker->pid);
|
uInfo("worker:%s:%d is running, thread:%08" PRId64, pool->name, worker->id, worker->pid);
|
||||||
|
@ -122,7 +126,13 @@ STaosQueue *tQWorkerAllocQueue(SQWorkerPool *pool, void *ahandle, FItem fp) {
|
||||||
|
|
||||||
(void)taosThreadMutexLock(&pool->mutex);
|
(void)taosThreadMutexLock(&pool->mutex);
|
||||||
taosSetQueueFp(queue, fp, NULL);
|
taosSetQueueFp(queue, fp, NULL);
|
||||||
(void)taosAddIntoQset(pool->qset, queue, ahandle);
|
code = taosAddIntoQset(pool->qset, queue, ahandle);
|
||||||
|
if (code) {
|
||||||
|
taosCloseQueue(queue);
|
||||||
|
(void)taosThreadMutexUnlock(&pool->mutex);
|
||||||
|
terrno = code;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// spawn a thread to process queue
|
// spawn a thread to process queue
|
||||||
if (pool->num < pool->max) {
|
if (pool->num < pool->max) {
|
||||||
|
@ -191,7 +201,7 @@ void tAutoQWorkerCleanup(SAutoQWorkerPool *pool) {
|
||||||
if (taosCheckPthreadValid(worker->thread)) {
|
if (taosCheckPthreadValid(worker->thread)) {
|
||||||
uInfo("worker:%s:%d is stopping", pool->name, worker->id);
|
uInfo("worker:%s:%d is stopping", pool->name, worker->id);
|
||||||
(void)taosThreadJoin(worker->thread, NULL);
|
(void)taosThreadJoin(worker->thread, NULL);
|
||||||
(void)taosThreadClear(&worker->thread);
|
taosThreadClear(&worker->thread);
|
||||||
uInfo("worker:%s:%d is stopped", pool->name, worker->id);
|
uInfo("worker:%s:%d is stopped", pool->name, worker->id);
|
||||||
}
|
}
|
||||||
taosMemoryFree(worker);
|
taosMemoryFree(worker);
|
||||||
|
@ -210,7 +220,11 @@ static void *tAutoQWorkerThreadFp(SQueueWorker *worker) {
|
||||||
void *msg = NULL;
|
void *msg = NULL;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
(void)taosBlockSIGPIPE();
|
int32_t ret = taosBlockSIGPIPE();
|
||||||
|
if (ret < 0) {
|
||||||
|
uError("worker:%s:%d failed to block SIGPIPE", pool->name, worker->id);
|
||||||
|
}
|
||||||
|
|
||||||
setThreadName(pool->name);
|
setThreadName(pool->name);
|
||||||
worker->pid = taosGetSelfPthreadId();
|
worker->pid = taosGetSelfPthreadId();
|
||||||
uInfo("worker:%s:%d is running, thread:%08" PRId64, pool->name, worker->id, worker->pid);
|
uInfo("worker:%s:%d is running, thread:%08" PRId64, pool->name, worker->id, worker->pid);
|
||||||
|
@ -254,7 +268,14 @@ STaosQueue *tAutoQWorkerAllocQueue(SAutoQWorkerPool *pool, void *ahandle, FItem
|
||||||
|
|
||||||
(void)taosThreadMutexLock(&pool->mutex);
|
(void)taosThreadMutexLock(&pool->mutex);
|
||||||
taosSetQueueFp(queue, fp, NULL);
|
taosSetQueueFp(queue, fp, NULL);
|
||||||
(void)taosAddIntoQset(pool->qset, queue, ahandle);
|
|
||||||
|
code = taosAddIntoQset(pool->qset, queue, ahandle);
|
||||||
|
if (code) {
|
||||||
|
taosCloseQueue(queue);
|
||||||
|
(void)taosThreadMutexUnlock(&pool->mutex);
|
||||||
|
terrno = code;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t queueNum = taosGetQueueNumber(pool->qset);
|
int32_t queueNum = taosGetQueueNumber(pool->qset);
|
||||||
int32_t curWorkerNum = taosArrayGetSize(pool->workers);
|
int32_t curWorkerNum = taosArrayGetSize(pool->workers);
|
||||||
|
@ -281,7 +302,7 @@ STaosQueue *tAutoQWorkerAllocQueue(SAutoQWorkerPool *pool, void *ahandle, FItem
|
||||||
|
|
||||||
if (taosThreadCreate(&worker->thread, &thAttr, (ThreadFp)tAutoQWorkerThreadFp, worker) != 0) {
|
if (taosThreadCreate(&worker->thread, &thAttr, (ThreadFp)tAutoQWorkerThreadFp, worker) != 0) {
|
||||||
uError("worker:%s:%d failed to create thread, total:%d", pool->name, worker->id, curWorkerNum);
|
uError("worker:%s:%d failed to create thread, total:%d", pool->name, worker->id, curWorkerNum);
|
||||||
(void)taosArrayPop(pool->workers);
|
void *tmp = taosArrayPop(pool->workers);
|
||||||
taosMemoryFree(worker);
|
taosMemoryFree(worker);
|
||||||
taosCloseQueue(queue);
|
taosCloseQueue(queue);
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -342,7 +363,7 @@ void tWWorkerCleanup(SWWorkerPool *pool) {
|
||||||
if (taosCheckPthreadValid(worker->thread)) {
|
if (taosCheckPthreadValid(worker->thread)) {
|
||||||
uInfo("worker:%s:%d is stopping", pool->name, worker->id);
|
uInfo("worker:%s:%d is stopping", pool->name, worker->id);
|
||||||
(void)taosThreadJoin(worker->thread, NULL);
|
(void)taosThreadJoin(worker->thread, NULL);
|
||||||
(void)taosThreadClear(&worker->thread);
|
taosThreadClear(&worker->thread);
|
||||||
taosFreeQall(worker->qall);
|
taosFreeQall(worker->qall);
|
||||||
taosCloseQset(worker->qset);
|
taosCloseQset(worker->qset);
|
||||||
uInfo("worker:%s:%d is stopped", pool->name, worker->id);
|
uInfo("worker:%s:%d is stopped", pool->name, worker->id);
|
||||||
|
@ -362,7 +383,11 @@ static void *tWWorkerThreadFp(SWWorker *worker) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t numOfMsgs = 0;
|
int32_t numOfMsgs = 0;
|
||||||
|
|
||||||
(void)taosBlockSIGPIPE();
|
int32_t ret = taosBlockSIGPIPE();
|
||||||
|
if (ret < 0) {
|
||||||
|
uError("worker:%s:%d failed to block SIGPIPE", pool->name, worker->id);
|
||||||
|
}
|
||||||
|
|
||||||
setThreadName(pool->name);
|
setThreadName(pool->name);
|
||||||
worker->pid = taosGetSelfPthreadId();
|
worker->pid = taosGetSelfPthreadId();
|
||||||
uInfo("worker:%s:%d is running, thread:%08" PRId64, pool->name, worker->id, worker->pid);
|
uInfo("worker:%s:%d is running, thread:%08" PRId64, pool->name, worker->id, worker->pid);
|
||||||
|
@ -407,7 +432,8 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) {
|
||||||
code = taosOpenQset(&worker->qset);
|
code = taosOpenQset(&worker->qset);
|
||||||
if (code) goto _OVER;
|
if (code) goto _OVER;
|
||||||
|
|
||||||
(void)taosAddIntoQset(worker->qset, queue, ahandle);
|
code = taosAddIntoQset(worker->qset, queue, ahandle);
|
||||||
|
if (code) goto _OVER;
|
||||||
code = taosAllocateQall(&worker->qall);
|
code = taosAllocateQall(&worker->qall);
|
||||||
if (code) goto _OVER;
|
if (code) goto _OVER;
|
||||||
|
|
||||||
|
@ -423,7 +449,8 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) {
|
||||||
pool->num++;
|
pool->num++;
|
||||||
if (pool->num > pool->max) pool->num = pool->max;
|
if (pool->num > pool->max) pool->num = pool->max;
|
||||||
} else {
|
} else {
|
||||||
(void)taosAddIntoQset(worker->qset, queue, ahandle);
|
code = taosAddIntoQset(worker->qset, queue, ahandle);
|
||||||
|
if (code) goto _OVER;
|
||||||
pool->nextId = (pool->nextId + 1) % pool->max;
|
pool->nextId = (pool->nextId + 1) % pool->max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -551,7 +578,7 @@ void tMultiWorkerCleanup(SMultiWorker *pWorker) {
|
||||||
static int32_t tQueryAutoQWorkerAddWorker(SQueryAutoQWorkerPool *pool);
|
static int32_t tQueryAutoQWorkerAddWorker(SQueryAutoQWorkerPool *pool);
|
||||||
static int32_t tQueryAutoQWorkerBeforeBlocking(void *p);
|
static int32_t tQueryAutoQWorkerBeforeBlocking(void *p);
|
||||||
static int32_t tQueryAutoQWorkerRecoverFromBlocking(void *p);
|
static int32_t tQueryAutoQWorkerRecoverFromBlocking(void *p);
|
||||||
static int32_t tQueryAutoQWorkerWaitingCheck(SQueryAutoQWorkerPool *pPool);
|
static void tQueryAutoQWorkerWaitingCheck(SQueryAutoQWorkerPool *pPool);
|
||||||
static bool tQueryAutoQWorkerTryRecycleWorker(SQueryAutoQWorkerPool *pPool, SQueryAutoQWorker *pWorker);
|
static bool tQueryAutoQWorkerTryRecycleWorker(SQueryAutoQWorkerPool *pPool, SQueryAutoQWorker *pWorker);
|
||||||
|
|
||||||
#define GET_ACTIVE_N(int64_val) (int32_t)((int64_val) >> 32)
|
#define GET_ACTIVE_N(int64_val) (int32_t)((int64_val) >> 32)
|
||||||
|
@ -629,7 +656,11 @@ static void *tQueryAutoQWorkerThreadFp(SQueryAutoQWorker *worker) {
|
||||||
void *msg = NULL;
|
void *msg = NULL;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
(void)taosBlockSIGPIPE();
|
int32_t ret = taosBlockSIGPIPE();
|
||||||
|
if (ret < 0) {
|
||||||
|
uError("worker:%s:%d failed to block SIGPIPE", pool->name, worker->id);
|
||||||
|
}
|
||||||
|
|
||||||
setThreadName(pool->name);
|
setThreadName(pool->name);
|
||||||
worker->pid = taosGetSelfPthreadId();
|
worker->pid = taosGetSelfPthreadId();
|
||||||
uDebug("worker:%s:%d is running, thread:%08" PRId64, pool->name, worker->id, worker->pid);
|
uDebug("worker:%s:%d is running, thread:%08" PRId64, pool->name, worker->id, worker->pid);
|
||||||
|
@ -648,7 +679,7 @@ static void *tQueryAutoQWorkerThreadFp(SQueryAutoQWorker *worker) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)tQueryAutoQWorkerWaitingCheck(pool);
|
tQueryAutoQWorkerWaitingCheck(pool);
|
||||||
|
|
||||||
if (qinfo.fp != NULL) {
|
if (qinfo.fp != NULL) {
|
||||||
qinfo.workerId = worker->id;
|
qinfo.workerId = worker->id;
|
||||||
|
@ -717,13 +748,13 @@ static bool tQueryAutoQWorkerTryDecActive(void *p, int32_t minActive) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t tQueryAutoQWorkerWaitingCheck(SQueryAutoQWorkerPool *pPool) {
|
static void tQueryAutoQWorkerWaitingCheck(SQueryAutoQWorkerPool *pPool) {
|
||||||
while (1) {
|
while (1) {
|
||||||
int64_t val64 = pPool->activeRunningN;
|
int64_t val64 = pPool->activeRunningN;
|
||||||
int32_t running = GET_RUNNING_N(val64), active = GET_ACTIVE_N(val64);
|
int32_t running = GET_RUNNING_N(val64), active = GET_ACTIVE_N(val64);
|
||||||
while (running < pPool->num) {
|
while (running < pPool->num) {
|
||||||
if (atomicCompareExchangeActiveAndRunning(&pPool->activeRunningN, &active, active, &running, running + 1)) {
|
if (atomicCompareExchangeActiveAndRunning(&pPool->activeRunningN, &active, active, &running, running + 1)) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (atomicCompareExchangeActive(&pPool->activeRunningN, &active, active - 1)) {
|
if (atomicCompareExchangeActive(&pPool->activeRunningN, &active, active - 1)) {
|
||||||
|
@ -736,7 +767,7 @@ static int32_t tQueryAutoQWorkerWaitingCheck(SQueryAutoQWorkerPool *pPool) {
|
||||||
if (!pPool->exit) (void)taosThreadCondWait(&pPool->waitingBeforeProcessMsgCond, &pPool->waitingBeforeProcessMsgLock);
|
if (!pPool->exit) (void)taosThreadCondWait(&pPool->waitingBeforeProcessMsgCond, &pPool->waitingBeforeProcessMsgLock);
|
||||||
// recovered from waiting
|
// recovered from waiting
|
||||||
(void)taosThreadMutexUnlock(&pPool->waitingBeforeProcessMsgLock);
|
(void)taosThreadMutexUnlock(&pPool->waitingBeforeProcessMsgLock);
|
||||||
return TSDB_CODE_SUCCESS;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tQueryAutoQWorkerTryRecycleWorker(SQueryAutoQWorkerPool *pPool, SQueryAutoQWorker *pWorker) {
|
bool tQueryAutoQWorkerTryRecycleWorker(SQueryAutoQWorkerPool *pPool, SQueryAutoQWorker *pWorker) {
|
||||||
|
@ -744,7 +775,7 @@ bool tQueryAutoQWorkerTryRecycleWorker(SQueryAutoQWorkerPool *pPool, SQueryAutoQ
|
||||||
tQueryAutoQWorkerTryDecActive(pPool, pPool->num)) {
|
tQueryAutoQWorkerTryDecActive(pPool, pPool->num)) {
|
||||||
(void)taosThreadMutexLock(&pPool->poolLock);
|
(void)taosThreadMutexLock(&pPool->poolLock);
|
||||||
SListNode *pNode = listNode(pWorker);
|
SListNode *pNode = listNode(pWorker);
|
||||||
(void)tdListPopNode(pPool->workers, pNode);
|
SListNode *tNode = tdListPopNode(pPool->workers, pNode);
|
||||||
// reclaim some workers
|
// reclaim some workers
|
||||||
if (pWorker->id >= pPool->maxInUse) {
|
if (pWorker->id >= pPool->maxInUse) {
|
||||||
while (listNEles(pPool->exitedWorkers) > pPool->maxInUse - pPool->num) {
|
while (listNEles(pPool->exitedWorkers) > pPool->maxInUse - pPool->num) {
|
||||||
|
@ -752,7 +783,7 @@ bool tQueryAutoQWorkerTryRecycleWorker(SQueryAutoQWorkerPool *pPool, SQueryAutoQ
|
||||||
SQueryAutoQWorker *pWorker = (SQueryAutoQWorker *)head->data;
|
SQueryAutoQWorker *pWorker = (SQueryAutoQWorker *)head->data;
|
||||||
if (pWorker && taosCheckPthreadValid(pWorker->thread)) {
|
if (pWorker && taosCheckPthreadValid(pWorker->thread)) {
|
||||||
(void)taosThreadJoin(pWorker->thread, NULL);
|
(void)taosThreadJoin(pWorker->thread, NULL);
|
||||||
(void)taosThreadClear(&pWorker->thread);
|
taosThreadClear(&pWorker->thread);
|
||||||
}
|
}
|
||||||
taosMemoryFree(head);
|
taosMemoryFree(head);
|
||||||
}
|
}
|
||||||
|
@ -777,7 +808,7 @@ bool tQueryAutoQWorkerTryRecycleWorker(SQueryAutoQWorkerPool *pPool, SQueryAutoQ
|
||||||
(void)taosThreadMutexUnlock(&pPool->poolLock);
|
(void)taosThreadMutexUnlock(&pPool->poolLock);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
(void)tdListPopNode(pPool->backupWorkers, pNode);
|
SListNode *tNode1 = tdListPopNode(pPool->backupWorkers, pNode);
|
||||||
tdListAppendNode(pPool->workers, pNode);
|
tdListAppendNode(pPool->workers, pNode);
|
||||||
(void)taosThreadMutexUnlock(&pPool->poolLock);
|
(void)taosThreadMutexUnlock(&pPool->poolLock);
|
||||||
|
|
||||||
|
@ -862,7 +893,7 @@ void tQueryAutoQWorkerCleanup(SQueryAutoQWorkerPool *pPool) {
|
||||||
(void)taosThreadMutexUnlock(&pPool->poolLock);
|
(void)taosThreadMutexUnlock(&pPool->poolLock);
|
||||||
if (worker && taosCheckPthreadValid(worker->thread)) {
|
if (worker && taosCheckPthreadValid(worker->thread)) {
|
||||||
(void)taosThreadJoin(worker->thread, NULL);
|
(void)taosThreadJoin(worker->thread, NULL);
|
||||||
(void)taosThreadClear(&worker->thread);
|
taosThreadClear(&worker->thread);
|
||||||
}
|
}
|
||||||
taosMemoryFree(pNode);
|
taosMemoryFree(pNode);
|
||||||
}
|
}
|
||||||
|
@ -872,7 +903,7 @@ void tQueryAutoQWorkerCleanup(SQueryAutoQWorkerPool *pPool) {
|
||||||
worker = (SQueryAutoQWorker *)pNode->data;
|
worker = (SQueryAutoQWorker *)pNode->data;
|
||||||
if (worker && taosCheckPthreadValid(worker->thread)) {
|
if (worker && taosCheckPthreadValid(worker->thread)) {
|
||||||
(void)taosThreadJoin(worker->thread, NULL);
|
(void)taosThreadJoin(worker->thread, NULL);
|
||||||
(void)taosThreadClear(&worker->thread);
|
taosThreadClear(&worker->thread);
|
||||||
}
|
}
|
||||||
taosMemoryFree(pNode);
|
taosMemoryFree(pNode);
|
||||||
}
|
}
|
||||||
|
@ -882,7 +913,7 @@ void tQueryAutoQWorkerCleanup(SQueryAutoQWorkerPool *pPool) {
|
||||||
worker = (SQueryAutoQWorker *)pNode->data;
|
worker = (SQueryAutoQWorker *)pNode->data;
|
||||||
if (worker && taosCheckPthreadValid(worker->thread)) {
|
if (worker && taosCheckPthreadValid(worker->thread)) {
|
||||||
(void)taosThreadJoin(worker->thread, NULL);
|
(void)taosThreadJoin(worker->thread, NULL);
|
||||||
(void)taosThreadClear(&worker->thread);
|
taosThreadClear(&worker->thread);
|
||||||
}
|
}
|
||||||
taosMemoryFree(pNode);
|
taosMemoryFree(pNode);
|
||||||
}
|
}
|
||||||
|
@ -913,7 +944,13 @@ STaosQueue *tQueryAutoQWorkerAllocQueue(SQueryAutoQWorkerPool *pool, void *ahand
|
||||||
|
|
||||||
(void)taosThreadMutexLock(&pool->poolLock);
|
(void)taosThreadMutexLock(&pool->poolLock);
|
||||||
taosSetQueueFp(queue, fp, NULL);
|
taosSetQueueFp(queue, fp, NULL);
|
||||||
(void)taosAddIntoQset(pool->qset, queue, ahandle);
|
code = taosAddIntoQset(pool->qset, queue, ahandle);
|
||||||
|
if (code) {
|
||||||
|
taosCloseQueue(queue);
|
||||||
|
queue = NULL;
|
||||||
|
(void)taosThreadMutexUnlock(&pool->poolLock);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
SQueryAutoQWorker worker = {0};
|
SQueryAutoQWorker worker = {0};
|
||||||
SQueryAutoQWorker *pWorker = NULL;
|
SQueryAutoQWorker *pWorker = NULL;
|
||||||
|
|
||||||
|
|