CN114546992A - Database migration method and device, storage medium and electronic equipment - Google Patents

Database migration method and device, storage medium and electronic equipment Download PDF

Info

Publication number
CN114546992A
CN114546992A CN202210279888.1A CN202210279888A CN114546992A CN 114546992 A CN114546992 A CN 114546992A CN 202210279888 A CN202210279888 A CN 202210279888A CN 114546992 A CN114546992 A CN 114546992A
Authority
CN
China
Prior art keywords
data
data record
record
database
checking
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.)
Pending
Application number
CN202210279888.1A
Other languages
Chinese (zh)
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.)
Lianlian Hangzhou Information Technology Co ltd
Original Assignee
Lianlian Hangzhou 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 Lianlian Hangzhou Information Technology Co ltd filed Critical Lianlian Hangzhou Information Technology Co ltd
Priority to CN202210279888.1A priority Critical patent/CN114546992A/en
Publication of CN114546992A publication Critical patent/CN114546992A/en
Pending legal-status Critical Current

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/21Design, administration or maintenance of databases
    • G06F16/214Database migration support
    • 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/25Integrating or interfacing systems involving database management systems
    • G06F16/258Data format conversion from or to a database
    • 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/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases

Abstract

The present disclosure relates to a database migration method, apparatus, storage medium and electronic device, the method establishes a mapping model, the mapping model is used for one-to-one converting data item information of a source database into data item information in a target database, the data item information includes at least one of the following: the source database and the target database are heterogeneous databases; writing the full data of the source database into the target database according to the mapping model; and responding to the condition that the incremental data log of the source database is received in the writing process, and changing the target database according to the incremental data log. The method and the device can directly perform data migration between heterogeneous databases, and can update the target database in real time according to the incremental data logs to realize data synchronization.

Description

Database migration method and device, storage medium and electronic equipment
Technical Field
The present disclosure relates to the field of database technologies, and in particular, to a database migration method and apparatus, a storage medium, and an electronic device.
Background
The informatization construction is developing at an unprecedented speed, comprehensive consideration factors such as safety, efficiency and cost are considered, a database architecture of a traditional manufacturer is urgently required to be migrated and upgraded, and data migration and data verification among heterogeneous databases are the primary problems. Most database manufacturers provide a copy function of a self-database, however, since different manufacturer databases have different storage structures and are maintained in different manners, data synchronization between heterogeneous databases cannot be realized by such a direct copy manner, and the technology is closed and the universality is poor. In addition, some third-party commercial copy software also has certain limitations in functions, safety and real-time performance, and is expensive.
Disclosure of Invention
In order to solve at least one technical problem, the present disclosure proposes a database migration method, apparatus, storage medium, and electronic device.
According to an aspect of the present disclosure, there is provided a database migration method, the method including:
establishing a mapping model, wherein the mapping model is used for converting the data item information of the source database into the data item information in the target database in a one-to-one correspondence manner, and the data item information comprises at least one of the following data items: the source database and the target database are heterogeneous databases;
writing the full data of the source database into the target database according to the mapping model;
and responding to the condition that the incremental data log of the source database is received in the writing process, and changing the target database according to the incremental data log.
In some possible embodiments, altering the target database according to the delta data log includes:
filtering the incremental data log to obtain a first cache file, wherein the first cache file comprises statements corresponding to database management languages in the incremental data log;
for each target data change record in the first cache file, performing record internal merging on the target data change record to obtain a second cache file, wherein each target data change record comprises at least two associated data change records, and the at least two associated data change records are used for recording data change operation on data records with the same main key;
and in response to the write-in completion condition, changing the target database based on the second cache file.
In some possible embodiments, the method further comprises:
writing a first data record in the second cache file into the target database by using a first thread; writing a second data record in the second cache file into the target database by using a second thread;
any data change record in the first data records and any data change record in the second data records point to data records corresponding to different primary keys;
the second thread is different from the first thread, and the second thread and the first thread run asynchronously.
In some possible embodiments, the method further comprises:
checking whether the number of rows of the data table of the source database and the data table which is correspondingly migrated to the target database are consistent in real time;
if the line numbers are not consistent, judging whether the current time for checking the line numbers is in a preset checking time window or not;
if the current time for checking the line number is in the checking time window, continuing to check the line number of the data table of the source database and the data table which is correspondingly migrated to the target database;
and if the current time for checking the line number is not in the checking time window, outputting a first checking result, wherein the first checking result comprises the checking result of the line number.
In some possible embodiments, the method further comprises:
if the line numbers are consistent, checking whether the data content of the data table of the source database and the data table which is correspondingly migrated to the target database is consistent;
if the data contents are inconsistent, judging whether the current time of the data contents is checked to be in the check time window;
if the current time of the data content is checked to be in the check time window, continuously checking the number of rows of the data table of the source database and the data table which is correspondingly migrated to the target database;
and if the current time for checking the data content is not in the checking time window, outputting a second checking result, wherein the second checking result comprises a line number checking result and a data content checking result.
In some possible embodiments, the performing record internal merging on the target data change records in the first cache file to obtain a second cache file includes: and merging a third data record and a fourth data record by using a merging rule, wherein the third data record and the fourth data record belong to two data change records of the same target data record, and the third data record is generated before the fourth data record.
In some possible embodiments, the merge rule comprises one or a combination of any of the following:
the third data record and the fourth data record both correspond to the same operation, and merging the third data record and the fourth data record by using a merging rule includes: taking a third data record or a fourth data record as a combined result of the third data record and the fourth data record, wherein the operation comprises deletion, update or insertion;
the third data record corresponds to an insert operation, the fourth data record corresponds to a delete operation, and merging the third data record and the fourth data record using a merge rule includes: taking the fourth data record as a merged result of the third data record and the fourth data record;
the third data record corresponds to a delete operation and the fourth data record corresponds to an insert operation, and merging the third data record and the fourth data record using a merge rule includes: taking the fourth data record as a merged result of the third data record and the fourth data record;
the third data record corresponds to an insert operation, the fourth data record corresponds to an update operation, and merging the third data record and the fourth data record using a merge rule includes: taking the third data record as a merged result of the third data record and the fourth data record;
the third data record corresponds to an update operation, the fourth data record corresponds to a delete operation, and merging the third data record and the fourth data record using a merge rule includes: the fourth data record is taken as a merged result of the third data record and the fourth data record.
According to a second aspect of the present disclosure, there is provided a database migration apparatus, the apparatus comprising:
the mapping model establishing module is used for establishing a mapping model, the mapping model is used for converting the data item information of the source database into the data item information in the target database in a one-to-one correspondence manner, and the data item information comprises at least one of the following information: the source database and the target database are heterogeneous databases;
a full data writing module, configured to write the full data of the source database into the target database according to the mapping model;
and the target database changing module is used for responding to the condition that the incremental data log of the source database is received in the writing process and changing the target database according to the incremental data log.
According to a third aspect of the present disclosure, there is provided an electronic device comprising at least one processor, and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the at least one processor implements the database migration method according to any one of the first aspect by executing the instructions stored by the memory.
According to a fourth aspect of the present disclosure, there is provided a computer-readable storage medium having at least one instruction or at least one program stored therein, the at least one instruction or at least one program being loaded and executed by a processor to implement the database migration method according to any one of the first aspect.
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.
The implementation of the present disclosure has the following beneficial effects:
according to the method and the device, data migration among the heterogeneous databases can be realized by constructing the mapping model among the heterogeneous databases, the universality and the expansibility are considered, the target database can be updated in real time according to the incremental data logs, and data synchronization is realized. And by analyzing the data characteristics of the service, the incremental data log data are classified, and the time cost for migrating the source database to the target database is reduced on the premise of not losing the data consistency by combining a synchronous mode and an asynchronous mode. By checking the design of the window in real time, the risk of data difference between the source database and the target database is found timely and efficiently.
Other features and aspects of the present disclosure will become apparent from the following detailed description of exemplary embodiments, which proceeds with reference to the accompanying drawings.
Drawings
In order to more clearly illustrate the embodiments of the present specification or the technical solutions and advantages of the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present specification, and other drawings can be obtained by those skilled in the art without inventive efforts.
FIG. 1 illustrates a flow diagram of a database migration method according to an embodiment of the present disclosure;
FIG. 2 illustrates a logical schematic of a database migration method according to an embodiment of the present disclosure;
FIG. 3 shows a flow diagram of a data warehousing method according to an embodiment of the present disclosure;
FIG. 4 shows a schematic flow diagram of a database reconciliation method according to an embodiment of the present disclosure;
FIG. 5 illustrates a flow diagram of a database migration apparatus according to an embodiment of the present disclosure;
FIG. 6 shows a block diagram of an electronic device in accordance with an embodiment of the disclosure;
fig. 7 shows a block diagram of another electronic device in accordance with an embodiment of the disclosure.
Detailed Description
The technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the drawings in the embodiments of the present disclosure, and it is obvious that the described embodiments are only a part of the embodiments of the present disclosure, and not all of the embodiments. All other embodiments, which can be obtained by a person skilled in the art without inventive step based on the embodiments in the present description, belong to the protection scope of the present invention.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are capable of operation in sequences other than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or server that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
Various exemplary embodiments, features and aspects of the present disclosure will be described in detail below with reference to the accompanying drawings. In the drawings, like reference numbers can indicate functionally identical or similar elements. While the various aspects of the embodiments are presented in drawings, the drawings are not necessarily drawn to scale unless specifically indicated.
The word "exemplary" is used exclusively herein to mean "serving as an example, embodiment, or illustration. Any embodiment described herein as "exemplary" is not necessarily to be construed as preferred or advantageous over other embodiments.
The term "and/or" herein is merely an association describing an associated object, meaning that three relationships may exist, e.g., a and/or B, may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the term "at least one" herein means any one of a plurality or any combination of at least two of a plurality, for example, including at least one of A, B, C, and may mean including any one or more elements selected from the group consisting of A, B and C.
Furthermore, in the following detailed description, numerous specific details are set forth in order to provide a better understanding of the present disclosure. It will be understood by those skilled in the art that the present disclosure may be practiced without some of these specific details. In some instances, methods, means, elements and circuits that are well known to those skilled in the art have not been described in detail so as not to obscure the present disclosure.
Fig. 1 is a schematic flow chart of a database migration method according to an embodiment of the present disclosure, as shown in fig. 1 and fig. 2, the method includes:
s101, establishing a mapping model, wherein the mapping model is used for converting data item information of a source database into data item information in a target database in a one-to-one correspondence manner, and the data item information comprises at least one of the following items: the source database and the target database are heterogeneous databases;
the migration specifications of a source database and a target database are agreed, because fields in the source database and the target database are heterogeneous, a mapping model for converting the fields needs to be constructed, the fields in the source database are mapped into the fields in the target database one by one, the conversion of database names, data table names, field types, field names and the like among the heterogeneous databases is realized through a conversion rule, and data objects of the source database are mapped to the target database. Therefore, a conversion rule between the source database and the target database needs to be configured, mapping relationships of fields such as database names, data table names, field types, field names and the like between the source database and the target database in the source database are constructed, and data objects of the source database are mapped to the target database; the source database and the target database are two different heterogeneous databases, for example, data in the relational database management system oracle database is migrated to the heterogeneous relational database management system MySQL;
s102, writing the full data of the source database into the target database according to the mapping model;
obtaining snapshot version data of full data of a source database in batches by a read obtaining resource Fetch interface of a standard JAVA database connection (JDBC); the obtained full data can be stored in a queue, and the full data in the queue is written into a target database according to a pre-established mapping model;
s103, in response to the condition that the incremental data log of the source database is received in the writing process, the target database is changed according to the incremental data log.
Acquiring an incremental data log of a source database in real time through a materialized view technology; the method comprises the steps of supporting a slave mode slave protocol of a relational database management system MySQL to acquire incremental data logs in real time, wherein the slave mode slave protocol is a real-time data replication protocol based on logs and is used for backing up MySQL data of the relational database management system. According to the method and the device, data migration among the heterogeneous databases can be realized by constructing the mapping model among the heterogeneous databases, the universality and the expansibility are considered, the target database can be updated in real time according to the incremental data logs, and data synchronization is realized.
In one embodiment, altering the target database according to the incremental data log includes:
filtering the incremental data log to obtain a first cache file, wherein the first cache file comprises statements corresponding to database management languages in the incremental data log;
for each target data change record in the first cache file, performing record internal merging on the target data change record to obtain a second cache file, wherein each target data change record comprises at least two associated data change records, and the at least two associated data change records are used for recording data change operation on data records with the same main key;
and in response to the write-in completion condition, changing the target database based on the second cache file.
In one embodiment, a data filtering rule of a source database is configured in advance, and the filtering rule can be user-defined; filtering statements corresponding to Database Management Languages (DML) in the relevant data table in the first cache file, for example, inserting INSERT, UPDATE, DELETE, etc. database relevant operation statements, removing statements corresponding to database schema definition languages (DDL), for example, statements such as modify ALERT, CREATE, DELETE, etc. statements corresponding to DML in the relevant data table in the first cache file; and filtering the data increment log through a filtering rule, filtering a database mode definition language (DLL) in the data increment log, and reserving a Database Management Language (DML) to obtain a first cache file. Merging the target data change records of the first cache file, wherein the target data change records comprise at least two associated data change records, and the associated data change records are database management languages aiming at the data records of the same main key. And internally combining the target data change records in the first cache file to obtain a second cache file, wherein the storage forms of the first cache file and the second cache file comprise queue storage. And writing the second cache file into the target database from the source database, after receiving the second cache file, the target database is changed according to the second cache file, and the database management language DML of the data increment log is internally merged, so that the migrated data is simplified to a great extent, and the efficiency of data migration is improved.
In one embodiment, the method further comprises:
writing a first data record in the second cache file into the target database by using a first thread; writing a second data record in the second cache file into the target database by using a second thread;
any data change record in the first data records and any data change record in the second data records point to data records corresponding to different primary keys;
the second thread is different from the first thread, and the second thread and the first thread run asynchronously.
In one embodiment, the data operation records in the second cache file are divided into a first data record and a second data record, the first data record and the second data record are operation records for different primary keys, for example, the first data record is a data change record of a DELETE operation with a primary key ID of "1001", the second data record is a data change record of a DELETE operation with a primary key ID of "1002", and the first data record may include at least one operation record of data records for the same primary key, and in case of merging failure, the first data record includes a data change record of a DELETE operation with a primary key ID of "1001" and a data change record of an UPDATE operation with a primary key ID of "1001". Writing a first data record into a target database through a first thread, writing a second data record into the target database through a second thread, wherein the first thread and the second thread are different threads, and concurrently writing data change of different main keys into the target database through multiple threads, as shown in fig. 3, the first cache file obtains a second cache file through internal merging and deduplication, the second cache file comprises a first data record and a second data record, the first data record and the second data record are data operation records of different main keys, namely multiple changes of different main keys, the first data record and the second data record are synchronously written into the target database through different threads, the first data record or the second data record comprises at least one operation record aiming at the data record of the same main key, and the operation records aiming at the same main key in the first data record are asynchronously written into the target database through the same thread, namely the first thread, and asynchronously writing operation records of a plurality of data records aiming at the same other main key in the first data record into the target database through the same thread, namely the first thread. By analyzing the data characteristics of the service, the data operation records are classified, and the time cost for transferring the source database to the target database is reduced by combining a synchronous mode and an asynchronous mode.
In one embodiment, the method further comprises:
checking whether the number of rows of the data table of the source database and the data table which is correspondingly migrated to the target database are consistent in real time;
if the line numbers are not consistent, judging whether the current time for checking the line numbers is in a preset checking time window or not;
if the current time for checking the line number is in the checking time window, continuing to check the line number of the data table of the source database and the data table which is correspondingly migrated to the target database;
and if the current time for checking the line number is not in the checking time window, outputting a first checking result, wherein the first checking result comprises the checking result of the line number.
Referring to fig. 4, in an embodiment, a data processing flow (SETL) is entered, a source database and a target database are grouped according to a database name or a data table name, a check time window is respectively created for each group, and the check time window may be 90s at most. Removing duplication according to the Hash algorithm of the data main key, and removing repeatedly recorded data; and performing reverse check on the source database and the target database in the check time window, recording whether the line numbers are consistent, judging whether the current time of the line numbers is in the check time window if the line numbers are inconsistent, continuously checking the data line numbers of the source database and the target database if the line numbers are inconsistent, and outputting a first check result if the line numbers are not in the check time window, wherein the first check result comprises a line number check result, and the first check result can be that the line number check result is inconsistent. For example, the data Table "Table 1" in the source database and the data Table "Table 1 '" corresponding to the migration target database are checked, the data tables of "Table 1" and "Table 1'" are stored in a queue form, the tables of "Table 1" and "Table 1 '" are checked according to the second cache file, a check time window is set to 90s, that is, the maximum number of times of retry of checking is allowed to be 90 times, if the row numbers in the tables of "Table 1" and "Table 1'" are inconsistent, it is determined whether the current check time is within the check time window, that is, whether the check number is within 90 times, if yes, the tables of "Table 1" and "Table 1 '" are continuously checked, and if 90 times are exceeded, the check result is output, and the line numbers of the tables of "Table 1" and "Table 1'" are inconsistent. The maximum allowable checking retry number is set, the situation of checking failure caused by concurrent change can be reduced, and the risk of data difference between the source database and the target database can be timely and efficiently found through the design of a real-time checking window in the target database.
In one embodiment, the method further comprises:
if the line numbers are consistent, checking whether the data content of the data table of the source database and the data table which is correspondingly migrated to the target database is consistent;
if the data contents are inconsistent, judging whether the current time of the data contents is checked to be in the check time window;
if the current time of the data content is checked to be in the check time window, continuously checking the number of rows of the data table of the source database and the data table which is correspondingly migrated to the target database;
and if the current time for checking the data content is not in the checking time window, outputting a second checking result, wherein the second checking result comprises a line number checking result and a data content checking result.
In one embodiment, if the row number of the data table of the source database is consistent with the row number of the data table of the target database in the check time window, continuously checking whether the data content of the data table of the source database is consistent with the data content of the data table of the target database, if the data content is inconsistent, judging whether the current time of the check data content is in the check time window, if not, outputting a second check result, wherein the second check result can be that the row number check result is consistent and the data content check result is inconsistent, and if the check time window is in the check time window, continuously checking whether the row number of the data table of the source database is consistent with the row number of the data table of the target database; if the data content is consistent, outputting a third checking result, wherein the third checking result can be that the line number checking result is consistent and the data content checking result is consistent; by means of an efficient real-time checking algorithm, real-time incremental data of a data Table in a source database are located in different checking windows in batches, for example, the line number checking results of the Table1 and the Table1 'are consistent, contents of the Table1 and the Table 1' are continuously checked, if the contents are consistent, the checking results are output, namely line numbers of the Table1 and the Table1 'are consistent with the contents, if the contents are inconsistent, whether the checking time of the Table1 and the Table 1' is within the checking time window is continuously judged, namely whether the checking frequency is within 90 times, if the checking times are not consistent, the line numbers and the contents of the Table1 and the Table1 'are continuously checked, and if the checking frequency is greater than 90 times, the checking results are output, namely line numbers of the Table1 and the Table 35 1' are consistent, and the contents are inconsistent. A single check window can be 90 seconds at most, and a source database and a target database are continuously and reversely checked in the real-time check window to check data, so that false alarm caused by data delay is avoided, and meanwhile, missing report is also avoided.
In an embodiment, the performing record internal merging on the target data change records in the first cache file to obtain a second cache file includes: and merging a third data record and a fourth data record by using a merging rule, wherein the third data record and the fourth data record belong to two data change records of the same target data record, and the third data record is generated before the fourth data record.
In one embodiment, the third data record and the fourth data record are merged by using a merge rule, for example, if the first generated third data record in the first cache file is a data change record for deleting DELETE operation with a primary key ID of "1001", and the later generated fourth data record is a data change record for inserting INSERT operation with a primary key ID of "1001", the third data record and the fourth data record are merged by using a merge rule, so as to obtain a data change record for inserting INSERT operation with a primary key ID of "1001", remove redundant data, and shorten the time cost for migrating the source database to the target database.
In one embodiment, the merge rule comprises one or a combination of any of the following:
the third data record and the fourth data record both correspond to the same operation, and merging the third data record and the fourth data record by using a merging rule includes: taking a third data record or a fourth data record as a combined result of the third data record and the fourth data record, wherein the operation comprises deletion, update or insertion;
the third data record corresponds to an insert operation, the fourth data record corresponds to a delete operation, and merging the third data record and the fourth data record using a merge rule includes: taking the fourth data record as a merged result of the third data record and the fourth data record;
the third data record corresponds to a delete operation and the fourth data record corresponds to an insert operation, and merging the third data record and the fourth data record using a merge rule includes: taking the fourth data record as a merged result of the third data record and the fourth data record;
the third data record corresponds to an insert operation, the fourth data record corresponds to an update operation, and merging the third data record and the fourth data record using a merge rule includes: taking the third data record as a merged result of the third data record and the fourth data record;
the third data record corresponds to an update operation, the fourth data record corresponds to a delete operation, and merging the third data record and the fourth data record using a merge rule includes: the fourth data record is taken as a merged result of the third data record and the fourth data record.
In one embodiment, when there are multiple identical data operation records for the same primary key, the multiple identical data operation records may be merged into one record, for example, multiple DELETE operations for the same primary key are merged into one DELETE operation record, multiple UPDATE operations for the same primary key are merged into one UPDATE operation record, and multiple INSERT operations for the same primary key are merged into one INSERT operation record; for example, when the third data record is the data change record for the DELETE operation with the primary key ID of "1001" and the fourth data record is the data change record for the DELETE operation with the primary key ID of "1001", the third data record and the fourth data record are merged into one record, that is, the data change record for the DELETE operation with the primary key ID of "1001". When DELETE operation is first performed and then INSERT operation is performed on the same primary key, the corresponding two records are merged into one INSERT operation record, for example, when the third data record is a data change record for DELETE operation with a primary key ID of "1001", and the fourth data record is a data change record for INSERT operation with a primary key ID of "1001", the third data record and the fourth data record are merged into one INSERT operation record with a primary key ID of "1001". When INSERT is inserted first and then DELETE is deleted for the same primary key, the corresponding two records are merged into one DELETE DELETE operation record, for example, when the third data record is the data change record of INSERT insertion operation with primary key ID of '1001' and the fourth data record is the data change record of DELETE DELETE operation with primary key ID of '1001', the third data record and the fourth data record are merged into one DELETE DELETE operation record with primary key ID of '1001'. When the UPDATE is performed before the DELETE is performed on the same primary key, the corresponding two records are merged into one DELETE operation record, for example, when the third data record is a data change record of an UPDATE operation with a primary key ID of "1001" and the fourth data record is a data change record of a DELETE operation with a primary key ID of "1001", the third data record and the fourth data record are merged into one DELETE operation record with a primary key ID of "1001". In addition, the rules are combined for use and are also suitable for use, for example, INSERT is firstly inserted into the same main key, then DELETE operation is deleted, UPDATE UPDATE operation is then carried out on the same main key, then insertion into INSER operation is carried out, according to the rules, the INSERT insertion operation record and the DELETE deletion operation record are firstly combined into a DELETE deletion operation record, then the DELETE deletion operation record and the UPDATE UPDATE operation record are combined to obtain a DELETE deletion operation record, then the DELETE deletion operation record and the INSER insertion operation record are combined, and finally an INSER insertion operation record is obtained. The multiple operation records of the same main key are combined into a final operation record, and then data migration is carried out, so that the data volume of migration is reduced to a greater extent on the premise of ensuring no loss of data consistency, the migration efficiency is improved, and the time cost for migrating the source database to the target database is shortened.
Referring to fig. 5, according to a second aspect of the present disclosure, there is provided a database migration apparatus, the apparatus including:
a mapping model establishing module 10, configured to establish a mapping model, where the mapping model is used to convert data item information of a source database into data item information in a target database in a one-to-one correspondence manner, where the data item information includes at least one of the following: the source database and the target database are heterogeneous databases;
a full data writing module 20, configured to write the full data of the source database into the target database according to the mapping model;
and the target database changing module 30 is configured to, in response to a situation that the incremental data log of the source database is received in the writing process, change the target database according to the incremental data log.
In some embodiments, functions of or modules included in the apparatus provided in the embodiments of the present disclosure may be used to execute the method described in the above method embodiments, and specific implementation thereof may refer to the description of the above method embodiments, and for brevity, will not be described again here.
The embodiment of the present disclosure also provides a computer-readable storage medium, where at least one instruction or at least one program is stored in the computer-readable storage medium, and the at least one instruction or the at least one program is loaded by a processor and executed to implement the method. The computer readable storage medium may be a non-volatile computer readable storage medium.
An embodiment of the present disclosure further provides an electronic device, including: a processor; a memory for storing processor-executable instructions; wherein the processor is configured as the method.
The electronic device may be provided as a terminal, server, or other form of device.
Fig. 6 illustrates a block diagram of an electronic device in accordance with an embodiment of the disclosure. For example, the electronic device 800 may be a mobile phone, a computer, a digital broadcast terminal, a messaging device, a game console, a tablet device, a medical device, a fitness device, a personal digital assistant, or the like terminal.
Referring to fig. 6, electronic device 800 may include one or more of the following components: processing component 802, memory 804, power component 806, multimedia component 808, audio component 810, input/output (I/O) interface 812, sensor component 814, and communication component 816.
The processing component 802 generally controls overall operation of the electronic device 800, such as operations associated with display, telephone calls, data communications, camera operations, and recording operations. The processing components 802 may include one or more processors 820 to execute instructions to perform all or a portion of the steps of the methods described above. Further, the processing component 802 can include one or more modules that facilitate interaction between the processing component 802 and other components. For example, the processing component 802 can include a multimedia module to facilitate interaction between the multimedia component 808 and the processing component 802.
The memory 804 is configured to store various types of data to support operations at the electronic device 800. Examples of such data include instructions for any application or method operating on the electronic device 800, contact data, phonebook data, messages, pictures, videos, and so forth. The memory 804 may be implemented by any type or combination of volatile or non-volatile memory devices such as Static Random Access Memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic or optical disks.
The power supply component 806 provides power to the various components of the electronic device 800. The power components 806 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power for the electronic device 800.
The multimedia component 808 includes a screen that provides an output interface between the electronic device 800 and a user as described above. In some embodiments, the screen may include a Liquid Crystal Display (LCD) and a Touch Panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive an input signal from a user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundary of the touch or slide action but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 808 includes a front facing camera and/or a rear facing camera. The front camera and/or the rear camera may receive external multimedia data when the electronic device 800 is in an operation mode, such as a shooting mode or a video mode. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
The audio component 810 is configured to output and/or input audio signals. For example, the audio component 810 includes a Microphone (MIC) configured to receive external audio signals when the electronic device 800 is in an operational mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signals may further be stored in the memory 804 or transmitted via the communication component 816. In some embodiments, audio component 810 also includes a speaker for outputting audio signals.
The I/O interface 812 provides an interface between the processing component 802 and peripheral interface modules, which may be keyboards, click wheels, buttons, etc. These buttons may include, but are not limited to: a home button, a volume button, a start button, and a lock button.
The sensor assembly 814 includes one or more sensors for providing various aspects of state assessment for the electronic device 800. For example, the sensor assembly 814 may detect an open/closed state of the electronic device 800, the relative positioning of components, such as a display and keypad of the electronic device 800, the sensor assembly 814 may also detect a change in position of the electronic device 800 or a component of the electronic device 800, the presence or absence of user contact with the electronic device 800, orientation or acceleration/deceleration of the electronic device 800, and a change in temperature of the electronic device 800. Sensor assembly 814 may include a proximity sensor configured to detect the presence of a nearby object without any physical contact. The sensor assembly 814 may also include a light sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 814 may also include an acceleration sensor, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
The communication component 816 is configured to facilitate wired or wireless communication between the electronic device 800 and other devices. The electronic device 800 may access a wireless network based on a communication standard, such as WiFi, 2G, 3G, 4G, 5G, or a combination thereof. In an exemplary embodiment, the communication component 816 receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the above-mentioned communication component 816 further comprises a Near Field Communication (NFC) module to facilitate short-range communication. For example, the NFC module may be implemented based on Radio Frequency Identification (RFID) technology, infrared data association (IrDA) technology, Ultra Wideband (UWB) technology, Bluetooth (BT) technology, and other technologies.
In an exemplary embodiment, the electronic device 800 may be implemented by one or more Application Specific Integrated Circuits (ASICs), Digital Signal Processors (DSPs), Digital Signal Processing Devices (DSPDs), Programmable Logic Devices (PLDs), Field Programmable Gate Arrays (FPGAs), controllers, micro-controllers, microprocessors or other electronic components for performing the above-described methods.
In an exemplary embodiment, a non-transitory computer-readable storage medium, such as the memory 804, is also provided that includes computer program instructions executable by the processor 820 of the electronic device 800 to perform the above-described methods.
Fig. 7 shows a block diagram of another electronic device in accordance with an embodiment of the disclosure. For example, electronic device 1900 may be provided as a server. Referring to fig. 7, electronic device 1900 includes a processing component 1922 further including one or more processors and memory resources, represented by memory 1932, for storing instructions, e.g., applications, executable by processing component 1922. The application programs stored in memory 1932 may include one or more modules that each correspond to a set of instructions. Further, the processing component 1922 is configured to execute instructions to perform the above-described method.
The electronic device 1900 may also include a power component 1926 configured to perform power management of the electronic device 1900, a wired or wireless network interface 1950 configured to connect the electronic device 1900 to a network, and an input/output (I/O) interface 1958. The electronic device 1900 may operate based on an operating system, such as Windows Server, MacOSXTM, UnixTM, LinuxTM, FreeBSDTM, or the like, stored in memory 1932.
In an exemplary embodiment, a non-transitory computer readable storage medium, such as the memory 1932, is also provided that includes computer program instructions executable by the processing component 1922 of the electronic device 1900 to perform the above-described methods.
The present disclosure may be systems, methods, and/or computer program products. The computer program product may include a computer-readable storage medium having computer-readable program instructions embodied thereon for causing a processor to implement various aspects of the present disclosure.
The computer readable storage medium may be a tangible device that can hold and store the instructions for use by the instruction execution device. The computer readable storage medium may be, for example, but not limited to, an electronic memory device, a magnetic memory device, an optical memory device, an electromagnetic memory device, a semiconductor memory device, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: 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), a Static Random Access Memory (SRAM), a portable compact disc read-only memory (CD-ROM), a Digital Versatile Disc (DVD), a memory stick, a floppy disk, a mechanical coding device, such as punch cards or in-groove projection structures having instructions stored thereon, and any suitable combination of the foregoing. Computer-readable storage media as used herein is not to be construed as transitory signals per se, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through a waveguide or other transmission medium (e.g., optical pulses through a fiber optic cable), or electrical signals transmitted through electrical wires.
The computer-readable program instructions described herein may be downloaded from a computer-readable storage medium to a respective computing/processing device, or to an external computer or external storage device via a network, such as the internet, a local area network, a wide area network, and/or a wireless network. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers and/or edge servers. The network adapter card or network interface in each computing/processing device receives computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in a computer-readable storage medium in the respective computing/processing device.
The computer program instructions for carrying out operations of the present disclosure may be assembly instructions, Instruction Set Architecture (ISA) instructions, machine related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including an object oriented programming language such as Smalltalk, C + or the like, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider). In some embodiments, the electronic circuitry that can execute the computer-readable program instructions implements aspects of the present disclosure by utilizing the state information of the computer-readable program instructions to personalize the electronic circuitry, such as a programmable logic circuit, a Field Programmable Gate Array (FPGA), or a Programmable Logic Array (PLA).
Various aspects of the present disclosure are described herein with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the disclosure. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer-readable program instructions.
These computer-readable program instructions may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks. These computer-readable program instructions may also be stored in a computer-readable storage medium that can direct a computer, programmable data processing apparatus, and/or other devices to function in a particular manner, such that the computer-readable medium storing the instructions comprises an article of manufacture including instructions which implement the function/act specified in the flowchart and/or block diagram block or blocks.
The computer readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other devices to cause a series of operational steps to be performed on the computer, other programmable apparatus or other devices to produce a computer implemented process such that the instructions which execute on the computer, other programmable apparatus or other devices implement the functions/acts specified in the flowchart and/or block diagram block or blocks.
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 instructions, which comprises one or more executable instructions for implementing the specified logical function(s). 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 and/or flowchart illustration, and combinations of blocks in the block diagrams and/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.
Having described embodiments of the present disclosure, the foregoing description is intended to be exemplary, not exhaustive, and not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The terminology used herein was chosen in order to best explain the principles of the embodiments, the practical application, or technical improvements to the market, or to enable others of ordinary skill in the art to understand the embodiments disclosed herein.

Claims (10)

1. A method of database migration, the method comprising:
establishing a mapping model, wherein the mapping model is used for converting the data item information of the source database into the data item information in the target database in a one-to-one correspondence manner, and the data item information comprises at least one of the following data items: the source database and the target database are heterogeneous databases;
writing the full data of the source database into the target database according to the mapping model;
and responding to the condition that the incremental data log of the source database is received in the writing process, and changing the target database according to the incremental data log.
2. The method of claim 1, wherein altering the target database from the delta data log comprises:
filtering the incremental data log to obtain a first cache file, wherein the first cache file comprises statements corresponding to database management languages in the incremental data log;
for each target data change record in the first cache file, performing record internal merging on the target data change record to obtain a second cache file, wherein each target data change record comprises at least two associated data change records, and the at least two associated data change records are used for recording data change operation on data records with the same main key;
and in response to the write-in completion condition, changing the target database based on the second cache file.
3. The method of claim 2, further comprising:
writing a first data record in the second cache file into the target database by using a first thread; writing a second data record in the second cache file into the target database by using a second thread;
any data change record in the first data records and any data change record in the second data records point to data records corresponding to different primary keys;
the second thread is different from the first thread, and the second thread and the first thread run asynchronously.
4. Method according to at least one of the claims 1 to 3, characterized in that the method further comprises:
checking whether the number of rows of the data table of the source database and the data table which is correspondingly migrated to the target database are consistent in real time;
if the line numbers are not consistent, judging whether the current time for checking the line numbers is in a preset checking time window or not;
if the current time for checking the line number is in the checking time window, continuing to check the line number of the data table of the source database and the data table which is correspondingly migrated to the target database;
and if the current time for checking the line number is not in the checking time window, outputting a first checking result, wherein the first checking result comprises the checking result of the line number.
5. The method of claim 4, further comprising:
if the line numbers are consistent, checking whether the data content of the data table of the source database and the data table which is correspondingly migrated to the target database is consistent;
if the data contents are inconsistent, judging whether the current time of the data contents is checked to be in the check time window;
if the current time of the data content is checked to be in the check time window, continuously checking the number of rows of the data table of the source database and the data table which is correspondingly migrated to the target database;
and if the current time for checking the data content is not in the checking time window, outputting a second checking result, wherein the second checking result comprises a line number checking result and a data content checking result.
6. The method of claim 2, wherein the performing record-internal merging on the target data change records to obtain a second cache file for each target data change record in the first cache file comprises: and merging a third data record and a fourth data record by using a merging rule, wherein the third data record and the fourth data record belong to two data change records of the same target data record, and the third data record is generated before the fourth data record.
7. The method of claim 6, wherein the merge rule comprises one or a combination of any of the following:
the third data record and the fourth data record both correspond to the same operation, and merging the third data record and the fourth data record by using a merging rule includes: taking a third data record or a fourth data record as a combined result of the third data record and the fourth data record, wherein the operation comprises deletion, update or insertion;
the third data record corresponds to an insert operation, the fourth data record corresponds to a delete operation, and merging the third data record and the fourth data record using a merge rule includes: taking the fourth data record as a merged result of the third data record and the fourth data record;
the third data record corresponds to a delete operation and the fourth data record corresponds to an insert operation, and merging the third data record and the fourth data record using a merge rule includes: taking the fourth data record as a merged result of the third data record and the fourth data record;
the third data record corresponds to an insert operation, the fourth data record corresponds to an update operation, and merging the third data record and the fourth data record using a merge rule includes: taking the third data record as a merged result of the third data record and the fourth data record;
the third data record corresponds to an update operation, the fourth data record corresponds to a delete operation, and merging the third data record and the fourth data record using a merge rule includes: the fourth data record is taken as a merged result of the third data record and the fourth data record.
8. An apparatus for database migration, the apparatus comprising:
the mapping model establishing module is used for establishing a mapping model, the mapping model is used for converting the data item information of the source database into the data item information in the target database in a one-to-one correspondence manner, and the data item information comprises at least one of the following information: the source database and the target database are heterogeneous databases;
a full data writing module, configured to write the full data of the source database into the target database according to the mapping model;
and the target database changing module is used for responding to the condition that the incremental data log of the source database is received in the writing process and changing the target database according to the incremental data log.
9. A computer-readable storage medium, in which at least one instruction or at least one program is stored, which is loaded and executed by a processor to implement the database migration method according to any one of claims 1 to 7.
10. An electronic device comprising at least one processor, and a memory communicatively coupled to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the at least one processor implementing the database migration method of any one of claims 1-7 by executing the instructions stored by the memory.
CN202210279888.1A 2022-03-21 2022-03-21 Database migration method and device, storage medium and electronic equipment Pending CN114546992A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210279888.1A CN114546992A (en) 2022-03-21 2022-03-21 Database migration method and device, storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210279888.1A CN114546992A (en) 2022-03-21 2022-03-21 Database migration method and device, storage medium and electronic equipment

Publications (1)

Publication Number Publication Date
CN114546992A true CN114546992A (en) 2022-05-27

Family

ID=81665509

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210279888.1A Pending CN114546992A (en) 2022-03-21 2022-03-21 Database migration method and device, storage medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN114546992A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115408473A (en) * 2022-11-01 2022-11-29 神州数码融信云技术服务有限公司 Data synchronization method and device, computer equipment and computer readable storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115408473A (en) * 2022-11-01 2022-11-29 神州数码融信云技术服务有限公司 Data synchronization method and device, computer equipment and computer readable storage medium

Similar Documents

Publication Publication Date Title
EP2950486B1 (en) Method and device for managing instant message
CN114546992A (en) Database migration method and device, storage medium and electronic equipment
CN114356891A (en) Data migration method, device, storage medium and program product
US20210133505A1 (en) Method, device, and storage medium for retrieving samples
US9894510B1 (en) Event-based data backup and recovery for mobile devices
CN107885571B (en) Display page control method and device
CN111290882B (en) Data file backup method, data file backup device and electronic equipment
CN115687303A (en) Data information migration method, device, equipment and storage medium
CN107256151A (en) Processing method, device and the terminal of page rendering
CN113378893A (en) Data management method and device, electronic equipment and storage medium
CN110493298B (en) Information synchronization method and device
CN113378022A (en) In-station search platform, search method and related device
CN110673850A (en) Method and device for obtaining size of static library
CN116361071B (en) Backup file generation method, device, equipment and storage medium
CN116774927B (en) Optical disk data management method, optical disk data management device, electronic equipment and readable storage medium
CN111274210B (en) Metadata processing method and device and electronic equipment
CN111159148B (en) Configuration information state management method and device, electronic equipment and storage medium
CN113946346B (en) Data processing method and device, electronic equipment and storage medium
CN114936048B (en) Configuration management method, device, electronic equipment and storage medium
CN114003558A (en) Data archiving method, device, equipment and storage medium
CN107273154B (en) Method, device and terminal for operating application program
CN116185301A (en) Data storage processing method, platform, server, system, medium and product
CN116009946A (en) Git-based code statistics method and device
CN115062012A (en) Data processing method, data processing device, storage medium and electronic equipment
CN116976291A (en) Nuclear power plant program file structured editing method and platform

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