Search in sources :

Example 6 with IndexMaintenanceException

use of org.apache.geode.cache.query.IndexMaintenanceException in project geode by apache.

the class LocalRegion method txApplyPutPart2.

void txApplyPutPart2(RegionEntry regionEntry, Object key, long lastModified, boolean isCreate, boolean didDestroy, boolean clearConflict) {
    if (this.testCallable != null) {
        Operation op = isCreate ? Operation.CREATE : Operation.UPDATE;
        this.testCallable.call(this, op, regionEntry);
    }
    if (isCreate) {
        updateStatsForCreate();
    }
    if (!isProxy() && !clearConflict) {
        if (this.indexManager != null) {
            try {
                this.indexManager.updateIndexes(regionEntry, isCreate ? IndexManager.ADD_ENTRY : IndexManager.UPDATE_ENTRY, isCreate ? IndexProtocol.OTHER_OP : IndexProtocol.AFTER_UPDATE_OP);
            } catch (QueryException e) {
                throw new IndexMaintenanceException(e);
            }
        }
    }
    if (didDestroy) {
        if (this.entryUserAttributes != null) {
            this.entryUserAttributes.remove(key);
        }
    }
    if (this.statisticsEnabled && !clearConflict) {
        addExpiryTaskIfAbsent(regionEntry);
    }
    setLastModifiedTime(lastModified);
}
Also used : QueryException(org.apache.geode.cache.query.QueryException) Operation(org.apache.geode.cache.Operation) IndexMaintenanceException(org.apache.geode.cache.query.IndexMaintenanceException)

Example 7 with IndexMaintenanceException

use of org.apache.geode.cache.query.IndexMaintenanceException in project geode by apache.

the class LocalRegion method recursiveDestroyRegion.

/**
   * Removes entries and recursively destroys subregions.
   *
   * @param eventSet collects the events for all destroyed regions if null, then we're closing so
   *        don't send events to callbacks or destroy the disk region
   */
private void recursiveDestroyRegion(Set eventSet, RegionEventImpl regionEvent, boolean cacheWrite) throws CacheWriterException, TimeoutException {
    final boolean isClose = regionEvent.getOperation().isClose();
    // do the cacheWriter beforeRegionDestroy first to fix bug 47736
    if (eventSet != null && cacheWrite) {
        try {
            cacheWriteBeforeRegionDestroy(regionEvent);
        } catch (CancelException e) {
            // I don't think this should ever happens: bulletproofing for bug 39454
            if (!this.cache.forcedDisconnect()) {
                logger.warn(LocalizedMessage.create(LocalizedStrings.LocalRegion_RECURSIVEDESTROYREGION_PROBLEM_IN_CACHEWRITEBEFOREREGIONDESTROY), e);
            }
        }
    }
    if (this.eventTracker != null) {
        this.eventTracker.stop();
    }
    if (logger.isTraceEnabled(LogMarker.RVV) && getVersionVector() != null) {
        logger.trace(LogMarker.RVV, "version vector for {} is {}", getName(), getVersionVector().fullToString());
    }
    cancelTTLExpiryTask();
    cancelIdleExpiryTask();
    cancelAllEntryExpiryTasks();
    if (!isInternalRegion()) {
        getCachePerfStats().incRegions(-1);
    }
    this.cache.getInternalResourceManager(false).removeResourceListener(this);
    if (getMembershipAttributes().hasRequiredRoles()) {
        if (!isInternalRegion()) {
            getCachePerfStats().incReliableRegions(-1);
        }
    }
    // then the add only needs to be done if hasListener || hasAdminListener
    if (eventSet != null) {
        eventSet.add(regionEvent);
    }
    try {
        // call recursiveDestroyRegion on each subregion and remove it
        // from this subregion map
        Collection values = this.subregions.values();
        for (Iterator itr = values.iterator(); itr.hasNext(); ) {
            // element is a LocalRegion
            Object element = itr.next();
            LocalRegion region;
            try {
                LocalRegion.setThreadInitLevelRequirement(LocalRegion.BEFORE_INITIAL_IMAGE);
                try {
                    // converts to a LocalRegion
                    region = toRegion(element);
                } finally {
                    LocalRegion.setThreadInitLevelRequirement(LocalRegion.AFTER_INITIAL_IMAGE);
                }
            } catch (CancelException ignore) {
                // ignore, keep going through the motions though
                region = (LocalRegion) element;
            } catch (RegionDestroyedException ignore) {
                // SharedRegionData was destroyed
                continue;
            }
            // failed initialization removing it from the parent subregion map
            if (region.isDestroyed) {
                continue;
            }
            // BEGIN operating on subregion of this region (rgn)
            if (eventSet != null) {
                regionEvent = (RegionEventImpl) regionEvent.clone();
                regionEvent.region = region;
            }
            try {
                region.recursiveDestroyRegion(eventSet, regionEvent, cacheWrite);
                if (!region.isInternalRegion()) {
                    InternalDistributedSystem system = region.cache.getInternalDistributedSystem();
                    system.handleResourceEvent(ResourceEvent.REGION_REMOVE, region);
                }
            } catch (CancelException e) {
                // I don't think this should ever happen: bulletproofing for bug 39454
                if (!this.cache.forcedDisconnect()) {
                    logger.warn(LocalizedMessage.create(LocalizedStrings.LocalRegion_RECURSIVEDESTROYREGION_RECURSION_FAILED_DUE_TO_CACHE_CLOSURE_REGION_0, region.getFullPath()), e);
                }
            }
            // remove from this subregion map;
            itr.remove();
        // END operating on subregion of this region
        }
        try {
            if (this.indexManager != null) {
                try {
                    if (this instanceof BucketRegion) {
                        this.indexManager.removeBucketIndexes(getPartitionedRegion());
                    }
                    this.indexManager.destroy();
                } catch (QueryException e) {
                    throw new IndexMaintenanceException(e);
                }
            }
        } catch (CancelException e) {
            // I don't think this should ever happens: bulletproofing for bug 39454
            if (!this.cache.forcedDisconnect()) {
                logger.warn(LocalizedMessage.create(LocalizedStrings.LocalRegion_BASICDESTROYREGION_INDEX_REMOVAL_FAILED_DUE_TO_CACHE_CLOSURE_REGION_0, getFullPath()), e);
            }
        }
    } finally {
        // mark this region as destroyed.
        if (regionEvent.isReinitializing()) {
            this.reinitialized_old = true;
        }
        this.cache.setRegionByPath(getFullPath(), null);
        if (this.eventTracker != null) {
            this.eventTracker.stop();
        }
        if (this.diskRegion != null) {
            this.diskRegion.prepareForClose(this);
        }
        this.isDestroyed = true;
        // after isDestroyed is set to true call removeResourceListener to fix bug 49555
        this.cache.getInternalResourceManager(false).removeResourceListener(this);
        closeEntries();
        if (logger.isDebugEnabled()) {
            logger.debug("recursiveDestroyRegion: Region Destroyed: {}", getFullPath());
        }
        // otherwise, the listener will be closed after the destroy event
        try {
            postDestroyRegion(!isClose, regionEvent);
        } catch (CancelException e) {
            logger.warn(LocalizedMessage.create(LocalizedStrings.LocalRegion_RECURSIVEDESTROYREGION_POSTDESTROYREGION_FAILED_DUE_TO_CACHE_CLOSURE_REGION_0, getFullPath()), e);
        }
        // fix for bug #47061
        if (getServerProxy() == null) {
            closeCqs();
        }
        detachPool();
        if (eventSet != null) {
            closeCallbacksExceptListener();
        } else {
            closeAllCallbacks();
        }
        if (this.concurrencyChecksEnabled && this.dataPolicy.withReplication() && !this.cache.isClosed()) {
            this.cache.getTombstoneService().unscheduleTombstones(this);
        }
        if (this.hasOwnStats) {
            this.cachePerfStats.close();
        }
    }
}
Also used : QueryException(org.apache.geode.cache.query.QueryException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) Iterator(java.util.Iterator) Collection(java.util.Collection) StoredObject(org.apache.geode.internal.offheap.StoredObject) CancelException(org.apache.geode.CancelException) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) IndexMaintenanceException(org.apache.geode.cache.query.IndexMaintenanceException)

Example 8 with IndexMaintenanceException

use of org.apache.geode.cache.query.IndexMaintenanceException in project geode by apache.

the class EntryEventImpl method setNewValueInRegion.

@Retained(ENTRY_EVENT_NEW_VALUE)
private void setNewValueInRegion(final LocalRegion owner, final RegionEntry reentry, Object oldValueForDelta) throws RegionClearedException {
    boolean wasTombstone = reentry.isTombstone();
    // not be applied. This is possible if the event originated locally.
    if (this.deltaBytes != null && this.newValue == null) {
        processDeltaBytes(oldValueForDelta);
    }
    if (owner != null) {
        owner.generateAndSetVersionTag(this, reentry);
    } else {
        this.region.generateAndSetVersionTag(this, reentry);
    }
    Object v = this.newValue;
    if (v == null) {
        v = isLocalInvalid() ? Token.LOCAL_INVALID : Token.INVALID;
    } else {
        this.region.regionInvalid = false;
    }
    reentry.setValueResultOfSearch(this.op.isNetSearch());
    // in the primary.
    if (v instanceof org.apache.geode.Delta && region.isUsedForPartitionedRegionBucket()) {
        int vSize;
        Object ov = basicGetOldValue();
        if (ov instanceof CachedDeserializable && !GemFireCacheImpl.DELTAS_RECALCULATE_SIZE) {
            vSize = ((CachedDeserializable) ov).getValueSizeInBytes();
        } else {
            vSize = CachedDeserializableFactory.calcMemSize(v, region.getObjectSizer(), false);
        }
        v = CachedDeserializableFactory.create(v, vSize);
        basicSetNewValue(v);
    }
    Object preparedV = reentry.prepareValueForCache(this.region, v, this, false);
    if (preparedV != v) {
        v = preparedV;
        if (v instanceof StoredObject) {
            if (!((StoredObject) v).isCompressed()) {
                // fix bug 52109
                // If we put it off heap and it is not compressed then remember that value.
                // Otherwise we want to remember the decompressed value in the event.
                basicSetNewValue(v);
            }
        }
    }
    boolean isTombstone = (v == Token.TOMBSTONE);
    boolean success = false;
    boolean calledSetValue = false;
    try {
        setNewValueBucketSize(owner, v);
        if ((this.op.isUpdate() && !reentry.isInvalid()) || this.op.isInvalidate()) {
            IndexManager idxManager = IndexUtils.getIndexManager(this.region, false);
            if (idxManager != null) {
                try {
                    idxManager.updateIndexes(reentry, IndexManager.REMOVE_ENTRY, this.op.isUpdate() ? IndexProtocol.BEFORE_UPDATE_OP : IndexProtocol.OTHER_OP);
                } catch (QueryException e) {
                    throw new IndexMaintenanceException(e);
                }
            }
        }
        calledSetValue = true;
        // already called prepareValueForCache
        reentry.setValueWithTombstoneCheck(v, this);
        success = true;
    } finally {
        if (!success && reentry instanceof OffHeapRegionEntry && v instanceof StoredObject) {
            OffHeapRegionEntryHelper.releaseEntry((OffHeapRegionEntry) reentry, (StoredObject) v);
        }
    }
    if (logger.isTraceEnabled()) {
        if (v instanceof CachedDeserializable) {
            logger.trace("EntryEventImpl.setNewValueInRegion: put CachedDeserializable({},{})", this.getKey(), ((CachedDeserializable) v).getStringForm());
        } else {
            logger.trace("EntryEventImpl.setNewValueInRegion: put({},{})", this.getKey(), StringUtils.forceToString(v));
        }
    }
    if (!isTombstone && wasTombstone) {
        owner.unscheduleTombstone(reentry);
    }
}
Also used : IndexManager(org.apache.geode.cache.query.internal.index.IndexManager) QueryException(org.apache.geode.cache.query.QueryException) StoredObject(org.apache.geode.internal.offheap.StoredObject) StoredObject(org.apache.geode.internal.offheap.StoredObject) IndexMaintenanceException(org.apache.geode.cache.query.IndexMaintenanceException) Retained(org.apache.geode.internal.offheap.annotations.Retained)

Example 9 with IndexMaintenanceException

use of org.apache.geode.cache.query.IndexMaintenanceException in project geode by apache.

the class LocalRegion method basicPutPart2.

protected long basicPutPart2(EntryEventImpl event, RegionEntry entry, boolean isInitialized, long lastModified, boolean clearConflict) {
    final boolean isNewKey = event.getOperation().isCreate();
    // Invoke callbacks only if we are not creating a tombstone
    final boolean invokeCallbacks = event.basicGetNewValue() != Token.TOMBSTONE;
    if (isNewKey) {
        updateStatsForCreate();
    }
    // fix for bug 31102
    final boolean lruRecentUse = event.isNetSearch() || event.isLoad();
    // the event may have a version timestamp that we need to use, so get the
    // event time to store in the entry
    long lastModifiedTime = event.getEventTime(lastModified);
    updateStatsForPut(entry, lastModifiedTime, lruRecentUse);
    if (!isProxy()) {
        if (!clearConflict && this.indexManager != null) {
            try {
                if (!entry.isInvalid()) {
                    this.indexManager.updateIndexes(entry, isNewKey ? IndexManager.ADD_ENTRY : IndexManager.UPDATE_ENTRY, isNewKey ? IndexProtocol.OTHER_OP : IndexProtocol.AFTER_UPDATE_OP);
                }
            } catch (QueryException e) {
                throw new IndexMaintenanceException(e);
            } finally {
                IndexManager.setIndexBufferTime(lastModifiedTime, cacheTimeMillis());
            }
        }
    }
    if (invokeCallbacks) {
        boolean doCallback = false;
        if (isInitialized) {
            // from invokePutCallbacks
            if (event.isGenerateCallbacks()) {
                doCallback = true;
            }
        } else if (this.isUsedForPartitionedRegionBucket) {
            // invokePutCallbacks in BucketRegion will be more discriminating
            doCallback = true;
        }
        if (doCallback) {
            if (event.isBulkOpInProgress() && this.isUsedForPartitionedRegionBucket) {
                if (logger.isDebugEnabled()) {
                    logger.debug("For bulk operation on bucket region, not to notify gateway sender earlier.");
                }
            } else {
                notifyGatewaySender(event.getOperation().isUpdate() ? EnumListenerEvent.AFTER_UPDATE : EnumListenerEvent.AFTER_CREATE, event);
            }
            // Notify listeners
            if (!event.isBulkOpInProgress()) {
                try {
                    entry.dispatchListenerEvents(event);
                } catch (InterruptedException ignore) {
                    Thread.currentThread().interrupt();
                    this.stopper.checkCancelInProgress(null);
                }
            }
        }
    }
    return lastModifiedTime;
}
Also used : QueryException(org.apache.geode.cache.query.QueryException) IndexMaintenanceException(org.apache.geode.cache.query.IndexMaintenanceException)

Aggregations

IndexMaintenanceException (org.apache.geode.cache.query.IndexMaintenanceException)9 QueryException (org.apache.geode.cache.query.QueryException)5 StoredObject (org.apache.geode.internal.offheap.StoredObject)3 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 AttributesFactory (org.apache.geode.cache.AttributesFactory)2 Portfolio (org.apache.geode.cache.query.data.Portfolio)2 IndexManager (org.apache.geode.cache.query.internal.index.IndexManager)2 Retained (org.apache.geode.internal.offheap.annotations.Retained)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 Test (org.junit.Test)2 Collection (java.util.Collection)1 FutureTask (java.util.concurrent.FutureTask)1 CancelException (org.apache.geode.CancelException)1 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)1 Operation (org.apache.geode.cache.Operation)1 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)1 TypeMismatchException (org.apache.geode.cache.query.TypeMismatchException)1 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)1 RegionEntry (org.apache.geode.internal.cache.RegionEntry)1