public class RecoveryTarget extends AbstractRefCounted implements RecoveryTargetHandler
RecoveriesCollection
.Constructor and Description |
---|
RecoveryTarget(IndexShard indexShard,
DiscoveryNode sourceNode,
PeerRecoveryTargetService.RecoveryListener listener,
java.util.function.LongConsumer ensureClusterStateVersionCallback)
Creates a new recovery target object that represents a recovery to the provided shard.
|
Modifier and Type | Method and Description |
---|---|
void |
cancel(java.lang.String reason)
cancel the recovery.
|
CancellableThreads |
cancellableThreads() |
void |
cleanFiles(int totalTranslogOps,
Store.MetadataSnapshot sourceMetaData)
After all source files has been sent over, this command is sent to the target so it can clean any local
files that are not part of the source store
|
protected void |
closeInternal() |
void |
ensureClusterStateVersion(long clusterStateVersion)
Blockingly waits for cluster state with at least clusterStateVersion to be available
|
void |
fail(RecoveryFailedException e,
boolean sendShardFailure)
fail the recovery and call listener
|
void |
finalizeRecovery(long globalCheckpoint)
The finalize request refreshes the engine now that new segments are available, enables garbage collection of tombstone files, and
updates the global checkpoint.
|
org.apache.lucene.store.IndexOutput |
getOpenIndexOutput(java.lang.String key) |
java.lang.String |
getTempNameForFile(java.lang.String origFile)
Get a temporary name for the provided file name.
|
void |
handoffPrimaryContext(GlobalCheckpointTracker.PrimaryContext primaryContext)
Handoff the primary context between the relocation source and the relocation target.
|
IndexShard |
indexShard() |
long |
indexTranslogOperations(java.util.List<Translog.Operation> operations,
int totalTranslogOps)
Index a set of translog operations on the target
|
long |
lastAccessTime()
return the last time this RecoveryStatus was used (based on System.nanoTime()
|
void |
markAsDone()
mark the current recovery as done
|
void |
notifyListener(RecoveryFailedException e,
boolean sendShardFailure) |
org.apache.lucene.store.IndexOutput |
openAndPutIndexOutput(java.lang.String fileName,
StoreFileMetaData metaData,
Store store)
Creates an
IndexOutput for the given file name. |
void |
prepareForTranslogOperations(int totalTranslogOps)
Implementation of
RecoveryTargetHandler |
void |
receiveFileInfo(java.util.List<java.lang.String> phase1FileNames,
java.util.List<java.lang.Long> phase1FileSizes,
java.util.List<java.lang.String> phase1ExistingFileNames,
java.util.List<java.lang.Long> phase1ExistingFileSizes,
int totalTranslogOps)
Notifies the target of the files it is going to receive
|
long |
recoveryId() |
org.apache.lucene.store.IndexOutput |
removeOpenIndexOutputs(java.lang.String name)
remove and
IndexOutput for a given file. |
void |
renameAllTempFiles()
renames all temporary files to their true name, potentially overriding existing files
|
RecoveryTarget |
retryCopy()
Returns a fresh recovery target to retry recovery from the same source node onto the same shard and using the same listener.
|
void |
setLastAccessTime()
sets the lasAccessTime flag to now
|
ShardId |
shardId() |
DiscoveryNode |
sourceNode() |
RecoveryState.Stage |
stage() |
RecoveryState |
state() |
Store |
store() |
java.lang.String |
toString() |
void |
writeFileChunk(StoreFileMetaData fileMetaData,
long position,
BytesReference content,
boolean lastChunk,
int totalTranslogOps)
writes a partial file chunk to the target store
|
alreadyClosed, decRef, getName, incRef, refCount, tryIncRef
public RecoveryTarget(IndexShard indexShard, DiscoveryNode sourceNode, PeerRecoveryTargetService.RecoveryListener listener, java.util.function.LongConsumer ensureClusterStateVersionCallback)
indexShard
- local shard where we want to recover tosourceNode
- source node of the recovery where we recover fromlistener
- called when recovery is completed/failedensureClusterStateVersionCallback
- callback to ensure that the current node is at least on a cluster state with the provided
version; necessary for primary relocation so that new primary knows about all other ongoing
replica recoveries when replicating documents (see RecoverySourceHandler
)public RecoveryTarget retryCopy()
public long recoveryId()
public ShardId shardId()
public IndexShard indexShard()
public DiscoveryNode sourceNode()
public RecoveryState state()
public CancellableThreads cancellableThreads()
public long lastAccessTime()
public void setLastAccessTime()
public Store store()
public RecoveryState.Stage stage()
public void renameAllTempFiles() throws java.io.IOException
java.io.IOException
public void cancel(java.lang.String reason)
AbstractRefCounted.decRef()
if cancellableThreads()
was used, the threads will be interrupted.
public void fail(RecoveryFailedException e, boolean sendShardFailure)
e
- exception that encapsulating the failuresendShardFailure
- indicates whether to notify the master of the shard failurepublic void notifyListener(RecoveryFailedException e, boolean sendShardFailure)
public void markAsDone()
public java.lang.String getTempNameForFile(java.lang.String origFile)
public org.apache.lucene.store.IndexOutput getOpenIndexOutput(java.lang.String key)
public org.apache.lucene.store.IndexOutput removeOpenIndexOutputs(java.lang.String name)
IndexOutput
for a given file. It is the caller's responsibility to close itpublic org.apache.lucene.store.IndexOutput openAndPutIndexOutput(java.lang.String fileName, StoreFileMetaData metaData, Store store) throws java.io.IOException
IndexOutput
for the given file name. Note that the
IndexOutput actually point at a temporary file.
Note: You can use getOpenIndexOutput(String)
with the same filename to retrieve the same IndexOutput
at a later stage
java.io.IOException
protected void closeInternal()
closeInternal
in class AbstractRefCounted
public java.lang.String toString()
toString
in class java.lang.Object
public void prepareForTranslogOperations(int totalTranslogOps) throws java.io.IOException
RecoveryTargetHandler
prepareForTranslogOperations
in interface RecoveryTargetHandler
totalTranslogOps
- total translog operations expected to be sentjava.io.IOException
public void finalizeRecovery(long globalCheckpoint)
RecoveryTargetHandler
finalizeRecovery
in interface RecoveryTargetHandler
globalCheckpoint
- the global checkpoint on the recovery sourcepublic void ensureClusterStateVersion(long clusterStateVersion)
RecoveryTargetHandler
ensureClusterStateVersion
in interface RecoveryTargetHandler
public void handoffPrimaryContext(GlobalCheckpointTracker.PrimaryContext primaryContext)
RecoveryTargetHandler
handoffPrimaryContext
in interface RecoveryTargetHandler
primaryContext
- the primary context from the relocation sourcepublic long indexTranslogOperations(java.util.List<Translog.Operation> operations, int totalTranslogOps) throws java.io.IOException
RecoveryTargetHandler
indexTranslogOperations
in interface RecoveryTargetHandler
operations
- operations to indextotalTranslogOps
- current number of total operations expected to be indexedjava.io.IOException
public void receiveFileInfo(java.util.List<java.lang.String> phase1FileNames, java.util.List<java.lang.Long> phase1FileSizes, java.util.List<java.lang.String> phase1ExistingFileNames, java.util.List<java.lang.Long> phase1ExistingFileSizes, int totalTranslogOps)
RecoveryTargetHandler
receiveFileInfo
in interface RecoveryTargetHandler
public void cleanFiles(int totalTranslogOps, Store.MetadataSnapshot sourceMetaData) throws java.io.IOException
RecoveryTargetHandler
cleanFiles
in interface RecoveryTargetHandler
totalTranslogOps
- an update number of translog operations that will be replayed later onsourceMetaData
- meta data of the source storejava.io.IOException
public void writeFileChunk(StoreFileMetaData fileMetaData, long position, BytesReference content, boolean lastChunk, int totalTranslogOps) throws java.io.IOException
RecoveryTargetHandler
writeFileChunk
in interface RecoveryTargetHandler
java.io.IOException