Search in sources :

Example 36 with InternalGemFireError

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

the class PeerTypeRegistration method getExistingIdForType.

/** Should be called holding the dlock */
private int getExistingIdForType(PdxType newType) {
    int totalPdxTypeIdInDS = 0;
    TXStateProxy currentState = suspendTX();
    try {
        int result = -1;
        for (Map.Entry<Object, Object> entry : getIdToType().entrySet()) {
            Object v = entry.getValue();
            Object k = entry.getKey();
            if (k instanceof EnumId) {
                EnumId id = (EnumId) k;
                EnumInfo info = (EnumInfo) v;
                enumToId.put(info, id);
            } else {
                PdxType foundType = (PdxType) v;
                Integer id = (Integer) k;
                int tmpDsId = PLACE_HOLDER_FOR_DS_ID & id;
                if (tmpDsId == this.dsId) {
                    totalPdxTypeIdInDS++;
                }
                typeToId.put(foundType, id);
                if (foundType.equals(newType)) {
                    result = foundType.getTypeId();
                }
            }
        }
        if (totalPdxTypeIdInDS == this.maxTypeId) {
            throw new InternalGemFireError("Used up all of the PDX type ids for this distributed system. The maximum number of PDX types is " + this.maxTypeId);
        }
        return result;
    } finally {
        resumeTX(currentState);
    }
}
Also used : TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) HashMap(java.util.HashMap) CopyOnWriteHashMap(org.apache.geode.internal.util.concurrent.CopyOnWriteHashMap) Map(java.util.Map) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 37 with InternalGemFireError

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

the class PeerTypeRegistration method allocateEnumId.

private EnumId allocateEnumId(EnumInfo ei) {
    TXStateProxy currentState = suspendTX();
    Region<Object, Object> r = getIdToType();
    int id = ei.hashCode() & PLACE_HOLDER_FOR_TYPE_ID;
    int newEnumId = id | this.dsId;
    try {
        int maxTry = this.maxTypeId;
        // Find the next available type id.
        while (r.get(new EnumId(newEnumId)) != null) {
            maxTry--;
            if (maxTry == 0) {
                throw new InternalGemFireError("Used up all of the PDX type ids for this distributed system. The maximum number of PDX types is " + this.maxTypeId);
            }
            // Find the next available type id.
            id++;
            if (id > this.maxTypeId) {
                id = 1;
            }
            newEnumId = id | this.dsId;
        }
        return new EnumId(newEnumId);
    } finally {
        resumeTX(currentState);
    }
}
Also used : TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 38 with InternalGemFireError

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

the class LuceneEventListener method process.

protected boolean process(final List<AsyncEvent> events) {
    // Try to get a PDX instance if possible, rather than a deserialized object
    DefaultQuery.setPdxReadSerialized(true);
    Set<IndexRepository> affectedRepos = new HashSet<IndexRepository>();
    try {
        for (AsyncEvent event : events) {
            Region region = event.getRegion();
            Object key = event.getKey();
            Object callbackArgument = event.getCallbackArgument();
            IndexRepository repository = repositoryManager.getRepository(region, key, callbackArgument);
            Object value = getValue(region.getEntry(key));
            if (value != null) {
                repository.update(key, value);
            } else {
                repository.delete(key);
            }
            affectedRepos.add(repository);
        }
        for (IndexRepository repo : affectedRepos) {
            repo.commit();
        }
        return true;
    } catch (BucketNotFoundException | RegionDestroyedException | PrimaryBucketException e) {
        logger.debug("Bucket not found while saving to lucene index: " + e.getMessage(), e);
        return false;
    } catch (CacheClosedException e) {
        logger.debug("Unable to save to lucene index, cache has been closed", e);
        return false;
    } catch (AlreadyClosedException e) {
        logger.debug("Unable to commit, the lucene index is already closed", e);
        return false;
    } catch (IOException e) {
        throw new InternalGemFireError("Unable to save to lucene index", e);
    } finally {
        DefaultQuery.setPdxReadSerialized(false);
    }
}
Also used : RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) IOException(java.io.IOException) AsyncEvent(org.apache.geode.cache.asyncqueue.AsyncEvent) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) IndexRepository(org.apache.geode.cache.lucene.internal.repository.IndexRepository) Region(org.apache.geode.cache.Region) BucketNotFoundException(org.apache.geode.internal.cache.BucketNotFoundException) HashSet(java.util.HashSet) InternalGemFireError(org.apache.geode.InternalGemFireError)

Aggregations

InternalGemFireError (org.apache.geode.InternalGemFireError)38 IOException (java.io.IOException)8 HashMap (java.util.HashMap)5 Map (java.util.Map)5 TXStateProxy (org.apache.geode.internal.cache.TXStateProxy)5 HashSet (java.util.HashSet)4 ExecutionException (java.util.concurrent.ExecutionException)4 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)4 Set (java.util.Set)3 Future (java.util.concurrent.Future)3 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)3 ServerOperationException (org.apache.geode.cache.client.ServerOperationException)3 InternalRegionArguments (org.apache.geode.internal.cache.InternalRegionArguments)3 Part (org.apache.geode.internal.cache.tier.sockets.Part)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2