2013-07-19 4 views
2

나는 Lucene 4.3.1 클러스터가 있으며, 매닝에서 "Lucene in Action" 책에 설명 된 것과 유사한 자동 핫 백업 프로세스를 추가하고 있습니다. 블로그 게시물이 있습니다. 그러나이 책은 Lucene 2.3을 기반으로하며 API는 4.3.1에서 약간 변경되었습니다. 이 책은 그래서 같은 IndexWriter 인스턴스를 말한다 :Lucene 4.3.1 백업 프로세스

IndexDeletionPolicy policy = new KeepOnlyLastCommitDeletionPolicy(); 
SnapshotDeletionPolicy snapshotter = new SnapshotDeletionPolicy(policy); 
IndexWriter writer = new IndexWriter(dir, analyzer, snapshotter, 
           IndexWriter.MaxFieldLength.UNLIMITED); 

때 백업을 수행 :

try { 
    IndexCommit commit = snapshotter.snapshot(); 
    Collection<String> fileNames = commit.getFileNames(); 
    /*<iterate over & copy files from fileNames>*/ 
} finally { 
    snapshotter.release(); 
} 

그러나,이 어떤 시점에서 루씬 4.x를 변경할 것으로 보인다. 이제 SnapshotDeletionPolicy가 IndexWriterConfig로 구성되며 IndexWriter를 만들 때 전달됩니다. 이것은 내가 지금까지 가지고있는 코드 :

public Indexer(Directory indexDir, PrintStream printStream) throws IOException { 
    IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_43, new Analyzer()); 
    snapshotter = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy()); 
    writerConfig.setIndexDeletionPolicy(snapshotter); 
    indexWriter = new IndexWriter(indexDir, writerConfig); 
} 

그리고 백업을 시작할 때, 당신은 단지 snapshotter.snapshot() 할 수 없습니다. 이제 commitIdentifier id를 임의로 지정해야하며 완료 후에 스냅 샷을 해제해야합니다.

SnapshotDeletionPolicy snapshotter = indexer.getSnapshotter(); 
String commitIdentifier = generateCommitIdentifier(); 
try { 
    IndexCommit commit = snapshotter.snapshot(commitIdentifier); 
    for (String fileName : commit.getFileNames()) { 
     backupFile(fileName); 
    } 
} catch (Exception e) { 
    logger.error("Exception", e); 
} finally { 
    snapshotter.release(commitIdentifier); 
    indexer.deleteUnusedFiles(); 
} 

그러나 이것은 작동하지 않는 것 같습니다. 색인이있는 문서가 있는지 여부와 상관없이 내가 커밋했는지 여부에 관계없이 snapshotter.snapshot(commitIdentifier)에 대한 호출은 항상 IllegalStateExceptionNo index commit to snapshot이라고합니다. 코드를 살펴보면 SnapshotDeletionPolicy는 5 초마다 디스크에 커밋하고 있음에도 커밋이 없다고 생각하는 것 같습니다. 필자는 검증을했고, 항상 색인을 작성하고 작성하고있는 문서가 있지만, snapshotter은 항상 커밋이 0이라고 생각합니다.

아무도 내가 뭘 잘못하고 있다고 말할 수 있습니까? 자세한 내용을 게시해야하는지 알려주세요.

+0

Lucene/Solr 메일 링리스트가 도움이 될 것 같습니다. 그리고 'Lucene Cluster'는 무엇입니까? 솔라? – bmargulies

+0

늦게 답장을 드려 죄송합니다. Lucene 메일 링리스트에 도움을 얻었습니다. 감사합니다. "Lucene cluster"는 집에서 자란 Solr과 같은 클러스터를 의미하지만 Solr을 사용하지 않았습니다. – mjuarez

답변

2

나는이 질문을 Lucene java-user 메일 링리스트에 올렸고 거의 즉시 대답을 얻었다. 문제는 처음에 IndexWriter을 구성하는 데 사용하는 SnapshotDeletionPolicy가 IndexWriter가 사용하는 것과 동일하지 않다는 것입니다. 건설에서 IndexWriter 실제로는 SnapshotDeletionPolicy 당신이 전달 클론, 그래서 위의 코드의 첫 번째 블록 대신 다음과 같아야합니다

public Indexer(Directory indexDir, PrintStream printStream) throws IOException { 
    IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_43, new Analyzer()); 
    writerConfig.setIndexDeletionPolicy(new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy())); 
    indexWriter = new IndexWriter(indexDir, writerConfig); 
    snapshotter = (SnapshotDeletionPolicy) indexWriter.getConfig().getIndexDeletionPolicy(); 
} 

주의 마지막 줄, 어디로부터의 IndexDeletionPolicy에 snapshotter을 설정하는 IndexWriter 구성. 그게 핵심이야. 그 후, 원래의 질문에 상세하게 설명 된 두 번째 코드가 완벽하게 작동합니다.

참고로, here's the answer 나는 Apache Lucene 메일 링리스트에서 가져 왔습니다.