lhotari commented on code in PR #24938:
URL: https://github.com/apache/pulsar/pull/24938#discussion_r2517541713
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java:
##########
@@ -1453,6 +1453,23 @@ public Position getFirstPosition() {
return firstLedgerId == null ? null :
PositionFactory.create(firstLedgerId, 0);
}
+ /**
+ * Compare two positions. It is different with {@link
Position#compareTo(Position)} when the params are invalid.
+ * For example: position-1 is "1:{latest entry}", and position-2 is "2:0",
they are the same position.
+ */
+ private int comparePositions(Position pos1, Position pos2) {
+ if (pos1 == null || pos2 == null) {
+ throw new IllegalArgumentException("Positions must not be null");
+ }
+ if (pos1.getLedgerId() == pos2.getLedgerId() && pos1.getEntryId() ==
pos2.getEntryId()) {
+ return 0;
+ }
+ if (!ledger.isValidPosition(pos1) || !ledger.isValidPosition(pos2)) {
+ return
ledger.getNextValidPosition(pos1).compareTo(ledger.getNextValidPosition(pos2));
+ }
Review Comment:
```suggestion
boolean isPos1Valid = ledger.isValidPosition(pos1);
boolean isPos2Valid = ledger.isValidPosition(pos2);
if (!isPos1Valid && !isPos2Valid) {
return
ledger.getNextValidPosition(pos1).compareTo(ledger.getNextValidPosition(pos2));
} else if (!isPos1Valid) {
return ledger.getNextValidPosition(pos1).compareTo(pos2);
} else if (!isPos2Valid) {
return pos1.compareTo(ledger.getNextValidPosition(pos2));
}
```
@poorbarcode this is what I mean with my previous comment.
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java:
##########
@@ -1453,6 +1453,23 @@ public Position getFirstPosition() {
return firstLedgerId == null ? null :
PositionFactory.create(firstLedgerId, 0);
}
+ /**
+ * Compare two positions. It is different with {@link
Position#compareTo(Position)} when the params are invalid.
+ * For example: position-1 is "1:{latest entry}", and position-2 is "2:0",
they are the same position.
+ */
+ private int comparePositions(Position pos1, Position pos2) {
+ if (pos1 == null || pos2 == null) {
+ throw new IllegalArgumentException("Positions must not be null");
+ }
+ if (pos1.getLedgerId() == pos2.getLedgerId() && pos1.getEntryId() ==
pos2.getEntryId()) {
+ return 0;
+ }
+ if (!ledger.isValidPosition(pos1) || !ledger.isValidPosition(pos2)) {
+ return
ledger.getNextValidPosition(pos1).compareTo(ledger.getNextValidPosition(pos2));
+ }
Review Comment:
> I can not fully understand the comment, could you write a demo code?
Please see https://github.com/apache/pulsar/pull/24938/files#r2517541713
--
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]