-
Notifications
You must be signed in to change notification settings - Fork 25k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use listeners to manage cache files associated with removed shards
- Loading branch information
Showing
7 changed files
with
316 additions
and
20 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
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
76 changes: 76 additions & 0 deletions
76
...asticsearch/xpack/searchablesnapshots/SearchableSnapshotIndexFoldersDeletionListener.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,76 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.searchablesnapshots; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.IndexSettings; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.plugins.IndexStorePlugin; | ||
import org.elasticsearch.repositories.IndexId; | ||
import org.elasticsearch.snapshots.SnapshotId; | ||
import org.elasticsearch.xpack.searchablesnapshots.cache.CacheService; | ||
|
||
import java.nio.file.Path; | ||
import java.util.Objects; | ||
import java.util.function.Supplier; | ||
|
||
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.SNAPSHOT_INDEX_ID_SETTING; | ||
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.SNAPSHOT_INDEX_NAME_SETTING; | ||
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.SNAPSHOT_SNAPSHOT_ID_SETTING; | ||
import static org.elasticsearch.xpack.searchablesnapshots.SearchableSnapshots.SNAPSHOT_SNAPSHOT_NAME_SETTING; | ||
|
||
/** | ||
* This {@link IndexStorePlugin.IndexFoldersDeletionListener} is called when an index folder or a shard folder is deleted from the disk. If | ||
* the index (or the shard) is a backed by a snapshot this listener notifies the {@link CacheService} that the cache files associated to the | ||
* shard(s) must be evicted. | ||
*/ | ||
public class SearchableSnapshotIndexFoldersDeletionListener implements IndexStorePlugin.IndexFoldersDeletionListener { | ||
|
||
private static final Logger logger = LogManager.getLogger(SearchableSnapshotIndexEventListener.class); | ||
|
||
private final Supplier<CacheService> cacheService; | ||
|
||
public SearchableSnapshotIndexFoldersDeletionListener(Supplier<CacheService> cacheService) { | ||
this.cacheService = Objects.requireNonNull(cacheService); | ||
} | ||
|
||
@Override | ||
public void beforeIndexFoldersDeleted(Index index, IndexSettings indexSettings, Path[] indexPaths) { | ||
if (SearchableSnapshotsConstants.isSearchableSnapshotStore(indexSettings.getSettings())) { | ||
for (int shard = 0; shard < indexSettings.getNumberOfShards(); shard++) { | ||
markShardAsEvictedInCache(new ShardId(index, shard), indexSettings); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void beforeShardFoldersDeleted(ShardId shardId, IndexSettings indexSettings, Path[] shardPaths) { | ||
if (SearchableSnapshotsConstants.isSearchableSnapshotStore(indexSettings.getSettings())) { | ||
markShardAsEvictedInCache(shardId, indexSettings); | ||
} | ||
} | ||
|
||
private void markShardAsEvictedInCache(ShardId shardId, IndexSettings indexSettings) { | ||
final CacheService cacheService = this.cacheService.get(); | ||
assert cacheService != null : "cache service not initialized"; | ||
|
||
logger.debug("{} marking shard as evicted in searchable snapshots cache (reason: cache files deleted from disk)", shardId); | ||
cacheService.markShardAsEvictedInCache( | ||
new SnapshotId( | ||
SNAPSHOT_SNAPSHOT_NAME_SETTING.get(indexSettings.getSettings()), | ||
SNAPSHOT_SNAPSHOT_ID_SETTING.get(indexSettings.getSettings()) | ||
), | ||
new IndexId( | ||
SNAPSHOT_INDEX_NAME_SETTING.get(indexSettings.getSettings()), | ||
SNAPSHOT_INDEX_ID_SETTING.get(indexSettings.getSettings()) | ||
), | ||
shardId | ||
); | ||
} | ||
} |
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
Oops, something went wrong.