A database management system

Abstract: A database management system comprises a plurality of sites having a computer, a database and a clock. The plurality of sites are interconnectad by a communication line. The database stores a plurality of data for processing. When a transaction request is generated in a site, the transaction management section of the computer in the site examines which database includes necessary data for executing the transaction. Maximum delay decision section determines maximum delay to send an instruction to the site having the database examined. Locktime decision section determines locktime according to the maxmum delay determined and the current time of the clock. Then, the transaction management section sends the locktime as a lock instruction to the site having the database examined through the communication line. A scheduler section receives the lock instruction sent by the transaction managemant section. A lock activation section activates the scheduler section when the locktime coincides with the current time of the clock. The scheduler section locks the necessary data in the database in response to activation by the lock activation section.

Description: The present invention relates to a database management system for locking data in a plurality of databases during the execution of a transaction. A plurality of computers can be arranged in a distributed database system, each computer having a database. The plurality of computers are interconnected by communication lines. Each computer manages its own database (computer and associated own database are called "site" herein). When a site is supplied with a data processing request through an input device, the computer in the site checks which database includes the necessary data for the requested processing, by referring to a table of stored data names and corresponding locations. If the data is included in the site's own database, the computer reads the data from this database, executes the data processing program and writes the result into the database (a series of such processes is called a "transaction"). If some data is included not only in the site's own database but also in a database of a second site, the computer sends the processing request to the second site, the database of which includes the data. The computer at the second site then reads the data from its database, executes the data processing at its site and writes the data processing result to its database, according to the processing request. In such cases, during processing of the transaction by using the data in the database, other computers at other sites must not access the same data to execute the other transaction. If the other computer accesses the same data, the resultant data in the database will be inconsistent. For example, Figure 1 shows an example of two computers attempting to access the same data item. For instance assume the site is the branch of a bank and its database stores the deposit balance. When the site receives money from the user, a transaction takes place. The deposit balance is read from user's account, the received money is added to the deposit balance and the result is written to his account. Assume that the database of site A stores the user X's deposit balance of $50 and a deposit of $100 is received at site A deposited by user X (this transaction is called Ta). Immediately thereafter, assume that another site B receives $30 for user X's account deposited by user Y (this transaction is called Tb). First the computer at site A executes READ (Ta). As user X's deposit balance is $50, the computer adds the received $100 to $50 and writes $150 as being the current balance. (WRITE (Ta)). However, the computer at site B executes READ (Tb) before WRITE (Ta). The computer at site B reads user X's deposit balance of $50 through the communication line. Then, the site B computer adds the $30 received to $50 and writes $80 in user X's account as the balance (WRITE (Tb)). Therefore, user X's deposit balance will be $80. However, actually user X's deposit balance should be $180. Therefore, in the prior art, a lock method is used to prevent occurrence of this type of problem. According to this method, before the computer at site A executes READ(Ta), the computer at site A sets a flag corresponding to user X's account in database A. This flag prohibits access by other computers. When the computer at site A finishes WRITE (Ta), the computer of site A resets the flag corresponding to user X's account in database A. Therefore, during the execution of transaction (Ta), the computer at site B delays executing transaction (Tb) because a flag corresponding to user X's account is set. After the flag is reset by the computer at site A, the computer at site B executes transaction (Tb). The lock method prevents generating incorrect data. However, in the lock method, a so-called dead lock between a plurality of transactions can occur. Figure 2A, 2B, 2C and 2D show an example of how dead lock between two transactions can occur. It is assumed that transaction A begins to lock other transaction out from two data i and j; transaction B also begins to lock out other transactions from the two data i and j, too. The lock operation is executed as follows. (1) transaction A locks data item i (Fig. 2A) (2) transaction B locks data item j (Fig. 2B) (3) transaction A tries to lock data item j, but must wait until data item j is released (Fig. 2C). (4) transaction B tries to lock data item i, but must wait until data item i is released (Fig. 2D). When both transactions A and B must wait until a required data item is released by the other transaction, as in this example, dead lock occurs. In this case, the cause of the dead lock is that transaction B has locked data item j before transaction A was able to lock data item j. However, if only one of transactions A and B locks both data items i and j at the same time, such a dead lock between transactions will not happen. When the first transaction releases data items i and j, the other transactions can lock both data items i and j. In short, dead lock does not occur. In such a case, two possible sequences can occur. Figure 3A shows the first sequence as follows: (1) transaction A locks out other transactions from data items i and j at the same time. (2) transactions B tries to lock out data items i and j, but must wait until transaction A releases data items i and j. Figure 3B shows the second sequence as follows: (1) transaction B locks out other transactions from data items i and j at the same time. (2) transaction A tries to lock out data items i and j, but must wait until transaction B releases data items i and j. In these two situations, one transaction gains exclusive access to both data items i and j. Therefore, the transaction finishes before the two data items i and j are released. Only then can the other transaction gain access to both data items i and j. However, in a distributed database system, the locking procedure is executed through communication lines between databases. For example, it is assumed that data items i and j are included in databases A and B respectively, site A includes computer A and database A, site B includes computer B and database B. Accordingly, transaction of computer A locks out other transactions from data items j in database B later than when transaction of computer A locks data item i in database A because there is a communication delay between computer A and database B. Likewise, when transaction of computer B locks data item i in database A later than when transaction of computer B locks data item j in database B because there is communication delay between computer B and database A. Therefore, in prior art data base management systems, it is difficult for a transaction to lock out the other transactions from plural data items in distributed databases at the same time. The paper "An Analysis of the Effect of Multiversions on the Performance of Timestamp Algorithms", IEEE Journal on Selected Areas in communications Vol. 7, No. 3, April 1989 describes a study of the performance of multiversion conservative timestamp algorithms in distributed database systems, in which data is retrieved in an order determined by timestamps associated with each transaction. It is an object of the present invention to provide a database management system for effectively locking out plural data items in distributed databases using a timestamp method which provides improved performance. Accordingly the present invention provides a database management system, comprising: a plurality of sites respectively having a computer, a database and a clock; communication means for interconnecting the plurality of sites to send instructions between the sites; wherein the respective databases store data for processing, and each computer includes: transaction generation means for generating a transaction, and transaction management means for determining which databases include data required for executing the transaction generated by the transaction generation means and therefore which sites will be involved in the transaction; characterised by: maximum delay decision means for selecting the maximum delay time required to send a lock instruction to all these sites having; locktime decision means for determining a locktime according to the maximum delay time and current time of the clock, wherein the transaction management means sends the locktime as the lock instruction to the said sites; scheduler means for receiving a lock instruction sent by the transaction management means of another site through the communication means; and lock activation means for activating the scheduler means when the locktime of the received lock instruction coincides with the current time of the clock, wherein the scheduler means locks the necessary data in the database in response to activation by the lock activation means. Figure 1 shows an example of two transactions which require accessing one database according to the prior art; Figures 2a, 2b, 2c and 2d show an example of dead lock between two computers attempting to process two transactions; Figure 3a and 3b show examples which avoid dead lock between two transactions; Figure 4 shows a block diagram of a single site of the database management system according to the present invention; Figure 5a shows examples of data construction of a transaction; Figure 5b shows an example of construction of a lock instruction; Figure 5c shows an example of data construction of database and queue; Figure 6 shows a block diagram of the database management system according to the present invention (each site is in accordance with Fig. 4 although for convenience not all pairs are shown); Figure 7 shows a flow chart of processing of the transaction management section of the database management system according to the present invention; and Figure 8 shows a flow chart for the processing of the scheduler section of the database management system according to the present invention. Figure 4 shows a block diagram of a site of the database management system according to the present invention. Each site has a computer 12 and a database 15. Each computer consists of a transaction generation section 1, a transaction management section 3, a transaction execution section 4, a maximum delay decision section 5, a locktime decision section 7, a scheduler section 9, a lock activation section 11, a clock 13 and a queue 14. In a plurality of the sites, the site where the transaction is generated through the transaction generation section 1 is called the "main site". The transaction generation section 1 is an input device such as a keyboard, and the user supplies the transaction request through the transaction generation section 1. The transaction management section 3 analyzes the transaction request and checks which database includes the data necessary for executing the transaction. Then, the transaction management section 3 generates the data structure of the transaction. Figure 5a shows data construction of the transaction. In this case, user X's account is stored in database A of site A (main site). He orders a transfer of money from his account to user Y's account stored in database B of site B. Two transactions are necessary for user X's order. Transaction (Tx) is to subtract $100 from user X's account in database A. Transaction (Ty) is to add $100 to user Y's account in database B. In this case, transaction execution section 4 of site A executes transaction (Tx) and transaction management section 4 of site A sends transaction (Ty) to site B. Therefore, in advance of the processing of the transactions, user X's account in database A and user Y's account in database B must be locked. The transaction management section 3 identifies and supplies the database name in which the necessary data is stored to the maximum delay decision section 5. The maximum delay decision section 5 has previously stored the respective delay times required to send instructions to each site in the database management system. Therefore, section 5 selects the delay time corresponding to the site name supplied by the transaction management section 3. If more than one site is involved and data must be obtained from two or more databases, other than at the main site, the maximum delay decision section will select the maximum delay time from among the delay times for each site. Next, the maximum delay decision section 5 supplies the maximum delay time to the locktime decision section 7. The locktime decision section 7 includes a current time register which always has the current time of clock 13. (The current time register is not disclosed in Figure 4.). Furthermore, the locktime decision section 7 previously stores error time of clock between the main site and the other sites. The locktime decision section 7 adds the maximum delay and the error time to the current time. This sum of time is called "locktime". Then the locktime decision section 7 supplies the locktime to the transaction management section 3. The transaction management section 3 generates lock instruction by using the locktime. Figure 5b shows the data construction of the lock instruction. The lock instruction means that the site, which receives the lock instruction, must lock the data item corresponding to the address at the locktime. The transaction management section 3 also sends the lock instruction to other sites having the data necessary for executing the transaction. Each site includes a scheduler section 9 which receives the lock instruction which is sent by the transaction management section of another site through the communication line. In the alternative, the lock instruction can be sent by the transaction management section of its own site. When the scheduler section 9 receives the lock instruction, the schedule section 9 sends the locktime of the lock instruction to the lock activation section 11. The lock activation section 11 compares the locktime with the current time of clock 13. When the locktime coincides with the current time of clock 13, the lock activation section 11 sends an activation signal to the scheduler section 9. At that time, the scheduler section 9 locks the data item corresponding to the address of the lock instruction in database 15. If the data item is free (in short, the data item has not been locked), the scheduler section 9 locks the data item immediately. However, if the data item is not free, the scheduler section 9 waits to execute the lock instruction. The site includes a queue 14 corresponding to each data item respectively in the database. The queue 14 stores lock instructions according to FIFO (first-in first-out). In short, the scheduler section 9 puts the lock instruction from the last row into the corresponding queue. When the data item is released by the transaction execution section 4, the lock instruction, which is located at the head row in the corresponding queue, is executed. In sort, the scheduler section 9 locks the data item again according to the lock instruction. Figure 5c shows the data construction of the database and queue. Database stores the data item and flag corresponding to an address. When the flag is set at "1", it means that the data item is locked. When the flag is reset at "0", it means that the data item is released (free). Each queue corresponds to a respective data item. Accordingly, during the queue process, the lock instruction is stored, and the flag is set repeatedly by the scheduler section 9 whenever the flag is reset by the transaction execution section 4. Figure 6 shows a block diagram of a database management system according to the present invention. This database management system consists of the three sites A, B and C. Figure 7 shows a flow chart for processing of a transaction by the transaction management section of the main site. Figure 8 shows a flow chart for processing by the scheduler section of each site. Referring to Figures 6, 7 and 8, the processing by the database management system of the present invention is explained in detail. (In site B and site C, it is understood that transaction generation section, transaction management section, maximum delay decision section, locktime decision section and clock are present although omitted in Figure 6 for purposes of clarity.) In site A, it is assumed that the transaction request is supplied by transaction generation section la of computer 12a and databases 15a, 15b, 15c stores the data necessary for executing the transaction. For example, databases 15a stores user X's account. Database 15b stores user Y's account. Database 15c stores user Z's account. User X requests transfer of money from his account to user Y's account in the amount of $100 and to user Z's account in the amount of $200 respectively through transaction generation section la of site A. According to the transaction request, three transaction (Ta, Tb, Tc) are generated by the transaction management section 3a. Transaction (Ta) is to subtract $300 from user X's account in database 15a. Transaction (Tb) is to add $100 to user Y's account in database 15b. Transaction (Tc) is to add $200 to user Z's account in database 15c. (Step 71 in Figure 7). The transaction management section 3a sends the database names (15a, 15b 15c) to the maximum delay decision section 5a. The maximum delay decision section 5a previously has stores the delay time to send instructions from site A to site B and to site C respectively. Accordingly, the maximum delay decision section 5a determines the maximum delay time () according to the following formula (Step 73 in Figure 7).  = max (delay A → B), delay (A → C)) delay (A → B) : delay time from site A to site B delay (A → C) : delay time from site A to site C In short, the maximum delay decision section 5 selects the maximum value from the stored delay times. Then, the maximum delay decision section 5 sends the maximum delay time () to the locktime decision section 7a. The locktime decision section 7a includes a current time register in which current time (t) is constantly supplied by a clock 13. (The current time register is not shown in Figure 6). The locktime decision section 7a previously stores error time (δ) between the clock time of site A and the clock time of sites B and C. Accordingly, the locktime decision section 7a determines locktime (T) according to the following formula (Step 75 in Figure 7). T = t +  + δ In short, the locktime decision section 7a adds the maximum delay time () and the error time (♂) to the current time (t). Then, the locktime decision section 7a sends the locktime to the transaction management section 3a. The transaction management section 3a generates a lock instruction by using the locktime and address corresponding to the required data for the transactions. In this case, three lock instructions to lock the data in database 15a, 15b, 15c respectively are generated. Then, the transaction management section 3a sends three lock instructions to scheduler sections 9a, 9b and 9c respectively. The lock instruction to lock the data item in database 15a is sent to scheduler section 9a. The lock instruction to lock the data item in database 15b is sent to scheduler section 9b. The lock instruction to lock the data item in database 15c is sent to scheduler section 9c (Step 77 in Figure 7). By using the formula (1) to determine locktime (T), it is assured that the lock instruction reaches sites B and C before the current time of each clock in sites B and C and that the database will all be locked simultaneously. After sending the lock instruction, the transaction management section 3a sends three transactions (Ta, Tb, Tc) to scheduler sections 9a, 9b, 9c respectively. The following explanation applies to processing at site A, but the processing at sites B and C are the same. When scheduler section 9a receives the lock instructions, the scheduler section 9a sends the locktime of the lock instruction to the lock activation section 11a (step 81 in Figure 8). The scheduler section 9a receives transaction (Ta). The scheduler section 9a sends the transaction (Ta) to transaction execution section 4a. The lock activation section lla includes a current time register in which current time of clock 13a is stored and constantly updated. The lock activation section lla compares the locktime with current time of the current time register. When the locktime coincides with the current time, the lock activation section lla sends signals to the scheduler section 9a. The scheduler section 9a searches the data item corresponding to the address of the lock instruction in database 15a (step 83 in Figure 8). The scheduler section 9a checks whether the data item corresponding to the address is free or not (step 85 in Figure 8). If the data item is free (flag corresponding to the data item is not set), the scheduler section 9a sets the flag and sends lock completion signal with the data item address to the transaction execution section 4a. The transaction execution section 4a begins to execute transaction (Ta) by using the data item (step 87 in Figure 8). If the data item is locked (the flag corresponding to the data item is set), the scheduler section 9a puts the lock instruction into the queue 14a corresponding to the data item according to FIFO (first-in first-out) (step 89 in Figure 8). In this case, the transaction execution section 4a is executing another transaction by using the data item. When the transaction execution section 4a finishes the other transaction, section 4a releases the data item (the flag is reset) and sends transaction completion signal with the data item address to the scheduler section 9a. The scheduler section 9a locks the data item corresponding to the address according to lock instruction stored at head row in the queue. In this way, by locking the necessary data item, transaction is executed in order of the locktime.

Claims: A database management system, comprising: a plurality of sites respectively having a computer (12), a database (15) and a clock (13); communication means for interconnecting the plurality of sites to send instructions between the sites; wherein the respective databases store data for processing, and each computer includes: transaction generation means (1) for generating a transaction, and transaction management means (3) for determining which databases include data required for executing the transaction generated by the transaction generation means and therefore which sites will be involved in the transaction; characterised by: maximum delay decision means (5) for selecting the maximum delay time required to send a lock instruction to all these sites; locktime decision means (7) for determining a locktime according to the maximum delay time and current time of the clock, wherein the transaction management means sends the locktime as the lock instruction to the said sites; scheduler means (9) for receiving a lock instruction sent by the transaction management means of another site through the communication means; and lock activation means (11) for activating the scheduler means when the locktime of the received lock instruction coincides with the current time of the clock, wherein the scheduler means locks the necessary data in the database in response to activation by the lock activation means. A database management system according to claim 1, wherein the transaction management means sends the transaction following the lock instruction to the said sites. A database management system according to claim 1 or claim 2, further including transaction execution means (4) for executing the transaction by using the required data in the database after the required data is locked by the scheduler means. A database management system according to any preceding claim, wherein the transaction management means also sends the lock instruction to the scheduler means in its own site if the database in its own site includes data required for executing the transaction. A database management system according to any preceding claim, wherein the transaction management means sends the transaction following the lock instruction to the scheduler means in its own sire if the database in its own site includes data required for executing the transaction. A database management system according to claim 1, wherein the locktime decision means determines locktime by adding to current time of the clock in its own site, the maximum delay time and a clock error time between its own site and the other sites. A database management system according to claim 3, wherein the transaction execution means releases the necessary data in the database when the transaction execution means finishes executing the transaction. A database management system according to claim 7, further including a plurality of queues (14), corresponding to data items, respectively held in the database, for temporarily storing lock instructions on a first-in first-out basis, and wherein the scheduler means puts the lock instruction in the queue corresponding to the necessary data item, if the necessary data item has already been locked in response to a previous lock instruction. A database management system according to claim 8, wherein the scheduler means locks the required data according to the lock instruction which is stored at the head row in a corresponding queue, when the required data has been released by the transaction execution means. A database management system according to claim 1, wherein the scheduler means locks the required data immediately in response to the lock instruction.

Inventors: KAKIMOTO MITSURU, KAKIMOTO, MITSURU, Kakimoto, Mitsuru, c/o Intellectual Prop. Div.
Applicants: TOSHIBA KK, KABUSHIKI KAISHA TOSHIBA
Application year: 1991
Main classification: G06F17
IPC codes: G06F12, G06F17