重新启动Docker容器时,点燃的缓存数据会丢失

时间:2018-12-19 10:14:40

标签: ignite

我想在ignite中启用持久性,以便在ignite docker容器重新启动或替换为新版本时不会丢失缓存数据。

我正在使用ignite 2.6.0。这是配置文件:

<?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">
   <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" />
               </bean>
            </property>           
            <property name="storagePath" value="/opt/ignite/apache-ignite-fabric/data/persistence" />           
            <property name="walPath" value="/opt/ignite/apache-ignite-fabric/data/wal" />
            <property name="walArchivePath" value="/opt/ignite/apache-ignite-fabric/data/wal/archive" />
         </bean>
      </property>          
      <property name="discoverySpi">
         <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
            <property name="ipFinder">            
               <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
                  <property name="addresses">
                     <list>
                        <value>127.0.0.1:47500..47502</value>
                     </list>
                  </property>
               </bean>
            </property>
         </bean>
      </property>
   </bean>
</beans>

我运行以下命令来部署可点燃docker容器

sudo docker run -d -e "CONFIG_URI=" -e "OPTION_LIBS=ignite-core,ignite-spring,ignite-indexing,ignite-rest-http" -v /var/ignitedata:/opt/ignite/apache-ignite-fabric/data -p 9005:8080 --name=apacheignite apacheignite/ignite:2.6.0

我没有将任何值传递给CONFIG_URI是因为我替换了Docker容器中的default-config.xml文件。

我使用ignite rest api创建了一个新缓存

http://localhost:9005/ignite?cmd=getorcreate&cacheName=myCache

将示例值添加到缓存

http://localhost:9005/ignite?cmd=put&key=10&val=2018-01-01&cacheName=myCache&keyType=int&valueType=date

我可以检索缓存值

http://172.30.5.28:9005/ignite?cmd=get&key=10&cacheName=myCache&keyType=int&valueType=date

现在,如果我重新启动docker容器并尝试获取值,它不会返回值

http://localhost:9005/ignite?cmd=get&key=10&cacheName=myCache&keyType=int&valueType=date

有人见过这个问题吗?

谢谢, 拉胡尔

3 个答案:

答案 0 :(得分:0)

启动集群后是否激活了集群?使用持久性时,您需要告诉Ignite它期望看到多少个节点(称为“基准”)。

您可以通过运行control.sh脚本来做到这一点:

./control.sh --activate

答案 1 :(得分:0)

您必须确保Docker容器仍然挂载了相同的存储,还必须在配置中将consistentId设置为相同的值。

如果执行此操作,则所有节点加入后,群集将自动激活。您只需要手动激活一次即可。

答案 2 :(得分:0)

感谢Andrei Aleksandrov为我指出正确的方向。我添加了工作目录路径,这有助于解决问题。 发布更新的default-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<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">
   <bean id="ignite.cfg" class="org.apache.ignite.configuration.IgniteConfiguration">
      <!-- Enabling Apache Ignite Persistent Store. -->
      <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" />
               </bean>
            </property>



         </bean>
      </property>
      <property name="workDirectory" value="/opt/ignite/apache-ignite-fabric/data" />
      <!-- Explicitly configure TCP discovery SPI to provide a list of initial nodes. -->
      <property name="discoverySpi">
         <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
            <property name="ipFinder">
               <!-- Uncomment static IP finder to enable static-based discovery of initial nodes. -->
               <!--<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">-->
               <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
                  <property name="addresses">
                     <list>
                        <!-- In distributed environment, replace with actual host IP address. -->
                        <value>127.0.0.1:47500..47502</value>
                     </list>
                  </property>
               </bean>
            </property>
         </bean>
      </property>
   </bean>
</beans>