Search in sources :

Example 1 with InvalidDeltaException

use of org.apache.geode.InvalidDeltaException in project geode by apache.

the class FaultyDelta method fromDelta.

public void fromDelta(DataInput in) throws IOException, InvalidDeltaException {
    try {
        byte deltaBits = DataSerializer.readByte(in);
        GemFireCacheImpl.getInstance().getLogger().fine("Applying delta on " + this.toString());
        if (deltaBits != 0) {
            // intentionly to produce faulty fromDelta implementation
            if ((deltaBits & INT_MASK) == INT_MASK) {
                this.bigObj = DataSerializer.readByteArray(in);
                GemFireCacheImpl.getInstance().getLogger().fine(" Applied delta on DeltaImpl's field 'bigObj' = {" + this.bigObj[0] + " " + this.bigObj[1] + "}");
            }
            if ((deltaBits & BIG_OBJECT_MASK) == BIG_OBJECT_MASK) {
                this.intVal = DataSerializer.readPrimitiveInt(in);
                GemFireCacheImpl.getInstance().getLogger().fine(" Applied delta on DeltaImpl's field 'intVal' = " + this.intVal);
            }
            if ((deltaBits | COMPLETE_MASK) != COMPLETE_MASK) {
                GemFireCacheImpl.getInstance().getLogger().fine(" <unknown field code>");
                throw new IllegalArgumentException("DeltaImpl.fromDelta(): Unknown field code, " + deltaBits);
            }
        }
    } catch (IOException ioe) {
        GemFireCacheImpl.getInstance().getLogger().warning("DeltaObj.fromDelta(): " + ioe);
        throw ioe;
    } catch (IllegalArgumentException iae) {
        GemFireCacheImpl.getInstance().getLogger().warning("DeltaObj.fromDelta(): " + iae);
        throw new InvalidDeltaException(iae);
    }
}
Also used : InvalidDeltaException(org.apache.geode.InvalidDeltaException) IOException(java.io.IOException)

Example 2 with InvalidDeltaException

use of org.apache.geode.InvalidDeltaException in project geode by apache.

the class DeltaSession7 method fromDelta.

public void fromDelta(DataInput in) throws IOException, InvalidDeltaException {
    // Read whether to apply the changes to another DS if necessary
    this.applyRemotely = in.readBoolean();
    // Read the events
    List<DeltaSessionAttributeEvent> events = null;
    try {
        events = DataSerializer.readArrayList(in);
    } catch (ClassNotFoundException e) {
        throw new InvalidDeltaException(e);
    }
    // This allows for backwards compatibility with 2.1 clients
    if (((InputStream) in).available() > 0) {
        this.lastAccessedTime = in.readLong();
        this.maxInactiveInterval = in.readInt();
    }
    // Iterate and apply the events
    for (DeltaSessionAttributeEvent event : events) {
        event.apply(this);
    }
    // Add the events to the gateway delta region if necessary
    if (this.enableGatewayDeltaReplication && this.applyRemotely) {
        setCurrentGatewayDeltaEvent(new DeltaSessionAttributeEventBatch(this.sessionRegionName, this.id, events));
    }
    // Access it to set the last accessed time. End access it to set not new.
    access();
    endAccess();
}
Also used : InvalidDeltaException(org.apache.geode.InvalidDeltaException) DeltaSessionAttributeEvent(org.apache.geode.modules.session.catalina.internal.DeltaSessionAttributeEvent) DeltaSessionAttributeEventBatch(org.apache.geode.modules.session.catalina.internal.DeltaSessionAttributeEventBatch)

Example 3 with InvalidDeltaException

use of org.apache.geode.InvalidDeltaException in project geode by apache.

the class AbstractRegionEntry method checkForDeltaConflict.

/**
   * for an event containing a delta we must check to see if the tag's previous member id is the
   * stamp's member id and ensure that the version is only incremented by 1. Otherwise the delta is
   * being applied to a value that does not match the source of the delta.
   */
private void checkForDeltaConflict(LocalRegion region, long stampVersion, long tagVersion, VersionStamp stamp, VersionTag tag, VersionSource dmId, InternalDistributedMember sender, StringBuilder verbose) {
    if (tagVersion != stampVersion + 1) {
        if (verbose != null) {
            verbose.append("\ndelta requires full value due to version mismatch");
        }
        region.getCachePerfStats().incDeltaFailedUpdates();
        throw new InvalidDeltaException("delta cannot be applied due to version mismatch");
    } else {
        // make sure the tag was based on the value in this entry by checking the
        // tag's previous-changer ID against this stamp's current ID
        VersionSource stampID = stamp.getMemberID();
        if (stampID == null) {
            stampID = dmId;
        }
        VersionSource tagID = tag.getPreviousMemberID();
        if (tagID == null) {
            tagID = sender;
        }
        if (!tagID.equals(stampID)) {
            if (verbose != null) {
                verbose.append("\ndelta requires full value.  tag.previous=").append(tagID).append(" but stamp.current=").append(stampID);
            }
            region.getCachePerfStats().incDeltaFailedUpdates();
            throw new InvalidDeltaException("delta cannot be applied due to version ID mismatch");
        }
    }
}
Also used : InvalidDeltaException(org.apache.geode.InvalidDeltaException) VersionSource(org.apache.geode.internal.cache.versions.VersionSource)

Example 4 with InvalidDeltaException

use of org.apache.geode.InvalidDeltaException 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 5 with InvalidDeltaException

use of org.apache.geode.InvalidDeltaException in project geode by apache.

the class DistTXState method applyOpsOnRedundantCopy.

protected boolean applyOpsOnRedundantCopy(DistributedMember sender, ArrayList<DistTxEntryEvent> secondaryTransactionalOperations) {
    boolean returnValue = true;
    try {
        boolean result = true;
        // Start TxState Update During PreCommit phase
        setUpdatingTxStateDuringPreCommit(true);
        if (logger.isDebugEnabled()) {
            logger.debug("DistTXState.applyOpOnRedundantCopy: size of " + "secondaryTransactionalOperations = {}", secondaryTransactionalOperations.size());
        }
        /*
       * Handle Put Operations meant for secondary.
       * 
       * @see org.apache.geode.internal.cache.partitioned.PutMessage.
       * operateOnPartitionedRegion(DistributionManager, PartitionedRegion, long)
       * 
       * [DISTTX] TODO need to handle other operations
       */
        for (DistTxEntryEvent dtop : secondaryTransactionalOperations) {
            if (logger.isDebugEnabled()) {
                logger.debug("DistTXState.applyOpOnRedundantCopy: processing dist " + "tx operation {}", dtop);
            }
            dtop.setDistributedMember(sender);
            dtop.setOriginRemote(false);
            /*
         * [DISTTX} TODO handle call back argument version tag and other settings in PutMessage
         */
            String failureReason = null;
            try {
                if (dtop.getKeyInfo().isDistKeyInfo()) {
                    dtop.getKeyInfo().setCheckPrimary(false);
                } else {
                    dtop.setKeyInfo(new DistTxKeyInfo(dtop.getKeyInfo()));
                    dtop.getKeyInfo().setCheckPrimary(false);
                }
                // apply the op
                result = applyIndividualOp(dtop);
                if (!result) {
                    // make sure the region hasn't gone away
                    dtop.getRegion().checkReadiness();
                }
            } catch (CacheWriterException cwe) {
                result = false;
                failureReason = "CacheWriterException";
            } catch (PrimaryBucketException pbe) {
                result = false;
                failureReason = "PrimaryBucketException";
            } catch (InvalidDeltaException ide) {
                result = false;
                failureReason = "InvalidDeltaException";
            } catch (DataLocationException e) {
                result = false;
                failureReason = "DataLocationException";
            }
            if (logger.isDebugEnabled()) {
                logger.debug("DistTXState.applyOpOnRedundantCopy {} ##op {},  " + "##region {}, ##key {}", (result ? " sucessfully applied op " : " failed to apply op due to " + failureReason), dtop.getOperation(), dtop.getRegion().getName(), dtop.getKey());
            }
            if (!result) {
                returnValue = false;
                break;
            }
        }
    } finally {
        // End TxState Update During PreCommit phase
        setUpdatingTxStateDuringPreCommit(false);
    }
    return returnValue;
}
Also used : InvalidDeltaException(org.apache.geode.InvalidDeltaException) DistTxEntryEvent(org.apache.geode.internal.cache.tx.DistTxEntryEvent) DistTxKeyInfo(org.apache.geode.internal.cache.tx.DistTxKeyInfo) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Aggregations

InvalidDeltaException (org.apache.geode.InvalidDeltaException)20 IOException (java.io.IOException)8 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)3 EventID (org.apache.geode.internal.cache.EventID)3 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)3 Part (org.apache.geode.internal.cache.tier.sockets.Part)3 ByteBuffer (java.nio.ByteBuffer)2 CancelException (org.apache.geode.CancelException)2 CacheWriterException (org.apache.geode.cache.CacheWriterException)2 Region (org.apache.geode.cache.Region)2 ResourceException (org.apache.geode.cache.ResourceException)2 PutOperationContext (org.apache.geode.cache.operations.PutOperationContext)2 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)2 LocalRegion (org.apache.geode.internal.cache.LocalRegion)2 DeltaSessionAttributeEvent (org.apache.geode.modules.session.catalina.internal.DeltaSessionAttributeEvent)2 DeltaSessionAttributeEventBatch (org.apache.geode.modules.session.catalina.internal.DeltaSessionAttributeEventBatch)2 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutput (java.io.DataOutput)1