Search in sources :

Example 1 with ClusterNodeAttributeAffinityBackupFilter

use of org.apache.ignite.cache.affinity.rendezvous.ClusterNodeAttributeAffinityBackupFilter in project ignite by apache.

the class PlatformConfigurationUtils method writeAffinityBackupFilter.

/**
 * Writes affinity backup filter.
 *
 * @param out Stream.
 * @param filter Filter.
 */
private static void writeAffinityBackupFilter(BinaryRawWriter out, Object filter) {
    if (filter instanceof ClusterNodeAttributeAffinityBackupFilter) {
        ClusterNodeAttributeAffinityBackupFilter backupFilter = (ClusterNodeAttributeAffinityBackupFilter) filter;
        String[] attrs = backupFilter.getAttributeNames();
        out.writeInt(attrs.length);
        for (String attr : attrs) out.writeString(attr);
    } else
        out.writeInt(-1);
}
Also used : ClusterNodeAttributeAffinityBackupFilter(org.apache.ignite.cache.affinity.rendezvous.ClusterNodeAttributeAffinityBackupFilter)

Example 2 with ClusterNodeAttributeAffinityBackupFilter

use of org.apache.ignite.cache.affinity.rendezvous.ClusterNodeAttributeAffinityBackupFilter in project ignite by apache.

the class PlatformConfigurationUtils method readAffinityFunction.

/**
 * Reads the eviction policy.
 *
 * @param in Stream.
 * @return Affinity function.
 */
public static PlatformAffinityFunction readAffinityFunction(BinaryRawReaderEx in) {
    byte plcTyp = in.readByte();
    if (plcTyp == 0)
        return null;
    int partitions = in.readInt();
    boolean exclNeighbours = in.readBoolean();
    byte overrideFlags = in.readByte();
    Object userFunc = in.readObjectDetached();
    AffinityFunction baseFunc = null;
    switch(plcTyp) {
        case 1:
            {
                throw new IllegalStateException("FairAffinityFunction");
            }
        case 2:
            {
                RendezvousAffinityFunction f = new RendezvousAffinityFunction();
                f.setPartitions(partitions);
                f.setExcludeNeighbors(exclNeighbours);
                baseFunc = f;
                int attrCnt = in.readInt();
                if (attrCnt > 0) {
                    String[] attrs = new String[attrCnt];
                    for (int i = 0; i < attrCnt; i++) {
                        attrs[i] = in.readString();
                    }
                    f.setAffinityBackupFilter(new ClusterNodeAttributeAffinityBackupFilter(attrs));
                }
                break;
            }
        default:
            assert plcTyp == 3;
    }
    return new PlatformAffinityFunction(userFunc, partitions, overrideFlags, baseFunc);
}
Also used : PlatformAffinityFunction(org.apache.ignite.internal.processors.platform.cache.affinity.PlatformAffinityFunction) ClusterNodeAttributeAffinityBackupFilter(org.apache.ignite.cache.affinity.rendezvous.ClusterNodeAttributeAffinityBackupFilter) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) AffinityFunction(org.apache.ignite.cache.affinity.AffinityFunction) PlatformAffinityFunction(org.apache.ignite.internal.processors.platform.cache.affinity.PlatformAffinityFunction) PlatformDotNetAffinityFunction(org.apache.ignite.platform.dotnet.PlatformDotNetAffinityFunction) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)

Example 3 with ClusterNodeAttributeAffinityBackupFilter

use of org.apache.ignite.cache.affinity.rendezvous.ClusterNodeAttributeAffinityBackupFilter in project ignite by apache.

the class BackupFilter method backupFilter.

@Test
void backupFilter() {
    // tag::backup-filter[]
    CacheConfiguration<Integer, String> cacheCfg = new CacheConfiguration<Integer, String>("myCache");
    cacheCfg.setBackups(1);
    RendezvousAffinityFunction af = new RendezvousAffinityFunction();
    af.setAffinityBackupFilter(new ClusterNodeAttributeAffinityBackupFilter("AVAILABILITY_ZONE"));
    cacheCfg.setAffinity(af);
// end::backup-filter[]
}
Also used : ClusterNodeAttributeAffinityBackupFilter(org.apache.ignite.cache.affinity.rendezvous.ClusterNodeAttributeAffinityBackupFilter) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Test(org.junit.jupiter.api.Test)

Example 4 with ClusterNodeAttributeAffinityBackupFilter

use of org.apache.ignite.cache.affinity.rendezvous.ClusterNodeAttributeAffinityBackupFilter in project ignite by apache.

the class IgniteWalRebalanceTest method testMultipleNodesFailHistoricalRebalance.

/**
 * Tests that demander switches to full rebalance if the previously chosen two of three of suppliers
 * for a group have failed to perform historical rebalance due to an unexpected error.
 *
 * @throws Exception If failed
 */
@Test
@WithSystemProperty(key = "IGNITE_DISABLE_WAL_DURING_REBALANCING", value = "true")
public void testMultipleNodesFailHistoricalRebalance() throws Exception {
    backups = 1;
    int node_cnt = 4;
    int demanderId = node_cnt - 1;
    // Start a new cluster with 3 suppliers.
    startGrids(node_cnt - 1);
    // Start demander node.
    userAttrs.put("TEST_ATTR", "TEST_ATTR");
    startGrid(node_cnt - 1);
    grid(0).cluster().state(ACTIVE);
    // Create a new cache that places a full set of partitions on demander node.
    RendezvousAffinityFunction aff = new RendezvousAffinityFunction(false, PARTS_CNT);
    aff.setAffinityBackupFilter(new ClusterNodeAttributeAffinityBackupFilter("TEST_ATTR"));
    String cacheName = "test-cache-1";
    IgniteCache<Integer, IndexedObject> cache0 = grid(0).getOrCreateCache(new CacheConfiguration<Integer, IndexedObject>(cacheName).setBackups(backups).setAffinity(aff).setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC));
    // Fill initial data and force checkpoint.
    final int entryCnt = PARTS_CNT * 200;
    final int preloadEntryCnt = PARTS_CNT * 201;
    int val = 0;
    for (int k = 0; k < preloadEntryCnt; k++) cache0.put(k, new IndexedObject(val++));
    forceCheckpoint();
    // Stop demander node.
    stopGrid(demanderId);
    // Rewrite data to trigger further rebalance.
    for (int k = 0; k < entryCnt; k++) {
        // even though the corresponding RebalanceFuture will be cancelled.
        if (grid(0).affinity(cacheName).partition(k) != 12)
            cache0.put(k, new IndexedObject(val++));
    }
    // Upload additional data to a particular partition (primary partition belongs to coordinator, for instance)
    // in order to trigger full rebalance for that partition instead of historical one.
    int[] primaries0 = grid(0).affinity(cacheName).primaryPartitions(grid(0).localNode());
    for (int i = 0; i < preloadEntryCnt; ++i) cache0.put(primaries0[0], new IndexedObject(val++));
    forceCheckpoint();
    // Delay rebalance process for specified group.
    blockMsgPred = (node, msg) -> {
        if (msg instanceof GridDhtPartitionDemandMessage) {
            GridDhtPartitionDemandMessage msg0 = (GridDhtPartitionDemandMessage) msg;
            return msg0.groupId() == CU.cacheId(cacheName);
        }
        return false;
    };
    Queue<RecordedDemandMessage> recorderedMsgs = new ConcurrentLinkedQueue<>();
    // Record demand messages for specified group.
    recordMsgPred = (node, msg) -> {
        if (msg instanceof GridDhtPartitionDemandMessage) {
            GridDhtPartitionDemandMessage msg0 = (GridDhtPartitionDemandMessage) msg;
            if (msg0.groupId() == CU.cacheId(cacheName)) {
                recorderedMsgs.add(new RecordedDemandMessage(node.id(), msg0.groupId(), msg0.partitions().hasFull(), msg0.partitions().hasHistorical()));
            }
        }
        return false;
    };
    // Corrupt WAL on suppliers, except the one.
    injectFailingIOFactory(grid(0));
    injectFailingIOFactory(grid(1));
    // Trigger rebalance process from suppliers.
    IgniteEx restartedDemander = startGrid(node_cnt - 1);
    TestRecordingCommunicationSpi demanderSpi = TestRecordingCommunicationSpi.spi(restartedDemander);
    // Wait until demander starts historical rebalancning.
    demanderSpi.waitForBlocked();
    final IgniteInternalFuture<Boolean> preloadFut = restartedDemander.cachex(cacheName).context().group().preloader().rebalanceFuture();
    // Unblock messages and start tracking demand and supply messages.
    demanderSpi.stopBlock();
    // Wait until rebalancing will be cancelled for both suppliers.
    assertTrue("Rebalance future was not cancelled [fut=" + preloadFut + ']', GridTestUtils.waitForCondition(preloadFut::isDone, getTestTimeout()));
    Assert.assertEquals("Rebalance should be cancelled on demander node: " + preloadFut, false, preloadFut.get());
    awaitPartitionMapExchange(true, true, null);
    // Check data consistency.
    assertPartitionsSame(idleVerify(restartedDemander, cacheName));
    // Check that historical rebalance switched to full for supplier 1 & 2 and it was historical for supplier3.
    IgnitePredicate<RecordedDemandMessage> histPred = msg -> msg.hasHistorical() && !msg.hasFull();
    IgnitePredicate<RecordedDemandMessage> fullPred = msg -> !msg.hasHistorical() && msg.hasFull();
    IgnitePredicate<RecordedDemandMessage> mixedPred = msg -> msg.hasHistorical() && msg.hasFull();
    IgniteBiInClosure<UUID, Boolean> supplierChecker = (supplierId, mixed) -> {
        List<RecordedDemandMessage> demandMsgsForSupplier = recorderedMsgs.stream().filter(msg -> msg.supplierId().equals(supplierId)).filter(msg -> msg.groupId() == CU.cacheId(cacheName)).filter(msg -> msg.hasFull() || msg.hasHistorical()).collect(toList());
        assertEquals("There should only two demand messages [supplierId=" + supplierId + ']', 2, demandMsgsForSupplier.size());
        assertTrue("The first message should require " + (mixed ? "mixed" : "historical") + " rebalance [msg=" + demandMsgsForSupplier.get(0) + ']', (mixed ? mixedPred.apply(demandMsgsForSupplier.get(0)) : histPred.apply(demandMsgsForSupplier.get(0))));
        assertTrue("The second message should require full rebalance [msg=" + demandMsgsForSupplier.get(0) + ']', fullPred.apply(demandMsgsForSupplier.get(1)));
    };
    supplierChecker.apply(grid(0).cluster().localNode().id(), true);
    supplierChecker.apply(grid(1).cluster().localNode().id(), false);
    // Check supplier3
    List<RecordedDemandMessage> demandMsgsForSupplier = recorderedMsgs.stream().filter(msg -> msg.supplierId().equals(grid(2).cluster().localNode().id())).filter(msg -> msg.groupId() == CU.cacheId(cacheName)).filter(msg -> msg.hasFull() || msg.hasHistorical()).collect(toList());
    assertEquals("There should only one demand message.", 1, demandMsgsForSupplier.size());
    assertTrue("The first message should require historical rebalance [msg=" + demandMsgsForSupplier.get(0) + ']', histPred.apply(demandMsgsForSupplier.get(0)));
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteEx(org.apache.ignite.internal.IgniteEx) GridDhtPartitionSupplyMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage) CacheRebalanceMode(org.apache.ignite.cache.CacheRebalanceMode) KeyCacheObjectImpl(org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) ByteBuffer(java.nio.ByteBuffer) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) IgniteSystemProperties(org.apache.ignite.IgniteSystemProperties) FileIO(org.apache.ignite.internal.processors.cache.persistence.file.FileIO) WalTestUtils(org.apache.ignite.internal.processors.cache.persistence.db.wal.crc.WalTestUtils) Map(java.util.Map) FileIODecorator(org.apache.ignite.internal.processors.cache.persistence.file.FileIODecorator) WALMode(org.apache.ignite.configuration.WALMode) RandomAccessFileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.RandomAccessFileIOFactory) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) QuerySqlField(org.apache.ignite.cache.query.annotations.QuerySqlField) GridCachePreloader(org.apache.ignite.internal.processors.cache.GridCachePreloader) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Set(java.util.Set) UUID(java.util.UUID) GridDhtPartitionDemander(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemander) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) DataRecord(org.apache.ignite.internal.pagemem.wal.record.DataRecord) DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) IgniteCache(org.apache.ignite.IgniteCache) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) Serializable(java.io.Serializable) StopNodeFailureHandler(org.apache.ignite.failure.StopNodeFailureHandler) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) GridDhtPartitionDemandMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage) CU(org.apache.ignite.internal.util.typedef.internal.CU) Message(org.apache.ignite.plugin.extensions.communication.Message) Queue(java.util.Queue) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteWriteAheadLogManager(org.apache.ignite.internal.pagemem.wal.IgniteWriteAheadLogManager) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) FileWriteAheadLogManager(org.apache.ignite.internal.processors.cache.persistence.wal.FileWriteAheadLogManager) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteDhtDemandedPartitionsMap(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.IgniteDhtDemandedPartitionsMap) IgniteWalIteratorFactory(org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) IgniteCallable(org.apache.ignite.lang.IgniteCallable) HashSet(java.util.HashSet) ClusterNodeAttributeAffinityBackupFilter(org.apache.ignite.cache.affinity.rendezvous.ClusterNodeAttributeAffinityBackupFilter) IgniteBiInClosure(org.apache.ignite.lang.IgniteBiInClosure) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) GridDhtPartitionsExchangeFuture(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture) CacheWriteSynchronizationMode(org.apache.ignite.cache.CacheWriteSynchronizationMode) S(org.apache.ignite.internal.util.typedef.internal.S) FileIOFactory(org.apache.ignite.internal.processors.cache.persistence.file.FileIOFactory) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) CheckpointListener(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener) FINISHED(org.apache.ignite.internal.processors.cache.persistence.CheckpointState.FINISHED) G(org.apache.ignite.internal.util.typedef.G) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) OpenOption(java.nio.file.OpenOption) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IOException(java.io.IOException) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) IGNITE_PDS_WAL_REBALANCE_THRESHOLD(org.apache.ignite.IgniteSystemProperties.IGNITE_PDS_WAL_REBALANCE_THRESHOLD) File(java.io.File) PartitionsExchangeAware(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.PartitionsExchangeAware) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) Collectors.toList(java.util.stream.Collectors.toList) Ignition(org.apache.ignite.Ignition) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Assert(org.junit.Assert) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) FileDescriptor(org.apache.ignite.internal.processors.cache.persistence.wal.FileDescriptor) CacheMode(org.apache.ignite.cache.CacheMode) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) ClusterNodeAttributeAffinityBackupFilter(org.apache.ignite.cache.affinity.rendezvous.ClusterNodeAttributeAffinityBackupFilter) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) UUID(java.util.UUID) GridDhtPartitionDemandMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionDemandMessage) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty)

Aggregations

ClusterNodeAttributeAffinityBackupFilter (org.apache.ignite.cache.affinity.rendezvous.ClusterNodeAttributeAffinityBackupFilter)4 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 File (java.io.File)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 ByteBuffer (java.nio.ByteBuffer)1 OpenOption (java.nio.file.OpenOption)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Queue (java.util.Queue)1 Set (java.util.Set)1 UUID (java.util.UUID)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)1 Collectors.toList (java.util.stream.Collectors.toList)1