CN-121979695-A - Database session processing method, device, equipment and readable storage medium
Abstract
The present application relates to a database session processing method, apparatus, computer device, computer readable storage medium and computer program product. The method comprises the steps that under the condition that a target process belongs to a coordinator and the target process successfully obtains the mutual exclusion lock of a process array, each session operation task is obtained from a task queue through the target process, the process array is used for storing state information of each process of a database, each session operation task comprises an operation task of a database session corresponding to the target process and an operation task of a database session corresponding to the process belonging to a participant, and batch processing is conducted on the process array through the target process based on each session operation task to obtain a database session processing result for the database. By adopting the method, the database session processing efficiency can be improved.
Inventors
- HU BIN
- ZHANG ZHIXIAN
Assignees
- 天翼云科技有限公司
Dates
- Publication Date
- 20260505
- Application Date
- 20251222
Claims (10)
- 1. A database session processing method, the method comprising: Under the condition that a target process belongs to a coordinator and the target process successfully acquires the mutual exclusion lock of a process array, acquiring each session operation task from a task queue through the target process, wherein the process array is used for storing the respective state information of each process of a database; And carrying out batch processing on the process array based on the session operation tasks through the target process to obtain a database session processing result aiming at the database.
- 2. The method of claim 1, wherein the task queue includes task metadata including a linked list pointer to next task metadata, and wherein the obtaining, by the target process, each session operation task from the task queue includes: determining a variable pointer of a task queue through the target process; determining a queue endpoint of the task queue according to the variable pointer, and resetting the task queue based on the variable pointer; And traversing the linked list based on the linked list pointer in the task metadata corresponding to the queue endpoint, and obtaining each session operation task according to the traversed task metadata.
- 3. The method according to claim 1, wherein the performing, by the target process, batch processing on the process array based on the session operation tasks to obtain a database session processing result for the database includes: sequencing the session operation tasks through the target process to obtain an operation task array; and carrying out batch processing on the process array based on the operation task array through the target process to obtain a database session processing result aiming at the database, wherein the database session processing result comprises an updated process array.
- 4. The method of claim 1, further comprising, before the target process obtains each session operation task from the task queue in the case that the target process belongs to a coordinator and the target process successfully obtains the mutex lock of the process array: Under the condition that the target process does not acquire the exclusive lock of the process array, determining a variable pointer of the task queue through the target process; determining task metadata of a database session corresponding to the target process, wherein the task metadata comprises a linked list pointer pointing to next task metadata; Updating a linked list pointer in task metadata of the database session corresponding to the target process into the variable pointer to obtain updated task metadata; And adding the updated task metadata into the task queue, and updating the variable pointer to point to the database session corresponding to the target process.
- 5. The method of claim 4, further comprising at least one of: Under the condition that the target process does not acquire the mutual exclusion lock of the process array and the variable pointer is empty, determining that the target process belongs to a coordinator; and under the condition that the target process does not acquire the exclusive lock of the process array and the variable pointer is not null, determining that the target process belongs to the participant.
- 6. The method according to any one of claims 1 to 5, further comprising, after the step of performing batch processing on the process array based on the session operation tasks by the target process to obtain a database session processing result for the database: releasing the mutual exclusion lock aiming at the process array through the target process, and sending an operation completion notification to the process belonging to the participant so as to finish the processing flow aiming at each session operation task.
- 7. The method according to any one of claims 1 to 5, further comprising: and under the condition that the target process successfully acquires the mutual exclusion lock of the process array in a non-blocking mode, processing the process array based on the operation task of the database session corresponding to the target process by the target process to obtain a database session processing result of the database.
- 8. A database session processing apparatus, the apparatus comprising: The system comprises an operation task acquisition module, a session operation task acquisition module and a processing module, wherein the operation task acquisition module is used for acquiring each session operation task from a task queue through a target process under the condition that the target process belongs to a coordinator and the target process successfully acquires a mutual exclusion lock of a process array; and the task batch processing module is used for carrying out batch processing on the progress array based on the session operation tasks through the target progress to obtain a database session processing result aiming at the database.
- 9. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor implements the steps of the method of any of claims 1 to 7 when the computer program is executed.
- 10. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 7.
Description
Database session processing method, device, equipment and readable storage medium Technical Field The present application relates to the field of database technologies, and in particular, to a method, an apparatus, a device, and a readable storage medium for processing a database session. Background With the development of database technology, concurrent connections can be processed using a multi-process model, and session states thereof can be managed by ordered process arrays in a shared memory. The process array may store core state information for each process in the order of process number. And each time a process is created or destroyed, the process array needs to be subjected to updating operations such as insertion or deletion. However, since the process array needs to be kept ordered, the insert and delete operations involve element movement in the process array, and all operations need to be performed under the protection of mutual exclusion lock, resulting in a dramatic decrease in performance in a high concurrency scenario, resulting in lower efficiency of database session processing. Disclosure of Invention In view of the foregoing, it is desirable to provide a database session processing method, apparatus, computer device, computer readable storage medium, and computer program product that can improve the efficiency of database session processing. In a first aspect, the present application provides a database session processing method, including: Under the condition that the target process belongs to a coordinator and the target process successfully acquires the mutual exclusion lock of the process array, acquiring each session operation task from a task queue through the target process, wherein the process array is used for storing the respective state information of each process of a database; And carrying out batch processing on the process array based on each session operation task through the target process to obtain a database session processing result for the database. In one embodiment, the task queue comprises task metadata, the task metadata comprises a linked list pointer pointing to the next task metadata, and the task obtaining the session operation task from the task queue through the target process comprises the following steps: determining a variable pointer of a task queue through a target process; Determining a queue endpoint of the task queue according to the variable pointer, and resetting the task queue based on the variable pointer; And traversing the linked list based on the linked list pointer in the task metadata corresponding to the queue endpoint, and obtaining each session operation task according to the traversed task metadata. In one embodiment, batch processing is performed on a process array based on each session operation task through a target process to obtain a database session processing result for a database, including: Sequencing each session operation task through a target process to obtain an operation task array; and carrying out batch processing on the process arrays based on the operation task arrays through the target process to obtain database session processing results for the database, wherein the database session processing results comprise updated process arrays. In one embodiment, before the target process obtains each session operation task from the task queue under the condition that the target process belongs to the coordinator and the target process successfully obtains the mutex lock of the process array, the method further comprises: Under the condition that the target process does not acquire the mutex lock of the process array, determining a variable pointer of a task queue through the target process; Determining task metadata of a database session corresponding to a target process, wherein the task metadata comprises a linked list pointer pointing to next task metadata; Updating a linked list pointer in task metadata of a database session corresponding to the target process into a variable pointer to obtain updated task metadata; And adding the updated task metadata into a task queue, and updating the variable pointer to point to the database session corresponding to the target process. In one embodiment, the database session processing method further includes at least one of: under the condition that the target process does not acquire the mutual exclusion lock of the process array and the variable pointer is empty, determining that the target process belongs to a coordinator; and under the condition that the target process does not acquire the mutual exclusion lock of the process array and the variable pointer is not null, determining that the target process belongs to the participant. In one embodiment, after batch processing is performed on the process array based on each session operation task through the target process to obtain a database session processing result for the database, the method further includes: Releasing the mutu