Does a pessimistic memory lock refer to writing lock information into the memory of the TiKV node where the Leader region is located (the cache of the Leader region)?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 内存悲观锁指的是锁信息写入到Leader region所在的TiKV节点的内存(Leader region的缓存)吧?

| username: alfred

【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.

| username: h5n1 | Original post link

| username: xiaohetao | Original post link

Written in the lock cf of memory

| username: xiaohetao | Original post link

Both pessimistic locks and optimistic locks are written in the lock column family (lock cf).

| username: xiaohetao | Original post link

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.

| username: Raymond | Original post link

It is the leader because write operations can only be performed on the leader.

| username: alfred | Original post link

Is it the memory of the KV node or the TiDB Server node?

| username: forever | Original post link

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.

| username: xiaohetao | Original post link

kv node

| username: alfred | Original post link

It is the raft group maintained in memory.

| username: alfred | Original post link

How is the pessimistic lock in memory globally known? For example, how do other sessions know about this lock?

| username: HACK | Original post link

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.

| username: HACK | Original post link

Transactions will check the lock status.

| username: alfred | Original post link

So, this information about the Region leader in memory will also be recorded in PD, right?

| username: HACK | Original post link

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.

| username: system | Original post link

This topic was automatically closed 1 minute after the last reply. No new replies are allowed.