mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 14:40:46 +00:00
#1427 - QueryCache should be cleared, if one of a dependent bean is updated
Update RemoteTransactionEvent, add (back) common binary message handling (Common to TCP, K8s and upcoming binary pubsub)
This commit is contained in:
1 parent
bd3c99e67f
commit
9c73309dfd
17 files changed
+563
-14
No files matched your search
@@ -1,8 +1,8 @@
|
||||
package io.ebeaninternal.server.transaction;
|
||||
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.server.cluster.BinaryMessage;
|
||||
import io.ebeaninternal.server.cluster.BinaryMessageList;
|
||||
import io.ebeaninternal.server.cluster.binarymessage.BinaryMessage;
|
||||
import io.ebeaninternal.server.cluster.binarymessage.BinaryMessageList;
|
||||
import io.ebeaninternal.server.core.PersistRequest;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.deploy.id.IdBinder;
|
||||
@@ -140,7 +140,7 @@ public class BeanPersistIds {
|
||||
idBinder.writeData(os, idList.get(i));
|
||||
}
|
||||
|
||||
os.flush();
|
||||
os.close();
|
||||
msgList.add(m);
|
||||
|
||||
} while (i < eof);
|
||||
@@ -167,7 +167,7 @@ public class BeanPersistIds {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
void addId(PersistRequest.Type type, Serializable id) {
|
||||
public void addId(PersistRequest.Type type, Serializable id) {
|
||||
switch (type) {
|
||||
case INSERT:
|
||||
addInsertId(id);
|
||||
@@ -210,10 +210,18 @@ public class BeanPersistIds {
|
||||
return beanDescriptor;
|
||||
}
|
||||
|
||||
List<Object> getDeleteIds() {
|
||||
public List<Object> getDeleteIds() {
|
||||
return deleteIds;
|
||||
}
|
||||
|
||||
public List<Object> getInsertIds() {
|
||||
return insertIds;
|
||||
}
|
||||
|
||||
public List<Object> getUpdateIds() {
|
||||
return updateIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify the cache of this event that came from another server in the cluster.
|
||||
*/
|
||||
|
||||
@@ -211,6 +211,10 @@ final class PostCommitProcessing {
|
||||
|
||||
RemoteTransactionEvent remoteTransactionEvent = new RemoteTransactionEvent(serverName);
|
||||
|
||||
Set<String> touched = cacheChanges.touchedTables();
|
||||
if (touched != null && !touched.isEmpty()) {
|
||||
remoteTransactionEvent.addRemoteTableMod(new RemoteTableMod(cacheChanges.modificationTimestamp(), touched));
|
||||
}
|
||||
if (beanPersistIdMap != null) {
|
||||
for (BeanPersistIds beanPersist : beanPersistIdMap.values()) {
|
||||
remoteTransactionEvent.addBeanPersistIds(beanPersist);
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package io.ebeaninternal.server.transaction;
|
||||
|
||||
import io.ebeaninternal.server.cluster.binarymessage.BinaryMessage;
|
||||
import io.ebeaninternal.server.cluster.binarymessage.BinaryMessageList;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class RemoteTableMod {
|
||||
|
||||
private final long timestamp;
|
||||
|
||||
private final Set<String> tables;
|
||||
|
||||
public RemoteTableMod(long timestamp, Set<String> tables) {
|
||||
this.timestamp = timestamp;
|
||||
this.tables = tables;
|
||||
}
|
||||
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public Set<String> getTables() {
|
||||
return tables;
|
||||
}
|
||||
|
||||
public static RemoteTableMod readBinaryMessage(DataInput dataInput) throws IOException {
|
||||
|
||||
long timestamp = dataInput.readLong();
|
||||
int count = dataInput.readInt();
|
||||
|
||||
Set<String> tables = new LinkedHashSet<>();
|
||||
for (int i = 0; i < count; i++) {
|
||||
tables.add(dataInput.readUTF());
|
||||
}
|
||||
return new RemoteTableMod(timestamp, tables);
|
||||
}
|
||||
|
||||
public void writeBinary(BinaryMessageList msgList) throws IOException {
|
||||
BinaryMessage msg = new BinaryMessage(tables.size() * 20 + 30);
|
||||
DataOutputStream os = msg.getOs();
|
||||
os.writeInt(BinaryMessage.TYPE_TABLEMOD);
|
||||
os.writeLong(timestamp);
|
||||
os.writeInt(tables.size());
|
||||
for (String table : tables) {
|
||||
os.writeUTF(table);
|
||||
}
|
||||
os.close();
|
||||
msgList.add(msg);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package io.ebeaninternal.server.transaction;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.api.TransactionEventTable.TableIUD;
|
||||
import io.ebeaninternal.server.cache.RemoteCacheEvent;
|
||||
import io.ebeaninternal.server.cluster.BinaryMessageList;
|
||||
import io.ebeaninternal.server.cluster.binarymessage.BinaryMessageList;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -19,6 +19,8 @@ public class RemoteTransactionEvent implements Runnable {
|
||||
|
||||
private RemoteCacheEvent remoteCacheEvent;
|
||||
|
||||
private RemoteTableMod remoteTableMod;
|
||||
|
||||
private String serverName;
|
||||
|
||||
private transient SpiEbeanServer server;
|
||||
@@ -53,6 +55,10 @@ public class RemoteTransactionEvent implements Runnable {
|
||||
|
||||
public void writeBinaryMessage(BinaryMessageList msgList) throws IOException {
|
||||
|
||||
if (remoteTableMod != null) {
|
||||
remoteTableMod.writeBinary(msgList);
|
||||
}
|
||||
|
||||
if (tableList != null) {
|
||||
for (TableIUD aTableList : tableList) {
|
||||
aTableList.writeBinaryMessage(msgList);
|
||||
@@ -113,6 +119,10 @@ public class RemoteTransactionEvent implements Runnable {
|
||||
tableList.add(tableIud);
|
||||
}
|
||||
|
||||
public void addRemoteTableMod(RemoteTableMod remoteTableMod) {
|
||||
this.remoteTableMod = remoteTableMod;
|
||||
}
|
||||
|
||||
public String getServerName() {
|
||||
return serverName;
|
||||
}
|
||||
@@ -141,4 +151,8 @@ public class RemoteTransactionEvent implements Runnable {
|
||||
return remoteCacheEvent;
|
||||
}
|
||||
|
||||
public RemoteTableMod getRemoteTableMod() {
|
||||
return remoteTableMod;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user