Disclosure of Invention
In order to solve the technical problems or at least partially solve the technical problems, the application provides a data processing method and system.
In a first aspect, an embodiment of the present application provides a data processing method, including:
acquiring change information of an operated database;
obtaining a data set according to the change information, wherein the data set comprises at least one field information;
determining a storage mode corresponding to the field information;
and storing the change information according to the storage mode.
Optionally, as in the foregoing data processing method, the determining a storage manner corresponding to the field information includes:
generating a corresponding query main key according to the field information;
and obtaining the corresponding storage mode according to the query main key and a preset storage strategy.
Optionally, as in the foregoing data processing method, obtaining the corresponding storage manner according to the query primary key and a preset storage policy includes:
acquiring a preset inquiry main key corresponding to the inquiry main key;
obtaining the storage mode corresponding to the query main key according to a preset query main key corresponding to the query main key and a preset corresponding relation; and the preset corresponding relation is the corresponding relation between the preset query main key and the storage mode.
Optionally, as in the foregoing data processing method, storing the change information according to the storage manner includes:
extracting corresponding fields to be stored from the data set according to the storage mode;
determining a change information database for storing the information in the field to be stored according to the storage mode;
and storing the field to be stored into the change information database.
Optionally, as in the foregoing data processing method, the obtaining change information of the operated database includes:
reading a change information file in the operated database;
analyzing the change information file, and determining changed data in the operated database;
generating change information according to the changed data; wherein the fields in the change information include: database information fields, data table information fields, and change data fields.
Optionally, as in the foregoing data processing method, the preset storage policy includes:
determining fields to be stored corresponding to different query main keys; and
and determining the change information database corresponding to different query main keys.
Optionally, as in the foregoing data processing method, the method further includes:
receiving a query request, wherein the query request carries query field information;
matching in a change information database according to the query field information in the query request to obtain corresponding field information;
determining historical change information including the corresponding field information;
and displaying the historical change information.
In a second aspect, an embodiment of the present application provides a data processing system, including: a data processing device; the data processing apparatus includes:
the acquisition module is used for acquiring the change information of the operated database;
the data set module is used for obtaining a data set according to the change information, and the data set comprises at least one field information;
the storage mode determining module is used for determining the storage mode corresponding to the field information;
and the storage module is used for storing the change information according to the storage mode.
Optionally, as in the foregoing data processing system, the method further includes: a data analysis device; the data analysis device includes:
the reading module is used for reading the change information file in the operated database;
the analysis module is used for analyzing the change information file and determining changed data in the operated database;
the generating module is used for generating change information according to the changed data; wherein the fields in the change information include: at least one of a database information field, a data table information field, and a change data field.
Optionally, as in the foregoing data processing system, the method further includes: a data configuration apparatus, the data configuration apparatus comprising:
the first configuration module is used for determining fields to be stored corresponding to different query main keys; and
the second configuration module is used for determining the change information databases corresponding to different inquiry primary keys; and the change information database is used for storing the information in the field to be stored.
Optionally, as in the foregoing data processing system, the method further includes: a data presentation device, the data presentation device comprising:
the receiving module is used for receiving a query request, and the query request carries query field information;
the query module is used for matching in a change information database according to the query field information in the query request to obtain corresponding field information;
a determination module for determining historical change information including the corresponding field information;
and the display module is used for displaying the historical change information.
In a third aspect, an embodiment of the present application provides an electronic device, including: the system comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are communicated with each other through the communication bus;
the memory is used for storing a computer program;
the processor, when executing the computer program, is configured to implement the method of any of the first aspect.
In a fourth aspect, embodiments of the present application provide a non-transitory computer-readable storage medium storing computer instructions that cause the computer to perform the method of any one of the first aspects.
The embodiment of the application provides a data processing method and a system, wherein the method comprises the following steps: acquiring change information of an operated database; obtaining a data set according to the change information, wherein the data set comprises at least one field information; determining a storage mode corresponding to the field information; and storing the change information according to the storage mode. Compared with the prior art, the technical scheme provided by the embodiment of the application has the following advantages: by the method, the problem that the change information of the database cannot be inquired or the retention period is limited in the related technology can be effectively solved, so that the change information in the database can be stored for a long time, and the data change in each time can be traced.
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.
Fig. 1 is a data processing method according to an embodiment of the present application, including the following steps S1 to S4:
s1, obtaining change information of an operated database.
Specifically, the change information may be: reading a binlog file of an operated database, and analyzing the binlog file to generate entity data; the entity data can comprise a database information field, can be a database name (such as schema), a data table information field, can be a data table name (such as table _ name) and a change data field (such as id, name, introduction, create _ date, etc. represent specific fields of a change table in binlog data); the above binlog is a file in binary format, and is used for recording SQL statement information updated by a user on a database.
And S2, obtaining a data set according to the change information, wherein the data set comprises at least one field information.
Specifically, the change information is entity data of an entity structure comprising a plurality of fields; therefore, the change information needs to be analyzed to obtain the field information of each field; the data set is a data set which is obtained by analyzing and splitting one piece of change information and comprises a plurality of pieces of field information; generally, a change message includes a plurality of field messages, and the field messages include: the field and the specific information of the field, for example, when the change information includes: the field "id" and the corresponding specific information are "10000"; a field "name", corresponding specific information being "andy"; a field "interaction", when the corresponding specific information is "this is an excellent child"; the changed information may be split to obtain the following pieces of field information: "id":10000, "name": "andy", "interaction": "this is an excellent child", and the above field information is set in the data set.
And S3, determining a storage mode corresponding to the field information.
Specifically, the storage manner may be obtained by performing confirmation or matching according to one or more field information, which is not specifically limited herein; in addition, the storage means may include: a database for storing change information (independent of the operated database), fields in the change information that need to be stored, and so on.
And S4, storing the change information according to the storage mode.
Specifically, after obtaining the corresponding storage method, the storage of the change information may be: all field information in the change information is stored, and part of preset field information in the change information can also be stored; before storage, a corresponding data table may be established in a database for storing change information, and a specific field in the data table includes a field that needs to be stored in the change information.
As shown in fig. 2, according to another embodiment of the present application, as in the foregoing data processing method, the step S3 determines the storage manner corresponding to the field information, and includes the following steps S31 to S32:
and S31, generating a corresponding query main key according to the field information.
Specifically, the query primary key may be generated according to one or more field information, and optionally, the query primary key may be generated according to specific information in the field information; by way of example:
when the field schema represents the change data of which database the binlog data is; and
the field table represents the changed data of which database table the binlog data is;
when the specific information corresponding to the field schema is schema and the specific information corresponding to the table _ name field is student in the analyzed change information, the specific information of the schema and the table _ name field is spliced into a query main key of a query configuration center, namely the schema and the student are spliced, wherein the query main key received by one splicing method can be the schema _ student _ key.
And S32, obtaining a corresponding storage mode according to the query main key and a preset storage strategy.
Specifically, the preset storage policy may be: different storage modes are corresponding to different query primary keys, that is, the storage positions or the stored field information of different databases or data tables can be different.
As shown in fig. 3, in some embodiments, as in the foregoing data processing method, the step S32 obtaining a corresponding storage manner according to the query primary key and a preset storage policy includes the following steps S321 to S322:
s321, acquiring a preset query main key corresponding to the query main key.
S322, obtaining a storage mode corresponding to the query main key according to the preset query main key corresponding to the query main key and the preset corresponding relation; the preset corresponding relation is the corresponding relation between the preset query main key and the storage mode.
Specifically, the preset storage strategy is the corresponding relation between different query main keys and storage modes; the query main key is a comparison word for matching the storage modes, and the preset query main keys and the storage modes are correspondingly arranged (generally, one preset query main key corresponds to a unique storage mode), so that after the query main key is matched with the corresponding preset query main key, the storage mode corresponding to the query main key can be determined.
As shown in fig. 4, according to another embodiment of the present application, as in the foregoing data processing method, the step S4 stores the change information according to the storage manner, and includes the following steps S41 to S43:
and S41, extracting corresponding fields to be stored from the data set according to the storage mode.
Specifically, the storage mode defines fields to be stored, for example:
when binlog resolves out entity data, the entity data comprises: school, table _ name, student, id 10000, name, and andy, interaction, wherein the table _ name is an excellent child, and the table _ date is 2019-08-0516, 04: 31;
when the fields stored in the Hbase storage engine defined in the storage method (for example, defined by the field store _ data. field) include the fields "id", "name", and "interaction", three field information of "id":10000, "name": and "andy", "interaction": which is an excellent child "are stored in the Hbase storage engine; HBase is a distributed, column-oriented open-ended database.
And the number of the first and second groups,
when the field defined in the storage mode and stored in the ElasticSearch storage engine (for example, defined by the field retrieval _ data. field) comprises the fields of 'id' and 'name', then storing two fields of 'id': 10000, name ': andy' information into the ElasticSearch storage engine; wherein the ElasticSearch is a search server based on Lucene. It provides a distributed multi-user capability full-text search engine.
And S42, determining a change information database for storing the information in the field to be stored according to the storage mode.
On the basis of the example shown in step S41, when the information in the fields "id", "name", and "introduction" is stored in the Hbase storage engine, it is preset to be stored in a library with a library name of school _ student _ Hbase (for example, it may be defined by a field store _ data. name); when the information in the fields "id" and "name" is stored in the ElasticSearch storage engine (for example, may be defined by the field "retrieve _ data. name"), the preset is stored in the library with the library name "school _ student _ elas";
and S43, storing the field to be stored into a change information database.
Taking the example based on step S42, three pieces of field information, namely "id":10000, "name": andy "," introduction ": this is an excellent child", can be extracted from the configuration in the store _ data field and stored in the Hbase storage engine with the library name of school _ student _ Hbase;
and the number of the first and second groups,
extracting two fields of ' id ': 10000, ' name ': andy ' according to the configuration in a retrieval _ data field in configuration information from entity data obtained by analyzing binlog, and storing the data into an ElasticSearch storage engine with the library name of school _ student _ elas;
as shown in fig. 5, in some embodiments, as the aforementioned data processing method, the step S1 obtains the change information of the operated database, including the following steps S11 to S13:
and S11, reading the change information file in the operated database. In general, the change information file is a binlog file.
Specifically, when the database performs an operation such as writing to cause a change in the data in the database, the corresponding operation is recorded in the change information file.
And S12, analyzing the change information file and determining changed data in the operated database.
Specifically, since the binlog file cannot be directly opened and viewed, it needs to be parsed to obtain the changed data, and the changed data may include, in addition to the data itself, a changed database, a changed data table, and the like, for example, data including the following fields:
field schema: change data representing which database binlog data is;
field table _ name: change data representing which database table binlog data is;
change data fields such as field id, name, introduction, create _ date, etc. represent change tables in binlog data.
S13, generating change information according to the changed data; wherein, the fields in the change information include: database information fields, data table information fields and change data fields;
specifically, the changed data is recombined to form a total piece of information including a plurality of fields, that is, the changed information is obtained.
In some embodiments, as in the foregoing data processing method, the preset storage policy includes steps T1 and T2 as follows:
and T1, determining fields to be stored corresponding to different query primary keys.
Specifically, the fields (i.e., fields to be stored) which are required to be stored and correspond to different query main keys are different; that is, different fields to be stored correspond to different pieces of change information.
And T2, determining the change information database corresponding to different query main keys.
Specifically, the change information databases for storing all or part of the change information corresponding to different query main keys are different from each other.
In some embodiments, the data processing method as described above further includes steps P1 to P4 as follows:
and P1, receiving a query request, wherein the query request carries query field information.
Specifically, an optional technical solution for receiving the query request may be: entering field information (i.e., the above-mentioned query field information, such as "" id ": 10000" in the foregoing embodiment, etc.) in an input box for a query; in addition, the information (such as library name, data table name and field name) in each change information database can be displayed in a pull-down mode for the user to select.
P2, matching in a change information database according to the query field information in the query request to obtain corresponding field information;
specifically, the number of the change information databases may be one or more, when a plurality of change information databases exist, the query field information needs to carry a library name, and when only one change information database exists, only a data table name and other information capable of locating the unique field information may be carried; one implementation method may be: when a plurality of change information databases exist, the corresponding change information database can be located first, then the corresponding change information database is located in a certain field in the corresponding change information database, and then the field information with the specific information of the field consistent with the specific information in the query field information is obtained by matching in the field.
P3. determining historical change information including corresponding field information.
Specifically, the historical change information is change information stored in a change information database; after the corresponding field information is located, the change information corresponding to the field information (i.e., the above-mentioned history change information) can be determined.
And P4, displaying the historical change information.
Specifically, after the history change information is obtained, the history change information may be displayed in a specific display window; the specific display form can be selected according to a specific mode, and is not particularly limited herein.
Therefore, by the method in the embodiment, the data stored in the storage engines such as elastic search and Hbase can be queried through the retroactive data presentation platform, and the presentation retroactive of the historical change data in the database can be performed.
As shown in fig. 6 and 7, according to another embodiment of the present application, there is also provided a data processing system including: a data processing apparatus 1; the data processing apparatus 1 includes:
the obtaining module 11 is used for obtaining the change information of the operated database;
a data set module 12, configured to obtain a data set according to the change information, where the data set includes at least one field information;
a storage mode determining module 13, configured to determine a storage mode corresponding to the field information;
and the storage module 14 is used for storing the change information according to the storage mode.
Specifically, the specific process of implementing the functions of each module in the apparatus according to the embodiment of the present invention may refer to the related description in the method embodiment, and is not described herein again.
As shown in fig. 6 and 8, in some embodiments, the data processing system further includes: a data analysis device 2; the data analysis device 2 includes:
a reading module 21, configured to read a binlog file in an operated database;
the analysis module 22 is used for analyzing the binlog file and determining changed data in the operated database;
a generating module 23, configured to generate change information according to the changed data; wherein, the fields in the change information include: database information fields, data table information fields, and change data fields.
Specifically, the specific process of implementing the functions of each module in the apparatus according to the embodiment of the present invention may refer to the related description in the method embodiment, and is not described herein again.
As shown in fig. 6 and 9, in some embodiments, the data processing system further includes: the data configuration device 3, include:
the first configuration module 31 is configured to determine fields to be stored corresponding to different query primary keys; and
a second configuration module 32, configured to determine a change information database corresponding to different query primary keys; the change information database is used for storing information in fields to be stored.
Specifically, the specific process of implementing the functions of each module in the apparatus according to the embodiment of the present invention may refer to the related description in the method embodiment, and is not described herein again.
As shown in fig. 6 and 10, in some embodiments, the data processing system further includes: data presentation device 4, data presentation device 4 includes:
a receiving module 41, configured to receive a query request, where the query request carries query field information;
the query module 42 is configured to match the field information in the change information database according to the query field information in the query request to obtain corresponding field information;
a determining module 43, configured to determine historical change information including corresponding field information;
and the display module 44 is used for displaying the historical change information.
Specifically, the specific process of implementing the functions of each module in the apparatus according to the embodiment of the present invention may refer to the related description in the method embodiment, and is not described herein again.
According to another embodiment of the present application, there is also provided an electronic apparatus including: as shown in fig. 11, the electronic device may include: the system comprises a processor 1501, a communication interface 1502, a memory 1503 and a communication bus 1504, wherein the processor 1501, the communication interface 1502 and the memory 1503 complete communication with each other through the communication bus 1504.
A memory 1503 for storing a computer program;
the processor 1501 is configured to implement the steps of the above-described method embodiments when executing the program stored in the memory 1503.
The bus mentioned in the electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
The Memory may include a Random Access Memory (RAM) or a Non-Volatile Memory (NVM), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the processor.
The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but also Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components.
Embodiments of the present application also provide a non-transitory computer-readable storage medium storing computer instructions for causing a computer to perform the steps of the above-described method embodiments.
It is noted that, in this document, relational terms such as "first" and "second," and the like, may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The foregoing are merely exemplary embodiments of the present invention, which enable those skilled in the art to understand or practice the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.