-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Harish Bhakuni <[email protected]>
- Loading branch information
Harish Bhakuni
committed
Mar 13, 2024
1 parent
76d1319
commit 5475951
Showing
5 changed files
with
126 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
server/src/main/java/org/opensearch/repositories/blobstore/RemoteStoreShardCleanupTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.repositories.blobstore; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.core.index.shard.ShardId; | ||
|
||
import java.util.Set; | ||
|
||
import static org.opensearch.common.util.concurrent.ConcurrentCollections.newConcurrentSet; | ||
|
||
/** | ||
A Runnable wrapper to make sure that for a given shard only one cleanup task runs at a time. | ||
*/ | ||
public class RemoteStoreShardCleanupTask implements Runnable { | ||
private final Runnable task; | ||
private final String shardIdentifier; | ||
final static Set<String> ongoingRemoteDirectoryCleanups = newConcurrentSet(); | ||
final static Set<String> pendingRemoteDirectoryCleanups = newConcurrentSet(); | ||
private static final Logger staticLogger = LogManager.getLogger(RemoteStoreShardCleanupTask.class); | ||
|
||
public RemoteStoreShardCleanupTask(Runnable task, String indexUUID, ShardId shardId) { | ||
this.task = task; | ||
this.shardIdentifier = indexShardIdentifier(indexUUID, shardId); | ||
} | ||
|
||
private static String indexShardIdentifier(String indexUUID, ShardId shardId) { | ||
return String.join("/", indexUUID, String.valueOf(shardId.id())); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
if (pendingRemoteDirectoryCleanups.add(shardIdentifier)) { | ||
if (ongoingRemoteDirectoryCleanups.add(shardIdentifier)) { | ||
while (pendingRemoteDirectoryCleanups.contains(shardIdentifier)) { | ||
ongoingRemoteDirectoryCleanups.add(shardIdentifier); | ||
pendingRemoteDirectoryCleanups.remove(shardIdentifier); | ||
task.run(); | ||
ongoingRemoteDirectoryCleanups.remove(shardIdentifier); | ||
} | ||
} else { | ||
staticLogger.debug("one task is already ongoing, we can leave entry in pending"); | ||
} | ||
} else { | ||
staticLogger.debug("one cleanup task for shard is already in pending, we can skip this task"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters