1. Field of the Invention
The present invention relates to a method of recovering a database in a computing apparatus employing a database management system, and more particularly, to a method of efficiently recovering a database that can be applied to a database management system installed in a mobile communication terminal employing a flash memory as a storage unit.
2. Description of the Related Art
With the recent development of multimedia and network fields, an embedded system has become to include functions for processing multimedia information and connecting a network, and the structure of the embedded system has become more complicated. In a simple embedded system used previously, a sequential design was good enough for simple functions. However, as the embedded system becomes complicated, a new method different from the conventional method is needed. As the jobs that should be processed increase, a multitasking function for a complicated system is needed, and an operating system (OS) used only in a computer system is now required in the embedded system. Furthermore, most of embedded systems were required to satisfy a characteristic of real time processing, and as a result, a real-time operation system (RTOS) has appeared.
The RTOS is an operating system that, if an event occurs inside and/or outside a system to which the RTOS is applied, makes a delay time from the occurrence of the event to a time when processing of the event begins, not exceed a predetermined time. In a system employing an RTOS (a real time system), an occurrence of an event and processing of the event are performed in real time, and a predetermined job is necessarily performed in a predetermined time. For example, mobile communication devices, such as a mobile communication terminal, a smart phone, a personal digital assistant (PDA), a wireless Internet terminal, and a car navigation system, and portable terminals for a special purpose, such as sales, marketing, and stock management, are real time system using the RTOS as other embedded systems.
Meanwhile, the variety of portable communication devices mentioned above, including the portable communication terminal, are continuously evolving and their functions are becoming more sophisticated and complicated. The portable communication devices have been changing and evolving continuously through fusion between heterogeneous devices, for example, fusion of a digital camera and a portable phone, fusion of an MP3 layer and a portable phone, and introduction of a TV reception function into a portable phone. In these portable communication devices, the amount of information to be managed and processed increases, and the contents of information processing jobs become more complicated, diversified, and sophisticated. Accordingly, in order to efficiently manage and process the information, introduction of means for performance improvement in terms of both hardware and software is needed, and as an example of these means, introduction of a database system can be considered.
However, so far there has been no precedence of introduction and commercialization of a database system in a portable communication terminal. In a conventional portable communication terminal, for example, a phone book is implemented by using a file system utilizing a data structure. However, when the trend and speed of evolution of a mobile communication terminal are considered, introduction of a database system into a mobile communication terminal can be regarded as a matter of time.
Generally, when a query is processed in a database system, a log-based recovery method, and a shadow paging method are used in order to perform complete recovery from a variety of failures. Meanwhile, a mobile communication terminal is greatly limited by its execution speed. A response to a job request from a user should be performed within a predetermined time. Accordingly, the shadow paging method that can be performed simply may be more suitable and effective for recovery of a database mounted on a mobile terminal.
In order to ensure data integrity, a database system divides a storage space into a recovery area to store data for recovery and a storage area to store actually processed results, and manages the areas. When data integrity is destroyed due to abnormal termination of a mobile communication terminal, data in the database storage area is recovered with using the data stored in the recovery area of the database. A method of storing data in the recovery area of the database is guaranteed, for example, through a write-ahead long (WAL) protocol. In order to remove a side effect occurring when changed contents of a transaction that is not completed are stored in the storage area of a database, the unchanged original image is stored first in the recovery area of the database and the changed image of the page is stored in the storage area of the database according to the WAL protocol.
A flash file system generally used in a mobile communication terminal does not provide any special method in preparation for problems, for example, power loss or a phone reset, occurring in the middle of performing overwriting a predetermined file. Even though a recovery method to deal with changes in one file is implemented, if a transaction of a database requires changes in multiple files, the multiple files cannot be recovered at once. This means that data being modified may be lost.
According to the conventional method of recovering data of the database storage area using the shade paging method, as illustrated in
In order to solve this problem, as illustrated in
The present invention provides a method of recovering a database by which each recovery file is stored together with information required for recovery, so that recovery of an original state before change can be successfully completed even though part of a file is lost due to abnormal termination, such as power supply stoppage, of a computing apparatus while a transaction is performed.
The present invention also provides a database recovery method requiring a less memory space and quickly and efficiently supporting recovery of a database, suitable for a mobile communication terminal environment employing a flash memory as a storage medium, in which the database is divided into files of a small size and input and/or output operations are performed in units of files.
According to an aspect of the present invention, there is provided a method of recovering a database, by which in a computing apparatus having a database management system which allocates a database storage area and a database recovery area separately in a data storing means, divides the database that is the object of management, into a plurality of page units of a smaller size, and performs input and/or output operations for the data storing means, if a failure occurs while the database management system performs a transaction, the database is recovered.
The method of recovering a database according to the present invention may be applied to a mobile communication terminal. In this case, a storage medium that can be employed as a data storing means may be a flash memory.
This method of recovering a database includes: sequentially reading images of pages in the database storage area that should be changed in order to perform the transaction, among the pages of the database in the database storage area, storing the read images in a memory buffer, assigning sequential serial numbers to the original images of the pages before change, backing up the original images in the database recovery area, then, changing the images of the pages in the memory buffer according to the transaction, and performing this series of jobs with respect to all pages that are the objects of change; updating each page in the database storage area that is the object of the change, with a corresponding page changed in the memory buffer; if the computing apparatus is abnormally terminated without successfully performing the updating operation, when the computing apparatus is booted again, confirming whether or not the serial number of the last page in the database recovery area matches the total number of pages stored in the database recovery area, and if the serial number matches the total number, with the original image of the page before modification stored in the database recovery area, recovering the corresponding page in the database storage area.
The recovering of the corresponding page in the database storage area may include: when the computing apparatus is booted again, reading the database recovery area and confirming whether or not data exists in the database recovery area; comparing the read total number of pages stored in the database recovery area with the serial number of the last page; if the two compared values are identical, with the original image of the page before modification stored in the database recovery area, recovering the corresponding page in the database storage area, and if the two values are different, deleting all pages stored in the database recovery area.
In the database recovery method, the serial numbers may be assigned to the pages backed up in the database recovery area such that, while one transaction is performed, by incrementing a serial number by 1 from 1, the serial number is assigned sequentially to each of all pages that should be changed according to the transaction, and if the transaction is completed, the serial numbers are reset.
Meanwhile, the size of the database may increase due to the contents changed during the transaction in relation to the database, and even in this case, complete recovery needs to be guaranteed. For this, when the original images of pages before change are backed up in the database recovery area together with the corresponding serial numbers, the size of the entire database before the transaction begins may be additionally stored together. In this case, if there are pages added due to the changed contents while the transaction is performed, pages, each having a page number greater than the size of the database before the transaction is performed is deleted. At the same time, recovery of other changed contents in relation to the transaction is performed by using the original images of the pages before the change that are backed up in the database recovery area. By doing so, even when pages increase due to the change, complete recovery can be guaranteed.
The above objects and advantages of the present invention will become more apparent by describing in detail preferred embodiments thereof with reference to the attached drawings in which:
The present invention will now be described more fully with reference to the accompanying drawings, in which an embodiment of the present invention is applied to a computing apparatus, such as a mobile communication terminal employing a database management system.
A mobile communication terminal mainly uses a flash memory as a storage medium. Accordingly, a database management system mounted on the mobile communication terminal stores data in the flash memory. A process of reading data from and storing data in the flash memory takes most of operation time in the database of the mobile communication terminal. When part of contents of a file recorded in the flash memory needs to be modified, the data of the part cannot be read or written separately due to the characteristic of the flash memory as a medium, and the entire contents of the recorded file should be read and the part can be modified. After the part is modified, again the entire contents of the changed file should be recorded in the flash memory. This process needs much more time to read and write again data, with the increasing size of data to be recorded. Furthermore, even though the actual change is limited to a part of a file, data should be transferred in units of files, such that the utilization of a memory space is degraded.
In a database management system operating based on a flash memory, a lump of a database file structure is divided into file units of a smaller size, for example, 2 KB or 4 KB, for efficient input and/or output operations, and input and/or output operations for the flash memory are performed. Also, when the database is recovered from an abnormal termination, the recovery operation is performed in units of the files. This is because of the input/output (I/O) characteristic of the flash memory described above. At this time, information on the size of the database is added to each file such that the information can be used when a recovery operation is performed.
Thus, the present invention relates to a method of recovering a database assuming that the method of dividing one database file structure of a large size into smaller pieces that are a plurality of page units of a small size and storing data in a flash memory is employed.
Referring to
One file in the flash memory 200 corresponds to one page in a database. Accordingly, hereinafter, ‘file’ and ‘page’, as terms having identical meanings, will be used interchangeably.
Referring to
This information is used to determine whether or not recovery of a database is performed when a mobile communication terminal (the database management system 100) is abnormally terminated and is booted again. Furthermore, preferably, a file for recovery backed up in the database recovery area 220 further include information on the total size of the database before a transaction begins, in addition to the serial number and the original image. A method of utilizing the total size information of a database will be explained later.
Referring to
However, in the process of performing this series of operations, if the mobile communication terminal cannot be terminated normally due to a cause, such as a power supply stoppage, a problem that the change is not successfully made, or that storing the change page is not successfully performed occurs. In this case, by using the data stored in the database recovery area 220, i.e., P1, and P2, the original images of the pages that are the objects of the change, data in the database storage area 210 is recovered in operation S10. In the present invention, whether or not to perform a recovery operation is determined by comparing the total number of pages stored in the database recovery area 220 with the serial number of the last page (i.e., file) of the database recovery area 220. If the transaction in relation to the database is normally finished, all the data in the database recovery area 220 is deleted. If the transaction is not normally terminated due to an occurrence of a problem, such as a power failure, in the middle of the execution of the transaction, a recovery process as illustrated in
According to the method of recovering data of a database illustrated in
Unlike this, if backup pages exist in the database recovery area 220, it means that the transaction is abnormally terminated due to a cause such as a power supply stoppage. In this case, a recovery procedure needs to be performed. In order to recover a database, the total number of pages (i.e., files) stored in the database recovery area 220 is compared with the serial number of the last page to determine whether or not the two values are identical in operation S26.
If the two information values compared in operation S26 are identical, with the backup pages stored in the database recovery area 220, corresponding pages stored in the database storage area 210 are replaced in operation S28. Since the original images of the pages before the change exist in the database recovery area 220 without being changed if the transaction is abnormally terminated, the state of the data before the change in the database storage area 210 can be recovered.
If the two information values compared in operation S26 are different to each other, all backup pages in the database recovery area 220 are deleted in operation S30. The reason for deleting all the backup pages is because it can be regarded that after the changed contents of the database were normally applied to the database storage area 210, a problem occurred in the process of deleting backup pages in the database recovery area 220.
Referring again to
(1) When an abnormal termination occurs after operation S1 is performed:
Even though the database recovery area 220 is examined in operation S22 when the mobile communication terminal is booted the next time after the abnormal termination, backup pages do not exist in the database recovery area 220 in this case. Accordingly, a recovery procedure is not needed.
(2) When an abnormal termination occurs after operations S2 through S6 are performed:
If the database recovery area 220 is examined in operation S22 when the mobile communication terminal is booted the next time after the abnormal termination, backup pages exist in the database recovery area 220. In this case, the serial number of the last page in the database recovery area 220 is compared with the total number of pages in the database recovery area 220 in operation S26. Since the two information values are identical according to the result of the comparison, by performing a rollback according to operation S28, the state before the change of the database files can be recovered.
(3) When an abnormal termination occurs after operation S7 is performed:
If the database recovery area 220 is examined in operation S22 when the mobile communication terminal is booted the next time after the abnormal termination, backup pages exist in the database recovery area 220. In this case, if the serial number of the last page in the database recovery area 220 is compared with the total number of pages in the database recovery area 220, it is confirmed that the two values are identical. Accordingly, by performing a rollback according to operation S28, the state before the change of the database files in the database storage area 210 can be recovered. If operation S7 was performed, the transaction may have been completed, but it cannot be confirmed that the transaction has been successfully completed. That is, since the memory buffer 230 is cleared after the rebooting, it cannot be confirmed that all pages that should be changed are correctly applied to the database storage area 210. Accordingly, it is safe that a recovery operation is tried by regarding all operations to operation S8 for deleting data in the database recovery area 220 as not completed.
(4) When an abnormal termination occurs after operation S8 is performed:
In the database recovery area 220, one backup page (P1) is deleted and the other backup page (P2) remains. Accordingly, when the mobile communication terminal is abnormally terminated and booted the next time, the serial number (‘2’ in
(5) When an abnormal termination occurs after operation S9 is performed:
Meanwhile, as described above, the total size information of the database before a transaction begins may be further included in the file for recovery backed up in the database recovery area 220, in addition to the serial number and the original image. The reason for further storing the total size information of the database is as follows. When necessary, the size of the database may increase due to the contents changed while the transaction is performed. For example, assuming that one page, P2, increases to two pages (P2′, and P2′), each page added at this time will have a page number greater than those of the pages existing previously. If an error occurs in this process and a recovery operation should be performed, there will be no original images of the added pages. In this case, by using the stored “database size before the transaction begins”, the original database size is recovered. Since no original images of the added pages exist, if pages having pages numbers, each greater than the “database size before the transaction begins”, are deleted, the “original database size” before the change can be recovered. Other changed contents in relation to the same transaction are recovered by using the original images stored in the database recovery area 220. If this process is performed, the original state before the change of the database in the database storage area 210 is completed recovered.
With an example of the mobile communication terminal employing a flash memory as a storage medium, optimum embodiments of the present invention have been explained above. However, it is apparent that variations and modifications by those skilled in the art can be effected within the spirit and scope of the present invention defined in the appended claims. For example, the present invention can be applied not only to the mobile communication terminal, but also to a variety of computing apparatuses employing an embedded system utilizing a flash memory as a storage medium, and employing a database management system. Therefore, all variations and modifications equivalent to the appended claims are within the scope of the present invention.
The method of recovering a database according to the present invention can guarantee a complete recovery of a database through a simple comparison of the total number of backup pages stored in a recovery area with a serial number even when the database using a flash file system of a mobile communication terminal is abnormally terminated by a cause such as a power supply stoppage. That is, if only the serial number of a backup file as information required for recovery, and, when, necessary, the total size information of the database before change are retained, a complete recovery can be guaranteed. Accordingly, the present invention requires a less memory space for recovery and enables a faster recovery.
Furthermore, if data in the header information among data stored in a recovery area is lost, a recovery according to the conventional recovery method cannot be performed. However, according to the recovery method of the present invention, information required for recovery is stored together in each backup page, without recording header information separately, such that even though a predetermined backup page is damaged, data can be completely recovered by using only information on the serial number of the last backup page. In addition, the cost of writing a file is reduced such that the execution speed is enhanced.
Number | Date | Country | Kind |
---|---|---|---|
10-2005-0018797 | Mar 2005 | KR | national |