Shekharrajak commented on code in PR #22572:
URL: https://github.com/apache/kafka/pull/22572#discussion_r3412538692
##########
share-coordinator/src/main/java/org/apache/kafka/coordinator/share/PersisterStateBatchCombiner.java:
##########
@@ -20,385 +20,170 @@
import org.apache.kafka.server.share.persister.PersisterStateBatch;
import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.Comparator;
import java.util.List;
-import java.util.Objects;
-import java.util.TreeSet;
+import java.util.TreeMap;
+/**
+ * Combines an existing list of {@link PersisterStateBatch} entries with a
list of newly produced
+ * entries and returns the shortest non-overlapping, {@code (deliveryState,
deliveryCount)}-distinct
+ * cover of the union, clipped at {@code startOffset} (SPSO).
+ *
+ * <p>The merge is performed by an event-driven sweep-line over the union of
both inputs. Each
+ * input batch contributes one BEGIN event at {@code firstOffset} and one END
event at
+ * {@code lastOffset + 1}. Events are processed in offset order (END before
BEGIN at the same
+ * offset). A counted ordered map tracks the currently active priorities; the
first key defines the
+ * {@code (state, count)} that wins on the current sub-range. Successive
sub-ranges with identical
+ * {@code (state, count)} are coalesced on the fly.
+ *
+ * <p>Complexity: {@code O((n + k) log p)} where {@code n} is the total number
of input batches,
+ * {@code k} is the number of overlap transitions encountered, and {@code p}
is the number of
+ * distinct {@code (deliveryState, deliveryCount)} priorities.
+ */
public class PersisterStateBatchCombiner {
- private List<PersisterStateBatch> combinedBatchList; // link between
pruning and merging
+ private static final Comparator<BatchPriority> PRIORITY_DESC = (a, b) -> {
+ int cmpCount = Short.compare(b.deliveryCount(), a.deliveryCount());
Review Comment:
State
0 = AVAILABLE
1 = ACQUIRED
2 = ACKNOWLEDGED
3 = ARCHIVING
4 = ARCHIVED
---
existing: (100,110,state0,count1)
new:
(101,105,state1,count2)
(101,115,state2,count2)
(101,120,state3,count2)
result:
(100,100,state0,count1)
(101,120,state3,count2)
Meaning: all new ranges have higher count 2, and among them state 3 wins
over state 2 and 1.
---
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]