Interbase6.0 In order to optimize its server performance, it enhances its internal core structures, especially the multi-variable architecture, multithreaded service structure, version transaction management, etc. 1. Garbage Collection Threads In the previous version of Interbase6.0, each database request must be completed by the garbage collection, which obviously reduces the performance of the database because a database request is written during the commission. The data pages will be dirty. In Interbase6.0, the background garbage collection is now executed by a central thread control. When a data page contains garbage, the interbase6.0 work thread will immediately notify the garbage thread, but it is often not cleared, and the CommT is only just Write back on the data page that is actually changed by the database. In summary, the garbage collection thread is maintained by the list of all dirty data pages, reads these data pages, clears the garbage, and finally write the data back. 2, transaction cleaning threads To ensure database consistency, InterBase6.0 will remove things from the database using a transaction cleaning thread. Garbage collection threads and transaction cleaning threads The priority of the transaction cleaning thread is higher than the priority of the thread, and the two threads are collaborative. When the transaction cleaning thread is idle, the garbage cleaning thread cleans the data garbage. 3. File Format Change Interbase6.0 uses its unique version of the transaction management mechanism to improve the internal format of the data record storage, so that a data page can store more data than before. 4, Versioning Model Transaction To understand the benefits of versioninging mode, understand how Interbase's version of the versioning structure is well supported by large online transaction processing and data decisions, must first clear the concurrent access control and transaction processing of the database. . [1], lock. We know that the most commonly used method of handling multi-user concurrent access is to lock. Other users can no longer access the object when a user locks an object in the database. The effect of locking the concurrent access is reflected in the particle size of the lock. For example, putting a lock restriction on a table to concurrently accessing the entire table; the lock on the data page limits access to the entire data page; the locks on the line limit restricts concurrent access to the row. It can be seen that the row is smaller, the concurrent visit is the best, the page lock is the largest, and the table lock is between 2. There are two types of locks: pessimistic locks and optimistic locks. Pessimacy vacation vacation, other users try to access or change you are accessing, the change in object is very high, so in a pessimistic lock environment, you lock the object before you start changing this object, and until you are submitted The lock is released after the changes. Pessimistic defects are pairs or line locks, and the time to lock may be very long, so that the may limit other users' access, that is, the pessimistic lock is not good. In contrast to pessimism, optimistic locks believe that other users try to change the probability of the object you are changing, so optimistic lock until you are ready to submit the changes, when you read and change the object Don't lock it when you are. It can be seen that the optimistic lock lock is shorter than pessimistic, and the optimistic lock can achieve better concurrent access performance with a larger lock size. But if the second user reads the object before the first user submits the change, the database will find that the object has changed when he completed his changes. This way, the second user is not This object is not read and make changes. This shows that in an optimistic lock environment, it will increase the number of times the user reads the object. From the perspective of database vendors, using optimistic page locks is better, especially in batches that can put relatively small locks in bulk operations, thereby reducing the performance of resources to resources. Consider the aggregation index.
In the database is stored in the physical order of the aggregation index. If you use a page lock, one user must wait for another user to release lock when the two users accessed at the same data page, and one of the users must wait for another user to release the lock, which will significantly reduce the performance of the system. Interbase is the same as most of the relational databases, and it is optimistic lock, and the lock is shared, and the write lock is row him. You can place a read lock on a read lock, but you can't place a write lock again; you can't place any locks on the write lock. The lock is an effective means of solving multi-user concurrent access. [2], transaction. In the database, transaction processing is divided into three steps: First you tell the database you start a transaction, so that the database will be treated as a unit; then, you have changed the data. Notify the database to submit or return the transaction. When you submit a transaction, the changes become permanent; when you fall back, all changes are revoked. The degree of isolation between the transaction is expressed by Isolation Level. It is defined as follows: Read Uncommited: Allows read any submission or uncommitted records, ie, whether the record is submitted to be read. Read command: Only records that have been submitted are allowed. REPEATABLE READ: You can only see a snapshot of the database at the beginning of the transaction. All records after the start of the transaction, no matter whether it is not submitted. Serializable: Most database default isolation levels are read committed. Transaction processing is very important to ensure database consistency. Transactions and locks are inseparable. Investigate the changes recorded in the database: (1), start a transaction (2), read row (3), storage line (4), make more (5) re-reading the line to see if other users have already Change (6), lock the line (7), write changes (8), submit or fall back, the release lock can see the close cooperation of transactions and locks. [3], Interbase's Versioning structure. In Interbase6.0, each transaction is assigned a sequential number version number, the database maintains a copy number, activity, submission, and rollback, etc. of all transactions to specifically record all transactions. Under version mode, the transaction is working: When a more transaction is submitted, the database checks if there is a version number small transaction is still active. If so, create a new version of the record, each new version Only the changed field value (instead of copying the original whole record) and the version number of the created transaction. This read transaction is assigned to the next version number when a read transaction begins. When reading a transaction requests to read the data line, the database will check if the recent version number of the data row is greater than the version number of the transaction, but also check if the transaction corresponding to the transaction is already submitted. If the version number of the data line is larger than the version number of the read transaction, or when the transaction corresponding to the transaction is still active, InterBase will look forward to the previous version from the transaction date until you find a version number than reading transactions. The version number is small and the transaction version that has been submitted at the beginning of the transaction, and then returns the record corresponding to this version.
Consider the following example, assume that a few versions have the following versions: TRAN = 100 (status = committed) TRAN = 60 (status = rolled back) TRAN = 40 (status = committed when Read Started) Let's take a look at a transaction attempt to 90 attempts to read the situation at the time. Obviously, 90 can't see version 100 because version 100 does after him; 90 cannot read version 80, although version 80 sequence number is more active than him, but version 80 is still active; 90 can not read version 60, Because version 60 returned; finally he could only read version 40 because version 40 has been submitted at the beginning of the 90, and the sequence number is smaller than him. In this example, version 80 cannot be submitted because version 100 has been submitted, and version 80 can only fall back. Below we use several examples to show the difference between the lock mode and version mode: assuming husband and wife at the same time to different automatic cash machines. In the lock mode, it is done like this: * Husband reads account balance to cause a reading lock * wife reading account balance caused a reading lock * husband more account balance placed write lock failed because his wife has already placed read lock * wife The account balance placed a write lock failed because the husband had already placed a lock, which formed a dead cycle. The database system may find that the dead loop retreats all transactions. In version mode: * Husband read account balance * Wife read account balance * Husband more account balance The new version of the balance * Wife more balance is reversed because the balance has a new version if there is a new version One of the rollbacks will have another situation. Plock mode: * Husband reads account balance Place a read lock * Husband submit balance change Place a write lock * Wife read account balance attempt to place a read lock but must wait for husband writing to release * husband retreat and release Lock * Wife can now read account balances and get the correct value version mode: * Husband more account balance generates a new version (not submit) * Wife reads account balance, this does not affect husband's uncommitted transaction * The husband retired and returned the version as a return visible version mode, the wife didn't have to read the balance of the account. let's continue. Suppose the husband wants to get a general ledger report on all of them, and his wife is also trying to change an account balance at this moment. Let us look at how to ensure the accuracy of the husband report in the lock mode. * Husband reads all accounts to place a read lock * Wife more accounts to place write locks, he must wait until husband read the business complete * husband has obtained the correct general ledger report and releases the lock, the wife can now have more accounts. And in version mode: * Husband reads all accounts to get a general ledger, start reading transactions * Wife more account balance begins more transaction, then submit changes and generate new versions of the balance, this version is invisible to the husband of. * The husband's read business reads the balance of his wife, and finds a number of versions, so he will choose a record along the transaction book, and the maximum record of the version number is the largest record, so he will Get the right general ledger report, and do not affect the wife's more affected. It can be seen by comparison that the benefits of Versioning mode are still permitted more transactions during a long read transaction, and read transactions and more transactions can be made concurrent, while the lock mode is not allowed. That is to say that version mode can solve large online transaction processing and data decision support. Finally, let's take a look at the lock mode and version mode in the database disaster recovery.