use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.
the class LocalRegion method serverDestroy.
/**
* Destroy an entry on the server given its event.
*
* @since GemFire 5.7
*/
void serverDestroy(EntryEventImpl event, Object expectedOldValue) {
if (event.getOperation().isDistributed()) {
ServerRegionProxy mySRP = getServerProxy();
if (mySRP != null) {
// send to server
Object key = event.getKey();
Object callbackArg = event.getRawCallbackArgument();
Object result = mySRP.destroy(key, expectedOldValue, event.getOperation(), event, callbackArg);
if (result instanceof EntryNotFoundException) {
throw (EntryNotFoundException) result;
}
}
}
}
use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.
the class LocalRegion method serverPut.
/**
* @since GemFire 5.7
*/
void serverPut(EntryEventImpl event, boolean requireOldValue, Object expectedOldValue) {
if (event.getOperation().isDistributed() && !event.isFromServer()) {
ServerRegionProxy mySRP = getServerProxy();
if (mySRP != null) {
if (event.isBulkOpInProgress()) {
// this is a put all, ignore this!
return;
}
Operation op = event.getOperation();
// TODO: is the newEntry flag needed?
Object key = event.getKey();
Object value = event.getRawNewValue();
// serverPut is called by cacheWriteBeforePut so the new value will not yet be off-heap
Object callbackArg = event.getRawCallbackArgument();
boolean isCreate = event.isCreate();
Object result = mySRP.put(key, value, event.getDeltaBytes(), event, op, requireOldValue, expectedOldValue, callbackArg, isCreate);
// bug #42296, serverProxy returns null when cache is closing
getCancelCriterion().checkCancelInProgress(null);
// to apply the operation and need to throw an exception
if (op.guaranteesOldValue()) {
if (op != Operation.REPLACE || requireOldValue) {
event.setConcurrentMapOldValue(result);
}
if (op == Operation.PUT_IF_ABSENT) {
if (result != null) {
// customers don't see this exception
throw new EntryNotFoundException("entry existed for putIfAbsent");
}
} else if (op == Operation.REPLACE) {
if (requireOldValue && result == null) {
throw new EntryNotFoundException("entry not found for replace");
} else if (!requireOldValue) {
if (!(Boolean) result) {
// customers don't see this exception
throw new EntryNotFoundException("entry found with wrong value");
}
}
}
}
}
}
}
use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.
the class LocalRegion method createExpiryTask.
/**
* If custom expiration returns non-null expiration attributes then create a CustomEntryExpiryTask
* for this region and the given entry and return it. Otherwise if the region is configured for
* expiration then create an EntryExpiryTask for this region and the given entry and return it.
* Null is returned if the expiration attributes indicate that expiration is disabled.
*/
private EntryExpiryTask createExpiryTask(RegionEntry regionEntry) {
if (regionEntry == null || regionEntry.isDestroyedOrRemoved()) {
return null;
}
if (this.customEntryIdleTimeout != null || this.customEntryTimeToLive != null) {
ExpiryRegionEntry expiryRegionEntry = new ExpiryRegionEntry(this, regionEntry);
ExpirationAttributes ttlAttributes = null;
ExpirationAttributes idleAttributes = null;
final RegionAttributes<?, ?> regionAttributes = this.getAttributes();
final CustomExpiry<?, ?> customTTL = regionAttributes.getCustomEntryTimeToLive();
if (customTTL != null) {
try {
ttlAttributes = customTTL.getExpiry(expiryRegionEntry);
if (ttlAttributes != null) {
this.checkEntryTimeoutAction("timeToLive", ttlAttributes.getAction());
}
} catch (RegionDestroyedException ignore) {
// Ignore - #42273
} catch (EntryNotFoundException ignore) {
// Ignore - #51933
} catch (EntryDestroyedException ignore) {
// Ignore - #51933
} catch (Exception e) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.EntryExpiryTask_ERROR_CALCULATING_EXPIRATION_0, e.getMessage()), e);
}
}
if (ttlAttributes == null) {
ttlAttributes = regionAttributes.getEntryTimeToLive();
}
CustomExpiry<?, ?> customIdle = regionAttributes.getCustomEntryIdleTimeout();
if (customIdle != null) {
try {
idleAttributes = customIdle.getExpiry(expiryRegionEntry);
if (idleAttributes != null) {
this.checkEntryTimeoutAction("idleTimeout", idleAttributes.getAction());
}
} catch (RegionDestroyedException ignore) {
// Ignore - #42273
} catch (EntryNotFoundException ignore) {
// Ignore - #51933
} catch (EntryDestroyedException ignore) {
// Ignore - #51933
} catch (Exception e) {
logger.fatal(LocalizedMessage.create(LocalizedStrings.EntryExpiryTask_ERROR_CALCULATING_EXPIRATION_0, e.getMessage()), e);
}
}
if (idleAttributes == null) {
idleAttributes = regionAttributes.getEntryIdleTimeout();
}
final boolean ttlDisabled = ttlAttributes == null || ttlAttributes.getTimeout() == 0;
final boolean idleDisabled = idleAttributes == null || idleAttributes.getTimeout() == 0;
if (ttlDisabled && idleDisabled) {
return null;
} else if ((ttlDisabled || ttlAttributes.equals(regionAttributes.getEntryTimeToLive())) && (idleDisabled || idleAttributes.equals(regionAttributes.getEntryIdleTimeout()))) {
// no need for custom since we can just use the region's expiration attributes.
return new EntryExpiryTask(this, regionEntry);
} else {
return new CustomEntryExpiryTask(this, regionEntry, ttlAttributes, idleAttributes);
}
} else if (isEntryExpiryPossible()) {
return new EntryExpiryTask(this, regionEntry);
} else {
return null;
}
}
use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.
the class TXState method txWriteExistingEntry.
/**
* Write an existing entry. This form takes an expectedOldValue which, if not null, must be equal
* to the current value of the entry. If it is not, an EntryNotFoundException is thrown.
*
* @param event
* @param expectedOldValue
* @return the tx entry object
* @throws EntryNotFoundException
*/
private TXEntryState txWriteExistingEntry(final EntryEventImpl event, Object expectedOldValue) throws EntryNotFoundException {
assert !event.isExpiration();
final Object entryKey = event.getKey();
final LocalRegion region = event.getRegion();
final Operation op = event.getOperation();
TXEntryState tx = txReadEntry(event.getKeyInfo(), region, true, expectedOldValue, true);
assert tx != null;
if (tx.existsLocally()) {
final boolean invalidatingInvalidEntry = op.isInvalidate() && Token.isInvalid(tx.getValueInVM(entryKey));
// Ignore invalidating an invalid entry
if (!invalidatingInvalidEntry) {
tx.updateForWrite(nextModSerialNum());
}
} else if (region.isProxy() && !op.isLocal() && !tx.hasOp()) {
// Distributed operations on proxy regions need to be done
// even if the entry does not exist locally.
// But only if we don't already have a tx operation (once we have an op
// then we honor tx.existsLocally since the tx has storage unlike the proxy).
// We must not throw EntryNotFoundException in this case
tx.updateForWrite(nextModSerialNum());
} else {
throw new EntryNotFoundException(entryKey.toString());
}
return tx;
}
use of org.apache.geode.cache.EntryNotFoundException in project geode by apache.
the class TXState method getEntryOnRemote.
/*
* (non-Javadoc)
*
* @see org.apache.geode.internal.cache.InternalDataView#getEntryOnRemote(java.lang.Object,
* org.apache.geode.internal.cache.LocalRegion)
*/
public Entry getEntryOnRemote(KeyInfo key, LocalRegion localRegion, boolean allowTombstones) throws DataLocationException {
PartitionedRegion pr = (PartitionedRegion) localRegion;
Region.Entry txval = getEntry(key, pr, allowTombstones);
if (txval == null) {
throw new EntryNotFoundException(LocalizedStrings.PartitionedRegionDataStore_ENTRY_NOT_FOUND.toLocalizedString());
} else {
NonLocalRegionEntry nlre = new NonLocalRegionEntry(txval, localRegion);
LocalRegion dataReg = localRegion.getDataRegionForRead(key);
return new EntrySnapshot(nlre, dataReg, (LocalRegion) txval.getRegion(), allowTombstones);
}
}
Aggregations