Search in sources :

Example 1 with Released

use of org.apache.geode.internal.offheap.annotations.Released in project geode by apache.

the class DummyQRegion method getValues.

@Override
public SelectResults getValues() {
    if (values == null) {
        values = new ResultsBag(((HasCachePerfStats) getRegion().getCache()).getCachePerfStats());
        values.setElementType(valueType);
    }
    values.clear();
    Object val = this.entry.getValueOffHeapOrDiskWithoutFaultIn((LocalRegion) getRegion());
    if (val instanceof StoredObject) {
        @Retained @Released StoredObject ohval = (StoredObject) val;
        try {
            val = ohval.getDeserializedValue(getRegion(), this.entry);
        } finally {
            ohval.release();
        }
    } else if (val instanceof CachedDeserializable) {
        val = ((CachedDeserializable) val).getDeserializedValue(getRegion(), this.entry);
    }
    values.add(val);
    return values;
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) StoredObject(org.apache.geode.internal.offheap.StoredObject) Retained(org.apache.geode.internal.offheap.annotations.Retained) CachedDeserializable(org.apache.geode.internal.cache.CachedDeserializable) HasCachePerfStats(org.apache.geode.internal.cache.HasCachePerfStats) StoredObject(org.apache.geode.internal.offheap.StoredObject) ResultsBag(org.apache.geode.cache.query.internal.ResultsBag)

Example 2 with Released

use of org.apache.geode.internal.offheap.annotations.Released in project geode by apache.

the class DummyQRegion method toArray.

@Override
public Object[] toArray() {
    if (valueInArray == null) {
        valueInArray = new Object[1];
    }
    Object val = this.entry.getValueOffHeapOrDiskWithoutFaultIn((LocalRegion) getRegion());
    if (val instanceof StoredObject) {
        @Retained @Released StoredObject ohval = (StoredObject) val;
        try {
            val = ohval.getDeserializedValue(getRegion(), this.entry);
        } finally {
            ohval.release();
        }
    } else if (val instanceof CachedDeserializable) {
        val = ((CachedDeserializable) val).getDeserializedValue(getRegion(), this.entry);
    }
    valueInArray[0] = val;
    return valueInArray;
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) StoredObject(org.apache.geode.internal.offheap.StoredObject) Retained(org.apache.geode.internal.offheap.annotations.Retained) CachedDeserializable(org.apache.geode.internal.cache.CachedDeserializable) StoredObject(org.apache.geode.internal.offheap.StoredObject)

Example 3 with Released

use of org.apache.geode.internal.offheap.annotations.Released in project geode by apache.

the class ClientStatsManager method publishClientStats.

/**
   * This method publishes the client stats using the admin region.
   * 
   * @param pool Connection pool which may be used for admin region.
   */
public static synchronized void publishClientStats(PoolImpl pool) {
    InternalCache currentCache = GemFireCacheImpl.getInstance();
    if (!initializeStatistics(currentCache)) {
        // handles null case too
        return;
    }
    LogWriterI18n logger = currentCache.getLoggerI18n();
    if (logger.fineEnabled())
        logger.fine("Entering ClientStatsManager#publishClientStats...");
    ClientHealthStats stats = getClientHealthStats(currentCache, pool);
    try {
        InternalDistributedSystem ds = (InternalDistributedSystem) currentCache.getDistributedSystem();
        ServerRegionProxy regionProxy = new ServerRegionProxy(ClientHealthMonitoringRegion.ADMIN_REGION_NAME, pool);
        EventID eventId = new EventID(ds);
        @Released EntryEventImpl event = new EntryEventImpl((Object) null);
        try {
            event.setEventId(eventId);
            regionProxy.putForMetaRegion(ds.getMemberId(), stats, null, event, null, true);
        } finally {
            event.release();
        }
    } catch (DistributedSystemDisconnectedException e) {
        throw e;
    } catch (CacheWriterException cwx) {
        pool.getCancelCriterion().checkCancelInProgress(cwx);
        currentCache.getCancelCriterion().checkCancelInProgress(cwx);
        // TODO: Need to analyze these exception scenarios.
        logger.warning(LocalizedStrings.ClientStatsManager_FAILED_TO_SEND_CLIENT_HEALTH_STATS_TO_CACHESERVER, cwx);
    } catch (Exception e) {
        pool.getCancelCriterion().checkCancelInProgress(e);
        currentCache.getCancelCriterion().checkCancelInProgress(e);
        logger.info(LocalizedStrings.ClientStatsManager_FAILED_TO_PUBLISH_CLIENT_STATISTICS, e);
    }
    if (logger.fineEnabled()) {
        logger.fine("Exiting ClientStatsManager#publishClientStats.");
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) Released(org.apache.geode.internal.offheap.annotations.Released) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) InternalCache(org.apache.geode.internal.cache.InternalCache) EventID(org.apache.geode.internal.cache.EventID) LogWriterI18n(org.apache.geode.i18n.LogWriterI18n) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ClientHealthStats(org.apache.geode.internal.admin.remote.ClientHealthStats) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CacheWriterException(org.apache.geode.cache.CacheWriterException) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 4 with Released

use of org.apache.geode.internal.offheap.annotations.Released in project geode by apache.

the class PutMessage method operateOnPartitionedRegion.

/**
   * This method is called upon receipt and make the desired changes to the PartitionedRegion Note:
   * It is very important that this message does NOT cause any deadlocks as the sender will wait
   * indefinitely for the acknowledgement
   */
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion r, long startTime) throws EntryExistsException, DataLocationException, IOException {
    // set the internal DS. Required to
    this.setInternalDs(r.getSystem());
    // checked DS level delta-enabled property
    // while sending delta
    PartitionedRegionDataStore ds = r.getDataStore();
    boolean sendReply = true;
    InternalDistributedMember eventSender = originalSender;
    if (eventSender == null) {
        eventSender = getSender();
    }
    @Released final EntryEventImpl ev = EntryEventImpl.create(r, getOperation(), getKey(), null, /* newValue */
    getCallbackArg(), false, /* originRemote - false to force distribution in buckets */
    eventSender, true, /* generateCallbacks */
    false);
    try {
        if (this.versionTag != null) {
            this.versionTag.replaceNullIDs(getSender());
            ev.setVersionTag(this.versionTag);
        }
        if (this.bridgeContext != null) {
            ev.setContext(this.bridgeContext);
        }
        Assert.assertTrue(eventId != null);
        ev.setEventId(eventId);
        ev.setCausedByMessage(this);
        ev.setInvokePRCallbacks(!notificationOnly);
        ev.setPossibleDuplicate(this.posDup);
        /*
       * if (this.hasOldValue) { if (this.oldValueIsSerialized) {
       * ev.setSerializedOldValue(getOldValueBytes()); } else { ev.setOldValue(getOldValueBytes());
       * } }
       */
        ev.setDeltaBytes(this.deltaBytes);
        if (this.hasDelta) {
            this.valObj = null;
            // New value will be set once it is generated with fromDelta() inside
            // EntryEventImpl.processDeltaBytes()
            ev.setNewValue(this.valObj);
        } else {
            switch(this.deserializationPolicy) {
                case DistributedCacheOperation.DESERIALIZATION_POLICY_LAZY:
                    ev.setSerializedNewValue(getValBytes());
                    break;
                case DistributedCacheOperation.DESERIALIZATION_POLICY_NONE:
                    ev.setNewValue(getValBytes());
                    break;
                default:
                    throw new AssertionError("unknown deserialization policy: " + deserializationPolicy);
            }
        }
        if (!notificationOnly) {
            if (ds == null) {
                throw new AssertionError("This process should have storage" + " for this operation: " + this.toString());
            }
            try {
                // the event must show it's true origin for cachewriter invocation
                // event.setOriginRemote(true);
                // this.op = r.doCacheWriteBeforePut(event, ifNew); // TODO fix this for bug 37072
                ev.setOriginRemote(false);
                result = r.getDataView().putEntryOnRemote(ev, this.ifNew, this.ifOld, this.expectedOldValue, this.requireOldValue, this.lastModified, true);
                if (!this.result) {
                    // make sure the region hasn't gone away
                    r.checkReadiness();
                // sbawaska: I cannot see how ifOld and ifNew can both be false, hence removing
                // if (!this.ifNew && !this.ifOld) {
                // // no reason to be throwing an exception, so let's retry
                // ForceReattemptException fre = new ForceReattemptException(
                // LocalizedStrings.PutMessage_UNABLE_TO_PERFORM_PUT_BUT_OPERATION_SHOULD_NOT_FAIL_0.toLocalizedString());
                // fre.setHash(key.hashCode());
                // sendReply(getSender(), getProcessorId(), dm,
                // new ReplyException(fre), r, startTime);
                // sendReply = false;
                // }
                }
            } catch (CacheWriterException cwe) {
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(cwe), r, startTime);
                return false;
            } catch (PrimaryBucketException pbe) {
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
                return false;
            } catch (InvalidDeltaException ide) {
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(ide), r, startTime);
                r.getCachePerfStats().incDeltaFullValuesRequested();
                return false;
            }
            if (logger.isTraceEnabled(LogMarker.DM)) {
                logger.trace(LogMarker.DM, "PutMessage {} with key: {} val: {}", (result ? "updated bucket" : "did not update bucket"), getKey(), (getValBytes() == null ? "null" : "(" + getValBytes().length + " bytes)"));
            }
        } else {
            // notificationOnly
            @Released EntryEventImpl e2 = createListenerEvent(ev, r, dm.getDistributionManagerId());
            final EnumListenerEvent le;
            try {
                if (e2.getOperation().isCreate()) {
                    le = EnumListenerEvent.AFTER_CREATE;
                } else {
                    le = EnumListenerEvent.AFTER_UPDATE;
                }
                r.invokePutCallbacks(le, e2, r.isInitialized(), true);
            } finally {
                // if e2 == ev then no need to free it here. The outer finally block will get it.
                if (e2 != ev) {
                    e2.release();
                }
            }
            result = true;
        }
        // set operation for reply message
        setOperation(ev.getOperation());
        if (sendReply) {
            sendReply(getSender(), getProcessorId(), dm, null, r, startTime, ev);
        }
        return false;
    } finally {
        ev.release();
    }
}
Also used : InvalidDeltaException(org.apache.geode.InvalidDeltaException) EnumListenerEvent(org.apache.geode.internal.cache.EnumListenerEvent) Released(org.apache.geode.internal.offheap.annotations.Released) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) ReplyException(org.apache.geode.distributed.internal.ReplyException) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 5 with Released

use of org.apache.geode.internal.offheap.annotations.Released in project geode by apache.

the class DestroyMessage method operateOnPartitionedRegion.

/**
   * This method is called upon receipt and make the desired changes to the PartitionedRegion Note:
   * It is very important that this message does NOT cause any deadlocks as the sender will wait
   * indefinitely for the acknowledgement
   */
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion r, long startTime) throws EntryExistsException, DataLocationException {
    InternalDistributedMember eventSender = originalSender;
    if (eventSender == null) {
        eventSender = getSender();
    }
    @Released EntryEventImpl event = null;
    try {
        if (this.bridgeContext != null) {
            event = EntryEventImpl.create(r, getOperation(), this.key, null, /* newValue */
            getCallbackArg(), false, /* originRemote */
            eventSender, true);
            event.setContext(this.bridgeContext);
        } else // bridgeContext != null
        {
            event = EntryEventImpl.create(r, getOperation(), this.key, null, /* newValue */
            getCallbackArg(), false, /* originRemote - false to force distribution in buckets */
            eventSender, true, /* generateCallbacks */
            false);
        }
        if (this.versionTag != null) {
            this.versionTag.replaceNullIDs(getSender());
            event.setVersionTag(this.versionTag);
        }
        event.setInvokePRCallbacks(!notificationOnly);
        Assert.assertTrue(eventId != null);
        event.setEventId(eventId);
        event.setPossibleDuplicate(this.posDup);
        PartitionedRegionDataStore ds = r.getDataStore();
        boolean sendReply = true;
        if (!notificationOnly) {
            Assert.assertTrue(ds != null, "This process should have storage for an item in " + this.toString());
            try {
                Integer bucket = Integer.valueOf(PartitionedRegionHelper.getHashKey(r, null, this.key, null, this.cbArg));
                // try {
                // // the event must show its true origin for cachewriter invocation
                // event.setOriginRemote(true);
                // event.setPartitionMessage(this);
                // r.doCacheWriteBeforeDestroy(event);
                // }
                // finally {
                // event.setOriginRemote(false);
                // }
                event.setCausedByMessage(this);
                r.getDataView().destroyOnRemote(event, true, /* cacheWrite */
                this.expectedOldValue);
                if (logger.isTraceEnabled(LogMarker.DM)) {
                    logger.trace(LogMarker.DM, "{} updated bucket: {} with key: {}", getClass().getName(), bucket, this.key);
                }
            } catch (CacheWriterException cwe) {
                sendReply(getSender(), this.processorId, dm, new ReplyException(cwe), r, startTime);
                return false;
            } catch (EntryNotFoundException eee) {
                logger.trace(LogMarker.DM, "{}: operateOnRegion caught EntryNotFoundException", getClass().getName());
                ReplyMessage.send(getSender(), getProcessorId(), new ReplyException(eee), getReplySender(dm), r.isInternalRegion());
                // this prevents us from acking later
                sendReply = false;
            } catch (PrimaryBucketException pbe) {
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
                sendReply = false;
            } finally {
                this.versionTag = event.getVersionTag();
            }
        } else {
            @Released EntryEventImpl e2 = createListenerEvent(event, r, dm.getDistributionManagerId());
            try {
                r.invokeDestroyCallbacks(EnumListenerEvent.AFTER_DESTROY, e2, r.isInitialized(), true);
            } finally {
                // if e2 == ev then no need to free it here. The outer finally block will get it.
                if (e2 != event) {
                    e2.release();
                }
            }
        }
        return sendReply;
    } finally {
        if (event != null) {
            event.release();
        }
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) ReplyException(org.apache.geode.distributed.internal.ReplyException) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Aggregations

Released (org.apache.geode.internal.offheap.annotations.Released)57 StoredObject (org.apache.geode.internal.offheap.StoredObject)29 CacheWriterException (org.apache.geode.cache.CacheWriterException)13 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)13 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)12 ConcurrentCacheModificationException (org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)9 GatewaySenderEventCallbackArgument (org.apache.geode.internal.cache.wan.GatewaySenderEventCallbackArgument)9 Retained (org.apache.geode.internal.offheap.annotations.Retained)9 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)8 VersionedObjectList (org.apache.geode.internal.cache.tier.sockets.VersionedObjectList)8 DiskAccessException (org.apache.geode.cache.DiskAccessException)6 Operation (org.apache.geode.cache.Operation)6 ReplyException (org.apache.geode.distributed.internal.ReplyException)6 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)5 IndexManager (org.apache.geode.cache.query.internal.index.IndexManager)5 PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)5 TimeoutException (org.apache.geode.cache.TimeoutException)4 EventID (org.apache.geode.internal.cache.EventID)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3