org.apache.ignite.internal.processors.cache.distributed.dht

## Class GridDhtCacheAdapter<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.dht.GridDhtCacheAdapter<K,V>

All Implemented Interfaces:
  Externalizable, Serializable, Iterable<javax.cache.Cache.Entry<K,V>>, IgniteInternalCache<K,V>

Direct Known Subclasses:
  GridDhtAtomicCache, GridDhtTransactionalCacheAdapter

    public abstract class GridDhtCacheAdapter<K,V>
    extends GridDistributedCacheAdapter<K,V>

DHT cache adapter.

See Also:
  Serialized Form

### Nested Class Summary

Nested Classes
`protected class` `GridDhtCacheAdapter.MessageHandler<M>`

### 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.BulkOperation, GridCacheAdapter.CacheExpiryPolicy, GridCacheAdapter.FutureHolder, GridCacheAdapter.InvokeAllTimeStatClosure<T>, GridCacheAdapter.PeekModes, GridCacheAdapter.TopologyVersionAwareJob, GridCacheAdapter.UpdateGetTimeStatClosure<T>, GridCacheAdapter.UpdatePutAndGetTimeStatClosure<T>, GridCacheAdapter.UpdatePutTimeStatClosure<T>, GridCacheAdapter.UpdateRemoveTimeStatClosure<T>, GridCacheAdapter.UpdateTimeStatClosure<T>`

### Field Summary

### Fields inherited from class org.apache.ignite.internal.processors.cache.GridCacheAdapter

`cacheCfg, CLEAR_ALL_SPLIT_THRESHOLD, ctx, DFLT_START_CACHE_SIZE, keyCheck, lastFut, locNodeId, log, map, MAX_RETRIES, metrics, RET2NULL, txLockMsgLog`

### Constructor Summary

Constructors
`protected` `GridDhtCacheAdapter()` Empty constructor required for `Externalizable`.
`protected` `GridDhtCacheAdapter(GridCacheContext<K,V> ctx)`
`protected` `GridDhtCacheAdapter(GridCacheContext<K,V> ctx, GridCacheConcurrentMap map)` Constructor used for near-only cache.

### Method Summary

All Methods Instance Methods Abstract Methods Concrete Methods
`boolean` `addFuture(GridDhtForceKeysFuture<?,?> fut)` Adds future to future map.
`protected GridDistributedCacheEntry` `createEntry(KeyCacheObject key)`
`void` `dumpDebugInfo()`
`GridCacheEntryEx` `entryEx(KeyCacheObject key, AffinityTopologyVersion topVer)`
`GridDhtCacheEntry` `entryExx(KeyCacheObject key)`
`GridDhtCacheEntry` `entryExx(KeyCacheObject key, AffinityTopologyVersion topVer)`
`IgniteInternalFuture<Map<K,V>>` `getAllAsync(@Nullable Collection<? extends K> keys, boolean forcePrimary, boolean skipTx, @Nullable UUID subjId, String taskName, boolean deserializeBinary, boolean recovery, boolean readRepair, boolean skipVals, boolean needVer)`
`GridDhtFuture<Collection<GridCacheEntryInfo>>` `getDhtAsync(UUID reader, long msgId, Map<KeyCacheObject,Boolean> keys, boolean addReaders, boolean readThrough, AffinityTopologyVersion topVer, @Nullable UUID subjId, int taskNameHash, @Nullable IgniteCacheExpiryPolicy expiry, boolean skipVals, boolean recovery, @Nullable String txLbl, MvccSnapshot mvccSnapshot)`
`Iterator<javax.cache.Cache.Entry<K,V>>` `localEntriesIterator(boolean primary, boolean backup, boolean keepBinary)`
`void` `localLoad(Collection<? extends K> keys, javax.cache.expiry.ExpiryPolicy plc, boolean keepBinary)`
`void` `localLoadCache(IgniteBiPredicate<K,V> p, Object[] args)` Delegates to `CacheStore.loadCache(IgniteBiInClosure, Object...)` method to load state from the underlying persistent storage.
`abstract GridNearCacheAdapter<K,V>` `near()`
`protected boolean` `needRemap(AffinityTopologyVersion mapVer, AffinityTopologyVersion curVer)`
`void` `onDeferredDelete(GridCacheEntryEx entry, GridCacheVersion ver)`
`void` `onKernalStop()` Kernal stop callback.
`@Nullable GridDhtCacheEntry` `peekExx(KeyCacheObject key)`
`GridCachePreloader` `preloader()`
`int` `primarySize()` Gets the number of all primary entries cached on this node.
`long` `primarySizeLong()` Gets the number of all primary entries cached on this node as a long value.
`void` `printMemoryStats()` Prints memory stats.
`protected void` `processForceKeyResponse(ClusterNode node, GridDhtForceKeysResponse msg)`
`protected void` `processForceKeysRequest(ClusterNode node, GridDhtForceKeysRequest msg)`
`protected void` `processNearGetRequest(UUID nodeId, GridNearGetRequest req)`
`protected void` `processNearGetResponse(UUID nodeId, GridNearGetResponse res)`
`protected void` `processNearSingleGetRequest(UUID nodeId, GridNearSingleGetRequest req)`
`protected void` `processNearSingleGetResponse(UUID nodeId, GridNearSingleGetResponse res)`
`void` `removeFuture(GridDhtForceKeysFuture<?,?> fut)` Removes future from future map.
`void` `sendTtlUpdateRequest(@Nullable IgniteCacheExpiryPolicy expiryPlc)` Initiates process of notifying all interested nodes that TTL was changed.
`int` `size()` Gets the number of all entries cached on this node.
`long` `sizeLong()` 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.
`void` `start()` Starts this cache.
`GridDhtPartitionTopology` `topology()`
`String` `toString()`
`void` `unlockAll(Collection<? extends K> keys)` Unlocks given keys only if current thread owns the locks.

### 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, awaitLastFut, cache, checkCurrentTx, checkJta, clear, clear, clearAll, clearAllAsync, clearAsync, clearAsync, clearLocally, clearLocally, clearLocally, clearLocallyAll, clusterMetrics, clusterMetrics, clusterMxBean, configuration, containsKey, containsKeyAsync, containsKeys, containsKeysAsync, context, decrementSize, entries, entryEx, entryEx, entrySet, entrySet, evict, evictAll, expiry, expiryPolicy, forceKeyCheck, forSubjectId, get, get, getAll, getAll, getAllAsync, getAllAsync, getAllAsync0, 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, isLocked, isLockedByThread, isNear, iterator, iterator, keepBinary, keySet, loadAll, localEntries, localLoadCacheAsync, localMetrics, localMxBean, localPeek, localPreloadPartition, localSize, lock, lockAll, lockAsync, log, lostPartitions, map, metrics0, name, nearSize, offHeapAllocatedSize, offHeapEntriesCount, onKernalStart, onReconnected, onUndeploy, parsePeekModes, peekEx, peekEx, preloadPartition, preloadPartitionAsync, 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, repairAsync, repairAsync, replace, replace, replaceAsync, replaceAsync, saveFuture, scanIterator, setSkipStore, size, sizeAsync, sizeLong, sizeLong, sizeLongAsync, sizeLongAsync, skipStore, startInfo, stop, stopInfo, tx, txStart, txStart, txStartEx, unlock, validateCacheKey, validateCacheKeys, warnIfUnordered, warnIfUnordered, withAllowAtomicOpsInTx, withExpiryPolicy, withNoRetries, writeExternal`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

### Constructor Detail

#### GridDhtCacheAdapter

    protected GridDhtCacheAdapter()

Empty constructor required for `Externalizable`.

#### GridDhtCacheAdapter

    protected GridDhtCacheAdapter(GridCacheContext<K,V> ctx)

Parameters:
  `ctx` - Context.

#### GridDhtCacheAdapter

    protected GridDhtCacheAdapter(GridCacheContext<K,V> ctx,
                                  GridCacheConcurrentMap map)

Constructor used for near-only cache.

Parameters:
  `ctx` - Cache context.
  `map` - Cache map.

### Method Detail

#### addFuture

    public boolean addFuture(GridDhtForceKeysFuture<?,?> fut)

Adds future to future map.

Parameters:
  `fut` - Future to add.
Returns:
  `False` if node cache is stopping and future was completed with error.

#### removeFuture

    public void removeFuture(GridDhtForceKeysFuture<?,?> fut)

Removes future from future map.

Parameters:
  `fut` - Future to remove.

#### processForceKeyResponse

    protected final void processForceKeyResponse(ClusterNode node,
                                                 GridDhtForceKeysResponse msg)

Parameters:
  `node` - Node.
  `msg` - Message.

#### processForceKeysRequest

    protected final void processForceKeysRequest(ClusterNode node,
                                                 GridDhtForceKeysRequest msg)

Parameters:
  `node` - Node originated request.
  `msg` - Force keys message.

#### dumpDebugInfo

    public void dumpDebugInfo()

#### onKernalStop

    public void onKernalStop()

Kernal stop callback.

Overrides:
  `onKernalStop` in class `GridCacheAdapter<K,V>`

#### processNearGetResponse

    protected final void processNearGetResponse(UUID nodeId,
                                                GridNearGetResponse res)

Parameters:
  `nodeId` - Sender node ID.
  `res` - Near get response.

#### processNearSingleGetResponse

    protected void processNearSingleGetResponse(UUID nodeId,
                                                GridNearSingleGetResponse res)

Parameters:
  `nodeId` - Sender node ID.
  `res` - Near get response.

#### start

    public void start()
               throws IgniteCheckedException

Starts this cache. Child classes should override this method to provide custom start-up behavior.

Specified by:
  `start` in class `GridCacheAdapter<K,V>`
Throws:
  `IgniteCheckedException` - If start failed.

#### printMemoryStats

    public void printMemoryStats()

Prints memory stats.

Overrides:
  `printMemoryStats` in class `GridCacheAdapter<K,V>`

#### near

    public abstract GridNearCacheAdapter<K,V> near()

Returns:
  Near cache.

#### topology

    public GridDhtPartitionTopology topology()

Returns:
  Partition topology.

#### preloader

    public GridCachePreloader preloader()

Specified by:
  `preloader` in class `GridCacheAdapter<K,V>`
Returns:
  Preloader.

#### peekExx

    @Nullable
    public @Nullable GridDhtCacheEntry peekExx(KeyCacheObject key)

Parameters:
  `key` - Key.
Returns:
  DHT entry.

#### entryEx

    public GridCacheEntryEx entryEx(KeyCacheObject key,
                                    AffinityTopologyVersion topVer)
                             throws GridDhtInvalidPartitionException

Overrides:
  `entryEx` in class `GridCacheAdapter<K,V>`
Parameters:
  `key` - Entry key.
  `topVer` - Topology version.
Returns:
  Entry (never `null`).
Throws:
  `GridDhtInvalidPartitionException` - If partition for the key is no longer valid.

#### entryExx

    public GridDhtCacheEntry entryExx(KeyCacheObject key)
                               throws GridDhtInvalidPartitionException

Parameters:
  `key` - Key.
Returns:
  DHT entry.
Throws:
  `GridDhtInvalidPartitionException` - If partition for the key is no longer valid.

#### entryExx

    public GridDhtCacheEntry entryExx(KeyCacheObject key,
                                      AffinityTopologyVersion topVer)
                               throws GridDhtInvalidPartitionException

Parameters:
  `key` - Key.
  `topVer` - Topology version.
Returns:
  DHT entry.
Throws:
  `GridDhtInvalidPartitionException` - If partition for the key is no longer valid.

#### createEntry

    protected GridDistributedCacheEntry createEntry(KeyCacheObject key)

Parameters:
  `key` - Key for which entry should be returned.
Returns:
  Cache entry.

#### localLoad

    public void localLoad(Collection<? extends K> keys,
                          javax.cache.expiry.ExpiryPolicy plc,
                          boolean keepBinary)
                   throws IgniteCheckedException

Overrides:
  `localLoad` in class `GridCacheAdapter<K,V>`
Parameters:
  `keys` - Keys to load.
  `plc` - Optional expiry policy.
Throws:
  `IgniteCheckedException` - If failed.

#### localLoadCache

    public void localLoadCache(IgniteBiPredicate<K,V> p,
                               Object[] args)
                        throws IgniteCheckedException

Delegates to `CacheStore.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 returns `true`, will be stored in cache. If predicate is `null`, 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 `CacheStore` implementation 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:
  `localLoadCache` in interface `IgniteInternalCache<K,V>`
Overrides:
  `localLoadCache` in class `GridCacheAdapter<K,V>`
Parameters:
  `p` - Optional predicate (may be `null`). If provided, will be used to filter values to be put into cache.
  `args` - Optional user arguments to be passed into `CacheStore.loadCache(IgniteBiInClosure, Object...)` method.
Throws:
  `IgniteCheckedException` - If loading failed.

#### 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 base `IgniteInternalCache`. 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:
  `size` in interface `IgniteInternalCache<K,V>`
Overrides:
  `size` in class `GridCacheAdapter<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 base `IgniteInternalCache`. 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:
  `sizeLong` in interface `IgniteInternalCache<K,V>`
Overrides:
  `sizeLong` in class `GridCacheAdapter<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.LOCAL` non-distributed cache mode, this method is identical to `IgniteInternalCache.size()`.

For `CacheMode.PARTITIONED` and `CacheMode.REPLICATED` modes, 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:
  `primarySize` in interface `IgniteInternalCache<K,V>`
Overrides:
  `primarySize` in class `GridCacheAdapter<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.LOCAL` non-distributed cache mode, this method is identical to `IgniteInternalCache.size()`.

For `CacheMode.PARTITIONED` and `CacheMode.REPLICATED` modes, 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:
  `primarySizeLong` in interface `IgniteInternalCache<K,V>`
Overrides:
  `primarySizeLong` in class `GridCacheAdapter<K,V>`
Returns:
  Number of primary entries in cache.

#### getAllAsync

    public IgniteInternalFuture<Map<K,V>> getAllAsync(@Nullable
                                                      @Nullable Collection<? extends K> keys,
                                                      boolean forcePrimary,
                                                      boolean skipTx,
                                                      @Nullable
                                                      @Nullable UUID subjId,
                                                      String taskName,
                                                      boolean deserializeBinary,
                                                      boolean recovery,
                                                      boolean readRepair,
                                                      boolean skipVals,
                                                      boolean needVer)

Overrides:
  `getAllAsync` in class `GridCacheAdapter<K,V>`
Parameters:
  `keys` - Keys.
  `forcePrimary` - Force primary.
  `skipTx` - Skip tx.
  `subjId` - Subj Id.
  `taskName` - Task name.
  `deserializeBinary` - Deserialize binary.
  `recovery` - Recovery mode flag.
  `skipVals` - Skip values.
  `needVer` - Need version.
Returns:
  Future for the get operation.
See Also:
  `GridCacheAdapter.getAllAsync(Collection)`

#### getDhtAsync

    public GridDhtFuture<Collection<GridCacheEntryInfo>> getDhtAsync(UUID reader,
                                                                     long msgId,
                                                                     Map<KeyCacheObject,Boolean> keys,
                                                                     boolean addReaders,
                                                                     boolean readThrough,
                                                                     AffinityTopologyVersion topVer,
                                                                     @Nullable
                                                                     @Nullable UUID subjId,
                                                                     int taskNameHash,
                                                                     @Nullable
                                                                     @Nullable IgniteCacheExpiryPolicy expiry,
                                                                     boolean skipVals,
                                                                     boolean recovery,
                                                                     @Nullable
                                                                     @Nullable String txLbl,
                                                                     MvccSnapshot mvccSnapshot)

Parameters:
  `reader` - Reader node ID.
  `msgId` - Message ID.
  `keys` - Keys to get.
  `addReaders` - Add readers flag.
  `readThrough` - Read through flag.
  `topVer` - Topology version.
  `subjId` - Subject ID.
  `taskNameHash` - Task name hash code.
  `expiry` - Expiry policy.
  `skipVals` - Skip values flag.
  `txLbl` - Transaction label.
  `mvccSnapshot` - MVCC snapshot.
Returns:
  DHT future.

#### processNearSingleGetRequest

    protected void processNearSingleGetRequest(UUID nodeId,
                                               GridNearSingleGetRequest req)

Parameters:
  `nodeId` - Node ID.
  `req` - Get request.

#### processNearGetRequest

    protected void processNearGetRequest(UUID nodeId,
                                         GridNearGetRequest req)

Parameters:
  `nodeId` - Node ID.
  `req` - Get request.

#### sendTtlUpdateRequest

    public void sendTtlUpdateRequest(@Nullable
                                     @Nullable IgniteCacheExpiryPolicy expiryPlc)

Initiates process of notifying all interested nodes that TTL was changed. Directly sends requests to primary nodes and `IgniteCacheExpiryPolicy.readers()`.

Parameters:
  `expiryPlc` - Expiry policy.

#### unlockAll

    public void unlockAll(Collection<? extends K> keys)

Unlocks given keys only if current thread owns the locks. Only the keys that have been locked by calling thread and pass through the filter (if any) will be unlocked. If none of the key locks is owned by current thread, then this method will do nothing.

## Transactions

Locks are not transactional and should not be used from within transactions. If you do need explicit locking within transaction, then you should use `TransactionConcurrency.PESSIMISTIC` concurrency control for transaction which will acquire explicit locks for relevant cache operations.

Parameters:
  `keys` - Keys to unlock.

#### toString

    public String toString()

Overrides:
  `toString` in class `GridDistributedCacheAdapter<K,V>`

#### splitClearLocally

    public List<GridCacheClearAllRunnable<K,V>> splitClearLocally(boolean srv,
                                                                  boolean near,
                                                                  boolean readers)

Split clearLocally all task into multiple runnables.

Overrides:
  `splitClearLocally` in class `GridCacheAdapter<K,V>`
Parameters:
  `srv` - Whether to clear server cache.
  `near` - Whether to clear near cache.
  `readers` - Whether to clear readers.
Returns:
  Split runnables.

#### onDeferredDelete

    public void onDeferredDelete(GridCacheEntryEx entry,
                                 GridCacheVersion ver)

Specified by:
  `onDeferredDelete` in class `GridCacheAdapter<K,V>`
Parameters:
  `entry` - Entry.
  `ver` - Version.

#### needRemap

    protected final boolean needRemap(AffinityTopologyVersion mapVer,
                                      AffinityTopologyVersion curVer)

Parameters:
  `mapVer` - Mapped topology version.
  `curVer` - Current topology version.
Returns:
  `True` if cache affinity changed and operation should be remapped.

#### localEntriesIterator

    public Iterator<javax.cache.Cache.Entry<K,V>> localEntriesIterator(boolean primary,
                                                                       boolean backup,
                                                                       boolean keepBinary)

Parameters:
  `primary` - If `true` includes primary entries.
  `backup` - If `true` includes backup entries.
  `keepBinary` - Keep binary flag.
Returns:
  Local entries iterator.

${current.year} Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.9.0
Release Date | : October 15 2020