forked from apache/druid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve CostBalancerStrategy, deprecate cachingCost (apache#14484)
Changes to `cost` strategy: - In every `ServerHolder`, track the number of segments per datasource per interval - Perform cost computations for a given interval just once, and then multiply by a constant factor to account for the total segment count in that interval - Do not perform joint cost computations with segments that are outside the compute interval (± 45 days) for the segment being considered for move - Remove metrics `segment/cost/*` as they were coordinator killers! Turning on these metrics (by setting `emitBalancingStats` to true) has often caused the coordinator to be stuck for hours. Moreover, they are too complicated to decipher and do not provide any meaningful insight into a Druid cluster. - Add new simpler metrics `segment/balancer/compute/*` to track cost computation time, count and errors. Other changes: - Remove flaky test from `CostBalancerStrategyTest`. - Add tests to verify that computed cost has remained unchanged - Remove usages of mock `BalancerStrategy` from `LoadRuleTest`, `BalanceSegmentsTest` - Clean up `BalancerStrategy` interface
- Loading branch information
1 parent
165810a
commit ca3be43
Showing
28 changed files
with
515 additions
and
567 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
67 changes: 67 additions & 0 deletions
67
server/src/main/java/org/apache/druid/server/coordinator/SegmentCountsPerInterval.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,67 @@ | ||
/* | ||
* 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.server.coordinator; | ||
|
||
import it.unimi.dsi.fastutil.objects.Object2IntMap; | ||
import it.unimi.dsi.fastutil.objects.Object2IntMaps; | ||
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; | ||
import org.apache.druid.timeline.DataSegment; | ||
import org.joda.time.Interval; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Maintains a count of segments for each datasource and interval. | ||
*/ | ||
public class SegmentCountsPerInterval | ||
{ | ||
private final Map<String, Object2IntMap<Interval>> | ||
datasourceIntervalToSegmentCount = new HashMap<>(); | ||
private final Object2IntMap<Interval> intervalToTotalSegmentCount = new Object2IntOpenHashMap<>(); | ||
|
||
public void addSegment(DataSegment segment) | ||
{ | ||
updateCountInInterval(segment, 1); | ||
} | ||
|
||
public void removeSegment(DataSegment segment) | ||
{ | ||
updateCountInInterval(segment, -1); | ||
} | ||
|
||
public Object2IntMap<Interval> getIntervalToSegmentCount(String datasource) | ||
{ | ||
return datasourceIntervalToSegmentCount.getOrDefault(datasource, Object2IntMaps.emptyMap()); | ||
} | ||
|
||
public Object2IntMap<Interval> getIntervalToTotalSegmentCount() | ||
{ | ||
return intervalToTotalSegmentCount; | ||
} | ||
|
||
private void updateCountInInterval(DataSegment segment, int delta) | ||
{ | ||
intervalToTotalSegmentCount.mergeInt(segment.getInterval(), delta, Integer::sum); | ||
datasourceIntervalToSegmentCount | ||
.computeIfAbsent(segment.getDataSource(), ds -> new Object2IntOpenHashMap<>()) | ||
.mergeInt(segment.getInterval(), delta, Integer::sum); | ||
} | ||
} |
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.