Search in sources :

Example 1 with VersionTagHolder

use of org.apache.geode.internal.cache.VersionTagHolder in project geode by apache.

the class Get70 method getEntryRetained.

/**
   * Same as getValueAndIsObject but the returned value can be a retained off-heap reference.
   */
@Retained
public Entry getEntryRetained(Region region, Object key, Object callbackArg, ServerConnection servConn) {
    // Region.Entry entry;
    String regionName = region.getFullPath();
    if (servConn != null) {
        servConn.setModificationInfo(true, regionName, key);
    }
    VersionTag versionTag = null;
    // LocalRegion lregion = (LocalRegion)region;
    // entry = lregion.getEntry(key, true);
    boolean isObject = true;
    @Retained Object data = null;
    ClientProxyMembershipID id = servConn == null ? null : servConn.getProxyID();
    VersionTagHolder versionHolder = new VersionTagHolder();
    data = ((LocalRegion) region).getRetained(key, callbackArg, true, true, id, versionHolder, true);
    versionTag = versionHolder.getVersionTag();
    // If it is Token.REMOVED, Token.DESTROYED,
    // Token.INVALID, or Token.LOCAL_INVALID
    // set it to null. If it is NOT_AVAILABLE, get the value from
    // disk. If it is already a byte[], set isObject to false.
    boolean wasInvalid = false;
    if (data == Token.REMOVED_PHASE1 || data == Token.REMOVED_PHASE2 || data == Token.DESTROYED) {
        data = null;
    } else if (data == Token.INVALID || data == Token.LOCAL_INVALID) {
        // fix for bug 35884
        data = null;
        wasInvalid = true;
    } else if (data instanceof byte[]) {
        isObject = false;
    } else if (data instanceof CachedDeserializable) {
        CachedDeserializable cd = (CachedDeserializable) data;
        isObject = cd.isSerialized();
        if (cd.usesHeapForStorage()) {
            data = cd.getValue();
        }
    }
    Entry result = new Entry();
    result.value = data;
    result.isObject = isObject;
    result.keyNotPresent = !wasInvalid && (data == null || data == Token.TOMBSTONE);
    result.versionTag = versionTag;
    return result;
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) Retained(org.apache.geode.internal.offheap.annotations.Retained) VersionTagHolder(org.apache.geode.internal.cache.VersionTagHolder) CachedDeserializable(org.apache.geode.internal.cache.CachedDeserializable) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) Retained(org.apache.geode.internal.offheap.annotations.Retained)

Example 2 with VersionTagHolder

use of org.apache.geode.internal.cache.VersionTagHolder in project geode by apache.

the class GetMessage method operateOnPartitionedRegion.

@Override
protected boolean operateOnPartitionedRegion(final DistributionManager dm, PartitionedRegion r, long startTime) throws ForceReattemptException {
    if (logger.isTraceEnabled(LogMarker.DM)) {
        logger.trace(LogMarker.DM, "GetMessage operateOnRegion: {}", r.getFullPath());
    }
    PartitionedRegionDataStore ds = r.getDataStore();
    if (this.getTXUniqId() != TXManagerImpl.NOTX) {
        assert r.getDataView() instanceof TXStateProxy;
    }
    RawValue valueBytes;
    Object val = null;
    try {
        if (ds != null) {
            VersionTagHolder event = new VersionTagHolder();
            try {
                KeyInfo keyInfo = r.getKeyInfo(key, cbArg);
                boolean lockEntry = forceUseOfPRExecutor || isDirectAck();
                val = r.getDataView().getSerializedValue(r, keyInfo, !lockEntry, this.context, event, returnTombstones);
                if (val == BucketRegion.REQUIRES_ENTRY_LOCK) {
                    Assert.assertTrue(!lockEntry);
                    this.forceUseOfPRExecutor = true;
                    if (logger.isDebugEnabled()) {
                        logger.debug("Rescheduling GetMessage due to possible cache-miss");
                    }
                    schedule(dm);
                    return false;
                }
                valueBytes = val instanceof RawValue ? (RawValue) val : new RawValue(val);
            } catch (DistributedSystemDisconnectedException sde) {
                sendReply(getSender(), this.processorId, dm, new ReplyException(new ForceReattemptException(LocalizedStrings.GetMessage_OPERATION_GOT_INTERRUPTED_DUE_TO_SHUTDOWN_IN_PROGRESS_ON_REMOTE_VM.toLocalizedString(), sde)), r, startTime);
                return false;
            } catch (PrimaryBucketException pbe) {
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
                return false;
            } catch (DataLocationException e) {
                sendReply(getSender(), getProcessorId(), dm, new ReplyException(e), r, startTime);
                return false;
            }
            if (logger.isTraceEnabled(LogMarker.DM)) {
                logger.debug("GetMessage sending serialized value {} back via GetReplyMessage using processorId: {}", valueBytes, getProcessorId());
            }
            r.getPrStats().endPartitionMessagesProcessing(startTime);
            GetReplyMessage.send(getSender(), getProcessorId(), valueBytes, getReplySender(dm), event.getVersionTag());
            // response
            return false;
        } else {
            throw new InternalGemFireError(LocalizedStrings.GetMessage_GET_MESSAGE_SENT_TO_WRONG_MEMBER.toLocalizedString());
        }
    } finally {
        OffHeapHelper.release(val);
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) DataLocationException(org.apache.geode.internal.cache.DataLocationException) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) PrimaryBucketException(org.apache.geode.internal.cache.PrimaryBucketException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) VersionTagHolder(org.apache.geode.internal.cache.VersionTagHolder) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) KeyInfo(org.apache.geode.internal.cache.KeyInfo) RawValue(org.apache.geode.internal.cache.BucketRegion.RawValue) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 3 with VersionTagHolder

use of org.apache.geode.internal.cache.VersionTagHolder in project geode by apache.

the class BaseCommand method handleKVAllKeys.

private static void handleKVAllKeys(LocalRegion region, String regex, boolean serializeValues, ServerConnection servConn) throws IOException {
    if (region instanceof PartitionedRegion) {
        handleKVKeysPR((PartitionedRegion) region, regex, serializeValues, servConn);
        return;
    }
    VersionedObjectList values = new VersionedObjectList(MAXIMUM_CHUNK_SIZE, true, region == null || region.getAttributes().getConcurrencyChecksEnabled(), serializeValues);
    if (region != null) {
        Pattern keyPattern = null;
        if (regex != null) {
            keyPattern = Pattern.compile(regex);
        }
        for (Object key : region.keySet(true)) {
            VersionTagHolder versionHolder = createVersionTagHolder();
            if (keyPattern != null) {
                if (!(key instanceof String)) {
                    // key is not a String, cannot apply regex to this entry
                    continue;
                }
                if (!keyPattern.matcher((String) key).matches()) {
                    // returned.
                    continue;
                }
            }
            ClientProxyMembershipID id = servConn == null ? null : servConn.getProxyID();
            Object data = region.get(key, null, true, true, true, id, versionHolder, true);
            VersionTag versionTag = versionHolder.getVersionTag();
            updateValues(values, key, data, versionTag);
            if (values.size() == MAXIMUM_CHUNK_SIZE) {
                sendNewRegisterInterestResponseChunk(region, regex != null ? regex : "ALL_KEYS", values, false, servConn);
                values.clear();
            }
        }
    // for
    }
    // if
    // Send the last chunk (the only chunk for individual and list keys)
    // always send it back, even if the list is of zero size.
    sendNewRegisterInterestResponseChunk(region, regex != null ? regex : "ALL_KEYS", values, true, servConn);
}
Also used : Pattern(java.util.regex.Pattern) VersionTagHolder(org.apache.geode.internal.cache.VersionTagHolder) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VersionTag(org.apache.geode.internal.cache.versions.VersionTag)

Example 4 with VersionTagHolder

use of org.apache.geode.internal.cache.VersionTagHolder in project geode by apache.

the class BaseCommand method handleKVList.

private static void handleKVList(final LocalRegion region, final List keyList, boolean serializeValues, final ServerConnection servConn) throws IOException {
    if (region instanceof PartitionedRegion) {
        handleKVKeysPR((PartitionedRegion) region, keyList, serializeValues, servConn);
        return;
    }
    VersionedObjectList values = new VersionedObjectList(MAXIMUM_CHUNK_SIZE, true, region == null || region.getAttributes().getConcurrencyChecksEnabled(), serializeValues);
    // Handle list of keys
    if (region != null) {
        for (Object key : keyList) {
            if (region.containsKey(key) || region.containsTombstone(key)) {
                VersionTagHolder versionHolder = createVersionTagHolder();
                ClientProxyMembershipID id = servConn == null ? null : servConn.getProxyID();
                Object data = region.get(key, null, true, true, true, id, versionHolder, true);
                VersionTag versionTag = versionHolder.getVersionTag();
                updateValues(values, key, data, versionTag);
                if (values.size() == MAXIMUM_CHUNK_SIZE) {
                    // Send the chunk and clear the list
                    // values.setKeys(null); // Now we need to send keys too.
                    sendNewRegisterInterestResponseChunk(region, keyList, values, false, servConn);
                    values.clear();
                }
            }
        }
    }
    // Send the last chunk (the only chunk for individual and list keys)
    // always send it back, even if the list is of zero size.
    sendNewRegisterInterestResponseChunk(region, keyList, values, true, servConn);
}
Also used : VersionTagHolder(org.apache.geode.internal.cache.VersionTagHolder) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VersionTag(org.apache.geode.internal.cache.versions.VersionTag)

Example 5 with VersionTagHolder

use of org.apache.geode.internal.cache.VersionTagHolder in project geode by apache.

the class BaseCommand method handleKVSingleton.

/**
   * Handles both RR and PR cases
   */
@SuppressWarnings(value = "NP_NULL_PARAM_DEREF", justification = "Null value handled in sendNewRegisterInterestResponseChunk()")
private static void handleKVSingleton(LocalRegion region, Object entryKey, boolean serializeValues, ServerConnection servConn) throws IOException {
    VersionedObjectList values = new VersionedObjectList(MAXIMUM_CHUNK_SIZE, true, region == null || region.getAttributes().getConcurrencyChecksEnabled(), serializeValues);
    if (region != null) {
        if (region.containsKey(entryKey) || region.containsTombstone(entryKey)) {
            VersionTagHolder versionHolder = createVersionTagHolder();
            ClientProxyMembershipID id = servConn == null ? null : servConn.getProxyID();
            // From Get70.getValueAndIsObject()
            Object data = region.get(entryKey, null, true, true, true, id, versionHolder, true);
            VersionTag vt = versionHolder.getVersionTag();
            updateValues(values, entryKey, data, vt);
        }
    }
    // Send the last chunk (the only chunk for individual and list keys)
    // always send it back, even if the list is of zero size.
    sendNewRegisterInterestResponseChunk(region, entryKey, values, true, servConn);
}
Also used : VersionTagHolder(org.apache.geode.internal.cache.VersionTagHolder) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) SuppressWarnings(edu.umd.cs.findbugs.annotations.SuppressWarnings)

Aggregations

VersionTagHolder (org.apache.geode.internal.cache.VersionTagHolder)9 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)6 ClientProxyMembershipID (org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID)3 CachedDeserializable (org.apache.geode.internal.cache.CachedDeserializable)2 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2 SuppressWarnings (edu.umd.cs.findbugs.annotations.SuppressWarnings)1 Pattern (java.util.regex.Pattern)1 InternalGemFireError (org.apache.geode.InternalGemFireError)1 CacheException (org.apache.geode.cache.CacheException)1 RegionFactory (org.apache.geode.cache.RegionFactory)1 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)1 RawValue (org.apache.geode.internal.cache.BucketRegion.RawValue)1 DataLocationException (org.apache.geode.internal.cache.DataLocationException)1 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)1 KeyInfo (org.apache.geode.internal.cache.KeyInfo)1 PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)1 PrimaryBucketException (org.apache.geode.internal.cache.PrimaryBucketException)1 TXStateProxy (org.apache.geode.internal.cache.TXStateProxy)1 VMVersionTag (org.apache.geode.internal.cache.versions.VMVersionTag)1 Retained (org.apache.geode.internal.offheap.annotations.Retained)1