Data import method, device, equipment and computer readable storage medium

文档序号:7491 发布日期:2021-09-17 浏览:42次 中文

1. A data import method, comprising:

when a file import request is received, reading a file to be imported into a chain type blocking queue;

requesting to obtain a container set from a container recoverer, and loading data contained in the file to be imported into each target container of the container set from the chain type blocking queue in a striping manner;

taking each target container as an import task to carry out data import operation;

judging whether each import task is executed completely;

and if so, carrying out recovery operation on each target container by using the container recoverer.

2. The data import method of claim 1, wherein reading the file to be imported into the chain blocking queue comprises:

acquiring file size information of the file to be imported;

determining a file reading mode according to the file size information;

and reading the file to be imported into the chain type blocking queue according to the file reading mode.

3. The data import method according to claim 2, wherein when the file read mode is determined to be a split read mode, before reading the file to be imported into the chain blocking queue according to the file read mode, the method further comprises:

carrying out segmentation operation on the file to be imported to obtain each subfile;

storing each subfile into a preset first temporary folder;

reading the file to be imported into the chain type blocking queue according to the file reading mode, wherein the reading comprises the following steps:

reading the file to be imported into the chain type blocking queue in a mode of sequentially reading each subfile;

and transferring the read subfiles to a preset second temporary folder.

4. The method according to claim 3, wherein requesting a container set from a container retriever, and striping data included in the file to be imported from the chained blocking queue into each target container of the container set comprises:

judging whether an available container exists in the container recoverer or not;

if so, performing container request operation from the container recoverer to obtain a corresponding target container;

loading data contained in a respective subfile from the chained blocking queue into the target container;

if not, performing blocking waiting, and repeatedly executing the step of judging whether the available container exists in the container recoverer according to a preset time interval.

5. The data import method according to claim 4, further comprising:

and outputting overtime abnormal prompt information when the blocking waiting time exceeds the preset time.

6. The data import method according to any one of claims 1 to 5, wherein performing data import operation on each target container as an import task includes:

calling corresponding threads for each target container from a thread pool;

and performing data parallel import operation by using each thread by taking each target container as an import task.

7. A data importing apparatus, comprising:

the file reading module is used for reading a file to be imported into the chained blocking queue when a file import request is received;

the data loading module is used for requesting to obtain a container set from the container recoverer and loading the data contained in the file to be imported into each target container of the container set from the chain type blocking queue in a strip mode;

the data import module is used for taking each target container as an import task to carry out data import operation;

the judging module is used for judging whether each import task is executed completely;

and the container recovery module is used for performing recovery operation on each target container by using the container recoverer when each import task is determined to be completed.

8. The data import apparatus according to claim 7, wherein the file reading module comprises:

the file size obtaining submodule is used for obtaining the file size information of the file to be imported;

the reading mode determining submodule is used for determining a file reading mode according to the file size information;

and the file reading submodule is used for reading the file to be imported into the chain type blocking queue according to the file reading mode.

9. A data import apparatus, comprising:

a memory for storing a computer program;

a processor for implementing the steps of the data import method according to any of claims 1 to 6 when executing the computer program.

10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the data import method according to any one of claims 1 to 6.

Background

In the process of product development and iteration, the requirements of database migration, unloading and the like are usually met. In most cases, the required data volume is quite large, for example, when a data structure with ten fields and a data volume of about ten million are used, the dump file capacity can reach more than one G, if data import and storage are performed through a traditional file import mode and the like, when data import is required, a container is generated, and after the data import is completed, the container is discarded.

When a large amount of data is imported, the time consumption of only the data import work is often in units of hours. In addition, the container generation and discarding process causes excessive waste containers in the data import process, and the container generation is continuously performed, so that the time consumption of non-import work is long, and the single import delays other work.

In summary, how to effectively solve the problems that the single import delays other work due to the long time consumption caused by the non-import work is a problem that needs to be solved urgently by those skilled in the art at present.

Disclosure of Invention

The invention aims to provide a data import method, which greatly shortens the time consumption generated by non-import work and avoids the influence on other works; another object of the present invention is to provide a data importing apparatus, device and computer readable storage medium.

In order to solve the technical problems, the invention provides the following technical scheme:

a data import method, comprising:

when a file import request is received, reading a file to be imported into a chain type blocking queue;

requesting to obtain a container set from a container recoverer, and loading data contained in the file to be imported into each target container of the container set from the chain type blocking queue in a striping manner;

taking each target container as an import task to carry out data import operation;

judging whether each import task is executed completely;

and if so, carrying out recovery operation on each target container by using the container recoverer.

In a specific embodiment of the present invention, reading a file to be imported into a chained blocking queue includes:

acquiring file size information of the file to be imported;

determining a file reading mode according to the file size information;

and reading the file to be imported into the chain type blocking queue according to the file reading mode.

In a specific embodiment of the present invention, when determining that the file reading mode is a split reading mode, before reading the file to be imported into the chain blocking queue according to the file reading mode, the method further includes:

carrying out segmentation operation on the file to be imported to obtain each subfile;

storing each subfile into a preset first temporary folder;

reading the file to be imported into the chain type blocking queue according to the file reading mode, wherein the reading comprises the following steps:

reading the file to be imported into the chain type blocking queue in a mode of sequentially reading each subfile;

and transferring the read subfiles to a preset second temporary folder.

In a specific embodiment of the present invention, requesting a container set from a container retriever, and loading data included in the file to be imported from the chained blocking queue into each target container of the container set in a striped manner includes:

judging whether an available container exists in the container recoverer or not;

if so, performing container request operation from the container recoverer to obtain a corresponding target container;

loading data contained in a respective subfile from the chained blocking queue into the target container;

if not, performing blocking waiting, and repeatedly executing the step of judging whether the available container exists in the container recoverer according to a preset time interval.

In one embodiment of the present invention, the method further comprises:

and outputting overtime abnormal prompt information when the blocking waiting time exceeds the preset time.

In a specific embodiment of the present invention, performing data import operation with each target container as an import task includes:

calling corresponding threads for each target container from a thread pool;

and performing data parallel import operation by using each thread by taking each target container as an import task.

A data import apparatus, comprising:

the file reading module is used for reading a file to be imported into the chained blocking queue when a file import request is received;

the data loading module is used for requesting to obtain a container set from the container recoverer and loading the data contained in the file to be imported into each target container of the container set from the chain type blocking queue in a strip mode;

the data import module is used for taking each target container as an import task to carry out data import operation;

the judging module is used for judging whether each import task is executed completely;

and the container recovery module is used for performing recovery operation on each target container by using the container recoverer when each import task is determined to be completed.

In a specific embodiment of the present invention, the file reading module includes:

the file size obtaining submodule is used for obtaining the file size information of the file to be imported;

the reading mode determining submodule is used for determining a file reading mode according to the file size information;

and the file reading submodule is used for reading the file to be imported into the chain type blocking queue according to the file reading mode.

A data import apparatus, comprising:

a memory for storing a computer program;

a processor for implementing the steps of the data importing method as described above when executing the computer program.

A computer-readable storage medium, having stored thereon a computer program which, when being executed by a processor, carries out the steps of the data import method as set forth above.

According to the data import method provided by the invention, when a file import request is received, a file to be imported is read into a chain type blocking queue; requesting to obtain a container set from the container recoverer, and loading data contained in a file to be imported into each target container of the container set from a chain type blocking queue in a strip mode; taking each target container as an import task to carry out data import operation; judging whether each import task is executed completely; if yes, the container recoverer is used for performing recovery operation on each target container.

By arranging the container recoverer, when the file to be imported needs to be imported, a container request is made from the container recoverer, and the data contained in the file to be imported and temporarily stored in the chain type blocking queue is loaded into each target container in a striped mode. And respectively taking each target container as an import task to perform data import operation, and performing container recovery operation by using the container recoverer after the import task is completed. Continuous container generation and container discarding operations are not required, the data import efficiency is improved, the time consumption caused by non-import work is greatly shortened, and the influence on other works is avoided.

Correspondingly, the invention also provides a data import device, equipment and a computer readable storage medium corresponding to the data import method, which have the technical effects and are not described herein again.

Drawings

In order to more clearly illustrate the embodiments of the present invention or the technical solutions in 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 invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.

FIG. 1 is a flowchart illustrating an implementation of a data importing method according to an embodiment of the present invention;

FIG. 2 is a flowchart illustrating another implementation of a data importing method according to an embodiment of the present invention;

fig. 3 is a block diagram illustrating a data importing apparatus according to an embodiment of the present invention;

fig. 4 is a block diagram of a data importing apparatus according to an embodiment of the present invention;

fig. 5 is a schematic structural diagram of a data importing apparatus provided in this embodiment.

Detailed Description

In order that those skilled in the art will better understand the disclosure, the invention will be described in further detail with reference to the accompanying drawings and specific embodiments. It is to be understood that the described embodiments are merely exemplary of the invention, and not restrictive of the full scope of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.

Referring to fig. 1, fig. 1 is a flowchart of an implementation of a data importing method according to an embodiment of the present invention, where the method may include the following steps:

s101: and when a file import request is received, reading the file to be imported into the chain blocking queue.

A chain blocking queue ArrayBlockingQueue is preset and serves as a channel for data import. And when a file import request is received, reading the file to be imported into the chain blocking queue.

The file import request may be a request to import data contained in a file from one database to another database.

S102: and requesting to obtain a container set from the container recoverer, and loading the data contained in the file to be imported into each target container of the container set from the chain blocking queue in a strip mode.

A container recoverer is preset and used for distributing and recovering the container. When the program is started, the container recoverer can be initialized to obtain a plurality of containers, and the containers are provided for the import task. After the file to be imported is read into the chain blocking queue, a container set is requested from the container recoverer, and data contained in the file to be imported is loaded into each target container of the container set in a strip mode from the chain blocking queue. If the file to be imported is the one-time import or the block import according to the file size of the file to be imported, when the file to be imported is determined to be the block import, container requests are sequentially carried out, and corresponding data are loaded into corresponding target containers.

S103: and taking each target container as an import task to perform data import operation.

And after the data contained in the file to be imported is loaded into each target container of the container set in a striping manner from the chain blocking queue, carrying out data import operation by taking each target container as an import task. Thereby realizing the effective utilization of each container in the container recoverer.

S104: and judging whether the execution of each import task is finished, if so, executing the step S105, and if not, not processing.

After each target container is used as an import task to perform data import operation, whether each import task is executed completely is judged, if yes, the file to be imported is all imported completely, step S105 is executed, and if not, the file to be imported still has data which is not imported, and no processing is performed.

S105: and carrying out recovery operation on each target container by using the container recoverer.

When the import tasks are determined to be executed completely, the files to be imported are indicated to be imported completely, namely the target containers are used completely at this time, and the container recoverer is used for recovering the target containers. The container recoverer is arranged to manage the containers used in the generation and execution of the import task, so that excessive waste containers are avoided in the data import process, the containers for loading data can be reused when the data are imported through the container management mechanism, and the time consumption caused by non-import work is reduced. And after the import task is executed for one time, the recovery container realizes container circulation. On the premise of ensuring controllable and recoverable import process of large data quantity to a certain extent, the rapid and efficient import of data is realized.

By arranging the container recoverer, when the file to be imported needs to be imported, a container request is made from the container recoverer, and the data contained in the file to be imported and temporarily stored in the chain type blocking queue is loaded into each target container in a striped mode. And respectively taking each target container as an import task to perform data import operation, and performing container recovery operation by using the container recoverer after the import task is completed. Continuous container generation and container discarding operations are not required, the data import efficiency is improved, the time consumption caused by non-import work is greatly shortened, and the influence on other works is avoided.

It should be noted that, based on the above embodiments, the embodiments of the present invention also provide corresponding improvements. In the following embodiments, steps that are the same as or correspond to those in the above embodiments may be referred to one another, and corresponding advantageous effects may also be referred to one another, which is not described in detail in the following modified embodiments.

Referring to fig. 2, fig. 2 is a flowchart of another implementation of a data importing method according to an embodiment of the present invention, where the method may include the following steps:

s201: and when a file import request is received, acquiring the file size information of the file to be imported.

And the sizes of the files to be imported corresponding to different import tasks are different. And when a file import request is received, acquiring the file size information of the file to be imported.

S202: and determining a file reading mode according to the file size information.

Presetting different file sizes corresponding to different file reading modes, for example, presetting a file size threshold, and when the size of a file to be imported is larger than the file size threshold, corresponding to a segmentation reading mode; and when the file size of the file to be imported is smaller than or equal to the file size threshold, corresponding to a one-time reading mode. And after the file size information of the file to be imported is acquired, determining a file reading mode according to the file size information.

S203: and carrying out segmentation operation on the file to be imported to obtain each subfile.

And when the file size of the file to be imported is larger than the file size threshold value, and the file to be imported is subjected to segmentation operation to obtain each subfile when the file to be imported corresponds to the segmentation reading mode.

S204: and saving each subfile to a preset first temporary folder.

Presetting a first temporary folder wait, and after each subfile is obtained, storing each subfile into a preset first temporary folder.

S205: and reading the file to be imported into the chain type blocking queue in a mode of sequentially reading each subfile.

After each subfile is stored in a preset first temporary folder, the file to be imported is read into a chain type blocking queue in a mode of sequentially reading each subfile, and therefore the block reading of the file to be imported is achieved.

S206: and transferring the read subfiles to a preset second temporary folder.

And presetting a second temporary folder loaded, and after reading the file to be imported into the chain type blocking queue in a mode of sequentially reading each subfile, transferring the read subfile to the preset second temporary folder. By storing the unread subfiles and the read subfiles in a distinguishing way, when a system is crashed, restarted and abnormal, the restart program can realize the continuous import of the nodes without importing the subfiles from the beginning again.

It should be noted that the first and second temporary folders in the first temporary folder and the second temporary folder are not sequentially distinguished, and are only used for storing the read subfiles and the unread subfiles differently.

S207: and judging whether the available container exists in the container recoverer, if not, executing step S208, and if so, executing step S209.

After the file to be imported is read into the chain blocking queue by sequentially reading the subfiles, whether an available container exists in the container retriever is judged, if not, step S208 is executed, and if so, step S209 is executed.

S208: a congestion wait is performed and step S207 is repeatedly performed at preset time intervals.

A time interval for requesting a container from the container retriever when it is determined that there is no available container in the container retriever is set in advance, a jam wait is performed, and step S207 is repeatedly performed at preset time intervals.

It should be noted that the preset time interval may be set and adjusted according to actual situations, which is not limited in the embodiment of the present invention.

In one embodiment of the present invention, the method may further comprise the steps of:

and outputting overtime abnormal prompt information when the blocking waiting time exceeds the preset time.

When the blocking waiting time is determined to exceed the preset time, the system is possibly abnormal, and overtime abnormal prompt information is output, so that operation and maintenance personnel can conveniently and timely perform abnormal processing.

S209: and carrying out container request operation from the container recoverer to obtain a corresponding target container.

And when determining that the available container exists in the container recoverer, performing container request operation from the container recoverer to obtain a corresponding target container.

S210: the data contained in the corresponding subfile is loaded from the chained blocking queue into the target container.

After the target container is obtained, the data contained in the corresponding subfile is loaded from the chained blocking queue into the target container. For example, according to the splicing sequence of each subfile in the file to be imported, each target container is requested in sequence, and each subfile is loaded into the corresponding target container.

S211: and calling corresponding threads for the target containers from the thread pool respectively.

And after the data contained in the corresponding subfile is loaded into the target container from the chain blocking queue, the corresponding thread is respectively called for each target container from the thread pool. In addition, a connection pool required by connection with the database can be arranged, and the database connection in the connection pool is matched with the threads in the thread pool to complete the importing work of the data in each target container.

S212: and respectively using each target container as an import task by using each thread to carry out data parallel import operation.

And after the corresponding threads are respectively called for the target containers, performing data parallel import operation by using the threads to respectively take each target container as an import task. The data is imported in parallel by utilizing each thread in the thread pool, so that the data import efficiency is greatly improved, and the time consumption for data import is reduced.

S213: and judging whether the execution of each import task is finished, if so, executing the step S214, and if not, not processing.

S214: and carrying out recovery operation on each target container by using the container recoverer.

Corresponding to the above method embodiment, the present invention further provides a data importing apparatus, and the data importing apparatus and the data importing method described above may be referred to correspondingly.

Referring to fig. 3, fig. 3 is a block diagram of a data importing apparatus according to an embodiment of the present invention, where the apparatus may include:

the file reading module 31 is configured to, when a file import request is received, read a file to be imported into the chain blocking queue;

the data loading module 32 is configured to request to obtain a container set from the container retriever, and load data included in the file to be imported into each target container of the container set from the chained blocking queue in a striped manner;

the data import module 33 is used for taking each target container as an import task to perform data import operation;

a judging module 34, configured to judge whether each import task is executed completely;

and the container recovery module 35 is configured to perform a recovery operation on each target container by using the container recoverer when it is determined that each import task is completely executed.

By arranging the container recoverer, when the file to be imported needs to be imported, a container request is made from the container recoverer, and the data contained in the file to be imported and temporarily stored in the chain type blocking queue is loaded into each target container in a striped mode. And respectively taking each target container as an import task to perform data import operation, and performing container recovery operation by using the container recoverer after the import task is completed. Continuous container generation and container discarding operations are not required, the data import efficiency is improved, the time consumption caused by non-import work is greatly shortened, and the influence on other works is avoided.

In an embodiment of the present invention, the file reading module 31 includes:

the file size acquisition submodule is used for acquiring file size information of a file to be imported;

the reading mode determining submodule is used for determining a file reading mode according to the file size information;

and the file reading submodule is used for reading the file to be imported into the chain type blocking queue according to the file reading mode.

In one embodiment of the present invention, the apparatus may further include:

the file splitting module is used for splitting the file to be imported into sub-files before reading the file to be imported into the chained blocking queue according to the file reading mode when the file reading mode is determined to be the splitting reading mode;

the file storage module is used for storing each subfile into a preset first temporary folder;

the file reading sub-module reads the file to be imported into the chain type blocking queue in a mode of sequentially reading each subfile; and transferring the read-completed subfile to a module in a preset second temporary folder.

In one embodiment of the present invention, the data loading module 32 includes:

the judgment submodule is used for judging whether an available container exists in the container recoverer or not;

the container request submodule is used for carrying out container request operation from the container recoverer to obtain a corresponding target container when determining that the available container exists in the container recoverer;

the data loading submodule is used for loading the data contained in the corresponding subfile into the target container from the chain blocking queue;

and the blocking waiting submodule is used for waiting for blocking when the usable container does not exist in the container recoverer, and repeatedly executing the step of judging whether the usable container exists in the container recoverer according to a preset time interval.

In one embodiment of the present invention, the apparatus may further include:

and the information output module is used for outputting the overtime abnormal prompt information when the blocking waiting time exceeds the preset time.

In an embodiment of the present invention, the data importing module 33 includes:

the thread calling submodule is used for calling corresponding threads for the target containers from the thread pool respectively;

and the data import submodule is used for respectively using each target container as an import task to carry out data parallel import operation by using each thread.

Corresponding to the above method embodiment, referring to fig. 4, fig. 4 is a schematic diagram of a data importing apparatus provided by the present invention, where the apparatus may include:

a memory 332 for storing a computer program;

the processor 322 is configured to implement the steps of the data importing method of the above method embodiment when executing the computer program.

Specifically, referring to fig. 5, fig. 5 is a schematic diagram of a specific structure of a data importing device provided in this embodiment, the data importing device may generate a large difference due to different configurations or performances, and may include a processor (CPU) 322 (e.g., one or more processors) and a memory 332, where the memory 332 stores one or more computer applications 342 or data 344. Memory 332 may be, among other things, transient or persistent storage. The program stored in memory 332 may include one or more modules (not shown), each of which may include a sequence of instructions operating on a data processing device. Further, the processor 322 may be configured to communicate with the memory 332 to execute a series of instruction operations in the memory 332 on the data import apparatus 301.

The data import apparatus 301 may also include one or more power supplies 326, one or more wired or wireless network interfaces 350, one or more input output interfaces 358, and/or one or more operating systems 341.

The steps in the data import method described above may be implemented by the structure of the data import apparatus.

Corresponding to the above method embodiment, the present invention further provides a computer-readable storage medium having a computer program stored thereon, the computer program, when executed by a processor, implementing the steps of:

when a file import request is received, reading a file to be imported into a chain type blocking queue; requesting to obtain a container set from the container recoverer, and loading data contained in a file to be imported into each target container of the container set from a chain type blocking queue in a strip mode; taking each target container as an import task to carry out data import operation; judging whether each import task is executed completely; if yes, the container recoverer is used for performing recovery operation on each target container.

The computer-readable storage medium may include: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.

For the introduction of the computer-readable storage medium provided by the present invention, please refer to the above method embodiments, which are not described herein again.

The embodiments are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same or similar parts among the embodiments are referred to each other. The device, the apparatus and the computer-readable storage medium disclosed in the embodiments correspond to the method disclosed in the embodiments, so that the description is simple, and the relevant points can be referred to the description of the method.

The principle and the implementation of the present invention are explained in the present application by using specific examples, and the above description of the embodiments is only used to help understanding the technical solution and the core idea of the present invention. It should be noted that, for those skilled in the art, it is possible to make various improvements and modifications to the present invention without departing from the principle of the present invention, and those improvements and modifications also fall within the scope of the claims of the present invention.

完整详细技术资料下载
上一篇:石墨接头机器人自动装卡簧、装栓机
下一篇:私有目录文件的导出方法、装置、电子设备和存储介质

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!