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 Modifier and Type Field Description static intDFLT_ATOMIC_CACHE_DELETE_HISTORY_SIZEstatic intDFLT_CACHE_REMOVE_ENTRIES_TTLstatic intMAX_DELETE_QUEUE_SIZEMaximum size for delete queue.
-
Constructor Summary
Constructors Constructor Description GridDhtLocalPartition(GridCacheSharedContext ctx, CacheGroupContext grp, int id, boolean recovery)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanaddReservation(GridDhtPartitionsReservation r)Adds group reservation to this partition.booleanbackup(AffinityTopologyVersion topVer)voidbeforeApplyBatch(boolean last)Called before next batch is about to be applied during rebalance.protected longclearAll(EvictionContext evictionCtx)Removes all entries and rows from this partition.IgniteInternalFuture<?>clearAsync()Initiates a partition clearing attempt.voidclearDeferredDeletes()Removes all deferred delete requests fromrmvQueue.intcompareTo(@NotNull GridDhtLocalPartition part)longcreateTime()IgniteCacheOffheapManager.CacheDataStoredataStore()voiddecrementPublicSize(@Nullable GridCacheConcurrentMap.CacheMapHolder hld, GridCacheEntryEx e)Decrements public size.voiddumpDebugInfo(SB buf)Collects detailed info about the partition.protected GridCacheConcurrentMap.CacheMapHolderentriesMap(GridCacheContext cctx)protected @Nullable GridCacheConcurrentMap.CacheMapHolderentriesMapIfExists(Integer cacheId)booleanequals(Object o)GridLongListfinalizeUpdateCounters()Flushes pending update counters closing all possible gaps.voidfinishEviction()Moves partition state toEVICTEDif possible.longfullSize()longgetAndIncrementUpdateCounter(long delta)Increments cache update counter on primary node.CacheGroupContextgroup()Returns group context.inthashCode()longhighestAppliedCounter()intid()voidincrementPublicSize(@Nullable GridCacheConcurrentMap.CacheMapHolder hld, GridCacheEntryEx e)Increments public size.longinitialUpdateCounter()intinternalSize()Returns the number of key-value mappings in this map.booleanisClearing()booleanisEmpty()booleanmarkLost()booleanmoving()Forcibly moves partition to a MOVING state.longnextUpdateCounter(int cacheId, AffinityTopologyVersion topVer, boolean primary, boolean init, @Nullable Long primaryCntr)Returns new update counter for primary node or passed counter for backup node.longnextUpdateCounter(int cacheId, IgniteInternalTx tx, @Nullable Long primaryCntr)Used for transactions.voidonCacheStopped(int cacheId)voidonDeferredDelete(int cacheId, KeyCacheObject key, GridCacheVersion ver)voidonRemoved(GridDhtCacheEntry entry)voidonUnlock()On partition unlock callback.booleanown()booleanprimary(AffinityTopologyVersion topVer)intpublicSize(int cacheId)Returns the number of publicly available key-value mappings in this map.voidrelease()Releases previously reserved partition.protected voidrelease(int sizeChange, GridCacheConcurrentMap.CacheMapHolder hld, GridCacheEntryEx e)voidremoveReservation(GridDhtPartitionsReservation r)IgniteInternalFuture<?>rent()Initiates partition eviction process and returns an eviction future.intreservations()booleanreserve()Reserves the partition so it won't be cleared or evicted.longreservedCounter()voidresetInitialUpdateCounter()Reset partition initial update counter.voidresetUpdateCounter()Reset partition update counter.voidrestoreState(GridDhtPartitionState stateToRestore)voidsetState(GridDhtPartitionState toState)For testing purposes only.GridDhtPartitionStatestate()StringtoString()voidtryContinueClearing()Continue clearing if it was delayed before due to reservation and topology version not changed.voidupdateClearVersion()Records a version for row clearing.voidupdateClearVersion(long clearVer)Used to set a version fromPartitionClearingStartRecordwhen need to repeat a clearing after node restart.longupdateCounter()voidupdateCounter(long val)booleanupdateCounter(long start, long delta)Updates cache update counter on backup node.booleanvalid()-
Methods inherited from class org.apache.ignite.internal.processors.cache.GridCacheConcurrentMapImpl
entries, entrySet, getEntry, putEntryIfObsoleteOrAbsent, putEntryIfObsoleteOrAbsent, removeEntry
-
-
-
-
Constructor Detail
-
GridDhtLocalPartition
public GridDhtLocalPartition(GridCacheSharedContext ctx, CacheGroupContext grp, int id, boolean recovery)
- Parameters:
ctx- Context.grp- Cache group.id- Partition ID.recovery- Flag indicates that partition is created during recovery phase.
-
-
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:
internalSizein interfaceGridCacheConcurrentMap- Returns:
- the number of key-value mappings in this map.
-
entriesMap
protected GridCacheConcurrentMap.CacheMapHolder entriesMap(GridCacheContext cctx)
- Specified by:
entriesMapin classGridCacheConcurrentMapImpl- Parameters:
cctx- Cache context.- Returns:
- Map for given cache ID.
-
entriesMapIfExists
@Nullable protected @Nullable GridCacheConcurrentMap.CacheMapHolder entriesMapIfExists(Integer cacheId)
- Specified by:
entriesMapIfExistsin classGridCacheConcurrentMapImpl- 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:
falseIf 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:
Trueif 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.
-
onDeferredDelete
public void onDeferredDelete(int cacheId, KeyCacheObject key, GridCacheVersion ver)- Parameters:
cacheId- cacheId Cache ID.key- Removed key.ver- Removed version.
-
reserve
public boolean reserve()
Reserves the partition so it won't be cleared or evicted. Only MOVING, OWNING and LOST partitions can be reserved.- Specified by:
reservein interfaceGridReservable- Overrides:
reservein classGridCacheConcurrentMapImpl- Returns:
Trueif reserved.
-
release
public void release()
Releases previously reserved partition.- Specified by:
releasein interfaceGridReservable- Overrides:
releasein classGridCacheConcurrentMapImpl
-
release
protected void release(int sizeChange, GridCacheConcurrentMap.CacheMapHolder hld, GridCacheEntryEx e)- Overrides:
releasein classGridCacheConcurrentMapImpl- 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:
Trueif transitioned to OWNING state.
-
moving
public boolean moving()
Forcibly moves partition to a MOVING state.- Returns:
Trueif a partition was switched to MOVING state.
-
updateClearVersion
public void updateClearVersion()
Records a version for row clearing. Must be called when a partition is marked for full rebalancing.- See Also:
clearAll(EvictionContext)
-
updateClearVersion
public void updateClearVersion(long clearVer)
Used to set a version fromPartitionClearingStartRecordwhen need to repeat a clearing after node restart.- Parameters:
clearVer- Clear version.
-
markLost
public boolean markLost()
- Returns:
Trueif partition state changed.
-
rent
public IgniteInternalFuture<?> rent()
Initiates partition eviction process and returns an eviction future. Future will be completed when a partition is moved to EVICTED state (possibly not yet physically deleted). If partition has reservations, eviction will be delayed and continued after all reservations will be released.- Returns:
- Future to signal that this node is no longer an owner or backup or null if corresponding partition
state is
RENTINGorEVICTED.
-
tryContinueClearing
public void tryContinueClearing()
Continue clearing if it was delayed before due to reservation and topology version not changed.
-
clearAsync
public IgniteInternalFuture<?> clearAsync()
Initiates a partition clearing attempt.- Returns:
- A future what will be finished then a current clearing attempt is done.
-
finishEviction
public void finishEviction()
Moves partition state toEVICTEDif possible.
-
isClearing
public boolean isClearing()
- Returns:
Trueif clearing process is running at the moment on the partition.
-
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:
Trueif local node is primary for this partition.
-
backup
public boolean backup(AffinityTopologyVersion topVer)
- Parameters:
topVer- Topology version.- Returns:
Trueif local node is backup for this partition.
-
nextUpdateCounter
public long nextUpdateCounter(int cacheId, AffinityTopologyVersion topVer, boolean primary, boolean init, @Nullable @Nullable Long primaryCntr)Returns new update counter for primary node or passed counter for backup node.Used for non-tx cases.
Counter generation/update logic is delegated to counter implementation.
- Parameters:
cacheId- ID of cache initiated counter update.topVer- Topology version for current operation.init-Trueif initial update.- Returns:
- Next update index.
-
nextUpdateCounter
public long nextUpdateCounter(int cacheId, IgniteInternalTx tx, @Nullable @Nullable Long primaryCntr)Used for transactions.- Parameters:
cacheId- Cache id.tx- Tx.primaryCntr- Primary counter.
-
updateCounter
public long updateCounter()
- Returns:
- Current update counter (LWM).
-
highestAppliedCounter
public long highestAppliedCounter()
- Returns:
- Highest applied update counter.
-
reservedCounter
public long reservedCounter()
- Returns:
- Current reserved counter (HWM).
-
updateCounter
public void updateCounter(long val)
- Parameters:
val- Update counter value.
-
initialUpdateCounter
public long initialUpdateCounter()
- Returns:
- Initial update counter.
-
getAndIncrementUpdateCounter
public long getAndIncrementUpdateCounter(long delta)
Increments cache update counter on primary node.- Parameters:
delta- Value to be added to update counter.- Returns:
- Update counter value before update.
-
updateCounter
public boolean updateCounter(long start, long delta)Updates cache update counter on backup node.- Parameters:
start- Start positiondelta- Delta.
-
resetUpdateCounter
public void resetUpdateCounter()
Reset partition update counter.
-
resetInitialUpdateCounter
public void resetInitialUpdateCounter()
Reset partition initial update counter.
-
fullSize
public long fullSize()
- Returns:
- Total size of all caches.
-
clearAll
protected long clearAll(EvictionContext evictionCtx) throws NodeStoppingException
Removes all entries and rows from this partition.- Returns:
- Number of rows cleared from page memory.
- Throws:
NodeStoppingException- If node stopping.
-
clearDeferredDeletes
public void clearDeferredDeletes()
Removes all deferred delete requests fromrmvQueue.
-
compareTo
public int compareTo(@NotNull @NotNull GridDhtLocalPartition part)- Specified by:
compareToin interfaceComparable<GridDhtLocalPartition>
-
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:
publicSizein interfaceGridCacheConcurrentMap- Parameters:
cacheId- Cache ID.- Returns:
- the number of publicly available key-value mappings in this map.
-
incrementPublicSize
public void incrementPublicSize(@Nullable @Nullable GridCacheConcurrentMap.CacheMapHolder hld, GridCacheEntryEx e)Increments public size.- Specified by:
incrementPublicSizein interfaceGridCacheConcurrentMap- 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 @Nullable GridCacheConcurrentMap.CacheMapHolder hld, GridCacheEntryEx e)Decrements public size.- Specified by:
decrementPublicSizein interfaceGridCacheConcurrentMap- 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.
-
finalizeUpdateCounters
public GridLongList finalizeUpdateCounters()
Flushes pending update counters closing all possible gaps.- Returns:
- Even-length array of pairs [start, end] for each gap.
-
beforeApplyBatch
public void beforeApplyBatch(boolean last)
Called before next batch is about to be applied during rebalance. Currently used for tests.- Parameters:
last-Trueif last batch for partition.
-
dumpDebugInfo
public void dumpDebugInfo(SB buf)
Collects detailed info about the partition.- Parameters:
buf- Buffer.
-
-