You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2023/04/21 04:19:42 UTC

[james-project] 05/06: JAMES-3777 JVM propoerty to disable JMAP filtering increments

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 0b7f40b2fd00019eedd68b435fe2fb8b00bae675
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Wed Apr 19 11:45:42 2023 +0700

    JAMES-3777 JVM propoerty to disable JMAP filtering increments
---
 .../cassandra-app/sample-configuration/jvm.properties    |  7 ++++++-
 .../distributed-app/sample-configuration/jvm.properties  |  5 +++++
 .../jmap/api/filtering/impl/FilteringAggregate.java      | 16 ++++++++++++----
 3 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/server/apps/cassandra-app/sample-configuration/jvm.properties b/server/apps/cassandra-app/sample-configuration/jvm.properties
index 96e4286ee1..7055fc8731 100644
--- a/server/apps/cassandra-app/sample-configuration/jvm.properties
+++ b/server/apps/cassandra-app/sample-configuration/jvm.properties
@@ -52,4 +52,9 @@ james.jmx.credential.generation=true
 
 # Disable Remote Code Execution feature from JMX
 # CF https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/19fb8f93c59dfd791f62d41f332db9e306bc1422/src/java.management/share/classes/com/sun/jmx/remote/security/MBeanServerAccessController.java#L646
-jmx.remote.x.mlet.allow.getMBeansFromURL=false
\ No newline at end of file
+jmx.remote.x.mlet.allow.getMBeansFromURL=false
+
+# Disabling JMAP filters event source increments is necessary during rolling adoption of this change.
+# Defaults to true, meaning James will use JMAP filters event source increments, thus transparently and significantly
+# improving JMAP filter storage efficiency.
+# james.jmap.filters.eventsource.increments.enabled=true
\ No newline at end of file
diff --git a/server/apps/distributed-app/sample-configuration/jvm.properties b/server/apps/distributed-app/sample-configuration/jvm.properties
index 3c62bafd29..2d5c47318e 100644
--- a/server/apps/distributed-app/sample-configuration/jvm.properties
+++ b/server/apps/distributed-app/sample-configuration/jvm.properties
@@ -53,3 +53,8 @@ james.jmx.credential.generation=true
 # Disable Remote Code Execution feature from JMX
 # CF https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/19fb8f93c59dfd791f62d41f332db9e306bc1422/src/java.management/share/classes/com/sun/jmx/remote/security/MBeanServerAccessController.java#L646
 jmx.remote.x.mlet.allow.getMBeansFromURL=false
+
+# Disabling JMAP filters event source increments is necessary during rolling adoption of this change.
+# Defaults to true, meaning James will use JMAP filters event source increments, thus transparently and significantly
+# improving JMAP filter storage efficiency.
+# james.jmap.filters.eventsource.increments.enabled=true
diff --git a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/impl/FilteringAggregate.java b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/impl/FilteringAggregate.java
index 51648f2e2b..d5ce85418d 100644
--- a/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/impl/FilteringAggregate.java
+++ b/server/data/data-jmap/src/main/java/org/apache/james/jmap/api/filtering/impl/FilteringAggregate.java
@@ -34,6 +34,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 
 public class FilteringAggregate {
+    private static final boolean ENABLE_INCREMENTS = Boolean.parseBoolean(System.getProperty("james.jmap.filters.eventsource.increments.enabled", "true"));
 
     public static FilteringAggregate load(FilteringAggregateId aggregateId, History eventsOfAggregate) {
         return new FilteringAggregate(aggregateId, eventsOfAggregate);
@@ -70,14 +71,21 @@ public class FilteringAggregate {
     public List<? extends Event> defineRules(DefineRulesCommand storeCommand) {
         Preconditions.checkArgument(shouldNotContainDuplicates(storeCommand.getRules()));
         StateMismatchException.checkState(expectedState(storeCommand.getIfInState()), "Provided state must be as same as the current state");
-
-        ImmutableList<Event> events = IncrementalRuleChange.ofDiff(aggregateId, history.getNextEventId(), state.rules, storeCommand.getRules())
-            .map(ImmutableList::<Event>of)
-            .orElseGet(() -> ImmutableList.of(new RuleSetDefined(aggregateId, history.getNextEventId(), ImmutableList.copyOf(storeCommand.getRules()))));
+        ImmutableList<Event> events = generateEvents(storeCommand);
         events.forEach(this::apply);
         return events;
     }
 
+    private ImmutableList<Event> generateEvents(DefineRulesCommand storeCommand) {
+        if (ENABLE_INCREMENTS) {
+            return IncrementalRuleChange.ofDiff(aggregateId, history.getNextEventId(), state.rules, storeCommand.getRules())
+                .map(ImmutableList::<Event>of)
+                .orElseGet(() -> ImmutableList.of(new RuleSetDefined(aggregateId, history.getNextEventId(), ImmutableList.copyOf(storeCommand.getRules()))));
+        } else {
+            return ImmutableList.of(new RuleSetDefined(aggregateId, history.getNextEventId(), ImmutableList.copyOf(storeCommand.getRules())));
+        }
+    }
+
     private boolean shouldNotContainDuplicates(List<Rule> rules) {
         long uniqueIdCount = rules.stream()
             .map(Rule::getId)


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