Search in sources :

Example 1 with PersistentReplicatesOfflineException

use of org.apache.geode.cache.persistence.PersistentReplicatesOfflineException in project geode by apache.

the class DistributedRegion method virtualPut.

@Override
protected boolean virtualPut(EntryEventImpl event, boolean ifNew, boolean ifOld, Object expectedOldValue, boolean requireOldValue, long lastModified, boolean overwriteDestroyed) throws TimeoutException, CacheWriterException {
    final boolean isTraceEnabled = logger.isTraceEnabled();
    Lock dlock = null;
    if (// lock only applies to global scope
    this.scope.isGlobal() && // only if operation originating locally
    !event.isOriginRemote() && // search and load processor handles own locking
    !event.isNetSearch() && !event.isNetLoad() && // @todo darrel/kirk: what about putAll?
    !event.isLocalLoad() && !event.isSingleHopPutOp()) {
        // Single Hop Op means dlock is already taken at origin node.
        dlock = this.getDistributedLockIfGlobal(event.getKey());
    }
    if (isTraceEnabled) {
        logger.trace("virtualPut invoked for event {}", event);
    }
    try {
        if (!hasSeenEvent(event)) {
            if (this.requiresOneHopForMissingEntry(event)) {
                // bug #45704: see if a one-hop must be done for this operation
                RegionEntry re = getRegionEntry(event.getKey());
                if (re == null || /* || re.isTombstone() */
                !this.generateVersionTag) {
                    if (!event.isBulkOpInProgress() || this.dataPolicy.withStorage()) {
                        // putAll will send a single one-hop for empty regions. for other missing entries
                        // we need to get a valid version number before modifying the local cache
                        boolean didDistribute = RemotePutMessage.distribute(event, lastModified, false, false, expectedOldValue, requireOldValue, !this.generateVersionTag);
                        if (!didDistribute && isTraceEnabled) {
                            logger.trace("Unable to perform one-hop messaging");
                        }
                        if (!this.generateVersionTag && !didDistribute) {
                            throw new PersistentReplicatesOfflineException();
                        }
                        if (didDistribute) {
                            if (isTraceEnabled) {
                                logger.trace("Event after remotePut operation: {}", event);
                            }
                            if (event.getVersionTag() == null) {
                                // and so should not be applied to this cache
                                return false;
                            }
                        }
                    }
                }
            }
            return super.virtualPut(event, ifNew, ifOld, expectedOldValue, requireOldValue, lastModified, overwriteDestroyed);
        } else {
            if (event.getDeltaBytes() != null && event.getRawNewValue() == null) {
                // The value in this vm may not be same as this event's value.
                throw new InvalidDeltaException("Cache encountered replay of event containing delta bytes for key " + event.getKey());
            }
            // return
            if (isTraceEnabled) {
                logger.trace("DR.virtualPut: this cache has already seen this event {}", event);
            }
            // LR.basicPutPart3 in purpose.
            if (event.isBulkOpInProgress() && !event.isOriginRemote()) {
                event.getPutAllOperation().addEntry(event, true);
            }
            /*
         * doing this so that other VMs will apply this no matter what. If it is an "update" they
         * will not apply it if they don't have the key. Because this is probably a retry, it will
         * never get applied to this local AbstractRegionMap, and so will never be flipped to a
         * 'create'
         */
            event.makeCreate();
            if (!getConcurrencyChecksEnabled() || event.hasValidVersionTag()) {
                distributeUpdate(event, lastModified, ifNew, ifOld, expectedOldValue, requireOldValue);
                event.invokeCallbacks(this, true, true);
            }
            return true;
        }
    } finally {
        if (dlock != null) {
            dlock.unlock();
        }
    }
}
Also used : InvalidDeltaException(org.apache.geode.InvalidDeltaException) PersistentReplicatesOfflineException(org.apache.geode.cache.persistence.PersistentReplicatesOfflineException) Lock(java.util.concurrent.locks.Lock)

Example 2 with PersistentReplicatesOfflineException

use of org.apache.geode.cache.persistence.PersistentReplicatesOfflineException in project geode by apache.

the class DistributedRemoveAllOperation method initMessage.

@Override
protected void initMessage(CacheOperationMessage msg, DirectReplyProcessor proc) {
    super.initMessage(msg, proc);
    RemoveAllMessage m = (RemoveAllMessage) msg;
    // if concurrency checks are enabled and this is not a replicated
    // region we need to see if any of the entries have no versions and,
    // if so, cull them out and send a 1-hop message to a replicate that
    // can generate a version for the operation
    RegionAttributes attr = this.event.getRegion().getAttributes();
    if (attr.getConcurrencyChecksEnabled() && !attr.getDataPolicy().withReplication() && attr.getScope() != Scope.GLOBAL) {
        if (attr.getDataPolicy() == DataPolicy.EMPTY) {
            // all entries are without version tags
            boolean success = RemoteRemoveAllMessage.distribute((EntryEventImpl) this.event, this.removeAllData, this.removeAllDataSize);
            if (success) {
                m.callbackArg = this.event.getCallbackArgument();
                m.removeAllData = new RemoveAllEntryData[0];
                m.removeAllDataSize = 0;
                m.skipCallbacks = !event.isGenerateCallbacks();
                return;
            } else if (!getRegion().getGenerateVersionTag()) {
                // to distribute versionless entries.
                throw new PersistentReplicatesOfflineException();
            }
        } else {
            // some entries may have Create ops - these will not have version tags
            RemoveAllEntryData[] versionless = selectVersionlessEntries();
            if (logger.isTraceEnabled()) {
                logger.trace("Found these versionless entries: {}", Arrays.toString(versionless));
            }
            if (versionless.length > 0) {
                boolean success = RemoteRemoveAllMessage.distribute((EntryEventImpl) this.event, versionless, versionless.length);
                if (success) {
                    versionless = null;
                    RemoveAllEntryData[] versioned = selectVersionedEntries();
                    if (logger.isTraceEnabled()) {
                        logger.trace("Found these remaining versioned entries: {}", Arrays.toString(versioned));
                    }
                    m.callbackArg = this.event.getCallbackArgument();
                    m.removeAllData = versioned;
                    m.removeAllDataSize = versioned.length;
                    m.skipCallbacks = !event.isGenerateCallbacks();
                    return;
                } else if (!getRegion().getGenerateVersionTag()) {
                    // to distribute versionless entries.
                    throw new PersistentReplicatesOfflineException();
                }
            } else {
                if (logger.isDebugEnabled()) {
                    logger.debug("All entries have versions, so using normal DPAO message");
                }
            }
        }
    }
    m.callbackArg = this.event.getCallbackArgument();
    m.removeAllData = this.removeAllData;
    m.removeAllDataSize = this.removeAllDataSize;
    m.skipCallbacks = !event.isGenerateCallbacks();
}
Also used : PersistentReplicatesOfflineException(org.apache.geode.cache.persistence.PersistentReplicatesOfflineException) RegionAttributes(org.apache.geode.cache.RegionAttributes)

Example 3 with PersistentReplicatesOfflineException

use of org.apache.geode.cache.persistence.PersistentReplicatesOfflineException in project geode by apache.

the class PersistentRecoveryOrderDUnitTest method testRecoverFromNonPeristentRegion.

/**
   * Tests that a persistent region cannot recover from a non persistent region.
   */
@Test
public void testRecoverFromNonPeristentRegion() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    createPersistentRegion(vm0);
    createNonPersistentRegion(vm1);
    putAnEntry(vm0);
    closeRegion(vm0);
    try {
        updateTheEntry(vm1);
        fail("expected PersistentReplicatesOfflineException not thrown");
    } catch (Exception expected) {
        if (!(expected.getCause() instanceof PersistentReplicatesOfflineException)) {
            throw expected;
        }
    }
    // This should initialize from vm1
    createPersistentRegion(vm0);
    checkForRecoveryStat(vm0, true);
    updateTheEntry(vm1);
    checkForEntry(vm0);
    checkForEntry(vm1);
}
Also used : PersistentReplicatesOfflineException(org.apache.geode.cache.persistence.PersistentReplicatesOfflineException) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) RevokedPersistentDataException(org.apache.geode.cache.persistence.RevokedPersistentDataException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) AdminException(org.apache.geode.admin.AdminException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) LockServiceDestroyedException(org.apache.geode.distributed.LockServiceDestroyedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) PersistentReplicatesOfflineException(org.apache.geode.cache.persistence.PersistentReplicatesOfflineException) IOException(java.io.IOException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 4 with PersistentReplicatesOfflineException

use of org.apache.geode.cache.persistence.PersistentReplicatesOfflineException in project geode by apache.

the class DistributedPutAllOperation method initMessage.

@Override
protected void initMessage(CacheOperationMessage msg, DirectReplyProcessor proc) {
    super.initMessage(msg, proc);
    PutAllMessage m = (PutAllMessage) msg;
    // if concurrency checks are enabled and this is not a replicated
    // region we need to see if any of the entries have no versions and,
    // if so, cull them out and send a 1-hop message to a replicate that
    // can generate a version for the operation
    RegionAttributes attr = this.event.getRegion().getAttributes();
    if (attr.getConcurrencyChecksEnabled() && !attr.getDataPolicy().withReplication() && attr.getScope() != Scope.GLOBAL) {
        if (attr.getDataPolicy() == DataPolicy.EMPTY) {
            // all entries are without version tags
            boolean success = RemotePutAllMessage.distribute((EntryEventImpl) this.event, this.putAllData, this.putAllDataSize);
            if (success) {
                m.callbackArg = this.event.getCallbackArgument();
                m.putAllData = new PutAllEntryData[0];
                m.putAllDataSize = 0;
                m.skipCallbacks = !event.isGenerateCallbacks();
                return;
            } else if (!getRegion().getGenerateVersionTag()) {
                // to distribute versionless entries.
                throw new PersistentReplicatesOfflineException();
            }
        } else {
            // some entries may have Create ops - these will not have version tags
            PutAllEntryData[] versionless = selectVersionlessEntries();
            if (logger.isTraceEnabled()) {
                logger.trace("Found these versionless entries: {}", Arrays.toString(versionless));
            }
            if (versionless.length > 0) {
                boolean success = RemotePutAllMessage.distribute((EntryEventImpl) this.event, versionless, versionless.length);
                if (success) {
                    versionless = null;
                    PutAllEntryData[] versioned = selectVersionedEntries();
                    if (logger.isTraceEnabled()) {
                        logger.trace("Found these remaining versioned entries: {}", Arrays.toString(versioned));
                    }
                    m.callbackArg = this.event.getCallbackArgument();
                    m.putAllData = versioned;
                    m.putAllDataSize = versioned.length;
                    m.skipCallbacks = !event.isGenerateCallbacks();
                    return;
                } else if (!getRegion().getGenerateVersionTag()) {
                    // to distribute versionless entries.
                    throw new PersistentReplicatesOfflineException();
                }
            } else {
                if (logger.isDebugEnabled()) {
                    logger.debug("All entries have versions, so using normal DPAO message");
                }
            }
        }
    }
    m.callbackArg = this.event.getCallbackArgument();
    m.putAllData = this.putAllData;
    m.putAllDataSize = this.putAllDataSize;
    m.skipCallbacks = !event.isGenerateCallbacks();
}
Also used : PersistentReplicatesOfflineException(org.apache.geode.cache.persistence.PersistentReplicatesOfflineException) RegionAttributes(org.apache.geode.cache.RegionAttributes)

Aggregations

PersistentReplicatesOfflineException (org.apache.geode.cache.persistence.PersistentReplicatesOfflineException)4 RegionAttributes (org.apache.geode.cache.RegionAttributes)2 IOException (java.io.IOException)1 Lock (java.util.concurrent.locks.Lock)1 InvalidDeltaException (org.apache.geode.InvalidDeltaException)1 AdminException (org.apache.geode.admin.AdminException)1 CacheClosedException (org.apache.geode.cache.CacheClosedException)1 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)1 ConflictingPersistentDataException (org.apache.geode.cache.persistence.ConflictingPersistentDataException)1 RevokedPersistentDataException (org.apache.geode.cache.persistence.RevokedPersistentDataException)1 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)1 LockServiceDestroyedException (org.apache.geode.distributed.LockServiceDestroyedException)1 Host (org.apache.geode.test.dunit.Host)1 IgnoredException (org.apache.geode.test.dunit.IgnoredException)1 VM (org.apache.geode.test.dunit.VM)1 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)1 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)1 Test (org.junit.Test)1