Is it possible to use Apache Ignite as transparent cache for several tables in PostgreSQL RDBMS and to query that cache using Ignite SQL?
For example like this:
Application (via SQL) ---> Apache Ignite (if data is not loaded) ---> Postgresql
I'm new to Ignite and cannot figure out how to do that or is it even possible.
Ignite's SQL works over in-memory data only so you need to load data into caches beforehand. In other words, read-through doesn't work for SQL queries.
Starting with version 2.1 Ignite provides its custom persistent store that allows running SQL queries against the data both in memory and on disk.
It will work, if you preload data to cache before querying.
You can do it by configuring a CacheStore and calling IgniteCache#loadCache(). Here is documentation: https://apacheignite.readme.io/v2.3/docs/3rd-party-store#cachestore
Another option is to enable readThrough parameter and use cache API. Unfortunately, this option has no effect on Ignite SQL and works for cache API only.
Related
I am working with an application where we have SQL Server as a database. There is a requirement to add Hazelcast cache layer over the SQL Server. This is a legacy system and sort of works like SQL as a service where SQL queries to be executed against SQL Server DB are stored in a configuration table. For instance there is a UI for which data is returned by the query
Select case when page > 18 then 'Adult' else 'Teen' as Category, convert(varchar(20), p.registrationDate) as registeredOn from Person p
This is dynamically fetched and retrieved and executed against the database. There are many such views rendered off dynamic queries. With Hazelcast some of these SQL syntax will not just work. Is there any database abstraction framework or library or some adapter layer which can take in the SQL query and execute it against Hazelcast?
I see a few choices with different trade-offs:
Use an ORM library (e.g. Hibernate) with Hazelcast as a 2nd level cache. ORM fully manages the cache by caching the entities and queries automatically. You should however use the ORM API instead of the native SQL. That might require you to rewrite the app code.
Cache complete query results and use the SQL query as a key. This is the least invasive option and is just good enough if the DB data change rarely and you use the same SQL queries repeatedly. By using cache-aside pattern, the changes to your app will be minimal (https://hazelcast.com/blog/a-hitchhikers-guide-to-caching-patterns/)
Query Hazelcast using SQL. This gives you most options to optimize the performance. Cache the DB tables you need and query Hazelcast using SQL. Might require rewriting the SQL queries to comply with Hazelcast SQL limitations: https://docs.hazelcast.com/hazelcast/5.1-beta-1/sql/sql-overview#limitations
I have some application written in JAVA.
We are using MySQL DB.
It is possible to integrate that MySQL DB with Apache Ignite as In Memory cache and use that configuration without any updates in JAVA application (of course some DB connection details should be changed)?
So my application do the same staff but only difference will be connection with Apache Ignite instead of MySQL?
It is possible this kind of configuration?
I suppose you are looking for the write-through feature. I'm not sure what is your use case, but you should be aware of some limitations like your data have to be preloaded into Ignite before running SELECT queries. From a very abstract perspective, you need to define POJOs and implement a custom CacheStore interface. Though GridGain Control Center can do the latter for you automatically, check this demo as a reference.
I'm currently building a Spring Boot Service with a h2 in-memory database.
This Database acts as an cache for a part of the data on a central db2 database with a different database schema.
Now when the Spring boot service starts it needs to populate the h2 database with the latest data from the central database.
How can I do this in the best way performance wise?
I'm currently looking to create an different data-source in my service to first get the data and then save the data to the h2.
This doesn't feel like a good solution and it would take quite a long time to populate the database.
If you want to use H2 instead of your DB2 database ... and if you don't want to re-create the database each time you run your app ...
... then consider using an H2 file, instead of in-memory:
http://www.h2database.com/html/features.html
jdbc:h2:[file:][<path>]<databaseName>
jdbc:h2:~/test
jdbc:h2:file:/data/sample
jdbc:h2:file:C:/data/sample (Windows only)
You can "initialize" the file whenever you want (perhaps just once).
Performance should be excellent.
Per your update:
I still need to access the central db to get the latest data in the
fastest way possible. The central db needs to stay for other services
also accessing this
The "fastest" way to get the very latest data ... is to query the central db directly. Period - no ifs/ands/buts.
But, if for whatever reason, you want to "cache" a subset of "recent" data ... then H2 is an excellent choice.
And if you don't want to "rebuild" each time you start your H2 database, then save H2 to a file instead of making it in-memory.
The performance difference between H2:mem and H2:file is small, compared to the network overhead of querying your central db.
'Hope that helps...
I currently use MySQL as a persistent data store and I'd like to introduce data grid layer between my application and MySQL to handle database outages. I'd like to do it as non-invasively to the current application structure as possible.
Apache Ignite is shipped with two features related to my problem: write-behind caching strategy with 3rd party persistence and custom JDBC driver.
I would like to combine these two features as follows:
the application will use Ignite JDBC driver to persist data.
Ignite will query/update data in memory and will asynchronously flush data to the MySQL database (write-behind caching strategy).
when MySQL becomes unavailable Ignite will batch the updates until MySQL restores and will still serve queries/updates without affecting the client app.
Is this setup possible with only configuration changes like replacing the DataSource implementation and configuring the Ignite cache?
I don't think that 3-rd point is available from out of the box.The CacheStore implementation (for example, CacheJdbcPojoStore) assumes that connection to the underlying database is reliable and can be established at any time. The write-behind mechanism works in the same way, i.e. it can establish a connection when the internal buffer is overflowed, a timeout occurs, the back-pressure mechanism is triggered.
Thus, you have to implement your own CacheStore, which takes care of the accumulation of data, while the MySQL database is disabled for some reason.
Perhaps, the following links will be helpful:
https://apacheignite.readme.io/docs/3rd-party-store#section-cachestore
https://apacheignite.readme.io/docs/3rd-party-store#section-cachestoresession
I am using Postgres 9.3 on my production servers. I would like to achieve high availability of Postgres DB using Master-Master configuration where each master would run in an Active-Active mode with bidirectional replication.
I have 2 Java Spring REST web-services pointed to 2 separate database engines each having their own storage. Both web services point to its own database plus the other one in HA configuration.
Now if any one of the Databases fails, I want the active database server to work and when the failed one recover, the data should be synced back to the recovered one.
I tried doing bidirectional replication using Bucardo 5.3.1 but the recovered database does not get updated with the new data and Bucardo syncs need to be kicked again. (see bug: https://github.com/bucardo/bucardo/issues/88)
Is there any way I can achieve this with some other bi-directional replication tool?
Or is there any other way where I can have with 2 Postgres engines pointing to a shared storage running in Active-Active configuration?
2nd Quadrant released Postgres BDR which is a patched version of PostgreSQL that can do multimaster replication using logical WAL decoding. You will find more informations here : https://www.2ndquadrant.com/fr/resources/bdr/
I have finally decided to move to Enterprise DB of Postgres (a paid licence) that provides replication tools via GUI which are easy to use and configure.