CN113076343B - Data query method, device, equipment and storage medium - Google Patents

Data query method, device, equipment and storage medium Download PDF

Info

Publication number
CN113076343B
CN113076343B CN202110482141.1A CN202110482141A CN113076343B CN 113076343 B CN113076343 B CN 113076343B CN 202110482141 A CN202110482141 A CN 202110482141A CN 113076343 B CN113076343 B CN 113076343B
Authority
CN
China
Prior art keywords
database
time
slave
interaction information
query
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202110482141.1A
Other languages
Chinese (zh)
Other versions
CN113076343A (en
Inventor
赵帅
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Zhenshi Information Technology Co Ltd
Original Assignee
Beijing Jingdong Zhenshi Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Zhenshi Information Technology Co Ltd filed Critical Beijing Jingdong Zhenshi Information Technology Co Ltd
Priority to CN202110482141.1A priority Critical patent/CN113076343B/en
Publication of CN113076343A publication Critical patent/CN113076343A/en
Application granted granted Critical
Publication of CN113076343B publication Critical patent/CN113076343B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24553Query execution of query operations
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2358Change logging, detection, and notification
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The disclosure provides a data query method, a device, equipment and a storage medium, and relates to the technical field of Internet. The method comprises the following steps: acquiring interaction information, wherein the interaction information is used for inquiring data in a database, and the database comprises a master database and a slave database; responding to the judgment that the interaction information does not comprise a writing operation statement, and acquiring the latest updating time of the slave database, wherein the slave database is updated by calling the master database; acquiring the inquiry time of the interaction information; and determining a target database from the master database and the slave database according to the latest updating time of the slave database and the query time of the interaction information so as to call the target database to query data according to the interaction information. The method improves timeliness and accuracy of data query.

Description

Data query method, device, equipment and storage medium
Technical Field
The disclosure relates to the technical field of internet, and in particular relates to a data query method, a device, equipment and a readable storage medium.
Background
In today's World Wide Web (abbreviated as Web) system, as the amount of users increases, the pressure of "reading" in the operation of the system database is much greater than "writing", so the database is more and more separated from reading and writing for use by people. After the database is read and written separately, the operation is distributed, the related operation of writing data can be carried out in a master database (master database), and the related operation of reading data can be carried out in a slave database (slave database or read database), so that the pressure of the master database is reduced, and the performance of the master database is ensured. However, in the actual service processing process, a situation that the corresponding latest data cannot be timely queried when the slave database is queried due to the synchronous delay (master-slave delay) of the master database and the slave database often occurs, so that a series of service problems are generated.
In the related art, when data is queried in a database system separated from reading and writing, a query method is analyzed, and if the latest data needs to be queried, the query method is forced to walk a master library through codes or other configurations, so that the query is ensured not to be influenced by slave delay. However, this approach requires analysis of the query method each time a data query is performed, and modification of the code that allocates the database operations to ensure forced access to the master library when the latest data is queried. If the query method is adjusted, whether the code or configuration of the forced-walking main library needs to be added or not is needed to ensure the normal operation of the service of the method, but the code of the operation of the distributed database is not modified due to the reasons of neglect of a code writer, higher cost and the like, so that the service problem is caused by not checking the main library timely.
As described above, how to improve the timeliness and accuracy of data query is a problem to be solved.
The above information disclosed in the background section is only for enhancement of understanding of the background of the disclosure and therefore it may include information that does not form the prior art that is already known to a person of ordinary skill in the art.
Disclosure of Invention
The present disclosure aims to provide a data query method, a device and a readable storage medium, which at least overcome the problem of low timeliness and accuracy of data query caused by that related technologies query the latest data by analyzing the query method to a certain extent.
Other features and advantages of the present disclosure will be apparent from the following detailed description, or may be learned in part by the practice of the disclosure.
According to an aspect of the present disclosure, there is provided a data query method including: acquiring interaction information, wherein the interaction information is used for inquiring data in a database, and the database comprises a master database and a slave database; responding to the judgment that the interaction information does not comprise a writing operation statement, and acquiring the latest updating time of the slave database, wherein the slave database is updated by calling the master database; acquiring the inquiry time of the interaction information; and determining a target database from the master database and the slave database according to the latest updating time of the slave database and the query time of the interaction information so as to call the target database to query data according to the interaction information.
According to an embodiment of the present disclosure, the method further comprises: and calling the master database to update the slave database with preset frequency, and obtaining the latest update time of the slave database as the current time.
According to an embodiment of the disclosure, the method is performed by a preset service, which is obtained by encapsulating a middleware service.
According to an embodiment of the disclosure, the obtaining the query time of the interaction information includes: and obtaining the time of the interaction information reaching the preset service as the query time of the interaction information.
According to an embodiment of the disclosure, the determining the target database from the master database and the slave database according to the latest update time of the slave database and the query time of the interaction information includes: responding to the judgment that the latest updating time of the slave database is earlier than the inquiring time of the interaction information, and obtaining the current dormancy times by dormancy preset time; responding to the judgment that the dormancy time is not larger than a preset dormancy time threshold, and judging whether the latest update time of the slave database is earlier than the inquiry time of the interaction information or not after dormancy for the preset time; and determining that the slave database is the target database in response to determining that the latest update time of the slave database is later than the query time of the interaction information.
According to an embodiment of the disclosure, the determining the target database from the master database and the slave database according to the latest update time of the slave database and the query time of the interaction information further includes: and determining the main database as the target database in response to determining that the dormancy number is greater than a preset dormancy number threshold.
According to an embodiment of the disclosure, the determining the target database from the master database and the slave database according to the latest update time of the slave database and the query time of the interaction information includes: and determining that the slave database is the target database in response to determining that the latest update time of the slave database is later than the query time of the interaction information.
According to still another aspect of the present disclosure, there is provided a data query apparatus including: the interactive information acquisition module is used for acquiring interactive information, wherein the interactive information is used for inquiring data in a database, and the database comprises a master database and a slave database; an update time obtaining module, configured to obtain a latest update time of the slave database in response to determining that the interaction information does not include a write operation statement, where the slave database is updated by calling the master database; the inquiry time acquisition module is used for acquiring the inquiry time of the interaction information; and the target database determining module is used for determining a target database from the master database and the slave database according to the latest update time of the slave database and the query time of the interaction information so as to call the target database to query data according to the interaction information.
According to an embodiment of the present disclosure, the apparatus further comprises: and the slave database updating module is used for calling the master database to update the slave database at preset frequency and obtaining the latest update time of the slave database as the current time.
According to an embodiment of the disclosure, the device is implemented through a preset service, and the preset service is obtained by encapsulating a middleware service.
According to an embodiment of the disclosure, the query time obtaining module is further configured to obtain a time when the interaction information arrives at the preset service as a query time of the interaction information.
According to an embodiment of the disclosure, the target database determination module includes: the delay judging module is used for judging whether the latest update time of the slave database is earlier than the inquiry time of the interaction information; the dormancy module is used for responding to the fact that the latest update time of the slave database is earlier than the inquiry time of the interaction information, dormancy preset time and obtaining current dormancy times; the dormancy number judgment module is used for judging whether the dormancy number is larger than a preset dormancy number threshold value; the delay judging module is used for judging whether the latest update time of the slave database is earlier than the inquiry time of the interaction information or not after the preset time is dormant in response to judging that the dormancy time is not greater than the preset dormancy time threshold; the target database determination module is further configured to determine that the slave database is the target database in response to determining that the latest update time of the slave database is later than the query time of the interaction information.
According to an embodiment of the disclosure, the target database determining module is further configured to determine that the master database is the target database in response to determining that the number of sleeps is greater than a preset number of sleeps threshold.
According to an embodiment of the disclosure, the target database determining module is further configured to determine that the slave database is the target database in response to determining that a latest update time of the slave database is later than a query time of the interaction information.
According to yet another aspect of the present disclosure, there is provided an apparatus comprising: a memory, a processor, and executable instructions stored in the memory and executable in the processor, the processor implementing any of the methods described above when executing the executable instructions.
According to yet another aspect of the present disclosure, there is provided a computer-readable storage medium having stored thereon computer-executable instructions which, when executed by a processor, implement any of the methods described above.
According to the data query method provided by the embodiment of the disclosure, when the acquired interactive information for querying the data in the database is judged not to comprise the write operation statement, the latest update time for calling the master database to update the slave database is acquired, then the target database is determined from the master database and the slave database according to the latest update time of the slave database and the query time of the interactive information, so that the target database is called to query the data according to the interactive information, the database can be allocated for query operation according to the relation between the latest update time of the slave database and the query time of the interactive information, analysis of the query method is not needed, and the timeliness and accuracy of data query are improved.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The above and other objects, features and advantages of the present disclosure will become more apparent by describing in detail exemplary embodiments thereof with reference to the attached drawings.
Fig. 1 is a schematic diagram showing a system configuration in an embodiment of the present disclosure.
Fig. 2 shows a flowchart of a data query method in an embodiment of the present disclosure.
Fig. 3 shows a schematic diagram of another system architecture in an embodiment of the present disclosure.
Fig. 4 illustrates a schematic diagram of a task encapsulated in a preset service, according to an embodiment of the present disclosure.
Fig. 5 illustrates a flow chart of a method of determining a target database, according to an embodiment of the disclosure.
FIG. 6 is a schematic diagram illustrating a data query flow according to an example embodiment.
Fig. 7 illustrates a block diagram of a data querying device in an embodiment of the present disclosure.
Fig. 8 illustrates a block diagram of another data querying device in an embodiment of the present disclosure.
Fig. 9 shows a schematic structural diagram of an electronic device in an embodiment of the disclosure.
Detailed Description
Example embodiments will now be described more fully with reference to the accompanying drawings. However, the exemplary embodiments may be embodied in many different forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of the example embodiments to those skilled in the art. The drawings are merely schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and thus a repetitive description thereof will be omitted.
Furthermore, the described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a thorough understanding of embodiments of the disclosure. One skilled in the relevant art will recognize, however, that the aspects of the disclosure may be practiced without one or more of the specific details, or with other methods, apparatus, steps, etc. In other instances, well-known structures, methods, devices, implementations, or operations are not shown or described in detail to avoid obscuring aspects of the disclosure.
Furthermore, the terms "first," "second," and the like, are used for descriptive purposes only and are not to be construed as indicating or implying a relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defining "a first" or "a second" may explicitly or implicitly include one or more such feature. In the description of the present disclosure, the meaning of "a plurality" is at least two, such as two, three, etc., unless explicitly specified otherwise. The symbol "/" generally indicates that the context-dependent object is an "or" relationship.
In the present disclosure, unless explicitly specified and limited otherwise, terms such as "connected" and the like are to be construed broadly and, for example, may be electrically connected or may communicate with each other; can be directly connected or indirectly connected through an intermediate medium. The specific meaning of the terms in this disclosure will be understood by those of ordinary skill in the art as the case may be.
As described above, in the related art, the query method is analyzed every time the data query is performed, and the code for allocating the database operation may not be modified in time when the query method is changed, which may cause a business problem due to not checking the master database in time. Therefore, the present disclosure provides a data method, by adding an update log of a slave database to obtain update time, to timely determine whether corresponding time node data exists in the slave database during a current query operation, if yes, directly query the slave database data, if not, dormancy waits for data synchronization of the corresponding time node, then queries the slave database, if not, directly forcing the master database to query if not waiting until the data is synchronized to the slave database for a long time, so that timeliness and accuracy of the query can be ensured to the greatest extent.
Fig. 1 illustrates an exemplary system architecture 10 in which the data query method or data query apparatus of the present disclosure may be applied.
As shown in fig. 1, system architecture 10 may include a terminal device 102, a network 104, a server 106, and a database 108. The terminal device 102 may be a variety of electronic devices having a display screen and supporting inputs, outputs, including but not limited to smartphones, tablets, laptop portable computers, desktop computers, wearable devices, virtual reality devices, smart homes, and the like. The network 104 is the medium used to provide communication links between the terminal devices 102 and the server 106. The network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others. The server 106 may be a server or a cluster of servers, etc., such as an application server, a proxy server, etc., that provide various services. Database 108 may be large database software located on a server or small database software installed on a computer for storing data.
A user may interact with the server 106 and database 108 over the network 104 using the terminal device 102 to receive or transmit data, etc. For example, a user may operate on the terminal device 102, send a data query request to the server 106 over the network 104, and then the server 106 sends the data query request to the corresponding database 108. For another example, a user may receive data at terminal device 102 via network 104 forwarded by database 108 via server 106.
Data may also be received from database 108 or sent to database 108 at server 106 via network 104, etc. For example, the server 106 may be an application server for sending a user's data query request to the database 108 over the network 104. For another example, the server 106 may be a proxy server for assigning databases for query operations based on a user's data query requests, and sending the data query requests to the corresponding databases 108, and receiving query results from the databases 108.
It should be understood that the number of terminal devices, networks, servers and databases in fig. 1 are merely illustrative. There may be any number of terminal devices, networks, servers, and databases, as desired for implementation.
FIG. 2 is a flow chart illustrating a method of data querying according to an exemplary embodiment. The method shown in fig. 2 can be applied to a server side of the above system, or to a terminal device of the above system, for example.
Referring to fig. 2, a data query method 20 provided by an embodiment of the present disclosure may include the following steps.
In step S202, interaction information is acquired, the interaction information being used to query data in a database, the database comprising a master database and a slave database.
In some embodiments, the system for implementing the separation of reading and writing of the database may be, for example, a Web system, a user may issue a data query request at a client, and the client sends interaction information to an application server of the Web system for processing according to the data query request, where the interaction information may be, for example, an interaction sentence, such as a structured query language (Structured Query Language, SQL), and a programming language for querying and updating the database and managing the relational database system.
In some embodiments, read-write separation may be implemented based on a middleware service, and when data query is performed, an interactive sentence generated at a client is sent to the middleware service to be distributed to a master library or a slave library in an operation manner, for example, a relational database management system MySQL may implement read-write separation by using the middleware service MySQL proxy, and then, the interactive sentence is processed through MySQL proxy to connect with a corresponding database.
In some embodiments, the interactive statements may include write operation statements and read operation statements. The write operation statements may include, for example, a data definition language (Data Definition Language, DDL) and a data operation language (Data Manipulation Language, DML). Among them, DDL is mainly used in defining or changing the structure of the TABLE (TABLE), data type, link and constraint among TABLEs, etc. initialization work, mostly used in setting up the TABLE, the main commands are Creation (CREATE), replacement (ALTER), DROP (DROP), etc.; DML is a language used to manipulate data in a database, and is mainly ordered by Selection (SELECT), UPDATE (UPDATE), INSERT (INSERT), DELETE (DELETE), etc. The read operation statement may include, for example, a data query language (Data Query Language, DQL) whose basic structure is a query block composed of a SELECT clause, a source (FROM) clause, and a (WHERE) clause.
In step S204, in response to determining that the write operation statement is not included in the interaction information, a latest update time of the slave database is acquired, wherein the slave database is updated by calling the master database. If the interactive information is judged not to include a writing operation statement, a subsequent step can be performed to judge whether the slave library can be connected.
In some embodiments, the data query method provided by the embodiments of the present disclosure may be performed through a preset service, which is obtained by encapsulating a middleware service. A detailed description of the preset service may refer to fig. 3.
In some embodiments, the master database is called to update the slave database with a preset frequency, and the latest update time of the slave database is obtained as the current time, and the specific implementation can refer to fig. 3 and 4.
In some embodiments, when it is determined that the interactive statement includes a write operation statement, e.g., a DDL and/or a DML, the master library is determined to be the target database, i.e., the master library connection is selected for data manipulation.
In step S206, the inquiry time of the interaction information is acquired. The query time of the interaction information can be used for comparing with the update time of the slave library to judge whether the data of the slave library is updated to all the data before the query time point.
In some embodiments, the time at which the interaction information arrives at the preset service may be obtained as the query time of the interaction information.
In step S208, a target database is determined from the master database and the slave database according to the latest update time of the slave database and the query time of the interaction information, so as to invoke the target database to query data according to the interaction information. And judging whether the data of the current slave database is updated to all the data before the query time point according to the sequence relation between the latest update time of the slave database and the query time of the interaction information, and further selecting to connect the master database or the slave database. The specific embodiment can refer to fig. 5.
According to the data query method provided by the embodiment of the disclosure, when the acquired interactive information for querying the data in the database is judged not to include the write operation statement, the latest update time for calling the master database to update the slave database is acquired, and then the target database is determined from the master database and the slave database according to the latest update time of the slave database and the query time of the interactive information so as to call the target database to query the data according to the interactive information, so that the database can be allocated for query operation according to the relation between the latest update time of the slave database and the query time of the interactive information, analysis of the query method is not needed, and the timeliness and accuracy of data query are improved.
The method does not use the secondary library state parameter' Seconds (seconds_Behind_Master) of the secondary library in MySQL to judge the data delay of the secondary library, and can avoid that the value of the secondary_Behind_Master obtained by recording input and output can not accurately display the delay time of the data under the conditions such as network delay.
Fig. 3 illustrates another exemplary system architecture 30 to which the data query method or data query apparatus of the present disclosure may be applied. As shown in fig. 3, the user 302 may include a plurality of users, each of which connects to the service 304 in the web system at respective end users 1, 2, and 3 … …, and different users connect different service nodes in the service 304, for example, the user 1 connects to the service 1, the user 2 connects to the service 2, the user 3 connects to the service 3, and different service nodes are aggregated to the preset service 3042 for performing operation allocation processing, so as to call the corresponding master library 3062 or slave libraries 1 and 2 in the database 306 according to the operation corresponding to the interactive sentence.
The preset service 3042 based on replication of the SQL Statement (SBR) of the hosting synchronization may be obtained by encapsulating the middleware service MySQL proxy. First, a table "slave library update time (t_slave)" is created in the slave library, and the table may have only one piece of data, and the field name of this piece of data is update time (update_time), for recording the update time of the slave library. The content encapsulated in the preset service 3042 may include tasks of updating the slave library, and fig. 4 is a schematic diagram illustrating the tasks encapsulated in the preset service according to an embodiment of the present disclosure, as shown in fig. 4, and as described in the implementation of step S204, the master library may be called to update the slave library data at a preset frequency (e.g., every k milliseconds, where k is a positive integer) (S2044), and update the current time once into t_slave (S2042), where the update interval k of t_slave may be configured according to the actual situation. The process of performing the target database determination may also be encapsulated in a preset service 3042, and specific embodiments of the target database determination method may refer to fig. 5 and 6.
According to the system architecture provided by the embodiment of the disclosure, the middleware service is packaged, whether the query method needs to walk the main library or not is not needed to be judged when query is performed each time, and the target database is determined after the slave library delay judgment is performed by executing the t_slave update time in the preset service.
Fig. 5 illustrates a flow chart of a method of determining a target database, according to an embodiment of the disclosure. The method shown in fig. 5 may be applied to, for example, a server side of the above system, or may be applied to a terminal device of the above system.
Referring to fig. 5, a target database determination method 50 provided by an embodiment of the present disclosure may include the following steps.
In step S502, in response to determining that the latest update time of the slave database is later than the query time of the interaction information, it is determined that the slave database is the target database. In the case where the latest update time of the slave database is later than the query time of the interaction information, it can be considered that the data of the slave database has been updated to all the data of the master database before the query time, and thus the slave database can be called for data query.
In step S504, in response to determining that the latest update time from the database is earlier than the inquiry time of the interaction information, the current number of sleeps is acquired by the sleep preset time. In the case that the latest update time of the slave database is earlier than the query time of the interaction information, it is considered that all data of the master database is not updated to the data of the slave database before the query time, and the preset dormancy time may be, for example, n milliseconds, where n is a positive number, the value of n may be configured according to the actual situation, and the number of dormancy is recorded, for example, the value of the "number of dormancy" field may be increased by one. Through the hibernation operation, all data of the master library may be awaited from the update of the library data to the query time ago.
In step S506, in response to determining that the number of sleeps is not greater than the preset number of sleeps threshold, it is again determined whether the latest update time from the database is earlier than the inquiry time of the interaction information after the preset number of sleeps. The preset dormancy frequency threshold m can be configured according to actual conditions, wherein m is a positive integer and is used for limiting dormancy frequency, so that overlong waiting time is avoided. After determining again whether the latest update time from the database is earlier than the inquiry time of the interaction information, the process returns to step S502 or step S504 according to the determination result.
In step S508, in response to determining that the number of sleeps is greater than the preset number of sleeps threshold, the primary database is determined to be the target database. When the current dormancy frequency is greater than the preset dormancy frequency threshold value, the delay time of the slave library is considered to be too long to meet the query requirement, and the master library is directly called for query.
According to the target database determining method provided by the embodiment of the disclosure, whether the corresponding time node data exists in the slave database is judged in time by adding the synchronous log of the database, if yes, the slave database data is directly inquired, if not, the slave database inquiry is carried out after waiting for the data synchronization of the corresponding time node, and if not, the master database inquiry is directly forced, and the timeliness and the accuracy of the inquiry are ensured to the greatest extent. The method determines the latest synchronization time of each slave library through the own synchronization mechanism of MySQL, thereby confirming whether the slave library can be directly inquired or not, and ensuring the accuracy of data. For the situation that delay occurs between the master and the slave at a certain time point, the data synchronization can be waited or the corresponding query statement can be forced to directly walk the master library, so that the accuracy of the query data is ensured. For a slave library with larger master-slave delay, the slave library is prevented from being queried, and the accuracy of data query is ensured.
FIG. 6 is a schematic diagram illustrating a data query flow according to an example embodiment. As shown in fig. 6, the flow starts (S602), firstly, it is determined whether the interactive statement SQL contains a write operation statement such as DML or DDL (S604), and if DML and/or DDL operations are contained, the main library operation is directly called (S606); if no DML and/or DDL operations are involved, i.e., only DQL operations are involved, a determination is made as to whether to invoke the slave library. The update time of the current slave library table t_slave is first queried (S608), and it is determined whether the update time of the slave library is later than the time (query time) when the current DQL reaches the preset service (S610). If the update time of the slave library is later than the time when the current DQL reaches the preset service, it is considered that the data of the slave library has been updated to all the data before the execution of the time when the DQL reaches the preset service, this slave library is called (S612), and the corresponding DQL is executed. If the update time of the slave library is earlier than the current DQL reaching the preset service time, it is considered that all data before the execution of the time from the update of the data of the slave library to the DQL reaching the preset service is not updated, and a sleep preset time (for example, n ms) is performed (S614), and the current sleep number is obtained by the sleep number +1. Then, it is determined whether the current sleep number is greater than a preset threshold m (S616), and if the sleep number is not greater than m, the process returns to S608 and S610 to continue the determination. If the number of sleeps is greater than m, the slave library delay time is considered too long to meet the query requirement, and the master library is directly called for query (S618).
According to the data query method provided by the embodiment of the disclosure, the data delay time of the master-slave delay of each slave library can be perceived in time before each DQL is executed, so that the accuracy of query statement data of each slave library is ensured. For the situation that the slave library is delayed, after waiting for a certain time through dormancy, judging whether the delay time of the slave library meets the requirement of inquiry time again. For the situation that the delay time of the slave library is too long to meet the query, the slave library can timely sense and ensure the accuracy of the data by walking the master library. For the problem that the slave library is always delayed, the method can also sense the problem in time, so that the DQL is prevented from calling the slave library.
Fig. 7 is a block diagram illustrating a data querying device, according to an example embodiment. The apparatus shown in fig. 7 may be applied to, for example, a server side of the system 10, or may be applied to a terminal device of the system.
Referring to fig. 7, an apparatus 70 provided by an embodiment of the present disclosure may include an interaction information acquisition module 702, an update time acquisition module 704, a query time acquisition module 706, and a target database determination module 708.
The interaction information acquisition module 702 may be configured to acquire interaction information for querying data in a database, the database including a master database and a slave database.
The update time acquisition module 704 may be configured to acquire a latest update time of the slave database in response to determining that the write operation statement is not included in the interaction information, where the slave database is updated by calling the master database.
The query time acquisition module 706 may be configured to acquire a query time of the interaction information.
The target database determination module 708 may be configured to determine a target database from the master database and the slave database based on a latest update time of the slave database and a query time of the interaction information to invoke the target database to query data based on the interaction information.
Fig. 8 is a block diagram illustrating another data querying device, according to an example embodiment. The apparatus shown in fig. 8 may be applied to, for example, a server side of the system 10, or may be applied to a terminal device of the system.
Referring to fig. 8, an apparatus 80 provided by an embodiment of the present disclosure may include an interaction information acquiring module 802, a slave library updating module 803, an update time acquiring module 804, a query time acquiring module 806, and a target database determining module 808, and the target database determining module 808 may include a delay judging module 8082, a sleep module 8084, and a sleep number judging module 8086. The device is realized through a preset service, and the preset service is obtained by packaging the middleware service.
The interaction information acquisition module 802 may be configured to acquire interaction information for querying data in a database including a master database and a slave database.
The slave database update module 803 may be configured to invoke the master database to update the slave database at a preset frequency, and obtain the latest update time of the slave database as the current time.
The update time acquisition module 804 may be configured to acquire a latest update time of the slave database in response to determining that the write operation statement is not included in the interaction information, where the slave database is updated by calling the master database.
The query time acquisition module 806 may be configured to acquire a query time of the interaction information.
The query time acquisition module 806 may be further configured to acquire a time when the interaction information arrives at the preset service as a query time of the interaction information.
The target database determination module 808 may be configured to determine a target database from the master database and the slave database based on a latest update time of the slave database and a query time of the interaction information to invoke the target database to query data based on the interaction information.
The delay determination module 8082 may be configured to determine whether the latest update time from the database is earlier than the query time of the interaction information.
The delay determination module 8082 may be further configured to, in response to determining that the number of sleeps is not greater than the preset number of sleeps threshold, again determine whether a latest update time from the database is earlier than a query time for the interaction information after the preset number of sleeps.
The sleep module 8084 may be configured to obtain the current number of sleeps in response to determining that the latest update time from the database is earlier than the query time for the interaction information by a sleep preset time.
The sleep number determination module 8086 may be configured to determine whether the sleep number is greater than a preset sleep number threshold.
The target database determination module 808 may also be operable to determine that the slave database is the target database in response to determining that the latest update time of the slave database is later than the query time of the interaction information.
The target database determination module 808 may be further configured to determine the primary database as the target database in response to determining that the number of sleeps is greater than a preset number of sleeps threshold.
The target database determination module 808 may also be operable to determine that the slave database is the target database in response to determining that the latest update time of the slave database is later than the query time of the interaction information.
Specific implementation of each module in the apparatus provided in the embodiments of the present disclosure may refer to the content in the foregoing method, which is not described herein again.
Fig. 9 shows a schematic structural diagram of an electronic device in an embodiment of the disclosure. It should be noted that the apparatus shown in fig. 9 is only used as an example of a computer system, and should not impose any limitation on the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 9, the apparatus 900 includes a Central Processing Unit (CPU) 901, which can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 902 or a program loaded from a storage section 908 into a Random Access Memory (RAM) 903. In the RAM 903, various programs and data necessary for the operation of the device 900 are also stored. The CPU901, ROM 902, and RAM 903 are connected to each other through a bus 904. An input/output (I/O) interface 905 is also connected to the bus 904.
The following components are connected to the I/O interface 905: an input section 906 including a keyboard, a mouse, and the like; an output portion 907 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and a speaker; a storage portion 908 including a hard disk or the like; and a communication section 909 including a network interface card such as a LAN card, a modem, or the like. The communication section 909 performs communication processing via a network such as the internet. The drive 910 is also connected to the I/O interface 905 as needed. A removable medium 911 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is installed as needed on the drive 910 so that a computer program read out therefrom is installed into the storage section 908 as needed.
In particular, according to embodiments of the present disclosure, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flowcharts. In such an embodiment, the computer program may be downloaded and installed from the network via the communication portion 909 and/or installed from the removable medium 911. The above-described functions defined in the system of the present disclosure are performed when the computer program is executed by a Central Processing Unit (CPU) 901.
It should be noted that the computer readable medium shown in the present disclosure may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this disclosure, a computer-readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present disclosure, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, fiber optic cable, RF, etc., or any suitable combination of the foregoing.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The modules described in the embodiments of the present disclosure may be implemented in software or hardware. The described modules may also be provided in a processor, for example, as: a processor includes an interaction information acquisition module, an update time acquisition module, a query time acquisition module, and a target database determination module. The names of these modules do not constitute a limitation on the module itself in some cases, and for example, the interaction information acquisition module may also be described as "a module that acquires interaction information for querying data in a database from a connected terminal".
As another aspect, the present disclosure also provides a computer-readable medium that may be contained in the apparatus described in the above embodiments; or may be present alone without being fitted into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to include:
acquiring interaction information, wherein the interaction information is used for inquiring data in a database, and the database comprises a master database and a slave database; responding to the judgment that the interactive information does not comprise a writing operation statement, and acquiring the latest updating time of the slave database, wherein the slave database is updated by calling the master database; acquiring inquiry time of the interaction information; and determining a target database from the master database and the slave database according to the latest update time of the slave database and the query time of the interaction information so as to call the target database to query the data according to the interaction information.
Exemplary embodiments of the present disclosure are specifically illustrated and described above. It is to be understood that this disclosure is not limited to the particular arrangements, instrumentalities and methods of implementation described herein; on the contrary, the disclosure is intended to cover various modifications and equivalent arrangements included within the spirit and scope of the appended claims.

Claims (10)

1. A method of querying data, comprising:
acquiring interaction information, wherein the interaction information is used for inquiring data in a database, and the database comprises a master database and a slave database;
responding to the judgment that the interaction information does not comprise a writing operation statement, and acquiring the latest updating time of the slave database, wherein the slave database is updated by calling the master database;
acquiring the inquiry time of the interaction information;
determining a target database from the master database and the slave database according to the latest update time of the slave database and the query time of the interaction information so as to call the target database to query data according to the interaction information;
determining a target database from the master database and the slave database according to the latest update time of the slave database and the query time of the interaction information, wherein the method comprises the following steps:
judging whether the current data of the slave database is updated to all data before the query time point according to the sequence relation between the latest update time of the slave database and the query time of the interaction information, and determining the master database or the slave database as the target database according to a judging result.
2. The method as recited in claim 1, further comprising:
and calling the master database to update the slave database with preset frequency, and obtaining the latest update time of the slave database as the current time.
3. Method according to claim 1 or 2, characterized in that the method is performed by a preset service, which is obtained by encapsulating a middleware service.
4. The method of claim 3, wherein the obtaining the query time for the interaction information comprises:
and obtaining the time of the interaction information reaching the preset service as the query time of the interaction information.
5. The method according to claim 1 or 2, wherein said determining a target database from said master database and said slave database based on a latest update time of said slave database and a query time of said interaction information comprises:
responding to the judgment that the latest updating time of the slave database is earlier than the inquiring time of the interaction information, and obtaining the current dormancy times by dormancy preset time;
responding to the judgment that the dormancy time is not larger than a preset dormancy time threshold, and judging whether the latest update time of the slave database is earlier than the inquiry time of the interaction information or not after dormancy for the preset time;
and determining that the slave database is the target database in response to determining that the latest update time of the slave database is later than the query time of the interaction information.
6. The method of claim 5, wherein determining the target database from the master database and the slave database based on the latest update time of the slave database and the query time of the interaction information further comprises:
and determining the main database as the target database in response to determining that the dormancy number is greater than a preset dormancy number threshold.
7. The method according to claim 1 or 2, wherein said determining a target database from said master database and said slave database based on a latest update time of said slave database and a query time of said interaction information comprises:
and determining that the slave database is the target database in response to determining that the latest update time of the slave database is later than the query time of the interaction information.
8. A data query device, comprising:
the interactive information acquisition module is used for acquiring interactive information, wherein the interactive information is used for inquiring data in a database, and the database comprises a master database and a slave database;
an update time obtaining module, configured to obtain a latest update time of the slave database in response to determining that the interaction information does not include a write operation statement, where the slave database is updated by calling the master database;
the inquiry time acquisition module is used for acquiring the inquiry time of the interaction information;
the target database determining module is used for determining a target database from the master database and the slave database according to the latest update time of the slave database and the query time of the interaction information so as to call the target database to query data according to the interaction information;
the target database determining module is further configured to determine, according to a sequence relationship between a latest update time of the slave database and a query time of the interaction information, whether data of the slave database is updated to all data before a query time point, and determine the master database or the slave database as the target database according to a determination result.
9. An apparatus, comprising: memory, a processor and executable instructions stored in the memory and executable in the processor, wherein the processor implements the method of any of claims 1-7 when executing the executable instructions.
10. A computer readable storage medium having stored thereon computer executable instructions which when executed by a processor implement the method of any of claims 1-7.
CN202110482141.1A 2021-04-30 2021-04-30 Data query method, device, equipment and storage medium Active CN113076343B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110482141.1A CN113076343B (en) 2021-04-30 2021-04-30 Data query method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110482141.1A CN113076343B (en) 2021-04-30 2021-04-30 Data query method, device, equipment and storage medium

Publications (2)

Publication Number Publication Date
CN113076343A CN113076343A (en) 2021-07-06
CN113076343B true CN113076343B (en) 2024-04-05

Family

ID=76616676

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110482141.1A Active CN113076343B (en) 2021-04-30 2021-04-30 Data query method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113076343B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113476853B (en) * 2021-07-26 2023-10-03 北京达佳互联信息技术有限公司 Data processing method and device for interactive task, electronic equipment and storage medium

Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102591964A (en) * 2011-12-30 2012-07-18 北京新媒传信科技有限公司 Implementation method and device for data reading-writing splitting system
CN104376127A (en) * 2014-12-12 2015-02-25 北京奇虎科技有限公司 Data manipulation method and device
CN105589797A (en) * 2015-09-17 2016-05-18 中国银联股份有限公司 Method for synchronous data time delay detection between master database and slave database
CN106453297A (en) * 2016-09-30 2017-02-22 努比亚技术有限公司 Master and slave time delay detection method, device and system
CN106802892A (en) * 2015-11-26 2017-06-06 阿里巴巴集团控股有限公司 For the method and apparatus of master/slave data consistency verification
CN106815097A (en) * 2017-01-18 2017-06-09 北京许继电气有限公司 Database disaster tolerance system and method
CN107704603A (en) * 2017-10-16 2018-02-16 山东浪潮通软信息科技有限公司 A kind of method and device for realizing read and write abruption
CN107766575A (en) * 2017-11-14 2018-03-06 中国联合网络通信集团有限公司 The data bank access method and device of read and write abruption
CN108121782A (en) * 2017-12-18 2018-06-05 新华三云计算技术有限公司 Distribution method, database middleware system and the electronic equipment of inquiry request
CN109189851A (en) * 2018-06-29 2019-01-11 网宿科技股份有限公司 Data access method, database facility and master-slave database instance system
CN110019257A (en) * 2017-08-18 2019-07-16 北京京东尚科信息技术有限公司 Master/slave data library delay time processing method, device, medium and electronic equipment
CN111581238A (en) * 2020-04-01 2020-08-25 北京奇艺世纪科技有限公司 Information query method and device, electronic equipment and computer readable storage medium
CN112527817A (en) * 2020-12-08 2021-03-19 北京大米科技有限公司 Information processing method, information processing apparatus, storage medium, and electronic device

Patent Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102591964A (en) * 2011-12-30 2012-07-18 北京新媒传信科技有限公司 Implementation method and device for data reading-writing splitting system
CN104376127A (en) * 2014-12-12 2015-02-25 北京奇虎科技有限公司 Data manipulation method and device
CN105589797A (en) * 2015-09-17 2016-05-18 中国银联股份有限公司 Method for synchronous data time delay detection between master database and slave database
CN106802892A (en) * 2015-11-26 2017-06-06 阿里巴巴集团控股有限公司 For the method and apparatus of master/slave data consistency verification
CN106453297A (en) * 2016-09-30 2017-02-22 努比亚技术有限公司 Master and slave time delay detection method, device and system
CN106815097A (en) * 2017-01-18 2017-06-09 北京许继电气有限公司 Database disaster tolerance system and method
CN110019257A (en) * 2017-08-18 2019-07-16 北京京东尚科信息技术有限公司 Master/slave data library delay time processing method, device, medium and electronic equipment
CN107704603A (en) * 2017-10-16 2018-02-16 山东浪潮通软信息科技有限公司 A kind of method and device for realizing read and write abruption
CN107766575A (en) * 2017-11-14 2018-03-06 中国联合网络通信集团有限公司 The data bank access method and device of read and write abruption
CN108121782A (en) * 2017-12-18 2018-06-05 新华三云计算技术有限公司 Distribution method, database middleware system and the electronic equipment of inquiry request
CN109189851A (en) * 2018-06-29 2019-01-11 网宿科技股份有限公司 Data access method, database facility and master-slave database instance system
CN111581238A (en) * 2020-04-01 2020-08-25 北京奇艺世纪科技有限公司 Information query method and device, electronic equipment and computer readable storage medium
CN112527817A (en) * 2020-12-08 2021-03-19 北京大米科技有限公司 Information processing method, information processing apparatus, storage medium, and electronic device

Also Published As

Publication number Publication date
CN113076343A (en) 2021-07-06

Similar Documents

Publication Publication Date Title
CN109840429B (en) Intelligent contract deployment and calling method and device
CN108228817B (en) Data processing method, device and system
CN111694857B (en) Method, device, electronic equipment and computer readable medium for storing resource data
CN109388626B (en) Method and apparatus for assigning numbers to services
CN110555030A (en) SQL statement processing method and device
CN113626223A (en) Interface calling method and device
CN111782235A (en) Data upgrading and querying method and device
CN111125064A (en) Method and device for generating database mode definition statement
CN113886485A (en) Data processing method, device, electronic equipment, system and storage medium
CN113076343B (en) Data query method, device, equipment and storage medium
CN113190517B (en) Data integration method and device, electronic equipment and computer readable medium
CN111241189A (en) Method and device for synchronizing data
CN108694172B (en) Information output method and device
CN115982148A (en) Database table processing method and device, electronic equipment and storage medium
CN111753226A (en) Page loading method and device
CN113779122B (en) Method and device for exporting data
CN115454971A (en) Data migration method and device, electronic equipment and storage medium
CN113760928A (en) Cache data updating system and method
CN113742321A (en) Data updating method and device
CN112579615A (en) Method and device for realizing distributed lock
CN111104409A (en) Database processing method and device, storage medium and electronic equipment
CN112559001A (en) Method and device for updating application
CN112214500A (en) Data comparison method and device, electronic equipment and storage medium
CN112507100B (en) Update processing method and device of question-answering system
CN113760860B (en) Data reading method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant