Lock management method, apparatus, and system
Example methods, apparatuses, and distributed systems are provided. An example method includes acquiring, by a network interface card of a serving device, a lock acquisition request of a client. The lock acquisition request requests to acquire access permission for a shared resource. The example method further includes determining, by the network interface card based on recorded lock information, whether the client is enabled to acquire a lock of the shared resource. The example method further includes, in response to determining that the client is enabled to acquire the lock of the shared resource, sending, by the network interface card, a lock acquisition success response to the client. The lock acquisition success response indicates that the client successfully acquires the lock of the shared resource.
1 . A method, comprising:
acquiring, by a network interface card of a serving device, a lock acquisition request of a client, wherein the lock acquisition request requests to acquire access permission for a shared resource, wherein the network interface card is coupled by at least one bus to at least one central processing unit and at least one memory of the serving device, the at least one memory of the serving device directly exchanges data with the at least one central processing unit, and wherein the network interface card comprises at least one internal memory storing lock information of the shared resource, the at least one memory of the serving device stores a cache queue of a lock of the shared resource, and the lock information of the shared resource that is stored in the at least one internal memory of the network interface card comprises information of whether a write lock of the shared resource is in an idle state and information of whether a read lock of the shared resource is in an idle state and at least one pointer that points to the cache queue of the lock of the shared resource stored in the at least one memory of the serving device;
determining, by the network interface card, and based on the information of whether the write lock of the shared resource is the idle state or the information of whether the read lock of the shared resource is in the idle state that is stored in the at least one internal memory of the network interface card, and without participation of the at least one central processing unit, whether the client is enabled to acquire the lock of the shared resource;
updating, by the network interface card, the cache queue of the lock of the shared resource stored in the at least one memory of the serving device according to the determining of whether the client is enabled to acquire the lock of the shared resource; and
in response to determining that the client is enabled to acquire the lock of the shared resource, sending, by the network interface card, a lock acquisition success response to the client, wherein the lock acquisition success response indicates that the client successfully acquires the lock of the shared resource;
wherein the information of whether the write lock of the shared resource is in the idle state comprises a first quantity of nodes that request to acquire a write lock of the shared resource and the information of whether the read lock of the shared resource is in the idle state comprises a second quantity of nodes that request to acquire a read lock of the shared resource, wherein the network interface card updates the first quantity of nodes in response to a request to acquire the write lock of the shared resource or a request to release the write lock of the shared resource, and the network interface card updates the second quantity of nodes in response to a request to acquire the read lock of the shared resource or a request to release the read lock of the shared resource; and
wherein determining, by the network interface card and based on the information of whether the write lock of the shared resource is in the idle state and the information of whether the read lock of the shared resource is in the idle state that are stored in the at least one internal memory of the network interface card, and without participation of the at least one central processing unit, whether the client is enabled to acquire the lock of the shared resource comprises:
when the first quantity indicates that the write lock of the shared resource is in the idle state, determining, by the network interface card, that the client is enabled to acquire the read lock of the shared resource.
2 . The method according to claim 1 ,
wherein determining, by the network interface card and based on the information of whether the write lock of the shared resource is in the idle state and the information of whether the read lock of the shared resource is in the idle state that are stored in the at least one internal memory of the network interface card, and without participation of the at least one central processing unit, whether the client is enabled to acquire the lock of the shared resource further comprises:
in response to the first quantity indicating that the write lock of the shared resource is in the idle state, and the second quantity indicating that the read lock of the shared resource is in the idle state, determining, by the network interface card, that the client is enabled to acquire the write lock of the shared resource.
3 . The method according to claim 1 , wherein the cache queue of the lock of the shared resource stored in the at least one memory of the serving device comprises lock state information and node state information, the node state information indicates whether an access node has acquired the lock, and the lock state information indicates whether the lock applied by the access node is in a lock released state.
4 . The method according to claim 3 , wherein the lock acquisition success response comprises lock location information, and the lock location information indicates a location of the lock information of the client in the cache queue; and
the method further comprises:
receiving, by the network interface card, a lock release request sent by the client, wherein the lock release request is used to request to release the lock of the shared resource, and the lock release request comprises the lock location information; and
modifying, by the network interface card and based on the lock location information, a state of the lock indicated by the lock location information in the cache queue to the lock released state.
5 . The method according to claim 1 , wherein acquiring, by the network interface card of the serving device, the lock acquisition request of the client comprises:
receiving, by the network interface card, the lock acquisition request sent by the client.
6 . The method according to claim 1 , wherein acquiring, by the network interface card of the serving device, the lock acquisition request of the client comprises:
acquiring, by the network interface card, the lock acquisition request of the client from the cache queue.
7 . The method according to claim 1 , wherein the at least one pointer that points to the cache queue of the lock of the shared resource stored in the at least one memory of the serving device comprises a head pointer and a tail pointer of the cache queue.
8 . The method according to claim 7 , wherein the cache queue is stored in a ring buffer of the at least one memory.
9 . An apparatus, wherein the apparatus comprises at least one processor and at least one memory, wherein the at least one memory stores computer program instructions that, when executed by the at least one processor, cause the apparatus to:
acquire, using a network interface card of the apparatus, a lock acquisition request of a client, wherein the lock acquisition request requests to acquire access permission for a shared resource, and the network interface card is coupled by at least one bus to at least one central processing unit of the apparatus and at least one memory of the apparatus, and the at least one memory of the apparatus directly exchanges data with the at least one central processing unit;
determine, using the network interface card and based on lock information stored in at least one internal memory of the network interface card, and without participation of the at least one central processing unit, whether the client is enabled to acquire a lock of the shared resource, wherein the at least one memory of the apparatus stores a cache queue of a lock of the shared resource, and the lock information of the shared resource that is stored in the at least one internal memory of the network interface card comprises information of whether a write lock of the shared resource is in an idle state and information of whether a read lock of the shared resource is in an idle state and at least one pointer that points to the cache queue of the lock of the shared resource stored in the at least one memory of the apparatus;
update, using the network interface card, the cache queue of the lock of the shared resource according to the determining of whether the client is enabled to acquire the lock of the shared resource; and
in response to determining that the client is enabled to acquire the lock of the shared resource, send, using the network interface card, a lock acquisition success response to the client, wherein the lock acquisition success response indicates that the client successfully acquires the lock of the shared resource;
wherein the information of whether the write lock of the shared resource is in the idle state comprises a first quantity of nodes that request to acquire a write lock of the shared resource and the information of whether the read lock of the shared resource is in the idle state comprises a second quantity of nodes that request to acquire a read lock of the shared resource, wherein the network interface card updates the first quantity of nodes in response to a request to acquire the write lock of the shared resource or a request to release the write lock of the shared resource, and the network interface card updates the second quantity of nodes in response to a request to acquire the read lock of the shared resource or a request to release the read lock of the shared resource; and
wherein to determine, based on the lock information stored in at least one internal memory of the network interface card, and without participation of the at least one central processing unit, whether the client is enabled to acquire the lock of the shared resource, the computer program instructions, when executed by the at least one processor, cause the apparatus to:
in response to the first quantity indicating that the write lock of the shared resource is in the idle state, determine that the client is enabled to acquire the read lock of the shared resource.
10 . The apparatus according to claim 9 , wherein to determine, based on the lock information stored in at least one internal memory of the network interface card, and without participation of the at least one central processing unit, whether the client is enabled to acquire the lock of the shared resource, the computer program instructions, when executed by the at least one processor, further cause the apparatus to:
in response to the first quantity indicating that the write lock of the shared resource is in the idle state, and the second quantity indicating that the read lock of the shared resource is in the idle state, determine that the client is enabled to acquire the write lock of the shared resource.
11 . The apparatus according to claim 9 , wherein the cache queue of the lock of the shared resource stored in the at least one memory of the apparatus comprises lock state information and node state information, the node state information indicates whether an access node has acquired the lock, and the lock state information indicates whether the lock applied by the access node is in a lock released state.
12 . The apparatus according to claim 11 , wherein the lock acquisition success response comprises lock location information, and the lock location information indicates a location of the lock information of the client in the cache queue; and
wherein the computer program instructions, when executed by the at least one processor, further cause the apparatus to:
receive a lock release request sent by the client, wherein the lock release request is used to request to release the lock of the shared resource, and the lock release request comprises the lock location information; and
modify, based on the lock location information, a state of the lock indicated by the lock location information in the cache queue to the lock released state.
13 . The apparatus according to claim 9 , wherein to acquire, by the network interface card, the lock acquisition request of the client, the computer program instructions, when executed by the at least one processor, cause the apparatus to:
acquire, by the network interface card, the lock acquisition request of the client from the cache queue.
14 . The apparatus according to claim 9 , wherein the at least one pointer that points to the cache queue of the lock of the shared resource stored in the at least one memory comprises a head pointer and a tail pointer of the cache queue.
15 . A distributed system, wherein the distributed system comprises a client and a serving device, and the serving device comprises a lock management apparatus,
wherein the client is configured to send a lock acquisition request to the serving device, wherein the lock acquisition request requests to acquire access permission for a shared resource; and
wherein the lock management apparatus comprises a network interface card comprising at least one internal memory, and at least one processor, and wherein the network interface card is coupled by at least one bus to at least one central processing unit of the serving device and at least one memory of the serving device, the at least one memory of the serving device directly exchanges data with the at least one central processing unit, and the at least one memory of the serving device stores a cache queue of the shared resource;
wherein the at least one internal memory stores lock information of the shared resource and computer program instructions that, when executed by the at least one processor, cause the lock management apparatus to:
acquire the lock acquisition request of the client;
determine, based on the lock information stored in the at least one internal memory of the network interface card, and without participation of the at least one central processing unit, whether the client is enabled to acquire a lock of the shared resource;
update the cache queue of the lock of the shared resource according to the determining of whether the client is enabled to acquire the lock of the shared resource, wherein the lock information of the shared resource that is stored in the at least one internal memory of the network interface card comprises information of whether a write lock of the shared resource is in an idle state and information of whether a read lock of the shared resource is in an idle state and at least one pointer that points to the cache queue of the lock of the shared resource stored in the at least one memory of the serving device; and
in response to determining that the client is enabled to acquire the lock of the shared resource, send a lock acquisition success response to the client, wherein the lock acquisition success response indicates that the client successfully acquires the lock of the shared resource;
wherein the information of whether the write lock of the shared resource is in the idle state comprises a first quantity of nodes that request to acquire a write lock of the shared resource and the information of whether the read lock of the shared resource is in the idle state comprises a second quantity of nodes that request to acquire a read lock of the shared resource, wherein the lock management apparatus is configured to update the first quantity of nodes in response to a request to acquire the write lock of the shared resource or a request to release the write lock of the shared resource, and the lock management apparatus is configured to update the second quantity of nodes in response to a request to acquire the read lock of the shared resource or a request to release the read lock of the shared resource; and
wherein to determine, based on the lock information stored in the at least one internal memory, whether the client is enabled to acquire the lock of the shared resource, the lock management apparatus is caused to:
in response to the first quantity indicating that the write lock of the shared resource is in the idle state, determine that the client is enabled to acquire the read lock of the shared resource.
16 . The distributed system according to claim 15 ,
wherein to determine, based on the lock information stored in the at least one internal memory, whether the client is enabled to acquire the lock of the shared resource, the lock management apparatus is further caused to:
in response to the first quantity indicating that the write lock of the shared resource is in the idle state, determine that the client is enabled to acquire the read lock of the shared resource.
17 . The distributed system according to claim 15 , wherein the cache queue of the lock of the shared resource stored in the at least one memory of the serving device comprises lock state information and node state information, the node state information indicates whether an access node has acquired the lock, and the lock state information indicates whether the lock applied by the access node is in a lock released state.
18 . The distributed system according to claim 15 , wherein to acquire the lock acquisition request of the client, the computer program instructions, when executed by the at least one processor, cause the lock management apparatus to:
acquire the lock acquisition request of the client from the cache queue.
19 . The distributed system according to claim 15 , wherein the at least one pointer that points to the cache queue of the lock of the shared resource stored in the at least one memory of the serving device comprises a head pointer and a tail pointer of the cache queue.