c# - Gap-less sequence where multiple transactions with multiple tables are involved -
i have requirement (by law) gap-less numbers on different tables. ids can have holes in them not sequences.
this have either solve in c# code or in database (postgres, ms sql , oracle).
this problem:
start transaction 1 start transaction 2 insert row on table "portfolio" in transaction 1 next number in sequence column portfolio_sequence (1) insert row on table "document" in transaction 1 next number in sequence column document_sequence (1) insert row on table "portfolio" in transaction 2 next number in sequence column portfolio_sequence (2) insert row on table "document" in transaction 2 next number in sequence column document_sequence (2) problem occurred in transaction 1 rollback transaction 1 commit transaction 2
problem: gap in sequence both portfolio_sequence
, document_sequence
.
note simplified , there way more tables included in each of transactions.
how can deal this?
i have seen suggestions "lock" sequence until transaction either committed or rolled back, huge halt system when many tables involved , complex long transactions.
as have seemed conclude, gapless sequences not scale. either run risk of dropping values when rollback occurs, or have serialization point prevent multi-user, concurrent transaction system scaling. cannot have both.
my thought be, post processing action, every day, have process runs @ close of business, checks gaps, , renumbers needs renumbered?
one final thought: don't know requirement, but, know said "required law". well, ask yourself, did people before there computers? how "requirement" met? assuming have stack of blank forms come preprinted "sequence" number in upper right corner? , happens if spilled coffee on form? how handled? seems need similar method handle in system.
hope helps.
Comments
Post a Comment