Method and device for storing logs
By determining the storage unit based on the sequence number information of the log block, the problem of uneven log distribution and low single-thread efficiency in multi-thread log transmission is solved, and efficient and orderly log storage is achieved.
Patent Information
- Application Number
- CN202111078493.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-15
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2041-09-15
AI Technical Summary
The existing multi-threaded log transmission method results in uneven log distribution and affects storage efficiency, while the single-threaded method results in low log storage efficiency.
By obtaining the log block to be stored in the message queue, determining the target storage unit in the storage space according to the sequence number information of the log block, and storing the log block in the unit in response to the available status of the target unit, achieving parallel storage and ordered storage.
It improves the efficiency of log storage, ensures the orderly storage of log blocks, timely releases the cache space of the log generator, and improves the operating efficiency and performance of the log generator thread.
Smart Images

Figure CN113742308B
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a method and device for storing logs. Background Art
[0002] Logs are important information used to record the system operation process. Archiving system logs can facilitate system recovery or anomaly detection. Existing methods for storing logs include: using multiple threads to transmit logs, the log storage service scans each thread and obtains and stores logs in the order of log sequence numbers, or based on a single thread to transmit logs, the log storage service receives each log in the order of log sequence numbers and stores the logs in sequence.
[0003] However, in the method of transmitting and storing logs based on multiple threads, the processing speeds of each thread are different, resulting in uneven distribution of logs. In order to obtain the next log in the order, some threads with fast processing speeds will have to wait for their logs to be stored, affecting the normal operation of the thread and the efficiency of log storage. The method of transmitting and storing logs based on a single thread will lead to the problem of low log storage efficiency. Summary of the invention
[0004] The present disclosure provides a method, an apparatus, an electronic device, and a computer-readable storage medium for storing a log.
[0005] According to a first aspect of the present disclosure, a method for storing logs is provided, comprising: obtaining at least one log block to be stored in a message queue, the log block to be stored including at least one system log; for each of the at least one log block to be stored, determining a target identifier of a storage unit in a storage space for storing the log block to be stored according to sequence number information of the log block to be stored; in response to determining that the state of the target storage unit indicated by the target identifier is an available state, storing the log block to be stored in the target storage unit.
[0006] In some embodiments, the serial number information of the log block to be stored includes the log sequence number of the starting log in the log block to be stored; based on the serial number information of the log block to be stored, the target identifier of the storage unit in the storage space for storing the log block to be stored is determined, including: determining the target identifier based on the log sequence number of the starting log and the space size of the storage space.
[0007] In some embodiments, the serial number information of the log block to be stored includes the block serial number of the log block to be stored; based on the serial number information of the log block to be stored, determining the target identifier of the storage unit in the storage space for storing the log block to be stored includes: determining the target identifier based on the block serial number of the log block to be stored and the number of storage units contained in the storage space.
[0008] In some embodiments, a method for determining that the status of a target storage unit is an available status includes: in response to determining that there is a stored log block in the target storage unit, determining whether the stored log block has been run by a preset program; in response to determining that the stored log block has been run by a preset program, determining that the status of the target storage unit is an available status; or, in response to determining that there is no log block in the target storage unit, determining that the status of the target storage unit is an available status.
[0009] In some embodiments, there are stored log blocks in the target storage unit, and the log blocks to be stored are stored in the target storage unit, including: in response to determining that the block sequence number of the log block to be stored is greater than the block sequence number of the stored log block, using the log block to be stored to overwrite the stored log block; or, in response to determining that the block sequence number of the log block to be stored is equal to the block sequence number of the stored log block, judging the relationship between the log sequence number of the last log in the log block to be stored and the log sequence number of the last log in the stored log block; in response to determining that the log sequence number of the last log in the log block to be stored is greater than the log sequence number of the last log in the stored log block, using the log block to be stored to overwrite the stored log block.
[0010] In some embodiments, the log block to be stored includes a log block header, a log block body and a log block tail, and the storage space includes: a first storage area for storing control information of the log block, a second storage area for storing the log block header and the log block tail, and a third storage area for storing the log body; according to the serial number information of the log block to be stored, determining the target identifier of the storage unit for storing the log block to be stored in the storage space, including: according to the serial number information of the log block to be stored, determining the target identifier of the storage unit for storing the control information, the log block header, the log block tail, and the log body of the log block to be stored in the storage space; storing the log block to be stored in the target storage unit, including: storing the control information of the log in the storage unit with the target identifier in the first storage area; storing the log block header and the log block tail in the storage unit with the target identifier in the second storage area; storing the log body in the storage unit with the target identifier in the third storage area.
[0011] According to a second aspect of the present disclosure, a device for storing logs is provided, comprising: an acquisition unit, configured to acquire at least one log block to be stored in a message queue, wherein the log block to be stored includes at least one system log; a determination unit, configured to determine, for each of the at least one log block to be stored, a target identifier of a storage unit in a storage space for storing the log block to be stored according to sequence number information of the log block to be stored; and a storage unit, configured to store the log block to be stored in the target storage unit in response to determining that the state of the target storage unit indicated by the target identifier is an available state.
[0012] In some embodiments, the serial number information of the log block to be stored includes the log sequence number of the starting log in the log block to be stored; the determination unit includes: a first determination module, configured to determine the target identifier according to the log sequence number of the starting log and the space size of the storage space.
[0013] In some embodiments, the sequence number information of the log block to be stored includes the block sequence number of the log block to be stored; the determination unit includes: a second determination module, configured to determine the target identifier according to the block sequence number of the log block to be stored and the number of storage units contained in the storage space.
[0014] In some embodiments, a method for determining that the status of a target storage unit is an available status includes: in response to determining that there is a stored log block in the target storage unit, determining whether the stored log block has been run by a preset program; in response to determining that the stored log block has been run by a preset program, determining that the status of the target storage unit is an available status; or, in response to determining that there is no log block in the target storage unit, determining that the status of the target storage unit is an available status.
[0015] In some embodiments, there are stored log blocks in the target storage unit, and the storage unit includes: a first storage module, configured to, in response to determining that the block sequence number of the log block to be stored is greater than the block sequence number of the stored log block, overwrite the stored log block with the log block to be stored; or, a second storage module, configured to, in response to determining that the block sequence number of the log block to be stored is equal to the block sequence number of the stored log block, determine the relationship between the log sequence number of the last log in the log block to be stored and the log sequence number of the last log in the stored log block; a second storage sub-module, configured to, in response to determining that the log sequence number of the last log in the log block to be stored is greater than the log sequence number of the last log in the stored log block, overwrite the stored log block with the log block to be stored.
[0016] In some embodiments, the log block to be stored includes a log block header, a log block body and a log block tail, and the storage space includes: a first storage area for storing control information of the log block, a second storage area for storing the log block header and the log block tail, and a third storage area for storing the log body; the determination unit includes: a third determination module, configured to determine the target identifier of the storage unit in the storage space for storing the control information, the log block header, the log block tail, and the log body of the log block to be stored according to the sequence number information of the log block to be stored; the storage module includes: a third storage module, configured to store the control information of the log in the storage unit with the target identifier in the first storage area; a fourth storage module, configured to store the log block header and the log block tail in the storage unit with the target identifier in the second storage area; and a fifth storage module, configured to store the log body in the storage unit with the target identifier in the third storage area.
[0017] According to the third aspect of the present disclosure, an embodiment of the present disclosure provides an electronic device, comprising: 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 for storing logs provided in the first aspect.
[0018] According to a fourth aspect of the present disclosure, an embodiment of the present disclosure provides a computer-readable storage medium having a computer program stored thereon, wherein when the program is executed by a processor, the method for storing logs provided in the first aspect is implemented.
[0019] The method and device for storing logs provided by the present disclosure include: obtaining at least one log block to be stored in a message queue, wherein the log block to be stored includes at least one system log; for each log block to be stored in the at least one log block to be stored, determining a target identifier of a storage unit in a storage space for storing the log block to be stored according to sequence number information of the log block to be stored; in response to determining that the state of the target storage unit indicated by the target identifier is an available state, storing the log block to be stored in the target storage unit, thereby improving the efficiency of storing logs.
[0020] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present application.
[0022] Figure 1 is an exemplary system architecture diagram to which embodiments of the present application may be applied;
[0023] Figure 2 is a flow chart of an embodiment of a method for storing logs according to the present application;
[0024] Figure 3 is a flow chart of another embodiment of a method for storing logs according to the present application;
[0025] Figure 4 is a flow chart of another embodiment of a method for storing logs according to the present application;
[0026] Figure 5 is a flow chart of another embodiment of a method for storing logs according to the present application;
[0027] Figure 6 is a structural schematic diagram of a log body of a method for storing logs according to the present application;
[0028] Figure 7 is a schematic diagram of a storage space of a method for storing logs according to the present application;
[0029] Figure 8 is a structural schematic diagram of an embodiment of a device for storing logs according to the present application;
[0030] Fig. 9 It is a block diagram of an electronic device used to implement the method for storing logs in an embodiment of the present application. DETAILED DESCRIPTION
[0031] The following is a description of exemplary embodiments of the present application in conjunction with the accompanying drawings, including various details of the embodiments of the present application 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 can be made to the embodiments described herein without departing from the scope and spirit of the present application. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0032] Figure 1 An exemplary system architecture 100 is shown to which an embodiment of a method for storing logs or an apparatus for storing logs of the present application can be applied.
[0033] like Figure 1 As shown, system architecture 100 may include server 101, network 102 and server 103. Network 102 is used to provide a medium for a communication link between server 101 and server 103. Network 102 may include various connection types, such as wired, wireless communication links or fiber optic cables.
[0034] The server 101 may interact with the server 103 through the network 102 to receive or send messages, logs, etc. The server 101 may be a server that provides services for applications, and various service processes may be run thereon.
[0035] The server 101 can be hardware or software. When the server 101 is hardware, it can be various electronic devices. When the server 101 is software, it can be various systems or processes running in electronic devices, such as application service systems, data processing processes, etc. It can be implemented as multiple software or software modules (such as multiple software modules for providing distributed services), or it can be implemented as a single software or software module. No specific limitation is made here.
[0036] The server 103 can be hardware or software. When the server 103 is hardware, it can be various electronic devices. When the server 103 is software, it can be a system or module running in an electronic device to provide storage services, such as a document storage system, a log storage system, etc. It can be implemented as multiple software or software modules (such as multiple software modules for providing distributed services), or it can be implemented as a single software or software module. No specific limitation is made here.
[0037] The server 103 can obtain at least one log block to be stored in the message queue, and for each log block to be stored, determine the target identifier of the storage unit in the storage space for storing the log block to be stored according to the serial number information of the log block to be stored, and after determining that the state of the target storage unit indicated by the target identifier is an available state, store the log block to be stored in the target storage unit.
[0038] It should be noted that the method for storing logs provided in the embodiments of the present disclosure can be executed by the terminal devices 101, 102, 103 or by the server 105. Accordingly, the device for storing logs can be set in the terminal devices 101, 102, 103 or in the server 105.
[0039] It should be understood that Figure 1 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.
[0040] Continue to refer Figure 2 , shows a process 200 of an embodiment of a method for storing logs according to the present disclosure, comprising the following steps:
[0041] Step 201: Obtain at least one log block to be stored in a message queue, wherein the log block to be stored includes at least one system log.
[0042] In this embodiment, the execution subject of the method for storing logs (eg Figure 1 The server 103 shown in the figure can obtain at least one log block to be stored in the message queue, wherein each log block contains at least one log generated by a system process / program during operation.
[0043] Step 202: for each of the at least one log block to be stored, determine a target identifier of a storage unit in the storage space for storing the log block to be stored according to the sequence number information of the log block to be stored.
[0044] In this embodiment, for each log block to be stored in at least one log block to be stored, the serial number information of the log block to be stored is obtained, and based on the serial number information of the log block to be stored, the target identifier of the storage unit in the storage space for storing the log block to be stored is determined.
[0045] Specifically, the serial number information of the log block (such as the block number of the log block, the log sequence number of a specified number of logs in the log block) can be used to take the remainder of the capacity of the storage space, and the remainder is used as the target identifier of the storage unit for storing the log block to be stored.
[0046] Specifically, each storage unit in the storage space can be corresponded to a slot on the hash ring, and a consistent hash calculation can be performed on the serial number information of the log block to be stored, and the calculation result can be determined as the target identifier. The slot on the hash ring where the target identifier falls is the target storage unit for storing the log block to be stored.
[0047] Step 203: In response to determining that the state of the target storage unit indicated by the target identifier is an available state, the log block to be stored is stored in the target storage unit.
[0048] In this embodiment, after determining that the state of the target storage unit indicated by the target identifier is in an available state, the log block to be stored is stored in the target storage unit. When no data is stored in the target storage unit, the state of the target storage unit can be determined to be in an available state; if any data such as log blocks has been stored in the target storage unit, after determining that the stored data has been applied or extracted by the data consumption module, the state of the target storage unit can be determined to be in an available state.
[0049] The method for storing logs provided in the embodiment obtains at least one log block to be stored in a message queue, wherein the log block to be stored includes at least one system log; for each log block to be stored in the at least one log block to be stored, according to the sequence number information of the log block to be stored, determines the target identifier of a storage unit in the storage space for storing the log block to be stored; in response to determining that the state of the target storage unit indicated by the target identifier is an available state, stores the log block to be stored in the target storage unit, firstly, log blocks generated by multiple threads can be received in parallel, and the log blocks are stored in the storage space according to the sequence number information of the log blocks. In the storage unit, even if the log block is not received according to the sequence number of the log block, since each log block is stored in the storage unit at the position corresponding to its sequence number, the log blocks stored in the storage space are in sequence, and the log blocks received out of order can be stored in order, thereby improving the efficiency of system log storage; secondly, the logs of the log generator can be received in time to release the cache space of the log generator, thereby improving the operating efficiency and performance of the log generator thread; in addition, the log blocks to be stored can be used to overwrite the log blocks stored in the storage unit and have been consumed, thereby realizing automatic cleaning of useless log blocks and saving system operation steps.
[0050] Optionally, the serial number information of the log block to be stored includes the log sequence number of the starting log in the log block to be stored; based on the serial number information of the log block to be stored, determining the target identifier of the storage unit in the storage space for storing the log block to be stored, including: determining the target identifier based on the log sequence number of the starting log and the space size of the storage space.
[0051] In this embodiment, the log block to be stored includes at least one log, and the target identifier of the storage unit in the storage space for storing the log block can be determined according to the LSN (log sequence number) of the first log / starting log in the log block to be stored. Specifically, the log sequence number of the starting log can be used to perform a modulo operation on the space size / space length of the storage space, and the operation result is used as the target identifier for indicating the target storage unit.
[0052] In some application scenarios, there may be reserved storage space in the storage space for storing other log information. For example, the first three storage units in the storage space are reserved for storing log control information and attribute information. In this case, the above calculation result needs to be offset based on the offset number (the offset number is determined according to the number or size of reserved bits).
[0053] In this embodiment, the target identifier of the storage unit for storing the log to be stored is determined based on the log sequence number of the starting log in the log block to be stored, which can improve the accuracy and efficiency of determining the target identifier.
[0054] Optionally, the serial number information of the log block to be stored includes the block serial number of the log block to be stored; based on the serial number information of the log block to be stored, determining the target identifier of the storage unit in the storage space for storing the log block to be stored, including: determining the target identifier based on the block serial number of the log block to be stored and the number of storage units contained in the storage space.
[0055] In this embodiment, each log block to be stored has a block sequence number, and the target identifier of the storage unit in the storage space for storing the log block can be determined according to the block sequence number of the log block to be stored. Specifically, the block sequence number of the log block to be stored can be modulo the number of storage units included in the storage space, and the result of the operation is used as the target identifier for indicating the target storage unit.
[0056] In this embodiment, the target identifier of the storage unit for storing the log to be stored is determined based on the block sequence number of the log block to be stored, which can improve the accuracy and efficiency of determining the target identifier.
[0057] Continue to refer Figure 3 , shows a process 300 of another embodiment of a method for storing logs according to the present disclosure, comprising the following steps:
[0058] Step 301: Obtain at least one log block to be stored in a message queue, wherein the log block to be stored includes at least one system log.
[0059] Step 302: for each of the at least one log block to be stored, determine a target identifier of a storage unit in the storage space for storing the log block to be stored according to the sequence number information of the log block to be stored.
[0060] The description of step 301 and step 302 in this embodiment is consistent with the description of step 201 and step 202, and will not be repeated here.
[0061] Step 303: In response to determining that there is a stored log block in the target storage unit, it is determined whether the stored log block has been executed by a preset program.
[0062] In this embodiment, if other log blocks have already been stored in the target storage unit indicated by the target identifier, it is necessary to determine whether the stored log block has been run by a preset program, such as whether it has been extracted by other computing nodes for calculation, or whether it has been received by a persistent storage system and stored as persistent data, so as to prevent other logs that have not been used after storage from being overwritten by new logs to be stored, thereby causing data loss.
[0063] Step 304, in response to determining that the stored log block has been run by the preset program, determining that the state of the target storage unit is an available state, and storing the log block to be stored in the target storage unit.
[0064] In this embodiment, after determining that the stored log blocks have been run by the preset program, it can be determined that the target storage unit is in an available state, that is, the log blocks stored in the target storage unit have been consumed, and the target storage unit can be used to store new log blocks. At this time, the log blocks to be stored can be stored in the target storage unit.
[0065] Compared with the method for storing logs provided in this embodiment, Figure 2 The described embodiment adds that if the target storage unit already has stored log blocks, the data block to be stored is stored in the target storage unit only after it is determined that the stored log blocks have been run by a preset program, so as to avoid the problem of data loss.
[0066] Optionally, after step 303, if it is determined that the stored log block has not been run by the preset program, wait until the stored log block is run by the preset program (i.e., after determining that the state of the target storage unit changes from an unavailable state to an available state), and then store the log block to be stored in the target storage unit.
[0067] Optionally, after step 302, in response to determining that the log block does not exist in the target storage unit, the state of the target storage unit is determined to be an available state, and the log block to be stored is stored in the target storage unit.
[0068] In this embodiment, if no log block is stored in the target storage unit, it can be determined that the state of the target storage unit is an available state, and the log block to be stored can be stored in the target storage unit.
[0069] Continue to refer Figure 4 , shows a process 400 of another embodiment of a method for storing logs according to the present disclosure, comprising the following steps:
[0070] Step 401: Obtain at least one log block to be stored in a message queue, wherein the log block to be stored includes at least one system log.
[0071] Step 402: for each of the at least one log block to be stored, determine a target identifier of a storage unit in the storage space for storing the log block to be stored according to the sequence number information of the log block to be stored.
[0072] The description of step 401 and step 402 in this embodiment is consistent with the description of step 201 and step 202, and will not be repeated here.
[0073] Step 403 : in response to determining that the state of the target storage unit indicated by the target identifier is an available state, compare the block sequence number of the log block to be stored with the block sequence number of the stored log block.
[0074] In this embodiment, if it is determined that the state of the target storage unit indicated by the target identifier is an available state, the block sequence number of the log block to be stored is compared with the block sequence number of the stored log block.
[0075] Step 4041: In response to determining that the block sequence number of the log block to be stored is greater than the block sequence number of the stored log block, the log block to be stored is used to overwrite the stored log block.
[0076] In this embodiment, if it is determined that the block number of the log block to be stored is greater than the block number of the stored log block, it means that the log block to be stored is generated later than the stored log block, and since the state of the target storage unit has been determined to be available in step 403, that is, the stored log block has been used up by the preset program, the log block to be stored can be used to overwrite the stored log block.
[0077] Step 40421, in response to determining that the block sequence number of the log block to be stored is equal to the block sequence number of the stored log block, determine the relationship between the log sequence number of the last log in the log block to be stored and the log sequence number of the last log in the stored log block.
[0078] In this embodiment, if it is determined that the block sequence number of the log block to be stored is equal to the block sequence number of the stored log block, it means that the same log block may be divided into at least two times for transmission. At this time, the relationship between the log sequence number of the last log in the log block to be stored and the log sequence number of the last log in the stored log block is determined to determine whether to store the log block with the same block sequence number received again. Among them, the last log in the log block to be stored refers to the last log in the log block.
[0079] Step 40422: In response to determining that the log sequence number of the last log in the log block to be stored is greater than the log sequence number of the last log in the stored log block, the stored log block is overwritten with the log block to be stored.
[0080] In this embodiment, if it is determined that the log sequence number of the last log in the log block to be stored is greater than the log sequence number of the last log in the stored log, it means that although the log block to be stored received this time has the same block number as the stored log block, the number of logs in the log block to be stored received this time is greater and the logs in the log block are more complete, so the log block to be stored is used to overwrite the stored log block to store the log block with a more complete log.
[0081] It can be understood that if it is determined that the log sequence number of the last log in the log block to be stored is less than the log sequence number of the last log in the stored log, it means that although the log block to be stored received this time has the same block number as the stored log block, the number of logs in the log block to be stored received this time is smaller and the logs in the stored log block are more complete, so the log block to be stored is discarded.
[0082] Compared with the method for storing logs provided in this embodiment, Figure 2 The described embodiment adds how to determine whether to store or discard the log block to be stored based on the block sequence number of the stored log block in the target storage unit and the block sequence number of the log block to be stored, as well as the log sequence number of the last log in the stored log block and the log sequence number of the last log in the log block to be stored. The storage operation can be performed on the log block to be stored only when necessary (when the log in the log block to be stored has not been stored or has not been completely stored), which can save system resources and improve storage efficiency.
[0083] Continue to refer Figure 5 , shows a process 500 of another embodiment of a method for storing logs according to the present disclosure, comprising the following steps:
[0084] Step 501: Obtain at least one log block to be stored in a message queue, wherein the log block to be stored includes at least one system log, wherein the log block to be stored includes a log block header, a log body, and a log block footer.
[0085] In this embodiment, the execution subject of the method for storing logs (eg Figure 1 The server 103 shown in FIG. 104 can obtain at least one log block to be stored in the message queue, wherein each log block contains at least one log generated during the operation of the system / program, such as Figure 6 As shown, each log to be stored includes three parts: a log block header, a log body, and a log block tail.
[0086] Step 502, for each of the at least one log block to be stored, determine the target identifier of a storage unit in the storage space for storing control information, a log block header, a log block tail, and a log body of the log block to be stored according to the sequence number information of the log block to be stored, wherein the storage space includes: a first storage area for storing control information of the log block, a second storage area for storing the log block header and the log block tail, and a third storage area for storing the log body.
[0087] In this embodiment, for each of the at least one log block to be stored, the target identifier of the storage unit for storing the control information of the log block to be stored, the storage unit for storing the log block header and the log block tail, and the storage unit for storing the log body in the storage space is determined according to the sequence number information of the log block to be stored. Figure 7 As shown, the storage area includes a first storage area for storing control information of a log block, a second storage area for storing a log block header and a log block tail, and a third storage area for storing a log body. The identifier of a storage unit for storing control information of a certain log block in the first storage area of the storage space, the identifier of a storage unit for storing a log block header and a log block tail of the certain log block in the second storage area, and the identifier of a storage unit for storing a log body of the certain log block in the third storage area are the same.
[0088] Step 503, in response to determining that the state of the storage unit in the first storage area indicated by the target identifier is an available state, the state of the storage unit in the second storage area indicated by the target identifier is an available state, and the state of the storage unit in the third storage area indicated by the target identifier is an available state, the control information of the log is stored in the storage unit with the target identifier in the first storage area; the log block header and the log block tail are stored in the storage unit with the target identifier in the second storage area; and the log body is stored in the storage unit with the target identifier in the third storage area.
[0089] In this embodiment, if it is determined that the state of the storage unit in the first storage area indicated by the target identifier is an available state, the state of the storage unit in the second storage area indicated by the target identifier is an available state, and the state of the storage unit in the third storage area indicated by the target identifier is an available state, then Figure 7 As shown, the control information of the log can be stored in a storage unit with a target identifier in the first storage area; the log block header and the log block tail can be stored in a storage unit with a target identifier in the second storage area; and the log body can be stored in a storage unit with a target identifier in the third storage area.
[0090] Compared with the method for storing logs provided in this embodiment, Figure 2 In the described embodiment, the log block to be stored includes three parts: a log block header, a log body and a log block tail. The storage area includes a first storage area for storing control information of the log block, a second storage area for storing header and tail information of the log block, and a third storage area for storing the log body of the log block. Storing each part of the information of the log block to be stored in each storage area respectively can improve the efficiency of storing information, and each log can be continuously stored in the log body part.
[0091] In some application scenarios, when querying the stored log blocks from the storage space, since the storage space is composed of a whole block of memory, including the control area (block_control) for storing the control information of the log block, the information area (block_info) for storing the log block header and log block tail, and the log area (block_data) for storing the log body, each part is composed of fixed-length information: the control area contains the log block sequence number, lock and other information; the information area contains the head and tail information of the log block or the head and tail information of the log therein; the log body area is composed of several logs spliced together continuously. The number of information blocks in each area is the same, so all the information of a log block can be queried by mathematical calculation.
[0092] For example, the starting address of the control area can be preset as Addr-ctrl, the starting address of the information area as Addr-info, and the starting address of the log body area (also called the data area) as Addr-redo. If you need to query the information of the log block with block number 100, you can query the control information of the log block from Addr-ctrl+100*sizeof(block_control); query the header and tail information of the log block from Addr-info+100*sizeof(block_info); and query the data / log body part of the log block from Addr-redo+100*sizeof(block_data). Among them, sizeof(block_control), sizeof(block_info), and sizeof(block_data) represent the size of the preset control information, the size of the preset log header and tail information, and the size of the preset log body, respectively.
[0093] In some application scenarios, methods for storing logs include:
[0094] The first step is to obtain a new message from the message queue, parse the log block in the message, and process the received log blocks in parallel: determine the target identifier of the storage unit used to store the log block in the storage space according to the start_lsn or block_no recorded in each log block. Assuming that the obtained target identifier is N, the storage area used to store the control information, log block header, log block tail, and log body of the log block to be stored is the Nth part / Nth storage unit of each area (control area, information area, data area).
[0095] Among them, determining the storage unit target identifier for storing the log block in the storage space according to the start_lsn recorded in the log block includes: (start_lsn%length-offset), start_lsn represents the log sequence number of the starting log in the log block to be stored, and length represents the space size of the storage space.
[0096] The target identifier of the storage unit for storing the log block in the storage space is determined according to the block_no recorded in the log block, including: (block_no%block_size), block_no represents the block number of the log block to be stored, and block_size represents the number of storage units contained in each storage area.
[0097] The second step is to determine whether the storage unit N is available, that is, whether the stored log blocks in the storage unit have been run by the preset program. If it is not available, wait for the stored log blocks to be run by the preset program. If it is available, continue to execute the subsequent steps.
[0098] The third step is to merge the head and tail information of the log block to be stored and store them in the Nth storage unit of the information area, that is, Addr-info+N*sizeof(block_info); store the log body in the Nth storage unit of the data area; store the control information of the log block to be stored in the Nth storage unit of the control area, including:
[0099] Compare the block sequence number of the log block to be stored with the block sequence number of the stored log block in the Nth storage unit. If the block sequence number of the log block to be stored is greater than the block sequence number of the stored log block, the log block header and log block footer information of the log block to be stored are used to overwrite the Nth storage unit in the information area, the log body of the log block to be stored is used to overwrite the Nth storage unit in the data area, and the control information of the log block to be stored is used to modify the information in the Nth storage unit in the control area.
[0100] If the block number of the log block to be stored is smaller than the block number of the stored log block, no operation is performed.
[0101] If the block number of the log block to be stored is equal to the block number of the stored log block, then determine whether the log sequence number of the last log in the log block to be stored is greater than the log sequence number of the last log in the stored log block. If so, use the log block to be stored to overwrite the stored log block. If so, discard the log block to be stored.
[0102] The fourth step is to update the global low water mark to notify the preset program that needs to apply / consume the log block of the maximum number of the currently stored continuous log blocks, so that the preset program that needs to apply the continuous log blocks can move forward.
[0103] Afterwards, it returns to the first step to continue parallel processing of the received log blocks.
[0104] The application scenario also includes a log file archiving step: reading the next log block based on the log sequence number of the archived log block, if the log sequence number of the last log in the read log block is less than the global low water mark, concatenating the head and tail information of the read log block with the log body to obtain the original log block, and then storing the original log block on the object storage; if the log sequence number of the last log of the read log block is equal to the global low water mark, continue to read the next log block; if the log sequence number of the last log of the read log block is greater than the global low water mark, it is necessary to wait for the global low water mark to advance.
[0105] Further references Figure 8 As an implementation of the methods shown in the above figures, the present disclosure provides an embodiment of a device for storing logs. Figure 2 , Figure 3 , Figure 4 ,and Figure 5 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0106] like Figure 8 As shown, the device for storing logs in this embodiment includes: an acquisition unit 801, a determination unit 802, and a storage unit 803. The acquisition unit is configured to acquire at least one log block to be stored in the message queue, wherein the log block to be stored includes at least one system log; the determination unit is configured to determine, for each log block to be stored in the at least one log block to be stored, a target identifier of a storage unit in the storage space for storing the log block to be stored according to the sequence number information of the log block to be stored; and the storage unit is configured to store the log block to be stored in the target storage unit in response to determining that the state of the target storage unit indicated by the target identifier is an available state.
[0107] In some embodiments, the serial number information of the log block to be stored includes the log sequence number of the starting log in the log block to be stored; the determination unit includes: a first determination module, configured to determine the target identifier according to the log sequence number of the starting log and the space size of the storage space.
[0108] In some embodiments, the sequence number information of the log block to be stored includes the block sequence number of the log block to be stored; the determination unit includes: a second determination module, configured to determine the target identifier according to the block sequence number of the log block to be stored and the number of storage units contained in the storage space.
[0109] In some embodiments, a method for determining that the status of a target storage unit is an available status includes: in response to determining that there is a stored log block in the target storage unit, determining whether the stored log block has been run by a preset program; in response to determining that the stored log block has been run by a preset program, determining that the status of the target storage unit is an available status; or, in response to determining that there is no log block in the target storage unit, determining that the status of the target storage unit is an available status.
[0110] In some embodiments, there are stored log blocks in the target storage unit, and the storage unit includes: a first storage module, configured to, in response to determining that the block sequence number of the log block to be stored is greater than the block sequence number of the stored log block, overwrite the stored log block with the log block to be stored; or, a second storage module, configured to, in response to determining that the block sequence number of the log block to be stored is equal to the block sequence number of the stored log block, determine the relationship between the log sequence number of the last log in the log block to be stored and the log sequence number of the last log in the stored log block; a second storage sub-module, configured to, in response to determining that the log sequence number of the last log in the log block to be stored is greater than the log sequence number of the last log in the stored log block, overwrite the stored log block with the log block to be stored.
[0111] In some embodiments, the log block to be stored includes a log block header, a log block body and a log block tail, and the storage space includes: a first storage area for storing control information of the log block, a second storage area for storing the log block header and the log block tail, and a third storage area for storing the log body; the determination unit includes: a third determination module, configured to determine the target identifier of the storage unit in the storage space for storing the control information, the log block header, the log block tail, and the log body of the log block to be stored according to the sequence number information of the log block to be stored; the storage unit includes: a third storage module, configured to store the control information of the log in the storage unit with the target identifier in the first storage area; a fourth storage module, configured to store the log block header and the log block tail in the storage unit with the target identifier in the second storage area; and a fifth storage module, configured to store the log body in the storage unit with the target identifier in the third storage area.
[0112] Each unit in the above device 800 is similar to the reference Figure 2 , Figure 3 , Figure 4 and Figure 5 Therefore, the operations, features and technical effects described above for the method for storing logs are also applicable to the device 800 and the units contained therein, and will not be described in detail here.
[0113] According to an embodiment of the present application, the present application also provides an electronic device and a readable storage medium.
[0114] like Fig. 9 , is a block diagram of an electronic device 900 for storing a log according to an embodiment of the present application. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or required herein.
[0115] like Fig. 9 As shown, the electronic device includes: one or more processors 901, a memory 902, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. The various components are interconnected using different buses and can be installed on a common mainboard or installed in other ways as needed. The processor can process instructions executed in the electronic device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as a display device coupled to the interface). In other embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple electronic devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Fig. 9 A processor 901 is taken as an example.
[0116] The memory 902 is a non-transient computer-readable storage medium provided in the present application. The memory stores instructions executable by at least one processor to enable the at least one processor to perform the method for storing logs provided in the present application. The non-transient computer-readable storage medium of the present application stores computer instructions, which are used to enable a computer to perform the method for storing logs provided in the present application.
[0117] The memory 902 is a non-transient computer-readable storage medium that can be used to store non-transient software programs, non-transient computer executable programs and modules, such as the program instructions / modules corresponding to the method for storing logs in the embodiment of the present application (for example, the attached Figure 8 The processor 901 executes various functional applications and data processing of the server by running the non-transient software programs, instructions and modules stored in the memory 902, that is, the method for storing logs in the above method embodiment is implemented.
[0118] The memory 902 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required by at least one function; the data storage area may store data created according to the use of the electronic device for extracting video clips, etc. In addition, the memory 902 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory 902 may optionally include a memory remotely arranged relative to the processor 901, and these remote memories may be connected to the electronic device for extracting video clips via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0119] The electronic device for storing logs may further include: an input device 903, an output device 904, and a bus 905. The processor 901, the memory 902, the input device 903, and the output device 904 may be connected via the bus 905 or in other ways. Fig. 9 The connection via bus 905 is taken as an example.
[0120] The input device 903 can receive input digital or character information, and generate key signal input related to user settings and function control of the electronic device for extracting video clips, such as input devices such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator rod, one or more mouse buttons, a trackball, a joystick, etc. The output device 904 may include a display device, an auxiliary lighting device (e.g., an LED), and a tactile feedback device (e.g., a vibration motor), etc. The display device may include, but is not limited to, a liquid crystal display (LCD), a light emitting diode (LED) display, and a plasma display. In some embodiments, the display device may be a touch screen.
[0121] Various implementations of the systems and techniques described herein can be realized in digital electronic circuit systems, integrated circuit systems, dedicated ASICs (application specific integrated circuits), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0122] These computer programs (also referred to as programs, software, software applications, or code) include machine instructions for programmable processors and can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, device, and / or means (e.g., disk, optical disk, memory, programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.
[0123] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0124] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0125] A computer system may include clients and servers. Clients and servers are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship to each other.
[0126] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this application can be executed in parallel, sequentially or in different orders, as long as the expected results of the technical solution disclosed in this application can be achieved, and this document is not limited here.
[0127] The above specific implementations do not constitute a limitation on the protection scope of this application. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of this application should be included in the protection scope of this application.
Claims
1. A method for storing logs, include: Acquire at least one log block to be stored in the message queue, wherein the log block to be stored includes at least one system log generated by a system process / program during operation; For each of the at least one log block to be stored, determining a target identifier of a storage unit in the storage space for storing the log block to be stored according to the sequence number information of the log block to be stored; In response to determining that the state of the target storage unit indicated by the target identifier is an available state, storing the log block to be stored in the target storage unit corresponding to its sequence number; The method for determining that the state of the target storage unit is an available state comprises: In response to determining that there is a stored log block in the target storage unit and the stored log block has been run by a preset program, determining that the state of the target storage unit is an available state; or, In response to determining that no log block exists in the target storage unit, determining that the state of the target storage unit is an available state.
2. The method according to claim 1, in, The serial number information of the log block to be stored includes the log sequence number of the starting log in the log block to be stored; The determining, according to the sequence number information of the log block to be stored, a target identifier of a storage unit in the storage space for storing the log block to be stored includes: The target identifier is determined according to the log sequence number of the starting log and the space size of the storage space.
3. The method according to claim 1, in, The sequence number information of the log block to be stored includes the block sequence number of the log block to be stored; The determining, according to the sequence number information of the log block to be stored, a target identifier of a storage unit in the storage space for storing the log block to be stored includes: The target identifier is determined according to the block sequence number of the log block to be stored and the number of storage units included in the storage space.
4. The method according to claim 1, in, The target storage unit has stored log blocks, and storing the log blocks to be stored in the target storage unit includes: In response to determining that the block sequence number of the log block to be stored is greater than the block sequence number of the stored log block, overwriting the stored log block with the log block to be stored; or, In response to determining that the block sequence number of the log block to be stored is equal to the block sequence number of the stored log block, determining the relationship between the log sequence number of the last log in the log block to be stored and the log sequence number of the last log in the stored log block; In response to determining that the log sequence number of the last log in the log block to be stored is greater than the log sequence number of the last log in the stored log block, the stored log block is overwritten with the log block to be stored.
5. The method according to claim 1, in, The log block to be stored includes a log block header, a log body and a log block tail, and the storage space includes: a first storage area for storing control information of the log block, a second storage area for storing the log block header and the log block tail, and a third storage area for storing the log body; The determining, according to the sequence number information of the log block to be stored, a target identifier of a storage unit in the storage space for storing the log block to be stored includes: Determine, according to the sequence number information of the log block to be stored, a target identifier of a storage unit in a storage space for storing control information of the log block to be stored, the log block header, the log block tail, and the log body; The step of storing the log block to be stored in the target storage unit includes: storing the control information of the log in a storage unit having the target identifier in the first storage area; storing the log block header and the log block tail in a storage unit having the target identifier in the second storage area; The log body is stored in a storage unit having the target identifier in the third storage area.
6. A device for storing logs, include: An acquisition unit is configured to acquire at least one log block to be stored in the message queue, wherein the log block to be stored includes at least one system log generated by a system process / program during operation; a determining unit configured to determine, for each of the at least one log block to be stored, a target identifier of a storage unit in the storage space for storing the log block to be stored according to the sequence number information of the log block to be stored; a storage unit configured to, in response to determining that the state of the target storage unit indicated by the target identifier is an available state, store the log block to be stored in the target storage unit corresponding to its sequence number; The method for determining that the state of the target storage unit is an available state comprises: In response to determining that there is a stored log block in the target storage unit and the stored log block has been run by a preset program, determining that the state of the target storage unit is an available state; or, In response to determining that no log block exists in the target storage unit, determining that the state of the target storage unit is an available state.
7. The device according to claim 6, in, The serial number information of the log block to be stored includes the log sequence number of the starting log in the log block to be stored; The determining unit comprises: The first determination module is configured to determine the target identifier according to the log sequence number of the starting log and the space size of the storage space.
8. The device according to claim 6, in, The sequence number information of the log block to be stored includes the block sequence number of the log block to be stored; The determining unit comprises: The second determination module is configured to determine the target identifier according to the block sequence number of the log block to be stored and the number of storage units included in the storage space.
9. The device according to claim 6, in, The target storage unit has stored log blocks, and the storage unit includes: A first storage module is configured to, in response to determining that the block sequence number of the log block to be stored is greater than the block sequence number of the stored log block, overwrite the stored log block with the log block to be stored; or A second storage module is configured to, in response to determining that the block sequence number of the log block to be stored is equal to the block sequence number of the stored log block, determine the relationship between the log sequence number of the last log in the log block to be stored and the log sequence number of the last log in the stored log block; The second storage submodule is configured to, in response to determining that the log sequence number of the last log in the log block to be stored is greater than the log sequence number of the last log in the stored log block, overwrite the stored log block with the log block to be stored.
10. The device according to claim 6, in, The log block to be stored includes a log block header, a log body and a log block tail, and the storage space includes: a first storage area for storing control information of the log block, a second storage area for storing the log block header and the log block tail, and a third storage area for storing the log body; The determining unit comprises: A third determination module is configured to determine, according to the sequence number information of the log block to be stored, a target identifier of a storage unit in the storage space for storing the control information of the log block to be stored, the log block header, the log block tail, and the log body; The storage unit comprises: A third storage module is configured to store the control information of the log in a storage unit having the target identifier in the first storage area; a fourth storage module, configured to store the log block header and the log block tail in a storage unit having the target identifier in the second storage area; The fifth storage module is configured to store the log body in a storage unit having the target identifier in the third storage area.
11. An electronic device, include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 5.
12. A non-transitory computer-readable storage medium storing computer instructions, in, The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Log recording method, battery management system, vehicle and electronic equipment
CN110555006A
Log storage method for improving performance of target system and related equipment thereof
CN112559476A
Log data backup method and device, equipment and storage medium
CN112905390A
Data storage method, data recovery method, related apparatus, and system
IN201614019287A
Resource reservation for storage system metadata updates
US20160110121A1
