Skip to content

Commit 557d924

Browse files
committed
Feedback
1 parent 4ab94ce commit 557d924

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

server/src/main/java/org/elasticsearch/index/shard/IndexShard.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,9 +1314,7 @@ public void close(String reason, boolean flushEngine) throws IOException {
13141314
}
13151315

13161316
public void preRecovery() {
1317-
if (state != IndexShardState.RECOVERING) {
1318-
throw new IndexShardNotRecoveringException(shardId, state);
1319-
}
1317+
assert state == IndexShardState.RECOVERING : "expected a recovering shard " + shardId + " but got " + state;
13201318
indexEventListener.beforeIndexShardRecovery(this, indexSettings);
13211319
}
13221320

server/src/main/java/org/elasticsearch/index/translog/Translog.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,6 +1843,23 @@ static String createEmptyTranslog(Path location, long initialGlobalCheckpoint, S
18431843
return createEmptyTranslog(location, shardId, initialGlobalCheckpoint, primaryTerm, null, channelFactory);
18441844
}
18451845

1846+
/**
1847+
* Creates a new empty translog within the specified {@code location} that contains the given {@code initialGlobalCheckpoint},
1848+
* {@code primaryTerm} and {@code translogUUID}.
1849+
*
1850+
* This method should be used directly under specific circumstances like for shards that will see no indexing. Specifying a non-unique
1851+
* translog UUID could cause a lot of issues and that's why in all (but one) cases the method
1852+
* {@link #createEmptyTranslog(Path, long, ShardId, long)} should be used instead.
1853+
*
1854+
* @param location a {@link Path} to the directory that will contains the translog files (translog + translog checkpoint)
1855+
* @param shardId the {@link ShardId}
1856+
* @param initialGlobalCheckpoint the global checkpoint to initialize the translog with
1857+
* @param primaryTerm the shard's primary term to initialize the translog with
1858+
* @param translogUUID the unique identifier to initialize the translog with
1859+
* @param factory a {@link ChannelFactory} used to open translog files
1860+
* @return the translog's unique identifier
1861+
* @throws IOException if something went wrong during translog creation
1862+
*/
18461863
public static String createEmptyTranslog(final Path location,
18471864
final ShardId shardId,
18481865
final long initialGlobalCheckpoint,

server/src/main/java/org/elasticsearch/indices/recovery/PeerRecoveryTargetService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ private void doRecovery(final long recoveryId) {
171171
final RecoveryTarget recoveryTarget = recoveryRef.target();
172172
timer = recoveryTarget.state().getTimer();
173173
cancellableThreads = recoveryTarget.cancellableThreads();
174-
final IndexShard indexShard = recoveryTarget.indexShard();
175174
try {
175+
final IndexShard indexShard = recoveryTarget.indexShard();
176176
indexShard.preRecovery();
177177
assert recoveryTarget.sourceNode() != null : "can not do a recovery without a source node";
178178
logger.trace("{} preparing shard for peer recovery", recoveryTarget.shardId());

0 commit comments

Comments
 (0)