mattisonchao commented on code in PR #17700:
URL: https://github.com/apache/pulsar/pull/17700#discussion_r973835719


##########
pulsar-metadata/src/test/java/org/apache/pulsar/metadata/LockManagerTest.java:
##########
@@ -293,4 +296,55 @@ public void revalidateLockOnDifferentSession(String 
provider, Supplier<String> u
             assertEquals(new 
String(store1.get(path2).join().get().getValue()), "\"value-1\"");
         });
     }
+
+    @Test(dataProvider = "impl")
+    public void testCleanUpStateWhenRevalidationGotLockBusy(String provider, 
Supplier<String> urlSupplier)
+            throws Exception {
+
+        if (provider.equals("Memory") || provider.equals("RocksDB")) {
+            // Local memory provider doesn't really have the concept of 
multiple sessions
+            return;
+        }
+
+        @Cleanup
+        MetadataStoreExtended store1 = 
MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
+        @Cleanup
+        MetadataStoreExtended store2 = 
MetadataStoreExtended.create(urlSupplier.get(),
+                MetadataStoreConfig.builder().build());
+
+        @Cleanup
+        CoordinationService cs1 = new CoordinationServiceImpl(store1);
+        @Cleanup
+        LockManager<String> lm1 = cs1.getLockManager(String.class);
+
+        @Cleanup
+        CoordinationService cs2 = new CoordinationServiceImpl(store2);
+        @Cleanup
+        LockManager<String> lm2 = cs2.getLockManager(String.class);
+
+        String path1 = newKey();
+
+        ResourceLock<String> lock1 = lm1.acquireLock(path1, "value-1").join();
+        AtomicReference<ResourceLock<String>> lock2 = new AtomicReference<>();
+        // lock 2 will steal the distributed lock first.

Review Comment:
   When I am writing this test, I found an interesting thing. We can allow the 
new lock to steal the existing lock that may hold by others(same value). 
   I'm not sure if it's a big problem. You can use this test to verify this 
behaviour.
   
   Plus, steal lock behaviour may cause an infinity loop when they use the same 
value or a different value in the same session. the details please see 
`ResourceLockImpl#doRevalidate`
   
   
https://github.com/apache/pulsar/blob/69f3f7471fa6faf24d4776d65e0509538c105d37/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/coordination/impl/ResourceLockImpl.java#L239-L310
   
   Case:
   - lock 1 holds the lock with value `value-1`.
   - lock 2 tries to acquire the lock with value `value-1` got the 
`LockBusyException` then invoked `revalidate` to steal the lock. (delete and 
re-create it)
   - lock 1 receives the delete notification **after lock 2 already acquires 
the lock**. then lock1 tries to invoke `revalidate` to steal the lock again.
   - Under this assumption, we're going to fall into an infinite loop.
   
   This is a theoretical assumption because the situation is more difficult to 
simulate. Please take a look, I'm not sure if I missing something.



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