A database serialization read / write method and system

By combining a multi-threaded architecture with a synchronization control module, the performance bottleneck of traditional single-threaded databases in high-concurrency scenarios is solved, achieving ordered and consistent data reading and writing, and improving the system's response speed and data storage reliability.

CN119759541BActive Publication Date: 2025-11-14QINGDAO HIGHTOP BIOTECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411980487.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-31
Publication Date
2025-11-14
Estimated Expiration
2044-12-31

AI Technical Summary

Technical Problem

Traditional single-threaded database read and write methods are prone to performance bottlenecks in high-concurrency scenarios. They cannot ensure that read and write operations are performed according to the predetermined priority and order, resulting in data inconsistency and errors, and making it difficult to meet the data read and write requirements in high-concurrency scenarios.

Method used

It adopts a multi-threaded architecture, including business threads, intermediary thread modules, database operation modules, and database thread modules. Through thread-safe operation instruction queues and synchronization control modules, it ensures the serialization and consistency of data reading and writing, and supports ordered operations in a multi-threaded high-concurrency environment.

Benefits of technology

It achieves ordered and consistent data reading and writing in a multi-threaded, high-concurrency environment, improves system response speed and data storage reliability, adapts to complex business logic, and avoids data inconsistency and errors.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119759541B_ABST
    Figure CN119759541B_ABST
Patent Text Reader

Abstract

This invention relates to the field of computer technology and discloses a database serialization read / write method and system. Addressing the performance bottlenecks and difficulties in ensuring data consistency and validity in high-concurrency scenarios associated with traditional single-threaded database read / write methods, this invention designs a novel method: First, according to software operation requirements, multiple business threads, an intermediary thread module, a database operation module, and a database thread module are created. The business threads package their operation requirements with the database operation module and add them to a temporary queue. The intermediary thread then sends the package to the instruction queue of the database thread module with the appropriate priority. The database thread module reads the data according to priority, calls methods to execute database operations, and notifies the business threads. A synchronization control module ensures the serialization of write operations. The advantages include flexible resource allocation and customizable priorities for business threads, ensuring accurate and orderly data read / write operations, making it suitable for fields such as big data processing, industrial control, and medical devices.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a database serialization read / write method and system. Background Technology

[0002] With the development of computer programming technology in industrial control and medical device fields, the amount of data that software needs to store is increasing. In terms of software architecture, especially when dealing with database read and write requests initiated by multiple threads at the same time, the management of data read and write becomes extremely difficult because these threads have different priority settings and specific execution order requirements.

[0003] Traditional single-threaded database read / write methods are prone to performance bottlenecks and cannot meet the ordered read / write requirements of high-concurrency scenarios. Their serialized processing mechanism easily falls into a performance bottleneck under high concurrency pressure. When faced with a large number of simultaneous database read / write tasks, single-threaded methods cannot process them quickly and efficiently, leading to significantly increased data processing latency and extremely slow system response, severely impacting the overall operating efficiency and performance of the software system. More importantly, this traditional approach cannot ensure that read / write operations are performed in an orderly manner according to predetermined priorities and execution order under multi-threaded concurrency, potentially causing serious problems such as data inconsistency, errors, or data loss. It cannot effectively meet the stringent requirements for accuracy, efficiency, and orderliness in high-concurrency scenarios.

[0004] Therefore, it is particularly important to design a serialized database data reading and writing method that can support multi-threaded high concurrency. Summary of the Invention

[0005] To address the above problems, this invention discloses a database serialization read / write method, comprising the following steps:

[0006] S1. Based on the software's operational requirements, multiple business threads, an intermediary thread module, multiple database operation modules, and a database thread module are created. The software system allocates a corresponding database operation module to each business thread, encapsulating the database operation instruction set required by the business thread. The database thread module has multiple thread-safe database operation instruction queues built-in. The intermediary thread module exposes the same number of interfaces as the database operation instruction queues. Each interface corresponds to a database operation instruction queue, and each database operation instruction queue has a different priority.

[0007] S2. Multiple business threads create database operation requirements, set operation instruction IDs and parameters for the database operation requirements, and package the database operation requirements and database operation modules together. At this time, the business threads can call the interfaces in the intermediary thread module according to the required priority, and then add the packaged data to the temporary instruction queue.

[0008] S3. The intermediary thread module, based on the called interface, passes the packaged data to the database operation instruction queue of the corresponding priority in the database thread module, and releases the lock. The database thread module then begins to process the data.

[0009] S4. The database thread module reads the packaged data sequentially according to the priority of the database operation instruction queue, calls the database operation method according to the specified ID and parameters, and sends a signal to the corresponding business thread after each database operation method is executed. The business thread module will then perform business processing based on the signal. This completes one database operation.

[0010] S5. Repeat step S4 until all database operation instruction queues are empty, and then block the database operation instruction queues with a lock.

[0011] The database thread module holds a lock to ensure that read operations will not be performed when all database operation instruction queues are empty, preventing repeated read operations from causing the entire program to freeze or even crash.

[0012] Furthermore, the database thread module also encapsulates a synchronization control module, which serializes database write operations to ensure data consistency and reliability. The implementation logic of the synchronization control module is similar to that of synchronization control in computer systems.

[0013] Furthermore, when adding database operation requests to the temporary instruction queue, an operation ID and parameters are set. Each data entry in the database operation instruction queue contains an operation ID and parameters, and the operation ID corresponds one-to-one with the database operation method encapsulated in the database operation module.

[0014] Preferably, each business thread can call multiple different interfaces simultaneously.

[0015] Furthermore, the database operation module encapsulates database operation methods, including adding, deleting, querying, and modifying data. It also allows data manipulation with other database interfaces (APIs) via structured query statements (SQL statements). The database operation module exposes an instruction set interface. Database operation methods are implemented through a polymorphic data processing module.

[0016] A database system equipped with the aforementioned database serialization read / write method is also disclosed.

[0017] The advantages of this invention are:

[0018] 1. Each business thread can call multiple different interfaces simultaneously, and resources can be flexibly allocated according to actual business needs. When multiple businesses need to interact with the database, the priority can be customized to specify one or more businesses to complete the database operation first, ensuring that the corresponding business is executed faster. This enhances the software system's ability to cope with complex and ever-changing business logic and improves its overall usability and adaptability.

[0019] 2. The synchronization control module encapsulated within the database thread module serializes database write operations, maintaining data integrity and consistency. It prevents data write conflicts in multi-threaded, high-concurrency environments, ensuring each write operation is completed in an orderly manner, thus improving data storage reliability. Furthermore, it sets priorities for different database operation instruction queues, processing read and write operations according to priority. This ensures high-priority tasks are executed first, guaranteeing the timeliness of critical data read and write operations. This meets the stringent requirements for accuracy and orderliness in data read and write operations, such as in industrial control and medical devices, effectively avoiding data inconsistency, errors, or loss. Attached Figure Description

[0020] Figure 1 This is a system architecture diagram of the present invention. Detailed Implementation

[0021] The present invention will be further described below with reference to specific embodiments and accompanying drawings.

[0022] like Figure 1 The database serialization read / write method shown involves creating multiple business threads based on business requirements during software or program runtime, and allocating a corresponding database operation module to each business thread, with a one-to-one correspondence between the two.

[0023] The intermediary thread module exposes interfaces to business threads. The number and priority of these interfaces are consistent with the number and priority of the database operation instruction queue in the database thread module. Business threads can select interfaces of appropriate priority based on their needs, or multiple interfaces with different priorities. For each database operation request, an operation instruction ID and parameters are set. Finally, the database operation request and the database operation module are packaged together and placed in a temporary instruction queue before being passed to the intermediary thread module. The selection of the appropriate priority interface and the setting of the operation instruction ID and parameters are not sequential.

[0024] The intermediary thread module selects the priority of each database operation request in the temporary queue and sends the packaged data to the database operation instruction queue in the database thread module of the corresponding priority.

[0025] When the database operation instruction queue is not empty, the lock is released. The database thread module reads the packaged data in each queue in sequence according to the queue priority, and calls the database operation method through the operation instruction ID. Each database operation method has a corresponding unique operation instruction ID. After reading the packaged data, the database operation execution thread module passes parameters to the database operation method and finally executes the database operation method to complete a database operation. Each time an operation is completed, a signal is sent to notify the corresponding business thread. The business thread will perform subsequent business based on the received signal. The signal may contain information such as the result of the database query and whether the deletion operation is completed.

[0026] Repeat the operations performed when the database operation instruction queue is not empty until the database operation instruction queue is empty.

[0027] When executing instructions, the synchronization control module serializes the instructions to ensure data consistency and accuracy. The polymorphic data processing module implements specific database operations, including adding, deleting, querying and modifying the database. It can also perform database operations with other database interfaces (APIs) through structured query statements (SQL statements).

[0028] When the queue is completely empty, a lock is used to block the queue to prevent program lag or even crashes caused by continuous access to the database.

[0029] A database system that incorporates the aforementioned database serialization read / write method is also provided.

[0030] In existing technologies, most multi-threaded database operations utilize the officially provided thread pool technique, which consists of a thread pool manager, a work queue, and thread pool threads. In this approach, whenever the system generates a database operation task, a corresponding thread is started, and its priority is set during the thread initialization phase.

[0031] Thread pool technology requires proper configuration: The performance and effectiveness of thread pools are affected by configuration parameters, and the size of the thread pool, the size of the task queue, and other parameters need to be configured appropriately according to the specific application scenario and hardware environment.

[0032] This could lead to resource leaks: If threads in a thread pool remain idle for an extended period without being used, it could result in wasted or leaked resources.

[0033] Potential deadlock: When using thread pools, if there are dependencies between tasks, deadlock may occur, requiring extra attention and handling.

[0034] Due to the aforementioned issues, the instruction queue for database operations initiated by the program is limited and cannot be too complex, which also hinders the subsequent expansion of the software. However, this invention is not affected by this. In this invention, each business thread can be set with multiple different priorities simultaneously, making business operations more flexible; it can adapt to various application scenarios without additional configuration, achieving the effect of "write once, run anywhere"; when the database thread module is not used for a long time, it will be put into a waiting state through locks, without consuming additional resources; no deadlock problem has occurred after extensive data testing, and no additional handling is required.

[0035] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

[0036] While the specific embodiments of the present invention have been described above, they are not intended to limit the scope of protection of the present invention. Those skilled in the art should understand that various modifications or variations that can be made by those skilled in the art without creative effort based on the technical solutions of the present invention are still within the scope of protection of the present invention.

Claims

1. A database serialization read / write method, characterized in that, The steps are as follows: S1. Based on the software's operational requirements, create multiple business threads, an intermediary thread module, multiple database operation modules, and a database thread module. Allocate a corresponding database operation module to each business thread, with a one-to-one correspondence between the two. The database thread module has multiple built-in thread-safe database operation instruction queues. The intermediary thread module exposes the same number of interfaces as the database operation instruction queues, with each interface corresponding to one database operation instruction queue. Each database operation instruction queue has a different priority. The database thread module also encapsulates database operation methods. S2. Multiple business threads create database operation requirements, set operation instruction IDs and parameters for the database operation requirements, package the database operation requirements with the database operation module, and call the interface in the intermediary thread module according to the required priority. The business thread selects the interface with the corresponding priority according to its own needs, or selects multiple interfaces with different priorities, and then adds the packaged data to the temporary instruction queue. S3. The intermediary thread module, according to the invoked interface, transmits each packaged data to the database operation instruction queue of the corresponding priority within the database thread module, and releases the lock. S4. The database thread module reads the packaged data sequentially according to the priority of the database operation instruction queue, calls the database operation method according to the operation instruction ID and the parameters, and sends a signal to notify the corresponding business thread after each database operation method is completed. The business thread will perform business processing according to the signal. S5. Repeat step S4 until all the database operation instruction queues are empty, and then block the database operation instruction queues using the lock.

2. The database serialization read / write method as described in claim 1, characterized in that, The database operation methods include adding, deleting, querying, and modifying data in the database, and can also use structured query statements to perform database operations with other database interfaces.

3. The database serialization read / write method as described in claim 2, characterized in that, Each of the database operation methods has a unique corresponding operation instruction ID.

4. The database serialization read / write method as described in claim 1, characterized in that, The database thread module exposes an instruction set interface.

5. A database serialization read / write method as described in claim 1, characterized in that, The database thread module implements the serialization processing of database write operations through its internally encapsulated synchronization control module.

6. A database serialization read / write method as described in claim 1, characterized in that, The database operation method is implemented through a polymorphic data processing module.

7. A database system, characterized in that, It is equipped with a database serialization read / write method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Database request processing method, device, electronic equipment and medium

    CN112346834A

  • Multi-thread data processing method and device for database and electronic equipment

    CN114443764A