Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database...

36
Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture 10 Presented By: Miss N. Nembhard

Transcript of Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database...

Page 1: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Distributed Databases

Reference Books:

An introduction to Database Systems - By C.J.

Database Systems and Concepts – Silberchatz, Korth and Sudarshan

Lecture 10Presented By: Miss N.

Nembhard

Page 2: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Definition of Distributed Database:

• A distributed database system consists of a collection of sites, connected together via some kind of communication network, in which:

a. Each site is a full database system site in its own right.

b. The sites have agreed to work together so that a user at any site can access data anywhere in the network exactly as if the data were all stored at the user’s own site.

Page 3: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Communication

network

New YorkShanghai

London San Francisco

A typical distributed database system:

Page 4: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

The Fundamental Principle of Distributed Database

“To the user, a distributed system should look

exactly like a non-distributed system.”

Page 5: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Distributed Database System

• A distributed database system consists of loosely coupled sites that share no physical component.

• Database systems that run on each site are independent of each other.

• Transactions may access data at one or more sites.

Page 6: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Homogeneous Distributed Databases

• In a homogeneous distributed database– All sites have identical software

– Are aware of each other and agree to cooperate in processing user requests.

– Each site surrenders part of its autonomy in terms of right to change schemas or software

– Appears to user as a single system

Page 7: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Heterogeneous Distributed Database

• In a heterogeneous distributed database– Different sites may use different schemas and

software• Difference in schema is a major problem for query

processing• Difference in software is a major problem for

transaction processing

– Sites may not be aware of each other and may provide only limited facilities for cooperation in transaction processing

Page 8: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Distributed Data Storage

• Assume relational data model

• Replication

– System maintains multiple copies of data, stored in different sites, for faster retrieval and fault tolerance.

• Fragmentation

– Relation is partitioned into several fragments stored in distinct sites

• Replication and fragmentation can be combined

– Relation is partitioned into several fragments: system maintains several identical replicas of each such fragment.

Page 9: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Data Replication

• A relation or fragment of a relation is replicated if it is stored redundantly in two or more sites.

• Full replication of a relation is the case where the relation is stored at all sites.

• Fully redundant databases are those in which every site contains a copy of the entire database.

Page 10: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Data Replication (Cont.)Data Replication (Cont.)• Advantages of Replication

– Availability: failure of site containing relation r does not result in unavailability of r is replicas exist.

– Parallelism: queries on r may be processed by several nodes in parallel.

– Reduced data transfer: relation r is available locally at each site containing a replica of r.

Page 11: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Data Replication (Cont.)Data Replication (Cont.)• Disadvantages of Replication

– Increased cost of updates: each replica of relation r must be updated.

– Increased complexity of concurrency control: concurrent updates to distinct replicas may lead to inconsistent data unless special concurrency control mechanisms are implemented.

• One solution: choose one copy as primary copy and apply concurrency control operations on primary copy

Page 12: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Data FragmentationData Fragmentation

• Division of relation r into fragments r1, r2, …, rn which contain sufficient information to reconstruct relation r.

• Horizontal fragmentation: each tuple of r is assigned to one or more fragments

• Vertical fragmentation: the schema for relation r is split into several smaller schemas

– All schemas must contain a common candidate key (or superkey) to ensure lossless join property.

– A special attribute, the tuple-id attribute may be added to each schema to serve as a candidate key.

Page 13: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Horizontal Fragmentation of Horizontal Fragmentation of accountaccount Relation Relation

branch_name account_number balance

HillsideHillsideHillside

A-305A-226A-155

50033662

account1 = branch_name=“Hillside” (account )

branch_name account_number balance

ValleyviewValleyviewValleyviewValleyview

A-177A-402A-408A-639

205100001123750

account2 = branch_name=“Valleyview” (account )

Page 14: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Vertical Fragmentation of Vertical Fragmentation of employee_info employee_info RelationRelation

branch_name customer_name tuple_id

HillsideHillsideValleyviewValleyviewHillsideValleyviewValleyview

LowmanCampCampKahnKahnKahnGreen

deposit1 = branch_name, customer_name, tuple_id (employee_info )

1234567

account_number balance tuple_id

50033620510000621123750

1234567

A-305A-226A-177A-402A-155A-408A-639

deposit2 = account_number, balance, tuple_id (employee_info )

Page 15: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Advantages of FragmentationAdvantages of Fragmentation• Horizontal:

– allows parallel processing on fragments of a relation– allows a relation to be split so that tuples are located where

they are most frequently accessed• Vertical:

– allows tuples to be split so that each part of the tuple is stored where it is most frequently accessed

– tuple-id attribute allows efficient joining of vertical fragments

– allows parallel processing on a relation• Vertical and horizontal fragmentation can be mixed.

– Fragments may be successively fragmented to an arbitrary depth.

Page 16: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Data Transparency

• Data transparency: Degree to which system user may remain unaware of the details of how and where the data items are stored in a distributed system

• Consider transparency issues in relation to:– Fragmentation transparency

– Replication transparency

– Location transparency

Page 17: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

The 12 Objectives Of a Distributed Database System

• Local autonomy

• No reliance on a central site

• Continuous operation

• Location independence

• Fragmentation independence

• Replication independence

• Distributed query processing

• Distributed transaction management

• Hardware independence

• Operating system independence

• Network independence

• DBMS independence

Page 18: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Why study the 12 Objectives?

--Useful as:

• A basis for understanding distributed technology in general

• A framework for characterizing the functionality of specific distributed systems.

Page 19: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Objective 1

Local Autonomy

• All operations at a given site are controlled by that site.

• No site X should depend on some other site Y for its successful operation.

-- Otherwise site Y is down might mean that site X is unable to run even if there is nothing wrong with site X itself.

Page 20: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Objective 2No Reliance on a Central Site

• All sites must be treated as equals.• There must not be any reliance on a central

“master” site for some central service—for example, centralized transaction management.

Two reasons:1. The central site might be a bottleneck.2. If the central site went down, the whole system would be

down.

Page 21: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Objective 3Continuous Operation

• Provide greater reliability and greater availability – it is the advantage of distributed systems in general.

• Unplanned shutdowns are undesirable, but hard to prevent entirely.

• Planned shutdowns should never be required.

Page 22: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Objective 4Location Independence

• Also known as location transparency.

• Users should not have to know where data is physically stored, but rather should be able to behave -- as if the data were all stored at their own local site.

Page 23: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Objective 5Fragmentation Independence

• A system supports data fragmentation if a given base relation can be divided into pieces or fragments for physical storage purposes.

Two benefits:

1. most operations are local

2. reduce network traffic

Page 24: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

An example of fragmentation

EMP#EMP# DEPT#DEPT# SALARYSALARY

E1E1 D1D1 40K40K

E2E2 D1D1 42K42K

E3E3 D2D2 30K30K

E4E4 D2D2 35K35K

E5E5 D3D3 48K48K

EMP#EMP# DEPT#DEPT# SALARYSALARY

E1E1 D1D1 40K40K

E2E2 D1D1 42K42K

E5E5 D3D3 48K48K

EMP#EMP# DEPT#DEPT# SALARYSALARY

E3E3 D2D2 30K30K

E4E4 D2D2 45K45K

• Define two fragments: FRAGMENT EMP AS N_EMP AT SITE ‘New York’ WHERE DEPT# = DEPT#(‘D1’) OR DEPT# = DEPT#(‘D3’) S_EMP AT SITE ‘Shanghai’ WHERE DEPT# = DEPT#(‘D2’)

User perception

EMP

New York

N_EMP

Shanghai

S_EMP

Page 25: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Objective 6

Replication Independence• A system supports data replication if a given base

relation or fragment can be represented in storage by many distinct copies or replicas, stored at many distinct sites.

• Ideally should be “transparent to the user”.

Desirable for two reasons: 1. Applications can operate on local copies instead of remote sites.

2. At least one copy available

Page 26: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

An example of replication

EMP#EMP# DEPT#DEPT# SALARSALARYY

E1E1 D1D1 40K40K

E2E2 D1D1 42K42K

E5E5 D3D3 48K48K

EMP#EMP# DEPTDEPT##

SALARYSALARY

E3E3 D2D2 30K30K

E4E4 D2D2 35K35K

EMP#EMP# DEPT#DEPT# SALARSALARYY

E3E3 D2D2 30K30K

E4E4 D2D2 35K35K

EMP#EMP# DEPT#DEPT# SALARYSALARY

E1E1 D1D1 40K40K

E2E2 D1D1 42K42K

E5E5 D3D3 48K48K

• REPLICATE N_EMP AS SN_EMP AT SITE ‘Shanghai’; REPLICATE S_EMP AS NS_EMP AT SITE ‘New York’;

New York

N_EMP

Shanghai

NS_EMP

(S_EMP Replica)

S_EMP

SN_EMP

(N_EMPReplica)

Page 27: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Objective 7

Distributed Query Processing

• A relational distributed system is likely to outperform a nonrelational one by orders of magnitude.

• The query that involves several sites, there will be many possible ways of moving data around the system.

Page 28: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Example:

Consider Query “Get supplier numbers for London suppliers of red parts”

Database (suppliers-and-parts, simplified):

S {S#, CITY} 10,000 stored tuples at site A

P {P#, COLOR} 100,000 stored tuples at site B

SP {S#, P#} 1,000,000 stored tuples at site A

Assume every stored tuple is 25 bytes(200 bits)long.

Query (“Get supplier numbers for London suppliers of red parts”):

( ( S JOIN SP JOIN P )WHERE CITY = ‘London’ AND

COLOR = COLOR (‘Red’) ) { S# }

Estimated cardinalities of certain intermediate results:

Number of red parts = 10

Number of shipments by London suppliers = 100,000

Communication assumptions:

Data rate = 50,000 bits per second

Access delay = 0.1 second

Page 29: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

We now briefly examine three possible strategies for processing this query, and for each strategy calculate the total communication time T from the formula:

( total access delay ) + (total data volume / data rate)

1. Move parts to site A and process the query at A.

T1 = 0.1 + (100000 * 200 ) / 50000

= 400 seconds approx. (6.67minutes)

2. Move suppliers and shipments to site B and process the query at B.

T2 = 0.2 + ( ( 10000 + 1000000 ) * 200 ) / 50000

= 4040 seconds approx. (1.12 hours)

3. Restrict parts at site B to those that are red and move the result to site A. Complete the processing at site A.

T3 = 0.1 + (10 * 200 ) / 50000

= 0.1 second approx.

Page 30: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Objective 8Distributed Transaction Management

• Recovery

The system must ensure that the set of agents for that transaction either all commit in unison or all roll back in unison.

Achieved by two-phase commit protocol.

• Concurrency

Typically based on locking.

Page 31: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Objective 9

Hardware Independence• Real world involves a multiplicity of different

machines—IBM machines, HP machines, PCs and workstations of various kinds.

• Need to be able to integrate the data on all of those systems.

• Desirable to be able to run the same DBMS on different hardware platform.

Page 32: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Objective 10Operating System Independence

• Be able to run the same DBMS on different operating system platforms.

• Have (e.g.) an OS/390 version and a UNIX version and a Windows version all participate in the same distributed system.

Page 33: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Objective 11

Network Independence

• Desirable to be able to support a variety of disparate communication networks also.

Page 34: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Objective 12

DBMS Independence

• All needed is that the DBMS instances at different sites all support the same interface– they don’t necessarily all of the same DBMS software.

For example, if Ingres and Oracle both supported the official SQL standard, the Ingres site and the Oracle site might be able to talk to each other in a distributed database system.

Page 35: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

GATEWAYIngres

(SQL)

Oracle

(SQL)

Ingres

database

Oracle

databaseIngres user

Distributed Ingres database

A hypothetical Ingres–provided gateway to Oracle:

Site X Site Y

Page 36: Distributed Databases Reference Books: An introduction to Database Systems - By C.J. Database Systems and Concepts – Silberchatz, Korth and Sudarshan Lecture.

Thank you!