Apache Ignite .Net (2.8.1) 条目 ICacheEntryProcessor 写入失败
Apache Ignite .Net (2.8.1) Entry ICacheEntryProcessor write Failure
我想验证一下我的理解是否正确。阅读了关于 ICacheEntryProcessor 的文档,它说如果我们想更新缓存条目中的字段,我们实现这个 class 并在缓存上使用 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 源代码来了解执行了哪些操作..还没有运气
您的代码没有问题,但是由于您只更改了 内部 对象 entry.Value
的数据,Ignite 不会检测到这些更改并且不会更新条目。
在 return true
之前添加 entry.Value = entry.Value
。
Ignite 使用 Value
属性 setter 将条目标记为已更新。
我想验证一下我的理解是否正确。阅读了关于 ICacheEntryProcessor 的文档,它说如果我们想更新缓存条目中的字段,我们实现这个 class 并在缓存上使用 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 源代码来了解执行了哪些操作..还没有运气
您的代码没有问题,但是由于您只更改了 内部 对象 entry.Value
的数据,Ignite 不会检测到这些更改并且不会更新条目。
在 return true
之前添加 entry.Value = entry.Value
。
Ignite 使用 Value
属性 setter 将条目标记为已更新。