-
Notifications
You must be signed in to change notification settings - Fork 702
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
SOLR-17310: Configurable LeafSorter to customize segment search order #2477
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
91384f0
leaf sorter support
91a7016
clean up
7c105f6
Merge branch 'apache:main' into leaf_sorter
weiwang19 397213a
format
b02dfce
clean up
81b27be
test
b9896f2
Merge branch 'apache:main' into leaf_sorter
weiwang19 117d2e4
gradlew check fix
f0b978f
code reivew changes
d5f4b29
clean up
ba4b9b0
ref guide
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
25 changes: 25 additions & 0 deletions
25
solr/core/src/java/org/apache/solr/update/LeafSorterSupplier.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,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.solr.update; | ||
|
||
import java.util.Comparator; | ||
import org.apache.lucene.index.LeafReader; | ||
|
||
public interface LeafSorterSupplier { | ||
Comparator<LeafReader> getLeafSorter(); | ||
} |
27 changes: 27 additions & 0 deletions
27
solr/core/src/java/org/apache/solr/update/SegmentSort.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,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.solr.update; | ||
|
||
public enum SegmentSort { | ||
/** No segment sort */ | ||
NONE, | ||
/** Sort leaf reader by segment creation time ascending order */ | ||
TIME_ASC, | ||
/** Sort leaf reader by segment creation time descending order */ | ||
TIME_DESC | ||
} |
78 changes: 78 additions & 0 deletions
78
solr/core/src/java/org/apache/solr/update/SegmentTimeLeafSorterSupplier.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,78 @@ | ||
/* | ||
* 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.solr.update; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
import java.util.Comparator; | ||
import org.apache.lucene.index.LeafReader; | ||
import org.apache.lucene.index.SegmentReader; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
final class SegmentTimeLeafSorterSupplier implements LeafSorterSupplier { | ||
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); | ||
private static final String TIME_FIELD = "timestamp"; | ||
private static final SegmentSort DEFAULT_SORT_OPTIONS = SegmentSort.NONE; | ||
|
||
private SegmentSort sortOptions; | ||
private Comparator<LeafReader> leafSorter; | ||
|
||
public SegmentTimeLeafSorterSupplier() { | ||
this(DEFAULT_SORT_OPTIONS); | ||
} | ||
|
||
public SegmentTimeLeafSorterSupplier(SegmentSort sortOptions) { | ||
this.sortOptions = sortOptions; | ||
} | ||
|
||
@Override | ||
public Comparator<LeafReader> getLeafSorter() { | ||
if (leafSorter == null) { | ||
if (SegmentSort.NONE == sortOptions) { | ||
return null; | ||
} | ||
boolean ascSort = SegmentSort.TIME_ASC == sortOptions; | ||
long missingValue = ascSort ? Long.MAX_VALUE : Long.MIN_VALUE; | ||
leafSorter = | ||
Comparator.comparingLong( | ||
r -> { | ||
try { | ||
return Long.parseLong( | ||
((SegmentReader) r).getSegmentInfo().info.getDiagnostics().get(TIME_FIELD)); | ||
} catch (Exception e) { | ||
log.error("Error getting time stamp for SegmentReader", e); | ||
return missingValue; | ||
} | ||
}); | ||
return ascSort ? leafSorter : leafSorter.reversed(); | ||
} | ||
; | ||
return leafSorter; | ||
} | ||
|
||
public SegmentSort getSortOptions() { | ||
return sortOptions; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuilder sb = new StringBuilder(50); | ||
sb.append("SegmentTimeLeafSorter{").append(sortOptions).append('}'); | ||
return sb.toString(); | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
solr/core/src/test-files/solr/collection1/conf/solrconfig-segmentsort.xml
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,29 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<!-- | ||
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. | ||
--> | ||
|
||
<config> | ||
<luceneMatchVersion>${tests.luceneMatchVersion:LATEST}</luceneMatchVersion> | ||
<directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.RAMDirectoryFactory}"/> | ||
<schemaFactory class="ClassicIndexSchemaFactory"/> | ||
|
||
<indexConfig> | ||
<segmentSort>TIME_DESC</segmentSort> | ||
</indexConfig> | ||
|
||
</config> |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use of the diagnostics here seems very specialised and potentially fragile. Leaf sorting is "between segment sorting" and we also have index sorting i.e. "within segment sorting" -- I wonder if there might be enough commonality to generalise. Will add more detailed scribbles on the https://issues.apache.org/jira/browse/SOLR-17310 ticket itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
convenience link: https://issues.apache.org/jira/browse/SOLR-17310?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17854761#comment-17854761
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have been checking the available sources but currently the timestamp is only in the segment info diagnostics.