|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.lucene.replicator.IndexReplicationHandler
public class IndexReplicationHandler
A ReplicationClient.ReplicationHandler
for replication of an index. Implements
revisionReady(java.lang.String, java.util.Map
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.
Field Summary | |
---|---|
static String |
INFO_STREAM_COMPONENT
The component used to log messages to the default InfoStream . |
Constructor Summary | |
---|---|
IndexReplicationHandler(Directory indexDir,
Callable<Boolean> callback)
Constructor with the given index directory and callback to notify when the indexes were updated. |
Method Summary | |
---|---|
static void |
cleanupFilesOnFailure(Directory dir,
List<String> files)
Cleanup the index directory by deleting all given files. |
static void |
cleanupOldIndexFiles(Directory dir,
String segmentsFile)
Cleans up the index directory from old index files. |
static void |
copyFiles(Directory source,
Directory target,
List<String> files)
Copies the files from the source directory to the target one, if they are not the same. |
Map<String,List<RevisionFile>> |
currentRevisionFiles()
Returns the current revision files held by the handler. |
String |
currentVersion()
Returns the current revision version held by the handler. |
static IndexCommit |
getLastCommit(Directory dir)
Returns the last IndexCommit found in the Directory , or
null if there are no commits. |
static String |
getSegmentsFile(List<String> files,
boolean allowEmpty)
Verifies that the last file is segments_N and fails otherwise. |
void |
revisionReady(String version,
Map<String,List<RevisionFile>> revisionFiles,
Map<String,List<String>> copiedFiles,
Map<String,Directory> sourceDirectory)
Called when a new revision was obtained and is available (i.e. |
void |
setInfoStream(InfoStream infoStream)
Sets the InfoStream to use for logging messages. |
static void |
writeSegmentsGen(String segmentsFile,
Directory dir)
Writes IndexFileNames.SEGMENTS_GEN file to the directory, reading
the generation from the given segmentsFile . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String INFO_STREAM_COMPONENT
default
InfoStream
.
Constructor Detail |
---|
public IndexReplicationHandler(Directory indexDir, Callable<Boolean> callback) throws IOException
IOException
Method Detail |
---|
public static IndexCommit getLastCommit(Directory dir) throws IOException
IndexCommit
found in the Directory
, or
null
if there are no commits.
IOException
public static String getSegmentsFile(List<String> files, boolean allowEmpty)
The reason why the code fails instead of putting segments_N file last is that this indicates an error in the Revision implementation.
public static void cleanupFilesOnFailure(Directory dir, List<String> files)
public static void cleanupOldIndexFiles(Directory dir, String segmentsFile)
getLastCommit(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.
public static void copyFiles(Directory source, Directory target, List<String> files) throws IOException
IOException
public static void writeSegmentsGen(String segmentsFile, Directory dir)
IndexFileNames.SEGMENTS_GEN
file to the directory, reading
the generation from the given segmentsFile
. If it is null
,
this method deletes segments.gen from the directory.
public String currentVersion()
ReplicationClient.ReplicationHandler
currentVersion
in interface ReplicationClient.ReplicationHandler
public Map<String,List<RevisionFile>> currentRevisionFiles()
ReplicationClient.ReplicationHandler
currentRevisionFiles
in interface ReplicationClient.ReplicationHandler
public void revisionReady(String version, Map<String,List<RevisionFile>> revisionFiles, Map<String,List<String>> copiedFiles, Map<String,Directory> sourceDirectory) throws IOException
ReplicationClient.ReplicationHandler
revisionReady
in interface ReplicationClient.ReplicationHandler
version
- the version of the Revision
that was copiedrevisionFiles
- the files contained by this Revision
copiedFiles
- the files that were actually copiedsourceDirectory
- a mapping from a source of files to the Directory
they
were copied into
IOException
public void setInfoStream(InfoStream infoStream)
InfoStream
to use for logging messages.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |