Search in sources :

Example 21 with EntryEventImpl

use of org.apache.geode.internal.cache.EntryEventImpl in project geode by apache.

the class DistributedAckRegionCCEDUnitTest method testConcurrentOpWithGII.

/**
   * test for bug #45564. a create() is received by region creator and then a later destroy() is
   * received in initial image and while the version info from the destroy is recorded we keep the
   * value from the create event
   */
@Test
public void testConcurrentOpWithGII() {
    if (this.getClass() != DistributedAckRegionCCEDUnitTest.class) {
        // not really a scope-related thing
        return;
    }
    final String name = this.getUniqueName() + "-CC";
    final String key = "mykey";
    VM vm1 = Host.getHost(0).getVM(1);
    VM vm2 = Host.getHost(0).getVM(2);
    // create some destroyed entries so the GC service is populated
    SerializableCallable create = new SerializableCallable("create region") {

        public Object call() {
            RegionFactory f = getCache().createRegionFactory(getRegionAttributes());
            CCRegion = (LocalRegion) f.create(name);
            return CCRegion.getDistributionManager().getDistributionManagerId();
        }
    };
    // do conflicting update() and destroy() on the region. We want the update() to
    // be sent with a message and the destroy() to be transferred in the initial image
    // and be the value that we want to keep
    InternalDistributedMember vm1ID = (InternalDistributedMember) vm1.invoke(create);
    AsyncInvocation partialCreate = vm2.invokeAsync(new SerializableCallable("create region with stall") {

        public Object call() throws Exception {
            final GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            RegionFactory f = cache.createRegionFactory(getRegionAttributes());
            InitialImageOperation.VMOTION_DURING_GII = true;
            // this will stall region creation at the point of asking for an initial image
            VMotionObserverHolder.setInstance(new VMotionObserver() {

                @Override
                public void vMotionBeforeCQRegistration() {
                }

                @Override
                public void vMotionBeforeRegisterInterest() {
                }

                @Override
                public void vMotionDuringGII(Set recipientSet, LocalRegion region) {
                    InitialImageOperation.VMOTION_DURING_GII = false;
                    int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.BEFORE_INITIAL_IMAGE);
                    LocalRegion ccregion = cache.getRegionByPath("/" + name);
                    try {
                        // happen
                        while (!ccregion.isDestroyed() && ccregion.getRegionEntry(key) == null) {
                            try {
                                Thread.sleep(1000);
                            } catch (InterruptedException e) {
                                return;
                            }
                        }
                    } finally {
                        LocalRegion.setThreadInitLevelRequirement(oldLevel);
                    }
                }
            });
            try {
                CCRegion = (LocalRegion) f.create(name);
                // at this point we should have received the update op and then the GII, which should
                // overwrite
                // the conflicting update op
                assertFalse("expected initial image transfer to destroy entry", CCRegion.containsKey(key));
            } finally {
                InitialImageOperation.VMOTION_DURING_GII = false;
            }
            return null;
        }
    });
    vm1.invoke(new SerializableRunnable("create conflicting events") {

        public void run() {
            // wait for the other to come on line
            long waitEnd = System.currentTimeMillis() + 45000;
            DistributionAdvisor adv = ((DistributedRegion) CCRegion).getCacheDistributionAdvisor();
            while (System.currentTimeMillis() < waitEnd && adv.adviseGeneric().isEmpty()) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    return;
                }
            }
            if (adv.adviseGeneric().isEmpty()) {
                fail("other member never came on line");
            }
            // inhibit all messaging
            DistributedCacheOperation.LOSS_SIMULATION_RATIO = 200.0;
            try {
                CCRegion.put("mykey", "initialValue");
                CCRegion.destroy("mykey");
            } finally {
                DistributedCacheOperation.LOSS_SIMULATION_RATIO = 0.0;
            }
            // generate a fake version tag for the message
            VersionTag tag = CCRegion.getRegionEntry(key).getVersionStamp().asVersionTag();
            // create a fake member ID that will be < mine and lose a concurrency check
            NetMember nm = CCRegion.getDistributionManager().getDistributionManagerId().getNetMember();
            InternalDistributedMember mbr = null;
            try {
                mbr = new InternalDistributedMember(nm.getInetAddress().getCanonicalHostName(), nm.getPort() - 1, "fake_id", "fake_id_ustring", DistributionManager.NORMAL_DM_TYPE, null, null);
                tag.setMemberID(mbr);
            } catch (UnknownHostException e) {
                org.apache.geode.test.dunit.Assert.fail("could not create member id", e);
            }
            // generate an event to distribute that contains the fake version tag
            EntryEventImpl event = EntryEventImpl.create(CCRegion, Operation.UPDATE, key, false, mbr, true, false);
            event.setNewValue("newValue");
            event.setVersionTag(tag);
            // this should update the controller's cache with the updated value but leave this cache
            // alone
            DistributedCacheOperation op = new UpdateOperation(event, tag.getVersionTimeStamp());
            op.distribute();
            event.release();
        }
    });
    try {
        partialCreate.getResult();
    } catch (Throwable e) {
        org.apache.geode.test.dunit.Assert.fail("async invocation in vm2 failed", e);
    }
}
Also used : DistributionAdvisor(org.apache.geode.distributed.internal.DistributionAdvisor) DistributedCacheOperation(org.apache.geode.internal.cache.DistributedCacheOperation) Set(java.util.Set) UnknownHostException(java.net.UnknownHostException) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) VMotionObserver(org.apache.geode.internal.cache.vmotion.VMotionObserver) LocalRegion(org.apache.geode.internal.cache.LocalRegion) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) RegionClearedException(org.apache.geode.internal.cache.RegionClearedException) UnknownHostException(java.net.UnknownHostException) CacheException(org.apache.geode.cache.CacheException) RegionFactory(org.apache.geode.cache.RegionFactory) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) UpdateOperation(org.apache.geode.internal.cache.UpdateOperation) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) NetMember(org.apache.geode.distributed.internal.membership.NetMember) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 22 with EntryEventImpl

use of org.apache.geode.internal.cache.EntryEventImpl in project geode by apache.

the class ClientsWithVersioningRetryDUnitTest method testRetryPut.

/**
   * Test that we can successfully retry a distributed put all and get the version information.
   * second failure in bug 44951
   */
@Test
public void testRetryPut() {
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    final VM vm1 = host.getVM(1);
    createServerRegion(vm0, RegionShortcut.REPLICATE);
    createServerRegion(vm1, RegionShortcut.REPLICATE);
    // create an event tag in vm0 and then replay that event in vm1
    final DistributedMember memberID = (DistributedMember) vm0.invoke(new SerializableCallable("get id") {

        public Object call() {
            return ((DistributedRegion) getCache().getRegion("region")).getDistributionManager().getDistributionManagerId();
        }
    });
    vm0.invoke(new SerializableCallable("create entry with fake event ID") {

        @Override
        public Object call() {
            DistributedRegion dr = (DistributedRegion) getCache().getRegion("region");
            VersionTag tag = new VMVersionTag();
            tag.setMemberID(dr.getVersionMember());
            tag.setRegionVersion(123);
            tag.setEntryVersion(9);
            tag.setVersionTimeStamp(System.currentTimeMillis());
            EventID eventID = new EventID(new byte[0], 1, 0);
            EntryEventImpl event = EntryEventImpl.create(dr, Operation.CREATE, "TestObject", "TestValue", null, false, memberID, true, eventID);
            event.setVersionTag(tag);
            event.setContext(new ClientProxyMembershipID(memberID));
            dr.recordEvent(event);
            event.release();
            return memberID;
        }
    });
    vm1.invoke(new SerializableRunnable("recover event tag in vm1 from vm0") {

        @Override
        public void run() {
            DistributedRegion dr = (DistributedRegion) getCache().getRegion("region");
            EventID eventID = new EventID(new byte[0], 1, 0);
            EntryEventImpl event = EntryEventImpl.create(dr, Operation.CREATE, "TestObject", "TestValue", null, false, memberID, true, eventID);
            try {
                event.setContext(new ClientProxyMembershipID(memberID));
                boolean recovered = ((BaseCommand) Put70.getCommand()).recoverVersionTagForRetriedOperation(event);
                assertTrue("Expected to recover the version for this event ID", recovered);
                assertEquals("Expected the region version to be 123", 123, event.getVersionTag().getRegionVersion());
            } finally {
                event.release();
            }
        }
    });
    // bug #48205 - a retried op in PR nodes not owning the primary bucket
    // may already have a version assigned to it in another backup bucket
    vm1.invoke(new SerializableRunnable("recover posdup event tag in vm1 event tracker from vm0") {

        @Override
        public void run() {
            DistributedRegion dr = (DistributedRegion) getCache().getRegion("region");
            EventID eventID = new EventID(new byte[0], 1, 0);
            EntryEventImpl event = EntryEventImpl.create(dr, Operation.CREATE, "TestObject", "TestValue", null, false, memberID, true, eventID);
            event.setPossibleDuplicate(true);
            try {
                dr.hasSeenEvent(event);
                assertTrue("Expected to recover the version for the event ID", event.getVersionTag() != null);
            } finally {
                event.release();
            }
        }
    });
}
Also used : EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) DistributedMember(org.apache.geode.distributed.DistributedMember) VMVersionTag(org.apache.geode.internal.cache.versions.VMVersionTag) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) EventID(org.apache.geode.internal.cache.EventID) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) SerializationTest(org.apache.geode.test.junit.categories.SerializationTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 23 with EntryEventImpl

use of org.apache.geode.internal.cache.EntryEventImpl in project geode by apache.

the class DistTxEntryEvent method putAllFromData.

/**
   * @param in
   * @throws IOException
   * @throws ClassNotFoundException
   */
private void putAllFromData(DataInput in) throws IOException, ClassNotFoundException {
    int putAllSize = DataSerializer.readInteger(in);
    PutAllEntryData[] putAllEntries = new PutAllEntryData[putAllSize];
    if (putAllSize > 0) {
        final Version version = InternalDataSerializer.getVersionForDataStreamOrNull(in);
        final ByteArrayDataInput bytesIn = new ByteArrayDataInput();
        for (int i = 0; i < putAllSize; i++) {
            putAllEntries[i] = new PutAllEntryData(in, this.eventID, i, version, bytesIn);
        }
        boolean hasTags = in.readBoolean();
        if (hasTags) {
            EntryVersionsList versionTags = EntryVersionsList.create(in);
            for (int i = 0; i < putAllSize; i++) {
                putAllEntries[i].versionTag = versionTags.get(i);
            }
        }
    }
    // TODO DISTTX: release this event?
    EntryEventImpl e = EntryEventImpl.create(this.region, Operation.PUTALL_CREATE, null, null, null, true, this.getDistributedMember(), true, true);
    this.putAllOp = new DistributedPutAllOperation(e, putAllSize, false);
    this.putAllOp.setPutAllEntryData(putAllEntries);
}
Also used : EntryVersionsList(org.apache.geode.internal.cache.DistributedPutAllOperation.EntryVersionsList) Version(org.apache.geode.internal.Version) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) DistributedPutAllOperation(org.apache.geode.internal.cache.DistributedPutAllOperation) ByteArrayDataInput(org.apache.geode.internal.ByteArrayDataInput) PutAllEntryData(org.apache.geode.internal.cache.DistributedPutAllOperation.PutAllEntryData)

Example 24 with EntryEventImpl

use of org.apache.geode.internal.cache.EntryEventImpl in project geode by apache.

the class PartitionedTXRegionStub method postPutAll.

/**
   * Create PutAllPRMsgs for each bucket, and send them.
   * 
   * @param putallO DistributedPutAllOperation object.
   */
public void postPutAll(DistributedPutAllOperation putallO, VersionedObjectList successfulPuts, LocalRegion r) throws TransactionException {
    if (r.getCache().isCacheAtShutdownAll()) {
        throw new CacheClosedException("Cache is shutting down");
    }
    PartitionedRegion pr = (PartitionedRegion) r;
    final long startTime = PartitionedRegionStats.startTime();
    // build all the msgs by bucketid
    HashMap prMsgMap = putallO.createPRMessages();
    PutAllPartialResult partialKeys = new PutAllPartialResult(putallO.putAllDataSize);
    // this is rebuilt by this method
    successfulPuts.clear();
    Iterator itor = prMsgMap.entrySet().iterator();
    while (itor.hasNext()) {
        Map.Entry mapEntry = (Map.Entry) itor.next();
        Integer bucketId = (Integer) mapEntry.getKey();
        PutAllPRMessage prMsg = (PutAllPRMessage) mapEntry.getValue();
        pr.checkReadiness();
        try {
            VersionedObjectList versions = sendMsgByBucket(bucketId, prMsg, pr);
            // prMsg.saveKeySet(partialKeys);
            partialKeys.addKeysAndVersions(versions);
            successfulPuts.addAll(versions);
        } catch (PutAllPartialResultException pre) {
            // sendMsgByBucket applied partial keys
            partialKeys.consolidate(pre.getResult());
        } catch (Exception ex) {
            // If failed at other exception
            @Released EntryEventImpl firstEvent = prMsg.getFirstEvent(pr);
            try {
                partialKeys.saveFailedKey(firstEvent.getKey(), ex);
            } finally {
                firstEvent.release();
            }
        }
    }
    pr.prStats.endPutAll(startTime);
    if (partialKeys.hasFailure()) {
        pr.getCache().getLoggerI18n().info(LocalizedStrings.Region_PutAll_Applied_PartialKeys_0_1, new Object[] { pr.getFullPath(), partialKeys });
        if (putallO.isBridgeOperation()) {
            if (partialKeys.getFailure() instanceof CancelException) {
                throw (CancelException) partialKeys.getFailure();
            } else {
                throw new PutAllPartialResultException(partialKeys);
            }
        } else {
            if (partialKeys.getFailure() instanceof RuntimeException) {
                throw (RuntimeException) partialKeys.getFailure();
            } else {
                throw new RuntimeException(partialKeys.getFailure());
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) PutAllPartialResult(org.apache.geode.internal.cache.PutAllPartialResultException.PutAllPartialResult) CacheClosedException(org.apache.geode.cache.CacheClosedException) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) CacheClosedException(org.apache.geode.cache.CacheClosedException) TransactionDataNodeHasDepartedException(org.apache.geode.cache.TransactionDataNodeHasDepartedException) DataLocationException(org.apache.geode.internal.cache.DataLocationException) CancelException(org.apache.geode.CancelException) PutAllPartialResultException(org.apache.geode.internal.cache.PutAllPartialResultException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) BucketNotFoundException(org.apache.geode.internal.cache.BucketNotFoundException) PutAllPartialResultException(org.apache.geode.internal.cache.PutAllPartialResultException) Entry(org.apache.geode.cache.Region.Entry) PutAllPRMessage(org.apache.geode.internal.cache.partitioned.PutAllPRMessage) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Iterator(java.util.Iterator) CancelException(org.apache.geode.CancelException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 25 with EntryEventImpl

use of org.apache.geode.internal.cache.EntryEventImpl in project geode by apache.

the class PartitionedTXRegionStub method postRemoveAll.

@Override
public void postRemoveAll(DistributedRemoveAllOperation op, VersionedObjectList successfulOps, LocalRegion r) {
    if (r.getCache().isCacheAtShutdownAll()) {
        throw new CacheClosedException("Cache is shutting down");
    }
    PartitionedRegion pr = (PartitionedRegion) r;
    final long startTime = PartitionedRegionStats.startTime();
    // build all the msgs by bucketid
    HashMap<Integer, RemoveAllPRMessage> prMsgMap = op.createPRMessages();
    PutAllPartialResult partialKeys = new PutAllPartialResult(op.removeAllDataSize);
    // this is rebuilt by this method
    successfulOps.clear();
    Iterator<Map.Entry<Integer, RemoveAllPRMessage>> itor = prMsgMap.entrySet().iterator();
    while (itor.hasNext()) {
        Map.Entry<Integer, RemoveAllPRMessage> mapEntry = itor.next();
        Integer bucketId = mapEntry.getKey();
        RemoveAllPRMessage prMsg = mapEntry.getValue();
        pr.checkReadiness();
        try {
            VersionedObjectList versions = sendMsgByBucket(bucketId, prMsg, pr);
            // prMsg.saveKeySet(partialKeys);
            partialKeys.addKeysAndVersions(versions);
            successfulOps.addAll(versions);
        } catch (PutAllPartialResultException pre) {
            // sendMsgByBucket applied partial keys
            partialKeys.consolidate(pre.getResult());
        } catch (Exception ex) {
            // If failed at other exception
            @Released EntryEventImpl firstEvent = prMsg.getFirstEvent(pr);
            try {
                partialKeys.saveFailedKey(firstEvent.getKey(), ex);
            } finally {
                firstEvent.release();
            }
        }
    }
    pr.prStats.endRemoveAll(startTime);
    if (partialKeys.hasFailure()) {
        pr.getCache().getLoggerI18n().info(LocalizedStrings.Region_RemoveAll_Applied_PartialKeys_0_1, new Object[] { pr.getFullPath(), partialKeys });
        if (op.isBridgeOperation()) {
            if (partialKeys.getFailure() instanceof CancelException) {
                throw (CancelException) partialKeys.getFailure();
            } else {
                throw new PutAllPartialResultException(partialKeys);
            }
        } else {
            if (partialKeys.getFailure() instanceof RuntimeException) {
                throw (RuntimeException) partialKeys.getFailure();
            } else {
                throw new RuntimeException(partialKeys.getFailure());
            }
        }
    }
}
Also used : EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) RemoveAllPRMessage(org.apache.geode.internal.cache.partitioned.RemoveAllPRMessage) PutAllPartialResult(org.apache.geode.internal.cache.PutAllPartialResultException.PutAllPartialResult) CacheClosedException(org.apache.geode.cache.CacheClosedException) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) CacheClosedException(org.apache.geode.cache.CacheClosedException) TransactionDataNodeHasDepartedException(org.apache.geode.cache.TransactionDataNodeHasDepartedException) DataLocationException(org.apache.geode.internal.cache.DataLocationException) CancelException(org.apache.geode.CancelException) PutAllPartialResultException(org.apache.geode.internal.cache.PutAllPartialResultException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) BucketNotFoundException(org.apache.geode.internal.cache.BucketNotFoundException) PutAllPartialResultException(org.apache.geode.internal.cache.PutAllPartialResultException) Entry(org.apache.geode.cache.Region.Entry) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) CancelException(org.apache.geode.CancelException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)34 EventID (org.apache.geode.internal.cache.EventID)14 Released (org.apache.geode.internal.offheap.annotations.Released)8 HashMap (java.util.HashMap)7 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)7 Map (java.util.Map)6 CacheWriterException (org.apache.geode.cache.CacheWriterException)6 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)6 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)6 PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)6 PrimaryBucketException (org.apache.geode.internal.cache.PrimaryBucketException)6 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)6 CancelException (org.apache.geode.CancelException)5 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)5 LocalRegion (org.apache.geode.internal.cache.LocalRegion)5 PutAllPartialResultException (org.apache.geode.internal.cache.PutAllPartialResultException)5 VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)5 CacheException (org.apache.geode.cache.CacheException)4 ReplyException (org.apache.geode.distributed.internal.ReplyException)4 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)4