나는 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)
에 대한 호출은 항상 IllegalStateException
을 No index commit to snapshot
이라고합니다. 코드를 살펴보면 SnapshotDeletionPolicy는 5 초마다 디스크에 커밋하고 있음에도 커밋이 없다고 생각하는 것 같습니다. 필자는 검증을했고, 항상 색인을 작성하고 작성하고있는 문서가 있지만, snapshotter
은 항상 커밋이 0이라고 생각합니다.
아무도 내가 뭘 잘못하고 있다고 말할 수 있습니까? 자세한 내용을 게시해야하는지 알려주세요.
Lucene/Solr 메일 링리스트가 도움이 될 것 같습니다. 그리고 'Lucene Cluster'는 무엇입니까? 솔라? – bmargulies
늦게 답장을 드려 죄송합니다. Lucene 메일 링리스트에 도움을 얻었습니다. 감사합니다. "Lucene cluster"는 집에서 자란 Solr과 같은 클러스터를 의미하지만 Solr을 사용하지 않았습니다. – mjuarez