Class GridNearCacheAdapter<K,V>
- java.lang.Object
-
- org.apache.ignite.internal.processors.cache.GridCacheAdapter<K,V>
-
- org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheAdapter<K,V>
-
- org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter<K,V>
-
- All Implemented Interfaces:
Externalizable,Serializable,Iterable<javax.cache.Cache.Entry<K,V>>,IgniteInternalCache<K,V>
- Direct Known Subclasses:
GridNearAtomicCache,GridNearTransactionalCache
public abstract class GridNearCacheAdapter<K,V> extends GridDistributedCacheAdapter<K,V>
Common logic for near caches (smaller local cache that stores most recently or most frequently accessed data).- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheAdapter
GridDistributedCacheAdapter.GlobalRemoveAllJob<K,V>
-
Nested classes/interfaces inherited from class org.apache.ignite.internal.processors.cache.GridCacheAdapter
GridCacheAdapter.AsyncOp<T>, GridCacheAdapter.AtomicReadRepairEntryProcessor<K,V>, GridCacheAdapter.BulkOperation, GridCacheAdapter.CacheExpiryPolicy, GridCacheAdapter.FutureHolder, GridCacheAdapter.InvokeAllTimeStatClosure<T>, GridCacheAdapter.PeekModes, GridCacheAdapter.TopologyVersionAwareJob, GridCacheAdapter.UpdateGetAllTimeStatClosure<T>, GridCacheAdapter.UpdateGetAndRemoveTimeStatClosure<T>, GridCacheAdapter.UpdateGetTimeStatClosure<T>, GridCacheAdapter.UpdatePutAllConflictTimeStatClosure<T>, GridCacheAdapter.UpdatePutAllTimeStatClosure<T>, GridCacheAdapter.UpdatePutAndGetTimeStatClosure<T>, GridCacheAdapter.UpdatePutTimeStatClosure<T>, GridCacheAdapter.UpdateRemoveAllConflictTimeStatClosure<T>, GridCacheAdapter.UpdateRemoveAllTimeStatClosure<T>, GridCacheAdapter.UpdateRemoveTimeStatClosure, GridCacheAdapter.UpdateTimeStatClosure<T>
-
-
Field Summary
-
Fields inherited from class org.apache.ignite.internal.processors.cache.GridCacheAdapter
cacheCfg, CLEAR_ALL_SPLIT_THRESHOLD, ctx, DFLT_CACHE_RETRIES_COUNT, DFLT_CACHE_START_SIZE, DFLT_START_CACHE_SIZE, lastFut, locNodeId, log, map, MAX_RETRIES, metrics, NON_TRANSACTIONAL_IGNITE_CACHE_CLEAR_IN_TX_ERROR_MESSAGE, RET2NULL, txLockMsgLog
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedGridNearCacheAdapter()Empty constructor required forExternalizable.protectedGridNearCacheAdapter(GridCacheContext<K,V> ctx)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanclearLocally(K key)Clears an entry from this cache and swap storage only if the entry is not currently locked, and is not participating in a transaction.voidclearLocallyAll(Set<? extends K> keys, boolean srv, boolean near, boolean readers)Clears entries from this cache and swap storage only if the entry is not currently locked, and is not participating in a transaction.abstract GridDhtCacheAdapter<K,V>dht()GridCacheMapEntryentryEx(KeyCacheObject key, AffinityTopologyVersion topVer)GridNearCacheEntryentryExx(KeyCacheObject key, AffinityTopologyVersion topVer)Set<javax.cache.Cache.Entry<K,V>>entrySet(@Nullable CacheEntryPredicate... filter)booleanevict(K key)Evicts entry associated with given key from cache.voidevictAll(Collection<? extends K> keys)Attempts to evict all entries associated with keys.booleanisAllLockedNearOnly(Iterable<? extends K> keys)booleanisLocked(K key)Checks if any node owns a lock for this key.booleanisLockedNearOnly(K key)booleanisNear()IgniteInternalFuture<Map<K,V>>loadAsync(@Nullable IgniteInternalTx tx, @Nullable Collection<KeyCacheObject> keys, boolean forcePrimary, String taskName, boolean deserializeBinary, boolean recovery, @Nullable javax.cache.expiry.ExpiryPolicy expiryPlc, boolean skipVal, boolean skipStore, boolean needVer)voidlocalLoad(Collection<? extends K> keys, javax.cache.expiry.ExpiryPolicy plc, boolean keepBinary)voidlocalLoadCache(IgniteBiPredicate<K,V> p, Object[] args)Delegates toCacheStore.loadCache(IgniteBiInClosure, Object...)method to load state from the underlying persistent storage.IgniteInternalFuture<?>localLoadCacheAsync(IgniteBiPredicate<K,V> p, Object[] args)Asynchronously delegates toCacheStore.loadCache(IgniteBiInClosure, Object...)method to reload state from the underlying persistent storage.Set<javax.cache.Cache.Entry<K,V>>nearEntries()intnearSize()Gets size of near cache key set.longoffHeapAllocatedSize()Gets memory size allocated in off-heap.longoffHeapEntriesCount()Gets number of cache entries stored in off-heap memory.voidonReconnected()@Nullable GridNearCacheEntrypeekExx(KeyCacheObject key)GridCachePreloaderpreloader()intprimarySize()Gets the number of all primary entries cached on this node.longprimarySizeLong()Gets the number of all primary entries cached on this node as a long value.protected voidprocessGetResponse(UUID nodeId, GridNearGetResponse res)intsize()Gets the number of all entries cached on this node.longsizeLong()Gets the number of all entries cached on this node as a long value.List<GridCacheClearAllRunnable<K,V>>splitClearLocally(boolean srv, boolean near, boolean readers)Split clearLocally all task into multiple runnables.voidstart()Starts this cache.StringtoString()-
Methods inherited from class org.apache.ignite.internal.processors.cache.distributed.GridDistributedCacheAdapter
localSizeLong, localSizeLong, lockAllAsync, lockAllAsync, removeAll, removeAllAsync, removeVersionedEntry, txLockAsync
-
Methods inherited from class org.apache.ignite.internal.processors.cache.GridCacheAdapter
active, active, affinity, allEntries, asyncOp, asyncOpAcquire, asyncOpRelease, cache, checkJta, clear, clear, clearAll, clearAllAsync, clearAsync, clearAsync, clearLocally, clearLocally, clusterMetrics, clusterMetrics, configuration, containsKey, containsKeyAsync, containsKeys, containsKeysAsync, context, decrementSize, entries, entryEx, entryEx, entrySet, expiry, expiryPolicy, get, get, getAll, getAll, getAllAsync, getAllAsync, getAllOutTx, getAllOutTxAsync, getAndPut, getAndPut, getAndPut0, getAndPutAsync, getAndPutAsync, getAndPutAsync0, getAndPutIfAbsent, getAndPutIfAbsentAsync, getAndRemove, getAndRemove0, getAndRemoveAsync, getAndRemoveAsync0, getAndReplace, getAndReplaceAsync, getAsync, getAsync, getEntries, getEntriesAsync, getEntry, getEntryAsync, getForcePrimary, getForcePrimaryAsync, igniteIterator, igniteIterator, incrementSize, init, invoke, invoke, invokeAll, invokeAll, invokeAllAsync, invokeAllAsync, invokeAsync, isColocated, isDht, isDhtAtomic, isEmpty, isLocal, isLockedByThread, iterator, iterator, keepBinary, keySet, lastAsyncFuture, loadAll, localEntries, localMetrics, localPeek, localPreloadPartition, localSize, lock, lockAll, lockAsync, log, lostPartitions, map, metrics0, name, nextVersion, nextVersion, onDeferredDelete, onKernalStart, onKernalStop, onUndeploy, parsePeekModes, peekEx, peekEx, preloadPartition, preloadPartitionAsync, printMemoryStats, put, put, put0, putAll, putAll0, putAllAsync, putAllAsync0, putAllConflict, putAllConflictAsync, putAsync, putAsync, putAsync0, putIfAbsent, putIfAbsentAsync, readExternal, readResolve, rebalance, remove, remove, remove, remove0, removeAll, removeAll0, removeAllAsync, removeAllAsync0, removeAllConflict, removeAllConflictAsync, removeAsync, removeAsync, removeAsync, removeAsync0, removeEntry, removeIfObsolete, removeMetrics, repairableGet, repairableGetAll, repairableGetAllAsync, repairableGetAsync, replace, replace, replaceAsync, replaceAsync, scanIterator, setSkipStore, size, sizeAsync, sizeLong, sizeLong, sizeLongAsync, sizeLongAsync, skipStore, startInfo, stop, stopInfo, tx, txStart, txStart, txStartEx, unlock, warnIfUnordered, warnIfUnordered, withExpiryPolicy, withNoRetries, writeExternal
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.ignite.internal.processors.cache.IgniteInternalCache
unlockAll
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
GridNearCacheAdapter
protected GridNearCacheAdapter()
Empty constructor required forExternalizable.
-
GridNearCacheAdapter
protected GridNearCacheAdapter(GridCacheContext<K,V> ctx)
- Parameters:
ctx- Context.
-
-
Method Detail
-
start
public void start() throws IgniteCheckedExceptionStarts this cache. Child classes should override this method to provide custom start-up behavior.- Specified by:
startin classGridCacheAdapter<K,V>- Throws:
IgniteCheckedException- If start failed.
-
dht
public abstract GridDhtCacheAdapter<K,V> dht()
- Returns:
- DHT cache.
-
onReconnected
public void onReconnected()
- Overrides:
onReconnectedin classGridCacheAdapter<K,V>
-
isNear
public boolean isNear()
- Overrides:
isNearin classGridCacheAdapter<K,V>- Returns:
Trueif this is near cache.
-
preloader
public GridCachePreloader preloader()
- Specified by:
preloaderin classGridCacheAdapter<K,V>- Returns:
- Preloader.
-
entryEx
public GridCacheMapEntry entryEx(KeyCacheObject key, AffinityTopologyVersion topVer)
- Overrides:
entryExin classGridCacheAdapter<K,V>- Parameters:
key- Entry key.topVer- Topology version.- Returns:
- Entry (never
null).
-
entryExx
public GridNearCacheEntry entryExx(KeyCacheObject key, AffinityTopologyVersion topVer)
- Parameters:
key- Key.topVer- Topology version.- Returns:
- Entry.
-
peekExx
@Nullable public @Nullable GridNearCacheEntry peekExx(KeyCacheObject key)
- Parameters:
key- Key.- Returns:
- Entry.
-
isLocked
public boolean isLocked(K key)
Checks if any node owns a lock for this key.This is a local in-VM operation and does not involve any network trips or access to persistent storage in any way.
- Specified by:
isLockedin interfaceIgniteInternalCache<K,V>- Overrides:
isLockedin classGridCacheAdapter<K,V>- Parameters:
key- Key to check.- Returns:
Trueif lock is owned by some node.
-
isLockedNearOnly
public boolean isLockedNearOnly(K key)
- Parameters:
key- Key.- Returns:
- If near entry is locked.
-
isAllLockedNearOnly
public boolean isAllLockedNearOnly(Iterable<? extends K> keys)
- Parameters:
keys- Keys.- Returns:
- If near entries for given keys are locked.
-
loadAsync
public IgniteInternalFuture<Map<K,V>> loadAsync(@Nullable @Nullable IgniteInternalTx tx, @Nullable @Nullable Collection<KeyCacheObject> keys, boolean forcePrimary, String taskName, boolean deserializeBinary, boolean recovery, @Nullable @Nullable javax.cache.expiry.ExpiryPolicy expiryPlc, boolean skipVal, boolean skipStore, boolean needVer)
- Parameters:
tx- Transaction.keys- Keys to load.forcePrimary- Force primary flag.taskName- Task name.deserializeBinary- Deserialize binary flag.expiryPlc- Expiry policy.skipVal- Skip value flag.skipStore- Skip store flag.needVer- Need version.- Returns:
- Loaded values.
-
localLoadCache
public void localLoadCache(IgniteBiPredicate<K,V> p, Object[] args) throws IgniteCheckedException
Delegates toCacheStore.loadCache(IgniteBiInClosure, Object...)method to load state from the underlying persistent storage. The loaded values will then be given to the optionally passed in predicate, and, if the predicate returnstrue, will be stored in cache. If predicate isnull, then all loaded values will be stored in cache.Note that this method does not receive keys as a parameter, so it is up to
CacheStoreimplementation to provide all the data to be loaded.This method is not transactional and may end up loading a stale value into cache if another thread has updated the value immediately after it has been loaded. It is mostly useful when pre-loading the cache from underlying data store before start, or for read-only caches.
- Specified by:
localLoadCachein interfaceIgniteInternalCache<K,V>- Overrides:
localLoadCachein classGridCacheAdapter<K,V>- Parameters:
p- Optional predicate (may benull). If provided, will be used to filter values to be put into cache.args- Optional user arguments to be passed intoCacheStore.loadCache(IgniteBiInClosure, Object...)method.- Throws:
IgniteCheckedException- If loading failed.
-
localLoad
public void localLoad(Collection<? extends K> keys, javax.cache.expiry.ExpiryPolicy plc, boolean keepBinary) throws IgniteCheckedException
- Overrides:
localLoadin classGridCacheAdapter<K,V>- Parameters:
keys- Keys to load.plc- Optional expiry policy.- Throws:
IgniteCheckedException- If failed.
-
localLoadCacheAsync
public IgniteInternalFuture<?> localLoadCacheAsync(IgniteBiPredicate<K,V> p, Object[] args)
Asynchronously delegates toCacheStore.loadCache(IgniteBiInClosure, Object...)method to reload state from the underlying persistent storage. The reloaded values will then be given to the optionally passed in predicate, and if the predicate returnstrue, will be stored in cache. If predicate isnull, then all reloaded values will be stored in cache.Note that this method does not receive keys as a parameter, so it is up to
CacheStoreimplementation to provide all the data to be loaded.This method is not transactional and may end up loading a stale value into cache if another thread has updated the value immediately after it has been loaded. It is mostly useful when pre-loading the cache from underlying data store before start, or for read-only caches.
- Specified by:
localLoadCacheAsyncin interfaceIgniteInternalCache<K,V>- Overrides:
localLoadCacheAsyncin classGridCacheAdapter<K,V>- Parameters:
p- Optional predicate (may benull). If provided, will be used to filter values to be put into cache.args- Optional user arguments to be passed intoCacheStore.loadCache(IgniteBiInClosure, Object...)method.- Returns:
- Future to be completed whenever loading completes.
-
processGetResponse
protected void processGetResponse(UUID nodeId, GridNearGetResponse res)
- Parameters:
nodeId- Sender ID.res- Response.
-
size
public int size()
Gets the number of all entries cached on this node. This method will return the count of all cache entries and has O(1) complexity on baseIgniteInternalCache. It is essentially the size of cache key set and is semantically identical to {Cache.keySet().size().NOTE: this operation is not distributed and returns only the number of entries cached on this node.
- Specified by:
sizein interfaceIgniteInternalCache<K,V>- Overrides:
sizein classGridCacheAdapter<K,V>- Returns:
- Size of cache on this node.
-
sizeLong
public long sizeLong()
Gets the number of all entries cached on this node as a long value. This method will return the count of all cache entries and has O(1) complexity on baseIgniteInternalCache. It is essentially the size of cache key set and is semantically identical to {Cache.keySet().size().NOTE: this operation is not distributed and returns only the number of entries cached on this node.
- Specified by:
sizeLongin interfaceIgniteInternalCache<K,V>- Overrides:
sizeLongin classGridCacheAdapter<K,V>- Returns:
- Size of cache on this node.
-
primarySize
public int primarySize()
Gets the number of all primary entries cached on this node.For
CacheMode.PARTITIONEDandCacheMode.REPLICATEDmodes, this method will return number of primary entries cached on this node (excluding any backups). The complexity of this method is O(P), where P is the total number of partitions.NOTE: this operation is not distributed and returns only the number of primary entries cached on this node.
- Specified by:
primarySizein interfaceIgniteInternalCache<K,V>- Overrides:
primarySizein classGridCacheAdapter<K,V>- Returns:
- Number of primary entries in cache.
-
primarySizeLong
public long primarySizeLong()
Gets the number of all primary entries cached on this node as a long value.For
CacheMode.PARTITIONEDandCacheMode.REPLICATEDmodes, this method will return number of primary entries cached on this node (excluding any backups). The complexity of this method is O(P), where P is the total number of partitions.NOTE: this operation is not distributed and returns only the number of primary entries cached on this node.
- Specified by:
primarySizeLongin interfaceIgniteInternalCache<K,V>- Overrides:
primarySizeLongin classGridCacheAdapter<K,V>- Returns:
- Number of primary entries in cache.
-
nearSize
public int nearSize()
Gets size of near cache key set. This method will return count of all entries in near cache and has O(1) complexity on base cache projection.Note that for
LOCALnon-distributed caches this method will always return0- Specified by:
nearSizein interfaceIgniteInternalCache<K,V>- Overrides:
nearSizein classGridCacheAdapter<K,V>- Returns:
- Size of near cache key set or
0if cache is notCacheMode.PARTITIONED.
-
entrySet
public Set<javax.cache.Cache.Entry<K,V>> entrySet(@Nullable @Nullable CacheEntryPredicate... filter)
- Overrides:
entrySetin classGridCacheAdapter<K,V>- Parameters:
filter- Filters to evaluate.- Returns:
- Entry set.
-
evict
public boolean evict(K key)
Evicts entry associated with given key from cache. Note, that entry will be evicted only if it's not used (not participating in any locks or transactions).- Specified by:
evictin interfaceIgniteInternalCache<K,V>- Overrides:
evictin classGridCacheAdapter<K,V>- Parameters:
key- Key to evict from cache.- Returns:
Trueif entry could be evicted,falseotherwise.
-
evictAll
public void evictAll(Collection<? extends K> keys)
Attempts to evict all entries associated with keys. Note, that entry will be evicted only if it's not used (not participating in any locks or transactions).- Specified by:
evictAllin interfaceIgniteInternalCache<K,V>- Overrides:
evictAllin classGridCacheAdapter<K,V>- Parameters:
keys- Keys to evict.
-
clearLocally
public boolean clearLocally(K key)
Clears an entry from this cache and swap storage only if the entry is not currently locked, and is not participating in a transaction.Note that this operation is local as it merely clears an entry from local cache. It does not remove entries from remote caches or from underlying persistent storage.
- Specified by:
clearLocallyin interfaceIgniteInternalCache<K,V>- Overrides:
clearLocallyin classGridCacheAdapter<K,V>- Parameters:
key- Key to clearLocally.- Returns:
Trueif entry was successfully cleared from cache,falseif entry was in use at the time of this method invocation and could not be cleared.
-
clearLocallyAll
public void clearLocallyAll(Set<? extends K> keys, boolean srv, boolean near, boolean readers)
Clears entries from this cache and swap storage only if the entry is not currently locked, and is not participating in a transaction.Note that this operation is local as it merely clears an entry from local cache. It does not remove entries from remote caches or from underlying persistent storage.
- Specified by:
clearLocallyAllin interfaceIgniteInternalCache<K,V>- Overrides:
clearLocallyAllin classGridCacheAdapter<K,V>- Parameters:
keys- Keys to clearLocally.srv- Whether to clear server cache.near- Whether to clear near cache.readers- Whether to clear readers.
-
offHeapEntriesCount
public long offHeapEntriesCount()
Gets number of cache entries stored in off-heap memory.- Specified by:
offHeapEntriesCountin interfaceIgniteInternalCache<K,V>- Overrides:
offHeapEntriesCountin classGridCacheAdapter<K,V>- Returns:
- Number of cache entries stored in off-heap memory.
-
offHeapAllocatedSize
public long offHeapAllocatedSize()
Gets memory size allocated in off-heap.- Specified by:
offHeapAllocatedSizein interfaceIgniteInternalCache<K,V>- Overrides:
offHeapAllocatedSizein classGridCacheAdapter<K,V>- Returns:
- Allocated memory size.
-
splitClearLocally
public List<GridCacheClearAllRunnable<K,V>> splitClearLocally(boolean srv, boolean near, boolean readers)
Split clearLocally all task into multiple runnables.- Overrides:
splitClearLocallyin classGridCacheAdapter<K,V>- Parameters:
srv- Whether to clear server cache.near- Whether to clear near cache.readers- Whether to clear readers.- Returns:
- Split runnables.
-
toString
public String toString()
- Overrides:
toStringin classGridDistributedCacheAdapter<K,V>
-
-