Class GridCacheUtils
- java.lang.Object
-
- org.apache.ignite.internal.processors.cache.GridCacheUtils
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceGridCacheUtils.BackupPostProcessingClosure
-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description protectedGridCacheUtils()Ensure singleton.
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static booleanaffinityNode(ClusterNode node, IgnitePredicate<ClusterNode> filter)static Collection<ClusterNode>affinityNodes(GridCacheContext ctx, AffinityTopologyVersion topVer)Gets DHT affinity nodes.static CacheEntryPredicate[]alwaysFalse0Arr()static Collection<ClusterNode>backups(Collection<ClusterNode> nodes)static booleanbaselineNode(ClusterNode node, DiscoveryDataClusterState discoveryDataClusterState)static IgniteReducer<Boolean,Boolean>boolReducer()static intcacheGroupId(String cacheName, @Nullable String grpName)static intcacheGroupId(CacheConfiguration<?,?> ccfg)static intcacheId(String cacheName)static StringcacheOrGroupName(CacheConfiguration<?,?> ccfg)static <C extends CachePluginConfiguration>
CcachePluginConfiguration(CacheConfiguration cfg, Class<C> cl)static <T extends CachePluginConfiguration>
List<T>cachePluginConfigurations(IgniteConfiguration cfg, Class<T> cls)static booleancheatCache(int id)Deprecated.static voidcheckAttributeMismatch(IgniteLogger log, String cfgName, UUID rmtNodeId, String attrName, String attrMsg, @Nullable Object locVal, @Nullable Object rmtVal, boolean fail)Checks that cache configuration attribute has the same value in local and remote cache configurations.static voidcheckAttributeMismatch(IgniteLogger log, CacheConfiguration locCfg, CacheConfiguration rmtCfg, UUID rmtNodeId, T2<String,String> attr, boolean fail)Checks that local and remove configurations have the same value of given attribute.static voidcheckStore(GridCacheContext<?,?> ctx)Checks that cache store is present.static <T> IgniteReducer<Collection<T>,Collection<T>>collectionsReducer(int size)Gets reducer that aggregates collections.static Map<Integer,int[]>convertInvalidPartitions(Map<Integer,Set<Integer>> partsMap)static @NotNull RuntimeExceptionconvertToCacheException(IgniteCheckedException e)static @Nullable GridCacheUtils.BackupPostProcessingClosurecreateBackupPostProcessingClosure(AffinityTopologyVersion topVer, IgniteLogger log, GridCacheContext cctx, @Nullable KeyCacheObject key, @Nullable IgniteCacheExpiryPolicy expiryPlc, boolean readThrough, boolean skipVals)Creates closure that saves initial value to backup partition.static <K,V>
IgnitePredicate<javax.cache.Cache.Entry<K,V>>[]empty()static CacheEntryPredicate[]empty0()static intencryptedPageSize(int pageSize, EncryptionSpi encSpi)static IgniteClosure<GridCacheEntryEx,KeyCacheObject>entry2Key()static IgniteInClosure<IgniteInternalFuture<?>>errorLogger(IgniteLogger log, Class<? extends Exception>... excl)static longexpireTimeInPast()static @Nullable DataStorageConfigurationextractDataStorage(ClusterNode node, JdkMarshaller marshaller, ClassLoader clsLdr)Extract and unmarshal data storage configuration from given node.static <K,V>
IgniteClosure<Integer,IgnitePredicate<javax.cache.Cache.Entry<K,V>>[]>factory()Entry predicate factory mostly used for deserialization.static @Nullable CacheObjectfailed(boolean err)static @Nullable CacheObjectfailed(boolean err, CacheObject val)static CacheEntryPredicate[]filterArray(@Nullable CacheEntryPredicate filter)Create filter array.static @Nullable DataRegionConfigurationfindDataRegion(DataStorageConfiguration dsCfg, String drName)Finds data region by name.static @Nullable DataRegionConfigurationfindDataRegionConfiguration(@Nullable DataStorageConfiguration dsCfg, @Nullable String name)Finds and returns a data region configuration with the specified name.static @Nullable DataRegionConfigurationfindRemoteDataRegionConfiguration(ClusterNode node, JdkMarshaller marshaller, ClassLoader clsLdr, @Nullable String name)Finds and returns a data region configuration with the specified name that is configured on remote node.static GridCacheContext<?,?>firstPartitioned(GridCacheSharedContext<?,?> sctx, Iterable<Integer> cacheIds)static <K,V>
IgniteClosure<GridCacheEntryInfo,K>info2Key()static voidinitializeConfigDefaults(IgniteLogger log, CacheConfiguration cfg, CacheObjectContext cacheObjCtx)static <K,V>
voidinTx(Ignite ignite, IgniteCache<K,V> cache, TransactionConcurrency concurrency, TransactionIsolation isolation, IgniteInClosureX<IgniteCache<K,V>> clo)Execute closure inside cache transaction.static <K,V>
voidinTx(IgniteInternalCache<K,V> cache, TransactionConcurrency concurrency, TransactionIsolation isolation, IgniteInClosureX<IgniteInternalCache<K,V>> clo)Execute closure inside cache transaction.static <K,V>
voidinvalidate(IgniteCache<K,V> cache, K key)Invalidate entry in cache.static booleanisCacheTemplateName(String cacheName)static booleanisCdcEnabled(IgniteConfiguration cfg)static booleanisDefaultDataRegionPersistent(DataStorageConfiguration cfg)static booleanisInMemoryCluster(Collection<ClusterNode> nodes, JdkMarshaller marshaller, ClassLoader clsLdr)static booleanisLockTimeoutOrCancelled(Throwable t)static booleanisNearEnabled(CacheConfiguration cfg)Checks if near cache is enabled for cache configuration.static booleanisNearEnabled(GridCacheContext ctx)Checks if near cache is enabled for cache context.static booleanisPersistenceEnabled(DataStorageConfiguration cfg)static booleanisPersistenceEnabled(IgniteConfiguration cfg)static booleanisPersistentCache(CacheConfiguration ccfg, DataStorageConfiguration dsCfg)Checks if cache configuration belongs to persistent cache.static booleanisReservedCacheName(String name)static booleanisSystemCache(String cacheName)static booleanisUtilityCache(String cacheName)static <K,V>
IgniteReducer<Map<K,V>,Map<K,V>>mapsReducer(int size)Gets reducer that aggregates maps into one.static byte[]marshal(GridCacheContext ctx, Object obj)static byte[]marshal(GridCacheSharedContext ctx, boolean depEnabled, Object obj)static Stringmask(String cacheName)Mask cache name in case it is null.static Map<UUID,Collection<ClusterNode>>neighbors(Collection<ClusterNode> topSnapshot)Builds neighborhood map for all nodes in snapshot.static Collection<ClusterNode>neighborsForNodes(Map<UUID,Collection<ClusterNode>> neighborhood, Iterable<ClusterNode> nodes)Returns neighbors for allnodes.static Comparator<ClusterNode>nodeComparator(boolean asc)static <T> IgniteReducer<T,Collection<T>>objectsReducer()Gets reducer that aggregates items into collection.static @Nullable ClusterNodeoldest(Collection<ClusterNode> nodes)static <K,V>
CacheConfiguration<K,V>patchCacheConfiguration(CacheConfiguration<K,V> oldCfg, Collection<QueryEntity> entities, String sqlSchema, boolean isSqlEscape, int qryParallelism)Patch cache configuration withSchemaAddQueryEntityOperation.static <K,V>
CacheConfiguration<K,V>patchCacheConfiguration(CacheConfiguration<K,V> oldCfg, SchemaAddQueryEntityOperation op)Patch cache configuration withSchemaAddQueryEntityOperation.static ClusterNodeprimary(Iterable<? extends ClusterNode> nodes)static IgnitePredicate<IgniteTxEntry>reads()static StringreplicationTopicReceive(String cacheName)Get topic to which replication responses are sent.static StringreplicationTopicSend()Get topic to which replication requests are sent.static <S> SretryTopologySafe(Callable<S> c)static ObjectskipValue(Object val, boolean skip)static Collection<CacheStoreSessionListener>startStoreSessionListeners(GridKernalContext ctx, javax.cache.configuration.Factory<CacheStoreSessionListener>[] factories)Creates and starts store session listeners.static voidstopStoreSessionListeners(GridKernalContext ctx, Collection<CacheStoreSessionListener> sesLsnrs)Stops store session listeners.static booleanstoreCacheConfig(GridCacheSharedContext<?,?> cctx, CacheConfiguration<?,?> cacheCfg)Checks whether given cache configuration should be persisted.static longtoExpireTime(long ttl)Convert TTL to expire time.static longtoTtl(javax.cache.expiry.Duration duration)static TransactionConfigurationtransactionConfiguration(@Nullable GridCacheContext sysCacheCtx, IgniteConfiguration cfg)static longttlForLoad(javax.cache.expiry.ExpiryPolicy plc)Get TTL for load operation.static IgniteClosure<IgniteInternalTx,GridCacheVersion>tx2xidVersion()static StringtxDump(@Nullable IgniteInternalTx tx)Alias fortxString(IgniteInternalTx).static booleantxOnPrimary(IgniteInternalTx tx)static GridNearTxLocaltxStartInternal(GridCacheContext ctx, IgniteInternalCache prj, TransactionConcurrency concurrency, TransactionIsolation isolation)static StringtxString(@Nullable IgniteInternalTx tx)static @Nullable Stringunmask(String cacheName)Unmask cache name.static voidunwindEvicts(GridCacheContext ctx)static voidvalidateCacheGroupsAttributesMismatch(IgniteLogger log, CacheConfiguration cfg1, CacheConfiguration cfg2, String attrName, String attrMsg, Object val1, Object val2, boolean fail)static voidvalidateCacheName(String name)static voidvalidateCacheNames(Collection<String> cacheNames)static voidvalidateConfigurationCacheNames(Collection<CacheConfiguration> ccfgs)static voidvalidateKeyConfigiration(String groupName, String cacheName, UUID rmtNodeId, CacheKeyConfiguration[] rmtCacheKeyCfgs, CacheKeyConfiguration[] locCacheKeyCfgs, IgniteLogger log, boolean fail)Validate and compare affinity key configurations.static Map<String,String>validateKeyConfigiration(String groupName, String cacheName, CacheKeyConfiguration[] cacheKeyCfgs, IgniteLogger log, boolean fail)Validate affinity key configurations.static voidvalidateNewCacheName(String name)static <T> Tvalue(@Nullable CacheObject cacheObj, GridCacheContext ctx, boolean cpy)static Map<Class<? extends WarmUpConfiguration>,WarmUpStrategy>warmUpStrategies(GridKernalContext kernalCtx)Getting available warming strategies.static IgnitePredicate<IgniteTxEntry>writes()
-
-
-
Field Detail
-
cheatCacheId
public static final int cheatCacheId
Cheat cache ID for debugging and benchmarking purposes.
-
DFLT_TTL_EXPIRE_BATCH_SIZE
public static final int DFLT_TTL_EXPIRE_BATCH_SIZE
-
UNDEFINED_CACHE_ID
public static final int UNDEFINED_CACHE_ID
- See Also:
- Constant Field Values
-
UTILITY_CACHE_NAME
public static final String UTILITY_CACHE_NAME
System cache name.- See Also:
- Constant Field Values
-
UTILITY_CACHE_GROUP_ID
public static final int UTILITY_CACHE_GROUP_ID
System cache group id.
-
RESERVED_NAMES
public static final String[] RESERVED_NAMES
Reserved cache names
-
CONTINUOUS_QRY_LOG_CATEGORY
public static final String CONTINUOUS_QRY_LOG_CATEGORY
- See Also:
- Constant Field Values
-
CACHE_MSG_LOG_CATEGORY
public static final String CACHE_MSG_LOG_CATEGORY
- See Also:
- Constant Field Values
-
ATOMIC_MSG_LOG_CATEGORY
public static final String ATOMIC_MSG_LOG_CATEGORY
- See Also:
- Constant Field Values
-
TX_MSG_LOG_CATEGORY
public static final String TX_MSG_LOG_CATEGORY
- See Also:
- Constant Field Values
-
TX_MSG_PREPARE_LOG_CATEGORY
public static final String TX_MSG_PREPARE_LOG_CATEGORY
- See Also:
- Constant Field Values
-
TX_MSG_FINISH_LOG_CATEGORY
public static final String TX_MSG_FINISH_LOG_CATEGORY
- See Also:
- Constant Field Values
-
TX_MSG_LOCK_LOG_CATEGORY
public static final String TX_MSG_LOCK_LOG_CATEGORY
- See Also:
- Constant Field Values
-
TX_MSG_RECOVERY_LOG_CATEGORY
public static final String TX_MSG_RECOVERY_LOG_CATEGORY
- See Also:
- Constant Field Values
-
TTL_MINIMUM
public static final long TTL_MINIMUM
TTL: minimum positive value.- See Also:
- Constant Field Values
-
TTL_ETERNAL
public static final long TTL_ETERNAL
TTL: eternal.- See Also:
- Constant Field Values
-
TTL_NOT_CHANGED
public static final long TTL_NOT_CHANGED
TTL: not changed.- See Also:
- Constant Field Values
-
TTL_ZERO
public static final long TTL_ZERO
TTL: zero (immediate expiration).- See Also:
- Constant Field Values
-
EXPIRE_TIME_ETERNAL
public static final long EXPIRE_TIME_ETERNAL
Expire time: eternal.- See Also:
- Constant Field Values
-
EXPIRE_TIME_CALCULATE
public static final long EXPIRE_TIME_CALCULATE
Expire time: must be calculated based on TTL value.- See Also:
- Constant Field Values
-
READ_FILTER
public static final IgnitePredicate<IgniteTxEntry> READ_FILTER
Read filter.
-
READ_FILTER_NEAR
public static final IgnitePredicate<IgniteTxEntry> READ_FILTER_NEAR
Read filter.
-
READ_FILTER_COLOCATED
public static final IgnitePredicate<IgniteTxEntry> READ_FILTER_COLOCATED
Read filter.
-
WRITE_FILTER
public static final IgnitePredicate<IgniteTxEntry> WRITE_FILTER
Write filter.
-
WRITE_FILTER_NEAR
public static final IgnitePredicate<IgniteTxEntry> WRITE_FILTER_NEAR
Write filter.
-
WRITE_FILTER_COLOCATED
public static final IgnitePredicate<IgniteTxEntry> WRITE_FILTER_COLOCATED
Write filter.
-
FILTER_NEAR_CACHE_ENTRY
public static final IgnitePredicate<IgniteTxEntry> FILTER_NEAR_CACHE_ENTRY
Write filter.
-
-
Method Detail
-
cheatCache
@Deprecated public static boolean cheatCache(int id)
Deprecated.Quickly checks if passed in cache ID is a "cheat cache ID" set by -DCHEAT_CACHE=user_cache_name and resolved in static block above. FOR DEBUGGING AND TESTING PURPOSES!- Parameters:
id- Cache ID to check.- Returns:
Trueif this is cheat cache ID.
-
failed
@Nullable public static @Nullable CacheObject failed(boolean err) throws GridCacheFilterFailedException
- Parameters:
err- Iftrue, then throwGridCacheFilterFailedException, otherwise returnvalpassed in.- Returns:
- Always return
null. - Throws:
GridCacheFilterFailedException- Iferrflag istrue.
-
failed
@Nullable public static @Nullable CacheObject failed(boolean err, CacheObject val) throws GridCacheFilterFailedException
- Parameters:
err- Iftrue, then throwGridCacheFilterFailedException, otherwise returnvalpassed in.val- Value for which evaluation happened.- Returns:
- Always return
valpassed in or throw exception. - Throws:
GridCacheFilterFailedException- Iferrflag istrue.
-
filterArray
public static CacheEntryPredicate[] filterArray(@Nullable @Nullable CacheEntryPredicate filter)
Create filter array.- Parameters:
filter- Filter.- Returns:
- Filter array.
-
factory
public static <K,V> IgniteClosure<Integer,IgnitePredicate<javax.cache.Cache.Entry<K,V>>[]> factory()
Entry predicate factory mostly used for deserialization.- Type Parameters:
K- Key type.V- Value type.- Returns:
- Factory instance.
-
checkStore
public static void checkStore(GridCacheContext<?,?> ctx) throws IgniteCheckedException
Checks that cache store is present.- Parameters:
ctx- Registry.- Throws:
IgniteCheckedException- If cache store is not present.
-
affinityNodes
public static Collection<ClusterNode> affinityNodes(GridCacheContext ctx, AffinityTopologyVersion topVer)
Gets DHT affinity nodes.- Parameters:
ctx- Cache context.topVer- Topology version.- Returns:
- Cache affinity nodes for given topology version.
-
isNearEnabled
public static boolean isNearEnabled(GridCacheContext ctx)
Checks if near cache is enabled for cache context.- Parameters:
ctx- Cache context to check.- Returns:
Trueif near cache is enabled,falseotherwise.
-
isNearEnabled
public static boolean isNearEnabled(CacheConfiguration cfg)
Checks if near cache is enabled for cache configuration.- Parameters:
cfg- Cache configuration to check.- Returns:
Trueif near cache is enabled,falseotherwise.
-
oldest
@Nullable public static @Nullable ClusterNode oldest(Collection<ClusterNode> nodes)
- Parameters:
nodes- Nodes.- Returns:
- Oldest node for the given topology version.
-
empty
public static <K,V> IgnitePredicate<javax.cache.Cache.Entry<K,V>>[] empty()
- Returns:
- Empty filter.
-
empty0
public static CacheEntryPredicate[] empty0()
- Returns:
- Empty filter.
-
alwaysFalse0Arr
public static CacheEntryPredicate[] alwaysFalse0Arr()
- Returns:
- Always false filter.
-
tx2xidVersion
public static IgniteClosure<IgniteInternalTx,GridCacheVersion> tx2xidVersion()
- Returns:
- Closure which converts transaction entry xid to XID version.
-
entry2Key
public static IgniteClosure<GridCacheEntryEx,KeyCacheObject> entry2Key()
- Returns:
- Closure that converts entry to key.
-
info2Key
public static <K,V> IgniteClosure<GridCacheEntryInfo,K> info2Key()
- Returns:
- Closure that converts entry info to key.
-
reads
public static IgnitePredicate<IgniteTxEntry> reads()
- Returns:
- Filter for transaction reads.
-
writes
public static IgnitePredicate<IgniteTxEntry> writes()
- Returns:
- Filter for transaction writes.
-
boolReducer
public static IgniteReducer<Boolean,Boolean> boolReducer()
- Returns:
- Boolean reducer.
-
mapsReducer
public static <K,V> IgniteReducer<Map<K,V>,Map<K,V>> mapsReducer(int size)
Gets reducer that aggregates maps into one.- Type Parameters:
K- Key type.V- Value type.- Parameters:
size- Predicted size of the resulting map to avoid resizings.- Returns:
- Reducer.
-
collectionsReducer
public static <T> IgniteReducer<Collection<T>,Collection<T>> collectionsReducer(int size)
Gets reducer that aggregates collections.- Type Parameters:
T- Collection element type.- Returns:
- Reducer.
-
objectsReducer
public static <T> IgniteReducer<T,Collection<T>> objectsReducer()
Gets reducer that aggregates items into collection.- Type Parameters:
T- Items type.- Returns:
- Reducer.
-
primary
public static ClusterNode primary(Iterable<? extends ClusterNode> nodes)
- Parameters:
nodes- Set of nodes.- Returns:
- Primary node.
-
backups
public static Collection<ClusterNode> backups(Collection<ClusterNode> nodes)
- Parameters:
nodes- Nodes.- Returns:
- Backup nodes.
-
errorLogger
public static IgniteInClosure<IgniteInternalFuture<?>> errorLogger(IgniteLogger log, Class<? extends Exception>... excl)
- Parameters:
log- Logger.excl- Excludes.- Returns:
- Future listener that logs errors.
-
isLockTimeoutOrCancelled
public static boolean isLockTimeoutOrCancelled(Throwable t)
- Parameters:
t- Exception to check.- Returns:
trueif caused by lock timeout or cancellation.
-
marshal
public static byte[] marshal(GridCacheContext ctx, Object obj) throws IgniteCheckedException
- Parameters:
ctx- Cache context.obj- Object to marshal.- Returns:
- Buffer that contains obtained byte array.
- Throws:
IgniteCheckedException- If marshalling failed.
-
marshal
public static byte[] marshal(GridCacheSharedContext ctx, boolean depEnabled, Object obj) throws IgniteCheckedException
- Parameters:
ctx- Cache context.depEnabled- deployment enabled flag.obj- Object to marshal.- Returns:
- Buffer that contains obtained byte array.
- Throws:
IgniteCheckedException- If marshalling failed.
-
skipValue
public static Object skipValue(Object val, boolean skip)
- Parameters:
val- Value.skip- Skip value flag.- Returns:
- Value.
-
txStartInternal
public static GridNearTxLocal txStartInternal(GridCacheContext ctx, IgniteInternalCache prj, TransactionConcurrency concurrency, TransactionIsolation isolation)
- Parameters:
ctx- Context.prj- Projection.concurrency- Concurrency.isolation- Isolation.- Returns:
- New transaction.
-
txOnPrimary
public static boolean txOnPrimary(IgniteInternalTx tx)
- Parameters:
tx- Transaction.- Returns:
Trueif transaction is on primary node.
-
txDump
public static String txDump(@Nullable @Nullable IgniteInternalTx tx)
Alias fortxString(IgniteInternalTx).
-
txString
public static String txString(@Nullable @Nullable IgniteInternalTx tx)
- Parameters:
tx- Transaction.- Returns:
- String view of all safe-to-print transaction properties.
-
unwindEvicts
public static void unwindEvicts(GridCacheContext ctx)
- Parameters:
ctx- Cache context.
-
nodeComparator
public static Comparator<ClusterNode> nodeComparator(boolean asc)
- Parameters:
asc-Truefor ascending.- Returns:
- Descending order comparator.
-
mask
public static String mask(String cacheName)
Mask cache name in case it is null.- Parameters:
cacheName- Cache name.- Returns:
- The same cache name or
<default>in case the name isnull.
-
unmask
@Nullable public static @Nullable String unmask(String cacheName)
Unmask cache name.- Parameters:
cacheName- Cache name.- Returns:
- Unmasked cache name, i.e. in case provided parameter was
<default>thennullwill be returned.
-
replicationTopicSend
public static String replicationTopicSend()
Get topic to which replication requests are sent.- Returns:
- Topic to which replication requests are sent.
-
replicationTopicReceive
public static String replicationTopicReceive(String cacheName)
Get topic to which replication responses are sent.- Parameters:
cacheName- Cache name.- Returns:
- Topic to which replication responses are sent.
-
checkAttributeMismatch
public static void checkAttributeMismatch(IgniteLogger log, CacheConfiguration locCfg, CacheConfiguration rmtCfg, UUID rmtNodeId, T2<String,String> attr, boolean fail) throws IgniteCheckedException
Checks that local and remove configurations have the same value of given attribute.- Parameters:
log- Logger used to log warning message (used only if fail flag is not set).locCfg- Local configuration.rmtCfg- Remote configuration.rmtNodeId- Remote node.attr- Attribute name.fail- If true throws IgniteCheckedException in case of attribute values mismatch, otherwise logs warning.- Throws:
IgniteCheckedException- If attribute values are different and fail flag is true.
-
checkAttributeMismatch
public static void checkAttributeMismatch(IgniteLogger log, String cfgName, UUID rmtNodeId, String attrName, String attrMsg, @Nullable @Nullable Object locVal, @Nullable @Nullable Object rmtVal, boolean fail) throws IgniteCheckedException
Checks that cache configuration attribute has the same value in local and remote cache configurations.- Parameters:
log- Logger used to log warning message (used only if fail flag is not set).cfgName- Remote cache name.rmtNodeId- Remote node.attrName- Short attribute name for error message.attrMsg- Full attribute name for error message.locVal- Local value.rmtVal- Remote value.fail- If true throws IgniteCheckedException in case of attribute values mismatch, otherwise logs warning.- Throws:
IgniteCheckedException- If attribute values are different and fail flag is true.
-
validateCacheGroupsAttributesMismatch
public static void validateCacheGroupsAttributesMismatch(IgniteLogger log, CacheConfiguration cfg1, CacheConfiguration cfg2, String attrName, String attrMsg, Object val1, Object val2, boolean fail) throws IgniteCheckedException
- Parameters:
cfg1- Existing configuration.cfg2- Cache configuration to start.attrName- Short attribute name for error message.attrMsg- Full attribute name for error message.val1- Attribute value in existing configuration.val2- Attribute value in starting configuration.fail- If true throws IgniteCheckedException in case of attribute values mismatch, otherwise logs warning.- Throws:
IgniteCheckedException- If validation failed.
-
isUtilityCache
public static boolean isUtilityCache(String cacheName)
- Parameters:
cacheName- Cache name.- Returns:
Trueif this is utility system cache.
-
isSystemCache
public static boolean isSystemCache(String cacheName)
- Parameters:
cacheName- Cache name.- Returns:
Trueif system cache.
-
cacheId
public static int cacheId(String cacheName)
- Parameters:
cacheName- Cache name.- Returns:
- Cache ID.
-
cacheGroupId
public static int cacheGroupId(String cacheName, @Nullable @Nullable String grpName)
- Parameters:
cacheName- Cache name.grpName- Group name.- Returns:
- Group ID.
-
cacheGroupId
public static int cacheGroupId(CacheConfiguration<?,?> ccfg)
- Parameters:
ccfg- Cache configuration.- Returns:
- Group ID.
-
cacheOrGroupName
public static String cacheOrGroupName(CacheConfiguration<?,?> ccfg)
- Parameters:
ccfg- Cache configuration.- Returns:
- Group name if it is specified, otherwise cache name.
-
toExpireTime
public static long toExpireTime(long ttl)
Convert TTL to expire time.- Parameters:
ttl- TTL.- Returns:
- Expire time.
-
inTx
public static <K,V> void inTx(IgniteInternalCache<K,V> cache, TransactionConcurrency concurrency, TransactionIsolation isolation, IgniteInClosureX<IgniteInternalCache<K,V>> clo) throws IgniteCheckedException
Execute closure inside cache transaction.- Parameters:
cache- Cache.concurrency- Concurrency.isolation- Isolation.clo- Closure.- Throws:
IgniteCheckedException- If failed.
-
inTx
public static <K,V> void inTx(Ignite ignite, IgniteCache<K,V> cache, TransactionConcurrency concurrency, TransactionIsolation isolation, IgniteInClosureX<IgniteCache<K,V>> clo) throws IgniteCheckedException
Execute closure inside cache transaction.- Parameters:
cache- Cache.concurrency- Concurrency.isolation- Isolation.clo- Closure.- Throws:
IgniteCheckedException- If failed.
-
invalidate
public static <K,V> void invalidate(IgniteCache<K,V> cache, K key)
Invalidate entry in cache.- Parameters:
cache- Cache.key- Key.
-
toTtl
public static long toTtl(javax.cache.expiry.Duration duration)
- Parameters:
duration- Duration.- Returns:
- TTL.
-
ttlForLoad
public static long ttlForLoad(javax.cache.expiry.ExpiryPolicy plc)
Get TTL for load operation.- Parameters:
plc- Expiry policy.- Returns:
- TTL for load operation or
TTL_ZEROin case of immediate expiration.
-
expireTimeInPast
public static long expireTimeInPast()
- Returns:
- Expire time denoting a point in the past.
-
convertToCacheException
@NotNull public static @NotNull RuntimeException convertToCacheException(IgniteCheckedException e)
- Parameters:
e- Ignite checked exception.- Returns:
- CacheException runtime exception, never null.
-
value
@Nullable public static <T> T value(@Nullable @Nullable CacheObject cacheObj, GridCacheContext ctx, boolean cpy)- Parameters:
cacheObj- Cache object.ctx- Cache context.cpy- Copy flag.- Returns:
- Cache object value.
-
cachePluginConfiguration
public static <C extends CachePluginConfiguration> C cachePluginConfiguration(CacheConfiguration cfg, Class<C> cl)
- Parameters:
cfg- Cache configuration.cl- Type of cache plugin configuration.- Returns:
- Cache plugin configuration by type from cache configuration or
null.
-
cachePluginConfigurations
public static <T extends CachePluginConfiguration> List<T> cachePluginConfigurations(IgniteConfiguration cfg, Class<T> cls)
- Parameters:
cfg- Config.cls- Class.- Returns:
- Not
nulllist.
-
affinityNode
public static boolean affinityNode(ClusterNode node, IgnitePredicate<ClusterNode> filter)
- Parameters:
node- Node.filter- Node filter.- Returns:
Trueif node is not client node and pass given filter.
-
baselineNode
public static boolean baselineNode(ClusterNode node, DiscoveryDataClusterState discoveryDataClusterState)
- Parameters:
node- Node.discoveryDataClusterState- Discovery data cluster state.- Returns:
Trueif node is included in BaselineTopology.
-
startStoreSessionListeners
public static Collection<CacheStoreSessionListener> startStoreSessionListeners(GridKernalContext ctx, javax.cache.configuration.Factory<CacheStoreSessionListener>[] factories) throws IgniteCheckedException
Creates and starts store session listeners.- Parameters:
ctx- Kernal context.factories- Factories.- Returns:
- Listeners.
- Throws:
IgniteCheckedException- In case of error.
-
convertInvalidPartitions
public static Map<Integer,int[]> convertInvalidPartitions(Map<Integer,Set<Integer>> partsMap)
- Parameters:
partsMap- Cache ID to partition IDs collection map.- Returns:
- Cache ID to partition ID array map.
-
stopStoreSessionListeners
public static void stopStoreSessionListeners(GridKernalContext ctx, Collection<CacheStoreSessionListener> sesLsnrs) throws IgniteCheckedException
Stops store session listeners.- Parameters:
ctx- Kernal context.sesLsnrs- Session listeners.- Throws:
IgniteCheckedException- In case of error.
-
retryTopologySafe
public static <S> S retryTopologySafe(Callable<S> c) throws IgniteCheckedException
- Parameters:
c- Closure to retry.- Returns:
- Closure result.
- Throws:
IgniteCheckedException- If failed.
-
neighbors
public static Map<UUID,Collection<ClusterNode>> neighbors(Collection<ClusterNode> topSnapshot)
Builds neighborhood map for all nodes in snapshot.- Parameters:
topSnapshot- Topology snapshot.- Returns:
- Neighbors map.
-
neighborsForNodes
public static Collection<ClusterNode> neighborsForNodes(Map<UUID,Collection<ClusterNode>> neighborhood, Iterable<ClusterNode> nodes)
Returns neighbors for allnodes.- Parameters:
neighborhood- Neighborhood cache.nodes- Nodes.- Returns:
- All neighbors for given nodes.
-
transactionConfiguration
public static TransactionConfiguration transactionConfiguration(@Nullable @Nullable GridCacheContext sysCacheCtx, IgniteConfiguration cfg)
- Returns:
- default TX configuration if system cache is used or current grid TX config otherwise.
-
validateCacheName
public static void validateCacheName(String name) throws IllegalArgumentException
- Parameters:
name- Cache name.- Throws:
IllegalArgumentException- In case the name is not valid.
-
validateNewCacheName
public static void validateNewCacheName(String name) throws IllegalArgumentException
- Parameters:
name- Cache name.- Throws:
IllegalArgumentException- In case the name is not valid.
-
validateCacheNames
public static void validateCacheNames(Collection<String> cacheNames) throws IllegalArgumentException
- Parameters:
cacheNames- Cache names to validate.- Throws:
IllegalArgumentException- In case the name is not valid.
-
validateConfigurationCacheNames
public static void validateConfigurationCacheNames(Collection<CacheConfiguration> ccfgs) throws IllegalArgumentException
- Parameters:
ccfgs- Configurations to validate.- Throws:
IllegalArgumentException- In case the name is not valid.
-
isReservedCacheName
public static boolean isReservedCacheName(String name)
- Parameters:
name- Cache name.- Returns:
Trueif it is a reserved cache name.
-
validateKeyConfigiration
public static Map<String,String> validateKeyConfigiration(String groupName, String cacheName, CacheKeyConfiguration[] cacheKeyCfgs, IgniteLogger log, boolean fail) throws IgniteCheckedException
Validate affinity key configurations. All fields are initialized and not empty (typeName and affKeyFieldName is defined). Definition for the type does not repeat.- Parameters:
groupName- Cache group name.cacheName- Cache name.cacheKeyCfgs- keyConfiguration to validate.log- Logger used to log warning message (used only if fail flag is not set).fail- If true throws IgniteCheckedException in case of attribute values mismatch, otherwise logs warning.- Returns:
- Affinity key maps (typeName -> fieldName)
- Throws:
IgniteCheckedException- In case the affinity key configurations is not valid.
-
validateKeyConfigiration
public static void validateKeyConfigiration(String groupName, String cacheName, UUID rmtNodeId, CacheKeyConfiguration[] rmtCacheKeyCfgs, CacheKeyConfiguration[] locCacheKeyCfgs, IgniteLogger log, boolean fail) throws IgniteCheckedException
Validate and compare affinity key configurations.- Parameters:
groupName- Cache group name.cacheName- Cache name.rmtNodeId- Remote node.rmtCacheKeyCfgs- Exist affinity key configurations.locCacheKeyCfgs- New affinity key configurations.log- Logger used to log warning message (used only if fail flag is not set).fail- If true throws IgniteCheckedException in case of attribute values mismatch, otherwise logs warning.- Throws:
IgniteCheckedException- In case the affinity key configurations is not valid.
-
initializeConfigDefaults
public static void initializeConfigDefaults(IgniteLogger log, CacheConfiguration cfg, CacheObjectContext cacheObjCtx) throws IgniteCheckedException
- Parameters:
cfg- Initializes cache configuration with proper defaults.cacheObjCtx- Cache object context.- Throws:
IgniteCheckedException- If configuration is not valid.
-
createBackupPostProcessingClosure
@Nullable public static @Nullable GridCacheUtils.BackupPostProcessingClosure createBackupPostProcessingClosure(AffinityTopologyVersion topVer, IgniteLogger log, GridCacheContext cctx, @Nullable @Nullable KeyCacheObject key, @Nullable @Nullable IgniteCacheExpiryPolicy expiryPlc, boolean readThrough, boolean skipVals)
Creates closure that saves initial value to backup partition.Useful only when store with readThrough is used. In situation when get() on backup node returns successful result, it's expected that localPeek() will be successful as well. But it isn't true when primary node loaded value from local store, in this case backups will remain non-initialized.
To meet that requirement the value requested from primary should be saved on backup during get().- Parameters:
topVer- Topology version.log- Logger.cctx- Cache context.key- Key.expiryPlc- Expiry policy.readThrough- Read through.skipVals- Skip values.
-
isPersistentCache
public static boolean isPersistentCache(CacheConfiguration ccfg, DataStorageConfiguration dsCfg)
Checks if cache configuration belongs to persistent cache.- Parameters:
ccfg- Cache configuration.dsCfg- Data storage config.
-
findDataRegion
@Nullable public static @Nullable DataRegionConfiguration findDataRegion(DataStorageConfiguration dsCfg, String drName)
Finds data region by name.- Parameters:
dsCfg- Data storage configuration.drName- Data region name.- Returns:
- Found data region.
-
isInMemoryCluster
public static boolean isInMemoryCluster(Collection<ClusterNode> nodes, JdkMarshaller marshaller, ClassLoader clsLdr)
- Parameters:
nodes- Nodes to check.marshaller- JdkMarshallerclsLdr- Class loader.- Returns:
trueif cluster has only in-memory nodes.
-
extractDataStorage
@Nullable public static @Nullable DataStorageConfiguration extractDataStorage(ClusterNode node, JdkMarshaller marshaller, ClassLoader clsLdr)
Extract and unmarshal data storage configuration from given node.- Parameters:
node- Source of data storage configuration.- Returns:
- Data storage configuration for given node,
or
nullif this node has not data storage configuration.
-
findDataRegionConfiguration
@Nullable public static @Nullable DataRegionConfiguration findDataRegionConfiguration(@Nullable @Nullable DataStorageConfiguration dsCfg, @Nullable @Nullable String name)
Finds and returns a data region configuration with the specified name.- Parameters:
dsCfg- Data storage configuration.name- Name of data region configuration to find.- Returns:
- Data region configuration with the specified name
or
nullif the given data storage configuration does not contain such data region. If thenameof required data region isnull, the default data region is returned.
-
findRemoteDataRegionConfiguration
@Nullable public static @Nullable DataRegionConfiguration findRemoteDataRegionConfiguration(ClusterNode node, JdkMarshaller marshaller, ClassLoader clsLdr, @Nullable @Nullable String name)
Finds and returns a data region configuration with the specified name that is configured on remote node.- Parameters:
node- Remote node.marshaller- JDK marshaller that is used in order to extract data storage configuration.clsLdr- Classloader that is used in order to extract data storage configuration.name- Name of data region configuration to find.- Returns:
- Data region configuration with the specified name
or
nullif the given data storage configuration does not contain such data region. If thenameof required data region isnull, the default data region is returned.
-
isDefaultDataRegionPersistent
public static boolean isDefaultDataRegionPersistent(DataStorageConfiguration cfg)
- Returns:
trueif persistence is enabled for a default data region,falseif not.
-
isPersistenceEnabled
public static boolean isPersistenceEnabled(IgniteConfiguration cfg)
- Returns:
trueif persistence is enabled for at least one data region,falseif not.
-
isPersistenceEnabled
public static boolean isPersistenceEnabled(DataStorageConfiguration cfg)
- Returns:
trueif persistence is enabled for at least one data region,falseif not.
-
isCdcEnabled
public static boolean isCdcEnabled(IgniteConfiguration cfg)
- Parameters:
cfg- Ignite configuration.- Returns:
trueif CDC enabled.
-
storeCacheConfig
public static boolean storeCacheConfig(GridCacheSharedContext<?,?> cctx, CacheConfiguration<?,?> cacheCfg)
Checks whether given cache configuration should be persisted.- Parameters:
cacheCfg- Cache config.- Returns:
Trueif cache configuration should be persisted,falsein other case.
-
encryptedPageSize
public static int encryptedPageSize(int pageSize, EncryptionSpi encSpi)- Parameters:
pageSize- Page size.encSpi- Encryption spi.- Returns:
- Page size without encryption overhead.
-
firstPartitioned
public static GridCacheContext<?,?> firstPartitioned(GridCacheSharedContext<?,?> sctx, Iterable<Integer> cacheIds)
- Parameters:
sctx- Shared context.cacheIds- Cache ids.- Returns:
- First partitioned cache or
nullin case no partitioned cache ids are in list.
-
isCacheTemplateName
public static boolean isCacheTemplateName(String cacheName)
- Parameters:
cacheName- Name of cache or cache template.- Returns:
trueif cache name ends with asterisk (*), and therefire is a template name.
-
patchCacheConfiguration
public static <K,V> CacheConfiguration<K,V> patchCacheConfiguration(CacheConfiguration<K,V> oldCfg, SchemaAddQueryEntityOperation op)
Patch cache configuration withSchemaAddQueryEntityOperation.- Parameters:
oldCfg- Old cache config.op- Schema add query entity operation.
-
patchCacheConfiguration
public static <K,V> CacheConfiguration<K,V> patchCacheConfiguration(CacheConfiguration<K,V> oldCfg, Collection<QueryEntity> entities, String sqlSchema, boolean isSqlEscape, int qryParallelism)
Patch cache configuration withSchemaAddQueryEntityOperation.- Parameters:
oldCfg- Old cache config.entities- New query entities.sqlSchema- Sql schema name.isSqlEscape- Sql escape flag.qryParallelism- Query parallelism parameter.
-
warmUpStrategies
public static Map<Class<? extends WarmUpConfiguration>,WarmUpStrategy> warmUpStrategies(GridKernalContext kernalCtx)
Getting available warming strategies.- Parameters:
kernalCtx- Kernal context.- Returns:
- Mapping configuration to strategy.
-
-