Data query method, device and equipment

By using a preset table in the client to determine the existence of data identification and compare the log sequence number to determine the target database, the performance loss problem when querying data in the prior art is solved, and the expected effect of load balancing is achieved.

CN115048416BActive Publication Date: 2025-02-11CETC JINCANG (BEIJING) TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210700350.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-20
Publication Date
2025-02-11
Estimated Expiration
2042-06-20

AI Technical Summary

Technical Problem

In the prior art, the client needs to obtain LSN from the primary database and the backup database every time he querys data, resulting in performance losses of the primary database and the backup database, which in turn affects the effect of load balancing.

Method used

Use the preset table to determine whether the data identification requested by the query task exists. If it exists, compare the log sequence numbers in the main database and the backup database to determine the target database. If it does not exist, directly send the query task to the backup database.

Benefits of technology

The need to obtain LSN from the primary and backup databases is avoided, performance losses are reduced, and the expected results of load balancing are ensured.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115048416B_ABST
    Figure CN115048416B_ABST
Patent Text Reader

Abstract

The present invention provides a data query method, device and equipment, the method comprising: obtaining a query task and a first identifier of the first data requested by the query task; judging whether the first identifier is contained in a preset table to obtain a judgment result, wherein the preset table stores a plurality of second identifiers of second data, and the second data is stored in a main database and a backup database; determining a target database in the main database and the backup database according to the judgment result, and sending the query task to the target database. In the present invention, it can be determined based on the preset table whether the query is obtained from the main database or the backup database, without determining whether the queried data is obtained from the main database or the backup database based on the LSN of the data, that is, it is not necessary to obtain the LSN from the main database and the backup database, thereby avoiding performance loss of the main database and the backup database, and ensuring that the load balancing of the main database and the backup database can achieve the expected effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data query technology, and in particular to a data query method, device and equipment. Background Art

[0002] Data is stored in a database. In order to prevent data in the database (primary database) from being lost and unable to be recovered, a backup database is generally established, that is, the data stored in the backup database is a backup of the data stored in the primary database. Although the backup database can ensure data security, it will cause a waste of backup database resources.

[0003] In order to improve the resource utilization of the backup database, the client can query data from the backup database as well as the primary database, so that the backup database shares the pressure of the primary database, thereby achieving a load balancing effect.

[0004] In an exemplary technology, the client obtains the LSN (log sequence number) of the required query data from the primary database and the backup database, and then determines whether to obtain the query data from the primary database or the backup database based on the comparison results of the two LSNs. However, any change in the data in the database will cause the LSN to change, so that the client needs to obtain the LSN from the primary database and the backup database every time it queries data, thereby increasing the performance loss of the primary database and the backup database, resulting in the load balancing effect failing to achieve the expected effect. Summary of the invention

[0005] The present invention provides a data query method, device and equipment, which are used to solve the problem that the effect of load balancing cannot achieve the expected effect.

[0006] In one aspect, the present invention provides a data query method, comprising:

[0007] Acquire a query task and a first identifier of first data requested by the query task;

[0008] Determine whether the preset table contains the first identifier to obtain a determination result, wherein the preset table stores second identifiers of a plurality of second data, and the second data is stored in a primary database and a backup database;

[0009] A target database is determined in the primary database and the backup database according to the judgment result, and the query task is sent to the target database.

[0010] In one embodiment, determining the target database in the primary database and the backup database according to the judgment result includes:

[0011] When the judgment result is that the preset table contains the first identifier, obtaining a first log sequence number and a second log sequence number corresponding to the first identifier in the preset table, wherein the first log sequence number is a log sequence number of the first data in the primary database, and the second log sequence number is a log sequence number of the first data in the backup database;

[0012] Comparing the first log sequence number with the second log sequence number to obtain a comparison result;

[0013] A target database is determined in the primary database and the backup database according to the comparison result.

[0014] In one embodiment, determining the target database in the primary database and the backup database according to the comparison result includes:

[0015] When the comparison result is that the first log sequence number is different from the second log sequence number, determining the primary database as the target database;

[0016] When the comparison result is that the first log sequence number is the same as the second log sequence number, the backup database is determined as the target database.

[0017] In one embodiment, determining the target database in the primary database and the backup database according to the judgment result includes:

[0018] When the judgment result is that the preset table does not include the first identifier, the backup database is determined as the target database.

[0019] In one embodiment, before the step of determining whether the preset table contains the first identifier to obtain a determination result, the step further includes:

[0020] Establishing a communication connection with the primary database and the backup database;

[0021] Acquire each second data, and read the second identifier of the second data in the main database, the second data being data with a usage frequency greater than a preset usage frequency;

[0022] The preset table is constructed according to each of the second identifiers.

[0023] In one embodiment, the step of constructing the preset table according to each of the second identifiers includes:

[0024] Reading the third log sequence number of each of the second data in the primary database, and reading the fourth log sequence number of each of the second data in the backup database;

[0025] The preset table is constructed according to the second identifier corresponding to each of the second data, the third log sequence number and the fourth log sequence number.

[0026] In one embodiment, after the step of constructing the preset table according to the second identifier, the third log sequence number, and the fourth log sequence number corresponding to each of the second data, the step further includes:

[0027] Receiving data update information sent by the server, and determining a third identifier of the data corresponding to the update information, wherein the third identifier is any second identifier in the preset table;

[0028] The third log sequence number corresponding to the third identifier in the preset table is updated according to the update information, or the third log sequence number and the fourth log sequence number corresponding to the third identifier in the preset table are updated according to the update information.

[0029] In one embodiment, before the step of receiving the data update information sent by the server, the method further includes:

[0030] Sending a registration request for a notification service to the server according to the preset table, the notification service being used to notify the third serial number and the fourth serial number corresponding to each second identifier in the preset table to be updated, the server being in communication connection with the primary database and the backup database;

[0031] Receive the prompt information of successful registration fed back by the server.

[0032] On the other hand, the present invention also provides a data query device, comprising:

[0033] An acquisition module, used for acquiring a query task and a first identifier of the first data requested by the query task;

[0034] A determination module, configured to determine whether a preset table contains the first identifier to obtain a determination result, wherein the preset table stores second identifiers of a plurality of second data, and the second data is stored in a primary database and a backup database;

[0035] The determination module is further used to determine whether the preset table contains the first identifier to obtain a determination result, the preset table stores second identifiers of multiple second data, and the second data is stored in a main database and a backup database.

[0036] On the other hand, the present invention also provides a data query device, comprising: a memory and a processor;

[0037] The memory stores computer-executable instructions;

[0038] The processor executes the computer-executable instructions stored in the memory, so that the data query device executes the data query method as described above.

[0039] The data query method, device and equipment provided by the present invention obtain the first identifier of the query task and the data requested by the query task, and determine whether the first identifier is included in the preset table to obtain the judgment result, thereby determining the target database according to the judgment result, and then sending the query task to the target database. In the present invention, it can be determined based on the preset table whether the query is obtained from the main database or the backup database, without determining whether the queried data is obtained from the main database or the backup database based on the LSN of the data, that is, it is not necessary to obtain the LSN from the main database and the backup database, thereby avoiding the performance loss of the main database and the backup database, and ensuring that the load balancing of the main database and the backup database can achieve the expected effect. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.

[0041] Figure 1 A system architecture diagram for implementing the data query method of the present invention;

[0042] Figure 2 This is a flow chart of a first embodiment of a data query method of the present invention;

[0043] Figure 3 This is a flow chart of a second embodiment of a data query method of the present invention;

[0044] Figure 4 This is a flow chart of a third embodiment of a data query method of the present invention;

[0045] Figure 5 It is a functional module schematic diagram of the data query device of the present invention;

[0046] Figure 6 It is a schematic diagram of the hardware structure of the data query device of the present invention.

[0047] The above drawings show clear embodiments of the present disclosure, which will be described in more detail below. These drawings and text descriptions are not intended to limit the scope of the present disclosure in any way, but to illustrate the concepts of the present disclosure to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION

[0048] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present disclosure. Instead, they are merely examples of devices and methods consistent with some aspects of the present disclosure as detailed in the appended claims.

[0049] The present invention provides a data query method, which can be Figure 1 The system architecture diagram shown in the figure is implemented. Figure 1 As shown, the data query device 100 is in communication with the main database 200 and the backup database 300. The data query device 100 can be any device with data processing capabilities, for example, the data query device 100 is a computer. The data query device 100 is provided with a preset table, which contains multiple data identifiers.

[0050] The data query device 100 is loaded with multiple applications. When a certain application initiates a data query task, the identifier of the data requested for query is extracted based on the query task. If the identifier is not stored in the preset table, the data query device 100 sends the query task to the backup database 300. If the identifier of the data requested for query by the query task is located in the preset table, the data query device 100 sends the query task to the main database 200, and the main database 200 feeds the data back to the data query device 100.

[0051] The following specific embodiments are used to describe in detail the technical solutions of the present invention and how the technical solutions of the present application solve the above-mentioned technical problems. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present invention will be described below in conjunction with the accompanying drawings.

[0052] Reference Figure 2 , Figure 2 The first embodiment of the data query method of the present invention comprises the following steps:

[0053] Step S201: Obtain a query task and a first identifier of first data requested by the query task.

[0054] In this embodiment, the execution subject is a data query device 100. The data query device 100 can be a client of an application or a terminal equipped with the required functions. For ease of description, the term "device" is used below to refer to the data query device.

[0055] When the device receives a query task sent by other applications, it parses the query task, that is, parses the statement in the SQL of the query task, thereby extracting the identifier of the data requested by the query task. The data is defined as the first data, and the identifier is defined as the first identifier.

[0056] In this embodiment, the data may be stored in the backup database and the main database in the form of a table, and the data in the backup database and the main database have the same table name, and the table name of the data is the identifier of the data.

[0057] Step S202, determining whether the preset table contains the first identifier to obtain a determination result, wherein the preset table stores a plurality of second identifiers of second data, and the second data is stored in the main database and the backup database.

[0058] A preset table is stored in the device, and the preset table is pre-configured. The preset table stores identifiers of multiple data, and the data in the preset table is defined as second data. The second data can be data that the device is concerned about. For example, the second data is data that the device often uses, that is, the second data is data that has a usage frequency greater than a preset usage frequency. The preset usage frequency can be any suitable value. The usage frequency refers to the number of times it is used per unit time, or the usage frequency is the usage frequency. Each second data in the preset table is stored in the main database and the backup database.

[0059] After obtaining the first identifier of the data requested by the query task, the device determines whether the first identifier is included in the preset table to obtain a determination result.

[0060] Step S203: determine a target database in the primary database and the backup database according to the determination result, and send the query task to the target database.

[0061] After obtaining the judgment result, the device can determine the target database in the main database and the backup database based on the judgment result, and then send the query task to the target database. For example, when the judgment result is that the preset table does not contain the first identifier, that is, the data requested by the query task is not the data that the device is concerned about, the device determines the target database from the backup database.

[0062] After receiving the query task, the target database parses the query task to obtain the first identifier, and then determines the data corresponding to the first identifier from the stored data, and finally sends the data corresponding to the first identifier to the device, and the device outputs the data, thereby completing the device's query on the data. The device output data can be display data, or it can be sent to the application or terminal that sent the query task.

[0063] In this embodiment, the query task and the first identifier of the data requested by the query task are obtained, and it is determined whether the preset table contains the first identifier to obtain a judgment result, thereby determining the target database according to the judgment result, and then sending the query task to the target database. In the present invention, it can be determined based on the preset table whether to obtain the query from the main database or the backup database, without determining whether the queried data is obtained from the main database or the backup database based on the LSN of the data, that is, it is not necessary to obtain the LSN from the main database and the backup database, thereby avoiding the performance loss of the main database and the backup database, and ensuring that the load balancing of the main database and the backup database can achieve the expected effect.

[0064] Reference Figure 3 , Figure 3 2 is a flow chart of a second embodiment of the data query method of the present invention. Based on the first embodiment, step S203 includes:

[0065] Step S301, when the judgment result is that the preset table contains the first identifier, obtain the first log sequence number and the second log sequence number corresponding to the first identifier in the preset table, the first log sequence number is the log sequence number of the first data in the main database, and the second log sequence number is the log sequence number of the first data in the backup database.

[0066] In this embodiment, the backup database is a disaster recovery database. The disaster recovery database and the main database need to maintain certain data, so that there is a certain delay difference in data synchronization between the main database and the backup database, that is, the main database synchronizes data to the backup database in an asynchronous manner.

[0067] The data in the main database and the backup database has an LSN (log sequence number), which can be understood as a digital number. When data is stored in the main database and the backup database, the LSN of the data in the two databases is the same, and when the data changes, the main database first updates the data, and the LSN of the data in the main database and the LSN of the backup database are synchronously updated, and the updated LSN of the data in the main database and the backup database is also the same. For example, each time a certain data in the main database and the backup database is updated, the LSN of the data in the main database and the backup database increases or decreases by a preset value, such as 1. Since the main database synchronizes data to the backup database asynchronously, the backup database may not update data in time, that is, the LSN of the data in the main database is different from the LSN of the data in the backup database.

[0068] In this embodiment, the preset table stores the second data, the third log sequence number of the second data in the main database, and the fourth log sequence number of the first data in the backup database. If there are multiple backup databases, the preset table stores the log sequence numbers of the second data in all backup databases. The log sequence number is the LSN of the numerical number.

[0069] When the judgment result is that the preset table contains the first identifier, the device also needs to determine whether the latest version of the data queried by the query task has been updated to the backup database based on the log sequence numbers of the data in the main database and the backup database. To this end, the device obtains the first log sequence number and the second log sequence number corresponding to the first identifier in the preset table, the first log sequence number is the log sequence number of the first data in the main database, and the second log sequence number is the log sequence number of the first data in the backup database.

[0070] Step S302: compare the first log sequence number with the second log sequence number to obtain a comparison result.

[0071] The device compares the first log sequence number and the second log sequence number to obtain a comparison result. The comparison result may be that the first log sequence number is the same as the second log sequence number, or that the first log sequence number is different from the second log sequence number.

[0072] Step S303: determine the target database in the primary database and the backup database according to the comparison result.

[0073] The device determines the target database in the main database and the backup database according to the comparison result. Specifically, when the comparison result is that the first log sequence number is different from the second log sequence number, it can be determined that the backup database does not store the latest version of the data requested by the query task, that is, it is determined that the main database does not back up the incremental data of the data corresponding to the first identifier to the backup database. The device determines the main database as the target database, that is, sends the query task to the main database to obtain the data fed back by the main database.

[0074] When the first log sequence number is the same as the second log sequence number, it can be determined that the main database backs up the incremental data corresponding to the first identifier to the backup database, and the device determines the backup database as the target database, that is, sends the query task to the backup database, thereby obtaining the data corresponding to the first identifier sent by the backup database.

[0075] It should be noted that when there are multiple backup databases, the device needs to determine whether the first log sequence number is different from each second log sequence number to obtain a comparison result. If the comparison result is that the first log sequence number is different from each second log sequence number, the device determines the main database as the target database. If the comparison database has one or more second log sequence numbers that are the same as the first log sequence number, the backup database corresponding to the second log sequence number that is the same as the first log sequence number is determined as the target database.

[0076] In this embodiment, the log sequence number of the data in the primary database and the log sequence number of the data in the backup database is used to determine whether the data requested by the query task is the latest data in the backup database, ensuring that the data obtained by the device is the most recently updated data.

[0077] Reference Figure 4 , Figure 4 This is the third embodiment of the data query method of the present invention, based on the first or second embodiment, and before step S202, further comprising:

[0078] Step S401, establishing communication connections with a primary database and a backup database.

[0079] In this embodiment, the device needs to pre-configure a preset table. To this end, the device first establishes a communication connection with the main database and the backup database.

[0080] Step S402, acquiring each second data, and reading the second identifier of the second data in the main database, the second data being data with a usage frequency greater than a preset usage frequency.

[0081] After the device establishes a communication connection with the main database and the backup database, the device determines each second data. The second data may be data with a usage frequency greater than a preset usage frequency, or the second data may be data selected by a user.

[0082] Step S403: construct a preset table according to each second identifier.

[0083] After obtaining each second data, the device reads the second identifier corresponding to the second data from the main database or the backup database, so as to construct a preset table according to each second identifier.

[0084] Furthermore, in order to ensure that the device obtains the latest version of the data required for the query task, the preset table needs to store the log sequence number of the data corresponding to the second identifier in the main database and the backup database. In response, the device sends a query request for the log sequence number of the data corresponding to the second identifier to the main database, thereby reading the third log sequence number of the second data in the main database from the main database. The device then sends a query request for the log sequence number of the data corresponding to the second identifier to the backup database, thereby reading the fourth log sequence number of the second data in the backup database from the backup database.

[0085] The device constructs a preset table based on the second identifier, the third log sequence number and the fourth log sequence number corresponding to each second data. Specifically, the device associates the second identifier of the second data, the third log sequence number and the fourth log sequence number corresponding to the second data to obtain the associated information corresponding to the second data, that is, the associated information includes the identifier of the second data, the third log sequence number and the fourth log sequence number. The device then stores each second data in a blank table to obtain the preset table.

[0086] In this embodiment, the device constructs a preset table, so that the device can obtain the data required for the query task from the main database and the backup database based on the preset table.

[0087] In one embodiment, after the step of constructing a preset table according to the second identifier, the third log sequence number, and the fourth log sequence number corresponding to each second data, the method further includes:

[0088] A. Receive data update information sent by the server, and determine a third identifier of the data corresponding to the update information, where the third identifier is any second identifier in a preset table.

[0089] In this embodiment, a preset table of the device is stored in the server, and a trigger is set in the server. When the trigger of the server detects that the data corresponding to the identifier in the preset table has a change operation (such as adding, deleting or modifying), it can be identified that the log sequence number of the corresponding data in the main database has changed, and the device will send data update information to the device. The device receives the data update information sent by the server and determines the identifier of the data corresponding to the update information, which is defined as the third identifier.

[0090] B. Update the third log sequence number corresponding to the third identifier in the preset table according to the update information, or update the third log sequence number and the fourth log sequence number corresponding to the third identifier in the preset table according to the update information.

[0091] Since the server also stores a preset table, the third identifier is any identifier in the preset table. The device updates the third log sequence number of the third identifier in the preset table based on the update information, or updates the third log sequence number and the fourth log sequence number of the third identifier in the preset table based on the update information.

[0092] Specifically, the update information includes the identifier corresponding to the updated data in the preset table and the third log sequence number of the updated data in the main database. In addition, if the main database synchronizes the updated data to the backup database, the update information includes the identifier corresponding to the updated data in the preset table, the third log sequence number of the updated data in the main database, and the fourth log sequence number of the updated data in the backup database. That is, the device synchronously updates the third log sequence number in the preset table based on the update information, or updates the third log sequence number and the fourth log sequence number in the preset table based on the update information.

[0093] Furthermore, before the device receives the update information, the device needs to register for the notification service with the server. Specifically, the device sends a registration request for the notification service to the server based on the preset table. The registration request carries the preset table. The server creates a corresponding trigger for the device, and the trigger is used to detect whether the data in the preset table has changed. After completing the registration of the notification service for the device, the server sends a prompt message of successful registration to the device, that is, the device receives the prompt message of successful registration fed back by the server. It can be understood that the notification service is used to notify the third sequence log number and the fourth log sequence number corresponding to each second identifier in the preset table to be updated.

[0094] In addition, the server is in communication connection with the main database and the backup database, so that the trigger can detect the update of the data in the main database and the backup database. In addition, the preset table stored in the server includes the channel name needed to be used for the notification service, and the channel name is associated with the device identifier and stored. When the data change in the preset table is detected, the server feeds back the data update information to the device through the channel name.

[0095] In this embodiment, the device updates the log sequence number in the preset table through the update information sent by the server, thereby ensuring that the device can obtain the latest version of the data required for the query task.

[0096] The present invention also provides a data query device, referring to Figure 5 , the data query device 500 comprises:

[0097] An acquisition module 510 is used to acquire a query task and a first identifier of the first data requested by the query task;

[0098] A judgment module 520, configured to judge whether a preset table contains a first identifier to obtain a judgment result, wherein the preset table stores a plurality of second identifiers of second data, and the second data is stored in a main database and a backup database;

[0099] The determination module 530 is used to determine a target database in the primary database and the backup database according to the determination result, and send the query task to the target database.

[0100] In one embodiment, the data query device 500 includes:

[0101] An acquisition module 510 is configured to acquire a first log sequence number and a second log sequence number corresponding to the first identifier in the preset table when the result of the judgment is that the preset table contains the first identifier, wherein the first log sequence number is a log sequence number of the first data in the primary database, and the second log sequence number is a log sequence number of the first data in the backup database;

[0102] A comparison module, used for comparing the first log sequence number with the second log sequence number to obtain a comparison result;

[0103] The determination module 530 is used to determine the target database in the primary database and the backup database according to the comparison result.

[0104] In one embodiment, the data query device 500 includes:

[0105] A determination module 530, configured to determine the primary database as a target database when the comparison result shows that the first log sequence number is different from the second log sequence number;

[0106] The determination module 530 is configured to determine the backup database as the target database when the comparison result shows that the first log sequence number is the same as the second log sequence number.

[0107] In one embodiment, the data query device 500 includes:

[0108] The determination module 530 is configured to determine the backup database as the target database when the determination result is that the preset table does not contain the first identifier.

[0109] In one embodiment, the data query device 500 includes:

[0110] Establishing a module for establishing communication connections with a primary database and a backup database;

[0111] The acquisition module 510 is used to acquire each second data and read the second identifier of the second data in the main database, where the second data is data with a usage frequency greater than a preset usage frequency;

[0112] A building module is used to build a preset table according to each second identifier.

[0113] In one embodiment, the data query device 500 includes:

[0114] A reading module, used for reading the third log sequence number of each second data in the primary database, and reading the fourth log sequence number of each second data in the backup database;

[0115] A module is established, which is used to construct a preset table according to the second identifier, the third log sequence number and the fourth log sequence number corresponding to each second data.

[0116] In one embodiment, the data query device 500 includes:

[0117] A receiving module, used for receiving data update information sent by the server, and determining a third identifier of the data corresponding to the update information, where the third identifier is any second identifier in a preset table;

[0118] The updating module is used to update the third log sequence number corresponding to the third identifier in the preset table according to the updating information, or to update the third log sequence number and the fourth log sequence number corresponding to the third identifier in the preset table according to the updating information.

[0119] In one embodiment, the data query device 500 includes:

[0120] A sending module, used for sending a registration request for a notification service to a server according to a preset table, wherein the notification service is used for notifying that the third serial number and the fourth serial number corresponding to each second identifier in the preset table are updated, and the server is in communication connection with the primary database and the backup database;

[0121] The receiving module is used to receive the prompt information of successful registration fed back by the server.

[0122] Figure 6 The figure is a schematic diagram of the hardware structure of a data query device according to an exemplary embodiment.

[0123] The interactive device 600 may include: a processor 601, such as a CPU, a memory 602, and a transceiver 603. Those skilled in the art will appreciate that Figure 6 The structure shown in the figure does not constitute a limitation on the data query device, and may include more or less components than shown in the figure, or combine certain components, or arrange components differently. The memory 602 may be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as a static random access memory (SRAM), an electrically erasable programmable read-only memory (EEPROM), an erasable programmable read-only memory (EPROM), a programmable read-only memory (PROM), a read-only memory (ROM), a magnetic memory, a flash memory, a magnetic disk or an optical disk.

[0124] The processor 601 may call the computer program stored in the memory 602 to complete all or part of the steps of the above-mentioned data query method.

[0125] The transceiver 603 is used to receive information sent by an external device and send information to the external device.

[0126] A non-transitory computer-readable storage medium, when instructions in the storage medium are executed by a processor of a data query device, enables the data query device to execute the above-mentioned data query method.

[0127] A computer program product includes a computer program. When the computer program is executed by a processor of a data query device, the data query device is enabled to execute the above data query method.

[0128] Those skilled in the art will readily appreciate other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. The present invention is intended to cover any variations, uses or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The description and examples are to be regarded as exemplary only, and the true scope and spirit of the present disclosure are indicated by the following claims.

[0129] It should be understood that the present disclosure is not limited to the exact structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims

1. A data query method, characterized in that: include: Acquire a query task and a first identifier of first data requested by the query task; Establish communication connections with the primary database and backup database; Acquire each second data, and read the second identifier of the second data in the main database, the second data being data with a usage frequency greater than a preset usage frequency; Constructing a preset table according to each of the second identifiers; Determine whether the preset table contains the first identifier to obtain a determination result, wherein the preset table stores second identifiers of a plurality of second data, and the second data is stored in a primary database and a backup database; Determine a target database in the primary database and the backup database according to the judgment result, and send the query task to the target database; The step of constructing a preset table according to each of the second identifiers comprises: Reading the third log sequence number of each second data in the primary database, and reading the fourth log sequence number of each second data in the backup database; constructing the preset table according to the second identifier, the third log sequence number and the fourth log sequence number corresponding to each of the second data; Receiving data update information sent by the server, and determining a third identifier of the data corresponding to the update information, wherein the third identifier is any second identifier in the preset table; Update the third log sequence number corresponding to the third identifier in the preset table according to the update information, or update the third log sequence number and the fourth log sequence number corresponding to the third identifier in the preset table according to the update information; Before the step of receiving the update information of the data sent by the server, the method further includes: Sending a registration request for a notification service to the server according to the preset table, the notification service being used to notify the third serial number and the fourth serial number corresponding to each second identifier in the preset table to be updated, the server being in communication connection with the primary database and the backup database; Receive the prompt information of successful registration fed back by the server.

2. The data query method according to claim 1, characterized in that: Determining the target database in the primary database and the backup database according to the judgment result includes: When the judgment result is that the preset table contains the first identifier, obtaining a first log sequence number and a second log sequence number corresponding to the first identifier in the preset table, wherein the first log sequence number is a log sequence number of the first data in the primary database, and the second log sequence number is a log sequence number of the first data in the backup database; Comparing the first log sequence number with the second log sequence number to obtain a comparison result; A target database is determined in the primary database and the backup database according to the comparison result.

3. The data query method according to claim 2, characterized in that: Determining the target database in the primary database and the backup database according to the comparison result includes: When the comparison result is that the first log sequence number is different from the second log sequence number, determining the primary database as the target database; When the comparison result is that the first log sequence number is the same as the second log sequence number, the backup database is determined as the target database.

4. The data query method according to claim 1, characterized in that: Determining the target database in the primary database and the backup database according to the judgment result includes: When the judgment result is that the preset table does not include the first identifier, the backup database is determined as the target database.

5. A data query device, characterized in that: include: An acquisition module, used for acquiring a query task and a first identifier of the first data requested by the query task; Establishing a module for establishing communication connections with a primary database and a backup database; an acquisition module, used to acquire each second data and read a second identifier of the second data in the main database, wherein the second data is data with a usage frequency greater than a preset usage frequency; The establishing module is further used to construct a preset table according to each of the second identifiers; A determination module, configured to determine whether a preset table contains the first identifier to obtain a determination result, wherein the preset table stores second identifiers of a plurality of second data, and the second data is stored in a primary database and a backup database; The determination module is further used to determine whether the preset table contains the first identifier to obtain a determination result, the preset table stores second identifiers of multiple second data, and the second data is stored in the main database and the backup database; The establishment module is specifically used to read the third log sequence number of each second data in the primary database, and read the fourth log sequence number of each second data in the backup database; construct the preset table according to the second identifier corresponding to each second data, the third log sequence number and the fourth log sequence number; receive the data update information sent by the server, determine the third identifier of the data corresponding to the update information, and the third identifier is any second identifier in the preset table; Update the third log sequence number corresponding to the third identifier in the preset table according to the update information, or update the third log sequence number and the fourth log sequence number corresponding to the third identifier in the preset table according to the update information; A sending module, used for sending a registration request for a notification service to a server according to a preset table, wherein the notification service is used for notifying that the third serial number and the fourth serial number corresponding to each second identifier in the preset table are updated, and the server is in communication connection with the primary database and the backup database; The receiving module is used to receive the prompt information of successful registration fed back by the server.

6. A data query device, characterized in that: include: Memory and processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, so that the data query device executes the data query method according to any one of claims 1 to 4.

Citation Information

Patent Citations

  • Resource caching method, resource obtaining method, device and system thereof

    CN101668046A

  • Data query method, device and equipment based on master and slave databases and storage medium

    CN113961592A