Tuesday, January 25, 2011

What is CSN ( Change Sequence Number )

Sun Java[TM] System Directory Server - Change Sequence Numbers [ID 1008938.1]
--------------------------------------------------------------------------------

  Modified 07-JAN-2010     Type HOWTO     Migrated ID 212298     Status PUBLISHED  
Description
This document contains information about Change Sequence Numbers (CSN),
and their format, for customers who have deployed servers running Sun
Java[TM] System Directory Server
Steps to Follow
In Sun Java System Directory Server software, a master server needs to keep track of changes made to an entry, prior to replicating those changes to other masters (in an MMR environment) and/or downstream consumers (in a cascaded environment).
The logical order in which these changes are
applied to entries on the consumer server, may be important, as there could
be logical interdependencies between each change made. These changes are
stored in the changelogs of a Sun Java System Directory Server instance,
and are marked with a Change Sequence Number(CSN), which is used to resolve
replication conflicts should the need arise.
Format of a CSN
===============
A CSN is basically a sequence of numbers, consisting of a time-stamp and
the ID of the master replica, on which the change was originally made.
To be precise, it is a ten-byte structure, where the first four bytes
contain a timestamp expressed as seconds after UTC 1st January 1970.
The next two bytes form a sequence number, used when more than one CSN is
generated within one second. Two bytes then follow, with the ID of the
replica for which the CSN is generated, and the remaining two bytes
contain a sub-sequence number
eg. 3cadb52d000000010000
^       ^   ^   ^
------- --- --- ----
Date    Seq Rep Sub-Seq
No  ID  Number
where:
a. the string ?3cadb52d? translates to 05 Apr 2002 07:30:46. This string
is a hexadecimal value of the number of seconds since 01 Jan 1970 (UTC).
b. the next portion, ?0000?, denotes this is the first CSN generated
this second.
c. the string "0001" denotes the replica ID of the master generating
the CSN and should be unique to each server in the topology.
d. the last portion of the string, "0000? represents the subsequence
number. This is currently reserved and is always set to zero.
The format should ensure that servers operating in a replicated
environment, and replicating changes to one another, will generate unique
CSNs, so that changes are ordered in a computable manner. If a consumer
does not receive the changes from its multiple suppliers in the right
order, it is able to determine what the right order is, via the Update
Resolution Procedure (URP), that is, by comparing the CSN of each change
it receives and replaying them in the correct order.

4 comments: