Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 67 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
67
Dung lượng
7,93 MB
Nội dung
Airline Reservation System using Concurrency Control Graduation Thesis Submitted to Hanoi University for the degree of Bachelor of Computer Science THƯVIỆNĐẠI HỌC HANỘI HANOI UN IVERSITY LIB R A R Y M; ! I lieu OÛOO _ By Ta Thỉ Hong (Computer Science) December,2009 Abstract Doing business on the Internet can be considered as a crucial source o f profit When transactions are performed online, the possibility o f concurrent, competing transactions is increased Thus, how to ensure such events not violate the data integrity o f a database system is one important question that needs to be solved when designing a commercial system Concurrency control is known as one key mechanism to deal with this problem Knowing its importance, this project aims to provide a sufficient knowledge base o f concurrency control and related issues Since it is impossible to cover all aspects o f concurrency control as well as its mechanisms, this paper focuses on investigating four transaction isolation levels: read uncommitted, read committed, repeatable read and serializable by building an airline reservation system for demonstration Although two months is a short time, this project ends with several surprising findings about highest level o f transaction isolation - serializable 一 in the MySQL open source DBMS Acknow ledgm ents I would like to thank my dear Instructor Mrs Marry Gallagher for her guidance and enthusiasm Without her detailed suggestions and encouragement, I never would have taken on this project I also thank Faculty o f Information Technology in Hanoi University that gives me a great chance to undertake this project Finally, I am grateful to my family, friends for their supports and encouragement Ta Thi Hong December 2009 Table of Contents Table o f Contents iv List o f fig u res vi Chapter Introduction Objectives Motivation Methodology An Overview o f the Rest o f the Document Chapter Background Knowledge Concurrency control definition Transactions and AC ID properties Schedules Serial schedules .10 Serializable schedules 11 Transaction Isolation 12 READ UNCOM M ITTED 13 READ C O M M IT T E D 14 REPEATABLE R E A D 14 S E R IA L IZ A B L E 15 Chapter Airline reservation system 20 Database design 20 Data objects and classes 22 Reservation Process 25 User interface .2ö Concurrency 28 Chapter Investigating isolation levels in airline reservation system 33 Remarkable problems in building the demo system 33 Four isolation levels in airline reservation system 34 Read Uncommitted isolation level 36 Read committed isolation level 37 Repeatable read isolation level 39 Serializable isolation level .41 Chapter Summary and Conclusions 48 References 50 Appendix Application Code 51 PHP Code 51 V List of Figures Figure 1: Two transactions 10 Figure 2: Serial schedule in which T ị precedes Tl 11 Figure 3: T ị and 72 interleaves 11 Figure 4: D irty read 17 Figure 5: Non-repeatable read 18 Figure 6: Phantom reads 19 Figure 7: ER diagram 21 Figure 8: Flight table 21 Figure 9: Customer table 21 Figure 10: Reservation table 22 Figure 11: Table relationship .22 Figure 12: List o f available flights .27 Figure 13: Check availability .27 Figure 14: Personal information form 27 Figure 15: Confirm ation 28 Figure 16: Flow chart 29 Figure 17: Check availability code 30 Figure 18: Code handles submit action 31 Figure 19: Code handles commit or rollback action 32 Figure 20: Customer reservation 35 Figure 21 : First test scenario Figure 22: Serializable tes scenario Chapter Introduction Objectives In the age o f information systems, where everything is shared on the Internet, people all over the world are connected together via an international channel Therefore, more and more businesses, services, social networks etc are taking advantage o f this trend Every day, there are hundreds o f millions o f people doing business on-line When transactions are performed on-line, the chance that two or more people w ill want the same product at the same time is inevitable It is a critical problem especially when it relates to money In term o f database management systems (DBMS), there is a mechanism to deal with this issue: concurrcncy control Since ¡I is important in designing a database system, the initial objective o f this paper is to provide a better understanding about concurrency control and its effect on a database management system Building a simple airline reservation system as a demonstration system to investigate differences among isolation levels o f transactions is another main objective o f this project M otivation Among many interesting topics about computer science, I decided to choose topic uairline reservation system using concurrency согПгоГ for my graduation thesis for the following reasons: First concurrency control o f transactions is a problem that must be considered in the design o f most commercial systems The accuracy and consistency o f data always are two important properties in a database management system However, when two or more transactions are performed simultaneously (especially when both try to update the same data at the same time), these two properties are more likely to be broken With concurrency control, the occurance o f inconsistent data is lower Unfortunately, in most undergraduate courses, concurrency control is not a subject covered in depth A t university, there are many subjects about programming languages, database management system, data structure algorithm or information system etc With this knowledge, a student can have an overall picture o f a system but this is not sufficient In case o f a real commercial system, there are many issues that need to be concerned and concurrency control is one o f them Thus, learning concurrency control o f transactions would help an undergraduate student have a better knowledge o f database management systems Lastly but most importantly, working in database field always brings me lot o f excitement Despite o f its hardness, database management system is an interesting subject In addition, since concurrency control is an important technique in database technologies, seizing the essence o f this matter is a competitive advantage for me in future jobs C ustom er Here is your reservation information: You have ordered for seat(s) of the flight Do you agree to make reservation with the above information? I f yes, please click, on "commit" button, otherwise click on "rollback" button Commit Rollback Customer Please enter your personal information Fullname 产 Address:* Phone* E-mail: Credit Card Number:* [ Submit I 故 肌 淡 «1■있 However, when Customer “ commits” his transaction,the commit rails and he cannot have the seats (see the below picture o f home page after this transaction) When clicking on “ commit, ,button, he might think that he has the seats but he does not Actually, the system aborts his transaction —~— — Flight N uniter ị ĩ V ĨA I-1000 h — Destmation Ha Ho Chi Noi Minh of Scat Seat price 2009-12-20 10 ІА9 Ѳ Bo,.»k now 2009-12-21 10 І50 Book now I'Turnber Date Available Seats H, W A L - 1001 From place Chi H a Noi Minh There is no record in reservation table for Customer (see the following image) Maybe he is not allowed to commit an update statement on data that has been read by the earlier transaction, which has not completed yet This behavior is not mentioned in any reference material A t first, I thought that i f Customer starts transaction first, he would get his reservation and no one could take his seats However, this system does not behave this way Even i f Customer starts transaction first, Customer still can read that data and even take the “ com m it, ,rig h t from Customer It means Customer is no longer granted his reservation This behavior is unexpected and not what is documented I f Customer clicks “ check availability” first or in other words, he starts a transaction first, the Customer is expected to not have ability o f checking availability When I searched on MySQL bugs for this problem, there is a long discussion about this issue Many people believe that this behavior is incorrect (Xuesong Zhang 2005) It seems that this is a serious bug in MySQL It also seems like this situation may causing a deadlock Both customers are allowed to read Because each may have some kind o f read lock, it means that neither 46 Customer can proceed to a write because each is waiting for the other to release the read lock But it would take further experimentation to decide i f this way actually the case or not 47 Chapter Summary and Conclusions Concurrency control is an interesting topic and have learned a lot Before undertaking this project, I not really understand about transactions and concurrent transaction issues when designing a system I used to think that to have a good system; it is important to ensure that every single execution statement works well without noticing the possibility o f transaction failure However, a failure somewhere in a transaction w ill lead to inconsistent data o f the whole transaction In terms o f databases, lack o f accuracy and inconsistencies o f data are costly Therefore, it is significant to have knowledge o f transactions and methods o f maintaining proper transactions Concurrency control is remarkable mechanism in maintaining concurrent transaction Thanks to this project, now I have a better understanding about transaction and concurrency control method Nevertheless, while conducting this project, especially when building the airline reservation system as demo system I have encountered many problems Though this system is just a very simple one, with simple reservation function, it fully contains many potential problems that may happen in reality The most challenging thing in this project is that under those simple, easy to understand theory, many things still are not explained clearly The problems that I mentioned in part are some o f these When first researching about concurrency control in general and transaction isolation level in particular, Ỉ thought that I understood all o f this theory and building a demo system would not be so difficult However, the reality is opposite I hardly found any material using web-based to crea:e a demo system for demonstrating differences among four isolation levels It was an 48 extreme problem when I wanted to break a transaction into smaller critical points so that I can let other transactions jump in and compete It is the time when I got problem o f lost connection Moreover, the unexpected result when running the demo system somehow confused me I am not sure I did it correct or not But after searching for bugs in concurrency control and isolation levels, it is likely that this is a real problem As a result, the unexpected results in Serializable isolation level mentioned in this project can be considered as the finding o f new bugs In such a short time, this project might be conducted with some inevitable limitations The simple airline reservation system cannot help demonstrate all cases you may encounter when performing concurrent transactions In addition, there are a question o f what w ill happen i f there is a hundred o f transaction performed concurrently? W ill this system behave the same way? What is the solution for a real system? In the future, i f I have a chance to further research, building a real complex demo system and testing in Internet environment with a large number o f users w ill give evidence that is more convincing 49 References DuBois p 2009,MySQL 4th edn, Addison-Wesley, New Jersey Garcia-Molina, H, Ullman, J, Widon, J 2009,Database Systems The Complete Book, 2nd edn, Pearson Prentice Hall, New Jersey Hoffer, J, Prescott, M & McFadden,F 2004,Modern Database Management,7th edn, Pearson Prentice Hall, New Jersey IBM 2009,'Pessimistic vs Optimistic Concurrency Control’ , SQL Guide, viewed 20 November, 2009, Sun Microsystems 2009,M ysql 5.1 Reference Manual, viewed 10 November, 2009 Wikipedia 2009a, ACID, viewed 12 November, 2009, Wikipedia 2009b, Concurrency control 2009,viewed 15 November, 2009, Xuesong Zhang 2005,Bug # 12714: Inconsistent non-locking read when isolation level serializable, viewed 28 November, 2009 50 Appendix Application Code PHP Code Config.php