Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
The-Manga-guide-to-databases.pdf
Скачиваний:
7
Добавлен:
17.11.2024
Размер:
36.39 Mб
Скачать

Vertical Distribution

Vertical distribution assigns different functions to different database servers. One of the servers functions as the main server and performs a key role, while the others are in charge of processing tasks as requested. A vertically distributed database makes it easier to manage the main database server, though this main server will have a heavy load. An example of vertical distribution would include a company-wide main server and individual servers operating in each department.

This server operates the entire server system.

Server A

Main

Server

Router

Router

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Server B

 

 

Server C

Partitioning Data

In a distributed database, data is spread across servers for storage. You should carefully consider how to divide up the data. Data can be split in the following ways.

Horizontal Partitioning

A horizontal partition divides data into units of rows. Rows resulting from the split are distributed across servers. This form of partitioning is often used when data can be ordered into groups in such a way that related data, which is often accessed at the same time, is stored on the same server.

 

 

Region A

 

 

 

 

 

 

 

 

Region B

BusinesS Department

 

 

 

 

 

BusinesS Department

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Product

Unit

District

Person

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

name

price

in charge

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

198  Chapter 6

Vertical Partitioning

A vertical partition divides data into units of columns. Columns resulting from the split are distributed across servers. For example, a vertical partition can be used to manage and join independent databases belonging to departments like the Merchandise Department, the Overseas Business Department, and the Export Department.

Merchandise

 

 

 

 

 

Overseas BusinesS

 

 

 

 

 

 

Product

Unit

District

Person

Department

 

name

price

in charge

 

Department

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Preventing Inconsistencies with a Two-Phase Commit

Databases on different servers in a distributed database system can be configured to act as a single database in the eyes of users. To achieve this, various steps must be taken to deal with the fact that data is actually distributed across different servers.

First, whenever data is committed, all data on all servers must be updated consistently. In a distributed database system, the standard commit method may lead to one of

the servers being updated while another is not, as shown below. This is a violation of the atomicity property of transactions, as this transaction will not end with either a commit or rollback. This would also cause the database system as a whole to become inconsistent.

User

Server A

 

 

 

 

 

 

 

Server B

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

UPDATE

Operation

UPDATE

Operation

COmMIT

COmMIT

Therefore, a two-phase commit is adopted in a distributed database system. The twophase commit creates one commit operation from both the first and the second commit operations.

Databases Are Everywhere!  199

A two-phase commit operation involves a coordinator and participants. In the first phase of a two-phase commit operation, the coordinator asks the participants if a commit operation is possible. The participants send an OK reply if it is. This preparatory step is referred to as a prepare. In the second phase, the coordinator gives the instructions for a commit, and all participants perform a commit accordingly.

CoOrdinator

Participant

 

 

 

 

 

 

 

Participant

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

UPDATE

Operation

UPDATE

Operation

Secure

Secure

OK

OK

COmMIT

COmMIT

If any one node fails to secure the operation in the two-phase commit, all participants receive a rollback directive. This is how databases on all servers remain consistent with each other.

CoOrdinator

Participant

 

 

 

 

 

 

 

Participant

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

UPDATE

Operation

UPDATE

Operation

Secure

Secure

OK

OK

RolLback

RolLback

200  Chapter 6

Questions

Try these questions about two-phase commits. The answers are on page 205.

Q3

In a two-phase commit scheme, what instructions does the coordinator give during the first phase?

Q4

In a two-phase commit scheme, what instructions does the coordinator give during the second phase?

Database Replication

Some distributed databases have a duplicated, or replica, database that reduces the load on the network. This practice is referred to as replication. The primary database is referred to as the master database, and the copy is called the replica. There are several types of replication.

Read-Only

A read-only replica is created and downloaded from the master database on the main server. To change data, users must connect to the main server.

Main server

Replica

Replica

Databases Are Everywhere!  201