Class GridCacheProcessor

  • All Implemented Interfaces:
    GridComponent, GridProcessor

    public class GridCacheProcessor
    extends GridProcessorAdapter
    The main responsibility of this processor is orchestrating of starting, stopping caches and everything related to that activity like validation of cache configuration, restoring configuration from persistence, etc.
    • Constructor Detail

      • GridCacheProcessor

        public GridCacheProcessor​(GridKernalContext ctx)
        Parameters:
        ctx - Kernal context.
    • Method Detail

      • exchangeTaskForCustomDiscoveryMessage

        public CachePartitionExchangeWorkerTask exchangeTaskForCustomDiscoveryMessage​(DiscoveryCustomMessage msg)
        Create exchange worker task for custom discovery message.
        Parameters:
        msg - Custom discovery message.
        Returns:
        Task or null if message doesn't require any special processing.
      • cacheGroup

        @Nullable
        public @Nullable CacheGroupContext cacheGroup​(int grpId)
        Parameters:
        grpId - Group ID.
        Returns:
        Cache group.
      • stopCaches

        public void stopCaches​(boolean cancel)
        Parameters:
        cancel - Cancel.
      • blockGateways

        public void blockGateways()
        Blocks all available gateways
      • blockGateways

        public List<GridCacheAdapter> blockGateways​(Collection<Integer> cacheGrpIds)
        Blocks (stops) cache gateway for caches according to given cacheGroupIds.
        Parameters:
        cacheGrpIds - Cache group ids for which cache gateway should be stopped.
        Returns:
        Caches for which cache gateway is blocked (stopped).
      • onKernalStop

        public void onKernalStop​(boolean cancel)
        Callback to notify that kernal is about to stop.
        Specified by:
        onKernalStop in interface GridComponent
        Overrides:
        onKernalStop in class GridProcessorAdapter
        Parameters:
        cancel - Flag indicating whether jobs should be canceled.
      • onKernalStopCaches

        public void onKernalStopCaches​(boolean cancel)
        Parameters:
        cancel - Cancel.
      • cacheNames

        public Collection<String> cacheNames()
        Gets a collection of currently started caches.
        Returns:
        Collection of started cache names.
      • getOrStartPublicCache

        public IgniteCacheProxy<?,​?> getOrStartPublicCache​(boolean start)
                                                          throws IgniteCheckedException
        Gets public cache that can be used for query execution. If cache isn't created on current node it will be started.
        Parameters:
        start - Start cache.
        Returns:
        Cache or null if there is no suitable cache.
        Throws:
        IgniteCheckedException
      • publicCacheNames

        public Collection<String> publicCacheNames()
        Gets a collection of currently started public cache names.
        Returns:
        Collection of currently started public cache names
      • publicAndDsCacheNames

        public Collection<String> publicAndDsCacheNames()
        Gets a collection of currently started public cache names.
        Returns:
        Collection of currently started public cache names
      • cacheMode

        public CacheMode cacheMode​(String cacheName)
        Gets cache mode.
        Parameters:
        cacheName - Cache name to check.
        Returns:
        Cache mode.
      • localJoinCachesContext

        @Nullable
        public @Nullable LocalJoinCachesContext localJoinCachesContext()
        Returns:
        Caches to be started when this node starts.
      • hasCachesReceivedFromJoin

        public boolean hasCachesReceivedFromJoin​(ClusterNode node)
        Parameters:
        node - Joined node.
        Returns:
        True if there are new caches received from joined node.
      • prepareCacheStart

        public void prepareCacheStart​(DynamicCacheDescriptor desc,
                                      @Nullable
                                      @Nullable NearCacheConfiguration reqNearCfg,
                                      AffinityTopologyVersion exchTopVer,
                                      boolean disabledAfterStart,
                                      boolean clientCache)
                               throws IgniteCheckedException
        Parameters:
        desc - Cache descriptor.
        reqNearCfg - Near configuration if specified for client cache start request.
        exchTopVer - Current exchange version.
        disabledAfterStart - If true, then we will discard restarting state from proxies. If false then we will change state of proxies to restarting
        Throws:
        IgniteCheckedException - If failed.
      • shutdownNotFinishedRecoveryCaches

        public void shutdownNotFinishedRecoveryCaches()
        Stops all caches and groups, that was recovered, but not activated on node join. Such caches can remain only if it was filtered by node filter on current node. It's impossible to check whether current node is affinity node for given cache before join to topology.
      • restartProxies

        public void restartProxies()
        Restarts proxies of caches if they was marked as restarting. Requires external synchronization - shouldn't be called concurrently with another caches restart.
      • resetRestartingProxies

        public List<String> resetRestartingProxies()
        Complete stopping of caches if they were marked as restarting but it failed.
        Returns:
        Cache names of proxies which were restarted.
      • blockGateway

        public void blockGateway​(String cacheName,
                                 boolean stop,
                                 boolean restart)
        Parameters:
        cacheName - Cache name.
        stop - True for stop cache, false for close cache.
        restart - Restart flag.
      • prepareCacheStop

        public void prepareCacheStop​(String cacheName,
                                     boolean callDestroy,
                                     boolean clearCache)
        Parameters:
        cacheName - Cache name.
        callDestroy - Cache destroy flag. This flag is passed to the GridCacheManager.stop(boolean, boolean) method.
        clearCache - Cache data clear flag. Setting to true will remove all cache data.
      • prepareCacheStop

        public void prepareCacheStop​(String cacheName,
                                     boolean callDestroy,
                                     boolean clearCache,
                                     boolean clearDbObjects)
        Parameters:
        cacheName - Cache name.
        callDestroy - Cache destroy flag. This flag is passed to the GridCacheManager.stop(boolean, boolean) method.
        clearCache - Cache data clear flag. Setting to true will remove all cache data.
        clearDbObjects - If false DB objects don't removed (used for cache.close() on client node).
      • onExchangeDone

        public void onExchangeDone​(AffinityTopologyVersion cacheStartVer,
                                   @Nullable
                                   @Nullable ExchangeActions exchActions,
                                   @Nullable
                                   @Nullable Throwable err)
        Callback invoked when first exchange future for dynamic cache is completed.
        Parameters:
        cacheStartVer - Started caches version to create proxy for.
        exchActions - Change requests.
        err - Error.
      • completeCacheStartFuture

        public void completeCacheStartFuture​(DynamicCacheChangeRequest req,
                                             boolean success,
                                             @Nullable
                                             @Nullable Throwable err)
        Parameters:
        req - Request to complete future for.
        success - Future result.
        err - Error if any.
      • onCacheStatisticsModeChange

        public void onCacheStatisticsModeChange​(CacheStatisticsModeChangeMessage msg)
        Cache statistics flag change message received.
        Parameters:
        msg - Message.
      • processStatisticsModeChange

        public void processStatisticsModeChange​(CacheStatisticsModeChangeMessage msg)
        Cache statistics flag change task processed by exchange worker.
        Parameters:
        msg - Message.
      • createFromTemplate

        public IgniteInternalFuture<?> createFromTemplate​(String cacheName)
        Dynamically starts cache using template configuration.
        Parameters:
        cacheName - Cache name.
        Returns:
        Future that will be completed when cache is deployed.
      • getOrCreateFromTemplate

        public IgniteInternalFuture<?> getOrCreateFromTemplate​(String cacheName,
                                                               boolean checkThreadTx)
        Dynamically starts cache using template configuration.
        Parameters:
        cacheName - Cache name.
        checkThreadTx - If true checks that current thread does not have active transactions.
        Returns:
        Future that will be completed when cache is deployed.
      • getOrCreateFromTemplate

        public IgniteInternalFuture<?> getOrCreateFromTemplate​(String cacheName,
                                                               String templateName,
                                                               CacheConfigurationOverride cfgOverride,
                                                               boolean checkThreadTx)
        Dynamically starts cache using template configuration.
        Parameters:
        cacheName - Cache name.
        templateName - Cache template name.
        cfgOverride - Cache config properties to override.
        checkThreadTx - If true checks that current thread does not have active transactions.
        Returns:
        Future that will be completed when cache is deployed.
      • dynamicStartCache

        public IgniteInternalFuture<Boolean> dynamicStartCache​(@Nullable
                                                               @Nullable CacheConfiguration ccfg,
                                                               String cacheName,
                                                               @Nullable
                                                               @Nullable NearCacheConfiguration nearCfg,
                                                               boolean failIfExists,
                                                               boolean failIfNotStarted,
                                                               boolean checkThreadTx)
        Dynamically starts cache.
        Parameters:
        ccfg - Cache configuration.
        cacheName - Cache name.
        nearCfg - Near cache configuration.
        failIfExists - Fail if exists flag.
        failIfNotStarted - If true fails if cache is not started.
        checkThreadTx - If true checks that current thread does not have active transactions.
        Returns:
        Future that will be completed when cache is deployed.
      • dynamicStartCache

        public IgniteInternalFuture<Boolean> dynamicStartCache​(@Nullable
                                                               @Nullable CacheConfiguration ccfg,
                                                               String cacheName,
                                                               @Nullable
                                                               @Nullable NearCacheConfiguration nearCfg,
                                                               CacheType cacheType,
                                                               boolean sql,
                                                               boolean failIfExists,
                                                               boolean failIfNotStarted,
                                                               boolean checkThreadTx)
        Dynamically starts cache.
        Parameters:
        ccfg - Cache configuration.
        cacheName - Cache name.
        nearCfg - Near cache configuration.
        cacheType - Cache type.
        sql - If the cache needs to be created as the result of SQL CREATE TABLE command.
        failIfExists - Fail if exists flag.
        failIfNotStarted - If true fails if cache is not started.
        checkThreadTx - If true checks that current thread does not have active transactions.
        Returns:
        Future that will be completed when cache is deployed.
      • dynamicStartCaches

        public IgniteInternalFuture<Boolean> dynamicStartCaches​(Collection<CacheConfiguration> ccfgList,
                                                                boolean failIfExists,
                                                                boolean checkThreadTx,
                                                                boolean disabledAfterStart)
        Dynamically starts multiple caches.
        Parameters:
        ccfgList - Collection of cache configuration.
        failIfExists - Fail if exists flag.
        checkThreadTx - If true checks that current thread does not have active transactions.
        disabledAfterStart - If true, cache proxies will be only activated after restartProxies().
        Returns:
        Future that will be completed when all caches are deployed.
      • dynamicStartCachesByStoredConf

        public IgniteInternalFuture<Boolean> dynamicStartCachesByStoredConf​(Collection<StoredCacheData> storedCacheDataList,
                                                                            boolean failIfExists,
                                                                            boolean checkThreadTx,
                                                                            boolean disabledAfterStart,
                                                                            IgniteUuid restartId)
        Dynamically starts multiple caches.
        Parameters:
        storedCacheDataList - Collection of stored cache data.
        failIfExists - Fail if exists flag.
        checkThreadTx - If true checks that current thread does not have active transactions.
        disabledAfterStart - If true, cache proxies will be only activated after restartProxies().
        restartId - Restart requester id (it'll allow to start this cache only him).
        Returns:
        Future that will be completed when all caches are deployed.
      • dynamicDestroyCache

        public IgniteInternalFuture<Boolean> dynamicDestroyCache​(String cacheName,
                                                                 boolean sql,
                                                                 boolean checkThreadTx,
                                                                 boolean restart,
                                                                 IgniteUuid restartId)
        Parameters:
        cacheName - Cache name to destroy.
        sql - If the cache needs to be destroyed only if it was created as the result of SQL CREATE TABLE command.
        checkThreadTx - If true checks that current thread does not have active transactions.
        restart - Restart flag.
        restartId - Restart requester id (it'll allow to start this cache only him).
        Returns:
        Future that will be completed when cache is destroyed.
      • dynamicDestroyCaches

        public IgniteInternalFuture<?> dynamicDestroyCaches​(Collection<String> cacheNames,
                                                            boolean checkThreadTx)
        Parameters:
        cacheNames - Collection of cache names to destroy.
        checkThreadTx - If true checks that current thread does not have active transactions.
        Returns:
        Future that will be completed when cache is destroyed.
      • dynamicDestroyCaches

        public IgniteInternalFuture<?> dynamicDestroyCaches​(Collection<String> cacheNames,
                                                            boolean checkThreadTx,
                                                            boolean destroy)
        Parameters:
        cacheNames - Collection of cache names to destroy.
        checkThreadTx - If true checks that current thread does not have active transactions.
        destroy - Cache data destroy flag. Setting to true will cause removing all cache data
        Returns:
        Future that will be completed when cache is destroyed.
      • createStopRequest

        @NotNull
        public @NotNull DynamicCacheChangeRequest createStopRequest​(String cacheName,
                                                                    boolean restart,
                                                                    IgniteUuid restartId,
                                                                    boolean destroy)
        Prepares cache stop request.
        Parameters:
        cacheName - Cache names to destroy.
        restart - Restart flag.
        restartId - Restart requester id (it'll allow to start this cache only him).
        destroy - Cache data destroy flag. Setting to true will cause removing all cache data from store.
        Returns:
        Future that will be completed when cache is destroyed.
      • dynamicChangeCaches

        @NotNull
        public @NotNull IgniteInternalFuture<?> dynamicChangeCaches​(List<DynamicCacheChangeRequest> reqs)
        Starts cache stop request as cache change batch.
        Parameters:
        reqs - cache stop requests.
        Returns:
        compound future.
      • finalizePartitionsCounters

        public IgniteInternalFuture<?> finalizePartitionsCounters()
        Finalizes partitions update counters.
        Returns:
        Future that will be completed when state is changed for all caches.
      • cacheType

        public CacheType cacheType​(String cacheName)
        Parameters:
        cacheName - Cache name.
        Returns:
        Cache type.
      • isEncrypted

        public boolean isEncrypted​(int cacheGrpId)
        Returns:
        True if cache group cacheGrpId is encrypted. False otherwise.
      • onCustomEvent

        public boolean onCustomEvent​(DiscoveryCustomMessage msg,
                                     AffinityTopologyVersion topVer,
                                     ClusterNode node)
        Callback invoked from discovery thread when discovery custom message is received.
        Parameters:
        msg - Customer message.
        topVer - Current topology version.
        node - Node sent message.
        Returns:
        True if minor topology version should be increased.
      • isCacheRestarting

        public boolean isCacheRestarting​(String cacheName)
        Parameters:
        cacheName - Cache to check.
        Returns:
        Cache is under restarting.
      • keepStaticCacheConfiguration

        public boolean keepStaticCacheConfiguration()
        Returns:
        Keep static cache configuration flag. If true, static cache configuration will override configuration persisted on disk.
      • cache

        @Nullable
        public <K,​V> @Nullable IgniteInternalCache<K,​V> cache​(String name)
        Type Parameters:
        K - type of keys.
        V - type of values.
        Parameters:
        name - Cache name.
        Returns:
        Cache instance for given name.
      • completeProxyInitialize

        public void completeProxyInitialize​(String name)
        Parameters:
        name - Cache name.
      • utilityCache

        public <K,​V> IgniteInternalCache<K,​V> utilityCache()
        Gets utility cache.
        Returns:
        Utility cache.
      • publicCache

        public <K,​V> IgniteInternalCache<K,​V> publicCache​(String name)
        Type Parameters:
        K - type of keys.
        V - type of values.
        Parameters:
        name - Cache name.
        Returns:
        Cache instance for given name.
        Throws:
        IllegalArgumentException - If cache not exists.
      • publicJCache

        @Nullable
        public <K,​V> @Nullable IgniteCacheProxy<K,​V> publicJCache​(String cacheName,
                                                                              boolean failIfNotStarted,
                                                                              boolean checkThreadTx)
                                                                       throws IgniteCheckedException
        Parameters:
        cacheName - Cache name.
        failIfNotStarted - If true throws IllegalArgumentException if cache is not started, otherwise returns null in this case.
        checkThreadTx - If true checks that current thread does not have active transactions.
        Returns:
        Cache instance for given name.
        Throws:
        IgniteCheckedException - If failed.
      • cacheConfiguration

        public CacheConfiguration cacheConfiguration​(String name)
        Get configuration for the given cache.
        Parameters:
        name - Cache name.
        Returns:
        Cache configuration.
      • cacheDescriptor

        public DynamicCacheDescriptor cacheDescriptor​(String name)
        Get registered cache descriptor.
        Parameters:
        name - Name.
        Returns:
        Descriptor.
      • cacheGroupDescriptor

        public CacheGroupDescriptor cacheGroupDescriptor​(int grpId)
        Tries to find cache group descriptor either in registered cache groups or in marked for deletion collection if cache group is considered to be stopped.
        Parameters:
        grpId - Group id.
      • cacheDescriptor

        @Nullable
        public @Nullable DynamicCacheDescriptor cacheDescriptor​(int cacheId)
        Parameters:
        cacheId - Cache ID.
        Returns:
        Cache descriptor.
      • jcache

        public <K,​V> IgniteCacheProxy<K,​V> jcache​(String name)
        Parameters:
        name - Cache name.
        Returns:
        Cache instance for given name.
      • jcacheProxy

        @Nullable
        public @Nullable IgniteCacheProxyImpl<?,​?> jcacheProxy​(String name,
                                                                     boolean awaitInit)
        Parameters:
        name - Cache name.
        awaitInit - Await proxy initialization.
        Returns:
        Cache proxy.
      • internalCache

        public <K,​V> GridCacheAdapter<K,​V> internalCache​(String name)
        Type Parameters:
        K - type of keys.
        V - type of values.
        Parameters:
        name - Cache name.
        Returns:
        Cache instance for given name.
      • systemCache

        public boolean systemCache​(String name)
        Parameters:
        name - Cache name.
        Returns:
        True if specified cache is system, false otherwise.
      • onUndeployed

        public void onUndeployed​(ClassLoader ldr)
        Callback invoked by deployment manager for whenever a class loader gets undeployed.
        Parameters:
        ldr - Class loader.
      • transactions

        public IgniteTransactionsEx transactions()
        Returns:
        Transactions interface implementation.
      • enableStatistics

        public void enableStatistics​(Collection<String> cacheNames,
                                     boolean enabled)
                              throws IgniteCheckedException
        Enable/disable statistics globally for the caches
        Parameters:
        cacheNames - Collection of cache names.
        enabled - Statistics enabled flag.
        Throws:
        IgniteCheckedException
      • splitter

        public CacheConfigurationSplitter splitter()
        Returns:
        By default it returns splitter without old format configuration support.
      • stopWarmUp

        public boolean stopWarmUp()
                           throws IgniteCheckedException
        Stop warming up and current running strategy.
        Returns:
        true if stopped by this call.
        Throws:
        IgniteCheckedException - If there is an error when stopping warm-up.