codelipenghui commented on code in PR #21248:
URL: https://github.com/apache/pulsar/pull/21248#discussion_r1337077079
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java:
##########
@@ -3633,12 +3633,19 @@ public boolean isValidPosition(PositionImpl position) {
log.debug("IsValid position: {} -- last: {}", position, last);
}
- if (position.getEntryId() < 0) {
+ if (!ledgers.containsKey(position.getLedgerId())){
Review Comment:
Do we need to add a test for covering this branch?
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java:
##########
@@ -3633,12 +3633,19 @@ public boolean isValidPosition(PositionImpl position) {
log.debug("IsValid position: {} -- last: {}", position, last);
}
- if (position.getEntryId() < 0) {
+ if (!ledgers.containsKey(position.getLedgerId())){
return false;
- } else if (position.getLedgerId() > last.getLedgerId()) {
+ } else if (position.getEntryId() < 0) {
return false;
+ } else if (position.getLedgerId() > last.getLedgerId() &&
position.getLedgerId() != currentLedger.getId()) {
+ return false;
Review Comment:
We shouldn't allow users to set to a position that after the last add
confirmed entry. Because the add operation might get failed if the message not
able to write to bookies.
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java:
##########
@@ -3633,12 +3633,19 @@ public boolean isValidPosition(PositionImpl position) {
log.debug("IsValid position: {} -- last: {}", position, last);
}
- if (position.getEntryId() < 0) {
+ if (!ledgers.containsKey(position.getLedgerId())){
return false;
- } else if (position.getLedgerId() > last.getLedgerId()) {
+ } else if (position.getEntryId() < 0) {
return false;
+ } else if (position.getLedgerId() > last.getLedgerId() &&
position.getLedgerId() != currentLedger.getId()) {
+ return false;
+ } else if (position.getLedgerId() == currentLedger.getId()) {
+ return position.getEntryId() <= currentLedgerEntries;
+ } else if (position.getLedgerId() == currentLedger.getId()) {
+ return position.getEntryId() <= currentLedgerEntries;
} else if (position.getLedgerId() == last.getLedgerId()) {
- return position.getEntryId() <= (last.getEntryId() + 1);
+ // Only last ledger can set entry id larger than the last entry.
+ return position.getEntryId() <= last.getEntryId();
Review Comment:
Interesting. Not sure why used `+1` before.
##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedLedgerImpl.java:
##########
@@ -3633,12 +3633,19 @@ public boolean isValidPosition(PositionImpl position) {
log.debug("IsValid position: {} -- last: {}", position, last);
}
- if (position.getEntryId() < 0) {
+ if (!ledgers.containsKey(position.getLedgerId())){
return false;
- } else if (position.getLedgerId() > last.getLedgerId()) {
+ } else if (position.getEntryId() < 0) {
return false;
+ } else if (position.getLedgerId() > last.getLedgerId() &&
position.getLedgerId() != currentLedger.getId()) {
+ return false;
+ } else if (position.getLedgerId() == currentLedger.getId()) {
+ return position.getEntryId() <= currentLedgerEntries;
+ } else if (position.getLedgerId() == currentLedger.getId()) {
+ return position.getEntryId() <= currentLedgerEntries;
Review Comment:
Are they duplicated?
Same comment as the above one. Any position greater than the last added
confirmed entry should be an invalid position.
--
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]