Search in sources :

Example 11 with SingleNodeMessage

use of org.apache.ignite.internal.util.distributed.SingleNodeMessage in project ignite by apache.

the class CacheGroupKeyChangeTest method checkNodeFailsDuringRotation.

/**
 * @param stopCrd {@code True} to stop coordinator.
 * @param prepare {@code True} to stop on the prepare phase. {@code False} to stop on the perform phase.
 * @param discoBlock  {@code True} to block discovery, {@code False} to block communication SPI.
 */
private void checkNodeFailsDuringRotation(boolean stopCrd, boolean prepare, boolean discoBlock) throws Exception {
    cleanPersistenceDir();
    DistributedProcessType type = prepare ? DistributedProcessType.CACHE_GROUP_KEY_CHANGE_PREPARE : DistributedProcessType.CACHE_GROUP_KEY_CHANGE_FINISH;
    InitMessageDiscoveryHook locHook = new InitMessageDiscoveryHook(type);
    if (discoBlock && stopCrd)
        discoveryHook = locHook;
    IgniteEx grid0 = startGrid(GRID_0);
    if (discoBlock && !stopCrd)
        discoveryHook = locHook;
    IgniteEx grid1 = startGrid(GRID_1);
    grid0.cluster().state(ClusterState.ACTIVE);
    createEncryptedCache(grid0, grid1, cacheName(), null);
    int grpId = CU.cacheId(cacheName());
    checkGroupKey(grpId, INITIAL_KEY_ID, MAX_AWAIT_MILLIS);
    TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(grid1);
    if (!discoBlock) {
        AtomicBoolean preparePhase = new AtomicBoolean(true);
        spi.blockMessages((node, msg) -> {
            if (msg instanceof SingleNodeMessage) {
                boolean isPrepare = preparePhase.compareAndSet(true, false);
                return prepare || !isPrepare;
            }
            return false;
        });
    }
    String alive = stopCrd ? GRID_1 : GRID_0;
    String stopped = stopCrd ? GRID_0 : GRID_1;
    IgniteFuture<Void> changeFut = grid(alive).encryption().changeCacheGroupKey(Collections.singleton(cacheName()));
    IgniteInternalFuture<?> stopFut = new GridFinishedFuture<>();
    if (discoBlock) {
        locHook.waitForBlocked(MAX_AWAIT_MILLIS);
        stopGrid(stopped, true);
        locHook.stopBlock();
    } else {
        spi.waitForBlocked();
        stopFut = runAsync(() -> stopGrid(stopped, true));
    }
    changeFut.get(MAX_AWAIT_MILLIS);
    stopFut.get(MAX_AWAIT_MILLIS);
    checkGroupKey(grpId, INITIAL_KEY_ID + 1, MAX_AWAIT_MILLIS);
    IgniteEx stoppedNode = startGrid(stopped);
    stoppedNode.resetLostPartitions(Collections.singleton(ENCRYPTED_CACHE));
    awaitPartitionMapExchange();
    checkGroupKey(grpId, INITIAL_KEY_ID + 1, MAX_AWAIT_MILLIS);
    stoppedNode.encryption().changeCacheGroupKey(Collections.singleton(cacheName())).get(MAX_AWAIT_MILLIS);
    checkGroupKey(grpId, INITIAL_KEY_ID + 2, MAX_AWAIT_MILLIS);
}
Also used : GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteEx(org.apache.ignite.internal.IgniteEx) DistributedProcessType(org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType) SingleNodeMessage(org.apache.ignite.internal.util.distributed.SingleNodeMessage)

Example 12 with SingleNodeMessage

use of org.apache.ignite.internal.util.distributed.SingleNodeMessage in project ignite by apache.

the class MasterKeyChangeTest method testRejectNodeJoinDuringRotation.

/**
 * @throws Exception If failed.
 */
@Test
public void testRejectNodeJoinDuringRotation() throws Exception {
    T2<IgniteEx, IgniteEx> grids = startTestGrids(true);
    createEncryptedCache(grids.get1(), grids.get2(), cacheName(), null);
    assertTrue(checkMasterKeyName(DEFAULT_MASTER_KEY_NAME));
    TestRecordingCommunicationSpi commSpi = TestRecordingCommunicationSpi.spi(grids.get2());
    commSpi.blockMessages((node, msg) -> msg instanceof SingleNodeMessage);
    IgniteFuture<Void> fut = grids.get1().encryption().changeMasterKey(MASTER_KEY_NAME_2);
    commSpi.waitForBlocked();
    assertThrowsWithCause(() -> startGrid(3), IgniteCheckedException.class);
    commSpi.stopBlock();
    fut.get();
    assertTrue(checkMasterKeyName(MASTER_KEY_NAME_2));
    checkEncryptedCaches(grids.get1(), grids.get2());
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteEx(org.apache.ignite.internal.IgniteEx) SingleNodeMessage(org.apache.ignite.internal.util.distributed.SingleNodeMessage) Test(org.junit.Test)

Example 13 with SingleNodeMessage

use of org.apache.ignite.internal.util.distributed.SingleNodeMessage in project ignite by apache.

the class MasterKeyChangeTest method checkNodeFailsDuringRotation.

/**
 * @param stopCrd {@code True} if stop coordinator.
 * @param prepare {@code True} if stop on the prepare phase. {@code False} if stop on the perform phase.
 */
private void checkNodeFailsDuringRotation(boolean stopCrd, boolean prepare) throws Exception {
    T2<IgniteEx, IgniteEx> grids = startTestGrids(true);
    createEncryptedCache(grids.get1(), grids.get2(), cacheName(), null);
    assertTrue(checkMasterKeyName(DEFAULT_MASTER_KEY_NAME));
    TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(grids.get2());
    AtomicBoolean preparePhase = new AtomicBoolean(true);
    spi.blockMessages((node, msg) -> {
        if (msg instanceof SingleNodeMessage) {
            boolean isPrepare = preparePhase.compareAndSet(true, false);
            return prepare || !isPrepare;
        }
        return false;
    });
    IgniteEx aliveNode = stopCrd ? grids.get2() : grids.get1();
    IgniteFuture<Void> fut = aliveNode.encryption().changeMasterKey(MASTER_KEY_NAME_2);
    spi.waitForBlocked();
    runAsync(() -> {
        if (stopCrd)
            stopGrid(GRID_0, true);
        else
            stopGrid(GRID_1, true);
    });
    fut.get();
    assertEquals(MASTER_KEY_NAME_2, aliveNode.encryption().getMasterKeyName());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteEx(org.apache.ignite.internal.IgniteEx) SingleNodeMessage(org.apache.ignite.internal.util.distributed.SingleNodeMessage)

Aggregations

IgniteEx (org.apache.ignite.internal.IgniteEx)13 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)13 SingleNodeMessage (org.apache.ignite.internal.util.distributed.SingleNodeMessage)13 Test (org.junit.Test)11 File (java.io.File)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 DistributedProcessType (org.apache.ignite.internal.util.distributed.DistributedProcess.DistributedProcessType)2 IOException (java.io.IOException)1 OpenOption (java.nio.file.OpenOption)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 UUID (java.util.UUID)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1