1. Field
Embodiments of the invention relate to creating and maintaining an order of a log stream without the use of a lock or latch.
2. Description of the Related Art
Databases store and retrieve data. Relational databases are organized into tables that consist of rows and columns of data. The rows may be called tuples or records or rows. A database typically has many tables, and each table typically has multiple records and multiple columns.
A table in a database can be accessed using an index. An index is an ordered set of references (e.g., pointers) to the records in the table. The index is used to access each record in the table using a key (i.e., one of the fields or attributes of the record, which corresponds to a column). The term “key” may also be referred to as “index key”. Without an index, finding a record may require a scan (e.g., linearly) of an entire table. Indexes provide an alternate technique to accessing data in a table. Users can create indexes on a table after the table is built. An index is based on one or more columns of the table. Also, a table may use hashing or some other mechanism that eliminates the need for an index.
A query may be described as a request for information from a database based on specific conditions. A query typically includes one or more predicates. A predicate may be described as an element of a search condition that expresses or implies a comparison operation (e.g., A=3).
Database systems provide for data consistency, transaction commit and abort, and recoverability in the event of a failure log changes made to database objects (e.g., tables). When a database system allows for concurrency of updates, the component responsible for managing the logged data determines how the log records are sequenced so that each log record can be uniquely identified and found. The simplest way to accomplish this is for the log managing component to serialize all requests to write a log record so that at any given moment in time only one log record is being added to the stream of log records. Typically, this serialization is facilitated through means of a lock or latch or similar mechanism (henceforth referred to generically as a latch). However, this level of serialization can become a bottleneck to all transactions making database updates.
In order to avoid this bottleneck, conventional systems offer various techniques. A first technique is using a single sequence number that is unique and not having to worry about the exact physical ordering of the log records. This makes the serialization very simple at the expense of making it difficult to find a particular log record. A second technique queues all requests to a single execution unit with the possibility of putting the entire log record on the queue. The advantages and disadvantages are similar to the first technique. A third technique reserves ranges of log records for multiple execution units and merges the records together at a later time. The complication again comes when an individual log record needs to be located for some purpose. Other techniques use variations on the first, second, and third techniques.
Some conventional systems rely on exact sequencing of the log records in the physical stream of log records. The Relative Byte Address (RBA) of a log record, which is an address relative to the beginning of the log stream, and the Logical Record Sequence Number (LRSN) are both increasing, although there could be multiple log records with the same LRSN value that only have increasing RBA values. The exact sequencing makes it very easy to locate a log record, but imposes limitations on the serialization technique used to place an individual log record in the stream of log records. In addition, the necessity of having to control Input/Output (I/O) of the log stream at the block level, which is often not necessary for some database systems, induces further complications and additional structures that need to be properly updated and kept in sequence. For this reason, and due to the desire to have the expense of placing the log record in the log stream charged to the requesting application, some conventional systems have serialized all requests so that the contention is on a single latch that controls the creation of the log stream.
Thus, there is a need for creating and maintaining the order of a log stream without the use of a lock or latch.
Provided are a method, computer program product, and system for using a series of compare and swap operations to assign a Relative Byte Address (RBA) and a Logical Record Sequence Number (LRSN) to a log record. One or more log buffers for storing the log record are identified, and the log record is moved to the one or more log buffers.
Referring now to the drawings in which like reference numbers represent corresponding parts throughout:
In the following description, reference is made to the accompanying drawings which form a part hereof and which illustrate several embodiments of the invention. It is understood that other embodiments may be utilized and structural and operational changes may be made without departing from the scope of the invention.
With a series of atomic updates, properly sequenced and with retry logic to deal with failed attempts, embodiments create a log stream that does not rely on a single latch to provide the serialization needed to maintain the proper sequencing of log records in the log stream.
In
In certain embodiments, the LRSN is based on a time stamp. Because multiple systems updating the same data are required to have synchronized clocks, the LRSN can be used to sequence the log records from multiple systems in chronological order. This creates a requirement in some situations that the LRSN generated for a particular log record must be greater than an existing value. In such a situation, the log record sequencer 154 may impose a delay so that the time-based LRSN will increase before the log record is placed in the log stream.
Each log buffer 240, 242, 244 consists of log record data, which may be an entire log record, multiple log records or part of a single log record followed by a trailer that contains information about the log buffer 240, 242, 244. The trailer contains, among other information, the RBA of the beginning of the log buffer 240, 242, 244 and the LRSN of the last log record in the log buffer 240, 242, 244. If there is one log record or part of one log record in the log buffer 240, 242, 244, the trailer contains the LRSN of that log record.
In certain embodiments, the log buffer 156 is in memory. The entire contents of the log buffer 240, 242, 244 are written to external storage 170 (e.g., disk) as a single unit, and the size of an individual log buffer 240, 242, 244 is the size of a physical block on the external storage 170, at least as the physical block appears to the system or application initiating the I/O operation. Certain modern disk subsystems emulate the physical blocks expected by the system or application initiating the I/O operation, and the actual implementation is typically an array of multiple disks that write in fixed block sizes that are not visible outside of the disk subsystem.
Compare and swap operations are a way of atomically updating the memory so that multiple concurrent user threads 110, 112, 114 can ensure that the update they intend to do is performed and not regressed by another user thread that requests an update to the same storage at the same time. In certain embodiments, the compare and swap is a hardware instruction and is implemented by using any of the following instructions, generically referred to as Compare and Swap or CS: Compare and Swap 32-bit (CS), Compare Double and Swap 32-bit (CDS), Compare and Swap 64-bit (CSG), Compare Double and Swap 64-bit (CDSG). The compare and swap may refer to several instructions that set values in a recovery tracking area in addition to doing the compare and swap for the value explicitly mentioned.
The process of writing a log record to the log stream involves invoking the log manager, performing serialization to assign the RBA and LRSN to the log record, moving the log record into the buffer, updating the control element, and, if needed, updating the information in the log buffer trailer. Instead of performing these operations while holding a latch, embodiments use a series of compare and swap operations, with appropriate retries for failures of attempted compared and swap operations, until the RBA and LRSN values are assigned. The assigning of the RBA to a log record simultaneously calculates the next RBA to be used by the next log record to ensure that the next log record will not overwrite the current log record. The log record is then moved to one or more log buffers 156, and the log buffer trailer is updated, if needed, by means of another compare and swap operation.
The log stream is written to the external storage 170, usually asynchronously, by the process 158. Because the log stream is read in the event of a data store management system 150 failure, the log buffers 156 written to the external storage 170 contain complete log records only (i.e., there can not be some combination of complete log records and incomplete log records still being moved). A log buffer 156 is not necessarily full when the log buffer is written to the external storage 170, but the log buffer does consist of at least one complete log record. There are a number of stimuli that result in the write of log buffer 156 to external storage 170 (i.e., a physical write of the log buffer 156 is initiated).
An individual user thread may be interrupted at any time, introducing an unpredictable delay. For this reason, other user threads that started processing later may complete processing sooner, and the LRSN value is checked and possibly updated at multiple points.
Thus, embodiments accomplish operations without obtaining a latch and still maintain the integrity of the log stream, even if there is an unrecoverable failure in the process of creating the log record. An unrecoverable failure may be an invalid request to write a log record or a cancel initiated by some other user thread that occurs somewhere in the process of creating the log record.
The procedure of embodiments starts at a point where a request has been made to write a log and control has been transferred to the log manager. The retry points listed below may be part of the normal flow and are used as retry points if branched to from another location.
Control begins at block 300 with the log record sequencer 154 receiving a log write request. In block 302, the log record sequencer 154 creates a tracking area that is used to record events in the creation of the log record. In block 304, the log record sequencer sets up recovery that will get control in the event of an error or unexpected termination. Setting up such recovery is well known to one skilled in the art.
In different embodiments, a current LRSN is either generated or centrally stored. In certain embodiments, the LRSN is based off the time of day clock, so the current LRSN is generated at any moment in time. In other embodiments, the LRSN may be a number that is stored in some centralized location. In block 306, the log record sequencer 154 determines whether the log record has a minimum required LRSN (which is determined by the user thread, depending on the resource that the user thread is updating) and whether the current LRSN is greater than or equal to (“>=”) the required LRSN. The required LRSN may be described as the minimum LRSN as set by the caller. When the log record is created, the log record may or may not have a required minimum LRSN. Typically, log records that update data (e.g., tables or indexes) have minimum required LRSNs. Many other log records do not have minimum required LRSNs and will use the current LRSN as the minimum required LRSN. If the log record does not have a minimum required LRSN or if the current LRSN is greater than or equal to the required LRSN, processing continues to block 308, otherwise, processing continues to block 310 (
From block 306, if the current LRSN is greater than or equal to the required LRSN, processing continues to block 310 (
In block 320 (
In block 326, the log record sequencer 154 updates the control element using a single compare and swap operation to 1) increment the use count, 2) set the next available space in the log buffer, and 3) set indicators if the log buffer is full and if the log record spans one or more log buffers. From block 326 (
In block 332, the log record sequencer determines whether the LRSN determined so far is greater than the LRSN in the control element. If so, processing continues to block 334, otherwise, processing continues to block 336. The LRSN for the log record being written is the LRSN “determined so far”. The possibility exists that the LRSN for the log record is fine, but, another log record is being written following the log record that this user thread is writing and that the other user thread has already updated the control element. Embodiments constantly deal with concurrency since there is no single lock or latch to prevent concurrency. In block 334, the log record sequencer 154 updates the LRSN in the control element using the compare and swap operation. From block 324, processing continues to block 336. In block 336, the log record sequencer 154 moves the log record into the one or more log buffers 154. In block 338, the log record sequencer 154 decrements the use count in the control element for the log buffer using the compare and swap operation.
From block 338 (
In block 408, the log record sequencer 154 determines whether the current log buffer has moved. This is another concurrency issue. Another user thread may have changed what the current log buffer is and updated the information in the current control element pointer 210. If so, processing continues to block 410, otherwise, processing continues to block 412. In block 410, if the current log buffer has moved, which is determined from the current control element, the log record sequencer 154 ends processing for determining the next log buffer. That is, the determination of whether the current log buffer has moved can be determined by checking what the current control element is. The determination of the next buffer can be retried from an appropriate point by the log record sequencer 154.
In block 412, the log record sequencer 154 determines whether the log record spans multiple buffers. If so, processing continues to block 414, otherwise, processing continues to block 418 (
In block 418, the log record sequencer 154 determines whether the current log buffer has moved. This check is done again because another user thread my have claimed the one or more log buffers first. If so, processing continues to block 420, otherwise, processing continues to block 422. In block 420, if the current log buffer has moved, which is determined from the current control element, the log record sequencer 154 ends processing for determining the next buffer. The determination of the next buffer can be retried from an appropriate point by the log record sequencer 154. There may be enough room in the new current log buffer and the user thread may not have to go through this new log buffer determination.
In block 422, the log record sequencer 154 determines whether another user has already updated the control element put in the log buffer. If so processing continues to block 424, otherwise, processing continues to block 426. In block 424, the log record sequencer 154 checks if other control element needs to be updated and updates them as necessary (i.e., checks the LRSN and uses that LRSN if it is greater than the previously generated LRSN). After the updates, the process continues to block 426.
In block 426, when it has been determined where the current log record will end, the log record sequencer 154 sets the ending log buffer as the current log buffer by making the corresponding control element the current control element.
In block 502, the log record sequencer 154 copies the log record with a move character operation. In block 504, the log record sequencer 154 updates the information in the log buffer trailer and control element with a compare and swap operation. In block 506, the log record sequencer 154 determines whether the compare and swap operation failed. If so, processing continues to block 508, otherwise, processing continues to block 516 (
In block 508, the log record sequencer 154 determines whether to retry the compare and swap operation. If so, processing loops back to block 504, otherwise, processing continues to block 516 (
In block 510, the log record sequencer 154 copies the data of the log record until the end of the buffer is reached and updates the log buffer trailer and control element with a compare and swap operation. The control element update also indicates whether the log buffer has been filled and if the log buffer contains the start of a spanned record. In block 512, the log record sequencer 154 determines whether another log buffer is needed to store the log record. If so, processing continues to block 514, otherwise processing continues to block 516. In block 514, the log record sequencer 154 determines the next log buffer (using the logic of
In block 516, the log record sequencer 154 updates the control element with the RBA of the first byte after the end of the log record with a compare and swap operation. In block 518, the log record sequencer 154 determines whether the compare and swap operation failed. If so, processing continues to block 520, otherwise, processing continues to block 524.
In block 520, log record sequencer 154 determines whether to retry the compare and swap operation. If so, processing loops back to block 516, otherwise, processing continues to block 524. In particular, this updates the RBA value for the end of the log record moved. If this compare and swap operation fails and a log record that is physically before the log record that was just moved was responsible for the update, the compare and swap operation will be retried. If the other log record was physically after the log record that was just moved, then the compare and swap operation is not retried. Thus, the compare and swap operation will either eventually succeed or there will be a situation in which the compare and swap operation does not need to be retried.
In block 524, the log record sequencer 154 ends processing for moving the log record into the log buffer.
Thus, embodiments eliminate the need for a single latch to provide serialization.
As will be appreciated by one skilled in the art, aspects of the present invention may be embodied as a system, method or computer program product. Accordingly, aspects of the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment (including firmware, resident software, micro-code, etc.) or an embodiment combining software and hardware aspects that may all generally be referred to herein as a “circuit,” “module” or “system.” Furthermore, aspects of the present invention may take the form of a computer program product embodied in one or more computer readable medium(s) having computer readable program code embodied thereon.
Any combination of one or more computer readable medium(s) may be utilized. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, solid state memory, magnetic tape or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A computer readable signal medium may include a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages that support thread concurrency operations (i.e., compare and swap or similar hardware operations), including an object oriented programming language such as Java, Smalltalk, C++ or the like and conventional procedural programming languages, such as the “C” programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the latter scenario, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet Service Provider).
Aspects of the embodiments of the invention are described below with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer readable medium that can direct a computer, other programmable data processing apparatus, or other devices to function in a particular manner, such that the instructions stored in the computer readable medium produce an article of manufacture including instructions which implement the function/act specified in the flowchart and/or block diagram block or blocks.
The computer program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other devices to cause a series of operational processing (e.g., operations or steps) to be performed on the computer, other programmable apparatus or other devices to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide processes for implementing the functions/acts specified in the flowchart and/or block diagram block or blocks.
The code implementing the described operations may further be implemented in hardware logic or circuitry (e.g., an integrated circuit chip, Programmable Gate Array (PGA), Application Specific Integrated Circuit (ASIC), etc. The hardware logic may be coupled to a processor to perform operations.
Input/Output (I/O) devices 712, 714 (including but not limited to keyboards, displays, pointing devices, etc.) may be coupled to the system either directly or through intervening I/O controllers 710.
Network adapters 708 may also be coupled to the system to enable the data processing system to become coupled to other data processing systems or remote printers or storage devices through intervening private or public networks. Modems, cable modem and Ethernet cards are just a few of the currently available types of network adapters 708.
The computer architecture 700 may be coupled to storage 716 (e.g., a non-volatile storage area, such as magnetic disk drives, optical disk drives, a tape drive, etc.). The storage 716 may comprise an internal storage device or an attached or network accessible storage. Computer programs 706 in storage 716 may be loaded into the memory elements 704 and executed by a processor 702 in a manner known in the art.
The computer architecture 700 may include fewer components than illustrated, additional components not illustrated herein, or some combination of the components illustrated and additional components. The computer architecture 700 may comprise any computing device known in the art, such as a mainframe, server, personal computer, workstation, laptop, handheld computer, telephony device, network appliance, virtualization device, storage controller, etc.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used herein, the singular forms “a”, “an” and “the” are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms “comprises” and/or “comprising,” when used in this specification, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
The corresponding structures, materials, acts, and equivalents of all means or step plus function elements in the claims below are intended to include any structure, material, or act for performing the function in combination with other claimed elements as specifically claimed. The description of embodiments of the present invention has been presented for purposes of illustration and description, but is not intended to be exhaustive or limited to the invention in the form disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the invention. The embodiments were chosen and described in order to best explain the principles of the invention and the practical application, and to enable others of ordinary skill in the art to understand the invention for various embodiments with various modifications as are suited to the particular use contemplated.
The foregoing description of embodiments of the invention has been presented for the purposes of illustration and description. It is not intended to be exhaustive or to limit the embodiments to the precise form disclosed. Many modifications and variations are possible in light of the above teaching. It is intended that the scope of the embodiments be limited not by this detailed description, but rather by the claims appended hereto. The above specification, examples and data provide a complete description of the manufacture and use of the composition of the embodiments. Since many embodiments may be made without departing from the spirit and scope of the invention, the embodiments reside in the claims hereinafter appended or any subsequently-filed claims, and their equivalents.
Number | Name | Date | Kind |
---|---|---|---|
5043866 | Myre et al. | Aug 1991 | A |
5455946 | Mohan et al. | Oct 1995 | A |
5581750 | Haderle et al. | Dec 1996 | A |
5933838 | Lomet | Aug 1999 | A |
6490594 | Lomet | Dec 2002 | B1 |
7219262 | Miller et al. | May 2007 | B2 |
7483911 | Cherkauer | Jan 2009 | B2 |
7689626 | Miller et al. | Mar 2010 | B2 |
8090691 | Lynn | Jan 2012 | B2 |
20030009477 | Wilding et al. | Jan 2003 | A1 |
20060020634 | Huras et al. | Jan 2006 | A1 |
20080133615 | Bradshaw et al. | Jun 2008 | A1 |
20080162084 | Bower et al. | Jul 2008 | A1 |
20080208924 | Bradshaw et al. | Aug 2008 | A1 |
20090089339 | Mitchell et al. | Apr 2009 | A1 |
20090240739 | Bhatt et al. | Sep 2009 | A1 |
20100036861 | Srihari et al. | Feb 2010 | A1 |
20110131186 | Whisenant | Jun 2011 | A1 |
Entry |
---|
Wang, J. And Y. Hu, “A Novel Reordering Write Buffer to Improve Write Performance of Log-Structured File Systems”, © 2003 IEEE, Total 14 pp (Also IEEE Transactions on vol. 52, Iss. 12, Dec. 2003). |
Wang, R., B. Salzberg, and D. Lomet, “Transaction Support for Log-Based Middleware Server Recovery”, © 2009 IEEE, Total 4 pp (Also ICDE IEEE International Conference on Mar. 29, 2009-Apr. 2, 2009). |
Preliminary Remarks, Apr. 18, 2012, for U.S. Appl. No. 13/450,337, filed Apr. 18, 2012 by S.H. Lee et al., Total 2 pp. |
U.S. Appl. No. 13/450,337, filed Apr. 18, 2012, entitled “Creating and Maintaining Order of a Log Stream Without Use of a Lock or Latch” invented by Lee, S.H., D.L. Levish, and R.E. Parrish, Total 35 pp. |
Amendment 1, Sep. 26, 2012, for U.S. Appl. No. 13/450,337, filed Apr. 18, 2012 by S.H. Lee et al., Total 6 pp. |
Office Action 1, Jul. 2, 2012, for U.S. Appl. No. 13/450,337, filed Apr. 18, 2012 by S.H. Lee et al., Total 20 pp. |
Amendment 2, Mar. 27, 2013, for U.S. Appl. No. 13/450,337, filed Apr. 18, 2012 by S.H. Lee et al., Total 8 pp. |
Final Office Action 1, Jan. 2, 2013, for U.S. Appl. No. 13/450,337, filed Apr. 18, 2012 by S.H. Lee et al., Total 15 pp. |
Notice of Allowance, Dec. 9, 2014, for U.S. Appl. No. US13/450,337, filed on Apr. 18, 2012 by S.H. Lee et al., Total 16 pp. [57204C1 (Noa)]. |
Number | Date | Country | |
---|---|---|---|
20120096055 A1 | Apr 2012 | US |