Issue Details (XML | Word | Printable)

Key: OFBIZ-1636
Type: Bug Bug
Status: Open Open
Priority: Minor Minor
Assignee: Unassigned
Reporter: Si Chen
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
OFBiz

delegator.getNextSubSeqId does not guarantee primary key uniqueness

Created: 12/Feb/08 10:17 PM   Updated: Yesterday 10:43 PM
Return to search
Component/s: framework
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified


 Description  « Hide
The delegator.getNextSubSeqId method currently will look into the table for all rows which shared the same primary key values except the subsequence ID field and returned the next available subsequence ID field value. However, if another process came in to ask for the same subsequence ID value, it will give the same value back again. It does not guarantee primary key uniqueness.

For example, if you are reserving inventory for inventory item ID 10000, delegator.getNextSubSeqId might return the next inventoryItemSeqId of 10. If you are reserving inventory for many items on a large order, however, your transaction would not be closed until all the inventory reservations are completed. In the meantime, if another order came in and inventory has to be reserved against inventory item ID 10000 again, delegator.getNextSubSeqId will give inventoryItemSeqId of 10 again. When both transactions try to commit, one of them will inevitably run into a foreign key collision.

We can think of two possible solutions for this problem:

1. Make inventoryItemSeqId the primary key of InventoryItemDetail table, and use delegator.getNextSeqId and SequenceValueItem to generate its values. InventoryItemDetail was still have an inventoryItemId and be related to InventoryItem.

2. Create a cache for subsequence ID values. The key of the cache would be a Map of the primary key fields for InventoryItemDetail minus inventoryItemSeqId, and the value of the cache would be the maximum available inventoryItemSeqId. The cache would be set to timeout or clear, every 30 minutes or so, and during that time it would be able to tell delegator.getNextSubSeqId what the maximum available value would be based on both what's in the database and what other processes may have been assigned. This method is more complicated and not as sure, but it would still allow us to have subsequence IDs of 1, 2, 3, 4, etc.

If anyone has other suggestions, please let me know.



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
David E. Jones added a comment - 20/Feb/08 12:10 AM
This is a known bug with a fix already in place in the trunk. See InventoryService.xml line 287 for a comment on it. The fix is a bit of a kludge since it abandons the nice sub-sequence and uses a global sequence instead.

This fix is a variation on your #1, but doesn't change the primary key, which I don't think we want to right now and we may get a more reliable sub-sequence in the future.

It isn't a common case, but for now sub-sequenced entities that may be written to by more than one thread should use the global sequencing instead.

Unfortunately #2 is not a good solution as that would aggravate the problem with multiple app servers instead of helping it.

What is a good solution is a another question....


Si Chen added a comment - 20/Feb/08 08:15 PM
thanks for your feedback. I think the fix you suggested is a pretty good one and probably the best course for now.

Jacopo Cappellato added a comment - 07/Mar/08 08:54 AM
David has provided a workaround for this, so I've changed the priority from Critical to Minor.
Or we can just close the issue?

Jacques Le Roux added a comment - 26/Nov/09 10:43 PM
Should we not close this issue now (and maybe reopen a new one with clear goal "new sub-sequence solution")?