Search in sources :

Example 16 with DistributionMessage

use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.

the class PersistentRecoveryOrderDUnitTest method testFinishIncompleteInitializationNoSend.

@Test
public void testFinishIncompleteInitializationNoSend() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    // Add a hook which will disconnect the DS before sending a prepare message
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void beforeSendMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof PrepareNewPersistentMemberMessage) {
                        DistributionMessageObserver.setInstance(null);
                        getSystem().disconnect();
                    }
                }

                @Override
                public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
                }
            });
        }
    });
    createPersistentRegion(vm0);
    putAnEntry(vm0);
    updateTheEntry(vm0);
    try {
        createPersistentRegion(vm1);
    } catch (Exception e) {
        if (!(e.getCause() instanceof DistributedSystemDisconnectedException)) {
            throw e;
        }
    }
    closeRegion(vm0);
    // This wait for VM0 to come back
    AsyncInvocation async1 = createPersistentRegionAsync(vm1);
    waitForBlockedInitialization(vm1);
    createPersistentRegion(vm0);
    async1.getResult();
    checkForEntry(vm1);
    vm0.invoke(new SerializableRunnable("check for offline members") {

        public void run() {
            Cache cache = getCache();
            DistributedRegion region = (DistributedRegion) cache.getRegion(REGION_NAME);
            PersistentMembershipView view = region.getPersistenceAdvisor().getMembershipView();
            DiskRegion dr = region.getDiskRegion();
            assertEquals(Collections.emptySet(), dr.getOfflineMembers());
            assertEquals(1, dr.getOnlineMembers().size());
        }
    });
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) RevokedPersistentDataException(org.apache.geode.cache.persistence.RevokedPersistentDataException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) AdminException(org.apache.geode.admin.AdminException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) LockServiceDestroyedException(org.apache.geode.distributed.LockServiceDestroyedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) PersistentReplicatesOfflineException(org.apache.geode.cache.persistence.PersistentReplicatesOfflineException) IOException(java.io.IOException) DiskRegion(org.apache.geode.internal.cache.DiskRegion) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 17 with DistributionMessage

use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.

the class PersistentRVVRecoveryDUnitTest method testSkipConflictChecksForConcurrentOps.

/**
   * Test that we skip conflict checks with entries that are on disk compared to entries that come
   * in as part of a concurrent operation
   */
@Test
public void testSkipConflictChecksForConcurrentOps() throws Throwable {
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    // Create the region in few members to test recovery
    createPersistentRegion(vm0);
    createPersistentRegion(vm1);
    // Create an update some entries in vm0 and vm1.
    createData(vm0, 0, 1, "value1");
    createData(vm0, 0, 1, "value2");
    createData(vm0, 0, 1, "value2");
    closeCache(vm1);
    // Update the keys in vm0 until the entry version rolls over.
    // This means that if we did a conflict check, vm0's key will have
    // a lower entry version than vm1, which would cause us to prefer vm1's
    // value
    SerializableRunnable createData = new SerializableRunnable("rollEntryVersion") {

        public void run() {
            Cache cache = getCache();
            LocalRegion region = (LocalRegion) cache.getRegion(REGION_NAME);
            region.put(0, "value3");
            RegionEntry entry = region.getRegionEntry(0);
            entry = region.getRegionEntry(0);
            // Sneak in and change the version number for an entry to generate
            // a conflict.
            VersionTag tag = entry.getVersionStamp().asVersionTag();
            tag.setEntryVersion(tag.getEntryVersion() - 2);
            entry.getVersionStamp().setVersions(tag);
        }
    };
    vm0.invoke(createData);
    // Add an observer to vm0 which will perform a concurrent operation during
    // the GII. If we do a conflict check, this operation will be rejected
    // because it will have a lower entry version that what vm1 recovered from
    // disk
    vm0.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage msg) {
                    if (msg instanceof InitialImageOperation.RequestImageMessage) {
                        if (((InitialImageOperation.RequestImageMessage) msg).regionPath.contains(REGION_NAME)) {
                            createData(vm0, 0, 1, "value4");
                            DistributionMessageObserver.setInstance(null);
                        }
                    }
                }
            });
        }
    });
    // Create vm1, doing a GII
    createPersistentRegion(vm1);
    // If we did a conflict check, this would be value2
    checkData(vm0, 0, 1, "value4");
    checkData(vm1, 0, 1, "value4");
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) RegionEntry(org.apache.geode.internal.cache.RegionEntry) InitialImageOperation(org.apache.geode.internal.cache.InitialImageOperation) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 18 with DistributionMessage

use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.

the class StreamingPartitionOperation method getPartitionedDataFrom.

/**
   * Returns normally if succeeded to get data, otherwise throws an exception
   */
public Set<InternalDistributedMember> getPartitionedDataFrom(Set recipients) throws org.apache.geode.cache.TimeoutException, InterruptedException, QueryException, ForceReattemptException {
    if (Thread.interrupted())
        throw new InterruptedException();
    if (recipients.isEmpty())
        return Collections.emptySet();
    StreamingPartitionResponse processor = new StreamingPartitionResponse(this.sys, recipients);
    DistributionMessage m = createRequestMessage(recipients, processor);
    this.sys.getDistributionManager().putOutgoing(m);
    // should we allow this to timeout?
    Set<InternalDistributedMember> failedMembers = processor.waitForCacheOrQueryException();
    return failedMembers;
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage)

Example 19 with DistributionMessage

use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.

the class JGroupsMessenger method createJGMessage.

/**
   * This is the constructor to use to create a JGroups message holding a GemFire
   * DistributionMessage. It sets the appropriate flags in the Message and properly serializes the
   * DistributionMessage for the recipient's product version
   * 
   * @param gfmsg the DistributionMessage
   * @param src the sender address
   * @param version the version of the recipient
   * @return the new message
   */
Message createJGMessage(DistributionMessage gfmsg, JGAddress src, short version) {
    if (gfmsg instanceof DirectReplyMessage) {
        ((DirectReplyMessage) gfmsg).registerProcessor();
    }
    Message msg = new Message();
    msg.setDest(null);
    msg.setSrc(src);
    setMessageFlags(gfmsg, msg);
    try {
        long start = services.getStatistics().startMsgSerialization();
        HeapDataOutputStream out_stream = new HeapDataOutputStream(Version.fromOrdinalOrCurrent(version));
        Version.CURRENT.writeOrdinal(out_stream, true);
        if (encrypt != null) {
            out_stream.writeBoolean(true);
            writeEncryptedMessage(gfmsg, version, out_stream);
        } else {
            out_stream.writeBoolean(false);
            serializeMessage(gfmsg, out_stream);
        }
        msg.setBuffer(out_stream.toByteArray());
        services.getStatistics().endMsgSerialization(start);
    } catch (IOException | GemFireIOException ex) {
        logger.warn("Error serializing message", ex);
        if (ex instanceof GemFireIOException) {
            throw (GemFireIOException) ex;
        } else {
            GemFireIOException ioe = new GemFireIOException("Error serializing message");
            ioe.initCause(ex);
            throw ioe;
        }
    } catch (Exception ex) {
        logger.warn("Error serializing message", ex);
        GemFireIOException ioe = new GemFireIOException("Error serializing message");
        ioe.initCause(ex.getCause());
        throw ioe;
    }
    return msg;
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) DirectReplyMessage(org.apache.geode.internal.cache.DirectReplyMessage) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) LocalizedMessage(org.apache.geode.internal.logging.log4j.LocalizedMessage) Message(org.jgroups.Message) HighPriorityDistributionMessage(org.apache.geode.distributed.internal.HighPriorityDistributionMessage) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) GemFireIOException(org.apache.geode.GemFireIOException) GemFireIOException(org.apache.geode.GemFireIOException) IOException(java.io.IOException) MemberShunnedException(org.apache.geode.internal.tcp.MemberShunnedException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) GemFireIOException(org.apache.geode.GemFireIOException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) DirectReplyMessage(org.apache.geode.internal.cache.DirectReplyMessage)

Example 20 with DistributionMessage

use of org.apache.geode.distributed.internal.DistributionMessage in project geode by apache.

the class PartitionedRegionFunctionResultWaiter method getPartitionedDataFrom.

/**
   * Returns normally if succeeded to get data, otherwise throws an exception Have to wait outside
   * this function and when getResult() is called. For the time being get the correct results.
   */
public ResultCollector getPartitionedDataFrom(Map<InternalDistributedMember, FunctionRemoteContext> recipMap, PartitionedRegion pr, AbstractExecution execution) {
    if (recipMap.isEmpty()) {
        return this.rc;
    }
    Set<InternalDistributedMember> recipientsSet = new HashSet<InternalDistributedMember>();
    for (InternalDistributedMember member : recipMap.keySet()) {
        recipientsSet.add(member);
    }
    this.recipients = recipientsSet;
    PRFunctionStreamingResultCollector processor = new PRFunctionStreamingResultCollector(this, this.sys, recipientsSet, this.rc, functionObject, pr, execution);
    this.reply = processor;
    for (Map.Entry<InternalDistributedMember, FunctionRemoteContext> entry : recipMap.entrySet()) {
        FunctionRemoteContext context = entry.getValue();
        DistributionMessage m = createRequestMessage(entry.getKey(), processor, context);
        this.sys.getDistributionManager().putOutgoing(m);
    }
    return processor;
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) Map(java.util.Map) PRFunctionStreamingResultCollector(org.apache.geode.internal.cache.partitioned.PRFunctionStreamingResultCollector) HashSet(java.util.HashSet)

Aggregations

DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)51 Test (org.junit.Test)34 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)29 DistributionMessageObserver (org.apache.geode.distributed.internal.DistributionMessageObserver)29 VM (org.apache.geode.test.dunit.VM)28 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)28 Host (org.apache.geode.test.dunit.Host)27 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)22 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)13 IOException (java.io.IOException)11 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)11 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)11 Cache (org.apache.geode.cache.Cache)9 IgnoredException (org.apache.geode.test.dunit.IgnoredException)9 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)8 DataInputStream (java.io.DataInputStream)7 RequestImageMessage (org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage)7 Properties (java.util.Properties)6 CacheClosedException (org.apache.geode.cache.CacheClosedException)6 Region (org.apache.geode.cache.Region)6