Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public final class SmbMmapFsDirectoryFactory extends FsDirectoryFactory {
@Override
protected Directory newFSDirectory(Path location, LockFactory lockFactory, IndexSettings indexSettings) throws IOException {
return new SmbDirectoryWrapper(
setPreload(
setMMapFunctions(
new MMapDirectory(location, lockFactory),
new HashSet<>(indexSettings.getValue(IndexModule.INDEX_STORE_PRE_LOAD_SETTING))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private static Version parseUnchecked(String version) {
public static final IndexVersion UPGRADE_TO_LUCENE_10_2_1 = def(9_023_00_0, Version.LUCENE_10_2_1);
public static final IndexVersion DEFAULT_OVERSAMPLE_VALUE_FOR_BBQ = def(9_024_0_00, Version.LUCENE_10_2_1);
public static final IndexVersion SEMANTIC_TEXT_DEFAULTS_TO_BBQ = def(9_025_0_00, Version.LUCENE_10_2_1);

public static final IndexVersion UPGRADE_TO_LUCENE_10_3_0 = def(9_050_00_0, Version.LUCENE_10_3_0);
/*
* STOP! READ THIS FIRST! No, really,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.index;

import org.apache.lucene.store.IOContext;

/**
* A hint that no special behavior should be set on open files
*/
public enum StandardIOBehaviorHint implements IOContext.FileOpenHint {
INSTANCE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to have an ESFileOpenHint or something, where we can gather several open hints ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do, but there can only be one hint of each type in an IOContext...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can always add that later if it's useful

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import org.apache.lucene.store.MMapDirectory;
import org.apache.lucene.store.NIOFSDirectory;
import org.apache.lucene.store.NativeFSLockFactory;
import org.apache.lucene.store.ReadAdvice;
import org.apache.lucene.store.SimpleFSLockFactory;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property;
import org.elasticsearch.core.IOUtils;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.StandardIOBehaviorHint;
import org.elasticsearch.index.codec.vectors.es818.DirectIOIndexInputSupplier;
import org.elasticsearch.index.shard.ShardPath;
import org.elasticsearch.logging.LogManager;
Expand All @@ -36,6 +38,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Optional;
import java.util.OptionalLong;
import java.util.Set;
import java.util.function.BiPredicate;
Expand Down Expand Up @@ -75,12 +78,12 @@ protected Directory newFSDirectory(Path location, LockFactory lockFactory, Index
// Use Lucene defaults
final FSDirectory primaryDirectory = FSDirectory.open(location, lockFactory);
if (primaryDirectory instanceof MMapDirectory mMapDirectory) {
return new HybridDirectory(lockFactory, setPreload(mMapDirectory, preLoadExtensions));
return new HybridDirectory(lockFactory, setMMapFunctions(mMapDirectory, preLoadExtensions));
} else {
return primaryDirectory;
}
case MMAPFS:
return setPreload(new MMapDirectory(location, lockFactory), preLoadExtensions);
return setMMapFunctions(new MMapDirectory(location, lockFactory), preLoadExtensions);
case SIMPLEFS:
case NIOFS:
return new NIOFSDirectory(location, lockFactory);
Expand All @@ -89,10 +92,18 @@ protected Directory newFSDirectory(Path location, LockFactory lockFactory, Index
}
}

private static Optional<ReadAdvice> overrideReadAdvice(String name, IOContext context) {
if (context.hints().contains(StandardIOBehaviorHint.INSTANCE)) {
return Optional.of(ReadAdvice.NORMAL);
}
return Optional.empty();
}

/** Sets the preload, if any, on the given directory based on the extensions. Returns the same directory instance. */
// visibility and extensibility for testing
public MMapDirectory setPreload(MMapDirectory mMapDirectory, Set<String> preLoadExtensions) {
public MMapDirectory setMMapFunctions(MMapDirectory mMapDirectory, Set<String> preLoadExtensions) {
mMapDirectory.setPreload(getPreloadFunc(preLoadExtensions));
mMapDirectory.setReadAdviceOverride(FsDirectoryFactory::overrideReadAdvice);
return mMapDirectory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static class PreLoadExposingFsDirectoryFactory extends FsDirectoryFactory {
final Map<MMapDirectory, BiPredicate<String, IOContext>> preLoadFuncMap = new HashMap<>();

@Override
public MMapDirectory setPreload(MMapDirectory mMapDirectory, Set<String> preLoadExtensions) {
public MMapDirectory setMMapFunctions(MMapDirectory mMapDirectory, Set<String> preLoadExtensions) {
var preLoadFunc = FsDirectoryFactory.getPreloadFunc(preLoadExtensions);
mMapDirectory.setPreload(preLoadFunc);
preLoadFuncMap.put(mMapDirectory, preLoadFunc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.ReadAdvice;
import org.elasticsearch.blobcache.BlobCacheUtils;
import org.elasticsearch.blobcache.common.ByteRange;
import org.elasticsearch.index.StandardIOBehaviorHint;
import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot.FileInfo;
import org.elasticsearch.xpack.searchablesnapshots.cache.common.CacheFile;
import org.elasticsearch.xpack.searchablesnapshots.store.IndexInputStats;
Expand All @@ -36,7 +36,7 @@ public class CachedBlobContainerIndexInput extends MetadataCachingIndexInput {
* a complete part of the {@link #fileInfo} at once in the cache and should not be
* used for anything else than what the {@link #prefetchPart(int, Supplier)} method does.
*/
public static final IOContext CACHE_WARMING_CONTEXT = new IOContext(IOContext.Context.DEFAULT, null, null, ReadAdvice.NORMAL);
public static final IOContext CACHE_WARMING_CONTEXT = IOContext.DEFAULT.withHints(StandardIOBehaviorHint.INSTANCE);

private static final Logger logger = LogManager.getLogger(CachedBlobContainerIndexInput.class);

Expand Down