james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [4/4] james-project git commit: JAMES-1945 Compute modseq and uid in parallel when saving a message
Date Thu, 23 Feb 2017 03:39:04 GMT
JAMES-1945 Compute modseq and uid in parallel when saving a message


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

Branch: refs/heads/master
Commit: f3140967ab888bed8d1dfc1cd0a219ae92ec87b1
Parents: 6d94a8f
Author: benwa <btellier@linagora.com>
Authored: Wed Feb 22 14:39:06 2017 +0700
Committer: benwa <btellier@linagora.com>
Committed: Thu Feb 23 10:38:06 2017 +0700

----------------------------------------------------------------------
 .../CassandraMailboxSessionMapperFactory.java   | 10 ++++++----
 .../cassandra/mail/CassandraMessageMapper.java  | 21 ++++++++++++--------
 2 files changed, 19 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/f3140967/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java
index a1a7ff3..9dde162 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java
@@ -37,6 +37,8 @@ import org.apache.james.mailbox.cassandra.mail.CassandraMessageIdDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraMessageIdMapper;
 import org.apache.james.mailbox.cassandra.mail.CassandraMessageIdToImapUidDAO;
 import org.apache.james.mailbox.cassandra.mail.CassandraMessageMapper;
+import org.apache.james.mailbox.cassandra.mail.CassandraModSeqProvider;
+import org.apache.james.mailbox.cassandra.mail.CassandraUidProvider;
 import org.apache.james.mailbox.cassandra.user.CassandraSubscriptionMapper;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
@@ -58,8 +60,8 @@ public class CassandraMailboxSessionMapperFactory extends MailboxSessionMapperFa
     public static final Integer DEFAULT_MAX_RETRY = 1000;
 
     private final Session session;
-    private final UidProvider uidProvider;
-    private final ModSeqProvider modSeqProvider;
+    private final CassandraUidProvider uidProvider;
+    private final CassandraModSeqProvider modSeqProvider;
     private final CassandraMessageDAO messageDAO;
     private final CassandraMessageIdDAO messageIdDAO;
     private final CassandraMessageIdToImapUidDAO imapUidDAO;
@@ -72,7 +74,7 @@ public class CassandraMailboxSessionMapperFactory extends MailboxSessionMapperFa
     private int maxRetry;
 
     @Inject
-    public CassandraMailboxSessionMapperFactory(UidProvider uidProvider, ModSeqProvider modSeqProvider,
Session session,
+    public CassandraMailboxSessionMapperFactory(CassandraUidProvider uidProvider, CassandraModSeqProvider
modSeqProvider, Session session,
                                                 CassandraMessageDAO messageDAO, CassandraMessageIdDAO
messageIdDAO, CassandraMessageIdToImapUidDAO imapUidDAO,
                                                 CassandraMailboxCounterDAO mailboxCounterDAO,
CassandraMailboxRecentsDAO mailboxRecentsDAO, CassandraMailboxDAO mailboxDAO,
                                                 CassandraMailboxPathDAO mailboxPathDAO, CassandraFirstUnseenDAO
firstUnseenDAO, @Named(CassandraMailboxDAO.MAX_ACL_RETRY) Integer maxRetry) {
@@ -91,7 +93,7 @@ public class CassandraMailboxSessionMapperFactory extends MailboxSessionMapperFa
         this.maxRetry = maxRetry;
     }
 
-    public CassandraMailboxSessionMapperFactory(UidProvider uidProvider, ModSeqProvider modSeqProvider,
Session session,
+    public CassandraMailboxSessionMapperFactory(CassandraUidProvider uidProvider, CassandraModSeqProvider
modSeqProvider, Session session,
                                                 CassandraMessageDAO messageDAO, CassandraMessageIdDAO
messageIdDAO, CassandraMessageIdToImapUidDAO imapUidDAO,
                                                 CassandraMailboxCounterDAO mailboxCounterDAO,
CassandraMailboxRecentsDAO mailboxRecentsDAO, CassandraMailboxDAO mailboxDAO,
                                                 CassandraMailboxPathDAO mailboxPathDAO, CassandraFirstUnseenDAO
firstUnseenDAO) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/f3140967/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
----------------------------------------------------------------------
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 c439e49..47fb80d 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
@@ -49,10 +49,7 @@ import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.UpdatedFlags;
 import org.apache.james.mailbox.store.FlagsUpdateCalculator;
 import org.apache.james.mailbox.store.SimpleMessageMetaData;
-import org.apache.james.mailbox.store.mail.AttachmentMapper;
 import org.apache.james.mailbox.store.mail.MessageMapper;
-import org.apache.james.mailbox.store.mail.ModSeqProvider;
-import org.apache.james.mailbox.store.mail.UidProvider;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
@@ -72,9 +69,9 @@ public class CassandraMessageMapper implements MessageMapper {
         .unseen(0L)
         .build();
 
-    private final ModSeqProvider modSeqProvider;
+    private final CassandraModSeqProvider modSeqProvider;
     private final MailboxSession mailboxSession;
-    private final UidProvider uidProvider;
+    private final CassandraUidProvider uidProvider;
     private final int maxRetries;
     private final CassandraMessageDAO messageDAO;
     private final CassandraMessageIdDAO messageIdDAO;
@@ -85,7 +82,7 @@ public class CassandraMessageMapper implements MessageMapper {
     private final CassandraFirstUnseenDAO firstUnseenDAO;
     private final AttachmentLoader attachmentLoader;
 
-    public CassandraMessageMapper(UidProvider uidProvider, ModSeqProvider modSeqProvider,
+    public CassandraMessageMapper(CassandraUidProvider uidProvider, CassandraModSeqProvider
modSeqProvider,
                                   MailboxSession mailboxSession, int maxRetries, CassandraAttachmentMapper
attachmentMapper,
                                   CassandraMessageDAO messageDAO, CassandraMessageIdDAO messageIdDAO,
CassandraMessageIdToImapUidDAO imapUidDAO,
                                   CassandraMailboxCounterDAO mailboxCounterDAO, CassandraMailboxRecentsDAO
mailboxRecentDAO,
@@ -228,9 +225,17 @@ public class CassandraMessageMapper implements MessageMapper {
 
     @Override
     public MessageMetaData add(Mailbox mailbox, MailboxMessage message) throws MailboxException
{
-        message.setUid(uidProvider.nextUid(mailboxSession, mailbox));
-        message.setModSeq(modSeqProvider.nextModSeq(mailboxSession, mailbox));
         CassandraId mailboxId = (CassandraId) mailbox.getMailboxId();
+
+        CompletableFuture<Optional<MessageUid>> uidFuture = uidProvider.nextUid(mailboxId);
+        CompletableFuture<Optional<Long>> modseqFuture = modSeqProvider.nextModSeq(mailboxId);
+        CompletableFuture.allOf(uidFuture, modseqFuture).join();
+
+        message.setUid(uidFuture.join()
+            .orElseThrow(() -> new MailboxException("Can not find a UID to save " + message.getMessageId()
+ " in " + mailboxId)));
+        message.setModSeq(modseqFuture.join()
+            .orElseThrow(() -> new MailboxException("Can not find a MODSEQ to save " +
message.getMessageId() + " in " + mailboxId)));
+
         save(mailbox, message)
             .thenCompose(voidValue -> indexTableHandler.updateIndexOnAdd(message, mailboxId))
             .join();


---------------------------------------------------------------------
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