...
A partition update counter has the following structure:
Code Block |
---|
|
/** Low watermark. */ |
...
private final AtomicLong cntr = new AtomicLong(); |
Low watermark or update counter is used to track sequential updates. It is only incremented when the corresponding update is recorded to a durable storage, and no missed updates exist with lesser counter value.
For example, LWM value=5 means what all updates with assigned counters 1, 2, 3, 4, 5 were applied to WAL.
Code Block |
---|
|
/** High watermark. */ |
...
private final AtomicLong reserveCntr = new AtomicLong(); |
High watermark or reservation counter is incremented for each pending update, which even not guaranteed to succeed. Reservation counter is assigned during tx prepare phase.
Code Block |
---|
|
/** Updates applied out of order. */ |
...
private SortedSet<Range> seq = new TreeSet<>(); |
This field is used for recording the updates that are applied out of order. This is possible because updates with higher counter could be applied to WAL before updates with lower counter, causing gaps in the update sequence.
...
* Update counter task. Update from start value by delta value. |
...
...
private static class Range implements Comparable<Range> { |
...
...
...
...
...
...
@Override public int compareTo(@NotNull Range r) { |
...
return Long.compare(this.start, r.start); |
...
...
A range represents a sequence of updates, for example (5, 3) means three updates with number 6, 7, 8. We will use this notation again later.
...
F(k1) = F(k2) = F(k3) = F(k4) = F(k5) = s1(Primary), s2(Backup1), s3(Backup2)Backup2)
Code Block |
---|
|
Ignite client = startClient(); |
...
IgniteCache<Integer, Integer> cache = client.cache(name); |
Thread 1:
Code Block |
---|
|
try(Transaction tx1 = client.transactions().txStart()) { |
...
cache.putAll(Map.of(k1, v1, k2, v2, k3, v3)); |
...
...
Thread 2:
Code Block |
---|
|
try(Transaction tx2 = client.transactions().txStart()) { |
...
cache.putAll(Map.of(k4, v4, k5, v4); |
...
...
Figure1 below shows the flow with the case of backup reordering, where tx with higher update counters is applied before the transaction with lower update counters on backup.
...