Skip to content

Commit 44573ba

Browse files
authored
Moving RecoveryState.Index to a top-level class and renaming (#3075)
* Moving RecoveryState.Index to a top-level class and renaming This class is a building block of replication and will be re-used between peer recovery and segment replication. Thus, the inner class has been extracted to a top-level class and moved to the replication.common package. It has been renamed to ReplicationLuceneIndex to better reflect what it represents. It has two dependent inner classes from RecoveryState that have also been moved along with it - these remain inner classes since they are not currently used anywhere else. The RecoveryFilesDetails class has been renamed to FilesDetails and the FileDetail class has been renamed to FileMetadata. Signed-off-by: Kartik Ganesh <gkart@amazon.com> * Incorporate PR comments Signed-off-by: Kartik Ganesh <gkart@amazon.com> * Revert Project_Default.xml Signed-off-by: Kartik Ganesh <gkart@amazon.com> * Update REST Action test to no longer mock a final class Instead, the test now populates dummy data. Signed-off-by: Kartik Ganesh <gkart@amazon.com> * Removing mocking of ReplicationLuceneIndex in RecoverySourceHandlerTests The class has been marked final, so it can no longer be mocked. Instead, the test class sets up the lucene index class by adding the smae file metadata that is set up for the store. Signed-off-by: Kartik Ganesh <gkart@amazon.com> * Configure @opensearch.internal as custom Javadoc tag Signed-off-by: Kartik Ganesh <gkart@amazon.com> * Revert "Configure @opensearch.internal as custom Javadoc tag" This reverts commit 2077d76. Signed-off-by: Kartik Ganesh <gkart@amazon.com>
1 parent 6003921 commit 44573ba

File tree

14 files changed

+634
-559
lines changed

14 files changed

+634
-559
lines changed

server/src/internalClusterTest/java/org/opensearch/gateway/RecoveryFromGatewayIT.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import org.opensearch.index.shard.ShardPath;
6363
import org.opensearch.indices.IndicesService;
6464
import org.opensearch.indices.recovery.RecoveryState;
65+
import org.opensearch.indices.replication.common.ReplicationLuceneIndex;
6566
import org.opensearch.plugins.Plugin;
6667
import org.opensearch.test.OpenSearchIntegTestCase;
6768
import org.opensearch.test.OpenSearchIntegTestCase.ClusterScope;
@@ -547,7 +548,7 @@ public void testReuseInFileBasedPeerRecovery() throws Exception {
547548
final Set<String> files = new HashSet<>();
548549
for (final RecoveryState recoveryState : initialRecoveryReponse.shardRecoveryStates().get("test")) {
549550
if (recoveryState.getTargetNode().getName().equals(replicaNode)) {
550-
for (final RecoveryState.FileDetail file : recoveryState.getIndex().fileDetails()) {
551+
for (final ReplicationLuceneIndex.FileMetadata file : recoveryState.getIndex().fileDetails()) {
551552
files.add(file.name());
552553
}
553554
break;
@@ -607,7 +608,7 @@ public Settings onNodeStopped(String nodeName) throws Exception {
607608
long reused = 0;
608609
int filesRecovered = 0;
609610
int filesReused = 0;
610-
for (final RecoveryState.FileDetail file : recoveryState.getIndex().fileDetails()) {
611+
for (final ReplicationLuceneIndex.FileMetadata file : recoveryState.getIndex().fileDetails()) {
611612
if (files.contains(file.name()) == false) {
612613
recovered += file.length();
613614
filesRecovered++;

server/src/internalClusterTest/java/org/opensearch/indices/recovery/IndexRecoveryIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
import org.opensearch.indices.NodeIndicesStats;
103103
import org.opensearch.indices.analysis.AnalysisModule;
104104
import org.opensearch.indices.recovery.RecoveryState.Stage;
105+
import org.opensearch.indices.replication.common.ReplicationLuceneIndex;
105106
import org.opensearch.node.NodeClosedException;
106107
import org.opensearch.node.RecoverySettingsChunkSizePlugin;
107108
import org.opensearch.plugins.AnalysisPlugin;
@@ -836,7 +837,7 @@ private IndicesStatsResponse createAndPopulateIndex(String name, int nodeCount,
836837
return client().admin().indices().prepareStats(name).execute().actionGet();
837838
}
838839

839-
private void validateIndexRecoveryState(RecoveryState.Index indexState) {
840+
private void validateIndexRecoveryState(ReplicationLuceneIndex indexState) {
840841
assertThat(indexState.time(), greaterThanOrEqualTo(0L));
841842
assertThat(indexState.recoveredFilesPercent(), greaterThanOrEqualTo(0.0f));
842843
assertThat(indexState.recoveredFilesPercent(), lessThanOrEqualTo(100.0f));

server/src/main/java/org/opensearch/index/shard/StoreRecovery.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import org.opensearch.index.store.Store;
6363
import org.opensearch.index.translog.Translog;
6464
import org.opensearch.indices.recovery.RecoveryState;
65+
import org.opensearch.indices.replication.common.ReplicationLuceneIndex;
6566
import org.opensearch.repositories.IndexId;
6667
import org.opensearch.repositories.Repository;
6768

@@ -176,7 +177,7 @@ void recoverFromLocalShards(
176177
}
177178

178179
void addIndices(
179-
final RecoveryState.Index indexRecoveryStats,
180+
final ReplicationLuceneIndex indexRecoveryStats,
180181
final Directory target,
181182
final Sort indexSort,
182183
final Directory[] sources,
@@ -231,9 +232,9 @@ void addIndices(
231232
* Directory wrapper that records copy process for recovery statistics
232233
*/
233234
static final class StatsDirectoryWrapper extends FilterDirectory {
234-
private final RecoveryState.Index index;
235+
private final ReplicationLuceneIndex index;
235236

236-
StatsDirectoryWrapper(Directory in, RecoveryState.Index indexRecoveryStats) {
237+
StatsDirectoryWrapper(Directory in, ReplicationLuceneIndex indexRecoveryStats) {
237238
super(in);
238239
this.index = indexRecoveryStats;
239240
}
@@ -354,7 +355,7 @@ private ActionListener<Boolean> recoveryListener(IndexShard indexShard, ActionLi
354355
+ "]";
355356

356357
if (logger.isTraceEnabled()) {
357-
RecoveryState.Index index = recoveryState.getIndex();
358+
ReplicationLuceneIndex index = recoveryState.getIndex();
358359
StringBuilder sb = new StringBuilder();
359360
sb.append(" index : files [")
360361
.append(index.totalFileCount())
@@ -471,7 +472,7 @@ private void internalRecoverFromStore(IndexShard indexShard) throws IndexShardRe
471472
writeEmptyRetentionLeasesFile(indexShard);
472473
}
473474
// since we recover from local, just fill the files and size
474-
final RecoveryState.Index index = recoveryState.getIndex();
475+
final ReplicationLuceneIndex index = recoveryState.getIndex();
475476
try {
476477
if (si != null) {
477478
addRecoveredFileDetails(si, store, index);
@@ -509,7 +510,7 @@ private static void writeEmptyRetentionLeasesFile(IndexShard indexShard) throws
509510
assert indexShard.loadRetentionLeases().leases().isEmpty();
510511
}
511512

512-
private void addRecoveredFileDetails(SegmentInfos si, Store store, RecoveryState.Index index) throws IOException {
513+
private void addRecoveredFileDetails(SegmentInfos si, Store store, ReplicationLuceneIndex index) throws IOException {
513514
final Directory directory = store.directory();
514515
for (String name : Lucene.files(si)) {
515516
long length = directory.fileLength(name);

server/src/main/java/org/opensearch/indices/recovery/MultiFileWriter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.opensearch.common.util.concurrent.ConcurrentCollections;
4545
import org.opensearch.index.store.Store;
4646
import org.opensearch.index.store.StoreFileMetadata;
47+
import org.opensearch.indices.replication.common.ReplicationLuceneIndex;
4748
import org.opensearch.transport.Transports;
4849

4950
import java.io.IOException;
@@ -58,7 +59,7 @@
5859

5960
public class MultiFileWriter extends AbstractRefCounted implements Releasable {
6061

61-
public MultiFileWriter(Store store, RecoveryState.Index indexState, String tempFilePrefix, Logger logger, Runnable ensureOpen) {
62+
public MultiFileWriter(Store store, ReplicationLuceneIndex indexState, String tempFilePrefix, Logger logger, Runnable ensureOpen) {
6263
super("multi_file_writer");
6364
this.store = store;
6465
this.indexState = indexState;
@@ -71,7 +72,7 @@ public MultiFileWriter(Store store, RecoveryState.Index indexState, String tempF
7172
private final AtomicBoolean closed = new AtomicBoolean(false);
7273
private final Logger logger;
7374
private final Store store;
74-
private final RecoveryState.Index indexState;
75+
private final ReplicationLuceneIndex indexState;
7576
private final String tempFilePrefix;
7677

7778
private final ConcurrentMap<String, IndexOutput> openIndexOutputs = ConcurrentCollections.newConcurrentMap();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import org.opensearch.index.translog.Translog;
7171
import org.opensearch.index.translog.TranslogCorruptedException;
7272
import org.opensearch.indices.recovery.RecoveriesCollection.RecoveryRef;
73+
import org.opensearch.indices.replication.common.ReplicationLuceneIndex;
7374
import org.opensearch.indices.replication.common.ReplicationTimer;
7475
import org.opensearch.tasks.Task;
7576
import org.opensearch.threadpool.ThreadPool;
@@ -521,8 +522,8 @@ public void messageReceived(final RecoveryFileChunkRequest request, TransportCha
521522
return;
522523
}
523524

524-
final RecoveryState.Index indexState = recoveryTarget.state().getIndex();
525-
if (request.sourceThrottleTimeInNanos() != RecoveryState.Index.UNKNOWN) {
525+
final ReplicationLuceneIndex indexState = recoveryTarget.state().getIndex();
526+
if (request.sourceThrottleTimeInNanos() != ReplicationLuceneIndex.UNKNOWN) {
526527
indexState.addSourceThrottling(request.sourceThrottleTimeInNanos());
527528
}
528529

0 commit comments

Comments
 (0)