Skip to content

Commit caa9e2b

Browse files
anshu1106Anshu Agarwalsachinpkale
authored andcommitted
[Snapshot V2] Fix for create snapshot build and test failures (opensearch-project#15602)
--------- Signed-off-by: Anshu Agarwal <anshukag@amazon.com> Signed-off-by: Sachin Kale <sachinpkale@gmail.com> Co-authored-by: Anshu Agarwal <anshukag@amazon.com> Co-authored-by: Sachin Kale <sachinpkale@gmail.com>
1 parent 5fcf996 commit caa9e2b

File tree

8 files changed

+127
-3
lines changed

8 files changed

+127
-3
lines changed

server/src/main/java/org/opensearch/repositories/FilterRepository.java

+21
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,27 @@ public void getRepositoryData(ActionListener<RepositoryData> listener) {
9797
in.getRepositoryData(listener);
9898
}
9999

100+
@Override
101+
public void finalizeSnapshot(
102+
ShardGenerations shardGenerations,
103+
long repositoryStateId,
104+
Metadata clusterMetadata,
105+
SnapshotInfo snapshotInfo,
106+
Version repositoryMetaVersion,
107+
Function<ClusterState, ClusterState> stateTransformer,
108+
ActionListener<RepositoryData> listener
109+
) {
110+
in.finalizeSnapshot(
111+
shardGenerations,
112+
repositoryStateId,
113+
clusterMetadata,
114+
snapshotInfo,
115+
repositoryMetaVersion,
116+
stateTransformer,
117+
listener
118+
);
119+
}
120+
100121
@Override
101122
public void finalizeSnapshot(
102123
ShardGenerations shardGenerations,

server/src/main/java/org/opensearch/repositories/Repository.java

+24
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,30 @@ default Repository create(RepositoryMetadata metadata, Function<String, Reposito
139139
*/
140140
void getRepositoryData(ActionListener<RepositoryData> listener);
141141

142+
/**
143+
* Finalizes snapshotting process
144+
* <p>
145+
* This method is called on cluster-manager after all shards are snapshotted.
146+
*
147+
* @param shardGenerations updated shard generations
148+
* @param repositoryStateId the unique id identifying the state of the repository when the snapshot began
149+
* @param clusterMetadata cluster metadata
150+
* @param snapshotInfo SnapshotInfo instance to write for this snapshot
151+
* @param repositoryMetaVersion version of the updated repository metadata to write
152+
* @param stateTransformer a function that filters the last cluster state update that the snapshot finalization will execute and
153+
* is used to remove any state tracked for the in-progress snapshot from the cluster state
154+
* @param listener listener to be invoked with the new {@link RepositoryData} after completing the snapshot
155+
*/
156+
void finalizeSnapshot(
157+
ShardGenerations shardGenerations,
158+
long repositoryStateId,
159+
Metadata clusterMetadata,
160+
SnapshotInfo snapshotInfo,
161+
Version repositoryMetaVersion,
162+
Function<ClusterState, ClusterState> stateTransformer,
163+
ActionListener<RepositoryData> listener
164+
);
165+
142166
/**
143167
* Finalizes snapshotting process
144168
* <p>

server/src/main/java/org/opensearch/repositories/blobstore/BlobStoreRepository.java

+22
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,28 @@ private DeleteResult cleanUpStaleSnapshotShardPathsFile(List<String> matchingSha
20242024
return new DeleteResult(matchingShardPaths.size(), totalBytes);
20252025
}
20262026

2027+
@Override
2028+
public void finalizeSnapshot(
2029+
final ShardGenerations shardGenerations,
2030+
final long repositoryStateId,
2031+
final Metadata clusterMetadata,
2032+
SnapshotInfo snapshotInfo,
2033+
Version repositoryMetaVersion,
2034+
Function<ClusterState, ClusterState> stateTransformer,
2035+
final ActionListener<RepositoryData> listener
2036+
) {
2037+
finalizeSnapshot(
2038+
shardGenerations,
2039+
repositoryStateId,
2040+
clusterMetadata,
2041+
snapshotInfo,
2042+
repositoryMetaVersion,
2043+
stateTransformer,
2044+
Priority.NORMAL,
2045+
listener
2046+
);
2047+
}
2048+
20272049
@Override
20282050
public void finalizeSnapshot(
20292051
final ShardGenerations shardGenerations,

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

+32
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,38 @@ public SnapshotInfo(SnapshotsInProgress.Entry entry) {
354354
);
355355
}
356356

357+
public SnapshotInfo(
358+
SnapshotId snapshotId,
359+
List<String> indices,
360+
List<String> dataStreams,
361+
long startTime,
362+
String reason,
363+
long endTime,
364+
int totalShards,
365+
List<SnapshotShardFailure> shardFailures,
366+
Boolean includeGlobalState,
367+
Map<String, Object> userMetadata,
368+
Boolean remoteStoreIndexShallowCopy
369+
) {
370+
this(
371+
snapshotId,
372+
indices,
373+
dataStreams,
374+
snapshotState(reason, shardFailures),
375+
reason,
376+
Version.CURRENT,
377+
startTime,
378+
endTime,
379+
totalShards,
380+
totalShards - shardFailures.size(),
381+
shardFailures,
382+
includeGlobalState,
383+
userMetadata,
384+
remoteStoreIndexShallowCopy,
385+
0
386+
);
387+
}
388+
357389
public SnapshotInfo(
358390
SnapshotId snapshotId,
359391
List<String> indices,

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ public class SnapshotsService extends AbstractLifecycleComponent implements Clus
205205
Setting.Property.Dynamic
206206
);
207207

208+
private static final String SNAPSHOT_PINNED_TIMESTAMP_DELIMITER = "__";
208209
/**
209210
* Setting to specify the maximum number of shards that can be included in the result for the snapshot status
210211
* API call. Note that it does not apply to V2-shallow snapshots.
@@ -216,8 +217,6 @@ public class SnapshotsService extends AbstractLifecycleComponent implements Clus
216217
Setting.Property.NodeScope,
217218
Setting.Property.Dynamic
218219
);
219-
220-
private static final String SNAPSHOT_PINNED_TIMESTAMP_DELIMITER = ":";
221220
private volatile int maxConcurrentOperations;
222221

223222
public SnapshotsService(

server/src/test/java/org/opensearch/repositories/RepositoriesServiceTests.java

+13
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,19 @@ public void finalizeSnapshot(
681681
listener.onResponse(null);
682682
}
683683

684+
@Override
685+
public void finalizeSnapshot(
686+
ShardGenerations shardGenerations,
687+
long repositoryStateId,
688+
Metadata clusterMetadata,
689+
SnapshotInfo snapshotInfo,
690+
Version repositoryMetaVersion,
691+
Function<ClusterState, ClusterState> stateTransformer,
692+
ActionListener<RepositoryData> listener
693+
) {
694+
listener.onResponse(null);
695+
}
696+
684697
@Override
685698
public void deleteSnapshots(
686699
Collection<SnapshotId> snapshotIds,

test/framework/src/main/java/org/opensearch/index/shard/RestoreOnlyRepository.java

+13
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,19 @@ public void getRepositoryData(ActionListener<RepositoryData> listener) {
118118
);
119119
}
120120

121+
@Override
122+
public void finalizeSnapshot(
123+
ShardGenerations shardGenerations,
124+
long repositoryStateId,
125+
Metadata clusterMetadata,
126+
SnapshotInfo snapshotInfo,
127+
Version repositoryMetaVersion,
128+
Function<ClusterState, ClusterState> stateTransformer,
129+
ActionListener<RepositoryData> listener
130+
) {
131+
listener.onResponse(null);
132+
}
133+
121134
@Override
122135
public void finalizeSnapshot(
123136
ShardGenerations shardGenerations,

test/framework/src/main/java/org/opensearch/test/OpenSearchIntegTestCase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2898,7 +2898,7 @@ private static Settings buildRemoteStoreNodeAttributes(
28982898
}
28992899
settings.put(RemoteStoreSettings.CLUSTER_REMOTE_STORE_PATH_TYPE_SETTING.getKey(), randomFrom(PathType.values()));
29002900
settings.put(RemoteStoreSettings.CLUSTER_REMOTE_STORE_TRANSLOG_METADATA.getKey(), randomBoolean());
2901-
settings.put(RemoteStoreSettings.CLUSTER_REMOTE_STORE_PINNED_TIMESTAMP_ENABLED.getKey(), false);
2901+
settings.put(RemoteStoreSettings.CLUSTER_REMOTE_STORE_PINNED_TIMESTAMP_ENABLED.getKey(), randomBoolean());
29022902
settings.put(RemoteStoreSettings.CLUSTER_REMOTE_STORE_SEGMENTS_PATH_PREFIX.getKey(), translogPathFixedPrefix ? "a" : "");
29032903
settings.put(RemoteStoreSettings.CLUSTER_REMOTE_STORE_TRANSLOG_PATH_PREFIX.getKey(), segmentsPathFixedPrefix ? "b" : "");
29042904
return settings.build();

0 commit comments

Comments
 (0)