Activar el almacenamiento persistente en apache ignite
De manera predeterminada ignite solo almacena información en memoria RAM y cuando se reinicia la instancia se pierde todo los datos.
Para gurdar los datos en disco es necesario activar el almacenamiento a disco.
La activación involucra dos pasos: configurar e inicializar activar el cluster.
Agregar esto en $IGNITE_HOME/config/default-config.xml
<bean class="org.apache.ignite.configuration.IgniteConfiguration"> <!-- Enabling Apache Ignite native persistence. --> <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>
La configuración final es:
<?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"> <!-- Alter configuration below as needed. --> <bean class="org.apache.ignite.configuration.IgniteConfiguration"> <!-- Enabling Apache Ignite native persistence. --> <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> <!-- Additional setting. --> </bean> </beans>
Es necesario reiniciar todas las instancias del cluster, con elcomando ignite.sh.
[12:18:43] To start Console Management & Monitoring run ignitevisorcmd.{sh|bat} [12:18:43] [12:18:43] Ignite node started OK (id=627aafed) [12:18:43] >>> Ignite cluster is not active (limited functionality available). Use control.(sh|bat) script or IgniteCluster interface to activate. [12:18:43] Topology snapshot [ver=1, servers=1, clients=0, CPUs=2, offheap=0.8GB, heap=1.0GB] [12:18:43] ^-- Node [id=627AAFED-CFEF-4D8F-B20C-A480A8E5C3DE, clusterState=INACTIVE] [12:18:43] Data Regions Configured: [12:18:43] ^-- default [initSize=256.0 MiB, maxSize=819.2 MiB, persistenceEnabled=true]
Al activar el almacenamiento, el clúster inicia de forma desactivada y evita la ejecución de comando CRUD para garantizar la integridad de los datos.
Si al ejecutar cualquier comando CRUD como insert se obtiene este error
[12:23:12,129][SEVERE][client-connector-#66][JdbcRequestHandler] Failed to execute SQL query [reqId=0, req=JdbcQueryExecuteRequest [schemaName=PUBLIC, pageSize=1024, maxRows=0, sqlQry=show, args=[], stmtType=ANY_STATEMENT_TYPE]] class org.apache.ignite.IgniteException: Can not perform the operation because the cluster is inactive. Note, that the cluster is considered inactive by default if Ignite Persistent Store is used to let all the nodes join the cluster. To activate the cluster call Ignite.active(true).at org.apache.ignite.internal.processors.query.GridQueryProcessor.querySqlFields(GridQueryProcessor.java:2013)
Lo cual indica que es necesario activar el cluster. Para activarlo, ejecutar el siguiente comando:
$IGNITE_HOME/bin/control.sh –activate
control.sh --activate Control utility [ver. 2.6.0#20180710-sha1:669feacc] 2018 Copyright(C) Apache Software Foundation User: ignite -------------------------------------------------------------------------------- Cluster activated
Para verificar la topología del cluster ejecutar:
$IGNITE_HOME/bin/control.sh –baseline
$IGNITE_HOME/bin/control.sh --baseline Control utility [ver. 2.6.0#20180710-sha1:669feacc] 2018 Copyright(C) Apache Software Foundation User: ignite -------------------------------------------------------------------------------- Cluster state: active Current topology version: 1 Baseline nodes: ConsistentID=ea7d251e-441b-453c-b1c3-7df88b690be9, STATE=ONLINE -------------------------------------------------------------------------------- Number of baseline nodes: 1 Other nodes not found.