【发布时间】:2020-06-22 05:15:01
【问题描述】:
我想验证我的理解是否正确.. 阅读了有关 ICacheEntryProcessor 的文档后,它说如果我们想更新缓存条目中的字段,我们实现这个类并在缓存上使用 Invoke 来更新缓存中的字段原子记录..
当我实现上述方法时,记录似乎没有更新..process方法中没有抛出异常。
这是我的实现
public class UserConnectionUpdateProcessor : ICacheEntryProcessor<string, User, UserConnection, bool>
{
/// <summary>
/// Processes the update
/// </summary>
/// <param name="entry"></param>
/// <param name="arg"></param>
/// <returns></returns>
public bool Process(IMutableCacheEntry<string, User> entry, UserConnection arg)
{
var connection = (from conn in entry.Value.Connections
where conn.ConnectionId == arg.ConnectionId
select conn).FirstOrDefault();
if(connection == null)
{
//this is a new connection
entry.Value.Connections.Add(arg);
return true;
}
if(arg.Disconnected)
{
entry.Value.Connections.Remove(connection);
}
else
{
connection.LastActivity = DateTime.Now;
}
return true;
}
}
我启用了 Ignite Trace 日志并打印出来了
2020-06-21 21:09:54.1732|DEBUG|org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache|<usersCache> Entry did not pass the filter or conflict resolution (will skip write) [entry=GridDhtCacheEntry [rdrs=ReaderId[] [], part=358, super=GridDistributedCacheEntry [super=GridCacheMapEntry [key=KeyCacheObjectImpl [part=358,
我还通过 Ignite 源来了解执行了哪些操作.. 还没有运气
【问题讨论】:
-
你能在 github 或其他地方粘贴一个小的复制器项目吗?
-
嗨@alamar,我得到了这个问题的解决方案,标记为已接受的答案。