|
Claims  |
|
|
We claim:
1. In a data processing system a method executed by a data processor for
fetching a selected key record in a group of record keys by utilizing a
portion of a key record through an index tree having a modifiable
structure during a transaction in said data processing system wherein
other transactions may concurrently modify the structure of said index
tree, said index tree having at least a root node, each root node having a
key record reference to one or more nodes in a next lower ordered level
and having bottom nodes that provide access to said key record data in an
ordered sequence of key records, said method comprising the steps
performed within said data processing system of:
traversing across said nodes within said data processing system from said
root node by using key record reference until an appropriate bottom node
is reached;
identifying said selected key record in said bottom node;
requesting a conditional access restriction on said selected key record;
fetching said selected key record if said conditional access restriction is
granted;
requesting an unconditional access restriction of said selected key record
if said conditional access restriction is not granted;
examining said appropriate bottom node after said unconditional access
restriction is granted to determine whether or note said appropriate
bottom node has been substantially altered;
fetching said selected key record is said appropriate bottom node has not
been substantially altered; and
traversing across said nodes from said root node by using said key record
reference until a second appropriate bottom node is reached if said
appropriate bottom node has been substantially altered.
2. The method according to claim 1, wherein said step of examining said
appropriate bottom node after said unconditional access restriction has
been granted to determine whether or not said appropriate bottom node has
been substantially altered further includes the step of determining
whether or not said selected key record is a first key record in said
ordered sequence of key records within said appropriate bottom node.
3. The method of according to claim 1, wherein said step of examining said
appropriate bottom node after said unconditional access restriction is
granted to determine whether or not said appropriate bottom node has been
substantially altered further includes the step of determining whether or
not a next lower key record in said ordered sequence of key records within
said appropriate bottom node is lower than said selected key record.
4. The method according to claim 1, wherein said step of examining said
appropriate bottom node after said unconditional access restriction is
granted to determine whether or not said appropriate bottom node has been
substantially altered further includes the step of determining whether or
not a key record exists in said appropriate bottom node which is lower
than said selected key record.
5. In a data processing system a method executed by a data processor for
inserting a single key record in a group of record keys according to a key
record through an index tree having a modifiable structure during a
transaction in said data processing system wherein other transactions may
concurrently modify the structure of said index tree, said index tree
having at least a root node, each root node having a key record reference
to one or more nodes in a next lower ordered level and having bottom nodes
that provide access to an ordered sequence of key records, said method
comprising the steps performed within said data processing system of:
traversing across said nodes within said data processing system from said
root node by using said key record reference until an appropriate bottom
node is reached;
identifying a next higher key record than the single key record to be
inserted;
requesting a conditional access restriction on said next higher key record;
inserting said single key record into said appropriate bottom node if said
conditional access restriction is granted;
requesting an unconditional access restriction on said next higher key
record if said conditional access restriction is not granted;
examining said appropriate bottom node after said unconditional access
restriction is granted to determine whether or not said appropriate bottom
node has been substantially altered;
inserting said single key record into said appropriate bottom node if said
appropriate bottom node has not been substantially altered; and
traversing across said node from said root node by using said key record
reference until a second appropriate bottom node is reached if said
appropriate bottom node has been substantially altered.
6. The method according to claim 5, wherein said step of examining said
appropriate bottom node after said unconditional access restriction is
granted further includes the step of determining whether said single key
record is bounded on said appropriate bottom node.
7. The method according to claim 5, wherein said step of examining said
appropriate bottom node after said unconditional access restriction is
granted further includes the step of determining whether said appropriate
bottom node is participating in a structure modification operation which
is not yet complete.
8. In a data processing system a method executed by a data processor for
deleting a single key record in a group of record keys according to a key
record through an index tree having a modifiable structure during a
transaction in said data processing system wherein other transactions may
concurrently modify the structure of said index tree, said index tree
having at least a root node, each root node having a key record reference
to one or more nodes in a next lower ordered level and having bottom nodes
that provide access to an ordered sequence of record keys, said method
comprising the steps performed within said data processing system of:
traversing said nodes within said data processing system from said root
node by using said key record reference until an appropriate bottom node
is reached;
requesting a conditional access restriction on a next higher key record
than the single key record to be deleted;
deleting said single key record from said appropriate bottom node if said
conditional access restriction is granted;
requesting an unconditional access restriction on said next higher key
record if said conditional access restriction is not granted;
examining said appropriate bottom node after said unconditional access
restriction is granted to determine whether or not said appropriate bottom
node has been substantially altered;
deleting said single key record from said appropriate bottom node if said
appropriate bottom node has not been substantially altered; and
traversing across said nodes from said root node by using said key record
reference until a second appropriate bottom node is reached if said
appropriate bottom node has been substantially altered.
9. The method according to claim 8, wherein said step of examining said
appropriate bottom node after said unconditional access restriction is
granted further includes the step of determining whether said appropriate
bottom node is participating in a structure modification operation which
is not yet complete.
10. A data processing system for fetching a selected key record in a group
of record keys by utilizing a portion of a key record through an index
tree having a modifiable structure during a transaction in said data
processing system wherein other transactions may concurrently modify the
structure of said index tree, said index tree having at least a root node,
each root node having a key record reference to one or more nodes in a
next lower ordered level and having bottom nodes that provide access to
said key record data in an ordered sequence of key records, said data
processing system comprising:
means for traversing across said nodes within said data processing system
from said root node by using said key record reference until an
appropriate bottom node is reached;
means for identifying said selected key record in said bottom node;
means for requesting a conditional access restriction on said selected key
record;
means for fetching said selected key record if said conditional access
restriction is granted;
means for requesting an unconditional access restriction of said selected
key record if said conditional access restriction is not granted;
means for examining said appropriate bottom node after said unconditional
access restriction is granted to determine whether or not said appropriate
bottom node has been substantially altered;
means for fetching said selected key record if said appropriate bottom node
has not been substantially altered; and
means for traversing across said nodes from said root node by using said
key record reference until a second appropriate bottom node is reached if
said appropriate bottom node has been substantially altered.
11. The data processing system according to claim 10, wherein said means
for examining said appropriate bottom node after said unconditional access
restriction has been granted to determine whether or not said appropriate
bottom node has been substantially altered further includes means for
determining whether or not said selected key record is a first key record
in said ordered sequence of key records within said appropriate bottom
node.
12. The data processing system according to claim 10, wherein said means
for examining said appropriate bottom node after said unconditional access
restriction is granted to determine whether or not said appropriate bottom
node has been substantially altered further includes means for determining
whether or not a next lower key record in said ordered sequence of key
records within said appropriate bottom node is lower than said selected
key record.
13. The data processing system according to claim 10, wherein said means
for examining said appropriate bottom node after said unconditional access
restriction is granted to determine whether or not said appropriate bottom
node has been substantially altered further includes means for determining
whether or not a key record exists in said appropriate bottom node which
is lower than said selected key record.
14. A data processing system for inserting a single key record in a group
of record keys according to a key record through an index tree having a
modifiable structure during a transaction in said data processing system
wherein other transactions may concurrently modify the structure of said
index tree, said index tree having at least a root node, each root node
having a key record reference to one or more nodes in a next lowered
ordered level and having bottom nodes that provide access to an ordered
sequence of key records, said data processing system comprising:
means for traversing across said nodes within said data processing system
from said root node by using said key record reference until an
appropriate bottom node is reached;
means for identifying a next higher key record than the single key record
to be inserted;
means for requesting a conditional access restriction on said next higher
key record;
means for inserting said single key record into said appropriate bottom
node if said conditional access restriction is granted;
means for requesting an unconditional access restriction on said next
higher key record if said conditional access restriction is not granted;
means for examining said appropriate bottom node after said unconditional
access restriction is granted to determine whether or not said appropriate
bottom node has been substantially altered;
means for inserting said single key record into said appropriate bottom
node if said appropriate bottom node has not been substantially altered;
and
means for traversing across said node from said root node by using said key
record reference until a second appropriate bottom node is reached if said
appropriate bottom node has been substantially altered.
15. The data processing system according to claim 14, wherein said means
for examining said appropriate bottom node after said unconditional access
restriction is granted further includes means for determining whether said
single key record is bounded on said appropriate bottom node.
16. The data processing system according to claim 14, wherein said means
for examining said appropriate bottom node after said unconditional access
restriction is granted further includes means for determining whether said
appropriate bottom node is participating in a structure modification
operation which is not yet complete.
17. A data processing system for deleting a single key record in a group of
record keys according to a key record through an index tree having a
modifiable structure during a transaction in said data processing system
wherein other transactions may concurrently modify the structure of said
index tree, said index tree having at least a root node, each root node
having a key record reference to one or more nodes in a next lower ordered
level and having bottom nodes that provide access to an ordered sequence
of record keys, said data processing system comprising:
means for traversing said nodes within said data processing system from
said root node by using said key record reference until an appropriate
bottom node is reached;
means for requesting a conditional access restriction on a next higher key
record than the single key record to be deleted;
means for deleting said single key record from said appropriate bottom node
if said conditional access restriction is granted;
means for requesting an unconditional access restriction on said next
higher key record if said conditional access restriction is not granted;
means for examining said appropriate bottom node after said unconditional
access restriction is granted to determine whether or not said appropriate
bottom node has been substantially altered;
means for deleting said single key record from said appropriate bottom node
if said appropriate bottom node has not been substantially altered; and
means for traversing across said nodes from said root node by using said
key record reference until a second appropriate bottom node is reached if
said appropriate bottom node has been substantially altered.
18. A data processing system according to claim 17, wherein said means for
examining said appropriate bottom node after said unconditional access
restriction is granted further includes means for determining whether said
appropriate bottom node is participating in a structure modification
operation which is not yet complete. |
|
|
|
|
Claims  |
|
|
Description  |
|
|
BACKGROUND OF THE INVENTION
1. Technical Field
This invention relates in general to data processing methods and devices
and more specifically in its illustrated embodiment to a method and
apparatus for database management of records.
2. Background Art
Database management or transaction processing systems are well known in the
prior art. These systems are generally utilized to provide rapid access to
database tables which contain a plurality of data records. A relational
transaction processing system provides access to multiple database tables
where elements of one database table are generally related to elements in
another database table. A relational database allows a user to search,
access, and alter data contained in multiple database tables using one or
more specific elements or fields.
One important aspect of all such database systems is the ability of the
system to provide rapid and efficient access to individual records in each
database. Recently, database management systems have been provided which
support the utilization of the database by multiple users simultaneously,
allowing users to access specific data concurrently.
An index file is commonly used by database management programs to provide
quick and efficient access to records in tables. These index files are
commonly configured in a B-Tree structure. A reference that discusses the
B-Tree is "Efficient Locking For Concurrent Operation on B-Tree" by Lehman
and Yao, ACM Transactions on Database Systems, volume 6, number 4,
December, 1981, pages 650-670. Other references addressing B-Tree
structures include "The Ubiquitous B-Tree" by Comer, Computing Surveys,
volume 11, number 2, June, 1979, pages 121-137; and "Concurrent Operation
on B-Trees with Over Taking" by Sagiv, Proceedings ACM SIGACT-SIGMOD
Symposium on Principles of Database Systems, March, 1985, pages 28-37.
The index file configured as a B-Tree structure consists of a root node
with many levels of nodes branching from the root node. The information
contained in these nodes include pointers to the nodes at the next level
or pointers to records in the database. These pointers include further
information termed key record information which may reference the records
in the database. The record keys are in an ordered form throughout the
nodes. For example, an index tree may exist for an alphabetic listing of
employee names. The root node would include reference keyed data that
relates to records indirectly or directly referenced by the next level of
nodes. The reference keys contain information about the index filed, i.e.
the alphabetic . spelling of employees name. Therefore, the ordered keys
in the root node would point to the next successive level of nodes. In
other words, the next successive node may indirectly or directly reference
all employees names beginning with A, B, and C. A next successive node,
parallel with the first successive node, may contain employee records
whose last name begins with the letters D-M. The last successive node on
this level would reference records of employees with last names starting
with N-Z. As one searches through the index file tree, a bottom node is
eventually reached. The contents of the bottom node include record keys
that point to the individual records in storage.
One problem in providing concurrent accesses to database tables occurs when
multiple transactions are trying to access a record at the same time.
Specifically, when one user wishes to change a record and another user is
attempting to access this record, a contention situation occurs. One
solution to the contention problem is to provide exclusive access (or
locking) to the records or to the portions of the B-Tree indexes to ensure
that the index node, or record is not changed while the user is attempting
to access it. Locking is addressed in "Index Locking and Splitting", IBM
Technical Disclosure Bulletin, volume 25, number 7B, December, 1982, pages
3725-3729; and "Locking Protocols for Concurrent Operations on B-Trees",
IBM Technical Disclosure Bulletin, volume 19, number 10, March, 1977,
pages 3887-3889. The disadvantage of a locking solution is that a lock,
while providing access to one user, prevents access by any other user. It
should therefore be apparent to those skilled in the art that by
minimizing the number of locks utilized it will be possible to enhance the
concurrency of a system.
Another important aspect of data processing systems is the capability of
such systems to make changes to the data contained within the database in
a recoverable manner. That is, these systems ensure that either all of the
changes entered by a particular user persists or none of the changes
persist in the event the operation of the system is interrupted by
failures of various components. Similarly, the user also is given the
ability to request that changes the user has made to the database be
reversed until a particular point in time has been reached. Thus, the
users' changes to the database are said to be "recoverable." This concept
is incorporated into database systems which operate in a "transaction"
processing manner. A transaction is a logical unit of work comprised of a
sequence of operations which transforms a first consistent state of a
recoverable database resource into another consistent state without
necessarily preserving consistency at all intermediate points in the
sequence. The utilization of a transaction processing system will
guarantee that if a transaction executes certain updates against a
recoverable database resource, and a failure occurs before the transaction
reaches its normal termination or an interim point of consistency, then
those updates will be undone.
Since a transaction includes the execution of an application-specified
sequence of operations, its existence in the system is generally initiated
with a special "BEGIN WORK" operation and ends with either a "COMMIT" or
an "ABORT". The COMMIT and ABORT operations previously described provide
atomicity in the system in that the COMMIT operation signifies that a new
point of consistency has been reached and all updates made by the
transaction involved must be made permanent. The ABORT operation signifies
that a fault has occurred and that any changes made by the particular
transaction involved must be "rolled back" or undone, and the recoverable
database resources returned to the prior point of consistency.
In order to permit this transaction recovery guarantee, the database system
must be able to remember across system outages those transactions which
were in progress and the state of their update actions so that the effect
of those actions on recoverable data may be properly reflected when the
system is restarted. This is accomplished by recording in a log stored on
stable storage the progress of each transaction from its beginning to its
end, and those actions which cause changes to recoverable data resources.
This log then becomes a source for ensuring that the transaction's
committed actions are reflected, or that its uncommitted actions are
reversed to ensure that the database stays consistent. When the log of
transaction operations reflects data object content these log records also
become the source for reconstruction of damaged or lost data. These
systems generally assign each log record a unique log sequence number
(LSN) at the time the record is written into the log. Such LSNs are
generally assigned in an ascending numerical sequence. Upon the completion
of the logging of an update to a page of memory in the database the LSN of
the log record corresponding to the update is also typically stored on
that page.
The type of system described above is generally referred to as a log
write-ahead system. A log write-ahead system requires that a log entry
corresponding to a particular operation must by physically written to
stable storage before new versions of the changed data replace the earlier
versions of the data on non-volatile storage. Stable storage, as described
herein means non-volatile storage which remains intact and available
across system failures. One such example is the utilization of a magnetic
storage disk. Additionally, such systems store transaction status in the
log and no transaction may be considered complete until its committed
status and all of its log data is safely recorded on stable storage. Thus,
in the event of a system failure, a restart procedure will recover any
operations within the transaction which were completed successfully but
did not manage to get their updated resources physically written to stable
storage prior to the system failure. Further, such systems do not permit a
transaction to complete COMMIT processing until all portions of all log
records for the transaction have been written to the physical log.
SUMMARY OF THE INVENTION
It is therefore one object of the present invention to provide a more
efficient method of accessing records in a database through an index tree.
It is another object of the present invention to provide a more efficient
method of accessing records in a database through an index tree while
providing more efficient concurrent access by multiple users to the
database.
It is yet another object of the present invention to provide a more
efficient method of accessing records in a database through an index tree
which permits data to be accessed without having to traverse the tree a
second time in the event of a delay in access due to a structure
modification to the tree.
The foregoing objects are achieved as is now described. A method and
apparatus are provided for concurrent modifications of an index tree in a
transaction processing system. The index tree includes at least one root
node having a key record reference to one or more nodes in a next lower
ordered level and at least one bottom node providing access to key
records. Transactions including a structure modification operation are
performed by traversing the index tree to the selected node and then
setting an indication of the pendency of a structure modification
operation. Concurrent key record inserts or deletes are permitted
throughout the index tree where no indication of a pending structure
modification operation is present and are delayed where a pending
structure modification operation is indicated. Similarly, transactions
which include a key record delete may require a structure modification
operation in the event the transaction does not reach a new point of
consistency and must be undone. Therefore, an indication of each key
record delete which has not yet reached a new point of consistency is set
and concurrent key record inserts are also delayed until the possibility
of a structure modification operation is completed. Once a structure
modification operation is complete, a log record is written which will
prevent the undoing of the structure modification operation in the event
of a system failure, whether or not the transaction containing the
structure modification operation has reached a new point of consistency.
In one preferred mode of the present invention, the local node is
researched after a delay to determine if key insertion or deletion is
possible without the necessity of traversing the tree a second time.
BRIEF DESCRIPTION OF THE DRAWINGS
The novel features believed characteristic of the invention are set forth
in the appended claims. The invention itself, however, as well as a
preferred mode of use, further objects and advantages thereof, will best
be understood by reference to the following detailed description of an
illustrative embodiment when read .in conjunction with the accompanying
drawings, wherein:
FIG. 1 is a block diagram of a concurrent access database system in
accordance with the present invention;
FIG. 2 is a logic flow chart illustrating an initial search operation
through a database in accordance with the present invention;
FIG. 3 is a logic flow diagram illustrating a fetch operation through a
database in accordance with the present invention;
FIGS. 4A and 4B when placed together form a logic flow chart illustrating
an insert operation through a database in accordance with the present
invention;
FIGS. 5A and 5B when placed together form a logic flow chart illustrating a
delete operation through a database in accordance with the present
invention;
FIG. 6 is a logic flow chart illustrating an UNDO operation of a key record
insert through a database in accordance with the present invention;
FIG. 7 is a logic flow diagram illustrating an NDO of a key record delete
through a database in accordance with the present invention;
FIG. 8 is a logic flow chart illustrating a node splitting algorithm in
accordance with the present invention; and
FIG. 9 is a logic flow chart illustrating a node collapsing algorithm in
accordance with the present invention.
DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENT
With reference now to the Figures and in particular with reference to FIG.
1, there is depicted a block diagram of a concurrent access database
system in accordance with the present invention. As can be seen, the
concurrent access database system includes a plurality of interactive work
stations 10 (IWS), which are all coupled to a host processor 12. Host
processor 12 is then coupled to database 14. Those skilled in the art will
appreciate that while this particular embodiment is disclosed, a similar
system comprised of individual computers coupled via a local area network
may also be utilized. As can be seen, each operator of an interactive work
station 10 may search, access, or alter records contained within database
14 by means of a database management system which is typically embodied
within the host processor 12. Those skilled in this art will appreciate
that database 14 is typically provided by utilizing index files, which are
commonly configured in a B-Tree structure as discussed above. A typical
B-Tree structure consists of at least one root node with multiple levels
of nodes branching from the root node. The information contained in each
node includes pointers to nodes at the next lower level or pointers to
records which are contained in the database at the lowest level of nodes,
often referred to as leaf nodes.
With reference now to FIG. 2, there is depicted a logic flow chart which
illustrates an initial search operation through a database in accordance
with the present invention. As can be seen, the access program begins at
step 100 and proceeds to step 102 where the index root node is S-latched
and accessed. An S-latch provides limited access to other concurrent
users. This limited access provides the other users with the capability to
access and read the information contained within the node. No other
access, such as the capability to delete or change, is provided. The index
root node identifies the type of index and provides the initial direction
for accessing a record in this example. For example, the index root node
could identify the index as an alphabetical index in ascending order for a
plurality of names. In step 103, the child node to be accessed would be
identified according to the information in the parent node. As illustrated
in step 104, it is next determined whether or not the operation to be
performed is a fetch operation. If the operation is not a fetch operation,
that is, the operation is a record insert (or key record insert), or a
record delete (or key record delete) operation, the access program then
proceeds to step 106 to determine if the next node beneath the parent node
is a bottom node or a "leaf node". If the next node is a leaf node, the
program proceeds to step- 110 and acquires an X-latch on the child node.
The X-latch is an exclusive latch which excludes all other accesses to
this particular node. By applying an X-latch to the node in question the
program prohibits all other transactions from accessing this particular
node.
Returning to step 104, if the operation is a fetch operation or, returning
to step 106, if the child is not a leaf node, the access program proceeds
to step 108 to acquire an S-latch on the child node. The access program
then proceeds to step 112 wherein it determines whether or not the key of
the record being searched is greater than the highest key in the child
node. Of course, those skilled in the art will appreciate that in the
event the search enters an empty node then the key being searched will
automatically be construed as greater than the highest key in the child
node. If the key record being searched is greater than the highest key
present in the child node, the program proceeds to step 114 to determine
if the tree index structure is latched. If the tree is not latched, the
program proceeds to step 118 where the parent and child nodes are
unlatched and the tree is latched. The access program then proceeds from
step 118 back to step 102 to reinitiate the operation upon the granting of
the tree latch. Those skilled in the art should appreciate that
optimizations are possible to reduce the number of nodes which must be
accessed when the operation is re-attempted.
In this example, an X-latch on a tree is provided to indicate to all other
accesses that a change in the tree structure is being made. If a tree
X-latch access is in progress when a latch is attempted on the tree, the
attempting access must wait until the earlier access has been completed.
An S-latch on the tree is provided to indicate all other accesses that no
structural changes are being made, but other accesses may concurrently
access the index tree. No other changes may occur until the S-latch is
released. Tree traversal may occur regardless of the existence of
S-latches or X-latches. These tree traversals may include key record
deletions or insertions.
In step 114, if the tree has been latched, or in step 112 if the key is not
greater than the highest key contained within the child node, the program
proceeds to step 116 to determine if the child node is a leaf node. If the
child node is not, the program proceeds to step 115 to unlatch the parent
node and then returns to step 103. However, if the child node is a leaf
node, the program proceeds to step 120 to unlatch the parent and then to
steps 122, 124 and 126 to determine if the operation is a fetch, an
insert, or a delete operation. In the depicted embodiment, if none of
these three operations are attempted, the program will return to the user
as illustrated in step 130. In actual practice, this return would include
an error message signifying that the operation to be performed is not
identifiable by this program.
If the operation to be performed is a fetch operation, then the access
program proceeds to step 200 of FIG. 3 wherein a logic flow chart is
depicted which illustrates a fetch operation through a database in
accordance with the present invention. In step 200 of FIG. 3, the program
finds the requested key being searched or the next higher key in the
database. In step 202, the program then requests a conditional lock on the
key record found. In the depicted example, a conditional lock is requested
from a database management program which manages the locks on the record
keys. The term "conditional" means that if the lock is not immediately
granted, a response will be provided to the requesting accessor indicating
that such a lock is not being granted. This response is utilized to make
the decision depicted in step 204. If the lock has not been granted, the
program proceeds to step 206 to unlatch the child node and then to step
208 to request an unconditional lock on the key record. The request for an
unconditional lock, as illustrated in step 208, requires that the accessor
wait until such lock is granted before proceeding. Once the lock has been
granted, the program next relatches the child node in step 214 and
determines whether or not the node has changed in step 216. This
examination of the node in step 216 is referred to herein as "local
research" and is utilized to enhance the efficiency of the system depicted
by permitting the program to proceed again from the local node rather than
traverse through the tree a second time if the node has not been
substantially altered. This may be determined, for example, by comparing
t | | |