Class IndexReplicationHandler
- All Implemented Interfaces:
ReplicationClient.ReplicationHandler
ReplicationClient.ReplicationHandler for replication of an index. Implements revisionReady(java.lang.String, java.util.Map<java.lang.String, java.util.List<org.apache.lucene.replicator.RevisionFile>>, java.util.Map<java.lang.String, java.util.List<java.lang.String>>, java.util.Map<java.lang.String, org.apache.lucene.store.Directory>) by
copying the files pointed by the client resolver to the index Directory and then touches
the index with IndexWriter to make sure any unused files are deleted.
NOTE: this handler assumes that IndexWriter is not opened by another process on
the index directory. In fact, opening an IndexWriter on the same directory to which files
are copied can lead to undefined behavior, where some or all the files will be deleted, override
other files or simply create a mess. When you replicate an index, it is best if the index is
never modified by IndexWriter, except the one that is open on the source index, from
which you replicate.
This handler notifies the application via a provided Callable when an updated index
commit was made available for it.
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDeprecated.The component used to log messages to thedefaultInfoStream. -
Constructor Summary
ConstructorsConstructorDescriptionIndexReplicationHandler(Directory indexDir, Callable<Boolean> callback) Deprecated.Constructor with the given index directory and callback to notify when the indexes were updated. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcleanupFilesOnFailure(Directory dir, List<String> files) Deprecated.Cleanup the index directory by deleting all given files.static voidcleanupOldIndexFiles(Directory dir, String segmentsFile, InfoStream infoStream) Deprecated.Cleans up the index directory from old index files.static voidDeprecated.Copies the files from the source directory to the target one, if they are not the same.Deprecated.Returns the current revision files held by the handler.Deprecated.Returns the current revision version held by the handler.static IndexCommitgetLastCommit(Directory dir) Deprecated.static StringgetSegmentsFile(List<String> files, boolean allowEmpty) Deprecated.Verifies that the last file is segments_N and fails otherwise.voidrevisionReady(String version, Map<String, List<RevisionFile>> revisionFiles, Map<String, List<String>> copiedFiles, Map<String, Directory> sourceDirectory) Deprecated.Called when a new revision was obtained and is available (i.e.voidsetInfoStream(InfoStream infoStream) Deprecated.Sets theInfoStreamto use for logging messages.
-
Field Details
-
INFO_STREAM_COMPONENT
Deprecated.The component used to log messages to thedefaultInfoStream.- See Also:
-
-
Constructor Details
-
IndexReplicationHandler
Deprecated.Constructor with the given index directory and callback to notify when the indexes were updated.- Throws:
IOException
-
-
Method Details
-
getLastCommit
Deprecated.- Throws:
IOException
-
getSegmentsFile
Deprecated.Verifies that the last file is segments_N and fails otherwise. It also removes and returns the file from the list, because it needs to be handled last, after all files. This is important in order to guarantee that if a reader sees the new segments_N, all other segment files are already on stable storage.The reason why the code fails instead of putting segments_N file last is that this indicates an error in the Revision implementation.
-
cleanupFilesOnFailure
Deprecated.Cleanup the index directory by deleting all given files. Called when file copy or sync failed. -
cleanupOldIndexFiles
Deprecated.Cleans up the index directory from old index files. This method uses the last commit found bygetLastCommit(Directory). If it matches the expected segmentsFile, then all files not referenced by this commit point are deleted.NOTE: this method does a best effort attempt to clean the index directory. It suppresses any exceptions that occur, as this can be retried the next time.
-
copyFiles
public static void copyFiles(Directory source, Directory target, List<String> files) throws IOException Deprecated.Copies the files from the source directory to the target one, if they are not the same.- Throws:
IOException
-
currentVersion
Deprecated.Description copied from interface:ReplicationClient.ReplicationHandlerReturns the current revision version held by the handler.- Specified by:
currentVersionin interfaceReplicationClient.ReplicationHandler
-
currentRevisionFiles
Deprecated.Description copied from interface:ReplicationClient.ReplicationHandlerReturns the current revision files held by the handler.- Specified by:
currentRevisionFilesin interfaceReplicationClient.ReplicationHandler
-
revisionReady
public void revisionReady(String version, Map<String, List<RevisionFile>> revisionFiles, Map<String, throws IOExceptionList<String>> copiedFiles, Map<String, Directory> sourceDirectory) Deprecated.Description copied from interface:ReplicationClient.ReplicationHandlerCalled when a new revision was obtained and is available (i.e. all needed files were successfully copied).- Specified by:
revisionReadyin interfaceReplicationClient.ReplicationHandler- Parameters:
version- the version of theRevisionthat was copiedrevisionFiles- the files contained by thisRevisioncopiedFiles- the files that were actually copiedsourceDirectory- a mapping from a source of files to theDirectorythey were copied into- Throws:
IOException
-
setInfoStream
Deprecated.Sets theInfoStreamto use for logging messages.
-