You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by "crudboy (via GitHub)" <gi...@apache.org> on 2024/02/28 11:03:38 UTC

[PR] [type: refactor] Admin distributed lock by spring-integration-jdbc [shenyu]

crudboy opened a new pull request, #5457:
URL: https://github.com/apache/shenyu/pull/5457

   <!-- Describe your PR here; e.g. Fixes #issueNo -->
   
   <!--
   Thank you for proposing a pull request. This template will guide you through the essential steps necessary for a pull request.
   -->
   Make sure that:
   
   - [x] You have read the [contribution guidelines](https://shenyu.apache.org/community/contributor-guide).
   - [x] You submit test cases (unit or integration tests) that back your changes.
   - [x] Your local test passed `./mvnw clean install -Dmaven.javadoc.skip=true`.
   
   About #5448 Task: Admin distributed lock by spring-integration-mysql 


-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [type: refactor] Admin distributed lock by spring-integration-jdbc [shenyu]

Posted by "crudboy (via GitHub)" <gi...@apache.org>.
crudboy commented on code in PR #5457:
URL: https://github.com/apache/shenyu/pull/5457#discussion_r1513828406


##########
shenyu-admin/src/test/java/org/apache/shenyu/admin/service/register/AbstractContextPathRegisterServiceTest.java:
##########
@@ -55,20 +58,56 @@ class AbstractContextPathRegisterServiceTest {
     private RuleServiceImpl ruleService;
 
     @Mock
-    private RegisterExecutionRepository registerExecutionRepository;
+    private LockRegistry registry;
 
     @Test
     public void testRegisterContextPath() {
         MetaDataRegisterDTO dto = MetaDataRegisterDTO.builder().build();
         dto.setContextPath("Context_Path");
         dto.setAddPrefixed(true);
-        RegisterExecutionLock registerExecutionLock = mock(RegisterExecutionLock.class);
         when(selectorService.registerDefault(dto, PluginEnum.CONTEXT_PATH.getName(), "")).thenReturn("Context_Path_Selector_Id");
-        when(registerExecutionRepository.getLock(any())).thenReturn(registerExecutionLock);
+        // org.springframework.integration.jdbc.lock.JdbcLockRegistry.JdbcLock is private and cannot be mocked directly so we mock the LockRegistry and return a mock MockLock
+        // here  mock ReentrantLock   cause cpu usage 100% in the jdk 19 20 21 environment
+        when(registry.obtain(any())).thenReturn(mock(MockLock.class));

Review Comment:
   i change this mock ReentrantLock   cause cpu usage 100% in the jdk 19 20 21 environment



-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [type: refactor] Admin distributed lock by spring-integration-jdbc [shenyu]

Posted by "crudboy (via GitHub)" <gi...@apache.org>.
crudboy commented on code in PR #5457:
URL: https://github.com/apache/shenyu/pull/5457#discussion_r1510763067


##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractContextPathRegisterService.java:
##########
@@ -17,37 +17,47 @@
 
 package org.apache.shenyu.admin.service.register;
 
-import org.apache.shenyu.admin.lock.RegisterExecutionLock;
-import org.apache.shenyu.admin.lock.RegisterExecutionRepository;
 import org.apache.shenyu.common.utils.PathUtils;
 import org.apache.shenyu.common.dto.convert.rule.impl.ContextMappingRuleHandle;
 import org.apache.shenyu.common.enums.PluginEnum;
 import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.integration.support.locks.LockRegistry;
+import java.util.concurrent.locks.Lock;
 import javax.annotation.Resource;
 import java.util.Objects;
 
 /**
  * The type Abstract context path register service.
  */
 public abstract class AbstractContextPathRegisterService extends AbstractShenyuClientRegisterServiceImpl {
+    private static final String LOCK_KEY_PREFIX = "context-path:";
+
+    private final Logger logger = LoggerFactory.getLogger(AbstractContextPathRegisterService.class);
 
     @Resource
-    private RegisterExecutionRepository registerExecutionRepository;
+    private LockRegistry registry;
 
     @Override
     public void registerContextPath(final MetaDataRegisterDTO dto) {
         String name = PluginEnum.CONTEXT_PATH.getName();
-        String contextPathSelectorId = getSelectorService().registerDefault(dto, name, "");
-        // avoid repeated registration for many client threads
-        // many client threads may register the same context path for contextPath plugin at the same time
-        RegisterExecutionLock lock = registerExecutionRepository.getLock(name);
+        String contextPath = PathUtils.decoratorContextPath(dto.getContextPath());
+        String key = LOCK_KEY_PREFIX + contextPath;
+        Lock lock = registry.obtain(key);
+        if (logger.isDebugEnabled()) {
+            logger.debug("register context-path obtain lock for key:{}", key);
+        }
         lock.lock();
         try {
+            String contextPathSelectorId = getSelectorService().registerDefault(dto, name, "");
+            // avoid repeated registration for many client threads
+            // many client threads may register the same context path for contextPath plugin at the same time
             if (Objects.nonNull(getRuleService().findBySelectorIdAndName(contextPathSelectorId, dto.getContextPath()))) {
                 return;
             }
             ContextMappingRuleHandle handle = new ContextMappingRuleHandle();
-            handle.setContextPath(PathUtils.decoratorContextPath(dto.getContextPath()));
+            handle.setContextPath(contextPath);

Review Comment:
   I didn't change contextPath.  use contextPath in  registry#obtain method parameters. 
   ```java
           String contextPath = PathUtils.decoratorContextPath(dto.getContextPath());
           String key = LOCK_KEY_PREFIX + contextPath;
           Lock lock = registry.obtain(key);
          .....
          handle.setContextPath(contextPath);
   ```



-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [type: refactor] Admin distributed lock by spring-integration-jdbc [shenyu]

Posted by "moremind (via GitHub)" <gi...@apache.org>.
moremind commented on PR #5457:
URL: https://github.com/apache/shenyu/pull/5457#issuecomment-1976043926

   LGTM


-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [type: refactor] Admin distributed lock by spring-integration-jdbc [shenyu]

Posted by "yunlongn (via GitHub)" <gi...@apache.org>.
yunlongn merged PR #5457:
URL: https://github.com/apache/shenyu/pull/5457


-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [type: refactor] Admin distributed lock by spring-integration-jdbc [shenyu]

Posted by "moremind (via GitHub)" <gi...@apache.org>.
moremind commented on PR #5457:
URL: https://github.com/apache/shenyu/pull/5457#issuecomment-1970497421

   pls add a table for all SQL


-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [type: refactor] Admin distributed lock by spring-integration-jdbc [shenyu]

Posted by "moremind (via GitHub)" <gi...@apache.org>.
moremind commented on PR #5457:
URL: https://github.com/apache/shenyu/pull/5457#issuecomment-1978544200

   LGTM


-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [type: refactor] Admin distributed lock by spring-integration-jdbc [shenyu]

Posted by "crudboy (via GitHub)" <gi...@apache.org>.
crudboy commented on PR #5457:
URL: https://github.com/apache/shenyu/pull/5457#issuecomment-1980100811

   @moremind Excuse me. Could you please reapproving ?  i  fix ci


-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [type: refactor] Admin distributed lock by spring-integration-jdbc [shenyu]

Posted by "crudboy (via GitHub)" <gi...@apache.org>.
crudboy commented on PR #5457:
URL: https://github.com/apache/shenyu/pull/5457#issuecomment-1972281186

   It seems that some files do not support jkd19,20,21?


-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [type: refactor] Admin distributed lock by spring-integration-jdbc [shenyu]

Posted by "moremind (via GitHub)" <gi...@apache.org>.
moremind commented on code in PR #5457:
URL: https://github.com/apache/shenyu/pull/5457#discussion_r1510745436


##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractContextPathRegisterService.java:
##########
@@ -17,37 +17,47 @@
 
 package org.apache.shenyu.admin.service.register;
 
-import org.apache.shenyu.admin.lock.RegisterExecutionLock;
-import org.apache.shenyu.admin.lock.RegisterExecutionRepository;
 import org.apache.shenyu.common.utils.PathUtils;
 import org.apache.shenyu.common.dto.convert.rule.impl.ContextMappingRuleHandle;
 import org.apache.shenyu.common.enums.PluginEnum;
 import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.integration.support.locks.LockRegistry;
+import java.util.concurrent.locks.Lock;
 import javax.annotation.Resource;
 import java.util.Objects;
 
 /**
  * The type Abstract context path register service.
  */
 public abstract class AbstractContextPathRegisterService extends AbstractShenyuClientRegisterServiceImpl {
+    private static final String LOCK_KEY_PREFIX = "context-path:";
+
+    private final Logger logger = LoggerFactory.getLogger(AbstractContextPathRegisterService.class);
 
     @Resource
-    private RegisterExecutionRepository registerExecutionRepository;
+    private LockRegistry registry;
 
     @Override
     public void registerContextPath(final MetaDataRegisterDTO dto) {
         String name = PluginEnum.CONTEXT_PATH.getName();
-        String contextPathSelectorId = getSelectorService().registerDefault(dto, name, "");
-        // avoid repeated registration for many client threads
-        // many client threads may register the same context path for contextPath plugin at the same time
-        RegisterExecutionLock lock = registerExecutionRepository.getLock(name);
+        String contextPath = PathUtils.decoratorContextPath(dto.getContextPath());
+        String key = LOCK_KEY_PREFIX + contextPath;
+        Lock lock = registry.obtain(key);
+        if (logger.isDebugEnabled()) {
+            logger.debug("register context-path obtain lock for key:{}", key);
+        }
         lock.lock();
         try {
+            String contextPathSelectorId = getSelectorService().registerDefault(dto, name, "");
+            // avoid repeated registration for many client threads
+            // many client threads may register the same context path for contextPath plugin at the same time
             if (Objects.nonNull(getRuleService().findBySelectorIdAndName(contextPathSelectorId, dto.getContextPath()))) {
                 return;
             }
             ContextMappingRuleHandle handle = new ContextMappingRuleHandle();
-            handle.setContextPath(PathUtils.decoratorContextPath(dto.getContextPath()));
+            handle.setContextPath(contextPath);

Review Comment:
   why change this?



-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [type: refactor] Admin distributed lock by spring-integration-jdbc [shenyu]

Posted by "moremind (via GitHub)" <gi...@apache.org>.
moremind commented on code in PR #5457:
URL: https://github.com/apache/shenyu/pull/5457#discussion_r1510797145


##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractContextPathRegisterService.java:
##########
@@ -17,37 +17,47 @@
 
 package org.apache.shenyu.admin.service.register;
 
-import org.apache.shenyu.admin.lock.RegisterExecutionLock;
-import org.apache.shenyu.admin.lock.RegisterExecutionRepository;
 import org.apache.shenyu.common.utils.PathUtils;
 import org.apache.shenyu.common.dto.convert.rule.impl.ContextMappingRuleHandle;
 import org.apache.shenyu.common.enums.PluginEnum;
 import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.integration.support.locks.LockRegistry;
+import java.util.concurrent.locks.Lock;
 import javax.annotation.Resource;
 import java.util.Objects;
 
 /**
  * The type Abstract context path register service.
  */
 public abstract class AbstractContextPathRegisterService extends AbstractShenyuClientRegisterServiceImpl {
+    private static final String LOCK_KEY_PREFIX = "context-path:";
+
+    private final Logger logger = LoggerFactory.getLogger(AbstractContextPathRegisterService.class);
 
     @Resource
-    private RegisterExecutionRepository registerExecutionRepository;
+    private LockRegistry registry;
 
     @Override
     public void registerContextPath(final MetaDataRegisterDTO dto) {
         String name = PluginEnum.CONTEXT_PATH.getName();
-        String contextPathSelectorId = getSelectorService().registerDefault(dto, name, "");
-        // avoid repeated registration for many client threads
-        // many client threads may register the same context path for contextPath plugin at the same time
-        RegisterExecutionLock lock = registerExecutionRepository.getLock(name);
+        String contextPath = PathUtils.decoratorContextPath(dto.getContextPath());
+        String key = LOCK_KEY_PREFIX + contextPath;
+        Lock lock = registry.obtain(key);
+        if (logger.isDebugEnabled()) {
+            logger.debug("register context-path obtain lock for key:{}", key);
+        }
         lock.lock();

Review Comment:
   put it in try



-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [type: refactor] Admin distributed lock by spring-integration-jdbc [shenyu]

Posted by "crudboy (via GitHub)" <gi...@apache.org>.
crudboy commented on PR #5457:
URL: https://github.com/apache/shenyu/pull/5457#issuecomment-1975498488

   @moremind Could you please take a look  and tell if there any changes needed or any mistakes I need to fix?


-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [type: refactor] Admin distributed lock by spring-integration-jdbc [shenyu]

Posted by "crudboy (via GitHub)" <gi...@apache.org>.
crudboy commented on PR #5457:
URL: https://github.com/apache/shenyu/pull/5457#issuecomment-1972279708

   Doesn't seem to support jkd19,20.21?


-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [type: refactor] Admin distributed lock by spring-integration-jdbc [shenyu]

Posted by "crudboy (via GitHub)" <gi...@apache.org>.
crudboy commented on code in PR #5457:
URL: https://github.com/apache/shenyu/pull/5457#discussion_r1510845661


##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractContextPathRegisterService.java:
##########
@@ -17,37 +17,47 @@
 
 package org.apache.shenyu.admin.service.register;
 
-import org.apache.shenyu.admin.lock.RegisterExecutionLock;
-import org.apache.shenyu.admin.lock.RegisterExecutionRepository;
 import org.apache.shenyu.common.utils.PathUtils;
 import org.apache.shenyu.common.dto.convert.rule.impl.ContextMappingRuleHandle;
 import org.apache.shenyu.common.enums.PluginEnum;
 import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.integration.support.locks.LockRegistry;
+import java.util.concurrent.locks.Lock;
 import javax.annotation.Resource;
 import java.util.Objects;
 
 /**
  * The type Abstract context path register service.
  */
 public abstract class AbstractContextPathRegisterService extends AbstractShenyuClientRegisterServiceImpl {
+    private static final String LOCK_KEY_PREFIX = "context-path:";
+
+    private final Logger logger = LoggerFactory.getLogger(AbstractContextPathRegisterService.class);
 
     @Resource
-    private RegisterExecutionRepository registerExecutionRepository;
+    private LockRegistry registry;
 
     @Override
     public void registerContextPath(final MetaDataRegisterDTO dto) {
         String name = PluginEnum.CONTEXT_PATH.getName();
-        String contextPathSelectorId = getSelectorService().registerDefault(dto, name, "");
-        // avoid repeated registration for many client threads
-        // many client threads may register the same context path for contextPath plugin at the same time
-        RegisterExecutionLock lock = registerExecutionRepository.getLock(name);
+        String contextPath = PathUtils.decoratorContextPath(dto.getContextPath());
+        String key = LOCK_KEY_PREFIX + contextPath;
+        Lock lock = registry.obtain(key);
+        if (logger.isDebugEnabled()) {
+            logger.debug("register context-path obtain lock for key:{}", key);
+        }
         lock.lock();

Review Comment:
   change lock.lock() put it in try



-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [type: refactor] Admin distributed lock by spring-integration-jdbc [shenyu]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #5457:
URL: https://github.com/apache/shenyu/pull/5457#issuecomment-1969030829

   ## [Codecov](https://app.codecov.io/gh/apache/shenyu/pull/5457?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   Attention: Patch coverage is `80.00000%` with `2 lines` in your changes are missing coverage. Please review.
   > Project coverage is 60.89%. Comparing base [(`d6aabd0`)](https://app.codecov.io/gh/apache/shenyu/commit/d6aabd0932b512a0c029c44891b8b986e342a18c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`e68b77c`)](https://app.codecov.io/gh/apache/shenyu/pull/5457?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   
   | [Files](https://app.codecov.io/gh/apache/shenyu/pull/5457?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...e/register/AbstractContextPathRegisterService.java](https://app.codecov.io/gh/apache/shenyu/pull/5457?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c2hlbnl1LWFkbWluL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGVueXUvYWRtaW4vc2VydmljZS9yZWdpc3Rlci9BYnN0cmFjdENvbnRleHRQYXRoUmVnaXN0ZXJTZXJ2aWNlLmphdmE=) | 75.00% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/shenyu/pull/5457?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   
   <details><summary>Additional details and impacted files</summary>
   
   
   ```diff
   @@            Coverage Diff            @@
   ##             master    #5457   +/-   ##
   =========================================
     Coverage     60.88%   60.89%           
   - Complexity     8635     8636    +1     
   =========================================
     Files          1263     1263           
     Lines         38544    38551    +7     
     Branches       3679     3680    +1     
   =========================================
   + Hits          23468    23474    +6     
   - Misses        12959    12960    +1     
     Partials       2117     2117           
   ```
   
   
   
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/shenyu/pull/5457?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   


-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [type: refactor] Admin distributed lock by spring-integration-jdbc [shenyu]

Posted by "crudboy (via GitHub)" <gi...@apache.org>.
crudboy commented on code in PR #5457:
URL: https://github.com/apache/shenyu/pull/5457#discussion_r1510763067


##########
shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractContextPathRegisterService.java:
##########
@@ -17,37 +17,47 @@
 
 package org.apache.shenyu.admin.service.register;
 
-import org.apache.shenyu.admin.lock.RegisterExecutionLock;
-import org.apache.shenyu.admin.lock.RegisterExecutionRepository;
 import org.apache.shenyu.common.utils.PathUtils;
 import org.apache.shenyu.common.dto.convert.rule.impl.ContextMappingRuleHandle;
 import org.apache.shenyu.common.enums.PluginEnum;
 import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.integration.support.locks.LockRegistry;
+import java.util.concurrent.locks.Lock;
 import javax.annotation.Resource;
 import java.util.Objects;
 
 /**
  * The type Abstract context path register service.
  */
 public abstract class AbstractContextPathRegisterService extends AbstractShenyuClientRegisterServiceImpl {
+    private static final String LOCK_KEY_PREFIX = "context-path:";
+
+    private final Logger logger = LoggerFactory.getLogger(AbstractContextPathRegisterService.class);
 
     @Resource
-    private RegisterExecutionRepository registerExecutionRepository;
+    private LockRegistry registry;
 
     @Override
     public void registerContextPath(final MetaDataRegisterDTO dto) {
         String name = PluginEnum.CONTEXT_PATH.getName();
-        String contextPathSelectorId = getSelectorService().registerDefault(dto, name, "");
-        // avoid repeated registration for many client threads
-        // many client threads may register the same context path for contextPath plugin at the same time
-        RegisterExecutionLock lock = registerExecutionRepository.getLock(name);
+        String contextPath = PathUtils.decoratorContextPath(dto.getContextPath());
+        String key = LOCK_KEY_PREFIX + contextPath;
+        Lock lock = registry.obtain(key);
+        if (logger.isDebugEnabled()) {
+            logger.debug("register context-path obtain lock for key:{}", key);
+        }
         lock.lock();
         try {
+            String contextPathSelectorId = getSelectorService().registerDefault(dto, name, "");
+            // avoid repeated registration for many client threads
+            // many client threads may register the same context path for contextPath plugin at the same time
             if (Objects.nonNull(getRuleService().findBySelectorIdAndName(contextPathSelectorId, dto.getContextPath()))) {
                 return;
             }
             ContextMappingRuleHandle handle = new ContextMappingRuleHandle();
-            handle.setContextPath(PathUtils.decoratorContextPath(dto.getContextPath()));
+            handle.setContextPath(contextPath);

Review Comment:
   @moremind  I didn't change contextPath.  use contextPath in  registry#obtain method parameters. 
   ```java
           String contextPath = PathUtils.decoratorContextPath(dto.getContextPath());
           String key = LOCK_KEY_PREFIX + contextPath;
           Lock lock = registry.obtain(key);
          .....
          handle.setContextPath(contextPath);
   ```



-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [type: refactor] Admin distributed lock by spring-integration-jdbc [shenyu]

Posted by "crudboy (via GitHub)" <gi...@apache.org>.
crudboy commented on PR #5457:
URL: https://github.com/apache/shenyu/pull/5457#issuecomment-1980113402

    i change this file [AbstractContextPathRegisterServiceTest](https://github.com/apache/shenyu/pull/5457/files#r1513828406)


-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [type: refactor] Admin distributed lock by spring-integration-jdbc [shenyu]

Posted by "moremind (via GitHub)" <gi...@apache.org>.
moremind commented on PR #5457:
URL: https://github.com/apache/shenyu/pull/5457#issuecomment-1980212137

   > @moremind Could you please take a look  and tell if there any changes needed or any mistakes I need to fix?
   
   no


-- 
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: notifications-unsubscribe@shenyu.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org