diff --git a/Jenkinsfile2 b/Jenkinsfile2 index b074a0ee05..5321dd8f10 100644 --- a/Jenkinsfile2 +++ b/Jenkinsfile2 @@ -306,9 +306,9 @@ def pre_test_build_win() { cd %WIN_CONNECTOR_ROOT% python.exe -m pip install --upgrade pip python -m pip uninstall taospy -y - python -m pip install taospy==2.7.13 + python -m pip install taospy==2.7.16 python -m pip uninstall taos-ws-py -y - python -m pip install taos-ws-py==0.3.1 + python -m pip install taos-ws-py==0.3.3 xcopy /e/y/i/f %WIN_INTERNAL_ROOT%\\debug\\build\\lib\\taos.dll C:\\Windows\\System32 ''' return 1 diff --git a/docs/en/08-develop/01-connect/index.md b/docs/en/08-develop/01-connect/index.md index ab35f6ad63..f4dbccba24 100644 --- a/docs/en/08-develop/01-connect/index.md +++ b/docs/en/08-develop/01-connect/index.md @@ -90,7 +90,7 @@ If `maven` is used to manage the projects, what needs to be done is only adding com.taosdata.jdbc taos-jdbcdriver - 3.3.2 + 3.3.3 ``` diff --git a/docs/examples/JDBC/JDBCDemo/pom.xml b/docs/examples/JDBC/JDBCDemo/pom.xml index a9b981a026..315b147cce 100644 --- a/docs/examples/JDBC/JDBCDemo/pom.xml +++ b/docs/examples/JDBC/JDBCDemo/pom.xml @@ -19,7 +19,7 @@ com.taosdata.jdbc taos-jdbcdriver - 3.3.2 + 3.3.3 org.locationtech.jts diff --git a/docs/examples/JDBC/connectionPools/pom.xml b/docs/examples/JDBC/connectionPools/pom.xml index a3705e6834..1791bfe8bc 100644 --- a/docs/examples/JDBC/connectionPools/pom.xml +++ b/docs/examples/JDBC/connectionPools/pom.xml @@ -18,7 +18,7 @@ com.taosdata.jdbc taos-jdbcdriver - 3.3.2 + 3.3.3 diff --git a/docs/examples/JDBC/consumer-demo/pom.xml b/docs/examples/JDBC/consumer-demo/pom.xml index 0db41bc33f..dcabfc1249 100644 --- a/docs/examples/JDBC/consumer-demo/pom.xml +++ b/docs/examples/JDBC/consumer-demo/pom.xml @@ -17,7 +17,7 @@ com.taosdata.jdbc taos-jdbcdriver - 3.3.2 + 3.3.3 com.google.guava diff --git a/docs/examples/JDBC/taosdemo/pom.xml b/docs/examples/JDBC/taosdemo/pom.xml index 8e61cbecdf..ffe159ea49 100644 --- a/docs/examples/JDBC/taosdemo/pom.xml +++ b/docs/examples/JDBC/taosdemo/pom.xml @@ -67,7 +67,7 @@ com.taosdata.jdbc taos-jdbcdriver - 3.3.2 + 3.3.3 diff --git a/docs/examples/java/pom.xml b/docs/examples/java/pom.xml index c44be4704d..f23b73177e 100644 --- a/docs/examples/java/pom.xml +++ b/docs/examples/java/pom.xml @@ -22,7 +22,7 @@ com.taosdata.jdbc taos-jdbcdriver - 3.3.2 + 3.3.3 diff --git a/docs/examples/java/src/main/java/com/taos/example/ParameterBindingFullDemo.java b/docs/examples/java/src/main/java/com/taos/example/ParameterBindingFullDemo.java index 5eb0cf0a61..dfb2915037 100644 --- a/docs/examples/java/src/main/java/com/taos/example/ParameterBindingFullDemo.java +++ b/docs/examples/java/src/main/java/com/taos/example/ParameterBindingFullDemo.java @@ -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 tsList = new ArrayList<>(); long current = System.currentTimeMillis(); @@ -90,45 +86,42 @@ public class ParameterBindingFullDemo { tsList.add(current + j); pstmt.setTimestamp(0, tsList); - ArrayList f1List = new ArrayList<>(); + ArrayList 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 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 f3List = new ArrayList<>(); - for (int j = 0; j < numOfRow; j++) - f3List.add(random.nextInt(Integer.MAX_VALUE)); - pstmt.setInt(3, f3List); - - ArrayList 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 tsList = new ArrayList<>(); long current = System.currentTimeMillis(); @@ -136,190 +129,54 @@ public class ParameterBindingFullDemo { tsList.add(current + j); pstmt.setTimestamp(0, tsList); - ArrayList f1List = new ArrayList<>(); + ArrayList 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 f2List = new ArrayList<>(); for (int j = 0; j < numOfRow; j++) f2List.add(random.nextDouble()); pstmt.setDouble(2, f2List); + ArrayList f3List = new ArrayList<>(); + for (int j = 0; j < numOfRow; j++) + f3List.add(true); + pstmt.setBoolean(3, f3List); + + ArrayList f4List = new ArrayList<>(); + for (int j = 0; j < numOfRow; j++) + f4List.add("binary_value"); + pstmt.setString(4, f4List, BINARY_COLUMN_SIZE); + + ArrayList f5List = new ArrayList<>(); + for (int j = 0; j < numOfRow; j++) + f5List.add("nchar_value"); + pstmt.setNString(5, f5List, BINARY_COLUMN_SIZE); + + ArrayList 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 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 tsList = new ArrayList<>(); - long current = System.currentTimeMillis(); - for (int j = 0; j < numOfRow; j++) - tsList.add(current + j); - pstmt.setTimestamp(0, tsList); - - ArrayList 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 tsList = new ArrayList<>(); - long current = System.currentTimeMillis(); - for (int j = 0; j < numOfRow; j++) - tsList.add(current + j); - pstmt.setTimestamp(0, tsList); - - ArrayList 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 tsList = new ArrayList<>(); - long current = System.currentTimeMillis(); - for (int j = 0; j < numOfRow; j++) - tsList.add(current + j); - pstmt.setTimestamp(0, tsList); - - ArrayList 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 tsList = new ArrayList<>(); - long current = System.currentTimeMillis(); - for (int j = 0; j < numOfRow; j++) - tsList.add(current + j); - pstmt.setTimestamp(0, tsList); - - ArrayList 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 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 tsList = new ArrayList<>(); - long current = System.currentTimeMillis(); - for (int j = 0; j < numOfRow; j++) - tsList.add(current + j); - pstmt.setTimestamp(0, tsList); - - ArrayList 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 diff --git a/docs/examples/java/src/main/java/com/taos/example/WSParameterBindingFullDemo.java b/docs/examples/java/src/main/java/com/taos/example/WSParameterBindingFullDemo.java index ec94f2ded6..f23fb187f4 100644 --- a/docs/examples/java/src/main/java/com/taos/example/WSParameterBindingFullDemo.java +++ b/docs/examples/java/src/main/java/com/taos/example/WSParameterBindingFullDemo.java @@ -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"); } } } diff --git a/docs/examples/java/src/test/java/com/taos/test/TestAll.java b/docs/examples/java/src/test/java/com/taos/test/TestAll.java index 6a45c5fd5b..e014a3b315 100644 --- a/docs/examples/java/src/test/java/com/taos/test/TestAll.java +++ b/docs/examples/java/src/test/java/com/taos/test/TestAll.java @@ -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); +// } } diff --git a/docs/examples/node/websocketexample/all_type_query.js b/docs/examples/node/websocketexample/all_type_query.js new file mode 100644 index 0000000000..266d110d24 --- /dev/null +++ b/docs/examples/node/websocketexample/all_type_query.js @@ -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() diff --git a/docs/examples/node/websocketexample/all_type_stmt.js b/docs/examples/node/websocketexample/all_type_stmt.js new file mode 100644 index 0000000000..8a0dcf21e1 --- /dev/null +++ b/docs/examples/node/websocketexample/all_type_stmt.js @@ -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() + diff --git a/docs/examples/node/websocketexample/sql_example.js b/docs/examples/node/websocketexample/sql_example.js index 5dc8ba6021..8eb8af989d 100644 --- a/docs/examples/node/websocketexample/sql_example.js +++ b/docs/examples/node/websocketexample/sql_example.js @@ -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"); diff --git a/docs/examples/rust/nativeexample/Cargo.toml b/docs/examples/rust/nativeexample/Cargo.toml index 13e68d6d9d..041ca4f617 100644 --- a/docs/examples/rust/nativeexample/Cargo.toml +++ b/docs/examples/rust/nativeexample/Cargo.toml @@ -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" diff --git a/docs/examples/rust/nativeexample/examples/stmt_all.rs b/docs/examples/rust/nativeexample/examples/stmt_all.rs new file mode 100644 index 0000000000..6560d8a0ab --- /dev/null +++ b/docs/examples/rust/nativeexample/examples/stmt_all.rs @@ -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(()) +} diff --git a/docs/examples/rust/nativeexample/examples/stmt_json_tag.rs b/docs/examples/rust/nativeexample/examples/stmt_json_tag.rs new file mode 100644 index 0000000000..7c1b26a0f5 --- /dev/null +++ b/docs/examples/rust/nativeexample/examples/stmt_json_tag.rs @@ -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(()) +} diff --git a/docs/examples/rust/restexample/examples/stmt_all.rs b/docs/examples/rust/restexample/examples/stmt_all.rs new file mode 100644 index 0000000000..07ab658bad --- /dev/null +++ b/docs/examples/rust/restexample/examples/stmt_all.rs @@ -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(()) +} diff --git a/docs/zh/01-index.md b/docs/zh/01-index.md index 6ba8f021a7..df6c327866 100644 --- a/docs/zh/01-index.md +++ b/docs/zh/01-index.md @@ -8,7 +8,7 @@ TDengine 是一款[开源](https://www.taosdata.com/tdengine/open_source_time-se TDengine 充分利用了时序数据的特点,提出了“一个数据采集点一张表”与“超级表”的概念,设计了创新的存储引擎,让数据的写入、查询和存储效率都得到极大的提升。为正确理解并使用 TDengine,无论如何,请您仔细阅读[快速入门](./basic)一章。 -如果你是开发工程师,请一定仔细阅读[开发指南](./develop)一章,该部分对数据库连接、建模、插入数据、查询、流式计算、缓存、数据订阅、用户自定义函数等功能都做了详细介绍,并配有各种编程语言的示例代码。大部分情况下,你只要复制粘贴示例代码,针对自己的应用稍作改动,就能跑起来。 +如果你是开发工程师,请一定仔细阅读[开发指南](./develop)一章,该部分对数据库连接、建模、插入数据、查询、流式计算、缓存、数据订阅、用户自定义函数等功能都做了详细介绍,并配有各种编程语言的示例代码。大部分情况下,你只要复制粘贴示例代码,针对自己的应用稍作改动,就能跑起来。对 REST API、各种编程语言的连接器(Connector)想做更多详细了解的话,请看[连接器](./reference/connector)一章。 我们已经生活在大数据时代,纵向扩展已经无法满足日益增长的业务需求,任何系统都必须具有水平扩展的能力,集群成为大数据以及 Database 系统的不可缺失功能。TDengine 团队不仅实现了集群功能,而且将这一重要核心功能开源。怎么部署、管理和维护 TDengine 集群,请仔细参考[运维管理](./operation)一章。 @@ -16,8 +16,6 @@ TDengine 采用 SQL 作为查询语言,大大降低学习成本、降低迁移 如果你是系统管理员,关心安装、升级、容错灾备、关心数据导入、导出、配置参数,如何监测 TDengine 是否健康运行,如何提升系统运行的性能,请仔细参考[运维指南](./operation)一章。 -如果你对 TDengine 的产品组件、REST API、各种编程语言的连接器(Connector)想做更多详细了解,请看[参考指南](./reference)一章。 - 最后,作为一个开源软件,欢迎大家的参与。如果发现文档有任何错误、描述不清晰的地方,请在每个页面的最下方,点击“编辑本文档”直接进行修改。 Together, we make a difference! diff --git a/docs/zh/03-intro.md b/docs/zh/03-intro.md index 0167f9323b..4207ab4eb6 100644 --- a/docs/zh/03-intro.md +++ b/docs/zh/03-intro.md @@ -14,9 +14,9 @@ TDengine 是一个高性能、分布式的时序数据库。通过集成的缓 TDengine OSS 是一个开源的高性能时序数据库,与其他时序数据库相比,它的核心优势在于其集群开源、高性能和云原生架构。而且除了基础的写入、查询和存储功能外,TDengine OSS 还集成了缓存、流式计算和数据订阅等高级功能,这些功能显著简化了系统设计,降低了企业的研发和运营成本。 -在 TDengine OSS 的基础上,企业版 TDengine Enterprise 提供了增强的辅助功能,包括数据的备份恢复、异地容灾、多级存储、视图、权限控制、安全加密、IP 白名单、支持 MQTT、OPC-UA、OPC-DA、PI、Wonderware、Kafka 等各种数据源。这些功能为企业提供了更为全面、安全、可靠和高效的时序数据管理解决方案。 +在 TDengine OSS 的基础上,企业版 TDengine Enterprise 提供了增强的辅助功能,包括数据的备份恢复、异地容灾、多级存储、视图、权限控制、安全加密、IP 白名单、支持 MQTT、OPC-UA、OPC-DA、PI、Wonderware、Kafka 等各种数据源。这些功能为企业提供了更为全面、安全、可靠和高效的时序数据管理解决方案。更多的细节请看 [TDengine Enterprise](https://www.taosdata.com/tdengine-pro) -此外,TDengine Cloud 作为一种全托管的云服务,存储与计算分离,分开计费,为企业提供了企业级的工具和服务,彻底解决了运维难题,尤其适合中小规模的用户使用。 +此外,TDengine Cloud 作为一种全托管的云服务,存储与计算分离,分开计费,为企业提供了企业级的工具和服务,彻底解决了运维难题,尤其适合中小规模的用户使用。更多的细节请看[TDengine 云服务](https://cloud.taosdata.com/?utm_source=menu&utm_medium=webcn) ## TDengine 主要功能与特性 @@ -135,9 +135,3 @@ TDengine 经过特别优化,以适应时间序列数据的独特需求,引 - [TDengine 与 InfluxDB、OpenTSDB、Cassandra、MySQL、ClickHouse 等数据库的对比测试报告](https://www.taosdata.com/downloads/TDengine_Testing_Report_cn.pdf) -## 主要产品 - -TDengine 有两个主要产品:TDengine Enterprise (即 TDengine 企业版)和 TDengine Cloud,关于它们的具体定义请参考 -- [TDengine 企业版](https://www.taosdata.com/tdengine-pro) -- [TDengine 云服务](https://cloud.taosdata.com/?utm_source=menu&utm_medium=webcn) - diff --git a/docs/zh/04-get-started/01-docker.md b/docs/zh/04-get-started/01-docker.md index 364e00f8f2..cadde10e0c 100644 --- a/docs/zh/04-get-started/01-docker.md +++ b/docs/zh/04-get-started/01-docker.md @@ -1,6 +1,6 @@ --- -sidebar_label: Docker -title: 通过 Docker 快速体验 TDengine +sidebar_label: 用Docker快速体验 +title: 用 Docker 快速体验 TDengine description: 使用 Docker 快速体验 TDengine 的高效写入和查询 --- @@ -90,7 +90,7 @@ taosBenchmark 提供了丰富的选项,允许用户自定义测试参数,如 taosBenchmark --help ``` -有关taosBenchmark 的详细使用方法,请参考[taosBenchmark 参考手册](../../reference/components/taosbenchmark) +有关taosBenchmark 的详细使用方法,请参考[taosBenchmark 参考手册](../../reference/tools/taosbenchmark) ### 体验查询 diff --git a/docs/zh/04-get-started/03-package.md b/docs/zh/04-get-started/03-package.md index 7df41af831..2a1f594b4f 100644 --- a/docs/zh/04-get-started/03-package.md +++ b/docs/zh/04-get-started/03-package.md @@ -1,6 +1,6 @@ --- -sidebar_label: 安装包 -title: 使用安装包立即开始 +sidebar_label: 用安装包快速体验 +title: 使用安装包快速体验 TDengine description: 使用安装包快速体验 TDengine --- @@ -263,7 +263,7 @@ SELECT * FROM t; Query OK, 2 row(s) in set (0.003128s) ``` -除执行 SQL 语句外,系统管理员还可以从 TDengine CLI 进行检查系统运行状态、添加删除用户账号等操作。TDengine CLI 连同应用驱动也可以独立安装在机器上运行,更多细节请参考 [TDengine 命令行](../../reference/components/taos-cli/)。 +除执行 SQL 语句外,系统管理员还可以从 TDengine CLI 进行检查系统运行状态、添加删除用户账号等操作。TDengine CLI 连同应用驱动也可以独立安装在机器上运行,更多细节请参考 [TDengine 命令行](../../reference/tools/taos-cli/)。 ## 快速体验 @@ -286,7 +286,7 @@ taosBenchmark 提供了丰富的选项,允许用户自定义测试参数,如 taosBenchmark --help ``` -有关taosBenchmark 的详细使用方法,请参考[taosBenchmark 参考手册](../../reference/components/taosbenchmark) +有关taosBenchmark 的详细使用方法,请参考[taosBenchmark 参考手册](../../reference/tools/taosbenchmark) ### 体验查询 diff --git a/docs/zh/04-get-started/05-cloud.md b/docs/zh/04-get-started/05-cloud.md index 1d01abb1bb..bd76add527 100644 --- a/docs/zh/04-get-started/05-cloud.md +++ b/docs/zh/04-get-started/05-cloud.md @@ -1,6 +1,6 @@ --- -sidebar_label: 云服务 -title: 通过 云服务 快速体验 TDengine +sidebar_label: 用云服务快速体验 +title: 通过云服务 快速体验 TDengine toc_max_heading_level: 4 --- diff --git a/docs/zh/04-get-started/index.md b/docs/zh/04-get-started/index.md index 4422efbf60..4d9f7ceae5 100644 --- a/docs/zh/04-get-started/index.md +++ b/docs/zh/04-get-started/index.md @@ -1,5 +1,5 @@ --- -title: 立即开始 +title: 快速体验 description: '快速设置 TDengine 环境并体验其高效写入和查询' --- diff --git a/docs/zh/05-basic/index.md b/docs/zh/05-basic/index.md index 18dcd3fc9c..f579dcb3a0 100644 --- a/docs/zh/05-basic/index.md +++ b/docs/zh/05-basic/index.md @@ -1,6 +1,6 @@ --- -title: 快速入门 -description: 'TDengine 基本功能' +title: 基础功能 +description: 'TDengine 基础功能' --- 本章主要介绍 TDengine 的数据模型以及写入和查询功能。 diff --git a/docs/zh/06-advanced/05-data-in/07-mqtt.md b/docs/zh/06-advanced/05-data-in/07-mqtt.md index eb6753b7b0..af99cd3621 100644 --- a/docs/zh/06-advanced/05-data-in/07-mqtt.md +++ b/docs/zh/06-advanced/05-data-in/07-mqtt.md @@ -72,15 +72,30 @@ TDengine 可以通过 MQTT 连接器从 MQTT 代理订阅数据并将其写入 T taosX 可以使用 JSON 提取器解析数据,并允许用户在数据库中指定数据模型,包括,指定表名称和超级表名,设置普通列和标签列等。 - #### 6.1 解析 + 有三种获取示例数据的方法: 点击 **从服务器检索** 按钮,从 MQTT 获取示例数据。 点击 **文件上传** 按钮,上传 CSV 文件,获取示例数据。 -在 **消息体** 中填写 MQTT 消息体中的示例数据,例如:`{"id": 1, "message": "hello-word"}{"id": 2, "message": "hello-word"}`。之后会使用这条示例数据来配置提取和过滤条件。 +在 **消息体** 中填写 MQTT 消息体中的示例数据。 + +json 数据支持 JSONObject 或者 JSONArray,使用 json 解析器可以解析一下数据: + +``` json +{"id": 1, "message": "hello-word"} +{"id": 2, "message": "hello-word"} +``` + +或者 + +``` json +[{"id": 1, "message": "hello-word"},{"id": 2, "message": "hello-word"}] +``` + +解析结果如下所示: ![mqtt-06.png](./mqtt-06.png) diff --git a/docs/zh/06-advanced/05-data-in/08-kafka.md b/docs/zh/06-advanced/05-data-in/08-kafka.md index 92bfc031ec..e05c205f6e 100644 --- a/docs/zh/06-advanced/05-data-in/08-kafka.md +++ b/docs/zh/06-advanced/05-data-in/08-kafka.md @@ -80,13 +80,29 @@ TDengine 可以高效地从 Kafka 读取数据并将其写入 TDengine,以实 在 **Payload 解析** 区域填写 Payload 解析相关的配置参数。 #### 7.1 解析 + 有三种获取示例数据的方法: 点击 **从服务器检索** 按钮,从 Kafka 获取示例数据。 点击 **文件上传** 按钮,上传 CSV 文件,获取示例数据。 -在 **消息体** 中填写 Kafka 消息体中的示例数据,例如:`{"id": 1, "message": "hello-word"}{"id": 2, "message": "hello-word"}`。之后会使用这条示例数据来配置提取和过滤条件。 +在 **消息体** 中填写 Kafka 消息体中的示例数据。 + +json 数据支持 JSONObject 或者 JSONArray,使用 json 解析器可以解析一下数据: + +``` json +{"id": 1, "message": "hello-word"} +{"id": 2, "message": "hello-word"} +``` + +或者 + +``` json +[{"id": 1, "message": "hello-word"},{"id": 2, "message": "hello-word"}] +``` + +解析结果如下所示: ![kafka-07.png](./kafka-07.png) diff --git a/docs/zh/06-advanced/05-data-in/09-influxdb.md b/docs/zh/06-advanced/05-data-in/09-influxdb.md index 3be24c8d5f..d0b781667d 100644 --- a/docs/zh/06-advanced/05-data-in/09-influxdb.md +++ b/docs/zh/06-advanced/05-data-in/09-influxdb.md @@ -17,7 +17,7 @@ InfluxDB 是一种流行的开源时间序列数据库,它针对处理大量 在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示: -![InfluxDB-01zh-EnterDataSourcePage.png](./pic/InfluxDB-01zh-EnterDataSourcePage.png "进入新增数据源页面") +![Common-zh00-EnterDataSourcePage.png](./pic/Common-zh00-EnterDataSourcePage.png "进入新增数据源页面") ### 2. 配置基本信息 diff --git a/docs/zh/06-advanced/05-data-in/10-opentsdb.md b/docs/zh/06-advanced/05-data-in/10-opentsdb.md index e7f804f86f..3737f2a415 100644 --- a/docs/zh/06-advanced/05-data-in/10-opentsdb.md +++ b/docs/zh/06-advanced/05-data-in/10-opentsdb.md @@ -17,7 +17,7 @@ OpenTSDB 是一个架构在 HBase 系统之上的实时监控信息收集和展 在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示: -![OpenTSDB-01zh-EnterDataSourcePage.png](./pic/OpenTSDB-01zh-EnterDataSourcePage.png "进入新增数据源页面") +![Common-zh00-EnterDataSourcePage.png](./pic/Common-zh00-EnterDataSourcePage.png "进入新增数据源页面") ### 2. 配置基本信息 diff --git a/docs/zh/06-advanced/05-data-in/13-mysql.md b/docs/zh/06-advanced/05-data-in/13-mysql.md index 14b015d67a..4cc84fbfa2 100644 --- a/docs/zh/06-advanced/05-data-in/13-mysql.md +++ b/docs/zh/06-advanced/05-data-in/13-mysql.md @@ -15,7 +15,7 @@ MySQL 是最流行的关系型数据库之一。很多系统都曾经或正在 在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示: -![InfluxDB-01zh-EnterDataSourcePage.png](./pic/InfluxDB-01zh-EnterDataSourcePage.png "进入新增数据源页面") +![Common-zh00-EnterDataSourcePage.png](./pic/Common-zh00-EnterDataSourcePage.png "进入新增数据源页面") ### 2. 配置基本信息 @@ -56,11 +56,19 @@ MySQL 是最流行的关系型数据库之一。很多系统都曾经或正在 ### 6. 配置 SQL 查询 +**子表字段** 用于拆分子表的字段,它是一条 select distinct 的 SQL 语句,查询指定字段组合的非重复项,通常与 transform 中的 tag 相对应: +> 此项配置主要为了解决数据迁移乱序问题,需要结合**SQL 模板**共同使用,否则不能达到预期效果,使用示例如下: +> 1. 子表字段填写语句 `select distinct col_name1, col_name2 from table`,它表示使用源表中的字段 col_name1 与 col_name2 拆分目标超级表的子表 +> 2. 在**SQL 模板**中添加子表字段占位符,例如 `select * from table where ts >= ${start} and ts < ${end} and ${col_name1} and ${col_name2}` 中的 `${col_name1} and ${col_name2}` 部分 +> 3. 在 **transform** 中配置 `col_name1` 与 `col_name2` 两个 tag 映射 + **SQL 模板** 用于查询的 SQL 语句模板,SQL 语句中必须包含时间范围条件,且开始时间和结束时间必须成对出现。SQL 语句模板中定义的时间范围由源数据库中的某个代表时间的列和下面定义的占位符组成。 > SQL使用不同的占位符表示不同的时间格式要求,具体有以下占位符格式: > 1. `${start}`、`${end}`:表示 RFC3339 格式时间戳,如: 2024-03-14T08:00:00+0800 > 2. `${start_no_tz}`、`${end_no_tz}`: 表示不带时区的 RFC3339 字符串:2024-03-14T08:00:00 > 3. `${start_date}`、`${end_date}`:表示仅日期,如:2024-03-14 +> +> 为了解决迁移数据乱序的问题,应在查询语句中添加排序条件,例如 `order by ts asc`。 **起始时间** 迁移数据的起始时间,此项为必填字段。 diff --git a/docs/zh/06-advanced/05-data-in/14-postgres.md b/docs/zh/06-advanced/05-data-in/14-postgres.md index cf86ab6ee3..af8297bfff 100644 --- a/docs/zh/06-advanced/05-data-in/14-postgres.md +++ b/docs/zh/06-advanced/05-data-in/14-postgres.md @@ -17,7 +17,7 @@ TDengine 可以高效地从 PostgreSQL 读取数据并将其写入 TDengine, 在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示: -![PostgreSQL-01zh-EnterDataSourcePage.png](./pic/PostgreSQL-01zh-EnterDataSourcePage.png "进入新增数据源页面") +![Common-zh00-EnterDataSourcePage.png](./pic/Common-zh00-EnterDataSourcePage.png "进入新增数据源页面") ### 2. 配置基本信息 @@ -57,11 +57,19 @@ TDengine 可以高效地从 PostgreSQL 读取数据并将其写入 TDengine, ### 6. 配置 SQL 查询 +**子表字段** 用于拆分子表的字段,它是一条 select distinct 的 SQL 语句,查询指定字段组合的非重复项,通常与 transform 中的 tag 相对应: +> 此项配置主要为了解决数据迁移乱序问题,需要结合**SQL 模板**共同使用,否则不能达到预期效果,使用示例如下: +> 1. 子表字段填写语句 `select distinct col_name1, col_name2 from table`,它表示使用源表中的字段 col_name1 与 col_name2 拆分目标超级表的子表 +> 2. 在**SQL 模板**中添加子表字段占位符,例如 `select * from table where ts >= ${start} and ts < ${end} and ${col_name1} and ${col_name2}` 中的 `${col_name1} and ${col_name2}` 部分 +> 3. 在 **transform** 中配置 `col_name1` 与 `col_name2` 两个 tag 映射 + **SQL 模板** 用于查询的 SQL 语句模板,SQL 语句中必须包含时间范围条件,且开始时间和结束时间必须成对出现。SQL 语句模板中定义的时间范围由源数据库中的某个代表时间的列和下面定义的占位符组成。 > SQL使用不同的占位符表示不同的时间格式要求,具体有以下占位符格式: > 1. `${start}`、`${end}`:表示 RFC3339 格式时间戳,如: 2024-03-14T08:00:00+0800 > 2. `${start_no_tz}`、`${end_no_tz}`: 表示不带时区的 RFC3339 字符串:2024-03-14T08:00:00 > 3. `${start_date}`、`${end_date}`:表示仅日期,如:2024-03-14 +> +> 为了解决迁移数据乱序的问题,应在查询语句中添加排序条件,例如 `order by ts asc`。 **起始时间** 迁移数据的起始时间,此项为必填字段。 diff --git a/docs/zh/06-advanced/05-data-in/15-oracle.md b/docs/zh/06-advanced/05-data-in/15-oracle.md index c99f6aae47..39bbab32d3 100644 --- a/docs/zh/06-advanced/05-data-in/15-oracle.md +++ b/docs/zh/06-advanced/05-data-in/15-oracle.md @@ -17,7 +17,7 @@ TDengine 可以高效地从 Oracle 读取数据并将其写入 TDengine,以实 在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示: -![Oracle-01zh-EnterDataSourcePage.png](./pic/Oracle-01zh-EnterDataSourcePage.png "进入新增数据源页面") +![Common-zh00-EnterDataSourcePage.png](./pic/Common-zh00-EnterDataSourcePage.png "进入新增数据源页面") ### 2. 配置基本信息 @@ -49,11 +49,19 @@ TDengine 可以高效地从 Oracle 读取数据并将其写入 TDengine,以实 ### 5. 配置 SQL 查询 +**子表字段** 用于拆分子表的字段,它是一条 select distinct 的 SQL 语句,查询指定字段组合的非重复项,通常与 transform 中的 tag 相对应: +> 此项配置主要为了解决数据迁移乱序问题,需要结合**SQL 模板**共同使用,否则不能达到预期效果,使用示例如下: +> 1. 子表字段填写语句 `select distinct col_name1, col_name2 from table`,它表示使用源表中的字段 col_name1 与 col_name2 拆分目标超级表的子表 +> 2. 在**SQL 模板**中添加子表字段占位符,例如 `select * from table where ts >= ${start} and ts < ${end} and ${col_name1} and ${col_name2}` 中的 `${col_name1} and ${col_name2}` 部分 +> 3. 在 **transform** 中配置 `col_name1` 与 `col_name2` 两个 tag 映射 + **SQL 模板** 用于查询的 SQL 语句模板,SQL 语句中必须包含时间范围条件,且开始时间和结束时间必须成对出现。SQL 语句模板中定义的时间范围由源数据库中的某个代表时间的列和下面定义的占位符组成。 > SQL使用不同的占位符表示不同的时间格式要求,具体有以下占位符格式: > 1. `${start}`、`${end}`:表示 RFC3339 格式时间戳,如: 2024-03-14T08:00:00+0800 > 2. `${start_no_tz}`、`${end_no_tz}`: 表示不带时区的 RFC3339 字符串:2024-03-14T08:00:00 > 3. `${start_date}`、`${end_date}`:表示仅日期,但 Oracle 中没有纯日期类型,所以它会带零时零分零秒,如:2024-03-14 00:00:00,所以使用 `date <= ${end_date}` 时需要注意,它不能包含 2024-03-14 当天数据 +> +> 为了解决迁移数据乱序的问题,应在查询语句中添加排序条件,例如 `order by ts asc`。 **起始时间** 迁移数据的起始时间,此项为必填字段。 diff --git a/docs/zh/06-advanced/05-data-in/16-mssql.md b/docs/zh/06-advanced/05-data-in/16-mssql.md index ba5451434d..81e9e98013 100644 --- a/docs/zh/06-advanced/05-data-in/16-mssql.md +++ b/docs/zh/06-advanced/05-data-in/16-mssql.md @@ -15,7 +15,7 @@ Microsoft SQL Server 是最流行的关系型数据库之一。很多系统都 在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示: -![InfluxDB-01zh-EnterDataSourcePage.png](./pic/InfluxDB-01zh-EnterDataSourcePage.png "进入新增数据源页面") +![Common-zh00-EnterDataSourcePage.png](./pic/Common-zh00-EnterDataSourcePage.png "进入新增数据源页面") ### 2. 配置基本信息 @@ -61,6 +61,12 @@ Microsoft SQL Server 是最流行的关系型数据库之一。很多系统都 ### 6. 配置 SQL 查询 +**子表字段** 用于拆分子表的字段,它是一条 select distinct 的 SQL 语句,查询指定字段组合的非重复项,通常与 transform 中的 tag 相对应: +> 此项配置主要为了解决数据迁移乱序问题,需要结合**SQL 模板**共同使用,否则不能达到预期效果,使用示例如下: +> 1. 子表字段填写语句 `select distinct col_name1, col_name2 from table`,它表示使用源表中的字段 col_name1 与 col_name2 拆分目标超级表的子表 +> 2. 在**SQL 模板**中添加子表字段占位符,例如 `select * from table where ts >= ${start} and ts < ${end} and ${col_name1} and ${col_name2}` 中的 `${col_name1} and ${col_name2}` 部分 +> 3. 在 **transform** 中配置 `col_name1` 与 `col_name2` 两个 tag 映射 + **SQL 模板** 用于查询的 SQL 语句模板,SQL 语句中必须包含时间范围条件,且开始时间和结束时间必须成对出现。SQL 语句模板中定义的时间范围由源数据库中的某个代表时间的列和下面定义的占位符组成。 > SQL使用不同的占位符表示不同的时间格式要求,具体有以下占位符格式: > 1. `${start}`、`${end}`:表示 RFC3339 格式时间戳,如: 2024-03-14T08:00:00+0800 @@ -68,6 +74,8 @@ Microsoft SQL Server 是最流行的关系型数据库之一。很多系统都 > 3. `${start_date}`、`${end_date}`:表示仅日期,如:2024-03-14 > > 注意:只有 `datetime2` 与 `datetimeoffset` 支持使用 start/end 查询,`datetime` 与 `smalldatetime` 只能使用 start_no_tz/end_no_tz 查询,而 `timestamp` 不能用作查询条件。 +> +> 为了解决迁移数据乱序的问题,应在查询语句中添加排序条件,例如 `order by ts asc`。 **起始时间** 迁移数据的起始时间,此项为必填字段。 diff --git a/docs/zh/06-advanced/05-data-in/17-mongodb.md b/docs/zh/06-advanced/05-data-in/17-mongodb.md new file mode 100644 index 0000000000..2434e2e122 --- /dev/null +++ b/docs/zh/06-advanced/05-data-in/17-mongodb.md @@ -0,0 +1,135 @@ +--- +title: "MongoDB" +sidebar_label: "MongoDB" +--- + +本节讲述如何通过 Explorer 界面创建数据迁移任务,从 MongoDB 迁移数据到当前 TDengine 集群。 + +## 功能概述 + +MongoDB 是一个介于关系型数据库与非关系型数据库之间的产品,被广泛应用于内容管理系统、移动应用与物联网等众多领域。从 TDengine 企业版 3.3.3.0 开始,TDengine 可以高效地从 MongoDB 读取数据并将其写入 TDengine,以实现历史数据迁移或实时数据同步,解决业务面临的技术痛点。 + +## 创建任务 + +### 1. 新增数据源 + +在数据写入页面中点击左上角的 **+新增数据源** 按钮进入新增数据源页面,如下图所示: + +![Common-zh00-EnterDataSourcePage.png](./pic/Common-zh00-EnterDataSourcePage.png "进入新增数据源页面") + +### 2. 配置基本信息 + +在 **名称** 字段中输入任务名称,例如 `test_mongodb_01` 。 + +选择 **类型** 下拉框中的 `MongoDB` ,如下图所示(选择完成后页面中的字段会发生变化)。 + +**代理** 是非必填项,如有需要,可以在下拉框中选择指定的代理,也可以先点击右侧的 **+创建新的代理** 按钮创建一个新的代理。 + +**目标数据库** 是必填项,可以在下拉框中选择指定的数据库,也可以先点击右侧的 **+创建数据库** 按钮创建一个新的数据库。 + +![mongodb-01.png](./pic/mongodb-01.png "选择数据源类型为 MongoDB") + +### 3. 配置连接信息 + +在 **连接配置** 区域填写 *`源 MongoDB 数据库的连接信息`*,如下图所示: + +![mongodb-02.png](./pic/mongodb-02.png "填写源 MongoDB 数据库的连接信息") + +### 4. 配置认证信息 + +**用户** 输入源 MongoDB 数据库的用户,该用户必须在 MongoDB 系统中拥有读取权限。 + +**密码** 输入源 MongoDB 数据库中上方用户的登陆密码。 + +**认证数据库** MongoDB 中存储用户信息的数据库,默认为 admin。 + +![mongodb-03.png](./pic/mongodb-03.png "配置认证信息") + +### 5. 配置连接选项 + +**应用名称** 设置应用程序名称,用于标识连接的应用程序。 + +**SSL 证书** 设置是否使用加密连接,默认关闭,如果开启,需要上传以下两个文件: + +  1. **CA 文件** 上传 SSL 加密的证书授权文件。 + +  2. **证书文件** 上传 SSL 加密的证书文件。 + +![ mongodb-04.png](./pic/mongodb-04.png "配置连接选项") + +然后点击 **检查连通性** 按钮,用户可以点击此按钮检查上方填写的信息是否可以正常获取源 MongoDB 数据库的数据。 + +### 6. 配置数据查询 + +**数据库** MongoDB 中源数据库,可以使用占位符进行动态配置,例如 `database_${Y}`,可用占位符列表见下方表格。 + +**集合** MongoDB 中集合,可以使用占位符进行动态配置,例如 `collection_${md}`,可用占位符列表见下方表格。 + +|占位符|描述|示例数据| +| :-----: | :------------: |:--------:| +|Y|完整的公历年表示,零填充的 4 位整数|2024| +|y|公历年除以 100,零填充的 2 位整数|24| +|M|整数月份(1 - 12)|1| +|m|整数月份(01 - 12)|01| +|B|月份英文全拼|January| +|b|月份英文的缩写(3 个字母)|Jan| +|D|日期的数字表示(1 - 31)|1| +|d|日期的数字表示(01 - 31)|01| +|J|一年中的第几天(1 - 366)|1| +|j|一年中的第几天(001 - 366)|001| +|F|相当于 `${Y}-${m}-${d}`|2024-01-01| + +**子表字段** 用于拆分子表的字段,通常与 transform 中的 tag 相对应,多个字段使用英文逗号分隔,例如 col_name1,col_name2。 +此项配置主要为了解决数据迁移乱序问题,需要结合**查询模板**共同使用,否则不能达到预期效果,使用示例如下: +1. 配置两个子表字段 `col_name1,col_name2` +2. 在**查询模板**中添加子表字段占位符,例如 `{"ddate":{"$gte":${start_datetime},"$lt":${end_datetime}}, ${col_name1}, ${col_name2}}` 中的 `${col_name1}, ${col_name2}` 部分 +3. 在 **transform** 中配置 `col_name1` 与 `col_name2` 两个 tag 映射 + +**查询模板** 用于查询数据的查询语句,JSON格式,语句中必须包含时间范围条件,且开始时间和结束时间必须成对出现。模板中定义的时间范围由源数据库中的某个代表时间的列和下面定义的占位符组成。 +使用不同的占位符表示不同的时间格式要求,具体有以下占位符格式: +1. `${start_datetime}`、`${end_datetime}`:对应后端 datetime 类型字段的筛选,如:`{"ddate":{"$gte":${start_datetime},"$lt":${end_datetime}}}` 将被转换为 `{"ddate":{"$gte":{"$date":"2024-06-01T00:00:00+00:00"},"$lt":{"$date":"2024-07-01T00:00:00+00:00"}}}` +2. `${start_timestamp}`、`${end_timestamp}`: 对应后端 timestamp 类型字段的筛选,如:`{"ttime":{"$gte":${start_timestamp},"$lt":${end_timestamp}}}` 将被转换为 `{"ttime":{"$gte":{"$timestamp":{"t":123,"i":456}},"$lt":{"$timestamp":{"t":123,"i":456}}}}` + +**查询排序** 执行查询时的排序条件,JSON格式,它必须符合 MongoDB 排序条件的格式规范,使用示例如下: +1. `{"createtime":1}`:MongoDB 查询结果按 createtime 正序返回。 +2. `{"createdate":1, "createtime":1}`:MongoDB 查询结果按 createdate 正序、createtime 正序返回。 + +**起始时间** 迁移数据的起始时间,此项为必填字段。 + +**结束时间** 迁移数据的结束时间,可留空。如果设置,则迁移任务执行到结束时间后,任务完成自动停止;如果留空,则持续同步实时数据,任务不会自动停止。 + +**查询间隔** 分段查询数据的时间间隔,默认1天。为了避免查询数据量过大,一次数据同步子任务会使用查询间隔分时间段查询数据。 + +**延迟时长** 实时同步数据场景中,为了避免延迟写入的数据丢失,每次同步任务会读取延迟时长之前的数据。 + +![ mongodb-05.png](./pic/mongodb-05.png "配置数据查询") + +### 7. 配置数据映射 + +在 **Payload 转换** 区域填写数据映射相关的配置参数。 + +点击 **从服务器检索** 按钮,从 MongoDB 服务器获取示例数据。 + +在 **解析** 中选择 JSON/Regex/UDT 三种规则解析原始消息体,配置完成后点击右侧的 **预览** 按钮可以查看解析的结果。 + +在 **从列中提取或拆分** 中填写从消息体中提取或拆分的字段,例如:将 vValue 字段拆分成 `vValue_0` 和 `vValue_1` 这 2 个字段,选择 split 提取器,seperator 填写分割符 `,`, number 填写 2,配置完成后点击右侧的 **预览** 按钮可以查看转换的结果。 + +在 **过滤** 中,填写过滤条件,例如:填写 `Value > 0`,则只有 Value 大于 0 的数据才会被写入 TDengine,配置完成后点击右侧的 **预览** 按钮可以查看过滤的结果。 + +在 **映射** 中,选择要映射到 TDengine 的超级表,以及映射到超级表的列,配置完成后点击右侧的 **预览** 按钮可以查看映射的结果。 + +![mongodb-06.png](pic/mongodb-06.png) + +### 8. 配置高级选项 + +**高级选项** 区域是默认折叠的,点击右侧 `>` 可以展开,如下图所示: + +**最大读取并发数** 数据源连接数或读取线程数限制,当默认参数不满足需要或需要调整资源使用量时修改此参数。 + +**批次大小** 单次发送的最大消息数或行数。默认是 10000。 + +![mongodb-07.png](pic/mongodb-07.png) + +### 9. 创建完成 + +点击 **提交** 按钮,完成创建 MongoDB 到 TDengine 的数据同步任务,回到**数据源列表**页面可查看任务执行情况。 diff --git a/docs/zh/06-advanced/05-data-in/index.md b/docs/zh/06-advanced/05-data-in/index.md index 1a142fd47a..7e5c467010 100644 --- a/docs/zh/06-advanced/05-data-in/index.md +++ b/docs/zh/06-advanced/05-data-in/index.md @@ -38,7 +38,6 @@ TDengine Enterprise 配备了一个强大的可视化数据管理工具—taosEx 下面详细讲解数据转换规则 - ### 解析 仅非结构化的数据源需要这个步骤,目前 MQTT 和 Kafka 数据源会使用这个步骤提供的规则来解析非结构化数据,以初步获取结构化数据,即可以以字段描述的行列数据。在 explorer 中您需要提供示例数据和解析规则,来预览解析出以表格呈现的结构化数据。 @@ -53,13 +52,15 @@ TDengine Enterprise 配备了一个强大的可视化数据管理工具—taosEx 2. 点击右侧按钮 “从服务器检索” 则从配置的服务器获取示例数据,并追加到示例数据 textarea 中; 3. 上传文件,将文件内容追加到示例数据 textarea 中。 +每一条示例数据以回车符结尾。 + #### 解析 解析就是通过解析规则,将非结构化字符串解析为结构化数据。消息体的解析规则目前支持 JSON、Regex 和 UDT。 ##### JSON 解析 -如下 JSON 示例数据,可自动解析出字段:`groupid`、`voltage`、`current`、`ts`、`inuse`、`location`。 +JSON 解析支持 JSONObject 或者 JSONArray。 如下 JSON 示例数据,可自动解析出字段:`groupid`、`voltage`、`current`、`ts`、`inuse`、`location`。 ``` json {"groupid": 170001, "voltage": "221V", "current": 12.3, "ts": "2023-12-18T22:12:00", "inuse": true, "location": "beijing.chaoyang.datun"} @@ -67,6 +68,16 @@ TDengine Enterprise 配备了一个强大的可视化数据管理工具—taosEx {"groupid": 170001, "voltage": "216V", "current": 12.5, "ts": "2023-12-18T22:12:04", "inuse": false, "location": "beijing.chaoyang.datun"} ``` +或者 + +``` json +[{"groupid": 170001, "voltage": "221V", "current": 12.3, "ts": "2023-12-18T22:12:00", "inuse": true, "location": "beijing.chaoyang.datun"}, +{"groupid": 170001, "voltage": "220V", "current": 12.2, "ts": "2023-12-18T22:12:02", "inuse": true, "location": "beijing.chaoyang.datun"}, +{"groupid": 170001, "voltage": "216V", "current": 12.5, "ts": "2023-12-18T22:12:04", "inuse": false, "location": "beijing.chaoyang.datun"}] +``` + +后续示例仅以JSONObject 为例说明。 + 如下嵌套结构的 JSON 数据,可自动解析出字段`groupid`、`data_voltage`、`data_current`、`ts`、`inuse`、`location_0_province`、`location_0_city`、`location_0_datun`,也可以选择要解析的字段,并设置解析的别名。 ``` json diff --git a/docs/zh/06-advanced/05-data-in/pic/Common-zh00-EnterDataSourcePage.png b/docs/zh/06-advanced/05-data-in/pic/Common-zh00-EnterDataSourcePage.png new file mode 100644 index 0000000000..04fa06ce73 Binary files /dev/null and b/docs/zh/06-advanced/05-data-in/pic/Common-zh00-EnterDataSourcePage.png differ diff --git a/docs/zh/06-advanced/05-data-in/pic/InfluxDB-01zh-EnterDataSourcePage.png b/docs/zh/06-advanced/05-data-in/pic/InfluxDB-01zh-EnterDataSourcePage.png deleted file mode 100644 index ca8107066f..0000000000 Binary files a/docs/zh/06-advanced/05-data-in/pic/InfluxDB-01zh-EnterDataSourcePage.png and /dev/null differ diff --git a/docs/zh/06-advanced/05-data-in/pic/OpenTSDB-01zh-EnterDataSourcePage.png b/docs/zh/06-advanced/05-data-in/pic/OpenTSDB-01zh-EnterDataSourcePage.png deleted file mode 100644 index ca8107066f..0000000000 Binary files a/docs/zh/06-advanced/05-data-in/pic/OpenTSDB-01zh-EnterDataSourcePage.png and /dev/null differ diff --git a/docs/zh/06-advanced/05-data-in/pic/Oracle-01zh-EnterDataSourcePage.png b/docs/zh/06-advanced/05-data-in/pic/Oracle-01zh-EnterDataSourcePage.png deleted file mode 100644 index ca8107066f..0000000000 Binary files a/docs/zh/06-advanced/05-data-in/pic/Oracle-01zh-EnterDataSourcePage.png and /dev/null differ diff --git a/docs/zh/06-advanced/05-data-in/pic/PostgreSQL-01zh-EnterDataSourcePage.png b/docs/zh/06-advanced/05-data-in/pic/PostgreSQL-01zh-EnterDataSourcePage.png deleted file mode 100644 index ca8107066f..0000000000 Binary files a/docs/zh/06-advanced/05-data-in/pic/PostgreSQL-01zh-EnterDataSourcePage.png and /dev/null differ diff --git a/docs/zh/06-advanced/05-data-in/pic/mongodb-01.png b/docs/zh/06-advanced/05-data-in/pic/mongodb-01.png new file mode 100644 index 0000000000..570dd7692f Binary files /dev/null and b/docs/zh/06-advanced/05-data-in/pic/mongodb-01.png differ diff --git a/docs/zh/06-advanced/05-data-in/pic/mongodb-02.png b/docs/zh/06-advanced/05-data-in/pic/mongodb-02.png new file mode 100644 index 0000000000..72ae02cce5 Binary files /dev/null and b/docs/zh/06-advanced/05-data-in/pic/mongodb-02.png differ diff --git a/docs/zh/06-advanced/05-data-in/pic/mongodb-03.png b/docs/zh/06-advanced/05-data-in/pic/mongodb-03.png new file mode 100644 index 0000000000..639466c7c9 Binary files /dev/null and b/docs/zh/06-advanced/05-data-in/pic/mongodb-03.png differ diff --git a/docs/zh/06-advanced/05-data-in/pic/mongodb-04.png b/docs/zh/06-advanced/05-data-in/pic/mongodb-04.png new file mode 100644 index 0000000000..55b4a718d9 Binary files /dev/null and b/docs/zh/06-advanced/05-data-in/pic/mongodb-04.png differ diff --git a/docs/zh/06-advanced/05-data-in/pic/mongodb-05.png b/docs/zh/06-advanced/05-data-in/pic/mongodb-05.png new file mode 100644 index 0000000000..823dfaf0ce Binary files /dev/null and b/docs/zh/06-advanced/05-data-in/pic/mongodb-05.png differ diff --git a/docs/zh/06-advanced/05-data-in/pic/mongodb-06.png b/docs/zh/06-advanced/05-data-in/pic/mongodb-06.png new file mode 100644 index 0000000000..cab2c80368 Binary files /dev/null and b/docs/zh/06-advanced/05-data-in/pic/mongodb-06.png differ diff --git a/docs/zh/06-advanced/05-data-in/pic/mongodb-07.png b/docs/zh/06-advanced/05-data-in/pic/mongodb-07.png new file mode 100644 index 0000000000..2305ec3d2e Binary files /dev/null and b/docs/zh/06-advanced/05-data-in/pic/mongodb-07.png differ diff --git a/docs/zh/06-advanced/05-data-in/pic/mssql-05.png b/docs/zh/06-advanced/05-data-in/pic/mssql-05.png index de12a55e06..a1e7fa3324 100644 Binary files a/docs/zh/06-advanced/05-data-in/pic/mssql-05.png and b/docs/zh/06-advanced/05-data-in/pic/mssql-05.png differ diff --git a/docs/zh/06-advanced/05-data-in/pic/mysql-05.png b/docs/zh/06-advanced/05-data-in/pic/mysql-05.png index e168d9e739..dd851ac193 100644 Binary files a/docs/zh/06-advanced/05-data-in/pic/mysql-05.png and b/docs/zh/06-advanced/05-data-in/pic/mysql-05.png differ diff --git a/docs/zh/06-advanced/05-data-in/pic/oracle-04.png b/docs/zh/06-advanced/05-data-in/pic/oracle-04.png index e168d9e739..650c807183 100644 Binary files a/docs/zh/06-advanced/05-data-in/pic/oracle-04.png and b/docs/zh/06-advanced/05-data-in/pic/oracle-04.png differ diff --git a/docs/zh/06-advanced/05-data-in/pic/postgres-05.png b/docs/zh/06-advanced/05-data-in/pic/postgres-05.png index e168d9e739..2604deddb7 100644 Binary files a/docs/zh/06-advanced/05-data-in/pic/postgres-05.png and b/docs/zh/06-advanced/05-data-in/pic/postgres-05.png differ diff --git a/docs/zh/08-develop/01-connect/_connect_c.mdx b/docs/zh/07-develop/01-connect/_connect_c.mdx similarity index 100% rename from docs/zh/08-develop/01-connect/_connect_c.mdx rename to docs/zh/07-develop/01-connect/_connect_c.mdx diff --git a/docs/zh/08-develop/01-connect/_connect_cs.mdx b/docs/zh/07-develop/01-connect/_connect_cs.mdx similarity index 100% rename from docs/zh/08-develop/01-connect/_connect_cs.mdx rename to docs/zh/07-develop/01-connect/_connect_cs.mdx diff --git a/docs/zh/08-develop/01-connect/_connect_go.mdx b/docs/zh/07-develop/01-connect/_connect_go.mdx similarity index 100% rename from docs/zh/08-develop/01-connect/_connect_go.mdx rename to docs/zh/07-develop/01-connect/_connect_go.mdx diff --git a/docs/zh/08-develop/01-connect/_connect_java.mdx b/docs/zh/07-develop/01-connect/_connect_java.mdx similarity index 100% rename from docs/zh/08-develop/01-connect/_connect_java.mdx rename to docs/zh/07-develop/01-connect/_connect_java.mdx diff --git a/docs/zh/08-develop/01-connect/_connect_node.mdx b/docs/zh/07-develop/01-connect/_connect_node.mdx similarity index 100% rename from docs/zh/08-develop/01-connect/_connect_node.mdx rename to docs/zh/07-develop/01-connect/_connect_node.mdx diff --git a/docs/zh/08-develop/01-connect/_connect_php.mdx b/docs/zh/07-develop/01-connect/_connect_php.mdx similarity index 100% rename from docs/zh/08-develop/01-connect/_connect_php.mdx rename to docs/zh/07-develop/01-connect/_connect_php.mdx diff --git a/docs/zh/08-develop/01-connect/_connect_python.mdx b/docs/zh/07-develop/01-connect/_connect_python.mdx similarity index 100% rename from docs/zh/08-develop/01-connect/_connect_python.mdx rename to docs/zh/07-develop/01-connect/_connect_python.mdx diff --git a/docs/zh/08-develop/01-connect/_connect_r.mdx b/docs/zh/07-develop/01-connect/_connect_r.mdx similarity index 100% rename from docs/zh/08-develop/01-connect/_connect_r.mdx rename to docs/zh/07-develop/01-connect/_connect_r.mdx diff --git a/docs/zh/08-develop/01-connect/_connect_rust.mdx b/docs/zh/07-develop/01-connect/_connect_rust.mdx similarity index 100% rename from docs/zh/08-develop/01-connect/_connect_rust.mdx rename to docs/zh/07-develop/01-connect/_connect_rust.mdx diff --git a/docs/zh/08-develop/01-connect/connection-type-zh.webp b/docs/zh/07-develop/01-connect/connection-type-zh.webp similarity index 100% rename from docs/zh/08-develop/01-connect/connection-type-zh.webp rename to docs/zh/07-develop/01-connect/connection-type-zh.webp diff --git a/docs/zh/08-develop/01-connect/index.md b/docs/zh/07-develop/01-connect/index.md similarity index 99% rename from docs/zh/08-develop/01-connect/index.md rename to docs/zh/07-develop/01-connect/index.md index b16e96922f..d15f481b05 100644 --- a/docs/zh/08-develop/01-connect/index.md +++ b/docs/zh/07-develop/01-connect/index.md @@ -89,7 +89,7 @@ TDengine 提供了丰富的应用程序开发接口,为了便于用户快速 com.taosdata.jdbc taos-jdbcdriver - 3.3.2 + 3.3.3 ``` diff --git a/docs/zh/08-develop/02-sql.md b/docs/zh/07-develop/02-sql.md similarity index 100% rename from docs/zh/08-develop/02-sql.md rename to docs/zh/07-develop/02-sql.md diff --git a/docs/zh/08-develop/04-schemaless.md b/docs/zh/07-develop/04-schemaless.md similarity index 100% rename from docs/zh/08-develop/04-schemaless.md rename to docs/zh/07-develop/04-schemaless.md diff --git a/docs/zh/08-develop/05-stmt.md b/docs/zh/07-develop/05-stmt.md similarity index 100% rename from docs/zh/08-develop/05-stmt.md rename to docs/zh/07-develop/05-stmt.md diff --git a/docs/zh/08-develop/07-tmq.md b/docs/zh/07-develop/07-tmq.md similarity index 100% rename from docs/zh/08-develop/07-tmq.md rename to docs/zh/07-develop/07-tmq.md diff --git a/docs/zh/08-develop/09-udf.md b/docs/zh/07-develop/09-udf.md similarity index 100% rename from docs/zh/08-develop/09-udf.md rename to docs/zh/07-develop/09-udf.md diff --git a/docs/zh/08-develop/15-high.md b/docs/zh/07-develop/15-high.md similarity index 100% rename from docs/zh/08-develop/15-high.md rename to docs/zh/07-develop/15-high.md diff --git a/docs/zh/08-develop/_sub_c.mdx b/docs/zh/07-develop/_sub_c.mdx similarity index 100% rename from docs/zh/08-develop/_sub_c.mdx rename to docs/zh/07-develop/_sub_c.mdx diff --git a/docs/zh/08-develop/_sub_cs.mdx b/docs/zh/07-develop/_sub_cs.mdx similarity index 100% rename from docs/zh/08-develop/_sub_cs.mdx rename to docs/zh/07-develop/_sub_cs.mdx diff --git a/docs/zh/08-develop/_sub_go.mdx b/docs/zh/07-develop/_sub_go.mdx similarity index 100% rename from docs/zh/08-develop/_sub_go.mdx rename to docs/zh/07-develop/_sub_go.mdx diff --git a/docs/zh/08-develop/_sub_java.mdx b/docs/zh/07-develop/_sub_java.mdx similarity index 100% rename from docs/zh/08-develop/_sub_java.mdx rename to docs/zh/07-develop/_sub_java.mdx diff --git a/docs/zh/08-develop/_sub_java_ws.mdx b/docs/zh/07-develop/_sub_java_ws.mdx similarity index 100% rename from docs/zh/08-develop/_sub_java_ws.mdx rename to docs/zh/07-develop/_sub_java_ws.mdx diff --git a/docs/zh/08-develop/_sub_node.mdx b/docs/zh/07-develop/_sub_node.mdx similarity index 100% rename from docs/zh/08-develop/_sub_node.mdx rename to docs/zh/07-develop/_sub_node.mdx diff --git a/docs/zh/08-develop/_sub_python.mdx b/docs/zh/07-develop/_sub_python.mdx similarity index 100% rename from docs/zh/08-develop/_sub_python.mdx rename to docs/zh/07-develop/_sub_python.mdx diff --git a/docs/zh/08-develop/_sub_rust.mdx b/docs/zh/07-develop/_sub_rust.mdx similarity index 100% rename from docs/zh/08-develop/_sub_rust.mdx rename to docs/zh/07-develop/_sub_rust.mdx diff --git a/docs/zh/08-develop/addsource.png b/docs/zh/07-develop/addsource.png similarity index 100% rename from docs/zh/08-develop/addsource.png rename to docs/zh/07-develop/addsource.png diff --git a/docs/zh/08-develop/dashboard.png b/docs/zh/07-develop/dashboard.png similarity index 100% rename from docs/zh/08-develop/dashboard.png rename to docs/zh/07-develop/dashboard.png diff --git a/docs/zh/08-develop/dashboard2.png b/docs/zh/07-develop/dashboard2.png similarity index 100% rename from docs/zh/08-develop/dashboard2.png rename to docs/zh/07-develop/dashboard2.png diff --git a/docs/zh/08-develop/highvolume.webp b/docs/zh/07-develop/highvolume.webp similarity index 100% rename from docs/zh/08-develop/highvolume.webp rename to docs/zh/07-develop/highvolume.webp diff --git a/docs/zh/08-develop/img_5.png b/docs/zh/07-develop/img_5.png similarity index 100% rename from docs/zh/08-develop/img_5.png rename to docs/zh/07-develop/img_5.png diff --git a/docs/zh/08-develop/img_6.png b/docs/zh/07-develop/img_6.png similarity index 100% rename from docs/zh/08-develop/img_6.png rename to docs/zh/07-develop/img_6.png diff --git a/docs/zh/08-develop/img_7.png b/docs/zh/07-develop/img_7.png similarity index 100% rename from docs/zh/08-develop/img_7.png rename to docs/zh/07-develop/img_7.png diff --git a/docs/zh/08-develop/index.md b/docs/zh/07-develop/index.md similarity index 100% rename from docs/zh/08-develop/index.md rename to docs/zh/07-develop/index.md diff --git a/docs/zh/07-operation/tdengine-topology.png b/docs/zh/07-operation/tdengine-topology.png deleted file mode 100644 index c2a2dee550..0000000000 Binary files a/docs/zh/07-operation/tdengine-topology.png and /dev/null differ diff --git a/docs/zh/07-operation/01-intro.md b/docs/zh/08-operation/01-intro.md similarity index 100% rename from docs/zh/07-operation/01-intro.md rename to docs/zh/08-operation/01-intro.md diff --git a/docs/zh/07-operation/02-planning.md b/docs/zh/08-operation/02-planning.md similarity index 100% rename from docs/zh/07-operation/02-planning.md rename to docs/zh/08-operation/02-planning.md diff --git a/docs/zh/07-operation/03-deployment.md b/docs/zh/08-operation/03-deployment.md similarity index 100% rename from docs/zh/07-operation/03-deployment.md rename to docs/zh/08-operation/03-deployment.md diff --git a/docs/zh/07-operation/04-maintenance.md b/docs/zh/08-operation/04-maintenance.md similarity index 100% rename from docs/zh/07-operation/04-maintenance.md rename to docs/zh/08-operation/04-maintenance.md diff --git a/docs/zh/07-operation/05-monitor.md b/docs/zh/08-operation/05-monitor.md similarity index 100% rename from docs/zh/07-operation/05-monitor.md rename to docs/zh/08-operation/05-monitor.md diff --git a/docs/zh/07-operation/06-gui.md b/docs/zh/08-operation/06-gui.md similarity index 100% rename from docs/zh/07-operation/06-gui.md rename to docs/zh/08-operation/06-gui.md diff --git a/docs/zh/07-operation/09-backup.md b/docs/zh/08-operation/09-backup.md similarity index 100% rename from docs/zh/07-operation/09-backup.md rename to docs/zh/08-operation/09-backup.md diff --git a/docs/zh/07-operation/10-disaster.md b/docs/zh/08-operation/10-disaster.md similarity index 100% rename from docs/zh/07-operation/10-disaster.md rename to docs/zh/08-operation/10-disaster.md diff --git a/docs/zh/07-operation/12-multi.md b/docs/zh/08-operation/12-multi.md similarity index 100% rename from docs/zh/07-operation/12-multi.md rename to docs/zh/08-operation/12-multi.md diff --git a/docs/zh/07-operation/14-user.md b/docs/zh/08-operation/14-user.md similarity index 100% rename from docs/zh/07-operation/14-user.md rename to docs/zh/08-operation/14-user.md diff --git a/docs/zh/07-operation/16-security.md b/docs/zh/08-operation/16-security.md similarity index 100% rename from docs/zh/07-operation/16-security.md rename to docs/zh/08-operation/16-security.md diff --git a/docs/zh/07-operation/18-dual.md b/docs/zh/08-operation/18-dual.md similarity index 100% rename from docs/zh/07-operation/18-dual.md rename to docs/zh/08-operation/18-dual.md diff --git a/docs/zh/07-operation/Active-Standby.png b/docs/zh/08-operation/Active-Standby.png similarity index 100% rename from docs/zh/07-operation/Active-Standby.png rename to docs/zh/08-operation/Active-Standby.png diff --git a/docs/zh/07-operation/TDinsight-1-cluster-status.webp b/docs/zh/08-operation/TDinsight-1-cluster-status.webp similarity index 100% rename from docs/zh/07-operation/TDinsight-1-cluster-status.webp rename to docs/zh/08-operation/TDinsight-1-cluster-status.webp diff --git a/docs/zh/07-operation/grafana.png b/docs/zh/08-operation/grafana.png similarity index 100% rename from docs/zh/07-operation/grafana.png rename to docs/zh/08-operation/grafana.png diff --git a/docs/zh/07-operation/index.md b/docs/zh/08-operation/index.md similarity index 100% rename from docs/zh/07-operation/index.md rename to docs/zh/08-operation/index.md diff --git a/docs/zh/07-operation/pic/Active-Standby.png b/docs/zh/08-operation/pic/Active-Standby.png similarity index 100% rename from docs/zh/07-operation/pic/Active-Standby.png rename to docs/zh/08-operation/pic/Active-Standby.png diff --git a/docs/zh/07-operation/pic/agent-01.png b/docs/zh/08-operation/pic/agent-01.png similarity index 100% rename from docs/zh/07-operation/pic/agent-01.png rename to docs/zh/08-operation/pic/agent-01.png diff --git a/docs/zh/07-operation/pic/agent-02.png b/docs/zh/08-operation/pic/agent-02.png similarity index 100% rename from docs/zh/07-operation/pic/agent-02.png rename to docs/zh/08-operation/pic/agent-02.png diff --git a/docs/zh/07-operation/pic/agent-03.png b/docs/zh/08-operation/pic/agent-03.png similarity index 100% rename from docs/zh/07-operation/pic/agent-03.png rename to docs/zh/08-operation/pic/agent-03.png diff --git a/docs/zh/07-operation/pic/agent-04.png b/docs/zh/08-operation/pic/agent-04.png similarity index 100% rename from docs/zh/07-operation/pic/agent-04.png rename to docs/zh/08-operation/pic/agent-04.png diff --git a/docs/zh/07-operation/pic/datain-01.png b/docs/zh/08-operation/pic/datain-01.png similarity index 100% rename from docs/zh/07-operation/pic/datain-01.png rename to docs/zh/08-operation/pic/datain-01.png diff --git a/docs/zh/07-operation/pic/datain-02.png b/docs/zh/08-operation/pic/datain-02.png similarity index 100% rename from docs/zh/07-operation/pic/datain-02.png rename to docs/zh/08-operation/pic/datain-02.png diff --git a/docs/zh/07-operation/pic/datain-03.png b/docs/zh/08-operation/pic/datain-03.png similarity index 100% rename from docs/zh/07-operation/pic/datain-03.png rename to docs/zh/08-operation/pic/datain-03.png diff --git a/docs/zh/07-operation/pic/explorer-01-explorer-entry.jpeg b/docs/zh/08-operation/pic/explorer-01-explorer-entry.jpeg similarity index 100% rename from docs/zh/07-operation/pic/explorer-01-explorer-entry.jpeg rename to docs/zh/08-operation/pic/explorer-01-explorer-entry.jpeg diff --git a/docs/zh/07-operation/pic/explorer-02-createDbentry.jpeg b/docs/zh/08-operation/pic/explorer-02-createDbentry.jpeg similarity index 100% rename from docs/zh/07-operation/pic/explorer-02-createDbentry.jpeg rename to docs/zh/08-operation/pic/explorer-02-createDbentry.jpeg diff --git a/docs/zh/07-operation/pic/explorer-03-createDbPage.jpeg b/docs/zh/08-operation/pic/explorer-03-createDbPage.jpeg similarity index 100% rename from docs/zh/07-operation/pic/explorer-03-createDbPage.jpeg rename to docs/zh/08-operation/pic/explorer-03-createDbPage.jpeg diff --git a/docs/zh/07-operation/pic/explorer-04-createDbPage2.jpeg b/docs/zh/08-operation/pic/explorer-04-createDbPage2.jpeg similarity index 100% rename from docs/zh/07-operation/pic/explorer-04-createDbPage2.jpeg rename to docs/zh/08-operation/pic/explorer-04-createDbPage2.jpeg diff --git a/docs/zh/07-operation/pic/explorer-05-createDbtest01.jpeg b/docs/zh/08-operation/pic/explorer-05-createDbtest01.jpeg similarity index 100% rename from docs/zh/07-operation/pic/explorer-05-createDbtest01.jpeg rename to docs/zh/08-operation/pic/explorer-05-createDbtest01.jpeg diff --git a/docs/zh/07-operation/pic/explorer-06-sqlCreateDb.jpeg b/docs/zh/08-operation/pic/explorer-06-sqlCreateDb.jpeg similarity index 100% rename from docs/zh/07-operation/pic/explorer-06-sqlCreateDb.jpeg rename to docs/zh/08-operation/pic/explorer-06-sqlCreateDb.jpeg diff --git a/docs/zh/07-operation/pic/explorer-07-createDbtest02.jpeg b/docs/zh/08-operation/pic/explorer-07-createDbtest02.jpeg similarity index 100% rename from docs/zh/07-operation/pic/explorer-07-createDbtest02.jpeg rename to docs/zh/08-operation/pic/explorer-07-createDbtest02.jpeg diff --git a/docs/zh/07-operation/pic/explorer-08-createStbEntry.jpeg b/docs/zh/08-operation/pic/explorer-08-createStbEntry.jpeg similarity index 100% rename from docs/zh/07-operation/pic/explorer-08-createStbEntry.jpeg rename to docs/zh/08-operation/pic/explorer-08-createStbEntry.jpeg diff --git a/docs/zh/07-operation/pic/explorer-09-createStbPage.jpeg b/docs/zh/08-operation/pic/explorer-09-createStbPage.jpeg similarity index 100% rename from docs/zh/07-operation/pic/explorer-09-createStbPage.jpeg rename to docs/zh/08-operation/pic/explorer-09-createStbPage.jpeg diff --git a/docs/zh/07-operation/pic/explorer-10-createStbSucc.jpeg b/docs/zh/08-operation/pic/explorer-10-createStbSucc.jpeg similarity index 100% rename from docs/zh/07-operation/pic/explorer-10-createStbSucc.jpeg rename to docs/zh/08-operation/pic/explorer-10-createStbSucc.jpeg diff --git a/docs/zh/07-operation/pic/explorer-11-viewStableEntry.jpeg b/docs/zh/08-operation/pic/explorer-11-viewStableEntry.jpeg similarity index 100% rename from docs/zh/07-operation/pic/explorer-11-viewStableEntry.jpeg rename to docs/zh/08-operation/pic/explorer-11-viewStableEntry.jpeg diff --git a/docs/zh/07-operation/pic/explorer-12-viewStableInfo.jpeg b/docs/zh/08-operation/pic/explorer-12-viewStableInfo.jpeg similarity index 100% rename from docs/zh/07-operation/pic/explorer-12-viewStableInfo.jpeg rename to docs/zh/08-operation/pic/explorer-12-viewStableInfo.jpeg diff --git a/docs/zh/07-operation/pic/explorer-13-editStableEntry.jpeg b/docs/zh/08-operation/pic/explorer-13-editStableEntry.jpeg similarity index 100% rename from docs/zh/07-operation/pic/explorer-13-editStableEntry.jpeg rename to docs/zh/08-operation/pic/explorer-13-editStableEntry.jpeg diff --git a/docs/zh/07-operation/pic/explorer-14-editStableInfo.jpeg b/docs/zh/08-operation/pic/explorer-14-editStableInfo.jpeg similarity index 100% rename from docs/zh/07-operation/pic/explorer-14-editStableInfo.jpeg rename to docs/zh/08-operation/pic/explorer-14-editStableInfo.jpeg diff --git a/docs/zh/07-operation/pic/explorer-15-delStb.jpeg b/docs/zh/08-operation/pic/explorer-15-delStb.jpeg similarity index 100% rename from docs/zh/07-operation/pic/explorer-15-delStb.jpeg rename to docs/zh/08-operation/pic/explorer-15-delStb.jpeg diff --git a/docs/zh/07-operation/pic/explorer-16-sqlEditor.jpeg b/docs/zh/08-operation/pic/explorer-16-sqlEditor.jpeg similarity index 100% rename from docs/zh/07-operation/pic/explorer-16-sqlEditor.jpeg rename to docs/zh/08-operation/pic/explorer-16-sqlEditor.jpeg diff --git a/docs/zh/07-operation/pic/explorer-17-favoritesAdd.png b/docs/zh/08-operation/pic/explorer-17-favoritesAdd.png similarity index 100% rename from docs/zh/07-operation/pic/explorer-17-favoritesAdd.png rename to docs/zh/08-operation/pic/explorer-17-favoritesAdd.png diff --git a/docs/zh/07-operation/pic/explorer-18-favoritesAddPublic.png b/docs/zh/08-operation/pic/explorer-18-favoritesAddPublic.png similarity index 100% rename from docs/zh/07-operation/pic/explorer-18-favoritesAddPublic.png rename to docs/zh/08-operation/pic/explorer-18-favoritesAddPublic.png diff --git a/docs/zh/07-operation/pic/explorer-19-favoritesPublic.png b/docs/zh/08-operation/pic/explorer-19-favoritesPublic.png similarity index 100% rename from docs/zh/07-operation/pic/explorer-19-favoritesPublic.png rename to docs/zh/08-operation/pic/explorer-19-favoritesPublic.png diff --git a/docs/zh/07-operation/pic/explorer-20-favoritesCancelPublic.png b/docs/zh/08-operation/pic/explorer-20-favoritesCancelPublic.png similarity index 100% rename from docs/zh/07-operation/pic/explorer-20-favoritesCancelPublic.png rename to docs/zh/08-operation/pic/explorer-20-favoritesCancelPublic.png diff --git a/docs/zh/07-operation/pic/explorer-21-favoritesSearch.png b/docs/zh/08-operation/pic/explorer-21-favoritesSearch.png similarity index 100% rename from docs/zh/07-operation/pic/explorer-21-favoritesSearch.png rename to docs/zh/08-operation/pic/explorer-21-favoritesSearch.png diff --git a/docs/zh/07-operation/pic/explorer-22-favoritesDelete.png b/docs/zh/08-operation/pic/explorer-22-favoritesDelete.png similarity index 100% rename from docs/zh/07-operation/pic/explorer-22-favoritesDelete.png rename to docs/zh/08-operation/pic/explorer-22-favoritesDelete.png diff --git a/docs/zh/07-operation/pic/explorer-23-favoritesNotes.png b/docs/zh/08-operation/pic/explorer-23-favoritesNotes.png similarity index 100% rename from docs/zh/07-operation/pic/explorer-23-favoritesNotes.png rename to docs/zh/08-operation/pic/explorer-23-favoritesNotes.png diff --git a/docs/zh/07-operation/pic/management-01-importInfo.jpeg b/docs/zh/08-operation/pic/management-01-importInfo.jpeg similarity index 100% rename from docs/zh/07-operation/pic/management-01-importInfo.jpeg rename to docs/zh/08-operation/pic/management-01-importInfo.jpeg diff --git a/docs/zh/07-operation/pic/management-01-slowsql.jpeg b/docs/zh/08-operation/pic/management-01-slowsql.jpeg similarity index 100% rename from docs/zh/07-operation/pic/management-01-slowsql.jpeg rename to docs/zh/08-operation/pic/management-01-slowsql.jpeg diff --git a/docs/zh/07-operation/pic/management-01-systemEntry.jpeg b/docs/zh/08-operation/pic/management-01-systemEntry.jpeg similarity index 100% rename from docs/zh/07-operation/pic/management-01-systemEntry.jpeg rename to docs/zh/08-operation/pic/management-01-systemEntry.jpeg diff --git a/docs/zh/07-operation/pic/management-02-addUser.jpeg b/docs/zh/08-operation/pic/management-02-addUser.jpeg similarity index 100% rename from docs/zh/07-operation/pic/management-02-addUser.jpeg rename to docs/zh/08-operation/pic/management-02-addUser.jpeg diff --git a/docs/zh/07-operation/pic/management-02-addUserSucc.jpeg b/docs/zh/08-operation/pic/management-02-addUserSucc.jpeg similarity index 100% rename from docs/zh/07-operation/pic/management-02-addUserSucc.jpeg rename to docs/zh/08-operation/pic/management-02-addUserSucc.jpeg diff --git a/docs/zh/07-operation/pic/management-02-slowsql.jpeg b/docs/zh/08-operation/pic/management-02-slowsql.jpeg similarity index 100% rename from docs/zh/07-operation/pic/management-02-slowsql.jpeg rename to docs/zh/08-operation/pic/management-02-slowsql.jpeg diff --git a/docs/zh/07-operation/pic/management-04-backupEntry.jpeg b/docs/zh/08-operation/pic/management-04-backupEntry.jpeg similarity index 100% rename from docs/zh/07-operation/pic/management-04-backupEntry.jpeg rename to docs/zh/08-operation/pic/management-04-backupEntry.jpeg diff --git a/docs/zh/07-operation/pic/management-04-backupModal.jpeg b/docs/zh/08-operation/pic/management-04-backupModal.jpeg similarity index 100% rename from docs/zh/07-operation/pic/management-04-backupModal.jpeg rename to docs/zh/08-operation/pic/management-04-backupModal.jpeg diff --git a/docs/zh/07-operation/pic/management-06-cluster.jpeg b/docs/zh/08-operation/pic/management-06-cluster.jpeg similarity index 100% rename from docs/zh/07-operation/pic/management-06-cluster.jpeg rename to docs/zh/08-operation/pic/management-06-cluster.jpeg diff --git a/docs/zh/07-operation/pic/management-07-license.jpeg b/docs/zh/08-operation/pic/management-07-license.jpeg similarity index 100% rename from docs/zh/07-operation/pic/management-07-license.jpeg rename to docs/zh/08-operation/pic/management-07-license.jpeg diff --git a/docs/zh/07-operation/pic/management-08-activationCode.jpeg b/docs/zh/08-operation/pic/management-08-activationCode.jpeg similarity index 100% rename from docs/zh/07-operation/pic/management-08-activationCode.jpeg rename to docs/zh/08-operation/pic/management-08-activationCode.jpeg diff --git a/docs/zh/07-operation/pic/management-09-audit.jpeg b/docs/zh/08-operation/pic/management-09-audit.jpeg similarity index 100% rename from docs/zh/07-operation/pic/management-09-audit.jpeg rename to docs/zh/08-operation/pic/management-09-audit.jpeg diff --git a/docs/zh/07-operation/pic/management-10-replicationEntry.jpeg b/docs/zh/08-operation/pic/management-10-replicationEntry.jpeg similarity index 100% rename from docs/zh/07-operation/pic/management-10-replicationEntry.jpeg rename to docs/zh/08-operation/pic/management-10-replicationEntry.jpeg diff --git a/docs/zh/07-operation/pic/management-11-replicationModal.jpeg b/docs/zh/08-operation/pic/management-11-replicationModal.jpeg similarity index 100% rename from docs/zh/07-operation/pic/management-11-replicationModal.jpeg rename to docs/zh/08-operation/pic/management-11-replicationModal.jpeg diff --git a/docs/zh/07-operation/pic/management-12-licenseNew.jpeg b/docs/zh/08-operation/pic/management-12-licenseNew.jpeg similarity index 100% rename from docs/zh/07-operation/pic/management-12-licenseNew.jpeg rename to docs/zh/08-operation/pic/management-12-licenseNew.jpeg diff --git a/docs/zh/07-operation/pic/management-13-activationCodeNew.jpeg b/docs/zh/08-operation/pic/management-13-activationCodeNew.jpeg similarity index 100% rename from docs/zh/07-operation/pic/management-13-activationCodeNew.jpeg rename to docs/zh/08-operation/pic/management-13-activationCodeNew.jpeg diff --git a/docs/zh/07-operation/pic/monitor-01.jpg b/docs/zh/08-operation/pic/monitor-01.jpg similarity index 100% rename from docs/zh/07-operation/pic/monitor-01.jpg rename to docs/zh/08-operation/pic/monitor-01.jpg diff --git a/docs/zh/07-operation/pic/monitor-02.jpg b/docs/zh/08-operation/pic/monitor-02.jpg similarity index 100% rename from docs/zh/07-operation/pic/monitor-02.jpg rename to docs/zh/08-operation/pic/monitor-02.jpg diff --git a/docs/zh/07-operation/pic/monitor-03.png b/docs/zh/08-operation/pic/monitor-03.png similarity index 100% rename from docs/zh/07-operation/pic/monitor-03.png rename to docs/zh/08-operation/pic/monitor-03.png diff --git a/docs/zh/07-operation/pic/monitor-04.jpg b/docs/zh/08-operation/pic/monitor-04.jpg similarity index 100% rename from docs/zh/07-operation/pic/monitor-04.jpg rename to docs/zh/08-operation/pic/monitor-04.jpg diff --git a/docs/zh/07-operation/pic/monitor-05.png b/docs/zh/08-operation/pic/monitor-05.png similarity index 100% rename from docs/zh/07-operation/pic/monitor-05.png rename to docs/zh/08-operation/pic/monitor-05.png diff --git a/docs/zh/07-operation/pic/monitor-06.jpg b/docs/zh/08-operation/pic/monitor-06.jpg similarity index 100% rename from docs/zh/07-operation/pic/monitor-06.jpg rename to docs/zh/08-operation/pic/monitor-06.jpg diff --git a/docs/zh/07-operation/pic/monitor-07.png b/docs/zh/08-operation/pic/monitor-07.png similarity index 100% rename from docs/zh/07-operation/pic/monitor-07.png rename to docs/zh/08-operation/pic/monitor-07.png diff --git a/docs/zh/07-operation/pic/monitor-08.png b/docs/zh/08-operation/pic/monitor-08.png similarity index 100% rename from docs/zh/07-operation/pic/monitor-08.png rename to docs/zh/08-operation/pic/monitor-08.png diff --git a/docs/zh/07-operation/pic/monitor-09.jpg b/docs/zh/08-operation/pic/monitor-09.jpg similarity index 100% rename from docs/zh/07-operation/pic/monitor-09.jpg rename to docs/zh/08-operation/pic/monitor-09.jpg diff --git a/docs/zh/07-operation/pic/monitor-10.jpg b/docs/zh/08-operation/pic/monitor-10.jpg similarity index 100% rename from docs/zh/07-operation/pic/monitor-10.jpg rename to docs/zh/08-operation/pic/monitor-10.jpg diff --git a/docs/zh/07-operation/pic/stream-01-streamEntry.jpeg b/docs/zh/08-operation/pic/stream-01-streamEntry.jpeg similarity index 100% rename from docs/zh/07-operation/pic/stream-01-streamEntry.jpeg rename to docs/zh/08-operation/pic/stream-01-streamEntry.jpeg diff --git a/docs/zh/07-operation/pic/stream-02-createStreamEntry.jpeg b/docs/zh/08-operation/pic/stream-02-createStreamEntry.jpeg similarity index 100% rename from docs/zh/07-operation/pic/stream-02-createStreamEntry.jpeg rename to docs/zh/08-operation/pic/stream-02-createStreamEntry.jpeg diff --git a/docs/zh/07-operation/pic/stream-03-createStreamWizard.jpeg b/docs/zh/08-operation/pic/stream-03-createStreamWizard.jpeg similarity index 100% rename from docs/zh/07-operation/pic/stream-03-createStreamWizard.jpeg rename to docs/zh/08-operation/pic/stream-03-createStreamWizard.jpeg diff --git a/docs/zh/07-operation/pic/stream-04-createStreamWizard.jpeg b/docs/zh/08-operation/pic/stream-04-createStreamWizard.jpeg similarity index 100% rename from docs/zh/07-operation/pic/stream-04-createStreamWizard.jpeg rename to docs/zh/08-operation/pic/stream-04-createStreamWizard.jpeg diff --git a/docs/zh/07-operation/pic/stream-05-createStreamSucc1.jpeg b/docs/zh/08-operation/pic/stream-05-createStreamSucc1.jpeg similarity index 100% rename from docs/zh/07-operation/pic/stream-05-createStreamSucc1.jpeg rename to docs/zh/08-operation/pic/stream-05-createStreamSucc1.jpeg diff --git a/docs/zh/07-operation/pic/stream-06-createStreamSql.jpeg b/docs/zh/08-operation/pic/stream-06-createStreamSql.jpeg similarity index 100% rename from docs/zh/07-operation/pic/stream-06-createStreamSql.jpeg rename to docs/zh/08-operation/pic/stream-06-createStreamSql.jpeg diff --git a/docs/zh/07-operation/pic/stream-07-createStreamSucc2.jpeg b/docs/zh/08-operation/pic/stream-07-createStreamSucc2.jpeg similarity index 100% rename from docs/zh/07-operation/pic/stream-07-createStreamSucc2.jpeg rename to docs/zh/08-operation/pic/stream-07-createStreamSucc2.jpeg diff --git a/docs/zh/07-operation/pic/topic-01-dataSubscription.jpeg b/docs/zh/08-operation/pic/topic-01-dataSubscription.jpeg similarity index 100% rename from docs/zh/07-operation/pic/topic-01-dataSubscription.jpeg rename to docs/zh/08-operation/pic/topic-01-dataSubscription.jpeg diff --git a/docs/zh/07-operation/pic/topic-02-addTopic.jpeg b/docs/zh/08-operation/pic/topic-02-addTopic.jpeg similarity index 100% rename from docs/zh/07-operation/pic/topic-02-addTopic.jpeg rename to docs/zh/08-operation/pic/topic-02-addTopic.jpeg diff --git a/docs/zh/07-operation/pic/topic-03-addTopicWizard.jpeg b/docs/zh/08-operation/pic/topic-03-addTopicWizard.jpeg similarity index 100% rename from docs/zh/07-operation/pic/topic-03-addTopicWizard.jpeg rename to docs/zh/08-operation/pic/topic-03-addTopicWizard.jpeg diff --git a/docs/zh/07-operation/pic/topic-05-addTopicSucc1.jpeg b/docs/zh/08-operation/pic/topic-05-addTopicSucc1.jpeg similarity index 100% rename from docs/zh/07-operation/pic/topic-05-addTopicSucc1.jpeg rename to docs/zh/08-operation/pic/topic-05-addTopicSucc1.jpeg diff --git a/docs/zh/07-operation/pic/topic-06-addTopicSql.jpeg b/docs/zh/08-operation/pic/topic-06-addTopicSql.jpeg similarity index 100% rename from docs/zh/07-operation/pic/topic-06-addTopicSql.jpeg rename to docs/zh/08-operation/pic/topic-06-addTopicSql.jpeg diff --git a/docs/zh/07-operation/pic/topic-07-addTopicsSucc2.jpeg b/docs/zh/08-operation/pic/topic-07-addTopicsSucc2.jpeg similarity index 100% rename from docs/zh/07-operation/pic/topic-07-addTopicsSucc2.jpeg rename to docs/zh/08-operation/pic/topic-07-addTopicsSucc2.jpeg diff --git a/docs/zh/07-operation/pic/topic-08-shareTopic.jpeg b/docs/zh/08-operation/pic/topic-08-shareTopic.jpeg similarity index 100% rename from docs/zh/07-operation/pic/topic-08-shareTopic.jpeg rename to docs/zh/08-operation/pic/topic-08-shareTopic.jpeg diff --git a/docs/zh/07-operation/pic/topic-09-sample.jpeg b/docs/zh/08-operation/pic/topic-09-sample.jpeg similarity index 100% rename from docs/zh/07-operation/pic/topic-09-sample.jpeg rename to docs/zh/08-operation/pic/topic-09-sample.jpeg diff --git a/docs/zh/07-operation/pic/topic-10-consumer.jpeg b/docs/zh/08-operation/pic/topic-10-consumer.jpeg similarity index 100% rename from docs/zh/07-operation/pic/topic-10-consumer.jpeg rename to docs/zh/08-operation/pic/topic-10-consumer.jpeg diff --git a/docs/zh/08-operation/tdengine-topology.png b/docs/zh/08-operation/tdengine-topology.png new file mode 100644 index 0000000000..f31443ef7f Binary files /dev/null and b/docs/zh/08-operation/tdengine-topology.png differ diff --git a/docs/zh/20-third-party/01-collection/02-prometheus.md b/docs/zh/10-third-party/01-collection/02-prometheus.md similarity index 100% rename from docs/zh/20-third-party/01-collection/02-prometheus.md rename to docs/zh/10-third-party/01-collection/02-prometheus.md diff --git a/docs/zh/20-third-party/01-collection/03-telegraf.md b/docs/zh/10-third-party/01-collection/03-telegraf.md similarity index 100% rename from docs/zh/20-third-party/01-collection/03-telegraf.md rename to docs/zh/10-third-party/01-collection/03-telegraf.md diff --git a/docs/zh/20-third-party/01-collection/05-collectd.md b/docs/zh/10-third-party/01-collection/05-collectd.md similarity index 100% rename from docs/zh/20-third-party/01-collection/05-collectd.md rename to docs/zh/10-third-party/01-collection/05-collectd.md diff --git a/docs/zh/20-third-party/01-collection/06-statsd.md b/docs/zh/10-third-party/01-collection/06-statsd.md similarity index 100% rename from docs/zh/20-third-party/01-collection/06-statsd.md rename to docs/zh/10-third-party/01-collection/06-statsd.md diff --git a/docs/zh/20-third-party/01-collection/07-icinga2.md b/docs/zh/10-third-party/01-collection/07-icinga2.md similarity index 100% rename from docs/zh/20-third-party/01-collection/07-icinga2.md rename to docs/zh/10-third-party/01-collection/07-icinga2.md diff --git a/docs/zh/20-third-party/01-collection/08-tcollector.md b/docs/zh/10-third-party/01-collection/08-tcollector.md similarity index 100% rename from docs/zh/20-third-party/01-collection/08-tcollector.md rename to docs/zh/10-third-party/01-collection/08-tcollector.md diff --git a/docs/zh/20-third-party/01-collection/09-emq-broker.md b/docs/zh/10-third-party/01-collection/09-emq-broker.md similarity index 100% rename from docs/zh/20-third-party/01-collection/09-emq-broker.md rename to docs/zh/10-third-party/01-collection/09-emq-broker.md diff --git a/docs/zh/20-third-party/01-collection/10-hive-mq-broker.md b/docs/zh/10-third-party/01-collection/10-hive-mq-broker.md similarity index 100% rename from docs/zh/20-third-party/01-collection/10-hive-mq-broker.md rename to docs/zh/10-third-party/01-collection/10-hive-mq-broker.md diff --git a/docs/zh/20-third-party/01-collection/11-kafka.md b/docs/zh/10-third-party/01-collection/11-kafka.md similarity index 84% rename from docs/zh/20-third-party/01-collection/11-kafka.md rename to docs/zh/10-third-party/01-collection/11-kafka.md index d9a416aa40..75adefbc50 100644 --- a/docs/zh/20-third-party/01-collection/11-kafka.md +++ b/docs/zh/10-third-party/01-collection/11-kafka.md @@ -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 topic,topic的命名规则 ``;如果设置为 false,则指定的 DB 中的所有数据进入一个 Kafka topic,topic 的命名规则为 `` -9. `topic.ignore.db`: topic 命名规则是否包含 database 名称,true 表示规则为 ``,false 表示规则为 ``,默认 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 topic,topic的命名规则 ``;如果设置为 false,则指定的 DB 中的所有数据进入一个 Kafka topic,topic 的命名规则为 `` +10. `topic.ignore.db`: topic 命名规则是否包含 database 名称,true 表示规则为 ``,false 表示规则为 ``,默认 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。 ## 其他说明 diff --git a/docs/zh/20-third-party/01-collection/emqx/add-action-handler.webp b/docs/zh/10-third-party/01-collection/emqx/add-action-handler.webp similarity index 100% rename from docs/zh/20-third-party/01-collection/emqx/add-action-handler.webp rename to docs/zh/10-third-party/01-collection/emqx/add-action-handler.webp diff --git a/docs/zh/20-third-party/01-collection/emqx/check-result-in-taos.webp b/docs/zh/10-third-party/01-collection/emqx/check-result-in-taos.webp similarity index 100% rename from docs/zh/20-third-party/01-collection/emqx/check-result-in-taos.webp rename to docs/zh/10-third-party/01-collection/emqx/check-result-in-taos.webp diff --git a/docs/zh/20-third-party/01-collection/emqx/check-rule-matched.webp b/docs/zh/10-third-party/01-collection/emqx/check-rule-matched.webp similarity index 100% rename from docs/zh/20-third-party/01-collection/emqx/check-rule-matched.webp rename to docs/zh/10-third-party/01-collection/emqx/check-rule-matched.webp diff --git a/docs/zh/20-third-party/01-collection/emqx/client-num.webp b/docs/zh/10-third-party/01-collection/emqx/client-num.webp similarity index 100% rename from docs/zh/20-third-party/01-collection/emqx/client-num.webp rename to docs/zh/10-third-party/01-collection/emqx/client-num.webp diff --git a/docs/zh/20-third-party/01-collection/emqx/create-resource.webp b/docs/zh/10-third-party/01-collection/emqx/create-resource.webp similarity index 100% rename from docs/zh/20-third-party/01-collection/emqx/create-resource.webp rename to docs/zh/10-third-party/01-collection/emqx/create-resource.webp diff --git a/docs/zh/20-third-party/01-collection/emqx/create-rule.webp b/docs/zh/10-third-party/01-collection/emqx/create-rule.webp similarity index 100% rename from docs/zh/20-third-party/01-collection/emqx/create-rule.webp rename to docs/zh/10-third-party/01-collection/emqx/create-rule.webp diff --git a/docs/zh/20-third-party/01-collection/emqx/edit-action.webp b/docs/zh/10-third-party/01-collection/emqx/edit-action.webp similarity index 100% rename from docs/zh/20-third-party/01-collection/emqx/edit-action.webp rename to docs/zh/10-third-party/01-collection/emqx/edit-action.webp diff --git a/docs/zh/20-third-party/01-collection/emqx/edit-resource.webp b/docs/zh/10-third-party/01-collection/emqx/edit-resource.webp similarity index 100% rename from docs/zh/20-third-party/01-collection/emqx/edit-resource.webp rename to docs/zh/10-third-party/01-collection/emqx/edit-resource.webp diff --git a/docs/zh/20-third-party/01-collection/emqx/login-dashboard.webp b/docs/zh/10-third-party/01-collection/emqx/login-dashboard.webp similarity index 100% rename from docs/zh/20-third-party/01-collection/emqx/login-dashboard.webp rename to docs/zh/10-third-party/01-collection/emqx/login-dashboard.webp diff --git a/docs/zh/20-third-party/01-collection/emqx/rule-engine.webp b/docs/zh/10-third-party/01-collection/emqx/rule-engine.webp similarity index 100% rename from docs/zh/20-third-party/01-collection/emqx/rule-engine.webp rename to docs/zh/10-third-party/01-collection/emqx/rule-engine.webp diff --git a/docs/zh/20-third-party/01-collection/emqx/rule-header-key-value.webp b/docs/zh/10-third-party/01-collection/emqx/rule-header-key-value.webp similarity index 100% rename from docs/zh/20-third-party/01-collection/emqx/rule-header-key-value.webp rename to docs/zh/10-third-party/01-collection/emqx/rule-header-key-value.webp diff --git a/docs/zh/20-third-party/01-collection/emqx/run-mock.webp b/docs/zh/10-third-party/01-collection/emqx/run-mock.webp similarity index 100% rename from docs/zh/20-third-party/01-collection/emqx/run-mock.webp rename to docs/zh/10-third-party/01-collection/emqx/run-mock.webp diff --git a/docs/zh/20-third-party/01-collection/index.md b/docs/zh/10-third-party/01-collection/index.md similarity index 100% rename from docs/zh/20-third-party/01-collection/index.md rename to docs/zh/10-third-party/01-collection/index.md diff --git a/docs/zh/20-third-party/01-collection/kafka/Kafka_Connect.webp b/docs/zh/10-third-party/01-collection/kafka/Kafka_Connect.webp similarity index 100% rename from docs/zh/20-third-party/01-collection/kafka/Kafka_Connect.webp rename to docs/zh/10-third-party/01-collection/kafka/Kafka_Connect.webp diff --git a/docs/zh/20-third-party/01-collection/kafka/confluentPlatform.webp b/docs/zh/10-third-party/01-collection/kafka/confluentPlatform.webp similarity index 100% rename from docs/zh/20-third-party/01-collection/kafka/confluentPlatform.webp rename to docs/zh/10-third-party/01-collection/kafka/confluentPlatform.webp diff --git a/docs/zh/20-third-party/01-collection/kafka/streaming-integration-with-kafka-connect.webp b/docs/zh/10-third-party/01-collection/kafka/streaming-integration-with-kafka-connect.webp similarity index 100% rename from docs/zh/20-third-party/01-collection/kafka/streaming-integration-with-kafka-connect.webp rename to docs/zh/10-third-party/01-collection/kafka/streaming-integration-with-kafka-connect.webp diff --git a/docs/zh/20-third-party/03-visual/01-grafana.mdx b/docs/zh/10-third-party/03-visual/01-grafana.mdx similarity index 100% rename from docs/zh/20-third-party/03-visual/01-grafana.mdx rename to docs/zh/10-third-party/03-visual/01-grafana.mdx diff --git a/docs/zh/20-third-party/03-visual/add_datasource1.webp b/docs/zh/10-third-party/03-visual/add_datasource1.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/add_datasource1.webp rename to docs/zh/10-third-party/03-visual/add_datasource1.webp diff --git a/docs/zh/20-third-party/03-visual/add_datasource2.webp b/docs/zh/10-third-party/03-visual/add_datasource2.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/add_datasource2.webp rename to docs/zh/10-third-party/03-visual/add_datasource2.webp diff --git a/docs/zh/20-third-party/03-visual/add_datasource3.webp b/docs/zh/10-third-party/03-visual/add_datasource3.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/add_datasource3.webp rename to docs/zh/10-third-party/03-visual/add_datasource3.webp diff --git a/docs/zh/20-third-party/03-visual/add_datasource4.webp b/docs/zh/10-third-party/03-visual/add_datasource4.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/add_datasource4.webp rename to docs/zh/10-third-party/03-visual/add_datasource4.webp diff --git a/docs/zh/20-third-party/03-visual/alert-annotations.webp b/docs/zh/10-third-party/03-visual/alert-annotations.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/alert-annotations.webp rename to docs/zh/10-third-party/03-visual/alert-annotations.webp diff --git a/docs/zh/20-third-party/03-visual/alert-email.webp b/docs/zh/10-third-party/03-visual/alert-email.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/alert-email.webp rename to docs/zh/10-third-party/03-visual/alert-email.webp diff --git a/docs/zh/20-third-party/03-visual/alert-evaluation.webp b/docs/zh/10-third-party/03-visual/alert-evaluation.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/alert-evaluation.webp rename to docs/zh/10-third-party/03-visual/alert-evaluation.webp diff --git a/docs/zh/20-third-party/03-visual/alert-feishu1.webp b/docs/zh/10-third-party/03-visual/alert-feishu1.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/alert-feishu1.webp rename to docs/zh/10-third-party/03-visual/alert-feishu1.webp diff --git a/docs/zh/20-third-party/03-visual/alert-feishu2.webp b/docs/zh/10-third-party/03-visual/alert-feishu2.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/alert-feishu2.webp rename to docs/zh/10-third-party/03-visual/alert-feishu2.webp diff --git a/docs/zh/20-third-party/03-visual/alert-labels.webp b/docs/zh/10-third-party/03-visual/alert-labels.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/alert-labels.webp rename to docs/zh/10-third-party/03-visual/alert-labels.webp diff --git a/docs/zh/20-third-party/03-visual/alert-notification1.webp b/docs/zh/10-third-party/03-visual/alert-notification1.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/alert-notification1.webp rename to docs/zh/10-third-party/03-visual/alert-notification1.webp diff --git a/docs/zh/20-third-party/03-visual/alert-notification2.webp b/docs/zh/10-third-party/03-visual/alert-notification2.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/alert-notification2.webp rename to docs/zh/10-third-party/03-visual/alert-notification2.webp diff --git a/docs/zh/20-third-party/03-visual/alert-rules1.webp b/docs/zh/10-third-party/03-visual/alert-rules1.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/alert-rules1.webp rename to docs/zh/10-third-party/03-visual/alert-rules1.webp diff --git a/docs/zh/20-third-party/03-visual/create_dashboard1.webp b/docs/zh/10-third-party/03-visual/create_dashboard1.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/create_dashboard1.webp rename to docs/zh/10-third-party/03-visual/create_dashboard1.webp diff --git a/docs/zh/20-third-party/03-visual/create_dashboard2.webp b/docs/zh/10-third-party/03-visual/create_dashboard2.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/create_dashboard2.webp rename to docs/zh/10-third-party/03-visual/create_dashboard2.webp diff --git a/docs/zh/20-third-party/03-visual/create_dashboard3.webp b/docs/zh/10-third-party/03-visual/create_dashboard3.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/create_dashboard3.webp rename to docs/zh/10-third-party/03-visual/create_dashboard3.webp diff --git a/docs/zh/20-third-party/03-visual/dashboard-15146.webp b/docs/zh/10-third-party/03-visual/dashboard-15146.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/dashboard-15146.webp rename to docs/zh/10-third-party/03-visual/dashboard-15146.webp diff --git a/docs/zh/20-third-party/03-visual/grafana-data-source.png b/docs/zh/10-third-party/03-visual/grafana-data-source.png similarity index 100% rename from docs/zh/20-third-party/03-visual/grafana-data-source.png rename to docs/zh/10-third-party/03-visual/grafana-data-source.png diff --git a/docs/zh/20-third-party/03-visual/grafana-install-and-config.png b/docs/zh/10-third-party/03-visual/grafana-install-and-config.png similarity index 100% rename from docs/zh/20-third-party/03-visual/grafana-install-and-config.png rename to docs/zh/10-third-party/03-visual/grafana-install-and-config.png diff --git a/docs/zh/20-third-party/03-visual/grafana-plugin-search-tdengine.png b/docs/zh/10-third-party/03-visual/grafana-plugin-search-tdengine.png similarity index 100% rename from docs/zh/20-third-party/03-visual/grafana-plugin-search-tdengine.png rename to docs/zh/10-third-party/03-visual/grafana-plugin-search-tdengine.png diff --git a/docs/zh/20-third-party/03-visual/import_dashboard.webp b/docs/zh/10-third-party/03-visual/import_dashboard.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/import_dashboard.webp rename to docs/zh/10-third-party/03-visual/import_dashboard.webp diff --git a/docs/zh/20-third-party/03-visual/import_dashboard1.webp b/docs/zh/10-third-party/03-visual/import_dashboard1.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/import_dashboard1.webp rename to docs/zh/10-third-party/03-visual/import_dashboard1.webp diff --git a/docs/zh/20-third-party/03-visual/import_dashboard2.webp b/docs/zh/10-third-party/03-visual/import_dashboard2.webp similarity index 100% rename from docs/zh/20-third-party/03-visual/import_dashboard2.webp rename to docs/zh/10-third-party/03-visual/import_dashboard2.webp diff --git a/docs/zh/20-third-party/03-visual/index.md b/docs/zh/10-third-party/03-visual/index.md similarity index 100% rename from docs/zh/20-third-party/03-visual/index.md rename to docs/zh/10-third-party/03-visual/index.md diff --git a/docs/zh/20-third-party/05-bi/01-looker.md b/docs/zh/10-third-party/05-bi/01-looker.md similarity index 100% rename from docs/zh/20-third-party/05-bi/01-looker.md rename to docs/zh/10-third-party/05-bi/01-looker.md diff --git a/docs/zh/20-third-party/05-bi/03-powerbi.md b/docs/zh/10-third-party/05-bi/03-powerbi.md similarity index 80% rename from docs/zh/20-third-party/05-bi/03-powerbi.md rename to docs/zh/10-third-party/05-bi/03-powerbi.md index f4709da447..bd51b5591d 100644 --- a/docs/zh/20-third-party/05-bi/03-powerbi.md +++ b/docs/zh/10-third-party/05-bi/03-powerbi.md @@ -8,35 +8,35 @@ Power BI是由Microsoft提供的一种商业分析工具。通过配置使用ODB ## 前置条件 -安装完成Power BI Desktop软件并运行(如未安装,请从其官方地址下载最新的Windows操作系统X64版本)。 +安装完成Power BI Desktop软件并运行(如未安装,请从其官方地址下载最新的Windows操作系统 32/64 位版本)。 ## 安装 ODBC 驱动 -从TDengine官网下载最新的Windows操作系统X64客户端驱动程序,并安装在运行Power BI的机器上。安装成功后可在“ODBC数据源(64位)”管理工具中看到 TAOS_ODBC_DSN”驱动程序。 +从TDengine官网下载最新的Windows操作系统X64客户端驱动程序,并安装在运行Power BI的机器上。安装成功后可在“ODBC数据源(32位)”或者“ODBC数据源(64位)”管理工具中看到 TDengine 驱动程序。 ## 配置ODBC数据源 配置ODBC数据源的操作步骤如下。 -第1步,在Windows操作系统的开始菜单中搜索并打开“ODBC数据源(64位)”管理工具。 -第2步,点击“用户DSN”选项卡→“添加”按钮,进入“创建新数据源”对话框。 -第3步,选择想要添加的数据源后选择“TDengine”,点击“完成”按钮,进入TDengine ODBC数据源配置页面。填写如下必要信息。 +第1步,在Windows操作系统的开始菜单中搜索并打开“ODBC数据源(32位)”或者“ODBC数据源(64位)”管理工具。 +第2步,点击“用户DSN”选项卡→“添加”按钮,进入“创建新数据源”对话框。 +第3步,在“选择您想为其安装数据源的驱动程序”列表中选择“TDengine”,点击“完成”按钮,进入TDengine ODBC数据源配置页面。填写如下必要信息。 - DSN:数据源名称,必填,比如“MyTDengine”。 - 连接类型:勾选“WebSocket”复选框。 - - 服务地址:输入“taos://127.0.0.1:6041”。 + - URL:ODBC 数据源 URL,必填,比如“http://127.0.0.1:6041”。 - 数据库:表示需要连接的数据库,可选,比如“test”。 - 用户名:输入用户名,如果不填,默认为“root”。 - - 密码:输入用户密码,如果不填,默认为“taosdata”。 -第4步,点击“测试连接”按钮,测试连接情况,如果成功连接,则会提示“成功连接到taos://root:taosdata@127.0.0.1:6041”。 + - 密码:输入用户密码,如果不填,默认为“taosdata”。 + +第4步,点击“测试连接”按钮,测试连接情况,如果成功连接,则会提示“成功连接到http://127.0.0.1:6041”。 第5步,点击“确定”按钮,即可保存配置并退出。 ## 导入TDengine数据到Power BI -将TDengine数据导入Power BI的操作步骤如下。 - -第1步,打开Power BI并登录后,点击“主页”→“获取数据”→“其他”→“ODBC”→“连接”,添加数据源。 -第2步,选择刚才创建的数据源名称,比如“MyTDengine”,点击“确定”按钮。在弹出的“ODBC驱动程序”对话框中,在左侧导航栏中点击“默认或自定义”→“连接”按钮,即可连接到配置好的数据源。进入“导航器”后,可以浏览对应数据库的数据表并加载。 -第3步,如果需要输入SQL,则可以点击“高级选项”选项卡,在展开的对话框中输入并加载数据。 +将TDengine数据导入Power BI的操作步骤如下: +第1步,打开Power BI并登录后,点击“主页”→“获取数据”→“其他”→“ODBC”→“连接”,添加数据源。 +第2步,选择刚才创建的数据源名称,比如“MyTDengine”,如果需要输入SQL,则可以点击“高级选项”选项卡,在展开的对话框的编辑框中输入SQL语句。点击“确定”按钮,即可连接到配置好的数据源。 +第3步,进入“导航器”后,可以浏览对应数据库的数据表/视图并加载数据。 为了充分发挥Power BI在分析TDengine中数据方面的优势,用户需要先理解维度、度量、窗口切分查询、数据切分查询、时序和相关性等核心概念,之后通过自定义的SQL导入数据。 - 维度:通常是分类(文本)数据,描述设备、测点、型号等类别信息。在TDengine的超级表中,使用标签列存储数据的维度信息,可以通过形如“select distinct tbname, tag1, tag2 from supertable”的SQL语法快速获得维度信息。 @@ -54,25 +54,25 @@ TDengine采用了一种独特的数据模型,以优化时序数据的存储和 在Power BI中,用户可以将TDengine表中的标签列映射为维度列,以便对数据进行分组和筛选。同时,数据列的聚合结果可以导入为度量列,用于计算关键指标和生成报表。通过这种方式,Power BI能够帮助决策者快速获取所需的信息,深入了解业务运营情况,从而制定更加明智的决策。 -根据如下步骤,便可以体验通过Power BI生成时序数据报表的功能。 +根据如下步骤,便可以体验通过Power BI生成时序数据报表的功能。 第1步,使用TDengine的taosBenchMark快速生成1000块智能电表3天的数据,采集频率为1s。 ```shell - taosBenchmark-t1000-n259200-S1000-H200-y + taosBenchmark -t 1000 -n 259200 -S 1000 -y ``` 第2步,导入维度数据。在Power BI中导入表的标签列,取名为tags,通过如下SQL获取超级表下所有智能电表的标签数据。 ```sql - selectdistincttbnamedevice,groupId,locationfromtest.meters + select distinct tbname device, groupId, location from test.meters ``` 第3步,导入度量数据。在Power BI中,按照1小时的时间窗口,导入每块智能电表的电流均值、电压均值、相位均值,取名为data,SQL如下。 ```sql - 第3步,导入度量数据。在Power BI中,按照1小时的时间窗口,导入每块智能电表的电流均值、电压均值、相位均值,取名为data,SQL如下。 + select tbname, _wstart ws, avg(current), avg(voltage), avg(phase) from test.meters PARTITION by tbname interval(1h) ``` 第4步,导入日期数据。按照1天的时间窗口,获得时序数据的时间范围及数据计数,SQL如下。需要在Power Query编辑器中将date列的格式从“文本”转化为“日期”。 ```sql - select_wstartdate,count(*)fromtest.metersinterval(1d)havingcount(*)>0 + select _wstart date, count(*) from test.meters interval(1d) having count(*)>0 ``` -第5步,建立维度和度量的关联关系。打开模型视图,建立表tags和data的关联关系,将tbname设置为关联数据列。 -第6步,建立日期和度量的关联关系。打开模型视图,建立数据集date和data的关联关系,关联的数据列为date和datatime。 -第7步,制作报告。在柱状图、饼图等控件中使用这些数据。 +第5步,建立维度和度量的关联关系。打开模型视图,建立表tags和data的关联关系,将tbname设置为关联数据列。 +第6步,建立日期和度量的关联关系。打开模型视图,建立数据集date和data的关联关系,关联的数据列为date和datatime。 +第7步,制作报告。在柱状图、饼图等控件中使用这些数据。 由于TDengine处理时序数据的超强性能,使得用户在数据导入及每日定期刷新数据时,都可以得到非常好的体验。更多有关Power BI视觉效果的构建方法,请参照Power BI的官方文档。 \ No newline at end of file diff --git a/docs/zh/20-third-party/05-bi/05-yhbi.md b/docs/zh/10-third-party/05-bi/05-yhbi.md similarity index 100% rename from docs/zh/20-third-party/05-bi/05-yhbi.md rename to docs/zh/10-third-party/05-bi/05-yhbi.md diff --git a/docs/zh/20-third-party/05-bi/09-seeq.md b/docs/zh/10-third-party/05-bi/09-seeq.md similarity index 100% rename from docs/zh/20-third-party/05-bi/09-seeq.md rename to docs/zh/10-third-party/05-bi/09-seeq.md diff --git a/docs/zh/20-third-party/05-bi/gds/gds-01.webp b/docs/zh/10-third-party/05-bi/gds/gds-01.webp similarity index 100% rename from docs/zh/20-third-party/05-bi/gds/gds-01.webp rename to docs/zh/10-third-party/05-bi/gds/gds-01.webp diff --git a/docs/zh/20-third-party/05-bi/gds/gds-02.png.webp b/docs/zh/10-third-party/05-bi/gds/gds-02.png.webp similarity index 100% rename from docs/zh/20-third-party/05-bi/gds/gds-02.png.webp rename to docs/zh/10-third-party/05-bi/gds/gds-02.png.webp diff --git a/docs/zh/20-third-party/05-bi/gds/gds-03.png.webp b/docs/zh/10-third-party/05-bi/gds/gds-03.png.webp similarity index 100% rename from docs/zh/20-third-party/05-bi/gds/gds-03.png.webp rename to docs/zh/10-third-party/05-bi/gds/gds-03.png.webp diff --git a/docs/zh/20-third-party/05-bi/gds/gds-04.png.webp b/docs/zh/10-third-party/05-bi/gds/gds-04.png.webp similarity index 100% rename from docs/zh/20-third-party/05-bi/gds/gds-04.png.webp rename to docs/zh/10-third-party/05-bi/gds/gds-04.png.webp diff --git a/docs/zh/20-third-party/05-bi/gds/gds-05.png.webp b/docs/zh/10-third-party/05-bi/gds/gds-05.png.webp similarity index 100% rename from docs/zh/20-third-party/05-bi/gds/gds-05.png.webp rename to docs/zh/10-third-party/05-bi/gds/gds-05.png.webp diff --git a/docs/zh/20-third-party/05-bi/gds/gds-06.png.webp b/docs/zh/10-third-party/05-bi/gds/gds-06.png.webp similarity index 100% rename from docs/zh/20-third-party/05-bi/gds/gds-06.png.webp rename to docs/zh/10-third-party/05-bi/gds/gds-06.png.webp diff --git a/docs/zh/20-third-party/05-bi/gds/gds-07.png.webp b/docs/zh/10-third-party/05-bi/gds/gds-07.png.webp similarity index 100% rename from docs/zh/20-third-party/05-bi/gds/gds-07.png.webp rename to docs/zh/10-third-party/05-bi/gds/gds-07.png.webp diff --git a/docs/zh/20-third-party/05-bi/gds/gds-08.png.webp b/docs/zh/10-third-party/05-bi/gds/gds-08.png.webp similarity index 100% rename from docs/zh/20-third-party/05-bi/gds/gds-08.png.webp rename to docs/zh/10-third-party/05-bi/gds/gds-08.png.webp diff --git a/docs/zh/20-third-party/05-bi/gds/gds-09.png.webp b/docs/zh/10-third-party/05-bi/gds/gds-09.png.webp similarity index 100% rename from docs/zh/20-third-party/05-bi/gds/gds-09.png.webp rename to docs/zh/10-third-party/05-bi/gds/gds-09.png.webp diff --git a/docs/zh/20-third-party/05-bi/gds/gds-10.png.webp b/docs/zh/10-third-party/05-bi/gds/gds-10.png.webp similarity index 100% rename from docs/zh/20-third-party/05-bi/gds/gds-10.png.webp rename to docs/zh/10-third-party/05-bi/gds/gds-10.png.webp diff --git a/docs/zh/20-third-party/05-bi/gds/gds-11.png.webp b/docs/zh/10-third-party/05-bi/gds/gds-11.png.webp similarity index 100% rename from docs/zh/20-third-party/05-bi/gds/gds-11.png.webp rename to docs/zh/10-third-party/05-bi/gds/gds-11.png.webp diff --git a/docs/zh/20-third-party/05-bi/index.md b/docs/zh/10-third-party/05-bi/index.md similarity index 100% rename from docs/zh/20-third-party/05-bi/index.md rename to docs/zh/10-third-party/05-bi/index.md diff --git a/docs/zh/20-third-party/05-bi/seeq/seeq-demo-schema.webp b/docs/zh/10-third-party/05-bi/seeq/seeq-demo-schema.webp similarity index 100% rename from docs/zh/20-third-party/05-bi/seeq/seeq-demo-schema.webp rename to docs/zh/10-third-party/05-bi/seeq/seeq-demo-schema.webp diff --git a/docs/zh/20-third-party/05-bi/seeq/seeq-demo-workbench.webp b/docs/zh/10-third-party/05-bi/seeq/seeq-demo-workbench.webp similarity index 100% rename from docs/zh/20-third-party/05-bi/seeq/seeq-demo-workbench.webp rename to docs/zh/10-third-party/05-bi/seeq/seeq-demo-workbench.webp diff --git a/docs/zh/20-third-party/05-bi/seeq/seeq-forecast-result.webp b/docs/zh/10-third-party/05-bi/seeq/seeq-forecast-result.webp similarity index 100% rename from docs/zh/20-third-party/05-bi/seeq/seeq-forecast-result.webp rename to docs/zh/10-third-party/05-bi/seeq/seeq-forecast-result.webp diff --git a/docs/zh/20-third-party/05-bi/seeq/seeq-workbench-with-tdengine-cloud.webp b/docs/zh/10-third-party/05-bi/seeq/seeq-workbench-with-tdengine-cloud.webp similarity index 100% rename from docs/zh/20-third-party/05-bi/seeq/seeq-workbench-with-tdengine-cloud.webp rename to docs/zh/10-third-party/05-bi/seeq/seeq-workbench-with-tdengine-cloud.webp diff --git a/docs/zh/20-third-party/07-tool/01-dbeaver.md b/docs/zh/10-third-party/07-tool/01-dbeaver.md similarity index 100% rename from docs/zh/20-third-party/07-tool/01-dbeaver.md rename to docs/zh/10-third-party/07-tool/01-dbeaver.md diff --git a/docs/zh/20-third-party/07-tool/03-qstudio.md b/docs/zh/10-third-party/07-tool/03-qstudio.md similarity index 100% rename from docs/zh/20-third-party/07-tool/03-qstudio.md rename to docs/zh/10-third-party/07-tool/03-qstudio.md diff --git a/docs/zh/20-third-party/07-tool/dbeaver/dbeaver-browse-cloud-data-zh.webp b/docs/zh/10-third-party/07-tool/dbeaver/dbeaver-browse-cloud-data-zh.webp similarity index 100% rename from docs/zh/20-third-party/07-tool/dbeaver/dbeaver-browse-cloud-data-zh.webp rename to docs/zh/10-third-party/07-tool/dbeaver/dbeaver-browse-cloud-data-zh.webp diff --git a/docs/zh/20-third-party/07-tool/dbeaver/dbeaver-browse-data-zh.webp b/docs/zh/10-third-party/07-tool/dbeaver/dbeaver-browse-data-zh.webp similarity index 100% rename from docs/zh/20-third-party/07-tool/dbeaver/dbeaver-browse-data-zh.webp rename to docs/zh/10-third-party/07-tool/dbeaver/dbeaver-browse-data-zh.webp diff --git a/docs/zh/20-third-party/07-tool/dbeaver/dbeaver-config-tdengine-zh.webp b/docs/zh/10-third-party/07-tool/dbeaver/dbeaver-config-tdengine-zh.webp similarity index 100% rename from docs/zh/20-third-party/07-tool/dbeaver/dbeaver-config-tdengine-zh.webp rename to docs/zh/10-third-party/07-tool/dbeaver/dbeaver-config-tdengine-zh.webp diff --git a/docs/zh/20-third-party/07-tool/dbeaver/dbeaver-connect-tdengine-cloud-test-zh.webp b/docs/zh/10-third-party/07-tool/dbeaver/dbeaver-connect-tdengine-cloud-test-zh.webp similarity index 100% rename from docs/zh/20-third-party/07-tool/dbeaver/dbeaver-connect-tdengine-cloud-test-zh.webp rename to docs/zh/10-third-party/07-tool/dbeaver/dbeaver-connect-tdengine-cloud-test-zh.webp diff --git a/docs/zh/20-third-party/07-tool/dbeaver/dbeaver-connect-tdengine-cloud-zh.webp b/docs/zh/10-third-party/07-tool/dbeaver/dbeaver-connect-tdengine-cloud-zh.webp similarity index 100% rename from docs/zh/20-third-party/07-tool/dbeaver/dbeaver-connect-tdengine-cloud-zh.webp rename to docs/zh/10-third-party/07-tool/dbeaver/dbeaver-connect-tdengine-cloud-zh.webp diff --git a/docs/zh/20-third-party/07-tool/dbeaver/dbeaver-connect-tdengine-test-zh.webp b/docs/zh/10-third-party/07-tool/dbeaver/dbeaver-connect-tdengine-test-zh.webp similarity index 100% rename from docs/zh/20-third-party/07-tool/dbeaver/dbeaver-connect-tdengine-test-zh.webp rename to docs/zh/10-third-party/07-tool/dbeaver/dbeaver-connect-tdengine-test-zh.webp diff --git a/docs/zh/20-third-party/07-tool/dbeaver/dbeaver-connect-tdengine-zh.webp b/docs/zh/10-third-party/07-tool/dbeaver/dbeaver-connect-tdengine-zh.webp similarity index 100% rename from docs/zh/20-third-party/07-tool/dbeaver/dbeaver-connect-tdengine-zh.webp rename to docs/zh/10-third-party/07-tool/dbeaver/dbeaver-connect-tdengine-zh.webp diff --git a/docs/zh/20-third-party/07-tool/dbeaver/dbeaver-sql-execution-cloud-zh.webp b/docs/zh/10-third-party/07-tool/dbeaver/dbeaver-sql-execution-cloud-zh.webp similarity index 100% rename from docs/zh/20-third-party/07-tool/dbeaver/dbeaver-sql-execution-cloud-zh.webp rename to docs/zh/10-third-party/07-tool/dbeaver/dbeaver-sql-execution-cloud-zh.webp diff --git a/docs/zh/20-third-party/07-tool/dbeaver/dbeaver-sql-execution-zh.webp b/docs/zh/10-third-party/07-tool/dbeaver/dbeaver-sql-execution-zh.webp similarity index 100% rename from docs/zh/20-third-party/07-tool/dbeaver/dbeaver-sql-execution-zh.webp rename to docs/zh/10-third-party/07-tool/dbeaver/dbeaver-sql-execution-zh.webp diff --git a/docs/zh/20-third-party/07-tool/dbeaver/tdengine-cloud-jdbc-dsn-zh.webp b/docs/zh/10-third-party/07-tool/dbeaver/tdengine-cloud-jdbc-dsn-zh.webp similarity index 100% rename from docs/zh/20-third-party/07-tool/dbeaver/tdengine-cloud-jdbc-dsn-zh.webp rename to docs/zh/10-third-party/07-tool/dbeaver/tdengine-cloud-jdbc-dsn-zh.webp diff --git a/docs/zh/20-third-party/07-tool/index.md b/docs/zh/10-third-party/07-tool/index.md similarity index 72% rename from docs/zh/20-third-party/07-tool/index.md rename to docs/zh/10-third-party/07-tool/index.md index 7142e7d425..d7959d48ab 100644 --- a/docs/zh/20-third-party/07-tool/index.md +++ b/docs/zh/10-third-party/07-tool/index.md @@ -1,6 +1,6 @@ --- -sidebar_label: 管理开发 -title: 与各种管理开发工具的集成 +sidebar_label: 数据库管理 +title: 与各种数据库管理开发工具的集成 toc_max_heading_level: 4 --- diff --git a/docs/zh/20-third-party/07-tool/qstudio/qstudio-browse-data.webp b/docs/zh/10-third-party/07-tool/qstudio/qstudio-browse-data.webp similarity index 100% rename from docs/zh/20-third-party/07-tool/qstudio/qstudio-browse-data.webp rename to docs/zh/10-third-party/07-tool/qstudio/qstudio-browse-data.webp diff --git a/docs/zh/20-third-party/07-tool/qstudio/qstudio-chart.webp b/docs/zh/10-third-party/07-tool/qstudio/qstudio-chart.webp similarity index 100% rename from docs/zh/20-third-party/07-tool/qstudio/qstudio-chart.webp rename to docs/zh/10-third-party/07-tool/qstudio/qstudio-chart.webp diff --git a/docs/zh/20-third-party/07-tool/qstudio/qstudio-connect-tdengine-test.webp b/docs/zh/10-third-party/07-tool/qstudio/qstudio-connect-tdengine-test.webp similarity index 100% rename from docs/zh/20-third-party/07-tool/qstudio/qstudio-connect-tdengine-test.webp rename to docs/zh/10-third-party/07-tool/qstudio/qstudio-connect-tdengine-test.webp diff --git a/docs/zh/20-third-party/07-tool/qstudio/qstudio-connect-tdengine.webp b/docs/zh/10-third-party/07-tool/qstudio/qstudio-connect-tdengine.webp similarity index 100% rename from docs/zh/20-third-party/07-tool/qstudio/qstudio-connect-tdengine.webp rename to docs/zh/10-third-party/07-tool/qstudio/qstudio-connect-tdengine.webp diff --git a/docs/zh/20-third-party/07-tool/qstudio/qstudio-jdbc-connector-download.webp b/docs/zh/10-third-party/07-tool/qstudio/qstudio-jdbc-connector-download.webp similarity index 100% rename from docs/zh/20-third-party/07-tool/qstudio/qstudio-jdbc-connector-download.webp rename to docs/zh/10-third-party/07-tool/qstudio/qstudio-jdbc-connector-download.webp diff --git a/docs/zh/20-third-party/07-tool/qstudio/qstudio-sql-execution.webp b/docs/zh/10-third-party/07-tool/qstudio/qstudio-sql-execution.webp similarity index 100% rename from docs/zh/20-third-party/07-tool/qstudio/qstudio-sql-execution.webp rename to docs/zh/10-third-party/07-tool/qstudio/qstudio-sql-execution.webp diff --git a/docs/zh/20-third-party/_75-powerbi.md b/docs/zh/10-third-party/_75-powerbi.md similarity index 100% rename from docs/zh/20-third-party/_75-powerbi.md rename to docs/zh/10-third-party/_75-powerbi.md diff --git a/docs/zh/20-third-party/_76-yonghongbi.md b/docs/zh/10-third-party/_76-yonghongbi.md similarity index 100% rename from docs/zh/20-third-party/_76-yonghongbi.md rename to docs/zh/10-third-party/_76-yonghongbi.md diff --git a/docs/zh/20-third-party/_deploytaosadapter.mdx b/docs/zh/10-third-party/_deploytaosadapter.mdx similarity index 100% rename from docs/zh/20-third-party/_deploytaosadapter.mdx rename to docs/zh/10-third-party/_deploytaosadapter.mdx diff --git a/docs/zh/20-third-party/index.md b/docs/zh/10-third-party/index.md similarity index 100% rename from docs/zh/20-third-party/index.md rename to docs/zh/10-third-party/index.md diff --git a/docs/zh/20-third-party/powerbi-step-zh.png b/docs/zh/10-third-party/powerbi-step-zh.png similarity index 100% rename from docs/zh/20-third-party/powerbi-step-zh.png rename to docs/zh/10-third-party/powerbi-step-zh.png diff --git a/docs/zh/20-third-party/yonghongbi-step-zh.png b/docs/zh/10-third-party/yonghongbi-step-zh.png similarity index 100% rename from docs/zh/20-third-party/yonghongbi-step-zh.png rename to docs/zh/10-third-party/yonghongbi-step-zh.png diff --git a/docs/zh/14-reference/01-components/01-taosd.md b/docs/zh/14-reference/01-components/01-taosd.md index ff6b27092d..fbf086bf6b 100644 --- a/docs/zh/14-reference/01-components/01-taosd.md +++ b/docs/zh/14-reference/01-components/01-taosd.md @@ -33,7 +33,6 @@ taosd 命令行参数如下 | secondEp | taosd 启动时,如果 firstEp 连接不上,尝试连接集群中第二个 dnode 的 endpoint,缺省值:无 | | fqdn | 启动 taosd 后所监听的服务地址,缺省值:所在服务器上配置的第一个 hostname | | serverPort | 启动 taosd 后所监听的端口,缺省值:6030 | -| maxShellConns | 一个 dnode 容许的连接数,取值范围为 10-5000000,缺省值:5000 | | numOfRpcSessions | 允许一个客户端能创建的最大连接数,取值范围 100-100000,缺省值:30000 | | timeToGetAvailableConn | 获得可用连接的最长等待时间,取值范围 10-50000000,单位为毫秒,缺省值:500000 | @@ -433,3 +432,30 @@ taosd 会将监控指标上报给 taosKeeper,这些监控指标会被 taosKeep | duration | VARCHAR | TAG | sql执行耗时,取值范围:3-10s,10-100s,100-1000s,1000s- | | cluster\_id | VARCHAR | TAG | cluster id | +## 日志相关 + +TDengine 通过日志文件记录系统运行状态,帮助用户监控系统运行情况,排查问题,这里主要介绍 taosc 和 taosd 两个系统日志的相关说明。 + +TDengine 的日志文件主要包括普通日志和慢日志两种类型。 + +1. 普通日志行为说明 + 1. 同一台机器上可以起多个客户端进程,所以客户端日志命名方式为 taoslogX.Y,其中 X 为序号,为空或者 0 到 9,Y 为后缀 0 或者 1。 + 2. 同一台机器上只能有一个服务端进程。所以服务端日志命名方式为 taosdlog.Y,其中 Y 为后缀, 0 或者 1。 + + 序号和后缀确定规则如下(假设日志路径为 /var/log/taos/): + 1. 确定序号:使用 10 个序号作为日志命名方式,/var/log/taos/taoslog0.Y - /var/log/taos/taoslog9.Y,依次检测每个序号是否使用,找到第一个没使用的序号作为该进程的日志文件使用的序号。 如果 10 个序号都被进程使用,不使用序号,即 /var/log/taos/taoslog.Y,进程都往相同的文件里写(序号为空)。 + 2. 确定后缀:0 或者 1。比如确定序号为 3,备选的日志文件名就为 /var/log/taos/taoslog3.0 /var/log/taos/taoslog3.1。如果两个文件都不存在用后缀 0,一个存在一个不存在,用存在的后缀。两个都存在,用修改时间最近的那个后缀。 + 3. 如果日志文件超过配置的条数 numOfLogLines,会切换后缀名,继续写日志,比如/var/log/taos/taoslog3.0 写够了,切换到 /var/log/taos/taoslog3.1 继续写日志。/var/log/taos/taoslog3.0 会添加时间戳后缀重命名并压缩存储(异步线程操作)。 + 4. 通过配置 logKeepDays 控制日志文件保存几天,几天之外的日志会被删除。比如配置为 1,则一天之前的日志会在新日志压缩存储时检测删除。不是自然天。 + +系统除了记录普通日志以外,对于执行时间超过配置时间的 SQL 语句,会被记录到慢日志中。慢日志文件主要用于分析系统性能,排查性能问题。 + +2. 慢日志行为说明 + 1. 慢日志一方面会记录到本地慢日志文件中,另一方面会通过 taosAdapter 发送到 taosKeeper 进行结构化存储(需打开 monitorr 开关)。 + 2. 慢日志文件存储规则为: + 1. 慢日志文件一天一个,如果当天没有慢日志,没有当天的文件。 + 2. 文件名为 taosSlowLog.yyyy-mm-dd(taosSlowLog.2024-08-02),日志存储路径通过 logDir 配置。 + 3. 多个客户端的日志存储在相应日志路径下的同一个 taosSlowLog.yyyy.mm.dd 文件里。 + 4. 慢日志文件不自动删除,不压缩。 + 5. 使用和普通日志文件相同的三个参数 logDir, minimalLogDirGB, asyncLog。另外两个参数 numOfLogLines,logKeepDays 不适用于慢日志。 + \ No newline at end of file diff --git a/docs/zh/14-reference/01-components/08-taos-cli.md b/docs/zh/14-reference/02-tools/08-taos-cli.md similarity index 99% rename from docs/zh/14-reference/01-components/08-taos-cli.md rename to docs/zh/14-reference/02-tools/08-taos-cli.md index 3eea24ac7b..c388e7edda 100644 --- a/docs/zh/14-reference/01-components/08-taos-cli.md +++ b/docs/zh/14-reference/02-tools/08-taos-cli.md @@ -82,7 +82,7 @@ taos -h h1.taos.com -s "use db; show tables;" ## 配置文件 -也可以通过配置文件中的参数设置来控制 TDengine CLI 的行为。可用配置参数请参考[客户端配置](../taosc) +也可以通过配置文件中的参数设置来控制 TDengine CLI 的行为。可用配置参数请参考[客户端配置](../../components/taosc) ## TDengine CLI 小技巧 diff --git a/docs/zh/14-reference/01-components/09-taosdump.md b/docs/zh/14-reference/02-tools/09-taosdump.md similarity index 100% rename from docs/zh/14-reference/01-components/09-taosdump.md rename to docs/zh/14-reference/02-tools/09-taosdump.md diff --git a/docs/zh/14-reference/01-components/10-taosbenchmark.md b/docs/zh/14-reference/02-tools/10-taosbenchmark.md similarity index 100% rename from docs/zh/14-reference/01-components/10-taosbenchmark.md rename to docs/zh/14-reference/02-tools/10-taosbenchmark.md diff --git a/docs/zh/14-reference/02-tools/index.md b/docs/zh/14-reference/02-tools/index.md new file mode 100644 index 0000000000..37ed3a460e --- /dev/null +++ b/docs/zh/14-reference/02-tools/index.md @@ -0,0 +1,13 @@ +--- +title: 工具 +description: TDengine 工具 +--- + +本节详细说明 TDengine 中的主要工具的功能和用法。 + +```mdx-code-block +import DocCardList from '@theme/DocCardList'; +import {useCurrentSidebarCategory} from '@docusaurus/theme-common'; + + +``` \ No newline at end of file diff --git a/docs/zh/14-reference/03-taos-sql/20-keywords.md b/docs/zh/14-reference/03-taos-sql/20-keywords.md index 4d2454ed5a..1ef0d07e14 100644 --- a/docs/zh/14-reference/03-taos-sql/20-keywords.md +++ b/docs/zh/14-reference/03-taos-sql/20-keywords.md @@ -131,6 +131,7 @@ description: TDengine 保留关键字的详细列表 ### H - HAVING +- HOST ### I diff --git a/docs/zh/14-reference/05-connector/14-java.mdx b/docs/zh/14-reference/05-connector/14-java.mdx index ec24f1329d..ba4cb38afd 100644 --- a/docs/zh/14-reference/05-connector/14-java.mdx +++ b/docs/zh/14-reference/05-connector/14-java.mdx @@ -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 | - | diff --git a/docs/zh/14-reference/05-connector/20-go.mdx b/docs/zh/14-reference/05-connector/20-go.mdx index 8d65fba321..61048f7b85 100644 --- a/docs/zh/14-reference/05-connector/20-go.mdx +++ b/docs/zh/14-reference/05-connector/20-go.mdx @@ -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) ## 常见问题 diff --git a/docs/zh/14-reference/05-connector/26-rust.mdx b/docs/zh/14-reference/05-connector/26-rust.mdx index 88be297ac6..c5d2a165d4 100644 --- a/docs/zh/14-reference/05-connector/26-rust.mdx +++ b/docs/zh/14-reference/05-connector/26-rust.mdx @@ -80,6 +80,8 @@ TDengine 目前支持时间戳、数字、字符、布尔类型,与 Rust 对 | BINARY | Vec\ | | NCHAR | String | | JSON | serde_json::Value | +| VARBINARY | Bytes | +| GEOMETRY | Bytes | **注意**:JSON 类型仅在 tag 中支持。 diff --git a/docs/zh/14-reference/05-connector/30-python.mdx b/docs/zh/14-reference/05-connector/30-python.mdx index 1a805c692e..8e08bfc103 100644 --- a/docs/zh/14-reference/05-connector/30-python.mdx +++ b/docs/zh/14-reference/05-connector/30-python.mdx @@ -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) diff --git a/docs/zh/14-reference/05-connector/35-node.mdx b/docs/zh/14-reference/05-connector/35-node.mdx index a3d5099235..3d8e82086e 100644 --- a/docs/zh/14-reference/05-connector/35-node.mdx +++ b/docs/zh/14-reference/05-connector/35-node.mdx @@ -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) | 参数绑定支持全部类型示例。 | ## 使用限制 diff --git a/docs/zh/14-reference/05-connector/40-csharp.mdx b/docs/zh/14-reference/05-connector/40-csharp.mdx index 3cfb14b21e..93f592fdd0 100644 --- a/docs/zh/14-reference/05-connector/40-csharp.mdx +++ b/docs/zh/14-reference/05-connector/40-csharp.mdx @@ -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 参考 diff --git a/docs/zh/14-reference/05-connector/43-r-lang.mdx b/docs/zh/14-reference/05-connector/43-r-lang.mdx index e8929e5ca0..13734dec8c 100644 --- a/docs/zh/14-reference/05-connector/43-r-lang.mdx +++ b/docs/zh/14-reference/05-connector/43-r-lang.mdx @@ -7,7 +7,7 @@ title: R Language Connector import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; -import Rdemo from "../../08-develop/01-connect/_connect_r.mdx" +import Rdemo from "../../07-develop/01-connect/_connect_r.mdx" 通过 R 语言中的 RJDBC 库可以使 R 语言程序支持访问 TDengine 数据。以下是安装过程、配置过程以及 R 语言示例代码。 diff --git a/docs/zh/14-reference/05-connector/50-odbc.mdx b/docs/zh/14-reference/05-connector/50-odbc.mdx index 244a3f8d4e..ee69cf9364 100644 --- a/docs/zh/14-reference/05-connector/50-odbc.mdx +++ b/docs/zh/14-reference/05-connector/50-odbc.mdx @@ -3,11 +3,11 @@ sidebar_label: ODBC title: TDengine ODBC --- -TDengine ODBC 是为 TDengine 实现的 ODBC 驱动程序,支持 Windows 系统的应用(如 [PowerBI](https://powerbi.microsoft.com/zh-cn/) 等)通过 ODBC 标准接口访问本地、远程和云服务的 TDengine 数据库。 +TDengine ODBC 是为 TDengine 实现的 ODBC 驱动程序,支持 Windows 系统的应用(如 [PowerBI](https://powerbi.microsoft.com/zh-cn/) 等)通过 ODBC 标准接口访问本地、远程和云服务的 TDengine 数据库的数据表/视图。 TDengine ODBC 提供基于 WebSocket(推荐)和 原生连接两种方式连接 TDengine 数据库,使用时可以为 TDengine 数据源设置不同的连接方式。访问云服务时必须使用 WebSocket 连接方式。 -注意:TDengine ODBC 只支持 64 位系统,调用 TDengine ODBC 必须通过 64 位的 ODBC 驱动管理器进行。因此调用 ODBC 的程序不能使用 32 位版本。 +注意:TDengine ODBC 支持 32/64 位 Windows 系统,调用 TDengine ODBC 需要通过相应位数的 ODBC 驱动管理器进行。在 32 位 Windows 系统或者 64 位 Windows 系统的 32 位应用程序中,仅支持使用 WebSocket 连接方式访问 TDengine 数据库。 想更多了解 TDengine 时序时序数据库的使用,可访问 [TDengine官方文档](https://docs.taosdata.com/intro/)。 @@ -18,7 +18,7 @@ TDengine ODBC 提供基于 WebSocket(推荐)和 原生连接两种方式连 1. 仅支持 Windows 平台。Windows 上需要安装过 VC 运行时库,可在此下载安装 [VC运行时库](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170) 如果已经安装VS开发工具可忽略。 -2. 安装 TDengine Windows 客户端,版本在 3.2.1.0 或以上,都会包含 TDengine 的 ODBC 驱动。 +2. 安装 TDengine Windows 客户端。版本在 3.2.1.0 或以上,包含 TDengine 的 ODBC 64 位驱动;版本在 3.3.3.0 或以上,包含 TDengine 的 ODBC 32/64 位驱动。 ## 配置数据源 @@ -26,17 +26,19 @@ TDengine ODBC 提供基于 WebSocket(推荐)和 原生连接两种方式连 TDengine ODBC 支持两种连接 TDengine 数据库方式:Websocket 连接与 Native 连接,其区别如下: -1. 只有 Websocket 支持连接云服务 +1. 访问云服务仅支持使用 Websocket 连接方式。 -2. Websocket 连接的兼容性更好,一般不需要随着 TDengine 数据库服务端升级而升级客户端的库。 +2. 32 位应用程序仅支持使用 WebSocket 连接方式。 -3. Native 连接通常性能更好一点,但是必须与 TDengine 数据库服务端的版本保持一致。 +3. Websocket 连接的兼容性更好,一般不需要随着 TDengine 数据库服务端升级而升级客户端的库。 -4. 对于一般用户,建议使用 **Websocket** 连接方式,性能与 Native 差别不大,兼容性更好。 +4. Native 连接通常性能更好一点,但是必须与 TDengine 数据库服务端的版本保持一致。 + +5. 对于一般用户,建议使用 **Websocket** 连接方式,性能与 Native 差别不大,兼容性更好。 ### WebSocket 连接 -1. 【开始】菜单搜索打开【ODBC 数据源(64 位)】管理工具(注意不要选择ODBC 数据源(32 位)) +1. 【开始】菜单搜索打开【ODBC 数据源(32 位)】或者【ODBC 数据源(64 位)】管理工具 2. 选中【用户 DSN】标签页,通过【添加(D)】按钮进入"创建数据源"界面 @@ -64,7 +66,7 @@ TDengine ODBC 支持两种连接 TDengine 数据库方式:Websocket 连接与 7. 也可以在第2步选择已经配置好的数据源名通过【配置】按钮进入配置页面,修改已有配置 -### 原生连接(不支持云服务) +### 原生连接(不支持云服务和 32 位应用程序) 1. 【开始】菜单搜索打开【ODBC 数据源(64 位)】管理工具(注意不要选择ODBC 数据源(32 位)) diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index 1179e710cd..004a3a8fb8 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -115,8 +115,8 @@ typedef struct { } SValueColumnCompressInfo; int32_t tValueColumnInit(SValueColumn *valCol); -int32_t tValueColumnDestroy(SValueColumn *valCol); -int32_t tValueColumnClear(SValueColumn *valCol); +void tValueColumnDestroy(SValueColumn *valCol); +void tValueColumnClear(SValueColumn *valCol); int32_t tValueColumnAppend(SValueColumn *valCol, const SValue *value); int32_t tValueColumnUpdate(SValueColumn *valCol, int32_t idx, const SValue *value); int32_t tValueColumnGet(SValueColumn *valCol, int32_t idx, SValue *value); diff --git a/include/common/tmsg.h b/include/common/tmsg.h index fc56f30db2..d4ad2dc0ad 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -463,6 +463,7 @@ typedef enum ENodeType { typedef struct { int32_t vgId; + uint8_t option; // 0x0 REQ_OPT_TBNAME, 0x01 REQ_OPT_TBUID const char* dbFName; const char* tbName; } SBuildTableInput; @@ -1460,6 +1461,7 @@ typedef struct { int32_t walFsyncPeriod; int16_t hashPrefix; int16_t hashSuffix; + int8_t hashMethod; int8_t walLevel; int8_t precision; int8_t compression; @@ -2045,10 +2047,13 @@ typedef struct { int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq); int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq); +#define REQ_OPT_TBNAME 0x0 +#define REQ_OPT_TBUID 0x01 typedef struct { SMsgHead header; char dbFName[TSDB_DB_FNAME_LEN]; char tbName[TSDB_TABLE_NAME_LEN]; + uint8_t option; } STableInfoReq; int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq); diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 572e26bc62..40464dc29a 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -309,6 +309,7 @@ TD_DEF_MSG_TYPE(TDMT_VND_ARB_HEARTBEAT, "vnode-arb-hb", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_ARB_CHECK_SYNC, "vnode-arb-check-sync", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_FETCH_TTL_EXPIRED_TBS, "vnode-fetch-ttl-expired-tbs", NULL, NULL) + TD_DEF_MSG_TYPE(TDMT_VND_TABLE_NAME, "vnode-table-name", NULL, NULL) TD_CLOSE_MSG_SEG(TDMT_VND_MSG) TD_NEW_MSG_SEG(TDMT_SCH_MSG) // 3<<8 diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 1f205b3f11..4abf8c27fd 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -119,9 +119,9 @@ void mndPostProcessQueryMsg(SRpcMsg *pMsg); */ void mndGenerateMachineCode(); -void mndDumpSdb(); +int32_t mndDumpSdb(); -void mndDeleteTrans(); +int32_t mndDeleteTrans(); #ifdef __cplusplus } diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index 11ed7c7da6..df3f87973f 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -96,6 +96,7 @@ typedef struct SCatalogReq { SArray* pView; // element is STablesReq SArray* pTableTSMAs; // element is STablesReq SArray* pTSMAs; // element is STablesReq + SArray* pTableName; // element is STablesReq bool qNodeRequired; // valid qnode bool dNodeRequired; // valid dnode bool svrVerRequired; @@ -417,6 +418,8 @@ int32_t catalogGetTsma(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTs int32_t catalogAsyncUpdateDbTsmaVersion(SCatalog* pCtg, int32_t tsmaVersion, const char* dbFName, int64_t dbId); +int32_t ctgHashValueComp(void const* lp, void const* rp); + /** * Destroy catalog and relase all resources */ diff --git a/include/libs/function/function.h b/include/libs/function/function.h index a71a2a6b7f..ec01cf1f6f 100644 --- a/include/libs/function/function.h +++ b/include/libs/function/function.h @@ -258,6 +258,7 @@ typedef struct SqlFunctionCtx { SFuncInputRowIter rowIter; bool bInputFinished; bool hasWindowOrGroup; // denote that the function is used with time window or group + bool needCleanup; // denote that the function need to be cleaned up } SqlFunctionCtx; typedef struct tExprNode { diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 21de2eff9a..2a18e800b8 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -240,6 +240,7 @@ typedef struct SDropTableStmt { ENodeType type; SNodeList* pTables; bool withTsma; + bool withOpt; } SDropTableStmt; typedef struct SDropSuperTableStmt { @@ -247,6 +248,7 @@ typedef struct SDropSuperTableStmt { char dbName[TSDB_DB_NAME_LEN]; char tableName[TSDB_TABLE_NAME_LEN]; bool ignoreNotExists; + bool withOpt; } SDropSuperTableStmt; typedef struct SAlterTableStmt { diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index 1b02203c07..5f9a4a1110 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -57,7 +57,6 @@ typedef struct SExprNode { char aliasName[TSDB_COL_NAME_LEN]; char userAlias[TSDB_COL_NAME_LEN]; SArray* pAssociation; - bool orderAlias; bool asAlias; bool asParam; bool asPosition; diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index c8c4fcad44..bcb1aa90d1 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -330,6 +330,7 @@ int32_t getAsofJoinReverseOp(EOperatorType op); int32_t queryCreateCTableMetaFromMsg(STableMetaRsp* msg, SCTableMeta* pMeta); int32_t queryCreateTableMetaFromMsg(STableMetaRsp* msg, bool isSuperTable, STableMeta** pMeta); +int32_t queryCreateTableMetaExFromMsg(STableMetaRsp* msg, bool isSuperTable, STableMeta** pMeta); char* jobTaskStatusStr(int32_t status); SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* name); diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h index 5a2cf3a3a0..74ab0bf484 100644 --- a/include/libs/wal/wal.h +++ b/include/libs/wal/wal.h @@ -177,7 +177,7 @@ int32_t walRollback(SWal *, int64_t ver); int32_t walBeginSnapshot(SWal *, int64_t ver, int64_t logRetention); int32_t walEndSnapshot(SWal *); int32_t walRestoreFromSnapshot(SWal *, int64_t ver); -int32_t walApplyVer(SWal *, int64_t ver); +void walApplyVer(SWal *, int64_t ver); // wal reader SWalReader *walOpenReader(SWal *, SWalFilterCond *pCond, int64_t id); diff --git a/include/util/tcompression.h b/include/util/tcompression.h index cea648a3a6..182465548b 100644 --- a/include/util/tcompression.h +++ b/include/util/tcompression.h @@ -268,7 +268,7 @@ typedef struct { uint8_t lvl[3]; // l[0] = 'low', l[1] = 'mid', l[2] = 'high' } TCmprLvlSet; -int32_t tcompressDebug(uint32_t cmprAlg, uint8_t *l1Alg, uint8_t *l2Alg, uint8_t *level); +void tcompressDebug(uint32_t cmprAlg, uint8_t *l1Alg, uint8_t *l2Alg, uint8_t *level); #define DEFINE_VAR(cmprAlg) \ uint8_t l1 = COMPRESS_L1_TYPE_U32(cmprAlg); \ diff --git a/include/util/tutil.h b/include/util/tutil.h index 6a8f58e360..87710b091d 100644 --- a/include/util/tutil.h +++ b/include/util/tutil.h @@ -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); \ diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 1c0be6b3ac..5b559451da 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -37,7 +37,6 @@ void setQueryRequest(int64_t rId) { pReq->isQuery = true; (void)releaseRequest(rId); } - } static bool stringLengthCheck(const char* str, size_t maxsize) { @@ -2245,7 +2244,7 @@ static int32_t doConvertJson(SReqResultInfo* pResultInfo, int32_t numOfCols, int } else if (tTagIsJson(data)) { char* jsonString = NULL; parseTagDatatoJson(data, &jsonString); - if(jsonString == NULL) { + if (jsonString == NULL) { tscError("doConvertJson error: parseTagDatatoJson failed"); return terrno; } @@ -2517,10 +2516,10 @@ TSDB_SERVER_STATUS taos_check_server_status(const char* fqdn, int port, char* de void* clientRpc = NULL; SServerStatusRsp statusRsp = {0}; SEpSet epSet = {.inUse = 0, .numOfEps = 1}; - SRpcMsg rpcMsg = {.info.ahandle = (void*)0x9526, .msgType = TDMT_DND_SERVER_STATUS}; - SRpcMsg rpcRsp = {0}; - SRpcInit rpcInit = {0}; - char pass[TSDB_PASSWORD_LEN + 1] = {0}; + SRpcMsg rpcMsg = {.info.ahandle = (void*)0x9527, .info.notFreeAhandle = 1, .msgType = TDMT_DND_SERVER_STATUS}; + SRpcMsg rpcRsp = {0}; + SRpcInit rpcInit = {0}; + char pass[TSDB_PASSWORD_LEN + 1] = {0}; rpcInit.label = "CHK"; rpcInit.numOfThreads = 1; @@ -2896,6 +2895,10 @@ TAOS_RES* taosQueryImpl(TAOS* taos, const char* sql, bool validateOnly, int8_t s taosMemoryFree(param); return NULL; } + code = tsem_destroy(¶m->sem); + if(TSDB_CODE_SUCCESS != code) { + tscError("failed to destroy semaphore since %s", tstrerror(code)); + } SRequestObj* pRequest = NULL; if (param->pRequest != NULL) { @@ -3032,7 +3035,8 @@ void taosAsyncFetchImpl(SRequestObj* pRequest, __taos_async_fn_t fp, void* param void doRequestCallback(SRequestObj* pRequest, int32_t code) { pRequest->inCallback = true; int64_t this = pRequest->self; - if (tsQueryTbNotExistAsEmpty && TD_RES_QUERY(&pRequest->resType) && pRequest->isQuery && (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_TDB_TABLE_NOT_EXIST)) { + if (tsQueryTbNotExistAsEmpty && TD_RES_QUERY(&pRequest->resType) && pRequest->isQuery && + (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_TDB_TABLE_NOT_EXIST)) { code = TSDB_CODE_SUCCESS; pRequest->type = TSDB_SQL_RETRIEVE_EMPTY_RESULT; } diff --git a/source/client/src/clientMonitor.c b/source/client/src/clientMonitor.c index 4c1a484c20..f424e4d1a2 100644 --- a/source/client/src/clientMonitor.c +++ b/source/client/src/clientMonitor.c @@ -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,10 +215,9 @@ 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); - if (!reset){ - tscError("failed to reset timer, pMonitor:%p", pMonitor); - } + bool reset = + taosTmrReset(reportSendProcess, pInst->monitorParas.tsMonitorInterval * 1000, param, monitorTimer, &tmrId); + tscDebug("reset timer, pMonitor:%p, %d", pMonitor, reset); taosRUnLockLatch(&monitorLock); } @@ -267,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; } @@ -320,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; @@ -328,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; @@ -396,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; @@ -408,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); @@ -637,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; } @@ -730,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; @@ -751,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); } } @@ -833,7 +832,7 @@ static int32_t tscMonitortInit() { static void tscMonitorStop() { if (taosCheckPthreadValid(monitorThread)) { (void)taosThreadJoin(monitorThread, NULL); - (void)taosThreadClear(&monitorThread); + taosThreadClear(&monitorThread); } } @@ -899,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); @@ -923,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 { diff --git a/source/client/src/clientRawBlockWrite.c b/source/client/src/clientRawBlockWrite.c index 8a888a2a47..a1022cf12a 100644 --- a/source/client/src/clientRawBlockWrite.c +++ b/source/client/src/clientRawBlockWrite.c @@ -361,7 +361,7 @@ static void processCreateStb(SMqMetaRsp* metaRsp, cJSON** pJson) { buildCreateTableJson(&req.schemaRow, &req.schemaTag, req.name, req.suid, TSDB_SUPER_TABLE, &req.colCmpr, pJson); end: - uDebug("create stable return, sql json:%s", cJSON_PrintUnformatted(*pJson)); + uDebug("create stable return"); tDecoderClear(&coder); } @@ -381,7 +381,7 @@ static void processAlterStb(SMqMetaRsp* metaRsp, cJSON** pJson) { buildAlterSTableJson(req.alterOriData, req.alterOriDataLen, pJson); end: - uDebug("alter stable return, sql json:%s", cJSON_PrintUnformatted(*pJson)); + uDebug("alter stable return"); tDecoderClear(&coder); } @@ -393,7 +393,7 @@ static void buildChildElement(cJSON* json, SVCreateTbReq* pCreateReq) { int64_t id = pCreateReq->uid; uint8_t tagNum = pCreateReq->ctb.tagNum; int32_t code = 0; - + cJSON* tags = NULL; cJSON* tableName = cJSON_CreateString(name); RAW_NULL_CHECK(tableName); RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tableName", tableName)); @@ -404,7 +404,7 @@ static void buildChildElement(cJSON* json, SVCreateTbReq* pCreateReq) { RAW_NULL_CHECK(tagNumJson); RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tagNum", tagNumJson)); - cJSON* tags = cJSON_CreateArray(); + tags = cJSON_CreateArray(); RAW_NULL_CHECK(tags); SArray* pTagVals = NULL; RAW_RETURN_CHECK(tTagToValArray(pTag, &pTagVals)); @@ -543,7 +543,7 @@ static void processCreateTable(SMqMetaRsp* metaRsp, cJSON** pJson) { } end: - uDebug("create table return, sql json:%s", cJSON_PrintUnformatted(*pJson)); + uDebug("create table return"); tDeleteSVCreateTbBatchReq(&req); tDecoderClear(&decoder); } @@ -772,7 +772,7 @@ static void processAlterTable(SMqMetaRsp* metaRsp, cJSON** pJson) { } end: - uDebug("alter table return, sql json:%s", cJSON_PrintUnformatted(json)); + uDebug("alter table return"); tDecoderClear(&decoder); *pJson = json; } @@ -807,7 +807,7 @@ static void processDropSTable(SMqMetaRsp* metaRsp, cJSON** pJson) { RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tableName", tableName)); end: - uDebug("processDropSTable return, sql json:%s", cJSON_PrintUnformatted(json)); + uDebug("processDropSTable return"); tDecoderClear(&decoder); *pJson = json; } @@ -843,7 +843,7 @@ static void processDeleteTable(SMqMetaRsp* metaRsp, cJSON** pJson) { RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "sql", sqlJson)); end: - uDebug("processDeleteTable return, sql json:%s", cJSON_PrintUnformatted(json)); + uDebug("processDeleteTable return"); tDecoderClear(&coder); *pJson = json; } @@ -880,7 +880,7 @@ static void processDropTable(SMqMetaRsp* metaRsp, cJSON** pJson) { RAW_FALSE_CHECK(cJSON_AddItemToObject(json, "tableNameList", tableNameList)); end: - uDebug("processDropTable return, json sql:%s", cJSON_PrintUnformatted(json)); + uDebug("processDropTable return"); tDecoderClear(&decoder); *pJson = json; } @@ -1923,6 +1923,10 @@ static int32_t tmqWriteRawMetaDataImpl(TAOS* taos, void* data, int32_t dataLen) code = rawBlockBindData(pQuery, pTableMeta, rawData, &pCreateReqDst, fields, pSW->nCols, true, err, ERR_MSG_LEN); taosMemoryFree(fields); taosMemoryFreeClear(pTableMeta); + if (pCreateReqDst) { + tdDestroySVCreateTbReq(pCreateReqDst); + taosMemoryFreeClear(pCreateReqDst); + } if (code != TSDB_CODE_SUCCESS) { SET_ERROR_MSG("table:%s, err:%s", tbName, err); goto end; @@ -1944,7 +1948,7 @@ end: taosMemoryFreeClear(pTableMeta); if (pCreateReqDst) { tdDestroySVCreateTbReq(pCreateReqDst); - taosMemoryFree(pCreateReqDst); + taosMemoryFreeClear(pCreateReqDst); } return code; } @@ -2038,6 +2042,7 @@ char* tmq_get_json_meta(TAOS_RES* res) { processSimpleMeta(&pMetaRspObj->metaRsp, &pJson); char* string = cJSON_PrintUnformatted(pJson); cJSON_Delete(pJson); + uDebug("tmq_get_json_meta string:%s", string); return string; } diff --git a/source/client/src/clientTmq.c b/source/client/src/clientTmq.c index 8da7367c30..2c92824855 100644 --- a/source/client/src/clientTmq.c +++ b/source/client/src/clientTmq.c @@ -1020,9 +1020,7 @@ OVER: tDestroySMqHbReq(&req); if (tmrId != NULL) { bool ret = taosTmrReset(tmqSendHbReq, tmq->heartBeatIntervalMs, param, tmqMgmt.timer, &tmq->hbLiveTimer); - if (!ret){ - tscError("failed to reset timer fo tmq hb"); - } + tscDebug("reset timer fo tmq hb:%d", ret); } int32_t ret = taosReleaseRef(tmqMgmt.rsetId, refId); if (ret != 0){ @@ -1064,9 +1062,7 @@ void tmqHandleAllDelayedTask(tmq_t* pTmq) { tscDebug("consumer:0x%" PRIx64 " retrieve ep from mnode in 1s", pTmq->consumerId); bool ret = taosTmrReset(tmqAssignAskEpTask, DEFAULT_ASKEP_INTERVAL, (void*)(pTmq->refId), tmqMgmt.timer, &pTmq->epTimer); - if (!ret){ - tscError("failed to reset timer fo tmq ask ep"); - } + tscDebug("reset timer fo tmq ask ep:%d", ret); } else if (*pTaskType == TMQ_DELAYED_TASK__COMMIT) { tmq_commit_cb* pCallbackFn = pTmq->commitCb ? pTmq->commitCb : defaultCommitCbFn; asyncCommitAllOffsets(pTmq, pCallbackFn, pTmq->commitCbUserParam); @@ -1074,9 +1070,7 @@ void tmqHandleAllDelayedTask(tmq_t* pTmq) { pTmq->autoCommitInterval / 1000.0); bool ret = taosTmrReset(tmqAssignDelayedCommitTask, pTmq->autoCommitInterval, (void*)(pTmq->refId), tmqMgmt.timer, &pTmq->commitTimer); - if (!ret){ - tscError("failed to reset timer fo commit"); - } + tscDebug("reset timer fo commit:%d", ret); } else { tscError("consumer:0x%" PRIx64 " invalid task type:%d", pTmq->consumerId, *pTaskType); } diff --git a/source/common/src/rsync.c b/source/common/src/rsync.c index 77787db3ce..47a452eab7 100644 --- a/source/common/src/rsync.c +++ b/source/common/src/rsync.c @@ -32,10 +32,14 @@ static void removeEmptyDir() { empty = false; } if (empty) taosRemoveDir(filename); - (void)taosCloseDir(&pDirTmp); + if (taosCloseDir(&pDirTmp) != 0) { + uError("[rsync] close dir error," ERRNO_ERR_FORMAT, ERRNO_ERR_DATA); + } } - (void)taosCloseDir(&pDir); + if (taosCloseDir(&pDir) != 0) { + uError("[rsync] close dir error," ERRNO_ERR_FORMAT, ERRNO_ERR_DATA); + } } #ifdef WINDOWS @@ -297,7 +301,7 @@ int32_t downloadByRsync(const char* id, const char* path, int64_t checkpointId) path, el); } - if (code != TSDB_CODE_SUCCESS) { // if failed, try to load it from data directory + if (code != TSDB_CODE_SUCCESS) { // if failed, try to load it from data directory #ifdef WINDOWS memset(pathTransform, 0, PATH_MAX); changeDirFromWindowsToLinux(path, pathTransform); diff --git a/source/common/src/systable.c b/source/common/src/systable.c index 2f3ffecf61..be841d9682 100644 --- a/source/common/src/systable.c +++ b/source/common/src/systable.c @@ -159,6 +159,7 @@ static const SSysDbTableSchema userStbsSchema[] = { {.name = "watermark", .bytes = 64 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false}, {.name = "max_delay", .bytes = 64 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false}, {.name = "rollup", .bytes = 128 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = false}, + {.name = "uid", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT, .sysInfo = false}, }; static const SSysDbTableSchema streamSchema[] = { diff --git a/source/common/src/tcol.c b/source/common/src/tcol.c index 17972c6777..84027c25b6 100644 --- a/source/common/src/tcol.c +++ b/source/common/src/tcol.c @@ -238,7 +238,7 @@ const char* columnLevelStr(uint8_t type) { bool checkColumnEncode(char encode[TSDB_CL_COMPRESS_OPTION_LEN]) { if (0 == strlen(encode)) return true; - (void)strtolower(encode, encode); + TAOS_UNUSED(strtolower(encode, encode)); for (int i = 0; i < supportedEncodeNum; ++i) { if (0 == strcmp((const char*)encode, supportedEncode[i])) { return true; @@ -255,7 +255,7 @@ bool checkColumnEncodeOrSetDefault(uint8_t type, char encode[TSDB_CL_COMPRESS_OP } bool checkColumnCompress(char compress[TSDB_CL_COMPRESS_OPTION_LEN]) { if (0 == strlen(compress)) return true; - (void)strtolower(compress, compress); + TAOS_UNUSED(strtolower(compress, compress)); for (int i = 0; i < supportedCompressNum; ++i) { if (0 == strcmp((const char*)compress, supportedCompress[i])) { return true; @@ -273,7 +273,7 @@ bool checkColumnCompressOrSetDefault(uint8_t type, char compress[TSDB_CL_COMPRES } bool checkColumnLevel(char level[TSDB_CL_COMPRESS_OPTION_LEN]) { if (0 == strlen(level)) return true; - (void)strtolower(level, level); + TAOS_UNUSED(strtolower(level, level)); if (1 == strlen(level)) { if ('h' == level[0] || 'm' == level[0] || 'l' == level[0]) return true; } else { diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 4b44e4af43..6147d50a84 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -481,6 +481,10 @@ int32_t tRowBuildFromBind(SBindInfo *infos, int32_t numOfInfos, bool infoSorted, }; if (IS_VAR_DATA_TYPE(infos[iInfo].type)) { value.nData = infos[iInfo].bind->length[iRow]; + if (value.nData > pTSchema->columns[iInfo].bytes - VARSTR_HEADER_SIZE) { + code = TSDB_CODE_INVALID_PARA; + goto _exit; + } value.pData = (uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bind->buffer_length * iRow; } else { (void)memcpy(&value.val, (uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bind->buffer_length * iRow, @@ -1704,7 +1708,7 @@ bool tTagGet(const STag *pTag, STagVal *pTagVal) { offset = pTag->idx[midx]; } - (void)tGetTagVal(p + offset, &tv, isJson); + int32_t nt = tGetTagVal(p + offset, &tv, isJson); if (isJson) { c = tTagValJsonCmprFn(pTagVal, &tv); } else { @@ -1754,7 +1758,7 @@ int32_t tTagToValArray(const STag *pTag, SArray **ppArray) { } else { offset = pTag->idx[iTag]; } - (void)tGetTagVal(p + offset, &tv, pTag->flags & TD_TAG_JSON); + int32_t nt = tGetTagVal(p + offset, &tv, pTag->flags & TD_TAG_JSON); if (taosArrayPush(*ppArray, &tv) == NULL) { code = terrno; goto _err; @@ -1784,7 +1788,7 @@ void tTagSetCid(const STag *pTag, int16_t iTag, int16_t cid) { offset = pTag->idx[iTag]; } - (void)tPutI16v(p + offset, cid); + int32_t nt = tPutI16v(p + offset, cid); } // STSchema ======================================== @@ -3279,6 +3283,10 @@ int32_t tRowBuildFromBind2(SBindInfo2 *infos, int32_t numOfInfos, bool infoSorte int32_t length = infos[iInfo].bind->length[iRow]; uint8_t **data = &((uint8_t **)TARRAY_DATA(bufArray))[iInfo]; value.nData = length; + if (value.nData > pTSchema->columns[iInfo].bytes - VARSTR_HEADER_SIZE) { + code = TSDB_CODE_INVALID_PARA; + goto _exit; + } value.pData = *data; *data += length; // value.pData = (uint8_t *)infos[iInfo].bind->buffer + infos[iInfo].bind->buffer_length * iRow; @@ -3352,16 +3360,16 @@ static int32_t tColDataCopyRowSingleCol(SColData *pFromColData, int32_t iFromRow SET_BIT1(pToColData->pBitMap, iToRow, GET_BIT1(pFromColData->pBitMap, iFromRow)); } break; case HAS_VALUE: { - (void)tColDataCopyRowCell(pFromColData, iFromRow, pToColData, iToRow); + TAOS_CHECK_RETURN(tColDataCopyRowCell(pFromColData, iFromRow, pToColData, iToRow)); } break; case (HAS_VALUE | HAS_NONE): case (HAS_VALUE | HAS_NULL): { SET_BIT1(pToColData->pBitMap, iToRow, GET_BIT1(pFromColData->pBitMap, iFromRow)); - (void)tColDataCopyRowCell(pFromColData, iFromRow, pToColData, iToRow); + TAOS_CHECK_RETURN(tColDataCopyRowCell(pFromColData, iFromRow, pToColData, iToRow)); } break; case (HAS_VALUE | HAS_NULL | HAS_NONE): { SET_BIT2(pToColData->pBitMap, iToRow, GET_BIT2(pFromColData->pBitMap, iFromRow)); - (void)tColDataCopyRowCell(pFromColData, iFromRow, pToColData, iToRow); + TAOS_CHECK_RETURN(tColDataCopyRowCell(pFromColData, iFromRow, pToColData, iToRow)); } break; default: return -1; @@ -3434,24 +3442,24 @@ static int32_t tColDataMergeSortMerge(SColData *aColData, int32_t start, int32_t tColDataArrGetRowKey(aColData, nColData, j, &keyj); while (i <= mid && j <= end) { if (tRowKeyCompare(&keyi, &keyj) <= 0) { - (void)tColDataCopyRowAppend(aColData, i++, aDstColData, nColData); + TAOS_CHECK_RETURN(tColDataCopyRowAppend(aColData, i++, aDstColData, nColData)); tColDataArrGetRowKey(aColData, nColData, i, &keyi); } else { - (void)tColDataCopyRowAppend(aColData, j++, aDstColData, nColData); + TAOS_CHECK_RETURN(tColDataCopyRowAppend(aColData, j++, aDstColData, nColData)); tColDataArrGetRowKey(aColData, nColData, j, &keyj); } } while (i <= mid) { - (void)tColDataCopyRowAppend(aColData, i++, aDstColData, nColData); + TAOS_CHECK_RETURN(tColDataCopyRowAppend(aColData, i++, aDstColData, nColData)); } while (j <= end) { - (void)tColDataCopyRowAppend(aColData, j++, aDstColData, nColData); + TAOS_CHECK_RETURN(tColDataCopyRowAppend(aColData, j++, aDstColData, nColData)); } for (i = start, k = 0; i <= end; ++i, ++k) { - (void)tColDataCopyRow(aDstColData, k, aColData, i, nColData); + TAOS_CHECK_RETURN(tColDataCopyRow(aDstColData, k, aColData, i, nColData)); } if (aDstColData) { @@ -3600,7 +3608,7 @@ int32_t tColDataSortMerge(SArray **arr) { // sort ------- if (doSort) { - (void)tColDataSort(aColData, nColData); + TAOS_CHECK_RETURN(tColDataSort(aColData, nColData)); } if (doMerge != 1) { @@ -4163,20 +4171,20 @@ int32_t tValueColumnInit(SValueColumn *valCol) { return 0; } -int32_t tValueColumnDestroy(SValueColumn *valCol) { +void tValueColumnDestroy(SValueColumn *valCol) { valCol->type = TSDB_DATA_TYPE_NULL; valCol->numOfValues = 0; tBufferDestroy(&valCol->data); tBufferDestroy(&valCol->offsets); - return 0; + return; } -int32_t tValueColumnClear(SValueColumn *valCol) { +void tValueColumnClear(SValueColumn *valCol) { valCol->type = TSDB_DATA_TYPE_NULL; valCol->numOfValues = 0; tBufferClear(&valCol->data); tBufferClear(&valCol->offsets); - return 0; + return; } int32_t tValueColumnAppend(SValueColumn *valCol, const SValue *value) { @@ -4247,17 +4255,17 @@ int32_t tValueColumnGet(SValueColumn *valCol, int32_t idx, SValue *value) { int32_t offset, nextOffset; SBufferReader reader = BUFFER_READER_INITIALIZER(idx * sizeof(offset), &valCol->offsets); - (void)tBufferGetI32(&reader, &offset); + TAOS_CHECK_RETURN(tBufferGetI32(&reader, &offset)); if (idx == valCol->numOfValues - 1) { nextOffset = tBufferGetSize(&valCol->data); } else { - (void)tBufferGetI32(&reader, &nextOffset); + TAOS_CHECK_RETURN(tBufferGetI32(&reader, &nextOffset)); } value->nData = nextOffset - offset; value->pData = (uint8_t *)tBufferGetDataAt(&valCol->data, offset); } else { SBufferReader reader = BUFFER_READER_INITIALIZER(idx * tDataTypes[value->type].bytes, &valCol->data); - (void)tBufferGet(&reader, tDataTypes[value->type].bytes, &value->val); + TAOS_CHECK_RETURN(tBufferGet(&reader, tDataTypes[value->type].bytes, &value->val)); } return 0; } @@ -4309,7 +4317,7 @@ int32_t tValueColumnDecompress(void *input, const SValueColumnCompressInfo *info SBuffer *assist) { int32_t code; - (void)tValueColumnClear(valCol); + tValueColumnClear(valCol); valCol->type = info->type; // offset if (IS_VAR_DATA_TYPE(valCol->type)) { diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index c1d943ab5c..557ac07bbd 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -4912,6 +4912,7 @@ int32_t tSerializeSDbCfgRspImpl(SEncoder *encoder, const SDbCfgRsp *pRsp) { TAOS_CHECK_RETURN(tEncodeI32(encoder, pRsp->s3ChunkSize)); TAOS_CHECK_RETURN(tEncodeI32(encoder, pRsp->s3KeepLocal)); TAOS_CHECK_RETURN(tEncodeI8(encoder, pRsp->s3Compact)); + TAOS_CHECK_RETURN(tEncodeI8(encoder, pRsp->hashMethod)); return 0; } @@ -5003,6 +5004,11 @@ int32_t tDeserializeSDbCfgRspImpl(SDecoder *decoder, SDbCfgRsp *pRsp) { TAOS_CHECK_RETURN(tDecodeI32(decoder, &pRsp->s3KeepLocal)); TAOS_CHECK_RETURN(tDecodeI8(decoder, &pRsp->s3Compact)); } + if (!tDecodeIsEnd(decoder)) { + TAOS_CHECK_RETURN(tDecodeI8(decoder, &pRsp->hashMethod)); + } else { + pRsp->hashMethod = 1; // default value + } return 0; } @@ -5720,6 +5726,7 @@ int32_t tSerializeSTableInfoReq(void *buf, int32_t bufLen, STableInfoReq *pReq) TAOS_CHECK_EXIT(tStartEncode(&encoder)); TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->dbFName)); TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->tbName)); + TAOS_CHECK_EXIT(tEncodeU8(&encoder, pReq->option)); tEndEncode(&encoder); _exit: @@ -5754,6 +5761,11 @@ int32_t tDeserializeSTableInfoReq(void *buf, int32_t bufLen, STableInfoReq *pReq TAOS_CHECK_EXIT(tStartDecode(&decoder)); TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->dbFName)); TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->tbName)); + if (!tDecodeIsEnd(&decoder)) { + TAOS_CHECK_EXIT(tDecodeU8(&decoder, &pReq->option)); + } else { + pReq->option = 0; + } tEndDecode(&decoder); _exit: diff --git a/source/common/src/trow.c b/source/common/src/trow.c index 40b4f863cb..626d1141e0 100644 --- a/source/common/src/trow.c +++ b/source/common/src/trow.c @@ -54,6 +54,7 @@ bool tdSTSRowIterFetch(STSRowIter *pIter, col_id_t colId, col_type_t colType, SC return true; } + bool ret = true; if (TD_IS_TP_ROW(pIter->pRow)) { STColumn *pCol = NULL; STSchema *pSchema = pIter->pSchema; @@ -68,16 +69,16 @@ bool tdSTSRowIterFetch(STSRowIter *pIter, col_id_t colId, col_type_t colType, SC return false; } } - (void)tdSTSRowIterGetTpVal(pIter, pCol->type, pCol->offset, pVal); + ret = tdSTSRowIterGetTpVal(pIter, pCol->type, pCol->offset, pVal); ++pIter->colIdx; } else if (TD_IS_KV_ROW(pIter->pRow)) { - return tdSTSRowIterGetKvVal(pIter, colId, &pIter->kvIdx, pVal); + ret = tdSTSRowIterGetKvVal(pIter, colId, &pIter->kvIdx, pVal); } else { pVal->valType = TD_VTYPE_NONE; terrno = TSDB_CODE_INVALID_PARA; - if (COL_REACH_END(colId, pIter->maxColId)) return false; + if (COL_REACH_END(colId, pIter->maxColId)) ret = false; } - return true; + return ret; } bool tdSTSRowIterGetTpVal(STSRowIter *pIter, col_type_t colType, int32_t offset, SCellVal *pVal) { @@ -138,7 +139,7 @@ int32_t tdGetBitmapValTypeII(const void *pBitmap, int16_t colIdx, TDRowValT *pVa int32_t tdGetBitmapValType(const void *pBitmap, int16_t colIdx, TDRowValT *pValType, int8_t bitmapMode) { switch (bitmapMode) { case 0: - (void)tdGetBitmapValTypeII(pBitmap, colIdx, pValType); + return tdGetBitmapValTypeII(pBitmap, colIdx, pValType); break; #if 0 case -1: @@ -365,7 +366,7 @@ bool tdSTpRowGetVal(STSRow *pRow, col_id_t colId, col_type_t colType, int32_t fl return true; } void *pBitmap = tdGetBitmapAddrTp(pRow, flen); - (void)tdGetTpRowValOfCol(pVal, pRow, pBitmap, colType, offset, colIdx); + if (tdGetTpRowValOfCol(pVal, pRow, pBitmap, colType, offset, colIdx)) return false; return true; } @@ -383,16 +384,17 @@ bool tdSTSRowIterNext(STSRowIter *pIter, SCellVal *pVal) { return true; } + bool ret = true; if (TD_IS_TP_ROW(pIter->pRow)) { - (void)tdSTSRowIterGetTpVal(pIter, pCol->type, pCol->offset, pVal); + ret = tdSTSRowIterGetTpVal(pIter, pCol->type, pCol->offset, pVal); } else if (TD_IS_KV_ROW(pIter->pRow)) { - (void)tdSTSRowIterGetKvVal(pIter, pCol->colId, &pIter->kvIdx, pVal); + ret = tdSTSRowIterGetKvVal(pIter, pCol->colId, &pIter->kvIdx, pVal); } else { return false; } ++pIter->colIdx; - return true; + return ret; } int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t rowType) { @@ -488,8 +490,8 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t r SRowBuilder rb = {.rowType = rowType}; tdSRowInit(&rb, pTSchema->version); - (void)tdSRowSetInfo(&rb, pTSchema->numOfCols, nBound, pTSchema->flen); - (void)tdSRowResetBuf(&rb, *ppRow); + TAOS_CHECK_GOTO(tdSRowSetInfo(&rb, pTSchema->numOfCols, nBound, pTSchema->flen), NULL, _exit); + TAOS_CHECK_GOTO(tdSRowResetBuf(&rb, *ppRow), NULL, _exit); int32_t iBound = 0; iColVal = 0; @@ -566,6 +568,7 @@ bool tdSTSRowGetVal(STSRowIter *pIter, col_id_t colId, col_type_t colType, SCell return true; } + bool ret = true; STSRow *pRow = pIter->pRow; int16_t colIdx = -1; if (TD_IS_TP_ROW(pRow)) { @@ -580,7 +583,7 @@ bool tdSTSRowGetVal(STSRowIter *pIter, col_id_t colId, col_type_t colType, SCell #ifdef TD_SUPPORT_BITMAP colIdx = POINTER_DISTANCE(pCol, pSchema->columns) / sizeof(STColumn); #endif - (void)tdGetTpRowValOfCol(pVal, pRow, pIter->pBitmap, pCol->type, pCol->offset, colIdx - 1); + if (tdGetTpRowValOfCol(pVal, pRow, pIter->pBitmap, pCol->type, pCol->offset, colIdx - 1)) ret = false; } else if (TD_IS_KV_ROW(pRow)) { SKvRowIdx *pIdx = (SKvRowIdx *)taosbsearch(&colId, TD_ROW_COL_IDX(pRow), tdRowGetNCols(pRow), sizeof(SKvRowIdx), compareKvRowColId, TD_EQ); @@ -589,13 +592,13 @@ bool tdSTSRowGetVal(STSRowIter *pIter, col_id_t colId, col_type_t colType, SCell colIdx = POINTER_DISTANCE(pIdx, TD_ROW_COL_IDX(pRow)) / sizeof(SKvRowIdx); } #endif - (void)tdGetKvRowValOfCol(pVal, pRow, pIter->pBitmap, pIdx ? pIdx->offset : -1, colIdx); + if (tdGetKvRowValOfCol(pVal, pRow, pIter->pBitmap, pIdx ? pIdx->offset : -1, colIdx)) ret = false; } else { if (COL_REACH_END(colId, pIter->maxColId)) return false; pVal->valType = TD_VTYPE_NONE; } - return true; + return ret; } int32_t tdGetKvRowValOfCol(SCellVal *output, STSRow *pRow, void *pBitmap, int32_t offset, int16_t colIdx) { @@ -694,9 +697,9 @@ int32_t tdAppendColValToRow(SRowBuilder *pBuilder, col_id_t colId, int8_t colTyp } if (TD_IS_TP_ROW(pRow)) { - (void)tdAppendColValToTpRow(pBuilder, valType, val, isCopyVarData, colType, colIdx, offset); + TAOS_CHECK_RETURN(tdAppendColValToTpRow(pBuilder, valType, val, isCopyVarData, colType, colIdx, offset)); } else { - (void)tdAppendColValToKvRow(pBuilder, valType, val, isCopyVarData, colType, colIdx, offset, colId); + TAOS_CHECK_RETURN(tdAppendColValToKvRow(pBuilder, valType, val, isCopyVarData, colType, colIdx, offset, colId)); } TAOS_RETURN(TSDB_CODE_SUCCESS); } @@ -947,9 +950,9 @@ int32_t tTSRowGetVal(STSRow *pRow, STSchema *pTSchema, int16_t iCol, SColVal *pC } if (TD_IS_TP_ROW(pRow)) { - (void)tdSTpRowGetVal(pRow, pTColumn->colId, pTColumn->type, pTSchema->flen, pTColumn->offset, iCol - 1, &cv); + TAOS_UNUSED(tdSTpRowGetVal(pRow, pTColumn->colId, pTColumn->type, pTSchema->flen, pTColumn->offset, iCol - 1, &cv)); } else if (TD_IS_KV_ROW(pRow)) { - (void)tdSKvRowGetVal(pRow, pTColumn->colId, iCol - 1, &cv); + TAOS_UNUSED(tdSKvRowGetVal(pRow, pTColumn->colId, iCol - 1, &cv)); } else { TAOS_RETURN(TSDB_CODE_INVALID_PARA); } diff --git a/source/common/test/msgTypeTable.ini b/source/common/test/msgTypeTable.ini index 6e5721075c..0325183d8b 100644 --- a/source/common/test/msgTypeTable.ini +++ b/source/common/test/msgTypeTable.ini @@ -382,6 +382,8 @@ TDMT_VND_ARB_CHECK_SYNC = 613 TDMT_VND_ARB_CHECK_SYNC_RSP = 614 TDMT_VND_FETCH_TTL_EXPIRED_TBS = 615 TDMT_VND_FETCH_TTL_EXPIRED_TBS_RSP = 616 +TDMT_VND_TABLE_NAME = 617 +TDMT_VND_TABLE_NAME_RSP = 618 TDMT_SCH_QUERY = 769 TDMT_SCH_QUERY_RSP = 770 TDMT_SCH_MERGE_QUERY = 771 diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index 9f5db9b0eb..377e4752f8 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -164,6 +164,9 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) { if (argc < 2) return 0; global.envCmd = taosMemoryMalloc((argc - 1) * sizeof(char *)); + if (global.envCmd == NULL) { + return terrno; + } memset(global.envCmd, 0, (argc - 1) * sizeof(char *)); for (int32_t i = 1; i < argc; ++i) { if (strcmp(argv[i], "-c") == 0) { @@ -433,7 +436,8 @@ int mainWindows(int argc, char **argv) { } if (global.dumpSdb) { - mndDumpSdb(); + int32_t code = 0; + TAOS_CHECK_RETURN(mndDumpSdb()); taosCleanupCfg(); taosCloseLog(); taosCleanupArgs(); @@ -442,6 +446,7 @@ int mainWindows(int argc, char **argv) { } if (global.deleteTrans) { + int32_t code = 0; TdFilePtr pFile; if ((code = dmCheckRunning(tsDataDir, &pFile)) != 0) { printf("failed to generate encrypt code since taosd is running, please stop it first, reason:%s", @@ -449,7 +454,7 @@ int mainWindows(int argc, char **argv) { return code; } - mndDeleteTrans(); + TAOS_CHECK_RETURN(mndDeleteTrans()); taosCleanupCfg(); taosCloseLog(); taosCleanupArgs(); diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index ae12bf6c99..020a8077b2 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c @@ -69,6 +69,7 @@ static void dmMayShouldUpdateIpWhiteList(SDnodeMgmt *pMgmt, int64_t ver) { .contLen = contLen, .msgType = TDMT_MND_RETRIEVE_IP_WHITE, .info.ahandle = (void *)0x9527, + .info.notFreeAhandle = 1, .info.refId = 0, .info.noResp = 0, .info.handle = 0}; @@ -185,6 +186,7 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { .contLen = contLen, .msgType = TDMT_MND_STATUS, .info.ahandle = (void *)0x9527, + .info.notFreeAhandle = 1, .info.refId = 0, .info.noResp = 0, .info.handle = 0}; @@ -234,6 +236,7 @@ void dmSendNotifyReq(SDnodeMgmt *pMgmt, SNotifyReq *pReq) { .contLen = contLen, .msgType = TDMT_MND_NOTIFY, .info.ahandle = (void *)0x9527, + .info.notFreeAhandle = 1, .info.refId = 0, .info.noResp = 1, .info.handle = 0}; @@ -483,7 +486,7 @@ int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) { } int32_t len = blockEncode(pBlock, pStart, numOfCols); - if(len < 0) { + if (len < 0) { dError("failed to retrieve data since %s", tstrerror(code)); blockDataDestroy(pBlock); rpcFreeCont(pRsp); diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c index 4cfadc8f59..1ed7c9ecd9 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmWorker.c @@ -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); } } diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index f020ba2f5e..3d6ff48dd1 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -235,7 +235,7 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) { pNode->nodePort = pCreate->replicas[pCfg->syncCfg.replicaNum].port; pNode->nodeRole = TAOS_SYNC_ROLE_VOTER; tstrncpy(pNode->nodeFqdn, pCreate->replicas[pCfg->syncCfg.replicaNum].fqdn, TSDB_FQDN_LEN); - (void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); + bool ret = tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); pCfg->syncCfg.replicaNum++; } if (pCreate->selfIndex != -1) { @@ -247,7 +247,7 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) { pNode->nodePort = pCreate->learnerReplicas[pCfg->syncCfg.totalReplicaNum].port; pNode->nodeRole = TAOS_SYNC_ROLE_LEARNER; tstrncpy(pNode->nodeFqdn, pCreate->learnerReplicas[pCfg->syncCfg.totalReplicaNum].fqdn, TSDB_FQDN_LEN); - (void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); + bool ret = tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); pCfg->syncCfg.totalReplicaNum++; } pCfg->syncCfg.totalReplicaNum += pCfg->syncCfg.replicaNum; @@ -992,6 +992,7 @@ SArray *vmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_INDEX, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_QUERY_COMPACT_PROGRESS, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_KILL_COMPACT, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_TABLE_NAME, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DEPLOY, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_STREAM_TASK_DROP, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; diff --git a/source/dnode/mgmt/node_util/src/dmEps.c b/source/dnode/mgmt/node_util/src/dmEps.c index f8f2b3dfca..0ae184ffd3 100644 --- a/source/dnode/mgmt/node_util/src/dmEps.c +++ b/source/dnode/mgmt/node_util/src/dmEps.c @@ -150,6 +150,10 @@ int32_t dmReadEps(SDnodeData *pData) { } char *tmp = taosMemoryMalloc(scopeLen + 1); + if (tmp == NULL) { + dError("failed to malloc memory for tsEncryptScope:%s", tsEncryptScope); + goto _OVER; + } memset(tmp, 0, scopeLen + 1); memcpy(tmp, tsEncryptScope, scopeLen); diff --git a/source/dnode/mgmt/node_util/src/dmFile.c b/source/dnode/mgmt/node_util/src/dmFile.c index 14154d1a23..1da13f72cd 100644 --- a/source/dnode/mgmt/node_util/src/dmFile.c +++ b/source/dnode/mgmt/node_util/src/dmFile.c @@ -342,6 +342,11 @@ static int32_t dmCompareEncryptKey(char *file, char *key, bool toLogFile) { int len = ENCRYPTED_LEN(size); result = taosMemoryMalloc(len); + if (result == NULL) { + code = terrno; + encryptError("failed to alloc memory file:%s since %s", file, tstrerror(code)); + goto _OVER; + } SCryptOpts opts = {0}; strncpy(opts.key, key, ENCRYPT_KEY_LEN); diff --git a/source/dnode/mnode/impl/inc/mndStream.h b/source/dnode/mnode/impl/inc/mndStream.h index dceb86c963..b97eaf31d1 100644 --- a/source/dnode/mnode/impl/inc/mndStream.h +++ b/source/dnode/mnode/impl/inc/mndStream.h @@ -35,6 +35,7 @@ extern "C" { #define MND_STREAM_TASK_UPDATE_NAME "stream-task-update" #define MND_STREAM_CHKPT_UPDATE_NAME "stream-chkpt-update" #define MND_STREAM_CHKPT_CONSEN_NAME "stream-chkpt-consen" +#define MND_STREAM_RESTART_NAME "stream-restart" typedef struct SStreamTransInfo { int64_t startTime; @@ -120,6 +121,7 @@ int32_t mndStreamGetRelTrans(SMnode *pMnode, int64_t streamId); int32_t mndGetNumOfStreams(SMnode *pMnode, char *dbName, int32_t *pNumOfStreams); int32_t mndGetNumOfStreamTasks(const SStreamObj *pStream); int32_t mndTakeVgroupSnapshot(SMnode *pMnode, bool *allReady, SArray** pList); +void mndDestroyVgroupChangeInfo(SVgroupChangeInfo *pInfo); void mndKillTransImpl(SMnode *pMnode, int32_t transId, const char *pDbName); int32_t setTransAction(STrans *pTrans, void *pCont, int32_t contLen, int32_t msgType, const SEpSet *pEpset, int32_t retryCode, int32_t acceptCode); @@ -127,31 +129,39 @@ int32_t doCreateTrans(SMnode *pMnode, SStreamObj *pStream, SRpcMsg *pReq, ETrnC const char *pMsg, STrans **pTrans1); int32_t mndPersistTransLog(SStreamObj *pStream, STrans *pTrans, int32_t status); SSdbRaw *mndStreamActionEncode(SStreamObj *pStream); -void killAllCheckpointTrans(SMnode *pMnode, SVgroupChangeInfo *pChangeInfo); int32_t mndStreamSetUpdateEpsetAction(SMnode *pMnode, SStreamObj *pStream, SVgroupChangeInfo *pInfo, STrans *pTrans); int32_t mndGetStreamObj(SMnode *pMnode, int64_t streamId, SStreamObj** pStream); +bool mndStreamNodeIsUpdated(SMnode *pMnode); + int32_t extractNodeEpset(SMnode *pMnode, SEpSet *pEpSet, bool *hasEpset, int32_t taskId, int32_t nodeId); int32_t mndProcessStreamHb(SRpcMsg *pReq); -void saveTaskAndNodeInfoIntoBuf(SStreamObj *pStream, SStreamExecInfo *pExecNode); int32_t extractStreamNodeList(SMnode *pMnode); int32_t mndStreamSetResumeAction(STrans *pTrans, SMnode *pMnode, SStreamObj *pStream, int8_t igUntreated); int32_t mndStreamSetPauseAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream); int32_t mndStreamSetDropAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream); int32_t mndStreamSetDropActionFromList(SMnode *pMnode, STrans *pTrans, SArray *pList); int32_t mndStreamSetResetTaskAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream); -int32_t mndCreateStreamResetStatusTrans(SMnode *pMnode, SStreamObj *pStream); int32_t mndStreamSetUpdateChkptAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream); +int32_t mndCreateStreamResetStatusTrans(SMnode *pMnode, SStreamObj *pStream); +int32_t mndStreamSetChkptIdAction(SMnode *pMnode, STrans *pTrans, SStreamTask* pTask, int64_t checkpointId, int64_t ts); +int32_t mndStreamSetRestartAction(SMnode* pMnode, STrans *pTrans, SStreamObj* pStream); +int32_t mndStreamSetCheckpointAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask, int64_t checkpointId, + int8_t mndTrigger); int32_t mndCreateStreamChkptInfoUpdateTrans(SMnode *pMnode, SStreamObj *pStream, SArray *pChkptInfoList); int32_t mndScanCheckpointReportInfo(SRpcMsg *pReq); int32_t mndCreateSetConsensusChkptIdTrans(SMnode *pMnode, SStreamObj *pStream, int32_t taskId, int64_t checkpointId, int64_t ts); void removeTasksInBuf(SArray *pTaskIds, SStreamExecInfo *pExecInfo); +int32_t mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pPrevNodeList, const SArray *pNodeList, + SVgroupChangeInfo *pInfo); +void killAllCheckpointTrans(SMnode *pMnode, SVgroupChangeInfo *pChangeInfo); int32_t createStreamTaskIter(SStreamObj *pStream, SStreamTaskIter **pIter); void destroyStreamTaskIter(SStreamTaskIter *pIter); bool streamTaskIterNextTask(SStreamTaskIter *pIter); int32_t streamTaskIterGetCurrent(SStreamTaskIter *pIter, SStreamTask **pTask); + int32_t mndInitExecInfo(); void mndInitStreamExecInfo(SMnode *pMnode, SStreamExecInfo *pExecInfo); void mndStreamResetInitTaskListLoadFlag(); diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index 5cec3a8f27..5e38a91ab0 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -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()); diff --git a/source/dnode/mnode/impl/src/mndCompactDetail.c b/source/dnode/mnode/impl/src/mndCompactDetail.c index d1bdb4734d..cbd0df7e68 100644 --- a/source/dnode/mnode/impl/src/mndCompactDetail.c +++ b/source/dnode/mnode/impl/src/mndCompactDetail.c @@ -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); } diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 4a09aa44a0..374dff8d0c 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -1329,6 +1329,7 @@ static void mndDumpDbCfgInfo(SDbCfgRsp *cfgRsp, SDbObj *pDb) { cfgRsp->walFsyncPeriod = pDb->cfg.walFsyncPeriod; cfgRsp->hashPrefix = pDb->cfg.hashPrefix; cfgRsp->hashSuffix = pDb->cfg.hashSuffix; + cfgRsp->hashMethod = pDb->cfg.hashMethod; cfgRsp->walLevel = pDb->cfg.walLevel; cfgRsp->precision = pDb->cfg.precision; cfgRsp->compression = pDb->cfg.compression; diff --git a/source/dnode/mnode/impl/src/mndDump.c b/source/dnode/mnode/impl/src/mndDump.c index 7613282ef8..d1dd99b319 100644 --- a/source/dnode/mnode/impl/src/mndDump.c +++ b/source/dnode/mnode/impl/src/mndDump.c @@ -16,6 +16,7 @@ #define _DEFAULT_SOURCE #include "mndDb.h" #include "mndInt.h" +#include "mndShow.h" #include "mndStb.h" #include "sdb.h" #include "tconfig.h" @@ -46,7 +47,9 @@ char *i642str(int64_t val) { } void dumpFunc(SSdb *pSdb, SJson *json) { - void *pIter = NULL; + int32_t code = 0; + int32_t lino = 0; + void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "funcs"); while (1) { @@ -55,26 +58,30 @@ void dumpFunc(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "name", pObj->name); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "funcType", i642str(pObj->funcType)); - (void)tjsonAddStringToObject(item, "scriptType", i642str(pObj->scriptType)); - (void)tjsonAddStringToObject(item, "align", i642str(pObj->align)); - (void)tjsonAddStringToObject(item, "outputType", i642str(pObj->outputType)); - (void)tjsonAddStringToObject(item, "outputLen", i642str(pObj->outputLen)); - (void)tjsonAddStringToObject(item, "bufSize", i642str(pObj->bufSize)); - (void)tjsonAddStringToObject(item, "signature", i642str(pObj->signature)); - (void)tjsonAddStringToObject(item, "commentSize", i642str(pObj->commentSize)); - (void)tjsonAddStringToObject(item, "codeSize", i642str(pObj->codeSize)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "name", pObj->name), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "funcType", i642str(pObj->funcType)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "scriptType", i642str(pObj->scriptType)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "align", i642str(pObj->align)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "outputType", i642str(pObj->outputType)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "outputLen", i642str(pObj->outputLen)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "bufSize", i642str(pObj->bufSize)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "signature", i642str(pObj->signature)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "commentSize", i642str(pObj->commentSize)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "codeSize", i642str(pObj->codeSize)), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump func info at line:%d since %s", lino, tstrerror(code)); } void dumpDb(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonCreateObject(); - (void)tjsonAddItemToObject(json, "dbs", items); + TAOS_CHECK_GOTO(tjsonAddItemToObject(json, "dbs", items), &lino, _OVER); while (1) { SDbObj *pObj = NULL; @@ -82,65 +89,86 @@ void dumpDb(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToObject(items, "db", item); + RETRIEVE_CHECK_GOTO(tjsonAddItemToObject(items, "db", item), pObj, &lino, _OVER); - (void)tjsonAddStringToObject(item, "name", mndGetDbStr(pObj->name)); - (void)tjsonAddStringToObject(item, "acct", pObj->acct); - (void)tjsonAddStringToObject(item, "createUser", pObj->createUser); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); - (void)tjsonAddStringToObject(item, "uid", i642str(pObj->uid)); - (void)tjsonAddStringToObject(item, "cfgVersion", i642str(pObj->cfgVersion)); - (void)tjsonAddStringToObject(item, "vgVersion", i642str(pObj->vgVersion)); - (void)tjsonAddStringToObject(item, "numOfVgroups", i642str(pObj->cfg.numOfVgroups)); - (void)tjsonAddStringToObject(item, "numOfStables", i642str(pObj->cfg.numOfStables)); - (void)tjsonAddStringToObject(item, "buffer", i642str(pObj->cfg.buffer)); - (void)tjsonAddStringToObject(item, "pageSize", i642str(pObj->cfg.pageSize)); - (void)tjsonAddStringToObject(item, "pages", i642str(pObj->cfg.pages)); - (void)tjsonAddStringToObject(item, "cacheLastSize", i642str(pObj->cfg.cacheLastSize)); - (void)tjsonAddStringToObject(item, "daysPerFile", i642str(pObj->cfg.daysPerFile)); - (void)tjsonAddStringToObject(item, "daysToKeep0", i642str(pObj->cfg.daysToKeep0)); - (void)tjsonAddStringToObject(item, "daysToKeep1", i642str(pObj->cfg.daysToKeep1)); - (void)tjsonAddStringToObject(item, "daysToKeep2", i642str(pObj->cfg.daysToKeep2)); - (void)tjsonAddStringToObject(item, "minRows", i642str(pObj->cfg.minRows)); - (void)tjsonAddStringToObject(item, "maxRows", i642str(pObj->cfg.maxRows)); - (void)tjsonAddStringToObject(item, "precision", i642str(pObj->cfg.precision)); - (void)tjsonAddStringToObject(item, "compression", i642str(pObj->cfg.compression)); - (void)tjsonAddStringToObject(item, "encryptAlgorithm", i642str(pObj->cfg.encryptAlgorithm)); - (void)tjsonAddStringToObject(item, "replications", i642str(pObj->cfg.replications)); - (void)tjsonAddStringToObject(item, "strict", i642str(pObj->cfg.strict)); - (void)tjsonAddStringToObject(item, "cacheLast", i642str(pObj->cfg.cacheLast)); - (void)tjsonAddStringToObject(item, "hashMethod", i642str(pObj->cfg.hashMethod)); - (void)tjsonAddStringToObject(item, "hashPrefix", i642str(pObj->cfg.hashPrefix)); - (void)tjsonAddStringToObject(item, "hashSuffix", i642str(pObj->cfg.hashSuffix)); - (void)tjsonAddStringToObject(item, "sstTrigger", i642str(pObj->cfg.sstTrigger)); - (void)tjsonAddStringToObject(item, "tsdbPageSize", i642str(pObj->cfg.tsdbPageSize)); - (void)tjsonAddStringToObject(item, "schemaless", i642str(pObj->cfg.schemaless)); - (void)tjsonAddStringToObject(item, "walLevel", i642str(pObj->cfg.walLevel)); - (void)tjsonAddStringToObject(item, "walFsyncPeriod", i642str(pObj->cfg.walFsyncPeriod)); - (void)tjsonAddStringToObject(item, "walRetentionPeriod", i642str(pObj->cfg.walRetentionPeriod)); - (void)tjsonAddStringToObject(item, "walRetentionSize", i642str(pObj->cfg.walRetentionSize)); - (void)tjsonAddStringToObject(item, "walRollPeriod", i642str(pObj->cfg.walRollPeriod)); - (void)tjsonAddStringToObject(item, "walSegmentSize", i642str(pObj->cfg.walSegmentSize)); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "name", mndGetDbStr(pObj->name)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "acct", pObj->acct), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createUser", pObj->createUser), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "uid", i642str(pObj->uid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "cfgVersion", i642str(pObj->cfgVersion)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "vgVersion", i642str(pObj->vgVersion)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "numOfVgroups", i642str(pObj->cfg.numOfVgroups)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "numOfStables", i642str(pObj->cfg.numOfStables)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "buffer", i642str(pObj->cfg.buffer)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "pageSize", i642str(pObj->cfg.pageSize)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "pages", i642str(pObj->cfg.pages)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "cacheLastSize", i642str(pObj->cfg.cacheLastSize)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "daysPerFile", i642str(pObj->cfg.daysPerFile)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "daysToKeep0", i642str(pObj->cfg.daysToKeep0)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "daysToKeep1", i642str(pObj->cfg.daysToKeep1)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "daysToKeep2", i642str(pObj->cfg.daysToKeep2)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "minRows", i642str(pObj->cfg.minRows)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "maxRows", i642str(pObj->cfg.maxRows)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "precision", i642str(pObj->cfg.precision)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "compression", i642str(pObj->cfg.compression)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "encryptAlgorithm", i642str(pObj->cfg.encryptAlgorithm)), pObj, + &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "replications", i642str(pObj->cfg.replications)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "strict", i642str(pObj->cfg.strict)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "cacheLast", i642str(pObj->cfg.cacheLast)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "hashMethod", i642str(pObj->cfg.hashMethod)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "hashPrefix", i642str(pObj->cfg.hashPrefix)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "hashSuffix", i642str(pObj->cfg.hashSuffix)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "sstTrigger", i642str(pObj->cfg.sstTrigger)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "tsdbPageSize", i642str(pObj->cfg.tsdbPageSize)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "schemaless", i642str(pObj->cfg.schemaless)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "walLevel", i642str(pObj->cfg.walLevel)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "walFsyncPeriod", i642str(pObj->cfg.walFsyncPeriod)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "walRetentionPeriod", i642str(pObj->cfg.walRetentionPeriod)), pObj, + &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "walRetentionSize", i642str(pObj->cfg.walRetentionSize)), pObj, + &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "walRollPeriod", i642str(pObj->cfg.walRollPeriod)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "walSegmentSize", i642str(pObj->cfg.walSegmentSize)), pObj, &lino, + _OVER); - (void)tjsonAddStringToObject(item, "numOfRetensions", i642str(pObj->cfg.numOfRetensions)); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "numOfRetensions", i642str(pObj->cfg.numOfRetensions)), pObj, + &lino, _OVER); for (int32_t i = 0; i < pObj->cfg.numOfRetensions; ++i) { SJson *rentensions = tjsonAddArrayToObject(item, "rentensions"); SJson *rentension = tjsonCreateObject(); - (void)tjsonAddItemToArray(rentensions, rentension); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(rentensions, rentension), pObj, &lino, _OVER); SRetention *pRetension = taosArrayGet(pObj->cfg.pRetensions, i); - (void)tjsonAddStringToObject(item, "freq", i642str(pRetension->freq)); - (void)tjsonAddStringToObject(item, "freqUnit", i642str(pRetension->freqUnit)); - (void)tjsonAddStringToObject(item, "keep", i642str(pRetension->keep)); - (void)tjsonAddStringToObject(item, "keepUnit", i642str(pRetension->keepUnit)); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "freq", i642str(pRetension->freq)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "freqUnit", i642str(pRetension->freqUnit)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "keep", i642str(pRetension->keep)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "keepUnit", i642str(pRetension->keepUnit)), pObj, &lino, _OVER); } sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump db info at line:%d since %s", lino, tstrerror(code)); } void dumpStb(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "stbs"); @@ -150,62 +178,67 @@ void dumpStb(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "name", mndGetStbStr(pObj->name)); - (void)tjsonAddStringToObject(item, "db", mndGetDbStr(pObj->db)); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); - (void)tjsonAddStringToObject(item, "uid", i642str(pObj->uid)); - (void)tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)); - (void)tjsonAddStringToObject(item, "tagVer", i642str(pObj->tagVer)); - (void)tjsonAddStringToObject(item, "colVer", i642str(pObj->colVer)); - (void)tjsonAddStringToObject(item, "smaVer", i642str(pObj->smaVer)); - (void)tjsonAddStringToObject(item, "nextColId", i642str(pObj->nextColId)); - (void)tjsonAddStringToObject(item, "watermark1", i642str(pObj->watermark[0])); - (void)tjsonAddStringToObject(item, "watermark2", i642str(pObj->watermark[1])); - (void)tjsonAddStringToObject(item, "maxdelay0", i642str(pObj->maxdelay[0])); - (void)tjsonAddStringToObject(item, "maxdelay1", i642str(pObj->maxdelay[1])); - (void)tjsonAddStringToObject(item, "ttl", i642str(pObj->ttl)); - (void)tjsonAddStringToObject(item, "numOfFuncs", i642str(pObj->numOfFuncs)); - (void)tjsonAddStringToObject(item, "commentLen", i642str(pObj->commentLen)); - (void)tjsonAddStringToObject(item, "ast1Len", i642str(pObj->ast1Len)); - (void)tjsonAddStringToObject(item, "ast2Len", i642str(pObj->ast2Len)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "name", mndGetStbStr(pObj->name)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "db", mndGetDbStr(pObj->db)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "uid", i642str(pObj->uid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "tagVer", i642str(pObj->tagVer)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "colVer", i642str(pObj->colVer)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "smaVer", i642str(pObj->smaVer)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "nextColId", i642str(pObj->nextColId)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "watermark1", i642str(pObj->watermark[0])), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "watermark2", i642str(pObj->watermark[1])), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "maxdelay0", i642str(pObj->maxdelay[0])), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "maxdelay1", i642str(pObj->maxdelay[1])), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "ttl", i642str(pObj->ttl)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "numOfFuncs", i642str(pObj->numOfFuncs)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "commentLen", i642str(pObj->commentLen)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "ast1Len", i642str(pObj->ast1Len)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "ast2Len", i642str(pObj->ast2Len)), pObj, &lino, _OVER); - (void)tjsonAddStringToObject(item, "numOfColumns", i642str(pObj->numOfColumns)); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "numOfColumns", i642str(pObj->numOfColumns)), pObj, &lino, _OVER); SJson *columns = tjsonAddArrayToObject(item, "columns"); for (int32_t i = 0; i < pObj->numOfColumns; ++i) { SJson *column = tjsonCreateObject(); - (void)tjsonAddItemToArray(columns, column); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(columns, column), pObj, &lino, _OVER); SSchema *pColumn = &pObj->pColumns[i]; - (void)tjsonAddStringToObject(column, "type", i642str(pColumn->type)); - (void)tjsonAddStringToObject(column, "typestr", tDataTypes[pColumn->type].name); - (void)tjsonAddStringToObject(column, "flags", i642str(pColumn->flags)); - (void)tjsonAddStringToObject(column, "colId", i642str(pColumn->colId)); - (void)tjsonAddStringToObject(column, "bytes", i642str(pColumn->bytes)); - (void)tjsonAddStringToObject(column, "name", pColumn->name); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(column, "type", i642str(pColumn->type)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(column, "typestr", tDataTypes[pColumn->type].name), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(column, "flags", i642str(pColumn->flags)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(column, "colId", i642str(pColumn->colId)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(column, "bytes", i642str(pColumn->bytes)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(column, "name", pColumn->name), pObj, &lino, _OVER); } - (void)tjsonAddStringToObject(item, "numOfTags", i642str(pObj->numOfTags)); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "numOfTags", i642str(pObj->numOfTags)), pObj, &lino, _OVER); SJson *tags = tjsonAddArrayToObject(item, "tags"); for (int32_t i = 0; i < pObj->numOfTags; ++i) { SJson *tag = tjsonCreateObject(); - (void)tjsonAddItemToArray(tags, tag); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(tags, tag), pObj, &lino, _OVER); SSchema *pTag = &pObj->pTags[i]; - (void)tjsonAddStringToObject(tag, "type", i642str(pTag->type)); - (void)tjsonAddStringToObject(tag, "typestr", tDataTypes[pTag->type].name); - (void)tjsonAddStringToObject(tag, "flags", i642str(pTag->flags)); - (void)tjsonAddStringToObject(tag, "colId", i642str(pTag->colId)); - (void)tjsonAddStringToObject(tag, "bytes", i642str(pTag->bytes)); - (void)tjsonAddStringToObject(tag, "name", pTag->name); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(tag, "type", i642str(pTag->type)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(tag, "typestr", tDataTypes[pTag->type].name), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(tag, "flags", i642str(pTag->flags)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(tag, "colId", i642str(pTag->colId)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(tag, "bytes", i642str(pTag->bytes)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(tag, "name", pTag->name), pObj, &lino, _OVER); } sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump stable info at line:%d since %s", lino, tstrerror(code)); } void dumpSma(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "smas"); @@ -215,32 +248,37 @@ void dumpSma(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "name", mndGetStbStr(pObj->name)); - (void)tjsonAddStringToObject(item, "stb", mndGetStbStr(pObj->stb)); - (void)tjsonAddStringToObject(item, "db", mndGetDbStr(pObj->db)); - (void)tjsonAddStringToObject(item, "dstTbName", mndGetStbStr(pObj->dstTbName)); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "uid", i642str(pObj->uid)); - (void)tjsonAddStringToObject(item, "stbUid", i642str(pObj->stbUid)); - (void)tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)); - (void)tjsonAddStringToObject(item, "dstTbUid", i642str(pObj->dstTbUid)); - (void)tjsonAddStringToObject(item, "intervalUnit", i642str(pObj->intervalUnit)); - (void)tjsonAddStringToObject(item, "slidingUnit", i642str(pObj->slidingUnit)); - (void)tjsonAddStringToObject(item, "timezone", i642str(pObj->timezone)); - (void)tjsonAddStringToObject(item, "dstVgId", i642str(pObj->dstVgId)); - (void)tjsonAddStringToObject(item, "interval", i642str(pObj->interval)); - (void)tjsonAddStringToObject(item, "offset", i642str(pObj->offset)); - (void)tjsonAddStringToObject(item, "sliding", i642str(pObj->sliding)); - (void)tjsonAddStringToObject(item, "exprLen", i642str(pObj->exprLen)); - (void)tjsonAddStringToObject(item, "tagsFilterLen", i642str(pObj->tagsFilterLen)); - (void)tjsonAddStringToObject(item, "sqlLen", i642str(pObj->sqlLen)); - (void)tjsonAddStringToObject(item, "astLen", i642str(pObj->astLen)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "name", mndGetStbStr(pObj->name)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "stb", mndGetStbStr(pObj->stb)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "db", mndGetDbStr(pObj->db)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "dstTbName", mndGetStbStr(pObj->dstTbName)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "uid", i642str(pObj->uid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "stbUid", i642str(pObj->stbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "dstTbUid", i642str(pObj->dstTbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "intervalUnit", i642str(pObj->intervalUnit)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "slidingUnit", i642str(pObj->slidingUnit)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "timezone", i642str(pObj->timezone)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "dstVgId", i642str(pObj->dstVgId)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "interval", i642str(pObj->interval)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "offset", i642str(pObj->offset)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "sliding", i642str(pObj->sliding)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "exprLen", i642str(pObj->exprLen)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "tagsFilterLen", i642str(pObj->tagsFilterLen)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "sqlLen", i642str(pObj->sqlLen)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "astLen", i642str(pObj->astLen)), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump sma info at line:%d since %s", lino, tstrerror(code)); } void dumpVgroup(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "vgroups"); @@ -250,28 +288,33 @@ void dumpVgroup(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "vgId", i642str(pObj->vgId)); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); - (void)tjsonAddStringToObject(item, "version", i642str(pObj->version)); - (void)tjsonAddStringToObject(item, "hashBegin", i642str(pObj->hashBegin)); - (void)tjsonAddStringToObject(item, "hashEnd", i642str(pObj->hashEnd)); - (void)tjsonAddStringToObject(item, "db", mndGetDbStr(pObj->dbName)); - (void)tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)); - (void)tjsonAddStringToObject(item, "isTsma", i642str(pObj->isTsma)); - (void)tjsonAddStringToObject(item, "replica", i642str(pObj->replica)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "vgId", i642str(pObj->vgId)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "version", i642str(pObj->version)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "hashBegin", i642str(pObj->hashBegin)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "hashEnd", i642str(pObj->hashEnd)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "db", mndGetDbStr(pObj->dbName)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "isTsma", i642str(pObj->isTsma)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "replica", i642str(pObj->replica)), pObj, &lino, _OVER); for (int32_t i = 0; i < pObj->replica; ++i) { SJson *replicas = tjsonAddArrayToObject(item, "replicas"); SJson *replica = tjsonCreateObject(); - (void)tjsonAddItemToArray(replicas, replica); - (void)tjsonAddStringToObject(replica, "dnodeId", i642str(pObj->vnodeGid[i].dnodeId)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(replicas, replica), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(replica, "dnodeId", i642str(pObj->vnodeGid[i].dnodeId)), pObj, &lino, + _OVER); } sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump vgroup info at line:%d since %s", lino, tstrerror(code)); } void dumpTopic(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "topics"); @@ -281,28 +324,32 @@ void dumpTopic(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "name", mndGetDbStr(pObj->name)); - (void)tjsonAddStringToObject(item, "name", mndGetDbStr(pObj->db)); - (void)tjsonAddStringToObject(item, "createTime", i642str(pObj->createTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); - (void)tjsonAddStringToObject(item, "uid", i642str(pObj->uid)); - (void)tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)); - (void)tjsonAddStringToObject(item, "version", i642str(pObj->version)); - (void)tjsonAddStringToObject(item, "subType", i642str(pObj->subType)); - (void)tjsonAddStringToObject(item, "withMeta", i642str(pObj->withMeta)); - (void)tjsonAddStringToObject(item, "stbUid", i642str(pObj->stbUid)); - (void)tjsonAddStringToObject(item, "stbName", mndGetStableStr(pObj->stbName)); - (void)tjsonAddStringToObject(item, "sqlLen", i642str(pObj->sqlLen)); - (void)tjsonAddStringToObject(item, "astLen", i642str(pObj->astLen)); - (void)tjsonAddStringToObject(item, "sqlLen", i642str(pObj->sqlLen)); - (void)tjsonAddStringToObject(item, "ntbUid", i642str(pObj->ntbUid)); - (void)tjsonAddStringToObject(item, "ctbStbUid", i642str(pObj->ctbStbUid)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "name", mndGetDbStr(pObj->name)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "name", mndGetDbStr(pObj->db)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createTime", i642str(pObj->createTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "uid", i642str(pObj->uid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "version", i642str(pObj->version)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "subType", i642str(pObj->subType)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "withMeta", i642str(pObj->withMeta)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "stbUid", i642str(pObj->stbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "stbName", mndGetStableStr(pObj->stbName)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "sqlLen", i642str(pObj->sqlLen)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "astLen", i642str(pObj->astLen)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "sqlLen", i642str(pObj->sqlLen)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "ntbUid", i642str(pObj->ntbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "ctbStbUid", i642str(pObj->ctbStbUid)), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump topic info at line:%d since %s", lino, tstrerror(code)); } void dumpConsumer(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "consumers"); @@ -312,14 +359,18 @@ void dumpConsumer(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "consumerId", i642str(pObj->consumerId)); - (void)tjsonAddStringToObject(item, "cgroup", pObj->cgroup); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "consumerId", i642str(pObj->consumerId)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "cgroup", pObj->cgroup), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump consumer info at line:%d since %s", lino, tstrerror(code)); } void dumpSubscribe(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "subscribes"); @@ -329,16 +380,20 @@ void dumpSubscribe(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "key", pObj->key); - (void)tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)); - (void)tjsonAddStringToObject(item, "stbUid", i642str(pObj->stbUid)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "key", pObj->key), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "dbUid", i642str(pObj->dbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "stbUid", i642str(pObj->stbUid)), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump subscribe info at line:%d since %s", lino, tstrerror(code)); } void dumpStream(SSdb *pSdb, SJson *json) { - void *pIter = NULL; + int32_t code = 0; + int32_t lino = 0; + void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "streams"); while (1) { @@ -347,31 +402,38 @@ void dumpStream(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "name", mndGetDbStr(pObj->name)); - (void)tjsonAddStringToObject(item, "createTime", i642str(pObj->createTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); - (void)tjsonAddStringToObject(item, "version", i642str(pObj->version)); - (void)tjsonAddStringToObject(item, "totalLevel", i642str(pObj->totalLevel)); - (void)tjsonAddStringToObject(item, "smaId", i642str(pObj->smaId)); - (void)tjsonAddStringToObject(item, "uid", i642str(pObj->uid)); - (void)tjsonAddStringToObject(item, "status", i642str(pObj->status)); - (void)tjsonAddStringToObject(item, "igExpired", i642str(pObj->conf.igExpired)); - (void)tjsonAddStringToObject(item, "trigger", i642str(pObj->conf.trigger)); - (void)tjsonAddStringToObject(item, "triggerParam", i642str(pObj->conf.triggerParam)); - (void)tjsonAddStringToObject(item, "watermark", i642str(pObj->conf.watermark)); - (void)tjsonAddStringToObject(item, "sourceDbUid", i642str(pObj->sourceDbUid)); - (void)tjsonAddStringToObject(item, "targetDbUid", i642str(pObj->targetDbUid)); - (void)tjsonAddStringToObject(item, "sourceDb", mndGetDbStr(pObj->sourceDb)); - (void)tjsonAddStringToObject(item, "targetDb", mndGetDbStr(pObj->targetDb)); - (void)tjsonAddStringToObject(item, "targetSTbName", mndGetStbStr(pObj->targetSTbName)); - (void)tjsonAddStringToObject(item, "targetStbUid", i642str(pObj->targetStbUid)); - (void)tjsonAddStringToObject(item, "fixedSinkVgId", i642str(pObj->fixedSinkVgId)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "name", mndGetDbStr(pObj->name)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createTime", i642str(pObj->createTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "version", i642str(pObj->version)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "totalLevel", i642str(pObj->totalLevel)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "smaId", i642str(pObj->smaId)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "uid", i642str(pObj->uid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "status", i642str(pObj->status)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "igExpired", i642str(pObj->conf.igExpired)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "trigger", i642str(pObj->conf.trigger)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "triggerParam", i642str(pObj->conf.triggerParam)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "watermark", i642str(pObj->conf.watermark)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "sourceDbUid", i642str(pObj->sourceDbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "targetDbUid", i642str(pObj->targetDbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "sourceDb", mndGetDbStr(pObj->sourceDb)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "targetDb", mndGetDbStr(pObj->targetDb)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "targetSTbName", mndGetStbStr(pObj->targetSTbName)), pObj, &lino, + _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "targetStbUid", i642str(pObj->targetStbUid)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "fixedSinkVgId", i642str(pObj->fixedSinkVgId)), pObj, &lino, + _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump stream info at line:%d since %s", lino, tstrerror(code)); } void dumpAcct(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "accts"); @@ -381,13 +443,15 @@ void dumpAcct(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "acct", pObj->acct); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); - (void)tjsonAddStringToObject(item, "acctId", i642str(pObj->acctId)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "acct", pObj->acct), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "acctId", i642str(pObj->acctId)), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump acct info at line:%d since %s", lino, tstrerror(code)); } void dumpAuth(SSdb *pSdb, SJson *json) { @@ -395,6 +459,8 @@ void dumpAuth(SSdb *pSdb, SJson *json) { } void dumpUser(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "users"); @@ -404,21 +470,27 @@ void dumpUser(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "name", pObj->user); - (void)tjsonAddStringToObject(item, "acct", pObj->acct); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); - (void)tjsonAddStringToObject(item, "superUser", i642str(pObj->superUser)); - (void)tjsonAddStringToObject(item, "authVersion", i642str(pObj->authVersion)); - (void)tjsonAddStringToObject(item, "passVersion", i642str(pObj->passVersion)); - (void)tjsonAddStringToObject(item, "numOfReadDbs", i642str(taosHashGetSize(pObj->readDbs))); - (void)tjsonAddStringToObject(item, "numOfWriteDbs", i642str(taosHashGetSize(pObj->writeDbs))); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "name", pObj->user), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "acct", pObj->acct), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "superUser", i642str(pObj->superUser)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "authVersion", i642str(pObj->authVersion)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "passVersion", i642str(pObj->passVersion)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "numOfReadDbs", i642str(taosHashGetSize(pObj->readDbs))), pObj, + &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "numOfWriteDbs", i642str(taosHashGetSize(pObj->writeDbs))), pObj, + &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump user info at line:%d since %s", lino, tstrerror(code)); } void dumpDnode(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "dnodes"); @@ -428,17 +500,21 @@ void dumpDnode(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "id", i642str(pObj->id)); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); - (void)tjsonAddStringToObject(item, "port", i642str(pObj->port)); - (void)tjsonAddStringToObject(item, "fqdn", pObj->fqdn); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "id", i642str(pObj->id)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "port", i642str(pObj->port)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "fqdn", pObj->fqdn), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump dnode info at line:%d since %s", lino, tstrerror(code)); } void dumpSnode(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "snodes"); @@ -448,15 +524,19 @@ void dumpSnode(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "id", i642str(pObj->id)); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "id", i642str(pObj->id)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump snode info at line:%d since %s", lino, tstrerror(code)); } void dumpQnode(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "qnodes"); @@ -466,15 +546,19 @@ void dumpQnode(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "id", i642str(pObj->id)); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "id", i642str(pObj->id)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump qnode info at line:%d since %s", lino, tstrerror(code)); } void dumpMnode(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "mnodes"); @@ -484,15 +568,20 @@ void dumpMnode(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "id", i642str(pObj->id)); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "id", i642str(pObj->id)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } +_OVER: + if (code != 0) mError("failed to dump mnode info at line:%d since %s", lino, tstrerror(code)); } void dumpCluster(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; + void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "clusters"); @@ -502,16 +591,21 @@ void dumpCluster(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "id", i642str(pObj->id)); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)); - (void)tjsonAddStringToObject(item, "name", pObj->name); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "id", i642str(pObj->id)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "updateTime", i642str(pObj->updateTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "name", pObj->name), pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } + +_OVER: + if (code != 0) mError("failed to dump cluster info at line:%d since %s", lino, tstrerror(code)); } void dumpTrans(SSdb *pSdb, SJson *json) { + int32_t code = 0; + int32_t lino = 0; void *pIter = NULL; SJson *items = tjsonAddArrayToObject(json, "transactions"); @@ -521,53 +615,64 @@ void dumpTrans(SSdb *pSdb, SJson *json) { if (pIter == NULL) break; SJson *item = tjsonCreateObject(); - (void)tjsonAddItemToArray(items, item); - (void)tjsonAddStringToObject(item, "id", i642str(pObj->id)); - (void)tjsonAddStringToObject(item, "stage", i642str(pObj->stage)); - (void)tjsonAddStringToObject(item, "policy", i642str(pObj->policy)); - (void)tjsonAddStringToObject(item, "conflict", i642str(pObj->conflict)); - (void)tjsonAddStringToObject(item, "exec", i642str(pObj->exec)); - (void)tjsonAddStringToObject(item, "oper", i642str(pObj->oper)); - (void)tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)); - (void)tjsonAddStringToObject(item, "dbname", pObj->dbname); - (void)tjsonAddStringToObject(item, "stbname", pObj->stbname); - (void)tjsonAddStringToObject(item, "opername", pObj->opername); - (void)tjsonAddStringToObject(item, "commitLogNum", i642str(taosArrayGetSize(pObj->commitActions))); - (void)tjsonAddStringToObject(item, "redoActionNum", i642str(taosArrayGetSize(pObj->redoActions))); - (void)tjsonAddStringToObject(item, "undoActionNum", i642str(taosArrayGetSize(pObj->undoActions))); + RETRIEVE_CHECK_GOTO(tjsonAddItemToArray(items, item), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "id", i642str(pObj->id)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "stage", i642str(pObj->stage)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "policy", i642str(pObj->policy)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "conflict", i642str(pObj->conflict)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "exec", i642str(pObj->exec)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "oper", i642str(pObj->oper)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "createdTime", i642str(pObj->createdTime)), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "dbname", pObj->dbname), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "stbname", pObj->stbname), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "opername", pObj->opername), pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "commitLogNum", i642str(taosArrayGetSize(pObj->commitActions))), + pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "redoActionNum", i642str(taosArrayGetSize(pObj->redoActions))), + pObj, &lino, _OVER); + RETRIEVE_CHECK_GOTO(tjsonAddStringToObject(item, "undoActionNum", i642str(taosArrayGetSize(pObj->undoActions))), + pObj, &lino, _OVER); sdbRelease(pSdb, pObj); } + +_OVER: + if (code != 0) mError("failed to dump trans info at line:%d since %s", lino, tstrerror(code)); } void dumpHeader(SSdb *pSdb, SJson *json) { - (void)tjsonAddStringToObject(json, "sver", i642str(1)); - (void)tjsonAddStringToObject(json, "applyIndex", i642str(pSdb->applyIndex)); - (void)tjsonAddStringToObject(json, "applyTerm", i642str(pSdb->applyTerm)); - (void)tjsonAddStringToObject(json, "applyConfig", i642str(pSdb->applyConfig)); + int32_t code = 0; + int32_t lino = 0; + TAOS_CHECK_GOTO(tjsonAddStringToObject(json, "sver", i642str(1)), &lino, _OVER); + TAOS_CHECK_GOTO(tjsonAddStringToObject(json, "applyIndex", i642str(pSdb->applyIndex)), &lino, _OVER); + TAOS_CHECK_GOTO(tjsonAddStringToObject(json, "applyTerm", i642str(pSdb->applyTerm)), &lino, _OVER); + TAOS_CHECK_GOTO(tjsonAddStringToObject(json, "applyConfig", i642str(pSdb->applyConfig)), &lino, _OVER); SJson *maxIdsJson = tjsonCreateObject(); - (void)tjsonAddItemToObject(json, "maxIds", maxIdsJson); + TAOS_CHECK_GOTO(tjsonAddItemToObject(json, "maxIds", maxIdsJson), &lino, _OVER); for (int32_t i = 0; i < SDB_MAX; ++i) { if(i == 5) continue; int64_t maxId = 0; if (i < SDB_MAX) { maxId = pSdb->maxId[i]; } - (void)tjsonAddStringToObject(maxIdsJson, sdbTableName(i), i642str(maxId)); + TAOS_CHECK_GOTO(tjsonAddStringToObject(maxIdsJson, sdbTableName(i), i642str(maxId)), &lino, _OVER); } SJson *tableVersJson = tjsonCreateObject(); - (void)tjsonAddItemToObject(json, "tableVers", tableVersJson); + TAOS_CHECK_GOTO(tjsonAddItemToObject(json, "tableVers", tableVersJson), &lino, _OVER); for (int32_t i = 0; i < SDB_MAX; ++i) { int64_t tableVer = 0; if (i < SDB_MAX) { tableVer = pSdb->tableVer[i]; } - (void)tjsonAddStringToObject(tableVersJson, sdbTableName(i), i642str(tableVer)); + TAOS_CHECK_GOTO(tjsonAddStringToObject(tableVersJson, sdbTableName(i), i642str(tableVer)), &lino, _OVER); } + +_OVER: + if (code != 0) mError("failed to dump sdb info at line:%d since %s", lino, tstrerror(code)); } -void mndDumpSdb() { +int32_t mndDumpSdb() { mInfo("start to dump sdb info to sdb.json"); char path[PATH_MAX * 2] = {0}; @@ -581,12 +686,12 @@ void mndDumpSdb() { msgCb.mgmt = (SMgmtWrapper *)(&msgCb); // hack tmsgSetDefault(&msgCb); - (void)walInit(NULL); - (void)syncInit(); + TAOS_CHECK_RETURN(walInit(NULL)); + TAOS_CHECK_RETURN(syncInit()); SMnodeOpt opt = {.msgCb = msgCb}; SMnode *pMnode = mndOpen(path, &opt); - if (pMnode == NULL) return; + if (pMnode == NULL) return -1; SSdb *pSdb = pMnode->pSdb; SJson *json = tjsonCreateObject(); @@ -616,21 +721,21 @@ void mndDumpSdb() { char file[] = "sdb.json"; TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) { - terrno = terrno; mError("failed to write %s since %s", file, terrstr()); - return; + return terrno; } - (void)taosWriteFile(pFile, pCont, contLen); - (void)taosWriteFile(pFile, "\n", 1); - UNUSED(taosFsyncFile(pFile)); - (void)taosCloseFile(&pFile); + TAOS_CHECK_RETURN(taosWriteFile(pFile, pCont, contLen)); + TAOS_CHECK_RETURN(taosWriteFile(pFile, "\n", 1)); + TAOS_CHECK_RETURN(taosFsyncFile(pFile)); + TAOS_CHECK_RETURN(taosCloseFile(&pFile)); tjsonDelete(json); taosMemoryFree(pCont); mInfo("dump sdb info success"); + return 0; } -void mndDeleteTrans() { +int32_t mndDeleteTrans() { mInfo("start to dump sdb info to sdb.json"); char path[PATH_MAX * 2] = {0}; @@ -644,16 +749,18 @@ void mndDeleteTrans() { msgCb.mgmt = (SMgmtWrapper *)(&msgCb); // hack tmsgSetDefault(&msgCb); - (void)walInit(NULL); - (void)syncInit(); + TAOS_CHECK_RETURN(walInit(NULL)); + TAOS_CHECK_RETURN(syncInit()); SMnodeOpt opt = {.msgCb = msgCb}; SMnode *pMnode = mndOpen(path, &opt); - if (pMnode == NULL) return; + if (pMnode == NULL) return terrno; - (void)sdbWriteFileForDump(pMnode->pSdb); + TAOS_CHECK_RETURN(sdbWriteFileForDump(pMnode->pSdb)); mInfo("dump sdb info success"); + + return 0; } #pragma GCC diagnostic pop diff --git a/source/dnode/mnode/impl/src/mndFunc.c b/source/dnode/mnode/impl/src/mndFunc.c index 9e97aa674b..4c5a695402 100644 --- a/source/dnode/mnode/impl/src/mndFunc.c +++ b/source/dnode/mnode/impl/src/mndFunc.c @@ -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); diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index a0dd30f11a..eb855d28a8 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -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__); + } } } @@ -210,10 +232,15 @@ static void mndPullupGrant(SMnode *pMnode) { int32_t contLen = 0; void *pReq = mndBuildTimerMsg(&contLen); if (pReq != NULL) { - SRpcMsg rpcMsg = { - .msgType = TDMT_MND_GRANT_HB_TIMER, .pCont = pReq, .contLen = contLen, .info.ahandle = (void *)0x9527}; + SRpcMsg rpcMsg = {.msgType = TDMT_MND_GRANT_HB_TIMER, + .pCont = pReq, + .contLen = contLen, + .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__); + } } } @@ -222,10 +249,15 @@ static void mndIncreaseUpTime(SMnode *pMnode) { int32_t contLen = 0; void *pReq = mndBuildTimerMsg(&contLen); if (pReq != NULL) { - SRpcMsg rpcMsg = { - .msgType = TDMT_MND_UPTIME_TIMER, .pCont = pReq, .contLen = contLen, .info.ahandle = (void *)0x9528}; + SRpcMsg rpcMsg = {.msgType = TDMT_MND_UPTIME_TIMER, + .pCont = pReq, + .contLen = contLen, + .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__); + } } } @@ -676,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; @@ -721,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)); + } } } @@ -872,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; } @@ -1039,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; @@ -1077,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) { diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index 0af0312b62..c00c88c4f9 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -14,10 +14,10 @@ */ #define _DEFAULT_SOURCE -#include "mndMnode.h" #include "audit.h" #include "mndCluster.h" #include "mndDnode.h" +#include "mndMnode.h" #include "mndPrivilege.h" #include "mndShow.h" #include "mndSync.h" @@ -114,7 +114,7 @@ static int32_t mndCreateDefaultMnode(SMnode *pMnode) { mndTransDrop(pTrans); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); + TAOS_CHECK_RETURN(sdbSetRawStatus(pRaw, SDB_STATUS_READY)); if ((code = mndTransPrepare(pMnode, pTrans)) != 0) { mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); @@ -270,19 +270,21 @@ void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet) { } } if (pObj->pDnode != NULL) { - (void)addEpIntoEpSet(pEpSet, pObj->pDnode->fqdn, pObj->pDnode->port); + if (addEpIntoEpSet(pEpSet, pObj->pDnode->fqdn, pObj->pDnode->port) != 0) { + mError("mnode:%d, failed to add ep:%s:%d into epset", pObj->id, pObj->pDnode->fqdn, pObj->pDnode->port); + } + sdbRelease(pSdb, pObj); } - sdbRelease(pSdb, pObj); - } - if (pEpSet->numOfEps == 0) { - syncGetRetryEpSet(pMnode->syncMgmt.sync, pEpSet); - } + if (pEpSet->numOfEps == 0) { + syncGetRetryEpSet(pMnode->syncMgmt.sync, pEpSet); + } - if (pEpSet->inUse >= pEpSet->numOfEps) { - pEpSet->inUse = 0; + if (pEpSet->inUse >= pEpSet->numOfEps) { + pEpSet->inUse = 0; + } + epsetSort(pEpSet); } - epsetSort(pEpSet); } static int32_t mndSetCreateMnodeRedoLogs(SMnode *pMnode, STrans *pTrans, SMnodeObj *pObj) { @@ -341,7 +343,11 @@ static int32_t mndBuildCreateMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *p int32_t code = 0; int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pCreateReq); void *pReq = taosMemoryMalloc(contLen); - (void)tSerializeSDCreateMnodeReq(pReq, contLen, pCreateReq); + code = tSerializeSDCreateMnodeReq(pReq, contLen, pCreateReq); + if (code < 0) { + taosMemoryFree(pReq); + TAOS_RETURN(code); + } STransAction action = { .epSet = *pCreateEpSet, @@ -363,7 +369,11 @@ static int32_t mndBuildAlterMnodeTypeRedoAction(STrans *pTrans, SDAlterMnodeType int32_t code = 0; int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pAlterMnodeTypeReq); void *pReq = taosMemoryMalloc(contLen); - (void)tSerializeSDCreateMnodeReq(pReq, contLen, pAlterMnodeTypeReq); + code = tSerializeSDCreateMnodeReq(pReq, contLen, pAlterMnodeTypeReq); + if (code < 0) { + taosMemoryFree(pReq); + TAOS_RETURN(code); + } STransAction action = { .epSet = *pAlterMnodeTypeEpSet, @@ -385,8 +395,11 @@ static int32_t mndBuildAlterMnodeRedoAction(STrans *pTrans, SDCreateMnodeReq *pA int32_t code = 0; int32_t contLen = tSerializeSDCreateMnodeReq(NULL, 0, pAlterReq); void *pReq = taosMemoryMalloc(contLen); - (void)tSerializeSDCreateMnodeReq(pReq, contLen, pAlterReq); - + code = tSerializeSDCreateMnodeReq(pReq, contLen, pAlterReq); + if (code < 0) { + taosMemoryFree(pReq); + TAOS_RETURN(code); + } STransAction action = { .epSet = *pAlterEpSet, .pCont = pReq, @@ -407,7 +420,11 @@ static int32_t mndBuildDropMnodeRedoAction(STrans *pTrans, SDDropMnodeReq *pDrop int32_t code = 0; int32_t contLen = tSerializeSCreateDropMQSNodeReq(NULL, 0, pDropReq); void *pReq = taosMemoryMalloc(contLen); - (void)tSerializeSCreateDropMQSNodeReq(pReq, contLen, pDropReq); + code = tSerializeSCreateDropMQSNodeReq(pReq, contLen, pDropReq); + if (code < 0) { + taosMemoryFree(pReq); + TAOS_RETURN(code); + } STransAction action = { .epSet = *pDroprEpSet, @@ -868,6 +885,7 @@ static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB ESdbStatus objStatus = 0; char *pWrite; int64_t curMs = taosGetTimestampMs(); + int code = 0; pSelfObj = sdbAcquire(pSdb, SDB_MNODE, &pMnode->selfDnodeId); if (pSelfObj == NULL) { @@ -881,13 +899,21 @@ static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB cols = 0; SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->id, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->id, false); + if (code != 0) { + mError("mnode:%d, failed to set col data val since %s", pObj->id, terrstr()); + goto _out; + } char b1[TSDB_EP_LEN + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(b1, pObj->pDnode->ep, TSDB_EP_LEN + VARSTR_HEADER_SIZE); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, b1, false); + code = colDataSetVal(pColInfo, numOfRows, b1, false); + if (code != 0) { + mError("mnode:%d, failed to set col data val since %s", pObj->id, terrstr()); + goto _out; + } char role[20] = "offline"; if (pObj->id == pMnode->selfDnodeId) { @@ -904,8 +930,11 @@ static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB char b2[12 + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(b2, role, 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) { + mError("mnode:%d, failed to set col data val since %s", pObj->id, terrstr()); + goto _out; + } const char *status = "ready"; if (objStatus == SDB_STATUS_CREATING) status = "creating"; if (objStatus == SDB_STATUS_DROPPING) status = "dropping"; @@ -913,14 +942,26 @@ static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB char b3[9 + VARSTR_HEADER_SIZE] = {0}; STR_WITH_MAXSIZE_TO_VARSTR(b3, status, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)b3, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)b3, false); + if (code != 0) { + mError("mnode:%d, failed to set col data val since %s", pObj->id, terrstr()); + goto _out; + } pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->createdTime, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pObj->createdTime, false); + if (code != 0) { + mError("mnode:%d, failed to set col data val since %s", pObj->id, terrstr()); + goto _out; + } int64_t roleTimeMs = (isDnodeOnline) ? pObj->roleTimeMs : 0; pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&roleTimeMs, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&roleTimeMs, false); + if (code != 0) { + mError("mnode:%d, failed to set col data val since %s", pObj->id, terrstr()); + goto _out; + } numOfRows++; sdbRelease(pSdb, pObj); @@ -1005,6 +1046,7 @@ static void mndReloadSyncConfig(SMnode *pMnode) { void *pIter = NULL; int32_t updatingMnodes = 0; int32_t readyMnodes = 0; + int32_t code = 0; SSyncCfg cfg = { .myIndex = -1, .lastIndex = 0, @@ -1030,7 +1072,10 @@ static void mndReloadSyncConfig(SMnode *pMnode) { pNode->nodePort = pObj->pDnode->port; pNode->nodeRole = pObj->role; tstrncpy(pNode->nodeFqdn, pObj->pDnode->fqdn, TSDB_FQDN_LEN); - (void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); + code = tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); + if (code != 0) { + mError("mnode:%d, failed to update dnode info since %s", pObj->id, terrstr()); + } mInfo("vgId:1, ep:%s:%u dnode:%d", pNode->nodeFqdn, pNode->nodePort, pNode->nodeId); if (pObj->pDnode->id == pMnode->selfDnodeId) { cfg.myIndex = cfg.totalReplicaNum; diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 645a187abb..4dc2f093e8 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -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++; } diff --git a/source/dnode/mnode/impl/src/mndQnode.c b/source/dnode/mnode/impl/src/mndQnode.c index 41d292a62f..ba1a88aab3 100644 --- a/source/dnode/mnode/impl/src/mndQnode.c +++ b/source/dnode/mnode/impl/src/mndQnode.c @@ -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); diff --git a/source/dnode/mnode/impl/src/mndSnode.c b/source/dnode/mnode/impl/src/mndSnode.c index 4616f50a79..2fb3d377c4 100644 --- a/source/dnode/mnode/impl/src/mndSnode.c +++ b/source/dnode/mnode/impl/src/mndSnode.c @@ -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); diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 915741ec49..fa9e4fa8fa 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -3626,6 +3626,11 @@ static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)rollup, false), pStb, &lino, _ERROR); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); + if (pColInfo) { + RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)(&pStb->uid), false), pStb, &lino, _ERROR); + } + numOfRows++; sdbRelease(pSdb, pStb); } diff --git a/source/dnode/mnode/impl/src/mndStream.c b/source/dnode/mnode/impl/src/mndStream.c index 886a87975d..e86a9f5681 100644 --- a/source/dnode/mnode/impl/src/mndStream.c +++ b/source/dnode/mnode/impl/src/mndStream.c @@ -62,9 +62,8 @@ static int32_t mndProcessStreamReqCheckpoint(SRpcMsg *pReq); static int32_t mndProcessCheckpointReport(SRpcMsg *pReq); static int32_t mndProcessConsensusInTmr(SRpcMsg *pMsg); static void doSendQuickRsp(SRpcHandleInfo *pInfo, int32_t msgSize, int32_t vgId, int32_t code); -static int32_t mndProcessDropOrphanTaskReq(SRpcMsg* pReq); -static int32_t mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pPrevNodeList, const SArray *pNodeList, SVgroupChangeInfo* pInfo); -static void mndDestroyVgroupChangeInfo(SVgroupChangeInfo *pInfo); +static int32_t mndProcessDropOrphanTaskReq(SRpcMsg *pReq); +static void saveTaskAndNodeInfoIntoBuf(SStreamObj *pStream, SStreamExecInfo *pExecNode); static void addAllStreamTasksIntoBuf(SMnode *pMnode, SStreamExecInfo *pExecInfo); static void removeExpiredNodeInfo(const SArray *pNodeSnapshot); @@ -919,6 +918,85 @@ _OVER: return code; } +static int32_t mndProcessRestartStreamReq(SRpcMsg *pReq) { + SMnode *pMnode = pReq->info.node; + SStreamObj *pStream = NULL; + int32_t code = 0; + SMPauseStreamReq pauseReq = {0}; + + if (tDeserializeSMPauseStreamReq(pReq->pCont, pReq->contLen, &pauseReq) < 0) { + return TSDB_CODE_INVALID_MSG; + } + + code = mndAcquireStream(pMnode, pauseReq.name, &pStream); + if (pStream == NULL || code != 0) { + if (pauseReq.igNotExists) { + mInfo("stream:%s, not exist, not restart stream", pauseReq.name); + return 0; + } else { + mError("stream:%s not exist, failed to restart stream", pauseReq.name); + TAOS_RETURN(TSDB_CODE_MND_STREAM_NOT_EXIST); + } + } + + mInfo("stream:%s,%" PRId64 " start to restart stream", pauseReq.name, pStream->uid); + if ((code = mndCheckDbPrivilegeByName(pMnode, pReq->info.conn.user, MND_OPER_WRITE_DB, pStream->targetDb)) != 0) { + sdbRelease(pMnode->pSdb, pStream); + return code; + } + + // check if it is conflict with other trans in both sourceDb and targetDb. + code = mndStreamTransConflictCheck(pMnode, pStream->uid, MND_STREAM_RESTART_NAME, true); + if (code) { + sdbRelease(pMnode->pSdb, pStream); + return code; + } + + bool updated = mndStreamNodeIsUpdated(pMnode); + if (updated) { + mError("tasks are not ready for restart, node update detected"); + sdbRelease(pMnode->pSdb, pStream); + TAOS_RETURN(TSDB_CODE_STREAM_TASK_IVLD_STATUS); + } + + STrans *pTrans = NULL; + code = doCreateTrans(pMnode, pStream, pReq, TRN_CONFLICT_NOTHING, MND_STREAM_RESTART_NAME, "restart the stream", &pTrans); + if (pTrans == NULL || code) { + mError("stream:%s failed to pause stream since %s", pauseReq.name, tstrerror(code)); + sdbRelease(pMnode->pSdb, pStream); + return code; + } + + code = mndStreamRegisterTrans(pTrans, MND_STREAM_RESTART_NAME, pStream->uid); + if (code) { + sdbRelease(pMnode->pSdb, pStream); + mndTransDrop(pTrans); + return code; + } + + // if nodeUpdate happened, not send pause trans + code = mndStreamSetRestartAction(pMnode, pTrans, pStream); + if (code) { + mError("stream:%s, failed to restart task since %s", pauseReq.name, tstrerror(code)); + sdbRelease(pMnode->pSdb, pStream); + mndTransDrop(pTrans); + return code; + } + + code = mndTransPrepare(pMnode, pTrans); + if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_ACTION_IN_PROGRESS) { + mError("trans:%d, failed to prepare restart stream trans since %s", pTrans->id, tstrerror(code)); + sdbRelease(pMnode->pSdb, pStream); + mndTransDrop(pTrans); + return code; + } + + sdbRelease(pMnode->pSdb, pStream); + mndTransDrop(pTrans); + + return TSDB_CODE_ACTION_IN_PROGRESS; +} + int64_t mndStreamGenChkptId(SMnode *pMnode, bool lock) { SStreamObj *pStream = NULL; void *pIter = NULL; @@ -972,82 +1050,6 @@ int64_t mndStreamGenChkptId(SMnode *pMnode, bool lock) { return maxChkptId + 1; } -static int32_t mndBuildStreamCheckpointSourceReq(void **pBuf, int32_t *pLen, int32_t nodeId, int64_t checkpointId, - int64_t streamId, int32_t taskId, int32_t transId, int8_t mndTrigger) { - SStreamCheckpointSourceReq req = {0}; - req.checkpointId = checkpointId; - req.nodeId = nodeId; - req.expireTime = -1; - req.streamId = streamId; // pTask->id.streamId; - req.taskId = taskId; // pTask->id.taskId; - req.transId = transId; - req.mndTrigger = mndTrigger; - - int32_t code; - int32_t blen; - - tEncodeSize(tEncodeStreamCheckpointSourceReq, &req, blen, code); - if (code < 0) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); - } - - int32_t tlen = sizeof(SMsgHead) + blen; - - void *buf = taosMemoryMalloc(tlen); - if (buf == NULL) { - return terrno; - } - - void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); - SEncoder encoder; - tEncoderInit(&encoder, abuf, tlen); - int32_t pos = tEncodeStreamCheckpointSourceReq(&encoder, &req); - if (pos == -1) { - tEncoderClear(&encoder); - return TSDB_CODE_INVALID_MSG; - } - - SMsgHead *pMsgHead = (SMsgHead *)buf; - pMsgHead->contLen = htonl(tlen); - pMsgHead->vgId = htonl(nodeId); - - tEncoderClear(&encoder); - - *pBuf = buf; - *pLen = tlen; - - return 0; -} - -static int32_t doSetCheckpointAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask, int64_t checkpointId, - int8_t mndTrigger) { - void *buf; - int32_t tlen; - int32_t code = 0; - SEpSet epset = {0}; - bool hasEpset = false; - - if ((code = mndBuildStreamCheckpointSourceReq(&buf, &tlen, pTask->info.nodeId, checkpointId, pTask->id.streamId, - pTask->id.taskId, pTrans->id, mndTrigger)) < 0) { - taosMemoryFree(buf); - return code; - } - - code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); - if (code != TSDB_CODE_SUCCESS || !hasEpset) { - taosMemoryFree(buf); - return code; - } - - code = setTransAction(pTrans, buf, tlen, TDMT_VND_STREAM_CHECK_POINT_SOURCE, &epset, TSDB_CODE_SYN_PROPOSE_NOT_READY, - TSDB_CODE_VND_INVALID_VGROUP_ID); - if (code != 0) { - taosMemoryFree(buf); - } - - return code; -} - static int32_t mndProcessStreamCheckpointTrans(SMnode *pMnode, SStreamObj *pStream, int64_t checkpointId, int8_t mndTrigger, bool lock) { int32_t code = TSDB_CODE_SUCCESS; @@ -1095,7 +1097,7 @@ static int32_t mndProcessStreamCheckpointTrans(SMnode *pMnode, SStreamObj *pStre int32_t sz = taosArrayGetSize(pLevel); for (int32_t j = 0; j < sz; j++) { SStreamTask *pTask = taosArrayGetP(pLevel, j); - code = doSetCheckpointAction(pMnode, pTrans, pTask, checkpointId, mndTrigger); + code = mndStreamSetCheckpointAction(pMnode, pTrans, pTask, checkpointId, mndTrigger); if (code != TSDB_CODE_SUCCESS) { taosWUnLockLatch(&pStream->lock); @@ -1142,70 +1144,9 @@ int32_t extractStreamNodeList(SMnode *pMnode) { return taosArrayGetSize(execInfo.pNodeList); } -static int32_t doCheckForUpdated(SMnode *pMnode, SArray **ppNodeSnapshot) { - bool allReady = false; - bool nodeUpdated = false; - SVgroupChangeInfo changeInfo = {0}; - - int32_t numOfNodes = extractStreamNodeList(pMnode); - - if (numOfNodes == 0) { - mDebug("stream task node change checking done, no vgroups exist, do nothing"); - execInfo.ts = taosGetTimestampSec(); - return false; - } - - for (int32_t i = 0; i < numOfNodes; ++i) { - SNodeEntry *pNodeEntry = taosArrayGet(execInfo.pNodeList, i); - if (pNodeEntry == NULL) { - continue; - } - - if (pNodeEntry->stageUpdated) { - mDebug("stream task not ready due to node update detected, checkpoint not issued"); - return true; - } - } - - int32_t code = mndTakeVgroupSnapshot(pMnode, &allReady, ppNodeSnapshot); - if (code) { - mError("failed to get the vgroup snapshot, ignore it and continue"); - } - - if (!allReady) { - mWarn("not all vnodes ready, quit from vnodes status check"); - return true; - } - - code = mndFindChangedNodeInfo(pMnode, execInfo.pNodeList, *ppNodeSnapshot, &changeInfo); - if (code) { - nodeUpdated = false; - } else { - nodeUpdated = (taosArrayGetSize(changeInfo.pUpdateNodeList) > 0); - if (nodeUpdated) { - mDebug("stream tasks not ready due to node update"); - } - } - - mndDestroyVgroupChangeInfo(&changeInfo); - return nodeUpdated; -} - -// check if the node update happens or not -static bool taskNodeIsUpdated(SMnode *pMnode) { - SArray *pNodeSnapshot = NULL; - - streamMutexLock(&execInfo.lock); - bool updated = doCheckForUpdated(pMnode, &pNodeSnapshot); - streamMutexUnlock(&execInfo.lock); - - taosArrayDestroy(pNodeSnapshot); - return updated; -} - static int32_t mndCheckTaskAndNodeStatus(SMnode *pMnode) { bool ready = true; - if (taskNodeIsUpdated(pMnode)) { + if (mndStreamNodeIsUpdated(pMnode)) { TAOS_RETURN(TSDB_CODE_STREAM_TASK_IVLD_STATUS); } @@ -1604,32 +1545,6 @@ int32_t mndDropStreamByDb(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) { return 0; } -int32_t mndGetNumOfStreams(SMnode *pMnode, char *dbName, int32_t *pNumOfStreams) { - SSdb *pSdb = pMnode->pSdb; - SDbObj *pDb = mndAcquireDb(pMnode, dbName); - if (pDb == NULL) { - TAOS_RETURN(TSDB_CODE_MND_DB_NOT_SELECTED); - } - - int32_t numOfStreams = 0; - void *pIter = NULL; - while (1) { - SStreamObj *pStream = NULL; - pIter = sdbFetch(pSdb, SDB_STREAM, pIter, (void **)&pStream); - if (pIter == NULL) break; - - if (pStream->sourceDbUid == pDb->uid) { - numOfStreams++; - } - - sdbRelease(pSdb, pStream); - } - - *pNumOfStreams = numOfStreams; - mndReleaseDb(pMnode, pDb); - return 0; -} - static int32_t mndRetrieveStream(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { SMnode *pMnode = pReq->info.node; SSdb *pSdb = pMnode->pSdb; @@ -1769,7 +1684,7 @@ static int32_t mndProcessPauseStreamReq(SRpcMsg *pReq) { TAOS_RETURN(code); } - bool updated = taskNodeIsUpdated(pMnode); + bool updated = mndStreamNodeIsUpdated(pMnode); if (updated) { mError("tasks are not ready for pause, node update detected"); sdbRelease(pMnode->pSdb, pStream); @@ -1964,102 +1879,6 @@ static int32_t mndProcessResumeStreamReq(SRpcMsg *pReq) { return TSDB_CODE_ACTION_IN_PROGRESS; } -static bool isNodeEpsetChanged(const SEpSet *pPrevEpset, const SEpSet *pCurrent) { - const SEp *pEp = GET_ACTIVE_EP(pPrevEpset); - const SEp *p = GET_ACTIVE_EP(pCurrent); - - if (pEp->port == p->port && strncmp(pEp->fqdn, p->fqdn, TSDB_FQDN_LEN) == 0) { - return false; - } - return true; -} - -// 1. increase the replica does not affect the stream process. -// 2. decreasing the replica may affect the stream task execution in the way that there is one or more running stream -// tasks on the will be removed replica. -// 3. vgroup redistribution is an combination operation of first increase replica and then decrease replica. So we -// will handle it as mentioned in 1 & 2 items. -static int32_t mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pPrevNodeList, const SArray *pNodeList, - SVgroupChangeInfo *pInfo) { - int32_t code = 0; - int32_t lino = 0; - - if (pInfo == NULL) { - return TSDB_CODE_INVALID_PARA; - } - - pInfo->pUpdateNodeList = taosArrayInit(4, sizeof(SNodeUpdateInfo)), - pInfo->pDBMap = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_NO_LOCK); - - if (pInfo->pUpdateNodeList == NULL || pInfo->pDBMap == NULL) { - mndDestroyVgroupChangeInfo(pInfo); - TSDB_CHECK_NULL(NULL, code, lino, _err, terrno); - } - - int32_t numOfNodes = taosArrayGetSize(pPrevNodeList); - for (int32_t i = 0; i < numOfNodes; ++i) { - SNodeEntry *pPrevEntry = taosArrayGet(pPrevNodeList, i); - if (pPrevEntry == NULL) { - continue; - } - - int32_t num = taosArrayGetSize(pNodeList); - for (int32_t j = 0; j < num; ++j) { - SNodeEntry *pCurrent = taosArrayGet(pNodeList, j); - if(pCurrent == NULL) { - continue; - } - - if (pCurrent->nodeId == pPrevEntry->nodeId) { - if (pPrevEntry->stageUpdated || isNodeEpsetChanged(&pPrevEntry->epset, &pCurrent->epset)) { - const SEp *pPrevEp = GET_ACTIVE_EP(&pPrevEntry->epset); - - char buf[256] = {0}; - code = epsetToStr(&pCurrent->epset, buf, tListLen(buf)); // ignore this error - if (code) { - mError("failed to convert epset string, code:%s", tstrerror(code)); - TSDB_CHECK_CODE(code, lino, _err); - } - - mDebug("nodeId:%d restart/epset changed detected, old:%s:%d -> new:%s, stageUpdate:%d", pCurrent->nodeId, - pPrevEp->fqdn, pPrevEp->port, buf, pPrevEntry->stageUpdated); - - SNodeUpdateInfo updateInfo = {.nodeId = pPrevEntry->nodeId}; - epsetAssign(&updateInfo.prevEp, &pPrevEntry->epset); - epsetAssign(&updateInfo.newEp, &pCurrent->epset); - - void* p = taosArrayPush(pInfo->pUpdateNodeList, &updateInfo); - TSDB_CHECK_NULL(p, code, lino, _err, terrno); - } - - // todo handle the snode info - if (pCurrent->nodeId != SNODE_HANDLE) { - SVgObj *pVgroup = mndAcquireVgroup(pMnode, pCurrent->nodeId); - code = taosHashPut(pInfo->pDBMap, pVgroup->dbName, strlen(pVgroup->dbName), NULL, 0); - mndReleaseVgroup(pMnode, pVgroup); - TSDB_CHECK_CODE(code, lino, _err); - } - - break; - } - } - } - - return code; - - _err: - mError("failed to find node change info, code:%s at %s line:%d", tstrerror(code), __func__, lino); - mndDestroyVgroupChangeInfo(pInfo); - return code; -} - -static void mndDestroyVgroupChangeInfo(SVgroupChangeInfo* pInfo) { - if (pInfo != NULL) { - taosArrayDestroy(pInfo->pUpdateNodeList); - taosHashCleanup(pInfo->pDBMap); - } -} - static int32_t mndProcessVgroupChange(SMnode *pMnode, SVgroupChangeInfo *pChangeInfo, bool includeAllNodes) { SSdb *pSdb = pMnode->pSdb; SStreamObj *pStream = NULL; diff --git a/source/dnode/mnode/impl/src/mndStreamTrans.c b/source/dnode/mnode/impl/src/mndStreamTrans.c index 25a735e152..e5b4447a39 100644 --- a/source/dnode/mnode/impl/src/mndStreamTrans.c +++ b/source/dnode/mnode/impl/src/mndStreamTrans.c @@ -21,6 +21,10 @@ typedef struct SKeyInfo { int32_t keyLen; } SKeyInfo; +static bool identicalName(const char *pDb, const char *pParam, int32_t len) { + return (strlen(pDb) == len) && (strncmp(pDb, pParam, len) == 0); +} + int32_t mndStreamRegisterTrans(STrans *pTrans, const char *pTransName, int64_t streamId) { SStreamTransInfo info = { .transId = pTrans->id, .startTime = taosGetTimestampMs(), .name = pTransName, .streamId = streamId}; @@ -117,7 +121,8 @@ int32_t mndStreamTransConflictCheck(SMnode *pMnode, int64_t streamId, const char } if (strcmp(tInfo.name, MND_STREAM_CHECKPOINT_NAME) == 0) { - if ((strcmp(pTransName, MND_STREAM_DROP_NAME) != 0) && (strcmp(pTransName, MND_STREAM_TASK_RESET_NAME) != 0)) { + if ((strcmp(pTransName, MND_STREAM_DROP_NAME) != 0) && (strcmp(pTransName, MND_STREAM_TASK_RESET_NAME) != 0) && + (strcmp(pTransName, MND_STREAM_RESTART_NAME) != 0)) { mWarn("conflict with other transId:%d streamUid:0x%" PRIx64 ", trans:%s", tInfo.transId, tInfo.streamId, tInfo.name); return TSDB_CODE_MND_TRANS_CONFLICT; @@ -126,7 +131,8 @@ int32_t mndStreamTransConflictCheck(SMnode *pMnode, int64_t streamId, const char } } else if ((strcmp(tInfo.name, MND_STREAM_CREATE_NAME) == 0) || (strcmp(tInfo.name, MND_STREAM_DROP_NAME) == 0) || (strcmp(tInfo.name, MND_STREAM_TASK_RESET_NAME) == 0) || - strcmp(tInfo.name, MND_STREAM_TASK_UPDATE_NAME) == 0) { + (strcmp(tInfo.name, MND_STREAM_TASK_UPDATE_NAME) == 0) || + strcmp(tInfo.name, MND_STREAM_RESTART_NAME) == 0) { mWarn("conflict with other transId:%d streamUid:0x%" PRIx64 ", trans:%s", tInfo.transId, tInfo.streamId, tInfo.name); return TSDB_CODE_MND_TRANS_CONFLICT; @@ -282,10 +288,6 @@ int32_t setTransAction(STrans *pTrans, void *pCont, int32_t contLen, int32_t msg return mndTransAppendRedoAction(pTrans, &action); } -static bool identicalName(const char *pDb, const char *pParam, int32_t len) { - return (strlen(pDb) == len) && (strncmp(pDb, pParam, len) == 0); -} - int32_t doKillCheckpointTrans(SMnode *pMnode, const char *pDBName, size_t len) { void *pIter = NULL; diff --git a/source/dnode/mnode/impl/src/mndStreamTransAct.c b/source/dnode/mnode/impl/src/mndStreamTransAct.c new file mode 100644 index 0000000000..3ecd192222 --- /dev/null +++ b/source/dnode/mnode/impl/src/mndStreamTransAct.c @@ -0,0 +1,669 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "mndDb.h" +#include "mndStb.h" +#include "mndStream.h" +#include "mndTrans.h" +#include "mndVgroup.h" +#include "taoserror.h" +#include "tmisce.h" + +static int32_t doSetPauseAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask) { + SVPauseStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVPauseStreamTaskReq)); + if (pReq == NULL) { + mError("failed to malloc in pause stream, size:%" PRIzu ", code:%s", sizeof(SVPauseStreamTaskReq), + tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + // terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; + } + + pReq->head.vgId = htonl(pTask->info.nodeId); + pReq->taskId = pTask->id.taskId; + pReq->streamId = pTask->id.streamId; + + SEpSet epset = {0}; + bool hasEpset = false; + int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); + if (code != TSDB_CODE_SUCCESS || !hasEpset) { + terrno = code; + taosMemoryFree(pReq); + return code; + } + + char buf[256] = {0}; + code = epsetToStr(&epset, buf, tListLen(buf)); + if (code != 0) { // print error and continue + mError("failed to convert epset to str, code:%s", tstrerror(code)); + } + + mDebug("pause stream task in node:%d, epset:%s", pTask->info.nodeId, buf); + code = setTransAction(pTrans, pReq, sizeof(SVPauseStreamTaskReq), TDMT_STREAM_TASK_PAUSE, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); + if (code != 0) { + taosMemoryFree(pReq); + return code; + } + return 0; +} + +static int32_t doSetDropAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask) { + SVDropStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVDropStreamTaskReq)); + if (pReq == NULL) { + // terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; + } + + pReq->head.vgId = htonl(pTask->info.nodeId); + pReq->taskId = pTask->id.taskId; + pReq->streamId = pTask->id.streamId; + + SEpSet epset = {0}; + bool hasEpset = false; + int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); + if (code != TSDB_CODE_SUCCESS || !hasEpset) { // no valid epset, return directly without redoAction + return code; + } + + // The epset of nodeId of this task may have been expired now, let's use the newest epset from mnode. + code = setTransAction(pTrans, pReq, sizeof(SVDropStreamTaskReq), TDMT_STREAM_TASK_DROP, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); + if (code != 0) { + taosMemoryFree(pReq); + return code; + } + + return 0; +} + +static int32_t doSetResumeAction(STrans *pTrans, SMnode *pMnode, SStreamTask *pTask, int8_t igUntreated) { + terrno = 0; + + SVResumeStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVResumeStreamTaskReq)); + if (pReq == NULL) { + mError("failed to malloc in resume stream, size:%" PRIzu ", code:%s", sizeof(SVResumeStreamTaskReq), + tstrerror(TSDB_CODE_OUT_OF_MEMORY)); + // terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; + } + + pReq->head.vgId = htonl(pTask->info.nodeId); + pReq->taskId = pTask->id.taskId; + pReq->streamId = pTask->id.streamId; + pReq->igUntreated = igUntreated; + + SEpSet epset = {0}; + bool hasEpset = false; + int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); + if (code != TSDB_CODE_SUCCESS || (!hasEpset)) { + terrno = code; + taosMemoryFree(pReq); + return terrno; + } + + code = setTransAction(pTrans, pReq, sizeof(SVResumeStreamTaskReq), TDMT_STREAM_TASK_RESUME, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); + if (code != 0) { + taosMemoryFree(pReq); + return terrno; + } + + mDebug("set the resume action for trans:%d", pTrans->id); + return 0; +} + +static int32_t doSetDropActionFromId(SMnode *pMnode, STrans *pTrans, SOrphanTask* pTask) { + SVDropStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVDropStreamTaskReq)); + if (pReq == NULL) { + // terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; + } + + pReq->head.vgId = htonl(pTask->nodeId); + pReq->taskId = pTask->taskId; + pReq->streamId = pTask->streamId; + + SEpSet epset = {0}; + bool hasEpset = false; + int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->taskId, pTask->nodeId); + if (code != TSDB_CODE_SUCCESS || (!hasEpset)) { // no valid epset, return directly without redoAction + taosMemoryFree(pReq); + return code; + } + + // The epset of nodeId of this task may have been expired now, let's use the newest epset from mnode. + code = setTransAction(pTrans, pReq, sizeof(SVDropStreamTaskReq), TDMT_STREAM_TASK_DROP, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); + if (code != 0) { + taosMemoryFree(pReq); + return code; + } + + return 0; +} + +static void initNodeUpdateMsg(SStreamTaskNodeUpdateMsg *pMsg, const SVgroupChangeInfo *pInfo, SStreamTaskId *pId, + int32_t transId) { + int32_t code = 0; + + pMsg->streamId = pId->streamId; + pMsg->taskId = pId->taskId; + pMsg->transId = transId; + pMsg->pNodeList = taosArrayInit(taosArrayGetSize(pInfo->pUpdateNodeList), sizeof(SNodeUpdateInfo)); + if (pMsg->pNodeList == NULL) { + mError("failed to prepare node list, code:%s", tstrerror(terrno)); + code = terrno; + } + + if (code == 0) { + void *p = taosArrayAddAll(pMsg->pNodeList, pInfo->pUpdateNodeList); + if (p == NULL) { + mError("failed to add update node list into nodeList"); + } + } +} + +static int32_t doBuildStreamTaskUpdateMsg(void **pBuf, int32_t *pLen, SVgroupChangeInfo *pInfo, int32_t nodeId, + SStreamTaskId *pId, int32_t transId) { + SStreamTaskNodeUpdateMsg req = {0}; + initNodeUpdateMsg(&req, pInfo, pId, transId); + + int32_t code = 0; + int32_t blen; + + tEncodeSize(tEncodeStreamTaskUpdateMsg, &req, blen, code); + if (code < 0) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + taosArrayDestroy(req.pNodeList); + return terrno; + } + + int32_t tlen = sizeof(SMsgHead) + blen; + + void *buf = taosMemoryMalloc(tlen); + if (buf == NULL) { + taosArrayDestroy(req.pNodeList); + return terrno; + } + + void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); + SEncoder encoder; + tEncoderInit(&encoder, abuf, tlen); + code = tEncodeStreamTaskUpdateMsg(&encoder, &req); + if (code == -1) { + tEncoderClear(&encoder); + taosMemoryFree(buf); + taosArrayDestroy(req.pNodeList); + return code; + } + + SMsgHead *pMsgHead = (SMsgHead *)buf; + pMsgHead->contLen = htonl(tlen); + pMsgHead->vgId = htonl(nodeId); + + tEncoderClear(&encoder); + + *pBuf = buf; + *pLen = tlen; + + taosArrayDestroy(req.pNodeList); + return TSDB_CODE_SUCCESS; +} + +static int32_t doSetUpdateTaskAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask, SVgroupChangeInfo *pInfo) { + void *pBuf = NULL; + int32_t len = 0; + SEpSet epset = {0}; + bool hasEpset = false; + + bool unusedRet = streamTaskUpdateEpsetInfo(pTask, pInfo->pUpdateNodeList); + int32_t code = doBuildStreamTaskUpdateMsg(&pBuf, &len, pInfo, pTask->info.nodeId, &pTask->id, pTrans->id); + if (code) { + mError("failed to build stream task epset update msg, code:%s", tstrerror(code)); + return code; + } + + code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); + if (code != TSDB_CODE_SUCCESS || !hasEpset) { + mError("failed to extract epset during create update epset, code:%s", tstrerror(code)); + return code; + } + + code = setTransAction(pTrans, pBuf, len, TDMT_VND_STREAM_TASK_UPDATE, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); + if (code != TSDB_CODE_SUCCESS) { + mError("failed to create update task epset trans, code:%s", tstrerror(code)); + taosMemoryFree(pBuf); + } + + return code; +} + +static int32_t doSetUpdateChkptAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask) { + SVUpdateCheckpointInfoReq *pReq = taosMemoryCalloc(1, sizeof(SVUpdateCheckpointInfoReq)); + if (pReq == NULL) { + mError("failed to malloc in reset stream, size:%" PRIzu ", code:%s", sizeof(SVUpdateCheckpointInfoReq), + tstrerror(terrno)); + return terrno; + } + + pReq->head.vgId = htonl(pTask->info.nodeId); + pReq->taskId = pTask->id.taskId; + pReq->streamId = pTask->id.streamId; + + SChkptReportInfo *pStreamItem = (SChkptReportInfo*)taosHashGet(execInfo.pChkptStreams, &pTask->id.streamId, sizeof(pTask->id.streamId)); + if (pStreamItem == NULL) { + return TSDB_CODE_INVALID_PARA; + } + + int32_t size = taosArrayGetSize(pStreamItem->pTaskList); + for(int32_t i = 0; i < size; ++i) { + STaskChkptInfo* pInfo = taosArrayGet(pStreamItem->pTaskList, i); + if (pInfo == NULL) { + continue; + } + + if (pInfo->taskId == pTask->id.taskId) { + pReq->checkpointId = pInfo->checkpointId; + pReq->checkpointVer = pInfo->version; + pReq->checkpointTs = pInfo->ts; + pReq->dropRelHTask = pInfo->dropHTask; + pReq->transId = pInfo->transId; + pReq->hStreamId = pTask->hTaskInfo.id.streamId; + pReq->hTaskId = pTask->hTaskInfo.id.taskId; + } + } + + SEpSet epset = {0}; + bool hasEpset = false; + int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); + if (code != TSDB_CODE_SUCCESS || !hasEpset) { + taosMemoryFree(pReq); + return code; + } + + code = setTransAction(pTrans, pReq, sizeof(SVUpdateCheckpointInfoReq), TDMT_STREAM_TASK_UPDATE_CHKPT, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); + if (code != TSDB_CODE_SUCCESS) { + taosMemoryFree(pReq); + } + + return code; +} + +static int32_t doSetResetAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask) { + SVResetStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVResetStreamTaskReq)); + if (pReq == NULL) { + mError("failed to malloc in reset stream, size:%" PRIzu ", code:%s", sizeof(SVResetStreamTaskReq), + tstrerror(terrno)); + return terrno; + } + + pReq->head.vgId = htonl(pTask->info.nodeId); + pReq->taskId = pTask->id.taskId; + pReq->streamId = pTask->id.streamId; + + SEpSet epset = {0}; + bool hasEpset = false; + int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); + if (code != TSDB_CODE_SUCCESS || !hasEpset) { + taosMemoryFree(pReq); + return code; + } + + code = setTransAction(pTrans, pReq, sizeof(SVResetStreamTaskReq), TDMT_VND_STREAM_TASK_RESET, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); + if (code != TSDB_CODE_SUCCESS) { + taosMemoryFree(pReq); + } + + return code; +} + +static int32_t mndBuildStreamCheckpointSourceReq(void **pBuf, int32_t *pLen, int32_t nodeId, int64_t checkpointId, + int64_t streamId, int32_t taskId, int32_t transId, int8_t mndTrigger) { + SStreamCheckpointSourceReq req = {0}; + req.checkpointId = checkpointId; + req.nodeId = nodeId; + req.expireTime = -1; + req.streamId = streamId; // pTask->id.streamId; + req.taskId = taskId; // pTask->id.taskId; + req.transId = transId; + req.mndTrigger = mndTrigger; + + int32_t code; + int32_t blen; + + tEncodeSize(tEncodeStreamCheckpointSourceReq, &req, blen, code); + if (code < 0) { + TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + } + + int32_t tlen = sizeof(SMsgHead) + blen; + + void *buf = taosMemoryMalloc(tlen); + if (buf == NULL) { + return terrno; + } + + void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); + SEncoder encoder; + tEncoderInit(&encoder, abuf, tlen); + int32_t pos = tEncodeStreamCheckpointSourceReq(&encoder, &req); + if (pos == -1) { + tEncoderClear(&encoder); + return TSDB_CODE_INVALID_MSG; + } + + SMsgHead *pMsgHead = (SMsgHead *)buf; + pMsgHead->contLen = htonl(tlen); + pMsgHead->vgId = htonl(nodeId); + + tEncoderClear(&encoder); + + *pBuf = buf; + *pLen = tlen; + + return 0; +} +int32_t mndStreamSetPauseAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { + SStreamTaskIter *pIter = NULL; + + int32_t code = createStreamTaskIter(pStream, &pIter); + if (code) { + mError("failed to create stream task iter:%s", pStream->name); + return code; + } + + while (streamTaskIterNextTask(pIter)) { + SStreamTask *pTask = NULL; + code = streamTaskIterGetCurrent(pIter, &pTask); + if (code) { + destroyStreamTaskIter(pIter); + return code; + } + + code = doSetPauseAction(pMnode, pTrans, pTask); + if (code) { + destroyStreamTaskIter(pIter); + return code; + } + + if (atomic_load_8(&pTask->status.taskStatus) != TASK_STATUS__PAUSE) { + atomic_store_8(&pTask->status.statusBackup, pTask->status.taskStatus); + atomic_store_8(&pTask->status.taskStatus, TASK_STATUS__PAUSE); + } + } + + destroyStreamTaskIter(pIter); + return code; +} + +int32_t mndStreamSetDropAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { + SStreamTaskIter *pIter = NULL; + + int32_t code = createStreamTaskIter(pStream, &pIter); + if (code) { + mError("failed to create stream task iter:%s", pStream->name); + return code; + } + + while(streamTaskIterNextTask(pIter)) { + SStreamTask *pTask = NULL; + code = streamTaskIterGetCurrent(pIter, &pTask); + if (code) { + destroyStreamTaskIter(pIter); + return code; + } + + code = doSetDropAction(pMnode, pTrans, pTask); + if (code) { + destroyStreamTaskIter(pIter); + return code; + } + } + destroyStreamTaskIter(pIter); + return 0; +} + +int32_t mndStreamSetResumeAction(STrans *pTrans, SMnode *pMnode, SStreamObj *pStream, int8_t igUntreated) { + SStreamTaskIter *pIter = NULL; + int32_t code = createStreamTaskIter(pStream, &pIter); + if (code) { + mError("failed to create stream task iter:%s", pStream->name); + return code; + } + + while (streamTaskIterNextTask(pIter)) { + SStreamTask *pTask = NULL; + code = streamTaskIterGetCurrent(pIter, &pTask); + if (code || pTask == NULL) { + destroyStreamTaskIter(pIter); + return code; + } + + code = doSetResumeAction(pTrans, pMnode, pTask, igUntreated); + if (code) { + destroyStreamTaskIter(pIter); + return code; + } + + if (atomic_load_8(&pTask->status.taskStatus) == TASK_STATUS__PAUSE) { + atomic_store_8(&pTask->status.taskStatus, pTask->status.statusBackup); + } + } + destroyStreamTaskIter(pIter); + return 0; +} + +// build trans to update the epset +int32_t mndStreamSetUpdateEpsetAction(SMnode *pMnode, SStreamObj *pStream, SVgroupChangeInfo *pInfo, STrans *pTrans) { + mDebug("stream:0x%" PRIx64 " set tasks epset update action", pStream->uid); + SStreamTaskIter *pIter = NULL; + + taosWLockLatch(&pStream->lock); + int32_t code = createStreamTaskIter(pStream, &pIter); + if (code) { + taosWUnLockLatch(&pStream->lock); + mError("failed to create stream task iter:%s", pStream->name); + return code; + } + + while (streamTaskIterNextTask(pIter)) { + SStreamTask *pTask = NULL; + code = streamTaskIterGetCurrent(pIter, &pTask); + if (code) { + destroyStreamTaskIter(pIter); + taosWUnLockLatch(&pStream->lock); + return code; + } + + code = doSetUpdateTaskAction(pMnode, pTrans, pTask, pInfo); + if (code != TSDB_CODE_SUCCESS) { + destroyStreamTaskIter(pIter); + taosWUnLockLatch(&pStream->lock); + return code; + } + } + + destroyStreamTaskIter(pIter); + taosWUnLockLatch(&pStream->lock); + return 0; +} + +int32_t mndStreamSetUpdateChkptAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { + SStreamTaskIter *pIter = NULL; + + taosWLockLatch(&pStream->lock); + int32_t code = createStreamTaskIter(pStream, &pIter); + if (code) { + taosWUnLockLatch(&pStream->lock); + mError("failed to create stream task iter:%s", pStream->name); + return code; + } + + while (streamTaskIterNextTask(pIter)) { + SStreamTask *pTask = NULL; + code = streamTaskIterGetCurrent(pIter, &pTask); + if (code) { + destroyStreamTaskIter(pIter); + taosWUnLockLatch(&pStream->lock); + return code; + } + + code = doSetUpdateChkptAction(pMnode, pTrans, pTask); + if (code != TSDB_CODE_SUCCESS) { + destroyStreamTaskIter(pIter); + taosWUnLockLatch(&pStream->lock); + return code; + } + } + + destroyStreamTaskIter(pIter); + taosWUnLockLatch(&pStream->lock); + return code; +} + +int32_t mndStreamSetDropActionFromList(SMnode *pMnode, STrans *pTrans, SArray* pList) { + for(int32_t i = 0; i < taosArrayGetSize(pList); ++i) { + SOrphanTask* pTask = taosArrayGet(pList, i); + if (pTask == NULL) { + return terrno; + } + + int32_t code = doSetDropActionFromId(pMnode, pTrans, pTask); + if (code != 0) { + return code; + } else { + mDebug("add drop task:0x%x action to drop orphan task", pTask->taskId); + } + } + return 0; +} + +int32_t mndStreamSetResetTaskAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { + SStreamTaskIter *pIter = NULL; + + taosWLockLatch(&pStream->lock); + int32_t code = createStreamTaskIter(pStream, &pIter); + if (code) { + taosWUnLockLatch(&pStream->lock); + mError("failed to create stream task iter:%s", pStream->name); + return code; + } + + while (streamTaskIterNextTask(pIter)) { + SStreamTask *pTask = NULL; + code = streamTaskIterGetCurrent(pIter, &pTask); + if (code) { + destroyStreamTaskIter(pIter); + taosWUnLockLatch(&pStream->lock); + return code; + } + + code = doSetResetAction(pMnode, pTrans, pTask); + if (code != TSDB_CODE_SUCCESS) { + destroyStreamTaskIter(pIter); + taosWUnLockLatch(&pStream->lock); + return code; + } + } + + destroyStreamTaskIter(pIter); + taosWUnLockLatch(&pStream->lock); + return 0; +} + +int32_t mndStreamSetChkptIdAction(SMnode *pMnode, STrans *pTrans, SStreamTask* pTask, int64_t checkpointId, int64_t ts) { + SRestoreCheckpointInfo req = { + .taskId = pTask->id.taskId, + .streamId = pTask->id.streamId, + .checkpointId = checkpointId, + .startTs = ts, + .nodeId = pTask->info.nodeId, + .transId = pTrans->id, + }; + + int32_t code = 0; + int32_t blen; + tEncodeSize(tEncodeRestoreCheckpointInfo, &req, blen, code); + if (code < 0) { + return terrno; + } + + int32_t tlen = sizeof(SMsgHead) + blen; + + void *pBuf = taosMemoryMalloc(tlen); + if (pBuf == NULL) { + return terrno; + } + + void *abuf = POINTER_SHIFT(pBuf, sizeof(SMsgHead)); + SEncoder encoder; + tEncoderInit(&encoder, abuf, tlen); + code = tEncodeRestoreCheckpointInfo(&encoder, &req); + tEncoderClear(&encoder); + if (code == -1) { + taosMemoryFree(pBuf); + return code; + } + + SMsgHead *pMsgHead = (SMsgHead *)pBuf; + pMsgHead->contLen = htonl(tlen); + pMsgHead->vgId = htonl(pTask->info.nodeId); + + SEpSet epset = {0}; + bool hasEpset = false; + code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); + if (code != TSDB_CODE_SUCCESS || !hasEpset) { + taosMemoryFree(pBuf); + return code; + } + + code = setTransAction(pTrans, pBuf, tlen, TDMT_STREAM_CONSEN_CHKPT, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); + if (code != TSDB_CODE_SUCCESS) { + taosMemoryFree(pBuf); + } + + return code; +} + + +int32_t mndStreamSetCheckpointAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask, int64_t checkpointId, + int8_t mndTrigger) { + void *buf; + int32_t tlen; + int32_t code = 0; + SEpSet epset = {0}; + bool hasEpset = false; + + if ((code = mndBuildStreamCheckpointSourceReq(&buf, &tlen, pTask->info.nodeId, checkpointId, pTask->id.streamId, + pTask->id.taskId, pTrans->id, mndTrigger)) < 0) { + taosMemoryFree(buf); + return code; + } + + code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); + if (code != TSDB_CODE_SUCCESS || !hasEpset) { + taosMemoryFree(buf); + return code; + } + + code = setTransAction(pTrans, buf, tlen, TDMT_VND_STREAM_CHECK_POINT_SOURCE, &epset, TSDB_CODE_SYN_PROPOSE_NOT_READY, + TSDB_CODE_VND_INVALID_VGROUP_ID); + if (code != 0) { + taosMemoryFree(buf); + } + + return code; +} + +int32_t mndStreamSetRestartAction(SMnode* pMnode, STrans *pTrans, SStreamObj* pStream) { + return 0; +} + diff --git a/source/dnode/mnode/impl/src/mndStreamUtil.c b/source/dnode/mnode/impl/src/mndStreamUtil.c index fec67fd839..e0f8c9e681 100644 --- a/source/dnode/mnode/impl/src/mndStreamUtil.c +++ b/source/dnode/mnode/impl/src/mndStreamUtil.c @@ -304,41 +304,6 @@ int32_t extractNodeEpset(SMnode *pMnode, SEpSet *pEpSet, bool *hasEpset, int32_t } } -static int32_t doSetResumeAction(STrans *pTrans, SMnode *pMnode, SStreamTask *pTask, int8_t igUntreated) { - terrno = 0; - - SVResumeStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVResumeStreamTaskReq)); - if (pReq == NULL) { - mError("failed to malloc in resume stream, size:%" PRIzu ", code:%s", sizeof(SVResumeStreamTaskReq), - tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - // terrno = TSDB_CODE_OUT_OF_MEMORY; - return terrno; - } - - pReq->head.vgId = htonl(pTask->info.nodeId); - pReq->taskId = pTask->id.taskId; - pReq->streamId = pTask->id.streamId; - pReq->igUntreated = igUntreated; - - SEpSet epset = {0}; - bool hasEpset = false; - int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); - if (code != TSDB_CODE_SUCCESS || (!hasEpset)) { - terrno = code; - taosMemoryFree(pReq); - return terrno; - } - - code = setTransAction(pTrans, pReq, sizeof(SVResumeStreamTaskReq), TDMT_STREAM_TASK_RESUME, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); - if (code != 0) { - taosMemoryFree(pReq); - return terrno; - } - - mDebug("set the resume action for trans:%d", pTrans->id); - return 0; -} - int32_t mndGetStreamTask(STaskId *pId, SStreamObj *pStream, SStreamTask **pTask) { *pTask = NULL; @@ -377,396 +342,29 @@ int32_t mndGetNumOfStreamTasks(const SStreamObj *pStream) { return num; } -int32_t mndStreamSetResumeAction(STrans *pTrans, SMnode *pMnode, SStreamObj *pStream, int8_t igUntreated) { - SStreamTaskIter *pIter = NULL; - int32_t code = createStreamTaskIter(pStream, &pIter); - if (code) { - mError("failed to create stream task iter:%s", pStream->name); - return code; +int32_t mndGetNumOfStreams(SMnode *pMnode, char *dbName, int32_t *pNumOfStreams) { + SSdb *pSdb = pMnode->pSdb; + SDbObj *pDb = mndAcquireDb(pMnode, dbName); + if (pDb == NULL) { + TAOS_RETURN(TSDB_CODE_MND_DB_NOT_SELECTED); } - while (streamTaskIterNextTask(pIter)) { - SStreamTask *pTask = NULL; - code = streamTaskIterGetCurrent(pIter, &pTask); - if (code || pTask == NULL) { - destroyStreamTaskIter(pIter); - return code; + int32_t numOfStreams = 0; + void *pIter = NULL; + while (1) { + SStreamObj *pStream = NULL; + pIter = sdbFetch(pSdb, SDB_STREAM, pIter, (void **)&pStream); + if (pIter == NULL) break; + + if (pStream->sourceDbUid == pDb->uid) { + numOfStreams++; } - code = doSetResumeAction(pTrans, pMnode, pTask, igUntreated); - if (code) { - destroyStreamTaskIter(pIter); - return code; - } - - if (atomic_load_8(&pTask->status.taskStatus) == TASK_STATUS__PAUSE) { - atomic_store_8(&pTask->status.taskStatus, pTask->status.statusBackup); - } - } - destroyStreamTaskIter(pIter); - return 0; -} - -static int32_t doSetPauseAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask) { - SVPauseStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVPauseStreamTaskReq)); - if (pReq == NULL) { - mError("failed to malloc in pause stream, size:%" PRIzu ", code:%s", sizeof(SVPauseStreamTaskReq), - tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - // terrno = TSDB_CODE_OUT_OF_MEMORY; - return terrno; + sdbRelease(pSdb, pStream); } - pReq->head.vgId = htonl(pTask->info.nodeId); - pReq->taskId = pTask->id.taskId; - pReq->streamId = pTask->id.streamId; - - SEpSet epset = {0}; - bool hasEpset = false; - int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); - if (code != TSDB_CODE_SUCCESS || !hasEpset) { - terrno = code; - taosMemoryFree(pReq); - return code; - } - - char buf[256] = {0}; - code = epsetToStr(&epset, buf, tListLen(buf)); - if (code != 0) { // print error and continue - mError("failed to convert epset to str, code:%s", tstrerror(code)); - } - - mDebug("pause stream task in node:%d, epset:%s", pTask->info.nodeId, buf); - code = setTransAction(pTrans, pReq, sizeof(SVPauseStreamTaskReq), TDMT_STREAM_TASK_PAUSE, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); - if (code != 0) { - taosMemoryFree(pReq); - return code; - } - return 0; -} - -int32_t mndStreamSetPauseAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { - SStreamTaskIter *pIter = NULL; - - int32_t code = createStreamTaskIter(pStream, &pIter); - if (code) { - mError("failed to create stream task iter:%s", pStream->name); - return code; - } - - while (streamTaskIterNextTask(pIter)) { - SStreamTask *pTask = NULL; - code = streamTaskIterGetCurrent(pIter, &pTask); - if (code) { - destroyStreamTaskIter(pIter); - return code; - } - - code = doSetPauseAction(pMnode, pTrans, pTask); - if (code) { - destroyStreamTaskIter(pIter); - return code; - } - - if (atomic_load_8(&pTask->status.taskStatus) != TASK_STATUS__PAUSE) { - atomic_store_8(&pTask->status.statusBackup, pTask->status.taskStatus); - atomic_store_8(&pTask->status.taskStatus, TASK_STATUS__PAUSE); - } - } - - destroyStreamTaskIter(pIter); - return code; -} - -static int32_t doSetDropAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask) { - SVDropStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVDropStreamTaskReq)); - if (pReq == NULL) { - // terrno = TSDB_CODE_OUT_OF_MEMORY; - return terrno; - } - - pReq->head.vgId = htonl(pTask->info.nodeId); - pReq->taskId = pTask->id.taskId; - pReq->streamId = pTask->id.streamId; - - SEpSet epset = {0}; - bool hasEpset = false; - int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); - if (code != TSDB_CODE_SUCCESS || !hasEpset) { // no valid epset, return directly without redoAction - return code; - } - - // The epset of nodeId of this task may have been expired now, let's use the newest epset from mnode. - code = setTransAction(pTrans, pReq, sizeof(SVDropStreamTaskReq), TDMT_STREAM_TASK_DROP, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); - if (code != 0) { - taosMemoryFree(pReq); - return code; - } - - return 0; -} - -int32_t mndStreamSetDropAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { - SStreamTaskIter *pIter = NULL; - - int32_t code = createStreamTaskIter(pStream, &pIter); - if (code) { - mError("failed to create stream task iter:%s", pStream->name); - return code; - } - - while(streamTaskIterNextTask(pIter)) { - SStreamTask *pTask = NULL; - code = streamTaskIterGetCurrent(pIter, &pTask); - if (code) { - destroyStreamTaskIter(pIter); - return code; - } - - code = doSetDropAction(pMnode, pTrans, pTask); - if (code) { - destroyStreamTaskIter(pIter); - return code; - } - } - destroyStreamTaskIter(pIter); - return 0; -} - -static int32_t doSetDropActionFromId(SMnode *pMnode, STrans *pTrans, SOrphanTask* pTask) { - SVDropStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVDropStreamTaskReq)); - if (pReq == NULL) { - // terrno = TSDB_CODE_OUT_OF_MEMORY; - return terrno; - } - - pReq->head.vgId = htonl(pTask->nodeId); - pReq->taskId = pTask->taskId; - pReq->streamId = pTask->streamId; - - SEpSet epset = {0}; - bool hasEpset = false; - int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->taskId, pTask->nodeId); - if (code != TSDB_CODE_SUCCESS || (!hasEpset)) { // no valid epset, return directly without redoAction - taosMemoryFree(pReq); - return code; - } - - // The epset of nodeId of this task may have been expired now, let's use the newest epset from mnode. - code = setTransAction(pTrans, pReq, sizeof(SVDropStreamTaskReq), TDMT_STREAM_TASK_DROP, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); - if (code != 0) { - taosMemoryFree(pReq); - return code; - } - - return 0; -} - -int32_t mndStreamSetDropActionFromList(SMnode *pMnode, STrans *pTrans, SArray* pList) { - for(int32_t i = 0; i < taosArrayGetSize(pList); ++i) { - SOrphanTask* pTask = taosArrayGet(pList, i); - if (pTask == NULL) { - return terrno; - } - - int32_t code = doSetDropActionFromId(pMnode, pTrans, pTask); - if (code != 0) { - return code; - } else { - mDebug("add drop task:0x%x action to drop orphan task", pTask->taskId); - } - } - return 0; -} - -static void initNodeUpdateMsg(SStreamTaskNodeUpdateMsg *pMsg, const SVgroupChangeInfo *pInfo, SStreamTaskId *pId, - int32_t transId) { - int32_t code = 0; - - pMsg->streamId = pId->streamId; - pMsg->taskId = pId->taskId; - pMsg->transId = transId; - pMsg->pNodeList = taosArrayInit(taosArrayGetSize(pInfo->pUpdateNodeList), sizeof(SNodeUpdateInfo)); - if (pMsg->pNodeList == NULL) { - mError("failed to prepare node list, code:%s", tstrerror(terrno)); - code = terrno; - } - - if (code == 0) { - void *p = taosArrayAddAll(pMsg->pNodeList, pInfo->pUpdateNodeList); - if (p == NULL) { - mError("failed to add update node list into nodeList"); - } - } -} - -static int32_t doBuildStreamTaskUpdateMsg(void **pBuf, int32_t *pLen, SVgroupChangeInfo *pInfo, int32_t nodeId, - SStreamTaskId *pId, int32_t transId) { - SStreamTaskNodeUpdateMsg req = {0}; - initNodeUpdateMsg(&req, pInfo, pId, transId); - - int32_t code = 0; - int32_t blen; - - tEncodeSize(tEncodeStreamTaskUpdateMsg, &req, blen, code); - if (code < 0) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - taosArrayDestroy(req.pNodeList); - return terrno; - } - - int32_t tlen = sizeof(SMsgHead) + blen; - - void *buf = taosMemoryMalloc(tlen); - if (buf == NULL) { - taosArrayDestroy(req.pNodeList); - return terrno; - } - - void *abuf = POINTER_SHIFT(buf, sizeof(SMsgHead)); - SEncoder encoder; - tEncoderInit(&encoder, abuf, tlen); - code = tEncodeStreamTaskUpdateMsg(&encoder, &req); - if (code == -1) { - tEncoderClear(&encoder); - taosMemoryFree(buf); - taosArrayDestroy(req.pNodeList); - return code; - } - - SMsgHead *pMsgHead = (SMsgHead *)buf; - pMsgHead->contLen = htonl(tlen); - pMsgHead->vgId = htonl(nodeId); - - tEncoderClear(&encoder); - - *pBuf = buf; - *pLen = tlen; - - taosArrayDestroy(req.pNodeList); - return TSDB_CODE_SUCCESS; -} - -static int32_t doSetUpdateTaskAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask, SVgroupChangeInfo *pInfo) { - void *pBuf = NULL; - int32_t len = 0; - SEpSet epset = {0}; - bool hasEpset = false; - - bool unusedRet = streamTaskUpdateEpsetInfo(pTask, pInfo->pUpdateNodeList); - int32_t code = doBuildStreamTaskUpdateMsg(&pBuf, &len, pInfo, pTask->info.nodeId, &pTask->id, pTrans->id); - if (code) { - mError("failed to build stream task epset update msg, code:%s", tstrerror(code)); - return code; - } - - code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); - if (code != TSDB_CODE_SUCCESS || !hasEpset) { - mError("failed to extract epset during create update epset, code:%s", tstrerror(code)); - return code; - } - - code = setTransAction(pTrans, pBuf, len, TDMT_VND_STREAM_TASK_UPDATE, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); - if (code != TSDB_CODE_SUCCESS) { - mError("failed to create update task epset trans, code:%s", tstrerror(code)); - taosMemoryFree(pBuf); - } - - return code; -} - -// build trans to update the epset -int32_t mndStreamSetUpdateEpsetAction(SMnode *pMnode, SStreamObj *pStream, SVgroupChangeInfo *pInfo, STrans *pTrans) { - mDebug("stream:0x%" PRIx64 " set tasks epset update action", pStream->uid); - SStreamTaskIter *pIter = NULL; - - taosWLockLatch(&pStream->lock); - int32_t code = createStreamTaskIter(pStream, &pIter); - if (code) { - taosWUnLockLatch(&pStream->lock); - mError("failed to create stream task iter:%s", pStream->name); - return code; - } - - while (streamTaskIterNextTask(pIter)) { - SStreamTask *pTask = NULL; - code = streamTaskIterGetCurrent(pIter, &pTask); - if (code) { - destroyStreamTaskIter(pIter); - taosWUnLockLatch(&pStream->lock); - return code; - } - - code = doSetUpdateTaskAction(pMnode, pTrans, pTask, pInfo); - if (code != TSDB_CODE_SUCCESS) { - destroyStreamTaskIter(pIter); - taosWUnLockLatch(&pStream->lock); - return code; - } - } - - destroyStreamTaskIter(pIter); - taosWUnLockLatch(&pStream->lock); - return 0; -} - -static int32_t doSetResetAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask) { - SVResetStreamTaskReq *pReq = taosMemoryCalloc(1, sizeof(SVResetStreamTaskReq)); - if (pReq == NULL) { - mError("failed to malloc in reset stream, size:%" PRIzu ", code:%s", sizeof(SVResetStreamTaskReq), - tstrerror(terrno)); - return terrno; - } - - pReq->head.vgId = htonl(pTask->info.nodeId); - pReq->taskId = pTask->id.taskId; - pReq->streamId = pTask->id.streamId; - - SEpSet epset = {0}; - bool hasEpset = false; - int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); - if (code != TSDB_CODE_SUCCESS || !hasEpset) { - taosMemoryFree(pReq); - return code; - } - - code = setTransAction(pTrans, pReq, sizeof(SVResetStreamTaskReq), TDMT_VND_STREAM_TASK_RESET, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); - if (code != TSDB_CODE_SUCCESS) { - taosMemoryFree(pReq); - } - - return code; -} - -int32_t mndStreamSetResetTaskAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { - SStreamTaskIter *pIter = NULL; - - taosWLockLatch(&pStream->lock); - int32_t code = createStreamTaskIter(pStream, &pIter); - if (code) { - taosWUnLockLatch(&pStream->lock); - mError("failed to create stream task iter:%s", pStream->name); - return code; - } - - while (streamTaskIterNextTask(pIter)) { - SStreamTask *pTask = NULL; - code = streamTaskIterGetCurrent(pIter, &pTask); - if (code) { - destroyStreamTaskIter(pIter); - taosWUnLockLatch(&pStream->lock); - return code; - } - - code = doSetResetAction(pMnode, pTrans, pTask); - if (code != TSDB_CODE_SUCCESS) { - destroyStreamTaskIter(pIter); - taosWUnLockLatch(&pStream->lock); - return code; - } - } - - destroyStreamTaskIter(pIter); - taosWUnLockLatch(&pStream->lock); + *pNumOfStreams = numOfStreams; + mndReleaseDb(pMnode, pDb); return 0; } @@ -1000,90 +598,6 @@ int32_t removeExpiredNodeEntryAndTaskInBuf(SArray *pNodeSnapshot) { return 0; } -static int32_t doSetUpdateChkptAction(SMnode *pMnode, STrans *pTrans, SStreamTask *pTask) { - SVUpdateCheckpointInfoReq *pReq = taosMemoryCalloc(1, sizeof(SVUpdateCheckpointInfoReq)); - if (pReq == NULL) { - mError("failed to malloc in reset stream, size:%" PRIzu ", code:%s", sizeof(SVUpdateCheckpointInfoReq), - tstrerror(terrno)); - return terrno; - } - - pReq->head.vgId = htonl(pTask->info.nodeId); - pReq->taskId = pTask->id.taskId; - pReq->streamId = pTask->id.streamId; - - SChkptReportInfo *pStreamItem = (SChkptReportInfo*)taosHashGet(execInfo.pChkptStreams, &pTask->id.streamId, sizeof(pTask->id.streamId)); - if (pStreamItem == NULL) { - return TSDB_CODE_INVALID_PARA; - } - - int32_t size = taosArrayGetSize(pStreamItem->pTaskList); - for(int32_t i = 0; i < size; ++i) { - STaskChkptInfo* pInfo = taosArrayGet(pStreamItem->pTaskList, i); - if (pInfo == NULL) { - continue; - } - - if (pInfo->taskId == pTask->id.taskId) { - pReq->checkpointId = pInfo->checkpointId; - pReq->checkpointVer = pInfo->version; - pReq->checkpointTs = pInfo->ts; - pReq->dropRelHTask = pInfo->dropHTask; - pReq->transId = pInfo->transId; - pReq->hStreamId = pTask->hTaskInfo.id.streamId; - pReq->hTaskId = pTask->hTaskInfo.id.taskId; - } - } - - SEpSet epset = {0}; - bool hasEpset = false; - int32_t code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); - if (code != TSDB_CODE_SUCCESS || !hasEpset) { - taosMemoryFree(pReq); - return code; - } - - code = setTransAction(pTrans, pReq, sizeof(SVUpdateCheckpointInfoReq), TDMT_STREAM_TASK_UPDATE_CHKPT, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); - if (code != TSDB_CODE_SUCCESS) { - taosMemoryFree(pReq); - } - - return code; -} - -int32_t mndStreamSetUpdateChkptAction(SMnode *pMnode, STrans *pTrans, SStreamObj *pStream) { - SStreamTaskIter *pIter = NULL; - - taosWLockLatch(&pStream->lock); - int32_t code = createStreamTaskIter(pStream, &pIter); - if (code) { - taosWUnLockLatch(&pStream->lock); - mError("failed to create stream task iter:%s", pStream->name); - return code; - } - - while (streamTaskIterNextTask(pIter)) { - SStreamTask *pTask = NULL; - code = streamTaskIterGetCurrent(pIter, &pTask); - if (code) { - destroyStreamTaskIter(pIter); - taosWUnLockLatch(&pStream->lock); - return code; - } - - code = doSetUpdateChkptAction(pMnode, pTrans, pTask); - if (code != TSDB_CODE_SUCCESS) { - destroyStreamTaskIter(pIter); - taosWUnLockLatch(&pStream->lock); - return code; - } - } - - destroyStreamTaskIter(pIter); - taosWUnLockLatch(&pStream->lock); - return code; -} - int32_t mndScanCheckpointReportInfo(SRpcMsg *pReq) { SMnode *pMnode = pReq->info.node; void *pIter = NULL; @@ -1172,60 +686,6 @@ int32_t mndScanCheckpointReportInfo(SRpcMsg *pReq) { return TSDB_CODE_SUCCESS; } -static int32_t mndStreamSetChkptIdAction(SMnode *pMnode, STrans *pTrans, SStreamTask* pTask, int64_t checkpointId, int64_t ts) { - SRestoreCheckpointInfo req = { - .taskId = pTask->id.taskId, - .streamId = pTask->id.streamId, - .checkpointId = checkpointId, - .startTs = ts, - .nodeId = pTask->info.nodeId, - .transId = pTrans->id, - }; - - int32_t code = 0; - int32_t blen; - tEncodeSize(tEncodeRestoreCheckpointInfo, &req, blen, code); - if (code < 0) { - return terrno; - } - - int32_t tlen = sizeof(SMsgHead) + blen; - - void *pBuf = taosMemoryMalloc(tlen); - if (pBuf == NULL) { - return terrno; - } - - void *abuf = POINTER_SHIFT(pBuf, sizeof(SMsgHead)); - SEncoder encoder; - tEncoderInit(&encoder, abuf, tlen); - code = tEncodeRestoreCheckpointInfo(&encoder, &req); - tEncoderClear(&encoder); - if (code == -1) { - taosMemoryFree(pBuf); - return code; - } - - SMsgHead *pMsgHead = (SMsgHead *)pBuf; - pMsgHead->contLen = htonl(tlen); - pMsgHead->vgId = htonl(pTask->info.nodeId); - - SEpSet epset = {0}; - bool hasEpset = false; - code = extractNodeEpset(pMnode, &epset, &hasEpset, pTask->id.taskId, pTask->info.nodeId); - if (code != TSDB_CODE_SUCCESS || !hasEpset) { - taosMemoryFree(pBuf); - return code; - } - - code = setTransAction(pTrans, pBuf, tlen, TDMT_STREAM_CONSEN_CHKPT, &epset, 0, TSDB_CODE_VND_INVALID_VGROUP_ID); - if (code != TSDB_CODE_SUCCESS) { - taosMemoryFree(pBuf); - } - - return code; -} - int32_t mndCreateSetConsensusChkptIdTrans(SMnode *pMnode, SStreamObj *pStream, int32_t taskId, int64_t checkpointId, int64_t ts) { char msg[128] = {0}; @@ -1882,6 +1342,163 @@ int32_t setTaskAttrInResBlock(SStreamObj *pStream, SStreamTask *pTask, SSDataBlo return code; } +static bool isNodeEpsetChanged(const SEpSet *pPrevEpset, const SEpSet *pCurrent) { + const SEp *pEp = GET_ACTIVE_EP(pPrevEpset); + const SEp *p = GET_ACTIVE_EP(pCurrent); + + if (pEp->port == p->port && strncmp(pEp->fqdn, p->fqdn, TSDB_FQDN_LEN) == 0) { + return false; + } + return true; +} + +void mndDestroyVgroupChangeInfo(SVgroupChangeInfo* pInfo) { + if (pInfo != NULL) { + taosArrayDestroy(pInfo->pUpdateNodeList); + taosHashCleanup(pInfo->pDBMap); + } +} + +// 1. increase the replica does not affect the stream process. +// 2. decreasing the replica may affect the stream task execution in the way that there is one or more running stream +// tasks on the will be removed replica. +// 3. vgroup redistribution is an combination operation of first increase replica and then decrease replica. So we +// will handle it as mentioned in 1 & 2 items. +int32_t mndFindChangedNodeInfo(SMnode *pMnode, const SArray *pPrevNodeList, const SArray *pNodeList, + SVgroupChangeInfo *pInfo) { + int32_t code = 0; + int32_t lino = 0; + + if (pInfo == NULL) { + return TSDB_CODE_INVALID_PARA; + } + + pInfo->pUpdateNodeList = taosArrayInit(4, sizeof(SNodeUpdateInfo)), + pInfo->pDBMap = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_NO_LOCK); + + if (pInfo->pUpdateNodeList == NULL || pInfo->pDBMap == NULL) { + mndDestroyVgroupChangeInfo(pInfo); + TSDB_CHECK_NULL(NULL, code, lino, _err, terrno); + } + + int32_t numOfNodes = taosArrayGetSize(pPrevNodeList); + for (int32_t i = 0; i < numOfNodes; ++i) { + SNodeEntry *pPrevEntry = taosArrayGet(pPrevNodeList, i); + if (pPrevEntry == NULL) { + continue; + } + + int32_t num = taosArrayGetSize(pNodeList); + for (int32_t j = 0; j < num; ++j) { + SNodeEntry *pCurrent = taosArrayGet(pNodeList, j); + if(pCurrent == NULL) { + continue; + } + + if (pCurrent->nodeId == pPrevEntry->nodeId) { + if (pPrevEntry->stageUpdated || isNodeEpsetChanged(&pPrevEntry->epset, &pCurrent->epset)) { + const SEp *pPrevEp = GET_ACTIVE_EP(&pPrevEntry->epset); + + char buf[256] = {0}; + code = epsetToStr(&pCurrent->epset, buf, tListLen(buf)); // ignore this error + if (code) { + mError("failed to convert epset string, code:%s", tstrerror(code)); + TSDB_CHECK_CODE(code, lino, _err); + } + + mDebug("nodeId:%d restart/epset changed detected, old:%s:%d -> new:%s, stageUpdate:%d", pCurrent->nodeId, + pPrevEp->fqdn, pPrevEp->port, buf, pPrevEntry->stageUpdated); + + SNodeUpdateInfo updateInfo = {.nodeId = pPrevEntry->nodeId}; + epsetAssign(&updateInfo.prevEp, &pPrevEntry->epset); + epsetAssign(&updateInfo.newEp, &pCurrent->epset); + + void* p = taosArrayPush(pInfo->pUpdateNodeList, &updateInfo); + TSDB_CHECK_NULL(p, code, lino, _err, terrno); + } + + // todo handle the snode info + if (pCurrent->nodeId != SNODE_HANDLE) { + SVgObj *pVgroup = mndAcquireVgroup(pMnode, pCurrent->nodeId); + code = taosHashPut(pInfo->pDBMap, pVgroup->dbName, strlen(pVgroup->dbName), NULL, 0); + mndReleaseVgroup(pMnode, pVgroup); + TSDB_CHECK_CODE(code, lino, _err); + } + + break; + } + } + } + + return code; + + _err: + mError("failed to find node change info, code:%s at %s line:%d", tstrerror(code), __func__, lino); + mndDestroyVgroupChangeInfo(pInfo); + return code; + } + +static int32_t doCheckForUpdated(SMnode *pMnode, SArray **ppNodeSnapshot) { + bool allReady = false; + bool nodeUpdated = false; + SVgroupChangeInfo changeInfo = {0}; + + int32_t numOfNodes = extractStreamNodeList(pMnode); + + if (numOfNodes == 0) { + mDebug("stream task node change checking done, no vgroups exist, do nothing"); + execInfo.ts = taosGetTimestampSec(); + return false; + } + + for (int32_t i = 0; i < numOfNodes; ++i) { + SNodeEntry *pNodeEntry = taosArrayGet(execInfo.pNodeList, i); + if (pNodeEntry == NULL) { + continue; + } + + if (pNodeEntry->stageUpdated) { + mDebug("stream task not ready due to node update detected, checkpoint not issued"); + return true; + } + } + + int32_t code = mndTakeVgroupSnapshot(pMnode, &allReady, ppNodeSnapshot); + if (code) { + mError("failed to get the vgroup snapshot, ignore it and continue"); + } + + if (!allReady) { + mWarn("not all vnodes ready, quit from vnodes status check"); + return true; + } + + code = mndFindChangedNodeInfo(pMnode, execInfo.pNodeList, *ppNodeSnapshot, &changeInfo); + if (code) { + nodeUpdated = false; + } else { + nodeUpdated = (taosArrayGetSize(changeInfo.pUpdateNodeList) > 0); + if (nodeUpdated) { + mDebug("stream tasks not ready due to node update"); + } + } + + mndDestroyVgroupChangeInfo(&changeInfo); + return nodeUpdated; +} + +// check if the node update happens or not +bool mndStreamNodeIsUpdated(SMnode *pMnode) { + SArray *pNodeSnapshot = NULL; + + streamMutexLock(&execInfo.lock); + bool updated = doCheckForUpdated(pMnode, &pNodeSnapshot); + streamMutexUnlock(&execInfo.lock); + + taosArrayDestroy(pNodeSnapshot); + return updated; +} + uint32_t seed = 0; static SRpcMsg createRpcMsg(STransAction* pAction, int64_t traceId, int64_t signature) { SRpcMsg rpcMsg = {.msgType = pAction->msgType, .contLen = pAction->contLen, .info.ahandle = (void *)signature}; diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index e73cc1b5db..50b8b3e275 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -497,11 +497,9 @@ int32_t mndInitSync(SMnode *pMnode) { pNode->nodePort = pMgmt->replicas[i].port; tstrncpy(pNode->nodeFqdn, pMgmt->replicas[i].fqdn, sizeof(pNode->nodeFqdn)); pNode->nodeRole = pMgmt->nodeRoles[i]; - if (tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort) != true) { - mError("failed to open sync, tmsgUpdateDnodeInfo is false"); - } - mInfo("vgId:1, index:%d ep:%s:%u dnode:%d cluster:%" PRId64, i, pNode->nodeFqdn, pNode->nodePort, pNode->nodeId, - pNode->clusterId); + bool update = tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); + mInfo("vgId:1, index:%d ep:%s:%u dnode:%d cluster:%" PRId64 ", update:%d", i, pNode->nodeFqdn, pNode->nodePort, + pNode->nodeId, pNode->clusterId, update); } int32_t code = 0; diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 8ca3d59868..99472ca457 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -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); diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index 3199292a7d..2fe1ef4cfb 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -14,7 +14,6 @@ */ #define _DEFAULT_SOURCE -#include "mndVgroup.h" #include "audit.h" #include "mndArbGroup.h" #include "mndDb.h" @@ -27,6 +26,7 @@ #include "mndTopic.h" #include "mndTrans.h" #include "mndUser.h" +#include "mndVgroup.h" #include "tmisce.h" #define VGROUP_VER_NUMBER 1 @@ -320,6 +320,7 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg createReq.tsdbPageSize = pDb->cfg.tsdbPageSize; createReq.changeVersion = ++(pVgroup->syncConfChangeVer); createReq.encryptAlgorithm = pDb->cfg.encryptAlgorithm; + int32_t code = 0; for (int32_t v = 0; v < pVgroup->replica; ++v) { SReplica *pReplica = NULL; @@ -390,7 +391,13 @@ void *mndBuildCreateVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVg return NULL; } - (void)tSerializeSCreateVnodeReq(pReq, contLen, &createReq); + code = tSerializeSCreateVnodeReq(pReq, contLen, &createReq); + if (code < 0) { + terrno = TSDB_CODE_APP_ERROR; + taosMemoryFree(pReq); + mError("vgId:%d, failed to serialize create vnode req,since %s", createReq.vgId, terrstr()); + return NULL; + } *pContLen = contLen; return pReq; } @@ -436,7 +443,12 @@ static void *mndBuildAlterVnodeConfigReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pV pHead->contLen = htonl(contLen); pHead->vgId = htonl(pVgroup->vgId); - (void)tSerializeSAlterVnodeConfigReq((char *)pReq + sizeof(SMsgHead), contLen, &alterReq); + if (tSerializeSAlterVnodeConfigReq((char *)pReq + sizeof(SMsgHead), contLen, &alterReq) < 0) { + taosMemoryFree(pReq); + mError("vgId:%d, failed to serialize alter vnode config req,since %s", pVgroup->vgId, terrstr()); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } *pContLen = contLen; return pReq; } @@ -514,7 +526,12 @@ static void *mndBuildAlterVnodeReplicaReq(SMnode *pMnode, SDbObj *pDb, SVgObj *p return NULL; } - (void)tSerializeSAlterVnodeReplicaReq(pReq, contLen, &alterReq); + if (tSerializeSAlterVnodeReplicaReq(pReq, contLen, &alterReq) < 0) { + mError("vgId:%d, failed to serialize alter vnode req,since %s", alterReq.vgId, terrstr()); + taosMemoryFree(pReq); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } *pContLen = contLen; return pReq; } @@ -587,7 +604,12 @@ static void *mndBuildCheckLearnCatchupReq(SMnode *pMnode, SDbObj *pDb, SVgObj *p return NULL; } - (void)tSerializeSAlterVnodeReplicaReq(pReq, contLen, &req); + if (tSerializeSAlterVnodeReplicaReq(pReq, contLen, &req) < 0) { + mError("vgId:%d, failed to serialize alter vnode req,since %s", req.vgId, terrstr()); + taosMemoryFree(pReq); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } *pContLen = contLen; return pReq; } @@ -611,7 +633,12 @@ static void *mndBuildDisableVnodeWriteReq(SMnode *pMnode, SDbObj *pDb, int32_t v return NULL; } - (void)tSerializeSDisableVnodeWriteReq(pReq, contLen, &disableReq); + if (tSerializeSDisableVnodeWriteReq(pReq, contLen, &disableReq) < 0) { + mError("vgId:%d, failed to serialize disable vnode write req,since %s", vgId, terrstr()); + taosMemoryFree(pReq); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } *pContLen = contLen; return pReq; } @@ -639,7 +666,12 @@ static void *mndBuildAlterVnodeHashRangeReq(SMnode *pMnode, int32_t srcVgId, SVg return NULL; } - (void)tSerializeSAlterVnodeHashRangeReq(pReq, contLen, &alterReq); + if (tSerializeSAlterVnodeHashRangeReq(pReq, contLen, &alterReq) < 0) { + mError("vgId:%d, failed to serialize alter vnode hashrange req,since %s", srcVgId, terrstr()); + taosMemoryFree(pReq); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } *pContLen = contLen; return pReq; } @@ -664,7 +696,12 @@ void *mndBuildDropVnodeReq(SMnode *pMnode, SDnodeObj *pDnode, SDbObj *pDb, SVgOb return NULL; } - (void)tSerializeSDropVnodeReq(pReq, contLen, &dropReq); + if (tSerializeSDropVnodeReq(pReq, contLen, &dropReq) < 0) { + mError("vgId:%d, failed to serialize drop vnode req,since %s", dropReq.vgId, terrstr()); + taosMemoryFree(pReq); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } *pContLen = contLen; return pReq; } @@ -907,7 +944,9 @@ SEpSet mndGetVgroupEpset(SMnode *pMnode, const SVgObj *pVgroup) { epset.inUse = epset.numOfEps; } - (void)addEpIntoEpSet(&epset, pDnode->fqdn, pDnode->port); + if (addEpIntoEpSet(&epset, pDnode->fqdn, pDnode->port) != 0) { + mWarn("vgId:%d, failed to add ep:%s:%d into epset", pVgroup->vgId, pDnode->fqdn, pDnode->port); + } mndReleaseDnode(pMnode, pDnode); } epsetSort(&epset); @@ -930,7 +969,9 @@ SEpSet mndGetVgroupEpsetById(SMnode *pMnode, int32_t vgId) { epset.inUse = epset.numOfEps; } - (void)addEpIntoEpSet(&epset, pDnode->fqdn, pDnode->port); + if (addEpIntoEpSet(&epset, pDnode->fqdn, pDnode->port) != 0) { + mWarn("vgId:%d, failed to add ep:%s:%d into epset", pVgroup->vgId, pDnode->fqdn, pDnode->port); + } mndReleaseDnode(pMnode, pDnode); } @@ -945,6 +986,7 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p SVgObj *pVgroup = NULL; int32_t cols = 0; int64_t curMs = taosGetTimestampMs(); + int32_t code = 0; SDbObj *pDb = NULL; if (strlen(pShow->db) > 0) { @@ -965,26 +1007,46 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p cols = 0; SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->vgId, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->vgId, false); + if (code != 0) { + mError("vgId:%d, failed to set vgId, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } SName name = {0}; char db[TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; - (void)tNameFromString(&name, pVgroup->dbName, T_NAME_ACCT | T_NAME_DB); + code = tNameFromString(&name, pVgroup->dbName, T_NAME_ACCT | T_NAME_DB); + if (code != 0) { + mError("vgId:%d, failed to set dbName, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } (void)tNameGetDbName(&name, varDataVal(db)); varDataSetLen(db, strlen(varDataVal(db))); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)db, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)db, false); + if (code != 0) { + mError("vgId:%d, failed to set dbName, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->numOfTables, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->numOfTables, false); + if (code != 0) { + mError("vgId:%d, failed to set numOfTables, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } // default 3 replica, add 1 replica if move vnode for (int32_t i = 0; i < 4; ++i) { pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); if (i < pVgroup->replica) { int16_t dnodeId = (int16_t)pVgroup->vnodeGid[i].dnodeId; - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&dnodeId, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&dnodeId, false); + if (code != 0) { + mError("vgId:%d, failed to set dnodeId, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } bool exist = false; bool online = false; @@ -1038,7 +1100,11 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p STR_WITH_MAXSIZE_TO_VARSTR(buf1, role, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)buf1, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)buf1, false); + if (code != 0) { + mError("vgId:%d, failed to set role, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } } else { colDataSetNULL(pColInfo, numOfRows); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); @@ -1048,21 +1114,25 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); int32_t cacheUsage = (int32_t)pVgroup->cacheUsage; - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&cacheUsage, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&cacheUsage, false); + if (code != 0) { + mError("vgId:%d, failed to set cacheUsage, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->numOfCachedTables, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->numOfCachedTables, false); + if (code != 0) { + mError("vgId:%d, failed to set numOfCachedTables, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->isTsma, false); - - // pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - // if (pDb == NULL || pDb->compactStartTime <= 0) { - // colDataSetNULL(pColInfo, numOfRows); - // } else { - // (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pDb->compactStartTime, false); - // } - + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->isTsma, false); + if (code != 0) { + mError("vgId:%d, failed to set isTsma, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } numOfRows++; sdbRelease(pSdb, pVgroup); } @@ -1147,6 +1217,7 @@ static int32_t mndRetrieveVnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB SVgObj *pVgroup = NULL; int32_t cols = 0; int64_t curMs = taosGetTimestampMs(); + int32_t code = 0; while (numOfRows < rows - TSDB_MAX_REPLICA) { pShow->pIter = sdbFetch(pSdb, SDB_VGROUP, pShow->pIter, (void **)&pVgroup); @@ -1158,10 +1229,17 @@ static int32_t mndRetrieveVnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB cols = 0; pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pGid->dnodeId, false); - + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pGid->dnodeId, false); + if (code != 0) { + mError("vgId:%d, failed to set dnodeId, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->vgId, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pVgroup->vgId, false); + if (code != 0) { + mError("vgId:%d, failed to set vgId, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } // db_name const char *dbname = mndGetDbStr(pVgroup->dbName); @@ -1172,7 +1250,11 @@ static int32_t mndRetrieveVnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB STR_WITH_MAXSIZE_TO_VARSTR(b1, "NULL", TSDB_DB_NAME_LEN + VARSTR_HEADER_SIZE); } pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)b1, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)b1, false); + if (code != 0) { + mError("vgId:%d, failed to set dbName, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } // dnode is online? SDnodeObj *pDnode = mndAcquireDnode(pMnode, pGid->dnodeId); @@ -1186,18 +1268,34 @@ static int32_t mndRetrieveVnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB ESyncState syncState = (isDnodeOnline) ? pGid->syncState : TAOS_SYNC_STATE_OFFLINE; STR_TO_VARSTR(buf, syncStr(syncState)); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)buf, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)buf, false); + if (code != 0) { + mError("vgId:%d, failed to set syncState, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } int64_t roleTimeMs = (isDnodeOnline) ? pGid->roleTimeMs : 0; pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&roleTimeMs, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&roleTimeMs, false); + if (code != 0) { + mError("vgId:%d, failed to set roleTimeMs, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } int64_t startTimeMs = (isDnodeOnline) ? pGid->startTimeMs : 0; pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&startTimeMs, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&startTimeMs, false); + if (code != 0) { + mError("vgId:%d, failed to set startTimeMs, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - (void)colDataSetVal(pColInfo, numOfRows, (const char *)&pGid->syncRestore, false); + code = colDataSetVal(pColInfo, numOfRows, (const char *)&pGid->syncRestore, false); + if (code != 0) { + mError("vgId:%d, failed to set syncRestore, since %s", pVgroup->vgId, tstrerror(code)); + return code; + } numOfRows++; sdbRelease(pSdb, pDnode); @@ -1270,8 +1368,10 @@ static int32_t mndAddVnodeToVgroup(SMnode *pMnode, STrans *pTrans, SVgObj *pVgro sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); - + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", pVgroup->vgId, tstrerror(code), __LINE__); + } TAOS_RETURN(code); } @@ -1332,7 +1432,10 @@ _OVER: sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", pVgroup->vgId, tstrerror(code), __LINE__); + } TAOS_RETURN(code); } @@ -1568,6 +1671,10 @@ int32_t mndAddNewVgPrepareAction(SMnode *pMnode, STrans *pTrans, SVgObj *pVg) { TAOS_CHECK_GOTO(mndTransAppendPrepareLog(pTrans, pRaw), NULL, _err); (void)sdbSetRawStatus(pRaw, SDB_STATUS_CREATING); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", pVg->vgId, tstrerror(code), __LINE__); + TAOS_RETURN(code); + } pRaw = NULL; TAOS_RETURN(code); @@ -1824,7 +1931,11 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, sdbFreeRaw(pRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", newVg.vgId, tstrerror(code), __LINE__); + return code; + } } TAOS_CHECK_RETURN(mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg, &del, true)); @@ -1850,7 +1961,6 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, sdbFreeRaw(pRaw); return -1; } - (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); } if (mndAddDropVnodeAction(pMnode, pTrans, pDb, &newVg, &del, true) != 0) return -1; @@ -1880,7 +1990,11 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, sdbFreeRaw(pRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", newVg.vgId, tstrerror(code), __LINE__); + return code; + } } for (int32_t i = 0; i < newVg.replica; ++i) { @@ -1930,7 +2044,11 @@ int32_t mndSetMoveVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SDbObj *pDb, sdbFreeRaw(pRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", newVg.vgId, tstrerror(code), __LINE__); + return code; + } } mInfo("vgId:%d, vgroup info after move, replica:%d", newVg.vgId, newVg.replica); @@ -2005,7 +2123,11 @@ static int32_t mndAddIncVgroupReplicaToTrans(SMnode *pMnode, STrans *pTrans, SDb sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", pVgroup->vgId, tstrerror(code), __LINE__); + TAOS_RETURN(code); + } // learner for (int32_t i = 0; i < pVgroup->replica - 1; ++i) { @@ -2057,7 +2179,11 @@ static int32_t mndAddDecVgroupReplicaFromTrans(SMnode *pMnode, STrans *pTrans, S sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", pVgroup->vgId, tstrerror(code), __LINE__); + TAOS_RETURN(code); + } TAOS_CHECK_RETURN(mndAddDropVnodeAction(pMnode, pTrans, pDb, pVgroup, &delGid, true)); for (int32_t i = 0; i < pVgroup->replica; ++i) { @@ -2171,7 +2297,11 @@ static int32_t mndRedistributeVgroup(SMnode *pMnode, SRpcMsg *pReq, SDbObj *pDb, sdbFreeRaw(pRaw); goto _OVER; } - (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", newVg.vgId, tstrerror(code), __LINE__); + goto _OVER; + } } mInfo("vgId:%d, vgroup info after redistribute, replica:%d", newVg.vgId, newVg.replica); @@ -2452,7 +2582,11 @@ static void *mndBuildSForceBecomeFollowerReq(SMnode *pMnode, SVgObj *pVgroup, in pHead->contLen = htonl(contLen); pHead->vgId = htonl(pVgroup->vgId); - (void)tSerializeSForceBecomeFollowerReq((char *)pReq + sizeof(SMsgHead), contLen, &balanceReq); + if (tSerializeSForceBecomeFollowerReq((char *)pReq + sizeof(SMsgHead), contLen, &balanceReq) < 0) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + taosMemoryFree(pReq); + return NULL; + } *pContLen = contLen; return pReq; } @@ -2693,7 +2827,11 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status since %s at line:%d", pNewVgroup->vgId, tstrerror(code), __LINE__); + TAOS_RETURN(code); + } } TAOS_RETURN(code); @@ -2776,7 +2914,12 @@ int32_t mndBuildRaftAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pO sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status to ready, error:%s, line:%d", newVgroup.vgId, tstrerror(code), + __LINE__); + TAOS_RETURN(code); + } } else if (newVgroup.replica == 3 && pNewDb->cfg.replications == 1) { mInfo("db:%s, vgId:%d, will remove 2 vnodes, vn:0 dnode:%d vn:1 dnode:%d vn:2 dnode:%d", pVgroup->dbName, pVgroup->vgId, pVgroup->vnodeGid[0].dnodeId, pVgroup->vnodeGid[1].dnodeId, pVgroup->vnodeGid[2].dnodeId); @@ -2801,7 +2944,12 @@ int32_t mndBuildRaftAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pO sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status to ready, error:%s, line:%d", newVgroup.vgId, tstrerror(code), + __LINE__); + TAOS_RETURN(code); + } SVnodeGid del2 = {0}; TAOS_CHECK_RETURN(mndRemoveVnodeFromVgroupWithoutSave(pMnode, pTrans, &newVgroup, pArray, &del2)); @@ -2823,7 +2971,12 @@ int32_t mndBuildRaftAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pO sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status to ready, error:%s, line:%d", newVgroup.vgId, tstrerror(code), + __LINE__); + TAOS_RETURN(code); + } } else { return -1; } @@ -2841,7 +2994,12 @@ int32_t mndBuildRaftAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pO sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status to ready, error:%s, line:%d", newVgroup.vgId, tstrerror(code), + __LINE__); + TAOS_RETURN(code); + } } TAOS_RETURN(code); @@ -2917,7 +3075,11 @@ int32_t mndBuildRestoreAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj sdbFreeRaw(pVgRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pVgRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status to ready, error:%s, line:%d", newVgroup.vgId, tstrerror(code), __LINE__); + TAOS_RETURN(code); + } TAOS_RETURN(code); } @@ -2938,7 +3100,11 @@ static int32_t mndAddVgStatusAction(STrans *pTrans, SVgObj *pVg, ESdbStatus vgSt goto _err; } if ((code = appendActionCb(pTrans, pRaw)) != 0) goto _err; - (void)sdbSetRawStatus(pRaw, vgStatus); + code = sdbSetRawStatus(pRaw, vgStatus); + if (code != 0) { + mError("vgId:%d, failed to set raw status to ready, error:%s, line:%d", pVg->vgId, tstrerror(code), __LINE__); + goto _err; + } pRaw = NULL; TAOS_RETURN(code); _err: @@ -2956,7 +3122,11 @@ static int32_t mndAddDbStatusAction(STrans *pTrans, SDbObj *pDb, ESdbStatus dbSt goto _err; } if ((code = appendActionCb(pTrans, pRaw)) != 0) goto _err; - (void)sdbSetRawStatus(pRaw, dbStatus); + code = sdbSetRawStatus(pRaw, dbStatus); + if (code != 0) { + mError("db:%s, failed to set raw status to ready, error:%s, line:%d", pDb->name, tstrerror(code), __LINE__); + goto _err; + } pRaw = NULL; TAOS_RETURN(code); _err: @@ -3165,7 +3335,11 @@ static int32_t mndSetBalanceVgroupInfoToTrans(SMnode *pMnode, STrans *pTrans, SD sdbFreeRaw(pRaw); TAOS_RETURN(code); } - (void)sdbSetRawStatus(pRaw, SDB_STATUS_READY); + code = sdbSetRawStatus(pRaw, SDB_STATUS_READY); + if (code != 0) { + mError("vgId:%d, failed to set raw status to ready, error:%s, line:%d", newVg.vgId, tstrerror(code), __LINE__); + TAOS_RETURN(code); + } } mInfo("vgId:%d, vgroup info after balance, replica:%d", newVg.vgId, newVg.replica); @@ -3391,7 +3565,11 @@ static void *mndBuildCompactVnodeReq(SMnode *pMnode, SDbObj *pDb, SVgObj *pVgrou pHead->contLen = htonl(contLen); pHead->vgId = htonl(pVgroup->vgId); - (void)tSerializeSCompactVnodeReq((char *)pReq + sizeof(SMsgHead), contLen, &compactReq); + if (tSerializeSCompactVnodeReq((char *)pReq + sizeof(SMsgHead), contLen, &compactReq) < 0) { + taosMemoryFree(pReq); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return NULL; + } *pContLen = contLen; return pReq; } diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 443e4433cc..204311aa98 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -125,7 +125,7 @@ int32_t metaGetTableTags(void *pVnode, uint64_t suid, SArray *uidList); int32_t metaGetTableTagsByUids(void *pVnode, int64_t suid, SArray *uidList); int32_t metaReadNext(SMetaReader *pReader); const void *metaGetTableTagVal(const void *tag, int16_t type, STagVal *tagVal); -int metaGetTableNameByUid(void *meta, uint64_t uid, char *tbName); +int32_t metaGetTableNameByUid(void *pVnode, uint64_t uid, char *tbName); int metaGetTableSzNameByUid(void *meta, uint64_t uid, char *tbName); int metaGetTableUidByName(void *pVnode, char *tbName, uint64_t *uid); diff --git a/source/dnode/vnode/src/inc/tsdb.h b/source/dnode/vnode/src/inc/tsdb.h index 38d6f020c7..20c43bb185 100644 --- a/source/dnode/vnode/src/inc/tsdb.h +++ b/source/dnode/vnode/src/inc/tsdb.h @@ -292,7 +292,7 @@ int32_t tsdbReadDelData(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx); // tsdbRead.c ============================================================================================== -int32_t tsdbTakeReadSnap2(STsdbReader *pReader, _query_reseek_func_t reseek, STsdbReadSnap **ppSnap, const char* id); +int32_t tsdbTakeReadSnap2(STsdbReader *pReader, _query_reseek_func_t reseek, STsdbReadSnap **ppSnap, const char *id); void tsdbUntakeReadSnap2(STsdbReader *pReader, STsdbReadSnap *pSnap, bool proactive); int32_t tsdbGetTableSchema(SMeta *pMeta, int64_t uid, STSchema **pSchema, int64_t *suid); @@ -1069,6 +1069,13 @@ int32_t tsdbSnapPrepDescription(SVnode *pVnode, SSnapshot *pSnap); void tsdbRemoveFile(const char *path); +#define taosCloseFileWithLog(fd) \ + do { \ + if (taosCloseFile(fd) < 0) { \ + tsdbTrace("failed to close file"); \ + } \ + } while (0) + #ifdef __cplusplus } #endif diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index e50ced2ebb..1bd4317234 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -143,7 +143,7 @@ typedef struct STbUidStore STbUidStore; int metaOpen(SVnode* pVnode, SMeta** ppMeta, int8_t rollback); int metaUpgrade(SVnode* pVnode, SMeta** ppMeta); -int metaClose(SMeta** pMeta); +void metaClose(SMeta** pMeta); int metaBegin(SMeta* pMeta, int8_t fromSys); TXN* metaGetTxn(SMeta* pMeta); int metaCommit(SMeta* pMeta, TXN* txn); @@ -207,7 +207,7 @@ int32_t metaGetInfo(SMeta* pMeta, int64_t uid, SMetaInfo* pInfo, SMetaReader* pR // tsdb int32_t tsdbOpen(SVnode* pVnode, STsdb** ppTsdb, const char* dir, STsdbKeepCfg* pKeepCfg, int8_t rollback, bool force); -int32_t tsdbClose(STsdb** pTsdb); +void tsdbClose(STsdb** pTsdb); int32_t tsdbBegin(STsdb* pTsdb); // int32_t tsdbPrepareCommit(STsdb* pTsdb); // int32_t tsdbCommit(STsdb* pTsdb, SCommitInfo* pInfo); @@ -284,7 +284,7 @@ int32_t tqProcessTaskConsenChkptIdReq(STQ* pTq, SRpcMsg* pMsg); int32_t smaInit(); void smaCleanUp(); int32_t smaOpen(SVnode* pVnode, int8_t rollback, bool force); -int32_t smaClose(SSma* pSma); +void smaClose(SSma* pSma); int32_t smaBegin(SSma* pSma); int32_t smaPrepareAsyncCommit(SSma* pSma); int32_t smaCommit(SSma* pSma, SCommitInfo* pInfo); @@ -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); diff --git a/source/dnode/vnode/src/meta/metaCache.c b/source/dnode/vnode/src/meta/metaCache.c index 06576c0671..91aa513aa6 100644 --- a/source/dnode/vnode/src/meta/metaCache.c +++ b/source/dnode/vnode/src/meta/metaCache.c @@ -216,7 +216,7 @@ void metaCacheClose(SMeta* pMeta) { } } -static int32_t metaRehashCache(SMetaCache* pCache, int8_t expand) { +static void metaRehashCache(SMetaCache* pCache, int8_t expand) { int32_t code = 0; int32_t nBucket; @@ -228,8 +228,7 @@ static int32_t metaRehashCache(SMetaCache* pCache, int8_t expand) { SMetaCacheEntry** aBucket = (SMetaCacheEntry**)taosMemoryCalloc(nBucket, sizeof(SMetaCacheEntry*)); if (aBucket == NULL) { - code = terrno; - goto _exit; + return; } // rehash @@ -250,9 +249,7 @@ static int32_t metaRehashCache(SMetaCache* pCache, int8_t expand) { taosMemoryFree(pCache->sEntryCache.aBucket); pCache->sEntryCache.nBucket = nBucket; pCache->sEntryCache.aBucket = aBucket; - -_exit: - return code; + return; } int32_t metaCacheUpsert(SMeta* pMeta, SMetaInfo* pInfo) { @@ -279,7 +276,7 @@ int32_t metaCacheUpsert(SMeta* pMeta, SMetaInfo* pInfo) { } } else { // insert if (pCache->sEntryCache.nEntry >= pCache->sEntryCache.nBucket) { - TAOS_UNUSED(metaRehashCache(pCache, 1)); + metaRehashCache(pCache, 1); iBucket = TABS(pInfo->uid) % pCache->sEntryCache.nBucket; } @@ -317,7 +314,7 @@ int32_t metaCacheDrop(SMeta* pMeta, int64_t uid) { pCache->sEntryCache.nEntry--; if (pCache->sEntryCache.nEntry < pCache->sEntryCache.nBucket / 4 && pCache->sEntryCache.nBucket > META_CACHE_BASE_BUCKET) { - TAOS_UNUSED(metaRehashCache(pCache, 0)); + metaRehashCache(pCache, 0); } } else { code = TSDB_CODE_NOT_FOUND; @@ -495,7 +492,7 @@ static int checkAllEntriesInCache(const STagFilterResEntry* pEntry, SArray* pInv return terrno; } } else { - (void)taosLRUCacheRelease(pCache, pRes, false); + bool ret = taosLRUCacheRelease(pCache, pRes, false); } } @@ -562,7 +559,7 @@ int32_t metaGetCachedTableUidList(void* pVnode, tb_uid_t suid, const uint8_t* pK ((double)(*pEntry)->hitTimes) / acc); } - (void)taosLRUCacheRelease(pCache, pHandle, false); + bool ret = taosLRUCacheRelease(pCache, pHandle, false); // unlock meta (void)taosThreadMutexUnlock(pLock); @@ -618,7 +615,7 @@ static int32_t addNewEntry(SHashObj* pTableEntry, const void* pKey, int32_t keyL p->hitTimes = 0; tdListInit(&p->list, keyLen); TAOS_CHECK_RETURN(taosHashPut(pTableEntry, &suid, sizeof(uint64_t), &p, POINTER_BYTES)); - (void)tdListAppend(&p->list, pKey); + TAOS_CHECK_RETURN(tdListAppend(&p->list, pKey)); return 0; } @@ -662,7 +659,10 @@ int32_t metaUidFilterCachePut(void* pVnode, uint64_t suid, const void* pKey, int } else { // check if it exists or not size_t size = listNEles(&(*pEntry)->list); if (size == 0) { - (void)tdListAppend(&(*pEntry)->list, pKey); + code = tdListAppend(&(*pEntry)->list, pKey); + if (code) { + goto _end; + } } else { SListNode* pNode = listHead(&(*pEntry)->list); uint64_t* p = (uint64_t*)pNode->data; @@ -671,7 +671,10 @@ int32_t metaUidFilterCachePut(void* pVnode, uint64_t suid, const void* pKey, int (void)taosThreadMutexUnlock(pLock); return TSDB_CODE_SUCCESS; } else { // not equal, append it - (void)tdListAppend(&(*pEntry)->list, pKey); + code = tdListAppend(&(*pEntry)->list, pKey); + if (code) { + goto _end; + } } } } @@ -761,7 +764,7 @@ int32_t metaGetCachedTbGroup(void* pVnode, tb_uid_t suid, const uint8_t* pKey, i ((double)(*pEntry)->hitTimes) / acc); } - (void)taosLRUCacheRelease(pCache, pHandle, false); + bool ret = taosLRUCacheRelease(pCache, pHandle, false); // unlock meta (void)taosThreadMutexUnlock(pLock); @@ -839,7 +842,10 @@ int32_t metaPutTbGroupToCache(void* pVnode, uint64_t suid, const void* pKey, int } else { // check if it exists or not size_t size = listNEles(&(*pEntry)->list); if (size == 0) { - (void)tdListAppend(&(*pEntry)->list, pKey); + code = tdListAppend(&(*pEntry)->list, pKey); + if (code) { + goto _end; + } } else { SListNode* pNode = listHead(&(*pEntry)->list); uint64_t* p = (uint64_t*)pNode->data; @@ -848,7 +854,10 @@ int32_t metaPutTbGroupToCache(void* pVnode, uint64_t suid, const void* pKey, int (void)taosThreadMutexUnlock(pLock); return TSDB_CODE_SUCCESS; } else { // not equal, append it - (void)tdListAppend(&(*pEntry)->list, pKey); + code = tdListAppend(&(*pEntry)->list, pKey); + if (code) { + goto _end; + } } } } diff --git a/source/dnode/vnode/src/meta/metaCommit.c b/source/dnode/vnode/src/meta/metaCommit.c index ec9e2d90ec..d8afd6aeaf 100644 --- a/source/dnode/vnode/src/meta/metaCommit.c +++ b/source/dnode/vnode/src/meta/metaCommit.c @@ -66,7 +66,10 @@ int metaPrepareAsyncCommit(SMeta *pMeta) { int32_t lino; metaWLock(pMeta); - TAOS_UNUSED(ttlMgrFlush(pMeta->pTtlMgr, pMeta->txn)); + int32_t ret = ttlMgrFlush(pMeta->pTtlMgr, pMeta->txn); + if (ret < 0) { + metaError("vgId:%d, failed to flush ttl since %s", TD_VID(pMeta->pVnode), tstrerror(ret)); + } metaULock(pMeta); code = tdbCommit(pMeta->pEnv, pMeta->txn); @@ -91,12 +94,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; } diff --git a/source/dnode/vnode/src/meta/metaOpen.c b/source/dnode/vnode/src/meta/metaOpen.c index 591c40332a..1da6ed584e 100644 --- a/source/dnode/vnode/src/meta/metaOpen.c +++ b/source/dnode/vnode/src/meta/metaOpen.c @@ -60,12 +60,13 @@ int32_t metaOpen(SVnode *pVnode, SMeta **ppMeta, int8_t rollback) { pMeta->path = (char *)&pMeta[1]; strcpy(pMeta->path, path); - (void)taosRealPath(pMeta->path, NULL, strlen(path) + 1); + int32_t ret = taosRealPath(pMeta->path, NULL, strlen(path) + 1); pMeta->pVnode = pVnode; // create path if not created yet - (void)taosMkDir(pMeta->path); + code = taosMkDir(pMeta->path); + TSDB_CHECK_CODE(code, lino, _exit); // open env code = tdbOpen(pMeta->path, pVnode->config.szPage, pVnode->config.szCache, &pMeta->pEnv, rollback, @@ -97,7 +98,7 @@ int32_t metaOpen(SVnode *pVnode, SMeta **ppMeta, int8_t rollback) { TSDB_CHECK_CODE(code, lino, _exit); sprintf(indexFullPath, "%s/%s", pMeta->path, "invert"); - TAOS_UNUSED(taosMkDir(indexFullPath)); + ret = taosMkDir(indexFullPath); SIndexOpts opts = {.cacheSize = 8 * 1024 * 1024}; code = indexOpen(&opts, indexFullPath, (SIndex **)&pMeta->pTagIvtIdx); @@ -169,9 +170,9 @@ _exit: return code; } -int metaClose(SMeta **ppMeta) { +void metaClose(SMeta **ppMeta) { metaCleanup(ppMeta); - return 0; + return; } int metaAlterCache(SMeta *pMeta, int32_t nPage) { diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index 3f6d17a5a7..14207e7fb3 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -62,7 +62,10 @@ int metaGetTableEntryByVersion(SMetaReader *pReader, int64_t version, tb_uid_t u tDecoderInit(&pReader->coder, pReader->pBuf, pReader->szBuf); code = metaDecodeEntry(&pReader->coder, &pReader->me); - if (code) return code; + if (code) { + tDecoderClear(&pReader->coder); + return code; + } // taosMemoryFreeClear(pReader->me.colCmpr.pColCmpr); return 0; @@ -393,6 +396,7 @@ _query: tDecoderInit(&dc, pData, nData); int32_t code = metaDecodeEntry(&dc, &me); if (code) { + tDecoderClear(&dc); goto _err; } if (me.type == TSDB_SUPER_TABLE) { @@ -1277,7 +1281,11 @@ int32_t metaFilterTableIds(void *pVnode, SMetaFltParam *arg, SArray *pUids) { tDecoderInit(&dc, pData, nData); - TAOS_CHECK_GOTO(metaDecodeEntry(&dc, &oStbEntry), NULL, END); + code = metaDecodeEntry(&dc, &oStbEntry); + if (code) { + tDecoderClear(&dc); + goto END; + } if (oStbEntry.stbEntry.schemaTag.pSchema == NULL || oStbEntry.stbEntry.schemaTag.pSchema == NULL) { TAOS_CHECK_GOTO(TSDB_CODE_INVALID_PARA, NULL, END); diff --git a/source/dnode/vnode/src/meta/metaSnapshot.c b/source/dnode/vnode/src/meta/metaSnapshot.c index 12ef5088b8..0936d8f092 100644 --- a/source/dnode/vnode/src/meta/metaSnapshot.c +++ b/source/dnode/vnode/src/meta/metaSnapshot.c @@ -87,7 +87,9 @@ int32_t metaSnapRead(SMetaSnapReader* pReader, uint8_t** ppData) { if (key.version < pReader->sver // || metaGetInfo(pReader->pMeta, key.uid, &info, NULL) == TSDB_CODE_NOT_FOUND) { - (void)tdbTbcMoveToNext(pReader->pTbc); + if (tdbTbcMoveToNext(pReader->pTbc) != 0) { + metaTrace("vgId:%d, vnode snapshot meta read data done", TD_VID(pReader->pMeta->pVnode)); + } continue; } @@ -110,7 +112,9 @@ int32_t metaSnapRead(SMetaSnapReader* pReader, uint8_t** ppData) { metaDebug("vgId:%d, vnode snapshot meta read data, version:%" PRId64 " uid:%" PRId64 " blockLen:%d", TD_VID(pReader->pMeta->pVnode), key.version, key.uid, nData); - (void)tdbTbcMoveToNext(pReader->pTbc); + if (tdbTbcMoveToNext(pReader->pTbc) != 0) { + metaTrace("vgId:%d, vnode snapshot meta read data done", TD_VID(pReader->pMeta->pVnode)); + } break; } @@ -233,7 +237,9 @@ static int32_t MoveToSnapShotVersion(SSnapContext* ctx) { return TAOS_GET_TERRNO(code); } if (c < 0) { - (void)tdbTbcMoveToPrev((TBC*)ctx->pCur); + if (tdbTbcMoveToPrev((TBC*)ctx->pCur) != 0) { + metaTrace("vgId:%d, vnode snapshot move to prev failed", TD_VID(ctx->pMeta->pVnode)); + } } return 0; } @@ -599,6 +605,7 @@ int32_t getTableInfoFromSnapshot(SSnapContext* ctx, void** pBuf, int32_t* contLe tDecoderInit(&dc, pVal, vLen); ret = metaDecodeEntry(&dc, &me); if (ret < 0) { + tDecoderClear(&dc); ret = TAOS_GET_TERRNO(ret); goto END; } diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 0fb8ca3fb1..8814e87140 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -22,7 +22,7 @@ static int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, con static int metaSaveToTbDb(SMeta *pMeta, const SMetaEntry *pME); static int metaUpdateUidIdx(SMeta *pMeta, const SMetaEntry *pME); static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME); -static int metaUpdateTtl(SMeta *pMeta, const SMetaEntry *pME); +static void metaUpdateTtl(SMeta *pMeta, const SMetaEntry *pME); static int metaUpdateChangeTime(SMeta *pMeta, tb_uid_t uid, int64_t changeTimeMs); static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME); static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME); @@ -285,7 +285,9 @@ static inline void metaTimeSeriesNotifyCheck(SMeta *pMeta) { int64_t deltaTS = nTimeSeries - pMeta->pVnode->config.vndStats.numOfReportedTimeSeries; if (deltaTS > tsTimeSeriesThreshold) { if (0 == atomic_val_compare_exchange_8(&dmNotifyHdl.state, 1, 2)) { - (void)tsem_post(&dmNotifyHdl.sem); + if (tsem_post(&dmNotifyHdl.sem) != 0) { + metaError("vgId:%d, failed to post semaphore, errno:%d", TD_VID(pMeta->pVnode), errno); + } } } #endif @@ -563,6 +565,7 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { if (ret < 0) { metaError("vgId:%d, failed to decode stb:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, pReq->suid, tstrerror(ret)); + tDecoderClear(&dc); tdbTbcClose(pTbDbc); tdbTbcClose(pUidIdxc); return terrno; @@ -1441,8 +1444,8 @@ static int metaBuildNColIdxKey(SNcolIdxKey *ncolKey, const SMetaEntry *pME) { return 0; } -static int metaDeleteTtl(SMeta *pMeta, const SMetaEntry *pME) { - if (pME->type != TSDB_CHILD_TABLE && pME->type != TSDB_NORMAL_TABLE) return 0; +static void metaDeleteTtl(SMeta *pMeta, const SMetaEntry *pME) { + if (pME->type != TSDB_CHILD_TABLE && pME->type != TSDB_NORMAL_TABLE) return; STtlDelTtlCtx ctx = {.uid = pME->uid, .pTxn = pMeta->txn}; if (pME->type == TSDB_CHILD_TABLE) { @@ -1451,7 +1454,12 @@ static int metaDeleteTtl(SMeta *pMeta, const SMetaEntry *pME) { ctx.ttlDays = pME->ntbEntry.ttlDays; } - return ttlMgrDeleteTtl(pMeta->pTtlMgr, &ctx); + int32_t ret = ttlMgrDeleteTtl(pMeta->pTtlMgr, &ctx); + if (ret < 0) { + metaError("vgId:%d, failed to delete ttl for table:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pME->name, + pME->uid, tstrerror(ret)); + } + return; } static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *pSuid, int8_t *pSysTbl) { @@ -1497,6 +1505,7 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type, tb_uid_t *p tDecoderInit(&tdc, tData, tLen); int32_t ret = metaDecodeEntry(&tdc, &stbEntry); if (ret < 0) { + tDecoderClear(&tdc); metaError("vgId:%d, failed to decode child table:%s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), e.name, e.ctbEntry.suid, tstrerror(ret)); return ret; @@ -1831,12 +1840,19 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl if (!TSDB_CACHE_NO(pMeta->pVnode->config)) { int16_t cid = pSchema->pSchema[entry.ntbEntry.schemaRow.nCols - 1].colId; int8_t col_type = pSchema->pSchema[entry.ntbEntry.schemaRow.nCols - 1].type; - (void)tsdbCacheNewNTableColumn(pMeta->pVnode->pTsdb, entry.uid, cid, col_type); + int32_t ret = tsdbCacheNewNTableColumn(pMeta->pVnode->pTsdb, entry.uid, cid, col_type); + if (ret < 0) { + terrno = ret; + goto _err; + } } SSchema *pCol = &pSchema->pSchema[entry.ntbEntry.schemaRow.nCols - 1]; uint32_t compress = pAlterTbReq->action == TSDB_ALTER_TABLE_ADD_COLUMN ? createDefaultColCmprByType(pCol->type) : pAlterTbReq->compress; - (void)updataTableColCmpr(&entry.colCmpr, pCol, 1, compress); + if (updataTableColCmpr(&entry.colCmpr, pCol, 1, compress) != 0) { + metaError("vgId:%d, failed to update table col cmpr:%s uid:%" PRId64, TD_VID(pMeta->pVnode), entry.name, + entry.uid); + } freeColCmpr = true; if (entry.colCmpr.nCols != pSchema->nCols) { if (pNewSchema) taosMemoryFree(pNewSchema); @@ -1876,10 +1892,16 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl if (!TSDB_CACHE_NO(pMeta->pVnode->config)) { int16_t cid = pColumn->colId; - (void)tsdbCacheDropNTableColumn(pMeta->pVnode->pTsdb, entry.uid, cid, hasPrimayKey); + if (tsdbCacheDropNTableColumn(pMeta->pVnode->pTsdb, entry.uid, cid, hasPrimayKey) != 0) { + metaError("vgId:%d, failed to drop ntable column:%s uid:%" PRId64, TD_VID(pMeta->pVnode), entry.name, + entry.uid); + } } - (void)updataTableColCmpr(&entry.colCmpr, &tScheam, 0, 0); + if (updataTableColCmpr(&entry.colCmpr, &tScheam, 0, 0) != 0) { + metaError("vgId:%d, failed to update table col cmpr:%s uid:%" PRId64, TD_VID(pMeta->pVnode), entry.name, + entry.uid); + } if (entry.colCmpr.nCols != pSchema->nCols) { terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION; goto _err; @@ -1928,20 +1950,36 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl // do actual write metaWLock(pMeta); - (void)metaDeleteNcolIdx(pMeta, &oldEntry); - (void)metaUpdateNcolIdx(pMeta, &entry); + if (metaDeleteNcolIdx(pMeta, &oldEntry) < 0) { + metaError("vgId:%d, failed to delete ncol idx:%s uid:%" PRId64, TD_VID(pMeta->pVnode), entry.name, entry.uid); + } + + if (metaUpdateNcolIdx(pMeta, &entry) < 0) { + metaError("vgId:%d, failed to update ncol idx:%s uid:%" PRId64, TD_VID(pMeta->pVnode), entry.name, entry.uid); + } + // save to table db - (void)metaSaveToTbDb(pMeta, &entry); + if (metaSaveToTbDb(pMeta, &entry) < 0) { + metaError("vgId:%d, failed to save to tb db:%s uid:%" PRId64, TD_VID(pMeta->pVnode), entry.name, entry.uid); + } - (void)metaUpdateUidIdx(pMeta, &entry); + if (metaUpdateUidIdx(pMeta, &entry) < 0) { + metaError("vgId:%d, failed to update uid idx:%s uid:%" PRId64, TD_VID(pMeta->pVnode), entry.name, entry.uid); + } - (void)metaSaveToSkmDb(pMeta, &entry); + if (metaSaveToSkmDb(pMeta, &entry) < 0) { + metaError("vgId:%d, failed to save to skm db:%s uid:%" PRId64, TD_VID(pMeta->pVnode), entry.name, entry.uid); + } - (void)metaUpdateChangeTime(pMeta, entry.uid, pAlterTbReq->ctimeMs); + if (metaUpdateChangeTime(pMeta, entry.uid, pAlterTbReq->ctimeMs) < 0) { + metaError("vgId:%d, failed to update change time:%s uid:%" PRId64, TD_VID(pMeta->pVnode), entry.name, entry.uid); + } metaULock(pMeta); - (void)metaUpdateMetaRsp(uid, pAlterTbReq->tbName, pSchema, pMetaRsp); + if (metaUpdateMetaRsp(uid, pAlterTbReq->tbName, pSchema, pMetaRsp) < 0) { + metaError("vgId:%d, failed to update meta rsp:%s uid:%" PRId64, TD_VID(pMeta->pVnode), entry.name, entry.uid); + } for (int32_t i = 0; i < entry.colCmpr.nCols; i++) { SColCmpr *p = &entry.colCmpr.pColCmpr[i]; pMetaRsp->pSchemaExt[i].colId = p->id; @@ -1997,14 +2035,18 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA TBC *pUidIdxc = NULL; TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL)); - (void)tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c); + if (tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c) < 0) { + metaTrace("meta/table: failed to move to uid index, uid:%" PRId64, uid); + } if (c != 0) { tdbTbcClose(pUidIdxc); metaError("meta/table: invalide c: %" PRId32 " update tb tag val failed.", c); return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST; } - (void)tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData); + if (tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData) != 0) { + metaError("meta/table: failed to get uid index, uid:%" PRId64, uid); + } oversion = ((SUidIdxVal *)pData)[0].version; // search table.db @@ -2014,7 +2056,9 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA /* get ctbEntry */ TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL)); - (void)tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c); + if (tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c) != 0) { + metaError("meta/table: failed to move to tb db, uid:%" PRId64, uid); + } if (c != 0) { tdbTbcClose(pUidIdxc); tdbTbcClose(pTbDbc); @@ -2022,29 +2066,43 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA return terrno = TSDB_CODE_TDB_TABLE_NOT_EXIST; } - (void)tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData); + if (tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData) != 0) { + metaError("meta/table: failed to get tb db, uid:%" PRId64, uid); + } if ((ctbEntry.pBuf = taosMemoryMalloc(nData)) == NULL) { - (void)tdbTbcClose(pUidIdxc); - (void)tdbTbcClose(pTbDbc); + tdbTbcClose(pUidIdxc); + tdbTbcClose(pTbDbc); return terrno; } memcpy(ctbEntry.pBuf, pData, nData); tDecoderInit(&dc1, ctbEntry.pBuf, nData); - (void)metaDecodeEntry(&dc1, &ctbEntry); + ret = metaDecodeEntry(&dc1, &ctbEntry); + if (ret < 0) { + terrno = ret; + goto _err; + } /* get stbEntry*/ - (void)tdbTbGet(pMeta->pUidIdx, &ctbEntry.ctbEntry.suid, sizeof(tb_uid_t), &pVal, &nVal); + if (tdbTbGet(pMeta->pUidIdx, &ctbEntry.ctbEntry.suid, sizeof(tb_uid_t), &pVal, &nVal) != 0) { + metaError("meta/table: failed to get uid index, uid:%" PRId64, ctbEntry.ctbEntry.suid); + } if (!pVal) { terrno = TSDB_CODE_INVALID_MSG; goto _err; } - (void)tdbTbGet(pMeta->pTbDb, &((STbDbKey){.uid = ctbEntry.ctbEntry.suid, .version = ((SUidIdxVal *)pVal)[0].version}), - sizeof(STbDbKey), (void **)&stbEntry.pBuf, &nVal); + if (tdbTbGet(pMeta->pTbDb, &((STbDbKey){.uid = ctbEntry.ctbEntry.suid, .version = ((SUidIdxVal *)pVal)[0].version}), + sizeof(STbDbKey), (void **)&stbEntry.pBuf, &nVal) != 0) { + metaError("meta/table: failed to get tb db, uid:%" PRId64, ctbEntry.ctbEntry.suid); + } tdbFree(pVal); tDecoderInit(&dc2, stbEntry.pBuf, nVal); - (void)metaDecodeEntry(&dc2, &stbEntry); + ret = metaDecodeEntry(&dc2, &stbEntry); + if (ret < 0) { + terrno = ret; + goto _err; + } SSchemaWrapper *pTagSchema = &stbEntry.stbEntry.schemaTag; SSchema *pColumn = NULL; @@ -2122,12 +2180,18 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA metaWLock(pMeta); // save to table.db - (void)metaSaveToTbDb(pMeta, &ctbEntry); + if (metaSaveToTbDb(pMeta, &ctbEntry) < 0) { + metaError("meta/table: failed to save to tb db:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid); + } // save to uid.idx - (void)metaUpdateUidIdx(pMeta, &ctbEntry); + if (metaUpdateUidIdx(pMeta, &ctbEntry) < 0) { + metaError("meta/table: failed to update uid idx:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid); + } - (void)metaUpdateTagIdx(pMeta, &ctbEntry); + if (metaUpdateTagIdx(pMeta, &ctbEntry) < 0) { + metaError("meta/table: failed to update tag idx:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid); + } if (NULL == ctbEntry.ctbEntry.pTags) { metaError("meta/table: null tags, update tag val failed."); @@ -2135,13 +2199,22 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA } SCtbIdxKey ctbIdxKey = {.suid = ctbEntry.ctbEntry.suid, .uid = uid}; - (void)tdbTbUpsert(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), ctbEntry.ctbEntry.pTags, - ((STag *)(ctbEntry.ctbEntry.pTags))->len, pMeta->txn); + if (tdbTbUpsert(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), ctbEntry.ctbEntry.pTags, + ((STag *)(ctbEntry.ctbEntry.pTags))->len, pMeta->txn) < 0) { + metaError("meta/table: failed to upsert ctb idx:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid); + } - (void)metaUidCacheClear(pMeta, ctbEntry.ctbEntry.suid); - (void)metaTbGroupCacheClear(pMeta, ctbEntry.ctbEntry.suid); + if (metaUidCacheClear(pMeta, ctbEntry.ctbEntry.suid) < 0) { + metaError("meta/table: failed to clear uid cache:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid); + } - (void)metaUpdateChangeTime(pMeta, ctbEntry.uid, pAlterTbReq->ctimeMs); + if (metaTbGroupCacheClear(pMeta, ctbEntry.ctbEntry.suid) < 0) { + metaError("meta/table: failed to clear group cache:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid); + } + + if (metaUpdateChangeTime(pMeta, ctbEntry.uid, pAlterTbReq->ctimeMs) < 0) { + metaError("meta/table: failed to update change time:%s uid:%" PRId64, ctbEntry.name, ctbEntry.uid); + } metaULock(pMeta); @@ -2189,21 +2262,27 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p TBC *pUidIdxc = NULL; TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, NULL)); - (void)tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c); + if (tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c) < 0) { + metaError("meta/table: failed to move to uid index, uid:%" PRId64, uid); + } if (c != 0) { tdbTbcClose(pUidIdxc); metaError("meta/table: invalide c: %" PRId32 " update tb options failed.", c); return TSDB_CODE_FAILED; } - (void)tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData); + if (tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData) < 0) { + metaError("meta/table: failed to get uid index, uid:%" PRId64, uid); + } oversion = ((SUidIdxVal *)pData)[0].version; // search table.db TBC *pTbDbc = NULL; TAOS_CHECK_RETURN(tdbTbcOpen(pMeta->pTbDb, &pTbDbc, NULL)); - (void)tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c); + if (tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c) < 0) { + metaError("meta/table: failed to move to tb db, uid:%" PRId64, uid); + } if (c != 0) { tdbTbcClose(pUidIdxc); tdbTbcClose(pTbDbc); @@ -2211,13 +2290,15 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p return TSDB_CODE_FAILED; } - (void)tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData); + if (tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData) < 0) { + metaError("meta/table: failed to get tb db, uid:%" PRId64, uid); + } // get table entry SDecoder dc = {0}; if ((entry.pBuf = taosMemoryMalloc(nData)) == NULL) { - (void)tdbTbcClose(pUidIdxc); - (void)tdbTbcClose(pTbDbc); + tdbTbcClose(pUidIdxc); + tdbTbcClose(pTbDbc); return terrno; } memcpy(entry.pBuf, pData, nData); @@ -2236,9 +2317,9 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p // build SMetaEntry if (entry.type == TSDB_CHILD_TABLE) { if (pAlterTbReq->updateTTL) { - (void)metaDeleteTtl(pMeta, &entry); + metaDeleteTtl(pMeta, &entry); entry.ctbEntry.ttlDays = pAlterTbReq->newTTL; - (void)metaUpdateTtl(pMeta, &entry); + metaUpdateTtl(pMeta, &entry); } if (pAlterTbReq->newCommentLen >= 0) { entry.ctbEntry.commentLen = pAlterTbReq->newCommentLen; @@ -2246,9 +2327,9 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p } } else { if (pAlterTbReq->updateTTL) { - (void)metaDeleteTtl(pMeta, &entry); + metaDeleteTtl(pMeta, &entry); entry.ntbEntry.ttlDays = pAlterTbReq->newTTL; - (void)metaUpdateTtl(pMeta, &entry); + metaUpdateTtl(pMeta, &entry); } if (pAlterTbReq->newCommentLen >= 0) { entry.ntbEntry.commentLen = pAlterTbReq->newCommentLen; @@ -2257,9 +2338,17 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p } // save to table db - (void)metaSaveToTbDb(pMeta, &entry); - (void)metaUpdateUidIdx(pMeta, &entry); - (void)metaUpdateChangeTime(pMeta, entry.uid, pAlterTbReq->ctimeMs); + if (metaSaveToTbDb(pMeta, &entry) < 0) { + metaError("meta/table: failed to save to tb db:%s uid:%" PRId64, entry.name, entry.uid); + } + + if (metaUpdateUidIdx(pMeta, &entry) < 0) { + metaError("meta/table: failed to update uid idx:%s uid:%" PRId64, entry.name, entry.uid); + } + + if (metaUpdateChangeTime(pMeta, entry.uid, pAlterTbReq->ctimeMs) < 0) { + metaError("meta/table: failed to update change time:%s uid:%" PRId64, entry.name, entry.uid); + } metaULock(pMeta); @@ -2305,10 +2394,14 @@ static int metaAddTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTb STbDbKey tbDbKey = {0}; tbDbKey.uid = suid; tbDbKey.version = ((SUidIdxVal *)pVal)[0].version; - (void)tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pVal, &nVal); + ret = tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pVal, &nVal); + if (ret < 0) { + goto _err; + } tDecoderInit(&dc, pVal, nVal); ret = metaDecodeEntry(&dc, &stbEntry); if (ret < 0) { + tDecoderClear(&dc); goto _err; } @@ -2384,7 +2477,10 @@ static int metaAddTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTb tdbTbcClose(pCtbIdxc); goto _err; } - (void)tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, pMeta->txn); + ret = tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, pMeta->txn); + if (ret < 0) { + metaError("meta/table: failed to upsert tag idx:%s uid:%" PRId64, stbEntry.name, stbEntry.uid); + } metaDestroyTagIdxKey(pTagIdxKey); pTagIdxKey = NULL; } @@ -2439,11 +2535,15 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT STbDbKey tbDbKey = {0}; tbDbKey.uid = suid; tbDbKey.version = ((SUidIdxVal *)pVal)[0].version; - (void)tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pVal, &nVal); + ret = tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pVal, &nVal); + if (ret < 0) { + goto _err; + } tDecoderInit(&dc, pVal, nVal); ret = metaDecodeEntry(&dc, &stbEntry); if (ret < 0) { + tDecoderClear(&dc); goto _err; } @@ -2507,7 +2607,10 @@ static int metaDropTagIndex(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterT metaWLock(pMeta); for (int i = 0; i < taosArrayGetSize(tagIdxList); i++) { SMetaPair *pair = taosArrayGet(tagIdxList, i); - (void)tdbTbDelete(pMeta->pTagIdx, pair->key, pair->nkey, pMeta->txn); + ret = tdbTbDelete(pMeta->pTagIdx, pair->key, pair->nkey, pMeta->txn); + if (ret < 0) { + metaError("meta/table: failed to delete tag idx:%s uid:%" PRId64, stbEntry.name, stbEntry.uid); + } } metaULock(pMeta); @@ -2594,9 +2697,17 @@ int32_t metaUpdateTableColCompress(SMeta *pMeta, int64_t version, SVAlterTbReq * tbEntry.version = version; metaWLock(pMeta); - (void)metaSaveToTbDb(pMeta, &tbEntry); - (void)metaUpdateUidIdx(pMeta, &tbEntry); - (void)metaUpdateChangeTime(pMeta, suid, pReq->ctimeMs); + if (metaSaveToTbDb(pMeta, &tbEntry) < 0) { + metaError("meta/table: failed to save to tb db:%s uid:%" PRId64, tbEntry.name, tbEntry.uid); + } + + if (metaUpdateUidIdx(pMeta, &tbEntry) < 0) { + metaError("meta/table: failed to update uid idx:%s uid:%" PRId64, tbEntry.name, tbEntry.uid); + } + + if (metaUpdateChangeTime(pMeta, suid, pReq->ctimeMs) < 0) { + metaError("meta/table: failed to update change time:%s uid:%" PRId64, tbEntry.name, tbEntry.uid); + } metaULock(pMeta); @@ -2691,7 +2802,10 @@ static int metaUpdateUidIdx(SMeta *pMeta, const SMetaEntry *pME) { // upsert cache SMetaInfo info; metaGetEntryInfo(pME, &info); - (void)metaCacheUpsert(pMeta, &info); + int32_t ret = metaCacheUpsert(pMeta, &info); + if (ret < 0) { + metaError("vgId:%d, failed to upsert cache, uid: %" PRId64 " %s", TD_VID(pMeta->pVnode), pME->uid, tstrerror(ret)); + } SUidIdxVal uidIdxVal = {.suid = info.suid, .version = info.version, .skmVer = info.skmVer}; @@ -2706,8 +2820,8 @@ static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME) { return tdbTbUpsert(pMeta->pNameIdx, pME->name, strlen(pME->name) + 1, &pME->uid, sizeof(tb_uid_t), pMeta->txn); } -static int metaUpdateTtl(SMeta *pMeta, const SMetaEntry *pME) { - if (pME->type != TSDB_CHILD_TABLE && pME->type != TSDB_NORMAL_TABLE) return 0; +static void metaUpdateTtl(SMeta *pMeta, const SMetaEntry *pME) { + if (pME->type != TSDB_CHILD_TABLE && pME->type != TSDB_NORMAL_TABLE) return; STtlUpdTtlCtx ctx = {.uid = pME->uid, .pTxn = pMeta->txn}; if (pME->type == TSDB_CHILD_TABLE) { @@ -2718,7 +2832,12 @@ static int metaUpdateTtl(SMeta *pMeta, const SMetaEntry *pME) { ctx.changeTimeMs = pME->ntbEntry.btime; } - return ttlMgrInsertTtl(pMeta->pTtlMgr, &ctx); + int32_t ret = ttlMgrInsertTtl(pMeta->pTtlMgr, &ctx); + if (ret < 0) { + metaError("vgId:%d, failed to insert ttl, uid: %" PRId64 " %s", TD_VID(pMeta->pVnode), pME->uid, tstrerror(ret)); + } + + return; } static int metaUpdateChangeTime(SMeta *pMeta, tb_uid_t uid, int64_t changeTimeMs) { @@ -2806,7 +2925,11 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) { } tbDbKey.uid = pCtbEntry->ctbEntry.suid; tbDbKey.version = ((SUidIdxVal *)pData)[0].version; - (void)tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pData, &nData); + ret = tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pData, &nData); + if (ret < 0) { + metaError("vgId:%d, failed to get stable for update. version:%" PRId64, TD_VID(pMeta->pVnode), pCtbEntry->version); + goto end; + } tDecoderInit(&dc, pData, nData); ret = metaDecodeEntry(&dc, &stbEntry); @@ -2854,7 +2977,9 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) { ret = -1; goto end; } - (void)tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, pMeta->txn); + if (tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, pMeta->txn) < 0) { + metaError("vgId:%d, failed to update tag index. version:%" PRId64, TD_VID(pMeta->pVnode), pCtbEntry->version); + } metaDestroyTagIdxKey(pTagIdxKey); pTagIdxKey = NULL; } @@ -2905,7 +3030,11 @@ static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME) { } tEncoderInit(&coder, pVal, vLen); - (void)tEncodeSSchemaWrapper(&coder, pSW); + ret = tEncodeSSchemaWrapper(&coder, pSW); + if (ret < 0) { + rcode = -1; + goto _exit; + } if (tdbTbInsert(pMeta->pSkmDb, &skmDbKey, sizeof(skmDbKey), pVal, vLen, pMeta->txn) < 0) { rcode = -1; @@ -2966,8 +3095,7 @@ int metaHandleEntry(SMeta *pMeta, const SMetaEntry *pME) { } if (pME->type != TSDB_SUPER_TABLE) { - code = metaUpdateTtl(pMeta, pME); - VND_CHECK_CODE(code, line, _err); + metaUpdateTtl(pMeta, pME); } if (pME->type == TSDB_SUPER_TABLE || pME->type == TSDB_NORMAL_TABLE) { @@ -2985,7 +3113,7 @@ _err: return TSDB_CODE_FAILED; } -int32_t colCompressDebug(SHashObj *pColCmprObj) { +static void colCompressDebug(SHashObj *pColCmprObj) { void *p = taosHashIterate(pColCmprObj, NULL); while (p) { uint32_t cmprAlg = *(uint32_t *)p; @@ -2993,14 +3121,14 @@ int32_t colCompressDebug(SHashObj *pColCmprObj) { p = taosHashIterate(pColCmprObj, p); uint8_t l1, l2, lvl; - (void)tcompressDebug(cmprAlg, &l1, &l2, &lvl); + tcompressDebug(cmprAlg, &l1, &l2, &lvl); const char *l1str = columnEncodeStr(l1); const char *l2str = columnCompressStr(l2); const char *lvlstr = columnLevelStr(lvl); metaDebug("colId: %d, encode:%s, compress:%s,level:%s", colId, l1str, l2str, lvlstr); } - return 0; + return; } int32_t metaGetColCmpr(SMeta *pMeta, tb_uid_t uid, SHashObj **ppColCmprObj) { int rc = 0; @@ -3063,7 +3191,7 @@ int32_t metaGetColCmpr(SMeta *pMeta, tb_uid_t uid, SHashObj **ppColCmprObj) { metaULock(pMeta); *ppColCmprObj = pColCmprObj; - (void)colCompressDebug(pColCmprObj); + colCompressDebug(pColCmprObj); return 0; } diff --git a/source/dnode/vnode/src/meta/metaTtl.c b/source/dnode/vnode/src/meta/metaTtl.c index e3d6e2cf9b..4077e9fa5d 100644 --- a/source/dnode/vnode/src/meta/metaTtl.c +++ b/source/dnode/vnode/src/meta/metaTtl.c @@ -144,7 +144,7 @@ static void ttlMgrCleanup(STtlManger *pTtlMgr) { taosMemoryFree(pTtlMgr->logPrefix); taosHashCleanup(pTtlMgr->pTtlCache); taosHashCleanup(pTtlMgr->pDirtyUids); - (void)tdbTbClose(pTtlMgr->pTtlIdx); + tdbTbClose(pTtlMgr->pTtlIdx); taosMemoryFree(pTtlMgr); } @@ -302,7 +302,10 @@ int32_t ttlMgrInsertTtl(STtlManger *pTtlMgr, const STtlUpdTtlCtx *updCtx) { } if (ttlMgrNeedFlush(pTtlMgr)) { - (void)ttlMgrFlush(pTtlMgr, updCtx->pTxn); + int32_t ret = ttlMgrFlush(pTtlMgr, updCtx->pTxn); + if (ret < 0) { + metaError("%s, ttlMgr insert failed to flush since %s", pTtlMgr->logPrefix, tstrerror(ret)); + } } code = TSDB_CODE_SUCCESS; @@ -326,7 +329,10 @@ int32_t ttlMgrDeleteTtl(STtlManger *pTtlMgr, const STtlDelTtlCtx *delCtx) { } if (ttlMgrNeedFlush(pTtlMgr)) { - (void)ttlMgrFlush(pTtlMgr, delCtx->pTxn); + int32_t ret = ttlMgrFlush(pTtlMgr, delCtx->pTxn); + if (ret < 0) { + metaError("%s, ttlMgr del failed to flush since %s", pTtlMgr->logPrefix, tstrerror(ret)); + } } code = TSDB_CODE_SUCCESS; @@ -350,7 +356,8 @@ int32_t ttlMgrUpdateChangeTime(STtlManger *pTtlMgr, const STtlUpdCtimeCtx *pUpdC .changeTimeMsDirty = pUpdCtimeCtx->changeTimeMs}; STtlDirtyEntry dirtryEntry = {.type = ENTRY_TYPE_UPSERT}; - code = taosHashPut(pTtlMgr->pTtlCache, &pUpdCtimeCtx->uid, sizeof(pUpdCtimeCtx->uid), &cacheEntry, sizeof(cacheEntry)); + code = + taosHashPut(pTtlMgr->pTtlCache, &pUpdCtimeCtx->uid, sizeof(pUpdCtimeCtx->uid), &cacheEntry, sizeof(cacheEntry)); if (TSDB_CODE_SUCCESS != code) { metaError("%s, ttlMgr update ctime failed to update cache since %s", pTtlMgr->logPrefix, tstrerror(code)); goto _out; @@ -359,13 +366,15 @@ int32_t ttlMgrUpdateChangeTime(STtlManger *pTtlMgr, const STtlUpdCtimeCtx *pUpdC code = taosHashPut(pTtlMgr->pDirtyUids, &pUpdCtimeCtx->uid, sizeof(pUpdCtimeCtx->uid), &dirtryEntry, sizeof(dirtryEntry)); if (TSDB_CODE_SUCCESS != code) { - metaError("%s, ttlMgr update ctime failed to update dirty uids since %s", pTtlMgr->logPrefix, - tstrerror(code)); + metaError("%s, ttlMgr update ctime failed to update dirty uids since %s", pTtlMgr->logPrefix, tstrerror(code)); goto _out; } if (ttlMgrNeedFlush(pTtlMgr)) { - (void)ttlMgrFlush(pTtlMgr, pUpdCtimeCtx->pTxn); + int32_t ret = ttlMgrFlush(pTtlMgr, pUpdCtimeCtx->pTxn); + if (ret < 0) { + metaError("%s, ttlMgr update ctime failed to flush since %s", pTtlMgr->logPrefix, tstrerror(ret)); + } } code = TSDB_CODE_SUCCESS; @@ -420,7 +429,7 @@ int32_t ttlMgrFlush(STtlManger *pTtlMgr, TXN *pTxn) { STtlCacheEntry *cacheEntry = taosHashGet(pTtlMgr->pTtlCache, pUid, sizeof(*pUid)); if (cacheEntry == NULL) { metaError("%s, ttlMgr flush failed to get ttl cache, uid: %" PRId64 ", type: %d", pTtlMgr->logPrefix, *pUid, - pEntry->type); + pEntry->type); continue; } diff --git a/source/dnode/vnode/src/sma/smaCommit.c b/source/dnode/vnode/src/sma/smaCommit.c index 75b112f42b..7b2c9457e3 100644 --- a/source/dnode/vnode/src/sma/smaCommit.c +++ b/source/dnode/vnode/src/sma/smaCommit.c @@ -257,7 +257,9 @@ static int32_t tdProcessRSmaAsyncPostCommitImpl(SSma *pSma) { if (RSMA_INFO_IS_DEL(pRSmaInfo)) { int32_t refVal = T_REF_VAL_GET(pRSmaInfo); if (refVal == 0) { - (void)taosHashRemove(RSMA_INFO_HASH(pRSmaStat), pSuid, sizeof(*pSuid)); + if(taosHashRemove(RSMA_INFO_HASH(pRSmaStat), pSuid, sizeof(*pSuid)) < 0) { + smaError("vgId:%d, rsma async post commit, failed to remove rsma info for table:%" PRIi64, SMA_VID(pSma), *pSuid); + } } else { smaDebug( "vgId:%d, rsma async post commit, not free rsma info since ref is %d although already deleted for " diff --git a/source/dnode/vnode/src/sma/smaEnv.c b/source/dnode/vnode/src/sma/smaEnv.c index 721c0130cf..efa248755b 100644 --- a/source/dnode/vnode/src/sma/smaEnv.c +++ b/source/dnode/vnode/src/sma/smaEnv.c @@ -46,7 +46,7 @@ int32_t smaInit() { old = atomic_val_compare_exchange_8(&smaMgmt.inited, 0, 2); if (old != 2) break; if (++nLoops > 1000) { - (void)sched_yield(); + TAOS_UNUSED(sched_yield()); nLoops = 0; } } @@ -97,7 +97,7 @@ void smaCleanUp() { old = atomic_val_compare_exchange_8(&smaMgmt.inited, 1, 2); if (old != 2) break; if (++nLoops > 1000) { - (void)sched_yield(); + TAOS_UNUSED(sched_yield()); nLoops = 0; } } @@ -130,7 +130,7 @@ static int32_t tdNewSmaEnv(SSma *pSma, int8_t smaType, SSmaEnv **ppEnv) { : atomic_store_ptr(&SMA_RSMA_ENV(pSma), *ppEnv); if ((code = tdInitSmaStat(&SMA_ENV_STAT(pEnv), smaType, pSma)) != TSDB_CODE_SUCCESS) { - (void)tdFreeSmaEnv(pEnv); + TAOS_UNUSED(tdFreeSmaEnv(pEnv)); *ppEnv = NULL; (smaType == TSDB_SMA_TYPE_TIME_RANGE) ? atomic_store_ptr(&SMA_TSMA_ENV(pSma), NULL) : atomic_store_ptr(&SMA_RSMA_ENV(pSma), NULL); @@ -183,7 +183,7 @@ static void tRSmaInfoHashFreeNode(void *data) { smaError("failed to hash remove %s:%d", __FUNCTION__, __LINE__); } } - (void)tdFreeRSmaInfo(pRSmaInfo->pSma, pRSmaInfo); + TAOS_UNUSED(tdFreeRSmaInfo(pRSmaInfo->pSma, pRSmaInfo)); } } @@ -289,7 +289,7 @@ static void tdDestroyRSmaStat(void *pRSmaStat) { } // step 3: - (void)tdRsmaStopExecutor(pSma); + TAOS_UNUSED(tdRsmaStopExecutor(pSma)); // step 4: destroy the rsma info and associated fetch tasks taosHashCleanup(RSMA_INFO_HASH(pStat)); @@ -302,7 +302,7 @@ static void tdDestroyRSmaStat(void *pRSmaStat) { } static void *tdFreeSmaState(SSmaStat *pSmaStat, int8_t smaType) { - (void)tdDestroySmaState(pSmaStat, smaType); + TAOS_UNUSED(tdDestroySmaState(pSmaStat, smaType)); if (smaType == TSDB_SMA_TYPE_TIME_RANGE) { taosMemoryFreeClear(pSmaStat); } @@ -382,16 +382,16 @@ int32_t tdCheckAndInitSmaEnv(SSma *pSma, int8_t smaType) { } // init sma env - (void)tdLockSma(pSma); + TAOS_UNUSED(tdLockSma(pSma)); pEnv = (smaType == TSDB_SMA_TYPE_TIME_RANGE) ? atomic_load_ptr(&SMA_TSMA_ENV(pSma)) : atomic_load_ptr(&SMA_RSMA_ENV(pSma)); if (!pEnv) { if ((code = tdInitSmaEnv(pSma, smaType, &pEnv)) < 0) { - (void)tdUnLockSma(pSma); + TAOS_UNUSED(tdUnLockSma(pSma)); TAOS_RETURN(code); } } - (void)tdUnLockSma(pSma); + TAOS_UNUSED(tdUnLockSma(pSma)); TAOS_RETURN(TSDB_CODE_SUCCESS); } @@ -399,7 +399,9 @@ int32_t tdCheckAndInitSmaEnv(SSma *pSma, int8_t smaType) { void *tdRSmaExecutorFunc(void *param) { setThreadName("vnode-rsma"); - (void)tdRSmaProcessExecImpl((SSma *)param, RSMA_EXEC_OVERFLOW); + if(tdRSmaProcessExecImpl((SSma *)param, RSMA_EXEC_OVERFLOW) < 0){ + smaError("vgId:%d, failed to process rsma exec", SMA_VID((SSma *)param)); + } return NULL; } diff --git a/source/dnode/vnode/src/sma/smaOpen.c b/source/dnode/vnode/src/sma/smaOpen.c index b87be63d04..7bc9237965 100644 --- a/source/dnode/vnode/src/sma/smaOpen.c +++ b/source/dnode/vnode/src/sma/smaOpen.c @@ -171,9 +171,9 @@ _exit: TAOS_RETURN(code); } -int32_t smaClose(SSma *pSma) { +void smaClose(SSma *pSma) { if (pSma) { - (void)smaPreClose(pSma); + TAOS_UNUSED(smaPreClose(pSma)); (void)taosThreadMutexDestroy(&pSma->mutex); SMA_TSMA_ENV(pSma) = tdFreeSmaEnv(SMA_TSMA_ENV(pSma)); SMA_RSMA_ENV(pSma) = tdFreeSmaEnv(SMA_RSMA_ENV(pSma)); @@ -182,7 +182,7 @@ int32_t smaClose(SSma *pSma) { if SMA_RSMA_TSDB2 (pSma) tsdbClose(&SMA_RSMA_TSDB2(pSma)); taosMemoryFreeClear(pSma); } - return 0; + return; } /** diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c index 14e79200aa..ee8ee962e9 100644 --- a/source/dnode/vnode/src/sma/smaRollup.c +++ b/source/dnode/vnode/src/sma/smaRollup.c @@ -89,7 +89,10 @@ void *tdFreeRSmaInfo(SSma *pSma, SRSmaInfo *pInfo) { if (pItem->tmrId) { smaDebug("vgId:%d, stop fetch timer %p for table %" PRIi64 " level %d", SMA_VID(pSma), pItem->tmrId, pInfo->suid, i + 1); - (void)taosTmrStopA(&pItem->tmrId); + if (!taosTmrStopA(&pItem->tmrId)) { + smaError("vgId:%d, failed to stop fetch timer for table %" PRIi64 " level %d", SMA_VID(pSma), pInfo->suid, + i + 1); + } } if (pItem->pStreamState) { @@ -246,7 +249,10 @@ static void tdRSmaTaskInit(SStreamMeta *pMeta, SRSmaInfoItem *pItem, SStreamTask } static void tdRSmaTaskRemove(SStreamMeta *pMeta, int64_t streamId, int32_t taskId) { - (void)streamMetaUnregisterTask(pMeta, streamId, taskId); + int32_t code = streamMetaUnregisterTask(pMeta, streamId, taskId); + if (code != 0) { + smaError("vgId:%d, rsma task:%" PRIi64 ",%d drop failed since %s", pMeta->vgId, streamId, taskId, tstrerror(code)); + } streamMetaWLock(pMeta); int32_t numOfTasks = streamMetaGetNumOfTasks(pMeta); if (streamMetaCommit(pMeta) < 0) { @@ -348,7 +354,11 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); } - (void)taosTmrReset(tdRSmaFetchTrigger, RSMA_FETCH_INTERVAL, pItem, smaMgmt.tmrHandle, &pItem->tmrId); + bool ret = taosTmrReset(tdRSmaFetchTrigger, RSMA_FETCH_INTERVAL, pItem, smaMgmt.tmrHandle, &pItem->tmrId); + if (!ret) { + smaError("vgId:%d, failed to reset fetch timer for table %" PRIi64 " level %d", TD_VID(pVnode), pRSmaInfo->suid, + idx + 1); + } smaInfo("vgId:%d, open rsma task:%p table:%" PRIi64 " level:%" PRIi8 ", checkpointId:%" PRIi64 ", submitReqVer:%" PRIi64 ", fetchResultVer:%" PRIi64 ", maxdelay:%" PRIi64 " watermark:%" PRIi64 @@ -394,7 +404,7 @@ int32_t tdRSmaProcessCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, con } STSchema *pTSchema; - code = metaGetTbTSchemaNotNull(SMA_META(pSma), suid, -1, 1, &pTSchema); + code = metaGetTbTSchemaNotNull(SMA_META(pSma), suid, -1, 1, &pTSchema); TAOS_CHECK_EXIT(code); pRSmaInfo->pSma = pSma; pRSmaInfo->pTSchema = pTSchema; @@ -412,7 +422,7 @@ int32_t tdRSmaProcessCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, con _exit: if (code != 0) { - (void)tdFreeRSmaInfo(pSma, pRSmaInfo); + TAOS_UNUSED(tdFreeRSmaInfo(pSma, pRSmaInfo)); } else { smaDebug("vgId:%d, register rsma info succeed for table %" PRIi64, SMA_VID(pSma), suid); } @@ -810,7 +820,10 @@ static int32_t tdExecuteRSmaImplAsync(SSma *pSma, int64_t version, const void *p int64_t nItems = atomic_fetch_add_64(&pRSmaStat->nBufItems, 1); if (atomic_load_8(&pInfo->assigned) == 0) { - (void)tsem_post(&(pRSmaStat->notEmpty)); + if (tsem_post(&(pRSmaStat->notEmpty)) != 0) { + smaError("vgId:%d, failed to post notEmpty semaphore for rsma %" PRIi64 " since %s", SMA_VID(pSma), suid, + tstrerror(terrno)); + } } // smoothing consume @@ -1264,7 +1277,7 @@ _checkpoint: if (pItem && pItem->pStreamTask) { SStreamTask *pTask = pItem->pStreamTask; // atomic_store_32(&pTask->pMeta->chkptNotReadyTasks, 1); - (void)streamTaskSetActiveCheckpointInfo(pTask, checkpointId); + TAOS_UNUSED(streamTaskSetActiveCheckpointInfo(pTask, checkpointId)); pTask->chkInfo.checkpointId = checkpointId; // 1pTask->checkpointingId; pTask->chkInfo.checkpointVer = pItem->submitReqVer; @@ -1339,7 +1352,7 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) { if (!(pStat = (SRSmaStat *)tdAcquireSmaRef(smaMgmt.rsetId, pRSmaRef->refId))) { smaWarn("rsma fetch task not start since rsma stat already destroyed, rsetId:%d refId:%" PRIi64 ")", smaMgmt.rsetId, pRSmaRef->refId); // pRSmaRef freed in taosHashRemove - (void)taosHashRemove(smaMgmt.refHash, ¶m, POINTER_BYTES); + TAOS_UNUSED(taosHashRemove(smaMgmt.refHash, ¶m, POINTER_BYTES)); return; } @@ -1348,8 +1361,8 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) { if ((code = tdAcquireRSmaInfoBySuid(pSma, pRSmaRef->suid, &pRSmaInfo)) != 0) { smaDebug("rsma fetch task not start since rsma info not exist, rsetId:%d refId:%" PRIi64 ")", smaMgmt.rsetId, pRSmaRef->refId); // pRSmaRef freed in taosHashRemove - (void)tdReleaseSmaRef(smaMgmt.rsetId, pRSmaRef->refId); - (void)taosHashRemove(smaMgmt.refHash, ¶m, POINTER_BYTES); + TAOS_UNUSED(tdReleaseSmaRef(smaMgmt.rsetId, pRSmaRef->refId)); + TAOS_UNUSED(taosHashRemove(smaMgmt.refHash, ¶m, POINTER_BYTES)); return; } @@ -1357,8 +1370,8 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) { smaDebug("rsma fetch task not start since rsma info already deleted, rsetId:%d refId:%" PRIi64 ")", smaMgmt.rsetId, pRSmaRef->refId); // pRSmaRef freed in taosHashRemove tdReleaseRSmaInfo(pSma, pRSmaInfo); - (void)tdReleaseSmaRef(smaMgmt.rsetId, pRSmaRef->refId); - (void)taosHashRemove(smaMgmt.refHash, ¶m, POINTER_BYTES); + TAOS_UNUSED(tdReleaseSmaRef(smaMgmt.rsetId, pRSmaRef->refId)); + TAOS_UNUSED(taosHashRemove(smaMgmt.refHash, ¶m, POINTER_BYTES)); return; } @@ -1373,10 +1386,15 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) { ", rsetId:%d refId:%" PRIi64, SMA_VID(pSma), pItem->level, rsmaTriggerStat, smaMgmt.rsetId, pRSmaRef->refId); if (rsmaTriggerStat == TASK_TRIGGER_STAT_PAUSED) { - (void)taosTmrReset(tdRSmaFetchTrigger, RSMA_FETCH_INTERVAL, pItem, smaMgmt.tmrHandle, &pItem->tmrId); + bool ret = taosTmrReset(tdRSmaFetchTrigger, RSMA_FETCH_INTERVAL, pItem, smaMgmt.tmrHandle, &pItem->tmrId); + if (!ret) { + smaWarn("vgId:%d, rsma fetch task not reset for level %" PRIi8 + " since tmr reset failed, rsetId:%d refId:%" PRIi64, + SMA_VID(pSma), pItem->level, smaMgmt.rsetId, pRSmaRef->refId); + } } tdReleaseRSmaInfo(pSma, pRSmaInfo); - (void)tdReleaseSmaRef(smaMgmt.rsetId, pRSmaRef->refId); + TAOS_UNUSED(tdReleaseSmaRef(smaMgmt.rsetId, pRSmaRef->refId)); return; } default: @@ -1393,7 +1411,10 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) { atomic_store_8(&pItem->fetchLevel, 1); if (atomic_load_8(&pRSmaInfo->assigned) == 0) { - (void)tsem_post(&(pStat->notEmpty)); + if (tsem_post(&(pStat->notEmpty)) != 0) { + smaError("vgId:%d, rsma fetch task not start for level:%" PRIi8 " suid:%" PRIi64 " since sem post failed", + SMA_VID(pSma), pItem->level, pRSmaInfo->suid); + } } } break; case TASK_TRIGGER_STAT_INACTIVE: { @@ -1414,7 +1435,7 @@ static void tdRSmaFetchTrigger(void *param, void *tmrId) { _end: taosTmrReset(tdRSmaFetchTrigger, pItem->maxDelay, pItem, smaMgmt.tmrHandle, &pItem->tmrId); tdReleaseRSmaInfo(pSma, pRSmaInfo); - (void)tdReleaseSmaRef(smaMgmt.rsetId, pRSmaRef->refId); + TAOS_UNUSED(tdReleaseSmaRef(smaMgmt.rsetId, pRSmaRef->refId)); } static void tdFreeRSmaSubmitItems(SArray *pItems, int32_t type) { @@ -1507,7 +1528,7 @@ static int32_t tdRSmaBatchExec(SSma *pSma, SRSmaInfo *pInfo, STaosQall *qall, SA // the submitReq/deleteReq msg may exsit alternately in the msg queue, consume them sequentially in batch mode while (1) { - (void)taosGetQitem(qall, (void **)&msg); + TAOS_UNUSED(taosGetQitem(qall, (void **)&msg)); if (msg) { int8_t inputType = RSMA_EXEC_MSG_TYPE(msg); if (inputType == STREAM_INPUT__DATA_SUBMIT) { @@ -1573,7 +1594,7 @@ _exit: tdFreeRSmaSubmitItems(pSubmitArr, nSubmit ? STREAM_INPUT__MERGED_SUBMIT : STREAM_INPUT__REF_DATA_BLOCK); while (1) { void *msg = NULL; - (void)taosGetQitem(qall, (void **)&msg); + TAOS_UNUSED(taosGetQitem(qall, (void **)&msg)); if (msg) { taosFreeQitem(msg); } else { @@ -1627,8 +1648,8 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) { batchMax = 100 / batchMax; batchMax = TMAX(batchMax, 4); } - while (occupied || (++batchCnt < batchMax)) { // greedy mode - (void)taosReadAllQitems(pInfo->queue, pInfo->qall); // queue has mutex lock + while (occupied || (++batchCnt < batchMax)) { // greedy mode + TAOS_UNUSED(taosReadAllQitems(pInfo->queue, pInfo->qall)); // queue has mutex lock int32_t qallItemSize = taosQallItemSize(pInfo->qall); if (qallItemSize > 0) { if ((code = tdRSmaBatchExec(pSma, pInfo, pInfo->qall, pSubmitArr, type)) != 0) { @@ -1662,7 +1683,7 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) { } if (qallItemSize > 0) { - (void)atomic_fetch_sub_64(&pRSmaStat->nBufItems, qallItemSize); + TAOS_UNUSED(atomic_fetch_sub_64(&pRSmaStat->nBufItems, qallItemSize)); continue; } if (RSMA_NEED_FETCH(pInfo)) { @@ -1672,7 +1693,7 @@ int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type) { break; } } - (void)atomic_val_compare_exchange_8(&pInfo->assigned, 1, 0); + TAOS_UNUSED(atomic_val_compare_exchange_8(&pInfo->assigned, 1, 0)); } } } else { diff --git a/source/dnode/vnode/src/sma/smaSnapshot.c b/source/dnode/vnode/src/sma/smaSnapshot.c index 881c8ac96d..5836b69b5f 100644 --- a/source/dnode/vnode/src/sma/smaSnapshot.c +++ b/source/dnode/vnode/src/sma/smaSnapshot.c @@ -93,27 +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)); - (void)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]) { - (void)tsdbSnapReaderClose(&pReader->pDataReader[i]); + tsdbSnapReaderClose(&pReader->pDataReader[i]); } } smaInfo("vgId:%d, vnode snapshot rsma reader closed", SMA_VID(pReader->pSma)); taosMemoryFreeClear(*ppReader); - TAOS_RETURN(code); + return; } // SRSmaSnapWriter ======================================== diff --git a/source/dnode/vnode/src/sma/smaTimeRange.c b/source/dnode/vnode/src/sma/smaTimeRange.c index 58dafa4f8b..86246aace1 100644 --- a/source/dnode/vnode/src/sma/smaTimeRange.c +++ b/source/dnode/vnode/src/sma/smaTimeRange.c @@ -123,7 +123,7 @@ static int32_t tdProcessTSmaCreateImpl(SSma *pSma, int64_t ver, const char *pMsg TAOS_CHECK_EXIT(metaCreateTSma(SMA_META(pSma), ver, pCfg)); // create stable to save tsma result in dstVgId - (void)tNameFromString(&stbFullName, pCfg->dstTbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + TAOS_CHECK_EXIT(tNameFromString(&stbFullName, pCfg->dstTbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE)); pReq.name = (char *)tNameGetTableName(&stbFullName); pReq.suid = pCfg->dstTbUid; pReq.schemaRow = pCfg->schemaRow; @@ -283,7 +283,10 @@ static int32_t tsmaProcessDelReq(SSma *pSma, int64_t indexUid, SBatchDeleteReq * SEncoder encoder; tEncoderInit(&encoder, POINTER_SHIFT(pBuf, sizeof(SMsgHead)), len); - (void)tEncodeSBatchDeleteReq(&encoder, pDelReq); + if ((code = tEncodeSBatchDeleteReq(&encoder, pDelReq)) < 0) { + tEncoderClear(&encoder); + TSDB_CHECK_CODE(code, lino, _exit); + } tEncoderClear(&encoder); ((SMsgHead *)pBuf)->vgId = TD_VID(pSma->pVnode); diff --git a/source/dnode/vnode/src/tq/tqMeta.c b/source/dnode/vnode/src/tq/tqMeta.c index b7c842d05c..89350e761f 100644 --- a/source/dnode/vnode/src/tq/tqMeta.c +++ b/source/dnode/vnode/src/tq/tqMeta.c @@ -127,7 +127,6 @@ int32_t tqMetaSaveOffset(STQ* pTq, STqOffset* pOffset) { goto END; } - buf = taosMemoryCalloc(1, vlen); if (buf == NULL) { code = terrno; @@ -152,7 +151,8 @@ int32_t tqMetaSaveInfo(STQ* pTq, TTB* ttb, const void* key, int32_t kLen, const int32_t code = TDB_CODE_SUCCESS; TXN* txn = NULL; - TQ_ERR_GO_TO_END(tdbBegin(pTq->pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED)); + TQ_ERR_GO_TO_END( + tdbBegin(pTq->pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED)); TQ_ERR_GO_TO_END(tdbTbUpsert(ttb, key, kLen, value, vLen, txn)); TQ_ERR_GO_TO_END(tdbCommit(pTq->pMetaDB, txn)); TQ_ERR_GO_TO_END(tdbPostCommit(pTq->pMetaDB, txn)); @@ -168,7 +168,8 @@ int32_t tqMetaDeleteInfo(STQ* pTq, TTB* ttb, const void* key, int32_t kLen) { int32_t code = TDB_CODE_SUCCESS; TXN* txn = NULL; - TQ_ERR_GO_TO_END(tdbBegin(pTq->pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED)); + TQ_ERR_GO_TO_END( + tdbBegin(pTq->pMetaDB, &txn, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED)); TQ_ERR_GO_TO_END(tdbTbDelete(ttb, key, kLen, txn)); TQ_ERR_GO_TO_END(tdbCommit(pTq->pMetaDB, txn)); TQ_ERR_GO_TO_END(tdbPostCommit(pTq->pMetaDB, txn)); @@ -180,7 +181,7 @@ END: return code; } -int32_t tqMetaGetOffset(STQ* pTq, const char* subkey, STqOffset** pOffset){ +int32_t tqMetaGetOffset(STQ* pTq, const char* subkey, STqOffset** pOffset) { void* data = taosHashGet(pTq->pOffset, subkey, strlen(subkey)); if (data == NULL) { int vLen = 0; @@ -203,7 +204,7 @@ int32_t tqMetaGetOffset(STQ* pTq, const char* subkey, STqOffset** pOffset){ tdbFree(data); *pOffset = taosHashGet(pTq->pOffset, subkey, strlen(subkey)); - if(*pOffset == NULL){ + if (*pOffset == NULL) { return TSDB_CODE_OUT_OF_MEMORY; } } else { @@ -266,8 +267,8 @@ static int tqMetaInitHandle(STQ* pTq, STqHandle* handle) { initStorageAPI(&reader.api); if (handle->execHandle.subType == TOPIC_SUB_TYPE__COLUMN) { - handle->execHandle.task = - qCreateQueueExecTaskInfo(handle->execHandle.execCol.qmsg, &reader, vgId, &handle->execHandle.numOfCols, handle->consumerId); + handle->execHandle.task = qCreateQueueExecTaskInfo(handle->execHandle.execCol.qmsg, &reader, vgId, + &handle->execHandle.numOfCols, handle->consumerId); TQ_NULL_GO_TO_END(handle->execHandle.task); void* scanner = NULL; qExtractStreamScanner(handle->execHandle.task, &scanner); @@ -280,20 +281,21 @@ static int tqMetaInitHandle(STQ* pTq, STqHandle* handle) { handle->execHandle.pTqReader = tqReaderOpen(pVnode); TQ_NULL_GO_TO_END(handle->execHandle.pTqReader); TQ_ERR_GO_TO_END(buildSnapContext(reader.vnode, reader.version, 0, handle->execHandle.subType, handle->fetchMeta, - (SSnapContext**)(&reader.sContext))); + (SSnapContext**)(&reader.sContext))); handle->execHandle.task = qCreateQueueExecTaskInfo(NULL, &reader, vgId, NULL, handle->consumerId); TQ_NULL_GO_TO_END(handle->execHandle.task); } else if (handle->execHandle.subType == TOPIC_SUB_TYPE__TABLE) { handle->pWalReader = walOpenReader(pVnode->pWal, NULL, 0); TQ_NULL_GO_TO_END(handle->pWalReader); - if(handle->execHandle.execTb.qmsg != NULL && strcmp(handle->execHandle.execTb.qmsg, "") != 0) { + if (handle->execHandle.execTb.qmsg != NULL && strcmp(handle->execHandle.execTb.qmsg, "") != 0) { if (nodesStringToNode(handle->execHandle.execTb.qmsg, &handle->execHandle.execTb.node) != 0) { tqError("nodesStringToNode error in sub stable, since %s", terrstr()); return TSDB_CODE_SCH_INTERNAL_ERROR; } } - TQ_ERR_GO_TO_END(buildSnapContext(reader.vnode, reader.version, handle->execHandle.execTb.suid, handle->execHandle.subType, - handle->fetchMeta, (SSnapContext**)(&reader.sContext))); + TQ_ERR_GO_TO_END(buildSnapContext(reader.vnode, reader.version, handle->execHandle.execTb.suid, + handle->execHandle.subType, handle->fetchMeta, + (SSnapContext**)(&reader.sContext))); handle->execHandle.task = qCreateQueueExecTaskInfo(NULL, &reader, vgId, NULL, handle->consumerId); TQ_NULL_GO_TO_END(handle->execHandle.task); SArray* tbUidList = NULL; @@ -341,7 +343,7 @@ int32_t tqMetaCreateHandle(STQ* pTq, SMqRebVgReq* req, STqHandle* handle) { handle->execHandle.subType = req->subType; handle->fetchMeta = req->withMeta; if (req->subType == TOPIC_SUB_TYPE__COLUMN) { - void *tmp = taosStrdup(req->qmsg); + void* tmp = taosStrdup(req->qmsg); if (tmp == NULL) { return terrno; } @@ -349,12 +351,12 @@ int32_t tqMetaCreateHandle(STQ* pTq, SMqRebVgReq* req, STqHandle* handle) { } else if (req->subType == TOPIC_SUB_TYPE__DB) { handle->execHandle.execDb.pFilterOutTbUid = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); - if(handle->execHandle.execDb.pFilterOutTbUid == NULL){ + if (handle->execHandle.execDb.pFilterOutTbUid == NULL) { return terrno; } - }else if(req->subType == TOPIC_SUB_TYPE__TABLE){ + } else if (req->subType == TOPIC_SUB_TYPE__TABLE) { handle->execHandle.execTb.suid = req->suid; - void *tmp = taosStrdup(req->qmsg); + void* tmp = taosStrdup(req->qmsg); if (tmp == NULL) { return terrno; } @@ -364,7 +366,7 @@ int32_t tqMetaCreateHandle(STQ* pTq, SMqRebVgReq* req, STqHandle* handle) { handle->snapshotVer = walGetCommittedVer(pTq->pVnode->pWal); int32_t code = tqMetaInitHandle(pTq, handle); - if (code != 0){ + if (code != 0) { return code; } tqInfo("tqMetaCreateHandle %s consumer 0x%" PRIx64 " vgId:%d, snapshotVer:%" PRId64, handle->subKey, @@ -437,10 +439,10 @@ END: return code; } -static int32_t replaceTqPath(char** path){ - char* tpath = NULL; +static int32_t replaceTqPath(char** path) { + char* tpath = NULL; int32_t code = tqBuildFName(&tpath, *path, TQ_SUBSCRIBE_NAME); - if (code != 0){ + if (code != 0) { return code; } taosMemoryFree(*path); @@ -475,7 +477,7 @@ END: } int32_t tqMetaOpen(STQ* pTq) { - char* maindb = NULL; + char* maindb = NULL; char* offsetNew = NULL; int32_t code = TDB_CODE_SUCCESS; TQ_ERR_GO_TO_END(tqBuildFName(&maindb, pTq->path, TDB_MAINDB_NAME)); @@ -488,7 +490,7 @@ int32_t tqMetaOpen(STQ* pTq) { } TQ_ERR_GO_TO_END(tqBuildFName(&offsetNew, pTq->path, TQ_OFFSET_NAME)); - if(taosCheckExistFile(offsetNew)){ + if (taosCheckExistFile(offsetNew)) { TQ_ERR_GO_TO_END(tqOffsetRestoreFromFile(pTq, offsetNew)); TQ_ERR_GO_TO_END(taosRemoveFile(offsetNew)); } @@ -522,7 +524,7 @@ int32_t tqMetaTransform(STQ* pTq) { TQ_ERR_GO_TO_END(tqBuildFName(&offsetNew, pTq->path, TQ_OFFSET_NAME)); - if(taosCheckExistFile(offset)) { + if (taosCheckExistFile(offset)) { if (taosCopyFile(offset, offsetNew) < 0) { tqError("copy offset file error"); } else { @@ -534,44 +536,22 @@ END: taosMemoryFree(offset); taosMemoryFree(offsetNew); - int32_t ret = tdbTbClose(pExecStore); - if (ret != 0) { - tqError("failed to close tb, ret:%d", ret); - } - ret = tdbTbClose(pCheckStore); - if (ret != 0) { - tqError("failed to close tb, ret:%d", ret); - } - ret = tdbClose(pMetaDB); - if (ret != 0) { - tqError("failed to close tdb, ret:%d", ret); - } - + tdbTbClose(pExecStore); + tdbTbClose(pCheckStore); + tdbClose(pMetaDB); return code; } void tqMetaClose(STQ* pTq) { int32_t ret = 0; if (pTq->pExecStore) { - ret = tdbTbClose(pTq->pExecStore); - if (ret != 0) { - tqError("failed to close tb, ret:%d", ret); - } + tdbTbClose(pTq->pExecStore); } if (pTq->pCheckStore) { - ret = tdbTbClose(pTq->pCheckStore); - if (ret != 0) { - tqError("failed to close tb, ret:%d", ret); - } + tdbTbClose(pTq->pCheckStore); } if (pTq->pOffsetStore) { - ret = tdbTbClose(pTq->pOffsetStore); - if (ret != 0) { - tqError("failed to close tb, ret:%d", ret); - } - } - ret = tdbClose(pTq->pMetaDB); - if (ret != 0) { - tqError("failed to close tdb, ret:%d", ret); + tdbTbClose(pTq->pOffsetStore); } + tdbClose(pTq->pMetaDB); } diff --git a/source/dnode/vnode/src/tq/tqSnapshot.c b/source/dnode/vnode/src/tq/tqSnapshot.c index 8861f1f49f..cfa97def74 100644 --- a/source/dnode/vnode/src/tq/tqSnapshot.c +++ b/source/dnode/vnode/src/tq/tqSnapshot.c @@ -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; } diff --git a/source/dnode/vnode/src/tq/tqStreamTask.c b/source/dnode/vnode/src/tq/tqStreamTask.c index 354e9b3693..b5ad3f1db1 100644 --- a/source/dnode/vnode/src/tq/tqStreamTask.c +++ b/source/dnode/vnode/src/tq/tqStreamTask.c @@ -114,7 +114,7 @@ int32_t tqScanWalInFuture(STQ* pTq, int32_t numOfTasks, int32_t idleDuration) { } else { bool ret = taosTmrReset(doStartScanWal, idleDuration, pParam, pTimer, &pMeta->scanInfo.scanTimer); if (!ret) { - tqError("vgId:%d failed to start scan wal in:%dms", vgId, idleDuration); +// tqError("vgId:%d failed to start scan wal in:%dms", vgId, idleDuration); } } diff --git a/source/dnode/vnode/src/tq/tqStreamTaskSnap.c b/source/dnode/vnode/src/tq/tqStreamTaskSnap.c index 2605d70c37..fd46c618a1 100644 --- a/source/dnode/vnode/src/tq/tqStreamTaskSnap.c +++ b/source/dnode/vnode/src/tq/tqStreamTaskSnap.c @@ -137,7 +137,7 @@ NextTbl: memcpy(pVal, tVal, tLen); vLen = tLen; } - (void)tdbTbcMoveToNext(pReader->pCur); + TAOS_UNUSED(tdbTbcMoveToNext(pReader->pCur)); break; } if (except == 1) { @@ -147,7 +147,7 @@ NextTbl: pReader->pos += 1; pPair = taosArrayGet(pReader->tdbTbList, pReader->pos); code = tdbTbcOpen(pPair->tbl, &pReader->pCur, NULL); - (void)tdbTbcMoveToFirst(pReader->pCur); + TAOS_UNUSED(tdbTbcMoveToFirst(pReader->pCur)); goto NextTbl; } @@ -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); + TAOS_UNUSED(tdbAbort(pTq->pStreamMeta->db, pTq->pStreamMeta->txn)); } else { code = tdbCommit(pTq->pStreamMeta->db, pTq->pStreamMeta->txn); if (code) goto _err; diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index 3983b6eded..2c70fc1816 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -577,7 +577,10 @@ static void tsdbCacheDeleter(const void *key, size_t klen, void *value, void *ud SLastCol *pLastCol = (SLastCol *)value; if (pLastCol->dirty) { - (void)tsdbCacheFlushDirty(key, klen, pLastCol, ud); + if (tsdbCacheFlushDirty(key, klen, pLastCol, ud) != 0) { + STsdb *pTsdb = (STsdb *)ud; + tsdbError("tsdb/cache: vgId:%d, flush cache %s failed at line %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__); + } } for (uint8_t i = 0; i < pLastCol->rowKey.numOfPKs; ++i) { @@ -719,14 +722,22 @@ static int32_t tsdbCacheDropTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid, rocksdb_writebatch_t *wb = pTsdb->rCache.writebatch; { SLastCol *pLastCol = NULL; - (void)tsdbCacheDeserialize(values_list[0], values_list_sizes[0], &pLastCol); + code = tsdbCacheDeserialize(values_list[0], values_list_sizes[0], &pLastCol); + if (code != TSDB_CODE_SUCCESS) { + tsdbWarn("vgId:%d, %s deserialize failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + } if (NULL != pLastCol) { rocksdb_writebatch_delete(wb, keys_list[0], klen); } taosMemoryFreeClear(pLastCol); pLastCol = NULL; - (void)tsdbCacheDeserialize(values_list[1], values_list_sizes[1], &pLastCol); + code = tsdbCacheDeserialize(values_list[1], values_list_sizes[1], &pLastCol); + if (code != TSDB_CODE_SUCCESS) { + tsdbWarn("vgId:%d, %s deserialize failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + } if (NULL != pLastCol) { rocksdb_writebatch_delete(wb, keys_list[1], klen); } @@ -738,7 +749,9 @@ static int32_t tsdbCacheDropTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid, for (int i = 0; i < 2; i++) { LRUHandle *h = taosLRUCacheLookup(pTsdb->lruCache, keys_list[i], klen); if (h) { - (void)taosLRUCacheRelease(pTsdb->lruCache, h, true); + if (taosLRUCacheRelease(pTsdb->lruCache, h, true)) { + tsdbInfo("vgId:%d, %s release lru cache failed at line %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__); + } taosLRUCacheErase(pTsdb->lruCache, keys_list[i], klen); } } @@ -765,8 +778,20 @@ int32_t tsdbCacheNewTable(STsdb *pTsdb, tb_uid_t uid, tb_uid_t suid, SSchemaWrap int16_t cid = pSchemaRow->pSchema[i].colId; int8_t col_type = pSchemaRow->pSchema[i].type; - (void)tsdbCacheNewTableColumn(pTsdb, uid, cid, col_type, LFLAG_LAST_ROW); - (void)tsdbCacheNewTableColumn(pTsdb, uid, cid, col_type, LFLAG_LAST); + code = tsdbCacheNewTableColumn(pTsdb, uid, cid, col_type, LFLAG_LAST_ROW); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s new table column failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + (void)taosThreadMutexUnlock(&pTsdb->lruMutex); + TAOS_RETURN(code); + } + code = tsdbCacheNewTableColumn(pTsdb, uid, cid, col_type, LFLAG_LAST); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s new table column failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + (void)taosThreadMutexUnlock(&pTsdb->lruMutex); + TAOS_RETURN(code); + } } } else { STSchema *pTSchema = NULL; @@ -781,8 +806,20 @@ int32_t tsdbCacheNewTable(STsdb *pTsdb, tb_uid_t uid, tb_uid_t suid, SSchemaWrap int16_t cid = pTSchema->columns[i].colId; int8_t col_type = pTSchema->columns[i].type; - (void)tsdbCacheNewTableColumn(pTsdb, uid, cid, col_type, LFLAG_LAST_ROW); - (void)tsdbCacheNewTableColumn(pTsdb, uid, cid, col_type, LFLAG_LAST); + code = tsdbCacheNewTableColumn(pTsdb, uid, cid, col_type, LFLAG_LAST_ROW); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s new table column failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + (void)taosThreadMutexUnlock(&pTsdb->lruMutex); + TAOS_RETURN(code); + } + code = tsdbCacheNewTableColumn(pTsdb, uid, cid, col_type, LFLAG_LAST); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s new table column failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + (void)taosThreadMutexUnlock(&pTsdb->lruMutex); + TAOS_RETURN(code); + } } taosMemoryFree(pTSchema); @@ -798,7 +835,13 @@ int32_t tsdbCacheDropTable(STsdb *pTsdb, tb_uid_t uid, tb_uid_t suid, SSchemaWra (void)taosThreadMutexLock(&pTsdb->lruMutex); - (void)tsdbCacheCommitNoLock(pTsdb); + code = tsdbCacheCommitNoLock(pTsdb); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s commit with no lock failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + (void)taosThreadMutexUnlock(&pTsdb->lruMutex); + TAOS_RETURN(code); + } if (pSchemaRow != NULL) { bool hasPrimayKey = false; @@ -810,7 +853,13 @@ int32_t tsdbCacheDropTable(STsdb *pTsdb, tb_uid_t uid, tb_uid_t suid, SSchemaWra int16_t cid = pSchemaRow->pSchema[i].colId; int8_t col_type = pSchemaRow->pSchema[i].type; - (void)tsdbCacheDropTableColumn(pTsdb, uid, cid, hasPrimayKey); + code = tsdbCacheDropTableColumn(pTsdb, uid, cid, hasPrimayKey); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s drop table column failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + (void)taosThreadMutexUnlock(&pTsdb->lruMutex); + TAOS_RETURN(code); + } } } else { STSchema *pTSchema = NULL; @@ -830,7 +879,13 @@ int32_t tsdbCacheDropTable(STsdb *pTsdb, tb_uid_t uid, tb_uid_t suid, SSchemaWra int16_t cid = pTSchema->columns[i].colId; int8_t col_type = pTSchema->columns[i].type; - (void)tsdbCacheDropTableColumn(pTsdb, uid, cid, hasPrimayKey); + code = tsdbCacheDropTableColumn(pTsdb, uid, cid, hasPrimayKey); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s drop table column failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + (void)taosThreadMutexUnlock(&pTsdb->lruMutex); + TAOS_RETURN(code); + } } taosMemoryFree(pTSchema); @@ -848,7 +903,13 @@ int32_t tsdbCacheDropSubTables(STsdb *pTsdb, SArray *uids, tb_uid_t suid) { (void)taosThreadMutexLock(&pTsdb->lruMutex); - (void)tsdbCacheCommitNoLock(pTsdb); + code = tsdbCacheCommitNoLock(pTsdb); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s commit with no lock failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + (void)taosThreadMutexUnlock(&pTsdb->lruMutex); + TAOS_RETURN(code); + } STSchema *pTSchema = NULL; code = metaGetTbTSchemaEx(pTsdb->pVnode->pMeta, suid, suid, -1, &pTSchema); @@ -871,7 +932,14 @@ int32_t tsdbCacheDropSubTables(STsdb *pTsdb, SArray *uids, tb_uid_t suid) { int16_t cid = pTSchema->columns[i].colId; int8_t col_type = pTSchema->columns[i].type; - (void)tsdbCacheDropTableColumn(pTsdb, uid, cid, hasPrimayKey); + code = tsdbCacheDropTableColumn(pTsdb, uid, cid, hasPrimayKey); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s drop table column failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + (void)taosThreadMutexUnlock(&pTsdb->lruMutex); + taosMemoryFree(pTSchema); + TAOS_RETURN(code); + } } } @@ -889,12 +957,22 @@ int32_t tsdbCacheNewNTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid, int8_t (void)taosThreadMutexLock(&pTsdb->lruMutex); - (void)tsdbCacheNewTableColumn(pTsdb, uid, cid, col_type, 0); - (void)tsdbCacheNewTableColumn(pTsdb, uid, cid, col_type, 1); - + code = tsdbCacheNewTableColumn(pTsdb, uid, cid, col_type, 0); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s new table column failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + (void)taosThreadMutexUnlock(&pTsdb->lruMutex); + TAOS_RETURN(code); + } + code = tsdbCacheNewTableColumn(pTsdb, uid, cid, col_type, 1); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s new table column failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + (void)taosThreadMutexUnlock(&pTsdb->lruMutex); + TAOS_RETURN(code); + } // rocksMayWrite(pTsdb, true, false, false); (void)taosThreadMutexUnlock(&pTsdb->lruMutex); - //(void)tsdbCacheCommit(pTsdb); TAOS_RETURN(code); } @@ -904,9 +982,21 @@ int32_t tsdbCacheDropNTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid, bool h (void)taosThreadMutexLock(&pTsdb->lruMutex); - (void)tsdbCacheCommitNoLock(pTsdb); + code = tsdbCacheCommitNoLock(pTsdb); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s commit with no lock failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + (void)taosThreadMutexUnlock(&pTsdb->lruMutex); + TAOS_RETURN(code); + } - (void)tsdbCacheDropTableColumn(pTsdb, uid, cid, hasPrimayKey); + code = tsdbCacheDropTableColumn(pTsdb, uid, cid, hasPrimayKey); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s drop table column failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + (void)taosThreadMutexUnlock(&pTsdb->lruMutex); + TAOS_RETURN(code); + } rocksMayWrite(pTsdb, false); @@ -923,14 +1013,24 @@ int32_t tsdbCacheNewSTableColumn(STsdb *pTsdb, SArray *uids, int16_t cid, int8_t for (int i = 0; i < TARRAY_SIZE(uids); ++i) { tb_uid_t uid = ((tb_uid_t *)TARRAY_DATA(uids))[i]; - (void)tsdbCacheNewTableColumn(pTsdb, uid, cid, col_type, 0); - (void)tsdbCacheNewTableColumn(pTsdb, uid, cid, col_type, 1); + code = tsdbCacheNewTableColumn(pTsdb, uid, cid, col_type, 0); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s new table column failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + (void)taosThreadMutexUnlock(&pTsdb->lruMutex); + TAOS_RETURN(code); + } + code = tsdbCacheNewTableColumn(pTsdb, uid, cid, col_type, 1); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s new table column failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + (void)taosThreadMutexUnlock(&pTsdb->lruMutex); + TAOS_RETURN(code); + } } // rocksMayWrite(pTsdb, true, false, false); (void)taosThreadMutexUnlock(&pTsdb->lruMutex); - //(void)tsdbCacheCommit(pTsdb); - TAOS_RETURN(code); } @@ -939,12 +1039,24 @@ int32_t tsdbCacheDropSTableColumn(STsdb *pTsdb, SArray *uids, int16_t cid, bool (void)taosThreadMutexLock(&pTsdb->lruMutex); - (void)tsdbCacheCommitNoLock(pTsdb); + code = tsdbCacheCommitNoLock(pTsdb); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s commit with no lock failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + (void)taosThreadMutexUnlock(&pTsdb->lruMutex); + TAOS_RETURN(code); + } for (int i = 0; i < TARRAY_SIZE(uids); ++i) { int64_t uid = ((tb_uid_t *)TARRAY_DATA(uids))[i]; - (void)tsdbCacheDropTableColumn(pTsdb, uid, cid, hasPrimayKey); + code = tsdbCacheDropTableColumn(pTsdb, uid, cid, hasPrimayKey); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s drop table column failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + (void)taosThreadMutexUnlock(&pTsdb->lruMutex); + TAOS_RETURN(code); + } } rocksMayWrite(pTsdb, false); @@ -1109,7 +1221,9 @@ static int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SArray } } - (void)taosLRUCacheRelease(pCache, h, false); + if (!taosLRUCacheRelease(pCache, h, false)) { + tsdbInfo("vgId:%d, %s release lru cache failed at line %d", TD_VID(pTsdb->pVnode), __func__, __LINE__); + } TAOS_CHECK_EXIT(code); } else { if (!remainCols) { @@ -1151,7 +1265,7 @@ static int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SArray keys_list_sizes[i] = ROCKS_KEY_LEN; } - rocksMayWrite(pTsdb, true); // flush writebatch cache + rocksMayWrite(pTsdb, true); // flush writebatch cache code = tsdbCacheGetValuesFromRocks(pTsdb, num_keys, (const char *const *)keys_list, keys_list_sizes, &values_list, &values_list_sizes); @@ -1169,7 +1283,11 @@ static int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SArray SColVal *pColVal = &updCtx->colVal; SLastCol *pLastCol = NULL; - (void)tsdbCacheDeserialize(values_list[i], values_list_sizes[i], &pLastCol); + code = tsdbCacheDeserialize(values_list[i], values_list_sizes[i], &pLastCol); + if (code != TSDB_CODE_SUCCESS) { + tsdbWarn("vgId:%d, %s deserialize failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + } /* if (code) { tsdbError("tsdb/cache: vgId:%d, deserialize failed since %s.", TD_VID(pTsdb->pVnode), tstrerror(code)); @@ -1237,7 +1355,8 @@ _exit: taosArrayDestroy(remainCols); if (code) { - tsdbError("tsdb/cache: vgId:%d, update failed at line %d since %s.", TD_VID(pTsdb->pVnode), lino, tstrerror(code)); + tsdbError("tsdb/cache: vgId:%d, update failed at line %d since %s.", TD_VID(pTsdb->pVnode), __LINE__, + tstrerror(code)); } TAOS_RETURN(code); @@ -1268,7 +1387,12 @@ int32_t tsdbCacheRowFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, int6 tsdbRowGetKey(&lRow, &tsdbRowKey); STSDBRowIter iter = {0}; - (void)tsdbRowIterOpen(&iter, &lRow, pTSchema); + code = tsdbRowIterOpen(&iter, &lRow, pTSchema); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s tsdbRowIterOpen failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + TAOS_CHECK_GOTO(code, &lino, _exit); + } int32_t iCol = 0; for (SColVal *pColVal = tsdbRowIterNext(&iter); pColVal && iCol < nCol; pColVal = tsdbRowIterNext(&iter), iCol++) { SLastUpdateCtx updateCtx = {.lflag = LFLAG_LAST_ROW, .tsdbRowKey = tsdbRowKey, .colVal = *pColVal}; @@ -1312,13 +1436,23 @@ int32_t tsdbCacheRowFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, int6 if (!taosArrayPush(ctxArray, &updateCtx)) { TAOS_CHECK_GOTO(terrno, &lino, _exit); } - (void)tSimpleHashIterateRemove(iColHash, &iCol, sizeof(iCol), &pIte, &iter); + code = tSimpleHashIterateRemove(iColHash, &iCol, sizeof(iCol), &pIte, &iter); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s tSimpleHashIterateRemove failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, + __LINE__, tstrerror(code)); + TAOS_CHECK_GOTO(code, &lino, _exit); + } } } } // 3. do update - (void)tsdbCacheUpdate(pTsdb, suid, uid, ctxArray); + code = tsdbCacheUpdate(pTsdb, suid, uid, ctxArray); + if (code < TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s tsdbCacheUpdate failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + TAOS_CHECK_GOTO(code, &lino, _exit); + } _exit: taosMemoryFreeClear(pTSchema); @@ -1384,7 +1518,12 @@ int32_t tsdbCacheColFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SBlo // 2. prepare last row STSDBRowIter iter = {0}; - (void)tsdbRowIterOpen(&iter, &lRow, pTSchema); + code = tsdbRowIterOpen(&iter, &lRow, pTSchema); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s tsdbRowIterOpen failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + TAOS_CHECK_GOTO(code, &lino, _exit); + } for (SColVal *pColVal = tsdbRowIterNext(&iter); pColVal; pColVal = tsdbRowIterNext(&iter)) { SLastUpdateCtx updateCtx = {.lflag = LFLAG_LAST_ROW, .tsdbRowKey = tsdbRowKey, .colVal = *pColVal}; if (!taosArrayPush(ctxArray, &updateCtx)) { @@ -1394,7 +1533,12 @@ int32_t tsdbCacheColFormatUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SBlo tsdbRowClose(&iter); // 3. do update - (void)tsdbCacheUpdate(pTsdb, suid, uid, ctxArray); + code = tsdbCacheUpdate(pTsdb, suid, uid, ctxArray); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s tsdbCacheUpdate failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + TAOS_CHECK_GOTO(code, &lino, _exit); + } _exit: taosMemoryFreeClear(pTSchema); @@ -1604,7 +1748,7 @@ static int32_t tsdbCacheLoadFromRocks(STsdb *pTsdb, tb_uid_t uid, SArray *pLastA keys_list_sizes[i] = ROCKS_KEY_LEN; } - rocksMayWrite(pTsdb, true); // flush writebatch cache + rocksMayWrite(pTsdb, true); // flush writebatch cache code = tsdbCacheGetValuesFromRocks(pTsdb, num_keys, (const char *const *)keys_list, keys_list_sizes, &values_list, &values_list_sizes); @@ -1624,7 +1768,11 @@ static int32_t tsdbCacheLoadFromRocks(STsdb *pTsdb, tb_uid_t uid, SArray *pLastA continue; } - (void)tsdbCacheDeserialize(values_list[i], values_list_sizes[i], &pLastCol); + code = tsdbCacheDeserialize(values_list[i], values_list_sizes[i], &pLastCol); + if (code != TSDB_CODE_SUCCESS) { + tsdbWarn("vgId:%d, %s deserialize failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + } SLastCol *pToFree = pLastCol; SIdxKey *idxKey = &((SIdxKey *)TARRAY_DATA(remainCols))[j]; if (pLastCol && pLastCol->cacheStatus != TSDB_LAST_CACHE_NO_CACHE) { @@ -1757,7 +1905,11 @@ int32_t tsdbCacheGetBatch(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArray, SCache } if (h) { - (void)taosLRUCacheRelease(pCache, h, false); + code = taosLRUCacheRelease(pCache, h, false); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s release lru cache failed at line %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__); + goto _exit; + } } } @@ -1786,7 +1938,11 @@ int32_t tsdbCacheGetBatch(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArray, SCache } if (h) { - (void)taosLRUCacheRelease(pCache, h, false); + code = taosLRUCacheRelease(pCache, h, false); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s release lru cache failed at line %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__); + goto _exit; + } } } @@ -1820,7 +1976,13 @@ int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKE int numKeys = 0; SArray *remainCols = NULL; - (void)tsdbCacheCommit(pTsdb); + code = tsdbCacheCommit(pTsdb); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s commit failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + (void)taosThreadMutexUnlock(&pTsdb->lruMutex); + TAOS_RETURN(code); + } (void)taosThreadMutexLock(&pTsdb->lruMutex); @@ -1837,7 +1999,9 @@ int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKE .cacheStatus = TSDB_LAST_CACHE_NO_CACHE}; code = tsdbCachePutToLRU(pTsdb, &lastKey, &noneCol); } - (void)taosLRUCacheRelease(pTsdb->lruCache, h, false); + if (taosLRUCacheRelease(pTsdb->lruCache, h, false) != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s release lru cache failed at line %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__); + } TAOS_CHECK_EXIT(code); } else { if (!remainCols) { @@ -1871,7 +2035,7 @@ int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKE code = terrno; goto _exit; } - SIdxKey* idxKey = taosArrayGet(remainCols, i); + SIdxKey *idxKey = taosArrayGet(remainCols, i); ((SLastKey *)key)[0] = idxKey->key; @@ -1879,7 +2043,7 @@ int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKE keys_list_sizes[i] = klen; } - rocksMayWrite(pTsdb, true); // flush writebatch cache + rocksMayWrite(pTsdb, true); // flush writebatch cache TAOS_CHECK_GOTO(tsdbCacheGetValuesFromRocks(pTsdb, numKeys, (const char *const *)keys_list, keys_list_sizes, &values_list, &values_list_sizes), @@ -1888,8 +2052,12 @@ int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKE rocksdb_writebatch_t *wb = pTsdb->rCache.writebatch; for (int i = 0; i < numKeys; ++i) { SLastCol *pLastCol = NULL; - (void)tsdbCacheDeserialize(values_list[i], values_list_sizes[i], &pLastCol); - SIdxKey* idxKey = taosArrayGet(remainCols, i); + code = tsdbCacheDeserialize(values_list[i], values_list_sizes[i], &pLastCol); + if (code != TSDB_CODE_SUCCESS) { + tsdbWarn("vgId:%d, %s deserialize failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + } + SIdxKey *idxKey = taosArrayGet(remainCols, i); SLastKey *pLastKey = &idxKey->key; if (NULL != pLastCol && (pLastCol->rowKey.ts <= eKey && pLastCol->rowKey.ts >= sKey)) { SLastCol noCacheCol = {.rowKey.ts = TSKEY_MIN, @@ -2389,7 +2557,12 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie state->pr->pCurFileSet = state->pFileSet; - (void)loadDataTomb(state->pr, state->pr->pFileReader); + code = loadDataTomb(state->pr, state->pr->pFileReader); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s load tomb failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + TAOS_CHECK_GOTO(code, &lino, _err); + } TAOS_CHECK_GOTO(tsdbDataFileReadBrinBlk(state->pr->pFileReader, &state->pr->pBlkArray), &lino, _err); } @@ -2467,7 +2640,12 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie if (!state->pLastRow) { if (state->pLastIter) { - (void)lastIterClose(&state->pLastIter); + code = lastIterClose(&state->pLastIter); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s close last iter failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + TAOS_RETURN(code); + } } clearLastFileSet(state); @@ -2575,7 +2753,12 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie if (!state->pLastRow) { if (state->pLastIter) { - (void)lastIterClose(&state->pLastIter); + code = lastIterClose(&state->pLastIter); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s close last iter failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + TAOS_RETURN(code); + } } *ppRow = &state->row; @@ -2599,7 +2782,12 @@ static int32_t getNextRowFromFS(void *iter, TSDBROW **ppRow, bool *pIgnoreEarlie } else { // TODO: merge rows and *ppRow = mergedRow SRowMerger *pMerger = &state->rowMerger; - (void)tsdbRowMergerInit(pMerger, state->pTSchema); + code = tsdbRowMergerInit(pMerger, state->pTSchema); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("vgId:%d, %s init row merger failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + TAOS_RETURN(code); + } TAOS_CHECK_GOTO(tsdbRowMergerAdd(pMerger, &state->row, state->pTSchema), &lino, _err); TAOS_CHECK_GOTO(tsdbRowMergerAdd(pMerger, state->pLastRow, state->pTSchema), &lino, _err); @@ -2765,7 +2953,11 @@ int32_t clearNextRowFromFS(void *iter) { } if (state->pLastIter) { - (void)lastIterClose(&state->pLastIter); + code = lastIterClose(&state->pLastIter); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s close last iter failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + TAOS_RETURN(code); + } } if (state->pBlockData) { @@ -2798,7 +2990,11 @@ int32_t clearNextRowFromFS(void *iter) { static void clearLastFileSet(SFSNextRowIter *state) { if (state->pLastIter) { - (void)lastIterClose(&state->pLastIter); + int code = lastIterClose(&state->pLastIter); + if (code != TSDB_CODE_SUCCESS) { + tsdbError("%s close last iter failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + return; + } } if (state->pBlockData) { @@ -2983,7 +3179,7 @@ static int32_t nextRowIterGet(CacheNextRowIter *pIter, TSDBROW **ppRow, bool *pI } if (!taosArrayAddAll(pInfo->pTombData, pIter->pMemDelData)) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } size_t delSize = TARRAY_SIZE(pInfo->pTombData); @@ -3363,7 +3559,11 @@ _err: TAOS_RETURN(code); } -void tsdbCacheRelease(SLRUCache *pCache, LRUHandle *h) { (void)taosLRUCacheRelease(pCache, h, false); } +void tsdbCacheRelease(SLRUCache *pCache, LRUHandle *h) { + if (taosLRUCacheRelease(pCache, h, false)) { + tsdbError("%s release lru cache failed at line %d.", __func__, __LINE__); + } +} void tsdbCacheSetCapacity(SVnode *pVnode, size_t capacity) { taosLRUCacheSetCapacity(pVnode->pTsdb->lruCache, capacity); diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit2.c b/source/dnode/vnode/src/tsdb/tsdbCommit2.c index 32371dc399..57f6aa3592 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit2.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit2.c @@ -199,9 +199,9 @@ _exit: return code; } -static int32_t tsdbCommitCloseReader(SCommitter2 *committer) { +static void tsdbCommitCloseReader(SCommitter2 *committer) { TARRAY2_CLEAR(committer->sttReaderArray, tsdbSttFileReaderClose); - return 0; + return; } static int32_t tsdbCommitOpenReader(SCommitter2 *committer) { @@ -243,19 +243,19 @@ static int32_t tsdbCommitOpenReader(SCommitter2 *committer) { _exit: if (code) { - TAOS_UNUSED(tsdbCommitCloseReader(committer)); + tsdbCommitCloseReader(committer); tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(committer->tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } return code; } -static int32_t tsdbCommitCloseIter(SCommitter2 *committer) { +static void tsdbCommitCloseIter(SCommitter2 *committer) { tsdbIterMergerClose(&committer->tombIterMerger); tsdbIterMergerClose(&committer->dataIterMerger); TARRAY2_CLEAR(committer->tombIterArray, tsdbIterClose); TARRAY2_CLEAR(committer->dataIterArray, tsdbIterClose); - return 0; + return; } static int32_t tsdbCommitOpenIter(SCommitter2 *committer) { @@ -309,7 +309,7 @@ static int32_t tsdbCommitOpenIter(SCommitter2 *committer) { _exit: if (code) { - TAOS_UNUSED(tsdbCommitCloseIter(committer)); + tsdbCommitCloseIter(committer); tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(committer->tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } @@ -322,7 +322,7 @@ static int32_t tsdbCommitFileSetBegin(SCommitter2 *committer) { STsdb *tsdb = committer->tsdb; // check if can commit - TAOS_UNUSED(tsdbFSCheckCommit(tsdb, committer->ctx->info->fid)); + tsdbFSCheckCommit(tsdb, committer->ctx->info->fid); committer->ctx->expLevel = tsdbFidLevel(committer->ctx->info->fid, &tsdb->keepCfg, committer->now); tsdbFidKeyRange(committer->ctx->info->fid, committer->minutes, committer->precision, &committer->ctx->minKey, @@ -355,8 +355,8 @@ static int32_t tsdbCommitFileSetEnd(SCommitter2 *committer) { int32_t lino = 0; TAOS_CHECK_GOTO(tsdbCommitCloseWriter(committer), &lino, _exit); - TAOS_CHECK_GOTO(tsdbCommitCloseIter(committer), &lino, _exit); - TAOS_CHECK_GOTO(tsdbCommitCloseReader(committer), &lino, _exit); + tsdbCommitCloseIter(committer); + tsdbCommitCloseReader(committer); _exit: if (code) { @@ -409,11 +409,11 @@ static uint32_t tFileSetCommitInfoHash(const void *arg) { return MurmurHash3_32((const char *)&info->fid, sizeof(info->fid)); } -static int32_t tsdbCommitInfoDestroy(STsdb *pTsdb) { +static void tsdbCommitInfoDestroy(STsdb *pTsdb) { if (pTsdb->commitInfo) { for (int32_t i = 0; i < taosArrayGetSize(pTsdb->commitInfo->arr); i++) { SFileSetCommitInfo *info = *(SFileSetCommitInfo **)taosArrayGet(pTsdb->commitInfo->arr, i); - TAOS_UNUSED(vHashDrop(pTsdb->commitInfo->ht, info)); + int32_t ret = vHashDrop(pTsdb->commitInfo->ht, info); tsdbTFileSetClear(&info->fset); taosMemoryFree(info); } @@ -423,7 +423,7 @@ static int32_t tsdbCommitInfoDestroy(STsdb *pTsdb) { pTsdb->commitInfo->arr = NULL; taosMemoryFreeClear(pTsdb->commitInfo); } - return 0; + return; } static int32_t tsdbCommitInfoInit(STsdb *pTsdb) { @@ -444,7 +444,7 @@ static int32_t tsdbCommitInfoInit(STsdb *pTsdb) { _exit: if (code) { - TAOS_UNUSED(tsdbCommitInfoDestroy(pTsdb)); + tsdbCommitInfoDestroy(pTsdb); tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(pTsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } return code; @@ -514,7 +514,7 @@ static int32_t tsdbCommitInfoBuild(STsdb *tsdb) { SFileSetCommitInfo tinfo = { .fid = fid, }; - TAOS_UNUSED(vHashGet(tsdb->commitInfo->ht, &tinfo, (void **)&info)); + int32_t ret = vHashGet(tsdb->commitInfo->ht, &tinfo, (void **)&info); if (info == NULL) { TAOS_CHECK_GOTO(tsdbCommitInfoAdd(tsdb, fid), &lino, _exit); } @@ -538,7 +538,7 @@ static int32_t tsdbCommitInfoBuild(STsdb *tsdb) { }; // check if the file set already on the commit list - TAOS_UNUSED(vHashGet(tsdb->commitInfo->ht, &tinfo, (void **)&info)); + int32_t ret = vHashGet(tsdb->commitInfo->ht, &tinfo, (void **)&info); if (info != NULL) { continue; } @@ -586,7 +586,7 @@ static int32_t tsdbCommitInfoBuild(STsdb *tsdb) { _exit: if (code) { - TAOS_UNUSED(tsdbCommitInfoDestroy(tsdb)); + tsdbCommitInfoDestroy(tsdb); tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } return code; @@ -716,7 +716,7 @@ int32_t tsdbCommitCommit(STsdb *tsdb) { (void)taosThreadMutexUnlock(&tsdb->mutex); - TAOS_UNUSED(tsdbCommitInfoDestroy(tsdb)); + tsdbCommitInfoDestroy(tsdb); tsdbUnrefMemTable(pMemTable, NULL, true); } @@ -745,7 +745,7 @@ int32_t tsdbCommitAbort(STsdb *pTsdb) { } } (void)taosThreadMutexUnlock(&pTsdb->mutex); - TAOS_UNUSED(tsdbCommitInfoDestroy(pTsdb)); + tsdbCommitInfoDestroy(pTsdb); _exit: if (code) { diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index 19e1f42726..a949fd69f0 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -130,7 +130,7 @@ _exit: tsdbError("%s failed at line %d since %s, fname:%s", __func__, lino, tstrerror(code), fname); } taosMemoryFree(pData); - (void)taosCloseFile(&pFD); + taosCloseFileWithLog(&pFD); return code; } @@ -300,26 +300,26 @@ static int32_t load_fs(const char *fname, STsdbFS *pFS) { int64_t size; code = taosFStatFile(pFD, &size, NULL); if (code != 0) { - (void)taosCloseFile(&pFD); + taosCloseFileWithLog(&pFD); TSDB_CHECK_CODE(code, lino, _exit); } pData = taosMemoryMalloc(size); if (pData == NULL) { code = terrno; - (void)taosCloseFile(&pFD); + taosCloseFileWithLog(&pFD); TSDB_CHECK_CODE(code, lino, _exit); } if (taosReadFile(pFD, pData, size) < 0) { code = terrno; - (void)taosCloseFile(&pFD); + taosCloseFileWithLog(&pFD); TSDB_CHECK_CODE(code, lino, _exit); } if (!taosCheckChecksumWhole(pData, size)) { code = TSDB_CODE_FILE_CORRUPTED; - (void)taosCloseFile(&pFD); + taosCloseFileWithLog(&pFD); TSDB_CHECK_CODE(code, lino, _exit); } @@ -331,7 +331,7 @@ _exit: tsdbError("%s failed at line %d since %s, fname:%s", __func__, lino, tstrerror(code), fname); } taosMemoryFree(pData); - (void)taosCloseFile(&pFD); + taosCloseFileWithLog(&pFD); return code; } diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.c b/source/dnode/vnode/src/tsdb/tsdbFS2.c index bcaa70f9a8..d3b783847c 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.c @@ -44,7 +44,12 @@ static int32_t create_fs(STsdb *pTsdb, STFileSystem **fs) { } fs[0]->tsdb = pTsdb; - (void)tsem_init(&fs[0]->canEdit, 0, 1); + int32_t code = tsem_init(&fs[0]->canEdit, 0, 1); + if (code) { + taosMemoryFree(fs[0]); + return code; + } + fs[0]->fsstate = TSDB_FS_STATE_NORMAL; fs[0]->neid = 0; TARRAY2_INIT(fs[0]->fSetArr); @@ -58,7 +63,9 @@ static void destroy_fs(STFileSystem **fs) { TARRAY2_DESTROY(fs[0]->fSetArr, NULL); TARRAY2_DESTROY(fs[0]->fSetArrTmp, NULL); - (void)tsem_destroy(&fs[0]->canEdit); + if (tsem_destroy(&fs[0]->canEdit) != 0) { + tsdbError("failed to destroy semaphore"); + } taosMemoryFree(fs[0]); fs[0] = NULL; } @@ -100,7 +107,7 @@ _exit: tsdbError("%s failed at %s:%d since %s", __func__, fname, __LINE__, tstrerror(code)); } taosMemoryFree(data); - (void)taosCloseFile(&fp); + taosCloseFileWithLog(&fp); return code; } @@ -140,7 +147,7 @@ _exit: tsdbError("%s failed at %s:%d since %s", __func__, fname, __LINE__, tstrerror(code)); json[0] = NULL; } - (void)taosCloseFile(&fp); + taosCloseFileWithLog(&fp); taosMemoryFree(data); return code; } @@ -803,7 +810,11 @@ void tsdbEnableBgTask(STsdb *pTsdb) { void tsdbCloseFS(STFileSystem **fs) { if (fs[0] == NULL) return; - TAOS_UNUSED(tsdbDisableAndCancelAllBgTask((*fs)->tsdb)); + int32_t code = tsdbDisableAndCancelAllBgTask((*fs)->tsdb); + if (code) { + tsdbError("vgId:%d %s failed at line %d since %s", TD_VID((*fs)->tsdb->pVnode), __func__, __LINE__, + tstrerror(code)); + } close_file_system(fs[0]); destroy_fs(fs); return; @@ -833,7 +844,9 @@ int32_t tsdbFSEditBegin(STFileSystem *fs, const TFileOpArray *opArray, EFEditT e current_fname(fs->tsdb, current_t, TSDB_FCURRENT_M); } - (void)tsem_wait(&fs->canEdit); + if (tsem_wait(&fs->canEdit) != 0) { + tsdbError("vgId:%d failed to wait semaphore", TD_VID(fs->tsdb->pVnode)); + } fs->etype = etype; // edit @@ -865,7 +878,7 @@ static void tsdbFSSetBlockCommit(STFileSet *fset, bool block) { } } -int32_t tsdbFSCheckCommit(STsdb *tsdb, int32_t fid) { +void tsdbFSCheckCommit(STsdb *tsdb, int32_t fid) { (void)taosThreadMutexLock(&tsdb->mutex); STFileSet *fset; tsdbFSGetFSet(tsdb->pFS, fid, &fset); @@ -877,7 +890,7 @@ int32_t tsdbFSCheckCommit(STsdb *tsdb, int32_t fid) { } } (void)taosThreadMutexUnlock(&tsdb->mutex); - return 0; + return; } // IMPORTANT: the caller must hold fs->tsdb->mutex @@ -939,13 +952,17 @@ _exit: } else { tsdbInfo("vgId:%d %s done, etype:%d", TD_VID(fs->tsdb->pVnode), __func__, fs->etype); } - (void)tsem_post(&fs->canEdit); + if (tsem_post(&fs->canEdit) != 0) { + tsdbError("vgId:%d failed to post semaphore", TD_VID(fs->tsdb->pVnode)); + } return code; } int32_t tsdbFSEditAbort(STFileSystem *fs) { int32_t code = abort_edit(fs); - (void)tsem_post(&fs->canEdit); + if (tsem_post(&fs->canEdit) != 0) { + tsdbError("vgId:%d failed to post semaphore", TD_VID(fs->tsdb->pVnode)); + } return code; } diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.h b/source/dnode/vnode/src/tsdb/tsdbFS2.h index 9993c1e33d..119015636b 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.h +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.h @@ -59,10 +59,10 @@ int32_t tsdbFSEditBegin(STFileSystem *fs, const TFileOpArray *opArray, EFEditT e int32_t tsdbFSEditCommit(STFileSystem *fs); int32_t tsdbFSEditAbort(STFileSystem *fs); // other -void tsdbFSGetFSet(STFileSystem *fs, int32_t fid, STFileSet **fset); -int32_t tsdbFSCheckCommit(STsdb *tsdb, int32_t fid); -void tsdbBeginTaskOnFileSet(STsdb *tsdb, int32_t fid, STFileSet **fset); -void tsdbFinishTaskOnFileSet(STsdb *tsdb, int32_t fid); +void tsdbFSGetFSet(STFileSystem *fs, int32_t fid, STFileSet **fset); +void tsdbFSCheckCommit(STsdb *tsdb, int32_t fid); +void tsdbBeginTaskOnFileSet(STsdb *tsdb, int32_t fid, STFileSet **fset); +void tsdbFinishTaskOnFileSet(STsdb *tsdb, int32_t fid); // utils int32_t save_fs(const TFileSetArray *arr, const char *fname); void current_fname(STsdb *pTsdb, char *fname, EFCurrentT ftype); diff --git a/source/dnode/vnode/src/tsdb/tsdbOpen.c b/source/dnode/vnode/src/tsdb/tsdbOpen.c index 1923c8bafc..c1f8f45d7e 100644 --- a/source/dnode/vnode/src/tsdb/tsdbOpen.c +++ b/source/dnode/vnode/src/tsdb/tsdbOpen.c @@ -102,7 +102,7 @@ _exit: return code; } -int32_t tsdbClose(STsdb **pTsdb) { +void tsdbClose(STsdb **pTsdb) { if (*pTsdb) { STsdb *pdb = *pTsdb; tsdbDebug("vgId:%d, tsdb is close at %s, days:%d, keep:%d,%d,%d, keepTimeOffset:%d", TD_VID(pdb->pVnode), pdb->path, @@ -121,5 +121,5 @@ int32_t tsdbClose(STsdb **pTsdb) { (void)taosThreadMutexDestroy(&(*pTsdb)->mutex); taosMemoryFreeClear(*pTsdb); } - return 0; + return; } diff --git a/source/dnode/vnode/src/tsdb/tsdbRead2.c b/source/dnode/vnode/src/tsdb/tsdbRead2.c index 1fc67ec66f..5b6511a38e 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead2.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead2.c @@ -82,7 +82,7 @@ static bool hasDataInFileBlock(const SBlockData* pBlockData, const SFil static bool hasDataInSttBlock(STableBlockScanInfo* pInfo); static void initBlockDumpInfo(STsdbReader* pReader, SDataBlockIter* pBlockIter); static int32_t getInitialDelIndex(const SArray* pDelSkyline, int32_t order); -static void resetTableListIndex(SReaderStatus* pStatus); +static int32_t resetTableListIndex(SReaderStatus* pStatus, const char* id); static void getMemTableTimeRange(STsdbReader* pReader, int64_t* pMaxKey, int64_t* pMinKey); static void updateComposedBlockInfo(STsdbReader* pReader, double el, STableBlockScanInfo* pBlockScanInfo); static int32_t buildFromPreFilesetBuffer(STsdbReader* pReader); @@ -257,9 +257,8 @@ static int32_t initFilesetIterator(SFilesetIter* pIter, TFileSetArray* pFileSetA if (pIter->pSttBlockReader == NULL) { pIter->pSttBlockReader = taosMemoryCalloc(1, sizeof(struct SSttBlockReader)); if (pIter->pSttBlockReader == NULL) { - code = terrno; - tsdbError("failed to prepare the last block iterator, since:%s %s", tstrerror(code), pReader->idStr); - return code; + tsdbError("failed to prepare the last block iterator, since:%s %s", tstrerror(terrno), pReader->idStr); + return terrno; } } @@ -300,7 +299,7 @@ static int32_t filesetIteratorNext(SFilesetIter* pIter, STsdbReader* pReader, bo pReader->status.pLDataIterArray = taosArrayInit(4, POINTER_BYTES); if (pReader->status.pLDataIterArray == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } // check file the time range of coverage @@ -381,13 +380,15 @@ _err: bool shouldFreePkBuf(SBlockLoadSuppInfo* pSupp) { return (pSupp->numOfPks > 0) && IS_VAR_DATA_TYPE(pSupp->pk.type); } -int32_t resetDataBlockIterator(SDataBlockIter* pIter, int32_t order, bool needFree) { +int32_t resetDataBlockIterator(SDataBlockIter* pIter, int32_t order, bool needFree, const char* id) { pIter->order = order; pIter->index = -1; pIter->numOfBlocks = 0; + if (pIter->blockList == NULL) { pIter->blockList = taosArrayInit(4, sizeof(SFileDataBlockInfo)); if (pIter->blockList == NULL) { + tsdbError("%s failed to reset block iter, func:%s at line:%d code:%s", id, __func__, __LINE__, tstrerror(terrno)); return terrno; } } else { @@ -555,7 +556,7 @@ static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, void pReader->idStr = (idstr != NULL) ? taosStrdup(idstr) : NULL; if (idstr != NULL && pReader->idStr == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _end; } @@ -584,7 +585,6 @@ static int32_t tsdbReaderCreate(SVnode* pVnode, SQueryTableDataCond* pCond, void code = tBlockDataCreate(&pReader->status.fileBlockData); if (code != TSDB_CODE_SUCCESS) { - terrno = code; goto _end; } @@ -2918,7 +2918,7 @@ int32_t initDelSkylineIterator(STableBlockScanInfo* pBlockScanInfo, int32_t orde } else { void* p1 = taosArrayAddAll(pSource, pBlockScanInfo->pMemDelData); if (p1 == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -3072,12 +3072,18 @@ static int32_t moveToNextFile(STsdbReader* pReader, SBlockNumber* pBlockNum, SAr } // pTableIter can be NULL, no need to handle the return value -static void resetTableListIndex(SReaderStatus* pStatus) { +static int32_t resetTableListIndex(SReaderStatus* pStatus, const char* id) { STableUidList* pList = &pStatus->uidList; pList->currentIndex = 0; uint64_t uid = pList->tableUidList[0]; pStatus->pTableIter = tSimpleHashGet(pStatus->pTableMap, &uid, sizeof(uid)); + if (pStatus->pTableIter == NULL) { + tsdbError("%s failed to load tableBlockScanInfo for uid:%"PRId64", code: internal error", id, uid); + return TSDB_CODE_INTERNAL_ERROR; + } + + return 0; } static void resetPreFilesetMemTableListIndex(SReaderStatus* pStatus) { @@ -3209,8 +3215,8 @@ static int32_t doLoadSttBlockSequentially(STsdbReader* pReader) { } // load the last data block of current table - STableBlockScanInfo* pScanInfo = *(STableBlockScanInfo**)pStatus->pTableIter; - if (pScanInfo == NULL) { + STableBlockScanInfo* pScanInfo = NULL; + if (pStatus->pTableIter == NULL) { tsdbError("table Iter is null, invalid pScanInfo, try next table %s", pReader->idStr); bool hasNexTable = moveToNextTable(pUidList, pStatus); if (!hasNexTable) { @@ -3218,6 +3224,8 @@ static int32_t doLoadSttBlockSequentially(STsdbReader* pReader) { } continue; + } else { + pScanInfo = *(STableBlockScanInfo**) pStatus->pTableIter; } if (pReader->pIgnoreTables && taosHashGet(*pReader->pIgnoreTables, &pScanInfo->uid, sizeof(pScanInfo->uid))) { @@ -3562,14 +3570,21 @@ static int32_t initForFirstBlockInFile(STsdbReader* pReader, SDataBlockIter* pBl code = initBlockIterator(pReader, pBlockIter, num.numOfBlocks, pTableList); } else { // no block data, only last block exists tBlockDataReset(&pReader->status.fileBlockData); - code = resetDataBlockIterator(pBlockIter, pReader->info.order, shouldFreePkBuf(&pReader->suppInfo)); - resetTableListIndex(&pReader->status); + code = resetDataBlockIterator(pBlockIter, pReader->info.order, shouldFreePkBuf(&pReader->suppInfo), pReader->idStr); + if (code) { + return code; + } + + code = resetTableListIndex(&pReader->status, pReader->idStr); + if (code) { + return code; + } } - if (code == TSDB_CODE_SUCCESS) { - // set the correct start position according to the query time window + if (code == TSDB_CODE_SUCCESS) { // set the correct start position according to the query time window initBlockDumpInfo(pReader, pBlockIter); } + taosArrayDestroy(pTableList); return code; } @@ -3584,38 +3599,40 @@ typedef enum { TSDB_READ_CONTINUE = 0x2, } ERetrieveType; -static ERetrieveType doReadDataFromSttFiles(STsdbReader* pReader) { +static int32_t doReadDataFromSttFiles(STsdbReader* pReader, ERetrieveType* pReturnType) { int32_t code = TSDB_CODE_SUCCESS; SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock; SDataBlockIter* pBlockIter = &pReader->status.blockIter; + *pReturnType = TSDB_READ_RETURN; + tsdbDebug("seq load data blocks from stt files %s", pReader->idStr); while (1) { - terrno = 0; - code = doLoadSttBlockSequentially(pReader); if (code != TSDB_CODE_SUCCESS) { - terrno = code; - return TSDB_READ_RETURN; + *pReturnType = TSDB_READ_RETURN; + return code; } if (pResBlock->info.rows > 0) { - return TSDB_READ_RETURN; + *pReturnType = TSDB_READ_RETURN; + return code; } // all data blocks are checked in this stt file, now let's try the next file set if (pReader->status.pTableIter != NULL) { - terrno = TSDB_CODE_INTERNAL_ERROR; - tsdbError("tsdb reader failed at: %s:%d", __func__, __LINE__); - return TSDB_READ_RETURN; + code = TSDB_CODE_INTERNAL_ERROR; + tsdbError("tsdb reader failed at: %s:%d, code:%s", __func__, __LINE__, tstrerror(code)); + return code; } + code = initForFirstBlockInFile(pReader, pBlockIter); // error happens or all the data files are completely checked if ((code != TSDB_CODE_SUCCESS) || (pReader->status.loadFromFile == false)) { - terrno = code; - return TSDB_READ_RETURN; + *pReturnType = TSDB_READ_RETURN; + return code; } if (pReader->status.bProcMemPreFileset) { @@ -3625,14 +3642,19 @@ static ERetrieveType doReadDataFromSttFiles(STsdbReader* pReader) { } if (pResBlock->info.rows > 0) { pReader->status.processingMemPreFileSet = true; - return TSDB_READ_RETURN; + *pReturnType = TSDB_READ_RETURN; + return code; } } if (pBlockIter->numOfBlocks > 0) { // there are data blocks existed. - return TSDB_READ_CONTINUE; - } else { // all blocks in data file are checked, let's check the data in last files - resetTableListIndex(&pReader->status); + *pReturnType = TSDB_READ_CONTINUE; + return code; + } else { // all blocks in data file are checked, let's check the data in stt-files + code = resetTableListIndex(&pReader->status, pReader->idStr); + if (code) { + return code; + } } } } @@ -3641,15 +3663,18 @@ static int32_t buildBlockFromFiles(STsdbReader* pReader) { int32_t code = TSDB_CODE_SUCCESS; bool asc = ASCENDING_TRAVERSE(pReader->info.order); - SDataBlockIter* pBlockIter = &pReader->status.blockIter; - SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock; + SDataBlockIter* pBlockIter = &pReader->status.blockIter; + SSDataBlock* pResBlock = pReader->resBlockInfo.pResBlock; + SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; + SBlockData* pBlockData = &pReader->status.fileBlockData; + const char* id = pReader->idStr; if (pBlockIter->numOfBlocks == 0) { // let's try to extract data from stt files. - terrno = 0; - ERetrieveType type = doReadDataFromSttFiles(pReader); - if (type == TSDB_READ_RETURN) { - return terrno; + ERetrieveType type = 0; + code = doReadDataFromSttFiles(pReader, &type); + if (code != 0 || type == TSDB_READ_RETURN) { + return code; } code = doBuildDataBlock(pReader); @@ -3658,9 +3683,6 @@ static int32_t buildBlockFromFiles(STsdbReader* pReader) { } } - SFileBlockDumpInfo* pDumpInfo = &pReader->status.fBlockDumpInfo; - SBlockData* pBlockData = &pReader->status.fileBlockData; - while (1) { if (fileBlockPartiallyRead(pDumpInfo, asc)) { // file data block is partially loaded code = buildComposedDataBlock(pReader); @@ -3679,15 +3701,20 @@ static int32_t buildBlockFromFiles(STsdbReader* pReader) { } tBlockDataReset(pBlockData); - code = resetDataBlockIterator(pBlockIter, pReader->info.order, shouldFreePkBuf(&pReader->suppInfo)); + code = resetDataBlockIterator(pBlockIter, pReader->info.order, shouldFreePkBuf(&pReader->suppInfo), id); if (code != TSDB_CODE_SUCCESS) { return code; } - resetTableListIndex(&pReader->status); - ERetrieveType type = doReadDataFromSttFiles(pReader); - if (type == TSDB_READ_RETURN) { - return terrno; + code = resetTableListIndex(&pReader->status, id); + if (code != TSDB_CODE_SUCCESS) { + return code; + } + + ERetrieveType type = 0; + code = doReadDataFromSttFiles(pReader, &type); + if (code != 0 || type == TSDB_READ_RETURN) { + return code; } } } @@ -4649,7 +4676,7 @@ uint64_t tsdbGetReaderMaxVersion2(STsdbReader* pReader) { return pReader->info.v static int32_t doOpenReaderImpl(STsdbReader* pReader) { SReaderStatus* pStatus = &pReader->status; SDataBlockIter* pBlockIter = &pStatus->blockIter; - int32_t code = TSDB_CODE_SUCCESS; + int32_t code = TSDB_CODE_SUCCESS; if (pReader->bFilesetDelimited) { getMemTableTimeRange(pReader, &pReader->status.memTableMaxKey, &pReader->status.memTableMinKey); @@ -4661,7 +4688,8 @@ static int32_t doOpenReaderImpl(STsdbReader* pReader) { return code; } - code = resetDataBlockIterator(&pStatus->blockIter, pReader->info.order, shouldFreePkBuf(&pReader->suppInfo)); + code = resetDataBlockIterator(&pStatus->blockIter, pReader->info.order, shouldFreePkBuf(&pReader->suppInfo), + pReader->idStr); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -4673,7 +4701,7 @@ static int32_t doOpenReaderImpl(STsdbReader* pReader) { } if (!pStatus->loadFromFile) { - resetTableListIndex(pStatus); + code = resetTableListIndex(pStatus, pReader->idStr); } return code; @@ -5146,7 +5174,11 @@ static int32_t doTsdbNextDataBlockFilesetDelimited(STsdbReader* pReader) { } if (pBlock->info.rows <= 0) { - resetTableListIndex(&pReader->status); + code = resetTableListIndex(&pReader->status, pReader->idStr); + if (code) { + return code; + } + int64_t endKey = (ASCENDING_TRAVERSE(pReader->info.order)) ? INT64_MAX : INT64_MIN; code = buildBlockFromBufferSequentially(pReader, endKey); } @@ -5169,7 +5201,11 @@ static int32_t doTsdbNextDataBlockFilesFirst(STsdbReader* pReader) { } if (pBlock->info.rows <= 0) { - resetTableListIndex(&pReader->status); + code = resetTableListIndex(&pReader->status, pReader->idStr); + if (code) { + return code; + } + int64_t endKey = (ASCENDING_TRAVERSE(pReader->info.order)) ? INT64_MAX : INT64_MIN; code = buildBlockFromBufferSequentially(pReader, endKey); } @@ -5587,13 +5623,17 @@ int32_t tsdbReaderReset2(STsdbReader* pReader, SQueryTableDataCond* pCond) { return code; } - code = resetDataBlockIterator(pBlockIter, pReader->info.order, shouldFreePkBuf(&pReader->suppInfo)); + code = resetDataBlockIterator(pBlockIter, pReader->info.order, shouldFreePkBuf(&pReader->suppInfo), pReader->idStr); if (code != TSDB_CODE_SUCCESS) { (void) tsdbReleaseReader(pReader); return code; } - resetTableListIndex(&pReader->status); + code = resetTableListIndex(&pReader->status, pReader->idStr); + if (code != TSDB_CODE_SUCCESS) { + (void) tsdbReleaseReader(pReader); + return code; + } bool asc = ASCENDING_TRAVERSE(pReader->info.order); int32_t step = asc ? 1 : -1; @@ -5608,7 +5648,11 @@ int32_t tsdbReaderReset2(STsdbReader* pReader, SQueryTableDataCond* pCond) { // no data in files, let's try buffer in memory if (pStatus->fileIter.numOfFiles == 0) { pStatus->loadFromFile = false; - resetTableListIndex(pStatus); + code = resetTableListIndex(pStatus, pReader->idStr); + if (code != TSDB_CODE_SUCCESS) { + (void) tsdbReleaseReader(pReader); + return code; + } } else { code = initForFirstBlockInFile(pReader, pBlockIter); if (code != TSDB_CODE_SUCCESS) { @@ -5845,9 +5889,9 @@ int32_t tsdbGetTableSchema(SMeta* pMeta, int64_t uid, STSchema** pSchema, int64_ metaReaderDoInit(&mr, pMeta, META_READER_LOCK); int32_t code = metaReaderGetTableEntryByUidCache(&mr, uid); if (code != TSDB_CODE_SUCCESS) { - terrno = TSDB_CODE_TDB_INVALID_TABLE_ID; + code = TSDB_CODE_TDB_INVALID_TABLE_ID; metaReaderClear(&mr); - return terrno; + return code; } *suid = 0; @@ -5858,15 +5902,15 @@ int32_t tsdbGetTableSchema(SMeta* pMeta, int64_t uid, STSchema** pSchema, int64_ *suid = mr.me.ctbEntry.suid; code = metaReaderGetTableEntryByUidCache(&mr, *suid); if (code != TSDB_CODE_SUCCESS) { - terrno = TSDB_CODE_TDB_INVALID_TABLE_ID; + code = TSDB_CODE_TDB_INVALID_TABLE_ID; metaReaderClear(&mr); - return terrno; + return code; } } else if (mr.me.type == TSDB_NORMAL_TABLE) { // do nothing } else { - terrno = TSDB_CODE_INVALID_PARA; + code = TSDB_CODE_INVALID_PARA; metaReaderClear(&mr); - return terrno; + return code; } metaReaderClear(&mr); diff --git a/source/dnode/vnode/src/tsdb/tsdbReadUtil.h b/source/dnode/vnode/src/tsdb/tsdbReadUtil.h index 7c7bee8260..6ec1f99577 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReadUtil.h +++ b/source/dnode/vnode/src/tsdb/tsdbReadUtil.h @@ -357,7 +357,7 @@ int32_t initRowKey(SRowKey* pKey, int64_t ts, int32_t numOfPks, int32_t type, in void clearRowKey(SRowKey* pKey); bool shouldFreePkBuf(SBlockLoadSuppInfo* pSupp); -int32_t resetDataBlockIterator(SDataBlockIter* pIter, int32_t order, bool hasPk); +int32_t resetDataBlockIterator(SDataBlockIter* pIter, int32_t order, bool hasPk, const char* id); void clearDataBlockIterator(SDataBlockIter* pIter, bool needFree); void cleanupDataBlockIterator(SDataBlockIter* pIter, bool hasPk); diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c index 74b7ebc06b..c0d8f7f17d 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c +++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c @@ -436,7 +436,7 @@ static int32_t tsdbReadFileS3(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64 code = tsdbCacheGetPageS3(pFD->pTsdb->pgCache, pFD, pgno, &handle); if (code != TSDB_CODE_SUCCESS) { if (handle) { - (void)tsdbCacheRelease(pFD->pTsdb->pgCache, handle); + tsdbCacheRelease(pFD->pTsdb->pgCache, handle); } TSDB_CHECK_CODE(code, lino, _exit); } @@ -447,7 +447,7 @@ static int32_t tsdbReadFileS3(STsdbFD *pFD, int64_t offset, uint8_t *pBuf, int64 uint8_t *pPage = (uint8_t *)taosLRUCacheValue(pFD->pTsdb->pgCache, handle); memcpy(pFD->pBuf, pPage, pFD->szPage); - (void)tsdbCacheRelease(pFD->pTsdb->pgCache, handle); + tsdbCacheRelease(pFD->pTsdb->pgCache, handle); // check if (pgno > 1 && !taosCheckChecksumWhole(pFD->pBuf, pFD->szPage)) { diff --git a/source/dnode/vnode/src/tsdb/tsdbRetention.c b/source/dnode/vnode/src/tsdb/tsdbRetention.c index 4b690cf53b..af42a0e592 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRetention.c +++ b/source/dnode/vnode/src/tsdb/tsdbRetention.c @@ -99,8 +99,12 @@ _exit: tsdbError("vgId:%d, %s failed at %s:%d since %s", TD_VID(rtner->tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } - (void)taosCloseFile(&fdFrom); - (void)taosCloseFile(&fdTo); + if (taosCloseFile(&fdFrom) != 0) { + tsdbError("vgId:%d, failed to close file %s", TD_VID(rtner->tsdb->pVnode), fname_from); + } + if (taosCloseFile(&fdTo) != 0) { + tsdbError("vgId:%d, failed to close file %s", TD_VID(rtner->tsdb->pVnode), fname_to); + } return code; } @@ -136,8 +140,12 @@ _exit: tsdbError("vgId:%d, %s failed at %s:%d since %s", TD_VID(rtner->tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } - (void)taosCloseFile(&fdFrom); - (void)taosCloseFile(&fdTo); + if (taosCloseFile(&fdFrom) != 0) { + tsdbTrace("vgId:%d, failed to close file", TD_VID(rtner->tsdb->pVnode)); + } + if (taosCloseFile(&fdTo) != 0) { + tsdbTrace("vgId:%d, failed to close file", TD_VID(rtner->tsdb->pVnode)); + } return code; } @@ -441,7 +449,9 @@ _exit: tsdbError("vgId:%d %s failed at line %s:%d since %s", TD_VID(rtner->tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } - (void)taosCloseFile(&fdFrom); + if (taosCloseFile(&fdFrom) != 0) { + tsdbTrace("vgId:%d, failed to close file", TD_VID(rtner->tsdb->pVnode)); + } return code; } @@ -541,8 +551,13 @@ _exit: tsdbError("vgId:%d %s failed at line %s:%d since %s", TD_VID(rtner->tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } - (void)taosCloseFile(&fdFrom); - (void)taosCloseFile(&fdTo); + if (taosCloseFile(&fdFrom) != 0) { + tsdbTrace("vgId:%d, failed to close file", TD_VID(rtner->tsdb->pVnode)); + } + + if (taosCloseFile(&fdTo) != 0) { + tsdbTrace("vgId:%d, failed to close file", TD_VID(rtner->tsdb->pVnode)); + } return code; } @@ -639,8 +654,12 @@ _exit: tsdbError("vgId:%d %s failed at line %s:%d since %s", TD_VID(rtner->tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); } - (void)taosCloseFile(&fdFrom); - (void)taosCloseFile(&fdTo); + if (taosCloseFile(&fdFrom) != 0) { + tsdbTrace("vgId:%d, failed to close file", TD_VID(rtner->tsdb->pVnode)); + } + if (taosCloseFile(&fdTo) != 0) { + tsdbTrace("vgId:%d, failed to close file", TD_VID(rtner->tsdb->pVnode)); + } return code; } @@ -699,7 +718,9 @@ static int32_t tsdbDoS3Migrate(SRTNer *rtner) { if (taosCheckExistFile(fname1)) { int32_t mtime = 0; int64_t size = 0; - (void)taosStatFile(fname1, &size, &mtime, NULL); + if (taosStatFile(fname1, &size, &mtime, NULL) != 0) { + tsdbError("vgId:%d, %s failed at %s:%d ", TD_VID(rtner->tsdb->pVnode), __func__, __FILE__, __LINE__); + } if (size > chunksize && mtime < rtner->now - tsS3UploadDelaySec) { TAOS_CHECK_GOTO(tsdbMigrateDataFileLCS3(rtner, fobj, size, chunksize), &lino, _exit); } diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c index da49b40d18..94ca8d96a1 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c @@ -57,10 +57,10 @@ struct STsdbSnapReader { STombBlock tombBlock[1]; }; -static int32_t tsdbSnapReadFileSetCloseReader(STsdbSnapReader* reader) { +static void tsdbSnapReadFileSetCloseReader(STsdbSnapReader* reader) { TARRAY2_CLEAR(reader->sttReaderArr, tsdbSttFileReaderClose); tsdbDataFileReaderClose(&reader->dataReader); - return 0; + return; } static int32_t tsdbSnapReadFileSetOpenReader(STsdbSnapReader* reader) { @@ -112,7 +112,7 @@ static int32_t tsdbSnapReadFileSetOpenReader(STsdbSnapReader* reader) { _exit: if (code) { - TAOS_UNUSED(tsdbSnapReadFileSetCloseReader(reader)); + tsdbSnapReadFileSetCloseReader(reader); TSDB_ERROR_LOG(TD_VID(reader->tsdb->pVnode), code, lino); } return code; @@ -190,12 +190,12 @@ _exit: return code; } -static int32_t tsdbSnapReadFileSetCloseIter(STsdbSnapReader* reader) { +static void tsdbSnapReadFileSetCloseIter(STsdbSnapReader* reader) { tsdbIterMergerClose(&reader->dataIterMerger); tsdbIterMergerClose(&reader->tombIterMerger); TARRAY2_CLEAR(reader->dataIterArr, tsdbIterClose); TARRAY2_CLEAR(reader->tombIterArr, tsdbIterClose); - return 0; + return; } static int32_t tsdbSnapReadRangeBegin(STsdbSnapReader* reader) { @@ -222,8 +222,8 @@ _exit: } static int32_t tsdbSnapReadRangeEnd(STsdbSnapReader* reader) { - TAOS_UNUSED(tsdbSnapReadFileSetCloseIter(reader)); - TAOS_UNUSED(tsdbSnapReadFileSetCloseReader(reader)); + tsdbSnapReadFileSetCloseIter(reader); + tsdbSnapReadFileSetCloseReader(reader); reader->ctx->fsr = NULL; return 0; } @@ -373,7 +373,7 @@ static int32_t tsdbSnapReadTombData(STsdbSnapReader* reader, uint8_t** data) { int32_t lino = 0; SMetaInfo info; - TAOS_UNUSED(tTombBlockClear(reader->tombBlock)); + tTombBlockClear(reader->tombBlock); TABLEID tbid[1] = {0}; for (STombRecord* record; (record = tsdbIterMergerGetTombRecord(reader->tombIterMerger)) != NULL;) { @@ -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; @@ -463,13 +463,13 @@ int32_t tsdbSnapReaderClose(STsdbSnapReader** reader) { tDestroyTSchema(reader[0]->skmTb->pTSchema); for (int32_t i = 0; i < ARRAY_SIZE(reader[0]->buffers); ++i) { - TAOS_UNUSED(tBufferDestroy(reader[0]->buffers + i)); + tBufferDestroy(reader[0]->buffers + i); } taosMemoryFree(reader[0]); reader[0] = NULL; - return code; + return; } int32_t tsdbSnapRead(STsdbSnapReader* reader, uint8_t** data) { @@ -1000,7 +1000,7 @@ static int32_t tsdbSnapWriteDecmprTombBlock(SSnapDataHdr* hdr, STombBlock* tombB int32_t code = 0; int32_t lino = 0; - TAOS_UNUSED(tTombBlockClear(tombBlock)); + tTombBlockClear(tombBlock); int64_t size = hdr->size; size = size / TOMB_RECORD_ELEM_NUM; diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshotRAW.c b/source/dnode/vnode/src/tsdb/tsdbSnapshotRAW.c index 609e2a80e9..a41003d9ab 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapshotRAW.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapshotRAW.c @@ -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) { diff --git a/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c b/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c index 1b6639882b..c7f877a51b 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c +++ b/source/dnode/vnode/src/tsdb/tsdbSttFileRW.c @@ -415,7 +415,7 @@ int32_t tsdbSttFileReadStatisBlock(SSttFileReader *reader, const SStatisBlk *sta &lino, _exit); // decode data - TAOS_UNUSED(tStatisBlockClear(statisBlock)); + tStatisBlockClear(statisBlock); statisBlock->numOfPKs = statisBlk->numOfPKs; statisBlock->numOfRecords = statisBlk->numRec; SBufferReader br = BUFFER_READER_INITIALIZER(0, buffer0); @@ -654,7 +654,7 @@ static int32_t tsdbSttFileDoWriteStatisBlock(SSttFileWriter *writer) { TAOS_CHECK_GOTO(TARRAY2_APPEND_PTR(writer->statisBlkArray, &statisBlk), &lino, _exit); - TAOS_UNUSED(tStatisBlockClear(writer->staticBlock)); + tStatisBlockClear(writer->staticBlock); _exit: if (code) { diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c index 34a07333ae..5b8a062361 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c @@ -609,7 +609,10 @@ void tsdbRowGetColVal(TSDBROW *pRow, STSchema *pTSchema, int32_t iCol, SColVal * SValue value; if (pRow->type == TSDBROW_ROW_FMT) { - (void)tRowGet(pRow->pTSRow, pTSchema, iCol, pColVal); + int32_t ret = tRowGet(pRow->pTSRow, pTSchema, iCol, pColVal); + if (ret != 0) { + tsdbError("failed to get column value, code:%d", ret); + } } else if (pRow->type == TSDBROW_COL_FMT) { if (iCol == 0) { *pColVal = diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil2.c b/source/dnode/vnode/src/tsdb/tsdbUtil2.c index 4bccf7df13..ba4ab9386b 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUtil2.c +++ b/source/dnode/vnode/src/tsdb/tsdbUtil2.c @@ -93,25 +93,25 @@ void tStatisBlockDestroy(STbStatisBlock *statisBlock) { statisBlock->numOfPKs = 0; statisBlock->numOfRecords = 0; for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) { - TAOS_UNUSED(tBufferDestroy(&statisBlock->buffers[i])); + tBufferDestroy(&statisBlock->buffers[i]); } for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) { - TAOS_UNUSED(tValueColumnDestroy(&statisBlock->firstKeyPKs[i])); - TAOS_UNUSED(tValueColumnDestroy(&statisBlock->lastKeyPKs[i])); + tValueColumnDestroy(&statisBlock->firstKeyPKs[i]); + tValueColumnDestroy(&statisBlock->lastKeyPKs[i]); } } -int32_t tStatisBlockClear(STbStatisBlock *statisBlock) { +void tStatisBlockClear(STbStatisBlock *statisBlock) { statisBlock->numOfPKs = 0; statisBlock->numOfRecords = 0; for (int32_t i = 0; i < ARRAY_SIZE(statisBlock->buffers); ++i) { - TAOS_UNUSED(tBufferClear(&statisBlock->buffers[i])); + tBufferClear(&statisBlock->buffers[i]); } for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) { - TAOS_UNUSED(tValueColumnClear(&statisBlock->firstKeyPKs[i])); - TAOS_UNUSED(tValueColumnClear(&statisBlock->lastKeyPKs[i])); + tValueColumnClear(&statisBlock->firstKeyPKs[i]); + tValueColumnClear(&statisBlock->lastKeyPKs[i]); } - return 0; + return; } static int32_t tStatisBlockAppend(STbStatisBlock *block, SRowInfo *row) { @@ -252,11 +252,11 @@ void tBrinBlockDestroy(SBrinBlock *brinBlock) { brinBlock->numOfPKs = 0; brinBlock->numOfRecords = 0; for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) { - TAOS_UNUSED(tBufferDestroy(&brinBlock->buffers[i])); + tBufferDestroy(&brinBlock->buffers[i]); } for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) { - TAOS_UNUSED(tValueColumnDestroy(&brinBlock->firstKeyPKs[i])); - TAOS_UNUSED(tValueColumnDestroy(&brinBlock->lastKeyPKs[i])); + tValueColumnDestroy(&brinBlock->firstKeyPKs[i]); + tValueColumnDestroy(&brinBlock->lastKeyPKs[i]); } } @@ -264,11 +264,11 @@ void tBrinBlockClear(SBrinBlock *brinBlock) { brinBlock->numOfPKs = 0; brinBlock->numOfRecords = 0; for (int32_t i = 0; i < ARRAY_SIZE(brinBlock->buffers); ++i) { - TAOS_UNUSED(tBufferClear(&brinBlock->buffers[i])); + tBufferClear(&brinBlock->buffers[i]); } for (int32_t i = 0; i < TD_MAX_PK_COLS; ++i) { - TAOS_UNUSED(tValueColumnClear(&brinBlock->firstKeyPKs[i])); - TAOS_UNUSED(tValueColumnClear(&brinBlock->lastKeyPKs[i])); + tValueColumnClear(&brinBlock->firstKeyPKs[i]); + tValueColumnClear(&brinBlock->lastKeyPKs[i]); } } diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil2.h b/source/dnode/vnode/src/tsdb/tsdbUtil2.h index ccc9009fd3..649f317485 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUtil2.h +++ b/source/dnode/vnode/src/tsdb/tsdbUtil2.h @@ -113,7 +113,7 @@ typedef struct { int32_t tStatisBlockInit(STbStatisBlock *statisBlock); void tStatisBlockDestroy(STbStatisBlock *statisBlock); -int32_t tStatisBlockClear(STbStatisBlock *statisBlock); +void tStatisBlockClear(STbStatisBlock *statisBlock); int32_t tStatisBlockPut(STbStatisBlock *statisBlock, SRowInfo *row, int32_t maxRecords); int32_t tStatisBlockGet(STbStatisBlock *statisBlock, int32_t idx, STbStatisRecord *record); diff --git a/source/dnode/vnode/src/vnd/vnodeAsync.c b/source/dnode/vnode/src/vnd/vnodeAsync.c index 27580f2e76..9e4fbd84a9 100644 --- a/source/dnode/vnode/src/vnd/vnodeAsync.c +++ b/source/dnode/vnode/src/vnd/vnodeAsync.c @@ -187,10 +187,12 @@ static void vnodeAsyncCancelAllTasks(SVAsync *async, SArray *cancelArray) { task->prev->next = task->next; task->next->prev = task->prev; if (task->cancel) { - TAOS_UNUSED(taosArrayPush(cancelArray, &(SVATaskCancelInfo){ - .cancel = task->cancel, - .arg = task->arg, - })); + if (taosArrayPush(cancelArray, &(SVATaskCancelInfo){ + .cancel = task->cancel, + .arg = task->arg, + }) == NULL) { + vError("failed to push cancel task into array"); + }; } vnodeAsyncTaskDone(async, task); } @@ -430,7 +432,7 @@ static void vnodeAsyncLaunchWorker(SVAsync *async) { if (async->workers[i].state == EVA_WORKER_STATE_ACTIVE) { continue; } else if (async->workers[i].state == EVA_WORKER_STATE_STOP) { - TAOS_UNUSED(taosThreadJoin(async->workers[i].thread, NULL)); + int32_t ret = taosThreadJoin(async->workers[i].thread, NULL); async->workers[i].state = EVA_WORKER_STATE_UINIT; } @@ -748,10 +750,12 @@ int32_t vnodeAChannelDestroy(SVAChannelID *channelID, bool waitRunning) { task->prev->next = task->next; task->next->prev = task->prev; if (task->cancel) { - TAOS_UNUSED(taosArrayPush(cancelArray, &(SVATaskCancelInfo){ - .cancel = task->cancel, - .arg = task->arg, - })); + if (taosArrayPush(cancelArray, &(SVATaskCancelInfo){ + .cancel = task->cancel, + .arg = task->arg, + }) == NULL) { + vError("failed to push cancel info"); + }; } vnodeAsyncTaskDone(async, task); } @@ -763,10 +767,12 @@ int32_t vnodeAChannelDestroy(SVAChannelID *channelID, bool waitRunning) { channel->scheduled->prev->next = channel->scheduled->next; channel->scheduled->next->prev = channel->scheduled->prev; if (channel->scheduled->cancel) { - TAOS_UNUSED(taosArrayPush(cancelArray, &(SVATaskCancelInfo){ - .cancel = channel->scheduled->cancel, - .arg = channel->scheduled->arg, - })); + if (taosArrayPush(cancelArray, &(SVATaskCancelInfo){ + .cancel = channel->scheduled->cancel, + .arg = channel->scheduled->arg, + }) == NULL) { + vError("failed to push cancel info"); + } } vnodeAsyncTaskDone(async, channel->scheduled); } diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index 0bb16261dd..438083f9b9 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -91,7 +91,9 @@ static int32_t vnodeGetBufPoolToUse(SVnode *pVnode) { struct timeval tv; struct timespec ts; - (void)taosGetTimeOfDay(&tv); + if (taosGetTimeOfDay(&tv) != 0) { + continue; + } ts.tv_nsec = tv.tv_usec * 1000 + WAIT_TIME_MILI_SEC * 1000000; if (ts.tv_nsec > 999999999l) { ts.tv_sec = tv.tv_sec + 1; @@ -199,7 +201,9 @@ _exit: vInfo("vgId:%d, vnode info is saved, fname:%s replica:%d selfIndex:%d changeVersion:%d", pInfo->config.vgId, fname, pInfo->config.syncCfg.replicaNum, pInfo->config.syncCfg.myIndex, pInfo->config.syncCfg.changeVersion); } - (void)taosCloseFile(&pFile); + if (taosCloseFile(&pFile) != 0) { + vError("vgId:%d, failed to close file", pInfo->config.vgId); + } taosMemoryFree(data); return code; } @@ -261,7 +265,9 @@ _exit: } } taosMemoryFree(pData); - (void)taosCloseFile(&pFile); + if (taosCloseFile(&pFile) != 0) { + vError("vgId:%d, failed to close file", pInfo->config.vgId); + } return code; } @@ -494,7 +500,9 @@ void vnodeRollback(SVnode *pVnode) { offset = strlen(tFName); snprintf(tFName + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VND_INFO_FNAME_TMP); - TAOS_UNUSED(taosRemoveFile(tFName)); + if (taosRemoveFile(tFName) != 0) { + vError("vgId:%d, failed to remove file %s since %s", TD_VID(pVnode), tFName, tstrerror(terrno)); + } } static int vnodeEncodeState(const void *pObj, SJson *pJson) { diff --git a/source/dnode/vnode/src/vnd/vnodeHash.c b/source/dnode/vnode/src/vnd/vnodeHash.c index 878f226309..e0faa05c78 100644 --- a/source/dnode/vnode/src/vnd/vnodeHash.c +++ b/source/dnode/vnode/src/vnd/vnodeHash.c @@ -24,10 +24,10 @@ struct SVHashEntry { void* obj; }; -static int32_t vHashRehash(SVHashTable* ht, uint32_t newNumBuckets) { +static void vHashRehash(SVHashTable* ht, uint32_t newNumBuckets) { SVHashEntry** newBuckets = (SVHashEntry**)taosMemoryCalloc(newNumBuckets, sizeof(SVHashEntry*)); if (newBuckets == NULL) { - return terrno; + return; } for (int32_t i = 0; i < ht->numBuckets; i++) { @@ -45,7 +45,7 @@ static int32_t vHashRehash(SVHashTable* ht, uint32_t newNumBuckets) { ht->buckets = newBuckets; ht->numBuckets = newNumBuckets; - return 0; + return; } int32_t vHashInit(SVHashTable** ht, uint32_t (*hash)(const void*), int32_t (*compare)(const void*, const void*)) { @@ -96,7 +96,7 @@ int32_t vHashPut(SVHashTable* ht, void* obj) { } if (ht->numEntries >= ht->numBuckets) { - (void)vHashRehash(ht, ht->numBuckets * 2); + vHashRehash(ht, ht->numBuckets * 2); bucketIndex = ht->hash(obj) % ht->numBuckets; } @@ -142,7 +142,7 @@ int32_t vHashDrop(SVHashTable* ht, const void* obj) { taosMemoryFree(tmp); ht->numEntries--; if (ht->numBuckets > VNODE_HASH_DEFAULT_NUM_BUCKETS && ht->numEntries < ht->numBuckets / 4) { - (void)vHashRehash(ht, ht->numBuckets / 2); + vHashRehash(ht, ht->numBuckets / 2); } return 0; } diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index 1f54fea27c..b857cdeb42 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -108,7 +108,7 @@ int32_t vnodeAlterReplica(const char *path, SAlterVnodeReplicaReq *pReq, int32_t pNode->nodePort = pReq->replicas[i].port; tstrncpy(pNode->nodeFqdn, pReq->replicas[i].fqdn, sizeof(pNode->nodeFqdn)); pNode->nodeRole = TAOS_SYNC_ROLE_VOTER; - (void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); + bool ret = tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); vInfo("vgId:%d, replica:%d ep:%s:%u dnode:%d", pReq->vgId, i, pNode->nodeFqdn, pNode->nodePort, pNode->nodeId); pCfg->replicaNum++; } @@ -121,7 +121,7 @@ int32_t vnodeAlterReplica(const char *path, SAlterVnodeReplicaReq *pReq, int32_t pNode->nodePort = pReq->learnerReplicas[pCfg->totalReplicaNum].port; pNode->nodeRole = TAOS_SYNC_ROLE_LEARNER; tstrncpy(pNode->nodeFqdn, pReq->learnerReplicas[pCfg->totalReplicaNum].fqdn, sizeof(pNode->nodeFqdn)); - (void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); + bool ret = tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); vInfo("vgId:%d, replica:%d ep:%s:%u dnode:%d", pReq->vgId, i, pNode->nodeFqdn, pNode->nodePort, pNode->nodeId); pCfg->totalReplicaNum++; } @@ -176,8 +176,10 @@ int32_t vnodeRenameVgroupId(const char *srcPath, const char *dstPath, int32_t sr int32_t prefixLen = strlen(tsdbFilePrefix); STfsDir *tsdbDir = NULL; - (void)tfsOpendir(pTfs, tsdbPath, &tsdbDir); - if (tsdbDir == NULL) return 0; + int32_t tret = tfsOpendir(pTfs, tsdbPath, &tsdbDir); + if (tsdbDir == NULL) { + return 0; + } while (1) { const STfsFile *tsdbFile = tfsReaddir(tsdbDir); @@ -248,7 +250,7 @@ int32_t vnodeAlterHashRange(const char *srcPath, const char *dstPath, SAlterVnod SNodeInfo *pNode = &pCfg->nodeInfo[0]; pNode->nodePort = tsServerPort; tstrncpy(pNode->nodeFqdn, tsLocalFqdn, TSDB_FQDN_LEN); - (void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); + bool ret1 = tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); vInfo("vgId:%d, ep:%s:%u dnode:%d", pReq->srcVgId, pNode->nodeFqdn, pNode->nodePort, pNode->nodeId); info.config.syncCfg = *pCfg; @@ -317,7 +319,9 @@ int32_t vnodeRestoreVgroupId(const char *srcPath, const char *dstPath, int32_t s void vnodeDestroy(int32_t vgId, const char *path, STfs *pTfs, int32_t nodeId) { vInfo("path:%s is removed while destroy vnode", path); - (void)tfsRmdir(pTfs, path); + if (tfsRmdir(pTfs, path) < 0) { + vError("failed to remove path:%s since %s", path, tstrerror(terrno)); + } // int32_t nlevel = tfsGetLevel(pTfs); if (nodeId > 0 && vgId > 0 /*&& nlevel > 1*/ && tsS3Enabled) { @@ -378,8 +382,13 @@ SVnode *vnodeOpen(const char *path, int32_t diskPrimary, STfs *pTfs, SMsgCb msgC } if (updated) { vInfo("vgId:%d, save vnode info since dnode info changed", info.config.vgId); - (void)vnodeSaveInfo(dir, &info); - (void)vnodeCommitInfo(dir); + if (vnodeSaveInfo(dir, &info) < 0) { + vError("vgId:%d, failed to save vnode info since %s", info.config.vgId, tstrerror(terrno)); + } + + if (vnodeCommitInfo(dir) < 0) { + vError("vgId:%d, failed to commit vnode info since %s", info.config.vgId, tstrerror(terrno)); + } } // create handle @@ -405,7 +414,10 @@ SVnode *vnodeOpen(const char *path, int32_t diskPrimary, STfs *pTfs, SMsgCb msgC pVnode->blocked = false; pVnode->disableWrite = false; - (void)tsem_init(&pVnode->syncSem, 0, 0); + if (tsem_init(&pVnode->syncSem, 0, 0) != 0) { + vError("vgId:%d, failed to init semaphore", TD_VID(pVnode)); + goto _err; + } (void)taosThreadMutexInit(&pVnode->mutex, NULL); (void)taosThreadCondInit(&pVnode->poolNotEmpty, NULL); @@ -499,9 +511,9 @@ _err: if (pVnode->pQuery) vnodeQueryClose(pVnode); if (pVnode->pTq) tqClose(pVnode->pTq); if (pVnode->pWal) walClose(pVnode->pWal); - if (pVnode->pTsdb) (void)tsdbClose(&pVnode->pTsdb); - if (pVnode->pSma) (void)smaClose(pVnode->pSma); - if (pVnode->pMeta) (void)metaClose(&pVnode->pMeta); + if (pVnode->pTsdb) tsdbClose(&pVnode->pTsdb); + if (pVnode->pSma) smaClose(pVnode->pSma); + if (pVnode->pMeta) metaClose(&pVnode->pMeta); if (pVnode->freeList) vnodeCloseBufPool(pVnode); taosMemoryFree(pVnode); @@ -518,13 +530,16 @@ void vnodePostClose(SVnode *pVnode) { vnodeSyncPostClose(pVnode); } void vnodeClose(SVnode *pVnode) { if (pVnode) { vnodeAWait(&pVnode->commitTask); - (void)vnodeAChannelDestroy(&pVnode->commitChannel, true); + if (vnodeAChannelDestroy(&pVnode->commitChannel, true) != 0) { + vError("vgId:%d, failed to destroy commit channel", TD_VID(pVnode)); + } + vnodeSyncClose(pVnode); vnodeQueryClose(pVnode); tqClose(pVnode->pTq); walClose(pVnode->pWal); if (pVnode->pTsdb) tsdbClose(&pVnode->pTsdb); - (void)smaClose(pVnode->pSma); + smaClose(pVnode->pSma); if (pVnode->pMeta) metaClose(&pVnode->pMeta); vnodeCloseBufPool(pVnode); diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 8c31b38d00..d616bfd4ce 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -55,6 +55,7 @@ int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) { SMetaReader mer1 = {0}; SMetaReader mer2 = {0}; char tableFName[TSDB_TABLE_FNAME_LEN]; + bool reqTbUid = false; SRpcMsg rpcMsg = {0}; int32_t code = 0; int32_t rspLen = 0; @@ -68,20 +69,33 @@ int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) { goto _exit4; } + if (infoReq.option == REQ_OPT_TBUID) reqTbUid = true; metaRsp.dbId = pVnode->config.dbId; (void)strcpy(metaRsp.tbName, infoReq.tbName); (void)memcpy(metaRsp.dbFName, infoReq.dbFName, sizeof(metaRsp.dbFName)); - (void)sprintf(tableFName, "%s.%s", infoReq.dbFName, infoReq.tbName); - code = vnodeValidateTableHash(pVnode, tableFName); - if (code) { - goto _exit4; + if (!reqTbUid) { + TAOS_UNUSED(sprintf(tableFName, "%s.%s", infoReq.dbFName, infoReq.tbName)); + code = vnodeValidateTableHash(pVnode, tableFName); + if (code) { + goto _exit4; + } } // query meta metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK); - - if (metaGetTableEntryByName(&mer1, infoReq.tbName) < 0) { + if (reqTbUid) { + errno = 0; + uint64_t tbUid = taosStr2UInt64(infoReq.tbName, NULL, 10); + if (errno == ERANGE || tbUid == 0) { + code = TSDB_CODE_TDB_TABLE_NOT_EXIST; + goto _exit3; + } + char tbName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0}; + TAOS_CHECK_GOTO(metaGetTableNameByUid(pVnode, tbUid, tbName), NULL, _exit3); + tstrncpy(metaRsp.tbName, varDataVal(tbName), TSDB_TABLE_NAME_LEN); + TAOS_CHECK_GOTO(metaGetTableEntryByName(&mer1, varDataVal(tbName)), NULL, _exit3); + } else if (metaGetTableEntryByName(&mer1, infoReq.tbName) < 0) { code = terrno; goto _exit3; } @@ -107,7 +121,7 @@ int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) { schema = mer1.me.ntbEntry.schemaRow; } else { vError("vnodeGetTableMeta get invalid table type:%d", mer1.me.type); - return TSDB_CODE_APP_ERROR; + goto _exit3; } metaRsp.numOfTags = schemaTag.nCols; @@ -175,7 +189,7 @@ _exit4: rpcMsg.msgType = pMsg->msgType; if (code) { - qError("get table %s meta failed cause of %s", infoReq.tbName, tstrerror(code)); + qError("get table %s meta with %" PRIu8 " failed cause of %s", infoReq.tbName, infoReq.option, tstrerror(code)); } if (direct) { @@ -400,6 +414,12 @@ int32_t vnodeGetBatchMeta(SVnode *pVnode, SRpcMsg *pMsg) { qWarn("vnodeGetBatchMeta failed, msgType:%d", req->msgType); } break; + case TDMT_VND_TABLE_NAME: + // error code has been set into reqMsg, no need to handle it here. + if (TSDB_CODE_SUCCESS != vnodeGetTableMeta(pVnode, &reqMsg, false)) { + qWarn("vnodeGetBatchName failed, msgType:%d", req->msgType); + } + break; case TDMT_VND_TABLE_CFG: // error code has been set into reqMsg, no need to handle it here. if (TSDB_CODE_SUCCESS != vnodeGetTableCfg(pVnode, &reqMsg, false)) { diff --git a/source/dnode/vnode/src/vnd/vnodeSnapshot.c b/source/dnode/vnode/src/vnd/vnodeSnapshot.c index 74b893d256..0c11083367 100644 --- a/source/dnode/vnode/src/vnd/vnodeSnapshot.c +++ b/source/dnode/vnode/src/vnd/vnodeSnapshot.c @@ -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) { @@ -274,13 +274,17 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData) int64_t size; code = taosFStatFile(pFile, &size, NULL); if (code != 0) { - (void)taosCloseFile(&pFile); + if (taosCloseFile(&pFile) != 0) { + vError("vgId:%d, failed to close file", vgId); + } TSDB_CHECK_CODE(code, lino, _exit); } *ppData = taosMemoryMalloc(sizeof(SSnapDataHdr) + size + 1); if (*ppData == NULL) { - (void)taosCloseFile(&pFile); + if (taosCloseFile(&pFile) != 0) { + vError("vgId:%d, failed to close file", vgId); + } TSDB_CHECK_CODE(code = terrno, lino, _exit); } ((SSnapDataHdr *)(*ppData))->type = SNAP_DATA_CFG; @@ -289,11 +293,15 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData) if (taosReadFile(pFile, ((SSnapDataHdr *)(*ppData))->data, size) < 0) { taosMemoryFree(*ppData); - (void)taosCloseFile(&pFile); + if (taosCloseFile(&pFile) != 0) { + vError("vgId:%d, failed to close file", vgId); + } TSDB_CHECK_CODE(code = terrno, lino, _exit); } - (void)taosCloseFile(&pFile); + if (taosCloseFile(&pFile) != 0) { + vError("vgId:%d, failed to close file", vgId); + } pReader->cfgDone = 1; goto _exit; @@ -333,8 +341,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 +358,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 +469,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 +595,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 +618,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 +668,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 +753,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 +767,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; } diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index af6f0024f3..c80e326dfc 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -466,7 +466,11 @@ static int32_t vnodePreProcessArbCheckSyncMsg(SVnode *pVnode, SRpcMsg *pMsg) { return TSDB_CODE_INVALID_MSG; } - (void)vnodePreCheckAssignedLogSyncd(pVnode, syncReq.member0Token, syncReq.member1Token); + int32_t ret = vnodePreCheckAssignedLogSyncd(pVnode, syncReq.member0Token, syncReq.member1Token); + if (ret != 0) { + vError("vgId:%d, failed to preprocess arb check sync request since %s", TD_VID(pVnode), tstrerror(ret)); + } + int32_t code = terrno; tFreeSVArbCheckSyncReq(&syncReq); @@ -708,7 +712,7 @@ int32_t vnodeProcessWriteMsg(SVnode *pVnode, SRpcMsg *pMsg, int64_t ver, SRpcMsg vTrace("vgId:%d, process %s request, code:0x%x index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), pRsp->code, ver); - (void)walApplyVer(pVnode->pWal, ver); + walApplyVer(pVnode->pWal, ver); code = tqPushMsg(pVnode->pTq, pMsg->msgType); if (code) { @@ -784,7 +788,7 @@ int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { vTrace("vgId:%d, msg:%p in fetch queue is processing", pVnode->config.vgId, pMsg); if ((pMsg->msgType == TDMT_SCH_FETCH || pMsg->msgType == TDMT_VND_TABLE_META || pMsg->msgType == TDMT_VND_TABLE_CFG || - pMsg->msgType == TDMT_VND_BATCH_META) && + pMsg->msgType == TDMT_VND_BATCH_META || pMsg->msgType == TDMT_VND_TABLE_NAME) && !syncIsReadyForRead(pVnode->sync)) { vnodeRedirectRpcMsg(pVnode, pMsg, terrno); return 0; @@ -805,6 +809,7 @@ int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) { case TDMT_SCH_QUERY_HEARTBEAT: return qWorkerProcessHbMsg(pVnode, pVnode->pQuery, pMsg, 0); case TDMT_VND_TABLE_META: + case TDMT_VND_TABLE_NAME: return vnodeGetTableMeta(pVnode, pMsg, true); case TDMT_VND_TABLE_CFG: return vnodeGetTableCfg(pVnode, pMsg, true); @@ -878,7 +883,10 @@ int32_t vnodeProcessStreamMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo) } void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) { - (void)tdProcessTSmaInsert(((SVnode *)pVnode)->pSma, smaId, (const char *)data); + int32_t code = tdProcessTSmaInsert(((SVnode *)pVnode)->pSma, smaId, (const char *)data); + if (code) { + vError("failed to process sma result since %s", tstrerror(code)); + } } void vnodeUpdateMetaRsp(SVnode *pVnode, STableMetaRsp *pMetaRsp) { @@ -954,7 +962,10 @@ static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t code = metaDropTables(pVnode->pMeta, ttlReq.pTbUids); if (code) return code; - (void)tqUpdateTbUidList(pVnode->pTq, ttlReq.pTbUids, false); + code = tqUpdateTbUidList(pVnode->pTq, ttlReq.pTbUids, false); + if (code) { + vError("vgId:%d, failed to update tbUid list since %s", TD_VID(pVnode), tstrerror(code)); + } } end: @@ -1157,7 +1168,9 @@ static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq, } } else { cRsp.code = TSDB_CODE_SUCCESS; - (void)tdFetchTbUidList(pVnode->pSma, &pStore, pCreateReq->ctb.suid, pCreateReq->uid); + if (tdFetchTbUidList(pVnode->pSma, &pStore, pCreateReq->ctb.suid, pCreateReq->uid) < 0) { + vError("vgId:%d, failed to fetch tbUid list", TD_VID(pVnode)); + } if (taosArrayPush(tbUids, &pCreateReq->uid) == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; rcode = -1; @@ -1174,11 +1187,13 @@ static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq, } vDebug("vgId:%d, add %d new created tables into query table list", TD_VID(pVnode), (int32_t)taosArrayGetSize(tbUids)); - (void)tqUpdateTbUidList(pVnode->pTq, tbUids, true); + if (tqUpdateTbUidList(pVnode->pTq, tbUids, true) < 0) { + vError("vgId:%d, failed to update tbUid list since %s", TD_VID(pVnode), tstrerror(terrno)); + } if (tdUpdateTbUidList(pVnode->pSma, pStore, true) < 0) { goto _exit; } - (void)tdUidStoreFree(pStore); + pStore = tdUidStoreFree(pStore); // prepare rsp int32_t ret = 0; @@ -1190,7 +1205,9 @@ static int32_t vnodeProcessCreateTbReq(SVnode *pVnode, int64_t ver, void *pReq, goto _exit; } tEncoderInit(&encoder, pRsp->pCont, pRsp->contLen); - (void)tEncodeSVCreateTbBatchRsp(&encoder, &rsp); + if (tEncodeSVCreateTbBatchRsp(&encoder, &rsp) != 0) { + vError("vgId:%d, failed to encode create table batch response", TD_VID(pVnode)); + } if (tsEnableAudit && tsEnableAuditCreateTable) { int64_t clusterId = pVnode->config.syncCfg.nodeInfo[0].clusterId; @@ -1344,7 +1361,9 @@ _exit: tEncodeSize(tEncodeSVAlterTbRsp, &vAlterTbRsp, pRsp->contLen, ret); pRsp->pCont = rpcMallocCont(pRsp->contLen); tEncoderInit(&ec, pRsp->pCont, pRsp->contLen); - (void)tEncodeSVAlterTbRsp(&ec, &vAlterTbRsp); + if (tEncodeSVAlterTbRsp(&ec, &vAlterTbRsp) != 0) { + vError("vgId:%d, failed to encode alter table response", TD_VID(pVnode)); + } tEncoderClear(&ec); if (vMetaRsp.pSchemas) { taosMemoryFree(vMetaRsp.pSchemas); @@ -1399,7 +1418,11 @@ static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t ver, void *pReq, in } } else { dropTbRsp.code = TSDB_CODE_SUCCESS; - if (tbUid > 0) (void)tdFetchTbUidList(pVnode->pSma, &pStore, pDropTbReq->suid, tbUid); + if (tbUid > 0) { + if (tdFetchTbUidList(pVnode->pSma, &pStore, pDropTbReq->suid, tbUid) < 0) { + vError("vgId:%d, failed to fetch tbUid list", TD_VID(pVnode)); + } + } } if (taosArrayPush(rsp.pArray, &dropTbRsp) == NULL) { @@ -1423,14 +1446,21 @@ static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t ver, void *pReq, in } } - (void)tqUpdateTbUidList(pVnode->pTq, tbUids, false); - (void)tdUpdateTbUidList(pVnode->pSma, pStore, false); + if (tqUpdateTbUidList(pVnode->pTq, tbUids, false) < 0) { + vError("vgId:%d, failed to update tbUid list since %s", TD_VID(pVnode), tstrerror(terrno)); + } + + if (tdUpdateTbUidList(pVnode->pSma, pStore, false) < 0) { + goto _exit; + } if (tsEnableAuditCreateTable) { int64_t clusterId = pVnode->config.syncCfg.nodeInfo[0].clusterId; SName name = {0}; - (void)tNameFromString(&name, pVnode->config.dbname, T_NAME_ACCT | T_NAME_DB); + if (tNameFromString(&name, pVnode->config.dbname, T_NAME_ACCT | T_NAME_DB) != 0) { + vError("vgId:%d, failed to get name from string", TD_VID(pVnode)); + } SStringBuilder sb = {0}; for (int32_t iReq = 0; iReq < req.nReqs; iReq++) { @@ -1454,12 +1484,14 @@ static int32_t vnodeProcessDropTbReq(SVnode *pVnode, int64_t ver, void *pReq, in _exit: taosArrayDestroy(tbUids); - (void)tdUidStoreFree(pStore); + pStore = tdUidStoreFree(pStore); tDecoderClear(&decoder); tEncodeSize(tEncodeSVDropTbBatchRsp, &rsp, pRsp->contLen, ret); pRsp->pCont = rpcMallocCont(pRsp->contLen); tEncoderInit(&encoder, pRsp->pCont, pRsp->contLen); - (void)tEncodeSVDropTbBatchRsp(&encoder, &rsp); + if (tEncodeSVDropTbBatchRsp(&encoder, &rsp) != 0) { + vError("vgId:%d, failed to encode drop table batch response", TD_VID(pVnode)); + } tEncoderClear(&encoder); taosArrayDestroy(rsp.pArray); taosArrayDestroy(tbNames); @@ -1799,7 +1831,9 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t ver, void *pReq, in } if (info.suid) { - (void)metaGetInfo(pVnode->pMeta, info.suid, &info, NULL); + if (metaGetInfo(pVnode->pMeta, info.suid, &info, NULL) != 0) { + vWarn("vgId:%d, table uid:%" PRId64 " not exists", TD_VID(pVnode), info.suid); + } } if (pSubmitTbData->sver != info.skmVer) { @@ -1895,7 +1929,9 @@ static int32_t vnodeProcessSubmitReq(SVnode *pVnode, int64_t ver, void *pReq, in if (taosArrayGetSize(newTbUids) > 0) { vDebug("vgId:%d, add %d table into query table list in handling submit", TD_VID(pVnode), (int32_t)taosArrayGetSize(newTbUids)); - (void)tqUpdateTbUidList(pVnode->pTq, newTbUids, true); + if (tqUpdateTbUidList(pVnode->pTq, newTbUids, true) != 0) { + vError("vgId:%d, failed to update tbUid list", TD_VID(pVnode)); + } } _exit: @@ -1921,7 +1957,7 @@ _exit: pVnode->monitor.strVgId, pOriginalMsg->info.conn.user, "Success"}; - (void)taos_counter_add(tsInsertCounter, pSubmitRsp->affectedRows, sample_labels); + int tv = taos_counter_add(tsInsertCounter, pSubmitRsp->affectedRows, sample_labels); } if (code == 0) { @@ -2146,7 +2182,12 @@ static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t ver, void *pRe pVnode->config.sttTrigger = req.sttTrigger; } else { vnodeAWait(&pVnode->commitTask); - (void)tsdbDisableAndCancelAllBgTask(pVnode->pTsdb); + + int32_t ret = tsdbDisableAndCancelAllBgTask(pVnode->pTsdb); + if (ret != 0) { + vError("vgId:%d, failed to disable bg task since %s", TD_VID(pVnode), tstrerror(errno)); + } + pVnode->config.sttTrigger = req.sttTrigger; tsdbEnableBgTask(pVnode->pTsdb); } @@ -2164,7 +2205,9 @@ static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t ver, void *pRe } if (walChanged) { - (void)walAlter(pVnode->pWal, &pVnode->config.walCfg); + if (walAlter(pVnode->pWal, &pVnode->config.walCfg) != 0) { + vError("vgId:%d, failed to alter wal config since %s", TD_VID(pVnode), tstrerror(errno)); + } } if (tsdbChanged) { @@ -2348,7 +2391,9 @@ static int32_t vnodeProcessCompactVnodeReq(SVnode *pVnode, int64_t ver, void *pR } static int32_t vnodeProcessConfigChangeReq(SVnode *pVnode, int64_t ver, void *pReq, int32_t len, SRpcMsg *pRsp) { - (void)syncCheckMember(pVnode->sync); + if (syncCheckMember(pVnode->sync) != 0) { + vError("vgId:%d, failed to check member", TD_VID(pVnode)); + } pRsp->msgType = TDMT_SYNC_CONFIG_CHANGE_RSP; pRsp->code = TSDB_CODE_SUCCESS; @@ -2408,7 +2453,9 @@ static int32_t vnodeProcessArbCheckSyncReq(SVnode *pVnode, void *pReq, int32_t l syncRsp.member1Token = syncReq.member1Token; syncRsp.vgId = TD_VID(pVnode); - (void)vnodeCheckAssignedLogSyncd(pVnode, syncReq.member0Token, syncReq.member1Token); + if (vnodeCheckAssignedLogSyncd(pVnode, syncReq.member0Token, syncReq.member1Token) != 0) { + vError("vgId:%d, failed to check assigned log syncd", TD_VID(pVnode)); + } syncRsp.errCode = terrno; if (vnodeUpdateArbTerm(pVnode, syncReq.arbTerm) != 0) { diff --git a/source/dnode/vnode/src/vnd/vnodeSync.c b/source/dnode/vnode/src/vnd/vnodeSync.c index f725fb3809..5f4628eb87 100644 --- a/source/dnode/vnode/src/vnd/vnodeSync.c +++ b/source/dnode/vnode/src/vnd/vnodeSync.c @@ -28,7 +28,9 @@ static inline void vnodeWaitBlockMsg(SVnode *pVnode, const SRpcMsg *pMsg) { const STraceId *trace = &pMsg->info.traceId; vGTrace("vgId:%d, msg:%p wait block, type:%s sec:%d seq:%" PRId64, pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType), pVnode->blockSec, pVnode->blockSeq); - (void)tsem_wait(&pVnode->syncSem); + if (tsem_wait(&pVnode->syncSem) != 0) { + vError("vgId:%d, failed to wait sem", pVnode->config.vgId); + } } static inline void vnodePostBlockMsg(SVnode *pVnode, const SRpcMsg *pMsg) { @@ -41,7 +43,9 @@ static inline void vnodePostBlockMsg(SVnode *pVnode, const SRpcMsg *pMsg) { pVnode->blocked = false; pVnode->blockSec = 0; pVnode->blockSeq = 0; - (void)tsem_post(&pVnode->syncSem); + if (tsem_post(&pVnode->syncSem) != 0) { + vError("vgId:%d, failed to post sem", pVnode->config.vgId); + } } (void)taosThreadMutexUnlock(&pVnode->lock); } @@ -69,7 +73,9 @@ void vnodeRedirectRpcMsg(SVnode *pVnode, SRpcMsg *pMsg, int32_t code) { if (rsp.pCont == NULL) { pMsg->code = TSDB_CODE_OUT_OF_MEMORY; } else { - (void)tSerializeSEpSet(rsp.pCont, contLen, &newEpSet); + if (tSerializeSEpSet(rsp.pCont, contLen, &newEpSet) != 0) { + vError("vgId:%d, failed to serialize ep set", pVnode->config.vgId); + } rsp.contLen = contLen; } @@ -163,7 +169,9 @@ void vnodeProposeCommitOnNeed(SVnode *pVnode, bool atExit) { rpcFreeCont(rpcMsg.pCont); rpcMsg.pCont = NULL; } else { - (void)tmsgPutToQueue(&pVnode->msgCb, WRITE_QUEUE, &rpcMsg); + if (tmsgPutToQueue(&pVnode->msgCb, WRITE_QUEUE, &rpcMsg) < 0) { + vTrace("vgId:%d, failed to put vnode commit to queue since %s", pVnode->config.vgId, terrstr()); + } } } @@ -560,7 +568,7 @@ static void vnodeRestoreFinish(const SSyncFSM *pFsm, const SyncIndex commitIdx) } } while (true); - (void)walApplyVer(pVnode->pWal, commitIdx); + walApplyVer(pVnode->pWal, commitIdx); pVnode->restored = true; SStreamMeta *pMeta = pVnode->pTq->pStreamMeta; @@ -609,13 +617,17 @@ static void vnodeBecomeFollower(const SSyncFSM *pFsm) { if (pVnode->blocked) { pVnode->blocked = false; vDebug("vgId:%d, become follower and post block", pVnode->config.vgId); - (void)tsem_post(&pVnode->syncSem); + if (tsem_post(&pVnode->syncSem) != 0) { + vError("vgId:%d, failed to post sync semaphore", pVnode->config.vgId); + } } (void)taosThreadMutexUnlock(&pVnode->lock); if (pVnode->pTq) { tqUpdateNodeStage(pVnode->pTq, false); - (void)tqStopStreamTasksAsync(pVnode->pTq); + if (tqStopStreamTasksAsync(pVnode->pTq) != 0) { + vError("vgId:%d, failed to stop stream tasks", pVnode->config.vgId); + } } } @@ -627,7 +639,9 @@ static void vnodeBecomeLearner(const SSyncFSM *pFsm) { if (pVnode->blocked) { pVnode->blocked = false; vDebug("vgId:%d, become learner and post block", pVnode->config.vgId); - (void)tsem_post(&pVnode->syncSem); + if (tsem_post(&pVnode->syncSem) != 0) { + vError("vgId:%d, failed to post sync semaphore", pVnode->config.vgId); + } } (void)taosThreadMutexUnlock(&pVnode->lock); } @@ -750,14 +764,19 @@ int32_t vnodeSyncStart(SVnode *pVnode) { void vnodeSyncPreClose(SVnode *pVnode) { vInfo("vgId:%d, sync pre close", pVnode->config.vgId); - (void)syncLeaderTransfer(pVnode->sync); + int32_t code = syncLeaderTransfer(pVnode->sync); + if (code) { + vError("vgId:%d, failed to transfer leader since %s", pVnode->config.vgId, tstrerror(code)); + } syncPreStop(pVnode->sync); (void)taosThreadMutexLock(&pVnode->lock); if (pVnode->blocked) { vInfo("vgId:%d, post block after close sync", pVnode->config.vgId); pVnode->blocked = false; - (void)tsem_post(&pVnode->syncSem); + if (tsem_post(&pVnode->syncSem) != 0) { + vError("vgId:%d, failed to post block", pVnode->config.vgId); + } } (void)taosThreadMutexUnlock(&pVnode->lock); } @@ -792,7 +811,9 @@ void vnodeSyncCheckTimeout(SVnode *pVnode) { pVnode->blocked = false; pVnode->blockSec = 0; pVnode->blockSeq = 0; - (void)tsem_post(&pVnode->syncSem); + if (tsem_post(&pVnode->syncSem) != 0) { + vError("vgId:%d, failed to post block", pVnode->config.vgId); + } } } (void)taosThreadMutexUnlock(&pVnode->lock); diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index 380e5224e1..0882db52a6 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -132,6 +132,7 @@ typedef enum { CTG_TASK_GET_VIEW, CTG_TASK_GET_TB_TSMA, CTG_TASK_GET_TSMA, + CTG_TASK_GET_TB_NAME, } CTG_TASK_TYPE; typedef enum { @@ -205,6 +206,14 @@ typedef struct SCtgTbMetasCtx { SArray* pFetchs; } SCtgTbMetasCtx; +typedef struct SCtgTbNamesCtx { + int32_t fetchNum; + SRWLatch lock; + SArray* pNames; + SArray* pResList; + SArray* pFetchs; +} SCtgTbNamesCtx; + typedef struct SCtgTbIndexCtx { SName* pName; } SCtgTbIndexCtx; @@ -421,6 +430,7 @@ typedef struct SCtgJob { int32_t viewNum; int32_t tbTsmaNum; int32_t tsmaNum; // currently, only 1 is possible + int32_t tbNameNum; } SCtgJob; typedef struct SCtgMsgCtx { @@ -797,7 +807,8 @@ typedef struct SCtgCacheItemInfo { #define CTG_IS_BATCH_TASK(_taskType) \ ((CTG_TASK_GET_TB_META_BATCH == (_taskType)) || (CTG_TASK_GET_TB_HASH_BATCH == (_taskType)) || \ - (CTG_TASK_GET_VIEW == (_taskType)) || (CTG_TASK_GET_TB_TSMA == (_taskType))) + (CTG_TASK_GET_VIEW == (_taskType)) || (CTG_TASK_GET_TB_TSMA == (_taskType)) || \ + (CTG_TASK_GET_TB_NAME == (_taskType))) #define CTG_GET_TASK_MSGCTX(_task, _id) \ (CTG_IS_BATCH_TASK((_task)->type) ? taosArrayGet((_task)->msgCtxs, (_id)) : &(_task)->msgCtx) @@ -996,6 +1007,8 @@ int32_t ctgRemoveTbMetaFromCache(SCatalog* pCtg, SName* pTableName, bool syncReq int32_t ctgGetTbMetaFromCache(SCatalog* pCtg, SCtgTbMetaCtx* ctx, STableMeta** pTableMeta); int32_t ctgGetTbMetasFromCache(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgTbMetasCtx* ctx, int32_t dbIdx, int32_t* fetchIdx, int32_t baseResIdx, SArray* pList); +int32_t ctgGetTbNamesFromCache(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgTbNamesCtx* ctx, int32_t dbIdx, + int32_t* fetchIdx, int32_t baseResIdx, SArray* pList); int32_t ctgCloneDbCfgInfo(void* pSrc, SDbCfgInfo** ppDst); int32_t ctgOpUpdateVgroup(SCtgCacheOperation* action); diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 619f4bc114..0ea1d98312 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -1461,7 +1461,7 @@ int32_t catalogGetAllMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SCatalo pRsp->pTableMeta = taosArrayInit(tbNum, POINTER_BYTES); if (NULL == pRsp->pTableMeta) { ctgError("taosArrayInit %d failed", tbNum); - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } for (int32_t i = 0; i < tbNum; ++i) { @@ -1476,7 +1476,7 @@ int32_t catalogGetAllMeta(SCatalog* pCtg, SRequestConnInfo* pConn, const SCatalo if (NULL == taosArrayPush(pRsp->pTableMeta, &pTableMeta)) { ctgError("taosArrayPush failed, idx:%d", i); taosMemoryFreeClear(pTableMeta); - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } } } diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c index c1cb6f8f44..46f4f86484 100644 --- a/source/libs/catalog/src/ctgAsync.c +++ b/source/libs/catalog/src/ctgAsync.c @@ -588,6 +588,35 @@ int32_t ctgInitGetTSMATask(SCtgJob* pJob, int32_t taskId, void* param) { return TSDB_CODE_SUCCESS; } +static int32_t ctgInitGetTbNamesTask(SCtgJob* pJob, int32_t taskId, void* param) { + SCtgTask task = {0}; + task.type = CTG_TASK_GET_TB_NAME; + task.taskId = taskId; + task.pJob = pJob; + + SCtgTbNamesCtx* pTaskCtx = taosMemoryCalloc(1, sizeof(SCtgTbNamesCtx)); + if (NULL == pTaskCtx) { + CTG_ERR_RET(terrno); + } + task.taskCtx = pTaskCtx; + taosInitRWLatch(&pTaskCtx->lock); + pTaskCtx->pNames = param; + pTaskCtx->pResList = taosArrayInit(pJob->tbNameNum, sizeof(SMetaRes)); + if (NULL == pTaskCtx->pResList) { + qError("qid:0x%" PRIx64 " taosArrayInit %d SMetaRes %d failed", pJob->queryId, pJob->tbNameNum, + (int32_t)sizeof(SMetaRes)); + ctgFreeTask(&task, true); + CTG_ERR_RET(terrno); + } + + if (NULL == taosArrayPush(pJob->pTasks, &task)) { + ctgFreeTask(&task, true); + CTG_ERR_RET(terrno); + } + + return TSDB_CODE_SUCCESS; +} + int32_t ctgHandleForceUpdateView(SCatalog* pCtg, const SCatalogReq* pReq) { int32_t viewNum = taosArrayGetSize(pReq->pView); for (int32_t i = 0; i < viewNum; ++i) { @@ -822,9 +851,10 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const int32_t viewNum = (int32_t)ctgGetTablesReqNum(pReq->pView); int32_t tbTsmaNum = (int32_t)taosArrayGetSize(pReq->pTableTSMAs); int32_t tsmaNum = (int32_t)taosArrayGetSize(pReq->pTSMAs); + int32_t tbNameNum = (int32_t)ctgGetTablesReqNum(pReq->pTableName); int32_t taskNum = tbMetaNum + dbVgNum + udfNum + tbHashNum + qnodeNum + dnodeNum + svrVerNum + dbCfgNum + indexNum + - userNum + dbInfoNum + tbIndexNum + tbCfgNum + tbTagNum + viewNum + tbTsmaNum; + userNum + dbInfoNum + tbIndexNum + tbCfgNum + tbTagNum + viewNum + tbTsmaNum + tbNameNum; *job = taosMemoryCalloc(1, sizeof(SCtgJob)); if (NULL == *job) { @@ -859,6 +889,7 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const pJob->viewNum = viewNum; pJob->tbTsmaNum = tbTsmaNum; pJob->tsmaNum = tsmaNum; + pJob->tbNameNum = tbNameNum; #if CTG_BATCH_FETCH pJob->pBatchs = @@ -991,6 +1022,9 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const if (tsmaNum > 0) { CTG_ERR_JRET(ctgInitTask(pJob, CTG_TASK_GET_TSMA, pReq->pTSMAs, NULL)); } + if (tbNameNum > 0) { + CTG_ERR_JRET(ctgInitTask(pJob, CTG_TASK_GET_TB_NAME, pReq->pTableName, NULL)); + } if (qnodeNum) { CTG_ERR_JRET(ctgInitTask(pJob, CTG_TASK_GET_QNODE, NULL, NULL)); } @@ -1059,6 +1093,18 @@ int32_t ctgDumpTbMetasRes(SCtgTask* pTask) { return TSDB_CODE_SUCCESS; } +static int32_t ctgDumpTbNamesRes(SCtgTask* pTask) { + if (pTask->subTask) { + return TSDB_CODE_SUCCESS; + } + + SCtgJob* pJob = pTask->pJob; + + pJob->jobRes.pTableMeta = pTask->res; + + return TSDB_CODE_SUCCESS; +} + int32_t ctgDumpDbVgRes(SCtgTask* pTask) { if (pTask->subTask) { return TSDB_CODE_SUCCESS; @@ -1858,6 +1904,201 @@ _return: CTG_RET(code); } +static int32_t ctgHandleGetTbNamesRsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBuf* pMsg, int32_t rspCode) { + int32_t code = 0; + SCtgDBCache* dbCache = NULL; + SCtgTask* pTask = tReq->pTask; + SCatalog* pCtg = pTask->pJob->pCtg; + SRequestConnInfo* pConn = &pTask->pJob->conn; + SCtgMsgCtx* pMsgCtx = CTG_GET_TASK_MSGCTX(pTask, tReq->msgIdx); + SCtgTbNamesCtx* ctx = (SCtgTbNamesCtx*)pTask->taskCtx; + bool taskDone = false; + bool lock = false; + + if (NULL == pMsgCtx) { + ctgError("fail to get task msgCtx, taskType:%d", pTask->type); + CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); + } + + SCtgFetch* pFetch = taosArrayGet(ctx->pFetchs, tReq->msgIdx); + if (NULL == pFetch) { + ctgError("fail to get the %dth fetch, fetchNum:%d", tReq->msgIdx, (int32_t)taosArrayGetSize(ctx->pFetchs)); + CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); + } + + int32_t flag = pFetch->flag; + int32_t* vgId = &pFetch->vgId; + SName* pName = NULL; + CTG_ERR_JRET(ctgGetFetchName(ctx->pNames, pFetch, &pName)); + + if (reqType == TDMT_VND_TABLE_NAME) { + taosWLockLatch(&ctx->lock); + lock = true; + } + + CTG_ERR_JRET(ctgProcessRspMsg(pMsgCtx->out, reqType, pMsg->pData, pMsg->len, rspCode, pMsgCtx->target)); + + switch (reqType) { + case TDMT_MND_USE_DB: { + SUseDbOutput* pOut = (SUseDbOutput*)pMsgCtx->out; + CTG_ERR_RET(ctgMakeVgArray(pOut->dbVgroup)); + SArray* pVgArray = NULL; + TSWAP(pVgArray, pOut->dbVgroup->vgArray); + int32_t vgSize = taosArrayGetSize(pVgArray); + if (0 == vgSize) { + taosArrayDestroy(pVgArray); + ctgTaskError("no vgroup got, dbName:%s", pName->dbname); + CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); + } + for (int32_t i = 0; i < vgSize; ++i) { + SVgroupInfo* vgInfo = TARRAY_GET_ELEM(pVgArray, i); + if (NULL == vgInfo) { + taosArrayDestroy(pVgArray); + ctgTaskError("fail to get the %dth vgInfo, vgSize:%d", i, vgSize); + CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); + } + ctgTaskDebug("will refresh tbmeta, not supposed to be stb, tbName:%s, flag:%d, vgId:%d", + tNameGetTableName(pName), flag, vgInfo->vgId); + // *vgId = vgInfo->vgId; + if (i > 0) atomic_add_fetch_32(&ctx->fetchNum, 1); + code = ctgGetTbMetaFromVnode(pCtg, pConn, pName, vgInfo, NULL, tReq); + if (code) { + taosArrayDestroy(pVgArray); + CTG_ERR_JRET(code); + } + } + taosArrayDestroy(pVgArray); + + return TSDB_CODE_SUCCESS; + } + case TDMT_MND_TABLE_META: { + STableMetaOutput* pOut = (STableMetaOutput*)pMsgCtx->out; + + if (CTG_IS_META_NULL(pOut->metaType)) { + if (CTG_FLAG_IS_STB(flag)) { + char dbFName[TSDB_DB_FNAME_LEN] = {0}; + (void)tNameGetFullDbName(pName, dbFName); + + CTG_ERR_RET(ctgAcquireVgInfoFromCache(pCtg, dbFName, &dbCache)); + if (NULL != dbCache) { + SVgroupInfo vgInfo = {0}; + CTG_ERR_JRET(ctgGetVgInfoFromHashValue(pCtg, &pConn->mgmtEps, dbCache->vgCache.vgInfo, pName, &vgInfo)); + + ctgTaskDebug("will refresh tbmeta, supposed to be stb, tbName:%s, flag:%d", tNameGetTableName(pName), flag); + + *vgId = vgInfo.vgId; + CTG_ERR_JRET(ctgGetTbMetaFromVnode(pCtg, pConn, pName, &vgInfo, NULL, tReq)); + + ctgReleaseVgInfoToCache(pCtg, dbCache); + dbCache = NULL; + } else { + SBuildUseDBInput input = {0}; + + tstrncpy(input.db, dbFName, tListLen(input.db)); + input.vgVersion = CTG_DEFAULT_INVALID_VERSION; + + CTG_ERR_JRET(ctgGetDBVgInfoFromMnode(pCtg, pConn, &input, NULL, tReq)); + } + + return TSDB_CODE_SUCCESS; + } + + ctgTaskError("no tbmeta got, tbName:%s", tNameGetTableName(pName)); + (void)ctgRemoveTbMetaFromCache(pCtg, pName, false); // cache update not fatal error + + CTG_ERR_JRET(CTG_ERR_CODE_TABLE_NOT_EXIST); + } + + if (pMsgCtx->lastOut) { + TSWAP(pMsgCtx->out, pMsgCtx->lastOut); + STableMetaOutput* pLastOut = (STableMetaOutput*)pMsgCtx->out; + TSWAP(pLastOut->tbMeta, pOut->tbMeta); + } + + break; + } + case TDMT_VND_TABLE_NAME: { + STableMetaOutput* pOut = (STableMetaOutput*)pMsgCtx->out; + + if (CTG_IS_META_NULL(pOut->metaType)) { + ctgTaskError("no tbmeta got, tbName:%s", tNameGetTableName(pName)); + CTG_ERR_JRET(CTG_ERR_CODE_TABLE_NOT_EXIST); + } + + break; + } + default: + ctgTaskError("invalid reqType %d", reqType); + CTG_ERR_JRET(TSDB_CODE_INVALID_MSG); + } + + STableMetaOutput* pOut = (STableMetaOutput*)pMsgCtx->out; + if (CTG_IS_META_BOTH(pOut->metaType)) { + TAOS_MEMCPY(pOut->tbMeta, &pOut->ctbMeta, sizeof(pOut->ctbMeta)); + } + + SMetaRes* pRes = taosArrayGet(ctx->pResList, pFetch->resIdx); + if (NULL == pRes) { + ctgTaskError("fail to get the %dth res in pResList, resNum:%d", pFetch->resIdx, + (int32_t)taosArrayGetSize(ctx->pResList)); + CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); + } + + if (!pRes->pRes) { + pRes->code = 0; + pRes->pRes = pOut->tbMeta; + pOut->tbMeta = NULL; + } else { + taosMemoryFreeClear(pOut->tbMeta); + } + + if (0 == atomic_sub_fetch_32(&ctx->fetchNum, 1)) { + TSWAP(pTask->res, ctx->pResList); + taskDone = true; + } + +_return: + if (dbCache) { + ctgReleaseVgInfoToCache(pCtg, dbCache); + } + + if (code) { + SMetaRes* pRes = taosArrayGet(ctx->pResList, pFetch->resIdx); + if (NULL == pRes) { + ctgTaskError("fail to get the %dth res in pResList, resNum:%d", pFetch->resIdx, + (int32_t)taosArrayGetSize(ctx->pResList)); + } else { + if (0 == atomic_sub_fetch_32(&ctx->fetchNum, 1)) { + TSWAP(pTask->res, ctx->pResList); + taskDone = true; + } + if (TDMT_VND_TABLE_NAME == reqType) { + if (!pRes->pRes && (0 == pRes->code)) pRes->code = code; + } else { + pRes->pRes = NULL; + pRes->code = code; + } + if (taskDone == true) { + ctgTaskError("Get table %d.%s.%s meta failed with error %s", pName->acctId, pName->dbname, pName->tname, + tstrerror(code)); + } + } + } + + if (pTask->res && taskDone) { + int32_t newCode = ctgHandleTaskEnd(pTask, code); + if (newCode && TSDB_CODE_SUCCESS == code) { + code = newCode; + } + } + + if (lock) { + taosWUnLockLatch(&ctx->lock); + } + + CTG_RET(code); +} + int32_t ctgHandleGetDbVgRsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBuf* pMsg, int32_t rspCode) { int32_t code = 0; SCtgTask* pTask = tReq->pTask; @@ -3730,6 +3971,70 @@ int32_t ctgLaunchGetTSMATask(SCtgTask* pTask) { return TSDB_CODE_SUCCESS; } +static int32_t ctgLaunchGetTbNamesTask(SCtgTask* pTask) { + SCatalog* pCtg = pTask->pJob->pCtg; + SRequestConnInfo* pConn = &pTask->pJob->conn; + SCtgTbNamesCtx* pCtx = (SCtgTbNamesCtx*)pTask->taskCtx; + SCtgJob* pJob = pTask->pJob; + SName* pName = NULL; + + int32_t dbNum = taosArrayGetSize(pCtx->pNames); + int32_t fetchIdx = 0; + int32_t baseResIdx = 0; + for (int32_t i = 0; i < dbNum; ++i) { + STablesReq* pReq = TARRAY_GET_ELEM(pCtx->pNames, i); + if (NULL == pReq) { + ctgError("fail to get the %dth STablesReq, num:%d", i, dbNum); + CTG_ERR_RET(TSDB_CODE_CTG_INVALID_INPUT); + } + + ctgDebug("start to check tbname metas in db %s, tbNum %ld", pReq->dbFName, taosArrayGetSize(pReq->pTables)); + CTG_ERR_RET(ctgGetTbNamesFromCache(pCtg, pConn, pCtx, i, &fetchIdx, baseResIdx, pReq->pTables)); + baseResIdx += taosArrayGetSize(pReq->pTables); + } + + pCtx->fetchNum = taosArrayGetSize(pCtx->pFetchs); + if (pCtx->fetchNum <= 0) { + TSWAP(pTask->res, pCtx->pResList); + + CTG_ERR_RET(ctgHandleTaskEnd(pTask, 0)); + return TSDB_CODE_SUCCESS; + } + + pTask->msgCtxs = taosArrayInit_s(sizeof(SCtgMsgCtx), pCtx->fetchNum); + if (NULL == pTask->msgCtxs) { + ctgError("taosArrayInit_s %d SCtgMsgCtx %d failed", pCtx->fetchNum, (int32_t)sizeof(SCtgMsgCtx)); + CTG_ERR_RET(terrno); + } + + for (int32_t i = 0; i < pCtx->fetchNum; ++i) { + SCtgFetch* pFetch = taosArrayGet(pCtx->pFetchs, i); + if (NULL == pFetch) { + ctgError("fail to get the %dth fetch in pCtx->pFetchs, fetchNum:%d", i, pCtx->fetchNum); + CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); + } + + CTG_ERR_RET(ctgGetFetchName(pCtx->pNames, pFetch, &pName)); + + SCtgMsgCtx* pMsgCtx = CTG_GET_TASK_MSGCTX(pTask, i); + if (NULL == pMsgCtx) { + ctgError("fail to get the %dth pMsgCtx", i); + CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR); + } + + if (NULL == pMsgCtx->pBatchs) { + pMsgCtx->pBatchs = pJob->pBatchs; + } + + SCtgTaskReq tReq; + tReq.pTask = pTask; + tReq.msgIdx = pFetch->fetchIdx; + CTG_ERR_RET(ctgAsyncRefreshTbMeta(&tReq, pFetch->flag, pName, &pFetch->vgId)); + } + + return TSDB_CODE_SUCCESS; +} + int32_t ctgDumpTbTSMARes(SCtgTask* pTask) { if (pTask->subTask) { return TSDB_CODE_SUCCESS; @@ -3876,6 +4181,7 @@ SCtgAsyncFps gCtgAsyncFps[] = { {ctgInitGetViewsTask, ctgLaunchGetViewsTask, ctgHandleGetViewsRsp, ctgDumpViewsRes, NULL, NULL}, {ctgInitGetTbTSMATask, ctgLaunchGetTbTSMATask, ctgHandleGetTbTSMARsp, ctgDumpTbTSMARes, NULL, NULL}, {ctgInitGetTSMATask, ctgLaunchGetTSMATask, ctgHandleGetTSMARsp, ctgDumpTSMARes, NULL, NULL}, + {ctgInitGetTbNamesTask, ctgLaunchGetTbNamesTask, ctgHandleGetTbNamesRsp, ctgDumpTbNamesRes, NULL, NULL}, }; int32_t ctgMakeAsyncRes(SCtgJob* pJob) { diff --git a/source/libs/catalog/src/ctgCache.c b/source/libs/catalog/src/ctgCache.c index ea51627ba5..80650a6095 100644 --- a/source/libs/catalog/src/ctgCache.c +++ b/source/libs/catalog/src/ctgCache.c @@ -3691,6 +3691,39 @@ _return: CTG_RET(code); } +int32_t ctgGetTbNamesFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbNamesCtx *ctx, int32_t dbIdx, + int32_t *fetchIdx, int32_t baseResIdx, SArray *pList) { + int32_t tbNum = taosArrayGetSize(pList); + char dbFName[TSDB_DB_FNAME_LEN] = {0}; + int32_t flag = CTG_FLAG_UNKNOWN_STB; + int32_t code = TSDB_CODE_SUCCESS; + uint64_t lastSuid = 0; + STableMeta *lastTableMeta = NULL; + SName *pName = taosArrayGet(pList, 0); + if (NULL == pName) { + ctgError("fail to get the 0th SName from tableList, tableNum:%d", (int32_t)taosArrayGetSize(pList)); + CTG_ERR_JRET(TSDB_CODE_CTG_INVALID_INPUT); + } + + if (IS_SYS_DBNAME(pName->dbname)) { + CTG_FLAG_SET_SYS_DB(flag); + TAOS_STRCPY(dbFName, pName->dbname); + } else { + (void)tNameGetFullDbName(pName, dbFName); + } + + ctgDebug("db %s not in cache", dbFName); + for (int32_t i = 0; i < tbNum; ++i) { + CTG_ERR_JRET(ctgAddFetch(&ctx->pFetchs, dbIdx, i, fetchIdx, baseResIdx + i, flag)); + if (NULL == taosArrayPush(ctx->pResList, &(SMetaData){0})) { + CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + } + } + +_return: + return code; +} + int32_t ctgGetTbHashVgroupFromCache(SCatalog *pCtg, const SName *pTableName, SVgroupInfo **pVgroup) { if (IS_SYS_DBNAME(pTableName->dbname)) { ctgError("no valid vgInfo for db, dbname:%s", pTableName->dbname); diff --git a/source/libs/catalog/src/ctgRemote.c b/source/libs/catalog/src/ctgRemote.c index c9114ce90e..d6e941c819 100644 --- a/source/libs/catalog/src/ctgRemote.c +++ b/source/libs/catalog/src/ctgRemote.c @@ -53,7 +53,7 @@ int32_t ctgHandleBatchRsp(SCtgJob* pJob, SCtgTaskCallbackParam* cbParam, SDataBu SHashObj* pBatchs = taosHashInit(taskNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); if (NULL == pBatchs) { ctgError("taosHashInit %d batch failed", taskNum); - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } for (int32_t i = 0; i < taskNum; ++i) { @@ -297,6 +297,27 @@ int32_t ctgProcessRspMsg(void* out, int32_t reqType, char* msg, int32_t msgSize, qDebug("Got table meta from vnode, tbFName:%s", target); break; } + case TDMT_VND_TABLE_NAME: { + if (TSDB_CODE_SUCCESS != rspCode) { + if (CTG_TABLE_NOT_EXIST(rspCode)) { + SET_META_TYPE_NULL(((STableMetaOutput*)out)->metaType); + qDebug("tablemeta not exist in vnode, tbFName:%s", target); + return TSDB_CODE_SUCCESS; + } + + qError("error rsp for table meta from vnode, code:%s, tbFName:%s", tstrerror(rspCode), target); + CTG_ERR_RET(rspCode); + } + + code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize); + if (code) { + qError("Process vnode tablemeta rsp failed, code:%s, tbFName:%s", tstrerror(code), target); + CTG_ERR_RET(code); + } + + qDebug("Got table meta from vnode, tbFName:%s", target); + break; + } case TDMT_VND_TABLE_CFG: { if (TSDB_CODE_SUCCESS != rspCode) { qError("error rsp for table cfg from vnode, code:%s, tbFName:%s", tstrerror(rspCode), target); @@ -441,7 +462,7 @@ int32_t ctgHandleMsgCallback(void* param, SDataBuf* pMsg, int32_t rspCode) { taosHashInit(CTG_DEFAULT_BATCH_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); if (NULL == pBatchs) { ctgError("taosHashInit %d batch failed", CTG_DEFAULT_BATCH_NUM); - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } SCtgMsgCtx* pMsgCtx = CTG_GET_TASK_MSGCTX(pTask, -1); @@ -575,7 +596,7 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo* pConn, SCtgT taosArrayDestroy(newBatch.pMsgs); taosArrayDestroy(newBatch.pTaskIds); taosArrayDestroy(newBatch.pMsgIdxs); - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } newBatch.conn = *pConn; @@ -585,14 +606,14 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo* pConn, SCtgT req.msgLen = msgSize; req.msg = msg; if (NULL == taosArrayPush(newBatch.pMsgs, &req)) { - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } msg = NULL; if (NULL == taosArrayPush(newBatch.pTaskIds, &pTask->taskId)) { - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } if (NULL == taosArrayPush(newBatch.pMsgIdxs, &req.msgIdx)) { - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } if (vgId > 0) { @@ -600,7 +621,7 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo* pConn, SCtgT if (TDMT_VND_TABLE_CFG == msgType) { SCtgTbCfgCtx* ctx = (SCtgTbCfgCtx*)pTask->taskCtx; pName = ctx->pName; - } else if (TDMT_VND_TABLE_META == msgType) { + } else if (TDMT_VND_TABLE_META == msgType || TDMT_VND_TABLE_NAME == msgType) { if (CTG_TASK_GET_TB_META_BATCH == pTask->type) { SCtgTbMetasCtx* ctx = (SCtgTbMetasCtx*)pTask->taskCtx; SCtgFetch* fetch = taosArrayGet(ctx->pFetchs, tReq->msgIdx); @@ -614,6 +635,10 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo* pConn, SCtgT ctgError("fail to get %d SName, totalTables:%d", pFetch->tbIdx, (int32_t)taosArrayGetSize(pTbReq->pTables)); CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); } + } else if (CTG_TASK_GET_TB_NAME == pTask->type) { + SCtgTbNamesCtx* ctx = (SCtgTbNamesCtx*)pTask->taskCtx; + SCtgFetch* fetch = taosArrayGet(ctx->pFetchs, tReq->msgIdx); + CTG_ERR_JRET(ctgGetFetchName(ctx->pNames, fetch, &pName)); } else { SCtgTbMetaCtx* ctx = (SCtgTbMetaCtx*)pTask->taskCtx; pName = ctx->pName; @@ -662,14 +687,14 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo* pConn, SCtgT req.msgLen = msgSize; req.msg = msg; if (NULL == taosArrayPush(pBatch->pMsgs, &req)) { - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } msg = NULL; if (NULL == taosArrayPush(pBatch->pTaskIds, &pTask->taskId)) { - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } if (NULL == taosArrayPush(pBatch->pMsgIdxs, &req.msgIdx)) { - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } if (vgId > 0) { @@ -677,7 +702,7 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo* pConn, SCtgT if (TDMT_VND_TABLE_CFG == msgType) { SCtgTbCfgCtx* ctx = (SCtgTbCfgCtx*)pTask->taskCtx; pName = ctx->pName; - } else if (TDMT_VND_TABLE_META == msgType) { + } else if (TDMT_VND_TABLE_META == msgType || TDMT_VND_TABLE_NAME == msgType) { if (CTG_TASK_GET_TB_META_BATCH == pTask->type) { SCtgTbMetasCtx* ctx = (SCtgTbMetasCtx*)pTask->taskCtx; SCtgFetch* fetch = taosArrayGet(ctx->pFetchs, tReq->msgIdx); @@ -691,6 +716,10 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo* pConn, SCtgT ctgError("fail to get %d SName, totalTables:%d", pFetch->tbIdx, (int32_t)taosArrayGetSize(pTbReq->pTables)); CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR); } + } else if (CTG_TASK_GET_TB_NAME == pTask->type) { + SCtgTbMetasCtx* ctx = (SCtgTbMetasCtx*)pTask->taskCtx; + SCtgFetch* fetch = taosArrayGet(ctx->pFetchs, tReq->msgIdx); + CTG_ERR_JRET(ctgGetFetchName(ctx->pNames, fetch, &pName)); } else { SCtgTbMetaCtx* ctx = (SCtgTbMetaCtx*)pTask->taskCtx; pName = ctx->pName; @@ -819,7 +848,7 @@ int32_t ctgGetQnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SArray if (pTask) { void* pOut = taosArrayInit(4, sizeof(SQueryNodeLoad)); if (NULL == pOut) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_ERR_RET(ctgUpdateMsgCtx(CTG_GET_TASK_MSGCTX(pTask, -1), reqType, pOut, NULL)); @@ -832,11 +861,11 @@ int32_t ctgGetQnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SArray #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -884,11 +913,11 @@ int32_t ctgGetDnodeListFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SArray #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -940,11 +969,11 @@ int32_t ctgGetDBVgInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SBuildU #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -998,11 +1027,11 @@ int32_t ctgGetDBCfgFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const char #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1056,11 +1085,11 @@ int32_t ctgGetIndexInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1121,11 +1150,11 @@ int32_t ctgGetTbIndexFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SName* n #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1179,11 +1208,11 @@ int32_t ctgGetUdfInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const ch #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1237,11 +1266,11 @@ int32_t ctgGetUserDbAuthFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1297,11 +1326,11 @@ int32_t ctgGetTbMetaFromMnodeImpl(SCatalog* pCtg, SRequestConnInfo* pConn, const #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1337,7 +1366,7 @@ int32_t ctgGetTbMetaFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SNa SCtgTask* pTask = tReq ? tReq->pTask : NULL; char dbFName[TSDB_DB_FNAME_LEN]; (void)tNameGetFullDbName(pTableName, dbFName); - int32_t reqType = TDMT_VND_TABLE_META; + int32_t reqType = (pTask && pTask->type == CTG_TASK_GET_TB_NAME ? TDMT_VND_TABLE_NAME : TDMT_VND_TABLE_META); char tbFName[TSDB_TABLE_FNAME_LEN]; (void)sprintf(tbFName, "%s.%s", dbFName, pTableName->tname); void* (*mallocFp)(int64_t) = pTask ? (MallocType)taosMemoryMalloc : (MallocType)rpcMallocCont; @@ -1346,10 +1375,12 @@ int32_t ctgGetTbMetaFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SNa ctgDebug("try to get table meta from vnode, vgId:%d, ep num:%d, ep %s:%d, tbFName:%s", vgroupInfo->vgId, vgroupInfo->epSet.numOfEps, pEp->fqdn, pEp->port, tbFName); - SBuildTableInput bInput = { - .vgId = vgroupInfo->vgId, .dbFName = dbFName, .tbName = (char*)tNameGetTableName(pTableName)}; - char* msg = NULL; - int32_t msgLen = 0; + SBuildTableInput bInput = {.vgId = vgroupInfo->vgId, + .option = reqType == TDMT_VND_TABLE_NAME ? REQ_OPT_TBUID : REQ_OPT_TBNAME, + .dbFName = dbFName, + .tbName = (char*)tNameGetTableName(pTableName)}; + char* msg = NULL; + int32_t msgLen = 0; int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](&bInput, &msg, 0, &msgLen, mallocFp); if (code) { @@ -1378,11 +1409,11 @@ int32_t ctgGetTbMetaFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SNa (void)tNameGetFullDbName(ctx->pName, dbFName); SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, &vConn, pTask->pJob, pTaskId, -1, NULL, dbFName, ctx->vgId, reqType, msg, msgLen)); @@ -1451,11 +1482,11 @@ int32_t ctgGetTableCfgFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, const S (void)tNameGetFullDbName(ctx->pName, dbFName); SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, &vConn, pTask->pJob, pTaskId, -1, NULL, dbFName, ctx->pVgInfo->vgId, reqType, msg, @@ -1515,11 +1546,11 @@ int32_t ctgGetTableCfgFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const S #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1567,11 +1598,11 @@ int32_t ctgGetSvrVerFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, char** ou #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1629,11 +1660,11 @@ int32_t ctgGetViewInfoFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, SName* #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1690,11 +1721,11 @@ int32_t ctgGetTbTSMAFromMnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SNa #else SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET(ctgAsyncSendMsg(pCtg, pConn, pTask->pJob, pTaskId, -1, NULL, NULL, 0, reqType, msg, msgLen)); @@ -1761,11 +1792,11 @@ int32_t ctgGetStreamProgressFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, c (void)tNameGetFullDbName(pTbName, dbFName); SArray* pTaskId = taosArrayInit(1, sizeof(int32_t)); if (NULL == pTaskId) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } if (NULL == taosArrayPush(pTaskId, &pTask->taskId)) { taosArrayDestroy(pTaskId); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } CTG_RET( diff --git a/source/libs/catalog/src/ctgUtil.c b/source/libs/catalog/src/ctgUtil.c index 545e3e1371..96cd783d2f 100644 --- a/source/libs/catalog/src/ctgUtil.c +++ b/source/libs/catalog/src/ctgUtil.c @@ -111,6 +111,8 @@ char* ctgTaskTypeStr(CTG_TASK_TYPE type) { return "[get table TSMA]"; case CTG_TASK_GET_TSMA: return "[get TSMA]"; + case CTG_TASK_GET_TB_NAME: + return "[bget table name]"; default: return "unknown"; } @@ -584,7 +586,8 @@ void ctgFreeMsgCtx(SCtgMsgCtx* pCtx) { break; } case TDMT_VND_TABLE_META: - case TDMT_MND_TABLE_META: { + case TDMT_MND_TABLE_META: + case TDMT_VND_TABLE_NAME: { STableMetaOutput* pOut = (STableMetaOutput*)pCtx->out; taosMemoryFree(pOut->tbMeta); taosMemoryFreeClear(pCtx->out); @@ -844,6 +847,15 @@ void ctgFreeTaskRes(CTG_TASK_TYPE type, void** pRes) { *pRes = NULL; break; } + case CTG_TASK_GET_TB_NAME: { + SArray* pArray = (SArray*)*pRes; + int32_t num = taosArrayGetSize(pArray); + for (int32_t i = 0; i < num; ++i) { + ctgFreeBatchMeta(taosArrayGet(pArray, i)); + } + *pRes = NULL; // no need to free it + break; + } default: qError("invalid task type %d", type); break; @@ -906,6 +918,11 @@ void ctgFreeSubTaskRes(CTG_TASK_TYPE type, void** pRes) { *pRes = NULL; break; } + case CTG_TASK_GET_TB_NAME: { + taosArrayDestroyEx(*pRes, ctgFreeBatchMeta); + *pRes = NULL; + break; + } default: qError("invalid task type %d", type); break; @@ -1016,6 +1033,21 @@ void ctgFreeTaskCtx(SCtgTask* pTask) { taosMemoryFreeClear(pTask->taskCtx); break; } + case CTG_TASK_GET_TB_NAME: { + SCtgTbNamesCtx* taskCtx = (SCtgTbNamesCtx*)pTask->taskCtx; + taosArrayDestroyEx(taskCtx->pResList, ctgFreeBatchMeta); + taosArrayDestroy(taskCtx->pFetchs); + // NO NEED TO FREE pNames + + taosArrayDestroyEx(pTask->msgCtxs, (FDelete)ctgFreeTbMetasMsgCtx); + + if (pTask->msgCtx.lastOut) { + ctgFreeSTableMetaOutput((STableMetaOutput*)pTask->msgCtx.lastOut); + pTask->msgCtx.lastOut = NULL; + } + taosMemoryFreeClear(pTask->taskCtx); + break; + } default: qError("invalid task type %d", pTask->type); break; @@ -1098,7 +1130,7 @@ int32_t ctgAddMsgCtx(SArray* pCtxs, int32_t reqType, void* out, char* target) { if (NULL == taosArrayPush(pCtxs, &ctx)) { ctgFreeMsgCtx(&ctx); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } return TSDB_CODE_SUCCESS; @@ -1124,7 +1156,7 @@ int32_t ctgGenerateVgList(SCatalog* pCtg, SHashObj* vgHash, SArray** pList) { vgList = taosArrayInit(vgNum, sizeof(SVgroupInfo)); if (NULL == vgList) { ctgError("taosArrayInit failed, num:%d", vgNum); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } void* pIter = taosHashIterate(vgHash, NULL); @@ -1134,12 +1166,14 @@ int32_t ctgGenerateVgList(SCatalog* pCtg, SHashObj* vgHash, SArray** pList) { if (NULL == taosArrayPush(vgList, vgInfo)) { ctgError("taosArrayPush failed, vgId:%d", vgInfo->vgId); taosHashCancelIterate(vgHash, pIter); - CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_JRET(terrno); } pIter = taosHashIterate(vgHash, pIter); } + taosArraySort(vgList, ctgVgInfoComp); + *pList = vgList; ctgDebug("Got vgList from cache, vgNum:%d", vgNum); @@ -1267,7 +1301,7 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SEpSet* pMgmgEpSet, SCtgTaskR for (int32_t i = 0; i < tbNum; ++i) { vgInfo = taosMemoryMalloc(sizeof(SVgroupInfo)); if (NULL == vgInfo) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } TAOS_MEMCPY(vgInfo, &mgmtInfo, sizeof(mgmtInfo)); @@ -1292,7 +1326,7 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SEpSet* pMgmgEpSet, SCtgTaskR } else { res.pRes = vgInfo; if (NULL == taosArrayPush(pCtx->pResList, &res)) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } } } @@ -1310,7 +1344,7 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SEpSet* pMgmgEpSet, SCtgTaskR for (int32_t i = 0; i < tbNum; ++i) { vgInfo = taosMemoryMalloc(sizeof(SVgroupInfo)); if (NULL == vgInfo) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } SVgroupInfo* pSrcVg = (SVgroupInfo*)taosArrayGet(dbInfo->vgArray, 0); @@ -1341,7 +1375,7 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SEpSet* pMgmgEpSet, SCtgTaskR } else { res.pRes = vgInfo; if (NULL == taosArrayPush(pCtx->pResList, &res)) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } } } @@ -1377,7 +1411,7 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SEpSet* pMgmgEpSet, SCtgTaskR SVgroupInfo* pNewVg = taosMemoryMalloc(sizeof(SVgroupInfo)); if (NULL == pNewVg) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } *pNewVg = *vgInfo; @@ -1403,7 +1437,7 @@ int32_t ctgGetVgInfosFromHashValue(SCatalog* pCtg, SEpSet* pMgmgEpSet, SCtgTaskR } else { res.pRes = pNewVg; if (NULL == taosArrayPush(pCtx->pResList, &res)) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } } } @@ -1533,16 +1567,17 @@ int32_t ctgMakeVgArray(SDBVgInfo* dbInfo) { } if (dbInfo->vgHash && NULL == dbInfo->vgArray) { - dbInfo->vgArray = taosArrayInit(100, sizeof(SVgroupInfo)); + int32_t vgSize = taosHashGetSize(dbInfo->vgHash); + dbInfo->vgArray = taosArrayInit(vgSize, sizeof(SVgroupInfo)); if (NULL == dbInfo->vgArray) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } void* pIter = taosHashIterate(dbInfo->vgHash, NULL); while (pIter) { if (NULL == taosArrayPush(dbInfo->vgArray, pIter)) { taosHashCancelIterate(dbInfo->vgHash, pIter); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } pIter = taosHashIterate(dbInfo->vgHash, pIter); @@ -1560,7 +1595,7 @@ int32_t ctgCloneVgInfo(SDBVgInfo* src, SDBVgInfo** dst) { *dst = taosMemoryMalloc(sizeof(SDBVgInfo)); if (NULL == *dst) { qError("malloc %d failed", (int32_t)sizeof(SDBVgInfo)); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } TAOS_MEMCPY(*dst, src, sizeof(SDBVgInfo)); @@ -1570,7 +1605,7 @@ int32_t ctgCloneVgInfo(SDBVgInfo* src, SDBVgInfo** dst) { if (NULL == (*dst)->vgHash) { qError("taosHashInit %d failed", (int32_t)hashSize); taosMemoryFreeClear(*dst); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } int32_t* vgId = NULL; @@ -1605,7 +1640,7 @@ int32_t ctgCloneMetaOutput(STableMetaOutput* output, STableMetaOutput** pOutput) *pOutput = taosMemoryMalloc(sizeof(STableMetaOutput)); if (NULL == *pOutput) { qError("malloc %d failed", (int32_t)sizeof(STableMetaOutput)); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } TAOS_MEMCPY(*pOutput, output, sizeof(STableMetaOutput)); @@ -1622,7 +1657,7 @@ int32_t ctgCloneMetaOutput(STableMetaOutput* output, STableMetaOutput** pOutput) if (NULL == (*pOutput)->tbMeta) { qError("malloc %d failed", (int32_t)sizeof(STableMetaOutput)); taosMemoryFreeClear(*pOutput); - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } TAOS_MEMCPY((*pOutput)->tbMeta, output->tbMeta, metaSize); @@ -1646,7 +1681,7 @@ int32_t ctgCloneTableIndex(SArray* pIndex, SArray** pRes) { int32_t num = taosArrayGetSize(pIndex); *pRes = taosArrayInit(num, sizeof(STableIndexInfo)); if (NULL == *pRes) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } for (int32_t i = 0; i < num; ++i) { @@ -1657,7 +1692,7 @@ int32_t ctgCloneTableIndex(SArray* pIndex, SArray** pRes) { } pInfo = taosArrayPush(*pRes, pInfo); if (NULL == pInfo) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } pInfo->expr = taosStrdup(pInfo->expr); if (NULL == pInfo->expr) { @@ -1669,7 +1704,7 @@ int32_t ctgCloneTableIndex(SArray* pIndex, SArray** pRes) { } int32_t ctgUpdateSendTargetInfo(SMsgSendInfo* pMsgSendInfo, int32_t msgType, char* dbFName, int32_t vgId) { - if (msgType == TDMT_VND_TABLE_META || msgType == TDMT_VND_TABLE_CFG || msgType == TDMT_VND_BATCH_META) { + if (msgType == TDMT_VND_TABLE_META || msgType == TDMT_VND_TABLE_CFG || msgType == TDMT_VND_BATCH_META || msgType == TDMT_VND_TABLE_NAME) { pMsgSendInfo->target.type = TARGET_TYPE_VNODE; pMsgSendInfo->target.vgId = vgId; pMsgSendInfo->target.dbFName = taosStrdup(dbFName); @@ -1707,7 +1742,7 @@ int32_t ctgAddFetch(SArray** pFetchs, int32_t dbIdx, int32_t tbIdx, int32_t* fet if (NULL == (*pFetchs)) { *pFetchs = taosArrayInit(CTG_DEFAULT_FETCH_NUM, sizeof(SCtgFetch)); if (NULL == *pFetchs) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } } @@ -1719,7 +1754,7 @@ int32_t ctgAddFetch(SArray** pFetchs, int32_t dbIdx, int32_t tbIdx, int32_t* fet fetch.flag = flag; if (NULL == taosArrayPush(*pFetchs, &fetch)) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } return TSDB_CODE_SUCCESS; @@ -2579,7 +2614,7 @@ int32_t ctgBuildViewNullRes(SCtgTask* pTask, SCtgViewsCtx* pCtx) { for (int32_t m = 0; m < viewNum; ++m) { if (NULL == taosArrayPush(pCtx->pResList, &(SMetaData){0})) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } } } @@ -2603,7 +2638,7 @@ int32_t dupViewMetaFromRsp(SViewMetaRsp* pRsp, SViewMeta* pViewMeta) { pViewMeta->numOfCols = pRsp->numOfCols; pViewMeta->pSchema = taosMemoryMalloc(pViewMeta->numOfCols * sizeof(SSchema)); if (pViewMeta->pSchema == NULL) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } TAOS_MEMCPY(pViewMeta->pSchema, pRsp->pSchema, pViewMeta->numOfCols * sizeof(SSchema)); @@ -2679,7 +2714,7 @@ int32_t ctgAddTSMAFetch(SArray** pFetchs, int32_t dbIdx, int32_t tbIdx, int32_t* if (NULL == (*pFetchs)) { *pFetchs = taosArrayInit(CTG_DEFAULT_FETCH_NUM, sizeof(SCtgTSMAFetch)); if (NULL == *pFetchs) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } } @@ -2696,7 +2731,7 @@ int32_t ctgAddTSMAFetch(SArray** pFetchs, int32_t dbIdx, int32_t tbIdx, int32_t* } if (NULL == taosArrayPush(*pFetchs, &fetch)) { - CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + CTG_ERR_RET(terrno); } return TSDB_CODE_SUCCESS; diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index eb74b81141..d24f830ea7 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -692,7 +692,7 @@ static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* p SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1); char* buf2 = taosMemoryMalloc(SHOW_CREATE_TB_RESULT_FIELD2_LEN); if (NULL == buf2) { - QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + QRY_ERR_RET(terrno); } int32_t len = 0; @@ -864,7 +864,7 @@ static int32_t buildLocalVariablesResultDataBlock(SSDataBlock** pOutput) { pBlock->pDataBlock = taosArrayInit(SHOW_LOCAL_VARIABLES_RESULT_COLS, sizeof(SColumnInfoData)); if (NULL == pBlock->pDataBlock) { taosMemoryFree(pBlock); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SColumnInfoData infoData = {0}; diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 886425c69b..b82bba250f 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -135,7 +135,7 @@ int32_t qExplainInitCtx(SExplainCtx **pCtx, SHashObj *groupHash, bool verbose, d char *tbuf = taosMemoryMalloc(TSDB_EXPLAIN_RESULT_ROW_SIZE); if (NULL == tbuf) { qError("malloc size %d failed", TSDB_EXPLAIN_RESULT_ROW_SIZE); - QRY_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + QRY_ERR_JRET(terrno); } ctx->mode = mode; @@ -184,7 +184,7 @@ int32_t qExplainGenerateResNodeExecInfo(SPhysiNode *pNode, SArray **pExecInfo, S *pExecInfo = taosArrayInit(group->nodeNum, sizeof(SExplainExecInfo)); if (NULL == (*pExecInfo)) { qError("taosArrayInit %d explainExecInfo failed", group->nodeNum); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SExplainRsp *rsp = NULL; @@ -302,7 +302,7 @@ int32_t qExplainResAppendRow(SExplainCtx *ctx, char *tbuf, int32_t len, int32_t row.buf = taosMemoryMalloc(len); if (NULL == row.buf) { qError("taosMemoryMalloc %d failed", len); - QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + QRY_ERR_RET(terrno); } memcpy(row.buf, tbuf, len); @@ -313,7 +313,7 @@ int32_t qExplainResAppendRow(SExplainCtx *ctx, char *tbuf, int32_t len, int32_t if (NULL == taosArrayPush(ctx->rows, &row)) { qError("taosArrayPush row to explain res rows failed"); taosMemoryFree(row.buf); - QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + QRY_ERR_RET(terrno); } return TSDB_CODE_SUCCESS; @@ -1971,7 +1971,7 @@ int32_t qExplainGetRspFromCtx(void *ctx, SRetrieveTableRsp **pRsp) { SRetrieveTableRsp *rsp = (SRetrieveTableRsp *)taosMemoryCalloc(1, rspSize); if (NULL == rsp) { qError("malloc SRetrieveTableRsp failed, size:%d", rspSize); - QRY_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + QRY_ERR_JRET(terrno); } rsp->completed = 1; @@ -2018,7 +2018,7 @@ int32_t qExplainPrepareCtx(SQueryPlan *pDag, SExplainCtx **pCtx) { taosHashInit(EXPLAIN_MAX_GROUP_NUM, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); if (NULL == groupHash) { qError("groupHash %d failed", EXPLAIN_MAX_GROUP_NUM); - QRY_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + QRY_ERR_RET(terrno); } QRY_ERR_JRET( @@ -2128,7 +2128,7 @@ int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t group->nodeExecInfo = taosArrayInit(group->nodeNum, sizeof(SExplainRsp)); if (NULL == group->nodeExecInfo) { qError("taosArrayInit %d explainExecInfo failed", group->nodeNum); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_CHECK_ERRNO(code); } @@ -2149,7 +2149,7 @@ int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t if(taosArrayPush(group->nodeExecInfo, pRspMsg) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_CHECK_ERRNO(code); } diff --git a/source/libs/executor/inc/executorInt.h b/source/libs/executor/inc/executorInt.h index c77f5456f3..35261570ae 100644 --- a/source/libs/executor/inc/executorInt.h +++ b/source/libs/executor/inc/executorInt.h @@ -578,6 +578,7 @@ typedef struct SIntervalAggOperatorInfo { EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model] STimeWindowAggSupp twAggSup; SArray* pPrevValues; // SArray used to keep the previous not null value for interpolation. + struct SOperatorInfo* pOperator; // for limit optimization bool limited; int64_t limit; @@ -646,6 +647,7 @@ typedef struct SStreamIntervalOperatorInfo { int32_t midDelIndex; SSHashObj* pDeletedMap; bool destHasPrimaryKey; + struct SOperatorInfo* pOperator; } SStreamIntervalOperatorInfo; typedef struct SDataGroupInfo { @@ -701,6 +703,7 @@ typedef struct SStreamSessionAggOperatorInfo { bool recvGetAll; bool destHasPrimaryKey; SSHashObj* pPkDeleted; + struct SOperatorInfo* pOperator; } SStreamSessionAggOperatorInfo; typedef struct SStreamStateAggOperatorInfo { @@ -728,6 +731,7 @@ typedef struct SStreamStateAggOperatorInfo { bool recvGetAll; SSHashObj* pPkDeleted; bool destHasPrimaryKey; + struct SOperatorInfo* pOperator; } SStreamStateAggOperatorInfo; typedef struct SStreamEventAggOperatorInfo { @@ -757,6 +761,7 @@ typedef struct SStreamEventAggOperatorInfo { SFilterInfo* pEndCondInfo; SSHashObj* pPkDeleted; bool destHasPrimaryKey; + struct SOperatorInfo* pOperator; } SStreamEventAggOperatorInfo; typedef struct SStreamCountAggOperatorInfo { @@ -781,6 +786,7 @@ typedef struct SStreamCountAggOperatorInfo { SSDataBlock* pCheckpointRes; SSHashObj* pPkDeleted; bool destHasPrimaryKey; + struct SOperatorInfo* pOperator; } SStreamCountAggOperatorInfo; typedef struct SStreamPartitionOperatorInfo { @@ -861,6 +867,10 @@ void cleanupBasicInfo(SOptrBasicInfo* pInfo); int32_t initExprSupp(SExprSupp* pSup, SExprInfo* pExprInfo, int32_t numOfExpr, SFunctionStateStore* pStore); void cleanupExprSupp(SExprSupp* pSup); +void cleanupResultInfoInStream(SExecTaskInfo* pTaskInfo, void* pState, SExprSupp* pSup, + SGroupResInfo* pGroupResInfo); +void cleanupResultInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf* pBuf, + SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap); int32_t initAggSup(SExprSupp* pSup, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols, size_t keyBufSize, const char* pkey, void* pState, SFunctionStateStore* pStore); void cleanupAggSup(SAggSupporter* pAggSup); @@ -882,8 +892,8 @@ void initLimitInfo(const SNode* pLimit, const SNode* pSLimit, SLimitInfo* pLimit void resetLimitInfoForNextGroup(SLimitInfo* pLimitInfo); bool applyLimitOffset(SLimitInfo* pLimitInfo, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo); -void applyAggFunctionOnPartialTuples(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, SColumnInfoData* pTimeWindowData, - int32_t offset, int32_t forwardStep, int32_t numOfTotal, int32_t numOfOutput); +int32_t applyAggFunctionOnPartialTuples(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, SColumnInfoData* pTimeWindowData, + int32_t offset, int32_t forwardStep, int32_t numOfTotal, int32_t numOfOutput); int32_t extractDataBlockFromFetchRsp(SSDataBlock* pRes, char* pData, SArray* pColList, char** pNextStart); void updateLoadRemoteInfo(SLoadRemoteDataInfo* pInfo, int64_t numOfRows, int32_t dataLen, int64_t startTs, @@ -954,8 +964,8 @@ SSDataBlock* buildCreateTableBlock(SExprSupp* tbName, SExprSupp* tag); SExprInfo* createExpr(SNodeList* pNodeList, int32_t* numOfExprs); void destroyExprInfo(SExprInfo* pExpr, int32_t numOfExprs); -void copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx, - SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo); +int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx, + SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo); void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExprs, const int32_t* rowEntryOffset); void doClearBufferedBlocks(SStreamScanInfo* pInfo); diff --git a/source/libs/executor/src/aggregateoperator.c b/source/libs/executor/src/aggregateoperator.c index 4605d19464..863ce01256 100644 --- a/source/libs/executor/src/aggregateoperator.c +++ b/source/libs/executor/src/aggregateoperator.c @@ -48,6 +48,7 @@ typedef struct SAggOperatorInfo { bool hasValidBlock; SSDataBlock* pNewGroupBlock; bool hasCountFunc; + SOperatorInfo* pOperator; } SAggOperatorInfo; static void destroyAggOperatorInfo(void* param); @@ -119,6 +120,7 @@ int32_t createAggregateOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pA pInfo->binfo.inputTsOrder = pAggNode->node.inputTsOrder; pInfo->binfo.outputTsOrder = pAggNode->node.outputTsOrder; pInfo->hasCountFunc = pAggNode->hasCountLikeFunc; + pInfo->pOperator = pOperator; setOperatorInfo(pOperator, "TableAggregate", QUERY_NODE_PHYSICAL_PLAN_HASH_AGG, !pAggNode->node.forceCreateNonBlockingOptr, OP_NOT_OPENED, pInfo, pTaskInfo); @@ -153,6 +155,9 @@ void destroyAggOperatorInfo(void* param) { SAggOperatorInfo* pInfo = (SAggOperatorInfo*)param; cleanupBasicInfo(&pInfo->binfo); + cleanupResultInfo(pInfo->pOperator->pTaskInfo, &pInfo->pOperator->exprSupp, pInfo->aggSup.pResultBuf, + &pInfo->groupResInfo, pInfo->aggSup.pResultRowHashTable); + pInfo->pOperator = NULL; cleanupAggSup(&pInfo->aggSup); cleanupExprSupp(&pInfo->scalarExprSup); cleanupGroupResInfo(&pInfo->groupResInfo); @@ -581,6 +586,80 @@ int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t n return code; } +void cleanupResultInfoInStream(SExecTaskInfo* pTaskInfo, void* pState, SExprSupp* pSup, SGroupResInfo* pGroupResInfo) { + int32_t code = TSDB_CODE_SUCCESS; + SStorageAPI* pAPI = &pTaskInfo->storageAPI; + int32_t numOfExprs = pSup->numOfExprs; + int32_t* rowEntryOffset = pSup->rowEntryInfoOffset; + SqlFunctionCtx* pCtx = pSup->pCtx; + int32_t numOfRows = getNumOfTotalRes(pGroupResInfo); + bool needCleanup = false; + + for (int32_t j = 0; j < numOfExprs; ++j) { + needCleanup |= pCtx[j].needCleanup; + } + if (!needCleanup) { + return; + } + + for (int32_t i = pGroupResInfo->index; i < numOfRows; i += 1) { + SResultWindowInfo* pWinInfo = taosArrayGet(pGroupResInfo->pRows, i); + SRowBuffPos* pPos = pWinInfo->pStatePos; + SResultRow* pRow = NULL; + + code = pAPI->stateStore.streamStateGetByPos(pState, pPos, (void**)&pRow); + if (TSDB_CODE_SUCCESS != code) { + qError("failed to get state by pos, code:%s, %s", tstrerror(code), GET_TASKID(pTaskInfo)); + continue; + } + + for (int32_t j = 0; j < numOfExprs; ++j) { + pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset); + if (pCtx[j].fpSet.cleanup) { + pCtx[j].fpSet.cleanup(&pCtx[j]); + } + } + } +} + +void cleanupResultInfo(SExecTaskInfo* pTaskInfo, SExprSupp* pSup, SDiskbasedBuf* pBuf, + SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap) { + int32_t numOfExprs = pSup->numOfExprs; + int32_t* rowEntryOffset = pSup->rowEntryInfoOffset; + SqlFunctionCtx* pCtx = pSup->pCtx; + bool needCleanup = false; + for (int32_t j = 0; j < numOfExprs; ++j) { + needCleanup |= pCtx[j].needCleanup; + } + if (!needCleanup) { + return; + } + + // begin from last iter + void* pData = pGroupResInfo->dataPos; + int32_t iter = pGroupResInfo->iter; + while ((pData = tSimpleHashIterate(pHashmap, pData, &iter)) != NULL) { + SResultRowPosition* pos = pData; + + SFilePage* page = getBufPage(pBuf, pos->pageId); + if (page == NULL) { + qError("failed to get buffer, code:%s, %s", tstrerror(terrno), GET_TASKID(pTaskInfo)); + continue; + } + + SResultRow* pRow = (SResultRow*)((char*)page + pos->offset); + + for (int32_t j = 0; j < numOfExprs; ++j) { + pCtx[j].resultInfo = getResultEntryInfo(pRow, j, rowEntryOffset); + if (pCtx[j].fpSet.cleanup) { + pCtx[j].fpSet.cleanup(&pCtx[j]); + } + } + + releaseBufPage(pBuf, page); + } +} + void cleanupAggSup(SAggSupporter* pAggSup) { taosMemoryFreeClear(pAggSup->keyBuf); tSimpleHashCleanup(pAggSup->pResultRowHashTable); @@ -613,8 +692,9 @@ int32_t initAggSup(SExprSupp* pSup, SAggSupporter* pAggSup, SExprInfo* pExprInfo return TSDB_CODE_SUCCESS; } -void applyAggFunctionOnPartialTuples(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, SColumnInfoData* pTimeWindowData, - int32_t offset, int32_t forwardStep, int32_t numOfTotal, int32_t numOfOutput) { +int32_t applyAggFunctionOnPartialTuples(SExecTaskInfo* taskInfo, SqlFunctionCtx* pCtx, SColumnInfoData* pTimeWindowData, + int32_t offset, int32_t forwardStep, int32_t numOfTotal, int32_t numOfOutput) { + int32_t code = TSDB_CODE_SUCCESS; for (int32_t k = 0; k < numOfOutput; ++k) { // keep it temporarily SFunctionCtxStatus status = {0}; @@ -641,15 +721,14 @@ void applyAggFunctionOnPartialTuples(SExecTaskInfo* taskInfo, SqlFunctionCtx* pC SScalarParam out = {.columnData = &idata}; SScalarParam tw = {.numOfRows = 5, .columnData = pTimeWindowData}; - int32_t code = pCtx[k].sfp.process(&tw, 1, &out); + code = pCtx[k].sfp.process(&tw, 1, &out); if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); taskInfo->code = code; - T_LONG_JMP(taskInfo->env, code); + return code; } pEntryInfo->numOfRes = 1; } else { - int32_t code = TSDB_CODE_SUCCESS; if (functionNeedToExecute(&pCtx[k]) && pCtx[k].fpSet.process != NULL) { if ((&pCtx[k])->input.pData[0] == NULL) { code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; @@ -664,7 +743,7 @@ void applyAggFunctionOnPartialTuples(SExecTaskInfo* taskInfo, SqlFunctionCtx* pC } qError("%s apply functions error, code: %s", GET_TASKID(taskInfo), tstrerror(code)); taskInfo->code = code; - T_LONG_JMP(taskInfo->env, code); + return code; } } @@ -672,6 +751,7 @@ void applyAggFunctionOnPartialTuples(SExecTaskInfo* taskInfo, SqlFunctionCtx* pC functionCtxRestore(&pCtx[k], &status); } } + return code; } void functionCtxSave(SqlFunctionCtx* pCtx, SFunctionCtxStatus* pStatus) { diff --git a/source/libs/executor/src/cachescanoperator.c b/source/libs/executor/src/cachescanoperator.c index 7c1ca294e7..649a7a4524 100644 --- a/source/libs/executor/src/cachescanoperator.c +++ b/source/libs/executor/src/cachescanoperator.c @@ -347,11 +347,7 @@ static int32_t doScanCacheNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { SExprSupp* pSup = &pInfo->pseudoExprSup; code = addTagPseudoColumnData(&pInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pRes, pRes->info.rows, pTaskInfo, NULL); - if (code != TSDB_CODE_SUCCESS) { - pTaskInfo->code = code; - (*ppRes) = NULL; - return code; - } + QUERY_CHECK_CODE(code, lino, _end); pRes->info.id.groupId = tableListGetTableGroupId(pTableList, pRes->info.id.uid); pInfo->indexOfBufferedRes += 1; @@ -414,11 +410,7 @@ static int32_t doScanCacheNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { pInfo->pRes->info.id.uid = *(tb_uid_t*)pUid; code = addTagPseudoColumnData(&pInfo->readHandle, pSup->pExprInfo, pSup->numOfExprs, pInfo->pRes, pInfo->pRes->info.rows, pTaskInfo, NULL); - if (code != TSDB_CODE_SUCCESS) { - pTaskInfo->code = code; - (*ppRes) = NULL; - return code; - } + QUERY_CHECK_CODE(code, lino, _end); } } diff --git a/source/libs/executor/src/countwindowoperator.c b/source/libs/executor/src/countwindowoperator.c index 2233d58ef8..542a7c89a9 100644 --- a/source/libs/executor/src/countwindowoperator.c +++ b/source/libs/executor/src/countwindowoperator.c @@ -149,8 +149,9 @@ void doCountWindowAggImpl(SOperatorInfo* pOperator, SSDataBlock* pBlock) { pInfo->pRow->win.ekey = tsCols[num + i - 1]; updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pInfo->pRow->win, 0); - applyAggFunctionOnPartialTuples(pTaskInfo, pExprSup->pCtx, &pInfo->twAggSup.timeWindowData, i, num, - pBlock->info.rows, pExprSup->numOfExprs); + code = applyAggFunctionOnPartialTuples(pTaskInfo, pExprSup->pCtx, &pInfo->twAggSup.timeWindowData, i, num, + pBlock->info.rows, pExprSup->numOfExprs); + QUERY_CHECK_CODE(code, lino, _end); if (pInfo->windowCount != pInfo->windowSliding) { if (prevRows <= pInfo->windowSliding) { if (pBuffInfo->winRows > pInfo->windowSliding) { @@ -164,8 +165,9 @@ void doCountWindowAggImpl(SOperatorInfo* pOperator, SSDataBlock* pBlock) { } if (pBuffInfo->winRows == pInfo->windowCount) { doUpdateNumOfRows(pExprSup->pCtx, pInfo->pRow, pExprSup->numOfExprs, pExprSup->rowEntryInfoOffset); - copyResultrowToDataBlock(pExprSup->pExprInfo, pExprSup->numOfExprs, pInfo->pRow, pExprSup->pCtx, pRes, - pExprSup->rowEntryInfoOffset, pTaskInfo); + code = copyResultrowToDataBlock(pExprSup->pExprInfo, pExprSup->numOfExprs, pInfo->pRow, pExprSup->pCtx, pRes, + pExprSup->rowEntryInfoOffset, pTaskInfo); + QUERY_CHECK_CODE(code, lino, _end); pRes->info.rows += pInfo->pRow->numOfRows; clearWinStateBuff(pBuffInfo); pInfo->preStateIndex = pInfo->countSup.curStateIndex; @@ -205,8 +207,9 @@ static void buildCountResult(SExprSupp* pExprSup, SCountWindowSupp* pCountSup, S continue; } doUpdateNumOfRows(pExprSup->pCtx, pResultRow, pExprSup->numOfExprs, pExprSup->rowEntryInfoOffset); - copyResultrowToDataBlock(pExprSup->pExprInfo, pExprSup->numOfExprs, pResultRow, pExprSup->pCtx, pBlock, - pExprSup->rowEntryInfoOffset, pTaskInfo); + code = copyResultrowToDataBlock(pExprSup->pExprInfo, pExprSup->numOfExprs, pResultRow, pExprSup->pCtx, pBlock, + pExprSup->rowEntryInfoOffset, pTaskInfo); + QUERY_CHECK_CODE(code, lino, _end); pBlock->info.rows += pResultRow->numOfRows; clearWinStateBuff(pBuff); clearResultRowInitFlag(pExprSup->pCtx, pExprSup->numOfExprs); diff --git a/source/libs/executor/src/dynqueryctrloperator.c b/source/libs/executor/src/dynqueryctrloperator.c index 638536349d..eb49057d89 100644 --- a/source/libs/executor/src/dynqueryctrloperator.c +++ b/source/libs/executor/src/dynqueryctrloperator.c @@ -938,7 +938,9 @@ _return: } if (code) { + qError("%s failed since %s", __func__, tstrerror(code)); pOperator->pTaskInfo->code = code; + T_LONG_JMP(pOperator->pTaskInfo->env, code); } else { seqStableJoinComposeRes(pStbJoin, *pRes); } diff --git a/source/libs/executor/src/eventwindowoperator.c b/source/libs/executor/src/eventwindowoperator.c index 0f3a08c14b..79e7494518 100644 --- a/source/libs/executor/src/eventwindowoperator.c +++ b/source/libs/executor/src/eventwindowoperator.c @@ -37,6 +37,7 @@ typedef struct SEventWindowOperatorInfo { bool inWindow; SResultRow* pRow; SSDataBlock* pPreDataBlock; + SOperatorInfo* pOperator; } SEventWindowOperatorInfo; static int32_t eventWindowAggregateNext(SOperatorInfo* pOperator, SSDataBlock** pRes); @@ -128,6 +129,7 @@ int32_t createEventwindowOperatorInfo(SOperatorInfo* downstream, SPhysiNode* phy pInfo->tsSlotId = tsSlotId; pInfo->pPreDataBlock = NULL; + pInfo->pOperator = pOperator; setOperatorInfo(pOperator, "EventWindowOperator", QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE, true, OP_NOT_OPENED, pInfo, pTaskInfo); @@ -152,6 +154,19 @@ _error: return code; } +void cleanupResultInfoInEventWindow(SOperatorInfo* pOperator, SEventWindowOperatorInfo* pInfo) { + if (pInfo == NULL || pInfo->pRow == NULL) { + return; + } + SExprSupp* pSup = &pOperator->exprSupp; + for (int32_t j = 0; j < pSup->numOfExprs; ++j) { + pSup->pCtx[j].resultInfo = getResultEntryInfo(pInfo->pRow, j, pSup->rowEntryInfoOffset); + if (pSup->pCtx[j].fpSet.cleanup) { + pSup->pCtx[j].fpSet.cleanup(&pSup->pCtx[j]); + } + } +} + void destroyEWindowOperatorInfo(void* param) { SEventWindowOperatorInfo* pInfo = (SEventWindowOperatorInfo*)param; if (pInfo == NULL) { @@ -175,6 +190,8 @@ void destroyEWindowOperatorInfo(void* param) { cleanupBasicInfo(&pInfo->binfo); colDataDestroy(&pInfo->twAggSup.timeWindowData); + cleanupResultInfoInEventWindow(pInfo->pOperator, pInfo); + pInfo->pOperator = NULL; cleanupAggSup(&pInfo->aggSup); cleanupExprSupp(&pInfo->scalarSup); taosMemoryFreeClear(param); @@ -260,8 +277,10 @@ static int32_t setSingleOutputTupleBufv1(SResultRowInfo* pResultRowInfo, STimeWi return setResultRowInitCtx(*pResult, pExprSup->pCtx, pExprSup->numOfExprs, pExprSup->rowEntryInfoOffset); } -static void doEventWindowAggImpl(SEventWindowOperatorInfo* pInfo, SExprSupp* pSup, int32_t startIndex, int32_t endIndex, - const SSDataBlock* pBlock, int64_t* tsList, SExecTaskInfo* pTaskInfo) { +static int32_t doEventWindowAggImpl(SEventWindowOperatorInfo* pInfo, SExprSupp* pSup, int32_t startIndex, + int32_t endIndex, const SSDataBlock* pBlock, int64_t* tsList, + SExecTaskInfo* pTaskInfo) { + int32_t code = TSDB_CODE_SUCCESS; SWindowRowsSup* pRowSup = &pInfo->winSup; int32_t numOfOutput = pSup->numOfExprs; @@ -269,15 +288,16 @@ static void doEventWindowAggImpl(SEventWindowOperatorInfo* pInfo, SExprSupp* pSu doKeepTuple(pRowSup, tsList[endIndex], pBlock->info.id.groupId); - int32_t ret = - setSingleOutputTupleBufv1(&pInfo->binfo.resultRowInfo, &pRowSup->win, &pInfo->pRow, pSup, &pInfo->aggSup); - if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code - T_LONG_JMP(pTaskInfo->env, TSDB_CODE_APP_ERROR); + code = setSingleOutputTupleBufv1(&pInfo->binfo.resultRowInfo, &pRowSup->win, &pInfo->pRow, pSup, &pInfo->aggSup); + if (code != TSDB_CODE_SUCCESS) { // null data, too many state code + qError("failed to set single output tuple buffer, code:%d", code); + return code; } updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pRowSup->win, 0); - applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startIndex, numOfRows, - pBlock->info.rows, numOfOutput); + code = applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startIndex, numOfRows, + pBlock->info.rows, numOfOutput); + return code; } int32_t eventWindowAggImpl(SOperatorInfo* pOperator, SEventWindowOperatorInfo* pInfo, SSDataBlock* pBlock) { @@ -287,11 +307,11 @@ int32_t eventWindowAggImpl(SOperatorInfo* pOperator, SEventWindowOperatorInfo* p SExprSupp* pSup = &pOperator->exprSupp; SSDataBlock* pRes = pInfo->binfo.pRes; int64_t gid = pBlock->info.id.groupId; + SColumnInfoData *ps = NULL, *pe = NULL; SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, pInfo->tsSlotId); QUERY_CHECK_NULL(pColInfoData, code, lino, _return, terrno); TSKEY* tsList = (TSKEY*)pColInfoData->pData; SWindowRowsSup* pRowSup = &pInfo->winSup; - SColumnInfoData *ps = NULL, *pe = NULL; int32_t rowIndex = 0; pRowSup->numOfRows = 0; @@ -333,7 +353,8 @@ int32_t eventWindowAggImpl(SOperatorInfo* pOperator, SEventWindowOperatorInfo* p } if (rowIndex < pBlock->info.rows) { - doEventWindowAggImpl(pInfo, pSup, startIndex, rowIndex, pBlock, tsList, pTaskInfo); + code = doEventWindowAggImpl(pInfo, pSup, startIndex, rowIndex, pBlock, tsList, pTaskInfo); + QUERY_CHECK_CODE(code, lino, _return); doUpdateNumOfRows(pSup->pCtx, pInfo->pRow, pSup->numOfExprs, pSup->rowEntryInfoOffset); // check buffer size @@ -343,8 +364,9 @@ int32_t eventWindowAggImpl(SOperatorInfo* pOperator, SEventWindowOperatorInfo* p QUERY_CHECK_CODE(code, lino, _return); } - copyResultrowToDataBlock(pSup->pExprInfo, pSup->numOfExprs, pInfo->pRow, pSup->pCtx, pRes, - pSup->rowEntryInfoOffset, pTaskInfo); + code = copyResultrowToDataBlock(pSup->pExprInfo, pSup->numOfExprs, pInfo->pRow, pSup->pCtx, pRes, + pSup->rowEntryInfoOffset, pTaskInfo); + QUERY_CHECK_CODE(code, lino, _return); pRes->info.rows += pInfo->pRow->numOfRows; pInfo->pRow->numOfRows = 0; @@ -352,7 +374,8 @@ int32_t eventWindowAggImpl(SOperatorInfo* pOperator, SEventWindowOperatorInfo* p pInfo->inWindow = false; rowIndex += 1; } else { - doEventWindowAggImpl(pInfo, pSup, startIndex, pBlock->info.rows - 1, pBlock, tsList, pTaskInfo); + code = doEventWindowAggImpl(pInfo, pSup, startIndex, pBlock->info.rows - 1, pBlock, tsList, pTaskInfo); + QUERY_CHECK_CODE(code, lino, _return); } } else { // find the first start value that is fulfill for the start condition for (; rowIndex < pBlock->info.rows; ++rowIndex) { diff --git a/source/libs/executor/src/exchangeoperator.c b/source/libs/executor/src/exchangeoperator.c index 5352ea37ae..767796977c 100644 --- a/source/libs/executor/src/exchangeoperator.c +++ b/source/libs/executor/src/exchangeoperator.c @@ -208,7 +208,7 @@ static SSDataBlock* doLoadRemoteDataImpl(SOperatorInfo* pOperator) { if (p != NULL) { void* tmp = taosArrayPush(pExchangeInfo->pRecycledBlocks, &p); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); pTaskInfo->code = code; T_LONG_JMP(pTaskInfo->env, code); @@ -236,7 +236,7 @@ static SSDataBlock* doLoadRemoteDataImpl(SOperatorInfo* pOperator) { taosArrayRemove(pExchangeInfo->pResultBlockList, 0); void* tmp = taosArrayPush(pExchangeInfo->pRecycledBlocks, &p); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); pTaskInfo->code = code; T_LONG_JMP(pTaskInfo->env, code); @@ -308,7 +308,7 @@ _end: static int32_t initDataSource(int32_t numOfSources, SExchangeInfo* pInfo, const char* id) { pInfo->pSourceDataInfo = taosArrayInit(numOfSources, sizeof(SSourceDataInfo)); if (pInfo->pSourceDataInfo == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (pInfo->dynamicOp) { @@ -329,7 +329,7 @@ static int32_t initDataSource(int32_t numOfSources, SExchangeInfo* pInfo, const SSourceDataInfo* pDs = taosArrayPush(pInfo->pSourceDataInfo, &dataInfo); if (pDs == NULL) { taosArrayDestroyEx(pInfo->pSourceDataInfo, freeSourceDataInfo); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -355,7 +355,7 @@ static int32_t initExchangeOperator(SExchangePhysiNode* pExNode, SExchangeInfo* pInfo->pSources = taosArrayInit(numOfSources, sizeof(SDownstreamSourceNode)); if (pInfo->pSources == NULL) { qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (pExNode->node.dynamicOp) { @@ -375,7 +375,7 @@ static int32_t initExchangeOperator(SExchangePhysiNode* pExNode, SExchangeInfo* void* tmp = taosArrayPush(pInfo->pSources, pNode); if (!tmp) { qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SExchangeSrcIndex idx = {.srcIdx = i, .inUseIdx = -1}; int32_t code = @@ -529,8 +529,6 @@ int32_t loadRemoteDataCallback(void* param, SDataBuf* pMsg, int32_t code) { } int32_t index = pWrapper->sourceIndex; - int64_t* pRpcHandle = taosArrayGet(pExchangeInfo->pFetchRpcHandles, index); - *pRpcHandle = -1; SSourceDataInfo* pSourceDataInfo = taosArrayGet(pExchangeInfo->pSourceDataInfo, index); if (!pSourceDataInfo) { return terrno; @@ -579,20 +577,20 @@ int32_t loadRemoteDataCallback(void* param, SDataBuf* pMsg, int32_t code) { int32_t buildTableScanOperatorParam(SOperatorParam** ppRes, SArray* pUidList, int32_t srcOpType, bool tableSeq) { *ppRes = taosMemoryMalloc(sizeof(SOperatorParam)); if (NULL == *ppRes) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } STableScanOperatorParam* pScan = taosMemoryMalloc(sizeof(STableScanOperatorParam)); if (NULL == pScan) { taosMemoryFreeClear(*ppRes); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pScan->pUidList = taosArrayDup(pUidList, NULL); if (NULL == pScan->pUidList) { taosMemoryFree(pScan); taosMemoryFreeClear(*ppRes); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pScan->tableSeq = tableSeq; @@ -1045,7 +1043,7 @@ int32_t addSingleExchangeSource(SOperatorInfo* pOperator, SExchangeOperatorBasic void* tmp = taosArrayPush(pExchangeInfo->pSourceDataInfo, &dataInfo); if (!tmp) { qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pIdx->inUseIdx = taosArrayGetSize(pExchangeInfo->pSourceDataInfo) - 1; } else { @@ -1096,6 +1094,7 @@ int32_t addDynamicExchangeSource(SOperatorInfo* pOperator) { int32_t prepareLoadRemoteData(SOperatorInfo* pOperator) { SExchangeInfo* pExchangeInfo = pOperator->info; int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; if ((OPTR_IS_OPENED(pOperator) && !pExchangeInfo->dynamicOp) || (pExchangeInfo->dynamicOp && NULL == pOperator->pOperatorGetParam)) { return TSDB_CODE_SUCCESS; @@ -1103,23 +1102,26 @@ int32_t prepareLoadRemoteData(SOperatorInfo* pOperator) { if (pExchangeInfo->dynamicOp) { code = addDynamicExchangeSource(pOperator); - if (code) { - return code; - } + QUERY_CHECK_CODE(code, lino, _end); } int64_t st = taosGetTimestampUs(); if (!pExchangeInfo->seqLoadData) { - int32_t code = prepareConcurrentlyLoad(pOperator); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + code = prepareConcurrentlyLoad(pOperator); + QUERY_CHECK_CODE(code, lino, _end); pExchangeInfo->openedTs = taosGetTimestampUs(); } OPTR_SET_OPENED(pOperator); pOperator->cost.openCost = (taosGetTimestampUs() - st) / 1000.0; + +_end: + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + pOperator->pTaskInfo->code = code; + T_LONG_JMP(pOperator->pTaskInfo->env, code); + } return TSDB_CODE_SUCCESS; } diff --git a/source/libs/executor/src/executil.c b/source/libs/executor/src/executil.c index 5225e8e4cd..c08dd817d0 100644 --- a/source/libs/executor/src/executil.c +++ b/source/libs/executor/src/executil.c @@ -622,14 +622,14 @@ int32_t getColInfoResultForGroupby(void* pVnode, SNodeList* group, STableListInf tagFilterAssist ctx = {0}; ctx.colHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_SMALLINT), false, HASH_NO_LOCK); if (ctx.colHash == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } ctx.index = 0; ctx.cInfoList = taosArrayInit(4, sizeof(SColumnInfo)); if (ctx.cInfoList == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } @@ -766,7 +766,7 @@ int32_t getColInfoResultForGroupby(void* pVnode, SNodeList* group, STableListInf pTableListInfo->remainGroups = taosHashInit(rows, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); if (pTableListInfo->remainGroups == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } } @@ -1024,7 +1024,7 @@ static int32_t optimizeTbnameInCondImpl(void* pVnode, SArray* pExistedUidList, S uHash = taosHashInit(numOfExisted / 0.7, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); if (!uHash) { qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int i = 0; i < numOfExisted; i++) { @@ -1052,7 +1052,7 @@ static int32_t optimizeTbnameInCondImpl(void* pVnode, SArray* pExistedUidList, S STUidTagInfo s = {.uid = uid, .name = name, .pTagVal = NULL}; void* tmp = taosArrayPush(pExistedUidList, &s); if (!tmp) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } } else { @@ -1193,13 +1193,13 @@ static int32_t doSetQualifiedUid(STableListInfo* pListInfo, SArray* pUidList, co info.uid = uid; void* p = taosArrayPush(pListInfo->pTableList, &info); if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (addUid) { void* tmp = taosArrayPush(pUidList, &uid); if (tmp == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } } @@ -1465,7 +1465,7 @@ _end: void* p = taosArrayPush(pListInfo->pTableList, &info); if (p == NULL) { taosArrayDestroy(pUidList); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } qTrace("tagfilter get uid:%" PRIu64 ", %s", info.uid, idstr); @@ -1652,7 +1652,7 @@ int32_t extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod SArray* pList = taosArrayInit(numOfCols, sizeof(SColMatchItem)); if (pList == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; return code; } @@ -2111,6 +2111,7 @@ SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, pCtx->saveHandle.currentPage = -1; pCtx->pStore = pStore; pCtx->hasWindowOrGroup = false; + pCtx->needCleanup = false; } for (int32_t i = 1; i < numOfOutput; ++i) { @@ -2643,7 +2644,7 @@ static int32_t sortTableGroup(STableListInfo* pTableListInfo) { pTableListInfo->groupOffset = taosMemoryMalloc(sizeof(int32_t) * pTableListInfo->numOfOuputGroups); if (pTableListInfo->groupOffset == NULL) { taosArrayDestroy(pList); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(pTableListInfo->groupOffset, taosArrayGet(pList, 0), sizeof(int32_t) * pTableListInfo->numOfOuputGroups); @@ -2666,7 +2667,7 @@ int32_t buildGroupIdMapForAllTables(STableListInfo* pTableListInfo, SReadHandle* pTableListInfo->remainGroups = taosHashInit(numOfTables, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); if (pTableListInfo->remainGroups == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int i = 0; i < numOfTables; i++) { diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index bfa4a56a77..6067f1cb66 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -488,7 +488,7 @@ int32_t qUpdateTableListForStreamScanner(qTaskInfo_t tinfo, const SArray* tableI keyBuf = taosMemoryMalloc(bufLen); if (keyBuf == NULL) { taosArrayDestroy(qa); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -877,7 +877,7 @@ int32_t qAppendTaskStopInfo(SExecTaskInfo* pTaskInfo, SExchangeOpStopInfo* pInfo if (!tmp) { qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return TSDB_CODE_SUCCESS; } diff --git a/source/libs/executor/src/executorInt.c b/source/libs/executor/src/executorInt.c index 4fef157984..5fc483087a 100644 --- a/source/libs/executor/src/executorInt.c +++ b/source/libs/executor/src/executorInt.c @@ -666,8 +666,8 @@ void doUpdateNumOfRows(SqlFunctionCtx* pCtx, SResultRow* pRow, int32_t numOfExpr } } -void copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx, - SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) { +int32_t copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultRow* pRow, SqlFunctionCtx* pCtx, + SSDataBlock* pBlock, const int32_t* rowEntryOffset, SExecTaskInfo* pTaskInfo) { int32_t code = TSDB_CODE_SUCCESS; int32_t lino = 0; for (int32_t j = 0; j < numOfExprs; ++j) { @@ -690,7 +690,7 @@ void copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultR int32_t winCode = pCtx[j].fpSet.finalize(&pCtx[j], pBlock); if (TAOS_FAILED(winCode)) { qError("%s build result data block error, code %s", GET_TASKID(pTaskInfo), tstrerror(winCode)); - T_LONG_JMP(pTaskInfo->env, winCode); + QUERY_CHECK_CODE(winCode, lino, _end); } } else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) { // do nothing @@ -710,8 +710,8 @@ void copyResultrowToDataBlock(SExprInfo* pExprInfo, int32_t numOfExprs, SResultR _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); - T_LONG_JMP(pTaskInfo->env, code); } + return code; } // todo refactor. SResultRow has direct pointer in miainfo @@ -747,7 +747,12 @@ void finalizeResultRows(SDiskbasedBuf* pBuf, SResultRowPosition* resultRowPositi T_LONG_JMP(pTaskInfo->env, code); } - copyResultrowToDataBlock(pExprInfo, pSup->numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo); + code = copyResultrowToDataBlock(pExprInfo, pSup->numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo); + if (TAOS_FAILED(code)) { + releaseBufPage(pBuf, page); + qError("%s copy result row to datablock failed, code %s", GET_TASKID(pTaskInfo), tstrerror(code)); + T_LONG_JMP(pTaskInfo->env, code); + } releaseBufPage(pBuf, page); pBlock->info.rows += pRow->numOfRows; @@ -818,9 +823,9 @@ void doCopyToSDataBlockByHash(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SEx pGroupResInfo->iter = iter; pGroupResInfo->dataPos = pData; - copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo); - + code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo); releaseBufPage(pBuf, page); + QUERY_CHECK_CODE(code, lino, _end); pBlock->info.rows += pRow->numOfRows; if (pBlock->info.rows >= threshold) { break; @@ -892,9 +897,10 @@ void doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprSupp } pGroupResInfo->index += 1; - copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo); - + code = copyResultrowToDataBlock(pExprInfo, numOfExprs, pRow, pCtx, pBlock, rowEntryOffset, pTaskInfo); releaseBufPage(pBuf, page); + QUERY_CHECK_CODE(code, lino, _end); + pBlock->info.rows += pRow->numOfRows; if (pBlock->info.rows >= threshold) { break; @@ -1014,10 +1020,6 @@ static void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_ } for (int32_t i = 0; i < numOfOutput; ++i) { - if (pCtx[i].fpSet.cleanup != NULL) { - pCtx[i].fpSet.cleanup(&pCtx[i]); - } - if (pExpr != NULL) { SExprInfo* pExprInfo = &pExpr[i]; for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) { @@ -1137,7 +1139,7 @@ int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* pDeleterParam->pUidList = taosArrayInit(numOfTables, sizeof(uint64_t)); if (NULL == pDeleterParam->pUidList) { taosMemoryFree(pDeleterParam); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int32_t i = 0; i < numOfTables; ++i) { @@ -1151,7 +1153,7 @@ int32_t createDataSinkParam(SDataSinkNode* pNode, void** pParam, SExecTaskInfo* if (!tmp) { taosArrayDestroy(pDeleterParam->pUidList); taosMemoryFree(pDeleterParam); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } diff --git a/source/libs/executor/src/filloperator.c b/source/libs/executor/src/filloperator.c index 76b41ca99a..d530382f7c 100644 --- a/source/libs/executor/src/filloperator.c +++ b/source/libs/executor/src/filloperator.c @@ -403,7 +403,7 @@ static int32_t createPrimaryTsExprIfNeeded(SFillOperatorInfo* pInfo, SFillPhysiN SExprInfo* pExpr = taosMemoryRealloc(pExprSupp->pExprInfo, (pExprSupp->numOfExprs + 1) * sizeof(SExprInfo)); if (pExpr == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = createExprFromTargetNode(&pExpr[pExprSupp->numOfExprs], (STargetNode*)pPhyFillNode->pWStartTs); diff --git a/source/libs/executor/src/groupcacheoperator.c b/source/libs/executor/src/groupcacheoperator.c index 17e18710f2..e4f6d73b7b 100644 --- a/source/libs/executor/src/groupcacheoperator.c +++ b/source/libs/executor/src/groupcacheoperator.c @@ -45,7 +45,7 @@ static int32_t initGroupColsInfo(SGroupColsInfo* pCols, bool grpColsMayBeNull, S pCols->withNull = grpColsMayBeNull; pCols->pColsInfo = taosMemoryMalloc(pCols->colNum * sizeof(SGroupColInfo)); if (NULL == pCols->pColsInfo) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t i = 0; @@ -67,7 +67,7 @@ static int32_t initGroupColsInfo(SGroupColsInfo* pCols, bool grpColsMayBeNull, S if (pCols->colNum > 1) { pCols->pBuf = taosMemoryMalloc(pCols->bufSize); if (NULL == pCols->pBuf) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -227,7 +227,7 @@ static int32_t acquireFdFromFileCtx(SGcFileCacheCtx* pFileCtx, int32_t fileId, S if (NULL == pFileCtx->pCacheFile) { pFileCtx->pCacheFile = taosHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK); if (NULL == pFileCtx->pCacheFile) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } taosHashSetFreeFp(pFileCtx->pCacheFile, freeSGroupCacheFileInfo); } @@ -373,8 +373,16 @@ _return: return code; } + +void freeGcBlkBufInfo(void* ptr) { + SGcBlkBufInfo* pBlk = (SGcBlkBufInfo*)ptr; + taosMemoryFreeClear(pBlk->pBuf); +} + + static int32_t addBlkToDirtyBufList(SGroupCacheOperatorInfo* pGCache, SGcDownstreamCtx* pCtx, SGcBlkCacheInfo* pCache, SGcBlkBufInfo* pBufInfo) { if (0 != taosHashPut(pCache->pDirtyBlk, &pBufInfo->basic.blkId, sizeof(pBufInfo->basic.blkId), pBufInfo, sizeof(*pBufInfo))) { + freeGcBlkBufInfo(pBufInfo); return TSDB_CODE_OUT_OF_MEMORY; } pBufInfo = taosHashGet(pCache->pDirtyBlk, &pBufInfo->basic.blkId, sizeof(pBufInfo->basic.blkId)); @@ -461,7 +469,7 @@ static int32_t addBlkToBufCache(struct SOperatorInfo* pOperator, SSDataBlock* pB pBufInfo->pBuf = taosMemoryMalloc(bufSize); if (NULL == pBufInfo->pBuf) { qError("group cache add block to cache failed, size:%" PRId64, bufSize); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } QRY_ERR_RET(blockDataToBuf(pBufInfo->pBuf, pBlock)); @@ -508,7 +516,7 @@ void blockDataDeepClear(SSDataBlock* pDataBlock) { static int32_t buildGroupCacheBaseBlock(SSDataBlock** ppDst, SSDataBlock* pSrc) { *ppDst = taosMemoryMalloc(sizeof(*pSrc)); if (NULL == *ppDst) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (*ppDst)->pBlockAgg = NULL; (*ppDst)->pDataBlock = taosArrayDup(pSrc->pDataBlock, NULL); @@ -578,7 +586,7 @@ static int32_t readBlockFromDisk(SGroupCacheOperatorInfo* pGCache, SGroupCacheDa *ppBuf = taosMemoryMalloc(pBasic->bufSize); if (NULL == *ppBuf) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _return; } @@ -643,7 +651,7 @@ static int32_t addNewGroupToVgHash(SOperatorInfo* pOperator, SSHashObj* pHash, S if (NULL == pVgCtx) { SArray* pList = taosArrayInit(10, sizeof(*pNew)); if (NULL == pList) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (NULL == taosArrayPush(pList, pNew)) { QRY_ERR_RET(terrno); @@ -798,7 +806,7 @@ static int32_t addFileRefTableNum(SGcFileCacheCtx* pFileCtx, int32_t fileId, int if (NULL == pFileCtx->pCacheFile) { pFileCtx->pCacheFile = taosHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK); if (NULL == pFileCtx->pCacheFile) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } taosHashSetFreeFp(pFileCtx->pCacheFile, freeSGroupCacheFileInfo); } @@ -913,7 +921,7 @@ static int32_t addNewGroupData(struct SOperatorInfo* pOperator, SOperatorParam* taosWLockLatch(&pCtx->grpLock); if (NULL == taosArrayPush(pCtx->pNewGrpList, &newGroup)) { taosWUnLockLatch(&pCtx->grpLock); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } taosWUnLockLatch(&pCtx->grpLock); @@ -1239,21 +1247,17 @@ _return: return code; } -void freeGcBlkBufInfo(void* ptr) { - SGcBlkBufInfo* pBlk = (SGcBlkBufInfo*)ptr; - taosMemoryFree(pBlk->pBuf); -} static int32_t initGroupCacheBlockCache(SGroupCacheOperatorInfo* pInfo) { SGcBlkCacheInfo* pCache = &pInfo->blkCache; pCache->pDirtyBlk = taosHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); if (NULL == pCache->pDirtyBlk) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } taosHashSetFreeFp(pCache->pDirtyBlk, freeGcBlkBufInfo); pCache->pReadBlk = taosHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); if (NULL == pCache->pReadBlk) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pCache->writeDownstreamId = -1; @@ -1421,30 +1425,30 @@ static int32_t initGroupCacheDownstreamCtx(SOperatorInfo* pOperator) { pCtx->pNewGrpList = taosArrayInit(10, sizeof(SGcNewGroupInfo)); if (NULL == pCtx->pNewGrpList) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (!pInfo->globalGrp) { pCtx->pGrpHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); if (pCtx->pGrpHash == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } taosHashSetFreeFp(pCtx->pGrpHash, freeRemoveGroupCacheData); } pCtx->pSessions = taosHashInit(20, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); if (pCtx->pSessions == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } taosHashSetFreeFp(pCtx->pSessions, freeSGcSessionCtx); pCtx->pFreeBlock = taosArrayInit(10, POINTER_BYTES); if (NULL == pCtx->pFreeBlock) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pCtx->pWaitSessions = taosHashInit(20, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK); if (pCtx->pWaitSessions == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)snprintf(pCtx->fileCtx.baseFilename, sizeof(pCtx->fileCtx.baseFilename) - 1, "%s/gc_%d_%" PRIx64 "_%" PRIu64 "_%d", @@ -1539,7 +1543,7 @@ int32_t createGroupCacheOperatorInfo(SOperatorInfo** pDownstream, int32_t numOfD if (pInfo->globalGrp) { pInfo->pGrpHash = taosHashInit(32, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); if (pInfo->pGrpHash == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _error; } taosHashSetFreeFp(pInfo->pGrpHash, freeRemoveGroupCacheData); diff --git a/source/libs/executor/src/groupoperator.c b/source/libs/executor/src/groupoperator.c index 6c52dbaed0..2df235c0d9 100644 --- a/source/libs/executor/src/groupoperator.c +++ b/source/libs/executor/src/groupoperator.c @@ -39,6 +39,7 @@ typedef struct SGroupbyOperatorInfo { int32_t groupKeyLen; // total group by column width SGroupResInfo groupResInfo; SExprSupp scalarSup; + SOperatorInfo *pOperator; } SGroupbyOperatorInfo; // The sort in partition may be needed later. @@ -85,16 +86,18 @@ static void destroyGroupOperatorInfo(void* param) { taosArrayDestroy(pInfo->pGroupCols); taosArrayDestroyEx(pInfo->pGroupColVals, freeGroupKey); cleanupExprSupp(&pInfo->scalarSup); - + cleanupResultInfo(pInfo->pOperator->pTaskInfo, &pInfo->pOperator->exprSupp, pInfo->aggSup.pResultBuf, + &pInfo->groupResInfo, pInfo->aggSup.pResultRowHashTable); cleanupGroupResInfo(&pInfo->groupResInfo); cleanupAggSup(&pInfo->aggSup); + pInfo->pOperator = NULL; taosMemoryFreeClear(param); } static int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char** keyBuf, const SArray* pGroupColList) { *pGroupColVals = taosArrayInit(4, sizeof(SGroupKeys)); if ((*pGroupColVals) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t numOfGroupCols = taosArrayGetSize(pGroupColList); @@ -117,7 +120,7 @@ static int32_t initGroupOptrInfo(SArray** pGroupColVals, int32_t* keyLen, char** void* tmp = taosArrayPush((*pGroupColVals), &key); if (!tmp) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -329,8 +332,11 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) { } int32_t rowIndex = j - num; - applyAggFunctionOnPartialTuples(pTaskInfo, pCtx, NULL, rowIndex, num, pBlock->info.rows, - pOperator->exprSupp.numOfExprs); + ret = applyAggFunctionOnPartialTuples(pTaskInfo, pCtx, NULL, rowIndex, num, pBlock->info.rows, + pOperator->exprSupp.numOfExprs); + if (ret != TSDB_CODE_SUCCESS) { + T_LONG_JMP(pTaskInfo->env, ret); + } // assign the group keys or user input constant values if required doAssignGroupKeys(pCtx, pOperator->exprSupp.numOfExprs, pBlock->info.rows, rowIndex); @@ -347,8 +353,11 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) { } int32_t rowIndex = pBlock->info.rows - num; - applyAggFunctionOnPartialTuples(pTaskInfo, pCtx, NULL, rowIndex, num, pBlock->info.rows, - pOperator->exprSupp.numOfExprs); + ret = applyAggFunctionOnPartialTuples(pTaskInfo, pCtx, NULL, rowIndex, num, pBlock->info.rows, + pOperator->exprSupp.numOfExprs); + if (ret != TSDB_CODE_SUCCESS) { + T_LONG_JMP(pTaskInfo->env, ret); + } doAssignGroupKeys(pCtx, pOperator->exprSupp.numOfExprs, pBlock->info.rows, rowIndex); } } @@ -441,7 +450,7 @@ static int32_t hashGroupbyAggregateNext(SOperatorInfo* pOperator, SSDataBlock** QRY_PARAM_CHECK(ppRes); if (pOperator->status == OP_EXEC_DONE) { - return TSDB_CODE_SUCCESS; + return code; } if (pOperator->status == OP_RES_TO_RETURN) { @@ -493,6 +502,7 @@ _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); } else { (*ppRes) = buildGroupResultDataBlockByHash(pOperator); } @@ -563,6 +573,8 @@ int32_t createGroupOperatorInfo(SOperatorInfo* downstream, SAggPhysiNode* pAggNo pInfo->binfo.inputTsOrder = pAggNode->node.inputTsOrder; pInfo->binfo.outputTsOrder = pAggNode->node.outputTsOrder; + pInfo->pOperator = pOperator; + pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, hashGroupbyAggregateNext, NULL, destroyGroupOperatorInfo, optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL); code = appendDownstream(pOperator, &downstream, 1); @@ -1522,8 +1534,9 @@ static int32_t doStreamHashPartitionNext(SOperatorInfo* pOperator, SSDataBlock** _end: if (code != TSDB_CODE_SUCCESS) { - pTaskInfo->code = code; qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); } (*ppRes) = NULL; return code; @@ -1758,7 +1771,7 @@ int32_t extractColumnInfo(SNodeList* pNodeList, SArray** pArrayRes) { size_t numOfCols = LIST_LENGTH(pNodeList); SArray* pList = taosArrayInit(numOfCols, sizeof(SColumn)); if (pList == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; (*pArrayRes) = NULL; QUERY_CHECK_CODE(code, lino, _end); } diff --git a/source/libs/executor/src/hashjoinoperator.c b/source/libs/executor/src/hashjoinoperator.c index 7f13608653..1f43a429b3 100644 --- a/source/libs/executor/src/hashjoinoperator.c +++ b/source/libs/executor/src/hashjoinoperator.c @@ -155,7 +155,7 @@ static int32_t hJoinInitKeyColsInfo(SHJoinTableCtx* pTable, SNodeList* pList) { pTable->keyCols = taosMemoryMalloc(pTable->keyNum * sizeof(SHJoinColInfo)); if (NULL == pTable->keyCols) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int64_t bufSize = 0; @@ -173,7 +173,7 @@ static int32_t hJoinInitKeyColsInfo(SHJoinTableCtx* pTable, SNodeList* pList) { if (pTable->keyNum > 1) { pTable->keyBuf = taosMemoryMalloc(bufSize); if (NULL == pTable->keyBuf) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -212,7 +212,7 @@ static int32_t hJoinInitValColsInfo(SHJoinTableCtx* pTable, SNodeList* pList) { pTable->valCols = taosMemoryMalloc(pTable->valNum * sizeof(SHJoinColInfo)); if (NULL == pTable->valCols) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t i = 0; @@ -260,7 +260,7 @@ static int32_t hJoinInitValColsInfo(SHJoinTableCtx* pTable, SNodeList* pList) { static int32_t hJoinInitPrimKeyInfo(SHJoinTableCtx* pTable, int32_t slotId) { pTable->primCol = taosMemoryMalloc(sizeof(SHJoinColMap)); if (NULL == pTable->primCol) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pTable->primCol->srcSlot = slotId; @@ -413,7 +413,7 @@ static FORCE_INLINE int32_t hJoinAddPageToBufs(SArray* pRowBufs) { page.offset = 0; page.data = taosMemoryMalloc(page.pageSize); if (NULL == page.data) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (NULL == taosArrayPush(pRowBufs, &page)) { @@ -425,7 +425,7 @@ static FORCE_INLINE int32_t hJoinAddPageToBufs(SArray* pRowBufs) { static int32_t hJoinInitBufPages(SHJoinOperatorInfo* pInfo) { pInfo->pRowBufs = taosArrayInit(32, sizeof(SBufPageInfo)); if (NULL == pInfo->pRowBufs) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return hJoinAddPageToBufs(pInfo->pRowBufs); @@ -784,13 +784,13 @@ static int32_t hJoinAddRowToHashImpl(SHJoinOperatorInfo* pJoin, SGroupData* pGro if (NULL == pGroup) { group.rows = taosMemoryMalloc(sizeof(SBufRowInfo)); if (NULL == group.rows) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pRow = group.rows; } else { pRow = taosMemoryMalloc(sizeof(SBufRowInfo)); if (NULL == pRow) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -993,6 +993,7 @@ static int32_t hJoinMainProcess(struct SOperatorInfo* pOperator, SSDataBlock** p SHJoinOperatorInfo* pJoin = pOperator->info; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; SSDataBlock* pRes = pJoin->finBlk; int64_t st = 0; @@ -1003,7 +1004,7 @@ static int32_t hJoinMainProcess(struct SOperatorInfo* pOperator, SSDataBlock** p if (pOperator->status == OP_EXEC_DONE) { pRes->info.rows = 0; - goto _return; + goto _end; } if (!pJoin->keyHashBuilt) { @@ -1011,13 +1012,10 @@ static int32_t hJoinMainProcess(struct SOperatorInfo* pOperator, SSDataBlock** p bool queryDone = false; code = hJoinBuildHash(pOperator, &queryDone); - if (code) { - pTaskInfo->code = code; - return code; - } + QUERY_CHECK_CODE(code, lino, _end); if (queryDone) { - goto _return; + goto _end; } } @@ -1025,17 +1023,11 @@ static int32_t hJoinMainProcess(struct SOperatorInfo* pOperator, SSDataBlock** p if (pJoin->ctx.rowRemains) { code = (*pJoin->joinFp)(pOperator); - if (code) { - pTaskInfo->code = code; - return pTaskInfo->code; - } + QUERY_CHECK_CODE(code, lino, _end); if (pRes->info.rows > 0 && pJoin->pFinFilter != NULL) { code = doFilter(pRes, pJoin->pFinFilter, NULL); - if (code) { - pTaskInfo->code = code; - return pTaskInfo->code; - } + QUERY_CHECK_CODE(code, lino, _end); } if (pRes->info.rows > 0) { @@ -1055,10 +1047,7 @@ static int32_t hJoinMainProcess(struct SOperatorInfo* pOperator, SSDataBlock** p pJoin->execInfo.probeBlkRows += pBlock->info.rows; code = hJoinPrepareStart(pOperator, pBlock); - if (code) { - pTaskInfo->code = code; - return pTaskInfo->code; - } + QUERY_CHECK_CODE(code, lino, _end); if (!hJoinBlkReachThreshold(pJoin, pRes->info.rows)) { continue; @@ -1066,10 +1055,7 @@ static int32_t hJoinMainProcess(struct SOperatorInfo* pOperator, SSDataBlock** p if (pRes->info.rows > 0 && pJoin->pFinFilter != NULL) { code = doFilter(pRes, pJoin->pFinFilter, NULL); - if (code) { - pTaskInfo->code = code; - return pTaskInfo->code; - } + QUERY_CHECK_CODE(code, lino, _end); } if (pRes->info.rows > 0) { @@ -1077,11 +1063,15 @@ static int32_t hJoinMainProcess(struct SOperatorInfo* pOperator, SSDataBlock** p } } -_return: +_end: if (pOperator->cost.openCost == 0) { pOperator->cost.openCost = (taosGetTimestampUs() - st) / 1000.0; } - + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); + } if (pRes->info.rows > 0) { *pResBlock = pRes; } diff --git a/source/libs/executor/src/mergejoinoperator.c b/source/libs/executor/src/mergejoinoperator.c index af5e4ed235..e007504ffb 100644 --- a/source/libs/executor/src/mergejoinoperator.c +++ b/source/libs/executor/src/mergejoinoperator.c @@ -1731,6 +1731,7 @@ int32_t mJoinMainProcess(struct SOperatorInfo* pOperator, SSDataBlock** pResBloc if (pJoin->pFinFilter != NULL) { code = doFilter(pBlock, pJoin->pFinFilter, NULL); if (code) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); pJoin->errCode = code; T_LONG_JMP(pOperator->pTaskInfo->env, pJoin->errCode); } diff --git a/source/libs/executor/src/mergeoperator.c b/source/libs/executor/src/mergeoperator.c index 49973ac373..45cd755f78 100644 --- a/source/libs/executor/src/mergeoperator.c +++ b/source/libs/executor/src/mergeoperator.c @@ -492,6 +492,8 @@ int32_t openMultiwayMergeOperator(SOperatorInfo* pOperator) { pOperator->status = OP_RES_TO_RETURN; if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); + pOperator->pTaskInfo->code = code; T_LONG_JMP(pTaskInfo->env, terrno); } @@ -501,6 +503,8 @@ int32_t openMultiwayMergeOperator(SOperatorInfo* pOperator) { int32_t doMultiwayMerge(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { QRY_PARAM_CHECK(pResBlock); + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; if (pOperator->status == OP_EXEC_DONE) { return 0; @@ -509,18 +513,12 @@ int32_t doMultiwayMerge(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SMultiwayMergeOperatorInfo* pInfo = pOperator->info; - int32_t code = pOperator->fpSet._openFn(pOperator); - if (code != TSDB_CODE_SUCCESS) { - pTaskInfo->code = code; - return code; - } + code = pOperator->fpSet._openFn(pOperator); + QUERY_CHECK_CODE(code, lino, _end); if (NULL != gMultiwayMergeFps[pInfo->type].getNextFn) { code = (*gMultiwayMergeFps[pInfo->type].getNextFn)(pOperator, pResBlock); - if (code) { - pTaskInfo->code = code; - return code; - } + QUERY_CHECK_CODE(code, lino, _end); } if ((*pResBlock) != NULL) { @@ -530,6 +528,12 @@ int32_t doMultiwayMerge(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { setOperatorCompleted(pOperator); } +_end: + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); + } return code; } diff --git a/source/libs/executor/src/operator.c b/source/libs/executor/src/operator.c index 3bdcdd084a..33f46ec73b 100644 --- a/source/libs/executor/src/operator.c +++ b/source/libs/executor/src/operator.c @@ -669,13 +669,11 @@ void destroyOperator(SOperatorInfo* pOperator) { pOperator->numOfDownstream = 0; } - cleanupExprSupp(&pOperator->exprSupp); - - // close operator after cleanup exprSupp, since we need to call cleanup of sqlFunctionCtx first to avoid mem leak. if (pOperator->fpSet.closeFn != NULL && pOperator->info != NULL) { pOperator->fpSet.closeFn(pOperator->info); } + cleanupExprSupp(&pOperator->exprSupp); taosMemoryFreeClear(pOperator); } @@ -885,14 +883,17 @@ SSDataBlock* getNextBlockFromDownstreamRemain(struct SOperatorInfo* pOperator, i int32_t optrDefaultGetNextExtFn(struct SOperatorInfo* pOperator, SOperatorParam* pParam, SSDataBlock** pRes) { QRY_PARAM_CHECK(pRes); + int32_t lino = 0; int32_t code = setOperatorParams(pOperator, pParam, OP_GET_PARAM); - if (TSDB_CODE_SUCCESS != code) { + QUERY_CHECK_CODE(code, lino, _end); + code = pOperator->fpSet.getNextFn(pOperator, pRes); + QUERY_CHECK_CODE(code, lino, _end); + +_end: + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); pOperator->pTaskInfo->code = code; - } else { - code = pOperator->fpSet.getNextFn(pOperator, pRes); - if (code) { - pOperator->pTaskInfo->code = code; - } + T_LONG_JMP(pOperator->pTaskInfo->env, code); } return code; diff --git a/source/libs/executor/src/projectoperator.c b/source/libs/executor/src/projectoperator.c index 790e97b27c..5b9e531679 100644 --- a/source/libs/executor/src/projectoperator.c +++ b/source/libs/executor/src/projectoperator.c @@ -270,6 +270,7 @@ int32_t doProjectOperation(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { SSDataBlock* pRes = pInfo->pRes; SSDataBlock* pFinalRes = pProjectInfo->pFinalRes; int32_t code = 0; + int32_t lino = 0; int64_t st = 0; int32_t order = pInfo->inputTsOrder; int32_t scanFlag = 0; @@ -290,9 +291,7 @@ int32_t doProjectOperation(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { if (downstream == NULL) { code = doGenerateSourceData(pOperator); - if (code != TSDB_CODE_SUCCESS) { - T_LONG_JMP(pTaskInfo->env, code); - } + QUERY_CHECK_CODE(code, lino, _end); if (pProjectInfo->outputIgnoreGroup) { pRes->info.id.groupId = 0; @@ -348,20 +347,14 @@ int32_t doProjectOperation(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { } code = setInputDataBlock(pSup, pBlock, order, scanFlag, false); - if (code) { - T_LONG_JMP(pTaskInfo->env, code); - } + QUERY_CHECK_CODE(code, lino, _end); code = blockDataEnsureCapacity(pInfo->pRes, pInfo->pRes->info.rows + pBlock->info.rows); - if (code != TSDB_CODE_SUCCESS) { - T_LONG_JMP(pTaskInfo->env, code); - } + QUERY_CHECK_CODE(code, lino, _end); code = projectApplyFunctions(pSup->pExprInfo, pInfo->pRes, pBlock, pSup->pCtx, pSup->numOfExprs, pProjectInfo->pPseudoColInfo); - if (code != TSDB_CODE_SUCCESS) { - T_LONG_JMP(pTaskInfo->env, code); - } + QUERY_CHECK_CODE(code, lino, _end); status = doIngroupLimitOffset(pLimitInfo, pBlock->info.id.groupId, pInfo->pRes, pOperator); if (status == PROJECT_RETRIEVE_CONTINUE) { @@ -377,11 +370,8 @@ int32_t doProjectOperation(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { pFinalRes->info.version = pRes->info.version; // continue merge data, ignore the group id - int32_t ret = blockDataMerge(pFinalRes, pRes); - if (ret < 0) { - pTaskInfo->code = code; - return code; - } + code = blockDataMerge(pFinalRes, pRes); + QUERY_CHECK_CODE(code, lino, _end); if (pFinalRes->info.rows + pRes->info.rows <= pOperator->resultInfo.threshold && (pOperator->status != OP_EXEC_DONE)) { continue; @@ -390,10 +380,7 @@ int32_t doProjectOperation(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { // do apply filter code = doFilter(pFinalRes, pOperator->exprSupp.pFilterInfo, NULL); - if (code) { - pTaskInfo->code = code; - return code; - } + QUERY_CHECK_CODE(code, lino, _end); // when apply the limit/offset for each group, pRes->info.rows may be 0, due to limit constraint. if (pFinalRes->info.rows > 0 || (pOperator->status == OP_EXEC_DONE)) { @@ -404,10 +391,7 @@ int32_t doProjectOperation(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { // do apply filter if (pRes->info.rows > 0) { code = doFilter(pRes, pOperator->exprSupp.pFilterInfo, NULL); - if (code) { - pTaskInfo->code = code; - return code; - } + QUERY_CHECK_CODE(code, lino, _end); if (pRes->info.rows == 0) { continue; @@ -436,6 +420,13 @@ int32_t doProjectOperation(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { } *pResBlock = (p->info.rows > 0)? p:NULL; + +_end: + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); + } return code; } @@ -578,14 +569,15 @@ int32_t doApplyIndefinitFunction(SOperatorInfo* pOperator, SSDataBlock** pResBlo SOptrBasicInfo* pInfo = &pIndefInfo->binfo; SExprSupp* pSup = &pOperator->exprSupp; int64_t st = 0; - int32_t code = 0; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; SSDataBlock* pRes = pInfo->pRes; blockDataCleanup(pRes); SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; if (pOperator->status == OP_EXEC_DONE) { - return 0; + return code; } if (pOperator->cost.openCost == 0) { @@ -637,10 +629,7 @@ int32_t doApplyIndefinitFunction(SOperatorInfo* pOperator, SSDataBlock** pResBlo } code = doFilter(pInfo->pRes, pOperator->exprSupp.pFilterInfo, NULL); - if (code) { - pTaskInfo->code = code; - return code; - } + QUERY_CHECK_CODE(code, lino, _end); size_t rows = pInfo->pRes->info.rows; if (rows > 0 || pOperator->status == OP_EXEC_DONE) { @@ -658,6 +647,13 @@ int32_t doApplyIndefinitFunction(SOperatorInfo* pOperator, SSDataBlock** pResBlo } *pResBlock = (rows > 0) ? pInfo->pRes : NULL; + +_end: + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); + } return code; } diff --git a/source/libs/executor/src/querytask.c b/source/libs/executor/src/querytask.c index cb0ebcff70..37461382dd 100644 --- a/source/libs/executor/src/querytask.c +++ b/source/libs/executor/src/querytask.c @@ -54,7 +54,7 @@ int32_t doCreateTask(uint64_t queryId, uint64_t taskId, int32_t vgId, EOPTR_EXEC p->pResultBlockList = taosArrayInit(128, POINTER_BYTES); if (p->stopInfo.pStopInfo == NULL || p->pResultBlockList == NULL) { doDestroyTask(p); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } p->storageAPI = *pAPI; @@ -73,7 +73,7 @@ int32_t doCreateTask(uint64_t queryId, uint64_t taskId, int32_t vgId, EOPTR_EXEC p->schemaInfos = taosArrayInit(1, sizeof(SSchemaInfo)); if (p->id.str == NULL || p->schemaInfos == NULL) { doDestroyTask(p); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } *pTaskInfo = p; diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 502d88b26d..7cb73ee88e 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -191,7 +191,7 @@ static int32_t insertTableToScanIgnoreList(STableScanInfo* pTableScanInfo, uint6 pTableScanInfo->pIgnoreTables = taosHashInit(tableNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK); if (NULL == pTableScanInfo->pIgnoreTables) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -951,7 +951,8 @@ static int32_t doTableScanImplNext(SOperatorInfo* pOperator, SSDataBlock** ppRes if (isTaskKilled(pTaskInfo)) { pAPI->tsdReader.tsdReaderReleaseDataBlock(pTableScanInfo->base.dataReader); - return pTaskInfo->code; + code = pTaskInfo->code; + goto _end; } if (pOperator->status == OP_EXEC_DONE) { @@ -996,6 +997,7 @@ _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); } return code; } @@ -1169,7 +1171,7 @@ static int32_t createTableListInfoFromParam(SOperatorInfo* pOperator) { info.uid = *pUid; void* p = taosArrayPush(pListInfo->pTableList, &info); if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } tableIdx++; @@ -1416,6 +1418,7 @@ _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); } return code; @@ -3123,8 +3126,9 @@ static int32_t doQueueScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { if (pResult && pResult->info.rows > 0) { bool hasPrimaryKey = pAPI->tqReaderFn.tqGetTablePrimaryKey(pInfo->tqReader); code = processPrimaryKey(pResult, hasPrimaryKey, &pTaskInfo->streamInfo.currentOffset); + QUERY_CHECK_CODE(code, lino, _end); qDebug("tmqsnap doQueueScan get data utid:%" PRId64 "", pResult->info.id.uid); - if (pResult->info.rows > 0 || code != TSDB_CODE_SUCCESS) { + if (pResult->info.rows > 0) { (*ppRes) = pResult; return code; } @@ -3188,8 +3192,9 @@ static int32_t doQueueScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { _end: if (code != TSDB_CODE_SUCCESS) { - pTaskInfo->code = code; qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); } (*ppRes) = NULL; return code; @@ -3527,9 +3532,7 @@ FETCH_NEXT_BLOCK: if (pBlock->info.parTbName[0]) { code = pAPI->stateStore.streamStatePutParName(pStreamInfo->pState, pBlock->info.id.groupId, pBlock->info.parTbName); - if (code != TSDB_CODE_SUCCESS) { - qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); - } + QUERY_CHECK_CODE(code, lino, _end); } // TODO move into scan @@ -3678,7 +3681,7 @@ FETCH_NEXT_BLOCK: return code; } qError("%s===stream=== %s failed at line %d since pInfo->pUpdateRes is empty", GET_TASKID(pTaskInfo), __func__, - lino); + __LINE__); blockDataCleanup(pInfo->pUpdateDataRes); pInfo->scanMode = STREAM_SCAN_FROM_READERHANDLE; } break; @@ -3692,7 +3695,7 @@ FETCH_NEXT_BLOCK: return code; } qError("%s===stream=== %s failed at line %d since pInfo->pUpdateRes is empty", GET_TASKID(pTaskInfo), __func__, - lino); + __LINE__); blockDataCleanup(pInfo->pUpdateDataRes); pInfo->scanMode = STREAM_SCAN_FROM_READERHANDLE; } break; @@ -3854,8 +3857,9 @@ FETCH_NEXT_BLOCK: _end: if (code != TSDB_CODE_SUCCESS) { - pTaskInfo->code = code; qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); } (*ppRes) = NULL; return code; @@ -3926,6 +3930,7 @@ static int32_t doRawScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { if (pBlock && pBlock->info.rows > 0) { bool hasPrimaryKey = pAPI->snapshotFn.taosXGetTablePrimaryKey(pInfo->sContext); code = processPrimaryKey(pBlock, hasPrimaryKey, &pTaskInfo->streamInfo.currentOffset); + QUERY_CHECK_CODE(code, lino, _end); qDebug("tmqsnap doRawScan get data uid:%" PRId64 "", pBlock->info.id.uid); (*ppRes) = pBlock; return code; @@ -3937,7 +3942,7 @@ static int32_t doRawScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { QUERY_CHECK_CODE(code, lino, _end); if (code != 0) { tDeleteSchemaWrapper(mtInfo.schema); - goto _end; + QUERY_CHECK_CODE(code, lino, _end); } STqOffsetVal offset = {0}; if (mtInfo.uid == 0 || pInfo->sContext->withMeta == ONLY_META) { // read snapshot done, change to get data from wal @@ -4027,6 +4032,7 @@ _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); } (*ppRes) = NULL; @@ -4875,6 +4881,7 @@ _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); } return code; @@ -4882,6 +4889,7 @@ _end: static int32_t doTagScanFromMetaEntryNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; if (pOperator->status == OP_EXEC_DONE) { (*ppRes) = NULL; return code; @@ -4897,10 +4905,7 @@ static int32_t doTagScanFromMetaEntryNext(SOperatorInfo* pOperator, SSDataBlock* int32_t size = 0; code = tableListGetSize(pInfo->pTableListInfo, &size); - if (code != TSDB_CODE_SUCCESS) { - qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); - return code; - } + QUERY_CHECK_CODE(code, lino, _end); if (size == 0) { setTaskStatus(pTaskInfo, TASK_COMPLETED); @@ -4914,11 +4919,11 @@ static int32_t doTagScanFromMetaEntryNext(SOperatorInfo* pOperator, SSDataBlock* while (pInfo->curPos < size && count < pOperator->resultInfo.capacity) { code = doTagScanOneTable(pOperator, pRes, count, &mr, &pTaskInfo->storageAPI); - if (code == TSDB_CODE_OUT_OF_MEMORY) { - break; - } else { + if (code != TSDB_CODE_OUT_OF_MEMORY) { // ignore other error + code = TSDB_CODE_SUCCESS; } + QUERY_CHECK_CODE(code, lino, _end); ++count; if (++pInfo->curPos >= size) { @@ -4942,6 +4947,13 @@ static int32_t doTagScanFromMetaEntryNext(SOperatorInfo* pOperator, SSDataBlock* pOperator->resultInfo.totalRows += pRes->info.rows; (*ppRes) = (pRes->info.rows == 0) ? NULL : pInfo->pRes; + +_end: + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); + } return code; } @@ -5627,6 +5639,7 @@ _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); } else { (*ppRes) = pBlock; } @@ -6143,6 +6156,7 @@ _end: if (code != TSDB_CODE_SUCCESS) { qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); } else { (*ppRes) = pBlock; } @@ -6658,7 +6672,12 @@ static int32_t doTableCountScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRe } code = buildVnodeDbTableCount(pOperator, pInfo, pSupp, pRes); - if ((pRes->info.rows > 0) && (code == 0)) { + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed since %s", __func__, tstrerror(code)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); + } + if (pRes->info.rows > 0) { *ppRes = pRes; } diff --git a/source/libs/executor/src/sortoperator.c b/source/libs/executor/src/sortoperator.c index 27ae5e7281..11b3fa8c70 100644 --- a/source/libs/executor/src/sortoperator.c +++ b/source/libs/executor/src/sortoperator.c @@ -349,82 +349,84 @@ void applyScalarFunction(SSDataBlock* pBlock, void* param) { int32_t doOpenSortOperator(SOperatorInfo* pOperator) { SSortOperatorInfo* pInfo = pOperator->info; SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; + SSortSource* pSource =NULL; if (OPTR_IS_OPENED(pOperator)) { - return TSDB_CODE_SUCCESS; + return code; } pInfo->startTs = taosGetTimestampUs(); // pInfo->binfo.pRes is not equalled to the input datablock. pInfo->pSortHandle = NULL; - int32_t code = + code = tsortCreateSortHandle(pInfo->pSortInfo, SORT_SINGLESOURCE_SORT, -1, -1, NULL, pTaskInfo->id.str, pInfo->maxRows, pInfo->maxTupleLength, tsPQSortMemThreshold * 1024 * 1024, &pInfo->pSortHandle); - if (code) { - return code; - } + QUERY_CHECK_CODE(code, lino, _end); tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock, applyScalarFunction, pOperator); - SSortSource* pSource = taosMemoryCalloc(1, sizeof(SSortSource)); - if (pSource == NULL) { - return terrno; - } + pSource = taosMemoryCalloc(1, sizeof(SSortSource)); + QUERY_CHECK_NULL(pSource, code, lino, _end, terrno); pSource->param = pOperator->pDownstream[0]; pSource->onlyRef = true; code = tsortAddSource(pInfo->pSortHandle, pSource); - if (code) { - taosMemoryFree(pSource); - return code; - } + QUERY_CHECK_CODE(code, lino, _end); + pSource = NULL; code = tsortOpen(pInfo->pSortHandle); - if (code != TSDB_CODE_SUCCESS) { - pTaskInfo->code = code; - } else { - pOperator->cost.openCost = (taosGetTimestampUs() - pInfo->startTs) / 1000.0; - pOperator->status = OP_RES_TO_RETURN; - OPTR_SET_OPENED(pOperator); - } + QUERY_CHECK_CODE(code, lino, _end); + pOperator->cost.openCost = (taosGetTimestampUs() - pInfo->startTs) / 1000.0; + pOperator->status = OP_RES_TO_RETURN; + OPTR_SET_OPENED(pOperator); +_end: + if (pSource) { + taosMemoryFree(pSource); + } + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); + } return code; } int32_t doSort(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { QRY_PARAM_CHECK(pResBlock); + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; if (pOperator->status == OP_EXEC_DONE) { - return 0; + return code; } SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SSortOperatorInfo* pInfo = pOperator->info; - int32_t code = pOperator->fpSet._openFn(pOperator); - if (code != TSDB_CODE_SUCCESS) { - return code; - } + code = pOperator->fpSet._openFn(pOperator); + QUERY_CHECK_CODE(code, lino, _end); // multi-group case not handle here SSDataBlock* pBlock = NULL; while (1) { if (tsortIsClosed(pInfo->pSortHandle)) { code = TSDB_CODE_TSC_QUERY_CANCELLED; - T_LONG_JMP(pTaskInfo->env, code); + QUERY_CHECK_CODE(code, lino, _end); } code = getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, pInfo->matchInfo.pList, pInfo, &pBlock); - if (pBlock == NULL || code != 0) { + QUERY_CHECK_CODE(code, lino, _end); + if (pBlock == NULL) { setOperatorCompleted(pOperator); return code; } code = doFilter(pBlock, pOperator->exprSupp.pFilterInfo, &pInfo->matchInfo); - if (code) { - break; - } + QUERY_CHECK_CODE(code, lino, _end); if (blockDataGetNumOfRows(pBlock) == 0) { continue; @@ -443,6 +445,12 @@ int32_t doSort(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { } *pResBlock = blockDataGetNumOfRows(pBlock) > 0 ? pBlock : NULL; +_end: + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); + } return code; } @@ -692,16 +700,16 @@ int32_t doGroupSort(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { QRY_PARAM_CHECK(pResBlock); SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; SGroupSortOperatorInfo* pInfo = pOperator->info; + int32_t code = TSDB_CODE_SUCCESS; + int32_t lino = 0; if (pOperator->status == OP_EXEC_DONE) { - return 0; - } - - int32_t code = pOperator->fpSet._openFn(pOperator); - if (code != TSDB_CODE_SUCCESS) { return code; } + code = pOperator->fpSet._openFn(pOperator); + QUERY_CHECK_CODE(code, lino, _end); + if (!pInfo->hasGroupId) { pInfo->hasGroupId = true; @@ -714,28 +722,26 @@ int32_t doGroupSort(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { pInfo->currGroupId = pInfo->prefetchedSortInput->info.id.groupId; pInfo->childOpStatus = CHILD_OP_NEW_GROUP; code = beginSortGroup(pOperator); - if (code) { - return code; - } + QUERY_CHECK_CODE(code, lino, _end); } SSDataBlock* pBlock = NULL; while (pInfo->pCurrSortHandle != NULL) { if (tsortIsClosed(pInfo->pCurrSortHandle)) { code = TSDB_CODE_TSC_QUERY_CANCELLED; - T_LONG_JMP(pTaskInfo->env, code); + QUERY_CHECK_CODE(code, lino, _end); } // beginSortGroup would fetch all child blocks of pInfo->currGroupId; if (pInfo->childOpStatus == CHILD_OP_SAME_GROUP) { - pTaskInfo->code = code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; - qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code)); - return code; + code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; + QUERY_CHECK_CODE(code, lino, _end); } code = getGroupSortedBlockData(pInfo->pCurrSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, pInfo->matchInfo.pList, pInfo, &pBlock); - if (pBlock != NULL && (code == 0)) { + QUERY_CHECK_CODE(code, lino, _end); + if (pBlock != NULL) { pBlock->info.id.groupId = pInfo->currGroupId; pOperator->resultInfo.totalRows += pBlock->info.rows; *pResBlock = pBlock; @@ -745,6 +751,7 @@ int32_t doGroupSort(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { (void) finishSortGroup(pOperator); pInfo->currGroupId = pInfo->prefetchedSortInput->info.id.groupId; code = beginSortGroup(pOperator); + QUERY_CHECK_CODE(code, lino, _end); } else if (pInfo->childOpStatus == CHILD_OP_FINISHED) { (void) finishSortGroup(pOperator); setOperatorCompleted(pOperator); @@ -753,6 +760,12 @@ int32_t doGroupSort(SOperatorInfo* pOperator, SSDataBlock** pResBlock) { } } +_end: + if (code != TSDB_CODE_SUCCESS) { + qError("%s failed at line %d since %s", __func__, lino, tstrerror(code)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); + } return code; } diff --git a/source/libs/executor/src/streamcountwindowoperator.c b/source/libs/executor/src/streamcountwindowoperator.c index 16c6775335..c3136d91e0 100644 --- a/source/libs/executor/src/streamcountwindowoperator.c +++ b/source/libs/executor/src/streamcountwindowoperator.c @@ -48,6 +48,9 @@ typedef struct SBuffInfo { void destroyStreamCountAggOperatorInfo(void* param) { SStreamCountAggOperatorInfo* pInfo = (SStreamCountAggOperatorInfo*)param; cleanupBasicInfo(&pInfo->binfo); + cleanupResultInfoInStream(pInfo->pOperator->pTaskInfo, pInfo->streamAggSup.pState, &pInfo->pOperator->exprSupp, + &pInfo->groupResInfo); + pInfo->pOperator = NULL; destroyStreamAggSupporter(&pInfo->streamAggSup); cleanupExprSupp(&pInfo->scalarSupp); clearGroupResInfo(&pInfo->groupResInfo); @@ -582,7 +585,7 @@ int32_t deleteCountWinState(SStreamAggSupporter* pAggSup, SSDataBlock* pBlock, S int32_t lino = 0; SArray* pWins = taosArrayInit(16, sizeof(SSessionKey)); if (!pWins) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } @@ -741,8 +744,9 @@ static int32_t doStreamCountAggNext(SOperatorInfo* pOperator, SSDataBlock** ppRe _end: if (code != TSDB_CODE_SUCCESS) { - pTaskInfo->code = code; qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); } setStreamOperatorCompleted(pOperator); (*ppRes) = NULL; @@ -881,7 +885,7 @@ int32_t createStreamCountAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pInfo->dataVersion = 0; pInfo->historyWins = taosArrayInit(4, sizeof(SSessionKey)); if (!pInfo->historyWins) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _error); } @@ -907,6 +911,7 @@ int32_t createStreamCountAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* QUERY_CHECK_CODE(code, lino, _error); taosMemoryFree(buff); } + pInfo->pOperator = pOperator; pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, doStreamCountAggNext, NULL, destroyStreamCountAggOperatorInfo, optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL); setOperatorStreamStateFn(pOperator, streamCountReleaseState, streamCountReloadState); diff --git a/source/libs/executor/src/streameventwindowoperator.c b/source/libs/executor/src/streameventwindowoperator.c index 1230638cff..017938ceb4 100644 --- a/source/libs/executor/src/streameventwindowoperator.c +++ b/source/libs/executor/src/streameventwindowoperator.c @@ -48,6 +48,9 @@ void destroyStreamEventOperatorInfo(void* param) { } SStreamEventAggOperatorInfo* pInfo = (SStreamEventAggOperatorInfo*)param; cleanupBasicInfo(&pInfo->binfo); + cleanupResultInfoInStream(pInfo->pOperator->pTaskInfo, pInfo->streamAggSup.pState, &pInfo->pOperator->exprSupp, + &pInfo->groupResInfo); + pInfo->pOperator = NULL; destroyStreamAggSupporter(&pInfo->streamAggSup); clearGroupResInfo(&pInfo->groupResInfo); taosArrayDestroyP(pInfo->pUpdated, destroyFlusedPos); @@ -176,7 +179,7 @@ _end: pAggSup->stateStore.streamStateSessionDel(pAggSup->pState, &pCurWin->winInfo.sessionWin); } pAggSup->stateStore.streamStateFreeCur(pCur); - qDebug("===stream===set event next win buff. skey:%" PRId64 ", endkey:%" PRId64, pCurWin->winInfo.sessionWin.win.skey, + qDebug("===stream===set event cur win buff. skey:%" PRId64 ", endkey:%" PRId64, pCurWin->winInfo.sessionWin.win.skey, pCurWin->winInfo.sessionWin.win.ekey); _error: @@ -230,7 +233,7 @@ int32_t updateEventWindowInfo(SStreamAggSupporter* pAggSup, SEventWindowInfo* pW pWinInfo->pWinFlag->endFlag = ends[i]; } else if (pWin->ekey == pTsData[i]) { pWinInfo->pWinFlag->endFlag |= ends[i]; - } else { + } else if (ends[i] && !pWinInfo->pWinFlag->endFlag) { *pRebuild = true; pWinInfo->pWinFlag->endFlag |= ends[i]; (*pWinRow) = i + 1 - start; @@ -695,7 +698,7 @@ static int32_t doStreamEventAggNext(SOperatorInfo* pOperator, SSDataBlock** ppRe if (pInfo->isHistoryOp) { SArray* pHisWins = taosArrayInit(16, sizeof(SEventWindowInfo)); if (!pHisWins) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } @@ -731,8 +734,9 @@ static int32_t doStreamEventAggNext(SOperatorInfo* pOperator, SSDataBlock** ppRe _end: if (code != TSDB_CODE_SUCCESS) { - pTaskInfo->code = code; qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); } setStreamOperatorCompleted(pOperator); (*ppRes) = NULL; @@ -952,6 +956,7 @@ int32_t createStreamEventAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* QUERY_CHECK_NULL(pInfo->pPkDeleted, code, lino, _error, terrno); pInfo->destHasPrimaryKey = pEventNode->window.destHasPrimaryKey; + pInfo->pOperator = pOperator; setOperatorInfo(pOperator, "StreamEventAggOperator", QUERY_NODE_PHYSICAL_PLAN_STREAM_EVENT, true, OP_NOT_OPENED, pInfo, pTaskInfo); // for stream diff --git a/source/libs/executor/src/streamfilloperator.c b/source/libs/executor/src/streamfilloperator.c index c178f22784..b673f88d50 100644 --- a/source/libs/executor/src/streamfilloperator.c +++ b/source/libs/executor/src/streamfilloperator.c @@ -838,7 +838,7 @@ static int32_t doDeleteFillResultImpl(SOperatorInfo* pOperator, TSKEY startTs, T }; void* tmp = taosArrayPush(pInfo->pFillInfo->delRanges, &tw); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -1138,8 +1138,9 @@ static int32_t doStreamFillNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { _end: if (code != TSDB_CODE_SUCCESS) { - pTaskInfo->code = code; qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); } setOperatorCompleted(pOperator); resetStreamFillInfo(pInfo); @@ -1247,13 +1248,13 @@ SStreamFillInfo* initStreamFillInfo(SStreamFillSupporter* pFillSup, SSDataBlock* if (pFillSup->type == TSDB_FILL_LINEAR) { pFillInfo->pLinearInfo->pEndPoints = taosArrayInit(pFillSup->numOfAllCols, sizeof(SPoint)); if (!pFillInfo->pLinearInfo->pEndPoints) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } pFillInfo->pLinearInfo->pNextEndPoints = taosArrayInit(pFillSup->numOfAllCols, sizeof(SPoint)); if (!pFillInfo->pLinearInfo->pNextEndPoints) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } @@ -1315,7 +1316,7 @@ SStreamFillInfo* initStreamFillInfo(SStreamFillSupporter* pFillSup, SSDataBlock* pFillInfo->type = pFillSup->type; pFillInfo->delRanges = taosArrayInit(16, sizeof(STimeRange)); if (!pFillInfo->delRanges) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } diff --git a/source/libs/executor/src/streamtimewindowoperator.c b/source/libs/executor/src/streamtimewindowoperator.c index 5bd3835d8e..e807b77d62 100644 --- a/source/libs/executor/src/streamtimewindowoperator.c +++ b/source/libs/executor/src/streamtimewindowoperator.c @@ -157,7 +157,7 @@ static int32_t savePullWindow(SPullWindowInfo* pPullInfo, SArray* pPullWins) { } } if (taosArrayInsert(pPullWins, index, pPullInfo) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return TSDB_CODE_SUCCESS; } @@ -298,7 +298,7 @@ static int32_t doDeleteWindows(SOperatorInfo* pOperator, SInterval* pInterval, S if (pUpWins) { void* tmp = taosArrayPush(pUpWins, &winRes); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -478,6 +478,9 @@ void destroyStreamFinalIntervalOperatorInfo(void* param) { } SStreamIntervalOperatorInfo* pInfo = (SStreamIntervalOperatorInfo*)param; cleanupBasicInfo(&pInfo->binfo); + cleanupResultInfo(pInfo->pOperator->pTaskInfo, &pInfo->pOperator->exprSupp, pInfo->aggSup.pResultBuf, + &pInfo->groupResInfo, pInfo->aggSup.pResultRowHashTable); + pInfo->pOperator = NULL; cleanupAggSup(&pInfo->aggSup); clearGroupResInfo(&pInfo->groupResInfo); taosArrayDestroyP(pInfo->pUpdated, destroyFlusedPos); @@ -688,7 +691,7 @@ int32_t addPullWindow(SHashObj* pMap, SWinKey* pWinRes, int32_t size) { for (int32_t i = 0; i < size; i++) { void* tmp = taosArrayPush(childIds, &i); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -824,13 +827,13 @@ static int32_t processPullOver(SSDataBlock* pBlock, SHashObj* pMap, SHashObj* pF void* tmp = taosArrayPush(pInfo->pMidPullDatas, &winRes); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } else if (savePullWindow(&pull, pPullWins) == TSDB_CODE_SUCCESS) { void* tmp = taosArrayPush(pInfo->pDelWins, &winRes); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } @@ -1177,8 +1180,9 @@ static int32_t doStreamIntervalAggImpl(SOperatorInfo* pOperator, SSDataBlock* pS } updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &nextWin, 1); - applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startPos, forwardRows, - pSDataBlock->info.rows, numOfOutput); + code = applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startPos, + forwardRows, pSDataBlock->info.rows, numOfOutput); + QUERY_CHECK_CODE(code, lino, _end); key.ts = nextWin.skey; if (pInfo->delKey.ts > key.ts) { @@ -1307,7 +1311,7 @@ int32_t decodeSPullWindowInfoArray(void* buf, SArray* pPullInfos, void** ppBuf) buf = decodeSPullWindowInfo(buf, &item); void* tmp = taosArrayPush(pPullInfos, &item); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -1422,7 +1426,7 @@ void doStreamIntervalDecodeOpState(void* buf, int32_t len, SOperatorInfo* pOpera SWinKey key = {0}; SArray* pArray = taosArrayInit(0, sizeof(int32_t)); if (!pArray) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } @@ -1434,7 +1438,7 @@ void doStreamIntervalDecodeOpState(void* buf, int32_t len, SOperatorInfo* pOpera buf = taosDecodeFixedI32(buf, &chId); void* tmp = taosArrayPush(pArray, &chId); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -1482,7 +1486,7 @@ int32_t copyIntervalDeleteKey(SSHashObj* pMap, SArray* pWins) { void* pKey = tSimpleHashGetKey(pIte, NULL); void* tmp = taosArrayPush(pWins, pKey); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -1544,7 +1548,7 @@ int32_t copyUpdateResult(SSHashObj** ppWinUpdated, SArray* pUpdated, __compar_fn while ((pIte = tSimpleHashIterate(*ppWinUpdated, pIte, &iter)) != NULL) { void* tmp = taosArrayPush(pUpdated, pIte); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -1803,8 +1807,9 @@ static int32_t doStreamFinalIntervalAggNext(SOperatorInfo* pOperator, SSDataBloc _end: if (code != TSDB_CODE_SUCCESS) { - pTaskInfo->code = code; qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); } setStreamOperatorCompleted(pOperator); (*ppRes) = NULL; @@ -2035,6 +2040,7 @@ int32_t createStreamFinalIntervalOperatorInfo(SOperatorInfo* downstream, SPhysiN pInfo->pDeletedMap = tSimpleHashInit(4096, hashFn); QUERY_CHECK_NULL(pInfo->pDeletedMap, code, lino, _error, terrno); pInfo->destHasPrimaryKey = pIntervalPhyNode->window.destHasPrimaryKey; + pInfo->pOperator = pOperator; pOperator->operatorType = pPhyNode->type; if (!IS_FINAL_INTERVAL_OP(pOperator) || numOfChild == 0) { @@ -2099,6 +2105,9 @@ void destroyStreamSessionAggOperatorInfo(void* param) { } SStreamSessionAggOperatorInfo* pInfo = (SStreamSessionAggOperatorInfo*)param; cleanupBasicInfo(&pInfo->binfo); + cleanupResultInfoInStream(pInfo->pOperator->pTaskInfo, pInfo->streamAggSup.pState, &pInfo->pOperator->exprSupp, + &pInfo->groupResInfo); + pInfo->pOperator = NULL; destroyStreamAggSupporter(&pInfo->streamAggSup); cleanupExprSupp(&pInfo->scalarSupp); clearGroupResInfo(&pInfo->groupResInfo); @@ -2334,7 +2343,7 @@ int32_t saveDeleteInfo(SArray* pWins, SSessionKey key) { int32_t lino = 0; void* res = taosArrayPush(pWins, &key); if (!res) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } @@ -2461,7 +2470,7 @@ int32_t doOneWindowAggImpl(SColumnInfoData* pTimeWindowData, SResultWindowInfo* QUERY_CHECK_CODE(code, lino, _end); updateTimeWindowInfo(pTimeWindowData, &pCurWin->sessionWin.win, winDelta); - applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, pTimeWindowData, startIndex, winRows, rows, numOutput); + code = applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, pTimeWindowData, startIndex, winRows, rows, numOutput); _end: if (code != TSDB_CODE_SUCCESS) { @@ -3178,7 +3187,7 @@ int32_t getMaxTsWins(const SArray* pAllWins, SArray* pMaxWins) { SSessionKey* pSeKey = &pWinInfo->sessionWin; void* tmp = taosArrayPush(pMaxWins, pSeKey); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } @@ -3192,7 +3201,7 @@ int32_t getMaxTsWins(const SArray* pAllWins, SArray* pMaxWins) { if (preGpId != pSeKey->groupId) { void* tmp = taosArrayPush(pMaxWins, pSeKey); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } preGpId = pSeKey->groupId; @@ -3306,9 +3315,8 @@ int32_t doStreamSessionDecodeOpState(void* buf, int32_t len, SOperatorInfo* pOpe int32_t mapSize = 0; buf = taosDecodeFixedI32(buf, &mapSize); for (int32_t i = 0; i < mapSize; i++) { - SSessionKey key = {0}; SResultWindowInfo winfo = {0}; - buf = decodeSSessionKey(buf, &key); + buf = decodeSSessionKey(buf, &winfo.sessionWin); int32_t winCode = TSDB_CODE_SUCCESS; code = pAggSup->stateStore.streamStateSessionAddIfNotExist( pAggSup->pState, &winfo.sessionWin, pAggSup->gap, (void**)&winfo.pStatePos, &pAggSup->resultRowSize, &winCode); @@ -3317,7 +3325,7 @@ int32_t doStreamSessionDecodeOpState(void* buf, int32_t len, SOperatorInfo* pOpe buf = decodeSResultWindowInfo(buf, &winfo, pInfo->streamAggSup.resultRowSize); code = - tSimpleHashPut(pInfo->streamAggSup.pResultRows, &key, sizeof(SSessionKey), &winfo, sizeof(SResultWindowInfo)); + tSimpleHashPut(pInfo->streamAggSup.pResultRows, &winfo.sessionWin, sizeof(SSessionKey), &winfo, sizeof(SResultWindowInfo)); QUERY_CHECK_CODE(code, lino, _end); } @@ -3583,8 +3591,9 @@ static int32_t doStreamSessionAggNext(SOperatorInfo* pOperator, SSDataBlock** pp _end: if (code != TSDB_CODE_SUCCESS) { - pTaskInfo->code = code; qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); } setStreamOperatorCompleted(pOperator); (*ppRes) = NULL; @@ -3875,6 +3884,7 @@ int32_t createStreamSessionAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode pInfo->destHasPrimaryKey = pSessionNode->window.destHasPrimaryKey; pInfo->pPkDeleted = tSimpleHashInit(64, hashFn); QUERY_CHECK_NULL(pInfo->pPkDeleted, code, lino, _error, terrno); + pInfo->pOperator = pOperator; pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION; setOperatorInfo(pOperator, getStreamOpName(pOperator->operatorType), QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION, true, @@ -3931,7 +3941,7 @@ int32_t deleteSessionWinState(SStreamAggSupporter* pAggSup, SSDataBlock* pBlock, int32_t lino = 0; SArray* pWins = taosArrayInit(16, sizeof(SSessionKey)); if (!pWins) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } code = doDeleteTimeWindows(pAggSup, pBlock, pWins); @@ -4088,8 +4098,9 @@ static int32_t doStreamSessionSemiAggNext(SOperatorInfo* pOperator, SSDataBlock* _end: if (code != TSDB_CODE_SUCCESS) { - pTaskInfo->code = code; qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); } clearFunctionContext(&pOperator->exprSupp); @@ -4123,6 +4134,7 @@ int32_t createStreamFinalSessionAggOperatorInfo(SOperatorInfo* downstream, SPhys SStorageAPI* pAPI = &pTaskInfo->storageAPI; SStreamSessionAggOperatorInfo* pInfo = pOperator->info; pOperator->operatorType = pPhyNode->type; + pInfo->pOperator = pOperator; if (pPhyNode->type != QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION) { pOperator->fpSet = @@ -4148,7 +4160,7 @@ int32_t createStreamFinalSessionAggOperatorInfo(SOperatorInfo* downstream, SPhys pAPI->stateStore.streamStateSetNumber(pChInfo->streamAggSup.pState, i, pInfo->primaryTsIndex); void* tmp = taosArrayPush(pInfo->pChildren, &pChildOp); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _error); } } @@ -4193,6 +4205,9 @@ void destroyStreamStateOperatorInfo(void* param) { } SStreamStateAggOperatorInfo* pInfo = (SStreamStateAggOperatorInfo*)param; cleanupBasicInfo(&pInfo->binfo); + cleanupResultInfoInStream(pInfo->pOperator->pTaskInfo, pInfo->streamAggSup.pState, &pInfo->pOperator->exprSupp, + &pInfo->groupResInfo); + pInfo->pOperator = NULL; destroyStreamAggSupporter(&pInfo->streamAggSup); clearGroupResInfo(&pInfo->groupResInfo); taosArrayDestroyP(pInfo->pUpdated, destroyFlusedPos); @@ -4608,9 +4623,8 @@ int32_t doStreamStateDecodeOpState(void* buf, int32_t len, SOperatorInfo* pOpera int32_t mapSize = 0; buf = taosDecodeFixedI32(buf, &mapSize); for (int32_t i = 0; i < mapSize; i++) { - SSessionKey key = {0}; SResultWindowInfo winfo = {0}; - buf = decodeSSessionKey(buf, &key); + buf = decodeSSessionKey(buf, &winfo.sessionWin); int32_t winCode = TSDB_CODE_SUCCESS; code = pAggSup->stateStore.streamStateStateAddIfNotExist( pAggSup->pState, &winfo.sessionWin, NULL, pAggSup->stateKeySize, compareStateKey, (void**)&winfo.pStatePos, @@ -4619,7 +4633,7 @@ int32_t doStreamStateDecodeOpState(void* buf, int32_t len, SOperatorInfo* pOpera buf = decodeSResultWindowInfo(buf, &winfo, pInfo->streamAggSup.resultRowSize); code = - tSimpleHashPut(pInfo->streamAggSup.pResultRows, &key, sizeof(SSessionKey), &winfo, sizeof(SResultWindowInfo)); + tSimpleHashPut(pInfo->streamAggSup.pResultRows, &winfo.sessionWin, sizeof(SSessionKey), &winfo, sizeof(SResultWindowInfo)); QUERY_CHECK_CODE(code, lino, _end); } @@ -4825,8 +4839,9 @@ static int32_t doStreamStateAggNext(SOperatorInfo* pOperator, SSDataBlock** ppRe _end: if (code != TSDB_CODE_SUCCESS) { - pTaskInfo->code = code; qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); } setStreamOperatorCompleted(pOperator); (*ppRes) = NULL; @@ -5050,6 +5065,7 @@ int32_t createStreamStateAggOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pInfo->pPkDeleted = tSimpleHashInit(64, hashFn); QUERY_CHECK_NULL(pInfo->pPkDeleted, code, lino, _error, terrno); pInfo->destHasPrimaryKey = pStateNode->window.destHasPrimaryKey; + pInfo->pOperator = pOperator; setOperatorInfo(pOperator, "StreamStateAggOperator", QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE, true, OP_NOT_OPENED, pInfo, pTaskInfo); @@ -5225,6 +5241,7 @@ static int32_t doStreamIntervalAggNext(SOperatorInfo* pOperator, SSDataBlock** p code = TSDB_CODE_SUCCESS; break; } + QUERY_CHECK_CODE(code, lino, _end); pInfo->twAggSup.maxTs = TMAX(pInfo->twAggSup.maxTs, pBlock->info.window.ekey); pInfo->twAggSup.minTs = TMIN(pInfo->twAggSup.minTs, pBlock->info.window.skey); } @@ -5246,7 +5263,7 @@ static int32_t doStreamIntervalAggNext(SOperatorInfo* pOperator, SSDataBlock** p while ((pIte = tSimpleHashIterate(pInfo->pUpdatedMap, pIte, &iter)) != NULL) { void* tmp = taosArrayPush(pInfo->pUpdated, pIte); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -5267,8 +5284,9 @@ static int32_t doStreamIntervalAggNext(SOperatorInfo* pOperator, SSDataBlock** p _end: if (code != TSDB_CODE_SUCCESS) { - pTaskInfo->code = code; qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); } setStreamOperatorCompleted(pOperator); (*ppRes) = NULL; @@ -5383,6 +5401,7 @@ int32_t createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SPhysiNode* pInfo->twAggSup.deleteMark, GET_TASKID(pTaskInfo), pHandle->checkpointId, STREAM_STATE_BUFF_HASH, &pInfo->pState->pFileState); QUERY_CHECK_CODE(code, lino, _error); + pInfo->pOperator = pOperator; setOperatorInfo(pOperator, "StreamIntervalOperator", QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL, true, OP_NOT_OPENED, pInfo, pTaskInfo); pOperator->fpSet = @@ -5497,8 +5516,9 @@ static void doStreamMidIntervalAggImpl(SOperatorInfo* pOperator, SSDataBlock* pS } updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &nextWin, 1); - applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startPos, forwardRows, - pSDataBlock->info.rows, numOfOutput); + code = applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startPos, + forwardRows, pSDataBlock->info.rows, numOfOutput); + QUERY_CHECK_CODE(code, lino, _end); key.ts = nextWin.skey; if (pInfo->delKey.ts > key.ts) { @@ -5667,7 +5687,7 @@ static int32_t doStreamMidIntervalAggNext(SOperatorInfo* pOperator, SSDataBlock* pBlock->info.type == STREAM_CLEAR) { SArray* delWins = taosArrayInit(8, sizeof(SWinKey)); if (!delWins) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } code = @@ -5721,7 +5741,7 @@ static int32_t doStreamMidIntervalAggNext(SOperatorInfo* pOperator, SSDataBlock* } else if (pBlock->info.type == STREAM_MID_RETRIEVE) { SArray* delWins = taosArrayInit(8, sizeof(SWinKey)); if (!delWins) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } code = doDeleteWindows(pOperator, &pInfo->interval, pBlock, delWins, pInfo->pUpdatedMap, NULL); @@ -5766,7 +5786,7 @@ static int32_t doStreamMidIntervalAggNext(SOperatorInfo* pOperator, SSDataBlock* while ((pIte = tSimpleHashIterate(pInfo->pUpdatedMap, pIte, &iter)) != NULL) { void* tmp = taosArrayPush(pInfo->pUpdated, pIte); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -5802,8 +5822,9 @@ static int32_t doStreamMidIntervalAggNext(SOperatorInfo* pOperator, SSDataBlock* _end: if (code != TSDB_CODE_SUCCESS) { - pTaskInfo->code = code; qError("%s failed at line %d since %s. task:%s", __func__, lino, tstrerror(code), GET_TASKID(pTaskInfo)); + pTaskInfo->code = code; + T_LONG_JMP(pTaskInfo->env, code); } (*ppRes) = NULL; return code; diff --git a/source/libs/executor/src/sysscanoperator.c b/source/libs/executor/src/sysscanoperator.c index 18344d9e79..7467d391d8 100644 --- a/source/libs/executor/src/sysscanoperator.c +++ b/source/libs/executor/src/sysscanoperator.c @@ -2049,7 +2049,7 @@ static int32_t doSysTableScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) if (isTaskKilled(pOperator->pTaskInfo)) { setOperatorCompleted(pOperator); (*ppRes) = NULL; - return pTaskInfo->code; + break; } blockDataCleanup(pInfo->pRes); @@ -2092,12 +2092,18 @@ static int32_t doSysTableScanNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) continue; } (*ppRes) = pBlock; - return pTaskInfo->code; } else { (*ppRes) = NULL; - return pTaskInfo->code; } + break; } + +_end: + if (pTaskInfo->code) { + qError("%s failed since %s", __func__, tstrerror(pTaskInfo->code)); + T_LONG_JMP(pTaskInfo->env, pTaskInfo->code); + } + return pTaskInfo->code; } static void sysTableScanFillTbName(SOperatorInfo* pOperator, const SSysTableScanInfo* pInfo, const char* name, @@ -2576,7 +2582,7 @@ int32_t optSysIntersection(SArray* in, SArray* out) { if (has == true) { void* tmp = taosArrayPush(out, &tgt); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _end; } } diff --git a/source/libs/executor/src/timesliceoperator.c b/source/libs/executor/src/timesliceoperator.c index 9309546fe0..b86d7725fa 100644 --- a/source/libs/executor/src/timesliceoperator.c +++ b/source/libs/executor/src/timesliceoperator.c @@ -544,7 +544,7 @@ static int32_t initPrevRowsKeeper(STimeSliceOperatorInfo* pInfo, SSDataBlock* pB pInfo->pPrevRow = taosArrayInit(4, sizeof(SGroupKeys)); if (pInfo->pPrevRow == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); @@ -579,7 +579,7 @@ static int32_t initNextRowsKeeper(STimeSliceOperatorInfo* pInfo, SSDataBlock* pB pInfo->pNextRow = taosArrayInit(4, sizeof(SGroupKeys)); if (pInfo->pNextRow == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); @@ -615,7 +615,7 @@ static int32_t initFillLinearInfo(STimeSliceOperatorInfo* pInfo, SSDataBlock* pB pInfo->pLinearInfo = taosArrayInit(4, sizeof(SFillLinearInfo)); if (pInfo->pLinearInfo == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t numOfCols = taosArrayGetSize(pBlock->pDataBlock); diff --git a/source/libs/executor/src/timewindowoperator.c b/source/libs/executor/src/timewindowoperator.c index 0cd506d15a..6ac24ad313 100644 --- a/source/libs/executor/src/timewindowoperator.c +++ b/source/libs/executor/src/timewindowoperator.c @@ -37,6 +37,7 @@ typedef struct SSessionAggOperatorInfo { int64_t gap; // session window gap int32_t tsSlotId; // primary timestamp slot id STimeWindowAggSupp twAggSup; + SOperatorInfo* pOperator; } SSessionAggOperatorInfo; typedef struct SStateWindowOperatorInfo { @@ -50,6 +51,7 @@ typedef struct SStateWindowOperatorInfo { SStateKeys stateKey; int32_t tsSlotId; // primary timestamp column slot id STimeWindowAggSupp twAggSup; + SOperatorInfo* pOperator; } SStateWindowOperatorInfo; typedef enum SResultTsInterpType { @@ -653,8 +655,11 @@ static void doInterpUnclosedTimeWindow(SOperatorInfo* pOperatorInfo, int32_t num setNotInterpoWindowKey(pSup->pCtx, numOfExprs, RESULT_ROW_START_INTERP); updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &w, 1); - applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startPos, 0, - pBlock->info.rows, numOfExprs); + ret = applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startPos, 0, + pBlock->info.rows, numOfExprs); + if (ret != TSDB_CODE_SUCCESS) { + T_LONG_JMP(pTaskInfo->env, ret); + } if (isResultRowInterpolated(pResult, RESULT_ROW_END_INTERP)) { closeResultRow(pr); @@ -799,8 +804,11 @@ static bool hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul } updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &win, 1); - applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startPos, forwardRows, + ret = applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startPos, forwardRows, pBlock->info.rows, numOfOutput); + if (ret != TSDB_CODE_SUCCESS) { + T_LONG_JMP(pTaskInfo->env, ret); + } doCloseWindow(pResultRowInfo, pInfo, pResult); @@ -838,8 +846,11 @@ static bool hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pResul } #endif updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &nextWin, 1); - applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startPos, forwardRows, - pBlock->info.rows, numOfOutput); + ret = applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, startPos, forwardRows, + pBlock->info.rows, numOfOutput); + if (ret != TSDB_CODE_SUCCESS) { + T_LONG_JMP(pTaskInfo->env, ret); + } doCloseWindow(pResultRowInfo, pInfo, pResult); } @@ -1031,8 +1042,11 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI } updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &window, 0); - applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, pRowSup->startRowIndex, - pRowSup->numOfRows, pBlock->info.rows, numOfOutput); + ret = applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, + pRowSup->startRowIndex, pRowSup->numOfRows, pBlock->info.rows, numOfOutput); + if (ret != TSDB_CODE_SUCCESS) { + T_LONG_JMP(pTaskInfo->env, ret); + } // here we start a new session window doKeepNewWindowStartInfo(pRowSup, tsList, j, gid); @@ -1056,8 +1070,11 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI } updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pRowSup->win, 0); - applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, pRowSup->startRowIndex, - pRowSup->numOfRows, pBlock->info.rows, numOfOutput); + ret = applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, pRowSup->startRowIndex, + pRowSup->numOfRows, pBlock->info.rows, numOfOutput); + if (ret != TSDB_CODE_SUCCESS) { + T_LONG_JMP(pTaskInfo->env, ret); + } } static int32_t openStateWindowAggOptr(SOperatorInfo* pOperator) { @@ -1209,6 +1226,9 @@ static void destroyStateWindowOperatorInfo(void* param) { SStateWindowOperatorInfo* pInfo = (SStateWindowOperatorInfo*)param; cleanupBasicInfo(&pInfo->binfo); taosMemoryFreeClear(pInfo->stateKey.pData); + cleanupResultInfo(pInfo->pOperator->pTaskInfo, &pInfo->pOperator->exprSupp, pInfo->aggSup.pResultBuf, + &pInfo->groupResInfo, pInfo->aggSup.pResultRowHashTable); + pInfo->pOperator = NULL; cleanupExprSupp(&pInfo->scalarSup); colDataDestroy(&pInfo->twAggSup.timeWindowData); cleanupAggSup(&pInfo->aggSup); @@ -1228,6 +1248,9 @@ void destroyIntervalOperatorInfo(void* param) { } SIntervalAggOperatorInfo* pInfo = (SIntervalAggOperatorInfo*)param; cleanupBasicInfo(&pInfo->binfo); + cleanupResultInfo(pInfo->pOperator->pTaskInfo, &pInfo->pOperator->exprSupp, pInfo->aggSup.pResultBuf, + &pInfo->groupResInfo, pInfo->aggSup.pResultRowHashTable); + pInfo->pOperator = NULL; cleanupAggSup(&pInfo->aggSup); cleanupExprSupp(&pInfo->scalarSupp); @@ -1415,6 +1438,7 @@ int32_t createIntervalOperatorInfo(SOperatorInfo* downstream, SIntervalPhysiNode } } + pInfo->pOperator = pOperator; initResultRowInfo(&pInfo->binfo.resultRowInfo); setOperatorInfo(pOperator, "TimeIntervalAggOperator", QUERY_NODE_PHYSICAL_PLAN_HASH_INTERVAL, true, OP_NOT_OPENED, pInfo, pTaskInfo); @@ -1492,8 +1516,11 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSessionAggOperator // pInfo->numOfRows data belong to the current session window updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &window, 0); - applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, pRowSup->startRowIndex, - pRowSup->numOfRows, pBlock->info.rows, numOfOutput); + ret = applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, pRowSup->startRowIndex, + pRowSup->numOfRows, pBlock->info.rows, numOfOutput); + if (ret != TSDB_CODE_SUCCESS) { + T_LONG_JMP(pTaskInfo->env, ret); + } } // here we start a new session window @@ -1511,8 +1538,11 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSessionAggOperator } updateTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pRowSup->win, 0); - applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, pRowSup->startRowIndex, - pRowSup->numOfRows, pBlock->info.rows, numOfOutput); + ret = applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &pInfo->twAggSup.timeWindowData, pRowSup->startRowIndex, + pRowSup->numOfRows, pBlock->info.rows, numOfOutput); + if (ret != TSDB_CODE_SUCCESS) { + T_LONG_JMP(pTaskInfo->env, ret); + } } static int32_t doSessionWindowAggNext(SOperatorInfo* pOperator, SSDataBlock** ppRes) { @@ -1685,7 +1715,7 @@ int32_t createStatewindowOperatorInfo(SOperatorInfo* downstream, SStateWinodwPhy QUERY_CHECK_CODE(code, lino, _error); pInfo->tsSlotId = tsSlotId; - + pInfo->pOperator = pOperator; setOperatorInfo(pOperator, "StateWindowOperator", QUERY_NODE_PHYSICAL_PLAN_MERGE_STATE, true, OP_NOT_OPENED, pInfo, pTaskInfo); pOperator->fpSet = createOperatorFpSet(openStateWindowAggOptr, doStateWindowAggNext, NULL, destroyStateWindowOperatorInfo, @@ -1717,7 +1747,9 @@ void destroySWindowOperatorInfo(void* param) { cleanupBasicInfo(&pInfo->binfo); colDataDestroy(&pInfo->twAggSup.timeWindowData); - + cleanupResultInfo(pInfo->pOperator->pTaskInfo, &pInfo->pOperator->exprSupp, pInfo->aggSup.pResultBuf, + &pInfo->groupResInfo, pInfo->aggSup.pResultRowHashTable); + pInfo->pOperator = NULL; cleanupAggSup(&pInfo->aggSup); cleanupExprSupp(&pInfo->scalarSupp); @@ -1784,6 +1816,7 @@ int32_t createSessionAggOperatorInfo(SOperatorInfo* downstream, SSessionWinodwPh code = filterInitFromNode((SNode*)pSessionNode->window.node.pConditions, &pOperator->exprSupp.pFilterInfo, 0); QUERY_CHECK_CODE(code, lino, _error); + pInfo->pOperator = pOperator; setOperatorInfo(pOperator, "SessionWindowAggOperator", QUERY_NODE_PHYSICAL_PLAN_MERGE_SESSION, true, OP_NOT_OPENED, pInfo, pTaskInfo); pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, doSessionWindowAggNext, NULL, destroySWindowOperatorInfo, @@ -1874,8 +1907,11 @@ static void doMergeAlignedIntervalAggImpl(SOperatorInfo* pOperatorInfo, SResultR } updateTimeWindowInfo(&iaInfo->twAggSup.timeWindowData, &currWin, 1); - applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &iaInfo->twAggSup.timeWindowData, startPos, - currPos - startPos, pBlock->info.rows, pSup->numOfExprs); + ret = applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &iaInfo->twAggSup.timeWindowData, startPos, + currPos - startPos, pBlock->info.rows, pSup->numOfExprs); + if (ret != TSDB_CODE_SUCCESS) { + T_LONG_JMP(pTaskInfo->env, ret); + } finalizeResultRows(iaInfo->aggSup.pResultBuf, &pResultRowInfo->cur, pSup, pResultBlock, pTaskInfo); resetResultRow(miaInfo->pResultRow, iaInfo->aggSup.resultRowSize - sizeof(SResultRow)); @@ -1894,8 +1930,11 @@ static void doMergeAlignedIntervalAggImpl(SOperatorInfo* pOperatorInfo, SResultR } updateTimeWindowInfo(&iaInfo->twAggSup.timeWindowData, &currWin, 1); - applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &iaInfo->twAggSup.timeWindowData, startPos, currPos - startPos, - pBlock->info.rows, pSup->numOfExprs); + ret = applyAggFunctionOnPartialTuples(pTaskInfo, pSup->pCtx, &iaInfo->twAggSup.timeWindowData, startPos, + currPos - startPos, pBlock->info.rows, pSup->numOfExprs); + if (ret != TSDB_CODE_SUCCESS) { + T_LONG_JMP(pTaskInfo->env, ret); + } } static void cleanupAfterGroupResultGen(SMergeAlignedIntervalAggOperatorInfo* pMiaInfo, SSDataBlock* pRes) { @@ -2094,6 +2133,7 @@ int32_t createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream, SMerge initResultRowInfo(&iaInfo->binfo.resultRowInfo); code = blockDataEnsureCapacity(iaInfo->binfo.pRes, pOperator->resultInfo.capacity); QUERY_CHECK_CODE(code, lino, _error); + iaInfo->pOperator = pOperator; setOperatorInfo(pOperator, "TimeMergeAlignedIntervalAggOperator", QUERY_NODE_PHYSICAL_PLAN_MERGE_ALIGNED_INTERVAL, false, OP_NOT_OPENED, miaInfo, pTaskInfo); @@ -2223,8 +2263,11 @@ static void doMergeIntervalAggImpl(SOperatorInfo* pOperatorInfo, SResultRowInfo* } updateTimeWindowInfo(&iaInfo->twAggSup.timeWindowData, &win, 1); - applyAggFunctionOnPartialTuples(pTaskInfo, pExprSup->pCtx, &iaInfo->twAggSup.timeWindowData, startPos, forwardRows, + ret = applyAggFunctionOnPartialTuples(pTaskInfo, pExprSup->pCtx, &iaInfo->twAggSup.timeWindowData, startPos, forwardRows, pBlock->info.rows, numOfOutput); + if (ret != TSDB_CODE_SUCCESS) { + T_LONG_JMP(pTaskInfo->env, ret); + } doCloseWindow(pResultRowInfo, iaInfo, pResult); // output previous interval results after this interval (&win) is closed @@ -2262,8 +2305,11 @@ static void doMergeIntervalAggImpl(SOperatorInfo* pOperatorInfo, SResultRowInfo* } updateTimeWindowInfo(&iaInfo->twAggSup.timeWindowData, &nextWin, 1); - applyAggFunctionOnPartialTuples(pTaskInfo, pExprSup->pCtx, &iaInfo->twAggSup.timeWindowData, startPos, forwardRows, - pBlock->info.rows, numOfOutput); + code = applyAggFunctionOnPartialTuples(pTaskInfo, pExprSup->pCtx, &iaInfo->twAggSup.timeWindowData, startPos, + forwardRows, pBlock->info.rows, numOfOutput); + if (code != TSDB_CODE_SUCCESS) { + T_LONG_JMP(pTaskInfo->env, code); + } doCloseWindow(pResultRowInfo, iaInfo, pResult); // output previous interval results after this interval (&nextWin) is closed @@ -2427,6 +2473,7 @@ int32_t createMergeIntervalOperatorInfo(SOperatorInfo* downstream, SMergeInterva } } + pIntervalInfo->pOperator = pOperator; initResultRowInfo(&pIntervalInfo->binfo.resultRowInfo); setOperatorInfo(pOperator, "TimeMergeIntervalAggOperator", QUERY_NODE_PHYSICAL_PLAN_MERGE_INTERVAL, false, OP_NOT_OPENED, pMergeIntervalInfo, pTaskInfo); diff --git a/source/libs/executor/src/tlinearhash.c b/source/libs/executor/src/tlinearhash.c index 9654f74ab1..99ef7ad9d9 100644 --- a/source/libs/executor/src/tlinearhash.c +++ b/source/libs/executor/src/tlinearhash.c @@ -229,7 +229,7 @@ static int32_t doAddNewBucket(SLHashObj* pHashObj) { char* p = taosMemoryRealloc(pHashObj->pBucket, POINTER_BYTES * newLen); if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memset(p + POINTER_BYTES * pHashObj->numOfBuckets, 0, newLen - pHashObj->numOfBuckets); diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index 19b825b0ca..6fef9a5e10 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -432,46 +432,41 @@ void tsortDestroySortHandle(SSortHandle* pSortHandle) { int32_t tsortAddSource(SSortHandle* pSortHandle, void* pSource) { void* p = taosArrayPush(pSortHandle->pOrderedSource, &pSource); - return (p != NULL)? TSDB_CODE_SUCCESS:TSDB_CODE_OUT_OF_MEMORY; + return (p != NULL)? TSDB_CODE_SUCCESS:terrno; } static int32_t doAddNewExternalMemSource(SDiskbasedBuf* pBuf, SArray* pAllSources, SSDataBlock* pBlock, int32_t* sourceId, SArray* pPageIdList) { + int32_t code = 0; + int32_t lino = 0; SSortSource* pSource = taosMemoryCalloc(1, sizeof(SSortSource)); - if (pSource == NULL) { - taosArrayDestroy(pPageIdList); - return terrno; - } + QUERY_CHECK_NULL(pSource, code, lino, _err, terrno); pSource->src.pBlock = pBlock; pSource->pageIdList = pPageIdList; - void* p = taosArrayPush(pAllSources, &pSource); - if (p == NULL) { - taosArrayDestroy(pPageIdList); - return TSDB_CODE_OUT_OF_MEMORY; - } + SSortSource** p = taosArrayPush(pAllSources, &pSource); + QUERY_CHECK_NULL(p, code, lino, _err, terrno); + pSource = NULL; (*sourceId) += 1; - int32_t rowSize = blockDataGetSerialRowSize(pSource->src.pBlock); + int32_t rowSize = blockDataGetSerialRowSize((*p)->src.pBlock); // The value of numOfRows must be greater than 0, which is guaranteed by the previous memory allocation int32_t numOfRows = (getBufPageSize(pBuf) - blockDataGetSerialMetaSize(taosArrayGetSize(pBlock->pDataBlock))) / rowSize; - if (numOfRows <= 0) { - qError("sort failed at: %s:%d", __func__, __LINE__); - taosArrayDestroy(pPageIdList); - return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR; - } + QUERY_CHECK_CONDITION((numOfRows > 0), code, lino, _err, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR); - int32_t code = blockDataEnsureCapacity(pSource->src.pBlock, numOfRows); - if (code != 0) { - qError("sort failed at: %s:%d", __func__, __LINE__); - taosArrayDestroy(pPageIdList); - } + code = blockDataEnsureCapacity((*p)->src.pBlock, numOfRows); + QUERY_CHECK_CODE(code, lino, _err); return code; + +_err: + if (pSource) taosMemoryFree(pSource); + qError("sort failed at %s:%d since %s", __func__, lino, tstrerror(code)); + return code; } static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) { @@ -525,7 +520,7 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) { if (px == NULL) { taosArrayDestroy(pPageIdList); blockDataDestroy(p); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t size = blockDataGetSize(p) + sizeof(int32_t) + taosArrayGetSize(p->pDataBlock) * sizeof(int32_t); @@ -554,7 +549,12 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) { return code; } - return doAddNewExternalMemSource(pHandle->pBuf, pHandle->pOrderedSource, pBlock, &pHandle->sourceId, pPageIdList); + code = doAddNewExternalMemSource(pHandle->pBuf, pHandle->pOrderedSource, pBlock, &pHandle->sourceId, pPageIdList); + if (code) { + blockDataDestroy(pBlock); + taosArrayDestroy(pPageIdList); + } + return code; } static void setCurrentSourceDone(SSortSource* pSource, SSortHandle* pHandle) { @@ -1023,6 +1023,9 @@ static int32_t doSortForEachGroup(SSortHandle* pHandle, int32_t sortTimes, int32 QUERY_CHECK_CODE(code, lino, _err); code = doAddNewExternalMemSource(pHandle->pBuf, pResList, pBlock, &pHandle->sourceId, pPageIdList); + if (code != TSDB_CODE_SUCCESS) { + blockDataDestroy(pBlock); + } QUERY_CHECK_CODE(code, lino, _err); } @@ -2144,6 +2147,10 @@ static int32_t sortBlocksToExtSource(SSortHandle* pHandle, SArray* aBlk, SArray* if (code) goto _error; code = doAddNewExternalMemSource(pHandle->pBuf, aExtSrc, pMemSrcBlk, &pHandle->sourceId, aPgId); + if (code != TSDB_CODE_SUCCESS) { + blockDataDestroy(pMemSrcBlk); + goto _error; + } cleanupMergeSup(&sup); tMergeTreeDestroy(&pTree); @@ -2306,9 +2313,15 @@ static int32_t createBlocksMergeSortInitialSources(SSortHandle* pHandle) { } code = tSimpleHashPut(mUidBlk, &pBlk->info.id.uid, sizeof(pBlk->info.id.uid), &tBlk, POINTER_BYTES); + if (code != TSDB_CODE_SUCCESS) { + blockDataDestroy(tBlk); + } QUERY_CHECK_CODE(code, lino, _err); void* px = taosArrayPush(aBlkSort, &tBlk); + if (px == NULL) { + blockDataDestroy(tBlk); + } QUERY_CHECK_NULL(px, code, lino, _err, terrno); } } diff --git a/source/libs/function/inc/builtinsimpl.h b/source/libs/function/inc/builtinsimpl.h index 41e2cadace..0b2fb70eba 100644 --- a/source/libs/function/inc/builtinsimpl.h +++ b/source/libs/function/inc/builtinsimpl.h @@ -122,6 +122,7 @@ bool getPercentileFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); int32_t percentileFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); int32_t percentileFunction(SqlFunctionCtx* pCtx); int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock); +void percentileFunctionCleanupExt(SqlFunctionCtx* pCtx); bool getApercentileFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv); int32_t apercentileFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo); diff --git a/source/libs/function/inc/tpercentile.h b/source/libs/function/inc/tpercentile.h index 1b80c2b1da..09df42d3a3 100644 --- a/source/libs/function/inc/tpercentile.h +++ b/source/libs/function/inc/tpercentile.h @@ -69,7 +69,7 @@ typedef struct tMemBucket { int32_t tMemBucketCreate(int32_t nElemSize, int16_t dataType, double minval, double maxval, bool hasWindowOrGroup, tMemBucket **pBucket); -void tMemBucketDestroy(tMemBucket *pBucket); +void tMemBucketDestroy(tMemBucket **pBucket); int32_t tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size); diff --git a/source/libs/function/src/builtins.c b/source/libs/function/src/builtins.c index d9432daf5b..60eccc6b07 100644 --- a/source/libs/function/src/builtins.c +++ b/source/libs/function/src/builtins.c @@ -3115,6 +3115,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = { .processFunc = percentileFunction, .sprocessFunc = percentileScalarFunction, .finalizeFunc = percentileFinalize, + .cleanupFunc = percentileFunctionCleanupExt, #ifdef BUILD_NO_CALL .invertFunc = NULL, #endif diff --git a/source/libs/function/src/builtinsimpl.c b/source/libs/function/src/builtinsimpl.c index a24b7197c6..194b68830b 100644 --- a/source/libs/function/src/builtinsimpl.c +++ b/source/libs/function/src/builtinsimpl.c @@ -480,7 +480,7 @@ int32_t funcInputGetNextRowDescPk(SFuncInputRowIter* pIter, SFuncInputRow* pRow, pIter->pPrevData = taosMemoryMalloc(pIter->pDataCol->info.bytes); if (NULL == pIter->pPrevData) { qError("out of memory when function get input row."); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } char* srcData = colDataGetData(pIter->pDataCol, pIter->inputEndIndex); (void)memcpy(pIter->pPrevData, srcData, pIter->pDataCol->info.bytes); @@ -489,7 +489,7 @@ int32_t funcInputGetNextRowDescPk(SFuncInputRowIter* pIter, SFuncInputRow* pRow, if (NULL == pIter->pPrevPk) { qError("out of memory when function get input row."); taosMemoryFree(pIter->pPrevData); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } char* pkData = colDataGetData(pIter->pPkCol, pIter->inputEndIndex); (void)memcpy(pIter->pPrevPk, pkData, pIter->pPkCol->info.bytes); @@ -545,14 +545,14 @@ int32_t funcInputGetNextRowDescPk(SFuncInputRowIter* pIter, SFuncInputRow* pRow, pIter->pPrevData = taosMemoryMalloc(pIter->pDataCol->info.bytes); if (NULL == pIter->pPrevData) { qError("out of memory when function get input row."); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)memcpy(pIter->pPrevData, colDataGetData(pIter->pDataCol, pIter->inputEndIndex), pIter->pDataCol->info.bytes); pIter->pPrevPk = taosMemoryMalloc(pIter->pPkCol->info.bytes); if (NULL == pIter->pPrevPk) { qError("out of memory when function get input row."); taosMemoryFree(pIter->pPrevData); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)memcpy(pIter->pPrevPk, colDataGetData(pIter->pPkCol, pIter->inputEndIndex), pIter->pPkCol->info.bytes); @@ -2009,6 +2009,17 @@ int32_t percentileFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResu return TSDB_CODE_SUCCESS; } +void percentileFunctionCleanupExt(SqlFunctionCtx* pCtx) { + if (pCtx == NULL || GET_RES_INFO(pCtx) == NULL || GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)) == NULL) { + return; + } + SPercentileInfo* pInfo = GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)); + if (pInfo->pMemBucket != NULL) { + tMemBucketDestroy(&(pInfo->pMemBucket)); + pInfo->pMemBucket = NULL; + } +} + int32_t percentileFunction(SqlFunctionCtx* pCtx) { int32_t code = TSDB_CODE_SUCCESS; int32_t numOfElems = 0; @@ -2095,7 +2106,7 @@ int32_t percentileFunction(SqlFunctionCtx* pCtx) { numOfElems += 1; code = tMemBucketPut(pInfo->pMemBucket, data, 1); if (code != TSDB_CODE_SUCCESS) { - tMemBucketDestroy(pInfo->pMemBucket); + tMemBucketDestroy(&(pInfo->pMemBucket)); return code; } } @@ -2103,6 +2114,7 @@ int32_t percentileFunction(SqlFunctionCtx* pCtx) { SET_VAL(pResInfo, numOfElems, 1); } + pCtx->needCleanup = true; return TSDB_CODE_SUCCESS; } @@ -2113,8 +2125,8 @@ int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { int32_t code = 0; double v = 0; - tMemBucket* pMemBucket = ppInfo->pMemBucket; - if (pMemBucket != NULL && pMemBucket->total > 0) { // check for null + tMemBucket** pMemBucket = &ppInfo->pMemBucket; + if ((*pMemBucket) != NULL && (*pMemBucket)->total > 0) { // check for null if (pCtx->numOfParams > 2) { char buf[3200] = {0}; // max length of double num is 317, e.g. use %.6lf to print -1.0e+308, consider the comma and bracket, 3200 is enough. @@ -2126,7 +2138,7 @@ int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { GET_TYPED_DATA(v, double, pVal->nType, &pVal->i); - code = getPercentile(pMemBucket, v, &ppInfo->result); + code = getPercentile((*pMemBucket), v, &ppInfo->result); if (code != TSDB_CODE_SUCCESS) { goto _fin_error; } @@ -2158,7 +2170,7 @@ int32_t percentileFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) { GET_TYPED_DATA(v, double, pVal->nType, &pVal->i); - code = getPercentile(pMemBucket, v, &ppInfo->result); + code = getPercentile((*pMemBucket), v, &ppInfo->result); if (code != TSDB_CODE_SUCCESS) { goto _fin_error; } @@ -2644,7 +2656,7 @@ static int32_t prepareBuf(SqlFunctionCtx* pCtx) { pCtx->subsidiaries.rowLen = rowLen + pCtx->subsidiaries.num * sizeof(bool); pCtx->subsidiaries.buf = taosMemoryMalloc(pCtx->subsidiaries.rowLen); if (NULL == pCtx->subsidiaries.buf) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } return TSDB_CODE_SUCCESS; @@ -6065,9 +6077,9 @@ int32_t modeFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo) { if (NULL == pInfo->buf) { taosHashCleanup(pInfo->pHash); pInfo->pHash = NULL; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } - + pCtx->needCleanup = true; return TSDB_CODE_SUCCESS; } diff --git a/source/libs/function/src/detail/tminmax.c b/source/libs/function/src/detail/tminmax.c index 608f3bf260..e3c12e9a57 100644 --- a/source/libs/function/src/detail/tminmax.c +++ b/source/libs/function/src/detail/tminmax.c @@ -947,7 +947,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc, int32_t* nElems) case TSDB_DATA_TYPE_NCHAR: { pBuf->str = taosMemoryMalloc(pCol->info.bytes); if (pBuf->str == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)memcpy(pBuf->str, colDataGetData(pCol, i), varDataTLen(colDataGetData(pCol, i))); break; diff --git a/source/libs/function/src/thistogram.c b/source/libs/function/src/thistogram.c index 2283845cfb..5ba43f546c 100644 --- a/source/libs/function/src/thistogram.c +++ b/source/libs/function/src/thistogram.c @@ -37,7 +37,7 @@ int32_t tHistogramCreate(int32_t numOfEntries, SHistogramInfo** pHisto) { /* need one redundant slot */ *pHisto = taosMemoryMalloc(sizeof(SHistogramInfo) + sizeof(SHistBin) * (numOfEntries + 1)); if (NULL == *pHisto) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } #if !defined(USE_ARRAYLIST) @@ -468,7 +468,7 @@ int32_t tHistogramUniform(SHistogramInfo* pHisto, double* ratio, int32_t num, do #if defined(USE_ARRAYLIST) *pVal = taosMemoryMalloc(num * sizeof(double)); if (NULL == *pVal) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int32_t i = 0; i < num; ++i) { @@ -521,7 +521,7 @@ int32_t tHistogramUniform(SHistogramInfo* pHisto, double* ratio, int32_t num, do #else double* pVal = taosMemoryMalloc(num * sizeof(double)); if (NULL == *pVal) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int32_t i = 0; i < num; ++i) { double numOfElem = ratio[i] * pHisto->numOfElems; diff --git a/source/libs/function/src/tpercentile.c b/source/libs/function/src/tpercentile.c index cc618f3f65..29c48460c0 100644 --- a/source/libs/function/src/tpercentile.c +++ b/source/libs/function/src/tpercentile.c @@ -291,12 +291,12 @@ int32_t tMemBucketCreate(int32_t nElemSize, int16_t dataType, double minval, dou (*pBucket)->maxCapacity = 200000; (*pBucket)->groupPagesMap = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); if ((*pBucket)->groupPagesMap == NULL) { - tMemBucketDestroy(*pBucket); + tMemBucketDestroy(pBucket); return terrno; } if (setBoundingBox(&(*pBucket)->range, (*pBucket)->type, minval, maxval) != 0) { // qError("MemBucket:%p, invalid value range: %f-%f", pBucket, minval, maxval); - tMemBucketDestroy(*pBucket); + tMemBucketDestroy(pBucket); return TSDB_CODE_FUNC_INVALID_VALUE_RANGE; } @@ -306,13 +306,13 @@ int32_t tMemBucketCreate(int32_t nElemSize, int16_t dataType, double minval, dou (*pBucket)->hashFunc = getHashFunc((*pBucket)->type); if ((*pBucket)->hashFunc == NULL) { // qError("MemBucket:%p, not support data type %d, failed", pBucket, pBucket->type); - tMemBucketDestroy(*pBucket); + tMemBucketDestroy(pBucket); return TSDB_CODE_FUNC_FUNTION_PARA_TYPE; } (*pBucket)->pSlots = (tMemBucketSlot *)taosMemoryCalloc((*pBucket)->numOfSlots, sizeof(tMemBucketSlot)); if ((*pBucket)->pSlots == NULL) { - tMemBucketDestroy(*pBucket); + tMemBucketDestroy(pBucket); return terrno; } @@ -320,13 +320,13 @@ int32_t tMemBucketCreate(int32_t nElemSize, int16_t dataType, double minval, dou if (!osTempSpaceAvailable()) { // qError("MemBucket create disk based Buf failed since %s", terrstr(terrno)); - tMemBucketDestroy(*pBucket); + tMemBucketDestroy(pBucket); return TSDB_CODE_NO_DISKSPACE; } int32_t ret = createDiskbasedBuf(&(*pBucket)->pBuffer, (*pBucket)->bufPageSize, (*pBucket)->bufPageSize * DEFAULT_NUM_OF_SLOT * 4, "1", tsTempDir); if (ret != 0) { - tMemBucketDestroy(*pBucket); + tMemBucketDestroy(pBucket); return ret; } @@ -334,22 +334,22 @@ int32_t tMemBucketCreate(int32_t nElemSize, int16_t dataType, double minval, dou return TSDB_CODE_SUCCESS; } -void tMemBucketDestroy(tMemBucket *pBucket) { - if (pBucket == NULL) { +void tMemBucketDestroy(tMemBucket **pBucket) { + if (*pBucket == NULL) { return; } - void *p = taosHashIterate(pBucket->groupPagesMap, NULL); + void *p = taosHashIterate((*pBucket)->groupPagesMap, NULL); while (p) { SArray **p1 = p; - p = taosHashIterate(pBucket->groupPagesMap, p); + p = taosHashIterate((*pBucket)->groupPagesMap, p); taosArrayDestroy(*p1); } - destroyDiskbasedBuf(pBucket->pBuffer); - taosMemoryFreeClear(pBucket->pSlots); - taosHashCleanup(pBucket->groupPagesMap); - taosMemoryFreeClear(pBucket); + destroyDiskbasedBuf((*pBucket)->pBuffer); + taosMemoryFreeClear((*pBucket)->pSlots); + taosHashCleanup((*pBucket)->groupPagesMap); + taosMemoryFreeClear(*pBucket); } int32_t tMemBucketUpdateBoundingBox(MinMaxEntry *r, const char *data, int32_t dataType) { @@ -460,7 +460,7 @@ int32_t tMemBucketPut(tMemBucket *pBucket, const void *data, size_t size) { pSlot->info.pageId = pageId; if (taosArrayPush(pPageIdList, &pageId) == NULL) { taosArrayDestroy(pPageIdList); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } diff --git a/source/libs/function/src/tudf.c b/source/libs/function/src/tudf.c index 6145d9f03f..ffdd4ea500 100644 --- a/source/libs/function/src/tudf.c +++ b/source/libs/function/src/tudf.c @@ -1678,7 +1678,7 @@ int32_t udfcInitializeUvTask(SClientUdfTask *task, int8_t uvTaskType, SClientUvT void *bufBegin = taosMemoryMalloc(bufLen); if(bufBegin == NULL) { fnError("udfc create uv task, malloc buffer failed. size: %d", bufLen); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } void *buf = bufBegin; if(encodeUdfRequest(&buf, &request) <= 0) @@ -1733,7 +1733,7 @@ int32_t udfcStartUvTask(SClientUvTaskNode *uvTask) { uv_pipe_t *pipe = taosMemoryMalloc(sizeof(uv_pipe_t)); if(pipe == NULL) { fnError("udfc event loop start connect task malloc pipe failed."); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (uv_pipe_init(&uvTask->udfc->uvLoop, pipe, 0) != 0) { fnError("udfc event loop start connect task uv_pipe_init failed."); @@ -1762,7 +1762,7 @@ int32_t udfcStartUvTask(SClientUvTaskNode *uvTask) { fnError("udfc event loop start connect task malloc connReq failed."); taosMemoryFree(pipe); taosMemoryFree(conn); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } connReq->data = uvTask; uv_pipe_connect(connReq, pipe, uvTask->udfc->udfdPipeName, onUdfcPipeConnect); @@ -1777,7 +1777,7 @@ int32_t udfcStartUvTask(SClientUvTaskNode *uvTask) { uv_write_t *write = taosMemoryMalloc(sizeof(uv_write_t)); if(write == NULL) { fnError("udfc event loop start req_rsp task malloc write failed."); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } write->data = pipe->data; QUEUE *connTaskQueue = &((SClientUvConn *)pipe->data)->taskQueue; diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index 72eaae9451..e1dfd686d4 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -1617,7 +1617,7 @@ int32_t udfdInitResidentFuncs() { if(taosArrayPush(global.residentFuncs, func) == NULL) { taosArrayDestroy(global.residentFuncs); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } diff --git a/source/libs/index/inc/indexUtil.h b/source/libs/index/inc/indexUtil.h index 9eb8001d17..61c16e1217 100644 --- a/source/libs/index/inc/indexUtil.h +++ b/source/libs/index/inc/indexUtil.h @@ -21,29 +21,29 @@ extern "C" { #endif -#define SERIALIZE_MEM_TO_BUF(buf, key, mem) \ - do { \ - (void)memcpy((void *)buf, (void *)(&key->mem), sizeof(key->mem)); \ - buf += sizeof(key->mem); \ +#define SERIALIZE_MEM_TO_BUF(buf, key, mem) \ + do { \ + TAOS_UNUSED(memcpy((void *)buf, (void *)(&key->mem), sizeof(key->mem))); \ + buf += sizeof(key->mem); \ } while (0) -#define SERIALIZE_STR_MEM_TO_BUF(buf, key, mem, len) \ - do { \ - (void)memcpy((void *)buf, (void *)key->mem, len); \ - buf += len; \ +#define SERIALIZE_STR_MEM_TO_BUF(buf, key, mem, len) \ + do { \ + TAOS_UNUSED(memcpy((void *)buf, (void *)key->mem, len)); \ + buf += len; \ } while (0) -#define SERIALIZE_VAR_TO_BUF(buf, var, type) \ - do { \ - type c = var; \ - (void)memcpy((void *)buf, (void *)&c, sizeof(c)); \ - buf += sizeof(c); \ +#define SERIALIZE_VAR_TO_BUF(buf, var, type) \ + do { \ + type c = var; \ + TAOS_UNUSED(memcpy((void *)buf, (void *)&c, sizeof(c))); \ + buf += sizeof(c); \ } while (0) -#define SERIALIZE_STR_VAR_TO_BUF(buf, var, len) \ - do { \ - (void)memcpy((void *)buf, (void *)var, len); \ - buf += len; \ +#define SERIALIZE_STR_VAR_TO_BUF(buf, var, len) \ + do { \ + TAOS_UNUSED(memcpy((void *)buf, (void *)var, len)); \ + buf += len; \ } while (0) #define INDEX_MERGE_ADD_DEL(src, dst, tgt) \ diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index b2fd0afd68..38d4efd1ed 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -99,15 +99,15 @@ static int32_t idxMergeCacheAndTFile(SArray* result, IterateValue* icache, Itera static void idxPost(void* idx) { SIndex* pIdx = idx; - (void)tsem_post(&pIdx->sem); + TAOS_UNUSED(tsem_post(&pIdx->sem)); } static void indexWait(void* idx) { SIndex* pIdx = idx; - (void)tsem_wait(&pIdx->sem); + TAOS_UNUSED(tsem_wait(&pIdx->sem)); } int32_t indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { - (void)taosThreadOnce(&isInit, indexEnvInit); + TAOS_UNUSED(taosThreadOnce(&isInit, indexEnvInit)); int code = TSDB_CODE_SUCCESS; SIndex* idx = taosMemoryCalloc(1, sizeof(SIndex)); @@ -128,17 +128,17 @@ int32_t indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { idx->colObj = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if (idx->colObj == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, END); + TAOS_CHECK_GOTO(terrno, NULL, END); } idx->version = 1; idx->path = taosStrdup(path); if (idx->path == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, END); + TAOS_CHECK_GOTO(terrno, NULL, END); } - (void)taosThreadMutexInit(&idx->mtx, NULL); - (void)tsem_init(&idx->sem, 0, 0); + TAOS_UNUSED(taosThreadMutexInit(&idx->mtx, NULL)); + TAOS_UNUSED(tsem_init(&idx->sem, 0, 0)); idx->refId = idxAddRef(idx); idx->opts = *opts; @@ -158,8 +158,8 @@ END: void indexDestroy(void* handle) { if (handle == NULL) return; SIndex* idx = handle; - (void)taosThreadMutexDestroy(&idx->mtx); - (void)tsem_destroy(&idx->sem); + TAOS_UNUSED(taosThreadMutexDestroy(&idx->mtx)); + TAOS_UNUSED(tsem_destroy(&idx->sem)); idxTFileDestroy(idx->tindex); taosMemoryFree(idx->path); @@ -190,7 +190,7 @@ void indexClose(SIndex* sIdx) { } idxReleaseRef(sIdx->refId); - (void)idxRemoveRef(sIdx->refId); + TAOS_UNUSED(idxRemoveRef(sIdx->refId)); } int64_t idxAddRef(void* p) { // impl @@ -203,17 +203,17 @@ int32_t idxRemoveRef(int64_t ref) { void idxAcquireRef(int64_t ref) { // impl - (void)taosAcquireRef(indexRefMgt, ref); + TAOS_UNUSED(taosAcquireRef(indexRefMgt, ref)); } void idxReleaseRef(int64_t ref) { // impl - (void)taosReleaseRef(indexRefMgt, ref); + TAOS_UNUSED(taosReleaseRef(indexRefMgt, ref)); } int32_t indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) { // TODO(yihao): reduce the lock range int32_t code = 0; - (void)taosThreadMutexLock(&index->mtx); + TAOS_UNUSED(taosThreadMutexLock(&index->mtx)); for (int i = 0; i < taosArrayGetSize(fVals); i++) { SIndexTerm* p = taosArrayGetP(fVals, i); @@ -231,7 +231,7 @@ int32_t indexPut(SIndex* index, SIndexMultiTerm* fVals, uint64_t uid) { } } } - (void)taosThreadMutexUnlock(&index->mtx); + TAOS_UNUSED(taosThreadMutexUnlock(&index->mtx)); if (code != 0) { return code; @@ -261,7 +261,7 @@ int32_t indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* re SArray* iRslts = taosArrayInit(4, POINTER_BYTES); if (iRslts == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int nQuery = taosArrayGetSize(multiQuerys->query); @@ -275,10 +275,10 @@ int32_t indexSearch(SIndex* index, SIndexMultiTermQuery* multiQuerys, SArray* re } if (taosArrayPush(iRslts, (void*)&trslt) == NULL) { idxInterRsltDestroy(iRslts); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } - (void)idxMergeFinalResults(iRslts, opera, result); + TAOS_UNUSED(idxMergeFinalResults(iRslts, opera, result)); idxInterRsltDestroy(iRslts); return 0; } @@ -319,7 +319,7 @@ void indexMultiTermQueryDestroy(SIndexMultiTermQuery* pQuery) { int32_t indexMultiTermQueryAdd(SIndexMultiTermQuery* pQuery, SIndexTerm* term, EIndexQueryType qType) { SIndexTermQuery q = {.qType = qType, .term = term}; if (taosArrayPush(pQuery->query, &q) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return 0; } @@ -387,7 +387,7 @@ SIndexMultiTerm* indexMultiTermCreate() { return taosArrayInit(4, sizeof(SIndexT int32_t indexMultiTermAdd(SIndexMultiTerm* terms, SIndexTerm* term) { if (taosArrayPush(terms, &term) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return 0; } @@ -421,7 +421,7 @@ void indexRebuild(SIndexJson* idx, void* iter) { schedMsg.fp = idxSchedRebuildIdx; schedMsg.ahandle = idx; idxAcquireRef(idx->refId); - (void)taosScheduleTask(indexQhandle, &schedMsg); + TAOS_UNUSED(taosScheduleTask(indexQhandle, &schedMsg)); } /* @@ -463,14 +463,14 @@ static int32_t idxTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** resu int32_t sz = idxSerialCacheKey(&key, buf); - (void)taosThreadMutexLock(&sIdx->mtx); + TAOS_UNUSED(taosThreadMutexLock(&sIdx->mtx)); IndexCache** pCache = taosHashGet(sIdx->colObj, buf, sz); cache = (pCache == NULL) ? NULL : *pCache; - (void)taosThreadMutexUnlock(&sIdx->mtx); + TAOS_UNUSED(taosThreadMutexUnlock(&sIdx->mtx)); *result = taosArrayInit(4, sizeof(uint64_t)); if (*result == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } // TODO: iterator mem and tidex @@ -574,7 +574,7 @@ static int32_t idxMayMergeTempToFinalRslt(SArray* result, TFileValue* tfv, SIdxT } } else { if (taosArrayPush(result, &tfv) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } return code; @@ -658,7 +658,7 @@ int32_t idxFlushCacheToTFile(SIndex* sIdx, void* cache, bool quit) { SArray* result = taosArrayInit(1024, sizeof(void*)); if (result == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); + TAOS_CHECK_GOTO(terrno, NULL, _exception); } bool cn = cacheIter ? cacheIter->next(cacheIter) : false; @@ -666,7 +666,7 @@ int32_t idxFlushCacheToTFile(SIndex* sIdx, void* cache, bool quit) { SIdxTRslt* tr = idxTRsltCreate(); if (tr == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); + TAOS_CHECK_GOTO(terrno, NULL, _exception); } while (cn == true || tn == true) { IterateValue* cv = (cn == true) ? cacheIter->getValue(cacheIter) : NULL; @@ -757,9 +757,9 @@ static int64_t idxGetAvailableVer(SIndex* sIdx, IndexCache* cache) { IndexTFile* tf = (IndexTFile*)(sIdx->tindex); - (void)taosThreadMutexLock(&tf->mtx); + TAOS_UNUSED(taosThreadMutexLock(&tf->mtx)); TFileReader* rd = tfileCacheGet(tf->cache, &key); - (void)taosThreadMutexUnlock(&tf->mtx); + TAOS_UNUSED(taosThreadMutexUnlock(&tf->mtx)); if (rd != NULL) { ver = (ver > rd->header.version ? ver : rd->header.version) + 1; @@ -801,9 +801,9 @@ static int32_t idxGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) { TFileHeader* header = &reader->header; ICacheKey key = {.suid = cache->suid, .colName = header->colName, .nColName = strlen(header->colName)}; - (void)taosThreadMutexLock(&tf->mtx); + TAOS_UNUSED(taosThreadMutexLock(&tf->mtx)); code = tfileCachePut(tf->cache, &key, reader); - (void)taosThreadMutexUnlock(&tf->mtx); + TAOS_UNUSED(taosThreadMutexUnlock(&tf->mtx)); return code; @@ -820,7 +820,7 @@ int32_t idxSerialCacheKey(ICacheKey* key, char* buf) { char* p = buf; char tbuf[65] = {0}; - (void)idxInt2str((int64_t)key->suid, tbuf, 0); + TAOS_UNUSED(idxInt2str((int64_t)key->suid, tbuf, 0)); SERIALIZE_STR_VAR_TO_BUF(buf, tbuf, strlen(tbuf)); SERIALIZE_VAR_TO_BUF(buf, '_', char); diff --git a/source/libs/index/src/indexCache.c b/source/libs/index/src/indexCache.c index 828a3e2e9e..4a03edaef4 100644 --- a/source/libs/index/src/indexCache.c +++ b/source/libs/index/src/indexCache.c @@ -80,6 +80,10 @@ static int32_t cacheSearchTerm(void* cache, SIndexTerm* term, SIdxTRslt* tr, STe IndexCache* pCache = mem->pCache; CacheTerm* pCt = taosMemoryCalloc(1, sizeof(CacheTerm)); + if (pCt == NULL) { + return terrno; + } + pCt->colVal = term->colVal; pCt->version = atomic_load_64(&pCache->version); @@ -109,7 +113,7 @@ static int32_t cacheSearchTerm(void* cache, SIndexTerm* term, SIdxTRslt* tr, STe } taosMemoryFree(pCt); - (void)tSkipListDestroyIter(iter); + TAOS_UNUSED(tSkipListDestroyIter(iter)); return code; } static int32_t cacheSearchPrefix(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) { @@ -153,7 +157,7 @@ static int32_t cacheSearchCompareFunc(void* cache, SIndexTerm* term, SIdxTRslt* break; } CacheTerm* c = (CacheTerm*)SL_GET_NODE_DATA(node); - TExeCond cond = cmpFn(c->colVal, pCt->colVal, pCt->colType); + TExeCond cond = cmpFn(c->colVal, pCt->colVal, pCt->colType); if (cond == FAILED) { code = terrno; goto _return; @@ -178,7 +182,7 @@ static int32_t cacheSearchCompareFunc(void* cache, SIndexTerm* term, SIdxTRslt* _return: taosMemoryFree(pCt); - (void)tSkipListDestroyIter(iter); + TAOS_UNUSED(tSkipListDestroyIter(iter)); return code; } static int32_t cacheSearchLessThan(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) { @@ -244,7 +248,7 @@ static int32_t cacheSearchTerm_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr taosMemoryFree(pCt); taosMemoryFree(exBuf); - (void)tSkipListDestroyIter(iter); + TAOS_UNUSED(tSkipListDestroyIter(iter)); return code; } static int32_t cacheSearchSuffix_JSON(void* cache, SIndexTerm* term, SIdxTRslt* tr, STermValueType* s) { @@ -290,6 +294,10 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR IndexCache* pCache = mem->pCache; CacheTerm* pCt = taosMemoryCalloc(1, sizeof(CacheTerm)); + if (pCt == NULL) { + return terrno; + } + pCt->colVal = term->colVal; pCt->version = atomic_load_64(&pCache->version); @@ -363,7 +371,7 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTR _return: taosMemoryFree(pCt); taosMemoryFree(exBuf); - (void)tSkipListDestroyIter(iter); + TAOS_UNUSED(tSkipListDestroyIter(iter)); return code; } @@ -390,8 +398,8 @@ IndexCache* idxCacheCreate(SIndex* idx, uint64_t suid, const char* colName, int8 cache->suid = suid; cache->occupiedMem = 0; - (void)taosThreadMutexInit(&cache->mtx, NULL); - (void)taosThreadCondInit(&cache->finished, NULL); + TAOS_UNUSED(taosThreadMutexInit(&cache->mtx, NULL)); + TAOS_UNUSED(taosThreadCondInit(&cache->finished, NULL)); idxCacheRef(cache); if (idx != NULL) { @@ -402,10 +410,10 @@ IndexCache* idxCacheCreate(SIndex* idx, uint64_t suid, const char* colName, int8 void idxCacheDebug(IndexCache* cache) { MemTable* tbl = NULL; - (void)taosThreadMutexLock(&cache->mtx); + TAOS_UNUSED(taosThreadMutexLock(&cache->mtx)); tbl = cache->mem; idxMemRef(tbl); - (void)taosThreadMutexUnlock(&cache->mtx); + TAOS_UNUSED(taosThreadMutexUnlock(&cache->mtx)); { SSkipList* slt = tbl->mem; @@ -418,16 +426,16 @@ void idxCacheDebug(IndexCache* cache) { indexInfo("{colVal: %s, version: %" PRId64 "} \t", ct->colVal, ct->version); } } - (void)tSkipListDestroyIter(iter); + TAOS_UNUSED(tSkipListDestroyIter(iter)); idxMemUnRef(tbl); } { - (void)taosThreadMutexLock(&cache->mtx); + TAOS_UNUSED(taosThreadMutexLock(&cache->mtx)); tbl = cache->imm; idxMemRef(tbl); - (void)taosThreadMutexUnlock(&cache->mtx); + TAOS_UNUSED(taosThreadMutexUnlock(&cache->mtx)); if (tbl != NULL) { SSkipList* slt = tbl->mem; SSkipListIterator* iter = tSkipListCreateIter(slt); @@ -439,7 +447,7 @@ void idxCacheDebug(IndexCache* cache) { indexInfo("{colVal: %s, version: %" PRId64 "} \t", ct->colVal, ct->version); } } - (void)tSkipListDestroyIter(iter); + TAOS_UNUSED(tSkipListDestroyIter(iter)); } idxMemUnRef(tbl); @@ -456,29 +464,29 @@ void idxCacheDestroySkiplist(SSkipList* slt) { taosMemoryFree(ct); } } - (void)tSkipListDestroyIter(iter); + TAOS_UNUSED(tSkipListDestroyIter(iter)); tSkipListDestroy(slt); } void idxCacheBroadcast(void* cache) { IndexCache* pCache = cache; - (void)taosThreadCondBroadcast(&pCache->finished); + TAOS_UNUSED(taosThreadCondBroadcast(&pCache->finished)); } void idxCacheWait(void* cache) { IndexCache* pCache = cache; - (void)taosThreadCondWait(&pCache->finished, &pCache->mtx); + TAOS_UNUSED(taosThreadCondWait(&pCache->finished, &pCache->mtx)); } void idxCacheDestroyImm(IndexCache* cache) { if (cache == NULL) { return; } MemTable* tbl = NULL; - (void)taosThreadMutexLock(&cache->mtx); + TAOS_UNUSED(taosThreadMutexLock(&cache->mtx)); tbl = cache->imm; cache->imm = NULL; // or throw int bg thread idxCacheBroadcast(cache); - (void)taosThreadMutexUnlock(&cache->mtx); + TAOS_UNUSED(taosThreadMutexUnlock(&cache->mtx)); idxMemUnRef(tbl); idxMemUnRef(tbl); @@ -493,8 +501,8 @@ void idxCacheDestroy(void* cache) { idxMemUnRef(pCache->imm); taosMemoryFree(pCache->colName); - (void)taosThreadMutexDestroy(&pCache->mtx); - (void)taosThreadCondDestroy(&pCache->finished); + TAOS_UNUSED(taosThreadMutexDestroy(&pCache->mtx)); + TAOS_UNUSED(taosThreadCondDestroy(&pCache->finished)); if (pCache->index != NULL) { idxReleaseRef(((SIndex*)pCache->index)->refId); } @@ -509,7 +517,7 @@ Iterate* idxCacheIteratorCreate(IndexCache* cache) { if (iter == NULL) { return NULL; } - (void)taosThreadMutexLock(&cache->mtx); + TAOS_UNUSED(taosThreadMutexLock(&cache->mtx)); idxMemRef(cache->imm); @@ -520,7 +528,7 @@ Iterate* idxCacheIteratorCreate(IndexCache* cache) { iter->next = idxCacheIteratorNext; iter->getValue = idxCacheIteratorGetValue; - (void)taosThreadMutexUnlock(&cache->mtx); + TAOS_UNUSED(taosThreadMutexUnlock(&cache->mtx)); return iter; } @@ -528,7 +536,7 @@ void idxCacheIteratorDestroy(Iterate* iter) { if (iter == NULL) { return; } - (void)tSkipListDestroyIter(iter->iter); + TAOS_UNUSED(tSkipListDestroyIter(iter->iter)); iterateValueDestroy(&iter->val, true); taosMemoryFree(iter); } @@ -539,10 +547,14 @@ int idxCacheSchedToMerge(IndexCache* pCache, bool notify) { schedMsg.ahandle = pCache; if (notify) { schedMsg.thandle = taosMemoryMalloc(1); + if (schedMsg.thandle == NULL) { + indexError("fail to schedule merge task"); + return terrno; + } } schedMsg.msg = NULL; idxAcquireRef(pCache->index->refId); - (void)taosScheduleTask(indexQhandle, &schedMsg); + TAOS_UNUSED(taosScheduleTask(indexQhandle, &schedMsg)); return 0; } @@ -567,7 +579,7 @@ static void idxCacheMakeRoomForWrite(IndexCache* cache) { } // 1. sched to merge // 2. unref cache in bgwork - (void)idxCacheSchedToMerge(cache, quit); + TAOS_UNUSED(idxCacheSchedToMerge(cache, quit)); } } } @@ -603,15 +615,15 @@ int idxCachePut(void* cache, SIndexTerm* term, uint64_t uid) { // ugly code, refactor later int64_t estimate = sizeof(ct) + strlen(ct->colVal); - (void)taosThreadMutexLock(&pCache->mtx); + TAOS_UNUSED(taosThreadMutexLock(&pCache->mtx)); pCache->occupiedMem += estimate; idxCacheMakeRoomForWrite(pCache); MemTable* tbl = pCache->mem; idxMemRef(tbl); - (void)tSkipListPut(tbl->mem, (char*)ct); + TAOS_UNUSED(tSkipListPut(tbl->mem, (char*)ct)); idxMemUnRef(tbl); - (void)taosThreadMutexUnlock(&pCache->mtx); + TAOS_UNUSED(taosThreadMutexUnlock(&pCache->mtx)); idxCacheUnRef(pCache); return 0; } @@ -619,13 +631,13 @@ void idxCacheForceToMerge(void* cache) { IndexCache* pCache = cache; idxCacheRef(pCache); - (void)taosThreadMutexLock(&pCache->mtx); + TAOS_UNUSED(taosThreadMutexLock(&pCache->mtx)); indexInfo("%p is forced to merge into tfile", pCache); pCache->occupiedMem += MEM_SIGNAL_QUIT; idxCacheMakeRoomForWrite(pCache); - (void)taosThreadMutexUnlock(&pCache->mtx); + TAOS_UNUSED(taosThreadMutexUnlock(&pCache->mtx)); idxCacheUnRef(pCache); return; } @@ -656,12 +668,12 @@ int idxCacheSearch(void* cache, SIndexTermQuery* query, SIdxTRslt* result, STerm IndexCache* pCache = cache; MemTable *mem = NULL, *imm = NULL; - (void)taosThreadMutexLock(&pCache->mtx); + TAOS_UNUSED(taosThreadMutexLock(&pCache->mtx)); mem = pCache->mem; imm = pCache->imm; idxMemRef(mem); idxMemRef(imm); - (void)taosThreadMutexUnlock(&pCache->mtx); + TAOS_UNUSED(taosThreadMutexUnlock(&pCache->mtx)); int64_t st = taosGetTimestampUs(); @@ -797,7 +809,7 @@ static void idxDoMergeWork(SSchedMsg* msg) { int quit = msg->thandle ? true : false; taosMemoryFree(msg->thandle); - (void)idxFlushCacheToTFile(sidx, pCache, quit); + TAOS_UNUSED(idxFlushCacheToTFile(sidx, pCache, quit)); } static bool idxCacheIteratorNext(Iterate* itera) { SSkipListIterator* iter = itera->iter; diff --git a/source/libs/index/src/indexComm.c b/source/libs/index/src/indexComm.c index 0fab194044..ce68615c0f 100644 --- a/source/libs/index/src/indexComm.c +++ b/source/libs/index/src/indexComm.c @@ -260,7 +260,10 @@ char* idxPackJsonData(SIndexTerm* itm) { int32_t sz = itm->nColName + itm->nColVal + sizeof(uint8_t) + sizeof(JSON_VALUE_DELIM) * 2 + 1; char* buf = (char*)taosMemoryCalloc(1, sz); - char* p = buf; + if (buf == NULL) { + return NULL; + } + char* p = buf; memcpy(p, itm->colName, itm->nColName); p += itm->nColName; @@ -288,7 +291,10 @@ char* idxPackJsonDataPrefix(SIndexTerm* itm, int32_t* skip) { int32_t sz = itm->nColName + itm->nColVal + sizeof(uint8_t) + sizeof(JSON_VALUE_DELIM) * 2 + 1; char* buf = (char*)taosMemoryCalloc(1, sz); - char* p = buf; + if (buf == NULL) { + return NULL; + } + char* p = buf; memcpy(p, itm->colName, itm->nColName); p += itm->nColName; @@ -315,7 +321,11 @@ char* idxPackJsonDataPrefixNoType(SIndexTerm* itm, int32_t* skip) { int32_t sz = itm->nColName + itm->nColVal + sizeof(uint8_t) + sizeof(JSON_VALUE_DELIM) * 2 + 1; char* buf = (char*)taosMemoryCalloc(1, sz); - char* p = buf; + if (buf == NULL) { + return NULL; + } + + char* p = buf; memcpy(p, itm->colName, itm->nColName); p += itm->nColName; @@ -349,7 +359,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { if (*dst == NULL) { return terrno; } - (void)idxInt2str(*(int64_t*)src, *dst, -1); + TAOS_UNUSED(idxInt2str(*(int64_t*)src, *dst, -1)); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_BOOL: @@ -358,7 +368,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { if (*dst == NULL) { return terrno; } - (void)idxInt2str(*(uint8_t*)src, *dst, 1); + TAOS_UNUSED(idxInt2str(*(uint8_t*)src, *dst, 1)); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_TINYINT: @@ -366,7 +376,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { if (*dst == NULL) { return terrno; } - (void)idxInt2str(*(int8_t*)src, *dst, 1); + TAOS_UNUSED(idxInt2str(*(int8_t*)src, *dst, 1)); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_SMALLINT: @@ -374,12 +384,12 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { if (*dst == NULL) { return terrno; } - (void)idxInt2str(*(int16_t*)src, *dst, -1); + TAOS_UNUSED(idxInt2str(*(int16_t*)src, *dst, -1)); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_USMALLINT: *dst = taosMemoryCalloc(1, bufSize + 1); - (void)idxInt2str(*(uint16_t*)src, *dst, -1); + TAOS_UNUSED(idxInt2str(*(uint16_t*)src, *dst, -1)); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_INT: @@ -387,7 +397,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { if (*dst == NULL) { return terrno; } - (void)idxInt2str(*(int32_t*)src, *dst, -1); + TAOS_UNUSED(idxInt2str(*(int32_t*)src, *dst, -1)); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_UINT: @@ -395,7 +405,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { if (*dst == NULL) { return terrno; } - (void)idxInt2str(*(uint32_t*)src, *dst, 1); + TAOS_UNUSED(idxInt2str(*(uint32_t*)src, *dst, 1)); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_BIGINT: @@ -411,7 +421,7 @@ int32_t idxConvertDataToStr(void* src, int8_t type, void** dst) { if (*dst == NULL) { return terrno; } - (void)idxInt2str(*(uint64_t*)src, *dst, 1); + TAOS_UNUSED(idxInt2str(*(uint64_t*)src, *dst, 1)); tlen = strlen(*dst); break; case TSDB_DATA_TYPE_FLOAT: diff --git a/source/libs/index/src/indexFilter.c b/source/libs/index/src/indexFilter.c index fa59fe23fe..02e5bd34a6 100644 --- a/source/libs/index/src/indexFilter.c +++ b/source/libs/index/src/indexFilter.c @@ -1033,7 +1033,7 @@ static int32_t sifCalculate(SNode *pNode, SIFParam *pDst) { if (NULL == ctx.pRes) { indexError("index-filter failed to taosHashInit"); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } nodesWalkExprPostOrder(pNode, sifCalcWalker, &ctx); @@ -1057,7 +1057,7 @@ static int32_t sifCalculate(SNode *pNode, SIFParam *pDst) { pDst->status = res->status; sifFreeParam(res); - (void)taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES); + TAOS_UNUSED(taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES)); } sifFreeRes(ctx.pRes); return code; @@ -1073,7 +1073,7 @@ static int32_t sifGetFltHint(SNode *pNode, SIdxFltStatus *status, SMetaDataFilte ctx.pRes = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); if (NULL == ctx.pRes) { indexError("index-filter failed to taosHashInit"); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } nodesWalkExprPostOrder(pNode, sifCalcWalker, &ctx); @@ -1089,7 +1089,7 @@ static int32_t sifGetFltHint(SNode *pNode, SIdxFltStatus *status, SMetaDataFilte } *status = res->status; sifFreeParam(res); - (void)taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES); + TAOS_UNUSED(taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES)); void *iter = taosHashIterate(ctx.pRes, NULL); while (iter != NULL) { @@ -1113,7 +1113,7 @@ int32_t doFilterTag(SNode *pFilterNode, SIndexMetaArg *metaArg, SArray *result, SArray *output = taosArrayInit(8, sizeof(uint64_t)); if (output == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SIFParam param = {.arg = *metaArg, .result = output, .status = SFLT_NOT_INDEX, .api = *pAPI}; diff --git a/source/libs/index/src/indexFst.c b/source/libs/index/src/indexFst.c index aa617c2de2..6f07df50fb 100644 --- a/source/libs/index/src/indexFst.c +++ b/source/libs/index/src/indexFst.c @@ -57,9 +57,17 @@ void fstUnFinishedNodesDestroy(FstUnFinishedNodes* nodes) { void fstUnFinishedNodesPushEmpty(FstUnFinishedNodes* nodes, bool isFinal) { FstBuilderNode* node = taosMemoryMalloc(sizeof(FstBuilderNode)); + if (node == NULL) { + return; + } + node->isFinal = isFinal; node->finalOutput = 0; node->trans = taosArrayInit(16, sizeof(FstTransition)); + if (node->trans == NULL) { + taosMemoryFree(node); + return; + } FstBuilderNodeUnfinished un = {.node = node, .last = NULL}; if (taosArrayPush(nodes->stack, &un) == NULL) { @@ -112,6 +120,9 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes* nodes, FstSlice bs, Output for (uint64_t i = 1; i < len; i++) { FstBuilderNode* n = taosMemoryMalloc(sizeof(FstBuilderNode)); + if (n == NULL) { + return; + } n->isFinal = false; n->finalOutput = 0; n->trans = taosArrayInit(16, sizeof(FstTransition)); @@ -219,9 +230,9 @@ void fstStateCompileForOneTransNext(IdxFstFile* w, CompiledAddr addr, uint8_t in uint8_t v = fstStateCommInput(&s, &null); if (null) { // w->write_all(&[inp]) - (void)idxFileWrite(w, &inp, 1); + TAOS_UNUSED(idxFileWrite(w, &inp, 1)); } - (void)idxFileWrite(w, &(s.val), 1); + TAOS_UNUSED(idxFileWrite(w, &(s.val), 1)); // w->write_all(&[s.val]) return; } @@ -233,7 +244,7 @@ void fstStateCompileForOneTrans(IdxFstFile* w, CompiledAddr addr, FstTransition* FST_SET_OUTPUT_PACK_SIZE(packSizes, outPackSize); FST_SET_TRANSITION_PACK_SIZE(packSizes, transPackSize); - (void)idxFileWrite(w, (char*)&packSizes, sizeof(packSizes)); + TAOS_UNUSED(idxFileWrite(w, (char*)&packSizes, sizeof(packSizes))); FstState st = fstStateCreate(OneTrans); @@ -242,9 +253,9 @@ void fstStateCompileForOneTrans(IdxFstFile* w, CompiledAddr addr, FstTransition* bool null = false; uint8_t inp = fstStateCommInput(&st, &null); if (null == true) { - (void)idxFileWrite(w, (char*)&trn->inp, sizeof(trn->inp)); + TAOS_UNUSED(idxFileWrite(w, (char*)&trn->inp, sizeof(trn->inp))); } - (void)idxFileWrite(w, (char*)(&(st.val)), sizeof(st.val)); + TAOS_UNUSED(idxFileWrite(w, (char*)(&(st.val)), sizeof(st.val))); return; } void fstStateCompileForAnyTrans(IdxFstFile* w, CompiledAddr addr, FstBuilderNode* node) { @@ -290,34 +301,37 @@ void fstStateCompileForAnyTrans(IdxFstFile* w, CompiledAddr addr, FstBuilderNode } for (int32_t i = sz - 1; i >= 0; i--) { FstTransition* t = taosArrayGet(node->trans, i); - (void)idxFileWrite(w, (char*)&t->inp, 1); + TAOS_UNUSED(idxFileWrite(w, (char*)&t->inp, 1)); } if (sz > TRANS_INDEX_THRESHOLD) { // A value of 255 indicates that no transition exists for the byte at that idx uint8_t* index = (uint8_t*)taosMemoryMalloc(sizeof(uint8_t) * 256); + if (index == NULL) { + return; + } memset(index, 255, sizeof(uint8_t) * 256); for (int32_t i = 0; i < sz; i++) { FstTransition* t = taosArrayGet(node->trans, i); index[t->inp] = i; } - (void)idxFileWrite(w, (char*)index, 256); + TAOS_UNUSED(idxFileWrite(w, (char*)index, 256)); taosMemoryFree(index); } - (void)idxFileWrite(w, (char*)&packSizes, 1); + TAOS_UNUSED(idxFileWrite(w, (char*)&packSizes, 1)); bool null = false; - (void)fstStateStateNtrans(&st, &null); + TAOS_UNUSED(fstStateStateNtrans(&st, &null)); if (null == true) { // 256 can't be represented in a u8, so we abuse the fact that // the # of transitions can never be 1 here, since 1 is always // encoded in the state byte. uint8_t v = 1; if (sz == 256) { - (void)idxFileWrite(w, (char*)&v, 1); + TAOS_UNUSED(idxFileWrite(w, (char*)&v, 1)); } else { - (void)idxFileWrite(w, (char*)&sz, 1); + TAOS_UNUSED(idxFileWrite(w, (char*)&sz, 1)); } } - (void)idxFileWrite(w, (char*)(&(st.val)), 1); + TAOS_UNUSED(idxFileWrite(w, (char*)(&(st.val)), 1)); return; } @@ -343,7 +357,7 @@ uint8_t fstStateCommInput(FstState* s, bool* null) { uint64_t fstStateInputLen(FstState* s) { bool null = false; - (void)fstStateCommInput(s, &null); + TAOS_UNUSED(fstStateCommInput(s, &null)); return null ? 1 : 0; } @@ -479,7 +493,7 @@ uint64_t fstStateTransIndexSize(FstState* s, uint64_t version, uint64_t nTrans) } uint64_t fstStateNtransLen(FstState* s) { bool null = false; - (void)fstStateStateNtrans(s, &null); + TAOS_UNUSED(fstStateStateNtrans(s, &null)); return null == true ? 1 : 0; } uint64_t fstStateNtrans(FstState* s, FstSlice* slice) { @@ -651,11 +665,11 @@ bool fstNodeGetTransitionAddrAt(FstNode* node, uint64_t i, CompiledAddr* res) { bool s = true; FstState* st = &node->state; if (st->state == OneTransNext) { - (void)fstStateTransAddr(st, node); + TAOS_UNUSED(fstStateTransAddr(st, node)); } else if (st->state == OneTrans) { - (void)fstStateTransAddr(st, node); + TAOS_UNUSED(fstStateTransAddr(st, node)); } else if (st->state == AnyTrans) { - (void)fstStateTransAddrForAnyTrans(st, node, i); + TAOS_UNUSED(fstStateTransAddrForAnyTrans(st, node, i)); } else if (FST_STATE_EMPTY_FINAL(node)) { s = false; } else { @@ -730,13 +744,13 @@ FstBuilder* fstBuilderCreate(void* w, FstType ty) { char buf64[8] = {0}; void* pBuf64 = buf64; - (void)taosEncodeFixedU64(&pBuf64, VERSION); - (void)idxFileWrite(b->wrt, buf64, sizeof(buf64)); + TAOS_UNUSED(taosEncodeFixedU64(&pBuf64, VERSION)); + TAOS_UNUSED(idxFileWrite(b->wrt, buf64, sizeof(buf64))); pBuf64 = buf64; memset(buf64, 0, sizeof(buf64)); - (void)taosEncodeFixedU64(&pBuf64, ty); - (void)idxFileWrite(b->wrt, buf64, sizeof(buf64)); + TAOS_UNUSED(taosEncodeFixedU64(&pBuf64, ty)); + TAOS_UNUSED(idxFileWrite(b->wrt, buf64, sizeof(buf64))); return b; } @@ -835,7 +849,7 @@ CompiledAddr fstBuilderCompile(FstBuilder* b, FstBuilderNode* bn) { } CompiledAddr startAddr = (CompiledAddr)(FST_WRITER_COUNT(b->wrt)); - (void)fstBuilderNodeCompileTo(bn, b->wrt, b->lastAddr, startAddr); + TAOS_UNUSED(fstBuilderNodeCompileTo(bn, b->wrt, b->lastAddr, startAddr)); b->lastAddr = (CompiledAddr)(FST_WRITER_COUNT(b->wrt) - 1); if (entry->state == NOTFOUND) { FST_REGISTRY_CELL_INSERT(entry->cell, b->lastAddr); @@ -854,23 +868,23 @@ void* fstBuilderInsertInner(FstBuilder* b) { char buf64[8] = {0}; void* pBuf64 = buf64; - (void)taosEncodeFixedU64(&pBuf64, b->len); - (void)idxFileWrite(b->wrt, buf64, sizeof(buf64)); + TAOS_UNUSED(taosEncodeFixedU64(&pBuf64, b->len)); + TAOS_UNUSED(idxFileWrite(b->wrt, buf64, sizeof(buf64))); pBuf64 = buf64; - (void)taosEncodeFixedU64(&pBuf64, rootAddr); - (void)idxFileWrite(b->wrt, buf64, sizeof(buf64)); + TAOS_UNUSED(taosEncodeFixedU64(&pBuf64, rootAddr)); + TAOS_UNUSED(idxFileWrite(b->wrt, buf64, sizeof(buf64))); char buf32[4] = {0}; void* pBuf32 = buf32; uint32_t sum = idxFileMaskedCheckSum(b->wrt); - (void)taosEncodeFixedU32(&pBuf32, sum); - (void)idxFileWrite(b->wrt, buf32, sizeof(buf32)); + TAOS_UNUSED(taosEncodeFixedU32(&pBuf32, sum)); + TAOS_UNUSED(idxFileWrite(b->wrt, buf32, sizeof(buf32))); - (void)idxFileFlush(b->wrt); + TAOS_UNUSED(idxFileFlush(b->wrt)); return b->wrt; } -void fstBuilderFinish(FstBuilder* b) { (void)fstBuilderInsertInner(b); } +void fstBuilderFinish(FstBuilder* b) { TAOS_UNUSED(fstBuilderInsertInner(b)); } FstSlice fstNodeAsSlice(FstNode* node) { FstSlice* slice = &node->data; @@ -930,19 +944,19 @@ Fst* fstCreate(FstSlice* slice) { uint64_t skip = 0; uint64_t version; - (void)taosDecodeFixedU64(buf, &version); + TAOS_UNUSED(taosDecodeFixedU64(buf, &version)); skip += sizeof(version); if (version == 0 || version > VERSION) { return NULL; } uint64_t type; - (void)taosDecodeFixedU64(buf + skip, &type); + TAOS_UNUSED(taosDecodeFixedU64(buf + skip, &type)); skip += sizeof(type); uint32_t checkSum = 0; len -= sizeof(checkSum); - (void)taosDecodeFixedU32(buf + len, &checkSum); + TAOS_UNUSED(taosDecodeFixedU32(buf + len, &checkSum)); if (taosCheckChecksum(buf, len, checkSum)) { indexError("index file is corrupted"); // verify fst @@ -950,11 +964,11 @@ Fst* fstCreate(FstSlice* slice) { } CompiledAddr rootAddr; len -= sizeof(rootAddr); - (void)taosDecodeFixedU64(buf + len, &rootAddr); + TAOS_UNUSED(taosDecodeFixedU64(buf + len, &rootAddr)); uint64_t fstLen; len -= sizeof(fstLen); - (void)taosDecodeFixedU64(buf + len, &fstLen); + TAOS_UNUSED(taosDecodeFixedU64(buf + len, &fstLen)); // TODO(validate root addr) Fst* fst = (Fst*)taosMemoryCalloc(1, sizeof(Fst)); if (fst == NULL) { @@ -973,10 +987,14 @@ Fst* fstCreate(FstSlice* slice) { fst->meta->checkSum = checkSum; FstSlice* s = taosMemoryCalloc(1, sizeof(FstSlice)); + if (s == NULL) { + goto FST_CREAT_FAILED; + } + *s = fstSliceCopy(slice, 0, FST_SLICE_LEN(slice) - 1); fst->data = s; - (void)taosThreadMutexInit(&fst->mtx, NULL); + TAOS_UNUSED(taosThreadMutexInit(&fst->mtx, NULL)); return fst; FST_CREAT_FAILED: @@ -990,7 +1008,7 @@ void fstDestroy(Fst* fst) { taosMemoryFree(fst->meta); fstSliceDestroy(fst->data); taosMemoryFree(fst->data); - (void)taosThreadMutexDestroy(&fst->mtx); + TAOS_UNUSED(taosThreadMutexDestroy(&fst->mtx)); } taosMemoryFree(fst); } @@ -1018,7 +1036,7 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) { } FstTransition trn; - (void)fstNodeGetTransitionAt(root, res, &trn); + TAOS_UNUSED(fstNodeGetTransitionAt(root, res, &trn)); tOut += trn.out; root = fstGetNode(fst, trn.addr); if (taosArrayPush(nodes, &root) == NULL) { @@ -1145,7 +1163,7 @@ FStmSt* stmStCreate(Fst* fst, FAutoCtx* automation, FstBoundWithData* min, FstBo sws->stack = (SArray*)taosArrayInit(256, sizeof(FstStreamState)); sws->endAt = max; - (void)stmStSeekMin(sws, min); + TAOS_UNUSED(stmStSeekMin(sws, min)); return sws; } @@ -1198,7 +1216,7 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) { uint64_t res = 0; if (fstNodeFindInput(node, b, &res)) { FstTransition trn; - (void)fstNodeGetTransitionAt(node, res, &trn); + TAOS_UNUSED(fstNodeGetTransitionAt(node, res, &trn)); void* preState = autState; autState = automFuncs[aut->type].accept(aut, preState, b); if (taosArrayPush(sws->inp, &b) == NULL) { @@ -1244,12 +1262,12 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) { FstStreamState* s = taosArrayGet(sws->stack, sz - 1); if (inclusize) { s->trans -= 1; - (void)taosArrayPop(sws->inp); + TAOS_UNUSED(taosArrayPop(sws->inp)); } else { FstNode* n = s->node; uint64_t trans = s->trans; FstTransition trn; - (void)fstNodeGetTransitionAt(n, trans - 1, &trn); + TAOS_UNUSED(fstNodeGetTransitionAt(n, trans - 1, &trn)); FstStreamState s = { .node = fstGetNode(sws->fst, trn.addr), .trans = 0, .out = {.null = false, .out = out}, .autState = autState}; if (taosArrayPush(sws->stack, &s) == NULL) { @@ -1283,13 +1301,13 @@ FStmStRslt* stmStNextWith(FStmSt* sws, streamCallback__fn callback) { FstStreamState* p = (FstStreamState*)taosArrayPop(sws->stack); if (p->trans >= FST_NODE_LEN(p->node) || !automFuncs[aut->type].canMatch(aut, p->autState)) { if (FST_NODE_ADDR(p->node) != fstGetRootAddr(sws->fst)) { - (void)taosArrayPop(sws->inp); + TAOS_UNUSED(taosArrayPop(sws->inp)); } fstStreamStateDestroy(p); continue; } FstTransition trn; - (void)fstNodeGetTransitionAt(p->node, p->trans, &trn); + TAOS_UNUSED(fstNodeGetTransitionAt(p->node, p->trans, &trn)); Output out = p->out.out + trn.out; void* nextState = automFuncs[aut->type].accept(aut, p->autState, trn.inp); @@ -1326,6 +1344,9 @@ FStmStRslt* stmStNextWith(FStmSt* sws, streamCallback__fn callback) { int32_t isz = taosArrayGetSize(sws->inp); uint8_t* buf = (uint8_t*)taosMemoryMalloc(isz * sizeof(uint8_t)); + if (buf == NULL) { + return NULL; + } for (uint32_t i = 0; i < isz; i++) { buf[i] = *(uint8_t*)taosArrayGet(sws->inp, i); } diff --git a/source/libs/index/src/indexFstAutomation.c b/source/libs/index/src/indexFstAutomation.c index 0c96d1aa0a..d0ea30997e 100644 --- a/source/libs/index/src/indexFstAutomation.c +++ b/source/libs/index/src/indexFstAutomation.c @@ -28,6 +28,11 @@ StartWithStateValue* startWithStateValueCreate(StartWithStateKind kind, ValueTyp } else if (ty == FST_CHAR) { size_t len = strlen((char*)val); sv->ptr = (char*)taosMemoryCalloc(1, len + 1); + if (sv->ptr == NULL) { + taosMemoryFree(sv); + return NULL; + } + memcpy(sv->ptr, val, len); } else if (ty == FST_ARRAY) { // TODO, @@ -63,6 +68,11 @@ StartWithStateValue* startWithStateValueDump(StartWithStateValue* sv) { } else if (nsv->type == FST_CHAR) { size_t len = strlen(sv->ptr); nsv->ptr = (char*)taosMemoryCalloc(1, len + 1); + if (nsv->ptr == NULL) { + taosMemoryFree(nsv); + return NULL; + } + memcpy(nsv->ptr, sv->ptr, len); } else if (nsv->type == FST_ARRAY) { // diff --git a/source/libs/index/src/indexFstDfa.c b/source/libs/index/src/indexFstDfa.c index c95847525f..3b0014f16a 100644 --- a/source/libs/index/src/indexFstDfa.c +++ b/source/libs/index/src/indexFstDfa.c @@ -132,7 +132,7 @@ bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet bool succ = sparSetAdd(cur, ip, NULL); if (succ == false) return false; } - (void)dfaRun(builder->dfa, cur, next, byte); + TAOS_UNUSED(dfaRun(builder->dfa, cur, next, byte)); t = taosArrayGet(builder->dfa->states, state); @@ -149,7 +149,7 @@ bool dfaBuilderCacheState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *r int32_t code = 0; SArray *tinsts = taosArrayInit(4, sizeof(uint32_t)); if (tinsts == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exception; } bool isMatch = false; @@ -163,13 +163,13 @@ bool dfaBuilderCacheState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *r continue; } else if (inst->ty == RANGE) { if (taosArrayPush(tinsts, &ip) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exception; } } else if (inst->ty == MATCH) { isMatch = true; if (taosArrayPush(tinsts, &ip) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exception; } } @@ -185,7 +185,7 @@ bool dfaBuilderCacheState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *r } else { DfaState st = {.insts = tinsts, .isMatch = isMatch}; if (taosArrayPush(builder->dfa->states, &st) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exception; } diff --git a/source/libs/index/src/indexFstFile.c b/source/libs/index/src/indexFstFile.c index 5c6a39d13c..73ecb22b3b 100644 --- a/source/libs/index/src/indexFstFile.c +++ b/source/libs/index/src/indexFstFile.c @@ -30,7 +30,9 @@ typedef struct { } SDataBlock; static void deleteDataBlockFromLRU(const void* key, size_t keyLen, void* value, void* ud) { - (void)ud; + TAOS_UNUSED(ud); + TAOS_UNUSED(key); + TAOS_UNUSED(keyLen); taosMemoryFree(value); } @@ -38,7 +40,7 @@ static FORCE_INLINE void idxGenLRUKey(char* buf, const char* path, int32_t block char* p = buf; SERIALIZE_STR_VAR_TO_BUF(p, path, strlen(path)); SERIALIZE_VAR_TO_BUF(p, '_', char); - (void)idxInt2str(blockId, p, 0); + TAOS_UNUSED(idxInt2str(blockId, p, 0)); return; } static FORCE_INLINE int idxFileCtxDoWrite(IFileCtx* ctx, uint8_t* buf, int len) { @@ -48,7 +50,7 @@ static FORCE_INLINE int idxFileCtxDoWrite(IFileCtx* ctx, uint8_t* buf, int len) if (len + ctx->file.wBufOffset >= cap) { int32_t nw = cap - ctx->file.wBufOffset; memcpy(ctx->file.wBuf + ctx->file.wBufOffset, buf, nw); - (void)taosWriteFile(ctx->file.pFile, ctx->file.wBuf, cap); + TAOS_UNUSED(taosWriteFile(ctx->file.pFile, ctx->file.wBuf, cap)); memset(ctx->file.wBuf, 0, cap); ctx->file.wBufOffset = 0; @@ -58,7 +60,7 @@ static FORCE_INLINE int idxFileCtxDoWrite(IFileCtx* ctx, uint8_t* buf, int len) nw = (len / cap) * cap; if (nw != 0) { - (void)taosWriteFile(ctx->file.pFile, buf, nw); + TAOS_UNUSED(taosWriteFile(ctx->file.pFile, buf, nw)); } len -= nw; @@ -115,7 +117,7 @@ static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t of SDataBlock* blk = taosLRUCacheValue(ctx->lru, h); nread = TMIN(blkLeft, len); memcpy(buf + total, blk->buf + blkOffset, nread); - (void)taosLRUCacheRelease(ctx->lru, h, false); + TAOS_UNUSED(taosLRUCacheRelease(ctx->lru, h, false)); } else { int32_t left = ctx->file.size - offset; if (left < kBlockSize) { @@ -132,6 +134,9 @@ static int idxFileCtxDoReadFrom(IFileCtx* ctx, uint8_t* buf, int len, int32_t of int32_t cacheMemSize = sizeof(SDataBlock) + kBlockSize; SDataBlock* blk = taosMemoryCalloc(1, cacheMemSize); + if (blk == NULL) { + return terrno; + } blk->blockId = blkId; blk->nread = taosPReadFile(ctx->file.pFile, blk->buf, kBlockSize, blkId * kBlockSize); if (blk->nread < kBlockSize && blk->nread < len) { @@ -166,7 +171,7 @@ static FORCE_INLINE int idxFileCtxGetSize(IFileCtx* ctx) { return ctx->offset; } else { int64_t file_size = 0; - (void)taosStatFile(ctx->file.buf, &file_size, NULL, NULL); + TAOS_UNUSED(taosStatFile(ctx->file.buf, &file_size, NULL, NULL)); return (int)file_size; } } @@ -209,6 +214,10 @@ IFileCtx* idxFileCtxCreate(WriterType type, const char* path, bool readOnly, int ctx->file.wBufOffset = 0; ctx->file.wBufCap = kBlockSize * 4; ctx->file.wBuf = taosMemoryCalloc(1, ctx->file.wBufCap); + if (ctx->file.wBuf == NULL) { + indexError("failed to allocate memory for write buffer"); + goto END; + } } else { ctx->file.pFile = taosOpenFile(path, TD_FILE_READ); code = taosFStatFile(ctx->file.pFile, &ctx->file.size, NULL); @@ -226,6 +235,11 @@ IFileCtx* idxFileCtxCreate(WriterType type, const char* path, bool readOnly, int } } else if (ctx->type == TMEMORY) { ctx->mem.buf = taosMemoryCalloc(1, sizeof(char) * capacity); + if (ctx->mem.buf == NULL) { + indexError("failed to allocate memory for memory buffer"); + goto END; + } + ctx->mem.cap = capacity; } @@ -254,16 +268,16 @@ void idxFileCtxDestroy(IFileCtx* ctx, bool remove) { int32_t nw = taosWriteFile(ctx->file.pFile, ctx->file.wBuf, ctx->file.wBufOffset); ctx->file.wBufOffset = 0; } - (void)(ctx->flush(ctx)); + TAOS_UNUSED(ctx->flush(ctx)); taosMemoryFreeClear(ctx->file.wBuf); - (void)taosCloseFile(&ctx->file.pFile); + TAOS_UNUSED(taosCloseFile(&ctx->file.pFile)); if (ctx->file.readOnly) { #ifdef USE_MMAP munmap(ctx->file.ptr, ctx->file.size); #endif } if (remove) { - (void)unlink(ctx->file.buf); + TAOS_UNUSED(unlink(ctx->file.buf)); } } taosMemoryFree(ctx); @@ -279,7 +293,7 @@ IdxFstFile* idxFileCreate(void* wrt) { return cw; } void idxFileDestroy(IdxFstFile* cw) { - (void)idxFileFlush(cw); + TAOS_UNUSED(idxFileFlush(cw)); taosMemoryFree(cw); } @@ -317,17 +331,21 @@ uint32_t idxFileMaskedCheckSum(IdxFstFile* write) { int idxFileFlush(IdxFstFile* write) { IFileCtx* ctx = write->wrt; - (void)(ctx->flush(ctx)); + TAOS_UNUSED(ctx->flush(ctx)); return 1; } void idxFilePackUintIn(IdxFstFile* writer, uint64_t n, uint8_t nBytes) { uint8_t* buf = taosMemoryCalloc(8, sizeof(uint8_t)); + if (buf == NULL) { + indexError("failed to allocate memory for packing uint"); + return; + } for (uint8_t i = 0; i < nBytes; i++) { buf[i] = (uint8_t)n; n = n >> 8; } - (void)idxFileWrite(writer, buf, nBytes); + TAOS_UNUSED(idxFileWrite(writer, buf, nBytes)); taosMemoryFree(buf); return; } diff --git a/source/libs/index/src/indexFstNode.c b/source/libs/index/src/indexFstNode.c index 245f5cf5fc..1f2b4cbddb 100644 --- a/source/libs/index/src/indexFstNode.c +++ b/source/libs/index/src/indexFstNode.c @@ -76,14 +76,14 @@ int32_t fstBuilderNodeCloneFrom(FstBuilderNode* dst, FstBuilderNode* src) { size_t sz = taosArrayGetSize(src->trans); dst->trans = taosArrayInit(sz, sizeof(FstTransition)); if (dst->trans == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (size_t i = 0; i < sz; i++) { FstTransition* trn = taosArrayGet(src->trans, i); if (taosArrayPush(dst->trans, trn) == NULL) { taosArrayDestroy(dst->trans); dst->trans = NULL; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } return 0; diff --git a/source/libs/index/src/indexFstRegister.c b/source/libs/index/src/indexFstRegister.c index cc069c5d0f..ce34bb50d0 100644 --- a/source/libs/index/src/indexFstRegister.c +++ b/source/libs/index/src/indexFstRegister.c @@ -128,7 +128,7 @@ FstRegistryEntry* fstRegistryGetEntry(FstRegistry* registry, FstBuilderNode* bNo entry->addr = cell->addr; return entry; } else { - (void)fstBuilderNodeCloneFrom(cell->node, bNode); + TAOS_UNUSED(fstBuilderNodeCloneFrom(cell->node, bNode)); entry->state = NOTFOUND; entry->cell = cell; // copy or not } @@ -148,7 +148,7 @@ FstRegistryEntry* fstRegistryGetEntry(FstRegistry* registry, FstBuilderNode* bNo return entry; } // clone from bNode, refactor later - (void)fstBuilderNodeCloneFrom(cell2->node, bNode); + TAOS_UNUSED(fstBuilderNodeCloneFrom(cell2->node, bNode)); fstRegistryCellSwap(registry->table, start, start + 1); FstRegistryCell* cCell = taosArrayGet(registry->table, start); @@ -169,7 +169,7 @@ FstRegistryEntry* fstRegistryGetEntry(FstRegistry* registry, FstBuilderNode* bNo uint64_t last = end - 1; FstRegistryCell* cell = (FstRegistryCell*)taosArrayGet(registry->table, last); // clone from bNode, refactor later - (void)fstBuilderNodeCloneFrom(cell->node, bNode); + TAOS_UNUSED(fstBuilderNodeCloneFrom(cell->node, bNode)); fstRegistryCellPromote(registry->table, last, start); FstRegistryCell* cCell = taosArrayGet(registry->table, start); diff --git a/source/libs/index/src/indexFstUtil.c b/source/libs/index/src/indexFstUtil.c index 92cece3890..8c1095fb1d 100644 --- a/source/libs/index/src/indexFstUtil.c +++ b/source/libs/index/src/indexFstUtil.c @@ -80,6 +80,10 @@ FstSlice fstSliceCreate(uint8_t* data, uint64_t len) { str->ref = 1; str->len = len; str->data = taosMemoryMalloc(len * sizeof(uint8_t)); + if (str == NULL || str->data == NULL) { + taosMemoryFree(str); + return (FstSlice){.str = NULL, .start = 0, .end = 0}; + } if (data != NULL && str->data != NULL) { memcpy(str->data, data, len); @@ -91,7 +95,7 @@ FstSlice fstSliceCreate(uint8_t* data, uint64_t len) { // just shallow copy FstSlice fstSliceCopy(FstSlice* s, int32_t start, int32_t end) { FstString* str = s->str; - (void)atomic_add_fetch_32(&str->ref, 1); + TAOS_UNUSED(atomic_add_fetch_32(&str->ref, 1)); FstSlice t = {.str = str, .start = start + s->start, .end = end + s->start}; return t; diff --git a/source/libs/index/src/indexTfile.c b/source/libs/index/src/indexTfile.c index eb00cc7990..d92fec104b 100644 --- a/source/libs/index/src/indexTfile.c +++ b/source/libs/index/src/indexTfile.c @@ -280,7 +280,7 @@ static int32_t tfSearchPrefix(void* reader, SIndexTerm* tem, SIdxTRslt* tr) { SArray* offsets = taosArrayInit(16, sizeof(uint64_t)); if (offsets == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } FAutoCtx* ctx = automCtxCreate((void*)p, AUTOMATION_PREFIX); @@ -374,7 +374,7 @@ static int32_t tfSearchCompareFunc(void* reader, SIndexTerm* tem, SIdxTRslt* tr, goto _return; } if (MATCH == cond) { - (void)tfileReaderLoadTableIds((TFileReader*)reader, rt->out.out, tr->total); + TAOS_UNUSED(tfileReaderLoadTableIds((TFileReader*)reader, rt->out.out, tr->total)); } else if (CONTINUE == cond) { } else if (BREAK == cond) { swsResultDestroy(rt); @@ -528,7 +528,7 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTRslt } } if (MATCH == cond) { - (void)tfileReaderLoadTableIds((TFileReader*)reader, rt->out.out, tr->total); + TAOS_UNUSED(tfileReaderLoadTableIds((TFileReader*)reader, rt->out.out, tr->total)); } else if (CONTINUE == cond) { } else if (BREAK == cond) { swsResultDestroy(rt); @@ -639,7 +639,7 @@ int32_t tfileWriterPut(TFileWriter* tw, void* data, bool order) { if (fn == NULL) { return terrno; } - (void)taosArraySortPWithExt((SArray*)(data), tfileValueCompare, &fn); + TAOS_UNUSED(taosArraySortPWithExt((SArray*)(data), tfileValueCompare, &fn)); } int32_t sz = taosArrayGetSize((SArray*)data); @@ -654,7 +654,7 @@ int32_t tfileWriterPut(TFileWriter* tw, void* data, bool order) { if (tbsz == 0) continue; fstOffset += TF_TABLE_TATOAL_SIZE(tbsz); } - (void)tfileWriteFstOffset(tw, fstOffset); + TAOS_UNUSED(tfileWriteFstOffset(tw, fstOffset)); int32_t cap = 4 * 1024; char* buf = taosMemoryCalloc(1, cap); @@ -675,14 +675,14 @@ int32_t tfileWriterPut(TFileWriter* tw, void* data, bool order) { char* t = (char*)taosMemoryRealloc(buf, cap); if (t == NULL) { taosMemoryFree(buf); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } buf = t; } char* p = buf; tfileSerialTableIdsToBuf(p, v->tableId); - (void)(tw->ctx->write(tw->ctx, buf, ttsz)); + TAOS_UNUSED((tw->ctx->write(tw->ctx, buf, ttsz))); v->offset = tw->offset; tw->offset += ttsz; memset(buf, 0, cap); @@ -710,7 +710,7 @@ int32_t tfileWriterPut(TFileWriter* tw, void* data, bool order) { } } fstBuilderDestroy(tw->fb); - (void)tfileWriteFooter(tw); + TAOS_UNUSED(tfileWriteFooter(tw)); return 0; } void tfileWriterClose(TFileWriter* tw) { @@ -739,7 +739,7 @@ IndexTFile* idxTFileCreate(SIndex* idx, const char* path) { tfileCacheDestroy(cache); return NULL; } - (void)taosThreadMutexInit(&tfile->mtx, NULL); + TAOS_UNUSED(taosThreadMutexInit(&tfile->mtx, NULL)); tfile->cache = cache; return tfile; } @@ -747,7 +747,7 @@ void idxTFileDestroy(IndexTFile* tfile) { if (tfile == NULL) { return; } - (void)taosThreadMutexDestroy(&tfile->mtx); + TAOS_UNUSED(taosThreadMutexDestroy(&tfile->mtx)); tfileCacheDestroy(tfile->cache); taosMemoryFree(tfile); } @@ -764,9 +764,9 @@ int idxTFileSearch(void* tfile, SIndexTermQuery* query, SIdxTRslt* result) { SIndexTerm* term = query->term; ICacheKey key = {.suid = term->suid, .colType = term->colType, .colName = term->colName, .nColName = term->nColName}; - (void)taosThreadMutexLock(&pTfile->mtx); + TAOS_UNUSED(taosThreadMutexLock(&pTfile->mtx)); TFileReader* reader = tfileCacheGet(pTfile->cache, &key); - (void)taosThreadMutexUnlock(&pTfile->mtx); + TAOS_UNUSED(taosThreadMutexUnlock(&pTfile->mtx)); if (reader == NULL) { return 0; } @@ -799,6 +799,10 @@ static bool tfileIteratorNext(Iterate* iiter) { int32_t sz = 0; char* ch = (char*)fstSliceData(&rt->data, &sz); colVal = taosMemoryCalloc(1, sz + 1); + if (colVal == NULL) { + return false; + } + memcpy(colVal, ch, sz); offset = (uint64_t)(rt->out.out); @@ -835,6 +839,10 @@ Iterate* tfileIteratorCreate(TFileReader* reader) { } Iterate* iter = taosMemoryCalloc(1, sizeof(Iterate)); + if (iter == NULL) { + return NULL; + } + iter->iter = tfileFstIteratorCreate(reader); if (iter->iter == NULL) { taosMemoryFree(iter); @@ -843,6 +851,11 @@ Iterate* tfileIteratorCreate(TFileReader* reader) { iter->next = tfileIteratorNext; iter->getValue = tifileIterateGetValue; iter->val.val = taosArrayInit(1, sizeof(uint64_t)); + if (iter->val.val == NULL) { + tfileIteratorDestroy(iter); + return NULL; + } + iter->val.colVal = NULL; return iter; } @@ -870,9 +883,9 @@ TFileReader* tfileGetReaderByCol(IndexTFile* tf, uint64_t suid, char* colName) { TFileReader* rd = NULL; ICacheKey key = {.suid = suid, .colType = TSDB_DATA_TYPE_BINARY, .colName = colName, .nColName = strlen(colName)}; - (void)taosThreadMutexLock(&tf->mtx); + TAOS_UNUSED(taosThreadMutexLock(&tf->mtx)); rd = tfileCacheGet(tf->cache, &key); - (void)taosThreadMutexUnlock(&tf->mtx); + TAOS_UNUSED(taosThreadMutexUnlock(&tf->mtx)); return rd; } @@ -915,7 +928,7 @@ int32_t tfileValuePush(TFileValue* tf, uint64_t val) { return TSDB_CODE_INVALID_PARA; } if (taosArrayPush(tf->tableId, &val) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return 0; } @@ -978,7 +991,7 @@ static int tfileWriteData(TFileWriter* write, TFileValue* tval) { static int tfileWriteFooter(TFileWriter* write) { char buf[sizeof(FILE_MAGIC_NUMBER) + 1] = {0}; void* pBuf = (void*)buf; - (void)taosEncodeFixedU64((void**)(void*)&pBuf, FILE_MAGIC_NUMBER); + TAOS_UNUSED(taosEncodeFixedU64((void**)(void*)&pBuf, FILE_MAGIC_NUMBER)); int nwrite = write->ctx->write(write->ctx, (uint8_t*)buf, (int32_t)strlen(buf)); indexInfo("tfile write footer size: %d", write->ctx->size(write->ctx)); @@ -1052,7 +1065,7 @@ static int32_t tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArr int32_t left = block + sizeof(block) - p; if (left >= sizeof(uint64_t)) { if (taosArrayPush(result, (uint64_t*)p) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } p += sizeof(uint64_t); } else { @@ -1065,7 +1078,7 @@ static int32_t tfileReaderLoadTableIds(TFileReader* reader, int32_t offset, SArr memcpy(buf + left, block, sizeof(uint64_t) - left); if (taosArrayPush(result, (uint64_t*)buf) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } p = block + sizeof(uint64_t) - left; } @@ -1088,7 +1101,7 @@ static int tfileReaderVerify(TFileReader* reader) { return TSDB_CODE_INDEX_INVALID_FILE; } - (void)taosDecodeFixedU64(buf, &tMagicNumber); + TAOS_UNUSED(taosDecodeFixedU64(buf, &tMagicNumber)); return tMagicNumber == FILE_MAGIC_NUMBER ? 0 : TSDB_CODE_INDEX_INVALID_FILE; } @@ -1118,7 +1131,7 @@ static int32_t tfileGetFileList(const char* path, SArray** ppResult) { int64_t version; SArray* files = taosArrayInit(4, sizeof(void*)); if (files == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } TdDirPtr pDir = taosOpenDir(path); @@ -1140,18 +1153,18 @@ static int32_t tfileGetFileList(const char* path, SArray** ppResult) { sprintf(buf, "%s/%s", path, file); if (taosArrayPush(files, &buf) == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); + TAOS_CHECK_GOTO(terrno, NULL, _exception); } } - (void)taosCloseDir(&pDir); + TAOS_UNUSED(taosCloseDir(&pDir)); taosArraySort(files, tfileCompare); - (void)tfileRmExpireFile(files); + TAOS_UNUSED(tfileRmExpireFile(files)); *ppResult = files; return 0; _exception: - (void)taosCloseDir(&pDir); + TAOS_UNUSED(taosCloseDir(&pDir)); if (files != NULL) { taosArrayDestroyEx(files, tfileDestroyFileName); taosArrayDestroy(files); @@ -1181,12 +1194,12 @@ static int tfileParseFileName(const char* filename, uint64_t* suid, char* col, i } // tfile name suid-colId-version.tindex static void tfileGenFileName(char* filename, uint64_t suid, const char* col, int64_t version) { - (void)sprintf(filename, "%" PRIu64 "-%s-%" PRId64 ".tindex", suid, col, version); + TAOS_UNUSED(sprintf(filename, "%" PRIu64 "-%s-%" PRId64 ".tindex", suid, col, version)); return; } static void FORCE_INLINE tfileGenFileFullName(char* fullname, const char* path, uint64_t suid, const char* col, int64_t version) { char filename[128] = {0}; tfileGenFileName(filename, suid, col, version); - (void)sprintf(fullname, "%s/%s", path, filename); + TAOS_UNUSED(sprintf(fullname, "%s/%s", path, filename)); } diff --git a/source/libs/index/src/indexUtil.c b/source/libs/index/src/indexUtil.c index aca1ec37fe..12bff36553 100644 --- a/source/libs/index/src/indexUtil.c +++ b/source/libs/index/src/indexUtil.c @@ -69,7 +69,7 @@ int32_t iIntersection(SArray *in, SArray *out) { } if (has == true) { if (taosArrayPush(out, &tgt) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } } @@ -90,6 +90,10 @@ int32_t iUnion(SArray *in, SArray *out) { } MergeIndex *mi = taosMemoryCalloc(sz, sizeof(MergeIndex)); + if (mi == NULL) { + return terrno; + } + for (int i = 0; i < sz; i++) { SArray *t = taosArrayGetP(in, i); mi[i].len = (int32_t)taosArrayGetSize(t); @@ -119,7 +123,7 @@ int32_t iUnion(SArray *in, SArray *out) { } } if (taosArrayPush(out, &mVal) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } } else { @@ -220,17 +224,17 @@ int32_t idxTRsltMergeTo(SIdxTRslt *tr, SArray *result) { } else { SArray *arrs = taosArrayInit(2, sizeof(void *)); if (arrs == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (taosArrayPush(arrs, &tr->total) == NULL) { taosArrayDestroy(arrs); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (taosArrayPush(arrs, &tr->add) == NULL) { taosArrayDestroy(arrs); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } code = iUnion(arrs, result); taosArrayDestroy(arrs); diff --git a/source/libs/monitor/src/monFramework.c b/source/libs/monitor/src/monFramework.c index 76473ccbb1..1e358ac8d4 100644 --- a/source/libs/monitor/src/monFramework.c +++ b/source/libs/monitor/src/monFramework.c @@ -100,7 +100,9 @@ extern char* tsMonFwUri; #define VNODE_ROLE "taosd_vnodes_info:role" void monInitMonitorFW(){ - (void)taos_collector_registry_default_init(); + if (taos_collector_registry_default_init() != 0) { + uError("failed to init default collector registry"); + } tsMonitor.metrics = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); taos_gauge_t *gauge = NULL; @@ -115,7 +117,9 @@ void monInitMonitorFW(){ for(int32_t i = 0; i < 25; i++){ gauge= taos_gauge_new(dnodes_gauges[i], "", dnodes_label_count, dnodes_sample_labels); if(taos_collector_registry_register_metric(gauge) == 1){ - (void)taos_counter_destroy(gauge); + if (taos_counter_destroy(gauge) != 0) { + uError("failed to delete metric %s", dnodes_gauges[i]); + } } if (taosHashPut(tsMonitor.metrics, dnodes_gauges[i], strlen(dnodes_gauges[i]), &gauge, sizeof(taos_gauge_t *)) != 0) { @@ -129,7 +133,9 @@ void monInitMonitorFW(){ for(int32_t i = 0; i < 3; i++){ gauge= taos_gauge_new(dnodes_data_gauges[i], "", dnodes_data_label_count, dnodes_data_sample_labels); if(taos_collector_registry_register_metric(gauge) == 1){ - (void)taos_counter_destroy(gauge); + if (taos_counter_destroy(gauge) != 0) { + uError("failed to delete metric %s", dnodes_data_gauges[i]); + } } if (taosHashPut(tsMonitor.metrics, dnodes_data_gauges[i], strlen(dnodes_data_gauges[i]), &gauge, sizeof(taos_gauge_t *)) != 0) { @@ -143,7 +149,9 @@ void monInitMonitorFW(){ for(int32_t i = 0; i < 3; i++){ gauge= taos_gauge_new(dnodes_log_gauges[i], "", dnodes_log_label_count, dnodes_log_sample_labels); if(taos_collector_registry_register_metric(gauge) == 1){ - (void)taos_counter_destroy(gauge); + if (taos_counter_destroy(gauge) != 0) { + uError("failed to delete metric %s", dnodes_log_gauges[i]); + } } if (taosHashPut(tsMonitor.metrics, dnodes_log_gauges[i], strlen(dnodes_log_gauges[i]), &gauge, sizeof(taos_gauge_t *)) != 0) { @@ -154,7 +162,9 @@ void monInitMonitorFW(){ void monCleanupMonitorFW(){ taosHashCleanup(tsMonitor.metrics); - (void)taos_collector_registry_destroy(TAOS_COLLECTOR_REGISTRY_DEFAULT); + if (taos_collector_registry_destroy(TAOS_COLLECTOR_REGISTRY_DEFAULT) != 0) { + uError("failed to destroy default collector registry"); + } TAOS_COLLECTOR_REGISTRY_DEFAULT = NULL; } @@ -174,7 +184,9 @@ void monGenClusterInfoTable(SMonInfo *pMonitor){ uError("failed to delete metric %s", metric_names[i]); } - (void)taosHashRemove(tsMonitor.metrics, metric_names[i], strlen(metric_names[i])); + if (taosHashRemove(tsMonitor.metrics, metric_names[i], strlen(metric_names[i])) != 0) { + uError("failed to remove metric %s", metric_names[i]); + } } if(pBasicInfo->cluster_id == 0) { @@ -191,7 +203,9 @@ void monGenClusterInfoTable(SMonInfo *pMonitor){ for(int32_t i = 0; i < 18; i++){ gauge= taos_gauge_new(metric_names[i], "", label_count, sample_labels1); if(taos_collector_registry_register_metric(gauge) == 1){ - (void)taos_counter_destroy(gauge); + if (taos_counter_destroy(gauge) != 0) { + uError("failed to delete metric %s", metric_names[i]); + } } if (taosHashPut(tsMonitor.metrics, metric_names[i], strlen(metric_names[i]), &gauge, sizeof(taos_gauge_t *)) != 0) { uError("failed to add cluster gauge at%d:%s", i, metric_names[i]); @@ -317,11 +331,15 @@ void monGenVgroupInfoTable(SMonInfo *pMonitor){ const char *vgroup_sample_labels[] = {"cluster_id", "vgroup_id", "database_name"}; taos_gauge_t *tableNumGauge = taos_gauge_new(TABLES_NUM, "", vgroup_label_count, vgroup_sample_labels); if(taos_collector_registry_register_metric(tableNumGauge) == 1){ - (void)taos_counter_destroy(tableNumGauge); + if (taos_counter_destroy(tableNumGauge) != 0) { + uError("failed to delete metric " TABLES_NUM); + } } taos_gauge_t *statusGauge = taos_gauge_new(STATUS, "", vgroup_label_count, vgroup_sample_labels); if(taos_collector_registry_register_metric(statusGauge) == 1){ - (void)taos_counter_destroy(statusGauge); + if (taos_counter_destroy(statusGauge) != 0) { + uError("failed to delete metric " STATUS); + } } char cluster_id[TSDB_CLUSTER_ID_LEN] = {0}; @@ -530,7 +548,9 @@ void monGenDnodeStatusInfoTable(SMonInfo *pMonitor){ gauge= taos_gauge_new(DNODE_STATUS, "", dnodes_label_count, dnodes_sample_labels); if(taos_collector_registry_register_metric(gauge) == 1){ - (void)taos_counter_destroy(gauge); + if (taos_counter_destroy(gauge) != 0) { + uError("failed to delete metric " DNODE_STATUS); + } } char cluster_id[TSDB_CLUSTER_ID_LEN]; @@ -633,7 +653,9 @@ void monGenMnodeRoleTable(SMonInfo *pMonitor){ uError("failed to delete metric %s", mnodes_role_gauges[i]); } - (void)taosHashRemove(tsMonitor.metrics, mnodes_role_gauges[i], strlen(mnodes_role_gauges[i])); + if (taosHashRemove(tsMonitor.metrics, mnodes_role_gauges[i], strlen(mnodes_role_gauges[i])) != 0) { + uError("failed to remove metric %s", mnodes_role_gauges[i]); + } } SMonClusterInfo *pInfo = &pMonitor->mmInfo.cluster; @@ -647,7 +669,9 @@ void monGenMnodeRoleTable(SMonInfo *pMonitor){ for(int32_t i = 0; i < 1; i++){ gauge= taos_gauge_new(mnodes_role_gauges[i], "", mnodes_role_label_count, mnodes_role_sample_labels); if(taos_collector_registry_register_metric(gauge) == 1){ - (void)taos_counter_destroy(gauge); + if (taos_counter_destroy(gauge) != 0) { + uError("failed to destroy gauge"); + } } if (taosHashPut(tsMonitor.metrics, mnodes_role_gauges[i], strlen(mnodes_role_gauges[i]), &gauge, sizeof(taos_gauge_t *)) != 0) { @@ -702,7 +726,9 @@ void monGenVnodeRoleTable(SMonInfo *pMonitor){ uError("failed to delete metric %s", vnodes_role_gauges[i]); } - (void)taosHashRemove(tsMonitor.metrics, vnodes_role_gauges[i], strlen(vnodes_role_gauges[i])); + if (taosHashRemove(tsMonitor.metrics, vnodes_role_gauges[i], strlen(vnodes_role_gauges[i])) != 0) { + uError("failed to remove metric %s", vnodes_role_gauges[i]); + } } SMonVgroupInfo *pInfo = &pMonitor->mmInfo.vgroup; @@ -716,7 +742,9 @@ void monGenVnodeRoleTable(SMonInfo *pMonitor){ for(int32_t i = 0; i < 1; i++){ gauge= taos_gauge_new(vnodes_role_gauges[i], "", vnodes_role_label_count, vnodes_role_sample_labels); if(taos_collector_registry_register_metric(gauge) == 1){ - (void)taos_counter_destroy(gauge); + if (taos_counter_destroy(gauge) != 0) { + uError("failed to destroy gauge"); + } } if (taosHashPut(tsMonitor.metrics, vnodes_role_gauges[i], strlen(vnodes_role_gauges[i]), &gauge, sizeof(taos_gauge_t *)) != 0) { @@ -774,7 +802,9 @@ void monSendPromReport() { tmp) != 0) { uError("failed to send monitor msg"); } else { - (void)taos_collector_registry_clear_batch(TAOS_COLLECTOR_REGISTRY_DEFAULT); + if (taos_collector_registry_clear_batch(TAOS_COLLECTOR_REGISTRY_DEFAULT) != 0) { + uError("failed to clear batch"); + } } taosMemoryFreeClear(pCont); } diff --git a/source/libs/monitor/src/monMain.c b/source/libs/monitor/src/monMain.c index 4808ae0fdf..744177b7a1 100644 --- a/source/libs/monitor/src/monMain.c +++ b/source/libs/monitor/src/monMain.c @@ -118,7 +118,7 @@ void monSetBmInfo(SMonBmInfo *pInfo) { int32_t monInit(const SMonCfg *pCfg) { tsMonitor.logs = taosArrayInit(16, sizeof(SMonLogItem)); if (tsMonitor.logs == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } tsMonitor.cfg = *pCfg; @@ -145,7 +145,9 @@ void monInitVnode() { counter = taos_counter_new(VNODE_METRIC_SQL_COUNT, "counter for insert sql", label_count, sample_labels); uDebug("new metric:%p", counter); if (taos_collector_registry_register_metric(counter) == 1) { - (void)taos_counter_destroy(counter); + if (taos_counter_destroy(counter) != 0) { + uError("failed to destroy metric:%p", counter); + } uError("failed to register metric:%p", counter); } else { tsInsertCounter = counter; @@ -226,14 +228,17 @@ static void monGenBasicJson(SMonInfo *pMonitor) { SJson *pJson = pMonitor->pJson; char buf[40] = {0}; - (void)taosFormatUtcTime(buf, sizeof(buf), pMonitor->curTime, TSDB_TIME_PRECISION_MILLI); + if (taosFormatUtcTime(buf, sizeof(buf), pMonitor->curTime, TSDB_TIME_PRECISION_MILLI) != 0) { + uError("failed to format time"); + return; + } - (void)tjsonAddStringToObject(pJson, "ts", buf); - (void)tjsonAddDoubleToObject(pJson, "dnode_id", pInfo->dnode_id); - (void)tjsonAddStringToObject(pJson, "dnode_ep", pInfo->dnode_ep); + if (tjsonAddStringToObject(pJson, "ts", buf) != 0) uError("failed to add ts"); + if (tjsonAddDoubleToObject(pJson, "dnode_id", pInfo->dnode_id) != 0) uError("failed to add dnode_id"); + if (tjsonAddStringToObject(pJson, "dnode_ep", pInfo->dnode_ep) != 0) uError("failed to add dnode_ep"); snprintf(buf, sizeof(buf), "%" PRId64, pInfo->cluster_id); - (void)tjsonAddStringToObject(pJson, "cluster_id", buf); - (void)tjsonAddDoubleToObject(pJson, "protocol", pInfo->protocol); + if (tjsonAddStringToObject(pJson, "cluster_id", buf) != 0) uError("failed to add cluster_id"); + if (tjsonAddDoubleToObject(pJson, "protocol", pInfo->protocol) != 0) uError("failed to add protocol"); } static void monGenBasicJsonBasic(SMonInfo *pMonitor) { @@ -244,12 +249,12 @@ static void monGenBasicJsonBasic(SMonInfo *pMonitor) { char buf[40] = {0}; sprintf(buf, "%" PRId64, taosGetTimestamp(TSDB_TIME_PRECISION_MILLI)); - (void)tjsonAddStringToObject(pJson, "ts", buf); - (void)tjsonAddDoubleToObject(pJson, "dnode_id", pInfo->dnode_id); - (void)tjsonAddStringToObject(pJson, "dnode_ep", pInfo->dnode_ep); + if (tjsonAddStringToObject(pJson, "ts", buf) != 0) uError("failed to add ts"); + if (tjsonAddDoubleToObject(pJson, "dnode_id", pInfo->dnode_id) != 0) uError("failed to add dnode_id"); + if (tjsonAddStringToObject(pJson, "dnode_ep", pInfo->dnode_ep) != 0) uError("failed to add dnode_ep"); snprintf(buf, sizeof(buf), "%" PRId64, pInfo->cluster_id); - (void)tjsonAddStringToObject(pJson, "cluster_id", buf); - (void)tjsonAddDoubleToObject(pJson, "protocol", pInfo->protocol); + if (tjsonAddStringToObject(pJson, "cluster_id", buf) != 0) uError("failed to add cluster_id"); + if (tjsonAddDoubleToObject(pJson, "protocol", pInfo->protocol) != 0) uError("failed to add protocol"); } static void monGenClusterJson(SMonInfo *pMonitor) { @@ -263,21 +268,24 @@ static void monGenClusterJson(SMonInfo *pMonitor) { return; } - (void)tjsonAddStringToObject(pJson, "first_ep", pInfo->first_ep); - (void)tjsonAddDoubleToObject(pJson, "first_ep_dnode_id", pInfo->first_ep_dnode_id); - (void)tjsonAddStringToObject(pJson, "version", pInfo->version); - (void)tjsonAddDoubleToObject(pJson, "master_uptime", pInfo->master_uptime); - (void)tjsonAddDoubleToObject(pJson, "monitor_interval", pInfo->monitor_interval); - (void)tjsonAddDoubleToObject(pJson, "dbs_total", pInfo->dbs_total); - (void)tjsonAddDoubleToObject(pJson, "tbs_total", pInfo->tbs_total); - (void)tjsonAddDoubleToObject(pJson, "stbs_total", pInfo->stbs_total); - (void)tjsonAddDoubleToObject(pJson, "vgroups_total", pInfo->vgroups_total); - (void)tjsonAddDoubleToObject(pJson, "vgroups_alive", pInfo->vgroups_alive); - (void)tjsonAddDoubleToObject(pJson, "vnodes_total", pInfo->vnodes_total); - (void)tjsonAddDoubleToObject(pJson, "vnodes_alive", pInfo->vnodes_alive); - (void)tjsonAddDoubleToObject(pJson, "connections_total", pInfo->connections_total); - (void)tjsonAddDoubleToObject(pJson, "topics_total", pInfo->topics_toal); - (void)tjsonAddDoubleToObject(pJson, "streams_total", pInfo->streams_total); + if (tjsonAddStringToObject(pJson, "first_ep", pInfo->first_ep) != 0) uError("failed to add first_ep"); + if (tjsonAddDoubleToObject(pJson, "first_ep_dnode_id", pInfo->first_ep_dnode_id) != 0) + uError("failed to add first_ep_dnode_id"); + if (tjsonAddStringToObject(pJson, "version", pInfo->version) != 0) uError("failed to add version"); + if (tjsonAddDoubleToObject(pJson, "master_uptime", pInfo->master_uptime) != 0) uError("failed to add master_uptime"); + if (tjsonAddDoubleToObject(pJson, "monitor_interval", pInfo->monitor_interval) != 0) + uError("failed to add monitor_interval"); + if (tjsonAddDoubleToObject(pJson, "dbs_total", pInfo->dbs_total) != 0) uError("failed to add dbs_total"); + if (tjsonAddDoubleToObject(pJson, "tbs_total", pInfo->tbs_total) != 0) uError("failed to add tbs_total"); + if (tjsonAddDoubleToObject(pJson, "stbs_total", pInfo->stbs_total) != 0) uError("failed to add stbs_total"); + if (tjsonAddDoubleToObject(pJson, "vgroups_total", pInfo->vgroups_total) != 0) uError("failed to add vgroups_total"); + if (tjsonAddDoubleToObject(pJson, "vgroups_alive", pInfo->vgroups_alive) != 0) uError("failed to add vgroups_alive"); + if (tjsonAddDoubleToObject(pJson, "vnodes_total", pInfo->vnodes_total) != 0) uError("failed to add vnodes_total"); + if (tjsonAddDoubleToObject(pJson, "vnodes_alive", pInfo->vnodes_alive) != 0) uError("failed to add vnodes_alive"); + if (tjsonAddDoubleToObject(pJson, "connections_total", pInfo->connections_total) != 0) + uError("failed to add connections_total"); + if (tjsonAddDoubleToObject(pJson, "topics_total", pInfo->topics_toal) != 0) uError("failed to add topics_total"); + if (tjsonAddDoubleToObject(pJson, "streams_total", pInfo->streams_total) != 0) uError("failed to add streams_total"); SJson *pDnodesJson = tjsonAddArrayToObject(pJson, "dnodes"); if (pDnodesJson == NULL) return; @@ -287,9 +295,9 @@ static void monGenClusterJson(SMonInfo *pMonitor) { if (pDnodeJson == NULL) continue; SMonDnodeDesc *pDnodeDesc = taosArrayGet(pInfo->dnodes, i); - (void)tjsonAddDoubleToObject(pDnodeJson, "dnode_id", pDnodeDesc->dnode_id); - (void)tjsonAddStringToObject(pDnodeJson, "dnode_ep", pDnodeDesc->dnode_ep); - (void)tjsonAddStringToObject(pDnodeJson, "status", pDnodeDesc->status); + if (tjsonAddDoubleToObject(pDnodeJson, "dnode_id", pDnodeDesc->dnode_id) != 0) uError("failed to add dnode_id"); + if (tjsonAddStringToObject(pDnodeJson, "dnode_ep", pDnodeDesc->dnode_ep) != 0) uError("failed to add dnode_ep"); + if (tjsonAddStringToObject(pDnodeJson, "status", pDnodeDesc->status) != 0) uError("failed to add status"); if (tjsonAddItemToArray(pDnodesJson, pDnodeJson) != 0) tjsonDelete(pDnodeJson); } @@ -302,9 +310,9 @@ static void monGenClusterJson(SMonInfo *pMonitor) { if (pMnodeJson == NULL) continue; SMonMnodeDesc *pMnodeDesc = taosArrayGet(pInfo->mnodes, i); - (void)tjsonAddDoubleToObject(pMnodeJson, "mnode_id", pMnodeDesc->mnode_id); - (void)tjsonAddStringToObject(pMnodeJson, "mnode_ep", pMnodeDesc->mnode_ep); - (void)tjsonAddStringToObject(pMnodeJson, "role", pMnodeDesc->role); + if (tjsonAddDoubleToObject(pMnodeJson, "mnode_id", pMnodeDesc->mnode_id) != 0) uError("failed to add mnode_id"); + if (tjsonAddStringToObject(pMnodeJson, "mnode_ep", pMnodeDesc->mnode_ep) != 0) uError("failed to add mnode_ep"); + if (tjsonAddStringToObject(pMnodeJson, "role", pMnodeDesc->role) != 0) uError("failed to add role"); if (tjsonAddItemToArray(pMnodesJson, pMnodeJson) != 0) tjsonDelete(pMnodeJson); } @@ -314,11 +322,11 @@ static void monGenClusterJsonBasic(SMonInfo *pMonitor) { SMonClusterInfo *pInfo = &pMonitor->mmInfo.cluster; if (pMonitor->mmInfo.cluster.first_ep_dnode_id == 0) return; - // (void)tjsonAddStringToObject(pMonitor->pJson, "first_ep", pInfo->first_ep); - (void)tjsonAddStringToObject(pMonitor->pJson, "first_ep", tsFirst); - (void)tjsonAddDoubleToObject(pMonitor->pJson, "first_ep_dnode_id", pInfo->first_ep_dnode_id); - (void)tjsonAddStringToObject(pMonitor->pJson, "cluster_version", pInfo->version); - // (void)tjsonAddDoubleToObject(pMonitor->pJson, "monitor_interval", pInfo->monitor_interval); + if (tjsonAddStringToObject(pMonitor->pJson, "first_ep", tsFirst) != 0) uError("failed to add first_ep"); + if (tjsonAddDoubleToObject(pMonitor->pJson, "first_ep_dnode_id", pInfo->first_ep_dnode_id) != 0) + uError("failed to add first_ep_dnode_id"); + if (tjsonAddStringToObject(pMonitor->pJson, "cluster_version", pInfo->version) != 0) + uError("failed to add cluster_version"); } static void monGenVgroupJson(SMonInfo *pMonitor) { @@ -337,10 +345,13 @@ static void monGenVgroupJson(SMonInfo *pMonitor) { } SMonVgroupDesc *pVgroupDesc = taosArrayGet(pInfo->vgroups, i); - (void)tjsonAddDoubleToObject(pVgroupJson, "vgroup_id", pVgroupDesc->vgroup_id); - (void)tjsonAddStringToObject(pVgroupJson, "database_name", pVgroupDesc->database_name); - (void)tjsonAddDoubleToObject(pVgroupJson, "tables_num", pVgroupDesc->tables_num); - (void)tjsonAddStringToObject(pVgroupJson, "status", pVgroupDesc->status); + if (tjsonAddDoubleToObject(pVgroupJson, "vgroup_id", pVgroupDesc->vgroup_id) != 0) + uError("failed to add vgroup_id"); + if (tjsonAddStringToObject(pVgroupJson, "database_name", pVgroupDesc->database_name) != 0) + uError("failed to add database_name"); + if (tjsonAddDoubleToObject(pVgroupJson, "tables_num", pVgroupDesc->tables_num) != 0) + uError("failed to add tables_num"); + if (tjsonAddStringToObject(pVgroupJson, "status", pVgroupDesc->status) != 0) uError("failed to add status"); SJson *pVnodesJson = tjsonAddArrayToObject(pVgroupJson, "vnodes"); if (pVnodesJson == NULL) continue; @@ -352,8 +363,9 @@ static void monGenVgroupJson(SMonInfo *pMonitor) { SJson *pVnodeJson = tjsonCreateObject(); if (pVnodeJson == NULL) continue; - (void)tjsonAddDoubleToObject(pVnodeJson, "dnode_id", pVnodeDesc->dnode_id); - (void)tjsonAddStringToObject(pVnodeJson, "vnode_role", pVnodeDesc->vnode_role); + if (tjsonAddDoubleToObject(pVnodeJson, "dnode_id", pVnodeDesc->dnode_id) != 0) uError("failed to add dnode_id"); + if (tjsonAddStringToObject(pVnodeJson, "vnode_role", pVnodeDesc->vnode_role) != 0) + uError("failed to add vnode_role"); if (tjsonAddItemToArray(pVnodesJson, pVnodeJson) != 0) tjsonDelete(pVnodeJson); } @@ -376,8 +388,9 @@ static void monGenStbJson(SMonInfo *pMonitor) { } SMonStbDesc *pStbDesc = taosArrayGet(pInfo->stbs, i); - (void)tjsonAddStringToObject(pStbJson, "stb_name", pStbDesc->stb_name); - (void)tjsonAddStringToObject(pStbJson, "database_name", pStbDesc->database_name); + if (tjsonAddStringToObject(pStbJson, "stb_name", pStbDesc->stb_name) != 0) uError("failed to add stb_name"); + if (tjsonAddStringToObject(pStbJson, "database_name", pStbDesc->database_name) != 0) + uError("failed to add database_name"); } } @@ -392,9 +405,11 @@ static void monGenGrantJson(SMonInfo *pMonitor) { return; } - (void)tjsonAddDoubleToObject(pJson, "expire_time", pInfo->expire_time); - (void)tjsonAddDoubleToObject(pJson, "timeseries_used", pInfo->timeseries_used); - (void)tjsonAddDoubleToObject(pJson, "timeseries_total", pInfo->timeseries_total); + if (tjsonAddDoubleToObject(pJson, "expire_time", pInfo->expire_time) != 0) uError("failed to add expire_time"); + if (tjsonAddDoubleToObject(pJson, "timeseries_used", pInfo->timeseries_used) != 0) + uError("failed to add timeseries_used"); + if (tjsonAddDoubleToObject(pJson, "timeseries_total", pInfo->timeseries_total) != 0) + uError("failed to add timeseries_total"); } static void monGenDnodeJson(SMonInfo *pMonitor) { @@ -451,36 +466,40 @@ static void monGenDnodeJson(SMonInfo *pMonitor) { double io_read_disk_rate = io_read_disk / interval; double io_write_disk_rate = io_write_disk / interval; - (void)tjsonAddDoubleToObject(pJson, "uptime", pInfo->uptime); - (void)tjsonAddDoubleToObject(pJson, "cpu_engine", cpu_engine); - (void)tjsonAddDoubleToObject(pJson, "cpu_system", pSys->cpu_system); - (void)tjsonAddDoubleToObject(pJson, "cpu_cores", pSys->cpu_cores); - (void)tjsonAddDoubleToObject(pJson, "mem_engine", mem_engine); - (void)tjsonAddDoubleToObject(pJson, "mem_system", pSys->mem_system); - (void)tjsonAddDoubleToObject(pJson, "mem_total", pSys->mem_total); - (void)tjsonAddDoubleToObject(pJson, "disk_engine", pSys->disk_engine); - (void)tjsonAddDoubleToObject(pJson, "disk_used", pSys->disk_used); - (void)tjsonAddDoubleToObject(pJson, "disk_total", pSys->disk_total); - (void)tjsonAddDoubleToObject(pJson, "net_in", net_in_rate); - (void)tjsonAddDoubleToObject(pJson, "net_out", net_out_rate); - (void)tjsonAddDoubleToObject(pJson, "io_read", io_read_rate); - (void)tjsonAddDoubleToObject(pJson, "io_write", io_write_rate); - (void)tjsonAddDoubleToObject(pJson, "io_read_disk", io_read_disk_rate); - (void)tjsonAddDoubleToObject(pJson, "io_write_disk", io_write_disk_rate); - (void)tjsonAddDoubleToObject(pJson, "req_select", pStat->numOfSelectReqs); - (void)tjsonAddDoubleToObject(pJson, "req_select_rate", req_select_rate); - (void)tjsonAddDoubleToObject(pJson, "req_insert", pStat->numOfInsertReqs); - (void)tjsonAddDoubleToObject(pJson, "req_insert_success", pStat->numOfInsertSuccessReqs); - (void)tjsonAddDoubleToObject(pJson, "req_insert_rate", req_insert_rate); - (void)tjsonAddDoubleToObject(pJson, "req_insert_batch", pStat->numOfBatchInsertReqs); - (void)tjsonAddDoubleToObject(pJson, "req_insert_batch_success", pStat->numOfBatchInsertSuccessReqs); - (void)tjsonAddDoubleToObject(pJson, "req_insert_batch_rate", req_insert_batch_rate); - (void)tjsonAddDoubleToObject(pJson, "errors", pStat->errors); - (void)tjsonAddDoubleToObject(pJson, "vnodes_num", pStat->totalVnodes); - (void)tjsonAddDoubleToObject(pJson, "masters", pStat->masterNum); - (void)tjsonAddDoubleToObject(pJson, "has_mnode", pInfo->has_mnode); - (void)tjsonAddDoubleToObject(pJson, "has_qnode", pInfo->has_qnode); - (void)tjsonAddDoubleToObject(pJson, "has_snode", pInfo->has_snode); + if (tjsonAddDoubleToObject(pJson, "uptime", pInfo->uptime) != 0) uError("failed to add uptime"); + if (tjsonAddDoubleToObject(pJson, "cpu_engine", cpu_engine) != 0) uError("failed to add cpu_engine"); + if (tjsonAddDoubleToObject(pJson, "cpu_system", pSys->cpu_system) != 0) uError("failed to add cpu_system"); + if (tjsonAddDoubleToObject(pJson, "cpu_cores", pSys->cpu_cores) != 0) uError("failed to add cpu_cores"); + if (tjsonAddDoubleToObject(pJson, "mem_engine", mem_engine) != 0) uError("failed to add mem_engine"); + if (tjsonAddDoubleToObject(pJson, "mem_system", pSys->mem_system) != 0) uError("failed to add mem_system"); + if (tjsonAddDoubleToObject(pJson, "mem_total", pSys->mem_total) != 0) uError("failed to add mem_total"); + if (tjsonAddDoubleToObject(pJson, "disk_engine", pSys->disk_engine) != 0) uError("failed to add disk_engine"); + if (tjsonAddDoubleToObject(pJson, "disk_used", pSys->disk_used) != 0) uError("failed to add disk_used"); + if (tjsonAddDoubleToObject(pJson, "disk_total", pSys->disk_total) != 0) uError("failed to add disk_total"); + if (tjsonAddDoubleToObject(pJson, "net_in", net_in_rate) != 0) uError("failed to add net_in"); + if (tjsonAddDoubleToObject(pJson, "net_out", net_out_rate) != 0) uError("failed to add net_out"); + if (tjsonAddDoubleToObject(pJson, "io_read", io_read_rate) != 0) uError("failed to add io_read"); + if (tjsonAddDoubleToObject(pJson, "io_write", io_write_rate) != 0) uError("failed to add io_write"); + if (tjsonAddDoubleToObject(pJson, "io_read_disk", io_read_disk_rate) != 0) uError("failed to add io_read_disk"); + if (tjsonAddDoubleToObject(pJson, "io_write_disk", io_write_disk_rate) != 0) uError("failed to add io_write_disk"); + if (tjsonAddDoubleToObject(pJson, "req_select", pStat->numOfSelectReqs) != 0) uError("failed to add req_select"); + if (tjsonAddDoubleToObject(pJson, "req_select_rate", req_select_rate) != 0) uError("failed to add req_select_rate"); + if (tjsonAddDoubleToObject(pJson, "req_insert", pStat->numOfInsertReqs) != 0) uError("failed to add req_insert"); + if (tjsonAddDoubleToObject(pJson, "req_insert_success", pStat->numOfInsertSuccessReqs) != 0) + uError("failed to add req_insert_success"); + if (tjsonAddDoubleToObject(pJson, "req_insert_rate", req_insert_rate) != 0) uError("failed to add req_insert_rate"); + if (tjsonAddDoubleToObject(pJson, "req_insert_batch", pStat->numOfBatchInsertReqs) != 0) + uError("failed to add req_insert_batch"); + if (tjsonAddDoubleToObject(pJson, "req_insert_batch_success", pStat->numOfBatchInsertSuccessReqs) != 0) + uError("failed to add req_insert_batch_success"); + if (tjsonAddDoubleToObject(pJson, "req_insert_batch_rate", req_insert_batch_rate) != 0) + uError("failed to add req_insert_batch_rate"); + if (tjsonAddDoubleToObject(pJson, "errors", pStat->errors) != 0) uError("failed to add errors"); + if (tjsonAddDoubleToObject(pJson, "vnodes_num", pStat->totalVnodes) != 0) uError("failed to add vnodes_num"); + if (tjsonAddDoubleToObject(pJson, "masters", pStat->masterNum) != 0) uError("failed to add masters"); + if (tjsonAddDoubleToObject(pJson, "has_mnode", pInfo->has_mnode) != 0) uError("failed to add has_mnode"); + if (tjsonAddDoubleToObject(pJson, "has_qnode", pInfo->has_qnode) != 0) uError("failed to add has_qnode"); + if (tjsonAddDoubleToObject(pJson, "has_snode", pInfo->has_snode) != 0) uError("failed to add has_snode"); } static void monGenDiskJson(SMonInfo *pMonitor) { @@ -515,18 +534,18 @@ static void monGenDiskJson(SMonInfo *pMonitor) { SJson *pLogdirJson = tjsonCreateObject(); if (pLogdirJson == NULL) return; if (tjsonAddItemToObject(pJson, "logdir", pLogdirJson) != 0) return; - (void)tjsonAddStringToObject(pLogdirJson, "name", pLogDesc->name); - (void)tjsonAddDoubleToObject(pLogdirJson, "avail", pLogDesc->size.avail); - (void)tjsonAddDoubleToObject(pLogdirJson, "used", pLogDesc->size.used); - (void)tjsonAddDoubleToObject(pLogdirJson, "total", pLogDesc->size.total); + if (tjsonAddStringToObject(pLogdirJson, "name", pLogDesc->name) != 0) uError("failed to add string to json"); + if (tjsonAddDoubleToObject(pLogdirJson, "avail", pLogDesc->size.avail) != 0) uError("failed to add double to json"); + if (tjsonAddDoubleToObject(pLogdirJson, "used", pLogDesc->size.used) != 0) uError("failed to add double to json"); + if (tjsonAddDoubleToObject(pLogdirJson, "total", pLogDesc->size.total) != 0) uError("failed to add double to json"); SJson *pTempdirJson = tjsonCreateObject(); if (pTempdirJson == NULL) return; if (tjsonAddItemToObject(pJson, "tempdir", pTempdirJson) != 0) return; - (void)tjsonAddStringToObject(pTempdirJson, "name", pTempDesc->name); - (void)tjsonAddDoubleToObject(pTempdirJson, "avail", pTempDesc->size.avail); - (void)tjsonAddDoubleToObject(pTempdirJson, "used", pTempDesc->size.used); - (void)tjsonAddDoubleToObject(pTempdirJson, "total", pTempDesc->size.total); + if (tjsonAddStringToObject(pTempdirJson, "name", pTempDesc->name) != 0) uError("failed to add string to json"); + if (tjsonAddDoubleToObject(pTempdirJson, "avail", pTempDesc->size.avail) != 0) uError("failed to add double to json"); + if (tjsonAddDoubleToObject(pTempdirJson, "used", pTempDesc->size.used) != 0) uError("failed to add double to json"); + if (tjsonAddDoubleToObject(pTempdirJson, "total", pTempDesc->size.total) != 0) uError("failed to add double to json"); } static const char *monLogLevelStr(ELogLevel level) { @@ -571,26 +590,26 @@ static void monGenLogJson(SMonInfo *pMonitor) { SJson *pLogError = tjsonCreateObject(); if (pLogError == NULL) return; - (void)tjsonAddStringToObject(pLogError, "level", "error"); - (void)tjsonAddDoubleToObject(pLogError, "total", numOfErrorLogs); + if (tjsonAddStringToObject(pLogError, "level", "error") != 0) uError("failed to add string to json"); + if (tjsonAddDoubleToObject(pLogError, "total", numOfErrorLogs) != 0) uError("failed to add double to json"); if (tjsonAddItemToArray(pSummaryJson, pLogError) != 0) tjsonDelete(pLogError); SJson *pLogInfo = tjsonCreateObject(); if (pLogInfo == NULL) return; - (void)tjsonAddStringToObject(pLogInfo, "level", "info"); - (void)tjsonAddDoubleToObject(pLogInfo, "total", numOfInfoLogs); + if (tjsonAddStringToObject(pLogInfo, "level", "info") != 0) uError("failed to add string to json"); + if (tjsonAddDoubleToObject(pLogInfo, "total", numOfInfoLogs) != 0) uError("failed to add double to json"); if (tjsonAddItemToArray(pSummaryJson, pLogInfo) != 0) tjsonDelete(pLogInfo); SJson *pLogDebug = tjsonCreateObject(); if (pLogDebug == NULL) return; - (void)tjsonAddStringToObject(pLogDebug, "level", "debug"); - (void)tjsonAddDoubleToObject(pLogDebug, "total", numOfDebugLogs); + if (tjsonAddStringToObject(pLogDebug, "level", "debug") != 0) uError("failed to add string to json"); + if (tjsonAddDoubleToObject(pLogDebug, "total", numOfDebugLogs) != 0) uError("failed to add double to json"); if (tjsonAddItemToArray(pSummaryJson, pLogDebug) != 0) tjsonDelete(pLogDebug); SJson *pLogTrace = tjsonCreateObject(); if (pLogTrace == NULL) return; - (void)tjsonAddStringToObject(pLogTrace, "level", "trace"); - (void)tjsonAddDoubleToObject(pLogTrace, "total", numOfTraceLogs); + if (tjsonAddStringToObject(pLogTrace, "level", "trace") != 0) uError("failed to add string to json"); + if (tjsonAddDoubleToObject(pLogTrace, "total", numOfTraceLogs) != 0) uError("failed to add double to json"); if (tjsonAddItemToArray(pSummaryJson, pLogTrace) != 0) tjsonDelete(pLogTrace); } diff --git a/source/libs/monitorfw/inc/taos_metric_formatter_i.h b/source/libs/monitorfw/inc/taos_metric_formatter_i.h index 54e683fa91..2c891dae95 100644 --- a/source/libs/monitorfw/inc/taos_metric_formatter_i.h +++ b/source/libs/monitorfw/inc/taos_metric_formatter_i.h @@ -30,7 +30,7 @@ taos_metric_formatter_t *taos_metric_formatter_new(); /** * @brief API PRIVATE taos_metric_formatter destructor */ -int taos_metric_formatter_destroy(taos_metric_formatter_t *self); +void taos_metric_formatter_destroy(taos_metric_formatter_t *self); /** * @brief API PRIVATE Loads the help text diff --git a/source/libs/monitorfw/inc/taos_string_builder_i.h b/source/libs/monitorfw/inc/taos_string_builder_i.h index 933d778691..02ca0a0900 100644 --- a/source/libs/monitorfw/inc/taos_string_builder_i.h +++ b/source/libs/monitorfw/inc/taos_string_builder_i.h @@ -31,7 +31,7 @@ taos_string_builder_t *taos_string_builder_new(void); * API PRIVATE * @brief Destroys a taos_string_builder* */ -int taos_string_builder_destroy(taos_string_builder_t *self); +void taos_string_builder_destroy(taos_string_builder_t *self); /** * API PRIVATE diff --git a/source/libs/monitorfw/inc/taos_test.h b/source/libs/monitorfw/inc/taos_test.h index b881b2cee2..11e145a7fa 100644 --- a/source/libs/monitorfw/inc/taos_test.h +++ b/source/libs/monitorfw/inc/taos_test.h @@ -23,6 +23,11 @@ if (!(i)) return 1; #define TAOS_TEST_PARA_NULL(i) \ if (!(i)) return NULL; +#define TAOS_TEST_PARA_VOID(i) \ + if (!(i)) { \ + TAOS_LOG("parameter is NULL"); \ + return; \ + } #endif // TAOS_TEST #endif // TAOS_TEST_H diff --git a/source/libs/monitorfw/src/taos_collector.c b/source/libs/monitorfw/src/taos_collector.c index 21ebb3f737..a7ea9f0f61 100644 --- a/source/libs/monitorfw/src/taos_collector.c +++ b/source/libs/monitorfw/src/taos_collector.c @@ -39,18 +39,24 @@ taos_collector_t *taos_collector_new(const char *name) { self->name = taos_strdup(name); self->metrics = taos_map_new(); if (self->metrics == NULL) { - (void)taos_collector_destroy(self); + if (taos_collector_destroy(self) != 0) { + TAOS_LOG("taos_collector_destroy failed"); + } return NULL; } r = taos_map_set_free_value_fn(self->metrics, &taos_metric_free_generic); if (r) { - (void)taos_collector_destroy(self); + if (taos_collector_destroy(self) != 0) { + TAOS_LOG("taos_collector_destroy failed"); + } return NULL; } self->collect_fn = &taos_collector_default_collect; self->string_builder = taos_string_builder_new(); if (self->string_builder == NULL) { - (void)taos_collector_destroy(self); + if (taos_collector_destroy(self) != 0) { + TAOS_LOG("taos_collector_destroy failed"); + } return NULL; } self->proc_limits_file_path = NULL; @@ -70,8 +76,7 @@ int taos_collector_destroy(taos_collector_t *self) { self->metrics = NULL; if(self->string_builder != NULL){ - r = taos_string_builder_destroy(self->string_builder); - if (r) ret = r; + taos_string_builder_destroy(self->string_builder); self->string_builder = NULL; } @@ -93,7 +98,9 @@ int taos_collector_destroy_generic(void *gen) { void taos_collector_free_generic(void *gen) { taos_collector_t *self = (taos_collector_t *)gen; - (void)taos_collector_destroy(self); + if (taos_collector_destroy(self) != 0) { + TAOS_LOG("taos_collector_destroy failed"); + } } int taos_collector_set_collect_fn(taos_collector_t *self, taos_collect_fn *fn) { diff --git a/source/libs/monitorfw/src/taos_collector_registry.c b/source/libs/monitorfw/src/taos_collector_registry.c index 94295bf9c0..bfdbf92156 100644 --- a/source/libs/monitorfw/src/taos_collector_registry.c +++ b/source/libs/monitorfw/src/taos_collector_registry.c @@ -50,7 +50,7 @@ taos_collector_registry_t *taos_collector_registry_new(const char *name) { self->name = taos_strdup(name); self->collectors = taos_map_new(); - (void)taos_map_set_free_value_fn(self->collectors, &taos_collector_free_generic); + if (taos_map_set_free_value_fn(self->collectors, &taos_collector_free_generic) != 0) return NULL; if (taos_map_set(self->collectors, "default", taos_collector_new("default")) != 0) return NULL; self->metric_formatter = taos_metric_formatter_new(); @@ -86,17 +86,14 @@ int taos_collector_registry_destroy(taos_collector_registry_t *self) { self->collectors = NULL; if (r) ret = r; - r = taos_metric_formatter_destroy(self->metric_formatter); + taos_metric_formatter_destroy(self->metric_formatter); self->metric_formatter = NULL; - if (r) ret = r; - r = taos_string_builder_destroy(self->string_builder); + taos_string_builder_destroy(self->string_builder); self->string_builder = NULL; - if (r) ret = r; - r = taos_string_builder_destroy(self->string_builder_batch); + taos_string_builder_destroy(self->string_builder_batch); self->string_builder_batch = NULL; - if (r) ret = r; r = pthread_rwlock_destroy(self->lock); taos_free(self->lock); @@ -241,13 +238,25 @@ const char *taos_collector_registry_bridge_new(taos_collector_registry_t *self, SJson* pJson = tjsonCreateArray(); SJson* item = tjsonCreateObject(); - (void)tjsonAddItemToArray(pJson, item); - (void)tjsonAddStringToObject(item, "ts", ts); - (void)tjsonAddDoubleToObject(item, "protocol", 2); - SJson* array = tjsonCreateArray(); - (void)tjsonAddItemToObject(item, "tables", array); + if (tjsonAddItemToArray(pJson, item) != 0) { + tjsonDelete(pJson); + return NULL; + } + if (tjsonAddStringToObject(item, "ts", ts) != 0) { + tjsonDelete(pJson); + return NULL; + } + if (tjsonAddDoubleToObject(item, "protocol", 2) != 0) { + tjsonDelete(pJson); + return NULL; + } + SJson *array = tjsonCreateArray(); + if (tjsonAddItemToObject(item, "tables", array) != 0) { + tjsonDelete(pJson); + return NULL; + } - if(taos_metric_formatter_load_metrics_new(self->metric_formatter, self->collectors, ts, format, array) != 0){ + if (taos_metric_formatter_load_metrics_new(self->metric_formatter, self->collectors, ts, format, array) != 0) { TAOS_LOG("failed to load metrics"); tjsonDelete(pJson); return NULL; @@ -294,9 +303,8 @@ const char *taos_collector_registry_bridge_new(taos_collector_registry_t *self, r = taos_string_builder_clear(tmp_builder); if (r) goto _OVER;; - r = taos_string_builder_destroy(tmp_builder); + taos_string_builder_destroy(tmp_builder); tmp_builder = NULL; - if (r) goto _OVER;; tjsonDelete(pJson); return data; @@ -304,7 +312,7 @@ const char *taos_collector_registry_bridge_new(taos_collector_registry_t *self, _OVER: tjsonDelete(pJson); if(tmp_builder != NULL){ - (void)taos_string_builder_destroy(tmp_builder); + taos_string_builder_destroy(tmp_builder); } return NULL; diff --git a/source/libs/monitorfw/src/taos_map.c b/source/libs/monitorfw/src/taos_map.c index 2f5bf566c2..bf1b85c534 100644 --- a/source/libs/monitorfw/src/taos_map.c +++ b/source/libs/monitorfw/src/taos_map.c @@ -45,21 +45,19 @@ taos_map_node_t *taos_map_node_new(const char *key, void *value, taos_map_node_f return self; } -int taos_map_node_destroy(taos_map_node_t *self) { - TAOS_TEST_PARA(self != NULL); - if (self == NULL) return 0; +void taos_map_node_destroy(taos_map_node_t *self) { + TAOS_TEST_PARA_VOID(self != NULL); taos_free((void *)self->key); self->key = NULL; if (self->value != NULL) (*self->free_value_fn)(self->value); self->value = NULL; taos_free(self); self = NULL; - return 0; } void taos_map_node_free(void *item) { taos_map_node_t *map_node = (taos_map_node_t *)item; - (void)taos_map_node_destroy(map_node); + taos_map_node_destroy(map_node); } taos_linked_list_compare_t taos_map_node_compare(void *item_a, void *item_b) { @@ -87,7 +85,9 @@ taos_map_t *taos_map_new() { // we will only have to deallocate each key once. That will happen on taos_map_node_destroy. r = taos_linked_list_set_free_fn(self->keys, taos_linked_list_no_op_free); if (r) { - (void)taos_map_destroy(self); + if (taos_map_destroy(self) != 0) { + TAOS_LOG("TAOS_MAP_DESTROY_ERROR"); + } return NULL; } @@ -98,12 +98,16 @@ taos_map_t *taos_map_new() { self->addrs[i] = taos_linked_list_new(); r = taos_linked_list_set_free_fn(self->addrs[i], taos_map_node_free); if (r) { - (void)taos_map_destroy(self); + if (taos_map_destroy(self) != 0) { + TAOS_LOG("TAOS_MAP_DESTROY_ERROR"); + } return NULL; } r = taos_linked_list_set_compare_fn(self->addrs[i], taos_map_node_compare); if (r) { - (void)taos_map_destroy(self); + if (taos_map_destroy(self) != 0) { + TAOS_LOG("TAOS_MAP_DESTROY_ERROR"); + } return NULL; } } @@ -112,7 +116,9 @@ taos_map_t *taos_map_new() { r = pthread_rwlock_init(self->rwlock, NULL); if (r) { TAOS_LOG(TAOS_PTHREAD_RWLOCK_INIT_ERROR); - (void)taos_map_destroy(self); + if (taos_map_destroy(self) != 0) { + TAOS_LOG("TAOS_MAP_DESTROY_ERROR"); + } return NULL; } @@ -188,12 +194,12 @@ static void *taos_map_get_internal(const char *key, size_t *size, size_t *max_si taos_map_node_t *current_map_node = (taos_map_node_t *)current_node->item; taos_linked_list_compare_t result = taos_linked_list_compare(list, current_map_node, temp_map_node); if (result == TAOS_EQUAL) { - (void)taos_map_node_destroy(temp_map_node); + taos_map_node_destroy(temp_map_node); temp_map_node = NULL; return current_map_node->value; } } - (void)taos_map_node_destroy(temp_map_node); + taos_map_node_destroy(temp_map_node); temp_map_node = NULL; return NULL; } @@ -388,7 +394,7 @@ static int taos_map_delete_internal(const char *key, size_t *size, size_t *max_s break; } } - r = taos_map_node_destroy(temp_map_node); + taos_map_node_destroy(temp_map_node); temp_map_node = NULL; return r; } diff --git a/source/libs/monitorfw/src/taos_metric.c b/source/libs/monitorfw/src/taos_metric.c index 42564437d0..9d55680c4d 100644 --- a/source/libs/monitorfw/src/taos_metric.c +++ b/source/libs/monitorfw/src/taos_metric.c @@ -49,12 +49,12 @@ taos_metric_t *taos_metric_new(taos_metric_type_t metric_type, const char *name, for (int i = 0; i < label_key_count; i++) { if (strcmp(label_keys[i], "le") == 0) { TAOS_LOG(TAOS_METRIC_INVALID_LABEL_NAME); - (void)taos_metric_destroy(self); + if (taos_metric_destroy(self) != 0) return NULL; return NULL; } if (strcmp(label_keys[i], "quantile") == 0) { TAOS_LOG(TAOS_METRIC_INVALID_LABEL_NAME); - (void)taos_metric_destroy(self); + if (taos_metric_destroy(self) != 0) return NULL; return NULL; } k[i] = taos_strdup(label_keys[i]); @@ -68,14 +68,14 @@ taos_metric_t *taos_metric_new(taos_metric_type_t metric_type, const char *name, } else { r = taos_map_set_free_value_fn(self->samples, &taos_metric_sample_free_generic); if (r) { - (void)taos_metric_destroy(self); + if (taos_metric_destroy(self) != 0) return NULL; return NULL; } } self->formatter = taos_metric_formatter_new(); if (self->formatter == NULL) { - (void)taos_metric_destroy(self); + if (taos_metric_destroy(self) != 0) return NULL; return NULL; } self->rwlock = (pthread_rwlock_t *)taos_malloc(sizeof(pthread_rwlock_t)); @@ -101,9 +101,8 @@ int taos_metric_destroy(taos_metric_t *self) { if (r) ret = r; } - r = taos_metric_formatter_destroy(self->formatter); + taos_metric_formatter_destroy(self->formatter); self->formatter = NULL; - if (r) ret = r; r = pthread_rwlock_destroy(self->rwlock); if (r) { @@ -140,7 +139,9 @@ int taos_metric_destroy_generic(void *item) { void taos_metric_free_generic(void *item) { taos_metric_t *self = (taos_metric_t *)item; - (void)taos_metric_destroy(self); + if (taos_metric_destroy(self) != 0) { + TAOS_LOG("taos_metric_destroy failed"); + } } taos_metric_sample_t *taos_metric_sample_from_labels(taos_metric_t *self, const char **label_values) { diff --git a/source/libs/monitorfw/src/taos_metric_formatter.c b/source/libs/monitorfw/src/taos_metric_formatter.c index cb1edd30b6..31796c20df 100644 --- a/source/libs/monitorfw/src/taos_metric_formatter.c +++ b/source/libs/monitorfw/src/taos_metric_formatter.c @@ -22,6 +22,7 @@ // Private #include "taos_collector_t.h" #include "taos_linked_list_t.h" +#include "taos_log.h" #include "taos_map_i.h" #include "taos_metric_formatter_i.h" #include "taos_metric_sample_t.h" @@ -33,35 +34,28 @@ taos_metric_formatter_t *taos_metric_formatter_new() { taos_metric_formatter_t *self = (taos_metric_formatter_t *)taos_malloc(sizeof(taos_metric_formatter_t)); self->string_builder = taos_string_builder_new(); if (self->string_builder == NULL) { - (void)taos_metric_formatter_destroy(self); + taos_metric_formatter_destroy(self); return NULL; } self->err_builder = taos_string_builder_new(); if (self->err_builder == NULL) { - (void)taos_metric_formatter_destroy(self); + taos_metric_formatter_destroy(self); return NULL; } return self; } -int taos_metric_formatter_destroy(taos_metric_formatter_t *self) { - TAOS_TEST_PARA(self != NULL); - if (self == NULL) return 0; +void taos_metric_formatter_destroy(taos_metric_formatter_t *self) { + TAOS_TEST_PARA_VOID(self != NULL); - int r = 0; - int ret = 0; - - r = taos_string_builder_destroy(self->string_builder); + taos_string_builder_destroy(self->string_builder); self->string_builder = NULL; - if (r) ret = r; - r = taos_string_builder_destroy(self->err_builder); + taos_string_builder_destroy(self->err_builder); self->err_builder = NULL; - if (r) ret = r; taos_free(self); self = NULL; - return ret; } /* int taos_metric_formatter_load_help(taos_metric_formatter_t *self, const char *name, const char *help) { diff --git a/source/libs/monitorfw/src/taos_metric_formatter_custom.c b/source/libs/monitorfw/src/taos_metric_formatter_custom.c index da05d09d9c..6e7ded62bb 100644 --- a/source/libs/monitorfw/src/taos_metric_formatter_custom.c +++ b/source/libs/monitorfw/src/taos_metric_formatter_custom.c @@ -88,17 +88,46 @@ int taos_metric_formatter_load_sample_new(taos_metric_formatter_t *self, taos_me char* value = *(pair + 1); SJson* tag = tjsonCreateObject(); - (void)tjsonAddStringToObject(tag, "name", key); - (void)tjsonAddStringToObject(tag, "value", value); - - (void)tjsonAddItemToArray(arrayTag, tag); + if ((r = tjsonAddStringToObject(tag, "name", key)) != 0) { + taosMemoryFreeClear(arr); + taosMemoryFreeClear(keyvalue); + taosMemoryFreeClear(keyvalues); + return r; + } + if ((r = tjsonAddStringToObject(tag, "value", value)) != 0) { + taosMemoryFreeClear(arr); + taosMemoryFreeClear(keyvalue); + taosMemoryFreeClear(keyvalues); + return r; + } + if ((r = tjsonAddItemToArray(arrayTag, tag)) != 0) { + taosMemoryFreeClear(arr); + taosMemoryFreeClear(keyvalue); + taosMemoryFreeClear(keyvalues); + return r; + } + } + if ((r = tjsonAddItemToObject(item, "tags", arrayTag)) != 0) { + taosMemoryFreeClear(arr); + taosMemoryFreeClear(keyvalue); + taosMemoryFreeClear(keyvalues); + return r; } - (void)tjsonAddItemToObject(item, "tags", arrayTag); metrics = tjsonCreateArray(); - (void)tjsonAddItemToObject(item, "metrics", metrics); + if ((r = tjsonAddItemToObject(item, "metrics", metrics)) != 0) { + taosMemoryFreeClear(arr); + taosMemoryFreeClear(keyvalue); + taosMemoryFreeClear(keyvalues); + return r; + } - (void)tjsonAddItemToArray(arrayMetricGroups, item); + if ((r = tjsonAddItemToArray(arrayMetricGroups, item)) != 0) { + taosMemoryFreeClear(arr); + taosMemoryFreeClear(keyvalue); + taosMemoryFreeClear(keyvalues); + return r; + } } else{ metrics = tjsonGetObjectItem(item, "metrics"); @@ -109,20 +138,20 @@ int taos_metric_formatter_load_sample_new(taos_metric_formatter_t *self, taos_me taosMemoryFreeClear(keyvalues); SJson* metric = tjsonCreateObject(); - (void)tjsonAddStringToObject(metric, "name", metricName); + if ((r = tjsonAddStringToObject(metric, "name", metricName)) != 0) return r; double old_value = 0; #define USE_EXCHANGE #ifdef USE_EXCHANGE - (void)taos_metric_sample_exchange(sample, 0, &old_value); + if ((r = taos_metric_sample_exchange(sample, 0, &old_value)) != 0) return r; #else old_value = sample->r_value; taos_metric_sample_set(sample, 0); #endif - (void)tjsonAddDoubleToObject(metric, "value", old_value); - (void)tjsonAddDoubleToObject(metric, "type", metric_type); - (void)tjsonAddItemToArray(metrics, metric); + if ((r = tjsonAddDoubleToObject(metric, "value", old_value)) != 0) return r; + if ((r = tjsonAddDoubleToObject(metric, "type", metric_type)) != 0) return r; + if ((r = tjsonAddItemToArray(metrics, metric)) != 0) return r; return 0; } @@ -150,7 +179,10 @@ int taos_metric_formatter_load_metric_new(taos_metric_formatter_t *self, taos_me SJson* table = tjsonGetArrayItem(tableArray, i); char tableName[MONITOR_TABLENAME_LEN] = {0}; - (void)tjsonGetStringValue(table, "name", tableName); + if ((r = tjsonGetStringValue(table, "name", tableName)) != 0) { + taosMemoryFreeClear(name); + return r; + } if(strcmp(tableName, arr[0]) == 0){ isFound = true; arrayMetricGroups = tjsonGetObjectItem(table, "metric_groups"); @@ -161,10 +193,16 @@ int taos_metric_formatter_load_metric_new(taos_metric_formatter_t *self, taos_me if(!isFound){ table = tjsonCreateObject(); - (void)tjsonAddStringToObject(table, "name", arr[0]); + if ((r = tjsonAddStringToObject(table, "name", arr[0])) != 0) { + taosMemoryFreeClear(name); + return r; + } arrayMetricGroups = tjsonCreateArray(); - (void)tjsonAddItemToObject(table, "metric_groups", arrayMetricGroups); + if ((r = tjsonAddItemToObject(table, "metric_groups", arrayMetricGroups)) != 0) { + taosMemoryFreeClear(name); + return r; + } } int32_t sample_count = 0; @@ -183,7 +221,10 @@ int taos_metric_formatter_load_metric_new(taos_metric_formatter_t *self, taos_me } if(!isFound && sample_count > 0){ - (void)tjsonAddItemToArray(tableArray, table); + if ((r = tjsonAddItemToArray(tableArray, table)) != 0) { + taosMemoryFreeClear(name); + return r; + } } else{ if(table != NULL) tjsonDelete(table); diff --git a/source/libs/monitorfw/src/taos_metric_sample.c b/source/libs/monitorfw/src/taos_metric_sample.c index e4b41d5475..ca41cf1a83 100644 --- a/source/libs/monitorfw/src/taos_metric_sample.c +++ b/source/libs/monitorfw/src/taos_metric_sample.c @@ -44,7 +44,6 @@ taos_metric_sample_t *taos_metric_sample_new(taos_metric_type_t type, const char int taos_metric_sample_destroy(taos_metric_sample_t *self) { TAOS_TEST_PARA(self != NULL); - if (self == NULL) return 0; taos_free((void *)self->l_value); self->l_value = NULL; taos_free((void *)self); @@ -63,7 +62,9 @@ int taos_metric_sample_destroy_generic(void *gen) { void taos_metric_sample_free_generic(void *gen) { taos_metric_sample_t *self = (taos_metric_sample_t *)gen; - (void)taos_metric_sample_destroy(self); + if(taos_metric_sample_destroy(self) != 0) { + TAOS_LOG(TAOS_METRIC_SAMPLE_DESTROY_ERROR); + } } int taos_metric_sample_add(taos_metric_sample_t *self, double r_value) { diff --git a/source/libs/monitorfw/src/taos_monitor_util.c b/source/libs/monitorfw/src/taos_monitor_util.c index 2285ed9e71..06ae4993c5 100644 --- a/source/libs/monitorfw/src/taos_monitor_util.c +++ b/source/libs/monitorfw/src/taos_monitor_util.c @@ -84,10 +84,10 @@ bool taos_monitor_is_match(const SJson* tags, char** pairs, int32_t count) { SJson* item = tjsonGetArrayItem(tags, i); char item_name[MONITOR_TAG_NAME_LEN] = {0}; - (void)tjsonGetStringValue(item, "name", item_name); + if (tjsonGetStringValue(item, "name", item_name) != 0) return false; char item_value[MONITOR_TAG_VALUE_LEN] = {0}; - (void)tjsonGetStringValue(item, "value", item_value); + if (tjsonGetStringValue(item, "value", item_value) != 0) return false; bool isfound = false; for(int32_t j = 0; j < count; j++){ diff --git a/source/libs/monitorfw/src/taos_string_builder.c b/source/libs/monitorfw/src/taos_string_builder.c index 6e3fe1d2e3..b1a5a098bc 100644 --- a/source/libs/monitorfw/src/taos_string_builder.c +++ b/source/libs/monitorfw/src/taos_string_builder.c @@ -20,6 +20,7 @@ #include "taos_alloc.h" // Private +#include "taos_log.h" #include "taos_string_builder_i.h" #include "taos_string_builder_t.h" #include "taos_test.h" @@ -44,7 +45,7 @@ taos_string_builder_t *taos_string_builder_new(void) { self->init_size = TAOS_STRING_BUILDER_INIT_SIZE; r = taos_string_builder_init(self); if (r) { - (void)taos_string_builder_destroy(self); + taos_string_builder_destroy(self); return NULL; } @@ -61,14 +62,12 @@ int taos_string_builder_init(taos_string_builder_t *self) { return 0; } -int taos_string_builder_destroy(taos_string_builder_t *self) { - TAOS_TEST_PARA(self != NULL); - if (self == NULL) return 0; +void taos_string_builder_destroy(taos_string_builder_t *self) { + TAOS_TEST_PARA_VOID(self != NULL); taos_free(self->str); self->str = NULL; taos_free(self); self = NULL; - return 0; } /** diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index f3573ddb42..6f6d7a0469 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -102,7 +102,6 @@ static int32_t exprNodeCopy(const SExprNode* pSrc, SExprNode* pDst) { COPY_OBJECT_FIELD(resType, sizeof(SDataType)); COPY_CHAR_ARRAY_FIELD(aliasName); COPY_CHAR_ARRAY_FIELD(userAlias); - COPY_SCALAR_FIELD(orderAlias); COPY_SCALAR_FIELD(projIdx); return TSDB_CODE_SUCCESS; } diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 1f65af928e..13b85a5ec2 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -442,7 +442,7 @@ static int32_t nodeListToJson(SJson* pJson, const char* pName, const SNodeList* if (LIST_LENGTH(pList) > 0) { SJson* jList = tjsonAddArrayToObject(pJson, pName); if (NULL == jList) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SNode* pNode; FOREACH(pNode, pList) { @@ -6177,6 +6177,7 @@ static int32_t jsonToDropTableStmt(const SJson* pJson, void* pObj) { static const char* jkDropSuperTableStmtDbName = "DbName"; static const char* jkDropSuperTableStmtTableName = "TableName"; static const char* jkDropSuperTableStmtIgnoreNotExists = "IgnoreNotExists"; +static const char* jkDropSuperTableStmtwithOpt = "withOpt"; static int32_t dropStableStmtToJson(const void* pObj, SJson* pJson) { const SDropSuperTableStmt* pNode = (const SDropSuperTableStmt*)pObj; @@ -6188,6 +6189,9 @@ static int32_t dropStableStmtToJson(const void* pObj, SJson* pJson) { if (TSDB_CODE_SUCCESS == code) { code = tjsonAddBoolToObject(pJson, jkDropSuperTableStmtIgnoreNotExists, pNode->ignoreNotExists); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddBoolToObject(pJson, jkDropSuperTableStmtwithOpt, pNode->withOpt); + } return code; } @@ -6202,6 +6206,9 @@ static int32_t jsonToDropStableStmt(const SJson* pJson, void* pObj) { if (TSDB_CODE_SUCCESS == code) { code = tjsonGetBoolValue(pJson, jkDropSuperTableStmtIgnoreNotExists, &pNode->ignoreNotExists); } + if (TSDB_CODE_SUCCESS == code) { + code = tjsonGetBoolValue(pJson, jkDropSuperTableStmtwithOpt, &pNode->withOpt); + } return code; } @@ -8385,8 +8392,7 @@ int32_t nodesNodeToString(const SNode* pNode, bool format, char** pStr, int32_t* SJson* pJson = tjsonCreateObject(); if (NULL == pJson) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = nodeToJson(pNode, pJson); @@ -8436,8 +8442,7 @@ int32_t nodesListToString(const SNodeList* pList, bool format, char** pStr, int3 SJson* pJson = tjsonCreateArray(); if (NULL == pJson) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SNode* pNode; diff --git a/source/libs/nodes/src/nodesMsgFuncs.c b/source/libs/nodes/src/nodesMsgFuncs.c index 4a82cc47b8..e16cda20ff 100644 --- a/source/libs/nodes/src/nodesMsgFuncs.c +++ b/source/libs/nodes/src/nodesMsgFuncs.c @@ -79,7 +79,7 @@ static int32_t initTlvEncoder(STlvEncoder* pEncoder) { pEncoder->offset = 0; pEncoder->tlvCount = 0; pEncoder->pBuf = taosMemoryMalloc(pEncoder->allocSize); - return NULL == pEncoder->pBuf ? TSDB_CODE_OUT_OF_MEMORY : TSDB_CODE_SUCCESS; + return NULL == pEncoder->pBuf ? terrno : TSDB_CODE_SUCCESS; } static void clearTlvEncoder(STlvEncoder* pEncoder) { taosMemoryFree(pEncoder->pBuf); } @@ -96,7 +96,7 @@ static int32_t tlvEncodeImpl(STlvEncoder* pEncoder, int16_t type, const void* pV pEncoder->allocSize = TMAX(pEncoder->allocSize * 2, pEncoder->allocSize + tlvLen); void* pNewBuf = taosMemoryRealloc(pEncoder->pBuf, pEncoder->allocSize); if (NULL == pNewBuf) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pEncoder->pBuf = pNewBuf; } @@ -113,7 +113,7 @@ static int32_t tlvEncodeValueImpl(STlvEncoder* pEncoder, const void* pValue, int if (pEncoder->offset + len > pEncoder->allocSize) { void* pNewBuf = taosMemoryRealloc(pEncoder->pBuf, pEncoder->allocSize * 2); if (NULL == pNewBuf) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pEncoder->pBuf = pNewBuf; pEncoder->allocSize = pEncoder->allocSize * 2; @@ -248,7 +248,7 @@ static int32_t tlvEncodeObj(STlvEncoder* pEncoder, int16_t type, FToMsg func, co pEncoder->allocSize = TMAX(pEncoder->allocSize * 2, pEncoder->allocSize + sizeof(STlv)); void* pNewBuf = taosMemoryRealloc(pEncoder->pBuf, pEncoder->allocSize); if (NULL == pNewBuf) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pEncoder->pBuf = pNewBuf; } @@ -520,7 +520,7 @@ static int32_t tlvDecodeCStrP(STlv* pTlv, char** pValue) { static int32_t tlvDecodeDynBinary(STlv* pTlv, void** pValue) { *pValue = taosMemoryMalloc(pTlv->len); if (NULL == *pValue) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(*pValue, pTlv->value, pTlv->len); return TSDB_CODE_SUCCESS; @@ -4843,7 +4843,7 @@ static int32_t msgToSArray(STlv* pTlv, void** pObj){ } pArray = taosArrayInit(capacity, elemSize); if (NULL == pArray) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pArray->size = actualSize; if (TSDB_CODE_SUCCESS != code || pTlvTemp == NULL) { @@ -4861,7 +4861,7 @@ static int32_t msgToSArray(STlv* pTlv, void** pObj){ if (pDataTlv != NULL) { pArray = taosArrayInit(capacity, elemSize); if (NULL == pArray) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pArray->size = actualSize; if (TSDB_CODE_SUCCESS != code || pTlvTemp == NULL) { diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index b7d04cc6bc..d65ddb6e2e 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -2446,8 +2446,7 @@ typedef struct SCollectFuncsCxt { static EDealRes collectFuncs(SNode* pNode, void* pContext) { SCollectFuncsCxt* pCxt = (SCollectFuncsCxt*)pContext; - if (QUERY_NODE_FUNCTION == nodeType(pNode) && pCxt->classifier(((SFunctionNode*)pNode)->funcId) && - !(((SExprNode*)pNode)->orderAlias)) { + if (QUERY_NODE_FUNCTION == nodeType(pNode) && pCxt->classifier(((SFunctionNode*)pNode)->funcId)) { SFunctionNode* pFunc = (SFunctionNode*)pNode; if (FUNCTION_TYPE_TBNAME == pFunc->funcType && pCxt->tableAlias) { SValueNode* pVal = (SValueNode*)nodesListGetNode(pFunc->pParameterList, 0); @@ -2768,7 +2767,7 @@ int32_t nodesMakeValueNodeFromString(char* literal, SValueNode** ppValNode) { pValNode->node.resType.bytes = lenStr + VARSTR_HEADER_SIZE; char* p = taosMemoryMalloc(lenStr + 1 + VARSTR_HEADER_SIZE); if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } varDataSetLen(p, lenStr); memcpy(varDataVal(p), literal, lenStr + 1); diff --git a/source/libs/parser/inc/parAst.h b/source/libs/parser/inc/parAst.h index f67f1d23b6..a2aec77c2e 100644 --- a/source/libs/parser/inc/parAst.h +++ b/source/libs/parser/inc/parAst.h @@ -211,8 +211,8 @@ SNode* createCreateSubTableFromFileClause(SAstCreateContext* pCxt, bool ignoreEx SNodeList* pSpecificTags, const SToken* pFilePath); SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables); SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable); -SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables); -SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable); +SNode* createDropTableStmt(SAstCreateContext* pCxt, bool withOpt, SNodeList* pTables); +SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool withOpt, bool ignoreNotExists, SNode* pRealTable); SNode* createAlterTableModifyOptions(SAstCreateContext* pCxt, SNode* pRealTable, SNode* pOptions); SNode* createAlterTableAddModifyCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_t alterType, SToken* pColName, SDataType dataType); diff --git a/source/libs/parser/inc/parTranslater.h b/source/libs/parser/inc/parTranslater.h index 93d6645e12..3cb3be4e90 100644 --- a/source/libs/parser/inc/parTranslater.h +++ b/source/libs/parser/inc/parTranslater.h @@ -43,6 +43,7 @@ typedef struct STranslateContext { bool createStream; bool stableQuery; bool showRewrite; + bool withOpt; SNode* pPrevRoot; SNode* pPostRoot; bool dual; // whether select stmt without from stmt, true for without. diff --git a/source/libs/parser/inc/parUtil.h b/source/libs/parser/inc/parUtil.h index f0f1ea51b0..857c7604a9 100644 --- a/source/libs/parser/inc/parUtil.h +++ b/source/libs/parser/inc/parUtil.h @@ -111,7 +111,8 @@ typedef struct SParseMetaCache { SHashObj* pTableCfg; // key is tbFName, element is STableCfg* SHashObj* pViews; // key is viewFName, element is SViewMeta* SHashObj* pTableTSMAs; // key is tbFName, elements are SArray - SHashObj* pTSMAs; // key is tsmaFName, elemetns are STableTSMAInfo* + SHashObj* pTSMAs; // key is tsmaFName, elements are STableTSMAInfo* + SHashObj* pTableName; // key is tbFUid, elements is STableMeta*(append with tbName) SArray* pDnodes; // element is SEpSet bool dnodeRequired; } SParseMetaCache; @@ -141,6 +142,7 @@ int32_t buildCatalogReq(const SParseMetaCache* pMetaCache, SCatalogReq* pCatalog int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMetaData, SParseMetaCache* pMetaCache); int32_t reserveTableMetaInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache); int32_t reserveTableMetaInCacheExt(const SName* pName, SParseMetaCache* pMetaCache); +int32_t reserveTableUidInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache); int32_t reserveViewMetaInCache(int32_t acctId, const char* pDb, const char* pView, SParseMetaCache* pMetaCache); int32_t reserveViewMetaInCacheExt(const SName* pName, SParseMetaCache* pMetaCache); int32_t reserveDbVgInfoInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache); @@ -159,10 +161,12 @@ int32_t reserveDnodeRequiredInCache(SParseMetaCache* pMetaCache); int32_t reserveTableTSMAInfoInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache); int32_t reserveTSMAInfoInCache(int32_t acctId, const char* pDb, const char* pTsmaName, SParseMetaCache* pMetaCache); int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta); +int32_t getTableNameFromCache(SParseMetaCache* pMetaCache, const SName* pName, char* pTbName); int32_t getViewMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta); int32_t buildTableMetaFromViewMeta(STableMeta** pMeta, SViewMeta* pViewMeta); int32_t getDbVgInfoFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SArray** pVgInfo); int32_t getTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName, SVgroupInfo* pVgroup); +int32_t getDbTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName, SVgroupInfo* pVgroup); int32_t getDbVgVersionFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, int32_t* pVersion, int64_t* pDbId, int32_t* pTableNum, int64_t* pStateTs); int32_t getDbCfgFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SDbCfgInfo* pInfo); diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index b084b0035e..588a11deaf 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -124,8 +124,8 @@ sysinfo_opt(A) ::= . sysinfo_opt(A) ::= SYSINFO NK_INTEGER(B). { A = taosStr2Int8(B.z, NULL, 10); } /************************************************ grant/revoke ********************************************************/ -cmd ::= GRANT privileges(A) ON priv_level(B) with_opt(D) TO user_name(C). { pCxt->pRootNode = createGrantStmt(pCxt, A, &B, &C, D); } -cmd ::= REVOKE privileges(A) ON priv_level(B) with_opt(D) FROM user_name(C). { pCxt->pRootNode = createRevokeStmt(pCxt, A, &B, &C, D); } +cmd ::= GRANT privileges(A) ON priv_level(B) with_clause_opt(D) TO user_name(C). { pCxt->pRootNode = createGrantStmt(pCxt, A, &B, &C, D); } +cmd ::= REVOKE privileges(A) ON priv_level(B) with_clause_opt(D) FROM user_name(C). { pCxt->pRootNode = createRevokeStmt(pCxt, A, &B, &C, D); } %type privileges { int64_t } %destructor privileges { } @@ -151,8 +151,8 @@ priv_level(A) ::= db_name(B) NK_DOT NK_STAR(C). priv_level(A) ::= db_name(B) NK_DOT table_name(C). { A.first = B; A.second = C; } priv_level(A) ::= topic_name(B). { A.first = B; A.second = nil_token; } -with_opt(A) ::= . { A = NULL; } -with_opt(A) ::= WITH search_condition(B). { A = B; } +with_clause_opt(A) ::= . { A = NULL; } +with_clause_opt(A) ::= WITH search_condition(B). { A = B; } /************************************************ create encrypt_key *********************************************/ cmd ::= CREATE ENCRYPT_KEY NK_STRING(A). { pCxt->pRootNode = createEncryptKeyStmt(pCxt, &A); } @@ -357,8 +357,8 @@ cmd ::= CREATE TABLE not_exists_opt(B) USING full_table_name(C) NK_LP tag_list_opt(D) NK_RP FILE NK_STRING(E). { pCxt->pRootNode = createCreateSubTableFromFileClause(pCxt, B, C, D, &E); } cmd ::= CREATE STABLE not_exists_opt(A) full_table_name(B) NK_LP column_def_list(C) NK_RP tags_def(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E); } -cmd ::= DROP TABLE multi_drop_clause(A). { pCxt->pRootNode = createDropTableStmt(pCxt, A); } -cmd ::= DROP STABLE exists_opt(A) full_table_name(B). { pCxt->pRootNode = createDropSuperTableStmt(pCxt, A, B); } +cmd ::= DROP TABLE with_opt(A) multi_drop_clause(B). { pCxt->pRootNode = createDropTableStmt(pCxt, A, B); } +cmd ::= DROP STABLE with_opt(A) exists_opt(B) full_table_name(C). { pCxt->pRootNode = createDropSuperTableStmt(pCxt, A, B, C); } cmd ::= ALTER TABLE alter_table_clause(A). { pCxt->pRootNode = A; } cmd ::= ALTER STABLE alter_table_clause(A). { pCxt->pRootNode = setAlterSuperTableType(A); } @@ -399,6 +399,11 @@ multi_drop_clause(A) ::= multi_drop_clause(B) NK_COMMA drop_table_clause(C). drop_table_clause(A) ::= exists_opt(B) full_table_name(C). { A = createDropTableClause(pCxt, B, C); } +%type with_opt { bool } +%destructor with_opt { } +with_opt(A) ::= . { A = false; } +with_opt(A) ::= WITH. { A = true; } + %type specific_cols_opt { SNodeList* } %destructor specific_cols_opt { nodesDestroyList($$); } specific_cols_opt(A) ::= . { A = NULL; } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 868b345101..7c533dd224 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -933,7 +933,7 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL SValueNode* pVal = (SValueNode*)pLeft; char* pNewLiteral = taosMemoryCalloc(1, strlen(pVal->literal) + 2); if (!pNewLiteral) { - pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY; + pCxt->errCode = terrno; goto _err; } if ('+' == pVal->literal[0]) { @@ -2355,19 +2355,20 @@ _err: return NULL; } -SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables) { +SNode* createDropTableStmt(SAstCreateContext* pCxt, bool withOpt, SNodeList* pTables) { CHECK_PARSER_STATUS(pCxt); SDropTableStmt* pStmt = NULL; pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_TABLE_STMT, (SNode**)&pStmt); CHECK_MAKE_NODE(pStmt); pStmt->pTables = pTables; + pStmt->withOpt = withOpt; return (SNode*)pStmt; _err: nodesDestroyList(pTables); return NULL; } -SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable) { +SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool withOpt, bool ignoreNotExists, SNode* pRealTable) { CHECK_PARSER_STATUS(pCxt); SDropSuperTableStmt* pStmt = NULL; pCxt->errCode = nodesMakeNode(QUERY_NODE_DROP_SUPER_TABLE_STMT, (SNode**)&pStmt); @@ -2375,6 +2376,7 @@ SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, S strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName); strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName); pStmt->ignoreNotExists = ignoreNotExists; + pStmt->withOpt = withOpt; nodesDestroyNode(pRealTable); return (SNode*)pStmt; _err: diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index d323d45c81..f4dd91f392 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -379,13 +379,24 @@ static int32_t collectMetaKeyFromDropTable(SCollectMetaKeyCxt* pCxt, SDropTableS SNode* pNode = NULL; FOREACH(pNode, pStmt->pTables) { SDropTableClause* pClause = (SDropTableClause*)pNode; - code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache); - if (TSDB_CODE_SUCCESS == code) { - code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache); - } - if (TSDB_CODE_SUCCESS == code) { - code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, - pClause->tableName, AUTH_TYPE_WRITE, pCxt->pMetaCache); + if (pStmt->withOpt) { + code = reserveTableUidInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache); + if (TSDB_CODE_SUCCESS == code) { + code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pClause->dbName, pCxt->pMetaCache); + } + if (TSDB_CODE_SUCCESS == code) { + code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pClause->dbName, pCxt->pMetaCache); + } + } else { + code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache); + if (TSDB_CODE_SUCCESS == code) { + code = + reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache); + } + if (TSDB_CODE_SUCCESS == code) { + code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, + pClause->tableName, AUTH_TYPE_WRITE, pCxt->pMetaCache); + } } if (TSDB_CODE_SUCCESS != code) { break; @@ -395,6 +406,9 @@ static int32_t collectMetaKeyFromDropTable(SCollectMetaKeyCxt* pCxt, SDropTableS } static int32_t collectMetaKeyFromDropStable(SCollectMetaKeyCxt* pCxt, SDropSuperTableStmt* pStmt) { + if (pStmt->withOpt) { + return reserveTableUidInCache(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, pCxt->pMetaCache); + } return reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pStmt->dbName, pStmt->tableName, AUTH_TYPE_WRITE, pCxt->pMetaCache); } diff --git a/source/libs/parser/src/parAuthenticator.c b/source/libs/parser/src/parAuthenticator.c index 9f738b32e8..0eb07d8143 100644 --- a/source/libs/parser/src/parAuthenticator.c +++ b/source/libs/parser/src/parAuthenticator.c @@ -290,7 +290,10 @@ static int32_t authCreateMultiTable(SAuthCxt* pCxt, SCreateMultiTablesStmt* pStm static int32_t authDropTable(SAuthCxt* pCxt, SDropTableStmt* pStmt) { int32_t code = TSDB_CODE_SUCCESS; - SNode* pNode = NULL; + if (pStmt->withOpt && !pCxt->pParseCxt->isSuperUser) { + return TSDB_CODE_PAR_PERMISSION_DENIED; + } + SNode* pNode = NULL; FOREACH(pNode, pStmt->pTables) { SDropTableClause* pClause = (SDropTableClause*)pNode; code = checkAuth(pCxt, pClause->dbName, pClause->tableName, AUTH_TYPE_WRITE, NULL); @@ -302,6 +305,9 @@ static int32_t authDropTable(SAuthCxt* pCxt, SDropTableStmt* pStmt) { } static int32_t authDropStable(SAuthCxt* pCxt, SDropSuperTableStmt* pStmt) { + if (pStmt->withOpt && !pCxt->pParseCxt->isSuperUser) { + return TSDB_CODE_PAR_PERMISSION_DENIED; + } return checkAuth(pCxt, pStmt->dbName, pStmt->tableName, AUTH_TYPE_WRITE, NULL); } diff --git a/source/libs/parser/src/parCalcConst.c b/source/libs/parser/src/parCalcConst.c index 87b434a202..e757ec8b24 100644 --- a/source/libs/parser/src/parCalcConst.c +++ b/source/libs/parser/src/parCalcConst.c @@ -210,7 +210,7 @@ static int32_t calcConstProject(SCalcConstContext* pCxt, SNode* pProject, bool d if (NULL != ((SExprNode*)pProject)->pAssociation) { pAssociation = taosArrayDup(((SExprNode*)pProject)->pAssociation, NULL); if (NULL == pAssociation) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } diff --git a/source/libs/parser/src/parInsertSml.c b/source/libs/parser/src/parInsertSml.c index 6bfab0c9ce..da9c9d5b8d 100644 --- a/source/libs/parser/src/parInsertSml.c +++ b/source/libs/parser/src/parInsertSml.c @@ -101,11 +101,11 @@ static int32_t smlBuildTagRow(SArray* cols, SBoundColInfo* tags, SSchema* pSchem SMsgBuf* msg) { SArray* pTagArray = taosArrayInit(tags->numOfBound, sizeof(STagVal)); if (!pTagArray) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } *tagName = taosArrayInit(8, TSDB_COL_NAME_LEN); if (!*tagName) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = TSDB_CODE_SUCCESS; @@ -125,7 +125,7 @@ static int32_t smlBuildTagRow(SArray* cols, SBoundColInfo* tags, SSchema* pSchem } if (taosArrayPush(*tagName, pTagSchema->name) == NULL){ - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; uError("SML smlBuildTagRow error push tag name"); goto end; } @@ -160,7 +160,7 @@ static int32_t smlBuildTagRow(SArray* cols, SBoundColInfo* tags, SSchema* pSchem (void)memcpy(&val.i64, &(kv->value), kv->length); } if (taosArrayPush(pTagArray, &val) == NULL){ - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; uError("SML smlBuildTagRow error push tag array"); goto end; } @@ -209,7 +209,7 @@ void clearColValArraySml(SArray* pCols) { int32_t smlBuildRow(STableDataCxt* pTableCxt) { SRow** pRow = taosArrayReserve(pTableCxt->pData->aRowP, 1); if (pRow == NULL){ - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow); if (TSDB_CODE_SUCCESS != ret) { @@ -431,7 +431,7 @@ int32_t smlBindData(SQuery* query, bool dataFormat, SArray* tags, SArray* colsSc pVal->value.nData = kv->length; pVal->value.pData = taosMemoryMalloc(kv->length); if (NULL == pVal->value.pData) { - ret = TSDB_CODE_OUT_OF_MEMORY; + ret = terrno; goto end; } (void)memcpy(pVal->value.pData, (uint8_t*)kv->value, kv->length); @@ -443,7 +443,7 @@ int32_t smlBindData(SQuery* query, bool dataFormat, SArray* tags, SArray* colsSc SRow** pRow = taosArrayReserve(pTableCxt->pData->aRowP, 1); if (NULL == pRow) { - ret = TSDB_CODE_OUT_OF_MEMORY; + ret = terrno; goto end; } ret = tRowBuild(pTableCxt->pValues, pTableCxt->pSchema, pRow); @@ -488,7 +488,7 @@ int32_t smlInitHandle(SQuery** query) { uError("create pTableBlockHashObj error"); qDestroyQuery(pQuery); nodesDestroyNode((SNode*)stmt); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } stmt->freeHashFunc = insDestroyTableDataCxtHashMap; stmt->freeArrayFunc = insDestroyVgroupDataCxtList; diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c index a7e842f486..d6841fb492 100644 --- a/source/libs/parser/src/parInsertSql.c +++ b/source/libs/parser/src/parInsertSql.c @@ -666,7 +666,7 @@ static int32_t parseTagToken(const char** end, SToken* pToken, SSchema* pSchema, } else { val->pData = taosMemoryMalloc(size); if (NULL == val->pData) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } else { memcpy(val->pData, output, size); val->nData = size; @@ -683,7 +683,7 @@ static int32_t parseTagToken(const char** end, SToken* pToken, SSchema* pSchema, if (realLen > pSchema->bytes - VARSTR_HEADER_SIZE) realLen = pSchema->bytes - VARSTR_HEADER_SIZE; void* p = taosMemoryMalloc(realLen); if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (!taosMbsToUcs4(pToken->z, pToken->n, (TdUcs4*)(p), realLen, &output)) { if (terrno == TAOS_SYSTEM_ERROR(E2BIG)) { @@ -736,7 +736,7 @@ int32_t parseTagValue(SMsgBuf* pMsgBuf, const char** pSql, uint8_t precision, SS bool isNull = isNullValue(pTagSchema->type, pToken); if (!isNull && pTagName) { if (NULL == taosArrayPush(pTagName, pTagSchema->name)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -758,7 +758,7 @@ int32_t parseTagValue(SMsgBuf* pMsgBuf, const char** pSql, uint8_t precision, SS int32_t code = parseTagToken(pSql, pToken, pTagSchema, precision, &val, pMsgBuf); if (TSDB_CODE_SUCCESS == code) { if (NULL == taosArrayPush(pTagVals, &val)){ - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } } @@ -946,7 +946,7 @@ static int32_t parseTagsClauseImpl(SInsertParseContext* pCxt, SVnodeModifyOpStmt if (!(pTagVals = taosArrayInit(pCxt->tags.numOfBound, sizeof(STagVal))) || !(pTagName = taosArrayInit(pCxt->tags.numOfBound, TSDB_COL_NAME_LEN))) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exit; } @@ -1425,7 +1425,7 @@ int32_t initTableColSubmitData(STableDataCxt* pTableCxt) { SSchema* pSchema = &pTableCxt->pMeta->schema[pTableCxt->boundColsInfo.pColIndex[i]]; SColData* pCol = taosArrayReserve(pTableCxt->pData->aCol, 1); if (NULL == pCol) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } tColDataInit(pCol, pSchema->colId, pSchema->type, pSchema->flags); } @@ -1595,7 +1595,7 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql, } pVal->value.pData = taosMemoryMalloc(pToken->n); if (NULL == pVal->value.pData) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(pVal->value.pData, pToken->z, pToken->n); pVal->value.nData = pToken->n; @@ -1615,7 +1615,7 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql, if (realLen > pSchema->bytes - VARSTR_HEADER_SIZE) realLen = pSchema->bytes - VARSTR_HEADER_SIZE; char* pUcs4 = taosMemoryMalloc(realLen); if (NULL == pUcs4) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (!taosMbsToUcs4(pToken->z, pToken->n, (TdUcs4*)pUcs4, realLen, &len)) { taosMemoryFree(pUcs4); @@ -1636,7 +1636,7 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql, } pVal->value.pData = taosMemoryMalloc(pToken->n); if (NULL == pVal->value.pData) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(pVal->value.pData, pToken->z, pToken->n); pVal->value.nData = pToken->n; @@ -1657,7 +1657,7 @@ static int32_t parseValueTokenImpl(SInsertParseContext* pCxt, const char** pSql, } else { pVal->value.pData = taosMemoryMalloc(size); if (NULL == pVal->value.pData) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } else { memcpy(pVal->value.pData, output, size); pVal->value.nData = size; @@ -2218,7 +2218,7 @@ static int32_t parseDataFromFileImpl(SInsertParseContext* pCxt, SVnodeModifyOpSt if (NULL == pStmt->pTableCxtHashObj) { pStmt->pTableCxtHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (!pStmt->pTableCxtHashObj) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } int32_t numOfRows = 0; @@ -2351,20 +2351,20 @@ static int32_t constructStbRowsDataContext(SVnodeModifyOpStmt* pStmt, SStbRowsDa pStbRowsCxt->aTagNames = taosArrayInit(8, TSDB_COL_NAME_LEN); if (!pStbRowsCxt->aTagNames) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } } if (TSDB_CODE_SUCCESS == code) { pStbRowsCxt->aTagVals = taosArrayInit(8, sizeof(STagVal)); if (!pStbRowsCxt->aTagVals) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } } if (TSDB_CODE_SUCCESS == code) { // col values and bound cols info of STableDataContext is not used pStbRowsCxt->aColVals = taosArrayInit(getNumOfColumns(pStbRowsCxt->pStbMeta), sizeof(SColVal)); if (!pStbRowsCxt->aColVals) - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } if (TSDB_CODE_SUCCESS == code) { code = insInitColValues(pStbRowsCxt->pStbMeta, pStbRowsCxt->aColVals); @@ -2539,7 +2539,7 @@ static int32_t checkTableClauseFirstToken(SInsertParseContext* pCxt, SVnodeModif static int32_t setStmtInfo(SInsertParseContext* pCxt, SVnodeModifyOpStmt* pStmt) { SBoundColInfo* tags = taosMemoryMalloc(sizeof(pCxt->tags)); if (NULL == tags) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(tags, &pCxt->tags, sizeof(pCxt->tags)); @@ -2726,13 +2726,13 @@ static int32_t addTableVgroupFromMetaData(const SArray* pTables, SVnodeModifyOpS static int32_t buildTagNameFromMeta(STableMeta* pMeta, SArray** pTagName) { *pTagName = taosArrayInit(pMeta->tableInfo.numOfTags, TSDB_COL_NAME_LEN); if (NULL == *pTagName) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SSchema* pSchema = getTableTagSchema(pMeta); int32_t code = 0; for (int32_t i = 0; i < pMeta->tableInfo.numOfTags; ++i) { if (NULL == taosArrayPush(*pTagName, pSchema[i].name)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; taosArrayDestroy(*pTagName); *pTagName = NULL; break; @@ -2872,12 +2872,12 @@ static int32_t setRefreshMeta(SQuery* pQuery) { taosArrayDestroy(pQuery->pTableList); pQuery->pTableList = taosArrayInit(taosHashGetSize(pStmt->pTableNameHashObj), sizeof(SName)); if (!pQuery->pTableList) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } else { SName* pTable = taosHashIterate(pStmt->pTableNameHashObj, NULL); while (NULL != pTable) { if (NULL == taosArrayPush(pQuery->pTableList, pTable)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; taosHashCancelIterate(pStmt->pTableNameHashObj, pTable); break; } @@ -2890,12 +2890,12 @@ static int32_t setRefreshMeta(SQuery* pQuery) { taosArrayDestroy(pQuery->pDbList); pQuery->pDbList = taosArrayInit(taosHashGetSize(pStmt->pDbFNameHashObj), TSDB_DB_FNAME_LEN); if (!pQuery->pDbList) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } else { char* pDb = taosHashIterate(pStmt->pDbFNameHashObj, NULL); while (NULL != pDb) { if (NULL == taosArrayPush(pQuery->pDbList, pDb)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; taosHashCancelIterate(pStmt->pDbFNameHashObj, pDb); break; } @@ -2970,13 +2970,13 @@ static int32_t parseInsertSqlImpl(SInsertParseContext* pCxt, SVnodeModifyOpStmt* static int32_t buildInsertTableReq(SName* pName, SArray** pTables) { *pTables = taosArrayInit(1, sizeof(SName)); if (NULL == *pTables) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (NULL == taosArrayPush(*pTables, pName)) { taosArrayDestroy(*pTables); *pTables = NULL; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return TSDB_CODE_SUCCESS; } @@ -2985,7 +2985,7 @@ static int32_t buildInsertDbReq(SName* pName, SArray** pDbs) { if (NULL == *pDbs) { *pDbs = taosArrayInit(1, sizeof(STablesReq)); if (NULL == *pDbs) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -3002,7 +3002,7 @@ static int32_t buildInsertDbReq(SName* pName, SArray** pDbs) { static int32_t buildInsertUserAuthReq(const char* pUser, SName* pName, SArray** pUserAuth) { *pUserAuth = taosArrayInit(1, sizeof(SUserAuthInfo)); if (NULL == *pUserAuth) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SUserAuthInfo userAuth = {.type = AUTH_TYPE_WRITE}; @@ -3011,7 +3011,7 @@ static int32_t buildInsertUserAuthReq(const char* pUser, SName* pName, SArray** if (NULL == taosArrayPush(*pUserAuth, &userAuth)) { taosArrayDestroy(*pUserAuth); *pUserAuth = NULL; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return TSDB_CODE_SUCCESS; diff --git a/source/libs/parser/src/parInsertStmt.c b/source/libs/parser/src/parInsertStmt.c index ec4a6ee0e7..500d0e213e 100644 --- a/source/libs/parser/src/parInsertStmt.c +++ b/source/libs/parser/src/parInsertStmt.c @@ -46,7 +46,7 @@ int32_t qCloneCurrentTbData(STableDataCxt* pDataBlock, SSubmitTbData** pData) { } pNew->aCol = taosArrayDup(pDataBlock->pData->aCol, NULL); if (!pNew->aCol) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; taosMemoryFreeClear(*pData); return code; } @@ -166,7 +166,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const ch } } if (NULL == taosArrayPush(tagName, pTagSchema->name)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } if (pTagSchema->type == TSDB_DATA_TYPE_JSON) { @@ -178,7 +178,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const ch isJson = true; char* tmp = taosMemoryCalloc(1, colLen + 1); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } memcpy(tmp, bind[c].buffer, colLen); @@ -219,7 +219,7 @@ int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const ch memcpy(&val.i64, bind[c].buffer, colLen); } if (NULL == taosArrayPush(pTagArray, &val)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } } @@ -261,7 +261,7 @@ int32_t convertStmtNcharCol(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_MULTI_BIND* if (dst->buffer_length < newBuflen) { dst->buffer = taosMemoryRealloc(dst->buffer, newBuflen); if (NULL == dst->buffer) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -269,7 +269,7 @@ int32_t convertStmtNcharCol(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_MULTI_BIND* dst->length = taosMemoryRealloc(dst->length, sizeof(int32_t) * src->num); if (NULL == dst->length) { taosMemoryFreeClear(dst->buffer); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -514,7 +514,7 @@ int32_t qBindStmtTagsValue2(void* pBlock, void* boundTags, int64_t suid, const c } } if (NULL == taosArrayPush(tagName, pTagSchema->name)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } if (pTagSchema->type == TSDB_DATA_TYPE_JSON) { @@ -526,7 +526,7 @@ int32_t qBindStmtTagsValue2(void* pBlock, void* boundTags, int64_t suid, const c isJson = true; char* tmp = taosMemoryCalloc(1, colLen + 1); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } memcpy(tmp, bind[c].buffer, colLen); @@ -567,7 +567,7 @@ int32_t qBindStmtTagsValue2(void* pBlock, void* boundTags, int64_t suid, const c memcpy(&val.i64, bind[c].buffer, colLen); } if (NULL == taosArrayPush(pTagArray, &val)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto end; } } @@ -690,12 +690,12 @@ int32_t qBindStmtStbColsValue2(void* pBlock, SArray* pCols, TAOS_STMT2_BIND* bin if (!ncharBinds) { ncharBinds = taosArrayInit(1, sizeof(ncharBind)); if (!ncharBinds) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _return; } } if (!taosArrayPush(ncharBinds, &ncharBind)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _return; } pBindInfos[c].bind = taosArrayGetLast(ncharBinds); @@ -733,7 +733,7 @@ static int32_t convertStmtNcharCol2(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_STM // if (dst->buffer_length < newBuflen) { dst->buffer = taosMemoryRealloc(dst->buffer, newBuflen); if (NULL == dst->buffer) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } //} @@ -741,7 +741,7 @@ static int32_t convertStmtNcharCol2(SMsgBuf* pMsgBuf, SSchema* pSchema, TAOS_STM dst->length = taosMemoryRealloc(dst->length, sizeof(int32_t) * src->num); if (NULL == dst->length) { taosMemoryFreeClear(dst->buffer); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -951,7 +951,7 @@ int32_t qResetStmtColumns(SArray* pCols, bool deepClear) { SColData* pCol = (SColData*)taosArrayGet(pCols, i); if (pCol == NULL) { qError("qResetStmtColumns column is NULL"); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (deepClear) { tColDataDeepClear(pCol); @@ -971,7 +971,7 @@ int32_t qResetStmtDataBlock(STableDataCxt* block, bool deepClear) { SColData* pCol = (SColData*)taosArrayGet(pBlock->pData->aCol, i); if (pCol == NULL) { qError("qResetStmtDataBlock column is NULL"); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (deepClear) { tColDataDeepClear(pCol); @@ -1000,7 +1000,7 @@ int32_t qCloneStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, bool rese void* pNewMeta = taosMemoryMalloc(TABLE_META_SIZE(pCxt->pMeta)); if (NULL == pNewMeta) { insDestroyTableDataCxt(*pDst); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(pNewMeta, pCxt->pMeta, TABLE_META_SIZE(pCxt->pMeta)); pNewCxt->pMeta = pNewMeta; @@ -1013,7 +1013,7 @@ int32_t qCloneStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, bool rese void* pNewColIdx = taosMemoryMalloc(pCxt->boundColsInfo.numOfBound * sizeof(*pCxt->boundColsInfo.pColIndex)); if (NULL == pNewColIdx) { insDestroyTableDataCxt(*pDst); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(pNewColIdx, pCxt->boundColsInfo.pColIndex, pCxt->boundColsInfo.numOfBound * sizeof(*pCxt->boundColsInfo.pColIndex)); @@ -1024,7 +1024,7 @@ int32_t qCloneStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, bool rese SSubmitTbData* pNewTb = (SSubmitTbData*)taosMemoryMalloc(sizeof(SSubmitTbData)); if (NULL == pNewTb) { insDestroyTableDataCxt(*pDst); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(pNewTb, pCxt->pData, sizeof(*pCxt->pData)); @@ -1033,7 +1033,7 @@ int32_t qCloneStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, bool rese pNewTb->aCol = taosArrayDup(pCxt->pData->aCol, NULL); if (NULL == pNewTb->aCol) { insDestroyTableDataCxt(*pDst); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pNewCxt->pData = pNewTb; diff --git a/source/libs/parser/src/parInsertUtil.c b/source/libs/parser/src/parInsertUtil.c index b3bfa3982c..4f9b46176c 100644 --- a/source/libs/parser/src/parInsertUtil.c +++ b/source/libs/parser/src/parInsertUtil.c @@ -178,7 +178,7 @@ static int32_t initColValues(STableMeta* pTableMeta, SArray* pValues) { for (int32_t i = 0; i < pTableMeta->tableInfo.numOfColumns; ++i) { SColVal val = COL_VAL_NONE(pSchemas[i].colId, pSchemas[i].type); if (NULL == taosArrayPush(pValues, &val)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } } @@ -261,7 +261,7 @@ static int32_t createTableDataCxt(STableMeta* pTableMeta, SVCreateTbReq** pCreat if (TSDB_CODE_SUCCESS == code && !ignoreColVals) { pTableCxt->pValues = taosArrayInit(pTableMeta->tableInfo.numOfColumns, sizeof(SColVal)); if (NULL == pTableCxt->pValues) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } else { code = initColValues(pTableMeta, pTableCxt->pValues); } @@ -281,12 +281,12 @@ static int32_t createTableDataCxt(STableMeta* pTableMeta, SVCreateTbReq** pCreat if (pTableCxt->pData->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) { pTableCxt->pData->aCol = taosArrayInit(128, sizeof(SColData)); if (NULL == pTableCxt->pData->aCol) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } } else { pTableCxt->pData->aRowP = taosArrayInit(128, POINTER_BYTES); if (NULL == pTableCxt->pData->aRowP) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } } } @@ -323,13 +323,13 @@ static int32_t rebuildTableData(SSubmitTbData* pSrc, SSubmitTbData** pDst) { if (pTmp->flags & SUBMIT_REQ_COLUMN_DATA_FORMAT) { pTmp->aCol = taosArrayInit(128, sizeof(SColData)); if (NULL == pTmp->aCol) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; taosMemoryFree(pTmp); } } else { pTmp->aRowP = taosArrayInit(128, POINTER_BYTES); if (NULL == pTmp->aRowP) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; taosMemoryFree(pTmp); } } @@ -458,13 +458,13 @@ static int32_t fillVgroupDataCxt(STableDataCxt* pTableCxt, SVgroupDataCxt* pVgCx if (NULL == pVgCxt->pData->aSubmitTbData) { pVgCxt->pData->aSubmitTbData = taosArrayInit(128, sizeof(SSubmitTbData)); if (NULL == pVgCxt->pData->aSubmitTbData) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } // push data to submit, rebuild empty data for next submit if (NULL == taosArrayPush(pVgCxt->pData->aSubmitTbData, pTableCxt->pData)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = 0; if (isRebuild) { @@ -494,7 +494,7 @@ static int32_t createVgroupDataCxt(STableDataCxt* pTableCxt, SHashObj* pVgroupHa int32_t code = taosHashPut(pVgroupHash, &pVgCxt->vgId, sizeof(pVgCxt->vgId), &pVgCxt, POINTER_BYTES); if (TSDB_CODE_SUCCESS == code) { if (NULL == taosArrayPush(pVgroupList, &pVgCxt)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; insDestroyVgroupDataCxt(pVgCxt); return code; } @@ -723,7 +723,7 @@ int32_t insMergeTableDataCxt(SHashObj* pTableHash, SArray** pVgDataBlocks, bool if (NULL == pVgroupHash || NULL == pVgroupList) { taosHashCleanup(pVgroupHash); taosArrayDestroy(pVgroupList); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = TSDB_CODE_SUCCESS; @@ -805,7 +805,7 @@ static int32_t buildSubmitReq(int32_t vgId, SSubmitReq2* pReq, void** pData, uin len += sizeof(SSubmitReq2Msg); pBuf = taosMemoryMalloc(len); if (NULL == pBuf) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } ((SSubmitReq2Msg*)pBuf)->header.vgId = htonl(vgId); ((SSubmitReq2Msg*)pBuf)->header.contLen = htonl(len); @@ -856,7 +856,7 @@ int32_t insBuildVgDataBlocks(SHashObj* pVgroupsHashObj, SArray* pVgDataCxtList, code = buildSubmitReq(src->vgId, src->pData, &dst->pData, &dst->size); } if (TSDB_CODE_SUCCESS == code) { - code = (NULL == taosArrayPush(pDataBlocks, &dst) ? TSDB_CODE_OUT_OF_MEMORY : TSDB_CODE_SUCCESS); + code = (NULL == taosArrayPush(pDataBlocks, &dst) ? terrno : TSDB_CODE_SUCCESS); } } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index fd121dec67..30f5433e98 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -396,7 +396,7 @@ static int32_t addNamespace(STranslateContext* pCxt, void* pTable) { if (currTotalLevel > pCxt->currLevel) { SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel); if (NULL == taosArrayPush(pTables, &pTable)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (hasSameTableAlias(pTables)) { return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_UNIQUE_TABLE_ALIAS, @@ -406,7 +406,7 @@ static int32_t addNamespace(STranslateContext* pCxt, void* pTable) { do { SArray* pTables = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES); if (NULL == pTables) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (pCxt->currLevel == currTotalLevel) { if (NULL == taosArrayPush(pTables, &pTable)) { @@ -420,7 +420,7 @@ static int32_t addNamespace(STranslateContext* pCxt, void* pTable) { } } if (NULL == taosArrayPush(pCxt->pNsLevel, &pTables)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; taosArrayDestroy(pTables); break; } @@ -478,6 +478,99 @@ static int32_t getViewMetaImpl(SParseContext* pParCxt, SParseMetaCache* pMetaCac } #endif +static int32_t getTargetNameImpl(SParseContext* pParCxt, SParseMetaCache* pMetaCache, const SName* pName, + char* pTbName) { + int32_t code = TSDB_CODE_SUCCESS; + if (pParCxt->async) { + code = getTableNameFromCache(pMetaCache, pName, pTbName); + } else { + code = TSDB_CODE_PAR_INTERNAL_ERROR; + } + if (TSDB_CODE_SUCCESS != code && TSDB_CODE_PAR_TABLE_NOT_EXIST != code) { + parserError("0x%" PRIx64 " catalogGetTableMeta error, code:%s, dbName:%s, tbName:%s", pParCxt->requestId, + tstrerror(code), pName->dbname, pName->tname); + } + return code; +} + +static int32_t getTargetName(STranslateContext* pCxt, const SName* pName, char* pTbName) { + SParseContext* pParCxt = pCxt->pParseCxt; + int32_t code = collectUseDatabase(pName, pCxt->pDbs); + if (TSDB_CODE_SUCCESS == code) { + code = collectUseTable(pName, pCxt->pTables); + } + if (TSDB_CODE_SUCCESS == code) { + code = getTargetNameImpl(pParCxt, pCxt->pMetaCache, pName, pTbName); + } + if (TSDB_CODE_SUCCESS != code && TSDB_CODE_PAR_TABLE_NOT_EXIST != code) { + parserError("0x%" PRIx64 " catalogGetTableMeta error, code:%s, dbName:%s, tbName:%s", pCxt->pParseCxt->requestId, + tstrerror(code), pName->dbname, pName->tname); + } + return code; +} + +static int32_t rewriteDropTableWithMetaCache(STranslateContext* pCxt) { + int32_t code = TSDB_CODE_SUCCESS; + SParseContext* pParCxt = pCxt->pParseCxt; + SParseMetaCache* pMetaCache = pCxt->pMetaCache; + int32_t tbMetaSize = taosHashGetSize(pMetaCache->pTableMeta); + int32_t tbMetaExSize = taosHashGetSize(pMetaCache->pTableName); + + if (tbMetaSize > 0 || tbMetaExSize <= 0) { + return TSDB_CODE_PAR_INTERNAL_ERROR; + } + if (!pMetaCache->pTableMeta && + !(pMetaCache->pTableMeta = + taosHashInit(tbMetaExSize, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK))) { + return terrno; + } + + SMetaRes** ppMetaRes = NULL; + char dbName[TSDB_DB_NAME_LEN] = {0}; + while ((ppMetaRes = taosHashIterate(pMetaCache->pTableName, ppMetaRes))) { + if (!(*ppMetaRes)) { + taosHashCancelIterate(pMetaCache->pTableName, ppMetaRes); + return TSDB_CODE_PAR_INTERNAL_ERROR; + } + + char* pKey = taosHashGetKey(ppMetaRes, NULL); + STableMeta* pMeta = (STableMeta*)(*ppMetaRes)->pRes; + if (!pMeta) { + taosHashCancelIterate(pMetaCache->pTableName, ppMetaRes); + return TSDB_CODE_PAR_INTERNAL_ERROR; + } + char* pDbStart = strstr(pKey, "."); + char* pDbEnd = pDbStart ? strstr(pDbStart + 1, ".") : NULL; + if (!pDbEnd) { + taosHashCancelIterate(pMetaCache->pTableName, ppMetaRes); + return TSDB_CODE_PAR_INTERNAL_ERROR; + } + tstrncpy(dbName, pDbStart + 1, pDbEnd - pDbStart); + + int32_t metaSize = + sizeof(STableMeta) + sizeof(SSchema) * (pMeta->tableInfo.numOfColumns + pMeta->tableInfo.numOfTags); + int32_t schemaExtSize = + (useCompress(pMeta->tableType) && pMeta->schemaExt) ? sizeof(SSchemaExt) * pMeta->tableInfo.numOfColumns : 0; + const char* pTbName = (const char*)pMeta + metaSize + schemaExtSize; + + SName name = {0}; + toName(pParCxt->acctId, dbName, pTbName, &name); + + char fullName[TSDB_TABLE_FNAME_LEN]; + code = tNameExtractFullName(&name, fullName); + if (TSDB_CODE_SUCCESS != code) { + taosHashCancelIterate(pMetaCache->pTableName, ppMetaRes); + return code; + } + + if ((code = taosHashPut(pMetaCache->pTableMeta, fullName, strlen(fullName), ppMetaRes, POINTER_BYTES))) { + taosHashCancelIterate(pMetaCache->pTableName, ppMetaRes); + return code; + } + } + return code; +} + int32_t getTargetMetaImpl(SParseContext* pParCxt, SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta, bool couldBeView) { int32_t code = TSDB_CODE_SUCCESS; @@ -617,7 +710,11 @@ static int32_t getTableHashVgroupImpl(STranslateContext* pCxt, const SName* pNam } if (TSDB_CODE_SUCCESS == code) { if (pParCxt->async) { - code = getTableVgroupFromCache(pCxt->pMetaCache, pName, pInfo); + if(pCxt->withOpt) { + code = getDbTableVgroupFromCache(pCxt->pMetaCache, pName, pInfo); + } else { + code = getTableVgroupFromCache(pCxt->pMetaCache, pName, pInfo); + } } else { SRequestConnInfo conn = {.pTrans = pParCxt->pTransporter, .requestId = pParCxt->requestId, @@ -811,7 +908,7 @@ static int32_t initTranslateContext(SParseContext* pParseCxt, SParseMetaCache* p pCxt->pTables = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); pCxt->pTargetTables = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (NULL == pCxt->pNsLevel || NULL == pCxt->pDbs || NULL == pCxt->pTables || NULL == pCxt->pTargetTables) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return TSDB_CODE_SUCCESS; } @@ -833,7 +930,7 @@ static int32_t resetHighLevelTranslateNamespace(STranslateContext* pCxt) { } pCxt->pNsLevel = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES); if (NULL == pCxt->pNsLevel) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return TSDB_CODE_SUCCESS; } @@ -848,7 +945,7 @@ static int32_t resetTranslateNamespace(STranslateContext* pCxt) { } pCxt->pNsLevel = taosArrayInit(TARRAY_MIN_SIZE, POINTER_BYTES); if (NULL == pCxt->pNsLevel) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return TSDB_CODE_SUCCESS; } @@ -1208,7 +1305,7 @@ static int32_t setColumnInfoByExpr(STempTableNode* pTable, SExprNode* pExpr, SCo if (NULL == pExpr->pAssociation) { pExpr->pAssociation = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SAssociationNode)); - if (!pExpr->pAssociation) return TSDB_CODE_OUT_OF_MEMORY; + if (!pExpr->pAssociation) return terrno; } SAssociationNode assNode; assNode.pPlace = (SNode**)pColRef; @@ -1990,7 +2087,7 @@ static EDealRes translateNormalValue(STranslateContext* pCxt, SValueNode* pVal, pVal->datum.p = taosMemoryCalloc(1, size + VARSTR_HEADER_SIZE); if (NULL == pVal->datum.p) { if (isHexChar) taosMemoryFree(data); - return generateDealNodeErrMsg(pCxt, TSDB_CODE_OUT_OF_MEMORY); + return generateDealNodeErrMsg(pCxt, terrno); } varDataSetLen(pVal->datum.p, size); memcpy(varDataVal(pVal->datum.p), data, size); @@ -2006,7 +2103,7 @@ static EDealRes translateNormalValue(STranslateContext* pCxt, SValueNode* pVal, int32_t len = TMIN(targetDt.bytes - VARSTR_HEADER_SIZE, vlen); pVal->datum.p = taosMemoryCalloc(1, len + VARSTR_HEADER_SIZE + 1); if (NULL == pVal->datum.p) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_OUT_OF_MEMORY); + return generateDealNodeErrMsg(pCxt, terrno); } varDataSetLen(pVal->datum.p, len); strncpy(varDataVal(pVal->datum.p), pVal->literal, len); @@ -2022,7 +2119,7 @@ static EDealRes translateNormalValue(STranslateContext* pCxt, SValueNode* pVal, case TSDB_DATA_TYPE_NCHAR: { pVal->datum.p = taosMemoryCalloc(1, targetDt.bytes + 1); if (NULL == pVal->datum.p) { - return generateDealNodeErrMsg(pCxt, TSDB_CODE_OUT_OF_MEMORY); + return generateDealNodeErrMsg(pCxt, terrno); } int32_t len = 0; @@ -2700,7 +2797,7 @@ static int32_t rewriteDatabaseFunc(STranslateContext* pCxt, SNode** pNode) { if (NULL != pCxt->pParseCxt->db) { pCurrDb = taosStrdup((void*)pCxt->pParseCxt->db); if (NULL == pCurrDb) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } int32_t code = rewriteFuncToValue(pCxt, &pCurrDb, pNode); @@ -2711,7 +2808,7 @@ static int32_t rewriteDatabaseFunc(STranslateContext* pCxt, SNode** pNode) { static int32_t rewriteClentVersionFunc(STranslateContext* pCxt, SNode** pNode) { char* pVer = taosStrdup((void*)version); if (NULL == pVer) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = rewriteFuncToValue(pCxt, &pVer, pNode); if (TSDB_CODE_SUCCESS != code) taosMemoryFree(pVer); @@ -2721,7 +2818,7 @@ static int32_t rewriteClentVersionFunc(STranslateContext* pCxt, SNode** pNode) { static int32_t rewriteServerVersionFunc(STranslateContext* pCxt, SNode** pNode) { char* pVer = taosStrdup((void*)pCxt->pParseCxt->svrVer); if (NULL == pVer) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = rewriteFuncToValue(pCxt, &pVer, pNode); if (TSDB_CODE_SUCCESS != code) taosMemoryFree(pVer); @@ -2749,7 +2846,7 @@ static int32_t rewriteUserFunc(STranslateContext* pCxt, SNode** pNode) { } char* pUserConn = taosStrdup((void*)userConn); if (NULL == pUserConn) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = rewriteFuncToValue(pCxt, &pUserConn, pNode); if (TSDB_CODE_SUCCESS != code) { @@ -3795,13 +3892,13 @@ static int32_t addMnodeToVgroupList(const SEpSet* pEpSet, SArray** pVgroupList) if (NULL == *pVgroupList) { *pVgroupList = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SVgroupInfo)); if (NULL == *pVgroupList) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } SVgroupInfo vg = {.vgId = MNODE_HANDLE}; memcpy(&vg.epSet, pEpSet, sizeof(SEpSet)); if (NULL == taosArrayPush(*pVgroupList, &vg)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return TSDB_CODE_SUCCESS; } @@ -3853,10 +3950,10 @@ static int32_t getVnodeSysTableVgroupListImpl(STranslateContext* pCxt, SName* pT if (TSDB_CODE_SUCCESS == code) { *pVgroupList = taosArrayInit(1, sizeof(SVgroupInfo)); if (NULL == *pVgroupList) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } else { if (NULL == taosArrayPush(*pVgroupList, &vgInfo)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } } } else if (TSDB_CODE_MND_DB_NOT_EXIST == code || TSDB_CODE_MND_DB_IN_CREATING == code || @@ -4040,7 +4137,7 @@ static int32_t setTableTsmas(STranslateContext* pCxt, SName* pName, SRealTableNo if (!pRealTable->tsmaTargetTbVgInfo) { pRealTable->tsmaTargetTbVgInfo = taosArrayInit(pRealTable->pTsmas->size, POINTER_BYTES); if (!pRealTable->tsmaTargetTbVgInfo) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } } @@ -4071,7 +4168,7 @@ static int32_t setTableTsmas(STranslateContext* pCxt, SName* pName, SRealTableNo if (!pRealTable->tsmaTargetTbInfo) { pRealTable->tsmaTargetTbInfo = taosArrayInit(pRealTable->pTsmas->size, sizeof(STsmaTargetTbInfo)); if (!pRealTable->tsmaTargetTbInfo) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } } @@ -5185,7 +5282,7 @@ static int32_t rewriteProjectAlias(SNodeList* pProjectionList) { static int32_t checkProjectAlias(STranslateContext* pCxt, SNodeList* pProjectionList, SHashObj** pOutput) { SHashObj* pUserAliasSet = taosHashInit(LIST_LENGTH(pProjectionList), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); - if (!pUserAliasSet) return TSDB_CODE_OUT_OF_MEMORY; + if (!pUserAliasSet) return terrno; SNode* pProject = NULL; int32_t code = TSDB_CODE_SUCCESS; FOREACH(pProject, pProjectionList) { @@ -6089,7 +6186,7 @@ static int32_t isOperatorTbnameInCond(STranslateContext* pCxt, SOperatorNode* pO } SNodeListNode* pValueListNode = (SNodeListNode*)pOperator->pRight; *ppTbNames = taosArrayInit(LIST_LENGTH(pValueListNode->pNodeList), sizeof(void*)); - if (!*ppTbNames) return TSDB_CODE_OUT_OF_MEMORY; + if (!*ppTbNames) return terrno; SNodeList* pValueNodeList = pValueListNode->pNodeList; SNode* pValNode = NULL; FOREACH(pValNode, pValueNodeList) { @@ -6159,7 +6256,7 @@ static int32_t findEqualCondTbnameInLogicCondAnd(STranslateContext* pCxt, SNode* if (!isTableExistInTableTbnames(aTableTbnames, info.pRealTable)) { // TODO: intersect tbNames of same table? speed if (NULL == taosArrayPush(aTableTbnames, &info)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } } else { @@ -6179,7 +6276,7 @@ static int32_t unionEqualCondTbnamesOfSameTable(SArray* aTableTbnames, SEqCondTb SEqCondTbNameTableInfo* info = taosArrayGet(aTableTbnames, i); if (info->pRealTable == pInfo->pRealTable) { if (NULL == taosArrayAddAll(info->aTbnames, pInfo->aTbnames)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } taosArrayDestroy(pInfo->aTbnames); @@ -6190,7 +6287,7 @@ static int32_t unionEqualCondTbnamesOfSameTable(SArray* aTableTbnames, SEqCondTb } if (TSDB_CODE_SUCCESS == code && !bFoundTable) { if (NULL == taosArrayPush(aTableTbnames, pInfo)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } } return code; @@ -6240,7 +6337,7 @@ static int32_t findEqualCondTbname(STranslateContext* pCxt, SNode* pWhere, SArra if (TSDB_CODE_SUCCESS != code) return code; if (bIsEqTbnameCond) { if (NULL == taosArrayPush(aTableTbnames, &info)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } } else if (nodeType(pWhere) == QUERY_NODE_LOGIC_CONDITION) { @@ -6375,12 +6472,12 @@ static int32_t setEqualTbnameTableVgroups(STranslateContext* pCxt, SSelectStmt* if (pInfo->pRealTable->pTsmas) { pInfo->pRealTable->tsmaTargetTbVgInfo = taosArrayInit(pInfo->pRealTable->pTsmas->size, POINTER_BYTES); - if (!pInfo->pRealTable->tsmaTargetTbVgInfo) return TSDB_CODE_OUT_OF_MEMORY; + if (!pInfo->pRealTable->tsmaTargetTbVgInfo) return terrno; for (int32_t i = 0; i < pInfo->pRealTable->pTsmas->size; ++i) { STableTSMAInfo* pTsma = taosArrayGetP(pInfo->pRealTable->pTsmas, i); SArray* pTbNames = taosArrayInit(pInfo->aTbnames->size, POINTER_BYTES); - if (!pTbNames) return TSDB_CODE_OUT_OF_MEMORY; + if (!pTbNames) return terrno; for (int32_t k = 0; k < pInfo->aTbnames->size; ++k) { const char* pTbName = taosArrayGetP(pInfo->aTbnames, k); @@ -6399,7 +6496,7 @@ static int32_t setEqualTbnameTableVgroups(STranslateContext* pCxt, SSelectStmt* } if (TSDB_CODE_SUCCESS == code) { vgsInfo = taosMemoryMalloc(sizeof(SVgroupsInfo) + nTbls * sizeof(SVgroupInfo)); - if (!vgsInfo) code = TSDB_CODE_OUT_OF_MEMORY; + if (!vgsInfo) code = terrno; } if (TSDB_CODE_SUCCESS == code) { findVgroupsFromEqualTbname(pCxt, pTbNames, pInfo->pRealTable->table.dbName, numOfVgs, vgsInfo); @@ -6656,7 +6753,6 @@ static EDealRes replaceOrderByAliasImpl(SNode** pNode, void* pContext) { pCxt->pTranslateCxt->errCode = code; return DEAL_RES_ERROR; } - ((SExprNode*)pNew)->orderAlias = true; nodesDestroyNode(*pNode); *pNode = pNew; return DEAL_RES_CONTINUE; @@ -6680,7 +6776,6 @@ static EDealRes replaceOrderByAliasImpl(SNode** pNode, void* pContext) { pCxt->pTranslateCxt->errCode = code; return DEAL_RES_ERROR; } - ((SExprNode*)pNew)->orderAlias = true; ((SOrderByExprNode*)*pNode)->pExpr = pNew; nodesDestroyNode(pExpr); return DEAL_RES_CONTINUE; @@ -7067,7 +7162,6 @@ static int32_t addOrderByPrimaryKeyToQueryImpl(STranslateContext* pCxt, SNode* p nodesDestroyNode((SNode*)pOrderByExpr); return code; } - ((SExprNode*)pOrderByExpr->pExpr)->orderAlias = true; // NODES_DESTORY_LIST(*pOrderByList); return nodesListMakeStrictAppend(pOrderByList, (SNode*)pOrderByExpr); } @@ -7176,7 +7270,7 @@ static int32_t buildCreateDbRetentions(const SNodeList* pRetentions, SCreateDbRe if (NULL != pRetentions) { pReq->pRetensions = taosArrayInit(LIST_LENGTH(pRetentions), sizeof(SRetention)); if (NULL == pReq->pRetensions) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SValueNode* pFreq = NULL; SValueNode* pKeep = NULL; @@ -7188,7 +7282,7 @@ static int32_t buildCreateDbRetentions(const SNodeList* pRetentions, SCreateDbRe SRetention retention = { .freq = pFreq->datum.i, .freqUnit = pFreq->unit, .keep = pKeep->datum.i, .keepUnit = pKeep->unit}; if (NULL == taosArrayPush(pReq->pRetensions, &retention)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } } @@ -7733,7 +7827,7 @@ static int32_t checkCreateDatabase(STranslateContext* pCxt, SCreateDatabaseStmt* CMD_TYPE* pCmdReq = genericCmd; \ char* cmdSql = taosMemoryMalloc(sqlLen); \ if (cmdSql == NULL) { \ - return TSDB_CODE_OUT_OF_MEMORY; \ + return terrno; \ } \ memcpy(cmdSql, sql, sqlLen); \ pCmdReq->sqlLen = sqlLen; \ @@ -7869,7 +7963,7 @@ static int32_t buildCmdMsg(STranslateContext* pCxt, int16_t msgType, FSerializeF if (TSDB_CODE_SUCCESS != code) return code; pCxt->pCmdMsg = taosMemoryMalloc(sizeof(SCmdMsgInfo)); if (NULL == pCxt->pCmdMsg) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet; pCxt->pCmdMsg->msgType = msgType; @@ -7880,7 +7974,7 @@ static int32_t buildCmdMsg(STranslateContext* pCxt, int16_t msgType, FSerializeF pCxt->pCmdMsg->pMsg = taosMemoryMalloc(pCxt->pCmdMsg->msgLen); if (NULL == pCxt->pCmdMsg->pMsg) { taosMemoryFreeClear(pCxt->pCmdMsg); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (-1 == func(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, pReq)) { code = TSDB_CODE_INVALID_MSG; @@ -8020,7 +8114,7 @@ static int32_t translateS3MigrateDatabase(STranslateContext* pCxt, SS3MigrateDat static int32_t columnDefNodeToField(SNodeList* pList, SArray** pArray, bool calBytes) { *pArray = taosArrayInit(LIST_LENGTH(pList), sizeof(SFieldWithOptions)); - if (!pArray) return TSDB_CODE_OUT_OF_MEMORY; + if (!pArray) return terrno; int32_t code = TSDB_CODE_SUCCESS; SNode* pNode; @@ -8046,7 +8140,7 @@ static int32_t columnDefNodeToField(SNodeList* pList, SArray** pArray, bool calB field.flags |= COL_IS_KEY; } if (NULL == taosArrayPush(*pArray, &field)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } } @@ -8059,7 +8153,7 @@ static int32_t columnDefNodeToField(SNodeList* pList, SArray** pArray, bool calB static int32_t tagDefNodeToField(SNodeList* pList, SArray** pArray, bool calBytes) { *pArray = taosArrayInit(LIST_LENGTH(pList), sizeof(SField)); - if (!*pArray) return TSDB_CODE_OUT_OF_MEMORY; + if (!*pArray) return terrno; SNode* pNode; FOREACH(pNode, pList) { SColumnDefNode* pCol = (SColumnDefNode*)pNode; @@ -8292,7 +8386,7 @@ static int32_t checkTableSchemaImpl(STranslateContext* pCxt, SNodeList* pTags, S SHashObj* pHash = taosHashInit(LIST_LENGTH(pTags) + LIST_LENGTH(pCols), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); if (NULL == pHash) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = checkTableTagsSchema(pCxt, pHash, pTags); @@ -8819,7 +8913,7 @@ static int32_t buildRollupFuncs(SNodeList* pFuncs, SArray** pArray) { return TSDB_CODE_SUCCESS; } *pArray = taosArrayInit(LIST_LENGTH(pFuncs), TSDB_FUNC_NAME_LEN); - if (!*pArray) return TSDB_CODE_OUT_OF_MEMORY; + if (!*pArray) return terrno; SNode* pNode; FOREACH(pNode, pFuncs) { if (NULL == taosArrayPush(*pArray, ((SFunctionNode*)pNode)->functionName)) { @@ -8855,7 +8949,7 @@ static int32_t buildCreateStbReq(STranslateContext* pCxt, SCreateTableStmt* pStm if (pStmt->pOptions->commentNull == false) { pReq->pComment = taosStrdup(pStmt->pOptions->comment); if (NULL == pReq->pComment) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pReq->commentLen = strlen(pStmt->pOptions->comment); } else { @@ -8932,7 +9026,7 @@ static int32_t buildAlterSuperTableReq(STranslateContext* pCxt, SAlterTableStmt* if (pStmt->pOptions->commentNull == false) { pAlterReq->comment = taosStrdup(pStmt->pOptions->comment); if (NULL == pAlterReq->comment) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pAlterReq->commentLen = strlen(pStmt->pOptions->comment); } else { @@ -8944,7 +9038,7 @@ static int32_t buildAlterSuperTableReq(STranslateContext* pCxt, SAlterTableStmt* pAlterReq->pFields = taosArrayInit(2, sizeof(TAOS_FIELD)); if (NULL == pAlterReq->pFields) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } switch (pStmt->alterType) { @@ -8957,7 +9051,7 @@ static int32_t buildAlterSuperTableReq(STranslateContext* pCxt, SAlterTableStmt* TAOS_FIELD field = {.type = pStmt->dataType.type, .bytes = calcTypeBytes(pStmt->dataType)}; strcpy(field.name, pStmt->colName); if (NULL == taosArrayPush(pAlterReq->pFields, &field)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } break; } @@ -8966,12 +9060,12 @@ static int32_t buildAlterSuperTableReq(STranslateContext* pCxt, SAlterTableStmt* TAOS_FIELD oldField = {0}; strcpy(oldField.name, pStmt->colName); if (NULL == taosArrayPush(pAlterReq->pFields, &oldField)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } TAOS_FIELD newField = {0}; strcpy(newField.name, pStmt->newColName); if (NULL == taosArrayPush(pAlterReq->pFields, &newField)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } break; } @@ -8989,7 +9083,7 @@ static int32_t buildAlterSuperTableReq(STranslateContext* pCxt, SAlterTableStmt* return code; } if (NULL == taosArrayPush(pAlterReq->pFields, &field)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } break; } @@ -8997,7 +9091,7 @@ static int32_t buildAlterSuperTableReq(STranslateContext* pCxt, SAlterTableStmt* taosArrayDestroy(pAlterReq->pFields); pAlterReq->pFields = taosArrayInit(1, sizeof(SFieldWithOptions)); - if (!pAlterReq->pFields) return TSDB_CODE_OUT_OF_MEMORY; + if (!pAlterReq->pFields) return terrno; SFieldWithOptions field = {.type = pStmt->dataType.type, .bytes = calcTypeBytes(pStmt->dataType)}; // TAOS_FIELD field = {.type = pStmt->dataType.type, .bytes = calcTypeBytes(pStmt->dataType)}; strcpy(field.name, pStmt->colName); @@ -9016,7 +9110,7 @@ static int32_t buildAlterSuperTableReq(STranslateContext* pCxt, SAlterTableStmt* return code; } } - if (NULL == taosArrayPush(pAlterReq->pFields, &field)) return TSDB_CODE_OUT_OF_MEMORY; + if (NULL == taosArrayPush(pAlterReq->pFields, &field)) return terrno; break; } default: @@ -9411,7 +9505,7 @@ static int32_t getSmaIndexDstVgId(STranslateContext* pCxt, const char* pDbName, static int32_t getSmaIndexSql(STranslateContext* pCxt, char** pSql, int32_t* pLen) { *pSql = taosStrdup(pCxt->pParseCxt->pSql); if (NULL == *pSql) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } *pLen = pCxt->pParseCxt->sqlLen + 1; return TSDB_CODE_SUCCESS; @@ -9751,7 +9845,7 @@ static int32_t buildCreateTopicReq(STranslateContext* pCxt, SCreateTopicStmt* pS pReq->sql = taosStrdup(pCxt->pParseCxt->pSql); if (NULL == pReq->sql) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = TSDB_CODE_SUCCESS; @@ -10595,6 +10689,10 @@ static int32_t checkStreamQuery(STranslateContext* pCxt, SCreateStreamStmt* pStm } } + if (NULL != pSelect->pGroupByList) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY, "Unsupported Group by"); + } + return TSDB_CODE_SUCCESS; } @@ -10669,7 +10767,7 @@ static int32_t addProjToProjColPos(STranslateContext* pCxt, const SSchema* pSche } if (TSDB_CODE_SUCCESS == code) { SProjColPos pos = {.colId = pSchema->colId, .pProj = pNewProj, .flags = pSchema->flags}; - code = (NULL == taosArrayPush(pProjColPos, &pos) ? TSDB_CODE_OUT_OF_MEMORY : TSDB_CODE_SUCCESS); + code = (NULL == taosArrayPush(pProjColPos, &pos) ? terrno : TSDB_CODE_SUCCESS); } if (TSDB_CODE_SUCCESS != code) { nodesDestroyNode(pNewProj); @@ -10681,7 +10779,7 @@ static int32_t setFillNullCols(SArray* pProjColPos, const STableMeta* pMeta, SCM int32_t numOfBoundCols = taosArrayGetSize(pProjColPos); pReq->fillNullCols = taosArrayInit(pMeta->tableInfo.numOfColumns - numOfBoundCols, sizeof(SColLocation)); if (NULL == pReq->fillNullCols) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } const SSchema* pSchemas = getTableColumnSchema(pMeta); int32_t indexOfBoundCols = 0; @@ -10697,7 +10795,7 @@ static int32_t setFillNullCols(SArray* pProjColPos, const STableMeta* pMeta, SCM } SColLocation colLoc = {.colId = pSchema->colId, .slotId = i, .type = pSchema->type}; if (NULL == taosArrayPush(pReq->fillNullCols, &colLoc)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } } @@ -10712,7 +10810,7 @@ static int32_t adjustOrderOfProjections(STranslateContext* pCxt, SNodeList** ppC SArray* pProjColPos = taosArrayInit(LIST_LENGTH((*ppCols)), sizeof(SProjColPos)); if (NULL == pProjColPos) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = TSDB_CODE_SUCCESS; @@ -10839,7 +10937,7 @@ static int32_t adjustOrderOfTags(STranslateContext* pCxt, SNodeList* pTags, cons SArray* pTagPos = taosArrayInit(LIST_LENGTH(pTags), sizeof(SProjColPos)); if (NULL == pTagPos) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = TSDB_CODE_SUCCESS; @@ -11244,7 +11342,7 @@ static int32_t buildCreateStreamReq(STranslateContext* pCxt, SCreateStreamStmt* if (TSDB_CODE_SUCCESS == code) { pReq->sql = taosStrdup(pCxt->pParseCxt->pSql); if (NULL == pReq->sql) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } } @@ -11286,7 +11384,7 @@ static int32_t translateCreateStream(STranslateContext* pCxt, SCreateStreamStmt* } else { pStmt->pReq = taosMemoryMalloc(sizeof(createReq)); if (NULL == pStmt->pReq) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } else { memcpy(pStmt->pReq, &createReq, sizeof(createReq)); memset(&createReq, 0, sizeof(createReq)); @@ -11325,7 +11423,7 @@ static int32_t buildIntervalForCreateStream(SCreateStreamStmt* pStmt, SInterval* static int32_t createStreamReqVersionInfo(SSDataBlock* pBlock, SArray** pArray, int64_t* lastTs, SInterval* pInterval) { *pArray = taosArrayInit(pBlock->info.rows, sizeof(SVgroupVer)); if (*pArray == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (pBlock->info.rows > 0) { @@ -11890,7 +11988,7 @@ static int32_t buildTSMAAstStreamSubTable(SCreateTSMAStmt* pStmt, SMCreateSmaReq sprintf(pConcatFunc->functionName, "%s", "concat"); pVal->literal = taosMemoryMalloc(TSDB_TABLE_FNAME_LEN + 1); if (!pVal->literal) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _end; } sprintf(pVal->literal, "%s_", pReq->name); @@ -13410,7 +13508,7 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* req.comment = taosStrdup(pStmt->pOptions->comment); if (NULL == req.comment) { tdDestroySVCreateTbReq(&req); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } req.commentLen = strlen(pStmt->pOptions->comment); } else { @@ -13455,11 +13553,11 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* pBatch->req.pArray = taosArrayInit(1, sizeof(struct SVCreateTbReq)); if (NULL == pBatch->req.pArray) { tdDestroySVCreateTbReq(&req); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (NULL == taosArrayPush(pBatch->req.pArray, &req)) { tdDestroySVCreateTbReq(&req); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return TSDB_CODE_SUCCESS; @@ -13481,7 +13579,7 @@ static int32_t serializeVgroupCreateTableBatch(SVgroupCreateTableBatch* pTbBatch tlen += sizeof(SMsgHead); void* buf = taosMemoryMalloc(tlen); if (NULL == buf) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } ((SMsgHead*)buf)->vgId = htonl(pTbBatch->info.vgId); ((SMsgHead*)buf)->contLen = htonl(tlen); @@ -13505,7 +13603,7 @@ static int32_t serializeVgroupCreateTableBatch(SVgroupCreateTableBatch* pTbBatch pVgData->size = tlen; pVgData->numOfTables = (int32_t)taosArrayGetSize(pTbBatch->req.pArray); if (NULL == taosArrayPush(pBufArray, &pVgData)) { - ret = TSDB_CODE_OUT_OF_MEMORY; + ret = terrno; taosMemoryFreeClear(buf); taosMemoryFreeClear(pVgData); } @@ -13551,7 +13649,7 @@ static int32_t buildCreateTableDataBlock(int32_t acctId, const SCreateTableStmt* SArray** pBufArray) { *pBufArray = taosArrayInit(1, POINTER_BYTES); if (NULL == *pBufArray) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SVgroupCreateTableBatch tbatch = {0}; @@ -13634,7 +13732,7 @@ static int32_t addCreateTbReqIntoVgroup(SHashObj* pVgroupHashmap, const char* db code = terrno; } else if (NULL == taosArrayPush(tBatch.req.pArray, &req)) { taosArrayDestroy(tBatch.req.pArray); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } else { code = taosHashPut(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId), &tBatch, sizeof(tBatch)); if (TSDB_CODE_SUCCESS != code) { @@ -13643,7 +13741,7 @@ static int32_t addCreateTbReqIntoVgroup(SHashObj* pVgroupHashmap, const char* db } } else { // add to the correct vgroup if (NULL == taosArrayPush(pTableBatch->req.pArray, &req)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } } @@ -13680,7 +13778,7 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla SArray* pTagArray = taosArrayInit(LIST_LENGTH(pStmt->pValsOfTags), sizeof(STagVal)); if (NULL == pTagArray) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = TSDB_CODE_SUCCESS; @@ -13747,7 +13845,7 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau SArray* pTagArray = taosArrayInit(LIST_LENGTH(pStmt->pValsOfTags), sizeof(STagVal)); if (NULL == pTagArray) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = TSDB_CODE_SUCCESS; @@ -13863,7 +13961,7 @@ static int32_t buildTagIndexForBindTags(SMsgBuf* pMsgBuf, SCreateSubTableFromFil SHashObj* pIdxHash = taosHashInit(16, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); if (NULL == pIdxHash) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } bool tbnameFound = false; @@ -13919,7 +14017,7 @@ static int32_t buildTagIndexForBindTags(SMsgBuf* pMsgBuf, SCreateSubTableFromFil } if (NULL == taosArrayPush(aTagIndexs, &idx)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OUT; } } @@ -14080,7 +14178,7 @@ static int32_t parseCsvFile(SMsgBuf* pMsgBuf, SParseContext* pParseCxt, SParseFi if (NULL == taosArrayPush(pParFileCxt->aCreateTbData, &data)) { taosMemoryFreeClear(pParFileCxt->pTag); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } } else { taosMemoryFreeClear(pParFileCxt->pTag); @@ -14135,7 +14233,7 @@ static int32_t constructParseFileContext(SCreateSubTableFromFileClause* pStmt, S if (NULL == pParFileCxt->aTagNames) { pParFileCxt->aTagNames = taosArrayInit(8, TSDB_COL_NAME_LEN); if (NULL == pParFileCxt->aTagNames) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _ERR; } } @@ -14143,7 +14241,7 @@ static int32_t constructParseFileContext(SCreateSubTableFromFileClause* pStmt, S if (NULL == pParFileCxt->aCreateTbData) { pParFileCxt->aCreateTbData = taosArrayInit(16, sizeof(SCreateTableData)); if (NULL == pParFileCxt->aCreateTbData) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _ERR; } } @@ -14151,7 +14249,7 @@ static int32_t constructParseFileContext(SCreateSubTableFromFileClause* pStmt, S if (NULL == pParFileCxt->aTagIndexs) { pParFileCxt->aTagIndexs = taosArrayInit(pStmt->pSpecificTags->length, sizeof(int16_t)); if (!pParFileCxt->aTagIndexs) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _ERR; } } @@ -14159,7 +14257,7 @@ static int32_t constructParseFileContext(SCreateSubTableFromFileClause* pStmt, S if (NULL == pParFileCxt->aTagVals) { pParFileCxt->aTagVals = taosArrayInit(8, sizeof(STagVal)); if (!pParFileCxt->aTagVals) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _ERR; } } @@ -14312,7 +14410,7 @@ static int32_t rewriteCreateMultiTable(STranslateContext* pCxt, SQuery* pQuery) SHashObj* pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); if (NULL == pVgroupHashmap) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } taosHashSetFreeFp(pVgroupHashmap, destroyCreateTbReqBatch); @@ -14348,7 +14446,7 @@ static int32_t rewriteCreateTableFromFile(STranslateContext* pCxt, SQuery* pQuer pModifyStmt->destroyParseFileCxt = destructParseFileContext; pModifyStmt->pVgroupsHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); if (NULL == pModifyStmt->pVgroupsHashObj) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } taosHashSetFreeFp(pModifyStmt->pVgroupsHashObj, destroyCreateTbReqBatch); @@ -14430,7 +14528,7 @@ static int32_t addDropTbReqIntoVgroup(SHashObj* pVgroupHashmap, SVgroupInfo* pVg if (NULL == taosArrayPush(tBatch.req.pArray, pReq)) { taosArrayDestroy(tBatch.req.pArray); tBatch.req.pArray = NULL; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } code = taosHashPut(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId), &tBatch, sizeof(tBatch)); @@ -14441,7 +14539,7 @@ static int32_t addDropTbReqIntoVgroup(SHashObj* pVgroupHashmap, SVgroupInfo* pVg } } else { // add to the correct vgroup if (NULL == taosArrayPush(pTableBatch->req.pArray, pReq)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } return code; @@ -14495,7 +14593,7 @@ static int32_t serializeVgroupDropTableBatch(SVgroupDropTableBatch* pTbBatch, SA tlen += sizeof(SMsgHead); void* buf = taosMemoryMalloc(tlen); if (NULL == buf) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } ((SMsgHead*)buf)->vgId = htonl(pTbBatch->info.vgId); ((SMsgHead*)buf)->contLen = htonl(tlen); @@ -14519,7 +14617,7 @@ static int32_t serializeVgroupDropTableBatch(SVgroupDropTableBatch* pTbBatch, SA pVgData->size = tlen; pVgData->numOfTables = (int32_t)taosArrayGetSize(pTbBatch->req.pArray); if (NULL == taosArrayPush(pBufArray, &pVgData)) { - ret = TSDB_CODE_OUT_OF_MEMORY; + ret = terrno; taosMemoryFreeClear(pVgData); taosMemoryFreeClear(buf); } @@ -14553,15 +14651,56 @@ int32_t serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap, SArray** pOut) return code; } +static int32_t rewriteDropTableWithOpt(STranslateContext* pCxt, SQuery* pQuery) { + int32_t code = TSDB_CODE_SUCCESS; + SDropTableStmt* pStmt = (SDropTableStmt*)pQuery->pRoot; + if (!pStmt->withOpt) return code; + pCxt->withOpt = true; + + SNode* pNode = NULL; + char pTableName[TSDB_TABLE_NAME_LEN] = {0}; + FOREACH(pNode, pStmt->pTables) { + SDropTableClause* pClause = (SDropTableClause*)pNode; + if (IS_SYS_DBNAME(pClause->dbName)) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_TSC_INVALID_OPERATION, + "Cannot drop table of system database: `%s`.`%s`", pClause->dbName, + pClause->tableName); + } + for (int32_t i = 0; i < TSDB_TABLE_NAME_LEN; i++) { + if (pClause->tableName[i] == '\0') { + break; + } + if (!isdigit(pClause->tableName[i])) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_TABLE_NOT_EXIST, "Table does not exist: `%s`.`%s`", + pClause->dbName, pClause->tableName); + } + } + SName name = {0}; + toName(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, &name); + int32_t code = getTargetName(pCxt, &name, pTableName); + if (TSDB_CODE_SUCCESS != code) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, code, "%s: db:`%s`, tbuid:`%s`", tstrerror(code), pClause->dbName, + pClause->tableName); + } + tstrncpy(pClause->tableName, pTableName, TSDB_TABLE_NAME_LEN); // rewrite table uid to table name + } + + code = rewriteDropTableWithMetaCache(pCxt); + + TAOS_RETURN(code); +} + static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) { SDropTableStmt* pStmt = (SDropTableStmt*)pQuery->pRoot; int8_t tableType; SNode* pNode; SArray* pTsmas = NULL; + TAOS_CHECK_RETURN(rewriteDropTableWithOpt(pCxt, pQuery)); + SHashObj* pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); if (NULL == pVgroupHashmap) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } taosHashSetFreeFp(pVgroupHashmap, destroyDropTbReqBatch); @@ -14575,8 +14714,10 @@ static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) { return code; } if (tableType == TSDB_SUPER_TABLE && LIST_LENGTH(pStmt->pTables) > 1) { + taosHashCleanup(pVgroupHashmap); return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DROP_STABLE); } + if (pCxt->withOpt) continue; if (pCxt->pMetaCache) code = getTableTsmasFromCache(pCxt->pMetaCache, &name, &pTsmas); if (TSDB_CODE_SUCCESS != code) { taosHashCleanup(pVgroupHashmap); @@ -14615,7 +14756,7 @@ static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) { reqOnVg.pTbs = pTbBatch->req.pArray; if (NULL == taosArrayPush(req.pVgReqs, &reqOnVg)) { taosHashCancelIterate(pVgroupHashmap, pTbBatch); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } } while (true); @@ -14638,6 +14779,50 @@ static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) { return rewriteToVnodeModifyOpStmt(pQuery, pBufArray); } +static int32_t rewriteDropSuperTablewithOpt(STranslateContext* pCxt, SQuery* pQuery) { + int32_t code = TSDB_CODE_SUCCESS; + SDropSuperTableStmt* pStmt = (SDropSuperTableStmt*)pQuery->pRoot; + if (!pStmt->withOpt) return code; + pCxt->withOpt = true; + + if (IS_SYS_DBNAME(pStmt->dbName)) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_TSC_INVALID_OPERATION, + "Cannot drop table of system database: `%s`.`%s`", pStmt->dbName, pStmt->tableName); + } + + for (int32_t i = 0; i < TSDB_TABLE_NAME_LEN; i++) { + if (pStmt->tableName[i] == '\0') { + break; + } + if (!isdigit(pStmt->tableName[i])) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_TABLE_NOT_EXIST, "STable not exist: `%s`.`%s`", + pStmt->dbName, pStmt->tableName); + } + } + + char pTableName[TSDB_TABLE_NAME_LEN] = {0}; + SName name = {0}; + toName(pCxt->pParseCxt->acctId, pStmt->dbName, pStmt->tableName, &name); + code = getTargetName(pCxt, &name, pTableName); + if (TSDB_CODE_SUCCESS != code) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, code, "%s: db:`%s`, tbuid:`%s`", + (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_TDB_TABLE_NOT_EXIST) + ? "STable not exist" + : tstrerror(code), + pStmt->dbName, pStmt->tableName); + } + tstrncpy(pStmt->tableName, pTableName, TSDB_TABLE_NAME_LEN); // rewrite table uid to table name + + code = rewriteDropTableWithMetaCache(pCxt); + + TAOS_RETURN(code); +} + +static int32_t rewriteDropSuperTable(STranslateContext* pCxt, SQuery* pQuery) { + TAOS_CHECK_RETURN(rewriteDropSuperTablewithOpt(pCxt, pQuery)); + TAOS_RETURN(0); +} + static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta, SVAlterTbReq* pReq) { SName tbName = {0}; @@ -14657,11 +14842,11 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS } pReq->tagName = taosStrdup(pStmt->colName); if (NULL == pReq->tagName) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pReq->pTagArray = taosArrayInit(1, sizeof(STagVal)); if (NULL == pReq->pTagArray) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pReq->colId = pSchema->colId; pReq->tagType = pSchema->type; @@ -14744,7 +14929,7 @@ static int32_t buildAddColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, S pReq->colName = taosStrdup(pStmt->colName); if (NULL == pReq->colName) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pReq->type = pStmt->dataType.type; @@ -14778,7 +14963,7 @@ static int32_t buildDropColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, pReq->colName = taosStrdup(pStmt->colName); if (NULL == pReq->colName) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pReq->colId = pSchema->colId; @@ -14809,7 +14994,7 @@ static int32_t buildUpdateColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt pReq->colName = taosStrdup(pStmt->colName); if (NULL == pReq->colName) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pReq->colId = pSchema->colId; @@ -14839,7 +15024,7 @@ static int32_t buildRenameColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt pReq->colName = taosStrdup(pStmt->colName); pReq->colNewName = taosStrdup(pStmt->newColName); if (NULL == pReq->colName || NULL == pReq->colNewName) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return TSDB_CODE_SUCCESS; } @@ -14856,7 +15041,7 @@ static int32_t buildUpdateOptionsReq(STranslateContext* pCxt, SAlterTableStmt* p if (pStmt->pOptions->commentNull == false) { pReq->newComment = taosStrdup(pStmt->pOptions->comment); if (NULL == pReq->newComment) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } else { pReq->newCommentLen = strlen(pReq->newComment); } @@ -14878,7 +15063,7 @@ static int buildAlterTableColumnCompress(STranslateContext* pCxt, SAlterTableStm pReq->colName = taosStrdup(pStmt->colName); pReq->colId = pSchema->colId; if (NULL == pReq->colName) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (!checkColumnEncode(pStmt->pColOptions->encode)) return TSDB_CODE_TSC_ENCODE_PARAM_ERROR; @@ -14894,7 +15079,7 @@ static int32_t buildAlterTbReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, SVAlterTbReq* pReq) { pReq->tbName = taosStrdup(pStmt->tableName); if (NULL == pReq->tbName) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pReq->action = pStmt->alterType; @@ -14946,7 +15131,7 @@ static int32_t serializeAlterTbReq(STranslateContext* pCxt, SAlterTableStmt* pSt tlen += sizeof(SMsgHead); void* pMsg = taosMemoryMalloc(tlen); if (NULL == pMsg) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } ((SMsgHead*)pMsg)->vgId = htonl(vg.vgId); ((SMsgHead*)pMsg)->contLen = htonl(tlen); @@ -14969,7 +15154,7 @@ static int32_t serializeAlterTbReq(STranslateContext* pCxt, SAlterTableStmt* pSt pVgData->size = tlen; pVgData->numOfTables = 1; if (NULL == taosArrayPush(pArray, &pVgData)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } } @@ -14980,7 +15165,7 @@ static int32_t buildModifyVnodeArray(STranslateContext* pCxt, SAlterTableStmt* p SArray** pArray) { SArray* pTmpArray = taosArrayInit(1, sizeof(void*)); if (NULL == pTmpArray) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = serializeAlterTbReq(pCxt, pStmt, pReq, pTmpArray); @@ -15059,7 +15244,7 @@ static int32_t serializeFlushVgroup(SVgroupInfo* pVg, SArray* pBufArray) { void* buf = taosMemoryMalloc(len); int32_t code = TSDB_CODE_SUCCESS; if (NULL == buf) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } ((SMsgHead*)buf)->vgId = htonl(pVg->vgId); ((SMsgHead*)buf)->contLen = htonl(len); @@ -15073,7 +15258,7 @@ static int32_t serializeFlushVgroup(SVgroupInfo* pVg, SArray* pBufArray) { pVgData->pData = buf; pVgData->size = len; if (NULL == taosArrayPush(pBufArray, &pVgData)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } return code; @@ -15084,7 +15269,7 @@ static int32_t serializeFlushDb(SArray* pVgs, SArray** pOutput) { SArray* pBufArray = taosArrayInit(numOfVgs, sizeof(void*)); if (NULL == pBufArray) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int32_t i = 0; i < numOfVgs; ++i) { @@ -15709,6 +15894,9 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { case QUERY_NODE_DROP_TABLE_STMT: code = rewriteDropTable(pCxt, pQuery); break; + case QUERY_NODE_DROP_SUPER_TABLE_STMT: + code = rewriteDropSuperTable(pCxt, pQuery); + break; case QUERY_NODE_ALTER_TABLE_STMT: code = rewriteAlterTable(pCxt, pQuery); break; @@ -15750,13 +15938,13 @@ static int32_t setRefreshMeta(STranslateContext* pCxt, SQuery* pQuery) { taosArrayDestroy(pQuery->pDbList); pQuery->pDbList = taosArrayInit(taosHashGetSize(pCxt->pDbs), TSDB_DB_FNAME_LEN); if (NULL == pQuery->pDbList) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SFullDatabaseName* pDb = taosHashIterate(pCxt->pDbs, NULL); while (NULL != pDb) { if (NULL == taosArrayPush(pQuery->pDbList, pDb->fullDbName)) { taosHashCancelIterate(pCxt->pDbs, pDb); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pDb = taosHashIterate(pCxt->pDbs, pDb); } @@ -15766,13 +15954,13 @@ static int32_t setRefreshMeta(STranslateContext* pCxt, SQuery* pQuery) { taosArrayDestroy(pQuery->pTableList); pQuery->pTableList = taosArrayInit(taosHashGetSize(pCxt->pTables), sizeof(SName)); if (NULL == pQuery->pTableList) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SName* pTable = taosHashIterate(pCxt->pTables, NULL); while (NULL != pTable) { if (NULL == taosArrayPush(pQuery->pTableList, pTable)) { taosHashCancelIterate(pCxt->pTables, pTable); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pTable = taosHashIterate(pCxt->pTables, pTable); } @@ -15782,13 +15970,13 @@ static int32_t setRefreshMeta(STranslateContext* pCxt, SQuery* pQuery) { taosArrayDestroy(pQuery->pTargetTableList); pQuery->pTargetTableList = taosArrayInit(taosHashGetSize(pCxt->pTargetTables), sizeof(SName)); if (NULL == pQuery->pTargetTableList) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SName* pTable = taosHashIterate(pCxt->pTargetTables, NULL); while (NULL != pTable) { if (NULL == taosArrayPush(pQuery->pTargetTableList, pTable)) { taosHashCancelIterate(pCxt->pTargetTables, pTable); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pTable = taosHashIterate(pCxt->pTargetTables, pTable); } diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index d17b8ac6c2..1ce8b04324 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -424,7 +424,7 @@ int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, voi keyHash = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, false); if (!keyHash) { - retCode = TSDB_CODE_OUT_OF_MEMORY; + retCode = terrno; goto end; } for (int32_t i = 0; i < size; i++) { @@ -494,7 +494,7 @@ int32_t parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, voi goto end; } if (NULL == taosArrayPush(pTagVals, &val)) { - retCode = TSDB_CODE_OUT_OF_MEMORY; + retCode = terrno; goto end; } } @@ -641,7 +641,7 @@ static int32_t buildTableReq(SHashObj* pTablesHash, SArray** pTables) { if (NULL != pTablesHash) { *pTables = taosArrayInit(taosHashGetSize(pTablesHash), sizeof(SName)); if (NULL == *pTables) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } void* p = taosHashIterate(pTablesHash, NULL); while (NULL != p) { @@ -653,7 +653,7 @@ static int32_t buildTableReq(SHashObj* pTablesHash, SArray** pTables) { int32_t code = tNameFromString(&name, fullName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); if (TSDB_CODE_SUCCESS == code) { if (NULL == taosArrayPush(*pTables, &name)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } } if (TSDB_CODE_SUCCESS != code) { @@ -672,7 +672,7 @@ static int32_t buildDbReq(SHashObj* pDbsHash, SArray** pDbs) { if (NULL != pDbsHash) { *pDbs = taosArrayInit(taosHashGetSize(pDbsHash), TSDB_DB_FNAME_LEN); if (NULL == *pDbs) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } void* p = taosHashIterate(pDbsHash, NULL); while (NULL != p) { @@ -684,7 +684,7 @@ static int32_t buildDbReq(SHashObj* pDbsHash, SArray** pDbs) { taosHashCancelIterate(pDbsHash, p); taosArrayDestroy(*pDbs); *pDbs = NULL; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } p = taosHashIterate(pDbsHash, p); } @@ -697,7 +697,7 @@ static int32_t buildTableReqFromDb(SHashObj* pDbsHash, SArray** pDbs) { if (NULL == *pDbs) { *pDbs = taosArrayInit(taosHashGetSize(pDbsHash), sizeof(STablesReq)); if (NULL == *pDbs) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } SParseTablesMetaReq* p = taosHashIterate(pDbsHash, NULL); @@ -707,7 +707,7 @@ static int32_t buildTableReqFromDb(SHashObj* pDbsHash, SArray** pDbs) { int32_t code = buildTableReq(p->pTables, &req.pTables); if (TSDB_CODE_SUCCESS == code) { if (NULL == taosArrayPush(*pDbs, &req)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } } if (TSDB_CODE_SUCCESS != code) { @@ -726,7 +726,7 @@ static int32_t buildUserAuthReq(SHashObj* pUserAuthHash, SArray** pUserAuth) { if (NULL != pUserAuthHash) { *pUserAuth = taosArrayInit(taosHashGetSize(pUserAuthHash), sizeof(SUserAuthInfo)); if (NULL == *pUserAuth) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } void* p = taosHashIterate(pUserAuthHash, NULL); while (NULL != p) { @@ -740,7 +740,7 @@ static int32_t buildUserAuthReq(SHashObj* pUserAuthHash, SArray** pUserAuth) { taosHashCancelIterate(pUserAuthHash, p); taosArrayDestroy(*pUserAuth); *pUserAuth = NULL; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } p = taosHashIterate(pUserAuthHash, p); } @@ -752,7 +752,7 @@ static int32_t buildUdfReq(SHashObj* pUdfHash, SArray** pUdf) { if (NULL != pUdfHash) { *pUdf = taosArrayInit(taosHashGetSize(pUdfHash), TSDB_FUNC_NAME_LEN); if (NULL == *pUdf) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } void* p = taosHashIterate(pUdfHash, NULL); while (NULL != p) { @@ -764,7 +764,7 @@ static int32_t buildUdfReq(SHashObj* pUdfHash, SArray** pUdf) { taosHashCancelIterate(pUdfHash, p); taosArrayDestroy(*pUdf); *pUdf = NULL; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } p = taosHashIterate(pUdfHash, p); } @@ -804,6 +804,9 @@ int32_t buildCatalogReq(const SParseMetaCache* pMetaCache, SCatalogReq* pCatalog if (TSDB_CODE_SUCCESS == code) { code = buildTableReqFromDb(pMetaCache->pTSMAs, &pCatalogReq->pTSMAs); } + if (TSDB_CODE_SUCCESS == code) { + code = buildTableReqFromDb(pMetaCache->pTableName, &pCatalogReq->pTableName); + } #ifdef TD_ENTERPRISE if (TSDB_CODE_SUCCESS == code) { code = buildTableReqFromDb(pMetaCache->pTableMeta, &pCatalogReq->pView); @@ -837,7 +840,7 @@ static int32_t putMetaDataToHash(const char* pKey, int32_t len, const SArray* pD if (NULL == *pHash) { *pHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (NULL == *pHash) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } SMetaRes* pRes = taosArrayGet(pData, index); @@ -960,6 +963,9 @@ int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMet if (TSDB_CODE_SUCCESS == code) { code = putDbTableDataToCache(pCatalogReq->pTSMAs, pMetaData->pTsmas, &pMetaCache->pTSMAs); } + if (TSDB_CODE_SUCCESS == code) { + code = putDbTableDataToCache(pCatalogReq->pTableName, pMetaData->pTableMeta, &pMetaCache->pTableName); + } #ifdef TD_ENTERPRISE if (TSDB_CODE_SUCCESS == code) { code = putDbTableDataToCache(pCatalogReq->pView, pMetaData->pView, &pMetaCache->pViews); @@ -973,7 +979,7 @@ static int32_t reserveTableReqInCacheImpl(const char* pTbFName, int32_t len, SHa if (NULL == *pTables) { *pTables = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (NULL == *pTables) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } return taosHashPut(*pTables, pTbFName, len, &nullPointer, POINTER_BYTES); @@ -999,7 +1005,7 @@ static int32_t reserveTableReqInDbCache(int32_t acctId, const char* pDb, const c if (NULL == *pDbs) { *pDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (NULL == *pDbs) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } char fullName[TSDB_DB_FNAME_LEN]; @@ -1019,8 +1025,12 @@ int32_t reserveTableMetaInCacheExt(const SName* pName, SParseMetaCache* pMetaCac return reserveTableReqInDbCache(pName->acctId, pName->dbname, pName->tname, &pMetaCache->pTableMeta); } +int32_t reserveTableUidInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache) { + return reserveTableReqInDbCache(acctId, pDb, pTable, &pMetaCache->pTableName); +} + int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta) { - char fullName[TSDB_TABLE_FNAME_LEN]; + char fullName[TSDB_TABLE_FNAME_LEN]; int32_t code = tNameExtractFullName(pName, fullName); if (TSDB_CODE_SUCCESS != code) { return code; @@ -1036,6 +1046,27 @@ int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, S return code; } +int32_t getTableNameFromCache(SParseMetaCache* pMetaCache, const SName* pName, char* pTbName) { + char fullName[TSDB_TABLE_FNAME_LEN]; + int32_t code = tNameExtractFullName(pName, fullName); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + const STableMeta* pMeta = NULL; + code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pTableName, (void**)&pMeta); + if (TSDB_CODE_SUCCESS == code) { + if (!pMeta) code = TSDB_CODE_PAR_INTERNAL_ERROR; + int32_t metaSize = + sizeof(STableMeta) + sizeof(SSchema) * (pMeta->tableInfo.numOfColumns + pMeta->tableInfo.numOfTags); + int32_t schemaExtSize = + (useCompress(pMeta->tableType) && pMeta->schemaExt) ? sizeof(SSchemaExt) * pMeta->tableInfo.numOfColumns : 0; + const char* pTableName = (const char*)pMeta + metaSize + schemaExtSize; + tstrncpy(pTbName, pTableName, TSDB_TABLE_NAME_LEN); + } + + return code; +} + int32_t buildTableMetaFromViewMeta(STableMeta** pMeta, SViewMeta* pViewMeta) { *pMeta = taosMemoryCalloc(1, sizeof(STableMeta) + pViewMeta->numOfCols * sizeof(SSchema)); if (NULL == *pMeta) { @@ -1074,7 +1105,7 @@ static int32_t reserveDbReqInCache(int32_t acctId, const char* pDb, SHashObj** p if (NULL == *pDbs) { *pDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (NULL == *pDbs) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } char fullName[TSDB_TABLE_FNAME_LEN]; @@ -1093,7 +1124,7 @@ int32_t getDbVgInfoFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, if (TSDB_CODE_SUCCESS == code && NULL != pVgList) { *pVgInfo = taosArrayDup(pVgList, NULL); if (NULL == *pVgInfo) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } } return code; @@ -1121,6 +1152,38 @@ int32_t getTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName, return code; } +int32_t getDbTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName, SVgroupInfo* pVgroup) { + char fullName[TSDB_TABLE_FNAME_LEN]; + int32_t code = tNameExtractFullName(pName, fullName); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + const char* pDb = strstr(fullName, "."); + if (pDb == NULL) return TSDB_CODE_PAR_INTERNAL_ERROR; + pDb = strstr(pDb + 1, "."); + if (pDb == NULL) return TSDB_CODE_PAR_INTERNAL_ERROR; + int32_t fullDbLen = pDb - fullName; + int32_t fullTbLen = strlen(fullName); + + SArray* pVgArray = NULL; + SDbCfgInfo* pDbCfg = NULL; + code = getMetaDataFromHash(fullName, fullDbLen, pMetaCache->pDbVgroup, (void**)&pVgArray); + if (TSDB_CODE_SUCCESS == code) { + code = getMetaDataFromHash(fullName, fullDbLen, pMetaCache->pDbCfg, (void**)&pDbCfg); + } + if (TSDB_CODE_SUCCESS == code) { + uint32_t hashValue = + taosGetTbHashVal(fullName, fullTbLen, pDbCfg->hashMethod, pDbCfg->hashPrefix, pDbCfg->hashSuffix); + SVgroupInfo* pVg = taosArraySearch(pVgArray, &hashValue, ctgHashValueComp, TD_EQ); + if (pVg) { + memcpy(pVgroup, pVg, sizeof(SVgroupInfo)); + } else { + code = TSDB_CODE_PAR_INTERNAL_ERROR; + } + } + return code; +} + int32_t reserveDbVgVersionInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache) { return reserveDbReqInCache(acctId, pDb, &pMetaCache->pDbInfo); } @@ -1155,7 +1218,7 @@ static int32_t reserveUserAuthInCacheImpl(const char* pKey, int32_t len, SParseM if (NULL == pMetaCache->pUserAuth) { pMetaCache->pUserAuth = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (NULL == pMetaCache->pUserAuth) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } return taosHashPut(pMetaCache->pUserAuth, pKey, len, &nullPointer, POINTER_BYTES); @@ -1191,7 +1254,7 @@ int32_t reserveUdfInCache(const char* pFunc, SParseMetaCache* pMetaCache) { if (NULL == pMetaCache->pUdf) { pMetaCache->pUdf = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (NULL == pMetaCache->pUdf) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } return taosHashPut(pMetaCache->pUdf, pFunc, strlen(pFunc), &nullPointer, POINTER_BYTES); @@ -1376,7 +1439,7 @@ int32_t getDnodeListFromCache(SParseMetaCache* pMetaCache, SArray** pDnodes) { *pDnodes = taosArrayDup((SArray*)pRes->pRes, NULL); if (NULL == *pDnodes) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return TSDB_CODE_SUCCESS; } @@ -1396,11 +1459,13 @@ void destoryParseMetaCache(SParseMetaCache* pMetaCache, bool request) { destoryParseTablesMetaReqHash(pMetaCache->pTableVgroup); destoryParseTablesMetaReqHash(pMetaCache->pViews); destoryParseTablesMetaReqHash(pMetaCache->pTSMAs); + destoryParseTablesMetaReqHash(pMetaCache->pTableName); } else { taosHashCleanup(pMetaCache->pTableMeta); taosHashCleanup(pMetaCache->pTableVgroup); taosHashCleanup(pMetaCache->pViews); taosHashCleanup(pMetaCache->pTSMAs); + taosHashCleanup(pMetaCache->pTableName); } taosHashCleanup(pMetaCache->pDbVgroup); taosHashCleanup(pMetaCache->pDbCfg); diff --git a/source/libs/parser/src/parser.c b/source/libs/parser/src/parser.c index 2de61ab669..8ac1acb1a2 100644 --- a/source/libs/parser/src/parser.c +++ b/source/libs/parser/src/parser.c @@ -351,6 +351,7 @@ void destoryCatalogReq(SCatalogReq* pCatalogReq) { #endif taosArrayDestroy(pCatalogReq->pTableTSMAs); taosArrayDestroy(pCatalogReq->pTSMAs); + taosArrayDestroy(pCatalogReq->pTableName); } else { taosArrayDestroyEx(pCatalogReq->pTableMeta, destoryTablesReq); taosArrayDestroyEx(pCatalogReq->pTableHash, destoryTablesReq); @@ -359,6 +360,7 @@ void destoryCatalogReq(SCatalogReq* pCatalogReq) { #endif taosArrayDestroyEx(pCatalogReq->pTableTSMAs, destoryTablesReq); taosArrayDestroyEx(pCatalogReq->pTSMAs, destoryTablesReq); + taosArrayDestroyEx(pCatalogReq->pTableName, destoryTablesReq); } taosArrayDestroy(pCatalogReq->pUdf); taosArrayDestroy(pCatalogReq->pIndex); diff --git a/source/libs/parser/src/sql.c b/source/libs/parser/src/sql.c index 4a92cc5a1a..a4ccd82ef2 100644 --- a/source/libs/parser/src/sql.c +++ b/source/libs/parser/src/sql.c @@ -24,7 +24,10 @@ ** The following is the concatenation of all %include directives from the ** input grammar file: */ +#include +#include /************ Begin %include sections from the grammar ************************/ + #include #include #include @@ -1589,7 +1592,7 @@ static const YYCODETYPE yy_lookahead[] = { /* 5070 */ 384, 384, 384, 384, 384, 384, 384, 384, 384, 384, /* 5080 */ 384, 384, 384, 384, 384, 384, 384, 384, 384, 384, }; -#define YY_SHIFT_COUNT (1006) +#define YY_SHIFT_COUNT (1008) #define YY_SHIFT_MIN (0) #define YY_SHIFT_MAX (2824) static const unsigned short int yy_shift_ofst[] = { @@ -2297,7 +2300,6 @@ struct yyParser { }; typedef struct yyParser yyParser; -#include #ifndef NDEBUG #include static FILE *yyTraceFILE = 0; @@ -4233,7 +4235,7 @@ static YYACTIONTYPE yy_find_shift_action( #endif /* YYWILDCARD */ return yy_default[stateno]; }else{ - assert( i>=0 && i<(int)(sizeof(yy_action)/sizeof(yy_action[0])) ); + assert( i>=0 && iyytos; +#ifndef NDEBUG + if( yyTraceFILE && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){ + yysize = yyRuleInfoNRhs[yyruleno]; + if( yysize ){ + fprintf(yyTraceFILE, "%sReduce %d [%s]%s, pop back to state %d.\n", + yyTracePrompt, + yyruleno, yyRuleName[yyruleno], + yyrulenoyytos - yypParser->yystack)>yypParser->yyhwm ){ + yypParser->yyhwm++; + assert( yypParser->yyhwm == (int)(yypParser->yytos - yypParser->yystack)); + } +#endif +#if YYSTACKDEPTH>0 + if( yypParser->yytos>=yypParser->yystackEnd ){ + yyStackOverflow(yypParser); + /* The call to yyStackOverflow() above pops the stack until it is + ** empty, causing the main parser loop to exit. So the return value + ** is never used and does not matter. */ + return 0; + } +#else + if( yypParser->yytos>=&yypParser->yystack[yypParser->yystksz-1] ){ + if( yyGrowStack(yypParser) ){ + yyStackOverflow(yypParser); + /* The call to yyStackOverflow() above pops the stack until it is + ** empty, causing the main parser loop to exit. So the return value + ** is never used and does not matter. */ + return 0; + } + yymsp = yypParser->yytos; + } +#endif + } switch( yyruleno ){ /* Beginning here are the reduction cases. A typical example @@ -8251,8 +8301,7 @@ void Parse( } #endif - while(1){ /* Exit by "break" */ - assert( yypParser->yytos>=yypParser->yystack ); + do{ assert( yyact==yypParser->yytos->stateno ); yyact = yy_find_shift_action((YYCODETYPE)yymajor,yyact); if( yyact >= YY_MIN_REDUCE ){ @@ -8356,13 +8405,14 @@ void Parse( yy_destructor(yypParser, (YYCODETYPE)yymajor, &yyminorunion); yymajor = YYNOCODE; }else{ - while( yypParser->yytos > yypParser->yystack ){ - yyact = yy_find_reduce_action(yypParser->yytos->stateno, - YYERRORSYMBOL); - if( yyact<=YY_MAX_SHIFTREDUCE ) break; + while( yypParser->yytos >= yypParser->yystack + && (yyact = yy_find_reduce_action( + yypParser->yytos->stateno, + YYERRORSYMBOL)) > YY_MAX_SHIFTREDUCE + ){ yy_pop_parser_stack(yypParser); } - if( yypParser->yytos <= yypParser->yystack || yymajor==0 ){ + if( yypParser->yytos < yypParser->yystack || yymajor==0 ){ yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion); yy_parse_failed(yypParser); #ifndef YYNOERRORRECOVERY @@ -8412,7 +8462,7 @@ void Parse( break; #endif } - } + }while( yypParser->yytos>yypParser->yystack ); #ifndef NDEBUG if( yyTraceFILE ){ yyStackEntry *i; diff --git a/source/libs/planner/src/planOptimizer.c b/source/libs/planner/src/planOptimizer.c index 1296986e7f..401b4f93d1 100644 --- a/source/libs/planner/src/planOptimizer.c +++ b/source/libs/planner/src/planOptimizer.c @@ -1198,7 +1198,7 @@ static int32_t pdcJoinCollectColsFromParent(SJoinLogicNode* pJoin, SSHashObj* pT .pColHash = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK) }; if (NULL == cxt.pColHash) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } nodesWalkExpr(pJoin->pPrimKeyEqCond, pdcJoinCollectCondCol, &cxt); @@ -4304,7 +4304,7 @@ static int32_t lastRowScanBuildFuncTypes(SScanLogicNode* pScan, SColumnNode* pCo pScan->pFuncTypes = taosArrayInit(pScan->pScanCols->length, sizeof(SFunctParam)); if (NULL == pScan->pFuncTypes) { taosMemoryFree(pFuncTypeParam); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -4317,7 +4317,7 @@ static int32_t lastRowScanBuildFuncTypes(SScanLogicNode* pScan, SColumnNode* pCo strcpy(pFuncTypeParam->pCol->name, pColNode->colName); if (NULL == taosArrayPush(pScan->pFuncTypes, pFuncTypeParam)) { taosMemoryFree(pFuncTypeParam); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } taosMemoryFree(pFuncTypeParam); @@ -6692,7 +6692,7 @@ static int32_t fillTSMAOptCtx(STSMAOptCtx* pTsmaOptCtx, SScanLogicNode* pScan) { pTsmaOptCtx->pUsefulTsmas = taosArrayInit(pScan->pTsmas->size, sizeof(STSMAOptUsefulTsma)); pTsmaOptCtx->pUsedTsmas = taosArrayInit(3, sizeof(STSMAOptUsefulTsma)); if (!pTsmaOptCtx->pUsefulTsmas || !pTsmaOptCtx->pUsedTsmas) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } return code; } @@ -6755,7 +6755,7 @@ static int32_t tsmaOptCheckValidFuncs(const SArray* pTsmaFuncs, const SNodeList* } found = true; if (NULL == taosArrayPush(pTsmaScanCols, &i)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } break; } @@ -6813,7 +6813,7 @@ static int32_t tsmaOptFilterTsmas(STSMAOptCtx* pTsmaOptCtx) { for (int32_t i = 0; i < pTsmaOptCtx->pTsmas->size; ++i) { if (!pTsmaScanCols) { pTsmaScanCols = taosArrayInit(pTsmaOptCtx->pAggFuncs->length, sizeof(int32_t)); - if (!pTsmaScanCols) return TSDB_CODE_OUT_OF_MEMORY; + if (!pTsmaScanCols) return terrno; } if (pTsmaOptCtx->pScan->tableType == TSDB_CHILD_TABLE || pTsmaOptCtx->pScan->tableType == TSDB_NORMAL_TABLE) { const STsmaTargetTbInfo* ptbInfo = taosArrayGet(pTsmaOptCtx->pScan->pTsmaTargetTbInfo, i); @@ -6842,7 +6842,7 @@ static int32_t tsmaOptFilterTsmas(STSMAOptCtx* pTsmaOptCtx) { if (pTsmaScanCols) { taosArrayDestroy(pTsmaScanCols); } - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } if (pTsmaScanCols) taosArrayDestroy(pTsmaScanCols); @@ -6949,7 +6949,7 @@ static int32_t tsmaOptSplitWindows(STSMAOptCtx* pTsmaOptCtx, const STimeWindow* .scanRange = scanRange, .pTsmaScanCols = pTsmaFound ? pTsmaFound->pTsmaScanCols : NULL}; if (NULL == taosArrayPush(pTsmaOptCtx->pUsedTsmas, &usefulTsma)) - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } // the main tsma @@ -6962,7 +6962,7 @@ static int32_t tsmaOptSplitWindows(STSMAOptCtx* pTsmaOptCtx, const STimeWindow* STSMAOptUsefulTsma usefulTsma = { .pTsma = pTsma, .scanRange = scanRange, .pTsmaScanCols = pUsefulTsma->pTsmaScanCols}; if (NULL == taosArrayPush(pTsmaOptCtx->pUsedTsmas, &usefulTsma)) - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } // add tail tsma if possible @@ -6976,7 +6976,7 @@ static int32_t tsmaOptSplitWindows(STSMAOptCtx* pTsmaOptCtx, const STimeWindow* .scanRange = scanRange, .pTsmaScanCols = pTsmaFound ? pTsmaFound->pTsmaScanCols : NULL}; if (NULL == taosArrayPush(pTsmaOptCtx->pUsedTsmas, &usefulTsma)) - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return code; } diff --git a/source/libs/planner/src/planPhysiCreater.c b/source/libs/planner/src/planPhysiCreater.c index 29440603cf..6b2eacc37e 100644 --- a/source/libs/planner/src/planPhysiCreater.c +++ b/source/libs/planner/src/planPhysiCreater.c @@ -171,18 +171,18 @@ static int32_t putSlotToHashImpl(int16_t dataBlockId, int16_t slotId, const char if (NULL != pIndex) { SSlotIdInfo info = {.slotId = slotId, .set = false}; if (NULL == taosArrayPush(pIndex->pSlotIdsInfo, &info)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return TSDB_CODE_SUCCESS; } SSlotIndex index = {.dataBlockId = dataBlockId, .pSlotIdsInfo = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SSlotIdInfo))}; if (NULL == index.pSlotIdsInfo) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SSlotIdInfo info = {.slotId = slotId, .set = false}; if (NULL == taosArrayPush(index.pSlotIdsInfo, &info)) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return taosHashPut(pHash, pName, len, &index, sizeof(SSlotIndex)); } @@ -195,22 +195,22 @@ static int32_t createDataBlockDescHash(SPhysiPlanContext* pCxt, int32_t capacity SHashObj** pDescHash, SHashObj** ppProjIdxDescHash) { SHashObj* pHash = taosHashInit(capacity, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); if (NULL == pHash) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SHashObj* pProjIdxHash = taosHashInit(capacity, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); if (!pProjIdxHash) { taosHashCleanup(pHash); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (NULL == taosArrayInsert(pCxt->pLocationHelper, dataBlockId, &pHash)) { taosHashCleanup(pHash); taosHashCleanup(pProjIdxHash); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (NULL == taosArrayInsert(pCxt->pProjIdxLocHelper, dataBlockId, &pProjIdxHash)) { taosHashCleanup(pHash); taosHashCleanup(pProjIdxHash); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } *pDescHash = pHash; @@ -529,14 +529,14 @@ static int32_t colIdCompare(const void* pLeft, const void* pRight) { static int32_t sortScanCols(SNodeList* pScanCols) { SArray* pArray = taosArrayInit(LIST_LENGTH(pScanCols), POINTER_BYTES); if (NULL == pArray) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = 0; SNode* pCol = NULL; FOREACH(pCol, pScanCols) { if (NULL == taosArrayPush(pArray, &pCol)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } } @@ -708,7 +708,7 @@ static int32_t createLastRowScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSu if (TSDB_CODE_SUCCESS == code && pScanLogicNode->pFuncTypes != NULL) { pScan->pFuncTypes = taosArrayInit(taosArrayGetSize(pScanLogicNode->pFuncTypes), sizeof(int32_t)); if (NULL == pScan->pFuncTypes) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SNode* pTargetNode = NULL; @@ -724,7 +724,7 @@ static int32_t createLastRowScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSu if (pColNode->colId == pFunctParam->pCol->colId && 0 == strncmp(pColNode->colName, pFunctParam->pCol->name, strlen(pColNode->colName))) { if (NULL == taosArrayInsert(pScan->pFuncTypes, funcTypeIndex, &pFunctParam->type)) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } break; } @@ -3054,7 +3054,7 @@ static int32_t setExecNodeList(SPhysiPlanContext* pCxt, SArray* pExecNodeList) { if (pCxt->hasSysScan || !pCxt->hasScan) { SQueryNodeLoad node = {.addr = {.nodeId = MNODE_HANDLE, .epSet = pCxt->pPlanCxt->mgmtEpSet}, .load = 0}; if (NULL == taosArrayPush(pExecNodeList, &node)) - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } return code; } @@ -3070,7 +3070,7 @@ int32_t createPhysiPlan(SPlanContext* pCxt, SQueryLogicPlan* pLogicPlan, SQueryP if (NULL == cxt.pLocationHelper || !cxt.pProjIdxLocHelper) { taosArrayDestroy(cxt.pLocationHelper); taosArrayDestroy(cxt.pProjIdxLocHelper); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t code = doCreatePhysiPlan(&cxt, pLogicPlan, pPlan); diff --git a/source/libs/qcom/src/queryUtil.c b/source/libs/qcom/src/queryUtil.c index e08d4cef87..ff20211af2 100644 --- a/source/libs/qcom/src/queryUtil.c +++ b/source/libs/qcom/src/queryUtil.c @@ -210,7 +210,6 @@ int32_t asyncSendMsgToServerExt(void* pTransporter, SEpSet* epSet, int64_t* pTra if (NULL == pMsg) { qError("0x%" PRIx64 " msg:%s malloc failed", pInfo->requestId, TMSG_INFO(pInfo->msgType)); destroySendMsgInfo(pInfo); - terrno = TSDB_CODE_OUT_OF_MEMORY; return terrno; } @@ -541,7 +540,7 @@ int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst) { } *pDst = taosMemoryMalloc(metaSize + schemaExtSize); if (NULL == *pDst) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(*pDst, pSrc, metaSize); if (useCompress(pSrc->tableType) && pSrc->schemaExt) { @@ -585,7 +584,7 @@ int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst) { *pDst = taosMemoryMalloc(sizeof(*pSrc)); if (NULL == *pDst) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(*pDst, pSrc, sizeof(*pSrc)); (*pDst)->vgArray = NULL; @@ -595,7 +594,7 @@ int32_t cloneDbVgInfo(SDBVgInfo* pSrc, SDBVgInfo** pDst) { HASH_ENTRY_LOCK); if (NULL == (*pDst)->vgHash) { taosMemoryFreeClear(*pDst); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SVgroupInfo* vgInfo = NULL; diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index 8725496ed2..542e549d40 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -53,7 +53,7 @@ int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) { pOut->dbVgroup->vgHash = taosHashInit(usedbRsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); if (NULL == pOut->dbVgroup->vgHash) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int32_t i = 0; i < usedbRsp->vgNum; ++i) { @@ -77,6 +77,7 @@ int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int3 } STableInfoReq infoReq = {0}; + infoReq.option = pInput->option; infoReq.header.vgId = pInput->vgId; if (pInput->dbFName) { tstrncpy(infoReq.dbFName, pInput->dbFName, TSDB_DB_FNAME_LEN); @@ -259,11 +260,11 @@ int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int3 funcReq.ignoreCodeComment = true; funcReq.pFuncNames = taosArrayInit(1, strlen(input) + 1); if (NULL == funcReq.pFuncNames) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (taosArrayPush(funcReq.pFuncNames, input) == NULL) { taosArrayDestroy(funcReq.pFuncNames); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t bufLen = tSerializeSRetrieveFuncReq(NULL, 0, &funcReq); @@ -603,6 +604,64 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta * return TSDB_CODE_SUCCESS; } +int32_t queryCreateTableMetaExFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) { + int32_t total = msg->numOfColumns + msg->numOfTags; + int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total; + int32_t schemaExtSize = (useCompress(msg->tableType) && msg->pSchemaExt) ? sizeof(SSchemaExt) * msg->numOfColumns : 0; + int32_t tbNameSize = strlen(msg->tbName) + 1; + + STableMeta *pTableMeta = taosMemoryCalloc(1, metaSize + schemaExtSize + tbNameSize); + if (NULL == pTableMeta) { + qError("calloc size[%d] failed", metaSize); + return terrno; + } + SSchemaExt *pSchemaExt = (SSchemaExt *)((char *)pTableMeta + metaSize); + + pTableMeta->vgId = isStb ? 0 : msg->vgId; + pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType; + pTableMeta->uid = isStb ? msg->suid : msg->tuid; + pTableMeta->suid = msg->suid; + pTableMeta->sversion = msg->sversion; + pTableMeta->tversion = msg->tversion; + + pTableMeta->tableInfo.numOfTags = msg->numOfTags; + pTableMeta->tableInfo.precision = msg->precision; + pTableMeta->tableInfo.numOfColumns = msg->numOfColumns; + + TAOS_MEMCPY(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total); + if (useCompress(msg->tableType) && msg->pSchemaExt) { + pTableMeta->schemaExt = pSchemaExt; + TAOS_MEMCPY(pSchemaExt, msg->pSchemaExt, schemaExtSize); + } else { + pTableMeta->schemaExt = NULL; + } + + bool hasPK = (msg->numOfColumns > 1) && (pTableMeta->schema[1].flags & COL_IS_KEY); + for (int32_t i = 0; i < msg->numOfColumns; ++i) { + pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes; + if (hasPK && (i > 0)) { + if ((pTableMeta->schema[i].flags & COL_IS_KEY)) { + ++pTableMeta->tableInfo.numOfPKs; + } else { + hasPK = false; + } + } + } + + char *pTbName = (char *)pTableMeta + metaSize + schemaExtSize; + tstrncpy(pTbName, msg->tbName, tbNameSize); + + qDebug("table %s uid %" PRIx64 " meta returned, type %d vgId:%d db %s stb %s suid %" PRIx64 + " sver %d tver %d" + " tagNum %d colNum %d precision %d rowSize %d", + msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName, + pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags, + pTableMeta->tableInfo.numOfColumns, pTableMeta->tableInfo.precision, pTableMeta->tableInfo.rowSize); + + *pMeta = pTableMeta; + return TSDB_CODE_SUCCESS; +} + int32_t queryProcessTableMetaRsp(void *output, char *msg, int32_t msgSize) { int32_t code = 0; STableMetaRsp metaRsp = {0}; @@ -659,6 +718,62 @@ PROCESS_META_OVER: return code; } +static int32_t queryProcessTableNameRsp(void *output, char *msg, int32_t msgSize) { + int32_t code = 0; + STableMetaRsp metaRsp = {0}; + + if (NULL == output || NULL == msg || msgSize <= 0) { + code = TSDB_CODE_TSC_INVALID_INPUT; + goto PROCESS_NAME_OVER; + } + + if (tDeserializeSTableMetaRsp(msg, msgSize, &metaRsp) != 0) { + code = TSDB_CODE_INVALID_MSG; + goto PROCESS_NAME_OVER; + } + + code = queryConvertTableMetaMsg(&metaRsp); + if (code != TSDB_CODE_SUCCESS) { + goto PROCESS_NAME_OVER; + } + + if (!IS_SYS_DBNAME(metaRsp.dbFName) && + !tIsValidSchema(metaRsp.pSchemas, metaRsp.numOfColumns, metaRsp.numOfTags)) { + code = TSDB_CODE_TSC_INVALID_VALUE; + goto PROCESS_NAME_OVER; + } + + STableMetaOutput *pOut = output; + strcpy(pOut->dbFName, metaRsp.dbFName); + pOut->dbId = metaRsp.dbId; + + if (metaRsp.tableType == TSDB_CHILD_TABLE) { + SET_META_TYPE_BOTH_TABLE(pOut->metaType); + + strcpy(pOut->ctbName, metaRsp.tbName); + strcpy(pOut->tbName, metaRsp.stbName); + + pOut->ctbMeta.vgId = metaRsp.vgId; + pOut->ctbMeta.tableType = metaRsp.tableType; + pOut->ctbMeta.uid = metaRsp.tuid; + pOut->ctbMeta.suid = metaRsp.suid; + + code = queryCreateTableMetaExFromMsg(&metaRsp, true, &pOut->tbMeta); + } else { + SET_META_TYPE_TABLE(pOut->metaType); + strcpy(pOut->tbName, metaRsp.tbName); + code = queryCreateTableMetaExFromMsg(&metaRsp, (metaRsp.tableType == TSDB_SUPER_TABLE), &pOut->tbMeta); + } + +PROCESS_NAME_OVER: + if (code != 0) { + qError("failed to process table name rsp since %s", tstrerror(code)); + } + + tFreeSTableMetaRsp(&metaRsp); + return code; +} + int32_t queryProcessQnodeListRsp(void *output, char *msg, int32_t msgSize) { SQnodeListRsp out = {0}; int32_t code = 0; @@ -880,6 +995,7 @@ int32_t queryProcessStreamProgressRsp(void* output, char* msg, int32_t msgSize) void initQueryModuleMsgHandle() { queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryBuildTableMetaReqMsg; + queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_NAME)] = queryBuildTableMetaReqMsg; queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryBuildTableMetaReqMsg; queryBuildMsg[TMSG_INDEX(TDMT_MND_USE_DB)] = queryBuildUseDbMsg; queryBuildMsg[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryBuildQnodeListMsg; @@ -898,6 +1014,7 @@ void initQueryModuleMsgHandle() { queryBuildMsg[TMSG_INDEX(TDMT_VND_GET_STREAM_PROGRESS)] = queryBuildGetStreamProgressMsg; queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryProcessTableMetaRsp; + queryProcessMsgRsp[TMSG_INDEX(TDMT_VND_TABLE_NAME)] = queryProcessTableNameRsp; queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryProcessTableMetaRsp; queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_USE_DB)] = queryProcessUseDBRsp; queryProcessMsgRsp[TMSG_INDEX(TDMT_MND_QNODE_LIST)] = queryProcessQnodeListRsp; diff --git a/source/libs/qworker/src/qwMsg.c b/source/libs/qworker/src/qwMsg.c index f84e5e463e..0011d1c70c 100644 --- a/source/libs/qworker/src/qwMsg.c +++ b/source/libs/qworker/src/qwMsg.c @@ -17,7 +17,7 @@ int32_t qwMallocFetchRsp(int8_t rpcMalloc, int32_t length, SRetrieveTableRsp **r (SRetrieveTableRsp *)(rpcMalloc ? rpcReallocCont(*rsp, msgSize) : taosMemoryRealloc(*rsp, msgSize)); if (NULL == pRsp) { qError("rpcMallocCont %d failed", msgSize); - QW_RET(TSDB_CODE_OUT_OF_MEMORY); + QW_RET(terrno); } if (NULL == *rsp) { @@ -79,7 +79,7 @@ int32_t qwBuildAndSendQueryRsp(int32_t rspType, SRpcHandleInfo *pConn, int32_t c void *pRsp = rpcMallocCont(msgSize); if (NULL == pRsp) { qError("rpcMallocCont %d failed", msgSize); - QW_RET(TSDB_CODE_OUT_OF_MEMORY); + QW_RET(terrno); } if (tSerializeSQueryTableRsp(pRsp, msgSize, &rsp) < 0) { @@ -246,7 +246,7 @@ int32_t qwBuildAndSendDropMsg(QW_FPARAMS_DEF, SRpcHandleInfo *pConn) { void *msg = rpcMallocCont(msgSize); if (NULL == msg) { QW_SCH_TASK_ELOG("rpcMallocCont %d failed", msgSize); - QW_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + QW_ERR_RET(terrno); } if (tSerializeSTaskDropReq(msg, msgSize, &qMsg) < 0) { @@ -325,7 +325,7 @@ int32_t qwRegisterQueryBrokenLinkArg(QW_FPARAMS_DEF, SRpcHandleInfo *pConn) { void *msg = rpcMallocCont(msgSize); if (NULL == msg) { QW_SCH_TASK_ELOG("rpcMallocCont %d failed", msgSize); - QW_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + QW_ERR_RET(terrno); } if (tSerializeSTaskDropReq(msg, msgSize, &qMsg) < 0) { @@ -360,7 +360,7 @@ int32_t qwRegisterHbBrokenLinkArg(SQWorker *mgmt, uint64_t sId, SRpcHandleInfo * void *msg = rpcMallocCont(msgSize); if (NULL == msg) { QW_SCH_ELOG("calloc %d failed", msgSize); - QW_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + QW_ERR_RET(terrno); } if (tSerializeSSchedulerHbReq(msg, msgSize, &req) < 0) { QW_SCH_ELOG("tSerializeSSchedulerHbReq hbReq failed, size:%d", msgSize); diff --git a/source/libs/qworker/src/qwUtil.c b/source/libs/qworker/src/qwUtil.c index aef348827a..d6266afa02 100644 --- a/source/libs/qworker/src/qwUtil.c +++ b/source/libs/qworker/src/qwUtil.c @@ -78,7 +78,7 @@ int32_t qwAddSchedulerImpl(SQWorker *mgmt, uint64_t sId, int32_t rwType) { if (NULL == newSch.tasksHash) { QW_SCH_ELOG("taosHashInit %d failed", mgmt->cfg.maxSchTaskNum); - QW_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + QW_ERR_RET(terrno); } QW_LOCK(QW_WRITE, &mgmt->schLock); diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index 2fd839cb8c..e08868d7c1 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -273,7 +273,7 @@ int32_t qwGenerateSchHbRsp(SQWorker *mgmt, SQWSchStatus *sch, SQWHbInfo *hbInfo) if (NULL == hbInfo->rsp.taskStatus) { QW_UNLOCK(QW_READ, &sch->tasksLock); QW_ELOG("taosArrayInit taskStatus failed, num:%d", taskNum); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } void *key = NULL; @@ -1343,14 +1343,14 @@ int32_t qWorkerInit(int8_t nodeType, int32_t nodeId, void **qWorkerMgmt, const S if (NULL == mgmt->schHash) { taosMemoryFreeClear(mgmt); qError("init %d scheduler hash failed", mgmt->cfg.maxSchedulerNum); - QW_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + QW_ERR_JRET(terrno); } mgmt->ctxHash = taosHashInit(mgmt->cfg.maxTaskNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); if (NULL == mgmt->ctxHash) { qError("init %d task ctx hash failed", mgmt->cfg.maxTaskNum); - QW_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + QW_ERR_JRET(terrno); } mgmt->timer = taosTmrInit(0, 0, 0, "qworker"); diff --git a/source/libs/scalar/src/filter.c b/source/libs/scalar/src/filter.c index 752bb2c0f5..a9a765c0fa 100644 --- a/source/libs/scalar/src/filter.c +++ b/source/libs/scalar/src/filter.c @@ -970,7 +970,7 @@ int32_t filterDetachCnfGroup(SFilterGroup *gp1, SFilterGroup *gp2, SArray *group if (NULL == taosArrayPush(group, &gp)) { taosMemoryFreeClear(gp.unitIdxs); - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } return TSDB_CODE_SUCCESS; @@ -989,7 +989,7 @@ int32_t filterDetachCnfGroups(SArray *group, SArray *left, SArray *right) { SFilterGroup *gp = NULL; while ((gp = (SFilterGroup *)taosArrayPop(right)) != NULL) { if (NULL == taosArrayPush(group, gp)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } } @@ -1000,7 +1000,7 @@ int32_t filterDetachCnfGroups(SArray *group, SArray *left, SArray *right) { SFilterGroup *gp = NULL; while ((gp = (SFilterGroup *)taosArrayPop(left)) != NULL) { if (NULL == taosArrayPush(group, gp)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } } @@ -1177,7 +1177,7 @@ int32_t filterAddUnitImpl(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, false); if (NULL == info->pctx.unitHash) { fltError("taosHashInit failed, size:%d", FILTER_DEFAULT_GROUP_SIZE * FILTER_DEFAULT_UNIT_SIZE); - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } } else { char v[14] = {0}; @@ -1196,7 +1196,7 @@ int32_t filterAddUnitImpl(SFilterInfo *info, uint8_t optr, SFilterFieldId *left, void *tmp = taosMemoryRealloc(info->units, info->unitSize * sizeof(SFilterUnit)); if (tmp == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } info->units = (SFilterUnit *)tmp; (void)memset(info->units + psize, 0, sizeof(*info->units) * FILTER_DEFAULT_UNIT_SIZE); @@ -1264,7 +1264,7 @@ int32_t filterAddUnitToGroup(SFilterGroup *group, uint32_t unitIdx) { void *tmp = taosMemoryRealloc(group->unitIdxs, group->unitSize * sizeof(*group->unitIdxs)); if (tmp == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } group->unitIdxs = tmp; } @@ -1351,7 +1351,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode *tree, SArray *group) { } if (NULL == taosArrayPush(group, &fgroup)) { filterFreeGroup((void*)&fgroup); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } @@ -1368,7 +1368,7 @@ int32_t fltAddGroupUnitFromNode(SFilterInfo *info, SNode *tree, SArray *group) { FLT_ERR_RET(filterAddUnitToGroup(&fgroup, uidx)); if (NULL == taosArrayPush(group, &fgroup)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } } @@ -1479,7 +1479,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan if (func(&ra->s, &ra->e) == 0) { void *data = taosMemoryMalloc(sizeof(int64_t)); if (data == NULL) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } SIMPLE_COPY_VALUES(data, &ra->s); FLT_ERR_RET(filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true, NULL)); @@ -1489,13 +1489,13 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan } else { void *data = taosMemoryMalloc(sizeof(int64_t)); if (data == NULL) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } SIMPLE_COPY_VALUES(data, &ra->s); FLT_ERR_RET(filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true, NULL)); void *data2 = taosMemoryMalloc(sizeof(int64_t)); if (data2 == NULL) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } SIMPLE_COPY_VALUES(data2, &ra->e); FLT_ERR_RET(filterAddField(dst, NULL, &data2, FLD_TYPE_VALUE, &right2, tDataTypes[type].bytes, true, NULL)); @@ -1512,7 +1512,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan if (!FILTER_GET_FLAG(ra->sflag, RANGE_FLG_NULL)) { void *data = taosMemoryMalloc(sizeof(int64_t)); if (data == NULL) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } SIMPLE_COPY_VALUES(data, &ra->s); FLT_ERR_RET(filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true, NULL)); @@ -1524,7 +1524,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan if (!FILTER_GET_FLAG(ra->eflag, RANGE_FLG_NULL)) { void *data = taosMemoryMalloc(sizeof(int64_t)); if (data == NULL) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } SIMPLE_COPY_VALUES(data, &ra->e); FLT_ERR_RET(filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true, NULL)); @@ -1551,7 +1551,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan FLT_ERR_RET(filterAddUnit(dst, OP_TYPE_IS_NULL, &left, NULL, &uidx)); FLT_ERR_RET(filterAddUnitToGroup(g, uidx)); if (NULL == taosArrayPush(res,g)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } } @@ -1566,7 +1566,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan FLT_ERR_RET(filterAddUnit(dst, OP_TYPE_IS_NOT_NULL, &left, NULL, &uidx)); FLT_ERR_RET(filterAddUnitToGroup(g, uidx)); if (NULL == taosArrayPush(res,g)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } } @@ -1593,7 +1593,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan if (func(&r->ra.s, &r->ra.e) == 0) { void *data = taosMemoryMalloc(sizeof(int64_t)); if (data == NULL) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } SIMPLE_COPY_VALUES(data, &r->ra.s); FLT_ERR_RET(filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true, NULL)); @@ -1602,13 +1602,13 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan } else { void *data = taosMemoryMalloc(sizeof(int64_t)); if (data == NULL) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } SIMPLE_COPY_VALUES(data, &r->ra.s); FLT_ERR_RET(filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true, NULL)); void *data2 = taosMemoryMalloc(sizeof(int64_t)); if (data2 == NULL) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } SIMPLE_COPY_VALUES(data2, &r->ra.e); FLT_ERR_RET(filterAddField(dst, NULL, &data2, FLD_TYPE_VALUE, &right2, tDataTypes[type].bytes, true, NULL)); @@ -1621,7 +1621,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan } if (NULL == taosArrayPush(res,g)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } r = r->next; @@ -1632,7 +1632,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan if (!FILTER_GET_FLAG(r->ra.sflag, RANGE_FLG_NULL)) { void *data = taosMemoryMalloc(sizeof(int64_t)); if (data == NULL) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } SIMPLE_COPY_VALUES(data, &r->ra.s); FLT_ERR_RET(filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true, NULL)); @@ -1644,7 +1644,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan if (!FILTER_GET_FLAG(r->ra.eflag, RANGE_FLG_NULL)) { void *data = taosMemoryMalloc(sizeof(int64_t)); if (data == NULL) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } SIMPLE_COPY_VALUES(data, &r->ra.e); FLT_ERR_RET(filterAddField(dst, NULL, &data, FLD_TYPE_VALUE, &right, tDataTypes[type].bytes, true, NULL)); @@ -1659,7 +1659,7 @@ int32_t filterAddGroupUnitFromCtx(SFilterInfo *dst, SFilterInfo *src, SFilterRan } if (NULL == taosArrayPush(res,g)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } r = r->next; @@ -2437,7 +2437,7 @@ int32_t filterMergeGroupUnits(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t uint32_t gResIdx = 0; uint32_t *colIdx = taosMemoryMalloc(info->fields[FLD_TYPE_COLUMN].num * sizeof(uint32_t)); if (colIdx == NULL) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } for (uint32_t i = 0; i < info->groupNum; ++i) { SFilterGroup *g = info->groups + i; @@ -2684,7 +2684,7 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx **gRes1, SFilter colCtx.colIdx = idx1; colCtx.ctx = ctx; if (NULL == taosArrayPush(colCtxs, &colCtx)) { - FLT_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_JRET(terrno); } break; } else { @@ -2703,7 +2703,7 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx **gRes1, SFilter colCtx.ctx = ctx; ctx = NULL; if (NULL == taosArrayPush(colCtxs, &colCtx)) { - FLT_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_JRET(terrno); } } } else { @@ -2717,7 +2717,7 @@ int32_t filterMergeTwoGroups(SFilterInfo *info, SFilterGroupCtx **gRes1, SFilter colCtx.ctx = ctx; ctx = NULL; if (NULL == taosArrayPush(colCtxs, &colCtx)) { - FLT_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_JRET(terrno); } } @@ -2968,7 +2968,7 @@ int32_t filterRewrite(SFilterInfo *info, SFilterGroupCtx **gRes, int32_t gResNum if (ng.unitNum > 0) { if (NULL == taosArrayPush(group, &ng)) { - FLT_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_JRET(terrno); } ng = (SFilterGroup){0}; } @@ -3113,7 +3113,7 @@ int32_t filterGenerateComInfo(SFilterInfo *info) { info->blkUnitRes = taosMemoryMalloc(sizeof(*info->blkUnitRes) * info->unitNum); info->blkUnits = taosMemoryMalloc(sizeof(*info->blkUnits) * (info->unitNum + 1) * info->groupNum); if (NULL == info->cunits || NULL == info->blkUnitRes || NULL == info->blkUnits) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (uint32_t i = 0; i < info->unitNum; ++i) { @@ -3835,11 +3835,11 @@ int32_t fltInitFromNode(SNode *tree, SFilterInfo *info, uint32_t options) { info->unitRes = taosMemoryMalloc(info->unitNum * sizeof(*info->unitRes)); if (info->unitRes == NULL) { - FLT_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_JRET(terrno); } info->unitFlags = taosMemoryMalloc(info->unitNum * sizeof(*info->unitFlags)); if (info->unitFlags == NULL) { - FLT_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_JRET(terrno); } FLT_ERR_JRET(filterDumpInfoToString(info, "Final", 0)); return code; @@ -3987,12 +3987,12 @@ int32_t fltSclMergeSort(SArray *pts1, SArray *pts2, SArray *result) { bool less = fltSclLessPoint(pt1, pt2); if (less) { if (NULL == taosArrayPush(result, pt1)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } ++i; } else { if (NULL == taosArrayPush(result, pt2)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } ++j; } @@ -4004,7 +4004,7 @@ int32_t fltSclMergeSort(SArray *pts1, SArray *pts2, SArray *result) { FLT_ERR_RET(TSDB_CODE_OUT_OF_RANGE); } if (NULL == taosArrayPush(result, pt1)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } } } @@ -4015,7 +4015,7 @@ int32_t fltSclMergeSort(SArray *pts1, SArray *pts2, SArray *result) { FLT_ERR_RET(TSDB_CODE_OUT_OF_RANGE); } if (NULL == taosArrayPush(result, pt2)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } } } @@ -4042,13 +4042,13 @@ int32_t fltSclMerge(SArray *pts1, SArray *pts2, bool isUnion, SArray *merged) { ++count; if (count == countRequired) { if (NULL == taosArrayPush(merged, pt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } } } else { if (count == countRequired) { if (NULL == taosArrayPush(merged, pt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } } --count; @@ -4089,7 +4089,7 @@ int32_t fltSclGetOrCreateColumnRange(SColumnNode *colNode, SArray *colRangeList, FLT_ERR_RET(terrno); } if (NULL == taosArrayPush(colRangeList, &newColRange)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } *colRange = taosArrayGetLast(colRangeList); return TSDB_CODE_SUCCESS; @@ -4188,10 +4188,10 @@ int32_t fltSclBuildRangeFromBlockSma(SFltSclColumnRange *colRange, SColumnDataAg SFltSclPoint startPt = {.start = true, .excl = false, .val = datum}; SFltSclPoint endPt = {.start = false, .excl = false, .val = datum}; if (NULL == taosArrayPush(points, &startPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } if (NULL == taosArrayPush(points, &endPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } return TSDB_CODE_SUCCESS; } @@ -4200,10 +4200,10 @@ int32_t fltSclBuildRangeFromBlockSma(SFltSclColumnRange *colRange, SColumnDataAg SFltSclPoint startPt = {.start = true, .excl = false, .val = nullDatum}; SFltSclPoint endPt = {.start = false, .excl = false, .val = nullDatum}; if (NULL == taosArrayPush(points, &startPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } if (NULL == taosArrayPush(points, &endPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } } SFltSclDatum min = {0}; @@ -4213,10 +4213,10 @@ int32_t fltSclBuildRangeFromBlockSma(SFltSclColumnRange *colRange, SColumnDataAg FLT_ERR_RET(fltSclBuildDatumFromBlockSmaValue(&max, colRange->colNode->node.resType.type, pAgg->max)); SFltSclPoint maxPt = {.excl = false, .start = false, .val = max}; if (NULL == taosArrayPush(points, &minPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } if (NULL == taosArrayPush(points, &maxPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } return TSDB_CODE_SUCCESS; } @@ -4242,7 +4242,7 @@ int32_t filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32 SColumnDataAgg *pAgg = &pDataStatis[j]; SArray *points = taosArrayInit(2, sizeof(SFltSclPoint)); if (NULL == points) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } FLT_ERR_RET(fltSclBuildRangeFromBlockSma(colRange, pAgg, numOfRows, points)); qDebug("column data agg: nulls %d, rows %d, max %" PRId64 " min %" PRId64, pAgg->numOfNull, numOfRows, @@ -4250,7 +4250,7 @@ int32_t filterRangeExecute(SFilterInfo *info, SColumnDataAgg *pDataStatis, int32 SArray *merged = taosArrayInit(8, sizeof(SFltSclPoint)); if (NULL == merged) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } FLT_ERR_RET(fltSclIntersect(points, colRange->points, merged)); bool isIntersect = taosArrayGetSize(merged) != 0; @@ -4570,7 +4570,7 @@ int32_t filterConverNcharColumns(SFilterInfo *info, int32_t rows, bool *gotNchar int32_t bytes = FILTER_GET_COL_FIELD_SIZE(fi); nfi.data = taosMemoryMalloc(rows * bytes); if (nfi.data == NULL) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } int32_t bufSize = bytes - VARSTR_HEADER_SIZE; for (int32_t j = 0; j < rows; ++j) { @@ -4629,7 +4629,7 @@ int32_t fltAddValueNodeToConverList(SFltTreeStat *stat, SValueNode *pNode) { } if (NULL == taosArrayPush(stat->nodeList, &pNode)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } return TSDB_CODE_SUCCESS; @@ -4881,10 +4881,10 @@ int32_t fltSclBuildRangePoints(SFltSclOperator *oper, SArray *points) { SFltSclDatum end = {.kind = FLT_SCL_DATUM_KIND_MAX, .type = oper->colNode->node.resType}; SFltSclPoint endPt = {.start = false, .excl = false, .val = end}; if (NULL == taosArrayPush(points, &startPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } if (NULL == taosArrayPush(points, &endPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } break; } @@ -4895,10 +4895,10 @@ int32_t fltSclBuildRangePoints(SFltSclOperator *oper, SArray *points) { SFltSclDatum end = {.kind = FLT_SCL_DATUM_KIND_MAX, .type = oper->colNode->node.resType}; SFltSclPoint endPt = {.start = false, .excl = false, .val = end}; if (NULL == taosArrayPush(points, &startPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } if (NULL == taosArrayPush(points, &endPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } break; } @@ -4909,10 +4909,10 @@ int32_t fltSclBuildRangePoints(SFltSclOperator *oper, SArray *points) { SFltSclDatum start = {.kind = FLT_SCL_DATUM_KIND_MIN, .type = oper->colNode->node.resType}; SFltSclPoint startPt = {.start = true, .excl = false, .val = start}; if (NULL == taosArrayPush(points, &startPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } if (NULL == taosArrayPush(points, &endPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } break; } @@ -4923,10 +4923,10 @@ int32_t fltSclBuildRangePoints(SFltSclOperator *oper, SArray *points) { SFltSclDatum start = {.kind = FLT_SCL_DATUM_KIND_MIN, .type = oper->colNode->node.resType}; SFltSclPoint startPt = {.start = true, .excl = false, .val = start}; if (NULL == taosArrayPush(points, &startPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } if (NULL == taosArrayPush(points, &endPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } break; } @@ -4936,10 +4936,10 @@ int32_t fltSclBuildRangePoints(SFltSclOperator *oper, SArray *points) { SFltSclPoint startPt = {.start = true, .excl = false, .val = valDatum}; SFltSclPoint endPt = {.start = false, .excl = false, .val = valDatum}; if (NULL == taosArrayPush(points, &startPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } if (NULL == taosArrayPush(points, &endPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } break; } @@ -4951,10 +4951,10 @@ int32_t fltSclBuildRangePoints(SFltSclOperator *oper, SArray *points) { SFltSclPoint startPt = {.start = true, .excl = false, .val = start}; SFltSclPoint endPt = {.start = false, .excl = true, .val = valDatum}; if (NULL == taosArrayPush(points, &startPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } if (NULL == taosArrayPush(points, &endPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } } { @@ -4962,10 +4962,10 @@ int32_t fltSclBuildRangePoints(SFltSclOperator *oper, SArray *points) { SFltSclDatum end = {.kind = FLT_SCL_DATUM_KIND_MAX, .type = oper->colNode->node.resType}; SFltSclPoint endPt = {.start = false, .excl = false, .val = end}; if (NULL == taosArrayPush(points, &startPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } if (NULL == taosArrayPush(points, &endPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } } break; @@ -4975,10 +4975,10 @@ int32_t fltSclBuildRangePoints(SFltSclOperator *oper, SArray *points) { SFltSclPoint startPt = {.start = true, .excl = false, .val = nullDatum}; SFltSclPoint endPt = {.start = false, .excl = false, .val = nullDatum}; if (NULL == taosArrayPush(points, &startPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } if (NULL == taosArrayPush(points, &endPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } break; } @@ -4988,10 +4988,10 @@ int32_t fltSclBuildRangePoints(SFltSclOperator *oper, SArray *points) { SFltSclDatum maxDatum = {.kind = FLT_SCL_DATUM_KIND_MAX, .type = oper->colNode->node.resType}; SFltSclPoint endPt = {.start = false, .excl = false, .val = maxDatum}; if (NULL == taosArrayPush(points, &startPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } if (NULL == taosArrayPush(points, &endPt)) { - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } break; } @@ -5082,7 +5082,7 @@ static int32_t fltSclCollectOperatorFromNode(SNode *pNode, SArray *sclOpList) { if (NULL == taosArrayPush(sclOpList, &sclOp)) { nodesDestroyNode(pLeft); nodesDestroyNode(pRight); - FLT_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + FLT_ERR_RET(terrno); } } diff --git a/source/libs/scalar/src/scalar.c b/source/libs/scalar/src/scalar.c index 3b2450906a..4f08c93c1e 100644 --- a/source/libs/scalar/src/scalar.c +++ b/source/libs/scalar/src/scalar.c @@ -240,7 +240,7 @@ int32_t sclCopyValueNodeValue(SValueNode *pNode, void **res) { *res = taosMemoryMalloc(pNode->node.resType.bytes); if (NULL == (*res)) { sclError("malloc %d failed", pNode->node.resType.bytes); - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } (void)memcpy(*res, nodesGetValueFromNode(pNode), pNode->node.resType.bytes); diff --git a/source/libs/scalar/src/sclfunc.c b/source/libs/scalar/src/sclfunc.c index 965e029c8f..1129b9c28b 100644 --- a/source/libs/scalar/src/sclfunc.c +++ b/source/libs/scalar/src/sclfunc.c @@ -1178,7 +1178,7 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu char *outputBuf = taosMemoryMalloc(outputLen); if (outputBuf == NULL) { qError("substr function memory allocation failure. size: %d", outputLen); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } int32_t numOfRows = 0; @@ -1271,7 +1271,7 @@ int32_t md5Function(SScalarParam* pInput, int32_t inputNum, SScalarParam* pOutpu char* pOutputBuf = taosMemoryMalloc(bufLen); if (!pOutputBuf) { qError("md5 function alloc memory failed"); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int32_t i = 0; i < pInput->numOfRows; ++i) { if (colDataIsNull_s(pInputData, i)) { @@ -1284,7 +1284,7 @@ int32_t md5Function(SScalarParam* pInput, int32_t inputNum, SScalarParam* pOutpu pOutputBuf = taosMemoryRealloc(pOutputBuf, bufLen); if (!pOutputBuf) { qError("md5 function alloc memory failed"); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } char *output = pOutputBuf; @@ -2306,7 +2306,7 @@ int32_t toJsonFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu for (int32_t i = 0; i < pInput[0].numOfRows; ++i) { SArray *pTagVals = taosArrayInit(8, sizeof(STagVal)); if (NULL == pTagVals) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } STag *pTag = NULL; @@ -2356,7 +2356,7 @@ int32_t toTimestampFunction(SScalarParam* pInput, int32_t inputNum, SScalarParam SArray *formats = NULL; if (tsStr == NULL || format == NULL) { - SCL_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_JRET(terrno); } for (int32_t i = 0; i < pInput[0].numOfRows; ++i) { if (colDataIsNull_s(pInput[1].columnData, i) || colDataIsNull_s(pInput[0].columnData, i)) { diff --git a/source/libs/scalar/src/sclvector.c b/source/libs/scalar/src/sclvector.c index 2bfad71ddb..230454483d 100644 --- a/source/libs/scalar/src/sclvector.c +++ b/source/libs/scalar/src/sclvector.c @@ -101,7 +101,7 @@ int32_t convertNcharToDouble(const void *inData, void *outData) { int32_t code = TSDB_CODE_SUCCESS; char *tmp = taosMemoryMalloc(varDataTLen(inData)); if (NULL == tmp) { - SCL_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_RET(terrno); } int len = taosUcs4ToMbs((TdUcs4 *)varDataVal(inData), varDataLen(inData), tmp); if (len < 0) { @@ -540,7 +540,7 @@ int32_t vectorConvertFromVarData(SSclVectorConvCtx *pCtx, int32_t *overflow) { tmp = taosMemoryMalloc(bufSize); if (tmp == NULL) { sclError("out of memory in vectorConvertFromVarData"); - SCL_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCL_ERR_JRET(terrno); } } diff --git a/source/libs/scheduler/src/schFlowCtrl.c b/source/libs/scheduler/src/schFlowCtrl.c index 20e1600737..d9a0b88e40 100644 --- a/source/libs/scheduler/src/schFlowCtrl.c +++ b/source/libs/scheduler/src/schFlowCtrl.c @@ -67,7 +67,7 @@ int32_t schChkJobNeedFlowCtrl(SSchJob *pJob, SSchLevel *pLevel) { taosHashInit(pJob->taskNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); if (NULL == pJob->flowCtrl) { SCH_JOB_ELOG("taosHashInit %d flowCtrl failed", pJob->taskNum); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } SCH_SET_JOB_NEED_FLOW_CTRL(pJob); @@ -160,13 +160,13 @@ int32_t schCheckIncTaskFlowQuota(SSchJob *pJob, SSchTask *pTask, bool *enough) { ctrl->taskList = taosArrayInit(pLevel->taskNum, POINTER_BYTES); if (NULL == ctrl->taskList) { SCH_TASK_ELOG("taosArrayInit taskList failed, size:%d", (int32_t)pLevel->taskNum); - SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_JRET(terrno); } } if (NULL == taosArrayPush(ctrl->taskList, &pTask)) { SCH_TASK_ELOG("taosArrayPush to taskList failed, size:%d", (int32_t)taosArrayGetSize(ctrl->taskList)); - SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_JRET(terrno); } *enough = false; diff --git a/source/libs/scheduler/src/schJob.c b/source/libs/scheduler/src/schJob.c index 80832ed528..f475c974cc 100644 --- a/source/libs/scheduler/src/schJob.c +++ b/source/libs/scheduler/src/schJob.c @@ -192,7 +192,7 @@ int32_t schBuildTaskRalation(SSchJob *pJob, SHashObj *planToTask) { pTask->children = taosArrayInit(childNum, POINTER_BYTES); if (NULL == pTask->children) { SCH_TASK_ELOG("taosArrayInit %d children failed", childNum); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } } @@ -211,7 +211,7 @@ int32_t schBuildTaskRalation(SSchJob *pJob, SHashObj *planToTask) { if (NULL == taosArrayPush(pTask->children, childTask)) { SCH_TASK_ELOG("taosArrayPush childTask failed, level:%d, taskIdx:%d, childIdx:%d", i, m, n); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } SCH_TASK_DLOG("children info, the %d child TID 0x%" PRIx64, n, (*childTask)->taskId); @@ -226,7 +226,7 @@ int32_t schBuildTaskRalation(SSchJob *pJob, SHashObj *planToTask) { pTask->parents = taosArrayInit(parentNum, POINTER_BYTES); if (NULL == pTask->parents) { SCH_TASK_ELOG("taosArrayInit %d parents failed", parentNum); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } } else { if (0 != pLevel->level) { @@ -250,7 +250,7 @@ int32_t schBuildTaskRalation(SSchJob *pJob, SHashObj *planToTask) { if (NULL == taosArrayPush(pTask->parents, parentTask)) { SCH_TASK_ELOG("taosArrayPush parentTask failed, level:%d, taskIdx:%d, childIdx:%d", i, m, n); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } SCH_TASK_DLOG("parents info, the %d parent TID 0x%" PRIx64, n, (*parentTask)->taskId); @@ -309,7 +309,7 @@ int32_t schValidateAndBuildJob(SQueryPlan *pDag, SSchJob *pJob) { pJob->dataSrcTasks = taosArrayInit(pDag->numOfSubplans, POINTER_BYTES); if (NULL == pJob->dataSrcTasks) { - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } int32_t levelNum = (int32_t)LIST_LENGTH(pDag->pSubplans); @@ -324,13 +324,13 @@ int32_t schValidateAndBuildJob(SQueryPlan *pDag, SSchJob *pJob) { HASH_NO_LOCK); if (NULL == planToTask) { SCH_JOB_ELOG("taosHashInit %d failed", SCHEDULE_DEFAULT_MAX_TASK_NUM); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } pJob->levels = taosArrayInit(levelNum, sizeof(SSchLevel)); if (NULL == pJob->levels) { SCH_JOB_ELOG("taosArrayInit %d failed", levelNum); - SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_JRET(terrno); } pJob->levelNum = levelNum; @@ -346,7 +346,7 @@ int32_t schValidateAndBuildJob(SQueryPlan *pDag, SSchJob *pJob) { for (int32_t i = 0; i < levelNum; ++i) { if (NULL == taosArrayPush(pJob->levels, &level)) { SCH_JOB_ELOG("taosArrayPush level failed, level:%d", i); - SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_JRET(terrno); } pLevel = taosArrayGet(pJob->levels, i); @@ -374,7 +374,7 @@ int32_t schValidateAndBuildJob(SQueryPlan *pDag, SSchJob *pJob) { pLevel->subTasks = taosArrayInit(taskNum, sizeof(SSchTask)); if (NULL == pLevel->subTasks) { SCH_JOB_ELOG("taosArrayInit %d failed", taskNum); - SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_JRET(terrno); } for (int32_t n = 0; n < taskNum; ++n) { @@ -390,7 +390,7 @@ int32_t schValidateAndBuildJob(SQueryPlan *pDag, SSchJob *pJob) { SSchTask *pTask = taosArrayPush(pLevel->subTasks, &task); if (NULL == pTask) { SCH_TASK_ELOG("taosArrayPush task to level failed, level:%d, taskIdx:%d", pLevel->level, n); - SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_JRET(terrno); } SCH_ERR_JRET(schInitTask(pJob, pTask, plan, pLevel)); @@ -662,7 +662,7 @@ int32_t schSaveJobExecRes(SSchJob *pJob, SQueryTableRsp *rsp) { pJob->execRes.res = taosArrayInit(pJob->taskNum, sizeof(STbVerInfo)); if (NULL == pJob->execRes.res) { SCH_UNLOCK(SCH_WRITE, &pJob->resLock); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } } @@ -832,7 +832,7 @@ int32_t schInitJob(int64_t *pJobId, SSchedulerReq *pReq) { pJob->sql = taosStrdup(pReq->sql); if (NULL == pJob->sql) { qError("qid:0x%" PRIx64 " strdup sql %s failed", pReq->pDag->queryId, pReq->sql); - SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_JRET(terrno); } } pJob->pDag = pReq->pDag; @@ -865,7 +865,7 @@ int32_t schInitJob(int64_t *pJobId, SSchedulerReq *pReq) { HASH_ENTRY_LOCK); if (NULL == pJob->taskList) { SCH_JOB_ELOG("taosHashInit %d taskList failed", pReq->pDag->numOfSubplans); - SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_JRET(terrno); } SCH_ERR_JRET(schValidateAndBuildJob(pReq->pDag, pJob)); @@ -878,7 +878,7 @@ int32_t schInitJob(int64_t *pJobId, SSchedulerReq *pReq) { HASH_ENTRY_LOCK); if (NULL == pJob->execTasks) { SCH_JOB_ELOG("taosHashInit %d execTasks failed", pReq->pDag->numOfSubplans); - SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_JRET(terrno); } if (tsem_init(&pJob->rspSem, 0, 0)) { diff --git a/source/libs/scheduler/src/schRemote.c b/source/libs/scheduler/src/schRemote.c index 7ff3d1386c..fe601c6b86 100644 --- a/source/libs/scheduler/src/schRemote.c +++ b/source/libs/scheduler/src/schRemote.c @@ -750,7 +750,7 @@ int32_t schCloneHbRpcCtx(SRpcCtx *pSrc, SRpcCtx *pDst) { pDst->args = taosHashInit(1, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK); if (NULL == pDst->args) { qError("taosHashInit %d RpcCtx failed", 1); - SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_JRET(terrno); } SRpcCtxVal dst = {0}; @@ -794,7 +794,7 @@ int32_t schMakeHbRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx) { pCtx->args = taosHashInit(1, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK); if (NULL == pCtx->args) { SCH_TASK_ELOG("taosHashInit %d RpcCtx failed", 1); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } pMsgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo)); @@ -868,7 +868,7 @@ int32_t schMakeQueryRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx) { pCtx->args = taosHashInit(1, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_ENTRY_LOCK); if (NULL == pCtx->args) { SCH_TASK_ELOG("taosHashInit %d RpcCtx failed", 1); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } SSchTrans trans = {.pTrans = pJob->conn.pTrans, .pHandle = SCH_GET_TASK_HANDLE(pTask)}; @@ -903,7 +903,7 @@ int32_t schCloneCallbackParam(SSchCallbackParamHeader *pSrc, SSchCallbackParamHe SSchHbCallbackParam *dst = taosMemoryMalloc(sizeof(SSchHbCallbackParam)); if (NULL == dst) { qError("malloc SSchHbCallbackParam failed"); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } TAOS_MEMCPY(dst, pSrc, sizeof(*dst)); @@ -915,7 +915,7 @@ int32_t schCloneCallbackParam(SSchCallbackParamHeader *pSrc, SSchCallbackParamHe SSchTaskCallbackParam *dst = taosMemoryMalloc(sizeof(SSchTaskCallbackParam)); if (NULL == dst) { qError("malloc SSchTaskCallbackParam failed"); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } TAOS_MEMCPY(dst, pSrc, sizeof(*dst)); diff --git a/source/libs/scheduler/src/schTask.c b/source/libs/scheduler/src/schTask.c index a72ec23f60..a0275d9c21 100644 --- a/source/libs/scheduler/src/schTask.c +++ b/source/libs/scheduler/src/schTask.c @@ -74,7 +74,7 @@ int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel * taosHashInit(pTask->maxExecTimes, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); pTask->profile.execTime = taosArrayInit(pTask->maxExecTimes, sizeof(int64_t)); if (NULL == pTask->execNodes || NULL == pTask->profile.execTime) { - SCH_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_JRET(terrno); } SCH_SET_TASK_STATUS(pTask, JOB_TASK_STATUS_INIT); @@ -786,7 +786,7 @@ int32_t schSetAddrsFromNodeList(SSchJob *pJob, SSchTask *pTask) { if (NULL == taosArrayPush(pTask->candidateAddrs, naddr)) { SCH_TASK_ELOG("taosArrayPush execNode to candidate addrs failed, addNum:%d, errno:%d", addNum, errno); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } SCH_TASK_TLOG("set %dth candidate addr, id %d, inUse:%d/%d, fqdn:%s, port:%d", i, naddr->nodeId, @@ -813,13 +813,13 @@ int32_t schSetTaskCandidateAddrs(SSchJob *pJob, SSchTask *pTask) { pTask->candidateAddrs = taosArrayInit(SCHEDULE_DEFAULT_MAX_NODE_NUM, sizeof(SQueryNodeAddr)); if (NULL == pTask->candidateAddrs) { SCH_TASK_ELOG("taosArrayInit %d condidate addrs failed", SCHEDULE_DEFAULT_MAX_NODE_NUM); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } if (pTask->plan->execNode.epSet.numOfEps > 0) { if (NULL == taosArrayPush(pTask->candidateAddrs, &pTask->plan->execNode)) { SCH_TASK_ELOG("taosArrayPush execNode to candidate addrs failed, errno:%d", errno); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } SCH_TASK_DLOG("use execNode in plan as candidate addr, numOfEps:%d", pTask->plan->execNode.epSet.numOfEps); @@ -1304,7 +1304,7 @@ int32_t schDelayLaunchTask(SSchJob *pJob, SSchTask *pTask) { SSchTimerParam *param = taosMemoryMalloc(sizeof(SSchTimerParam)); if (NULL == param) { SCH_TASK_ELOG("taosMemoryMalloc %d failed", (int)sizeof(SSchTimerParam)); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } param->rId = pJob->refId; diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 7bd40500ec..0c74e99a29 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -47,7 +47,7 @@ int32_t schedulerInit() { schMgmt.hbConnections = taosHashInit(100, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); if (NULL == schMgmt.hbConnections) { qError("taosHashInit hb connections failed"); - SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); + SCH_ERR_RET(terrno); } schMgmt.timer = taosTmrInit(0, 0, 0, "scheduler"); diff --git a/source/libs/stream/src/streamBackendRocksdb.c b/source/libs/stream/src/streamBackendRocksdb.c index 278b504e09..e77b2fefbd 100644 --- a/source/libs/stream/src/streamBackendRocksdb.c +++ b/source/libs/stream/src/streamBackendRocksdb.c @@ -412,7 +412,7 @@ int32_t remoteChkpGetDelFile(char* path, SArray* toDel) { if (taosArrayPush(toDel, &p) == NULL) { taosMemoryFree(pMeta); taosMemoryFree(p); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -427,7 +427,7 @@ void cleanDir(const char* pPath, const char* id) { if (taosIsDir(pPath)) { taosRemoveDir(pPath); - (void)taosMkDir(pPath); + TAOS_UNUSED(taosMkDir(pPath)); stInfo("%s clear dir:%s, succ", id, pPath); } } @@ -533,7 +533,7 @@ int32_t rebuildFromRemoteChkp_s3(const char* key, char* chkpPath, int64_t chkpId _EXIT: if (code != 0) { if (rename) { - (void)taosRenameFile(defaultTmp, defaultPath); + TAOS_UNUSED(taosRenameFile(defaultTmp, defaultPath)); } } @@ -653,13 +653,13 @@ int32_t backendFileCopyFilesImpl(const char* src, const char* dst) { taosMemoryFreeClear(srcName); taosMemoryFreeClear(dstName); - (void)taosCloseDir(&pDir); + TAOS_UNUSED(taosCloseDir(&pDir)); return code; _ERROR: taosMemoryFreeClear(srcName); taosMemoryFreeClear(dstName); - (void)taosCloseDir(&pDir); + TAOS_UNUSED(taosCloseDir(&pDir)); return code; } @@ -833,9 +833,8 @@ int32_t streamBackendInit(const char* streamPath, int64_t chkpId, int32_t vgId, pHandle->list = tdListNew(sizeof(SCfComparator)); TSDB_CHECK_NULL(pHandle->list, code, lino, _EXIT, terrno); - (void)taosThreadMutexInit(&pHandle->mutex, NULL); - (void)taosThreadMutexInit(&pHandle->cfMutex, NULL); - + TAOS_UNUSED(taosThreadMutexInit(&pHandle->mutex, NULL)); + TAOS_UNUSED(taosThreadMutexInit(&pHandle->cfMutex, NULL)); pHandle->cfInst = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); TSDB_CHECK_NULL(pHandle->cfInst, code, lino, _EXIT, terrno); @@ -948,11 +947,11 @@ void streamBackendCleanup(void* arg) { void streamBackendHandleCleanup(void* arg) { SBackendCfWrapper* wrapper = arg; bool remove = wrapper->remove; - (void)taosThreadRwlockWrlock(&wrapper->rwLock); + TAOS_UNUSED(taosThreadRwlockWrlock(&wrapper->rwLock)); stDebug("start to do-close backendwrapper %p, %s", wrapper, wrapper->idstr); if (wrapper->rocksdb == NULL) { - (void)taosThreadRwlockUnlock(&wrapper->rwLock); + TAOS_UNUSED(taosThreadRwlockUnlock(&wrapper->rwLock)); return; } @@ -1003,9 +1002,9 @@ void streamBackendHandleCleanup(void* arg) { wrapper->readOpts = NULL; taosMemoryFreeClear(wrapper->cfOpts); taosMemoryFreeClear(wrapper->param); - (void)taosThreadRwlockUnlock(&wrapper->rwLock); + TAOS_UNUSED(taosThreadRwlockUnlock(&wrapper->rwLock)); - (void)taosThreadRwlockDestroy(&wrapper->rwLock); + TAOS_UNUSED(taosThreadRwlockDestroy(&wrapper->rwLock)); wrapper->rocksdb = NULL; // taosReleaseRef(streamBackendId, wrapper->backendId); @@ -1099,20 +1098,20 @@ int32_t chkpMayDelObsolete(void* arg, int64_t chkpId, char* path) { int32_t code = 0; STaskDbWrapper* pBackend = arg; SArray * chkpDel = NULL, *chkpDup = NULL; - (void)taosThreadRwlockWrlock(&pBackend->chkpDirLock); + TAOS_UNUSED(taosThreadRwlockWrlock(&pBackend->chkpDirLock)); if (taosArrayPush(pBackend->chkpSaved, &chkpId) == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); + TAOS_CHECK_GOTO(terrno, NULL, _exception); } chkpDel = taosArrayInit(8, sizeof(int64_t)); if (chkpDel == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); + TAOS_CHECK_GOTO(terrno, NULL, _exception); } chkpDup = taosArrayInit(8, sizeof(int64_t)); if (chkpDup == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); + TAOS_CHECK_GOTO(terrno, NULL, _exception); } int64_t firsId = 0; @@ -1123,11 +1122,11 @@ int32_t chkpMayDelObsolete(void* arg, int64_t chkpId, char* path) { int64_t id = *(int64_t*)taosArrayGet(pBackend->chkpSaved, i); if (id >= firsId) { if (taosArrayPush(chkpDup, &id) == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); + TAOS_CHECK_GOTO(terrno, NULL, _exception); } } else { if (taosArrayPush(chkpDel, &id) == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); + TAOS_CHECK_GOTO(terrno, NULL, _exception); } } } @@ -1138,13 +1137,13 @@ int32_t chkpMayDelObsolete(void* arg, int64_t chkpId, char* path) { for (int i = 0; i < dsz; i++) { int64_t id = *(int64_t*)taosArrayGet(pBackend->chkpSaved, i); if (taosArrayPush(chkpDel, &id) == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); + TAOS_CHECK_GOTO(terrno, NULL, _exception); } } for (int i = dsz < 0 ? 0 : dsz; i < sz; i++) { int64_t id = *(int64_t*)taosArrayGet(pBackend->chkpSaved, i); if (taosArrayPush(chkpDup, &id) == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); + TAOS_CHECK_GOTO(terrno, NULL, _exception); } } } @@ -1152,7 +1151,7 @@ int32_t chkpMayDelObsolete(void* arg, int64_t chkpId, char* path) { taosArrayDestroy(pBackend->chkpSaved); pBackend->chkpSaved = chkpDup; - (void)taosThreadRwlockUnlock(&pBackend->chkpDirLock); + TAOS_UNUSED(taosThreadRwlockUnlock(&pBackend->chkpDirLock)); for (int i = 0; i < taosArrayGetSize(chkpDel); i++) { int64_t id = *(int64_t*)taosArrayGet(chkpDel, i); @@ -1169,7 +1168,7 @@ int32_t chkpMayDelObsolete(void* arg, int64_t chkpId, char* path) { _exception: taosArrayDestroy(chkpDup); taosArrayDestroy(chkpDel); - (void)taosThreadRwlockUnlock(&pBackend->chkpDirLock); + TAOS_UNUSED(taosThreadRwlockUnlock(&pBackend->chkpDirLock)); return code; } @@ -1305,7 +1304,7 @@ int32_t taskDbLoadChkpInfo(STaskDbWrapper* pBackend) { int ret = sscanf(taosGetDirEntryName(de), "checkpoint%" PRId64 "", &checkpointId); if (ret == 1) { if (taosArrayPush(pBackend->chkpSaved, &checkpointId) == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); + TAOS_CHECK_GOTO(terrno, NULL, _exception); } } } else { @@ -1315,12 +1314,12 @@ int32_t taskDbLoadChkpInfo(STaskDbWrapper* pBackend) { taosArraySort(pBackend->chkpSaved, chkpIdComp); taosMemoryFree(pChkpDir); - (void)taosCloseDir(&pDir); + TAOS_UNUSED(taosCloseDir(&pDir)); return 0; _exception: taosMemoryFree(pChkpDir); - (void)taosCloseDir(&pDir); + TAOS_UNUSED(taosCloseDir(&pDir)); return code; } int32_t chkpGetAllDbCfHandle2(STaskDbWrapper* pBackend, rocksdb_column_family_handle_t*** ppHandle) { @@ -1330,7 +1329,7 @@ int32_t chkpGetAllDbCfHandle2(STaskDbWrapper* pBackend, rocksdb_column_family_ha if (pBackend->pCf[i]) { rocksdb_column_family_handle_t* p = pBackend->pCf[i]; if (taosArrayPush(pHandle, &p) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _exception; } } @@ -1485,7 +1484,7 @@ int32_t taskDbBuildSnap(void* arg, SArray* pSnap) { // remove chkpid from chkp-in-use set taskDbUnRefChkp(pTaskDb, pTaskDb->chkpId); taskDbRemoveRef(pTaskDb); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } if (taosArrayPush(pSnap, &snap) == NULL) { @@ -1561,7 +1560,7 @@ void* taskAcquireDb(int64_t refId) { } void taskReleaseDb(int64_t refId) { // release - (void)taosReleaseRef(taskDbWrapperId, refId); + TAOS_UNUSED(taosReleaseRef(taskDbWrapperId, refId)); } int64_t taskGetDBRef(void* arg) { @@ -1622,7 +1621,7 @@ int32_t chkpLoadExtraInfo(char* pChkpIdDir, int64_t* chkpId, int64_t* processId) code = 0; _EXIT: taosMemoryFree(pDst); - (void)taosCloseFile(&pFile); + TAOS_UNUSED(taosCloseFile(&pFile)); return code; } int32_t chkpAddExtraInfo(char* pChkpIdDir, int64_t chkpId, int64_t processId) { @@ -1677,7 +1676,7 @@ int32_t chkpAddExtraInfo(char* pChkpIdDir, int64_t chkpId, int64_t processId) { code = 0; _EXIT: - (void)taosCloseFile(&pFile); + TAOS_UNUSED(taosCloseFile(&pFile)); taosMemoryFree(pDst); return code; } @@ -1735,7 +1734,7 @@ int32_t taskDbDoCheckpoint(void* arg, int64_t chkpId, int64_t processId) { goto _EXIT; } - (void)atomic_store_64(&pTaskDb->dataWritten, 0); + TAOS_UNUSED(atomic_store_64(&pTaskDb->dataWritten, 0)); pTaskDb->chkpId = chkpId; _EXIT: @@ -1743,13 +1742,13 @@ _EXIT: // clear checkpoint dir if failed if (code != 0 && pChkpDir != NULL) { if (taosDirExist(pChkpIdDir)) { - (void)taosRemoveDir(pChkpIdDir); + TAOS_UNUSED(taosRemoveDir(pChkpIdDir)); } } taosMemoryFree(pChkpIdDir); taosMemoryFree(pChkpDir); - (void)taosReleaseRef(taskDbWrapperId, refId); + TAOS_UNUSED(taosReleaseRef(taskDbWrapperId, refId)); taosMemoryFree(ppCf); return code; } @@ -1822,7 +1821,7 @@ int defaultKeyComp(void* state, const char* aBuf, size_t aLen, const char* bBuf, } int streamStateValueIsStale(char* v) { int64_t ts = 0; - (void)taosDecodeFixedI64(v, &ts); + TAOS_UNUSED(taosDecodeFixedI64(v, &ts)); return (ts != 0 && ts < taosGetTimestampMs()) ? 1 : 0; } int iterValueIsStale(rocksdb_iterator_t* iter) { @@ -1865,8 +1864,8 @@ int stateKeyDBComp(void* state, const char* aBuf, size_t aLen, const char* bBuf, p1 = taosDecodeFixedI64(p1, &key1.key.ts); p2 = taosDecodeFixedI64(p2, &key2.key.ts); - (void)taosDecodeFixedI64(p1, &key1.opNum); - (void)taosDecodeFixedI64(p2, &key2.opNum); + TAOS_UNUSED(taosDecodeFixedI64(p1, &key1.opNum)); + TAOS_UNUSED(taosDecodeFixedI64(p2, &key2.opNum)); return stateKeyCmpr(&key1, sizeof(key1), &key2, sizeof(key2)); } @@ -2062,8 +2061,8 @@ int parKeyDBComp(void* state, const char* aBuf, size_t aLen, const char* bBuf, s char* p1 = (char*)aBuf; char* p2 = (char*)bBuf; - (void)taosDecodeFixedI64(p1, &w1); - (void)taosDecodeFixedI64(p2, &w2); + TAOS_UNUSED(taosDecodeFixedI64(p1, &w1)); + TAOS_UNUSED(taosDecodeFixedI64(p2, &w2)); if (w1 == w2) { return 0; } else { @@ -2107,7 +2106,7 @@ int32_t valueIsStale(void* k, int64_t ts) { } void destroyCompare(void* arg) { - (void)arg; + TAOS_UNUSED(arg); return; } @@ -2190,7 +2189,7 @@ int32_t valueDecode(void* value, int32_t vlen, int64_t* ttl, char** dest) { // compatiable with previous data p = taosDecodeBinary(p, (void**)&pOutput, key.len); if (p == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _EXCEPT; } @@ -2205,7 +2204,7 @@ int32_t valueDecode(void* value, int32_t vlen, int64_t* ttl, char** dest) { if (key.compress == 1) { p = taosDecodeBinary(p, (void**)&pCompressData, key.len); if (p == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _EXCEPT; } pOutput = taosMemoryCalloc(1, key.rawLen); @@ -2224,7 +2223,7 @@ int32_t valueDecode(void* value, int32_t vlen, int64_t* ttl, char** dest) { } else { p = taosDecodeBinary(p, (void**)&pOutput, key.len); if (p == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _EXCEPT; } } @@ -2251,31 +2250,28 @@ _EXCEPT: } const char* compareDefaultName(void* arg) { - (void)arg; + TAOS_UNUSED(arg); return ginitDict[0].key; } const char* compareStateName(void* arg) { - (void)arg; + TAOS_UNUSED(arg); return ginitDict[1].key; } -const char* compareWinKeyName(void* arg) { - (void)arg; - return ginitDict[2].key; -} +const char* compareWinKeyName(void* arg) { return ginitDict[2].key; } const char* compareSessionKeyName(void* arg) { - (void)arg; + TAOS_UNUSED(arg); return ginitDict[3].key; } const char* compareFuncKeyName(void* arg) { - (void)arg; + TAOS_UNUSED(arg); return ginitDict[4].key; } const char* compareParKeyName(void* arg) { - (void)arg; + TAOS_UNUSED(arg); return ginitDict[5].key; } const char* comparePartagKeyName(void* arg) { - (void)arg; + TAOS_UNUSED(arg); return ginitDict[6].key; } @@ -2303,7 +2299,7 @@ const char* compactFilteFactoryNameFunc(void* arg) { return "stream_compact_factory_filter_func"; } -void destroyCompactFilte(void* arg) { (void)arg; } +void destroyCompactFilte(void* arg) { TAOS_UNUSED(arg); } unsigned char compactFilte(void* arg, int level, const char* key, size_t klen, const char* val, size_t vlen, char** newval, size_t* newvlen, unsigned char* value_changed) { return streamStateValueIsStale((char*)val) ? 1 : 0; @@ -2416,7 +2412,7 @@ void taskDbRemoveRef(void* pTaskDb) { } STaskDbWrapper* pBackend = pTaskDb; - (void)taosReleaseRef(taskDbWrapperId, pBackend->refId); + TAOS_UNUSED(taosReleaseRef(taskDbWrapperId, pBackend->refId)); } void taskDbSetClearFileFlag(void* pTaskDb) { @@ -2491,24 +2487,24 @@ void taskDbInitChkpOpt(STaskDbWrapper* pTaskDb) { pTaskDb->chkpId = -1; pTaskDb->chkpCap = 4; pTaskDb->chkpSaved = taosArrayInit(4, sizeof(int64_t)); - (void)taskDbLoadChkpInfo(pTaskDb); + TAOS_UNUSED(taskDbLoadChkpInfo(pTaskDb)); pTaskDb->chkpInUse = taosArrayInit(4, sizeof(int64_t)); - (void)taosThreadRwlockInit(&pTaskDb->chkpDirLock, NULL); + TAOS_UNUSED(taosThreadRwlockInit(&pTaskDb->chkpDirLock, NULL)); } void taskDbRefChkp(STaskDbWrapper* pTaskDb, int64_t chkp) { - (void)taosThreadRwlockWrlock(&pTaskDb->chkpDirLock); + TAOS_UNUSED(taosThreadRwlockWrlock(&pTaskDb->chkpDirLock)); if (taosArrayPush(pTaskDb->chkpInUse, &chkp) == NULL) { stError("failed to push chkp: %" PRIi64 " into inuse", chkp); } taosArraySort(pTaskDb->chkpInUse, chkpIdComp); - (void)taosThreadRwlockUnlock(&pTaskDb->chkpDirLock); + TAOS_UNUSED(taosThreadRwlockUnlock(&pTaskDb->chkpDirLock)); } void taskDbUnRefChkp(STaskDbWrapper* pTaskDb, int64_t chkp) { - (void)taosThreadRwlockWrlock(&pTaskDb->chkpDirLock); + TAOS_UNUSED(taosThreadRwlockWrlock(&pTaskDb->chkpDirLock)); int32_t size = taosArrayGetSize(pTaskDb->chkpInUse); for (int i = 0; i < size; i++) { int64_t* p = taosArrayGet(pTaskDb->chkpInUse, i); @@ -2517,13 +2513,13 @@ void taskDbUnRefChkp(STaskDbWrapper* pTaskDb, int64_t chkp) { break; } } - (void)taosThreadRwlockUnlock(&pTaskDb->chkpDirLock); + TAOS_UNUSED(taosThreadRwlockUnlock(&pTaskDb->chkpDirLock)); } void taskDbDestroyChkpOpt(STaskDbWrapper* pTaskDb) { taosArrayDestroy(pTaskDb->chkpSaved); taosArrayDestroy(pTaskDb->chkpInUse); - (void)taosThreadRwlockDestroy(&pTaskDb->chkpDirLock); + TAOS_UNUSED(taosThreadRwlockDestroy(&pTaskDb->chkpDirLock)); } int32_t taskDbBuildFullPath(char* path, char* key, char** dbFullPath, char** stateFullPath) { @@ -2569,9 +2565,9 @@ int32_t taskDbBuildFullPath(char* path, char* key, char** dbFullPath, char** sta void taskDbUpdateChkpId(void* pTaskDb, int64_t chkpId) { STaskDbWrapper* p = pTaskDb; - (void)streamMutexLock(&p->mutex); + TAOS_UNUSED(streamMutexLock(&p->mutex)); p->chkpId = chkpId; - (void)streamMutexUnlock(&p->mutex); + TAOS_UNUSED(streamMutexUnlock(&p->mutex)); } STaskDbWrapper* taskDbOpenImpl(const char* key, char* statePath, char* dbPath) { @@ -2587,7 +2583,7 @@ STaskDbWrapper* taskDbOpenImpl(const char* key, char* statePath, char* dbPath) { pTaskDb->idstr = key ? taosStrdup(key) : NULL; pTaskDb->path = statePath ? taosStrdup(statePath) : NULL; - (void)taosThreadMutexInit(&pTaskDb->mutex, NULL); + TAOS_UNUSED(taosThreadMutexInit(&pTaskDb->mutex, NULL)); taskDbInitChkpOpt(pTaskDb); taskDbInitOpt(pTaskDb); @@ -2772,7 +2768,7 @@ int32_t taskDbGenChkpUploadData__rsync(STaskDbWrapper* pDb, int64_t chkpId, char char* buf = taosMemoryCalloc(1, cap); if (buf == NULL) { - (void)taosReleaseRef(taskDbWrapperId, refId); + TAOS_UNUSED(taosReleaseRef(taskDbWrapperId, refId)); return terrno; } @@ -2780,7 +2776,7 @@ int32_t taskDbGenChkpUploadData__rsync(STaskDbWrapper* pDb, int64_t chkpId, char snprintf(buf, cap, "%s%s%s%s%s%" PRId64 "", pDb->path, TD_DIRSEP, "checkpoints", TD_DIRSEP, "checkpoint", chkpId); if (nBytes <= 0 || nBytes >= cap) { taosMemoryFree(buf); - (void)taosReleaseRef(taskDbWrapperId, refId); + TAOS_UNUSED(taosReleaseRef(taskDbWrapperId, refId)); return TSDB_CODE_OUT_OF_RANGE; } @@ -2791,7 +2787,7 @@ int32_t taskDbGenChkpUploadData__rsync(STaskDbWrapper* pDb, int64_t chkpId, char taosMemoryFree(buf); } - (void)taosReleaseRef(taskDbWrapperId, refId); + TAOS_UNUSED(taosReleaseRef(taskDbWrapperId, refId)); return code; } @@ -3028,7 +3024,7 @@ int32_t streamStateOpenBackendCf(void* backend, char* name, char** cfs, int32_t inst->dbOpt = handle->dbOpt; rocksdb_writeoptions_disable_WAL(inst->wOpt, 1); - (void)taosHashPut(handle->cfInst, idstr, strlen(idstr) + 1, &inst, sizeof(void*)); + TAOS_UNUSED(taosHashPut(handle->cfInst, idstr, strlen(idstr) + 1, &inst, sizeof(void*))); } else { inst = *pInst; } @@ -3269,9 +3265,9 @@ rocksdb_iterator_t* streamStateIterCreate(SStreamState* pState, const char* cfKe break; \ } \ STaskDbWrapper* wrapper = pState->pTdbState->pOwner->pBackend; \ - (void)atomic_add_fetch_64(&wrapper->dataWritten, 1); \ + TAOS_UNUSED(atomic_add_fetch_64(&wrapper->dataWritten, 1)); \ char toString[128] = {0}; \ - if (stDebugFlag & DEBUG_TRACE) (void)(ginitDict[i].toStrFunc((void*)key, toString)); \ + if (stDebugFlag & DEBUG_TRACE) TAOS_UNUSED((ginitDict[i].toStrFunc((void*)key, toString))); \ int32_t klen = ginitDict[i].enFunc((void*)key, buf); \ rocksdb_column_family_handle_t* pHandle = ((rocksdb_column_family_handle_t**)wrapper->pCf)[ginitDict[i].idx]; \ rocksdb_writeoptions_t* opts = wrapper->writeOpt; \ @@ -3303,7 +3299,7 @@ rocksdb_iterator_t* streamStateIterCreate(SStreamState* pState, const char* cfKe } \ STaskDbWrapper* wrapper = pState->pTdbState->pOwner->pBackend; \ char toString[128] = {0}; \ - if (stDebugFlag & DEBUG_TRACE) (void)(ginitDict[i].toStrFunc((void*)key, toString)); \ + if (stDebugFlag & DEBUG_TRACE) TAOS_UNUSED((ginitDict[i].toStrFunc((void*)key, toString))); \ int32_t klen = ginitDict[i].enFunc((void*)key, buf); \ rocksdb_column_family_handle_t* pHandle = ((rocksdb_column_family_handle_t**)wrapper->pCf)[ginitDict[i].idx]; \ rocksdb_t* db = wrapper->db; \ @@ -3346,9 +3342,9 @@ rocksdb_iterator_t* streamStateIterCreate(SStreamState* pState, const char* cfKe break; \ } \ STaskDbWrapper* wrapper = pState->pTdbState->pOwner->pBackend; \ - (void)atomic_add_fetch_64(&wrapper->dataWritten, 1); \ + TAOS_UNUSED(atomic_add_fetch_64(&wrapper->dataWritten, 1)); \ char toString[128] = {0}; \ - if (stDebugFlag & DEBUG_TRACE) (void)(ginitDict[i].toStrFunc((void*)key, toString)); \ + if (stDebugFlag & DEBUG_TRACE) TAOS_UNUSED(ginitDict[i].toStrFunc((void*)key, toString)); \ int32_t klen = ginitDict[i].enFunc((void*)key, buf); \ rocksdb_column_family_handle_t* pHandle = ((rocksdb_column_family_handle_t**)wrapper->pCf)[ginitDict[i].idx]; \ rocksdb_t* db = wrapper->db; \ @@ -3387,7 +3383,7 @@ int32_t streamStateClear_rocksdb(SStreamState* pState) { stDebug("streamStateClear_rocksdb"); STaskDbWrapper* wrapper = pState->pTdbState->pOwner->pBackend; - (void)atomic_add_fetch_64(&wrapper->dataWritten, 1); + TAOS_UNUSED(atomic_add_fetch_64(&wrapper->dataWritten, 1)); char sKeyStr[128] = {0}; char eKeyStr[128] = {0}; @@ -3403,8 +3399,8 @@ int32_t streamStateClear_rocksdb(SStreamState* pState) { if (err != NULL) { char toStringStart[128] = {0}; char toStringEnd[128] = {0}; - (void)stateKeyToString(&sKey, toStringStart); - (void)stateKeyToString(&eKey, toStringEnd); + TAOS_UNUSED(stateKeyToString(&sKey, toStringStart)); + TAOS_UNUSED(stateKeyToString(&eKey, toStringEnd)); stWarn("failed to delete range cf(state) start: %s, end:%s, reason:%s", toStringStart, toStringEnd, err); taosMemoryFree(err); @@ -3439,7 +3435,6 @@ int32_t streamStateGetFirst_rocksdb(SStreamState* pState, SWinKey* key) { } int32_t streamStateGetGroupKVByCur_rocksdb(SStreamStateCur* pCur, SWinKey* pKey, const void** pVal, int32_t* pVLen) { - stDebug("streamStateGetGroupKVByCur_rocksdb"); if (!pCur) { return -1; } @@ -3465,7 +3460,7 @@ int32_t streamStateAddIfNotExist_rocksdb(SStreamState* pState, const SWinKey* ke } *pVal = taosMemoryMalloc(size); if (*pVal == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memset(*pVal, 0, size); return 0; @@ -3483,7 +3478,7 @@ int32_t streamStateGetKVByCur_rocksdb(SStreamStateCur* pCur, SWinKey* pKey, cons if (rocksdb_iter_valid(pCur->iter) && !iterValueIsStale(pCur->iter)) { size_t tlen; char* keyStr = (char*)rocksdb_iter_key(pCur->iter, &tlen); - (void)stateKeyDecode((void*)pKtmp, keyStr); + TAOS_UNUSED(stateKeyDecode((void*)pKtmp, keyStr)); if (pKtmp->opNum != pCur->number) { return -1; } @@ -3536,7 +3531,7 @@ SStreamStateCur* streamStateSeekKeyNext_rocksdb(SStreamState* pState, const SWin SStateKey curKey; size_t kLen; char* keyStr = (char*)rocksdb_iter_key(pCur->iter, &kLen); - (void)stateKeyDecode((void*)&curKey, keyStr); + TAOS_UNUSED(stateKeyDecode((void*)&curKey, keyStr)); if (stateKeyCmpr(&sKey, sizeof(sKey), &curKey, sizeof(curKey)) > 0) { return pCur; } @@ -3558,7 +3553,7 @@ SStreamStateCur* streamStateSeekToLast_rocksdb(SStreamState* pState) { { char tbuf[256] = {0}; - (void)stateKeyToString((void*)&maxStateKey, tbuf); + TAOS_UNUSED(stateKeyToString((void*)&maxStateKey, tbuf)); stDebug("seek to last:%s", tbuf); } @@ -3609,7 +3604,7 @@ SStreamStateCur* streamStateGetCur_rocksdb(SStreamState* pState, const SWinKey* SStateKey curKey; size_t kLen = 0; char* keyStr = (char*)rocksdb_iter_key(pCur->iter, &kLen); - (void)stateKeyDecode((void*)&curKey, keyStr); + TAOS_UNUSED(stateKeyDecode((void*)&curKey, keyStr)); if (stateKeyCmpr(&sKey, sizeof(sKey), &curKey, sizeof(curKey)) == 0) { pCur->number = pState->number; @@ -3757,7 +3752,7 @@ SStreamStateCur* streamStateSessionSeekKeyCurrentPrev_rocksdb(SStreamState* pSta size_t klen; const char* iKey = rocksdb_iter_key(pCur->iter, &klen); SStateSessionKey curKey = {0}; - (void)stateSessionKeyDecode(&curKey, (char*)iKey); + TAOS_UNUSED(stateSessionKeyDecode(&curKey, (char*)iKey)); if (stateSessionKeyCmpr(&sKey, sizeof(sKey), &curKey, sizeof(curKey)) >= 0) return pCur; rocksdb_iter_prev(pCur->iter); @@ -3794,7 +3789,7 @@ SStreamStateCur* streamStateSessionSeekKeyCurrentNext_rocksdb(SStreamState* pSta size_t klen; const char* iKey = rocksdb_iter_key(pCur->iter, &klen); SStateSessionKey curKey = {0}; - (void)stateSessionKeyDecode(&curKey, (char*)iKey); + TAOS_UNUSED(stateSessionKeyDecode(&curKey, (char*)iKey)); if (stateSessionKeyCmpr(&sKey, sizeof(sKey), &curKey, sizeof(curKey)) <= 0) return pCur; rocksdb_iter_next(pCur->iter); @@ -3834,7 +3829,7 @@ SStreamStateCur* streamStateSessionSeekKeyNext_rocksdb(SStreamState* pState, con size_t klen; const char* iKey = rocksdb_iter_key(pCur->iter, &klen); SStateSessionKey curKey = {0}; - (void)stateSessionKeyDecode(&curKey, (char*)iKey); + TAOS_UNUSED(stateSessionKeyDecode(&curKey, (char*)iKey)); if (stateSessionKeyCmpr(&sKey, sizeof(sKey), &curKey, sizeof(curKey)) < 0) return pCur; rocksdb_iter_next(pCur->iter); @@ -3874,7 +3869,7 @@ SStreamStateCur* streamStateSessionSeekKeyPrev_rocksdb(SStreamState* pState, con size_t klen; const char* iKey = rocksdb_iter_key(pCur->iter, &klen); SStateSessionKey curKey = {0}; - (void)stateSessionKeyDecode(&curKey, (char*)iKey); + TAOS_UNUSED(stateSessionKeyDecode(&curKey, (char*)iKey)); if (stateSessionKeyCmpr(&sKey, sizeof(sKey), &curKey, sizeof(curKey)) > 0) return pCur; rocksdb_iter_prev(pCur->iter); @@ -3886,7 +3881,6 @@ SStreamStateCur* streamStateSessionSeekKeyPrev_rocksdb(SStreamState* pState, con } int32_t streamStateSessionGetKVByCur_rocksdb(SStreamStateCur* pCur, SSessionKey* pKey, void** pVal, int32_t* pVLen) { - stDebug("streamStateSessionGetKVByCur_rocksdb"); if (!pCur) { return -1; } @@ -3897,7 +3891,7 @@ int32_t streamStateSessionGetKVByCur_rocksdb(SStreamStateCur* pCur, SSessionKey* return -1; } const char* curKey = rocksdb_iter_key(pCur->iter, (size_t*)&kLen); - (void)stateSessionKeyDecode((void*)&ktmp, (char*)curKey); + TAOS_UNUSED(stateSessionKeyDecode((void*)&ktmp, (char*)curKey)); if (pVal != NULL) *pVal = NULL; if (pVLen != NULL) *pVLen = 0; @@ -3976,7 +3970,7 @@ SStreamStateCur* streamStateFillGetCur_rocksdb(SStreamState* pState, const SWinK size_t kLen; SWinKey curKey; char* keyStr = (char*)rocksdb_iter_key(pCur->iter, &kLen); - (void)winKeyDecode((void*)&curKey, keyStr); + TAOS_UNUSED(winKeyDecode((void*)&curKey, keyStr)); if (winKeyCmpr(key, sizeof(*key), &curKey, sizeof(curKey)) == 0) { return pCur; } @@ -3986,7 +3980,6 @@ SStreamStateCur* streamStateFillGetCur_rocksdb(SStreamState* pState, const SWinK return NULL; } int32_t streamStateFillGetKVByCur_rocksdb(SStreamStateCur* pCur, SWinKey* pKey, const void** pVal, int32_t* pVLen) { - stDebug("streamStateFillGetKVByCur_rocksdb"); if (!pCur) { return -1; } @@ -3996,7 +3989,7 @@ int32_t streamStateFillGetKVByCur_rocksdb(SStreamStateCur* pCur, SWinKey* pKey, } size_t klen, vlen; char* keyStr = (char*)rocksdb_iter_key(pCur->iter, &klen); - (void)winKeyDecode(&winKey, keyStr); + TAOS_UNUSED(winKeyDecode(&winKey, keyStr)); const char* valStr = rocksdb_iter_value(pCur->iter, &vlen); int32_t len = valueDecode((void*)valStr, vlen, NULL, (char**)pVal); @@ -4037,7 +4030,7 @@ SStreamStateCur* streamStateFillSeekKeyNext_rocksdb(SStreamState* pState, const SWinKey curKey; size_t kLen = 0; char* keyStr = (char*)rocksdb_iter_key(pCur->iter, &kLen); - (void)winKeyDecode((void*)&curKey, keyStr); + TAOS_UNUSED(winKeyDecode((void*)&curKey, keyStr)); if (winKeyCmpr(key, sizeof(*key), &curKey, sizeof(curKey)) < 0) { return pCur; } @@ -4074,7 +4067,7 @@ SStreamStateCur* streamStateFillSeekKeyPrev_rocksdb(SStreamState* pState, const SWinKey curKey; size_t kLen = 0; char* keyStr = (char*)rocksdb_iter_key(pCur->iter, &kLen); - (void)winKeyDecode((void*)&curKey, keyStr); + TAOS_UNUSED(winKeyDecode((void*)&curKey, keyStr)); if (winKeyCmpr(key, sizeof(*key), &curKey, sizeof(curKey)) > 0) { return pCur; } @@ -4164,7 +4157,7 @@ int32_t streamStateSessionAddIfNotExist_rocksdb(SStreamState* pState, SSessionKe void* tmp = taosMemoryMalloc(valSize); if (tmp == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SStreamStateCur* pCur = streamStateSessionSeekKeyCurrentPrev_rocksdb(pState, key); @@ -4216,7 +4209,7 @@ void streamStateSessionClear_rocksdb(SStreamState* pState) { if (code == 0 && size > 0) { memset(buf, 0, size); // refactor later - (void)streamStateSessionPut_rocksdb(pState, &delKey, buf, size); + TAOS_UNUSED(streamStateSessionPut_rocksdb(pState, &delKey, buf, size)); } else { taosMemoryFreeClear(buf); break; @@ -4407,7 +4400,7 @@ int32_t streamDefaultIterGet_rocksdb(SStreamState* pState, const void* start, co int64_t checkPoint = 0; if (sscanf(key + strlen(key), ":%" PRId64 "", &checkPoint) == 1) { if (taosArrayPush(result, &checkPoint) == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } } @@ -4481,7 +4474,7 @@ void streamStateDestroyBatch(void* pBatch) { rocksdb_writebatch_destroy((rock int32_t streamStatePutBatch(SStreamState* pState, const char* cfKeyName, rocksdb_writebatch_t* pBatch, void* key, void* val, int32_t vlen, int64_t ttl) { STaskDbWrapper* wrapper = pState->pTdbState->pOwner->pBackend; - (void)atomic_add_fetch_64(&wrapper->dataWritten, 1); + TAOS_UNUSED(atomic_add_fetch_64(&wrapper->dataWritten, 1)); int i = streamStateGetCfIdx(pState, cfKeyName); if (i < 0) { @@ -4501,7 +4494,7 @@ int32_t streamStatePutBatch(SStreamState* pState, const char* cfKeyName, rocksdb { char tbuf[256] = {0}; - (void)(ginitDict[i].toStrFunc((void*)key, tbuf)); + TAOS_UNUSED(ginitDict[i].toStrFunc((void*)key, tbuf)); stTrace("streamState str: %s succ to write to %s_%s, len: %d", tbuf, wrapper->idstr, ginitDict[i].key, vlen); } return 0; @@ -4516,7 +4509,7 @@ int32_t streamStatePutBatchOptimize(SStreamState* pState, int32_t cfIdx, rocksdb STaskDbWrapper* wrapper = pState->pTdbState->pOwner->pBackend; - (void)atomic_add_fetch_64(&wrapper->dataWritten, 1); + TAOS_UNUSED(atomic_add_fetch_64(&wrapper->dataWritten, 1)); rocksdb_column_family_handle_t* pCf = wrapper->pCf[ginitDict[cfIdx].idx]; rocksdb_writebatch_put_cf((rocksdb_writebatch_t*)pBatch, pCf, buf, (size_t)klen, ttlV, (size_t)ttlVLen); @@ -4527,7 +4520,7 @@ int32_t streamStatePutBatchOptimize(SStreamState* pState, int32_t cfIdx, rocksdb { char tbuf[256] = {0}; - (void)(ginitDict[cfIdx].toStrFunc((void*)key, tbuf)); + TAOS_UNUSED(ginitDict[cfIdx].toStrFunc((void*)key, tbuf)); stTrace("streamState str: %s succ to write to %s_%s", tbuf, wrapper->idstr, ginitDict[cfIdx].key); } return 0; @@ -4535,7 +4528,7 @@ int32_t streamStatePutBatchOptimize(SStreamState* pState, int32_t cfIdx, rocksdb int32_t streamStatePutBatch_rocksdb(SStreamState* pState, void* pBatch) { char* err = NULL; STaskDbWrapper* wrapper = pState->pTdbState->pOwner->pBackend; - (void)atomic_add_fetch_64(&wrapper->dataWritten, 1); + TAOS_UNUSED(atomic_add_fetch_64(&wrapper->dataWritten, 1)); rocksdb_write(wrapper->db, wrapper->writeOpt, (rocksdb_writebatch_t*)pBatch, &err); if (err != NULL) { stError("streamState failed to write batch, err:%s", err); @@ -4624,10 +4617,10 @@ int32_t compareHashTableImpl(SHashObj* p1, SHashObj* p2, SArray* diff) { if (fname == NULL) { return terrno; } - (void)strncpy(fname, name, len); + TAOS_UNUSED(strncpy(fname, name, len)); if (taosArrayPush(diff, &fname) == NULL) { taosMemoryFree(fname); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } pIter = taosHashIterate(p2, pIter); @@ -4704,7 +4697,7 @@ void dbChkpDebugInfo(SDbChkp* pDb) { int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) { int32_t code = 0; int32_t nBytes; - (void)taosThreadRwlockWrlock(&p->rwLock); + TAOS_UNUSED(taosThreadRwlockWrlock(&p->rwLock)); p->preCkptId = p->curChkpId; p->curChkpId = chkpId; @@ -4722,7 +4715,7 @@ int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) { nBytes = snprintf(p->buf, p->len, "%s%s%s%scheckpoint%" PRId64 "", p->path, TD_DIRSEP, "checkpoints", TD_DIRSEP, chkpId); if (nBytes <= 0 || nBytes >= p->len) { - (void)taosThreadRwlockUnlock(&p->rwLock); + TAOS_UNUSED(taosThreadRwlockUnlock(&p->rwLock)); return TSDB_CODE_OUT_OF_RANGE; } @@ -4732,7 +4725,7 @@ int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) { TdDirPtr pDir = taosOpenDir(p->buf); if (pDir == NULL) { - (void)taosThreadRwlockUnlock(&p->rwLock); + TAOS_UNUSED(taosThreadRwlockUnlock(&p->rwLock)); return terrno; } @@ -4746,7 +4739,7 @@ int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) { p->pCurrent = taosStrdup(name); if (p->pCurrent == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } continue; @@ -4756,7 +4749,7 @@ int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) { taosMemoryFreeClear(p->pManifest); p->pManifest = taosStrdup(name); if (p->pManifest == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } continue; @@ -4768,9 +4761,9 @@ int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) { continue; } } - (void)taosCloseDir(&pDir); + TAOS_UNUSED(taosCloseDir(&pDir)); if (code != 0) { - (void)taosThreadRwlockUnlock(&p->rwLock); + TAOS_UNUSED(taosThreadRwlockUnlock(&p->rwLock)); return code; } @@ -4782,15 +4775,15 @@ int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) { if (name != NULL && !isBkdDataMeta(name, len)) { char* fname = taosMemoryCalloc(1, len + 1); if (fname == NULL) { - (void)taosThreadRwlockUnlock(&p->rwLock); + TAOS_UNUSED(taosThreadRwlockUnlock(&p->rwLock)); return terrno; } - (void)strncpy(fname, name, len); + TAOS_UNUSED(strncpy(fname, name, len)); if (taosArrayPush(p->pAdd, &fname) == NULL) { taosMemoryFree(fname); - (void)taosThreadRwlockUnlock(&p->rwLock); - return TSDB_CODE_OUT_OF_MEMORY; + TAOS_UNUSED(taosThreadRwlockUnlock(&p->rwLock)); + return terrno; } } pIter = taosHashIterate(p->pSstTbl[1 - p->idx], pIter); @@ -4823,7 +4816,7 @@ int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) { p->idx = 1 - p->idx; - (void)taosThreadRwlockUnlock(&p->rwLock); + TAOS_UNUSED(taosThreadRwlockUnlock(&p->rwLock)); return code; } @@ -4842,7 +4835,7 @@ int32_t dbChkpCreate(char* path, int64_t initChkpId, SDbChkp** ppChkp) { p->preCkptId = -1; p->pSST = taosArrayInit(64, sizeof(void*)); if (p->pSST == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; dbChkpDestroy(p); return code; } @@ -4858,30 +4851,30 @@ int32_t dbChkpCreate(char* path, int64_t initChkpId, SDbChkp** ppChkp) { p->idx = 0; p->pSstTbl[0] = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); if (p->pSstTbl[0] == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _EXIT; } p->pSstTbl[1] = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); if (p->pSstTbl[1] == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _EXIT; } p->pAdd = taosArrayInit(64, sizeof(void*)); if (p->pAdd == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _EXIT; } p->pDel = taosArrayInit(64, sizeof(void*)); if (p->pDel == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _EXIT; } p->update = 0; - (void)taosThreadRwlockInit(&p->rwLock, NULL); + TAOS_UNUSED(taosThreadRwlockInit(&p->rwLock, NULL)); SArray* list = NULL; code = dbChkpGetDelta(p, initChkpId, list); @@ -4922,7 +4915,7 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { static char* chkpMeta = "META"; int32_t code = 0; - (void)taosThreadRwlockRdlock(&p->rwLock); + TAOS_UNUSED(taosThreadRwlockRdlock(&p->rwLock)); int32_t cap = p->len + 128; @@ -4992,12 +4985,12 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { char* filename = taosArrayGetP(p->pDel, i); char* p = taosStrdup(filename); if (p == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _ERROR; } if (taosArrayPush(list, &p) == NULL) { taosMemoryFree(p); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _ERROR; } } @@ -5065,7 +5058,7 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { if (nBytes <= 0 || nBytes >= sizeof(content)) { code = TSDB_CODE_OUT_OF_RANGE; stError("chkp failed to format meta file: %s, reason: invalid msg", dstDir); - (void)taosCloseFile(&pFile); + TAOS_UNUSED(taosCloseFile(&pFile)); goto _ERROR; } @@ -5073,10 +5066,10 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { if (nBytes != strlen(content)) { code = terrno; stError("chkp failed to write meta file: %s,reason:%s", dstDir, tstrerror(code)); - (void)taosCloseFile(&pFile); + TAOS_UNUSED(taosCloseFile(&pFile)); goto _ERROR; } - (void)taosCloseFile(&pFile); + TAOS_UNUSED(taosCloseFile(&pFile)); // clear delta data buf taosArrayClearP(p->pAdd, taosMemoryFree); @@ -5085,7 +5078,7 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { _ERROR: taosMemoryFree(buffer); - (void)taosThreadRwlockUnlock(&p->rwLock); + TAOS_UNUSED(taosThreadRwlockUnlock(&p->rwLock)); return code; } @@ -5098,14 +5091,14 @@ int32_t bkdMgtCreate(char* path, SBkdMgt** mgt) { p->pDbChkpTbl = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if (p->pDbChkpTbl == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; bkdMgtDestroy(p); return code; } p->path = taosStrdup(path); if (p->path == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; bkdMgtDestroy(p); return code; } @@ -5130,7 +5123,7 @@ void bkdMgtDestroy(SBkdMgt* bm) { pIter = taosHashIterate(bm->pDbChkpTbl, pIter); } - (void)taosThreadRwlockDestroy(&bm->rwLock); + TAOS_UNUSED(taosThreadRwlockDestroy(&bm->rwLock)); taosMemoryFree(bm->path); taosHashCleanup(bm->pDbChkpTbl); @@ -5138,7 +5131,7 @@ void bkdMgtDestroy(SBkdMgt* bm) { } int32_t bkdMgtGetDelta(SBkdMgt* bm, char* taskId, int64_t chkpId, SArray* list, char* dname) { int32_t code = 0; - (void)taosThreadRwlockWrlock(&bm->rwLock); + TAOS_UNUSED(taosThreadRwlockWrlock(&bm->rwLock)); SDbChkp** ppChkp = taosHashGet(bm->pDbChkpTbl, taskId, strlen(taskId)); SDbChkp* pChkp = ppChkp != NULL ? *ppChkp : NULL; @@ -5146,14 +5139,14 @@ int32_t bkdMgtGetDelta(SBkdMgt* bm, char* taskId, int64_t chkpId, SArray* list, int32_t cap = strlen(bm->path) + 64; char* path = taosMemoryCalloc(1, cap); if (path == NULL) { - (void)taosThreadRwlockUnlock(&bm->rwLock); + TAOS_UNUSED(taosThreadRwlockUnlock(&bm->rwLock)); return terrno; } int32_t nBytes = snprintf(path, cap, "%s%s%s", bm->path, TD_DIRSEP, taskId); if (nBytes <= 0 || nBytes >= cap) { taosMemoryFree(path); - (void)taosThreadRwlockUnlock(&bm->rwLock); + TAOS_UNUSED(taosThreadRwlockUnlock(&bm->rwLock)); code = TSDB_CODE_OUT_OF_RANGE; return code; } @@ -5162,20 +5155,20 @@ int32_t bkdMgtGetDelta(SBkdMgt* bm, char* taskId, int64_t chkpId, SArray* list, code = dbChkpCreate(path, chkpId, &p); if (code != 0) { taosMemoryFree(path); - (void)taosThreadRwlockUnlock(&bm->rwLock); + TAOS_UNUSED(taosThreadRwlockUnlock(&bm->rwLock)); return code; } if (taosHashPut(bm->pDbChkpTbl, taskId, strlen(taskId), &p, sizeof(void*)) != 0) { dbChkpDestroy(p); - (void)taosThreadRwlockUnlock(&bm->rwLock); + TAOS_UNUSED(taosThreadRwlockUnlock(&bm->rwLock)); code = terrno; return code; } pChkp = p; code = dbChkpDumpTo(pChkp, dname, list); - (void)taosThreadRwlockUnlock(&bm->rwLock); + TAOS_UNUSED(taosThreadRwlockUnlock(&bm->rwLock)); return code; } else { code = dbChkpGetDelta(pChkp, chkpId, NULL); @@ -5184,7 +5177,7 @@ int32_t bkdMgtGetDelta(SBkdMgt* bm, char* taskId, int64_t chkpId, SArray* list, } } - (void)taosThreadRwlockUnlock(&bm->rwLock); + TAOS_UNUSED(taosThreadRwlockUnlock(&bm->rwLock)); return code; } diff --git a/source/libs/stream/src/streamCheckpoint.c b/source/libs/stream/src/streamCheckpoint.c index 769116264d..699774ed52 100644 --- a/source/libs/stream/src/streamCheckpoint.c +++ b/source/libs/stream/src/streamCheckpoint.c @@ -62,7 +62,7 @@ int32_t createChkptTriggerBlock(SStreamTask* pTask, int32_t checkpointType, int6 if (pChkpoint->blocks == NULL) { taosMemoryFree(pBlock); taosFreeQitem(pChkpoint); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } void* p = taosArrayPush(pChkpoint->blocks, pBlock); @@ -70,7 +70,7 @@ int32_t createChkptTriggerBlock(SStreamTask* pTask, int32_t checkpointType, int6 taosArrayDestroy(pChkpoint->blocks); taosMemoryFree(pBlock); taosFreeQitem(pChkpoint); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } *pRes = pChkpoint; @@ -740,7 +740,7 @@ int32_t uploadCheckpointData(SStreamTask* pTask, int64_t checkpointId, int64_t d SArray* toDelFiles = taosArrayInit(4, POINTER_BYTES); if (toDelFiles == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if ((code = taskDbGenChkpUploadData(pTask->pBackend, pMeta->bkdChkptMgt, checkpointId, type, &path, toDelFiles, @@ -900,9 +900,6 @@ static int32_t doChkptStatusCheck(SStreamTask* pTask) { int32_t ref = streamCleanBeforeQuitTmr(pTmrInfo, pTask); stDebug("s-task:%s vgId:%d all checkpoint-trigger recv, quit from monitor checkpoint-trigger, ref:%d", id, vgId, ref); - -// streamMutexUnlock(&pTask->lock); -// streamMetaReleaseTask(pTask->pMeta, pTask); return -1; } @@ -911,9 +908,6 @@ static int32_t doChkptStatusCheck(SStreamTask* pTask) { stWarn("s-task:%s vgId:%d checkpoint-trigger retrieve by previous checkpoint procedure, checkpointId:%" PRId64 ", quit, ref:%d", id, vgId, pTmrInfo->launchChkptId, ref); - -// streamMutexUnlock(&pActiveInfo->lock); -// streamMetaReleaseTask(pTask->pMeta, pTask); return -1; } @@ -922,9 +916,6 @@ static int32_t doChkptStatusCheck(SStreamTask* pTask) { int32_t ref = streamCleanBeforeQuitTmr(pTmrInfo, pTask); stWarn("s-task:%s vgId:%d active checkpoint may be cleared, quit from retrieve checkpoint-trigger send tmr, ref:%d", id, vgId, ref); - -// streamMutexUnlock(&pActiveInfo->lock); -// streamMetaReleaseTask(pTask->pMeta, pTask); return -1; } @@ -1020,7 +1011,7 @@ void checkpointTriggerMonitorFn(void* param, void* tmrId) { int32_t code = doChkptStatusCheck(pTask); if (code) { - streamMutexUnlock(&pTask->lock); + streamMutexUnlock(&pActiveInfo->lock); streamMetaReleaseTask(pTask->pMeta, pTask); return; } @@ -1086,7 +1077,7 @@ int32_t doSendRetrieveTriggerMsg(SStreamTask* pTask, SArray* pNotSendList) { SRetrieveChkptTriggerReq* pReq = rpcMallocCont(sizeof(SRetrieveChkptTriggerReq)); if (pReq == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; stError("vgId:%d failed to create msg to retrieve trigger msg for task:%s exec, code:out of memory", vgId, pId); continue; } diff --git a/source/libs/stream/src/streamData.c b/source/libs/stream/src/streamData.c index 64d79d6b42..72d0fa3232 100644 --- a/source/libs/stream/src/streamData.c +++ b/source/libs/stream/src/streamData.c @@ -215,6 +215,37 @@ void streamDataSubmitDestroy(SStreamDataSubmit* pDataSubmit) { } } +int32_t streamMergedSubmitNew(SStreamMergedSubmit** pSubmit) { + *pSubmit = NULL; + + int32_t code = taosAllocateQitem(sizeof(SStreamMergedSubmit), DEF_QITEM, 0, (void**)pSubmit); + if (code) { + return TSDB_CODE_OUT_OF_MEMORY; + } + + (*pSubmit)->submits = taosArrayInit(0, sizeof(SPackedData)); + if ((*pSubmit)->submits == NULL) { + taosFreeQitem(*pSubmit); + *pSubmit = NULL; + return terrno; + } + + (*pSubmit)->type = STREAM_INPUT__MERGED_SUBMIT; + return TSDB_CODE_SUCCESS; +} + +int32_t streamMergeSubmit(SStreamMergedSubmit* pMerged, SStreamDataSubmit* pSubmit) { + void* p = taosArrayPush(pMerged->submits, &pSubmit->submit); + if (p == NULL) { + return terrno; + } + + if (pSubmit->ver > pMerged->ver) { + pMerged->ver = pSubmit->ver; + } + return 0; +} + // todo handle memory error int32_t streamQueueMergeQueueItem(SStreamQueueItem* dst, SStreamQueueItem* pElem, SStreamQueueItem** pRes) { *pRes = NULL; diff --git a/source/libs/stream/src/streamDispatch.c b/source/libs/stream/src/streamDispatch.c index 0f0015c7d9..a3146ae9d4 100644 --- a/source/libs/stream/src/streamDispatch.c +++ b/source/libs/stream/src/streamDispatch.c @@ -73,7 +73,7 @@ static int32_t tInitStreamDispatchReq(SStreamDispatchReq* pReq, const SStreamTas if (pReq->data == NULL || pReq->dataLen == NULL) { taosArrayDestroyP(pReq->data, taosMemoryFree); taosArrayDestroy(pReq->dataLen); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } return TSDB_CODE_SUCCESS; @@ -110,7 +110,7 @@ int32_t streamTaskBroadcastRetrieveReq(SStreamTask* pTask, SStreamRetrieveReq* r buf = rpcMallocCont(sizeof(SMsgHead) + len); if (buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } ((SMsgHead*)buf)->vgId = htonl(pEpInfo->nodeId); @@ -209,7 +209,7 @@ int32_t streamSendCheckMsg(SStreamTask* pTask, const SStreamTaskCheckReq* pReq, buf = rpcMallocCont(sizeof(SMsgHead) + tlen); if (buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } ((SMsgHead*)buf)->vgId = htonl(nodeId); @@ -671,7 +671,10 @@ int32_t streamSearchAndAddBlock(SStreamTask* pTask, SStreamDispatchReq* pReqs, S } else { int32_t code = buildCtbNameByGroupIdImpl(pTask->outputInfo.shuffleDispatcher.stbFullName, groupId, pDataBlock->info.parTbName); - stError("s-task:%s failed to build child table name, code:%s", pTask->id.idStr, tstrerror(code)); + if (code) { + stError("s-task:%s failed to build child table name for group:%" PRId64 ", code:%s", pTask->id.idStr, + groupId, tstrerror(code)); + } } snprintf(ctbName, TSDB_TABLE_NAME_LEN, "%s.%s", pTask->outputInfo.shuffleDispatcher.dbInfo.db, @@ -865,7 +868,7 @@ int32_t initCheckpointReadyMsg(SStreamTask* pTask, int32_t upstreamNodeId, int32 buf = rpcMallocCont(sizeof(SMsgHead) + tlen); if (buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } ((SMsgHead*)buf)->vgId = htonl(req.upstreamNodeId); @@ -1280,7 +1283,7 @@ int32_t streamTaskBuildCheckpointSourceRsp(SStreamCheckpointSourceReq* pReq, SRp void* pBuf = rpcMallocCont(sizeof(SMsgHead) + len); if (pBuf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } ((SMsgHead*)pBuf)->vgId = htonl(pReq->mnodeId); @@ -1668,7 +1671,7 @@ int32_t streamProcessDispatchRsp(SStreamTask* pTask, SStreamDispatchRsp* pRsp, i static int32_t buildDispatchRsp(const SStreamTask* pTask, const SStreamDispatchReq* pReq, int32_t status, void** pBuf) { *pBuf = rpcMallocCont(sizeof(SMsgHead) + sizeof(SStreamDispatchRsp)); if (*pBuf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } ((SMsgHead*)(*pBuf))->vgId = htonl(pReq->upstreamNodeId); diff --git a/source/libs/stream/src/streamExtraInfo.c b/source/libs/stream/src/streamExtraInfo.c new file mode 100644 index 0000000000..168571363f --- /dev/null +++ b/source/libs/stream/src/streamExtraInfo.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "os.h" + +#define UP_TASKS_NOT_SEND_CHKPT_TRIGGER 1 +#define DOWN_TASKS_NOT_READY 2 +#define DOWN_TASKS_BACKPRESSURE 3 +#define DOWN_TASKS_INPUTQ_CLOSED 4 +#define TASK_OUTPUTQ_FULL 5 +#define TASK_SINK_QUOTA_REACHED 6 + +typedef struct SStreamTaskExtraInfo { + int32_t infoId; + char* pMsg; +} SStreamTaskExtraInfo; + +SStreamTaskExtraInfo extraInfoList[8] = { + {0}, + {.infoId = UP_TASKS_NOT_SEND_CHKPT_TRIGGER, .pMsg = "%d(us) not send checkpoint-trigger"}, + {.infoId = DOWN_TASKS_NOT_READY, .pMsg = "%d(ds) tasks not ready"}, + {.infoId = DOWN_TASKS_BACKPRESSURE, .pMsg = "0x%x(ds) backpressure"}, + {.infoId = DOWN_TASKS_INPUTQ_CLOSED, .pMsg = "0x%x(ds) inputQ closed"}, + {.infoId = TASK_OUTPUTQ_FULL, .pMsg = "outputQ is full"}, + {.infoId = TASK_SINK_QUOTA_REACHED, .pMsg = "sink quota reached"}, +}; + diff --git a/source/libs/stream/src/streamHb.c b/source/libs/stream/src/streamHb.c index 72d2e89936..dde3595eb3 100644 --- a/source/libs/stream/src/streamHb.c +++ b/source/libs/stream/src/streamHb.c @@ -153,7 +153,6 @@ int32_t streamMetaSendHbHelper(SStreamMeta* pMeta) { pMsg->pUpdateNodes = taosArrayInit(numOfTasks, sizeof(int32_t)); if (pMsg->pTaskStatus == NULL || pMsg->pUpdateNodes == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; return terrno; } diff --git a/source/libs/stream/src/streamMeta.c b/source/libs/stream/src/streamMeta.c index 10c64260e6..b8c433d82f 100644 --- a/source/libs/stream/src/streamMeta.c +++ b/source/libs/stream/src/streamMeta.c @@ -89,7 +89,7 @@ int32_t metaRefMgtInit() { } if (gMetaRefMgt.pTable == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } else { return code; } @@ -126,7 +126,7 @@ int32_t metaRefMgtAdd(int64_t vgId, int64_t* rid) { p = taosArrayPush(pList, &rid); if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } code = taosHashPut(gMetaRefMgt.pTable, &vgId, sizeof(vgId), &pList, sizeof(void*)); @@ -138,7 +138,7 @@ int32_t metaRefMgtAdd(int64_t vgId, int64_t* rid) { SArray* list = *(SArray**)p; void* px = taosArrayPush(list, &rid); if (px == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; } } @@ -476,23 +476,14 @@ _err: if (pMeta->pTasksMap) taosHashCleanup(pMeta->pTasksMap); if (pMeta->pTaskList) taosArrayDestroy(pMeta->pTaskList); if (pMeta->pTaskDb) { - int32_t ret = tdbTbClose(pMeta->pTaskDb); - if (ret) { - stError("vgId:%d tdb failed close task db, code:%s", pMeta->vgId, tstrerror(ret)); - } + tdbTbClose(pMeta->pTaskDb); pMeta->pTaskDb = NULL; } if (pMeta->pCheckpointDb) { - int32_t ret = tdbTbClose(pMeta->pCheckpointDb); - if (ret) { - stError("vgId:%d tdb failed close task checkpointDb, code:%s", pMeta->vgId, tstrerror(ret)); - } + tdbTbClose(pMeta->pCheckpointDb); } if (pMeta->db) { - int32_t ret = tdbClose(pMeta->db); - if (ret) { - stError("vgId:%d tdb failed close meta db, code:%s", pMeta->vgId, tstrerror(ret)); - } + tdbClose(pMeta->db); } if (pMeta->pHbInfo) taosMemoryFreeClear(pMeta->pHbInfo); @@ -597,22 +588,10 @@ 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)); - } - code = tdbTbClose(pMeta->pTaskDb); - if (code) { - stError("vgId:%d failed to close taskDb, code:%s", vgId, tstrerror(code)); - } - code = tdbTbClose(pMeta->pCheckpointDb); - if (code) { - stError("vgId:%d failed to close checkpointDb, code:%s", vgId, tstrerror(code)); - } - code = tdbClose(pMeta->db); - if (code) { - stError("vgId:%d failed to close db, code:%s", vgId, tstrerror(code)); - } + tdbAbort(pMeta->db, pMeta->txn); + tdbTbClose(pMeta->pTaskDb); + tdbTbClose(pMeta->pCheckpointDb); + tdbClose(pMeta->db); taosArrayDestroy(pMeta->pTaskList); taosArrayDestroy(pMeta->chkpSaved); @@ -718,7 +697,7 @@ int32_t streamMetaRegisterTask(SStreamMeta* pMeta, int64_t ver, SStreamTask* pTa p = taosArrayPush(pMeta->pTaskList, &pTask->id); if (p == NULL) { stError("s-task:0x%" PRIx64 " failed to register task into meta-list, code: out of memory", id.taskId); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } code = taosHashPut(pMeta->pTasksMap, &id, sizeof(id), &pTask, POINTER_BYTES); @@ -895,7 +874,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 +1056,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); } diff --git a/source/libs/stream/src/streamQueue.c b/source/libs/stream/src/streamQueue.c index 6c3685bb0f..6af6ebd044 100644 --- a/source/libs/stream/src/streamQueue.c +++ b/source/libs/stream/src/streamQueue.c @@ -384,13 +384,13 @@ int32_t streamTaskPutTranstateIntoInputQ(SStreamTask* pTask) { pTranstate->blocks = taosArrayInit(4, sizeof(SSDataBlock)); // pBlock; if (pTranstate->blocks == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _err; } void* p = taosArrayPush(pTranstate->blocks, pBlock); if (p == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _err; } diff --git a/source/libs/stream/src/streamSessionState.c b/source/libs/stream/src/streamSessionState.c index b2907037e6..692306eefc 100644 --- a/source/libs/stream/src/streamSessionState.c +++ b/source/libs/stream/src/streamSessionState.c @@ -99,7 +99,7 @@ static int32_t addNewSessionWindow(SStreamFileState* pFileState, SArray* pWinInf memcpy(pNewPos->pKey, pKey, sizeof(SSessionKey)); void* tmp = taosArrayPush(pWinInfos, &pNewPos); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } (*ppPos) = pNewPos; @@ -124,7 +124,7 @@ static int32_t insertNewSessionWindow(SStreamFileState* pFileState, SArray* pWin memcpy(pNewPos->pKey, pKey, sizeof(SSessionKey)); void* tmp = taosArrayInsert(pWinInfos, index, &pNewPos); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } @@ -178,7 +178,7 @@ int32_t getSessionWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey, } else { pWinStates = taosArrayInit(16, POINTER_BYTES); if (!pWinStates) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } code = tSimpleHashPut(pSessionBuff, &pKey->groupId, sizeof(uint64_t), &pWinStates, POINTER_BYTES); @@ -299,7 +299,7 @@ int32_t putSessionWinResultBuff(SStreamFileState* pFileState, SRowBuffPos* pPos) } else { pWinStates = taosArrayInit(16, POINTER_BYTES); if (!pWinStates) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } @@ -311,7 +311,7 @@ int32_t putSessionWinResultBuff(SStreamFileState* pFileState, SRowBuffPos* pPos) if (size == 0) { void* tmp = taosArrayPush(pWinStates, &pPos); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } goto _end; @@ -322,13 +322,13 @@ int32_t putSessionWinResultBuff(SStreamFileState* pFileState, SRowBuffPos* pPos) if (index >= 0) { void* tmp = taosArrayInsert(pWinStates, index, &pPos); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } else { void* tmp = taosArrayInsert(pWinStates, 0, &pPos); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -419,7 +419,7 @@ int32_t allocSessioncWinBuffByNextPosition(SStreamFileState* pFileState, SStream if (!ppBuff) { pWinStates = taosArrayInit(16, POINTER_BYTES); if (!pWinStates) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } @@ -802,7 +802,7 @@ int32_t getStateWinResultBuff(SStreamFileState* pFileState, SSessionKey* key, ch } else { pWinStates = taosArrayInit(16, POINTER_BYTES); if (!pWinStates) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } @@ -942,7 +942,7 @@ int32_t getCountWinResultBuff(SStreamFileState* pFileState, SSessionKey* pKey, C } else { pWinStates = taosArrayInit(16, POINTER_BYTES); if (!pWinStates) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } diff --git a/source/libs/stream/src/streamSnapshot.c b/source/libs/stream/src/streamSnapshot.c index 2742798a04..ae8a71d988 100644 --- a/source/libs/stream/src/streamSnapshot.c +++ b/source/libs/stream/src/streamSnapshot.c @@ -204,7 +204,7 @@ int32_t snapFileGenMeta(SBackendSnapFile2* pSnapFile) { p = taosArrayPush(pSnapFile->pFileList, &item); if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } // mainfest @@ -217,7 +217,7 @@ int32_t snapFileGenMeta(SBackendSnapFile2* pSnapFile) { p = taosArrayPush(pSnapFile->pFileList, &item); if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } // options @@ -230,7 +230,7 @@ int32_t snapFileGenMeta(SBackendSnapFile2* pSnapFile) { p = taosArrayPush(pSnapFile->pFileList, &item); if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } // sst @@ -245,7 +245,7 @@ int32_t snapFileGenMeta(SBackendSnapFile2* pSnapFile) { p = taosArrayPush(pSnapFile->pFileList, &item); if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -255,7 +255,7 @@ int32_t snapFileGenMeta(SBackendSnapFile2* pSnapFile) { if (streamGetFileSize(pSnapFile->path, item.name, &item.size) == 0) { p = taosArrayPush(pSnapFile->pFileList, &item); if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -265,7 +265,7 @@ int32_t snapFileGenMeta(SBackendSnapFile2* pSnapFile) { if (streamGetFileSize(pSnapFile->path, item.name, &item.size) == 0) { p = taosArrayPush(pSnapFile->pFileList, &item); if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } @@ -287,7 +287,7 @@ int32_t snapFileReadMeta(SBackendSnapFile2* pSnapFile) { if (strlen(name) >= strlen(ROCKSDB_CURRENT) && 0 == strncmp(name, ROCKSDB_CURRENT, strlen(ROCKSDB_CURRENT))) { pSnapFile->pCurrent = taosStrdup(name); if (pSnapFile->pCurrent == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } continue; @@ -295,7 +295,7 @@ int32_t snapFileReadMeta(SBackendSnapFile2* pSnapFile) { if (strlen(name) >= strlen(ROCKSDB_MAINFEST) && 0 == strncmp(name, ROCKSDB_MAINFEST, strlen(ROCKSDB_MAINFEST))) { pSnapFile->pMainfest = taosStrdup(name); if (pSnapFile->pMainfest == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } continue; @@ -303,7 +303,7 @@ int32_t snapFileReadMeta(SBackendSnapFile2* pSnapFile) { if (strlen(name) >= strlen(ROCKSDB_OPTIONS) && 0 == strncmp(name, ROCKSDB_OPTIONS, strlen(ROCKSDB_OPTIONS))) { pSnapFile->pOptions = taosStrdup(name); if (pSnapFile->pOptions == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } continue; @@ -312,7 +312,7 @@ int32_t snapFileReadMeta(SBackendSnapFile2* pSnapFile) { 0 == strncmp(name, ROCKSDB_CHECKPOINT_META, strlen(ROCKSDB_CHECKPOINT_META))) { pSnapFile->pCheckpointMeta = taosStrdup(name); if (pSnapFile->pCheckpointMeta == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } continue; @@ -321,7 +321,7 @@ int32_t snapFileReadMeta(SBackendSnapFile2* pSnapFile) { 0 == strncmp(name, ROCKSDB_CHECKPOINT_SELF_CHECK, strlen(ROCKSDB_CHECKPOINT_SELF_CHECK))) { pSnapFile->pCheckpointSelfcheck = taosStrdup(name); if (pSnapFile->pCheckpointSelfcheck == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } continue; @@ -330,13 +330,13 @@ int32_t snapFileReadMeta(SBackendSnapFile2* pSnapFile) { 0 == strncmp(name + strlen(name) - strlen(ROCKSDB_SST), ROCKSDB_SST, strlen(ROCKSDB_SST))) { char* sst = taosStrdup(name); if (sst == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } void* p = taosArrayPush(pSnapFile->pSst, &sst); if (p == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } } @@ -370,7 +370,7 @@ int32_t streamBackendSnapInitFile(char* metaPath, SStreamTaskSnap* pSnap, SBacke pSnapFile->pSst = taosArrayInit(16, sizeof(void*)); pSnapFile->pFileList = taosArrayInit(64, sizeof(SBackendFileItem)); if (pSnapFile->pSst == NULL || pSnapFile->pFileList == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _ERROR; } @@ -426,7 +426,7 @@ int32_t streamSnapHandleInit(SStreamSnapHandle* pHandle, char* path, void* pMeta SArray* pSnapInfoSet = taosArrayInit(4, sizeof(SStreamTaskSnap)); if (pSnapInfoSet == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } code = streamCreateTaskDbSnapInfo(pMeta, path, pSnapInfoSet); @@ -437,7 +437,7 @@ int32_t streamSnapHandleInit(SStreamSnapHandle* pHandle, char* path, void* pMeta pDbSnapSet = taosArrayInit(8, sizeof(SBackendSnapFile2)); if (pDbSnapSet == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _err; } @@ -452,7 +452,7 @@ int32_t streamSnapHandleInit(SStreamSnapHandle* pHandle, char* path, void* pMeta void* p = taosArrayPush(pDbSnapSet, &snapFile); if (p == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _err; } } @@ -651,7 +651,7 @@ int32_t streamSnapWriterOpen(void* pMeta, int64_t sver, int64_t ever, char* path pHandle->metaPath = taosStrdup(path); if (pHandle->metaPath == NULL) { taosMemoryFree(pWriter); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; return code; } @@ -673,7 +673,7 @@ int32_t streamSnapWriterOpen(void* pMeta, int64_t sver, int64_t ever, char* path stError("failed close snaphost writer"); } - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; return code; } @@ -726,12 +726,12 @@ int32_t streamSnapWriteImpl(SStreamSnapWriter* pWriter, uint8_t* pData, uint32_t item.name = taosStrdup(pHdr->name); item.type = pHdr->type; if (item.name == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } void* p = taosArrayPush(pSnapFile->pFileList, &item); if (p == NULL) { // can NOT goto _err here. - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SBackendFileItem* pItem2 = taosArrayGet(pSnapFile->pFileList, pSnapFile->currFileIdx); @@ -810,7 +810,7 @@ int32_t streamSnapWrite(SStreamSnapWriter* pWriter, uint8_t* pData, uint32_t nDa void* p = taosArrayPush(pDbSnapFile->pFileList, &item); if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pDbSnapFile->inited = 1; @@ -822,7 +822,7 @@ int32_t streamSnapWrite(SStreamSnapWriter* pWriter, uint8_t* pData, uint32_t nDa SBackendSnapFile2 snapFile = {0}; void* p = taosArrayPush(pHandle->pDbSnapSet, &snapFile); if (p == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pHandle->currIdx += 1; diff --git a/source/libs/stream/src/streamStartHistory.c b/source/libs/stream/src/streamStartHistory.c index 1290aef6a3..b376dbd16b 100644 --- a/source/libs/stream/src/streamStartHistory.c +++ b/source/libs/stream/src/streamStartHistory.c @@ -70,7 +70,7 @@ int32_t streamStartScanHistoryAsync(SStreamTask* pTask, int8_t igUntreated) { int32_t len = sizeof(SStreamScanHistoryReq); void* serializedReq = rpcMallocCont(len); if (serializedReq == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(serializedReq, &req, len); diff --git a/source/libs/stream/src/streamState.c b/source/libs/stream/src/streamState.c index 484877e37b..e6b5a28d78 100644 --- a/source/libs/stream/src/streamState.c +++ b/source/libs/stream/src/streamState.c @@ -106,14 +106,14 @@ SStreamState* streamStateOpen(const char* path, void* pTask, int64_t streamId, i stDebug("open stream state %p, %s", pState, path); if (pState == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } pState->pTdbState = taosMemoryCalloc(1, sizeof(STdbState)); if (pState->pTdbState == NULL) { streamStateDestroy(pState, true); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } diff --git a/source/libs/stream/src/streamTask.c b/source/libs/stream/src/streamTask.c index ed8f23a4ab..047e3ef2c8 100644 --- a/source/libs/stream/src/streamTask.c +++ b/source/libs/stream/src/streamTask.c @@ -32,7 +32,7 @@ static int32_t addToTaskset(SArray* pArray, SStreamTask* pTask) { int32_t childId = taosArrayGetSize(pArray); pTask->info.selfChildId = childId; void* p = taosArrayPush(pArray, &pTask); - return (p == NULL) ? TSDB_CODE_OUT_OF_MEMORY : TSDB_CODE_SUCCESS; + return (p == NULL) ? terrno : TSDB_CODE_SUCCESS; } static int32_t doUpdateTaskEpset(SStreamTask* pTask, int32_t nodeId, SEpSet* pEpSet, bool* pUpdated) { @@ -411,7 +411,7 @@ int32_t streamTaskSetBackendPath(SStreamTask* pTask) { int32_t len = strlen(pTask->pMeta->path); pTask->backendPath = (char*)taosMemoryMalloc(len + nBytes + 2); if (pTask->backendPath == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)sprintf(pTask->backendPath, "%s%s%s", pTask->pMeta->path, TD_DIRSEP, id); @@ -549,7 +549,7 @@ int32_t streamTaskGetNumOfUpstream(const SStreamTask* pTask) { return taosArrayG int32_t streamTaskSetUpstreamInfo(SStreamTask* pTask, const SStreamTask* pUpstreamTask) { SStreamUpstreamEpInfo* pEpInfo = createStreamTaskEpInfo(pUpstreamTask); if (pEpInfo == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if (pTask->upstreamInfo.pList == NULL) { @@ -557,7 +557,7 @@ int32_t streamTaskSetUpstreamInfo(SStreamTask* pTask, const SStreamTask* pUpstre } void* p = taosArrayPush(pTask->upstreamInfo.pList, &pEpInfo); - return (p == NULL) ? TSDB_CODE_OUT_OF_MEMORY : TSDB_CODE_SUCCESS; + return (p == NULL) ? terrno : TSDB_CODE_SUCCESS; } int32_t streamTaskUpdateUpstreamInfo(SStreamTask* pTask, int32_t nodeId, const SEpSet* pEpSet, bool* pUpdated) { @@ -1133,7 +1133,7 @@ int32_t createStreamTaskIdStr(int64_t streamId, int32_t taskId, const char** pId *pId = taosStrdup(buf); if (*pId == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } else { return TSDB_CODE_SUCCESS; } diff --git a/source/libs/stream/src/streamTaskSm.c b/source/libs/stream/src/streamTaskSm.c index 3709c4dfbd..3501d30be4 100644 --- a/source/libs/stream/src/streamTaskSm.c +++ b/source/libs/stream/src/streamTaskSm.c @@ -88,7 +88,7 @@ static int32_t attachWaitedEvent(SStreamTask* pTask, SFutureHandleEventInfo* pEv if (px == NULL) { stError("s-task:%s failed to add into waiting list, total waiting events:%d, code: out of memory", pTask->id.idStr, (int32_t)taosArrayGetSize(pList)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } else { stDebug("s-task:%s add into waiting list, total waiting events:%d", pTask->id.idStr, (int32_t)taosArrayGetSize(pList)); @@ -298,7 +298,7 @@ int32_t streamCreateStateMachine(SStreamTask* pTask) { taosMemoryFree(pSM); stError("s-task:%s failed to create task stateMachine, size:%d, code:%s", id, (int32_t)sizeof(SStreamTaskSM), tstrerror(terrno)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } // set the initial state for the state-machine of stream task diff --git a/source/libs/stream/src/streamUpdate.c b/source/libs/stream/src/streamUpdate.c index f93559401f..740c6f3d9d 100644 --- a/source/libs/stream/src/streamUpdate.c +++ b/source/libs/stream/src/streamUpdate.c @@ -80,7 +80,7 @@ int32_t windowSBfAdd(SUpdateInfo* pInfo, uint64_t count) { QUERY_CHECK_CODE(code, lino, _error); void* res = taosArrayPush(pInfo->pTsSBFs, &tsSBF); if (!res) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _error); } } @@ -168,7 +168,7 @@ int32_t updateInfoInit(int64_t interval, int32_t precision, int64_t watermark, b pInfo->pTsSBFs = taosArrayInit(bfSize, sizeof(void*)); if (pInfo->pTsSBFs == NULL) { updateInfoDestroy(pInfo); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } code = windowSBfAdd(pInfo, bfSize); @@ -177,7 +177,7 @@ int32_t updateInfoInit(int64_t interval, int32_t precision, int64_t watermark, b pInfo->pTsBuckets = taosArrayInit(DEFAULT_BUCKET_SIZE, sizeof(TSKEY)); if (pInfo->pTsBuckets == NULL) { updateInfoDestroy(pInfo); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } @@ -185,7 +185,7 @@ int32_t updateInfoInit(int64_t interval, int32_t precision, int64_t watermark, b for (uint64_t i = 0; i < DEFAULT_BUCKET_SIZE; ++i) { void* tmp = taosArrayPush(pInfo->pTsBuckets, &dumy); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -195,7 +195,7 @@ int32_t updateInfoInit(int64_t interval, int32_t precision, int64_t watermark, b _hash_fn_t hashFn = taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT); pInfo->pMap = taosHashInit(DEFAULT_MAP_CAPACITY, hashFn, true, HASH_NO_LOCK); if (!pInfo->pMap) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } pInfo->maxDataVersion = 0; @@ -254,7 +254,7 @@ static int32_t getSBf(SUpdateInfo* pInfo, TSKEY ts, SScalableBf** ppSBf) { void* tmp = taosArrayPush(pInfo->pTsSBFs, &res); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } } @@ -574,7 +574,7 @@ int32_t updateInfoDeserialize(void* buf, int32_t bufLen, SUpdateInfo* pInfo) { if (tDecodeI64(&decoder, &ts) < 0) return -1; void* tmp = taosArrayPush(pInfo->pTsBuckets, &ts); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _error); } } @@ -593,7 +593,7 @@ int32_t updateInfoDeserialize(void* buf, int32_t bufLen, SUpdateInfo* pInfo) { void* tmp = taosArrayPush(pInfo->pTsSBFs, &pSBf); if (!tmp) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _error); } } diff --git a/source/libs/stream/src/tstreamFileState.c b/source/libs/stream/src/tstreamFileState.c index a88ab661e6..703e0056a6 100644 --- a/source/libs/stream/src/tstreamFileState.c +++ b/source/libs/stream/src/tstreamFileState.c @@ -513,13 +513,13 @@ SRowBuffPos* getNewRowPos(SStreamFileState* pFileState) { int32_t lino = 0; SRowBuffPos* pPos = taosMemoryCalloc(1, sizeof(SRowBuffPos)); if (!pPos) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _error); } pPos->pKey = taosMemoryCalloc(1, pFileState->keyLen); if (!pPos->pKey) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _error); } @@ -756,7 +756,7 @@ void flushSnapshot(SStreamFileState* pFileState, SStreamSnapshot* pSnapshot, boo int32_t len = pFileState->rowSize + sizeof(uint64_t) + sizeof(int32_t) + 64; char* buf = taosMemoryCalloc(1, len); if (!buf) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _end); } diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index 51a0679889..e3f94c1c9a 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -175,11 +175,12 @@ _SEND_RESPONSE: if (accepted && matched) { pReply->success = true; // update commit index only after matching - (void)syncNodeUpdateCommitIndex(ths, TMIN(pMsg->commitIndex, pReply->lastSendIndex)); + SyncIndex returnIndex = syncNodeUpdateCommitIndex(ths, TMIN(pMsg->commitIndex, pReply->lastSendIndex)); + sTrace("vgId:%d, update commit return index %" PRId64 "", ths->vgId, returnIndex); } // ack, i.e. send response - (void)syncNodeSendMsgById(&pReply->destId, ths, &rpcRsp); + TAOS_CHECK_RETURN(syncNodeSendMsgById(&pReply->destId, ths, &rpcRsp)); // commit index, i.e. leader notice me if (ths->fsmState != SYNC_FSM_STATE_INCOMPLETE && syncLogBufferCommit(ths->pLogBuf, ths, ths->commitIndex) < 0) { diff --git a/source/libs/sync/src/syncCommit.c b/source/libs/sync/src/syncCommit.c index 5054339e8e..b3560f9283 100644 --- a/source/libs/sync/src/syncCommit.c +++ b/source/libs/sync/src/syncCommit.c @@ -85,10 +85,9 @@ int64_t syncNodeCheckCommitIndex(SSyncNode* ths, SyncIndex indexLikely) { int32_t code = 0; if (indexLikely > ths->commitIndex && syncNodeAgreedUpon(ths, indexLikely)) { SyncIndex commitIndex = indexLikely; - // TODO add return when error - (void)syncNodeUpdateCommitIndex(ths, commitIndex); - sTrace("vgId:%d, agreed upon. role:%d, term:%" PRId64 ", index:%" PRId64 "", ths->vgId, ths->state, - raftStoreGetTerm(ths), commitIndex); + SyncIndex returnIndex = syncNodeUpdateCommitIndex(ths, commitIndex); + sTrace("vgId:%d, agreed upon. role:%d, term:%" PRId64 ", index:%" PRId64 ", return:%" PRId64, ths->vgId, ths->state, + raftStoreGetTerm(ths), commitIndex, returnIndex); } return ths->commitIndex; } diff --git a/source/libs/sync/src/syncEnv.c b/source/libs/sync/src/syncEnv.c index 1ebf47403a..dab9107332 100644 --- a/source/libs/sync/src/syncEnv.c +++ b/source/libs/sync/src/syncEnv.c @@ -87,7 +87,10 @@ int64_t syncNodeAdd(SSyncNode *pNode) { void syncNodeRemove(int64_t rid) { sDebug("sync node refId:%" PRId64 " is removed from rsetId:%d", rid, gNodeRefId); if (rid > 0) { - (void)taosRemoveRef(gNodeRefId, rid); + int32_t code = 0; + if ((code = taosRemoveRef(gNodeRefId, rid)) != 0) + sError("failed to remove sync node from refId:%" PRId64 ", rsetId:%d, since %s", rid, gNodeRefId, + tstrerror(code)); } } @@ -103,7 +106,10 @@ SSyncNode *syncNodeAcquire(int64_t rid) { void syncNodeRelease(SSyncNode *pNode) { if (pNode) { - (void)taosReleaseRef(gNodeRefId, pNode->rid); + int32_t code = 0; + if ((code = taosReleaseRef(gNodeRefId, pNode->rid)) != 0) + sError("failed to release sync node from refId:%" PRId64 ", rsetId:%d, since %s", pNode->rid, gNodeRefId, + tstrerror(code)); } } @@ -118,7 +124,9 @@ int64_t syncHbTimerDataAdd(SSyncHbTimerData *pData) { void syncHbTimerDataRemove(int64_t rid) { if (rid > 0) { - (void)taosRemoveRef(gHbDataRefId, rid); + int32_t code = 0; + if ((code = taosRemoveRef(gHbDataRefId, rid)) != 0) + sError("failed to remove hbdata from refId:%" PRId64 ", rsetId:%d, since %s", rid, gHbDataRefId, tstrerror(code)); } } @@ -134,6 +142,10 @@ SSyncHbTimerData *syncHbTimerDataAcquire(int64_t rid) { void syncHbTimerDataRelease(SSyncHbTimerData *pData) { if (pData) { - (void)taosReleaseRef(gHbDataRefId, pData->rid); + int32_t code = 0; + if ((code = taosReleaseRef(gHbDataRefId, pData->rid)) != 0) { + sError("failed to release hbdata from refId:%" PRId64 ", rsetId:%d, since %s", pData->rid, gHbDataRefId, + tstrerror(code)); + } } } diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 4dce54fc1a..1a90eb8ab0 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -201,13 +201,13 @@ int32_t syncReconfig(int64_t rid, SSyncCfg* pNewCfg) { if (pSyncNode->state == TAOS_SYNC_STATE_LEADER || pSyncNode->state == TAOS_SYNC_STATE_ASSIGNED_LEADER) { // TODO check return value - (void)syncNodeStopHeartbeatTimer(pSyncNode); + TAOS_CHECK_RETURN(syncNodeStopHeartbeatTimer(pSyncNode)); for (int32_t i = 0; i < TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA; ++i) { - (void)syncHbTimerInit(pSyncNode, &pSyncNode->peerHeartbeatTimerArr[i], pSyncNode->replicasId[i]); + TAOS_CHECK_RETURN(syncHbTimerInit(pSyncNode, &pSyncNode->peerHeartbeatTimerArr[i], pSyncNode->replicasId[i])); } - (void)syncNodeStartHeartbeatTimer(pSyncNode); + TAOS_CHECK_RETURN(syncNodeStartHeartbeatTimer(pSyncNode)); // syncNodeReplicate(pSyncNode); } @@ -367,7 +367,7 @@ int32_t syncBecomeAssignedLeader(SSyncNode* ths, SRpcMsg* pRpcMsg) { } pHead = rpcMallocCont(contLen); if (!pHead) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; sError("vgId:%d, failed to malloc memory for SVArbSetAssignedLeaderRsp", ths->vgId); goto _OVER; } @@ -403,16 +403,15 @@ int32_t syncSendTimeoutRsp(int64_t rid, int64_t seq) { TAOS_RETURN(code); } - SRpcMsg rpcMsg = {0}; + SRpcMsg rpcMsg = {0, .info.notFreeAhandle = 1}; int32_t ret = syncRespMgrGetAndDel(pNode->pSyncRespMgr, seq, &rpcMsg.info); rpcMsg.code = TSDB_CODE_SYN_TIMEOUT; syncNodeRelease(pNode); if (ret == 1) { sInfo("send timeout response, seq:%" PRId64 " handle:%p ahandle:%p", seq, rpcMsg.info.handle, rpcMsg.info.ahandle); - // TODO check return value - (void)rpcSendResponse(&rpcMsg); - return 0; + code = rpcSendResponse(&rpcMsg); + return code; } else { sError("no message handle to send timeout response, seq:%" PRId64, seq); return TSDB_CODE_SYN_INTERNAL_ERROR; @@ -933,7 +932,7 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak, int64_ int32_t code = syncBuildClientRequest(&rpcMsg, pMsg, seqNum, isWeak, pSyncNode->vgId); if (code != 0) { sError("vgId:%d, failed to propose msg while serialize since %s", pSyncNode->vgId, terrstr()); - (void)syncRespMgrDel(pSyncNode->pSyncRespMgr, seqNum); + code = syncRespMgrDel(pSyncNode->pSyncRespMgr, seqNum); TAOS_RETURN(code); } @@ -941,7 +940,7 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak, int64_ code = (*pSyncNode->syncEqMsg)(pSyncNode->msgcb, &rpcMsg); if (code != 0) { sWarn("vgId:%d, failed to propose msg while enqueue since %s", pSyncNode->vgId, terrstr()); - (void)syncRespMgrDel(pSyncNode->pSyncRespMgr, seqNum); + TAOS_CHECK_RETURN(syncRespMgrDel(pSyncNode->pSyncRespMgr, seqNum)); } if (seq != NULL) *seq = seqNum; @@ -961,7 +960,7 @@ static int32_t syncHbTimerInit(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer, SRa } static int32_t syncHbTimerStart(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer) { - int32_t ret = 0; + int32_t code = 0; int64_t tsNow = taosGetTimestampMs(); if (syncIsInit()) { SSyncHbTimerData* pData = syncHbTimerDataAcquire(pSyncTimer->hbDataRid); @@ -980,21 +979,20 @@ static int32_t syncHbTimerStart(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer) { sTrace("vgId:%d, start hb timer, rid:%" PRId64 " addr:%" PRId64, pSyncNode->vgId, pData->rid, pData->destId.addr); - (void)taosTmrReset(pSyncTimer->timerCb, pSyncTimer->timerMS / HEARTBEAT_TICK_NUM, (void*)(pData->rid), - syncEnv()->pTimerManager, &pSyncTimer->pTimer); + TAOS_CHECK_RETURN(taosTmrReset(pSyncTimer->timerCb, pSyncTimer->timerMS / HEARTBEAT_TICK_NUM, (void*)(pData->rid), + syncEnv()->pTimerManager, &pSyncTimer->pTimer)); } else { - ret = TSDB_CODE_SYN_INTERNAL_ERROR; + code = TSDB_CODE_SYN_INTERNAL_ERROR; sError("vgId:%d, start ctrl hb timer error, sync env is stop", pSyncNode->vgId); } - return ret; + return code; } static int32_t syncHbTimerStop(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer) { int32_t ret = 0; (void)atomic_add_fetch_64(&pSyncTimer->logicClock, 1); - if (!taosTmrStop(pSyncTimer->pTimer)) { - return TSDB_CODE_SYN_INTERNAL_ERROR; - } + bool stop = taosTmrStop(pSyncTimer->pTimer); + sDebug("vgId:%d, stop hb timer stop:%d", pSyncNode->vgId, stop); pSyncTimer->pTimer = NULL; syncHbTimerDataRemove(pSyncTimer->hbDataRid); pSyncTimer->hbDataRid = -1; @@ -1141,8 +1139,8 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo, int32_t vnodeVersion) { pSyncNode->replicaNum = pSyncNode->raftCfg.cfg.replicaNum; pSyncNode->totalReplicaNum = pSyncNode->raftCfg.cfg.totalReplicaNum; for (int32_t i = 0; i < pSyncNode->raftCfg.cfg.totalReplicaNum; ++i) { - if (!syncUtilNodeInfo2RaftId(&pSyncNode->raftCfg.cfg.nodeInfo[i], pSyncNode->vgId, &pSyncNode->replicasId[i])) { - terrno = TSDB_CODE_SYN_INTERNAL_ERROR; + if (syncUtilNodeInfo2RaftId(&pSyncNode->raftCfg.cfg.nodeInfo[i], pSyncNode->vgId, &pSyncNode->replicasId[i]) == + false) { sError("vgId:%d, failed to determine raft member id, replica:%d", pSyncNode->vgId, i); goto _error; } @@ -1308,7 +1306,10 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo, int32_t vnodeVersion) { } // tools - (void)syncRespMgrCreate(pSyncNode, SYNC_RESP_TTL_MS, &pSyncNode->pSyncRespMgr); // TODO: check return value + if ((code = syncRespMgrCreate(pSyncNode, SYNC_RESP_TTL_MS, &pSyncNode->pSyncRespMgr)) != 0) { + sError("vgId:%d, failed to create SyncRespMgr", pSyncNode->vgId); + goto _error; + } if (pSyncNode->pSyncRespMgr == NULL) { sError("vgId:%d, failed to create SyncRespMgr", pSyncNode->vgId); goto _error; @@ -1471,29 +1472,31 @@ int32_t syncNodeStart(SSyncNode* pSyncNode) { #ifdef BUILD_NO_CALL int32_t syncNodeStartStandBy(SSyncNode* pSyncNode) { // state change + int32_t code = 0; pSyncNode->state = TAOS_SYNC_STATE_FOLLOWER; pSyncNode->roleTimeMs = taosGetTimestampMs(); // TODO check return value - (void)syncNodeStopHeartbeatTimer(pSyncNode); + TAOS_CHECK_RETURN(syncNodeStopHeartbeatTimer(pSyncNode)); // reset elect timer, long enough int32_t electMS = TIMER_MAX_MS; - int32_t ret = syncNodeRestartElectTimer(pSyncNode, electMS); - if (ret < 0) { + code = syncNodeRestartElectTimer(pSyncNode, electMS); + if (code < 0) { sError("vgId:%d, failed to restart elect timer since %s", pSyncNode->vgId, terrstr()); return -1; } - ret = syncNodeStartPingTimer(pSyncNode); - if (ret < 0) { + code = syncNodeStartPingTimer(pSyncNode); + if (code < 0) { sError("vgId:%d, failed to start ping timer since %s", pSyncNode->vgId, terrstr()); return -1; } - return ret; + return code; } #endif void syncNodePreClose(SSyncNode* pSyncNode) { + int32_t code = 0; if (pSyncNode == NULL) { sError("failed to pre close sync node since sync node is null"); return; @@ -1508,13 +1511,22 @@ void syncNodePreClose(SSyncNode* pSyncNode) { } // stop elect timer - (void)syncNodeStopElectTimer(pSyncNode); + if ((code = syncNodeStopElectTimer(pSyncNode)) != 0) { + sError("vgId:%d, failed to stop elect timer since %s", pSyncNode->vgId, tstrerror(code)); + return; + } // stop heartbeat timer - (void)syncNodeStopHeartbeatTimer(pSyncNode); + if ((code = syncNodeStopHeartbeatTimer(pSyncNode)) != 0) { + sError("vgId:%d, failed to stop heartbeat timer since %s", pSyncNode->vgId, tstrerror(code)); + return; + } // stop ping timer - (void)syncNodeStopPingTimer(pSyncNode); + if ((code = syncNodeStopPingTimer(pSyncNode)) != 0) { + sError("vgId:%d, failed to stop ping timer since %s", pSyncNode->vgId, tstrerror(code)); + return; + } // clean rsp syncRespCleanRsp(pSyncNode->pSyncRespMgr); @@ -1536,14 +1548,24 @@ void syncNodePostClose(SSyncNode* pSyncNode) { void syncHbTimerDataFree(SSyncHbTimerData* pData) { taosMemoryFree(pData); } void syncNodeClose(SSyncNode* pSyncNode) { + int32_t code = 0; if (pSyncNode == NULL) return; sNInfo(pSyncNode, "sync close, node:%p", pSyncNode); syncRespCleanRsp(pSyncNode->pSyncRespMgr); - (void)syncNodeStopPingTimer(pSyncNode); - (void)syncNodeStopElectTimer(pSyncNode); - (void)syncNodeStopHeartbeatTimer(pSyncNode); + if ((code = syncNodeStopPingTimer(pSyncNode)) != 0) { + sError("vgId:%d, failed to stop ping timer since %s", pSyncNode->vgId, tstrerror(code)); + return; + } + if ((code = syncNodeStopElectTimer(pSyncNode)) != 0) { + sError("vgId:%d, failed to stop elect timer since %s", pSyncNode->vgId, tstrerror(code)); + return; + } + if ((code = syncNodeStopHeartbeatTimer(pSyncNode)) != 0) { + sError("vgId:%d, failed to stop heartbeat timer since %s", pSyncNode->vgId, tstrerror(code)); + return; + } syncNodeLogReplDestroy(pSyncNode); syncRespMgrDestroy(pSyncNode->pSyncRespMgr); @@ -1599,28 +1621,28 @@ ESyncStrategy syncNodeStrategy(SSyncNode* pSyncNode) { return pSyncNode->raftCfg // timer control -------------- int32_t syncNodeStartPingTimer(SSyncNode* pSyncNode) { - int32_t ret = 0; + int32_t code = 0; if (syncIsInit()) { - (void)taosTmrReset(pSyncNode->FpPingTimerCB, pSyncNode->pingTimerMS, (void*)pSyncNode->rid, - syncEnv()->pTimerManager, &pSyncNode->pPingTimer); + TAOS_CHECK_RETURN(taosTmrReset(pSyncNode->FpPingTimerCB, pSyncNode->pingTimerMS, (void*)pSyncNode->rid, + syncEnv()->pTimerManager, &pSyncNode->pPingTimer)); atomic_store_64(&pSyncNode->pingTimerLogicClock, pSyncNode->pingTimerLogicClockUser); } else { sError("vgId:%d, start ping timer error, sync env is stop", pSyncNode->vgId); } - return ret; + return code; } int32_t syncNodeStopPingTimer(SSyncNode* pSyncNode) { - int32_t ret = 0; + int32_t code = 0; (void)atomic_add_fetch_64(&pSyncNode->pingTimerLogicClockUser, 1); - // TODO check return value - (void)taosTmrStop(pSyncNode->pPingTimer); + bool stop = taosTmrStop(pSyncNode->pPingTimer); + sDebug("vgId:%d, stop ping timer, stop:%d", pSyncNode->vgId, stop); pSyncNode->pPingTimer = NULL; - return ret; + return code; } int32_t syncNodeStartElectTimer(SSyncNode* pSyncNode, int32_t ms) { - int32_t ret = 0; + int32_t code = 0; if (syncIsInit()) { pSyncNode->electTimerMS = ms; @@ -1630,22 +1652,22 @@ int32_t syncNodeStartElectTimer(SSyncNode* pSyncNode, int32_t ms) { pSyncNode->electTimerParam.pSyncNode = pSyncNode; pSyncNode->electTimerParam.pData = NULL; - (void)taosTmrReset(pSyncNode->FpElectTimerCB, pSyncNode->electTimerMS, (void*)(pSyncNode->rid), - syncEnv()->pTimerManager, &pSyncNode->pElectTimer); + TAOS_CHECK_RETURN(taosTmrReset(pSyncNode->FpElectTimerCB, pSyncNode->electTimerMS, (void*)(pSyncNode->rid), + syncEnv()->pTimerManager, &pSyncNode->pElectTimer)); } else { sError("vgId:%d, start elect timer error, sync env is stop", pSyncNode->vgId); } - return ret; + return code; } int32_t syncNodeStopElectTimer(SSyncNode* pSyncNode) { - int32_t ret = 0; + int32_t code = 0; (void)atomic_add_fetch_64(&pSyncNode->electTimerLogicClock, 1); - // TODO check return value - (void)taosTmrStop(pSyncNode->pElectTimer); + bool stop = taosTmrStop(pSyncNode->pElectTimer); + sDebug("vgId:%d, stop elect timer, stop:%d", pSyncNode->vgId, stop); pSyncNode->pElectTimer = NULL; - return ret; + return code; } int32_t syncNodeRestartElectTimer(SSyncNode* pSyncNode, int32_t ms) { @@ -1666,7 +1688,10 @@ void syncNodeResetElectTimer(SSyncNode* pSyncNode) { } // TODO check return value - (void)syncNodeRestartElectTimer(pSyncNode, electMS); + if ((code = syncNodeRestartElectTimer(pSyncNode, electMS)) != 0) { + sError("vgId:%d, failed to restart elect timer since %s", pSyncNode->vgId, terrstr()); + return; + }; sNTrace(pSyncNode, "reset elect timer, min:%d, max:%d, ms:%d", pSyncNode->electBaseLine, 2 * pSyncNode->electBaseLine, electMS); @@ -1674,17 +1699,17 @@ void syncNodeResetElectTimer(SSyncNode* pSyncNode) { #ifdef BUILD_NO_CALL static int32_t syncNodeDoStartHeartbeatTimer(SSyncNode* pSyncNode) { - int32_t ret = 0; + int32_t code = 0; if (syncIsInit()) { - (void)taosTmrReset(pSyncNode->FpHeartbeatTimerCB, pSyncNode->heartbeatTimerMS, (void*)pSyncNode->rid, - syncEnv()->pTimerManager, &pSyncNode->pHeartbeatTimer); + TAOS_CHECK_RETURN(taosTmrReset(pSyncNode->FpHeartbeatTimerCB, pSyncNode->heartbeatTimerMS, (void*)pSyncNode->rid, + syncEnv()->pTimerManager, &pSyncNode->pHeartbeatTimer)); atomic_store_64(&pSyncNode->heartbeatTimerLogicClock, pSyncNode->heartbeatTimerLogicClockUser); } else { sError("vgId:%d, start heartbeat timer error, sync env is stop", pSyncNode->vgId); } sNTrace(pSyncNode, "start heartbeat timer, ms:%d", pSyncNode->heartbeatTimerMS); - return ret; + return code; } #endif @@ -1707,12 +1732,12 @@ int32_t syncNodeStartHeartbeatTimer(SSyncNode* pSyncNode) { } int32_t syncNodeStopHeartbeatTimer(SSyncNode* pSyncNode) { - int32_t ret = 0; + int32_t code = 0; #if 0 - //TODO check return value - (void)atomic_add_fetch_64(&pSyncNode->heartbeatTimerLogicClockUser, 1); - (void)taosTmrStop(pSyncNode->pHeartbeatTimer); + TAOS_CHECK_RETURN(atomic_add_fetch_64(&pSyncNode->heartbeatTimerLogicClockUser, 1)); + bool stop = taosTmrStop(pSyncNode->pHeartbeatTimer); + sDebug("vgId:%d, stop heartbeat timer, stop:%d", pSyncNode->vgId, stop); pSyncNode->pHeartbeatTimer = NULL; #endif @@ -1723,14 +1748,15 @@ int32_t syncNodeStopHeartbeatTimer(SSyncNode* pSyncNode) { } } - return ret; + return code; } #ifdef BUILD_NO_CALL int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode) { // TODO check return value - (void)syncNodeStopHeartbeatTimer(pSyncNode); - (void)syncNodeStartHeartbeatTimer(pSyncNode); + int32_t code = 0; + TAOS_CHECK_RETURN(syncNodeStopHeartbeatTimer(pSyncNode)); + TAOS_CHECK_RETURN(syncNodeStartHeartbeatTimer(pSyncNode)); return 0; } #endif @@ -1806,6 +1832,7 @@ static bool syncIsConfigChanged(const SSyncCfg* pOldCfg, const SSyncCfg* pNewCfg } int32_t syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncIndex lastConfigChangeIndex) { + int32_t code = 0; SSyncCfg oldConfig = pSyncNode->raftCfg.cfg; if (!syncIsConfigChanged(&oldConfig, pNewConfig)) { sInfo("vgId:1, sync not reconfig since not changed"); @@ -1873,7 +1900,7 @@ int32_t syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncI // init internal pSyncNode->myNodeInfo = pSyncNode->raftCfg.cfg.nodeInfo[pSyncNode->raftCfg.cfg.myIndex]; - (void)syncUtilNodeInfo2RaftId(&pSyncNode->myNodeInfo, pSyncNode->vgId, &pSyncNode->myRaftId); + if (syncUtilNodeInfo2RaftId(&pSyncNode->myNodeInfo, pSyncNode->vgId, &pSyncNode->myRaftId) == false) return terrno; // init peersNum, peers, peersId pSyncNode->peersNum = pSyncNode->raftCfg.cfg.totalReplicaNum - 1; @@ -1886,14 +1913,17 @@ int32_t syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncI } } for (int32_t i = 0; i < pSyncNode->peersNum; ++i) { - (void)syncUtilNodeInfo2RaftId(&pSyncNode->peersNodeInfo[i], pSyncNode->vgId, &pSyncNode->peersId[i]); + if (syncUtilNodeInfo2RaftId(&pSyncNode->peersNodeInfo[i], pSyncNode->vgId, &pSyncNode->peersId[i]) == false) + return terrno; } // init replicaNum, replicasId pSyncNode->replicaNum = pSyncNode->raftCfg.cfg.replicaNum; pSyncNode->totalReplicaNum = pSyncNode->raftCfg.cfg.totalReplicaNum; for (int32_t i = 0; i < pSyncNode->raftCfg.cfg.totalReplicaNum; ++i) { - (void)syncUtilNodeInfo2RaftId(&pSyncNode->raftCfg.cfg.nodeInfo[i], pSyncNode->vgId, &pSyncNode->replicasId[i]); + if (syncUtilNodeInfo2RaftId(&pSyncNode->raftCfg.cfg.nodeInfo[i], pSyncNode->vgId, &pSyncNode->replicasId[i]) == + false) + return terrno; } // update quorum first @@ -1939,7 +1969,7 @@ int32_t syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncI // create new for (int32_t i = 0; i < TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA; ++i) { if (pSyncNode->senders[i] == NULL) { - (void)snapshotSenderCreate(pSyncNode, i, &pSyncNode->senders[i]); + TAOS_CHECK_RETURN(snapshotSenderCreate(pSyncNode, i, &pSyncNode->senders[i])); if (pSyncNode->senders[i] == NULL) { // will be created later while send snapshot sSError(pSyncNode->senders[i], "snapshot sender create failed while reconfig"); @@ -1961,10 +1991,10 @@ int32_t syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncI } // persist cfg - (void)syncWriteCfgFile(pSyncNode); + TAOS_CHECK_RETURN(syncWriteCfgFile(pSyncNode)); } else { // persist cfg - (void)syncWriteCfgFile(pSyncNode); + TAOS_CHECK_RETURN(syncWriteCfgFile(pSyncNode)); sNInfo(pSyncNode, "do not config change from %d to %d", oldConfig.totalReplicaNum, pNewConfig->totalReplicaNum); } @@ -2015,7 +2045,7 @@ void syncNodeStepDown(SSyncNode* pSyncNode, SyncTerm newTerm) { void syncNodeLeaderChangeRsp(SSyncNode* pSyncNode) { syncRespCleanRsp(pSyncNode->pSyncRespMgr); } void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr) { - // maybe clear leader cache + int32_t code = 0; // maybe clear leader cache if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) { pSyncNode->leaderCache = EMPTY_RAFT_ID; } @@ -2025,7 +2055,10 @@ void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr) { // state change pSyncNode->state = TAOS_SYNC_STATE_FOLLOWER; pSyncNode->roleTimeMs = taosGetTimestampMs(); - (void)syncNodeStopHeartbeatTimer(pSyncNode); + if ((code = syncNodeStopHeartbeatTimer(pSyncNode)) != 0) { + sError("vgId:%d, failed to stop heartbeat timer since %s", pSyncNode->vgId, tstrerror(code)); + return; + } // trace log sNTrace(pSyncNode, "become follower %s", debugStr); @@ -2042,7 +2075,10 @@ void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr) { pSyncNode->minMatchIndex = SYNC_INDEX_INVALID; // reset log buffer - (void)syncLogBufferReset(pSyncNode->pLogBuf, pSyncNode); + if ((code = syncLogBufferReset(pSyncNode->pLogBuf, pSyncNode)) != 0) { + sError("vgId:%d, failed to reset log buffer since %s", pSyncNode->vgId, tstrerror(code)); + return; + } // reset elect timer syncNodeResetElectTimer(pSyncNode); @@ -2069,7 +2105,11 @@ void syncNodeBecomeLearner(SSyncNode* pSyncNode, const char* debugStr) { pSyncNode->minMatchIndex = SYNC_INDEX_INVALID; // reset log buffer - (void)syncLogBufferReset(pSyncNode->pLogBuf, pSyncNode); + int32_t code = 0; + if ((code = syncLogBufferReset(pSyncNode->pLogBuf, pSyncNode)) != 0) { + sError("vgId:%d, failed to reset log buffer since %s", pSyncNode->vgId, tstrerror(code)); + return; + }; } // TLA+ Spec @@ -2091,6 +2131,7 @@ void syncNodeBecomeLearner(SSyncNode* pSyncNode, const char* debugStr) { // /\ UNCHANGED <> // void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) { + int32_t code = 0; pSyncNode->becomeLeaderNum++; pSyncNode->hbrSlowNum = 0; @@ -2122,7 +2163,10 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) { } // init peer mgr - (void)syncNodePeerStateInit(pSyncNode); + if ((code = syncNodePeerStateInit(pSyncNode)) != 0) { + sError("vgId:%d, failed to init peer state since %s", pSyncNode->vgId, tstrerror(code)); + return; + } #if 0 // update sender private term @@ -2143,13 +2187,22 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) { } // stop elect timer - (void)syncNodeStopElectTimer(pSyncNode); + if ((code = syncNodeStopElectTimer(pSyncNode)) != 0) { + sError("vgId:%d, failed to stop elect timer since %s", pSyncNode->vgId, tstrerror(code)); + return; + } // start heartbeat timer - (void)syncNodeStartHeartbeatTimer(pSyncNode); + if ((code = syncNodeStartHeartbeatTimer(pSyncNode)) != 0) { + sError("vgId:%d, failed to start heartbeat timer since %s", pSyncNode->vgId, tstrerror(code)); + return; + } // send heartbeat right now - (void)syncNodeHeartbeatPeers(pSyncNode); + if ((code = syncNodeHeartbeatPeers(pSyncNode)) != 0) { + sError("vgId:%d, failed to send heartbeat to peers since %s", pSyncNode->vgId, tstrerror(code)); + return; + } // call back if (pSyncNode->pFsm != NULL && pSyncNode->pFsm->FpBecomeLeaderCb != NULL) { @@ -2160,13 +2213,17 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) { pSyncNode->minMatchIndex = SYNC_INDEX_INVALID; // reset log buffer - (void)syncLogBufferReset(pSyncNode->pLogBuf, pSyncNode); + if ((code = syncLogBufferReset(pSyncNode->pLogBuf, pSyncNode)) != 0) { + sError("vgId:%d, failed to reset log buffer since %s", pSyncNode->vgId, tstrerror(code)); + return; + } // trace log sNInfo(pSyncNode, "become leader %s", debugStr); } void syncNodeBecomeAssignedLeader(SSyncNode* pSyncNode) { + int32_t code = 0; pSyncNode->becomeAssignedLeaderNum++; pSyncNode->hbrSlowNum = 0; @@ -2198,7 +2255,10 @@ void syncNodeBecomeAssignedLeader(SSyncNode* pSyncNode) { } // init peer mgr - (void)syncNodePeerStateInit(pSyncNode); + if ((code = syncNodePeerStateInit(pSyncNode)) != 0) { + sError("vgId:%d, failed to init peer state since %s", pSyncNode->vgId, tstrerror(code)); + return; + } // close receiver if (snapshotReceiverIsStart(pSyncNode->pNewNodeReceiver)) { @@ -2206,13 +2266,22 @@ void syncNodeBecomeAssignedLeader(SSyncNode* pSyncNode) { } // stop elect timer - (void)syncNodeStopElectTimer(pSyncNode); + if ((code = syncNodeStopElectTimer(pSyncNode)) != 0) { + sError("vgId:%d, failed to stop elect timer since %s", pSyncNode->vgId, tstrerror(code)); + return; + } // start heartbeat timer - (void)syncNodeStartHeartbeatTimer(pSyncNode); + if ((code = syncNodeStartHeartbeatTimer(pSyncNode)) != 0) { + sError("vgId:%d, failed to start heartbeat timer since %s", pSyncNode->vgId, tstrerror(code)); + return; + } // send heartbeat right now - (void)syncNodeHeartbeatPeers(pSyncNode); + if ((code = syncNodeHeartbeatPeers(pSyncNode)) != 0) { + sError("vgId:%d, failed to send heartbeat to peers since %s", pSyncNode->vgId, tstrerror(code)); + return; + } // call back if (pSyncNode->pFsm != NULL && pSyncNode->pFsm->FpBecomeAssignedLeaderCb != NULL) { @@ -2223,7 +2292,10 @@ void syncNodeBecomeAssignedLeader(SSyncNode* pSyncNode) { pSyncNode->minMatchIndex = SYNC_INDEX_INVALID; // reset log buffer - (void)syncLogBufferReset(pSyncNode->pLogBuf, pSyncNode); + if ((code = syncLogBufferReset(pSyncNode->pLogBuf, pSyncNode)) != 0) { + sError("vgId:%d, failed to reset log buffer since %s", pSyncNode->vgId, tstrerror(code)); + return; + } // trace log sNInfo(pSyncNode, "become assigned leader"); @@ -2513,8 +2585,10 @@ static void syncNodeEqPingTimer(void* param, void* tmrId) { } _out: - (void)taosTmrReset(syncNodeEqPingTimer, pNode->pingTimerMS, (void*)pNode->rid, syncEnv()->pTimerManager, - &pNode->pPingTimer); + if ((code = taosTmrReset(syncNodeEqPingTimer, pNode->pingTimerMS, (void*)pNode->rid, syncEnv()->pTimerManager, + &pNode->pPingTimer)) != 0) { + sError("failed to reset ping timer since %s", tstrerror(code)); + }; } syncNodeRelease(pNode); } @@ -2591,8 +2665,9 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) { } _out: - (void)taosTmrReset(syncNodeEqHeartbeatTimer, pNode->heartbeatTimerMS, (void*)pNode->rid, syncEnv()->pTimerManager, - &pNode->pHeartbeatTimer); + if (taosTmrReset(syncNodeEqHeartbeatTimer, pNode->heartbeatTimerMS, (void*)pNode->rid, syncEnv()->pTimerManager, + &pNode->pHeartbeatTimer) != 0) + return; } else { sTrace("==syncNodeEqHeartbeatTimer== heartbeatTimerLogicClock:%" PRId64 ", heartbeatTimerLogicClockUser:%" PRId64, @@ -2603,6 +2678,7 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) { #endif static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) { + int32_t code = 0; int64_t hbDataRid = (int64_t)param; int64_t tsNow = taosGetTimestampMs(); @@ -2646,7 +2722,12 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) { pData->execTime += pSyncTimer->timerMS; SRpcMsg rpcMsg = {0}; - (void)syncBuildHeartbeat(&rpcMsg, pSyncNode->vgId); + if ((code = syncBuildHeartbeat(&rpcMsg, pSyncNode->vgId)) != 0) { + sError("vgId:%d, failed to build heartbeat msg since %s", pSyncNode->vgId, tstrerror(code)); + syncNodeRelease(pSyncNode); + syncHbTimerDataRelease(pData); + return; + } pSyncNode->minMatchIndex = syncMinMatchIndex(pSyncNode); @@ -2668,14 +2749,22 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) { STraceId* trace = &(rpcMsg.info.traceId); sGTrace("vgId:%d, send sync-heartbeat to dnode:%d", pSyncNode->vgId, DID(&(pSyncMsg->destId))); syncLogSendHeartbeat(pSyncNode, pSyncMsg, false, timerElapsed, pData->execTime); - (void)syncNodeSendHeartbeat(pSyncNode, &pSyncMsg->destId, &rpcMsg); + int ret = syncNodeSendHeartbeat(pSyncNode, &pSyncMsg->destId, &rpcMsg); + if (ret != 0) { + sError("vgId:%d, failed to send heartbeat since %s", pSyncNode->vgId, tstrerror(ret)); + } } else { } if (syncIsInit()) { // sTrace("vgId:%d, reset peer hb timer", pSyncNode->vgId); - (void)taosTmrReset(syncNodeEqPeerHeartbeatTimer, pSyncTimer->timerMS / HEARTBEAT_TICK_NUM, (void*)hbDataRid, - syncEnv()->pTimerManager, &pSyncTimer->pTimer); + if ((code = taosTmrReset(syncNodeEqPeerHeartbeatTimer, pSyncTimer->timerMS / HEARTBEAT_TICK_NUM, + (void*)hbDataRid, syncEnv()->pTimerManager, &pSyncTimer->pTimer)) != 0) { + sError("vgId:%d, reset peer hb timer error, %s", pSyncNode->vgId, tstrerror(code)); + syncNodeRelease(pSyncNode); + syncHbTimerDataRelease(pData); + return; + } } else { sError("sync env is stop, reset peer hb timer error"); } @@ -2715,6 +2804,7 @@ int32_t syncCacheEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry, LRUHand void syncBuildConfigFromReq(SAlterVnodeReplicaReq* pReq, SSyncCfg* cfg) { // TODO SAlterVnodeReplicaReq name is proper? cfg->replicaNum = 0; cfg->totalReplicaNum = 0; + int32_t code = 0; for (int i = 0; i < pReq->replica; ++i) { SNodeInfo* pNode = &cfg->nodeInfo[i]; @@ -2722,9 +2812,9 @@ void syncBuildConfigFromReq(SAlterVnodeReplicaReq* pReq, SSyncCfg* cfg) { // TO pNode->nodePort = pReq->replicas[i].port; tstrncpy(pNode->nodeFqdn, pReq->replicas[i].fqdn, sizeof(pNode->nodeFqdn)); pNode->nodeRole = TAOS_SYNC_ROLE_VOTER; - (void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); - sInfo("vgId:%d, replica:%d ep:%s:%u dnode:%d nodeRole:%d", pReq->vgId, i, pNode->nodeFqdn, pNode->nodePort, - pNode->nodeId, pNode->nodeRole); + bool update = tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); + sInfo("vgId:%d, replica:%d ep:%s:%u dnode:%d nodeRole:%d, update:%d", pReq->vgId, i, pNode->nodeFqdn, + pNode->nodePort, pNode->nodeId, pNode->nodeRole, update); cfg->replicaNum++; } if (pReq->selfIndex != -1) { @@ -2736,9 +2826,9 @@ void syncBuildConfigFromReq(SAlterVnodeReplicaReq* pReq, SSyncCfg* cfg) { // TO pNode->nodePort = pReq->learnerReplicas[cfg->totalReplicaNum].port; pNode->nodeRole = TAOS_SYNC_ROLE_LEARNER; tstrncpy(pNode->nodeFqdn, pReq->learnerReplicas[cfg->totalReplicaNum].fqdn, sizeof(pNode->nodeFqdn)); - (void)tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); - sInfo("vgId:%d, replica:%d ep:%s:%u dnode:%d nodeRole:%d", pReq->vgId, i, pNode->nodeFqdn, pNode->nodePort, - pNode->nodeId, pNode->nodeRole); + bool update = tmsgUpdateDnodeInfo(&pNode->nodeId, &pNode->clusterId, pNode->nodeFqdn, &pNode->nodePort); + sInfo("vgId:%d, replica:%d ep:%s:%u dnode:%d nodeRole:%d, update:%d", pReq->vgId, i, pNode->nodeFqdn, + pNode->nodePort, pNode->nodeId, pNode->nodeRole, update); cfg->totalReplicaNum++; } cfg->totalReplicaNum += pReq->replica; @@ -2849,9 +2939,9 @@ int32_t syncNodeRebuildPeerAndCfg(SSyncNode* ths, SSyncCfg* cfg) { syncUtilNodeInfo2EpSet(&ths->peersNodeInfo[i], &ths->peersEpset[i]); - if (!syncUtilNodeInfo2RaftId(&ths->peersNodeInfo[i], ths->vgId, &ths->peersId[i])) { + if (syncUtilNodeInfo2RaftId(&ths->peersNodeInfo[i], ths->vgId, &ths->peersId[i]) == false) { sError("vgId:%d, failed to determine raft member id, peer:%d", ths->vgId, i); - return -1; + return terrno; } i++; @@ -2919,8 +3009,7 @@ int32_t syncNodeRebuildAndCopyIfExist(SSyncNode* ths, int32_t oldtotalReplicaNum ths->replicaNum = ths->raftCfg.cfg.replicaNum; ths->totalReplicaNum = ths->raftCfg.cfg.totalReplicaNum; for (int32_t i = 0; i < ths->raftCfg.cfg.totalReplicaNum; ++i) { - if (!syncUtilNodeInfo2RaftId(&ths->raftCfg.cfg.nodeInfo[i], ths->vgId, &ths->replicasId[i])) - return TSDB_CODE_SYN_INTERNAL_ERROR; + if (syncUtilNodeInfo2RaftId(&ths->raftCfg.cfg.nodeInfo[i], ths->vgId, &ths->replicasId[i]) == false) return terrno; } // 2.rebuild MatchIndex, remove deleted one @@ -2965,7 +3054,7 @@ int32_t syncNodeRebuildAndCopyIfExist(SSyncNode* ths, int32_t oldtotalReplicaNum SSyncLogReplMgr* oldLogReplMgrs = NULL; int64_t length = sizeof(SSyncLogReplMgr) * (TSDB_MAX_REPLICA + TSDB_MAX_LEARNER_REPLICA); oldLogReplMgrs = taosMemoryMalloc(length); - if (NULL == oldLogReplMgrs) return TSDB_CODE_OUT_OF_MEMORY; + if (NULL == oldLogReplMgrs) return terrno; memset(oldLogReplMgrs, 0, length); for (int i = 0; i < oldtotalReplicaNum; i++) { @@ -3287,7 +3376,10 @@ int32_t syncNodeAppend(SSyncNode* ths, SSyncRaftEntry* pEntry) { // append to log buffer if ((code = syncLogBufferAppend(ths->pLogBuf, ths, pEntry)) < 0) { sError("vgId:%d, failed to enqueue sync log buffer, index:%" PRId64, ths->vgId, pEntry->index); - (void)syncFsmExecute(ths, ths->pFsm, ths->state, raftStoreGetTerm(ths), pEntry, terrno, false); + int32_t ret = 0; + if ((ret = syncFsmExecute(ths, ths->pFsm, ths->state, raftStoreGetTerm(ths), pEntry, terrno, false)) != 0) { + sError("vgId:%d, failed to execute fsm, since %s", ths->vgId, tstrerror(ret)); + } syncEntryDestroy(pEntry); pEntry = NULL; goto _out; @@ -3305,7 +3397,7 @@ _out:; ths->pLogBuf->matchIndex, ths->pLogBuf->endIndex); if (code == 0 && ths->state == TAOS_SYNC_STATE_ASSIGNED_LEADER) { - (void)syncNodeUpdateAssignedCommitIndex(ths, matchIndex); + TAOS_CHECK_RETURN(syncNodeUpdateAssignedCommitIndex(ths, matchIndex)); if (ths->fsmState != SYNC_FSM_STATE_INCOMPLETE && syncLogBufferCommit(ths->pLogBuf, ths, ths->assignedCommitIndex) < 0) { @@ -3320,7 +3412,8 @@ _out:; } // single replica - (void)syncNodeUpdateCommitIndex(ths, matchIndex); + SyncIndex returnIndex = syncNodeUpdateCommitIndex(ths, matchIndex); + sTrace("vgId:%d, update commit return index %" PRId64 "", ths->vgId, returnIndex); if (ths->fsmState != SYNC_FSM_STATE_INCOMPLETE && (code = syncLogBufferCommit(ths->pLogBuf, ths, ths->commitIndex)) < 0) { @@ -3442,7 +3535,7 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, const SRpcMsg* pRpcMsg) { } SRpcMsg rpcMsg = {0}; - (void)syncBuildHeartbeatReply(&rpcMsg, ths->vgId); + TAOS_CHECK_RETURN(syncBuildHeartbeatReply(&rpcMsg, ths->vgId)); SyncTerm currentTerm = raftStoreGetTerm(ths); SyncHeartbeatReply* pMsgReply = rpcMsg.pCont; @@ -3470,7 +3563,7 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, const SRpcMsg* pRpcMsg) { if (ths->state == TAOS_SYNC_STATE_FOLLOWER || ths->state == TAOS_SYNC_STATE_LEARNER) { SRpcMsg rpcMsgLocalCmd = {0}; - (void)syncBuildLocalCmd(&rpcMsgLocalCmd, ths->vgId); + TAOS_CHECK_RETURN(syncBuildLocalCmd(&rpcMsgLocalCmd, ths->vgId)); SyncLocalCmd* pSyncMsg = rpcMsgLocalCmd.pCont; pSyncMsg->cmd = @@ -3494,7 +3587,7 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, const SRpcMsg* pRpcMsg) { if (pMsg->term >= currentTerm && (ths->state == TAOS_SYNC_STATE_LEADER || ths->state == TAOS_SYNC_STATE_ASSIGNED_LEADER)) { SRpcMsg rpcMsgLocalCmd = {0}; - (void)syncBuildLocalCmd(&rpcMsgLocalCmd, ths->vgId); + TAOS_CHECK_RETURN(syncBuildLocalCmd(&rpcMsgLocalCmd, ths->vgId)); SyncLocalCmd* pSyncMsg = rpcMsgLocalCmd.pCont; pSyncMsg->cmd = SYNC_LOCAL_CMD_STEP_DOWN; @@ -3577,7 +3670,8 @@ int32_t syncNodeOnLocalCmd(SSyncNode* ths, const SRpcMsg* pRpcMsg) { return TSDB_CODE_SYN_INTERNAL_ERROR; } if (pMsg->currentTerm == matchTerm) { - (void)syncNodeUpdateCommitIndex(ths, pMsg->commitIndex); + SyncIndex returnIndex = syncNodeUpdateCommitIndex(ths, pMsg->commitIndex); + sTrace("vgId:%d, update commit return index %" PRId64 "", ths->vgId, returnIndex); } if (ths->fsmState != SYNC_FSM_STATE_INCOMPLETE && syncLogBufferCommit(ths->pLogBuf, ths, ths->commitIndex) < 0) { sError("vgId:%d, failed to commit raft log since %s. commit index:%" PRId64 "", ths->vgId, terrstr(), @@ -3644,7 +3738,9 @@ int32_t syncNodeOnClientRequest(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRetIn if (code > 0) { SRpcMsg rsp = {.code = pMsg->code, .info = pMsg->info}; - (void)syncRespMgrGetAndDel(ths->pSyncRespMgr, pEntry->seqNum, &rsp.info); + int32_t num = syncRespMgrGetAndDel(ths->pSyncRespMgr, pEntry->seqNum, &rsp.info); + sDebug("vgId:%d, get response stub for config change, seqNum:%" PRIu64 ", num:%d", ths->vgId, pEntry->seqNum, + num); if (rsp.info.handle != NULL) { tmsgSendRsp(&rsp); } diff --git a/source/libs/sync/src/syncMessage.c b/source/libs/sync/src/syncMessage.c index 1c67c12a98..e4caf69845 100644 --- a/source/libs/sync/src/syncMessage.c +++ b/source/libs/sync/src/syncMessage.c @@ -25,7 +25,7 @@ int32_t syncBuildTimeout(SRpcMsg* pMsg, ESyncTimeoutType timeoutType, uint64_t l pMsg->msgType = (timeoutType == SYNC_TIMEOUT_ELECTION) ? TDMT_SYNC_TIMEOUT_ELECTION : TDMT_SYNC_TIMEOUT; pMsg->contLen = bytes; if (pMsg->pCont == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SyncTimeout* pTimeout = pMsg->pCont; @@ -45,7 +45,7 @@ int32_t syncBuildClientRequest(SRpcMsg* pMsg, const SRpcMsg* pOriginal, uint64_t pMsg->pCont = rpcMallocCont(bytes); if (pMsg->pCont == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pMsg->msgType = TDMT_SYNC_CLIENT_REQUEST; pMsg->contLen = bytes; @@ -69,7 +69,7 @@ int32_t syncBuildClientRequestFromNoopEntry(SRpcMsg* pMsg, const SSyncRaftEntry* pMsg->msgType = TDMT_SYNC_CLIENT_REQUEST; pMsg->contLen = bytes; if (pMsg->pCont == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SyncClientRequest* pClientRequest = pMsg->pCont; @@ -89,7 +89,7 @@ int32_t syncBuildRequestVote(SRpcMsg* pMsg, int32_t vgId) { pMsg->msgType = TDMT_SYNC_REQUEST_VOTE; pMsg->contLen = bytes; if (pMsg->pCont == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SyncRequestVote* pRequestVote = pMsg->pCont; @@ -105,7 +105,7 @@ int32_t syncBuildRequestVoteReply(SRpcMsg* pMsg, int32_t vgId) { pMsg->msgType = TDMT_SYNC_REQUEST_VOTE_REPLY; pMsg->contLen = bytes; if (pMsg->pCont == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SyncRequestVoteReply* pRequestVoteReply = pMsg->pCont; @@ -121,7 +121,7 @@ int32_t syncBuildAppendEntries(SRpcMsg* pMsg, int32_t dataLen, int32_t vgId) { pMsg->msgType = TDMT_SYNC_APPEND_ENTRIES; pMsg->contLen = bytes; if (pMsg->pCont == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SyncAppendEntries* pAppendEntries = pMsg->pCont; @@ -138,7 +138,7 @@ int32_t syncBuildAppendEntriesReply(SRpcMsg* pMsg, int32_t vgId) { pMsg->msgType = TDMT_SYNC_APPEND_ENTRIES_REPLY; pMsg->contLen = bytes; if (pMsg->pCont == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SyncAppendEntriesReply* pAppendEntriesReply = pMsg->pCont; @@ -155,7 +155,7 @@ int32_t syncBuildAppendEntriesFromRaftEntry(SSyncNode* pNode, SSyncRaftEntry* pE pRpcMsg->contLen = bytes; pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen); if (pRpcMsg->pCont == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SyncAppendEntries* pMsg = pRpcMsg->pCont; @@ -181,7 +181,7 @@ int32_t syncBuildHeartbeat(SRpcMsg* pMsg, int32_t vgId) { pMsg->msgType = TDMT_SYNC_HEARTBEAT; pMsg->contLen = bytes; if (pMsg->pCont == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SyncHeartbeat* pHeartbeat = pMsg->pCont; @@ -197,7 +197,7 @@ int32_t syncBuildHeartbeatReply(SRpcMsg* pMsg, int32_t vgId) { pMsg->msgType = TDMT_SYNC_HEARTBEAT_REPLY; pMsg->contLen = bytes; if (pMsg->pCont == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SyncHeartbeatReply* pHeartbeatReply = pMsg->pCont; @@ -213,7 +213,7 @@ int32_t syncBuildSnapshotSend(SRpcMsg* pMsg, int32_t dataLen, int32_t vgId) { pMsg->msgType = TDMT_SYNC_SNAPSHOT_SEND; pMsg->contLen = bytes; if (pMsg->pCont == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SyncSnapshotSend* pSnapshotSend = pMsg->pCont; @@ -230,7 +230,7 @@ int32_t syncBuildSnapshotSendRsp(SRpcMsg* pMsg, int32_t dataLen, int32_t vgId) { pMsg->msgType = TDMT_SYNC_SNAPSHOT_RSP; pMsg->contLen = bytes; if (pMsg->pCont == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SyncSnapshotRsp* pPreSnapshotRsp = pMsg->pCont; @@ -246,7 +246,7 @@ int32_t syncBuildLeaderTransfer(SRpcMsg* pMsg, int32_t vgId) { pMsg->msgType = TDMT_SYNC_LEADER_TRANSFER; pMsg->contLen = bytes; if (pMsg->pCont == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SyncLeaderTransfer* pLeaderTransfer = pMsg->pCont; @@ -262,7 +262,7 @@ int32_t syncBuildLocalCmd(SRpcMsg* pMsg, int32_t vgId) { pMsg->msgType = TDMT_SYNC_LOCAL_CMD; pMsg->contLen = bytes; if (pMsg->pCont == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } SyncLocalCmd* pLocalCmd = pMsg->pCont; diff --git a/source/libs/sync/src/syncPipeline.c b/source/libs/sync/src/syncPipeline.c index d042bf8ade..de83c51211 100644 --- a/source/libs/sync/src/syncPipeline.c +++ b/source/libs/sync/src/syncPipeline.c @@ -450,14 +450,14 @@ int32_t syncLogBufferAccept(SSyncLogBuffer* pBuf, SSyncNode* pNode, SSyncRaftEnt goto _out; } if (pEntry->term != pExist->term) { - (void)syncLogBufferRollback(pBuf, pNode, index); + TAOS_CHECK_GOTO(syncLogBufferRollback(pBuf, pNode, index), NULL, _out); } else { sTrace("vgId:%d, duplicate log entry received. index:%" PRId64 ", term:%" PRId64 ". log buffer: [%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 ")", pNode->vgId, pEntry->index, pEntry->term, pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex); SyncTerm existPrevTerm = -1; - (void)syncLogReplGetPrevLogTerm(NULL, pNode, index, &existPrevTerm); + TAOS_CHECK_GOTO(syncLogReplGetPrevLogTerm(NULL, pNode, index, &existPrevTerm), NULL, _out); if (!(pEntry->term == pExist->term && (pEntry->index > pBuf->matchIndex || prevTerm == existPrevTerm))) { sError("vgId:%d, failed to accept, pEntry->term:%" PRId64 ", pExist->indexpExist->term:%" PRId64 ", pEntry->index:%" PRId64 ", pBuf->matchIndex:%" PRId64 ", prevTerm:%" PRId64 @@ -650,7 +650,10 @@ int64_t syncLogBufferProceed(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncTerm* p } // replicate on demand - (void)syncNodeReplicateWithoutLock(pNode); + if ((code = syncNodeReplicateWithoutLock(pNode)) != 0) { + sError("vgId:%d, failed to replicate since %s. index:%" PRId64, pNode->vgId, tstrerror(code), pEntry->index); + goto _out; + } if (pEntry->index != pBuf->matchIndex) { sError("vgId:%d, failed to proceed, pEntry->index:%" PRId64 ", pBuf->matchIndex:%" PRId64, pNode->vgId, @@ -721,7 +724,8 @@ int32_t syncFsmExecute(SSyncNode* pNode, SSyncFSM* pFsm, ESyncState role, SyncTe cbMeta.currentTerm = term; cbMeta.flag = -1; - (void)syncRespMgrGetAndDel(pNode->pSyncRespMgr, cbMeta.seqNum, &rpcMsg.info); + int32_t num = syncRespMgrGetAndDel(pNode->pSyncRespMgr, cbMeta.seqNum, &rpcMsg.info); + sDebug("vgId:%d, get response info, seqNum:%" PRId64 ", num:%d", pNode->vgId, cbMeta.seqNum, num); code = pFsm->FpCommitCb(pFsm, &rpcMsg, &cbMeta); retry = (code != 0) && (terrno == TSDB_CODE_OUT_OF_RPC_MEMORY_QUEUE); if (retry) { @@ -1033,7 +1037,7 @@ int32_t syncLogReplRecover(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEn } } else { if (pMsg->lastSendIndex < pMgr->startIndex || pMsg->lastSendIndex >= pMgr->endIndex) { - (void)syncLogReplRetryOnNeed(pMgr, pNode); + TAOS_CHECK_RETURN(syncLogReplRetryOnNeed(pMgr, pNode)); return 0; } @@ -1108,7 +1112,7 @@ int32_t syncLogReplRecover(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncAppendEn } // attempt to replicate the raft log at index - (void)syncLogReplReset(pMgr); + syncLogReplReset(pMgr); return syncLogReplProbe(pMgr, pNode, index); } @@ -1136,9 +1140,9 @@ int32_t syncLogReplProcessReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncApp } if (pMgr->restored) { - (void)syncLogReplContinue(pMgr, pNode, pMsg); + TAOS_CHECK_RETURN(syncLogReplContinue(pMgr, pNode, pMsg)); } else { - (void)syncLogReplRecover(pMgr, pNode, pMsg); + TAOS_CHECK_RETURN(syncLogReplRecover(pMgr, pNode, pMsg)); } (void)taosThreadMutexUnlock(&pBuf->mutex); return 0; @@ -1146,9 +1150,9 @@ int32_t syncLogReplProcessReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncApp int32_t syncLogReplStart(SSyncLogReplMgr* pMgr, SSyncNode* pNode) { if (pMgr->restored) { - (void)syncLogReplAttempt(pMgr, pNode); + TAOS_CHECK_RETURN(syncLogReplAttempt(pMgr, pNode)); } else { - (void)syncLogReplProbe(pMgr, pNode, pNode->pLogBuf->matchIndex); + TAOS_CHECK_RETURN(syncLogReplProbe(pMgr, pNode, pNode->pLogBuf->matchIndex)); } return 0; } @@ -1164,7 +1168,7 @@ int32_t syncLogReplProbe(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex inde nowMs < pMgr->states[pMgr->startIndex % pMgr->size].timeMs + retryMaxWaitMs) { return 0; } - (void)syncLogReplReset(pMgr); + syncLogReplReset(pMgr); SRaftId* pDestId = &pNode->replicasId[pMgr->peerId]; bool barrier = false; @@ -1237,7 +1241,7 @@ int32_t syncLogReplAttempt(SSyncLogReplMgr* pMgr, SSyncNode* pNode) { } } - (void)syncLogReplRetryOnNeed(pMgr, pNode); + TAOS_CHECK_RETURN(syncLogReplRetryOnNeed(pMgr, pNode)); SSyncLogBuffer* pBuf = pNode->pLogBuf; sTrace("vgId:%d, replicated %d msgs to peer:%" PRIx64 ". indexes:%" PRId64 "..., terms: ...%" PRId64 @@ -1291,7 +1295,7 @@ void syncLogReplDestroy(SSyncLogReplMgr* pMgr) { if (pMgr == NULL) { return; } - (void)taosMemoryFree(pMgr); + taosMemoryFree(pMgr); return; } @@ -1300,7 +1304,7 @@ int32_t syncNodeLogReplInit(SSyncNode* pNode) { if (pNode->logReplMgrs[i] != NULL) return TSDB_CODE_SYN_INTERNAL_ERROR; pNode->logReplMgrs[i] = syncLogReplCreate(); if (pNode->logReplMgrs[i] == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } pNode->logReplMgrs[i]->peerId = i; } @@ -1374,7 +1378,7 @@ void syncLogBufferDestroy(SSyncLogBuffer* pBuf) { syncLogBufferClear(pBuf); (void)taosThreadMutexDestroy(&pBuf->mutex); (void)taosThreadMutexAttrDestroy(&pBuf->attr); - (void)taosMemoryFree(pBuf); + taosMemoryFree(pBuf); return; } @@ -1395,7 +1399,7 @@ int32_t syncLogBufferRollback(SSyncLogBuffer* pBuf, SSyncNode* pNode, SyncIndex while (index >= toIndex) { SSyncRaftEntry* pEntry = pBuf->entries[index % pBuf->size].pItem; if (pEntry != NULL) { - (void)syncEntryDestroy(pEntry); + syncEntryDestroy(pEntry); pEntry = NULL; (void)memset(&pBuf->entries[index % pBuf->size], 0, sizeof(pBuf->entries[0])); } @@ -1435,7 +1439,7 @@ int32_t syncLogBufferReset(SSyncLogBuffer* pBuf, SSyncNode* pNode) { if (lastVer != pBuf->matchIndex) return TSDB_CODE_SYN_INTERNAL_ERROR; SyncIndex index = pBuf->endIndex - 1; - (void)syncLogBufferRollback(pBuf, pNode, pBuf->matchIndex + 1); + TAOS_CHECK_RETURN(syncLogBufferRollback(pBuf, pNode, pBuf->matchIndex + 1)); sInfo("vgId:%d, reset sync log buffer. buffer: [%" PRId64 " %" PRId64 " %" PRId64 ", %" PRId64 ")", pNode->vgId, pBuf->startIndex, pBuf->commitIndex, pBuf->matchIndex, pBuf->endIndex); @@ -1483,6 +1487,7 @@ int32_t syncLogReplSendTo(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex ind SyncTerm prevLogTerm = -1; SSyncLogBuffer* pBuf = pNode->pLogBuf; int32_t code = 0; + int32_t lino = 0; code = syncLogBufferGetOneEntry(pBuf, pNode, index, &inBuf, &pEntry); if (pEntry == NULL) { @@ -1492,7 +1497,7 @@ int32_t syncLogReplSendTo(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex ind if (pMgr) { sInfo("vgId:%d, reset sync log repl of peer:%" PRIx64 " since %s. index:%" PRId64, pNode->vgId, pDestId->addr, tstrerror(code), index); - (void)syncLogReplReset(pMgr); + syncLogReplReset(pMgr); } } goto _err; @@ -1512,7 +1517,7 @@ int32_t syncLogReplSendTo(SSyncLogReplMgr* pMgr, SSyncNode* pNode, SyncIndex ind goto _err; } - (void)syncNodeSendAppendEntries(pNode, pDestId, &msgOut); + TAOS_CHECK_GOTO(syncNodeSendAppendEntries(pNode, pDestId, &msgOut), &lino, _err); sTrace("vgId:%d, replicate one msg index:%" PRId64 " term:%" PRId64 " prevterm:%" PRId64 " to dest: 0x%016" PRIx64, pNode->vgId, pEntry->index, pEntry->term, prevLogTerm, pDestId->addr); diff --git a/source/libs/sync/src/syncRaftCfg.c b/source/libs/sync/src/syncRaftCfg.c index e8ed73b089..5d938afa67 100644 --- a/source/libs/sync/src/syncRaftCfg.c +++ b/source/libs/sync/src/syncRaftCfg.c @@ -49,7 +49,7 @@ static int32_t syncEncodeSyncCfg(const void *pObj, SJson *pJson) { SJson *nodeInfo = tjsonCreateArray(); if (nodeInfo == NULL) { - TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); + TAOS_CHECK_EXIT(terrno); } if ((code = tjsonAddItemToObject(pJson, "nodeInfo", nodeInfo)) < 0) { @@ -60,7 +60,7 @@ static int32_t syncEncodeSyncCfg(const void *pObj, SJson *pJson) { for (int32_t i = 0; i < pCfg->totalReplicaNum; ++i) { SJson *info = tjsonCreateObject(); if (info == NULL) { - TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); + TAOS_CHECK_EXIT(terrno); } TAOS_CHECK_GOTO(tjsonAddDoubleToObject(info, "nodePort", pCfg->nodeInfo[i].nodePort), NULL, _err); TAOS_CHECK_GOTO(tjsonAddStringToObject(info, "nodeFqdn", pCfg->nodeInfo[i].nodeFqdn), NULL, _err); @@ -97,7 +97,7 @@ static int32_t syncEncodeRaftCfg(const void *pObj, SJson *pJson) { SJson *configIndexArr = tjsonCreateArray(); if (configIndexArr == NULL) { - TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); + TAOS_CHECK_EXIT(terrno); } if ((code = tjsonAddItemToObject(pJson, "configIndexArr", configIndexArr)) < 0) { @@ -108,7 +108,7 @@ static int32_t syncEncodeRaftCfg(const void *pObj, SJson *pJson) { for (int32_t i = 0; i < pCfg->configIndexCount; ++i) { SJson *configIndex = tjsonCreateObject(); if (configIndex == NULL) { - TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); + TAOS_CHECK_EXIT(terrno); } TAOS_CHECK_EXIT(tjsonAddIntegerToObject(configIndex, "index", pCfg->configIndexArr[i])); TAOS_CHECK_EXIT(tjsonAddItemToArray(configIndexArr, configIndex)); @@ -139,13 +139,13 @@ int32_t syncWriteCfgFile(SSyncNode *pNode) { (void)snprintf(file, sizeof(file), "%s.bak", realfile); if ((pJson = tjsonCreateObject()) == NULL) { - TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); + TAOS_CHECK_EXIT(terrno); } TAOS_CHECK_EXIT(tjsonAddObject(pJson, "RaftCfg", syncEncodeRaftCfg, pCfg)); buffer = tjsonToString(pJson); if (buffer == NULL) { - TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); + TAOS_CHECK_EXIT(terrno); } pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); @@ -163,7 +163,7 @@ int32_t syncWriteCfgFile(SSyncNode *pNode) { TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno)); } - (void)taosCloseFile(&pFile); + TAOS_CHECK_EXIT(taosCloseFile(&pFile)); TAOS_CHECK_EXIT(taosRenameFile(file, realfile)); sInfo("vgId:%d, succeed to write sync cfg file:%s, len:%d, lastConfigIndex:%" PRId64 ", changeVersion:%d", @@ -273,7 +273,7 @@ int32_t syncReadCfgFile(SSyncNode *pNode) { pData = taosMemoryMalloc(size + 1); if (pData == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } diff --git a/source/libs/sync/src/syncRaftEntry.c b/source/libs/sync/src/syncRaftEntry.c index 56a702a9d5..f4301fa167 100644 --- a/source/libs/sync/src/syncRaftEntry.c +++ b/source/libs/sync/src/syncRaftEntry.c @@ -107,7 +107,7 @@ int32_t syncEntry2OriginalRpc(const SSyncRaftEntry* pEntry, SRpcMsg* pRpcMsg) { pRpcMsg->contLen = (int32_t)(pEntry->dataLen); pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen); if (pRpcMsg->pCont == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(pRpcMsg->pCont, pEntry->data, pRpcMsg->contLen); diff --git a/source/libs/sync/src/syncRaftStore.c b/source/libs/sync/src/syncRaftStore.c index 3bb40286bc..c61be4356c 100644 --- a/source/libs/sync/src/syncRaftStore.c +++ b/source/libs/sync/src/syncRaftStore.c @@ -66,7 +66,7 @@ int32_t raftStoreReadFile(SSyncNode *pNode) { pData = taosMemoryMalloc(size + 1); if (pData == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } if (taosReadFile(pFile, pData, size) != size) { @@ -120,11 +120,11 @@ int32_t raftStoreWriteFile(SSyncNode *pNode) { snprintf(file, sizeof(file), "%s.bak", realfile); pJson = tjsonCreateObject(); - if (pJson == NULL) TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + if (pJson == NULL) TAOS_CHECK_GOTO(terrno, &lino, _OVER); if (raftStoreEncode(pJson, pStore) != 0) TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); buffer = tjsonToString(pJson); - if (buffer == NULL) TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); + if (buffer == NULL) TAOS_CHECK_GOTO(terrno, &lino, _OVER); pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) TAOS_CHECK_GOTO(terrno, &lino, _OVER); @@ -134,7 +134,7 @@ int32_t raftStoreWriteFile(SSyncNode *pNode) { if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(terrno, &lino, _OVER); - (void)taosCloseFile(&pFile); + TAOS_CHECK_GOTO(taosCloseFile(&pFile), &lino, _OVER); if (taosRenameFile(file, realfile) != 0) TAOS_CHECK_GOTO(terrno, &lino, _OVER); code = 0; @@ -168,21 +168,30 @@ bool raftStoreHasVoted(SSyncNode *pNode) { void raftStoreVote(SSyncNode *pNode, SRaftId *pRaftId) { (void)taosThreadMutexLock(&pNode->raftStore.mutex); pNode->raftStore.voteFor = *pRaftId; - (void)raftStoreWriteFile(pNode); + int32_t code = 0; + if ((code = raftStoreWriteFile(pNode)) != 0) { + sError("vgId:%d, failed to write raft store file since %s", pNode->vgId, tstrerror(code)); + } (void)taosThreadMutexUnlock(&pNode->raftStore.mutex); } void raftStoreClearVote(SSyncNode *pNode) { (void)taosThreadMutexLock(&pNode->raftStore.mutex); pNode->raftStore.voteFor = EMPTY_RAFT_ID; - (void)raftStoreWriteFile(pNode); + int32_t code = 0; + if ((code = raftStoreWriteFile(pNode)) != 0) { + sError("vgId:%d, failed to write raft store file since %s", pNode->vgId, tstrerror(code)); + } (void)taosThreadMutexUnlock(&pNode->raftStore.mutex); } void raftStoreNextTerm(SSyncNode *pNode) { (void)taosThreadMutexLock(&pNode->raftStore.mutex); pNode->raftStore.currentTerm++; - (void)raftStoreWriteFile(pNode); + int32_t code = 0; + if ((code = raftStoreWriteFile(pNode)) != 0) { + sError("vgId:%d, failed to write raft store file since %s", pNode->vgId, tstrerror(code)); + } (void)taosThreadMutexUnlock(&pNode->raftStore.mutex); } @@ -190,7 +199,10 @@ void raftStoreSetTerm(SSyncNode *pNode, SyncTerm term) { (void)taosThreadMutexLock(&pNode->raftStore.mutex); if (pNode->raftStore.currentTerm < term) { pNode->raftStore.currentTerm = term; - (void)raftStoreWriteFile(pNode); + int32_t code = 0; + if ((code = raftStoreWriteFile(pNode)) != 0) { + sError("vgId:%d, failed to write raft store file since %s", pNode->vgId, tstrerror(code)); + } } (void)taosThreadMutexUnlock(&pNode->raftStore.mutex); } diff --git a/source/libs/sync/src/syncReplication.c b/source/libs/sync/src/syncReplication.c index 6233801a51..247b5624c3 100644 --- a/source/libs/sync/src/syncReplication.c +++ b/source/libs/sync/src/syncReplication.c @@ -68,14 +68,16 @@ int32_t syncNodeReplicate(SSyncNode* pNode) { int32_t syncNodeReplicateWithoutLock(SSyncNode* pNode) { if ((pNode->state != TAOS_SYNC_STATE_LEADER && pNode->state != TAOS_SYNC_STATE_ASSIGNED_LEADER) || pNode->raftCfg.cfg.totalReplicaNum == 1) { - TAOS_RETURN(TSDB_CODE_FAILED); + TAOS_RETURN(TSDB_CODE_SUCCESS); } for (int32_t i = 0; i < pNode->totalReplicaNum; i++) { if (syncUtilSameId(&pNode->replicasId[i], &pNode->myRaftId)) { continue; } SSyncLogReplMgr* pMgr = pNode->logReplMgrs[i]; - (void)syncLogReplStart(pMgr, pNode); + if (syncLogReplStart(pMgr, pNode) != 0) { + sError("vgId:%d, failed to start log replication to dnode:%d", pNode->vgId, DID(&(pNode->replicasId[i]))); + } } TAOS_RETURN(TSDB_CODE_SUCCESS); @@ -84,7 +86,7 @@ int32_t syncNodeReplicateWithoutLock(SSyncNode* pNode) { int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, SRpcMsg* pRpcMsg) { SyncAppendEntries* pMsg = pRpcMsg->pCont; pMsg->destId = *destRaftId; - (void)syncNodeSendMsgById(destRaftId, pSyncNode, pRpcMsg); + TAOS_CHECK_RETURN(syncNodeSendMsgById(destRaftId, pSyncNode, pRpcMsg)); TAOS_RETURN(TSDB_CODE_SUCCESS); } @@ -116,7 +118,10 @@ int32_t syncNodeHeartbeatPeers(SSyncNode* pSyncNode) { STraceId* trace = &(rpcMsg.info.traceId); sGTrace("vgId:%d, send sync-heartbeat to dnode:%d", pSyncNode->vgId, DID(&(pSyncMsg->destId))); syncLogSendHeartbeat(pSyncNode, pSyncMsg, true, 0, 0); - (void)syncNodeSendHeartbeat(pSyncNode, &pSyncMsg->destId, &rpcMsg); + int32_t ret = syncNodeSendHeartbeat(pSyncNode, &pSyncMsg->destId, &rpcMsg); + if (ret != 0) { + sError("vgId:%d, failed to send sync-heartbeat since %s", pSyncNode->vgId, tstrerror(ret)); + } } TAOS_RETURN(TSDB_CODE_SUCCESS); diff --git a/source/libs/sync/src/syncRequestVote.c b/source/libs/sync/src/syncRequestVote.c index c8e81b13df..fe5b3eb7ad 100644 --- a/source/libs/sync/src/syncRequestVote.c +++ b/source/libs/sync/src/syncRequestVote.c @@ -137,7 +137,7 @@ int32_t syncNodeOnRequestVote(SSyncNode* ths, const SRpcMsg* pRpcMsg) { // trace log syncLogRecvRequestVote(ths, pMsg, pReply->voteGranted, "", "proceed"); syncLogSendRequestVoteReply(ths, pReply, ""); - (void)syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg); + TAOS_CHECK_RETURN(syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg)); if (resetElect) syncNodeResetElectTimer(ths); diff --git a/source/libs/sync/src/syncRespMgr.c b/source/libs/sync/src/syncRespMgr.c index 854d6bc314..59825ef91e 100644 --- a/source/libs/sync/src/syncRespMgr.c +++ b/source/libs/sync/src/syncRespMgr.c @@ -32,7 +32,7 @@ int32_t syncRespMgrCreate(void *data, int64_t ttl, SSyncRespMgr **ppObj) { taosHashInit(sizeof(uint64_t), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (pObj->pRespHash == NULL) { taosMemoryFree(pObj); - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } pObj->ttl = ttl; @@ -110,7 +110,9 @@ int32_t syncRespMgrGetAndDel(SSyncRespMgr *pObj, uint64_t seq, SRpcHandleInfo *p *pInfo = pStub->rpcMsg.info; sNTrace(pObj->data, "get-and-del message handle:%p, type:%s seq:%" PRIu64, pStub->rpcMsg.info.handle, TMSG_INFO(pStub->rpcMsg.msgType), seq); - (void)taosHashRemove(pObj->pRespHash, &seq, sizeof(uint64_t)); + if (taosHashRemove(pObj->pRespHash, &seq, sizeof(uint64_t)) != 0) { + sError("failed to remove seq:%" PRIu64, seq); + } (void)taosThreadMutexUnlock(&pObj->mutex); return 1; // get one object @@ -130,7 +132,7 @@ static int32_t syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp) { SArray *delIndexArray = taosArrayInit(4, sizeof(uint64_t)); if (delIndexArray == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } sDebug("vgId:%d, resp manager begin clean by ttl", pNode->vgId); @@ -165,7 +167,9 @@ static int32_t syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp) { SRpcMsg rpcMsg = {.info = pStub->rpcMsg.info, .code = TSDB_CODE_SYN_TIMEOUT}; sInfo("vgId:%d, message handle:%p expired, type:%s ahandle:%p", pNode->vgId, rpcMsg.info.handle, TMSG_INFO(pStub->rpcMsg.msgType), rpcMsg.info.ahandle); - (void)rpcSendResponse(&rpcMsg); + if (rpcSendResponse(&rpcMsg) != 0) { + sError("vgId:%d, failed to send response, handle:%p", pNode->vgId, rpcMsg.info.handle); + } } pStub = taosHashIterate(pObj->pRespHash, pStub); @@ -176,7 +180,9 @@ static int32_t syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp) { for (int32_t i = 0; i < arraySize; ++i) { uint64_t *pSeqNum = taosArrayGet(delIndexArray, i); - (void)taosHashRemove(pObj->pRespHash, pSeqNum, sizeof(uint64_t)); + if (taosHashRemove(pObj->pRespHash, pSeqNum, sizeof(uint64_t)) != 0) { + sError("vgId:%d, failed to remove seq:%" PRIu64, pNode->vgId, *pSeqNum); + } sDebug("vgId:%d, resp manager clean by ttl, seq:%" PRId64, pNode->vgId, *pSeqNum); } taosArrayDestroy(delIndexArray); @@ -191,7 +197,10 @@ void syncRespCleanRsp(SSyncRespMgr *pObj) { sTrace("vgId:%d, clean all resp", pNode->vgId); (void)taosThreadMutexLock(&pObj->mutex); - (void)syncRespCleanByTTL(pObj, -1, true); + int32_t code = 0; + if ((code = syncRespCleanByTTL(pObj, -1, true)) != 0) { + sError("vgId:%d, failed to clean all resp since %s", pNode->vgId, tstrerror(code)); + } (void)taosThreadMutexUnlock(&pObj->mutex); } @@ -200,6 +209,9 @@ void syncRespClean(SSyncRespMgr *pObj) { sTrace("vgId:%d, clean resp by ttl", pNode->vgId); (void)taosThreadMutexLock(&pObj->mutex); - (void)syncRespCleanByTTL(pObj, pObj->ttl, false); + int32_t code = 0; + if ((code = syncRespCleanByTTL(pObj, pObj->ttl, false)) != 0) { + sError("vgId:%d, failed to clean resp by ttl since %s", pNode->vgId, tstrerror(code)); + } (void)taosThreadMutexUnlock(&pObj->mutex); } diff --git a/source/libs/sync/src/syncSnapshot.c b/source/libs/sync/src/syncSnapshot.c index 0b77ab78a6..78fda6b093 100644 --- a/source/libs/sync/src/syncSnapshot.c +++ b/source/libs/sync/src/syncSnapshot.c @@ -720,7 +720,7 @@ static int32_t syncSnapReceiverExchgSnapInfo(SSyncNode *pSyncNode, SSyncSnapshot SSnapshotParam *pParam = &pReceiver->snapshotParam; data = taosMemoryRealloc(pParam->data, dataLen); if (data == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; sError("vgId:%d, failed to realloc memory for snapshot prep due to %s. dataLen:%d", pSyncNode->vgId, tstrerror(code), dataLen); goto _exit; @@ -916,7 +916,9 @@ static int32_t syncSnapBufferRecv(SSyncSnapshotReceiver *pReceiver, SyncSnapshot } } pRcvBuf->start = seq + 1; - (void)syncSnapSendRsp(pReceiver, pRcvBuf->entries[seq % pRcvBuf->size], NULL, 0, 0, code); + if (syncSnapSendRsp(pReceiver, pRcvBuf->entries[seq % pRcvBuf->size], NULL, 0, 0, code) != 0) { + sError("failed to send snap rsp"); + } pRcvBuf->entryDeleteCb(pRcvBuf->entries[seq % pRcvBuf->size]); pRcvBuf->entries[seq % pRcvBuf->size] = NULL; if (code) goto _out; @@ -1011,7 +1013,7 @@ int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SRpcMsg *pRpcMsg) { sRError(pReceiver, "reject snap replication with smaller term. msg term:%" PRId64 ", seq:%d", pMsg->term, pMsg->seq); code = TSDB_CODE_SYN_MISMATCHED_SIGNATURE; - (void)syncSnapSendRsp(pReceiver, pMsg, NULL, 0, 0, code); + if (syncSnapSendRsp(pReceiver, pMsg, NULL, 0, 0, code) != 0) sError("failed to send snap rsp"); TAOS_RETURN(code); } @@ -1092,7 +1094,7 @@ static int32_t syncSnapSenderExchgSnapInfo(SSyncNode *pSyncNode, SSyncSnapshotSe SSnapshotParam *pParam = &pSender->snapshotParam; void *data = taosMemoryRealloc(pParam->data, dataLen); if (data == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } (void)memcpy(data, pMsg->data, dataLen); @@ -1298,13 +1300,13 @@ int32_t syncNodeOnSnapshotRsp(SSyncNode *pSyncNode, SRpcMsg *pRpcMsg) { if (pMsg->ack == SYNC_SNAPSHOT_SEQ_END) { sSInfo(pSender, "process end rsp"); snapshotSenderStop(pSender, true); - (void)syncNodeReplicateReset(pSyncNode, &pMsg->srcId); + TAOS_CHECK_GOTO(syncNodeReplicateReset(pSyncNode, &pMsg->srcId), NULL, _ERROR); } return 0; _ERROR: snapshotSenderStop(pSender, false); - (void)syncNodeReplicateReset(pSyncNode, &pMsg->srcId); + if (syncNodeReplicateReset(pSyncNode, &pMsg->srcId) != 0) sError("failed to reset replicate"); TAOS_RETURN(code); } diff --git a/source/libs/sync/src/syncTimeout.c b/source/libs/sync/src/syncTimeout.c index b2233ae664..c073c2c1bb 100644 --- a/source/libs/sync/src/syncTimeout.c +++ b/source/libs/sync/src/syncTimeout.c @@ -65,7 +65,7 @@ static int32_t syncNodeTimerRoutine(SSyncNode* ths) { } // timer replicate - (void)syncNodeReplicate(ths); + TAOS_CHECK_RETURN(syncNodeReplicate(ths)); // clean mnode index if (syncNodeIsMnode(ths)) { @@ -89,7 +89,7 @@ static int32_t syncNodeTimerRoutine(SSyncNode* ths) { snapshotSenderStop(pSender, false); } else { sSWarn(pSender, "snap replication resend."); - (void)snapshotReSend(pSender); + TAOS_CHECK_RETURN(snapshotReSend(pSender)); } } } @@ -112,14 +112,14 @@ int32_t syncNodeOnTimeout(SSyncNode* ths, const SRpcMsg* pRpc) { if (atomic_load_64(&ths->pingTimerLogicClockUser) <= pMsg->logicClock) { ++(ths->pingTimerCounter); - (void)syncNodeTimerRoutine(ths); + TAOS_CHECK_RETURN(syncNodeTimerRoutine(ths)); } } else if (pMsg->timeoutType == SYNC_TIMEOUT_ELECTION) { if (atomic_load_64(&ths->electTimerLogicClock) <= pMsg->logicClock) { ++(ths->electTimerCounter); - (void)syncNodeElect(ths); + TAOS_CHECK_RETURN(syncNodeElect(ths)); } } else if (pMsg->timeoutType == SYNC_TIMEOUT_HEARTBEAT) { diff --git a/source/libs/sync/src/syncUtil.c b/source/libs/sync/src/syncUtil.c index 553560f089..6f7ea9375c 100644 --- a/source/libs/sync/src/syncUtil.c +++ b/source/libs/sync/src/syncUtil.c @@ -499,7 +499,7 @@ void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteRepl int32_t syncSnapInfoDataRealloc(SSnapshot* pSnap, int32_t size) { void* data = taosMemoryRealloc(pSnap->data, size); if (data == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pSnap->data = data; return 0; diff --git a/source/libs/sync/test/syncRespMgrTest.cpp b/source/libs/sync/test/syncRespMgrTest.cpp index 714f42a836..a9887243de 100644 --- a/source/libs/sync/test/syncRespMgrTest.cpp +++ b/source/libs/sync/test/syncRespMgrTest.cpp @@ -77,7 +77,7 @@ SSyncNode *createSyncNode() { void test1() { printf("------- test1 ---------\n"); - (void)syncRespMgrCreate(createSyncNode(), 0, &pMgr); + assert(syncRespMgrCreate(createSyncNode(), 0, &pMgr) == 0); assert(pMgr != NULL); syncRespMgrInsert(10); @@ -102,7 +102,7 @@ void test1() { void test2() { printf("------- test2 ---------\n"); - (void)syncRespMgrCreate(createSyncNode(), 0, &pMgr); + assert(syncRespMgrCreate(createSyncNode(), 0, &pMgr) == 0); assert(pMgr != NULL); syncRespMgrInsert(10); @@ -119,7 +119,7 @@ void test2() { void test3() { printf("------- test3 ---------\n"); - (void)syncRespMgrCreate(createSyncNode(), 0, &pMgr); + assert(syncRespMgrCreate(createSyncNode(), 0, &pMgr) == 0); assert(pMgr != NULL); syncRespMgrInsert(10); @@ -136,7 +136,7 @@ void test3() { void test4() { printf("------- test4 ---------\n"); - (void)syncRespMgrCreate(createSyncNode(), 2, &pMgr); + assert(syncRespMgrCreate(createSyncNode(), 2, &pMgr) == 0); assert(pMgr != NULL); syncRespMgrInsert(5); diff --git a/source/libs/sync/test/syncSnapshotSenderTest.cpp b/source/libs/sync/test/syncSnapshotSenderTest.cpp index be31df30e9..e415a5761b 100644 --- a/source/libs/sync/test/syncSnapshotSenderTest.cpp +++ b/source/libs/sync/test/syncSnapshotSenderTest.cpp @@ -40,7 +40,7 @@ SSyncSnapshotSender* createSender() { #endif SSyncSnapshotSender* pSender = NULL; - (void)snapshotSenderCreate(pSyncNode, 2, &pSender); + assert(snapshotSenderCreate(pSyncNode, 2, &pSender) == 0); pSender->start = true; pSender->seq = 10; pSender->ack = 20; diff --git a/source/libs/tdb/inc/tdb.h b/source/libs/tdb/inc/tdb.h index 374c3e0dc3..52ff749191 100644 --- a/source/libs/tdb/inc/tdb.h +++ b/source/libs/tdb/inc/tdb.h @@ -34,19 +34,19 @@ typedef struct STxn TXN; // TDB int32_t tdbOpen(const char *dbname, int szPage, int pages, TDB **ppDb, int8_t rollback, int32_t encryptAlgorithm, char *encryptKey); -int32_t tdbClose(TDB *pDb); +void tdbClose(TDB *pDb); int32_t tdbBegin(TDB *pDb, TXN **pTxn, void *(*xMalloc)(void *, size_t), void (*xFree)(void *, void *), void *xArg, int flags); 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 int32_t tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprFn, TDB *pEnv, TTB **ppTb, int8_t rollback); -int32_t tdbTbClose(TTB *pTb); +void tdbTbClose(TTB *pTb); bool tdbTbExist(const char *tbname, TDB *pEnv); int tdbTbDropByName(const char *tbname, TDB *pEnv, TXN *pTxn); int32_t tdbTbDrop(TTB *pTb); @@ -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 diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index 7c342c0527..c688a6cc6a 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -79,7 +79,7 @@ int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, char const *tbname, SPg pBt = (SBTree *)tdbOsCalloc(1, sizeof(*pBt)); if (pBt == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } // pBt->keyLen @@ -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) { diff --git a/source/libs/tdb/src/db/tdbDb.c b/source/libs/tdb/src/db/tdbDb.c index 825a6e2b94..02ab997f69 100644 --- a/source/libs/tdb/src/db/tdbDb.c +++ b/source/libs/tdb/src/db/tdbDb.c @@ -90,7 +90,7 @@ int32_t tdbOpen(const char *dbname, int32_t szPage, int32_t pages, TDB **ppDb, i return 0; } -int tdbClose(TDB *pDb) { +void tdbClose(TDB *pDb) { SPager *pPager; if (pDb) { @@ -101,15 +101,15 @@ 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); } - return 0; + return; } int32_t tdbAlter(TDB *pDb, int pages) { return tdbPCacheAlter(pDb->pCache, pages); } @@ -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) { diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index 53c1284faa..b0bcbd1a4c 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -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; @@ -58,14 +77,14 @@ int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache) { pCache = (SPCache *)tdbOsCalloc(1, sizeof(*pCache) + sizeof(SPage *) * cacheSize); if (pCache == NULL) { - TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } pCache->szPage = pageSize; pCache->nPages = cacheSize; pCache->aPage = (SPage **)tdbOsCalloc(cacheSize, sizeof(SPage *)); if (pCache->aPage == NULL) { - TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } code = tdbPCacheOpenImpl(pCache); @@ -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: @@ -105,7 +124,7 @@ static int tdbPCacheAlterImpl(SPCache *pCache, int32_t nPage) { } else if (pCache->nPages < nPage) { SPage **aPage = tdbOsCalloc(nPage, sizeof(SPage *)); if (aPage == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int32_t iPage = pCache->nPages; iPage < nPage; iPage++) { @@ -502,7 +521,7 @@ static int tdbPCacheOpenImpl(SPCache *pCache) { pCache->nHash = pCache->nPages < 8 ? 8 : pCache->nPages; pCache->pgHash = (SPage **)tdbOsCalloc(pCache->nHash, sizeof(SPage *)); if (pCache->pgHash == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } // Open LRU list @@ -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 ; } diff --git a/source/libs/tdb/src/db/tdbPage.c b/source/libs/tdb/src/db/tdbPage.c index 7888a08bb3..be391a75f1 100644 --- a/source/libs/tdb/src/db/tdbPage.c +++ b/source/libs/tdb/src/db/tdbPage.c @@ -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) { @@ -322,7 +325,7 @@ int32_t tdbPageCopy(SPage *pFromPage, SPage *pToPage, int deepCopyOvfl) { pNewCell = (SCell *)tdbOsMalloc(szCell); if (pNewCell == NULL) { tdbError("tdb/page-copy: out of memory, size: %d", szCell); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(pNewCell, pFromPage->apOvfl[iOvfl], szCell); tdbTrace("tdbPage/copy/new ovfl cell: %p/%p/%p", pNewCell, pToPage, pFromPage); @@ -524,7 +527,7 @@ static int tdbPageDefragment(SPage *pPage) { SCellIdx *aCellIdx = (SCellIdx *)tdbOsMalloc(sizeof(SCellIdx) * nCell); if (aCellIdx == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int32_t iCell = 0; iCell < nCell; iCell++) { aCellIdx[iCell].iCell = iCell; diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index 64b892692d..2753fe30d6 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -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); } @@ -167,7 +167,7 @@ int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager) { + fsize + 8 + 1; /* jFileName */ pPtr = (uint8_t *)tdbOsCalloc(1, zsize); if (pPtr == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pPager = (SPager *)pPtr; @@ -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); @@ -508,7 +511,7 @@ int tdbPagerAbort(SPager *pPager, TXN *pTxn) { u8 *pageBuf = tdbOsCalloc(1, pPager->pageSize); if (pageBuf == NULL) { - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } tdbDebug("pager/abort: %p, %d/%d, txnId:%" PRId64, pPager, pPager->dbOrigSize, pPager->dbFileSize, pTxn->txnId); @@ -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); @@ -741,7 +748,7 @@ int tdbPagerInsertFreePage(SPager *pPager, SPage *pPage, TXN *pTxn) { if (pPager->frps) { if (taosArrayPush(pPager->frps, &pgno) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pPage->pPager = NULL; return code; @@ -749,7 +756,7 @@ int tdbPagerInsertFreePage(SPager *pPager, SPage *pPage, TXN *pTxn) { pPager->frps = taosArrayInit(8, sizeof(SPgno)); if (pPager->frps == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } // memset(pPage->pData, 0, pPage->pageSize); tdbTrace("tdb/insert-free-page: tbc recycle page: %d.", pgno); @@ -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 (;;) { @@ -1056,7 +1074,7 @@ static int tdbPagerRestore(SPager *pPager, const char *jFileName) { pageBuf = tdbOsCalloc(1, pPager->pageSize); if (pageBuf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } tdbDebug("pager/restore: %p, %d/%d, txnId:%s", pPager, pPager->dbOrigSize, pPager->dbFileSize, jFileName); @@ -1141,7 +1159,7 @@ int tdbPagerRestoreJournals(SPager *pPager) { SArray *pTxnList = taosArrayInit(16, sizeof(int64_t)); if (pTxnList == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } while ((pDirEntry = tdbReadDir(pDir)) != NULL) { @@ -1150,7 +1168,7 @@ int tdbPagerRestoreJournals(SPager *pPager) { int64_t txnId = -1; (void)sscanf(name, TDB_MAINDB_NAME "-journal.%" PRId64, &txnId); if (taosArrayPush(pTxnList, &txnId) == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } } diff --git a/source/libs/tdb/src/db/tdbTable.c b/source/libs/tdb/src/db/tdbTable.c index f62e211586..6dc6aa0940 100644 --- a/source/libs/tdb/src/db/tdbTable.c +++ b/source/libs/tdb/src/db/tdbTable.c @@ -41,7 +41,7 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF pTb = (TTB *)tdbOsCalloc(1, sizeof(*pTb)); if (pTb == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } // pTb->pEnv @@ -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 @@ -126,12 +130,12 @@ int tdbTbOpen(const char *tbname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprF return 0; } -int tdbTbClose(TTB *pTb) { +void tdbTbClose(TTB *pTb) { if (pTb) { tdbBtreeClose(pTb->pBt); tdbOsFree(pTb); } - return 0; + return; } bool tdbTbExist(const char *tbname, TDB *pEnv) { @@ -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); } @@ -221,7 +225,7 @@ int tdbTbcOpen(TTB *pTb, TBC **ppTbc, TXN *pTxn) { *ppTbc = NULL; pTbc = (TBC *)tdbOsMalloc(sizeof(*pTbc)); if (pTbc == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if ((ret = tdbBtcOpen(&pTbc->btc, pTb->pBt, pTxn)) != 0) { @@ -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; diff --git a/source/libs/tdb/src/db/tdbTxn.c b/source/libs/tdb/src/db/tdbTxn.c index 71560e3e85..fff0fc0261 100644 --- a/source/libs/tdb/src/db/tdbTxn.c +++ b/source/libs/tdb/src/db/tdbTxn.c @@ -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; } diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index a4498ee1ea..3e12483309 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -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); diff --git a/source/libs/tdb/test/tdbExOVFLTest.cpp b/source/libs/tdb/test/tdbExOVFLTest.cpp index a2deba4696..388a812ff5 100644 --- a/source/libs/tdb/test/tdbExOVFLTest.cpp +++ b/source/libs/tdb/test/tdbExOVFLTest.cpp @@ -197,8 +197,7 @@ static void insertOfp(void) { tdbTbClose(pDb); // Close Env - ret = tdbClose(pEnv); - GTEST_ASSERT_EQ(ret, 0); + tdbClose(pEnv); } // TEST(TdbOVFLPagesTest, DISABLED_TbInsertTest) { @@ -247,8 +246,7 @@ TEST(TdbOVFLPagesTest, TbGetTest) { tdbTbClose(pDb); // Close Env - ret = tdbClose(pEnv); - GTEST_ASSERT_EQ(ret, 0); + tdbClose(pEnv); } // TEST(TdbOVFLPagesTest, DISABLED_TbDeleteTest) { @@ -357,8 +355,7 @@ tdbBegin(pEnv, &txn); tdbTbClose(pDb); // Close Env - ret = tdbClose(pEnv); - GTEST_ASSERT_EQ(ret, 0); + tdbClose(pEnv); } // TEST(tdb_test, DISABLED_simple_insert1) { @@ -492,6 +489,5 @@ TEST(tdb_test, simple_insert1) { tdbTbClose(pDb); // Close Env - ret = tdbClose(pEnv); - GTEST_ASSERT_EQ(ret, 0); + tdbClose(pEnv); } diff --git a/source/libs/tdb/test/tdbPageDefragmentTest.cpp b/source/libs/tdb/test/tdbPageDefragmentTest.cpp index b64517c787..85b5c6e6b3 100644 --- a/source/libs/tdb/test/tdbPageDefragmentTest.cpp +++ b/source/libs/tdb/test/tdbPageDefragmentTest.cpp @@ -468,8 +468,7 @@ TEST(TdbPageDefragmentTest, DISABLED_simple_insert1) { tdbTbClose(pDb); // Close Env - ret = tdbClose(pEnv); - GTEST_ASSERT_EQ(ret, 0); + tdbClose(pEnv); } // TEST(TdbPageDefragmentTest, DISABLED_seq_insert) { @@ -551,8 +550,7 @@ TEST(TdbPageDefragmentTest, seq_insert) { tdbTbClose(pDb); // Close Env - ret = tdbClose(pEnv); - GTEST_ASSERT_EQ(ret, 0); + tdbClose(pEnv); } // TEST(TdbPageDefragmentTest, DISABLED_seq_delete) { @@ -635,8 +633,7 @@ TEST(TdbPageDefragmentTest, seq_delete) { tdbTbClose(pDb); // Close Env - ret = tdbClose(pEnv); - GTEST_ASSERT_EQ(ret, 0); + tdbClose(pEnv); } // TEST(TdbPageDefragmentTest, DISABLED_defragment_insert) { @@ -717,6 +714,5 @@ TEST(TdbPageDefragmentTest, defragment_insert) { tdbTbClose(pDb); // Close Env - ret = tdbClose(pEnv); - GTEST_ASSERT_EQ(ret, 0); + tdbClose(pEnv); } diff --git a/source/libs/tdb/test/tdbPageRecycleTest.cpp b/source/libs/tdb/test/tdbPageRecycleTest.cpp index bbbd90e73d..30e1081d0c 100644 --- a/source/libs/tdb/test/tdbPageRecycleTest.cpp +++ b/source/libs/tdb/test/tdbPageRecycleTest.cpp @@ -123,7 +123,7 @@ static int tDefaultKeyCmpr(const void *pKey1, int keyLen1, const void *pKey2, in static TDB *openEnv(char const *envName, int const pageSize, int const pageNum) { TDB *pEnv = NULL; - int ret = tdbOpen(envName, pageSize, pageNum, &pEnv, 0 , 0, NULL); + int ret = tdbOpen(envName, pageSize, pageNum, &pEnv, 0, 0, NULL); if (ret) { pEnv = NULL; } @@ -187,8 +187,7 @@ static void insertOfp(void) { tdbTbClose(pDb); // Close Env - ret = tdbClose(pEnv); - GTEST_ASSERT_EQ(ret, 0); + tdbClose(pEnv); } static void clearDb(char const *db) { taosRemoveDir(db); } @@ -471,8 +470,7 @@ TEST(TdbPageRecycleTest, DISABLED_simple_insert1) { tdbTbClose(pDb); // Close Env - ret = tdbClose(pEnv); - GTEST_ASSERT_EQ(ret, 0); + tdbClose(pEnv); } static void insertDb(int nData) { @@ -537,8 +535,7 @@ static void insertDb(int nData) { tdbTbClose(pDb); // Close Env - ret = tdbClose(pEnv); - GTEST_ASSERT_EQ(ret, 0); + tdbClose(pEnv); system("ls -l ./tdb"); } @@ -607,8 +604,7 @@ static void deleteDb(int nData) { tdbTbClose(pDb); // Close Env - ret = tdbClose(pEnv); - GTEST_ASSERT_EQ(ret, 0); + tdbClose(pEnv); system("ls -l ./tdb"); } @@ -675,8 +671,7 @@ static void deleteOfp(void) { tdbTbClose(pDb); // Close Env - ret = tdbClose(pEnv); - GTEST_ASSERT_EQ(ret, 0); + tdbClose(pEnv); } // TEST(TdbPageRecycleTest, DISABLED_seq_delete_ofp) { @@ -761,8 +756,7 @@ TEST(TdbPageRecycleTest, recycly_seq_insert_ofp_nocommit) { tdbTbClose(pDb); // Close Env - ret = tdbClose(pEnv); - GTEST_ASSERT_EQ(ret, 0); + tdbClose(pEnv); system("ls -l ./tdb"); } @@ -828,8 +822,7 @@ TEST(TdbPageRecycleTest, recycly_delete_interior_ofp_nocommit) { tdbTbClose(pDb); // Close Env - ret = tdbClose(pEnv); - GTEST_ASSERT_EQ(ret, 0); + tdbClose(pEnv); system("ls -l ./tdb"); } diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index e358ac0197..a8fdce2c38 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -231,8 +231,7 @@ TEST(tdb_test, DISABLED_simple_insert1) { tdbTbClose(pDb); // Close Env - ret = tdbClose(pEnv); - GTEST_ASSERT_EQ(ret, 0); + tdbClose(pEnv); } TEST(tdb_test, DISABLED_simple_insert2) { @@ -315,8 +314,7 @@ TEST(tdb_test, DISABLED_simple_insert2) { tdbTbClose(pDb); // Close Env - ret = tdbClose(pEnv); - GTEST_ASSERT_EQ(ret, 0); + tdbClose(pEnv); } TEST(tdb_test, DISABLED_simple_delete1) { @@ -620,8 +618,7 @@ TEST(tdb_test, multi_thread_query) { tdbTbClose(pDb); // Close Env - ret = tdbClose(pEnv); - GTEST_ASSERT_EQ(ret, 0); + tdbClose(pEnv); } TEST(tdb_test, DISABLED_multi_thread1) { @@ -745,7 +742,6 @@ TEST(tdb_test, DISABLED_multi_thread1) { tdbTbClose(pTb); // Close Env - ret = tdbClose(pDb); - GTEST_ASSERT_EQ(ret, 0); + tdbClose(pEnv); #endif } diff --git a/source/libs/tfs/src/tfs.c b/source/libs/tfs/src/tfs.c index 9727256a58..51fda85f0a 100644 --- a/source/libs/tfs/src/tfs.c +++ b/source/libs/tfs/src/tfs.c @@ -50,7 +50,7 @@ int32_t tfsOpen(SDiskCfg *pCfg, int32_t ndisk, STfs **ppTfs) { pTfs->hash = taosHashInit(TFS_MAX_DISKS * 2, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_NO_LOCK); if (pTfs->hash == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } for (int32_t idisk = 0; idisk < ndisk; idisk++) { @@ -96,15 +96,15 @@ void tfsUpdateSize(STfs *pTfs) { size.used += pTier->size.used; } - (void)tfsLock(pTfs); + TAOS_UNUSED(tfsLock(pTfs)); pTfs->size = size; - (void)tfsUnLock(pTfs); + TAOS_UNUSED(tfsUnLock(pTfs)); } SDiskSize tfsGetSize(STfs *pTfs) { - (void)tfsLock(pTfs); + TAOS_UNUSED(tfsLock(pTfs)); SDiskSize size = pTfs->size; - (void)tfsUnLock(pTfs); + TAOS_UNUSED(tfsUnLock(pTfs)); return size; } @@ -204,8 +204,8 @@ bool tfsIsSameFile(const STfsFile *pFile1, const STfsFile *pFile2) { (void)strncpy(nameBuf2, pFile2->rname, TMPNAME_LEN); nameBuf1[TMPNAME_LEN - 1] = 0; nameBuf2[TMPNAME_LEN - 1] = 0; - (void)taosRealPath(nameBuf1, NULL, TMPNAME_LEN); - (void)taosRealPath(nameBuf2, NULL, TMPNAME_LEN); + TAOS_UNUSED(taosRealPath(nameBuf1, NULL, TMPNAME_LEN)); + TAOS_UNUSED(taosRealPath(nameBuf2, NULL, TMPNAME_LEN)); if (strncmp(nameBuf1, nameBuf2, TMPNAME_LEN) != 0) return false; return true; } @@ -284,7 +284,7 @@ int32_t tfsMkdirRecurAt(STfs *pTfs, const char *rname, SDiskID diskId) { if (errno == ENOENT) { // Try to create upper if ((s = taosStrdup(rname)) == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } // Make a copy of dirname(s) because the implementation of 'dirname' differs on different platforms. @@ -295,7 +295,7 @@ int32_t tfsMkdirRecurAt(STfs *pTfs, const char *rname, SDiskID diskId) { // https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/dirname.3.html if ((dir = taosStrdup(taosDirName(s))) == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } if (strlen(dir) >= strlen(rname)) { // TODO: check if it is necessary for equal length @@ -483,7 +483,7 @@ const STfsFile *tfsReaddir(STfsDir *pTfsDir) { void tfsClosedir(STfsDir *pTfsDir) { if (pTfsDir) { if (pTfsDir->pDir != NULL) { - (void)taosCloseDir(&pTfsDir->pDir); + TAOS_UNUSED(taosCloseDir(&pTfsDir->pDir)); pTfsDir->pDir = NULL; } taosMemoryFree(pTfsDir); @@ -693,12 +693,12 @@ static STfsDisk *tfsNextDisk(STfs *pTfs, SDiskIter *pIter) { int32_t tfsGetMonitorInfo(STfs *pTfs, SMonDiskInfo *pInfo) { pInfo->datadirs = taosArrayInit(32, sizeof(SMonDiskDesc)); if (pInfo->datadirs == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } tfsUpdateSize(pTfs); - (void)tfsLock(pTfs); + TAOS_UNUSED(tfsLock(pTfs)); for (int32_t level = 0; level < pTfs->nlevel; level++) { STfsTier *pTier = &pTfs->tiers[level]; for (int32_t disk = 0; disk < pTier->ndisk; ++disk) { @@ -708,14 +708,14 @@ int32_t tfsGetMonitorInfo(STfs *pTfs, SMonDiskInfo *pInfo) { dinfo.level = pDisk->level; tstrncpy(dinfo.name, pDisk->path, sizeof(dinfo.name)); if (taosArrayPush(pInfo->datadirs, &dinfo) == NULL) { - (void)tfsUnLock(pTfs); + TAOS_UNUSED(tfsUnLock(pTfs)); taosArrayDestroy(pInfo->datadirs); pInfo->datadirs = NULL; - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } } } - (void)tfsUnLock(pTfs); + TAOS_UNUSED(tfsUnLock(pTfs)); TAOS_RETURN(0); } diff --git a/source/libs/tfs/src/tfsDisk.c b/source/libs/tfs/src/tfsDisk.c index 6041f68f6f..14dd7f5b07 100644 --- a/source/libs/tfs/src/tfsDisk.c +++ b/source/libs/tfs/src/tfsDisk.c @@ -26,7 +26,7 @@ int32_t tfsNewDisk(int32_t level, int32_t id, int8_t disable, const char *path, } if ((pDisk->path = taosStrdup(path)) == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } pDisk->level = level; diff --git a/source/libs/tfs/src/tfsTier.c b/source/libs/tfs/src/tfsTier.c index 0733e3c76a..2cfcdc6d0a 100644 --- a/source/libs/tfs/src/tfsTier.c +++ b/source/libs/tfs/src/tfsTier.c @@ -88,7 +88,7 @@ void tfsUpdateTierSize(STfsTier *pTier) { SDiskSize size = {0}; int32_t nAvailDisks = 0; - (void)tfsLockTier(pTier); + TAOS_UNUSED(tfsLockTier(pTier)); for (int32_t id = 0; id < pTier->ndisk; id++) { STfsDisk *pDisk = pTier->disks[id]; @@ -104,15 +104,15 @@ void tfsUpdateTierSize(STfsTier *pTier) { pTier->size = size; pTier->nAvailDisks = nAvailDisks; - (void)tfsUnLockTier(pTier); + TAOS_UNUSED(tfsUnLockTier(pTier)); } // Round-Robin to allocate disk on a tier int32_t tfsAllocDiskOnTier(STfsTier *pTier) { - (void)tfsLockTier(pTier); + TAOS_UNUSED(tfsLockTier(pTier)); if (pTier->ndisk <= 0 || pTier->nAvailDisks <= 0) { - (void)tfsUnLockTier(pTier); + TAOS_UNUSED(tfsUnLockTier(pTier)); TAOS_RETURN(TSDB_CODE_FS_NO_VALID_DISK); } @@ -155,7 +155,7 @@ int32_t tfsAllocDiskOnTier(STfsTier *pTier) { #endif } - (void)tfsUnLockTier(pTier); + TAOS_UNUSED(tfsUnLockTier(pTier)); if (retId < 0) { TAOS_RETURN(TSDB_CODE_FS_NO_VALID_DISK); } diff --git a/source/libs/transport/src/thttp.c b/source/libs/transport/src/thttp.c index d4c973926e..4ac49e929c 100644 --- a/source/libs/transport/src/thttp.c +++ b/source/libs/transport/src/thttp.c @@ -154,7 +154,7 @@ static int32_t taosCompressHttpRport(char* pSrc, int32_t srcLen) { void* pDest = taosMemoryMalloc(destLen); if (pDest == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _OVER; } @@ -236,7 +236,7 @@ static FORCE_INLINE int32_t taosBuildDstAddr(const char* server, uint16_t port, static void* httpThread(void* arg) { SHttpModule* http = (SHttpModule*)arg; setThreadName("http-cli-send-thread"); - (void)uv_run(http->loop, UV_RUN_DEFAULT); + TAOS_UNUSED(uv_run(http->loop, UV_RUN_DEFAULT)); return NULL; } @@ -258,7 +258,7 @@ static int32_t httpCreateMsg(const char* server, const char* uri, uint16_t port, SHttpMsg* msg = taosMemoryMalloc(sizeof(SHttpMsg)); if (msg == NULL) { *httpMsg = NULL; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } msg->seq = seqNum; @@ -273,7 +273,7 @@ static int32_t httpCreateMsg(const char* server, const char* uri, uint16_t port, if (msg->server == NULL || msg->uri == NULL || msg->cont == NULL) { httpDestroyMsg(msg); *httpMsg = NULL; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } memcpy(msg->cont, pCont, contLen); @@ -352,7 +352,7 @@ static void httpAsyncCb(uv_async_t* handle) { static int32_t BATCH_SIZE = 20; int32_t count = 0; - (void)taosThreadMutexLock(&item->mtx); + TAOS_UNUSED(taosThreadMutexLock(&item->mtx)); httpMayDiscardMsg(http, item); while (!QUEUE_IS_EMPTY(&item->qmsg) && count++ < BATCH_SIZE) { @@ -360,7 +360,7 @@ static void httpAsyncCb(uv_async_t* handle) { QUEUE_REMOVE(h); QUEUE_PUSH(&wq, h); } - (void)taosThreadMutexUnlock(&item->mtx); + TAOS_UNUSED(taosThreadMutexUnlock(&item->mtx)); httpTrace(&wq); @@ -393,7 +393,7 @@ static FORCE_INLINE void clientCloseCb(uv_handle_t* handle) { SHttpModule* http = taosAcquireRef(httpRefMgt, cli->chanId); if (http != NULL) { http->connNum -= 1; - (void)taosReleaseRef(httpRefMgt, chanId); + TAOS_UNUSED(taosReleaseRef(httpRefMgt, chanId)); } destroyHttpClient(cli); @@ -453,7 +453,7 @@ static void clientConnCb(uv_connect_t* req, int32_t status) { if (!uv_is_closing((uv_handle_t*)&cli->tcp)) { uv_close((uv_handle_t*)&cli->tcp, clientCloseCb); } - (void)taosReleaseRef(httpRefMgt, chanId); + TAOS_UNUSED(taosReleaseRef(httpRefMgt, chanId)); return; } http->connNum += 1; @@ -468,7 +468,7 @@ static void clientConnCb(uv_connect_t* req, int32_t status) { uv_close((uv_handle_t*)&cli->tcp, clientCloseCb); } } - (void)taosReleaseRef(httpRefMgt, chanId); + TAOS_UNUSED(taosReleaseRef(httpRefMgt, chanId)); } int32_t httpSendQuit(SHttpModule* http, int64_t chanId) { @@ -514,7 +514,7 @@ static void httpHandleQuit(SHttpMsg* msg) { SHttpModule* http = taosAcquireRef(httpRefMgt, chanId); if (http == NULL) return; uv_walk(http->loop, httpWalkCb, NULL); - (void)taosReleaseRef(httpRefMgt, chanId); + TAOS_UNUSED(taosReleaseRef(httpRefMgt, chanId)); } static bool httpFailFastShoudIgnoreMsg(SHashObj* pTable, char* server, int16_t port) { @@ -536,15 +536,15 @@ static bool httpFailFastShoudIgnoreMsg(SHashObj* pTable, char* server, int16_t p } static void httpFailFastMayUpdate(SHashObj* pTable, char* server, int16_t port, int8_t succ) { int32_t code = 0; - char buf[256] = {0}; + char buf[256] = {0}; sprintf(buf, "%s:%d", server, port); if (succ) { - (void)taosHashRemove(pTable, buf, strlen(buf)); + TAOS_UNUSED(taosHashRemove(pTable, buf, strlen(buf))); } else { int32_t st = taosGetTimestampSec(); if ((code = taosHashPut(pTable, buf, strlen(buf), &st, sizeof(st))) != 0) { - tError("http-report failed to update conn status, dst:%s, reason:%s", buf, tstrerror(code)); + tError("http-report failed to update conn status, dst:%s, reason:%s", buf, tstrerror(code)); } } return; @@ -585,7 +585,7 @@ static void httpHandleReq(SHttpMsg* msg) { int32_t cap = 2048; header = taosMemoryCalloc(1, cap); if (header == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto END; } @@ -597,7 +597,7 @@ static void httpHandleReq(SHttpMsg* msg) { uv_buf_t* wb = taosMemoryCalloc(2, sizeof(uv_buf_t)); if (wb == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto END; } @@ -607,7 +607,7 @@ static void httpHandleReq(SHttpMsg* msg) { SHttpClient* cli = taosMemoryCalloc(1, sizeof(SHttpClient)); if (cli == NULL) { taosMemoryFree(wb); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto END; } cli->seq = msg->seq; @@ -628,7 +628,7 @@ static void httpHandleReq(SHttpMsg* msg) { tError("http-report failed to alloc read buf, dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 ",reason:%s", cli->addr, cli->port, chanId, cli->seq, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); destroyHttpClient(cli); - (void)taosReleaseRef(httpRefMgt, chanId); + TAOS_UNUSED(taosReleaseRef(httpRefMgt, chanId)); return; } @@ -637,7 +637,7 @@ static void httpHandleReq(SHttpMsg* msg) { tError("http-report failed to init socket handle, dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 ", reason:%s", cli->addr, cli->port, chanId, cli->seq, uv_strerror(err)); destroyHttpClient(cli); - (void)taosReleaseRef(httpRefMgt, chanId); + TAOS_UNUSED(taosReleaseRef(httpRefMgt, chanId)); return; } @@ -647,7 +647,7 @@ static void httpHandleReq(SHttpMsg* msg) { tError("http-report failed to open socket, dst:%s:%d, chanId:%" PRId64 ", seq:%" PRId64 ", reason:%s", cli->addr, cli->port, chanId, cli->seq, tstrerror(terrno)); destroyHttpClient(cli); - (void)taosReleaseRef(httpRefMgt, chanId); + TAOS_UNUSED(taosReleaseRef(httpRefMgt, chanId)); return; } @@ -657,7 +657,7 @@ static void httpHandleReq(SHttpMsg* msg) { cli->port, chanId, cli->seq, uv_strerror(ret)); destroyHttpClient(cli); - (void)taosReleaseRef(httpRefMgt, chanId); + TAOS_UNUSED(taosReleaseRef(httpRefMgt, chanId)); return; } @@ -668,7 +668,7 @@ static void httpHandleReq(SHttpMsg* msg) { httpFailFastMayUpdate(http->connStatusTable, cli->addr, cli->port, 0); destroyHttpClient(cli); } - (void)taosReleaseRef(httpRefMgt, chanId); + TAOS_UNUSED(taosReleaseRef(httpRefMgt, chanId)); return; END: @@ -678,7 +678,7 @@ END: } httpDestroyMsg(msg); taosMemoryFree(header); - (void)taosReleaseRef(httpRefMgt, chanId); + TAOS_UNUSED(taosReleaseRef(httpRefMgt, chanId)); } static void httpModuleDestroy(SHttpModule* http) { @@ -689,7 +689,7 @@ static void httpModuleDestroy(SHttpModule* http) { transAsyncPoolDestroy(http->asyncPool); } if (http->loop) { - (void)uv_loop_close(http->loop); + TAOS_UNUSED(uv_loop_close(http->loop)); taosMemoryFree(http->loop); } @@ -754,7 +754,7 @@ int32_t taosSendHttpReport(const char* server, const char* uri, uint16_t port, c int32_t taosSendHttpReportWithQID(const char* server, const char* uri, uint16_t port, char* pCont, int32_t contLen, EHttpCompFlag flag, const char* qid) { - (void)taosThreadOnce(&transHttpInit, transHttpEnvInit); + TAOS_UNUSED(taosThreadOnce(&transHttpInit, transHttpEnvInit)); return taosSendHttpReportImplByChan(server, uri, port, pCont, contLen, flag, httpDefaultChanId, qid); } @@ -784,13 +784,13 @@ int64_t transInitHttpChanImpl() { http->connStatusTable = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); if (http->connStatusTable == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _ERROR; } http->loop = taosMemoryMalloc(sizeof(uv_loop_t)); if (http->loop == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto _ERROR; } @@ -825,7 +825,7 @@ _ERROR: return code; } int64_t taosInitHttpChan() { - (void)taosThreadOnce(&transHttpInit, transHttpEnvInit); + TAOS_UNUSED(taosThreadOnce(&transHttpInit, transHttpEnvInit)); return transInitHttpChanImpl(); } @@ -844,14 +844,14 @@ void taosDestroyHttpChan(int64_t chanId) { ret = httpSendQuit(load, chanId); if (ret != 0) { tDebug("http-report already destroyed, chanId %" PRId64 ",reason:%s", chanId, tstrerror(ret)); - (void)taosReleaseRef(httpRefMgt, chanId); + TAOS_UNUSED(taosReleaseRef(httpRefMgt, chanId)); return; } - (void)taosThreadJoin(load->thread, NULL); + TAOS_UNUSED(taosThreadJoin(load->thread, NULL)); httpModuleDestroy(load); - (void)taosReleaseRef(httpRefMgt, chanId); - (void)taosRemoveRef(httpRefMgt, chanId); + TAOS_UNUSED(taosReleaseRef(httpRefMgt, chanId)); + TAOS_UNUSED(taosRemoveRef(httpRefMgt, chanId)); } diff --git a/source/libs/transport/src/tmsgcb.c b/source/libs/transport/src/tmsgcb.c index 619592c82c..5685ac55ae 100644 --- a/source/libs/transport/src/tmsgcb.c +++ b/source/libs/transport/src/tmsgcb.c @@ -81,6 +81,6 @@ bool tmsgUpdateDnodeInfo(int32_t* dnodeId, int64_t* clusterId, char* fqdn, uint1 void tmsgUpdateDnodeEpSet(SEpSet* epset) { for (int32_t i = 0; i < epset->numOfEps; ++i) { - (void)tmsgUpdateDnodeInfo(NULL, NULL, epset->eps[i].fqdn, &epset->eps[i].port); + bool ret = tmsgUpdateDnodeInfo(NULL, NULL, epset->eps[i].fqdn, &epset->eps[i].port); } } diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index df7b181a82..9ba1c3d677 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -40,7 +40,7 @@ void* rpcOpen(const SRpcInit* pInit) { SRpcInfo* pRpc = taosMemoryCalloc(1, sizeof(SRpcInfo)); if (pRpc == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + TAOS_CHECK_GOTO(terrno, NULL, _end); } if (pInit->label) { int len = strlen(pInit->label) > sizeof(pRpc->label) ? sizeof(pRpc->label) : strlen(pInit->label); diff --git a/source/libs/transport/src/transCli.c b/source/libs/transport/src/transCli.c index 087e82d0ec..30582594ba 100644 --- a/source/libs/transport/src/transCli.c +++ b/source/libs/transport/src/transCli.c @@ -233,11 +233,11 @@ static void destroyThrdObj(SCliThrd* pThrd); int32_t cliSendQuit(SCliThrd* thrd); static void cliWalkCb(uv_handle_t* handle, void* arg); -#define CLI_RELEASE_UV(loop) \ - do { \ - (void)uv_walk(loop, cliWalkCb, NULL); \ - (void)uv_run(loop, UV_RUN_DEFAULT); \ - (void)uv_loop_close(loop); \ +#define CLI_RELEASE_UV(loop) \ + do { \ + TAOS_UNUSED(uv_walk(loop, cliWalkCb, NULL)); \ + TAOS_UNUSED(uv_run(loop, UV_RUN_DEFAULT)); \ + TAOS_UNUSED(uv_loop_close(loop)); \ } while (0); // snprintf may cause performance problem @@ -247,7 +247,7 @@ static void cliWalkCb(uv_handle_t* handle, void* arg); int16_t len = strlen(ip); \ if (ip != NULL) memcpy(t, ip, len); \ t[len] = ':'; \ - (void)titoa(port, 10, &t[len + 1]); \ + TAOS_UNUSED(titoa(port, 10, &t[len + 1])); \ } while (0) #define CONN_PERSIST_TIME(para) ((para) <= 90000 ? 90000 : (para)) @@ -336,7 +336,7 @@ void cliResetTimer(SCliThrd* pThrd, SCliConn* conn) { if (conn->timer) { if (uv_is_active((uv_handle_t*)conn->timer)) { tDebug("%s conn %p stop timer", CONN_GET_INST_LABEL(conn), conn); - (void)uv_timer_stop(conn->timer); + TAOS_UNUSED(uv_timer_stop(conn->timer)); } if (taosArrayPush(pThrd->timerList, &conn->timer) == NULL) { tError("failed to push timer %p to list, reason:%s", conn->timer, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); @@ -375,15 +375,15 @@ bool cliConnSendSeqMsg(int64_t refId, SCliConn* conn) { taosWUnLockLatch(&exh->latch); SCliMsg* t = QUEUE_DATA(h, SCliMsg, seqq); transCtxMerge(&conn->ctx, &t->ctx->appCtx); - (void)transQueuePush(&conn->cliMsgs, t); + TAOS_UNUSED(transQueuePush(&conn->cliMsgs, t)); tDebug("pop from conn %p, refId: %" PRId64 "", conn, refId); - (void)transReleaseExHandle(transGetRefMgt(), refId); + TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), refId)); cliSend(conn); return true; } taosWUnLockLatch(&exh->latch); tDebug("empty conn %p, refId: %" PRId64 "", conn, refId); - (void)transReleaseExHandle(transGetRefMgt(), refId); + TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), refId)); return false; } @@ -496,7 +496,7 @@ void cliHandleResp(SCliConn* conn) { return addConnToPool(pThrd->pool, conn); } - (void)uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb); + TAOS_UNUSED(uv_read_start((uv_stream_t*)conn->stream, cliAllocRecvBufferCb, cliRecvCb)); } static void cliDestroyMsgInExhandle(int64_t refId) { if (refId == 0) return; @@ -510,7 +510,7 @@ static void cliDestroyMsgInExhandle(int64_t refId) { destroyCmsg(t); } taosWUnLockLatch(&exh->latch); - (void)transReleaseExHandle(transGetRefMgt(), refId); + TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), refId)); } } @@ -598,7 +598,7 @@ void cliConnTimeout(uv_timer_t* handle) { tTrace("%s conn %p conn timeout, ref:%d", CONN_GET_INST_LABEL(conn), conn, T_REF_VAL_GET(conn)); - (void)uv_timer_stop(handle); + TAOS_UNUSED(uv_timer_stop(handle)); handle->data = NULL; cliResetTimer(pThrd, conn); @@ -610,7 +610,7 @@ void cliReadTimeoutCb(uv_timer_t* handle) { // set up timeout cb SCliConn* conn = handle->data; tTrace("%s conn %p timeout, ref:%d", CONN_GET_INST_LABEL(conn), conn, T_REF_VAL_GET(conn)); - (void)uv_read_stop(conn->stream); + TAOS_UNUSED(uv_read_stop(conn->stream)); cliHandleExceptImpl(conn, TSDB_CODE_RPC_TIMEOUT); } @@ -847,7 +847,7 @@ static void addConnToPool(void* pool, SCliConn* conn) { pMsg->ctx->task = NULL; transCtxMerge(&conn->ctx, &pMsg->ctx->appCtx); - (void)transQueuePush(&conn->cliMsgs, pMsg); + TAOS_UNUSED(transQueuePush(&conn->cliMsgs, pMsg)); conn->status = ConnNormal; cliSend(conn); @@ -871,8 +871,8 @@ static void addConnToPool(void* pool, SCliConn* conn) { } static int32_t allocConnRef(SCliConn* conn, bool update) { if (update) { - (void)transReleaseExHandle(transGetRefMgt(), conn->refId); - (void)transRemoveExHandle(transGetRefMgt(), conn->refId); + TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), conn->refId)); + TAOS_UNUSED(transRemoveExHandle(transGetRefMgt(), conn->refId)); conn->refId = -1; } @@ -907,8 +907,8 @@ static int32_t allocConnRef(SCliConn* conn, bool update) { static int32_t specifyConnRef(SCliConn* conn, bool update, int64_t handle) { if (update) { - (void)transReleaseExHandle(transGetRefMgt(), conn->refId); - (void)transRemoveExHandle(transGetRefMgt(), conn->refId); + TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), conn->refId)); + TAOS_UNUSED(transRemoveExHandle(transGetRefMgt(), conn->refId)); conn->refId = -1; } SExHandle* exh = transAcquireExHandle(transGetRefMgt(), handle); @@ -924,7 +924,7 @@ static int32_t specifyConnRef(SCliConn* conn, bool update, int64_t handle) { tDebug("conn %p specified by %" PRId64 "", conn, handle); - (void)transReleaseExHandle(transGetRefMgt(), handle); + TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), handle)); return 0; } @@ -984,7 +984,7 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { // read/write stream handle conn->stream = (uv_stream_t*)taosMemoryMalloc(sizeof(uv_tcp_t)); if (conn->stream == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; TAOS_CHECK_GOTO(code, NULL, _failed); } @@ -1004,7 +1004,7 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { } tDebug("no available timer, create a timer %p", timer); - (void)uv_timer_init(pThrd->loop, timer); + TAOS_UNUSED(uv_timer_init(pThrd->loop, timer)); } timer->data = conn; @@ -1022,7 +1022,7 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) { conn->broken = false; transRefCliHandle(conn); - (void)atomic_add_fetch_32(&pThrd->connCount, 1); + TAOS_UNUSED(atomic_add_fetch_32(&pThrd->connCount, 1)); TAOS_CHECK_GOTO(allocConnRef(conn, false), NULL, _failed); @@ -1032,7 +1032,7 @@ _failed: if (conn) { taosMemoryFree(conn->stream); transReqQueueClear(&conn->wreqQueue); - (void)transDestroyBuffer(&conn->readBuf); + TAOS_UNUSED(transDestroyBuffer(&conn->readBuf)); transQueueDestroy(&conn->cliMsgs); } taosMemoryFree(conn); @@ -1059,8 +1059,8 @@ static void cliDestroyConn(SCliConn* conn, bool clear) { } conn->list = NULL; - (void)transReleaseExHandle(transGetRefMgt(), conn->refId); - (void)transRemoveExHandle(transGetRefMgt(), conn->refId); + TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), conn->refId)); + TAOS_UNUSED(transRemoveExHandle(transGetRefMgt(), conn->refId)); conn->refId = -1; if (conn->task != NULL) { @@ -1071,7 +1071,7 @@ static void cliDestroyConn(SCliConn* conn, bool clear) { if (clear) { if (!uv_is_closing((uv_handle_t*)conn->stream)) { - (void)uv_read_stop(conn->stream); + TAOS_UNUSED(uv_read_stop(conn->stream)); uv_close((uv_handle_t*)conn->stream, cliDestroy); } } @@ -1084,11 +1084,11 @@ static void cliDestroy(uv_handle_t* handle) { SCliThrd* pThrd = conn->hostThrd; cliResetTimer(pThrd, conn); - (void)atomic_sub_fetch_32(&pThrd->connCount, 1); + TAOS_UNUSED(atomic_sub_fetch_32(&pThrd->connCount, 1)); if (conn->refId > 0) { - (void)transReleaseExHandle(transGetRefMgt(), conn->refId); - (void)transRemoveExHandle(transGetRefMgt(), conn->refId); + TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), conn->refId)); + TAOS_UNUSED(transRemoveExHandle(transGetRefMgt(), conn->refId)); } taosMemoryFree(conn->dstAddr); taosMemoryFree(conn->stream); @@ -1097,7 +1097,7 @@ static void cliDestroy(uv_handle_t* handle) { tTrace("%s conn %p destroy successfully", CONN_GET_INST_LABEL(conn), conn); transReqQueueClear(&conn->wreqQueue); - (void)transDestroyBuffer(&conn->readBuf); + TAOS_UNUSED(transDestroyBuffer(&conn->readBuf)); taosMemoryFree(conn); } @@ -1106,7 +1106,7 @@ static bool cliHandleNoResp(SCliConn* conn) { if (!transQueueEmpty(&conn->cliMsgs)) { SCliMsg* pMsg = transQueueGet(&conn->cliMsgs, 0); if (REQUEST_NO_RESP(&pMsg->msg)) { - (void)transQueuePop(&conn->cliMsgs); + TAOS_UNUSED(transQueuePop(&conn->cliMsgs)); destroyCmsg(pMsg); res = true; } @@ -1153,7 +1153,7 @@ static void cliSendCb(uv_write_t* req, int status) { tTrace("%s conn %p no resp required", CONN_GET_INST_LABEL(pConn), pConn); return; } - (void)uv_read_start((uv_stream_t*)pConn->stream, cliAllocRecvBufferCb, cliRecvCb); + TAOS_UNUSED(uv_read_start((uv_stream_t*)pConn->stream, cliAllocRecvBufferCb, cliRecvCb)); } void cliSendBatch(SCliConn* pConn) { int32_t code = 0; @@ -1167,7 +1167,7 @@ void cliSendBatch(SCliConn* pConn) { uv_buf_t* wb = taosMemoryCalloc(wLen, sizeof(uv_buf_t)); if (wb == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; tError("%s conn %p failed to send batch msg since:%s", CONN_GET_INST_LABEL(pConn), pConn, tstrerror(code)); goto _exception; } @@ -1221,7 +1221,7 @@ void cliSendBatch(SCliConn* pConn) { uv_write_t* req = taosMemoryCalloc(1, sizeof(uv_write_t)); if (req == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; tError("%s conn %p failed to send batch msg since:%s", CONN_GET_INST_LABEL(pConn), pConn, tstrerror(code)); goto _exception; } @@ -1296,13 +1296,13 @@ void cliSend(SCliConn* pConn) { if (timer == NULL) { timer = taosMemoryCalloc(1, sizeof(uv_timer_t)); tDebug("no available timer, create a timer %p", timer); - (void)uv_timer_init(pThrd->loop, timer); + TAOS_UNUSED(uv_timer_init(pThrd->loop, timer)); } timer->data = pConn; pConn->timer = timer; tGTrace("%s conn %p start timer for msg:%s", CONN_GET_INST_LABEL(pConn), pConn, TMSG_INFO(pMsg->msgType)); - (void)uv_timer_start((uv_timer_t*)pConn->timer, cliReadTimeoutCb, TRANS_READ_TIMEOUT, 0); + TAOS_UNUSED(uv_timer_start((uv_timer_t*)pConn->timer, cliReadTimeoutCb, TRANS_READ_TIMEOUT, 0)); } if (pHead->comp == 0 && pMsg->info.compressed == 0 && pConn->clientIp != pConn->serverIp) { @@ -1402,8 +1402,7 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { tTrace("%s conn %p try to connect to %s", pTransInst->label, conn, pList->dst); int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT * 10); if (fd == -1) { - tError("%s conn %p failed to create socket, reason:%s", transLabel(pTransInst), conn, - tstrerror(terrno)); + tError("%s conn %p failed to create socket, reason:%s", transLabel(pTransInst), conn, tstrerror(terrno)); cliHandleFastFail(conn, -1); return; } @@ -1428,7 +1427,7 @@ static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd) { cliHandleFastFail(conn, -1); return; } - (void)uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); + TAOS_UNUSED(uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0)); return; } @@ -1541,12 +1540,12 @@ void cliConnCb(uv_connect_t* req, int status) { struct sockaddr peername, sockname; int addrlen = sizeof(peername); - (void)uv_tcp_getpeername((uv_tcp_t*)pConn->stream, &peername, &addrlen); - (void)transSockInfo2Str(&peername, pConn->dst); + TAOS_UNUSED(uv_tcp_getpeername((uv_tcp_t*)pConn->stream, &peername, &addrlen)); + TAOS_UNUSED(transSockInfo2Str(&peername, pConn->dst)); addrlen = sizeof(sockname); - (void)uv_tcp_getsockname((uv_tcp_t*)pConn->stream, &sockname, &addrlen); - (void)transSockInfo2Str(&sockname, pConn->src); + TAOS_UNUSED(uv_tcp_getsockname((uv_tcp_t*)pConn->stream, &sockname, &addrlen)); + TAOS_UNUSED(transSockInfo2Str(&sockname, pConn->src)); struct sockaddr_in addr = *(struct sockaddr_in*)&sockname; struct sockaddr_in saddr = *(struct sockaddr_in*)&peername; @@ -1596,8 +1595,8 @@ static void cliHandleQuit(SCliMsg* pMsg, SCliThrd* pThrd) { tDebug("cli work thread %p start to quit", pThrd); destroyCmsg(pMsg); - (void)destroyConnPool(pThrd); - (void)uv_walk(pThrd->loop, cliWalkCb, NULL); + TAOS_UNUSED(destroyConnPool(pThrd)); + TAOS_UNUSED(uv_walk(pThrd->loop, cliWalkCb, NULL)); } static void cliHandleRelease(SCliMsg* pMsg, SCliThrd* pThrd) { int64_t refId = (int64_t)(pMsg->msg.info.handle); @@ -1611,8 +1610,7 @@ static void cliHandleRelease(SCliMsg* pMsg, SCliThrd* pThrd) { taosRLockLatch(&exh->latch); SCliConn* conn = exh->handle; taosRUnLockLatch(&exh->latch); - - (void)transReleaseExHandle(transGetRefMgt(), refId); + TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), refId)); tDebug("%s conn %p start to release to inst", CONN_GET_INST_LABEL(conn), conn); if (T_REF_VAL_GET(conn) == 2) { @@ -1636,7 +1634,7 @@ static void cliHandleFreeById(SCliMsg* pMsg, SCliThrd* pThrd) { int64_t refId = (int64_t)(pMsg->msg.info.handle); SExHandle* exh = transAcquireExHandle(transGetRefMgt(), refId); if (exh == NULL) { - tDebug("id %" PRId64 " already released", refId); + tDebug("refId %" PRId64 " already released", refId); destroyCmsg(pMsg); return; } @@ -1648,7 +1646,7 @@ static void cliHandleFreeById(SCliMsg* pMsg, SCliThrd* pThrd) { if (conn == NULL || conn->refId != refId) { TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _exception); } - tDebug("do free conn %p by id %" PRId64 "", conn, refId); + tDebug("do free conn %p by refId %" PRId64 "", conn, refId); int32_t size = transQueueSize(&conn->cliMsgs); if (size == 0) { @@ -1656,7 +1654,7 @@ static void cliHandleFreeById(SCliMsg* pMsg, SCliThrd* pThrd) { TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _exception); } else { destroyCmsg(pMsg); - (void)transReleaseExHandle(transGetRefMgt(), refId); + TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), refId)); while (T_REF_VAL_GET(conn) >= 1) { transUnrefCliHandle(conn); @@ -1666,9 +1664,9 @@ static void cliHandleFreeById(SCliMsg* pMsg, SCliThrd* pThrd) { _exception: tDebug("already free conn %p by id %" PRId64 "", conn, refId); - (void)transReleaseExHandle(transGetRefMgt(), refId); - (void)transReleaseExHandle(transGetRefMgt(), refId); - (void)transRemoveExHandle(transGetRefMgt(), refId); + TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), refId)); + TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), refId)); + TAOS_UNUSED(transRemoveExHandle(transGetRefMgt(), refId)); destroyCmsg(pMsg); } @@ -1691,7 +1689,7 @@ SCliConn* cliGetConn(SCliMsg** pMsg, SCliThrd* pThrd, bool* ignore, char* addr) conn = getConnFromPool2(pThrd, addr, pMsg); if (conn != NULL) specifyConnRef(conn, true, refId); } - (void)transReleaseExHandle(transGetRefMgt(), refId); + TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), refId)); } return conn; }; @@ -1787,7 +1785,7 @@ static void cliMayUpdateFqdnCache(SHashObj* cache, char* dst) { if (i > 0) { char fqdn[TSDB_FQDN_LEN + 1] = {0}; memcpy(fqdn, dst, i); - (void)cliUpdateFqdnCache(cache, fqdn); + TAOS_UNUSED(cliUpdateFqdnCache(cache, fqdn)); } } @@ -1824,7 +1822,7 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { if (ignore == true) { // persist conn already release by server STransMsg resp = {0}; - (void)cliBuildExceptResp(pMsg, &resp); + TAOS_UNUSED(cliBuildExceptResp(pMsg, &resp)); // refactorr later resp.info.cliVer = pTransInst->compatibilityVer; @@ -1841,14 +1839,14 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { if (conn != NULL) { transCtxMerge(&conn->ctx, &pMsg->ctx->appCtx); - (void)transQueuePush(&conn->cliMsgs, pMsg); + TAOS_UNUSED(transQueuePush(&conn->cliMsgs, pMsg)); cliSend(conn); } else { code = cliCreateConn(pThrd, &conn); if (code != 0) { tError("%s failed to create conn, reason:%s", pTransInst->label, tstrerror(code)); STransMsg resp = {.code = code}; - (void)cliBuildExceptResp(pMsg, &resp); + TAOS_UNUSED(cliBuildExceptResp(pMsg, &resp)); resp.info.cliVer = pTransInst->compatibilityVer; if (pMsg->type != Release) { @@ -1862,7 +1860,7 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { if (refId != 0) specifyConnRef(conn, true, refId); transCtxMerge(&conn->ctx, &pMsg->ctx->appCtx); - (void)transQueuePush(&conn->cliMsgs, pMsg); + TAOS_UNUSED(transQueuePush(&conn->cliMsgs, pMsg)); conn->dstAddr = taosStrdup(addr); @@ -1882,8 +1880,7 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { tGTrace("%s conn %p try to connect to %s", pTransInst->label, conn, conn->dstAddr); int32_t fd = taosCreateSocketWithTimeout(TRANS_CONN_TIMEOUT * 10); if (fd == -1) { - tGError("%s conn %p failed to create socket, reason:%s", transLabel(pTransInst), conn, - tstrerror(terrno)); + tGError("%s conn %p failed to create socket, reason:%s", transLabel(pTransInst), conn, tstrerror(terrno)); cliHandleExcept(conn, -1); terrno = 0; return; @@ -1911,7 +1908,7 @@ void cliHandleReq(SCliMsg* pMsg, SCliThrd* pThrd) { cliHandleFastFail(conn, ret); return; } - (void)uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0); + TAOS_UNUSED(uv_timer_start(conn->timer, cliConnTimeout, TRANS_CONN_TIMEOUT, 0)); } tGTrace("%s conn %p ready", pTransInst->label, conn); } @@ -1971,7 +1968,7 @@ static int32_t createBatchList(SCliBatchList** ppBatchList, char* key, char* ip, taosMemoryFree(pBatchList->dst); taosMemoryFree(pBatchList); tError("failed to create batch list, reason:%s", tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } *ppBatchList = pBatchList; return 0; @@ -2110,9 +2107,9 @@ static void cliAsyncCb(uv_async_t* handle) { // batch process to avoid to lock/unlock frequently queue wq; - (void)taosThreadMutexLock(&item->mtx); + TAOS_UNUSED(taosThreadMutexLock(&item->mtx)); QUEUE_MOVE(&item->qmsg, &wq); - (void)taosThreadMutexUnlock(&item->mtx); + TAOS_UNUSED(taosThreadMutexUnlock(&item->mtx)); int8_t supportBatch = pTransInst->supportBatch; if (supportBatch == 0) { @@ -2162,7 +2159,7 @@ bool cliRecvReleaseReq(SCliConn* conn, STransMsgHead* pHead) { tDebug("%s conn %p receive release request, refId:%" PRId64 ", may ignore", CONN_GET_INST_LABEL(conn), conn, conn->refId); - (void)transClearBuffer(&conn->readBuf); + TAOS_UNUSED(transClearBuffer(&conn->readBuf)); transFreeMsg(transContFromHead((char*)pHead)); for (int i = 0; ahandle == 0 && i < transQueueSize(&conn->cliMsgs); i++) { @@ -2192,10 +2189,10 @@ static void* cliWorkThread(void* arg) { SCliThrd* pThrd = (SCliThrd*)arg; pThrd->pid = taosGetSelfPthreadId(); - (void)strtolower(threadName, pThrd->pTransInst->label); + TAOS_UNUSED(strtolower(threadName, pThrd->pTransInst->label)); setThreadName(threadName); - (void)uv_run(pThrd->loop, UV_RUN_DEFAULT); + TAOS_UNUSED(uv_run(pThrd->loop, UV_RUN_DEFAULT)); tDebug("thread quit-thread:%08" PRId64, pThrd->pid); return NULL; @@ -2205,7 +2202,7 @@ void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, int32_t code = 0; SCliObj* cli = taosMemoryCalloc(1, sizeof(SCliObj)); if (cli == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _err); + TAOS_CHECK_GOTO(terrno, NULL, _err); } STrans* pTransInst = shandle; @@ -2214,7 +2211,7 @@ void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads, cli->pThreadObj = (SCliThrd**)taosMemoryCalloc(cli->numOfThreads, sizeof(SCliThrd*)); if (cli->pThreadObj == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _err); + TAOS_CHECK_GOTO(terrno, NULL, _err); } for (int i = 0; i < cli->numOfThreads; i++) { @@ -2239,7 +2236,7 @@ _err: if (cli) { for (int i = 0; i < cli->numOfThreads; i++) { if (cli->pThreadObj[i]) { - (void)cliSendQuit(cli->pThreadObj[i]); + TAOS_UNUSED(cliSendQuit(cli->pThreadObj[i])); destroyThrdObj(cli->pThreadObj[i]); } } @@ -2283,8 +2280,8 @@ static FORCE_INLINE void destroyCmsgAndAhandle(void* param) { } if (pMsg->msg.info.handle != 0) { - (void)transReleaseExHandle(transGetRefMgt(), (int64_t)pMsg->msg.info.handle); - (void)transRemoveExHandle(transGetRefMgt(), (int64_t)pMsg->msg.info.handle); + TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), (int64_t)pMsg->msg.info.handle)); + TAOS_UNUSED(transRemoveExHandle(transGetRefMgt(), (int64_t)pMsg->msg.info.handle)); } transDestroyConnCtx(pMsg->ctx); @@ -2302,7 +2299,7 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { } QUEUE_INIT(&pThrd->msg); - (void)taosThreadMutexInit(&pThrd->msgMtx, NULL); + TAOS_UNUSED(taosThreadMutexInit(&pThrd->msgMtx, NULL)); pThrd->loop = (uv_loop_t*)taosMemoryMalloc(sizeof(uv_loop_t)); if (pThrd->loop == NULL) { @@ -2324,8 +2321,8 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { pThrd->pool = createConnPool(4); if (pThrd->pool == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + code = terrno; + TAOS_CHECK_GOTO(terrno, NULL, _end); } if ((code = transDQCreate(pThrd->loop, &pThrd->delayQueue)) != 0) { TAOS_CHECK_GOTO(code, NULL, _end); @@ -2342,33 +2339,33 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { pThrd->destroyAhandleFp = pTransInst->destroyFp; pThrd->fqdn2ipCache = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (pThrd->fqdn2ipCache == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + TAOS_CHECK_GOTO(terrno, NULL, _end); } pThrd->failFastCache = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (pThrd->failFastCache == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + TAOS_CHECK_GOTO(terrno, NULL, _end); } pThrd->batchCache = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); if (pThrd->batchCache == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + TAOS_CHECK_GOTO(terrno, NULL, _end); } int32_t timerSize = 64; pThrd->timerList = taosArrayInit(timerSize, sizeof(void*)); if (pThrd->timerList == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + code = terrno; + TAOS_CHECK_GOTO(terrno, NULL, _end); } for (int i = 0; i < timerSize; i++) { uv_timer_t* timer = taosMemoryCalloc(1, sizeof(uv_timer_t)); if (timer == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + TAOS_CHECK_GOTO(terrno, NULL, _end); } - (void)uv_timer_init(pThrd->loop, timer); + TAOS_UNUSED(uv_timer_init(pThrd->loop, timer)); if (taosArrayPush(pThrd->timerList, &timer) == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + TAOS_CHECK_GOTO(terrno, NULL, _end); } } pThrd->nextTimeout = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime); @@ -2380,19 +2377,19 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) { _end: if (pThrd) { - (void)taosThreadMutexDestroy(&pThrd->msgMtx); + TAOS_UNUSED(taosThreadMutexDestroy(&pThrd->msgMtx)); - (void)uv_loop_close(pThrd->loop); + TAOS_UNUSED(uv_loop_close(pThrd->loop)); taosMemoryFree(pThrd->loop); transAsyncPoolDestroy(pThrd->asyncPool); for (int i = 0; i < taosArrayGetSize(pThrd->timerList); i++) { uv_timer_t* timer = taosArrayGetP(pThrd->timerList, i); - (void)uv_timer_stop(timer); + TAOS_UNUSED(uv_timer_stop(timer)); taosMemoryFree(timer); } taosArrayDestroy(pThrd->timerList); - (void)destroyConnPool(pThrd); + TAOS_UNUSED(destroyConnPool(pThrd)); transDQDestroy(pThrd->delayQueue, NULL); transDQDestroy(pThrd->timeoutQueue, NULL); transDQDestroy(pThrd->waitConnQueue, NULL); @@ -2409,9 +2406,9 @@ static void destroyThrdObj(SCliThrd* pThrd) { return; } - (void)taosThreadJoin(pThrd->thread, NULL); + TAOS_UNUSED(taosThreadJoin(pThrd->thread, NULL)); CLI_RELEASE_UV(pThrd->loop); - (void)taosThreadMutexDestroy(&pThrd->msgMtx); + TAOS_UNUSED(taosThreadMutexDestroy(&pThrd->msgMtx)); TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SCliMsg, destroyCmsgWrapper, (void*)pThrd); transAsyncPoolDestroy(pThrd->asyncPool); @@ -2478,9 +2475,9 @@ void cliWalkCb(uv_handle_t* handle, void* arg) { if (uv_handle_get_type(handle) == UV_TIMER) { // do nothing } else { - (void)uv_read_stop((uv_stream_t*)handle); + TAOS_UNUSED(uv_read_stop((uv_stream_t*)handle)); } - (void)uv_close(handle, cliDestroy); + TAOS_UNUSED(uv_close(handle, cliDestroy)); } } @@ -2518,7 +2515,7 @@ static void cliSchedMsgToDebug(SCliMsg* pMsg, char* label) { STransConnCtx* pCtx = pMsg->ctx; STraceId* trace = &pMsg->msg.info.traceId; char tbuf[512] = {0}; - (void)epsetToStr(&pCtx->epSet, tbuf, tListLen(tbuf)); + TAOS_UNUSED(epsetToStr(&pCtx->epSet, tbuf, tListLen(tbuf))); tGDebug("%s retry on next node,use:%s, step: %d,timeout:%" PRId64 "", label, tbuf, pCtx->retryStep, pCtx->retryNextInterval); return; @@ -2533,7 +2530,7 @@ static void cliSchedMsgToNextNode(SCliMsg* pMsg, SCliThrd* pThrd) { arg->param1 = pMsg; arg->param2 = pThrd; - (void)transDQSched(pThrd->delayQueue, doDelayTask, arg, pCtx->retryNextInterval); + TAOS_UNUSED(transDQSched(pThrd->delayQueue, doDelayTask, arg, pCtx->retryNextInterval)); } FORCE_INLINE bool cliTryExtractEpSet(STransMsg* pResp, SEpSet* dst) { @@ -2751,7 +2748,7 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { if (hasEpSet) { if (rpcDebugFlag & DEBUG_TRACE) { char tbuf[512] = {0}; - (void)epsetToStr(&pCtx->epSet, tbuf, tListLen(tbuf)); + TAOS_UNUSED(epsetToStr(&pCtx->epSet, tbuf, tListLen(tbuf))); tGTrace("%s conn %p extract epset from msg", CONN_GET_INST_LABEL(pConn), pConn); } } @@ -2763,7 +2760,7 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { } else { memcpy((char*)pCtx->pRsp, (char*)pResp, sizeof(*pResp)); } - (void)tsem_post(pCtx->pSem); + TAOS_UNUSED(tsem_post(pCtx->pSem)); pCtx->pRsp = NULL; } else { STransSyncMsg* pSyncMsg = taosAcquireRef(transGetSyncMsgMgt(), pCtx->syncMsgRef); @@ -2773,8 +2770,8 @@ int cliAppCb(SCliConn* pConn, STransMsg* pResp, SCliMsg* pMsg) { pSyncMsg->hasEpSet = 1; epsetAssign(&pSyncMsg->epSet, &pCtx->epSet); } - (void)tsem2_post(pSyncMsg->pSem); - (void)taosReleaseRef(transGetSyncMsgMgt(), pCtx->syncMsgRef); + TAOS_UNUSED(tsem2_post(pSyncMsg->pSem)); + TAOS_UNUSED(taosReleaseRef(transGetSyncMsgMgt(), pCtx->syncMsgRef)); } else { rpcFreeCont(pResp->pCont); } @@ -2843,7 +2840,7 @@ static FORCE_INLINE SCliThrd* transGetWorkThrdFromHandle(STrans* trans, int64_t pThrd = exh->pThrd; taosWUnLockLatch(&exh->latch); - (void)transReleaseExHandle(transGetRefMgt(), handle); + TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), handle)); return pThrd; } @@ -2949,7 +2946,7 @@ int32_t transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, S code = transInitMsg(shandle, pEpSet, pReq, ctx, &pCliMsg); if (code != 0) { taosWUnLockLatch(&exh->latch); - (void)transReleaseExHandle(transGetRefMgt(), handle); + TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), handle)); TAOS_CHECK_GOTO(code, NULL, _exception); } @@ -2957,13 +2954,13 @@ int32_t transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, S taosWUnLockLatch(&exh->latch); tDebug("msg refId: %" PRId64 "", handle); - (void)transReleaseExHandle(transGetRefMgt(), handle); - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), handle)); + TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); return 0; } else { exh->inited = 1; taosWUnLockLatch(&exh->latch); - (void)transReleaseExHandle(transGetRefMgt(), handle); + TAOS_UNUSED(transReleaseExHandle(transGetRefMgt(), handle)); } } } @@ -2976,16 +2973,16 @@ int32_t transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, S EPSET_GET_INUSE_IP(pEpSet), EPSET_GET_INUSE_PORT(pEpSet), pReq->info.ahandle); if ((code = transAsyncSend(pThrd->asyncPool, &(pCliMsg->q))) != 0) { destroyCmsg(pCliMsg); - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); return (code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code); } - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); return 0; _exception: transFreeMsg(pReq->pCont); pReq->pCont = NULL; - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); return code; } int32_t transSendRequestWithId(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, int64_t* transpointId) { @@ -3021,16 +3018,16 @@ int32_t transSendRequestWithId(void* shandle, const SEpSet* pEpSet, STransMsg* p EPSET_GET_INUSE_IP(pEpSet), EPSET_GET_INUSE_PORT(pEpSet), pReq->info.ahandle); if ((code = transAsyncSend(pThrd->asyncPool, &(pCliMsg->q))) != 0) { destroyCmsg(pCliMsg); - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); return (code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code); } - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); return 0; _exception: transFreeMsg(pReq->pCont); pReq->pCont = NULL; - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); return code; } @@ -3068,7 +3065,7 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx)); if (pCtx == NULL) { - (void)tsem_destroy(sem); + TAOS_UNUSED(tsem_destroy(sem)); taosMemoryFree(sem); TAOS_CHECK_GOTO(terrno, NULL, _RETURN1); } @@ -3082,7 +3079,7 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg)); if (cliMsg == NULL) { - (void)tsem_destroy(sem); + TAOS_UNUSED(tsem_destroy(sem)); taosMemoryFree(sem); taosMemoryFree(pCtx); TAOS_CHECK_GOTO(terrno, NULL, _RETURN1); @@ -3103,18 +3100,18 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra destroyCmsg(cliMsg); TAOS_CHECK_GOTO((code == TSDB_CODE_RPC_ASYNC_MODULE_QUIT ? TSDB_CODE_RPC_MODULE_QUIT : code), NULL, _RETURN); } - (void)tsem_wait(sem); + TAOS_UNUSED(tsem_wait(sem)); memcpy(pRsp, pTransRsp, sizeof(STransMsg)); _RETURN: tsem_destroy(sem); taosMemoryFree(sem); - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); taosMemoryFree(pTransRsp); return code; _RETURN1: - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); taosMemoryFree(pTransRsp); taosMemoryFree(pReq->pCont); pReq->pCont = NULL; @@ -3151,7 +3148,7 @@ int32_t transCreateSyncMsg(STransMsg* pTransMsg, int64_t* refId) { return 0; _EXIT: - (void)tsem2_destroy(sem); + TAOS_UNUSED(tsem2_destroy(sem)); taosMemoryFree(sem); taosMemoryFree(pSyncMsg); return code; @@ -3235,15 +3232,15 @@ int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq, } } _RETURN: - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); - (void)taosReleaseRef(transGetSyncMsgMgt(), ref); - (void)taosRemoveRef(transGetSyncMsgMgt(), ref); + TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); + TAOS_UNUSED(taosReleaseRef(transGetSyncMsgMgt(), ref)); + TAOS_UNUSED(taosRemoveRef(transGetSyncMsgMgt(), ref)); return code; _RETURN2: transFreeMsg(pReq->pCont); pReq->pCont = NULL; taosMemoryFree(pTransMsg); - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); return code; } /* @@ -3295,7 +3292,7 @@ int32_t transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) { } } - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)shandle)); return code; } @@ -3319,13 +3316,14 @@ int32_t transAllocHandle(int64_t* refId) { QUEUE_INIT(&exh->q); taosInitRWLatch(&exh->latch); - tDebug("pre alloc refId %" PRId64 "", exh->refId); + tDebug("pre alloc refId %" PRId64 ", alloc exhandle %p", exh->refId, exh); *refId = exh->refId; return 0; } int32_t transFreeConnById(void* shandle, int64_t transpointId) { - int32_t code = 0; - STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle); + int32_t code = 0; + SCliMsg* pCli = NULL; + STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)shandle); if (pTransInst == NULL) { return TSDB_CODE_RPC_MODULE_QUIT; } @@ -3339,7 +3337,7 @@ int32_t transFreeConnById(void* shandle, int64_t transpointId) { TAOS_CHECK_GOTO(TSDB_CODE_REF_INVALID_ID, NULL, _exception); } - SCliMsg* pCli = taosMemoryCalloc(1, sizeof(SCliMsg)); + pCli = taosMemoryCalloc(1, sizeof(SCliMsg)); if (pCli == NULL) { TAOS_CHECK_GOTO(terrno, NULL, _exception); } @@ -3352,11 +3350,19 @@ int32_t transFreeConnById(void* shandle, int64_t transpointId) { code = transAsyncSend(pThrd->asyncPool, &pCli->q); if (code != 0) { - taosMemoryFree(pCli); + taosMemoryFreeClear(pCli); TAOS_CHECK_GOTO(code, NULL, _exception); } _exception: transReleaseExHandle(transGetInstMgt(), (int64_t)shandle); + if (code != 0) { + if (transpointId != 0) { + (void)transReleaseExHandle(transGetRefMgt(), transpointId); + (void)transRemoveExHandle(transGetRefMgt(), transpointId); + } + taosMemoryFree(pCli); + } + return code; } diff --git a/source/libs/transport/src/transComm.c b/source/libs/transport/src/transComm.c index 05244dbce2..e1371fbffa 100644 --- a/source/libs/transport/src/transComm.c +++ b/source/libs/transport/src/transComm.c @@ -128,7 +128,7 @@ int32_t transClearBuffer(SConnBuffer* buf) { p->cap = BUFFER_CAP; p->buf = taosMemoryRealloc(p->buf, BUFFER_CAP); if (p->buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } p->left = -1; @@ -179,7 +179,7 @@ int32_t transResetBuffer(SConnBuffer* connBuf, int8_t resetBuf) { p->cap = BUFFER_CAP; p->buf = taosMemoryRealloc(p->buf, p->cap); if (p->buf == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } } @@ -209,7 +209,7 @@ int32_t transAllocBuffer(SConnBuffer* connBuf, uv_buf_t* uvBuf) { if (p->buf == NULL) { uvBuf->base = NULL; uvBuf->len = 0; - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } uvBuf->base = p->buf + p->len; uvBuf->len = p->left; @@ -272,7 +272,7 @@ int32_t transAsyncPoolCreate(uv_loop_t* loop, int sz, void* arg, AsyncCB cb, SAs } item->pThrd = arg; QUEUE_INIT(&item->qmsg); - (void)taosThreadMutexInit(&item->mtx, NULL); + TAOS_UNUSED(taosThreadMutexInit(&item->mtx, NULL)); async->data = item; err = uv_async_init(loop, async, cb); @@ -301,7 +301,7 @@ void transAsyncPoolDestroy(SAsyncPool* pool) { SAsyncItem* item = async->data; if (item == NULL) continue; - (void)taosThreadMutexDestroy(&item->mtx); + TAOS_UNUSED(taosThreadMutexDestroy(&item->mtx)); taosMemoryFree(item); } taosMemoryFree(pool->asyncs); @@ -328,9 +328,9 @@ int transAsyncSend(SAsyncPool* pool, queue* q) { uv_async_t* async = &(pool->asyncs[idx]); SAsyncItem* item = async->data; - (void)taosThreadMutexLock(&item->mtx); + TAOS_UNUSED(taosThreadMutexLock(&item->mtx)); QUEUE_PUSH(&item->qmsg, q); - (void)taosThreadMutexUnlock(&item->mtx); + TAOS_UNUSED(taosThreadMutexUnlock(&item->mtx)); int ret = uv_async_send(async); if (ret != 0) { tError("failed to send async,reason:%s", uv_err_name(ret)); @@ -393,7 +393,7 @@ void* transCtxDumpVal(STransCtx* ctx, int32_t key) { return NULL; } void* ret = NULL; - (void)(*cVal->clone)(cVal->val, &ret); + TAOS_UNUSED((*cVal->clone)(cVal->val, &ret)); return ret; } void* transCtxDumpBrokenlinkVal(STransCtx* ctx, int32_t* msgType) { @@ -401,7 +401,7 @@ void* transCtxDumpBrokenlinkVal(STransCtx* ctx, int32_t* msgType) { if (ctx->brokenVal.clone == NULL) { return ret; } - (void)(*ctx->brokenVal.clone)(ctx->brokenVal.val, &ret); + TAOS_UNUSED((*ctx->brokenVal.clone)(ctx->brokenVal.val, &ret)); *msgType = ctx->brokenVal.msgType; @@ -443,7 +443,7 @@ void transReqQueueClear(queue* q) { int32_t transQueueInit(STransQueue* queue, void (*freeFunc)(const void* arg)) { queue->q = taosArrayInit(2, sizeof(void*)); if (queue->q == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } queue->freeFunc = (void (*)(const void*))freeFunc; @@ -549,7 +549,7 @@ static void transDQTimeout(uv_timer_t* timer) { } } while (1); if (timeout != 0) { - (void)uv_timer_start(queue->timer, transDQTimeout, timeout, 0); + TAOS_UNUSED(uv_timer_start(queue->timer, transDQTimeout, timeout, 0)); } } int32_t transDQCreate(uv_loop_t* loop, SDelayQueue** queue) { @@ -565,12 +565,12 @@ int32_t transDQCreate(uv_loop_t* loop, SDelayQueue** queue) { heap = heapCreate(timeCompare); if (heap == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _return1); + TAOS_CHECK_GOTO(terrno, NULL, _return1); } q = taosMemoryCalloc(1, sizeof(SDelayQueue)); if (q == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _return1); + TAOS_CHECK_GOTO(terrno, NULL, _return1); } q->heap = heap; q->timer = timer; @@ -614,7 +614,7 @@ void transDQDestroy(SDelayQueue* queue, void (*freeFunc)(void* arg)) { taosMemoryFree(queue); } void transDQCancel(SDelayQueue* queue, SDelayTask* task) { - (void)uv_timer_stop(queue->timer); + TAOS_UNUSED(uv_timer_stop(queue->timer)); if (heapSize(queue->heap) <= 0) { taosMemoryFree(task->arg); @@ -634,7 +634,7 @@ void transDQCancel(SDelayQueue* queue, SDelayTask* task) { SDelayTask* task = container_of(minNode, SDelayTask, node); uint64_t timeout = now > task->execTime ? now - task->execTime : 0; - (void)uv_timer_start(queue->timer, transDQTimeout, timeout, 0); + TAOS_UNUSED(uv_timer_start(queue->timer, transDQTimeout, timeout, 0)); } } @@ -659,7 +659,7 @@ SDelayTask* transDQSched(SDelayQueue* queue, void (*func)(void* arg), void* arg, tTrace("timer %p put task into delay queue, timeoutMs:%" PRIu64, queue->timer, timeoutMs); heapInsert(queue->heap, &task->node); - (void)uv_timer_start(queue->timer, transDQTimeout, timeoutMs, 0); + TAOS_UNUSED(uv_timer_start(queue->timer, transDQTimeout, timeoutMs, 0)); return task; } @@ -708,7 +708,7 @@ static void transInitEnv() { svrRefMgt = transOpenRefMgt(50000, transDestroyExHandle); instMgt = taosOpenRef(50, rpcCloseImpl); transSyncMsgMgt = taosOpenRef(50, transDestroySyncMsg); - (void)uv_os_setenv("UV_TCP_SINGLE_ACCEPT", "1"); + TAOS_UNUSED(uv_os_setenv("UV_TCP_SINGLE_ACCEPT", "1")); } static void transDestroyEnv() { transCloseRefMgt(refMgt); @@ -768,6 +768,7 @@ void transDestroyExHandle(void* handle) { if (!QUEUE_IS_EMPTY(&eh->q)) { tDebug("handle %p mem leak", handle); } + tDebug("free exhandle %p", handle); taosMemoryFree(handle); } @@ -775,7 +776,7 @@ void transDestroySyncMsg(void* msg) { if (msg == NULL) return; STransSyncMsg* pSyncMsg = msg; - (void)tsem2_destroy(pSyncMsg->pSem); + TAOS_UNUSED(tsem2_destroy(pSyncMsg->pSem)); taosMemoryFree(pSyncMsg->pSem); transFreeMsg(pSyncMsg->pRsp->pCont); taosMemoryFree(pSyncMsg->pRsp); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index 4c70ff5212..f8f8878f86 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -188,11 +188,11 @@ static void sendQuitToWorkThrd(SWorkThrd* pThrd); static int32_t addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName); static int32_t addHandleToAcceptloop(void* arg); -#define SRV_RELEASE_UV(loop) \ - do { \ - (void)uv_walk(loop, uvWalkCb, NULL); \ - (void)uv_run(loop, UV_RUN_DEFAULT); \ - (void)uv_loop_close(loop); \ +#define SRV_RELEASE_UV(loop) \ + do { \ + TAOS_UNUSED(uv_walk(loop, uvWalkCb, NULL)); \ + TAOS_UNUSED(uv_run(loop, UV_RUN_DEFAULT)); \ + TAOS_UNUSED(uv_loop_close(loop)); \ } while (0); #define ASYNC_ERR_JRET(thrd) \ @@ -594,7 +594,7 @@ void uvOnSendCb(uv_write_t* req, int status) { (pTransInst->cfp)(pTransInst->parent, &(conn->regArg.msg), NULL); memset(&conn->regArg, 0, sizeof(conn->regArg)); } - (void)transQueuePop(&conn->srvMsgs); + TAOS_UNUSED(transQueuePop(&conn->srvMsgs)); taosMemoryFree(msg); msg = (SSvrMsg*)transQueueGet(&conn->srvMsgs, 0); @@ -636,7 +636,7 @@ static int uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { if (pMsg->pCont == 0) { pMsg->pCont = (void*)rpcMallocCont(0); if (pMsg->pCont == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } pMsg->contLen = 0; @@ -651,7 +651,7 @@ static int uvPrepareSendData(SSvrMsg* smsg, uv_buf_t* wb) { // handle invalid drop_task resp, TD-20098 if (pConn->inType == TDMT_SCH_DROP_TASK && pMsg->code == TSDB_CODE_VND_INVALID_VGROUP_ID) { - (void)transQueuePop(&pConn->srvMsgs); + TAOS_UNUSED(transQueuePop(&pConn->srvMsgs)); destroySmsg(smsg); return TSDB_CODE_INVALID_MSG; } @@ -707,7 +707,7 @@ static FORCE_INLINE void uvStartSendRespImpl(SSvrMsg* smsg) { transRefSrvHandle(pConn); uv_write_t* req = transReqQueuePush(&pConn->wreqQueue); - (void)uv_write(req, (uv_stream_t*)pConn->pTcp, &wb, 1, uvOnSendCb); + TAOS_UNUSED(uv_write(req, (uv_stream_t*)pConn->pTcp, &wb, 1, uvOnSendCb)); } static void uvStartSendResp(SSvrMsg* smsg) { // impl @@ -759,9 +759,9 @@ void uvWorkerAsyncCb(uv_async_t* handle) { queue wq; // batch process to avoid to lock/unlock frequently - (void)taosThreadMutexLock(&item->mtx); + TAOS_UNUSED(taosThreadMutexLock(&item->mtx)); QUEUE_MOVE(&item->qmsg, &wq); - (void)taosThreadMutexUnlock(&item->mtx); + TAOS_UNUSED(taosThreadMutexUnlock(&item->mtx)); while (!QUEUE_IS_EMPTY(&wq)) { queue* head = QUEUE_HEAD(&wq); @@ -784,12 +784,12 @@ void uvWorkerAsyncCb(uv_async_t* handle) { SExHandle* exh2 = transAcquireExHandle(transGetSvrRefMgt(), refId); if (exh2 == NULL || exh1 != exh2) { tTrace("handle except msg %p, ignore it", exh1); - (void)transReleaseExHandle(transGetSvrRefMgt(), refId); + TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); destroySmsg(msg); continue; } msg->pConn = exh1->handle; - (void)transReleaseExHandle(transGetSvrRefMgt(), refId); + TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); (*transAsyncHandle[msg->type])(msg, pThrd); } } @@ -827,7 +827,7 @@ static bool uvRecvReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) { tTrace("conn %p received release request", pConn); STraceId traceId = pHead->traceId; - (void)transClearBuffer(&pConn->readBuf); + TAOS_UNUSED(transClearBuffer(&pConn->readBuf)); transFreeMsg(transContFromHead((char*)pHead)); if (pConn->status != ConnAcquire) { return true; @@ -906,7 +906,8 @@ void uvOnAcceptCb(uv_stream_t* stream, int status) { tTrace("new connection accepted by main server, dispatch to %dth worker-thread", pObj->workerIdx); - (void)uv_write2(wr, (uv_stream_t*)&(pObj->pipe[pObj->workerIdx][0]), &buf, 1, (uv_stream_t*)cli, uvOnPipeWriteCb); + TAOS_UNUSED( + uv_write2(wr, (uv_stream_t*)&(pObj->pipe[pObj->workerIdx][0]), &buf, 1, (uv_stream_t*)cli, uvOnPipeWriteCb)); } else { if (!uv_is_closing((uv_handle_t*)cli)) { tError("failed to accept tcp: %s", uv_err_name(err)); @@ -971,7 +972,7 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { if (uv_accept(q, (uv_stream_t*)(pConn->pTcp)) == 0) { uv_os_fd_t fd; - (void)uv_fileno((const uv_handle_t*)pConn->pTcp, &fd); + TAOS_UNUSED(uv_fileno((const uv_handle_t*)pConn->pTcp, &fd)); tTrace("conn %p created, fd:%d", pConn, fd); struct sockaddr peername, sockname; @@ -981,7 +982,7 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { transUnrefSrvHandle(pConn); return; } - (void)transSockInfo2Str(&peername, pConn->dst); + TAOS_UNUSED(transSockInfo2Str(&peername, pConn->dst)); addrlen = sizeof(sockname); if (0 != uv_tcp_getsockname(pConn->pTcp, (struct sockaddr*)&sockname, &addrlen)) { @@ -989,7 +990,7 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { transUnrefSrvHandle(pConn); return; } - (void)transSockInfo2Str(&sockname, pConn->src); + TAOS_UNUSED(transSockInfo2Str(&sockname, pConn->src)); struct sockaddr_in addr = *(struct sockaddr_in*)&peername; struct sockaddr_in saddr = *(struct sockaddr_in*)&sockname; @@ -998,7 +999,7 @@ void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf) { pConn->serverIp = saddr.sin_addr.s_addr; pConn->port = ntohs(addr.sin_port); - (void)uv_read_start((uv_stream_t*)(pConn->pTcp), uvAllocRecvBufferCb, uvOnRecvCb); + TAOS_UNUSED(uv_read_start((uv_stream_t*)(pConn->pTcp), uvAllocRecvBufferCb, uvOnRecvCb)); } else { tDebug("failed to create new connection"); @@ -1010,7 +1011,7 @@ void* transAcceptThread(void* arg) { // opt setThreadName("trans-accept"); SServerObj* srv = (SServerObj*)arg; - (void)uv_run(srv->loop, UV_RUN_DEFAULT); + TAOS_UNUSED(uv_run(srv->loop, UV_RUN_DEFAULT)); return NULL; } @@ -1021,13 +1022,13 @@ void uvOnPipeConnectionCb(uv_connect_t* connect, int status) { }; SWorkThrd* pThrd = container_of(connect, SWorkThrd, connect_req); - (void)uv_read_start((uv_stream_t*)pThrd->pipe, uvAllocConnBufferCb, uvOnConnectionCb); + TAOS_UNUSED(uv_read_start((uv_stream_t*)pThrd->pipe, uvAllocConnBufferCb, uvOnConnectionCb)); } static int32_t addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName) { int32_t code = 0; pThrd->loop = (uv_loop_t*)taosMemoryMalloc(sizeof(uv_loop_t)); if (pThrd->loop == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } if ((code = uv_loop_init(pThrd->loop)) != 0) { @@ -1124,7 +1125,7 @@ static int32_t addHandleToAcceptloop(void* arg) { void* transWorkerThread(void* arg) { setThreadName("trans-svr-work"); SWorkThrd* pThrd = (SWorkThrd*)arg; - (void)uv_run(pThrd->loop, UV_RUN_DEFAULT); + TAOS_UNUSED(uv_run(pThrd->loop, UV_RUN_DEFAULT)); return NULL; } @@ -1135,7 +1136,7 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { SSvrConn* pConn = (SSvrConn*)taosMemoryCalloc(1, sizeof(SSvrConn)); if (pConn == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + TAOS_CHECK_GOTO(terrno, NULL, _end); } transReqQueueInit(&pConn->wreqQueue); @@ -1156,7 +1157,7 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { SExHandle* exh = taosMemoryMalloc(sizeof(SExHandle)); if (exh == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + TAOS_CHECK_GOTO(terrno, NULL, _end); } exh->handle = pConn; @@ -1187,7 +1188,7 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { // init client handle pConn->pTcp = (uv_tcp_t*)taosMemoryMalloc(sizeof(uv_tcp_t)); if (pConn->pTcp == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end); + TAOS_CHECK_GOTO(terrno, NULL, _end); } code = uv_tcp_init(pThrd->loop, pConn->pTcp); @@ -1201,7 +1202,7 @@ static FORCE_INLINE SSvrConn* createConn(void* hThrd) { _end: if (pConn) { transQueueDestroy(&pConn->srvMsgs); - (void)transDestroyBuffer(&pConn->readBuf); + TAOS_UNUSED(transDestroyBuffer(&pConn->readBuf)); taosMemoryFree(pConn->pTcp); taosMemoryFree(pConn); pConn = NULL; @@ -1230,13 +1231,13 @@ static FORCE_INLINE void destroyConnRegArg(SSvrConn* conn) { } static int32_t reallocConnRef(SSvrConn* conn) { if (conn->refId > 0) { - (void)transReleaseExHandle(transGetSvrRefMgt(), conn->refId); - (void)transRemoveExHandle(transGetSvrRefMgt(), conn->refId); + TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), conn->refId)); + TAOS_UNUSED(transRemoveExHandle(transGetSvrRefMgt(), conn->refId)); } // avoid app continue to send msg on invalid handle SExHandle* exh = taosMemoryMalloc(sizeof(SExHandle)); if (exh == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } exh->handle = conn; @@ -1267,8 +1268,8 @@ static void uvDestroyConn(uv_handle_t* handle) { } SWorkThrd* thrd = conn->hostThrd; - (void)transReleaseExHandle(transGetSvrRefMgt(), conn->refId); - (void)transRemoveExHandle(transGetSvrRefMgt(), conn->refId); + TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), conn->refId)); + TAOS_UNUSED(transRemoveExHandle(transGetSvrRefMgt(), conn->refId)); STrans* pTransInst = thrd->pTransInst; tDebug("%s conn %p destroy", transLabel(pTransInst), conn); @@ -1283,7 +1284,7 @@ static void uvDestroyConn(uv_handle_t* handle) { QUEUE_REMOVE(&conn->queue); taosMemoryFree(conn->pTcp); destroyConnRegArg(conn); - (void)transDestroyBuffer(&conn->readBuf); + TAOS_UNUSED(transDestroyBuffer(&conn->readBuf)); taosMemoryFree(conn); if (thrd->quit && QUEUE_IS_EMPTY(&thrd->conn)) { @@ -1335,7 +1336,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, SServerObj* srv = taosMemoryCalloc(1, sizeof(SServerObj)); if (srv == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; tError("failed to init server since: %s", tstrerror(code)); return NULL; } @@ -1349,7 +1350,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, srv->pThreadObj = (SWorkThrd**)taosMemoryCalloc(srv->numOfThreads, sizeof(SWorkThrd*)); srv->pipe = (uv_pipe_t**)taosMemoryCalloc(srv->numOfThreads, sizeof(uv_pipe_t*)); if (srv->loop == NULL || srv->pThreadObj == NULL || srv->pipe == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto End; } @@ -1400,14 +1401,14 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, thrd->pWhiteList = uvWhiteListCreate(); if (thrd->pWhiteList == NULL) { destroyWorkThrdObj(thrd); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto End; } srv->pipe[i] = (uv_pipe_t*)taosMemoryCalloc(2, sizeof(uv_pipe_t)); if (srv->pipe[i] == NULL) { destroyWorkThrdObj(thrd); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto End; } @@ -1433,7 +1434,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, for (int i = 0; i < srv->numOfThreads; i++) { SWorkThrd* thrd = (SWorkThrd*)taosMemoryCalloc(1, sizeof(SWorkThrd)); if (thrd == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto End; } srv->pThreadObj[i] = thrd; @@ -1444,13 +1445,13 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads, thrd->pWhiteList = uvWhiteListCreate(); if (thrd->pWhiteList == NULL) { destroyWorkThrdObj(thrd); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto End; } srv->pipe[i] = (uv_pipe_t*)taosMemoryCalloc(2, sizeof(uv_pipe_t)); if (srv->pipe[i] == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; goto End; } @@ -1563,7 +1564,7 @@ void uvHandleRegister(SSvrMsg* msg, SWorkThrd* thrd) { if (!transQueuePush(&conn->srvMsgs, msg)) { return; } - (void)transQueuePop(&conn->srvMsgs); + TAOS_UNUSED(transQueuePop(&conn->srvMsgs)); if (conn->regArg.init) { transFreeMsg(conn->regArg.msg.pCont); @@ -1599,7 +1600,7 @@ void uvHandleUpdate(SSvrMsg* msg, SWorkThrd* thrd) { SIpWhiteList* pList = taosMemoryCalloc(1, sz + sizeof(SIpWhiteList)); if (pList == NULL) { tError("failed to create ip-white-list since %s", tstrerror(code)); - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; break; } pList->num = pUser->numOfRange; @@ -1636,7 +1637,7 @@ void destroyWorkThrd(SWorkThrd* pThrd) { } if (pThrd->inited) { sendQuitToWorkThrd(pThrd); - (void)taosThreadJoin(pThrd->thread, NULL); + TAOS_UNUSED(taosThreadJoin(pThrd->thread, NULL)); SRV_RELEASE_UV(pThrd->loop); TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SSvrMsg, destroySmsgWrapper, NULL); } @@ -1646,7 +1647,7 @@ void sendQuitToWorkThrd(SWorkThrd* pThrd) { SSvrMsg* msg = taosMemoryCalloc(1, sizeof(SSvrMsg)); msg->type = Quit; tDebug("server send quit msg to work thread"); - (void)transAsyncSend(pThrd->asyncPool, &msg->q); + TAOS_UNUSED(transAsyncSend(pThrd->asyncPool, &msg->q)); } void transCloseServer(void* arg) { @@ -1655,8 +1656,8 @@ void transCloseServer(void* arg) { if (srv->inited) { tDebug("send quit msg to accept thread"); - (void)uv_async_send(srv->pAcceptAsync); - (void)taosThreadJoin(srv->thread, NULL); + TAOS_UNUSED(uv_async_send(srv->pAcceptAsync)); + TAOS_UNUSED(taosThreadJoin(srv->thread, NULL)); SRV_RELEASE_UV(srv->loop); for (int i = 0; i < srv->numOfThreads; i++) { @@ -1724,15 +1725,15 @@ int32_t transReleaseSrvHandle(void* handle) { tDebug("%s conn %p start to release", transLabel(pThrd->pTransInst), exh->handle); if ((code = transAsyncSend(pThrd->asyncPool, &m->q)) != 0) { destroySmsg(m); - (void)transReleaseExHandle(transGetSvrRefMgt(), refId); + TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); return code; } - (void)transReleaseExHandle(transGetSvrRefMgt(), refId); + TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); return 0; _return1: tDebug("handle %p failed to send to release handle", exh); - (void)transReleaseExHandle(transGetSvrRefMgt(), refId); + TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); return code; _return2: tDebug("handle %p failed to send to release handle", exh); @@ -1775,17 +1776,17 @@ int32_t transSendResponse(const STransMsg* msg) { tGDebug("conn %p start to send resp (1/2)", exh->handle); if ((code = transAsyncSend(pThrd->asyncPool, &m->q)) != 0) { destroySmsg(m); - (void)transReleaseExHandle(transGetSvrRefMgt(), refId); + TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); return code; } - (void)transReleaseExHandle(transGetSvrRefMgt(), refId); + TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); return 0; _return1: tDebug("handle %p failed to send resp", exh); rpcFreeCont(msg->pCont); - (void)transReleaseExHandle(transGetSvrRefMgt(), refId); + TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); return code; _return2: tDebug("handle %p failed to send resp", exh); @@ -1820,17 +1821,17 @@ int32_t transRegisterMsg(const STransMsg* msg) { tDebug("%s conn %p start to register brokenlink callback", transLabel(pTransInst), exh->handle); if ((code = transAsyncSend(pThrd->asyncPool, &m->q)) != 0) { destroySmsg(m); - (void)transReleaseExHandle(transGetSvrRefMgt(), refId); + TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); return code; } - (void)transReleaseExHandle(transGetSvrRefMgt(), refId); + TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); return 0; _return1: tDebug("handle %p failed to register brokenlink", exh); rpcFreeCont(msg->pCont); - (void)transReleaseExHandle(transGetSvrRefMgt(), refId); + TAOS_UNUSED(transReleaseExHandle(transGetSvrRefMgt(), refId)); return code; _return2: tDebug("handle %p failed to register brokenlink", exh); @@ -1875,7 +1876,7 @@ int32_t transSetIpWhiteList(void* thandle, void* arg, FilteFunc* func) { break; } } - (void)transReleaseExHandle(transGetInstMgt(), (int64_t)thandle); + TAOS_UNUSED(transReleaseExHandle(transGetInstMgt(), (int64_t)thandle)); if (code != 0) { tError("ip-white-list update failed since %s", tstrerror(code)); diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 0dd55aacdb..7ea98d648d 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -57,7 +57,11 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in walBuildLogName(pWal, pFileInfo->firstVer, fnameStr); int64_t fileSize = 0; - (void)taosStatFile(fnameStr, &fileSize, NULL, NULL); + if (taosStatFile(fnameStr, &fileSize, NULL, NULL) != 0) { + wError("vgId:%d, failed to stat file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr); + code = terrno; + goto _err; + } TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ | TD_FILE_WRITE); if (pFile == NULL) { @@ -99,7 +103,7 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in ptr = taosMemoryRealloc(buf, capacity); if (ptr == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } buf = ptr; @@ -163,7 +167,7 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in capacity += extraSize; void* ptr = taosMemoryRealloc(buf, capacity); if (ptr == NULL) { - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } buf = ptr; } @@ -270,7 +274,7 @@ static int32_t walRebuildFileInfoSet(SArray* metaLogList, SArray* actualLogList) for (int i = 0; i < actualFileNum; i++) { SWalFileInfo* pFileInfo = taosArrayGet(actualLogList, i); if (NULL == taosArrayPush(metaLogList, pFileInfo)) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } } @@ -356,6 +360,7 @@ static int32_t walLogEntriesComplete(const SWal* pWal) { } static int32_t walTrimIdxFile(SWal* pWal, int32_t fileIdx) { + int32_t code = 0; SWalFileInfo* pFileInfo = taosArrayGet(pWal->fileInfoSet, fileIdx); if (!pFileInfo) { TAOS_RETURN(TSDB_CODE_FAILED); @@ -365,7 +370,11 @@ static int32_t walTrimIdxFile(SWal* pWal, int32_t fileIdx) { walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr); int64_t fileSize = 0; - (void)taosStatFile(fnameStr, &fileSize, NULL, NULL); + if (taosStatFile(fnameStr, &fileSize, NULL, NULL) != 0) { + wError("vgId:%d, failed to stat file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr); + code = terrno; + TAOS_RETURN(code); + } int64_t records = TMAX(0, pFileInfo->lastVer - pFileInfo->firstVer + 1); int64_t lastEndOffset = records * sizeof(SWalIdxEntry); @@ -381,7 +390,11 @@ static int32_t walTrimIdxFile(SWal* pWal, int32_t fileIdx) { wInfo("vgId:%d, trim idx file. file: %s, size: %" PRId64 ", offset: %" PRId64, pWal->cfg.vgId, fnameStr, fileSize, lastEndOffset); - (void)taosFtruncateFile(pFile, lastEndOffset); + code = taosFtruncateFile(pFile, lastEndOffset); + if (code < 0) { + wError("vgId:%d, failed to truncate file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr); + TAOS_RETURN(code); + } (void)taosCloseFile(&pFile); TAOS_RETURN(TSDB_CODE_SUCCESS); @@ -395,8 +408,14 @@ int32_t walCheckAndRepairMeta(SWal* pWal) { regex_t logRegPattern; regex_t idxRegPattern; - (void)regcomp(&logRegPattern, logPattern, REG_EXTENDED); - (void)regcomp(&idxRegPattern, idxPattern, REG_EXTENDED); + if (regcomp(&logRegPattern, logPattern, REG_EXTENDED) != 0) { + wError("failed to compile log pattern, error:%s", tstrerror(terrno)); + return terrno; + } + if (regcomp(&idxRegPattern, idxPattern, REG_EXTENDED) != 0) { + wError("failed to compile idx pattern"); + return terrno; + } TdDirPtr pDir = taosOpenDir(pWal->path); if (pDir == NULL) { @@ -420,14 +439,22 @@ int32_t walCheckAndRepairMeta(SWal* pWal) { if (!taosArrayPush(actualLog, &fileInfo)) { regfree(&logRegPattern); regfree(&idxRegPattern); - (void)taosCloseDir(&pDir); + int32_t ret = taosCloseDir(&pDir); + if (ret != 0) { + wError("failed to close dir, ret:%s", tstrerror(ret)); + return terrno; + } return terrno; } } } - (void)taosCloseDir(&pDir); + int32_t ret = taosCloseDir(&pDir); + if (ret != 0) { + wError("failed to close dir, ret:%s", tstrerror(ret)); + return terrno; + } regfree(&logRegPattern); regfree(&idxRegPattern); @@ -684,7 +711,9 @@ _err: int64_t walGetVerRetention(SWal* pWal, int64_t bytes) { int64_t ver = -1; int64_t totSize = 0; - (void)taosThreadRwlockRdlock(&pWal->mutex); + if (taosThreadRwlockRdlock(&pWal->mutex) != 0) { + wError("vgId:%d failed to lock %p", pWal->cfg.vgId, &pWal->mutex); + } int32_t fileIdx = taosArrayGetSize(pWal->fileInfoSet); while (--fileIdx) { SWalFileInfo* pInfo = taosArrayGet(pWal->fileInfoSet, fileIdx); @@ -694,7 +723,9 @@ int64_t walGetVerRetention(SWal* pWal, int64_t bytes) { } totSize += pInfo->fileSize; } - (void)taosThreadRwlockUnlock(&pWal->mutex); + if (taosThreadRwlockUnlock(&pWal->mutex) != 0) { + wError("vgId:%d failed to lock %p", pWal->cfg.vgId, &pWal->mutex); + } return ver + 1; } @@ -728,7 +759,7 @@ int32_t walRollFileInfo(SWal* pWal) { // TODO: change to emplace back SWalFileInfo* pNewInfo = taosMemoryMalloc(sizeof(SWalFileInfo)); if (pNewInfo == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } pNewInfo->firstVer = pWal->vers.lastVer + 1; pNewInfo->lastVer = -1; @@ -738,7 +769,7 @@ int32_t walRollFileInfo(SWal* pWal) { pNewInfo->syncedOffset = 0; if (!taosArrayPush(pArray, pNewInfo)) { taosMemoryFree(pNewInfo); - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } taosMemoryFree(pNewInfo); @@ -765,21 +796,35 @@ int32_t walMetaSerialize(SWal* pWal, char** serialized) { TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); } - (void)cJSON_AddItemToObject(pRoot, "meta", pMeta); + if (cJSON_AddItemToObject(pRoot, "meta", pMeta) != 0) { + wInfo("vgId:%d, failed to add meta to root", pWal->cfg.vgId); + } (void)sprintf(buf, "%" PRId64, pWal->vers.firstVer); - (void)cJSON_AddStringToObject(pMeta, "firstVer", buf); + if (cJSON_AddStringToObject(pMeta, "firstVer", buf) == NULL) { + wInfo("vgId:%d, failed to add firstVer to meta", pWal->cfg.vgId); + } (void)sprintf(buf, "%" PRId64, pWal->vers.snapshotVer); - (void)cJSON_AddStringToObject(pMeta, "snapshotVer", buf); + if (cJSON_AddStringToObject(pMeta, "snapshotVer", buf) == NULL) { + wInfo("vgId:%d, failed to add snapshotVer to meta", pWal->cfg.vgId); + } (void)sprintf(buf, "%" PRId64, pWal->vers.commitVer); - (void)cJSON_AddStringToObject(pMeta, "commitVer", buf); + if (cJSON_AddStringToObject(pMeta, "commitVer", buf) == NULL) { + wInfo("vgId:%d, failed to add commitVer to meta", pWal->cfg.vgId); + } (void)sprintf(buf, "%" PRId64, pWal->vers.lastVer); - (void)cJSON_AddStringToObject(pMeta, "lastVer", buf); + if (cJSON_AddStringToObject(pMeta, "lastVer", buf) == NULL) { + wInfo("vgId:%d, failed to add lastVer to meta", pWal->cfg.vgId); + } - (void)cJSON_AddItemToObject(pRoot, "files", pFiles); + if (cJSON_AddItemToObject(pRoot, "files", pFiles) != 0) { + wInfo("vgId:%d, failed to add files to root", pWal->cfg.vgId); + } SWalFileInfo* pData = pWal->fileInfoSet->pData; for (int i = 0; i < sz; i++) { SWalFileInfo* pInfo = &pData[i]; - (void)cJSON_AddItemToArray(pFiles, pField = cJSON_CreateObject()); + if (cJSON_AddItemToArray(pFiles, pField = cJSON_CreateObject()) != 0) { + wInfo("vgId:%d, failed to add field to files", pWal->cfg.vgId); + } if (pField == NULL) { cJSON_Delete(pRoot); @@ -788,15 +833,25 @@ int32_t walMetaSerialize(SWal* pWal, char** serialized) { // cjson only support int32_t or double // string are used to prohibit the loss of precision (void)sprintf(buf, "%" PRId64, pInfo->firstVer); - (void)cJSON_AddStringToObject(pField, "firstVer", buf); + if (cJSON_AddStringToObject(pField, "firstVer", buf) == NULL) { + wInfo("vgId:%d, failed to add firstVer to field", pWal->cfg.vgId); + } (void)sprintf(buf, "%" PRId64, pInfo->lastVer); - (void)cJSON_AddStringToObject(pField, "lastVer", buf); + if (cJSON_AddStringToObject(pField, "lastVer", buf) == NULL) { + wInfo("vgId:%d, failed to add lastVer to field", pWal->cfg.vgId); + } (void)sprintf(buf, "%" PRId64, pInfo->createTs); - (void)cJSON_AddStringToObject(pField, "createTs", buf); + if (cJSON_AddStringToObject(pField, "createTs", buf) == NULL) { + wInfo("vgId:%d, failed to add createTs to field", pWal->cfg.vgId); + } (void)sprintf(buf, "%" PRId64, pInfo->closeTs); - (void)cJSON_AddStringToObject(pField, "closeTs", buf); + if (cJSON_AddStringToObject(pField, "closeTs", buf) == NULL) { + wInfo("vgId:%d, failed to add closeTs to field", pWal->cfg.vgId); + } (void)sprintf(buf, "%" PRId64, pInfo->fileSize); - (void)cJSON_AddStringToObject(pField, "fileSize", buf); + if (cJSON_AddStringToObject(pField, "fileSize", buf) == NULL) { + wInfo("vgId:%d, failed to add fileSize to field", pWal->cfg.vgId); + } } char* pSerialized = cJSON_Print(pRoot); cJSON_Delete(pRoot); @@ -874,7 +929,10 @@ _err: static int walFindCurMetaVer(SWal* pWal) { const char* pattern = "^meta-ver[0-9]+$"; regex_t walMetaRegexPattern; - (void)regcomp(&walMetaRegexPattern, pattern, REG_EXTENDED); + if (regcomp(&walMetaRegexPattern, pattern, REG_EXTENDED) != 0) { + wError("failed to compile wal meta pattern, error %s", tstrerror(terrno)); + return terrno; + } TdDirPtr pDir = taosOpenDir(pWal->path); if (pDir == NULL) { @@ -896,7 +954,10 @@ static int walFindCurMetaVer(SWal* pWal) { } wDebug("vgId:%d, wal find current meta: %s is not meta file", pWal->cfg.vgId, name); } - (void)taosCloseDir(&pDir); + if (taosCloseDir(&pDir) != 0) { + wError("failed to close dir, ret:%s", tstrerror(terrno)); + return terrno; + } regfree(&walMetaRegexPattern); return metaVer; } @@ -979,21 +1040,31 @@ int32_t walSaveMeta(SWal* pWal) { // delete old file if (metaVer > -1) { - (void)walBuildMetaName(pWal, metaVer, fnameStr); - (void)taosRemoveFile(fnameStr); + n = walBuildMetaName(pWal, metaVer, fnameStr); + if (n >= sizeof(fnameStr)) { + TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + } + code = taosRemoveFile(fnameStr); + if (code) { + wError("vgId:%d, failed to remove file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr); + } else { + wInfo("vgId:%d, remove old meta file: %s", pWal->cfg.vgId, fnameStr); + } } taosMemoryFree(serialized); return code; _err: - taosCloseFile(&pMetaFile); + wError("vgId:%d, %s failed at line %d since %s", pWal->cfg.vgId, __func__, lino, tstrerror(code)); + (void)taosCloseFile(&pMetaFile); taosMemoryFree(serialized); return code; } int32_t walLoadMeta(SWal* pWal) { int32_t code = 0; + int n = 0; // find existing meta file int metaVer = walFindCurMetaVer(pWal); if (metaVer == -1) { @@ -1002,12 +1073,24 @@ int32_t walLoadMeta(SWal* pWal) { TAOS_RETURN(TSDB_CODE_FAILED); } char fnameStr[WAL_FILE_LEN]; - (void)walBuildMetaName(pWal, metaVer, fnameStr); + n = walBuildMetaName(pWal, metaVer, fnameStr); + if (n >= sizeof(fnameStr)) { + TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + } // read metafile int64_t fileSize = 0; - (void)taosStatFile(fnameStr, &fileSize, NULL, NULL); + if (taosStatFile(fnameStr, &fileSize, NULL, NULL) != 0) { + wError("vgId:%d, failed to stat file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr); + code = terrno; + TAOS_RETURN(code); + } if (fileSize == 0) { - (void)taosRemoveFile(fnameStr); + code = taosRemoveFile(fnameStr); + if (code) { + wError("vgId:%d, failed to remove file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr); + } else { + wInfo("vgId:%d, remove old meta file: %s", pWal->cfg.vgId, fnameStr); + } wDebug("vgId:%d, wal find empty meta ver %d", pWal->cfg.vgId, metaVer); TAOS_RETURN(TSDB_CODE_FAILED); @@ -1015,7 +1098,7 @@ int32_t walLoadMeta(SWal* pWal) { int size = (int)fileSize; char* buf = taosMemoryMalloc(size + 5); if (buf == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } (void)memset(buf, 0, size + 5); TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ); @@ -1046,6 +1129,9 @@ int32_t walRemoveMeta(SWal* pWal) { int metaVer = walFindCurMetaVer(pWal); if (metaVer == -1) return 0; char fnameStr[WAL_FILE_LEN]; - (void)walBuildMetaName(pWal, metaVer, fnameStr); + int n = walBuildMetaName(pWal, metaVer, fnameStr); + if (n >= sizeof(fnameStr)) { + TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + } return taosRemoveFile(fnameStr); } diff --git a/source/libs/wal/src/walMgmt.c b/source/libs/wal/src/walMgmt.c index 3bb4b9d747..2d9ca4cce3 100644 --- a/source/libs/wal/src/walMgmt.c +++ b/source/libs/wal/src/walMgmt.c @@ -160,7 +160,9 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) { pWal->writeHead.magic = WAL_MAGIC; // load meta - (void)walLoadMeta(pWal); + if (walLoadMeta(pWal) < 0) { + wInfo("vgId:%d, failed to load meta since %s", pWal->cfg.vgId, tstrerror(terrno)); + } if (walCheckAndRepairMeta(pWal) < 0) { wError("vgId:%d, cannot open wal since repair meta file failed", pWal->cfg.vgId); @@ -187,6 +189,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) { _err: taosArrayDestroy(pWal->fileInfoSet); + taosArrayDestroy(pWal->toDeleteFiles); taosHashCleanup(pWal->pRefHash); TAOS_UNUSED(taosThreadRwlockDestroy(&pWal->mutex)); taosMemoryFreeClear(pWal); @@ -233,7 +236,9 @@ int32_t walPersist(SWal *pWal) { void walClose(SWal *pWal) { TAOS_UNUSED(taosThreadRwlockWrlock(&pWal->mutex)); - (void)walSaveMeta(pWal); + if (walSaveMeta(pWal) < 0) { + wError("vgId:%d, failed to save meta since %s", pWal->cfg.vgId, tstrerror(terrno)); + } TAOS_UNUSED(taosCloseFile(&pWal->pLogFile)); pWal->pLogFile = NULL; (void)taosCloseFile(&pWal->pIdxFile); @@ -257,10 +262,14 @@ void walClose(SWal *pWal) { if (pWal->cfg.level == TAOS_WAL_SKIP) { wInfo("vgId:%d, remove all wals, path:%s", pWal->cfg.vgId, pWal->path); taosRemoveDir(pWal->path); - (void)taosMkDir(pWal->path); + if (taosMkDir(pWal->path) != 0) { + wError("vgId:%d, path:%s, failed to create directory since %s", pWal->cfg.vgId, pWal->path, tstrerror(terrno)); + } } - (void)taosRemoveRef(tsWal.refSetId, pWal->refId); + if (taosRemoveRef(tsWal.refSetId, pWal->refId) < 0) { + wError("vgId:%d, failed to remove ref for Wal since %s", pWal->cfg.vgId, tstrerror(terrno)); + } } static void walFreeObj(void *wal) { @@ -285,7 +294,9 @@ static bool walNeedFsync(SWal *pWal) { static void walUpdateSeq() { taosMsleep(WAL_REFRESH_MS); - (void)atomic_add_fetch_32((volatile int32_t *)&tsWal.seq, 1); + if (atomic_add_fetch_32((volatile int32_t *)&tsWal.seq, 1) < 0) { + wError("failed to update wal seq since %s", strerror(errno)); + } } static void walFsyncAll() { diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index 321a47d678..9cf5bcbf09 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -212,7 +212,7 @@ static int32_t walReadSeekVerImpl(SWalReader *pReader, int64_t ver) { if (pRet == NULL) { wError("failed to allocate memory for localRet"); TAOS_UNUSED(taosThreadRwlockUnlock(&pWal->mutex)); - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } TAOS_MEMCPY(pRet, gloablPRet, sizeof(SWalFileInfo)); TAOS_UNUSED(taosThreadRwlockUnlock(&pWal->mutex)); @@ -341,7 +341,7 @@ int32_t walFetchBody(SWalReader *pRead) { if (pRead->capacity < cryptedBodyLen) { SWalCkHead *ptr = (SWalCkHead *)taosMemoryRealloc(pRead->pHead, sizeof(SWalCkHead) + cryptedBodyLen); if (ptr == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } pRead->pHead = ptr; pReadHead = &pRead->pHead->head; @@ -463,7 +463,7 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) { if (ptr == NULL) { TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex)); - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } pReader->pHead = ptr; pReader->capacity = cryptedBodyLen; @@ -523,7 +523,7 @@ int32_t decryptBody(SWalCfg *cfg, SWalCkHead *pHead, int32_t plainBodyLen, const int32_t cryptedBodyLen = ENCRYPTED_LEN(plainBodyLen); char *newBody = taosMemoryMalloc(cryptedBodyLen); if (!newBody) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } SCryptOpts opts; diff --git a/source/libs/wal/src/walRef.c b/source/libs/wal/src/walRef.c index bf24ed89fb..6b8b063b2b 100644 --- a/source/libs/wal/src/walRef.c +++ b/source/libs/wal/src/walRef.c @@ -52,8 +52,11 @@ void walCloseRef(SWal *pWal, int64_t refId) { } else { wDebug("vgId:%d, wal close ref null, refId %" PRId64, pWal->cfg.vgId, refId); } - - (void)taosHashRemove(pWal->pRefHash, &refId, sizeof(int64_t)); + int32_t code = 0; + code = taosHashRemove(pWal->pRefHash, &refId, sizeof(int64_t)); + if (code) { + wError("vgId:%d, wal remove ref failed, refId %" PRId64 ", error:%s", pWal->cfg.vgId, refId, tstrerror(code)); + } } } diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index a5105fc107..bb6dbbeeb6 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -86,11 +86,9 @@ int32_t walRestoreFromSnapshot(SWal *pWal, int64_t ver) { TAOS_RETURN(TSDB_CODE_SUCCESS); } -int32_t walApplyVer(SWal *pWal, int64_t ver) { +void walApplyVer(SWal *pWal, int64_t ver) { // TODO: error check pWal->vers.appliedVer = ver; - - TAOS_RETURN(TSDB_CODE_SUCCESS); } int32_t walCommit(SWal *pWal, int64_t ver) { @@ -603,7 +601,7 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy wError("vgId:%d, file:%" PRId64 ".log, failed to malloc since %s", pWal->cfg.vgId, walGetLastFileFirstVer(pWal), strerror(errno)); - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } TAOS_UNUSED(memset(newBody, 0, cyptedBodyLen)); TAOS_UNUSED(memcpy(newBody, body, plainBodyLen)); @@ -615,7 +613,7 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy if (newBody != NULL) taosMemoryFreeClear(newBody); - TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } SCryptOpts opts; diff --git a/source/os/src/osSemaphore.c b/source/os/src/osSemaphore.c index f6d339c89e..ea9e824947 100644 --- a/source/os/src/osSemaphore.c +++ b/source/os/src/osSemaphore.c @@ -232,7 +232,7 @@ int32_t tsem_init(tsem_t *psem, int flags, unsigned int count) { if(sem_init(psem, flags, count) == 0) { return 0; } else { - return TAOS_SYSTEM_ERROR(errno); + return terrno = TAOS_SYSTEM_ERROR(errno); } } diff --git a/source/util/src/talgo.c b/source/util/src/talgo.c index f1ee40eccf..21201df309 100644 --- a/source/util/src/talgo.c +++ b/source/util/src/talgo.c @@ -335,7 +335,7 @@ int32_t taosheapadjust(void *base, int32_t size, int32_t start, int32_t end, con if (buf == NULL) { tmp = taosMemoryMalloc(size); if (NULL == tmp) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } else { tmp = buf; @@ -467,7 +467,7 @@ static int32_t taosMergeSortHelper(void *src, int64_t numOfElem, int64_t size, c int32_t currSize; void *tmp = taosMemoryMalloc(numOfElem * size); if (tmp == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (currSize = THRESHOLD_SIZE; currSize <= numOfElem - 1; currSize = 2 * currSize) { diff --git a/source/util/src/tbase64.c b/source/util/src/tbase64.c index 86b069b853..f623d34a2f 100644 --- a/source/util/src/tbase64.c +++ b/source/util/src/tbase64.c @@ -22,7 +22,7 @@ int32_t base64_encode(const uint8_t *value, int32_t vlen, char **result) { uint8_t oval = 0; *result = (char *)taosMemoryMalloc((size_t)(vlen * 4) / 3 + 10); if (*result == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } char *out = *result; while (vlen >= 3) { @@ -58,7 +58,7 @@ int32_t base64_decode(const char *value, int32_t inlen, int32_t *outlen, uint8_t int32_t c1, c2, c3, c4; *result = (uint8_t *)taosMemoryMalloc((size_t)(inlen * 3) / 4 + 1); if (*result == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } uint8_t *out = *result; diff --git a/source/util/src/tcompression.c b/source/util/src/tcompression.c index afbd5304ce..eec89617c9 100644 --- a/source/util/src/tcompression.c +++ b/source/util/src/tcompression.c @@ -1766,12 +1766,12 @@ int32_t tsDecompressBigint2(void *pIn, int32_t nIn, int32_t nEle, void *pOut, in FUNC_COMPRESS_IMPL(pIn, nIn, nEle, pOut, nOut, cmprAlg, pBuf, nBuf, TSDB_DATA_TYPE_BIGINT, 0); } -int32_t tcompressDebug(uint32_t cmprAlg, uint8_t *l1Alg, uint8_t *l2Alg, uint8_t *level) { +void tcompressDebug(uint32_t cmprAlg, uint8_t *l1Alg, uint8_t *l2Alg, uint8_t *level) { DEFINE_VAR(cmprAlg) *l1Alg = l1; *l2Alg = l2; *level = lvl; - return 0; + return; } int8_t tUpdateCompress(uint32_t oldCmpr, uint32_t newCmpr, uint8_t l2Disabled, uint8_t lvlDiabled, uint8_t lvlDefault, diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index 6868e6d0eb..ee55243415 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -51,7 +51,7 @@ int32_t cfgInit(SConfig **ppCfg) { pCfg->array = taosArrayInit(32, sizeof(SConfigItem)); if (pCfg->array == NULL) { taosMemoryFree(pCfg); - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } TAOS_CHECK_RETURN(taosThreadMutexInit(&pCfg->lock, NULL)); @@ -127,7 +127,7 @@ static int32_t cfgCheckAndSetConf(SConfigItem *pItem, const char *conf) { pItem->str = taosStrdup(conf); if (pItem->str == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } TAOS_RETURN(TSDB_CODE_SUCCESS); @@ -144,7 +144,7 @@ static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) { taosMemoryFreeClear(pItem->str); pItem->str = taosStrdup(fullDir); if (pItem->str == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } TAOS_RETURN(TSDB_CODE_SUCCESS); @@ -211,7 +211,7 @@ static int32_t cfgSetString(SConfigItem *pItem, const char *value, ECfgSrcType s if (tmp == NULL) { uError("cfg:%s, type:%s src:%s value:%s failed to dup since %s", pItem->name, cfgDtypeStr(pItem->dtype), cfgStypeStr(stype), value, tstrerror(TSDB_CODE_OUT_OF_MEMORY)); - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } taosMemoryFreeClear(pItem->str); @@ -272,7 +272,7 @@ static int32_t cfgSetTfsItem(SConfig *pCfg, const char *name, const char *value, if (pItem->array == NULL) { (void)taosThreadMutexUnlock(&pCfg->lock); - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } } @@ -285,7 +285,7 @@ static int32_t cfgSetTfsItem(SConfig *pCfg, const char *name, const char *value, if (ret == NULL) { (void)taosThreadMutexUnlock(&pCfg->lock); - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } pItem->stype = stype; @@ -304,7 +304,7 @@ static int32_t cfgUpdateDebugFlagItem(SConfig *pCfg, const char *name, bool rese if (pDebugFlagItem->array == NULL) { pDebugFlagItem->array = taosArrayInit(16, sizeof(SLogVar)); if (pDebugFlagItem->array == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } } taosArrayClear(pDebugFlagItem->array); @@ -317,7 +317,7 @@ static int32_t cfgUpdateDebugFlagItem(SConfig *pCfg, const char *name, bool rese SLogVar logVar = {0}; (void)strncpy(logVar.name, name, TSDB_LOG_VAR_LEN - 1); if (NULL == taosArrayPush(pDebugFlagItem->array, &logVar)) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } } TAOS_RETURN(TSDB_CODE_SUCCESS); @@ -505,7 +505,7 @@ static int32_t cfgAddItem(SConfig *pCfg, SConfigItem *pItem, const char *name) { pItem->stype = CFG_STYPE_DEFAULT; pItem->name = taosStrdup(name); if (pItem->name == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } int32_t size = taosArrayGetSize(pCfg->array); @@ -527,7 +527,7 @@ static int32_t cfgAddItem(SConfig *pCfg, SConfigItem *pItem, const char *name) { } taosMemoryFree(pItem->name); - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } TAOS_RETURN(TSDB_CODE_SUCCESS); @@ -587,7 +587,7 @@ int32_t cfgAddString(SConfig *pCfg, const char *name, const char *defaultVal, in SConfigItem item = {.dtype = CFG_DTYPE_STRING, .scope = scope, .dynScope = dynScope}; item.str = taosStrdup(defaultVal); if (item.str == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } return cfgAddItem(pCfg, &item, name); } @@ -1309,7 +1309,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { size_t itemValueStringLen = strlen(itemValueString); void *px = taosMemoryRealloc(cfgLineBuf, itemNameLen + itemValueStringLen + 3); if (NULL == px) { - TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY); + TAOS_CHECK_EXIT(terrno); } cfgLineBuf = px; diff --git a/source/util/src/tencode.c b/source/util/src/tencode.c index 99b0b2bded..db59d19fb5 100644 --- a/source/util/src/tencode.c +++ b/source/util/src/tencode.c @@ -78,7 +78,7 @@ int32_t tStartEncode(SEncoder* pCoder) { pNode = tEncoderMalloc(pCoder, sizeof(*pNode)); if (pNode == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } pNode->data = pCoder->data; @@ -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; } @@ -126,7 +126,7 @@ int32_t tStartDecode(SDecoder* pCoder) { pNode = tDecoderMalloc(pCoder, sizeof(*pNode)); if (pNode == NULL) { - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } pNode->data = pCoder->data; diff --git a/source/util/src/thash.c b/source/util/src/thash.c index 758e283bc3..ab88bef1a0 100644 --- a/source/util/src/thash.c +++ b/source/util/src/thash.c @@ -352,7 +352,7 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, const vo // no data in hash table with the specified key, add it into hash table SHashNode *pNewNode = doCreateHashNode(key, keyLen, data, size, hashVal); if (pNewNode == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + // terrno = TSDB_CODE_OUT_OF_MEMORY; code = terrno; goto _exit; } @@ -364,7 +364,7 @@ int32_t taosHashPut(SHashObj *pHashObj, const void *key, size_t keyLen, const vo if (pHashObj->enableUpdate) { SHashNode *pNewNode = doCreateHashNode(key, keyLen, data, size, hashVal); if (pNewNode == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; + // terrno = TSDB_CODE_OUT_OF_MEMORY; code = terrno; goto _exit; } @@ -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; } diff --git a/source/util/src/theap.c b/source/util/src/theap.c index 7ee49ff56d..e906d1f55b 100644 --- a/source/util/src/theap.c +++ b/source/util/src/theap.c @@ -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); } diff --git a/source/util/src/tjson.c b/source/util/src/tjson.c index 4cf5917f7c..0f2504ff5e 100644 --- a/source/util/src/tjson.c +++ b/source/util/src/tjson.c @@ -131,7 +131,7 @@ int32_t tjsonAddArray(SJson* pJson, const char* pName, FToJson func, const void* if (num > 0) { SJson* pJsonArray = tjsonAddArrayToObject(pJson, pName); if (NULL == pJsonArray) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (size_t i = 0; i < num; ++i) { int32_t code = tjsonAddItem(pJsonArray, func, (const char*)pArray + itemSize * i); @@ -148,7 +148,7 @@ int32_t tjsonAddTArray(SJson* pJson, const char* pName, FToJson func, const SArr if (num > 0) { SJson* pJsonArray = tjsonAddArrayToObject(pJson, pName); if (NULL == pJsonArray) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int32_t i = 0; i < num; ++i) { int32_t code = tjsonAddItem(pJsonArray, func, taosArrayGet(pArray, i)); @@ -343,7 +343,7 @@ int32_t tjsonToTArray(const SJson* pJson, const char* pName, FToObject func, SAr if (size > 0) { *pArray = taosArrayInit_s(itemSize, size); if (NULL == *pArray) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } for (int32_t i = 0; i < size; ++i) { int32_t code = func(tjsonGetArrayItem(jArray, i), taosArrayGet(*pArray, i)); diff --git a/source/util/src/tlrucache.c b/source/util/src/tlrucache.c index cfbd875890..fbd17dd023 100644 --- a/source/util/src/tlrucache.c +++ b/source/util/src/tlrucache.c @@ -14,12 +14,12 @@ */ #define _DEFAULT_SOURCE -#include "tlrucache.h" #include "os.h" #include "taoserror.h" #include "tarray.h" #include "tdef.h" #include "tlog.h" +#include "tlrucache.h" #include "tutil.h" typedef struct SLRUEntry SLRUEntry; @@ -305,8 +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 +528,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 +573,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); @@ -870,4 +869,4 @@ bool taosLRUCacheIsStrictCapacity(SLRUCache *cache) { (void)taosThreadMutexUnlock(&cache->shardedCache.capacityMutex); return strict; -} +} \ No newline at end of file diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c index 46f2fdc647..25e10a17df 100644 --- a/source/util/src/tpagedbuf.c +++ b/source/util/src/tpagedbuf.c @@ -57,7 +57,7 @@ static int32_t createDiskFile(SDiskbasedBuf* pBuf) { taosGetTmpfilePath(pBuf->prefix, "paged-buf", path); pBuf->path = taosStrdup(path); if (pBuf->path == NULL) { - return TSDB_CODE_OUT_OF_MEMORY; + return terrno; } } diff --git a/source/util/src/tqueue.c b/source/util/src/tqueue.c index d067847376..f531d9ad61 100644 --- a/source/util/src/tqueue.c +++ b/source/util/src/tqueue.c @@ -224,7 +224,9 @@ int32_t taosWriteQitem(STaosQueue *queue, void *pItem) { (void)taosThreadMutexUnlock(&queue->mutex); if (queue->qset) { - (void)tsem_post(&queue->qset->sem); + if (tsem_post(&queue->qset->sem) != 0) { + uError("failed to post semaphore for queue set:%p", queue->qset); + } } return code; } @@ -333,7 +335,10 @@ int32_t taosOpenQset(STaosQset **qset) { } (void)taosThreadMutexInit(&(*qset)->mutex, NULL); - (void)tsem_init(&(*qset)->sem, 0, 0); + if (tsem_init(&(*qset)->sem, 0, 0) != 0) { + taosMemoryFree(*qset); + return terrno; + } uDebug("qset:%p is opened", qset); return 0; @@ -354,7 +359,9 @@ void taosCloseQset(STaosQset *qset) { (void)taosThreadMutexUnlock(&qset->mutex); (void)taosThreadMutexDestroy(&qset->mutex); - (void)tsem_destroy(&qset->sem); + if (tsem_destroy(&qset->sem) != 0) { + uError("failed to destroy semaphore for qset:%p", qset); + } taosMemoryFree(qset); uDebug("qset:%p is closed", qset); } @@ -364,7 +371,9 @@ void taosCloseQset(STaosQset *qset) { // thread to exit. void taosQsetThreadResume(STaosQset *qset) { uDebug("qset:%p, it will exit", qset); - (void)tsem_post(&qset->sem); + if (tsem_post(&qset->sem) != 0) { + uError("failed to post semaphore for qset:%p", qset); + } } int32_t taosAddIntoQset(STaosQset *qset, STaosQueue *queue, void *ahandle) { @@ -432,7 +441,9 @@ int32_t taosReadQitemFromQset(STaosQset *qset, void **ppItem, SQueueInfo *qinfo) STaosQnode *pNode = NULL; int32_t code = 0; - (void)tsem_wait(&qset->sem); + if (tsem_wait(&qset->sem) != 0) { + uError("failed to wait semaphore for qset:%p", qset); + } (void)taosThreadMutexLock(&qset->mutex); @@ -476,7 +487,9 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, SQueueInfo * STaosQueue *queue; int32_t code = 0; - (void)tsem_wait(&qset->sem); + if (tsem_wait(&qset->sem) != 0) { + uError("failed to wait semaphore for qset:%p", qset); + } (void)taosThreadMutexLock(&qset->mutex); for (int32_t i = 0; i < qset->numOfQueues; ++i) { @@ -510,7 +523,9 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, SQueueInfo * (void)atomic_sub_fetch_32(&qset->numOfItems, qall->numOfItems); for (int32_t j = 1; j < qall->numOfItems; ++j) { - (void)tsem_wait(&qset->sem); + if (tsem_wait(&qset->sem) != 0) { + uError("failed to wait semaphore for qset:%p", qset); + } } } diff --git a/source/util/src/tref.c b/source/util/src/tref.c index 685fe01fee..9360bd8b0e 100644 --- a/source/util/src/tref.c +++ b/source/util/src/tref.c @@ -158,6 +158,8 @@ int64_t taosAddRef(int32_t rsetId, void *p) { pNode = taosMemoryCalloc(sizeof(SRefNode), 1); if (pNode == NULL) { + taosDecRsetCount(pSet); + uError("rsetId:%d p:%p failed to add, out of memory", rsetId, p); return terrno; } diff --git a/source/util/src/tscalablebf.c b/source/util/src/tscalablebf.c index ebc076e02e..a45d157366 100644 --- a/source/util/src/tscalablebf.c +++ b/source/util/src/tscalablebf.c @@ -46,7 +46,7 @@ int32_t tScalableBfInit(uint64_t expectedEntries, double errorRate, SScalableBf* pSBf->numBits = 0; pSBf->bfArray = taosArrayInit(defaultSize, sizeof(void*)); if (!pSBf->bfArray) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _error); } @@ -76,7 +76,7 @@ int32_t tScalableBfPutNoCheck(SScalableBf* pSBf, const void* keyBuf, uint32_t le int32_t size = taosArrayGetSize(pSBf->bfArray); SBloomFilter* pNormalBf = taosArrayGetP(pSBf->bfArray, size - 1); if (!pNormalBf) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _error); } if (tBloomFilterIsFull(pNormalBf)) { @@ -236,7 +236,7 @@ int32_t tScalableBfDecode(SDecoder* pDecoder, SScalableBf** ppSBf) { } pSBf->bfArray = taosArrayInit(size * 2, POINTER_BYTES); if (!pSBf->bfArray) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _error); } @@ -246,7 +246,7 @@ int32_t tScalableBfDecode(SDecoder* pDecoder, SScalableBf** ppSBf) { QUERY_CHECK_CODE(code, lino, _error); void* tmpRes = taosArrayPush(pSBf->bfArray, &pBF); if (!tmpRes) { - code = TSDB_CODE_OUT_OF_MEMORY; + code = terrno; QUERY_CHECK_CODE(code, lino, _error); } } diff --git a/source/util/src/tskiplist.c b/source/util/src/tskiplist.c index ae01292e08..95680686cf 100644 --- a/source/util/src/tskiplist.c +++ b/source/util/src/tskiplist.c @@ -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) { diff --git a/source/util/src/tworker.c b/source/util/src/tworker.c index c2757dcabc..6370e6ca50 100644 --- a/source/util/src/tworker.c +++ b/source/util/src/tworker.c @@ -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) { @@ -168,7 +178,7 @@ int32_t tAutoQWorkerInit(SAutoQWorkerPool *pool) { pool->workers = taosArrayInit(2, sizeof(SQueueWorker *)); if (pool->workers == NULL) { taosCloseQset(pool->qset); - return terrno = TSDB_CODE_OUT_OF_MEMORY; + return terrno; } (void)taosThreadMutexInit(&pool->mutex, NULL); @@ -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,14 +432,16 @@ 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; TdThreadAttr thAttr; (void)taosThreadAttrInit(&thAttr); (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); - if (taosThreadCreate(&worker->thread, &thAttr, (ThreadFp)tWWorkerThreadFp, worker) != 0) goto _OVER; + code = taosThreadCreate(&worker->thread, &thAttr, (ThreadFp)tWWorkerThreadFp, worker); + if ((code)) goto _OVER; uInfo("worker:%s:%d is launched, max:%d", pool->name, worker->id, pool->max); pool->nextId = (pool->nextId + 1) % pool->max; @@ -423,7 +450,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 +579,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 +657,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 +680,7 @@ static void *tQueryAutoQWorkerThreadFp(SQueryAutoQWorker *worker) { } } - (void)tQueryAutoQWorkerWaitingCheck(pool); + tQueryAutoQWorkerWaitingCheck(pool); if (qinfo.fp != NULL) { qinfo.workerId = worker->id; @@ -717,13 +749,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 +768,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 +776,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 +784,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 +809,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); @@ -803,11 +835,11 @@ int32_t tQueryAutoQWorkerInit(SQueryAutoQWorkerPool *pool) { code = taosOpenQset(&pool->qset); if (code) return terrno = code; pool->workers = tdListNew(sizeof(SQueryAutoQWorker)); - if (!pool->workers) return TSDB_CODE_OUT_OF_MEMORY; + if (!pool->workers) return terrno; pool->backupWorkers = tdListNew(sizeof(SQueryAutoQWorker)); - if (!pool->backupWorkers) return TSDB_CODE_OUT_OF_MEMORY; + if (!pool->backupWorkers) return terrno; pool->exitedWorkers = tdListNew(sizeof(SQueryAutoQWorker)); - if (!pool->exitedWorkers) return TSDB_CODE_OUT_OF_MEMORY; + if (!pool->exitedWorkers) return terrno; pool->maxInUse = pool->max * 2 + 2; if (!pool->pCb) { @@ -862,7 +894,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 +904,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 +914,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 +945,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; diff --git a/tests/army/query/subquery/subqueryBugs.py b/tests/army/query/subquery/subqueryBugs.py index 8442474d40..e208c40abc 100644 --- a/tests/army/query/subquery/subqueryBugs.py +++ b/tests/army/query/subquery/subqueryBugs.py @@ -78,6 +78,72 @@ class TDTestCase(TBase): rows = [row1, row2, row3, row4] tdSql.checkDataMem(sql1, rows) + def ts_5443(self): + tdLog.info("create database ts_5443") + tdSql.execute("create database ts_5443") + tdSql.execute("use ts_5443") + sqls = [ + "CREATE STABLE demo (ts TIMESTAMP, site NCHAR(8), expected BIGINT) TAGS (group_id BIGINT UNSIGNED)", + "CREATE TABLE demo_1 USING demo (group_id) TAGS (1)", + "INSERT INTO demo_1 VALUES ('2022-10-25 16:05:00.000', 'MN-01', 1)", + "CREATE TABLE demo_2 USING demo (group_id) TAGS (2)", + "INSERT INTO demo_2 VALUES ('2022-10-25 16:10:00.000', 'MN-02', 2)", + "CREATE TABLE demo_3 USING demo (group_id) TAGS (3)", + "INSERT INTO demo_3 VALUES ('2022-10-25 16:15:00.000', 'MN-03', 3)", + ] + tdSql.executes(sqls) + # test result of order by in plain query + query = ''' + SELECT _wend, site, SUM(expected) AS check + FROM ts_5443.demo + PARTITION BY site INTERVAL(5m) SLIDING (5m) + ORDER BY 1 DESC, 2, 3 + ''' + tdSql.query(query) + tdSql.checkRows(3) + rows = [ + ['2022-10-25 16:20:00.000', 'MN-03', 3], + ['2022-10-25 16:15:00.000', 'MN-02', 2], + ['2022-10-25 16:10:00.000', 'MN-01', 1], + ] + tdSql.checkDataMem(query, rows) + # test order by position alias within subquery + query = ''' + SELECT COUNT(*) FROM ( + SELECT _wend, site, SUM(expected) AS check + FROM ts_5443.demo + PARTITION BY site INTERVAL(5m) SLIDING (5m) + ORDER BY 1 DESC, 2, 3 + ) WHERE check <> 0 + ''' + tdSql.query(query) + tdSql.checkRows(1) + tdSql.checkData(0, 0, 3) + # test order by target name within subquery + query = ''' + SELECT COUNT(*) FROM ( + SELECT _wend, site, SUM(expected) AS check + FROM ts_5443.demo + PARTITION BY site INTERVAL(5m) SLIDING (5m) + ORDER BY _wend DESC, site, check + ) WHERE check <> 0 + ''' + tdSql.query(query) + tdSql.checkRows(1) + tdSql.checkData(0, 0, 3) + # test having clause within subquery + query = ''' + SELECT COUNT(*) FROM ( + SELECT _wend, site, SUM(expected) AS check + FROM ts_5443.demo + PARTITION BY site INTERVAL(5m) SLIDING (5m) + HAVING _wend > '2022-10-25 16:13:00.000' + ) WHERE check <> 0 + ''' + tdSql.query(query) + tdSql.checkRows(1) + tdSql.checkData(0, 0, 2) + # run def run(self): tdLog.debug(f"start to excute {__file__}") @@ -85,6 +151,8 @@ class TDTestCase(TBase): # TS-30189 self.ts_30189() + # TS-5443 + self.ts_5443() tdLog.success(f"{__file__} successfully executed") diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index e66cc928e2..3ecf5d7b03 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -280,6 +280,7 @@ ,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/dataFromTsdbNWal.py ,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/dataFromTsdbNWal-multiCtb.py ,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmq_taosx.py +,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmq_ts-5473.py ,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmq_ts4563.py ,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmq_replay.py ,,y,system-test,./pytest.sh python3 ./test.py -f 7-tmq/tmqSeekAndCommit.py diff --git a/tests/parallel_test/run_case.sh b/tests/parallel_test/run_case.sh index ff84d9e66c..fa8fedbdbe 100755 --- a/tests/parallel_test/run_case.sh +++ b/tests/parallel_test/run_case.sh @@ -76,15 +76,15 @@ ulimit -c unlimited md5sum /usr/lib/libtaos.so.1 md5sum /home/TDinternal/debug/build/lib/libtaos.so -#define taospy 2.7.10 +#define taospy 2.7.16 pip3 list|grep taospy pip3 uninstall taospy -y -pip3 install --default-timeout=120 taospy==2.7.15 +pip3 install --default-timeout=120 taospy==2.7.16 #define taos-ws-py 0.3.1 pip3 list|grep taos-ws-py pip3 uninstall taos-ws-py -y -pip3 install --default-timeout=600 taos-ws-py==0.3.1 +pip3 install --default-timeout=600 taos-ws-py==0.3.3 $TIMEOUT_CMD $cmd RET=$? diff --git a/tests/pytest/util/csv.py b/tests/pytest/util/csv.py index 6e1ee1732c..2d2e929c86 100644 --- a/tests/pytest/util/csv.py +++ b/tests/pytest/util/csv.py @@ -1,5 +1,6 @@ import csv import os +import platform class TDCsv: def __init__(self): @@ -25,7 +26,11 @@ class TDCsv: @property def file(self): if self.file_name and self.file_path: - return os.path.join(self.file_path, self.file_name) + print(f"self.file_path {self.file_path}, self.file_name {self.file_name}") + csv_file = os.path.join(self.file_path, self.file_name) + if platform.system().lower() == 'windows': + csv_file = csv_file.replace("\\", "/") + return csv_file return None diff --git a/tests/pytest/util/sql.py b/tests/pytest/util/sql.py index 90d3f2fe6c..3bc784063e 100644 --- a/tests/pytest/util/sql.py +++ b/tests/pytest/util/sql.py @@ -24,26 +24,48 @@ from util.log import * from util.constant import * import ctypes import random -# from datetime import timezone +import datetime import time +from tzlocal import get_localzone def _parse_ns_timestamp(timestr): dt_obj = datetime.datetime.strptime(timestr[:len(timestr)-3], "%Y-%m-%d %H:%M:%S.%f") tz = int(int((dt_obj-datetime.datetime.fromtimestamp(0,dt_obj.tzinfo)).total_seconds())*1e9) + int(dt_obj.microsecond * 1000) + int(timestr[-3:]) return tz - def _parse_datetime(timestr): - try: - return datetime.datetime.strptime(timestr, '%Y-%m-%d %H:%M:%S.%f') - except ValueError: - pass - try: - return datetime.datetime.strptime(timestr, '%Y-%m-%d %H:%M:%S') - except ValueError: - pass + # defined timestr formats + formats = [ + '%Y-%m-%d %H:%M:%S.%f%z', # 包含微秒和时区偏移 + '%Y-%m-%d %H:%M:%S%z', # 不包含微秒但包含时区偏移 + '%Y-%m-%d %H:%M:%S.%f', # 包含微秒 + '%Y-%m-%d %H:%M:%S' # 不包含微秒 + ] + + for fmt in formats: + try: + # try to parse the string with the current format + dt = datetime.datetime.strptime(timestr, fmt) + # 如果字符串包含时区信息,则返回 aware 对象 + # if sting contains timezone info, return aware object + if dt.tzinfo is not None: + return dt + + else: + # if sting does not contain timezone info, assume it is in local timezone + # get local timezone + local_timezone = get_localzone() + # print("Timezone:", local_timezone) + return dt.replace(tzinfo=local_timezone) + except ValueError: + continue # if the current format does not match, try the next format + + # 如果所有格式都不匹配,返回 None + # if none of the formats match, return + raise ValueError(f"input format does not match. correct formats include: '{', '.join(formats)}'") class TDSql: + def __init__(self): self.queryRows = 0 self.queryCols = 0 @@ -408,6 +430,7 @@ class TDSql: if self.queryResult[row][col] != data: if self.cursor.istype(col, "TIMESTAMP"): + # tdLog.debug(f"self.queryResult[row][col]:{self.queryResult[row][col]}, data:{data},len(data):{len(data)}, isinstance(data,str) :{isinstance(data,str)}") # suppose user want to check nanosecond timestamp if a longer data passed`` if isinstance(data,str) : if (len(data) >= 28): @@ -419,8 +442,9 @@ class TDSql: args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data) tdLog.exit("%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s" % args) else: + # tdLog.info(f"datetime.timezone.utc:{datetime.timezone.utc},data:{data},_parse_datetime(data).astimezone(datetime.timezone.utc):{_parse_datetime(data).astimezone(datetime.timezone.utc)}") if self.queryResult[row][col].astimezone(datetime.timezone.utc) == _parse_datetime(data).astimezone(datetime.timezone.utc): - # tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{data}") + # tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col].astimezone(datetime.timezone.utc)} == expect:{_parse_datetime(data).astimezone(datetime.timezone.utc)}") if(show): tdLog.info("check successfully") else: diff --git a/tests/script/tsim/stream/basic3.sim b/tests/script/tsim/stream/basic3.sim index 010578d4d2..c6c98281c1 100644 --- a/tests/script/tsim/stream/basic3.sim +++ b/tests/script/tsim/stream/basic3.sim @@ -99,6 +99,18 @@ if $rows == 0 then return -1 endi +print ========== step2 + +sql CREATE DATABASE test2 VGROUPS 2; +sql use test2; + +sql CREATE STABLE st (time TIMESTAMP, ca DOUBLE, cb DOUBLE, cc int) TAGS (ta VARCHAR(10) ); + +sql_error create stream stream_t1 trigger at_once ignore update 0 ignore expired 0 into streamtST as select time, count(*) c1, count(1) c2 from st partition by tbname group by ca,time ; + +sql_error create stream stream_t1 trigger at_once ignore update 0 ignore expired 0 into streamtST as select time, count(*) c1, count(1) c2 from st group by ca,time ; + + _OVER: system sh/exec.sh -n dnode1 -s stop -x SIGINT print =============== check diff --git a/tests/system-test/0-others/backquote_check.py b/tests/system-test/0-others/backquote_check.py index 8cb268fb3d..aad2e21e6e 100644 --- a/tests/system-test/0-others/backquote_check.py +++ b/tests/system-test/0-others/backquote_check.py @@ -133,7 +133,7 @@ class TDTestCase: def run(self): self.topic_name_check() self.db_name_check() - if platform.system().lower() == 'windows': + if platform.system().lower() != 'windows': self.stream_name_check() self.table_name_check() self.view_name_check() diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index b342bc7b0e..f59410b552 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -222,7 +222,7 @@ class TDTestCase: tdSql.query("select * from information_schema.ins_columns where db_name ='information_schema'") tdLog.info(len(tdSql.queryResult)) - tdSql.checkEqual(True, len(tdSql.queryResult) in range(271, 272)) + tdSql.checkEqual(True, len(tdSql.queryResult) in range(272, 273)) tdSql.query("select * from information_schema.ins_columns where db_name ='performance_schema'") tdSql.checkEqual(56, len(tdSql.queryResult)) diff --git a/tests/system-test/0-others/test_hot_refresh_configurations.py b/tests/system-test/0-others/test_hot_refresh_configurations.py index 35137dfeb1..da218162d4 100644 --- a/tests/system-test/0-others/test_hot_refresh_configurations.py +++ b/tests/system-test/0-others/test_hot_refresh_configurations.py @@ -203,7 +203,7 @@ class TDTestCase: assert str(v) == str(value) else: for v in values: - tdLog.debug("Set {} to {}".format(name, v)) + tdLog.debug("Set client {} to {}".format(name, v)) tdSql.error(f'alter local "{name} {v}";') def svr_check(self, item, except_values=False): diff --git a/tests/system-test/1-insert/composite_primary_key_insert.py b/tests/system-test/1-insert/composite_primary_key_insert.py index c888bacadc..311b9cf5b6 100644 --- a/tests/system-test/1-insert/composite_primary_key_insert.py +++ b/tests/system-test/1-insert/composite_primary_key_insert.py @@ -4,6 +4,7 @@ from util.log import * from util.sql import * from util.cases import * from util.csv import * +import platform import os import taos import json @@ -56,7 +57,6 @@ class TDTestCase: tdSql.init(conn.cursor(), True) self.testcasePath = os.path.split(__file__)[0] - self.testcasePath = self.testcasePath.replace('\\', '//') self.testcaseFilename = os.path.split(__file__)[-1] os.system("rm -rf %s/%s.sql" % (self.testcasePath,self.testcaseFilename)) # tdSql.execute(f"insert into db4096.ctb00 file '{self.testcasePath}//tableColumn4096csvLength64k.csv'") diff --git a/tests/system-test/1-insert/drop.py b/tests/system-test/1-insert/drop.py index bd5e4cab49..ad9f6c9be6 100644 --- a/tests/system-test/1-insert/drop.py +++ b/tests/system-test/1-insert/drop.py @@ -49,6 +49,12 @@ class TDTestCase: 'col12': 'binary(20)', 'col13': 'nchar(20)' } + self.db_names = [ f'dbtest_0', f'dbtest_1'] + self.stb_names = [ f'aa\u00bf\u200bstb0'] + self.ctb_names = [ f'ctb0', 'ctb1', f'aa\u00bf\u200bctb0', f'aa\u00bf\u200bctb1'] + self.ntb_names = [ f'ntb0', f'aa\u00bf\u200bntb0', f'ntb1', f'aa\u00bf\u200bntb1'] + self.vgroups_opt = f'vgroups 4' + self.err_dup_cnt = 5 def insert_data(self,column_dict,tbname,row_num): insert_sql = self.setsql.set_insertsql(column_dict,tbname,self.binary_str,self.nchar_str) for i in range(row_num): @@ -116,6 +122,141 @@ class TDTestCase: tdSql.query(f'select * from {stbname} where {k} = {self.ts}') tdSql.checkRows(self.tbnum) tdSql.execute(f'drop database {self.dbname}') + def drop_table_check_init(self): + for db_name in self.db_names: + tdSql.execute(f'create database if not exists {db_name} {self.vgroups_opt}') + tdSql.execute(f'use {db_name}') + for stb_name in self.stb_names: + tdSql.execute(f'create table `{stb_name}` (ts timestamp,c0 int) tags(t0 int)') + for ctb_name in self.ctb_names: + tdSql.execute(f'create table `{ctb_name}` using `{stb_name}` tags(0)') + tdSql.execute(f'insert into `{ctb_name}` values (now,1)') + for ntb_name in self.ntb_names: + tdSql.execute(f'create table `{ntb_name}` (ts timestamp,c0 int)') + tdSql.execute(f'insert into `{ntb_name}` values (now,1)') + def drop_table_check_end(self): + for db_name in self.db_names: + tdSql.execute(f'drop database {db_name}') + def drop_stable_with_check(self): + self.drop_table_check_init() + tdSql.query(f'select * from information_schema.ins_stables where db_name like "dbtest_%"') + result = tdSql.queryResult + print(result) + tdSql.checkEqual(len(result),2) + i = 0 + for stb_result in result: + if i == 0: + dropTable = f'drop table with `{stb_result[1]}`.`{stb_result[10]}`,' + dropStable = f'drop stable with `{stb_result[1]}`.`{stb_result[10]}`,' + dropTableWithSpace = f'drop table with `{stb_result[1]}`.`{stb_result[10]} `,' + dropStableWithSpace = f'drop stable with `{stb_result[1]}`.` {stb_result[10]}`,' + dropStableNotExist = f'drop stable with `{stb_result[1]}`.`{stb_result[10]}_notexist`,' + for _ in range(self.err_dup_cnt): + tdLog.info(dropTableWithSpace[:-1]) + tdSql.error(dropTableWithSpace[:-1], expectErrInfo="Table does not exist", fullMatched=False) + tdLog.info(dropStableWithSpace[:-1]) + tdSql.error(dropStableWithSpace[:-1], expectErrInfo="STable not exist", fullMatched=False) + tdLog.info(dropStableNotExist[:-1]) + tdSql.error(dropStableWithSpace[:-1], expectErrInfo="STable not exist", fullMatched=False) + else: + dropTable += f'`{stb_result[1]}`.`{stb_result[10]}`,' + dropStable += f'`{stb_result[1]}`.`{stb_result[10]}`,' + for _ in range(self.err_dup_cnt): + tdLog.info(dropTable[:-1]) + tdLog.info(dropStable[:-1]) + tdSql.error(dropTable[:-1], expectErrInfo="Cannot drop super table in batch") + tdSql.error(dropStable[:-1], expectErrInfo="syntax error", fullMatched=False) + dropTableWithSpace += f'`{stb_result[1]}`.` {stb_result[10]}`,' + dropStableWithSpace += f'`{stb_result[1]}`.`{stb_result[10]} `,' + for _ in range(self.err_dup_cnt): + tdLog.info(dropTableWithSpace[:-1]) + tdLog.info(dropStableWithSpace[:-1]) + tdSql.error(dropTableWithSpace[:-1], expectErrInfo="Table does not exist", fullMatched=False) + tdSql.error(dropStableWithSpace[:-1], expectErrInfo="syntax error", fullMatched=False) + i += 1 + i = 0 + for stb_result in result: + if i == 0: + tdSql.execute(f'drop table with `{stb_result[1]}`.`{stb_result[10]}`') + else: + tdSql.execute(f'drop stable with `{stb_result[1]}`.`{stb_result[10]}`') + i += 1 + for i in range(30): + tdSql.query(f'select * from information_schema.ins_stables where db_name like "dbtest_%"') + if(len(tdSql.queryResult) == 0): + break + tdLog.info(f'ins_stables not empty, sleep 1s') + time.sleep(1) + tdSql.query(f'select * from information_schema.ins_stables where db_name like "dbtest_%"') + tdSql.checkRows(0) + tdSql.query(f'select * from information_schema.ins_tables where db_name like "dbtest_%"') + tdSql.checkRows(8) + for _ in range(self.err_dup_cnt): + tdSql.error(f'drop stable with information_schema.`ins_tables`;', expectErrInfo="Cannot drop table of system database", fullMatched=False) + tdSql.error(f'drop stable with performance_schema.`perf_connections`;', expectErrInfo="Cannot drop table of system database", fullMatched=False) + self.drop_table_check_end() + def drop_table_with_check(self): + self.drop_table_check_init() + tdSql.query(f'select * from information_schema.ins_tables where db_name like "dbtest_%"') + result = tdSql.queryResult + print(result) + tdSql.checkEqual(len(result),16) + dropTable = f'drop table with ' + for tb_result in result: + dropTable += f'`{tb_result[1]}`.`{tb_result[5]}`,' + tdLog.info(dropTable[:-1]) + tdSql.execute(dropTable[:-1]) + for i in range(30): + tdSql.query(f'select * from information_schema.ins_tables where db_name like "dbtest_%"') + if(len(tdSql.queryResult) == 0): + break + tdLog.info(f'ins_tables not empty, sleep 1s') + time.sleep(1) + tdSql.query(f'select * from information_schema.ins_tables where db_name like "dbtest_%"') + tdSql.checkRows(0) + tdSql.query(f'select * from information_schema.ins_stables where db_name like "dbtest_%"') + tdSql.checkRows(2) + for _ in range(self.err_dup_cnt): + tdSql.error(f'drop table with information_schema.`ins_tables`;', expectErrInfo="Cannot drop table of system database", fullMatched=False) + tdSql.error(f'drop table with performance_schema.`perf_connections`;', expectErrInfo="Cannot drop table of system database", fullMatched=False) + self.drop_table_check_end() + def drop_table_with_check_tsma(self): + tdSql.execute(f'create database if not exists {self.dbname} {self.vgroups_opt}') + tdSql.execute(f'use {self.dbname}') + tdSql.execute(f'create table {self.dbname}.stb (ts timestamp,c0 int) tags(t0 int)') + tdSql.execute(f'create tsma stb_tsma on {self.dbname}.stb function(avg(c0),count(c0)) interval(1d)') + tdSql.execute(f'create table {self.dbname}.ctb using {self.dbname}.stb tags(0)') + tdSql.execute(f'insert into {self.dbname}.ctb values (now,1)') + tdSql.execute(f'create table {self.dbname}.ntb (ts timestamp,c0 int)') + tdSql.execute(f'create tsma ntb_tsma on {self.dbname}.ntb function(avg(c0),count(c0)) interval(1d)') + tdSql.execute(f'insert into {self.dbname}.ntb values (now,1)') + tdSql.query(f'select * from information_schema.ins_tsmas where db_name = "{self.dbname}"') + tdSql.checkRows(2) + tdSql.query(f'select * from information_schema.ins_tables where db_name = "{self.dbname}" and type="CHILD_TABLE"') + tdSql.checkRows(1) + tdSql.execute(f'drop table with {tdSql.queryResult[0][1]}.`{tdSql.queryResult[0][5]}`') + tdSql.query(f'select * from information_schema.ins_tables where db_name = "{self.dbname}" and type="CHILD_TABLE"') + tdSql.checkRows(0) + tdSql.query(f'select * from information_schema.ins_stables where db_name = "{self.dbname}"') + tdSql.checkRows(1) + tdSql.error(f'drop table with {tdSql.queryResult[0][1]}.`{tdSql.queryResult[0][10]}`') + tdSql.query(f'select * from information_schema.ins_stables where db_name = "{self.dbname}"') + tdSql.error(f'drop stable with {tdSql.queryResult[0][1]}.`{tdSql.queryResult[0][10]}`') + tdSql.query(f'select * from information_schema.ins_stables where db_name = "{self.dbname}"') + tdSql.checkRows(1) + tdSql.query(f'select * from information_schema.ins_tables where db_name = "{self.dbname}" and type="NORMAL_TABLE"') + tdSql.checkRows(1) + tdSql.execute(f'drop table with {tdSql.queryResult[0][1]}.`{tdSql.queryResult[0][5]}`') + tdSql.query(f'select * from information_schema.ins_tables where db_name = "{self.dbname}" and type="NORMAL_TABLE"') + tdSql.checkRows(0) + tdSql.query(f'select * from information_schema.ins_tsmas where db_name = "{self.dbname}"') + tsmas = tdSql.queryResult + tdSql.checkEqual(len(tsmas),2) + for tsma in tsmas: + tdSql.execute(f'drop tsma {tsma[1]}.{tsma[0]}') + tdSql.query(f'show tsmas') + tdSql.checkRows(0) + tdSql.execute(f'drop database {self.dbname}') def drop_topic_check(self): tdSql.execute(f'create database {self.dbname} replica {self.replicaVar} wal_retention_period 3600') tdSql.execute(f'use {self.dbname}') @@ -161,8 +302,11 @@ class TDTestCase: def run(self): self.drop_ntb_check() self.drop_stb_ctb_check() + self.drop_stable_with_check() + self.drop_table_with_check() + self.drop_table_with_check_tsma() self.drop_topic_check() - if platform.system().lower() == 'windows': + if platform.system().lower() != 'windows': self.drop_stream_check() pass def stop(self): diff --git a/tests/system-test/2-query/fill.py b/tests/system-test/2-query/fill.py index 31d2d92563..3a868b7877 100644 --- a/tests/system-test/2-query/fill.py +++ b/tests/system-test/2-query/fill.py @@ -1,6 +1,5 @@ import queue import random -from fabric2.runners import threading from pandas._libs import interval import taos import sys @@ -9,6 +8,7 @@ from util.common import TDCom from util.log import * from util.sql import * from util.cases import * +import threading diff --git a/tests/system-test/2-query/normal.py b/tests/system-test/2-query/normal.py index f4b40f408b..161a9e610d 100644 --- a/tests/system-test/2-query/normal.py +++ b/tests/system-test/2-query/normal.py @@ -140,14 +140,14 @@ class TDTestCase: tdsql2 = tdCom.newTdSqlWithTimezone(timezone="UTC") tdsql2.query(f"select * from {dbname}.tzt") tdsql2.checkRows(1) - tdsql2.checkData(0, 0, "2018-09-17 01:00:00") - - + # checkData:The expected date and time is the local time zone of the machine where the test case is executed. + tdsql2.checkData(0, 0, "2018-09-17 09:00:00") + tdsql2.execute(f'insert into {dbname}.tzt values({self.ts + 1000}, 2)') tdsql2.query(f"select * from {dbname}.tzt order by ts") tdsql2.checkRows(2) - tdsql2.checkData(0, 0, "2018-09-17 01:00:00") - tdsql2.checkData(1, 0, "2018-09-17 01:00:01") + tdsql2.checkData(0, 0, "2018-09-17 09:00:00") + tdsql2.checkData(1, 0, "2018-09-17 09:00:01") tdsql2 = tdCom.newTdSqlWithTimezone(timezone="Asia/Shanghai") tdsql2.query(f"select * from {dbname}.tzt order by ts") @@ -160,7 +160,7 @@ class TDTestCase: tdSql.prepare() self.timeZoneTest() - self.inAndNotinTest() + # self.inAndNotinTest() def stop(self): @@ -168,4 +168,5 @@ class TDTestCase: tdLog.success("%s successfully executed" % __file__) tdCases.addWindows(__file__, TDTestCase()) + tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/system-test/7-tmq/tmq_ts-5473.py b/tests/system-test/7-tmq/tmq_ts-5473.py new file mode 100644 index 0000000000..ad08fa559c --- /dev/null +++ b/tests/system-test/7-tmq/tmq_ts-5473.py @@ -0,0 +1,39 @@ + +import taos +import sys +import time +import socket +import os +import threading + +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * +from util.common import * +from taos.tmq import * +sys.path.append("./7-tmq") +from tmqCommon import * + +class TDTestCase: + updatecfgDict = {'debugFlag': 135, 'asynclog': 0} + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) + tdLog.debug(f"start to excute {__file__}") + tdSql.init(conn.cursor()) + #tdSql.init(conn.cursor(), logSql) # output sql.txt file + + def run(self): + buildPath = tdCom.getBuildPath() + cmdStr = '%s/build/bin/tmq_write_raw_test'%(buildPath) + tdLog.info(cmdStr) + os.system(cmdStr) + + return + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index a16a03d30a..3ba6f8521e 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -18,7 +18,7 @@ IF (TD_WEBSOCKET) COMMAND git clean -f -d BUILD_COMMAND COMMAND cargo update - COMMAND RUSTFLAGS=-Ctarget-feature=-crt-static cargo build --release -p taos-ws-sys --features rustls + COMMAND export CFLAGS=-fno-builtin && RUSTFLAGS=-Ctarget-feature=-crt-static cargo build --release -p taos-ws-sys --features rustls INSTALL_COMMAND COMMAND cp target/release/${websocket_lib_file} ${CMAKE_BINARY_DIR}/build/lib COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/build/include @@ -37,7 +37,7 @@ IF (TD_WEBSOCKET) COMMAND git clean -f -d BUILD_COMMAND COMMAND cargo update - COMMAND cargo build --release -p taos-ws-sys --features rustls + COMMAND export CFLAGS=-fno-builtin && cargo build --release -p taos-ws-sys --features rustls INSTALL_COMMAND COMMAND cp target/release/taosws.dll ${CMAKE_BINARY_DIR}/build/lib COMMAND cp target/release/taosws.dll.lib ${CMAKE_BINARY_DIR}/build/lib/taosws.lib @@ -57,7 +57,7 @@ IF (TD_WEBSOCKET) COMMAND git clean -f -d BUILD_COMMAND COMMAND cargo update - COMMAND cargo build --release -p taos-ws-sys --features rustls + COMMAND export CFLAGS=-fno-builtin && cargo build --release -p taos-ws-sys --features rustls INSTALL_COMMAND COMMAND cp target/release/${websocket_lib_file} ${CMAKE_BINARY_DIR}/build/lib COMMAND cmake -E make_directory ${CMAKE_BINARY_DIR}/build/include diff --git a/tools/auto/testCompression/json/d0_10w.csv.zip b/tools/auto/testCompression/json/d0_10w.csv.zip new file mode 100644 index 0000000000..d7dcea6cd5 Binary files /dev/null and b/tools/auto/testCompression/json/d0_10w.csv.zip differ diff --git a/tools/auto/testCompression/json/generate.json b/tools/auto/testCompression/json/generate.json new file mode 100644 index 0000000000..1394dfc28d --- /dev/null +++ b/tools/auto/testCompression/json/generate.json @@ -0,0 +1,64 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "num_of_records_per_req": 500, + "thread_count": 4, + "create_table_thread_count": 1, + "confirm_parameter_prompt": "no", + "databases": [ + { + "dbinfo": { + "name": "test", + "drop": "yes", + "vgroups": 2 + }, + "super_tables": [ + { + "name": "meters", + "child_table_exists": "no", + "childtable_count": 1, + "insert_rows": 100000, + "childtable_prefix": "d", + "insert_mode": "taosc", + "timestamp_step": 1, + "start_timestamp":1700000000000, + "columns": [ + { "type": "bool", "name": "bc"}, + { "type": "float", "name": "fc", "max": 1, "min": 0 }, + { "type": "double", "name": "dc", "max": 1, "min": 0 }, + { "type": "tinyint", "name": "ti", "max": 100, "min": 0 }, + { "type": "smallint", "name": "si", "max": 100, "min": 0 }, + { "type": "int", "name": "ic", "max": 100, "min": 0 }, + { "type": "bigint", "name": "bi", "max": 100, "min": 0 }, + { "type": "utinyint", "name": "uti", "max": 100, "min": 0 }, + { "type": "usmallint", "name": "usi", "max": 100, "min": 0 }, + { "type": "uint", "name": "ui", "max": 100, "min": 0 }, + { "type": "ubigint", "name": "ubi", "max": 100, "min": 0 }, + { "type": "binary", "name": "bin", "len": 32}, + { "type": "nchar", "name": "nch", "len": 64} + ], + "tags": [ + { + "type": "tinyint", + "name": "groupid", + "max": 10, + "min": 1 + }, + { + "name": "location", + "type": "binary", + "len": 16, + "values": ["San Francisco", "Los Angles", "San Diego", + "San Jose", "Palo Alto", "Campbell", "Mountain View", + "Sunnyvale", "Santa Clara", "Cupertino"] + } + ] + } + ] + } + ] +} diff --git a/tools/auto/testCompression/json/template.json b/tools/auto/testCompression/json/template.json new file mode 100644 index 0000000000..1be39d21a1 --- /dev/null +++ b/tools/auto/testCompression/json/template.json @@ -0,0 +1,59 @@ +{ + "filetype": "insert", + "cfgdir": "/etc/taos", + "host": "127.0.0.1", + "port": 6030, + "user": "root", + "password": "taosdata", + "thread_count": 1, + "create_table_thread_count": 1, + "confirm_parameter_prompt": "no", + "num_of_records_per_req": 2000, + "prepared_rand": 100000, + "escape_character": "yes", + "databases": [ + { + "dbinfo": { + "name": "dbrate", + "drop": "yes", + "vgroups": 1, + "stt_trigger": 1, + "wal_retention_size": 1, + "wal_retention_period": 1 + }, + "super_tables": [ + { + "name": "meters", + "child_table_exists": "no", + "childtable_count": 1, + "childtable_prefix": "d", + "data_source": "sample", + "insert_mode": "taosc", + "insert_rows": 100000, + "timestamp_step": 1, + "start_timestamp": "2020-10-01 00:00:00.000", + "sample_file": "./json/d0_10w.csv", + "use_sample_ts": "yes", + "columns": [ + { "type": "bool", "name": "bc", "compress":"@COMPRESS"}, + { "type": "float", "name": "fc", "compress":"@COMPRESS"}, + { "type": "double", "name": "dc", "compress":"@COMPRESS"}, + { "type": "tinyint", "name": "ti", "compress":"@COMPRESS"}, + { "type": "smallint", "name": "si", "compress":"@COMPRESS"}, + { "type": "int", "name": "ic", "compress":"@COMPRESS"}, + { "type": "bigint", "name": "bi", "compress":"@COMPRESS"}, + { "type": "utinyint", "name": "uti","compress":"@COMPRESS"}, + { "type": "usmallint", "name": "usi","compress":"@COMPRESS"}, + { "type": "uint", "name": "ui", "compress":"@COMPRESS"}, + { "type": "ubigint", "name": "ubi","compress":"@COMPRESS"}, + { "type": "binary", "name": "bin", "len": 32, "compress":"@COMPRESS"}, + { "type": "nchar", "name": "nch", "len": 64, "compress":"@COMPRESS"} + ], + "tags": [ + {"type": "TINYINT", "name": "groupid", "max": 10, "min": 1} + ] + } + ] + } + ] +} diff --git a/tools/auto/testCompression/testCompression.py b/tools/auto/testCompression/testCompression.py new file mode 100644 index 0000000000..768fa87f71 --- /dev/null +++ b/tools/auto/testCompression/testCompression.py @@ -0,0 +1,297 @@ +import taos +import sys +import os +import subprocess +import time +import random +import json +from datetime import datetime + + +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- +dataDir = "/var/lib/taos/" +templateFile = "json/template.json" +Number = 0 +resultContext = "" + + +def showLog(str): + print(str) + +def exec(command, show=True): + if(show): + print(f"exec {command}\n") + return os.system(command) + +# run return output and error +def run(command, timeout = 60, show=True): + if(show): + print(f"run {command} timeout={timeout}s\n") + + process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process.wait(timeout) + + output = process.stdout.read().decode(encoding="gbk") + error = process.stderr.read().decode(encoding="gbk") + + return output, error + +# return list after run +def runRetList(command, timeout=10): + output,error = run(command, timeout) + return output.splitlines() + +def readFileContext(filename): + file = open(filename) + context = file.read() + file.close() + return context + + +def writeFileContext(filename, context): + file = open(filename, "w") + file.write(context) + file.close() + +def appendFileContext(filename, context): + global resultContext + resultContext += context + try: + file = open(filename, "a") + wsize = file.write(context) + file.close() + except: + print(f"appand file error context={context} .") + +def getFolderSize(folder): + total_size = 0 + for dirpath, dirnames, filenames in os.walk(folder): + for filename in filenames: + filepath = os.path.join(dirpath, filename) + total_size += os.path.getsize(filepath) + return total_size + +def waitClusterAlive(loop): + for i in range(loop): + command = 'taos -s "show cluster alive\G;" ' + out,err = run(command) + print(out) + if out.find("status: 1") >= 0: + showLog(f" i={i} wait cluster alive ok.\n") + return True + + showLog(f" i={i} wait cluster alive ...\n") + time.sleep(1) + + showLog(f" i={i} wait cluster alive failed.\n") + return False + +def waitCompactFinish(loop): + for i in range(loop): + command = 'taos -s "show compacts;" ' + out,err = run(command) + if out.find("Query OK, 0 row(s) in set") >= 0: + showLog(f" i={i} wait compact finish ok\n") + return True + + showLog(f" i={i} wait compact ...\n") + time.sleep(1) + + showLog(f" i={i} wait compact failed.\n") + return False + + +def getTypeName(datatype): + str1 = datatype.split(",")[0] + str2 = str1.split(":")[1] + str3 = str2.replace('"','').replace(' ','') + return str3 + + +def getMatch(datatype, algo): + if algo == "tsz": + if datatype == "float" or datatype == "double": + return True + else: + return False + else: + return True + + +def generateJsonFile(algo): + print(f"doTest algo: {algo} \n") + + # replace datatype + context = readFileContext(templateFile) + # replace compress + context = context.replace("@COMPRESS", algo) + + # write to file + fileName = f"json/test_{algo}.json" + if os.path.exists(fileName): + os.remove(fileName) + writeFileContext(fileName, context) + + return fileName + +def taosdStart(): + cmd = "nohup /usr/bin/taosd 2>&1 & " + ret = exec(cmd) + print(f"exec taosd ret = {ret}\n") + time.sleep(3) + waitClusterAlive(10) + +def taosdStop(): + i = 1 + toBeKilled = "taosd" + killCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}' | xargs kill -TERM > /dev/null 2>&1" % toBeKilled + psCmd = "ps -ef|grep -w %s| grep -v grep | awk '{print $2}'" % toBeKilled + processID = subprocess.check_output(psCmd, shell=True) + while(processID): + os.system(killCmd) + time.sleep(1) + processID = subprocess.check_output(psCmd, shell=True) + print(f"i={i} kill taosd pid={processID}") + i += 1 + +def cleanAndStartTaosd(): + + # stop + taosdStop() + # clean + exec(f"rm -rf {dataDir}") + # start + taosdStart() + +def findContextValue(context, label): + start = context.find(label) + if start == -1 : + return "" + start += len(label) + 2 + # skip blank + while context[start] == ' ': + start += 1 + + # find end ',' + end = start + ends = [',','}',']', 0] + while context[end] not in ends: + end += 1 + + print(f"start = {start} end={end}\n") + return context[start:end] + + +def writeTemplateInfo(resultFile): + # create info + context = readFileContext(templateFile) + vgroups = findContextValue(context, "vgroups") + childCount = findContextValue(context, "childtable_count") + insertRows = findContextValue(context, "insert_rows") + line = f"vgroups = {vgroups}\nchildtable_count = {childCount}\ninsert_rows = {insertRows}\n\n" + print(line) + appendFileContext(resultFile, line) + + +def totalCompressRate(algo, resultFile, writeSecond): + global Number + # flush + command = 'taos -s "flush database dbrate;"' + rets = exec(command) + command = 'taos -s "compact database dbrate;"' + rets = exec(command) + waitCompactFinish(60) + + # read compress rate + command = 'taos -s "show table distributed dbrate.meters\G;"' + rets = runRetList(command) + print(rets) + + str1 = rets[5] + arr = str1.split(" ") + + # Total_Size KB + str2 = arr[2] + pos = str2.find("=[") + totalSize = int(float(str2[pos+2:])/1024) + + # Compression_Ratio + str2 = arr[6] + pos = str2.find("=[") + rate = str2[pos+2:] + print("rate =" + rate) + + # total data file size + #dataSize = getFolderSize(f"{dataDir}/vnode/") + #dataSizeMB = int(dataSize/1024/1024) + + # appand to file + + Number += 1 + context = "%10s %10s %10s %10s %10s\n"%( Number, algo, str(totalSize)+" MB", rate+"%", writeSecond + " s") + showLog(context) + appendFileContext(resultFile, context) + + +def doTest(algo, resultFile): + print(f"doTest algo: {algo} \n") + #cleanAndStartTaosd() + + + # json + jsonFile = generateJsonFile(algo) + + # run taosBenchmark + t1 = time.time() + exec(f"taosBenchmark -f {jsonFile}") + t2 = time.time() + + # total compress rate + totalCompressRate(algo, resultFile, str(int(t2-t1))) + +def main(): + + # test compress method + algos = ["lz4", "zlib", "zstd", "xz", "disabled"] + + # record result + resultFile = "./result.txt" + timestamp = time.time() + now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp)) + context = f"\n---------------------- test rate ({now}) ---------------------------------\n" + + appendFileContext(resultFile, context) + # json info + writeTemplateInfo(resultFile) + # head + context = "\n%10s %10s %10s %10s %10s\n"%("No", "compress", "dataSize", "rate", "insertSeconds") + appendFileContext(resultFile, context) + + + # loop for all compression + for algo in algos: + # do test + doTest(algo, resultFile) + appendFileContext(resultFile, " \n") + + timestamp = time.time() + now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp)) + appendFileContext(resultFile, f"\n{now} finished test!\n") + + +if __name__ == "__main__": + print("welcome use TDengine compress rate test tools.\n") + main() + # show result + print(resultContext) \ No newline at end of file diff --git a/tools/shell/src/shellNettest.c b/tools/shell/src/shellNettest.c index 9fe92212ca..2e5ec7bc24 100644 --- a/tools/shell/src/shellNettest.c +++ b/tools/shell/src/shellNettest.c @@ -61,7 +61,7 @@ static void shellWorkAsClient() { uint64_t startTime = taosGetTimestampUs(); for (int32_t i = 0; i < pArgs->pktNum; ++i) { - SRpcMsg rpcMsg = {.info.ahandle = (void *)0x9525, .msgType = TDMT_DND_NET_TEST}; + SRpcMsg rpcMsg = {.info.ahandle = (void *)0x9525, .info.notFreeAhandle = 1, .msgType = TDMT_DND_NET_TEST}; rpcMsg.pCont = rpcMallocCont(pArgs->pktLen); rpcMsg.contLen = pArgs->pktLen; diff --git a/tools/shell/src/shellWebsocket.c b/tools/shell/src/shellWebsocket.c index fc7c914c21..1ec1697c3a 100644 --- a/tools/shell/src/shellWebsocket.c +++ b/tools/shell/src/shellWebsocket.c @@ -34,10 +34,10 @@ int shell_conn_ws_server(bool first) { size_t len = strlen(shell.args.dsn); char * dsn = taosMemoryMalloc(len + 32); sprintf(dsn, "%s&conn_mode=1", shell.args.dsn); - shell.ws_conn = ws_connect_with_dsn(dsn); + shell.ws_conn = ws_connect(dsn); taosMemoryFree(dsn); } else { - shell.ws_conn = ws_connect_with_dsn(shell.args.dsn); + shell.ws_conn = ws_connect(shell.args.dsn); } if (NULL == shell.ws_conn) { @@ -95,7 +95,7 @@ int shell_conn_ws_server(bool first) { static int horizontalPrintWebsocket(WS_RES* wres, double* execute_time) { const void* data = NULL; int rows; - ws_fetch_block(wres, &data, &rows); + ws_fetch_raw_block(wres, &data, &rows); if (wres) { *execute_time += (double)(ws_take_timing(wres)/1E6); } @@ -129,7 +129,7 @@ static int horizontalPrintWebsocket(WS_RES* wres, double* execute_time) { putchar('\n'); } numOfRows += rows; - ws_fetch_block(wres, &data, &rows); + ws_fetch_raw_block(wres, &data, &rows); } while (rows && !shell.stop_query); return numOfRows; } @@ -137,7 +137,7 @@ static int horizontalPrintWebsocket(WS_RES* wres, double* execute_time) { static int verticalPrintWebsocket(WS_RES* wres, double* pexecute_time) { int rows = 0; const void* data = NULL; - ws_fetch_block(wres, &data, &rows); + ws_fetch_raw_block(wres, &data, &rows); if (wres) { *pexecute_time += (double)(ws_take_timing(wres)/1E6); } @@ -172,7 +172,7 @@ static int verticalPrintWebsocket(WS_RES* wres, double* pexecute_time) { } numOfRows++; } - ws_fetch_block(wres, &data, &rows); + ws_fetch_raw_block(wres, &data, &rows); } while (rows && !shell.stop_query); return numOfRows; } @@ -192,7 +192,7 @@ static int dumpWebsocketToFile(const char* fname, WS_RES* wres, } int rows = 0; const void* data = NULL; - ws_fetch_block(wres, &data, &rows); + ws_fetch_raw_block(wres, &data, &rows); if (wres) { *pexecute_time += (double)(ws_take_timing(wres)/1E6); } @@ -226,7 +226,7 @@ static int dumpWebsocketToFile(const char* fname, WS_RES* wres, } taosFprintfFile(pFile, "\r\n"); } - ws_fetch_block(wres, &data, &rows); + ws_fetch_raw_block(wres, &data, &rows); } while (rows && !shell.stop_query); taosCloseFile(&pFile); return numOfRows; diff --git a/utils/test/c/CMakeLists.txt b/utils/test/c/CMakeLists.txt index e5902856e6..4eac64ac85 100644 --- a/utils/test/c/CMakeLists.txt +++ b/utils/test/c/CMakeLists.txt @@ -3,6 +3,7 @@ add_dependencies(tmq_demo taos) add_executable(tmq_sim tmqSim.c) add_executable(create_table createTable.c) add_executable(tmq_taosx_ci tmq_taosx_ci.c) +add_executable(tmq_write_raw_test tmq_write_raw_test.c) add_executable(write_raw_block_test write_raw_block_test.c) add_executable(sml_test sml_test.c) add_executable(get_db_name_test get_db_name_test.c) @@ -69,11 +70,11 @@ target_link_libraries( ) target_link_libraries( - replay_test - PUBLIC taos - PUBLIC util - PUBLIC common - PUBLIC os + replay_test + PUBLIC taos + PUBLIC util + PUBLIC common + PUBLIC os ) target_link_libraries( @@ -84,6 +85,14 @@ target_link_libraries( PUBLIC os ) +target_link_libraries( + tmq_write_raw_test + PUBLIC taos + PUBLIC util + PUBLIC common + PUBLIC os +) + target_link_libraries( sml_test PUBLIC taos diff --git a/utils/test/c/tmq_write_raw_test.c b/utils/test/c/tmq_write_raw_test.c new file mode 100644 index 0000000000..f33fac9a0a --- /dev/null +++ b/utils/test/c/tmq_write_raw_test.c @@ -0,0 +1,281 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include "cJSON.h" +#include "taos.h" +#include "tmsg.h" +#include "types.h" + +static TAOS* use_db() { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + if (pConn == NULL) { + return NULL; + } + + TAOS_RES* pRes = taos_query(pConn, "use db_taosx"); + if (taos_errno(pRes) != 0) { + printf("error in use db_taosx, reason:%s\n", taos_errstr(pRes)); + return NULL; + } + taos_free_result(pRes); + return pConn; +} + +static void msg_process(TAOS_RES* msg) { + printf("-----------topic-------------: %s\n", tmq_get_topic_name(msg)); + printf("db: %s\n", tmq_get_db_name(msg)); + printf("vg: %d\n", tmq_get_vgroup_id(msg)); + TAOS* pConn = use_db(); + if (tmq_get_res_type(msg) == TMQ_RES_TABLE_META || tmq_get_res_type(msg) == TMQ_RES_METADATA) { + char* result = tmq_get_json_meta(msg); + printf("meta result: %s\n", result); + tmq_free_json_meta(result); + } + + tmq_raw_data raw = {0}; + tmq_get_raw(msg, &raw); + printf("write raw data type: %d\n", raw.raw_type); + int32_t ret = tmq_write_raw(pConn, raw); + printf("write raw data: %s\n", tmq_err2str(ret)); + ASSERT(ret == 0); + + tmq_free_raw(raw); + taos_close(pConn); +} + +int buildDatabase(TAOS* pConn, TAOS_RES* pRes) { + pRes = taos_query(pConn, + "create stable if not exists st1 (ts timestamp, c1 int, c2 float, c3 binary(16)) tags(t1 int, t3 " + "nchar(8), t4 bool)"); + if (taos_errno(pRes) != 0) { + printf("failed to create super table st1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table if not exists ct0 using st1 tags(1000, \"ttt\", true)"); + if (taos_errno(pRes) != 0) { + printf("failed to create child table tu1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "insert into ct0 using st1 tags(1000, \"ttt\", true) values(1626006833400, 1, 2, 'a')"); + if (taos_errno(pRes) != 0) { + printf("failed to insert into ct0, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table if not exists ct1 using st1(t1) tags(2000)"); + if (taos_errno(pRes) != 0) { + printf("failed to create child table ct1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table if not exists ct2 using st1(t1) tags(NULL)"); + if (taos_errno(pRes) != 0) { + printf("failed to create child table ct2, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "insert into ct1 using st1(t1) tags(2000) values(1626006833600, 3, 4, 'b')"); + if (taos_errno(pRes) != 0) { + printf("failed to insert into ct1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create table if not exists ct3 using st1(t1) tags(3000)"); + if (taos_errno(pRes) != 0) { + printf("failed to create child table ct3, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "insert into ct0 using st1 tags(1000, \"ttt\", true) values(1626006833400, 1, 2, 'a')"); + if (taos_errno(pRes) != 0) { + printf("failed to insert into ct0, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "insert into ct1 using st1(t1) tags(2000) values(1626006833600, 3, 4, 'b')"); + if (taos_errno(pRes) != 0) { + printf("failed to insert into ct1, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query( + pConn, + "insert into ct3 using st1(t1) tags(3000) values(1626006833600, 5, 6, 'c') ct1 using st1(t1) tags(2000) values(1626006833601, 2, 3, 'sds') (1626006833602, 4, 5, " + "'ddd') ct0 using st1 tags(1000, \"ttt\", true) values(1626006833603, 4, 3, 'hwj') ct1 using st1(t1) tags(2000) values(now+5s, 23, 32, 's21ds')"); + if (taos_errno(pRes) != 0) { + printf("failed to insert into ct3, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + return 0; +} + +int32_t init_env() { + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + if (pConn == NULL) { + return -1; + } + + TAOS_RES* pRes = taos_query(pConn, "drop database if exists db_taosx"); + if (taos_errno(pRes) != 0) { + printf("error in drop db_taosx, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create database if not exists db_taosx vgroups 1 wal_retention_period 3600"); + if (taos_errno(pRes) != 0) { + printf("error in create db_taosx, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "drop topic if exists topic_db"); + if (taos_errno(pRes) != 0) { + printf("error in drop topic, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "drop database if exists abc1"); + if (taos_errno(pRes) != 0) { + printf("error in drop db, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "create database if not exists abc1 vgroups 1 wal_retention_period 3600"); + if (taos_errno(pRes) != 0) { + printf("error in create db, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + pRes = taos_query(pConn, "use abc1"); + if (taos_errno(pRes) != 0) { + printf("error in use db, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + buildDatabase(pConn, pRes); + + taos_close(pConn); + return 0; +} + +int32_t create_topic() { + printf("create topic\n"); + TAOS_RES* pRes; + TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0); + if (pConn == NULL) { + return -1; + } + + pRes = taos_query(pConn, "create topic topic_db with meta as database abc1"); + if (taos_errno(pRes) != 0) { + printf("failed to create topic topic_db, reason:%s\n", taos_errstr(pRes)); + return -1; + } + taos_free_result(pRes); + + taos_close(pConn); + return 0; +} + +void tmq_commit_cb_print(tmq_t* tmq, int32_t code, void* param) { + printf("commit %d tmq %p param %p\n", code, tmq, param); +} + +tmq_t* build_consumer() { + tmq_conf_t* conf = tmq_conf_new(); + tmq_conf_set(conf, "group.id", "tg2"); + tmq_conf_set(conf, "client.id", "my app 1"); + tmq_conf_set(conf, "td.connect.user", "root"); + tmq_conf_set(conf, "td.connect.pass", "taosdata"); + tmq_conf_set(conf, "msg.with.table.name", "true"); + tmq_conf_set(conf, "enable.auto.commit", "true"); + tmq_conf_set(conf, "auto.offset.reset", "earliest"); + tmq_conf_set(conf, "msg.consume.excluded", "1"); +// tmq_conf_set(conf, "max.poll.interval.ms", "20000"); + + tmq_conf_set_auto_commit_cb(conf, tmq_commit_cb_print, NULL); + tmq_t* tmq = tmq_consumer_new(conf, NULL, 0); + assert(tmq); + tmq_conf_destroy(conf); + return tmq; +} + +tmq_list_t* build_topic_list() { + tmq_list_t* topic_list = tmq_list_new(); + tmq_list_append(topic_list, "topic_db"); + return topic_list; +} + +void basic_consume_loop(tmq_t* tmq, tmq_list_t* topics) { + int32_t code; + + if ((code = tmq_subscribe(tmq, topics))) { + fprintf(stderr, "%% Failed to start consuming topics: %s\n", tmq_err2str(code)); + printf("subscribe err\n"); + return; + } + int32_t cnt = 0; + while (1) { + TAOS_RES* tmqmessage = tmq_consumer_poll(tmq, 5000); + if (tmqmessage) { + cnt++; + msg_process(tmqmessage); + taos_free_result(tmqmessage); + } else { + break; + } + } + + code = tmq_consumer_close(tmq); + if (code) + fprintf(stderr, "%% Failed to close consumer: %s\n", tmq_err2str(code)); + else + fprintf(stderr, "%% Consumer closed\n"); +} + +int main(int argc, char* argv[]) { + if (init_env() < 0) { + return -1; + } + create_topic(); + + tmq_t* tmq = build_consumer(); + tmq_list_t* topic_list = build_topic_list(); + basic_consume_loop(tmq, topic_list); + tmq_list_destroy(topic_list); +}