You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apache Ignite容器部署下Native Persistence数据写入失败排查

Apache Ignite Native Persistence 数据未写入挂载目录问题解决

核心问题说明

你已经配置了Native Persistence并挂载了主机目录,但数据没写入磁盘,主要原因有两个:一是Ignite默认将数据存在内存,必须触发Checkpoint操作才会把数据刷写到磁盘;二是缓存未明确关联到开启持久化的数据区域。下面是具体解决步骤:


1. 修改Ignite配置文件

更新ignite-config.xml,确保默认缓存模板开启持久化,同时完善存储路径配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd">

    <!-- Ignite主配置 -->
    <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">

        <!-- 数据存储配置 -->
        <property name="dataStorageConfiguration">
            <bean class="org.apache.ignite.configuration.DataStorageConfiguration">
                <!-- 默认数据区域开启持久化 -->
                <property name="defaultDataRegionConfiguration">
                    <bean class="org.apache.ignite.configuration.DataRegionConfiguration">
                        <property name="persistenceEnabled" value="true"/>
                        <!-- 可选:设置内存区域上限,比如2GB -->
                        <property name="maxSize" value="#{2L * 1024 * 1024 * 1024}"/>
                    </bean>
                </property>
                <!-- 磁盘存储路径 -->
                <property name="storagePath" value="/opt/ignite/persistence"/>
                <!-- WAL日志路径(保障数据一致性) -->
                <property name="walPath" value="/opt/ignite/persistence/wal"/>
                <property name="walArchivePath" value="/opt/ignite/persistence/wal/archive"/>
                <!-- 自动Checkpoint间隔(生产环境推荐,比如60秒) -->
                <property name="checkpointFrequency" value="60000"/>
            </bean>
        </property>

        <!-- 默认缓存模板:所有新建缓存自动开启持久化 -->
        <property name="cacheConfiguration">
            <bean class="org.apache.ignite.configuration.CacheConfiguration">
                <property name="name" value=""/>
                <property name="persistenceEnabled" value="true"/>
            </bean>
        </property>

    </bean>
</beans>

2. 调整Docker运行命令(解决权限问题)

Windows挂载目录到Docker容器时容易出现权限不足,添加--user root确保容器有写入权限:

docker run -d --name ignite-container --user root \
  -p 10800:10800 -p 47100:47100 -p 47500:47500 -p 49112:49112 \
  -v C:/Users/ArchanaAnand/Desktop/ignite-config/persistence:/opt/ignite/persistence \
  -v C:/Users/ArchanaAnand/Desktop/ignite-config/ignite-config.xml:/opt/ignite/apache-ignite/config/ignite-config.xml \
  -e IGNITE_CONFIG_URI=file:///opt/ignite/apache-ignite/config/ignite-config.xml \
  apacheignite/ignite

3. 修改Python代码(确保缓存持久化+触发Checkpoint)

在代码中明确开启缓存持久化,并手动触发Checkpoint(测试用,生产环境可依赖自动Checkpoint):

from pyignite import Client
from pyignite.datatypes import CacheAtomicityMode

client = Client()
with client.connect('127.0.0.1', 10800):   
    # 创建缓存时明确开启持久化
    cache = client.create_cache({
        'name': 'my cache',
        'persistence_enabled': True,
        'atomicity_mode': CacheAtomicityMode.TRANSACTIONAL
    })

    cache.put(1, 'Hello, Ignite!')
    cache.put(2, 'Apache Ignite is awesome!')

    # 手动触发Checkpoint,将内存数据刷写到磁盘
    client.checkpoint_run()

    value1 = cache.get(1)
    value2 = cache.get(2)

    print(value1)
    print(value2)

client.close()

4. 验证配置与数据持久化

  1. 检查配置是否生效:查看容器日志确认持久化开启
docker logs ignite-container | grep "Persistent store is enabled"

看到Persistent store is enabled for default data region.即说明配置生效。

  1. 验证数据持久化:重启容器后运行以下读取代码,能获取到之前写入的数据则成功:
from pyignite import Client

client = Client()
with client.connect('127.0.0.1', 10800):   
    cache = client.get_cache('my cache')
    print(cache.get(1))
    print(cache.get(2))

client.close()

内容的提问来源于stack exchange,提问作者Archana Anand

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 21:18:16