Search in sources :

Example 31 with CancelException

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

the class AddCacheServerProfileMessage method process.

@Override
protected void process(DistributionManager dm) {
    int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.BEFORE_INITIAL_IMAGE);
    try {
        InternalCache cache = GemFireCacheImpl.getInstance();
        // will be null if not initialized
        if (cache != null && !cache.isClosed()) {
            operateOnCache(cache);
        }
    } finally {
        LocalRegion.setThreadInitLevelRequirement(oldLevel);
        ReplyMessage reply = new ReplyMessage();
        reply.setProcessorId(this.processorId);
        reply.setRecipient(getSender());
        try {
            dm.putOutgoing(reply);
        } catch (CancelException ignore) {
        // can't send a reply, so ignore the exception
        }
    }
}
Also used : CancelException(org.apache.geode.CancelException) ReplyMessage(org.apache.geode.distributed.internal.ReplyMessage)

Example 32 with CancelException

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

the class AbstractRegionEntry method processGatewayTag.

private boolean processGatewayTag(EntryEvent cacheEvent) {
    // Gateway tags are installed in the server-side LocalRegion cache
    // modification methods. They do not have version numbers or distributed
    // member IDs. Instead they only have timestamps and distributed system IDs.
    // If there is a resolver plug-in, invoke it. Otherwise we use the timestamps and
    // distributed system IDs to determine whether to allow the event to proceed.
    final boolean isDebugEnabled = logger.isDebugEnabled();
    if (this.isRemoved() && !this.isTombstone()) {
        // no conflict on a new entry
        return true;
    }
    EntryEventImpl event = (EntryEventImpl) cacheEvent;
    VersionTag tag = event.getVersionTag();
    long stampTime = getVersionStamp().getVersionTimeStamp();
    long tagTime = tag.getVersionTimeStamp();
    int stampDsid = getVersionStamp().getDistributedSystemId();
    int tagDsid = tag.getDistributedSystemId();
    if (isDebugEnabled) {
        logger.debug("processing gateway version information for {}.  Stamp dsid={} time={} Tag dsid={} time={}", event.getKey(), stampDsid, stampTime, tagDsid, tagTime);
    }
    if (tagTime == VersionTag.ILLEGAL_VERSION_TIMESTAMP) {
        // no timestamp received from other system - just apply it
        return true;
    }
    if (tagDsid == stampDsid || stampDsid == -1) {
        return true;
    }
    GatewayConflictResolver resolver = event.getRegion().getCache().getGatewayConflictResolver();
    if (resolver != null) {
        if (isDebugEnabled) {
            logger.debug("invoking gateway conflict resolver");
        }
        final boolean[] disallow = new boolean[1];
        final Object[] newValue = new Object[] { this };
        GatewayConflictHelper helper = new GatewayConflictHelper() {

            @Override
            public void disallowEvent() {
                disallow[0] = true;
            }

            @Override
            public void changeEventValue(Object value) {
                newValue[0] = value;
            }
        };
        @Released TimestampedEntryEventImpl timestampedEvent = (TimestampedEntryEventImpl) event.getTimestampedEvent(tagDsid, stampDsid, tagTime, stampTime);
        // gateway conflict resolvers will usually want to see the old value
        if (!timestampedEvent.hasOldValue() && isRemoved()) {
            // OFFHEAP: since isRemoved I think getValue will never be stored off heap in this case
            timestampedEvent.setOldValue(getValue(timestampedEvent.getRegion()));
        }
        Throwable thr = null;
        try {
            resolver.onEvent(timestampedEvent, helper);
        } catch (CancelException cancelled) {
            throw cancelled;
        } catch (VirtualMachineError err) {
            SystemFailure.initiateFailure(err);
            // now, so don't let this thread continue.
            throw err;
        } catch (Throwable t) {
            // Whenever you catch Error or Throwable, you must also
            // catch VirtualMachineError (see above). However, there is
            // _still_ a possibility that you are dealing with a cascading
            // error condition, so you also need to check to see if the JVM
            // is still usable:
            SystemFailure.checkFailure();
            logger.error(LocalizedMessage.create(LocalizedStrings.LocalRegion_EXCEPTION_OCCURRED_IN_CONFLICTRESOLVER), t);
            thr = t;
        } finally {
            timestampedEvent.release();
        }
        if (isDebugEnabled) {
            logger.debug("done invoking resolver", thr);
        }
        if (thr == null) {
            if (disallow[0]) {
                if (isDebugEnabled) {
                    logger.debug("conflict resolver rejected the event for {}", event.getKey());
                }
                throw new ConcurrentCacheModificationException("WAN conflict resolver rejected the operation");
            }
            tag.setAllowedByResolver(true);
            if (newValue[0] != this) {
                if (isDebugEnabled) {
                    logger.debug("conflict resolver changed the value of the event for {}", event.getKey());
                }
                // the resolver changed the event value!
                event.setNewValue(newValue[0]);
            }
            // if nothing was done then we allow the event
            if (isDebugEnabled) {
                logger.debug("change was allowed by conflict resolver: {}", tag);
            }
            return true;
        }
    }
    if (isDebugEnabled) {
        logger.debug("performing normal WAN conflict check");
    }
    if (tagTime > stampTime || tagTime == stampTime && tagDsid >= stampDsid) {
        if (isDebugEnabled) {
            logger.debug("allowing event");
        }
        return true;
    }
    if (isDebugEnabled) {
        logger.debug("disallowing event for {}", event.getKey());
    }
    throw new ConcurrentCacheModificationException("conflicting WAN event detected");
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) GatewayConflictResolver(org.apache.geode.cache.util.GatewayConflictResolver) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) GatewayConflictHelper(org.apache.geode.cache.util.GatewayConflictHelper) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) StoredObject(org.apache.geode.internal.offheap.StoredObject) CancelException(org.apache.geode.CancelException)

Example 33 with CancelException

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

the class PrepareBackupRequest method send.

public static Map<DistributedMember, Set<PersistentID>> send(DM dm, Set recipients) {
    PrepareBackupRequest request = new PrepareBackupRequest();
    request.setRecipients(recipients);
    PrepareBackupReplyProcessor replyProcessor = new PrepareBackupReplyProcessor(dm, recipients);
    request.msgId = replyProcessor.getProcessorId();
    dm.putOutgoing(request);
    try {
        replyProcessor.waitForReplies();
    } catch (ReplyException e) {
        if (!(e.getCause() instanceof CancelException)) {
            throw e;
        }
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    AdminResponse response = request.createResponse((DistributionManager) dm);
    response.setSender(dm.getDistributionManagerId());
    replyProcessor.process(response);
    return replyProcessor.results;
}
Also used : AdminResponse(org.apache.geode.internal.admin.remote.AdminResponse) CancelException(org.apache.geode.CancelException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 34 with CancelException

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

the class InternalDataSerializer method writeUserObject.

/**
   * Data serializes an instance of a "user class" (that is, a class that can be handled by a
   * registered {@code DataSerializer}) to the given {@code DataOutput}.
   *
   * @return {@code true} if {@code o} was written to {@code out}.
   */
private static boolean writeUserObject(Object o, DataOutput out, boolean ensurePdxCompatibility) throws IOException {
    final Class<?> c = o.getClass();
    final DataSerializer serializer = InternalDataSerializer.getSerializer(c);
    if (serializer != null) {
        int id = serializer.getId();
        if (id != 0) {
            checkPdxCompatible(o, ensurePdxCompatibility);
            // id will be 0 if it is a WellKnowDS
            if (id <= Byte.MAX_VALUE && id >= Byte.MIN_VALUE) {
                out.writeByte(USER_CLASS);
                out.writeByte((byte) id);
            } else if (id <= Short.MAX_VALUE && id >= Short.MIN_VALUE) {
                out.writeByte(USER_CLASS_2);
                out.writeShort(id);
            } else {
                out.writeByte(USER_CLASS_4);
                out.writeInt(id);
            }
        } else {
            if (ensurePdxCompatibility) {
                if (!(serializer instanceof WellKnownPdxDS)) {
                    checkPdxCompatible(o, ensurePdxCompatibility);
                }
            }
        }
        boolean toDataResult;
        try {
            toDataResult = serializer.toData(o, out);
        } catch (IOException io) {
            if (serializer instanceof WellKnownDS) {
                // see bug 44659
                throw io;
            } else {
                // with the plugin code.
                throw new ToDataException("toData failed on DataSerializer with id=" + id + " for class " + c, io);
            }
        } catch (CancelException | ToDataException | GemFireRethrowable ex) {
            // Serializing a PDX can result in a cache closed exception. Just rethrow
            throw ex;
        } catch (VirtualMachineError err) {
            SystemFailure.initiateFailure(err);
            // now, so don't let this thread continue.
            throw err;
        } catch (Throwable t) {
            // Whenever you catch Error or Throwable, you must also
            // catch VirtualMachineError (see above). However, there is
            // _still_ a possibility that you are dealing with a cascading
            // error condition, so you also need to check to see if the JVM
            // is still usable:
            SystemFailure.checkFailure();
            throw new ToDataException("toData failed on DataSerializer with id=" + id + " for class " + c, t);
        }
        if (toDataResult) {
            return true;
        } else {
            throw new ToDataException(LocalizedStrings.DataSerializer_SERIALIZER_0_A_1_SAID_THAT_IT_COULD_SERIALIZE_AN_INSTANCE_OF_2_BUT_ITS_TODATA_METHOD_RETURNED_FALSE.toLocalizedString(serializer.getId(), serializer.getClass().getName(), o.getClass().getName()));
        }
    // Do byte[][] and Object[] here to fix bug 44060
    } else if (o instanceof byte[][]) {
        byte[][] byteArrays = (byte[][]) o;
        out.writeByte(ARRAY_OF_BYTE_ARRAYS);
        writeArrayOfByteArrays(byteArrays, out);
        return true;
    } else if (o instanceof Object[]) {
        Object[] array = (Object[]) o;
        out.writeByte(OBJECT_ARRAY);
        writeObjectArray(array, out, ensurePdxCompatibility);
        return true;
    } else if (is662SerializationEnabled() && (o.getClass().isEnum() || /* for bug 52271 */
    (o.getClass().getSuperclass() != null && o.getClass().getSuperclass().isEnum()))) {
        if (isPdxSerializationInProgress()) {
            writePdxEnum((Enum<?>) o, out);
        } else {
            checkPdxCompatible(o, ensurePdxCompatibility);
            writeGemFireEnum((Enum<?>) o, out);
        }
        return true;
    } else {
        PdxSerializer pdxSerializer = TypeRegistry.getPdxSerializer();
        return pdxSerializer != null && writePdx(out, null, o, pdxSerializer);
    }
}
Also used : PdxInstanceEnum(org.apache.geode.pdx.internal.PdxInstanceEnum) PdxSerializer(org.apache.geode.pdx.PdxSerializer) IOException(java.io.IOException) GemFireIOException(org.apache.geode.GemFireIOException) GemFireRethrowable(org.apache.geode.GemFireRethrowable) ToDataException(org.apache.geode.ToDataException) CancelException(org.apache.geode.CancelException) DataSerializer(org.apache.geode.DataSerializer)

Example 35 with CancelException

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

the class InternalDataSerializer method writeDSFID.

public static void writeDSFID(DataSerializableFixedID o, DataOutput out) throws IOException {
    int dsfid = o.getDSFID();
    if (dsfidToClassMap != null && logger.isTraceEnabled(LogMarker.DEBUG_DSFID)) {
        logger.trace(LogMarker.DEBUG_DSFID, "writeDSFID {} class={}", dsfid, o.getClass());
        if (dsfid != DataSerializableFixedID.NO_FIXED_ID && dsfid != DataSerializableFixedID.ILLEGAL) {
            // consistency check to make sure that the same DSFID is not used
            // for two different classes
            String newClassName = o.getClass().getName();
            String existingClassName = (String) dsfidToClassMap.putIfAbsent(dsfid, newClassName);
            if (existingClassName != null && !existingClassName.equals(newClassName)) {
                logger.trace(LogMarker.DEBUG_DSFID, "dsfid={} is used for class {} and class {}", dsfid, existingClassName, newClassName);
            }
        }
    }
    if (dsfid == DataSerializableFixedID.NO_FIXED_ID) {
        out.writeByte(DS_NO_FIXED_ID);
        DataSerializer.writeClass(o.getClass(), out);
    } else {
        writeDSFIDHeader(dsfid, out);
    }
    try {
        invokeToData(o, out);
    } catch (IOException | CancelException | ToDataException | GemFireRethrowable io) {
        throw io;
    } catch (VirtualMachineError err) {
        SystemFailure.initiateFailure(err);
        // now, so don't let this thread continue.
        throw err;
    } catch (Throwable t) {
        // Whenever you catch Error or Throwable, you must also
        // catch VirtualMachineError (see above). However, there is
        // _still_ a possibility that you are dealing with a cascading
        // error condition, so you also need to check to see if the JVM
        // is still usable:
        SystemFailure.checkFailure();
        throw new ToDataException("toData failed on dsfid=" + dsfid + " msg:" + t.getMessage(), t);
    }
}
Also used : GemFireRethrowable(org.apache.geode.GemFireRethrowable) ToDataException(org.apache.geode.ToDataException) IOException(java.io.IOException) GemFireIOException(org.apache.geode.GemFireIOException) CancelException(org.apache.geode.CancelException)

Aggregations

CancelException (org.apache.geode.CancelException)135 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)46 IOException (java.io.IOException)40 ReplyException (org.apache.geode.distributed.internal.ReplyException)30 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)25 CacheClosedException (org.apache.geode.cache.CacheClosedException)23 Region (org.apache.geode.cache.Region)22 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)21 LocalRegion (org.apache.geode.internal.cache.LocalRegion)18 Set (java.util.Set)16 Cache (org.apache.geode.cache.Cache)16 CacheException (org.apache.geode.cache.CacheException)16 HashSet (java.util.HashSet)15 Iterator (java.util.Iterator)15 QueryException (org.apache.geode.cache.query.QueryException)15 ArrayList (java.util.ArrayList)13 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)13 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)13 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)13 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)13