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

Control the id generation for BpmProcessInstance #1115

Open
brunobuzzi opened this issue Feb 26, 2020 · 3 comments
Open

Control the id generation for BpmProcessInstance #1115

brunobuzzi opened this issue Feb 26, 2020 · 3 comments

Comments

@brunobuzzi
Copy link
Owner

brunobuzzi commented Feb 26, 2020

When a new BpmProcessInstance is created control if the id already exist.
The probability of an id clash is pretty high with 100.000 instances with ids up to 4294967295 (32 bit number).
Note:
theorically it could be a clash of [id] in collection IF for the same [BpmProcessDefinition] the random generation answer the same number [id := Lag1MwcRandom new integer].
Lag1MwcRandom new integer - answer a nonnegative 32bit integer. (max 4.294.967.295)
The probability of a clash depends on the number of [BpmProcessInstances]:
It can be calculated with (it take to much time to calculate):

|max instances p m |
max := 4294967295.
instances := 100000.
m := 1.
1 to: instances - 1 do: [:k | m := m * (1 - (k/max))].
p := 1 - m.
p asFloat.

A more efficient way is:

| numbers instances clashes |
numbers := Set new.
instances := 900000.
1 to: instances do: [:each | numbers add: Lag1MwcRandom new integer  ].
clashes := instances - numbers size.
clashes

With 100000 is pretty possible to have a clash --> a new issue to control the clash of ids should be created.

@brunobuzzi
Copy link
Owner Author

brunobuzzi pushed a commit that referenced this issue Feb 27, 2020
@brunobuzzi brunobuzzi reopened this Jun 12, 2020
@brunobuzzi
Copy link
Owner Author

brunobuzzi commented Jun 12, 2020

The issue is partially fixed. But there is still a problem in:

BpmProcessDefinition>>addProcessInstance:
   processInstancesSet add: aBpmProcessInstance.
   ^processInstances at: aBpmProcessInstance id put: aBpmProcessInstance

If two different Gems (transactions) at the same time are adding a process it could be possible that both transactions generate the same id (let's call it clashID) and for both transactions processInstances at: classID is a free slot.

This is a border case because both process must have identical process definition and both transaction must overlap during the commit. In practical terms is highly unlikely but theorically possible. It will depend on how many process are been created per millisecond.

@brunobuzzi
Copy link
Owner Author

brunobuzzi commented Jun 12, 2020

It seems if processInstances collection is an RC collection then replay is done and the entry will be overwritten unless the transaction that has the commit conflict do an abort.
Research on Seaside Web and Seaside REST what is done when a commit conflict with RC collection arise.

brunobuzzi added a commit that referenced this issue Jun 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant