sivakumar-mahalingam opened a new issue, #4395:
URL: https://github.com/apache/amoro/issues/4395
### What happened?
The AMS REST endpoints for manually creating or scaling out an optimizer
currently accept `parallelism` values of `0` or negative numbers.
Both `OptimizerController#createOptimizer` and
`OptimizerGroupController#scaleOutOptimizer` pass the supplied value directly
to `Resource.Builder#setThreadCount()` without validating that the parallelism
is positive.
For example:
```java
int parallelism = Integer.parseInt(map.get("parallelism").toString());
Resource resource =
new Resource.Builder(
resourceGroup.getContainer(),
resourceGroup.getName(),
ResourceType.OPTIMIZER)
.setProperties(resourceGroup.getProperties())
.setThreadCount(parallelism)
.build();
```
The optimizer later uses the configured execution parallelism to create its
executor array:
```java
this.executors =
new OptimizerExecutor[config.getExecutionParallel()];
```
As a result:
- `parallelism = 0` can create an optimizer resource with no executor
threads.
- A negative parallelism can eventually result in an invalid executor array
size or fail further downstream instead of being rejected at the API boundary.
An individual optimizer instance should have at least one executor thread.
This is also consistent with the dynamic-allocation configuration, where
`dynamic-allocation.executor-parallelism` is required to be at least `1`.
### Affects Versions
master
### What table formats are you seeing the problem on?
_No response_
### What engines are you seeing the problem on?
AMS, Optimizer
### How to reproduce
With an existing optimizer group, call either optimizer creation endpoint
with a non-positive parallelism.
For example:
```json
{
"optimizerGroup": "<optimizer-group>",
"parallelism": 0
}
```
for:
```text
POST /api/ams/v1/optimize/optimizers
```
or:
```json
{
"parallelism": 0
}
```
for:
```text
POST /api/ams/v1/optimize/optimizerGroups/<optimizer-group>/optimizers
```
The request is currently allowed to proceed to resource creation.
Expected behavior:
The request should be rejected as a bad request when:
```text
parallelism <= 0
```
before requesting or creating the optimizer resource.
### Relevant log output
```shell
```
### Anything else
The validation should apply to both manual optimizer creation paths:
- `OptimizerController#createOptimizer`
- `OptimizerGroupController#scaleOutOptimizer`
Tests can cover both zero and negative values and verify that invalid
requests are rejected before resource creation.
### Are you willing to submit a PR?
- [x] Yes I am willing to submit a PR!
### Code of Conduct
- [x] I agree to follow this project's Code of Conduct
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]