![](https://csdnimg.cn/release/download_crawler_static/86289411/bg1.jpg)
C H A P T E R
24
Advanced Application
Development
Practice Exercises
24.1 Many applications need to generate sequence numbers for each trans-
action.
a. If a sequence counter is locked in two-phase manner, it can become
a concurrency bottleneck. Explain why this may be the case.
b. Many database systems support built-in sequence counters that
are not locked in two-phase manner; when a transaction requests
a sequence number, the counter is locked, incremented and un-
locked.
i. Explain how such counters can improve concurrency.
ii. Explain why there may be gaps in the sequence numbers be-
longing to the final set of committed transactions.
Answer: If two-phase locking is used on the counter, the counter must
remain locked in exclusive mode until the transaction is done acquiring
locks. During that time, the counter is unavailable and no concurrent
transactions can be started regardless of whether they would have data
conflicts with the transaction holding the counter.
If locking is done outside the scope of a two-phase locking protocol,
the counter is locked only for the brief time it takes to increment the
counter. SInce there is no other operation besides increment performed
on the counter, this creates noproblem except when a transaction aborts.
During an abort, the counter cannot be restored to its old value but
instead should remain as it stands. This means that some counter values
are unused since those values were assigned to aborted transactions. To
see why we cannot restore the old counter value, assume transaction
T
a
has counter value 100 and then T
b
is given the next value, 101. If
T
a
aborts and the counter were restored to 100, the value 100 would
be given to some other transaction T
c
and then 101 would be given to
9
评论0