Skip to content

[Improvement]: NPE when releasing optimizer due to non-atomic deleteResource + deleteOptimizer #4139

@seoyoniee

Description

@seoyoniee

Search before asking

  • I have searched in the issues and found no similar issues.

What would you like to be improved?

When releasing an optimizer via DELETE /api/ams/v1/optimize/optimizers/{jobId}, a NullPointerException is thrown if the resource table entry is missing.

Root cause

deleteResource and deleteOptimizer are executed as two separate DB operations without a transaction:

optimizerManager.deleteResource(resourceId);                           // step 1
optimizerManager.deleteOptimizer(resource.getGroupName(), resourceId); // step 2

If step 1 succeeds but step 2 fails, the resource row is deleted while the optimizer row remains. On the next release attempt, getResource() returns null and the following line throws NPE:

Resource resource = optimizerManager.getResource(resourceId); // null
resource.getProperties().putAll(...);                         // NPE

How should we improve?

Both operations should be executed atomically in a single transaction to prevent inconsistent state. If resource is already missing due to a previous partial failure, the release should handle it gracefully using OptimizerInstance fields instead of failing with NPE.

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Subtasks

No response

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions