How to decode replication CSN ?

Solution Verified - Updated -

Environment

  • Red Hat Directory Server 10.x
  • Red Hat Directory Server 11.x
  • Red Hat Directory Server 12.x
  • Red Hat Directory Server 13.x
  • Red Hat Identity Management (IPA) 4.x

Issue

It can be useful for troubleshooting replication to be able to decode a CSN (Change Sequence Number).

Resolution

Replication protocol needs to identify uniquely each change in the topology. The way to achieve this is to generate and assign to each update a CSN, a change sequence number. As we can have multiple suppliers in a replication topology, the CSN should be complex enough to include all the information that allows to order the updates of the whole topology.

The replication changelog is ordered by CSN.

  • To identify a CSN, we can find an update in the access logs:
[18/Jul/2018:09:00:00.097853574 -0400] conn=5 op=160 MOD dn="cn=MasterCRL,ou=crlIssuingPoints,ou=ca,o=ipaca"
[18/Jul/2018:09:00:00.103652669 -0400] conn=5 op=160 RESULT err=0 tag=103 nentries=0 etime=0.0006578222 csn=5b4f39d1000000a00000

The former update has been identified with CSN = 5b4f39d1000000a00000

A CSN is a 16 character hexadecimal string including the date, the replica id, the sequence number, and an additional number. More precisely:
- First 8 digits representing the date and time of the update generated in the supplier. It's the number of seconds from January 1st 1970.
- The next 4 characters represent the number of change that took place during that second, since we can have several updates per second.
- The following 4 characters are the replica ID.
- The latest 4 characters are reserved but not used for the moment, and they are always shown as "0000".

Taking into account the former explanation, we can decode the former CSN = 5b4f39d1000000060000, as this:
- The time when the supplier has generated this CSN is 5b4f39d1, that translated to decimal is 1531918801. This quantity of seconds, the "epoch" timestamp from January 1st 1970 corresponds to "GMT: Wednesday, July 18, 2018 1:00:01 PM"
- The number of change during that second is 0000, that is to say, the first one.
- The replica id is 00a0, that is to say, replica id 10.
- And the reserved characters that are always showing 0000.

Root Cause

  • In different scenarios, we need to decode a CSN to understand the origin of a replication update.

Diagnostic Steps

We can find references to CSN in the access and errors logs of Red Hat Directory Server, either as standalone server or in IPA context.

  1. If you wish decode the CSNs using a script you can create file called csn_decoder with the below content:
#!/bin/bash
# By Cilmar Oliveira
# csn_decoder - decode a 389-DS / IPA replication CSN
# Usage: ./csn_decoder <csn>
#   e.g. ./csn_decoder 61a4d8f8000100010000

csn_decode() {
    local csn="$1"
    local hex_ts="${csn:0:8}"
    local hex_seq="${csn:8:4}"
    local hex_rid="${csn:16:4}"

    echo "CSN       : $csn"
    echo "Timestamp : $(date -d @$((16#$hex_ts)))"
    echo "Sequence  : $((16#$hex_seq))"
    echo "Replica ID: $((16#$hex_rid))"
}

if [ -z "$1" ]; then
    echo "Usage: $0 <csn>"
    exit 1
fi

csn_decode "$1"
  1. Decode CSN example:
# ./csn_decoder 61a4d8f8000100010000
CSN       : 61a4d8f8000100010000
Timestamp : Mon Nov 29 10:43:20 AM -03 2021
Sequence  : 1
Replica ID: 0

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments