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

Alexander Belyak updated IGNITE-19247:
--------------------------------------
    Description: 
Simple example:
{code:java}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
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 = 100;

    private static final String TABLE_NAME = "t1";
    private static final int ROWS = 1000;

    private static final int TABLES = 1000;

    private static final int BATCH_SIZE = 100;

    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 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 );
            stmt.executeUpdate(getCreateSql(tableName));
        }
    }

    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();
                    long nextTs = System.currentTimeMillis();
                    System.out.println("Batch " + BATCH_SIZE + " took " + 
(nextTs - ts) + " to get " + i + " rows");
                    ts = nextTs;
                }
            }

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

    public static void main(String[] args) throws SQLException {
        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);
            }
        }
    }
}
  {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
>
>
> Simple example:
> {code:java}
> import java.sql.Connection;
> import java.sql.DriverManager;
> import java.sql.PreparedStatement;
> 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 = 100;
>     private static final String TABLE_NAME = "t1";
>     private static final int ROWS = 1000;
>     private static final int TABLES = 1000;
>     private static final int BATCH_SIZE = 100;
>     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 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 );
>             stmt.executeUpdate(getCreateSql(tableName));
>         }
>     }
>     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();
>                     long nextTs = System.currentTimeMillis();
>                     System.out.println("Batch " + BATCH_SIZE + " took " + 
> (nextTs - ts) + " to get " + i + " rows");
>                     ts = nextTs;
>                 }
>             }
>             if (batch > 0) {
>                 batch = 0;
>                 ps.executeBatch();
>                 ps.clearBatch();
>             }
>         }
>     }
>     public static void main(String[] args) throws SQLException {
>         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);
>             }
>         }
>     }
> }
>   {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