Search in sources :

Example 16 with Operation

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

the class LocalRegion method findObjectInSystem.

/**
   * 
   * Search for the value in a server (if one exists), then try a loader.
   * 
   * If we find a value, we put it in the cache.
   * 
   * @param preferCD return the CacheDeserializable, if that's what the value is.
   * @param requestingClient the client making the request, if any
   * @param clientEvent the client's event, if any. If not null, we set the version tag
   * @return the deserialized value
   */
protected Object findObjectInSystem(KeyInfo keyInfo, boolean isCreate, TXStateInterface tx, boolean generateCallbacks, Object localValue, boolean disableCopyOnRead, boolean preferCD, ClientProxyMembershipID requestingClient, EntryEventImpl clientEvent, boolean returnTombstones) throws CacheLoaderException, TimeoutException {
    final Object key = keyInfo.getKey();
    final Object aCallbackArgument = keyInfo.getCallbackArg();
    Object value = null;
    boolean fromServer = false;
    VersionTagHolder holder = null;
    /*
     * First lets try the server
     */
    ServerRegionProxy mySRP = getServerProxy();
    if (mySRP != null) {
        holder = new VersionTagHolder();
        value = mySRP.get(key, aCallbackArgument, holder);
        fromServer = value != null;
    }
    /*
     * If we didn't get anything from the server, try the loader
     */
    if (!fromServer || value == Token.TOMBSTONE) {
        // copy into local var to prevent race condition
        CacheLoader loader = basicGetLoader();
        if (loader != null) {
            final LoaderHelper loaderHelper = this.loaderHelperFactory.createLoaderHelper(key, aCallbackArgument, false, /* netSearchAllowed */
            true, /* netloadAllowed */
            null);
            CachePerfStats stats = getCachePerfStats();
            long statStart = stats.startLoad();
            try {
                value = loader.load(loaderHelper);
                fromServer = false;
            } finally {
                stats.endLoad(statStart);
            }
        }
    }
    // have concurrency checks enabled
    if (fromServer && value == Token.TOMBSTONE && !this.concurrencyChecksEnabled) {
        value = null;
    }
    /*
     * If we got a value back, let's put it in the cache.
     */
    RegionEntry re = null;
    if (value != null && !isMemoryThresholdReachedForLoad()) {
        long startPut = CachePerfStats.getStatTime();
        validateKey(key);
        Operation op;
        if (isCreate) {
            op = Operation.LOCAL_LOAD_CREATE;
        } else {
            op = Operation.LOCAL_LOAD_UPDATE;
        }
        @Released EntryEventImpl event = EntryEventImpl.create(this, op, key, value, aCallbackArgument, false, getMyId(), generateCallbacks);
        try {
            // already one there with the same version
            if (fromServer) {
                if (alreadyInvalid(key, event)) {
                    return null;
                }
                event.setFromServer(fromServer);
                event.setVersionTag(holder.getVersionTag());
                if (clientEvent != null) {
                    clientEvent.setVersionTag(holder.getVersionTag());
                }
            }
            // the value to the server
            if (!fromServer) {
                event.setNewEventId(this.cache.getDistributedSystem());
            }
            try {
                try {
                    re = basicPutEntry(event, 0L);
                    if (!fromServer && clientEvent != null) {
                        clientEvent.setVersionTag(event.getVersionTag());
                        clientEvent.isConcurrencyConflict(event.isConcurrencyConflict());
                    }
                    if (fromServer && event.getRawNewValue() == Token.TOMBSTONE) {
                        // tombstones are destroyed entries
                        return null;
                    }
                } catch (ConcurrentCacheModificationException ignore) {
                    // this means the value attempted to overwrite a newer modification and was rejected
                    if (logger.isDebugEnabled()) {
                        logger.debug("caught concurrent modification attempt when applying {}", event);
                    }
                    notifyBridgeClients(event);
                }
                if (!getDataView().isDeferredStats()) {
                    getCachePerfStats().endPut(startPut, event.isOriginRemote());
                }
            } catch (CacheWriterException cwe) {
                if (logger.isDebugEnabled()) {
                    logger.debug("findObjectInSystem: writer exception putting entry {}", event, cwe);
                }
            }
        } finally {
            event.release();
        }
    }
    if (isCreate) {
        recordMiss(re, key);
    }
    return value;
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) Operation(org.apache.geode.cache.Operation) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException) LoaderHelper(org.apache.geode.cache.LoaderHelper) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) StoredObject(org.apache.geode.internal.offheap.StoredObject) CacheLoader(org.apache.geode.cache.CacheLoader) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 17 with Operation

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

the class LocalRegion method virtualPut.

/**
   * Subclasses should reimplement if needed
   */
boolean virtualPut(final EntryEventImpl event, final boolean ifNew, final boolean ifOld, Object expectedOldValue, boolean requireOldValue, final long lastModified, final boolean overwriteDestroyed) throws TimeoutException, CacheWriterException {
    if (!MemoryThresholds.isLowMemoryExceptionDisabled()) {
        checkIfAboveThreshold(event);
    }
    Operation originalOp = event.getOperation();
    RegionEntry oldEntry;
    try {
        oldEntry = this.entries.basicPut(event, lastModified, ifNew, ifOld, expectedOldValue, requireOldValue, overwriteDestroyed);
    } catch (ConcurrentCacheModificationException ignore) {
        // thread got around to doing so
        if (logger.isDebugEnabled()) {
            logger.debug("caught concurrent modification attempt when applying {}", event);
        }
        notifyBridgeClients(event);
        return false;
    }
    // for EMPTY clients, see if a concurrent map operation had an entry on the server
    ServerRegionProxy mySRP = getServerProxy();
    if (mySRP != null && this.dataPolicy == DataPolicy.EMPTY) {
        if (originalOp == Operation.PUT_IF_ABSENT) {
            return !event.hasOldValue();
        }
        if (originalOp == Operation.REPLACE && !requireOldValue) {
            // LocalRegion.serverPut throws an EntryNotFoundException if the operation failed
            return true;
        }
    }
    return oldEntry != null;
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) Operation(org.apache.geode.cache.Operation) ConcurrentCacheModificationException(org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)

Example 18 with Operation

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

the class LocalRegion method invokeTXCallbacks.

public void invokeTXCallbacks(final EnumListenerEvent eventType, final EntryEventImpl event, final boolean callDispatchListenerEvent) {
    // The spec for ConcurrentMap support requires that operations be mapped
    // to non-CM counterparts
    Operation operation = event.getOperation();
    if (logger.isDebugEnabled()) {
        logger.debug("invokeTXCallbacks for event {}", event);
    }
    if (operation == Operation.REMOVE) {
        event.setOperation(Operation.DESTROY);
    } else if (operation == Operation.PUT_IF_ABSENT) {
        event.setOperation(Operation.CREATE);
    } else if (operation == Operation.REPLACE) {
        event.setOperation(Operation.UPDATE);
    }
    event.setEventType(eventType);
    notifyBridgeClients(event);
    notifyGatewaySender(eventType, event);
    if (callDispatchListenerEvent) {
        if (event.getInvokePRCallbacks() || !(event.getRegion() instanceof PartitionedRegion) && !event.getRegion().isUsedForPartitionedRegionBucket()) {
            dispatchListenerEvent(eventType, event);
        }
    }
}
Also used : Operation(org.apache.geode.cache.Operation)

Example 19 with Operation

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

the class LocalRegion method invalidateAllEntries.

/**
   * @param rgnEvent the RegionEvent for region invalidation
   */
protected void invalidateAllEntries(RegionEvent rgnEvent) {
    Operation operation = Operation.LOCAL_INVALIDATE;
    if (rgnEvent.getOperation().isDistributed()) {
        operation = Operation.INVALIDATE;
    }
    // region operation so it is ok to ignore tx state
    for (Object keyObject : keySet()) {
        try {
            // EventID will not be generated by this constructor
            @Released EntryEventImpl event = EntryEventImpl.create(this, operation, keyObject, null, null, rgnEvent.isOriginRemote(), rgnEvent.getDistributedMember());
            try {
                event.setLocalInvalid(!rgnEvent.getOperation().isDistributed());
                basicInvalidate(event, false);
            } finally {
                event.release();
            }
        } catch (EntryNotFoundException ignore) {
        // ignore
        }
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) StoredObject(org.apache.geode.internal.offheap.StoredObject) Operation(org.apache.geode.cache.Operation)

Example 20 with Operation

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

the class EntryEventImpl method createRemoveAllEvent.

@Retained
protected static EntryEventImpl createRemoveAllEvent(DistributedRemoveAllOperation op, LocalRegion region, Object entryKey) {
    @Retained EntryEventImpl e;
    final Operation entryOp = Operation.REMOVEALL_DESTROY;
    if (op != null) {
        EntryEventImpl event = op.getBaseEvent();
        if (event.isBridgeEvent()) {
            e = EntryEventImpl.create(region, entryOp, entryKey, null, event.getRawCallbackArgument(), false, event.distributedMember, event.isGenerateCallbacks());
            e.setContext(event.getContext());
        } else {
            e = EntryEventImpl.create(region, entryOp, entryKey, null, event.getCallbackArgument(), false, region.getMyId(), event.isGenerateCallbacks());
        }
    } else {
        e = EntryEventImpl.create(region, entryOp, entryKey, null, null, false, region.getMyId(), true);
    }
    e.removeAllOp = op;
    return e;
}
Also used : Retained(org.apache.geode.internal.offheap.annotations.Retained) Operation(org.apache.geode.cache.Operation) EntryOperation(org.apache.geode.cache.EntryOperation) Retained(org.apache.geode.internal.offheap.annotations.Retained)

Aggregations

Operation (org.apache.geode.cache.Operation)26 Released (org.apache.geode.internal.offheap.annotations.Released)6 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)4 ServerRegionProxy (org.apache.geode.cache.client.internal.ServerRegionProxy)3 StoredObject (org.apache.geode.internal.offheap.StoredObject)3 Retained (org.apache.geode.internal.offheap.annotations.Retained)3 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 CancelException (org.apache.geode.CancelException)2 CacheLoader (org.apache.geode.cache.CacheLoader)2 CacheWriterException (org.apache.geode.cache.CacheWriterException)2 LoaderHelper (org.apache.geode.cache.LoaderHelper)2 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)2 Portfolio (org.apache.geode.cache.query.data.Portfolio)2 EventID (org.apache.geode.internal.cache.EventID)2 EventIDHolder (org.apache.geode.internal.cache.EventIDHolder)2 LocalRegion (org.apache.geode.internal.cache.LocalRegion)2 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2