Hibernate search with infinispan, How to store the index in a persistent cache store - hibernate-search

Hibernate search default infinispan configuration store indexes in memory,you have to reindex everything once you shutdown application.
I read infinispan document, there is a way to store index into a infinispan file store. After I do googling around and around, I still don't know how to configure it.

You can check Infinispan user guide chapters 5 (Persistence) and 16 (Infinispan as a storage for Lucene indexes). Chapter numbers are from Infinispan 8.2. Hibernate search also provides a "default-hibernatesearch-infinispan.xml" file to start with. You basically need to add persistence to metadata and actual index caches. Here is the one I use for index cache:
<distributed-cache name="LuceneIndexesData" mode="SYNC" remote-timeout="25000">
<transaction mode="NONE"/>
<state-transfer enabled="true" timeout="480000" await-initial-transfer="true"/>
<indexing index="NONE"/>
<locking striping="false" acquire-timeout="10000" concurrency-level="500" write-skew="false"/>
<eviction max-entries="-1" strategy="NONE"/>
<expiration max-idle="-1"/>
<persistence passivation="false">
<jdbc:string-keyed-jdbc-store preload="true" fetch-state="true" read-only="false" purge="false">
<jdbc:data-source jndi-url="java:comp/env/jdbc/..."/>
<jdbc:string-keyed-table drop-on-exit="false" create-on-start="true" prefix="ISPN_STRING_TABLE">
<jdbc:id-column name="ID" type="VARCHAR(255)"/>
<jdbc:data-column name="DATA" type="MEDIUMBLOB"/>
<jdbc:timestamp-column name="TIMESTAMP" type="BIGINT"/>
</jdbc:string-keyed-table>
<property name="key2StringMapper">org.infinispan.lucene.LuceneKey2StringMapper</property>
<write-behind/>
</jdbc:string-keyed-jdbc-store>
</persistence>
</distributed-cache>
This example uses JDBC because it works on a dynamic cluster. You need to replace "jdbc:string-keyed=jdbc-store" with a "file-store" if you want to store the index a file.

Related

How to access only virtual views and hide physical tables with a standalone-vdb.xml wildfly/Teiid domain

We are using standalone-vdb.xml domain to create a vdb and then make it accessible through Jupiter for other users.
Now based on the xml file below as an example, we created the VIEW "customer_view"
from the table "Export2.customer_table" and they are both accessible from the Jupiter.
However, we only want the VIEWS to be accessible and not the physical tables
which property can be used to hide the tables and only expose the VIEWS for the end user.
Any one have a clue which property can do that? I tried to find it from the documentation but couldn't find any mentioning for that.
we are using WildFly Full 17.0.1 through the HAL management interface in a Docker container environment and Postgresql database.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<vdb name="stock" version="1">
<description>The VDB</description>
<property name="UseConnectorMetadata" value="true" />
<model visible="true" name="Export2">
<property name="importer.useFullSchemaName" value="false"/>
<property name="importer.schemaPattern" value="public"/>
<property name="importer.tableTypes" value="TABLES,VIEW"/>
<source name="stockDS" translator-name="postgresql" connection-jndi-name="java:jboss/datasources/stockDS"/>
</model>
<model visible="true" name="Data" type="VIRTUAL">
<metadata type="DDL"><![CDATA[
CREATE VIEW customer_view (
field_names string,
field_description string
) AS
SELECT variable_name, variable_description
FROM Export2.customer_table;
]]> </metadata>
</model>
<data-role name="RoleA" any-authenticated="true">
<description>Allow Reads and Writes to tables and procedures</description>
<permission>
<resource-name>Export2.customer_table</resource-name>
<allow-create>true</allow-create>
<allow-read>true</allow-read>
<allow-update>true</allow-update>
</permission>
<mapped-role-name>Admin</mapped-role-name>
</data-role>
</vdb>
see http://teiid.github.io/teiid-documents/master/content/reference/r_xml-deployment-mode.html
you need to define the model with visibility to false like
<model visible="false" name="Export2">
note that this will remove the metadata exposure from any APIs, however, if someone knows the schema they still can use the same connection to issue the query and see the data. If you want to avoid that then you need to look into data security policies to avoid any access.

Infinispan Cache store - "class not found" Exception in wildlfy addon module

I am using the 11.0.7 Infinispan cache store which is configured with an XML file. I have imported that cache module in a Wildlfy server. I am using this dependency in my application. But when I try to fetch cache elements from cache, it gives me the exception ClassNotFound.
I have used this configuration:
<local-cache name="TaskStoreCache" statistics="false">
<locking acquire-timeout="60000" />
<persistence passivation="false">
<rocksdb-store path=" C:\CacheStore\Data\TaskStoreCache" preload="false" shared="false"
purge="false" read-only="false">
<expiration path="C: \CacheStore\Expired\TaskStoreCache"/>
</rocksdb-store>
</persistence>
<memory max-count="500"/>
<encoding media-type="application/x-java-object"/>
</local-cache>
And I used this serialization:
<serialization marshaller="org.infinispan.commons.marshall.JavaSerializationMarshaller">
<white-list>
<regex>com.xyz.cache.*</regex>
<regex>java.util.*</regex>
<regex>java.lang.*</regex>
</white-list>
</serialization>
I am sure it is a class loading related issue. Please help me with that.
You should double-check how the dependency is wrapped into your application (war/ear), and make sure the scope is correct.
If you did not pack it within your application, the module has to be present on your wildfly and known to your application (e.g. jboss-deployment-structure.xml)

Infinispan cache table not auto-created with Wildfly 15+ using invalidation-cache and jdbc-store

I am attempting to use the jdbc-store type for my session cache in Wildfly 15+.
I ran the following commands to configure my standalone-full-ha.xml configuration file:
/subsystem=infinispan/cache-container=web/invalidation-cache=jdbc/:add(mode=SYNC)
/subsystem=infinispan/cache-container=web/invalidation-cache=jdbc/store=none:remove(){allow-resource-service-restart=true}
/subsystem=infinispan/cache-container=web/invalidation-cache=jdbc/store=jdbc/:add(data-source="...",passivation=false,shared=true){allow-resource-service-restart=true}
/subsystem=infinispan/cache-container=web/invalidation-cache=jdbc/component=transaction/:add()
/subsystem=infinispan/cache-container=web/invalidation-cache=jdbc/component=transaction/:write-attribute(name=mode,value=BATCH)
/subsystem=infinispan/cache-container=web:write-attribute(name=default-cache,value=jdbc)
... which produces the following in the configuration file:
<cache-container name="web" default-cache="jdbc" module="org.wildfly.clustering.web.infinispan">
<transport lock-timeout="60000"/>
<invalidation-cache name="jdbc">
<transaction mode="BATCH"/>
<jdbc-store data-source="..." passivation="false" shared="true">
<table/>
</jdbc-store>
</invalidation-cache>
<distributed-cache name="dist">
<locking isolation="REPEATABLE_READ"/>
<transaction mode="BATCH"/>
<file-store/>
</distributed-cache>
</cache-container>
It looks like I've configured the cache correctly using JBoss CLI, but when the cluster instances start-up, the session store table is not created in the database, even though everything starts up properly.
My question is, is there something that I should be setting in the <table/> element that I'm just overlooking? Looking at the documentation, I don't see any required attributes, or anything about auto-creation.
I've looked at previous examples of how to achieve this in Wildfly 11, but the string-keyed-jdbc-store element no longer seems to be valid. I know the Infinispan documentation mentions the create-on-start attribute on the string-keyed-table element, but this configuration is so wildly different in Wildfly that it's completely unhelpful.
Add
<property name="createTableOnStart">
true
</property>
in your jdbc-store element
and make sure your web.xml is <distributable />

Wildfly 12 - Does HttpSession replication work only if it is configured with transaction?

I'm trying to use session replication but without lock contention.
So I set up the infinispan "web" cache-container like this:
<cache-container name="web" default-cache="repl" module="org.wildfly.clustering.web.infinispan">
<transport lock-timeout="60000"/>
<replicated-cache name="repl">
<locking isolation="READ_COMMITTED"/>
<transaction locking="OPTIMISTIC" mode="NONE"/>
<file-store/>
</replicated-cache>
</cache-container>
But the session is not replicating across the cluster.
It replicates only if I use mode="BATCH" and default transaction locking PESSIMISTIC. But with this strategy does not perform well with long requests (about 2~3 seconds) and a lot of concurrent access (one request locks others requests because the first request owns the session lock).
Is there any way to replicate the session across the cluster without using transaction and consequently without session lock?
Thanks!

Mule CE: Database Connector and JBoss/XA Transaction work together?

I would like to use JBoss/XA Transacion with Database Connector component in Mule 3.7.
But an exception is throws: Transactional action is ALWAYS_JOIN but there is no active transaction (java.lang.IllegalStateException).
My transactional scenario is:
Pool + Database component - select table A
VM Component. Just to start a transaction - ALWAYS_BEGIN
Database component - MySQL - insert table B
Database component - Oracle - insert table C
We must ensure that both inserts running and commit together or rollback together.
Following XML code:
<jbossts:transaction-manager doc:name="JBoss Transaction Manager">
<property key="com.arjuna.ats.arjuna.coordinator.defaultTimeout" value="50" />
<property key="com.arjuna.ats.arjuna.coordinator.txReaperTimeout" value="108000"/><
</jbossts:transaction-manager>
<spring:beans>
<spring:bean id="oraDataSource" class="oracle.ucp.jdbc.PoolXADataSourceImpl" name="Bean">
<spring:property name="URL" value="jdbc:oracle:thin:#//${db.host}:${db.port}/${db.instance}"/>
<spring:property name="user" value="${db.user}"/>
<spring:property name="password" value="${db.password}"/>
<spring:property name="connectionFactoryClassName" value="oracle.jdbc.xa.client.OracleXADataSource"/>
<spring:property name="minPoolSize" value="1"/>
<spring:property name="maxPoolSize" value="20"/>
<spring:property name="connectionWaitTimeout" value="30"/>
</spring:bean>
</spring:beans>
<spring:bean id="mysqlDataSource" class="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource">
<spring:property name="url" value="jdbc:mysql://${mysql.host}:${mysql.port}/${mysql.instance}?user=${mysql.user}&password=${mysql.password}" />
</spring:bean>
<db:oracle-config name="Oracle_Configuration" doc:name="Oracle Configuration Bean" dataSource-ref="oraDataSource"/>
<db:mysql-config name="MySQL_Configuration" doc:name="MySQL Configuration Bean" dataSource-ref="mysqlDataSource"/>
<vm:connector name="VM" validateConnections="true" doc:name="VM"/>
<flow name="propostaFlow" processingStrategy="synchronous">
<poll doc:name="Poll">
<fixed-frequency-scheduler frequency="1000"/>
<watermark variable="carimboTempo" default-expression="2016-01-01 00:00:00" selector="MAX" selector-expression="#[payload.date_modified]"/>
<db:select config-ref="MySQL_Configuration" doc:name="Database Proposta">
<db:parameterized-query><![CDATA[select a.id, a.number, a.date_modified from table_a a where a.date_modified > #[flowVars.carimboTempo]]]></db:parameterized-query>
</db:select>
</poll>
<foreach doc:name="For Each - Proposta">
<vm:outbound-endpoint exchange-pattern="one-way" path="in" connector-ref="VM" doc:name="VM">
<xa-transaction action="ALWAYS_BEGIN" timeout="10000"/>
</vm:outbound-endpoint>
<enricher target="#[flowVars.resultadoInsert1]" doc:name="Message Enricher">
<db:insert config-ref="Oracle_Configuration" transactionalAction="ALWAYS_JOIN" doc:name="Database 1">
<db:parameterized-query><![CDATA[insert into table_b(ID, NAME) values(#[payload.id],#[payload.name])]]></db:parameterized-query>
</db:insert>
</enricher>
<db:insert config-ref="MySQL_Configuration" transactionalAction="ALWAYS_JOIN" doc:name="Database 2">
<db:parameterized-query><![CDATA[insert into table_c(ID, NAME) values(#[payload.id],#[payload.name])]]></db:parameterized-query>
</db:insert>
</foreach>
</flow>
IMPORTANT: We are using Mule 3.7.0 CE. We know that in Mule EE a solution is very easy with <transaction> and XA.
Questions:
Did we something wrong?
Is the Database Connect component aware of the JBoss/XA Transaction?
Is a correct form to start XA transaction with VM Component?
Finally, what we want to do, embed XA transaction in Mule CE, is really possible?
Thanks!
Based from the link you provided, since you use the driver classes oracle.jdbc.xa.client.OracleXADataSource and com.mysql.jdbc.jdbc2.optional.MysqlXADataSource you need to update the configuration like the following:
<jdbc:inbound-endpoint queryKey="selectQuery"
connector-ref="jdbcConnectorSource" pollingFrequency="10000">
<xa-transaction action="ALWAYS_BEGIN" />
</jdbc:inbound-endpoint>
<jdbc:outbound-endpoint queryKey="insert_call"
connector-ref="jdbcConnectorDest">
<xa-transaction action="ALWAYS_JOIN" />
</jdbc:outbound-endpoint>
Based on my experience I have found that the only way to use XA transactions is to use Mule EE.
You have to include your transactional operations (for example database update and JMS publishing ) in this block
<ee:xa-transactional action="ALWAYS_BEGIN" doc:name="Transactional">
and be sure to use database XA datasource, JMS XA connection factory and a transaction manager like this
<jbossts:transaction-manager doc:name="JBoss Transaction Manager" />
I've noticed this difference in Anypoint Studio between CE and EE.
In Mule CE transactional block, you can only specify transaction action
Instead in Mule EE you can specify transaction action and transaction type
Francesco.