Dynamic Timestamp Allocation for Reducing Transaction Aborts
Total Page:16
File Type:pdf, Size:1020Kb
1 Dynamic Timestamp Allocation for Reducing Transaction Aborts Vaibhav Arora, Ravi Kumar Suresh Babu, Sujaya Maiyya, Divyakant Agrawal, Amr El Abbadi vaibhavarora, ravikumar, sujaya maiyya, agrawal, [email protected] Department of Computer Science, University of California, Santa Barbara Xun Xue, Zhiyanan, Zhujianfeng xun.xue, zhiyanan, [email protected] Huawei 300 Abstract—CockroachDB is an open-source database, providing 1,500 Throughput transactional access to data in a distributed setting. CockroachDB Aborts employs a multi-version timestamp ordering protocol to provide 200 1,000 serializability. This provides a simple mechanism to enforce serializability, but the static timestamp allocation scheme can lead to a high number of aborts under contention. We aim to 500 100 reduce the aborts for transactional workloads by integrating a dynamic timestamp ordering based concurrency control scheme Throughput (Txns/sec) 0 0 Number of Aborts/1000 txns in CockroachDB. Dynamic timestamp ordering scheme tries to 50:50 60:40 70:30 80:20 90:10 99:01 reduce the number of aborts by allocating timestamps dynami- Contention Ratio cally based on the conflicts of accessed data items. This gives a Fig. 1: Performance of Fixed Timestamp Ordering Scheme transaction higher chance to fit on a logically serializable timeline, under Contention. Contention ratio x:y specifies that x percent especially in workloads with high contention. of the transactions access y percent of the items. I. INTRODUCTION logical serializable timeline. We integrate CockroachDB with CockroachDB [2] is an open-source distributed SQL the dynamic timestamp allocation technique we designed in database built on a transactional and strongly-consistent key- our previous work MaaT (Multiaccess as a Transaction) [17]. value store. The transactional guarantees are provided over MaaT changes the validation phase of the optimistic con- data, which is synchronously replicated using a distributed currency control mechanism to allocate a commit timestamp consensus protocol, Raft [18]. dynamically by keeping track of the items accessed and CockroachDB provides two transaction isolation levels: SI conflicting transactions accessing the items using read and (Snapshot Isolation) [9] and Serializable [10]. Snapshot Iso- write markers. By performing dynamic timestamp allocation lation can detect write-write conflicts among transactions and during validation and commit, MaaT is able to reduce aborts provides efficient performance, but does not guarantee serializ- under contention. ability [15]. Applications needing stricter correctness guaran- Adapting the dynamic timestamp allocation technique de- tees than snapshot isolation can use the Serializable isolation signed in MaaT with the SSI implementation in CockroachDB level, which is provided using a Serializable Snapshot Isolation can eliminate unnecessary aborts. Our technique targets cases (SSI) [23] based technique. To implement SSI, CockroachDB where transactions are aborted due to being non-serializable employs a lock-free multi-version timestamp ordering scheme. because of a fixed timestamp ordering, rather than being The timestamp ordering scheme in CockroachDB uses a fixed aborted because of actual conflicting order of access of items timestamp allocation scheme, and assigns timestamps at the (in other words an ordering that would lead to cycle in a start of each transaction. These timestamps are used as commit conflict graph). Some of these cases are serializable when timestamp for the transaction. This commit timestamp is used timestamps are dynamically allocated to fit them on a logicial to order the transactions in logical timestamp order, and hence timeline, based on the order of access of data items. enforce serializability. SSI, unlike SI, detects and handles read- CockroachDB is modified to integrate the dynamic times- write conflicts but the restrictive fixed timestamp ordering tamp ordering based concurrency-control mechanism. As the leads to higher number of aborts under contention. Figure 1 concurrency-control layer interacts with the lower layers of illustrates that with increasing contention in the workload, the the database for ensuring strong consistency of data, multiple number of aborts increases, leading to a drop in throughput components had to be modified to integrate the technique. with timestamp ordering concurrency-control employed in Past techniques proposed to reduce aborts in lock-free CockroachDB. concurrency control techniques [26], [17], [25] have been To reduce the number of aborts at high contention, a implemented and evaluated in standalone prototypes. Imple- possible strategy is to use dynamic timestamps for allocating menting the dynamic timestamp ordering technique in a full- the commit timestamp to a transaction. In this technique, the featured database system like CockroachDB gives an insight system tries to dynamically allocate a timestamp range to into the performance characteristics of the dynamic timestamp each transaction, based on the conflicts of data items accessed ordering like optimizations, and how to integrate such opti- by the transaction. At commit, a timestamp is allocated to mizations in existing systems. the transaction from that range, to fit that transaction on a A benchmark is also developed to extensively evalu- ate the performance of dynamic timestamp ordering based patterns which occur in non-serializable patterns in Optimistic concurrency-control in CockroachDB. The benchmark eval- concurrency control (OCC) algorithms. Rather than aborting a uates the performance while varying contention, the degree transaction on detecting an anti-dependency, as in OCC, BCC of concurrent access and the ratio of read-only and read- tracks dependencies to abort transactions only when these write transactions. The source-code changes as well as the non-serializable patterns are detected. Although a BCC like benchmark are available on Github [4], [1]. technique would reduce the number of aborts, it adds extra The rest of the paper is organized as follows. Related overhead to track dependencies. work is discussed in Section II. In Section III, we describe Deterministic transaction scheduling [22] has also been pro- CockroachDB’s architecture. Section IV describes the dynamic posed to eliminate transaction aborts and improve performance timestamping technique employed by MaaT. An abstract under high contention. However, such techniques need a priori overview of the integration of dynamic timestamp allocation knowledge of read-write sets and do not work in an ad-hoc in CockroachDB is presented in Section V. The details of the transaction access setting, like in CockroachDB. integration and the implementation are provided in Section VI. CockroachDB’s [2] SSI technique employs timestamp allo- Evaluation results are presented in Section VII. Section VIII cation, is lock-free and can support distributed transactions. concludes the paper. Hence, dynamic timestamping proposed in MaaT is a good fit for CockroachDB, since it is timestamp based and lock-free. II. BACKGROUND The SI implementation in CockroachDB also provides a mech- Snapshot Isolation (SI) has been implemented in major anism to push commit timestamps for distributed transactions. database systems, like Oracle and PostgreSQL. Fekete et However, this technique cannot be applied to SSI [3]. al. [15] illustrated that SI does not provide serializability and III. COCKROACHDB OVERVIEW then subsequently Fekete et al. [14] studied the transaction patterns occurring in SI violations. Various techniques have CockroachDB [2] is an open-source distributed cloud been proposed to make Snapshot Isolation serializable. Some database built on top of a transactional and consistent key- of the techniques [14], [16] perform static analysis of ap- value store. Its primary design goals are scalability and strong plication code and detect SI violation patterns. The potential consistency. CockroachDB aims to tolerate disk, machine, violations are translated into write-write conflicts, which are rack, and datacenter failures with minimal disruption and no then detected by snapshot isolation. However, these techniques manual intervention, thus being survivable (hence the name). are limited in scope and cannot be applied to systems dy- CockroachDB achieves strong consistency by synchronous namically generating transactions. Cahill et al. [12] develop replication of data. It replicates data over multiple nodes a SSI (Serializable Snapshot Isolation) methodology to detect and guarantees consistency between replicas using Raft [18] SI violations at run-time and implement the technique over consensus protocol. Cockroach provides transactional access existing snapshot isolation providing database, BerkleyDB. to data. It supports two isolation levels: Snapshot Isolation (SI) CockroachDB’s technique for providing serializable snapshot and Serializable Snapshot Isolation (SSI). While both provide isolation is inspired by a multi-version timestamp order- lock-free reads and writes, SI allows write-skew [9], and does ing [19] variant proposed by Yabandeh et al. [23]. not guarantee a serializable history. SSI eliminates write-skew Various mechanisms have been proposed to reduce aborts but introduces a performance hit in cases of high contention. in pessimistic as well as optimistic concurrency control (CC) A. Architecture algorithms. For locking algorithms, variants of 2PL such as CockroachDB implements a layered architecture as shown Order-shared [6] locking, Altruistic Locking [20]