Search in sources :

Example 1 with TestAffinityFunction

use of org.apache.ignite.internal.processors.cache.metric.SqlViewExporterSpiTest.TestAffinityFunction in project ignite by apache.

the class SystemViewCommandTest method testPartitionStates.

/**
 */
@Test
public void testPartitionStates() throws Exception {
    String nodeName0 = getTestIgniteInstanceName(0);
    String nodeName1 = getTestIgniteInstanceName(1);
    String nodeName2 = getTestIgniteInstanceName(2);
    IgniteCache<Integer, Integer> cache1 = ignite0.createCache(new CacheConfiguration<Integer, Integer>().setName("cache1").setCacheMode(CacheMode.PARTITIONED).setAffinity(new TestAffinityFunction(new String[][] { { nodeName0, nodeName1 }, { nodeName1, nodeName2 }, { nodeName2, nodeName0 } })));
    IgniteCache<Integer, Integer> cache2 = ignite0.createCache(new CacheConfiguration<Integer, Integer>().setName("cache2").setCacheMode(CacheMode.PARTITIONED).setAffinity(new TestAffinityFunction(new String[][] { { nodeName0, nodeName1, nodeName2 }, { nodeName1 } })));
    for (int i = 0; i < 100; i++) {
        cache1.put(i, i);
        cache2.put(i, i);
    }
    try (IgniteEx ignite2 = startGrid(nodeName2)) {
        ignite2.rebalanceEnabled(false);
        ignite0.cluster().setBaselineTopology(ignite0.cluster().topologyVersion());
        String nodeId0 = ignite0.cluster().localNode().id().toString();
        String nodeId1 = ignite(1).cluster().localNode().id().toString();
        String nodeId2 = ignite2.cluster().localNode().id().toString();
        String cacheGrpId1 = Integer.toString(ignite0.cachex("cache1").context().groupId());
        String cacheGrpId2 = Integer.toString(ignite0.cachex("cache2").context().groupId());
        String owningState = GridDhtPartitionState.OWNING.name();
        String movingState = GridDhtPartitionState.MOVING.name();
        for (int i = 0; i < 3; i++) {
            List<List<String>> partStatesView = systemView(ignite(i), PART_STATES_VIEW);
            // Check partitions for cache1.
            checkPartitionStatesView(partStatesView, owningState, true, cacheGrpId1, nodeId0, 0);
            checkPartitionStatesView(partStatesView, owningState, false, cacheGrpId1, nodeId1, 0);
            checkPartitionStatesView(partStatesView, owningState, true, cacheGrpId1, nodeId1, 1);
            checkPartitionStatesView(partStatesView, movingState, false, cacheGrpId1, nodeId2, 1);
            checkPartitionStatesView(partStatesView, owningState, true, cacheGrpId1, nodeId0, 2);
            checkPartitionStatesView(partStatesView, movingState, false, cacheGrpId1, nodeId2, 2);
            checkPartitionStatesView(partStatesView, owningState, true, cacheGrpId2, nodeId0, 0);
            checkPartitionStatesView(partStatesView, owningState, false, cacheGrpId2, nodeId1, 0);
            checkPartitionStatesView(partStatesView, movingState, false, cacheGrpId2, nodeId2, 0);
            checkPartitionStatesView(partStatesView, owningState, true, cacheGrpId2, nodeId1, 1);
        }
        AffinityTopologyVersion topVer = ignite0.context().discovery().topologyVersionEx();
        ignite2.rebalanceEnabled(true);
        // Wait until rebalance complete.
        assertTrue(waitForCondition(() -> ignite0.context().discovery().topologyVersionEx().compareTo(topVer) > 0, getTestTimeout()));
        for (int i = 0; i < 3; i++) {
            List<List<String>> rows = systemView(ignite(i), PART_STATES_VIEW);
            assertEquals(10, rows.stream().filter(row -> (cacheGrpId1.equals(row.get(0)) || cacheGrpId2.equals(row.get(0))) && owningState.equals(row.get(3))).count());
            assertTrue(rows.stream().noneMatch(row -> (cacheGrpId1.equals(row.get(0)) || cacheGrpId2.equals(row.get(0))) && movingState.equals(row.get(3))));
        }
        // Check that assignment is now changed to ideal.
        for (int i = 0; i < 3; i++) {
            List<List<String>> rows = systemView(ignite(i), PART_STATES_VIEW);
            checkPartitionStatesView(rows, owningState, false, cacheGrpId1, nodeId0, 2);
            checkPartitionStatesView(rows, owningState, true, cacheGrpId1, nodeId2, 2);
        }
    } finally {
        ignite0.cluster().setBaselineTopology(ignite0.cluster().topologyVersion());
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Arrays(java.util.Arrays) GridCacheUtils.cacheId(org.apache.ignite.internal.processors.cache.GridCacheUtils.cacheId) MAX_VALUE(java.lang.Integer.MAX_VALUE) TestObjectEnum(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses.TestObjectEnum) EXIT_CODE_INVALID_ARGUMENTS(org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_INVALID_ARGUMENTS) Arrays.asList(java.util.Arrays.asList) PART_STATES_VIEW(org.apache.ignite.internal.processors.cache.GridCacheProcessor.PART_STATES_VIEW) SQL_TBLS_VIEW(org.apache.ignite.internal.processors.query.h2.SchemaManager.SQL_TBLS_VIEW) IgniteUtils.toStringSafe(org.apache.ignite.internal.util.IgniteUtils.toStringSafe) TestAffinityFunction(org.apache.ignite.internal.processors.cache.metric.SqlViewExporterSpiTest.TestAffinityFunction) INACTIVE(org.apache.ignite.cluster.ClusterState.INACTIVE) SystemView(org.apache.ignite.spi.systemview.view.SystemView) Set(java.util.Set) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) IgniteCache(org.apache.ignite.IgniteCache) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TEST_TRANSFORMER(org.apache.ignite.internal.metric.SystemViewSelfTest.TEST_TRANSFORMER) QueryCursor(org.apache.ignite.cache.query.QueryCursor) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) ScanQuery(org.apache.ignite.cache.query.ScanQuery) U(org.apache.ignite.internal.util.typedef.internal.U) EXIT_CODE_OK(org.apache.ignite.internal.commandline.CommandHandler.EXIT_CODE_OK) BINARY_METADATA_VIEW(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl.BINARY_METADATA_VIEW) ArrayList(java.util.ArrayList) COLUMN_SEPARATOR(org.apache.ignite.internal.commandline.systemview.SystemViewCommand.COLUMN_SEPARATOR) DISTRIBUTED_METASTORE_VIEW(org.apache.ignite.internal.processors.metastorage.persistence.DistributedMetaStorageImpl.DISTRIBUTED_METASTORE_VIEW) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) IgniteClient(org.apache.ignite.client.IgniteClient) AbstractSchemaSelfTest.queryProcessor(org.apache.ignite.internal.processors.cache.index.AbstractSchemaSelfTest.queryProcessor) TEST_PREDICATE(org.apache.ignite.internal.metric.SystemViewSelfTest.TEST_PREDICATE) SQL_SCHEMA_VIEW(org.apache.ignite.internal.processors.query.h2.SchemaManager.SQL_SCHEMA_VIEW) TestTransformer(org.apache.ignite.internal.metric.SystemViewSelfTest.TestTransformer) STREAM_POOL_QUEUE_VIEW(org.apache.ignite.internal.processors.pool.PoolProcessor.STREAM_POOL_QUEUE_VIEW) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) TASKS_VIEW(org.apache.ignite.internal.processors.task.GridTaskProcessor.TASKS_VIEW) Properties(java.util.Properties) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) Field(java.lang.reflect.Field) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) SCAN_QRY_SYS_VIEW(org.apache.ignite.internal.managers.systemview.ScanQuerySystemView.SCAN_QRY_SYS_VIEW) TRANSACTIONAL(org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL) NODE_ID(org.apache.ignite.internal.commandline.systemview.SystemViewCommandArg.NODE_ID) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) SQL_VIEW_COLS_VIEW(org.apache.ignite.internal.processors.query.h2.SchemaManager.SQL_VIEW_COLS_VIEW) SNAPSHOT_SYS_VIEW(org.apache.ignite.spi.systemview.view.SnapshotView.SNAPSHOT_SYS_VIEW) SYSTEM_VIEW(org.apache.ignite.internal.commandline.CommandList.SYSTEM_VIEW) CQ_SYS_VIEW(org.apache.ignite.internal.processors.continuous.GridContinuousProcessor.CQ_SYS_VIEW) CacheMode(org.apache.ignite.cache.CacheMode) IgniteJdbcThinDriver(org.apache.ignite.IgniteJdbcThinDriver) StripedExecutor(org.apache.ignite.internal.util.StripedExecutor) DATA_REGION_PAGE_LIST_VIEW(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager.DATA_REGION_PAGE_LIST_VIEW) Connection(java.sql.Connection) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) SQL_TBL_COLS_VIEW(org.apache.ignite.internal.processors.query.h2.SchemaManager.SQL_TBL_COLS_VIEW) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) DistributedMetaStorage(org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage) Transaction(org.apache.ignite.transactions.Transaction) CACHE_GRP_PAGE_LIST_VIEW(org.apache.ignite.internal.processors.cache.GridCacheProcessor.CACHE_GRP_PAGE_LIST_VIEW) IgniteEx(org.apache.ignite.internal.IgniteEx) METASTORE_VIEW(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager.METASTORE_VIEW) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) SystemViewCommandArg(org.apache.ignite.internal.commandline.systemview.SystemViewCommandArg) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridDhtPartitionState(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState) SVCS_VIEW(org.apache.ignite.internal.processors.service.IgniteServiceProcessor.SVCS_VIEW) CLI_CONN_VIEW(org.apache.ignite.internal.processors.odbc.ClientListenerProcessor.CLI_CONN_VIEW) SCHEMA_SYS(org.apache.ignite.internal.processors.query.QueryUtils.SCHEMA_SYS) OPTIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC) UUID(java.util.UUID) CommandList(org.apache.ignite.internal.commandline.CommandList) Collectors(java.util.stream.Collectors) VisorSystemViewTask(org.apache.ignite.internal.visor.systemview.VisorSystemViewTask) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) Objects(java.util.Objects) List(java.util.List) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) DFLT_SCHEMA(org.apache.ignite.internal.processors.query.QueryUtils.DFLT_SCHEMA) DummyService(org.apache.ignite.internal.processors.service.DummyService) GridCacheUtils.cacheGroupId(org.apache.ignite.internal.processors.cache.GridCacheUtils.cacheGroupId) GridTestUtils.waitForCondition(org.apache.ignite.testframework.GridTestUtils.waitForCondition) CACHES_VIEW(org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHES_VIEW) HashSet(java.util.HashSet) SYS_POOL_QUEUE_VIEW(org.apache.ignite.internal.processors.pool.PoolProcessor.SYS_POOL_QUEUE_VIEW) AttributeVisitor(org.apache.ignite.spi.systemview.view.SystemViewRowAttributeWalker.AttributeVisitor) Pattern.quote(java.util.regex.Pattern.quote) TestRunnable(org.apache.ignite.internal.metric.SystemViewSelfTest.TestRunnable) SQL_VIEWS_VIEW(org.apache.ignite.internal.processors.query.h2.SchemaManager.SQL_VIEWS_VIEW) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) MetricUtils.toSqlName(org.apache.ignite.internal.processors.metric.impl.MetricUtils.toSqlName) SqlConfiguration(org.apache.ignite.configuration.SqlConfiguration) TestPredicate(org.apache.ignite.internal.metric.SystemViewSelfTest.TestPredicate) TXS_MON_LIST(org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager.TXS_MON_LIST) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) CACHE_GRPS_VIEW(org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHE_GRPS_VIEW) TestObjectAllTypes(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses.TestObjectAllTypes) GridTestUtils.assertContains(org.apache.ignite.testframework.GridTestUtils.assertContains) Consumer(java.util.function.Consumer) IgniteCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager) Ignition(org.apache.ignite.Ignition) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) TestAffinityFunction(org.apache.ignite.internal.processors.cache.metric.SqlViewExporterSpiTest.TestAffinityFunction) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteEx(org.apache.ignite.internal.IgniteEx) Arrays.asList(java.util.Arrays.asList) ArrayList(java.util.ArrayList) CommandList(org.apache.ignite.internal.commandline.CommandList) List(java.util.List) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.Test)

Aggregations

MAX_VALUE (java.lang.Integer.MAX_VALUE)1 Field (java.lang.reflect.Field)1 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1 Properties (java.util.Properties)1 Set (java.util.Set)1 UUID (java.util.UUID)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Consumer (java.util.function.Consumer)1 Pattern.quote (java.util.regex.Pattern.quote)1 Collectors (java.util.stream.Collectors)1 Ignite (org.apache.ignite.Ignite)1 IgniteCache (org.apache.ignite.IgniteCache)1