<?xml-model href='http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng' schematypens='http://relaxng.org/ns/structure/1.0'?><TEI xmlns="http://www.tei-c.org/ns/1.0">
	<teiHeader>
		<fileDesc>
			<titleStmt><title level='a'>Verifying vMVCC, a high-performance transaction library using multi-version concurrency control</title></titleStmt>
			<publicationStmt>
				<publisher></publisher>
				<date>07/10/2023</date>
			</publicationStmt>
			<sourceDesc>
				<bibl> 
					<idno type="par_id">10438568</idno>
					<idno type="doi"></idno>
					<title level='j'>Proceedings of the 17th USENIX Symposium on Operating Systems Design and Implementation (OSDI)</title>
<idno></idno>
<biblScope unit="volume"></biblScope>
<biblScope unit="issue"></biblScope>					

					<author>Yun-Sheng Chang</author><author>Ralf Jung</author><author>Upamanyu Sharma</author><author>Joseph Tassarotti</author><author>M. Frans Kaashoek</author><author>Nickolai Zeldovich</author>
				</bibl>
			</sourceDesc>
		</fileDesc>
		<profileDesc>
			<abstract><ab><![CDATA[Multi-version concurrency control (MVCC) is a widely used, sophisticated approach for handling concurrent transactions. vMVCC is the first MVCC-based transaction library that comes with a machine-checked proof of correctness, providing clients with a guarantee that it will correctly handle all transactions despite a complicated design and implementation that might otherwise be error-prone. vMVCC is implemented in Go, stores data in memory, and uses several optimizations, such as RDTSC-based timestamps, to achieve high performance (25–96% the throughput of Silo, a state-of-the-art in-memory database, for YCSB and TPC-C workloads). Formally specifying and verifying vMVCC required adopting advanced proof techniques, such as logical atomicity and prophecy variables, owing to the fact that MVCC transactions can linearize at timestamp generation prior to transaction execution.]]></ab></abstract>
		</profileDesc>
	</teiHeader>
	<text><body xmlns="http://www.tei-c.org/ns/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink">
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="1">Introduction</head><p>Applications routinely rely on databases not just for storing data durably on disk, but also for ensuring that transactions execute atomically despite concurrency and crashes. This simplifies application development, because the application developer no longer has to worry about concurrency bugs or partial state left over after a crash. Indeed, this pattern is so ubiquitous that it is common for cloud providers to offer databases as a black-box service to application developers. In this model, application correctness and performance crucially hinges on the database system correctly handling all possible corner cases and doing so efficiently.</p><p>Achieving both correctness and high performance in a database system for many concurrent transactions is challenging. In particular, when transactions read and write an overlapping set of data items, the database system must ensure the transactions appear to execute in a serial order. A widely used technique for improving performance in this setting is multi-version concurrency control, or MVCC <ref type="bibr">[8,</ref><ref type="bibr">30,</ref><ref type="bibr">35,</ref><ref type="bibr">36]</ref>, in which the database stores not just the latest version of a data item, but also past versions. Storing past versions allows the database system to execute writes that add a new version, while also being able to use the older versions to execute reads from transactions that appear to execute earlier in the serial order.</p><p>Multi-version concurrency control requires a sophisticated implementation of its data structures, in order to efficiently track multiple versions of each tuple, implement garbage collection (GC), etc. The implementation must also employ low-level optimizations to get high performance. For instance, using a mutex on a shared counter to get a unique ID for each transaction is too costly, and highly scalable implementations must use contention-free approaches such as relying on the CPU timestamp counter. The end result, therefore, is a complex implementation that can have bugs leading to incorrect or non-serializable executions. These bugs can be costly: they can cause data to be lost or corrupted; they can lead to many applications being affected; and tracking down bugs in the database system can be difficult for application developers.</p><p>This paper presents vMVCC, a high-performance MVCCbased transaction library with a formal specification and a machine-checked proof of correctness. vMVCC addresses the core technical challenges faced by the transaction layer in a database, and can be used to build transactional applications. Verifying vMVCC requires addressing several challenges. First, we must formalize a specification that captures the guarantees provided by MVCC transactions in a concise manner. Second, we must develop proof techniques to show that MVCC achieves a serializable execution order in the presence of concurrency. Finally, we must be able to formally reason about high-performance implementations that use low-level programming techniques such as sharded data structures, accessing the CPU timestamp counter with an RDTSC-like instruction, etc.</p><p>The key technical challenge addressed in vMVCC lies in dealing with the fact that MVCC's linearization point happens before the transaction body runs-the linearization point is when the timestamp is obtained in Begin(). This makes it challenging to verify MVCC-based transactions because, at the linearization point, the transaction has not executed yet, and the proof does not know what data the transaction is going to write or whether it is going to commit or abort. However, it is important for the specification and proof to update the abstract state of the system at the linearization point, because subsequent transactions must observe these changes. In contrast, under two-phase locking, a transaction linearizes at the point when it commits, where it is well known what state the transaction modified and that it is about to commit. vMVCC addresses this challenge by adopting prophecy variables <ref type="bibr">[1,</ref><ref type="bibr">18]</ref>. Our use of prophecy variables allows the proof to speculatively predict what state the transaction is going to modify and whether it will commit. This translates into the proof considering every possible prediction, allowing vMVCC to update the abstract state accordingly at the linearization point. As the transaction is about to commit, the proof can check whether the prediction was correct or not, and either stop considering further an incorrect prediction, or continue with a correct prediction. vMVCC is not the first to develop or use prophecy variables-many earlier frameworks developed support for them and proved that they are a sound proof technique-but it is the first to prove the correctness of MVCC-based transactions.</p><p>We implemented vMVCC in Go, and verified it using the Goose and Perennial frameworks. vMVCC implements sophisticated optimizations such as the use of RDTSC to generate strictly increasing timestamps, on-the-fly GC of past versions, and efficient data structures for storing multiple versions. vMVCC provides a transactional key-value store interface, similar to Silo <ref type="bibr">[35]</ref>. For the YCSB benchmark with 32 worker threads, vMVCC achieves an aggregated throughput of 18.6M-52M transactions per second, which is 38-96% of that achieved by the unverified Silo database. For TPC-C, vMVCC achieves a throughput of 10.7K-33K transactions per second per warehouse, which is 25-43% of Silo's throughput.</p><p>The key technical contribution of vMVCC lies in demonstrating how to formally reason about transactions whose linearization point precedes the execution of their transaction body, using prophecy variables. This verification technique would be applicable to any system that uses MVCC <ref type="bibr">[8, 10-12, 14, 19, 27, 30, 32, 35-37]</ref>. The second contribution is vMVCC itself, the first verified MVCC transaction library. The vMVCC artifact is interesting in its own right, providing a high-assurance and high-performance implementation, and can be used as a Go package independent of verification. vMVCC includes several other technical contributions, including a verified algorithm for computing strictly increasing transaction IDs using RDTSC, and a precise specification of a transaction library interface using logical atomicity <ref type="bibr">[16]</ref>.</p><p>One of the limitations of vMVCC is that it does not implement durability. In-memory databases are widely used in practice, but we do plan to extend vMVCC to store data durably on disk so that it persists across crashes, and to for-mally verify it using techniques from Perennial <ref type="bibr">[3]</ref>. Another limitation of vMVCC is that it provides a simple key-value data model, as opposed to SQL's relational data, and does not support range scans.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="2">Design and interface of vMVCC</head><p>vMVCC is a transaction library, and applications interact with it through a standard interface for transactions, as follows (in Go syntax): vMVCC uses an MVCC design closest to the original protocol as proposed by Reed <ref type="bibr">[30]</ref> (also known as multi-version timestamp ordering <ref type="bibr">[36]</ref>). The design is based around assigning a strictly increasing timestamp in Begin() to every transaction, and storing multiple versions for each key, corresponding to a range of timestamps for which that version is valid. When an application modifies a key, using Write(k,v) or Delete(k), the vMVCC transaction keeps track of the modification in a per-transaction write buffer. When an application invokes Read(k), the transaction first checks its local write buffer for pending writes to k; if there are no pending writes, it then searches from the global state the version of key k whose timestamp immediately precedes the transaction's timestamp. On successfully calling Commit(), the transaction creates a new version for each key in the write buffer with the transaction's timestamp as well. On calling Abort(), or a failed Commit(), the transaction drops its write buffer.</p><p>Read-only transactions always succeed in vMVCC because vMVCC retains all past versions required by active transactions (i.e., those that have begun but not yet committed or aborted). A transaction involving updates, however, might fail to commit if another transaction with a higher timestamp has read or updated the modified key in the meantime. The reason this requires aborting the first transaction is that, to achieve linearizability, the second transaction should have seen the update made by the first one, but it did not. Data structures. Figure <ref type="figure">1</ref> shows the data structures that vMVCC uses to implement its design. The crux of multiversioning lies in the data structure tuple, consisting of a list of versions, a tslast field to detect conflicts, and a mutex (not shown) used for synchronizing access to this data structure. Each version corresponds to a range of timestamps for which it is valid, represented by the ts field, which marks the start of the validity region. The version is valid until the next version's ts field, or, if this is the last version in the tuple, then it is the latest version. Each version also contains the value (val) and whether this key is deleted or not (del). The tslast field of each tuple represents the highest timestamp of any transaction that has read or written this tuple. It is  used to detect conflicts if a Write or a Delete with an earlier timestamp tries to commit later on. On top of tuples, vMVCC maintains its index, a hash map from keys to tuple pointers. Keys not present in the index are assumed to be not present (deleted) at every timestamp.</p><p>Every active transaction in vMVCC is represented using a transaction object, which consists of a unique timestamp ts, as well as a local write buffer keeping track of the modifications made by this transaction so far. When the transaction commits, it tries to acquire the mutexes of the tuples to be modified, and if successful, atomically applies the modification in its local writer buffer. Transaction IDs are generated by the transaction manager. For the purposes of GC, it also keeps track of the IDs of active transactions. This example also shows the concurrency advantages of MVCC over conventional concurrency control approaches such as two-phase locking (2PL) and optimistic concurrency control (OCC). With 2PL, Txn 15 cannot commit until Txn 4 commits, at which point the lock on &#119896; is released. With OCC, Txn 4 would have to abort as the value of &#119896; changes during the execution of Txn 4.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>Execution examples.</head><p>Figure <ref type="figure">2</ref>(b) shows an example of how vMVCC detects and aborts conflicting writes. 1 Txn 12 reads the second version of the tuple, and 2 increases the tslast field to its timestamp. 3 Txn 10 attempts to commit and update the tuple, but fails because the timestamp of Txn 10 is less than tslast of the tuple (i.e., 12). Thus, Txn 10 aborts.</p><p>Garbage collection. To reclaim space occupied by unusable versions, vMVCC employs a garbage collector that runs in the background to remove those versions. The garbage collector must ensure that the versions it removes cannot be accessed by any transactions, including those that have not even begun. Concretely, the garbage collector first determines a lower bound on the transaction IDs of all active and future transactions. This lower bound can be computed by finding the minimal transaction ID among the active ones; if there are no active transactions, the current timestamp is used. Because timestamps are strictly increasing (as described below), the garbage collector can safely remove versions whose lifetime ends before that lower bound.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>Generating timestamps with CPU timestamp counter.</head><p>A key requirement for vMVCC is that every transaction is assigned a strictly increasing timestamp. However, assigning these timestamps by modifying a shared in-memory counter leads to contention on that counter. Instead, vMVCC uses the CPU timestamp counter (e.g., RDTSC on x86 machines) to generate timestamps in a scalable way. Modern hardware ensures that timestamps are monotonically increasing and consistent across cores and sockets <ref type="bibr">[2]</ref>.</p><p>One complication is that two threads running on different cores may obtain the same timestamp. vMVCC addresses this problem by using transaction sites to make transaction IDs unique. Each site has its own ID, which is a short integer value (e.g., from 0 to 63). When the transaction manager wants to assign a timestamp, it replaces the low bits of the timestamp counter with the site ID value. To ensure that the transaction manager does not use the same site for two transactions at the same time, vMVCC maintains an array of mutexes, one per site, and the transaction manager holds the site's mutex while computing the timestamp. The transaction manager can pick any site ID, such as the one associated with the local core. vMVCC takes a more flexible approach by assigning each thread a site ID in a round-robin manner. Having per-site mutexes ensures that the transaction manager does not contend when assigning timestamps on different sites.</p><p>Na&#239;vely replacing the low bits of the timestamp counter with the site ID leads to subtle correctness issues. For example, Txn A may choose the highest possible site ID (all ones), quickly execute, and commit. Txn B, runs after Txn A but chooses the lowest possible site ID (all zeroes). The processor ensures that the RDTSC value seen by Txn B is higher than that seen by Txn A, but once the low bits are replaced with all-ones and all-zeroes, it may be that Txn B's transaction ID is lower than that of Txn A. One possible fix would be to represent the transaction ID as a tuple of the complete 64-bit RDTSC value and the site ID. However, since transaction IDs are used throughout vMVCC, this leads to a noticeable performance overhead.</p><p>Instead, vMVCC modifies the timestamp algorithm to ensure that timestamps are strictly increasing. To obtain a timestamp, the transaction manager first obtains &#119905;, the current RDTSC value, and then computes the next highest value &#119905; &#8242; &#8805; &#119905; such that &#119905; &#8242; has the desired site ID in the low bits. The transaction manager then spins in a loop calling RDTSC until it returns a timestamp &#119905; &#8242;&#8242; &gt; &#119905; &#8242; . The transaction manager then uses &#119905; &#8242; as the transaction's ID. The reason this loop-based design achieves strictly increasing transaction IDs is that the transaction manager is holding the site's mutex while the CPU timestamp counter passed through &#119905; &#8242; . This means no other thread could have generated the same transaction ID. In practice, of course, the loop runs for a few cycles at most, since the RDTSC value will quickly exceed the loop threshold.</p><p>Whole-transaction execution. For developer convenience, vMVCC provides an interface that wraps up the details of beginning, committing, and aborting a transaction, in db.Run, a higher-order function whose implementation is as follows: The developer provides the body of the transaction, which can use Read, Write, and Delete to access the system state. The transaction body returns a boolean to indicate whether it wants to commit or abort.</p><p>3 Using and specifying vMVCC vMVCC is a transaction library that facilitates building and verifying applications by providing an atomic transaction abstraction. We begin with constructing on top of vMVCC an example application that atomically transfers some amount from one account to another, along the lines of what a bank application might do ( &#167;3.1). We then describe the formal specification of vMVCC and how to build arbitrary applications on top of it ( &#167;3.2).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.1">Example: AtomicXfer</head><p>Figure <ref type="figure">3</ref> shows the implementation of AtomicXfer (ignore the inline proof for now). This code is implementing a simple bank, transferring amt from the src account to dst. If not enough funds are available in src, the transaction aborts. vMVCC ensures that the logical effect of the transaction body, xfer, appears to apply atomically. This frees the developer from worrying about other concurrent transactions that  may affect the balance in src or dst, or about the versioning going on inside of vMVCC. vMVCC also ensures the transactions execute in a linearizable order, so that once AtomicXfer returns, any subsequent transactions will observe the effects of this AtomicXfer.</p><p>Sequential reasoning in xfer. vMVCC formalizes the fact that the developer need not consider other concurrent transactions by allowing the developer to use sequential reasoning for the body of the transaction. To achieve this, vMVCC uses Iris <ref type="bibr">[17]</ref>, a modern concurrent separation logic (CSL) <ref type="bibr">[29]</ref>, to specify its interface. In Iris/CSL, threads can own logical resources, and resource ownership can be exclusive, meaning that if one thread owns a resource, no other thread can own the same resource. For example, the resource &#119896; &#8614; &#119907; says that the value of &#119896; is &#119907;, and also says that the current thread owns &#119896;-that is, no other thread can own &#119896; &#8614; &#119907; in the meantime (and thus no other thread can read or write &#119896;).</p><p>In our example, the proof of the transaction body, xfer, assumes ownership of &#119904;&#119903;&#119888; t &#8614; &#119907; &#119904; * &#119889;&#119904;&#119905; t &#8614; &#119907; &#119889; ; the * operator ("separating conjunction") says the thread owns both resources and they are disjoint. Having ownership of these resources allows the proof to assume that it is the only one accessing &#119904;&#119903;&#119888; and &#119889;&#119904;&#119905;. This, in turn, allows the developer to prove xfer as if it was running in isolation, with no other concurrent transactions. To prove this, the developer considers each line of code, and how that code affects the resources owned by the thread, as shown in the proof state comments between lines of code.</p><p>Concurrent specification for AtomicXfer. Specifying a function with exclusive resource ownership (like we did with xfer) simplifies the reasoning for that function, but at the cost of limiting its implementations to sequential onesonly the thread owning the required resources would be allowed to execute the function.</p><p>To specify the behavior of AtomicXfer in Iris/CSL without requiring ownership of src and dst for the entire duration of AtomicXfer, vMVCC uses the notion of logical atomicity <ref type="bibr">[16]</ref>. Figure <ref type="figure">4</ref> shows the flow of resources in a logically atomic specification of AtomicXfer as compared to that of sequential xfer. The xfer specification says that the thread owns the resources throughout the entire execution of xfer, whereas in AtomicXfer, the specification says that there will be some point in time at which AtomicXfer appears to run atomically. One notable difference here is the kinds of resources appearing in the two specifications. Intuitively, the &#119896; t &#8614; &#119907; used by xfer says that "this transaction believes the value of &#119896; is &#119907;", whereas the &#119896; &#8614; &#119907; used by AtomicXfer reflects "the actual value of &#119896; is &#119907;". We will explain the meaning of these resources in more depth in &#167;3.2.</p><p>The resulting logically-atomic specification for AtomicXfer captures that any number of threads are allowed to concurrently invoke AtomicXfer, possibly with overlapping src and dst values. For each thread's invocation of AtomicXfer, the specification says that the transfer will execute correctly and atomically. The application can, in turn, prove that this maintains some application-level invariant, such as the sum of the balances of all accounts remains fixed.</p><p>Proving AtomicXfer. Proving AtomicXfer involves two parts. First, the developer proves that xfer meets its specification, as described above. Second, the developer uses the vMVCC library to obtain a proof that AtomicXfer's specification is the logically-atomic equivalent of xfer's sequential specification, as shown in Figure <ref type="figure">3</ref>. The next subsection describes how vMVCC formally specifies db.Run in the general case to enable this second step.</p><p>The angle brackets indicate a logically atomic specification <ref type="bibr">[16]</ref>. The vertical arrow indicates that, as a precondition for invoking db.Run, the developer must prove the standard Hoare-logic specification shown above the arrow for body. Not shown is the part of the specification that describes the representation predicates. We color the resources established for commit with green, and for abort with red.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="3.2">Specifying the transaction interface</head><p>Transactions give users an illusion that they are "isolated" from each other. To capture this intuition, we define the resource &#119896; t &#8614; &#119907; (which already showed up in the above example) as the transaction-local view of the system state. We can then specify operations that manipulate the transactionlocal view in terms of &#119896; t &#8614; &#119907;:</p><p>These specifications use standard Hoare-logic syntax, where {&#119875;} op {&#119876;} means that, if op runs starting with the resources specified in precondition &#119875;, it will return with the resources as specified in the postcondition &#119876;.</p><p>Next, we define the resource &#119896; &#8614; &#119907; as the logical view of the system state, representing the linearizable state. The fact that only a single value of each key is exposed to users might seem counter-intuitive in the case of MVCC, given that the system physically stores multiple values for each key. However, from the application's point of view, it suffices to view the abstract state of the system as having a single value for each key at any given point in time, and updating that value at the transaction's linearization point. (We discuss this in more detail in &#167;4.2.)</p><p>The specification of db.Run shown in Figure <ref type="figure">5</ref> connects these two kinds of resources. This is also the top-level theorem of vMVCC as a transaction library. The specification requires the developer to prove a sequential specification for body with a precondition that takes the transaction-local view of some set of key-value pairs, &#119898;, along with some Given such a specification for body, the specification of db.Run says that db.Run(body) will be the logically atomic equivalent: at some instant during its execution, it will swap the logical view of &#119898; satisfying &#119875;(&#119898;) for that of &#119898; &#8242; satisfying &#119876;(&#119898;, &#119898; &#8242; ). Further, if this transaction aborts (either at its own will or because of conflicts with another transaction), then db.Run(body) keeps the logical view of &#119898; intact.</p><p>As an example, we can instantiate &#119875; and &#119876; for AtomicXfer from &#167;3.1 as follows:</p><p>The use of &#119875; and &#119876; as arbitrary predicates allows the db.Run specification to capture the behavior of body and transfer it to the logically atomic specification of db.Run(body). One technicality here is that &#119875; and &#119876; are both pure predicates, meaning they cannot encode ownership of other resources, but merely restrict the values of &#119898; and &#119898; &#8242; .</p><p>The specification of db.Run can be regarded as a programlogic formalization of strict serializability <ref type="bibr">[15]</ref> in the database literature. Serializability comes from the part of the specification that says transactions appear to observe and modify the system state one at a time (at their linearization point), with strictness owing to the fact that they do so during the course of their respective execution (and hence the serial order respects the transaction precedence order).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4">Proving vMVCC</head><p>This section describes the important aspects of our proof for vMVCC. We start with a key verification challenge and how we solve it with prophecy variables ( &#167;4.1). We describe how we abstract a tuple from its physical representation containing multiple versions to its logical view with a single value, which potentially reflects some update that happens only in the future ( &#167;4.2). We present a key invariant about the prophecy variable used in vMVCC, and how the invariant helps maintain other system-wide invariants under correct and incorrect predictions ( &#167;4.3). We discuss how we define the transaction-local view of the system state, and its connection to the logical view ( &#167;4.4). We finally conclude this section with the challenges and the approach regarding proving strict monotonicity of transaction IDs ( &#167;4.5).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.1">Speculation using prophecy variables</head><p>We introduce the verification challenge with an example shown in Figure <ref type="figure">6</ref>. Observe that in the example, the value of &#119896; to be read by Txn 10 is determined up front by &#119896; &#8614; &#119907; at its linearization point, despite the fact that by the second read of Txn 10, Txn 15 has already committed and updated the physical state of &#119896;. Similarly, the write of Txn 15 updates the logical state to &#119896; &#8614; &#119907; + 1 before it physically executes. This kind of "speculative" behavior of MVCC turns out to be tricky to reason about in a Hoare-logic reasoning style where the proof considers each line of code in turn and reasons about how that code updates the abstract and physical states. The challenge arises from the fact that MVCC transactions linearize when their timestamp is generated. In the proof, the logical state must be updated at the transaction's linearization point, which happens before the transaction body runs. The changes to the logical state depend both on the transaction itself (i.e., what data the transaction decides to write), as well as conflicts with other transactions (i.e., whether another transaction reads or writes the same keys as this transaction in a way that will force this transaction to abort, as discussed in &#167;2). This poses the question: how do we know, at the transaction's linearization point, what values will a transaction write, and whether a transaction will encounter a conflict and thus be forced to abort? To tackle this issue, we use prophecy variables.</p><p>Intuitively, prophecy variables allow the proof to speculate about future execution. In the case of vMVCC, the prophecy variable is a list of transaction actions, which describes what actions each transaction will perform, and in what order. We refer to the list as the future-action list. There are two kinds of actions in vMVCC's proof: &#57903; &#119898; &#119905; ("Txn &#119905; commits and applies updates &#119898; to the system state") and &#57918; &#119896; &#119905; ("Txn &#119905; reads key &#119896;"). Transaction aborts are represented by a commit with an empty write-set.</p><p>At transaction begin time, vMVCC's proof uses the prophecy variable to speculatively predict the execution of the transaction, which allows the proof to update the logical state as if it knew what the transaction is going to do. The main challenge of using the prophecy variable, however, is that some of the predictions could be incorrect-it predicts something that does not match what happens later. As an example, Figure <ref type="figure">7</ref> shows five concrete predictions for Txn 15 that increases the value of &#119896; by 1. Only the bottom prediction turns out to be correct when the transaction actually commits. The incorrect predictions eventually diverge from the actual changes made by the transaction, and will make the logical state inconsistent with the physical state.</p><p>To deal with the divergence, the proof performs prophecy resolution at the point where the transaction actually commits and updates the physical state. Prophecy resolution allows the proof to stop considering cases corresponding to predictions that did not match reality, and continue only with the cases that did. We will elaborate more on correct/incorrect predictions and prophecy resolution with a concrete example in &#167;4. <ref type="bibr">3.</ref> This description may make it sound like there are a large number of cases to consider in the proof, greatly increasing the proof burden. In practice, the predictions are symbolic, rather than concrete timestamps, keys, and values; for instance, the prophecy variable speculates the updates made by a transaction as a symbolic partial map. Furthermore, the proof can group together many speculative executions (e.g., those in which the transaction of interest is speculated to commit without encountering a conflict), and consider the entire family of executions just once.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.2">Incorporating speculation in abstract state</head><p>vMVCC exposes a single linearizable copy of the system state, thereby freeing the users from explicitly reasoning about the timestamps. Thus, the logical view (shown in the "logical" row of Figure <ref type="figure">8</ref>) of vMVCC is a single value for every key, and the proof must connect this logical view to the physical state (shown in the "physical" row of Figure <ref type="figure">8</ref>), consisting of the Go struct representing each tuple.</p><p>This connection is challenging for several reasons, including the fact that the Go data structure contains multiple versions, and the fact that the value in the logical view may not even be present in the Go data structure, if it is made by a write speculated by the prophecy variable for an active transaction. Moreover, reasoning about the physical layout of the tuple in all intermediate proofs is cumbersome.</p><p>To address these challenges, we introduce two intermediate layers modeled with monotonic lists (i.e., lists that only grow). The first is the linear view of the tuple, shown in the "linear" row of Figure <ref type="figure">8</ref>. The linear view is a contiguous list of values, indexed by timestamps. The linear view gives us an elegant way to specify operations on tuples: reading a tuple with a given timestamp &#119905; just returns its value at index &#119905;. If the transaction needs to extend tslast, doing so extends the linear view up to the new tslast timestamp, filling in new entries with the last value in the list. Writing a tuple with a given timestamp &#119905; extends the tuple up to index &#119905;, and appends the new value to the end.</p><p>To capture the speculative behavior of MVCC as described in &#167;4.1, we add the "speculative" layer, as shown in Prophecy</p><p>An example execution with a prediction that Txn 5 commits despite conflicts. Figure <ref type="figure">9</ref>: Two example executions illustrating how the proof handles correct and incorrect predictions in Figure <ref type="figure">9</ref>(a) and Figure <ref type="figure">9</ref>(b), respectively. We indicate the linearization and prophecy resolution points with red and blue dots, respectively. For concreteness, we use Txn 5 in the examples, but in the actual proof, the timestamp is just a symbolic value &#119905; that represents all possible timestamps. Note that all these states are sealed in some global invariant to enable sharing-each thread (or, transaction) can access them only at its atomic steps, including the linearization and prophecy resolution points. This means that the states could have changed by another thread between two atomic steps.</p><p>based on the prophecy variable. The linear view is updated when physically reading and writing a tuple.</p><p>We use these intermediate views to relate vMVCC's physical state to its top-level logical view, as shown in Figure <ref type="figure">8</ref>, for each key in the system state. The tuple abstraction relation describes how the physical tuple layout is connected to its abstract linear view. The prefix invariant requires that the linear view must be a prefix of the speculative view, capturing the intuition that the speculative view runs ahead of the linear one. Finally, the last-value invariant says the last element of the speculative view is equal to the top-level logical value of that key. vMVCC's proof heavily relies on the invariants maintained between these layers.</p><p>Modeling these intermediate views as monotonic lists allows the proof to seal their "authoritative" ownership in a global invariant for sharing among transactions, but at the same time enables the proof to retain knowledge about existing prefixes of the lists. As we will see in &#167;4.4, this is crucial to bridge the gap between reading the logical state at the linearization point, and reading the physical state later on when the transaction actually executes.</p><p>Abstraction relation under GC. In the presence of GC, the tuple abstraction relation (shown as AR in Figure <ref type="figure">8</ref>) cannot hold on all timestamps, as that would require mutating the existing part of the linear view when removing unusable versions from the physical state. As mentioned in &#167;2, the key idea of GC safety is to identify versions that will not be accessed by any transactions, including those that have not even begun. We formalize this line of reasoning with a monotonic timestamp &#119905; safe , which serves as a lower bound on the transaction IDs of all active and future transactions.</p><p>To start a round of GC, the garbage collector first computes a new &#119905; safe , and then relaxes the abstraction relation of the target tuples so that it no longer places any constraints on versions whose lifetime ends before &#119905; safe . Doing so allows the garbage collector to delete those versions without violating the abstraction relation. We further weaken the specification for reading and writing a tuple at timestamp &#119905; by requiring a proof of &#119905; &#8805; &#119905; safe in their precondition, ensuring that the deleted versions are never observed.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.3">Maintaining invariants under speculation</head><p>One challenge in vMVCC's proof stems from the fact that prophecy variables can speculatively predict that a transaction will commit in the future, while at the same time predicting earlier transactions that conflict with it. This brings up two challenges related to the system-wide invariant maintained by vMVCC's proof.</p><p>The first challenge is that the invariant ensures that transactions cannot commit in the presence of conflicts, which would be at odds with the (ultimately incorrect) speculative prediction described above. This makes it impossible for the proof developer to update the logical state based on the incorrect predictions but still maintain the invariant, which must always hold. To get around this issue, vMVCC's proof treats such inconsistent predictions as transaction aborts, which makes it easy to maintain the invariant and thereby carry through the prediction to the prophecy resolution point.</p><p>The second challenge stems from the fact that an inconsistent prediction, such as the example above, involves multiple transactions, and therefore relies on prophecy resolution in multiple threads. The prediction about each individual transaction and thread could be correct in its own right, but it is the combination of them that leads to a contradiction. How should the proof be structured to establish the contradiction despite only doing one prophecy resolution at a time? vMVCC's proof addresses this challenge by maintaining a sufficiently strong invariant that carries along facts from each prediction to derive contradictions against later predictions as needed, as we describe below.</p><p>To illustrate this point, we first sketch out the proof for a correct prediction, where a transaction commits and there are no conflicts that would have forced it to abort, and then show how vMVCC's proof handles incorrect predictions.</p><p>Predicted commit without conflicts. In Figure <ref type="figure">9</ref>(a), Txn 5 is speculated to commit without encountering any conflict. The reason is that at its linearization point, the commit action of Txn 5 in the future-action list, &#57903; (&#119896;,&#119907; 5 ) 5 (there might be multiple of them in the list, but the proof cares only about the first one), is conflict-free against all the actions prior to it. We define &#57903; &#119898; &#119905; to be conflict-free against an action &#119886; if (1) &#119886; = &#57918; &#119896; &#119905; &#8242; , where &#119905; &#8242; &#8804; &#119905; &#8744; &#119896; &#8713; dom(&#119898;), or (2) &#119886; = &#57903; &#119898; &#8242; &#119905; &#8242; , where &#119905; &#8242; &lt; &#119905; &#8744; dom(&#119898; &#8242; ) &#8745; dom(&#119898;) = &#8709;. Knowing that Txn 5 will commit without conflicts, the proof safely extends the speculative view up to timestamp 5 using the old value &#119907; 2 , and appends the new value &#119907; 5 to it (which updates the logical view to &#119907; 5 as well) without violating the conflict-free invariant, as described below.</p><p>Intuitively, the conflict-free invariant requires that a transaction reflects its update to the speculative view only if the first commit action of the transaction is conflict-free against all the actions prior to it in the future-action list. As we will see below, this invariant is crucial to prove invariance of the prefix property between the linear and speculative views.</p><p>On reading key &#119896;, the proof resolves the head of the futureaction list to &#57918; &#119896; 5 . Then, it uses the conflict-free invariant to deduce that transactions which contain updates to the speculative view, but not to the linear view, must have timestamps greater than or equal to the timestamp of this read. This implies that the speculative view can differ from the linear view only after a timestamp &#119905; &gt; 5, allowing the proof to re-establish the prefix invariant after extending the linear view. A similar reasoning goes for commit, except the proof additionally uses the promise that Txn 5 will commit to know the value at timestamp 5 of the speculative view is &#119907; 5 .</p><p>Predicted commit despite conflicts. In Figure <ref type="figure">9</ref>(b), Txn 5 is speculated to commit despite the presence of conflicts because its first commit action, &#57903; (&#119896;,&#119907; 5 )</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>5</head><p>, conflicts with an earlier action &#57903; (&#119896;,&#119907; 6 )</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head>6</head><p>. The proof, as in the previous case, extends the speculative view up to timestamp 5 using the old value &#119907; 2 ; however, it does not append the new value &#119907; 5 as doing so would violate the conflict-free invariant, and proceeds as if the transaction will abort, which makes the invariant true.</p><p>For read, the proof of the prefix property is similar to the previous case. For commit, however, the proof cannot re-establish the prefix property after extending the linear view, because it indeed did not apply the new value &#119907; 5 at the linearization point. Fortunately, at this point the proof knows two facts that contradict each other: (1) reaching the prophecy resolution point for commit, the execution must have passed the conflict detection as illustrated in Figure <ref type="figure">2(b)</ref>, implying the length of the linear view &#119897; &#8804; 5 + 1 (the +1 part is due to our lists being zero-indexed); (2) some conflicting action (in this case &#57903; (&#119896;,&#119907; 6 ) <ref type="formula">6</ref>), which extends the linear view to at least timestamp &#119905; &gt; 5, must have happened before Txn 5 commits, implying &#119897; &gt; 5 + 1. The proof closes this case with the derived contradiction.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.4">Abstract state of a transaction</head><p>As mentioned in &#167;4.1 (and illustrated in Figure <ref type="figure">6</ref>), the value of key &#119896; to be read by a transaction is determined up front by &#119896; &#8614; &#119907; at the transaction's linearization point. Reading from the physical state, however, happens only at some later point in time, and the value is based on &#119896; t &#8614; &#119907; &#8242; , as specified in &#167;3.2. This means the proof has to somehow connect &#119896; &#8614; &#119907;, &#119896; t &#8614; &#119907; &#8242; , and &#119907; &#8242;&#8242; , the result of physically reading the tuple of &#119896;. This section describes how the system-wide invariants shown in Figure <ref type="figure">8</ref> establish that connection.</p><p>Let us first consider the case where the transaction has not written key &#119896;. Our first step then is to show &#119907; = &#119907; &#8242; . Recall that at the linearization point of Txn &#119905; that reads or writes &#119896;, we extend the speculative view of &#119896; up to &#119905; using its last value. Doing so, along with the last-value invariant, allows us to deduce that the value of the speculative view at index &#119905; is &#119907; (and will remain so since the speculative view is monotonic). The proof then follows from the definition of the transaction-local invariant, which says that if Txn &#119905; has not written &#119896;, then &#119907; &#8242; , the transaction-local value, is equal to the value of the speculative view at index &#119905;.</p><p>Our next step is to show &#119907; &#8242; = &#119907; &#8242;&#8242; . Again recall that physically reading the tuple of &#119896; at timestamp &#119905; means extending the linear view of &#119896; up to &#119905; (if the value at &#119905; is still absent), and looking up its value at index &#119905;. The proof of &#119907; &#8242; = &#119907; &#8242;&#8242; then follows immediately from the prefix invariant that requires the linear view to remain a prefix of the speculative one. Now consider the case where the transaction has last written &#119896; with value &#119906;. As specified in &#167;3.2, the logical effect of the write is &#119896; t &#8614; &#119906;. We thus define the remaining case for the transaction-local invariant: if the transaction has written &#119896;, then the transaction-local value is equal to the value in its local write buffer.</p><p>The contents of the write buffer are also what the speculated updates in a commit action (i.e., &#119898; in &#57903; &#119898; &#119905; ) resolve to. This allows us to obtain the equality between the speculated updates with the actual updates at the prophecy resolution point, which is crucial when re-establishing the prefix invariant as discussed in &#167;4.3.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="4.5">Strict monotonicity of transaction ID</head><p>Another challenge in vMVCC's proof is establishing strict monotonicity of transaction IDs, for vMVCC's RDTSC-based algorithm described in &#167;2. The challenge lies not only in proving that the algorithm generates strictly increasing transaction IDs, but also in being able to logically execute the transaction (i.e., update the logical state) at the linearization point corresponding to that transaction ID. The reason this is challenging is that the linearization point for some transaction ID &#119905; &#8242; might not correspond to any line of code that was executed for this transaction-the algorithm simply spins in a loop waiting for RDTSC to advance past &#119905; &#8242; , and linearization occurs when any transaction observes that &#119905; &#8242; has passed.</p><p>To formally reason about this algorithm, vMVCC's proof maintains a logical table of slots, one per timestamp. The slot contains the logical set of changes that a transaction with that timestamp wants to perform, represented as a ghost function. The actual state changes performed by this ghost function are determined by prophecy variables, as described above. The proof uses the slots to invoke the ghost functions for each timestamp in order, as the RDTSC clock advances; the proof maintains a "latest-slot" timestamp corresponding to the last table slot that has been invoked. The invariant associated with this proof states that this latest timestamp is always below (or equal to) the real RDTSC clock. Furthermore each future slot is protected by the site's mutex that corresponds to this timestamp.</p><p>When the transaction manager first computes &#119905; &#8242; , it registers the &#119905; &#8242; slot in the table, putting in a ghost function that will perform its transaction's changes. Since &#119905; &#8242; &gt; &#119905;, the proof has not yet invoked the ghost function for this slot, and the current thread also holds the site's mutex needed to fill this slot (which proves that no concurrent thread could fill the same slot). As the transaction manager runs the loop waiting for RDTSC to move past &#119905; &#8242; , it updates the latest-slot with each iteration, executing all of the ghost functions in the slots that have been advanced over. The proof takes advantage of later credits <ref type="bibr">[31]</ref> in Iris that enable verification of this "unsolicited helping" pattern.</p><p>The invariant for the slot table says that, for every slot with a timestamp below the latest-slot, its ghost function callback has been invoked. As a result, when the transaction manager's loop exits, it knows that the latest-slot is at least as high as &#119905; &#8242; , and therefore its ghost callback must have been invoked (either by this same thread or by some other thread running the same loop).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="5">Implementation and proof details</head><p>We implemented vMVCC in Go, and verified its implementation using the Perennial framework <ref type="bibr">[3]</ref> (based on Iris <ref type="bibr">[21]</ref><ref type="bibr">[22]</ref><ref type="bibr">[23]</ref> and Coq <ref type="bibr">[33]</ref>), using Goose <ref type="bibr">[4]</ref> to lift vMVCC's Go code into  Perennial. To enable vMVCC's proofs of MVCC transaction linearizability, we incorporated prophecy variable support from Iris <ref type="bibr">[18]</ref> into Perennial. Figure <ref type="figure">10</ref> summarizes the implementation and proof effort, not including changes to Perennial that were necessary for the verification. The lines of proof include the specifications for each function in vMVCC's implementation. The proof effort for vMVCC required about 13&#215; as many lines of proof as lines of code, which is in the same ballpark as other verified systems that handle concurrency <ref type="bibr">[3,</ref><ref type="bibr">6,</ref><ref type="bibr">13]</ref>.</p><p>The implementation contains several low-level optimizations that improve performance. We used RDTSC to generate transaction IDs. We also padded data structures to avoid false cache-line sharing that limits multi-core scalability, and sharded the index and the set of active transaction IDs to reduce contention from concurrent accesses.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="5.1">Bugs found during verification</head><p>When we were first designing and implementing vMVCC, we were careful to structure the code in a way that makes it clear why the code is correct, what the invariants are, how they are maintained, and what guarantees each interface or function provides. Nevertheless, during the actual verification, we ran into several bugs in corner cases that we missed or did not correctly handle in the implementation, highlighting the importance of formal reasoning. In this subsection, we give several examples of such bugs.</p><p>One interesting bug we found when verifying vMVCC is related to garbage collection. The buggy code is: among them. If every transaction site is empty (i.e., if every site returned MAX_U64), the garbage collector generates a timestamp using an arbitrary site. (Recall that vMVCC always places a site ID in the low bits of the timestamp, and the choice of site ID does not matter, as it is purely there to ensure uniqueness.) The bug arises when a transaction enters the system right after getSafeTS returns, and then the garbage collector computes a timestamp larger than the ID of that transaction. Our fix to this bug is to generate a timestamp within each site, as shown in the commented-out code. Doing so ensures that future transaction IDs generated by this site will be larger than the one getSafeTS returns.</p><p>Another subtle bug we discovered is missing the wait loop when generating transaction IDs, violating the strict monotonicity of our timestamp generation scheme. The fix was the looping RDTSC algorithm described in &#167;2. Finally, since our protocol is centered around timestamps, we also discovered several off-by-one errors in the implementation when conducting the verification of vMVCC (e.g., where greater-than comparisons should have been greater-than-orequal-to comparisons).</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="6">Evaluation</head><p>We experimentally answer the following questions:</p><p>&#8226; Is vMVCC competitive with state-of-the-art unverified systems? ( &#167;6.2)</p><p>&#8226; Does the use of MVCC in vMVCC help with long-running read-only transactions? ( &#167;6.3)</p><p>&#8226; Are the low-level optimizations in vMVCC important for performance? ( &#167;6.4)</p><p>&#8226; Does vMVCC scale under high-contention workloads? ( &#167;6.5) We used the YCSB benchmark <ref type="bibr">[7]</ref> to understand the performance characteristics of vMVCC under various workloads. Unless otherwise specified, we execute each YCSB put or get in a separate transaction. The data set contains 1M keyvalue pairs with each key being an 8-byte integer and value an 100-byte string. The access pattern follows the uniform distribution, or the Zipfian distribution, with a parameter &#120579; controlling the skewness of the distribution. We vary the read-write ratio and the number of keys accessed in each transaction.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="6.1">Experimental setup</head><p>We also used the TPC-C benchmark, which involves more sophisticated transactions. TPC-C models the operation of a wholesale supplier, a common online-transaction processing (OLTP) workload. It contains 9 tables and 5 kinds of transactions, each with various workload characteristics. In particular, most transactions can be processed in a single warehouse, so it is natural and efficient to map each warehouse to one thread. Our current implementation of vMVCC requires the key to be an 8-byte integer, and every tuple needs a key. Because of these limitations we made two modification to TPC-C. First, we do not support "get customers by their last name" appearing in the OrderStatus and NewOrder transactions; they are replaced with just "get customers by customer ID". Second, the History table does not have a primary key, so we randomly generate one for it.</p><p>We employ a background GC thread for vMVCC in every experiment. We repeat each experiment 10 times, each for 30 seconds. We report the mean, minimum, and maximum (the last two as error bars) among the 10 runs.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="6.2">Comparison with Silo</head><p>To evaluate whether vMVCC achieves competitive performance with state-of-the-art systems, we compare vMVCC to Silo <ref type="bibr">[35]</ref>, a high-performance transactional database system. Because vMVCC does not store data durably, we compare with MemSilo, a variant of Silo that does not persist its data. Silo is an OCC/MVCC based system, using OCC to provide serializability, and using MVCC to access a consistent snapshot of old versions. Unlike vMVCC, Silo does not generate a new version for every write, but only once per snapshot epoch (on the order of 1 second), which reduces memory management costs. Silo's OCC/MVCC design has the ad- vantage of lower memory usage and allocation overhead over vMVCC's pure MVCC design. On the other hand, Silo only ensures its snapshot transactions (those that access past versions) always read a consistent snapshot, without imposing ordering constraints on them with respect to normal linearizable transactions, whereas in vMVCC, a "snapshot transaction" is simply a linearizable transaction that does not perform writes.</p><p>Figure <ref type="figure">11</ref> shows the results of the comparison for several configurations of YCSB and TPC-C, normalizing to the throughput achieved by Silo. Similarly to Silo, each worker thread in vMVCC generates the workload parameters and then immediately processes the transaction. We used a YCSB profile where each transaction accesses a single key sampled from a uniform distribution. vMVCC achieves 96.6% the throughput of Silo for a read-only workload in YCSB, and 38.8% for a write-only workload. For TPC-C, vMVCC achieves 43% the throughput of Silo for 1 warehouse and 25.7% for 32 warehouses. We hypothesize that the performance difference between Silo and vMVCC is largely due to (1) vMVCC's higher memory allocation overhead for storing past versions, and (2) its inefficient way of executing range scans-lacking a tree-like index structure, vMVCC relies on the continuity invariant of TPC-C <ref type="bibr">[34]</ref>, and expands a range query into multiple point queries. To test these hypotheses, we conducted the following two experiments.</p><p>First, we ran the same write-only YCSB workload, except that we fixed the write value to some statically allocated string, and modified vMVCC to perform in-place update on its tuples, without changing any other parts of the code (hence the resulting system is not even correct, but it is merely for us to understand more about vMVCC's performance characteristics). Applying these changes increases the relative performance from 38.8% to 87.3%.</p><p>Second, we ran an additional range scan workload where each transaction first randomly picks a starting key, and then reads the next 100 keys. Silo executes each transaction with a single scan, whereas vMVCC issues 100 reads. Figure <ref type="figure">11</ref> shows the results in the "scan" column. vMVCC achieves 48.1% of Silo's throughput; the difference mostly attributes to more cache misses in vMVCC.</p><p>Based on these experiments, we conclude that the gap between vMVCC's performance and that of Silo is indeed largely due to memory allocation and vMVCC's lack of support for range scans. For benchmarks that do not stress these two aspects, vMVCC achieves performance competitive with Silo.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="6.3">Robustness to long-running readers</head><p>One main advantage of MVCC over traditional concurrency control protocols is that its performance should remain stable even in the presence of long-running readers. To confirm that vMVCC's design indeed achieves these performance benefits, we implemented a variant of vMVCC that uses twophase locking for concurrency control instead of MVCC, and compared the performance of vMVCC with this 2PL variant.</p><p>YCSB. We first compare vMVCC and 2PL under the YCSB workload, using a YCSB profile where each transaction reads or writes 4 keys. We fixed the number of threads to 24, &#120579; to 0.85, and varied the read-write ratio from 0% to 100%. We then ran one experiment without long-running readers, and another one where the workload includes 8 transactions repeatedly reading 10K keys (1% of the entire key space).</p><p>Figure <ref type="figure">12</ref> shows the results. In the absence of long-running readers, 2PL performs better than vMVCC for all read-write ratios except for the read-only workload (comparing the solid lines). The difference stems from MVCC's overhead of (1) generating timestamps and (2) keeping past versions and the associated memory allocation costs.</p><p>In the presence of long-running readers (comparing the solid and dashed lines of each system), vMVCC's throughput drops slightly between the range of 11.5%-22.2%, whereas 2PL's throughput drops significantly as the write ratio increases (e.g., 72.6% and 84.9% for write ratio 80% and 100%, respectively). As a result, the performance of 2PL with longrunning readers is worse than that of vMVCC for workloads with 40% or more writes; for instance, under write ratios 80% and 100%, vMVCC performs 2.2&#215; and 4&#215; better than 2PL, respectively. The reason is that, in 2PL, the long-running readers hold read locks on keys for a long duration, preventing other transactions from writing to those keys. TPC-C. We also compare vMVCC and 2PL under the TPC-C workload. Similarly to prior work <ref type="bibr">[36]</ref>, we add a read-only transaction StockScan that counts the number of each item in   all warehouses. We parametrize the workload by the interval of invoking StockScan. Figure <ref type="figure">13</ref> shows the results. When no StockScan is invoked (represented by the &#8734; interval on the x-axis), 2PL performs better than vMVCC by around 14%. However, when there are StockScan transactions running, NewOrder transactions that update the stock table will conflict with StockScan, and block under 2PL concurrency control. As the interval between StockScan transactions decreases, 2PL's performance drops significantly, whereas vMVCC throughput remains more-or-less the same, since StockScan accesses old versions of tuples and does not impact other transactions. For StockScan intervals 500 and 100 ms, the throughput of vMVCC is 11&#215; and 54.4&#215; that of 2PL. In terms of latency, vMVCC maintains its 99.9% latency around 3.4 ms across all StockScan intervals, whereas the 99.9% latency of 2PL increases from 3.2 ms in the absence of StockScan transactions, to a few tens and occasionally hundreds of ms when StockScan is invoked every 100 ms.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="6.4">Low-level optimizations</head><p>vMVCC implements (and verifies) two low-level optimizations to achieve high performance on many cores: (1) padding and sharding data structures and mutexes, to avoid cache-line contention, and (2) using RDTSC to generate transaction IDs without shared-memory contention. To understand whether they are important for performance, we enable each optimization in turn and measure the resulting performance. To stress the implementation, we chose a lightweight YCSB profile where each transaction accesses a single key. We chose a low-contention setting (&#120579; = 0.2) so that transactions largely access different portions of the key space; we will evaluate scalability under high contention in the next subsection.</p><p>To evaluate the benefit of the RDTSC-based transaction ID generation, we compare with two alternatives. The first is a lock-based design where the transaction manager acquires a mutex to get (and increment) the next transaction ID counter. The second is a lock-free implementation that uses the fetchand-increment (FAI) instruction to atomically obtain the next transaction ID.</p><p>Figure <ref type="figure">14</ref> shows the results. The optimizations have little effect on a single core, but significantly improve vMVCC's performance on 32 cores. Partitioning and padding index and transaction sites improves vMVCC's performance by 2.8&#215; at 32 cores. Using FAI increases throughput by a further 3&#215; over the lock-based design at 32 cores. Finally, RDTSC-based transaction IDs achieve yet another 3.7&#215; improvement in throughput compared to FAI at 32 cores. In summary, the results show that all of these optimizations are important for scaling vMVCC's performance with many cores.</p><p>Enabling all the optimizations, vMVCC's throughput scales by 15.6&#215; using 16 threads. The result suggests that vMVCC eliminates almost all contention on its internal data structures (when the keys themselves do not contend). The throughput scales further by 1.66&#215; when doubling the number of threads to 32, implying that vMVCC can benefit from hyper-threading even though not as much as from having more physical cores.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="6.5">Scalability under contention</head><p>The previous section showed that vMVCC scales nearly linearly for a low-contention workload, with its low-level optimizations. In this section, we evaluate vMVCC's scalability under high-contention workloads, using a YCSB profile where each transaction issues 4 reads/writes, with the skewness parameter &#120579; ranging from 0.8 to 0.95.</p><p>Figure <ref type="figure">15</ref> shows the results. For reads (Figure <ref type="figure">15</ref>(a)), before reaching the hyper-threading threshold (i.e., 18 cores), the throughput scales almost linearly with respect to the number of threads, except for extremely contended workloads (e.g., &#120579; = 0.95): the aggregated throughput of 16 threads is 14.9&#215; that of a single thread for &#120579; = 0.8, and 12.6&#215; for &#120579; = 0.95. Scalability drops after reaching the hyper-threading threshold because of interference, especially for higher skewness: using 32 threads achieves 22.8&#215; better performance for &#120579; = 0.8, and 16.9&#215; for &#120579; = 0.95.</p><p>For writes (Figure <ref type="figure">15</ref>(b)), asides from hyper-threading interference, having more contention also causes more conflicts between transactions, and hence higher abort rates. For instance, the abort rate at 32 threads for &#120579; = 0.8 is 4.8%, whereas for &#120579; = 0.95 is 27.6%. The result is that vMVCC's throughput with 32 threads is 11.7&#215; that of a single thread for &#120579; = 0.8 and 9.9&#215; for &#120579; = 0.95.</p><p>The results show that vMVCC's performance scales with the number of cores even for workloads of high contention.</p><p>7 Related work vMVCC is the first formally verified MVCC-based system, but builds on prior work on formal verification and specification of transactions, as we now discuss.</p><p>Verified systems. The closest related work to vMVCC is GoTxn <ref type="bibr">[6]</ref>, a verified transaction library that uses 2PL for concurrency control. GoTxn stores data durably to disk and uses the verified GoJournal <ref type="bibr">[5]</ref> journaling system to provide crash atomicity. vMVCC uses a more sophisticated concurrency control plan (MVCC), which allows it to achieve high performance for long-running read-only transactions, while GoTxn uses standard 2PL which does not perform well with long-running readers. vMVCC also implements and verifies sophisticated optimizations, such as strictly increasing RDTSC-based timestamps, which are not present in GoTxn.</p><p>Malecha et al. <ref type="bibr">[28]</ref> verified a simple relational database, focusing on SQL queries, the relational data model, and the use of B+-trees on disk. These issues are complementary to the focus of vMVCC, which targets handling concurrent transactions using sophisticated concurrency control protocols and low-level optimizations.</p><p>Prophecy variables. Abadi and Lamport <ref type="bibr">[1]</ref> first proposed prophecy variables as a proof technique to establish refinement mappings between state machines. Jung et al. <ref type="bibr">[18]</ref> later integrated it in a Hoare-style program logic. Prior work using prophecy variables is mostly focused on verification of protocols and small examples of data structures and algorithms, such as RDCSS, the Herlihy-Wing queue <ref type="bibr">[18]</ref>, and the atomic snapshot algorithm <ref type="bibr">[24]</ref>.</p><p>In this paper, we apply prophecy variables in a sophisticated transaction library. We use prophecy variables to make more elaborate predictions about the behavior of transactions, including what data they read and write, and we demonstrate that prophecy variables are useful for reasoning about transactions.</p><p>Framework for specifying and verifying transactions. Lesani et al. <ref type="bibr">[25]</ref> develop a framework for verifying software transactional memory systems and apply it to the NOrec transactional memory algorithm <ref type="bibr">[9]</ref>. NOrec uses a form of OCC, in which transactions check whether they have been invalidated by conflicting writes during commit time. As with 2PL, NOrec transaction's linearization point occurs during commit, and hence does not appear to require prophecy variables in its proof.</p><p>vMVCC uses logically atomic triples to specify transactions, instead of classical serializability and linearizability definitions <ref type="bibr">[15]</ref> that are based on trace equivalence (e.g., as used by GoTxn). This makes it easier to verify clients of a transaction library by proving Hoare triples about code running inside of the transaction library. Prior work has similarly found it useful to introduce alternate specifications for transactions and serializability in the context of formal verification. The Push/Pull model <ref type="bibr">[20]</ref> provides a set of primitive operations which can be used to describe a variety of Any system that can be decomposed into these operations is guaranteed to be serializable. C4 <ref type="bibr">[26]</ref> is a framework that supports verifying transactional objects, that is, concurrent data structures that allow chaining multiple operations together in an atomic transaction. The framework supports composing transactional objects as components of a higher-level transactional object.</p></div>
<div xmlns="http://www.tei-c.org/ns/1.0"><head n="8">Conclusion</head><p>This paper presented vMVCC, the first MVCC-based transaction library with a machine-checked proof of correctness. A key challenge in verifying vMVCC lies in reasoning about the linearization of transactions under MVCC, where the linearization point occurs before the transaction body actually runs. vMVCC addressed this challenge by using prophecy variables to speculate whether upcoming transactions are going to commit, and what values they are going to write, thereby allowing vMVCC to state and prove a simple yet general specification for its top-level transaction interface using logical atomicity. vMVCC incorporates further lowlevel optimizations, such as using RDTSC to generate strictly increasing transaction IDs, with corresponding proofs of correctness, to achieve high performance. An evaluation demonstrated that, for a range of YCSB and TPC-C workloads, vMVCC's throughput is 25-96% of the throughput of Silo, a state-of-the-art unverified system; that vMVCC benefits from MVCC to achieve good performance for longrunning read-only transactions compared to two-phase locking; and that vMVCC's low-level optimizations are important for achieving high performance. At the same time, vMVCC's proof effort-13&#215; as many lines of proof as lines of code-is on par with other verified concurrent systems.</p></div></body>
		</text>
</TEI>
