Search in sources :

Example 6 with EntryEventImpl

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

the class DestroyMessage method operateOnPartitionedRegion.

/**
   * This method is called upon receipt and make the desired changes to the PartitionedRegion Note:
   * It is very important that this message does NOT cause any deadlocks as the sender will wait
   * indefinitely for the acknowledgement
   */
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion r, long startTime) throws EntryExistsException, DataLocationException {
    InternalDistributedMember eventSender = originalSender;
    if (eventSender == null) {
        eventSender = getSender();
    }
    @Released EntryEventImpl event = null;
    try {
        if (this.bridgeContext != null) {
            event = EntryEventImpl.create(r, getOperation(), this.key, null, /* newValue */
            getCallbackArg(), false, /* originRemote */
            eventSender, true);
            event.setContext(this.bridgeContext);
        } else // bridgeContext != null
        {
            event = EntryEventImpl.create(r, getOperation(), this.key, null, /* newValue */
            getCallbackArg(), false, /* originRemote - false to force distribution in buckets */
            eventSender, true, /* generateCallbacks */
            false);
        }
        if (this.versionTag != null) {
            this.versionTag.replaceNullIDs(getSender());
            event.setVersionTag(this.versionTag);
        }
        event.setInvokePRCallbacks(!notificationOnly);
        Assert.assertTrue(eventId != null);
        event.setEventId(eventId);
        event.setPossibleDuplicate(this.posDup);
        PartitionedRegionDataStore ds = r.getDataStore();
        boolean sendReply = true;
        if (!notificationOnly) {
            Assert.assertTrue(ds != null, "This process should have storage for an item in " + this.toString());
            try {
                Integer bucket = Integer.valueOf(PartitionedRegionHelper.getHashKey(r, null, this.key, null, this.cbArg));
                // try {
                // // the event must show its true origin for cachewriter invocation
                // event.setOriginRemote(true);
                // event.setPartitionMessage(this);
                // r.doCacheWriteBeforeDestroy(event);
                // }
                // finally {
                // event.setOriginRemote(false);
                // }
                event.setCausedByMessage(this);
                r.getDataView().destroyOnRemote(event, true, /* cacheWrite */
                this.expectedOldValue);
                if (logger.isTraceEnabled(LogMarker.DM)) {
                    logger.trace(LogMarker.DM, "{} updated bucket: {} with key: {}", getClass().getName(), bucket, this.key);
                }
            } catch (CacheWriterException cwe) {
                sendReply(getSender(), this.processorId, dm, new ReplyException(cwe), r, startTime);
                return false;
            } catch (EntryNotFoundException eee) {
                logger.trace(LogMarker.DM, "{}: operateOnRegion caught EntryNotFoundException", getClass().getName());
                ReplyMessage.send(getSender(), getProcessorId(), new ReplyException(eee), getReplySender(dm), r.isInternalRegion());
                // this prevents us from acking later
                sendReply = false;
            } catch (PrimaryBucketException pbe) {
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
                sendReply = false;
            } finally {
                this.versionTag = event.getVersionTag();
            }
        } else {
            @Released EntryEventImpl e2 = createListenerEvent(event, r, dm.getDistributionManagerId());
            try {
                r.invokeDestroyCallbacks(EnumListenerEvent.AFTER_DESTROY, e2, r.isInitialized(), true);
            } finally {
                // if e2 == ev then no need to free it here. The outer finally block will get it.
                if (e2 != event) {
                    e2.release();
                }
            }
        }
        return sendReply;
    } finally {
        if (event != null) {
            event.release();
        }
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) ReplyException(org.apache.geode.distributed.internal.ReplyException) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 7 with EntryEventImpl

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

the class DestroyMessage method createListenerEvent.

/**
   * create a new EntryEvent to be used in notifying listeners, bridge servers, etc. Caller must
   * release result if it is != to sourceEvent
   */
@Retained
EntryEventImpl createListenerEvent(EntryEventImpl sourceEvent, PartitionedRegion r, InternalDistributedMember member) {
    final EntryEventImpl e2;
    if (this.notificationOnly && this.bridgeContext == null) {
        e2 = sourceEvent;
    } else {
        e2 = new EntryEventImpl(sourceEvent);
        if (this.bridgeContext != null) {
            e2.setContext(this.bridgeContext);
        }
    }
    e2.setRegion(r);
    e2.setOriginRemote(true);
    e2.setInvokePRCallbacks(!notificationOnly);
    if (this.filterInfo != null) {
        e2.setLocalFilterInfo(this.filterInfo.getFilterInfo(member));
    }
    if (this.versionTag != null) {
        this.versionTag.replaceNullIDs(getSender());
        e2.setVersionTag(this.versionTag);
    }
    return e2;
}
Also used : EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) Retained(org.apache.geode.internal.offheap.annotations.Retained)

Example 8 with EntryEventImpl

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

the class InvalidateMessage method operateOnPartitionedRegion.

/**
   * This method is called upon receipt and make the desired changes to the PartitionedRegion Note:
   * It is very important that this message does NOT cause any deadlocks as the sender will wait
   * indefinitely for the acknowledgement
   * 
   * @throws EntryExistsException
   * @throws DataLocationException
   */
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion r, long startTime) throws EntryExistsException, DataLocationException {
    InternalDistributedMember eventSender = originalSender;
    if (eventSender == null) {
        eventSender = getSender();
    }
    final Object key = getKey();
    @Released final EntryEventImpl event = EntryEventImpl.create(r, getOperation(), key, null, /* newValue */
    getCallbackArg(), false, /* originRemote - false to force distribution in buckets */
    eventSender, true, /* generateCallbacks */
    false);
    try {
        if (this.versionTag != null) {
            this.versionTag.replaceNullIDs(getSender());
            event.setVersionTag(this.versionTag);
        }
        if (this.bridgeContext != null) {
            event.setContext(this.bridgeContext);
        }
        // Assert.assertTrue(eventId != null); bug #47235: region invalidation doesn't send event ids
        event.setEventId(eventId);
        event.setPossibleDuplicate(this.posDup);
        PartitionedRegionDataStore ds = r.getDataStore();
        boolean sendReply = true;
        // boolean failed = false;
        event.setInvokePRCallbacks(!notificationOnly);
        if (!notificationOnly) {
            Assert.assertTrue(ds != null, "This process should have storage for an item in " + this.toString());
            try {
                Integer bucket = Integer.valueOf(PartitionedRegionHelper.getHashKey(event));
                event.setCausedByMessage(this);
                r.getDataView().invalidateOnRemote(event, true, /* invokeCallbacks */
                false);
                this.versionTag = event.getVersionTag();
                if (logger.isTraceEnabled(LogMarker.DM)) {
                    logger.trace(LogMarker.DM, "{} invalidateLocally in bucket: {}, key: {}", getClass().getName(), bucket, key);
                }
            } catch (DataLocationException e) {
                ((ForceReattemptException) e).checkKey(event.getKey());
                throw e;
            } catch (EntryNotFoundException eee) {
                // failed = true;
                if (logger.isDebugEnabled()) {
                    logger.debug("{}: operateOnRegion caught EntryNotFoundException {}", getClass().getName(), eee.getMessage(), eee);
                }
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(eee), r, startTime);
                // this prevents us from acking later
                sendReply = false;
            } catch (PrimaryBucketException pbe) {
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
                return false;
            }
        } else {
            event.setRegion(r);
            event.setOriginRemote(true);
            if (this.versionTag != null) {
                this.versionTag.replaceNullIDs(getSender());
                event.setVersionTag(this.versionTag);
            }
            if (this.filterInfo != null) {
                event.setLocalFilterInfo(this.filterInfo.getFilterInfo(dm.getDistributionManagerId()));
            }
            r.invokeInvalidateCallbacks(EnumListenerEvent.AFTER_INVALIDATE, event, r.isInitialized());
        }
        return sendReply;
    } finally {
        event.release();
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DataLocationException(org.apache.geode.internal.cache.DataLocationException) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 9 with EntryEventImpl

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

the class DistTxEntryEvent method removeAllFromData.

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

Example 10 with EntryEventImpl

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

the class BatchDestroyOperation method initMessage.

@Override
protected void initMessage(CacheOperationMessage msg, DirectReplyProcessor processor) {
    super.initMessage(msg, processor);
    DestroyMessage m = (DestroyMessage) msg;
    EntryEventImpl event = getEvent();
    m.key = event.getKey();
    m.eventId = event.getEventId();
}
Also used : EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl)

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