Skip to content
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

check and warn for invalid partition weight #1033

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bohhyang
Copy link
Contributor

Summary

See context in container PR. Note that this change will warn invalid weights set dynamically thru ZookeeperAnnouncerJmx as well.

Test Done

See container PR.

Comment on lines +827 to +845
private void validatePartitionData(Map<Integer, PartitionData> partitionData) {
for (Map.Entry<Integer, PartitionData> entry : partitionData.entrySet()) {
double weight = entry.getValue().getWeight();
// check max weight
if (_maxWeight != null && weight > _maxWeight) {
_log.warn("", new IllegalArgumentException(String.format("[ACTION NEEDED] Weight %f in Partition %d is greater"
+ " than the max weight allowed: %d. Please correct the weight. It will be force-capped to the max weight "
+ "in the future.", weight, entry.getKey(), _maxWeight)));
// TODO: throw exception or cap weight to max weight
}

// check decimal places
if (BigDecimal.valueOf(weight).scale() > 2) {
_log.warn("", new IllegalArgumentException(String.format("Weight %f in Partition %d has more than 2 decimal "
+ "places. It will be rounded to 2 decimal places in the future.", weight, entry.getKey())));
// TODO: round weight to 2 decimal places.
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private void validatePartitionData(Map<Integer, PartitionData> partitionData) {
for (Map.Entry<Integer, PartitionData> entry : partitionData.entrySet()) {
double weight = entry.getValue().getWeight();
// check max weight
if (_maxWeight != null && weight > _maxWeight) {
_log.warn("", new IllegalArgumentException(String.format("[ACTION NEEDED] Weight %f in Partition %d is greater"
+ " than the max weight allowed: %d. Please correct the weight. It will be force-capped to the max weight "
+ "in the future.", weight, entry.getKey(), _maxWeight)));
// TODO: throw exception or cap weight to max weight
}
// check decimal places
if (BigDecimal.valueOf(weight).scale() > 2) {
_log.warn("", new IllegalArgumentException(String.format("Weight %f in Partition %d has more than 2 decimal "
+ "places. It will be rounded to 2 decimal places in the future.", weight, entry.getKey())));
// TODO: round weight to 2 decimal places.
}
}
}
private void validatePartitionData(Map<Integer, PartitionData> partitionData) {
partitionData.forEach((partitionId, data) -> {
final double weight = data.getWeight();
// check max weight
if (_maxWeight != null && weight > _maxWeight) {
_log.warn("", new IllegalArgumentException(String.format("[ACTION NEEDED] Weight %f in Partition %d is greater"
+ " than the max weight allowed: %d. Please correct the weight. It will be force-capped to the max weight "
+ "in the future.", weight, partitionId, _maxWeight)));
// TODO: throw exception or cap weight to max weight
}
// check decimal places
if (BigDecimal.valueOf(weight).scale() > 2) {
_log.warn("", new IllegalArgumentException(String.format("Weight %f in Partition %d has more than 2 decimal "
+ "places. It will be rounded to 2 decimal places in the future.", weight, partitionId)));
// TODO: round weight to 2 decimal places.
}
});
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants