简体   繁体   English

Lucene 热索引备份使用 IndexReader 而不是 IndexWriter/SnapshotDeletionPolicy

[英]Lucene hot index backup using IndexReader instead of IndexWriter/SnapshotDeletionPolicy

Are the following lines of code acceptable to get a hot backup of a lucene index or IndexWriter/SnapshotDeletionPolicy as described in Lucene index backup should be followed?是否应遵循以下代码行以获得 lucene 索引或 IndexWriter/SnapshotDeletionPolicy 的热备份,如Lucene 索引备份中所述?

Directory dir = ...;
IndexReader reader = IndexReader.open(dir);
IndexCommit commit = reader.getIndexCommit();
Collection<String> fileNames = commit.getFileNames();
//copy the files
reader.close();

Even on a locked index you may open a reader on a commit point while a writer may still change the index.即使在锁定的索引上,您也可以在提交点打开阅读器,而编写器仍可能更改索引。

If you have no IndexWriter writing to the index, then the above code is fine.如果您没有 IndexWriter 写入索引,那么上面的代码就可以了。

But an open IndexWriter against the index can easily delete the files referenced/still in use by this IndexReader (for example, when a merge completes) and then your backup will fail.但是针对索引打开的 IndexWriter 可以轻松删除此 IndexReader 引用/仍在使用的文件(例如,当合并完成时),然后您的备份将失败。

You need to use a SnapshotDeletionPolicy.您需要使用 SnapshotDeletionPolicy。

Unless you have an unreleased snapshot, the writer will be free to delete files as it pleases.除非您有未发布的快照,否则作者可以随意删除文件。 This will only happen on flush/close, so you might be able to get away with it most of the time, but it won't always work.这只会在刷新/关闭时发生,因此您可能大部分时间都可以摆脱它,但它并不总是有效。

Note that the policy is owned by the writer, so if you're trying to somehow use one process to back it up while another process writes, this won't work.请注意,该策略归作者所有,因此如果您试图以某种方式使用一个进程来备份它,而另一个进程正在写入,这将不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM