github.com/matrixorigin/matrixone@v1.2.0/proto/lock.proto (about) 1 /* 2 * Copyright 2021 Matrix Origin 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 syntax = "proto3"; 18 package lock; 19 option go_package = "github.com/matrixorigin/matrixone/pkg/pb/lock"; 20 21 import "github.com/gogo/protobuf/gogoproto/gogo.proto"; 22 import "timestamp.proto"; 23 24 option (gogoproto.goproto_enum_prefix_all) = true; 25 26 // Granularity row granularity, single row or row range 27 enum Granularity { 28 Row = 0; 29 Range = 1; 30 } 31 32 // LockMode lock mode 33 enum LockMode { 34 Exclusive = 0; 35 Shared = 1; 36 } 37 38 // WaitPolicy wait policy 39 enum WaitPolicy { 40 Wait = 0; 41 FastFail = 1; 42 } 43 44 enum Sharding { 45 None = 0; 46 ByRow = 1; 47 } 48 49 // LockOptions lock options 50 message LockOptions { 51 Granularity Granularity = 1; 52 LockMode Mode = 2; 53 WaitPolicy Policy = 3; 54 string ForwardTo = 4; 55 bool TableDefChanged = 5; 56 int64 RetryWait = 6; 57 uint32 Group = 7; 58 Sharding Sharding = 8; 59 timestamp.Timestamp SnapShotTs = 9 [(gogoproto.nullable) = false]; 60 } 61 62 // LockTable describes which CN manages a Table's Locks. 63 message LockTable { 64 // Table table id 65 uint64 Table = 1; 66 // ServiceID lock service id, a cn node will only run one instance of LockService 67 string ServiceID = 2; 68 // Version will incr if CN-Table bind changed. 69 uint64 Version = 3; 70 // Valid false if the service is disabled, and no new service bind this table 71 bool Valid = 4; 72 uint32 Group = 5; 73 Sharding Sharding = 6; 74 uint64 OriginTable = 7; 75 } 76 77 // Method lock table operations 78 enum Method { 79 // Lock lock rows on remote lock table 80 Lock = 0; 81 // Write unlock rows from remote lock table 82 Unlock = 1; 83 // GetTxnLock get lock data on a special lock 84 GetTxnLock = 2; 85 // GetWaitingList get waiting txns on a special lock 86 GetWaitingList = 3; 87 // KeepRemoteLock keep remote lock on remote lock service 88 KeepRemoteLock = 4; 89 // GetBind get or create lock table bind from lock table allocator 90 GetBind = 5; 91 // KeepLockTableBind keep the lock table bind on lock table allocator 92 KeepLockTableBind = 6; 93 // ForwardLock forward lock request to another service 94 ForwardLock = 7; 95 // ForwardUnlock forward unlock request to another service 96 ForwardUnlock = 8; 97 // ValidateService validate if lock service alive 98 ValidateService = 9; 99 // CannotCommit for orphaned transactions that are found, the lock is released 100 // immediately, and you need to mark these transactions as not being able to be 101 // committed in the TN 102 CannotCommit = 10; 103 // GetActiveTxn used to get the active txn on the lock service 104 GetActiveTxn = 11; 105 // SetRestartService set restart lock service 106 SetRestartService = 12; 107 // RemainTxnInService get remain txn in lock service 108 RemainTxnInService = 13; 109 // canRestartService judge if can restart lock service 110 CanRestartService = 14; 111 } 112 113 enum Status { 114 ServiceLockEnable = 0; 115 ServiceLockWaiting = 1; 116 ServiceUnLockSucc = 2; 117 ServiceCanRestart = 3; 118 } 119 120 // Request is used to send a request for a LockTable related operation to another 121 // service. 122 message Request { 123 // RequestID request id 124 uint64 RequestID = 1; 125 // LockTable lock target table 126 LockTable LockTable = 2 [(gogoproto.nullable) = false]; 127 Method Method = 3; 128 LockRequest Lock = 4 [(gogoproto.nullable) = false]; 129 UnlockRequest Unlock = 5 [(gogoproto.nullable) = false]; 130 GetTxnLockRequest GetTxnLock = 6 [(gogoproto.nullable) = false]; 131 GetWaitingListRequest GetWaitingList = 7 [(gogoproto.nullable) = false]; 132 GetBindRequest GetBind = 8 [(gogoproto.nullable) = false]; 133 KeepLockTableBindRequest KeepLockTableBind = 9 [(gogoproto.nullable) = false]; 134 KeepRemoteLockRequest KeepRemoteLock = 10 [(gogoproto.nullable) = false]; 135 ValidateServiceRequest ValidateService = 11 [(gogoproto.nullable) = false]; 136 CannotCommitRequest CannotCommit = 12 [(gogoproto.nullable) = false]; 137 GetActiveTxnRequest GetActiveTxn = 13 [(gogoproto.nullable) = false]; 138 SetRestartServiceRequest SetRestartService = 14 [(gogoproto.nullable) = false]; 139 CanRestartServiceRequest CanRestartService = 15 [(gogoproto.nullable) = false]; 140 RemainTxnInServiceRequest RemainTxnInService = 16 [(gogoproto.nullable) = false]; 141 } 142 143 // Response response 144 message Response { 145 // RequestID corresponding request id 146 uint64 RequestID = 1; 147 Method Method = 2; 148 // Error we use this field to send moerr from service to another cn. Set with 149 // moerr.MarshalBinary, and use moerr.UnmarshalBinary to restore moerr. 150 bytes Error = 3; 151 LockTable NewBind = 4; 152 LockResponse Lock = 5 [(gogoproto.nullable) = false]; 153 UnlockResponse Unlock = 6 [(gogoproto.nullable) = false]; 154 GetTxnLockResponse GetTxnLock = 7 [(gogoproto.nullable) = false]; 155 GetWaitingListResponse GetWaitingList = 8 [(gogoproto.nullable) = false]; 156 GetBindResponse GetBind = 9 [(gogoproto.nullable) = false]; 157 KeepLockTableBindResponse KeepLockTableBind = 10 [(gogoproto.nullable) = false]; 158 KeepRemoteLockResponse KeepRemoteLock = 11 [(gogoproto.nullable) = false]; 159 ValidateServiceResponse ValidateService = 12 [(gogoproto.nullable) = false]; 160 CannotCommitResponse CannotCommit = 13 [(gogoproto.nullable) = false]; 161 GetActiveTxnResponse GetActiveTxn = 14 [(gogoproto.nullable) = false]; 162 SetRestartServiceResponse SetRestartService = 15 [(gogoproto.nullable) = false]; 163 CanRestartServiceResponse CanRestartService = 16 [(gogoproto.nullable) = false]; 164 RemainTxnInServiceResponse RemainTxnInService = 17 [(gogoproto.nullable) = false]; 165 } 166 167 // LockRequest lock request 168 message LockRequest { 169 bytes TxnID = 1; 170 string ServiceID = 2; 171 repeated bytes Rows = 3; 172 // LockOptions lock options 173 LockOptions Options = 4 [(gogoproto.nullable) = false]; 174 } 175 176 // LockResponse lock response 177 message LockResponse { 178 Result Result = 1 [(gogoproto.nullable) = false]; 179 } 180 181 // GetTxnLockRequest get a waiting txn list on a special lock 182 // request, used to dead lock detect 183 message GetTxnLockRequest { 184 bytes TxnID = 1; 185 bytes Row = 2; 186 } 187 188 // GetTxnLockResponse get txn Lock response 189 message GetTxnLockResponse { 190 int32 Value = 1; 191 repeated WaitTxn WaitingList = 2 [(gogoproto.nullable) = false]; 192 } 193 194 // GetWaitingListRequest get a waiting txn list on a specical txn request. CN -> CN 195 message GetWaitingListRequest { 196 WaitTxn Txn = 1 [(gogoproto.nullable) = false]; 197 } 198 199 // GetWaitingListResponse get a waiting txn list on a specical txn response. CN -> CN 200 message GetWaitingListResponse { 201 repeated WaitTxn WaitingList = 1 [(gogoproto.nullable) = false]; 202 } 203 204 // WaitTxn wait txn include txn created on 205 message WaitTxn { 206 bytes TxnID = 1; 207 string CreatedOn = 2; 208 } 209 210 // UnlockRequest unlock lock on remote lock service request. CN -> CN 211 message UnlockRequest { 212 bytes TxnID = 1; 213 // CommitTS is the commit timestamp of the current txn. Empty if txn is 214 // roll backed 215 timestamp.Timestamp CommitTS = 2 [(gogoproto.nullable) = false]; 216 repeated ExtraMutation Mutations = 3 [(gogoproto.nullable) = false]; 217 } 218 219 // UnlockResponse unlock lock on remote lock service response. CN -> CN 220 message UnlockResponse { 221 222 } 223 224 // GetBindRequest get bind request from allocator request. CN -> TN 225 message GetBindRequest { 226 string ServiceID = 1; 227 uint64 Table = 2; 228 uint32 Group = 3; 229 Sharding Sharding = 4; 230 uint64 OriginTable = 5; 231 } 232 233 // GetBindResponse get bind request from allocator response. TN -> CN 234 message GetBindResponse { 235 LockTable LockTable = 2 [(gogoproto.nullable) = false]; 236 } 237 238 // KeepLockTableBindRequest keep lock table bind request. CN -> TN 239 message KeepLockTableBindRequest { 240 string ServiceID = 1; 241 Status Status = 2; 242 repeated bytes TxnIDs = 3; 243 repeated LockTable LockTables = 4 [(gogoproto.nullable) = false]; 244 } 245 246 // KeepLockTableBindResponse keep lock table bind response. TN -> CN 247 message KeepLockTableBindResponse { 248 bool OK = 1; 249 Status Status = 2; 250 } 251 252 // SetRestartServiceRequest set restart lock service request from allocator request. operator -> TN 253 message SetRestartServiceRequest { 254 string ServiceID = 1; 255 } 256 257 // SetRestartServiceResponse set restart lock service request from allocator response. TN -> operator 258 message SetRestartServiceResponse { 259 bool OK = 1; 260 } 261 262 // CanRestartServiceRequest can restart lock service request from allocator request. operator -> TN 263 message CanRestartServiceRequest { 264 string ServiceID = 1; 265 } 266 267 // CanRestartServiceResponse can restart lock service request from allocator response. TN -> operator 268 message CanRestartServiceResponse { 269 bool OK = 1; 270 } 271 272 // RemainTxnInServiceRequest get remain txn in service request from allocator request. operator -> TN 273 message RemainTxnInServiceRequest { 274 string ServiceID = 1; 275 } 276 277 // RemainTxnInServiceResponse get remain txn in service request from allocator response. TN -> operator 278 message RemainTxnInServiceResponse { 279 int32 RemainTxn = 1; 280 } 281 282 // KeepRemoteLockRequest keep lock on remote lockservice request. CN -> CN 283 message KeepRemoteLockRequest { 284 string ServiceID = 1; 285 } 286 287 // KeepRemoteLockResponse keep lock on remote lockservice response. TN -> CN 288 message KeepRemoteLockResponse { 289 bool OK = 1; 290 } 291 292 // ValidateServiceRequest validate if lock service alive request. TN -> CN 293 message ValidateServiceRequest { 294 string ServiceID = 1; 295 } 296 297 // KeepLockTableBindResponse keep lock table bind response. CN -> DN 298 message ValidateServiceResponse { 299 bool OK = 1; 300 } 301 302 303 // CannotCommitRequest cannot commit request. CN -> TN 304 message CannotCommitRequest { 305 repeated OrphanTxn OrphanTxnList = 1 [(gogoproto.nullable) = false]; 306 } 307 308 // CannotCommitResponse cannot commit response. TN -> CN 309 message CannotCommitResponse { 310 repeated bytes CommittingTxn = 1; 311 } 312 313 message GetActiveTxnRequest { 314 string ServiceID = 1; 315 } 316 317 message GetActiveTxnResponse { 318 bool Valid = 1; 319 repeated bytes Txn = 2; 320 } 321 322 message OrphanTxn { 323 string Service = 1; 324 repeated bytes Txn = 2; 325 } 326 327 // Result result is used to tell the caller the result of the lock operation. 328 message Result { 329 // LockedOn lock is locked on which locktable 330 LockTable LockedOn = 1 [(gogoproto.nullable) = false]; 331 // HasConflict if true means encounter lock conflict 332 bool HasConflict = 2; 333 // HasPrevCommit if HasPrevCommit && HasConflict, Timestamp is the latest commit 334 // timestamp. 335 bool HasPrevCommit = 3; 336 // Timestamp is used to help determine which version of RC should be queried 337 // under the RC isolation level, this timestamp ensures that the latest data 338 // is always read. 339 timestamp.Timestamp Timestamp = 4 [(gogoproto.nullable) = false]; 340 // TableDefChanged conflict with ddl lock, need rebuild plan to get new table def 341 bool TableDefChanged = 5; 342 bytes ConflictKey = 6; 343 bytes ConflictTxn = 7; 344 bytes PrevWaiter = 8; 345 uint32 Waiters = 9; 346 } 347 348 message ExtraMutation { 349 bytes key = 1; 350 bool skip = 2; 351 bytes replaceTo = 3; 352 }