Chương 5: Khái Niệm và Lý Thuyết Xử Lý Giao Dịch trong Hệ Quản Trị Cơ Sở Dữ Liệu

Tài liệu nghiên cứu Dbms chapter 5 transaction processing, tổng hợp lý thuyết và thực hành, cung cấp kiến thức chuyên sâu về ., phục vụ nghiên cứu và ứng dụng thực tiễn

Chuyên ngành

Computer Science

Người đăng

Ẩn danh

Thể loại

course outline

2020-2021

92
4
0

Phí lưu trữ

35 Point

Mục lục chi tiết

1. CHƯƠNG 1: OVERALL INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS

2. CHƯƠNG 2: DISK STORAGE AND BASIC FILE STRUCTURES

3. CHƯƠNG 3: INDEXING STRUCTURES FOR FILES

4. CHƯƠNG 4: QUERY PROCESSING AND OPTIMIZATION

5. CHƯƠNG 5: INTRODUCTION TO TRANSACTION PROCESSING CONCEPTS AND THEORY

5.1. Transaction and System Concepts

5.2. Desirable Properties of Transactions

5.3. Characterizing Schedules based on Recoverability

5.4. Characterizing Schedules based on Serializability

5.5. Transaction Support in SQL

6. CHƯƠNG 6: CONCURRENCY CONTROL TECHNIQUES

7. CHƯƠNG 7: DATABASE RECOVERY TECHNIQUES

TÀI LIỆU THAM KHẢO

Tóm tắt

I. Tổng Quan về Khái Niệm và Lý Thuyết Xử Lý Giao Dịch

Khái niệm xử lý giao dịch trong hệ quản trị cơ sở dữ liệu (DBMS) là một phần quan trọng trong việc đảm bảo tính toàn vẹn và hiệu suất của hệ thống. Giao dịch được định nghĩa là một đơn vị logic của xử lý cơ sở dữ liệu, bao gồm một hoặc nhiều thao tác truy cập cơ sở dữ liệu. Mục tiêu chính của lý thuyết giao dịch là đảm bảo rằng tất cả các thao tác trong một giao dịch được thực hiện thành công hoặc không có thao tác nào được thực hiện. Điều này giúp duy trì tính nhất quán của dữ liệu trong hệ thống.

1.1. Định Nghĩa và Tầm Quan Trọng của Giao Dịch

Giao dịch là một khái niệm cốt lõi trong hệ quản trị cơ sở dữ liệu. Nó đảm bảo rằng các thao tác như đọc, ghi, cập nhật và xóa được thực hiện một cách chính xác. Tính toàn vẹn của dữ liệu phụ thuộc vào việc thực hiện thành công các giao dịch này.

1.2. Các Tính Chất Cơ Bản của Giao Dịch

Các giao dịch phải đáp ứng các tính chất ACID: Tính nguyên tử (Atomicity), Tính nhất quán (Consistency), Tính độc lập (Isolation), và Tính bền vững (Durability). Những tính chất này đảm bảo rằng giao dịch được thực hiện một cách an toàn và hiệu quả.

II. Vấn Đề và Thách Thức trong Xử Lý Giao Dịch

Trong quá trình xử lý giao dịch, có nhiều vấn đề và thách thức cần phải đối mặt. Các vấn đề này có thể ảnh hưởng đến tính toàn vẹn và hiệu suất của hệ thống. Một số vấn đề phổ biến bao gồm: mất cập nhật, đọc tạm thời, và các vấn đề không thể lặp lại. Những vấn đề này có thể dẫn đến sự không nhất quán trong cơ sở dữ liệu.

2.1. Vấn Đề Mất Cập Nhật

Vấn đề mất cập nhật xảy ra khi hai giao dịch truy cập cùng một mục dữ liệu và thao tác của chúng bị xen kẽ, dẫn đến giá trị của mục dữ liệu không chính xác. Điều này có thể gây ra sự không nhất quán trong cơ sở dữ liệu.

2.2. Vấn Đề Đọc Tạm Thời

Vấn đề đọc tạm thời xảy ra khi một giao dịch đọc dữ liệu đã được cập nhật bởi một giao dịch khác nhưng chưa được cam kết. Điều này có thể dẫn đến việc giao dịch đọc dữ liệu không chính xác, gây ra lỗi trong quá trình xử lý.

III. Phương Pháp Giải Quyết Vấn Đề Xử Lý Giao Dịch

Để giải quyết các vấn đề trong xử lý giao dịch, các phương pháp như kiểm soát đồng thời và phục hồi giao dịch được áp dụng. Kiểm soát đồng thời giúp quản lý việc thực hiện nhiều giao dịch cùng lúc mà không gây ra xung đột. Phục hồi giao dịch đảm bảo rằng hệ thống có thể quay lại trạng thái nhất quán sau khi xảy ra lỗi.

3.1. Kiểm Soát Đồng Thời

Kiểm soát đồng thời là một kỹ thuật quan trọng trong hệ quản trị cơ sở dữ liệu. Nó cho phép nhiều giao dịch được thực hiện đồng thời mà không gây ra xung đột, đảm bảo tính nhất quán của dữ liệu.

3.2. Phục Hồi Giao Dịch

Phục hồi giao dịch là quá trình khôi phục trạng thái của cơ sở dữ liệu sau khi xảy ra lỗi. Điều này bao gồm việc hoàn tác các giao dịch không thành công và đảm bảo rằng tất cả các thay đổi đã được cam kết.

IV. Ứng Dụng Thực Tiễn của Lý Thuyết Xử Lý Giao Dịch

Lý thuyết xử lý giao dịch có nhiều ứng dụng thực tiễn trong các lĩnh vực như ngân hàng, thương mại điện tử và quản lý dữ liệu. Các hệ thống giao dịch như đặt vé máy bay, xử lý thẻ tín dụng, và thanh toán trực tuyến đều dựa vào các nguyên tắc của lý thuyết này để đảm bảo tính chính xác và an toàn.

4.1. Ứng Dụng trong Ngân Hàng

Trong ngành ngân hàng, việc xử lý giao dịch là rất quan trọng. Các giao dịch như rút tiền, chuyển khoản và thanh toán đều yêu cầu tính chính xác và an toàn cao. Hệ thống ngân hàng sử dụng lý thuyết giao dịch để đảm bảo rằng tất cả các giao dịch được thực hiện một cách chính xác.

4.2. Ứng Dụng trong Thương Mại Điện Tử

Trong thương mại điện tử, lý thuyết xử lý giao dịch giúp quản lý các giao dịch mua bán trực tuyến. Điều này bao gồm việc xử lý thanh toán, quản lý đơn hàng và đảm bảo rằng tất cả các giao dịch đều được thực hiện một cách an toàn.

V. Kết Luận và Tương Lai của Xử Lý Giao Dịch

Tương lai của xử lý giao dịch trong hệ quản trị cơ sở dữ liệu sẽ tiếp tục phát triển với sự gia tăng của công nghệ và nhu cầu về tính chính xác trong xử lý dữ liệu. Các nghiên cứu và cải tiến trong lĩnh vực này sẽ giúp nâng cao hiệu suất và độ tin cậy của các hệ thống giao dịch.

5.1. Xu Hướng Phát Triển

Xu hướng phát triển trong lĩnh vực xử lý giao dịch bao gồm việc áp dụng trí tuệ nhân tạo và học máy để tối ưu hóa quy trình xử lý. Điều này sẽ giúp cải thiện hiệu suất và giảm thiểu lỗi trong các giao dịch.

5.2. Tương Lai của Hệ Quản Trị Cơ Sở Dữ Liệu

Hệ quản trị cơ sở dữ liệu sẽ tiếp tục đóng vai trò quan trọng trong việc quản lý dữ liệu. Các cải tiến trong lý thuyết xử lý giao dịch sẽ giúp nâng cao tính toàn vẹn và hiệu suất của hệ thống, đáp ứng nhu cầu ngày càng cao của người dùng.

15/07/2025

Trích đoạn nội dung tài liệu

Ho Chi Minh City University of Technology Faculty of Computer Science and Engineering Chapter 5: Introduction to Transaction Processing Concepts and Theory Database Management Systems (CO3021) Computer Science Program Dr. Võ Thị Ngọc Châu (chauvtn@hcmut.vn) Semester 1 – 2020-2021 Course outline  Chapter 1. Overall Introduction to Database Management Systems  Chapter 2. Disk Storage and Basic File Structures  Chapter 3.

Indexing Structures for Files  Chapter 4. Query Processing and Optimization  Chapter 5. Introduction to Transaction Processing Concepts and Theory  Chapter 6. Concurrency Control Techniques  Chapter 7.

Database Recovery Techniques 2 References  [1] R. Navathe, Fundamentals of Database Systems- 6th Edition, Pearson- Addison Wesley, 2011. Navathe, Fundamentals of Database Systems- 7th Edition, Pearson, 2016. Widom, Database System Implementation, Prentice-Hall, 2000.

Widom, Database Systems: The Complete Book, Prentice-Hall, 2002  [4] A. Sudarshan, Database System Concepts –3rd Edition, McGraw-Hill, 1999. Introduction to Transaction Processing  5. Transaction and System Concepts  5.

Desirable Properties of Transactions  5. Characterizing Schedules based on Recoverability  5. Characterizing Schedules based on Serializability  5. Transaction Support in SQL 4 5.

Introduction to Transaction Processing  Transaction processing systems are systems with large databases and hundreds of concurrent users executing database transactions.  High availability and fast response time for hundreds of concurrent users  Examples: airline reservations, banking, credit card processing, online retail purchasing, stock markets, supermarket checkouts, etc.  the concept of a transaction, which is used to represent a logical unit of database processing that must be completed in its entirety to ensure correctness 5 5. Introduction to Transaction Processing  Single-user vs.

multi-user database systems  Concurrent execution of transactions in a multi- user system  Recovery from transaction failures when transactions fail while executing  The number of users who can use the system concurrently-that is, at the same time  Single-user if at most one user at a time can use the system  Multiuser if many users can use the system - and hence access the database - concurrently 6 5. Introduction to Transaction Processing Interleaved processing versus parallel processing of concurrent transactions Figure 20. 747 Concurrent execution of processes is actually interleaved. Interleaving keeps the CPU busy If the computer system has when a process requires an input or output multiple hardware processors (I/O) operation, such as reading a block from disk.

The CPU is switched to execute another (CPUs), parallel processing of process rather than remaining idle during I/O multiple processes is possible. Interleaving also prevents a long 7 process from delaying other processes. Introduction to Transaction Processing  A Transaction: logical unit of database processing that includes one or more database access operations (read – retrieval, write – insert, update, delete).  Typically implemented by a computer program that includes database commands  The database operations that form a transaction can either be embedded within an application program or they can be specified interactively via a high-level query language such as SQL.

 Transaction boundaries: Begin and End transaction statements.  An application program may contain several transactions separated by the transaction boundaries. Introduction to Transaction Processing SIMPLE MODEL OF A DATABASE (for purposes of discussing transactions):  A database - collection of named data items  Granularity of data - a field, a record , or a whole disk block (Concepts are independent of granularity)  Basic operations are read and write  read_item(X): Reads a database item named X into a program variable. To simplify our notation, we assume that the program variable is also named X.

 write_item(X): Writes the value of program variable X into the database item named X. Introduction to Transaction Processing READ AND WRITE OPERATIONS:  Basic unit of data transfer from the disk to the computer main memory is one block. In general, a data item (what is read or written) will be the field of some record in the database, although it may be a larger unit such as a record or even a whole block.  read_item(X) command includes the following steps: 1.

Find the address of the disk block that contains item X. Copy that disk block into a buffer in main memory (if that disk block is not already in some main memory buffer). Copy item X from the buffer to the program variable named X. Introduction to Transaction Processing READ AND WRITE OPERATIONS:  write_item(X) command includes the following steps: 1.

Find the address of the disk block that contains item X. Copy that disk block into a buffer in main memory (if that disk block is not already in some main memory buffer). Copy item X from the program variable named X into its correct location in the buffer. Store the updated block from the buffer back to disk (either immediately or at some later point in time).

Introduction to Transaction Processing Two sample transactions. Introduction to Transaction Processing  Why concurrency control is needed  The problems encountered with the transactions running concurrently if uncontrolled  The lost update problem  The temporary update (or dirty read) problem  The incorrect summary problem  The unrepeatable problem  The phantom problem 13 5. Introduction to Transaction Processing  The lost update problem  This problem occurs when two transactions that access the same database items have their operations interleaved in a way that makes the value of some database items incorrect. Introduction to Transaction Processing  The temporary update (or dirty read) problem  This problem occurs when one transaction updates a database item and then the transaction fails for some reason.

The updated item is accessed by another transaction before it is changed.  The incorrect summary problem  If one transaction is calculating an aggregate summary function on a number of records while other transactions are updating some of these records, the aggregate function may calculate some values before they are 16 updated and others after they are updated. Introduction to Transaction Processing  The unrepeatable (nonrepeatable) problem  A transaction T reads an item twice and the item is changed by another transaction T' between the two reads. Hence, T receives different values for its two reads of the same item.

Introduction to Transaction Processing  The phantom problem  A transaction T1 may read a set of rows from a table, perhaps based on some condition specified in the SQL WHERE-clause. Now suppose that a transaction T2 inserts a new row that also satisfies the WHERE-clause condition used in T1, into the table used by T1. If T1 is repeated, then T1 will see a phantom, a row that previously did not exist. Introduction to Transaction Processing  Why recovery is needed  Whenever a transaction is submitted to a DBMS for execution, the system is responsible for making sure:  either (1) all the operations in the transaction are completed successfully and their effect is recorded permanently in the database,  or (2) the transaction has no effect whatsoever on the database or on any other transactions.

 The DBMS must not permit some operations of a transaction T to be applied to the database while other operations of T are not.  This may happen if a transaction fails after executing some of its operations but before executing all of them. Introduction to Transaction Processing  Several possible reasons for a transaction to fail in the middle of execution:  1. A transaction or system error  3.

Local errors or exception conditions detected by the transaction  4. Concurrency control enforcement  5. Physical problems and catastrophes  Recovery and backup 20 5. Introduction to Transaction Processing Why recovery is needed: (What causes a Transaction to fail) 1.

A computer failure (system crash): A hardware or software error occurs in the computer system during transaction execution. If the hardware crashes, the contents of the computer’s internal memory may be lost. A transaction or system error : Some operation in the transaction may cause it to fail, such as integer overflow or division by zero. Transaction failure may also occur because of erroneous parameter values or because of a logical programming error.

In addition, the user may interrupt the transaction during its execution. Introduction to Transaction Processing Why recovery is needed: 3. Local errors or exception conditions detected by the transaction: - certain conditions necessitate cancellation of the transaction. For example, data for the transaction may not be found.

A condition, such as insufficient account balance in a banking database, may cause a transaction, such as a fund withdrawal from that account, to be canceled. - a programmed abort in the transaction causes it to fail. Concurrency control enforcement: The concurrency control method may decide to abort the transaction, to be restarted later, because it violates serializability or because several transactions are in a state of deadlock. Introduction to Transaction Processing Why recovery is needed: 5.

Disk failure: Some disk blocks may lose their data because of a read or write malfunction or because of a disk read/write head crash. This may happen during a read or a write operation of the transaction. Physical problems and catastrophes: This refers to an endless list of problems that includes power or air-conditioning failure, fire, theft, sabotage, overwriting disks or tapes by mistake, and mounting of a wrong tape by the operator. Transaction and System Concepts A transaction is an atomic (logical) unit of work that is either completed in its entirety or not done at all.

Transaction states:  Active state  Partially committed state  Committed state  Failed state  Terminated State 24 5. Transaction and System Concepts State transition diagram illustrating the states for transaction execution. Transaction and System Concepts  Transaction states  Active state: a transaction goes into an active state immediately after it starts execution, where it can issue READ and WRITE operations.  Partially committed: when the transaction ends, some recovery protocols need to ensure that a system failure will not result in an inability to record the changes of the transaction permanently (usually by recording changes in the system log).

 Committed: once this check is successful, the transaction is said to have reached its commit point. Once a transaction is committed, it has concluded its execution successfully and all its changes must be recorded permanently in the database.  Failed: if one of the checks fails or if the transaction is aborted during its active state. The transaction may then have to be rolled back to undo the effect of its WRITE operations on the database.

Failed or aborted transactions may be restarted later - either automatically or after being resubmitted by the user-as brand new transactions.  Terminated: the transaction leaving the system. The transaction information that is maintained in system tables while the transaction has been running is removed when the transaction terminates. Transaction and System Concepts For recovery purposes, the system needs to keep track of when the transaction starts, terminates, and commits or aborts.

 begin_transaction: This marks the beginning of transaction execution.  read or write: These specify read or write operations on the database items that are executed as part of a transaction.  end_transaction: This specifies that read and write transaction operations have ended and marks the end limit of transaction execution. At this point it may be necessary to check whether the changes introduced by the transaction can be permanently applied to the database or whether the transaction has to be aborted because it violates concurrency control or for some other reason.

Transaction and System Concepts For recovery purposes, the system needs to keep track of when the transaction starts, terminates, and commits or aborts.  commit_transaction: This signals a successful end of the transaction so that any changes (updates) executed by the transaction can be safely committed to the database and will not be undone.

Nội dung được bảo vệ bản quyền — Tải xuống đầy đủ