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 2020/09/30 02:12:10 UTC

[james-project] branch master updated (91f3a79 -> 60f8428)

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 91f3a79  JAMES-3028 Adapt the script for performance testing for the new s3 provisioning
     new b6ed5fa  JAMES-3393 build stability, add retry to delete mailbox
     new 60f8428  JAMES-3393 wrap exception into Mono instead of using Throwing

The 2 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:
 .../cassandra/mail/CassandraMessageMapper.java     |  7 +++---
 .../james/vault/DeletedMessageVaultHook.java       |  7 +++---
 .../james/mailbox/store/StoreMailboxManager.java   | 27 +++++++++++++---------
 3 files changed, 23 insertions(+), 18 deletions(-)


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


[james-project] 01/02: JAMES-3393 build stability, add retry to delete mailbox

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 b6ed5faa2ae912c58664245a169a6525b8d0e844
Author: Rémi Kowalski <rk...@linagora.com>
AuthorDate: Tue Sep 29 13:56:54 2020 +0200

    JAMES-3393 build stability, add retry to delete mailbox
---
 .../james/mailbox/store/StoreMailboxManager.java   | 27 +++++++++++++---------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
index 52e66c9..e90651d 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
@@ -23,6 +23,7 @@ import static org.apache.james.mailbox.store.MailboxReactorUtils.block;
 import static org.apache.james.mailbox.store.MailboxReactorUtils.blockOptional;
 import static org.apache.james.mailbox.store.mail.AbstractMessageMapper.UNLIMITED;
 
+import java.time.Duration;
 import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.List;
@@ -98,6 +99,8 @@ import com.google.common.collect.Iterables;
 
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
+import reactor.util.retry.Retry;
+import reactor.util.retry.RetryBackoffSpec;
 
 /**
  * This base class of an {@link MailboxManager} implementation provides a high-level api for writing your own
@@ -110,6 +113,9 @@ public class StoreMailboxManager implements MailboxManager {
     private static final Logger LOGGER = LoggerFactory.getLogger(StoreMailboxManager.class);
     public static final char SQL_WILDCARD_CHAR = '%';
     public static final EnumSet<MessageCapabilities> DEFAULT_NO_MESSAGE_CAPABILITIES = EnumSet.noneOf(MessageCapabilities.class);
+    public static final int MAX_ATTEMPTS = 3;
+    public static final Duration MIN_BACKOFF = Duration.ofMillis(100);
+    public static final RetryBackoffSpec RETRY_BACKOFF_SPEC = Retry.backoff(MAX_ATTEMPTS, MIN_BACKOFF);
 
     private final StoreRightManager storeRightManager;
     private final EventBus eventBus;
@@ -410,8 +416,7 @@ public class StoreMailboxManager implements MailboxManager {
         MailboxMapper mailboxMapper = mailboxSessionMapperFactory.getMailboxMapper(session);
 
         mailboxMapper.execute(() -> block(mailboxMapper.findMailboxByPath(mailboxPath)
-            .flatMap(Throwing.<Mailbox, Mono<Mailbox>>function(mailbox ->
-                doDeleteMailbox(mailboxMapper, mailbox, session)).sneakyThrow())
+            .flatMap(mailbox -> doDeleteMailbox(mailboxMapper, mailbox, session))
             .switchIfEmpty(Mono.error(new MailboxNotFoundException(mailboxPath)))));
     }
 
@@ -425,17 +430,16 @@ public class StoreMailboxManager implements MailboxManager {
                 assertIsOwner(session, mailbox.generateAssociatedPath());
                 return mailbox;
             }).sneakyThrow())
-            .flatMap(Throwing.<Mailbox, Mono<Mailbox>>function(mailbox ->
-                doDeleteMailbox(mailboxMapper, mailbox, session)).sneakyThrow())));
+            .flatMap(mailbox -> doDeleteMailbox(mailboxMapper, mailbox, session))));
     }
 
-    private Mono<Mailbox> doDeleteMailbox(MailboxMapper mailboxMapper, Mailbox mailbox, MailboxSession session) throws MailboxException {
+    private Mono<Mailbox> doDeleteMailbox(MailboxMapper mailboxMapper, Mailbox mailbox, MailboxSession session) {
         MessageMapper messageMapper = mailboxSessionMapperFactory.getMessageMapper(session);
 
-        QuotaRoot quotaRoot = quotaRootResolver.getQuotaRoot(mailbox.generateAssociatedPath());
-        long messageCount = messageMapper.countMessagesInMailbox(mailbox);
+        Mono<QuotaRoot> quotaRootPublisher = Mono.fromCallable(() -> quotaRootResolver.getQuotaRoot(mailbox.generateAssociatedPath()));
+        Mono<Long> messageCountPublisher = Mono.fromCallable(() -> messageMapper.countMessagesInMailbox(mailbox));
 
-        return messageMapper.findInMailboxReactive(mailbox, MessageRange.all(), MessageMapper.FetchType.Metadata, UNLIMITED)
+        return quotaRootPublisher.zipWith(messageCountPublisher).flatMap(quotaRootWithMessageCount -> messageMapper.findInMailboxReactive(mailbox, MessageRange.all(), MessageMapper.FetchType.Metadata, UNLIMITED)
             .map(message -> MetadataWithMailboxId.from(message.metaData(), message.getMailboxId()))
             .collect(Guavate.toImmutableList())
             .flatMap(metadata -> {
@@ -450,15 +454,16 @@ public class StoreMailboxManager implements MailboxManager {
                             .randomEventId()
                             .mailboxSession(session)
                             .mailbox(mailbox)
-                            .quotaRoot(quotaRoot)
-                            .quotaCount(QuotaCountUsage.count(messageCount))
+                            .quotaRoot(quotaRootWithMessageCount.getT1())
+                            .quotaCount(QuotaCountUsage.count(quotaRootWithMessageCount.getT2()))
                             .quotaSize(QuotaSizeUsage.size(totalSize))
                             .build(),
                         new MailboxIdRegistrationKey(mailbox.getMailboxId())));
             })
+            .retryWhen(RETRY_BACKOFF_SPEC)
             // We need to create a copy of the mailbox as maybe we can not refer to the real
             // mailbox once we remove it
-            .thenReturn(new Mailbox(mailbox));
+            .thenReturn(new Mailbox(mailbox)));
     }
 
     @Override


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


[james-project] 02/02: JAMES-3393 wrap exception into Mono instead of using Throwing

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 60f84283b6d6414da381d9cb5723815a08a5ddd8
Author: Rémi Kowalski <rk...@linagora.com>
AuthorDate: Tue Sep 29 14:52:55 2020 +0200

    JAMES-3393 wrap exception into Mono instead of using Throwing
---
 .../james/mailbox/cassandra/mail/CassandraMessageMapper.java       | 7 ++++---
 .../main/java/org/apache/james/vault/DeletedMessageVaultHook.java  | 7 +++----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
index 75adad6..851db3d 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
@@ -25,6 +25,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import java.util.function.Function;
 
 import javax.mail.Flags;
 import javax.mail.Flags.Flag;
@@ -56,7 +57,6 @@ import org.apache.james.util.streams.Limit;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.github.fge.lambdas.Throwing;
 import com.github.steveash.guavate.Guavate;
 import com.google.common.collect.ImmutableList;
 
@@ -262,8 +262,9 @@ public class CassandraMessageMapper implements MessageMapper {
         CassandraId mailboxId = (CassandraId) mailbox.getMailboxId();
 
         return block(addUidAndModseq(message, mailboxId)
-            .flatMap(Throwing.function(messageWithUidAndModSeq -> save(mailbox, messageWithUidAndModSeq)
-                .thenReturn(messageWithUidAndModSeq)))
+            .flatMap(messageWithUidAndModSeq -> Mono.fromCallable(() -> save(mailbox, messageWithUidAndModSeq))
+                .flatMap(Function.identity())
+                .thenReturn(messageWithUidAndModSeq))
             .map(MailboxMessage::metaData));
     }
 
diff --git a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/DeletedMessageVaultHook.java b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/DeletedMessageVaultHook.java
index 5474f86..30c03e2 100644
--- a/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/DeletedMessageVaultHook.java
+++ b/mailbox/plugin/deleted-messages-vault/src/main/java/org/apache/james/vault/DeletedMessageVaultHook.java
@@ -40,7 +40,6 @@ import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.mail.MessageMapper;
 import org.reactivestreams.Publisher;
 
-import com.github.fge.lambdas.Throwing;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 
@@ -125,11 +124,11 @@ public class DeletedMessageVaultHook implements PreDeletionHook {
             .findReactive(ImmutableList.of(deletedMessageMailboxContext.getMessageId()), MessageMapper.FetchType.Full)
             .next()
             .switchIfEmpty(Mono.error(new RuntimeException("Cannot find " + deletedMessageMailboxContext.getMessageId())))
-            .map(Throwing.function(mailboxMessage -> Pair.of(mailboxMessage,
+            .flatMap(mailboxMessage -> Mono.fromCallable(() -> Pair.of(mailboxMessage,
                 deletedMessageConverter.convert(deletedMessageMailboxContext, mailboxMessage,
                     ZonedDateTime.ofInstant(clock.instant(), ZoneOffset.UTC)))))
-            .flatMap(Throwing.function(pairs -> Mono.from(deletedMessageVault
-                .append(pairs.getRight(), pairs.getLeft().getFullContent()))));
+            .flatMap(pairs -> Mono.fromCallable(() -> pairs.getLeft().getFullContent())
+                .flatMap(fullContent -> Mono.from(deletedMessageVault.append(pairs.getRight(), fullContent))));
     }
 
     private Flux<DeletedMessageMailboxContext> groupMetadataByOwnerAndMessageId(DeleteOperation deleteOperation) {


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