Skip to content

Commit f2eff60

Browse files
author
Harish Bhakuni
committed
Address PR Comments
Signed-off-by: Harish Bhakuni <hbhakuni@amazon.com>
1 parent c98b8ac commit f2eff60

File tree

5 files changed

+118
-20
lines changed

5 files changed

+118
-20
lines changed

server/src/main/java/org/opensearch/index/snapshots/blobstore/RemoteStoreShardShallowCopySnapshot.java

Lines changed: 97 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import java.io.IOException;
1818
import java.util.ArrayList;
1919
import java.util.List;
20-
import java.util.Objects;
2120

2221
/**
2322
* Remote Store based Shard snapshot metadata
@@ -40,7 +39,7 @@ public class RemoteStoreShardShallowCopySnapshot implements ToXContentFragment {
4039
private final String indexUUID;
4140
private final List<String> fileNames;
4241

43-
private static final String DEFAULT_VERSION = "1";
42+
static final String DEFAULT_VERSION = "1";
4443
static final String NAME = "name";
4544
static final String VERSION = "version";
4645
static final String INDEX_VERSION = "index_version";
@@ -116,22 +115,69 @@ public RemoteStoreShardShallowCopySnapshot(
116115
String repositoryBasePath,
117116
List<String> fileNames
118117
) {
119-
this.snapshot = Objects.requireNonNull(snapshot, "Invalid/Missing Snapshot Name");
120-
assert indexVersion > 0 : "Invalid Index Version";
121-
assert primaryTerm > 0 : "Invalid Primary Term";
122-
assert commitGeneration > 0 : "Invalid Commit Generation";
118+
this.version = DEFAULT_VERSION;
119+
verifyParameters(
120+
version,
121+
snapshot,
122+
indexVersion,
123+
primaryTerm,
124+
commitGeneration,
125+
indexUUID,
126+
remoteStoreRepository,
127+
repositoryBasePath
128+
);
129+
this.snapshot = snapshot;
123130
this.indexVersion = indexVersion;
124131
this.primaryTerm = primaryTerm;
125132
this.commitGeneration = commitGeneration;
126133
this.startTime = startTime;
127134
this.time = time;
128135
this.totalFileCount = totalFileCount;
129136
this.totalSize = totalSize;
130-
this.indexUUID = Objects.requireNonNull(indexUUID, "Invalid/Missing Index UUID");
131-
this.remoteStoreRepository = Objects.requireNonNull(remoteStoreRepository, "Invalid/Missing Remote Store Repository");
132-
this.repositoryBasePath = Objects.requireNonNull(repositoryBasePath, "Invalid/Missing Repository Base Path");
137+
this.indexUUID = indexUUID;
138+
this.remoteStoreRepository = remoteStoreRepository;
139+
this.repositoryBasePath = repositoryBasePath;
140+
this.fileNames = fileNames;
141+
}
142+
143+
private RemoteStoreShardShallowCopySnapshot(
144+
String version,
145+
String snapshot,
146+
long indexVersion,
147+
long primaryTerm,
148+
long commitGeneration,
149+
long startTime,
150+
long time,
151+
int totalFileCount,
152+
long totalSize,
153+
String indexUUID,
154+
String remoteStoreRepository,
155+
String repositoryBasePath,
156+
List<String> fileNames
157+
) {
158+
verifyParameters(
159+
version,
160+
snapshot,
161+
indexVersion,
162+
primaryTerm,
163+
commitGeneration,
164+
indexUUID,
165+
remoteStoreRepository,
166+
repositoryBasePath
167+
);
168+
this.version = version;
169+
this.snapshot = snapshot;
170+
this.indexVersion = indexVersion;
171+
this.primaryTerm = primaryTerm;
172+
this.commitGeneration = commitGeneration;
173+
this.startTime = startTime;
174+
this.time = time;
175+
this.totalFileCount = totalFileCount;
176+
this.totalSize = totalSize;
177+
this.indexUUID = indexUUID;
178+
this.remoteStoreRepository = remoteStoreRepository;
179+
this.repositoryBasePath = repositoryBasePath;
133180
this.fileNames = fileNames;
134-
this.version = DEFAULT_VERSION;
135181
}
136182

137183
/**
@@ -142,7 +188,7 @@ public RemoteStoreShardShallowCopySnapshot(
142188
*/
143189
public static RemoteStoreShardShallowCopySnapshot fromXContent(XContentParser parser) throws IOException {
144190
String snapshot = null;
145-
String version = DEFAULT_VERSION;
191+
String version = null;
146192
long indexVersion = -1;
147193
long startTime = 0;
148194
long time = 0;
@@ -205,6 +251,7 @@ public static RemoteStoreShardShallowCopySnapshot fromXContent(XContentParser pa
205251
}
206252

207253
return new RemoteStoreShardShallowCopySnapshot(
254+
version,
208255
snapshot,
209256
indexVersion,
210257
primaryTerm,
@@ -308,4 +355,43 @@ public long totalSize() {
308355
return totalSize;
309356
}
310357

358+
private void verifyParameters(
359+
String version,
360+
String snapshot,
361+
long indexVersion,
362+
long primaryTerm,
363+
long commitGeneration,
364+
String indexUUID,
365+
String remoteStoreRepository,
366+
String repositoryBasePath
367+
) {
368+
String exceptionStr = null;
369+
if (version == null) {
370+
exceptionStr = "Invalid Version Provided";
371+
}
372+
if (snapshot == null) {
373+
exceptionStr = "Invalid/Missing Snapshot Name";
374+
}
375+
if (indexVersion < 0) {
376+
exceptionStr = "Invalid Index Version";
377+
}
378+
if (primaryTerm < 0) {
379+
exceptionStr = "Invalid Primary Term";
380+
}
381+
if (commitGeneration < 0) {
382+
exceptionStr = "Invalid Commit Generation";
383+
}
384+
if (indexUUID == null) {
385+
exceptionStr = "Invalid/Missing Index UUID";
386+
}
387+
if (remoteStoreRepository == null) {
388+
exceptionStr = "Invalid/Missing Remote Store Repository";
389+
}
390+
if (repositoryBasePath == null) {
391+
exceptionStr = "Invalid/Missing Repository Base Path";
392+
}
393+
if (exceptionStr != null) {
394+
throw new IllegalArgumentException(exceptionStr);
395+
}
396+
}
311397
}

server/src/main/java/org/opensearch/snapshots/SnapshotInfo.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public static final class SnapshotInfoBuilder {
118118
private ShardStatsBuilder shardStatsBuilder = null;
119119
private Boolean includeGlobalState = null;
120120

121-
private Boolean remoteStoreIndexShallowCopy = false;
121+
private Boolean remoteStoreIndexShallowCopy = null;
122122
private Map<String, Object> userMetadata = null;
123123
private int version = -1;
124124
private List<SnapshotShardFailure> shardFailures = null;
@@ -422,8 +422,6 @@ public SnapshotInfo(final StreamInput in) throws IOException {
422422
dataStreams = in.readStringList();
423423
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
424424
remoteStoreIndexShallowCopy = in.readOptionalBoolean();
425-
} else {
426-
remoteStoreIndexShallowCopy = false;
427425
}
428426
}
429427

@@ -747,7 +745,7 @@ public static SnapshotInfo fromXContentInternal(final XContentParser parser) thr
747745
int totalShards = 0;
748746
int successfulShards = 0;
749747
Boolean includeGlobalState = null;
750-
Boolean remoteStoreIndexShallowCopy = false;
748+
Boolean remoteStoreIndexShallowCopy = null;
751749
Map<String, Object> userMetadata = null;
752750
List<SnapshotShardFailure> shardFailures = Collections.emptyList();
753751
if (parser.currentToken() == null) { // fresh parser? move to the first token

server/src/main/java/org/opensearch/snapshots/SnapshotsService.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,17 @@ public ClusterState execute(ClusterState currentState) {
338338
}
339339

340340
boolean remoteStoreIndexShallowCopy = REMOTE_STORE_INDEX_SHALLOW_COPY.get(repository.getMetadata().settings());
341-
if (remoteStoreIndexShallowCopy && !currentState.nodes().getMinNodeVersion().onOrAfter(Version.V_2_9_0)) {
341+
Version minVersionInCluster = currentState.nodes().getMinNodeVersion();
342+
if (remoteStoreIndexShallowCopy && !minVersionInCluster.onOrAfter(Version.V_2_9_0)) {
342343
remoteStoreIndexShallowCopy = false;
343-
logger.warn("setting is ignored and will be used when all nodes are moved to version > 2.9");
344+
logger.warn(
345+
"setting "
346+
+ REMOTE_STORE_INDEX_SHALLOW_COPY
347+
+ " is ignored as some of the nodes in cluster have version < "
348+
+ Version.V_2_9_0
349+
+ ", minimum version found in cluster is "
350+
+ minVersionInCluster
351+
);
344352
}
345353
newEntry = SnapshotsInProgress.startedEntry(
346354
new Snapshot(repositoryName, snapshotId),

server/src/test/java/org/opensearch/index/snapshots/blobstore/RemoteStoreShardShallowCopySnapshotTests.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ public void testFromXContentInvalid() throws IOException {
135135
List<String> fileNames = new ArrayList<>(5);
136136
fileNames.addAll(Arrays.asList("file1", "file2", "file3", "file4", "file5"));
137137
String failure = null;
138+
String version = RemoteStoreShardShallowCopySnapshot.DEFAULT_VERSION;
138139
long length = Math.max(0, Math.abs(randomLong()));
139140
// random corruption
140-
switch (randomIntBetween(0, 7)) {
141+
switch (randomIntBetween(0, 8)) {
141142
case 0:
142143
snapshot = null;
143144
failure = "Invalid/Missing Snapshot Name";
@@ -167,13 +168,18 @@ public void testFromXContentInvalid() throws IOException {
167168
failure = "Invalid/Missing Repository Base Path";
168169
break;
169170
case 7:
171+
version = null;
172+
failure = "Invalid Version Provided";
173+
break;
174+
case 8:
170175
break;
171176
default:
172177
fail("shouldn't be here");
173178
}
174179

175180
XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
176181
builder.startObject();
182+
builder.field(RemoteStoreShardShallowCopySnapshot.VERSION, version);
177183
builder.field(RemoteStoreShardShallowCopySnapshot.NAME, snapshot);
178184
builder.field(RemoteStoreShardShallowCopySnapshot.INDEX_VERSION, indexVersion);
179185
builder.field(RemoteStoreShardShallowCopySnapshot.START_TIME, startTime);
@@ -213,7 +219,7 @@ public void testFromXContentInvalid() throws IOException {
213219
parser.nextToken();
214220
RemoteStoreShardShallowCopySnapshot.fromXContent(parser);
215221
fail("Should have failed with [" + failure + "]");
216-
} catch (NullPointerException | AssertionError ex) {
222+
} catch (IllegalArgumentException ex) {
217223
assertThat(ex.getMessage(), containsString(failure));
218224
}
219225
}

server/src/test/java/org/opensearch/repositories/blobstore/BlobStoreRepositoryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ private String[] getLockFilesInRemoteStore(String remoteStoreIndex, String remot
239239
BlobPath shardLevelBlobPath = remoteStorerepository.basePath().add(indexUUID).add("0").add("segments").add("lock_files");
240240
BlobContainer blobContainer = remoteStorerepository.blobStore().blobContainer(shardLevelBlobPath);
241241
try (RemoteBufferedOutputDirectory lockDirectory = new RemoteBufferedOutputDirectory(blobContainer)) {
242-
return lockDirectory.listAll();
242+
return Arrays.stream(lockDirectory.listAll()).filter(lock -> lock.endsWith(".lock")).toArray(String[]::new);
243243
}
244244
}
245245

0 commit comments

Comments
 (0)