Jira Link: DB-5194


When we create an index on a table, the index backfill process starts to populate the data in the index. This happens asynchronously and can also update the schema version of the table.

If the schema version is bumped in the middle of the execution of a PreparedStatement, it can lead to schema mismatched errors.

Example test that reproduces this issue:

// Create a table with a large number of tablets so that index backfill takes time (even though the table is empty).
        "CREATE TABLE test_table (h INT PRIMARY KEY, a int, b varchar) WITH tablets = 100 AND default_time_to_live = 0 AND transactions = {'enabled': 'true'};");
session.execute("CREATE INDEX test_index_ab ON test_table (a) include (b);");

// If we sleep for 10 seconds, then the test passes 10/10 times, otherwise it fails 3/10 times.

// Insert 15 rows of data.
for (int i = 0; i < 15; i++) {
  String.format("INSERT INTO test_table (h, a, b) VALUES (%d, 10, 'varstr%d')", i, i));

// This query can fail sometimes due to the bump in the schema version
PreparedStatement prepared =
          session.prepare(new SimpleStatement("SELECT a, b FROM test_table WHERE a = 10"));

Not sure what the potential solutions are for this. May be if the new schema after the backfill is compatible with the initial schema, then #15805 could help.

© 2022 pullanswer.com - All rights reserved.