Cyrill commented on code in PR #6458:
URL: https://github.com/apache/ignite-3/pull/6458#discussion_r2300465458
##########
modules/transactions/src/integrationTest/java/org/apache/ignite/internal/disaster/ItDisasterRecoveryManagerTest.java:
##########
@@ -840,4 +872,299 @@ private static Row createKeyValueRow(int id, int value) {
private static boolean compareRows(BinaryRow row1, BinaryRow row2) {
return row1.schemaVersion() == row2.schemaVersion() &&
row1.tupleSlice().equals(row2.tupleSlice());
}
+
+ @WithSystemProperty(key = IgniteSystemProperties.COLOCATION_FEATURE_FLAG,
value = "true")
+ @Test
+ void testRestartPartitionsWithCleanUpFails() throws Exception {
+ IgniteImpl node = unwrapIgniteImpl(cluster.aliveNode());
+
+ insert(0, 0);
+ insert(1, 1);
+
+ Set<IgniteImpl> runningNodes =
cluster.runningNodes().map(TestWrappers::unwrapIgniteImpl).collect(Collectors.toSet());
+
+ assertValueOnSpecificNodes(TABLE_NAME, runningNodes, 0, 0);
+ assertValueOnSpecificNodes(TABLE_NAME, runningNodes, 1, 1);
+
+ int partitionId = 0;
+
+ CompletableFuture<Void> restartPartitionsWithCleanupFuture =
node.disasterRecoveryManager().restartPartitionsWithCleanup(
+ Set.of(node.name()),
+ ZONE_NAME,
+ Set.of(partitionId)
+ );
+
+ ExecutionException exception = assertThrows(
+ ExecutionException.class,
+ () -> restartPartitionsWithCleanupFuture.get(10_000,
MILLISECONDS)
+ );
+
+ assertInstanceOf(DisasterRecoveryException.class,
exception.getCause());
+
+ assertThat(exception.getCause().getMessage(), is("Not enough alive
nodes to perform reset with clean up."));
+ }
+
+ @WithSystemProperty(key = IgniteSystemProperties.COLOCATION_FEATURE_FLAG,
value = "true")
+ @Test
+ void testRestartHaPartitionsWithCleanUpFails() {
+ IgniteImpl node = unwrapIgniteImpl(cluster.aliveNode());
+
+ String testZone = "TEST_ZONE";
+
+ createZone(node.catalogManager(), testZone, 1, 1, null, null,
ConsistencyMode.HIGH_AVAILABILITY);
+
+ String tableName = "TABLE_NAME";
+
+ node.sql().executeScript(String.format(
+ "CREATE TABLE %s (id INT PRIMARY KEY, valInt INT) ZONE %s",
+ tableName,
+ testZone
+ ));
+
+ int partitionId = 0;
+
+ CompletableFuture<Void> restartPartitionsWithCleanupFuture =
node.disasterRecoveryManager().restartPartitionsWithCleanup(
+ Set.of(node.name()),
+ testZone,
+ Set.of(partitionId)
+ );
+
+ ExecutionException exception = assertThrows(
+ ExecutionException.class,
+ () -> restartPartitionsWithCleanupFuture.get(10_000,
MILLISECONDS)
+ );
+
+ assertInstanceOf(DisasterRecoveryException.class,
exception.getCause());
+
+ assertThat(exception.getCause().getMessage(), is("Not enough alive
nodes to perform reset with clean up."));
+ }
+
+ @WithSystemProperty(key = IgniteSystemProperties.COLOCATION_FEATURE_FLAG,
value = "true")
+ @ParameterizedTest(name = "consistencyMode={0}, primaryReplica={1},
raftLeader={2}")
+ @CsvSource({
+ "STRONG_CONSISTENCY, true, false",
+ "STRONG_CONSISTENCY, false, true",
+ "STRONG_CONSISTENCY, false, false",
+ "HIGH_AVAILABILITY, true, false",
+ "HIGH_AVAILABILITY, false, true",
+ "HIGH_AVAILABILITY, false, false"
+ })
+ void testRestartPartitionsWithCleanUp(
+ ConsistencyMode consistencyMode,
+ boolean primaryReplica,
+ boolean raftLeader
+ ) throws Exception {
+ IgniteImpl node = unwrapIgniteImpl(cluster.aliveNode());
+ cluster.startNode(1);
+
+ String testZone = "TEST_ZONE";
+
+ if (consistencyMode == ConsistencyMode.HIGH_AVAILABILITY) {
+ createZone(node.catalogManager(), testZone, 1, 2, null, null,
ConsistencyMode.HIGH_AVAILABILITY);
+ } else {
+ cluster.startNode(2);
+
+ createZone(node.catalogManager(), testZone, 1, 3);
+ }
+
+ Set<IgniteImpl> runningNodes =
cluster.runningNodes().map(TestWrappers::unwrapIgniteImpl).collect(Collectors.toSet());
+
+ String tableName = "TABLE_NAME";
+
+ node.sql().executeScript(String.format(
+ "CREATE TABLE %s (id INT PRIMARY KEY, valInt INT) ZONE %s",
+ tableName,
+ testZone
+ ));
+
+ insert(0, 0, tableName);
+
+ assertValueOnSpecificNodes(tableName, runningNodes, 0, 0);
+
+ IgniteImpl nodeToCleanup = findZoneNodeConformingOptions(testZone,
primaryReplica, raftLeader);
+
+ CompletableFuture<Void> restartPartitionsWithCleanupFuture =
node.disasterRecoveryManager().restartPartitionsWithCleanup(
+ Set.of(nodeToCleanup.name()),
+ testZone,
+ Set.of(0)
+ );
+
+ assertThat(restartPartitionsWithCleanupFuture,
willCompleteSuccessfully());
+
+ insert(1, 1, tableName);
+
+ assertValueOnSpecificNodes(tableName, runningNodes, 0, 0);
+
+ assertValueOnSpecificNodes(tableName, runningNodes, 1, 1);
+ }
+
+ @WithSystemProperty(key = IgniteSystemProperties.COLOCATION_FEATURE_FLAG,
value = "true")
+ @ParameterizedTest(name = "consistencyMode={0}, primaryReplica={1}")
+ @CsvSource({
+ "STRONG_CONSISTENCY, true",
+ "STRONG_CONSISTENCY, false",
+ "HIGH_AVAILABILITY, true",
+ "HIGH_AVAILABILITY, false",
+ })
+ void testRestartPartitionsWithCleanUpTxRollback(ConsistencyMode
consistencyMode, boolean primaryReplica) throws Exception {
+ IgniteImpl node = unwrapIgniteImpl(cluster.aliveNode());
+
+ cluster.startNode(1);
+
+ String testZone = "TEST_ZONE";
+
+ if (consistencyMode == ConsistencyMode.HIGH_AVAILABILITY) {
+ createZone(node.catalogManager(), testZone, 1, 2, null, null,
ConsistencyMode.HIGH_AVAILABILITY);
+ } else {
+ cluster.startNode(2);
+
+ createZone(node.catalogManager(), testZone, 1, 3);
+ }
+
+ Set<IgniteImpl> runningNodes =
cluster.runningNodes().map(TestWrappers::unwrapIgniteImpl).collect(Collectors.toSet());
+
+ String tableName = "TABLE_NAME";
+
+ node.sql().executeScript(String.format(
+ "CREATE TABLE %s (id INT PRIMARY KEY, valInt INT) ZONE %s",
+ tableName,
+ testZone
+ ));
+
+ insert(0, 0, tableName);
+
+ assertValueOnSpecificNodes(tableName, runningNodes, 0, 0);
+
+ IgniteImpl primaryNode =
+ unwrapIgniteImpl(findPrimaryIgniteNode(node, new
ZonePartitionId(zoneId(node.catalogManager(), testZone), 0)));
+
+ IgniteImpl nodeToCleanup;
+
+ if (primaryReplica) {
+ nodeToCleanup = primaryNode;
+ } else {
+ nodeToCleanup = cluster.runningNodes()
+ .filter(n -> !n.name().equals(primaryNode.name()))
+ .map(TestWrappers::unwrapIgniteImpl)
+ .findFirst()
+ .orElseThrow(() -> new IllegalStateException("No node
found that is not a primary replica."));
+ }
+
+ Transaction tx = nodeToCleanup.transactions().begin();
+
+ nodeToCleanup.sql().execute(tx, String.format("INSERT INTO %s VALUES
(2, 2)", tableName));
+
+ CompletableFuture<Void> restartPartitionsWithCleanupFuture =
+
nodeToCleanup.disasterRecoveryManager().restartPartitionsWithCleanup(
+ Set.of(nodeToCleanup.name()),
+ testZone,
+ Set.of(0)
+ );
+
+ assertThat(restartPartitionsWithCleanupFuture,
willCompleteSuccessfully());
+
+ if (primaryReplica) {
+ // We expect here that tx will be rolled back because we have
restarted primary replica. This is ensured by the fact that we
+ // use ReplicaManager.weakStopReplica(RESTART) in
restartPartitionsWithCleanup, and this mechanism
+ // waits for replica expiration and stops lease prolongation. As a
result, the transaction will not be able to commit
+ // because the primary replica has expired.
+ assertThrows(TransactionException.class, tx::commit, "Primary
replica has expired, transaction will be rolled back");
+
+ assertValueOnSpecificNodes(tableName, runningNodes, 0, 0);
+
+ for (IgniteImpl igniteImpl : runningNodes) {
+ assertEquals(1L, igniteImpl.sql().execute(null, "SELECT
count(*) as cnt FROM TABLE_NAME").next().longValue("cnt"));
+ }
+ } else {
+ tx.commit();
+
+ assertValueOnSpecificNodes(tableName, runningNodes, 0, 0);
+ assertValueOnSpecificNodes(tableName, runningNodes, 2, 2);
+
+ for (IgniteImpl igniteImpl : runningNodes) {
+ assertEquals(2L, igniteImpl.sql().execute(null, "SELECT
count(*) as cnt FROM TABLE_NAME").next().longValue("cnt"));
+ }
+ }
+ }
+
+ @WithSystemProperty(key = IgniteSystemProperties.COLOCATION_FEATURE_FLAG,
value = "true")
+ @Test
+ void testRestartPartitionsWithCleanUpConcurrentRebalance() throws
Exception {
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]