MiniM Knowledge Base | Sep 27, 2010
How MiniM implements transaction sequence number
MiniM Database Server implements transactions and one of the most important part of transaction implementation is a special number named as TSN or Transaction Sequence Number.
This number is a unique number for all transactions currently are active and are recorded in the journal. Each time while MiniM execute start transaction, TSN is created and is used as an internal part of journal records. TSN is created only if value of system variable $tlevel switches from 0 to 1 and does not changes if $tlevel increments from 1 to 2 and other. TSN does not used for new journal records if $tlevel have a 0 value.
MiniM Database Server creates TSN as based on the current last created TSN and TSN consists of two parts - timestamp and incremented integer for TSN created whithin the same timestamp. This incremented integer part is a synthetic TSN correction.
If MiniM process requires to get next TSN, process evaluates current timestamp and compares with the last used TSN timestamp part. If current timestamp is greater than last used, process use current timestamp. Otherwise process use timestamp part of last created TSN and increments synthetic integer part. If synthetic integer part can overflows limit, process automatically increments timestamp part by one second and use new value.
On server start in initialization phase MiniM Database Server searches inside last journal records any records which have TSN markers and use last used of recorded TSN. This TSN is used as a first value for last created TSN. This last used TSN may have a timestamp greater than current timestamp if administrator revert current date or time on the computer before MiniM start.
So, all transactions are made on current MiniM instance have different TSN with growing TSN values and server can handle date and time revertion safely. If administrator change date and time while MiniM Database Server is stopped or running, internal TSN counter synthetically waits current date and time be greater than last used and next use current date and time.Eugene Karataev