Allocation method and device for a distributed lock
AssigneeAlibaba Group Holding Limited
InventorsYunfeng Zhu, Haoran Yang, Yijun Lu
Life of this patent
Estimating the term…
Abstract
A method and device for allocating a distributed lock is provided. A globally unique service process ID (SPI) is introduced for each distributed application service process while guaranteeing correctness of a distributed lock, and the SPI is used to directly manage ownership of the distributed lock. The service replacement process sends to the server a request for inheriting ownership of the distributed lock before the lifecycle of the lock file expires, the inherit request including the SPI.
Claims19
An allocation method for a distributed lock at a server, comprising:
- creating a lock file having a lifecycle for a distributed lock according to a lock file creation request received from a service process of a client;
- writing a unique service process ID (SPI) of the service process into the lock file according to an SPI writing request received from the service process, wherein upon a service process crash is detected, a service replacement process is initiated for allocating the SPI of the crashed service process to the service replacement process;
- acquiring a distributed lock inherit request sent by the service replacement process before the lifecycle of the lock file expires, the distributed lock inherit request including the SPI and indicating a request for inheriting ownership of the distributed lock to the server, the distributed lock inherit request further including a lock file deletion request for deleting the lock file created based on the request from the service process;
- determining whether the SPI of the service replacement process is consistent with an SPI in the lock file;
- and
- in response to the SPI of the service replacement process being consistent with the SPI in the lock file, deleting the lock file created according to the lock file creation request received from the service process and creating a new lock file of the distributed lock for the service replacement process, wherein deleting the lock file is based on a comparison of a transaction ID generated during creation of the lock file and a transaction ID in the lock file deletion request.
A server, comprising:
- a creation apparatus configured to create a lock file having a lifecycle for a distributed lock according to a lock file creation request received from a service process of a client;
- a writing apparatus configured to write a unique service process ID (SPI) of the service process into the lock file according to an SPI writing request received from the service process, wherein upon a service process crash is detected, a service replacement process is initiated for allocating the SPI of the crashed service process to the service replacement process;
- and
- an allocation apparatus configured to:
- acquire a distributed lock inherit request sent by the service replacement process before the lifecycle of the lock file expires, the distributed lock inherit request including the SPI and indicating a request for inheriting ownership of the distributed lock to the server, and the distributed lock inherit request further including a lock file deletion request for deleting the lock file created based on the request from the service process;
- determine whether the SPI of the service replacement process is consistent with an SPI in the lock file;
- and
- in response to the SPI of the service replacement process being consistent with the SPI in the lock file, delete the lock file created according to the lock file creation request received from the service process and create a new lock file of the distributed lock for the service replacement process, wherein deleting the lock file is based on a comparison of a transaction ID generated during creation of the lock file and a transaction ID in the lock file deletion request.
A computing-based device, comprising:
- a memory configured to store computer executable instructions;
- and
- a processor configured to execute the instructions to cause the computing-based device to:
- create a lock file having a lifecycle for a distributed lock according to a lock file creation request received from a service process of a client;
- write a unique service process ID (SPI) of the service process into the lock file according to an SPI writing request received from the service process, wherein upon a service process crash is detected, a service replacement process is initiated for allocating the SPI of the crashed service process to the service replacement process;
- acquire a distributed lock inherit request sent by the service replacement process before the lifecycle of the lock file expires, the distributed lock inherit request including the SPI of the service replacement process and indicating a request for inheriting ownership of the distributed lock to a server, and the distributed lock inherit request further including a lock file deletion request for deleting the lock file created based on the request from the service process;
- and
- determine whether the SPI of the service replacement process is consistent with an SPI in the lock file, and in response to the SPI of the service replacement process being consistent with the SPI in the lock file, delete the lock file created according to the lock file creation request received from the service process and create a new lock file of the distributed lock for the service replacement process, wherein deleting the lock file is based on a comparison of a transaction ID generated during creation of the lock file and a transaction ID in the lock file deletion request.
A non-transitory computer-readable storage medium storing a set of instructions that is executable by one or more processors of an electronic device to cause the electronic device to perform a method comprising:
- creating a lock file having a lifecycle for a distributed lock according to a lock file creation request received from a service process of a client;
- writing a unique service process ID (SPI) of the service process into the lock file according to an SPI writing request received from the service process, wherein upon a service process crash is detected, a service replacement process is initiated for allocating the SPI of the crashed service process to the service replacement process;
- acquiring a distributed lock inherit request sent by the service replacement process before the lifecycle of the lock file expires, the distributed lock inherit request including the SPI and indicating a request for inheriting ownership of the distributed lock to a server, and the distributed lock inherit request further including a lock file deletion request for deleting the lock file created based on the request from the service process;
- determining whether the SPI of the service replacement process is consistent with an SPI in the lock file;
- and
- in response to the SPI of the service replacement process being consistent with the SPI in the lock file, deleting the lock file created according to the lock file creation request received from the service process and creating a new lock file of the distributed lock for the service replacement process, wherein deleting the lock file is based on a comparison of a transaction ID generated during creation of the lock file and a transaction ID in the lock file deletion request.
Dependencies are inferred from the claim text.