WO2022222523A1 - Log management method and apparatus - Google Patents

Log management method and apparatus Download PDF

Info

Publication number
WO2022222523A1
WO2022222523A1 PCT/CN2021/140172 CN2021140172W WO2022222523A1 WO 2022222523 A1 WO2022222523 A1 WO 2022222523A1 CN 2021140172 W CN2021140172 W CN 2021140172W WO 2022222523 A1 WO2022222523 A1 WO 2022222523A1
Authority
WO
WIPO (PCT)
Prior art keywords
log
segment
lsn
index
entry
Prior art date
Application number
PCT/CN2021/140172
Other languages
French (fr)
Chinese (zh)
Inventor
舒继武
汪庆
陈佩
王硕
陆游游
姚建业
赵玥
Original Assignee
华为技术有限公司
清华大学
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司, 清华大学 filed Critical 华为技术有限公司
Publication of WO2022222523A1 publication Critical patent/WO2022222523A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/13File access structures, e.g. distributed indices
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/1805Append-only file systems, e.g. using logs or journals to store data
    • G06F16/1815Journaling file systems

Definitions

  • the present application relates to the field of data storage, and in particular, to a log management method and device.
  • WAL Write ahead log
  • the server Before the server writes business data to the storage device, it will be recorded in the WAL.
  • the server writes multiple logs to the storage device by means of append writing, and the storage device saves the logs in the form of log files, wherein each log file includes a fixed number of log entries .
  • the server needs to lock the log file to which the new log entry is to be written, resulting in a slow log writing speed. Therefore, how to improve the efficiency of log writing has become an urgent problem to be solved at present.
  • the present application provides a log management method and device, which solves the problem of slow log writing speed caused by the server writing logs with log files as granularity.
  • the present application provides a log management method, and the method can be applied to a processor, or the method can be applied to a communication device that can support a processor to implement the method, for example, the communication device includes a chip system, and the log management
  • the method includes: first, the processor divides the storage space of the hard disk into a plurality of segments, one segment includes one or more physical blocks (blocks), and the one segment is used to store logs; secondly, the processor receives a first log write request and a second log write request, the first log write request includes a first log entry, and the second log write request includes a second log entry; finally, the processor writes the first log entry into the first log entry in the plurality of segments in parallel segment, and write the second log entry to the first segment.
  • the hard disk manages logs based on segments, which avoids the hard disk from storing logs in the form of log files, reduces the overhead of file locks in the log writing process, and improves the The efficiency of log writing is improved; in addition, multiple log items can be written to a segment in parallel, avoiding the locking process required to write log items in the log file, and improving the parallel writing of logs to the hard disk. efficiency.
  • the log in this embodiment of the present application refers to business data, or a copy, snapshot, or clone of the business data.
  • the processor does not perform a locking mechanism in the process of writing the first log entry into the first segment or during the process of writing the second log entry into the first segment.
  • the log management method does not implement a locking mechanism on the hard disk because the processor does not.
  • the processor can write the first log item and the second log item to the first segment of the hard disk in parallel, which improves the efficiency of the processor writing multiple log items to the hard disk in parallel.
  • the log management method further includes: the processor matches the log sequence number LSN of the first log write request with the log index, and determines that the first log entry included in the first log write request is to be written
  • the paragraph is the first paragraph.
  • the log index is used to indicate the correspondence between the first segment and the LSN.
  • the processor matches the LSN of the log write request with the log index, and determines the segment to be written in the log entry included in the log write request, which reduces the path query time required for log writing and improves the efficiency of log writing.
  • the log index includes a first index and a second index
  • the first index is used to indicate the storage address range of the first segment in the hard disk
  • the second index is used for each of the at least one storage address range The correspondence between the LSN of the log entry and the storage address.
  • the process that the above-mentioned processor matches the LSN and the log index to determine the first segment may include: the processor determines whether the LSN of the LSN and the third log item are continuous, and the third log item is any log item recorded by the second index; It is continuous with the LSN of the third log entry, and the processor uses the segment where the third log entry is located as the first segment; if the LSN is not continuous with the LSN of the third log entry, the processor matches the LSN with the first index to determine the first segment. , the LSN of the first log entry in the first segment matches the LSN of the first log write request. Since the storage capacity of the cache of the processor is small, a large amount of index data cannot be stored in the cache.
  • the log index includes a first index and a second index. Any one of the first index and the second index is preferentially matched. If the match is successful, the processor can be prevented from searching for all data in the log index, the path query time required for log writing is reduced, and the log writing efficiency is improved.
  • the processor may also first match the LSN of the log read request with the second index. If the match is successful (hit), the processor may determine the log to be read by the log read request according to the second index The storage address where the item is located reduces the path query time required for log reading and improves the efficiency of log reading. If the LSN of the log read request is not hit in the second index, the processor can determine the log segment to be read by the log read request according to the first index, and obtain the log entry corresponding to the read log request by traversing the log segment, avoiding processing The server will query the storage address of the log read request in the file system, which improves the efficiency of log reading.
  • the log index is stored in the cache.
  • the cache may be the internal memory of the processor.
  • the processing unit in the processor can read the log index in the cache, so as to quickly determine the segment to be written in the log entry included in the log write request, and reduce the path query time required for log writing. The efficiency of log writing is improved.
  • the first log entry includes description information and data information
  • the description information includes the LSN of the first log write request, the length of the log entry, and the checksum of the length of the log entry
  • the data information is used to indicate the first log The log content recorded by the item.
  • the log entry length checksum is used to determine the integrity and accuracy of the first log entry
  • the log entry length is used to determine the size of the storage space occupied by the first log entry
  • the LSN is used to indicate the log of the first log write request Add the sequence number of the operation.
  • the description information included in the first log entry may also be referred to as metadata information of the first log entry.
  • the process in which the processor writes the first log entry into the first segment includes: the processor generates a starting storage address according to the LSN of the first log write request, and the starting storage address is in the first log entry. The storage address range of the segment; further, the processor writes the first log entry into the first segment according to the starting storage address.
  • the processor first generates the initial storage address according to the LSN of the log write request, and then writes the log items included in the log write request to the hard disk according to the initial storage address. The log entries are written to the hard disk to ensure the accuracy of log writing.
  • the log management method further includes: the processor sends the LSN and the start address of the first log write request to the backup device storage address.
  • the processor is the master replica node (referred to as: master node)
  • the master node sends the LSN and starting storage address of the log write request to the slave replica node (referred to as: slave node)
  • slave node writes the log items included in the log write request into the first segment according to the LSN and the starting storage address of the log write request, avoiding the need for the master node to go to the slave node for backup after the log writing is completed. Write efficiency for multi-write scenarios.
  • the log management method further includes: the processor receives the LSN and the starting storage address of the first log write request sent by the backup device, and according to the first log write request Once the LSN and starting storage address of the log request are written, the first log entry is written into the first segment.
  • the processor is a slave node, after receiving the log write request sent by the client, the processor can also receive the LSN and the log write request sent by the backup device (master node). The starting storage address, and the processor (slave node) writes the log items included in the log writing request into the first segment according to the LSN and starting storage address of the log write request, avoiding the completion of log writing on the master node. Then go to the slave node for backup, which improves the writing efficiency of multi-write scenarios.
  • the log management method further includes: the processor sends a log write response to the client, where the log write response is used to indicate that the first log and the second log have been written to the first segment.
  • the client can determine that the current round of log addition operation has been completed according to the log write response fed back by the processor, so as to avoid the client from repeatedly sending log write requests to the log system, resulting in repeated backups of log write requests and saving the storage resources of the log system. Improve the storage resource utilization of the log system.
  • the processor writes the first log entry into the first segment, including: when the remaining storage space of the first segment is less than the log entry length of the first log write request, the processor writes the first log entry into the first segment.
  • One part of the log write request is written into the first segment, and another part of the first log write request is written into the second segment, and the second segment is the segment in the hard disk that has an association relationship with the first segment that is continuously read;
  • the processor sets the log tail address in the hard disk as the start storage address of the first log entry in the second segment.
  • the log tail address is represented by the starting storage address of the log entry at the segment head of the log segment where the last log is located.
  • the log needs to be updated
  • the starting storage address of the log segment where the tail is located In this way, the log tail address can be represented by the starting storage address of the log segment where the log tail is located, which avoids the need to update the log tail address every time a log is added in the file system, and reduces the randomness of the log tail address required for log addition. Lowercase operations improve the efficiency of log writing.
  • the log management method before the processor generates the starting storage address according to the LSN of the log write request, the log management method further includes: the processor determines whether the length of the log entry of the log write request is less than or equal to the log read length of the hard disk.
  • Write unit the log read/write unit of the hard disk refers to the minimum data granularity of the log entries in the hard disk read and written by the processor.
  • the processor performs the step of generating the starting storage address according to the LSN of the log write request; if the log entry length of the log write request is greater than the log read/write unit of the hard disk unit, the processor divides the log write request into multiple sub-logs, and the log entry length of each sub-log in the multiple sub-logs is the same as the log read-write unit. Finally, the processor generates a starting storage address of each sub-log in the multiple sub-logs according to the LSN of the log write request.
  • the processor can write multiple sub-logs according to the log read/write unit of the hard disk, even when the processor directly writes the log entry included in the log write request When the medium hard disk and the processor are powered off, the sub-logs that have been written to the hard disk by the processor will not be repeatedly written (or read) by the processor, which reduces the storage resource consumption of the hard disk and improves the storage resource utilization efficiency of the hard disk.
  • the processor may split the log items to be written included in the log write request according to the log read/write unit of the hard disk, and further, the processor atomically generates the starting storage address of each sub-log, because The processor reads and writes logs based on the granularity of log segments that do not use the file system. Therefore, the processor does not need to lock the log segments, thus realizing the process of the processor adding and writing to the hard disk in parallel, reducing the time required for log writing and improving the efficiency of log writing.
  • the present application provides a log management device, and the beneficial effects can be found in the description of any aspect of the first aspect, which will not be repeated here.
  • the log management apparatus has the function of implementing the behavior in the method example of any one of the above-mentioned first aspects.
  • the functions can be implemented by hardware, or can be implemented by hardware executing corresponding software.
  • the hardware or software includes one or more modules corresponding to the above functions.
  • the log management apparatus can be applied to a processor, or the log management apparatus can be applied to a communication device that can support the processor to implement the method.
  • the communication device includes a chip system
  • the log management apparatus includes: The processing module is used to divide the storage space of the hard disk into multiple segments, one segment includes one or more physical blocks, and one segment is used to store logs; the communication module is used to receive the first log write request and the second log write request , the first log write request includes the first log entry, and the second log write request includes the second log entry; the processing module is further configured to write the first log entry into the first segment of the multiple segments in parallel, and write the first log entry into the first segment in parallel. Two log entries are written to the first segment.
  • no locking mechanism is implemented in the process of writing the first log entry into the first segment or during the process of writing the second log entry into the first segment.
  • the log management apparatus further includes: an index module, configured to match the log sequence number LSN of the first log write request with the log index, and determine the first log item included in the first log write request The segment to be written is the first segment, and the log index is used to indicate the correspondence between the first segment and the LSN.
  • the log index includes a first index and a second index
  • the first index is used to indicate the storage address range of the first segment in the hard disk
  • the second index is used for each storage address range in at least one storage address range.
  • the index module is specifically used to judge whether the LSN of the third log entry is continuous, and the third log entry is any log entry recorded by the second index; if the LSN is continuous with the LSN of the third log entry, the index module is specifically used for Take the segment where the third log entry is located as the first segment; if the LSN is not continuous with the LSN of the third log entry, the indexing module is specifically used to match the LSN with the first index, and determine the first segment, the first segment in the first segment.
  • the LSN of a log entry matches the LSN of the first log write request.
  • the log index is stored in the cache.
  • the first log entry includes description information and data information
  • the description information includes the LSN of the first log write request, the length of the log entry, and the checksum of the length of the log entry
  • the data information is used to indicate the first log entry. The log content recorded by the log entry.
  • the processing module is specifically configured to generate a starting storage address according to the LSN of the first log write request, and the starting storage address is in the storage address range of the first segment; The starting storage address writes the first log entry to the first segment.
  • the communication module is further configured to send the LSN and the starting storage address of the first log write request to the backup device.
  • the communication module is further configured to receive the LSN and the initial storage address of the first log write request sent by the backup device; the processing module is further configured to receive the LSN and the initial storage address of the first log write request according to the first log write request. Start storage address, write the first log entry into the first segment.
  • the communication module is further configured to send a log write response to the client, where the log write response is used to indicate that the first log and the second log have been written to the first segment.
  • the present application provides a chip, including a memory and a processor, the memory is used to store computer instructions, and when the processor calls and runs the computer instructions from the memory, any one of the first aspect and the first aspect is possible. Operation steps of the log management method of the implementation.
  • the present application provides a communication device, including the chip described in the third aspect, the chip includes a processor and a memory, and the memory is used for storing computer instructions.
  • the processor executes the computer instructions
  • the communication device realizes Operation steps of the log management method of the first aspect and any possible implementation manner of the first aspect.
  • the communication device may be a network card, a server or a desktop computer, and so on.
  • the present application provides a computer-readable storage medium, in which a computer program or instruction is stored, and when the computer program or instruction is executed by a processor or a communication device, any one of the first aspect and the first aspect is implemented Operation steps of a log management method of a possible implementation.
  • the present application provides a computer program product that, when the computer program product runs on a communication device such as a computer or a server, enables the computer or server to perform the log management of the first aspect and any one of the possible implementations of the first aspect steps of the method.
  • the present application provides a log system, and the communication system includes at least one server.
  • the server divides the storage space of the hard disk into multiple segments, and one segment includes one or more physical blocks (blocks), which are used to store logs;
  • the server receives the first log write request and the first log write request sent by the client.
  • Two log write requests the first log write request includes a first log entry, and the second log write request includes a second log entry; finally, the server writes the first log entry into the first segment of the multiple segments in parallel, and writing the second log entry to the first segment.
  • the hard disk manages logs based on segments, which avoids the hard disk from storing logs in the form of log files, reduces the overhead of file locks in the log writing process, and improves the The efficiency of log writing is improved; in addition, multiple log items can be written to a segment in parallel, avoiding the locking process required to write log items in the log file, and improving the parallel writing of logs to the hard disk. efficiency.
  • the log system provided by the present application can implement the operation steps of the log management method of the first aspect and any possible implementation manner of the first aspect, and the beneficial effects can be found in the description of any aspect of the first aspect, which will not be repeated here.
  • the present application may further combine to provide more implementation manners.
  • FIG. 2 is a schematic flowchart one of a log management method provided by the present application
  • FIG. 3 is a schematic diagram of the division of a hard disk provided by the application.
  • FIG. 5 is a second schematic flowchart of a log management method provided by the present application.
  • FIG. 6 is a schematic diagram 2 of log writing provided by the application.
  • FIG. 8 is a schematic flowchart three of a log management method provided by the present application.
  • FIG. 9 is a schematic structural diagram of a log management device provided by the present application.
  • FIG. 10 is a schematic structural diagram of a communication device provided by this application.
  • the multi-read and multi-write log system is used to read and write the write-ahead log of business data.
  • the upper-layer application can conveniently use only a small amount of work. It implements its own application layer method, and at the same time, the log system ensures the characteristics of strong consistency, data durability, fault atomicity and transaction isolation required by the upper-layer application.
  • a distributed log system based on flash arrays stores logs in the form of files, each log file stores a specific number (eg, 1000) of log entries, which are used for Indicates the data file recorded in at least one data operation (such as business data write) in the log.
  • CORFU uses an independent file to store the metadata of the log system.
  • CORFU needs to lock the log segment where the log item is located, and the parallel read and write performance is poor.
  • CORFU needs to lock the log file to which the new log entry is to be written, resulting in slower log writing speed.
  • the log system 100 includes at least one server, and the client 120 can access the log data by using a network to access the server in the log system 100.
  • the communication function of the network can be controlled by Switch or router implementation.
  • the client may also communicate with the server through a wired connection, such as a peripheral component interconnect express (PCIe) high-speed bus.
  • PCIe peripheral component interconnect express
  • the client 120 may be a computer running an application program, and the computer running the application program may be a physical machine or a virtual machine.
  • the computer running the application program is a physical computing device
  • the physical computing device may be a server or a terminal.
  • the terminal may also be referred to as terminal equipment, user equipment (UE), mobile station (mobile station, MS), mobile terminal (mobile terminal, MT), and the like.
  • the terminal can be a mobile phone, a tablet computer, a notebook computer, a desktop computer, a personal communication service (PCS) phone, a desktop computer, a virtual reality (Virtual Reality, VR) terminal device, an augmented reality (Augmented Reality, AR) terminal device , wireless terminals in industrial control, wireless terminals in self driving, wireless terminals in remote medical surgery, wireless terminals in smart grid, transportation safety ( Wireless terminals in transportation safety), wireless terminals in smart cities, wireless terminals in smart homes, and so on.
  • the embodiments of the present application do not limit the specific technology and specific device form adopted by the client 120 .
  • the log system provided by the embodiment of the present application may be a distributed storage system or a centralized storage system.
  • the log system 100 shown in FIG. 1 may be a distributed storage system.
  • the distributed storage system provided in this embodiment includes a storage cluster integrating computing and storage.
  • the storage cluster includes one or more servers (such as server 110A and server 110B as shown in FIG. 1 ), and each server can communicate with each other.
  • the server 110A shown in FIG. 1 is used for description.
  • the server 110A is a device having both computing capability and storage capability, such as a server, a desktop computer, and the like.
  • an Advanced Reduced Instruction Set Computer Machines (ARM) server or an X86 server can be used as the server 110A here.
  • the server 110A at least includes a processor 112 , a memory 113 , a network card 114 and a hard disk 105 .
  • the processor 112, the memory 113, the network card 114 and the hard disk 105 are connected through a bus. Among them, the processor 112 and the memory 113 are used to provide computing resources.
  • the processor 112 is a central processing unit (CPU), which is used to process data access requests (such as log write requests) from outside the server 110A (application server or other servers), and is also used to process the server 110A Internally generated request.
  • data access requests such as log write requests
  • the processor 112 receives log write requests, it temporarily stores the data in the log write requests in the memory 113 .
  • the processor 112 sends the data stored in the memory 113 to the hard disk 105 for persistent storage.
  • the processor 112 is also used for data calculation or processing. Only one processor 112 is shown in FIG. 1 . In practical applications, there are often multiple processors 112 , and one processor 112 has one or more CPU cores. This embodiment does not limit the number of CPUs and the number of CPU cores.
  • the memory 113 refers to the internal memory that directly exchanges data with the processor, it can read and write data at any time, and is very fast, and serves as a temporary data storage for the operating system or other running programs.
  • the memory includes at least two kinds of memory, for example, the memory can be either a random access memory or a read only memory (Read Only Memory, ROM).
  • the random access memory is Dynamic Random Access Memory (DRAM), or Storage Class Memory (SCM).
  • DRAM Dynamic Random Access Memory
  • SCM Storage Class Memory
  • DRAM is a semiconductor memory, and like most Random Access Memory (RAM), it belongs to a volatile memory (volatile memory) device.
  • SCM is a composite storage technology that combines the characteristics of traditional storage devices and memory.
  • Storage-level memory can provide faster read and write speeds than hard disks, but its access speed is slower than that of DRAM, and its cost is cheaper than DRAM.
  • the DRAM and the SCM are only exemplary descriptions in this embodiment, and the memory may also include other random access memories, such as static random access memory (Static Random Access Memory, SRAM) and the like.
  • SRAM static random access memory
  • the read-only memory for example, it may be Programmable Read Only Memory (PROM), Erasable Programmable Read Only Memory (EPROM), and the like.
  • the memory 113 may also be a Dual In-line Memory Module (Dual In-line Memory Module, DIMM for short), that is, a module composed of Dynamic Random Access Memory (DRAM), or a solid state drive (Solid State Disk, SSD).
  • DIMM Dual In-line Memory Module
  • DRAM Dynamic Random Access Memory
  • SSD Solid State Disk
  • multiple memories 113 and different types of memories 113 may be configured in the storage server 110A. This embodiment does not limit the quantity and type of the memory 113 .
  • the memory 113 can be configured to have a power saving function. The power saving function means that when the system is powered off and then powered on again, the data stored in the memory 113 will not be lost. Memory with a power-saving function is called non-volatile memory.
  • the hard disk 105 is used for providing storage resources, such as storing logs and the like. It can be a magnetic disk or other type of storage medium, such as a solid state drive or a shingled magnetic recording hard drive.
  • the hard disk 105 may be a solid state disk based on a non-volatile memory host controller interface specification (Non-Volatile Memory Express, NVMe), such as an NVMe SSD.
  • NVMe non-volatile Memory Express
  • the network card 114 in the server 110A is used to communicate with the client 120 or other application server (such as the server 110B shown in FIG. 1 ).
  • processor 112 may be offloaded to network card 114 .
  • the processor 112 does not perform log reading and writing operations, but the network card 114 performs log reading and writing, address translation, and other computing functions.
  • the network card 114 shown in FIG. 1 may include a processing unit 1141 and a memory 1142 .
  • the network card 114 is an intelligent network card.
  • the processing unit 1141 may be a CPU or other chips, and the other chips may be, but not limited to, a digital signal processor (Digital Signal Processor, DSP), an application specific integrated circuit (ASIC), a field programmable gate Field Programmable Gate Array (FPGA) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof.
  • a general-purpose processor may be a microprocessor or any conventional processor.
  • the memory 1142 may refer to the internal memory that directly exchanges data with the processor, it can read and write logs at any time, and is very fast, as a temporary data storage for the operating system or other running programs.
  • the memory 1142 may be either random access memory or ROM.
  • random access memory is DRAM or SCM.
  • the memory may also include other random access memories such as SRAM and the like.
  • the read-only memory for example, it can be PROM, EPROM and so on.
  • the memory 1142 may also be a DIMM, that is, a module composed of DRAM, and may also be an SSD.
  • multiple memories 1142 and different types of memories 1142 may be configured in the network card 114 . This embodiment does not limit the quantity and type of the memory 1142 .
  • the memory 1142 can be configured to have a power saving function.
  • the power saving function means that the data stored in the memory 1142 will not be lost when the system is powered off and then powered on again.
  • Memory with a power-saving function is called non-volatile memory.
  • the network card 114 may also have persistent memory media, such as persistent memory (PM), or non-volatile random access memory (NVRAM), or Phase change memory (phase change memory, PCM), etc.
  • the CPU is used to perform operations such as address translation and reading and writing logs.
  • the memory is used to temporarily store data to be written into the hard disk 105 or read data from the hard disk 105 to be sent to the controller.
  • It can also be a programmable electronic component, such as a data processing unit (DPU).
  • the DPU has the generality and programmability of a CPU, but is more specialized and can operate efficiently on network packets, storage requests, or analytics requests.
  • DPUs are distinguished from CPUs by a greater degree of parallelism (the need to handle a large number of requests).
  • the DPU here can also be replaced by a graphics processing unit (graphics processing unit, GPU), an embedded neural network processor (neural-network processing units, NPU) and other processing chips.
  • graphics processing unit graphics processing unit, GPU
  • embedded neural network processor neural-network processing units, NPU
  • NPU neural-network processing units
  • the smart NIC can be a general-purpose smart NIC, such as a NIC with 8 processor cores and 2 x 100 giga bits per second (Gb/s) network bandwidth, which can run full operations system.
  • a general-purpose smart NIC such as a NIC with 8 processor cores and 2 x 100 giga bits per second (Gb/s) network bandwidth, which can run full operations system.
  • Gb/s giga bits per second
  • the smart network card may also be an application-oriented smart network card, and the network card may be an FPGA- or ASIC-based smart network card, such as GPU and NPU for deep neural network acceleration.
  • the network card may be an FPGA- or ASIC-based smart network card, such as GPU and NPU for deep neural network acceleration.
  • FPGA- or ASIC-based smart network card such as GPU and NPU for deep neural network acceleration.
  • the log system provided by this embodiment of the present application may also be a storage cluster separated from computing and storage, where the storage cluster includes a computing device cluster and a storage device cluster, and the computing device cluster includes one or more computing devices , each computing device can communicate with each other.
  • the computing device may be a computing device, such as a server, a desktop computer, or a controller of a storage array, or the like.
  • computing devices may include processors, memory, and network cards, among others.
  • the processor is a CPU for processing data access requests from outside the computing device, or requests generated inside the computing device. Exemplarily, when the processor receives a log write request sent by a user, it temporarily stores the log in the log write request in the memory.
  • the processor sends the log data stored in the memory to the storage device for persistent storage.
  • the processor is also used for data calculation or processing, such as metadata management, data deduplication, data compression, virtualized storage space, and address translation.
  • the log system provided by the embodiment of the present application may also be a centralized storage system.
  • the characteristic of the centralized storage system is that there is a unified entrance through which all data from external devices must pass.
  • This entrance is the engine of the centralized storage system.
  • the engine is the core component of the centralized storage system, and many advanced functions of the storage system are implemented in it.
  • the engine also includes a front-end interface and a back-end interface, wherein the front-end interface is used to communicate with the computing devices in the centralized storage system, thereby providing storage services for the computing devices.
  • the back-end interface is used to communicate with the hard disk to expand the capacity of the centralized storage system. Through the back-end interface, the engine can connect more hard disks, thus forming a very large storage resource pool.
  • FIG. 2 provides a log management method for this application.
  • the client 21 can implement the functions of the client 120 shown in FIG. 1 , and the log management method is executed by the processor 22, which can be the processing in the server 110A shown in FIG. 1 .
  • the server 112 may also be the processing unit 1141 included in the network card 114 in the server 110B, and the log management method includes the following steps.
  • the processor 22 divides the storage space of the hard disk into multiple segments.
  • the multiple segments refer to multiple log segments (log segments) in the hard disk for storing logs.
  • One of the plurality of segments includes one or more physical blocks, and the one segment may be used to store logs.
  • FIG. 3 is a schematic diagram of division of a hard disk provided by the present application.
  • the hard disk 105 may be one or more flash memory chips (chip) package.
  • a flash memory chip (chip) may include one or more dies, and one die may include multiple planes.
  • a die is internally divided into two Planes, and the block numbers in the two Planes are single and double crossover, so during operation, a single double crossover operation can be performed to improve performance.
  • a plane contains multiple physical blocks (block).
  • a block consists of several pages.
  • the content and 218 bytes (byte, B) of error checking and correction (error correcting code, ECC) check data, page is also the smallest unit of input and output (input output, IO) operations.
  • a whole flash memory chip consists of two planes. One plane stores blocks with odd numbers, and the other stores blocks with even numbers. The two planes can be paralleled. operate. This is just an example, the size of the page, the capacity of the block, and the capacity of the flash memory chip may all have different specifications, which are not limited in this embodiment.
  • the processor 22 writes data into the block, and when a block is full, the master controller of the hard disk 105 selects the next block to continue writing.
  • a page is the smallest unit of data writing. In other words, the master writes data into the block at the granularity of pages.
  • a block is the smallest unit of data erasure; when the master controller erases data, it can only erase the entire block at a time.
  • the above-mentioned one segment may include one or more physical blocks (blocks). As shown in FIG. 3 , the first segment includes two physical blocks (blocks), and the second segment includes one physical block (block). It is worth noting that the above-mentioned embodiments are only possible implementations provided by the present application.
  • FIG. 3 illustrates an example where a segment includes an integer number of blocks, but in other possible examples, a segment may also include parts block, for example, if a block includes 4 pages, the above-mentioned one segment can include 3 pages or 2 pages, and the above-mentioned one segment can also include 1 block and 3 pages.
  • CORFU uses the file system to manage the storage space of the hard disk, in the process of reading and writing log files, log append writing and log reading are simple read and write operations without complex semantics. Therefore, CORFU Adopting a file system introduces a lot of file management overhead, such as file locks (mandatory access to files can only be accessed by one user or at any given time), resulting in a waste of processing and storage resources.
  • the hardware storage space is divided into multiple segments, and the processor can manage logs based on segments to avoid In order to add a file lock to the log file in the file system, the waste of processing resources and storage resources is reduced, and the efficiency of log reading and writing is improved.
  • the process of dividing the storage space of the hard disk by the processor 22 may be performed only once. For example, if the log system reads and writes logs for the first time, the processor 22 may use the log entries in the log system for storing log items. The storage space is divided to obtain the above-mentioned multiple segments.
  • the process of dividing the storage space of the hard disk by the processor 22 may be performed multiple times.
  • a timer may be set in the log system, and the timer may be a computer software instruction.
  • the processor 22 divides the storage space of the hard disk in the log system.
  • the process of dividing the storage space of the hard disk by the processor 22 may be set or adjusted according to the actual usage requirements of the log system, which is not limited in this application.
  • the processor 22 may further divide the storage space of the hard disk according to the division instruction.
  • the client 21 sends the first log write request and the second log write request to the processor 22.
  • the log write request provided by the embodiment of the present application refers to a data write request including a log entry to be written.
  • the first log write request includes a first log entry
  • the second log write request includes a second log entry.
  • multiple log write requests may be sent by two or more clients to Sent by the processor, for example, the above-mentioned first log write request and second log write request may be sent to the processor by two different clients.
  • the first log entry provided by this application includes description information and data information
  • the description information includes a log sequencer number (log sequencer number, LSN) of the first log write request, a log entry length ( length) and the log length checksum (log length checksum)
  • the data information is used to indicate the log content recorded by the first log item.
  • the log may include one or more log items, a log segment may store one or more log items, and each log item records part of the log content of the log, and the log content Refers to the event recorded by the first log item in the log.
  • the log content of the first log item may be that the client performs the opening operation of the application (application, APP) at the first time; another example, the above-mentioned second log
  • the log content of the item may be that the client performs the closing operation of the APP at the second time.
  • the log in this embodiment of the present application refers to business data, or a copy, snapshot, or clone of the business data.
  • FIG. 4 is a schematic diagram 1 of log writing provided by this application.
  • the first log entry in the hard disk includes description information and data information, and the description information includes the log entry length checksum, the log entry length, and the LSN of the first log write request.
  • the log entry length checksum is used to determine the integrity and accuracy of the first log entry
  • the log entry length is used to determine the size of the storage space occupied by the first log entry
  • the LSN is used to indicate the log of the first log write request Add the sequence number of the operation.
  • the description information included in the first log entry may also be referred to as metadata information of the first log entry.
  • the data information included in the log entry refers to the log content recorded by the log entry.
  • the log content recorded by the log entry can refer to the operation type of the data to be stored on the hard disk, the time when the stored data is received, or the data to be stored. One or a combination of data access addresses, etc.
  • the data to be stored refers to content data to be stored on the hard disk, for example, the content data may be a streaming media file.
  • the format of the data to be stored is different from the format of the log entry included in the log write request.
  • the log management method provided by the embodiment of the present application further includes step S230.
  • the processor 22 writes the first log entry into the first segment of the plurality of segments in parallel, and writes the second log entry into the first segment.
  • a lock is a synchronization mechanism, and the lock overhead includes the memory space occupied by the lock, the time it takes for the processor to initialize and destroy the lock, acquire and release the lock, etc. The more locks an application uses, the greater the corresponding lock overhead.
  • the granularity of the lock determines the amount of data protected by each lock.
  • CORFU uses file granularity-based locks to lock log files, multiple log items are written to the hard disk in parallel. During the log file process, if the log file is locked, CORFU can only write one log item of the multiple log items into the log file at a time, resulting in a slow writing speed of the multiple log items.
  • the log management method provided by the embodiment of the present application does not implement a locking mechanism on the hard disk because the processor does not.
  • the processor can write the first log item and the second log item to the first segment of the hard disk in parallel, which improves the efficiency of the processor writing multiple log items to the hard disk in parallel.
  • the storage space of the hardware is divided into multiple segments, and the processor can manage the logs based on the segments, avoiding the process of adding file locks to the log files in the file system, The waste of processing resources and storage resources is reduced, and the efficiency of log reading and writing is improved; in addition, since the processor does not perform a locking mechanism on the hard disk, the processor can write the first log entry and the second log entry in parallel The first segment of the hard disk improves the efficiency of the processor writing multiple log entries to the hard disk in parallel.
  • the processor 22 is the processing unit 1141 in the network card 114 shown in FIG. 1 , then in the process of log reading and writing, the network card 114 can implement the log management method provided by this application. .
  • the network card 114 uses a direct memory access (DMA) technique to access data.
  • DMA direct memory access
  • the processing unit 1141 uses the DMA technology to access the log segment of the hard disk 105 in the server 110B where the network card 114 is located to read and write the log, so as to realize direct hard disk access, so as to reduce the connection between the network card 114 and the processor 112 during the log reading and writing process.
  • the interaction (such as log request replication and transmission, etc.) improves the efficiency of log reading and writing.
  • the network card 114 uses remote direct memory access (RDMA) technology to access data.
  • RDMA remote direct memory access
  • the processing unit 1141 uses the RDMA technology to access the log segment of the hard disk 105 in the server 110B other than the server 110A where the network card 114 is located in the log system to read and write the log, realize remote direct hard disk access, and reduce the number of logs in the log.
  • the network card 114 interacts with the processor 112 in the server 110B, and then the processor 112 in the server 110B interacts with the hard disk 105 of the server 110B, which improves the efficiency of log reading and writing.
  • the log management method provided by the embodiments of the present application is implemented by the processing unit of the network card in the server, which can reduce the processing resource consumption of the CPU in the server, thereby improving the efficiency of processing other data by the CPU in the server.
  • the processor can also sort the log write requests, please continue to refer to FIG. 4 , the processor in FIG. 4 can implement the log management method provided by this application , the processor may include a processing unit and an internal memory, the internal memory is provided with a sequencer, the sequencer may be a computer software (such as an application program or a thread, etc.), and the sequencer is integrated with a log sorting function hardware circuit.
  • the sorter can globally sort the logs in the log system, so that all logs in the log system are globally ordered, which is beneficial for each server in the log system to achieve consistent snapshots and cross-region atomic updates based on the LSN of each log. wait
  • the storage space of the hard disk includes a metadata area and a log segment area.
  • the metadata area is used to store the metadata information of each log segment in the hard disk.
  • the metadata information in the metadata area includes segment header, header LSN and segment end.
  • the LSN of a log entry, the segment tail is used to indicate the end storage address of the log segment on the hard disk.
  • the log segment area is divided into 3 log segments (the first segment, the second segment, and the third segment), and each log segment can store one or more log entries. As shown in FIG. 4, a third log entry is stored in the first segment.
  • the sorter sorts the first log write request and the second log write request. For example, the LSN of the first log entry in the first log write request is The first LSN, the LSN of the second log entry in the second log write request is the second LSN.
  • sequencer shown in FIG. 4 is set in the internal memory of the processor, but in some possible examples, in order to reduce the processing resource occupation of the processor, the sequencer may also be set in the client In the terminal, or set in another processor, for example, the other processor is used to sort the log write requests sent by the client, which is not limited in this application.
  • the embodiment of the present application further provides a method for determining the first segment
  • the processor 22 may match the LSN of the first log write request with the log index to determine that the segment to be written in the first log entry included in the first log write request is the first segment.
  • the log index is used to indicate the correspondence between the first segment and the LSN.
  • the above-mentioned log index is stored in the cache of the processor.
  • the cache may be a memory 1142, and the memory 1142 may be a DRAM.
  • the processing unit 1141 can read the log index in the cache (memory 1142), so as to quickly determine the segment to be written for the log item included in the log write request, and reduce the path query time required for log writing , which improves the efficiency of log writing.
  • the above-mentioned log index is stored in another cache connected to the processor.
  • the other cache includes one or more caches
  • the processor can use DMA or RDMA technology to read the log index from the other cache, and then the processor matches the LSN of the log write request with the log index to determine the write log index.
  • the segment to be written by the log entry included in the log request reduces the path query time required for log writing and improves the efficiency of log writing.
  • the above-mentioned other cache may be a distributed memory system, and the processor accesses the distributed memory system to read the above-mentioned log index.
  • the above-mentioned log index includes a first index and a second index.
  • the first index may be called a first-level index or a segment cache index (segment cache index), and the first index is used to indicate the storage address range of the first segment in the hard disk.
  • the first index points to the secondary index corresponding to the first segment among the multiple segments of the hard disk and the starting storage address of the log segment.
  • the first index includes the identifiers of multiple segments in the hard disk, the LSN of the first log entry (or the log entry at the beginning of the segment) stored in each segment in the multiple segments, and the log entry of the first log entry. The corresponding starting storage address.
  • the hard disk further includes other segments (the second segment and the third segment shown in FIG.
  • the first index is also used to indicate the storage address range of the other segments in the hard disk. As shown in Table 1 below, the first index may include the segment identifier, the LSN of the segment header log entry, and the start storage address of the segment header log entry.
  • the H at the end is used to indicate that the starting storage address is expressed in hexadecimal form.
  • the LSN of the first log entry in the first segment is 001, and the starting storage address is 0000 0000H; the storage address range indicated by the first segment is: 0000 0000H ⁇ 0000 FFFFH.
  • the LSN of the first log entry in the second segment is 101, and the starting storage address is 0001 0000H; the storage address range indicated by the second segment is: 0001 0000H ⁇ 0001 FFFFH.
  • the LSN of the first log entry in the third segment is 201, and the starting storage address is 0001 0001; the storage address range indicated by the third segment is: 0010 0000H ⁇ 0010 FFFFH.
  • the second index may be referred to as a secondary index or a log entry cache index, and the second index is used between the LSN and the storage address of each log entry in at least one storage address range corresponding relationship.
  • the second index includes the correspondence between the LSN and the storage address of each log entry in one or more segments in the hard disk.
  • the second index includes the correspondence between the LSN and the storage address of each log entry in a segment of the hard disk, as shown in Table 2, and the second index includes the relationship shown in FIG. 4 .
  • the second index includes 4 log items, and the correspondences between the LSNs of the 4 log items and the storage addresses are: 001-0000 0000H, 002-0000 0010H, 003-0000 0011H, 004-0000 0030H .
  • the second index includes the correspondence between the LSN and the storage address of each log entry in the multiple segments of the hard disk.
  • the second index includes the first segment shown in FIG. 4 . and the LSN and storage address of each log entry in the second paragraph.
  • the relevant content in Table 2 above which will not be repeated here.
  • the log index includes a first index and a second index. Any one of the first index and the second index is preferentially matched. If the match is successful, the processor can be prevented from searching for all data in the log index, the path query time required for log writing is reduced, and the log writing efficiency is improved.
  • the processor since the processor uses the log index to determine the first segment to be stored in the first log entry, without using the file system to determine the log file to be stored in the first log entry, the storage management overhead caused by the file system is reduced, Thus, the storage path query time required for log writing is reduced, and the efficiency of log writing is improved.
  • the processor since the hard disk does not introduce a file system when storing the log, in the case where the processor writes multiple log entries in parallel, the processor does not need to Multiple log segments to be written by multiple log entries are locked, which reduces the process of setting file locks for each log segment by the processor and improves the efficiency of log writing.
  • FIG. 5 is a flowchart of a log management method provided by the present application
  • the process that the processor matches the LSN of the first log write request with the log index to determine the first segment includes the following steps S221-S223.
  • S221 Determine whether the LSN of the first log write request is continuous with the LSN of the third log entry.
  • the third log entry is any log entry recorded by the second index. As shown in Table 2, the third log entry may refer to a log entry whose LSN is 004, and the starting storage address of the third log entry is 0000 0030H.
  • the processor writes the log into the log system by appending.
  • the processor determines whether the LSN of the first log write request is the same as the LSN of the third log entry in the second index according to the LSN of the third log entry in the second index.
  • the LSN of the first log write request is continuous, and then, if the LSN of the first log write request is continuous with the LSN of the third log item, then execute S222; if the LSN of the first log write request is not continuous with the LSN of the third log item, Then execute S223.
  • the processor takes the segment where the third log entry is located as the first segment, so that the processor uses appending to write the first segment.
  • the first log entry included in the first log write request is written into the first segment, which prevents the processor from searching the file system for the to-be-written file of the first log entry included in the first log write request, and reduces the log writing process.
  • the query time of the write path is shortened, which improves the efficiency of log writing.
  • S223 Match the LSN of the first log write request with the first index to determine the first segment.
  • the LSN of the first log entry (log entry at the beginning of the segment) in the first segment matches the LSN of the first log write request.
  • “matching” means that the LSN of the first log write request is in the first segment.
  • the LSN range corresponds to the storage address range of the first segment. As shown in Table 1, the LSN of the segment header log entry (first log entry) of the first segment is 001, the LSN of the segment header log entry of the second segment is 101, and the LSN of the segment header log entry of the third segment is 201, the LSN range corresponding to the first segment is "001-100", and the LSN range corresponding to the second segment is "101-200".
  • the LSC of the first log write request is any one of "001-100"
  • it is confirmed that the segment to be written in the first log entry included in the first log write request is the first segment.
  • the LSC of the first log write request is any one of "101-200"
  • it is confirmed that the segment to be written in the first log entry included in the first log write request is the second segment.
  • the processor first matches the LSN of the first log write request with the LSN of the second index including the third log entry. If the LSN of the first log write request is continuous with the LSN of the third log entry, Then the processor does not need to match the LSN of the first log write request with the first index. Compared with the processor matching the first log write request with the directory of the file system, a large amount of path query time is reduced, and log writing is improved. s efficiency.
  • the processor may also first match the LSN of the log read request with the second index. If the match is successful (hit), the processor may determine the log to be read by the log read request according to the second index The storage address where the item is located reduces the path query time required for log reading and improves the efficiency of log reading. If the LSN of the log read request is not hit in the second index, the processor can determine the log segment to be read by the log read request according to the first index, and obtain the log entry corresponding to the read log request by traversing the log segment, avoiding processing The server will query the storage address of the log read request in the file system, which improves the efficiency of log reading.
  • this embodiment of the present application provides a possible embodiment.
  • FIG. 5 FIG. 5
  • FIG. 5 In an implementation manner of the processor writing the first log entry into the first segment, the above-mentioned S230 may include the following steps.
  • the processor 22 generates an initial storage address according to the LSN of the first log write request.
  • the starting storage address is in the storage address range of the first segment. According to the content shown in Table 1, if the storage address range of the first segment is 0000 0000H ⁇ 0000 FFFFH, if the LSN of the first log write request is continuous with the LSN (001) of the segment header log entry of the first segment, then The starting memory address can be 0000 0010H.
  • the processor 22 writes the first log entry into the first segment according to the initial storage address.
  • the processor In the process of writing the log items to the hard disk, the processor first generates the initial storage address according to the LSN of the log write request, and then writes the log items included in the log write request to the hard disk according to the initial storage address.
  • the log entries are written to the hard disk to ensure the accuracy of log writing.
  • the processor can atomically write log entries to disk.
  • "Atomic write” can be understood as the processor writes log items to the hard disk according to the preset read and write units.
  • the preset read and write units may refer to the log read and write units of the hard disk.
  • the log read and write units of the hard disk are Refers to the minimum data granularity for the processor to read and write log items in the hard disk.
  • the log read and write unit of the hard disk can be set according to the type of the hard disk, and can also be adjusted according to the needs of users, such as 4KB, 8KB or 16KB.
  • the processor before the above S2301, the processor further determines whether the log entry length of the log write request is less than or equal to the log read/write unit of the hard disk. If the log entry length of the log write request is less than or equal to the log read/write unit of the hard disk, the above-mentioned S2301 is executed.
  • FIG. 6 provides a log write request provided by this application
  • the processor divides the log items included in the log write request into multiple sub-logs, and the log item length of each sub-log in the multiple sub-logs is consistent with the hard disk log read-write unit;
  • the LSN generates the starting storage address of each sub-log in the multiple sub-logs. For the process of generating the starting storage address by the processor according to the LSN, reference may be made to the example of S2301, which will not be repeated here.
  • each sub-log in the multiple sub-logs includes description information of the log item to be written, and the description information is consistent with the description information in the log write request.
  • description information please refer to the related content of FIG. 4 , here No longer.
  • the processor may also assign a sub-sequence number to each sub-log, and the sub-sequence number is used to indicate that the sub-log is in the log entry to be written (such as the first log entry or second log entry).
  • the processor can write multiple sub-logs according to the log read/write unit of the hard disk, even when the processor directly writes the log entry included in the log write request.
  • the sub-logs that have been written to the hard disk by the processor will not be repeatedly written (or read) by the processor, which reduces the storage resource consumption of the hard disk and improves the storage resource utilization efficiency of the hard disk.
  • the processor may split the log items to be written included in the log write request according to the log read/write unit of the hard disk, and further, the processor atomically generates the starting storage address of each sub-log, because The processor reads and writes logs based on the granularity of log segments that do not use the file system. Therefore, the processor does not need to lock the log segments, thus realizing the process of the processor adding and writing to the hard disk in parallel, reducing the time required for log writing and improving the efficiency of log writing.
  • the processor may also write part of the log write request into the first segment, and write another part of the log write request into the first segment.
  • a part of the content is written into the second segment, where the second segment is a log segment in the hard disk that has an associated relationship with the first segment that is continuously read. Then, the processor sets the log tail address in the hard disk as the start storage address of the first log entry in the second segment.
  • FIG. 7 is a schematic diagram 3 of log writing provided by this application. If the remaining storage space of the first segment is less than the log entry length of the log write request, the processor will write the log entries included in the log write request to be written.
  • the log entry is divided into multiple sub-logs, and part of the content (sub-logs with sub-sequence numbers 1 and 2 shown in Figure 7) is written into the first segment, and another part of the content (sub-log shown in Figure 7)
  • the sub-log with sequence number 3) is written into the second segment that has an association relationship with the first segment that is continuously read.
  • the second segment further includes a blank area, and the blank area can be used to store other log items.
  • the log tail address is represented by the starting storage address of the log entry at the segment head of the log segment where the last log is located.
  • the processor needs to allocate a new log segment to store the log entry, and update the starting storage address of the log segment where the log tail is located. In other cases, such as the log entry does not need to be stored in the newly allocated log segment, the processor does not need to update the starting storage address of the log segment where the log tail is located.
  • the log tail address can be represented by the starting storage address of the log segment where the log tail is located, avoiding the process of updating the log tail address every time a log is added in the file system.
  • the random lowercase operation of the log tail address required for log addition is reduced, and the efficiency of log writing is improved.
  • FIG. 8 is a schematic flow chart 3 of a log management method provided by this application.
  • the master node 810 and the slave node 820 shown in FIG. 8 are any servers in the log system 100 shown in FIG. 1 .
  • a storage device for example, the master node 810 is the server 110B, and the slave node 820 is the server 110A.
  • Table 3 The meaning of each time mark in FIG. 8 is shown in Table 3 below.
  • T total (this application) 2T1+T2+T3+T4.
  • the processor 22 is the master node 210 shown in FIG. 8 , after the master node 810 generates the starting storage address according to the LSN of the first log write request, that is, after T2, the master node 810 The LSN and the starting storage address of the first write log request are sent to the slave node 820 .
  • the slave node 820 can write the first log entry included in the first log write request into the first segment according to the LSN and the starting storage address of the first log write request.
  • FIG. 2 to FIG. 7 For the specific process, please refer to the above-mentioned FIG. 2 to FIG. 7 . The related content will not be repeated here.
  • the master node 810 sends the LSN and the starting storage address of the log write request to the slave node 820
  • the slave node 820 sends the LSN and the starting storage address of the log write request to the slave node 820 according to
  • the log items included in the log write request are written into the first segment, which avoids the need to go to the slave node 820 for backup after the log writing of the master node 810 is completed, and improves the multi-write scenario. write efficiency.
  • the processor 22 in the above embodiment is the slave node 820 shown in FIG. 8
  • the processor 22 It can also receive the LSN and the initial storage address of the first write log request sent by the backup device (main node 810), and then, the processor 22 writes the first log according to the LSN and the initial storage address of the first write log request.
  • the first log entry included in the request is written into the first segment, and the specific process can refer to the above-mentioned related content of FIG. 2 to FIG. 7 , which will not be repeated here.
  • the processor 22 can also receive the backup device (master node 810) after receiving the log write request sent by the client.
  • the LSN and starting storage address of the log write request sent, and the processor 22 (slave node 820) writes the log items included in the log write request into the first segment according to the LSN and starting storage address of the log write request , which avoids the backup of the slave node 820 after the log writing of the master node 810 is completed, and improves the writing efficiency of the multi-write scenario.
  • the slave node 820 may also send a log write response to the client, where the log write response is used to indicate that the log write request has been
  • the log entries included in the log write request (such as the above-mentioned first log entry and second log entry) are written to the hard disk.
  • the client can determine that the current round of log addition operation has been completed according to the log write response fed back from the node 820, so as to avoid the client from repeatedly sending log write requests to the log system, resulting in repeated backups of log write requests and saving the storage resources of the log system. , to improve the storage resource utilization of the log system.
  • the present application separates the control (LSN and starting storage address) and data (log entry) in the log management method, and for the log addition operation, the client can concurrently send a log write request to the master node 810 and the slave node 820 , after receiving the log write request, the master node 810 generates a corresponding log entry sequence number and a log entry start storage address, and sends them to the slave node 820 .
  • the master node 810 and the slave node 820 can persist the log entries in parallel. After the persistence operation is completed, the master node 810 and the slave node 820 update the log entry cache index (such as the above-mentioned second index), and send confirmation information (such as the above-mentioned log write response) to the client.
  • the client receives confirmation information from all nodes, it determines that the log addition operation is complete.
  • the client can read from the master node and the slave node at will, which can reduce the bandwidth occupied by the client on the network card of the server where the master node is located, and effectively improve the bandwidth utilization of the server where the master node is located.
  • the network device and the terminal device include corresponding hardware structures and/or software modules for performing each function.
  • the units and method steps of each example described in conjunction with the embodiments disclosed in the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is performed by hardware or computer software-driven hardware depends on the specific application scenarios and design constraints of the technical solution.
  • FIG. 9 is a schematic structural diagram of a log management apparatus provided by the present application.
  • the log management apparatus 900 can be used to implement the function of the processor in the above method embodiments, and thus can also achieve the beneficial effects of the above method embodiments.
  • the log management apparatus 900 may be the processor 22 shown in FIG. 2 , the server 110A, the server 110B or the network card 114 shown in FIG. 1 , or may be applied to a server A module (such as a chip), such as the processor 112 or the processing unit 1141 shown in FIG. 1 .
  • the log management apparatus 900 includes a processing module 910 , a communication module 920 and an indexing module 930 .
  • the log management apparatus 900 is used to implement the functions of the processor or the hard disk in the method embodiments shown in the foregoing Fig. 2 to Fig. 8 .
  • the processing module 910 is used to execute S210 and S230; the communication module 920 is used to execute S220.
  • the processing module 910 is used to execute S210 and S2301-S2302; the communication module 920 is used to execute S220, and the index module 930 is used to execute S221 to S223.
  • processing module 910 communication module 920 and indexing module 930 can be obtained directly by referring to the relevant descriptions in the method embodiments shown in FIG. 2 to FIG. 8 , and details are not repeated here.
  • FIG. 10 is a schematic structural diagram of a communication device provided by this application.
  • the communication device 1000 can implement the operation steps of the log management methods shown in FIGS. 2 to 8 .
  • the communication device 1000 includes a processor 1010 and a communication interface 1020 .
  • the processor 1010 and the communication interface 1020 are coupled to each other. It can be understood that the communication interface 1020 can be a transceiver or an input-output interface.
  • the specific connection medium between the communication interface 1020 , the processor 1010 , and the memory 1030 is not limited in the embodiments of the present application.
  • the communication interface 1020, the processor 1010, and the memory 1030 are connected through a bus 1040 in FIG. 10.
  • the bus is represented by a thick line in FIG. 10, and the connection between other components is only for schematic illustration. , is not limited.
  • the bus can be divided into an address bus, a data bus, a control bus, and the like. For ease of presentation, only one thick line is used in FIG. 10, but it does not mean that there is only one bus or one type of bus.
  • the communication device 1000 may further include a memory 1030 for storing instructions executed by the processor 1010 or input data required by the processor 1010 to run the instructions or data generated after the processor 1010 runs the instructions.
  • the memory 1030 may Used to store the above log index.
  • the memory 1030 may be used to store software programs and modules, such as program instructions/modules corresponding to the log management method provided by the embodiments of the present application, and the processor 1010 executes various functional applications by executing the software programs and modules stored in the memory 1030. and data processing.
  • the communication interface 1020 can be used for signaling or data communication with other devices.
  • the network device 1000 may have multiple communication interfaces 1020 in this application.
  • the processor 1010 is used to perform the functions of the above-mentioned processing unit 910
  • the communication interface 1020 is used to perform the functions of the above-mentioned transceiver unit 920 .
  • processor in the embodiments of the present application may be a CPU, an NPU, or a GPU, and may also be other general-purpose processors, DSPs, ASICs, FPGAs, or other programmable logic devices, transistor logic devices, hardware components or the like. random combination.
  • a general-purpose processor may be a microprocessor or any conventional processor.
  • the communication device 1000 provided by the present application may be a network card (the network card 114 shown in FIG. 1 ), a server, a mobile phone, a tablet computer, a notebook computer or a desktop computer, and the like.
  • the method steps in the embodiments of the present application may be implemented in a hardware manner, or may be implemented in a manner in which a processor executes software instructions.
  • the software instructions can be composed of corresponding software modules, and the software modules can be stored in RAM, flash memory, ROM, PROM, EPROM, EEPROM, registers, hard disk, removable hard disk, CD-ROM or any other form of storage medium well known in the art .
  • An exemplary storage medium is coupled to the processor, such that the processor can read information from, and write information to, the storage medium.
  • the storage medium can also be an integral part of the processor.
  • the processor and storage medium may reside in an ASIC.
  • the ASIC may be located in a network device or in an end device.
  • the processor and the storage medium may also exist in the network device or the terminal device as discrete components.
  • the above-mentioned embodiments it may be implemented in whole or in part by software, hardware, firmware or any combination thereof.
  • software it can be implemented in whole or in part in the form of a computer program product.
  • the computer program product includes one or more computer programs or instructions.
  • the processes or functions described in the embodiments of the present application are executed in whole or in part.
  • the computer may be a general purpose computer, a special purpose computer, a computer network, network equipment, user equipment, or other programmable apparatus.
  • the computer program or instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer program or instructions may be downloaded from a website site, computer, A server or data center transmits by wire or wireless to another website site, computer, server or data center.
  • the computer-readable storage medium may be any available medium that can be accessed by a computer, or a data storage device such as a server, data center, or the like that integrates one or more available media.
  • the usable media may be magnetic media, such as floppy disks, hard disks, magnetic tapes; optical media, such as digital video discs (DVD); and semiconductor media, such as SSDs.
  • At least one of means one or any combination of subsequent associated objects, for example "at least one of A, B and C” includes A, B, C, AB, AC, BC, or ABC .
  • the character “/” generally indicates that the related objects before and after are a kind of "or” relationship; in the formula of this application, the character “/” indicates that the related objects are a kind of "division” Relationship.

Abstract

A log management method and apparatus, which relate to the field of data storage. The log management method comprises: firstly, a processor dividing a storage space of a hard disk into a plurality of segments, wherein one segment comprises one or more physical blocks, and the one segment is used for storing a log; secondly, the processor receiving a first log writing request and a second log writing request, wherein the first log writing request comprises a first log item, and the second log writing request comprises a second log item; and finally, the processor concurrently writing the first log item into a first segment of the plurality of segments and writing the second log item into the first segment. Since a storage space of a hard disk is divided into a plurality of segments, the hard disk is prevented from storing a log in the form of a log file, thereby reducing the overheads of a file lock during a log writing process, and improving the log writing efficiency. A plurality of log items can be concurrently written into one segment, thereby avoiding a locking process, which is required for writing the log items into the log file, and improving the efficiency of concurrently writing logs into the hard disk.

Description

一种日志管理方法及装置A log management method and device
本申请要求于2021年04月22日提交国家知识产权局、申请号为202110436373.3、申请名称为“更新数据的方法和相关装置”的中国专利申请的优先权,本申请还要求于2021年06月30日提交国家知识产权局、申请号为202110744793.8、申请名称为“一种日志管理方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application with the application number 202110436373.3 and the application name "Data Update Method and Related Apparatus", which was submitted to the State Intellectual Property Office on April 22, 2021, and the application is also claimed in June 2021 The priority of the Chinese patent application filed with the State Intellectual Property Office on the 30th with the application number of 202110744793.8 and the application title of "A Log Management Method and Device", the entire contents of which are incorporated in this application by reference.
技术领域technical field
本申请涉及数据存储领域,尤其涉及一种日志管理方法及装置。The present application relates to the field of data storage, and in particular, to a log management method and device.
背景技术Background technique
预写式日志(write ahead log,WAL)提供了一种高并发、持久化的日志保存与回放机制。服务器在将业务数据写入存储设备之前,都会记录在WAL中。通常,在日志写入过程中,服务器使用追加写的方式将多个日志写入存储设备,存储设备以日志文件(log file)的形式保存日志,其中,每个日志文件包括固定数目的日志项。然而,服务器在追加写日志的过程中,需要将新日志项所要写入的日志文件进行加锁,导致日志写入速度较慢。因此,如何提高日志写入的效率成为目前亟需解决的问题。Write ahead log (WAL) provides a highly concurrent and persistent log storage and playback mechanism. Before the server writes business data to the storage device, it will be recorded in the WAL. Usually, in the log writing process, the server writes multiple logs to the storage device by means of append writing, and the storage device saves the logs in the form of log files, wherein each log file includes a fixed number of log entries . However, in the process of appending the log, the server needs to lock the log file to which the new log entry is to be written, resulting in a slow log writing speed. Therefore, how to improve the efficiency of log writing has become an urgent problem to be solved at present.
发明内容SUMMARY OF THE INVENTION
本申请提供一种日志管理方法及装置,解决了服务器以日志文件为粒度写入日志所导致的日志写入速度较慢的问题。The present application provides a log management method and device, which solves the problem of slow log writing speed caused by the server writing logs with log files as granularity.
为达到上述目的,本申请采用如下技术方案。In order to achieve the above purpose, the present application adopts the following technical solutions.
第一方面,本申请提供了一种日志管理方法,该方法可应用于处理器,或者该方法可应用于可以支持处理器实现该方法的通信设备,例如该通信设备包括芯片系统,该日志管理方法包括:首先,处理器将硬盘的存储空间划分为多个段,一个段包括一个或多个物理块(block),该一个段用于存储日志;其次,处理器接收第一写日志请求和第二写日志请求,该第一写日志请求包括第一日志项,该第二写日志请求包括第二日志项;最后,处理器并行地将第一日志项写入多个段中的第一段,以及将第二日志项写入第一段。在本申请的实施例中,由于硬盘的存储空间被划分为多个段,硬盘基于段管理日志,避免了硬盘以日志文件的形式存储日志,减少了日志写入过程中文件锁的开销,提高了日志写入的效率;除此之外,多个日志项可以被并行的写入一个段,避免了在日志文件中写入日志项所需的加锁过程,提高了日志并行写入硬盘的效率。In a first aspect, the present application provides a log management method, and the method can be applied to a processor, or the method can be applied to a communication device that can support a processor to implement the method, for example, the communication device includes a chip system, and the log management The method includes: first, the processor divides the storage space of the hard disk into a plurality of segments, one segment includes one or more physical blocks (blocks), and the one segment is used to store logs; secondly, the processor receives a first log write request and a second log write request, the first log write request includes a first log entry, and the second log write request includes a second log entry; finally, the processor writes the first log entry into the first log entry in the plurality of segments in parallel segment, and write the second log entry to the first segment. In the embodiment of the present application, since the storage space of the hard disk is divided into multiple segments, the hard disk manages logs based on segments, which avoids the hard disk from storing logs in the form of log files, reduces the overhead of file locks in the log writing process, and improves the The efficiency of log writing is improved; in addition, multiple log items can be written to a segment in parallel, avoiding the locking process required to write log items in the log file, and improving the parallel writing of logs to the hard disk. efficiency.
本申请实施例中的日志是指业务数据,或业务数据的副本或快照或克隆等。The log in this embodiment of the present application refers to business data, or a copy, snapshot, or clone of the business data.
作为一种可能的实现方式,在处理器将第一日志项写入第一段的过程中或者在将第二日志项写入第一段的过程中没有执行加锁机制。相较于通常技术中日志系统执行文件锁机制,导致多个日志项无法并行写入硬盘的问题,本申请的实施例所提供的日志管理方法,由于处理器没有对硬盘执行加锁机制,因此,处理器可以并行地将第一日志项和第二日志项写入硬盘的第一段,提高了处理器将多个日志项并行写入硬盘的效率。As a possible implementation manner, the processor does not perform a locking mechanism in the process of writing the first log entry into the first segment or during the process of writing the second log entry into the first segment. Compared with the problem that multiple log items cannot be written to the hard disk in parallel due to the log system implementing the file locking mechanism in the conventional technology, the log management method provided by the embodiment of the present application does not implement a locking mechanism on the hard disk because the processor does not. , the processor can write the first log item and the second log item to the first segment of the hard disk in parallel, which improves the efficiency of the processor writing multiple log items to the hard disk in parallel.
作为另一种可能的实现方式,该日志管理方法还包括:处理器将第一写日志请求的日志序列号LSN与日志索引进行匹配,确定第一写日志请求包括的第一日志项待写入的段是第一段。其中,该日志索引用于指示第一段与LSN的对应关系。处理器将写日志请求的LSN与该日志索引进行匹配,确定写日志请求包括的日志项所要写入的段,减少了日志写入所需的路径查询时间,提高了日志写入的效率。As another possible implementation manner, the log management method further includes: the processor matches the log sequence number LSN of the first log write request with the log index, and determines that the first log entry included in the first log write request is to be written The paragraph is the first paragraph. The log index is used to indicate the correspondence between the first segment and the LSN. The processor matches the LSN of the log write request with the log index, and determines the segment to be written in the log entry included in the log write request, which reduces the path query time required for log writing and improves the efficiency of log writing.
作为另一种可能的实现方式,日志索引包括第一索引和第二索引,第一索引用于指示第一段在硬盘中的存储地址范围,第二索引用于至少一个存储地址范围中每个日志项的LSN和存储地址之间的对应关系。As another possible implementation manner, the log index includes a first index and a second index, the first index is used to indicate the storage address range of the first segment in the hard disk, and the second index is used for each of the at least one storage address range The correspondence between the LSN of the log entry and the storage address.
上述处理器将LSN与日志索引进行匹配确定第一段的过程可以包括:处理器判断LSN与第三日志项的LSN是否连续,第三日志项为第二索引记录的任意一个日志项;若LSN与第三日志项的LSN连续,处理器将第三日志项所在的段作为第一段;若LSN与第三日志项的LSN不连续,处理器将LSN与第一索引进行匹配确定第一段,第一段中第一个日志项的LSN与第一写日志请求的LSN匹配。由于处理器的缓存的存储容量较小,使得缓存中无法存储大量的索引数据,在本申请实施例所提供的日志管理方法中,日志索引包括第一索引和第二索引,处理器可以先对第一索引和第二索引中任一个进行优先匹配,若匹配成功,则可以避免处理器查找日志索引中所有的数据,减少日志写入所需的路径查询时间,提高日志写入效率。The process that the above-mentioned processor matches the LSN and the log index to determine the first segment may include: the processor determines whether the LSN of the LSN and the third log item are continuous, and the third log item is any log item recorded by the second index; It is continuous with the LSN of the third log entry, and the processor uses the segment where the third log entry is located as the first segment; if the LSN is not continuous with the LSN of the third log entry, the processor matches the LSN with the first index to determine the first segment. , the LSN of the first log entry in the first segment matches the LSN of the first log write request. Since the storage capacity of the cache of the processor is small, a large amount of index data cannot be stored in the cache. In the log management method provided by the embodiment of the present application, the log index includes a first index and a second index. Any one of the first index and the second index is preferentially matched. If the match is successful, the processor can be prevented from searching for all data in the log index, the path query time required for log writing is reduced, and the log writing efficiency is improved.
在日志读取的过程中,处理器也可以先将读日志请求的LSN与第二索引进行匹配,若匹配成功(命中),则处理器可以依据第二索引确定读日志请求所要读取的日志项所在的存储地址,减少了日志读取所需的路径查询时间,提高了日志读取的效率。若读日志请求的LSN未在第二索引中命中,则处理器可以依据第一索引确定读日志请求所要读取的日志段,通过遍历该日志段得到读日志请求对应的日志项,避免了处理器将在文件系统中查询读日志请求的存储地址,提高了日志读取的效率。During the log reading process, the processor may also first match the LSN of the log read request with the second index. If the match is successful (hit), the processor may determine the log to be read by the log read request according to the second index The storage address where the item is located reduces the path query time required for log reading and improves the efficiency of log reading. If the LSN of the log read request is not hit in the second index, the processor can determine the log segment to be read by the log read request according to the first index, and obtain the log entry corresponding to the read log request by traversing the log segment, avoiding processing The server will query the storage address of the log read request in the file system, which improves the efficiency of log reading.
作为另一种可能的实现方式,日志索引存储在缓存中。该缓存可以是处理器的内存储器。在日志写入过程中,处理器中的处理单元可以读取缓存中的日志索引,从而快速确定写日志请求包括的日志项所要写入的段,减少了日志写入所需的路径查询时间,提高了日志写入的效率。As another possible implementation, the log index is stored in the cache. The cache may be the internal memory of the processor. During the log writing process, the processing unit in the processor can read the log index in the cache, so as to quickly determine the segment to be written in the log entry included in the log write request, and reduce the path query time required for log writing. The efficiency of log writing is improved.
作为另一种可能的实现方式,第一日志项包括描述信息和数据信息,描述信息包括第一写日志请求的LSN、日志项长度以及日志项长度校验和,数据信息用于指示第一日志项记录的日志内容。该日志项长度校验和用于确定该第一日志项的完整性和准确性,日志项长度用于确定第一日志项所占据的存储空间大小,LSN用于指示第一写日志请求的日志添加操作的序号。在一些可能的示例中,第一日志项包括的描述信息也可以称为第一日志项的元数据信息。As another possible implementation manner, the first log entry includes description information and data information, the description information includes the LSN of the first log write request, the length of the log entry, and the checksum of the length of the log entry, and the data information is used to indicate the first log The log content recorded by the item. The log entry length checksum is used to determine the integrity and accuracy of the first log entry, the log entry length is used to determine the size of the storage space occupied by the first log entry, and the LSN is used to indicate the log of the first log write request Add the sequence number of the operation. In some possible examples, the description information included in the first log entry may also be referred to as metadata information of the first log entry.
作为另一种可能的实现方式,上述处理器将第一日志项写入第一段的过程,包括:处理器依据第一写日志请求的LSN生成起始存储地址,起始存储地址处于第一段的存储地址范围;进而,处理器依据起始存储地址将第一日志项写入第一段。在处理器将日志项写入硬盘的过程中,首先依据写日志请求的LSN生成起始存储地址,再依据起始存储地址将写日志请求包括的日志项写入硬盘中,避免了处理器随机的将日志项写入硬盘,保证了日志写入的准确性。As another possible implementation manner, the process in which the processor writes the first log entry into the first segment includes: the processor generates a starting storage address according to the LSN of the first log write request, and the starting storage address is in the first log entry. The storage address range of the segment; further, the processor writes the first log entry into the first segment according to the starting storage address. In the process of writing the log items to the hard disk, the processor first generates the initial storage address according to the LSN of the log write request, and then writes the log items included in the log write request to the hard disk according to the initial storage address. The log entries are written to the hard disk to ensure the accuracy of log writing.
作为另一种可能的实现方式,在处理器依据第一写日志请求的LSN生成起始存储地址之 后,该日志管理方法还包括:处理器向备份设备发送第一写日志请求的LSN和起始存储地址。在日志系统具有多个存储设备的情况下,若处理器为主副本节点(简称:主节点),主节点向从副本节点(简称:从节点)发送写日志请求的LSN和起始存储地址,并由从节点依据该写日志请求的LSN和起始存储地址,将写日志请求包括的日志项写入第一段中,避免了主节点的日志写入完成后再去从节点备份,提高了多写场景的写入效率。As another possible implementation manner, after the processor generates the start storage address according to the LSN of the first log write request, the log management method further includes: the processor sends the LSN and the start address of the first log write request to the backup device storage address. In the case where the log system has multiple storage devices, if the processor is the master replica node (referred to as: master node), the master node sends the LSN and starting storage address of the log write request to the slave replica node (referred to as: slave node), And the slave node writes the log items included in the log write request into the first segment according to the LSN and the starting storage address of the log write request, avoiding the need for the master node to go to the slave node for backup after the log writing is completed. Write efficiency for multi-write scenarios.
作为另一种可能的实现方式,在处理器接收第一写日志请求之后,该日志管理方法还包括:处理器接收备份设备发送的第一写日志请求的LSN和起始存储地址,并依据第一写日志请求的LSN和起始存储地址,将第一日志项写入第一段。在日志系统具有多个存储设备的情况下,若处理器为从节点,处理器在接收到客户端发送的写日志请求之后,还可以接收备份设备(主节点)发送的写日志请求的LSN和起始存储地址,并由处理器(从节点)依据该写日志请求的LSN和起始存储地址,将写日志请求包括的日志项写入第一段中,避免了主节点的日志写入完成后再去从节点备份,提高了多写场景的写入效率。As another possible implementation manner, after the processor receives the first log write request, the log management method further includes: the processor receives the LSN and the starting storage address of the first log write request sent by the backup device, and according to the first log write request Once the LSN and starting storage address of the log request are written, the first log entry is written into the first segment. When the log system has multiple storage devices, if the processor is a slave node, after receiving the log write request sent by the client, the processor can also receive the LSN and the log write request sent by the backup device (master node). The starting storage address, and the processor (slave node) writes the log items included in the log writing request into the first segment according to the LSN and starting storage address of the log write request, avoiding the completion of log writing on the master node. Then go to the slave node for backup, which improves the writing efficiency of multi-write scenarios.
作为另一种可能的实现方式,该日志管理方法还包括:处理器向客户端发送日志写入响应,该日志写入响应用于指示已将第一日志和第二日志写入第一段。如此,客户端可以依据处理器反馈的日志写入响应确定本轮日志添加操作已经完成,避免客户端重复向日志系统发送写日志请求,造成写日志请求的重复备份,节省日志系统的存储资源,提高日志系统的存储资源利用率。As another possible implementation manner, the log management method further includes: the processor sends a log write response to the client, where the log write response is used to indicate that the first log and the second log have been written to the first segment. In this way, the client can determine that the current round of log addition operation has been completed according to the log write response fed back by the processor, so as to avoid the client from repeatedly sending log write requests to the log system, resulting in repeated backups of log write requests and saving the storage resources of the log system. Improve the storage resource utilization of the log system.
作为另一种可能的实现方式,处理器将第一日志项写入第一段,包括:在第一段的剩余存储空间小于第一写日志请求的日志项长度的情况下,处理器将第一写日志请求的一部分内容写入第一段,将第一写日志请求的另一部分内容写入第二段,第二段为硬盘中与第一段具有被连续读取的关联关系的段;进而,处理器将硬盘中的日志尾地址设置为第二段中第一个日志项的起始存储地址。在本申请的实施例中,日志尾地址是以最后一个日志所在的日志段的段首日志项的起始存储地址来表示的。As another possible implementation manner, the processor writes the first log entry into the first segment, including: when the remaining storage space of the first segment is less than the log entry length of the first log write request, the processor writes the first log entry into the first segment. One part of the log write request is written into the first segment, and another part of the first log write request is written into the second segment, and the second segment is the segment in the hard disk that has an association relationship with the first segment that is continuously read; Further, the processor sets the log tail address in the hard disk as the start storage address of the first log entry in the second segment. In the embodiment of the present application, the log tail address is represented by the starting storage address of the log entry at the segment head of the log segment where the last log is located.
在本申请的实施例中,对于日志添加操作,只有当日志项需要被存储到两个日志段,其中一个日志段是新分配的日志段(如上述的第二段)时,才需要更新日志尾所在日志段的起始存储地址。如此,日志尾地址可以用日志尾所在日志段的起始存储地址来表示,避免了文件系统中每次添加日志都需要更新日志尾地址的过程,减少了日志添加所需的日志尾地址的随机小写操作,提高了日志写入的效率。In the embodiment of the present application, for the log adding operation, only when the log entry needs to be stored in two log segments, one of which is a newly allocated log segment (such as the second segment above), the log needs to be updated The starting storage address of the log segment where the tail is located. In this way, the log tail address can be represented by the starting storage address of the log segment where the log tail is located, which avoids the need to update the log tail address every time a log is added in the file system, and reduces the randomness of the log tail address required for log addition. Lowercase operations improve the efficiency of log writing.
作为另一种可能的实现方式,在处理器依据写日志请求的LSN生成起始存储地址之前,该日志管理方法还包括:处理器判断写日志请求的日志项长度是否小于或等于硬盘的日志读写单位,该硬盘的日志读写单位是指处理器读写硬盘中日志项的最小数据粒度。若写日志请求的日志项长度小于或等于硬盘的日志读写单位,则处理器执行依据写日志请求的LSN生成起始存储地址的步骤;若写日志请求的日志项长度大于硬盘的日志读写单位,则处理器将写日志请求划分为多个子日志,多个子日志中每个子日志的日志项长度与日志读写单位一致。最后,处理器依据写日志请求的LSN生成多个子日志中每个子日志的起始存储地址。在写日志请求包括的日志项的日志项长度较大的情况下,由于处理器可以依据硬盘的日志读写单位写入多个子日志,即使在处理器直接将写日志请求包括的日志项的过程中硬盘和处理器断电,已经被处理器写入硬盘的子日志不会被处理器重复写入(或读取),减少了硬盘的存储资源消耗,提高了硬盘的存储资源利用效率。As another possible implementation, before the processor generates the starting storage address according to the LSN of the log write request, the log management method further includes: the processor determines whether the length of the log entry of the log write request is less than or equal to the log read length of the hard disk. Write unit, the log read/write unit of the hard disk refers to the minimum data granularity of the log entries in the hard disk read and written by the processor. If the log entry length of the log write request is less than or equal to the log read/write unit of the hard disk, the processor performs the step of generating the starting storage address according to the LSN of the log write request; if the log entry length of the log write request is greater than the log read/write unit of the hard disk unit, the processor divides the log write request into multiple sub-logs, and the log entry length of each sub-log in the multiple sub-logs is the same as the log read-write unit. Finally, the processor generates a starting storage address of each sub-log in the multiple sub-logs according to the LSN of the log write request. In the case where the log entry length of the log entry included in the log write request is large, since the processor can write multiple sub-logs according to the log read/write unit of the hard disk, even when the processor directly writes the log entry included in the log write request When the medium hard disk and the processor are powered off, the sub-logs that have been written to the hard disk by the processor will not be repeatedly written (or read) by the processor, which reduces the storage resource consumption of the hard disk and improves the storage resource utilization efficiency of the hard disk.
在本申请的实施例中,处理器可以依据硬盘的日志读写单位将写日志请求包括的待写入日志项进行拆分,进而,处理器原子地生成每个子日志的起始存储地址,由于处理器基于未采用文件系统的日志段粒度读写日志,因此,处理器无需为日志段进行加锁,从而实现了处理器并行追加写入硬盘的过程,减少日志写入所需的时间,提高了日志写入的效率。In the embodiment of the present application, the processor may split the log items to be written included in the log write request according to the log read/write unit of the hard disk, and further, the processor atomically generates the starting storage address of each sub-log, because The processor reads and writes logs based on the granularity of log segments that do not use the file system. Therefore, the processor does not need to lock the log segments, thus realizing the process of the processor adding and writing to the hard disk in parallel, reducing the time required for log writing and improving the efficiency of log writing.
第二方面,本申请提供一种日志管理装置,有益效果可以参见第一方面中任一方面的描述,此处不再赘述。所述日志管理装置具有实现上述第一方面中任一方面的方法实例中行为的功能。所述功能可以通过硬件实现,也可以通过硬件执行相应的软件实现。所述硬件或软件包括一个或多个与上述功能相对应的模块。在一个可能的设计中,该日志管理装置可应用于处理器,或者该日志管理装置可应用于可以支持处理器实现该方法的通信设备,例如该通信设备包括芯片系统,该日志管理装置包括:处理模块,用于将硬盘的存储空间划分为多个段,一个段包括一个或多个物理块,一个段用于存储日志;通信模块,用于接收第一写日志请求和第二写日志请求,第一写日志请求包括第一日志项,第二写日志请求包括第二日志项;处理模块,还用于并行地将第一日志项写入多个段中的第一段,以及将第二日志项写入第一段。In the second aspect, the present application provides a log management device, and the beneficial effects can be found in the description of any aspect of the first aspect, which will not be repeated here. The log management apparatus has the function of implementing the behavior in the method example of any one of the above-mentioned first aspects. The functions can be implemented by hardware, or can be implemented by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above functions. In a possible design, the log management apparatus can be applied to a processor, or the log management apparatus can be applied to a communication device that can support the processor to implement the method. For example, the communication device includes a chip system, and the log management apparatus includes: The processing module is used to divide the storage space of the hard disk into multiple segments, one segment includes one or more physical blocks, and one segment is used to store logs; the communication module is used to receive the first log write request and the second log write request , the first log write request includes the first log entry, and the second log write request includes the second log entry; the processing module is further configured to write the first log entry into the first segment of the multiple segments in parallel, and write the first log entry into the first segment in parallel. Two log entries are written to the first segment.
作为一种可选的实现方式,在将第一日志项写入第一段的过程中或者在将第二日志项写入第一段的过程中没有执行加锁机制。As an optional implementation manner, no locking mechanism is implemented in the process of writing the first log entry into the first segment or during the process of writing the second log entry into the first segment.
作为另一种可选的实现方式,日志管理装置还包括:索引模块,用于将第一写日志请求的日志序列号LSN与日志索引进行匹配,确定第一写日志请求包括的第一日志项待写入的段是第一段,日志索引用于指示第一段与LSN的对应关系。As another optional implementation manner, the log management apparatus further includes: an index module, configured to match the log sequence number LSN of the first log write request with the log index, and determine the first log item included in the first log write request The segment to be written is the first segment, and the log index is used to indicate the correspondence between the first segment and the LSN.
作为另一种可选的实现方式,日志索引包括第一索引和第二索引,第一索引用于指示第一段在硬盘中的存储地址范围,第二索引用于至少一个存储地址范围中每个日志项的LSN和存储地址之间的对应关系。索引模块,具体用于判断LSN与第三日志项的LSN是否连续,第三日志项为第二索引记录的任意一个日志项;若LSN与第三日志项的LSN连续,索引模块,具体用于将第三日志项所在的段作为第一段;若LSN与第三日志项的LSN不连续,索引模块,具体用于将LSN与第一索引进行匹配,确定第一段,第一段中第一个日志项的LSN与第一写日志请求的LSN匹配。As another optional implementation manner, the log index includes a first index and a second index, the first index is used to indicate the storage address range of the first segment in the hard disk, and the second index is used for each storage address range in at least one storage address range. The correspondence between the LSN and storage address of each log entry. The index module is specifically used to judge whether the LSN of the third log entry is continuous, and the third log entry is any log entry recorded by the second index; if the LSN is continuous with the LSN of the third log entry, the index module is specifically used for Take the segment where the third log entry is located as the first segment; if the LSN is not continuous with the LSN of the third log entry, the indexing module is specifically used to match the LSN with the first index, and determine the first segment, the first segment in the first segment. The LSN of a log entry matches the LSN of the first log write request.
作为另一种可选的实现方式,日志索引存储在缓存中。As another optional implementation, the log index is stored in the cache.
作为另一种可选的实现方式,第一日志项包括描述信息和数据信息,描述信息包括第一写日志请求的LSN、日志项长度以及日志项长度校验和,数据信息用于指示第一日志项记录的日志内容。As another optional implementation manner, the first log entry includes description information and data information, the description information includes the LSN of the first log write request, the length of the log entry, and the checksum of the length of the log entry, and the data information is used to indicate the first log entry. The log content recorded by the log entry.
作为另一种可选的实现方式,处理模块,具体用于依据第一写日志请求的LSN生成起始存储地址,起始存储地址处于第一段的存储地址范围;处理模块,具体用于依据起始存储地址将第一日志项写入第一段。As another optional implementation manner, the processing module is specifically configured to generate a starting storage address according to the LSN of the first log write request, and the starting storage address is in the storage address range of the first segment; The starting storage address writes the first log entry to the first segment.
作为另一种可选的实现方式,通信模块,还用于向备份设备发送第一写日志请求的LSN和起始存储地址。As another optional implementation manner, the communication module is further configured to send the LSN and the starting storage address of the first log write request to the backup device.
作为另一种可选的实现方式,通信模块,还用于接收备份设备发送的第一写日志请求的LSN和起始存储地址;处理模块,还用于依据第一写日志请求的LSN和起始存储地址,将第一日志项写入第一段。As another optional implementation manner, the communication module is further configured to receive the LSN and the initial storage address of the first log write request sent by the backup device; the processing module is further configured to receive the LSN and the initial storage address of the first log write request according to the first log write request. Start storage address, write the first log entry into the first segment.
作为另一种可选的实现方式,通信模块,还用于向客户端发送日志写入响应,日志写入 响应用于指示已将第一日志和第二日志写入第一段。As another optional implementation manner, the communication module is further configured to send a log write response to the client, where the log write response is used to indicate that the first log and the second log have been written to the first segment.
第三方面,本申请提供一种芯片,包括存储器和处理器,存储器用于存储计算机指令,当处理器从存储器中调用并运行计算机指令时,实现第一方面和第一方面中任一种可能实现方式的日志管理方法的操作步骤。In a third aspect, the present application provides a chip, including a memory and a processor, the memory is used to store computer instructions, and when the processor calls and runs the computer instructions from the memory, any one of the first aspect and the first aspect is possible. Operation steps of the log management method of the implementation.
第四方面,本申请提供一种通信设备,包括第三方面所述的芯片,该芯片包括处理器和存储器,存储器用于存储计算机指令,当处理器执行该计算机指令时,以使通信设备实现第一方面和第一方面中任一种可能实现方式的日志管理方法的操作步骤。In a fourth aspect, the present application provides a communication device, including the chip described in the third aspect, the chip includes a processor and a memory, and the memory is used for storing computer instructions. When the processor executes the computer instructions, the communication device realizes Operation steps of the log management method of the first aspect and any possible implementation manner of the first aspect.
示例的,该通信设备可以是网卡、服务器或桌面计算机等。For example, the communication device may be a network card, a server or a desktop computer, and so on.
第五方面,本申请提供一种计算机可读存储介质,存储介质中存储有计算机程序或指令,当计算机程序或指令被处理器或通信设备执行时,实现第一方面和第一方面中任一种可能实现方式的日志管理方法的操作步骤。In a fifth aspect, the present application provides a computer-readable storage medium, in which a computer program or instruction is stored, and when the computer program or instruction is executed by a processor or a communication device, any one of the first aspect and the first aspect is implemented Operation steps of a log management method of a possible implementation.
第六方面,本申请提供一种计算机程序产品,当计算机程序产品在计算机或服务器等通信设备上运行时,使得计算机或服务器执行第一方面和第一方面中任一种可能实现方式的日志管理方法的操作步骤。In a sixth aspect, the present application provides a computer program product that, when the computer program product runs on a communication device such as a computer or a server, enables the computer or server to perform the log management of the first aspect and any one of the possible implementations of the first aspect steps of the method.
第七方面,本申请提供一种日志系统,该通信系统包括至少一个服务器。首先,服务器将硬盘的存储空间划分为多个段,一个段包括一个或多个物理块(block),该一个段用于存储日志;其次,服务器接收客户端发送的第一写日志请求和第二写日志请求,该第一写日志请求包括第一日志项,该第二写日志请求包括第二日志项;最后,服务器并行地将第一日志项写入多个段中的第一段,以及将第二日志项写入第一段。在本申请的实施例中,由于硬盘的存储空间被划分为多个段,硬盘基于段管理日志,避免了硬盘以日志文件的形式存储日志,减少了日志写入过程中文件锁的开销,提高了日志写入的效率;除此之外,多个日志项可以被并行的写入一个段,避免了在日志文件中写入日志项所需的加锁过程,提高了日志并行写入硬盘的效率。In a seventh aspect, the present application provides a log system, and the communication system includes at least one server. First, the server divides the storage space of the hard disk into multiple segments, and one segment includes one or more physical blocks (blocks), which are used to store logs; secondly, the server receives the first log write request and the first log write request sent by the client. Two log write requests, the first log write request includes a first log entry, and the second log write request includes a second log entry; finally, the server writes the first log entry into the first segment of the multiple segments in parallel, and writing the second log entry to the first segment. In the embodiment of the present application, since the storage space of the hard disk is divided into multiple segments, the hard disk manages logs based on segments, which avoids the hard disk from storing logs in the form of log files, reduces the overhead of file locks in the log writing process, and improves the The efficiency of log writing is improved; in addition, multiple log items can be written to a segment in parallel, avoiding the locking process required to write log items in the log file, and improving the parallel writing of logs to the hard disk. efficiency.
本申请提供的日志系统可以实现第一方面和第一方面中任一种可能实现方式的日志管理方法的操作步骤,有益效果可以参见第一方面中任一方面的描述,此处不再赘述。The log system provided by the present application can implement the operation steps of the log management method of the first aspect and any possible implementation manner of the first aspect, and the beneficial effects can be found in the description of any aspect of the first aspect, which will not be repeated here.
本申请在上述各方面提供的实现方式的基础上,还可以进行进一步组合以提供更多实现方式。On the basis of the implementation manners provided by the above aspects, the present application may further combine to provide more implementation manners.
附图说明Description of drawings
图1为本申请提供的一种日志系统的结构示意图;1 is a schematic structural diagram of a log system provided by the application;
图2为本申请提供的一种日志管理方法的流程示意图一;FIG. 2 is a schematic flowchart one of a log management method provided by the present application;
图3为本申请提供的一种硬盘的划分示意图;3 is a schematic diagram of the division of a hard disk provided by the application;
图4为本申请提供的一种日志写入的示意图一;4 is a schematic diagram one of log writing provided by the application;
图5为本申请提供的一种日志管理方法的流程示意图二;5 is a second schematic flowchart of a log management method provided by the present application;
图6为本申请提供的一种日志写入的示意图二;6 is a schematic diagram 2 of log writing provided by the application;
图7为本申请提供的一种日志写入的示意图三;7 is a schematic diagram three of log writing provided by the application;
图8为本申请提供的一种日志管理方法的流程示意图三;8 is a schematic flowchart three of a log management method provided by the present application;
图9为本申请提供的一种日志管理装置的结构示意图;9 is a schematic structural diagram of a log management device provided by the present application;
图10为本申请提供的一种通信设备的结构示意图。FIG. 10 is a schematic structural diagram of a communication device provided by this application.
具体实施方式Detailed ways
为了下述各实施例的描述清楚简洁,首先给出相关技术的简要介绍。For the sake of clarity and conciseness in the description of the following embodiments, a brief introduction of related technologies is first given.
在通常的技术方案中,多读多写日志系统用于读写业务数据的预写式日志,基于日志系统提供的添加、读取等接口,上层应用只需要很少的工作量便可以方便地实现自身的应用层方法,同时由日志系统保证上层应用所需要的强一致性、数据持久性、故障原子性和事务隔离性等特征。In the usual technical solution, the multi-read and multi-write log system is used to read and write the write-ahead log of business data. Based on the add, read and other interfaces provided by the log system, the upper-layer application can conveniently use only a small amount of work. It implements its own application layer method, and at the same time, the log system ensures the characteristics of strong consistency, data durability, fault atomicity and transaction isolation required by the upper-layer application.
然而,基于闪存阵列的分布式日志系统(a shared log design for flash clusters,CORFU)以文件的形式存储日志,每个日志文件存储特定数目(例如,1000个)的日志项,日志项是用于指示日志中至少一次数据操作(如业务数据写入)记录的数据文件。通常,CORFU使用独立的文件存储日志系统元数据,对于单个日志项追加操作而言,CORFU需要对日志项所在的日志段加锁,并行读写性能差。最后,对于所有的日志追加操作,CORFU都需要将新日志项所要写入的日志文件进行加锁,导致日志写入速度较慢。However, a distributed log system based on flash arrays (a shared log design for flash clusters, CORFU) stores logs in the form of files, each log file stores a specific number (eg, 1000) of log entries, which are used for Indicates the data file recorded in at least one data operation (such as business data write) in the log. Usually, CORFU uses an independent file to store the metadata of the log system. For a single log item append operation, CORFU needs to lock the log segment where the log item is located, and the parallel read and write performance is poor. Finally, for all log append operations, CORFU needs to lock the log file to which the new log entry is to be written, resulting in slower log writing speed.
下面将结合附图对本申请实施例的实施方式进行详细阐述。The implementation of the embodiments of the present application will be described in detail below with reference to the accompanying drawings.
图1为本申请提供的一种日志系统的结构示意图,该日志系统100包括至少一个服务器,客户端120可以利用网络访问日志系统100中的服务器以存取日志数据,该网络的通信功能可以由交换机或路由器实现。在一种可能的示例中,客户端也可以通过有线连接与服务器通信,例如,快捷外围组件互连(peripheral component interconnect express,PCIe)高速总线。1 is a schematic structural diagram of a log system provided by the present application, the log system 100 includes at least one server, and the client 120 can access the log data by using a network to access the server in the log system 100. The communication function of the network can be controlled by Switch or router implementation. In one possible example, the client may also communicate with the server through a wired connection, such as a peripheral component interconnect express (PCIe) high-speed bus.
客户端120可以是运行有应用程序的计算机,该运行有应用程序的计算机可以是物理机,也可以是虚拟机。例如,若该运行有应用程序的计算机为物理计算设备,该物理计算设备可以是服务器或终端(Terminal)。其中,终端也可以称为终端设备、用户设备(user equipment,UE)、移动台(mobile station,MS)、移动终端(mobile terminal,MT)等。终端可以是手机、平板电脑、笔记本电脑、桌面电脑、个人通信业务(personal communication service,PCS)电话、台式计算机、虚拟现实(Virtual Reality,VR)终端设备、增强现实(Augmented Reality,AR)终端设备、工业控制(industrial control)中的无线终端、无人驾驶(self driving)中的无线终端、远程手术(remote medical surgery)中的无线终端、智能电网(smart grid)中的无线终端、运输安全(transportation safety)中的无线终端、智慧城市(smart city)中的无线终端、智慧家庭(smart home)中的无线终端等等。本申请的实施例对客户端120所采用的具体技术和具体设备形态不做限定。The client 120 may be a computer running an application program, and the computer running the application program may be a physical machine or a virtual machine. For example, if the computer running the application program is a physical computing device, the physical computing device may be a server or a terminal. The terminal may also be referred to as terminal equipment, user equipment (UE), mobile station (mobile station, MS), mobile terminal (mobile terminal, MT), and the like. The terminal can be a mobile phone, a tablet computer, a notebook computer, a desktop computer, a personal communication service (PCS) phone, a desktop computer, a virtual reality (Virtual Reality, VR) terminal device, an augmented reality (Augmented Reality, AR) terminal device , wireless terminals in industrial control, wireless terminals in self driving, wireless terminals in remote medical surgery, wireless terminals in smart grid, transportation safety ( Wireless terminals in transportation safety), wireless terminals in smart cities, wireless terminals in smart homes, and so on. The embodiments of the present application do not limit the specific technology and specific device form adopted by the client 120 .
本申请实施例所提供的日志系统可以为分布是存储系统或集中式存储系统。The log system provided by the embodiment of the present application may be a distributed storage system or a centralized storage system.
在一种可能的情形中,图1所示出的日志系统100可以为分布式存储系统。如图1所示,本实施例提供的分布式存储系统包括计算存储一体化的存储集群。存储集群包括一个或多个服务器(如图1所示出的服务器110A和服务器110B),各个服务器之间可以相互通信。In a possible situation, the log system 100 shown in FIG. 1 may be a distributed storage system. As shown in FIG. 1 , the distributed storage system provided in this embodiment includes a storage cluster integrating computing and storage. The storage cluster includes one or more servers (such as server 110A and server 110B as shown in FIG. 1 ), and each server can communicate with each other.
这里以图1所示出的服务器110A进行说明,服务器110A是一种既具有计算能力又具有存储能力的设备,如服务器、台式计算机等。示例的,先进精简指令(Advanced Reduced Instruction Set Computer Machines,ARM)服务器或者X86服务器都可以作为这里的服务器110A。在硬件上,如图1所示,服务器110A至少包括处理器112、内存113、网卡114和硬盘105。处理器112、内存113、网卡114和硬盘105之间通过总线连接。其中,处理器112和内存113用于提供计算资源。具体地,处理器112是一个中央处理器(central processing unit,CPU),用于处理来自服务器110A外部(应用服务器或者其他服务器)的数据访问请求(如 写日志请求),也用于处理服务器110A内部生成的请求。示例性的,处理器112接收写日志请求时,会将这些写日志请求中的数据暂时保存在内存113中。当内存113中的数据总量达到一定阈值时,处理器112将内存113中存储的数据发送给硬盘105进行持久化存储。除此之外,处理器112还用于数据进行计算或处理等。图1中仅示出了一个处理器112,在实际应用中,处理器112的数量往往有多个,其中,一个处理器112又具有一个或多个CPU核。本实施例不对CPU的数量,以及CPU核的数量进行限定。Here, the server 110A shown in FIG. 1 is used for description. The server 110A is a device having both computing capability and storage capability, such as a server, a desktop computer, and the like. For example, an Advanced Reduced Instruction Set Computer Machines (ARM) server or an X86 server can be used as the server 110A here. In terms of hardware, as shown in FIG. 1 , the server 110A at least includes a processor 112 , a memory 113 , a network card 114 and a hard disk 105 . The processor 112, the memory 113, the network card 114 and the hard disk 105 are connected through a bus. Among them, the processor 112 and the memory 113 are used to provide computing resources. Specifically, the processor 112 is a central processing unit (CPU), which is used to process data access requests (such as log write requests) from outside the server 110A (application server or other servers), and is also used to process the server 110A Internally generated request. Exemplarily, when the processor 112 receives log write requests, it temporarily stores the data in the log write requests in the memory 113 . When the total amount of data in the memory 113 reaches a certain threshold, the processor 112 sends the data stored in the memory 113 to the hard disk 105 for persistent storage. Besides, the processor 112 is also used for data calculation or processing. Only one processor 112 is shown in FIG. 1 . In practical applications, there are often multiple processors 112 , and one processor 112 has one or more CPU cores. This embodiment does not limit the number of CPUs and the number of CPU cores.
内存113是指与处理器直接交换数据的内部存储器,它可以随时读写数据,而且速度很快,作为操作系统或其他正在运行中的程序的临时数据存储器。内存包括至少两种存储器,例如内存既可以是随机存取存储器,也可以是只读存储器(Read Only Memory,ROM)。举例来说,随机存取存储器是动态随机存取存储器(Dynamic Random Access Memory,DRAM),或者存储级存储器(Storage Class Memory,SCM)。DRAM是一种半导体存储器,与大部分随机存取存储器(Random Access Memory,RAM)一样,属于一种易失性存储器(volatile memory)设备。SCM是一种同时结合传统储存装置与存储器特性的复合型储存技术,存储级存储器能够提供比硬盘更快速的读写速度,但存取速度上比DRAM慢,在成本上也比DRAM更为便宜。然而,DRAM和SCM在本实施例中只是示例性的说明,内存还可以包括其他随机存取存储器,例如静态随机存取存储器(Static Random Access Memory,SRAM)等。而对于只读存储器,举例来说,可以是可编程只读存储器(Programmable Read Only Memory,PROM)、可抹除可编程只读存储器(Erasable Programmable Read Only Memory,EPROM)等。另外,内存113还可以是双列直插式存储器模块或双线存储器模块(Dual In-line Memory Module,简称DIMM),即由动态随机存取存储器(DRAM)组成的模块,还可以是固态硬盘(Solid State Disk,SSD)。实际应用中,存储服务器110A中可配置多个内存113,以及不同类型的内存113。本实施例不对内存113的数量和类型进行限定。此外,可对内存113进行配置使其具有保电功能。保电功能是指系统发生掉电又重新上电时,内存113中存储的数据也不会丢失。具有保电功能的内存被称为非易失性存储器。The memory 113 refers to the internal memory that directly exchanges data with the processor, it can read and write data at any time, and is very fast, and serves as a temporary data storage for the operating system or other running programs. The memory includes at least two kinds of memory, for example, the memory can be either a random access memory or a read only memory (Read Only Memory, ROM). For example, the random access memory is Dynamic Random Access Memory (DRAM), or Storage Class Memory (SCM). DRAM is a semiconductor memory, and like most Random Access Memory (RAM), it belongs to a volatile memory (volatile memory) device. SCM is a composite storage technology that combines the characteristics of traditional storage devices and memory. Storage-level memory can provide faster read and write speeds than hard disks, but its access speed is slower than that of DRAM, and its cost is cheaper than DRAM. . However, the DRAM and the SCM are only exemplary descriptions in this embodiment, and the memory may also include other random access memories, such as static random access memory (Static Random Access Memory, SRAM) and the like. As for the read-only memory, for example, it may be Programmable Read Only Memory (PROM), Erasable Programmable Read Only Memory (EPROM), and the like. In addition, the memory 113 may also be a Dual In-line Memory Module (Dual In-line Memory Module, DIMM for short), that is, a module composed of Dynamic Random Access Memory (DRAM), or a solid state drive (Solid State Disk, SSD). In practical applications, multiple memories 113 and different types of memories 113 may be configured in the storage server 110A. This embodiment does not limit the quantity and type of the memory 113 . In addition, the memory 113 can be configured to have a power saving function. The power saving function means that when the system is powered off and then powered on again, the data stored in the memory 113 will not be lost. Memory with a power-saving function is called non-volatile memory.
硬盘105用于提供存储资源,例如存储日志等。它可以是磁盘或者其他类型的存储介质,例如固态硬盘或者叠瓦式磁记录硬盘等。示例的,硬盘105可以是基于非易失性内存主机控制器接口规范(Non-Volatile Memory Express,NVMe)的固态硬盘,如NVMe SSD。The hard disk 105 is used for providing storage resources, such as storing logs and the like. It can be a magnetic disk or other type of storage medium, such as a solid state drive or a shingled magnetic recording hard drive. For example, the hard disk 105 may be a solid state disk based on a non-volatile memory host controller interface specification (Non-Volatile Memory Express, NVMe), such as an NVMe SSD.
服务器110A中的网卡114用于与客户端120或其他应用服务器(如图1所示出的服务器110B)通信。The network card 114 in the server 110A is used to communicate with the client 120 or other application server (such as the server 110B shown in FIG. 1 ).
在一种实施方式中,处理器112的功能可以卸载到网卡114上。换言之,在该种实施方式中,处理器112不执行日志读写的操作,而是由网卡114来完成日志读写、地址转换以及其他计算功能。In one embodiment, the functionality of processor 112 may be offloaded to network card 114 . In other words, in this embodiment, the processor 112 does not perform log reading and writing operations, but the network card 114 performs log reading and writing, address translation, and other computing functions.
这里以图1所示出的服务器110B为例进行说明,图1所示出的网卡114可以包括处理单元1141和内存1142。此时,网卡114是一个智能网卡。处理单元1141可以是CPU,也可以是其他芯片,该其他芯片可以是,但不限于数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现场可编程门阵列(Field Programmable Gate Array,FPGA)或者其它可编程逻辑器件、晶体管逻辑器件,硬件部件或者其任意组合。通用处理器可以是微处理器,也可以是任何常规的处理器。Here, the server 110B shown in FIG. 1 is used as an example for description. The network card 114 shown in FIG. 1 may include a processing unit 1141 and a memory 1142 . At this point, the network card 114 is an intelligent network card. The processing unit 1141 may be a CPU or other chips, and the other chips may be, but not limited to, a digital signal processor (Digital Signal Processor, DSP), an application specific integrated circuit (ASIC), a field programmable gate Field Programmable Gate Array (FPGA) or other programmable logic devices, transistor logic devices, hardware components or any combination thereof. A general-purpose processor may be a microprocessor or any conventional processor.
内存1142可以是指是指与处理器直接交换数据的内部存储器,它可以随时读写日志,而 且速度很快,作为操作系统或其他正在运行中的程序的临时数据存储器。内存1142既可以是随机存取存储器,也可以是ROM。举例来说,随机存取存储器是DRAM或者SCM。内存还可以包括其他随机存取存储器,例如SRAM等。而对于只读存储器,举例来说,可以是PROM、EPROM等。另外,内存1142还可以是DIMM,即由DRAM组成的模块,还可以是SSD。实际应用中,网卡114中可配置多个内存1142,以及不同类型的内存1142。本实施例不对内存1142的数量和类型进行限定。此外,可对内存1142进行配置使其具有保电功能。保电功能是指系统发生掉电又重新上电时,内存1142中存储的数据也不会丢失。具有保电功能的内存被称为非易失性存储器。The memory 1142 may refer to the internal memory that directly exchanges data with the processor, it can read and write logs at any time, and is very fast, as a temporary data storage for the operating system or other running programs. The memory 1142 may be either random access memory or ROM. For example, random access memory is DRAM or SCM. The memory may also include other random access memories such as SRAM and the like. As for the read-only memory, for example, it can be PROM, EPROM and so on. In addition, the memory 1142 may also be a DIMM, that is, a module composed of DRAM, and may also be an SSD. In practical applications, multiple memories 1142 and different types of memories 1142 may be configured in the network card 114 . This embodiment does not limit the quantity and type of the memory 1142 . In addition, the memory 1142 can be configured to have a power saving function. The power saving function means that the data stored in the memory 1142 will not be lost when the system is powered off and then powered on again. Memory with a power-saving function is called non-volatile memory.
例如,在某些应用场景中,网卡114也可能具有持久化内存介质,如持久性内存(persistent memory,PM),或者非易失性随机访问存储器(non-volatile random access memory,NVRAM),或者相变存储器(phase change memory,PCM)等。CPU用于执行地址转换以及读写日志等操作。内存用于临时存储将要写入硬盘105的数据,或者从硬盘105读取出来将要发送给控制器的数据。也可以是一个可编程的电子部件,例如数据处理单元(data processing unit,DPU)。DPU具有CPU的通用性和可编程性,但更具有专用性,可以在网络数据包,存储请求或分析请求上高效运行。DPU通过较大程度的并行性(需要处理大量请求)与CPU区别开来。可选的,这里的DPU也可以替换成图形处理单元(graphics processing unit,GPU)、嵌入式神经网络处理器(neural-network processing units,NPU)等处理芯片。网卡114和硬盘105之间没有归属关系,网卡114可访问网卡114所在的服务器110B中任意一个硬盘105,因此在存储空间不足时扩展硬盘会较为便捷。For example, in some application scenarios, the network card 114 may also have persistent memory media, such as persistent memory (PM), or non-volatile random access memory (NVRAM), or Phase change memory (phase change memory, PCM), etc. The CPU is used to perform operations such as address translation and reading and writing logs. The memory is used to temporarily store data to be written into the hard disk 105 or read data from the hard disk 105 to be sent to the controller. It can also be a programmable electronic component, such as a data processing unit (DPU). The DPU has the generality and programmability of a CPU, but is more specialized and can operate efficiently on network packets, storage requests, or analytics requests. DPUs are distinguished from CPUs by a greater degree of parallelism (the need to handle a large number of requests). Optionally, the DPU here can also be replaced by a graphics processing unit (graphics processing unit, GPU), an embedded neural network processor (neural-network processing units, NPU) and other processing chips. There is no affiliation between the network card 114 and the hard disk 105, and the network card 114 can access any hard disk 105 in the server 110B where the network card 114 is located, so it is convenient to expand the hard disk when the storage space is insufficient.
智能网卡可以是通用型的智能网卡,例如配备8个处理器核和2×100千兆比特每秒(giga bits per second,Gb/s)的网络带宽的网卡,此类网卡可以运行完整的操作系统。The smart NIC can be a general-purpose smart NIC, such as a NIC with 8 processor cores and 2 x 100 giga bits per second (Gb/s) network bandwidth, which can run full operations system.
智能网卡还可以是面向特定应用的智能网卡,该网卡可以是基于FPGA或ASIC的智能网卡,例如用于深度神经网络加速的GPU和NPU等。关于服务器110B的其他硬件可以参考服务器110A的相关内容,此处不予赘述。The smart network card may also be an application-oriented smart network card, and the network card may be an FPGA- or ASIC-based smart network card, such as GPU and NPU for deep neural network acceleration. For other hardware of the server 110B, reference may be made to the relevant content of the server 110A, which will not be repeated here.
在另一种可能的情形中,本申请实施例所提供的日志系统也可以为计算存储分离的存储集群,该存储集群包括计算设备集群和存储设备集群,计算设备集群包括一个或多个计算设备,各个计算设备之间可以相互通信。计算设备可以是一种计算设备,如服务器、台式计算机或者存储阵列的控制器等。在硬件上,计算设备可以包括处理器、内存和网卡等。其中,处理器是一个CPU,用于处理来自计算设备外部的数据访问请求,或者计算设备内部生成的请求。示例性的,处理器接收用户发送的写日志请求时,会将这些写日志请求中的日志暂时保存在内存中。当内存中的日志数据总量达到一定阈值时,处理器将内存中存储的日志数据发送给存储设备进行持久化存储。除此之外,处理器还用于数据进行计算或处理,例如元数据管理、重复数据删除、数据压缩、虚拟化存储空间以及地址转换等。In another possible situation, the log system provided by this embodiment of the present application may also be a storage cluster separated from computing and storage, where the storage cluster includes a computing device cluster and a storage device cluster, and the computing device cluster includes one or more computing devices , each computing device can communicate with each other. The computing device may be a computing device, such as a server, a desktop computer, or a controller of a storage array, or the like. In hardware, computing devices may include processors, memory, and network cards, among others. The processor is a CPU for processing data access requests from outside the computing device, or requests generated inside the computing device. Exemplarily, when the processor receives a log write request sent by a user, it temporarily stores the log in the log write request in the memory. When the total amount of log data in the memory reaches a certain threshold, the processor sends the log data stored in the memory to the storage device for persistent storage. In addition, the processor is also used for data calculation or processing, such as metadata management, data deduplication, data compression, virtualized storage space, and address translation.
作为一种可选的实现方式,本申请实施例所提供的日志系统也可以为集中式存储系统。集中式存储系统的特点是有一个统一的入口,所有从外部设备来的数据都要经过这个入口,这个入口就是集中式存储系统的引擎。引擎是集中式存储系统中最为核心的部件,许多存储系统的高级功能都在其中实现。示例的,引擎中可以有一个或多个控制器,在一种可能的示例中,若引擎具有多个控制器,任意两个控制器之间可以具有镜像通道,实现任意两个控制器互为备份的功能,从而避免硬件故障导致集中式存储系统的不可用。引擎还包含前端接口 和后端接口,其中,前端接口用于与集中式存储系统中的计算设备通信,从而为计算设备提供存储服务。而后端接口用于与硬盘通信,以扩充集中式存储系统的容量。通过后端接口,引擎可以连接更多的硬盘,从而形成一个非常大的存储资源池。As an optional implementation manner, the log system provided by the embodiment of the present application may also be a centralized storage system. The characteristic of the centralized storage system is that there is a unified entrance through which all data from external devices must pass. This entrance is the engine of the centralized storage system. The engine is the core component of the centralized storage system, and many advanced functions of the storage system are implemented in it. Illustratively, there can be one or more controllers in the engine. In a possible example, if the engine has multiple controllers, any two controllers can have a mirror channel between them, so that any two controllers can communicate with each other. Backup function, thus avoiding the unavailability of centralized storage system caused by hardware failure. The engine also includes a front-end interface and a back-end interface, wherein the front-end interface is used to communicate with the computing devices in the centralized storage system, thereby providing storage services for the computing devices. The back-end interface is used to communicate with the hard disk to expand the capacity of the centralized storage system. Through the back-end interface, the engine can connect more hard disks, thus forming a very large storage resource pool.
为了提高日志写入的效率,下面在图1所示出的日志系统100的基础上,本申请实施例提供一种日志管理方法,请参见图2,图2为本申请提供的一种日志管理方法的流程示意图一,客户端21可以实现图1所示出的客户端120的功能,该日志管理方法由处理器22执行,该处理器22可以是图1所示出的服务器110A中的处理器112,也可以是服务器110B中网卡114包括的处理单元1141,该日志管理方法包括以下步骤。In order to improve the efficiency of log writing, on the basis of the log system 100 shown in FIG. 1 , an embodiment of the present application provides a log management method. Please refer to FIG. 2 . FIG. 2 provides a log management method for this application. First, the client 21 can implement the functions of the client 120 shown in FIG. 1 , and the log management method is executed by the processor 22, which can be the processing in the server 110A shown in FIG. 1 . The server 112 may also be the processing unit 1141 included in the network card 114 in the server 110B, and the log management method includes the following steps.
S210,处理器22将硬盘的存储空间划分为多个段。S210, the processor 22 divides the storage space of the hard disk into multiple segments.
该多个段是指硬盘中用于存储日志的多个日志段(log segment)。该多个段中的一个段包括一个或多个物理块,该一个段可以用于存储日志。The multiple segments refer to multiple log segments (log segments) in the hard disk for storing logs. One of the plurality of segments includes one or more physical blocks, and the one segment may be used to store logs.
这里以对图1所示出的硬盘105进行划分为例进行说明,如图3所示,图3为本申请提供的一种硬盘的划分示意图,该硬盘105可以是一个或多个闪存芯片(chip)的封装。一个闪存芯片(chip)内部可以包括一个或多个die,一个die可包含多个区域(plane)。如图3所示,一个die内部分成了2个Plane,而且2个Plane内的block编号是单双交叉的,因此在操作时,可以进行一单一双交叉操作来提升性能。一个plane包含多个物理块(block)。而一个block由若干个页(page)组成。以一个16千兆字节(giga bytes,GB)容量的闪存芯片为例,每4314*8=34512个cell逻辑上形成一个page,每个page中可以存放4千字节(kilo bytes,KB)的内容和218字节(byte,B)的错误检查和纠正(error correcting code,ECC)校验数据,page也是输入输出(input output,IO)操作的最小单位。每128个page组成一个block,每个2048个block组成一个plane,一整片闪存芯片由两个plane组成,一个plane存储奇数序号的block,另一个则存储偶数序号的block,两个plane可以并行操作。这只是一个示例,page的尺寸,block的容量,闪存芯片的容量都可以有不同的规格,本实施例不予限定。Here, the division of the hard disk 105 shown in FIG. 1 is used as an example for description. As shown in FIG. 3 , FIG. 3 is a schematic diagram of division of a hard disk provided by the present application. The hard disk 105 may be one or more flash memory chips ( chip) package. A flash memory chip (chip) may include one or more dies, and one die may include multiple planes. As shown in Figure 3, a die is internally divided into two Planes, and the block numbers in the two Planes are single and double crossover, so during operation, a single double crossover operation can be performed to improve performance. A plane contains multiple physical blocks (block). A block consists of several pages. Taking a flash memory chip with a capacity of 16 gigabytes (GB) as an example, every 4314*8=34512 cells logically form a page, and each page can store 4 kilobytes (kilo bytes, KB) The content and 218 bytes (byte, B) of error checking and correction (error correcting code, ECC) check data, page is also the smallest unit of input and output (input output, IO) operations. Every 128 pages form a block, and each 2048 blocks form a plane. A whole flash memory chip consists of two planes. One plane stores blocks with odd numbers, and the other stores blocks with even numbers. The two planes can be paralleled. operate. This is just an example, the size of the page, the capacity of the block, and the capacity of the flash memory chip may all have different specifications, which are not limited in this embodiment.
处理器22往block中写入数据,当一个block写满的时候,硬盘105的主控会挑选下一个Block继续写入。页(page)是数据写入的最小单位。换言之,主控是以页(page)为粒度往block里面写入数据的。block是数据擦除的最小单位;主控在擦除数据时,每次只能擦除整个block。The processor 22 writes data into the block, and when a block is full, the master controller of the hard disk 105 selects the next block to continue writing. A page is the smallest unit of data writing. In other words, the master writes data into the block at the granularity of pages. A block is the smallest unit of data erasure; when the master controller erases data, it can only erase the entire block at a time.
上述的一个段可以包括一个或多个物理块(block),如图3所示,第一包括2个物理块(block),第二段包括1个物理块(block)。值得注意的是,上述实施例仅为本申请提供的可能的实现方式,图3是以一个段包括整数个block为例进行说明的,但在另一些可能的示例中,一个段也可以包括部分block,例如,若一个block包括4个page,上述的一个段可以包括3个page或2个page,上述的一个段也可以包括1个block和3个page。The above-mentioned one segment may include one or more physical blocks (blocks). As shown in FIG. 3 , the first segment includes two physical blocks (blocks), and the second segment includes one physical block (block). It is worth noting that the above-mentioned embodiments are only possible implementations provided by the present application. FIG. 3 illustrates an example where a segment includes an integer number of blocks, but in other possible examples, a segment may also include parts block, for example, if a block includes 4 pages, the above-mentioned one segment can include 3 pages or 2 pages, and the above-mentioned one segment can also include 1 block and 3 pages.
在通常的技术方案中,由于CORFU采用文件系统来管理硬盘的存储空间,在日志文件的读写过程中,日志追加写和日志读取为简单的读写操作,无需复杂的语义,因此,CORFU采用文件系统会引入大量的文件管理开销,如文件锁(强制访问文件只能由一个用户或在任何特定时间访问),导致处理资源和存储资源的浪费。In the usual technical solution, since CORFU uses the file system to manage the storage space of the hard disk, in the process of reading and writing log files, log append writing and log reading are simple read and write operations without complex semantics. Therefore, CORFU Adopting a file system introduces a lot of file management overhead, such as file locks (mandatory access to files can only be accessed by one user or at any given time), resulting in a waste of processing and storage resources.
在日志读写过程中,相较于CORFU基于文件粒度为日志文件加文件锁,在本申请的实施例中,硬件的存储空间被划分为多个段,处理器可以基于段来管理日志,避免了为文件系统中的日志文件加文件锁的过程,减少了处理资源和存储资源的浪费,提高了日志读写的效 率。In the process of log reading and writing, compared to CORFU adding file locks to log files based on file granularity, in the embodiment of the present application, the hardware storage space is divided into multiple segments, and the processor can manage logs based on segments to avoid In order to add a file lock to the log file in the file system, the waste of processing resources and storage resources is reduced, and the efficiency of log reading and writing is improved.
在一种可能的情形中,处理器22划分硬盘的存储空间的过程可以只进行一次,示例的,若日志系统首次进行日志读写,则处理器22可以将日志系统中用于存储日志项的存储空间进行划分,得到上述的多个段。In a possible situation, the process of dividing the storage space of the hard disk by the processor 22 may be performed only once. For example, if the log system reads and writes logs for the first time, the processor 22 may use the log entries in the log system for storing log items. The storage space is divided to obtain the above-mentioned multiple segments.
在另一种可能的情形中,处理器22划分硬盘的存储空间的过程可以进行多次,示例的,日志系统中可以设置一个定时器,该定时器可以是一个计算机软件指令,当时间达到定时器设定的周期的情况下,处理器22对日志系统中硬盘的存储空间进行划分。In another possible situation, the process of dividing the storage space of the hard disk by the processor 22 may be performed multiple times. For example, a timer may be set in the log system, and the timer may be a computer software instruction. In the case of the period set by the processor, the processor 22 divides the storage space of the hard disk in the log system.
换句话说,处理器22对硬盘的存储空间进行划分的过程可以依据日志系统实际的使用需求进行设置或调整,本申请对此不予限定。例如,若处理器22接收到客户端发送的划分指令,则处理器22还可以依据该划分指令对硬盘的存储空间进行划分。In other words, the process of dividing the storage space of the hard disk by the processor 22 may be set or adjusted according to the actual usage requirements of the log system, which is not limited in this application. For example, if the processor 22 receives the division instruction sent by the client, the processor 22 may further divide the storage space of the hard disk according to the division instruction.
S220,客户端21向处理器22发送第一写日志请求和第二写日志请求。S220, the client 21 sends the first log write request and the second log write request to the processor 22.
本申请实施例所提供的写日志请求是指包括待写入日志项的数据写入请求,示例的,该第一写日志请求包括第一日志项,第二写日志请求包括第二日志项。The log write request provided by the embodiment of the present application refers to a data write request including a log entry to be written. For example, the first log write request includes a first log entry, and the second log write request includes a second log entry.
值得注意的是,本申请的实施例是以日志系统连接有一个客户端为例进行说明的,但在一些可能的示例中,多个写日志请求可以是两个或两个以上的客户端向处理器发送的,如上述的第一写日志请求和第二写日志请求可以是两个不同的客户端向处理器发送的。It is worth noting that the embodiments of this application are described by taking the log system connected to one client as an example, but in some possible examples, multiple log write requests may be sent by two or more clients to Sent by the processor, for example, the above-mentioned first log write request and second log write request may be sent to the processor by two different clients.
在一种可选的实现方式中,本申请提供的第一日志项包括描述信息和数据信息,该描述信息包括第一写日志请求的日志序列号(log sequencer number,LSN)、日志项长度(length)以及日志项长度校验和(log length checksum),该数据信息用于指示第一日志项记录的日志内容。In an optional implementation manner, the first log entry provided by this application includes description information and data information, and the description information includes a log sequencer number (log sequencer number, LSN) of the first log write request, a log entry length ( length) and the log length checksum (log length checksum), the data information is used to indicate the log content recorded by the first log item.
在本申请实施例提供的日志管理方法中,日志可以包括一个或多个日志项,一个日志段可以存储一个或多个日志项,每个日志项记录有该日志的部分日志内容,该日志内容是指日志中第一日志项记录的事件,例如,该第一日志项的日志内容可以是客户端在第一时间执行了应用程序(application,APP)的开启操作;又如,上述第二日志项的日志内容可以是客户端在第二时间执行了APP的关闭操作。本申请实施例中的日志是指业务数据,或业务数据的副本或快照或克隆等。In the log management method provided by the embodiment of the present application, the log may include one or more log items, a log segment may store one or more log items, and each log item records part of the log content of the log, and the log content Refers to the event recorded by the first log item in the log. For example, the log content of the first log item may be that the client performs the opening operation of the application (application, APP) at the first time; another example, the above-mentioned second log The log content of the item may be that the client performs the closing operation of the APP at the second time. The log in this embodiment of the present application refers to business data, or a copy, snapshot, or clone of the business data.
如图4所示,图4为本申请提供的一种日志写入的示意图一。该硬盘中的第一日志项包括描述信息和数据信息,该描述信息包括日志项长度校验和、日志项长度以及第一写日志请求的LSN。该日志项长度校验和用于确定该第一日志项的完整性和准确性,日志项长度用于确定第一日志项所占据的存储空间大小,LSN用于指示第一写日志请求的日志添加操作的序号。在一些可能的示例中,第一日志项包括的描述信息也可以称为第一日志项的元数据信息。As shown in FIG. 4 , FIG. 4 is a schematic diagram 1 of log writing provided by this application. The first log entry in the hard disk includes description information and data information, and the description information includes the log entry length checksum, the log entry length, and the LSN of the first log write request. The log entry length checksum is used to determine the integrity and accuracy of the first log entry, the log entry length is used to determine the size of the storage space occupied by the first log entry, and the LSN is used to indicate the log of the first log write request Add the sequence number of the operation. In some possible examples, the description information included in the first log entry may also be referred to as metadata information of the first log entry.
日志项包括的数据信息是指该日志项所记录的日志内容,通常情况下,日志项记录的日志内容可以是指硬盘的待存储数据的操作类型、接收该存储数据的时间,或该待存储数据的访问地址等中一种或几种的组合。该待存储数据是指硬盘要存储的内容数据,如该内容数据可以是流媒体文件。该待存储数据的格式与写日志请求所包含的日志项的格式不同。The data information included in the log entry refers to the log content recorded by the log entry. Usually, the log content recorded by the log entry can refer to the operation type of the data to be stored on the hard disk, the time when the stored data is received, or the data to be stored. One or a combination of data access addresses, etc. The data to be stored refers to content data to be stored on the hard disk, for example, the content data may be a streaming media file. The format of the data to be stored is different from the format of the log entry included in the log write request.
请继续参见图2,在处理器22接收到第一写日志请求和第二写日志请求之后,本申请实施例提供的日志管理方法还包括步骤S230。Please continue to refer to FIG. 2 , after the processor 22 receives the first log writing request and the second log writing request, the log management method provided by the embodiment of the present application further includes step S230.
S230,处理器22并行地将第一日志项写入多个段中的第一段,以及将第二日志项写入第一段。S230, the processor 22 writes the first log entry into the first segment of the plurality of segments in parallel, and writes the second log entry into the first segment.
在处理器将第一日志项写入第一段的过程中,或者在处理器将第二日志项写入第一段的过程中没有执行加锁机制。锁(lock)是一种同步机制,锁开销(lock overhead)包括锁占用的内存空间,处理器初始化和销毁锁、获取和释放锁的时间等。应用程序使用的锁越多,相应的锁开销越大。No locking mechanism is implemented during the process of the processor writing the first log entry into the first segment, or during the process of the processor writing the second log entry into the first segment. A lock is a synchronization mechanism, and the lock overhead includes the memory space occupied by the lock, the time it takes for the processor to initialize and destroy the lock, acquire and release the lock, etc. The more locks an application uses, the greater the corresponding lock overhead.
锁的粒度确定了每个锁所保护的数据量的大小,在通常的技术方案中,由于CORFU采用基于文件粒度的锁对日志文件进行加锁,因此,在多个日志项并行写入硬盘中日志文件的过程中,该日志文件被加锁,则CORFU每次只能将该多个日志项中一个日志项写入该日志文件中,导致该多个日志项的写入速度较慢。The granularity of the lock determines the amount of data protected by each lock. In a common technical solution, since CORFU uses file granularity-based locks to lock log files, multiple log items are written to the hard disk in parallel. During the log file process, if the log file is locked, CORFU can only write one log item of the multiple log items into the log file at a time, resulting in a slow writing speed of the multiple log items.
相较于通常技术中日志系统执行文件锁机制,导致多个日志项无法并行写入硬盘的问题,本申请的实施例所提供的日志管理方法,由于处理器没有对硬盘执行加锁机制,因此,处理器可以并行地将第一日志项和第二日志项写入硬盘的第一段,提高了处理器将多个日志项并行写入硬盘的效率。Compared with the problem that multiple log items cannot be written to the hard disk in parallel due to the log system implementing the file locking mechanism in the conventional technology, the log management method provided by the embodiment of the present application does not implement a locking mechanism on the hard disk because the processor does not. , the processor can write the first log item and the second log item to the first segment of the hard disk in parallel, which improves the efficiency of the processor writing multiple log items to the hard disk in parallel.
如此,在本申请实施例所提供的日志管理方法中,硬件的存储空间被划分为多个段,处理器可以基于段来管理日志,避免了为文件系统中的日志文件加文件锁的过程,减少了处理资源和存储资源的浪费,提高了日志读写的效率;此外,由于处理器没有对硬盘执行加锁机制,因此,处理器可以并行地将第一日志项和第二日志项写入硬盘的第一段,提高了处理器将多个日志项并行写入硬盘的效率。In this way, in the log management method provided by the embodiment of the present application, the storage space of the hardware is divided into multiple segments, and the processor can manage the logs based on the segments, avoiding the process of adding file locks to the log files in the file system, The waste of processing resources and storage resources is reduced, and the efficiency of log reading and writing is improved; in addition, since the processor does not perform a locking mechanism on the hard disk, the processor can write the first log entry and the second log entry in parallel The first segment of the hard disk improves the efficiency of the processor writing multiple log entries to the hard disk in parallel.
若上述实施例提供的日志管理方法中,处理器22为图1所示出的网卡114中的处理单元1141,则在日志读写的过程中,网卡114可以实现本申请所提供的日志管理方法。If in the log management method provided by the above embodiment, the processor 22 is the processing unit 1141 in the network card 114 shown in FIG. 1 , then in the process of log reading and writing, the network card 114 can implement the log management method provided by this application. .
在一种可能的示例中,网卡114采用直接内存访问(direct memory access,DMA)技术来访问数据。例如,在本示例中,处理单元1141利用DMA技术访问网卡114所在服务器110B中硬盘105的日志段以读写日志,实现直接硬盘访问,以减少在日志读写过程中,网卡114与处理器112的交互(如日志请求复制和传输等),提高了日志读写的效率。In one possible example, the network card 114 uses a direct memory access (DMA) technique to access data. For example, in this example, the processing unit 1141 uses the DMA technology to access the log segment of the hard disk 105 in the server 110B where the network card 114 is located to read and write the log, so as to realize direct hard disk access, so as to reduce the connection between the network card 114 and the processor 112 during the log reading and writing process. The interaction (such as log request replication and transmission, etc.) improves the efficiency of log reading and writing.
在另一种可能的示例中,网卡114采用远程直接内存访问(remote direct memory access,RDMA)技术来访问数据。例如,在本示例中,处理单元1141利用RDMA技术访问日志系统中除网卡114所在服务器服务器110A外的其他服务器110B中硬盘105的日志段以读写日志,实现远程直接硬盘访问,以减少在日志读写过程中,网卡114与该服务器110B中的处理器112交互,再由该服务器110B中的处理器112与该服务器110B的硬盘105交互的过程,提高了日志读写的效率。In another possible example, the network card 114 uses remote direct memory access (RDMA) technology to access data. For example, in this example, the processing unit 1141 uses the RDMA technology to access the log segment of the hard disk 105 in the server 110B other than the server 110A where the network card 114 is located in the log system to read and write the log, realize remote direct hard disk access, and reduce the number of logs in the log. During the reading and writing process, the network card 114 interacts with the processor 112 in the server 110B, and then the processor 112 in the server 110B interacts with the hard disk 105 of the server 110B, which improves the efficiency of log reading and writing.
如此,由服务器中网卡的处理单元来实现本申请实施例所提供的日志管理方法,可以减少服务器中CPU的处理资源消耗,从而提高服务器中CPU处理其他数据的效率。In this way, the log management method provided by the embodiments of the present application is implemented by the processing unit of the network card in the server, which can reduce the processing resource consumption of the CPU in the server, thereby improving the efficiency of processing other data by the CPU in the server.
作为一种可选的实现方式,在日志写入的过程中,处理器还可以对写日志请求进行排序,请继续参见图4,图4中的处理器可以实现本申请所提供的日志管理方法,该处理器中可以包括处理单元和内存储器,该内存储器中设置有排序器(sequencer),该排序器可以是一个计算机软件(如应用程序或线程等),该排序器集成有日志排序功能的硬件电路。该排序器可以为日志系统中的日志进行全局排序,使得日志系统中所有的日志是全局有序的,有利于日志系统中各服务器基于每个日志的LSN实现一致性快照、跨区的原子更新等操作As an optional implementation manner, in the process of log writing, the processor can also sort the log write requests, please continue to refer to FIG. 4 , the processor in FIG. 4 can implement the log management method provided by this application , the processor may include a processing unit and an internal memory, the internal memory is provided with a sequencer, the sequencer may be a computer software (such as an application program or a thread, etc.), and the sequencer is integrated with a log sorting function hardware circuit. The sorter can globally sort the logs in the log system, so that all logs in the log system are globally ordered, which is beneficial for each server in the log system to achieve consistent snapshots and cross-region atomic updates based on the LSN of each log. wait
如图4所示,硬盘的存储空间包括元数据区和日志段(segement)区域。As shown in FIG. 4, the storage space of the hard disk includes a metadata area and a log segment area.
该元数据区用于存储硬盘中每个日志段的元数据信息。如图4所示,该元数据区中的元 数据信息包括段头、头LSN和段尾,段头用于指示日志段在硬盘中的起始存储地址,头LSN用于指示日志段中第一个日志项的LSN,段尾用于指示日志段在硬盘中的结束存储地址。The metadata area is used to store the metadata information of each log segment in the hard disk. As shown in Figure 4, the metadata information in the metadata area includes segment header, header LSN and segment end. The LSN of a log entry, the segment tail is used to indicate the end storage address of the log segment on the hard disk.
该日志段区域被划分为3个日志段(第一段、第二段和第三段),每个日志段可以存储一个或多个日志项。如图4所示,第一段中存储有第三日志项。The log segment area is divided into 3 log segments (the first segment, the second segment, and the third segment), and each log segment can store one or more log entries. As shown in FIG. 4, a third log entry is stored in the first segment.
在处理器接收到第一写日志请求和第二写日志请求之后,由排序器对第一写日志请求和第二写日志请求进行排序,如第一写日志请求中第一日志项的LSN为第一LSN,第二写日志请求中第二日志项的LSN为第二LSN。After the processor receives the first log write request and the second log write request, the sorter sorts the first log write request and the second log write request. For example, the LSN of the first log entry in the first log write request is The first LSN, the LSN of the second log entry in the second log write request is the second LSN.
值得注意的是,图4所示出的排序器是设置在处理器的内存储器中,但在一些可能的示例中,为了降低该处理器的处理资源占用,该排序器还可以是设置在客户端中,或是设置在另一个处理器中,如该另一个处理器用于对客户端发送的写日志请求进行排序,本申请对此不予限定。It is worth noting that the sequencer shown in FIG. 4 is set in the internal memory of the processor, but in some possible examples, in order to reduce the processing resource occupation of the processor, the sequencer may also be set in the client In the terminal, or set in another processor, for example, the other processor is used to sort the log write requests sent by the client, which is not limited in this application.
为了确定第一段在硬盘包括的多个段中的位置,在处理器22并行将第一日志项和第二日志项写入第一段之前,本申请实施例还提供一种确定第一段的实施例,示例的,处理器22可以将第一写日志请求的LSN与日志索引进行匹配,以确定第一写日志请求包括的第一日志项待写入的段是第一段。该日志索引用于指示第一段与LSN的对应关系。In order to determine the position of the first segment in the multiple segments included in the hard disk, before the processor 22 writes the first log entry and the second log entry into the first segment in parallel, the embodiment of the present application further provides a method for determining the first segment For example, the processor 22 may match the LSN of the first log write request with the log index to determine that the segment to be written in the first log entry included in the first log write request is the first segment. The log index is used to indicate the correspondence between the first segment and the LSN.
在一种可能的实现方式中,上述的日志索引存储在处理器的缓存中。如图1所示,该缓存可以是内存1142,该内存1142可以是DRAM。在日志写入过程中,处理单元1141可以读取缓存(内存1142)中的日志索引,从而快速确定写日志请求包括的日志项所要写入的段,减少了日志写入所需的路径查询时间,提高了日志写入的效率。In a possible implementation manner, the above-mentioned log index is stored in the cache of the processor. As shown in FIG. 1, the cache may be a memory 1142, and the memory 1142 may be a DRAM. During the log writing process, the processing unit 1141 can read the log index in the cache (memory 1142), so as to quickly determine the segment to be written for the log item included in the log write request, and reduce the path query time required for log writing , which improves the efficiency of log writing.
在另一种可能的实现方式中,上述的日志索引存储在与处理器连接的其他缓存中。例如,该其他缓存包括一个或多个缓存,处理器可以利用DMA或RDMA技术从该其他缓存中读取该日志索引,进而,处理器将写日志请求的LSN与该日志索引进行匹配,确定写日志请求包括的日志项所要写入的段,减少了日志写入所需的路径查询时间,提高了日志写入的效率。又如,上述的其他缓存可以是一个分布式内存系统,处理器通过访问该分布式内存系统以读取上述的日志索引。In another possible implementation manner, the above-mentioned log index is stored in another cache connected to the processor. For example, the other cache includes one or more caches, the processor can use DMA or RDMA technology to read the log index from the other cache, and then the processor matches the LSN of the log write request with the log index to determine the write log index. The segment to be written by the log entry included in the log request reduces the path query time required for log writing and improves the efficiency of log writing. For another example, the above-mentioned other cache may be a distributed memory system, and the processor accesses the distributed memory system to read the above-mentioned log index.
作为一种可选的实施方式,上述的日志索引包括第一索引和第二索引。As an optional implementation manner, the above-mentioned log index includes a first index and a second index.
如图4所示,第一索引可以被称为一级索引或分段缓存索引(segment cache index),第一索引用于指示第一段在硬盘中的存储地址范围。示例的,该第一索引指向硬盘的多个段中第一段对应的二级索引和该日志段的起始存储地址。具体的,该第一索引包括硬盘中多个段的标识,该多个段中每个段存储的第一个日志项(或称段首日志项)的LSN,和该第一个日志项所对应的起始存储地址。在一些可能的示例中,若硬盘还包括其他段(如图4所示出的第二段和第三段),第一索引还用于指示其他段在硬盘中的存储地址范围。如下表1所示,该第一索引可以包括段标识,段首日志项的LSN,以及段首日志项的起始存储地址。As shown in FIG. 4 , the first index may be called a first-level index or a segment cache index (segment cache index), and the first index is used to indicate the storage address range of the first segment in the hard disk. Exemplarily, the first index points to the secondary index corresponding to the first segment among the multiple segments of the hard disk and the starting storage address of the log segment. Specifically, the first index includes the identifiers of multiple segments in the hard disk, the LSN of the first log entry (or the log entry at the beginning of the segment) stored in each segment in the multiple segments, and the log entry of the first log entry. The corresponding starting storage address. In some possible examples, if the hard disk further includes other segments (the second segment and the third segment shown in FIG. 4 ), the first index is also used to indicate the storage address range of the other segments in the hard disk. As shown in Table 1 below, the first index may include the segment identifier, the LSN of the segment header log entry, and the start storage address of the segment header log entry.
表1Table 1
段标识Segment ID 段首日志项的LSNLSN of the segment header log entry 起始存储地址starting storage address
第一段first paragraph 001001 0000 0000H0000 0000H
第二段second paragraph 101101 0001 0000H0001 0000H
第三段third paragraph 201201 0010 0000H0010 0000H
其中,尾部的H用于指示起始存储地址是以十六进制的形式来表示的。Among them, the H at the end is used to indicate that the starting storage address is expressed in hexadecimal form.
第一段中段首日志项的LSN为001,起始存储地址为0000 0000H;该第一段指示的存储地址范围为:0000 0000H~0000 FFFFH。The LSN of the first log entry in the first segment is 001, and the starting storage address is 0000 0000H; the storage address range indicated by the first segment is: 0000 0000H~0000 FFFFH.
第二段中段首日志项的LSN为101,起始存储地址为0001 0000H;该第二段指示的存储地址范围为:0001 0000H~0001 FFFFH。The LSN of the first log entry in the second segment is 101, and the starting storage address is 0001 0000H; the storage address range indicated by the second segment is: 0001 0000H~0001 FFFFH.
第三段中段首日志项的LSN为201,起始存储地址为0001 0001;该第三段指示的存储地址范围为:0010 0000H~0010 FFFFH。The LSN of the first log entry in the third segment is 201, and the starting storage address is 0001 0001; the storage address range indicated by the third segment is: 0010 0000H~0010 FFFFH.
如图4所示,第二索引可以被称为二级索引或日志项缓存索引(log entry cache index),第二索引用于至少一个存储地址范围中每个日志项的LSN和存储地址之间的对应关系。该第二索引包括硬盘中一个或多个段中每个日志项的LSN和存储地址之间的对应关系。As shown in FIG. 4 , the second index may be referred to as a secondary index or a log entry cache index, and the second index is used between the LSN and the storage address of each log entry in at least one storage address range corresponding relationship. The second index includes the correspondence between the LSN and the storage address of each log entry in one or more segments in the hard disk.
在第一种可能的示例中,该第二索引包括硬盘的一个段中每个日志项的LSN和存储地址之间的对应关系,如表2所示,该第二索引包括图4所示出的第一段中每个日志项的LSN和存储地址。In a first possible example, the second index includes the correspondence between the LSN and the storage address of each log entry in a segment of the hard disk, as shown in Table 2, and the second index includes the relationship shown in FIG. 4 . The LSN and storage address of each log entry in the first segment of .
表2Table 2
Figure PCTCN2021140172-appb-000001
Figure PCTCN2021140172-appb-000001
例如,该第二索引包括有4个日志项,这4个日志项的LSN和存储地址之间的对应关系分别为:001-0000 0000H,002-0000 0010H,003-0000 0011H,004-0000 0030H。For example, the second index includes 4 log items, and the correspondences between the LSNs of the 4 log items and the storage addresses are: 001-0000 0000H, 002-0000 0010H, 003-0000 0011H, 004-0000 0030H .
在第二种可能的示例中,该第二索引包括硬盘的多个段中每个日志项的LSN和存储地址之间的对应关系,如该第二索引包括图4所示出的第一段和第二段中每个日志项的LSN和存储地址。关于日志项的LSN和存储地址之间的对应关系可以参考上述表2的相关内容,此处不予赘述。In a second possible example, the second index includes the correspondence between the LSN and the storage address of each log entry in the multiple segments of the hard disk. For example, the second index includes the first segment shown in FIG. 4 . and the LSN and storage address of each log entry in the second paragraph. For the corresponding relationship between the LSN of the log entry and the storage address, reference may be made to the relevant content in Table 2 above, which will not be repeated here.
由于处理器的缓存的存储容量较小,使得缓存中无法存储大量的索引数据,在本申请实施例所提供的日志管理方法中,日志索引包括第一索引和第二索引,处理器可以先对第一索引和第二索引中任一个进行优先匹配,若匹配成功,则可以避免处理器查找日志索引中所有的数据,减少日志写入所需的路径查询时间,提高日志写入效率。Since the storage capacity of the cache of the processor is small, a large amount of index data cannot be stored in the cache. In the log management method provided by the embodiment of the present application, the log index includes a first index and a second index. Any one of the first index and the second index is preferentially matched. If the match is successful, the processor can be prevented from searching for all data in the log index, the path query time required for log writing is reduced, and the log writing efficiency is improved.
在本申请中,由于处理器利用日志索引确定第一日志项所要存储的第一段,而无需使用文件系统确定第一日志项所要存储的日志文件,减少了文件系统所导致的存储管理开销,进而减少了日志写入所需的存储路径查询时间,提高了日志写入的效率。In the present application, since the processor uses the log index to determine the first segment to be stored in the first log entry, without using the file system to determine the log file to be stored in the first log entry, the storage management overhead caused by the file system is reduced, Thus, the storage path query time required for log writing is reduced, and the efficiency of log writing is improved.
另外,在处理器将第一日志项写入第一段的过程中,由于硬盘存储日志时没有引入文件系统,因此,在处理器并行写入多个日志项的情况下,处理器无需为该多个日志项所要写入的多个日志段上锁,减少了处理器为每个日志段设置文件锁的过程,提高了日志写入的效率。In addition, in the process of writing the first log entry into the first segment by the processor, since the hard disk does not introduce a file system when storing the log, in the case where the processor writes multiple log entries in parallel, the processor does not need to Multiple log segments to be written by multiple log entries are locked, which reduces the process of setting file locks for each log segment by the processor and improves the efficiency of log writing.
为了确定第一日志项和第二日志项待写入的第一段,本申请提供一种可能的具体实现方式,如图5所示,图5为本申请提供的一种日志管理方法的流程示意图二,在上述的S220之后,处理器将第一写日志请求的LSN与日志索引进行匹配确定第一段的过程包括以下步骤S221~S223。In order to determine the first segment to be written in the first log entry and the second log entry, the present application provides a possible specific implementation manner, as shown in FIG. 5 , which is a flowchart of a log management method provided by the present application In schematic diagram 2, after the above S220, the process that the processor matches the LSN of the first log write request with the log index to determine the first segment includes the following steps S221-S223.
S221,判断第一写日志请求的LSN与第三日志项的LSN是否连续。S221: Determine whether the LSN of the first log write request is continuous with the LSN of the third log entry.
该第三日志项为第二索引记录的任意一个日志项。如表2所示,该第三日志项可以是指LSN为004的日志项,该第三日志项的起始存储地址为0000 0030H。The third log entry is any log entry recorded by the second index. As shown in Table 2, the third log entry may refer to a log entry whose LSN is 004, and the starting storage address of the third log entry is 0000 0030H.
通常,处理器采用追加写(append)的方式将日志写入日志系统,在本申请的示例中,处理器依据第二索引中第三日志项的LSN,确定第一写日志请求的LSN是否与第一写日志请求的LSN连续,进而,若第一写日志请求的LSN与第三日志项的LSN连续,则执行S222;若第一写日志请求的LSN与第三日志项的LSN不连续,则执行S223。Usually, the processor writes the log into the log system by appending. In the example of this application, the processor determines whether the LSN of the first log write request is the same as the LSN of the third log entry in the second index according to the LSN of the third log entry in the second index. The LSN of the first log write request is continuous, and then, if the LSN of the first log write request is continuous with the LSN of the third log item, then execute S222; if the LSN of the first log write request is not continuous with the LSN of the third log item, Then execute S223.
S222,将第三日志项所在的段作为第一段。S222, taking the segment where the third log entry is located as the first segment.
若第二索引中第三日志项的LSN与第一写日志请求的LSN连续,处理器将第三日志项所在的段作为第一段,从而,处理器利用追加写(append)的方式将第一写日志请求包括的第一日志项写入第一段,避免了处理器从文件系统中查找第一写日志请求包括的第一日志项的待写入文件,减少了日志写入过程所需的写入路径查询时间,提高了日志写入的效率。If the LSN of the third log entry in the second index is continuous with the LSN of the first log write request, the processor takes the segment where the third log entry is located as the first segment, so that the processor uses appending to write the first segment. The first log entry included in the first log write request is written into the first segment, which prevents the processor from searching the file system for the to-be-written file of the first log entry included in the first log write request, and reduces the log writing process. The query time of the write path is shortened, which improves the efficiency of log writing.
S223,将第一写日志请求的LSN与第一索引进行匹配确定第一段。S223: Match the LSN of the first log write request with the first index to determine the first segment.
该第一段中第一个日志项(段首日志项)的LSN与第一写日志请求的LSN匹配,在本示例中,“匹配”是指第一写日志请求的LSN处于第一段的LSN范围内,该LSN范围对应第一段的存储地址范围。如表1所示,第一段的段首日志项(第一个日志项)的LSN为001,第二段的段首日志项的LSN为101,第三段的段首日志项的LSN为201,则第一段所对应的LSN范围为“001~100”,第二段所对应的LSN范围为“101~200”。The LSN of the first log entry (log entry at the beginning of the segment) in the first segment matches the LSN of the first log write request. In this example, "matching" means that the LSN of the first log write request is in the first segment. Within the LSN range, the LSN range corresponds to the storage address range of the first segment. As shown in Table 1, the LSN of the segment header log entry (first log entry) of the first segment is 001, the LSN of the segment header log entry of the second segment is 101, and the LSN of the segment header log entry of the third segment is 201, the LSN range corresponding to the first segment is "001-100", and the LSN range corresponding to the second segment is "101-200".
例如,若第一写日志请求的LSC为“001~100”中任意一个,则确认第一写日志请求包括的第一日志项待写入的段为第一段。For example, if the LSC of the first log write request is any one of "001-100", it is confirmed that the segment to be written in the first log entry included in the first log write request is the first segment.
又如,若第一写日志请求的LSC为“101~200”中任意一个,则确认第一写日志请求包括的第一日志项待写入的段为第二段。For another example, if the LSC of the first log write request is any one of "101-200", it is confirmed that the segment to be written in the first log entry included in the first log write request is the second segment.
值得注意的是,上述的S221~S223仅为本申请实施例提供的一种可能的确定第一段的方式,不应理解为对本申请的限定。It should be noted that the above S221 to S223 are only a possible way of determining the first paragraph provided by the embodiments of the present application, and should not be construed as a limitation on the present application.
在本申请的实施例中,处理器先将第一写日志请求的LSN与第二索引包括第三日志项的LSN进行匹配,若第一写日志请求的LSN与第三日志项的LSN连续,则处理器无需将第一写日志请求的LSN与第一索引匹配,相较于处理器将第一写日志请求与文件系统的目录进行匹配,减少了大量的路径查询时间,提高了日志写入的效率。In the embodiment of the present application, the processor first matches the LSN of the first log write request with the LSN of the second index including the third log entry. If the LSN of the first log write request is continuous with the LSN of the third log entry, Then the processor does not need to match the LSN of the first log write request with the first index. Compared with the processor matching the first log write request with the directory of the file system, a large amount of path query time is reduced, and log writing is improved. s efficiency.
在日志读取的过程中,处理器也可以先将读日志请求的LSN与第二索引进行匹配,若匹配成功(命中),则处理器可以依据第二索引确定读日志请求所要读取的日志项所在的存储地址,减少了日志读取所需的路径查询时间,提高了日志读取的效率。若读日志请求的LSN未在第二索引中命中,则处理器可以依据第一索引确定读日志请求所要读取的日志段,通过遍历该日志段得到读日志请求对应的日志项,避免了处理器将在文件系统中查询读日志请求的存储地址,提高了日志读取的效率。During the log reading process, the processor may also first match the LSN of the log read request with the second index. If the match is successful (hit), the processor may determine the log to be read by the log read request according to the second index The storage address where the item is located reduces the path query time required for log reading and improves the efficiency of log reading. If the LSN of the log read request is not hit in the second index, the processor can determine the log segment to be read by the log read request according to the first index, and obtain the log entry corresponding to the read log request by traversing the log segment, avoiding processing The server will query the storage address of the log read request in the file system, which improves the efficiency of log reading.
作为一种可选的实现方式,为了提高日志写入的准确性,本申请实施例提供一种可能的实施例,如图5所示,图5给出了上述图2所示出的S230中处理器将第一日志项写入第一段的实现方式,上述的S230可以包括以下步骤。As an optional implementation manner, in order to improve the accuracy of log writing, this embodiment of the present application provides a possible embodiment. As shown in FIG. 5 , FIG. In an implementation manner of the processor writing the first log entry into the first segment, the above-mentioned S230 may include the following steps.
S2301,处理器22依据第一写日志请求的LSN生成起始存储地址。S2301, the processor 22 generates an initial storage address according to the LSN of the first log write request.
该起始存储地址处于第一段的存储地址范围。根据表1所示出的内容,若第一段的存储地址范围为0000 0000H~0000 FFFFH,若该第一写日志请求的LSN与第一段的段首日志项 的LSN(001)连续,则该起始存储地址可以为0000 0010H。The starting storage address is in the storage address range of the first segment. According to the content shown in Table 1, if the storage address range of the first segment is 0000 0000H~0000 FFFFH, if the LSN of the first log write request is continuous with the LSN (001) of the segment header log entry of the first segment, then The starting memory address can be 0000 0010H.
S2302,处理器22依据起始存储地址将第一日志项写入第一段。S2302, the processor 22 writes the first log entry into the first segment according to the initial storage address.
在处理器将日志项写入硬盘的过程中,首先依据写日志请求的LSN生成起始存储地址,再依据起始存储地址将写日志请求包括的日志项写入硬盘中,避免了处理器随机的将日志项写入硬盘,保证了日志写入的准确性。In the process of writing the log items to the hard disk, the processor first generates the initial storage address according to the LSN of the log write request, and then writes the log items included in the log write request to the hard disk according to the initial storage address. The log entries are written to the hard disk to ensure the accuracy of log writing.
作为一种可选的实现方式,处理器可以原子地将日志项写入硬盘。“原子地写入”可以理解为处理器按照预设的读写单位将日志项写入硬盘,该预设的读写单位可以是指硬盘的日志读写单位,该硬盘的日志读写单位是指处理器读写硬盘中日志项的最小数据粒度,该硬盘的日志读写单位可以根据硬盘的类型来设置,也可以根据或用户的需求进行调整,如4KB,8KB或16KB等。As an optional implementation, the processor can atomically write log entries to disk. "Atomic write" can be understood as the processor writes log items to the hard disk according to the preset read and write units. The preset read and write units may refer to the log read and write units of the hard disk. The log read and write units of the hard disk are Refers to the minimum data granularity for the processor to read and write log items in the hard disk. The log read and write unit of the hard disk can be set according to the type of the hard disk, and can also be adjusted according to the needs of users, such as 4KB, 8KB or 16KB.
在一种可能的示例中,在上述的S2301之前,处理器还判断写日志请求的日志项长度是否小于或等于硬盘的日志读写单位。若写日志请求的日志项长度小于或等于硬盘的日志读写单位,则执行上述的S2301。In a possible example, before the above S2301, the processor further determines whether the log entry length of the log write request is less than or equal to the log read/write unit of the hard disk. If the log entry length of the log write request is less than or equal to the log read/write unit of the hard disk, the above-mentioned S2301 is executed.
在另一种可能的示例中,若写日志请求的日志项长度(如12KB)大于硬盘的日志读写单位(如4KB),如图6所示,图6为本申请提供的一种日志写入的示意图二,处理器将写日志请求包括的日志项划分为多个子日志,该多个子日志中每个子日志的日志项长度与硬盘日志读写单位一致;进而,处理器依据写日志请求的LSN生成多个子日志中每个子日志的起始存储地址。关于处理器依据LSN生成起始存储地址的过程可以参考S2301的示例,此处不予赘述。In another possible example, if the log entry length (such as 12KB) of the log write request is greater than the log read/write unit (such as 4KB) of the hard disk, as shown in FIG. 6, FIG. 6 provides a log write request provided by this application In the second schematic diagram, the processor divides the log items included in the log write request into multiple sub-logs, and the log item length of each sub-log in the multiple sub-logs is consistent with the hard disk log read-write unit; The LSN generates the starting storage address of each sub-log in the multiple sub-logs. For the process of generating the starting storage address by the processor according to the LSN, reference may be made to the example of S2301, which will not be repeated here.
在本示例中,多个子日志中每个子日志包括待写入日志项的描述信息,该描述信息与写日志请求中的描述信息一致,关于描述信息的内容可以参考图4的相关内容,此处不再赘述。In this example, each sub-log in the multiple sub-logs includes description information of the log item to be written, and the description information is consistent with the description information in the log write request. For the content of the description information, please refer to the related content of FIG. 4 , here No longer.
在一种可能的情形中,为区分上述的多个子日志,处理器还可以为每个子日志分配一个子序列号,该子序列号用于指示子日志在待写入日志项(如第一日志项或第二日志项)中的相对位置。In a possible situation, in order to distinguish the above-mentioned multiple sub-logs, the processor may also assign a sub-sequence number to each sub-log, and the sub-sequence number is used to indicate that the sub-log is in the log entry to be written (such as the first log entry or second log entry).
在写日志请求包括的日志项的日志项长度较大的情况下,处理器可以依据硬盘的日志读写单位写入多个子日志,即使在处理器直接将写日志请求包括的日志项的过程中硬盘和处理器断电,已经被处理器写入硬盘的子日志不会被处理器重复写入(或读取),减少了硬盘的存储资源消耗,提高了硬盘的存储资源利用效率。In the case where the log entry length of the log entry included in the log write request is large, the processor can write multiple sub-logs according to the log read/write unit of the hard disk, even when the processor directly writes the log entry included in the log write request. When the hard disk and the processor are powered off, the sub-logs that have been written to the hard disk by the processor will not be repeatedly written (or read) by the processor, which reduces the storage resource consumption of the hard disk and improves the storage resource utilization efficiency of the hard disk.
在本申请的实施例中,处理器可以依据硬盘的日志读写单位将写日志请求包括的待写入日志项进行拆分,进而,处理器原子地生成每个子日志的起始存储地址,由于处理器基于未采用文件系统的日志段粒度读写日志,因此,处理器无需为日志段进行加锁,从而实现了处理器并行追加写入硬盘的过程,减少日志写入所需的时间,提高了日志写入的效率。In the embodiment of the present application, the processor may split the log items to be written included in the log write request according to the log read/write unit of the hard disk, and further, the processor atomically generates the starting storage address of each sub-log, because The processor reads and writes logs based on the granularity of log segments that do not use the file system. Therefore, the processor does not need to lock the log segments, thus realizing the process of the processor adding and writing to the hard disk in parallel, reducing the time required for log writing and improving the efficiency of log writing.
作为另一种可选的实现方式,若第一段的剩余存储空间小于写日志请求的日志项长度,处理器还可以将写日志请求的一部分内容写入第一段,将写日志请求的另一部分内容写入第二段,该第二段为硬盘中与第一段具有被连续读取的关联关系的日志段。继而,处理器将硬盘中的日志尾地址设置为第二段中第一个日志项的起始存储地址。As another optional implementation, if the remaining storage space of the first segment is less than the log entry length of the log write request, the processor may also write part of the log write request into the first segment, and write another part of the log write request into the first segment. A part of the content is written into the second segment, where the second segment is a log segment in the hard disk that has an associated relationship with the first segment that is continuously read. Then, the processor sets the log tail address in the hard disk as the start storage address of the first log entry in the second segment.
如图7所示,图7为本申请提供的一种日志写入的示意图三,若第一段的剩余存储空间小于写日志请求的日志项长度,处理器将写日志请求包括的待写入日志项划分为多个子日志,将一部分内容(如图7所示出的子序列号为1和2的子日志)写入第一段,并将另一部分内 容(如图7所示出的子序列号为3的子日志)写入与第一段具有被连续读取的关联关系的第二段中。As shown in FIG. 7 , FIG. 7 is a schematic diagram 3 of log writing provided by this application. If the remaining storage space of the first segment is less than the log entry length of the log write request, the processor will write the log entries included in the log write request to be written. The log entry is divided into multiple sub-logs, and part of the content (sub-logs with sub-sequence numbers 1 and 2 shown in Figure 7) is written into the first segment, and another part of the content (sub-log shown in Figure 7) The sub-log with sequence number 3) is written into the second segment that has an association relationship with the first segment that is continuously read.
如图7所示,若第二段所指示的存储空间未被全部占用,则第二段还包括有空白区域,该空白区域可以用于存储其他日志项。As shown in FIG. 7 , if the storage space indicated by the second segment is not fully occupied, the second segment further includes a blank area, and the blank area can be used to store other log items.
在本申请的实施例中,日志尾地址是以最后一个日志所在的日志段的段首日志项的起始存储地址来表示的。In the embodiment of the present application, the log tail address is represented by the starting storage address of the log entry at the segment head of the log segment where the last log is located.
值得注意的是,图7示出的内容是以处理器将写日志请求包括的待写入日志项写入两个日志段为例进行说明的,但在一些可能的情形中,处理器还可以将待写入日志项写入更多个日志段,本申请对此不予限定。It is worth noting that the content shown in FIG. 7 is described by taking the processor writing the log entry to be written included in the log write request into two log segments as an example, but in some possible situations, the processor may also The log entry to be written is written into more log segments, which is not limited in this application.
也就是说,在本申请的实施例中,对于日志添加操作,只有当日志项需要被存储到新分配的日志段(如上述的第二段)时,才需要更新日志尾所在日志段的起始存储地址。例如,设置日志段的大小为32MB,日志系统中日志尾在其日志段的偏移为“31×1024×1024+1024×1024-3×1024”。如果,这个时候客户端进行4KB的日志追加操作,则处理器需要分配新的日志段存储该日志项,并更新日志尾所在日志段的起始存储地址。在其他情况下,如日志项无需被存储到新分配的日志段,处理器不需要更新日志尾所在日志段的起始存储地址。That is to say, in the embodiment of the present application, for the log adding operation, only when the log entry needs to be stored in the newly allocated log segment (such as the above-mentioned second segment), it is necessary to update the start of the log segment where the log tail is located. start storage address. For example, set the size of the log segment to 32MB, and the offset of the log tail in the log segment in the log system is “31×1024×1024+1024×1024-3×1024”. If the client performs a 4KB log append operation at this time, the processor needs to allocate a new log segment to store the log entry, and update the starting storage address of the log segment where the log tail is located. In other cases, such as the log entry does not need to be stored in the newly allocated log segment, the processor does not need to update the starting storage address of the log segment where the log tail is located.
如此,本申请实施例提供的上述日志管理方法中,日志尾地址可以用日志尾所在日志段的起始存储地址来表示,避免了文件系统中每次添加日志都需要更新日志尾地址的过程,减少了日志添加所需的日志尾地址的随机小写操作,提高了日志写入的效率。In this way, in the above log management method provided by the embodiment of the present application, the log tail address can be represented by the starting storage address of the log segment where the log tail is located, avoiding the process of updating the log tail address every time a log is added in the file system. The random lowercase operation of the log tail address required for log addition is reduced, and the efficiency of log writing is improved.
为了保证日志系统的高可用,客户端在写入日志的过程中,还可以对日志进行备份。如图8所示,图8为本申请提供的一种日志管理方法的流程示意图三,图8所示出的主节点810和从节点820为图1所示出的日志系统100中任意一个服务器或存储设备,如该主节点810是服务器110B,从节点820是服务器110A。图8中的各时间标记的含义如下表3所示。In order to ensure the high availability of the log system, the client can also back up the log during the log writing process. As shown in FIG. 8 , FIG. 8 is a schematic flow chart 3 of a log management method provided by this application. The master node 810 and the slave node 820 shown in FIG. 8 are any servers in the log system 100 shown in FIG. 1 . Or a storage device, for example, the master node 810 is the server 110B, and the slave node 820 is the server 110A. The meaning of each time mark in FIG. 8 is shown in Table 3 below.
表3table 3
Figure PCTCN2021140172-appb-000002
Figure PCTCN2021140172-appb-000002
图8中的(a)示出了通常技术中日志写入所需花费的时间,该总时间为T总(通常)=2T1+T2+2T3+2T4。(a) in FIG. 8 shows the time taken for log writing in the conventional technique, and the total time is T total (usually)=2T1+T2+2T3+2T4.
图8中的(b)示出了本申请所提供的日志管理方法中日志写入所需花费的时间,该总时间为T总(本申请)=2T1+T2+T3+T4。(b) in FIG. 8 shows the time required for log writing in the log management method provided by the present application, and the total time is T total (this application)=2T1+T2+T3+T4.
请参见图8中(b),若处理器22为图8所示出的主节点210,在主节点810依据第一写日志请求的LSN生成起始存储地址之后,即T2之后,主节点810向从节点820发送第一写日志请求的LSN和起始存储地址。从节点820可以依据该第一写日志请求的LSN和起始存储地址,将第一写日志请求包括的第一日志项写入第一段中,其具体过程可以参考上述图2~图7的相关内容,此处不予赘述。Please refer to (b) in FIG. 8 , if the processor 22 is the master node 210 shown in FIG. 8 , after the master node 810 generates the starting storage address according to the LSN of the first log write request, that is, after T2, the master node 810 The LSN and the starting storage address of the first write log request are sent to the slave node 820 . The slave node 820 can write the first log entry included in the first log write request into the first segment according to the LSN and the starting storage address of the first log write request. For the specific process, please refer to the above-mentioned FIG. 2 to FIG. 7 . The related content will not be repeated here.
也就是说,在日志系统具有多个存储设备的情况下,若处理器22为主节点810,主节点810向从节点820发送写日志请求的LSN和起始存储地址,并由从节点820依据该写日志请求的LSN和起始存储地址,将写日志请求包括的日志项写入第一段中,避免了主节点810的日志写入完成后再去从节点820备份,提高了多写场景的写入效率。That is to say, in the case where the log system has multiple storage devices, if the processor 22 is the master node 810, the master node 810 sends the LSN and the starting storage address of the log write request to the slave node 820, and the slave node 820 sends the LSN and the starting storage address of the log write request to the slave node 820 according to For the LSN and the starting storage address of the log write request, the log items included in the log write request are written into the first segment, which avoids the need to go to the slave node 820 for backup after the log writing of the master node 810 is completed, and improves the multi-write scenario. write efficiency.
作为一种可选的实现方式,若上述实施例中的处理器22为图8所示出的从节点820,在处理器22(从节点820)接收第一写日志请求之后,该处理器22还可以接收备份设备(主节点810)发送的第一写日志请求的LSN和起始存储地址,进而,处理器22依据该第一写日志请求的LSN和起始存储地址,将第一写日志请求包括的第一日志项写入第一段中,其具体过程可以参考上述图2~图7的相关内容,此处不予赘述。As an optional implementation manner, if the processor 22 in the above embodiment is the slave node 820 shown in FIG. 8 , after the processor 22 (slave node 820 ) receives the first log write request, the processor 22 It can also receive the LSN and the initial storage address of the first write log request sent by the backup device (main node 810), and then, the processor 22 writes the first log according to the LSN and the initial storage address of the first write log request. The first log entry included in the request is written into the first segment, and the specific process can refer to the above-mentioned related content of FIG. 2 to FIG. 7 , which will not be repeated here.
也就是说,在日志系统具有多个存储设备的情况下,若处理器22为从节点820,处理器22在接收到客户端发送的写日志请求之后,还可以接收备份设备(主节点810)发送的写日志请求的LSN和起始存储地址,并由处理器22(从节点820)依据该写日志请求的LSN和起始存储地址,将写日志请求包括的日志项写入第一段中,避免了主节点810的日志写入完成后再去从节点820备份,提高了多写场景的写入效率。That is to say, in the case where the log system has multiple storage devices, if the processor 22 is the slave node 820, the processor 22 can also receive the backup device (master node 810) after receiving the log write request sent by the client. The LSN and starting storage address of the log write request sent, and the processor 22 (slave node 820) writes the log items included in the log write request into the first segment according to the LSN and starting storage address of the log write request , which avoids the backup of the slave node 820 after the log writing of the master node 810 is completed, and improves the writing efficiency of the multi-write scenario.
本申请实施例提供的日志管理方法,在从节点820将写日志请求包括的日志项写入硬盘之后,从节点820还可以向客户端发送日志写入响应,日志写入响应用于指示已将写日志请求包括的日志项(如上述的第一日志项和第二日志项)写入硬盘。如此,客户端可以依据从节点820反馈的日志写入响应确定本轮日志添加操作已经完成,避免客户端重复向日志系统发送写日志请求,造成写日志请求的重复备份,节省日志系统的存储资源,提高日志系统的存储资源利用率。In the log management method provided by this embodiment of the present application, after the slave node 820 writes the log items included in the log write request to the hard disk, the slave node 820 may also send a log write response to the client, where the log write response is used to indicate that the log write request has been The log entries included in the log write request (such as the above-mentioned first log entry and second log entry) are written to the hard disk. In this way, the client can determine that the current round of log addition operation has been completed according to the log write response fed back from the node 820, so as to avoid the client from repeatedly sending log write requests to the log system, resulting in repeated backups of log write requests and saving the storage resources of the log system. , to improve the storage resource utilization of the log system.
具体的,本申请将日志管理方法中的控制(LSN和起始存储地址)和数据(日志项)分离,对于日志添加操作,客户端可并发地将写日志请求发送到主节点810和从节点820,主节点810收到写日志请求后,生成对应的日志项序列号和日志项起始存储地址,并发送给从节点820,主节点810和从节点820可并行持久化日志项。当持久化操作完成后,主节点810和从节点820更新日志项缓存索引(如上述的第二索引),并将确认信息(如上述的日志写入响应)发送给客户端。当客户端收到所有节点的确认信息后,确定日志添加操作完成。Specifically, the present application separates the control (LSN and starting storage address) and data (log entry) in the log management method, and for the log addition operation, the client can concurrently send a log write request to the master node 810 and the slave node 820 , after receiving the log write request, the master node 810 generates a corresponding log entry sequence number and a log entry start storage address, and sends them to the slave node 820 . The master node 810 and the slave node 820 can persist the log entries in parallel. After the persistence operation is completed, the master node 810 and the slave node 820 update the log entry cache index (such as the above-mentioned second index), and send confirmation information (such as the above-mentioned log write response) to the client. When the client receives confirmation information from all nodes, it determines that the log addition operation is complete.
对于日志读操作,客户端可任意向主节点和从节点进行读取,这可以减少客户端对主节点所在服务器的网卡的带宽占用,有效提高主节点所在服务器的带宽利用率。For log read operations, the client can read from the master node and the slave node at will, which can reduce the bandwidth occupied by the client on the network card of the server where the master node is located, and effectively improve the bandwidth utilization of the server where the master node is located.
可以理解的是,为了实现上述实施例中功能,网络设备和终端设备包括了执行各个功能相应的硬件结构和/或软件模块。本领域技术人员应该很容易意识到,结合本申请中所公开的实施例描述的各示例的单元及方法步骤,本申请能够以硬件或硬件和计算机软件相结合的形式来实现。某个功能究竟以硬件还是计算机软件驱动硬件的方式来执行,取决于技术方案的特定应用场景和设计约束条件。It can be understood that, in order to implement the functions in the foregoing embodiments, the network device and the terminal device include corresponding hardware structures and/or software modules for performing each function. Those skilled in the art should easily realize that the units and method steps of each example described in conjunction with the embodiments disclosed in the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is performed by hardware or computer software-driven hardware depends on the specific application scenarios and design constraints of the technical solution.
图9为本申请提供的一种日志管理装置的结构示意图。该日志管理装置900可以用于实现上述方法实施例中处理器的功能,因此也能实现上述方法实施例所具备的有益效果。在本申请的实施例中,该日志管理装置900可以是如图2所示的处理器22,也可以是如图1所示出的服务器110A、服务器110B或网卡114,还可以是应用于服务器的模块(如芯片),如图1所示出的处理器112或处理单元1141。FIG. 9 is a schematic structural diagram of a log management apparatus provided by the present application. The log management apparatus 900 can be used to implement the function of the processor in the above method embodiments, and thus can also achieve the beneficial effects of the above method embodiments. In the embodiment of the present application, the log management apparatus 900 may be the processor 22 shown in FIG. 2 , the server 110A, the server 110B or the network card 114 shown in FIG. 1 , or may be applied to a server A module (such as a chip), such as the processor 112 or the processing unit 1141 shown in FIG. 1 .
如图9所示,该日志管理装置900包括处理模块910、通信模块920和索引模块930。该 日志管理装置900用于实现上述图2~图8中所示的方法实施例中处理器或硬盘的功能。As shown in FIG. 9 , the log management apparatus 900 includes a processing module 910 , a communication module 920 and an indexing module 930 . The log management apparatus 900 is used to implement the functions of the processor or the hard disk in the method embodiments shown in the foregoing Fig. 2 to Fig. 8 .
当日志管理装置900用于实现图2所示的方法实施例中处理器22的功能时:处理模块910用于执行S210和S230;通信模块920用于执行S220。When the log management apparatus 900 is used to implement the function of the processor 22 in the method embodiment shown in FIG. 2 : the processing module 910 is used to execute S210 and S230; the communication module 920 is used to execute S220.
当日志管理装置900用于实现图5所示的方法实施例中处理器22的功能时:处理模块910用于执行S210和S2301~S2302;通信模块920用于执行S220,索引模块930用于执行S221~S223。When the log management apparatus 900 is used to implement the function of the processor 22 in the method embodiment shown in FIG. 5 : the processing module 910 is used to execute S210 and S2301-S2302; the communication module 920 is used to execute S220, and the index module 930 is used to execute S221 to S223.
有关上述处理模块910、通信模块920和索引模块930更详细的描述可以直接参考图2~图8所示的方法实施例中相关描述直接得到,这里不加赘述。More detailed descriptions of the above-mentioned processing module 910 , communication module 920 and indexing module 930 can be obtained directly by referring to the relevant descriptions in the method embodiments shown in FIG. 2 to FIG. 8 , and details are not repeated here.
图10为本申请提供的一种通信设备的结构示意图,该通信设备1000可以实现图2~图8所示出的日志管理方法的操作步骤。该通信设备1000包括处理器1010和通信接口1020。处理器1010和通信接口1020之间相互耦合。可以理解的是,通信接口1020可以为收发器或输入输出接口。FIG. 10 is a schematic structural diagram of a communication device provided by this application. The communication device 1000 can implement the operation steps of the log management methods shown in FIGS. 2 to 8 . The communication device 1000 includes a processor 1010 and a communication interface 1020 . The processor 1010 and the communication interface 1020 are coupled to each other. It can be understood that the communication interface 1020 can be a transceiver or an input-output interface.
本申请实施例中不限定上述通信接口1020、处理器1010以及存储器1030之间的具体连接介质。本申请实施例在图10中以通信接口1020、处理器1010以及存储器1030之间通过总线1040连接,总线在图10中以粗线表示,其它部件之间的连接方式,仅是进行示意性说明,并不引以为限。所述总线可以分为地址总线、数据总线、控制总线等。为便于表示,图10中仅用一条粗线表示,但并不表示仅有一根总线或一种类型的总线。The specific connection medium between the communication interface 1020 , the processor 1010 , and the memory 1030 is not limited in the embodiments of the present application. In the embodiment of the present application, the communication interface 1020, the processor 1010, and the memory 1030 are connected through a bus 1040 in FIG. 10. The bus is represented by a thick line in FIG. 10, and the connection between other components is only for schematic illustration. , is not limited. The bus can be divided into an address bus, a data bus, a control bus, and the like. For ease of presentation, only one thick line is used in FIG. 10, but it does not mean that there is only one bus or one type of bus.
可选的,通信设备1000还可以包括存储器1030,用于存储处理器1010执行的指令或存储处理器1010运行指令所需要的输入数据或存储处理器1010运行指令后产生的数据,如存储器1030可以用于存储上述的日志索引。存储器1030可用于存储软件程序及模块,如本申请实施例所提供的日志管理方法对应的程序指令/模块,处理器1010通过执行存储在存储器1030内的软件程序及模块,从而执行各种功能应用以及数据处理。该通信接口1020可用于与其他设备进行信令或数据的通信。在本申请中该网络设备1000可以具有多个通信接口1020。Optionally, the communication device 1000 may further include a memory 1030 for storing instructions executed by the processor 1010 or input data required by the processor 1010 to run the instructions or data generated after the processor 1010 runs the instructions. For example, the memory 1030 may Used to store the above log index. The memory 1030 may be used to store software programs and modules, such as program instructions/modules corresponding to the log management method provided by the embodiments of the present application, and the processor 1010 executes various functional applications by executing the software programs and modules stored in the memory 1030. and data processing. The communication interface 1020 can be used for signaling or data communication with other devices. The network device 1000 may have multiple communication interfaces 1020 in this application.
当通信设备1000用于实现图2~图8所示的方法时,处理器1010用于执行上述处理单元910的功能,通信接口1020用于执行上述收发单元920的功能。When the communication device 1000 is used to implement the methods shown in FIGS. 2 to 8 , the processor 1010 is used to perform the functions of the above-mentioned processing unit 910 , and the communication interface 1020 is used to perform the functions of the above-mentioned transceiver unit 920 .
可以理解的是,本申请的实施例中的处理器可以是CPU、NPU或GPU,还可以是其它通用处理器、DSP、ASIC、FPGA或者其它可编程逻辑器件、晶体管逻辑器件,硬件部件或者其任意组合。通用处理器可以是微处理器,也可以是任何常规的处理器。It can be understood that the processor in the embodiments of the present application may be a CPU, an NPU, or a GPU, and may also be other general-purpose processors, DSPs, ASICs, FPGAs, or other programmable logic devices, transistor logic devices, hardware components or the like. random combination. A general-purpose processor may be a microprocessor or any conventional processor.
如图10所示,本申请所提供的通信设备1000可以是网卡(如图1所示出的网卡114)、服务器、手机、平板电脑、笔记本电脑或桌面电脑等。As shown in FIG. 10 , the communication device 1000 provided by the present application may be a network card (the network card 114 shown in FIG. 1 ), a server, a mobile phone, a tablet computer, a notebook computer or a desktop computer, and the like.
本申请的实施例中的方法步骤可以通过硬件的方式来实现,也可以由处理器执行软件指令的方式来实现。软件指令可以由相应的软件模块组成,软件模块可以被存放于RAM、闪存、ROM、PROM、EPROM、EEPROM、寄存器、硬盘、移动硬盘、CD-ROM或者本领域熟知的任何其它形式的存储介质中。一种示例性的存储介质耦合至处理器,从而使处理器能够从该存储介质读取信息,且可向该存储介质写入信息。当然,存储介质也可以是处理器的组成部分。处理器和存储介质可以位于ASIC中。另外,该ASIC可以位于网络设备或终端设备中。当然,处理器和存储介质也可以作为分立组件存在于网络设备或终端设备中。The method steps in the embodiments of the present application may be implemented in a hardware manner, or may be implemented in a manner in which a processor executes software instructions. The software instructions can be composed of corresponding software modules, and the software modules can be stored in RAM, flash memory, ROM, PROM, EPROM, EEPROM, registers, hard disk, removable hard disk, CD-ROM or any other form of storage medium well known in the art . An exemplary storage medium is coupled to the processor, such that the processor can read information from, and write information to, the storage medium. Of course, the storage medium can also be an integral part of the processor. The processor and storage medium may reside in an ASIC. Alternatively, the ASIC may be located in a network device or in an end device. Of course, the processor and the storage medium may also exist in the network device or the terminal device as discrete components.
在上述实施例中,可以全部或部分地通过软件、硬件、固件或者其任意组合来实现。当 使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。所述计算机程序产品包括一个或多个计算机程序或指令。在计算机上加载和执行所述计算机程序或指令时,全部或部分地执行本申请实施例所述的流程或功能。所述计算机可以是通用计算机、专用计算机、计算机网络、网络设备、用户设备或者其它可编程装置。所述计算机程序或指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,所述计算机程序或指令可以从一个网站站点、计算机、服务器或数据中心通过有线或无线方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质或者是集成一个或多个可用介质的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质,例如,软盘、硬盘、磁带;也可以是光介质,例如,数字视频光盘(digital video disc,DVD);还可以是半导体介质,例如,SSD。In the above-mentioned embodiments, it may be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented in software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer programs or instructions. When the computer program or instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present application are executed in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, network equipment, user equipment, or other programmable apparatus. The computer program or instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer program or instructions may be downloaded from a website site, computer, A server or data center transmits by wire or wireless to another website site, computer, server or data center. The computer-readable storage medium may be any available medium that can be accessed by a computer, or a data storage device such as a server, data center, or the like that integrates one or more available media. The usable media may be magnetic media, such as floppy disks, hard disks, magnetic tapes; optical media, such as digital video discs (DVD); and semiconductor media, such as SSDs.
在本申请的各个实施例中,如果没有特殊说明以及逻辑冲突,不同的实施例之间的术语和/或描述具有一致性、且可以相互引用,不同的实施例中的技术特征根据其内在的逻辑关系可以组合形成新的实施例。In the various embodiments of the present application, if there is no special description or logical conflict, the terms and/or descriptions between different embodiments are consistent and can be referred to each other, and the technical features in different embodiments are based on their inherent Logical relationships can be combined to form new embodiments.
本申请说明书和权利要求书及上述附图中的术语“第一”、“第二”和“第三”等是用于区别不同对象,而不是用于限定特定顺序。在本申请实施例中,“示例性的”或者“例如”等词用于表示作例子、例证或说明。本申请实施例中被描述为“示例性的”或者“例如”的任何实施例或设计方案不应被解释为比其它实施例或设计方案更优选或更具优势。确切而言,使用“示例性的”或者“例如”等词旨在以具体方式呈现相关概念。The terms "first", "second" and "third" in the description and claims of the present application and the above drawings are used to distinguish different objects, rather than to limit a specific order. In the embodiments of the present application, words such as "exemplary" or "for example" are used to represent examples, illustrations or illustrations. Any embodiments or designs described in the embodiments of the present application as "exemplary" or "such as" should not be construed as preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "such as" is intended to present the related concepts in a specific manner.
本申请中,“至少一个”是指一个或者多个,“多个”是指两个或两个以上,其它量词与之类似。“和/或”描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。此外,对于单数形式“a”,“an”和“the”出现的元素(element),除非上下文另有明确规定,否则其不意味着“一个或仅一个”,而是意味着“一个或多于一个”。例如,“a device”意味着对一个或多个这样的device。再者,至少一个(at least one of)意味着后续关联对象中的一个或任意组合,例如“A、B和C中的至少一个”包括A,B,C,AB,AC,BC,或ABC。在本申请的文字描述中,字符“/”,一般表示前后关联对象是一种“或”的关系;在本申请的公式中,字符“/”,表示前后关联对象是一种“相除”的关系。In this application, "at least one" refers to one or more, "multiple" refers to two or more, and other quantifiers are similar. "And/or" describes the association relationship between associated objects, indicating that there can be three kinds of relationships, for example, A and/or B, which can mean that A exists alone, A and B exist at the same time, and B exists alone. Furthermore, occurrences of the singular forms "a", "an" and "the" do not mean "one or only one" unless the context clearly dictates otherwise, but rather "one or more" in one". For example, "a device" means to one or more such devices. Furthermore, at least one of means one or any combination of subsequent associated objects, for example "at least one of A, B and C" includes A, B, C, AB, AC, BC, or ABC . In the text description of this application, the character "/" generally indicates that the related objects before and after are a kind of "or" relationship; in the formula of this application, the character "/" indicates that the related objects are a kind of "division" Relationship.
可以理解的是,在本申请的实施例中涉及的各种数字编号仅为描述方便进行的区分,并不用来限制本申请的实施例的范围。上述各过程的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定。It can be understood that, the various numbers and numbers involved in the embodiments of the present application are only for the convenience of description, and are not used to limit the scope of the embodiments of the present application. The size of the sequence numbers of the above processes does not mean the sequence of execution, and the sequence of execution of each process should be determined by its function and internal logic.

Claims (22)

  1. 一种日志管理方法,其特征在于,包括:A log management method, comprising:
    将硬盘的存储空间划分为多个段,一个段包括一个或多个物理块,所述一个段用于存储日志;Divide the storage space of the hard disk into multiple segments, one segment includes one or more physical blocks, and the one segment is used to store logs;
    接收第一写日志请求和第二写日志请求,所述第一写日志请求包括第一日志项,所述第二写日志请求包括第二日志项;receiving a first log write request and a second log write request, the first log write request includes a first log entry, and the second log write request includes a second log entry;
    并行地将所述第一日志项写入所述多个段中的第一段,以及将所述第二日志项写入所述第一段。The first log entry is written to the first segment of the plurality of segments in parallel, and the second log entry is written to the first segment.
  2. 根据权利要求1所述的方法,其特征在于,在所述将所述第一日志项写入所述第一段的过程中或者在所述将所述第二日志项写入所述第一段的过程中没有执行加锁机制。The method according to claim 1, wherein in the process of writing the first log entry into the first segment or during the writing the second log entry into the first segment There is no locking mechanism implemented during the segment.
  3. 根据权利要求1或2所述的方法,其特征在于,所述方法还包括:The method according to claim 1 or 2, wherein the method further comprises:
    将所述第一写日志请求的日志序列号LSN与日志索引进行匹配,确定所述第一日志项待写入的段是所述第一段,所述日志索引用于指示所述第一段与所述LSN的对应关系。Matching the log sequence number LSN of the first log write request with the log index to determine that the segment to be written in the first log entry is the first segment, and the log index is used to indicate the first segment Correspondence with the LSN.
  4. 根据权利要求3所述的方法,其特征在于,所述日志索引包括第一索引和第二索引,所述第一索引用于指示所述第一段在所述硬盘中的存储地址范围,所述第二索引用于至少一个所述存储地址范围中每个日志项的LSN和存储地址之间的对应关系;The method according to claim 3, wherein the log index comprises a first index and a second index, the first index is used to indicate a storage address range of the first segment in the hard disk, and the The second index is used for the correspondence between the LSN and the storage address of each log entry in at least one of the storage address ranges;
    将所述LSN与日志索引进行匹配确定所述第一段,包括:Matching the LSN with the log index to determine the first segment includes:
    判断所述LSN与第三日志项的LSN是否连续,所述第三日志项为所述第二索引记录的任意一个日志项;Judging whether the LSN of the LSN is continuous with the LSN of the third log entry, and the third log entry is any log entry recorded by the second index;
    若所述LSN与所述第三日志项的LSN连续,将所述第三日志项所在的段作为所述第一段;If the LSN is continuous with the LSN of the third log entry, the segment where the third log entry is located is used as the first segment;
    若所述LSN与第三日志项的LSN不连续,将所述LSN与所述第一索引进行匹配,确定所述第一段,所述第一段中第一个日志项的LSN与所述第一写日志请求的LSN匹配。If the LSN is not continuous with the LSN of the third log entry, the LSN is matched with the first index to determine the first segment, where the LSN of the first log entry in the first segment is the same as the first index. The LSN of the first write log request matches.
  5. 根据权利要求3或4所述的方法,其特征在于,所述日志索引存储在缓存中。The method according to claim 3 or 4, wherein the log index is stored in a cache.
  6. 根据权利要求1-5中任一项所述的方法,其特征在于,所述第一日志项包括描述信息和数据信息,所述描述信息包括所述第一写日志请求的LSN、日志项长度以及日志项长度校验和,所述数据信息用于指示所述第一日志项记录的日志内容。The method according to any one of claims 1-5, wherein the first log entry includes description information and data information, and the description information includes an LSN of the first log write request and a log entry length and a log entry length checksum, the data information is used to indicate the log content recorded by the first log entry.
  7. 根据权利要求6所述的方法,其特征在于,将所述第一日志项写入所述第一段,包括:The method according to claim 6, wherein writing the first log entry into the first segment comprises:
    依据所述第一写日志请求的LSN生成起始存储地址,所述起始存储地址处于所述第一段的存储地址范围;generating an initial storage address according to the LSN of the first write log request, and the initial storage address is in the storage address range of the first segment;
    依据所述起始存储地址将所述第一日志项写入所述第一段。The first log entry is written into the first segment according to the starting storage address.
  8. 根据权利要求7所述的方法,其特征在于,在依据所述第一写日志请求的LSN生成起始存储地址之后,所述方法还包括:The method according to claim 7, wherein after generating the starting storage address according to the LSN of the first log write request, the method further comprises:
    向备份设备发送所述第一写日志请求的LSN和起始存储地址。Send the LSN and the starting storage address of the first log write request to the backup device.
  9. 根据权利要求1-8中任一项所述的方法,其特征在于,在所述接收第一写日志请求之后,所述方法还包括:The method according to any one of claims 1-8, wherein after the receiving the first log write request, the method further comprises:
    接收备份设备发送的所述第一写日志请求的LSN和起始存储地址;receiving the LSN and the initial storage address of the first log write request sent by the backup device;
    依据所述第一写日志请求的LSN和所述起始存储地址,将所述第一日志项写入所述第一段。The first log entry is written into the first segment according to the LSN of the first log write request and the start storage address.
  10. 根据权利要求1-9中任一项所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 1-9, wherein the method further comprises:
    向客户端发送日志写入响应,所述日志写入响应用于指示已将所述第一日志和所述第二日志写入所述第一段。A log write response is sent to the client, where the log write response is used to indicate that the first log and the second log have been written to the first segment.
  11. 一种日志管理装置,其特征在于,包括:A log management device, comprising:
    处理模块,用于将硬盘的存储空间划分为多个段,一个段包括一个或多个物理块,所述一个段用于存储日志;a processing module, configured to divide the storage space of the hard disk into multiple segments, one segment includes one or more physical blocks, and the one segment is used for storing logs;
    通信模块,用于接收第一写日志请求和第二写日志请求,所述第一写日志请求包括第一日志项,所述第二写日志请求包括第二日志项;a communication module, configured to receive a first log write request and a second log write request, the first log write request includes a first log entry, and the second log write request includes a second log entry;
    所述处理模块,还用于并行地将所述第一日志项写入所述多个段中的第一段,以及将所述第二日志项写入所述第一段。The processing module is further configured to write the first log entry into the first segment of the plurality of segments in parallel, and write the second log entry into the first segment.
  12. 根据权利要求11所述的装置,其特征在于,在所述将所述第一日志项写入所述第一段的过程中或者在所述将所述第二日志项写入所述第一段的过程中没有执行加锁机制。The apparatus according to claim 11, wherein in the process of writing the first log entry into the first segment or during the writing the second log entry into the first segment There is no locking mechanism implemented during the segment.
  13. 根据权利要求11或12所述的装置,其特征在于,所述装置还包括:The device according to claim 11 or 12, wherein the device further comprises:
    索引模块,用于将所述第一写日志请求的日志序列号LSN与日志索引进行匹配,确定所述第一日志项待写入的段是所述第一段,所述日志索引用于指示所述第一段与所述LSN的对应关系。An indexing module, configured to match the log sequence number LSN of the first log write request with a log index, and determine that the segment to be written in the first log entry is the first segment, and the log index is used to indicate Correspondence between the first segment and the LSN.
  14. 根据权利要求13所述的装置,其特征在于,所述日志索引包括第一索引和第二索引,所述第一索引用于指示所述第一段在所述硬盘中的存储地址范围,所述第二索引用于至少一个所述存储地址范围中每个日志项的LSN和存储地址之间的对应关系;The apparatus according to claim 13, wherein the log index includes a first index and a second index, the first index is used to indicate a storage address range of the first segment in the hard disk, and the The second index is used for the correspondence between the LSN and the storage address of each log entry in at least one of the storage address ranges;
    所述索引模块,具体用于判断所述LSN与第三日志项的LSN是否连续,所述第三日志项为所述第二索引记录的任意一个日志项;The index module is specifically configured to judge whether the LSN of the LSN and the third log entry are continuous, and the third log entry is any log entry recorded by the second index;
    若所述LSN与所述第三日志项的LSN连续,所述索引模块,具体用于将所述第三日志项所在的段作为所述第一段;If the LSN is continuous with the LSN of the third log entry, the index module is specifically configured to use the segment where the third log entry is located as the first segment;
    若所述LSN与第三日志项的LSN不连续,所述索引模块,具体用于将所述LSN与所述第一索引进行匹配,确定所述第一段,所述第一段中第一个日志项的LSN与所述第一写日志请求的LSN匹配。If the LSN is not continuous with the LSN of the third log entry, the index module is specifically configured to match the LSN with the first index, and determine the first segment, where the first segment in the first segment is the first segment. The LSN of each log entry matches the LSN of the first log write request.
  15. 根据权利要求13或14所述的装置,其特征在于,所述日志索引存储在缓存中。The apparatus according to claim 13 or 14, wherein the log index is stored in a cache.
  16. 根据权利要求11-15中任一项所述的装置,其特征在于,所述第一日志项包括描述信息和数据信息,所述描述信息包括所述第一写日志请求的LSN、日志项长度以及日志项长度校验和,所述数据信息用于指示所述第一日志项记录的日志内容。The apparatus according to any one of claims 11-15, wherein the first log entry includes description information and data information, and the description information includes an LSN of the first log write request and a log entry length and a log entry length checksum, the data information is used to indicate the log content recorded by the first log entry.
  17. 根据权利要求16所述的装置,其特征在于,所述处理模块,具体用于依据所述第一写日志请求的LSN生成起始存储地址,所述起始存储地址处于所述第一段的存储地址范围;The apparatus according to claim 16, wherein the processing module is specifically configured to generate a starting storage address according to the LSN of the first log write request, and the starting storage address is in the first segment storage address range;
    所述处理模块,具体用于依据所述起始存储地址将所述第一日志项写入所述第一段。The processing module is specifically configured to write the first log entry into the first segment according to the starting storage address.
  18. 根据权利要求17所述的装置,其特征在于,所述通信模块,还用于向备份设备发送所述第一写日志请求的LSN和起始存储地址。The apparatus according to claim 17, wherein the communication module is further configured to send the LSN and the starting storage address of the first log write request to the backup device.
  19. 根据权利要求11-18中任一项所述的装置,其特征在于,所述通信模块,还用于接收备份设备发送的所述第一写日志请求的LSN和起始存储地址;The apparatus according to any one of claims 11-18, wherein the communication module is further configured to receive the LSN and the initial storage address of the first log write request sent by the backup device;
    所述处理模块,还用于依据所述第一写日志请求的LSN和所述起始存储地址,将所述第一日志项写入所述第一段。The processing module is further configured to write the first log entry into the first segment according to the LSN of the first log write request and the starting storage address.
  20. 根据权利要求11-19中任一项所述的装置,其特征在于,所述通信模块,还用于向客户端发送日志写入响应,所述日志写入响应用于指示已将所述第一日志和所述第二日志写入所述第一段。The apparatus according to any one of claims 11-19, wherein the communication module is further configured to send a log write response to the client, where the log write response is used to indicate that the first A log and the second log are written to the first segment.
  21. 一种通信设备,其特征在于,包括芯片,所述芯片包括处理器和存储器,所述存储器用于存储计算机指令,当所述处理器执行该计算机指令时,以使所述通信设备执行权利要求1-10中任一项所述的方法。A communication device, characterized in that it includes a chip, the chip includes a processor and a memory, the memory is used for storing computer instructions, when the processor executes the computer instructions, so that the communication device executes the claims The method of any one of 1-10.
  22. 一种计算机可读存储介质,其特征在于,所述存储介质中存储有计算机程序或指令,当所述计算机程序或指令被处理器或通信设备执行时,实现如权利要求1至10中任一项所述的方法。A computer-readable storage medium, characterized in that, a computer program or instruction is stored in the storage medium, and when the computer program or instruction is executed by a processor or a communication device, any one of claims 1 to 10 is implemented. method described in item.
PCT/CN2021/140172 2021-04-22 2021-12-21 Log management method and apparatus WO2022222523A1 (en)

Applications Claiming Priority (4)

Application Number Priority Date Filing Date Title
CN202110436373.3 2021-04-22
CN202110436373 2021-04-22
CN202110744793.8 2021-06-30
CN202110744793.8A CN115237854A (en) 2021-04-22 2021-06-30 Log management method and device

Publications (1)

Publication Number Publication Date
WO2022222523A1 true WO2022222523A1 (en) 2022-10-27

Family

ID=83666063

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/140172 WO2022222523A1 (en) 2021-04-22 2021-12-21 Log management method and apparatus

Country Status (2)

Country Link
CN (1) CN115237854A (en)
WO (1) WO2022222523A1 (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103729442A (en) * 2013-12-30 2014-04-16 华为技术有限公司 Method for recording event logs and database engine
US9361306B1 (en) * 2012-12-27 2016-06-07 Emc Corporation Managing concurrent write operations to a file system transaction log
CN105868228A (en) * 2014-11-25 2016-08-17 Sap欧洲公司 In-memory database system providing lockless read and write operations for OLAP and OLTP transactions
CN106462449A (en) * 2014-06-26 2017-02-22 亚马逊科技公司 Multi-database log with multi-item transaction support
CN110832473A (en) * 2017-06-21 2020-02-21 华为技术有限公司 Log structure management system and method

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9361306B1 (en) * 2012-12-27 2016-06-07 Emc Corporation Managing concurrent write operations to a file system transaction log
CN103729442A (en) * 2013-12-30 2014-04-16 华为技术有限公司 Method for recording event logs and database engine
CN106462449A (en) * 2014-06-26 2017-02-22 亚马逊科技公司 Multi-database log with multi-item transaction support
CN105868228A (en) * 2014-11-25 2016-08-17 Sap欧洲公司 In-memory database system providing lockless read and write operations for OLAP and OLTP transactions
CN110832473A (en) * 2017-06-21 2020-02-21 华为技术有限公司 Log structure management system and method

Also Published As

Publication number Publication date
CN115237854A (en) 2022-10-25

Similar Documents

Publication Publication Date Title
US8819335B1 (en) System and method for executing map-reduce tasks in a storage device
US10437721B2 (en) Efficient garbage collection for a log-structured data store
US9092321B2 (en) System and method for performing efficient searches and queries in a storage node
US9021189B2 (en) System and method for performing efficient processing of data stored in a storage node
KR102044023B1 (en) Data Storage System based on a key-value and Operating Method thereof
US20160179581A1 (en) Content-aware task assignment in distributed computing systems using de-duplicating cache
WO2017041570A1 (en) Method and apparatus for writing data to cache
CN112632069B (en) Hash table data storage management method, device, medium and electronic equipment
WO2019127018A1 (en) Memory system access method and device
WO2023035646A1 (en) Method and apparatus for expanding memory, and related device
WO2023165196A1 (en) Journal storage acceleration method and apparatus, and electronic device and non-volatile readable storage medium
WO2023125524A1 (en) Data storage method and system, storage access configuration method and related device
US20220253252A1 (en) Data processing method and apparatus
US20240086113A1 (en) Synchronous write method and device, storage system and electronic device
US20240070120A1 (en) Data processing method and apparatus
US20170300255A1 (en) Method and Apparatus for Detecting Transaction Conflict and Computer System
WO2022222523A1 (en) Log management method and apparatus
WO2023050856A1 (en) Data processing method and storage system
WO2023000770A1 (en) Method and apparatus for processing access request, and storage device and storage medium
WO2022262345A1 (en) Data management method and apparatus, and storage space management method and apparatus
US11662949B2 (en) Storage server, a method of operating the same storage server and a data center including the same storage server
CN116594551A (en) Data storage method and device
CN115793957A (en) Method and device for writing data and computer storage medium
WO2023093091A1 (en) Data storage system, smart network card, and computing node
WO2023029417A1 (en) Data storage method and device

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21937745

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21937745

Country of ref document: EP

Kind code of ref document: A1