You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2021/05/04 07:27:16 UTC

[james-project] branch master updated (71ecf36 -> f93cdfc)

This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git.


    from 71ecf36  [DOCUMENTATION] Update document - Manage James via the Command Line
     new f9f3b22  JAMES-3467 Avoid loading all domains for auto-detection when auto-detection is off
     new 793d39f  JAMES-3467 Domain cache should include auto-detection
     new f93cdfc  JAMES-3467 Domain cache should be refreshed periodically under read load

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../domainlist/cassandra/CacheDomainListTest.java  | 28 ++++++++++++++++++----
 .../james/domainlist/lib/AbstractDomainList.java   | 16 +++++++++----
 .../impl/JamesMailetContextTest.java               |  4 ++--
 3 files changed, 37 insertions(+), 11 deletions(-)

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[james-project] 02/03: JAMES-3467 Domain cache should include auto-detection

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 793d39f4c94838e8427e233415b98f415e1335af
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon Apr 26 22:38:53 2021 +0700

    JAMES-3467 Domain cache should include auto-detection
    
    This allows fully relying on the cache for remote addresses, that previously
    would have been attempting auto-detection all of the time.
---
 .../java/org/apache/james/domainlist/lib/AbstractDomainList.java     | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java b/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java
index 2a19598..9f371eb 100644
--- a/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java
+++ b/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java
@@ -97,7 +97,7 @@ public abstract class AbstractDomainList implements DomainList, Configurable {
             .build(new CacheLoader<>() {
                 @Override
                 public Boolean load(Domain key) throws DomainListException {
-                    return containsDomainInternal(key);
+                    return containsDomainInternal(key) || detectedDomainsContains(key);
                 }
             });
 
@@ -169,8 +169,7 @@ public abstract class AbstractDomainList implements DomainList, Configurable {
     public boolean containsDomain(Domain domain) throws DomainListException {
         if (configuration.isCacheEnabled()) {
             try {
-                boolean internalAnswer = cache.get(domain);
-                return internalAnswer || detectedDomainsContains(domain);
+                return cache.get(domain);
             } catch (ExecutionException e) {
                 if (e.getCause() instanceof DomainListException) {
                     throw (DomainListException) e.getCause();

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[james-project] 01/03: JAMES-3467 Avoid loading all domains for auto-detection when auto-detection is off

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit f9f3b2232da0d4bcaabbc5df43ad59d4d8bc2f4d
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon Apr 26 22:38:11 2021 +0700

    JAMES-3467 Avoid loading all domains for auto-detection when auto-detection is off
    
    AbstractDomainList::getDomainsWithType provides DomainType.Internal covered by the containsDomainInternal method,
    DomainType.DefaultDomain whih is always added internally upon configure,
    DomainType.Detected only added if autoDetect is true and DomainType.DetectedIp if autoDetectIp is true.
    
    Given that default domain is added internally upon configure and only autoDetection is mutale (as it
    depends on DNS context), when there is no auto-detection, we can only rely on internal domain list, and
    dont need to perform a full listing upon contains.
---
 .../org/apache/james/domainlist/lib/AbstractDomainList.java   | 11 +++++++++--
 .../james/mailetcontainer/impl/JamesMailetContextTest.java    |  4 ++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java b/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java
index 4053a73..2a19598 100644
--- a/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java
+++ b/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java
@@ -170,7 +170,7 @@ public abstract class AbstractDomainList implements DomainList, Configurable {
         if (configuration.isCacheEnabled()) {
             try {
                 boolean internalAnswer = cache.get(domain);
-                return internalAnswer || getDomains().contains(domain);
+                return internalAnswer || detectedDomainsContains(domain);
             } catch (ExecutionException e) {
                 if (e.getCause() instanceof DomainListException) {
                     throw (DomainListException) e.getCause();
@@ -179,10 +179,17 @@ public abstract class AbstractDomainList implements DomainList, Configurable {
             }
         } else {
             boolean internalAnswer = containsDomainInternal(domain);
-            return internalAnswer || getDomains().contains(domain);
+            return internalAnswer || detectedDomainsContains(domain);
         }
     }
 
+    private boolean detectedDomainsContains(Domain domain) throws DomainListException {
+        if (configuration.isAutoDetect() || configuration.isAutoDetectIp()) {
+            return getDomains().contains(domain);
+        }
+        return false;
+    }
+
     @Override
     public ImmutableList<Domain> getDomains() throws DomainListException {
         Multimap<DomainType, Domain> domainsWithType = getDomainsWithType();
diff --git a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java
index de64fc2..92d7bfa 100644
--- a/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java
+++ b/server/mailet/mailetcontainer-camel/src/test/java/org/apache/james/mailetcontainer/impl/JamesMailetContextTest.java
@@ -108,7 +108,7 @@ class JamesMailetContextTest {
 
     @Test
     void isLocalServerShouldPropagateDomainExceptions() throws Exception {
-        when(domainList.getDomains()).thenThrow(new DomainListException("fail!"));
+        when(domainList.containsDomain(any())).thenThrow(new DomainListException("fail!"));
 
         assertThatThrownBy(() -> testee.isLocalServer(DOMAIN_COM))
             .isInstanceOf(RuntimeException.class);
@@ -249,7 +249,7 @@ class JamesMailetContextTest {
 
     @Test
     void isLocalEmailShouldPropagateDomainExceptions() throws Exception {
-        when(domainList.getDomains()).thenThrow(new DomainListException("fail!"));
+        when(domainList.containsDomain(any())).thenThrow(new DomainListException("fail!"));
 
         assertThatThrownBy(() -> testee.isLocalEmail(mailAddress))
             .isInstanceOf(RuntimeException.class);

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org


[james-project] 03/03: JAMES-3467 Domain cache should be refreshed periodically under read load

Posted by rc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit f93cdfc8ff70ca569e77eed79e7496a64785f507
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon Apr 26 23:39:38 2021 +0700

    JAMES-3467 Domain cache should be refreshed periodically under read load
    
    The documentation states:
    
    ```
    Expiracy of the cache. Longer means less reads are performed to the backend but writes will take longer to propagate.
    ```
    
    Which implies writes will e visible after the expiracy period.
    
    Sadly it was not the case as the added test proves it...
---
 .../domainlist/cassandra/CacheDomainListTest.java  | 28 ++++++++++++++++++----
 .../james/domainlist/lib/AbstractDomainList.java   |  2 +-
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/server/data/data-cassandra/src/test/java/org/apache/james/domainlist/cassandra/CacheDomainListTest.java b/server/data/data-cassandra/src/test/java/org/apache/james/domainlist/cassandra/CacheDomainListTest.java
index c74d661..f216b01 100644
--- a/server/data/data-cassandra/src/test/java/org/apache/james/domainlist/cassandra/CacheDomainListTest.java
+++ b/server/data/data-cassandra/src/test/java/org/apache/james/domainlist/cassandra/CacheDomainListTest.java
@@ -22,6 +22,7 @@ package org.apache.james.domainlist.cassandra;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.net.UnknownHostException;
+import java.time.Duration;
 
 import org.apache.james.backends.cassandra.CassandraCluster;
 import org.apache.james.backends.cassandra.CassandraClusterExtension;
@@ -29,10 +30,8 @@ import org.apache.james.backends.cassandra.StatementRecorder;
 import org.apache.james.core.Domain;
 import org.apache.james.dnsservice.api.DNSService;
 import org.apache.james.dnsservice.api.InMemoryDNSService;
-import org.apache.james.domainlist.api.DomainList;
 import org.apache.james.domainlist.api.DomainListException;
 import org.apache.james.domainlist.lib.DomainListConfiguration;
-import org.apache.james.domainlist.lib.DomainListContract;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.RegisterExtension;
@@ -40,6 +39,8 @@ import org.junit.jupiter.api.extension.RegisterExtension;
 import com.github.fge.lambdas.Throwing;
 
 import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.core.scheduler.Schedulers;
 
 class CacheDomainListTest {
 
@@ -57,6 +58,7 @@ class CacheDomainListTest {
             .autoDetect(false)
             .autoDetectIp(false)
             .cacheEnabled(true)
+            .cacheExpiracy(Duration.ofSeconds(1))
             .build());
     }
 
@@ -77,12 +79,30 @@ class CacheDomainListTest {
     }
 
     @Test
-    void additionIsInstant() throws DomainListException {
+    void cacheShouldBeRefreshedPeriodicallyUnderReadLoad(CassandraCluster cassandra) throws DomainListException {
+        domainList.addDomain(DOMAIN_1);
+
+        StatementRecorder statementRecorder = new StatementRecorder();
+        cassandra.getConf().recordStatements(statementRecorder);
+
+        Flux.range(0, 6)
+            .delayElements(Duration.ofMillis(500))
+            .flatMap(Throwing.function(i -> Mono.fromCallable(() ->domainList.containsDomain(DOMAIN_1)).subscribeOn(Schedulers.elastic())))
+            .subscribeOn(Schedulers.elastic())
+            .blockLast();
+
+        assertThat(statementRecorder.listExecutedStatements(
+            StatementRecorder.Selector.preparedStatement("SELECT domain FROM domains WHERE domain=:domain;")))
+            .hasSize(2);
+    }
+
+    @Test
+    void additionIsNotInstant() throws DomainListException {
         domainList.containsDomain(DOMAIN_1);
 
         domainList.addDomain(DOMAIN_1);
 
-        assertThat(domainList.containsDomain(DOMAIN_1)).isEqualTo(true);
+        assertThat(domainList.containsDomain(DOMAIN_1)).isEqualTo(false);
     }
 
     @Test
diff --git a/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java b/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java
index 9f371eb..f505db6 100644
--- a/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java
+++ b/server/data/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java
@@ -93,7 +93,7 @@ public abstract class AbstractDomainList implements DomainList, Configurable {
         this.configuration = domainListConfiguration;
 
         this.cache = CacheBuilder.newBuilder()
-            .expireAfterAccess(configuration.getCacheExpiracy())
+            .expireAfterWrite(configuration.getCacheExpiracy())
             .build(new CacheLoader<>() {
                 @Override
                 public Boolean load(Domain key) throws DomainListException {

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org