【问题标题】:Apache Ignite .Net (2.8.1) Entry ICacheEntryProcessor write FailureApache Ignite .Net (2.8.1) 条目 ICacheEntryProcessor 写入失败
【发布时间】: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 源来了解执行了哪些操作.. 还没有运气

https://github.com/apache/ignite/blob/master/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java

【问题讨论】:

  • 你能在 github 或其他地方粘贴一个小的复制器项目吗?
  • 嗨@alamar,我得到了这个问题的解决方案,标记为已接受的答案。

标签: c# .net ignite


【解决方案1】:

您的代码没问题,但由于您只更改了entry.Value 对象内部的数据,Ignite 不会检测到这些更改并且不会更新条目。

return true 之前添加entry.Value = entry.Value。 Ignite 使用Value 属性设置器将条目标记为已更新。

【讨论】:

  • 感谢 Pavel Tupitsyn 的快速帮助。这有效!..
猜你喜欢
  • 2022-06-17
  • 2017-10-01
  • 1970-01-01
  • 2020-03-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-27
  • 1970-01-01
相关资源
最近更新 更多