mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-12-03 07:42:04 +00:00
#1427 - QueryCache should be cleared, if one of a dependent bean is updated
Refactor on PostCommitProcessing with fixes for dependent table invalidation
This commit is contained in:
1 parent
9159cec36c
commit
ed566ca153
19 files changed
+262
-127
No files matched your search
@@ -3,7 +3,9 @@ package io.ebeaninternal.api;
|
||||
import io.ebeaninternal.server.cache.CacheChangeSet;
|
||||
import io.ebeaninternal.server.core.PersistRequestBean;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptorManager;
|
||||
import io.ebeaninternal.server.transaction.DeleteByIdMap;
|
||||
import io.ebeaninternal.server.transaction.TransactionManager;
|
||||
import io.ebeanservice.docstore.api.DocStoreUpdates;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -27,8 +29,6 @@ public class TransactionEvent implements Serializable {
|
||||
*/
|
||||
private final transient boolean local;
|
||||
|
||||
private final long modificationTimestamp;
|
||||
|
||||
private TransactionEventTable eventTables;
|
||||
|
||||
private transient TransactionEventBeans eventBeans;
|
||||
@@ -38,9 +38,8 @@ public class TransactionEvent implements Serializable {
|
||||
/**
|
||||
* Create the TransactionEvent, one per Transaction.
|
||||
*/
|
||||
public TransactionEvent(long modificationTimestamp) {
|
||||
public TransactionEvent() {
|
||||
this.local = true;
|
||||
this.modificationTimestamp = modificationTimestamp;
|
||||
}
|
||||
|
||||
public void addDeleteById(BeanDescriptor<?> desc, Object id) {
|
||||
@@ -111,8 +110,20 @@ public class TransactionEvent implements Serializable {
|
||||
/**
|
||||
* Build and return the cache changeSet.
|
||||
*/
|
||||
public CacheChangeSet buildCacheChanges() {
|
||||
CacheChangeSet changeSet = new CacheChangeSet(modificationTimestamp);
|
||||
public CacheChangeSet buildCacheChanges(TransactionManager manager) {
|
||||
|
||||
if (eventBeans == null && deleteByIdMap == null && eventTables == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
CacheChangeSet changeSet = new CacheChangeSet(manager.clockNowMillis());
|
||||
if (eventTables != null && !eventTables.isEmpty()) {
|
||||
// notify cache with table based changes
|
||||
BeanDescriptorManager dm = manager.getBeanDescriptorManager();
|
||||
for (TransactionEventTable.TableIUD tableIUD : eventTables.values()) {
|
||||
dm.cacheNotify(tableIUD, changeSet);
|
||||
}
|
||||
}
|
||||
if (eventBeans != null) {
|
||||
eventBeans.notifyCache(changeSet);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,6 @@ class CacheChangeBeanUpdate implements CacheChange {
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
desc.cacheBeanUpdate(id, changes, updateNaturalKey, version);
|
||||
desc.cacheApplyBeanUpdate(id, changes, updateNaturalKey, version);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,8 @@ public class CacheChangeSet {
|
||||
|
||||
private final Set<BeanDescriptor<?>> queryCaches = new HashSet<>();
|
||||
|
||||
private final Set<BeanDescriptor<?>> beanCaches = new HashSet<>();
|
||||
|
||||
private final Map<BeanDescriptor<?>, CacheChangeBeanRemove> beanRemoveMap = new HashMap<>();
|
||||
|
||||
private final Map<ManyKey, ManyChange> manyChangeMap = new HashMap<>();
|
||||
@@ -51,6 +53,9 @@ public class CacheChangeSet {
|
||||
for (BeanDescriptor<?> entry : queryCaches) {
|
||||
entry.clearQueryCache();
|
||||
}
|
||||
for (BeanDescriptor<?> entry : beanCaches) {
|
||||
entry.clearBeanCache();
|
||||
}
|
||||
for (CacheChange entry : entries) {
|
||||
entry.apply();
|
||||
}
|
||||
@@ -69,6 +74,13 @@ public class CacheChangeSet {
|
||||
touchedTables.add(descriptor.getBaseTable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add invalidation on a set of tables.
|
||||
*/
|
||||
public void addInvalidate(Set<String> tables) {
|
||||
touchedTables.addAll(tables);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an entry to clear a query cache.
|
||||
*/
|
||||
@@ -76,6 +88,13 @@ public class CacheChangeSet {
|
||||
queryCaches.add(descriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an entry to clear a bean cache.
|
||||
*/
|
||||
public void addClearBean(BeanDescriptor<?> descriptor) {
|
||||
beanCaches.add(descriptor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add many property clear.
|
||||
*/
|
||||
|
||||
@@ -384,8 +384,8 @@ public final class OrmQueryRequest<T> extends BeanRequest implements SpiOrmQuery
|
||||
}
|
||||
|
||||
private int notifyCache(int rows, boolean update) {
|
||||
if (rows > 0 && beanDescriptor.isCaching()) {
|
||||
transaction.getEvent().add(beanDescriptor.getBaseTable(), false, update, !update);
|
||||
if (rows > 0) {
|
||||
beanDescriptor.cacheUpdateQuery(update, transaction);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
@@ -450,14 +450,14 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
|
||||
if (notifyCache) {
|
||||
switch (type) {
|
||||
case INSERT:
|
||||
beanDescriptor.cacheHandleInsert(this, changeSet);
|
||||
beanDescriptor.cachePersistInsert(this, changeSet);
|
||||
break;
|
||||
case UPDATE:
|
||||
beanDescriptor.cacheHandleUpdate(idValue, this, changeSet);
|
||||
beanDescriptor.cachePersistUpdate(idValue, this, changeSet);
|
||||
break;
|
||||
case DELETE:
|
||||
case DELETE_SOFT:
|
||||
beanDescriptor.cacheHandleDelete(idValue, this, changeSet);
|
||||
beanDescriptor.cachePersistDelete(idValue, this, changeSet);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Invalid type " + type);
|
||||
|
||||
@@ -40,6 +40,7 @@ import io.ebeaninternal.api.ConcurrencyMode;
|
||||
import io.ebeaninternal.api.LoadContext;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.api.SpiQuery;
|
||||
import io.ebeaninternal.api.SpiTransaction;
|
||||
import io.ebeaninternal.api.SpiUpdatePlan;
|
||||
import io.ebeaninternal.api.TransactionEventTable.TableIUD;
|
||||
import io.ebeaninternal.api.json.SpiJsonReader;
|
||||
@@ -828,8 +829,11 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void initialiseDocMapping() {
|
||||
for (BeanPropertyAssocMany<?> aPropertiesMany : propertiesMany) {
|
||||
aPropertiesMany.initialisePostTarget();
|
||||
for (BeanPropertyAssocMany<?> many : propertiesMany) {
|
||||
many.initialisePostTarget();
|
||||
}
|
||||
for (BeanPropertyAssocOne<?> one : propertiesOne) {
|
||||
one.initialisePostTarget();
|
||||
}
|
||||
if (inheritInfo != null && !inheritInfo.isRoot()) {
|
||||
docStoreAdapter = (DocStoreBeanAdapter<T>) inheritInfo.getRoot().desc().docStoreAdapter();
|
||||
@@ -1366,13 +1370,6 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
cacheHelp.queryCachePut(id, entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a query cache clear into the changeSet.
|
||||
*/
|
||||
public void queryCacheClear(CacheChangeSet changeSet) {
|
||||
cacheHelp.queryCacheClear(changeSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to load the beanCollection from cache return true if successful.
|
||||
*/
|
||||
@@ -1469,13 +1466,6 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
return cacheHelp.beanCacheGet(id, readOnly, context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a bean from the cache given its Id.
|
||||
*/
|
||||
public void cacheHandleDeleteByIds(Collection<Object> ids, CacheChangeSet changeSet) {
|
||||
cacheHelp.handleDeleteIds(ids, changeSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a collection of beans from the cache given the ids.
|
||||
*/
|
||||
@@ -1510,38 +1500,52 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
cacheHelp.cacheNaturalKeyPut(id, newKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if bulk update or delete query has a cache impact.
|
||||
*/
|
||||
public void cacheUpdateQuery(boolean update, SpiTransaction transaction) {
|
||||
cacheHelp.cacheUpdateQuery(update, transaction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invalidate parts of cache due to SqlUpdate or external modification etc.
|
||||
*/
|
||||
public void cacheHandleBulkUpdate(TableIUD tableIUD) {
|
||||
cacheHelp.handleBulkUpdate(tableIUD);
|
||||
public void cachePersistTableIUD(TableIUD tableIUD, CacheChangeSet changeSet) {
|
||||
cacheHelp.persistTableIUD(tableIUD, changeSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a bean from the cache given its Id.
|
||||
*/
|
||||
public void cacheHandleDelete(Object id, PersistRequestBean<T> deleteRequest, CacheChangeSet changeSet) {
|
||||
cacheHelp.handleDelete(id, deleteRequest, changeSet);
|
||||
public void cachePersistDeleteByIds(Collection<Object> ids, CacheChangeSet changeSet) {
|
||||
cacheHelp.persistDeleteIds(ids, changeSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a bean from the cache given its Id.
|
||||
*/
|
||||
public void cachePersistDelete(Object id, PersistRequestBean<T> deleteRequest, CacheChangeSet changeSet) {
|
||||
cacheHelp.persistDelete(id, deleteRequest, changeSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the insert changes to the changeSet.
|
||||
*/
|
||||
public void cacheHandleInsert(PersistRequestBean<T> insertRequest, CacheChangeSet changeSet) {
|
||||
cacheHelp.handleInsert(insertRequest, changeSet);
|
||||
public void cachePersistInsert(PersistRequestBean<T> insertRequest, CacheChangeSet changeSet) {
|
||||
cacheHelp.persistInsert(insertRequest, changeSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the update to the changeSet.
|
||||
*/
|
||||
public void cacheHandleUpdate(Object id, PersistRequestBean<T> updateRequest, CacheChangeSet changeSet) {
|
||||
cacheHelp.handleUpdate(id, updateRequest, changeSet);
|
||||
public void cachePersistUpdate(Object id, PersistRequestBean<T> updateRequest, CacheChangeSet changeSet) {
|
||||
cacheHelp.persistUpdate(id, updateRequest, changeSet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the update to the cache.
|
||||
*/
|
||||
public void cacheBeanUpdate(Object id, Map<String, Object> changes, boolean updateNaturalKey, long version) {
|
||||
public void cacheApplyBeanUpdate(Object id, Map<String, Object> changes, boolean updateNaturalKey, long version) {
|
||||
cacheHelp.cacheBeanUpdate(id, changes, updateNaturalKey, version);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import io.ebean.bean.PersistenceContext;
|
||||
import io.ebean.cache.QueryCacheEntry;
|
||||
import io.ebean.cache.ServerCache;
|
||||
import io.ebeaninternal.api.BeanCacheResult;
|
||||
import io.ebeaninternal.api.SpiTransaction;
|
||||
import io.ebeaninternal.api.TransactionEventTable.TableIUD;
|
||||
import io.ebeaninternal.server.cache.CacheChangeSet;
|
||||
import io.ebeaninternal.server.cache.CachedBeanData;
|
||||
@@ -68,6 +69,8 @@ final class BeanDescriptorCacheHelp<T> {
|
||||
private final ServerCache naturalKeyCache;
|
||||
private final ServerCache queryCache;
|
||||
|
||||
private final boolean noCaching;
|
||||
|
||||
/**
|
||||
* Set to true if all persist changes need to notify the cache.
|
||||
*/
|
||||
@@ -108,6 +111,7 @@ final class BeanDescriptorCacheHelp<T> {
|
||||
this.beanCache = null;
|
||||
this.naturalKeyCache = null;
|
||||
}
|
||||
this.noCaching = (beanCache == null && queryCache == null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +136,7 @@ final class BeanDescriptorCacheHelp<T> {
|
||||
*/
|
||||
private boolean isNotifyOnDeletes() {
|
||||
for (BeanPropertyAssocOne<?> imported : propertiesOneImported) {
|
||||
if (imported.isCacheNotify()) {
|
||||
if (imported.isCacheNotifyRelationship()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -722,10 +726,16 @@ final class BeanDescriptorCacheHelp<T> {
|
||||
return true;
|
||||
}
|
||||
|
||||
void cacheUpdateQuery(boolean update, SpiTransaction transaction) {
|
||||
if (invalidateQueryCache || cacheNotifyOnAll || (!update && cacheNotifyOnDelete)) {
|
||||
transaction.getEvent().add(desc.getBaseTable(), false, update, !update);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add appropriate cache changes to support delete by id.
|
||||
*/
|
||||
void handleDeleteIds(Collection<Object> ids, CacheChangeSet changeSet) {
|
||||
void persistDeleteIds(Collection<Object> ids, CacheChangeSet changeSet) {
|
||||
if (invalidateQueryCache) {
|
||||
changeSet.addInvalidate(desc);
|
||||
} else {
|
||||
@@ -739,7 +749,7 @@ final class BeanDescriptorCacheHelp<T> {
|
||||
/**
|
||||
* Add appropriate cache changes to support delete bean.
|
||||
*/
|
||||
void handleDelete(Object id, PersistRequestBean<T> deleteRequest, CacheChangeSet changeSet) {
|
||||
void persistDelete(Object id, PersistRequestBean<T> deleteRequest, CacheChangeSet changeSet) {
|
||||
if (invalidateQueryCache) {
|
||||
changeSet.addInvalidate(desc);
|
||||
} else {
|
||||
@@ -754,7 +764,7 @@ final class BeanDescriptorCacheHelp<T> {
|
||||
/**
|
||||
* Add appropriate cache changes to support insert.
|
||||
*/
|
||||
void handleInsert(PersistRequestBean<T> insertRequest, CacheChangeSet changeSet) {
|
||||
void persistInsert(PersistRequestBean<T> insertRequest, CacheChangeSet changeSet) {
|
||||
if (invalidateQueryCache) {
|
||||
changeSet.addInvalidate(desc);
|
||||
} else {
|
||||
@@ -773,7 +783,7 @@ final class BeanDescriptorCacheHelp<T> {
|
||||
/**
|
||||
* Add appropriate changes to support update.
|
||||
*/
|
||||
void handleUpdate(Object id, PersistRequestBean<T> updateRequest, CacheChangeSet changeSet) {
|
||||
void persistUpdate(Object id, PersistRequestBean<T> updateRequest, CacheChangeSet changeSet) {
|
||||
if (invalidateQueryCache) {
|
||||
changeSet.addInvalidate(desc);
|
||||
|
||||
@@ -803,16 +813,24 @@ final class BeanDescriptorCacheHelp<T> {
|
||||
/**
|
||||
* Invalidate parts of cache due to SqlUpdate or external modification etc.
|
||||
*/
|
||||
void handleBulkUpdate(TableIUD tableIUD) {
|
||||
void persistTableIUD(TableIUD tableIUD, CacheChangeSet changeSet) {
|
||||
if (invalidateQueryCache) {
|
||||
changeSet.addInvalidate(desc);
|
||||
return;
|
||||
}
|
||||
if (noCaching) {
|
||||
return;
|
||||
}
|
||||
changeSet.addInvalidate(desc);
|
||||
// inserts don't invalidate the bean cache
|
||||
if (tableIUD.isUpdateOrDelete()) {
|
||||
beanCacheClear();
|
||||
changeSet.addClearBean(desc);
|
||||
}
|
||||
// any change invalidates the query cache
|
||||
queryCacheClear();
|
||||
changeSet.addClearQuery(desc);
|
||||
// any change invalidates the collection IDs cache
|
||||
for (BeanPropertyAssocOne<?> imported : propertiesOneImported) {
|
||||
imported.cacheClear();
|
||||
imported.cacheClear(changeSet);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import io.ebean.util.AnnotationUtil;
|
||||
import io.ebeaninternal.api.ConcurrencyMode;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.api.TransactionEventTable;
|
||||
import io.ebeaninternal.server.cache.CacheChangeSet;
|
||||
import io.ebeaninternal.server.cache.SpiCacheManager;
|
||||
import io.ebeaninternal.server.core.InternString;
|
||||
import io.ebeaninternal.server.core.InternalConfiguration;
|
||||
@@ -449,21 +450,21 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
/**
|
||||
* For SQL based modifications we need to invalidate appropriate parts of the cache.
|
||||
*/
|
||||
public void cacheNotify(TransactionEventTable.TableIUD tableIUD) {
|
||||
public void cacheNotify(TransactionEventTable.TableIUD tableIUD, CacheChangeSet changeSet) {
|
||||
|
||||
String tableName = tableIUD.getTableName().toLowerCase();
|
||||
List<BeanDescriptor<?>> normalBeanTypes = tableToDescMap.get(tableName);
|
||||
if (normalBeanTypes != null) {
|
||||
// 'normal' entity beans based on a "base table"
|
||||
for (BeanDescriptor<?> normalBeanType : normalBeanTypes) {
|
||||
normalBeanType.cacheHandleBulkUpdate(tableIUD);
|
||||
normalBeanType.cachePersistTableIUD(tableIUD, changeSet);
|
||||
}
|
||||
}
|
||||
List<BeanDescriptor<?>> viewBeans = tableToViewDescMap.get(tableName);
|
||||
if (viewBeans != null) {
|
||||
// entity beans based on a "view"
|
||||
for (BeanDescriptor<?> viewBean : viewBeans) {
|
||||
viewBean.cacheHandleBulkUpdate(tableIUD);
|
||||
viewBean.cachePersistTableIUD(tableIUD, changeSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
|
||||
private String deleteByParentIdInSql;
|
||||
|
||||
private BeanPropertyAssocMany<?> relationshipProperty;
|
||||
private boolean cacheNotifyRelationship;
|
||||
|
||||
/**
|
||||
* Create based on deploy information of an EmbeddedId.
|
||||
@@ -127,6 +128,13 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Derive late in lifecycle cache notification on this relationship.
|
||||
*/
|
||||
public void initialisePostTarget() {
|
||||
this.cacheNotifyRelationship = isCacheNotifyRelationship();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the property value as an entity bean.
|
||||
*/
|
||||
@@ -141,25 +149,31 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
|
||||
/**
|
||||
* Return true if this relationship needs to maintain/update L2 cache.
|
||||
*/
|
||||
boolean isCacheNotify() {
|
||||
return targetDescriptor.isBeanCaching() && relationshipProperty != null;
|
||||
boolean isCacheNotifyRelationship() {
|
||||
return relationshipProperty != null && targetDescriptor.isBeanCaching();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the L2 relationship cache for this property.
|
||||
*/
|
||||
void cacheClear() {
|
||||
if (isCacheNotify()) {
|
||||
if (cacheNotifyRelationship) {
|
||||
targetDescriptor.cacheManyPropClear(relationshipProperty.getName());
|
||||
}
|
||||
}
|
||||
|
||||
void cacheClear(CacheChangeSet changeSet) {
|
||||
if (cacheNotifyRelationship) {
|
||||
changeSet.addManyClear(targetDescriptor, relationshipProperty.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear part of the L2 relationship cache for this property.
|
||||
*/
|
||||
void cacheDelete(boolean clear, EntityBean bean, CacheChangeSet changeSet) {
|
||||
|
||||
if (isCacheNotify()) {
|
||||
if (cacheNotifyRelationship) {
|
||||
if (clear) {
|
||||
changeSet.addManyClear(targetDescriptor, relationshipProperty.getName());
|
||||
} else {
|
||||
|
||||
@@ -4,6 +4,7 @@ import io.ebeaninternal.api.BinaryReadContext;
|
||||
import io.ebeaninternal.api.BinaryWritable;
|
||||
import io.ebeaninternal.api.BinaryWriteContext;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.server.cache.CacheChangeSet;
|
||||
import io.ebeaninternal.server.core.PersistRequest;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.deploy.id.IdBinder;
|
||||
@@ -126,11 +127,10 @@ public class BeanPersistIds implements BinaryWritable {
|
||||
/**
|
||||
* Notify the cache of this event that came from another server in the cluster.
|
||||
*/
|
||||
void notifyCacheAndListener() {
|
||||
// any change invalidates the query cache
|
||||
beanDescriptor.clearQueryCache();
|
||||
public void notifyCache(CacheChangeSet changeSet) {
|
||||
changeSet.addClearQuery(beanDescriptor);
|
||||
if (ids != null) {
|
||||
beanDescriptor.cacheApplyInvalidate(ids);
|
||||
changeSet.addBeanRemoveMany(beanDescriptor, ids);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public final class DeleteByIdMap {
|
||||
BeanDescriptor<?> d = deleteIds.getBeanDescriptor();
|
||||
List<Object> idValues = deleteIds.getIds();
|
||||
if (idValues != null) {
|
||||
d.cacheHandleDeleteByIds(idValues, changeSet);
|
||||
d.cachePersistDeleteByIds(idValues, changeSet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -855,7 +855,7 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
||||
public TransactionEvent getEvent() {
|
||||
queryOnly = false;
|
||||
if (event == null) {
|
||||
event = new TransactionEvent(startMillis);
|
||||
event = new TransactionEvent();
|
||||
}
|
||||
return event;
|
||||
}
|
||||
@@ -1052,7 +1052,7 @@ public class JdbcTransaction implements SpiTransaction, TxnProfileEventCodes {
|
||||
// the event has been sent to the transaction manager
|
||||
// for postCommit processing (l2 cache updates etc)
|
||||
// start a new transaction event
|
||||
event = new TransactionEvent(startMillis);
|
||||
event = new TransactionEvent();
|
||||
|
||||
} catch (Exception e) {
|
||||
doRollback(e);
|
||||
|
||||
@@ -8,7 +8,6 @@ import io.ebeaninternal.api.TransactionEventTable.TableIUD;
|
||||
import io.ebeaninternal.server.cache.CacheChangeSet;
|
||||
import io.ebeaninternal.server.cluster.ClusterManager;
|
||||
import io.ebeaninternal.server.core.PersistRequestBean;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptorManager;
|
||||
import io.ebeanservice.docstore.api.DocStoreUpdates;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -46,8 +45,6 @@ final class PostCommitProcessing {
|
||||
|
||||
private final int txnDocStoreBatchSize;
|
||||
|
||||
private CacheChangeSet cacheChanges;
|
||||
|
||||
/**
|
||||
* Create for an external modification.
|
||||
*/
|
||||
@@ -83,31 +80,12 @@ final class PostCommitProcessing {
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the local part of L2 cache.
|
||||
* Perform foreground cache notification if desired.
|
||||
*/
|
||||
void notifyLocalCache() {
|
||||
processTableEvents(event.getEventTables());
|
||||
if (manager.notifyL2CacheInForeground) {
|
||||
// process l2 cache changes in foreground
|
||||
processCacheChanges(event.buildCacheChanges());
|
||||
} else {
|
||||
// collect l2 cache changes for delayed background processing
|
||||
cacheChanges = event.buildCacheChanges();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Table events are where SQL or external tools are used. In this case the
|
||||
* cache is notified based on the table name (rather than bean type).
|
||||
*/
|
||||
private void processTableEvents(TransactionEventTable tableEvents) {
|
||||
|
||||
if (tableEvents != null && !tableEvents.isEmpty()) {
|
||||
// notify cache with table based changes
|
||||
BeanDescriptorManager dm = manager.getBeanDescriptorManager();
|
||||
for (TableIUD tableIUD : tableEvents.values()) {
|
||||
dm.cacheNotify(tableIUD);
|
||||
}
|
||||
processCacheChanges();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +132,9 @@ final class PostCommitProcessing {
|
||||
*/
|
||||
Runnable backgroundNotify() {
|
||||
return () -> {
|
||||
processCacheChanges(cacheChanges);
|
||||
if (!manager.notifyL2CacheInForeground) {
|
||||
processCacheChanges();
|
||||
}
|
||||
localPersistListenersNotify();
|
||||
notifyCluster();
|
||||
processDocStoreUpdates();
|
||||
@@ -164,7 +144,8 @@ final class PostCommitProcessing {
|
||||
/**
|
||||
* Apply the changes to the L2 caches.
|
||||
*/
|
||||
private void processCacheChanges(CacheChangeSet cacheChanges) {
|
||||
private void processCacheChanges() {
|
||||
CacheChangeSet cacheChanges = event.buildCacheChanges(manager);
|
||||
if (cacheChanges != null) {
|
||||
Set<String> touched = cacheChanges.touchedTables();
|
||||
if (touched != null && !touched.isEmpty()) {
|
||||
|
||||
@@ -38,7 +38,7 @@ public class TableModState implements QueryCacheEntryValidate, ServerCacheNotify
|
||||
tableModStamp.put(tableName, modTimestamp);
|
||||
}
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("TableModState updated - " + tableModStamp);
|
||||
log.debug("TableModState updated - touched:{} modTimestamp:{}", touchedTables, modTimestamp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,10 @@ public class TableModState implements QueryCacheEntryValidate, ServerCacheNotify
|
||||
boolean isValid(Set<String> tables, long sinceTimestamp) {
|
||||
for (String tableName : tables) {
|
||||
Long modTime = tableModStamp.get(tableName);
|
||||
if (modTime != null && modTime > sinceTimestamp ) {
|
||||
if (modTime != null && modTime >= sinceTimestamp ) {
|
||||
if (log.isTraceEnabled()) {
|
||||
log.trace("Invalidate on table:{}", tableName);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -75,6 +78,9 @@ public class TableModState implements QueryCacheEntryValidate, ServerCacheNotify
|
||||
|
||||
// use local clock - for slightly more aggressive invalidation (as later)
|
||||
// that removes any concern regarding clock syncing across cluster
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("ServerCacheNotification:{}", notification);
|
||||
}
|
||||
touch(notification.getDependentTables(), clockService.nowMillis());
|
||||
}
|
||||
|
||||
@@ -88,6 +94,9 @@ public class TableModState implements QueryCacheEntryValidate, ServerCacheNotify
|
||||
|
||||
// use local clock - for slightly more aggressive invalidation (as later)
|
||||
// that removes any concern regarding clock syncing across cluster
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("RemoteTableMod:{}", tableMod);
|
||||
}
|
||||
touch(tableMod.getTables(), clockService.nowMillis());
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import io.ebeaninternal.api.TransactionEventTable.TableIUD;
|
||||
import io.ebeaninternal.metric.MetricFactory;
|
||||
import io.ebeaninternal.metric.TimedMetric;
|
||||
import io.ebeaninternal.metric.TimedMetricMap;
|
||||
import io.ebeaninternal.server.cache.CacheChangeSet;
|
||||
import io.ebeaninternal.server.cluster.ClusterManager;
|
||||
import io.ebeaninternal.server.core.ClockService;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptorManager;
|
||||
@@ -451,7 +452,7 @@ public class TransactionManager implements SpiTransactionManager {
|
||||
|
||||
private void externalModificationEvent(TransactionEventTable tableEvents) {
|
||||
|
||||
TransactionEvent event = new TransactionEvent(clockNowMillis());
|
||||
TransactionEvent event = new TransactionEvent();
|
||||
event.add(tableEvents);
|
||||
|
||||
PostCommitProcessing postCommit = new PostCommitProcessing(clusterManager, this, event);
|
||||
@@ -468,15 +469,17 @@ public class TransactionManager implements SpiTransactionManager {
|
||||
clusterLogger.debug("processing {}", remoteEvent);
|
||||
}
|
||||
|
||||
CacheChangeSet changeSet = new CacheChangeSet(clockNowMillis());
|
||||
|
||||
RemoteTableMod tableMod = remoteEvent.getRemoteTableMod();
|
||||
if (tableMod != null) {
|
||||
tableModState.notify(tableMod);
|
||||
changeSet.addInvalidate(tableMod.getTables());
|
||||
}
|
||||
|
||||
List<TableIUD> tableIUDList = remoteEvent.getTableIUDList();
|
||||
if (tableIUDList != null) {
|
||||
for (TableIUD tableIUD : tableIUDList) {
|
||||
beanDescriptorManager.cacheNotify(tableIUD);
|
||||
beanDescriptorManager.cacheNotify(tableIUD, changeSet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -484,10 +487,12 @@ public class TransactionManager implements SpiTransactionManager {
|
||||
// processes both Bean IUD and DeleteById
|
||||
List<BeanPersistIds> beanPersistList = remoteEvent.getBeanPersistList();
|
||||
if (beanPersistList != null) {
|
||||
for (BeanPersistIds aBeanPersistList : beanPersistList) {
|
||||
aBeanPersistList.notifyCacheAndListener();
|
||||
for (BeanPersistIds persistIds : beanPersistList) {
|
||||
persistIds.notifyCache(changeSet);
|
||||
}
|
||||
}
|
||||
|
||||
changeSet.apply();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user