Skip to content

Enhance service semaphore to support parameter-based locking#1166

Draft
dixitdeepak wants to merge 1 commit intoapache:trunkfrom
dixitdeepak:OFBIZ-13395-semaphore-parameter-name
Draft

Enhance service semaphore to support parameter-based locking#1166
dixitdeepak wants to merge 1 commit intoapache:trunkfrom
dixitdeepak:OFBIZ-13395-semaphore-parameter-name

Conversation

@dixitdeepak
Copy link
Copy Markdown
Contributor

@dixitdeepak dixitdeepak commented May 6, 2026

Enhance service semaphore to support parameter-based locking (OFBIZ-13395)

  • Added semaphore-parameter-name attribute to service definitions
  • Extended ServiceSemaphore to include parameterValue
  • Updated locking logic to use (serviceName, parameterValue) scope
  • Modified dispatcher to pass parameter values from service requests
  • Allows concurrent execution of the same service for different parameter values
  • Enables finer-grained concurrency control compared to service-level locking

Please use the following SQL to update the service_semaphore table schema for parameter-based locking support:

ALTER TABLE service_semaphore DROP PRIMARY KEY;

ALTER TABLE service_semaphore
ADD PRIMARY KEY (service_name, parameter_value);

…3395)

- Added semaphore-parameter-name attribute to service definitions
- Extended ServiceSemaphore to include parameterValue
- Updated locking logic to use (serviceName, parameterValue) scope
- Modified dispatcher to pass parameter values from service requests
- Allows concurrent execution of the same service for different parameter values
- Enables finer-grained concurrency control compared to service-level locking
@dixitdeepak dixitdeepak force-pushed the OFBIZ-13395-semaphore-parameter-name branch from 4a51f9d to fa80d7a Compare May 6, 2026 07:35
@jacopoc
Copy link
Copy Markdown
Contributor

jacopoc commented May 7, 2026

@dixitdeepak , your implementation looks correct and straightforward. Although I haven’t tested it, it should work without causing regressions.

That said, while I can see it being useful for specific use cases (for example, when locking based on the value of a single parameter), I have some doubts about whether it is a good fit for more general scenarios.

A few more specific remarks:

  • Specifying the parameter name through the semaphore-parameter-name attribute may introduce inconsistencies (for example, the provided name may not match any valid service parameter). Also, it should not be possible to specify an optional parameter.
  • Restricting this to a single parameter feels somewhat arbitrary and does not seem well suited to more general use cases.

For these reasons, instead of semaphore-parameter-name, I think it would be better to add an attribute on the service parameter element itself to indicate whether that parameter should be included in the lock.

Regarding the data model, I am not sure it is worth the added complexity of introducing a separate entity to store multiple attribute values flexibly. That approach could also make the locking process trickier, less robust, and less efficient. One possible alternative would be to hash all relevant parameter values, append the result to the service name, and keep the existing single-field primary key.

In its current form, I still think your patch could be useful for others with similar use cases. However, in my opinion, it may be better to keep it in a Jira ticket or pull request for reference rather than merging it directly into the codebase.

@dixitdeepak
Copy link
Copy Markdown
Contributor Author

Thanks for the review @jacopoc

Yes, the current implementation in the PR supports locking based on a single parameter only. It would definitely be useful to extend this capability to support multiple service input parameters as part of the semaphore key.

I like the idea of supporting multi-attribute semaphores. However, I am still in favor of adding a new field to the ServiceSemaphore entity to store the parameter value(s). The value could be stored using a pattern similar to how EntityAuditLog.pkCombinedValueText stores combined PK values.

This would keep the implementation relatively straightforward while still allowing support for composite parameter-based locking.

I am moving this PR to draft for now.

@dixitdeepak dixitdeepak marked this pull request as draft May 8, 2026 04:30
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