首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apache.Ignite.Net CacheStoreFactory和CacheMode.Replicated并不会写入所有节点。

Apache.Ignite.Net CacheStoreFactory和CacheMode.Replicated并不会写入所有节点。
EN

Stack Overflow用户
提问于 2018-04-26 06:29:11
回答 1查看 171关注 0票数 0

在Windows10上使用C#,ApacheIgnite2.4,我的目标是拥有多个具有自定义CacheStoreFactory的复制节点。每当缓存项更改时,我都希望调用每个节点的CacheStoreFactory。下面的代码示例将输出到我预期的CacheMode.Partitioned行为。对于CacheMode.Replicated,我希望每个cache.Put操作都有两个输出行(因为两个节点正在运行)。我怎样才能做到这一点?

输出

代码语言:javascript
复制
Node count: 2
Started..
Write 0-0 by 63642613
Write 1-1 by 12036987
Write 2-2 by 63642613
Write 3-3 by 12036987
Write 4-4 by 63642613
Write 5-5 by 63642613
Write 6-6 by 12036987
Write 7-7 by 63642613
Write 8-8 by 12036987
Write 9-9 by 12036987
Finished count1:10 count2:10

样本代码

代码语言:javascript
复制
class Program
{
    static void Main(string[] args)
    {
        var config = new IgniteConfiguration()
        {
            IgniteInstanceName = "A",
            CacheConfiguration = new List<CacheConfiguration>
            {
                new CacheConfiguration("mycache",new QueryEntity(typeof(int), typeof(int)))
                {
                    CacheMode = CacheMode.Replicated,
                    WriteThrough = true,
                    CacheStoreFactory = new StoreFactory(),
                },
            },
        };

        var ignite1 = Ignition.Start(config);
        config.IgniteInstanceName = "B";
        var ignite2 = Ignition.Start(config);

        Console.WriteLine("Node count: " + ignite1.GetCluster().GetNodes().Count);
        ignite1.GetCluster().SetActive(true);

        var mycache1 = ignite1.GetCache<int, int>("mycache");
        var mycache2 = ignite2.GetCache<int, int>("mycache");
        Console.WriteLine("Started..");
        for (int i = 0; i < 10; i++)
        {
            mycache1.Put(i, i);
        }
        Console.WriteLine($"Finished count1:{mycache1.Count()} count2:{mycache2.Count()}");
        Console.ReadLine();

        ignite1.Dispose();
        ignite2.Dispose();
    }

    private class StoreFactory : IFactory<ICacheStore>
    {
        public ICacheStore CreateInstance() { return new Store(); }
    }

    private class Store : CacheStoreAdapter<int, int>
    {
        public override void Delete(int key) { }

        public override int Load(int key) { return 1; }

        public override void Write(int key, int val)
        {
            Console.WriteLine($"Write {key}-{val} by {this.GetHashCode()}");
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-26 13:35:50

即使使用复制的缓存,每个键也有自己的主节点,只有这个主节点才会将值写入存储区。need期望所有节点都具有相同的底层CacheStore,在这种情况下,只向其写入值一次是有意义的,因为不需要从备份再次写入它。

如果您想拥有分布式底层存储,我建议您尝试Ignite本地持久性:https://apacheignite.readme.io/docs/distributed-persistent-store

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50036192

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档