coderzc commented on code in PR #17164:
URL: https://github.com/apache/pulsar/pull/17164#discussion_r972618141


##########
managed-ledger/src/main/java/org/apache/bookkeeper/mledger/impl/ManagedCursorImpl.java:
##########
@@ -350,21 +356,48 @@ public void operationComplete(Void result, Stat stat) {
                     public void operationFailed(MetaStoreException e) {
                         log.error("[{}] Error while updating ledger cursor: {} 
properties {}", ledger.getName(),
                                 name, cursorProperties, e);
-                        updateCursorPropertiesResult.completeExceptionally(e);
+                        // if resource is updated by other operate then we 
will get bad-version exception
+                        // so, retry the operation.
+                        if (e instanceof 
ManagedLedgerException.BadVersionException) {
+                            
asyncReadAndUpdateCursorProperties(updateFunction).whenComplete((__, ex) -> {

Review Comment:
   > If we only retry put/remove here, I think it should be ok. It looks like 
we can introduce a new API in the feature to support compute operation for 
cursor properties. If we have a set operation, it will overwrite the whole 
cursor properties, the incoming properties maybe just a new version based on 
the old one. The retry will mess up the properties.
   
   I agree this, I think we can use 
`computeCursorProperties(Function<Map<String, String>, Map<String, String>> 
updateFunction)` instead of `setCursorProperties(Map<String, String> 
cursorProperties)`.
   
   > As @Jason918 said, it's a concurrency issue. If we have an internal retry, 
the callers need to guarantee the concurrent behavior. If we don't have an 
internal retry, the callers need to handle the update conflict. In my opinion, 
the former is more challenging than the latter
   
   It looks like giving the callers handle the update conflict is better. Can 
we add a parameter to choose whether need to automatically retry?



-- 
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]

Reply via email to