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 23fa274b00588ada8866836a40b0e6315ca88e24 Author: Benoit Tellier <btell...@linagora.com> AuthorDate: Tue Aug 25 15:55:03 2020 +0700 JAMES-3364 DeletedMessageVault: deleting many messages dead-locks --- .../apache/james/vault/DeletedMessageVaultHook.java | 21 +-------------------- .../james/vault/DeletedMessageVaultHookTest.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 20 deletions(-) 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 72cc971..d357649 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 @@ -50,19 +50,6 @@ import reactor.core.publisher.Mono; public class DeletedMessageVaultHook implements PreDeletionHook { static class DeletedMessageMailboxContext { - private static DeletedMessageMailboxContext combine(DeletedMessageMailboxContext first, DeletedMessageMailboxContext second) { - Preconditions.checkArgument(first.messageId.equals(second.getMessageId())); - Preconditions.checkArgument(first.owner.equals(second.getOwner())); - - return new DeletedMessageMailboxContext( - first.messageId, - first.owner, - ImmutableList.<MailboxId>builder() - .addAll(first.ownerMailboxes) - .addAll(second.ownerMailboxes) - .build()); - } - private final MessageId messageId; private final Username owner; private final List<MailboxId> ownerMailboxes; @@ -146,9 +133,7 @@ public class DeletedMessageVaultHook implements PreDeletionHook { private Flux<DeletedMessageMailboxContext> groupMetadataByOwnerAndMessageId(DeleteOperation deleteOperation) { return Flux.fromIterable(deleteOperation.getDeletionMetadataList()) .groupBy(MetadataWithMailboxId::getMailboxId) - .flatMap(this::addOwnerToMetadata) - .groupBy(this::toMessageIdUserPair) - .flatMap(groupFlux -> groupFlux.reduce(DeletedMessageMailboxContext::combine)); + .flatMap(this::addOwnerToMetadata); } private Flux<DeletedMessageMailboxContext> addOwnerToMetadata(GroupedFlux<MailboxId, MetadataWithMailboxId> groupedFlux) { @@ -157,10 +142,6 @@ public class DeletedMessageVaultHook implements PreDeletionHook { new DeletedMessageMailboxContext(metadata.getMessageMetaData().getMessageId(), owner, ImmutableList.of(metadata.getMailboxId())))); } - private Pair<MessageId, Username> toMessageIdUserPair(DeletedMessageMailboxContext deletedMessageMetadata) { - return Pair.of(deletedMessageMetadata.getMessageId(), deletedMessageMetadata.getOwner()); - } - private Mono<Username> retrieveMailboxUser(MailboxId mailboxId) { return mapperFactory.getMailboxMapper(session) .findMailboxById(mailboxId) diff --git a/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/DeletedMessageVaultHookTest.java b/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/DeletedMessageVaultHookTest.java index 688574f..12165b6 100644 --- a/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/DeletedMessageVaultHookTest.java +++ b/mailbox/plugin/deleted-messages-vault/src/test/java/org/apache/james/vault/DeletedMessageVaultHookTest.java @@ -23,11 +23,13 @@ import static org.apache.james.vault.DeletedMessageFixture.DELETION_DATE; import static org.apache.james.vault.DeletedMessageFixture.DELIVERY_DATE; import static org.apache.james.vault.DeletedMessageFixture.INTERNAL_DATE; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; import java.nio.charset.StandardCharsets; import java.time.Clock; import java.time.ZoneOffset; import java.util.List; +import java.util.stream.IntStream; import org.apache.james.blob.api.HashBlobId; import org.apache.james.blob.memory.MemoryDumbBlobStore; @@ -58,6 +60,7 @@ import org.apache.james.vault.search.Query; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import com.github.fge.lambdas.Throwing; import com.github.steveash.guavate.Guavate; import com.google.common.collect.ImmutableList; @@ -164,6 +167,19 @@ class DeletedMessageVaultHookTest { } @Test + void deletingManyMessagesShouldSucceed() throws Exception { + MailboxId aliceMailbox = mailboxManager.createMailbox(MAILBOX_ALICE_ONE, aliceSession).get(); + MessageManager messageManager = mailboxManager.getMailbox(aliceMailbox, aliceSession); + + ImmutableList<MessageId> ids = IntStream.range(0, 1000) + .mapToObj(Throwing.intFunction(i -> appendMessage(messageManager).getMessageId())) + .collect(Guavate.toImmutableList()); + + assertThatCode(() -> messageIdManager.delete(ids, aliceSession)) + .doesNotThrowAnyException(); + } + + @Test void notifyDeleteShouldAppendMessageToVaultOfMailboxOwnerWhenOtherUserDeleteMessageInSharingMailbox() throws Exception { MailboxId aliceMailbox = mailboxManager.createMailbox(MAILBOX_ALICE_ONE, aliceSession).get(); MessageManager aliceMessageManager = mailboxManager.getMailbox(aliceMailbox, aliceSession); --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org