1 Reply Latest reply on Apr 10, 2013 9:26 AM by andersbohn

    Infinispan Queries in AS7

    andersbohn

      Update 19th of June 2013:

      Using the container provided infinispan is NOT supported in Redhat EAP (even though it runs fine - in 6.1.0.Final at least). A supported solution would either be a separate JBoss DataGrid-server or embedding your own Infinispan in your app from DataGrid (or community..)

      (I've got most of it running and may post about it separately...)

       

      Previously posted (https://community.jboss.org/thread/196309) about using Hibernate Search and indexed infinispan caches in AS7.

      It's running in production, but the actual index is written (sort of overflows) into files on disk, and must be cleaned up at restart to avoid weird null search results.

      It's not possible to specify RAM in 7.1.x. (https://issues.jboss.org/browse/AS7-4022)

       

      With jboss-eap-6.1.0.Alpha this should be fixed, and I finally took the time to check it out. The setup is even a bit simpler (it could be simpler still, dunno if my approach is complete kosher):

       

      Add to standalone.xml:

       

      {code:xml}<local-cache name="searchindex" start="EAGER">

            <indexing index="LOCAL">

              <property name="hibernate.search.default.directory_provider">ram</property>

            </indexing>

            <eviction strategy="LRU" max-entries="120000"/>

            <expiration max-idle="-1"/>

          </local-cache>{code}

       

      For AS 7.2.0.Alpha1-redhat-4 I set up a module in <SERVER>/modules/system/layers/base/org/infinispan/query/main/module.xml

       

      {code:xml}<module xmlns="urn:jboss:module:1.0" name="org.infinispan.query">

        <resources>

       

          <resource-root path="infinispan-query-5.2.1.FINAL.jar"/>

       

          <resource-root path="avro-1.6.3.jar"/>

          <resource-root path="jackson-core-asl-1.8.8.jar"/>

          <resource-root path="jackson-mapper-asl-1.8.8.jar"/>

          <resource-root path="paranamer-2.3.jar"/>

          <resource-root path="snappy-java-1.0.4.1.jar"/>

       

          <resource-root path="lucene-core-3.6.2.jar"/>

       

          <resource-root path="hibernate-search-4.2.0.CR1.jar"/>

          <resource-root path="hibernate-search-orm-4.2.0.CR1.jar"/>

          <resource-root path="hibernate-search-analyzers-4.2.0.CR1.jar"/>

          <resource-root path="hibernate-search-engine-4.2.0.CR1.jar"/>

       

          <resource-root path="hibernate-search-infinispan-4.2.0.CR1.jar"/>

       

          <resource-root path="lucene-analyzers-3.6.2.jar"/>

          <resource-root path="lucene-grouping-3.6.2.jar"/>

          <resource-root path="lucene-highlighter-3.6.2.jar"/>

          <resource-root path="lucene-memory-3.6.2.jar"/>

          <resource-root path="lucene-misc-3.6.2.jar"/>

          <resource-root path="lucene-smartcn-3.6.2.jar"/>

          <resource-root path="lucene-spatial-3.6.2.jar"/>

          <resource-root path="lucene-spellchecker-3.6.2.jar"/>

          <resource-root path="lucene-stempel-3.6.2.jar"/>

       

          <resource-root path="solr-analysis-extras-3.6.2.jar"/>

          <resource-root path="solr-core-3.6.2.jar"/>

          <resource-root path="solr-solrj-3.6.2.jar"/>

       

        </resources>

        <dependencies>

          <module name="javax.api"/>

       

          <module name="javax.transaction.api"/>

       

          <module name="org.hibernate.commons-annotations" services="import"/>

          <module name="org.jgroups"/>

          <module name="org.hibernate" services="import"/>

       

          <module name="org.infinispan" services="import" export="true"/>

       

          <module name="org.apache.commons.codec"/>

          <module name="org.apache.commons.io"/>

          <module name="org.apache.commons.lang"/>

          <module name="com.google.guava"/>

       

          <module name="org.slf4j" export="true"/>

       

          <module name="org.jboss.logging"/>

       

        </dependencies>

      </module>{code}

       

      (All the jars are built with a maven assembly, so not sure if every single on is actually needed.)

       

      To allow the server-infinispan-cache-manager to load correctly, it needs a dendency added in <SERVER>/modules/system/layers/base/org/jboss/as/clustering/infinispan/main/module.xml:

       

      {code:xml}<...>

              <module name="net.jcip"/>

       

              <module name="org.infinispan.query" services="import" />

              <module name="org.infinispan" services="import"/>

      <...>{code}

       

      Finally the project must depend on the modules, eg:

       

      {code:xml}<?xml version="1.0" encoding="UTF-8"?>

      <jboss-deployment-structure>

        <ear-subdeployments-isolated>false</ear-subdeployments-isolated>

        <deployment>

          <dependencies>

            <module name="org.apache.log4j" export="true"/>

       

       

            <module name="org.slf4j" export="true"/>

       

       

            <module name="org.hibernate" export="true" services="import"/>

       

       

            <module name="org.infinispan" export="true" services="import"/>

            <module name="org.infinispan.query" export="true" services="import"/>

          </dependencies>

        </deployment>

      </jboss-deployment-structure>{code}

       

      It's now possible to inject the indexed cache in a bean:

       

      {code:java}  @Resource(mappedName = "java:jboss/infinispan/cache/bskCache/searchindex")

        Cache<String, Object> searchindexCache;{code}

       

      And obtain a Hibernate search manager via:

       

      {code:java}SearchManager searchManager = Search.getSearchManager(searchindexCache);{code}

       

      Documentation: https://docs.jboss.org/author/display/ISPN/Querying+Infinispan

        • 1. Re: Infinispan Queries in AS7
          andersbohn

          Ok, a more correct way would be to add a module similar to the built in ones (eg org.jboss.as.clustering.web.infinispan) and then attach this to the cache-container.

           

          {code:xml}<cache-container name="bskCache" default-cache="data" module="org.infinispan.query">{code}

           

          This way I need not modify <SERVER>/modules/system/layers/base/org/jboss/as/clustering/infinispan/main/module.xml:

           

          Added some lines to the module to get it to work. It should probably be split into two modules, one for the cache-container, and a subset for the app.

           

          Only downside is that Infinispan now warns me "Indexing can only be enabled if infinispan-query.jar is available on your classpath, and this jar has not been detected. Intended behavior may not be exhibited." on startup (but everything works fine..).