Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: 内存悲观锁指的是锁信息写入到Leader region所在的TiKV节点的内存(Leader region的缓存)吧?
【TiDB Usage Environment】Production, Testing, Research
【TiDB Version】
【Encountered Problem】
【Reproduction Path】Operations performed that led to the problem
【Problem Phenomenon and Impact】
【Attachments】
Please provide the version information of each component, such as cdc/tikv, which can be obtained by executing cdc version/tikv-server --version.
Written in the lock cf of memory
Both pessimistic locks and optimistic locks are written in the lock column family (lock cf).
The difference between pessimistic locking and optimistic locking is that optimistic locking only locks during the commit phase of the first stage, while pessimistic locking performs detection and writes lock information before DML.
It is the leader because write operations can only be performed on the leader.
Is it the memory of the KV node or the TiDB Server node?
In the memory of kv, TiDB nodes are multiple and stateless, and do not store lock information. Each region independently maintains an in-memory lock table (only maintained by the leader peer). When region changes occur, such as Leader transfer or Region merge, the pessimistic locks in the lock table will be synchronized to other nodes through raft.
It is the raft group maintained in memory.
How is the pessimistic lock in memory globally known? For example, how do other sessions know about this lock?
Pessimistic locks in memory are only stored in the memory of the Region leader. They are not persisted to disk, nor are they synchronized to other replicas through the Raft protocol. If this node fails, it will result in the loss of the pessimistic lock.
Transactions will check the lock status.
So, this information about the Region leader in memory will also be recorded in PD, right?
Region and store-related metadata are reported to PD through heartbeats. PD analyzes the specific information uploaded and sends it back to the TiKV nodes to achieve scheduling and adjustment of the cluster’s region distribution and other related aspects. This has nothing to do with whether it is an in-memory pessimistic lock.
This topic was automatically closed 1 minute after the last reply. No new replies are allowed.