Skip to content

Commit

Permalink
PR comments and fixing clone IT
Browse files Browse the repository at this point in the history
Signed-off-by: Gaurav Bafna <gbbafna@amazon.com>
  • Loading branch information
gbbafna committed Oct 27, 2023
1 parent b422212 commit b987c55
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.opensearch.common.settings.Settings;
import org.opensearch.core.xcontent.MediaTypeRegistry;
import org.opensearch.index.query.TermsQueryBuilder;
import org.opensearch.index.seqno.SeqNoStats;
import org.opensearch.remotestore.RemoteStoreBaseIntegTestCase;
import org.opensearch.test.VersionUtils;

Expand Down Expand Up @@ -91,44 +90,22 @@ public void testCreateCloneIndex() {
.setTransientSettings(Settings.builder().put(EnableAllocationDecider.CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.getKey(), "none"))
.get();
try {

final boolean createWithReplicas = randomBoolean();
assertAcked(
client().admin()
.indices()
.prepareResizeIndex("source", "target")
.setResizeType(ResizeType.CLONE)
.setSettings(
Settings.builder().put("index.number_of_replicas", createWithReplicas ? 1 : 0).putNull("index.blocks.write").build()
)
.setSettings(Settings.builder().put("index.number_of_replicas", 0).putNull("index.blocks.write").build())
.get()
);
ensureGreen();

final IndicesStatsResponse targetStats = client().admin().indices().prepareStats("target").get();
assertThat(targetStats.getIndex("target").getIndexShards().keySet().size(), equalTo(numPrimaryShards));

for (int i = 0; i < numPrimaryShards; i++) {
final SeqNoStats sourceSeqNoStats = sourceStats.getIndex("source").getIndexShards().get(i).getAt(0).getSeqNoStats();
final SeqNoStats targetSeqNoStats = targetStats.getIndex("target").getIndexShards().get(i).getAt(0).getSeqNoStats();
assertEquals(sourceSeqNoStats.getMaxSeqNo(), targetSeqNoStats.getMaxSeqNo());
assertEquals(targetSeqNoStats.getMaxSeqNo(), targetSeqNoStats.getLocalCheckpoint());
}

final int size = docs > 0 ? 2 * docs : 1;
assertHitCount(client().prepareSearch("target").setSize(size).setQuery(new TermsQueryBuilder("foo", "bar")).get(), docs);

if (createWithReplicas == false) {
// bump replicas
client().admin()
.indices()
.prepareUpdateSettings("target")
.setSettings(Settings.builder().put("index.number_of_replicas", 1))
.get();
ensureGreen();
assertHitCount(client().prepareSearch("target").setSize(size).setQuery(new TermsQueryBuilder("foo", "bar")).get(), docs);
}

for (int i = docs; i < 2 * docs; i++) {
client().prepareIndex("target").setSource("{\"foo\" : \"bar\", \"i\" : " + i + "}", MediaTypeRegistry.JSON).get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1998,10 +1998,10 @@ private RemoteSegmentStoreDirectory getRemoteDirectory() {
}

/**
Returns true iff it is able to verify that there is at least one
remote segment metadata uploaded
Returns true iff it is able to verify that remote segment store
is in sync with local
*/
boolean isRemoteSync() {
boolean isRemoteSegmentStoreInSync() {
assert indexSettings.isRemoteStoreEnabled();
try {
RemoteSegmentStoreDirectory directory = getRemoteDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void recoverFromLocalShards(
// copied segments - we will also see them in stats etc.
indexShard.getEngine().forceMerge(false, -1, false, false, false, UUIDs.randomBase64UUID());
if (indexShard.isRemoteTranslogEnabled()) {
if (indexShard.isRemoteSync() == false) {
if (indexShard.isRemoteSegmentStoreInSync() == false) {
throw new IndexShardRecoveryException(
indexShard.shardId(),
"failed to upload to remote",
Expand Down Expand Up @@ -428,7 +428,7 @@ void recoverFromSnapshotAndRemoteStore(
indexShard.getEngine().fillSeqNoGaps(indexShard.getPendingPrimaryTerm());
indexShard.finalizeRecovery();
if (indexShard.isRemoteTranslogEnabled()) {
if (indexShard.isRemoteSync() == false) {
if (indexShard.isRemoteSegmentStoreInSync() == false) {
listener.onFailure(new IndexShardRestoreFailedException(shardId, "Failed to upload to remote segment store"));
return;
}
Expand Down Expand Up @@ -713,7 +713,7 @@ private void restore(
indexShard.getEngine().fillSeqNoGaps(indexShard.getPendingPrimaryTerm());
indexShard.finalizeRecovery();
if (indexShard.isRemoteTranslogEnabled()) {
if (indexShard.isRemoteSync() == false) {
if (indexShard.isRemoteSegmentStoreInSync() == false) {
listener.onFailure(new IndexShardRestoreFailedException(shardId, "Failed to upload to remote segment store"));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2850,7 +2850,7 @@ public void testSyncSegmentsFromGivenRemoteSegmentStore() throws IOException {
indexDoc(source, "_doc", "1");
indexDoc(source, "_doc", "2");
source.refresh("test");
assertTrue("At lease one remote sync should have been completed", source.isRemoteSync());
assertTrue("At lease one remote sync should have been completed", source.isRemoteSegmentStoreInSync());
assertDocs(source, "1", "2");
indexDoc(source, "_doc", "3");
source.refresh("test");
Expand Down

0 comments on commit b987c55

Please sign in to comment.