• No results found

Transactions and the Internet

N/A
N/A
Protected

Academic year: 2021

Share "Transactions and the Internet"

Copied!
20
0
0

Loading.... (view fulltext now)

Full text

(1)

Transactions and the Internet

Week 12-13

(2)

Schedule

Week Date Lecture Topic

1 Jan 9 Introduction to Data Management 2 Jan 16 The Relational Model

3 Jan. 23 Constraints and SQL DDL

4 Jan. 30 SQL DML, DB Applications, JDBC 5 Feb 6 JDBC, DDL (Views, Access Control) 6 Feb 13 Relational Algebra, Advanced SQL - Feb 20 [Reading Week]

7 Feb 27 Review and Midterm (Mar 1)

8 Mar 5 OLAP

9 Mar 12 ER Conceptual Modelling 10 Mar 19 Normalization

11 Mar 26 XML and Data Integration

12 Apr 2 Transactions and the Internet, Query Processing

This week’s reading:

Chapters 18,20,22

(3)

Transaction Processing in the WWW

Browser requests information from an HTTP server

Server sends to the browser an HTML page (and possibly scripts)

User interacts with the page (and scripts) and sends information back to the server

Application on HTTP server (CGI, servlet, JSP, ASP.NET) reads information from the browser, processes it (accesses a

(4)

Three-Tiered Model of TPS

DBMS

database server machine

presentation server

• • •

client machines

communication presentation

server

application server

application server machine

(5)

Interconnection of Servers

(6)

Sessions on the Internet

HTTP sessions do not maintain context between interactions

Context information is stored in file on Web server that is accessed through a session number

Cookies: servlet places session number in a cookie file in browser; subsequent servlets can access cookie

Hidden fields in HTML: servlet places session number in hidden field in HTML document it sends to

browser; hidden field is not displayed but is returned with HTML document

Appended field to URL (HTTP return address):

session number is appended to URL return address and can be accessed by the next servlet

(7)

ACID Properties of Transactions

Transaction execution must maintain the correctness of the database model

Therefore additional requirements are placed on the execution of transactions beyond those placed on ordinary programs

Atomicity (all or nothing)

Consistency (w.r.t. Integrity Constraints)

Isolation Durability

(8)

Isolation

Serial execution of a set of (consistent) transactions is correct, but performance might be inadequate

Concurrent (interleaved) execution of a set of transactions offers performance benefits, but might not be correct

(9)

Interleaved Execution

(10)

Incorrect Interleaved Schedule

Example for course registrations: c is the number of current registrants, transaction reads and adds 1 to this number

T1: r1(c: 29) w1 (c: 30) T2: r2 (c: 29) w2 (c: 30)

Schedule not equivalent to T1, T2 or T2, T1 Database state no longer corresponds to

real-world state, integrity constraints are

(11)

Serializable Schedules

The concurrent schedule S is serializable

S: r1(a:4) r2(b:5) w2(a:5*2) r1(b:5) w1(c:4+5)

because it is equivalent to the serial schedule

T1, T2: r1(a:4) r1(b:5) w1(c:4+5) r2(b:5) w2(a:5*2)

read operations of distinct transactions on the same data item commute

S is not equivalent to T2, T1 since read and write

(12)

Commutativity

Two operations commute if, when executed in either order:

The values returned by both are the same and

The database is left in the same final state

Two schedules are equivalent if one can be derived from the other by a series of simple interchanges of commutative operations

A schedule is serializable if it is equivalent to a serial schedule

(13)

Implementing Serializability:

Two-Phase Locking

Locks are associated with each data item

A transaction must acquire a read (shared) or write (exclusive) lock on an item in order to read or write it

A write lock on an item conflicts with all other locks on the item; a read lock conflicts with a write lock

If T1 requests a lock on x and T2 holds a conflicting lock on x, T1 must wait

(14)
(15)

Atomicity and Durability

Atomicity deals with transaction aborts:

User aborts transaction (e.g., cancel button)

System aborts transaction (e.g., deadlock)

Transaction aborts itself (e.g., unexpected db state)

System crashes

Durability deals with failure:

System and Media failures

(16)

Log

Log:

Append-only sequence of records used to restore database to a consistent state after a failure.

Stored on non-volatile device distinct from mass storage device that contains database

Survives processor crash and media failure

To execute an Update:

Appended Update Record to the log when a transaction modifies an item

Contains before image: value of item prior to update

Used to restore item when transaction is aborted

(17)

Aborting a Transaction

Transaction abort:

Scan log backward; apply before image in each of the transaction’s update records to database items to restore them to their original state.

Begin Record terminates scan

B T1

U T1

B T2

U T1

U T2

U T1

U T2 B - begin

A T2

(18)

Recovery From Crash

Transaction is not committed until its Commit Record is in the log

A crash at any time before that causes transaction to be rolled back

Active transactions must be identified and aborted when system recovers

B T1

U T1

B T2

U T1

U T2

U T1

B T3

A T2

U T3

C T3

B T4

End of scan for crash recovery

U T4

End of log when crash occurs;

roll back T1 and B - begin

U - update C - commit

(19)

Write-Ahead Log

Both the log and database must be updated when a transaction modifies an item. If a crash occurs between updates, abort the transaction

Database updated first - On recovery, item is in the new state but there is no before image to roll it back.

Transaction cannot be aborted.

Log updated first - On recovery, item in old state and before image in log. Use of before image has no effect, but transaction can be aborted

Update record in log must be written-ahead of

(20)

Summary: Transactions

Architectures for TP on the Internet

Two and Three Tiers

Sessions

ACID Properties

Isolation

TP Abstraction: Schedule

Serializability, Anomalies, Commutativity

Two-phase Locking

Atomicity and Durability

Logs, Recovery

References

Related documents

gimmick sold in magic trick stores known as a D’Lite. I prefer the yellow or red colored ones. This item lets you produce a light at your fingertips. I shake hands using my right

(A and B) Representative sagittal tissue section through a maxillary implant site on post-surgery day 14, stained with Pentachrome; dotted line indicates native bone and arrows

Safety of percutaneous ultrasound-guided fine-needle aspiration of adrenal lesions in dogs: Perception of the procedure by radiologists and presentation of

Member States shall separate and allocate the components of a price to the COICOP divisions concerned where a price is charged for educational services combined

In the Swedish national numbering plan, there are currently a number of telephone numbers that strictly interpreted are not so-called E.164 numbers according to that stipulated

For all the above discussed cases concerning samples of st3s carbon steel, reinforcing steel and structural steel samples immersed in the calcium chloride solution, the

model [50], based on a quantitative theory for the strain induced transformation of retained austenite in a class of TRIP-assisted steels The model allow the progress of

The normative research stream relies upon the findings from the positive stream, but its primary focus is on the recommendations about private choices of lead firms