Transaction
Transaction
Transaction
T1 T2
1. read(A)
2. A := A – 50
3. write(A)
read(A), read(B), print(A+B)
4. read(B)
5. B := B + 50
6. write(B)
• Deadlock prevention protocols ensure that the system will never enter
into a deadlock state. Some prevention strategies:
– Require that each transaction locks all its data items before it
begins execution (pre-declaration).
– Impose partial ordering of all data items and require that a
transaction can lock data items only in the order specified by the
Distributed Database
• 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
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
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
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.
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
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.
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
Data 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.
Advantage and DisAdvantages
• 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.
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
Concurrency Control
• Modify concurrency control schemes for use in
distributed environment.
– We assume that each site participates in the execution of
a commit protocol to ensure global transaction atomicity.
– We assume all replicas of any item are updated
– Will see how to relax this in case of site failures later
Single-Lock-Manager Approach
• System maintains a single lock manager that resides in a single chosen
site, say Si
• When a transaction needs to lock a data item, it sends a lock request to Si
and lock manager determines whether the lock can be granted immediately
• If yes, lock manager sends a message to the site which initiated the request
• If no, request is delayed until it can be granted, at which time a message is
sent to the initiating site
• The transaction can read the data item from any one of the sites at which a
replica of the data item resides.
• Writes must be performed on all replicas of a data item
Advantages of scheme:
• Simple implementation
• Simple deadlock handling
Disadvantages of scheme :
• Bottleneck: lock manager site becomes a bottleneck
• Vulnerability: system is vulnerable to lock manager site failure
Distributed Lock Manager
• In this approach, functionality of locking is implemented by lock
managers at each site
– Lock managers control access to local data items
– But special protocols may be used for replicas
Advantage:
– work is distributed and can be made robust to failures
• Disadvantage:
– deadlock detection is more complicated
– Lock managers cooperate for deadlock detection
Several variants of this approach
– Primary copy
– Majority protocol
– Biased protocol
Directory Systems
• Typical kinds of directory information
• Employee information such as name, id, email, phone, office
addr, ..
• Even personal information to be accessed from multiple places
e.g. Web browser bookmarks
White pages
• Entries organized by name or identifier
– Meant for forward lookup to find more about an entry
Yellow pages
• Entries organized by properties
• For reverse lookup to find entries matching specific requirements
When directories are to be accessed across an organization
• Alternative 1: Web interface. Not great for programs
• Alternative 2: Specialized directory access protocols
Directory Access Protocols
• Most commonly used directory access protocol:
– LDAP (Lightweight Directory Access Protocol)
– Simplified from earlier X.500 protocol
– Question: Why not use database protocols like
ODBC/JDBC?
– Answer: Simplified protocols for a limited type of data
access, evolved parallel to ODBC/JDBC
– Provide a nice hierarchical naming mechanism similar to
file system directories
– Data can be partitioned amongst multiple servers for
different parts of the hierarchy, yet give a single view to
user – E.g. different servers for Bell Labs Murray Hill and
Bell Labs Bangalore
Distributed Directory Trees
• Organizational information may be split into multiple directory information
trees
• Suffix of a DIT gives RDN to be tagged onto to all entries to get an overall
DN
• E.g. two DITs, one with suffix o=Lucent, c=USA and another with suffix
o=Lucent, c=India Organizations often split up DITs based on
geographical location or by organizational structure
• Many LDAP implementations support replication (master-slave or
multimaster replication) of DITs (not part of LDAP 3 standard)
• A node in a DIT may be a referral to a node in another DIT
• E.g. Ou= Bell Labs may have a separate DIT, and DIT for o=Lucent may
have a leaf with ou=Bell Labs containing a referral to the Bell Labs DIT
• Refer alls are the key to integrating a distributed collection of directories
• When a server gets a query reaching a referral node, it may either
• Forward query to referred DIT and return answer to client, or
• Give referral back to client, which transparently sends query to referred DIT
Implementation Issues for Distributed Databases
• Atomicity needed even for transactions that update data at multiple
sites
• The two-phase commit protocol (2PC) is used to ensure atomicity
– Basic idea: each site executes transaction until just before commit,
and the leaves final decision to a coordinator
– Each site must follow decision of coordinator, even if there is a
failure while waiting for coordinators decision
• 2PC is not always appropriate: other transaction models based on
persistent messaging, and workflows, are also used
• Distributed concurrency control (and deadlock detection) required
• Data items may be replicated to improve data availability