0% found this document useful (0 votes)
21 views33 pages

Transaction Conceptplustcpip

Hpbose tcl

Uploaded by

Tarun Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views33 pages

Transaction Conceptplustcpip

Hpbose tcl

Uploaded by

Tarun Thakur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 33

Transaction Processing Concepts

Tarun Thakur
Single-User Vs. Multi-User System

• A DBMS is single-user if at most one user at a


time can use the system
• A DBMS is multi-user if many user can use the
system concurrently
• In a multi DBMS, the stored data items are the
primary resources that may be accessed
concurrently by user programs, which are
constantly retrieving information from and
modifying the database. The execution of a
program that accesses or change the contents of
the database is called a transaction.
Transaction Support
Transaction
Action, or series of actions, carried out by user or
application, which accesses or changes contents of
database.
• Logical unit of work on the database.
• Application program is series of transactions with
non-database processing in between.
• Transforms database from one consistent state to
another, although consistency may be violated
during transaction. (If the system crashes, each
transaction's changes are reflected in the
persistent database either entirely or not at all.)
Transaction Example

Case Study 1:- Suppose a db system has to


execute a transaction say(t1) that transfers
Rs. 500/- from account A to account B.
Transaction Support
• Begin Transaction:
Get Balanace from account a
Calcualte balance as A-500
Store new balance into database file
Get Balance from account B
Calculate new balance as B+500
Store new balance into database file
Logical Operations
• Read (A)
• A=A-500
• Write A
• Read (B)
• B=B+500
• Write B
Either all the six steps are carried out or none
of them are carried out. Suppose a failure
occurs after the execution of first three steps .
Now, due to some sys. Failure the rest of
steps cannot be carried out. At this point Rs.
500 has been withdrawn from ac A but not
added to ac B. which will create inconsistency
in db.Therefore
Transaction Support
– A transaction is a sequence of one or more SQL
operations treated as a unit ( another working
definition).
– SQL standard (and Oracle):
– Transaction begins automatically when first SQL
command is issued.
– Transaction ends (and new one begins) when
"COMMIT" command is issued or session ends.
– Alternative "AUTO COMMIT" mode turns each
statement into a transaction.
Transaction Example
• Book passenger Smith on Flight QF9 on
22/10/99 in seat A22
• 1.INSERT INTO PASSENGER VALUES
(‘Simth’,’98198333’,’VISA’,’4940123456781234’);
2. INSERT INTO SEAT VALUES
(‘QF9’,’22-10-99’,’A22’,’Smith’,’Vegetarian’);
3. INSERT FLIGHT SET seats_left = seats_left -1
WHERE flight_code = ‘QF9’ AND flight_data = ’22-10-
99’;
step 1 by itself is inconsistent
step 1&2 without step 3 would make seats_left inconsistent
Step 1,2 &3 make sense together.
Transaction Support
• Can have one of two outcomes:
– Success - transaction commits and database reaches a
new consistent state.
– Failure - transaction aborts, and database must be
restored to consistent state before it started.
– Such a transaction is rolled back or undone.
• Committed transaction cannot be aborted.
• Aborted transaction that is rolled back can
be restarted later.
Properties of Transactions
•Four basic (ACID) properties of a transaction are:
Atomicity , Consistency, Isolation and Durability
Atomicity Each transaction's operations are
executed all-or-nothing, never left "half done."
•E.g., If system crashes before transaction commits, no
effects of transaction remain in database - transaction can
start over when system comes back up.
•E.g., If error or exception occurs during a transaction,
partial effects of the transaction are undone.
•Question: How is this guarantee achieved?
•Implemented by COMMIT and ROLLBACK
Properties of Transactions
Consistency Must transform database from
one consistent state to another.
Implemented by database integrity
constraints.
Properties of Transactions
Isolation Partial effects of incomplete
transactions should not be visible to other
transactions.
Implemented by locking
•Two transactions can be executed in perfect isolation if they run
serially
•However, running transactions strictly serially results in low
throughput and poor response time
•To improve efficiency, transactions can be interleaved. This is
called concurrency.
•The operations of one transaction can be freely interleaved with
another so long as they do not conflict( operate on the same data)
•Transaction can run concurrently
Properties of Transactions
Durability Effects of a committed transaction
are permanent and must not be lost because
of later failure.
Implemented by transaction logging and
recovery
Concurrency Control
Process of managing simultaneous operations on
the database without having them interfere with
one another.( Centralized system with concurrent
access by several users)

• Prevents interference when two or more users are


accessing database simultaneously and at least
one is updating data.
• Although two transactions may be correct in
themselves, interleaving of operations may
produce an incorrect result.
Transaction
It is a series of SQL statements that either fails or
succeeds as a unit. Transaction provides consistency
and robustness. Robustness refers to the ability of a
program to recover following an error and to continue
operating within its environment.
Transaction is composed of one or more DML or DDL
statements. For every transaction in oracle one of
two situations occurs.
1) If transaction completes normally the effects of
transaction are made permanent in the database.
This is known as committing the transaction or
2) A situation in which any one of statement is unable
to complete for whatever reason. In this case the
effects of transaction are removed from database
and transaction ends. This is called rolling back of
the transaction
The events possible in the
transaction are:-
• Connecting to Oracle
• Disconnecting from Oracle
• Committing changes to the database table
• Rollback
PL/SQL provides three types of
transaction specifications
• COMMIT:- which ends the transaction and
makes permanent any changes made during the
transaction.
• SAVEPOINT:- marks and saves the current
point in the processing of a transaction. It
allows you to perform partial ROLLBACKS.
• ROLLBACK :- does exactly the opposite of
COMMIT. It ends the transaction without
making changes.
Using COMMIT
To save the changes made to the database , we need to COMMIT the transaction.
Until you perform a COMMIT the following principles characterize state of
your transaction:-
• DML operations only affect the database buffer, so if you want that change
does not affect your db , you can undo all changes
• A rollback segment buffer is created in the server.
• The effects of transaction are only viewed to the transaction.
• Other users of database cannot see the effects of transaction
• The affected rows are locked and other users cannot change the data within the
affected rows.
AFTER the COMMIT is executed:-
• Locks held on affected rows are released.
• The transaction is marked complete
• The internal transaction table of the server generates a system change number,
assigns the number to the transaction and saves them both in the table.
• To save the changes permanently COMMIT is used:-

COMMIT [WORK] [COMMENT text];

Work is optional and comment is also optional and can be of maximum


50 characters length, enclosed in single quotation marks

Eg.:-
COMMIT
COMMIT WORK
COMMIT COMMENT ‘Student Record’
COMMIT WORK COMMENT ‘Student Record’
ROLLBACK an entire
transaction
• All changes made by the current transaction
are undone
• All locks on rows caused by transaction are
released
• Transaction is ended
ROLLBACK to a savepoint
• Only the SQL statements executed after last
savepoint is rolled back
• The specified savepoint in the ROLLBACK
command is preserved , but all other
savepoints after that savepoints are removed
from database
• All locks established since the specified
savepoint are released
• The transaction is still active and can continue
Syntax ROLLBACK
ROLLBACK [WORK]
[TO[SAVEPOINT]<savepoint>]

To rollback a transaction partially we need to


create SAVEPOINTS
SAVEPOINT statements
• It is like a bookmark in transaction. It can
be referenced later.
• Breaking a large transaction can be done
using SAVEPOINTS
SAVEPOINT<savepoint_name>;
EXAMPLE of SAVEPOINT
BEGIN
insert into emp_rec(emp_id) values (‘1001’); SAVEPOINT X;
insert into emp_rec(emp_id) values (‘1002’); SAVEPOINT Y;
insert into emp_rec(emp_id) values (‘1003’); SAVEPOINT Z;
……
……
COMMIT;
END;
If we apply ROLLBACK TO Y;
Then the third insert and SAVEPOINT will be undone , but the
first two will be processed
DECLARE
Choice char(1);
BEGIN
insert into employee(emp_id,emp_name,job) values (1001,’Mohit’,’Manager’);
UPDATE employee SET job=‘Typist’ where emp_id=1001;
SAVEPOINT A;
DELETE from employee where emp_id=1001;
Choice :=‘rollback’;
IF Choice=‘Y’ THEN ROLLBACK;
DBMS_OUTPUT.PUT_LINE(‘complete rollback’);
ELSIF Choice=‘N’ THEN ROLLBACK TO A;
DBMS_OUTPUT.PUT_LINE(‘partial rollback’);
ELSE
COMMIT;
DBMS_OUTPUT.PUT_LINE(‘Transaction Completed’);
END IF;
END;
TCP/IP PROTOCOL SUITE

Communications between computers on a network is done through


protocol suits. The most widely used and most widely available
protocol suite is TCP/IP protocol suite. A protocol suit consists of a
layered architecture where each layer depicts some functionality
which can be carried out by a protocol. Each layer usually has
more than one protocol options to carry out the responsibility that
the layer adheres to. TCP/IP is normally considered to be a 4 layer
system.
TCP/IP
Has two major components
• TCP
• IP
Transmission
Control Protocol
• Breaks data into packets that the network
can handle efficiently
• Verifies that all the packets arrive at the
destination
• Reassembles the data
IP
• Envelops and address the data
• Enables the network to read the envelope
and forward the data to its destination
• Defines how much data can fit into a single
envelope
Simple explanation
• Suppose you are transferred from delhi to mumbai.
You pack your things in your house in boxes and put
your new address on them. The courier company
picks them up makes shifting across the state along
the most efficient route. Your belomgings arrive at
your own address. You consult your list to make sure
that everything has arrived, then you unpack your
boxes and reassemble various things at your home.
Here the various things are data, boxes are data
packets and route is network path
• Packing the things in various boxes is
equivalent to breaking the data into various
packets . TCP does it
• The contents or the capacity of boxes is
decided by IP. Putting new address to boxes
is equivalent to addressing the data-IP do it.

You might also like