You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2020/04/03 02:09:44 UTC

[james-project] 01/04: JAMES-2990 Reduce consistency level: CassandraMessageFastViewProjection::store

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

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

commit 0afb84f2e8909346e76aca6d138168d1dcb0c153
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Feb 5 09:22:17 2020 +0700

    JAMES-2990 Reduce consistency level: CassandraMessageFastViewProjection::store
    
    Rationals: An outdated projection is very well handled on the read path so
    inconsistencies are acceptable.
    
    We have been noticing failed writes (partial quorum writes) and relying on
    Cassandra consistency mechanisms for this (hinted handoff, etc...) seems like
    an acceptable solution.
---
 .../projections/CassandraMessageFastViewProjection.java  | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/CassandraMessageFastViewProjection.java b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/CassandraMessageFastViewProjection.java
index 628a3b6..21352c8 100644
--- a/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/CassandraMessageFastViewProjection.java
+++ b/server/data/data-jmap-cassandra/src/main/java/org/apache/james/jmap/cassandra/projections/CassandraMessageFastViewProjection.java
@@ -39,7 +39,10 @@ import org.apache.james.mailbox.cassandra.ids.CassandraMessageId;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.metrics.api.Metric;
 import org.apache.james.metrics.api.MetricFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
+import com.datastax.driver.core.ConsistencyLevel;
 import com.datastax.driver.core.PreparedStatement;
 import com.datastax.driver.core.Row;
 import com.datastax.driver.core.Session;
@@ -50,6 +53,7 @@ import reactor.core.publisher.Mono;
 
 public class CassandraMessageFastViewProjection implements MessageFastViewProjection {
 
+    public static final Logger LOGGER = LoggerFactory.getLogger(CassandraMessageFastViewProjection.class);
     private final Metric metricRetrieveHitCount;
     private final Metric metricRetrieveMissCount;
 
@@ -90,7 +94,8 @@ public class CassandraMessageFastViewProjection implements MessageFastViewProjec
         return cassandraAsyncExecutor.executeVoid(storeStatement.bind()
             .setUUID(MESSAGE_ID, ((CassandraMessageId) messageId).get())
             .setString(PREVIEW, precomputedProperties.getPreview().getValue())
-            .setBool(HAS_ATTACHMENT, precomputedProperties.hasAttachment()));
+            .setBool(HAS_ATTACHMENT, precomputedProperties.hasAttachment())
+            .setConsistencyLevel(ConsistencyLevel.ONE));
     }
 
     @Override
@@ -98,10 +103,15 @@ public class CassandraMessageFastViewProjection implements MessageFastViewProjec
         checkMessage(messageId);
 
         return cassandraAsyncExecutor.executeSingleRow(retrieveStatement.bind()
-                .setUUID(MESSAGE_ID, ((CassandraMessageId) messageId).get()))
+                .setUUID(MESSAGE_ID, ((CassandraMessageId) messageId).get())
+                .setConsistencyLevel(ConsistencyLevel.ONE))
             .map(this::fromRow)
             .doOnNext(preview -> metricRetrieveHitCount.increment())
-            .switchIfEmpty(Mono.fromRunnable(metricRetrieveMissCount::increment));
+            .switchIfEmpty(Mono.fromRunnable(metricRetrieveMissCount::increment))
+            .onErrorResume(e -> {
+                LOGGER.error("Error while retrieving MessageFastView projection item for {}", messageId, e);
+                return Mono.empty();
+            });
     }
 
     @Override


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