#1427 - RemoteTransactionEvent process dependent tables

This commit is contained in:
rob bygrave
2018-06-19 00:50:14 +12:00
parent 3a64cf6952
commit 43e95d81f6
12 changed files with 56 additions and 19 deletions
@@ -53,7 +53,7 @@ public class RemoteCacheEvent implements BinaryWritable {
@Override
public String toString() {
return "clearAll:" + clearAll + " caches:" + clearCaches;
return "CacheEvent[ clearAll:" + clearAll + " caches:" + clearCaches + "]";
}
public static RemoteCacheEvent readBinaryMessage(BinaryReadContext dataInput) throws IOException {
@@ -106,7 +106,7 @@ public class InternalConfiguration {
private static final Logger logger = LoggerFactory.getLogger(InternalConfiguration.class);
private final TableModState tableModState = new TableModState();
private final TableModState tableModState;
private final boolean online;
@@ -169,6 +169,7 @@ public class InternalConfiguration {
this.online = online;
this.serverConfig = serverConfig;
this.clockService = new ClockService(serverConfig.getClock());
this.tableModState = new TableModState(clockService);
this.logManager = initLogManager();
this.docStoreFactory = initDocStoreFactory(serverConfig.service(DocStoreFactory.class));
this.jsonFactory = serverConfig.getJsonFactory();
@@ -1517,13 +1517,6 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
cacheHelp.handleBulkUpdate(tableIUD);
}
/**
* Handle a delete by id request adding an cache change into the changeSet.
*/
public void cacheHandleDeleteById(Object id, CacheChangeSet changeSet) {
cacheHelp.handleDelete(id, changeSet);
}
/**
* Remove a bean from the cache given its Id.
*/
@@ -447,8 +447,7 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
}
/**
* For SQL based modifications we need to invalidate appropriate parts of the
* cache.
* For SQL based modifications we need to invalidate appropriate parts of the cache.
*/
public void cacheNotify(TransactionEventTable.TableIUD tableIUD) {
@@ -94,6 +94,7 @@ public class BeanPersistIds implements BinaryWritable {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("BeanIds[");
if (beanDescriptor != null) {
sb.append(beanDescriptor.getFullName());
} else {
@@ -102,6 +103,7 @@ public class BeanPersistIds implements BinaryWritable {
if (ids != null) {
sb.append(" ids:").append(ids);
}
sb.append("]");
return sb.toString();
}
@@ -7,7 +7,6 @@ import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeanservice.docstore.api.DocStoreUpdates;
import io.ebeanservice.docstore.api.support.DocStoreDeleteEvent;
import java.io.Serializable;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
@@ -22,7 +21,7 @@ public final class DeleteByIdMap {
@Override
public String toString() {
return beanMap.toString();
return "DeleteById[" + beanMap.values() + "]";
}
public void notifyCache(CacheChangeSet changeSet) {
@@ -20,6 +20,11 @@ public class RemoteTableMod implements BinaryWritable {
this.tables = tables;
}
@Override
public String toString() {
return "TableMod[" + timestamp + "; " + tables + "]";
}
public long getTimestamp() {
return timestamp;
}
@@ -52,6 +52,10 @@ public class RemoteTransactionEvent implements Runnable, BinaryWritable {
@Override
public String toString() {
StringBuilder sb = new StringBuilder(100);
sb.append("TransEvent[");
if (remoteTableMod != null) {
sb.append(remoteTableMod);
}
if (!beanPersistList.isEmpty()) {
sb.append(beanPersistList);
}
@@ -59,8 +63,9 @@ public class RemoteTransactionEvent implements Runnable, BinaryWritable {
sb.append(tableList);
}
if (deleteByIdMap != null) {
sb.append(deleteByIdMap.values());
sb.append(deleteByIdMap);
}
sb.append("]");
return sb.toString();
}
@@ -4,6 +4,7 @@ import io.ebean.cache.QueryCacheEntry;
import io.ebean.cache.QueryCacheEntryValidate;
import io.ebean.cache.ServerCacheNotification;
import io.ebean.cache.ServerCacheNotify;
import io.ebeaninternal.server.core.ClockService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -21,8 +22,14 @@ public class TableModState implements QueryCacheEntryValidate, ServerCacheNotify
private static final Logger log = LoggerFactory.getLogger("io.ebean.cache.TABLEMOD");
private final ClockService clockService;
private Map<String,Long> tableModStamp = new ConcurrentHashMap<>();
public TableModState(ClockService clockService) {
this.clockService = clockService;
}
/**
* Set the modified timestamp on the tables that have been touched.
*/
@@ -59,12 +66,28 @@ public class TableModState implements QueryCacheEntryValidate, ServerCacheNotify
/**
* Update the table modification timestamps based on remote table modification events.
* <p>
* Generally this is used with distributed caches (Hazelcast, Ignite etc) via topic.
* </p>
*/
@Override
public void notify(ServerCacheNotification notification) {
// TODO: Change to use ClockService ...
long modifyTimestamp = notification.getModifyTimestamp();
touch(notification.getDependentTables(), modifyTimestamp);
// use local clock - for slightly more aggressive invalidation (as later)
// that removes any concern regarding clock syncing across cluster
touch(notification.getDependentTables(), clockService.nowMillis());
}
/**
* Update from Remote transaction event.
* <p>
* Generally this is used with Clustering (ebean-cluster, k8scache).
* </p>
*/
public void notify(RemoteTableMod tableMod) {
// use local clock - for slightly more aggressive invalidation (as later)
// that removes any concern regarding clock syncing across cluster
touch(tableMod.getTables(), clockService.nowMillis());
}
}
@@ -468,6 +468,11 @@ public class TransactionManager implements SpiTransactionManager {
clusterLogger.debug("processing {}", remoteEvent);
}
RemoteTableMod tableMod = remoteEvent.getRemoteTableMod();
if (tableMod != null) {
tableModState.notify(tableMod);
}
List<TableIUD> tableIUDList = remoteEvent.getTableIUDList();
if (tableIUDList != null) {
for (TableIUD tableIUD : tableIUDList) {