Source:
public void testSnapshotWithMetadataConcurrentlyModified() throws Exception { int shards = randomFrom(1, 3, 5); int replicas = randomIntBetween(2, 10); long documents = randomLongBetween(2, 100); execute("CREATE TABLE test (" + " id long primary key)" + "clustered into " + shards + " shards with (column_policy = 'dynamic', number_of_replicas=" + replicas + ")"); ensureYellow(); ActionFuture<SQLResponse> createSnapshot = null; for (var i = 0; i < documents; i++) { execute("INSERT INTO test (id, field_" + i + ") VALUES (?, ?)", new Object[][]{{i, "value_" + i},}); if (createSnapshot == null) { createSnapshot = sqlExecutor.execute( "CREATE SNAPSHOT " + snapshotName() + " TABLE test with (wait_for_completion=true)", null); } } if (createSnapshot != null) { createSnapshot.actionGet(); } execute("DROP table test"); execute("RESTORE SNAPSHOT " + snapshotName() + " ALL with (wait_for_completion=true)"); waitNoPendingTasksOnAll(); SnapshotsInProgress finalSnapshotsInProgress = clusterService().state().custom(SnapshotsInProgress.TYPE); assertFalse(finalSnapshotsInProgress.entries().stream().anyMatch(entry -> entry.state().completed() == false)); ImmutableOpenMap<String, IndexMetaData> state = clusterService().state().metaData().indices(); IndexMetaData indexMetaData = state.values().iterator().next().value; int sizeOfProperties = ((Map<?, ?>) indexMetaData.getMappings().values().iterator().next().value.sourceAsMap().get("properties")).size(); execute("select count(*) from test"); assertThat( "Documents were restored but the restored index mapping was older than some documents and misses some of their fields", (Long)response.rows()[0][0], lessThanOrEqualTo((long) sizeOfProperties)); execute("select state from sys.snapshots where name=?", new Object[]{SNAPSHOT_NAME}); assertThat(response.rows()[0][0], is("SUCCESS")); }

Target:
public void testSnapshotWithMetadataConcurrentlyModified() throws Exception { int shards = randomFrom(1, 3, 5); int replicas = randomIntBetween(2, 10); long documents = randomLongBetween(2, 100); execute("CREATE TABLE test (" + " id long primary key)" + "clustered into " + shards + " shards with (column_policy = 'dynamic', number_of_replicas=" + replicas + ")"); ensureYellow(); ActionFuture<SQLResponse> createSnapshot = null; for (var i = 0; i < documents; i++) { execute("INSERT INTO test (id, field_" + i + ") VALUES (?, ?)", new Object[][]{{i, "value_" + i},}); execute("REFRESH TABLE test"); if (createSnapshot == null) { createSnapshot = sqlExecutor.execute( "CREATE SNAPSHOT " + snapshotName() + " TABLE test with (wait_for_completion=true)", null); } } if (createSnapshot != null) { createSnapshot.actionGet(); } execute("DROP table test"); execute("select state from sys.snapshots where name=?", new Object[]{SNAPSHOT_NAME}); assertThat(response.rows()[0][0], is("SUCCESS")); execute("RESTORE SNAPSHOT " + snapshotName() + " ALL with (wait_for_completion=true)"); waitNoPendingTasksOnAll(); SnapshotsInProgress finalSnapshotsInProgress = clusterService().state().custom(SnapshotsInProgress.TYPE); assertFalse(finalSnapshotsInProgress.entries().stream().anyMatch(entry -> entry.state().completed() == false)); ImmutableOpenMap<String, IndexMetaData> state = clusterService().state().metaData().indices(); IndexMetaData indexMetaData = state.values().iterator().next().value; int sizeOfProperties = ((Map<?, ?>) indexMetaData.getMappings().values().iterator().next().value.sourceAsMap().get("properties")).size(); execute("select count(*) from test"); assertThat( "Documents were restored but the restored index mapping was older than some documents and misses some of their fields", (Long)response.rows()[0][0], lessThanOrEqualTo((long) sizeOfProperties)); }