diff --git a/src/main/java/io/ebean/config/ServerConfig.java b/src/main/java/io/ebean/config/ServerConfig.java index e2b1af685..a3f9348c9 100644 --- a/src/main/java/io/ebean/config/ServerConfig.java +++ b/src/main/java/io/ebean/config/ServerConfig.java @@ -463,6 +463,12 @@ public class ServerConfig { */ private boolean disableL2Cache; + /** + * Generally we want to perform L2 cache notification in the background and not impact + * the performance of executing transactions. + */ + private boolean notifyL2CacheInForeground; + /** * The time in millis used to determine when a query is alerted for being slow. */ @@ -473,7 +479,6 @@ public class ServerConfig { */ private SlowQueryListener slowQueryListener; - private ProfilingConfig profilingConfig = new ProfilingConfig(); /** @@ -2680,6 +2685,7 @@ public class ServerConfig { slowQueryMillis = p.getLong("slowQueryMillis", slowQueryMillis); docStoreOnly = p.getBoolean("docStoreOnly", docStoreOnly); disableL2Cache = p.getBoolean("disableL2Cache", disableL2Cache); + notifyL2CacheInForeground = p.getBoolean("notifyL2CacheInForeground", notifyL2CacheInForeground); explicitTransactionBeginMode = p.getBoolean("explicitTransactionBeginMode", explicitTransactionBeginMode); autoCommitMode = p.getBoolean("autoCommitMode", autoCommitMode); useJtaTransactionManager = p.getBoolean("useJtaTransactionManager", useJtaTransactionManager); @@ -2900,6 +2906,25 @@ public class ServerConfig { this.disableL2Cache = disableL2Cache; } + /** + * Return true if L2 cache notification should run in the foreground. + */ + public boolean isNotifyL2CacheInForeground() { + return notifyL2CacheInForeground; + } + + /** + * Set this to true to run L2 cache notification in the foreground. + *
+ * In general we don't want to do that as when we use a distributed cache (like Ignite, Hazelcast etc) + * we are making network calls and we prefer to do this in background and not impact the response time + * of the executing transaction. + *
+ */ + public void setNotifyL2CacheInForeground(boolean notifyL2CacheInForeground) { + this.notifyL2CacheInForeground = notifyL2CacheInForeground; + } + /** * Return the query plan time to live. */ diff --git a/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java b/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java index e2da8f4b4..3702d1984 100644 --- a/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java +++ b/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java @@ -372,10 +372,10 @@ public class InternalConfiguration { public TransactionManager createTransactionManager(DocStoreUpdateProcessor indexUpdateProcessor) { TransactionScopeManager scopeManager = createTransactionScopeManager(); - boolean localL2 = cacheManager.isLocalL2Caching(); + boolean notifyL2CacheInForeground = cacheManager.isLocalL2Caching() || serverConfig.isNotifyL2CacheInForeground(); TransactionManagerOptions options = - new TransactionManagerOptions(localL2, serverConfig, scopeManager, clusterManager, backgroundExecutor, + new TransactionManagerOptions(notifyL2CacheInForeground, serverConfig, scopeManager, clusterManager, backgroundExecutor, indexUpdateProcessor, beanDescriptorManager, dataSource(), profileHandler()); if (serverConfig.isExplicitTransactionBeginMode()) { diff --git a/src/main/java/io/ebeaninternal/server/transaction/PostCommitProcessing.java b/src/main/java/io/ebeaninternal/server/transaction/PostCommitProcessing.java index 637482a2c..ac3a57560 100644 --- a/src/main/java/io/ebeaninternal/server/transaction/PostCommitProcessing.java +++ b/src/main/java/io/ebeaninternal/server/transaction/PostCommitProcessing.java @@ -86,7 +86,7 @@ public final class PostCommitProcessing { */ void notifyLocalCache() { processTableEvents(event.getEventTables()); - if (manager.localL2Caching) { + if (manager.notifyL2CacheInForeground) { // process l2 cache changes in foreground processCacheChanges(event.buildCacheChanges(manager.viewInvalidation)); } else { diff --git a/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java b/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java index d4e0379ff..b9d3ce08f 100644 --- a/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java +++ b/src/main/java/io/ebeaninternal/server/transaction/TransactionManager.java @@ -120,7 +120,7 @@ public class TransactionManager implements SpiTransactionManager { */ private final boolean changeLogAsync; - protected final boolean localL2Caching; + protected final boolean notifyL2CacheInForeground; protected final boolean viewInvalidation; @@ -144,7 +144,7 @@ public class TransactionManager implements SpiTransactionManager { this.databasePlatform = options.config.getDatabasePlatform(); this.skipCacheAfterWrite = options.config.isSkipCacheAfterWrite(); - this.localL2Caching = options.localL2Caching; + this.notifyL2CacheInForeground = options.notifyL2CacheInForeground; this.persistBatch = options.config.getPersistBatch(); this.persistBatchOnCascade = options.config.appliedPersistBatchOnCascade(); this.rollbackOnChecked = options.config.isTransactionRollbackOnChecked(); diff --git a/src/main/java/io/ebeaninternal/server/transaction/TransactionManagerOptions.java b/src/main/java/io/ebeaninternal/server/transaction/TransactionManagerOptions.java index 87a469b80..6c8c40d47 100644 --- a/src/main/java/io/ebeaninternal/server/transaction/TransactionManagerOptions.java +++ b/src/main/java/io/ebeaninternal/server/transaction/TransactionManagerOptions.java @@ -12,7 +12,7 @@ import io.ebeanservice.docstore.api.DocStoreUpdateProcessor; */ public class TransactionManagerOptions { - final boolean localL2Caching; + final boolean notifyL2CacheInForeground; final ServerConfig config; final ClusterManager clusterManager; final BackgroundExecutor backgroundExecutor; @@ -23,11 +23,11 @@ public class TransactionManagerOptions { final SpiProfileHandler profileHandler; final TransactionScopeManager scopeManager; - public TransactionManagerOptions(boolean localL2Caching, ServerConfig config, TransactionScopeManager scopeManager, ClusterManager clusterManager, + public TransactionManagerOptions(boolean notifyL2CacheInForeground, ServerConfig config, TransactionScopeManager scopeManager, ClusterManager clusterManager, BackgroundExecutor backgroundExecutor, DocStoreUpdateProcessor docStoreUpdateProcessor, BeanDescriptorManager descMgr, DataSourceSupplier dataSourceSupplier, SpiProfileHandler profileHandler) { - this.localL2Caching = localL2Caching; + this.notifyL2CacheInForeground = notifyL2CacheInForeground; this.config = config; this.scopeManager = scopeManager; this.clusterManager = clusterManager; diff --git a/src/test/java/io/ebean/config/ServerConfigTest.java b/src/test/java/io/ebean/config/ServerConfigTest.java index dbeb9cdb8..860ad9582 100644 --- a/src/test/java/io/ebean/config/ServerConfigTest.java +++ b/src/test/java/io/ebean/config/ServerConfigTest.java @@ -7,6 +7,7 @@ import org.junit.Test; import java.util.Properties; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -43,9 +44,13 @@ public class ServerConfigTest { props.setProperty("dbOffline", "true"); props.setProperty("jsonDateTime", "ISO8601"); props.setProperty("autoReadOnlyDataSource", "true"); + props.setProperty("disableL2Cache", "true"); + props.setProperty("notifyL2CacheInForeground", "true"); serverConfig.loadFromProperties(props); + assertTrue(serverConfig.isDisableL2Cache()); + assertTrue(serverConfig.isNotifyL2CacheInForeground()); assertTrue(serverConfig.isDbOffline()); assertTrue(serverConfig.isAutoReadOnlyDataSource()); @@ -66,7 +71,15 @@ public class ServerConfigTest { props1.setProperty("ebean.persistBatch", "ALL"); props1.setProperty("ebean.persistBatchOnCascade", "ALL"); + serverConfig.setNotifyL2CacheInForeground(true); + serverConfig.setDisableL2Cache(true); + props1.setProperty("ebean.disableL2Cache", "false"); + props1.setProperty("ebean.notifyL2CacheInForeground", "false"); + serverConfig.loadFromProperties(props1); + assertFalse(serverConfig.isDisableL2Cache()); + assertFalse(serverConfig.isNotifyL2CacheInForeground()); + serverConfig.loadTestProperties(); assertEquals(PersistBatch.ALL, serverConfig.getPersistBatch());