tags:

views:

156

answers:

1

Hi,

I am thinking of adding JMX bean for taking hot backup of lucene index.

LuceneMBean mbean = new LuceneMBeanImpl(); ObjectName name = new ObjectName("indexing.index:type=lucene"); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); mbs.registerMBean(mbean, name);

LuceneMBean will have method called backupIndex(String directory).

I have gone through lucene docs and I found out copy() method of Directory. If I have Writer Open on directory will this method will work? Basically my code snippet is like follows :

public class LuceneMBeanImpl implements LuceneMBean{
     public void backupIndex(String directory){
           Directory fileDirectory =  FSDirectory.getDirectory(directory);
           Directory.copy(masterDirectory, fileDirectory,false);
     }
}
A: 

I think an open Writer should be okay, but you definitely can't copy while another thread is modifying the index, or you may get a FileNotFoundException. From the source:

 /**
   * Copy contents of a directory src to a directory dest.
   * If a file in src already exists in dest then the
   * one in dest will be blindly overwritten.
   *
   * <p><b>NOTE:</b> the source directory cannot change
   * while this method is running.  Otherwise the results
   * are undefined and you could easily hit a
   * FileNotFoundException.
   *
   * @param src source directory
   * @param dest destination directory
   * @param closeDirSrc if <code>true</code>, call {@link #close()} method on source directory
   * @throws IOException
   */
  public static void copy(Directory src, Directory dest, boolean closeDirSrc) throws IOException {
bajafresh4life