Data query method and device
Technical Field
The present application relates to the field of computer technologies, and in particular, to a data query method and apparatus.
Background
With the rapid development of computer and network technologies, the scale of network access data is increasing. How to process mass data generated in the information explosion era becomes a problem to be solved urgently. In a traditional centralized database system, an application program is concentrated on one computer to run, and once the computer fails, the whole system is affected. In addition, centralized processing causes the scale and configuration of the system to be inflexible, and the expandability of the system is poor. Therefore, the traditional centralized database system cannot meet the application requirements of large-scale data.
Distributed database systems have been developed based on centralized database systems and are the product of a combination of computer technology and network technology. The distributed database is a unified whole logically, and is stored on different physical nodes respectively physically. An application may access a database distributed in different locations through a network connection. The distributivity of the distributed database system is represented by that the data in the database is stored on the storage devices of different computers, and a user can execute a global application on any one computer through a network connection. The distributed database system has high reliability, when one computer in the system breaks down, the system can operate the same copy on the other computer, and the whole system cannot be broken down due to one failure. Moreover, the distributed database system can select the data copy closest to the user for operation according to the distance, so that the communication cost is reduced, and the performance of the whole system is improved.
However, in the use process of the distributed database system, data in the database is stored in storage devices of different computers, so that an application server needs to be connected with a plurality of databases, and the problem of insufficient links between the application server and the databases exists, which leads to low efficiency or abnormal conditions of users during query operation. In the prior art, the problem of insufficient link number of a data source still cannot be solved by splitting a database or introducing a memory cache.
Disclosure of Invention
The invention aims to provide a data query method and a data query device, which are used for solving the problem of insufficient data source link number in a large-scale distributed database system.
In a first aspect, a data query method is provided, where the method includes:
a data bus receives a data query request sent by an application server, wherein the query request carries data query condition information;
the data bus inquires corresponding first data in a memory cache according to the inquiry condition information;
if the first data is inquired by the data bus, the first data is sent to the application server;
and if the first data is not inquired by the data bus, sending the data inquiry request to an actuator, and using the actuator to inquire the first data in a database according to the data inquiry condition information.
In a second aspect, there is provided a data query apparatus, including:
the receiving unit is used for receiving a data query request sent by an application server through a data bus, wherein the query request carries data query condition information;
the first query unit is used for the data bus to query the corresponding first data in the memory cache according to the query condition information;
and the judging unit is used for judging whether the first data is inquired in the memory cache by the data bus.
The first sending unit is used for sending the first data to the application server when the first data is inquired by the data bus;
the second sending unit is used for sending the data query request to an actuator when the first data is not queried by the data bus;
and the second query unit is used for querying the first data in a database by the executor according to the data query condition information.
According to the data query method and device, the data bus is additionally arranged in the distributed database system, so that distributed cache is added, the data bus is forwarded, the consumption of the number of the data source links is reduced, and the query performance of the application server is improved.
Drawings
Fig. 1 is a flowchart of a data query method according to an embodiment of the present application;
FIG. 2 is a diagram of a prior art single database schema distributed database system;
FIG. 3 is a diagram of a prior art multi-database schema distributed database system;
FIG. 4 is a diagram illustrating a distributed database system after memory caching is introduced in the prior art;
fig. 5 is a schematic diagram of a distributed database system according to an embodiment of the present application;
fig. 6 is a schematic diagram of a data query apparatus according to a second embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
According to the data query method and device provided by the embodiment of the application, the application server firstly sends a data query request to the data bus, the data bus queries in the memory cache according to the query condition information, if the data bus does not query the query result meeting the query condition, the data query request is sent to the actuator, and the actuator queries in the database according to the data query condition information. The invention adds the data bus in the distributed database system, reduces the number of links between the application server and the database through the forwarding of the data bus, and improves the query efficiency.
Example one
Fig. 1 is a flowchart of a data query method according to an embodiment of the present application. The method specifically comprises the following steps:
step 101, a data bus receives a data query request sent by an application server, wherein the query request carries data query condition information.
The network environment in which the method of the present invention operates may be, but is not limited to, a distributed database system in a cloud computing environment.
In the prior art distributed database system, the application server is directly connected with the database, and a schematic diagram of the distributed database system in a single database mode is shown in fig. 2. The number of links linking a single database and N application servers is M × N.
In order to reduce the number of links, the database is split, and the database is split to form a multi-database schema database system, as shown in fig. 3. After a single database is split into i databases, the total number of links of the N application servers and the i databases is mxnxi, and the problem of insufficient number of links of the data source is not solved.
Even if the memory cache is introduced, since the memory cache cannot send feedback information to the application server, the application server still needs to be linked with the database, and the total number of links between N application servers and i databases is still mxnxi, which cannot solve the problem of insufficient number of links of the data source, as shown in fig. 4.
In order to solve the problem of insufficient link number of a data source, a data bus is introduced into a distributed database system, wherein the data bus comprises a memory cache and an SQL (Structured Query Language) executor. Due to the introduction of Q data buses, the total number of the links of the N application servers and the i databases is Q multiplied by i (Q < M multiplied by N), and the consumption of the number of the database links is reduced. As shown in fig. 5.
The application server is an upper-layer service system and is used for processing services related to the requirements of the users. For example, the user accesses a shopping site, searches for commodity information satisfying a certain condition, and the like.
The data query condition information is a condition of any combination of upper-layer services, for example, a user wants to purchase a lady black woolen overcoat with a price of 1000-2000 yuan, a search keyword can be ' lady ' + ' black ' + ' woolen overcoat ' + ' 1000-2000 yuan, if the search range is to be enlarged, the keywords can be selected to be combined randomly, and then commodity information meeting the combination condition is searched and fed back to the user.
In this embodiment, the application server sends the data query request carrying the query condition information to the data bus through SQL. The data bus collects SQL query requests of an upper-layer business system, and the use of database links can be effectively reduced through the forwarding of the data bus.
And 102, the data bus queries corresponding first data in a memory cache according to the query condition information.
Specifically, the data bus accesses an inquiry interface of the memory cache according to the main key, and inquires data meeting an inquiry condition in the memory cache, where the first data is the data meeting the inquiry condition.
Step 103, determining whether the first data exists in the memory cache.
Specifically, if the data bus queries the data meeting the condition in the memory cache, the step 106 is continuously executed to feed the data meeting the query condition back to the application server for the upper layer service system to use. Otherwise, step 104 is performed.
And 104, sending the data query request to an executor when the first data is not queried by the data bus.
And if the data bus does not inquire the information meeting the inquiry condition in the memory cache, sending the data inquiry request to an actuator, triggering the actuator, and continuing to execute the step 105.
The executor is an SQL executor and queries the database by using SOL.
And 105, the executor queries the first data in a database according to the data query condition information.
Specifically, the executor queries in a database by using SQL according to the data query condition information.
The database is a mysql database, and is accessed by using SQL. The SQL executor obtains a query table name from the query request SQL, selects a database according to the query table name, and queries data meeting conditions.
And 106, sending the first data to the application server.
And if the data bus inquires the data meeting the conditions in the memory cache, the data bus sends the first data to an application server to meet the use requirement of an upper-layer service system.
And if the executor queries the data meeting the conditions in the database, the executor sends the first data to the application server, and simultaneously stores the data meeting the query conditions in a memory cache to update the cache, so that the next user can conveniently search the requirement.
According to the data query method provided by the embodiment of the application, the application server firstly sends a data query request to the data bus, the data bus queries in the memory cache according to the query condition information, if the data bus does not query the query result meeting the query condition, the data query request is sent to the actuator, and the actuator queries in the database according to the data query condition information. The invention adds the data bus in the distributed database system, thereby increasing the distributed cache, reducing the consumption of the data source link number through the forwarding of the data bus, and improving the query performance of the application server.
Example two
Corresponding to the data query method, a data query apparatus provided in the embodiment of the present application is further provided, and fig. 3 is a schematic diagram of an apparatus provided in the second embodiment of the present application, where the apparatus includes: a receiving unit 201, a first query unit 202, a judging unit 203, a first sending unit 204, a second sending unit 205, a second query unit 206 and a storage unit 207.
The receiving unit 201 is configured to receive, by using a data bus, a data query request sent by an application server, where the query request carries information of a data query condition.
The first query unit 202 is configured to query, by the data bus, the corresponding first data in the memory cache according to the query condition information.
The determining unit 203 is configured to determine whether the first data is queried in the memory cache by the data bus.
The first sending unit 204 is configured to send the first data to the application server when the first data is queried by the data bus.
The second sending unit 205 is configured to send the data query request to an executor when the data bus does not query the first data.
The second query unit 206 is configured to query the first data in a database according to the data query condition information.
The apparatus further includes a storage unit 207, configured to send the queried first data to the application server, and store the first data in the memory cache.
The device provided by the second embodiment of the present application is implanted with the method provided by the first embodiment of the present application, and therefore, detailed descriptions of the specific working process of the device provided by the present application are omitted here.
According to the data query device provided by the embodiment of the application, the application server firstly sends a data query request to the data bus, the data bus queries in the memory cache according to the query condition information, if the data bus does not query the query result meeting the query condition, the data query request is sent to the actuator, and the actuator queries in the database according to the data query condition information. The invention adds the data bus in the distributed database system, thereby increasing the distributed cache, reducing the consumption of the data source link number through the forwarding of the data bus, and improving the query performance of the application server.
Those of skill would further appreciate that the various illustrative objects and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative components and steps have been described above generally in terms of their functionality in order to clearly illustrate the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied in hardware, a software module executed by a processor, or a combination of the two. A software module may reside in Random Access Memory (RAM), memory, Read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The above-mentioned embodiments, objects, technical solutions and advantages of the present application are described in further detail, it should be understood that the above-mentioned embodiments are merely exemplary embodiments of the present application, and are not intended to limit the scope of the present application, and any modifications, equivalent substitutions, improvements and the like made within the spirit and principle of the present application should be included in the scope of the present application.