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

[BugFix] Make cpu_weight always store positive default value (backport #51005) #51008

Merged
merged 2 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions fe/fe-core/src/main/java/com/starrocks/catalog/ResourceGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public ColumnMeta(Column column, BiFunction<ResourceGroup, ResourceGroupClassifi
(rg, classifier) -> "" + rg.getId()),
new ColumnMeta(
new Column(CPU_WEIGHT, ScalarType.createVarchar(200)),
(rg, classifier) -> "" + rg.getCpuWeight()),
(rg, classifier) -> "" + rg.geNormalizedCpuWeight()),
new ColumnMeta(
new Column(EXCLUSIVE_CPU_CORES, ScalarType.createVarchar(200)),
(rg, classifier) -> "" + rg.getNormalizedExclusiveCpuCores()),
Expand Down Expand Up @@ -264,18 +264,35 @@ public TWorkGroup toThrift() {
return twg;
}

public Integer getCpuWeight() {
public Integer getRawCpuWeight() {
return cpuWeight;
}

public void setCpuWeight(int cpuWeight) {
this.cpuWeight = cpuWeight;
}

public int geNormalizedCpuWeight() {
if (exclusiveCpuCores != null && exclusiveCpuCores > 0) {
return 0;
}
return cpuWeight;
}

/**
* The old version considers cpu_weight as a positive integer, but now it can be non-positive.
* To be compatible with the old version, if cpu_weight is non-positive, it is stored as 1.
* And use geNormalizedCpuWeight() to get the normalized value when using cpu_weight.
*/
public void normalizeCpuWeight() {
if (cpuWeight == null || cpuWeight <= 0) {
cpuWeight = 1;
}
}

public Integer getExclusiveCpuCores() {
return exclusiveCpuCores;
}

public int getNormalizedExclusiveCpuCores() {
if (exclusiveCpuCores != null && exclusiveCpuCores > 0) {
return exclusiveCpuCores;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ public void createResourceGroup(CreateResourceGroupStmt stmt) throws DdlExceptio
dropResourceGroupUnlocked(wg.getName());
}

if (wg.getCpuWeight() == null) {
wg.setCpuWeight(0);
}
wg.normalizeCpuWeight();

if (ResourceGroup.DEFAULT_RESOURCE_GROUP_NAME.equals(wg.getName())) {
wg.setId(ResourceGroup.DEFAULT_WG_ID);
Expand Down Expand Up @@ -367,9 +365,9 @@ public void alterResourceGroup(AlterResourceGroupStmt stmt) throws DdlException
} else if (cmd instanceof AlterResourceGroupStmt.AlterProperties) {
ResourceGroup changedProperties = stmt.getChangedProperties();

Integer cpuWeight = changedProperties.getCpuWeight();
Integer cpuWeight = changedProperties.getRawCpuWeight();
if (cpuWeight == null) {
cpuWeight = wg.getCpuWeight();
cpuWeight = wg.geNormalizedCpuWeight();
}
Integer exclusiveCpuCores = changedProperties.getExclusiveCpuCores();
if (exclusiveCpuCores == null) {
Expand All @@ -394,6 +392,7 @@ public void alterResourceGroup(AlterResourceGroupStmt stmt) throws DdlException
if (cpuWeight != null) {
wg.setCpuWeight(cpuWeight);
}
wg.normalizeCpuWeight();

if (exclusiveCpuCores != null) {
sumExclusiveCpuCores -= wg.getNormalizedExclusiveCpuCores();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void analyze() {
if (changedProperties.getResourceGroupType() != null) {
throw new SemanticException("type of ResourceGroup is immutable");
}
if (changedProperties.getCpuWeight() == null &&
if (changedProperties.getRawCpuWeight() == null &&
changedProperties.getExclusiveCpuCores() == null &&
changedProperties.getMemLimit() == null &&
changedProperties.getConcurrencyLimit() == null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void analyze() throws SemanticException {
throw new SemanticException(SHORT_QUERY_SET_EXCLUSIVE_CPU_CORES_ERR_MSG);
}

ResourceGroup.validateCpuParameters(resourceGroup.getCpuWeight(), resourceGroup.getExclusiveCpuCores());
ResourceGroup.validateCpuParameters(resourceGroup.getRawCpuWeight(), resourceGroup.getExclusiveCpuCores());

if (resourceGroup.getMemLimit() == null) {
throw new SemanticException("property 'mem_limit' is absent");
Expand Down
Loading