Introduction
In this tutorial, we will understand Apache Ignite write through database caching. First of all, let’s understand what write thorough cache is actually! Write-through caching ensures that data is updated to cache and the persistent store (disk, database etc) in same transaction. Therefore, if the transaction is successful then the change will be committed to both cache and persistent store. However, if it’s failed, the transaction will be rolled back and any change to database or cache is reverted to earlier state. There are pros and cons to this approach that can be covered in another post later.
In this blog post, we’ll implement and demonstrate an end-to-end solution for “write-through” cache. Following are used as part of this implementation –
Technology Stack
1 2 3 4 5 6 7 |
JAVA version "1.8.0_144" Apache Ignite version "2.0.0" Eclipse Neon Apache Maven MySQL version "5.7" DBeaver "4.0.5" Windows 10 Laptop |
Create Database Tables
- To start with, we’ll create two tables in mysql database. The tables are self-explanatory. With each write-through insertion, we will create one order record with one or many order lines –
12orders (order_number - primary key, order_type, order_fulfillment_date)order_line (order_number - foreign key, order_line_number, item_name, item_qty) - In order to create these tables and relationship constraint, let’s execute following statements –
123CREATE TABLE orders ( order_number INT NOT NULL primary key, order_type VARCHAR(30) NOT NULL , order_fulfillment_date DATE NOT NULL ) ENGINE=INNODB;CREATE TABLE order_line( order_number INT not NULL , order_line_number INT NOT NULL , item_name VARCHAR(30) NOT NULL , item_qty INT NOT null ) ENGINE=INNODB;ALTER TABLE order_line ADD CONSTRAINT order_num_fk FOREIGN KEY (order_number) REFERENCES orders(order_number)
JAVA program: Model Classes
- Next, we’ll start with our program that will insert records in database tables using write-through caching mechanism of apache ignite.
- In the previous blog post, we have already created a maven project. We’ll build this program in the same project.
- Right click on src/main/java and create a new package with the name com.iteritory.ignite.model. This package will hold the an Orders class that will in turn refer to OrderLines class. Orders and OrderLines calsses are exact mirror image of the underlying database.
- Right click on this newly created package and select New –> Class. Provide the class name as OrderLines.
- Content of OrderLines class is as below –
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051package com.iteritory.ignite.model;public class OrderLines {int orderNumber;int orderLineNumber;String itemName;int itemQty;public OrderLines(){}public OrderLines(int orderNumber, int orderLineNumber, String itemName, int itemQty) {super();this.orderNumber = orderNumber;this.orderLineNumber = orderLineNumber;this.itemName = itemName;this.itemQty = itemQty;}public int getOrderNumber() {return orderNumber;}public void setOrderNumber(int orderNumber) {this.orderNumber = orderNumber;}public int getOrderLineNumber() {return orderLineNumber;}public void setOrderLineNumber(int orderLineNumber) {this.orderLineNumber = orderLineNumber;}public String getItemName() {return itemName;}public void setItemName(String itemName) {this.itemName = itemName;}public int getItemQty() {return itemQty;}public void setItemQty(int itemQty) {this.itemQty = itemQty;}}
- We will now create Orders class with following content –
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950package com.iteritory.ignite.model;import java.sql.Date;public class Orders {int orderNumber;String orderType;Date orderFulfillmentDate;OrderLines orderLine[];public Orders(int orderNumber, String orderType, Date orderFulfillmentDate, OrderLines[] orderLine) {super();this.orderNumber = orderNumber;this.orderType = orderType;this.orderFulfillmentDate = orderFulfillmentDate;this.orderLine = orderLine;}public Orders(int orderNumber, String orderType, Date orderFulfillmentDate) {// TODO Auto-generated constructor stubsuper();this.orderNumber = orderNumber;this.orderType = orderType;this.orderFulfillmentDate = orderFulfillmentDate;}public int getOrderNumber() {return orderNumber;}public void setOrderNumber(int orderNumber) {this.orderNumber = orderNumber;}public String getOrderType() {return orderType;}public void setOrderType(String orderType) {this.orderType = orderType;}public Date getOrderFulfillmentDate() {return orderFulfillmentDate;}public void setOrderFulfillmentDate(Date orderFulfillmentDate) {this.orderFulfillmentDate = orderFulfillmentDate;}public OrderLines[] getOrderLine() {return orderLine;}public void setOrderLine(OrderLines[] orderLine) {this.orderLine = orderLine;}}
Maven Dependency
- In order to run this sample program, we need to resolve few dependency jars. We’ll use maven tool for that. Following is the pom.xml content used –
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.iteritory.ignite</groupId><artifactId>ignite-tutorial</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><name>ignite-tutorial</name><url>http://maven.apache.org</url><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>3.8.1</version><scope>test</scope></dependency><dependency><groupId>org.apache.ignite</groupId><artifactId>ignite-core</artifactId><version>2.0.0</version></dependency><dependency><groupId>org.apache.ignite</groupId><artifactId>ignite-spring</artifactId><version>2.0.0</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>6.0.5</version></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.6.2</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin></plugins></build></project>
JAVA Program: CacheStoreAdapter / CacheStore
- Concept: –To implement write-through caching behavior, we’ll need to implement CacheStore interface and also set the CacheStoreFactory. Additionally, we will need to set writeThrough property of ignite CacheConfiguration. Apache ignite provides a convenience adapter in the form of CacheStoreAdapter that implement CacheStore interface. Here in this example, we will use CacheStoreAdapter to implement Write-Through behavior.
- Right click on src/main/java folder and create a new package com.iteritory.ignite.adapter. Create a class OrdersCacheStoreAdapter.java inside this package.
- Modify the class to extend CacheStoreAdapter<Key, Value>. The class will look like after fixing the necessary imports -ckage com.iteritory.ignite.adapter;
1234import org.apache.ignite.cache.store.CacheStoreAdapter;import com.iteritory.ignite.model.*;public class OrdersCacheStoreAdapter extends CacheStoreAdapter<Long, Orders> {}
- However, the class will still show errors as there are some unimplemented methods. To fix this, hover the mouse over OrdersCacheStoreAdapter; a pop-up will open; select “Add unimplemented methods”. This will auto-populate load, delete and write methods. The class will look like below –
1234567891011121314151617181920212223242526package com.iteritory.ignite.adapter;import javax.cache.Cache.Entry;import javax.cache.integration.CacheLoaderException;import javax.cache.integration.CacheWriterException;import org.apache.ignite.cache.store.CacheStoreAdapter;import com.iteritory.ignite.model.*;public class OrdersCacheStoreAdapter extends CacheStoreAdapter<Long, Orders> {public Orders load(Long key) throws CacheLoaderException {// TODO Auto-generated method stubreturn null;}public void write(Entry<? extends Long, ? extends Orders> entry) throws CacheWriterException {// TODO Auto-generated method stub}public void delete(Object key) throws CacheWriterException {// TODO Auto-generated method stub}}
- As part of this tutorial, we will implement write method only. In subsequent few blog posts, we’ll cover others.
- Concept:- Here we’ll use CacheStoreSession interface. CacheStoreSession interface is used to maintain the cache store operations. In this example, we’ll use JDBC. More on this concept can be found in the ignite official documentation. We’ll use @CacheStoreSessionResource annotation to inject CacheStoreSession.
- Next, we’ll create openConnection method responsible for creating connection to Database and returning the connection object. This method expects a Boolean value to set the connection’s auto commit mode.
- We’ll also create endConnection method that will close allocated connection resource (if any) depending on the status of ongoing transaction.
- We’ll create connection method that will be responsible for creating a new connection or reuse one depending on the current status.
- We’ll also then override the write method with our implementation. Here, we’ll use up-sert operation using prepared statement.
- We’ll implement sessionEnd method to either commit or rollback the transaction.
- Let’s check how the entire OrdersCacheStoreAdapter class look like after putting together all of the above –
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141package com.iteritory.ignite.adapter;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.SQLException;import java.util.Map;import javax.cache.Cache.Entry;import javax.cache.integration.CacheLoaderException;import javax.cache.integration.CacheWriterException;import org.apache.ignite.cache.store.CacheStoreAdapter;import org.apache.ignite.cache.store.CacheStoreSession;import org.apache.ignite.resources.CacheStoreSessionResource;import org.jetbrains.annotations.Nullable;import com.iteritory.ignite.model.*;public class OrdersCacheStoreAdapter extends CacheStoreAdapter<Long, Orders> {// This is a key to store connectionprivate static final String CONN_NAME = "CONN_STORE";@CacheStoreSessionResourceprivate CacheStoreSession cacheStoreSession;public Orders load(Long key) throws CacheLoaderException {// TODO Auto-generated method stubreturn null;}public void write(Entry<? extends Long, ? extends Orders> entry) throws CacheWriterException {// TODO Auto-generated method stub//Get the key and value for every insert call from the invokation class IgniteWtiteThroughCacheLong key = entry.getKey();Orders value = entry.getValue();System.out.println("INFO: Inserting the record for order#:" + key);Connection conn = null;try {conn = connection();PreparedStatement stOrder, stOrderLine;// Delete the row if any from the orderlines table for the current keystOrder = conn.prepareStatement("delete from orders where order_number = ?");stOrderLine = conn.prepareStatement("delete from order_line where order_number = ?");stOrder.setLong(1, value.getOrderNumber());stOrderLine.setLong(1, value.getOrderNumber());stOrderLine.executeUpdate();stOrder.executeUpdate();// Insert the rows into tablestOrder = conn.prepareStatement("insert into orders (order_number, order_type, order_fulfillment_date) values (?, ?, ?)");stOrderLine = conn.prepareStatement("insert into order_line (order_number, order_line_number, item_name,item_qty) values (?, ?, ?,?)");stOrder.setLong(1, value.getOrderNumber());stOrder.setString(2, value.getOrderType());stOrder.setDate(3, value.getOrderFulfillmentDate());stOrder.executeUpdate();for (int i =0; i < value.getOrderLine().length; i ++){OrderLines currentOrderLine = value.getOrderLine()[i];stOrderLine.setInt(1, currentOrderLine.getOrderNumber());stOrderLine.setInt(2, currentOrderLine.getOrderLineNumber());stOrderLine.setString(3, currentOrderLine.getItemName());stOrderLine.setInt(4, currentOrderLine.getItemQty());stOrderLine.executeUpdate();}} catch (Exception ex) {throw new CacheLoaderException("Failed to put object [key=" + key + ", val=" + value + ']', ex);} finally {endConnection(conn);}}public void delete(Object key) throws CacheWriterException {// TODO Auto-generated method stub}@Overridepublic void sessionEnd(boolean commit) {Map<String, Connection> connectionProperties = cacheStoreSession.properties();try {Connection conn = (Connection) connectionProperties.remove(CONN_NAME);if (conn != null) {//when the transaction is successfully committed [tx.commit() in IgniteWriteThroughCache],//the commit variable will be trueif (commit)conn.commit();elseconn.rollback();}System.out.println("END:Transaction ended successfully [commit=" + commit + ']');} catch (SQLException e) {throw new CacheWriterException("ERROR:Failed to end transaction: " + cacheStoreSession.transaction(), e);}}private Connection openConnection(boolean autocommitFlag) throws SQLException {Connection objConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql_ignite?user=root&password=password123");objConn.setAutoCommit(autocommitFlag);System.out.println("INFO:Connection object is created with autoCommitFlag as:" + autocommitFlag);return objConn;}private void endConnection(@Nullable Connection objConn) {if (!cacheStoreSession.isWithinTransaction() && objConn != null) {//Close connection as there is no transaction.try {objConn.close();System.out.println("INFO:Connection object is closed");} catch (SQLException ex) {ex.printStackTrace();}}}private Connection connection() throws SQLException {// Check if there is ongoing session; if so, we'll reuse itif (cacheStoreSession.isWithinTransaction()) {System.out.println("INFO:The cache store session is within Transaction");Map<Object, Object> connectionProperties = cacheStoreSession.properties();Connection conn = (Connection) connectionProperties.get(CONN_NAME);if (conn == null) {System.out.println("INFO:Connection does not exist; create a new connection with autoCommitFlag as False");conn = openConnection(false);connectionProperties.put(CONN_NAME, conn);}else{System.out.println("INFO:Connection exists; we'll reuse the same connection");}return conn;} else {System.out.println("INFO:The cache store session is NOT within Transaction; create a new connection");return openConnection(true);}}}
JAVA Program: Implementation Class
- Now, we will create com.iteritory.ignite.impl package and inside that we’ll create a class IgniteWriteThroughCache.java –
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384package com.iteritory.ignite.impl;import org.apache.ignite.Ignite;import org.apache.ignite.IgniteCache;import org.apache.ignite.Ignition;import org.apache.ignite.configuration.CacheConfiguration;import org.apache.ignite.transactions.Transaction;import com.iteritory.ignite.adapter.OrdersCacheStoreAdapter;import com.iteritory.ignite.model.OrderLines;import com.iteritory.ignite.model.Orders;import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;import java.text.SimpleDateFormat;import javax.cache.configuration.FactoryBuilder;public class IgniteWriteThroughCache {/** Orders cache name. */private static final String ORDERS_CACHE = "Orders_Cache";public static void main(String[] args) {try {// Set the node start mode as client; so, this node will join the// apache// cluster as clientIgnition.setClientMode(true);// Here, we provide the cache configuration fileIgnite objIgnite = Ignition.start("F:\\apache-ignite-fabric-2.0.0-bin\\config\\itc-poc-config.xml");CacheConfiguration<Long, Orders> ordersCacheCfg = new CacheConfiguration<>(ORDERS_CACHE);// Set atomicity as transaction, since we are showing transactions// in// example.ordersCacheCfg.setAtomicityMode(TRANSACTIONAL);// Configure JDBC store.ordersCacheCfg.setCacheStoreFactory(FactoryBuilder.factoryOf(OrdersCacheStoreAdapter.class));// Set as write-thorugh cacheordersCacheCfg.setWriteThrough(true);IgniteCache<Long, Orders> cache = objIgnite.getOrCreateCache(ordersCacheCfg);// Start transaction and execute several cache operations with// read/write-through to persistent store.persistData(cache);} catch (Exception ex) {ex.printStackTrace();}}private static void persistData(IgniteCache<Long, Orders> cache) {try {Transaction tx = Ignition.ignite().transactions().txStart();System.out.println("START:Transaction started");// Put/Insert first orderOrderLines olBanana = new OrderLines(11, 1, "Banana", 12);OrderLines olApple = new OrderLines(11, 2, "Apple", 6);OrderLines[] ol1 = new OrderLines[] { olBanana, olApple };java.util.Date utilDate1 = new SimpleDateFormat("dd-MM-yyyy").parse("01-01-2017");java.sql.Date sqlDate1 = new java.sql.Date(utilDate1.getTime());Orders ord1 = new Orders(11, "EcomDeliveryOrder", sqlDate1, ol1);cache.put((long) 11, ord1);// Put/Insert second orderOrderLines olMosambi = new OrderLines(22, 1, "Mosambi", 3);OrderLines olMango = new OrderLines(22, 2, "Mango", 4);OrderLines[] ol2 = new OrderLines[] { olMosambi, olMango };java.util.Date utilDate2 = new SimpleDateFormat("dd-MM-yyyy").parse("02-01-2017");java.sql.Date sqlDate2 = new java.sql.Date(utilDate2.getTime());Orders ord2 = new Orders(22, "StorePickupOrder", sqlDate2, ol2);cache.put((long) 22, ord2);tx.commit();} catch (Exception ex) {ex.printStackTrace();}}}
- Now, we’ll do a maven update [Right Click ignite-tutorial –> Maven –> Update Project …] and then will do a maven build [Right Click ignite-tutorial –>Run As –> Maven Build… ; set Goals as “clean install”]
- This will create a jar file in the target directory.
- Important step: Copy the jar file created in above step to the %IGNITE_HOME%/libs folder. This is essential for our program to run.
JAVA Project Structure

Apache Ignite Sample Program Project Structure
Execute the JAVA program
- Let’s start a single node apache ignite server by executing following command –>ignite.bat F:\apache-ignite-fabric-2.0.0-bin\config\itc-poc-config.xml from %IGNITE_HOME%/bin directory.
- If you are reading this blog afresh and haven’t gone through earlier posts, you can get the content of itc-poc-config.xml from this link; check step 7.
- Now run the IgniteWriteThroughCache.java program. Upon successful execution, you will see execution result something similar to below:
123456789101112[23:49:09] Ignite node started OK (id=c9ea9d6d)[23:49:09] Topology snapshot [ver=2, servers=1, clients=1, CPUs=4, heap=2.8GB]START:Transaction startedINFO: Inserting the record for order#:11INFO:The cache store session is within TransactionINFO:Connection does not exist; create a new connection with autoCommitFlag as FalseTue Aug 22 23:49:09 IST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.INFO:Connection object is created with autoCommitFlag as:falseINFO: Inserting the record for order#:22INFO:The cache store session is within TransactionINFO:Connection exists; we'll reuse the same connectionEND:Transaction ended successfully [commit=true]
I hope this blog post helps you with some key understanding, concepts of Apache Ignite along with how to implement these concepts using JAVA. Happy reading!!
Naseer
May 16, 2018Thank you for this valuable article.
You coded the example using 2 tables that have relationship.
How can I extend this example to work with database that has more than 20 tables?
Sadruddin Md
May 17, 2018Hi Naseer, Thank you.
Coming to your scenario, it’s absolutely fine to use more tables with relationships among them as well.
Is there any issue you are observing or anticipating in particular?
Naseer
May 18, 2018Thank you for your replay…
The observation that I got until now is that the write method is coded to deal with one or two tables.
So, how I can use the same write method to insert or update records in the other tables?
Sadruddin Md
May 18, 2018The write method over here deals with two related tables, hence I used one orders cache (look at the implementation class above). If there are other unrelated tables in the same database, why don’t you implement a new cache for them? You will have to write a new cache adapter implementation (like OrdersCacheStoreAdapter class above).
Naseer
May 23, 2018Yes, it seems a good method to deal with many tables.
actually, I am still stuck with one table. I am building cache of the database to be accessed from PHP interface. I implemented your example with one table and it works from Eclipse. from PHP interface, read operations are working, but I Got errors when I tried to insert records from PHP interface.
Sadruddin Md
May 23, 2018What’s the error you are getting? Can you provide the full error stack
Naseer
May 23, 2018[01:39:11,916][SEVERE][odbc-#48%null%][OdbcRequestHandler] Failed to execute SQL query [reqId=6, req=OdbcQueryExecuteRequest [cacheName=PatientCache, sqlQry=merge INTO Patient (id, name, address, orgid) VALUES ( ?, ?, ?, ?), args=[6, zain, KulaLampur, 10]]]
javax.cache.CacheException: class org.apache.ignite.internal.processors.query.IgniteSQLException: Failed to execute DML statement [stmt=merge INTO Patient (id, name, address, orgid) VALUES ( ?, ?, ?, ?), params=[6, zain, KulaLampur, 10]]
at org.apache.ignite.internal.processors.cache.IgniteCacheProxy.query(IgniteCacheProxy.java:818)
at org.apache.ignite.internal.processors.odbc.OdbcRequestHandler.executeQuery(OdbcRequestHandler.java:213)
at org.apache.ignite.internal.processors.odbc.OdbcRequestHandler.handle(OdbcRequestHandler.java:108)
at org.apache.ignite.internal.processors.odbc.OdbcNioListener.onMessage(OdbcNioListener.java:124)
at org.apache.ignite.internal.processors.odbc.OdbcNioListener.onMessage(OdbcNioListener.java:33)
at org.apache.ignite.internal.util.nio.GridNioFilterChain$TailFilter.onMessageReceived(GridNioFilterChain.java:279)
at org.apache.ignite.internal.util.nio.GridNioFilterAdapter.proceedMessageReceived(GridNioFilterAdapter.java:109)
at org.apache.ignite.internal.util.nio.GridNioAsyncNotifyFilter$3.body(GridNioAsyncNotifyFilter.java:97)
at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:110)
at org.apache.ignite.internal.util.worker.GridWorkerPool$1.run(GridWorkerPool.java:70)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: class org.apache.ignite.internal.processors.query.IgniteSQLException: Failed to execute DML statement [stmt=merge INTO Patient (id, name, address, orgid) VALUES ( ?, ?, ?, ?), params=[6, zain, KulaLampur, 10]]
at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.queryTwoStep(IgniteH2Indexing.java:1662)
at org.apache.ignite.internal.processors.query.GridQueryProcessor$4.applyx(GridQueryProcessor.java:1659)
at org.apache.ignite.internal.processors.query.GridQueryProcessor$4.applyx(GridQueryProcessor.java:1657)
at org.apache.ignite.internal.util.lang.IgniteOutClosureX.apply(IgniteOutClosureX.java:36)
at org.apache.ignite.internal.processors.query.GridQueryProcessor.executeQuery(GridQueryProcessor.java:2103)
at org.apache.ignite.internal.processors.query.GridQueryProcessor.queryTwoStep(GridQueryProcessor.java:1657)
at org.apache.ignite.internal.processors.cache.IgniteCacheProxy.query(IgniteCacheProxy.java:806)
… 12 more
Caused by: class org.apache.ignite.IgniteCheckedException: Key is missing from query
at org.apache.ignite.internal.processors.query.h2.dml.UpdatePlanBuilder.createSupplier(UpdatePlanBuilder.java:330)
at org.apache.ignite.internal.processors.query.h2.dml.UpdatePlanBuilder.planForInsert(UpdatePlanBuilder.java:195)
at org.apache.ignite.internal.processors.query.h2.dml.UpdatePlanBuilder.planForStatement(UpdatePlanBuilder.java:81)
at org.apache.ignite.internal.processors.query.h2.DmlStatementsProcessor.getPlanForStatement(DmlStatementsProcessor.java:412)
at org.apache.ignite.internal.processors.query.h2.DmlStatementsProcessor.updateSqlFields(DmlStatementsProcessor.java:140)
at org.apache.ignite.internal.processors.query.h2.DmlStatementsProcessor.updateSqlFieldsTwoStep(DmlStatementsProcessor.java:198)
at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.queryTwoStep(IgniteH2Indexing.java:1659)
… 18 more
Sadruddin Md
May 23, 2018I hope you are using latest version of ignite? Additionally can you put values in single quotes for the columns with character data type?
Sadruddin Md
May 23, 2018Just noticed in the error stack, the exception is “org.apache.ignite.IgniteCheckedException: Key is missing from query”.
Please rectify this
Naseer
May 23, 2018Yes, the problem is just I am sending the record only. while the write method needs the key and record.
write(Entry entry)
I can not use the put(long , patient) method in PHP. I just used normal SQL statement to insert the record to the cache.
I have used it before without the read-through and write-through functionality and it worked with me.
Nek
July 24, 2018@ Sadruddin, Example shows how to insert few records and its very helpful. thanks!! I would like to test this on multiple tables. Can you help me with steps to read a table 1 from Oracle DB to Cache 1 and perform some calculations on cache 1 based on values in cache 2 (loaded from table 2 and related to table 1) before writing it back to a new cache 3 (optional) and table 3 in DB. Also, how do I do this in a n/w. with my laptop as client and a physical server in n/w.
Anand
November 6, 2018Hi very nice article… Actually i am new to ignite…And willing to use ignite.net for my asp.net mssql server website…Actually i have stored procedure in mssql server in which every time I have to update user score and their rank in real-time basis… Currently I am using only mssql server…Please let me kNow how ignite can help me in processing of my stored procedure for leader board calculation in real-time basis..Assume user to be 1 million
Dev
March 24, 2020After doing all the steps I am getting exceptions as below. Could you please help.
objIgnite.getOrCreateCache(ordersCacheCfg); line is throwing exception and in server logs I am getting –
java.lang.RuntimeException: Failed to create an instance of com.example.IgnitePersistenceCache.adapter.OrdersCacheStoreAdapter
at javax.cache.configuration.FactoryBuilder$ClassFactory.create(FactoryBuilder.java:134)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.createCacheContext(GridCacheProcessor.java:1199)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepareCacheContext(GridCacheProcessor.java:1995)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepareCacheStart(GridCacheProcessor.java:1926)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.lambda$prepareStartCaches$55a0e703$1(GridCacheProcessor.java:1801)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.lambda$prepareStartCachesIfPossible$9(GridCacheProcessor.java:1771)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepareStartCaches(GridCacheProcessor.java:1798)
at org.apache.ignite.internal.processors.cache.GridCacheProcessor.prepareStartCachesIfPossible(GridCacheProcessor.java:1769)
at org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager.processCacheStartRequests(CacheAffinitySharedManager.java:965)
at org.apache.ignite.internal.processors.cache.CacheAffinitySharedManager.onCacheChangeRequest(CacheAffinitySharedManager.java:851)
Client logs –
javax.cache.CacheException: class org.apache.ignite.IgniteCheckedException: Failed to complete exchange process.
at org.apache.ignite.internal.processors.cache.GridCacheUtils.convertToCacheException(GridCacheUtils.java:1317)
at org.apache.ignite.internal.IgniteKernal.getOrCreateCache0(IgniteKernal.java:3321)
at org.apache.ignite.internal.IgniteKernal.getOrCreateCache(IgniteKernal.java:3285)
at com.example.IgnitePersistenceCache.impl.IgniteWriteThroughCache.main(IgniteWriteThroughCache.java:45)
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to complete exchange process.
at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.createExchangeException(GridDhtPartitionsExchangeFuture.java:3380)
at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.sendExchangeFailureMessage(GridDhtPartitionsExchangeFuture.java:3408)
at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.finishExchangeOnCoordinator(GridDhtPartitionsExchangeFuture.java:3504)
at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.onAllReceived(GridDhtPartitionsExchangeFuture.java:3485)
at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.distributedExchange(GridDhtPartitionsExchangeFuture.java:1610)
at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.init(GridDhtPartitionsExchangeFuture.java:891)
at org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeWorker.body0(GridCachePartitionExchangeManager.java:3172)
at org.apache.ignite.internal.processors.cache.GridCachePartitionExchangeManager$ExchangeWorker.body(GridCachePartitionExchangeManager.java:3021)
at org.apache.ignite.internal.util.worker.GridWorker.run(GridWorker.java:120)
at java.base/java.lang.Thread.run(Thread.java:834)
Suppressed: class org.apache.ignite.IgniteCheckedException: Failed to initialize exchange locally [locNodeId=4f8b6ee5-28c9-40c4-bef6-eec1e6edcbc5]
at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.onCacheChangeRequest(GridDhtPartitionsExchangeFuture.java:1313)
at org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture.init(GridDhtPartitionsExchangeFuture.java:820)
… 4 more
Caused by: java.lang.RuntimeException: Failed to create an instance of com.example.IgnitePersistenceCache.adapter.OrdersCacheStoreAdapter
at javax.cache.configuration.FactoryBuilder$ClassFactory.create(FactoryBuilder.java:134)