Aniketh Jain
Aniketh Jain

Reputation: 625

Role of H2 database in Apache Ignite

I have an Apache Spark Job and one of its components fires queries at Apache Ignite Data Grid using Ignite SQL and the query is a SQLFieldsQuery. I was going through the thread dump and in one of the Executor logs I saw the following :

org.h2.mvstore.db.TransactionStore.begin(TransactionStore.java:229)

org.h2.engine.Session.getTransaction(Session.java:1580)

org.h2.engine.Session.getStatementSavepoint(Session.java:1588)

org.h2.engine.Session.setSavepoint(Session.java:793)

org.h2.command.Command.executeUpdate(Command.java:252)

org.h2.jdbc.JdbcStatement.executeUpdateInternal(JdbcStatement.java:130)

org.h2.jdbc.JdbcStatement.executeUpdate(JdbcStatement.java:115)

org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.connectionForThread(IgniteH2Indexing.java:428)

org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.connectionForSpace(IgniteH2Indexing.java:360)

org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.queryLocalSqlFields(IgniteH2Indexing.java:770)

org.apache.ignite.internal.processors.query.GridQueryProcessor$5.applyx(GridQueryProcessor.java:892)

org.apache.ignite.internal.processors.query.GridQueryProcessor$5.applyx(GridQueryProcessor.java:886)

org.apache.ignite.internal.util.lang.IgniteOutClosureX.apply(IgniteOutClosureX.java:36)

org.apache.ignite.internal.processors.query.GridQueryProcessor.executeQuery(GridQueryProcessor.java:1666)

org.apache.ignite.internal.processors.query.GridQueryProcessor.queryLocalFields(GridQueryProcessor.java:886)

org.apache.ignite.internal.processors.cache.IgniteCacheProxy.query(IgniteCacheProxy.java:698)

com.test.ignite.cache.CacheWrapper.queryFields(CacheWrapper.java:1019)

The last line in my code executes a sql fields query as follows :

SqlFieldsQuery sql = new SqlFieldsQuery(queryString).setArgs(args);
cache.query(sql);

According to my understanding, Ignite has its own data grid which it uses to store the cache data and indices. It only makes use of H2 database to parse the SQL query and get a query execution plan.

But, the Thread dump shows that updates are being executed and transactions are involved. I don't understand the need for transactions or updates in a SQL Select Query.

I want to know the following about the role of H2 database in Ignite :

Upvotes: 3

Views: 3416

Answers (1)

Sergi Vladykin
Sergi Vladykin

Reputation: 344

  1. Yes, we call executeUpdate to set schema. In Ignite 2.x we will be able to switch to Connection.setSchema for that. Right now we create SQL schema for each cache and you can create multiple tables in it, but this is going to be changed in the future. It does not actually contain anything, we just utilize some H2 APIs.
  2. Space name is basically the same thing as a cache name. You can configure SQL schema name for a cache using CacheConfiguration.setSqlSchema.
  3. If you run queries using the same cache instance, schema will not change.

Upvotes: 1

Related Questions