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/02 04:32:13 UTC
[james-project] 06/15: JAMES-2648 Avoid reading schemaVersion upon
each alias resolution
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 c84c807cc7210be2bcc35d65a44e7248676185c8
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Mon Mar 30 11:00:02 2020 +0700
JAMES-2648 Avoid reading schemaVersion upon each alias resolution
Reading it once upon James startup is enough for up-to-date James server.
We shall keep this pattern when James is not yet up to date.
---
.../cassandra/CassandraRecipientRewriteTable.java | 31 ++++++++++++++++------
1 file changed, 23 insertions(+), 8 deletions(-)
diff --git a/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java b/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
index 5b751a3..d28e2e2 100644
--- a/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
+++ b/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java
@@ -44,14 +44,17 @@ public class CassandraRecipientRewriteTable extends AbstractRecipientRewriteTabl
private final CassandraRecipientRewriteTableDAO cassandraRecipientRewriteTableDAO;
private final CassandraMappingsSourcesDAO cassandraMappingsSourcesDAO;
private final CassandraSchemaVersionDAO cassandraSchemaVersionDAO;
+ private final SchemaVersion initialSchemaVersion;
@Inject
- public CassandraRecipientRewriteTable(CassandraRecipientRewriteTableDAO cassandraRecipientRewriteTableDAO,
- CassandraMappingsSourcesDAO cassandraMappingsSourcesDAO,
- CassandraSchemaVersionDAO cassandraSchemaVersionDAO) {
+ CassandraRecipientRewriteTable(CassandraRecipientRewriteTableDAO cassandraRecipientRewriteTableDAO,
+ CassandraMappingsSourcesDAO cassandraMappingsSourcesDAO,
+ CassandraSchemaVersionDAO cassandraSchemaVersionDAO) {
this.cassandraRecipientRewriteTableDAO = cassandraRecipientRewriteTableDAO;
this.cassandraMappingsSourcesDAO = cassandraMappingsSourcesDAO;
this.cassandraSchemaVersionDAO = cassandraSchemaVersionDAO;
+
+ initialSchemaVersion = retrieveCurrentSchemaVersion();
}
@Override
@@ -98,14 +101,26 @@ public class CassandraRecipientRewriteTable extends AbstractRecipientRewriteTabl
Preconditions.checkArgument(listSourcesSupportedType.contains(mapping.getType()),
"Not supported mapping of type %s", mapping.getType());
- SchemaVersion schemaVersion = cassandraSchemaVersionDAO.getCurrentSchemaVersion()
- .block()
- .orElse(CassandraSchemaVersionManager.MIN_VERSION);
-
- if (schemaVersion.isBefore(MAPPINGS_SOURCES_SUPPORTED_VERSION)) {
+ if (isLegacy()) {
return super.listSources(mapping);
}
return cassandraMappingsSourcesDAO.retrieveSources(mapping).toStream();
}
+
+ private boolean isLegacy() {
+ return isLegacy(initialSchemaVersion)
+ // If we started with a legacy james then maybe schema version had been updated since then
+ || isLegacy(retrieveCurrentSchemaVersion());
+ }
+
+ private boolean isLegacy(SchemaVersion schemaVersion) {
+ return schemaVersion.isBefore(MAPPINGS_SOURCES_SUPPORTED_VERSION);
+ }
+
+ private SchemaVersion retrieveCurrentSchemaVersion() {
+ return cassandraSchemaVersionDAO.getCurrentSchemaVersion()
+ .block()
+ .orElse(CassandraSchemaVersionManager.MIN_VERSION);
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org