github.com/matrixorigin/matrixone@v0.7.0/proto/txn.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 txn; 
    19  option go_package = "github.com/matrixorigin/matrixone/pkg/pb/txn";
    20  
    21  import "github.com/gogo/protobuf/gogoproto/gogo.proto";
    22  import "timestamp.proto";
    23  import "metadata.proto";
    24  
    25  option (gogoproto.goproto_enum_prefix_all) = true;
    26  
    27  // TxnStatus transaction status
    28  enum TxnStatus {
    29      // Active is the state of transaction creation, in this state, can execute the 
    30      // transaction Read/Write/Commit/Rollback.
    31      Active = 0;
    32      // Prepared for distributed transactions across DNs, a 2pc commit is performed, 
    33      // and the prepared status means that the transaction on a DN was executed 
    34      // successfully in the first phase. 
    35      // 
    36      // Note that this status needs to be saved to the LogService. Once the first 
    37      // phase of a transaction is successful, data cannot be lost.
    38      Prepared = 1;
    39      // Committing for distributed transactions across DNs, once all DNs have completed
    40      // the first phase, the transaction enters the Committing state and initiates an 
    41      // asynchronous process to handle the commit of temporary data.
    42      //
    43      // Note that when all DNs involved are in the prepared state, the distributed 
    44      // transaction can be considered committed because all data has been written 
    45      // successfully. The subsequent Committing process just explicitly converts these
    46      // writes into committed data.
    47      //
    48      // Note that the state exists only in memory and is not persisted to the LogService.
    49      // It can be restored through the Prepared state, if all(DN).Status == Prepared.
    50      Committing = 2;
    51      // Committed after the Committing phase has transformed all DN data involved into 
    52      // committed data, the status of the distributed transaction is explicitly recorded 
    53      // as Committed.
    54      //
    55      // Note that this status needs to be saved to the LogService
    56      Committed = 3;
    57      // Aborting a client initiating a Rollback call or a distributed transaction that has
    58      // any error in the first phase will enter the Aborting state. This state starts an 
    59      // asynchronous task to clean up the temporary data written by the transaction.
    60      //
    61      // Note that the state exists only in memory and is not persisted to the LogService.
    62      // It can be restored through the Prepared state, if Any(DN).Status != Prepared.
    63      Aborting  = 4;
    64      // Aborted after the Aborting phase, all data involved in the DN is cleaned up and 
    65      // the transaction status is explicitly recorded as Aborted.
    66      //
    67      // Note that this status needs to be saved to the LogService
    68      Aborted   = 5;
    69  }
    70  
    71  // TxnMeta transaction metadata
    72  message TxnMeta {
    73      // ID transaction id, generated at the CN node at the time of transaction creation, 
    74      // globally unique.
    75      bytes               ID          = 1;
    76      // Status transaction status
    77      TxnStatus           Status      = 2;
    78      // SnapshotTS transaction read timestamp, generated at the CN node at the time of 
    79      // transaction creation. All data.TS < txn.SnapshotTS is visible for the current 
    80      // transaction.
    81      timestamp.Timestamp SnapshotTS  = 3 [(gogoproto.nullable) = false];
    82      // PreparedTS timestamp to complete the first phase of a 2pc commit transaction.
    83      timestamp.Timestamp PreparedTS  = 4 [(gogoproto.nullable) = false];
    84      // CommitTS transaction commit timestamp. For a 2pc transaction, commitTS = max(preparedTS).
    85      timestamp.Timestamp CommitTS    = 5 [(gogoproto.nullable) = false];
    86      // DNShards all DNShards that have written data. The first DN is the coordinator of the 
    87      // transaction
    88      repeated metadata.DNShard DNShards = 6 [(gogoproto.nullable) = false];
    89  }
    90  
    91  // CNTxnSnapshot snapshot of the cn txn operation.
    92  message CNTxnSnapshot {
    93      // ID txn id
    94      TxnMeta                   Txn      = 1 [(gogoproto.nullable) = false];
    95      // ReadyOnly txn options
    96      bool ReadyOnly        = 2;
    97      // EnableCacheWrite txn options
    98      bool EnableCacheWrite = 3;
    99      // Disable1PCOpt txn options
   100      bool Disable1PCOpt    = 4;
   101  }
   102  
   103  // CNOpRequest cn read/write request, CN -> DN. If data is written to more than one DN (>1) in a 
   104  // single transaction, then the transaction becomes a 2pc transaction.
   105  message CNOpRequest {
   106      // OpCode request operation type
   107      uint32           OpCode  = 1;
   108      // Payload the content of the request, TxnClient does not perceive the exact
   109      // format and content
   110      bytes            Payload = 2;
   111      // Target target to which the request was sent
   112  	metadata.DNShard Target  = 3 [(gogoproto.nullable) = false]; 
   113  }
   114  
   115  // CNOpResponse cn read/write response, DN -> CN. A request corresponds to a response.
   116  message CNOpResponse {
   117      // Payload response payload
   118  	bytes Payload = 1;
   119  }
   120  
   121  // TxnMethod transaction operations
   122  enum TxnMethod {
   123      // Read transaction read
   124      Read              = 0;
   125      // Write transaction write
   126      Write             = 1;
   127      // Commit commit transaction
   128      Commit            = 2;
   129      // Rollback rollback transaction
   130      Rollback          = 3;
   131      // Prepare when DN(Coordinator) receives a commit request from CN, it sends a prepare to 
   132      // each DN(DNShard)
   133      Prepare           = 4;
   134      // GetStatus query the status of a transaction on a DN. When a DN encounters a transaction
   135      // in the Prepared state, it needs to go to the DN(Coordinator) to query the status of the 
   136      // current transaction. When a DN encounters a transaction in the Prepared state during the 
   137      // recover, it needs to query the status of the transaction on each DN(DNShard) to determine
   138      // if the transaction is committed.
   139      GetStatus         = 5;
   140      // CommitDNShard after the 2pc transaction is committed, the temporary data on each DN needs
   141      // to be explicitly converted to committed data.
   142      CommitDNShard     = 6;
   143      // RollbackDNShard after the 2pc transaction is aborted, the temporary data on each DN needs
   144      // to cleanup.
   145      RollbackDNShard   = 7;
   146      // RemoveMedata Remove metadata for transactions on DNShard. For a 2pc distributed transaction, 
   147      // after all participating DNShards have Prepared successfully, the asynchronous commit process 
   148      // starts, sending CommitDNShard requests to all participating DNShards in parallel. After each 
   149      // DNShard has processed the CommitDNShard, the metadata of the transaction cannot be deleted 
   150      // immediately, otherwise when the transaction coordinator node is down and restarted, the commit 
   151      // status of the transaction cannot be determined in the recovery process, as it is possible that
   152      // some participating DNShards cannot find the transaction information.
   153      //
   154      // TODO: needs to work with TAE's log compaction, not currently supported.
   155      RemoveMedata      = 8;
   156      // DEBUG used to send debug request from cn to dn, and received response from dn to cn
   157      DEBUG             = 9;
   158  }
   159  
   160  // TxnRequest transaction request. All requests for the transaction are made using TxnRequest, so that 
   161  // the codec and logical processing of the RPC can be unified. Specific requests are selected according 
   162  // to TxnMethod.
   163  //
   164  // Request flow of TxnRequest as below:
   165  // 1. CN -> DN (TxnMethod.Read, TxnMethod.Write, TxnMethod.Commit, TxnMethod.Rollback)
   166  // 2. DN -> DN (TxnMethod.Prepare, TxnMethod.GetStatus, TxnMethod.CommitDNShard, TxnMethod.RollbackDNShard,
   167  //             TxnMethod.RemoveMetadata)
   168  message TxnRequest {
   169      // RequestID request id
   170      uint64                      RequestID                = 1;
   171      // Txn transaction metadata
   172      TxnMeta                     Txn                      = 2 [(gogoproto.nullable) = false];
   173      // TxnMethod TxnRequest opCode, select the Request defined below according to TxnMethod.
   174      TxnMethod                   Method                   = 3;
   175      // Flag request flag
   176      uint32                      Flag                     = 4;
   177      // CNOpRequest corresponds to TxnMethod.Read, TxnMethod.Write
   178      CNOpRequest                 CNRequest                = 5; 
   179      // TxnCommitRequest corresponds to TxnMethod.Commit
   180      TxnCommitRequest            CommitRequest            = 6;
   181      // TxnRollbackRequest corresponds to TxnMethod.Rollback
   182      TxnRollbackRequest          RollbackRequest          = 7;
   183      // TxnPrepareRequest corresponds to TxnMethod.Prepare
   184      TxnPrepareRequest           PrepareRequest           = 8;
   185      // TxnGetStatusRequest corresponds to TxnMethod.GetStatus
   186      TxnGetStatusRequest         GetStatusRequest         = 9;
   187      // TxnCommitDNShardRequest corresponds to TxnMethod.CommitDNShard
   188      TxnCommitDNShardRequest     CommitDNShardRequest     = 10;
   189      // TxnRollbackDNShardRequest corresponds to TxnMethod.RollbackDNShard
   190      TxnRollbackDNShardRequest   RollbackDNShardRequest   = 11;
   191      // TxnRemoveMetadataRequest  corresponds to TxnMethod.RemoveMetadata
   192      TxnRemoveMetadataRequest    RemoveMetadata           = 12;
   193      // TxnRequestOptions request options
   194      TxnRequestOptions           Options                  = 13;
   195  }
   196  
   197  // TxnRequestOptions txn options
   198  message TxnRequestOptions {
   199      // RetryCodes when DN processes TxnRequest and encounters the specified error, it needs to retry
   200      // on the server side. Only read and write can retry.
   201      repeated int32 RetryCodes    = 1;
   202      // RetryInterval retry interval, default is 100ms.
   203      int64              RetryInterval = 2;    
   204  }
   205  
   206  // TxnResponse response of TxnRequest.
   207  message TxnResponse {
   208      // RequestID corresponding request id
   209      uint64                       RequestID                 = 1;
   210      // Txn transaction metadata. TxnResponse.TxnMeta and TxnRequest.TxnMeta may differ 
   211      // in that the node initiating the TxnRequest needs to process the returned TxnMeta, 
   212      // e.g. to determine whether the transaction is Aborted by the status of the returned 
   213      // TxnMeta.
   214      TxnMeta                      Txn                       = 2;
   215      // TxnMethod same as TxnRequest.TxnMethod
   216      TxnMethod                    Method                    = 3;
   217      // Flag request flag, same as the corresponding request
   218      uint32                       Flag                      = 4;
   219      // TxnError explicit error
   220      TxnError                     TxnError                  = 5;
   221      // CNOpResponse corresponds to TxnMethod.Read, TxnMethod.Write response
   222      CNOpResponse                 CNOpResponse              = 6; 
   223      // TxnCommitResponse corresponds to TxnMethod.Commit response
   224      TxnCommitResponse            CommitResponse            = 7;
   225      // TxnRollbackResponse corresponds to TxnMethod.Rollback response
   226      TxnRollbackResponse          RollbackResponse          = 8;
   227      // TxnPrepareResponse corresponds to TxnMethod.Prepare response
   228      TxnPrepareResponse           PrepareResponse           = 9;
   229      // TxnGetStatusResponse corresponds to TxnMethod.GetStatus response
   230      TxnGetStatusResponse         GetStatusResponse         = 10;
   231      // TxnCommitDNShardResponse corresponds to TxnMethod.CommitDNShard response
   232      TxnCommitDNShardResponse     CommitDNShardResponse     = 11;
   233      // TxnRollbackDNShardResponse corresponds to TxnMethod.RollbackDNShard response
   234      TxnRollbackDNShardResponse   RollbackDNShardResponse   = 12;
   235       // TxnRemoveMetadataResponse  corresponds to TxnMethod.RemoveMetadata
   236       TxnRemoveMetadataResponse   RemoveMetadata            = 13;
   237  }
   238  
   239  // TxnCommitRequest CN sent the commit request to coordinator DN.
   240  message TxnCommitRequest {
   241      bool                      Disable1PCOpt = 2;
   242  }
   243  
   244  // TxnCommitResponse response of TxnCommitRequest. 
   245  message TxnCommitResponse {
   246  }
   247  
   248  // TxnCommitRequest CN sent the rollback request to coordinator DN.
   249  message TxnRollbackRequest {
   250  }
   251  
   252  // TxnRollbackResponse response of TxnRollbackRequest.
   253  message TxnRollbackResponse {
   254  }
   255  
   256  // TxnPrepareRequest when a DN(coordinator) receives a Commit request from a CN, if 
   257  // more than one DN is involved, the 2PC commit process is enabled and the first phase
   258  // is to send prepare requests to all DNs.
   259  message TxnPrepareRequest {
   260      // DNShard prepare DN
   261      metadata.DNShard          DNShard  = 1 [(gogoproto.nullable) = false];
   262  }
   263  
   264  // TxnPrepareResponse response of TxnPrepareRequest
   265  message TxnPrepareResponse {
   266  
   267  }
   268  
   269  // TxnGetStatusRequest query the status of a transaction on DN
   270  message TxnGetStatusRequest {
   271      // DNShard target DN
   272      metadata.DNShard DNShard = 1 [(gogoproto.nullable) = false];
   273  }
   274  
   275  // TxnGetStatusResponse response of TxnGetStatusRequest
   276  message TxnGetStatusResponse {
   277  }
   278  
   279  // TxnCommitDNShardRequest commit txn on DNShard. Data needs to be written to the 
   280  // LogService.
   281  message TxnCommitDNShardRequest {
   282       // DNShard target DN
   283       metadata.DNShard DNShard = 1 [(gogoproto.nullable) = false];
   284  }
   285  
   286  // TxnCommitDNShardResponse response of TxnCommitDNShardRequest
   287  message TxnCommitDNShardResponse {
   288  }
   289  
   290  // TxnRollbackDNShardRequest rollback txn on DNShard
   291  message TxnRollbackDNShardRequest {
   292       // DNShard target DN
   293       metadata.DNShard DNShard = 1 [(gogoproto.nullable) = false];
   294  }
   295  
   296  // TxnRollbackDNShardResponse response of TxnRollbackDNShardRequest
   297  message TxnRollbackDNShardResponse {
   298  }
   299  
   300  
   301  // TxnRemoveMetadataRequest remove txn metadata on DNShard
   302  message TxnRemoveMetadataRequest {
   303      // DNShard target DN
   304      metadata.DNShard DNShard = 1 [(gogoproto.nullable) = false];
   305  }
   306  
   307  // TxnRemoveMetadataResponse response of TxnRemoveMetadataRequest
   308  message TxnRemoveMetadataResponse {
   309  }
   310  
   311  // TxnError all explicit errors in transaction operations. 
   312  message TxnError {
   313      // Code moerr code, used to special error handle without unmarshal moerr
   314      uint32 Code       = 1;
   315      // Error we use this field to send moerr from dn to cn. Set with 
   316      // moerr.MarshalBinary, and use moerr.UnmarshalBinary to restore 
   317      // moerr.
   318      bytes  Error      = 2;
   319      // TxnErrCode is a internal err code in the txn framework and used to indicate
   320      // what transaction operation failed. Usually this value is the same as the value 
   321      // of Code, except for the error returned by the interface call to TxnStorage.
   322      // Because the types of errors returned by TxnStorage's interface are unknown to the 
   323      // transaction framework, it is necessary to use a code for the interface call to uniformly
   324      // replace these error codes.
   325      uint32 TxnErrCode = 3;
   326  }