This is an automated email from the ASF dual-hosted git repository. sk0x50 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 f0e23a4b62 IGNITE-21036 introduce zones' system view (#3056) f0e23a4b62 is described below commit f0e23a4b62eb52e16d86c0d7cae44b30470a32d0 Author: Mirza Aliev <alievmi...@gmail.com> AuthorDate: Thu Jan 18 21:35:43 2024 +0400 IGNITE-21036 introduce zones' system view (#3056) --- .../internal/catalog/CatalogManagerImpl.java | 22 ++- .../internal/catalog/commands/CatalogUtils.java | 2 +- modules/distribution-zones/README.md | 7 + .../ItDistributionZonesFilterTest.java | 16 +- .../internal/sql/engine/ItZonesSystemViewTest.java | 168 +++++++++++++++++++++ 5 files changed, 205 insertions(+), 10 deletions(-) diff --git a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogManagerImpl.java b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogManagerImpl.java index 34f2a86585..f6bcdbc5e5 100644 --- a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogManagerImpl.java +++ b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/CatalogManagerImpl.java @@ -33,6 +33,7 @@ import java.util.NavigableMap; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.Flow.Publisher; +import java.util.function.Function; import java.util.function.LongSupplier; import org.apache.ignite.internal.catalog.descriptors.CatalogIndexDescriptor; import org.apache.ignite.internal.catalog.descriptors.CatalogObjectDescriptor; @@ -409,7 +410,8 @@ public class CatalogManagerImpl extends AbstractEventProducer<CatalogEvent, Cata public List<SystemView<?>> systemViews() { return List.of( createSystemViewsView(), - createSystemViewColumnsView() + createSystemViewColumnsView(), + createSystemViewZonesView() ); } @@ -557,6 +559,24 @@ public class CatalogManagerImpl extends AbstractEventProducer<CatalogEvent, Cata .build(); } + private SystemView<?> createSystemViewZonesView() { + return SystemViews.<CatalogZoneDescriptor>clusterViewBuilder() + .name("ZONES") + .addColumn("NAME", NativeTypes.STRING, CatalogZoneDescriptor::name) + .addColumn("PARTITIONS", NativeTypes.INT32, CatalogZoneDescriptor::partitions) + .addColumn("REPLICAS", NativeTypes.INT32, CatalogZoneDescriptor::replicas) + .addColumn("DATA_NODES_AUTO_ADJUST_SCALE_UP", NativeTypes.INT32, CatalogZoneDescriptor::dataNodesAutoAdjustScaleUp) + .addColumn("DATA_NODES_AUTO_ADJUST_SCALE_DOWN", NativeTypes.INT32, CatalogZoneDescriptor::dataNodesAutoAdjustScaleDown) + .addColumn("DATA_NODES_FILTER", NativeTypes.STRING, CatalogZoneDescriptor::filter) + .addColumn("IS_DEFAULT_ZONE", NativeTypes.BOOLEAN, isDefaultZone()) + .dataProvider(SubscriptionUtils.fromIterable(() -> catalog(latestCatalogVersion()).zones().iterator())) + .build(); + } + + private static Function<CatalogZoneDescriptor, Boolean> isDefaultZone() { + return zone -> zone.name().equals(DEFAULT_ZONE_NAME); + } + /** * A container that keeps given descriptor along with name of the schema this * descriptor belongs to. diff --git a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CatalogUtils.java b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CatalogUtils.java index 4a63ce972c..45d2e522f0 100644 --- a/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CatalogUtils.java +++ b/modules/catalog/src/main/java/org/apache/ignite/internal/catalog/commands/CatalogUtils.java @@ -59,7 +59,7 @@ public class CatalogUtils { * Default filter of distribution zone, which is a {@link com.jayway.jsonpath.JsonPath} expression for including all attributes of * nodes. */ - public static final String DEFAULT_FILTER = "'$..*'"; + public static final String DEFAULT_FILTER = "$..*"; /** Default distribution zone storage engine. */ // TODO: IGNITE-19719 Should be defined differently diff --git a/modules/distribution-zones/README.md b/modules/distribution-zones/README.md index a567805b53..310122ea74 100644 --- a/modules/distribution-zones/README.md +++ b/modules/distribution-zones/README.md @@ -20,3 +20,10 @@ a zone. After timeout, new data nodes of a zone are propagated to the meta stora If a new intent is appeared at the moment, when old intent has not been started yet, then old intent will be canceled and replaced with a new one. +## Access to the list of zones +To check the existing list of zones in the cluster, use zones' system view + +```sql +SELECT * FROM SYSTEM.ZONES +``` + diff --git a/modules/distribution-zones/src/integrationTest/java/org/apache/ignite/internal/distributionzones/ItDistributionZonesFilterTest.java b/modules/distribution-zones/src/integrationTest/java/org/apache/ignite/internal/distributionzones/ItDistributionZonesFilterTest.java index 874a290147..20c9188570 100644 --- a/modules/distribution-zones/src/integrationTest/java/org/apache/ignite/internal/distributionzones/ItDistributionZonesFilterTest.java +++ b/modules/distribution-zones/src/integrationTest/java/org/apache/ignite/internal/distributionzones/ItDistributionZonesFilterTest.java @@ -101,7 +101,7 @@ public class ItDistributionZonesFilterTest extends ClusterPerTestIntegrationTest */ @Test void testFilteredDataNodesPropagatedToStable() throws Exception { - String filter = "'$[?(@.region == \"US\" && @.storage == \"SSD\")]'"; + String filter = "$[?(@.region == \"US\" && @.storage == \"SSD\")]"; // This node do not pass the filter @Language("JSON") String firstNodeAttributes = "{region:{attribute:\"EU\"},storage:{attribute:\"SSD\"}}"; @@ -169,7 +169,7 @@ public class ItDistributionZonesFilterTest extends ClusterPerTestIntegrationTest */ @Test void testAlteringFiltersPropagatedDataNodesToStableImmediately() throws Exception { - String filter = "'$[?(@.region == \"US\" && @.storage == \"SSD\")]'"; + String filter = "$[?(@.region == \"US\" && @.storage == \"SSD\")]"; IgniteImpl node0 = node(0); @@ -226,7 +226,7 @@ public class ItDistributionZonesFilterTest extends ClusterPerTestIntegrationTest */ @Test void testEmptyDataNodesDoNotPropagatedToStableAfterAlteringFilter() throws Exception { - String filter = "'$[?(@.region == \"US\" && @.storage == \"SSD\")]'"; + String filter = "$[?(@.region == \"US\" && @.storage == \"SSD\")]"; IgniteImpl node0 = node(0); @@ -265,7 +265,7 @@ public class ItDistributionZonesFilterTest extends ClusterPerTestIntegrationTest waitDataNodeAndListenersAreHandled(metaStorageManager, 1, zoneId); // There is no node that match the filter - String newFilter = "'$[?(@.region == \"FOO\" && @.storage == \"BAR\")]'"; + String newFilter = "$[?(@.region == \"FOO\" && @.storage == \"BAR\")]"; session.execute(null, alterZoneSql(newFilter)); @@ -289,7 +289,7 @@ public class ItDistributionZonesFilterTest extends ClusterPerTestIntegrationTest */ @Test void testFilteredEmptyDataNodesDoNotTriggerRebalance() throws Exception { - String filter = "'$[?(@.region == \"EU\" && @.storage == \"HDD\")]'"; + String filter = "$[?(@.region == \"EU\" && @.storage == \"HDD\")]"; // This node do not pass the filter. IgniteImpl node0 = node(0); @@ -335,7 +335,7 @@ public class ItDistributionZonesFilterTest extends ClusterPerTestIntegrationTest @Test void testFilteredEmptyDataNodesDoNotTriggerRebalanceOnReplicaUpdate() throws Exception { - String filter = "'$[?(@.region == \"EU\" && @.storage == \"HDD\")]'"; + String filter = "$[?(@.region == \"EU\" && @.storage == \"HDD\")]"; // This node do not pass the filter. IgniteImpl node0 = node(0); @@ -441,7 +441,7 @@ public class ItDistributionZonesFilterTest extends ClusterPerTestIntegrationTest String sqlFormat = "CREATE ZONE \"%s\" WITH " + "\"REPLICAS\" = %s, " + "\"PARTITIONS\" = %s, " - + "\"DATA_NODES_FILTER\" = %s, " + + "\"DATA_NODES_FILTER\" = '%s', " + "\"DATA_NODES_AUTO_ADJUST_SCALE_UP\" = %s, " + "\"DATA_NODES_AUTO_ADJUST_SCALE_DOWN\" = %s"; @@ -449,7 +449,7 @@ public class ItDistributionZonesFilterTest extends ClusterPerTestIntegrationTest } private static String alterZoneSql(String filter) { - return String.format("ALTER ZONE \"%s\" SET \"DATA_NODES_FILTER\" = %s", ZONE_NAME, filter); + return String.format("ALTER ZONE \"%s\" SET \"DATA_NODES_FILTER\" = '%s'", ZONE_NAME, filter); } private static String alterZoneSql(int replicas) { diff --git a/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItZonesSystemViewTest.java b/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItZonesSystemViewTest.java new file mode 100644 index 0000000000..bffe3e2bd2 --- /dev/null +++ b/modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItZonesSystemViewTest.java @@ -0,0 +1,168 @@ +/* + * 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.sql.engine; + +import static org.apache.ignite.internal.catalog.CatalogService.DEFAULT_ZONE_NAME; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.DEFAULT_FILTER; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.DEFAULT_PARTITION_COUNT; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.DEFAULT_REPLICA_COUNT; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.IMMEDIATE_TIMER_VALUE; +import static org.apache.ignite.internal.catalog.commands.CatalogUtils.INFINITE_TIMER_VALUE; + +import org.apache.ignite.internal.sql.BaseSqlIntegrationTest; +import org.apache.ignite.internal.testframework.IgniteTestUtils; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; + +/** + * End-to-end tests to verify zones system view. + */ +public class ItZonesSystemViewTest extends BaseSqlIntegrationTest { + private static final String ZONE_NAME = "TEST_ZONE"; + + private static final String ALTER_ZONE_NAME = "NEW_TEST_ZONE"; + + @Override + @BeforeAll + protected void beforeAll(TestInfo testInfo) { + super.beforeAll(testInfo); + + IgniteTestUtils.await(systemViewManager().completeRegistration()); + } + + @Test + public void systemViewDefaultZone() { + assertQuery("SELECT * FROM SYSTEM.ZONES").returns( + DEFAULT_ZONE_NAME, + DEFAULT_PARTITION_COUNT, + DEFAULT_REPLICA_COUNT, + IMMEDIATE_TIMER_VALUE, + INFINITE_TIMER_VALUE, + DEFAULT_FILTER, + true + ).check(); + } + + @Test + public void systemViewCustomZone() { + sql(createZoneSql(ZONE_NAME, 1, 2, 3, 4, DEFAULT_FILTER)); + + assertQuery(selectFromZonesSystemView(ZONE_NAME)).returns( + ZONE_NAME, + 1, + 2, + 3, + 4, + DEFAULT_FILTER, + false + ).check(); + + sql("DROP ZONE " + ZONE_NAME); + } + + @Test + public void systemViewAlterCustomZone() { + sql(createZoneSql(ZONE_NAME, 1, 2, 3, 4, DEFAULT_FILTER)); + + assertQuery(selectFromZonesSystemView(ZONE_NAME)).returns( + ZONE_NAME, + 1, + 2, + 3, + 4, + DEFAULT_FILTER, + false + ).check(); + + sql("ALTER ZONE " + ZONE_NAME + " SET REPLICAS = 100"); + + assertQuery(selectFromZonesSystemView(ZONE_NAME)).returns( + ZONE_NAME, + 1, + 100, + 3, + 4, + DEFAULT_FILTER, + false + ).check(); + + sql("DROP ZONE " + ZONE_NAME); + } + + @Test + public void systemViewRenameCustomZone() { + sql(createZoneSql(ZONE_NAME, 1, 2, 3, 4, DEFAULT_FILTER)); + + assertQuery(selectFromZonesSystemView(ZONE_NAME)).returns( + ZONE_NAME, + 1, + 2, + 3, + 4, + DEFAULT_FILTER, + false + ).check(); + + sql("ALTER ZONE " + ZONE_NAME + " RENAME TO " + ALTER_ZONE_NAME); + + assertQuery(selectFromZonesSystemView(ALTER_ZONE_NAME)).returns( + ALTER_ZONE_NAME, + 1, + 2, + 3, + 4, + DEFAULT_FILTER, + false + ).check(); + + assertQuery("SELECT COUNT(*) FROM SYSTEM.ZONES").returns(2L).check(); + + sql("DROP ZONE " + ALTER_ZONE_NAME); + } + + @Test + public void systemViewDropCustomZone() { + assertQuery("SELECT COUNT(*) FROM SYSTEM.ZONES").returns(1L).check(); + + sql(createZoneSql(ZONE_NAME, 1, 2, 3, 4, DEFAULT_FILTER)); + + assertQuery("SELECT COUNT(*) FROM SYSTEM.ZONES").returns(2L).check(); + + sql("DROP ZONE " + ZONE_NAME); + + assertQuery("SELECT COUNT(*) FROM SYSTEM.ZONES").returns(1L).check(); + } + + private static String createZoneSql(String zoneName, int partitions, int replicas, int scaleUp, int scaleDown, String filter) { + String sqlFormat = "CREATE ZONE \"%s\" WITH " + + "\"PARTITIONS\" = %d, " + + "\"REPLICAS\" = %d, " + + "\"DATA_NODES_AUTO_ADJUST_SCALE_UP\" = %d, " + + "\"DATA_NODES_AUTO_ADJUST_SCALE_DOWN\" = %d," + + "\"DATA_NODES_FILTER\" = '%s'"; + + return String.format(sqlFormat, zoneName, partitions, replicas, scaleUp, scaleDown, filter); + } + + private static String selectFromZonesSystemView(String zoneName) { + String sqlFormat = "SELECT * FROM SYSTEM.ZONES WHERE NAME = '%s'"; + + return String.format(sqlFormat, zoneName); + } +}