Decorating Method, Device, Storage Medium and Processor of Data Access Object

Through the decorative method of asynchronous query at the data access layer, the cooperation of child thread tasks and routing engines is used to solve the problem of slow response caused by busy database nodes or network jitter, and the transaction response speed and success rate of the financial system are improved.

CN116089024BActive Publication Date: 2025-07-22中国邮政储蓄银行股份有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211686129.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-27
Publication Date
2025-07-22
Estimated Expiration
2042-12-27

AI Technical Summary

Technical Problem

In the prior art, the response caused by busyness of a certain database node or network jitter is too slow, which affects the overall transaction response speed, especially in the core systems in the financial field.

Method used

The decorative method of data access objects is adopted. By obtaining the single query time period and the overall query time period, the Nth subthread task is issued for asynchronous query, and the N+1st subthread task is issued when the information is not obtained. Until the overall query time period or the information is obtained, the routing engine is used to select different database nodes for retry, ensuring that the query is completed within the specified time.

Benefits of technology

It improves the query success rate during the overall timeout time, solves the problem of too slow response caused by busy database nodes or network jitter, and improves transaction stability and response speed.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116089024B_ABST
    Figure CN116089024B_ABST
Patent Text Reader

Abstract

The present application provides a decoration method, device, storage medium and processor for a data access object. The method includes: an acquisition step of acquiring a single query time period and an overall query time period, where the single query time period is the time for asynchronous query of a database node; a first processing step of issuing an Nth sub-thread task; a second processing step of acquiring an execution result of the Nth sub-thread task, and in the case that the execution result indicates that the information of the database node is not acquired, issuing an (N + 1)th sub-thread task; repeating the second processing step until the overall query time period is reached or the information of the database node is acquired, and in each repeated execution process, N is incremented by 1 in sequence. This method can solve the technical problem that the response speed is too slow due to the busyness of a certain database node or network jitter, which affects the response speed of the overall transaction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of databases, and in particular, to a method, device, computer-readable storage medium, and processor for decorating a data access object. Background Art

[0002] In order to improve the system's concurrent access ability to the database and reduce the impact of a large number of transactions on the overall performance of the service, some solutions are usually adopted to vertically expand the database level.

[0003] Currently, the commonly used method is to adopt a read-write separation scheme. Read-write separation means that the main database processes transactional insert, update, and delete operations, while the slave database processes query operations. The evolution of this architecture has indeed solved most of the performance problems of concurrent access to the database, but it is not applicable to the financial field. Since the services of the core systems in the financial field are at the end of the call chain, many front-end systems have stable and strict requirements for the response success rate within a specified time, especially the timeliness of queries based on public services such as customer account card numbers. If there is an instantaneous performance or network jitter of a certain database node, it will cause a chain reaction of a series of front-end services, greatly affecting the user experience. Summary of the Invention

[0004] The main purpose of this application is to provide a method, device, computer-readable storage medium, and processor for decorating a data access object, so as to at least solve the technical problem in the prior art that the response is too slow due to the busyness of a certain database node or network jitter, which affects the response speed of the overall transaction.

[0005] To achieve the above object, according to one aspect of this application, a method for decorating a data access object is provided, including: an acquisition step of acquiring a single query time period and an overall query time period, where the single query time period is the time for asynchronously querying a database node, and the overall query time period includes multiple single query time periods; a first processing step of issuing the Nth sub-thread task, where the Nth sub-thread task is used to asynchronously query the database node, and N is a positive integer greater than or equal to 1; a second processing step of acquiring the execution result of the Nth sub-thread task. In the case where the execution result indicates that the information of the database node is not acquired, issue the (N + 1)th sub-thread task, where the (N + 1)th sub-thread task is used to asynchronously query the database node, and the database node corresponding to the information acquired by the Nth sub-thread task is different from the database node corresponding to the information acquired by the (N + 1)th sub-thread task; repeat the second processing step until the overall query time period is reached or the information of the database node is acquired. In each repeated execution process, N is incremented by 1 in turn.

[0006] Optionally, after the obtaining step, the method further includes: establishing, in the main thread, a session object for the data access request, where the session object is used to record the IDs and execution results of the subtask of each child thread.

[0007] Optionally, obtaining the execution result of the Nth child thread task includes: after the single query time period or when the Nth child thread task is completed, executing the main thread to determine whether the execution result exists in the session object.

[0008] Optionally, when the execution result indicates that the information of the database node has not been obtained, issuing the (N + 1)th child thread task includes: obtaining the remaining query time period, where the remaining query time period is the difference between the overall query time period and the single query time period; and when the remaining query time period is greater than the single query time period, issuing the (N + 1)th child thread task.

[0009] Optionally, the method further includes: controlling the main thread to transparently transmit the ID of the child thread task to the child thread, so that the child thread writes the operation result of the child thread task back to the session object according to the ID of the Nth child thread task.

[0010] Optionally, the method further includes: the Nth child thread task obtains the information of the database node through a routing engine; controlling the routing engine to delete the information of the database node obtained by the Nth child thread task, so that the database node corresponding to the information obtained by the Nth child thread task is different from the database node corresponding to the information obtained by the (N + 1)th child thread task.

[0011] Optionally, controlling the routing engine to select the priorities of the nodes of the database as the database nodes in the same computer room as the application service, the database nodes in another computer room in the same city as the application server, and the database nodes in a computer room in a different city from the application server.

[0012] To achieve the above object, according to one aspect of the present application, there is provided a decoration device for a data access object, including: an acquisition unit configured to perform an acquisition step of acquiring a single query time period and an overall query time period, where the single query time period is the time for asynchronously querying a database node, and the overall query time period includes a plurality of single query time periods; a first processing unit configured to perform a first processing step of issuing an Nth sub-thread task for asynchronously querying the database node, where N is a positive integer greater than or equal to 1; a second processing unit configured to perform a second processing step of acquiring an execution result of the Nth sub-thread task, and in the case where the execution result indicates that information of the database node is not acquired, issuing an (N + 1)th sub-thread task for asynchronously querying the database node, where the database node corresponding to the information acquired by the Nth sub-thread task is different from the database node corresponding to the information acquired by the (N + 1)th sub-thread task; and a third processing unit configured to repeat the second processing step until the overall query time period is reached or the information of the database node is acquired, and in each repeated execution process, N is incremented by 1 in sequence.

[0013] According to another aspect of the present application, there is provided a computer-readable storage medium, where the computer-readable storage medium includes a stored program, and when the program runs, it controls a device where the computer-readable storage medium is located to execute any one of the above methods.

[0014] According to still another aspect of the present application, there is provided a processor for running a program, and when the program runs, it executes any one of the above methods.

[0015] Applying the technical solution of the present application, first, obtain the single query time period and the overall query time period; then, issue the Nth sub-thread task for asynchronously querying the database node. Then, obtain the execution result of the Nth sub-thread task. In the case that the execution result indicates that the information of the database node has not been obtained, issue the (N + 1)th sub-thread task, and the (N + 1)th sub-thread task is used for asynchronously querying the database node. The database node corresponding to the information obtained by the Nth sub-thread task is different from the database node corresponding to the information obtained by the (N + 1)th sub-thread task. Finally, repeat issuing the sub-thread task until the overall query time period is reached or the information of the database node is obtained. By using the method of re-decoration on the access interface at the data access layer, and by issuing asynchronous query tasks batch by batch based on different database nodes and performing the data access operation of the DAO in the asynchronous task, before the first issuance, the overall timeout time specified by the pre-system is divided into multiple single query times according to the total number of database nodes. If the task issued within the first single query time fails to complete or an exception occurs, then continue to issue the task after the first single-node timeout to retry other database nodes, and the task of the first single node is still continuing to execute without interruption. And so on, among the numerous asynchronous query tasks issued, the task that completes the operation fastest will return the execution result first, and finally achieves the effect of improving the query success rate within the overall timeout, thereby solving the technical problem that the response is too slow due to a busy database node or network jitter, which affects the response speed of the overall transaction. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] The specification drawings forming a part of the present application are used to provide a further understanding of the present application. The schematic embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation to the present application. In the drawings:

[0017] Figure 1 The hardware structure block diagram of a mobile terminal showing a method for decorating an execution data access object according to an embodiment of the present application is shown;

[0018] Figure 2 The flowchart showing a method for decorating a data access object according to an embodiment of the present application is shown;

[0019] Figure 3 The overall flowchart showing a method for decorating a data access object according to an embodiment of the present application is shown;

[0020] Figure 4 The architecture diagram of a database deployed in a two-location and three-center showing a method for decorating a data access object according to an embodiment of the present application is shown;

[0021] Figure 5The block diagram of a decoration device for a data access object provided according to an embodiment of the present application is shown.

[0022] Among them, the above-mentioned drawings include the following reference numerals:

[0023] 102, processor; 104, memory; 106, transmission device; 108, input / output device. Detailed implementation manners

[0024] It should be noted that, without conflict, the embodiments in the present application and the features in the embodiments may be combined with each other. The present application will be described in detail below with reference to the drawings and in combination with the embodiments.

[0025] In order to enable those skilled in the art to better understand the solution of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.

[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily need to be used to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so as to implement the embodiments of the present application described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device including a series of steps or units does not necessarily need to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these process, method, product or device.

[0027] For the convenience of description, some nouns or terms related to the embodiments of the present application are described below:

[0028] DAO: DAO (Data Access Object), the DAO layer is the intermediate layer between the business logic layer and the database layer, which can reduce the development cost and improve the system maintenance efficiency. The business logic code realizes the interaction with the database by calling the DAO component.

[0029] Read-write separation: The master database processes transactional insert, update, and delete operations (INSERT, UPDATE, DELETE), while the slave database processes SELECT query operations. To ensure the stability of database products, many databases have a multi-node hot standby function. The first master database server is the production server that provides insert, update, and delete services to the outside world; the second and other database servers mainly perform read operations.

[0030] Decorator Pattern: The Decorator Pattern allows new functionality to be added to an existing object without changing its structure. This type of design pattern belongs to the structural pattern and it acts as a wrapper for the existing class. This pattern creates a decorator class to wrap the original class and provides additional functionality while maintaining the integrity of the class method signature.

[0031] As introduced in the background art, the instantaneous performance of a certain database node or network jitter in the prior art can cause a series of chain reactions in the front-end services, greatly affecting the user experience. To solve the above problems, embodiments of the present application provide a method, device, computer-readable storage medium, and processor for decorating a data access object.

[0032] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described with reference to the accompanying drawings in the embodiments of the present invention.

[0033] The method embodiments provided in the embodiments of the present application can be executed on a mobile terminal, a computer terminal, or a similar computing device. Taking running on a mobile terminal as an example, Figure 1 is a hardware structural block diagram of a mobile terminal for a method of decorating a data access object according to an embodiment of the present invention. As Figure 1 shown, the mobile terminal may include one or more ( Figure 1 only one is shown in Figure 1 processors 102 (the processors 102 may include, but are not limited to, processing devices such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data. Among them, the above mobile terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those of ordinary skill in the art can understand that Figure 1 the structure shown is only schematic and does not limit the structure of the above mobile terminal. For example, the mobile terminal may further include more or fewer components than Figure 1 shown, or have a different configuration from

[0034] The memory 104 can be used to store computer programs, such as software programs and modules of application software, such as the computer program corresponding to the display method of device information in the embodiments of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, implements the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some instances, the memory 104 may further include a memory remotely disposed relative to the processor 102, and these remote memories may be connected to the mobile terminal through a network. Examples of the above network include but are not limited to the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof. The transmission device 106 is used to receive or send data via a network. Specific examples of the above network may include a wireless network provided by a communication provider of the mobile terminal. In one instance, the transmission device 106 includes a network adapter (Network Interface Controller, abbreviated as NIC), which can be connected to other network devices through a base station and thus communicate with the Internet. In one instance, the transmission device 106 may be a radio frequency (Radio Frequency, abbreviated as RF) module, which is used to communicate with the Internet wirelessly.

[0035] In this embodiment, a decoration method for a data access object running on a mobile terminal, a computer terminal, or a similar computing device is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.

[0036] Figure 2 is a flowchart of the decoration method for a data access object according to an embodiment of the present application. As Figure 2 shown, the method includes the following steps:

[0037] Step S101, an acquisition step, to acquire a single query time period and an overall query time period, where the single query time period is the time for asynchronous query of a database node, and the overall query time period includes multiple single query time periods;

[0038] Specifically, the decorator redecorates the existing DAO access interface. After decoration, the DAO interface can read the overall timeout time configured according to the transaction, and the timeout time for waiting for the asynchronous query execution of a single database node, that is, the single-node timeout time, or directly allows the user to specify the above two timeout times personally.

[0039] Step S102, the first processing step, issue the Nth sub-thread task, where the Nth sub-thread task is used to asynchronously query the database node, and N is a positive integer greater than or equal to 1;

[0040] Specifically, the decorator will issue asynchronous DAO interface query tasks to multiple database nodes in batches according to these two timeout times. In the asynchronous sub-thread task, the database access logic of the original DAO is executed.

[0041] Step S103, the second processing step, obtain the execution result of the Nth sub-thread task. If the execution result indicates that the information of the database node has not been obtained, issue the (N + 1)th sub-thread task. The (N + 1)th sub-thread task is used to asynchronously query the database node. The database node corresponding to the information obtained by the Nth sub-thread task is different from the database node corresponding to the information obtained by the (N + 1)th sub-thread task;

[0042] Specifically, the database node corresponding to the information obtained by the Nth sub-thread task is different from the database node corresponding to the information obtained by the (N + 1)th sub-thread task. This method can save resources and prevent repeated queries.

[0043] Step S104, repeat the above second processing step until the overall query time period is reached or the information of the database node is obtained. In each repeated execution process, N is increased by 1 in turn.

[0044] Specifically, in the data access DAO layer, a decorator with an asynchronous thread issuing function is introduced. This asynchronous query decorator will issue asynchronous query thread sub-tasks in batches according to two timeout times, namely the overall query timeout time of this business request and the single-node query timeout time, and truly execute the DAO data access logic in the sub-task. When the first asynchronous query thread fails to complete the response of the result set within the specified single-node query timeout, the asynchronous decorator will issue the second asynchronous query thread to execute again. Similarly, when the second asynchronous query task fails to complete the execution within the single-node query timeout, it will be issued again, and so on until there is no remaining time or the information of the database node is queried.

[0045] Through this embodiment, first, obtain the single query time period and the overall query time period; then, issue the Nth sub-thread task for asynchronously querying the database node. Then, obtain the execution result of the Nth sub-thread task. In the case where the execution result indicates that the information of the database node has not been obtained, issue the (N + 1)th sub-thread task. The (N + 1)th sub-thread task is used for asynchronously querying the database node, and the database node corresponding to the information obtained by the Nth sub-thread task is different from the database node corresponding to the information obtained by the (N + 1)th sub-thread task. Finally, repeatedly issue sub-thread tasks until the overall query time period is reached or the information of the database node is obtained. By adopting the method of re-decoration on the access interface in the data access layer, by issuing asynchronous query tasks batch by batch based on different database nodes and performing DAO data access operations in the asynchronous tasks, before the first issuance, the overall timeout time specified by the pre-system will be divided into multiple single query times according to the total number of database nodes. If the task issued within the first single query time fails to complete or an exception occurs, after the first single-node timeout, continue to issue the task to retry other database nodes, and the task of the first single node is still continuing to execute without interruption. And so on, the task that completes the operation fastest among the numerous issued asynchronous query tasks will return the execution result first, finally achieving the effect of improving the query success rate within the overall timeout, thereby solving the technical problem of slow response due to a busy database node or network jitter, which affects the response speed of the overall transaction.

[0046] In order to enable those skilled in the art to more clearly understand the technical solution of the present application, the implementation process of the decoration method of the data access object of the present application will be described in detail below in combination with specific embodiments.

[0047] On the basis of including the above steps S101 to S104, after step S101, it further includes: step S105, establish a session object for the data access request in the main thread. The session object is used to record the IDs and execution results of each sub-thread task. In the above method, after the decorator main thread obtains the above two timeout times, before the first issuance of the task, the decorator main thread will create a session object for this data access request in the memory. The session object is used to record the issued task ID number.

[0048] In the specific implementation process, the above step S103 can be implemented through the following steps: Step S1031, after the above single query time period or when the above Nth sub-thread task is completed, execute the main thread to determine whether there is the above execution result in the above session object. After the decorator creates the current shared session, it will issue the first sub-thread task to perform the DAO interface operation. At this time, the main thread of the decorator enters the await state to wait for waking up, and the waking-up duration is the single-node query timeout duration. If the main thread of the decorator is woken up because it waits for the single-node query timeout duration, it will check the current shared session object to see if there is a completed operation result.

[0049] To further determine the time to issue the N+1th sub-thread task, the above step S103 of the present application can be implemented through the following steps: Step S1032, obtain the remaining query time period, where the remaining query time period is the difference between the above overall query time period and the above single query time period; Step S1033, when the remaining query time period is greater than the single query time period, issue the above N+1th sub-thread task. If there is no operation result in the session object, at this time, the main thread of the decorator will calculate the remaining duration according to the overall timeout duration and the starting duration of the first issue. If the remaining duration is greater than the single timeout duration, the main thread will continue to append and register the next batch of issue information to the session, then issue a task to the thread pool and the thread pool executes the sub-task of the DAO interface. Then the main thread of the decorator continues to wait to be woken up when the issued sub-task operation is completed, or is woken up because it waits for the single-node query timeout duration. During the waiting period for subsequent tasks, the previously issued tasks continue to execute without interruption, that is, the tasks issued first will execute for a longer time.

[0050] The above step S105 can also be implemented in other ways. For example: control the main thread to transparently transmit the ID of the above sub-thread task to the sub-thread, so that the above sub-thread writes the operation result of the above sub-thread task back to the above session object according to the ID of the above Nth sub-thread task. This method can further record the task ID and the operation result.

[0051] In some embodiments, the above-mentioned step S105 can be specifically implemented through the following steps: Step S1051, the above-mentioned Nth sub-thread task obtains the information of the above-mentioned database node through the routing engine; Step S1052, control the above-mentioned routing engine to delete the information of the above-mentioned database node obtained by the above-mentioned Nth sub-thread task, so that the above-mentioned database node corresponding to the information used by the above-mentioned Nth sub-thread task is different from the above-mentioned database node corresponding to the information used by the above-mentioned (N + 1)th sub-thread task. In this method, the sub-tasks executed asynchronously will hit the target database node through the routing engine during the execution process. When multiple asynchronous tasks are issued in one request, the routing engine can obtain the previously issued information according to the session object of the current request created by the decorator, so as to remove the used database nodes that have been previously issued, achieving the purpose of the decorator to avoid issuing tasks to the same database node multiple times in one request. As Figure 3 shown Figure 3 shows the overall flowchart of the decoration method according to the access object.

[0052] In some embodiments, the above-mentioned step S1051 can be specifically implemented through the following steps: Step S10511, control the above-mentioned routing engine to select the priorities of the nodes of the above-mentioned database as the database nodes in the same computer room as the application service, the database nodes in another computer room in the same city as the application server, and the database nodes in the computer rooms in different cities from the application server. In the application service in the financial field, in order to improve the disaster tolerance ability, the application service and the database cluster can be based on a deployment mode of two places and three centers, as Figure 4 shown Figure 4Shows the architecture diagram of the database deployment in two places and three centers. The mode of a database cluster with one master and multiple backups is adopted for deployment in two data centers in the same city and a remote data center in a different location. For the service based on the read-write separation architecture mode, it can fully utilize the existing multiple database node resources to maximize the overall stability of query transactions within the specified response time by sending asynchronous query tasks to multiple database nodes, so as to reduce the fluctuations or timeouts of the current query request caused by network jitter or performance jitter within a certain database. After reading the session object of the current request, the above routing engine removes the used nodes and selects the priority among the remaining database nodes as follows: first, select the database nodes in the same computer room as the application service, then select those without an exception mark, and then select according to the weight. If there are still no available database nodes, go to the other computer room in the same city of the application server and select the optimal hit database node according to dimensions such as no exception mark and weight. If there are still no available database nodes, go to the remote computer room in a different location and select the optimal database node according to dimensions such as no exception mark and weight. Information about whether the database node is in the same computer room as the application service, in the other computer room in the same city, in the remote computer room, and the weight can be read through the configuration method and loaded when the service starts. Any exception that occurs during the data access of the DAO will report the exception information, and an exception mark will be issued when the execution threshold is reached.

[0053] The embodiment of the present application also provides a decoration device for a data access object. It should be noted that the decoration device for a data access object in the embodiment of the present application can be used to execute the decoration method for a data access object provided in the embodiment of the present application. This device is used to implement the above-mentioned embodiment and preferred implementation manners, and those that have been described will not be repeated. As used hereinafter, the term "module" can be a combination of software and / or hardware that can achieve a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation in hardware, or a combination of software and hardware is also possible and contemplated.

[0054] The following introduces the decoration device for a data access object provided in the embodiment of the present application.

[0055] Figure 5 is a schematic diagram of the decoration device for a data access object according to the embodiment of the present application. As Figure 5 shown, the device includes:

[0056] An acquisition unit 10, configured to perform an acquisition step of acquiring the single query time period and the overall query time period, where the above single query time period is the time for performing an asynchronous query on the database node, and the above overall query time period includes multiple single query time periods;

[0057] Specifically, the decorator redecorates the existing DAO access interface. The decorated DAO interface can read the overall timeout configured according to the transaction and the timeout for waiting for the asynchronous query execution of a single database node, i.e., the single-node timeout, or allows the user to directly and individually specify the above two timeout times.

[0058] The first processing unit 20 is used for the first processing step of issuing the Nth sub-thread task. The Nth sub-thread task is used to perform an asynchronous query on the database node, where N is a positive integer greater than or equal to 1.

[0059] Specifically, the decorator issues asynchronous DAO interface query tasks to multiple database nodes in batches according to these two timeout times. In the asynchronous sub-thread task, the database access logic of the original DAO is executed.

[0060] The second processing unit 30 is used for the second processing step of obtaining the execution result of the Nth sub-thread task. In the case where the execution result indicates that the information of the database node has not been obtained, the (N + 1)th sub-thread task is issued. The (N + 1)th sub-thread task is used to perform an asynchronous query on the database node. The database node corresponding to the information obtained by the Nth sub-thread task is different from the database node corresponding to the information obtained by the (N + 1)th sub-thread task.

[0061] Specifically, the database node corresponding to the information obtained by the Nth sub-thread task is different from the database node corresponding to the information obtained by the (N + 1)th sub-thread task. The above device can save resources and prevent repeated queries.

[0062] The third processing unit 40 is used to repeat the above second processing step until the overall query time period is reached or the information of the database node is obtained. In each repeated execution process, N is incremented by 1 in sequence.

[0063] Specifically, in the data access DAO layer, a decorator with an asynchronous thread issuing function is introduced. This asynchronous query decorator issues asynchronous query thread sub-tasks in batches according to two timeout times, namely the overall query timeout time for the current business request and the single-node query timeout time, and truly executes the DAO data access logic in the sub-tasks. When the first asynchronous query thread fails to complete the response of the result set within the specified single-node query timeout, the asynchronous decorator will issue a second asynchronous query thread for execution. Similarly, when the second asynchronous query task fails to complete the execution within the single-node query timeout, it will be issued again, and so on until there is no remaining time or the information of the database node is queried.

[0064] Based on the above-mentioned acquisition unit, first processing unit, second processing unit, and third processing unit, after the acquisition unit, it further includes: a processing module, which is used to establish a session object for the data access request in the main thread, and the session object is used to record the IDs and execution results of each sub-thread task. In the above device, after the decorator main thread obtains the above two timeout times and before the first task is dispatched for the first time, the decorator main thread will create a session object for this data access request in the memory, and this session object is used to record the dispatched task ID number.

[0065] In the specific implementation process, the above second processing unit can be implemented through the following steps: an execution module, which is used to execute the main thread after the above single query time period or when the above Nth sub-thread task is completed, to determine whether there is the above execution result in the above session object. After the decorator creates this shared session, it will dispatch the first sub-thread task that executes the DAO interface operation. At this time, the decorator main thread enters the await state to wait for awakening, and the awakening duration is the single-node query timeout duration. If the decorator main thread is awakened because it waits for the single-node query timeout duration, it will check the above shared session object to see if there is a completed operation result.

[0066] In order to further determine the time for dispatching the N+1th sub-thread task, the above second processing unit of the present application can be implemented through the following steps: an acquisition module, which is used to acquire the remaining query time period, and the remaining query time period is the difference between the above overall query time period and the above single query time period; a dispatching module, which is used to dispatch the above N+1th sub-thread task when the above remaining query time period is greater than the above single query time period. If there is no operation result in the session object, at this time, the decorator main thread will calculate the remaining duration according to the overall timeout duration and the starting duration of the first dispatch. If this remaining duration is greater than the single timeout duration, the main thread will continue to append and register the next batch of dispatch information in the session, then dispatch tasks to the thread pool and the thread pool executes the sub-tasks of the DAO interface, and then the decorator main thread continues to wait to be awakened because the dispatched sub-tasks are completed, or because it waits for the single-node query timeout duration. During the waiting period for subsequent task dispatches, the previously dispatched tasks continue to execute without interruption, that is, the tasks dispatched first will execute for a longer time.

[0067] The above processing module can also be implemented in other ways. For example: controlling the main thread to transparently transmit the ID of the above sub-thread task to the sub-thread, so that the sub-thread writes the operation result of the above sub-thread task back to the above session object according to the ID of the above Nth sub-thread task. The device can further record the task ID and operation result.

[0068] In some embodiments, the above-mentioned processing module may be specifically implemented through the following steps: an acquisition sub-module, configured to obtain, through a routing engine, information of the above-mentioned database node for the above-mentioned Nth sub-thread task; a control sub-module, configured to control the above-mentioned routing engine to delete the information of the above-mentioned database node obtained by the above-mentioned Nth sub-thread task, so that the above-mentioned database node corresponding to the information used by the above-mentioned Nth sub-thread task is different from the above-mentioned database node corresponding to the information used by the above-mentioned (N + 1)th sub-thread task. In this device, the sub-tasks executed asynchronously will hit the target database node through the routing engine during the execution process. When multiple asynchronous tasks are issued in one request, the routing engine can obtain the previously issued information according to the session object of the current request created by the decorator, so as to remove the previously used database nodes that have been issued, achieving the purpose of the decorator to avoid issuing tasks to the same database node multiple times in one request. As Figure 3 shown Figure 3 shows the overall flowchart of the decoration method according to the access object.

[0069] In some embodiments, the above-mentioned control sub-module may be specifically implemented through the following steps: controlling the above-mentioned routing engine to select the priorities of the nodes of the above-mentioned database as the database nodes in the same computer room as the application service, the database nodes in another computer room in the same city as the application server, and the database nodes in a computer room in a different city from the application server. In the application service in the financial field, in order to improve the disaster tolerance ability, the application service and the database cluster are often based on the deployment mode of two places and three centers. As Figure 4 shown Figure 4The figure shows the architecture diagram of a database deployed in two locations with three centers. A database cluster mode with one master and multiple backups is adopted for deployment in two data centers in the same city and a remote data center in a different location. For the service based on the read-write separation architecture mode, it can fully utilize the existing resources of multiple database nodes to maximize the overall stability of query transactions within the specified response time by sending asynchronous query tasks to multiple database nodes, so as to reduce the fluctuations or timeouts of the current query request caused by network jitters or performance jitters within a certain database. After the above routing engine reads the session object of the current request, it removes the used nodes and selects the priority among the remaining database nodes as follows: first, the database nodes in the same computer room as the application service, then those selected without an exception mark, and then those selected according to the weight from high to low. If there are still no available database nodes, it goes to the other computer room in the same city of the application server and selects the optimal hit database node according to dimensions such as without an exception mark and then weight from high to low. If there are still no available database nodes, it goes to the remote computer room in a different location and selects the optimal database node according to dimensions such as without an exception mark and then weight from high to low. Information such as whether the database node is in the same computer room as the application service, in the other computer room in the same city, in the remote computer room, and the weight can be read through the configuration method and loaded when the service starts. Any exceptions occurring during the data access of the DAO will report the exception information, and an exception mark will be issued when the execution threshold is reached.

[0070] The decoration device of the above data access object includes a processor and a memory. The above acquisition unit, first processing unit, second processing unit, and third processing unit, etc., are all stored in the memory as program units, and the corresponding functions are implemented by the processor executing the above program units stored in the memory. The above modules are all located in the same processor; or, the above modules are respectively located in different processors in any combination form.

[0071] The processor contains a kernel, and the kernel retrieves the corresponding program unit from the memory. One or more kernels can be set, and the data access object can be decorated by adjusting the kernel parameters.

[0072] The memory may include non-permanent memory in a computer-readable medium, forms such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash memory (flash RAM), and the memory includes at least one storage chip.

[0073] An embodiment of the present invention provides a computer-readable storage medium. The above computer-readable storage medium includes a stored program, and when the above program runs, it controls the device where the above computer-readable storage medium is located to execute the decoration method of the above data access object.

[0074] Specifically, the decoration method of the data access object includes:

[0075] Step S101, the acquisition step, to obtain a single query time period and an overall query time period, where the single query time period is the time for asynchronous query of the database node, and the overall query time period includes multiple single query time periods;

[0076] Specifically, the decorator redecorates the existing DAO access interface. After decoration, the DAO interface can read the overall timeout time configured according to the transaction and the timeout time for waiting for the asynchronous query execution of a single database node, that is, the single-node timeout time, or allows the user to directly and personally specify the above two timeout times.

[0077] Step S102, the first processing step, to issue the Nth sub-thread task, where the Nth sub-thread task is used to perform an asynchronous query on the database node, and N is a positive integer greater than or equal to 1;

[0078] Specifically, the decorator will issue asynchronous DAO interface query tasks to multiple database nodes in batches according to these two timeout times. In the asynchronous sub-thread task, the database access logic of the original DAO is executed.

[0079] Step S103, the second processing step, to obtain the execution result of the Nth sub-thread task. In the case where the execution result indicates that the information of the database node has not been obtained, issue the (N + 1)th sub-thread task, where the (N + 1)th sub-thread task is used to perform an asynchronous query on the database node, and the database node corresponding to the information obtained by the Nth sub-thread task is different from the database node corresponding to the information obtained by the (N + 1)th sub-thread task;

[0080] Specifically, the database node corresponding to the information obtained by the Nth sub-thread task is different from the database node corresponding to the information obtained by the (N + 1)th sub-thread task. The above method can save resources and prevent repeated queries.

[0081] Step S104, repeat the above second processing step until the overall query time period is reached or the information of the database node is obtained. In each repeated execution process, N is incremented by 1 in sequence.

[0082] Specifically, in the data access DAO layer, a decorator with an asynchronous issuing thread is introduced. This asynchronous query decorator will issue asynchronous query thread subtasks in batches according to two timeout times, namely the overall query timeout time for this business request and the single-node query timeout time, and will truly execute the DAO data access logic in the subtasks. When the first asynchronous query thread fails to respond with the result set within the specified single-node query timeout, the asynchronous decorator will issue a second asynchronous query thread to execute. Similarly, when the second asynchronous query task fails to complete within the single-node query timeout, it will be issued again, and so on until there is no remaining time or information about the database node is retrieved.

[0083] Optionally, after the obtaining step, it further includes: establishing a session object for the data access request in the main thread, and the session object is used to record the IDs and execution results of each sub-thread task.

[0084] Optionally, obtaining the execution result of the Nth sub-thread task includes: after the single query time period or when the Nth sub-thread task is completed, executing the main thread to determine whether there is such an execution result in the session object.

[0085] Optionally, in the case where the execution result indicates that the information of the database node has not been obtained, issuing the (N + 1)th sub-thread task includes: obtaining the remaining query time period, where the remaining query time period is the difference between the overall query time period and the single query time period; and issuing the (N + 1)th sub-thread task when the remaining query time period is greater than the single query time period.

[0086] Optionally, the method further includes: controlling the main thread to transparently transmit the ID of the sub-thread task to the sub-thread, so that the sub-thread writes the operation result of the sub-thread task back to the session object according to the ID of the Nth sub-thread task.

[0087] Optionally, the method further includes: the Nth sub-thread task obtains the information of the database node through a routing engine; controlling the routing engine to delete the information of the database node obtained by the Nth sub-thread task, so that the database node corresponding to the information obtained by the Nth sub-thread task is different from the database node corresponding to the information obtained by the (N + 1)th sub-thread task.

[0088] Optionally, controlling the routing engine to select the priority of the nodes of the database as the database nodes in the same computer room as the application service, the database nodes in another computer room in the same city as the application server, and the database nodes in a computer room in a different city from the application server.

[0089] An embodiment of the present invention provides a processor, which is used to run a program. When the program runs, it executes a decoration method for a data access object.

[0090] Specifically, the decoration method for the data access object includes:

[0091] Step S101, an acquisition step, to acquire a single query time period and an overall query time period. The single query time period is the time for asynchronous query of a database node, and the overall query time period includes multiple single query time periods;

[0092] Specifically, the decorator redecorates the existing DAO access interface. The decorated DAO interface can read the overall timeout time configured according to the transaction and the timeout time for waiting for the asynchronous query execution of a single database node, that is, the single-node timeout time, or allows the user to directly and personally specify the above two timeout times.

[0093] Step S102, a first processing step, to issue the Nth sub-thread task, where the Nth sub-thread task is used to perform an asynchronous query on the database node, and N is a positive integer greater than or equal to 1;

[0094] Specifically, the decorator issues asynchronous DAO interface query tasks to multiple database nodes in batches according to these two timeout times. In the asynchronous sub-thread task, the database access logic of the original DAO is executed.

[0095] Step S103, a second processing step, to obtain the execution result of the Nth sub-thread task. In the case where the execution result indicates that the information of the database node has not been obtained, issue the (N + 1)th sub-thread task, where the (N + 1)th sub-thread task is used to perform an asynchronous query on the database node. The database node corresponding to the information obtained by the Nth sub-thread task is different from the database node corresponding to the information obtained by the (N + 1)th sub-thread task;

[0096] Specifically, the database node corresponding to the information obtained by the Nth sub-thread task is different from the database node corresponding to the information obtained by the (N + 1)th sub-thread task. This method can save resources and prevent repeated queries.

[0097] Step S104, repeat the above second processing step until the overall query time period is reached or the information of the database node is obtained. In each repeated execution process, N is incremented by 1 in turn.

[0098] Specifically, in the data access DAO layer, a decorator with an asynchronous issuing thread is introduced. This asynchronous query decorator will issue asynchronous query thread subtasks in batches according to two timeout times, namely the overall query timeout time for this business request and the single-node query timeout time, and will truly execute the DAO data access logic in the subtasks. When the first asynchronous query thread fails to respond with the result set within the specified single-node query timeout, the asynchronous decorator will issue a second asynchronous query thread to execute. Similarly, when the second asynchronous query task fails to complete within the single-node query timeout, it will be issued again, and so on until there is no remaining time or the information of the database node is queried.

[0099] Optionally, after the obtaining step, it further includes: establishing a session object for the data access request in the main thread, and the session object is used to record the IDs and execution results of each sub-thread task.

[0100] Optionally, obtaining the execution result of the Nth sub-thread task includes: after the single query time period or when the Nth sub-thread task is completed, executing the main thread to determine whether there is the execution result in the session object.

[0101] Optionally, in the case that the execution result indicates that the information of the database node is not obtained, issuing the (N + 1)th sub-thread task includes: obtaining the remaining query time period, where the remaining query time period is the difference between the overall query time period and the single query time period; and in the case that the remaining query time period is greater than the single query time period, issuing the (N + 1)th sub-thread task.

[0102] Optionally, the method further includes: controlling the main thread to transparently transmit the ID of the sub-thread task to the sub-thread, so that the sub-thread writes the operation result of the sub-thread task back to the session object according to the ID of the Nth sub-thread task.

[0103] Optionally, the method further includes: the Nth sub-thread task obtains the information of the database node through a routing engine; controlling the routing engine to delete the information of the database node obtained by the Nth sub-thread task, so that the database node corresponding to the information obtained by the Nth sub-thread task is different from the database node corresponding to the information obtained by the (N + 1)th sub-thread task.

[0104] Optionally, controlling the routing engine to select the priority of the database nodes as the database nodes in the same computer room as the application service, the database nodes in another computer room in the same city as the application server, and the database nodes in a different city from the application server.

[0105] An embodiment of the present invention provides a device, which includes a processor, a memory, and a program stored on the memory and executable on the processor. When the processor executes the program, at least the following steps are implemented:

[0106] Step S101, an acquisition step, to acquire a single query time period and an overall query time period. Among them, the single query time period is the time for asynchronously querying a database node, and the overall query time period includes multiple single query time periods;

[0107] Step S102, a first processing step, to issue the Nth sub-thread task, where the Nth sub-thread task is used to asynchronously query the database node, and N is a positive integer greater than or equal to 1;

[0108] Step S103, a second processing step, to acquire the execution result of the Nth sub-thread task. If the execution result indicates that the information of the database node has not been acquired, issue the (N + 1)th sub-thread task. The database node corresponding to the information acquired by the Nth sub-thread task is different from the database node corresponding to the information acquired by the (N + 1)th sub-thread task;

[0109] Step S104, repeat the above second processing step until the overall query time period is reached or the information of the database node is acquired. In each repeated execution process, N is incremented by 1 in sequence.

[0110] The device in this article can be a server, a PC, a PAD, a mobile phone, etc.

[0111] Optionally, after the acquisition step, it further includes: establishing a session object for a data access request in the main thread, where the session object is used to record the IDs and execution results of each sub-thread task.

[0112] Optionally, acquiring the execution result of the Nth sub-thread task includes: executing the main thread after the single query time period or when the Nth sub-thread task is completed to determine whether there is such an execution result in the session object.

[0113] Optionally, when the execution result indicates that the information of the database node has not been acquired, issuing the (N + 1)th sub-thread task includes: acquiring the remaining query time period, where the remaining query time period is the difference between the overall query time period and the single query time period; when the remaining query time period is greater than the single query time period, issuing the (N + 1)th sub-thread task.

[0114] Optionally, the above method further includes: controlling the main thread to transparently transmit the ID of the above sub-thread task to the sub-thread, so that the above sub-thread writes the operation result of the above sub-thread task back to the above session object according to the ID of the above Nth sub-thread task.

[0115] Optionally, the above method further includes: the above Nth sub-thread task obtains the information of the above database node through the routing engine; controlling the above routing engine to delete the information of the above database node obtained by the above Nth sub-thread task, so that the above database node corresponding to the information used by the above Nth sub-thread task is different from the above database node corresponding to the information used by the above (N + 1)th sub-thread task.

[0116] Optionally, control the above routing engine to select the priority of the nodes of the above database as the database nodes in the same computer room as the application service, the database nodes in another computer room in the same city as the application server, and the database nodes in a different city from the application server.

[0117] The present application also provides a computer program product, which, when executed on a data processing device, is adapted to execute a program initialized with at least the following method steps:

[0118] Step S101, an acquisition step, to acquire a single query time period and an overall query time period, wherein the above single query time period is the time for asynchronously querying the database node, and the above overall query time period includes a plurality of single query time periods;

[0119] Step S102, a first processing step, to issue the Nth sub-thread task, the above Nth sub-thread task is used to asynchronously query the above database node, and N is a positive integer greater than or equal to 1;

[0120] Step S103, a second processing step, to obtain the execution result of the above Nth sub-thread task. In the case that the above execution result indicates that the information of the above database node has not been obtained, issue the (N + 1)th sub-thread task, the above (N + 1)th sub-thread task is used to asynchronously query the above database node, and the above database node corresponding to the information used by the above Nth sub-thread task is different from the above database node corresponding to the information used by the above (N + 1)th sub-thread task;

[0121] Step S104, repeat the above second processing step until the overall query time period is reached or the information of the above database node is obtained, and in each repeated execution process, N is incremented by 1 in sequence.

[0122] Optionally, after the acquisition step, it further includes: establishing a session object for the data access request in the main thread, and the above session object is used to record the ID and execution result of each sub-thread task.

[0123] Optionally, obtaining the execution result of the Nth sub-thread task includes: after the single query time period or when the Nth sub-thread task is completed, executing the main thread to determine whether there is such an execution result in the session object.

[0124] Optionally, when the execution result indicates that the information of the database node is not obtained, issuing the (N + 1)th sub-thread task, including: obtaining the remaining query time period, where the remaining query time period is the difference between the overall query time period and the single query time period; when the remaining query time period is greater than the single query time period, issuing the (N + 1)th sub-thread task.

[0125] Optionally, the method further includes: controlling the main thread to transparently transmit the ID of the sub-thread task to the sub-thread, so that the sub-thread writes the operation result of the sub-thread task back to the session object according to the ID of the Nth sub-thread task.

[0126] Optionally, the method further includes: the Nth sub-thread task obtains the information of the database node through a routing engine; controlling the routing engine to delete the information of the database node obtained by the Nth sub-thread task, so that the database node corresponding to the information obtained by the Nth sub-thread task is different from the database node corresponding to the information obtained by the (N + 1)th sub-thread task.

[0127] Optionally, controlling the routing engine to select the priorities of the nodes of the database as the database nodes in the same computer room as the application service, the database nodes in another computer room in the same city as the application server, and the database nodes in a different city from the application server.

[0128] Obviously, those skilled in the art should understand that the above-mentioned modules or steps of the present invention can be implemented by a general-purpose computing device. They can be concentrated on a single computing device or distributed on a network composed of multiple computing devices. They can be implemented by program codes executable by the computing device. Thus, they can be stored in a storage device and executed by the computing device. And in some cases, the steps shown or described can be executed in a different order from here, or they can be separately made into individual integrated circuit modules, or multiple modules or steps among them can be made into a single integrated circuit module to implement. In this way, the present invention is not limited to any specific combination of hardware and software.

[0129] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of an all-hardware embodiment, an all-software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0130] The present application is described with reference to the flowcharts and / or block diagrams of methods, apparatuses (systems), and computer program products according to the embodiments of the present application. It should be understood that each flow and / or block in the flowchart and / or block diagram, and the combination of flows and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate means for implementing the functions specified in Figure 1 one or more of the processes Figure 1 or blocks.

[0131] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory generate a manufactured article including instruction means, and the instruction means implement the functions specified in Figure 1 one or more of the processes Figure 1 or blocks.

[0132] These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in Figure 1 one or more of the processes Figure 1 or blocks.

[0133] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and a memory.

[0134] The memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM), and / or non-volatile memory such as read-only memory (ROM) or flash memory (flash RAM). The memory is an example of computer-readable media.

[0135] A computer-readable medium includes permanent and non-permanent, removable and non-removable media that can implement information storage by any method or technology. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transitory medium that can be used to store information accessible by a computing device. As defined herein, a computer-readable medium does not include transitory computer-readable media, such as modulated data signals and carrier waves.

[0136] It should also be noted that the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, commodity or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or also includes elements inherent to such process, method, commodity or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, commodity or device comprising the element.

[0137] From the above description, it can be seen that the above embodiments of the present application achieve the following technical effects:

[0138] 1) In the decoration method of the data access object of this application, obtain the single query time period and the overall query time period; then, issue the Nth sub-thread task for asynchronous query of the database node. Then, obtain the execution result of the Nth sub-thread task. If the execution result indicates that the information of the database node has not been obtained, issue the (N + 1)th sub-thread task. The (N + 1)th sub-thread task is used for asynchronous query of the database node, and the database node corresponding to the information obtained by the Nth sub-thread task is different from the database node corresponding to the information obtained by the (N + 1)th sub-thread task. Finally, repeat issuing sub-thread tasks until the overall query time period is reached or the information of the database node is obtained. Adopt the method of re-decoration for the access interface in the data access layer. By issuing asynchronous query tasks in batches based on different database nodes and performing DAO data access operations in the asynchronous tasks, before the first issuance, the overall timeout time specified by the pre-system is divided into multiple single query times according to the total number of database nodes. If the task issued within the first single query time fails to complete or an exception occurs, continue to issue the task after the first single node timeout to retry other database nodes, and the task of the first single node is still executing without interruption. And so on. The task that completes the operation fastest among the numerous issued asynchronous query tasks will return the execution result first. Finally, the effect of improving the query success rate within the overall timeout is achieved, thereby solving the technical problem that the response is too slow due to a busy database node or network jitter, which affects the response speed of the overall transaction.

[0139] 2) The decoration device for the data access object of the present application, the acquisition unit is used for the acquisition step, to acquire the single query time period and the overall query time period, wherein the single query time period is the time for asynchronous query of the database node, and the overall query time period includes multiple single query time periods; the first processing unit is used for the first processing step, to issue the Nth sub-thread task, and the Nth sub-thread task is used for asynchronous query of the database node, where N is a positive integer greater than or equal to 1; the second processing unit is used for the second processing step, to acquire the execution result of the Nth sub-thread task, and in the case where the execution result indicates that the information of the database node has not been acquired, to issue the (N + 1)th sub-thread task, and the (N + 1)th sub-thread task is used for asynchronous query of the database node, and the database node corresponding to the information acquired by the Nth sub-thread task is different from the database node corresponding to the information acquired by the (N + 1)th sub-thread task; the third processing unit is used to repeat the second processing step until the overall query time period is reached or the information of the database node is acquired. In each repeated execution process, N is incremented by 1 in sequence. By using the method of re-decoration on the access interface at the data access layer, by issuing asynchronous query tasks batch by batch based on different database nodes and performing the data access operation of DAO in the asynchronous tasks, before the first issuance, the overall timeout time specified by the pre-system is divided into multiple single query times according to the total number of database nodes. If the task issued within the first single query time fails to complete or an exception occurs, then after the first single node timeout, the task is continued to be issued to retry other database nodes, and the task of the first single node is still continuing to execute without interruption. And so on, the task that completes the operation fastest among the numerous issued asynchronous query tasks will return the execution result first. Finally, the effect of improving the query success rate within the overall timeout is achieved, thereby solving the technical problem that the response is too slow due to the busyness of a certain database node or network jitter, which affects the response speed of the overall transaction.

[0140] The above are only the preferred embodiments of the present application and are not used to limit the present application. For those skilled in the art, various changes and modifications can be made to the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included within the protection scope of the present application.

Claims

1. A decoration method for a data access object, characterized in that, Including: An obtaining step, where the decorator decorates the DAO access interface, and uses the decorated DAO interface to obtain the single query time period and the overall query time period. Among them, the single query time period is the time for asynchronous query of the database node, and the overall query time period includes multiple single query time periods; A first processing step, where the decorator issues the Nth sub-thread task, and the Nth sub-thread task is used for asynchronous query of the database node, and N is a positive integer greater than or equal to 1; A second processing step, obtaining the execution result of the Nth sub-thread task. In the case where the execution result indicates that the information of the database node has not been obtained, the decorator issues the (N + 1)th sub-thread task, and the (N + 1)th sub-thread task is used for asynchronous query of the database node. The database node corresponding to the information obtained by the Nth sub-thread task is different from the database node corresponding to the information obtained by the (N + 1)th sub-thread task; Repeat the second processing step until the overall query time period is reached or the information of the database node is obtained. In each repeated execution process, N increases by 1 in turn; After the obtaining step, it further includes: establishing a session object for the data access request in the main thread, and the session object is used to record the IDs and execution results of each sub-thread task; The method further includes: controlling the main thread to transparently transmit the ID of the sub-thread task to the sub-thread, so that the sub-thread writes the operation result of the sub-thread task back to the session object according to the ID of the Nth sub-thread task.

2. The method according to claim 1, characterized in that, Obtaining the execution result of the Nth sub-thread task includes: After the single query time period or when the Nth sub-thread task is completed, execute the main thread to determine whether there is the execution result in the session object.

3. The method according to claim 1, wherein In the case where the execution result indicates that the information of the database node has not been obtained, issuing the (N + 1)th sub-thread task includes: Obtaining the remaining query time period, where the remaining query time period is the difference between the overall query time period and the single query time period; In the case where the remaining query time period is greater than the single query time period, issue the (N + 1)th sub-thread task.

4. The method according to claim 1, wherein The method further includes: The Nth sub-thread task obtains the information of the database node through the routing engine; Controlling the routing engine to delete the information of the database node obtained by the Nth sub-thread task, so that the database node corresponding to the information obtained by the Nth sub-thread task is different from the database node corresponding to the information obtained by the (N + 1)th sub-thread task.

5. The method according to claim 4, characterized in that Controlling the routing engine to select the priorities of the nodes of the database in turn as: the database node in the same computer room as the application service, the database node in another computer room in the same city as the application server, and the database node in a computer room in a different city from the application server.

6. A decoration device for a data access object, characterized in that, Including: An acquisition unit, configured to perform an acquisition step. A decorator decorates a DAO access interface, and uses the decorated DAO interface to obtain a single query time period and an overall query time period. Wherein, the single query time period is the time for asynchronously querying a database node, and the overall query time period includes multiple single query time periods; A first processing unit, configured to perform a first processing step. The decorator issues an Nth sub-thread task, and the Nth sub-thread task is used to asynchronously query the database node, where N is a positive integer greater than or equal to 1; A second processing unit, configured to perform a second processing step. Obtain the execution result of the Nth sub-thread task. When the execution result indicates that the information of the database node is not obtained, the decorator issues an (N + 1)th sub-thread task, and the (N + 1)th sub-thread task is used to asynchronously query the database node. The database node corresponding to the information obtained by the Nth sub-thread task is different from the database node corresponding to the information obtained by the (N + 1)th sub-thread task; A third processing unit, configured to repeat the second processing step until the overall query time period is reached or the information of the database node is obtained. In each repeated execution process, N is incremented by 1 in sequence; The apparatus further includes: a processing module, configured to establish a session object for a data access request in the main thread, and the session object is used to record the IDs and execution results of each sub-thread task; The processing module is further configured to control the main thread to transparently transmit the ID of the sub-thread task to the sub-thread, so that the sub-thread writes the operation result of the sub-thread task back to the session object according to the ID of the Nth sub-thread task; 7. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein when the program runs, it controls the device where the computer-readable storage medium is located to execute the method according to any one of claims 1 to 5; 8. A processor, characterized in that, The processor is configured to run a program, wherein when the program runs, it executes the method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Transaction processing method and system of distributed type database

    CN103345502A

  • Adaptive query routing in a replicated database environment

    US20180322157A1