Search in sources :

Example 31 with Released

use of org.apache.geode.internal.offheap.annotations.Released in project geode by apache.

the class LocalRegion method localDestroy.

@Override
public void localDestroy(Object key, Object aCallbackArgument) throws EntryNotFoundException {
    validateKey(key);
    checkReadiness();
    checkForNoAccess();
    @Released EntryEventImpl event = EntryEventImpl.create(this, Operation.LOCAL_DESTROY, key, null, aCallbackArgument, false, getMyId());
    if (generateEventID()) {
        event.setNewEventId(this.cache.getDistributedSystem());
    }
    try {
        // expectedOldValue
        basicDestroy(event, false, null);
    } catch (CacheWriterException e) {
        // cache writer not called
        throw new Error(LocalizedStrings.LocalRegion_CACHE_WRITER_SHOULD_NOT_HAVE_BEEN_CALLED_FOR_LOCALDESTROY.toLocalizedString(), e);
    } catch (TimeoutException e) {
        // no distributed lock
        throw new Error(LocalizedStrings.LocalRegion_NO_DISTRIBUTED_LOCK_SHOULD_HAVE_BEEN_ATTEMPTED_FOR_LOCALDESTROY.toLocalizedString(), e);
    } finally {
        event.release();
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) InternalGemFireError(org.apache.geode.InternalGemFireError) CacheWriterException(org.apache.geode.cache.CacheWriterException) TimeoutException(org.apache.geode.cache.TimeoutException)

Example 32 with Released

use of org.apache.geode.internal.offheap.annotations.Released in project geode by apache.

the class ConcurrentSerialGatewaySenderEventProcessor method enqueueEvent.

public void enqueueEvent(EnumListenerEvent operation, EntryEvent event, Object substituteValue, int index) throws CacheException, IOException {
    // Get the appropriate gateway
    SerialGatewaySenderEventProcessor serialProcessor = this.processors.get(index);
    if (sender.getOrderPolicy() == OrderPolicy.KEY || sender.getOrderPolicy() == OrderPolicy.PARTITION) {
        // Create copy since the event id will be changed, otherwise the same
        // event will be changed for multiple gateways. Fix for bug 44471.
        @Released EntryEventImpl clonedEvent = new EntryEventImpl((EntryEventImpl) event);
        try {
            EventID originalEventId = clonedEvent.getEventId();
            if (logger.isDebugEnabled()) {
                logger.debug("The original EventId is {}", originalEventId);
            }
            // PARALLEL_THREAD_BUFFER * (index +1) + originalEventId.getThreadID();
            // generating threadId by the algorithm explained above used to clash with
            // fakeThreadId generated by putAll
            // below is new way to generate threadId so that it doesn't clash with
            // any.
            long newThreadId = ThreadIdentifier.createFakeThreadIDForParallelGateway(index, originalEventId.getThreadID(), 0);
            EventID newEventId = new EventID(originalEventId.getMembershipID(), newThreadId, originalEventId.getSequenceID());
            if (logger.isDebugEnabled()) {
                logger.debug("{}: Generated event id for event with key={}, index={}, original event id={}, threadId={}, new event id={}, newThreadId={}", this, event.getKey(), index, originalEventId, originalEventId.getThreadID(), newEventId, newThreadId);
            }
            clonedEvent.setEventId(newEventId);
            serialProcessor.enqueueEvent(operation, clonedEvent, substituteValue);
        } finally {
            clonedEvent.release();
        }
    } else {
        serialProcessor.enqueueEvent(operation, event, substituteValue);
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) EventID(org.apache.geode.internal.cache.EventID)

Example 33 with Released

use of org.apache.geode.internal.offheap.annotations.Released in project geode by apache.

the class AbstractGatewaySender method distribute.

public void distribute(EnumListenerEvent operation, EntryEventImpl event, List<Integer> allRemoteDSIds) {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    // If this gateway is not running, return
    if (!isRunning()) {
        if (isDebugEnabled) {
            logger.debug("Returning back without putting into the gateway sender queue");
        }
        return;
    }
    final GatewaySenderStats stats = getStatistics();
    stats.incEventsReceived();
    if (!checkForDistribution(event, stats)) {
        stats.incEventsNotQueued();
        return;
    }
    // not considering this filter
    if (!this.filter.enqueueEvent(event)) {
        stats.incEventsFiltered();
        return;
    }
    // released by this method or transfers ownership to TmpQueueEvent
    @Released EntryEventImpl clonedEvent = new EntryEventImpl(event, false);
    boolean freeClonedEvent = true;
    try {
        Region region = event.getRegion();
        setModifiedEventId(clonedEvent);
        Object callbackArg = clonedEvent.getRawCallbackArgument();
        if (isDebugEnabled) {
            // We can't deserialize here for logging purposes so don't
            // call getNewValue.
            // event.getNewValue(); // to deserialize the value if necessary
            logger.debug("{} : About to notify {} to perform operation {} for {} callback arg {}", this.isPrimary(), getId(), operation, clonedEvent, callbackArg);
        }
        if (callbackArg instanceof GatewaySenderEventCallbackArgument) {
            GatewaySenderEventCallbackArgument seca = (GatewaySenderEventCallbackArgument) callbackArg;
            if (isDebugEnabled) {
                logger.debug("{}: Event originated in {}. My DS id is {}. The remote DS id is {}. The recipients are: {}", this, seca.getOriginatingDSId(), this.getMyDSId(), this.getRemoteDSId(), seca.getRecipientDSIds());
            }
            if (seca.getOriginatingDSId() == DEFAULT_DISTRIBUTED_SYSTEM_ID) {
                if (isDebugEnabled) {
                    logger.debug("{}: Event originated in {}. My DS id is {}. The remote DS id is {}. The recipients are: {}", this, seca.getOriginatingDSId(), this.getMyDSId(), this.getRemoteDSId(), seca.getRecipientDSIds());
                }
                seca.setOriginatingDSId(this.getMyDSId());
                seca.initializeReceipientDSIds(allRemoteDSIds);
            } else {
                // if the dispatcher is GatewaySenderEventCallbackDispatcher (which is the case of WBCL),
                // skip the below check of remoteDSId.
                // Fix for #46517
                AbstractGatewaySenderEventProcessor ep = getEventProcessor();
                if (ep != null && !(ep.getDispatcher() instanceof GatewaySenderEventCallbackDispatcher)) {
                    if (seca.getOriginatingDSId() == this.getRemoteDSId()) {
                        if (isDebugEnabled) {
                            logger.debug("{}: Event originated in {}. My DS id is {}. It is being dropped as remote is originator.", this, seca.getOriginatingDSId(), getMyDSId());
                        }
                        return;
                    } else if (seca.getRecipientDSIds().contains(this.getRemoteDSId())) {
                        if (isDebugEnabled) {
                            logger.debug("{}: Event originated in {}. My DS id is {}. The remote DS id is {}.. It is being dropped as remote ds is already a recipient. Recipients are: {}", this, seca.getOriginatingDSId(), getMyDSId(), this.getRemoteDSId(), seca.getRecipientDSIds());
                        }
                        return;
                    }
                }
                seca.getRecipientDSIds().addAll(allRemoteDSIds);
            }
        } else {
            GatewaySenderEventCallbackArgument geCallbackArg = new GatewaySenderEventCallbackArgument(callbackArg, this.getMyDSId(), allRemoteDSIds);
            clonedEvent.setCallbackArgument(geCallbackArg);
        }
        if (!this.getLifeCycleLock().readLock().tryLock()) {
            synchronized (this.queuedEventsSync) {
                if (!this.enqueuedAllTempQueueEvents) {
                    if (!this.getLifeCycleLock().readLock().tryLock()) {
                        Object substituteValue = getSubstituteValue(clonedEvent, operation);
                        this.tmpQueuedEvents.add(new TmpQueueEvent(operation, clonedEvent, substituteValue));
                        freeClonedEvent = false;
                        stats.incTempQueueSize();
                        if (isDebugEnabled) {
                            logger.debug("Event : {} is added to TempQueue", clonedEvent);
                        }
                        return;
                    }
                }
            }
            if (this.enqueuedAllTempQueueEvents) {
                this.getLifeCycleLock().readLock().lock();
            }
        }
        try {
            // The sender may have stopped, after we have checked the status in the beginning.
            if (!isRunning()) {
                if (isDebugEnabled) {
                    logger.debug("Returning back without putting into the gateway sender queue");
                }
                return;
            }
            try {
                AbstractGatewaySenderEventProcessor ev = this.eventProcessor;
                if (ev == null) {
                    getStopper().checkCancelInProgress(null);
                    this.getCache().getDistributedSystem().getCancelCriterion().checkCancelInProgress(null);
                    // connecting to the other site (bug #40681)
                    if (ev == null) {
                        throw new GatewayCancelledException("Event processor thread is gone");
                    }
                }
                // Get substitution value to enqueue if necessary
                Object substituteValue = getSubstituteValue(clonedEvent, operation);
                ev.enqueueEvent(operation, clonedEvent, substituteValue);
            } catch (CancelException e) {
                logger.debug("caught cancel exception", e);
                throw e;
            } catch (RegionDestroyedException e) {
                logger.warn(LocalizedMessage.create(LocalizedStrings.GatewayImpl_0_AN_EXCEPTION_OCCURRED_WHILE_QUEUEING_1_TO_PERFORM_OPERATION_2_FOR_3, new Object[] { this, getId(), operation, clonedEvent }), e);
            } catch (Exception e) {
                logger.fatal(LocalizedMessage.create(LocalizedStrings.GatewayImpl_0_AN_EXCEPTION_OCCURRED_WHILE_QUEUEING_1_TO_PERFORM_OPERATION_2_FOR_3, new Object[] { this, getId(), operation, clonedEvent }), e);
            }
        } finally {
            this.getLifeCycleLock().readLock().unlock();
        }
    } finally {
        if (freeClonedEvent) {
            // fix for bug 48035
            clonedEvent.release();
        }
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) GatewayCancelledException(org.apache.geode.distributed.GatewayCancelledException) RegionExistsException(org.apache.geode.cache.RegionExistsException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) GatewayCancelledException(org.apache.geode.distributed.GatewayCancelledException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) CancelException(org.apache.geode.CancelException)

Example 34 with Released

use of org.apache.geode.internal.offheap.annotations.Released in project geode by apache.

the class GatewaySenderEventImpl method release.

@Override
@Released(OffHeapIdentifier.GATEWAY_SENDER_EVENT_IMPL_VALUE)
public synchronized void release() {
    @Released(OffHeapIdentifier.GATEWAY_SENDER_EVENT_IMPL_VALUE) Object vo = this.valueObj;
    if (OffHeapHelper.releaseAndTrackOwner(vo, this)) {
        this.valueObj = null;
        this.valueObjReleased = true;
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) StoredObject(org.apache.geode.internal.offheap.StoredObject) Released(org.apache.geode.internal.offheap.annotations.Released)

Example 35 with Released

use of org.apache.geode.internal.offheap.annotations.Released in project geode by apache.

the class HARegion method findObjectInSystem.

/**
   * @return the deserialized value
   * @see LocalRegion#findObjectInSystem(KeyInfo, boolean, TXStateInterface, boolean, Object,
   *      boolean, boolean, ClientProxyMembershipID, EntryEventImpl, boolean)
   * 
   */
@Override
protected Object findObjectInSystem(KeyInfo keyInfo, boolean isCreate, TXStateInterface txState, boolean generateCallbacks, Object localValue, boolean disableCopyOnRead, boolean preferCD, ClientProxyMembershipID requestingClient, EntryEventImpl clientEvent, boolean returnTombstones) throws CacheLoaderException, TimeoutException {
    Object value = null;
    final Object key = keyInfo.getKey();
    final Object aCallbackArgument = keyInfo.getCallbackArg();
    // copy into local var to prevent race condition
    RegionEntry re = null;
    Assert.assertTrue(!hasServerProxy());
    CacheLoader loader = basicGetLoader();
    if (loader != null) {
        final LoaderHelper loaderHelper = loaderHelperFactory.createLoaderHelper(key, aCallbackArgument, false, /* netSearchAllowed */
        true, /* netloadallowed */
        null);
        try {
            value = loader.load(loaderHelper);
        } finally {
        }
        if (value != null) {
            try {
                validateKey(key);
                Operation op;
                if (isCreate) {
                    op = Operation.LOCAL_LOAD_CREATE;
                } else {
                    op = Operation.LOCAL_LOAD_UPDATE;
                }
                @Released EntryEventImpl event = EntryEventImpl.create(this, op, key, value, aCallbackArgument, false, getMyId(), generateCallbacks);
                try {
                    re = basicPutEntry(event, 0L);
                } finally {
                    event.release();
                }
                if (txState == null) {
                }
            } catch (CacheWriterException cwe) {
            // @todo smenon Log the exception
            }
        }
    }
    if (isCreate) {
        recordMiss(re, key);
    }
    return value;
}
Also used : LoaderHelper(org.apache.geode.cache.LoaderHelper) Released(org.apache.geode.internal.offheap.annotations.Released) CacheLoader(org.apache.geode.cache.CacheLoader) Operation(org.apache.geode.cache.Operation) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Aggregations

Released (org.apache.geode.internal.offheap.annotations.Released)57 StoredObject (org.apache.geode.internal.offheap.StoredObject)29 CacheWriterException (org.apache.geode.cache.CacheWriterException)13 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)13 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)12 ConcurrentCacheModificationException (org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)9 GatewaySenderEventCallbackArgument (org.apache.geode.internal.cache.wan.GatewaySenderEventCallbackArgument)9 Retained (org.apache.geode.internal.offheap.annotations.Retained)9 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)8 VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)8 DiskAccessException (org.apache.geode.cache.DiskAccessException)6 Operation (org.apache.geode.cache.Operation)6 ReplyException (org.apache.geode.distributed.internal.ReplyException)6 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)5 IndexManager (org.apache.geode.cache.query.internal.index.IndexManager)5 PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)5 TimeoutException (org.apache.geode.cache.TimeoutException)4 EventID (org.apache.geode.internal.cache.EventID)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3