A data storage method, system, and electronic device
By using multiple log shards for parallel writing and instance number management in the data storage system, the problem of low log file writing speed is solved and the writing performance and data storage efficiency of the key-value storage system are improved.
Patent Information
- Application Number
- CN202111421028.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-26
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2041-11-26
AI Technical Summary
The writing speed of log files is lower than the writing speed of memory tables, which becomes the writing performance bottleneck of the key-value storage system and affects the data storage efficiency.
Use multiple log shards to write to the disk partition of the data storage system in parallel, manage operation records through instance numbers and operation sequence numbers, avoid single log shard performance bottlenecks, and directly use disks or disk partitions to store write-ahead logs, reducing the file system performance loss.
It improves the overall performance of the data storage system, reduces the impact of log writing performance bottlenecks, improves data storage efficiency, and avoids the additional performance loss of file system storage of write-ahead logs.
Smart Images

Figure CN114625312B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data storage, and in particular to a data storage method, system and electronic equipment. Background Art
[0002] The key-value storage system is a commonly used data storage system. When the system stores data, it creates a memory table, and the relevant parameters of the data to be stored are written into the memory table. When the memory table is full, the system background will create a new memory table to continue to accept subsequent data write requests. When creating the memory table, a corresponding log file is usually created. The log file is saved on a stable storage device. If the system fails, the log file can also be read after the failure is recovered to ensure data reliability.
[0003] In the process of implementing the embodiments of the present invention, the inventors found that due to the different data storage locations, the write speed of the log files stored in the stable storage device is much lower than the write speed of the memory table in the memory. Therefore, the write performance of the log files will become the write performance bottleneck of the entire key-value storage system. Summary of the invention
[0004] The main technical problem solved by the embodiments of the present invention is how to improve the writing performance of log files to enhance data storage efficiency.
[0005] In order to solve the above technical problems, a technical solution adopted by an embodiment of the present invention is: to provide a data storage method, which is applied to a data storage system, wherein the data storage system generates an instance number for marking a system running instance each time it is run, and the instance number is stored in the global information of the data storage system, and the method comprises:
[0006] At least two log shards are created based on the log area, wherein the log area is a disk or a disk partition for storing write-ahead logs, each log shard has a different shard number, and the shard number is recorded in the header information of the corresponding log shard;
[0007] Receive a data write request, and assign a unique operation sequence number in this running instance to the data write request, wherein the data write request includes an operation type, operation data, and a shard number of a log shard;
[0008] Writing an operation record corresponding to the data write request to one of the at least two log shards, wherein the operation record includes the instance number, the data write request, and an operation sequence number corresponding to the data write request;
[0009] Writing the data write request to a memory table, and updating a maximum operation sequence number in the memory table based on an operation sequence number corresponding to the data write request, wherein the maximum operation sequence number is stored in the memory table and is used to record an operation sequence number corresponding to the data write request most recently stored in the memory table;
[0010] After the memory table is full, the data write request in the memory table is flushed to the sorting table, and after the flushing is completed, the maximum operation sequence number is stored in the global information of the data storage system;
[0011] Based on the maximum operation sequence number, the operation record of the data write request is recovered.
[0012] Optionally, writing the operation record corresponding to the data write request to one of the at least two log shards includes:
[0013] Obtain the shard number in the data write request;
[0014] Selecting the log shard having the shard number based on the shard number;
[0015] Write the operation record corresponding to the data write request to the selected log shard.
[0016] Optionally, writing the operation record corresponding to the data write request to one of the at least two log shards includes:
[0017] Obtaining a key for the data writing request;
[0018] Selecting the corresponding log shard based on the key, wherein the data write requests with the same key select the same log shard;
[0019] Write the operation record corresponding to the data write request to the selected log shard.
[0020] Optionally, the creating at least two log shards based on the log area includes:
[0021] Obtain the capacity of the log area and the number of log shards, wherein the minimum unit for storing data in the log area is a log area data block;
[0022] The capacity of each log shard is calculated according to the capacity of the log area and the number of the log shards, and a unique shard number is assigned to each log shard, and the capacity of the log shard and the shard number are stored in the header information of the log shard, wherein the capacity of the log shard is an integer multiple of the log area data block, and the header information of the log shard also records the instance number of the current running instance, the starting storage position and the starting sequence number, wherein the starting storage position is the position in the log shard in a running instance for storing the first operation record, and the starting sequence number is the operation sequence number of the first operation record in a running instance;
[0023] Based on the number of the log shards and the capacity of the log shards, the position of each log shard is calculated, and the position of the log shard includes the starting position of the log shard and the ending position of the log shard.
[0024] Optionally, the reclaiming the operation record of the data write request based on the maximum operation sequence number includes:
[0025] Obtaining the maximum operation sequence number of the memory table that has been flushed;
[0026] Based on the starting storage position, sequentially obtain the operation sequence numbers of the operation records in the log shards, and compare the operation sequence numbers with the maximum operation sequence number;
[0027] Obtain the first operation record whose operation sequence number is greater than the maximum operation sequence number as a reference operation record, and obtain the first position of the reference operation record in the log shard;
[0028] The starting storage position in the header information of the log shard is updated to be the first position, and the starting sequence number in the header information of the log shard is updated to be the operation sequence number of the reference operation record.
[0029] Optionally, the method further includes: when the data storage system is restarted, detecting whether the log segment needs to be replayed, and if so, triggering a replay mechanism of the log segment, wherein the detecting whether the log segment needs to be replayed includes:
[0030] Obtain the instance number and the starting sequence number in the log shard header information;
[0031] Detect whether the instance number is the same as the instance number in the global information, if not, no playback is required;
[0032] Detect whether the starting sequence number is greater than the maximum operation sequence number in the global information, if not, no playback is required;
[0033] If the instance number is the same as the instance number in the global information, and the starting sequence number is greater than the maximum operation sequence number in the global information, it is determined that the log segment needs to be replayed, and the replay mechanism of the log segment is triggered.
[0034] Optionally, the method further includes: when a playback mechanism of the log shard is triggered, playing back the data in the log shard, wherein playing back the data in the log shard includes:
[0035] Acquire the instance number and the maximum operation sequence number based on the global information;
[0036] Create a new memory table;
[0037] Acquire the operation record to be replayed based on the instance number and the maximum operation sequence number;
[0038] The operation records to be replayed are stored in the new memory table in sequence;
[0039] Flashing the new memory table to the sorting table;
[0040] The maximum operation sequence number in the global information is updated.
[0041] Optionally, the acquiring the operation record to be replayed based on the instance number and the maximum operation sequence number includes:
[0042] Obtaining the maximum operation sequence number;
[0043] Obtain the starting position and the starting storage position of the log shard, and obtain the first operation record stored in the log shard according to the starting position and the starting storage position;
[0044] Based on the first operation record, sequentially detecting whether the operation records in the log shards are operation records to be replayed, wherein the detection method includes:
[0045] Check whether the magic value and the instance number of the operation record are correct;
[0046] If correct, then detecting whether the operation sequence number of the operation record is greater than or equal to the maximum operation sequence number;
[0047] If so, the operation record is obtained as the operation record to be replayed, and the maximum operation sequence number is updated based on the operation sequence number of the operation record to be replayed.
[0048] In order to solve the above technical problems, another technical solution adopted by the embodiment of the present invention is: to provide a data storage system, wherein the data storage system generates an instance number for marking the system running instance each time it is run, and the instance number is stored in the global information of the data storage system, and the system comprises:
[0049] A shard configuration module is used to create at least two log shards based on a log area, wherein the log area is a disk or a disk partition for storing write-ahead logs, and each log shard has a different shard number, which is recorded in the header information of the corresponding log shard;
[0050] A request accepting module, used to receive a data writing request and assign a unique and increasing operation sequence number in this running instance to the data writing request, wherein the data writing request includes an operation type, operation data, and a shard number of a log shard;
[0051] A write-ahead log module, configured to write an operation record corresponding to the data write request to one of the at least two log shards, wherein the operation record includes the instance number, the data write request, and an operation sequence number corresponding to the data write request;
[0052] A data cache module, used to write the data write request to a memory table, and based on the operation sequence number corresponding to the data write request, update the maximum operation sequence number in the memory table, wherein the maximum operation sequence number is stored in the memory table and is used to record the operation sequence number corresponding to the data write request most recently stored in the memory table;
[0053] A data writing module, used for writing the data writing request in the memory table to the sorting table, and storing the maximum operation sequence number in the global information of the data storage system after writing is completed;
[0054] The log recovery module is used to recover the operation record of the data write request based on the maximum operation sequence number.
[0055] In order to solve the above technical problems, another technical solution adopted in the embodiment of the present invention is: to provide an electronic device, the electronic device comprising:
[0056] at least one processor;
[0057] a memory communicatively coupled to the at least one processor;
[0058] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the data storage method described above.
[0059] Different from the related art, the present invention provides a data storage method, system and electronic device. By using multiple log shards to write operation records in parallel to the disk partitions of the data storage system, the impact of the write performance bottleneck of a single log can be reduced and the overall performance of the data storage system can be improved. In addition, the disk or disk partition is directly used to store the pre-write log, avoiding the additional performance loss caused by using the file system to store the pre-write log. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] One or more embodiments are exemplarily described by corresponding drawings, which do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and the figures in the drawings do not constitute proportional limitations unless otherwise stated.
[0061] Figure 1 It is a flow chart of a data storage method provided by an embodiment of the present invention;
[0062] Figure 2 It is a schematic diagram of a process of creating at least two log shards in a data storage method provided in an embodiment of the present invention;
[0063] Figure 3 It is a schematic diagram of a method for writing operation records to a selected log shard in a data storage method provided by an embodiment of the present invention;
[0064] Figure 4 It is a schematic diagram of another method for writing operation records to a selected log shard in the data storage method provided by an embodiment of the present invention;
[0065] Figure 5 It is a schematic diagram of a method for recovering log fragments in a data storage method provided in an embodiment of the present invention;
[0066] Figure 6 It is a schematic diagram of a method for detecting whether a log segment needs to be replayed in a data storage method provided in an embodiment of the present invention;
[0067] Figure 7 It is a flow chart of determining whether a log segment needs to be replayed in a data storage method provided by an embodiment of the present invention;
[0068] Figure 8 It is a schematic diagram of a playback method of log shards in a data storage method provided by an embodiment of the present invention;
[0069] Fig. 9 It is a schematic diagram of the process of obtaining the operation record to be played back in the data storage method provided by an embodiment of the present invention;
[0070] Fig.10is a schematic diagram of log sharding in a log area provided by an embodiment of the present invention;
[0071] Fig.11 A schematic diagram of an example table of operation records in an example of an embodiment of the present invention;
[0072] Fig.12 It is a schematic diagram of a log sharding operation sequence number table in an example of an embodiment of the present invention;
[0073] Fig.13 is a schematic diagram of log sharding and memory table in a storage example provided by an embodiment of the present invention;
[0074] Fig.14 This is a schematic diagram of a storage example provided by an embodiment of the present invention before log sharding is recycled;
[0075] Fig.15 This is a schematic diagram of a storage example provided by an embodiment of the present invention after log sharding is recycled;
[0076] Fig.16 is a storage example diagram of log sharding in a storage example provided by an embodiment of the present invention;
[0077] Fig.17 is a structural schematic diagram of a data storage system provided by an embodiment of the present invention;
[0078] Fig.18 It is a schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0079] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0080] It should be noted that, if there is no conflict, the various features in the embodiments of the present invention can be combined with each other, and all are within the protection scope of the present invention. In addition, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in a different order from the module division in the device schematic diagram or the order in the flow chart.
[0081] Unless otherwise defined, all technical and scientific terms used in this specification have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in the specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The term "and / or" used in this specification includes any and all combinations of one or more of the related listed items.
[0082] The embodiment of the present invention provides a data storage method, which is applied to a data storage system. The data storage system in the embodiment of the present invention takes a key-value storage system (key-value store) as an example. The systems described below can all be regarded as key-value storage systems. The data storage system generates an instance ID for marking the current running instance each time it runs. The instance ID is usually stored in the global information of the data storage system. The global information of the system is stored in a stable storage medium, such as a disk. Please refer to Figure 1 , the data storage method comprises:
[0083] S11. Create at least two log shards based on the log area, wherein the log area is a disk or disk partition used to store write-ahead logs. Each log shard corresponds to a different shard number, and the shard number is recorded in the header information of the corresponding log shard. Write-ahead logs are a common method in data storage systems to ensure the atomicity and persistence of data operations. They are usually files written sequentially and stored on a stable storage medium, such as a disk. The disk or disk partition used to store write-ahead logs is called a log area. The location of the log area corresponding to the disk or disk partition is the path of the log area. The path of the log area is stored in the global information of the system. For details, please refer to Figure 2 , the step of creating at least two log shards based on the log area includes:
[0084] S111. Obtain the capacity of the log area and the number of log shards, wherein the minimum unit for storing data in the log area is the log area data block. The log area is a disk or disk partition for storing pre-write logs. The path of the log area is stored in the global information of the system, which is used to specify the disk corresponding to the log area. The capacity of the log area is the size of the disk corresponding to the log area or the size of the disk partition. The capacity of the log area can usually be expressed as disk_size. The log area data block is the minimum unit for storing data in the log area, which can be set to an integer multiple of the disk data block (indicating the minimum unit of disk read data, usually 512 bytes), usually expressed as block_size. If the data to be written in some scenarios is relatively small, the disk data block can be set to the log area data block, that is, 512 bytes; if the data to be written in some scenarios is large, a larger log area data block can be set, that is, 512*a bytes, and the value of a is determined according to the use environment. Such a setting can store data more conveniently. The data written to the log area needs to be set to an integer multiple of the log area data block size. If the data is not an integer multiple of the log area data block size, it is necessary to fill the data with zeros until the data reaches an integer multiple of the log area data block size. For example, in a log shard, if the header information of the log shard is smaller than one log area data block, then zeros are added to the data of the header information until the data of the header information reaches the size of one log area data block; if the data of operation record 1 in the log shard is larger than one log area data block and smaller than two log area data blocks, then zeros are added to the data of operation record 1 until the data of operation record 1 reaches the size of two log area data blocks. This setting can ensure that in a fault scenario, the system can search for the starting position of the operation record in the log shard in units of log area data blocks, making the inspection process more convenient. The number of log shards and the size of the log shard data blocks can usually be configured in advance by the configuration personnel, and this information is stored in the header information of the corresponding log shard. That is, before the system is run for the first time, the configuration personnel will determine in advance how many log shards the log area will be divided into, and what the size of the log shard data block will be set to, and store the number of log shards in the global information of the system. The capacity of the log area and the number of log shards can be obtained based on the global information of the system.
[0085] S112. Calculate the capacity of each log shard according to the capacity of the log area and the number of the log shards, assign a unique shard number to each log shard, and store the capacity of the log shard and the shard number in the header information of the log shard. The capacity of the log shard is an integer multiple of the log area data block, and the header information of the log shard also records the instance number of the current running instance, the starting storage position and the starting sequence number. The starting storage position is the position in the log shard in a running instance for storing the first operation record, and the starting sequence number is the operation sequence number of the first operation record in a running instance.
[0086] The capacity of the log area disk_size is divided by the number of log shards n to get the capacity of each log shard. The capacity of the log shard can be expressed as max_size. The number of log shards is recorded as n, and the capacity of each log shard is max_size / n. The capacity of the log shard is set to an integer multiple of the log area data block. If the value obtained by dividing the capacity of the log area by the number of log shards is not an integer multiple of the log area data block, the decimal part is discarded and only the integer part is retained as the capacity of the log shard. Please combine Fig.10 , multiple log shards are continuously distributed in the disk or disk partition corresponding to the log area. Each log shard consists of the header information of a shard header and several operation records. Fig.10 The null in indicates that there is no free space to store valid operation records. The shard header stores the header information of the log shard. The example format of the header information of the shard header is as follows:
[0087] instance id: the instance number of the current running instance;
[0088] index: the shard number of the log shard;
[0089] block_size: log area data block size;
[0090] max_size: the capacity of the log shard, which is an integer multiple of the log area data block;
[0091] start_offset: the starting position of the log shard, that is, the offset from the starting position of the log area to the starting position of the log shard, in bytes;
[0092] end_offset: the end position of the log shard, that is, the offset from the start position of the log area to the end position of the log shard, in bytes;
[0093] start_pos: the starting storage position, that is, the offset from the starting position of the log shard to the starting position of the first operation record in the log shard, in bytes;
[0094] start_seq: the starting sequence number, that is, the operation sequence number of the first operation record in the log shard.
[0095] S113. Based on the number of log shards and the capacity of the log shards, calculate the position of each log shard, the position of the log shard includes the starting position of the log shard and the ending position of the log shard. The shard number of the log shard starts from 0 and increases continuously. The starting position of the log shard is calculated as: the starting position of the log area + the shard number of the log shard * the capacity of the log shard, that is, 0+max_size*index; the ending position of the log shard is calculated as the starting position of the log area + (the shard number of the log shard + 1) * the capacity of the log shard, that is, 0+max_size*(index+1).
[0096] For example, take an 8GB disk as an example. If a 4GB disk partition in the disk is selected as the log area, the number of log shards is 4, the size of the log area data block is 4KB, the size of the log shard header information is 128 bytes, and the magic value of the operation record is 0x5a5a5a5a, a total of 4 bytes, where the magic value can be used to identify the starting position of the operation record, and the first few bytes of each operation record are the set magic value. Based on the above configuration, the log area is divided into 4 log shards, namely log shard 0, log shard 1, log shard 2 and log shard 3. The size of each log shard is 4GB / 4=1GB, and the header information of each log shard is as follows:
[0097] Header information of log fragment 0:
[0098] instance id: 0
[0099] index:0
[0100] block_size: 4096
[0101] max_size: 1073741824
[0102] start_offset: 0
[0103] end_offset: 1073741823
[0104] start_pos: 4096
[0105] start_seq: 0
[0106] Header information of log shard 1:
[0107] instance id: 0
[0108] index:1
[0109] block_size: 4096
[0110] max_size: 1073741824
[0111] start_offset: 1073741824
[0112] end_offset: 2147483647
[0113] start_pos: 4096
[0114] start_seq: 0
[0115] Header information of log shard 2:
[0116] instance id: 0
[0117] index:2
[0118] block_size: 4096
[0119] max_size: 1073741824
[0120] start_offset: 2147483648
[0121] end_offset: 3221225471
[0122] start_pos: 4096
[0123] start_seq: 0
[0124] Header information of log shard 3:
[0125] instance id: 0
[0126] index:3
[0127] block_size: 4096
[0128] max_size: 1073741824
[0129] start_offset: 3221225472
[0130] end_offset: 4294967295
[0131] start_pos: 4096
[0132] start_seq: 0
[0133] When writing the data of the header information to the shard header of the corresponding log shard, assuming that the size of the header information of the log shard is 128 bytes and the size of the log area data block is 4096 bytes, 0 is added at 128 bytes to 4096 bytes of the header information, and the header information data after the zero filling is written to the corresponding position of the header information of the corresponding log shard, wherein the starting position of the header information is specified according to the starting position start_offset of the log shard in the header information. It should be noted that the log shard needs to be formatted before the system is run for the first time, and the above header information of the log shard is written to the corresponding log shard. Header; after the system is started, the instance number of the current running instance is generated. For example, the instance number can be determined based on the startup time this_start_time, and the header information of the log shard is updated in sequence, including updating the instance number in the header information to the startup time, that is, instance_id = this_start_time, and updating the operation sequence number of the first operation record in the log shard to 0, that is, start_seq = 0; the updated header information is written to the disk offset 0; the write position of the log shard is updated to 4096, which can be recorded as write_pos = 4096.
[0134] S12, receiving a data write request, and assigning a unique operation sequence number in this running instance to the data write request, wherein the data write request includes an operation type, operation data, and a shard number of a log shard. The data write request format provided in an embodiment of the present invention is: operation type (operation data, shard number of a log shard), for example: Put (key1, val1, 1) or Del (key1, 1), etc. Among them, the operation type is not limited to only Put and Del, and may also be other operation types in some other embodiments; key1 and val1 are operation data, and 1 is the shard number of a log shard. The operation sequence number is assigned in ascending order based on the order in which the data write request is received, and can be recorded as seq. For example, in a running instance, the first data write request received is assigned an operation sequence number of 0, the second data write request received is assigned an operation sequence number of 1, and the third data write request received is assigned an operation sequence number of 2, and so on.
[0135] S13. Write the operation record corresponding to the data write request to one of the at least two log shards, wherein the operation record includes the instance number, the data write request, and the operation sequence number corresponding to the data write request. Each data write request corresponds to an operation record, and the example format of the operation record is as follows:
[0136] magic: the magic value of the operation record;
[0137] instance id: the instance number of the current running instance;
[0138] seq: operation sequence number;
[0139] len: the length of the operation record, that is, the length of all data from magic to pad in this operation record;
[0140] op: operation type;
[0141] data: operation data;
[0142] pad: The padding byte at the end is 0, which is used to make the data recorded by the operation reach an integral multiple of the data block in the log area.
[0143] For details, please refer to Figure 3 , the step of writing the operation record corresponding to the data write request to one of the at least two log shards comprises:
[0144] S1301. Obtain the shard number in the data write request. Since the data write request format provided in the embodiment of the present invention includes the shard number of the log shard, the shard number can be directly obtained based on the data write request.
[0145] S1302: Select the log shard having the shard number based on the shard number;
[0146] S1303. Write the operation record corresponding to the data write request to the selected log shard.
[0147] For example, in a data storage system with n (n is a positive integer greater than or equal to 2) log shards, the received data write request 1 is Put(key1,val1,0), then according to the shard number 0, log shard 0 is selected, and the operation record 1 is written to log shard 0; the received data write request 2 is Put(key2,val2,1), then log shard 1 is selected, and the operation record 2 is written to log shard 1; the received data write request 3 is Del(key1,2), then log shard 2 is selected, and the operation record 3 is written to log shard 2.
[0148] In some other embodiments, see Figure 4 , the step of writing the operation record corresponding to the data write request to one of the at least two log shards comprises:
[0149] S131, obtaining the key of the data writing request; taking the key-value storage system as an example, the data writing request usually includes a key value, that is, the key of the data writing request.
[0150] S132: Select the corresponding log shard based on the key, wherein the data write requests with the same key select the same log shard;
[0151] S133. Write the operation record corresponding to the data write request to the selected log shard.
[0152] This method does not require the shard number in the data write request. For example, in a data storage system with 3 log shards, log shard 0 is selected for all data write requests with a key value of 1, log shard 1 is selected for all data write requests with a key value of 2, and log shard 2 is selected for all data write requests with a key value of 3. If the received data write request 1 is Put(key1,val1,0), log shard 0 is selected and operation record 1 is written to log shard 0; if the received data write request 2 is Put(key2,val2,1), log shard 1 is selected and operation record 2 is written to log shard 1; if the received data write request 3 is Del(key1,2), log shard 0 is selected and operation record 3 is written to log shard 0.
[0153] The two methods of writing operation records to the selected log shards described above are only examples and are not intended to limit the present invention to only the above two methods. In some other embodiments, it can also be a method of writing operation records to the selected log shards that can be implemented in a specific environment. It should be noted that in the various methods of writing operation records to log shards mentioned above, the operation records are all written to the log shards in a sequential and appended manner. The writing processes of different log shards are independent of each other and do not affect each other. The operation record writing processes of multiple log shards can be carried out simultaneously.
[0154] S14, write the data write request to the memory table, and based on the operation sequence number corresponding to the data write request, update the maximum operation sequence number in the memory table, wherein the maximum operation sequence number is stored in the memory table, and is used to record the operation sequence number corresponding to the data write request stored in the memory table the most recently. The maximum operation sequence number can be recorded as max_seq. After the operation record of the data write request is written into the log shard, the data write request is written into the memory table again, and the writing order of the data write request in the memory table is ensured to be the same as the order in which the system receives the data write request. After the process of writing the current data write request into the memory table is completed, the next data write request can be written into the memory table.
[0155] For example, based on the log sharding settings of the 4GB disk partition in the above example, Figure 3 Take the corresponding log shard selection method as an example, please combine Fig.11 and Fig.12 , suppose that after a system is started, it receives data write request 1: Put(key1,val1,0), data write request 2: Put(key2,val2,1), data write request 3: Del(key2,1), data write request 4: Put(key3,val3,3) and data write request 5: Del(key1,0) in sequence.
[0156] First, the data write request 1 is processed. After receiving the data write request 1, the system assigns the operation sequence number 0 to it and generates the operation record 0 (record0). Assuming that the length of the operation record 0 is 7688 bytes, the start time this_start_time is used as the instance number instance_id in this example. Since the size of the log area data block is 4KB, that is, 4096 bytes, the 504 bytes after the operation record 0 are padded with 0 to reach the size of the two log area data blocks of 8192 (4096*2) bytes. Figure 3 Take the corresponding log shard selection method as an example. For operation record 0, select log shard 0. Since only the header information in log shard 0 occupies 4096 bytes at this time, operation record 0 can be written immediately after the header information. Before writing operation record 0, the write position of log shard 0 is 4096. After writing operation record 0, the write position of log shard 0 is updated to 4096+8192=12288. The write position of log shard 0 is updated to write_pos=12288. Log shard 0 obtains the operation sequence number 0 of operation record 0 and records it as the current operation sequence number, which is expressed as cur_seq=0, which is used to record the operation sequence number of the most recently received data write request. Write Put(key1,val1) into the memory table and update the maximum operation sequence number max_seq of the memory table to 0. Add a record in the operation sequence table of log shard 0: seq=0, pos=4096, indicating that the operation sequence number of the most recently stored operation record is 0 and the position of the operation record is 4096.
[0157] Similar to the above process, after receiving the data write request 2, the system assigns an operation sequence number 1 to it and generates an operation record 1 (record 1). Assuming that the length of the operation record 1 is 78 bytes, 0 is added to the 4018 bytes after the operation record 1 to reach a log area data block size of 4096 bytes. Log shard 1 is selected for the operation record 1. Since only the header information in the log shard 1 occupies 4096 bytes at this time, the operation record 1 can be written immediately after the header information. Before writing the operation record 1, the write position of the log shard 1 is 4096. After writing the operation record 1, the write position of the log shard 1 is updated to 4096+4096=8192, and the write position of the log shard 1 is updated to write_pos=8192. The log shard 1 obtains the operation sequence number 1 of the operation record 1 and records it as the current operation sequence number, expressed as cur_seq=1, which is used to record the operation sequence number of the most recently received data write request. Write Put(key2,val2) into the memory table and update the maximum operation sequence number max_seq of the memory table to 1. Add a record to the operation sequence number table of log shard 1: seq=1, pos=4096, indicating that the operation sequence number of the most recently stored operation record is 1 and the position of the operation record is 4096.
[0158] Similarly, the processing process of data write request 3-5 can be obtained, see Fig.11 , the information of operation records 0-4 is shown in the figure. At this time, the maximum operation sequence number in the memory table is 4. Please refer to Fig.12 The information of the operation sequence table of each log shard is shown in the figure. Fig.13 The status of log shards 0-3 and their corresponding memory table 1 are shown in the figure. Memory table 1 stores data write requests and will eventually display the results of data processing. Fig.13 , the process of the five data write requests in the above example is: key1 = val1; key2 = val2; delete key2; key3 = val3; delete key1. So the data actually stored in memory table 1 is key3 = val3. The memory table in the figure represents the active memtable, which means the memory table that is receiving data write requests. When the active memtable is full of data, it will be converted into a read-only memtable. It can be understood that Fig.13 In the example, log shards 0-3 are shown separately to facilitate understanding of the solution. In actual situations, log shards 0-3 are located in continuous disk space on the disk.
[0159] It should be noted that in the above process, for different log shards, the writing process of operation records can be carried out simultaneously. For example, when writing operation record 0 to log shard 0, the system receives data write request 2, then the writing process of operation record 0 and the writing process of operation record 1 can be executed simultaneously; for the same log shard, the writing process of operation records is written in a sequential and append manner. For example, before writing operation record 4, it is necessary to wait until operation record 0 is finished, and operation record 4 needs to be written after operation record 0.
[0160] S15, flushing the data write request in the memory table to the sorting table, and storing the maximum operation sequence number in the global information of the data storage system after the flushing is completed.
[0161] When the active memory table is full of data, or when the user calls the flush interface, the active memory table will be converted to a read-only memory table. The data in the read-only memory table cannot be modified. After the data in the read-only memory table is flushed to the sorting table, the read-only memory table can be released. The data in the memory table is cached in the memory. If the system loses power or exits abnormally, the data in the memory table may be lost. The data in the sorting table is stored in a stable medium, such as a disk, so the data will not be lost even if the system loses power or exits abnormally.
[0162] S16. Based on the maximum operation sequence number, the operation record of the data write request is recovered. When the data write request in the memory table is flushed to the sorting table, it means that the data that these data write requests need to store has been stored on the disk and will not be easily lost. In this case, the pre-write logs corresponding to these data write requests need to be recovered, otherwise they will continue to occupy the storage space of the disk until all the space of the log shard is exhausted, making it impossible to write the operation records of subsequent data write requests. For details, please refer to Figure 5 , the operation record of reclaiming the data write request includes:
[0163] S161. Obtain the maximum operation sequence number of the memory table that has been written. At this point, the data write request corresponding to the maximum operation sequence number and the data write request received before have all been written to the sorting table. At this point, the operation records corresponding to these data write requests can be recovered without causing the system to lose data. Among them, the maximum operation sequence number of the memory table that has been written is the operation sequence number of the latest data write request among the data write requests that have been written to the sorting table at this time, and is also the maximum operation sequence number stored in the system global information at this time.
[0164] S162: Based on the starting storage position, sequentially obtain the operation sequence numbers of the operation records in the log shards, and compare the operation sequence numbers with the maximum operation sequence number. The starting storage position is the position in the log shards in this operation instance for storing the first operation record.
[0165] S163, obtain the first operation record whose operation sequence number is greater than the maximum operation sequence number as a reference operation record, and obtain the first position of the reference operation record in the log shard. Starting from the starting storage position, read the operation sequence numbers of the operation records in sequence, and compare the operation sequence number with the maximum operation sequence number. If the operation sequence number is less than or equal to the maximum operation sequence number, continue to read the next one until the operation sequence number is greater than the maximum operation sequence number, obtain the operation record whose operation sequence number is equal to the maximum operation sequence number as a reference operation record, and the data write request corresponding to the reference operation record is the data write request corresponding to the maximum operation sequence number.
[0166] S164, update the starting storage position in the header information of the log shard to the first position, and update the starting sequence number in the header information of the log shard to the operation sequence number of the reference operation record. After the update is completed, the starting storage position start_pos in the header information is the position of the reference operation record, and the starting sequence number in the header information is the operation sequence number of the reference operation record, that is, the starting storage position and starting sequence number of the log shard are updated.
[0167] See also Fig.14 and Fig.15 , taking the maximum operation sequence number of the memory table as 5866 as an example, before recycling, the data contained in log shards 0-3 is as follows Fig.14 As shown in the figure, the shaded part represents the valid operation record, and the unshaded part except the header information is the free space of the log shard. New data can be written into the free space, or the original data can be overwritten by the new data.
[0168] When the memory table is completely flushed to the sorting table, the maximum operation sequence number 5866 of the memory table is obtained, and then the maximum operation sequence number in the global information is updated to 5866. Next, the header information of log shards 0-3 is updated in sequence, taking log shard 0 as an example, specifically including: reading the operation sequence number seq value recorded in the log shard operation sequence number table in sequence, and if the seq value is less than or equal to 5866, continue to read the next item.
[0169] If seq>5866 is read, the operation record currently being read is obtained as the reference operation record, and the position pos of the reference operation record in the log shard is obtained and recorded as the first position. The start_seq in the header information of the log shard is updated to the operation sequence number of the reference operation record, and the start_pos in the header information of the log shard is updated to the first position, for example, it can be recorded as: header.start_seq=item.seq; header.start_pos=item.pos, which means that the operation sequence number seq value of the current item (i.e., the reference operation record) is assigned to the start_seq in the header information; and the position pos value of the current item is assigned to the start_pos in the header information.
[0170] If no item with seq>5866 is found after reading the log shard operation sequence number table, the starting storage position and starting sequence number in the log shard header information are updated to: header.start_seq=cur_seq+1; header.start_pos=write_pos.
[0171] See also Fig.15 , when log shards 0-3 are all recovered, if Fig.15 As shown in the figure, after the recovery is completed, the starting sequence numbers start_seq of the log shards 0-3 are updated to 5868, 5869, 5870 and 5867 respectively. The shaded part in the figure represents the valid operation record. The unshaded part except the header information is the free space of the log shard. New data can be written into the free space, or the new data can be used to overwrite the original data.
[0172] In some other embodiments, the data storage method further includes:
[0173] S17. When the data storage system is restarted, it is detected whether the log segment needs to be replayed. If necessary, the replay mechanism of the log segment is triggered. Figure 6 and Figure 7 , wherein the detecting whether the log segment needs to be replayed includes:
[0174] S1701. Obtain the instance number and the starting sequence number in the log shard header information.
[0175] S1702, detect whether the instance number is the same as the instance number in the global information, if not, no playback is required. If the instance number is different from the instance number in the global information, it means that the operation record stored in the log shard does not belong to the running instance before the system restart, and no playback is required; if the instance number is the same as the instance number in the global information, it means that the operation record stored in the log shard belongs to the running instance before the system restart, and playback may be required. Whether playback is required can be further determined by comparing the starting sequence number and the maximum operation sequence number.
[0176] S1703, check whether the starting sequence number is greater than the maximum operation sequence number in the global information, if not, no replay is required. If the starting sequence number is less than or equal to the maximum operation sequence number in the global information, it means that the data write requests corresponding to the operation records in the log shard have all been flushed to the sorting table, and no replay is required; if the starting sequence number is greater than the maximum operation sequence number in the global information, it means that there are still some data write requests corresponding to some operation records in the log shard that have not been flushed to the sorting table, and at this time, the memory table corresponding to these data write requests no longer exists, so it is necessary to replay these data write requests from the log shard.
[0177] S1704. If the instance number is the same as the instance number in the global information, and the starting sequence number is greater than the maximum operation sequence number in the global information, it is determined that the log segment needs to be replayed, and the replay mechanism of the log segment is triggered. If the system exits abnormally, it is necessary to check whether the log segment needs to be replayed. For example, if the system suddenly loses power during operation, the data in the memory table may not be flushed to the sorting table in time, resulting in data loss in the memory table. In this case, when the system restarts, the replay mechanism of the log segment will be triggered.
[0178] Assume that before the system exits abnormally, the instance number instance_id in the global information is 1631850593 and the maximum operation sequence number max_seq is 959.
[0179] Assume that the instance number and the starting sequence number in the log shard header information are:
[0180] Log shard 0: instance_id: 1631850593; start_seq: 960
[0181] Log shard 1: instance_id: 1631850593; start_seq: 961
[0182] Log shard 2: instance_id: 1631850593; start_seq: 962
[0183] Log shard 3: instance_id: 1631850593; start_seq: 963
[0184] The instance numbers of log shards 0-3 are the same as the data in the global information, and the starting sequence numbers are all greater than the maximum operation sequence number in the global information. This means that log shards 0-3 contain valid operation records, and it is determined that log shards 0-3 need to be replayed.
[0185] See also Figure 8 When the playback mechanism of the log shard is triggered, playing back the data in the log shard includes:
[0186] S171. Acquire the instance number and the maximum operation sequence number based on the global information. Assume that before the system exits abnormally, the instance number instance_id in the global information is 1631850593, and the maximum operation sequence number max_seq is 959.
[0187] S172: Create a new memory table, where the new memory table is used to cache data write requests corresponding to the operation records to be played back.
[0188] S173. Obtain the operation record to be replayed based on the instance number and the maximum operation sequence number. Fig. 9 , obtain the operation records to be played back including:
[0189] S1731. Obtain the maximum operation sequence number. The obtained maximum operation sequence number can be recorded as max_seq.
[0190] S1732. Obtain the starting position and the starting storage position of the log shard, and obtain the first operation record stored in the log shard based on the starting position and the starting storage position. Specifically, calculate the position of the first operation record in the log area as start_offset+start_pos, and obtain the first operation record based on the position of the first operation record in the log area.
[0191] S1733. Based on the first operation record, sequentially detect whether the operation records in the log shards are operation records to be replayed, starting from the first operation record, sequentially check the subsequent operation records until all subsequent valid operation records are checked, wherein sequentially checking the operation records can be based on the log area data blocks, which can improve the inspection efficiency of the system. The specific detection method includes:
[0192] S17331. Check whether the magic value and the instance number of the operation record are correct. If they are correct, execute step S17332. If they are incorrect, end the test.
[0193] S17332. Detect whether the operation sequence number of the operation record is greater than the maximum operation sequence number. If so, execute step S17333; if not, end the detection.
[0194] S17333. Acquire the operation record as the operation record to be replayed, and update the maximum operation sequence number based on the operation sequence number of the operation record to be replayed.
[0195] S1734. Check the valid operation records in the log shards in sequence until the check is complete. Fig.16 After the detection is completed, all operation records to be replayed are obtained. Fig.16 Specifically, the operation records to be replayed include the operation records with instance number 1631850593 and operation sequence number range 960 to 1286. Fig.16 In the example, the instance number is abbreviated as ins_id, which actually means the instance number instance_id.
[0196] S174, storing the operation records to be replayed in the new memory table in sequence. The new memory table is an active memory table. When all data write requests corresponding to the operation records to be replayed are stored in the new memory table, the new memory table is converted into a read-only memory table and flushed to the sorting table.
[0197] S175, writing the new memory table to the sorting table.
[0198] S176. Update the maximum operation sequence number in the global information. When the process of writing the new memory table to the sorting table is completed, it means that the data corresponding to all operation records in the log shard have been stored in the sorting table. At this time, the operation records to be replayed in the log shard can be recycled, and the maximum operation sequence number in the global information is updated to the maximum operation sequence number in the new memory table. The playback process of the log shard is completed, and the system can start normally. When the system starts normally, a new instance number and the maximum operation sequence number in this running instance will be generated in the global information of the system, such as instance_id: 1631861659; max_seq: 0. Log shards 0-3 will also initialize the instance number, starting sequence number and starting storage position in the header information, for example: instance id: 1631861659; start_seq: 0; start_pos: 0, to store the operation records in this running instance.
[0199] The embodiments of the present invention use multiple log shards to write operation records in parallel to the disk partition of the data storage system, thereby reducing the impact of the write performance bottleneck of a single log and improving the overall performance of the data storage system. In addition, directly using disks or disk partitions to store write-ahead logs avoids the additional performance loss caused by using a file system to store write-ahead logs.
[0200] The embodiment of the present invention provides a data storage system 300. The data storage system 300 generates an instance number for marking the system running instance each time it is run. The instance number is stored in the global information of the data storage system. Fig.17 , the system comprising:
[0201] The shard configuration module 31 is used to create at least two log shards based on the log area, wherein the log area is a disk or disk partition for storing pre-write logs, and each log shard corresponds to a different shard number, and the shard number is recorded in the header information of the corresponding log shard. Specifically, it can be used to obtain the capacity of the log area and the number of log shards, calculate the capacity of each log shard according to the capacity of the log area and the number of log shards, and assign a unique shard number to each log shard, store the capacity of the log shard and the shard number in the header information of the log shard, and calculate the position of each log shard based on the number of log shards and the capacity of the log shards.
[0202] The request receiving module 32 is used to receive a data writing request and assign a unique and increasing operation sequence number in this running instance to the data writing request, wherein the data writing request includes an operation type, operation data, and a shard number of a log shard. The operation sequence number is assigned in increasing order based on the order in which the data writing request is received.
[0203] A write-ahead log module 33, the write-ahead log module 33 is used to write the operation record corresponding to the data write request to one of the at least two log shards, wherein the operation record includes the instance number, the data write request and the operation sequence number corresponding to the data write request. Specifically, it can be used to obtain the shard number in the data write request, select the log shard with the shard number based on the shard number; or obtain the key of the data write request, select the corresponding log shard based on the key, and then write the operation record corresponding to the data write request to the selected log shard.
[0204] The data cache module 34 is used to write the data write request to the memory table, and based on the operation sequence number corresponding to the data write request, update the maximum operation sequence number in the memory table, wherein the maximum operation sequence number is stored in the memory table, and is used to record the operation sequence number corresponding to the data write request most recently stored in the memory table. After the operation record of the data write request is written into the log shard, the data write request is written into the memory table, and the writing order of the data write request in the memory table is ensured to be the same as the order in which the system receives the data write request. After the process of writing the current data write request into the memory table is completed, the next data write request can be written into the memory table.
[0205] The data flushing module 35 is used to flush the data write request in the memory table to the sorting table, and store the maximum operation sequence number in the global information of the data storage system after the flushing is completed. When the active memory table is full of data, or when the user calls the flush interface, the active memory table will be converted into a read-only memory table. The data in the read-only memory table cannot be modified. After the data in the read-only memory table is flushed to the sorting table, the read-only memory table can be released. Among them, the data in the memory table are all cached in the memory. If the system loses power or exits abnormally, the data in the memory table may be lost, while the data in the sorting table are all stored in a stable medium, such as a disk, so that the data will not be lost even if the system loses power or exits abnormally.
[0206] The log recovery module 36 is used to recover the operation record of the data write request based on the maximum operation sequence number. Specifically, it can be used to obtain the maximum operation sequence number of the memory table that has been flushed, and based on the starting storage position, sequentially obtain the operation sequence numbers of the operation records in the log shard, and compare the operation sequence number with the maximum operation sequence number, obtain the operation record whose operation sequence number is equal to the maximum operation sequence number as a reference operation record, and obtain the first position of the reference operation record in the log shard, and update the starting storage position in the header information of the log shard to the first position, and update the starting sequence number in the header information of the log shard to the maximum operation sequence number.
[0207] The data storage system provided by the embodiment of the present invention uses multiple log shards to write operation records in parallel to the disk partition of the data storage system, which can reduce the impact of the write performance bottleneck of a single log and improve the overall performance of the data storage system. In addition, directly using disks or disk partitions to store pre-write logs avoids the additional performance loss caused by using a file system to store pre-write logs.
[0208] In some other embodiments, the data storage system 300 also includes a log playback module 37, which is used to detect whether the log segment needs to be replayed when the data storage system is restarted, and if so, trigger the playback mechanism of the log segment; and is also used to play back the data in the log segment when the playback mechanism of the log segment is triggered.
[0209] It should be noted that the above data storage system can execute the data storage method provided in the embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method. For technical details not fully described in the data storage system embodiment, please refer to the data storage method provided in the embodiment of the present invention.
[0210] The present invention also provides an electronic device, see Fig.18 , which shows that it is possible to execute Figures 1 to 9 Hardware structure of electronic device of the data storage method. The electronic device 500 may be a host device or a terminal device.
[0211] The electronic device 500 includes: at least one processor 51; and a memory 52 that is communicatively connected to the at least one processor 51. Fig.18 Taking a processor 51 as an example, the memory 52 stores instructions that can be executed by the at least one processor 51, and the instructions are executed by the at least one processor 51 so that the at least one processor 31 can execute the data storage method described in the above embodiment.
[0212] The processor 51 and the memory 52 may be connected via a bus or other means. Fig.18 In the example of bus connection, the memory 52 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The processor 51 executes various functional applications and data processing by running the non-volatile software programs, instructions and modules stored in the memory 52, that is, realizing the data storage method in the above embodiment.
[0213] The memory 52 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created by the use of the electronic device, etc. In addition, the memory 52 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 52 may optionally include a memory 52 remotely arranged relative to the processor 51. These remote memories may be connected to the electronic device 500 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0214] The one or more modules are stored in the memory 52, and when executed by the one or more processors 51, the data storage method in any of the above embodiments is executed, for example, Figures 1 to 9 The method steps in .
[0215] The above product can execute the data storage method provided in the embodiment of the present invention, and has the functional modules corresponding to the data storage method. For technical details not described in detail in this embodiment, please refer to the data storage method provided in the embodiment of the present invention.
[0216] Through the description of the above implementation methods, ordinary technicians in this field can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, it can also be implemented by hardware. Ordinary technicians in this field can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0217] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them. Under the concept of the present invention, the technical features in the above embodiments or different embodiments may also be combined, the steps may be implemented in any order, and there are many other changes in different aspects of the present invention as described above, which are not provided in detail for the sake of simplicity. Although the present invention has been described in detail with reference to the aforementioned embodiments, a person of ordinary skill in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A data storage method, applied to a data storage system, It is characterized in that The data storage system generates an instance number for marking the system running instance each time it is run, and the instance number is stored in the global information of the data storage system. The method includes: At least two log shards are created based on the log area, wherein the log area is a disk for storing write-ahead logs, each log shard has a different shard number, and the shard number is recorded in the header information of the corresponding log shard; Receive a data write request, and assign a unique operation sequence number in this running instance to the data write request, wherein the data write request includes an operation type, operation data, and a shard number of a log shard; Writing an operation record corresponding to the data write request to one of the at least two log shards, wherein the operation record includes the instance number, the data write request, and an operation sequence number corresponding to the data write request; Writing the data write request to a memory table, and updating a maximum operation sequence number in the memory table based on an operation sequence number corresponding to the data write request, wherein the maximum operation sequence number is stored in the memory table and is used to record an operation sequence number corresponding to the data write request most recently stored in the memory table; Flashing the data write request in the memory table to the sorting table, and storing the maximum operation sequence number in the global information of the data storage system after the flashing is completed; Based on the maximum operation sequence number, the operation record of the data write request is recovered.
2. The method according to claim 1, It is characterized in that Writing the operation record corresponding to the data write request to one of the at least two log shards includes: Obtain the shard number in the data write request; Selecting the log shard having the shard number based on the shard number; Write the operation record corresponding to the data write request to the selected log shard.
3. The method according to claim 1, It is characterized in that Writing the operation record corresponding to the data write request to one of the at least two log shards includes: Obtaining a key for the data writing request; Selecting the corresponding log shard based on the key, wherein the data write requests with the same key select the same log shard; Write the operation record corresponding to the data write request to the selected log shard.
4. The method according to claim 1, It is characterized in that The creating at least two log shards based on the log area includes: Obtain the capacity of the log area and the number of log shards, wherein the minimum unit for storing data in the log area is a log area data block; The capacity of each log shard is calculated according to the capacity of the log area and the number of the log shards, and a unique shard number is assigned to each log shard, and the capacity of the log shard and the shard number are stored in the header information of the log shard, wherein the capacity of the log shard is an integer multiple of the log area data block, and the header information of the log shard also records the instance number of the current running instance, the starting storage position and the starting sequence number, wherein the starting storage position is the position in the log shard in a running instance for storing the first operation record, and the starting sequence number is the operation sequence number of the first operation record in a running instance; Based on the number of the log shards and the capacity of the log shards, the position of each log shard is calculated, and the position of the log shard includes the starting position of the log shard and the ending position of the log shard.
5. The method according to claim 4, It is characterized in that The reclaiming the operation record of the data write request based on the maximum operation sequence number comprises: Obtaining the maximum operation sequence number of the memory table that has been flushed; Based on the starting storage position, sequentially obtain the operation sequence numbers of the operation records in the log shards, and compare the operation sequence numbers with the maximum operation sequence number; Obtain the first operation record whose operation sequence number is greater than the maximum operation sequence number as a reference operation record, and obtain the first position of the reference operation record in the log shard; The starting storage position in the header information of the log shard is updated to be the first position, and the starting sequence number in the header information of the log shard is updated to be the operation sequence number of the reference operation record.
6. The method according to claim 4, It is characterized in that The method further includes: when the data storage system is restarted, detecting whether the log segment needs to be replayed, and if so, triggering a replay mechanism of the log segment, wherein the detecting whether the log segment needs to be replayed includes: Obtain the instance number and the starting sequence number in the log shard header information; Detect whether the instance number is the same as the instance number in the global information, if not, no playback is required; Detect whether the starting sequence number is greater than the maximum operation sequence number in the global information, if not, no playback is required; If the instance number is the same as the instance number in the global information, and the starting sequence number is greater than the maximum operation sequence number in the global information, it is determined that the log segment needs to be replayed, and the replay mechanism of the log segment is triggered.
7. The method according to claim 6, It is characterized in that The method further includes: when a playback mechanism of the log shard is triggered, playing back the data in the log shard, wherein playing back the data in the log shard includes: Acquire the instance number and the maximum operation sequence number based on the global information; Create a new memory table; Acquire the operation record to be replayed based on the instance number and the maximum operation sequence number; The operation records to be replayed are stored in the new memory table in sequence; Flashing the new memory table to the sorting table; The maximum operation sequence number in the global information is updated.
8. The method according to claim 7, It is characterized in that The acquiring the operation record to be replayed based on the instance number and the maximum operation sequence number comprises: Obtaining the maximum operation sequence number; Obtain the starting position and the starting storage position of the log shard, and obtain the first operation record stored in the log shard according to the starting position and the starting storage position; Based on the first operation record, sequentially detecting whether the operation records in the log shards are operation records to be replayed, wherein the detection method includes: Check whether the magic value and the instance number of the operation record are correct; If correct, then detecting whether the operation sequence number of the operation record is greater than the maximum operation sequence number; If so, the operation record is obtained as the operation record to be replayed, and the maximum operation sequence number is updated based on the operation sequence number of the operation record to be replayed.
9. A data storage system, It is characterized in that The data storage system generates an instance number for marking the system running instance each time it is run, and the instance number is stored in the global information of the data storage system. The system includes: A shard configuration module, used to create at least two log shards based on a log area, wherein the log area is a disk for storing write-ahead logs, each log shard has a different shard number, and the shard number is recorded in the header information of the corresponding log shard; A request accepting module, used to receive a data writing request and assign a unique and increasing operation sequence number in this running instance to the data writing request, wherein the data writing request includes an operation type, operation data, and a shard number of a log shard; A write-ahead log module, configured to write an operation record corresponding to the data write request to one of the at least two log shards, wherein the operation record includes the instance number, the data write request, and an operation sequence number corresponding to the data write request; A data cache module, used to write the data write request to a memory table, and based on the operation sequence number corresponding to the data write request, update the maximum operation sequence number in the memory table, wherein the maximum operation sequence number is stored in the memory table and is used to record the operation sequence number corresponding to the data write request most recently stored in the memory table; A data writing module, used for writing the data writing request in the memory table to the sorting table, and storing the maximum operation sequence number in the global information of the data storage system after writing is completed; The log recovery module is used to recover the operation record of the data write request based on the maximum operation sequence number.
10. An electronic device, It is characterized in that The electronic device comprises: at least one processor; a memory communicatively coupled to the at least one processor; The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the data storage method described in any one of claims 1 to 8.
Citation Information
Patent Citations
Log management method and device, equipment and medium
CN110457258A
Data flashing method, device and apparatus of storage system and readable storage medium
CN111104254A
Data backup method and device and data recovery method and device
CN113495807A
Method and device for file system log
US20180349410A1
