データベースのトランザクション処理に関する次の記述中の a, b に入れる字句の適切な組合せはどれか。 複数のユーザが同時に同じデータを更新しようとしたとき, データの整合性を保つために, そのデータへのアクセスを一時的に制限する仕組みを [ a ] という。 これを実現する一つの方法は, データを更新する前に, そのデータに [ b ] をかけ, 処理が終了するまでほかのユーザからのアクセスを制限することである。
平成23年度 特別試験 ITパスポート試験 問78
This question's explanation and your answers so far.
問 78
Incorrectア
Both a, “routing control”, and b, “deadlock”, fail to fit the description in the question, so this option is wrong twice over. Routing control (routing) is the function of deciding by which path a packet is delivered to its destination on a network, and it is handled by routers; it has nothing to do with simultaneous updates in a database or with data consistency. A deadlock is an abnormal state in which several transactions each keep waiting for the lock held by another to be released, so that none of them can move their processing forward. It is not a means of implementing exclusive control; rather, it is an undesirable phenomenon that can occur as a result of performing exclusive control. It is also not something that can be “applied to” data.
Incorrectイ
b, “lock”, is correct, but a, “routing control”, is wrong. Routing control is the function of selecting the forwarding path of a packet at the network layer; it is not the name of a mechanism that restricts simultaneous access in a database. Blank a in the question asks for the general term for “a mechanism that temporarily restricts access in order to keep the data consistent”, and what goes there is exclusive control. In a combination question, note that even if one half is correct, the whole option becomes incorrect when the other half is wrong.
Incorrectウ
a, “exclusive control”, is correct, but b, “deadlock”, is wrong. A deadlock refers to a state in which, for example, transaction 1 holds a lock on data X and waits for a lock on Y while, at the same time, transaction 2 holds a lock on Y and waits for a lock on X, so that this cycle of waiting stops both of them forever. It is a fault that should be avoided, not something that is intentionally “applied” before an update. What blank b asks for is a concrete means of implementing exclusive control, and what goes there is a lock.
- エ
正解 The correct answer is エ (a = exclusive control, b = lock). The word that goes in blank a is exclusive control. When multiple users (transactions) try to update the same data at the same time, problems such as the “lost update”, in which the update result of one side is overwritten and lost by the update of the other side, occur and the consistency of the data breaks down. To prevent this, the mechanism that temporarily restricts access to the data from other transactions while one transaction is handling that data is exclusive control. The wording in the question, “the mechanism that temporarily restricts access to that data in order to keep the data consistent”, corresponds directly to this definition of exclusive control. The word that goes in blank b is lock. The representative way of implementing exclusive control is the locking method, in which a lock is placed on the target data (a table, a row, a page, and so on) before the update so that the data is occupied, and the lock is released when the processing ends, for example at commit. While the lock is held, access from other users is made to wait, so this matches the description in the question, “apply [ b ] to the data before updating it, and restrict access from other users until the processing is finished”. Therefore エ, the combination of a = exclusive control and b = lock, is the correct answer. Note also that locks come in two kinds: the dedicated lock (exclusive lock), which takes sole possession for updating, and the shared lock, which several transactions can hold at the same time when they only read the data; using the two properly keeps consistency while raising concurrency.
- Exclusive control and locks — the mechanism that temporarily restricts access so that consistency is not broken even when several transactions update the same data at the same time is exclusive control. Its representative implementation is the lock, which takes possession of the target data before an update and is released when the processing ends. Locks come in two kinds: the shared lock, which several transactions can hold at once for reading, and the dedicated lock (exclusive lock), which takes sole possession for updating.
- A deadlock is not a means but an abnormal state — the state in which several transactions wait for each other to release the locks they hold, so that neither can proceed, is a deadlock. It is a problem that can occur as a side effect of exclusive control that uses locks, not the means of implementing exclusive control itself. Also keep “routing control” separate: it is the network function of deciding the path of a packet, and not a term from the database field.