2 Replies Latest reply on Jan 4, 2013 3:35 AM by johnbesel

    InfinispanDirectory, two Cluster

      Hello together,

       

      I use Lucene with InfinispanDirectory because we have two mashines and we need to bind them in a cluster.

       

      in documentation of Infinispan I found following limitation:

      "As when using an IndexWriter on a filesystem based Directory, even on the clustered edition only one IndexWriter can be opened across the whole cluster."

      https://docs.jboss.org/author/display/ISPN/Infinispan+as+a+Directory+for+Lucene

       

      If I have the same application on two or more nodes, how can I know that the IndexWriter is already opened on other node???

       

      my code is:

      EmbeddedCacheManager manager = new DefaultCacheManager("infinispan.xml");

      Cache<Object, Object> cache = manager.getCache("customerIndexerCache");

       

      customerIndexDirectory = new InfinispanDirectory(cache, "customerIndex");

      writer = new IndexWriter(customerIndexDirectory, config);

       

      My infinispan.xml has following cache entry:

         <namedCache name="customerIndexerCache">

            <clustering mode="replication" />

         </namedCache>

       

      when I execute this code on two nodes, then I make

              writer = new IndexWriter(customerIndexDirectory, config);

      on two nodes.

       

      Both nodes take data from the same source and will try to create lucene documents and add to the writer. Should I avoid it somehow in my source, or does infinispanDirectory it for me?

       

       

      thank you for your answer.

        • 1. Re: InfinispanDirectory, two Cluster
          sannegrinovero

          Hello,

          when opening an IndexWriter on any Directory implementation is implicitly acquires an exclusive Lock.

          So if you try opening an IndexWriter on both nodes at the same time, you won't corrupt the index but one of the two nodes will succeed and the other will likely see a timeout exception.

           

          If your application doesn't open IndexWriters very often, you might have the code just try and hope for the best, eventually retrying; but it's of course better and less tricky if you can configure your application in such a way that only one of the two nodes ever attempts to write to the index.

           

          For example Infinispan Query uses the Hibernate Search engine to delegate writes to a remote node; the options there are to use JMS or JGroups to forward needs to write to a specific node.

          I'd suggest to have a look in this chapter: http://docs.jboss.org/hibernate/search/4.2/reference/en-US/html_single/#d0e652

          1 of 1 people found this helpful
          • 2. Re: InfinispanDirectory, two Cluster

            thank you for your answer.

             

            I think it will help me to understand what should I do as next.