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:07 UTC
[james-project] 09/10: JAMES-2927 Avoid un-intentional tumbstones
in Cassandra mail repository
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 89ee810392033394610365e054cfdf2016b5aeec
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon Oct 21 23:32:49 2019 +0200
JAMES-2927 Avoid un-intentional tumbstones in Cassandra mail repository
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
---
.../cassandra/CassandraMailRepositoryMailDAO.java | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryMailDAO.java b/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryMailDAO.java
index d4d05f5..981bf42 100644
--- a/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryMailDAO.java
+++ b/server/mailrepository/mailrepository-cassandra/src/main/java/org/apache/james/mailrepository/cassandra/CassandraMailRepositoryMailDAO.java
@@ -75,6 +75,7 @@ import org.apache.mailet.AttributeValue;
import org.apache.mailet.Mail;
import org.apache.mailet.PerRecipientHeaders;
+import com.datastax.driver.core.BoundStatement;
import com.datastax.driver.core.PreparedStatement;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
@@ -143,21 +144,30 @@ public class CassandraMailRepositoryMailDAO implements CassandraMailRepositoryMa
@Override
public Mono<Void> store(MailRepositoryUrl url, Mail mail, BlobId headerId, BlobId bodyId) {
- return Mono.fromCallable(() -> insertMail.bind()
+ return Mono.fromCallable(() -> {
+ BoundStatement boundStatement = insertMail.bind()
.setString(REPOSITORY_NAME, url.asString())
.setString(MAIL_KEY, mail.getName())
.setString(HEADER_BLOB_ID, headerId.asString())
.setString(BODY_BLOB_ID, bodyId.asString())
.setString(STATE, mail.getState())
- .setString(SENDER, mail.getMaybeSender().asString(null))
.setList(RECIPIENTS, asStringList(mail.getRecipients()))
- .setString(ERROR_MESSAGE, mail.getErrorMessage())
.setString(REMOTE_ADDR, mail.getRemoteAddr())
.setString(REMOTE_HOST, mail.getRemoteHost())
.setLong(MESSAGE_SIZE, mail.getMessageSize())
.setTimestamp(LAST_UPDATED, mail.getLastUpdated())
.setMap(ATTRIBUTES, toRawAttributeMap(mail))
- .setMap(PER_RECIPIENT_SPECIFIC_HEADERS, toHeaderMap(mail.getPerRecipientSpecificHeaders())))
+ .setMap(PER_RECIPIENT_SPECIFIC_HEADERS, toHeaderMap(mail.getPerRecipientSpecificHeaders()));
+
+ Optional.ofNullable(mail.getErrorMessage())
+ .ifPresent(errorMessage -> boundStatement.setString(ERROR_MESSAGE, mail.getErrorMessage()));
+
+ mail.getMaybeSender()
+ .asOptional()
+ .map(MailAddress::asString)
+ .ifPresent(mailAddress -> boundStatement.setString(SENDER, mailAddress));
+ return boundStatement;
+ })
.flatMap(executor::executeVoid);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org