rdhabalia commented on a change in pull request #5604: [pulsar-broker] recover 
zk-badversion while updating cursor metadata
URL: https://github.com/apache/pulsar/pull/5604#discussion_r346036936
 
 

 ##########
 File path: 
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java
 ##########
 @@ -2033,6 +2033,30 @@ public void operationComplete(Void result, Stat stat) {
 
                     @Override
                     public void operationFailed(MetaStoreException e) {
+                        if (e instanceof 
MetaStoreException.BadVersionException) {
+                            log.warn("[{}] Failed to update cursor metadata 
for {} due to version conflict {}",
+                                    ledger.name, name, e.getMessage());
+                            // it means previous owner of the ml might have 
updated the version incorrectly. So, check
+                            // the ownership and refresh the version again.
+                            if (ledger.mlOwnershipChecker != null && 
ledger.mlOwnershipChecker.get()) {
+                                
ledger.getStore().asyncGetCursorInfo(ledger.getName(), name,
+                                        new 
MetaStoreCallback<ManagedCursorInfo>() {
+                                            @Override
+                                            public void 
operationComplete(ManagedCursorInfo info, Stat stat) {
+                                                cursorLedgerStat = stat;
 
 Review comment:
   Yes, I have thought about it earlier but it will be tricky because of race 
condition:
    if we retry the same function `persistPositionMetaStore` or any other 
functions with same metadata then by that time markDelete position could have 
been changed. also, metadata contains multiple info eg: ledgerId, 
markDelete-position and its properties, etc.. and cursor only maintains latest 
markDeletePosition in memory.. so, it's tricky to update metadata with all 
latest information in a synchronized manner. So, broker can rely on next acked 
message as this exception occurs rarely. 

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to