RID
Overview
A RID is an identifier that each node in a replication network uses to manage its own version of data. Each node manages one set of RIDs per resource.
Example of a RID:
00000000000000000000000000:01DT3V6WF6K5K12JBV8B563TXP:01DT3TREEM05JE0G8NFRACKJ3Y:01DT3TPFFQV48H3D51300DH53S:01DT3P4BTHN2T3QZTR9V78CPV5:1:0:0:0:3
Example of simplified output (outputting only the timestamp):
0000000000:01DT3V6WF6:01DT3TREEM:01DT3TPFFQ:01DT3P4BTH:1:0:0:0:3
Structure
[ data id list ]:[flags]
[incoming]:[head]:[old1]:[old2]:[base]:[flags]
incoming
The ULID assigned to the target when synchronization is in progress.
The same value as current in the synchronization source.
head
The ULID of the current data.
old1, old2
Past data ULID. cycled in the order of current → old1 → old2.
Used to determine the direction of synchronization between nodes.
base
Unique ULID for the replication network. Not cycled.
Added to prove that the nodes are from the same replication network if the RID is cycled more than 3 times while the node is unconnected and determined to be SB.
flags
An area to hold additional information beyond the ULID. Flags other than file_lock can only take two values: 0 or 1.
consistency
A flag indicating the consistency of the data.
outdated
A flag that is set on the Secondary when replication with the Primary stops.
primary
It is set when the node is promoted, and is only released upon demotion.
crashed_primary
Set if not statically terminated in the primary state, and released by synchronization.
file_lock
File lock status
0: Unknown, 1: Unlocked, 2: Allow Read, 3: Locked
Operations
The default values for RID are
00000000000000000000000000:00000000000000000000000000:00000000000000000000000000:00000000000000000000000000:00000000000000000000000000:0:0:0:0:0
It's too long to be readable, so we'll keep it short in this article.
Initial State
When a replication network is connected and all nodes are in equilibrium as secondaries, each node's ULID remains at its default value, as follows
inco:head:old1:old2:base
0000:0000:0000:0000:0000
Promote
If the current value is not set when the node is promoted, the initialization process is performed first.
Initialization process by promotion
base create
inco:curr:old1:old2:base
0000:0000:0000:0000:0001current create
inco:curr:old1:old2:base
0000:0001:0000:0000:0001
Turn on the Primary flag.
inco:curr:old1:old2:base
0000:0001:0000:0000:0001
Demote
Turn off the Primary flag.
Synchronization
During the synchronization process, RIDs operate as follows
A → B Sync
Before Sync.
A
inco:head:old1:old2:base
0000:0001:0000:0000:0001
B
inco:head:old1:old2:base
0000:0000:0000:0000:0001
Start Sync.
A is unchanged, and A's current is set to B's incoming.
inco:head:old1:old2:base
0001:0000:0000:0000:0001
Complete Sync.
RID Rotation of B
inco:head:old1:old2:base
0000:0001:0000:0000:0001
Synchronize between nodes with the same current
It works as above, but is not redundantly rotated.
Before Sync.
A & B
inco:head:old1:old2:base
0000:0003:0002:0001:0001
Start Sync.
B
inco:head:old1:old2:base
0003:0003:0002:0001:0001
Complete Sync.
B
inco:head:old1:old2:base
0000:0003:0002:0001:0001
RID Compare
Once the replication network is up and connected, each node passes its RID to the other and compares them in the following order.
- If both nodes' bases exist and are different, they are determined to be unrelated.
- Compare head, old1, and old2 to find the same ULID and derive an index number (0, 1, and 2, respectively).
- Compare their indexes.
- If both nodes have index 0, they have the same data, so no synchronization is required. (head is the same)
- If one node (A) has an index of 0 and the other node (B) has an index of 1 or more, synchronize as B → A.
- If both nodes are 1 or greater, we determine that they are SBs with a common denominator.
- Determine younger primary by comparing timestamps in the head
- Determine the data point before the SB occurred by looking at the ULID of the same index.
- Compare their indexes.
- If the same ULID does not exist
- If the head of one node is empty, synchronize towards that node.
- If the head of both nodes exists, it is judged as an SB where a common denominator cannot be found.
- Judgment of younger primary is meaningless
- Data point before SB occurrence is unknown
RID Flags
If no replication data is generated, there is no need to differentiate between generations of data, so we keep a flag to indicate whether replication has occurred.
When to update the flag:
- When you are promoted
- Set a flag if an unconnected node exists
- When you are Primary
- Setting the flag when the connection with the other node ends (disconnecting state)
- Unflagged if it is determined that all nodes are connected when it is connected to the other node (ESTABLISHED state)