[
https://issues.apache.org/jira/browse/IGNITE-19247?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Alexander Belyak updated IGNITE-19247:
--------------------------------------
Summary: BatchUpdateException: Replication is timed out" upon inserting
rows in batches via JDBC (was: Replication is timed out)
> BatchUpdateException: Replication is timed out" upon inserting rows in
> batches via JDBC
> ---------------------------------------------------------------------------------------
>
> 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
>
> Attachments: node_0.log.zip, node_1.log.zip, test.log
>
>
> This is very basic acceptance test.
> Code below just create <TABLES> tables with <COLUMNS+1> columns (int key and
> varchar cols) and insert <ROWS> rows into each table (with SLEEP ms interval
> between operations, with <RETRY> attemps.
>
> {noformat}
> 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 = 1000;
> private static final int TABLES = 10;
> private static final int BATCH_SIZE = 10;
> private static final int SLEEP = 30;
> private static final int RETRY = 10;
> 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() {
> if (SLEEP > 0) {
> 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 insertBatch(PreparedStatement ps) {
> int retryCounter = 0;
> while(retryCounter <= RETRY) {
> try {
> ps.executeBatch();
> return;
> } catch (SQLException e) {
> System.err.println(retryCounter + " error while executing " +
> ps + ":" + e);
> retryCounter++;
> }
> }
> }
> 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;
> insertBatch(ps);
> ps.clearBatch();
> System.out.println("Batch " + BATCH_SIZE + " took " +
> (System.currentTimeMillis() - ts) + " to get " + i + " rows");
> s();
> ts = System.currentTimeMillis();
> }
> }
> if (batch > 0) {
> insertBatch(ps);
> 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);
> }
> s();
> 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);
> }
> }
> {noformat}
> And we can see some problems, like:
> 1) Replication timeout exception
> 2) Data loss
> even if there are only one node in the cluster, small number of columns,
> tables and rows and huge sleep between operations.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)