github.com/matrixorigin/matrixone@v1.2.0/pkg/util/executor/options.go (about) 1 // Copyright 2023 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 executor 16 17 import ( 18 "time" 19 20 "github.com/matrixorigin/matrixone/pkg/pb/lock" 21 "github.com/matrixorigin/matrixone/pkg/pb/timestamp" 22 "github.com/matrixorigin/matrixone/pkg/txn/client" 23 ) 24 25 // WithDisableIncrStatement disable incr statement 26 func (opts Options) WithDisableIncrStatement() Options { 27 opts.disableIncrStatement = true 28 return opts 29 } 30 31 // WithTxn exec sql in a exists txn 32 func (opts Options) WithTxn(txnOp client.TxnOperator) Options { 33 opts.txnOp = txnOp 34 return opts 35 } 36 37 // WithDatabase exec sql in database 38 func (opts Options) WithDatabase(database string) Options { 39 opts.database = database 40 return opts 41 } 42 43 // WithAccountID execute sql in account 44 func (opts Options) WithAccountID(accountID uint32) Options { 45 opts.accountID = accountID 46 return opts 47 } 48 49 func (opts Options) WithTimeZone(timeZone *time.Location) Options { 50 opts.timeZone = timeZone 51 return opts 52 } 53 54 // WithMinCommittedTS use minCommittedTS to exec sql. It will set txn's snapshot to 55 // minCommittedTS+1, so the txn can see the data which committed at minCommittedTS. 56 // It's not work if txn operator is set. 57 func (opts Options) WithMinCommittedTS(ts timestamp.Timestamp) Options { 58 opts.minCommittedTS = ts 59 return opts 60 } 61 62 // WithWaitCommittedLogApplied if set, the executor will wait all committed log applied 63 // for the txn. 64 func (opts Options) WithWaitCommittedLogApplied() Options { 65 opts.waitCommittedLogApplied = true 66 return opts 67 } 68 69 // Database returns default database 70 func (opts Options) Database() string { 71 return opts.database 72 } 73 74 // AccountID returns account id 75 func (opts Options) AccountID() uint32 { 76 return opts.accountID 77 } 78 79 // HasAccountID returns true if account is set 80 func (opts Options) HasAccountID() bool { 81 return opts.accountID > 0 82 } 83 84 // MinCommittedTS returns min committed ts 85 func (opts Options) MinCommittedTS() timestamp.Timestamp { 86 return opts.minCommittedTS 87 } 88 89 // WaitCommittedLogApplied return true means need wait committed log applied in current cn. 90 func (opts Options) WaitCommittedLogApplied() bool { 91 return opts.waitCommittedLogApplied 92 } 93 94 // HasExistsTxn return true if a exists txn is set 95 func (opts Options) HasExistsTxn() bool { 96 return opts.txnOp != nil 97 } 98 99 // ExistsTxn return true if the txn is a exists txn which is not create by executor 100 func (opts Options) ExistsTxn() bool { 101 return !opts.innerTxn 102 } 103 104 // SetupNewTxn setup new txn 105 func (opts Options) SetupNewTxn(txnOp client.TxnOperator) Options { 106 opts.txnOp = txnOp 107 opts.innerTxn = true 108 return opts 109 } 110 111 // Txn returns the txn operator 112 func (opts Options) Txn() client.TxnOperator { 113 return opts.txnOp 114 } 115 116 // DisableIncrStatement returns the txn operator need incr a new input statement 117 func (opts Options) DisableIncrStatement() bool { 118 return opts.disableIncrStatement 119 } 120 121 // GetTimeZone return the time zone of original session 122 func (opts Options) GetTimeZone() *time.Location { 123 return opts.timeZone 124 } 125 126 // WithStatementOption set statement option 127 func (opts Options) WithStatementOption(statementOption StatementOption) Options { 128 opts.statementOptions = statementOption 129 return opts 130 } 131 132 // StatementOption returns statement options 133 func (opts Options) StatementOption() StatementOption { 134 return opts.statementOptions 135 } 136 137 // WithWaitPolicy set wait policy for current statement 138 func (opts StatementOption) WithWaitPolicy(waitPolicy lock.WaitPolicy) StatementOption { 139 opts.waitPolicy = waitPolicy 140 return opts 141 } 142 143 // WaitPolicy returns the wait policy for current statement 144 func (opts StatementOption) WaitPolicy() lock.WaitPolicy { 145 return opts.waitPolicy 146 } 147 148 // WithAccountID execute sql in account 149 func (opts StatementOption) WithAccountID(accountID uint32) StatementOption { 150 opts.accountId = accountID 151 return opts 152 } 153 154 func (opts StatementOption) AccountID() uint32 { 155 return opts.accountId 156 } 157 158 func (opts StatementOption) HasAccountID() bool { 159 return opts.accountId > 0 160 } 161 162 func (opts Options) WithDisableTrace() Options { 163 opts.txnOpts = append(opts.txnOpts, client.WithDisableTrace(true)) 164 return opts 165 } 166 167 func (opts Options) ExtraTxnOptions() []client.TxnOption { 168 return opts.txnOpts 169 } 170 171 func (opts Options) WithEnableTrace() Options { 172 opts.enableTrace = true 173 return opts 174 } 175 176 func (opts Options) EnableTrace() bool { 177 return opts.enableTrace 178 }