Как взять онлайн-горячее резервное копирование индекса Lucene FileDirecotry?

Я думаю о добавлении JMX-бина для горячего резервного копирования индекса lucene.

LuceneMBean mbean = new LuceneMBeanImpl(); имя_объекта = новое имя_объекта("indexing.index:type=lucene"); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); mbs.registerMBean(mbean, имя);

LuceneMBean будет иметь метод с именем backupIndex (каталог строк).

Я просмотрел документы Lucene и обнаружил метод copy() каталога. Если у меня есть Writer Open в каталоге, будет ли этот метод работать? В основном мой фрагмент кода выглядит следующим образом:

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

person Community    schedule 16.07.2009    source источник


Ответы (1)


Я думаю, что открытый Writer должен быть в порядке, но вы определенно не можете копировать, пока другой поток изменяет индекс, или вы можете получить исключение FileNotFoundException. Из источника:

 /**
   * 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 {
person bajafresh4life    schedule 16.07.2009