This ensures that the specified ExternalCacheFragment has not
been invalidated.

@param externalCacheFragment The unfiltered ExternalCacheFragment.
@return The filtered ExternalCacheFragment.
761830
public ExternalInvalidation filterExternalCacheFragment(String cacheName, ExternalInvalidation externalCacheFragment) {
		InvalidationTableList invalidationTableList = getInvalidationTableList(cacheName);
		try {
			invalidationTableList.readWriteLock.readLock().lock();
			return internalFilterExternalCacheFragment(cacheName, invalidationTableList, externalCacheFragment);
		} finally {
			invalidationTableList.readWriteLock.readLock().unlock();
		}
	}
1247116
public FragmentResponseMessage processFragmentTask(SiteProcedureConnection siteConnection)
    {
        // Ensure default procs loaded here
        // Also used for LoadMultipartitionTable
        String procNameToLoad = m_fragmentMsg.getProcNameToLoad();
        if (procNameToLoad != null) {
            // this will ensure proc is loaded
            ProcedureRunner runner = siteConnection.getProcedureRunner(procNameToLoad);
            assert(runner != null);
        }

        // IZZY: actually need the "executor" HSId these days?
        final FragmentResponseMessage currentFragResponse =
                new FragmentResponseMessage(m_fragmentMsg, m_initiator.getHSId());
        currentFragResponse.setStatus(FragmentResponseMessage.SUCCESS, null);

        if (m_inputDeps != null) {
            siteConnection.stashWorkUnitDependencies(m_inputDeps);
        }

        if (m_fragmentMsg.isEmptyForRestart()) {
            int outputDepId = m_fragmentMsg.getOutputDepId(0);
            currentFragResponse.addDependency(new DependencyPair.BufferDependencyPair(outputDepId,
                    m_rawDummyResponse, 0, m_rawDummyResponse.length));
            return currentFragResponse;
        }

        ProcedureRunner currRunner = siteConnection.getProcedureRunner(m_fragmentMsg.getProcedureName());
        long[] executionTimes = null;
        int succeededFragmentsCount = 0;
        if (currRunner != null) {
            currRunner.getExecutionEngine().setPerFragmentTimingEnabled(m_fragmentMsg.isPerFragmentStatsRecording());
            if (m_fragmentMsg.isPerFragmentStatsRecording()) {
                // At this point, we will execute the fragments one by one.
                executionTimes = new long[1];
            }
        }

        int drBufferChanged = 0;
        boolean exceptionThrown = false;
        boolean exceptionCaught = false;
        for (int frag = 0; frag < m_fragmentMsg.getFragmentCount(); frag++)
        {
            byte[] planHash = m_fragmentMsg.getPlanHash(frag);
            final int outputDepId = m_fragmentMsg.getOutputDepId(frag);

            ParameterSet params = m_fragmentMsg.getParameterSetForFragment(frag);
            final int inputDepId = m_fragmentMsg.getOnlyInputDepId(frag);

            long fragmentId = 0;
            byte[] fragmentPlan = null;

            /*
             * Currently the error path when executing plan fragments
             * does not adequately distinguish between fatal errors and
             * abort type errors that should result in a roll back.
             * Assume that it is ninja: succeeds or doesn't return.
             * No roll back support.
             *
             * AW in 2012, the preceding comment might be wrong,
             * I am pretty sure what we don't support is partial rollback.
             * The entire procedure will roll back successfully on failure
             */
            VoltTable dependency = null;
            try {
                FastDeserializer fragResult;
                fragmentPlan = m_fragmentMsg.getFragmentPlan(frag);
                String stmtText = null;

                // if custom fragment, load the plan and get local fragment id
                if (fragmentPlan != null) {
                    // statement text for unplanned fragments are pulled from the message,
                    // to ensure that we get the correct constants from the most recent
                    // invocation.
                    stmtText = m_fragmentMsg.getStmtText(frag);
                    fragmentId = ActivePlanRepository.loadOrAddRefPlanFragment(planHash, fragmentPlan, null);
                }
                // otherwise ask the plan source for a local fragment id
                else {
                    fragmentId = ActivePlanRepository.getFragmentIdForPlanHash(planHash);
                    stmtText = ActivePlanRepository.getStmtTextForPlanHash(planHash);
                }

                // set up the batch context for the fragment set
                siteConnection.setBatch(m_fragmentMsg.getCurrentBatchIndex());

                fragResult = siteConnection.executePlanFragments(
                        1,
                        new long[] { fragmentId },
                        new long [] { inputDepId },
                        new ParameterSet[] { params },
                        null,
                        stmtText == null ? null : new String[] { stmtText }, // for long-running queries
                        new boolean[] { false },    // FragmentTasks don't generate statement hashes,
                        null,
                        m_txnState.txnId,
                        m_txnState.m_spHandle,
                        m_txnState.uniqueId,
                        m_txnState.isReadOnly(),
                        VoltTrace.log(VoltTrace.Category.EE) != null);

                if (!exceptionThrown) {
                    // Ignore results for all work done after an exception is thrown. We need to still do
                    // the work because Shared Replicated Table changes require participation by all sites.

                    // get a copy of the result buffers from the cache buffer so we can post the
                    // fragment response to the network
                    final int tableSize;
                    final byte fullBacking[];
                    try {
                        // read the size of the DR buffer used
                        drBufferChanged = fragResult.readInt();
                        // read the complete size of the buffer used
                        fragResult.readInt();
                        // read number of dependencies (1)
                        fragResult.readInt();
                        // read the dependencyId() -1;
                        fragResult.readInt();
                        tableSize = fragResult.readInt();
                        fullBacking = new byte[tableSize];
                        // get a copy of the buffer
                        fragResult.readFully(fullBacking);
                    } catch (final IOException ex) {
                        hostLog.error("Failed to deserialze result table" + ex);
                        throw new EEException(ExecutionEngine.ERRORCODE_WRONG_SERIALIZED_BYTES);
                    }

                    if (hostLog.isTraceEnabled()) {
                        hostLog.l7dlog(Level.TRACE,
                           LogKeys.org_voltdb_ExecutionSite_SendingDependency.name(),
                           new Object[] { outputDepId }, null);
                    }
                    currentFragResponse.addDependency(new DependencyPair.BufferDependencyPair(outputDepId, fullBacking, 0, tableSize));
                }
            } catch (final EEException | SQLException | ReplicatedTableException | InterruptException e) {
                if (!exceptionThrown) {
                    hostLog.l7dlog( Level.TRACE, LogKeys.host_ExecutionSite_ExceptionExecutingPF.name(), new Object[] { Encoder.hexEncode(planHash) }, e);
                    currentFragResponse.setStatus(FragmentResponseMessage.UNEXPECTED_ERROR, e);
                    if (currentFragResponse.getTableCount() == 0) {
                        // Make sure the response has at least 1 result with a valid DependencyId
                        currentFragResponse.addDependency(new DependencyPair.BufferDependencyPair(outputDepId,
                                m_rawDummyResult, 0, m_rawDummyResult.length));
                    }
                    exceptionThrown = true;
                }
            }
            finally {
                // ensure adhoc plans are unloaded
                if (fragmentPlan != null) {
                    ActivePlanRepository.decrefPlanFragmentById(fragmentId);
                }
                // If the executed fragment comes from a stored procedure, we need to update the per-fragment stats for it.
                // Notice that this code path is used to handle multi-partition stored procedures.
                // The single-partition stored procedure handler is in the ProcedureRunner.
                if (currRunner != null && !exceptionCaught) {
                    succeededFragmentsCount = currRunner.getExecutionEngine().extractPerFragmentStats(1, executionTimes);

                    long stmtDuration = 0;
                    int stmtResultSize = 0;
                    int stmtParameterSetSize = 0;
                    if (m_fragmentMsg.isPerFragmentStatsRecording()) {
                        stmtDuration = executionTimes == null ? 0 : executionTimes[0];
                        stmtResultSize = dependency == null ? 0 : dependency.getSerializedSize();
                        stmtParameterSetSize = params == null ? 0 : params.getSerializedSize();
                    }

                    currRunner.getStatsCollector().endFragment(m_fragmentMsg.getStmtName(frag),
                                                               m_fragmentMsg.isCoordinatorTask(),
                                                               succeededFragmentsCount == 0,
                                                               m_fragmentMsg.isPerFragmentStatsRecording(),
                                                               stmtDuration,
                                                               stmtResultSize,
                                                               stmtParameterSetSize);
                    if (exceptionThrown) {
                        // skip the stats work for all fragments after the fragment that threw an exception
                        exceptionCaught = true;
                    }
                }
            }
        }
        // for multi fragments task, using the aggregated dr Buffer size
        currentFragResponse.setDrBufferSize(drBufferChanged);
        return currentFragResponse;
    }
195540
public Filter getFilter()
        throws CacheReloadException
    {
        final IWhere where = eqlStmt.getQuery().getWhere();
        final IOrder order = eqlStmt.getOrder();
        return Filter.get(where, order, getTypes().toArray(new Type[getTypes().size()]));
    }
1273882
@Override
	public void cacheResult(
		List<CommerceNotificationTemplateUserSegmentRel> commerceNotificationTemplateUserSegmentRels) {
		for (CommerceNotificationTemplateUserSegmentRel commerceNotificationTemplateUserSegmentRel : commerceNotificationTemplateUserSegmentRels) {
			if (entityCache.getResult(
						CommerceNotificationTemplateUserSegmentRelModelImpl.ENTITY_CACHE_ENABLED,
						CommerceNotificationTemplateUserSegmentRelImpl.class,
						commerceNotificationTemplateUserSegmentRel.getPrimaryKey()) == null) {
				cacheResult(commerceNotificationTemplateUserSegmentRel);
			}
			else {
				commerceNotificationTemplateUserSegmentRel.resetOriginalValues();
			}
		}
	}
1155616
private static void setCache(CmsObject cms, CmsXmlContainerPage xmlCntPage, boolean keepEncoding) {

        if (xmlCntPage.getFile() instanceof I_CmsHistoryResource) {
            return;
        }
        boolean online = cms.getRequestContext().getCurrentProject().isOnlineProject();
        getCache().setCacheContainerPage(
            getCache().getCacheKey(xmlCntPage.getFile().getStructureId(), keepEncoding),
            xmlCntPage,
            online);
    }
817618
private final CacheEntry internalFilterEntry(String cacheName, InvalidationTableList invalidationTableList, CacheEntry cacheEntry) {
		InvalidateByIdEvent idEvent = null;
		if (cacheEntry == null) {
			if (tc.isDebugEnabled()) {
				Tr.debug(tc, "internalFilterEntry(): Filtered cacheName=" + cacheName + " CE == NULL");
			}
			return null;
		} else if (cacheEntry.id == null) {		
			if (tc.isDebugEnabled()) {
				Tr.debug(tc, "internalFilterEntry(): Filtered cacheName=" + cacheName + " id == NULL");
			}
		    return null;
		}

		long timeStamp = cacheEntry.getTimeStamp();
		idEvent = (InvalidateByIdEvent) invalidationTableList.presentIdSet.get(cacheEntry.id);
		if ((idEvent != null) && (idEvent.getTimeStamp() > timeStamp)) {
			if (tc.isDebugEnabled()) {
				Tr.debug(tc, "internalFilterEntry(): Filtered Found a more recent InvalidateByIdEvent for the cacheEntry in presentIdSet. cacheName=" + cacheName + " id=" + cacheEntry.id);
			}
			return null;
		}
		if (collision(invalidationTableList.presentTemplateSet, cacheEntry.getTemplates(), timeStamp) || collision(invalidationTableList.presentIdSet, cacheEntry.getDataIds(), timeStamp)) {
			if (tc.isDebugEnabled()) {
				Tr.debug(tc, "internalFilterEntry(): Filtered due to preexisting invalidations due to dependencies and templates in present template and IdSet. cacheName=" + cacheName + " id=" + cacheEntry.id);
			}
			return null;
		}
		if (timeStamp > lastTimeCleared) {
			return cacheEntry;
		}
		//else check past values as well
		idEvent = (InvalidateByIdEvent) invalidationTableList.pastIdSet.get(cacheEntry.id);

		if ((idEvent != null) && (idEvent.getTimeStamp() > timeStamp)) {
			if (tc.isDebugEnabled()) {
				Tr.debug(tc, "internalFilterEntry(): Filtered Found a more recent InvalidateByIdEvent for the cacheEntry in pastIdSet. cacheName=" + cacheName + " id=" + cacheEntry.id);
			}
			return null;
		}
		if (collision(invalidationTableList.pastTemplateSet, cacheEntry.getTemplates(), timeStamp) || collision(invalidationTableList.pastIdSet, cacheEntry.getDataIds(), timeStamp)) {
			if (tc.isDebugEnabled()) {
				Tr.debug(tc, "internalFilterEntry(): Filtered due to preexisting invalidations due to dependencies and templates in past template and IdSet. cacheName=" + cacheName + " id=" + cacheEntry.id);
			}
			return null;
		}
		return cacheEntry;
	}
573148
public void setExternalSelectedPart(IAtomContainer externalSelectedPart) {
        this.externalSelectedPart = externalSelectedPart;
        Map<IChemObject, Color> colorHash = getParameter(ColorHash.class).getValue();
        colorHash.clear();
        if (externalSelectedPart != null) {
            for (int i = 0; i < externalSelectedPart.getAtomCount(); i++) {
                colorHash.put(externalSelectedPart.getAtom(i), getParameter(ExternalHighlightColor.class).getValue());
            }
            Iterator<IBond> bonds = externalSelectedPart.bonds().iterator();
            while (bonds.hasNext()) {
                colorHash.put(bonds.next(), getParameter(ExternalHighlightColor.class).getValue());
            }
        }
        fireChange();
    }
381378
public final <R extends Request<T>> R setShouldCache(boolean shouldCache) {
        checkIfActive();
        this.shouldCache = shouldCache;
        return (R) this;
    }
1261166
@Override
	public void clearCache() {
		entityCache.clearCache(CPRuleUserSegmentRelImpl.class);

		finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
		finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
		finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
	}
1097172
public static PutFromLoadValidator removeFromCache(AdvancedCache cache) {
      AsyncInterceptorChain chain = cache.getAsyncInterceptorChain();
      BasicComponentRegistry cr = cache.getComponentRegistry().getComponent(BasicComponentRegistry.class);

		chain.removeInterceptor(TxPutFromLoadInterceptor.class);
		chain.removeInterceptor(NonTxPutFromLoadInterceptor.class);

      chain.getInterceptors().stream()
            .filter(BaseInvalidationInterceptor.class::isInstance).findFirst().map(AsyncInterceptor::getClass)
            .ifPresent(invalidationClass -> {
               InvalidationInterceptor invalidationInterceptor = new InvalidationInterceptor();
               cr.replaceComponent(InvalidationInterceptor.class.getName(), invalidationInterceptor, true);
               cr.getComponent(InvalidationInterceptor.class).running();
               chain.replaceInterceptor(invalidationInterceptor, invalidationClass);
            });

      chain.getInterceptors().stream()
            .filter(LockingInterceptor.class::isInstance).findFirst().map(AsyncInterceptor::getClass)
            .ifPresent(invalidationClass -> {
               NonTransactionalLockingInterceptor lockingInterceptor = new NonTransactionalLockingInterceptor();
               cr.replaceComponent(NonTransactionalLockingInterceptor.class.getName(), lockingInterceptor, true);
               cr.getComponent(NonTransactionalLockingInterceptor.class).running();
               chain.replaceInterceptor(lockingInterceptor, LockingInterceptor.class);
            });

		CacheCommandInitializer cci = cr.getComponent(CacheCommandInitializer.class).running();
		return cci.removePutFromLoadValidator(cache.getName());
	}
1077749
public <Result, Param extends Resource> Result execWithoutCacheClear(Param resource, IUnitOfWork<Result, Param> transaction) throws WrappedException {
		CacheAdapter cacheAdapter = getOrCreate(resource);
		try {
			cacheAdapter.ignoreNotifications();
			return transaction.exec(resource);
		} catch (RuntimeException e) {
			throw e;
		} catch (Exception e) {
			throw new WrappedException(e);
		} finally {
			cacheAdapter.listenToNotifications();
		}
	}
116194
@Override
    public CacheManager.CacheStatus getCacheStatus() {
        int minGen = 0;
        int maxGen = 0;
        long size = 0;
        synchronized (this.segmentCaches) {
            for (SegmentKeyCache e : this.segmentCaches.values()) {
                if (e != null) {
                    val cs = e.getCacheStatus();
                    minGen = Math.min(minGen, cs.getOldestGeneration());
                    maxGen = Math.max(maxGen, cs.getNewestGeneration());
                    size += cs.getSize();
                }
            }
        }

        return new CacheManager.CacheStatus(size, minGen, maxGen);
    }
1296687
public static long getURLLastModified(String externalForm) {
        long lastModified = 0L;
        InputStream is = null;
        try {
            URL url = new URL(externalForm);
            URLConnection connection = url.openConnection();
            lastModified = connection.getLastModified();
            is = connection.getInputStream();
        } catch (MalformedURLException e) {
            Log.e("Incorrect URL", e);
        } catch (IOException e) {
            // This can happen also if file does not exist.
        } finally {
            closeAndIgnoreExceptions(is);
        }
        return lastModified;
    }
717517
public void cacheCleared(DCache cache) {
        final String methodName = "cacheCleared()";
        ExpirationMetaData expirationMetaData = (ExpirationMetaData)cacheInstancesTable.get(cache);
        if (expirationMetaData == null) {
            return;
        }
        synchronized (expirationMetaData) {
            if (!expirationMetaData.expirationTable.isEmpty()) {
                Enumeration e = expirationMetaData.expirationTable.elements();
                while (e.hasMoreElements()) {
                    InvalidationTask it = (InvalidationTask)e.nextElement();
                    it.reset();
                    taskPool.add(it);
                }
                expirationMetaData.expirationTable.clear();
                expirationMetaData.timeLimitHeap.clear();
                if (tc.isDebugEnabled()){
                	Tr.debug(tc, methodName + cache.getCacheName() + " expirationTable=" + expirationMetaData.expirationTable.size());
                }
            }
        }
    }
1047184
CompletedCheckpointStats.DiscardCallback reportCompletedCheckpoint(String externalPointer) {
		CompletedCheckpointStats completed = new CompletedCheckpointStats(
			checkpointId,
			triggerTimestamp,
			props,
			numberOfSubtasks,
			new HashMap<>(taskStats),
			currentNumAcknowledgedSubtasks,
			currentStateSize,
			currentAlignmentBuffered,
			latestAcknowledgedSubtask,
				externalPointer);

		trackerCallback.reportCompletedCheckpoint(completed);

		return completed.getDiscardCallback();
	}
401884
public static AdvancedCache asyncWriteCache(
			AdvancedCache cache,
			Flag extraFlag) {
		return cache.withFlags(
				Flag.SKIP_CACHE_LOAD,
				Flag.SKIP_REMOTE_LOOKUP,
				Flag.FORCE_ASYNCHRONOUS,
				extraFlag
		);
	}
707239
@Override
    public Cache getCache()
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "getCache : " + this);
        throw new UnsupportedOperationException("This operation is not supported on a pooling EntityManagerFactory.");
    }