Data migration method and device
By creating temporary tables in the database and utilizing the multi-threaded import and exchange model, the problems of index failure and slow import speed are solved, and rapid updating of big data tables and business continuity are achieved.
Patent Information
- Application Number
- CN202011476755.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-14
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2040-12-14
AI Technical Summary
When importing a large amount of data into a database table with an index, the index in the existing technology is prone to failure, resulting in slow data import speed and high risk, and it is impossible to ensure that the index does not fail and has high performance at the same time.
By creating a temporary table consistent with the target table structure, use the preset split model to divide the data into multiple files, and use sqlldr's multi-threading method to import the temporary table. After establishing the index, the data is exchanged to the target table through the preset exchange model. , and delete the temporary table index information at the same time to avoid index failure problems.
It achieves avoiding index failures while maintaining high performance, ensuring rapid batch updates of big data tables, ensuring uninterrupted business, and faster import speed.
Smart Images

Figure CN112597126B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a data migration method and device. Background Art
[0002] Oracle's Sql Loader (abbreviated as sqlldr) tool can import data files into Oracle database, that is, import data files into Oracle database through Oracle's own sqlldr. The ctl file of sqlldr can be written to modify the parameters when using sqlldr.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0004] If you want to quickly import data into the database, you need to set the direct parameter of sqlldr to true, but this will invalidate the database index during the derivation process, especially when the amount of data is huge. Index failure is very dangerous, and there is also a huge risk of rebuilding the index for the large amount of data. In the process, there will also be problems accessing the table. If the direct parameter is set to false, the data can be safely imported without invalidating the index, but the derivation speed is greatly reduced and the performance is very poor. Summary of the invention
[0005] In view of this, an embodiment of the present invention provides a data migration method and device, which can solve the security and performance problems caused by importing a large amount of data into a table with an index, while ensuring that the business will not be interrupted.
[0006] To achieve the above-mentioned purpose, according to one aspect of an embodiment of the present invention, a data migration method is provided, comprising acquiring data to be migrated, determining a target table to be imported into the data to be migrated, so as to create a temporary table consistent with the structure of the target table; calling a preset segmentation model to divide the data to be migrated into multiple data files, and then importing the data files into the temporary table; wherein, after each data file is imported into the temporary table, index information of the data file consistent with the target table is established for the temporary table; based on a preset exchange model, the data files in the temporary table are exchanged with the target table.
[0007] Optionally, the data to be migrated is divided into multiple data files based on a preset segmentation model, including:
[0008] The business type corresponding to the data to be migrated is determined to obtain a partition field of the business type, and then the data to be migrated is divided into a plurality of data files according to the partition field.
[0009] Optionally, after dividing the to-be-migrated data into a plurality of data files according to the partition field, the method further includes:
[0010] It is determined whether the data volume of the data file is greater than a preset quantity threshold, if so, the data file is divided into a plurality of sub-data files, otherwise, the data file is not processed.
[0011] Optionally, importing the data file into the temporary table includes:
[0012] The data file is imported into the temporary table through the sqlldr multi-thread method; wherein the direct parameter and the parallel parameter in the ctl file of sqlldr are set to true.
[0013] Optionally, the data file is imported into the temporary table by using the sqlldr multi-thread method, including:
[0014] Multiple threads import the same data file at the same time;
[0015] If there is a thread without data file import, the thread state is set to wait.
[0016] Optionally, based on a preset exchange model, exchanging the data file in the temporary table to the target table includes:
[0017] After a data file is imported, the temporary table and the target table exchange partitions, and exchange indexes at the same time.
[0018] Optionally, after exchanging the data file in the temporary table to the target table, the method further includes: deleting index information in the temporary table.
[0019] In addition, the present invention also provides a data migration device, including an acquisition module, used to acquire the data to be migrated, determine the target table to be imported into the data to be migrated, so as to create a temporary table consistent with the structure of the target table; a processing module, used to call a preset segmentation model, divide the data to be migrated into multiple data files, and then import the data files into the temporary table; wherein, after each data file is imported into the temporary table, index information of the data file consistent with the target table is established for the temporary table; based on a preset exchange model, the data files in the temporary table are exchanged to the target table.
[0020] An embodiment of the above invention has the following advantages or beneficial effects: the present invention can use temporary tables to perform partition exchange, thereby avoiding the problem of index failure; and, in a high-throughput real-time trading system, it can achieve uninterrupted business and quickly complete batch data updates of large data tables; at the same time, the present invention performs derivatives while keeping the direct parameter as true, and will not cause index failure problems, and enables multi-threaded parallel import to make the import speed faster.
[0021] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0023] Figure 1 is a schematic diagram of the main process of the data migration method according to the first embodiment of the present invention;
[0024] Figure 2 is a schematic diagram of the architecture of a data migration method according to a second embodiment of the present invention;
[0025] Figure 3 is a schematic diagram of main modules of a data migration device according to an embodiment of the present invention;
[0026] Figure 4 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0027] Figure 5 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0028] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0029] Figure 1 is a schematic diagram of the main process of the data migration method according to the first embodiment of the present invention. Figure 1 As shown, the data migration method includes:
[0030] Step S101 : acquiring data to be migrated, determining a target table into which the data to be migrated is to be imported, and creating a temporary table having a structure consistent with the target table.
[0031] In an embodiment, the data to be migrated is migrated from the data source layer to the target layer, namely the target table, wherein a temporary table having a structure completely consistent with the target table is created as a transfer station, and finally the data is migrated to the target layer through partition exchange technology.
[0032] Step S102, calling a preset segmentation model to divide the data to be migrated into multiple data files, and then importing the data files into the temporary table; wherein, after each data file is imported into the temporary table, index information of the data file consistent with the target table is established for the temporary table.
[0033] In some embodiments, the data to be migrated is divided into multiple data files based on a preset segmentation model, including determining the business type corresponding to the data to be migrated to obtain a partition field of the business type, and then dividing the data to be migrated into multiple data files according to the partition field. For example: for a complete repayment cash flow plan business type of a bank, the data can be partitioned by branch according to the branch field.
[0034] In a further embodiment, after the data to be migrated is divided into multiple data files according to the partition field, it can also be determined whether the data volume of the data file is greater than a preset quantity threshold. If so, the data file is divided into a plurality of sub-data files, otherwise, it is not processed. For example: there are 3 values in the partition field X, then 3 data files should be divided, and the attribute values of the field X of the 3 data files t, m, and n are different. If the data volume of the data file is greater than the preset quantity threshold, that is, the file may be too large, then continue to divide it to obtain t1, t2, t3, t4, m1, m2, n1, n2, and n3, each file can contain 500,000 to 5 million data, of course, the overall data volume must also be referred to.
[0035] As some other embodiments, importing the data file into the temporary table includes: importing the data file into the temporary table through the sqlldr multi-threading method; wherein, setting the direct parameter and the parallel parameter in the ctl file of sqlldr to true, thereby improving the derivative performance. It should be noted that sqlldr is ORACLE's data loading tool. Ctl is the control file of sqlldr. Among them, the Direct parameter directly pours the data into the table. During this process, if the table has an index, the index will become invalid. The Parallel parameter is to turn on parallelism, and it can only be turned on when the direct parameter is turned on. Both the direct parameter and the parallel parameter will speed up the derivative speed.
[0036] In a further embodiment, the data file is imported into the temporary table by the sqlldr multi-thread method, including: multiple threads import the same data file at the same time; if there is a thread that has no data file to import, the thread state is set to wait. For example: 3 threads are started, and the t data file has 4 sub-data files, then when thread 1 imports the fourth sub-data file, the other two threads wait for thread 1 to complete. That is, each thread imports 1 sub-data file, and if there is only one sub-data file, only 1 thread works.
[0037] Step S103: based on a preset exchange model, exchange the data files in the temporary table to the target table.
[0038] In some embodiments, based on a preset exchange model, the data files in the temporary table are exchanged with the target table, including after a data file is imported, the temporary table and the target table perform partition exchange, and exchange indexes while exchanging partitions. The index information is an index field, and the index field in the temporary table is completely consistent with the index field in the target table.
[0039] In a further embodiment, after exchanging the data files in the temporary table to the target table, the index information in the temporary table can be deleted, i.e., to prepare for the import of other data files, for example: repeat the above operation for m and n data files until all data files are imported into the target table.
[0040] Figure 2 is a schematic diagram of the main process of a data migration method according to a second embodiment of the present invention, the data migration method comprising:
[0041] Step S201: acquiring data to be migrated and determining a target table into which the data to be migrated is to be imported.
[0042] Step S202: Create a temporary table according to the table structure of the target table.
[0043] Step S203: determining the business type corresponding to the data to be migrated to obtain a partition field of the business type, and then dividing the data to be migrated into a plurality of data files according to the partition field.
[0044] Step S204: if the data volume of the data file is greater than a preset data volume threshold, the data file is divided into a plurality of sub-data files.
[0045] Step S205, setting the direct parameter and the parallel parameter in the ctl file of sqlldr to true.
[0046] Step S206: import the data file into the temporary table through the sqlldr multi-thread method.
[0047] Step S207: after each data file is imported into the temporary table, index information of the data file consistent with the target table is created for the temporary table.
[0048] Step S208, after a data file is imported, the temporary table and the target table perform partition exchange, and the indexes are exchanged at the same time when the partitions are exchanged.
[0049] Step S209, deleting the index information in the temporary table, returning to step S206 to iteratively execute steps S206 to S209 until all data files are stored in the target table.
[0050] Figure 3 is a schematic diagram of main modules of a data migration device according to an embodiment of the present invention, such as Figure 3 As shown, the data migration device includes an acquisition module 301 and a processing module 302. The acquisition module 301 acquires the data to be migrated, determines the target table to be imported into the data to be migrated, and creates a temporary table consistent with the structure of the target table; the processing module 302 calls a preset segmentation model to divide the data to be migrated into multiple data files, and then imports the data files into the temporary table; after each data file is imported into the temporary table, index information of the data file consistent with the target table is established for the temporary table; based on the preset exchange model, the data files in the temporary table are exchanged with the target table.
[0051] In some embodiments, the processing module 302 divides the data to be migrated into multiple data files based on a preset segmentation model, including: determining the business type corresponding to the data to be migrated to obtain the partition field of the business type, and then dividing the data to be migrated into multiple data files according to the partition field.
[0052] In some embodiments, after the processing module 302 divides the to-be-migrated data into multiple data files according to the partition field, the processing module 302 further includes:
[0053] It is determined whether the data volume of the data file is greater than a preset quantity threshold, if so, the data file is divided into a plurality of sub-data files, otherwise, the data file is not processed.
[0054] In some embodiments, the processing module 302 imports the data file into the temporary table, including:
[0055] The data file is imported into the temporary table through the sqlldr multi-thread method; wherein the direct parameter and the parallel parameter in the ctl file of sqlldr are set to true.
[0056] In some embodiments, the processing module 302 imports the data file into the temporary table through the sqlldr multi-thread method, including:
[0057] Multiple threads import the same data file at the same time;
[0058] If there is a thread without data file import, the thread state is set to wait.
[0059] In some embodiments, the processing module 302 exchanges the data files in the temporary table to the target table based on a preset exchange model, including:
[0060] After a data file is imported, the temporary table and the target table exchange partitions, and exchange indexes at the same time.
[0061] In some embodiments, after the processing module 302 exchanges the data file in the temporary table to the target table, the processing module 302 includes: deleting the index information in the temporary table.
[0062] It should be noted that the data migration method and the data migration device of the present invention have a corresponding relationship in terms of specific implementation contents, so the repeated contents will not be described again.
[0063] Figure 4 An exemplary system architecture 400 is shown to which the data migration method or data migration apparatus according to the embodiment of the present invention can be applied.
[0064] like Figure 4 As shown, system architecture 400 may include terminal devices 401, 402, 403, network 404 and server 405. Network 404 is used to provide a medium for communication links between terminal devices 401, 402, 403 and server 405. Network 404 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0065] Users can use terminal devices 401, 402, 403 to interact with server 405 through network 404 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 401, 402, 403, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only as examples).
[0066] The terminal devices 401 , 402 , and 403 may be various electronic devices having a data migration screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.
[0067] The server 405 may be a server that provides various services, such as a backend management server (only an example) that provides support for shopping websites browsed by users using the terminal devices 401, 402, and 403. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information, product information - only an example) to the terminal device.
[0068] It should be noted that the data migration method provided in the embodiment of the present invention is generally executed by the server 405 , and accordingly, the computing device is generally arranged in the server 405 .
[0069] It should be understood that Figure 4 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0070] Reference below Figure 5 , which shows a schematic diagram of the structure of a computer system 500 of a terminal device suitable for implementing an embodiment of the present invention. Figure 5 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0071] like Figure 5 As shown, the computer system 500 includes a central processing unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage part 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the computer system 500 are also stored. The CPU 401, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0072] The following components are connected to the I / O interface 505: an input section 506 including a keyboard, a mouse, etc.; an output section 507 including a cathode ray tube (CRT), a liquid crystal data transfer device (LCD), etc., and a speaker, etc.; a storage section 508 including a hard disk, etc.; and a communication section 509 including a network interface card such as a LAN card, a modem, etc. The communication section 509 performs communication processing via a network such as the Internet. A drive 510 is also connected to the I / O interface 505 as needed. A removable medium 511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 510 as needed, so that a computer program read therefrom is installed into the storage section 508 as needed.
[0073] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 509, and / or installed from the removable medium 511. When the computer program is executed by the central processing unit (CPU) 501, the above-mentioned functions defined in the system of the present invention are executed.
[0074] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0075] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0076] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor. For example, it may be described as follows: a processor includes an acquisition module and a processing module. The names of these modules do not, in some cases, limit the modules themselves.
[0077] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently and not be assembled into the device. The above computer-readable medium carries one or more programs. When the above one or more programs are executed by a device, the device includes obtaining the data to be migrated, determining the target table to be imported into the data to be migrated, and creating a temporary table consistent with the structure of the target table; calling a preset segmentation model to divide the data to be migrated into multiple data files, and then importing the data files into the temporary table; wherein, after each data file is imported into the temporary table, index information of the data file consistent with the target table is established for the temporary table; based on the preset exchange model, the data files in the temporary table are exchanged to the target table.
[0078] The technical solution according to the embodiment of the present invention can solve the problem of data update of large data tables during high concurrent access, ensuring that data is updated securely and quickly without interrupting business.
[0079] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A data migration method, characterized in that: include: Acquire the data to be migrated, determine the target table into which the data to be migrated is to be imported, and create a temporary table consistent with the structure of the target table; Calling a preset segmentation model, dividing the data to be migrated into multiple data files, and then importing the data files into the temporary table; wherein, after each data file is imported into the temporary table, index information of the data file consistent with the target table is established for the temporary table; dividing the data to be migrated into multiple data files based on the preset segmentation model, including: determining the business type corresponding to the data to be migrated to obtain the partition field of the business type, and then dividing the data to be migrated into multiple data files according to the partition field; setting the direct parameter in the ctl file of sqlldr to true; Based on a preset exchange model, the data files in the temporary table are exchanged to the target table.
2. The method according to claim 1, characterized in that After dividing the data to be migrated into a plurality of data files according to the partition field, the method further includes: It is determined whether the data volume of the data file is greater than a preset quantity threshold, if so, the data file is divided into a plurality of sub-data files, otherwise, the data file is not processed.
3. The method according to claim 1, characterized in that Importing the data file into the temporary table includes: The data file is imported into the temporary table through the sqlldr multi-thread method; wherein the direct parameter and the parallel parameter in the ctl file of sqlldr are set to true.
4. The method according to claim 3, characterized in that: Importing the data file into the temporary table by using the sqlldr multi-thread method includes: Multiple threads import the same data file at the same time; If there is a thread without data file import, the thread state is set to wait.
5. The method according to claim 1, characterized in that Based on a preset exchange model, exchanging the data file in the temporary table to the target table includes: After a data file is imported, the temporary table and the target table exchange partitions; and the indexes are exchanged while the partitions are exchanged.
6. The method according to any one of claims 1 to 5, characterized in that: After exchanging the data file in the temporary table to the target table, the method includes: Delete the index information in the temporary table.
7. A data migration device, characterized in that: include: An acquisition module, used for acquiring data to be migrated, determining a target table into which the data to be migrated is to be imported, and creating a temporary table consistent with the structure of the target table; A processing module is used to call a preset segmentation model to divide the data to be migrated into multiple data files, and then import the data files into the temporary table; wherein, after each data file is imported into the temporary table, index information of the data file consistent with the target table is established for the temporary table; based on the preset segmentation model, the data to be migrated is divided into multiple data files, including: determining the business type corresponding to the data to be migrated to obtain the partition field of the business type, and then dividing the data to be migrated into multiple data files according to the partition field; setting the direct parameter in the ctl file of sqlldr to true; based on the preset exchange model, exchanging the data files in the temporary table to the target table.
8. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6.
9. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
