github.com/matrixorigin/matrixone@v1.2.0/pkg/txn/service/types.go (about) 1 // Copyright 2021 - 2022 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package service 16 17 import ( 18 "context" 19 20 "github.com/matrixorigin/matrixone/pkg/pb/metadata" 21 "github.com/matrixorigin/matrixone/pkg/pb/txn" 22 ) 23 24 // TxnService is a transaction service that runs on the DNStore and is used to receive transaction requests 25 // from the CN. In the case of a 2 pc distributed transaction, it acts as a transaction coordinator to handle 26 // distributed transactions. 27 // 28 // The TxnService is managed by the DNStore and a TxnService serves only one DNShard. 29 // 30 // The txn service use Clock-SI to implement distributed transaction. 31 type TxnService interface { 32 // Shard returns the metadata of DNShard 33 Shard() metadata.TNShard 34 // Start start the txn service 35 Start() error 36 // Close close the txn service. Destroy TxnStorage if destroy is true. 37 Close(destroy bool) error 38 39 // Read handle txn read request from CN. For reuse, the response is provided by the 40 // TODO: only read log tail. 41 Read(ctx context.Context, request *txn.TxnRequest, response *txn.TxnResponse) error 42 // Write handle txn write request from CN. For reuse, the response is provided by the caller 43 Write(ctx context.Context, request *txn.TxnRequest, response *txn.TxnResponse) error 44 // Commit handle txn commit request from CN. For reuse, the response is provided by the caller 45 Commit(ctx context.Context, request *txn.TxnRequest, response *txn.TxnResponse) error 46 // Rollback handle txn rollback request from CN. For reuse, the response is provided by the caller 47 Rollback(ctx context.Context, request *txn.TxnRequest, response *txn.TxnResponse) error 48 49 // Prepare handle txn prepare request from coordinator DN. For reuse, the response is provided by 50 // the caller 51 Prepare(ctx context.Context, request *txn.TxnRequest, response *txn.TxnResponse) error 52 // GetStatus handle get txn status in current DNShard request from coordinator DN. For reuse, the 53 // response is provided by the caller. 54 GetStatus(ctx context.Context, request *txn.TxnRequest, response *txn.TxnResponse) error 55 // CommitTNShard handle commit txn data in current DNShard request from coordinator DN. For reuse, the 56 // response is provided by the caller. 57 CommitTNShard(ctx context.Context, request *txn.TxnRequest, response *txn.TxnResponse) error 58 // RollbackTNShard handle rollback txn data in current DNShard request from coordinator DN. For reuse, 59 // the response is provided by the caller. 60 RollbackTNShard(ctx context.Context, request *txn.TxnRequest, response *txn.TxnResponse) error 61 62 // Debug handle txn debug request from CN. For reuse, the response is provided by the caller 63 Debug(ctx context.Context, request *txn.TxnRequest, response *txn.TxnResponse) error 64 }