mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 14:40:46 +00:00
#1427 - RemoteTransactionEvent process dependent tables
This commit is contained in:
1 parent
3a64cf6952
commit
43e95d81f6
12 files changed
+56
-19
No files matched your search
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user