WO2013174305A1 - 基于SSD的Key-Value型本地存储方法及系统 - Google Patents

基于SSD的Key-Value型本地存储方法及系统 Download PDF

Info

Publication number
WO2013174305A1
WO2013174305A1 PCT/CN2013/076222 CN2013076222W WO2013174305A1 WO 2013174305 A1 WO2013174305 A1 WO 2013174305A1 CN 2013076222 W CN2013076222 W CN 2013076222W WO 2013174305 A1 WO2013174305 A1 WO 2013174305A1
Authority
WO
WIPO (PCT)
Prior art keywords
page
node
write
read
ssd
Prior art date
Application number
PCT/CN2013/076222
Other languages
English (en)
French (fr)
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 WO2013174305A1 publication Critical patent/WO2013174305A1/zh

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2246Trees, e.g. B+trees

Definitions

  • the invention relates to a local data storage management system, and in particular to a Key-Value (local key) type local storage method and system based on SSD (Solid State Drive). Background technique
  • the organization and management of data is mainly divided into three steps.
  • One is the online access of data. It mainly refers to the acquisition of data and the provision of read services, that is, to the traditional OLTP-type load, and the second is the organization of data.
  • Traditionally it refers to The data in the OLTP type database is converted into a data format suitable for the data warehouse, which is called ETL.
  • the third is data analysis, which refers to long-term, complex data mining and other work to discover the connections and potential value in the data, that is, OLAP-type tasks. In this article, we focus on the online access portion of the data.
  • relational database represented by MySQL.
  • the relational database was the product of the 1970s, and the main structure that originated at the beginning has been inherited ever since. Relational database is a milestone in the history of data storage management. It is characterized by good transaction processing and data security. But for the new load in the era of big data, relational databases have their inherent limitations:
  • the size of big data load changes rapidly.
  • the amount of related data tends to rise rapidly.
  • the business is adjusted, the amount of data may shrink rapidly and transfer to other services.
  • the application scenarios oriented by traditional databases are generally carried out in a relatively static user group.
  • the expansion and contraction involve the sub-database partitioning operation of the database.
  • NoSQL noSQL
  • NoSQL systems can provide significantly higher data throughput than traditional databases.
  • SSD storage media are more obvious than the advantages and disadvantages of the disk.
  • the advantage is that the random read and write performance is greatly improved.
  • the disadvantage is that the cost per unit of storage capacity is much higher than that of the disk. But from another perspective, the cost of a unit's random read and write performance is lower than that of a disk. So in the scenario of requiring high random IOPS (received read and write request responses per second), SSD has application value. From the actual situation, major Internet companies have begun to use SSD in storage architecture to improve the overall performance of the system. .
  • Hash-type data indexing mechanism In the existing similar systems, Flashstore and FAWN systems use the Hash-type data indexing mechanism. There are two main problems in this indexing method. One is that the Hash-type data index needs to be in the memory footprint and the number of hard disk reads. It is difficult to obtain the effect of both. The second is that Hash-style data index is difficult to achieve range lookup operations.
  • the late LSM-tree index structure is applied in systems such as LevelDB.
  • the advantage is that the write mode is large-grained continuous write, which is very beneficial to the performance of SSD, but LSM-tree is a mechanism that tends to write optimization.
  • the read operation has a lower performance due to the higher number of read hard disks introduced.
  • the present invention implements a S-based Key-Value type local storage method and system for high concurrent load.
  • the invention discloses a SSD-based Key-Value type local storage method, which comprises:
  • Step 1 Using a memory snapshot B+ tree index structure for data, performing read and write separation operations in the memory;
  • Step 2 After the indexed data, use the FIFO queue management cache for the B+ tree page; Step 3: Append the SSD to the data page, and implement the logical page number in the log type additionally written data through the hole file mechanism. Mapping management of physical locations.
  • the SSD-based Key-Value type local storage method includes:
  • Step 21 The root node A is a B+ tree root node, such as performing an update operation on the first node D. First, the first node D page is copied, the copied copy page is the first node D, and then the first node D, the page is performed. Required updates;
  • Step 22 After performing this operation, the index of the first node D in the intermediate node B needs to be updated.
  • the intermediate node B needs to be copied first, and then An update operation is performed in the intermediate node B of the copy; in sequence, the copy process also occurs on the root node A;
  • Step 23 When the entire update operation is completed, a new B+ tree with root node A as the root node is formed, and the root node A, compared with A, points to B, the index changes, and the other indexes remain unchanged;
  • the intermediate node B updates the page pointing to the first node D, and the other indexes are unchanged.
  • the SSD-based Key-Value type local storage method the step 2 includes:
  • Step 31 The design of the FIFO page-level write cache uses the structure of the circular queue.
  • the entire ring is divided into a write area and a read area.
  • the write area is a write operation, a page that has not been submitted, and the read area has completed the write operation and submitted.
  • Page which can be read from the cache for reading operations;
  • Step 32 The write pointer points to the end of the write area.
  • the pointer is also the location where the next write operation loads the new page when writing to the write cache.
  • the write pointer position continuously obtains a new page and moves forward along the circular queue.
  • the page that completes the write operation is submitted as the read area, and the read pointer points to the newly submitted page position;
  • Step 33 in this process, the background asynchronous write thread will be at a speed suitable for the application needs
  • the read area is persisted to the SSD in turn, the page area that has been persisted is called the flush area, a flush pointer points to the next page to be persisted, the flush area is part of the read area, and the write pointer is used to obtain the new page area. ;
  • Step 34 In the process that the asynchronous write thread writes the corresponding page into the SSD in the background, the page that has the updated copy in the circular queue belongs to the redundant page, and does not need to be written, and the page is skipped in this method. At the same time, a file hole of the same size is created in the data file of the SSD. The file hole does not occupy the actual space and does not perform the actual write operation, but maintains the correspondence between the logical page number and the displacement of the data page in the file.
  • the step 3 read operation includes: Step 41: Obtain a current B+ tree root node as a starting point of a B+ tree index search; the read operation does not need to lock the page ;
  • Step 42 Perform an internal half-page search for the intermediate node page including the root node, obtain a correct index item, and obtain a logical page number of the next page to be searched, and the search process is terminated after obtaining the leaf node;
  • the use of memory snapshot technology, the read operation does not need to lock the page;
  • Step 43 The operation of obtaining the physical page by the logical page number is completed by calling the memory pool management module; the memory pool management module compares the page number with the smallest page number in the FIFO queue, and determines whether it is in the queue, if the minimum page number is Large, that is, the case of a cache hit, directly returning to the page reference in the memory pool management;
  • Step 44 if there is no hit buffer, then need to allocate additional page space, and then read to the SSD; obtaining the data in the SSD with the logical page number needs to be completed by calling the function of the log data management module; because of the file hole mechanism Function, the log data management module is very simple at this time, only need to multiply the page size by the logical page number, and then read the corresponding page;
  • Step 45 finally complete the final Key-Value pair lookup in the leaf node page, and return the result.
  • the SSD-based Key-Value type local storage method, the step 3 write operation process further includes:
  • Step 51 Determine the correct location of the new data record to be inserted by searching the B+ tree, obtain the current B+ tree root node, and start the B+ tree index search; the read operation does not need to lock the page; for the memory pool management module
  • the FIFO ring queue Read Region changes all in the write thread In the middle, the write thread itself does not need to lock the page cache hit;
  • Step 52 when the operation of finding the correct insertion position is completed, the write thread pushes the root node to the page of the entire path of the insertion position page into a stack structure.
  • the intermediate node in the path is also pointed to the in-page index number of the child node;
  • Step 53 The process of writing the page will pop up the page pointer in the stack in turn.
  • the memory snapshot technology is used to avoid the lock protection.
  • the memory pool management interface needs to be called to request a new page. Then copy the content of the source page to the new page, and then modify the operation; in the parent node page that pops up later, you need to modify the index page number that originally pointed to the child node to the new logical page number;
  • Step 54 In the parent node page, the index page number originally directed to the child node needs to be modified to a new logical page number, and the modification is also completed by using the memory snapshot; if the child node is split, the split point needs to be inserted;
  • Step 55 After the entire write operation is completed, the submitting operation is performed by incorporating all the pages that have been written or updated into the Read Region, and then modifying the new B+ tree root node to the current index B+ tree root node. .
  • the present invention also discloses a SSD-based Key-Value type local storage system, including: a memory snapshot B+ tree index module, which is used for a data snapshot B+ tree index structure for data, and performs read and write separation operations in the memory;
  • a memory pool management module for the indexed data using a FIFO queue management cache for the B+ tree page;
  • the log data management module is configured to additionally write the SSD to the data page, and implement mapping management of the logical page number and the physical location in the log type additionally written data by the hole file mechanism.
  • the memory snapshot B+ tree index module includes:
  • the first node update operation module is used for the root node A to be a B+ tree root node, for example, an update operation is performed on the first node D; first, the first node D page is copied, the copied copy page is the first node D, and then the first node D , the required updates are made on the page;
  • the intermediate node update operation module after performing this operation, needs to update the index of the first node D in the intermediate node B, according to the principle of the memory snapshot, in order to prevent reading and writing competition,
  • the intermediate node B is first copied, and then the update operation is performed in the intermediate node B of the copy; in sequence, the copying process also occurs on the root node A;
  • the update completion module is configured to form a new B+ tree with the root node A as the root node when the entire update operation is completed, and the root node A, compared to A, points to B, the index changes, and other indexes still Unchanged
  • the page points to the module, used for intermediate node B, updated the page pointing to the first node D, and the other indexes have not changed.
  • the memory pool management module includes: a queue structure module, a FIFO page-level write cache design using a circular queue structure, and the entire ring is divided into a write area and a read The area, the write area is the write operation, the page that has not been submitted, the page in the read area that has completed the write operation and submitted, can be obtained from the cache for the read operation;
  • the pointer position forward module is used for the write pointer to point to the end of the write area.
  • the pointer is also the position where the next write operation is loaded when applying for a new page to the write cache.
  • the write pointer position continuously acquires a new page and follows the ring. The queue is moved forward, and the page that completes the write operation is submitted as the read area, and the read pointer points to the newly submitted page position;
  • Persistence module used in this process, the background asynchronous write thread will continue to persist the read area to the SSD at the speed suitable for the application requirements.
  • the page area that has been persisted is called the flush area, and a flush pointer points to the next.
  • the corresponding write module is used in the process of asynchronously writing the thread to write the corresponding page into the SSD in the background.
  • the page that has the updated copy in the circular queue belongs to the redundant page, and does not need to be written, and the system will jump.
  • the same size file hole is created in the data file of the SSD.
  • the file hole does not occupy the actual space and does not perform the actual write operation, but the correspondence between the logical page number and the displacement of the data page in the file is maintained. .
  • the SSD-based Key-Value type local storage system, the log data management module includes:
  • An index entry module configured to obtain a current B+ tree root node, as a starting point of a B+ tree index search; obtain an index item module, configured to perform an internal page for an intermediate node page including a root node
  • the binary search finds the correct index entry and obtains the logical page number of the next page to be searched. This search process is terminated after the leaf node is obtained. Because of the use of the memory snapshot technology, the read operation does not need to lock the page;
  • the operation for obtaining the physical page by the logical page number is completed by calling the memory pool management module; the memory pool management module compares the page number with the smallest page number in the FIFO queue to determine whether it is in the queue, If it is larger than the minimum page number, that is, the cache hit, directly return to the page reference in the memory pool management module;
  • the page space module is allocated, if there is no hit buffer, then additional page space needs to be allocated, and then read into the SSD; obtaining the data in the SSD by using the logical page number needs to be completed by calling the function of the log data management module;
  • the role of the file hole mechanism, the log data management module at this time the task is very simple, only need to multiply the page size by the logical page number, and then read the corresponding page; complete the search module, used in the last leaf node page Complete the final Key-Value pair lookup and return the result.
  • the SSD-based Key-Value type local storage system, the log data management module further includes:
  • the change of the FIFO ring queue Read Region in the management module all occurs in the write thread, so the write thread itself does not need to lock the page cache hit; the page push module is used to complete the operation of finding the correct insertion position.
  • the write thread pushes the root node to the page of the entire path of the insertion location page into a stack structure. In addition to saving the pointer to the corresponding page, the stack structure also stores the in-page index of the intermediate node in the path to the child node. number;
  • the page modification module the process for writing the page will pop up the page pointer in the stack in turn.
  • the memory snapshot technology is used to avoid the lock protection.
  • the interface of the memory pool management module needs to be called first to request a page.
  • the new page then copy the contents of the source page to the new page, and then perform 4 tampering operations; in the parent node page that pops up later, the index page number originally pointed to the child node needs to be modified to a new logical page number;
  • the submitting module is configured to perform the commit after the entire write operation is completed, and the required operation is to merge all the pages that have been written or updated into the Read Region, and then modify the new B+ tree root node to the current index B+ tree. Root node.
  • the B+ tree index structure is used in conjunction with a FIFO (first in, first out) queue page level cache.
  • the B+ tree index is a common indexing mechanism for storing data on disk. It can provide page-by-page aggregation to effectively reduce the number of reads and writes. At the same time, because of the advantages of data locality, the Hash class index has better performance in range retrieval. However, the past disk-based B+ tree index required a large number of small-grained in place updates, which are not suitable for SSD. Because this not only writes low performance, but also accelerates SSD wear.
  • the invention adopts the memory snapshot technology to realize the read-write separation of data in the memory and improve the read and write concurrency of the system. The nature of the memory snapshot makes it possible to use the FIFO buffering strategy to effectively reflect the temporal locality of the data, eliminating the need for additional cache replacement algorithms, and making the hit judgments more straightforward and faster.
  • the swapped out page using the FIFO type cache is directly written into the SSD, does not overwrite the original data, uses an additional write mode, and uses the user state cache of the standard output library to aggregate the write granularity, thereby achieving the purpose of large-grained write, and Due to the natural characteristics of additional writes, it is suitable for data consistency and reliability.
  • the present invention uses a technique of uninterrupted snapshots to ensure high reliability of data and provides an efficient failure recovery mechanism.
  • the additional write needs to remove redundant data during writing, so that the page logical number does not correspond to the actual location. If another layer of mapping management is added, the risk of metadata burden and inconsistency is increased, and the file system itself is utilized in the present invention.
  • the hollow file mechanism has a relationship between the page logical number and the actual location, which greatly reduces the difficulty of data placement management.
  • the system utilizes memory snapshots.
  • the data index structure of the B+ tree provides high read and write concurrency.
  • the non-stop snapshot mechanism provides a data placement mechanism that is suitable for SSD features and provides high data reliability.
  • DRAWINGS 1 is an overall storage organization structure of the system of the present invention.
  • FIG. 2 is a structural diagram of a page-level write cache of the present invention
  • FIG. 3 is an illustration of a memory snapshot B+ tree of the present invention.
  • Figure 5 is a flow chart of the read operation of the present invention.
  • FIG. 6 is a flow chart of the write operation of the present invention. detailed description
  • Tree Index Memory Snapshot B+ Tree Indexing Module: Uses the memory snapshot B+ tree technology to implement the data indexing mechanism.
  • Memory Pool Management Module Performs space allocation and cache management for B+ tree pages.
  • Log Manager Log data management module: Performs specific read and write operations on the data persistence function, and implements mapping management of logical page numbers and physical locations through a hole file mechanism.
  • the B+ tree is a commonly used data index structure in databases and file systems.
  • the advantage is that the stored data is stable and orderly, and the insertion and modification have a relatively stable logarithmic time complexity.
  • the present invention uses a memory snapshot mechanism to improve the traditional B+ tree data indexing mechanism to meet new requirements.
  • the structure of the B+ tree is in units of pages, and each page is a node in the tree structure.
  • the intermediate node starts to extend downward from the root node of the B+ tree.
  • the page index of the child node is recorded in the page of each node.
  • the root node is at the end of the B+ tree, and the root node corresponds to the actual page. Key-value data.
  • the organization of the B+ tree node page includes page metadata information maintained by the header, and a data list held by the rest of the page, wherein the data list of the leaf node is a Key-Value pair stored in the system, and the data list of the intermediate node stores Key- Index Pair, the Index item points to the child node page pointed to by the record, and the Key item holds the smallest Key in the child page pointed to by the record as the separated value of the subtree.
  • the position of any Key in the B+ tree can be found by the root node along the separated value index to the leaf node.
  • Figure 3 shows how the memory snapshot technology works.
  • the figure shows a part of the B+ tree, and the A node is
  • B+ tree root node now need to do an update operation on the D node. Then we first copy the D-node page, copy the copied page to D', and then perform the required updates in the D' page. After this operation, you need to update the index of D in B. According to the principle of memory snapshot, in order to prevent reading and writing competition, you need to copy B first, then update in copy B. . And so on, this copy also happens on root node A.
  • the page is the root node
  • a new B+ tree structure is formed.
  • the update operation is completed, the operation must be submitted to reach a new consistent state. Only the B+ tree index root node of the storage system index needs to be changed to A. , the node can be. Subsequent operations will enter the B+ tree index from A, as the starting point, and then start to find, of course, can successfully reflect the update effect on the D page. And after submitting A, become new
  • the concurrent read operation thread Before the B+ tree root node, the concurrent read operation thread will enter the B+ tree index from the A node page, and the search operations performed by them will not be affected by the update operation performed in the copy page, and no read/write competition will occur. .
  • this chapter describes the design and implementation of memory snapshot technology in improving the concurrency of B+ tree index structure.
  • the thread that processes the read request does not need to lock the data structure in the index.
  • this technology can significantly improve the overall concurrency of the system in the dominant load.
  • the cache management strategy proposed by the present invention is directed to a memory snapshot B+ tree page, which itself has load specificity.
  • the root node page enters the index structure to perform the search and locate work.
  • the most frequently accessed B+ tree is the node page at a higher level in the tree structure.
  • each update write operation causes a new page to be re-allocated for the page on the corresponding B+ tree path for copy operation.
  • pages that are often on the B+ tree lookup path, that is, higher-level pages often appear in newly allocated pages because they are copied. That is to say, in the B+ tree index structure of the memory snapshot, the order in which the pages are allocated itself shows a strong localization feature of the access time.
  • the FIFO (First-In First-Out) algorithm manages the replacement of cached pages by a first-in, first-out queue. Each time a new page is allocated, it is placed in the FIFO queue. When the queue is full, the principle of replacement is to select the tail page to replace. This is to realize that the page in the resident cache is a newly allocated page. According to the discussion in the previous paragraph, the allocation order reflects the temporal locality of the memory snapshot B+ tree index page.
  • the design of the FIFO page-level write cache uses the structure of a circular queue.
  • the entire ring is divided into a write area and a read area.
  • the write area is a write operation, a page that has not yet been committed, and a read area is a page that has been written and submitted. Read operations are available from the cache.
  • the write pointer points to the end of the write area. This pointer is also the location where the next write operation is loaded when the new page is requested from the write cache.
  • the write pointer position continuously gets a new page and moves forward along the circular queue, and the write operation is completed.
  • the page is submitted as a read area, and a read pointer points to the newly submitted page location.
  • a background asynchronous write thread will persist the read area to the SSD at the speed appropriate for the application.
  • the page area that has been persisted is called the flush area, and a flush pointer points to the next one to be persisted.
  • the page, the flush area is part of the read area, and is also the area where the write pointer can get the new page.
  • the advantage of the additional write mode is that it does not cause in-place update operations, and it is easy to write large-size aggregates. This allows for more efficient use of write bandwidth while reducing the pressure on small-grain random write types for garbage collection and data fragmentation. Therefore, the additional write mode is a write mode optimization suitable for SSD characteristics.
  • the Log-Structured log-type append method is used to write a memory snapshot B+ tree.
  • the case can ensure that the parent page in the B+ tree is always written after the child page.
  • the index of the parent page to the child page is represented by the logical page number.
  • the logical page number is the sequential number of the page allocation. If all the allocated pages are sequentially written into the SSD, the physical displacement of the page on the SSD and the logical page number establish a single order.
  • Correspondence relationship that is, the physical displacement can be directly calculated by the logical page of the index sub-node page, and the process of redundant page filtering actually skips the partially allocated page without actually writing it, then the above mentioned
  • the correspondence between the logical page number of the allocation page and the physical displacement of the written SSD does not exist. Then we have to do some extra management of this correspondence so that we can find the physical page location through the logical page number.
  • each submitted root node represents a consistent data view. As long as the current B+ tree root node is Flushed into the SSD and the root node is recorded, it is equivalent to establishing a A snapshot of the data.
  • the Flush thread needs to skip the page that has been copied. This kind of skipping makes the logical page number not correspond to the actual page physical position. Therefore, the system uses the file system's hole file mechanism to write holes when skipping the page. Keep the two Corresponding logical correspondence, so that it is not necessary to introduce additional page mapping management layer.
  • the page index number is actually the sequence number of the SSD written in sequence. The index number can be directly used to determine whether the page is in the write cache. If there is no hit (the page frame has been requested to be reclaimed), the page can be found in the SSD according to the index number. The location in the middle, then read.
  • Figure 4 shows a view of the write operation occurring in Figure 3 at the actual physical write level. Because the D page is written, the copy generates 3 new pages D, ⁇ ', ⁇ ', which appear in the order of allocation in the FIFO page buffer queue on the right (actually implemented in a circular queue, here is done , but does not affect the principle description).
  • the background Flush thread first skips the D page, forms a page-sized hole, and then finds that the C page is valid data, then writes it to the hole, and then needs to traverse the A and B pages to form another
  • the hole the size of the two pages, the subsequent ⁇ ,, ⁇ ,, C, the page is normally written.
  • the logical page numbers are allocated in sequential increments. After using the file hole mechanism, we can find that all pages can be accessed directly by the logical page number multiplied by the displacement generated by the page size. The actual amount of files written is reduced to 4 pages, which plays a role in filtering redundant writes.
  • the storage system When the read record operation refers to a given Key, the storage system returns the value corresponding to the Key.
  • the operation of obtaining the physical page by the logical page number is completed by calling the Memory Pool module.
  • the Memory Pool module compares the page number with the smallest page number in the current FIFO queue to determine if it is in the queue. If it is larger than the minimum page number, that is, the cache hit, you can directly return to the page reference in the Memory Pool.
  • the write record operation refers to writing a Key value and a Value value to the storage system in a data pair for later reading.
  • the storage system adopts the threading model of single-write and multi-read. When the write thread enters the index structure, it always faces the latest B+ tree root node, which is different from the situation faced by the read thread.
  • the first step and the read operation required for the write operation are the same. It is to determine the correct position to insert the new data record by searching the B+ tree.
  • the operation is basically the same as the read operation, and will not be described again.
  • One difference is that because the changes to the Read Region of the FIFO ring queue in the Memory Pool module all occur in the write thread, the write thread itself does not need to lock the page cache hit.
  • the write thread pushes the page of the root node to the entire path of the insertion position page into a stack structure, and saves the path in addition to the pointer pointing to the corresponding page in the stack structure.
  • the intermediate node points to the in-page index number of the child node.
  • the process of writing to the page will pop up the page pointer in the stack, here use the memory snapshot technology to avoid lock protection, modify a page, you need to call the Memory Pool interface to request a new page, then Copy the contents of the source page to the new page and modify it.
  • the commit is performed by incorporating all the pages that have been written or updated into the Read Region, and then modifying the new B+ tree root node to the current index B+ tree root node.
  • the present invention also discloses a SSD-based Key-Value type local storage system, including: a memory snapshot B+ tree index module, which is used for a data snapshot B+ tree index structure for data, and performs read and write separation operations in the memory;
  • a memory pool management module for the indexed data using a FIFO queue management cache for the B+ tree page;
  • the log data management module is configured to additionally write the SSD to the data page, and implement mapping management of the logical page number and the physical location in the log type additionally written data by the hole file mechanism.
  • the memory snapshot B+ tree index module includes:
  • the first node update operation module is used for the root node A to be a B+ tree root node, for example, an update operation is performed on the first node D; first, the first node D page is copied, the copied copy page is the first node D, and then the first node D , the required updates are made on the page;
  • the intermediate node update operation module is used to update the index of the first node D in the intermediate node B after the operation is completed. According to the principle of the memory snapshot, in order to prevent literacy competition, the intermediate node B needs to be used first. Copying, and then performing an update operation in the intermediate node B of the copy; in sequence, the copying process also occurs on the root node A;
  • the update completion module is configured to form a new B+ tree with the root node A as the root node when the entire update operation is completed, and the root node A, compared to A, points to B, the index changes, and other indexes still Unchanged
  • the page points to the module, used for intermediate node B, updated the page pointing to the first node D, and the other indexes have not changed.
  • the SSD-based Key-Value type local storage system includes: a queue structure module, a FIFO page-level write cache design using a circular queue structure, The entire ring is divided into a write area and a read area.
  • the write area is a write operation, a page that has not been committed, and a page in the read area that has completed the write operation and is submitted, and can be obtained from the cache for the read operation;
  • the pointer position forward module is used for the write pointer to point to the end of the write area.
  • the pointer is also the position where the next write operation is loaded when applying for a new page to the write cache.
  • the write pointer position continuously acquires a new page and follows the ring. The queue is moved forward, and the page that completes the write operation is submitted as the read area, and the read pointer points to the newly submitted page position;
  • Persistence module used in this process, the background asynchronous write thread will continue to persist the read area to the SSD at the speed suitable for the application requirements.
  • the page area that has been persisted is called the flush area, and a flush pointer points to the next.
  • the corresponding write module is used in the process of asynchronously writing the thread to write the corresponding page into the SSD in the background.
  • the page that has the updated copy in the circular queue belongs to the redundant page, and does not need to be written, and the system will jump.
  • the same size file hole is created in the data file of the SSD.
  • the file hole does not occupy the actual space and does not perform the actual write operation, but the correspondence between the logical page number and the displacement of the data page in the file is maintained. .
  • the SSD-based Key-Value type local storage system, the log data management module includes:
  • An index entry module is configured to obtain a current B+ tree root node as a starting point of a B+ tree index search; obtain an index item module, configured to perform a half-search inside the page for an intermediate node page including the root node, and obtain a correct index Item, obtain the logical page number of the next page to be searched. This search process is terminated after obtaining the leaf node; because of the use of the memory snapshot technology, the read operation does not need to lock the page;
  • the operation for obtaining the physical page by the logical page number is completed by calling the memory pool management module; the memory pool management module compares the page number with the smallest page number in the FIFO queue to determine whether it is in the queue, If it is larger than the minimum page number, that is, the cache hit, directly return to the page reference in the memory pool management module;
  • Allocate the page space module if there is no hit buffer, you need to allocate extra page space, and then read to the SSD; use the logical page number to get the data in the SSD needs to call the log data tube The function of the module is completed; because of the role of the file hole mechanism, the task of the log data management module is very simple at this time, only need to multiply the page size by the logical page number, and then read the corresponding page; It is used to finally complete the final Key-Value pair lookup in the leaf node page and return the result.
  • the SSD-based Key-Value type local storage system, the log data management module further includes:
  • the change of the FIFO ring queue Read Region in the management module all occurs in the write thread, so the write thread itself does not need to lock the page cache hit; the page push module is used to complete the operation of finding the correct insertion position.
  • the write thread pushes the root node to the page of the entire path of the insertion location page into a stack structure. In addition to saving the pointer to the corresponding page, the stack structure also stores the in-page index of the intermediate node in the path to the child node. number;
  • the page modification module the process for writing the page will pop up the page pointer in the stack in turn.
  • the memory snapshot technology is used to avoid the lock protection.
  • the interface of the memory pool management module needs to be called first to request a page.
  • the new page then copy the contents of the source page to the new page, and then perform 4 tampering operations; in the parent node page that pops up later, the index page number originally pointed to the child node needs to be modified to a new logical page number;
  • the submitting module is configured to perform the commit after the entire write operation is completed, and the required operation is to merge all the pages that have been written or updated into the Read Region, and then modify the new B+ tree root node to the current index B+ tree. Root node.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明公开一种基于SSD的Key-Value型本地存储方法和系统,所述方法包括:步骤1,对于数据采用内存快照B+树索引结构,进行内存的读写分离操作;步骤2,经过索引后的数据,针对B+树使用FIFO队列管理缓存;步骤3,对所述数据进行读写操作,通过空洞文件机制在日志型追加写入的数据中实现逻辑页号和物理位置的映射管理。

Description

基于 SSD的 Key-Value型^ 储方法及系统
本申请要求于 2012 年 05 月 24 日提交中国专利局、 申请号为 201210165053.X、发明名称为 "基于 SSD的 Key- Value型本地存储方法及系统" 的中国专利申请的优先权, 其全部内容通过引用结合在本申请中。 技术领域
该发明涉及本地数据存储管理系统, 尤其涉及基于 SSD (固态硬盘) 的 Key-Value (键值)型本地存储方法及系统。 背景技术
数据的组织管理主要分为三步,一是数据的在线存取, 主要指的是获得数 据和提供读取服务, 即面向传统的 OLTP型负载, 二是数据的组织, 传统上指 的是将 OLTP型数据库中的数据转为适合数据仓库的数据格式, 即称为 ETL的 过程。 三是数据分析, 指的是进行长时间, 复杂的数据挖掘等工作来发现数据 中的联系和潜在价值, 也就是 OLAP型任务。 本文中, 我们关注的是数据的在 线存取部分。
传统的方案中, 满足数据在线存取任务的是以 MySQL为代表的关系型数 据库。 关系型数据库是上世纪 70年代的产物, 产生伊始的主体架构沿袭至今。 关系型数据库是数据存储管理发展史上的里程碑,其特点是擅长严格事务处理, 提供数据安全性保障等。但对于大数据时代的新型负载, 关系型数据库体现出 了其固有的局限性:
其一, 大数据负载的规模变化快, 当新业务上线时, 相关的数据量往往急 速上升, 而当业务调整时, 数据量又可能会快速收缩, 转移到别的业务上去。 而在传统数据库面向的应用场景一般都是在比较静态的用户群体中进行,扩展 和收缩会牽涉到数据库的分库分表操作。这些复杂的行为一是会耗费大量人力 物力,二是可能导致相关业务的暂时下线, 这是目前的互联网服务商很难接受 的。
其二, 大数据负载的形式变化快。 传统的数据库在线事务处理中, 一般面 向的文书,报表等,都具有比较固定的格式内容,而正如上文已经提到的那样, 现今面临的负载中,越来越多的却是没有固定范式,或者经常根据业务需要进 行调整的的非结构化数据或半结构化数据。这种灵活性是传统的关系型数据库 所不具备的。
其三, 事务性支持的需求与以往有变化。传统关系型数据库都提供了严格 的 ACID事务支持,但目前来说这种事务支持从两个方面引起人们的重新考量。 第一是因为现在以互联网应用为典型的新型业务需求中, 相对来说对 ACID的 特性并没有严格遵循的需求, 比如对于博客文章, 相关评论, 相册图片, 甚至 网上店铺的库存, 暂时的不一致状态对于用户来说都是可以接受的。 第二, 严 格的 ACID特性限制使得数据库整体的性能和扩展性难以提高, 这主要是复杂 的锁机制, 日志机制等造成的。
正是由于关系型数据库存在的这些问题 ,使得被称为 NoSQL类型的新一代 存储系统渐渐崛起,并被广为使用。 NoSQL这个名称意味着它和关系型数据库 有截然不同的地方, 一般不再支持 SQL语句的复杂功能, 同时另一个重要区别 的是大多数的 NoSQL系统放弃了 ACID的完整支持, 它们的特点可以大致归纳 如下:
因为放弃一些复杂的但是不实用的特性, NoSQL系统得以规避了很大一部 分复杂的设计实现。
NoSQL系统可以提供明显高于传统数据库的数据吞吐能力。
具有良好的水平扩展能力, 并适合运行在一般的廉价 PC服务器硬件上。 Key-Value型存储系统固然具有这些优势, 但数据负载的增长一直保持着 迅猛的态势, 同时也对存储系统层面造成越来越大的压力。 我们可以看到, 计 算机硬件特别是 CPU和内存容量一直保持着高速发展的态势,而作为持久化存 储设备的硬盘的读写能力却一直都没有突破性的进展,这是由于磁盘的结构涉 及到机械运动的本质决定的,随机读写中机械寻道动作造成的响应速度限制恐 怕是传统磁盘结构中无法解决的问题。 这样一来, 随着计算速度快速提高, 磁 盘读写能力的瓶颈问题越来越突出。
有部分的 Key-Value型系统使用全内存的架构, 避免磁盘读写瓶颈来获得 极高的性能。 但在实际应用中, 这种系统只被用来作为数据库的前端緩存, 难 以成为数据的最终落脚之处。内存型数据库的局限之处在于放置在内存中的数 据容易在系统崩溃等意外中丟失, 安全性得不到保障, 另外内存的价格和能耗 依然远高于磁盘, 出于数据访问的二八原则,将其全部放置于内存不符合经济 方面的考量,将冷数据放置在磁盘等二级存储可以做到不大幅降低性能的同时 降低系统的整体成本。
SSD的出现有利于这个问题的解决, SSD存储介质相比较磁盘的优势和劣 势都很明显,优势是随机读写性能大大提高, 劣势是单位存储容量的成本大大 高于磁盘。但从另一个角度来说,单位随机读写性能的成本 SSD却比磁盘更低。 所以在要求高随机 IOPS(每秒读写请求响应数)的场景中, SSD有应用的价值, 从实际情况来看,各大互联网公司已经开始在存储架构中大量使用 SSD来提高 系统的整体性能。 但从 SSD的特点来说, 小粒度随机写的性能较差, 而且从实 测性能来看, FTL (闪存翻译层)的技术并无法完全解决这个问题。 小粒度随 机写造成性能下降的原因主要是: 所以为了最大程度地发挥出 SSD的性能优势, 存储系统的读写模式需要针对其进行优化。
现有的同类系统中, Flashstore和 FAWN等系统, 利用的是 Hash式数据索引 的机制,这种索引方式主要存在两个问题,一是 Hash式数据索引需要在内存占 用量和硬盘读取次数之间做权衡,难以获得两者兼得的效果。二是 Hash式数据 索引难以实现范围查找的操作。
对于以 Berkeley DB为代表的许多利用传统 B+树索引机制的系统来说, 在
SSD上使用主要面临的问题其数据插入会造成大量的原地更新写入操作,这是 不利于 SSD性能的 10模式, 另一方面, 对于并发支持来说, B+树索引需要引 入复杂的锁机制, 不利于系统的整体性能。
而较晚出现的 LSM-tree索引结构被应用在 LevelDB等系统中, 其优势在于 写入模式为大粒度连续写, 非常利于 SSD的性能发挥, 但 LSM-tree作为一种倾 向于写优化的机制, 读操作因为引入的读硬盘次数较多, 使得其性能较低。
综上所述, 现有的 Key-Value系统不能满足当前的应用需求, 主要体现在 以下两点:
第一, 以锁机制为基础的并发控制技术难以满足高并发读写负载的要求; 第二, 现有系统的写入模式不适应 SSD的特性。 发明内容
为了应对非结构化数据的管理这一突出需求的问题,本发明实现一个面向 高并发负载, 基于 SSD的 Key- Value型本地存储方法及系统。
本发明公开一种基于 SSD的 Key- Value型本地存储方法, 包括:
步骤 1 , 对于数据采用内存快照 B+树索引结构, 进行内存中的读写分离操 作;
步骤 2, 经过索引后的数据, 针对 B+树页面使用 FIFO队列管理緩存; 步骤 3 , 对所述数据页面追加写入 SSD, 通过空洞文件机制在日志型追加 写入的数据中实现逻辑页号和物理位置的映射管理。
所述的基于 SSD的 Key- Value型本地存储方法, 所述步骤 1包括:
步骤 21 , 根节点 A为 B+树根节点, 如对首节点 D做一次更新操作; 首先将 首节点 D页面进行拷贝, 拷贝的副本页面为首节点 D,, 然后在首节点 D, 页面 中进行所需要的更新;
步骤 22, 进行完这个操作以后, 需要对中间节点 B中对首节点 D, 的索引 也做更新, 根据内存快照的原则, 为了防止读写竟争, 需要先对中间节点 B进 行拷贝, 然后在副本中间节点 B, 中进行更新操作; 依次操作, 所述拷贝过程 也在根节点 A上发生;
步骤 23 , 当整个更新操作完成时, 形成了一棵以根节点 A, 为根节点的新 B+树, 根节点 A, 相比较 A, 指向 B, 的索引有变化, 而其他索引仍然不变; 步骤 24, 中间节点 B, 更新了指向首节点 D, 的页面, 其他索引没有变化。 所述的基于 SSD的 Key- Value型本地存储方法, 所述步骤 2包括:
步骤 31 , FIFO页级写緩存的设计使用环形队列的结构,整个环划分为 write 区域和 read区域, write区域中为正在进行写操作, 尚未提交的页面, read区域 中为已经完成写操作并提交的页面, 可以供读操作从緩存中获得;
步骤 32, write指针指向 write区域的末尾,该指针也是下一个写操作向写緩 存申请新页面时装载的位置,在系统运行时, write指针位置不断获得新页面并 沿着环形队列前移, 同时完成写操作的页面提交为 read区域, 并由 read指针指 向新近提交的页面位置;
步骤 33 , 在这个过程中, 后台异步写入线程将以适合应用需求的速度将 read区域依次持久化到 SSD中, 已经完成持久化的页面区域称为 flush区域, 一 个 flush指针指向下一个要做持久化的页面, flush区域为 read区域的一部分, 供 write指针获得新页面的区域;
步骤 34, 在后台异步写入线程将相应页面写入 SSD中的过程中, 已经在环 形队列中存在更新拷贝的页面属于冗余页面, 不需要进行写入,本方法中将跳 过该种页面, 同时在 SSD的数据文件中制造同样大小的文件空洞, 该文件空洞 不占用实际空间也不进行实际写入操作,但保持了逻辑页号和数据页面在文件 中位移的对应关系。
所述的基于 SSD的 Key- Value型本地存储方法, 所述步骤 3读出操作包括: 步骤 41 , 获得当前的 B+树根节点, 作为 B+树索引查找的起点; 读操作无 需对页面进行加锁;
步骤 42, 对于包括根节点在内的中间节点页面进行页面内部的折半查找, 取得正确的索引项, 获得下一个需要进行查找的页面逻辑页号, 这一查找过程 直到获得叶子节点后终结; 因为内存快照技术的使用,读操作无需对页面进行 加锁;
步骤 43 ,通过逻辑页号获得物理页面的操作通过调用内存池管理模块完成; 内存池管理模块将该页号与 FIFO队列中最小的页号相比较, 判断是否在队列 中, 如果比最小页号大, 也就是緩存命中的情况, 直接返回内存池管理中的页 面引用;
步骤 44, 如果没有命中緩冲, 则需要分配额外页面空间, 然后到 SSD中读 取; 用逻辑页号获得 SSD中的数据需要通过调用日志型数据管理模块的功能来 完成; 因为文件空洞机制的作用, 日志型数据管理模块此时的任务非常筒单, 只需要用逻辑页号乘以页面大小, 然后读取相应页面即可;
步骤 45 ,最后在叶子节点页面中完成最终的 Key- Value对查找,返回结果。 所述的基于 SSD的 Key-Value型本地存储方法, 所述步骤 3写入操作流程还 包括:
步骤 51 , 通过 B+树的查找来确定要插入新数据记录的正确位置, 获得当 前的 B+树根节点, 作为 B+树索引查找的起点; 读操作无需对页面进行加锁; 对于内存池管理模块中的 FIFO环形队列 Read Region的改变全部发生在写线程 中, 所以写线程本身对于页面緩存命中的判断就不需要进行加锁; 步骤 52, 完成查找正确插入位置的操作时, 写线程将根节点到插入位置页 面整条路径的页面压入一个栈结构中,该栈结构中除了保存指向对应页面的指 针外, 还保存了路径中的中间节点指向子节点的页内索引号;
步骤 53 , 写入页面的过程将会依次弹出栈中页指针, 这里使用内存快照的 技术来避免加锁保护,对一个页面的修改, 需要先调用内存池管理的接口来请 求一个新的页面, 然后将源页面的内容拷贝到新页面中, 再进行修改操作; 在 随后弹出的父节点页面中,需要将原先指向子节点的索引页号修改为新的逻辑 页号;
步骤 54, 父节点页面中, 需要将原先指向子节点的索引页号修改为新的逻 辑页号, 这个修改也同样是利用内存快照完成; 如果子节点发生了分裂, 则还 需要插入分裂点;
步骤 55 , 当整个写操作完成后, 进行提交, 需要进行的操作是将已经完成 写入或者更新的所有页面并入 Read Region中, 然后修改新的 B+树根节点为当 前的索引 B+树根节点。
本发明还公开一种基于 SSD的 Key- Value型本地存储系统, 包括: 内存快照 B+树索引模块, 用于对于数据采用内存快照 B+树索引结构, 进 行内存中的读写分离操作;
内存池管理模块, 用于经过索引后的数据, 针对 B+树页面使用 FIFO队列 管理緩存;
日志型数据管理模块, 用于对所述数据页面追加写入 SSD, 通过空洞文件 机制在日志型追加写入的数据中实现逻辑页号和物理位置的映射管理。
所述的基于 SSD的 Key- Value型本地存储系统, 所述内存快照 B+树索引模 块包括:
首节点更新操作模块, 用于根节点 A为 B+树根节点, 如对首节点 D做一次 更新操作; 首先将首节点 D页面进行拷贝, 拷贝的副本页面为首节点 D,, 然后 在首节点 D, 页面中进行所需要的更新;
中间节点更新操作模块, 用于进行完这个操作以后, 需要对中间节点 B中 对首节点 D, 的索引也做更新, 根据内存快照的原则, 为了防止读写竟争, 需 要先对中间节点 B进行拷贝, 然后在副本中间节点 B, 中进行更新操作; 依次 操作, 所述拷贝过程也在根节点 A上发生;
更新完成模块, 用于当整个更新操作完成时, 形成了一棵以根节点 A, 为 根节点的新 B+树, 根节点 A, 相比较 A, 指向 B, 的索引有变化, 而其他索引 仍然不变;
页面指向模块, 用于中间节点 B, 更新了指向首节点 D, 的页面, 其他索 引没有变化。
所述的基于 SSD的 Key- Value型本地存储系统, 所述内存池管理模块包括: 形成队列结构模块, 用于 FIFO页级写緩存的设计使用环形队列的结构, 整个环划分为 write区域和 read区域, write区域中为正在进行写操作, 尚未提交 的页面, read区域中为已经完成写操作并提交的页面, 可以供读操作从緩存中 获得;
指针位置前移模块,用于 write指针指向 write区域的末尾,该指针也是下一 个写操作向写緩存申请新页面时装载的位置,在系统运行时, write指针位置不 断获得新页面并沿着环形队列前移, 同时完成写操作的页面提交为 read区域, 并由 read指针指向新近提交的页面位置;
持久化模块, 用于在这个过程中,后台异步写入线程将以适合应用需求的 速度将 read区域依次持久化到 SSD中, 已经完成持久化的页面区域称为 flush区 域, 一个 flush指针指向下一个要做持久化的页面, flush区域为 read区域的一部 分, 供 write指针获得新页面的区域;
对应写入模块,用于在后台异步写入线程将相应页面写入 SSD中的过程中, 已经在环形队列中存在更新拷贝的页面属于冗余页面, 不需要进行写入, 本系 统中将跳过该种页面, 同时在 SSD的数据文件中制造同样大小的文件空洞, 该 文件空洞不占用实际空间也不进行实际写入操作,但保持了逻辑页号和数据页 面在文件中位移的对应关系。
所述的基于 SSD的 Key- Value型本地存储系统,所述日志型数据管理模块包 括:
索引入口模块,用于获得当前的 B+树根节点,作为 B+树索引查找的起点; 获得索引项模块,用于对于包括根节点在内的中间节点页面进行页面内部 的折半查找, 取得正确的索引项, 获得下一个需要进行查找的页面逻辑页号, 这一查找过程直到获得叶子节点后终结; 因为内存快照技术的使用,读操作无 需对页面进行加锁;
调用内存池管理模块,用于通过逻辑页号获得物理页面的操作通过调用内 存池管理模块完成; 内存池管理模块将该页号与 FIFO队列中最小的页号相比 较, 判断是否在队列中, 如果比最小页号大, 也就是緩存命中的情况, 直接返 回内存池管理模块中的页面引用;
分配页面空间模块, 用于如果没有命中緩冲, 则需要分配额外页面空间, 然后到 SSD中读取; 用逻辑页号获得 SSD中的数据需要通过调用日志型数据管 理模块的功能来完成; 因为文件空洞机制的作用, 日志型数据管理模块此时的 任务非常筒单, 只需要用逻辑页号乘以页面大小, 然后读取相应页面即可; 完成查找模块, 用于最后在叶子节点页面中完成最终的 Key- Value对查找, 返回结果。
所述的基于 SSD的 Key- Value型本地存储系统,所述日志型数据管理模块还 包括:
插入位置模块, 用于通过 B+树的查找来确定要插入新数据记录的正确位 置, 获得当前的 B+树根节点, 作为 B+树索引查找的起点; 读操作无需对页面 进行加锁; 对于内存池管理模块中的 FIFO环形队列 Read Region的改变全部发 生在写线程中, 所以写线程本身对于页面緩存命中的判断就不需要进行加锁; 页面压入模块, 用于完成查找正确插入位置的操作时, 写线程将根节点到 插入位置页面整条路径的页面压入一个栈结构中 ,该栈结构中除了保存指向对 应页面的指针外, 还保存了路径中的中间节点指向子节点的页内索引号;
页面修改模块, 用于写入页面的过程将会依次弹出栈中页指针, 这里使用 内存快照的技术来避免加锁保护,对一个页面的修改, 需要先调用内存池管理 模块的接口来请求一个新的页面, 然后将源页面的内容拷贝到新页面中,再进 行 4爹改操作; 在随后弹出的父节点页面中, 需要将原先指向子节点的索引页号 修改为新的逻辑页号;
修改逻辑页号模块, 用于父节点页面中, 需要将原先指向子节点的索引页 号修改为新的逻辑页号, 这个修改也同样是利用内存快照完成; 如果子节点发 生了分裂, 则还需要插入分裂点;
提交模块, 用于当整个写操作完成后, 进行提交, 需要进行的操作是将已 经完成写入或者更新的所有页面并入 Read Region中, 然后修改新的 B+树根节 点为当前的索引 B+树根节点。
本发明的有益效果为:
1 : 内存快照 B+树索引结构与基于 FIFO (先入先出) 队列页级緩存结合 使用。
B+树索引是磁盘上存储数据常用索引机制, 可以提供按页聚合有效减少 读写次数, 同时因为数据局部性方面的优势,相比较 Hash类索引在范围检索上 有更好的性能。 但是, 过去的基于磁盘的 B+树索引, 需要大量小粒度的就地 更新操作 ( in place updates ), 这种读写模式是不合适 SSD的。 因为这样不仅写 入性能低, 而且加速 SSD磨损。 本发明采用内存快照技术, 在内存中实现数据 的读写分离, 提高系统的读写并发度。 而内存快照的特性使得使用 FIFO緩存 策略可以有效体现数据时间局部性的特点,免去额外的緩存替换算法, 并且使 得命中判断更加筒单和快速。
2: 追加写入数据与空洞文件相结合。
使用 FIFO型緩存的换出页直接写入 SSD中, 不覆盖原有数据,使用的是追 加的写入方式, 利用标准输出库的用户态緩存聚合写粒度, 实现大粒度写入的 目的, 并且由于追加写入的天然特性决定了适合实现数据一致性, 可靠性。 本 发明使用不间断快照的技术保障数据的高可靠性,并提供高效的故障恢复机制。
但追加写入需要在写入时去除冗余数据,使得页面逻辑编号与实际位置不 相对应,如果另外加一层映射管理势必增加了元数据负担和不一致的风险, 本 发明中利用文件系统本身具有的空洞文件机制,使得页面逻辑编号与实际位置 建立起筒单对应的关系, 大大降低了数据放置的管理难度。
总的技术效果
系统利用内存快照 B+树的数据索引结构可提供高读写并发性能。 利用基 于追加写入的 10模式, 并使用文件空洞, 不间断快照机制, 可以提供适合 SSD 特性, 并提供数据高可靠性的数据放置机制。
附图说明 图 1为本发明系统整体存储组织架构;
图 2为本发明页级写緩存结构图;
图 3为本发明内存快照 B+树示例说明;
图 4为本发明 LogManager工作原理示意图;
图 5为本发明读出操作流程;
图 6为本发明写入操作流程。 具体实施方式
下面给出本发明的具体实施方式, 结合附图对本发明做出了详细描述。 ( Tree Index ) 内存快照 B+树索引模块: 利用内存快照 B+树技术, 实现 数据索引机制。
( Memory Pool )内存池管理模块:进行 B+树页面的空间分配,緩存管理。 ( Log Manager ) 日志型数据管理模块: 对数据持久化功能进行具体的读 写操作, 并通过空洞文件机制实现逻辑页号和物理位置的映射管理。
内存快照 B+树索引
B+树是数据库和文件系统中常用的数据索引结构, 优点是保持存储数据 稳定有序, 插入和修改拥有较稳定的对数时间复杂度。本发明使用内存快照机 制改进传统 B+树数据索引机制来满足新的需求。
B+树的结构以页为单位, 各个页为树结构中的节点。 B+树种存在中间节 点和叶子节点两类节点, 中间节点由 B+树根节点开始向下延伸, 各个节点的 页中记录子节点的页索引, 根节点在 B+树末端, 根节点对应页中存放实际 key-value数据。 B+树节点页面的组织包括页头保持的页面元数据信息, 已经 页面其余部分保持的数据列表, 其中叶子节点的数据列表为存储在系统中的 Key- Value对, 中间节点的数据列表存储 Key-Index对, Index项指向该条记录指 向的子节点页面, Key项保存该条记录指向的子页面中最小的 Key作为子树的 分离值。任意 Key在 B+树中的位置可以由根节点开始顺着分离值索引到叶子节 点找到。 随着 Key-Value对的插入, 某页面放满数据时会进行分裂操作, 并加 深 B+树, 这样来保证 B+树的平衡性, 提供稳定的插入和检索性能。
本小节将叙述如何利用内存快照技术来改进 B+树索引结构, 实现高并发 特性。
图 3展示了内存快照技术的运作机理。 图中标明 B+树的一部分, A节点为
B+树根节点, 现在需要对 D节点做一次更新操作。 则我们首先将 D节点页面进 行拷贝, 拷贝的副本页面为 D' , 然后在 D' 页面中进行所需要的更新。 进行完 这个操作以后,需要对 B中对 D, 的索引也做更新,那么根据内存快照的原则, 为了防止读写竟争,也需要先对 B进行拷贝,然后在副本 B, 中进行更新操作。 依次类推, 这个拷贝也在根节点 A上发生了。
当整个更新操作完成时, 形成了一棵以 A, 为根节点的新 B+树, 值得注意 的是, A, 相比较 A来说, 指向 B, 的索引有变化, 而其他索引仍然不变。 同样 的, B, 更新了指向 D, 的页面, 其他索引没有变化, 如图中的 C页面, 依然可 由 B, 中的索引项找到。
若以 A, 页面为根节点则当前形成了一个新的 B+树结构, 当更新操作完成 时, 要提交该操作达到新的一致状态, 只需要将存储系统索引的 B+树索引根 节点变更为 A, 节点即可。 后续操作将从 A, 为起点进入 B+树索引中, 然后开 始查找, 当然可以成功地体现出对 D页面的更新效果。 而在提交 A, 成为新的
B+树根节点之前, 并发的读操作线程将从 A节点页面进入到 B+树索引中, 它 们进行的查找操作均不会受到在拷贝页面中进行的更新操作的影响,不会发生 读写竟争。
上图中演示的是最筒单的快照技术应用, 实际中的情况要更为复杂。 比如 当对 D页面的操作引发了页面分裂, 则 B, 中不仅需要更新索引, 还需要插入 新的索引项。 同样, 对 B, 页面的插入操作也可能会造成 B, 页面的分裂, 这 种具体的情形和传统 B+树操作的情况基本类似, 也就不在此赘述。
总结而言, 本章节阐述了内存快照技术在改进 B+树索引结构并发性上的 设计和实现,通过该技术的应用,使得处理读请求的线程不需要对索引中的数 据结构进行加锁而可以做到直接访问,这种技术在读占优的负载中可以显著提 高系统整体的并发性。
FIFO页緩存管理机制
本发明提出的緩存管理策略是面向内存快照 B+树页面的, 其本身具有负 载特殊性。 我们知道, 在 B+树索引结构中, 所有的读写操作都需要从 B+树的 根节点页面进入索引结构, 进行查找定位的工作。 从这个特性可以看出, B+ 树中访问最频繁的恰恰是树结构中位于较高层次的节点页面。与内存快照技术 相结合来看, 每次的更新写入操作都会引起重新为对应的 B+树路径上的页面 分配新页面以进行拷贝操作。 这种特点造成的结果是, 经常处于 B+树查找路 径上的页面,也就是较高层次的页面,会经常因为被拷贝而出现在新分配的页 面中。 也就是说, 在内存快照的 B+树索引结构中, 页面的分配顺序本身就体 现出了很强的访问时间局部性特征。
在这种特征下,基于 FIFO替换算法的緩存管理成为一种可能的选择。 FIFO ( First-In First-Out )算法, 即是由一个先进先出的队列来对緩存页面的替换进 行管理。 每次分配新的页面时, 都会将其放入 FIFO队列中, 队列满时, 发生 替换的原则就是选择队尾页面进行替换。这也就是实现了驻留緩存中的页面是 新分配的页面, 根据前一段中的论述, 分配顺序体现了内存快照 B+树索引页 面的时间局部性。
FIFO页级写緩存的设计使用环形队列的结构, 整个环划分为 write区域和 read区域, write区域中为正在进行写操作, 尚未提交的页面, read区域中为已 经完成写操作并提交的页面,可以供读操作从緩存中获得。 write指针指向 write 区域的末尾, 该指针也是下一个写操作向写緩存申请新页面时装载的位置,在 系统运行时, write指针位置不断获得新页面并沿着环形队列前移, 同时完成写 操作的页面提交为 read区域, 并由一 read指针指向新近提交的页面位置。 在这 个过程中, 一个后台异步写入线程将以适合应用需求的速度将 read区域依次持 久化到 SSD中, 已经完成持久化的页面区域称为 flush区域, 一个 flush指针指向 下一个要做持久化的页面, flush区域为 read区域的一部分, 也是可以供 write指 针获得新页面的区域。
利用空洞文件机制的追加写
对于 SSD来说, 追加写入方式的优点主要是不会产生原地更新操作, 以及 容易进行大粒度聚合的写入。这可以更加充分地利用写入带宽, 同时减少小粒 度随机写类型的操作对于垃圾回收和数据碎片化带来的压力。所以追加写入方 式是一种适合 SSD特性的写入模式优化。
另外, Log-Structured日志型追加方式进行写入内存快照 B+树这种解决方 案可以保证 B+树中的父节点页面总是要在子节点页面之后再进行写入。 每次 实际写入 B+树的根节点, 即表明一个完整而且一致的 B+树索引结构以及被持 久化到 SSD中。 在发生系统崩溃, 而需要进行故障恢复的时候, 只需要在日志 型写入的数据文件中, 找到最靠近末尾的 B+树根节点, 就可以顺利恢复一个 全局一致的索引和数据结构。 也就是说, 我们通过一种不间断快照的手段, 达 到了数据高可靠的目的, 避免了数据损坏的场景, 而且使得故障恢复的时间与 总数据集大小无关。
内存快照技术分配产生的所有内存页面如果全部由 Log-Structured型写入 持久化到 SSD中, 则会产生过多的冗余数据, 使得 SSD写入带宽的利用率过于 低下。 为了解决这一问题, 我们在实际写入的时候对页面必须进行过滤。 已经 被快照的页面,也就是说更新的版本的版本存在于内存中,那么在一般情况下, 就不需要将其写入到 SSD中去。
在 B+树型索引结构中, 父节点页面对子节点页面的索引是由逻辑页号来 表示的。 对于内存快照 B+树结构来说, 逻辑页号就是页面分配的顺序编号, 如果将所有分配的页面依次写入 SSD, 则页面在 SSD上的物理位移与逻辑页号 就建立了一种筒单的——对应关系,即可以由索引子节点页面的逻辑页面直接 计算获得物理位移,冗余页面过滤的过程实际上也就跳过了部分分配的页面而 没有将其真正写入,那么前文提到的分配页面的逻辑页号和写入 SSD的物理位 移之间的筒单对应关系也就不存在了。那么我们必须要对这个对应关系进行一 些额外的管理以使得可以顺利通过逻辑页号找到物理的页面位置。
我们提出利用文件系统空洞文件的支持来管理逻辑页号和实际物理位置 的关系, 大大降低了系统的实现和逻辑复杂度, 并且通过对内核级功能支持的 灵活运用, 保证了实现的性能。
持久化写入的具体事项通过在页级緩存中运行的后台异步 Flush线程完成, 该线程持续将页面写入 SSD。 而根据内存快照的特性, 每个提交的根节点都代 表了一个一致的数据视图, 只要确保将当前的 B+树根节点 Flush到 SSD中, 并 记录下根节点所在位置, 就相当于建立了一个数据快照。 Flush线程需要跳过 已被拷贝的页, 这样的跳过使得逻辑的页编号与实际的页物理位置不相对应, 故本系统中利用文件系统的空洞文件机制,跳过页面时写入空洞,保持了两者 的对应的逻辑对应关系, 这样就不必引入额外的页面映射管理层。 页面索引号 实际就是顺序写入 SSD的序号,通过索引号的计算可以直接判断该页是否在写 緩存中, 如果没有命中(页框已经被写请求回收)则根据索引号可以找到该页 在 SSD中的位置, 然后读取。
操作示例
1、 后台异步写入线程的运行过程说明
图 4显示图 3中发生的写入操作在实际物理写入层面的视图。 因为发生 D页 面的写入,拷贝生成 3个新页面 D,, Β' , Α' ,按照分配的次序出现在右边的 FIFO 页面緩存队列中(实际上是用环形队列实现, 这里做了筒化, 但不影响原理说 明)。
后台有并发的异步写入线程会在 FIFO队列上顺着页面分配顺序运行, 将 相应位置上的页面写入到 SSD中去。
我们在写入 A, B , D页面的时候,已经知道它们是冗余页面(已经被拷贝), 不应该实际将其写入存储设备中。这里我们引入文件空洞的机制,检查到冗余 页面时, 虽然不进行数据写入,但是利用 lseek系统调用在目前的 Log-Structured 数据文件末尾形成一个页面大小的文件空洞,依次类推, 直到非冗余页面的时 候, 才真正写入数据。 比如在例子中, 后台 Flush线程首先跳过 D页面, 形成一 个页面大小的空洞, 随后发现 C页面是有效数据, 就将其写入空洞之后, 随后 又需要兆过 A和 B页面, 形成又一个空洞, 大小为两个页面, 随后的 Α,, Β,, C, 页面则正常进行写入。 在这些页面分配的过程中, 逻辑页号都是顺次递增 分配的, 在使用文件空洞机制之后, 我们可以发现, 所有页面还是可以由逻辑 页号乘以页面大小产生的位移来直接进行访问,而实际写入文件的量却减少为 4个页面, 起到了过滤冗余写入的作用。
2、 读出操作流程
读出记录操作指给定一个 Key的情况下, 存储系统返回该 Key对应的 Value
( Key和 Value均以字符串表示)。 如图 5 , 读操作的流程大致如下:
1、 从系统获得出当前的 B+树根节点, 作为 B+树索引查找的起点。 因为前 文所述的内存快照技术的运用, 读操作无需对页面进行加锁。
2、 对于包括根节点在内的中间节点页面进行页面内部的折半查找, 取得 正确的索引项, 获得下一个需要进行查找的页面逻辑页号。这一查找过程直到 获得叶子节点后终结。
3、 通过逻辑页号获得物理页面的操作通过调用 Memory Pool模块完成。 Memory Pool模块将该页号与目前 FIFO队列中最小的页号相比较, 判断是否在 队列中。 如果比最小页号大, 也就是緩存命中的情况, 可以直接返回 Memory Pool中的页面引用。
4、 如果没有命中緩冲, 则需要分配额外页面空间, 然后到 SSD中读取。 用逻辑页号获得 SSD中的数据需要通过调用 Log Manager模块的功能来完成。 因为文件空洞机制的作用, Log Manager模块此时的任务非常筒单, 只需要用 逻辑页号乘以页面大小, 然后读取相应页面即可。
5、 最后在叶子节点页面中完成最终的 Key-Value对查找, 返回结果。
(3) 写入操作流程
写入记录操作指的是将一个 Key值和一个 Value值以数据对的方式写入到 存储系统中, 供以后的读取。 存储系统采用单写多读的线程模型, 写线程进入 索引结构时始终面对最新的 B+树根节点, 这点不同于读线程面对的情况。
如图 6, 写操作的流程大致如下:
1、 写操作需要进行的第一步和读操作是一致的, 是通过一次 B+树的查找 来确定要插入新数据记录的正确位置, 所进行的操作与读操作基本一样, 就不 再赘述。 有一点不同的是, 因为对于 Memory Pool模块中的 FIFO环形队列 Read Region的改变全部发生在写线程中,所以写线程本身对于页面緩存命中的判断 就不需要进行加锁了。
2、 完成查找正确插入位置的操作时, 写线程将根节点到插入位置页面整 条路径的页面压入一个栈结构中 ,该栈结构中除了保存指向对应页面的指针外 , 还保存了路径中的中间节点指向子节点的页内索引号。
3、 写入页面的过程将会依次弹出栈中页指针, 这里使用内存快照的技术 来避免加锁保护, 对一个页面的修改, 需要先调用 Memory Pool的接口来请求 一个新的页面, 然后将源页面的内容拷贝到新页面中, 再进行修改操作。 在随 后弹出的父节点页面中,需要将原先指向子节点的索引页号修改为新的逻辑页 号。 4、 父节点页面中, 需要将原先指向子节点的索引页号修改为新的逻辑页 号, 这个修改也同样是利用内存快照机制完成的。 如果子节点发生了分裂, 则 还需要插入分裂点。
5、 当整个写操作完成后, 进行提交, 需要进行的操作是将已经完成写入 或者更新的所有页面并入 Read Region中, 然后修改新的 B+树根节点为当前的 索引 B+树根节点。
本发明还公开一种基于 SSD的 Key- Value型本地存储系统, 包括: 内存快照 B+树索引模块, 用于对于数据采用内存快照 B+树索引结构, 进 行内存中的读写分离操作;
内存池管理模块, 用于经过索引后的数据, 针对 B+树页面使用 FIFO队列 管理緩存;
日志型数据管理模块, 用于对所述数据页面追加写入 SSD, 通过空洞文件 机制在日志型追加写入的数据中实现逻辑页号和物理位置的映射管理。
所述的基于 SSD的 Key- Value型本地存储系统, 所述内存快照 B+树索引模 块包括:
首节点更新操作模块, 用于根节点 A为 B+树根节点, 如对首节点 D做一次 更新操作; 首先将首节点 D页面进行拷贝, 拷贝的副本页面为首节点 D,, 然后 在首节点 D, 页面中进行所需要的更新;
中间节点更新操作模块, 用于进行完这个操作以后, 需要对中间节点 B中 对首节点 D, 的索引也做更新, 根据内存快照的原则, 为了防止读写竟争, 需 要先对中间节点 B进行拷贝, 然后在副本中间节点 B, 中进行更新操作; 依次 操作, 所述拷贝过程也在根节点 A上发生;
更新完成模块, 用于当整个更新操作完成时, 形成了一棵以根节点 A, 为 根节点的新 B+树, 根节点 A, 相比较 A, 指向 B, 的索引有变化, 而其他索引 仍然不变;
页面指向模块, 用于中间节点 B, 更新了指向首节点 D, 的页面, 其他索 引没有变化。
所述的基于 SSD的 Key- Value型本地存储系统, 所述内存池管理模块包括: 形成队列结构模块, 用于 FIFO页级写緩存的设计使用环形队列的结构, 整个环划分为 write区域和 read区域, write区域中为正在进行写操作, 尚未提交 的页面, read区域中为已经完成写操作并提交的页面, 可以供读操作从緩存中 获得;
指针位置前移模块,用于 write指针指向 write区域的末尾,该指针也是下一 个写操作向写緩存申请新页面时装载的位置,在系统运行时, write指针位置不 断获得新页面并沿着环形队列前移, 同时完成写操作的页面提交为 read区域, 并由 read指针指向新近提交的页面位置;
持久化模块, 用于在这个过程中,后台异步写入线程将以适合应用需求的 速度将 read区域依次持久化到 SSD中, 已经完成持久化的页面区域称为 flush区 域, 一个 flush指针指向下一个要做持久化的页面, flush区域为 read区域的一部 分, 供 write指针获得新页面的区域;
对应写入模块,用于在后台异步写入线程将相应页面写入 SSD中的过程中, 已经在环形队列中存在更新拷贝的页面属于冗余页面, 不需要进行写入, 本系 统中将跳过该种页面, 同时在 SSD的数据文件中制造同样大小的文件空洞, 该 文件空洞不占用实际空间也不进行实际写入操作,但保持了逻辑页号和数据页 面在文件中位移的对应关系。
所述的基于 SSD的 Key- Value型本地存储系统,所述日志型数据管理模块包 括:
索引入口模块,用于获得当前的 B+树根节点,作为 B+树索引查找的起点; 获得索引项模块,用于对于包括根节点在内的中间节点页面进行页面内部 的折半查找, 取得正确的索引项, 获得下一个需要进行查找的页面逻辑页号, 这一查找过程直到获得叶子节点后终结; 因为内存快照技术的使用,读操作无 需对页面进行加锁;
调用内存池管理模块,用于通过逻辑页号获得物理页面的操作通过调用内 存池管理模块完成; 内存池管理模块将该页号与 FIFO队列中最小的页号相比 较, 判断是否在队列中, 如果比最小页号大, 也就是緩存命中的情况, 直接返 回内存池管理模块中的页面引用;
分配页面空间模块, 用于如果没有命中緩冲, 则需要分配额外页面空间, 然后到 SSD中读取; 用逻辑页号获得 SSD中的数据需要通过调用日志型数据管 理模块的功能来完成; 因为文件空洞机制的作用, 日志型数据管理模块此时的 任务非常筒单, 只需要用逻辑页号乘以页面大小, 然后读取相应页面即可; 完成查找模块, 用于最后在叶子节点页面中完成最终的 Key- Value对查找, 返回结果。
所述的基于 SSD的 Key- Value型本地存储系统,所述日志型数据管理模块还 包括:
插入位置模块, 用于通过 B+树的查找来确定要插入新数据记录的正确位 置, 获得当前的 B+树根节点, 作为 B+树索引查找的起点; 读操作无需对页面 进行加锁; 对于内存池管理模块中的 FIFO环形队列 Read Region的改变全部发 生在写线程中, 所以写线程本身对于页面緩存命中的判断就不需要进行加锁; 页面压入模块, 用于完成查找正确插入位置的操作时, 写线程将根节点到 插入位置页面整条路径的页面压入一个栈结构中 ,该栈结构中除了保存指向对 应页面的指针外, 还保存了路径中的中间节点指向子节点的页内索引号;
页面修改模块, 用于写入页面的过程将会依次弹出栈中页指针, 这里使用 内存快照的技术来避免加锁保护,对一个页面的修改, 需要先调用内存池管理 模块的接口来请求一个新的页面, 然后将源页面的内容拷贝到新页面中,再进 行 4爹改操作; 在随后弹出的父节点页面中, 需要将原先指向子节点的索引页号 修改为新的逻辑页号;
修改逻辑页号模块, 用于父节点页面中, 需要将原先指向子节点的索引页 号修改为新的逻辑页号, 这个修改也同样是利用内存快照完成; 如果子节点发 生了分裂, 则还需要插入分裂点;
提交模块, 用于当整个写操作完成后, 进行提交, 需要进行的操作是将已 经完成写入或者更新的所有页面并入 Read Region中, 然后修改新的 B+树根节 点为当前的索引 B+树根节点。
本领域的技术人员在不脱离权利要求书确定的本发明的精神和范围的条 件下,还可以对以上内容进行各种各样的修改。 因此本发明的范围并不仅限于 以上的说明, 而是由权利要求书的范围来确定的。

Claims

权 利 要 求
1、 一种基于 SSD的 Key- Value型本地存储方法, 其特征在于, 包括: 步骤 1 , 对于数据采用内存快照 B+树索引结构, 进行内存中的读写分离 操作;
步骤 2, 经过索引后的数据, 针对 B+树页面使用 FIFO队列管理緩存; 步骤 3 , 对所述数据页面追加写入 SSD, 通过空洞文件机制在日志型追加 写入的数据中实现逻辑页号和物理位置的映射管理。
2、 如权利要求 1所述的基于 SSD的 Key- Value型本地存储方法, 其特征 在于, 所述步骤 1包括:
步骤 21 , 根节点 A为 B+树根节点, 如对首节点 D做一次更新操作; 首 先将首节点 D页面进行拷贝,拷贝的副本页面为首节点 D,,然后在首节点 D, 页面中进行所需要的更新;
步骤 22, 进行完这个操作以后, 需要对中间节点 B中对首节点 D, 的索 引也做更新, 根据内存快照的原则, 为了防止读写竟争, 需要先对中间节点 B 进行拷贝, 然后在副本中间节点 B, 中进行更新操作; 依次操作, 所述拷贝过 程也在根节点 A上发生;
步骤 23 , 当整个更新操作完成时, 形成了一棵以根节点 A, 为根节点的 新 B+树, 根节点 A, 相比较 A, 指向 B, 的索引有变化, 而其他索引仍然不 变;
步骤 24, 中间节点 B, 更新了指向首节点 D, 的页面, 其他索引没有变 化。
3、 如权利要求 1所述的基于 SSD的 Key- Value型本地存储方法, 其特征 在于, 所述步骤 2包括:
步骤 31 , FIFO 页级写緩存的设计使用环形队列的结构, 整个环划分为 write区域和 read区域, write区域中为正在进行写操作,尚未提交的页面, read 区域中为已经完成写操作并提交的页面, 可以供读操作从緩存中获得;
步骤 32, write指针指向 write区域的末尾,该指针也是下一个写操作向写 緩存申请新页面时装载的位置, 在系统运行时, write指针位置不断获得新页 面并沿着环形队列前移, 同时完成写操作的页面提交为 read 区域, 并由 read 指针指向新近提交的页面位置; 步骤 33 , 在这个过程中, 后台异步写入线程将以适合应用需求的速度将 read区域依次持久化到 SSD中, 已经完成持久化的页面区域称为 flush区域, 一个 flush指针指向下一个要做持久化的页面, flush区域为 read区域的一部分, 供 write指针获得新页面的区域;
步骤 34, 在后台异步写入线程将相应页面写入 SSD中的过程中, 已经在 环形队列中存在更新拷贝的页面属于冗余页面, 不需要进行写入, 本方法中将 跳过该种页面, 同时在 SSD的数据文件中制造同样大小的文件空洞, 该文件 空洞不占用实际空间也不进行实际写入操作,但保持了逻辑页号和数据页面在 文件中位移的对应关系。
4、 如权利要求 1所述的基于 SSD的 Key- Value型本地存储方法, 其特征 在于, 所述步骤 3读出操作包括:
步骤 41 , 获得当前的 B+树根节点, 作为 B+树索引查找的起点; 读操作 无需对页面进行加锁;
步骤 42, 对于包括根节点在内的中间节点页面进行页面内部的折半查找, 取得正确的索引项, 获得下一个需要进行查找的页面逻辑页号, 这一查找过程 直到获得叶子节点后终结; 因为内存快照技术的使用,读操作无需对页面进行 加锁;
步骤 43 , 通过逻辑页号获得物理页面的操作通过调用内存池管理模块完 成; 内存池管理模块将该页号与 FIFO队列中最小的页号相比较, 判断是否在 队列中, 如果比最小页号大, 也就是緩存命中的情况, 直接返回内存池管理中 的页面引用;
步骤 44, 如果没有命中緩冲, 则需要分配额外页面空间, 然后到 SSD中 读取; 用逻辑页号获得 SSD中的数据需要通过调用日志型数据管理模块的功 能来完成; 因为文件空洞机制的作用, 日志型数据管理模块此时的任务非常筒 单, 只需要用逻辑页号乘以页面大小, 然后读取相应页面即可;
步骤 45 ,最后在叶子节点页面中完成最终的 Key- Value对查找,返回结果。
5、 如权利要求 1所述的基于 SSD的 Key- Value型本地存储方法, 其特征 在于, 所述步骤 3写入操作流程还包括:
步骤 51 , 通过 B+树的查找来确定要插入新数据记录的正确位置, 获得当 前的 B+树根节点, 作为 B+树索引查找的起点; 读操作无需对页面进行加锁; 对于内存池管理模块中的 FIFO环形队列 Read Region的改变全部发生在写线 程中, 所以写线程本身对于页面緩存命中的判断就不需要进行加锁;
步骤 52, 完成查找正确插入位置的操作时, 写线程将根节点到插入位置 页面整条路径的页面压入一个栈结构中,该栈结构中除了保存指向对应页面的 指针外, 还保存了路径中的中间节点指向子节点的页内索引号;
步骤 53 , 写入页面的过程将会依次弹出栈中页指针, 这里使用内存快照 的技术来避免加锁保护,对一个页面的修改, 需要先调用内存池管理的接口来 请求一个新的页面, 然后将源页面的内容拷贝到新页面中, 再进行修改操作; 在随后弹出的父节点页面中,需要将原先指向子节点的索引页号修改为新的逻 辑页号;
步骤 54, 父节点页面中, 需要将原先指向子节点的索引页号修改为新的 逻辑页号, 这个修改也同样是利用内存快照完成; 如果子节点发生了分裂, 则 还需要插入分裂点;
步骤 55 , 当整个写操作完成后, 进行提交, 需要进行的操作是将已经完 成写入或者更新的所有页面并入 Read Region中, 然后修改新的 B+树根节点 为当前的索引 B+树根节点。
6、 一种基于 SSD的 Key- Value型本地存储系统, 其特征在于, 包括: 内存快照 B+树索引模块, 用于对于数据采用内存快照 B+树索引结构, 进 行内存中的读写分离操作;
内存池管理模块, 用于经过索引后的数据, 针对 B+树页面使用 FIFO队 列管理緩存;
日志型数据管理模块,用于对所述数据页面追加写入 SSD,通过空洞文件 机制在日志型追加写入的数据中实现逻辑页号和物理位置的映射管理。
7、 如权利要求 6所述的基于 SSD的 Key- Value型本地存储系统, 其特征 在于, 所述内存快照 B+树索引模块包括:
首节点更新操作模块, 用于根节点 A为 B+树根节点, 如对首节点 D做一 次更新操作; 首先将首节点 D页面进行拷贝, 拷贝的副本页面为首节点 D,, 然后在首节点 D, 页面中进行所需要的更新;
中间节点更新操作模块, 用于进行完这个操作以后, 需要对中间节点 B 中对首节点 D, 的索引也做更新, 根据内存快照的原则, 为了防止读写竟争, 需要先对中间节点 B进行拷贝, 然后在副本中间节点 B, 中进行更新操作; 依 次操作, 所述拷贝过程也在根节点 A上发生;
更新完成模块, 用于当整个更新操作完成时, 形成了一棵以根节点 A, 为 根节点的新 B+树, 根节点 A, 相比较 A, 指向 B, 的索引有变化, 而其他索 引仍然不变;
页面指向模块, 用于中间节点 B, 更新了指向首节点 D, 的页面, 其他索 引没有变化。
8、 如权利要求 6所述的基于 SSD的 Key- Value型本地存储系统, 其特征 在于, 所述内存池管理模块包括:
形成队列结构模块, 用于 FIFO 页级写緩存的设计使用环形队列的结构, 整个环划分为 write区域和 read区域, write区域中为正在进行写操作, 尚未提 交的页面, read区域中为已经完成写操作并提交的页面, 可以供读操作从緩存 中获得;
指针位置前移模块,用于 write指针指向 write区域的末尾,该指针也是下 一个写操作向写緩存申请新页面时装载的位置, 在系统运行时, write指针位 置不断获得新页面并沿着环形队列前移, 同时完成写操作的页面提交为 read 区域, 并由 read指针指向新近提交的页面位置;
持久化模块, 用于在这个过程中,后台异步写入线程将以适合应用需求的 速度将 read区域依次持久化到 SSD中, 已经完成持久化的页面区域称为 flush 区域, 一个 flush指针指向下一个要做持久化的页面, flush区域为 read区域的 一部分, 供 write指针获得新页面的区域;
对应写入模块, 用于在后台异步写入线程将相应页面写入 SSD中的过程 中, 已经在环形队列中存在更新拷贝的页面属于冗余页面, 不需要进行写入, 本系统中将跳过该种页面, 同时在 SSD的数据文件中制造同样大小的文件空 洞, 该文件空洞不占用实际空间也不进行实际写入操作,但保持了逻辑页号和 数据页面在文件中位移的对应关系。
9、 如权利要求 6所述的基于 SSD的 Key- Value型本地存储系统, 其特征 在于, 所述日志型数据管理模块包括:
索引入口模块,用于获得当前的 B+树根节点,作为 B+树索引查找的起点; 获得索引项模块,用于对于包括根节点在内的中间节点页面进行页面内部 的折半查找, 取得正确的索引项, 获得下一个需要进行查找的页面逻辑页号, 这一查找过程直到获得叶子节点后终结; 因为内存快照技术的使用,读操作无 需对页面进行加锁;
调用内存池管理模块,用于通过逻辑页号获得物理页面的操作通过调用内 存池管理模块完成; 内存池管理模块将该页号与 FIFO队列中最小的页号相比 较, 判断是否在队列中, 如果比最小页号大, 也就是緩存命中的情况, 直接返 回内存池管理模块中的页面引用;
分配页面空间模块, 用于如果没有命中緩冲, 则需要分配额外页面空间, 然后到 SSD中读取; 用逻辑页号获得 SSD中的数据需要通过调用日志型数据 管理模块的功能来完成; 因为文件空洞机制的作用, 日志型数据管理模块此时 的任务非常筒单, 只需要用逻辑页号乘以页面大小, 然后读取相应页面即可; 完成查找模块,用于最后在叶子节点页面中完成最终的 Key- Value对查找, 返回结果。
10、如权利要求 6所述的基于 SSD的 Key- Value型本地存储系统,其特征 在于, 所述日志型数据管理模块还包括:
插入位置模块, 用于通过 B+树的查找来确定要插入新数据记录的正确位 置, 获得当前的 B+树根节点, 作为 B+树索引查找的起点; 读操作无需对页面 进行加锁; 对于内存池管理模块中的 FIFO环形队列 Read Region的改变全部 发生在写线程中,所以写线程本身对于页面緩存命中的判断就不需要进行加锁; 页面压入模块, 用于完成查找正确插入位置的操作时, 写线程将根节点到 插入位置页面整条路径的页面压入一个栈结构中 ,该栈结构中除了保存指向对 应页面的指针外, 还保存了路径中的中间节点指向子节点的页内索引号;
页面修改模块, 用于写入页面的过程将会依次弹出栈中页指针, 这里使用 内存快照的技术来避免加锁保护,对一个页面的修改, 需要先调用内存池管理 模块的接口来请求一个新的页面, 然后将源页面的内容拷贝到新页面中,再进 行 4爹改操作; 在随后弹出的父节点页面中, 需要将原先指向子节点的索引页号 修改为新的逻辑页号;
修改逻辑页号模块, 用于父节点页面中, 需要将原先指向子节点的索引页 号修改为新的逻辑页号, 这个修改也同样是利用内存快照完成; 如果子节点发 生了分裂, 则还需要插入分裂点; 提交模块, 用于当整个写操作完成后, 进行提交, 需要进行的操作是将已 经完成写入或者更新的所有页面并入 Read Region中, 然后修改新的 B+树根 节点为当前的索引 B+树根节点。
PCT/CN2013/076222 2012-05-24 2013-05-24 基于SSD的Key-Value型本地存储方法及系统 WO2013174305A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201210165053.XA CN102722449B (zh) 2012-05-24 2012-05-24 基于SSD的Key-Value型本地存储方法及系统
CN201210165053.X 2012-05-24

Publications (1)

Publication Number Publication Date
WO2013174305A1 true WO2013174305A1 (zh) 2013-11-28

Family

ID=46948222

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2013/076222 WO2013174305A1 (zh) 2012-05-24 2013-05-24 基于SSD的Key-Value型本地存储方法及系统

Country Status (2)

Country Link
CN (1) CN102722449B (zh)
WO (1) WO2013174305A1 (zh)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016155238A1 (zh) * 2015-03-27 2016-10-06 中兴通讯股份有限公司 一种分布式存储系统中的文件读取方法及服务端
CN109521959A (zh) * 2018-11-01 2019-03-26 西安交通大学 一种基于ssd-smr磁盘混合键值存储系统数据组织方法
US11586629B2 (en) 2017-08-17 2023-02-21 Samsung Electronics Co., Ltd. Method and device of storing data object

Families Citing this family (37)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102722449B (zh) * 2012-05-24 2015-01-21 中国科学院计算技术研究所 基于SSD的Key-Value型本地存储方法及系统
CN102968381A (zh) * 2012-11-19 2013-03-13 浪潮电子信息产业股份有限公司 一种利用固态硬盘提高快照性能的方法
CN103902471B (zh) * 2012-12-28 2017-08-25 华为技术有限公司 数据缓存处理方法和装置
CN103135946B (zh) * 2013-03-25 2014-11-26 中国人民解放军国防科学技术大学 基于ssd的大规模存储系统中的文件布局方法
CN103135945B (zh) * 2013-03-25 2014-11-26 中国人民解放军国防科学技术大学 用于ssd的多通道动态读写调度方法
CN103197958B (zh) * 2013-04-01 2016-08-10 天脉聚源(北京)传媒科技有限公司 一种数据传输方法及系统与转发器设备
CN104252386B (zh) * 2013-06-26 2017-11-21 阿里巴巴集团控股有限公司 数据更新的加锁方法和设备
CN104424103B (zh) * 2013-08-21 2018-05-29 光宝科技股份有限公司 固态储存装置中高速缓存的管理方法
CN104915145B (zh) * 2014-03-11 2018-05-18 华为技术有限公司 一种降低LSM Tree写放大的方法和装置
CN104035729B (zh) * 2014-05-22 2017-02-15 中国科学院计算技术研究所 一种日志映射的块设备精简配置方法
CN105447059B (zh) * 2014-09-29 2019-10-01 华为技术有限公司 一种数据处理方法及装置
CN104461384B (zh) * 2014-11-28 2017-11-24 华为技术有限公司 一种数据写入方法及存储设备
CN104657500A (zh) * 2015-03-12 2015-05-27 浪潮集团有限公司 一种基于key-value键值对的分布式存储方法
CN104809237B (zh) * 2015-05-12 2018-12-14 百度在线网络技术(北京)有限公司 LSM-tree索引的优化方法和装置
CN105117415B (zh) * 2015-07-30 2018-07-03 西安交通大学 一种优化的ssd数据更新方法
CN105138622B (zh) * 2015-08-14 2018-05-22 中国科学院计算技术研究所 用于lsm树存储系统的插入操作及负载的读取和合并方法
CN107678981A (zh) * 2017-08-24 2018-02-09 北京盛和大地数据科技有限公司 数据处理方法及装置
CN107832236B (zh) * 2017-10-24 2021-08-03 记忆科技(深圳)有限公司 一种提高固态硬盘写性能的方法
CN107798130B (zh) * 2017-11-17 2020-08-07 广西广播电视信息网络股份有限公司 一种分布式存储快照的方法
CN108052643B (zh) * 2017-12-22 2021-02-23 北京奇虎科技有限公司 基于LSM Tree结构的数据存储方法、装置及存储引擎
CN110109914A (zh) * 2018-01-16 2019-08-09 恒为科技(上海)股份有限公司 一种应用驱动的数据存储与索引方法
US11392544B2 (en) * 2018-02-06 2022-07-19 Samsung Electronics Co., Ltd. System and method for leveraging key-value storage to efficiently store data and metadata in a distributed file system
CN108509613A (zh) * 2018-04-03 2018-09-07 重庆大学 一种利用nvm提升加密文件系统性能的方法
CN108763572B (zh) * 2018-06-06 2021-06-22 湖南蚁坊软件股份有限公司 一种实现Apache Solr读写分离的方法和装置
CN110659154A (zh) * 2018-06-28 2020-01-07 北京京东尚科信息技术有限公司 一种数据处理方法和装置
CN109683811B (zh) * 2018-11-22 2020-05-19 华中科技大学 一种混合内存键值对存储系统的请求处理方法
CN110162525B (zh) * 2019-04-17 2023-09-26 平安科技(深圳)有限公司 基于b+树的读写冲突解决方法、装置及存储介质
CN110058969B (zh) * 2019-04-18 2023-02-28 腾讯科技(深圳)有限公司 一种数据恢复方法及装置
CN110716695A (zh) * 2019-09-12 2020-01-21 北京浪潮数据技术有限公司 一种节点日志的存储方法、系统、电子设备及存储介质
CN110764705B (zh) * 2019-10-22 2023-08-04 北京锐安科技有限公司 一种数据的读写方法、装置、设备和存储介质
CN110716923B (zh) * 2019-12-12 2020-03-17 腾讯科技(深圳)有限公司 数据处理方法、装置、节点设备及存储介质
CN111352860B (zh) * 2019-12-26 2022-05-13 天津中科曙光存储科技有限公司 一种Linux Bcache中的垃圾回收方法及系统
CN114625713A (zh) * 2020-12-10 2022-06-14 华为技术有限公司 一种存储系统中元数据管理方法、装置及存储系统
CN112784120B (zh) * 2021-01-25 2023-02-21 浪潮云信息技术股份公司 一种基于范围分片方式的kv内存数据库存储管理方法
CN113821476B (zh) * 2021-11-25 2022-03-22 云和恩墨(北京)信息技术有限公司 数据处理方法及装置
CN114579061B (zh) * 2022-04-28 2022-07-29 苏州浪潮智能科技有限公司 一种数据存储方法、装置、设备及介质
CN115793989B (zh) * 2023-02-06 2023-06-20 江苏华存电子科技有限公司 一种基于NAND的NVMe KV SSD数据管理方法

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102364474A (zh) * 2011-11-17 2012-02-29 中国科学院计算技术研究所 用于机群文件系统的元数据存储系统和管理方法
CN102402602A (zh) * 2011-11-18 2012-04-04 航天科工深圳(集团)有限公司 一种实时数据库的b+树索引方法及装置
CN102722449A (zh) * 2012-05-24 2012-10-10 中国科学院计算技术研究所 基于SSD的Key-Value型本地存储方法及系统

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO1998031161A2 (en) * 1997-01-11 1998-07-16 Tandem Computers, Incorporated Method and apparatus for automated a-key updates in a mobile telephone system

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102364474A (zh) * 2011-11-17 2012-02-29 中国科学院计算技术研究所 用于机群文件系统的元数据存储系统和管理方法
CN102402602A (zh) * 2011-11-18 2012-04-04 航天科工深圳(集团)有限公司 一种实时数据库的b+树索引方法及装置
CN102722449A (zh) * 2012-05-24 2012-10-10 中国科学院计算技术研究所 基于SSD的Key-Value型本地存储方法及系统

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
LIM, HYEONTAEK ET AL.: "SILT: A Memory-Efficient, High-Performance Key-Value Store.", SOSP' 11., 26 October 2011 (2011-10-26), pages 1 - 12 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016155238A1 (zh) * 2015-03-27 2016-10-06 中兴通讯股份有限公司 一种分布式存储系统中的文件读取方法及服务端
US11586629B2 (en) 2017-08-17 2023-02-21 Samsung Electronics Co., Ltd. Method and device of storing data object
CN109521959A (zh) * 2018-11-01 2019-03-26 西安交通大学 一种基于ssd-smr磁盘混合键值存储系统数据组织方法

Also Published As

Publication number Publication date
CN102722449A (zh) 2012-10-10
CN102722449B (zh) 2015-01-21

Similar Documents

Publication Publication Date Title
WO2013174305A1 (zh) 基于SSD的Key-Value型本地存储方法及系统
US11288252B2 (en) Transactional key-value store
CN105630409B (zh) 使用存储器内阵列和盘上页结构的双重数据存储
CN110825748B (zh) 利用差异化索引机制的高性能和易扩展的键值存储方法
CN106575297B (zh) 使用盲更新操作的高吞吐量数据修改
US11023453B2 (en) Hash index
US10437662B2 (en) Crash recovery using non-volatile memory
KR101932372B1 (ko) 인 플레이스 스냅샷들
KR101914019B1 (ko) 분산 데이터베이스 시스템들을 위한 고속 장애 복구
KR101926674B1 (ko) 로그 레코드 관리
KR101827239B1 (ko) 분산 데이터 시스템들을 위한 전 시스템에 미치는 체크포인트 회피
US8738850B2 (en) Flash-aware storage optimized for mobile and embedded DBMS on NAND flash memory
US8589361B2 (en) Reduced disk space standby
US20180011892A1 (en) Foster twin data structure
Levandoski et al. LLAMA: A cache/storage subsystem for modern hardware
US20170351543A1 (en) Heap data structure
US10521117B2 (en) Unified table delta dictionary memory size and load time optimization
US11100083B2 (en) Read only bufferpool
US10289709B2 (en) Interleaved storage of dictionary blocks in a page chain
WO2023165196A1 (zh) 一种日志存储加速方法、装置、电子设备及非易失性可读存储介质
US11537582B2 (en) Data access method, a data access control device, and a data access system
US10909091B1 (en) On-demand data schema modifications
US11615083B1 (en) Storage level parallel query processing
Nguyen et al. Why Files If You Have a DBMS
US10997164B2 (en) Unified table delta dictionary lazy materialization

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: 13794547

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: 13794547

Country of ref document: EP

Kind code of ref document: A1