Merge branch '3.0' of https://github.com/taosdata/TDengine into docs/wade-3.0

This commit is contained in:
gccgdb1234 2024-09-24 08:34:07 +08:00
commit 3983c2a7b9
59 changed files with 1675 additions and 735 deletions

View File

@ -90,7 +90,7 @@ If `maven` is used to manage the projects, what needs to be done is only adding
<dependency>
<groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId>
<version>3.3.2</version>
<version>3.3.3</version>
</dependency>
```

View File

@ -19,7 +19,7 @@
<dependency>
<groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId>
<version>3.3.2</version>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>org.locationtech.jts</groupId>

View File

@ -18,7 +18,7 @@
<dependency>
<groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId>
<version>3.3.2</version>
<version>3.3.3</version>
</dependency>
<!-- druid -->
<dependency>

View File

@ -17,7 +17,7 @@
<dependency>
<groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId>
<version>3.3.2</version>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>

View File

@ -67,7 +67,7 @@
<dependency>
<groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId>
<version>3.3.2</version>
<version>3.3.3</version>
<!-- <scope>system</scope>-->
<!-- <systemPath>${project.basedir}/src/main/resources/lib/taos-jdbcdriver-2.0.15-dist.jar</systemPath>-->
</dependency>

View File

@ -22,7 +22,7 @@
<dependency>
<groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId>
<version>3.3.2</version>
<version>3.3.3</version>
</dependency>
<!-- ANCHOR_END: dep-->

View File

@ -3,10 +3,7 @@ package com.taos.example;
import com.taosdata.jdbc.TSDBPreparedStatement;
import com.taosdata.jdbc.utils.StringUtils;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
@ -16,15 +13,32 @@ public class ParameterBindingFullDemo {
private static final String host = "127.0.0.1";
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 = {
"create table stable1(ts timestamp, f1 tinyint, f2 smallint, f3 int, f4 bigint) tags(t1 tinyint, t2 smallint, t3 int, t4 bigint)",
"create table stable2(ts timestamp, f1 float, f2 double) tags(t1 float, t2 double)",
"create table stable3(ts timestamp, f1 bool) tags(t1 bool)",
"create table stable4(ts timestamp, f1 binary(" + BINARY_COLUMN_SIZE + ")) tags(t1 binary(" + BINARY_COLUMN_SIZE + "))",
"create table stable5(ts timestamp, f1 nchar(" + BINARY_COLUMN_SIZE + ")) tags(t1 nchar(" + BINARY_COLUMN_SIZE + "))",
"create table stable6(ts timestamp, f1 varbinary(" + BINARY_COLUMN_SIZE + ")) tags(t1 varbinary(" + BINARY_COLUMN_SIZE + "))",
"create table stable7(ts timestamp, f1 geometry(" + BINARY_COLUMN_SIZE + ")) tags(t1 geometry(" + BINARY_COLUMN_SIZE + "))",
"drop database if exists example_all_type_stmt",
"CREATE DATABASE IF NOT EXISTS example_all_type_stmt",
"USE example_all_type_stmt",
"CREATE STABLE IF NOT EXISTS stb_json (" +
"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;
@ -34,55 +48,37 @@ public class ParameterBindingFullDemo {
try (Connection conn = DriverManager.getConnection(jdbcUrl, "root", "taosdata")) {
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) {
// 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;
} catch (Exception ex){
System.out.println("Failed to insert to table meters using stmt, url: " + jdbcUrl + "; ErrMessage: " + ex.getMessage());
} catch (Exception ex) {
System.out.println("Failed to insert data using stmt, ErrMessage: " + ex.getMessage());
throw ex;
}
}
private static void init(Connection conn) throws SQLException {
clean(conn);
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++) {
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 {
String sql = "insert into ? using stable1 tags(?,?,?,?) values(?,?,?,?,?)";
private static void stmtJsonTag(Connection conn) throws SQLException {
String sql = "INSERT INTO ? using stb_json tags(?) VALUES (?,?)";
try (TSDBPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSDBPreparedStatement.class)) {
for (int i = 1; i <= numOfSubTable; i++) {
// set table name
pstmt.setTableName("t1_" + i);
pstmt.setTableName("ntb_json_" + i);
// set tags
pstmt.setTagByte(0, Byte.parseByte(Integer.toString(random.nextInt(Byte.MAX_VALUE))));
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());
pstmt.setTagJson(0, "{\"device\":\"device_" + i + "\"}");
// set columns
ArrayList<Long> tsList = new ArrayList<>();
long current = System.currentTimeMillis();
@ -90,45 +86,42 @@ public class ParameterBindingFullDemo {
tsList.add(current + j);
pstmt.setTimestamp(0, tsList);
ArrayList<Byte> f1List = new ArrayList<>();
ArrayList<Integer> f1List = new ArrayList<>();
for (int j = 0; j < numOfRow; j++)
f1List.add(Byte.parseByte(Integer.toString(random.nextInt(Byte.MAX_VALUE))));
pstmt.setByte(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);
f1List.add(random.nextInt(Integer.MAX_VALUE));
pstmt.setInt(1, f1List);
// add column
pstmt.columnDataAddBatch();
}
// execute column
pstmt.columnDataExecuteBatch();
System.out.println("Successfully inserted rows to example_all_type_stmt.ntb_json");
}
}
private static void bindFloat(Connection conn) throws SQLException {
String sql = "insert into ? using stable2 tags(?,?) values(?,?,?)";
private static void stmtAll(Connection conn) throws SQLException {
String sql = "INSERT INTO ? using stb tags(?,?,?,?,?,?,?) VALUES (?,?,?,?,?,?,?,?)";
TSDBPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSDBPreparedStatement.class);
for (int i = 1; i <= numOfSubTable; i++) {
// set table name
pstmt.setTableName("t2_" + i);
pstmt.setTableName("ntb" + i);
// set tags
pstmt.setTagFloat(0, random.nextFloat());
pstmt.setTagDouble(1, random.nextDouble());
pstmt.setTagInt(0, i);
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
ArrayList<Long> tsList = new ArrayList<>();
long current = System.currentTimeMillis();
@ -136,190 +129,54 @@ public class ParameterBindingFullDemo {
tsList.add(current + j);
pstmt.setTimestamp(0, tsList);
ArrayList<Float> f1List = new ArrayList<>();
ArrayList<Integer> f1List = new ArrayList<>();
for (int j = 0; j < numOfRow; j++)
f1List.add(random.nextFloat());
pstmt.setFloat(1, f1List);
f1List.add(random.nextInt(Integer.MAX_VALUE));
pstmt.setInt(1, f1List);
ArrayList<Double> f2List = new ArrayList<>();
for (int j = 0; j < numOfRow; j++)
f2List.add(random.nextDouble());
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
pstmt.columnDataAddBatch();
}
// execute
pstmt.columnDataExecuteBatch();
System.out.println("Successfully inserted rows to example_all_type_stmt.ntb");
// close if no try-with-catch statement is used
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

View File

@ -11,11 +11,30 @@ public class WSParameterBindingFullDemo {
private static final Random random = new Random(System.currentTimeMillis());
private static final int BINARY_COLUMN_SIZE = 30;
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)",
"create table stable2(ts timestamp, f1 float, f2 double) tags(t1 float, t2 double)",
"create table stable3(ts timestamp, f1 bool) tags(t1 bool)",
"create table stable4(ts timestamp, f1 binary(" + BINARY_COLUMN_SIZE + ")) tags(t1 binary(" + BINARY_COLUMN_SIZE + "))",
"create table stable5(ts timestamp, f1 nchar(" + BINARY_COLUMN_SIZE + ")) tags(t1 nchar(" + BINARY_COLUMN_SIZE + "))"
"drop database if exists example_all_type_stmt",
"CREATE DATABASE IF NOT EXISTS example_all_type_stmt",
"USE example_all_type_stmt",
"CREATE STABLE IF NOT EXISTS stb_json (" +
"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;
@ -27,153 +46,91 @@ public class WSParameterBindingFullDemo {
init(conn);
bindInteger(conn);
stmtJsonTag(conn);
bindFloat(conn);
bindBoolean(conn);
bindBytes(conn);
bindString(conn);
stmtAll(conn);
} catch (SQLException ex) {
// 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;
} catch (Exception ex){
System.out.println("Failed to insert to table meters using stmt, url: " + jdbcUrl + "; ErrMessage: " + ex.getMessage());
} catch (Exception ex) {
System.out.println("Failed to insert data using stmt, ErrMessage: " + ex.getMessage());
throw ex;
}
}
private static void init(Connection conn) throws SQLException {
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++) {
stmt.execute(schemaList[i]);
}
}
}
private static void bindInteger(Connection conn) throws SQLException {
String sql = "insert into ? using stable1 tags(?,?,?,?) values(?,?,?,?,?)";
private static void stmtJsonTag(Connection conn) throws SQLException {
String sql = "INSERT INTO ? using stb_json tags(?) VALUES (?,?)";
try (TSWSPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSWSPreparedStatement.class)) {
for (int i = 1; i <= numOfSubTable; i++) {
// set table name
pstmt.setTableName("t1_" + i);
pstmt.setTableName("ntb_json_" + i);
// set tags
pstmt.setTagByte(1, Byte.parseByte(Integer.toString(random.nextInt(Byte.MAX_VALUE))));
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());
pstmt.setTagJson(1, "{\"device\":\"device_" + i + "\"}");
// set columns
long current = System.currentTimeMillis();
for (int j = 0; j < numOfRow; j++) {
pstmt.setTimestamp(1, new Timestamp(current + j));
pstmt.setByte(2, Byte.parseByte(Integer.toString(random.nextInt(Byte.MAX_VALUE))));
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.setInt(2, j);
pstmt.addBatch();
}
pstmt.executeBatch();
}
System.out.println("Successfully inserted rows to example_all_type_stmt.ntb_json");
}
}
private static void bindFloat(Connection conn) throws SQLException {
String sql = "insert into ? using stable2 tags(?,?) values(?,?,?)";
try(TSWSPreparedStatement pstmt = conn.prepareStatement(sql).unwrap(TSWSPreparedStatement.class)) {
for (int i = 1; i <= numOfSubTable; i++) {
// set table name
pstmt.setTableName("t2_" + i);
// set tags
pstmt.setTagFloat(1, random.nextFloat());
pstmt.setTagDouble(2, random.nextDouble());
// set columns
long current = System.currentTimeMillis();
for (int j = 0; j < numOfRow; j++) {
pstmt.setTimestamp(1, new Timestamp(current + j));
pstmt.setFloat(2, random.nextFloat());
pstmt.setDouble(3, random.nextDouble());
pstmt.addBatch();
}
pstmt.executeBatch();
}
}
}
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(?,?)";
private static void stmtAll(Connection conn) throws SQLException {
String sql = "INSERT INTO ? using stb 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 table name
pstmt.setTableName("ntb");
// set tags
pstmt.setTagInt(1, 1);
pstmt.setTagDouble(2, 1.1);
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});
// 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();
}
}
}
long current = System.currentTimeMillis();
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();
}
pstmt.setTimestamp(1, new Timestamp(current));
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.executeBatch();
System.out.println("Successfully inserted rows to example_all_type_stmt.ntb");
}
}
}

View File

@ -50,36 +50,68 @@ public class TestAll {
}
@Test
public void testRestInsert() throws SQLException {
dropDB("power");
RestInsertExample.main(args);
RestQueryExample.main(args);
public void testWsConnect() throws Exception {
WSConnectExample.main(args);
}
@Test
public void testStmtInsert() throws SQLException {
public void testBase() throws Exception {
JdbcCreatDBDemo.main(args);
JdbcInsertDataDemo.main(args);
JdbcQueryDemo.main(args);
dropDB("power");
StmtInsertExample.main(args);
}
@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);
}
@Test
public void testSubscribeOverWebsocket() {
WebsocketSubscribeDemo.main(args);
}
@Test
public void testSchemaless() throws SQLException {
LineProtocolExample.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);
}
// @Test
// public void testSubscribeJni() throws SQLException, InterruptedException {
// dropDB("power");
// ConsumerLoopFull.main(args);
// }
// @Test
// public void testSubscribeWs() throws SQLException, InterruptedException {
// dropDB("power");
// WsConsumerLoopFull.main(args);
// }
}

View File

@ -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()

View File

@ -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()

View File

@ -24,13 +24,18 @@ async function createConnect() {
async function createDbAndTable() {
let wsSql = null;
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
await wsSql.exec('CREATE DATABASE IF NOT EXISTS power');
console.log("Create database power successfully.");
// create table
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);');
console.log("Create stable power.meters successfully");

View File

@ -8,6 +8,7 @@ edition = "2021"
anyhow = "1"
chrono = "0.4"
serde = { version = "1", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "1", features = ["rt", "macros", "rt-multi-thread"] }
log = "0.4"
pretty_env_logger = "0.5.0"

View File

@ -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(())
}

View File

@ -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(())
}

View File

@ -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(())
}

View File

@ -89,7 +89,7 @@ TDengine 提供了丰富的应用程序开发接口,为了便于用户快速
<dependency>
<groupId>com.taosdata.jdbc</groupId>
<artifactId>taos-jdbcdriver</artifactId>
<version>3.3.2</version>
<version>3.3.3</version>
</dependency>
```

View File

@ -243,6 +243,7 @@ vi source-demo.json
"topic.per.stable": true,
"topic.ignore.db": false,
"out.format": "line",
"data.precision": "ms",
"key.converter": "org.apache.kafka.connect.storage.StringConverter",
"value.converter": "org.apache.kafka.connect.storage.StringConverter"
}
@ -331,14 +332,13 @@ curl -X DELETE http://localhost:8083/connectors/TDengineSourceConnector
1. 打开 KAFKA_HOME/config/producer.properties 配置文件。
2. 参数说明及配置建议如下:
| **参数** | **参数说明** | **设置建议** |
| --------| --------------------------------- | -------------- |
| producer.type | 此参数用于设置消息的发送方式,默认值为 `sync` 表示同步发送,`async` 表示异步发送。采用异步发送能够提升消息发送的吞吐量。 | async |
| request.required.acks | 参数用于配置生产者发送消息后需要等待的确认数量。当设置为1时表示只要领导者副本成功写入消息就会给生产者发送确认而无需等待集群中的其他副本写入成功。这种设置可以在一定程度上保证消息的可靠性同时也能保证一定的吞吐量。因为不需要等待所有副本都写入成功所以可以减少生产者的等待时间提高发送消息的效率。|1|
| max.request.size| 该参数决定了生产者在一次请求中可以发送的最大数据量。其默认值为 1048576也就是 1M。如果设置得太小可能会导致频繁的网络请求降低吞吐量。如果设置得太大可能会导致内存占用过高或者在网络状况不佳时增加请求失败的概率。建议设置为 100M。|104857600|
|batch.size| 此参数用于设定 batch 的大小,默认值为 16384即 16KB。在消息发送过程中发送到 Kafka 缓冲区中的消息会被划分成一个个的 batch。故而减小 batch 大小有助于降低消息延迟,而增大 batch 大小则有利于提升吞吐量,可根据实际的数据量大小进行合理配置。可根据实际情况进行调整,建议设置为 512K。|524288|
| buffer.memory| 此参数用于设置生产者缓冲待发送消息的内存总量。较大的缓冲区可以允许生产者积累更多的消息后批量发送,提高吞吐量,但也会增加延迟和内存使用。可根据机器资源来配置,建议配置为 1G。|1073741824|
| **参数** | **参数说明** | **设置建议** |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
| producer.type | 此参数用于设置消息的发送方式,默认值为 `sync` 表示同步发送,`async` 表示异步发送。采用异步发送能够提升消息发送的吞吐量。 | async |
| request.required.acks | 参数用于配置生产者发送消息后需要等待的确认数量。当设置为1时表示只要领导者副本成功写入消息就会给生产者发送确认而无需等待集群中的其他副本写入成功。这种设置可以在一定程度上保证消息的可靠性同时也能保证一定的吞吐量。因为不需要等待所有副本都写入成功所以可以减少生产者的等待时间提高发送消息的效率。 | 1 |
| max.request.size | 该参数决定了生产者在一次请求中可以发送的最大数据量。其默认值为 1048576也就是 1M。如果设置得太小可能会导致频繁的网络请求降低吞吐量。如果设置得太大可能会导致内存占用过高或者在网络状况不佳时增加请求失败的概率。建议设置为 100M。 | 104857600 |
| batch.size | 此参数用于设定 batch 的大小,默认值为 16384即 16KB。在消息发送过程中发送到 Kafka 缓冲区中的消息会被划分成一个个的 batch。故而减小 batch 大小有助于降低消息延迟,而增大 batch 大小则有利于提升吞吐量,可根据实际的数据量大小进行合理配置。可根据实际情况进行调整,建议设置为 512K。 | 524288 |
| buffer.memory | 此参数用于设置生产者缓冲待发送消息的内存总量。较大的缓冲区可以允许生产者积累更多的消息后批量发送,提高吞吐量,但也会增加延迟和内存使用。可根据机器资源来配置,建议配置为 1G。 | 1073741824 |
## 配置参考
@ -370,7 +370,7 @@ curl -X DELETE http://localhost:8083/connectors/TDengineSourceConnector
7. `data.precision`: 使用 InfluxDB 行协议格式时,时间戳的精度。可选值为:
1. ms 表示毫秒
2. us 表示微秒
3. ns 表示纳秒。默认为纳秒。
3. ns 表示纳秒。
### TDengine Source Connector 特有的配置
@ -381,12 +381,16 @@ curl -X DELETE http://localhost:8083/connectors/TDengineSourceConnector
5. `fetch.max.rows` : 检索数据库时最大检索条数。 默认为 100。
6. `query.interval.ms`: 从 TDengine 一次读取数据的时间跨度,需要根据表中的数据特征合理配置,避免一次查询的数据量过大或过小;在具体的环境中建议通过测试设置一个较优值,默认值为 0即获取到当前最新时间的所有数据。
7. `out.format` : 结果集输出格式。`line` 表示输出格式为 InfluxDB Line 协议格式,`json` 表示输出格式是 json。默认为 line。
8. `topic.per.stable`: 如果设置为 true表示一个超级表对应一个 Kafka topictopic的命名规则 `<topic.prefix><topic.delimiter><connection.database><topic.delimiter><stable.name>`;如果设置为 false则指定的 DB 中的所有数据进入一个 Kafka topictopic 的命名规则为 `<topic.prefix><topic.delimiter><connection.database>`
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 时不生效。
10. `topic.delimiter`: topic 名称分割符,默认为 `-`
11. `read.method`: 从 TDengine 读取数据方式query 或是 subscription。默认为 subscription。
12. `subscription.group.id`: 指定 TDengine 数据订阅的组 id`read.method` 为 subscription 时,此项为必填项。
13. `subscription.from`: 指定 TDengine 数据订阅起始位置latest 或是 earliest。默认为 latest。
8. `data.precision`: 使用 InfluxDB 行协议格式时,时间戳的精度。可选值为:
1. ms 表示毫秒,
2. us 表示微秒
3. ns 表示纳秒。
9. `topic.per.stable`: 如果设置为 true表示一个超级表对应一个 Kafka topictopic的命名规则 `<topic.prefix><topic.delimiter><connection.database><topic.delimiter><stable.name>`;如果设置为 false则指定的 DB 中的所有数据进入一个 Kafka topictopic 的命名规则为 `<topic.prefix><topic.delimiter><connection.database>`
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。
## 其他说明

View File

@ -33,6 +33,7 @@ REST 连接支持所有能运行 Java 的平台。
| taos-jdbcdriver 版本 | 主要变化 | TDengine 版本 |
| :------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------: | :----------------: |
| 3.3.3 | 1. 解决了 Websocket statement 关闭导致的内存泄漏 | - |
| 3.3.2 | 1. 优化 Websocket 连接下的参数绑定性能2. 优化了对 mybatis 的支持 | - |
| 3.3.0 | 1. 优化 Websocket 连接下的数据传输性能2. 支持跳过 SSL 验证,默认关闭 | 3.3.2.0 及更高版本 |
| 3.2.11 | 解决了 Native 连接关闭结果集 bug | - |

View File

@ -63,10 +63,15 @@ TDengine 其他功能模块的报错,请参考 [错误码](../../../reference/
| BINARY | string |
| NCHAR | string |
| JSON | []byte |
| GEOMETRY | []byte |
| VARBINARY | []byte |
**注意**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)
## 常见问题

View File

@ -80,6 +80,8 @@ TDengine 目前支持时间戳、数字、字符、布尔类型,与 Rust 对
| BINARY | Vec\<u8> |
| NCHAR | String |
| JSON | serde_json::Value |
| VARBINARY | Bytes |
| GEOMETRY | Bytes |
**注意**JSON 类型仅在 tag 中支持。

View File

@ -103,7 +103,8 @@ TDengine 目前支持时间戳、数字、字符、布尔类型,与 Python 对
|BINARY|str|
|NCHAR|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 行协议写入 |
| [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 订阅 |
| [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)

View File

@ -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 行协议写入示例。 |
| [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) | 订阅的使用示例。 |
| [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) | 参数绑定支持全部类型示例。 |
## 使用限制

View File

@ -67,9 +67,13 @@ TDengine 其他功能模块的报错,请参考 [错误码](../../../reference/
| VARBINARY | 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 参考

View File

@ -176,6 +176,15 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
} \
} 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) \
do { \
int32_t __c = (CMD); \

View File

@ -73,7 +73,7 @@ static void destroyMonitorClient(void* data) {
}
taosHashCleanup(pMonitor->counters);
int ret = taos_collector_registry_destroy(pMonitor->registry);
if (ret){
if (ret) {
tscError("failed to destroy registry, pMonitor:%p ret:%d", pMonitor, ret);
}
taosMemoryFree(pMonitor);
@ -192,7 +192,7 @@ static void generateClusterReport(taos_collector_registry_t* registry, void* pTr
if (strlen(pCont) != 0 && sendReport(pTransporter, epSet, pCont, MONITOR_TYPE_COUNTER, NULL) == 0) {
int ret = taos_collector_registry_clear_batch(registry);
if (ret){
if (ret) {
tscError("failed to clear registry, ret:%d", ret);
}
}
@ -215,7 +215,8 @@ static void reportSendProcess(void* param, void* tmrId) {
SEpSet ep = getEpSet_s(&pInst->mgmtEp);
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);
taosRUnLockLatch(&monitorLock);
}
@ -265,7 +266,7 @@ void monitorCreateClient(int64_t clusterId) {
}
int r = taos_collector_registry_register_collector(pMonitor->registry, pMonitor->colector);
if (r){
if (r) {
tscError("failed to register collector, ret:%d", r);
goto fail;
}
@ -318,7 +319,7 @@ void monitorCreateClientCounter(int64_t clusterId, const char* name, const char*
if (taos_collector_add_metric(pMonitor->colector, newCounter) != 0) {
tscError("failed to add metric to collector");
int r = taos_counter_destroy(newCounter);
if (r){
if (r) {
tscError("failed to destroy counter, code: %d", r);
}
goto end;
@ -326,7 +327,7 @@ void monitorCreateClientCounter(int64_t clusterId, const char* name, const char*
if (taosHashPut(pMonitor->counters, name, strlen(name), &newCounter, POINTER_BYTES) != 0) {
tscError("failed to put counter to monitor");
int r = taos_counter_destroy(newCounter);
if (r){
if (r) {
tscError("failed to destroy counter, code: %d", r);
}
goto end;
@ -394,7 +395,7 @@ static void monitorWriteSlowLog2File(MonitorSlowLogData* slowLogData, char* tmpP
if (pClient == NULL) {
tscError("failed to allocate memory for slow log client");
int32_t ret = taosCloseFile(&pFile);
if (ret != 0){
if (ret != 0) {
tscError("failed to close file:%p ret:%d", pFile, ret);
}
return;
@ -406,7 +407,7 @@ static void monitorWriteSlowLog2File(MonitorSlowLogData* slowLogData, char* tmpP
if (taosHashPut(monitorSlowLogHash, &slowLogData->clusterId, LONG_BYTES, &pClient, POINTER_BYTES) != 0) {
tscError("failed to put clusterId:%" PRId64 " to hash table", slowLogData->clusterId);
int32_t ret = taosCloseFile(&pFile);
if (ret != 0){
if (ret != 0) {
tscError("failed to close file:%p ret:%d", pFile, ret);
}
taosMemoryFree(pClient);
@ -635,7 +636,7 @@ static void processFileRemoved(SlowLogClient* pClient) {
return;
}
int32_t ret = taosCloseFile(&(pClient->pFile));
if (ret != 0){
if (ret != 0) {
tscError("failed to close file:%p ret:%d", pClient->pFile, ret);
return;
}
@ -728,7 +729,7 @@ static void monitorSendAllSlowLogFromTempDir(int64_t clusterId) {
if (taosLockFile(pFile) < 0) {
tscInfo("failed to lock file:%s since %s, maybe used by other process", filename, terrstr());
int32_t ret = taosCloseFile(&pFile);
if (ret != 0){
if (ret != 0) {
tscError("failed to close file:%p ret:%d", pFile, ret);
}
continue;
@ -749,7 +750,7 @@ static void monitorSendAllSlowLogFromTempDir(int64_t clusterId) {
}
int32_t ret = taosCloseDir(&pDir);
if (ret != 0){
if (ret != 0) {
tscError("failed to close dir, ret:%d", ret);
}
}
@ -831,7 +832,7 @@ static int32_t tscMonitortInit() {
static void tscMonitorStop() {
if (taosCheckPthreadValid(monitorThread)) {
(void)taosThreadJoin(monitorThread, NULL);
(void)taosThreadClear(&monitorThread);
taosThreadClear(&monitorThread);
}
}
@ -897,7 +898,7 @@ void monitorClose() {
taosHashCleanup(monitorSlowLogHash);
taosTmrCleanUp(monitorTimer);
taosCloseQueue(monitorQueue);
if(tsem2_destroy(&monitorSem) != 0) {
if (tsem2_destroy(&monitorSem) != 0) {
tscError("failed to destroy semaphore");
}
taosWUnLockLatch(&monitorLock);
@ -921,7 +922,7 @@ int32_t monitorPutData2MonitorQueue(MonitorSlowLogData data) {
tscDebug("[monitor] write slow log to queue, clusterId:%" PRIx64 " type:%s, data:%s", slowLogData->clusterId,
queueTypeStr[slowLogData->type], slowLogData->data);
if (taosWriteQitem(monitorQueue, slowLogData) == 0) {
if(tsem2_post(&monitorSem) != 0) {
if (tsem2_post(&monitorSem) != 0) {
tscError("failed to post semaphore");
}
} else {

View File

@ -347,14 +347,14 @@ int32_t dmStartAuditThread(SDnodeMgmt *pMgmt) {
void dmStopMonitorThread(SDnodeMgmt *pMgmt) {
if (taosCheckPthreadValid(pMgmt->monitorThread)) {
(void)taosThreadJoin(pMgmt->monitorThread, NULL);
(void)taosThreadClear(&pMgmt->monitorThread);
taosThreadClear(&pMgmt->monitorThread);
}
}
void dmStopAuditThread(SDnodeMgmt *pMgmt) {
if (taosCheckPthreadValid(pMgmt->auditThread)) {
(void)taosThreadJoin(pMgmt->auditThread, NULL);
(void)taosThreadClear(&pMgmt->auditThread);
taosThreadClear(&pMgmt->auditThread);
}
}
@ -385,7 +385,7 @@ void dmStopCrashReportThread(SDnodeMgmt *pMgmt) {
if (taosCheckPthreadValid(pMgmt->crashReportThread)) {
(void)taosThreadJoin(pMgmt->crashReportThread, NULL);
(void)taosThreadClear(&pMgmt->crashReportThread);
taosThreadClear(&pMgmt->crashReportThread);
}
}

View File

@ -14,8 +14,8 @@
*/
#define _DEFAULT_SOURCE
#include "mndCluster.h"
#include "audit.h"
#include "mndCluster.h"
#include "mndGrant.h"
#include "mndPrivilege.h"
#include "mndShow.h"
@ -257,7 +257,11 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
code = terrno;
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);
@ -275,7 +279,12 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
mndTransDrop(pTrans);
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) {
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++);
COL_DATA_SET_VAL_GOTO((const char *)&pCluster->createdTime, false, pCluster, _OVER);
char ver[12] = {0};
STR_WITH_MAXSIZE_TO_VARSTR(ver, tsVersionName, pShow->pMeta->pSchemas[cols].bytes);
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
@ -386,7 +394,12 @@ static int32_t mndProcessUptimeTimer(SRpcMsg *pReq) {
mndTransDrop(pTrans);
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) {
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());

View File

@ -67,22 +67,28 @@ int32_t mndRetrieveCompactDetail(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
char tmpBuf[TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE] = {0};
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++);
(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++);
(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++);
(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++);
(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++);
(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++;
sdbRelease(pSdb, pCompactDetail);
@ -302,7 +308,7 @@ int32_t mndAddCompactDetailToTran(SMnode *pMnode, STrans *pTrans, SCompactObj *p
if (terrno != 0) code = terrno;
TAOS_RETURN(code);
}
(void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY);
code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY);
TAOS_RETURN(code);
}

View File

@ -621,8 +621,8 @@ static void *mnodeGenTypeStr(char *buf, int32_t buflen, uint8_t type, int32_t le
return msg;
}
if (type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_VARBINARY ||
type == TSDB_DATA_TYPE_BINARY || type == TSDB_DATA_TYPE_GEOMETRY) {
if (type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_VARBINARY || type == TSDB_DATA_TYPE_BINARY ||
type == TSDB_DATA_TYPE_GEOMETRY) {
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);
@ -640,6 +640,7 @@ static int32_t mndRetrieveFuncs(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
int32_t numOfRows = 0;
SFuncObj *pFunc = NULL;
int32_t cols = 0;
int32_t code = 0;
char buf[TSDB_TYPE_STR_MAX_LEN];
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);
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) {
char *b2 = taosMemoryCalloc(1, pShow->pMeta->pSchemas[cols].bytes);
STR_WITH_MAXSIZE_TO_VARSTR(b2, pFunc->pComment, pShow->pMeta->pSchemas[cols].bytes);
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);
} else {
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;
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};
STR_WITH_MAXSIZE_TO_VARSTR(b3, mnodeGenTypeStr(buf, TSDB_TYPE_STR_MAX_LEN, pFunc->outputType, pFunc->outputLen),
pShow->pMeta->pSchemas[cols].bytes);
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++);
(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++);
(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++);
(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++);
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};
varDataSetLen(varLang, strlen(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++);
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);
(void)memcpy(varDataVal(b4), pFunc->pCode, 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);
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++;
sdbRelease(pSdb, pFunc);

View File

@ -85,7 +85,9 @@ static void *mndBuildTimerMsg(int32_t *pContLen) {
void *pReq = rpcMallocCont(contLen);
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;
return pReq;
}
@ -97,7 +99,9 @@ static void mndPullupTrans(SMnode *pMnode) {
if (pReq != NULL) {
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRANS_TIMER, .pCont = pReq, .contLen = contLen};
// 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) {
SRpcMsg rpcMsg = {.msgType = TDMT_MND_COMPACT_TIMER, .pCont = pReq, .contLen = contLen};
// 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);
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TTL_TIMER, .pCont = pReq, .contLen = contLen};
// 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) {
@ -127,7 +135,9 @@ static void mndPullupTrimDb(SMnode *pMnode) {
void *pReq = mndBuildTimerMsg(&contLen);
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TRIM_DB_TIMER, .pCont = pReq, .contLen = contLen};
// 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) {
@ -136,7 +146,9 @@ static void mndPullupS3MigrateDb(SMnode *pMnode) {
void *pReq = mndBuildTimerMsg(&contLen);
// TODO check return value
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) {
@ -160,7 +172,9 @@ static void mndCalMqRebalance(SMnode *pMnode) {
void *pReq = mndBuildTimerMsg(&contLen);
if (pReq != NULL) {
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);
SRpcMsg rpcMsg = {.msgType = TDMT_MND_STREAM_BEGIN_CHECKPOINT, .pCont = pMsg, .contLen = size};
// 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) {
SRpcMsg rpcMsg = {.msgType = TDMT_MND_NODECHECK_TIMER, .pCont = pReq, .contLen = contLen};
// 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) {
SRpcMsg rpcMsg = {.msgType = TDMT_MND_STREAM_CONSEN_TIMER, .pCont = pReq, .contLen = contLen};
// 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) {
SRpcMsg rpcMsg = {.msgType = TDMT_MND_TELEM_TIMER, .pCont = pReq, .contLen = contLen};
// 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.ahandle = (void *)0x9527};
// 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.ahandle = (void *)0x9527};
// 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";
(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);
pMnode->deploy = pOption->deploy;
@ -727,10 +759,17 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
void mndPreClose(SMnode *pMnode) {
if (pMnode != NULL) {
int32_t code = 0;
// 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);
(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);
pMsg->info.rsp = rpcMallocCont(contLen);
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.rspLen = contLen;
}
@ -1045,7 +1086,12 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr
desc.vgroup_id = pVgroup->vgId;
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);
desc.tables_num = pVgroup->numOfTables;
@ -1083,11 +1129,21 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr
SMonStbDesc desc = {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);
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);
if (taosArrayPush(pStbInfo->stbs, &desc) == NULL) {

View File

@ -14,12 +14,12 @@
*/
#define _DEFAULT_SOURCE
#include "mndProfile.h"
#include "audit.h"
#include "mndDb.h"
#include "mndDnode.h"
#include "mndMnode.h"
#include "mndPrivilege.h"
#include "mndProfile.h"
#include "mndQnode.h"
#include "mndShow.h"
#include "mndSma.h"
@ -65,7 +65,7 @@ typedef struct {
int64_t ipWhiteListVer;
} SConnPreparedObj;
#define CACHE_OBJ_KEEP_TIME 3 // s
#define CACHE_OBJ_KEEP_TIME 3 // s
static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, int8_t connType, uint32_t ip, uint16_t port,
int32_t pid, const char *app, int64_t startTime);
@ -377,7 +377,8 @@ static SAppObj *mndCreateApp(SMnode *pMnode, uint32_t clientIp, SAppHbReq *pReq)
(void)memcpy(&app.summary, &pReq->summary, sizeof(pReq->summary));
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) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
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;
int32_t numOfRows = 0;
int32_t cols = 0;
int32_t code = 0;
SConnObj *pConn = NULL;
if (pShow->pIter == NULL) {
@ -863,32 +865,60 @@ static int32_t mndRetrieveConns(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBl
cols = 0;
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};
STR_TO_VARSTR(user, pConn->user);
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];
STR_TO_VARSTR(app, pConn->app);
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++);
(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};
(void)sprintf(&endpoint[VARSTR_HEADER_SIZE], "%s:%d", taosIpStr(pConn->ip), pConn->port);
varDataLen(endpoint) = strlen(&endpoint[VARSTR_HEADER_SIZE]);
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++);
(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++);
(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++;
}
@ -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,
uint32_t rowsToPack) {
int32_t cols = 0;
int32_t code = 0;
taosRLockLatch(&pConn->queryLock);
int32_t numOfQueries = taosArrayGetSize(pConn->pQueries);
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);
varDataLen(queryId) = strlen(&queryId[VARSTR_HEADER_SIZE]);
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++);
(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++);
(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];
STR_TO_VARSTR(app, pConn->app);
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++);
(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};
STR_TO_VARSTR(user, pConn->user);
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};
(void)sprintf(&endpoint[VARSTR_HEADER_SIZE], "%s:%d", taosIpStr(pConn->ip), pConn->port);
varDataLen(endpoint) = strlen(&endpoint[VARSTR_HEADER_SIZE]);
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++);
(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++);
(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++);
(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++);
(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++);
(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};
int64_t reserve = 64;
@ -983,12 +1074,22 @@ static int32_t packQueriesIntoBlock(SShowObj *pShow, SConnObj *pConn, SSDataBloc
}
varDataLen(subStatus) = strlen(&subStatus[VARSTR_HEADER_SIZE]);
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};
STR_TO_VARSTR(sql, pQuery->sql);
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++;
}
@ -1040,6 +1141,7 @@ static int32_t mndRetrieveApps(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlo
int32_t numOfRows = 0;
int32_t cols = 0;
SAppObj *pApp = NULL;
int32_t code = 0;
if (pShow->pIter == NULL) {
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
@ -1057,55 +1159,115 @@ static int32_t mndRetrieveApps(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlo
cols = 0;
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};
(void)sprintf(&ip[VARSTR_HEADER_SIZE], "%s", taosIpStr(pApp->ip));
varDataLen(ip) = strlen(&ip[VARSTR_HEADER_SIZE]);
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++);
(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};
(void)sprintf(&name[VARSTR_HEADER_SIZE], "%s", pApp->name);
varDataLen(name) = strlen(&name[VARSTR_HEADER_SIZE]);
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++);
(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++);
(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++);
(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++);
(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++);
(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++);
(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++);
(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++);
(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++);
(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++);
(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++);
(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++;
}

View File

@ -14,13 +14,13 @@
*/
#define _DEFAULT_SOURCE
#include "mndQnode.h"
#include "audit.h"
#include "mndDnode.h"
#include "mndPrivilege.h"
#include "mndQnode.h"
#include "mndShow.h"
#include "mndTrans.h"
#include "mndUser.h"
#include "audit.h"
#define QNODE_VER_NUMBER 1
#define QNODE_RESERVE_SIZE 64
@ -209,9 +209,7 @@ int32_t mndSetCreateQnodeCommitLogs(STrans *pTrans, SQnodeObj *pObj) {
TAOS_RETURN(code);
}
bool mndQnodeInDnode(SQnodeObj *pQnode, int32_t dnodeId) {
return pQnode->pDnode->id == dnodeId;
}
bool mndQnodeInDnode(SQnodeObj *pQnode, int32_t dnodeId) { return pQnode->pDnode->id == dnodeId; }
int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeObj *pObj) {
int32_t code = 0;
@ -224,8 +222,10 @@ int32_t mndSetCreateQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQnodeOb
terrno = TSDB_CODE_OUT_OF_MEMORY;
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};
action.epSet = mndGetDnodeEpset(pDnode);
action.pCont = pReq;
@ -252,7 +252,10 @@ static int32_t mndSetCreateQnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, S
code = terrno;
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};
action.epSet = mndGetDnodeEpset(pDnode);
@ -383,7 +386,10 @@ static int32_t mndSetDropQnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SQn
code = terrno;
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};
action.epSet = mndGetDnodeEpset(pDnode);
@ -536,7 +542,10 @@ static int32_t mndProcessQnodeListReq(SRpcMsg *pReq) {
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.rsp = pRsp;
@ -561,15 +570,16 @@ static int32_t mndRetrieveQnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
cols = 0;
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};
STR_WITH_MAXSIZE_TO_VARSTR(ep, pObj->pDnode->ep, pShow->pMeta->pSchemas[cols].bytes);
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++);
(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++;
sdbRelease(pSdb, pObj);

View File

@ -14,10 +14,10 @@
*/
#define _DEFAULT_SOURCE
#include "mndSnode.h"
#include "mndDnode.h"
#include "mndPrivilege.h"
#include "mndShow.h"
#include "mndSnode.h"
#include "mndTrans.h"
#include "mndUser.h"
@ -223,7 +223,10 @@ static int32_t mndSetCreateSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, S
code = terrno;
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};
action.epSet = mndGetDnodeEpset(pDnode);
@ -251,7 +254,10 @@ static int32_t mndSetCreateSnodeUndoActions(STrans *pTrans, SDnodeObj *pDnode, S
code = terrno;
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};
action.epSet = mndGetDnodeEpset(pDnode);
@ -320,7 +326,7 @@ static int32_t mndProcessCreateSnodeReq(SRpcMsg *pReq) {
// goto _OVER;
// }
if (sdbGetSize(pMnode->pSdb, SDB_SNODE) >= 1){
if (sdbGetSize(pMnode->pSdb, SDB_SNODE) >= 1) {
code = TSDB_CODE_MND_SNODE_ALREADY_EXIST;
goto _OVER;
}
@ -340,7 +346,7 @@ _OVER:
TAOS_RETURN(code);
}
// mndReleaseSnode(pMnode, pObj);
// mndReleaseSnode(pMnode, pObj);
mndReleaseDnode(pMnode, pDnode);
tFreeSMCreateQnodeReq(&createReq);
TAOS_RETURN(code);
@ -383,7 +389,10 @@ static int32_t mndSetDropSnodeRedoActions(STrans *pTrans, SDnodeObj *pDnode, SSn
code = terrno;
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};
action.epSet = mndGetDnodeEpset(pDnode);
@ -482,16 +491,17 @@ static int32_t mndRetrieveSnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB
cols = 0;
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};
STR_WITH_MAXSIZE_TO_VARSTR(ep, pObj->pDnode->ep, pShow->pMeta->pSchemas[cols].bytes);
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++);
(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++;
sdbRelease(pSdb, pObj);

View File

@ -220,14 +220,18 @@ _OVER:
TAOS_RETURN(code);
}
int32_t ipWhiteMgtRemove(char *user) {
bool update = true;
bool update = true;
int32_t code = 0;
(void)taosThreadRwlockWrlock(&ipWhiteMgt.rw);
SIpWhiteList **ppList = taosHashGet(ipWhiteMgt.pIpWhiteTab, user, strlen(user));
if (ppList == NULL || *ppList == NULL) {
update = false;
} else {
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++;
@ -391,7 +395,9 @@ int32_t mndUpdateIpWhiteImpl(SHashObj *pIpWhiteTab, char *user, char *fqdn, int8
if (pList != NULL) {
if (isRangeInWhiteList(pList, &range)) {
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);
} else {
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) {
int32_t code = 0;
int32_t lino = 0;
SUserObj userObj = {0};
taosEncryptPass_c((uint8_t *)pass, strlen(pass), userObj.pass);
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);
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);
@ -876,7 +883,7 @@ static int32_t mndCreateDefaultUser(SMnode *pMnode, char *acct, char *user, char
mndTransDrop(pTrans);
goto _ERROR;
}
(void)sdbSetRawStatus(pRaw, SDB_STATUS_READY);
TAOS_CHECK_GOTO(sdbSetRawStatus(pRaw, SDB_STATUS_READY), &lino, _ERROR);
if (mndTransPrepare(pMnode, pTrans) != 0) {
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);
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) {
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);
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) {
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);
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);
} else {
taosHashClear(pNewUser->readDbs);
@ -2205,7 +2219,10 @@ static int32_t mndProcessAlterUserPrivilegesReq(SAlterUserReq *pAlterReq, SMnode
mndReleaseDb(pMnode, pDb);
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);
} else {
taosHashClear(pNewUser->writeDbs);
@ -2275,7 +2292,10 @@ static int32_t mndProcessAlterUserPrivilegesReq(SAlterUserReq *pAlterReq, SMnode
mndReleaseTopic(pMnode, pTopic);
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);
}
@ -2461,7 +2481,7 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
ALTER_USER_ADD_ALL_TB_PRIV(alterReq.alterType, alterReq.privileges, alterReq.tabName)) {
if (strcmp(alterReq.objname, "1.*") != 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,
alterReq.sqlLen);
} else {
@ -2476,7 +2496,7 @@ static int32_t mndProcessAlterUserReq(SRpcMsg *pReq) {
} else {
if (strcmp(alterReq.objname, "1.*") != 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,
alterReq.sqlLen);
} else {
@ -2511,7 +2531,10 @@ static int32_t mndDropUser(SMnode *pMnode, SRpcMsg *pReq, SUserObj *pUser) {
mndTransDrop(pTrans);
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) {
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};
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));
varDataSetLen(objName, strlen(varDataVal(objName)));
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
@ -3026,7 +3053,11 @@ static int32_t mndRetrievePrivileges(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock
SName name = {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));
varDataSetLen(objName, strlen(varDataVal(objName)));
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
@ -3213,6 +3244,7 @@ _OVER:
int32_t mndUserRemoveDb(SMnode *pMnode, STrans *pTrans, char *db) {
int32_t code = 0;
int32_t lino = 0;
SSdb *pSdb = pMnode->pSdb;
int32_t len = strlen(db) + 1;
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 inWrite = (taosHashGet(newUser.writeDbs, db, len) != NULL);
if (inRead || inWrite) {
(void)taosHashRemove(newUser.readDbs, db, len);
(void)taosHashRemove(newUser.writeDbs, db, len);
code = taosHashRemove(newUser.readDbs, 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);
if (pCommitRaw == NULL || (code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
code = TSDB_CODE_OUT_OF_MEMORY;
break;
}
(void)sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
TAOS_CHECK_GOTO(sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY), &lino, _OVER);
}
mndUserFreeObj(&newUser);
@ -3272,16 +3310,30 @@ int32_t mndUserRemoveStb(SMnode *pMnode, STrans *pTrans, char *stb) {
bool inWrite = (taosHashGet(newUser.writeTbs, stb, len) != NULL);
bool inAlter = (taosHashGet(newUser.alterTbs, stb, len) != NULL);
if (inRead || inWrite || inAlter) {
(void)taosHashRemove(newUser.readTbs, stb, len);
(void)taosHashRemove(newUser.writeTbs, stb, len);
(void)taosHashRemove(newUser.alterTbs, stb, len);
code = taosHashRemove(newUser.readTbs, stb, len);
if (code < 0) {
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);
if (pCommitRaw == NULL || (code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
code = TSDB_CODE_OUT_OF_MEMORY;
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);
@ -3314,16 +3366,30 @@ int32_t mndUserRemoveView(SMnode *pMnode, STrans *pTrans, char *view) {
bool inWrite = (taosHashGet(newUser.writeViews, view, len) != NULL);
bool inAlter = (taosHashGet(newUser.alterViews, view, len) != NULL);
if (inRead || inWrite || inAlter) {
(void)taosHashRemove(newUser.readViews, view, len);
(void)taosHashRemove(newUser.writeViews, view, len);
(void)taosHashRemove(newUser.alterViews, view, len);
code = taosHashRemove(newUser.readViews, view, len);
if (code < 0) {
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);
if (pCommitRaw == NULL || (code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
code = TSDB_CODE_OUT_OF_MEMORY;
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);
@ -3356,13 +3422,21 @@ int32_t mndUserRemoveTopic(SMnode *pMnode, STrans *pTrans, char *topic) {
bool inTopic = (taosHashGet(newUser.topics, topic, len) != NULL);
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);
if (pCommitRaw == NULL || (code = mndTransAppendCommitlog(pTrans, pCommitRaw)) != 0) {
code = TSDB_CODE_OUT_OF_MEMORY;
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);

View File

@ -314,7 +314,7 @@ int32_t metaSnapWriterClose(SMetaSnapWriter** ppWriter, int8_t rollback);
// STsdbSnapReader ========================================
int32_t tsdbSnapReaderOpen(STsdb* pTsdb, int64_t sver, int64_t ever, int8_t type, void* pRanges,
STsdbSnapReader** ppReader);
int32_t tsdbSnapReaderClose(STsdbSnapReader** ppReader);
void tsdbSnapReaderClose(STsdbSnapReader** ppReader);
int32_t tsdbSnapRead(STsdbSnapReader* pReader, uint8_t** ppData);
// STsdbSnapWriter ========================================
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);
// STsdbSnapRAWReader ========================================
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);
// STsdbSnapRAWWriter ========================================
int32_t tsdbSnapRAWWriterOpen(STsdb* pTsdb, int64_t ever, STsdbSnapRAWWriter** ppWriter);
@ -368,7 +368,7 @@ int32_t streamStateLoadTasks(SStreamStateWriter* pWriter);
// SStreamStateReader =====================================
// SRSmaSnapReader ========================================
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);
// SRSmaSnapWriter ========================================
int32_t rsmaSnapWriterOpen(SSma* pSma, int64_t sver, int64_t ever, void** ppRanges, SRSmaSnapWriter** ppWriter);

View File

@ -91,12 +91,7 @@ int metaAbort(SMeta *pMeta) {
return 0;
}
int code = 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;
}
return code;
tdbAbort(pMeta->pEnv, pMeta->txn);
pMeta->txn = NULL;
return 0;
}

View File

@ -93,30 +93,26 @@ int32_t rsmaSnapRead(SRSmaSnapReader* pReader, uint8_t** ppData) {
_exit:
if (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 {
smaInfo("vgId:%d, vnode snapshot rsma read succeed", SMA_VID(pReader->pSma));
}
TAOS_RETURN(code);
}
int32_t rsmaSnapReaderClose(SRSmaSnapReader** ppReader) {
int32_t code = 0;
void rsmaSnapReaderClose(SRSmaSnapReader** ppReader) {
SRSmaSnapReader* pReader = *ppReader;
for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) {
if (pReader->pDataReader[i]) {
if ((code = tsdbSnapReaderClose(&pReader->pDataReader[i])) < 0) {
smaError("vgId:%d, vnode snapshot rsma , failed to close tsdbSnapReader since %s", SMA_VID(pReader->pSma),
tstrerror(code));
}
tsdbSnapReaderClose(&pReader->pDataReader[i]);
}
}
smaInfo("vgId:%d, vnode snapshot rsma reader closed", SMA_VID(pReader->pSma));
taosMemoryFreeClear(*ppReader);
TAOS_RETURN(code);
return;
}
// SRSmaSnapWriter ========================================

View File

@ -42,7 +42,7 @@ int32_t tqSnapReaderOpen(STQ* pTq, int64_t sver, int64_t ever, int8_t type, STqS
pReader->type = type;
// impl
TTB *pTb = NULL;
TTB* pTb = NULL;
if (type == SNAP_DATA_TQ_CHECKINFO) {
pTb = pTq->pCheckStore;
} else if (type == SNAP_DATA_TQ_HANDLE) {
@ -132,7 +132,8 @@ int32_t tqSnapWriterOpen(STQ* pTq, int64_t sver, int64_t ever, STqSnapWriter** p
// alloc
pWriter = (STqSnapWriter*)taosMemoryCalloc(1, sizeof(*pWriter));
if (pWriter == NULL) {
code = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);;
code = TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
;
goto _err;
}
pWriter->pTq = pTq;
@ -160,7 +161,7 @@ int32_t tqSnapWriterClose(STqSnapWriter** ppWriter, int8_t rollback) {
STQ* pTq = pWriter->pTq;
if (rollback) {
(void)tdbAbort(pWriter->pTq->pMetaDB, pWriter->txn);
tdbAbort(pWriter->pTq->pMetaDB, pWriter->txn);
} else {
code = tdbCommit(pWriter->pTq->pMetaDB, pWriter->txn);
if (code) goto _err;
@ -189,7 +190,8 @@ int32_t tqSnapHandleWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nData
code = tDecodeSTqHandle(pDecoder, &handle);
if (code) goto end;
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);
end:
@ -200,15 +202,16 @@ end:
}
int32_t tqSnapCheckInfoWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nData) {
int32_t code = 0;
STQ* pTq = pWriter->pTq;
int32_t code = 0;
STQ* pTq = pWriter->pTq;
STqCheckInfo info = {0};
code = tqMetaDecodeCheckInfo(&info, pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr));
if(code != 0){
if (code != 0) {
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);
if (code) goto _err;
@ -220,22 +223,23 @@ _err:
}
int32_t tqSnapOffsetWrite(STqSnapWriter* pWriter, uint8_t* pData, uint32_t nData) {
int32_t code = 0;
STQ* pTq = pWriter->pTq;
int32_t code = 0;
STQ* pTq = pWriter->pTq;
STqOffset info = {0};
code = tqMetaDecodeOffsetInfo(&info, pData + sizeof(SSnapDataHdr), nData - sizeof(SSnapDataHdr));
if(code != 0){
if (code != 0) {
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);
if (code) goto _err;
return code;
_err:
_err:
tqError("vgId:%d, vnode check info tq write failed since %s", TD_VID(pTq->pVnode), tstrerror(code));
return code;
}

View File

@ -210,7 +210,7 @@ int32_t streamTaskSnapWriterClose(SStreamTaskWriter* pWriter, int8_t rollback, i
streamMetaWLock(pTq->pStreamMeta);
tqDebug("vgId:%d, vnode stream-task snapshot writer closed", TD_VID(pTq->pVnode));
if (rollback) {
(void)tdbAbort(pTq->pStreamMeta->db, pTq->pStreamMeta->txn);
tdbAbort(pTq->pStreamMeta->db, pTq->pStreamMeta->txn);
} else {
code = tdbCommit(pTq->pStreamMeta->db, pTq->pStreamMeta->txn);
if (code) goto _err;

View File

@ -440,9 +440,9 @@ _exit:
return code;
}
int32_t tsdbSnapReaderClose(STsdbSnapReader** reader) {
void tsdbSnapReaderClose(STsdbSnapReader** reader) {
if (reader[0] == NULL) {
return 0;
return;
}
int32_t code = 0;
@ -469,7 +469,7 @@ int32_t tsdbSnapReaderClose(STsdbSnapReader** reader) {
taosMemoryFree(reader[0]);
reader[0] = NULL;
return code;
return;
}
int32_t tsdbSnapRead(STsdbSnapReader* reader, uint8_t** data) {

View File

@ -75,8 +75,8 @@ _exit:
return code;
}
int32_t tsdbSnapRAWReaderClose(STsdbSnapRAWReader** reader) {
if (reader[0] == NULL) return 0;
void tsdbSnapRAWReaderClose(STsdbSnapRAWReader** reader) {
if (reader[0] == NULL) return;
int32_t code = 0;
int32_t lino = 0;
@ -87,14 +87,7 @@ int32_t tsdbSnapRAWReaderClose(STsdbSnapRAWReader** reader) {
tsdbFSDestroyRefSnapshot(&reader[0]->fsetArr);
taosMemoryFree(reader[0]);
reader[0] = NULL;
_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;
return;
}
static int32_t tsdbSnapRAWReadFileSetOpenReader(STsdbSnapRAWReader* reader) {

View File

@ -219,15 +219,15 @@ void vnodeSnapReaderClose(SVSnapReader *pReader) {
vnodeSnapReaderDestroyTsdbRanges(pReader);
if (pReader->pRsmaReader) {
(void)rsmaSnapReaderClose(&pReader->pRsmaReader);
rsmaSnapReaderClose(&pReader->pRsmaReader);
}
if (pReader->pTsdbReader) {
(void)tsdbSnapReaderClose(&pReader->pTsdbReader);
tsdbSnapReaderClose(&pReader->pTsdbReader);
}
if (pReader->pTsdbRAWReader) {
(void)tsdbSnapRAWReaderClose(&pReader->pTsdbRAWReader);
tsdbSnapRAWReaderClose(&pReader->pTsdbRAWReader);
}
if (pReader->pMetaReader) {
@ -333,8 +333,7 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData)
goto _exit;
} else {
pReader->tsdbDone = 1;
code = tsdbSnapReaderClose(&pReader->pTsdbReader);
TSDB_CHECK_CODE(code, lino, _exit);
tsdbSnapReaderClose(&pReader->pTsdbReader);
}
}
@ -351,8 +350,7 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData)
goto _exit;
} else {
pReader->tsdbRAWDone = 1;
code = tsdbSnapRAWReaderClose(&pReader->pTsdbRAWReader);
TSDB_CHECK_CODE(code, lino, _exit);
tsdbSnapRAWReaderClose(&pReader->pTsdbRAWReader);
}
}
@ -463,8 +461,7 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData)
goto _exit;
} else {
pReader->rsmaDone = 1;
code = rsmaSnapReaderClose(&pReader->pRsmaReader);
TSDB_CHECK_CODE(code, lino, _exit);
rsmaSnapReaderClose(&pReader->pRsmaReader);
}
}
@ -590,15 +587,15 @@ extern int32_t tsdbDisableAndCancelAllBgTask(STsdb *pTsdb);
extern void tsdbEnableBgTask(STsdb *pTsdb);
static int32_t vnodeCancelAndDisableAllBgTask(SVnode *pVnode) {
(void)tsdbDisableAndCancelAllBgTask(pVnode->pTsdb);
(void)vnodeSyncCommit(pVnode);
(void)vnodeAChannelDestroy(&pVnode->commitChannel, true);
TAOS_CHECK_RETURN(tsdbDisableAndCancelAllBgTask(pVnode->pTsdb));
TAOS_CHECK_RETURN(vnodeSyncCommit(pVnode));
TAOS_CHECK_RETURN(vnodeAChannelDestroy(&pVnode->commitChannel, true));
return 0;
}
static int32_t vnodeEnableBgTask(SVnode *pVnode) {
tsdbEnableBgTask(pVnode->pTsdb);
(void)vnodeAChannelInit(1, &pVnode->commitChannel);
TAOS_CHECK_RETURN(vnodeAChannelInit(1, &pVnode->commitChannel));
return 0;
}
@ -613,7 +610,9 @@ int32_t vnodeSnapWriterOpen(SVnode *pVnode, SSnapshotParam *pParam, SVSnapWriter
(void)taosThreadMutexLock(&pVnode->mutex);
pVnode->disableWrite = true;
(void)taosThreadMutexUnlock(&pVnode->mutex);
(void)vnodeCancelAndDisableAllBgTask(pVnode);
code = vnodeCancelAndDisableAllBgTask(pVnode);
TSDB_CHECK_CODE(code, lino, _exit);
// alloc
pWriter = (SVSnapWriter *)taosMemoryCalloc(1, sizeof(*pWriter));
@ -661,15 +660,18 @@ int32_t vnodeSnapWriterClose(SVSnapWriter *pWriter, int8_t rollback, SSnapshot *
// prepare
if (pWriter->pTsdbSnapWriter) {
(void)tsdbSnapWriterPrepareClose(pWriter->pTsdbSnapWriter, rollback);
code = tsdbSnapWriterPrepareClose(pWriter->pTsdbSnapWriter, rollback);
if (code) goto _exit;
}
if (pWriter->pTsdbSnapRAWWriter) {
(void)tsdbSnapRAWWriterPrepareClose(pWriter->pTsdbSnapRAWWriter);
code = tsdbSnapRAWWriterPrepareClose(pWriter->pTsdbSnapRAWWriter);
if (code) goto _exit;
}
if (pWriter->pRsmaSnapWriter) {
(void)rsmaSnapWriterPrepareClose(pWriter->pRsmaSnapWriter, rollback);
code = rsmaSnapWriterPrepareClose(pWriter->pRsmaSnapWriter, rollback);
if (code) goto _exit;
}
// commit json
@ -743,7 +745,9 @@ int32_t vnodeSnapWriterClose(SVSnapWriter *pWriter, int8_t rollback, SSnapshot *
if (code) goto _exit;
}
(void)vnodeBegin(pVnode);
code = vnodeBegin(pVnode);
if (code) goto _exit;
(void)taosThreadMutexLock(&pVnode->mutex);
pVnode->disableWrite = false;
(void)taosThreadMutexUnlock(&pVnode->mutex);
@ -755,7 +759,9 @@ _exit:
vInfo("vgId:%d, vnode snapshot writer closed, rollback:%d", TD_VID(pVnode), rollback);
taosMemoryFree(pWriter);
}
(void)vnodeEnableBgTask(pVnode);
if (vnodeEnableBgTask(pVnode) != 0) {
tsdbError("vgId:%d, failed to enable bg task", TD_VID(pVnode));
}
return code;
}

View File

@ -597,10 +597,7 @@ void streamMetaCloseImpl(void* arg) {
streamMetaWUnLock(pMeta);
// already log the error, ignore here
code = tdbAbort(pMeta->db, pMeta->txn);
if (code) {
stError("vgId:%d failed to jump of trans for tdb, code:%s", vgId, tstrerror(code));
}
tdbAbort(pMeta->db, pMeta->txn);
code = tdbTbClose(pMeta->pTaskDb);
if (code) {
stError("vgId:%d failed to close taskDb, code:%s", vgId, tstrerror(code));
@ -895,7 +892,7 @@ int32_t streamMetaUnregisterTask(SStreamMeta* pMeta, int64_t streamId, int32_t t
stError("vgId:%d failed to remove task:0x%" PRIx64 ", code:%s", pMeta->vgId, id.taskId, tstrerror(code));
}
int32_t size = (int32_t) taosHashGetSize(pMeta->pTasksMap);
int32_t size = (int32_t)taosHashGetSize(pMeta->pTasksMap);
int32_t sizeInList = taosArrayGetSize(pMeta->pTaskList);
if (sizeInList != size) {
stError("vgId:%d tasks number not consistent in list:%d and map:%d, ", vgId, sizeInList, size);
@ -1077,7 +1074,7 @@ void streamMetaLoadAllTasks(SStreamMeta* pMeta) {
tFreeStreamTask(pTask);
STaskId id = streamTaskGetTaskId(pTask);
void* px = taosArrayPush(pRecycleList, &id);
void* px = taosArrayPush(pRecycleList, &id);
if (px == NULL) {
stError("s-task:0x%x failed record the task into recycle list due to out of memory", taskId);
}

View File

@ -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 tdbPostCommit(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);
// TTB
@ -79,11 +79,11 @@ 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 *),
void *xArg, int flags);
int32_t tdbTxnCloseImpl(TXN *pTxn);
#define tdbTxnClose(pTxn) \
do { \
(void)tdbTxnCloseImpl(pTxn); \
(pTxn) = NULL; \
void tdbTxnCloseImpl(TXN *pTxn);
#define tdbTxnClose(pTxn) \
do { \
tdbTxnCloseImpl(pTxn); \
(pTxn) = NULL; \
} while (0)
// other

View File

@ -118,7 +118,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, char const *tbname, SPg
zArg.pBt = pBt;
ret = tdbPagerFetchPage(pPager, &pgno, &pPage, tdbBtreeInitPage, &zArg, txn);
if (ret < 0) {
(void)tdbAbort(pEnv, txn);
tdbAbort(pEnv, txn);
tdbOsFree(pBt);
return ret;
}
@ -126,7 +126,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, char const *tbname, SPg
ret = tdbPagerWrite(pPager, pPage);
if (ret < 0) {
tdbError("failed to write page since %s", terrstr());
(void)tdbAbort(pEnv, txn);
tdbAbort(pEnv, txn);
tdbOsFree(pBt);
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);
if (ret < 0) {
(void)tdbAbort(pEnv, txn);
tdbAbort(pEnv, txn);
tdbOsFree(pBt);
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
(void)tdbPageCopy(pRoot, pChild, 0);
ret = tdbPageCopy(pRoot, pChild, 0);
if (ret < 0) {
return ret;
}
// Reinitialize the root page
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) {
SArray *ofps = pParent->pPager->ofps;
if (ofps) {
for (int i = 0; i < TARRAY_SIZE(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) {
@ -853,7 +864,11 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
if (iNew == nNews - 1 && pIntHdr->pgno == 0) {
pIntHdr->pgno = TDB_PAGE_PGNO(pNews[iNew]);
} 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
SCell *pNewCell = tdbOsMalloc(cd.kLen + 9);
@ -863,8 +878,12 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
int szNewCell;
SPgno pgno;
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);
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);
if (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) {
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);
}
@ -2189,7 +2211,11 @@ int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int
}
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) {
*ppKey = (void *)pBtc->coder.pKey;
@ -2238,13 +2264,19 @@ int tdbBtcDelete(SBTC *pBtc) {
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;
if (ofps) {
for (int i = 0; i < TARRAY_SIZE(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) {
@ -2282,7 +2314,10 @@ int tdbBtcDelete(SBTC *pBtc) {
tdbError("tdb/btc-delete: malloc failed.");
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);
if (ret < 0) {

View File

@ -101,10 +101,10 @@ int tdbClose(TDB *pDb) {
for (pPager = pDb->pgrList; pPager; pPager = pDb->pgrList) {
pDb->pgrList = pPager->pNext;
(void)tdbPagerClose(pPager);
tdbPagerClose(pPager);
}
(void)tdbPCacheClose(pDb->pCache);
tdbPCacheClose(pDb->pCache);
tdbOsFree(pDb->pgrHash);
tdbOsFree(pDb);
}
@ -199,7 +199,7 @@ int32_t tdbPrepareAsyncCommit(TDB *pDb, TXN *pTxn) {
return 0;
}
int32_t tdbAbort(TDB *pDb, TXN *pTxn) {
void tdbAbort(TDB *pDb, TXN *pTxn) {
SPager *pPager;
int ret;
@ -208,13 +208,12 @@ int32_t tdbAbort(TDB *pDb, TXN *pTxn) {
if (ret < 0) {
tdbError("failed to abort pager since %s. dbName:%s, txnId:%" PRId64, tstrerror(terrno), pDb->dbName,
pTxn->txnId);
return ret;
}
}
tdbTxnClose(pTxn);
return 0;
return;
}
SPager *tdbEnvGetPager(TDB *pDb, const char *fname) {

View File

@ -42,12 +42,31 @@ static void tdbPCachePinPage(SPCache *pCache, SPage *pPage);
static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage);
static void tdbPCacheAddPageToHash(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 tdbPCacheDestroyLock(SPCache *pCache) { (void)tdbMutexDestroy(&(pCache->mutex)); }
static void tdbPCacheLock(SPCache *pCache) { (void)tdbMutexLock(&(pCache->mutex)); }
static void tdbPCacheUnlock(SPCache *pCache) { (void)tdbMutexUnlock(&(pCache->mutex)); }
static void tdbPCacheInitLock(SPCache *pCache) {
if (tdbMutexInit(&(pCache->mutex), NULL) != 0) {
tdbError("tdb/pcache: mutex init failed.");
}
}
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) {
int32_t code = 0;
@ -74,7 +93,7 @@ int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) {
_exit:
if (code) {
tdbError("%s failed at %s:%d since %s", __func__, __FILE__, __LINE__, tstrerror(code));
(void)tdbPCacheClose(pCache);
tdbPCacheClose(pCache);
*ppCache = NULL;
} else {
*ppCache = pCache;
@ -82,13 +101,13 @@ _exit:
return code;
}
int tdbPCacheClose(SPCache *pCache) {
void tdbPCacheClose(SPCache *pCache) {
if (pCache) {
(void)tdbPCacheCloseImpl(pCache);
tdbPCacheCloseImpl(pCache);
tdbOsFree(pCache->aPage);
tdbOsFree(pCache);
}
return 0;
return;
}
// TODO:
@ -514,7 +533,7 @@ static int tdbPCacheOpenImpl(SPCache *pCache) {
return 0;
}
static int tdbPCacheCloseImpl(SPCache *pCache) {
static void tdbPCacheCloseImpl(SPCache *pCache) {
// free free page
for (SPage *pPage = pCache->pFree; pPage;) {
SPage *pPageT = pPage->pFreeNext;
@ -532,5 +551,5 @@ static int tdbPCacheCloseImpl(SPCache *pCache) {
tdbOsFree(pCache->pgHash);
tdbPCacheDestroyLock(pCache);
return 0;
return ;
}

View File

@ -64,7 +64,10 @@ int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t)
memset(ptr, 0, size);
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->pData = ptr;
if (pageSize < 65536) {

View File

@ -95,7 +95,7 @@ static int hashset_add(hashset_t set, void *item) {
set->nitems = 0;
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);
}
@ -209,12 +209,15 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) {
return 0;
}
int tdbPagerClose(SPager *pPager) {
void tdbPagerClose(SPager *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);
}
return 0;
return;
}
int tdbPagerWrite(SPager *pPager, SPage *pPage) {
@ -224,14 +227,14 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) {
if (pPage->isDirty) return 0;
// ref page one more time so the page will not be release
(void)tdbRefPage(pPage);
tdbTrace("pager/mdirty page %p/%d/%d", pPage, TDB_PAGE_PGNO(pPage), pPage->id);
int32_t nRef = tdbRefPage(pPage);
tdbTrace("pager/mdirty page %p/%d/%d, ref:%d", pPage, TDB_PAGE_PGNO(pPage), pPage->id, nRef);
// Set page as dirty
pPage->isDirty = 1;
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
if (TDB_PAGE_PGNO(pPage) <= pPager->dbOrigSize &&
@ -244,7 +247,7 @@ int tdbPagerWrite(SPager *pPager, SPage *pPage) {
}
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);
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);
@ -577,7 +580,7 @@ int tdbPagerAbort(SPager *pPager, TXN *pTxn) {
pPage->isDirty = 0;
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);
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);
pgid.pgno = pgno;
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);
@ -879,7 +886,9 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
lcode = TDB_TRY_LOCK_PAGE(pPage);
if (lcode == P_LOCK_SUCC) {
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;
}
@ -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);
if (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);
}
@ -939,7 +951,10 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
if (ret < 0) {
tdbError("tdb/pager:%p, pgno:%d, nRead:%" PRId64 "pgSize:%" PRId32 " init page failed.", 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 ret;
}
@ -947,7 +962,10 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage
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) {
nLoops = 0;
for (;;) {

View File

@ -112,7 +112,11 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF
return ret;
}
} else {
(void)tdbPagerRollback(pPager);
ret = tdbPagerRollback(pPager);
if (ret < 0) {
tdbOsFree(pTb);
return ret;
}
}
// 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 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);
}
@ -241,7 +245,11 @@ int32_t tdbTbTraversal(TTB *pTb, void *data,
return ret;
}
(void)tdbTbcMoveToFirst(pCur);
ret = tdbTbcMoveToFirst(pCur);
if (ret < 0) {
tdbTbcClose(pCur);
return ret;
}
void *pKey = NULL;
int kLen = 0;

View File

@ -31,7 +31,7 @@ int tdbTxnOpen(TXN *pTxn, int64_t txnid, void *(*xMalloc)(void *, size_t), void
return 0;
}
int tdbTxnCloseImpl(TXN *pTxn) {
void tdbTxnCloseImpl(TXN *pTxn) {
if (pTxn) {
if (pTxn->jPageSet) {
hashset_destroy(pTxn->jPageSet);
@ -39,11 +39,14 @@ int tdbTxnCloseImpl(TXN *pTxn) {
}
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);
}
return 0;
return;
}

View File

@ -179,7 +179,7 @@ int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int
// tdbPager.c ====================================
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 tdbPagerWrite(SPager *pPager, SPage *pPage);
int tdbPagerBegin(SPager *pPager, TXN *pTxn);
@ -214,7 +214,7 @@ int tdbPagerRollback(SPager *pPager);
// For page ref
int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache);
int tdbPCacheClose(SPCache *pCache);
void tdbPCacheClose(SPCache *pCache);
int tdbPCacheAlter(SPCache *pCache, int32_t nPage);
SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, TXN *pTxn);
void tdbPCacheRelease(SPCache *pCache, SPage *pPage, TXN *pTxn);

View File

@ -112,7 +112,7 @@ void tEndEncode(SEncoder* pCoder) {
pCoder->size = pNode->size;
pCoder->pos = pNode->pos;
(void)tEncodeI32(pCoder, len);
int32_t ret = tEncodeI32(pCoder, len);
pCoder->pos += len;
}

View File

@ -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) {
terrno = 0;
(void)taosHashGetImpl(pHashObj, key, keyLen, &destBuf, 0, false);
void *data = taosHashGetImpl(pHashObj, key, keyLen, &destBuf, 0, false);
return terrno;
}
int32_t taosHashGetDup_m(SHashObj *pHashObj, const void *key, size_t keyLen, void **destBuf, int32_t *size) {
terrno = 0;
(void)taosHashGetImpl(pHashObj, key, keyLen, destBuf, size, false);
void *data = taosHashGetImpl(pHashObj, key, keyLen, destBuf, size, false);
return terrno;
}

View File

@ -257,10 +257,11 @@ static PriorityQueueNode* pqHeapify(PriorityQueue* pq, size_t from, size_t last)
static void pqBuildHeap(PriorityQueue* pq) {
if (pqContainerSize(pq) > 1) {
PriorityQueueNode* node;
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) {
PriorityQueueNode* node;
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
(void)pqHeapify(pq, i, pqContainerSize(pq));
node = pqHeapify(pq, i, pqContainerSize(pq));
} else {
// 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) {
if (i == pqContainerSize(pq) - 1) {
(void)taosArrayPop(pq->container);
void* tmp = taosArrayPop(pq->container);
return;
}
taosArraySet(pq->container, i, taosArrayGet(pq->container, pqContainerSize(pq) - 1));
(void)taosArrayPop(pq->container);
void* tmp = taosArrayPop(pq->container);
pqUpdate(pq, i);
}

View File

@ -305,7 +305,7 @@ static void taosLRUCacheShardEvictLRU(SLRUCacheShard *shard, size_t charge, SArr
SLRUEntry *old = shard->lru.next;
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);
shard->usage -= old->totalCharge;
@ -529,7 +529,7 @@ static void taosLRUCacheShardEraseUnrefEntries(SLRUCacheShard *shard) {
while (shard->lru.next != &shard->lru) {
SLRUEntry *old = shard->lru.next;
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);
shard->usage -= old->totalCharge;
@ -574,7 +574,7 @@ static bool taosLRUCacheShardRelease(SLRUCacheShard *shard, LRUHandle *handle, b
lastReference = taosLRUEntryUnref(e);
if (lastReference && TAOS_LRU_ENTRY_IN_CACHE(e)) {
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);
} else {
taosLRUCacheShardLRUInsert(shard, e);

View File

@ -32,9 +32,9 @@ static SSkipListNode *tSkipListNewNode(uint8_t level);
static SSkipListNode *tSkipListPutImpl(SSkipList *pSkipList, void *pData, SSkipListNode **direction, bool isForward,
bool hasDup);
static FORCE_INLINE int32_t tSkipListWLock(SSkipList *pSkipList);
static FORCE_INLINE int32_t tSkipListRLock(SSkipList *pSkipList);
static FORCE_INLINE int32_t tSkipListUnlock(SSkipList *pSkipList);
static FORCE_INLINE void tSkipListWLock(SSkipList *pSkipList);
static FORCE_INLINE void tSkipListRLock(SSkipList *pSkipList);
static FORCE_INLINE void tSkipListUnlock(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,
@ -103,7 +103,7 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint16_t keyLen, _
void tSkipListDestroy(SSkipList *pSkipList) {
if (pSkipList == NULL) return;
(void)tSkipListWLock(pSkipList);
tSkipListWLock(pSkipList);
SSkipListNode *pNode = SL_NODE_GET_FORWARD_POINTER(pSkipList->pHead, 0);
@ -113,7 +113,7 @@ void tSkipListDestroy(SSkipList *pSkipList) {
tSkipListFreeNode(pTemp);
}
(void)tSkipListUnlock(pSkipList);
tSkipListUnlock(pSkipList);
if (pSkipList->lock != NULL) {
(void)taosThreadRwlockDestroy(pSkipList->lock);
taosMemoryFreeClear(pSkipList->lock);
@ -130,12 +130,12 @@ SSkipListNode *tSkipListPut(SSkipList *pSkipList, void *pData) {
SSkipListNode *backward[MAX_SKIP_LIST_LEVEL] = {0};
SSkipListNode *pNode = NULL;
(void)tSkipListWLock(pSkipList);
tSkipListWLock(pSkipList);
bool hasDup = tSkipListGetPosToPut(pSkipList, backward, pData);
pNode = tSkipListPutImpl(pSkipList, pData, backward, false, hasDup);
(void)tSkipListUnlock(pSkipList);
tSkipListUnlock(pSkipList);
return pNode;
}
@ -293,11 +293,11 @@ SSkipListIterator *tSkipListCreateIterFromVal(SSkipList *pSkipList, const char *
return iter;
}
(void)tSkipListRLock(pSkipList);
tSkipListRLock(pSkipList);
iter->cur = getPriorNode(pSkipList, val, order, &(iter->next));
(void)tSkipListUnlock(pSkipList);
tSkipListUnlock(pSkipList);
return iter;
}
@ -307,13 +307,13 @@ bool tSkipListIterNext(SSkipListIterator *iter) {
SSkipList *pSkipList = iter->pSkipList;
(void)tSkipListRLock(pSkipList);
tSkipListRLock(pSkipList);
if (iter->order == TSDB_ORDER_ASC) {
// no data in the skip list
if (iter->cur == pSkipList->pTail || iter->next == NULL) {
iter->cur = pSkipList->pTail;
(void)tSkipListUnlock(pSkipList);
tSkipListUnlock(pSkipList);
return false;
}
@ -329,7 +329,7 @@ bool tSkipListIterNext(SSkipListIterator *iter) {
} else {
if (iter->cur == pSkipList->pHead) {
iter->cur = pSkipList->pHead;
(void)tSkipListUnlock(pSkipList);
tSkipListUnlock(pSkipList);
return false;
}
@ -344,7 +344,7 @@ bool tSkipListIterNext(SSkipListIterator *iter) {
iter->step++;
}
(void)tSkipListUnlock(pSkipList);
tSkipListUnlock(pSkipList);
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;
}
static FORCE_INLINE int32_t tSkipListWLock(SSkipList *pSkipList) {
static FORCE_INLINE void tSkipListWLock(SSkipList *pSkipList) {
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) {
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) {
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) {

View File

@ -59,7 +59,7 @@ void tQWorkerCleanup(SQWorkerPool *pool) {
if (taosCheckPthreadValid(worker->thread)) {
uInfo("worker:%s:%d is stopping", pool->name, worker->id);
(void)taosThreadJoin(worker->thread, NULL);
(void)taosThreadClear(&worker->thread);
taosThreadClear(&worker->thread);
uInfo("worker:%s:%d is stopped", pool->name, worker->id);
}
}
@ -77,7 +77,11 @@ static void *tQWorkerThreadFp(SQueueWorker *worker) {
void *msg = NULL;
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);
worker->pid = taosGetSelfPthreadId();
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);
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
if (pool->num < pool->max) {
@ -191,7 +201,7 @@ void tAutoQWorkerCleanup(SAutoQWorkerPool *pool) {
if (taosCheckPthreadValid(worker->thread)) {
uInfo("worker:%s:%d is stopping", pool->name, worker->id);
(void)taosThreadJoin(worker->thread, NULL);
(void)taosThreadClear(&worker->thread);
taosThreadClear(&worker->thread);
uInfo("worker:%s:%d is stopped", pool->name, worker->id);
}
taosMemoryFree(worker);
@ -210,7 +220,11 @@ static void *tAutoQWorkerThreadFp(SQueueWorker *worker) {
void *msg = NULL;
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);
worker->pid = taosGetSelfPthreadId();
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);
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 curWorkerNum = taosArrayGetSize(pool->workers);
@ -281,7 +302,7 @@ STaosQueue *tAutoQWorkerAllocQueue(SAutoQWorkerPool *pool, void *ahandle, FItem
if (taosThreadCreate(&worker->thread, &thAttr, (ThreadFp)tAutoQWorkerThreadFp, worker) != 0) {
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);
taosCloseQueue(queue);
terrno = TSDB_CODE_OUT_OF_MEMORY;
@ -342,7 +363,7 @@ void tWWorkerCleanup(SWWorkerPool *pool) {
if (taosCheckPthreadValid(worker->thread)) {
uInfo("worker:%s:%d is stopping", pool->name, worker->id);
(void)taosThreadJoin(worker->thread, NULL);
(void)taosThreadClear(&worker->thread);
taosThreadClear(&worker->thread);
taosFreeQall(worker->qall);
taosCloseQset(worker->qset);
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 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);
worker->pid = taosGetSelfPthreadId();
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);
if (code) goto _OVER;
(void)taosAddIntoQset(worker->qset, queue, ahandle);
code = taosAddIntoQset(worker->qset, queue, ahandle);
if (code) goto _OVER;
code = taosAllocateQall(&worker->qall);
if (code) goto _OVER;
@ -423,7 +449,8 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) {
pool->num++;
if (pool->num > pool->max) pool->num = pool->max;
} else {
(void)taosAddIntoQset(worker->qset, queue, ahandle);
code = taosAddIntoQset(worker->qset, queue, ahandle);
if (code) goto _OVER;
pool->nextId = (pool->nextId + 1) % pool->max;
}
@ -551,7 +578,7 @@ void tMultiWorkerCleanup(SMultiWorker *pWorker) {
static int32_t tQueryAutoQWorkerAddWorker(SQueryAutoQWorkerPool *pool);
static int32_t tQueryAutoQWorkerBeforeBlocking(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);
#define GET_ACTIVE_N(int64_val) (int32_t)((int64_val) >> 32)
@ -629,7 +656,11 @@ static void *tQueryAutoQWorkerThreadFp(SQueryAutoQWorker *worker) {
void *msg = NULL;
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);
worker->pid = taosGetSelfPthreadId();
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) {
qinfo.workerId = worker->id;
@ -717,13 +748,13 @@ static bool tQueryAutoQWorkerTryDecActive(void *p, int32_t minActive) {
return false;
}
static int32_t tQueryAutoQWorkerWaitingCheck(SQueryAutoQWorkerPool *pPool) {
static void tQueryAutoQWorkerWaitingCheck(SQueryAutoQWorkerPool *pPool) {
while (1) {
int64_t val64 = pPool->activeRunningN;
int32_t running = GET_RUNNING_N(val64), active = GET_ACTIVE_N(val64);
while (running < pPool->num) {
if (atomicCompareExchangeActiveAndRunning(&pPool->activeRunningN, &active, active, &running, running + 1)) {
return TSDB_CODE_SUCCESS;
return;
}
}
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);
// recovered from waiting
(void)taosThreadMutexUnlock(&pPool->waitingBeforeProcessMsgLock);
return TSDB_CODE_SUCCESS;
return;
}
bool tQueryAutoQWorkerTryRecycleWorker(SQueryAutoQWorkerPool *pPool, SQueryAutoQWorker *pWorker) {
@ -744,7 +775,7 @@ bool tQueryAutoQWorkerTryRecycleWorker(SQueryAutoQWorkerPool *pPool, SQueryAutoQ
tQueryAutoQWorkerTryDecActive(pPool, pPool->num)) {
(void)taosThreadMutexLock(&pPool->poolLock);
SListNode *pNode = listNode(pWorker);
(void)tdListPopNode(pPool->workers, pNode);
SListNode *tNode = tdListPopNode(pPool->workers, pNode);
// reclaim some workers
if (pWorker->id >= pPool->maxInUse) {
while (listNEles(pPool->exitedWorkers) > pPool->maxInUse - pPool->num) {
@ -752,7 +783,7 @@ bool tQueryAutoQWorkerTryRecycleWorker(SQueryAutoQWorkerPool *pPool, SQueryAutoQ
SQueryAutoQWorker *pWorker = (SQueryAutoQWorker *)head->data;
if (pWorker && taosCheckPthreadValid(pWorker->thread)) {
(void)taosThreadJoin(pWorker->thread, NULL);
(void)taosThreadClear(&pWorker->thread);
taosThreadClear(&pWorker->thread);
}
taosMemoryFree(head);
}
@ -777,7 +808,7 @@ bool tQueryAutoQWorkerTryRecycleWorker(SQueryAutoQWorkerPool *pPool, SQueryAutoQ
(void)taosThreadMutexUnlock(&pPool->poolLock);
return false;
}
(void)tdListPopNode(pPool->backupWorkers, pNode);
SListNode *tNode1 = tdListPopNode(pPool->backupWorkers, pNode);
tdListAppendNode(pPool->workers, pNode);
(void)taosThreadMutexUnlock(&pPool->poolLock);
@ -862,7 +893,7 @@ void tQueryAutoQWorkerCleanup(SQueryAutoQWorkerPool *pPool) {
(void)taosThreadMutexUnlock(&pPool->poolLock);
if (worker && taosCheckPthreadValid(worker->thread)) {
(void)taosThreadJoin(worker->thread, NULL);
(void)taosThreadClear(&worker->thread);
taosThreadClear(&worker->thread);
}
taosMemoryFree(pNode);
}
@ -872,7 +903,7 @@ void tQueryAutoQWorkerCleanup(SQueryAutoQWorkerPool *pPool) {
worker = (SQueryAutoQWorker *)pNode->data;
if (worker && taosCheckPthreadValid(worker->thread)) {
(void)taosThreadJoin(worker->thread, NULL);
(void)taosThreadClear(&worker->thread);
taosThreadClear(&worker->thread);
}
taosMemoryFree(pNode);
}
@ -882,7 +913,7 @@ void tQueryAutoQWorkerCleanup(SQueryAutoQWorkerPool *pPool) {
worker = (SQueryAutoQWorker *)pNode->data;
if (worker && taosCheckPthreadValid(worker->thread)) {
(void)taosThreadJoin(worker->thread, NULL);
(void)taosThreadClear(&worker->thread);
taosThreadClear(&worker->thread);
}
taosMemoryFree(pNode);
}
@ -913,7 +944,13 @@ STaosQueue *tQueryAutoQWorkerAllocQueue(SQueryAutoQWorkerPool *pool, void *ahand
(void)taosThreadMutexLock(&pool->poolLock);
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 *pWorker = NULL;