[ 
https://issues.apache.org/jira/browse/MRESOLVER-349?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17708788#comment-17708788
 ] 

ASF GitHub Bot commented on MRESOLVER-349:
------------------------------------------

cstamas commented on code in PR #276:
URL: https://github.com/apache/maven-resolver/pull/276#discussion_r1158294798


##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/NamedLockFactoryAdapter.java:
##########
@@ -130,47 +145,78 @@ private TimeUnit getTimeUnit(final 
RepositorySystemSession session) {
             return TimeUnit.valueOf(ConfigUtils.getString(session, 
DEFAULT_TIME_UNIT.name(), TIME_UNIT_KEY));
         }
 
+        private int getRetries(final RepositorySystemSession session) {
+            return ConfigUtils.getInteger(session, DEFAULT_RETRIES, 
RETRIES_KEY);
+        }
+
+        private long getRetrySleep(final RepositorySystemSession session) {
+            return ConfigUtils.getLong(session, DEFAULT_RETRY_SLEEP, 
RETRY_SLEEP_KEY);
+        }
+
         @Override
         public void acquire(Collection<? extends Artifact> artifacts, 
Collection<? extends Metadata> metadatas) {
             Collection<String> keys = lockNaming.nameLocks(session, artifacts, 
metadatas);
             if (keys.isEmpty()) {
                 return;
             }
 
-            LOGGER.trace("Need {} {} lock(s) for {}", keys.size(), shared ? 
"read" : "write", keys);
-            int acquiredLockCount = 0;
-            for (String key : keys) {
-                NamedLock namedLock = namedLockFactory.getLock(key);
-                try {
-                    LOGGER.trace("Acquiring {} lock for '{}'", shared ? "read" 
: "write", key);
-
-                    boolean locked;
-                    if (shared) {
-                        locked = namedLock.lockShared(time, timeUnit);
-                    } else {
-                        locked = namedLock.lockExclusively(time, timeUnit);
-                    }
-
-                    if (!locked) {
-                        LOGGER.trace("Failed to acquire {} lock for '{}'", 
shared ? "read" : "write", key);
-
-                        namedLock.close();
-                        throw new IllegalStateException("Could not acquire " + 
(shared ? "read" : "write")
-                                + " lock for '" + namedLock.name() + "'");
+            final ArrayList<IllegalStateException> illegalStateExceptions = 
new ArrayList<>();
+            for (int retry = 0; retry <= retries; retry++) {

Review Comment:
   attempt != retry. "2 retries" means "3 attemptes". "0 retries" means "1 
attempt" (like before). But agreed, will clear up variable names here.



##########
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/synccontext/named/NamedLockFactoryAdapter.java:
##########
@@ -130,47 +145,78 @@ private TimeUnit getTimeUnit(final 
RepositorySystemSession session) {
             return TimeUnit.valueOf(ConfigUtils.getString(session, 
DEFAULT_TIME_UNIT.name(), TIME_UNIT_KEY));
         }
 
+        private int getRetries(final RepositorySystemSession session) {
+            return ConfigUtils.getInteger(session, DEFAULT_RETRIES, 
RETRIES_KEY);
+        }
+
+        private long getRetrySleep(final RepositorySystemSession session) {
+            return ConfigUtils.getLong(session, DEFAULT_RETRY_SLEEP, 
RETRY_SLEEP_KEY);
+        }
+
         @Override
         public void acquire(Collection<? extends Artifact> artifacts, 
Collection<? extends Metadata> metadatas) {
             Collection<String> keys = lockNaming.nameLocks(session, artifacts, 
metadatas);
             if (keys.isEmpty()) {
                 return;
             }
 
-            LOGGER.trace("Need {} {} lock(s) for {}", keys.size(), shared ? 
"read" : "write", keys);
-            int acquiredLockCount = 0;
-            for (String key : keys) {
-                NamedLock namedLock = namedLockFactory.getLock(key);
-                try {
-                    LOGGER.trace("Acquiring {} lock for '{}'", shared ? "read" 
: "write", key);
-
-                    boolean locked;
-                    if (shared) {
-                        locked = namedLock.lockShared(time, timeUnit);
-                    } else {
-                        locked = namedLock.lockExclusively(time, timeUnit);
-                    }
-
-                    if (!locked) {
-                        LOGGER.trace("Failed to acquire {} lock for '{}'", 
shared ? "read" : "write", key);
-
-                        namedLock.close();
-                        throw new IllegalStateException("Could not acquire " + 
(shared ? "read" : "write")
-                                + " lock for '" + namedLock.name() + "'");
+            final ArrayList<IllegalStateException> illegalStateExceptions = 
new ArrayList<>();
+            for (int retry = 0; retry <= retries; retry++) {

Review Comment:
   attempt != retry. "2 retries" means "3 attempts". "0 retries" means "1 
attempt" (like before). But agreed, will clear up variable names here.





> Adapter when locking should "give up and retry"
> -----------------------------------------------
>
>                 Key: MRESOLVER-349
>                 URL: https://issues.apache.org/jira/browse/MRESOLVER-349
>             Project: Maven Resolver
>          Issue Type: Task
>          Components: Resolver
>    Affects Versions: 1.9.7
>            Reporter: Tamas Cservenak
>            Assignee: Tamas Cservenak
>            Priority: Major
>             Fix For: 1.9.8
>
>
> Somewhat in relation to MRESOLVER-346, but sync context (the named lock 
> adapter to be more specific) instead of holding as many it could locked so 
> far (and cause lock timeouts), should simply give up all and retry.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to