Class PartitionUpdateCounterTrackingImpl
- java.lang.Object
-
- org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl
-
- All Implemented Interfaces:
Iterable<long[]>,PartitionUpdateCounter
public class PartitionUpdateCounterTrackingImpl extends Object implements PartitionUpdateCounter
Update counter implementation used for cache groups in persistent mode for both tx and atomic caches.Implements the partition update counter flow to avoid situations when:
- update counter could be incremented and persisted while corresponding update is not recorded to WAL.
- update counter could be updated out of order.
The main idea is to track updates received out-of-order to ensure valid state of the update counter for rebalancing.
Below a short description of new flow:
- Update counter is reserved for each update in partition on tx prepare phase (which always happens on primary partition owner). Reservation causes HWM increment.
- Reserved counter values are propagated on backup nodes and stored in backup transactions.
- On commit reserved counters are assigned to cache entries.
- LWM is incremented ONLY after corresponding WAL data record for each entry was written.
- In case of rollback (manual or during tx recovery on node failure) reserved updates are also applied and
logged to WAL using
RollbackRecordfor further recovery purposes.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanfirstprotected CacheGroupContextgrpprotected longinitCntrDeprecated.TODO FIXME https://issues.apache.org/jira/browse/IGNITE-11794protected AtomicLonglwmLWM.static intMAX_MISSED_UPDATESMax allowed missed updates.protected NavigableMap<Long,org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl.Item>queueQueue of applied out of order counter updates.protected AtomicLongreservedCntrReserved.
-
Constructor Summary
Constructors Constructor Description PartitionUpdateCounterTrackingImpl(CacheGroupContext grp)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ObjectcomparableState()CacheGroupContextcontext()PartitionUpdateCountercopy()protected PartitionUpdateCounterTrackingImplcreateInstance()booleanempty()booleanequals(Object o)GridLongListfinalizeUpdateCounters()Flushes pending update counters closing all possible gaps.longget()Get LWM.@org.jetbrains.annotations.Nullable byte[]getBytes()longhighestAppliedCounter()Returns highest applied update counter.voidinit(long initUpdCntr, @org.jetbrains.annotations.Nullable byte[] cntrUpdData)Restores update counter state.longinitial()Iterator<long[]>iterator()longnext()Increment LWM by 1.longnext(long delta)Increment LWM by delta.longreserve(long delta)Increment HWM by delta.longreserved()Returns HWM.voidreset()Reset counter internal state to zero.voidresetInitialCounter()Reset the initial counter value to zero.booleansequential()StringtoString()voidupdate(long val)Sets update counter to absolute value.booleanupdate(long start, long delta)Applies counter update out of range.voidupdateInitial(long start, long delta)-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
MAX_MISSED_UPDATES
public static final int MAX_MISSED_UPDATES
Max allowed missed updates. Overflow will trigger critical failure handler to prevent OOM.- See Also:
- Constant Field Values
-
queue
protected NavigableMap<Long,org.apache.ignite.internal.processors.cache.PartitionUpdateCounterTrackingImpl.Item> queue
Queue of applied out of order counter updates.
-
lwm
protected final AtomicLong lwm
LWM.
-
reservedCntr
protected final AtomicLong reservedCntr
Reserved.
-
first
protected boolean first
-
grp
protected final CacheGroupContext grp
-
initCntr
@Deprecated protected volatile long initCntr
Deprecated.TODO FIXME https://issues.apache.org/jira/browse/IGNITE-11794Initial counter points to last sequential update after WAL recovery.
-
-
Constructor Detail
-
PartitionUpdateCounterTrackingImpl
public PartitionUpdateCounterTrackingImpl(CacheGroupContext grp)
- Parameters:
grp- Group.
-
-
Method Detail
-
init
public void init(long initUpdCntr, @Nullable @org.jetbrains.annotations.Nullable byte[] cntrUpdData)Restores update counter state.- Specified by:
initin interfacePartitionUpdateCounter- Parameters:
initUpdCntr- LWM.cntrUpdData- Counter updates raw data.
-
initial
public long initial()
- Specified by:
initialin interfacePartitionUpdateCounter
-
get
public long get()
Get LWM.- Specified by:
getin interfacePartitionUpdateCounter- Returns:
- Current LWM.
-
highestAppliedCounter
public long highestAppliedCounter()
Returns highest applied update counter.- Specified by:
highestAppliedCounterin interfacePartitionUpdateCounter- Returns:
- Highest applied counter.
-
next
public long next()
Description copied from interface:PartitionUpdateCounterIncrement LWM by 1.- Specified by:
nextin interfacePartitionUpdateCounter- Returns:
- Next update counter. For tx mode called by
DataStreamerImplIsolatedUpdater.
-
update
public void update(long val) throws IgniteCheckedExceptionSets update counter to absolute value. All missed updates will be discarded.- Specified by:
updatein interfacePartitionUpdateCounter- Parameters:
val- Absolute value.- Throws:
IgniteCheckedException- if counter cannot be set to passed value due to incompatibility with current state.
-
update
public boolean update(long start, long delta)Applies counter update out of range. Update ranges must not intersect.- Specified by:
updatein interfacePartitionUpdateCounter- Parameters:
start- Start (<= lwm).delta- Delta.- Returns:
Trueif update was actually applied.
-
updateInitial
public void updateInitial(long start, long delta)- Specified by:
updateInitialin interfacePartitionUpdateCounter- Parameters:
start- Counter.delta- Delta.
-
finalizeUpdateCounters
public GridLongList finalizeUpdateCounters()
Flushes pending update counters closing all possible gaps.- Specified by:
finalizeUpdateCountersin interfacePartitionUpdateCounter- Returns:
- Even-length array of pairs [start, end] for each gap.
-
reserve
public long reserve(long delta)
Increment HWM by delta.- Specified by:
reservein interfacePartitionUpdateCounter- Parameters:
delta- Delta.- Returns:
- New HWM.
-
next
public long next(long delta)
Increment LWM by delta.- Specified by:
nextin interfacePartitionUpdateCounter- Parameters:
delta- Delta.- Returns:
- New LWM.
-
sequential
public boolean sequential()
- Specified by:
sequentialin interfacePartitionUpdateCounter- Returns:
Trueif counter has no missed updates.
-
getBytes
@Nullable public @org.jetbrains.annotations.Nullable byte[] getBytes()
- Specified by:
getBytesin interfacePartitionUpdateCounter
-
reset
public void reset()
Reset counter internal state to zero.- Specified by:
resetin interfacePartitionUpdateCounter
-
resetInitialCounter
public void resetInitialCounter()
Reset the initial counter value to zero.- Specified by:
resetInitialCounterin interfacePartitionUpdateCounter
-
reserved
public long reserved()
Returns HWM.- Specified by:
reservedin interfacePartitionUpdateCounter- Returns:
- Current HWM.
-
empty
public boolean empty()
- Specified by:
emptyin interfacePartitionUpdateCounter- Returns:
Trueif counter has not seen any update.
-
iterator
public Iterator<long[]> iterator()
- Specified by:
iteratorin interfaceIterable<long[]>- Specified by:
iteratorin interfacePartitionUpdateCounter- Returns:
- Iterator for pairs [start, range] for each out-of-order update in the update counter sequence.
-
comparableState
public Object comparableState()
- Specified by:
comparableStatein interfacePartitionUpdateCounter- Returns:
- Comparable counter state.
-
context
public CacheGroupContext context()
- Specified by:
contextin interfacePartitionUpdateCounter- Returns:
- Cache group context.
-
copy
public PartitionUpdateCounter copy()
- Specified by:
copyin interfacePartitionUpdateCounter- Returns:
- A deep copy of current instance.
-
createInstance
protected PartitionUpdateCounterTrackingImpl createInstance()
-
-