Search in sources :

Example 11 with InternalGemFireError

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

the class DistributedRegion method getInitialImageAndRecovery.

// TODO: cleanup getInitialImageAndRecovery
private void getInitialImageAndRecovery(InputStream snapshotInputStream, InternalDistributedMember imageSrc, InternalRegionArguments internalRegionArgs, boolean recoverFromDisk, PersistentMemberID persistentId) throws TimeoutException {
    logger.info(LocalizedMessage.create(LocalizedStrings.DistributedRegion_INITIALIZING_REGION_0, this.getName()));
    ImageState imgState = getImageState();
    imgState.init();
    boolean targetRecreated = internalRegionArgs.getRecreateFlag();
    Boolean isCBool = (Boolean) isConversion.get();
    boolean isForConversion = isCBool != null ? isCBool : false;
    if (recoverFromDisk && snapshotInputStream != null && !isForConversion) {
        throw new InternalGemFireError(LocalizedStrings.DistributedRegion_IF_LOADING_A_SNAPSHOT_THEN_SHOULD_NOT_BE_RECOVERING_ISRECOVERING_0_SNAPSHOTSTREAM_1.toLocalizedString(new Object[] { true, snapshotInputStream }));
    }
    ProfileExchangeProcessor targetProvider;
    if (this.dataPolicy.withPersistence()) {
        targetProvider = new CreatePersistentRegionProcessor(this, getPersistenceAdvisor(), recoverFromDisk);
    } else {
        // this will go in the advisor profile
        targetProvider = new CreateRegionProcessor(this);
    }
    imgState.setInRecovery(false);
    RegionVersionVector recovered_rvv = null;
    if (this.dataPolicy.withPersistence()) {
        recovered_rvv = this.getVersionVector() == null ? null : this.getVersionVector().getCloneForTransmission();
    }
    // initializeRegion will send out our profile
    targetProvider.initializeRegion();
    if (this.persistenceAdvisor != null) {
        this.persistenceAdvisor.initialize();
    }
    // remote members
    if (!isInternalRegion()) {
        if (!this.isDestroyed) {
            this.cache.getInternalResourceManager().addResourceListener(ResourceType.MEMORY, this);
        }
    }
    releaseBeforeGetInitialImageLatch();
    // allow GII to invoke test hooks. Do this just after releasing the
    // before-gii latch for bug #48962. See ConcurrentLeaveDuringGIIDUnitTest
    InitialImageOperation.beforeGetInitialImage(this);
    if (snapshotInputStream != null) {
        try {
            if (logger.isDebugEnabled()) {
                logger.debug("DistributedRegion.getInitialImageAndRecovery: About to load snapshot, isInitialized={}; {}", isInitialized(), getFullPath());
            }
            loadSnapshotDuringInitialization(snapshotInputStream);
        } catch (IOException e) {
            // TODO: change this exception?
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            // TODO: change this exception?
            throw new RuntimeException(e);
        }
        cleanUpDestroyedTokensAndMarkGIIComplete(GIIStatus.NO_GII);
        return;
    }
    // No snapshot provided, use the imageTarget(s)
    // if we were given a recommended imageTarget, use that first, and
    // treat it like it is a replicate (regardless of whether it actually is
    // or not)
    InitialImageOperation iiop = new InitialImageOperation(this, this.entries);
    CacheDistributionAdvisor.InitialImageAdvice advice = null;
    boolean done = false;
    while (!done && !isDestroyed()) {
        advice = targetProvider.getInitialImageAdvice(advice);
        boolean attemptGetFromOne = // we were given a specific member
        imageSrc != null || // this is a preloaded
        this.dataPolicy.withPreloaded() && !advice.preloaded.isEmpty() || // region
        (!advice.replicates.isEmpty());
        if (attemptGetFromOne) {
            if (recoverFromDisk) {
                if (LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER) {
                    CacheObserverHolder.getInstance().afterMarkingGIIStarted();
                }
            }
            {
                // Plan A: use specified imageSrc, if specified
                if (imageSrc != null) {
                    try {
                        GIIStatus ret = iiop.getFromOne(Collections.singleton(imageSrc), targetRecreated, advice, recoverFromDisk, recovered_rvv);
                        if (GIIStatus.didGII(ret)) {
                            this.giiMissingRequiredRoles = false;
                            cleanUpDestroyedTokensAndMarkGIIComplete(ret);
                            done = true;
                            return;
                        }
                    } finally {
                        imageSrc = null;
                    }
                }
                // Plan C: use a replicate, if one exists
                GIIStatus ret = iiop.getFromOne(advice.replicates, false, advice, recoverFromDisk, recovered_rvv);
                if (GIIStatus.didGII(ret)) {
                    cleanUpDestroyedTokensAndMarkGIIComplete(ret);
                    done = true;
                    return;
                }
                // Plan D: if this is a PRELOADED region, fetch from another PRELOADED
                if (this.dataPolicy.isPreloaded()) {
                    GIIStatus ret_preload = iiop.getFromOne(advice.preloaded, false, advice, recoverFromDisk, recovered_rvv);
                    if (GIIStatus.didGII(ret_preload)) {
                        cleanUpDestroyedTokensAndMarkGIIComplete(ret_preload);
                        done = true;
                        return;
                    }
                }
            // isPreloaded
            }
            // If we got to this point, we failed in the GII. Cleanup
            // any partial image we received
            cleanUpAfterFailedGII(recoverFromDisk);
        } else // attemptGetFromOne
        {
            if (!isDestroyed()) {
                if (recoverFromDisk) {
                    logger.info(LocalizedMessage.create(LocalizedStrings.DistributedRegion_INITIALIZED_FROM_DISK, new Object[] { this.getFullPath(), persistentId, getPersistentID() }));
                    if (persistentId != null) {
                        RegionLogger.logRecovery(this.getFullPath(), persistentId, getDistributionManager().getDistributionManagerId());
                    }
                } else {
                    RegionLogger.logCreate(this.getFullPath(), getDistributionManager().getDistributionManagerId());
                    if (getPersistentID() != null) {
                        RegionLogger.logPersistence(this.getFullPath(), getDistributionManager().getDistributionManagerId(), getPersistentID());
                        logger.info(LocalizedMessage.create(LocalizedStrings.DistributedRegion_NEW_PERSISTENT_REGION_CREATED, new Object[] { this.getFullPath(), getPersistentID() }));
                    }
                }
                cleanUpDestroyedTokensAndMarkGIIComplete(GIIStatus.NO_GII);
                done = true;
                return;
            }
            break;
        }
    }
}
Also used : RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector) IOException(java.io.IOException) GIIStatus(org.apache.geode.internal.cache.InitialImageOperation.GIIStatus) CreatePersistentRegionProcessor(org.apache.geode.internal.cache.persistence.CreatePersistentRegionProcessor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 12 with InternalGemFireError

use of org.apache.geode.InternalGemFireError 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 13 with InternalGemFireError

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

the class FetchEntryMessage method operateOnPartitionedRegion.

@Override
protected boolean operateOnPartitionedRegion(DistributionManager dm, PartitionedRegion r, long startTime) throws ForceReattemptException {
    // FetchEntryMessage is used in refreshing client caches during interest list recovery,
    // so don't be too verbose or hydra tasks may time out
    PartitionedRegionDataStore ds = r.getDataStore();
    EntrySnapshot val;
    if (ds != null) {
        try {
            KeyInfo keyInfo = r.getKeyInfo(key);
            val = (EntrySnapshot) r.getDataView().getEntryOnRemote(keyInfo, r, true);
            r.getPrStats().endPartitionMessagesProcessing(startTime);
            FetchEntryReplyMessage.send(getSender(), getProcessorId(), val, dm, null);
        } catch (TransactionException tex) {
            FetchEntryReplyMessage.send(getSender(), getProcessorId(), null, dm, new ReplyException(tex));
        } catch (PRLocallyDestroyedException pde) {
            FetchEntryReplyMessage.send(getSender(), getProcessorId(), null, dm, new ReplyException(new ForceReattemptException(LocalizedStrings.FetchEntryMessage_ENCOUNTERED_PRLOCALLYDESTROYED.toLocalizedString(), pde)));
        } catch (EntryNotFoundException enfe) {
            FetchEntryReplyMessage.send(getSender(), getProcessorId(), null, dm, new ReplyException(LocalizedStrings.FetchEntryMessage_ENTRY_NOT_FOUND.toLocalizedString(), enfe));
        } catch (PrimaryBucketException pbe) {
            FetchEntryReplyMessage.send(getSender(), getProcessorId(), null, dm, new ReplyException(pbe));
        } catch (ForceReattemptException pbe) {
            pbe.checkKey(key);
            // Slightly odd -- we're marshalling the retry to the peer on another host...
            FetchEntryReplyMessage.send(getSender(), getProcessorId(), null, dm, new ReplyException(pbe));
        } catch (DataLocationException e) {
            FetchEntryReplyMessage.send(getSender(), getProcessorId(), null, dm, new ReplyException(e));
        }
    } else {
        throw new InternalGemFireError(LocalizedStrings.FetchEntryMessage_FETCHENTRYMESSAGE_MESSAGE_SENT_TO_WRONG_MEMBER.toLocalizedString());
    }
    // response
    return false;
}
Also used : TransactionException(org.apache.geode.cache.TransactionException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) DataLocationException(org.apache.geode.internal.cache.DataLocationException) KeyInfo(org.apache.geode.internal.cache.KeyInfo) 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) EntrySnapshot(org.apache.geode.internal.cache.EntrySnapshot) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 14 with InternalGemFireError

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

the class AbstractOp method processAck.

/**
   * Process a response that contains an ack.
   * 
   * @param msg the message containing the response
   * @param opName text describing this op
   * @throws Exception if response could not be processed or we received a response with a server
   *         exception.
   */
protected void processAck(Message msg, String opName) throws Exception {
    final int msgType = msg.getMessageType();
    if (msgType == MessageType.REPLY) {
        return;
    } else {
        Part part = msg.getPart(0);
        if (msgType == MessageType.EXCEPTION) {
            String s = ": While performing a remote " + opName;
            Throwable t = (Throwable) part.getObject();
            if (t instanceof PutAllPartialResultException) {
                throw (PutAllPartialResultException) t;
            } else {
                throw new ServerOperationException(s, t);
            }
        // Get the exception toString part.
        // This was added for c++ thin client and not used in java
        // Part exceptionToStringPart = msg.getPart(1);
        } else if (isErrorResponse(msgType)) {
            throw new ServerOperationException(part.getString());
        } else {
            throw new InternalGemFireError("Unexpected message type " + MessageType.getString(msgType));
        }
    }
}
Also used : Part(org.apache.geode.internal.cache.tier.sockets.Part) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) PutAllPartialResultException(org.apache.geode.internal.cache.PutAllPartialResultException) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 15 with InternalGemFireError

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

the class AbstractOp method processChunkedResponse.

/**
   * Process a chunked response that contains a single Object result.
   * 
   * @param msg the message containing the response
   * @param opName text describing this op
   * @param callback used to handle each chunks data
   * @throws Exception if response could not be processed or we received a response with a server
   *         exception.
   */
protected void processChunkedResponse(ChunkedMessage msg, String opName, ChunkHandler callback) throws Exception {
    msg.readHeader();
    final int msgType = msg.getMessageType();
    if (msgType == MessageType.RESPONSE) {
        do {
            msg.receiveChunk();
            callback.handle(msg);
        } while (!msg.isLastChunk());
    } else {
        if (msgType == MessageType.EXCEPTION) {
            msg.receiveChunk();
            Part part = msg.getPart(0);
            String s = "While performing a remote " + opName;
            throw new ServerOperationException(s, (Throwable) part.getObject());
        // Get the exception toString part.
        // This was added for c++ thin client and not used in java
        // Part exceptionToStringPart = msg.getPart(1);
        } else if (isErrorResponse(msgType)) {
            msg.receiveChunk();
            Part part = msg.getPart(0);
            throw new ServerOperationException(part.getString());
        } else {
            throw new InternalGemFireError("Unexpected message type " + MessageType.getString(msgType));
        }
    }
}
Also used : Part(org.apache.geode.internal.cache.tier.sockets.Part) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) 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