Skip to content

Commit

Permalink
Change to forceAllocate
Browse files Browse the repository at this point in the history
Signed-off-by: Sachin Kale <[email protected]>
  • Loading branch information
Sachin Kale committed Oct 24, 2023
1 parent ffee1a7 commit 2e3fbfd
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount;
import static org.hamcrest.Matchers.greaterThan;

@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.SUITE, numDataNodes = 0)
@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0)
public class RemoteStoreRestoreIT extends BaseRemoteStoreRestoreIT {

/**
Expand Down Expand Up @@ -236,7 +236,7 @@ public void testRestoreFlowNoRedIndex() throws Exception {
verifyRestoredData(indexStats, INDEX_NAME);
}

public void testRestoreFlowWithForceEmptyTranslogNoOp() throws Exception {
public void testRestoreFlowWithForceAllocateNoOp() throws Exception {
prepareCluster(1, 3, INDEX_NAME, 0, 1);
Map<String, Long> indexStats = indexData(randomIntBetween(2, 3), randomBoolean(), INDEX_NAME);

Expand All @@ -252,7 +252,7 @@ public void testRestoreFlowWithForceEmptyTranslogNoOp() throws Exception {
client().admin()
.cluster()
.restoreRemoteStore(
new RestoreRemoteStoreRequest().indices(INDEX_NAME).restoreAllShards(true).forceEmptyTranslog(true),
new RestoreRemoteStoreRequest().indices(INDEX_NAME).restoreAllShards(true).forceAllocate(true),
PlainActionFuture.newFuture()
);
ensureGreen(INDEX_NAME);
Expand All @@ -267,7 +267,7 @@ public void testRestoreFlowWithForceEmptyTranslogNoOp() throws Exception {
);
}

public void testRestoreFlowWithForceEmptyTranslog() throws Exception {
public void testRestoreFlowWithForceAllocate() throws Exception {
prepareCluster(1, 3, INDEX_NAME, 0, 1);
Map<String, Long> indexStats = indexData(randomIntBetween(2, 3), randomBoolean(), INDEX_NAME);

Expand All @@ -292,7 +292,7 @@ public void testRestoreFlowWithForceEmptyTranslog() throws Exception {
client().admin()
.cluster()
.restoreRemoteStore(
new RestoreRemoteStoreRequest().indices(INDEX_NAME).restoreAllShards(true).forceEmptyTranslog(true),
new RestoreRemoteStoreRequest().indices(INDEX_NAME).restoreAllShards(true).forceAllocate(true),
PlainActionFuture.newFuture()
);
ensureGreen(INDEX_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class RestoreRemoteStoreRequest extends ClusterManagerNodeRequest<Restore
private String[] indices = Strings.EMPTY_ARRAY;
private Boolean waitForCompletion = false;
private Boolean restoreAllShards = false;
private Boolean forceEmptyTranslog = false;
private Boolean forceAllocate = false;

public RestoreRemoteStoreRequest() {}

Expand All @@ -48,7 +48,7 @@ public RestoreRemoteStoreRequest(StreamInput in) throws IOException {
waitForCompletion = in.readOptionalBoolean();
restoreAllShards = in.readOptionalBoolean();
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
forceEmptyTranslog = in.readOptionalBoolean();
forceAllocate = in.readOptionalBoolean();
}
}

Expand All @@ -59,7 +59,7 @@ public void writeTo(StreamOutput out) throws IOException {
out.writeOptionalBoolean(waitForCompletion);
out.writeOptionalBoolean(restoreAllShards);
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
out.writeOptionalBoolean(forceEmptyTranslog);
out.writeOptionalBoolean(forceAllocate);
}
}

Expand Down Expand Up @@ -151,24 +151,24 @@ public boolean restoreAllShards() {
}

/**
* Set the value for forceEmptyTranslog, denoting whether to create empty translog if remote translog does not have any data.
* Set the value for forceAllocate, denoting whether to create empty store/translog if remote segment store/translog does not have any data.
*
* @param forceEmptyTranslog If true and if remote translog does not have any data, the operation will create empty translog on local
* If false, the operation will always try to fetch data from remote translog and will fail if remote translog is empty.
* @param forceAllocate If true and if remote segment store/translog does not have any data, the operation will create empty store/translog on local
* If false, the operation will always try to fetch data from remote segment store/translog and will fail if either one is empty.
* @return this request
*/
public RestoreRemoteStoreRequest forceEmptyTranslog(boolean forceEmptyTranslog) {
this.forceEmptyTranslog = forceEmptyTranslog;
public RestoreRemoteStoreRequest forceAllocate(boolean forceAllocate) {
this.forceAllocate = forceAllocate;
return this;

Check warning on line 162 in server/src/main/java/org/opensearch/action/admin/cluster/remotestore/restore/RestoreRemoteStoreRequest.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/remotestore/restore/RestoreRemoteStoreRequest.java#L161-L162

Added lines #L161 - L162 were not covered by tests
}

/**
* Returns forceEmptyTranslog setting
* Returns forceAllocate setting
*
* @return true if the operation will create empty translog on local when remote translog is empty
* @return true if the operation will create empty store/translog on local when remote segment store/translog is empty
*/
public boolean forceEmptyTranslog() {
return forceEmptyTranslog;
public boolean forceAllocate() {
return forceAllocate;

Check warning on line 171 in server/src/main/java/org/opensearch/action/admin/cluster/remotestore/restore/RestoreRemoteStoreRequest.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/action/admin/cluster/remotestore/restore/RestoreRemoteStoreRequest.java#L171

Added line #L171 was not covered by tests
}

/**
Expand Down Expand Up @@ -222,13 +222,13 @@ public boolean equals(Object o) {
RestoreRemoteStoreRequest that = (RestoreRemoteStoreRequest) o;
return waitForCompletion == that.waitForCompletion
&& restoreAllShards == that.restoreAllShards
&& forceEmptyTranslog == that.forceEmptyTranslog
&& forceAllocate == that.forceAllocate
&& Arrays.equals(indices, that.indices);
}

@Override
public int hashCode() {
int result = Objects.hash(waitForCompletion, restoreAllShards, forceEmptyTranslog);
int result = Objects.hash(waitForCompletion, restoreAllShards, forceAllocate);
result = 31 * result + Arrays.hashCode(indices);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,27 +419,27 @@ public static class RemoteStoreRecoverySource extends RecoverySource {
private final String restoreUUID;
private final IndexId index;
private final Version version;
private final boolean forceEmptyTranslog;
private final boolean forceAllocate;

public RemoteStoreRecoverySource(String restoreUUID, Version version, IndexId indexId) {
this(restoreUUID, version, indexId, false);
}

public RemoteStoreRecoverySource(String restoreUUID, Version version, IndexId indexId, boolean forceEmptyTranslog) {
public RemoteStoreRecoverySource(String restoreUUID, Version version, IndexId indexId, boolean forceAllocate) {
this.restoreUUID = restoreUUID;
this.version = Objects.requireNonNull(version);
this.index = Objects.requireNonNull(indexId);
this.forceEmptyTranslog = forceEmptyTranslog;
this.forceAllocate = forceAllocate;
}

RemoteStoreRecoverySource(StreamInput in) throws IOException {
restoreUUID = in.readString();
version = in.readVersion();
index = new IndexId(in);
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
forceEmptyTranslog = in.readBoolean();
forceAllocate = in.readBoolean();
} else {
forceEmptyTranslog = false;
forceAllocate = false;

Check warning on line 442 in server/src/main/java/org/opensearch/cluster/routing/RecoverySource.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/routing/RecoverySource.java#L442

Added line #L442 was not covered by tests
}
}

Expand All @@ -461,8 +461,8 @@ public Version version() {
return version;
}

public boolean forceEmptyTranslog() {
return forceEmptyTranslog;
public boolean forceAllocate() {
return forceAllocate;

Check warning on line 465 in server/src/main/java/org/opensearch/cluster/routing/RecoverySource.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/routing/RecoverySource.java#L465

Added line #L465 was not covered by tests
}

@Override
Expand All @@ -471,7 +471,7 @@ protected void writeAdditionalFields(StreamOutput out) throws IOException {
out.writeVersion(version);
index.writeTo(out);
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
out.writeBoolean(forceEmptyTranslog);
out.writeBoolean(forceAllocate);
}
}

Expand All @@ -485,7 +485,7 @@ public void addAdditionalFields(XContentBuilder builder, ToXContent.Params param
builder.field("version", version.toString())
.field("index", index.getName())
.field("restoreUUID", restoreUUID)
.field("forceEmptyTranslog", forceEmptyTranslog);
.field("forceAllocate", forceAllocate);

Check warning on line 488 in server/src/main/java/org/opensearch/cluster/routing/RecoverySource.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/routing/RecoverySource.java#L485-L488

Added lines #L485 - L488 were not covered by tests
}

@Override
Expand All @@ -506,12 +506,12 @@ public boolean equals(Object o) {
return restoreUUID.equals(that.restoreUUID)
&& index.equals(that.index)
&& version.equals(that.version)
&& forceEmptyTranslog == that.forceEmptyTranslog;
&& forceAllocate == that.forceAllocate;
}

@Override
public int hashCode() {
return Objects.hash(restoreUUID, index, version, forceEmptyTranslog);
return Objects.hash(restoreUUID, index, version, forceAllocate);

Check warning on line 514 in server/src/main/java/org/opensearch/cluster/routing/RecoverySource.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/cluster/routing/RecoverySource.java#L514

Added line #L514 was not covered by tests
}

// TODO: This override should be removed/be updated to return "true",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public ClusterState execute(ClusterState currentState) {
currentState,
null,
request.restoreAllShards(),
request.forceEmptyTranslog(),
request.forceAllocate(),
request.indices()

Check warning on line 107 in server/src/main/java/org/opensearch/index/recovery/RemoteStoreRestoreService.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/recovery/RemoteStoreRestoreService.java#L105-L107

Added lines #L105 - L107 were not covered by tests
);
restoreUUID = remoteRestoreResult.getRestoreUUID();
Expand Down Expand Up @@ -141,7 +141,7 @@ public RemoteRestoreResult restore(
ClusterState currentState,
@Nullable String restoreClusterUUID,
boolean restoreAllShards,
boolean forceEmptyTranslog,
boolean forceAllocate,
String[] indexNames
) {
Map<String, Tuple<Boolean, IndexMetadata>> indexMetadataMap = new HashMap<>();
Expand Down Expand Up @@ -183,7 +183,7 @@ public RemoteRestoreResult restore(
}
}
}
return executeRestore(currentState, indexMetadataMap, restoreAllShards, remoteMetadata, forceEmptyTranslog);
return executeRestore(currentState, indexMetadataMap, restoreAllShards, remoteMetadata, forceAllocate);

Check warning on line 186 in server/src/main/java/org/opensearch/index/recovery/RemoteStoreRestoreService.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/index/recovery/RemoteStoreRestoreService.java#L186

Added line #L186 was not covered by tests
}

/**
Expand All @@ -198,7 +198,7 @@ private RemoteRestoreResult executeRestore(
Map<String, Tuple<Boolean, IndexMetadata>> indexMetadataMap,
boolean restoreAllShards,
Metadata remoteMetadata,
boolean forceEmptyTranslog
boolean forceAllocate
) {
final String restoreUUID = UUIDs.randomBase64UUID();
List<String> indicesToBeRestored = new ArrayList<>();
Expand Down Expand Up @@ -237,7 +237,7 @@ private RemoteRestoreResult executeRestore(
restoreUUID,
updatedIndexMetadata.getCreationVersion(),
indexId,
forceEmptyTranslog
forceAllocate
);

rtBuilder.addAsRemoteStoreRestore(updatedIndexMetadata, recoverySource, indexShardRoutingTableMap, restoreAllShards);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ private void recoverFromRemoteStore(IndexShard indexShard) throws IndexShardReco
store.createEmpty(indexShard.indexSettings().getIndexVersionCreated().luceneVersion, translogHeader.getTranslogUUID());
}
} else if (remoteSegmentEmpty == false && remoteTranslogEmpty) {
if (((RecoverySource.RemoteStoreRecoverySource) indexShard.shardRouting.recoverySource()).forceEmptyTranslog()) {
if (((RecoverySource.RemoteStoreRecoverySource) indexShard.shardRouting.recoverySource()).forceAllocate()) {
bootstrapFromLastCommit(indexShard, store);

Check warning on line 558 in server/src/main/java/org/opensearch/index/shard/StoreRecovery.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L558 was not covered by tests
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
);
restoreRemoteStoreRequest.waitForCompletion(request.paramAsBoolean("wait_for_completion", false));
restoreRemoteStoreRequest.restoreAllShards(request.paramAsBoolean("restore_all_shards", false));
restoreRemoteStoreRequest.forceEmptyTranslog(request.paramAsBoolean("force_empty_translog", false));
restoreRemoteStoreRequest.forceAllocate(request.paramAsBoolean("force_allocate", false));

Check warning on line 48 in server/src/main/java/org/opensearch/rest/action/admin/cluster/RestRestoreRemoteStoreAction.java

View check run for this annotation

Codecov / codecov/patch

server/src/main/java/org/opensearch/rest/action/admin/cluster/RestRestoreRemoteStoreAction.java#L48

Added line #L48 was not covered by tests
request.applyContentParser(p -> restoreRemoteStoreRequest.source(p.mapOrdered()));
return channel -> client.admin().cluster().restoreRemoteStore(restoreRemoteStoreRequest, new RestToXContentListener<>(channel));
}
Expand Down

0 comments on commit 2e3fbfd

Please sign in to comment.