james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [17/17] james-project git commit: JAMES-2555 Allow re-indexing of a single message
Date Mon, 15 Oct 2018 06:28:40 GMT
JAMES-2555 Allow re-indexing of a single message

Note that message reIndexing allows one grokking the logs and fix a partially
failed re-indexing without going through the wall process yet-another-time.


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/45d311c5
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/45d311c5
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/45d311c5

Branch: refs/heads/master
Commit: 45d311c558affbda21282a54ae10ee84c42defc1
Parents: a873181
Author: Benoit Tellier <btellier@linagora.com>
Authored: Fri Oct 12 17:47:31 2018 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Mon Oct 15 13:20:00 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/indexer/ReIndexer.java |  3 +
 .../mailbox/tools/indexer/ReIndexerImpl.java    |  5 ++
 .../tools/indexer/ReIndexerPerformer.java       |  8 ++
 .../indexer/SingleMessageReindexingTask.java    | 85 ++++++++++++++++++++
 .../mailbox/tools/indexer/ThrowsReIndexer.java  |  6 ++
 .../tools/indexer/ReIndexerImplTest.java        | 21 +++++
 6 files changed, 128 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/45d311c5/mailbox/api/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java b/mailbox/api/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java
index 5ed156e..817307b 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/indexer/ReIndexer.java
@@ -20,6 +20,7 @@
 package org.apache.james.mailbox.indexer;
 
 import org.apache.james.core.User;
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.task.Task;
@@ -32,4 +33,6 @@ public interface ReIndexer {
 
     Task reIndex() throws MailboxException;
 
+    Task reIndex(MailboxPath path, MessageUid uid) throws MailboxException;
+
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/45d311c5/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
index 8fd3786..c32c533 100644
--- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerImpl.java
@@ -22,6 +22,7 @@ package org.apache.mailbox.tools.indexer;
 import javax.inject.Inject;
 
 import org.apache.james.core.User;
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.indexer.ReIndexer;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.task.Task;
@@ -59,4 +60,8 @@ public class ReIndexerImpl implements ReIndexer {
         return new UserReindexingTask(reIndexerPerformer, user);
     }
 
+    @Override
+    public Task reIndex(MailboxPath path, MessageUid uid) {
+        return new SingleMessageReindexingTask(reIndexerPerformer, path, uid);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/45d311c5/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
index fb5bf89..625adda 100644
--- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ReIndexerPerformer.java
@@ -101,6 +101,14 @@ class ReIndexerPerformer {
         }
     }
 
+    Task.Result handleMessageReIndexing(MailboxPath path, MessageUid uid) throws MailboxException
{
+        MailboxSession mailboxSession = mailboxManager.createSystemSession(path.getUser());
+        Mailbox mailbox = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession)
+            .findMailboxByPath(path);
+
+        return handleMessageReIndexing(mailboxSession, mailbox, uid);
+    }
+
     private Task.Result reIndex(List<MailboxPath> mailboxPaths, MailboxSession mailboxSession,
ReprocessingContext reprocessingContext) throws MailboxException {
         return wrapInGlobalRegistration(mailboxSession,
             globalRegistration -> handleMultiMailboxesReindexingIterations(mailboxPaths,
globalRegistration, reprocessingContext));

http://git-wip-us.apache.org/repos/asf/james-project/blob/45d311c5/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTask.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTask.java
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTask.java
new file mode 100644
index 0000000..501ee6f
--- /dev/null
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/SingleMessageReindexingTask.java
@@ -0,0 +1,85 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.mailbox.tools.indexer;
+
+import java.util.Optional;
+
+import javax.inject.Inject;
+
+import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.task.Task;
+import org.apache.james.task.TaskExecutionDetails;
+
+public class SingleMessageReindexingTask implements Task {
+
+    public static final String MESSAGE_RE_INDEXING = "messageReIndexing";
+
+    public static class AdditionalInformation implements TaskExecutionDetails.AdditionalInformation
{
+        private final MailboxPath mailboxPath;
+        private final MessageUid uid;
+
+        AdditionalInformation(MailboxPath mailboxPath, MessageUid uid) {
+            this.mailboxPath = mailboxPath;
+            this.uid = uid;
+        }
+
+        public String getMailboxPath() {
+            return mailboxPath.asString();
+        }
+
+        public long getUid() {
+            return uid.asLong();
+        }
+    }
+
+    private final ReIndexerPerformer reIndexerPerformer;
+    private final MailboxPath path;
+    private final MessageUid uid;
+    private final AdditionalInformation additionalInformation;
+
+    @Inject
+    public SingleMessageReindexingTask(ReIndexerPerformer reIndexerPerformer, MailboxPath
path, MessageUid uid) {
+        this.reIndexerPerformer = reIndexerPerformer;
+        this.path = path;
+        this.uid = uid;
+        this.additionalInformation = new AdditionalInformation(path, uid);
+    }
+
+    @Override
+    public Result run() {
+        try {
+            return reIndexerPerformer.handleMessageReIndexing(path, uid);
+        } catch (MailboxException e) {
+            return Result.PARTIAL;
+        }
+    }
+
+    @Override
+    public String type() {
+        return MESSAGE_RE_INDEXING;
+    }
+
+    @Override
+    public Optional<TaskExecutionDetails.AdditionalInformation> details() {
+        return Optional.of(additionalInformation);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/45d311c5/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ThrowsReIndexer.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ThrowsReIndexer.java
b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ThrowsReIndexer.java
index f0d86ae..5ffb02b 100644
--- a/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ThrowsReIndexer.java
+++ b/mailbox/tools/indexer/src/main/java/org/apache/mailbox/tools/indexer/ThrowsReIndexer.java
@@ -20,6 +20,7 @@
 package org.apache.mailbox.tools.indexer;
 
 import org.apache.james.core.User;
+import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.indexer.ReIndexer;
 import org.apache.james.mailbox.model.MailboxPath;
@@ -41,4 +42,9 @@ public class ThrowsReIndexer implements ReIndexer {
     public Task reIndex(User user) throws MailboxException {
         throw new MailboxException("Not implemented");
     }
+
+    @Override
+    public Task reIndex(MailboxPath path, MessageUid uid) throws MailboxException {
+        throw new MailboxException("Not implemented");
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/45d311c5/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
----------------------------------------------------------------------
diff --git a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
index d1fed69..74e834a 100644
--- a/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
+++ b/mailbox/tools/indexer/src/test/java/org/apache/mailbox/tools/indexer/ReIndexerImplTest.java
@@ -133,4 +133,25 @@ public class ReIndexerImplTest {
         assertThat(messageCaptor.getValue()).matches(message -> message.getMailboxId().equals(mailboxId)
             && message.getUid().equals(createdMessage.getUid()));
     }
+
+    @Test
+    void messageReIndexShouldBeWellPerformed() throws Exception {
+        MailboxSession systemSession = mailboxManager.createSystemSession(USERNAME);
+        MailboxId mailboxId = mailboxManager.createMailbox(INBOX, systemSession).get();
+        ComposedMessageId createdMessage = mailboxManager.getMailbox(INBOX, systemSession)
+            .appendMessage(
+                MessageManager.AppendCommand.builder().build("header: value\r\n\r\nbody"),
+                systemSession);
+
+        reIndexer.reIndex(INBOX, createdMessage.getUid()).run();
+        ArgumentCaptor<MailboxMessage> messageCaptor = ArgumentCaptor.forClass(MailboxMessage.class);
+        ArgumentCaptor<Mailbox> mailboxCaptor = ArgumentCaptor.forClass(Mailbox.class);
+
+        verify(messageSearchIndex).add(any(MailboxSession.class), mailboxCaptor.capture(),
messageCaptor.capture());
+        verifyNoMoreInteractions(messageSearchIndex);
+
+        assertThat(mailboxCaptor.getValue()).matches(mailbox -> mailbox.getMailboxId().equals(mailboxId));
+        assertThat(messageCaptor.getValue()).matches(message -> message.getMailboxId().equals(mailboxId)
+            && message.getUid().equals(createdMessage.getUid()));
+    }
 }


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


Mime
View raw message