Client Server Cache consistency Algorithms

advertisement
Client-Server Cache Consistency Maintenance Algorithms Survey
David Krasnopolsky
Cornell University
Abstract
This paper surveys several cache consistency maintenance algorithms. Four design
families are explored: Server-Based Two Phase Locking (S2PL), No-Wait Locking (NWL),
Callback Locking (CBL), Optimistic Two Phase Locking (O2PL). Each algorithm is presented in
depth along with a comparison to its peers.
Introduction
Client data caching is an optimization technique designed to enhance performance and
scalability in a page/object server DBMS. Caching takes advantage of temporal locality,
references are clustered in time, and spatial locality, references are clustered in space. Note
caching introduces several copies of the same data across several sites, this introduces a problem
of data and view integrity. The problem of keeping data consistent across all views is referred to
as “cache consistency maintenance”. Protocols needed to perform cache consistency
maintenance are closely related to transaction processing and concurrency control. Data can be
cached within transaction boundaries (intra-transaction caching) and across transaction
processing (inter-transaction caching). Intra-transaction caching assumes all copies of its data are
invalid at the start of transaction execution, thus on first access all pages must be fetched into the
transaction’s buffer pool. However as pointed out in [Wang91] intra-transaction caching can not
benefit from inter-transaction reference locality. The rest of the paper will focus on intertransaction caching algorithms. Caching of objects as opposed to pages is of interest in
comparing OODBMS’s vs. RDBMS’s however our discussion is relevant for both purposes, thus
we will make no distinction between caching units be it pages or objects. Note the benefits of
caching may be offset due to higher overhead, communication and processing costs.
Algorithm Taxonomy
According to [Fran96] most cache consistency maintenance algorithms can be divided
into two categories: detection based and avoidance-based. Detection-based schemes allow for
stale data copies to reside in a client’s cache. Transactions must explicitly check the validity of
the data they access before they are allowed to commit. The server is responsible for making
such a checking algorithm possible. The name detection-based implies that stale data must be
explicitly detected, furthermore any transaction accessing stale data is not allowed to commit.
Avoidance-based methods avoid accessing stale data, its protocols make such access impossible.
These protocols are based on the read one/write all (ROWA) approach to replication
management. A ROWA type protocol ensures that every copy of an updated item has the same
value when the transaction commits. The ROWA approach is specialized to take advantage of
server services, allowing the server to eliminate any unreachable data pages.
The main advantage of detection-based algorithms is their simplicity, because the clientserver interactions involve a single client-server pair. Therefore the amount of code required at
the client is significantly less then in ROWA based approaches. The need for distributed global
deadlock detection is also eliminated. These advantages come at a price; detection-based
methods are highly dependent on client-server communication as well as the servers themselves.
This survey will study four families of algorithms: Server-Based Two Phase Locking
(S2PL) and No-Wait Locking (NWL) which are detection-based, Callback Locking (CBL) and
Optimistic Two Phase Locking (O2PL) which are avoidance-based.
Server-Based Two Phase Locking (S2PL)
The family of S2PL algorithms is detection-based. Their main feature is the ability to
validate previously cached pages synchronously during a transaction’s initial page access. As
described in [Fran97] these algorithms are based on a primary copy approach to replication
management. Before any transaction is allowed to commit it must access the primary copy,
which in this case is residing on the server. For reads, the client’s data copy is verified to have
the updated values. For writes, the new value must be reflected in the primary copy.
One of the simplest algorithms in this family, studied by Franklin and Carey, is Caching
2PL (C2PL). C2PL maintains a “check-on-access” philosophy, disallowing inter-transactional
lock caching. All cached pages are tagged with a log sequence number (LSN), which represents
the current version of the page. Any page access for which the transaction does not have a lock
results in a lock request being sent to the server. If there is a cached copy of the page present in
the client’s buffer pool, the LSN of the cached page is included in the lock request message. If
other transactions hold conflicting locks on the requested page the server blocks the request until
all conflicting locks are released. If a read-lock is granted to a transaction the server determines if
the cached copy of the page is up-to-date by comparing LSNs. If the page is out-of-date the
server piggybacks the up-to-date page copy on the lock request response. Note all locks are held
at the server, furthermore the server uses strict 2PL (all locks are held until a transaction commits
or aborts). The centralized architecture allows the server to perform deadlock detection, conflicts
are resolved by aborting the youngest transaction.
It is immediately evident C2PL is a pessimistic algorithm, which leads to 2
communication messages for every new page access. This places a heavy emphasis on the
network making it a possible bottleneck.
No-Wait Locking (NWL)
In S2PL algorithms a transaction is blocked while waiting for a response from the server
to confirm/deny cached object validity. An alternate view is to optimistically assume that all
objects in the cache are valid and all requested locks will be granted, this allows the application to
execute without waiting for a server to respond. If the cached page is valid and the requested
lock can be granted the server does not send any response until a commit message is received, an
example of asynchronous communication. If the cached page is invalid or deadlock is detected,
the transaction is aborted by the server and the client must restart it. It is important to note, the
client must receive a response from the server before it can commit.
In NWL transactions can be aborted due to invalid object access or deadlock. An
extension of NWL proposed in [Wang91] uses notification to reduce aborts due to invalid page
access. The proposed mechanism has the server send updated pages or invalidation messages to
clients when a cached page is updated by a committed transaction. At a later time the client
transactions will read valid objects and thus commit. Note a transaction can still read an invalid
object if it receives the update page late.
It was found in [Wang91] when the network or the server present a bottleneck, S2PL and
CBL techniques outperform NWL and NWL with notification.
Callback Locking (CBL)
CBL algorithms are avoidance-based, support inter-transactional caching, and are based
on two-phase pessimistic locking methodology. As with all avoidance-based algorithms locally
cached page copies are guaranteed to be valid, thus a requesting transaction is immediately
granted a lock(R/W) by the local lock manager. When a cache miss occurs, the application is
blocked and the local lock manager sends a page request message to the server. A valid copy of
the page is returned to the client when the server determines that no other clients have write
permissions on that page.
The server contains a list of all the cached copies throughout the system (implicit lock
list). When a write lock request arrives, the server sends a “call back” request to all sites that
have locally cached locks on the page in question. When the clients are through using the page
(for example it is in use by a local transaction on some client) the page is removed from the
client’s buffer and a corresponding message is sent to the server. Once a server receives
confirmation on all callbacks it grants the client write permissions on the page. Any subsequent
read/write requests by other clients are blocked until the current transaction releases its write lock
or the lock is revoked by the server. In CBL a client lock manager must have server write
permissions before it can grant a write lock to a local transaction. The write permissions are
obtained and granted during transaction execution, thus no additional consistency maintenance
operations are required.
There are two widely studied variants of the CBL scheme [Fran92a] : Callback-Read
(CB-R) and Callback-All (CB-A). In CB-R write permissions are granted only for the duration of
a single transaction (traditional write locks ) and only read locks are cached across transactions.
In CB-A write permissions are retained at clients until they are “called back” by the server or the
page is dropped from the cache. Since write locks are kept at the clients, the client has an
exclusive copy of that page. When a read request is sent to the server it determines where the
exclusive copy is located and sends a lock-downgrade request (from exclusive (write) to a simple
read-lock ) to that client. When exclusive rights to that page are returned to the server it will send
back a copy to the requesting client.
It was found in [Wang91] that CBL is better than S2PL when inter-transaction locality is
high and the page update probability is low.
Optimistic Two Phase Locking (O2PL)
As described in [Fran92a] O2PL algorithms are avoidance-based, allow for inter-transactional
data caching, and are more “optimistic” than CBL algorithms, which obtain write locks at the
beginning of the transaction, because they defer write intention declaration until the end of the
execution phase. Each client has a local lock manager, which hands out locks to executing
transactions. If a page is not in the cache the local lock manager sends a request to the server to
obtain a copy of the page for the client. It is important to note during the execution phase of a
transaction no two-phase locks are obtained, the server uses “latches” (non-two-phase read-lock)
to give the transaction a copy of a page. Once the updating transaction is ready to commit it
sends a message to the server along with the updated pages. The server obtains the exclusive
locks on the transaction’s behalf and holds them until the appropriate changes have been made.
The server sends an exclusive (update) lock request to all clients containing a copy of that page.
Once these locks have been obtained (the client may have to wait for a local transaction to release
any read locks it has on the page to be updated) the appropriate update actions will be performed.
There are several algorithm variants at this point. The O2PL-Invalidate (O2PL-I)
algorithm simply purges the data pages at each client site, releases the local locks on the data
pages, and sends an acknowledgement to the server. O2PL-I does not require a two-phase
commit protocol. The O2PL-Propagate (O2PL-P) algorithm propagates the updates to clients.
This involves a two-phase commit protocol. Once the client has obtained all the update locks it
sends a “prepared” message to the server. When the server has received all the “prepared”
messages it sends the updated page copy to all the clients. This begins the second phase of the
commit protocol, when the clients update the data pages and release the acquired locks. Note it is
possible to have a smart algorithm which either purges or propagates updates depending on the
workload, such an algorithm O2PL-Dynamic (O2PL-D) was studied in [Care91].
In O2PL algorithms distributed deadlock can arise. Deadlock detection is performed
through local client “waits-for” graph analysis, and global “waits-for” graph composition and
analysis.
The tradeoffs between these algorithms were studied in [Care91] it was found that O2PLI performs well under many workloads, O2PL-P is workload sensitive ( best for “informationfeed” application) and does not scale well. Another result of the study performed in [Care91]
shows that C2PL was generally outperformed by the better of the two O2PL algorithms, except in
a high level of data contention case.
Summary
This paper has surveyed the possible design algorithms for transaction cache consistency
maintenance algorithms. We will briefly summarize the information presented in the paper, for a
detailed performance study of these algorithms please see [Fran97].
C2PL and NWL are detection based algorithms. C2PL uses the “check-on-access”
philosophy to guarantee consistency of accessed data. It is a pessimistic algorithm, because all
locks are obtained at the beginning of a transaction and retained until the end. NWL is an
optimistic algorithm, it provides stale data access to transaction thus increasing the likely hood of
aborts. CBL and O2PL algorithms are avoidance based. O2PL algorithms are lock-based,
partially optimistic ROWA implementations. Read locks are obtained during transaction
execution and write lock acquisition is deferred (“optimism”) until commit time. CBL algorithms
are lock-based and pessimistic.
It is worthwhile to note that all the cache consistency maintenance algorithms require
extra processing and communication overhead. Furthermore it is evident that both types of
protocols are dependent on good server implementations. In the case of avoidance-based
algorithms there is a heavier emphasis on the client-side processing, due to local lock managers.
References
[ Alon90]
Alonso, R., Barbara, D., Garcia-Molina, H., “Data Caching Issues in an Information
Retrieval System”, ACM Transactions on Database Systems, Vol. 15, No. 3, September
1990, Pages 359-384
[Care91]
Carey, M., Franklin, M., Livny, M., Shekita, E., “Data Caching Tradeoffs in ClientServer DBMS Architectures”. Proc. ACM SIGMOD Int’l Conf. on Management of Data,
Denver, CO, June 1991.
[Fran92a]
Franklin, M., Carey, M., “Client-Server Caching Revisited”, Tech. Rep. 1089, University
of Wisconsin-Madison, May, 1992.
[Fran96]
Franklin, M., Client Data Caching, Kluwer Academic Publishers, Boston, 1996.
[Fran97]
Franklin, M., Carey, M., Livny, M., “Transactional Client-Server Cache Consistency:
Alternatives and Performance”, ACM Transactions on Database Systems, Vol. 22, No. 3,
September 1997, Pages 315-363.
[Wang91]
Wang, Y., Rowe, L., “Cache Consistency and Concurrency Control in a Client/Server
DBMS Architecture”, Proc. ACM SIGMOD Int’l Conf. on Management of Data, Denver,
June 1991.
Download