Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.9k
[fix](auto bucket)Fix auto bucket calc bucketnum err when partition size is invalid#52801
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6 fe/fe-common/src/main/java/org/apache/doris/common/Config.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
4 changes: 2 additions & 2 deletions
4 fe/fe-core/src/main/java/org/apache/doris/catalog/MaterializedIndex.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
4 changes: 2 additions & 2 deletions
4 fe/fe-core/src/main/java/org/apache/doris/catalog/MetadataViewer.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
2 changes: 1 addition & 1 deletion
2 fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.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
14 changes: 11 additions & 3 deletions
14 fe/fe-core/src/main/java/org/apache/doris/catalog/Partition.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
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
3 changes: 2 additions & 1 deletion
3 fe/fe-core/src/main/java/org/apache/doris/clone/ColocateTableCheckerAndBalancer.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
116 changes: 83 additions & 33 deletions
116 fe/fe-core/src/main/java/org/apache/doris/clone/DynamicPartitionScheduler.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 |
|---|---|---|
| @@ -58,6 +58,7 @@ | ||
| import org.apache.doris.rpc.RpcException; | ||
| import org.apache.doris.thrift.TStorageMedium; | ||
| import com.google.common.base.Preconditions; | ||
| import com.google.common.base.Strings; | ||
| import com.google.common.collect.Lists; | ||
| import com.google.common.collect.Maps; | ||
| @@ -159,7 +160,7 @@ private Map<String, String> createDefaultRuntimeInfo() { | ||
| } | ||
| // exponential moving average | ||
| private static long ema(ArrayList<Long> history, int period) { | ||
| private static long ema(List<Long> history, int period) { | ||
| double alpha = 2.0 / (period + 1); | ||
| double ema = history.get(0); | ||
| for (int i = 1; i < history.size(); i++) { | ||
| @@ -168,7 +169,7 @@ private static long ema(ArrayList<Long> history, int period) { | ||
| return (long) ema; | ||
| } | ||
| private static long getNextPartitionSize(ArrayList<Long> historyPartitionsSize) { | ||
| private static long getNextPartitionSize(List<Long> historyPartitionsSize) { | ||
| if (historyPartitionsSize.size() < 2) { | ||
| return historyPartitionsSize.get(0); | ||
| } | ||
| @@ -191,65 +192,98 @@ private static long getNextPartitionSize(ArrayList<Long> historyPartitionsSize) | ||
| } | ||
| } | ||
| private static int getBucketsNum(DynamicPartitionProperty property, OlapTable table, | ||
| private static Pair<Integer, Integer> getBucketsNum(DynamicPartitionProperty property, OlapTable table, | ||
| String partitionName, String nowPartitionName, boolean executeFirstTime) { | ||
| // if execute first time, all partitions no contain data | ||
| if (!table.isAutoBucket() || executeFirstTime) { | ||
| return property.getBuckets(); | ||
| return Pair.of(property.getBuckets(), 0); | ||
| } | ||
| // auto bucket | ||
| // get all history partitions | ||
| RangePartitionInfo info = (RangePartitionInfo) (table.getPartitionInfo()); | ||
| List<Map.Entry<Long, PartitionItem>> idToItems = new ArrayList<>(info.getIdToItem(false).entrySet()); | ||
| idToItems.sort(Comparator.comparing(o -> ((RangePartitionItem) o.getValue()).getItems().upperEndpoint())); | ||
| List<Partition> partitions = idToItems.stream() | ||
| .map(entry -> table.getPartition(entry.getKey())) | ||
| .filter(partition -> partition != null && !partition.getName().equals(nowPartitionName)) | ||
| .collect(Collectors.toList()); | ||
| List<Long> visibleVersions = null; | ||
| List<Partition> partitions = getHistoricalPartitions(table, nowPartitionName); | ||
| List<Long> visibleVersions; | ||
| try { | ||
| visibleVersions = Partition.getVisibleVersions(partitions); | ||
| } catch (RpcException e) { | ||
| LOG.warn("autobucket use property's buckets get visible version fail, table: [{}-{}], " | ||
| LOG.warn("auto bucket use property's buckets get visible version fail, table: [{}-{}], " | ||
| + "partition: {}, buckets num: {}, exception: ", | ||
| table.getName(), table.getId(), partitionName, property.getBuckets(), e); | ||
| return property.getBuckets(); | ||
| return Pair.of(property.getBuckets(), 0); | ||
| } | ||
| List<Partition> hasDataPartitions = filterDataPartitions(partitions, visibleVersions); | ||
| if (hasDataPartitions.isEmpty()) { | ||
| return handleNoDataPartitions(table, partitionName, property.getBuckets()); | ||
| } | ||
| List<Partition> hasDataPartitions = Lists.newArrayList(); | ||
| return calculateBuckets(hasDataPartitions); | ||
| } | ||
| private static List<Partition> getHistoricalPartitions(OlapTable table, String nowPartitionName) { | ||
| RangePartitionInfo info = (RangePartitionInfo) (table.getPartitionInfo()); | ||
| List<Map.Entry<Long, PartitionItem>> idToItems = new ArrayList<>(info.getIdToItem(false).entrySet()); | ||
| idToItems.sort(Comparator.comparing(o -> ((RangePartitionItem) o.getValue()).getItems().upperEndpoint())); | ||
| return idToItems.stream() | ||
| .map(entry -> table.getPartition(entry.getKey())) | ||
| .filter(partition -> partition != null && !partition.getName().equals(nowPartitionName)) | ||
| .collect(Collectors.toList()); | ||
| } | ||
| private static List<Partition> filterDataPartitions(List<Partition> partitions, List<Long> visibleVersions) { | ||
| Preconditions.checkState(partitions.size() == visibleVersions.size(), | ||
| String.format("partitions size %d not eq visibleVersions size %d, impossible", | ||
| partitions.size(), visibleVersions.size())); | ||
| List<Partition> hasDataPartitions = new ArrayList<>(); | ||
| for (int i = 0; i < partitions.size(); i++) { | ||
| if (visibleVersions.get(i) >= 2) { | ||
deardeng marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| hasDataPartitions.add(partitions.get(i)); | ||
| } | ||
| } | ||
| return hasDataPartitions; | ||
| } | ||
| // no exist history partition data | ||
| if (hasDataPartitions.isEmpty()) { | ||
| LOG.info("autobucket use property's buckets due to all partitions no data, table: [{}-{}], " | ||
| + "partition: {}, buckets num: {}", | ||
| table.getName(), table.getId(), partitionName, property.getBuckets()); | ||
| return property.getBuckets(); | ||
| private static Pair<Integer, Integer> handleNoDataPartitions(OlapTable table, | ||
| String partitionName, int defaultBuckets) { | ||
| LOG.info("auto bucket use property's buckets due to all partitions no data, table: [{}-{}], " | ||
| + "partition: {}, buckets num: {}", table.getName(), table.getId(), partitionName, defaultBuckets); | ||
| return Pair.of(defaultBuckets, 0); | ||
| } | ||
| private static Pair<Integer, Integer> calculateBuckets(List<Partition> hasDataPartitions) { | ||
| List<Long> partitionSizeArray = new ArrayList<>(); | ||
| List<Long> sizeUnknownArray = new ArrayList<>(); | ||
| for (Partition hasDataPartition : hasDataPartitions) { | ||
| long partitionSize = hasDataPartition.getDataSizeExcludeEmptyReplica(true); | ||
| if (partitionSize == 0) { | ||
| sizeUnknownArray.add(partitionSize); | ||
| } else { | ||
| partitionSizeArray.add(partitionSize); | ||
| } | ||
| } | ||
| int size = hasDataPartitions.size(); | ||
| Preconditions.checkState(size > 0, "hasDataPartitions size must be greater than 0"); | ||
| int previousPartitionBucketsNum = hasDataPartitions.get(size - 1).getDistributionInfo().getBucketNum(); | ||
| if (hasDataPartitions.size() == sizeUnknownArray.size()) { | ||
| LOG.info("TabletStatMgr not synchronized partitions size yet, so use previous partition bucket num"); | ||
| return Pair.of(previousPartitionBucketsNum, previousPartitionBucketsNum); | ||
| } | ||
| ArrayList<Long> partitionSizeArray = hasDataPartitions.stream() | ||
| .map(partition -> partition.getAllDataSize(true)) | ||
| .collect(Collectors.toCollection(ArrayList::new)); | ||
| long estimatePartitionSize = getNextPartitionSize(partitionSizeArray); | ||
| // plus 5 for uncompressed data | ||
| long uncompressedPartitionSize = estimatePartitionSize * 5; | ||
| int bucketsNum = AutoBucketUtils.getBucketsNum(uncompressedPartitionSize, Config.autobucket_min_buckets); | ||
| LOG.info("autobucket calc with {} history partitions, table: [{}-{}], partition: {}, buckets num: {}, " | ||
| + " estimate partition size: {}, last partitions(partition name, local size, remote size): {}", | ||
| hasDataPartitions.size(), table.getName(), table.getId(), partitionName, bucketsNum, | ||
| estimatePartitionSize, | ||
| LOG.info("auto bucket calc with {} history partitions, {} history partitions size not sync size yet," | ||
| + " buckets num: {}, estimate partition size: {}, last partitions: {}", | ||
| hasDataPartitions.size(), sizeUnknownArray.size(), bucketsNum, estimatePartitionSize, | ||
| hasDataPartitions.stream() | ||
| .skip(Math.max(0, hasDataPartitions.size() - 7)) | ||
| .map(partition -> "(" + partition.getName() + ", " + partition.getDataSize(true) | ||
| + ", " + partition.getRemoteDataSize() + ")") | ||
| .collect(Collectors.toList())); | ||
| return bucketsNum; | ||
| return Pair.of(bucketsNum, previousPartitionBucketsNum); | ||
| } | ||
| private ArrayList<AddPartitionClause> getAddPartitionClause(Database db, OlapTable olapTable, | ||
| @@ -356,8 +390,13 @@ private ArrayList<AddPartitionClause> getAddPartitionClause(Database db, OlapTab | ||
| DistributionDesc distributionDesc = null; | ||
| DistributionInfo distributionInfo = olapTable.getDefaultDistributionInfo(); | ||
| int bucketsNum = getBucketsNum(dynamicPartitionProperty, olapTable, partitionName, | ||
| Pair<Integer, Integer> ret = getBucketsNum(dynamicPartitionProperty, olapTable, partitionName, | ||
| nowPartitionName, executeFirstTime); | ||
| int bucketsNum = ret.first; | ||
| int previousPartitionBucketsNum = ret.second; | ||
| if (olapTable.isAutoBucket()) { | ||
| checkAutoBucketCalcNumIsValid(bucketsNum, previousPartitionBucketsNum); | ||
| } | ||
| if (distributionInfo.getType() == DistributionInfo.DistributionInfoType.HASH) { | ||
| HashDistributionInfo hashDistributionInfo = (HashDistributionInfo) distributionInfo; | ||
| List<String> distColumnNames = new ArrayList<>(); | ||
| @@ -374,6 +413,17 @@ private ArrayList<AddPartitionClause> getAddPartitionClause(Database db, OlapTab | ||
| return addPartitionClauses; | ||
| } | ||
| private void checkAutoBucketCalcNumIsValid(int calcNum, int previousPartitionBucketsNum) { | ||
| // previousPartitionBucketsNum == 0, some abnormal case, ignore it | ||
| if (previousPartitionBucketsNum != 0 | ||
| && (calcNum > previousPartitionBucketsNum * (1 + Config.autobucket_out_of_bounds_percent_threshold)) | ||
| || (calcNum < previousPartitionBucketsNum * (1 - Config.autobucket_out_of_bounds_percent_threshold))) { | ||
| LOG.warn("auto bucket calc num may be err, plz check. " | ||
| + "calc bucket num {}, previous partition bucket num {}, percent {}", | ||
| calcNum, previousPartitionBucketsNum, Config.autobucket_out_of_bounds_percent_threshold); | ||
| } | ||
| } | ||
| /** | ||
| * If dynamic_partition.storage_medium is set to SSD, | ||
| * ignore hot_partition_num property and set to (SSD, 9999-12-31 23:59:59) | ||
6 changes: 3 additions & 3 deletions
6 fe/fe-core/src/main/java/org/apache/doris/cloud/CacheHotspotManager.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
2 changes: 1 addition & 1 deletion
2 fe/fe-core/src/main/java/org/apache/doris/common/proc/TabletHealthProcDir.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
2 changes: 1 addition & 1 deletion
2 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowDataCommand.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
2 changes: 1 addition & 1 deletion
2 fe/fe-core/src/test/java/org/apache/doris/catalog/CatalogTestUtil.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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.