首页 文章

系统重启后,Ignite缓存变空

提问于
浏览
1

我玩点燃并有简单的测试应用程序来探索其持久性功能:

using System;
using Apache.Ignite.Core;
using Apache.Ignite.Core.PersistentStore;

namespace IgniteDemo
{
    internal class Item
    {
        public int Number { get; set; }
        public DateTime PointInTime { get; set; }
        public override string ToString() => $"Item:{{Number={Number} ,PointInTime={PointInTime}}}";
    }

    class Program
    {
        static void Main(string[] args)
        {
            const string itemCacheName = @"Items";
            var random = new Random();

            var igniteConfig = new IgniteConfiguration{
                JvmInitialMemoryMb = 1024,
                PersistentStoreConfiguration = new PersistentStoreConfiguration()
            };

            using (var ignite = Ignition.Start(igniteConfig))
            {
                ignite.SetActive(true);

                var cache = ignite.GetOrCreateCache<Guid, Item>(itemCacheName);
                cache.LoadCache(null);

                // put random item into cache
                cache.Put(Guid.NewGuid(), new Item {Number = random.Next(), PointInTime = DateTime.Now});

                //print all items in the cache
                Console.WriteLine(@"Cache content:");
                foreach (var cacheEntry in cache)
                    Console.WriteLine(cacheEntry);

                Console.WriteLine("\nPress any key to Close");
                Console.ReadKey();
            }
        }
    }
}

一切都好 . 数据在应用程序执行之间保留在缓存中 . 但是,如果我重启系统,所有缓存数据都会消失 . 我的第一个猜测是问题发生在默认情况下Temp文件夹中的工作目录 . 所以我决定将工作目录移动到自定义文件夹:

var igniteConfig = new IgniteConfiguration
        {
            JvmInitialMemoryMb = 1024,
            WorkDirectory = @"D:\Store\Wd",
            PersistentStoreConfiguration = new PersistentStoreConfiguration()
            {
                PersistentStorePath = @"D:\Store\Data",
                WalStorePath = @"D:\Store\Wal",
                WalArchivePath = @"D:\Store\Wal\Archive"
            }
        };

这没有结果 .

我已阅读下面列出的官方资源

https://apacheignite.readme.io/docs

https://ptupitsyn.github.io/

但我仍然不明白为什么我的缓存数据会消失 . 我错过了一些关于Ignite持久性的重要信息吗?


我使用NuGet获取Ignite并在我的机器上安装了Java 1.8.0_151

1 回答

  • 3

    如果查看 PersistentStorePath 文件夹的内容,您将看到 0_0_0_0_0_0_0_1_127_0_0_1_172_25_4_66_2001_0_9d38_6abd_388e_bade_3c6f_269_47500 等文件夹(有关名称生成here的详细信息) .

    重新启动计算机会导致此ID更改,这是known issue与Ignite 2.1和2.2(在即将发布的2.3中修复) . 解决方法是设置 IgniteConfiguration.consistentId 属性,但它在 Ignite.NET 中不可用(也在2.3中添加) .

    所以你的选择是:

    • 等待Ignite 2.3发布,或使用nightly build

    • 设置 consistentIdSpring XML并使用 IgniteConfiguration.SpringConfigUrl 属性加载它

相关问题