github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/kv/kvserver/concurrency/isolation/levels.pb.go (about) 1 // Code generated by protoc-gen-gogo. DO NOT EDIT. 2 // source: kv/kvserver/concurrency/isolation/levels.proto 3 4 package isolation 5 6 import ( 7 fmt "fmt" 8 _ "github.com/gogo/protobuf/gogoproto" 9 proto "github.com/gogo/protobuf/proto" 10 math "math" 11 ) 12 13 // Reference imports to suppress errors if they are not otherwise used. 14 var _ = proto.Marshal 15 var _ = fmt.Errorf 16 var _ = math.Inf 17 18 // This is a compile-time assertion to ensure that this generated file 19 // is compatible with the proto package it is being compiled against. 20 // A compilation error at this line likely means your copy of the 21 // proto package needs to be updated. 22 const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package 23 24 // Level represents the different transaction isolation levels, which define how 25 // concurrent transactions are allowed to interact and the isolation guarantees 26 // that are made to individual transactions. Conceptually, isolation levels 27 // achieve this by controlling how and when the changes made by one transaction 28 // become visible to other transactions. 29 // 30 // Isolation levels in this enumeration are ordered from strongest to weakest. 31 // Strong isolation levels provide a high degree of isolation between concurrent 32 // transactions. They limit or eliminate the forms of concurrency effects that 33 // transactions may observe. Weak isolation levels are more permissive. They 34 // trade off isolation guarantees for improved performance. Transactions run 35 // under weaker isolation levels block less and encounter fewer retry errors. In 36 // some cases, they also perform less work. 37 // 38 // WARNING: Because isolation levels are defined from strongest to weakest in 39 // this enumeration (which is important for backwards compatability), their 40 // value comparison semantics do not represent a comparison of strength. The 41 // equality operators (==, !=) may be used to match a specific isolation level, 42 // but ordering operators (<, <=, >, >=) must not be used. Use the WeakerThan 43 // method instead. 44 // 45 // # Background 46 // 47 // Transaction isolation levels have historically been defined in multiple ways. 48 // 49 // ANSI SQL[^1] defined four isolation levels: READ UNCOMMITTED, READ COMMITTED, 50 // REPEATABLE READ, and SERIALIZABLE. The levels were defined in terms of three 51 // _phenomena_: Dirty Reads, Non-Repeatable Reads, and Phantom Reads. Stronger 52 // isolation levels allow fewer phenomena to occur. As a result, they permit 53 // less anomalous behavior ("permit fewer anomalies"). Weaker isolation levels 54 // allow more phenomena to occur. 55 // 56 // | Isolation Level | Dirty Read | Non-repeatable Read | Phantom Read | 57 // | ---------------- | ------------ | ------------------- | ------------ | 58 // | Read Uncommitted | Possible | Possible | Possible | 59 // | Read Committed | Not Possible | Possible | Possible | 60 // | Repeatable Read | Not Possible | Not Possible | Possible | 61 // | Serializable | Not Possible | Not Possible | Not Possible | 62 // 63 // "A Critique of ANSI SQL Isolation Levels"[^2] demonstrated that the ANSI SQL 64 // standard definitions of isolation levels were insufficient. Some phenomena 65 // were ambiguous, while others were missing entirely. The work provided a new 66 // characterization of isolation levels, defining the levels using a set of 67 // eight different phenomena. The expanded characterization also made room for a 68 // new isolation level: SNAPSHOT. 69 // 70 // While more complete, these definitions were still based on preventing 71 // conflicting operations that could lead to anomalies from executing 72 // concurrently. Adya’s dissertation "Weak Consistency: A Generalized Theory and 73 // Optimistic Implementations for Distributed Transactions"[^3] argued that this 74 // _preventative_ approach is overly restrictive. The definitions were 75 // “disguised versions of locking” and therefore disallow optimistic and 76 // multi-versioning schemes. Adya’s work generalizes existing isolation levels 77 // in terms of conflicts, serialization graphs, and the forms of phenomena 78 // allowed in the serialization graphs of different isolation levels. 79 // 80 // While these formalizations of isolation levels differ in their classification 81 // approach (e.g. permitted anomalies vs. permitted histories), all three leave 82 // room for a large degree of implementation freedom, leading to a diverse 83 // landscape of database systems with unique approaches towards transaction 84 // isolation that all "conform to the specification". 85 // 86 // # Implementation 87 // 88 // CockroachDB implements three isolation levels: READ COMMITTED, SNAPSHOT, and 89 // SERIALIZABLE, which loosely map on to each of the classifications presented 90 // above. The system also exposes REPEATABLE READ, which maps to SNAPSHOT, and 91 // READ UNCOMMITTED, which maps to READ COMMITTED. 92 // 93 // It contrasts the three isolation levels using a pair of properties: 94 // 95 // Write Skew Tolerance: Does the isolation level permit write skew? In an MVCC 96 // system, this property can be expressed as whether the isolation level allows 97 // transactions to write and commit at an MVCC timestamp above the MVCC 98 // timestamp of its read snapshot(s). 99 // 100 // Read Snapshot Scope: Does the isolation level allow transactions to operate 101 // across multiple read snapshots? If not, a single read snapshot is used for 102 // the entire transaction. If so, what is the scope of each read snapshot? 103 // 104 // With these two properties in hand, CockroachDB then constructs a unifying 105 // framework for its three supported isolation levels: 106 // 107 // | Isolation Level | Write Skew Tolerance | Read Snapshot Scope | 108 // |---------------------|----------------------|---------------------| 109 // | Serializable (SSI) | No | Per-Transaction | 110 // | Snapshot (SI) | Yes | Per-Transaction | 111 // | Read Committed (RC) | Yes | Per-Statement | 112 // 113 // Write Skew Tolerance characterizes the difference between Snapshot and 114 // Serializable isolation. Snapshot transactions permit write skew, so they 115 // can commit at a later timestamp than their read timestamp. Serializable 116 // transactions proscribe write skew, so they must commit at their read 117 // timestamp. These transactions accomplish this by refreshing their reads to 118 // their commit timestamp at commit time, effectively advancing their read 119 // timestamp forward while verifying equivalence with their original read 120 // timestamp. When a read refresh fails validation, the transaction must 121 // restart. For more details, see the comment on txnSpanRefresher. 122 // 123 // Read Snapshot Scope characterizes the difference between Snapshot isolation 124 // and Read Committed isolation. Snapshot transactions use a single consistent 125 // read snapshot across their entire lifetime, ensuring "repeatable reads" and 126 // avoiding "phantoms" across statements. When the transaction's read snapshot 127 // must change due to contention (e.g. on a write-write conflict to avoid lost 128 // updates, or on a read uncertainty error to enforce real-time ordering), the 129 // transaction must restart. Conversely, Read Committed transactions use a new 130 // read snapshot for each statement. The use of multiple read snapshots across 131 // the lifetime of a transaction permits anomalies like non-repeatable reads 132 // between statements. However, this scoping benefits from only requiring 133 // statement-level retries when a read snapshot must change. As a result, these 134 // retries can commonly be handled gateway-side without application involvement. 135 // 136 // For more about isolation levels in CockroachDB, see the Read Committed RFC: 137 // 138 // cockroachdb/cockroach/docs/RFCS/20230122_read_committed_isolation.md 139 // 140 // # References 141 // 142 // [^1]: 1992, https://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt 143 // 144 // [^2]: 1995, https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/tr-95-51.pdf 145 // 146 // [^3]: 1999, https://pmg.csail.mit.edu/papers/adya-phd.pdf 147 type Level int32 148 149 const ( 150 // Serializable provides the strictest transaction isolation. The isolation 151 // level emulates serial transaction execution for all committed transactions; 152 // as if transactions had been executed one after another, serially, rather 153 // than concurrently. 154 // 155 // Serializable isolation is commonly implemented using two-phase locking 156 // [2PL]. However, CockroachDB does not use two-phase locking. Instead, its 157 // implementation of Serializable isolation uses an optimistic concurrency 158 // control algorithm that is related to Serializable Snapshot Isolation [SSI] 159 // and is probably most accurately described as a variant of Write-Snapshot 160 // Isolation [WSI]. These two algorithms live in a family of concurrency 161 // control schemes that extend the multi-versioning present in Snapshot 162 // Isolation with additional runtime conflict detection to provide 163 // Serializable Isolation. 164 // 165 // [2PL]: https://en.wikipedia.org/wiki/Two-phase_locking 166 // [SSI]: https://dl.acm.org/doi/10.1145/1620585.1620587 167 // [WSI]: https://dl.acm.org/doi/10.1145/2168836.2168853 168 Serializable Level = 0 169 // Snapshot provides moderately strict transaction isolation. A transaction 170 // using the isolation level sees only data committed before the transaction 171 // began; it never sees either uncommitted data or changes committed during 172 // transaction execution by concurrent transactions. A transaction using this 173 // isolation level is also prevented from writing to data that has changed 174 // since the transaction began ("first committer wins"), preventing lost 175 // updates. 176 // 177 // Snapshot isolation is commonly built upon Multi-Version Concurrency Control 178 // (MVCC), which allows to isolation level to provide efficient concurrent 179 // access to reads and writes in different transactions that operate on the 180 // same data. 181 Snapshot Level = 1 182 // ReadCommitted provides relatively weak transaction isolation. Each 183 // statement in a transaction using this isolation level sees only data 184 // committed before that statement began. However, two successive statements 185 // can see different data. 186 // 187 // For more about ReadCommitted, see the Read Committed RFC: 188 // cockroachdb/cockroach/docs/RFCS/20230122_read_committed_isolation.md 189 ReadCommitted Level = 2 190 ) 191 192 var Level_name = map[int32]string{ 193 0: "Serializable", 194 1: "Snapshot", 195 2: "ReadCommitted", 196 } 197 198 var Level_value = map[string]int32{ 199 "Serializable": 0, 200 "Snapshot": 1, 201 "ReadCommitted": 2, 202 } 203 204 func (x Level) String() string { 205 return proto.EnumName(Level_name, int32(x)) 206 } 207 208 func (Level) EnumDescriptor() ([]byte, []int) { 209 return fileDescriptor_d42c90129c01d117, []int{0} 210 } 211 212 func init() { 213 proto.RegisterEnum("cockroach.parser.kv.kvserver.concurrency.isolation.Level", Level_name, Level_value) 214 } 215 216 func init() { 217 proto.RegisterFile("kv/kvserver/concurrency/isolation/levels.proto", fileDescriptor_d42c90129c01d117) 218 } 219 220 var fileDescriptor_d42c90129c01d117 = []byte{ 221 // 239 bytes of a gzipped FileDescriptorProto 222 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0xcf, 0x31, 0x4e, 0xc3, 0x30, 223 0x18, 0x05, 0x60, 0x1b, 0x01, 0x42, 0x56, 0x91, 0x42, 0xc4, 0xd4, 0xe1, 0x3f, 0x00, 0x48, 0xf6, 224 0xc0, 0x05, 0x10, 0x48, 0x4c, 0x4c, 0x74, 0x63, 0x73, 0x9c, 0x5f, 0x89, 0x65, 0x27, 0x7f, 0xe4, 225 0xb8, 0x96, 0xe0, 0x04, 0x8c, 0xdc, 0x81, 0xcb, 0x74, 0xec, 0xd8, 0x11, 0x9c, 0x8b, 0xa0, 0x16, 226 0x51, 0xd8, 0xba, 0xbd, 0xe5, 0x7b, 0x7a, 0x4f, 0x48, 0x97, 0x94, 0x4b, 0x23, 0x86, 0x84, 0x41, 227 0x19, 0xea, 0xcd, 0x32, 0x04, 0xec, 0xcd, 0x8b, 0xb2, 0x23, 0x79, 0x1d, 0x2d, 0xf5, 0xca, 0x63, 228 0x42, 0x3f, 0xca, 0x21, 0x50, 0xa4, 0xf2, 0xda, 0x90, 0x71, 0x81, 0xb4, 0x69, 0xa5, 0x4b, 0xf2, 229 0x57, 0xca, 0x7f, 0x52, 0xee, 0xe5, 0xfc, 0xb2, 0xa1, 0x86, 0x76, 0x4e, 0x6d, 0xd3, 0x4f, 0xc5, 230 0xd5, 0xad, 0x38, 0x79, 0xdc, 0x56, 0x96, 0x85, 0x98, 0x2d, 0x30, 0x58, 0xed, 0xed, 0xab, 0xae, 231 0x3c, 0x16, 0xac, 0x9c, 0x89, 0xb3, 0x45, 0xaf, 0x87, 0xb1, 0xa5, 0x58, 0xf0, 0xf2, 0x42, 0x9c, 232 0x3f, 0xa1, 0xae, 0xef, 0xa9, 0xeb, 0x6c, 0x8c, 0x58, 0x17, 0x47, 0xf3, 0xe3, 0xb7, 0x0f, 0x60, 233 0x77, 0xed, 0xea, 0x0b, 0xd8, 0x2a, 0x03, 0x5f, 0x67, 0xe0, 0x9b, 0x0c, 0xfc, 0x33, 0x03, 0x7f, 234 0x9f, 0x80, 0xad, 0x27, 0x60, 0x9b, 0x09, 0xd8, 0xf3, 0x43, 0x63, 0x63, 0xbb, 0xac, 0xa4, 0xa1, 235 0x4e, 0xed, 0x17, 0xd7, 0xd5, 0x5f, 0x56, 0x83, 0x6b, 0xd4, 0xc1, 0xef, 0xd5, 0xe9, 0x6e, 0xf2, 236 0xcd, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0xc5, 0x58, 0xb3, 0x8f, 0x27, 0x01, 0x00, 0x00, 237 } 238