[ 
https://issues.apache.org/jira/browse/IGNITE-19247?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Alexander Belyak updated IGNITE-19247:
--------------------------------------
    Description: 
Code below just create TABLES tables with COLUMNS+1 columns and insert ROWS 
rows into each table (with SLEEP ms interval between operations).

Simple example:
{code:java}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class TimeoutExceptionReproducer {
    private static final String DB_URL = "jdbc:ignite:thin://172.24.1.2:10800";
    private static final int COLUMNS = 10;

    private static final String TABLE_NAME = "K";
    private static final int ROWS = 10;

    private static final int TABLES = 10;

    private static final int BATCH_SIZE = 10;

    private static final int SLEEP = 30;

    private static String getCreateSql(String tableName) {
        StringBuilder sql = new StringBuilder("create table 
").append(tableName).append(" (id int primary key");

        for (int i = 0; i < COLUMNS; i++) {
            sql.append(", col").append(i).append(" varchar NOT NULL");
        }

        sql.append(")");

        return sql.toString();
    }

    private static final void s() {
        try {
            Thread.sleep(SLEEP);
        } catch (InterruptedException e) {
            // NoOp
        }
    }

    private static void createTables(Connection connection, String tableName) 
throws SQLException {
        try (Statement stmt = connection.createStatement()) {
            System.out.println("Creating " + tableName);

            stmt.executeUpdate("drop table if exists " + tableName );
            s();
            stmt.executeUpdate(getCreateSql(tableName));
            s();
        }
    }

    private static String getInsertSql(String tableName) {
        StringBuilder sql = new StringBuilder("insert into 
").append(tableName).append(" values(?");

        for (int i = 0; i < COLUMNS; i++) {
            sql.append(", ?");
        }

        sql.append(")");

        return sql.toString();
    }

    private static void insertData(Connection connection, String tableName) 
throws SQLException {
        long ts = System.currentTimeMillis();
        try (PreparedStatement ps = 
connection.prepareStatement(getInsertSql(tableName))) {
            int batch = 0;

            for (int i = 0; i < ROWS; i++) {
                ps.setInt(1, i);

                for (int j = 2; j < COLUMNS + 2; j++) {
                    ps.setString(j, "value" + i + "_" + j);
                }

                ps.addBatch();
                batch++;

                if (batch == BATCH_SIZE) {
                    batch = 0;
                    ps.executeBatch();
                    ps.clearBatch();

                    System.out.println("Batch " + BATCH_SIZE + " took " + 
(System.currentTimeMillis() - ts) + " to get " + i + " rows");

                    s();
                    ts = System.currentTimeMillis();
                }
            }

            if (batch > 0) {
                batch = 0;
                ps.executeBatch();
                ps.clearBatch();
                s();
            }
        }
    }

    private static int testData(Connection connection, String tableName) throws 
SQLException {
        try (Statement stmt = connection.createStatement();
            ResultSet rs = stmt.executeQuery("select count(*) from " + 
tableName);) {
            rs.next();

            int count = rs.getInt(1);

            int result = ROWS - count;

            if (result == 0) {
                System.out.println("Found " + count + " rows in " + tableName);
            } else {
                System.err.println("Found " + count + " rows in " + tableName + 
" instead of " + ROWS);
            }

            return result;
        }
    }

    public static void main(String[] args) throws SQLException {
        int lostRows = 0;
        try (Connection connection = DriverManager.getConnection(DB_URL)) {
            for (int i = 0; i < TABLES; i++) {
                String tableName = TABLE_NAME + i;
                createTables(connection, tableName);

                insertData(connection, tableName);

                lostRows += testData(connection, tableName);
            }
        }

        System.exit(lostRows);
    }
}
   {code}
lead to timeout exception:
{code:java}
Batch 100 took 4228 to get 2899 rows
Batch 100 took 5669 to get 2999 rows
Batch 100 took 3902 to get 3099 rows
Exception in thread "main" java.sql.BatchUpdateException: IGN-REP-3 
TraceId:b2c2c9e5-b917-482e-91df-2e0576c443c7 Replication is timed out 
[replicaGrpId=76c2b69a-a2bc-4d16-838d-5aff014c6004_part_11]
    at 
org.apache.ignite.internal.jdbc.JdbcPreparedStatement.executeBatch(JdbcPreparedStatement.java:124)
    at TimeoutExceptionReproducer.insertData(TimeoutExceptionReproducer.java:64)
    at TimeoutExceptionReproducer.main(TimeoutExceptionReproducer.java:84){code}

  was:
Code below just create 1000 tables with 101 columns and insert 1000 rows into 
each table.

Simple example:
{code:java}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class TimeoutExceptionReproducer {
    private static final String DB_URL = "jdbc:ignite:thin://172.24.1.2:10800";
    private static final int COLUMNS = 10;

    private static final String TABLE_NAME = "K";
    private static final int ROWS = 10;

    private static final int TABLES = 10;

    private static final int BATCH_SIZE = 10;

    private static final int SLEEP = 30;

    private static String getCreateSql(String tableName) {
        StringBuilder sql = new StringBuilder("create table 
").append(tableName).append(" (id int primary key");

        for (int i = 0; i < COLUMNS; i++) {
            sql.append(", col").append(i).append(" varchar NOT NULL");
        }

        sql.append(")");

        return sql.toString();
    }

    private static final void s() {
        try {
            Thread.sleep(SLEEP);
        } catch (InterruptedException e) {
            // NoOp
        }
    }

    private static void createTables(Connection connection, String tableName) 
throws SQLException {
        try (Statement stmt = connection.createStatement()) {
            System.out.println("Creating " + tableName);

            stmt.executeUpdate("drop table if exists " + tableName );
            s();
            stmt.executeUpdate(getCreateSql(tableName));
            s();
        }
    }

    private static String getInsertSql(String tableName) {
        StringBuilder sql = new StringBuilder("insert into 
").append(tableName).append(" values(?");

        for (int i = 0; i < COLUMNS; i++) {
            sql.append(", ?");
        }

        sql.append(")");

        return sql.toString();
    }

    private static void insertData(Connection connection, String tableName) 
throws SQLException {
        long ts = System.currentTimeMillis();
        try (PreparedStatement ps = 
connection.prepareStatement(getInsertSql(tableName))) {
            int batch = 0;

            for (int i = 0; i < ROWS; i++) {
                ps.setInt(1, i);

                for (int j = 2; j < COLUMNS + 2; j++) {
                    ps.setString(j, "value" + i + "_" + j);
                }

                ps.addBatch();
                batch++;

                if (batch == BATCH_SIZE) {
                    batch = 0;
                    ps.executeBatch();
                    ps.clearBatch();

                    System.out.println("Batch " + BATCH_SIZE + " took " + 
(System.currentTimeMillis() - ts) + " to get " + i + " rows");

                    s();
                    ts = System.currentTimeMillis();
                }
            }

            if (batch > 0) {
                batch = 0;
                ps.executeBatch();
                ps.clearBatch();
                s();
            }
        }
    }

    private static int testData(Connection connection, String tableName) throws 
SQLException {
        try (Statement stmt = connection.createStatement();
            ResultSet rs = stmt.executeQuery("select count(*) from " + 
tableName);) {
            rs.next();

            int count = rs.getInt(1);

            int result = ROWS - count;

            if (result == 0) {
                System.out.println("Found " + count + " rows in " + tableName);
            } else {
                System.err.println("Found " + count + " rows in " + tableName + 
" instead of " + ROWS);
            }

            return result;
        }
    }

    public static void main(String[] args) throws SQLException {
        int lostRows = 0;
        try (Connection connection = DriverManager.getConnection(DB_URL)) {
            for (int i = 0; i < TABLES; i++) {
                String tableName = TABLE_NAME + i;
                createTables(connection, tableName);

                insertData(connection, tableName);

                lostRows += testData(connection, tableName);
            }
        }

        System.exit(lostRows);
    }
}
   {code}
lead to timeout exception:
{code:java}
Batch 100 took 4228 to get 2899 rows
Batch 100 took 5669 to get 2999 rows
Batch 100 took 3902 to get 3099 rows
Exception in thread "main" java.sql.BatchUpdateException: IGN-REP-3 
TraceId:b2c2c9e5-b917-482e-91df-2e0576c443c7 Replication is timed out 
[replicaGrpId=76c2b69a-a2bc-4d16-838d-5aff014c6004_part_11]
    at 
org.apache.ignite.internal.jdbc.JdbcPreparedStatement.executeBatch(JdbcPreparedStatement.java:124)
    at TimeoutExceptionReproducer.insertData(TimeoutExceptionReproducer.java:64)
    at TimeoutExceptionReproducer.main(TimeoutExceptionReproducer.java:84){code}


> Replication is timed out
> ------------------------
>
>                 Key: IGNITE-19247
>                 URL: https://issues.apache.org/jira/browse/IGNITE-19247
>             Project: Ignite
>          Issue Type: Bug
>          Components: general
>    Affects Versions: 3.0
>            Reporter: Alexander Belyak
>            Priority: Critical
>              Labels: ignite-3
>             Fix For: 3.0
>
>
> Code below just create TABLES tables with COLUMNS+1 columns and insert ROWS 
> rows into each table (with SLEEP ms interval between operations).
> Simple example:
> {code:java}
> import java.sql.Connection;
> import java.sql.DriverManager;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.SQLException;
> import java.sql.Statement;
> public class TimeoutExceptionReproducer {
>     private static final String DB_URL = 
> "jdbc:ignite:thin://172.24.1.2:10800";
>     private static final int COLUMNS = 10;
>     private static final String TABLE_NAME = "K";
>     private static final int ROWS = 10;
>     private static final int TABLES = 10;
>     private static final int BATCH_SIZE = 10;
>     private static final int SLEEP = 30;
>     private static String getCreateSql(String tableName) {
>         StringBuilder sql = new StringBuilder("create table 
> ").append(tableName).append(" (id int primary key");
>         for (int i = 0; i < COLUMNS; i++) {
>             sql.append(", col").append(i).append(" varchar NOT NULL");
>         }
>         sql.append(")");
>         return sql.toString();
>     }
>     private static final void s() {
>         try {
>             Thread.sleep(SLEEP);
>         } catch (InterruptedException e) {
>             // NoOp
>         }
>     }
>     private static void createTables(Connection connection, String tableName) 
> throws SQLException {
>         try (Statement stmt = connection.createStatement()) {
>             System.out.println("Creating " + tableName);
>             stmt.executeUpdate("drop table if exists " + tableName );
>             s();
>             stmt.executeUpdate(getCreateSql(tableName));
>             s();
>         }
>     }
>     private static String getInsertSql(String tableName) {
>         StringBuilder sql = new StringBuilder("insert into 
> ").append(tableName).append(" values(?");
>         for (int i = 0; i < COLUMNS; i++) {
>             sql.append(", ?");
>         }
>         sql.append(")");
>         return sql.toString();
>     }
>     private static void insertData(Connection connection, String tableName) 
> throws SQLException {
>         long ts = System.currentTimeMillis();
>         try (PreparedStatement ps = 
> connection.prepareStatement(getInsertSql(tableName))) {
>             int batch = 0;
>             for (int i = 0; i < ROWS; i++) {
>                 ps.setInt(1, i);
>                 for (int j = 2; j < COLUMNS + 2; j++) {
>                     ps.setString(j, "value" + i + "_" + j);
>                 }
>                 ps.addBatch();
>                 batch++;
>                 if (batch == BATCH_SIZE) {
>                     batch = 0;
>                     ps.executeBatch();
>                     ps.clearBatch();
>                     System.out.println("Batch " + BATCH_SIZE + " took " + 
> (System.currentTimeMillis() - ts) + " to get " + i + " rows");
>                     s();
>                     ts = System.currentTimeMillis();
>                 }
>             }
>             if (batch > 0) {
>                 batch = 0;
>                 ps.executeBatch();
>                 ps.clearBatch();
>                 s();
>             }
>         }
>     }
>     private static int testData(Connection connection, String tableName) 
> throws SQLException {
>         try (Statement stmt = connection.createStatement();
>             ResultSet rs = stmt.executeQuery("select count(*) from " + 
> tableName);) {
>             rs.next();
>             int count = rs.getInt(1);
>             int result = ROWS - count;
>             if (result == 0) {
>                 System.out.println("Found " + count + " rows in " + 
> tableName);
>             } else {
>                 System.err.println("Found " + count + " rows in " + tableName 
> + " instead of " + ROWS);
>             }
>             return result;
>         }
>     }
>     public static void main(String[] args) throws SQLException {
>         int lostRows = 0;
>         try (Connection connection = DriverManager.getConnection(DB_URL)) {
>             for (int i = 0; i < TABLES; i++) {
>                 String tableName = TABLE_NAME + i;
>                 createTables(connection, tableName);
>                 insertData(connection, tableName);
>                 lostRows += testData(connection, tableName);
>             }
>         }
>         System.exit(lostRows);
>     }
> }
>    {code}
> lead to timeout exception:
> {code:java}
> Batch 100 took 4228 to get 2899 rows
> Batch 100 took 5669 to get 2999 rows
> Batch 100 took 3902 to get 3099 rows
> Exception in thread "main" java.sql.BatchUpdateException: IGN-REP-3 
> TraceId:b2c2c9e5-b917-482e-91df-2e0576c443c7 Replication is timed out 
> [replicaGrpId=76c2b69a-a2bc-4d16-838d-5aff014c6004_part_11]
>     at 
> org.apache.ignite.internal.jdbc.JdbcPreparedStatement.executeBatch(JdbcPreparedStatement.java:124)
>     at 
> TimeoutExceptionReproducer.insertData(TimeoutExceptionReproducer.java:64)
>     at 
> TimeoutExceptionReproducer.main(TimeoutExceptionReproducer.java:84){code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to