Managing allocation of temporary and permanent files in a database system

A database system includes a plurality of access modules and corresponding persistent storage devices each having a pool of storage elements that can be allocated to store permanent files and temporary files. Each access module is associated with a non-persistent file management context and each storage device contains a persistent file management context. The persistent file management context indicates allocation of permanent files, while the non-persistent file management context indicates the allocation of both permanent and temporary files.

TECHNICAL FIELD

The invention relates to managing allocation of temporary and permanent files in a database system.

BACKGROUND

Database systems are used to collect and store various types of information that are later extracted for viewing or manipulation. Various different types of database systems exist, including relational database systems, object relational database systems, and others. Relational database systems store data in relational tables. When a query, such as a Structured Query Language (SQL) query is received, a subset of the data is extracted from one or more relational tables.

Many typical database systems divide data into different storage regions, such as system storage, permanent storage, and temporary storage. System storage contains data associated with the operation and configuration of the database system. Permanent storage typically is used to store user data. The storage is “permanent” in the sense that stored data remains in storage until deleted or modified by a request to delete or update the data. Temporary storage is typically used to store intermediate or final results of a query. The data in temporary storage is usually discarded after the query has completed so that the temporary storage can be used by other database operations.

The behavior of the database control logic differs when accessing data in the permanent and temporary storage regions. When accessing the permanent storage region, the database control logic usually acquires transaction locks to prevent one operation from interfering with another operation, logs data changes, and maintains context information to enable recovery of data if a system crash occurs. However, such tasks are usually not performed when accessing data in the temporary storage region.

To allow different treatment of the different storage regions, the database control logic may have to be separated for the different types of files. This allows the database control logic responsible for the temporary storage region to avoid some of the management overhead associated with the permanent storage region. However, the separation of the database control logic for temporary and permanent files creates other inefficiencies. For example, the storage space allocated for temporary storage may not be available for permanent storage, and vice versa.

SUMMARY

In general, a method for use in a database system having a persistent storage device and a non-persistent memory comprises storing a first file management context in the persistent storage device, and storing a second file management context in the non-persistent memory. Both the first and second file management contexts are updated to allocate a permanent file, and the second file management context is updated without updating the first file management context to allocate a temporary file.

DETAILED DESCRIPTION

FIG. 1illustrates one example embodiment of a database system10that is coupled to a client system12over a network14. Examples of the network14include a local area network (LAN), a wide area network (WAN), or a public network (such as the Internet). A user at the client system12can issue requests, such as Structured Query Language (SQL) requests, to the database system10to extract data stored in the database system10. SQL is the language of relational databases, and is defined by the American National Standards Institute (ANSI).

In the illustrated embodiment, the database system10includes multiple nodes16A and16B (two or more). In an alternative embodiment, the database system12can also be a single-node system. The nodes16A and16B are coupled by an interconnect network18, which is in turn connected to an interface system20. The interface system20includes a query coordinator21to receive queries from the client12, to parse the received requests, and to generate access requests to one or more data servers22A,22B in corresponding nodes16A,16B. Each node16A,16B includes respective one or more control units50A,50B that are coupled to a respective memory52A,52B, which can be main memory, a cache, or some other form of storage.

Each data server22A,22B controls access to a respective storage unit30A,30B. The data servers22A,22B can also be referred to as “access modules” for the storage units30A,30B. In one embodiment, the database system10is a relational database management system or an object relational database management system. User data34A,34B are contained in relational tables in respective storage units30A,30B. The storage units30A,30B also contain respective system tables32A,32B for storing system operational and configuration information. In addition, the storage units30A,30B contain temporary files36A,36B that are used to store intermediate or final results of database operations.

The user data34is stored in a permanent storage region of the storage unit30, while the temporary files36are stored in a temporary storage region of the storage unit30. The user data34are stored in “permanent” files. Such files are considered “permanent” in the sense that they are not lost in the event of system crashes, resets, or power cycles. However, permanent files can be changed or deleted by user requests during normal operation of the database system10. A “file” refers to any apportionment of data in the database system—for example, a file can refer to a row or column of a relational table or to some other apportionment.

In accordance with some embodiments of the invention, the permanent storage region and temporary storage region are part of the same pool of storage resources in each storage unit. For example, the pool of storage resources includes blocks or pages (generally referred to as “storage elements”) in the storage unit30.

By employing file management contexts in accordance with some embodiments, a block or a group of blocks can be selectively allocated to either permanent or temporary storage. Two groups of file management contexts are maintained: a first group38(referred to as “persistent file management context”) is stored in the storage unit30; and a second group26(referred to as “non-persistent file management context”) is stored in the memory52of each node16. The storage unit30in one embodiment is a persistent storage unit. A persistent storage unit maintains stored data even if power is removed from the database system or the database system is reset. However, the second group26is stored in a non-persistent storage unit, such as the memory52in the node16. Examples of the memory52include dynamic random access memories (DRAMs), static random access memories (SRAMs), and the like.

In one embodiment, the file management context in either persistent or non-persistent storage includes two maps: a first map to allocate storage identifiers for uniquely identifying each file created in the database system, and a second map to allocate allocation units, which are blocks or pages of storage in the storage units30A,30B. Each map contains flags that can be set to indicate allocation of a storage identifier or allocation unit. The flags can be released to indicate when a storage identifier or allocation unit has been released.

A file management context control routine or module23in each data server22is capable of accessing the file management context26through an application programming interface (API)24, which defines a collection of API calls. In one example embodiment, the API24defines the following methods that are invocable by the file management context control routine23: a method SET_STORAGE_ID( ) to allocate a temporary or permanent storage identifier; a method RELEASE_STORAGE_ID( ) to release a temporary or permanent storage identifier; a method SET_ALLOCATION_UNIT( ) to allocate blocks of storage; and a method RELEASE_ALLOCATION_UNIT( ) to release blocks of storage.

To access the storage units30A,30B, the data servers22A,22B issue requests to respective file systems28A,28B. The file systems28A,28B then generate commands to the storage units30A,30B to access data in the storage units30A,30B.

The database system10according to the arrangement ofFIG. 1is provided as an example only. In other embodiments, other arrangements of the database system can be utilized. For example, another database system is the Teradata database system from NCR Corporation. The Teradata database system includes a parsing engine that interprets SQL statements and controls the dispatch of requests to virtual access module processors (VAMPs) in one or more nodes. The VAMPs control extraction or manipulation of data stored in respective storage units.

FIG. 2illustrates one example of file management contexts stored in the database system10. The persistent version38of the file management context is stored in the persistent storage unit30, while the non-persistent version26of the file management context is stored in non-persistent storage52.

The persistent file management context38includes a STORAGE_ID map106(to allocate storage identifiers to permanent files) and an ALLOCATION_UNIT map108to allocate blocks or pages to permanent files). Each map106or108includes an array of flags that can be set to a “1” or “0” state. A “1” or active state indicates that a storage ID or an allocation unit has been allocated to a permanent file.

The non-persistent file management context26also includes a STORAGE_ID map110and an ALLOCATION_UNIT map112. Whereas the maps106and108in persistent storage are used to allocate storage IDs or allocation units to permanent files, the maps110and112are used to allocate storage IDs or allocation unit to both permanent and temporary files. The persistent maps106and108are subsets of respective non-persistent maps110and112. Each of the STORAGE_ID and ALLOCATION_UNIT maps110and112includes flags that can be set to a “1” or “0” state, with some of the flags corresponding to permanent files and others corresponding to temporary files.

Even though the same pool of storage elements are used to store both temporary and permanent files, the control logic in the data server22performs different management functions depending on whether a flag that is set in the STORAGE_ID or ALLOCATION_UNIT maps correspond to a temporary file or permanent file. For a permanent file, the control logic in the data server22performs transaction locking, logging of data changes made to the maps, and performs tasks to provide data consistency across restart boundaries. Allocation of a permanent file is indicated when the persistent STORAGE_ID map106or ALLOCATION_UNIT map108is updated. However, when a temporary file is allocated, and the non-persistent maps110and112are updated without updating the persistent maps106and108, the control logic in the data server22does not perform transaction locking, logging of data changes made to the maps, and performing tasks to provide data consistency across restart boundaries.

Storage capacity is made more efficient by combining the pool of storage elements to store both temporary and permanent files. At the same time management overhead is reduced by performing certain tasks only if permanent files are allocated.

FIG. 4illustrates how flags in the STORAGE_ID map106or110and in the ALLOCATION_UNIT map108or112correspond to storage blocks250. A first flag252in the ALLOCATION_UNIT map is set to the active “1” state, which allocates a storage block272(which is referred to as Allocation Unit1). Similarly, flags254and256in the ALLOCATION_UNIT map are set to active “1” states to allocate respective block274(referred to as Allocation Unit2) and block276(referred to as Allocation Unit X), respectively. Although the example shows one storage block per allocation unit, multiple storage blocks can be in one allocation unit. If multiple blocks are assigned to one allocation unit, then corresponding multiple flags in the ALLOCATION_UNIT map are set active. Flags262,264, and266in the STORAGE_ID map are set to the active “1” state to allocate storage identifiers to Allocation Units1,2, and X.

FIG. 3shows tasks performed by the data server22at system startup as they relate to the file management contexts26and38. The file management context control routine23in each node16that is starting up reads (at202) a persistent version of the STORAGE_ID map106contained in the storage unit30and loads (at204) the map into the memory52of the node16. The map loaded into the memory52is the non-persistent STORAGE_ID map110. The file management context routine23also reads (at206) the persistent version of the ALLOCATION_UNIT map108and loads (at208) the map into the memory52of the node16. This loaded map is the non-persistent ALLOCATION_UNIT map112.

In response to requests received from the query coordinator21, the data server22issues calls to the file management context control routine23to perform storage allocation. Each storage management call contains a flag that identifies the class of storage desired: temporary or permanent. As shown inFIG. 5, when the file management context control routine23receives (at302) a storage management call, it determines (at304) if the flag in the storage management call indicates a temporary file or a permanent file. If the flag indicates a temporary file, then the file management context routine23searches (at306) the in-memory or non-persistent STORAGE_ID map110to find a free storage identifier. The routine23then sets (at308) the corresponding bit in the non-persistent STORAGE_ID map to an active state. This is accomplished by calling the SET_STORAGE_ID( ) method in the API24(FIG. 1). Next, the routine23searches (at310) the non-persistent ALLOCATION_UNIT map112to find a free block or a group of free blocks. The corresponding bit(s) in the non-persistent ALLOCATION_UNIT map112are then set (at312) to the active state by calling the SET_ALLOCATION_UNIT( ) method. Plural bits are set if the allocation unit contains plural storage blocks.

For temporary files, only the non-persistent maps110and112are updated; the persistent106and108remain unchanged. When a temporary file is deleted, the API methods RELEASE_STORAGE_ID( ) and RELEASE_ALLOCATION_UNIT( ) are called to release flags (set the flags to the inactive state) in the maps110and112.

However, if the flag in the storage management call indicates a permanent file (as detected at304), then the file management context control routine23searches (at320) the non-persistent STORAGE_ID map110for a free storage identifier. The corresponding bit in the non-persistent STORAGE_ID map110is then set (at322) to an active state. In addition, the file management context control routine23also sets (at324) a corresponding bit in the persistent STORAGE_ID map106to an active state. Setting flags in the STORAGE_ID maps106and108are accomplished with respective calls of the SET_STORAGE_ID( )method.

Next, the routine23searches (at326) the non-persistent ALLOCATION_UNIT map112for a free block or a group of free blocks. The routine23then sets (at328) the corresponding bit(s) in the non-persistent ALLOCATION_UNIT map112to an active state. The corresponding bit in the persistent ALLOCATION_UNIT map108is also set (at330) in the persistent ALLOCATION_UNIT map to the active state. Setting flags in the ALLOCATION_UNIT maps are accomplished by calling the SET_ALLOCATION_UNIT( ) method.

In the operation discussed above, when the control logic in each data server22detects that the persistent maps106and108are updated (indicating that a permanent file is being allocated), the control logic performs transaction locking, data change logging, and other tasks to provide data consistency across restart boundaries. Such tasks are not performed when a temporary file is allocated.

The persistent maps106and108can be considered to be “shadows” of the non-persistent maps110and112. In the event of a system crash or reset, the persistent maps106and108are maintained in the persistent storage units30A,30B so that permanent files are not lost as a result of the system crash or reset. However, the non-persistent maps110and112are lost, which effectively erases any allocated temporary files.

The various software routines or modules discussed above are executable on corresponding one or more control units in the database system10. Each of the control units includes a microprocessor, a microcontroller, a processor card (including one or more microprocessors or microcontrollers), or other control or computing devices. As used here, a “controller” refers to hardware, software, or a combination of both. A “controller” can refer to a single component or to plural components (whether software or hardware).

The storage units or devices referred to herein include one or more machine-readable storage media for storing data and instructions. The storage media include different forms of memory including semiconductor memory devices such as dynamic or static random access memories (DRAMs or SRAMs), erasable and programmable read-only memories (EPROMs), electrically erasable and programmable read-only memories (EEPROMs) and flash memories; magnetic disks such as fixed, floppy and removable disks; other magnetic media including tape; and optical media such as compact disks (CDs) or digital video disks (DVDs). Instructions that make up the various software routines or modules are stored in respective storage units. The instructions when executed by a respective control unit cause the corresponding system to perform programmed acts.

The instructions of the software routines or modules are loaded or transported to each system in one of many different ways. For example, code segments including instructions stored on floppy disks, CD or DVD media, a hard disk, or transported through a network interface card, modem, or other interface device are loaded into the system and executed as corresponding software routines or modules. In the loading or transport process, data signals that are embodied in carrier waves (transmitted over telephone lines, network lines, wireless links, cables, and the like) communicate the code segments, including instructions, to the system. Such carrier waves are in the form of electrical, optical, acoustical, electromagnetic, or other types of signals.