A method and device for data archiving
The cache switch controls query stop and streaming query, combined with message queue asynchronous storage, which solves the problem of database performance being affected during the data archiving process, improves efficiency, and reduces exception handling workload.
Patent Information
- Application Number
- CN202010603605.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-29
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2040-06-29
AI Technical Summary
During the data archiving process, existing technology cannot interrupt the data reading and storage processes, causing database performance to be affected, and the paging query method reduces efficiency and increases the workload of processing abnormal data.
Control the query stop through the cache switch, use streaming query and message queue to store data asynchronously, avoid synchronous saving, and retry abnormal storage until successful.
It effectively reduces database pressure, improves performance, avoids performance problems caused by paging queries, and reduces the workload of processing abnormal data.
Smart Images

Figure CN113779137B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for data archiving. Background Art
[0002] With the rapid development of Internet technology, various industries are becoming more and more information-based, and data is increasing day by day. No matter which industry, with the growth of data, there will be a problem. The pressure on the production library to save online production data is increasing, so it is necessary to archive historical data to reduce the pressure on the production library. When archiving data, it is necessary to read the data in the production library and store (or synchronize) it in the archive database immediately after the data is read.
[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] In the process of data archiving, since the data reading and storage process cannot be interrupted, the performance of the database will be seriously affected when data archiving conflicts with business operations. In addition, the existing paging query method will affect the performance of the database, and when data storage fails, it needs to be stored separately in the exception table, which will increase the workload of processing abnormal data. Summary of the invention
[0005] In view of this, an embodiment of the present invention provides a method and device for data archiving, which can control the query stop through a cache switch to solve the pressure on the database server caused by the archiving operation; and solve the performance problems caused by paging queries by streaming data and caching; and use message queues to asynchronously store data to avoid database performance problems caused by having to save data synchronously after reading it.
[0006] To achieve the above objective, according to one aspect of an embodiment of the present invention, a method for data archiving is provided.
[0007] A method for data archiving comprises: receiving an archiving control request, the archiving control request comprising a cache switch value for controlling whether an archiving operation is stopped; if the cache switch value indicates that the archiving operation continues, streaming archived data from a source database according to a data query instruction, encapsulating the acquired archived data into a message, and adding the message to a message queue; acquiring a message from the message queue, and asynchronously saving the parsed archived data to a target database.
[0008] Optionally, streaming archived data from a source database according to data query instructions and encapsulating the acquired archived data into messages includes: querying archived data from the source database according to data query instructions and saving them to a sending cache on the source database end; whenever the amount of archived data in the sending cache meets a set data packet size, acquiring archived data from the sending cache, parsing the archived data one by one and encapsulating them into messages.
[0009] Optionally, it also includes: if the cache switch value is to stop the archiving operation, then stop data archiving and directly release memory resources.
[0010] Optionally, it also includes: if it is necessary to extend the fields of the parsed archived data, obtaining a message from the message queue, encapsulating the parsed archived data with the extended fields, and then saving them into the target database, wherein the extended fields are obtained from the extended field database.
[0011] Optionally, the method further includes: in the process of asynchronously saving the parsed archived data to the target database, if an abnormal situation occurs, retrying until the saving is successful.
[0012] Optionally, a communication connection with the database is established through a database connection interface, and the database query mode is set to streaming query.
[0013] According to another aspect of an embodiment of the present invention, a data archiving device is provided.
[0014] A data archiving device comprises: a request receiving module for receiving an archiving control request, wherein the archiving control request comprises a cache switch value for controlling whether the archiving operation is stopped; a data acquiring module for streaming archived data from a source database according to a data query instruction if the cache switch value indicates that the archiving operation continues, and encapsulating the acquired archived data into a message and adding it to a message queue; and a data saving module for acquiring messages from the message queue and asynchronously saving the parsed archived data to a target database.
[0015] Optionally, the data acquisition module is also used to: query archived data from the source database according to data query instructions and save it to the sending cache of the source database end; whenever the amount of archived data in the sending cache meets the set data packet size, obtain the archived data from the sending cache, parse the archived data one by one and encapsulate it into a message.
[0016] Optionally, it further includes an archiving stop module, which is used to: if the cache switch value is the archiving operation stop, stop data archiving and directly release memory resources.
[0017] Optionally, it also includes a field extension module, which is used to: if it is necessary to extend the fields of the parsed archived data, obtain messages from the message queue, encapsulate the parsed archived data with extended fields, and then save them into the target database, wherein the extended fields are obtained from the extended field database.
[0018] Optionally, a retry module is also included, which is used to: in the process of asynchronously saving the parsed archived data to the target database, if an abnormal situation occurs, retry until the saving is successful.
[0019] Optionally, a communication connection with the database is established through a database connection interface, and the database query mode is set to streaming query.
[0020] According to yet another aspect of an embodiment of the present invention, an electronic device for archiving data is provided.
[0021] An electronic device for data archiving includes: 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 data archiving method provided by an embodiment of the present invention.
[0022] According to still another aspect of the embodiments of the present invention, a computer readable medium is provided.
[0023] A computer readable medium stores a computer program, which, when executed by a processor, implements the data archiving method provided by an embodiment of the present invention.
[0024] An embodiment of the above invention has the following advantages or beneficial effects: by receiving an archive control request, the archive control request includes a cache switch value for controlling whether the archive operation is stopped; if the cache switch value indicates that the archive operation continues, the archive data is streamed from the source database according to the data query instruction, and the acquired archive data is encapsulated as a message and added to the message queue; the message is obtained from the message queue, and the parsed archive data is asynchronously saved to the target database, so that the archive data is obtained by streaming, and the data is streamed according to the cache switch value, and then the archive data is saved through the message queue. The query stop can be controlled by the cache switch to solve the pressure on the database server caused by the archive operation; and the performance problem caused by paging query is solved by streaming query and caching the data; using the message queue to asynchronously store data can avoid the database performance problem caused by the need to save the data synchronously after reading.
[0025] 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
[0026] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0027] Figure 1 is a schematic diagram of main steps of a method for data archiving according to an embodiment of the present invention;
[0028] Figure 2 is a schematic diagram of a data archiving process according to an embodiment of the present invention;
[0029] Figure 3 This is a schematic diagram of a process for obtaining archived data based on JDBC according to an embodiment of the present invention;
[0030] Figure 4 is a schematic diagram of a data storage process according to an embodiment of the present invention;
[0031] Figure 5 is a schematic diagram of main modules of a data archiving device according to an embodiment of the present invention;
[0032] Figure 6 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0033] Figure 7 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
[0034] 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.
[0035] The existing technology has the following shortcomings when archiving data:
[0036] 1. The state of reading data from the production database is uncontrollable. Once data reading begins, it will continue until the reading is completed or abnormally stopped, but abnormal stops generally do not occur; and because the amount of production data is increasing during the data reading process, there is a possibility that data reading and production are carried out at the same time, which seriously affects the performance of the database;
[0037] 2. As the existing data archiving mostly uses paging query when reading data, 80% of the impact on database performance is caused by slow SQL. In the traditional paging query method, the later the page is, the slower it is to read, which greatly reduces the efficiency of data archiving;
[0038] 3. The existing archiving storage time is generally to store data immediately after reading it, that is, synchronous storage. If there is a storage exception, the exception table is stored separately, and the abnormal data is processed separately later. It can be seen that synchronous processing will increase the workload of processing abnormal data separately.
[0039] It can be seen that during the data archiving process, since the data reading and storage process cannot be interrupted, when data archiving conflicts with business operations, it will seriously affect the performance of the database; and when data storage fails, it needs to be stored separately in the exception table, which will increase the workload of processing abnormal data.
[0040] In order to solve the above technical problems existing in the prior art, the present invention provides a method and device for data archiving, which can control the stop of data reading by setting a cache switch to solve the pressure on the database server caused by archiving; based on JDBC (Java Database Connectivity, Java Database Connectivity is an application program interface used in Java language to standardize how client programs access databases, and provides methods such as querying and updating data in databases) and using database streaming query, all data is queried from the database server at one time and cached, and then streamed back to the client for processing, solving the performance problems caused by paging query; using message queue MQ to asynchronously store data, if there is abnormal data, it will automatically retry until the storage is successful, thereby avoiding the situation where abnormal data is processed separately.
[0041] Figure 1 FIG. 1 is a schematic diagram of the main steps of the method for data archiving according to an embodiment of the present invention. Figure 1 As shown, the data archiving method of the embodiment of the present invention mainly includes the following steps S101 to S103.
[0042] Step S101: receiving an archiving control request, the archiving control request including a cache switch value for controlling whether an archiving operation is stopped;
[0043] Step S102: if the cache switch value is to continue the archiving operation, then the archived data is streamed from the source database according to the data query instruction, and the acquired archived data is encapsulated as a message and added to the message queue;
[0044] Step S103: Obtain the message from the message queue, and asynchronously save the archived data obtained by parsing into the target database.
[0045] According to the technical solution of the present invention, archived data is acquired by streaming, and streaming processing of the data is performed according to the cache switch value, and then the archived data is saved through the message queue. The query stop can be controlled by the cache switch to solve the pressure on the database server caused by the archiving operation; and the performance problem caused by paging query is solved by streaming query and caching data; and the use of message queues to asynchronously store data can avoid database performance problems caused by having to save the data synchronously after reading it.
[0046] According to one embodiment of the present invention, when the archived data is obtained from the source database in a streaming manner according to the data query instruction and the obtained archived data is encapsulated as a message, the archived data can be specifically queried from the source database according to the data query instruction and saved in the sending buffer of the source database end; whenever the amount of archived data in the sending buffer meets the set data packet size, the archived data is obtained from the sending buffer, and the archived data is parsed one by one and encapsulated into a message. By saving the obtained archived data to the sending buffer of the source database end, it is convenient to judge whether the amount of data read meets the size of the set cache switch value. By encapsulating the archived data that meets the set data packet size into a message, streaming processing of data is achieved.
[0047] According to another embodiment of the present invention, a judgment is made based on the cache switch value. If the cache switch value indicates that the archiving operation is stopped, data archiving is stopped and memory resources are directly released. Specifically, if during the data archiving process, the data archiving query has an impact on the interaction between the production process related to the source database and the source database, in order to meet the needs of online data production, the cache switch value can be set to 0 to stop the current archiving operation, and at this time, memory resources, such as database connection resources, operation database resources, data return resources, etc., will also be released. In this way, online data production can be given priority, and data archiving operations can be performed when idle.
[0048] According to an embodiment of the present invention, the cache switch value is set through an http (http is a simple request-response protocol, which usually runs on TCP) request. In this way, the cache switch value can be adjusted at any time by sending an http request, and the execution of the data archiving operation can be adjusted at any time, so as to ensure the optimal performance of the database and reduce the pressure on the database in time.
[0049] According to another embodiment of the present invention, when archiving data, if it is necessary to extend the fields of the archived data obtained by parsing, a message is obtained from a message queue, and the archived data obtained by parsing is encapsulated with an extended field, and then saved to a target database, wherein the extended field is obtained from an extended field database. In this way, data archiving can be flexibly performed according to the needs of business applications.
[0050] According to another embodiment of the present invention, during the process of asynchronously saving the parsed archived data to the target database, if an abnormal situation occurs, retries are performed until the saving is successful, thus avoiding the situation where the abnormal data needs to be saved separately and processed separately.
[0051] According to an embodiment of the present invention, a communication connection with a database is established through a database connection interface, and the database query mode is set to a streaming query. Wherein, the database connection interface is, for example, JDBC, and a communication connection is established with a source database, a target database, and / or an extended field database through JDBC, so that the database can be easily set.
[0052] Figure 2 FIG. 1 is a schematic diagram of a data archiving process according to an embodiment of the present invention. Figure 2 As shown, in one embodiment of the present invention, before performing the data archiving operation, a data archiving server (hereinafter referred to as the "server") for performing the data archiving operation may be first configured and started, wherein the basic configuration includes, for example:
[0053] 1) Source database and target database data source connection property configuration: such as database user name, password, URL (uniform resource locator), port, etc., used to establish a communication connection between the server and the database through JDBC;
[0054] 2) Cache switch configuration: used to control the communication connection status between the server and the source database. The default setting is to allow the connection to be maintained. Once the archiving request starts, the cache switch controls whether to continue reading data from the source database. The switch can control the cache value through http requests;
[0055] 3) Application, production, and consumption configuration of message queue MQ: The server builds producers and consumers through MQ. The production topic and the consumption topic are one. The producer sends data to the message queue corresponding to the production topic, and the consumer receives and consumes data from the topic.
[0056] 4) Preparation of target database table: The target database table is the database table after archiving. The fields of the target database table can be consistent with the fields of the source database table, or they can be extended by combining the extended fields in the extended field database, depending on the actual needs of archiving.
[0057] After the server configuration is completed, you can start data archiving. The data archiving operation mainly includes the following steps:
[0058] 1. Receive a data archiving request. The network communication request for data archiving is an http request, through which a data query instruction for obtaining archived data is passed in, wherein the data query instruction is, for example, an SQL statement;
[0059] 2. Establish a communication connection with the source database through JDBC and query the archived data according to SQL statements. Figure 3 FIG. 1 is a flow chart of obtaining archived data based on JDBC according to an embodiment of the present invention. Figure 3 As shown in the figure, the process of obtaining archived data based on JDBC is as follows:
[0060] 1) Loading the driver: Loading the driver according to the connection properties of the source database included in the previous basic configuration. The database driver is related to the selected database, such as MYSQL database, ORACLE database, etc. In the embodiment of the present invention, MYSQL database is taken as an example, and its corresponding driver is com.mysql.jdbc.Drive. The driver is a jar package that connects the server and the database server for data interaction;
[0061] 2) Create a communication connection with the source database: connect to the database according to the database connection parameters (for example, database user name, password, URL, port, etc.) included in the previous basic configuration;
[0062] 3) Operate the database to configure streaming query parameters: set the size of the data packet to be processed each time to fetchSize = -2147483648, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY three required parameters, and enable the database query as streaming query;
[0063] 4) Execute SQL query: query the archived data according to the parameter SQL statement in the http request;
[0064] 5) Return data according to streaming configuration parameters: query archived data from the source database and put it in the send buffer of the source database, then stream the data of the set data packet size fetchSize to the server for reception;
[0065] 6) Is it the last piece of data: If all data on the server has been received, jump to the following step 9) to release resources; otherwise, continue to step 7);
[0066] 7) Whether to release resources midway: If an archiving control request is received during the data archiving operation, which includes a cache switch value for controlling whether the archiving operation is stopped, then according to the cache switch value, if the cache switch value indicates that the current data archiving is stopped, directly jump to step 9) to release resources, thereby reducing the database pressure in time; otherwise, continue to step 8);
[0067] 8) Parse the data one by one and send data messages: parse the current data according to the current position of the cursor, encapsulate the data into messages and send them, then return to step 6);
[0068] 9) Release resources: Release all resources created by JDBC, such as database connection resources, database operation resources, data return resources, etc.
[0069] 3. Send and receive archived data through message queues. After parsing the data on the server side, the producer configured by MQ encapsulates the archived data message and sends it to the specified topic; then, the consumer configured by MQ receives the archived data message of the corresponding topic for subsequent message parsing, field extension and other business processing;
[0070] 4. Establish a communication connection with the target database and the extended field database through JDBC and store the archived data. After receiving the data message, parse the archived data. If the archived data needs to be expanded, it is necessary to establish a communication connection with the extended field database. Here, the process of establishing a communication connection with the target database and the extended field database is similar to the aforementioned process of establishing a communication connection with the source database. The difference is that when establishing a communication connection with the extended field database, it is not necessary to configure the streaming query parameters, and only ordinary queries are required. Finally, the archived data obtained by parsing are encapsulated with the extended fields to obtain the encapsulated archived data, and then the SQL statement for inserting data is executed in the target database to save the encapsulated archived data to the target database. In this step, if an abnormal situation occurs, the message is retried until the storage is successfully completed.
[0071] Figure 4 FIG. 1 is a schematic diagram of a data storage process according to an embodiment of the present invention. Figure 4 As shown, when storing archived data, the received data message is first parsed to obtain the archived data, and then the extended field is obtained to extend the archived data, and then the data is stored until the storage is successful.
[0072] Figure 5 Schematic diagram of the main modules of the data archiving device according to an embodiment of the present invention. Figure 5 As shown, the data archiving device 500 of the embodiment of the present invention mainly includes a request receiving module 501, a data acquiring module 502 and a data saving module 503.
[0073] A request receiving module 501 is used to receive an archiving control request, wherein the archiving control request includes a cache switch value for controlling whether the archiving operation is stopped;
[0074] The data acquisition module 502 is used to obtain the archived data from the source database in a streaming manner according to the data query instruction if the cache switch value is to continue the archiving operation, and to encapsulate the obtained archived data into a message and add it to the message queue;
[0075] The data saving module 503 is used to obtain messages from the message queue and asynchronously save the archived data obtained by parsing into a target database.
[0076] According to one embodiment of the present invention, the data acquisition module 502 may also be used to:
[0077] Query archived data from the source database according to data query instructions and save them to the sending buffer on the source database side;
[0078] Whenever the amount of archived data in the sending buffer meets the set data packet size, the archived data is obtained from the sending buffer, and the archived data is parsed one by one and encapsulated into a message.
[0079] According to another embodiment of the present invention, the data archiving device 500 may further include an archiving stop module (not shown in the figure) for:
[0080] If the cache switch value is to stop the archiving operation, data archiving is stopped and memory resources are directly released.
[0081] According to another embodiment of the present invention, the data archiving device 500 may further include a field expansion module (not shown in the figure) for:
[0082] If it is necessary to extend the fields of the archived data obtained through parsing, a message is obtained from the message queue, and the archived data obtained through parsing is encapsulated with an extended field and then saved in the target database, wherein the extended field is obtained from an extended field database.
[0083] According to another embodiment of the present invention, the data archiving device 500 may further include a retry module (not shown in the figure) for:
[0084] In the process of asynchronously saving the parsed archived data to the target database, if an exception occurs, retries are made until the save is successful.
[0085] According to an embodiment of the present invention, a communication connection with a database is established through a database connection interface, and the database query mode is set to a streaming query.
[0086] According to the technical solution of the embodiment of the present invention, by receiving an archive control request, the archive control request includes a cache switch value for controlling whether the archive operation is stopped; if the cache switch value indicates that the archive operation continues, the archive data is streamed from the source database according to the data query instruction, and the acquired archive data is encapsulated as a message and added to the message queue; the message is obtained from the message queue, and the parsed archive data is asynchronously saved to the target database, thereby realizing the archive data being obtained by streaming, and streaming processing of the data according to the cache switch value, and then saving the archive data through the message queue. The query stop can be controlled by the cache switch to solve the pressure on the database server caused by the archive operation; and the performance problem caused by paging query is solved by streaming query and caching the data; and the message queue is used to asynchronously store data to avoid the database performance problem caused by the need to synchronously save the data after reading it.
[0087] Figure 6 An exemplary system architecture 600 is shown to which the method or apparatus for data archiving according to an embodiment of the present invention may be applied.
[0088] like Figure 6 As shown, system architecture 600 may include terminal devices 601, 602, 603, network 604 and server 605. Network 604 is used to provide a medium for communication links between terminal devices 601, 602, 603 and server 605. Network 604 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0089] Users can use terminal devices 601, 602, and 603 to interact with server 605 through network 604 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 601, 602, and 603, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).
[0090] The terminal devices 601 , 602 , and 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc.
[0091] The server 605 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 601, 602, and 603. 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.
[0092] It should be noted that the data archiving method provided in the embodiment of the present invention is generally executed by the server 605 , and accordingly, the data archiving device is generally set in the server 605 .
[0093] It should be understood that Figure 6 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.
[0094] Reference below Figure 7 , which shows a schematic diagram of the structure of a computer system 700 of a terminal device or a server suitable for implementing an embodiment of the present invention. Figure 7 The terminal device or server 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.
[0095] like Figure 7 As shown, the computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage part 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the system 700 are also stored. The CPU 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0096] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, etc.; an output section 707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, a modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed, so that a computer program read therefrom is installed into the storage section 708 as needed.
[0097] 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 709, and / or installed from the removable medium 711. When the computer program is executed by the central processing unit (CPU) 701, the above-mentioned functions defined in the system of the present invention are executed.
[0098] 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.
[0099] 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.
[0100] The units or modules involved in the embodiments of the present invention may be implemented by software or hardware. The units or modules described may also be arranged in a processor. For example, they may be described as follows: a processor includes a request receiving module, a data acquisition module, and a data storage module. The names of these units or modules do not, in some cases, constitute limitations on the units or modules themselves. For example, the request receiving module may also be described as a "module for receiving an archiving control request."
[0101] 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 may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: receiving an archive control request, the archive control request includes a cache switch value for controlling whether the archive operation is stopped; if the cache switch value indicates that the archive operation continues, then streaming archive data from the source database according to the data query instruction, encapsulating the acquired archive data into a message, and adding it to the message queue; acquiring messages from the message queue, and asynchronously saving the parsed archive data to the target database.
[0102] According to the technical solution of the embodiment of the present invention, by receiving an archive control request, the archive control request includes a cache switch value for controlling whether the archive operation is stopped; if the cache switch value indicates that the archive operation continues, the archive data is streamed from the source database according to the data query instruction, and the acquired archive data is encapsulated as a message and added to the message queue; the message is obtained from the message queue, and the parsed archive data is asynchronously saved to the target database, thereby realizing the archive data being obtained by streaming, and streaming processing of the data according to the cache switch value, and then saving the archive data through the message queue. The query stop can be controlled by the cache switch to solve the pressure on the database server caused by the archive operation; and the performance problem caused by paging query is solved by streaming query and caching the data; and the message queue is used to asynchronously store data to avoid the database performance problem caused by the need to synchronously save the data after reading it.
[0103] 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 method for data archiving, It is characterized in that include: receiving an archiving control request, wherein the archiving control request includes a cache switch value for controlling whether an archiving operation is stopped; If the cache switch value is to continue the archiving operation, the archived data is streamed from the source database according to the data query instruction, and the acquired archived data is encapsulated as a message and added to the message queue; Obtaining messages from the message queue, and asynchronously saving the parsed archived data into a target database; The step of streaming archived data from a source database according to a data query instruction and encapsulating the acquired archived data into a message comprises: querying the archived data from the source database according to the data query instruction and saving the archived data into a sending buffer at the source database end; whenever the amount of archived data in the sending buffer meets a set data packet size, acquiring the archived data from the sending buffer, parsing the archived data one by one and encapsulating the archived data into a message; If the cache switch value is to stop the archiving operation, data archiving is stopped and memory resources are directly released; In the process of asynchronously saving the parsed archived data to the target database, if an exception occurs, retries are made until the save is successful.
2. The method according to claim 1, It is characterized in that Also includes: If it is necessary to extend the fields of the archived data obtained through parsing, a message is obtained from the message queue, and the archived data obtained through parsing is encapsulated with an extended field and then saved in the target database, wherein the extended field is obtained from an extended field database.
3. The method according to claim 1, It is characterized in that Establish a communication connection with the database through the database connection interface, and set the database query mode to streaming query.
4. A device for archiving data, It is characterized in that include: A request receiving module, used for receiving an archiving control request, wherein the archiving control request includes a cache switch value for controlling whether the archiving operation is stopped; A data acquisition module, for acquiring the archived data from the source database in a streaming manner according to the data query instruction if the cache switch value is to continue the archiving operation, and encapsulating the acquired archived data into a message and adding it to the message queue; A data storage module is used to obtain messages from the message queue and asynchronously save the parsed archived data into a target database; The data acquisition module is also used to: query archived data from the source database according to the data query instruction and save it to the sending buffer of the source database end; whenever the amount of archived data in the sending buffer meets the set data packet size, obtain the archived data from the sending buffer, parse the archived data one by one and encapsulate them into messages; An archiving stop module is used to stop data archiving and directly release memory resources if the cache switch value is archiving operation stop; The retry module is used to retry until the save is successful if an abnormal situation occurs during the process of asynchronously saving the parsed archived data to the target database.
5. An electronic device for archiving data, It is 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 3.
6. A computer readable medium having a computer program stored thereon, It is characterized in that When the program is executed by a processor, the method according to any one of claims 1 to 3 is implemented.
Citation Information
Patent Citations
Astronomical metadata archiving method and system based on streaming data processing architecture
CN107317838A
Export method, export device, server, terminal, and readable storage medium
CN109542874A
