github.com/matrixorigin/matrixone@v1.2.0/pkg/pb/txn/txn_option.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 txn 16 17 var ( 18 txnFeatureUserTxn = uint32(1 << 0) 19 txnFeatureReadOnly = uint32(1 << 1) 20 txnFeatureCacheWrite = uint32(1 << 2) 21 txnFeatureDisable1PC = uint32(1 << 3) 22 txnFeatureCheckDup = uint32(1 << 4) 23 txnFeatureDisableTrace = uint32(1 << 5) 24 ) 25 26 func (m TxnOptions) WithDisableTrace() TxnOptions { 27 m.Features |= txnFeatureDisableTrace 28 return m 29 } 30 31 func (m TxnOptions) WithEnableCheckDup() TxnOptions { 32 m.Features |= txnFeatureCheckDup 33 return m 34 } 35 36 func (m TxnOptions) WithDisable1PC() TxnOptions { 37 m.Features |= txnFeatureDisable1PC 38 return m 39 } 40 41 func (m TxnOptions) WithEnableCacheWrite() TxnOptions { 42 m.Features |= txnFeatureCacheWrite 43 return m 44 } 45 46 func (m TxnOptions) WithReadOnly() TxnOptions { 47 m.Features |= txnFeatureReadOnly 48 return m 49 } 50 51 func (m TxnOptions) WithUserTxn() TxnOptions { 52 m.Features |= txnFeatureUserTxn 53 return m 54 } 55 56 func (m TxnOptions) CacheWriteEnabled() bool { 57 return m.featureEnabled(txnFeatureCacheWrite) 58 } 59 60 func (m TxnOptions) TraceDisabled() bool { 61 return m.featureEnabled(txnFeatureDisableTrace) 62 } 63 64 func (m TxnOptions) UserTxn() bool { 65 return m.featureEnabled(txnFeatureUserTxn) 66 } 67 68 func (m TxnOptions) ReadOnly() bool { 69 return m.featureEnabled(txnFeatureReadOnly) 70 } 71 72 func (m TxnOptions) CheckDupEnabled() bool { 73 return m.featureEnabled(txnFeatureCheckDup) 74 } 75 76 func (m TxnOptions) Is1PCDisabled() bool { 77 return m.featureEnabled(txnFeatureDisable1PC) 78 } 79 80 func (m TxnOptions) featureEnabled(feature uint32) bool { 81 return m.Features&feature > 0 82 }