public abstract class ReplicaNode extends Object
Modifier and Type | Field and Description |
---|---|
protected CopyJob |
curNRTCopy
Non-null when we are currently copying files from a new NRT point:
|
protected Directory |
dir |
static long |
globalStartNS
Startup time of original test, carefully propogated to all nodes to produce consistent "seconds since start time" in messages
|
protected int |
id
Compact ordinal for this node
|
protected Map<String,FileMetaData> |
lastFileMetaData
File metadata for last sync that succeeded; we use this as a cache
|
protected Collection<String> |
lastNRTFiles
IncRef'd files in the current NRT point:
|
protected long |
lastPrimaryGen
Primary gen last time we successfully replicated:
|
static long |
localStartNS
When this node was started
|
protected Set<CopyJob> |
mergeCopyJobs
Currently running merge pre-copy jobs
|
protected ReferenceManager<IndexSearcher> |
mgr |
static String |
PRIMARY_GEN_KEY
Key to store the primary gen in the commit data, which increments every time we promote a new primary, so replicas can detect when the
primary they were talking to is changed
|
protected PrintStream |
printStream
For debug logging
|
protected SearcherFactory |
searcherFactory |
static String |
VERSION_KEY
Key to store the version in the commit data, which increments every time we open a new NRT reader
|
Constructor and Description |
---|
ReplicaNode(int id,
Directory dir,
SearcherFactory searcherFactory,
PrintStream printStream) |
Modifier and Type | Method and Description |
---|---|
static String |
bytesToString(long bytes) |
void |
close() |
void |
commit() |
IndexOutput |
createTempOutput(String prefix,
String suffix,
IOContext ioContext) |
void |
finishCopyFile(String name) |
long |
getCurrentSearchingVersion() |
List<Map.Entry<String,FileMetaData>> |
getFilesToCopy(Map<String,FileMetaData> files)
Compares incoming per-file identity (id, checksum, header, footer) versus what we have locally and returns the subset of the incoming
files that need copying
|
boolean |
isClosed() |
boolean |
isCopying() |
protected abstract void |
launch(CopyJob job)
Runs this job async'd
|
protected CopyJob |
launchPreCopyMerge(AtomicBoolean finished,
long newPrimaryGen,
Map<String,FileMetaData> files) |
protected void |
maybeNewPrimary(long newPrimaryGen)
Called when the primary changed
|
protected void |
message(String message) |
String |
name() |
protected abstract CopyJob |
newCopyJob(String reason,
Map<String,FileMetaData> files,
Map<String,FileMetaData> prevFiles,
boolean highPriority,
CopyJob.OnceDone onceDone)
Start a background copying job, to copy the specified files from the current primary node.
|
CopyJob |
newNRTPoint(long newPrimaryGen,
long version)
Call this to notify this replica node that a new NRT infos is available on the primary.
|
static void |
nodeMessage(PrintStream printStream,
int id,
String message) |
static void |
nodeMessage(PrintStream printStream,
String message) |
FileMetaData |
readLocalFileMetaData(String fileName)
Opens the specified file, reads its identifying information, including file length, full index header (includes the unique segment
ID) and the full footer (includes checksum), and returns the resulting
FileMetaData . |
protected abstract void |
sendNewReplica()
Tell primary we (replica) just started, so primary can tell us to warm any already warming merges.
|
protected void |
start(long curPrimaryGen)
Start up this replica, which possibly requires heavy copying of files from the primary node, if we were down for a long time
|
void |
startCopyFile(String name) |
String |
toString() |
protected final Collection<String> lastNRTFiles
protected CopyJob curNRTCopy
protected long lastPrimaryGen
public static String PRIMARY_GEN_KEY
public static String VERSION_KEY
protected final int id
protected final Directory dir
protected final SearcherFactory searcherFactory
protected ReferenceManager<IndexSearcher> mgr
public static long globalStartNS
public static final long localStartNS
protected final PrintStream printStream
protected volatile Map<String,FileMetaData> lastFileMetaData
public ReplicaNode(int id, Directory dir, SearcherFactory searcherFactory, PrintStream printStream) throws IOException
IOException
protected void start(long curPrimaryGen) throws IOException
IOException
public void commit() throws IOException
IOException
protected abstract CopyJob newCopyJob(String reason, Map<String,FileMetaData> files, Map<String,FileMetaData> prevFiles, boolean highPriority, CopyJob.OnceDone onceDone) throws IOException
IOException
protected abstract void launch(CopyJob job)
protected abstract void sendNewReplica() throws IOException
IOException
public CopyJob newNRTPoint(long newPrimaryGen, long version) throws IOException
IOException
public boolean isCopying()
public boolean isClosed()
public void close() throws IOException
IOException
protected void maybeNewPrimary(long newPrimaryGen) throws IOException
IOException
protected CopyJob launchPreCopyMerge(AtomicBoolean finished, long newPrimaryGen, Map<String,FileMetaData> files) throws IOException
IOException
public IndexOutput createTempOutput(String prefix, String suffix, IOContext ioContext) throws IOException
IOException
public List<Map.Entry<String,FileMetaData>> getFilesToCopy(Map<String,FileMetaData> files) throws IOException
IOException
public void startCopyFile(String name)
public void finishCopyFile(String name)
public static void nodeMessage(PrintStream printStream, String message)
public static void nodeMessage(PrintStream printStream, int id, String message)
protected void message(String message)
public String name()
public long getCurrentSearchingVersion() throws IOException
IOException
public static String bytesToString(long bytes)
public FileMetaData readLocalFileMetaData(String fileName) throws IOException
FileMetaData
.
This returns null, logging a message, if there are any problems (the file does not exist, is corrupt, truncated, etc.).
IOException
Copyright © 2000–2017 The Apache Software Foundation. All rights reserved.