Skip to content

Commit 822db8c

Browse files
committed
Always use CacheService for caching metadata blobs (#70668) (#70795)
This PR unifies CachedBlobContainerIndexInput and FrozenIndexInput so that they share the same infrastructure for caching metadata blobs as well as header and footer ranges for data blobs. The idea is to always use CacheService for this, which does not evict the metadata, and which efficiently stores the information on disk (using sparse file support). This also allows us to align writes in FrozenCacheService to 4KB block sizes in this PR, which addresses an issue when reusing regions from the shared cache, as writes that are not aligned on page cache boundaries causes the existing data (which we don't care about) to be loaded from disk, which comes with a dramatic performance penalty. Closes #70728 Closes #70763
1 parent 83f97a1 commit 822db8c

File tree

12 files changed

+669
-880
lines changed

12 files changed

+669
-880
lines changed

x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/blobstore/cache/SearchableSnapshotsBlobStoreCacheIntegTests.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ public void testBlobStoreCache() throws Exception {
157157
() -> systemClient().admin().indices().prepareGetIndex().addIndices(SNAPSHOT_BLOB_CACHE_INDEX).get()
158158
);
159159

160-
final Storage storage = randomFrom(Storage.values());
160+
final Storage storage1 = randomFrom(Storage.values());
161161
logger.info(
162162
"--> mount snapshot [{}] as an index for the first time [storage={}, max length={}]",
163163
snapshot,
164-
storage,
164+
storage1,
165165
blobCacheMaxLength.getStringRep()
166166
);
167167
final String restoredIndex = randomBoolean() ? indexName : randomAlphaOfLength(10).toLowerCase(Locale.ROOT);
@@ -175,7 +175,7 @@ public void testBlobStoreCache() throws Exception {
175175
.put(SearchableSnapshots.SNAPSHOT_CACHE_PREWARM_ENABLED_SETTING.getKey(), false)
176176
.put(SearchableSnapshots.SNAPSHOT_BLOB_CACHE_METADATA_FILES_MAX_LENGTH, blobCacheMaxLength)
177177
.build(),
178-
storage
178+
storage1
179179
);
180180
ensureGreen(restoredIndex);
181181

@@ -244,7 +244,8 @@ public void testBlobStoreCache() throws Exception {
244244
);
245245
});
246246

247-
logger.info("--> mount snapshot [{}] as an index for the second time [storage={}]", snapshot, storage);
247+
final Storage storage2 = randomFrom(Storage.values());
248+
logger.info("--> mount snapshot [{}] as an index for the second time [storage={}]", snapshot, storage2);
248249
final String restoredAgainIndex = randomBoolean() ? indexName : randomAlphaOfLength(10).toLowerCase(Locale.ROOT);
249250
mountSnapshot(
250251
repositoryName,
@@ -256,7 +257,7 @@ public void testBlobStoreCache() throws Exception {
256257
.put(SearchableSnapshots.SNAPSHOT_CACHE_PREWARM_ENABLED_SETTING.getKey(), false)
257258
.put(SearchableSnapshots.SNAPSHOT_BLOB_CACHE_METADATA_FILES_MAX_LENGTH, blobCacheMaxLength)
258259
.build(),
259-
storage
260+
storage2
260261
);
261262
ensureGreen(restoredAgainIndex);
262263

x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsPrewarmingIntegTests.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.elasticsearch.threadpool.ThreadPool;
5050
import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotAction;
5151
import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest;
52+
import org.junit.After;
5253

5354
import java.io.FilterInputStream;
5455
import java.io.IOException;
@@ -180,14 +181,7 @@ public void testConcurrentPrewarming() throws Exception {
180181
.setSettings(repositorySettings.build())
181182
);
182183

183-
TrackingRepositoryPlugin tracker = null;
184-
for (RepositoryPlugin plugin : getInstanceFromNode(PluginsService.class).filterPlugins(RepositoryPlugin.class)) {
185-
if (plugin instanceof TrackingRepositoryPlugin) {
186-
tracker = ((TrackingRepositoryPlugin) plugin);
187-
}
188-
}
189-
190-
assertThat(tracker, notNullValue());
184+
TrackingRepositoryPlugin tracker = getTrackingRepositoryPlugin();
191185
assertThat(tracker.totalFilesRead(), equalTo(0L));
192186
assertThat(tracker.totalBytesRead(), equalTo(0L));
193187

@@ -305,6 +299,20 @@ public void testConcurrentPrewarming() throws Exception {
305299
}
306300
}
307301

302+
@After
303+
public void resetTracker() {
304+
getTrackingRepositoryPlugin().clear();
305+
}
306+
307+
private TrackingRepositoryPlugin getTrackingRepositoryPlugin() {
308+
for (RepositoryPlugin plugin : getInstanceFromNode(PluginsService.class).filterPlugins(RepositoryPlugin.class)) {
309+
if (plugin instanceof TrackingRepositoryPlugin) {
310+
return ((TrackingRepositoryPlugin) plugin);
311+
}
312+
}
313+
throw new IllegalStateException("tracking repository missing");
314+
}
315+
308316
/**
309317
* A plugin that allows to track the read operations on blobs
310318
*/
@@ -313,6 +321,11 @@ public static class TrackingRepositoryPlugin extends Plugin implements Repositor
313321
private final ConcurrentHashMap<String, Long> files = new ConcurrentHashMap<>();
314322
private final AtomicBoolean enabled = new AtomicBoolean(true);
315323

324+
void clear() {
325+
files.clear();
326+
enabled.set(true);
327+
}
328+
316329
long totalFilesRead() {
317330
return files.size();
318331
}

x-pack/plugin/searchable-snapshots/src/internalClusterTest/java/org/elasticsearch/xpack/searchablesnapshots/SearchableSnapshotsUuidValidationIntegTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.elasticsearch.plugins.ActionPlugin;
2222
import org.elasticsearch.plugins.Plugin;
2323
import org.elasticsearch.snapshots.SnapshotRestoreException;
24+
import org.elasticsearch.test.ESIntegTestCase;
2425
import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotAction;
2526
import org.elasticsearch.xpack.core.searchablesnapshots.MountSearchableSnapshotRequest;
2627

@@ -33,6 +34,7 @@
3334
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
3435
import static org.hamcrest.Matchers.containsString;
3536

37+
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST)
3638
public class SearchableSnapshotsUuidValidationIntegTests extends BaseSearchableSnapshotsIntegTestCase {
3739

3840
public static class TestPlugin extends Plugin implements ActionPlugin {

x-pack/plugin/searchable-snapshots/src/main/java/org/elasticsearch/index/store/BaseSearchableSnapshotIndexInput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private boolean maybeReadChecksumFromFileInfo(ByteBuffer b) throws IOException {
152152
return success;
153153
}
154154

155-
protected ByteRange maybeReadFromBlobCache(long position, int length) {
155+
protected ByteRange rangeToReadFromBlobCache(long position, int length) {
156156
final long end = position + length;
157157
if (headerBlobCacheByteRange.contains(position, end)) {
158158
return headerBlobCacheByteRange;

0 commit comments

Comments
 (0)