Skip to content

Commit 7f08d68

Browse files
anshu1106Anshu Agarwal
and
Anshu Agarwal
authored
[Snapshot V2] Support pinned timestamp in delete flow (#15256) (#15730)
(cherry picked from commit 5bf34d2) Signed-off-by: Anshu Agarwal <anshukag@amazon.com> Co-authored-by: Anshu Agarwal <anshukag@amazon.com>
1 parent dac70e8 commit 7f08d68

File tree

8 files changed

+794
-31
lines changed

8 files changed

+794
-31
lines changed

server/src/internalClusterTest/java/org/opensearch/snapshots/DeleteSnapshotITV2.java

+332
Large diffs are not rendered by default.

server/src/main/java/org/opensearch/action/admin/cluster/repositories/cleanup/TransportCleanupRepositoryAction.java

+9
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.opensearch.common.inject.Inject;
5555
import org.opensearch.core.action.ActionListener;
5656
import org.opensearch.core.common.io.stream.StreamInput;
57+
import org.opensearch.index.store.RemoteSegmentStoreDirectoryFactory;
5758
import org.opensearch.index.store.lockmanager.RemoteStoreLockManagerFactory;
5859
import org.opensearch.indices.RemoteStoreSettings;
5960
import org.opensearch.repositories.RepositoriesService;
@@ -101,6 +102,8 @@ public final class TransportCleanupRepositoryAction extends TransportClusterMana
101102

102103
private final RemoteStoreLockManagerFactory remoteStoreLockManagerFactory;
103104

105+
private final RemoteSegmentStoreDirectoryFactory remoteSegmentStoreDirectoryFactory;
106+
104107
@Override
105108
protected String executor() {
106109
return ThreadPool.Names.SAME;
@@ -128,6 +131,11 @@ public TransportCleanupRepositoryAction(
128131
);
129132
this.repositoriesService = repositoriesService;
130133
this.snapshotsService = snapshotsService;
134+
this.remoteSegmentStoreDirectoryFactory = new RemoteSegmentStoreDirectoryFactory(
135+
() -> repositoriesService,
136+
threadPool,
137+
remoteStoreSettings.getSegmentsPathFixedPrefix()
138+
);
131139
this.remoteStoreLockManagerFactory = new RemoteStoreLockManagerFactory(
132140
() -> repositoriesService,
133141
remoteStoreSettings.getSegmentsPathFixedPrefix()
@@ -291,6 +299,7 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
291299
repositoryStateId,
292300
snapshotsService.minCompatibleVersion(newState.nodes().getMinNodeVersion(), repositoryData, null),
293301
remoteStoreLockManagerFactory,
302+
remoteSegmentStoreDirectoryFactory,
294303
ActionListener.wrap(result -> after(null, result), e -> after(e, null))
295304
)
296305
)

server/src/main/java/org/opensearch/node/remotestore/RemoteStorePinnedTimestampService.java

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.apache.logging.log4j.Logger;
1313
import org.apache.logging.log4j.message.ParameterizedMessage;
1414
import org.opensearch.cluster.service.ClusterService;
15+
import org.opensearch.common.annotation.ExperimentalApi;
1516
import org.opensearch.common.blobstore.BlobContainer;
1617
import org.opensearch.common.blobstore.BlobMetadata;
1718
import org.opensearch.common.collect.Tuple;
@@ -42,6 +43,7 @@
4243
*
4344
* @opensearch.internal
4445
*/
46+
@ExperimentalApi
4547
public class RemoteStorePinnedTimestampService implements Closeable {
4648
private static final Logger logger = LogManager.getLogger(RemoteStorePinnedTimestampService.class);
4749
private static Tuple<Long, Set<Long>> pinnedTimestampsSet = new Tuple<>(-1L, Set.of());

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

+55-5
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@
5050
import org.opensearch.index.mapper.MapperService;
5151
import org.opensearch.index.snapshots.IndexShardSnapshotStatus;
5252
import org.opensearch.index.snapshots.blobstore.RemoteStoreShardShallowCopySnapshot;
53+
import org.opensearch.index.store.RemoteSegmentStoreDirectoryFactory;
5354
import org.opensearch.index.store.Store;
5455
import org.opensearch.index.store.lockmanager.RemoteStoreLockManagerFactory;
5556
import org.opensearch.indices.recovery.RecoveryState;
57+
import org.opensearch.node.remotestore.RemoteStorePinnedTimestampService;
5658
import org.opensearch.snapshots.SnapshotId;
5759
import org.opensearch.snapshots.SnapshotInfo;
5860

@@ -220,11 +222,59 @@ void deleteSnapshots(
220222
/**
221223
* Deletes snapshots and releases respective lock files from remote store repository.
222224
*
223-
* @param snapshotIds snapshot ids
224-
* @param repositoryStateId the unique id identifying the state of the repository when the snapshot deletion began
225-
* @param repositoryMetaVersion version of the updated repository metadata to write
226-
* @param remoteStoreLockManagerFactory RemoteStoreLockManagerFactory to be used for cleaning up remote store lock files
227-
* @param listener completion listener
225+
* @param snapshotIds snapshot ids
226+
* @param repositoryStateId the unique id identifying the state of the repository when the snapshot deletion began
227+
* @param repositoryMetaVersion version of the updated repository metadata to write
228+
* @param remoteStoreLockManagerFactory RemoteStoreLockManagerFactory to be used for cleaning up remote store lock files
229+
* @param remoteSegmentStoreDirectoryFactory RemoteSegmentStoreDirectoryFactory to be used for cleaning up remote store segment files
230+
* @param remoteStorePinnedTimestampService service for pinning and unpinning of the timestamp
231+
* @param snapshotIdsPinnedTimestampMap map of snapshots ids and the pinned timestamp
232+
* @param isShallowSnapshotV2 true for shallow snapshots v2
233+
* @param listener completion listener
234+
*/
235+
default void deleteSnapshotsInternal(
236+
Collection<SnapshotId> snapshotIds,
237+
long repositoryStateId,
238+
Version repositoryMetaVersion,
239+
RemoteStoreLockManagerFactory remoteStoreLockManagerFactory,
240+
RemoteSegmentStoreDirectoryFactory remoteSegmentStoreDirectoryFactory,
241+
RemoteStorePinnedTimestampService remoteStorePinnedTimestampService,
242+
Map<SnapshotId, Long> snapshotIdsPinnedTimestampMap,
243+
boolean isShallowSnapshotV2,
244+
ActionListener<RepositoryData> listener
245+
) {
246+
throw new UnsupportedOperationException();
247+
}
248+
249+
/**
250+
* Deletes snapshots and unpin the snapshot timestamp using remoteStorePinnedTimestampService
251+
*
252+
* @param snapshotsWithPinnedTimestamp map of snapshot ids and the pinned timestamps
253+
* @param repositoryStateId the unique id identifying the state of the repository when the snapshot deletion began
254+
* @param repositoryMetaVersion version of the updated repository metadata to write
255+
* @param remoteSegmentStoreDirectoryFactory RemoteSegmentStoreDirectoryFactory to be used for cleaning up remote store segment files
256+
* @param remoteStorePinnedTimestampService service for pinning and unpinning of the timestamp
257+
* @param listener completion listener
258+
*/
259+
default void deleteSnapshotsWithPinnedTimestamp(
260+
Map<SnapshotId, Long> snapshotsWithPinnedTimestamp,
261+
long repositoryStateId,
262+
Version repositoryMetaVersion,
263+
RemoteSegmentStoreDirectoryFactory remoteSegmentStoreDirectoryFactory,
264+
RemoteStorePinnedTimestampService remoteStorePinnedTimestampService,
265+
ActionListener<RepositoryData> listener
266+
) {
267+
throw new UnsupportedOperationException();
268+
}
269+
270+
/**
271+
* Deletes snapshots and releases respective lock files from remote store repository
272+
*
273+
* @param snapshotIds
274+
* @param repositoryStateId
275+
* @param repositoryMetaVersion
276+
* @param remoteStoreLockManagerFactory
277+
* @param listener
228278
*/
229279
default void deleteSnapshotsAndReleaseLockFiles(
230280
Collection<SnapshotId> snapshotIds,

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

+5
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ public final class RepositoryData {
112112
* The indices found in the repository across all snapshots, as a name to {@link IndexId} mapping
113113
*/
114114
private final Map<String, IndexId> indices;
115+
116+
public Map<IndexId, List<SnapshotId>> getIndexSnapshots() {
117+
return indexSnapshots;
118+
}
119+
115120
/**
116121
* The snapshots that each index belongs to.
117122
*/

0 commit comments

Comments
 (0)