An Assertional Characterization of Serializability* E. Robert McCurley Fred B. Schneider TR 89-1039 September 1989 Department of Computer Science Cornell University Ithaca, NY 14853-7501 *This material is based on work supported by the Office of Naval Research under contract NOOOI4-86-k-0092, the National Science Foundation under grant no OCR-8701 103, and Digital Equipment Corporation. Any opinions, findings, and conclusions or recommendations expressed in this publication are those of the authors and do not reflect the views of these agencies. An Assertional Characterization of serializability* E. Robert McCuriey School of Information and Computer Science Georgia Institute of Technology Atlanta, Georgia 30332 Fred B. Schneider Department of Computer Science Cornell University Ithaca, New York 1?853 September 28, 1989 Abstract Serializability is usually defined operationally in terms of sequences of operations. This paper gives another definition of serializability--H in terms of sequences of states. It also shows how this definition can be used to prove correctness of solutions to the concurrency control problem. 1 Introduction A database system is a computer system that stores information. Consis- tency constraints restrict system states to those that are meaningful; trans- actions are designed so that each individually transforms the database from - This material is based on work supported in part by the Office of Naval Research un- der contract N00014-86-K-0092, the National Sdence Foundation under Grant No. CCR 8701103, and Digital Equipment Corporation. Any opinions, findings, and conclusions or recommendations expressed in this publication are those of the authors and do not reflect the views of these agencies. one consistent state to another. For example, in a database for a banking application, a consistency constraint might relate cash-on-hand to the sum of the account balances; a transaction for a deposit would adjust both an account balance and cash-on-hand, preserving the consistency constraint. During concurrent execution of transactions, operations can interleave in ways that leave the database in an inconsistent state. Avoiding such states is called the concurrency control problem. The traditional solution to this problem is based on serializability [EGLT76], which asserts that transactions executing concurrently "behave like" they are run serially, one after another. If, when run in isolation, each transaction transforms the database from one consistent state to another and if transactions are seriallzable, then concurrent execution of those transactions will also transform the database from one consistent state to another. Thus, implementing serializability solves the concurrency control problem. Seriallzability is usually defined (operationally) in terms of sequences, called schedules, that list operations in the order they run. This would seem to preclude use of programming methodologies based on assertions about states--Hso called asseflional reasoning. It is tempting to regard this as a fundamental limitation of such methodologies. In this paper, we show this view to be erroneous. We give an assertional characterization of seriallzabil- ity and show how this definition can be used to prove correctness of solutions to the concurrency control problem. We proceed as follows. In Section 2, we present a database system model and give a formal definition of seriallzability. Two ways to specify seriallzability using formulas of a Hoare-style programming logic are given in Section 3. In Section 4, we discuss possible extensions to our database system model and their implications. We conclude, in Section 5, with a comparison of our definition and previous ones. 2 Serializability 2.1 System Model A database system ? can be represented by a triple (V, C, T?, where V is a set of variables, C is a predicate on V, and T: [ro II . II is a concurrent program in which each transaction Tj is a program that references only variables of V- 2 Variables ill V represent the state of the database, including but not limited to the part that actually contains application data.1 C is the con- sistency constraint of the database. A state is consistent iff C is true in that state. Each transaction r? is assumed to terminate in a consistent state when run aione starting in one. An example of a database system is given in Figure 1. ?o models a database that maintains an unordered collection of records, represented by variable s of type set. Variables ?....., rn??i are sequences, containing records that have or will be inserted into 8, and consistency constraint Co requires 8 to contain a subset of these. Each transaction Addi adds the records of ?flj to 8. Variable tj of Addi is locai to the transaction, hence excluded from V0. In the guard of the loop, linil denotes the length of the sequence ?flj. Angle brackets "(" and ")" surround operations that execute atomically. 2.2 Serializability ?o=(Vo: 8,??,???,??N--H1, C0: 8C?(inoU...UinN?1), T0: [Ad?? ... II AddN?l] Add?: (ti:=O); doti#Iinil (8:=8uini(tj)); od Figure 1: Database System ?o. Seriallzability of ? = ( V, C, T? can be understood in terms of an abstract database system ?` = ( V', C', T'? where V' and C' are the same as V and C of?, and T': [ro' II . II r?'?iJ , (1) is the concurrent program in which each r: is (r2-), a transaction that exe- cutes the same operations as r? but as a single atomic operation. Executions `A commit flag is an example of an element of V that does not contain application data. 3 of T' are serial, meaning that transactions are executed one after another without interleaving. Recall that serializability asserts that every (potentially interleaved) exe- cution of T "behaves like" some (serial) execution of T'. Since if one system T implements another one T', then every behavior of T can be viewed as a behavior of T', serializability of T is equivalent to T implementing T' [Lam88]. 2.3 Defining "Implements" 111 [Pri87, GP85j, a formal definition in terms of predicate transformers is given for when one program implements another. This definition is a gen- eralization of that presented in [Hoa72j and can be summarized as follows. Let S' be a program operating on variables X, and let P be a predicate on X such that S' is guaranteed to terminate when run in an initial state satisfying F. Let S be a program 011 variables Y (disjoint from X), which is intended to implement s,. Programs S' and S are called the abstract and concrete programs, re- spectively. The correspondence between the states of these programs is represented by a predicate I on X and Y, called a coupling invariant. It often takes the form X = F( Y), where F is a function that maps any state of s to the state of S' that it implements. The property that S implements S' is formalized as (P A I) ? wp(S, wp*(S',I)). (2) Here, wp(S, R) denotes the weakest precondition of S with respect to R [Dij76], the set of states in which any execution of S is guaranteed to ter- minate in a state satisfying R, and wp*(S', R) denotes the angelic weakest precondition of S' with respect to R, the set of states in which some exe- cution of S' wffl terminate in a state satisfying R.2 Thus, (2) specifies a correspondence between the effect of concrete program S and that of the abstract program S1, when both programs are viewed as predicate trans- formers. In particular, (2) asserts that concrete program S changes its variables in a way that is consistent--Has defined by I--Hwith some execution of the abstract program it implements. 2The relationship between wp and wp is as follows: wp(S, true) ? (wp*(S,R) ? ?wp(S, ?R)). For deterrainistic S, wp(S, R) ? wp?(S,R). 4 2.4 Serializability as "Implements" Serializability of? = ( V, C, T) can be formalized in terms of?'= ( V', C', T'? using (2) by taking T' of (1) to be the abstract program and T to be the concrete program. To do so, however, variables V' in C' and T' must be replaced by fresh variables ??.?? ,VM' 1 disjoint from V. Henceforth, we assume that V and V' are disjoint. For P in (2) we take C' and for I we take A,jE v Vj = v: giving the fol- lowing characterization of serializability. Definition: ? is serializable if and only if (C'A A Vi=v:')?wp(T,wp*(T', A vi=v:()). ?Ev ?Ev (3) Some simplification of (3) is possible. Since .?.... ,r?'?1 run serially in T', any execution of T' will be equivalent to some execution of a sequential program p in the set S( T'): ....... ?? is a transaction of T', 0< i