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 2019/11/04 02:30:05 UTC

[james-project] 07/10: JAMES-2927 Prevent attachments to create tumbstones

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 de31975e0a6d10050b5deacd65b8c3dd050d2080
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon Oct 21 17:31:10 2019 +0700

    JAMES-2927 Prevent attachments to create tumbstones
    
    A tumbstone is created when a null value is specified in a prepared statement.
    
    This is due to the fact that null has the meaning `remove` and not the meaning `unspecified`, which is represented by no binding at all.
    
    Of course unwanted tumbstones occurs with a performance cost.
    
    The recommended method for fixing on the latest version of cassandra is to not bind the null value.
    
    Read this for further information: https://thelastpickle.com/blog/2016/09/15/Null-bindings-on-prepared-statements-and-undesired-tombstone-creation.html
---
 .../apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java
index 2848c69..0899903 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageDAO.java
@@ -213,12 +213,15 @@ public class CassandraMessageDAO {
     }
 
     private UDTValue toUDT(MessageAttachment messageAttachment) {
-        return typesProvider.getDefinedUserType(ATTACHMENTS)
+        UDTValue result = typesProvider.getDefinedUserType(ATTACHMENTS)
             .newValue()
             .setString(Attachments.ID, messageAttachment.getAttachmentId().getId())
-            .setString(Attachments.NAME, messageAttachment.getName().orElse(null))
-            .setString(Attachments.CID, messageAttachment.getCid().map(Cid::getValue).orElse(null))
             .setBool(Attachments.IS_INLINE, messageAttachment.isInline());
+        messageAttachment.getName()
+            .ifPresent(name -> result.setString(Attachments.NAME, name));
+        messageAttachment.getCid()
+            .ifPresent(cid -> result.setString(Attachments.CID, cid.getValue()));
+        return result;
     }
 
     private List<UDTValue> buildPropertiesUdt(MailboxMessage message) {


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