Full-flow data storage method, related method and device

Through layered compression and index construction technology, it solves the performance bottleneck problem of traditional full-traffic data storage methods in high-traffic environments, achieves efficient storage and retrieval, and is suitable for high-throughput network monitoring and data analysis scenarios.

CN118764542AActive Publication Date: 2024-10-11WUHAN BOYIXUN INFORMATION TECH CO LTD

Patent Information

Application Number
CN202411190624.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-28
Publication Date
2024-10-11
Estimated Expiration
2044-08-28

AI Technical Summary

Technical Problem

Traditional full-flow data storage methods have serious performance bottlenecks in high-flow environments, making it difficult to balance storage costs and data retrieval requirements. Moreover, existing compression methods are not ideal in terms of CPU resource usage and compression effect, affecting the real-time processing capabilities and integrity of data.

Method used

Adopt a layered compression strategy to select the most suitable compression algorithm based on data characteristics, perform layered compression on data packet headers and payloads, and generate compressed files and index files through index construction and loop coverage storage methods to optimize storage space and retrieval efficiency. .

Benefits of technology

It significantly reduces the storage space requirements for full-flow packets, improves storage economy and overall system I/O performance, enables quick retrieval and access of compressed data, and adapts to different network environments and application requirements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118764542A_ABST
    Figure CN118764542A_ABST
Patent Text Reader

Abstract

The invention discloses a full-flow data storage method, a related method and a device. The full-flow data storage method comprises the following steps: acquiring a data packet according to a set capture condition, and adding a packet header to the data packet; copying the data packets into a cache queue according to the acquisition sequence to obtain a message file; when the message file meets a preset compression condition, segmenting the message file into at least one file segment according to a preset segment length; according to the data characteristics of each data packet of each file segment, determining a corresponding compression algorithm to perform hierarchical compression on a packet header and an effective load of each data packet of the file segment, generating a compressed file segment, and adding a segment header to the compressed file segment; generating a compressed file and a corresponding version file according to each compressed file segment and the corresponding segment head; according to the segment ID of each compressed file segment and the position of each data packet in the file segment, generating an index file and storing the index file in a file header; and writing the compressed file into a memory according to a circular coverage mode, and updating a file header.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of computer network data processing, and in particular to a full-flow data storage method, related methods and devices. Background Art

[0002] In the era of the booming Internet, the amount of network data has shown explosive growth. The capture and analysis of full-flow data has become increasingly important for network security monitoring, troubleshooting, traffic behavior analysis and other fields. Full-flow data storage is a data storage method that captures all packets or specified types of packets in network traffic, saves the captured packets on disk, and processes them by indexing, parsing, and compressing. It aims to save complete records of network communication, realize network full-flow collection and storage, behavior analysis and full-flow backtracking, so as to achieve post-analysis, security auditing, troubleshooting, compliance inspection and business insights. Full-flow storage faces extremely high data throughput and storage capacity requirements, which require efficient storage solutions and data compression technologies. Given the high cost and technical difficulty of storing and processing full-flow data, effectively managing and indexing this data and balancing storage costs with data retrieval and analysis requirements have become key challenges in implementing full-flow storage. Summary of the invention

[0003] In order to better realize full-flow data storage, a full-flow data storage method, related methods and devices are provided in an embodiment of the present invention.

[0004] In a first aspect, an embodiment of the present invention provides a method for storing full-flow data, which may include: Acquire a data packet according to the set capture conditions, and add a packet header to the data packet; Copy the data packets to the cache queue in the order of acquisition to obtain the message file; When the message file meets the preset compression condition, the message file is divided into at least one file segment according to the preset segment length; each of the file segments includes a plurality of data packets; According to the data characteristics of each data packet of each file segment, determine the corresponding compression algorithm to perform hierarchical compression on the packet header and the effective load of each data packet of the file segment to generate a compressed file segment, and add a segment header to the compressed file segment; Generate a compressed file and a corresponding version file according to each compressed file segment and the corresponding segment header; the version file includes the file header of the compressed file and the segment position information of each compressed file segment; Generate an index file according to the segment ID of each compressed file segment and the position of each data packet in the file segment and store it in the file header; the index file includes the segment ID of the compressed file segment and the offset within the segment of each data packet; The compressed file is written into the memory in a circular overwriting manner, and the file header is updated.

[0005] In one or some optional implementations of the embodiments of the present application, determining, according to data characteristics of each data packet of each file segment, a corresponding compression algorithm to perform hierarchical compression on a packet header and a payload of each data packet of the file segment to generate a compressed file segment, and adding a segment header to the compressed file segment includes: Determine a corresponding compression algorithm to compress the header of each data packet of each file segment according to data characteristics of the header of each data packet of each file segment, and generate a compressed header; Determine a corresponding compression algorithm to compress the payload of each data packet of each file segment according to the data characteristics of the message content of each data packet of each file segment to generate compressed message data; Obtain a compressed data packet according to each compressed packet header and the corresponding compressed message data, and generate a compressed file segment; A segment header is added to the compressed file segment; the segment header includes a segment ID of the compressed file segment, a compression algorithm used, a length of the compressed data, and an uncompressed length of the original data.

[0006] In one or some optional implementations of the embodiments of the present application, the data characteristics of the message content of the data packet include redundant information; The step of determining, according to the data characteristics of the message content of each data packet of each file segment, a corresponding compression algorithm to compress the effective load of each data packet of the file segment to generate compressed message data comprises: Determine whether the type of redundant information present in the message content of each data packet of each file segment is a static field, a semi-static field or a variable field; According to the type of redundant information existing in the message content of each data packet of the file segment, a corresponding compression algorithm is determined, and the effective load of each data packet of the file segment is compressed to generate compressed message data.

[0007] In one or some optional implementations of the embodiments of the present application, the method described further includes: if the data type of the message content of each data packet of each of the file segments is a preset data type that is easy to compress, then a packet-by-packet compression strategy is adopted according to a determined compression algorithm to compress the payload of each data packet of the file segment to generate compressed message data.

[0008] In one or some optional implementations of the embodiments of the present application, the method described further includes: determining whether there is data with the same characteristics in each data packet based on data characteristics of the message content of each data packet of each file segment; if so, using a determined compression algorithm to compress the first data with the same characteristics to obtain compressed message data, and using metadata indexes to reference the compressed message data for other data with the same characteristics.

[0009] In one or some optional implementations of the embodiment of the present application, generating an index file according to the segment ID of each compressed file segment and the position of each data packet in the file segment and storing it in the file header includes: Obtaining the segment header of each compressed file segment, and extracting the segment ID of each compressed file segment; Determine the data packet to be indexed and the position of the data packet in the file segment according to the pre-configured feature rule; According to the segment ID of each compressed file segment and the position of each data packet to be indexed in the file segment, the index thread is called to generate an index file, and the index file is stored in the file header; the index file includes the segment ID of the compressed file segment and the intra-segment offset of each data packet to be indexed in the file segment.

[0010] In one or some optional implementations of the embodiment of the present application, acquiring a data packet according to a set capture condition and adding a packet header to the data packet includes: Capture passing data packets through the network interface according to the set capture conditions; The captured data packet is truncated according to a preset length to obtain a truncated data packet, and a packet header is added to the truncated data packet; the packet header includes a timestamp of the data packet, a data packet length, a source address and a destination address.

[0011] In one or some optional implementations of the embodiment of the present application, the method further includes: judging whether the message file meets the preset compression condition in the following manner: Determine whether the data volume of the message file reaches a preset data volume threshold; and / or, Determine whether the cache time of the message file reaches a preset time threshold; wherein the cache time is the time interval from the cache time of the earliest cached data packet in the message file to the current time.

[0012] In one or some optional implementations of the embodiment of the present application, the memory includes storage space for a plurality of original message files arranged in sequence; the file size of the original message file is a preset storage capacity value; The step of writing the compressed file into the memory in a circular overwriting manner and updating the file header comprises: Searching in order whether the storage space of each original message file in the memory reaches a preset storage capacity value; If not, writing the compressed file into the free storage space of the original message file preceding in the order, and updating the file header; If so, the earliest written data is overwritten by the compressed file in the order of the time when the data is written in the storage space of each original message file, and the file header is updated; the information in the file header includes the file's version information, status, start time, end time, file name prefix, file name, segment ID of the last compressed file segment, and the write position of the compressed file.

[0013] In a second aspect, an embodiment of the present invention provides a method for decompressing full-flow data, including: Determine the segment ID of the compressed data segment where the target data packet is located and the offset within the segment of the target data packet according to the index file in the file header of the compressed file; Reading a corresponding segment header of the compressed data segment according to the segment ID of the compressed data segment, and determining the allocated memory space according to the information of the segment header; Reading the compressed data segment into the allocated memory space, decompressing it, and copying the decompressed data to an uncompressed buffer; According to the intra-segment offset of the target data packet, the header position of the target data packet is located in the decompressed data, and the packet header and the effective load of the target data packet are obtained.

[0014] In a third aspect, an embodiment of the present invention provides a full-flow data storage device, including: A capture module, used to acquire data packets according to set capture conditions and add a packet header to the data packets; A cache module is used to copy the data packets into the cache queue in the acquisition order to obtain the message file; A segmentation module, used for segmenting the message file into at least one file segment according to a preset segment length when the message file meets a preset compression condition; each of the file segments includes a plurality of data packets; A compression module, for determining a corresponding compression algorithm according to data characteristics of each data packet of each file segment, performing hierarchical compression on the packet header and the effective load of each data packet of the file segment, generating a compressed file segment, and adding a segment header to the compressed file segment; A generation module, used to generate a compressed file and a corresponding version file according to each compressed file segment and the corresponding segment header; the version file includes the file header of the compressed file and the segment position information of each compressed file segment; An index module, used to generate an index file according to the segment ID of each compressed file segment and the position of each data packet in the file segment and store it in the file header; the index file includes the segment ID of the compressed file segment and the offset within the segment of each data packet; The storage module is used to write the compressed file into the storage in a circular overwriting manner and update the file header.

[0015] In a fourth aspect, an embodiment of the present invention provides a full-flow data decompression device, comprising: An index search module, used to determine the segment ID of the compressed data segment where the target data packet is located and the offset within the segment of the target data packet according to the index file in the file header of the compressed file; A reading module, configured to read a corresponding segment header of the compressed data segment according to the segment ID of the compressed data segment, and determine the allocated memory space according to the information of the segment header; A decompression module, used for reading the compressed data segment into the allocated memory space, decompressing it, and copying the decompressed data to an uncompressed buffer; The acquisition module is used to locate the header position of the target data packet in the decompressed data according to the intra-segment offset of the target data packet, and acquire the packet header and payload of the target data packet.

[0016] In a fifth aspect, an embodiment of the present invention provides a computer-readable storage medium having a computer program / instruction stored thereon, which, when executed by a processor, implements the full-flow data storage method described above, and / or the full-flow data decompression method described above.

[0017] In a sixth aspect, an embodiment of the present invention provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the full-flow data storage method as described above, and / or the full-flow data decompression method as described above. In the seventh aspect, an embodiment of the present invention provides a computer device, including a memory, a processor, and a computer program stored in the memory. When the processor executes the computer program, it implements the full-flow data storage method as described above, and / or the full-flow data decompression method as described above. The beneficial effects of the above technical solution provided by the embodiment of the present invention include at least: The embodiment of the present invention provides a method for storing full-flow data. By copying the captured data packets into a cache queue, a message file is obtained, the storage space occupation and the complexity of subsequent processing are reduced, the integrity and order of the data are ensured, and when the message file meets the preset compression condition, the message file is divided into at least one file segment, each file segment is hierarchically compressed, a compressed file segment is generated, and then a compressed file and an index file are generated, and the compressed file is written into the memory in a circular overlay manner. Through the hierarchical compression strategy, the most suitable compression method is adopted according to the different characteristics of the data, the storage space requirement of the full-flow message is significantly reduced, the compression efficiency can be optimized, the use of storage space can be reduced, and the economy of storage can be improved. Moreover, through index construction and circular overlay storage methods, the compressed message data can be quickly retrieved and accessed, the number of disk reads and writes can be reduced, and the overall I / O performance of the system can be improved. The full-flow data storage method provided by the embodiment of the present invention solves the performance bottleneck problem of the traditional storage method in a high-flow environment, has good adaptability and flexibility, can adjust the compression strategy according to different network flows and data characteristics, can adapt to different network environments and application requirements, and provide a basis for opening or closing the compression function. It is suitable for large-scale data processing and analysis scenarios such as high-throughput network monitoring and data analysis.

[0018] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures particularly pointed out in the written description and the accompanying drawings.

[0019] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings: Figure 1 A schematic diagram of a flow chart of a full-flow data storage method provided by an embodiment of the present invention; Figure 2 A schematic diagram of the format of a compressed file provided by an embodiment of the present invention; Figure 3 A schematic diagram of a process for index construction provided by an embodiment of the present invention; Figure 4 A schematic diagram of a flow chart of a method for decompressing full-flow data provided by an embodiment of the present invention; Figure 5 A schematic diagram of the structure of a full-flow data storage device provided in an embodiment of the present application; Figure 6A schematic diagram of the structure of a full-flow data decompression device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0021] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

[0022] The inventors have found that the traditional full-flow data storage method not only occupies huge storage resources, but also encounters severe challenges in performance and storage efficiency. Especially in high-flow environments, the I / O performance and disk utilization issues of storage devices are more prominent. Traditional storage methods often find it difficult to find a balance between performance and storage efficiency when processing massive full-flow data. On the one hand, the direct storage of a large amount of original message data not only occupies a large amount of storage space, but also increases the complexity of data retrieval and processing; on the other hand, although existing compression methods, such as gzip compression methods, can reduce storage space to a certain extent, they are not ideal in terms of CPU resource usage and compression effects, and may even sacrifice the real-time processing capabilities and integrity of the data. Based on this, the inventors have made the present invention after further research and development, providing a full-flow data storage method, related methods and devices.

[0023] Embodiment 1 In the first embodiment of the present invention, a method for storing full-flow data is provided. Figure 1 As shown, the method may include the following steps S101-S107: S101: Acquire a data packet according to a set capture condition, and add a packet header to the data packet.

[0024] S102: Copy the data packets to the cache queue in the order of acquisition to obtain a message file.

[0025] S103: When the message file meets the preset compression condition, the message file is divided into at least one file segment according to a preset segment length. Each file segment includes a plurality of data packets.

[0026] S104: Determine a corresponding compression algorithm according to data characteristics of each data packet of each file segment, perform hierarchical compression on the packet header and the effective load of each data packet of the file segment, generate a compressed file segment, and add a segment header to the compressed file segment.

[0027] S105: Generate a compressed file and a corresponding version file according to each compressed file segment and the corresponding segment header. The version file includes the file header of the compressed file and the segment position information of each compressed file segment.

[0028] S106: Generate an index file according to the segment ID of each compressed file segment and the position of each data packet in the file segment and store it in the file header. The index file includes the segment ID of the compressed file segment and the offset of each data packet in the segment.

[0029] S107: Writing the compressed file into the memory in a circular overwriting manner, and updating the file header.

[0030] The embodiment of the present invention provides a method for storing full-flow data. By copying the captured data packets into a cache queue, a message file is obtained, the storage space occupation and the complexity of subsequent processing are reduced, the integrity and order of the data are ensured, and when the message file meets the preset compression condition, the message file is divided into at least one file segment, each file segment is hierarchically compressed, a compressed file segment is generated, and then a compressed file and an index file are generated, and the compressed file is written into the memory in a circular overlay manner. Through the hierarchical compression strategy, the most suitable compression method is adopted according to the different characteristics of the data, the storage space requirement of the full-flow message is significantly reduced, the compression efficiency can be optimized, the use of storage space can be reduced, and the economy of storage can be improved. Moreover, through index construction and circular overlay storage methods, the compressed message data can be quickly retrieved and accessed, the number of disk reads and writes can be reduced, and the overall I / O performance of the system can be improved. The full-flow data storage method provided by the embodiment of the present invention solves the performance bottleneck problem of the traditional storage method in a high-flow environment, has good adaptability and flexibility, can adjust the compression strategy according to different network flows and data characteristics, can adapt to different network environments and application requirements, and provide a basis for opening or closing the compression function. It is suitable for large-scale data processing and analysis scenarios such as high-throughput network monitoring and data analysis.

[0031] In an optional embodiment, in the above S101, acquiring a data packet according to a set capture condition and adding a packet header to the data packet specifically includes: S1011: Capture passing data packets according to set capture conditions through the network interface.

[0032] S1012: truncating the captured data packet according to a preset length to obtain a truncated data packet, and adding a packet header to the truncated data packet, wherein the packet header includes a timestamp, a length, a source address, and a destination address of the data packet.

[0033] The full-flow data storage method provided in the embodiment of the present invention can be implemented in a computer device serving as a server. The computer device can capture the passing data packets in real time through the network interface. According to the actual application requirements, the capture conditions of the data packets can be set to filter the data packets to be captured. For example, all data packets are captured or only data packets that meet a specific protocol or port are captured. In the embodiment of the present invention, the specific protocol, for example, can be Internet Protocol (Internet Protocol, IP), Transmission Control Protocol (Transmission Control Protocol, TCP) or User Datagram Protocol (User Datagram Protocol, UDP), Hypertext Transfer Protocol (Hypertext Transfer Protocol, HTTP), Real-time Transport Protocol (Real-time Transport Protocol, RTP) and Real-time Streaming Protocol (Real Time Streaming Protocol, RTSP), etc., and the port can be, for example, an IP port, a TCP port or a UDP port.

[0034] In the embodiment of the present invention, the captured data packets can be truncated according to a preset length to obtain truncated data packets to simulate the standard size of Ethernet frames. The preset length can be, for example, 1500 bytes. Subsequently, a custom packet header is added to each truncated data packet, and the header information of the packet header includes but is not limited to metadata such as the timestamp of the data packet, the length of the data packet, the source address and the destination address.

[0035] In an optional embodiment, in the full-flow data storage method, after obtaining the above-mentioned data packet in real time, the data packet (i.e. the above-mentioned truncated data packet and the corresponding packet header) can be copied to the cache queue in the acquisition order based on the above-mentioned step S102 to obtain a message file.

[0036] Furthermore, during the data packet caching process, it is possible to determine whether the message file meets the preset compression condition in the following manner: It is determined whether the data volume of the message file reaches a preset data volume threshold value. The preset data volume threshold value can be set according to actual application requirements, for example, it can be 1GB or 512MB.

[0037] If the data volume of the message file has not reached the preset data volume threshold, the data packets continue to be captured for buffering and added to the message file.

[0038] If the data volume of the message file reaches the preset data volume threshold, the step of compressing the message file can be performed. After that, return to the above step S101 to re-execute the data packet capture and cache process until it is determined that the data volume of the next message file reaches the preset data volume threshold and meets the compression condition.

[0039] In other embodiments, during the data packet caching process, it is also possible to determine whether the message file meets the preset compression condition in the following manner: It is determined whether the cache time of the message file reaches a preset time threshold. The preset time threshold can be set according to actual application requirements, such as 30 seconds or 1 minute.

[0040] If the cache time of the message file has not reached the preset time threshold, the data packets continue to be captured for caching and added to the message file.

[0041] If the cache time of the message file reaches the preset time threshold, the step of compressing the message file can be performed. After that, return to the above step S101 to re-execute the data packet capture and cache process until the cache time of the next message file reaches the preset time threshold and meets the compression condition.

[0042] In the embodiment of the present invention, the cache time is the time interval from the cache time of the earliest cached data packet in the message file to the current time.

[0043] Of course, in some other embodiments, it may be that the data volume of the message file reaches a preset data volume threshold, and the cache time of the message file reaches the preset time threshold, only then is it determined that the message file meets the compression condition, and the step of compressing the message file can be executed.

[0044] In the embodiment of the present invention, after determining that the data volume of the message file in the cache queue reaches the preset data volume threshold or meets the preset time threshold, the message file is subsequently compressed and the data is written into the memory, rather than starting to write into the memory after the session ends. This is conducive to the real-time processing of network traffic data, ensuring that data can be quickly compressed and stored, and can be applied to application scenarios that require fast response. By centrally processing data packets containing a certain amount, storage space can be saved, data writing operations can be reduced, frequent data writing can be avoided, and the I / O performance of the memory can be improved.

[0045] In an optional embodiment, in the above step S103, when the message file meets the preset compression condition, segmenting the message file into at least one file segment according to a preset segment length may specifically include: When the message file meets the preset compression condition, the message file is divided into at least one file segment according to the data volume of the message file and the preset segment length. In an embodiment of the present invention, the preset segment length can be set according to actual application requirements, for example, it can be set to 128M or 200M. The smaller the preset segment length is set, the more file segments will be divided. Of course, the larger the data volume of the message file, the more file segments will be divided. When dividing the message file, the division can be carried out in sequence according to the cache time of the data packets in the message file to ensure that the data volume of each file segment except the last file segment is uniform.

[0046] In the embodiment of the present invention, the segmented processing strategy is used to help manage and control the scale of the compression operation, making the compression task more efficient and controllable.

[0047] In an optional embodiment, in the above step S104, determining a corresponding compression algorithm to perform hierarchical compression on the packet header and the payload of each data packet of the file segment according to the data characteristics of each data packet of the file segment to generate a compressed file segment, and adding a segment header to the compressed file segment may specifically include: S1041: Determine a corresponding compression algorithm according to data characteristics of the packet header of each data packet of each file segment to compress the packet header of each data packet of the file segment to generate a compressed packet header; S1042: Determine a corresponding compression algorithm according to data characteristics of message contents of each data packet of each file segment to compress the payload of each data packet of the file segment to generate compressed message data; S1043: Obtain a compressed data packet according to each compressed packet header and the corresponding compressed message data, and generate a compressed file segment; S1044: Add a segment header to the compressed file segment; the segment header includes the segment ID of the compressed file segment, the compression algorithm used, the length of the compressed data, and the uncompressed length of the original data.

[0048] In the embodiment of the present invention, the data characteristics of the above data packets may be the characteristics of repetitive patterns, predictable changes or statistical regularities contained in the characteristic fields in the packet header and payload of the data packet. For example, the length of the payload in the data packet, the content in the payload, the message length, the arrival timestamp of the message, the time interval between adjacent messages in multiple data packets, etc. Different compression algorithms are applied according to the data characteristics of each part of the data packet to achieve the overall optimal compression effect.

[0049] The full-flow data storage method provided by the embodiment of the present invention adopts a hierarchical compression strategy to compress the file segment, and realizes efficient compression and storage of the full-flow data under the premise of ensuring data integrity. The most suitable compression method can be selected according to the specific characteristics of the data, thereby improving the compression efficiency and processing speed. First, the header of each data packet is compressed to reduce the volume of the compressed file segment, and then, according to the data characteristics of the message content of the data packet, the most suitable compression algorithm is selected to further compress the effective load. In this way, the storage space requirement of the full-flow message can be significantly reduced, and the overall compression efficiency can be improved to achieve the overall optimal compression effect. When compressing data, a suitable compression algorithm is selected according to the data characteristics of the packet header and the message content of the data packet, and compression is performed at a finer granularity, such as for a single data packet or a specific field of a data packet, rather than the entire data stream or a large data block, with good adaptability and flexibility. Therefore, the compression strategy can be adaptively adjusted for different network traffic and data, and the real-time performance of data processing can be improved, which can be applicable to the compression and storage of traffic data with changing data characteristics. For the compressed data, that is, the compressed file segment, ensure that its length does not exceed the above preset segment length limit to ensure data integrity and compression efficiency, and improve storage efficiency and storage I / O performance.

[0050] The above compression algorithms include but are not limited to the following compression algorithms: LSB encoding, W-LSB encoding, RTP timestamp encoding, IP-ID offset encoding, DCT (discrete cosine transform) based compression algorithm, LPC (linear predictive coding) based compression algorithm, snappy compression algorithm and gzip compression algorithm. In the embodiment of the present invention, no limitation is made.

[0051] In a specific embodiment, the data characteristics of the message content of the data packet include redundant information; The step of determining, according to the data characteristics of the message content of each data packet of each file segment, a corresponding compression algorithm to compress the effective load of each data packet of the file segment to generate compressed message data comprises: Determine whether the type of redundant information present in the message content of each data packet of each file segment is a static field, a semi-static field or a variable field; According to the type of redundant information existing in the message content of each data packet of the file segment, a corresponding compression algorithm is determined, and the effective load of each data packet of the file segment is compressed to generate compressed message data.

[0052] In an embodiment of the present invention, by making full use of the redundant information present in the message and selecting a suitable compression algorithm, the amount of data required for storage can be reduced. For example, by identifying the static fields in the messages of the same type, a static dictionary can be used to compress the static fields, and the storage or transmission of these unchanged data multiple times can be avoided. By identifying the semi-static fields with a very low frequency of change in the messages of the same type, incremental updates can be performed by, for example, W-LSB encoding instead of transmitting the complete information of the entire field each time. By identifying the changing fields in the messages of the same type, an encoding method such as differential encoding or Protobuf is used for these changing fields, and only the changing parts are stored instead of the complete information of the entire field.

[0053] In a specific embodiment, when compressing the file segment, the full-flow data storage method may further include the following steps: If the data type of the message content of each data packet of each file segment is a preset data type that is easy to compress, a packet-by-packet compression strategy is adopted according to a determined compression algorithm to compress the payload of each data packet of the file segment to generate compressed message data.

[0054] In the embodiment of the present invention, the preset data type that is easy to compress may be, for example, HTTP data, video stream data or voice data, and a specific compression algorithm may be applied, and a packet-by-packet compression strategy may be adopted to improve compression efficiency. For example, video data may use a compression algorithm based on DCT (discrete cosine transform), and voice data may use a compression algorithm based on LPC (linear predictive coding), or the snappy compression algorithm or the gzip compression algorithm may be used to compress HTTP data, video stream data or voice data.

[0055] In a specific embodiment, when compressing the file segment, the full-flow data storage method may further include the following steps: According to the data characteristics of the message content of each data packet of each file segment, determine whether there is data with the same characteristics in each data packet. If so, use a determined compression algorithm to compress the first data with the same characteristics to obtain compressed message data, and use metadata indexes to reference the compressed message data for other data with the same characteristics.

[0056] In an embodiment of the present invention, repeated data is referenced by using metadata indexes instead of repeatedly storing the same data, which can significantly reduce data storage space. For data packets with the same characteristic fields in a file segment, only the original field of the first characteristic field is compressed during compression, and for subsequent data packets, metadata indexes can be used to retain only index data to save storage space. For example, if the packet headers of the first and second data packets in a file segment contain fields with the same characteristics, the original field of the field with the same characteristics is saved for the first compressed data packet, and the original field is not saved in the second compressed data packet. Instead, only an index is saved, which is referenced to the packet header of the first compressed data packet.

[0057] In an optional embodiment, in the above step S105, generating a compressed file and a corresponding version file according to each compressed file segment and the corresponding segment header specifically includes: S1051: Generate a compressed file and a file header from each compressed file segment and a corresponding segment header according to the order of the compressed file segments; S1052: Create a version file and add the file header of the compressed file and the segment position information of each compressed file segment, wherein the segment position information records the segment ID of each compressed file segment and the offset position of each compressed file segment in the compressed file.

[0058] In the embodiment of the present invention, the version file is a metadata file, which includes a file header and segment location information of each compressed file segment. The file header records the file version information, status, start and end time, file name prefix, file name, ID of the last written file compression segment, and the location where the current file is written.

[0059] In a specific embodiment, referring to Figure 2 As shown, it is a schematic diagram of the format of a compressed file, which includes a file header (i.e., the Spcap file header in the figure) and n+1 compressed file segments (i.e., compressed segment 0, ..., compressed segment n in the figure), wherein each compressed file segment includes a segment header and compressed data, and the compressed data of each compressed file segment is obtained by hierarchically compressing the packet header and the payload (i.e., the Ethernet frame in the figure) of each data packet of the file segment.

[0060] In an optional embodiment, in the above step S106, generating an index file according to the segment ID of each compressed file segment and the position of each data packet in the file segment and storing it in the file header specifically includes: S1061: Obtain the segment header of each compressed file segment, and extract the segment ID of each compressed file segment; S1062: Determine the data packet to be indexed and the position of the data packet in the file segment according to the pre-configured feature rule; S1063: According to the segment ID of each compressed file segment and the position of each data packet to be indexed in the file segment, call the index thread, generate an index file, and store the index file in the file header; the index file includes the segment ID of the compressed file segment and the intra-segment offset of each data packet to be indexed in the file segment.

[0061] In an embodiment of the present invention, when a compressed file is generated, segment location information of the compressed file segment is added to the version file, and when an index is created, an index of the data packet is established, thereby reducing the number of indexes and the storage space occupied by the index. This method is suitable for scenarios where a large number of original messages are processed in a high-traffic environment, and reduces the complexity of index search.

[0062] In the embodiment of the present invention, refer to Figure 3 In the flowchart of index construction shown, each compressed file can include multiple compressed file segments. First, the segment header of each compressed file segment is obtained, multiple index data are obtained, and the segment ID of each compressed file segment is extracted. Then, according to the pre-configured protocol or rule characteristics, such as the characteristics of the communication protocol, quintuple or payload, the stored data packets are determined, the data packets to be indexed and the positions of the data packets in the file segment are determined, and the offset of the data packets from the header of the file segment, that is, the offset within the segment, is obtained; then, the index thread is called to generate an index file, and the index file includes the segment ID of the compressed file segment and the segment offset of each data packet to be indexed in the file segment.

[0063] In an embodiment of the present invention, when creating an index file, an index can be created based on the different parts and features of each data packet in the compressed file segment. For example, if the compressed file segment includes 10 data packets with different features, 10 index files are generated; if the compressed file segment includes 10 data packets that reuse the same features, only an index file of the original field of the first data packet is established, and the indexes of other data packets reuse this index file, and the corresponding data is found through different offsets to achieve further compression of the space.

[0064] In an embodiment of the present invention, by using segment ID and intra-segment offset as index information, the segment ID points to the segment position information stored in the version file, and the intra-segment offset indicates the precise position of the data packet in the specific segment. The separate storage strategy of segment ID and intra-segment offset makes it possible to quickly locate a specific data packet even in the case of a large amount of data, supporting an efficient random access mode.

[0065] In an optional embodiment, the memory includes a plurality of storage spaces for sequentially arranged original message files; the file size of the original message file is a preset storage capacity value; In the above step S107, writing the compressed file into the memory in a circular overwriting manner and updating the file header specifically includes: S1071: sequentially searching whether the storage space of each original message file in the memory reaches a preset storage capacity value, if not, executing step S1072, if yes, executing step S1073; S1072: writing the compressed file into the free storage space of the original message file that comes before in the order, and updating the file header; S1073: According to the time sequence of data writing in the storage space of each original message file, the earliest written data is overwritten with the compressed file, and the file header is updated; the information of the file header includes the file version information, status, start time, end time, file name prefix, file name, segment ID of the last compressed file segment and the write position of the compressed file.

[0066] In the embodiment of the present invention, when storing a compressed file, a directio function can be called to write the compressed file into the memory in a directio manner. This writing method can significantly reduce file system operations and improve I / O performance.

[0067] In an embodiment of the present invention, the memory may refer to a disk. In order to further improve storage efficiency, the file size of the original message storage may be pre-set before executing the method, and may be set to a larger fixed value, such as 128GB, 256GB or 512GB. When allocating disk space, sufficient space is allocated in advance for each file stored in the original message. When the disk space reaches the upper limit, the old data may be cyclically overwritten. By overwriting data, compared with the conventional writing method of creating a new file and deleting the previous file, frequent file deletion and addition operations are avoided, and the number of disk read and write times is reduced.

[0068] In the embodiment of the present invention, since the compressed files are stored in a circular overwriting manner, in order to further improve the query efficiency and reduce the storage space, the index construction process of the above step S106 may further include: Within a specific time range or a specified number of compressed files (message storage blocks), determine whether the content of the original message corresponding to the data packet (hereinafter referred to as the current data packet) that currently needs to create an index has been indexed. If so, the existing index will be compared when creating the index. If the index information (such as hash value) created by the current data packet is consistent with the index information in the existing index file, the index file will not be recreated, but the existing index file will be referenced and the annotation time of the existing index file will be updated.

[0069] In the embodiment of the present invention, the above-mentioned specific time range can be set according to actual application requirements, such as being set to a data packet within a time range of 5 minutes before. The above-mentioned specified number of compressed files can also be further set according to actual application requirements, such as being set to 5 adjacent compressed files stored before, and each compressed file can include multiple data packets.

[0070] In the embodiment of the present invention, the size and complexity of the index can be further reduced by index reuse, and the storage of duplicate indexes can be avoided, thereby saving storage space. In addition, it is helpful to quickly locate the index record during query, and the update and management of the index becomes simpler and more efficient, reducing the maintenance cost. The efficiency of data storage and query can be significantly improved, while reducing unnecessary resource consumption.

[0071] In the embodiment of the present invention, after the compressed file is written into the memory, referring to Figure 4 As shown, the data in the compressed file can also be decompressed and backtracked in the following manner. Specifically, the following steps S201-S204 may be included: S201: Determine the segment ID of the compressed data segment where the target data packet is located and the offset within the segment of the target data packet according to the index file in the file header of the compressed file; S202: Reading a corresponding segment header of the compressed data segment according to the segment ID of the compressed data segment, and determining an allocated memory space according to information of the segment header; S203: reading the compressed data segment into the allocated memory space, decompressing it, and copying the decompressed data to an uncompressed buffer; S204: According to the intra-segment offset of the target data packet, locate the header position of the target data packet in the decompressed data, and obtain the packet header and payload of the target data packet.

[0072] The file header of the compressed file stores the index file and compressed data corresponding to each compressed file segment in the compressed file. Through the index file, a specific data packet can be quickly located, and accurate access to the target data packet is achieved, which reduces the time cost of data retrieval. When decompressing, only the target data that needs to be analyzed needs to be decompressed, avoiding unnecessary resource consumption, reflecting a high degree of flexibility and efficiency. The entire process is carefully designed to ensure accurate data tracing and efficient processing.

[0073] Embodiment 2 Based on the same inventive concept, the embodiment of the present invention also provides a full flow data decompression method, referring to Figure 4 As shown, the method may include the following steps S201-S204: S201: Determine the segment ID of the compressed data segment where the target data packet is located and the offset within the segment of the target data packet according to the index file in the file header of the compressed file; S202: Reading a corresponding segment header of the compressed data segment according to the segment ID of the compressed data segment, and determining an allocated memory space according to information of the segment header; S203: reading the compressed data segment into the allocated memory space, decompressing it, and copying the decompressed data to an uncompressed buffer; S204: According to the intra-segment offset of the target data packet, locate the header position of the target data packet in the decompressed data, and obtain the packet header and payload of the target data packet.

[0074] In the full-flow data decompression method provided by the embodiment of the present invention, the compressed file in the above step S201 is a compressed file obtained and stored by the full-flow data storage method described in the above embodiment 1, and the file header of the compressed file stores the index file and compressed data corresponding to each compressed file segment in the compressed file. The specific implementation method can refer to the detailed description of the above embodiment 1, which will not be repeated here.

[0075] Embodiment 3 Based on the same inventive concept, the embodiment of the present invention also provides a full-flow data storage device, referring to Figure 5 As shown, the device comprises: The capture module 101 is used to obtain a data packet according to a set capture condition and add a packet header to the data packet; The cache module 102 is used to copy the data packets into the cache queue according to the acquisition order to obtain the message file; The segmentation module 103 is used to segment the message file into at least one file segment according to a preset segment length when the message file meets the preset compression condition; each file segment includes a plurality of data packets; The compression module 104 is used to determine the corresponding compression algorithm according to the data characteristics of each data packet of each file segment, perform hierarchical compression on the packet header and the effective load of each data packet of the file segment, generate a compressed file segment, and add a segment header to the compressed file segment; A generating module 105, configured to generate a compressed file and a corresponding version file according to each compressed file segment and the corresponding segment header; the version file includes the file header of the compressed file and the segment position information of each compressed file segment; An index module 106, configured to generate an index file according to the segment ID of each compressed file segment and the position of each data packet in the file segment and store the index file in the file header; the index file includes the segment ID of the compressed file segment and the offset of each data packet in the segment; The storage module 107 is used to write the compressed file into the memory in a circular overwriting manner and update the file header.

[0076] Embodiment 4 Based on the same inventive concept, the embodiment of the present invention also provides a full flow data decompression device, referring to Figure 6 As shown, the device comprises: An index search module 201, used to determine the segment ID of the compressed data segment where the target data packet is located and the offset within the segment of the target data packet according to the index file in the file header of the compressed file; A reading module 202, configured to read a corresponding segment header of the compressed data segment according to the segment ID of the compressed data segment, and determine the allocated memory space according to the information of the segment header; A decompression module 203 is used to read the compressed data segment into the allocated memory space, decompress it, and copy the decompressed data to an uncompressed buffer; The acquisition module 204 is used to locate the header position of the target data packet in the decompressed data according to the intra-segment offset of the target data packet, and acquire the packet header and payload of the target data packet.

[0077] Embodiment 5 Based on the same inventive concept, an embodiment of the present invention also provides a computer-readable storage medium on which a computer program / instruction is stored. When the computer program / instruction is executed by a processor, it implements the full-flow data storage method described in the above embodiment one, and / or the full-flow data decompression method described in the above embodiment two.

[0078] Embodiment 6 Based on the same inventive concept, an embodiment of the present invention also provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the full-flow data storage method described in the above-mentioned embodiment 1, and / or the full-flow data decompression method described in the above-mentioned embodiment 2.

[0079] Embodiment 7 Based on the same inventive concept, an embodiment of the present invention also provides a computer device, including a memory, a processor and a computer program stored in the memory. When the processor executes the computer program, it implements the full-flow data storage method described in the above embodiment one, and / or the full-flow data decompression method described in the above embodiment two.

[0080] It should be understood by those skilled in the art that the embodiments of the present invention may be provided as methods, systems or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment or an embodiment combining software and hardware aspects. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) containing computer-usable program codes.

[0081] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems) and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the process in the flowchart. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0082] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0083] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0084] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A method for storing full-flow data, characterized in that: include: Acquire a data packet according to the set capture conditions, and add a packet header to the data packet; Copy the data packets to the cache queue in the order of acquisition to obtain the message file; When the message file meets the preset compression condition, the message file is divided into at least one file segment according to the preset segment length; each of the file segments includes a plurality of data packets; According to the data characteristics of each data packet of each file segment, determine the corresponding compression algorithm to perform hierarchical compression on the packet header and the effective load of each data packet of the file segment to generate a compressed file segment, and add a segment header to the compressed file segment; Generate a compressed file and a corresponding version file according to each compressed file segment and the corresponding segment header; the version file includes the file header of the compressed file and the segment position information of each compressed file segment; Generate an index file according to the segment ID of each compressed file segment and the position of each data packet in the file segment and store it in the file header; the index file includes the segment ID of the compressed file segment and the offset within the segment of each data packet; The compressed file is written into the memory in a circular overwriting manner, and the file header is updated.

2. The method according to claim 1, characterized in that The step of determining, according to the data characteristics of each data packet of each file segment, a corresponding compression algorithm to perform hierarchical compression on the packet header and the effective load of each data packet of the file segment to generate a compressed file segment, and adding a segment header to the compressed file segment comprises: Determine a corresponding compression algorithm to compress the header of each data packet of each file segment according to data characteristics of the header of each data packet of each file segment, and generate a compressed header; Determine a corresponding compression algorithm to compress the payload of each data packet of each file segment according to the data characteristics of the message content of each data packet of each file segment to generate compressed message data; Obtain a compressed data packet according to each compressed packet header and the corresponding compressed message data, and generate a compressed file segment; A segment header is added to the compressed file segment; the segment header includes a segment ID of the compressed file segment, a compression algorithm used, a length of the compressed data, and an uncompressed length of the original data.

3. The method according to claim 2, characterized in that Data characteristics of the message content of the data packet, including redundant information; The step of determining, according to the data characteristics of the message content of each data packet of each file segment, a corresponding compression algorithm to compress the effective load of each data packet of the file segment to generate compressed message data comprises: Determine whether the type of redundant information present in the message content of each data packet of each file segment is a static field, a semi-static field or a variable field; According to the type of redundant information existing in the message content of each data packet of the file segment, a corresponding compression algorithm is determined, and the effective load of each data packet of the file segment is compressed to generate compressed message data.

4. The method according to claim 3, characterized in that Also includes: If the data type of the message content of each data packet of each file segment is a preset data type that is easy to compress, a packet-by-packet compression strategy is adopted according to a determined compression algorithm to compress the payload of each data packet of the file segment to generate compressed message data.

5. The method according to claim 3, characterized in that: Also includes: According to the data characteristics of the message content of each data packet of each file segment, determine whether there is data with the same characteristics in each data packet. If so, use a determined compression algorithm to compress the first data with the same characteristics to obtain compressed message data, and use metadata indexes to reference the compressed message data for other data with the same characteristics.

6. The method according to claim 1, characterized in that The step of generating an index file according to the segment ID of each compressed file segment and the position of each data packet in the file segment and storing the index file in the file header comprises: Obtaining the segment header of each compressed file segment, and extracting the segment ID of each compressed file segment; Determine the data packet to be indexed and the position of the data packet in the file segment according to the pre-configured feature rule; According to the segment ID of each compressed file segment and the position of each data packet to be indexed in the file segment, the index thread is called to generate an index file, and the index file is stored in the file header; the index file includes the segment ID of the compressed file segment and the intra-segment offset of each data packet to be indexed in the file segment.

7. The method according to claim 1, characterized in that The step of acquiring a data packet according to the set capture condition and adding a packet header to the data packet includes: Capture passing data packets through the network interface according to the set capture conditions; The captured data packet is truncated according to a preset length to obtain a truncated data packet, and a packet header is added to the truncated data packet; the packet header includes a timestamp of the data packet, a data packet length, a source address and a destination address.

8. The method according to claim 1, characterized in that Also includes: Determine whether the message file meets the preset compression condition by the following method: Determine whether the data volume of the message file reaches a preset data volume threshold; and / or, Determine whether the cache time of the message file reaches a preset time threshold; wherein the cache time is the time interval from the cache time of the earliest cached data packet in the message file to the current time.

9. The method according to any one of claims 1 to 8, characterized in that: The memory includes a storage space for a plurality of original message files arranged in sequence; the file size of the original message file is a preset storage capacity value; The step of writing the compressed file into the memory in a circular overwriting manner and updating the file header comprises: Searching in order whether the storage space of each original message file in the memory reaches a preset storage capacity value; If not, writing the compressed file into the free storage space of the original message file preceding in the order, and updating the file header; If so, the earliest written data is overwritten by the compressed file in the order of the time when the data is written in the storage space of each original message file, and the file header is updated; the information in the file header includes the file's version information, status, start time, end time, file name prefix, file name, segment ID of the last compressed file segment, and the write position of the compressed file.

10. A method for decompressing full-flow data, characterized in that: include: Determine the segment ID of the compressed data segment where the target data packet is located and the offset within the segment of the target data packet according to the index file in the file header of the compressed file; Reading a corresponding segment header of the compressed data segment according to the segment ID of the compressed data segment, and determining the allocated memory space according to the information of the segment header; Reading the compressed data segment into the allocated memory space, decompressing it, and copying the decompressed data to an uncompressed buffer; According to the intra-segment offset of the target data packet, the header position of the target data packet is located in the decompressed data, and the packet header and the effective load of the target data packet are obtained.

11. A full-flow data storage device, characterized in that: include: A capture module, used to acquire data packets according to set capture conditions and add a packet header to the data packets; A cache module is used to copy the data packets into the cache queue in the acquisition order to obtain the message file; A segmentation module, used for segmenting the message file into at least one file segment according to a preset segment length when the message file meets a preset compression condition; each of the file segments includes a plurality of data packets; A compression module, for determining a corresponding compression algorithm according to data characteristics of each data packet of each file segment, performing hierarchical compression on the packet header and the effective load of each data packet of the file segment, generating a compressed file segment, and adding a segment header to the compressed file segment; A generation module, used to generate a compressed file and a corresponding version file according to each compressed file segment and the corresponding segment header; the version file includes the file header of the compressed file and the segment position information of each compressed file segment; An index module, used to generate an index file according to the segment ID of each compressed file segment and the position of each data packet in the file segment and store it in the file header; the index file includes the segment ID of the compressed file segment and the offset within the segment of each data packet; The storage module is used to write the compressed file into the storage in a circular overwriting manner and update the file header.

12. A full-flow data decompression device, characterized in that: include: An index search module, used to determine the segment ID of the compressed data segment where the target data packet is located and the offset within the segment of the target data packet according to the index file in the file header of the compressed file; A reading module, configured to read a corresponding segment header of the compressed data segment according to the segment ID of the compressed data segment, and determine the allocated memory space according to the information of the segment header; A decompression module, used for reading the compressed data segment into the allocated memory space, decompressing it, and copying the decompressed data to an uncompressed buffer; The acquisition module is used to locate the header position of the target data packet in the decompressed data according to the intra-segment offset of the target data packet, and acquire the packet header and payload of the target data packet.

13. A computer-readable storage medium having a computer program / instruction stored thereon, characterized in that: When the computer program / instruction is executed by a processor, it implements the full-flow data storage method as described in any one of claims 1 to 9, and / or the full-flow data decompression method as described in claim 10.

14. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instruction is executed by a processor, it implements the full-flow data storage method as described in any one of claims 1 to 9, and / or the full-flow data decompression method as described in claim 10.

15. A computer device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the full-flow data storage method as described in any one of claims 1-9, and / or the full-flow data decompression method as described in claim 10.

Citation Information

Patent Citations

  • Method for high-security network data storage

    CN105516204A

  • Distributed network traffic retrieval method and device

    CN113672629A

  • Index creation method and device, equipment and storage medium

    CN114676133A

  • Network traffic retrieval method and device, equipment and storage medium

    CN115858462A

  • Method and apparatus for storage and signaling of compressed point clouds

    EP3745354A1

Cited By

  • Message storage method and device and electronic equipment

    CN120835100A

  • ZSTD data packet retrieval method and device, equipment and medium

    CN121486247A

  • A ZSTD data packet retrieval method, device, equipment and medium

    CN121486247B