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

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

Info

Publication number
CN113076343A
CN113076343A CN202110482141.1A CN202110482141A CN113076343A CN 113076343 A CN113076343 A CN 113076343A CN 202110482141 A CN202110482141 A CN 202110482141A CN 113076343 A CN113076343 A CN 113076343A
Authority
CN
China
Prior art keywords
database
time
slave
query
determining
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.)
Granted
Application number
CN202110482141.1A
Other languages
Chinese (zh)
Other versions
CN113076343B (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

Images

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

Abstract

The disclosure provides a data query method, a data query device, data query equipment and a storage medium, and relates to the technical field of internet. The method comprises the following steps: 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; in response to determining that the interactive information does not include a write operation statement, obtaining a latest update time of the slave database, wherein the slave database is updated by calling the master database; acquiring the query time of the interactive 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 the timeliness and accuracy of data query.

Description

Data query method, device, equipment and storage medium
Technical Field
The present disclosure relates to the field of internet technologies, and in particular, to a data query method, apparatus, device, and readable storage medium.
Background
In the World Wide Web (Web) system nowadays, as the number of users increases, the pressure of "reading" in the operation of the system database is much higher than that of "writing", so that the database reading and writing separation is more and more used by people. After the database reading and writing are separated, the operations are distributed, the related operations of the writing data can be put into a master database (master library) for execution, and the related operations of the reading data can be put into a slave database (slave library or reading library) for operation, so that the pressure of the master library is reduced, and the performance of the master library is ensured. However, in the actual service processing process, the situation that the corresponding latest data cannot be queried in time when the slave database is queried due to the synchronization delay (master-slave delay) of the master-slave database often occurs, so that a series of service problems are generated.
In the related technology, when data is queried from a database system after read-write separation, a query method is analyzed, and if the latest data needs to be queried, the query method is forced to leave a master database through codes or other configurations, so that the query is not influenced by master-slave delay. However, this approach requires analysis of the query method each time a data query is performed, and requires modification of the code that allocates database operations to ensure that the master is forced when querying the most recent data. If the query method is adjusted, whether a code or configuration for forcing the master library to be removed needs to be added to ensure that the service of the method operates normally needs to be considered, but the code for allocating database operation is not modified due to reasons of code writer omission, high cost and the like, so that the master library is not checked in time to cause a service problem.
As described above, how to improve the timeliness and accuracy of data query becomes an urgent problem to be solved.
The above information disclosed in this background section is only for enhancement of understanding of the background of the disclosure and therefore it may contain information that does not constitute prior art that is already known to a person of ordinary skill in the art.
Disclosure of Invention
The present disclosure is directed to a data query method, apparatus, device and readable storage medium, which at least to some extent overcome the problem of low timeliness and accuracy of data query caused by the related art that queries the latest data by analyzing a query method.
Additional features and advantages of the disclosure will be set forth in the detailed description which follows, or in part will be obvious from the description, or may be learned by practice of the disclosure.
According to an aspect of the present disclosure, there is provided a data query method including: 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; in response to determining that the interactive information does not include a write operation statement, obtaining a latest update time of the slave database, wherein the slave database is updated by calling the master database; acquiring the query time of the interactive 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: calling the master database at a preset frequency to update the slave database, and obtaining the latest update time of the slave database as the current time.
According to an embodiment of the present disclosure, the method is performed by a preset service, which is obtained by encapsulating a middleware service.
According to an embodiment of the present disclosure, the obtaining of the query time of the interaction information includes: and obtaining the time of the interactive information reaching the preset service as the query time of the interactive information.
According to an embodiment of the present disclosure, the 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 includes: responding to the fact that the latest updating time of the slave database is judged to be earlier than the query time of the interactive information, sleeping preset time, and obtaining the current sleeping times; in response to the fact that the sleep times are not larger than a preset sleep time threshold value, judging whether the latest updating time of the slave database is earlier than the query time of the interactive information again after sleeping for the preset time; determining the slave database as 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 present disclosure, the 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 further includes: and in response to determining that the sleep times are greater than a preset sleep time threshold, determining the master database as the target database.
According to an embodiment of the present disclosure, the 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 includes: determining the slave database as 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 interactive information does not include a write operation statement, where the slave database is updated by calling the master database; the query time acquisition module is used for acquiring the query time of the interactive 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 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 apparatus further comprises: and the slave database updating module is used for calling the master database to update the slave database at a preset frequency and obtaining the latest updating time of the slave database as the current time.
According to an embodiment of the present disclosure, the device is implemented by 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 reaches the preset service as the query time of the interaction information.
According to an embodiment of the present disclosure, the target database determination module includes: the delay judging module is used for judging whether the latest updating time of the slave database is earlier than the query time of the interactive information; the dormancy module is used for responding to the fact that the latest updating time of the slave database is judged to be earlier than the query time of the interactive information and dormancy preset time, and obtaining the current dormancy times; the sleep time judging module is used for judging whether the sleep times are larger than a preset sleep time threshold value or not; the delay judging module is used for responding to the judgment that the dormancy times are not larger than a preset dormancy time threshold value, and judging whether the latest updating time of the slave database is earlier than the query time of the interactive information again after the preset dormancy time; the target database determination module is further used for determining the slave database as the target database in response to judging that the latest updating 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 determination module is further configured to determine that the master database is the target database in response to determining that the sleep time is greater than a preset sleep time threshold.
According to an embodiment of the disclosure, 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 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 that, 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 interactive information for querying the data in the database does not include the write operation statement, the latest update time for updating the slave database by calling the master database is obtained, 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, and the target database is called to query the data according to the interactive information, so that the database can be distributed for the query operation according to the relation between the latest update time of the slave database and the query time of the interactive information, the query method does not need to be analyzed, and the timeliness and the 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 shows a schematic diagram of a system architecture in an embodiment of the disclosure.
Fig. 2 shows a flowchart of a data query method in an embodiment of the disclosure.
Fig. 3 shows a schematic diagram of another system architecture in an embodiment of the disclosure.
FIG. 4 illustrates a schematic diagram of tasks encapsulated in a provisioning service, according to an embodiment of the present disclosure.
FIG. 5 illustrates a flow chart of a method of target database determination, according to an embodiment of the present disclosure.
FIG. 6 is a schematic diagram illustrating a data query flow, according to an example embodiment.
Fig. 7 shows a block diagram of a data query device in an embodiment of the disclosure.
Fig. 8 shows a block diagram of another data query device in an embodiment of the disclosure.
Fig. 9 shows a schematic structural diagram of an electronic device in an embodiment of the present disclosure.
Detailed Description
Example embodiments will now be described more fully with reference to the accompanying drawings. Example embodiments may, however, 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 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 their repetitive description 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 subject matter of the present disclosure can 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", etc. are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of the present disclosure, "a plurality" means at least two, e.g., two, three, etc., unless explicitly specifically limited otherwise. The symbol "/" generally indicates that the former and latter associated objects are in an "or" relationship.
In the present disclosure, unless otherwise expressly specified or limited, the terms "connected" and the like are to be construed broadly, e.g., as meaning electrically connected or in communication with each other; may be directly connected or indirectly connected through an intermediate. The specific meaning of the above terms in the present disclosure can be understood by those of ordinary skill in the art as appropriate.
As described above, in the related art, analyzing the query method each time a data query is performed, the code for allocating the database operation may not be modified in time when the query method is changed, resulting in a business problem due to not checking the master library in time. Therefore, the present disclosure provides a data method, which obtains the update time by adding the update log of the slave database, to timely determine whether the corresponding time node data exists in the slave database during the current query operation, if so, directly querying the slave database, if not, dormancy waits for the data synchronization of the corresponding time node, and then query the slave database, and if not, the master database is directly forced to query when the data is not synchronized to the slave database for a long time, so as to maximally ensure the timeliness and accuracy of the query.
Fig. 1 illustrates an exemplary system architecture 10 to 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 input, output, including but not limited to smart phones, tablets, laptop portable computers, desktop computers, wearable devices, virtual reality devices, smart homes, and the like. Network 104 is the medium used to provide communication links between terminal device 102 and server 106. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few. The server 106 may be a server or a cluster of servers or the like that provide various services, such as an application server, a proxy server, and so forth. The database 108 may be a large database software installed on a server or a small database software installed on a computer for storing data.
A user may use terminal device 102 to interact with server 106 and database 108 via network 104 to receive or transmit data and the like. For example, a user may operate on the terminal device 102 to send a data query request to the server 106 via the network 104, and then the server 106 sends the data query request to the corresponding database 108. As another example, a user may receive data on 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, etc. at server 106 via network 104. For example, server 106 may be an application server that sends a user's data query request to database 108 over network 104. Also for example, the server 106 may be a proxy server for allocating a database for a query operation based on a data query request of a user, sending the data query request to the corresponding database 108, and receiving a query result from the database 108.
It should be understood that the number of terminal devices, networks, servers, and databases in fig. 1 is 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 in accordance with an exemplary embodiment. The method shown in fig. 2 may be applied to, for example, a server side of the system, and may also be applied to a terminal device of the system.
Referring to fig. 2, a data query method 20 provided by the embodiment of the present disclosure may include the following steps.
In step S202, mutual information is obtained, and the mutual information is used to query data in databases, where the databases include a master database and a slave database.
In some embodiments, the system for implementing database read-write separation may be, for example, a Web system, a user may send 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 statement, such as Structured Query Language (SQL), which is used for querying and updating a database and managing a programming Language of a 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 statement generated at a client is sent to the middleware service to be operated and distributed to a master library or a slave library, for example, the MySQL of the relational database management system may implement read-write separation by using a MySQL proxy, and then the interactive statement is processed by the MySQL proxy to connect to a corresponding database.
In some embodiments, the interactive statements may include write operation statements and read operation statements. The write operation statement may include, for example, a Data Definition Language (DDL) and a Data Management Language (DML). The DDL is mainly used in initialization work of defining or changing the structure, data type, and links and constraints between TABLEs (TABLE), and is mostly used in TABLE creation, replacement, and DROP; DML is a language used to operate on data in a database, and the main commands include SELECT (SELECT), UPDATE (UPDATE), INSERT (INSERT), DELETE (DELETE), and the like. The read operation statement may include, for example, a Data Query Language (DQL) whose basic structure is a Query block composed of a SELECT clause, a source (FROM) clause, and a WHERE (WHERE) clause.
In step S204, in response to determining that the write operation statement is not included in the interactive 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 does not include the write operation statement, the 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 by a preset service, and the preset service 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 at a preset frequency to update the slave database, and the latest update time of the slave database is obtained as the current time, and the detailed description may refer to fig. 3 and 4.
In some embodiments, when the interactive statement is determined to include a write operation statement, for example, including a DDL and/or a DML, the master library is determined to be the target database, that is, the master library is selected to be connected for data operation.
In step S206, the query time of the mutual information is acquired. The query time of the interactive 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 data before the query time point.
In some embodiments, the time when the interaction information reaches 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 to call the target database to query data according to the interaction information. Whether the data of the current slave database is updated to all data before the query time point can be judged according to the precedence relationship between the latest update time of the slave database and the query time of the interactive information, and then the master database or the slave database is selected to be connected. Reference may be made to fig. 5 for a specific embodiment.
According to the data query method provided by the embodiment of the disclosure, when the interactive information for querying the data in the database does not include the write operation statement, the latest update time for updating the slave database by calling the master database is obtained, 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 distributed for the query operation according to the relation between the latest update time of the slave database and the query time of the interactive information, the query method does not need to be analyzed, and the timeliness and the accuracy of data query are improved.
According to the method, the slave library state parameter (Seconds _ while _ Master) Behind the Master library in MySQL is not used for judging the data delay of the slave library, so that the delay time that the values of the Seconds _ while _ Master obtained by recording input and output cannot accurately display data under the conditions of network delay and the like can be avoided.
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, where the respective end user 1, user 2, and user 3 … … are connected to the service 304 in the web system, and different users are connected to different service nodes in the service 304, for example, the user 1 is connected to the service 1, the user 2 is connected to the service 2, the user 3 is connected to the service 3, and the different service nodes are collected to the preset service 3042 to perform operation distribution processing, so as to invoke the corresponding master library 3062 or slave library 1 and slave library 2 in the database 306 according to the operation corresponding to the interactive statement.
The provisioning service 3042 based on replication of primary-synchronized SQL Statements (SBR) 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 the piece of data is update time (update _ time) for recording the update time of the slave library. The content packaged in the preset service 3042 may include a task of updating the slave library, fig. 4 shows a schematic diagram of the task packaged in the preset service according to an embodiment of the present disclosure, as shown in fig. 4, as described in the implementation of step S204, the master library may be called at a preset frequency (for example, every k milliseconds, k is a positive integer) to update the slave library data (S2044), and the current time is updated once to t _ slave (S2042), where an update interval k of t _ slave may be configured according to an actual situation. The process of performing the target database determination may also be encapsulated in the preset service 3042, and a specific embodiment of the target database determination method may refer to fig. 5 and fig. 6.
According to the system architecture provided by the embodiment of the disclosure, by encapsulating the middleware service, whether the query method needs to go to the master library or not is not required to be judged during each query, and only the target database is determined after the slave library delay judgment is carried out by executing the t _ slave update time in the preset service, so that the code flow is simplified and the development cost is saved on the premise of accurately querying the latest data.
FIG. 5 illustrates a flow chart of a method of target database determination, according to an embodiment of the present disclosure. The method shown in fig. 5 may be applied to, for example, a server side of the system, and may also be applied to a terminal device of the system.
Referring to fig. 5, a target database determination method 50 provided by the 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, the slave database is determined to be the target database. In the case that the latest update time of the slave database is later than the query time of the interactive information, the data of the slave database can be considered to be updated to all the data of the master database before the query time, so that the slave database can be called to perform data query.
In step S504, in response to determining that the latest update time from the database is earlier than the query time of the mutual information, the sleep preset time, the current sleep number is acquired. In the case that the latest update time of the slave database is earlier than the query time of the interactive information, the data of the slave database is considered not to be updated to all the data of the master database before the query time, the sleep preset time may be n milliseconds, for example, where n is a positive number, the value of n may be configured according to the actual situation, and the number of times of sleep is recorded, for example, the value of the "number of times of sleep" field may be incremented by one. Through the hibernate operation, all data from the library data update to the master library prior to the query time may be awaited.
In step S506, in response to determining that the sleep time is not greater than the preset sleep time threshold, it is determined again after the sleep preset time whether the latest update time of the slave database is earlier than the query time of the interactive information. The preset sleep time threshold m can be configured according to actual conditions, wherein m is a positive integer and is used for limiting the sleep times and avoiding overlong waiting time. And after judging whether the latest updating time of the slave database is earlier than the query time of the interactive information again, returning to the step S502 or the step S504 according to the judgment result.
In step S508, in response to determining that the sleep number is greater than the preset sleep number threshold, the master database is determined to be the target database. When the current dormancy times are larger than a preset dormancy time 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 to 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 during the current query operation is judged in time by adding the synchronization log of the database, if so, the slave database data is directly queried, if not, the slave database query is performed after waiting for the data synchronization of the corresponding time node, if the data synchronization is not achieved to the slave database for a long time, the master database query is directly forced, and the query timeliness and accuracy are ensured to the maximum extent. The method determines the latest synchronization time of each slave library through the MySQL self synchronization mechanism, thereby confirming whether the slave library can be directly inquired or not and ensuring the accuracy of data. For the condition that the master and the slave are delayed at a certain time point, the data synchronization can be waited or the corresponding query statement is forced to directly go to the master library, so that the accuracy of the query data is ensured. For the 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 process starts (S602), and first, it is determined whether the interactive statement SQL includes a write operation statement such as DML or DDL (S604), and if the interactive statement SQL includes a DML and/or DDL operation, a master library operation is directly invoked (S606); if no DML and/or DDL operations, i.e. only DQL operations, are involved, it is necessary to decide whether to invoke a slave library. The update time of the current slave table t _ slave is queried (S608), and it is determined whether the update time of the slave table 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, all data before the execution of the time when the data of the slave library is updated to the time when the DQL reaches the preset service is considered, the slave library is invoked (S612), and the corresponding DQL is executed. If the update time of the slave library is earlier than the current time of the DQL reaching the preset service, regarding all data before the execution of the time from the non-update of the data of the slave library to the time of the DQL reaching the preset service, performing sleep for a preset time (e.g., n milliseconds) (S614), and obtaining the current sleep number by the number of times of sleep + 1. Then, whether the current sleep time is larger than a preset threshold m is judged (S616), and if the sleep time is not larger than m, the steps return to S608 and S610 to continue the judgment. If the sleep times are greater than m, the slave library is considered to have too long delay time 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 sensed in time before each DQL is executed, so that the accuracy of query statement data of each slave library is ensured. And for the condition that the slave stock is delayed, waiting for a certain time through dormancy, and judging whether the delay time of the slave stock meets the requirement of query time again. For the condition that the delay time of the slave library is too long to meet the query, the slave library can sense the delay time in time and ensure the accuracy of the data by walking the master library. The problem that the slave library is delayed all the time can be sensed in time through the method, and the DQL is prevented from calling the slave library.
FIG. 7 is a block diagram illustrating a data query device in accordance with an exemplary embodiment. The apparatus shown in fig. 7 may be applied, for example, to a server side of the system 10, and may also be applied to a terminal device of the above system.
Referring to fig. 7, the apparatus 70 provided by the embodiment of the present disclosure may include an interaction information obtaining module 702, an update time obtaining module 704, a query time obtaining module 706, and a target database determining module 708.
The interaction information obtaining module 702 may be configured to obtain interaction information, where the interaction information is used to query data in a database, and the database includes a master database and a slave database.
The update time obtaining module 704 may be configured to obtain a latest update time of the slave database in response to determining that the write operation statement is not included in the interaction information, wherein the slave database is updated by calling the master database.
The query time obtaining module 706 may be configured to obtain 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 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.
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, and may also be applied to a terminal device of the system.
Referring to fig. 8, the apparatus 80 provided in this disclosure may include an interaction information obtaining module 802, a slave library updating module 803, an update time obtaining module 804, a query time obtaining module 806, and a target database determining module 808, where the target database determining module 808 may include a delay determining module 8082, a sleep module 8084, and a sleep number determining module 8086. The device is realized through a preset service, and the preset service is obtained by packaging the middleware service.
The mutual information obtaining module 802 may be configured to obtain mutual information, where the mutual information is used to query data in databases, where the databases include a master database and a slave database.
The slave library update module 803 may be configured to call 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 obtaining module 804 may be configured to obtain a latest update time of the slave database in response to determining that the write operation statement is not included in the interaction information, wherein the slave database is updated by calling the master database.
The query time obtaining module 806 can be used to obtain the query time of the interaction information.
The query time obtaining module 806 may be further configured to obtain a time when the interaction information reaches the preset service as the query time of the interaction information.
The target database determination module 808 may be configured to determine 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, so as to invoke the target database to query the data according to the interaction information.
The delay determination module 8082 may be used 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 determine again whether the latest update time of the slave database is earlier than the query time of the interaction information after the preset sleep time in response to determining that the sleep time is not greater than the preset sleep time threshold.
The hibernation module 8084 can be configured to obtain the current hibernation times in response to determining that the latest update time from the database is earlier than the query time of the interaction information, the hibernation preset time.
The sleep time determination module 8086 may be configured to determine whether the sleep time is greater than a preset sleep time threshold.
The target database determination module 808 may be further operable to determine the slave database as the target database in response to determining that the most recent 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 master database as the target database in response to determining that the number of hibernation times is greater than a preset number of hibernation times threshold.
The target database determination module 808 may be further operable to determine the slave database as the target database in response to determining that the most recent update time of the slave database is later than the query time of the interaction information.
The specific implementation of each module in the apparatus provided in the embodiment of the present disclosure may refer to the content in the foregoing method, and is not described herein again.
Fig. 9 shows a schematic structural diagram of an electronic device in an embodiment of the present disclosure. It should be noted that the apparatus shown in fig. 9 is only an example of a computer system, and should not bring any limitation to the function and the scope of the application of the embodiments of the present disclosure.
As shown in fig. 9, the apparatus 900 includes a Central Processing Unit (CPU)901 that can perform various appropriate actions and processes in accordance with 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 apparatus 900 are also stored. The CPU901, ROM 902, and RAM 903 are connected to each other via a bus 904. An input/output (I/O) interface 905 is also connected to bus 904.
The following components are connected to the I/O interface 905: an input portion 906 including a keyboard, a mouse, and the like; an output section 907 including components such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 908 including a hard disk and 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 necessary. A removable medium 911 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 910 as necessary, so that a computer program read out therefrom is mounted into the storage section 908 as necessary.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the 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 illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 909, and/or installed from the removable medium 911. The above-described functions defined in the system of the present disclosure are executed when the computer program is executed by a Central Processing Unit (CPU) 901.
It should be noted that the computer readable media shown in the present disclosure may be computer readable signal media or computer readable storage media or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination 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 present 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 contrast, in the present disclosure, a computer-readable signal medium may include a propagated data signal with computer-readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. 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 flowchart 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 by software or hardware. The described modules may also be provided in a processor, which may be described as: a processor comprises an interactive 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 to the modules themselves 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, which may be contained in the apparatus described in the above embodiments; or may be separate and not incorporated into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to comprise:
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; acquiring the latest updating time of the slave database in response to the fact that the writing operation statement is not included in the interactive information, wherein the slave database is updated by calling the master database; acquiring query time of the interactive 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.
Exemplary embodiments of the present disclosure are specifically illustrated and described above. It is to be understood that the present disclosure is not limited to the precise arrangements, instrumentalities, or instrumentalities 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 for querying data, comprising:
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;
in response to determining that the interactive information does not include a write operation statement, obtaining a latest update time of the slave database, wherein the slave database is updated by calling the master database;
acquiring the query time of the interactive 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.
2. The method of claim 1, further comprising:
calling the master database at a preset frequency to update the slave database, 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 it is performed by means of a pre-set service obtained by encapsulating middleware services.
4. The method of claim 3, wherein the obtaining the query time of the interaction information comprises:
and obtaining the time of the interactive information reaching the preset service as the query time of the interactive information.
5. The method of claim 1 or 2, wherein the 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 comprises:
responding to the fact that the latest updating time of the slave database is judged to be earlier than the query time of the interactive information, sleeping preset time, and obtaining the current sleeping times;
in response to the fact that the sleep times are not larger than a preset sleep time threshold value, judging whether the latest updating time of the slave database is earlier than the query time of the interactive information again after sleeping for the preset time;
determining the slave database as 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 the 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 further comprises:
and in response to determining that the sleep times are greater than a preset sleep time threshold, determining the master database as the target database.
7. The method of claim 1 or 2, wherein the 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 comprises:
determining the slave database as 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 apparatus, 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 interactive information does not include a write operation statement, where the slave database is updated by calling the master database;
the query time acquisition module is used for acquiring the query time of the interactive 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 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.
9. An apparatus, comprising: memory, processor and executable instructions stored in the memory and executable in the processor, characterized in that the processor implements the method according to 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 one 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 true CN113076343A (en) 2021-07-06
CN113076343B 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)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113476853A (en) * 2021-07-26 2021-10-08 北京达佳互联信息技术有限公司 Data processing method and device for interactive tasks, 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

Cited By (2)

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

Also Published As

Publication number Publication date
CN113076343B (en) 2024-04-05

Similar Documents

Publication Publication Date Title
CN111694857B (en) Method, device, electronic equipment and computer readable medium for storing resource data
CN110019263B (en) Information storage method and device
CN111339171B (en) Data query method, device and equipment
CN108667660B (en) Method and device for route management and service routing and routing system
CN113626223A (en) Interface calling method and device
CN113360519B (en) Data processing method, device, equipment and storage medium
CN113190517B (en) Data integration method and device, electronic equipment and computer readable medium
CN111008865A (en) Coupon synchronous display method and device, server and storage medium
CN113076343B (en) Data query method, device, equipment and storage medium
CN111241189A (en) Method and device for synchronizing data
CN111984723A (en) Data synchronization method and device and terminal equipment
CN115629909A (en) Service data processing method and device, electronic equipment and storage medium
CN116244383A (en) BOM synchronous processing method, equipment and medium based on BOM middle station
CN115982148A (en) Database table processing method and device, electronic equipment and storage medium
US10114864B1 (en) List element query support and processing
CN114489674A (en) Data verification method and device of dynamic data model
CN114070889A (en) Configuration method, traffic forwarding method, device, storage medium, and program product
CN113742321A (en) Data updating method and device
CN113760695A (en) Method and device for positioning problem code
CN112214500A (en) Data comparison method and device, electronic equipment and storage medium
CN116301869B (en) Front-end page configuration management and control system, method, equipment and medium
CN110851192A (en) Method and device for responding to configuration of degraded switch
CN113760860B (en) Data reading method and device
US20220191104A1 (en) Access management for a multi-endpoint data store
CN113110873A (en) Method and apparatus for unifying system coding specifications

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