Abstract:
Data is loaded to a data structure while an image copy of the data structure is concurrently formed. After data records are obtained from one or more data sources, each of the data records is associated with one of multiple pages. As each page is completed, it is written to a primary data structure. Also upon completion of each page in the primary data structure, concurrently with storage of the page in the primary data structure, an image copy of the page is made in an image copy data set. Partially or completely failed primary data structures may also be restored using image copies made according to the invention. Timestamps mark the time at which each page are made; image copy pages include the same timestamp as their respective primary pages. Upon detecting a data structure failure, each page of the image copy is sequentially reviewed. For each image page being reviewed, the page&#39;s timestamp is compared with the timestamp of the corresponding page from the primary data structure. The page is copied from the image copy to the primary data structure only if the timestamp comparison indicates that the image page is more recent than the page from the primary data structure.

Description:
BACKGROUND OF THE INVENTION 
     1. Field of the Invention 
     The present invention relates to the use of database tables in computers. More particularly, the invention concerns an apparatus, article of manufacture, and process for loading or reorganizing a data structure and concurrently forming a full or incremental image copy (&#34;backup copy&#34;) of the data structure. Such data structures may comprise, for example, tables and/or indices. The invention also facilitates recovery of lost or damaged data structures from full or incremental image copies. 
     2. Description of Related Art 
     Database applications constitute one of the most popular applications of computers today. Engineers have designed may different systems and programs to store, query, and modify information stored in database tables. Intricate manipulation of table data is performed using a database language such as &#34;SQL&#34;. Higher level operations are typically achieved by executing various high level database commands, in a database system language, such as the &#34;DB2&#34; product of International Business Machines Corp. Some of these high level operations include &#34;Load &#34; and &#34;Image Copy&#34; operations, for example. 
     Typically, a database management system performs a &#34;Load&#34; operation to compile data from various sources, and ultimately assemble the data into a new or existing table. An &#34;Image Copy&#34; operation creates a backup copy (an &#34;image copy&#34;) of a loaded table. In systems such as DB2™ systems, an Image Copy operation is typically performed immediately after a table is loaded to create an image copy of a table. This Image Copy operation serves a number of functions, which aid in reconstruction of the table. First, if the Load operation leaded data into an existing table without separately storing (&#34;logging&#34;) the changes, a copy of the updated table is the only way to recover the updated table. Second, even if the Load operation logged changes to the table, having the copy of the updates table helps reduce the time needed for recovering the loaded table. In particular, the table may be recovered by performing the logged updates to the previous version of the table. Accordingly, the Image Copy operation is extremely useful in modern database systems. 
     The Image Copy operation works by making a second &#34;pass&#34; over the table data, the first pass being performed when the underlining data is initially located, sorted, and assembled by the Load operation itself. In the second pass, the database manager reviews the loaded table, copying each page of the completed table to the image copy. Thus, as shown in Table 1, pages of the table are copied in order from the beginning of the table to its end, each page being copied only once. The image copy is therefore structured as shown in Table 1, below. 
     
                       TABLE 1______________________________________Conventional Image Copy______________________________________page 1page 2page 3page 4page 5. . .______________________________________ 
    
     Known Load operations wait until completion of the Load to perform an Image Copy operation, delaying the user&#39;ability to update the data until temporarily delaying availability of the data to the user until completion of the Image Copy operation. This protects the data, preventing user access to the table until an image copy has been made. Although this arrangement has proven satisfactory in many applications, some applications may require faster access to data of loaded tables. As mentioned above, creating an image copy of the loaded table requires a second pass of the table. For some users, then, waiting until the Load and Image Copy complete may simply take too long. 
     SUMMARY OF THE INVENTION 
     Broadly, he present invention concerns the loading or reorganizing of a data structure concurrently with forming an image copy of the data structure. The invention also facilitates recovery of lost or damaged data structures from image copies. 
     As a more specific example, the invention may be implemented to provide a method of forming or reorganizing a primary data structure in a primary database while concurrently creating a image copy of the primary data structure. The primary data structure is formed by first obtaining data records from one or more source locations. Then, each of the data records is associated with one of multiple pages. Finally, the data records are written page-by-page to the primary data structure to complete the data structure. Concurrently with storage of each page, the page is copied to an image copy data set. 
     This method may also include further steps to restore a partially or completely failed data structure using the image copy data set. This method uses timestamps provided by the primary and image copy pages. Namely, when a page is written to the primary data structure, it is provided with a timestamp representing the time of writing the page to the primary data structure. Image copy pages include the same timestamp as their respective primary pages. When recovering from a data structure failure, each page of the image copy is sequentially reviewed. For each image page being reviewed, the page&#39;s timestamp is compared with the timestamp of the corresponding page from the primary data structure. The page is copied from the image copy data set to the primary data structure only if the timestamp comparison indicates that the image copy is more recent than the primary table page. 
     In addition to the method described above, the invention may be implemented to provide an apparatus for data structure loading/copying or restoration. In still another embodiment, the invention may be implemented to provide an article of manufacture comprising a data storage device tangibly embodying a program of machine-readable instructions executable by a digital data processing apparatus to perform method steps for data structure loading/copying or restoration. 
     The invention affords its users with a number of distinct advantages. Importantly, the invention enhances data integrity by proving an image copy of a data structure during loading of the data structure. Thus, the image copy is available in case the loaded data structure later fails. Unlike prior arrangements, the invention creates pages of the image copy concurrently with writing of data structure pages. Consequently, the image copy of the invention is conducted more quickly, since its creation is effectively transparent to the user. 
    
    
     BRIEF DESCRIPTION OF THE DRAWINGS 
     The nature, objects, and advantages of the invention will become more apparent to those skilled in the art after considering the following detailed description in connection with the accompanying drawings, in which like reference numerals designate like parts throughout, wherein: 
     FIG. 1 is a block diagram of a system exemplifying hardware components and interconnections pursuant to the invention. 
     FIG. 2 is a perspective view showing one example of an article of manufacture pursuant to the invention. 
     FIG. 3 is a flowchart illustrating a sequence of method steps to concurrently load data into a data structure and store an image cop of the data structure pursuant to the invention. 
     FIG. 4 is a flowchart illustrating a sequence of method steps to recover data table from a full image copy pursuant to the invention. 
     FIG. 5 is a flowchart illustrating a sequence of method steps to recover data from an incremental image copy pursuant to the invention. 
    
    
     DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS 
     Hardware Components &amp; Interconnections 
     One aspect of the invention concerns a database management system 100, which may be embodied by various hardware components and interconnections as described in FIG. 1. The system 100 includes a database manager 102, and a number of different data items. In the illustrated example, the items of data include an image copy (or &#34;backup copy&#34;) data set 110, source data 112, and a primary data structure 114. However, it should be apparent to ordinarily skilled artisans (having the benefit of the disclosure) that one or more of the data items may reside on a single device, or may be dispersed among multiple different devices. 
     The database manager 102 includes one or more processing units, such as a load processor 104 and a copy processor 106. As an example of another alternative, a single multitasking processor may be used. The processors 104/106 are interconnected by a buffer 108. The load processor 104 is coupled to the source data 112 and primary data structure 114, for the purpose of obtaining raw data records, assembling the data records, and ultimately storing the data records in the primary data structure 114. The copy processor 106 is coupled to the image copy data set 110, for storage of an image copy of the data structure created by the load processor 104. 
     As an example, the database manager 102 may be provided by a multiprocessing system such as an IBM™ System 390 model 9672 mainframe computer, where each processor 104/106 comprises a central processing unit (CPU) of the System 390 computer, and the buffer 108 is a RAM buffer. The database manager 102 may utilize an operating system such as IBM MVS™, for example. The data items 110/112/114 may be provided by a variety of different storage devices, such as magnetic disk drive(&#34;hard drive&#34;), magnetic or optical tape storage, etc. The data items 110/112/114 may be consolidates on separate data storage devices (as illustrated), distributed among multiple devices, consolidated on a common device, or another suitable alternative. 
     The operation of the foregoing components is discussed in greater detail below. 
     Operation 
     In addition to the various hardware embodiments described above, a different aspect of the invention concerns a method for loading and currently making an image copy of a data structure, and a method for restoring a failed data structure from the image copy. Such a method may be implemented, for example, by operating the system 100 to execute a sequence of machine-readable instructions. 
     Data Storage Device 
     These instructions may reside in various types of data storage medium. In this respect, one aspect of the present invention concerns an article of manufacture, comprising a data storage medium tangible embodying a program of machine-readable instructions executable by a digital data processor to perform method steps to perform operations such as loading, copying, and restoration of a data structure. 
     This data storage medium may reside, for example, in a RAM program storage buffer (not shown) contained in the database manager 102. Alternatively, the instructions may be contained in another data storage medium, such as a magnetic data storage diskette 200 (FIG. 2). Whether contained in the database manager 102 or elsewhere, the instructions may instead be stored on another type of data storage medium such as hard drive storage (e.g., conventional magnetic disk or RAID array), magnetic tape, electronic read-only memory (e.g. ROM), optical storage device (e.g. WORM), paper &#34;punch &#34; cards, or other data storage medium. In an illustrative embodiment of the invention, the machine-readable instructions may comprise lines of compiled DB2™ language code. 
     Load/Image Copy 
     FIG. 3 shows a sequence of method steps 300 to illustrate one example of the method aspect of the present invention, involving loading a data structure and concurrently creating a full image copy (or &#34;backup copy&#34;) For ease of explanation, but without limitation intended thereby, the example of FIG. 3 is described in the context of the database management system 100 as shown in FIG. 1. 
     After the steps 300 are initiated in task 302, the load processor 104 obtains data records from the source data 112. The source data 112 may be embodied by one or more data storage devices, of various makes and models. Next, the load processor 104 organized the data records into pages in task 306; as these pages contain data from data records, they may be referred to as &#34;data pages&#34;. Additional pages may be created in the form of &#34;format pages&#34;, which contain information besides raw data, such as &#34;space map&#34; pages, header information, and the like. Task 306&#39;s organization of data records into pages may be performed, for example, in the buffer 108. 
     These data and format pages constitute subcomponents of the primary data structure, which is created in task 308 (discussed below). The primary data structure may comprise a table, an index, or another appropriate data structure made up of subcomponents provided by the data and format pages. 
     Following task 306, the load processor 104 in task 308 individually writes one page to the primary data structure 114. As each page is written to the primary data structure in task 308, the copy processor 106 writes a copy of the page to the image copy data set 110 in task 310. Task 308 is therefore performed concurrently, which is possible due to the multiprocessing nature of the database manager 102. Accordingly, the image copy created by task 310 may be referred to as an &#34;inline&#34; image copy. 
     In task 308, the load processor 104 also assigns the current page a timestamp, which is recorded in the data structure as part of the page. The timestamp may comprise a new code or a well known code such as a log sequence number. Accordingly, the image copy page (task 310) is written with the same timestamp as the original page (task 308). As discussed in greater detail below, the timestamps help to distinguish different versions of the same page. After each page is written to the primary data structure in task 308, query 312 asks whether all pages have been written; if not, task 308 is repeated. 
     Pages in tasks 308/310 are stored as they are created. Therefore, the pages are not necessarily in sequential order, and the same page may be stored multiple times, as shown in Table 2 (below). 
     
                       TABLE 2______________________________________Inline Image Copy______________________________________page 2page 1page 3page 2page 4. . .______________________________________ 
    
     Pages may be stored out of order for a number of different reasons. For example, the sequence 300 may sort the data records concurrently with loading the pages. As a result, page 15 may be filled with data before page 5; and accordingly, page 14 would be written to the data structure earlier. For a number of different reasons, the same page may be written to the data structure multiple times. As one example, a partially complete data page may be written to the data structure as part of a prescribed &#34;checkpoint&#34;, where data is written to the data structure and its image copy (whether the page is complete or not) to protect against possible future data failure. Space map pages are another reason for possibly writing the same page multiple times. For instance, even though a space map page may be initially written to indicate one state of space availability in the table, the space map page must be rewritten whenever changed or new data pages affect the space availability reported by the space map page. in task 308. Task 310 does not reconfigure the image copy to invalidate older versions of duplicate pages. 
     When query 312 find that there are no table pages remaining to be loaded to the table, the routine 300 ends in task 314. 
     Incremental Load/Incremental Image Copy 
     Using similar techniques as described above, the invention may also be implemented (not shown) to perform an Incremental Load operation and a concurrent Incremental Image Copy operation. An incremental Load operation loads updated and/or new pages to an existing data structure. The Incremental Image Copy operation creates a copy of each page written to the data structure as part of the Incremental Load. Therefore, an incremental image copy data set only represents incrementally loaded pages of a primary data structure. 
     Restore Using Full Image Copy 
     FIG. 4 shows a sequence of method steps 400 to illustrate a different aspect of the method of the present invention, involving restoration of a data structure from an image copy. For ease of explanation, but without any limitation intended thereby, the example of FIG. 4 is described in the context of the database management system 100 shown in FIG. 1. 
     The steps may be initiated (task 402) upon detecting partial or complete failure of the primary data structure 114. Generally, the copy processor 106 proceeds thought all pages in the image copy data set, overseeing restoration of the necessary pages to the primary data structure. In particular, the copy processor 106 in task 404 selects one of the data pages stored in the image copy data set. Next, in task 404 the load processor 104 determines whether this page is already contained in the primary data structure; the current page may already be present in the primary data structure because (1) the data structure failure did not affect this page, or (2) this page has already been restored to the primary data structure according to task 410, described below. 
     If the current page is already contained in the primary data structure, query 408 determined whether the timestamp of the current page (e.g., page 1) exceeds the timestamp of the corresponding page (page 1) on the primary data structure. Query 408 may be performed by either processor 104/106 or a different processor, if desired. 
     If the current page is newer than the existing page in the primary data structure, the database manager 102 in task 410 copies the current page from the image copy into the primary data structure, superseding the existing copy of that page in the primary data structure. After task 410, or a negative answer to query 408, the copy processor 106 in query 412 determines whether all pages in the image copy data set have been reviewed. If not, another page is examined in task 404. Otherwise, having reviewed all pages in the image copy data set, the routine 400 ends in task 414. 
     As an alternative to task 408, a record may be made of the highest page yet restored, with timestamps only being compared in task 408 if the page number of the current page is less than or equal to tot the highest page yet restored. Otherwise, if the current page&#39;s number is higher than any yet stored, it is being stored anew, so no comparison is needed. 
     Restore Using Incremental Image Copy 
     FIG. 5 shows a sequence of method steps 500 to illustrate a different aspect of the method of the present invention, where a primary data structure is restored using an incremental image copy. For ease of explanation, but without any limitation intended thereby, the example of FIG. 5 is described in the context of the database management system 100 shown in FIG. 1. 
     The steps may be initiated (task 501) upon detecting partial or complete failure of the primary data structure 114. First, in task 502 the primary data structure is restored as completely as possible using the most recent full image copy (see FIG. 4). This may not be necessary, however, if the failure of the primary table is limited in scope. The state of the primary data structure after task 502 may be referred to as &#34;semi-restored&#34;. After task 502, the database manager 102 consults a log of intermediate modifications (i.e., non-loads) to the semi-restored table in task 503. As is known in the database industry, many systems maintain a record of modifications to a data structure between Load operations, e.g., changes to a table achieved using SQL. In task 503, the database manager 102 re-executes the logged changes to the semi-restored primary data structure, thereby further restoring the table. 
     After task 503, the copy processor 106 in task 504 selects one of the data pages stored in the incremental image copy. Then, in query 506, the load processor 104 determines whether this page is already contained in the primary data structure; the current page may already be present in the primary data structure because (1) the primary data structure failed did not affect this page, or (2) this page has already been restored to the primary data structure according to tasks 502, 503, or 510 (discussed below). 
     If the current page is already contained in the primary data structure, query 508 determines whether the timestamp of the current page (e.g., page 1) exceeds the timestamp of the correspondingpage (page 1) in the primary data structure. Query 508 may be performed by either processor 104/106 or a different processor, if desired. If the current page is newer than the existing page in the primary data structure, the database manager 102 in task 510 copies the current page from the image copy into the primary data structure, superseding the existing copy of that page in the primary data structure. 
     After task 510, or a negative answer to query 508, the copy processor 106 in query 512 determines whether all pages in the image copy have been reviewed. If not, another page is examined in task 504. Otherwise, having reviewed all pages in the image copy, the routine 500 ends in task 514. 
     Reorganization/Image Copy 
     According to still another embodiment of the method aspect of the invention, a &#34;Reorganize&#34; operation (not shown) may be performed to reclaim the wasted space and place rows of the primary data structure in proper order, while concurrently creating an inline image copy. This process may be useful because, after a period of user updates to a data structure, it may become &#34;disorganized&#34;, i.e., rows with similar keys may be placed far apart, and excessive space may be used. Preferably, the Reorganize operation unloads the data from the primary data structure into an intermediate data set sorts the data as it is unloaded, and the reloads the data into the primary data structure. The second part of the Reorganize operation, that of reloading the data into the table, is similar to the Load/Image Copy operation described previously, and illustrated in FIG. 3, where the unloaded data is the source data 112, and the concurrent reload and image copy creation take place as described previously in tasks 302 through 314. 
     Other Embodiments 
     While there have been shown what are presently considered to be preferred embodiments of the invention, it will be apparent to those skilled din the art that various changes and modifications can be made herein without departing from the scope of the invention as defined by the appended claims.