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

## Class GridDhtLocalPartition

- java.lang.Object
- - org.apache.ignite.internal.processors.cache.GridCacheConcurrentMapImpl
  - - org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition

All Implemented Interfaces:
  Comparable<GridDhtLocalPartition>, GridReservable, GridCacheConcurrentMap

    public class GridDhtLocalPartition
    extends GridCacheConcurrentMapImpl
    implements Comparable<GridDhtLocalPartition>, GridReservable

Key partition.

### Nested Class Summary

### Nested classes/interfaces inherited from interface org.apache.ignite.internal.processors.cache.GridCacheConcurrentMap

`GridCacheConcurrentMap.CacheMapHolder`

### Field Summary

Fields
`static int` `MAX_DELETE_QUEUE_SIZE` Maximum size for delete queue.

### Constructor Summary

Constructors
Constructor and Description
`GridDhtLocalPartition(GridCacheSharedContext ctx, CacheGroupContext grp, int id)`

### Method Summary

All Methods Instance Methods Concrete Methods
`boolean` `addReservation(GridDhtPartitionsReservation r)` Adds group reservation to this partition.
`void` `awaitDestroy()` Awaits completion of partition destroy process in case of `EVICTED` partition state.
`boolean` `backup(AffinityTopologyVersion topVer)`
`void` `cleanupRemoveQueue()`
`void` `clearAsync()` Initiates single clear process if partition is in MOVING state or continues cleaning for RENTING state.
`int` `compareTo(GridDhtLocalPartition part)`
`long` `createTime()`
`IgniteCacheOffheapManager.CacheDataStore` `dataStore()`
`void` `decrementPublicSize(GridCacheConcurrentMap.CacheMapHolder hld, GridCacheEntryEx e)` Decrements public size.
`void` `destroy()` Destroys partition data store and invokes appropriate callbacks.
`protected GridCacheConcurrentMap.CacheMapHolder` `entriesMap(GridCacheContext cctx)`
`protected GridCacheConcurrentMap.CacheMapHolder` `entriesMapIfExists(Integer cacheId)`
`boolean` `equals(Object obj)`
`void` `finalizeUpdateCountres()` Flushes pending update counters closing all possible gaps.
`long` `fullSize()`
`long` `getAndIncrementUpdateCounter(long delta)` Updates MVCC cache update counter on primary node.
`CacheGroupContext` `group()` Returns group context.
`int` `hashCode()`
`int` `id()`
`void` `incrementPublicSize(GridCacheConcurrentMap.CacheMapHolder hld, GridCacheEntryEx e)` Increments public size.
`long` `initialUpdateCounter()`
`void` `initialUpdateCounter(long val)`
`int` `internalSize()` Returns the number of key-value mappings in this map.
`boolean` `isClearing()`
`boolean` `isEmpty()`
`void` `lock()` Locks partition.
`boolean` `markForDestroy()`
`boolean` `markLost()`
`void` `moving()` Forcibly moves partition to a MOVING state.
`long` `nextUpdateCounter(int cacheId, AffinityTopologyVersion topVer, boolean primary, Long primaryCntr)`
`void` `onCacheStopped(int cacheId)`
`void` `onClearFinished(IgniteInClosure<? super IgniteInternalFuture<?>> lsnr)` Adds listener on `clearFuture` finish.
`void` `onDeferredDelete(int cacheId, KeyCacheObject key, GridCacheVersion ver)`
`void` `onRemoved(GridDhtCacheEntry entry)`
`void` `onUnlock()` On partition unlock callback.
`boolean` `own()`
`boolean` `primary(AffinityTopologyVersion topVer)`
`int` `publicSize(int cacheId)` Returns the number of publicly available key-value mappings in this map.
`void` `release()` Releases previously reserved partition.
`protected void` `release(int sizeChange, GridCacheConcurrentMap.CacheMapHolder hld, GridCacheEntryEx e)`
`void` `removeReservation(GridDhtPartitionsReservation r)`
`IgniteInternalFuture<?>` `rent(boolean updateSeq)` Initiates partition eviction process.
`int` `reservations()`
`boolean` `reserve()` Reserves a partition so it won't be cleared or evicted.
`void` `restoreState(GridDhtPartitionState stateToRestore)`
`void` `setState(GridDhtPartitionState toState)` For testing purposes only.
`GridDhtPartitionState` `state()`
`String` `toString()`
`boolean` `tryClear(EvictionContext evictionCtx)` Tries to start partition clear process `clearAll(EvictionContext)`).
`void` `tryContinueClearing()` Continues delayed clearing of partition if possible.
`void` `unlock()` Unlocks partition.
`long` `updateCounter()`
`void` `updateCounter(long val)`
`void` `updateCounter(long start, long delta)` Updates MVCC cache update counter on backup node.
`boolean` `valid()`

### Methods inherited from class org.apache.ignite.internal.processors.cache.GridCacheConcurrentMapImpl

`entries, entrySet, getEntry, putEntryIfObsoleteOrAbsent, putEntryIfObsoleteOrAbsent, removeEntry`

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

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

### Field Detail

#### MAX_DELETE_QUEUE_SIZE

    public static final int MAX_DELETE_QUEUE_SIZE

Maximum size for delete queue.

### Constructor Detail

#### GridDhtLocalPartition

    public GridDhtLocalPartition(GridCacheSharedContext ctx,
                                 CacheGroupContext grp,
                                 int id)

Parameters:
  `ctx` - Context.
  `grp` - Cache group.
  `id` - Partition ID.

### Method Detail

#### internalSize

    public int internalSize()

Returns the number of key-value mappings in this map. It does not include entries from underlying data store.

Specified by:
  `internalSize` in interface `GridCacheConcurrentMap`
Returns:
  the number of key-value mappings in this map.

#### entriesMap

    protected GridCacheConcurrentMap.CacheMapHolder entriesMap(GridCacheContext cctx)

Specified by:
  `entriesMap` in class `GridCacheConcurrentMapImpl`
Parameters:
  `cctx` - Cache context.
Returns:
  Map for given cache ID.

#### entriesMapIfExists

    @Nullable
    protected GridCacheConcurrentMap.CacheMapHolder entriesMapIfExists(Integer cacheId)

Specified by:
  `entriesMapIfExists` in class `GridCacheConcurrentMapImpl`
Parameters:
  `cacheId` - Cache ID.
Returns:
  Map for given cache ID.

#### dataStore

    public IgniteCacheOffheapManager.CacheDataStore dataStore()

Returns:
  Data store.

#### addReservation

    public boolean addReservation(GridDhtPartitionsReservation r)

Adds group reservation to this partition.

Parameters:
  `r` - Reservation.
Returns:
  `false` If such reservation already added.

#### removeReservation

    public void removeReservation(GridDhtPartitionsReservation r)

Parameters:
  `r` - Reservation.

#### id

    public int id()

Returns:
  Partition ID.

#### createTime

    public long createTime()

Returns:
  Create time.

#### state

    public GridDhtPartitionState state()

Returns:
  Partition state.

#### reservations

    public int reservations()

Returns:
  Reservations.

#### isEmpty

    public boolean isEmpty()

Returns:
  `True` if partition is empty.

#### valid

    public boolean valid()

Returns:
  If partition is moving or owning or renting.

#### onRemoved

    public void onRemoved(GridDhtCacheEntry entry)

Parameters:
  `entry` - Entry to remove.

#### cleanupRemoveQueue

    public void cleanupRemoveQueue()

#### onDeferredDelete

    public void onDeferredDelete(int cacheId,
                                 KeyCacheObject key,
                                 GridCacheVersion ver)

Parameters:
  `cacheId` - cacheId Cache ID.
  `key` - Removed key.
  `ver` - Removed version.

#### lock

    public void lock()

Locks partition.

#### unlock

    public void unlock()

Unlocks partition.

#### reserve

    public boolean reserve()

Reserves a partition so it won't be cleared or evicted.

Specified by:
  `reserve` in interface `GridReservable`
Overrides:
  `reserve` in class `GridCacheConcurrentMapImpl`
Returns:
  `True` if reserved.

#### release

    public void release()

Releases previously reserved partition.

Specified by:
  `release` in interface `GridReservable`
Overrides:
  `release` in class `GridCacheConcurrentMapImpl`

#### release

    protected void release(int sizeChange,
                           GridCacheConcurrentMap.CacheMapHolder hld,
                           GridCacheEntryEx e)

Overrides:
  `release` in class `GridCacheConcurrentMapImpl`
Parameters:
  `sizeChange` - Size delta.
  `hld` - Map holder.
  `e` - Map entry.

#### restoreState

    public void restoreState(GridDhtPartitionState stateToRestore)

Parameters:
  `stateToRestore` - State to restore.

#### setState

    public void setState(GridDhtPartitionState toState)

For testing purposes only.

Parameters:
  `toState` - State to set.

#### own

    public boolean own()

Returns:
  `True` if transitioned to OWNING state.

#### moving

    public void moving()

Forcibly moves partition to a MOVING state.

#### markLost

    public boolean markLost()

Returns:
  `True` if partition state changed.

#### rent

    public IgniteInternalFuture<?> rent(boolean updateSeq)

Initiates partition eviction process. If partition has reservations, eviction will be delayed and continued after all reservations will be released.

Parameters:
  `updateSeq` - If `true` topology update sequence will be updated after eviction is finished.
Returns:
  Future to signal that this node is no longer an owner or backup.

#### clearAsync

    public void clearAsync()

Initiates single clear process if partition is in MOVING state or continues cleaning for RENTING state. Method does nothing if clear process is already running.

#### tryContinueClearing

    public void tryContinueClearing()

Continues delayed clearing of partition if possible. Clearing may be delayed because of existing reservations.

#### markForDestroy

    public boolean markForDestroy()

Returns:
  `True` if partition is safe to destroy.

#### destroy

    public void destroy()

Destroys partition data store and invokes appropriate callbacks.

#### awaitDestroy

    public void awaitDestroy()

Awaits completion of partition destroy process in case of `EVICTED` partition state.

#### onClearFinished

    public void onClearFinished(IgniteInClosure<? super IgniteInternalFuture<?>> lsnr)

Adds listener on `clearFuture` finish.

Parameters:
  `lsnr` - Listener.

#### isClearing

    public boolean isClearing()

Returns:
  `True` if clearing process is running at the moment on the partition.

#### tryClear

    public boolean tryClear(EvictionContext evictionCtx)
                     throws NodeStoppingException

Tries to start partition clear process `clearAll(EvictionContext)`). Only one thread is allowed to do such process concurrently. At the end of clearing method completes `clearFuture`.

Returns:
  `false` if clearing is not started due to existing reservations.
Throws:
  `NodeStoppingException` - If node is stopping.

#### onUnlock

    public void onUnlock()

On partition unlock callback. Tries to continue delayed partition clearing.

#### primary

    public boolean primary(AffinityTopologyVersion topVer)

Parameters:
  `topVer` - Topology version.
Returns:
  `True` if local node is primary for this partition.

#### backup

    public boolean backup(AffinityTopologyVersion topVer)

Parameters:
  `topVer` - Topology version.
Returns:
  `True` if local node is backup for this partition.

#### nextUpdateCounter

    public long nextUpdateCounter(int cacheId,
                                  AffinityTopologyVersion topVer,
                                  boolean primary,
                                  @Nullable
                                  Long primaryCntr)

Parameters:
  `cacheId` - ID of cache initiated counter update.
  `topVer` - Topology version for current operation.
Returns:
  Next update index.

#### updateCounter

    public long updateCounter()

Returns:
  Current update counter.

#### updateCounter

    public void updateCounter(long val)

Parameters:
  `val` - Update counter value.

#### initialUpdateCounter

    public long initialUpdateCounter()

Returns:
  Initial update counter.

#### initialUpdateCounter

    public void initialUpdateCounter(long val)

Parameters:
  `val` - Initial update counter value.

#### getAndIncrementUpdateCounter

    public long getAndIncrementUpdateCounter(long delta)

Updates MVCC cache update counter on primary node.

Parameters:
  `delta` - Value to be added to update counter.
Returns:
  Update counter value before update.

#### updateCounter

    public void updateCounter(long start,
                              long delta)

Updates MVCC cache update counter on backup node.

Parameters:
  `start` - Start position
  `delta` - Delta.

#### fullSize

    public long fullSize()

Returns:
  Total size of all caches.

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Object`

#### equals

    public boolean equals(Object obj)

Overrides:
  `equals` in class `Object`

#### compareTo

    public int compareTo(@NotNull
                         GridDhtLocalPartition part)

Specified by:
  `compareTo` in interface `Comparable<GridDhtLocalPartition>`

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

#### publicSize

    public int publicSize(int cacheId)

Returns the number of publicly available key-value mappings in this map. It excludes entries that are marked as deleted. It also does not include entries from underlying data store.

Specified by:
  `publicSize` in interface `GridCacheConcurrentMap`
Parameters:
  `cacheId` - Cache ID.
Returns:
  the number of publicly available key-value mappings in this map.

#### incrementPublicSize

    public void incrementPublicSize(@Nullable
                                    GridCacheConcurrentMap.CacheMapHolder hld,
                                    GridCacheEntryEx e)

Increments public size.

Specified by:
  `incrementPublicSize` in interface `GridCacheConcurrentMap`
Parameters:
  `hld` - Cache map (passed as optimization to avoid cache map lookup for shared groups).
  `e` - Entry that caused public size change.

#### decrementPublicSize

    public void decrementPublicSize(@Nullable
                                    GridCacheConcurrentMap.CacheMapHolder hld,
                                    GridCacheEntryEx e)

Decrements public size.

Specified by:
  `decrementPublicSize` in interface `GridCacheConcurrentMap`
Parameters:
  `hld` - Cache map (passed as optimization to avoid cache map lookup for shared groups).
  `e` - Entry that caused public size change.

#### group

    public CacheGroupContext group()

Returns group context.

Returns:
  Group context.

#### onCacheStopped

    public void onCacheStopped(int cacheId)

Parameters:
  `cacheId` - Cache ID.

#### finalizeUpdateCountres

    public void finalizeUpdateCountres()

Flushes pending update counters closing all possible gaps.

2018 Copyright © Apache Software Foundation

Follow @ApacheIgnite

Ignite Database and Caching Platform | : ver. 2.7.5
Release Date | : June 4 2019