Distributed Databases
Distributed Databases
Features
Databases in the collection are logically interrelated with each other. Often they
represent a single logical database.
Data is physically stored across multiple sites. Data in each site can be managed by a
DBMS independent of the other sites.
The processors in the sites are connected via a network. They do not have any
multiprocessor configuration.
Features
It is used to create, retrieve, update and delete distributed databases.
It is used in application areas where large volumes of data are processed and accessed
by numerous users simultaneously.
Support for Both OLTP and OLAP − Online Transaction Processing (OLTP) and
Online Analytical Processing (OLAP) work upon diversified systems which may have
common data. Distributed database systems aid both these processing by providing
synchronized data.
Modular Development − If the system needs to be expanded to new locations or new units,
in centralized database systems, the action requires substantial efforts and disruption in the
existing functioning. However, in distributed databases, the work simply requires adding new
computers and local data to the new site and finally connecting them to the distributed
system, with no interruption in current functions.
More Reliable − In case of database failures, the total system of centralized databases
comes to a halt. However, in distributed systems, when a component fails, the functioning of
the system continues may be at a reduced performance. Hence DDBMS is more reliable.
Better Response − If data is distributed in an efficient manner, then user requests can be
met from local data itself, thus providing faster response. On the other hand, in centralized
systems, all queries have to pass through the central computer for processing, which
increases the response time.
Need for complex and expensive software − DDBMS demands complex and often
expensive software to provide data transparency and co-ordination across the several
sites.
Data integrity − The need for updating data in multiple sites pose problems of data
integrity.
The sites use identical DBMS or DBMS from the same vendor.
Each site is aware of all other sites and cooperates with other sites to process user
requests.
Autonomous − Each database is independent that functions on its own. They are
integrated by a controlling application and use message passing to share data updates.
A site may not be aware of other sites and so there is limited co-operation in processing
user requests.
Distribution − It states the physical distribution of data across the different sites.
Autonomy − It indicates the distribution of control of the database system and the
degree to which each constituent DBMS can operate independently.
Multi-database Internal Level − Depicts the data distribution across different sites
and multi-database to local data mapping.
Local database Conceptual Level − Depicts local data organization at each site.
Local database Internal Level − Depicts physical data organization at each site.
There are two design alternatives for multi-DBMS −
Data Replication
Data replication is the process of storing separate copies of the database at two or more sites.
It is a popular fault tolerance technique of distributed databases.
Increased Cost and Complexity of Data Updating − Each time a data item is
updated, the update needs to be reflected in all the copies of the data at the different
sites. This requires complex synchronization techniques and protocols.
Snapshot replication
Near-real-time replication
Pull replication
Fragmentation
Fragmentation is the task of dividing a table into a set of smaller tables. The subsets of the
table are called fragments. Fragmentation can be of three types: horizontal, vertical, and
hybrid (combination of horizontal and vertical). Horizontal fragmentation can further be
classified into two techniques: primary horizontal fragmentation and derived horizontal
fragmentation.
Fragmentation should be done in a way so that the original table can be reconstructed from
the fragments. This is needed so that the original table can be reconstructed from the
fragments whenever required. This requirement is called “reconstructiveness.”
Advantages of Fragmentation
Since data is stored close to the site of usage, efficiency of the database system is
increased.
Local query optimization techniques are sufficient for most queries since data is locally
available.
Since irrelevant data is not available at the sites, security and privacy of the database
system can be maintained.
Disadvantages of Fragmentation
When data from different fragments are required, the access speeds may be very high.
Lack of back-up copies of data in different sites may render the database ineffective in
case of failure of a site.
Vertical Fragmentation
In vertical fragmentation, the fields or columns of a table are grouped into fragments. In order
to maintain reconstructiveness, each fragment should contain the primary key field(s) of the
table. Vertical fragmentation can be used to enforce privacy of data.
For example, let us consider that a University database keeps records of all registered
students in a Student table having the following schema.
STUDENT
Now, the fees details are maintained in the accounts section. In this case, the designer will
fragment the database as follows −
FROM STUDENT;
Horizontal Fragmentation
Horizontal fragmentation groups the tuples of a table in accordance to values of one or more
fields. Horizontal fragmentation should also confirm to the rule of reconstructiveness. Each
horizontal fragment must have all columns of the original base table.
For example, in the student schema, if the details of all students of Computer Science Course
needs to be maintained at the School of Computer Science, then the designer will horizontally
fragment the database as follows −
CREATE COMP_STD AS
Hybrid Fragmentation
In hybrid fragmentation, a combination of horizontal and vertical fragmentation techniques
are used. This is the most flexible fragmentation technique since it generates fragments with
minimal extraneous information. However, reconstruction of the original table is often an
expensive task.
At first, generate a set of horizontal fragments; then generate vertical fragments from
one or more of the horizontal fragments.
At first, generate a set of vertical fragments; then generate horizontal fragments from
one or more of the vertical fragments.
Design Alternatives
The distribution design alternatives for the tables in a DDBMS are as follows −
Fully replicated
Partially replicated
Fragmented
Mixed
Non-replicated & Non-fragmented
In this design alternative, different tables are placed at different sites. Data is placed so that
it is at a close proximity to the site where it is used most. It is most suitable for database
systems where the percentage of queries needed to join information in tables placed at
different sites is low. If an appropriate distribution strategy is adopted, then this design
alternative helps to reduce the communication cost during data processing.
Fully Replicated
In this design alternative, at each site, one copy of all the database tables is stored. Since,
each site has its own copy of the entire database, queries are very fast requiring negligible
communication cost. On the contrary, the massive redundancy in data requires huge cost
during update operations. Hence, this is suitable for systems where a large number of queries
is required to be handled whereas the number of database updates is low.
Partially Replicated
Copies of tables or portions of tables are stored at different sites. The distribution of the tables
is done in accordance to the frequency of access. This takes into consideration the fact that
the frequency of accessing the tables vary considerably from site to site. The number of copies
of the tables (or portions) depends on how frequently the access queries execute and the site
which generate the access queries.
Fragmented
In this design, a table is divided into two or more pieces referred to as fragments or partitions,
and each fragment can be stored at different sites. This considers the fact that it seldom
happens that all data stored in a table is required at a given site. Moreover, fragmentation
increases parallelism and provides better disaster recovery. Here, there is only one copy of
each fragment in the system, i.e. no redundant data.
Vertical fragmentation
Horizontal fragmentation
Hybrid fragmentation
Mixed Distribution
This is a combination of fragmentation and partial replications. Here, the tables are
initially fragmented in any form (horizontal or vertical), and then these fragments
are partially replicated across the frequency of accessing the fragments.
For example, let us consider a data table PROJECT(PId, PName, PLocation). We need to run
a transaction T1 that updates PLocation to ‘Mumbai’, if PLocation is ‘Bombay’. If no replications
are there, the operations in transaction T1 will be −
Begin T1:
End T1;
If the data table has two replicas in Site A and Site B, T1 needs to spawn two children T1A
and T1B corresponding to the two sites. The expanded transaction T1 will be −
Begin T1:
Begin T1A :
End T1A;
Begin T2A :
End T2A;
End T1;
A popular method of synchronization is store and forward method. In this method, one site is
designated as the primary site and the other sites are secondary sites. The primary site always
contains updated values. All the transactions first enter the primary site. These transactions
are then queued for application in the secondary sites. The secondary sites are updated using
rollout method only when a transaction is scheduled to execute on it.
Distributed transaction application phase − Upon entering this phase, the site
where the transaction has entered, broadcasts a request to all slaves for executing the
transaction. On receiving the requests, the peer slaves execute the transaction and
send an “ACK” message to the requesting slave on completion. After the requesting
slave has received “ACK” messages from all its peers, it lets the transaction manager
know that the transaction has been completed.
Voting phase − When a transaction enters the transaction manager of a site, it sends
a transaction request to all other sites. On receiving a request, a peer site tests for
conflicts using voting rules and keeps the conflicting transactions, if any, in pending
queue. Then, it sends either an “OK” or a “NOT OK” message.
Transaction application phase − When a site receives a transaction along with its
ticket, it places the transaction for execution according to its ticket. After the
transaction has finished execution, this site broadcasts an appropriate message. A
transaction ends when it has completed execution in all the sites.
Distribution Transparency
Distribution transparency is the property of distributed databases by the virtue of which the
internal details of the distribution are hidden from the users. The DDBMS designer may choose
to fragment tables, replicate the fragments and store them at different sites. However, since
users are oblivious of these details, they find the distributed database easy to use like any
centralized database.
Location transparency
Fragmentation transparency
Replication transparency
Location Transparency
Location transparency ensures that the user can query on any table(s) or fragment(s) of a
table as if they were stored locally in the user’s site. The fact that the table or its fragments
are stored at remote site in the distributed database system, should be completely oblivious
to the end user. The address of the remote site(s) and the access mechanisms are completely
hidden.
In order to incorporate location transparency, DDBMS should have access to updated and
accurate data dictionary and DDBMS directory which contains the details of locations of data.
Fragmentation Transparency
Fragmentation transparency enables users to query upon any table as if it were
unfragmented. Thus, it hides the fact that the table the user is querying on is actually a
fragment or union of some fragments. It also conceals the fact that the fragments are located
at diverse sites.
This is somewhat similar to users of SQL views, where the user may not know that they are
using a view of a table instead of the table itself.
Replication Transparency
Replication transparency ensures that replication of databases are hidden from the users. It
enables users to query upon a table as if only a single copy of the table exists.
Combination of Transparencies
In any distributed database system, the designer should ensure that all the stated
transparencies are maintained to a considerable extent. The designer may choose to fragment
tables, replicate them and store them at different sites; all oblivious to the end user. However,
complete distribution transparency is a tough task and requires considerable design efforts.
Each high level operation can be divided into a number of low level tasks or operations. For
example, a data update operation can be divided into three tasks −
Database access is restricted to read_item() and write_item() operations. Likewise, for all
transactions, read and write forms the basic database operations.
Transaction Operations
The low level operations performed in a transaction are −
commit − A signal to specify that the transaction has been successfully completed in
its entirety and will not be undone.
rollback − A signal to specify that the transaction has been unsuccessful and so all
temporary changes in the database are undone. A committed transaction cannot be
rolled back.
Transaction States
A transaction may go through a subset of five states, active, partially committed, committed,
failed and aborted.
Active − The initial state where the transaction enters is the active state. The
transaction remains in this state while it is executing read, write or other operations.
Partially Committed − The transaction enters this state after the last statement of
the transaction has been executed.
Committed − The transaction enters this state after successful completion of the
transaction and system checks have issued commit signal.
Failed − The transaction goes from partially committed state or active state to failed
state when it is discovered that normal execution can no longer proceed or system
checks fail.
Aborted − This is the state after the transaction has been rolled back after failure and
the database has been restored to its state that was before the transaction began.
The following state transition diagram depicts the states in the transaction and the low level
transaction operations that causes change in states.
Desirable Properties of Transactions
Any transaction must maintain the ACID properties, viz. Atomicity, Consistency, Isolation,
and Durability.
Consistency − A transaction should take the database from one consistent state to
another consistent state. It should not adversely affect any data item in the database.
Types of Schedules
There are two types of schedules −
Serial Schedules − In a serial schedule, at any point of time, only one transaction is
active, i.e. there is no overlapping of transactions. This is depicted in the following
graph −
Parallel Schedules − In parallel schedules, more than one transactions are active
simultaneously, i.e. the transactions contain operations that overlap at time. This is
depicted in the following graph −
Conflicts in Schedules
In a schedule comprising of multiple transactions, a conflict occurs when two active
transactions perform non-compatible operations. Two operations are said to be in conflict,
when all of the following three conditions exists simultaneously −
At least one of the operations is a write_item() operation, i.e. it tries to modify the
data item.
Serializability
A serializable schedule of ‘n’ transactions is a parallel schedule which is equivalent to a
serial schedule comprising of the same ‘n’ transactions. A serializable schedule contains the
correctness of serial schedule while ascertaining better CPU utilization of parallel schedule.
Equivalence of Schedules
Equivalence of two schedules can be of the following types −
Result equivalence − Two schedules producing identical results are said to be result
equivalent.
View equivalence − Two schedules that perform similar action in a similar manner
are said to be view equivalent.
Conflict equivalence − Two schedules are said to be conflict equivalent if both contain
the same set of transactions and has the same order of conflicting pairs of operations.
Controlling Concurrency
Concurrency controlling techniques ensure that multiple transactions are executed
simultaneously while maintaining the ACID properties of the transactions and serializability in
the schedules.
In this chapter, we will study the various approaches for concurrency control.
Locking-based concurrency control systems can use either one-phase or two-phase locking
protocols.
These algorithms ensure that transactions commit in the order dictated by their timestamps.
An older transaction should commit before a younger transaction, since the older transaction
enters the system before the younger one.
Access Rule − When two transactions try to access the same data item
simultaneously, for conflicting operations, priority is given to the older transaction. This
causes the younger transaction to wait for the older transaction to commit first.
Late Transaction Rule − If a younger transaction has written a data item, then an
older transaction is not allowed to read or write that data item. This rule prevents the
older transaction from committing after the younger transaction has already
committed.
Younger Transaction Rule − A younger transaction can read or write a data item
that has already been written by an older transaction.
In this approach, a transaction’s life cycle is divided into the following three phases −
Rule 1 − Given two transactions Ti and Tj, if Ti is reading the data item which Tj is writing,
then Ti’s execution phase cannot overlap with Tj’s commit phase. Tj can commit only after Ti
has finished execution.
Rule 2 − Given two transactions Ti and Tj, if Ti is writing the data item that Tj is reading, then
Ti’s commit phase cannot overlap with Tj’s execution phase. Tj can start executing only after
Ti has already committed.
Rule 3 − Given two transactions Ti and Tj, if Ti is writing the data item which Tj is also writing,
then Ti’s commit phase cannot overlap with Tj’s commit phase. Tj can start to commit only
after Ti has already committed.
Depending upon the number of sites who can detect lock conflicts, distributed two-phase
locking approaches can be of three types −
For implementing timestamp ordering algorithms, each site has a scheduler that maintains a
separate queue for each transaction manager. During transaction, a transaction manager
sends a lock request to the site’s scheduler. The scheduler puts the request to the
corresponding queue in increasing timestamp order. Requests are processed from the front
of the queues in the order of their timestamps, i.e. the oldest first.
Conflict Graphs
Another method is to create conflict graphs. For this transaction classes are defined. A
transaction class contains two set of data items called read set and write set. A transaction
belongs to a particular class if the transaction’s read set is a subset of the class’ read set and
the transaction’s write set is a subset of the class’ write set. In the read phase, each
transaction issues its read requests for the data items in its read set. In the write phase, each
transaction issues its write requests.
A conflict graph is created for the classes to which active transactions belong. This contains a
set of vertical, horizontal, and diagonal edges. A vertical edge connects two nodes within a
class and denotes conflicts within the class. A horizontal edge connects two nodes across two
classes and denotes a write-write conflict among different classes. A diagonal edge connects
two nodes across two classes and denotes a write-read or a read-write conflict among two
classes.
The conflict graphs are analyzed to ascertain whether two transactions within the same class
or across two different classes can be run in parallel.
Rule 1 − According to this rule, a transaction must be validated locally at all sites when it
executes. If a transaction is found to be invalid at any site, it is aborted. Local validation
guarantees that
the transaction maintains serializability at the sites where it has been executed. After a
transaction passes local validation test, it is globally validated.
Rule 2 − According to this rule, after a transaction passes local validation test, it should be
globally validated. Global validation ensures that if two conflicting transactions run together
at more than one site, they should commit in the same relative order at all the sites they run
together. This may require a transaction to wait for the other conflicting transaction, after
validation before commit. This requirement makes the algorithm less optimistic since a
transaction may not be able to commit as soon as it is validated at a site.
Commit Protocols
In a local database system, for committing a transaction, the transaction manager has to only
convey the decision to commit to the recovery manager. However, in a distributed system,
the transaction manager should convey the decision to commit to all the servers in the various
sites where the transaction is being executed and uniformly enforce the decision. When
processing is complete at each site, it reaches the partially committed transaction state and
waits for all other transactions to reach their partially committed states. When it receives the
message that all the sites are ready to commit, it starts to commit. In a distributed system,
either all sites commit or none of them does.
One-phase commit
Two-phase commit
Three-phase commit
After each slave has locally completed its transaction, it sends a “DONE” message to
the controlling site.
The slaves wait for “Commit” or “Abort” message from the controlling site. This waiting
time is called window of vulnerability.
When the controlling site receives “DONE” message from each slave, it makes a
decision to commit or abort. This is called the commit point. Then, it sends this
message to all the slaves.
On receiving this message, a slave either commits or aborts and then sends an
acknowledgement message to the controlling site.
After each slave has locally completed its transaction, it sends a “DONE” message to
the controlling site. When the controlling site has received “DONE” message from all
slaves, it sends a “Prepare” message to the slaves.
The slaves vote on whether they still want to commit or not. If a slave wants to commit,
it sends a “Ready” message.
A slave that does not want to commit sends a “Not Ready” message. This may happen
when the slave has conflicting concurrent transactions or there is a timeout.
After the controlling site has received “Ready” message from all the slaves −
o The slaves apply the transaction and send a “Commit ACK” message to the
controlling site.
o When the controlling site receives “Commit ACK” message from all the slaves,
it considers the transaction as committed.
After the controlling site has received the first “Not Ready” message from any slave −
o The slaves abort the transaction and send a “Abort ACK” message to the
controlling site.
o When the controlling site receives “Abort ACK” message from all the slaves, it
considers the transaction as aborted.
Reliability: In distributed database system, if one system fails down or stops working for
some time another system can complete the task.
Availability: In distributed database system reliability can be achieved even if sever fails
down. Another system is available to serve the client request.
Performance: Performance can be achieved by distributing database over different locations.
So the databases are available to every location which is easy to maintain.
Types of distributed databases.
The two types of distributed systems are as follows:
Example: Consider that we have three departments using Oracle-9i for DBMS. If some
changes are made in one department then, it would update the other department also.
Example: In the following diagram, different DBMS software are accessible to each
other using ODBC and JDBC.
The basic types of distributed DBMS are as follows:
3. Middleware architecture.
What is fragmentation?
The process of dividing the database into a smaller multiple parts is called
as fragmentation.
These fragments may be stored at different locations.
The data fragmentation process should be carrried out in such a way that
the reconstruction of original database from the fragments is possible.
Types of data Fragmentation
Example:
Account (Acc_No, Balance, Branch_Name, Type).
In this example if values are inserted in table Branch_Name as Pune, Baroda,
Delhi.
Example:
For the above table we can define any simple condition like, Branch_Name=
'Pune', Branch_Name= 'Delhi', Balance < 50,000
Fragmentation1:
SELECT * FROM Account WHERE Branch_Name= 'Pune' AND Balance <
50,000
Fragmentation2:
SELECT * FROM Account WHERE Branch_Name= 'Delhi' AND Balance <
50,000
Fragmentation1:
SELECT * FROM Account WHERE Branch_Name= 'Baroda' AND Balance <
50,000
Fragmentation2:
SELECT * FROM Account WHERE Branch_Name= 'Delhi' AND Balance <
50,000
Example:
Fragmentation1:
SELECT * FROM Acc_NO
Fragmentation2:
SELECT * FROM Balance
3) Hybrid Fragmentation
Fragmentation1:
SELECT * FROM Emp_Name WHERE Emp_Age < 40
Fragmentation2:
SELECT * FROM Emp_Id WHERE Emp_Address= 'Pune' AND Salary <
14000
1. Synchronous Replication:
In synchronous replication, the replica will be modified immediately after
some changes are made in the relation table. So there is no difference
between original data and replica.
2. Asynchronous replication:
In asynchronous replication, the replica will be modified after commit is fired
on to the database.
Replication Schemes
1. Full Replication
2. No Replication
3. Partial replication
Partial replication means only some fragments are replicated from the
database.
Advantages of partial replication
The number of replicas created for fragments depend upon the importance of
data in that fragment.
Distributed Transactions
For example:
Consider that, location A sends message to location B and expects response
from B but B is unable to receive it. There are several problems for this
situation which are as follows.
Message was failed due to failure in the network.
Location B sent message but not delivered to location A.
Location B crashed down.
So it is actually very difficult to find the cause of failure in a large
communication network.
Distributed commit in the network is also a serious problem which can affect
the recovery in a distributed databases.
Two-phase commit protocol in Distributed databases
Commit request:
In commit phase the coordinator attempts to prepare all cohorts and take
necessary steps to commit or terminate the transactions.
Commit phase:
The commit phase is based on voting of cohorts and the coordinator decides
to commit or terminate the transaction.
4. Distributed commit
While committing a transaction which is accessing databases stored on
multiple locations, if failure occurs on some location during the commit
process then this problem is called as distributed commit.
5. Distributed deadlock
Deadlock can occur at several locations due to recovery problem and
concurrency problem (multiple locations are accessing same system in the
communication network).
3) Exclusive lock
The transaction can activate exclusive lock on a data to read and write
operation. In this system, no other transaction can activate any kind of lock
on that same data.