-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Create file open hints on IOContext to replace ReadAdvice #14482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
739f816
Split IOContext into separate implementations
thecoop 0843b20
Anonymous classes
thecoop a29183a
Add a hints field
thecoop b70ce5e
Add hint classes and validation method
thecoop edfc21e
Add calls to validate and a test
thecoop 5a6fbec
Map from IOContext to ReadAdvice
thecoop 808e7fa
PR comments
thecoop d85a990
Merge branch 'main' into iocontext-split
thecoop 7ffca77
Add javadocs
thecoop ae1bc87
Move the hint assertion into IOContext
thecoop eb80be0
Add a ReadAdvice override function
thecoop 86e7935
Remove toReadAdvice from Directory
thecoop b99c98d
PR comments
thecoop b0a1552
Merge remote-tracking branch 'upstream/main' into iocontext-split
thecoop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
25 changes: 25 additions & 0 deletions
25
lucene/core/src/java/org/apache/lucene/store/DataAccessHint.java
This file contains hidden or 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,25 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.lucene.store; | ||
|
|
||
| /** Hint on the data access pattern likely to be used */ | ||
| public enum DataAccessHint implements IOContext.FileOpenHint { | ||
| /** The access pattern is completely random */ | ||
| RANDOM, | ||
| /** The access pattern is only sequential (forwards-only) */ | ||
| SEQUENTIAL | ||
| } | ||
83 changes: 83 additions & 0 deletions
83
lucene/core/src/java/org/apache/lucene/store/DefaultIOContext.java
This file contains hidden or 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,83 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.lucene.store; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| record DefaultIOContext(Optional<ReadAdvice> readAdvice, Set<FileOpenHint> hints) | ||
| implements IOContext { | ||
|
|
||
| public DefaultIOContext { | ||
| Objects.requireNonNull(readAdvice); | ||
| Objects.requireNonNull(hints); | ||
| if (readAdvice.isPresent() && !hints.isEmpty()) | ||
| throw new IllegalArgumentException("Either ReadAdvice or hints can be specified, not both"); | ||
|
|
||
| // there should only be one hint of each type in the IOContext | ||
| Map<Class<? extends FileOpenHint>, List<FileOpenHint>> hintClasses = | ||
| hints.stream().collect(Collectors.groupingBy(IOContext.FileOpenHint::getClass)); | ||
| for (var hintType : hintClasses.entrySet()) { | ||
| if (hintType.getValue().size() > 1) { | ||
| throw new IllegalArgumentException("Multiple hints of type " + hintType + " specified"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public DefaultIOContext(Optional<ReadAdvice> readAdvice, FileOpenHint... hints) { | ||
| this(readAdvice, Set.of(hints)); | ||
| } | ||
|
|
||
| @Override | ||
| public Context context() { | ||
| return Context.DEFAULT; | ||
| } | ||
|
|
||
| @Override | ||
| public MergeInfo mergeInfo() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public FlushInfo flushInfo() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public IOContext withHints(FileOpenHint... hints) { | ||
| if (readAdvice().isPresent()) | ||
| throw new IllegalArgumentException("ReadAdvice has been specified directly"); | ||
| // TODO: see if this is needed or not | ||
| if (!hints().isEmpty()) throw new IllegalArgumentException("Hints have already been specified"); | ||
| return new DefaultIOContext(Optional.empty(), hints); | ||
| } | ||
|
|
||
| private static final DefaultIOContext[] READADVICE_TO_IOCONTEXT = | ||
| Arrays.stream(ReadAdvice.values()) | ||
| .map(r -> new DefaultIOContext(Optional.of(r))) | ||
| .toArray(DefaultIOContext[]::new); | ||
|
|
||
| @Override | ||
| public DefaultIOContext withReadAdvice(ReadAdvice advice) { | ||
| return READADVICE_TO_IOCONTEXT[advice.ordinal()]; | ||
| } | ||
| } |
27 changes: 27 additions & 0 deletions
27
lucene/core/src/java/org/apache/lucene/store/FileDataHint.java
This file contains hidden or 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,27 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.lucene.store; | ||
|
|
||
| /** Hints on the type of data stored in the file */ | ||
| public enum FileDataHint implements IOContext.FileOpenHint { | ||
| /** The file contains postings data */ | ||
| POSTINGS, | ||
| /** The file contains stored fields */ | ||
| STORED_FIELDS, | ||
| /** The file contains vector data for kNN search */ | ||
| KNN_VECTORS | ||
| } |
27 changes: 27 additions & 0 deletions
27
lucene/core/src/java/org/apache/lucene/store/FileTypeHint.java
This file contains hidden or 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,27 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.lucene.store; | ||
|
|
||
| /** Hints on the type of file being opened */ | ||
| public enum FileTypeHint implements IOContext.FileOpenHint { | ||
| /** The file contains metadata */ | ||
| METADATA, | ||
| /** The file contains field data */ | ||
| DATA, | ||
| /** The file contains indexes */ | ||
| INDEX | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.