-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Making optimal usage of multiple segment cache locations #8038
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
39 commits
Select commit
Hold shift + click to select a range
a619112
#7641 - Changing segment distribution algorithm to distribute segment…
t-sashidhar f23dac1
Merge branch 'master' into s3_firehose
t-sashidhar 08b6256
Fixing indentation
t-sashidhar c2bd858
WIP
t-sashidhar d88c614
Merge branch 'master' into s3_firehose
t-sashidhar f9fa66f
Adding interface for location strategy selection, least bytes used st…
t-sashidhar e2efc73
Resolving merge conflicts. Adding comparator for sorting locations by…
t-sashidhar fd0c6d6
fixing code style
t-sashidhar 449e929
Fixing test
t-sashidhar 33db506
Adding a method visible only for testing, fixing tests
t-sashidhar 2712aeb
1. Changing the method contract to return an iterator of locations in…
t-sashidhar c1e8597
fixing the conditional statement
t-sashidhar b999dba
Merge branch 'master' into s3_firehose
t-sashidhar 66f00ee
Added testSegmentDistributionUsingLeastBytesUsedStrategy, fixed testS…
t-sashidhar d60ab71
to trigger CI build
t-sashidhar f60e0c8
Add documentation for the selection strategy configuration
t-sashidhar 53c56bd
to re trigger CI build
t-sashidhar b985553
Merge branch 'master' into s3_firehose
t-sashidhar da21a3c
Merge branch 'master' of https://github.com/apache/incubator-druid in…
t-sashidhar e930cd7
updated docs as per review comments, made LeastBytesUsedStorageLocati…
t-sashidhar d7e0980
merging changes from master
t-sashidhar d66c25d
In checkLocationConfigForNull method, using getLocations() to check f…
t-sashidhar e309b68
Merge branch 'master' into s3_firehose
t-sashidhar 65dedb2
Implementing review comments. Added tests for StorageLocationSelector…
t-sashidhar 4ee0868
Merge branch 'master' into s3_firehose
t-sashidhar 039683a
Checkstyle fixes
t-sashidhar 25af782
Adding java doc comments for StorageLocationSelectorStrategy interface
t-sashidhar f03b71c
checkstyle
t-sashidhar 5b9ab18
empty commit to retrigger build
t-sashidhar 78dae2e
Empty commit
t-sashidhar 1b81d48
Adding suppressions for words leastBytesUsed and roundRobin of ../doc…
t-sashidhar 7c72d11
Impl review comments including updating docs as suggested
t-sashidhar e4ae066
Merge branch 'master' into s3_firehose
t-sashidhar 4cac096
Removing checkLocationConfigForNull(), @NotEmpty annotation serves th…
t-sashidhar d0cffef
Round robin iterator to keep track of the no. of iterations, impl rev…
t-sashidhar 844d55d
Fixing the round robin iterator
t-sashidhar 0c35182
Removed numLocationsToTry, updated java docs
t-sashidhar dc2bf9f
changing property attribute value from tier to type
t-sashidhar 55bc6e8
Fixing assert messages
t-sashidhar 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
57 changes: 57 additions & 0 deletions
57
.../java/org/apache/druid/segment/loading/LeastBytesUsedStorageLocationSelectorStrategy.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,57 @@ | ||
| /* | ||
| * 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.druid.segment.loading; | ||
|
|
||
| import com.google.common.collect.Ordering; | ||
|
|
||
| import java.util.Comparator; | ||
| import java.util.Iterator; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * A {@link StorageLocation} selector strategy that selects a segment cache location that is least filled each time | ||
| * among the available storage locations. | ||
| */ | ||
| public class LeastBytesUsedStorageLocationSelectorStrategy implements StorageLocationSelectorStrategy | ||
| { | ||
| private static final Ordering<StorageLocation> ORDERING = Ordering.from(Comparator | ||
| .comparingLong(StorageLocation::currSizeBytes)); | ||
|
|
||
| private List<StorageLocation> storageLocations; | ||
|
|
||
| public LeastBytesUsedStorageLocationSelectorStrategy(List<StorageLocation> storageLocations) | ||
| { | ||
| this.storageLocations = storageLocations; | ||
| } | ||
|
|
||
| @Override | ||
| public Iterator<StorageLocation> getLocations() | ||
| { | ||
| return ORDERING.sortedCopy(this.storageLocations).iterator(); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() | ||
| { | ||
| return "LeastBytesUsedStorageLocationSelectorStrategy{" + | ||
| "storageLocations=" + storageLocations + | ||
| '}'; | ||
| } | ||
| } |
72 changes: 72 additions & 0 deletions
72
...main/java/org/apache/druid/segment/loading/RoundRobinStorageLocationSelectorStrategy.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,72 @@ | ||
| /* | ||
| * 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.druid.segment.loading; | ||
|
|
||
| import java.util.Iterator; | ||
| import java.util.List; | ||
| import java.util.NoSuchElementException; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
| /** | ||
| * A {@link StorageLocation} selector strategy that selects a segment cache location in a round-robin fashion each time | ||
| * among the available storage locations. When {@link Iterator#next()} on iterator retuned by | ||
| * {@link RoundRobinStorageLocationSelectorStrategy#getLocations()} is called the locations are returned in a round | ||
| * robin fashion even when multiple threads are in use. | ||
| */ | ||
| public class RoundRobinStorageLocationSelectorStrategy implements StorageLocationSelectorStrategy | ||
| { | ||
|
|
||
| private final List<StorageLocation> storageLocations; | ||
| private final AtomicInteger startIndex = new AtomicInteger(0); | ||
|
|
||
| public RoundRobinStorageLocationSelectorStrategy(List<StorageLocation> storageLocations) | ||
| { | ||
| this.storageLocations = storageLocations; | ||
| } | ||
|
|
||
| @Override | ||
| public Iterator<StorageLocation> getLocations() | ||
| { | ||
| return new Iterator<StorageLocation>() { | ||
|
|
||
| private final int numStorageLocations = storageLocations.size(); | ||
| private int remainingIterations = numStorageLocations; | ||
|
|
||
| @Override | ||
| public boolean hasNext() | ||
| { | ||
| return remainingIterations > 0; | ||
| } | ||
|
|
||
| @Override | ||
| public StorageLocation next() | ||
| { | ||
| if (!hasNext()) { | ||
| throw new NoSuchElementException(); | ||
| } | ||
| remainingIterations--; | ||
| final StorageLocation nextLocation = | ||
| storageLocations.get(startIndex.getAndUpdate(n -> (n + 1) % numStorageLocations)); | ||
| return nextLocation; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| } |
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
57 changes: 57 additions & 0 deletions
57
server/src/main/java/org/apache/druid/segment/loading/StorageLocationSelectorStrategy.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,57 @@ | ||
| /* | ||
| * 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.druid.segment.loading; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonSubTypes; | ||
| import com.fasterxml.jackson.annotation.JsonTypeInfo; | ||
| import org.apache.druid.timeline.DataSegment; | ||
|
|
||
| import java.util.Iterator; | ||
|
|
||
| /** | ||
| * This interface describes the storage location selection strategy which is responsible for ordering the | ||
| * available multiple {@link StorageLocation}s for segment distribution. | ||
| * | ||
| * Only a snapshot of the locations is returned here. The implemntations currently do not handle all kinds of | ||
| * concurrency issues and accesses to the underlying storage. Please see | ||
| * https://github.com/apache/incubator-druid/pull/8038#discussion_r325520829 of PR https://github | ||
| * .com/apache/incubator-druid/pull/8038 for more details. | ||
| */ | ||
| @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", defaultImpl = | ||
| LeastBytesUsedStorageLocationSelectorStrategy.class) | ||
| @JsonSubTypes(value = { | ||
| @JsonSubTypes.Type(name = "leastBytesUsed", value = LeastBytesUsedStorageLocationSelectorStrategy.class), | ||
| @JsonSubTypes.Type(name = "roundRobin", value = RoundRobinStorageLocationSelectorStrategy.class) | ||
| }) | ||
| public interface StorageLocationSelectorStrategy | ||
| { | ||
| /** | ||
| * Finds the best ordering of the {@link StorageLocation}s to load a {@link DataSegment} according to | ||
| * the location selector strategy. This method returns an iterator instead of a single best location. The | ||
| * caller is responsible for iterating over the locations and calling {@link StorageLocation#reserve} | ||
| * method. This is because a single location may be problematic like failed disk or might become unwritable for | ||
| * whatever reasons. | ||
| * | ||
| * This method can be called by different threads and so should be thread-safe. | ||
| * | ||
| * @return An iterator of {@link StorageLocation}s from which the callers can iterate and pick a location. | ||
| */ | ||
| Iterator<StorageLocation> getLocations(); | ||
| } | ||
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.
I almost forgot. Would you please add to javadoc that this method can be called by different threads and so should be thread-safe?
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.
Updated javadoc.