You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sa...@apache.org on 2025/07/03 16:06:29 UTC
(ignite-3) branch main updated: IGNITE-25826 Provide table info in the old states API with colocation on (#6182)
This is an automated email from the ASF dual-hosted git repository.
sanpwc pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new f2de2036cec IGNITE-25826 Provide table info in the old states API with colocation on (#6182)
f2de2036cec is described below
commit f2de2036cec712420faa696e6132331ba7433096
Author: Cyrill <cy...@gmail.com>
AuthorDate: Thu Jul 3 19:06:23 2025 +0300
IGNITE-25826 Provide table info in the old states API with colocation on (#6182)
---
.../partitions/states/ItPartitionStatesTest.java | 55 ++++----------
.../rest/recovery/DisasterRecoveryController.java | 88 +++++++++++++---------
.../disaster/DisasterRecoveryManager.java | 25 ++++++
.../table/distributed/disaster/TableState.java | 56 ++++++++++++++
4 files changed, 149 insertions(+), 75 deletions(-)
diff --git a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/ItPartitionStatesTest.java b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/ItPartitionStatesTest.java
index c457098fbf2..72d60b4a645 100644
--- a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/ItPartitionStatesTest.java
+++ b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/ItPartitionStatesTest.java
@@ -64,10 +64,6 @@ public abstract class ItPartitionStatesTest extends CliIntegrationTest {
private static final String LOCAL_PARTITION_STATE_FIELDS = "Node name\t" + GLOBAL_PARTITION_STATE_FIELDS;
- private static final String GLOBAL_ZONE_PARTITION_STATE_FIELDS = "Zone name\tPartition ID\tState" + System.lineSeparator();
-
- private static final String LOCAL_ZONE_PARTITION_STATE_FIELDS = "Node name\t" + GLOBAL_ZONE_PARTITION_STATE_FIELDS;
-
private static Set<String> nodeNames;
@BeforeAll
@@ -256,21 +252,12 @@ public abstract class ItPartitionStatesTest extends CliIntegrationTest {
assertErrOutputIsEmpty();
- if (colocationEnabled()) {
- assertOutputMatches(String.format(
- "%1$s%2$s\t1\t(HEALTHY|AVAILABLE)%3$s",
- GLOBAL_ZONE_PARTITION_STATE_FIELDS,
- zoneName,
- System.lineSeparator()
- ));
- } else {
- assertOutputMatches(String.format(
- "%1$s%2$s\tPUBLIC\t[0-9]+\t%2$s_table\t1\t(HEALTHY|AVAILABLE)%3$s",
- GLOBAL_PARTITION_STATE_FIELDS,
- zoneName,
- System.lineSeparator()
- ));
- }
+ assertOutputMatches(String.format(
+ "%1$s%2$s\tPUBLIC\t[0-9]+\t%2$s_table\t1\t(HEALTHY|AVAILABLE)%3$s",
+ GLOBAL_PARTITION_STATE_FIELDS,
+ zoneName,
+ System.lineSeparator()
+ ));
}
@Test
@@ -288,32 +275,18 @@ public abstract class ItPartitionStatesTest extends CliIntegrationTest {
assertErrOutputIsEmpty();
- if (colocationEnabled()) {
- assertOutputMatches(String.format(
- "%1$s(%2$s)\t%3$s\t1\t(HEALTHY|AVAILABLE)%4$s",
- LOCAL_ZONE_PARTITION_STATE_FIELDS,
- possibleNodeNames,
- zoneName,
- System.lineSeparator()
- ));
- } else {
- assertOutputMatches(String.format(
- "%1$s(%2$s)\t%3$s\tPUBLIC\t[0-9]+\t%3$s_table\t1\t(HEALTHY|AVAILABLE)%4$s",
- LOCAL_PARTITION_STATE_FIELDS,
- possibleNodeNames,
- zoneName,
- System.lineSeparator()
- ));
- }
+ assertOutputMatches(String.format(
+ "%1$s(%2$s)\t%3$s\tPUBLIC\t[0-9]+\t%3$s_table\t1\t(HEALTHY|AVAILABLE)%4$s",
+ LOCAL_PARTITION_STATE_FIELDS,
+ possibleNodeNames,
+ zoneName,
+ System.lineSeparator()
+ ));
}
private void checkOutput(boolean global, Set<String> zoneNames, Set<String> nodes, int partitions) {
assertErrOutputIsEmpty();
- if (colocationEnabled()) {
- assertOutputStartsWith(global ? GLOBAL_ZONE_PARTITION_STATE_FIELDS : LOCAL_ZONE_PARTITION_STATE_FIELDS);
- } else {
- assertOutputStartsWith(global ? GLOBAL_PARTITION_STATE_FIELDS : LOCAL_PARTITION_STATE_FIELDS);
- }
+ assertOutputStartsWith(global ? GLOBAL_PARTITION_STATE_FIELDS : LOCAL_PARTITION_STATE_FIELDS);
if (!global) {
if (!nodes.isEmpty()) {
diff --git a/modules/rest/src/main/java/org/apache/ignite/internal/rest/recovery/DisasterRecoveryController.java b/modules/rest/src/main/java/org/apache/ignite/internal/rest/recovery/DisasterRecoveryController.java
index 5659df9b3fc..3e259d16fb3 100644
--- a/modules/rest/src/main/java/org/apache/ignite/internal/rest/recovery/DisasterRecoveryController.java
+++ b/modules/rest/src/main/java/org/apache/ignite/internal/rest/recovery/DisasterRecoveryController.java
@@ -19,7 +19,6 @@ package org.apache.ignite.internal.rest.recovery;
import static java.util.Collections.emptySet;
import static java.util.Comparator.comparing;
-import static java.util.stream.Collectors.toList;
import io.micronaut.context.annotation.Requires;
import io.micronaut.http.annotation.Body;
@@ -56,6 +55,7 @@ import org.apache.ignite.internal.table.distributed.disaster.LocalPartitionState
import org.apache.ignite.internal.table.distributed.disaster.LocalPartitionStateByNode;
import org.apache.ignite.internal.table.distributed.disaster.LocalTablePartitionState;
import org.apache.ignite.internal.table.distributed.disaster.LocalTablePartitionStateByNode;
+import org.apache.ignite.internal.table.distributed.disaster.TableState;
import org.apache.ignite.table.QualifiedName;
/**
@@ -82,7 +82,7 @@ public class DisasterRecoveryController implements DisasterRecoveryApi, Resource
// The table response is actually a superset of the zone response, so should be fine to convert it.
CompletableFuture<LocalZonePartitionStatesResponse> zoneStates =
getZoneLocalPartitionStates(zoneNames, nodeNames, partitionIds);
- return zoneStates.thenApply(DisasterRecoveryController::toTableLocalStates);
+ return zoneStates.thenApply(zoneResponse -> convertLocalZoneToTableStates(zoneResponse, disasterRecoveryManager));
}
return disasterRecoveryManager.localTablePartitionStates(
@@ -93,22 +93,6 @@ public class DisasterRecoveryController implements DisasterRecoveryApi, Resource
.thenApply(DisasterRecoveryController::convertLocalTableStates);
}
- private static LocalPartitionStatesResponse toTableLocalStates(LocalZonePartitionStatesResponse zoneResponse) {
- List<LocalPartitionStateResponse> states = zoneResponse.states().stream()
- .map(state -> new LocalPartitionStateResponse(
- state.nodeName(),
- state.zoneName(),
- "",
- -1,
- "",
- state.partitionId(),
- state.state(),
- state.estimatedRows()
- ))
- .collect(toList());
- return new LocalPartitionStatesResponse(states);
- }
-
@Override
public CompletableFuture<GlobalPartitionStatesResponse> getGlobalPartitionStates(
Optional<Set<String>> zoneNames,
@@ -119,7 +103,7 @@ public class DisasterRecoveryController implements DisasterRecoveryApi, Resource
CompletableFuture<GlobalZonePartitionStatesResponse> zoneStates =
getZoneGlobalPartitionStates(zoneNames, partitionIds);
- return zoneStates.thenApply(DisasterRecoveryController::toTableGlobalStates);
+ return zoneStates.thenApply(zoneResponse -> convertGlobalZoneToTableStates(zoneResponse, disasterRecoveryManager));
}
return disasterRecoveryManager.globalTablePartitionStates(
@@ -129,21 +113,6 @@ public class DisasterRecoveryController implements DisasterRecoveryApi, Resource
.thenApply(DisasterRecoveryController::convertGlobalStates);
}
- private static GlobalPartitionStatesResponse toTableGlobalStates(GlobalZonePartitionStatesResponse zoneStates) {
- List<GlobalPartitionStateResponse> states = zoneStates.states().stream()
- .map(state -> new GlobalPartitionStateResponse(
- state.zoneName(),
- "",
- -1,
- "",
- state.partitionId(),
- state.state()
- ))
- .collect(toList());
-
- return new GlobalPartitionStatesResponse(states);
- }
-
@Override
public CompletableFuture<Void> resetPartitions(@Body ResetPartitionsRequest command) {
if (nodeProperties.colocationEnabled()) {
@@ -223,6 +192,28 @@ public class DisasterRecoveryController implements DisasterRecoveryApi, Resource
).thenApply(DisasterRecoveryController::convertGlobalZoneStates);
}
+ private static LocalPartitionStatesResponse convertLocalZoneToTableStates(
+ LocalZonePartitionStatesResponse zoneResponse,
+ DisasterRecoveryManager manager) {
+ List<LocalPartitionStateResponse> states = new ArrayList<>();
+
+ for (LocalZonePartitionStateResponse zoneState : zoneResponse.states()) {
+ for (TableState tableState : manager.zoneTablesStates(zoneState.zoneName())) {
+ states.add(new LocalPartitionStateResponse(
+ zoneState.nodeName(),
+ zoneState.zoneName(),
+ tableState.schemaName,
+ tableState.tableId,
+ tableState.tableName,
+ zoneState.partitionId(),
+ zoneState.state(),
+ zoneState.estimatedRows()
+ ));
+ }
+ }
+ return createLocalPartitionStatesResponse(states);
+ }
+
private static LocalPartitionStatesResponse convertLocalTableStates(Map<TablePartitionId, LocalTablePartitionStateByNode> localStates) {
List<LocalPartitionStateResponse> states = new ArrayList<>();
@@ -244,6 +235,10 @@ public class DisasterRecoveryController implements DisasterRecoveryApi, Resource
}
}
+ return createLocalPartitionStatesResponse(states);
+ }
+
+ private static LocalPartitionStatesResponse createLocalPartitionStatesResponse(List<LocalPartitionStateResponse> states) {
// Sort the output conveniently.
states.sort(comparing(LocalPartitionStateResponse::schemaName)
.thenComparing(LocalPartitionStateResponse::tableName)
@@ -292,6 +287,31 @@ public class DisasterRecoveryController implements DisasterRecoveryApi, Resource
));
}
+ return createGlobalPartitionStatesResponse(states);
+ }
+
+ private static GlobalPartitionStatesResponse convertGlobalZoneToTableStates(
+ GlobalZonePartitionStatesResponse zoneResponse,
+ DisasterRecoveryManager manager
+ ) {
+ List<GlobalPartitionStateResponse> states = new ArrayList<>();
+
+ for (GlobalZonePartitionStateResponse zoneState : zoneResponse.states()) {
+ for (TableState tableState : manager.zoneTablesStates(zoneState.zoneName())) {
+ states.add(new GlobalPartitionStateResponse(
+ zoneState.zoneName(),
+ tableState.schemaName,
+ tableState.tableId,
+ tableState.tableName,
+ zoneState.partitionId(),
+ zoneState.state()
+ ));
+ }
+ }
+ return createGlobalPartitionStatesResponse(states);
+ }
+
+ private static GlobalPartitionStatesResponse createGlobalPartitionStatesResponse(List<GlobalPartitionStateResponse> states) {
// Sort the output conveniently.
states.sort(comparing(GlobalPartitionStateResponse::schemaName)
.thenComparing(GlobalPartitionStateResponse::tableName)
diff --git a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/DisasterRecoveryManager.java b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/DisasterRecoveryManager.java
index 0cf54a564ba..79fc2a72d9c 100644
--- a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/DisasterRecoveryManager.java
+++ b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/DisasterRecoveryManager.java
@@ -1523,6 +1523,31 @@ public class DisasterRecoveryManager implements IgniteComponent, SystemViewProvi
return catalog;
}
+ /**
+ * A helper method to get table states for the specified zone when colocation is enabled.
+ *
+ * @param zoneName Zone name.
+ * @return A collection of table states.
+ */
+ public Collection<TableState> zoneTablesStates(String zoneName) {
+ Catalog catalog = catalogLatestVersion();
+ int zoneId = zoneDescriptor(catalog, zoneName).id();
+
+ return tableManager.zoneTables(zoneId).stream()
+ .map(table -> {
+ CatalogTableDescriptor tableDescriptor = catalog.table(table.tableId());
+ String schemaName = catalog.schema(tableDescriptor.schemaId()).name();
+
+ return new TableState(
+ table.tableId(),
+ table.qualifiedName().objectName(),
+ tableDescriptor.schemaId(),
+ schemaName
+ );
+ })
+ .collect(toList());
+ }
+
private static CatalogTableDescriptor tableDescriptor(Catalog catalog, String schemaName, String tableName) {
CatalogTableDescriptor tableDescriptor = catalog.table(schemaName, tableName);
diff --git a/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/TableState.java b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/TableState.java
new file mode 100644
index 00000000000..d23a2b62542
--- /dev/null
+++ b/modules/table/src/main/java/org/apache/ignite/internal/table/distributed/disaster/TableState.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.table.distributed.disaster;
+
+import org.apache.ignite.internal.tostring.S;
+
+/**
+ * Table state.
+ */
+public class TableState {
+
+ public final int schemaId;
+ public final int tableId;
+
+ public final String schemaName;
+ public final String tableName;
+
+ TableState(int tableId, String tableName, int schemaId, String schemaName) {
+ this.schemaId = schemaId;
+ this.tableId = tableId;
+ this.schemaName = schemaName;
+ this.tableName = tableName;
+ }
+
+ public int schemaId() {
+ return schemaId;
+ }
+
+ public String schemaName() {
+ return schemaName;
+ }
+
+ public String tableName() {
+ return tableName;
+ }
+
+ @Override
+ public String toString() {
+ return S.toString(TableState.class, this);
+ }
+}