Search in sources :

Example 1 with PartitionedRegionDataStore

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

the class PartitionedIndex method verifyAndCreateMissingIndex.

/**
   * Verify if the index is available of the buckets. If not create index on the bucket.
   */
public void verifyAndCreateMissingIndex(List buckets) throws QueryInvocationTargetException {
    PartitionedRegion pr = (PartitionedRegion) this.getRegion();
    PartitionedRegionDataStore prds = pr.getDataStore();
    for (Object bId : buckets) {
        // create index
        BucketRegion bukRegion = (BucketRegion) prds.getLocalBucketById((Integer) bId);
        if (bukRegion == null) {
            throw new QueryInvocationTargetException("Bucket not found for the id :" + bId);
        }
        IndexManager im = IndexUtils.getIndexManager(bukRegion, true);
        if (im != null && im.getIndex(indexName) == null) {
            try {
                if (pr.getCache().getLogger().fineEnabled()) {
                    pr.getCache().getLogger().fine("Verifying index presence on bucket region. " + " Found index " + this.indexName + " not present on the bucket region " + bukRegion.getFullPath() + ", index will be created on this region.");
                }
                ExecutionContext externalContext = new ExecutionContext(null, bukRegion.getCache());
                externalContext.setBucketRegion(pr, bukRegion);
                im.createIndex(this.indexName, this.type, this.originalIndexedExpression, this.fromClause, this.imports, externalContext, this, true);
            } catch (IndexExistsException iee) {
            // Index exists.
            } catch (IndexNameConflictException ince) {
            // ignore.
            }
        }
    }
}
Also used : ExecutionContext(org.apache.geode.cache.query.internal.ExecutionContext) IndexExistsException(org.apache.geode.cache.query.IndexExistsException) BucketRegion(org.apache.geode.internal.cache.BucketRegion) IndexNameConflictException(org.apache.geode.cache.query.IndexNameConflictException) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore)

Example 2 with PartitionedRegionDataStore

use of org.apache.geode.internal.cache.PartitionedRegionDataStore 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 3 with PartitionedRegionDataStore

use of org.apache.geode.internal.cache.PartitionedRegionDataStore 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 4 with PartitionedRegionDataStore

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

the class MoveBucketMessage method operateOnPartitionedRegion.

@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion region, long startTime) throws ForceReattemptException {
    PartitionedRegionDataStore dataStore = region.getDataStore();
    boolean moved = dataStore.moveBucket(this.bucketId, this.source, true);
    region.getPrStats().endPartitionMessagesProcessing(startTime);
    MoveBucketReplyMessage.send(getSender(), getProcessorId(), dm, null, moved);
    return false;
}
Also used : PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore)

Example 5 with PartitionedRegionDataStore

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

the class PRUpdateEntryVersionMessage method operateOnPartitionedRegion.

/*
   * (non-Javadoc)
   * 
   * @see org.apache.geode.internal.cache.partitioned.PartitionMessage# operateOnPartitionedRegion
   * (org.apache.geode.distributed.internal.DistributionManager,
   * org.apache.geode.internal.cache.PartitionedRegion, long)
   */
@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion pr, long startTime) throws CacheException, QueryException, DataLocationException, InterruptedException, IOException {
    // release not needed because disallowOffHeapValues called
    final EntryEventImpl event = EntryEventImpl.create(pr, getOperation(), getKey(), null, /* newValue */
    null, /* callbackargs */
    false, /* originRemote - false to force distribution in buckets */
    getSender(), /* eventSender */
    false, /* generateCallbacks */
    false);
    event.disallowOffHeapValues();
    Assert.assertTrue(eventId != null);
    if (this.versionTag != null) {
        event.setVersionTag(this.versionTag);
    }
    event.setEventId(eventId);
    event.setPossibleDuplicate(this.posDup);
    event.setInvokePRCallbacks(false);
    event.setCausedByMessage(this);
    boolean sendReply = true;
    if (!notificationOnly) {
        PartitionedRegionDataStore ds = pr.getDataStore();
        Assert.assertTrue(ds != null, "This process should have storage for an item in " + this.toString());
        try {
            Integer bucket = Integer.valueOf(PartitionedRegionHelper.getHashKey(event));
            pr.getDataView().updateEntryVersion(event);
            if (logger.isTraceEnabled(LogMarker.DM)) {
                logger.debug("{}: updateEntryVersionLocally in bucket: {}, key: {}", getClass().getName(), bucket, key);
            }
        } catch (EntryNotFoundException eee) {
            // failed = true;
            if (logger.isDebugEnabled()) {
                logger.debug("{}: operateOnRegion caught EntryNotFoundException", getClass().getName());
            }
            sendReply(getSender(), getProcessorId(), dm, null, /*
                                                           * No need to send exception back
                                                           */
            pr, startTime);
            // this prevents us from acknowledging later
            sendReply = false;
        } catch (PrimaryBucketException pbe) {
            sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), pr, startTime);
            return false;
        }
    }
    return sendReply;
}
Also used : 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)

Aggregations

PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)30 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)9 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)9 ReplyException (org.apache.geode.distributed.internal.ReplyException)7 BucketRegion (org.apache.geode.internal.cache.BucketRegion)7 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)7 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)6 PrimaryBucketException (org.apache.geode.internal.cache.PrimaryBucketException)6 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)5 Released (org.apache.geode.internal.offheap.annotations.Released)5 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)5 HashSet (java.util.HashSet)4 Set (java.util.Set)4 CacheWriterException (org.apache.geode.cache.CacheWriterException)4 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)4 PartitionMemberInfo (org.apache.geode.cache.partition.PartitionMemberInfo)3 DataLocationException (org.apache.geode.internal.cache.DataLocationException)3 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)3 Test (org.junit.Test)3 Iterator (java.util.Iterator)2