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();
}
}
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);
}
}
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();
}
}
}
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;
}
}
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;
}
Aggregations