LeongHW, SOC, NUS (UIT2201:3 Database) Page 1 Copyright © 2007-9 by Leong Hon Wai Database – Info Storage and Retrieval  Aim: Understand basics of  Info.

Slides:



Advertisements
Similar presentations
Reconcile a Bank Statement
Advertisements

Balancing Your Checking Account All firms must reconcile their check book balances with the balances reported to them by their banks.
LeongHW, SoC, NUS (UIT2201: Algorithms) Page 1 © Leong Hon Wai, Animation of Algorithm Goal: To understand an algorithm by animating its execution,
Concurrency Control WXES 2103 Database. Content Concurrency Problems Concurrency Control Concurrency Control Approaches.
Crash Recovery John Ortiz. Lecture 22Crash Recovery2 Review: The ACID properties  Atomicity: All actions in the transaction happen, or none happens 
1 Lecture 11: Transactions: Concurrency. 2 Overview Transactions Concurrency Control Locking Transactions in SQL.
Accessing data Transactions. Agenda Questions from last class? Transactions concurrency Locking rollback.
Fan Qi Database Lab 1, com1 #01-08 CS3223 Tutorial 10.
CIS 720 Lecture 2. Concurrency …shared variable declaration…. …shared variable initialization… co P 1 // P 2 // P 3 // P 4 oc Execution of P 1 … P 4 starts.
CSC271 Database Systems Lecture # 32.
LeongHW, SoC, NUS (UIT2201: Algorithms) Page 1 Animation of Algorithm Goal: To understand an algorithm by animating its execution, step-by-step. Algorithm:
LeongHW, SOC, NUS (UIT2201:3 Database) Page 1 Copyright © by Leong Hon Wai Database – Info Storage and Retrieval  Aim: Understand basics of  Info.
Data and Database Administration Chapter 12. Outline What is Concurrency Control? Background Serializability  Locking mechanisms.
CSE 486/586, Spring 2014 CSE 486/586 Distributed Systems Concurrency Control Steve Ko Computer Sciences and Engineering University at Buffalo.
1 Lecture 8: Data structures for databases II Jose M. Peña
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 16 – Intro. to Transactions.
CS444/CS544 Operating Systems Synchronization 2/16/2006 Prof. Searleman
1 Transaction Management Database recovery Concurrency control.
Transactions and concurrency control
Hacking ATMs: The Difficulties of Sharing Information Presented by Eli Kosminsky.
Chapter 1 Database and Database Users Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
Academic Year 2014 Spring Academic Year 2014 Spring.
Concurrency Recitation – 2/24 Nisarg Raval Slides by Prof. Landon Cox.
LeongHW, SoC-USP, NUS (UTT2201: Introduction) Page 1 © Leong Hon Wai, UIT2201: Lecture 1  Lecture Outline: 1.The Pervasive Computer 2.Examples.
LeongHW, SOC, NUS (UIT2201:3 Database) Page 1 Copyright © by Leong Hon Wai Database – Info Storage and Retrieval  Aim: Understand basics of  Info.
08_Transactions_LECTURE2 DBMSs should guarantee ACID properties (Atomicity, Consistency, Isolation, Durability). This is typically done by guaranteeing.
LeongHW, SoC, NUS (UIT2201: Database) Page 1 © Leong Hon Wai, Animation of SQL Queries To illustrate three SQL queries: –Q1: simple select (one.
LeongHW, SOC, NUS (UIT2201:3 Database) Page 1 Copyright © by Leong Hon Wai Database – Info Storage and Retrieval  Aim: Understand basics of  Info.
LeongHW, SoC, NUS (UIT2201: AI) Page 1 © Leong Hon Wai, Integrating Different Ideas Together  Reading Materials:  Ch 3.6 of [SG]  Contents:
DAY 12: DATABASE CONCEPT Tazin Afrin September 26,
Transaction processing Book, chapter 6.6. Problem: With a single user…. you run a query, you get the results, you run the next, etc. But database life.
Optimistic Design 1. Guarded Methods Do something based on the fact that one or more objects have particular states  Make a set of purchases assuming.
Advantage of File-oriented system: it provides useful historical information about how data are managed earlier. File-oriented systems create many problems.
Introduction to Database Systems1. 2 Basic Definitions Mini-world Some part of the real world about which data is stored in a database. Data Known facts.
INFO1408 Database Design Concepts Week 16: Introduction to Database Management Systems Continued.
The Relational Model1 Transaction Processing Units of Work.
Check Registers pp SECTION. Click to edit Master text styles Second level Third level Fourth level Fifth level 2 SECTION Copyright © Glencoe/McGraw-Hill.
LeongHW, SoC, NUS (UIT2201: Networks) Page 1© Leong Hon Wai, (MACP) Medium Access Control Protocol.
LeongHW, SoC&USP, NUS (UTT2201: Introduction) Page 1 © Leong Hon Wai, UIT2201 Project (25%) [Fall 2013]  Project Info is Online  Team size:
CSC 240 (Blum)1 Database Transactions. CSC 240 (Blum)2 Transaction  A transaction is an interaction between a user (or application) and a database. A.
© Leong Hon Wai, LeongHW, SoC, NUS (UIT2201: Algorithms) Page 1 Animation of Algorithm Goal: To understand an algorithm by animating its execution,
Transaction Management Transparencies. ©Pearson Education 2009 Chapter 14 - Objectives Function and importance of transactions. Properties of transactions.
Hon Wai Leong, NUS (CS5234, 16 Oct 2007) Page L09.1 Copyright © 2007 by Leong Hon Wai UIT2201 Spring 2010 Notices and Reminders.
What’s in the Box DBMS Features. Access Specific S13 MIS 2 “Form” screen construction to support “stand alone” applications Report Contents are Tables.
Instructor: Craig Duckett Lecture 07: Tuesday, October 20 th, 2015 Conflicts and Isolation, MySQL Workbench 1 BIT275: Database Design (Fall 2015)
Inconsistent retrieval (is locking enough CC? NO!) ________ - |ACCOUNTS| _____ - ' | | |AUDIT| >___' | ____ |CHECKING|
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 16 – Intro. to Transactions.
BANK RESEARCH MAKE A TABLE WITH THE FOLLOWING INFORMATION.
Managing Hierarchies of Database Elements Section 18.6 CS257 Jack Price.
COMP 430 Intro. to Database Systems Transactions, concurrency, & ACID.
LeongHW, SoC&USP, NUS (UTT2201: Introduction) Page 1 © Leong Hon Wai, UIT2201: CS & IT Revolution  Assessment:  Participation: 05 %  Tutorials:20.
Types of Bank Accounts Checking – The owner of the account can make deposits, withdrawals and write checks against the balance Savings – The owner of the.
CSE 486/586 CSE 486/586 Distributed Systems Concurrency Control Steve Ko Computer Sciences and Engineering University at Buffalo.
I Wanted To Order This Book
Concurrency Control Managing Hierarchies of Database Elements (18.6)
Transactions Won’t Update or Download in Quicken More info : update-or-download-in-quicken-the-balance/
Ch 21: Transaction Processing
CSE 486/586 Distributed Systems Concurrency Control --- 1
Accessing Your MySQL Database from the Web with PHP (Ch 11)
Instructor: Craig Duckett
Database Security Transactions
SECTION 4-4 Bank Statements pp
SECTION 7-1 Account Statements pp
SECTION 4-3 Check Registers pp
SECTION 5-3 Account Statements pp
Lab4 PROGRAMMING 1 exercise chapter3.
Finding Interest and amount Start.
CSE 486/586 Distributed Systems Concurrency Control --- 1
CSE 332: Concurrency and Locks
Lesson 6-2 (GJ) BANK STATEMENT Lesson 6-2, page 125.
Presentation transcript:

LeongHW, SOC, NUS (UIT2201:3 Database) Page 1 Copyright © by Leong Hon Wai Database – Info Storage and Retrieval  Aim: Understand basics of  Info storage and Retrieval;  Database Organization;  DBMS, Query and Query Processing;  Work some simple exercises;  Concurrency Issues (in Database)  Readings:  [SG] --- Ch 13.3  Optional:  Some experiences with MySQL, Access

LeongHW, SOC, NUS (UIT2201:3 Database) Page 2 Copyright © by Leong Hon Wai

LeongHW, SOC, NUS (UIT2201:3 Database) Page 3 Copyright © by Leong Hon Wai Concurrency Issues  Concurrency  When 2 processes access S at the same time!  Can cause all kinds of problems  Important issue in all areas  Illustrate with concurrency issue in database  Readings for Concurrency Issues  Record Locking – Wikipedia u  Read [SG3] Section (pp ) u Efficient Allocation and Safe Use of Resources

LeongHW, SOC, NUS (UIT2201:3 Database) Page 4 Copyright © by Leong Hon Wai Concurrency Issue: Example  Bank account info: Withdraw-P (amt); begin check balance; bal  bal - amt; end; Deposit-P (amt); begin check balance; bal  bal + amt; end;  Deposit and Withdrawal Processes B ANK -A CCOUNT-DB Account #NameBalanceOther Info… Albert Bank5000…

LeongHW, SOC, NUS (UIT2201:3 Database) Page 5 Copyright © by Leong Hon Wai Normal Operations (1/2) Bank-Account-DB Withdraw-P(1000);Deposit-P(2000); TWTW TDTD Time Withdraw-P(1000) Deposit(2000) Balance TWTW Check balance [5000]5000 T W +1Bal  Bal – TDTD Check balance [4000]4000 T D +1Bal  Bal If (T W < T D ), then Correct balance

LeongHW, SOC, NUS (UIT2201:3 Database) Page 6 Copyright © by Leong Hon Wai Normal Operations (2/2) Bank-Account-DB Withdraw-P(1000);Deposit-P(2000); TWTW TDTD Time Withdraw-P(1000) Deposit(2000) Balance TDTD Check balance [5000]5000 T D +1Bal  Bal TWTW Check balance [7000]7000 T W +1Bal  Bal – If (T W > T D ), then Correct balance

LeongHW, SOC, NUS (UIT2201:3 Database) Page 7 Copyright © by Leong Hon Wai Concurrency Issue (1/4) But… What if two processes accesses the same database record at the same time?  Which process get access first?  Does it matter?

LeongHW, SOC, NUS (UIT2201:3 Database) Page 8 Copyright © by Leong Hon Wai Concurrency Problem (2/4) Bank-Account-DB Withdraw-P(1000);Deposit-P(2000); TWTW TDTD Time Withdraw-P(1000) Deposit(2000) Balance TDTD Check balance [5000]5000 T D +1Check balance [5000]5000 T D +2 Bal  Bal T D +3Bal  Bal – If (T W = T D ), and Deposit-process “got in” first Wrong balance

LeongHW, SOC, NUS (UIT2201:3 Database) Page 9 Copyright © by Leong Hon Wai Concurrency Problem (2/3) Bank-Account-DB Withdraw-P(1000);Deposit-P(2000); TWTW TDTD Time Withdraw-P(1000) Deposit(2000) Balance TWTW Check balance [5000]5000 T W +1 Check balance [5000]5000 T W +2Bal  Bal – T W +3Bal  Bal If (T W = T D ), and Withdraw-process “got in” first Wrong balance

LeongHW, SOC, NUS (UIT2201:3 Database) Page 10 Copyright © by Leong Hon Wai Concurrency Problem (3/3)  Operations of the two processes are interleaved  Withdraw-Process and Deposit-Process “interfere” with each other  Wrong balance for both cases  Since one of the operations is over-written

LeongHW, SOC, NUS (UIT2201:3 Database) Page 11 Copyright © by Leong Hon Wai Concurrency Solution: Lock operation IDEA: If one process P is changing balance, make sure that other processes do not access the same balance until P is done Solution: The process that “get-in” first, locks up the record. This makes sure other processes will not be to access the same record. Unlock the record after update is done.

LeongHW, SOC, NUS (UIT2201:3 Database) Page 12 Copyright © by Leong Hon Wai Concurrency Solution: (2/4) Withdraw-P (amt); begin Get & lock record; bal  bal - amt; unlock record; end; Deposit-P (amt); begin Get & lock record; bal  bal + amt; unlock record; end;  Deposit and Withdrawal Processes Bank-Account-DB

LeongHW, SOC, NUS (UIT2201:3 Database) Page 13 Copyright © by Leong Hon Wai Concurrency Solution: (3/4) Bank-Account-DB Withdraw-P(1000);Deposit-P(2000); TWTW TDTD Time Withdraw-P(1000) Deposit(2000) Balance TWTW Get & Lock record;5000 T W +1 Get...; [blocked]5000 T W +2Bal  Bal – 1000; Unlock record; 4000 T W +3Get & Lock record;4000 T W +4Bal  Bal ; Unlock record; 6000 If (T W = T D ), and Withdraw-process “got in” first

LeongHW, SOC, NUS (UIT2201:3 Database) Page 14 Copyright © by Leong Hon Wai Concurrency Solution: (4/4) Bank-Account-DB Withdraw-P(1000);Deposit-P(2000); TWTW TDTD Time Withdraw-P(1000) Deposit(2000) Balance TWTW Get & Lock record;5000 T W +1Get...; [blocked]5000 T W +2Bal  Bal ; Unlock record; 7000 T W +3Get & Lock record;7000 T W +4Bal  Bal – 1000; Unlock record; 6000 If (T W = T D ), and Deposit-process “got in” first

LeongHW, SOC, NUS (UIT2201:3 Database) Page 15 Copyright © by Leong Hon Wai

LeongHW, SOC, NUS (UIT2201:3 Database) Page 16 Copyright © by Leong Hon Wai Thank you!