-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize the SchedulingPolicy logic, and implement a plugin-based fra…
…mework for the sorter of the policy
- Loading branch information
张文领
committed
Jan 13, 2025
1 parent
0cc0529
commit e8ca237
Showing
5 changed files
with
199 additions
and
34 deletions.
There are no files selected for viewing
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
50 changes: 50 additions & 0 deletions
50
amoro-ams/src/main/java/org/apache/amoro/server/optimizing/sorter/BalancedSorter.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,50 @@ | ||
/* | ||
* 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.amoro.server.optimizing.sorter; | ||
|
||
import org.apache.amoro.server.table.TableRuntime; | ||
|
||
import java.util.Comparator; | ||
|
||
public class BalancedSorter implements SorterFactory { | ||
|
||
private static final String IDENTIFIER = "balanced"; | ||
|
||
@Override | ||
public String getIdentifier() { | ||
return IDENTIFIER; | ||
} | ||
|
||
@Override | ||
public Comparator<TableRuntime> createComparator() { | ||
return new Comparator<TableRuntime>() { | ||
@Override | ||
public int compare(TableRuntime one, TableRuntime another) { | ||
return Long.compare( | ||
Math.max( | ||
one.getLastFullOptimizingTime(), | ||
Math.max(one.getLastMinorOptimizingTime(), one.getLastMajorOptimizingTime())), | ||
Math.max( | ||
another.getLastFullOptimizingTime(), | ||
Math.max( | ||
another.getLastMinorOptimizingTime(), another.getLastMajorOptimizingTime()))); | ||
} | ||
}; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
amoro-ams/src/main/java/org/apache/amoro/server/optimizing/sorter/QuotaOccupySorter.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,48 @@ | ||
/* | ||
* 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.amoro.server.optimizing.sorter; | ||
|
||
import org.apache.amoro.server.table.TableRuntime; | ||
import org.apache.amoro.shade.guava32.com.google.common.collect.Maps; | ||
|
||
import java.util.Comparator; | ||
import java.util.Map; | ||
|
||
public class QuotaOccupySorter implements SorterFactory { | ||
|
||
public static final String IDENTIFIER = "quota"; | ||
|
||
@Override | ||
public String getIdentifier() { | ||
return IDENTIFIER; | ||
} | ||
|
||
@Override | ||
public Comparator<TableRuntime> createComparator() { | ||
final Map<TableRuntime, Double> tableWeightMap = Maps.newHashMap(); | ||
return new Comparator<TableRuntime>() { | ||
@Override | ||
public int compare(TableRuntime one, TableRuntime another) { | ||
return Double.compare( | ||
tableWeightMap.computeIfAbsent(one, TableRuntime::calculateQuotaOccupy), | ||
tableWeightMap.computeIfAbsent(another, TableRuntime::calculateQuotaOccupy)); | ||
} | ||
}; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
amoro-ams/src/main/java/org/apache/amoro/server/optimizing/sorter/SorterFactory.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,48 @@ | ||
/* | ||
* 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.amoro.server.optimizing.sorter; | ||
|
||
import org.apache.amoro.server.optimizing.SchedulingPolicy; | ||
|
||
import java.util.Comparator; | ||
|
||
/** | ||
* A factory for sorter. Sorter instantiates a comparator, which is automatically loaded by the | ||
* {@link SchedulingPolicy} as a plugin, as long as the sorter is constructed and the {@link | ||
* /resources/META-INF/services/org.apache.amoro.server.optimizing.sorter.SorterFactory} file | ||
* contains the full qualified class name for the sorter. The comparator sorts the tableRuntimes | ||
* based on the parameters of each tableRuntime in the input tableRuntimeList, and determines the | ||
* scheduling priority for optimization of each tableRuntime. | ||
*/ | ||
public interface SorterFactory { | ||
|
||
/** | ||
* Returns a globally unique identifier for the sorter instance, such as Balanced、balanced and | ||
* BALANCED represent the different sorter instance. The {@link SchedulingPolicy} will check the | ||
* values of {@link SchedulingPolicy#policyName} and {@link SorterFactory#getIdentifier} to decide | ||
* which sorter instance to use. If sorter instances sorterA and sorterB have the same identifier | ||
* id1, the {@link SchedulingPolicy} loads sorter instances in the order of their loading, first | ||
* loading sorterA, then sorterB. Ultimately, sorterB will replace sorterA as the final sorter | ||
* instance associated with id1, which is stored in {@link SchedulingPolicy#sorterFactoryCache}. | ||
*/ | ||
String getIdentifier(); | ||
|
||
/** Create a comparator for sorter. */ | ||
Comparator createComparator(); | ||
} |
20 changes: 20 additions & 0 deletions
20
.../main/resources/META-INF/services/org.apache.amoro.server.optimizing.sorter.SorterFactory
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,20 @@ | ||
# | ||
# 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. | ||
# | ||
|
||
org.apache.amoro.server.optimizing.sorter.QuotaOccupySorter | ||
org.apache.amoro.server.optimizing.sorter.BalancedSorter |