US 6978396 B2
This invention relates generally to database servers and computer systems and, more particularly, describes the mechanism to run transaction operations originating from a primary server used to replicate data in parallel in a secondary server. Especially the invention relates to running concurrent or parallel operations in a secondary server for redundancy, recovery and propagated transactions. This invention describes how parallel operation in a secondary server improves performance and availability and how it maintains transaction order and output congruent with the primary server where transaction operations are originated.
1. A method for processing on at least one secondary server a plurality of database transactions originating from at least one primary server in a database system, comprising steps, in which
a first timestamp is attached to each transaction of the plurality of transactions in the primary server in the beginning of the transaction, and
a second timestamp is attached to each transaction of the plurality of transactions in the primary server at the end of the transaction, wherein
said second timestamp is a commit level of an ending transaction and it is determined to be the highest AND latest commit level among the plurality of transactions incremented by a non-zero number,
first and second timestamps of each transaction of a plurality of transactions originating from at least one primary server are evaluated according to specific rules, and
in pursuance of the evaluation according to the specific rules the plurality of transactions originating from at least one primary server are run parallel and/or serially in at least one secondary server.
2. A method according to
a transaction is allowed to begin when its first timestamp is equal to or less than the highest second timestamp of committed transactions,
a transaction having a lower first timestamp is forced to begin before a transaction having a higher second timestamp is committed, and
a transaction is allowed to commit when all other transactions having lower second timestamps are committed.
3. A method according to
4. A method according to
5. A method according to
6. A method according to
7. A method according to
8. A method according to
9. A method according to
10. A method according to
11. A method according to
transaction log file is opened for read access,
next write or commit operation is read from the recovery log file,
said write or commit operation is sent to a parallel transaction executor, and
said operation is executed in the recovering server.
12. A method according to
13. A method according to
14. A method according to
saved transactions are propagated from primary server to secondary server as a batch,
saved statements are sent to a parallel transaction executor, and
saved statement is executed in the secondary server.
15. A method according to
16. A method according to
17. A method according to
18. A database system, comprising at least one primary server and at least one secondary server, wherein at least one secondary server is arranged to evaluate a first and second timestamp attached to each transaction of the plurality of transactions in the primary server, said second timestamp is a commit level of an ending transaction and it is determined to be the highest AND latest commit level among the plurality of transactions incremented by a non-zero number and is arranged to run according to said first and second timestamp transactions parallel and/or serially on at least one secondary server.
19. A system according to
a transaction is allowed to begin when its first timestamp is equal to or less than the highest second timestamp of a committed transaction,
a transaction having a lower first timestamp is forced to begin before a transaction having a higher second timestamp is committed, and
a transaction is allowed to commit when all other transactions having lower second timestamps are committed.
20. A system according to
21. A system according to
22. A system according to
23. A system according to
24. A system according to
25. A system according to
26. A system according to
27. A system according to
28. A system according to
29. A system according to
30. A system according to
The present invention relates generally to database server and computer systems and, more particularly, to run transaction operations in a fault tolerant system originating from a primary server used to replicate data in parallel in a secondary server. Especially the invention relates to running parallel transactions in a secondary server for redundancy or recovery purposes.
Various mechanisms are known for replication or recovery of data in a database server system to ensure correct operation in the case of a crash of a system or a failure that causes the system to be out of order for an undefined period of time.
A Hot Standby (HS) is a mechanism which supports non-disruptive failover of database server system maintaining system availability, i.e. its ability to provide desired service when required, by a second server system ready to take over when the main system is unavailable. In the hot standby replication scheme servers usually have two different roles, the first of which is a primary server and the second a secondary (backup, slave) server. The hot standby configuration provides a way for a secondary database to automatically maintain a mirror image of the primary database. The secondary database on the secondary server is usually of read-only type and it is logically identical to the primary database on the primary server. In case a failure occurs in the primary server, the secondary server can take over and assume the role of a new primary server.
There are several methods for achieving high availability in computer systems that contain databases. One known way to carry out continuous hot standby is to mirror the entire system, i.e. databases and the applications that use the database. All operations of the system are performed on both applications of the system. The applications write each transaction to their respective databases so both systems are completely synchronized at all times. To ensure that the applications and their databases are mutually in synchronization, typically a mechanism called application checkpointing is used. After each executed operation, the application ensures by some means that the other application has executed the same operation. In other words, the secondary database in association with the secondary application precisely mirrors the primary database and application. The application level mirroring is a good choice for real-time applications where everything, including the application processes need to be fault tolerant. However, it requires lots of work from the application programmers as the application checkpointing mechanism is a difficult task to implement.
Another method for processing hot standby replication operations is to create a transaction log of the operations of a transaction run in the primary server, transfer the log to the secondary server and run serially the transferred transaction log on the secondary server. This log is a record of all data items that have been inserted, deleted or updated as a result of processing and manipulation of the data within the transaction. The data needs to be written to both databases before it can be committed in either of the databases. This ensures that data is safely stored in the secondary server before the primary server sends acknowledgement of successful commit to the client application. An example of this kind of data mirroring system is described in the U.S. Pat. No. 6,324,654 where “A primary mirror daemon on a local computer system monitors the writelog device (redundant data storage or memory device) for data updates and feeds the data over a network in the same order in which it is stored to a receiving remote mirror daemon on a remote computer system, which in turns commits the data updates to a mirror device.” This document is here cited as a reference for prior art . In a situation of a failure recovery these primary and secondary mirror daemons transfer the log to the secondary node where the log is run just as it was in the primary node. The replicated operations are run serially in the secondary node which slows down processing speed and hence reduces overall performance.
Still another mechanism for achieving database fault tolerance is to have an application connect to two databases. Whenever the application executes an application function, it commits the related data changes to both servers. To ensure that the transaction is committed in both databases, the application typically needs to use so called two-phase commit protocol to ensure the success of the transaction in both databases. If the transaction fails in either of the databases, it needs to fail also in the other databases. Using two-phase commit protocol needs to be done in the application which makes the application code more complex. Moreover, distributed transactions are quite common cause to performance problems as the transaction cannot be completed before both databases acknowledge the transaction commit. In this scenario, recovery from error situations can also be very difficult.
Still another way for processing hot standby replication operations is to copy the transaction rows to the secondary node after they have been committed on the primary node. This method is a mere copying procedure where transactions are run serially in the secondary node. This method is known as asynchronous data replication. This method is not always suitable for real-time database mirroring because all transactions of the primary database may not yet be executed in the secondary database when the fail-over from primary to secondary happens.
Many database servers are able to execute concurrent transactions in parallel in an efficient manner. For example, the server may execute different transactions on different processors of a multi-processor computer. This way, the processing power of the database server can be scaled up by adding processors to the computer. Moreover, parallel execution of transactions avoid blocking effect of serially executed long-running transactions such as creating an index to a large table. To ensure integrity of the database, some concurrency control method such as locking or data versioning needs to be used to manage access to data that is shared between transactions. If two transactions try to have write access to the same data item simultaneously and versioning concurrency control is in use, the server either returns a “concurrency conflict” error to one of the transactions and the application needs to re-attempt executing the transaction later. If locking concurrency control is in use, the server makes one of the transactions wait until the locked resources are released. However, in this scenario it is possible that a deadlock condition, where two transactions lock resources from each other, occurs and one of the transactions must be killed to clear the deadlock condition. The application that tried to execute the killed transaction, must handle the error e.g. by re-attempting execution of the transaction.
These concurrency control methods known in the prior art are suitable for use in the primary server of the Hot Standby database configuration to manage concurrent online transactions of client applications but they cannot be applied in the secondary server of the system. This is because the concurrency conflict errors cannot be allowed in the secondary server as there is no way to properly handle these error conditions. Because of the absence of a proper Hot Standby concurrency control method, in the prior art replicated hot standby operations are run substantially in a serial form in the secondary node. Because operations cannot be executed in parallel, it is difficult to improve secondary server's performance without raising problems in data integrity and transaction consistency. Essentially, a mechanism is needed that allows transactions to run parallel but that ensures that transactions are not started too early and they are committed before dependent transactions are started.
An object of the invention is to provide a method and system for running replicated transactions parallel in a secondary server originating from a primary server. More precisely, the object of the invention is to identify which transactions can be run concurrently in the secondary server without a risk of a concurrency conflict error and the other object is to guarantee that the transaction order and context (output) maintain similar to the transactions of the primary server. For these purposes a set of specific rules are introduced to evaluate which ones of the plurality of transactions can be run parallel securely. The rest of the transactions which don't meet the criteria may end in serial processing. A point of the invention is to improve performance in complex server systems compared to prior art of totally serial transaction approach.
To fulfill the objects of the invention a set of specific rules is determined. The specific rules are defined on basis of a “first timestamp” and “second timestamp” attached to each transaction in the primary server and the rules form a “timestamp criteria”. When a transaction meets this timestamp criteria it can be run in parallel with other transactions met the same criteria in the secondary server in accordance with the instructions set in the specific rules to maintain the transaction order and output correct. The use of timestamp criteria as an instrument of parallel transaction executor (PTE) is explained more detail in section Detailed Description.
This invention is used in a database server system comprising a primary server, a secondary server and associated database management system. It is also possible to use this invention having multiple network connections between primary and secondary servers. In multi-node configurations each primary server can have multiple secondary servers.
A preferred embodiment of this invention is to run replicated hot standby (HS) operations and transactions parallel in a secondary server for redundancy. Another embodiment of this invention is to execute transactions parallel from recovery log file after a system crash. Still another embodiment of this invention is to enhance performance of asynchronous data replication process where a batch of transactions that has been executed earlier in one database is to be later executed in another database. This batch of transactions is also known as propagated transactions.
A method for processing on at least one secondary server a plurality of database transactions originating from at least one primary server in a database system comprising steps, in which first and second timestamps of each transaction of a plurality of transactions originating from at least one primary server are evaluated according to specific rules, and in pursuance of the evaluation according to the specific rules the plurality of transactions originating from at least one primary server are run parallel and/or serially on at least one secondary server.
A database system, comprising at least one primary server and at least one secondary server, characterized in that at least one primary or secondary server is arranged to evaluate a first and second timestamp attached to each transaction of the plurality of transactions in the primary server and is arranged to run according to said first and second timestamp transactions parallel and/or serially on at least one secondary server.
The advantage of the invention is to improve speed and performance allowing parallel operations in hot standby, recovery and propagated transactions. High performance is needed in environments where large number of write operations are run each second and parallel processing power of a multi-processing computer is needed to handle the transaction load. Parallel operation according to the invention would not block all hot standby operations in a secondary server in case of executing large operations like creating and index for a large table. Hence, these improvements increase system availability in database server environment.
The best mode of the invention is considered to execute replicated hot standby transactions in the secondary server of a hot standby server pair in a parallel fashion whenever the transactions meet the timestamp-based criteria for parallel execution.
Some embodiments of the invention are described in the dependent claims.
The foregoing and other objects, features and advantages of this invention will be apparent from the following more particular description of the preferred embodiments of the invention as illustrated in accompanying drawings.
The following notions are used in this application:
“Client application” is a software process that connects to another software process such as database server application via a network or other means of inter-process communication and uses services provided by the server application.
“Database server” is an entity, which comprises one or more databases, whereby the server is responsible for reading the data structures contained in the databases and/or data management systems and for changing these data structures.
“Database” is an information structure, which comprises one or more data elements, and the use of which is controlled by the data management system. The invention is applicable both in relational databases and in databases of other forms, such as in object oriented databases.
“Database operation” is an event, during which data elements are read from the database, during which data elements of the database are modified, during which data elements are removed from the database, and/or during which data elements are added to the database. Database operation can also be a call to a stored procedure or other piece of program code that is run by the database server.
“Timestamp” refers to any mechanism which can be used to put events in relative order. The timestamp value can for example be the current time or it can be a value of a global counter object that is incremented whenever an event that requires a timestamp, occurs.
“Transaction” is a plurality of database operations acting on the data elements. A transaction can also comprise further transactions. Typically, transactions implement at least some of the so called ACID (Atomic, Consistent, Isolated and Durable) properties. Atomic property means that a transaction is completed or terminated as a whole. A “commit” operation signifies the successful completion of a transaction and a “rollback” operation signifies the termination of a transaction. The isolation property hides the operations of an ongoing transaction from other users of the database. The consistency property ensures that during a transaction, the application's view to the entire database remains unchanged. Commit makes all operations of the transaction durable and visible to other users. Rollback cancels all operations of the transaction so that no changes to the database are made by the transaction.
As shown in
It must be guaranteed that parallel operations and especially transaction commit operations in the secondary server are executed in the same order as in the primary server. It also must be guaranteed that operations in one transaction are always in the same order in the secondary and primary server. Commit operation also requires that all operations of the transaction must be finished before the transaction is committed and next operation in a new transaction is commenced. It also must be guaranteed that transaction does not start before other preceding transactions that may have modified data used by the transaction are committed.
The number at the end of transaction is called the “commit level” of the transaction, and it signifies the order in which the transaction is committed.
These numbers that are assigned to each transaction in the primary server are used to control parallel transaction processing in the secondary server of the hot standby server pair. The basic rule is that a commencing transaction that has a certain read level may start only after transactions having lower or equal commit levels have ended. As an example of this, according to
A flow diagram in
Here are used foregoing markings, namely TS is the abbreviation of timestamp, TS(excluding A) refers to timestamps of all other transactions than transaction A (TR A) and timestamps of transaction A are referred by TS(A). In first step 31 it is checked if the first timestamp of the beginning transaction (1. TS(A)) is equal to or less than the highest second timestamp of the committed transaction (2. TS(excluding A)). In other words the transactions can commence when commit level equal to or higher than read level is visible. In case the condition is fulfilled the transaction in question is allowed to begin as shown in step 32. Eventually the transaction will be ready to commit in step 35.
In second step 33 it is checked whether the first timestamp of the beginning transaction (1. TS(A)) is less than the second timestamp of the committed transaction (2. TS(excluding A)). In case of affirmative answer the transaction in question is forced to begin as shown in step 34. This means it is necessary to commence the transactions having lower read level before committing higher commit level. Eventually the transaction will be ready to commit in step 35. However, if neither condition 31 or 33 is fulfilled, the transaction waits in the loop 37, and begins the evaluation for the criteria 31 and 33 later.
Once the transaction has reached phase 35 and is ready to commit, it will be compared with the third criterion in step 36. In step 36 it is checked whether the second timestamp of the committing transaction (2. TS(A)) is equal to 1+the greatest second timestamp of the committed transaction (2. TS(excluding A)). Here we assume for simplicity that the non-zero increment that is being used is one. In case this is fulfilled the transaction in question is allowed to commit as shown in step 39. If the criterion is not met, the transaction enters a commit wait loop 38 and the criterion is re-evaluated after some time. This means that the transactions can commit when transactions having lower commit level have committed. In other words a time-line of commit levels is continuous and incrementing in numeric order as shown in
To improve the performance of the roll-forward recovery in a multiprocessor computer, the recovery transactions should advantageously be executed in parallel whenever possible. According to the present invention, parallel execution can be achieved using the Parallel Transaction Executor that reads the transactions from the transaction log file and determines the transaction execution schedule based on the read and commit levels. In connection with transactions and operations P in parenthesis means transactions written to the log file 55 by the server that is operating on normal mode, i.e. in similar manner than primary server operates in the hot standby arrangement. S relates to a server that is operating in the recovery mode in this embodiment, i.e. in similar manner than secondary server operates in the hot standby arrangement. In
The described method and system of the invention is independent of the communication technology and the client/server or multi-database system. The primary database server and secondary database server can be connected to each other to communicate transactions by any known suitable data transfer system such as cable, wireless, Internet or other communication system or by any combination of these when the connection is established. Parallel transaction executor (PTE) is a program object which is integrated into a database management system (DBMS) or an application using it. The saved statements table (SST) is a table managed by a database management system. The storage medium for SST is a memory or a disk accessed by this DBMS.
The invention is not only limited to transaction scheduling. It is evident that the same inventive idea may be applied in the parallel processing of database rows in a level lower than transactional level.
A system according to the invention can be implemented by a person skilled in the art with state of the art information and communication technology components. A person skilled in the art can implement the functions according to the invention by arranging and programming such components to realize the inventive functions.
For example, it is preferable to implement the invention to work in a telecommunication system which is compliant with, but is not limited to, at least one of the following: TCP/IP, CDMA, GSM, HSCSD, GPRS, WCDMA, EDGE, UMTS, Bluetooth, Teldesic, Iridium, Inmarsat, WLAN, DIGI-TV and imode.
It is also preferable to use a standardized operating system in the terminals and servers. The operating system of a terminal can be, but is not limited to, for example Unix, MS-Windows, EPOC, NT, MSCE, Linux, PalmOS, GEOS, VxWorks, OSE, Solaris, HP-UX, AIX, WinCE, ITRON, QNX and all upgrades of these.
While presently preferred embodiments of the invention have been shown and described in particularity, those skilled in the art will recognize that the invention is not limited to the embodiments described herein. The invention may be otherwise embodied within the spirit and scope of the idea as set forth in the appended claims.