Search in sources :

Example 16 with EntryDestroyedException

use of org.apache.geode.cache.EntryDestroyedException in project geode by apache.

the class Coder method getKeyValArrayResponse.

public static ByteBuf getKeyValArrayResponse(ByteBufAllocator alloc, Collection<Entry<ByteArrayWrapper, ByteArrayWrapper>> items) {
    Iterator<Map.Entry<ByteArrayWrapper, ByteArrayWrapper>> it = items.iterator();
    ByteBuf response = alloc.buffer();
    response.writeByte(ARRAY_ID);
    int size = 0;
    ByteBuf tmp = alloc.buffer();
    while (it.hasNext()) {
        Map.Entry<ByteArrayWrapper, ByteArrayWrapper> next = it.next();
        byte[] key;
        byte[] nextByteArray;
        try {
            key = next.getKey().toBytes();
            nextByteArray = next.getValue().toBytes();
        } catch (EntryDestroyedException e) {
            continue;
        }
        // Add key
        tmp.writeByte(BULK_STRING_ID);
        tmp.writeBytes(intToBytes(key.length));
        tmp.writeBytes(CRLFar);
        tmp.writeBytes(key);
        tmp.writeBytes(CRLFar);
        // Add value
        tmp.writeByte(BULK_STRING_ID);
        tmp.writeBytes(intToBytes(nextByteArray.length));
        tmp.writeBytes(CRLFar);
        tmp.writeBytes(nextByteArray);
        tmp.writeBytes(CRLFar);
        size++;
    }
    response.writeBytes(intToBytes(size * 2));
    response.writeBytes(CRLFar);
    response.writeBytes(tmp);
    tmp.release();
    return response;
}
Also used : Entry(java.util.Map.Entry) EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) ByteBuf(io.netty.buffer.ByteBuf) Map(java.util.Map)

Example 17 with EntryDestroyedException

use of org.apache.geode.cache.EntryDestroyedException in project geode by apache.

the class FlushAllExecutor method executeCommand.

@Override
public void executeCommand(Command command, ExecutionHandlerContext context) {
    if (context.hasTransaction())
        throw new UnsupportedOperationInTransactionException();
    for (Entry<String, RedisDataType> e : context.getRegionProvider().metaEntrySet()) {
        try {
            String skey = e.getKey();
            RedisDataType type = e.getValue();
            removeEntry(Coder.stringToByteWrapper(skey), type, context);
        } catch (EntryDestroyedException e1) {
            continue;
        }
    }
    command.setResponse(Coder.getSimpleStringResponse(context.getByteBufAllocator(), "OK"));
}
Also used : RedisDataType(org.apache.geode.redis.internal.RedisDataType) EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException)

Example 18 with EntryDestroyedException

use of org.apache.geode.cache.EntryDestroyedException in project geode by apache.

the class AttributeDescriptor method readReflection.

// used when the resolution of an attribute must be on a superclass
// instead of the runtime class
private Object readReflection(Object target) throws NameNotFoundException, QueryInvocationTargetException {
    Support.Assert(target != null);
    Support.Assert(target != QueryService.UNDEFINED);
    if (target instanceof Token) {
        return QueryService.UNDEFINED;
    }
    Class resolutionClass = target.getClass();
    Member m = getReadMember(resolutionClass);
    try {
        if (m instanceof Method) {
            try {
                return ((Method) m).invoke(target, (Object[]) null);
            } catch (EntryDestroyedException e) {
                // eat the Exception
                return QueryService.UNDEFINED;
            } catch (IllegalAccessException e) {
                throw new NameNotFoundException(LocalizedStrings.AttributeDescriptor_METHOD_0_IN_CLASS_1_IS_NOT_ACCESSIBLE_TO_THE_QUERY_PROCESSOR.toLocalizedString(new Object[] { m.getName(), target.getClass().getName() }), e);
            } catch (InvocationTargetException e) {
                // if the target exception is Exception, wrap that,
                // otherwise wrap the InvocationTargetException itself
                Throwable t = e.getTargetException();
                if ((t instanceof EntryDestroyedException)) {
                    // eat the exception
                    return QueryService.UNDEFINED;
                }
                if (t instanceof Exception)
                    throw new QueryInvocationTargetException(t);
                throw new QueryInvocationTargetException(e);
            }
        } else {
            try {
                return ((Field) m).get(target);
            } catch (IllegalAccessException e) {
                throw new NameNotFoundException(LocalizedStrings.AttributeDescriptor_FIELD_0_IN_CLASS_1_IS_NOT_ACCESSIBLE_TO_THE_QUERY_PROCESSOR.toLocalizedString(new Object[] { m.getName(), target.getClass().getName() }), e);
            } catch (EntryDestroyedException e) {
                return QueryService.UNDEFINED;
            }
        }
    } catch (EntryDestroyedException e) {
        // eat the exception
        return QueryService.UNDEFINED;
    }
}
Also used : EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) NameNotFoundException(org.apache.geode.cache.query.NameNotFoundException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) Token(org.apache.geode.internal.cache.Token) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) PdxSerializationException(org.apache.geode.pdx.PdxSerializationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NameNotFoundException(org.apache.geode.cache.query.NameNotFoundException) EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) Field(java.lang.reflect.Field) AccessibleObject(java.lang.reflect.AccessibleObject) Member(java.lang.reflect.Member)

Example 19 with EntryDestroyedException

use of org.apache.geode.cache.EntryDestroyedException in project geode by apache.

the class PartitionedRegionHelper method cleanUpMetaDataForRegion.

public static void cleanUpMetaDataForRegion(final InternalCache cache, final String prName, final DistributedMember failedMemId, final Runnable postCleanupTask) {
    boolean runPostCleanUp = true;
    try {
        final PartitionRegionConfig prConf;
        Region rootReg = PartitionedRegionHelper.getPRRoot(cache, false);
        if (rootReg == null) {
            return;
        }
        try {
            prConf = (PartitionRegionConfig) rootReg.get(prName);
        } catch (EntryDestroyedException ignore) {
            return;
        }
        if (prConf == null) {
            // so I added this check and continue
            return;
        }
        Set<Node> nodeList = prConf.getNodes();
        if (nodeList == null) {
            return;
        }
        for (final Node node1 : nodeList) {
            if (cache.getCancelCriterion().isCancelInProgress()) {
                return;
            }
            if (node1.getMemberId().equals(failedMemId)) {
                // Do the cleanup in another thread so we don't have the advisor locked.
                // Fix for #45365, we don't schedule an asynchronous task until
                // we have determined the node to remove (Which includes the
                // serial number).
                cache.getDistributionManager().getPrMetaDataCleanupThreadPool().execute(new Runnable() {

                    public void run() {
                        cleanPartitionedRegionMetaDataForNode(cache, node1, prConf, prName);
                        if (postCleanupTask != null) {
                            postCleanupTask.run();
                        }
                    }
                });
                runPostCleanUp = false;
                return;
            }
        }
    } finally {
        if (runPostCleanUp && postCleanupTask != null) {
            postCleanupTask.run();
        }
    }
}
Also used : EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) Region(org.apache.geode.cache.Region)

Example 20 with EntryDestroyedException

use of org.apache.geode.cache.EntryDestroyedException in project geode by apache.

the class CompiledOperation method evaluate.

public Object evaluate(ExecutionContext context) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
    CompiledValue rcvr = getReceiver(context);
    Object result;
    Object evalRcvr;
    if (rcvr == null) {
        // must be intended as implicit iterator operation
        // see if it's an implicit operation name
        RuntimeIterator rcvrItr = context.resolveImplicitOperationName(this.methodName, this.args.size(), true);
        evalRcvr = rcvrItr.evaluate(context);
    /*
       * // evaluate on current iteration of collection if (rcvrItr != null) { result =
       * eval0(rcvrItr.evaluate(context), rcvrItr.getElementType().resolveClass(), context); }
       * 
       * // function call: no functions implemented except keywords in the grammar throw new
       * TypeMismatchException(LocalizedStrings.CompiledOperation_COULD_NOT_RESOLVE_METHOD_NAMED_0.
       * toLocalizedString(this.methodName));
       */
    } else {
        // if not null, then explicit receiver
        evalRcvr = rcvr.evaluate(context);
    }
    // short circuit null immediately
    if (evalRcvr == null) {
        return QueryService.UNDEFINED;
    }
    if (context.isCqQueryContext() && evalRcvr instanceof Region.Entry) {
        Region.Entry re = (Region.Entry) evalRcvr;
        if (re.isDestroyed()) {
            return QueryService.UNDEFINED;
        }
        try {
            evalRcvr = re.getValue();
        } catch (EntryDestroyedException ede) {
            // throw EntryDestroyedException if the value becomes null.
            return QueryService.UNDEFINED;
        }
    }
    // check if the receiver is the iterator, in which
    // case we resolve the method on the constraint rather
    // than the runtime type of the receiver
    Class resolveClass = null;
    // if (resolveClass == null)
    if (evalRcvr instanceof PdxInstance) {
        String className = ((PdxInstance) evalRcvr).getClassName();
        try {
            resolveClass = InternalDataSerializer.getCachedClass(className);
        } catch (ClassNotFoundException cnfe) {
            throw new QueryInvocationTargetException(cnfe);
        }
    } else if (evalRcvr instanceof PdxString) {
        resolveClass = String.class;
    } else {
        resolveClass = evalRcvr.getClass();
    }
    result = eval0(evalRcvr, resolveClass, context);
    // }
    // check for PR substitution
    // check for BucketRegion substitution
    PartitionedRegion pr = context.getPartitionedRegion();
    if (pr != null && (result instanceof Region)) {
        if (pr.getFullPath().equals(((Region) result).getFullPath())) {
            result = context.getBucketRegion();
        }
    }
    return result;
}
Also used : EntryDestroyedException(org.apache.geode.cache.EntryDestroyedException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) PdxString(org.apache.geode.pdx.internal.PdxString) PdxString(org.apache.geode.pdx.internal.PdxString) PdxInstance(org.apache.geode.pdx.PdxInstance) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

Aggregations

EntryDestroyedException (org.apache.geode.cache.EntryDestroyedException)28 Region (org.apache.geode.cache.Region)12 QueryInvocationTargetException (org.apache.geode.cache.query.QueryInvocationTargetException)5 LRUEntry (org.apache.geode.internal.cache.lru.LRUEntry)5 StoredObject (org.apache.geode.internal.offheap.StoredObject)5 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 DiskAccessException (org.apache.geode.cache.DiskAccessException)4 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)4 Test (org.junit.Test)4 ByteBuf (io.netty.buffer.ByteBuf)3 Entry (java.util.Map.Entry)3 NoSuchElementException (java.util.NoSuchElementException)3 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)3 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)3 IOException (java.io.IOException)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)2 RollbackException (javax.transaction.RollbackException)2